From patchwork Fri May 20 08:27:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 9128883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 445F06048B for ; Fri, 20 May 2016 08:28:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34C1F25D91 for ; Fri, 20 May 2016 08:28:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 296DE279C4; Fri, 20 May 2016 08:28:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id ADEFC25D91 for ; Fri, 20 May 2016 08:28:56 +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 1b3fnk-0004KF-CB; Fri, 20 May 2016 08:28:56 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b3fnP-00045U-Sw for linux-amlogic@lists.infradead.org; Fri, 20 May 2016 08:28:37 +0000 Received: by mail-wm0-x22d.google.com with SMTP id n129so261398286wmn.1 for ; Fri, 20 May 2016 01:28:15 -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=2NhwLUjvbU/z8791zRmvcwm6za6eX3sVzIkkzmTON/0=; b=1+IvV3EK8zQxy4Pc3hooDIZMnvHQjtJo+nuw01PoGUVR1uLxLZpf7rL1x6PtSx/g3E RM+VS4Bl7d9Os7basB0kAPGQAL3k6LxeTB7HM5M367xK83t07YUegDO3Zzk+8CFP6KDc 3nc8aCiOEmgKDp2oYd4mj9OjzGmjOvV2jSdfpB8jPMZcaTJbBxUa1dqfFYUqLIJZZsyG Owaoxjaguf8eVkxW+HGCZ3lYEmfOUGJLgvWYgH8QH1GPCD9zOCsJfVJyoFAz2Y/+OwC+ w36+FDtP4QYotFQwi0/AjNMzNKAZRbalfWeJ61KfFhy8+zppS2Sq3afI3IykOk0R305T wLcQ== 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=2NhwLUjvbU/z8791zRmvcwm6za6eX3sVzIkkzmTON/0=; b=iZ4czw/gIcV12VYKxOcuYZNcxuZ8M687BoXxI+VMlz6DCw6t+mcGKdPZtDp/8xYzCh +JwgFZtNASd7lchykh70hVT5x4S3YZLdkLTvspXUz4r0R7zHUvlp2OinQj63NfLTOUm5 3ijl6u9ygBcQnyzcrbvff6bfL7wgJrIr5Z4oMPHn2C5bVjbXWWbz1/+1I5EhsHE035nO S1n1Z3IlNHbDk/3HdCQdgVH/g0bzLQejSzGXjjr1FR+RNujpcwn+FPoBXJZ/zvBkdmFh 7M6P268eXcqIq2YfmVKYzECdtbqgwSm8um/hQLkUWtNYmZ4K0yYJeAi/OKiC0p3ccy4c SCWQ== X-Gm-Message-State: AOPr4FWSo0RhIcZPpbhSyZ0KscDidNi02dAeUQcS7fqUECbWnIEgdoSOwmu8Jhk0ynFraBd7 X-Received: by 10.28.230.137 with SMTP id e9mr2234168wmi.90.1463732894105; Fri, 20 May 2016 01:28:14 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id k1sm18564150wjx.22.2016.05.20.01.28.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 20 May 2016 01:28:13 -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: [PATCH 1/3] reset: Add support for the Amlogic Meson GXBB Reset Controller Date: Fri, 20 May 2016 10:27:53 +0200 Message-Id: <1463732875-23141-2-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1463732875-23141-1-git-send-email-narmstrong@baylibre.com> References: <1463732875-23141-1-git-send-email-narmstrong@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160520_012836_337137_4FFCE0F8 X-CRM114-Status: GOOD ( 20.51 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jerry.cao@amlogic.com, xing.xu@amlogic.com, victor.wan@amlogic.com, Neil Armstrong MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.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 | 129 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 136 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..e96691b --- /dev/null +++ b/drivers/reset/reset-meson-gxbb.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2016 BayLibre, SAS. + * 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 8 +#define BITS_PER_REG 32 + +struct meson_gxbb_reset { + void __iomem *reg_base; + struct reset_controller_dev rcdev; +}; + +static int meson_gxbb_reset_reset(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 __iomem *reg_addr = data->reg_base + (bank << 2); + + if (bank >= REG_COUNT) + return -EINVAL; + + writel(BIT(offset), reg_addr); + + return 0; +} + +static const struct reset_control_ops meson_gxbb_reset_ops = { + .reset = meson_gxbb_reset_reset, +}; + +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);