From patchwork Fri May 13 14:00:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 9091741 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 846F89F1C1 for ; Fri, 13 May 2016 14:02:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5847E20260 for ; Fri, 13 May 2016 14:02:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C99D20251 for ; Fri, 13 May 2016 14:02:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b1DeO-000642-4G; Fri, 13 May 2016 14:01:08 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b1De9-0005iT-2j for linux-arm-kernel@lists.infradead.org; Fri, 13 May 2016 14:00:55 +0000 Received: by mail-wm0-x235.google.com with SMTP id g17so31884053wme.1 for ; Fri, 13 May 2016 07:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ehCkLs4pAoVw8rcZS47jnX7YnGSqBEPjPyIg3i5kz0Q=; b=Ywehk5mn/OZkUUxFbcnlGGMbyZvosYNzMV4CdKQbmnsuZFAlWqF4xITEUeihJCJ0il 8nrwtwTFJ6B643vn7wX5Tp/BBY8Ob+XIqvRAr82Gkpxx6pIYcMLW1qxMajoeRwfmdLLz EWjPVL9mmOO6bVYKhF2cIzUAXSvrAIw4lQpd4V+ESWUcZoX7mopGJu2ytDJYjqLxXPy8 GGcWrV7C3uhgOzZmq8oyQuDQoJ4NbW6zQyXmBlNuIbboO4jYcnnUn3fBh65+t7crybrU Yps55nwzUHIpGSWpLXF0PgipJQvShOUI7GrnbUR6HbZy56dZOwG7r2VGsDH1Pa4/+9Hs LohA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ehCkLs4pAoVw8rcZS47jnX7YnGSqBEPjPyIg3i5kz0Q=; b=Ax2IN/B8pKNBmiJoXAfmNnIkyKq31BlSPMGpU04m/zYYpBcwzhBaC6NQdNUWhfyEwu tiwEJZ00UHUDkT7dZRpn5/7kmQqpMJHn1ZtaGNO8ZY+2F9r2BKkWb2amEZF7LchqH18e /TAHbxs+RT0wvKkcUzHThXMsJpGeBnteR8m+5E8QpVGbJznnzvX7B2mPgVos0iz3EMsn q9Brfj4Z84tYO2zk3G71uZw1uVjcHw5CB3ZVD9Bma1q4MUFfRdM18g/VpVFqEvERUPhc xw8dLz+1HhruvCVZ3nB0PGnidSoeN1WOQP0YZ/TiDnPQC4eTI4xIj4qpVpOgC71sOKJG xz2g== X-Gm-Message-State: AOPr4FVwGZr/JDQHL1+uih00Ju8HcpxAP/OjmS0nx4v+s6x4fOMt22S9rJJAwcSRLbHc7sOe X-Received: by 10.194.179.233 with SMTP id dj9mr16236252wjc.115.1463148031533; Fri, 13 May 2016 07:00:31 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id d1sm18749091wjb.47.2016.05.13.07.00.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 May 2016 07:00:30 -0700 (PDT) From: Neil Armstrong To: linux-kernel@vger.kernel.org, p.zabel@pengutronix.de, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org Subject: [RFC PATCH 1/3] reset: Add support for the Amlogic Meson GXBB Reset Controller Date: Fri, 13 May 2016 16:00:10 +0200 Message-Id: <1463148012-25988-2-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1463148012-25988-1-git-send-email-narmstrong@baylibre.com> References: <1463148012-25988-1-git-send-email-narmstrong@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160513_070053_495520_4F726334 X-CRM114-Status: GOOD ( 22.28 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Neil Armstrong MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds the platform driver for the Amlogic Meson GXBB Reset Controller. Signed-off-by: Neil Armstrong --- drivers/reset/Kconfig | 6 ++ drivers/reset/Makefile | 1 + drivers/reset/reset-meson-gxbb.c | 160 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 drivers/reset/reset-meson-gxbb.c diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig index df37212..4ac5c4d 100644 --- a/drivers/reset/Kconfig +++ b/drivers/reset/Kconfig @@ -12,5 +12,11 @@ menuconfig RESET_CONTROLLER If unsure, say no. +config MESON_GXBB_RESET + tristate "Amlogic Meson GXBB Reset Driver" + depends on (ARCH_MESON && RESET_CONTROLLER) + help + Build the Amlogic Meson GxBB reset driver. + source "drivers/reset/sti/Kconfig" source "drivers/reset/hisilicon/Kconfig" diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile index a1fc8ed..5ff83a1 100644 --- a/drivers/reset/Makefile +++ b/drivers/reset/Makefile @@ -3,6 +3,7 @@ obj-$(CONFIG_ARCH_LPC18XX) += reset-lpc18xx.o obj-$(CONFIG_ARCH_SOCFPGA) += reset-socfpga.o obj-$(CONFIG_ARCH_BERLIN) += reset-berlin.o obj-$(CONFIG_MACH_PISTACHIO) += reset-pistachio.o +obj-$(CONFIG_MESON_GXBB_RESET) += reset-meson-gxbb.o obj-$(CONFIG_ARCH_SUNXI) += reset-sunxi.o obj-$(CONFIG_ARCH_STI) += sti/ obj-$(CONFIG_ARCH_HISI) += hisilicon/ diff --git a/drivers/reset/reset-meson-gxbb.c b/drivers/reset/reset-meson-gxbb.c new file mode 100644 index 0000000..798fdf9 --- /dev/null +++ b/drivers/reset/reset-meson-gxbb.c @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2016 BayLibre, Inc. + * Author: Neil Armstrong + * + * This file is dual-licensed: you can use it either under the terms + * of the GPL or the X11 license, at your option. Note that this dual + * licensing only applies to this file, and not this project as a + * whole. + * + * a) This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Or, alternatively, + * + * b) Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#define REG_COUNT 7 +#define BITS_PER_REG 16 + +struct meson_gxbb_reset { + void *reg_base; + struct reset_controller_dev rcdev; +}; + +static int meson_gxbb_reset_assert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct meson_gxbb_reset *data = + container_of(rcdev, struct meson_gxbb_reset, rcdev); + unsigned int bank = id / BITS_PER_REG; + unsigned int offset = id % BITS_PER_REG; + void *reg_addr = data->reg_base + (bank << 2); + + if (bank >= REG_COUNT) + return -EINVAL; + + writel(readl(reg_addr) | BIT(offset), reg_addr); + + return 0; +} + +static int meson_gxbb_reset_deassert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct meson_gxbb_reset *data = + container_of(rcdev, struct meson_gxbb_reset, rcdev); + unsigned int bank = id / BITS_PER_REG; + unsigned int offset = id % BITS_PER_REG; + void *reg_addr = data->reg_base + (bank << 2); + + if (bank >= REG_COUNT) + return -EINVAL; + + writel(readl(reg_addr) & ~BIT(offset), reg_addr); + + return 0; +} + +static int meson_gxbb_reset_reset(struct reset_controller_dev *rcdev, + unsigned long id) +{ + int err; + + err = meson_gxbb_reset_assert(rcdev, id); + if (err) + return err; + + return meson_gxbb_reset_deassert(rcdev, id); +} + +static const struct reset_control_ops meson_gxbb_reset_ops = { + .reset = meson_gxbb_reset_reset, + .assert = meson_gxbb_reset_assert, + .deassert = meson_gxbb_reset_deassert, +}; + +static const struct of_device_id meson_gxbb_reset_dt_ids[] = { + { .compatible = "amlogic,meson-gxbb-reset", }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, meson_gxbb_reset_dt_ids); + +static int meson_gxbb_reset_probe(struct platform_device *pdev) +{ + struct meson_gxbb_reset *data; + struct resource *res; + + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + data->reg_base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(data->reg_base)) + return PTR_ERR(data->reg_base); + + platform_set_drvdata(pdev, data); + + data->rcdev.owner = THIS_MODULE; + data->rcdev.nr_resets = REG_COUNT * BITS_PER_REG; + data->rcdev.ops = &meson_gxbb_reset_ops; + data->rcdev.of_node = pdev->dev.of_node; + + return reset_controller_register(&data->rcdev); +} + +static int meson_gxbb_reset_remove(struct platform_device *pdev) +{ + struct meson_gxbb_reset *data = platform_get_drvdata(pdev); + + reset_controller_unregister(&data->rcdev); + + return 0; +} + +static struct platform_driver meson_gxbb_reset_driver = { + .probe = meson_gxbb_reset_probe, + .remove = meson_gxbb_reset_remove, + .driver = { + .name = "meson_gxbb_reset", + .of_match_table = meson_gxbb_reset_dt_ids, + }, +}; + +module_platform_driver(meson_gxbb_reset_driver);