From patchwork Tue May 10 09:50:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 67425 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp2033504qge; Tue, 10 May 2016 02:53:41 -0700 (PDT) X-Received: by 10.98.19.151 with SMTP id 23mr56770766pft.62.1462874021429; Tue, 10 May 2016 02:53:41 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e18si2010220pag.116.2016.05.10.02.53.41; Tue, 10 May 2016 02:53:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752670AbcEJJxW (ORCPT + 29 others); Tue, 10 May 2016 05:53:22 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:37926 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751790AbcEJJxS (ORCPT ); Tue, 10 May 2016 05:53:18 -0400 Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id u4A9o2q9001762; Tue, 10 May 2016 18:50:19 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com u4A9o2q9001762 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1462873820; bh=TYi2l4OjescD3fh2LzUYS//Gw14OzK+sKLWYvlFiSDM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ybEcwn4KeYxrRQPAG6nWqunIYgpjHKNw1COGeubRTWWYAfOyo1x4+5kuohpxiOLvS 7y9xVLyIm0/W41M4R5UpSUVHL3oCctbl4SWUe/HHsToivU2MP1qlBEJFOTY838H90m /meE+7xZarcUxuzt+uqvqXSJ5RuB8v/53pzj9msPWiC8YirqfWOGdsNbSA8LvCePAj RzgkGyFkrcOaRSrON5HMUt5bqlD1mrsAcfXNclQRqWOopSE54VnXU7/EYVIN9UZ0NW oVNXJOoBntuY+dRQ2IABBtqFmtIvIFrrdm9tp+C8EOjHooqK7l8dSBtU5S2bmuU6eh zyIGuphNQsM7A== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-clk@vger.kernel.org, Arnd Bergmann , Philipp Zabel Cc: Masahiro Yamada , Guenter Roeck , Kalle Valo , Jiri Slaby , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, "David S. Miller" , linux-arm-kernel@lists.infradead.org, Greg Kroah-Hartman , Andrew Morton Subject: [RFC PATCH 12/21] reset: uniphier: add core support for UniPhier reset driver Date: Tue, 10 May 2016 18:50:53 +0900 Message-Id: <1462873862-30940-13-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462873862-30940-1-git-send-email-yamada.masahiro@socionext.com> References: <1462873862-30940-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The core support for UniPhier reset drivers. On UniPhier SoCs, registers for clock, reset, and other system controlling are mixed in one hardware block. It is difficult to have one independent reset node. So, I chose to use MFD from which clocks and resets (and power in the future) are populated. This series is just for review. Please do not apply this patch. Signed-off-by: Masahiro Yamada --- MAINTAINERS | 1 + drivers/reset/Kconfig | 1 + drivers/reset/Makefile | 1 + drivers/reset/uniphier/Kconfig | 9 ++ drivers/reset/uniphier/Makefile | 1 + drivers/reset/uniphier/reset-uniphier-core.c | 151 +++++++++++++++++++++++++++ drivers/reset/uniphier/reset-uniphier.h | 33 ++++++ 7 files changed, 197 insertions(+) create mode 100644 drivers/reset/uniphier/Kconfig create mode 100644 drivers/reset/uniphier/Makefile create mode 100644 drivers/reset/uniphier/reset-uniphier-core.c create mode 100644 drivers/reset/uniphier/reset-uniphier.h -- 1.9.1 diff --git a/MAINTAINERS b/MAINTAINERS index 38c6bb5..95a4030 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1732,6 +1732,7 @@ F: drivers/i2c/busses/i2c-uniphier* F: drivers/mfd/uniphier-mfd.c F: drivers/mmc/host/uniphier-sd.c F: drivers/pinctrl/uniphier/ +F: drivers/reset/uniphier/ F: drivers/tty/serial/8250/8250_uniphier.c N: uniphier diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig index 6a0b24b..f7e5381 100644 --- a/drivers/reset/Kconfig +++ b/drivers/reset/Kconfig @@ -16,5 +16,6 @@ if RESET_CONTROLLER source "drivers/reset/sti/Kconfig" source "drivers/reset/hisilicon/Kconfig" +source "drivers/reset/uniphier/Kconfig" endif diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile index a1fc8ed..e2bb8c6 100644 --- a/drivers/reset/Makefile +++ b/drivers/reset/Makefile @@ -6,5 +6,6 @@ obj-$(CONFIG_MACH_PISTACHIO) += reset-pistachio.o obj-$(CONFIG_ARCH_SUNXI) += reset-sunxi.o obj-$(CONFIG_ARCH_STI) += sti/ obj-$(CONFIG_ARCH_HISI) += hisilicon/ +obj-$(CONFIG_RESET_UNIPHIER) += uniphier/ obj-$(CONFIG_ARCH_ZYNQ) += reset-zynq.o obj-$(CONFIG_ATH79) += reset-ath79.o diff --git a/drivers/reset/uniphier/Kconfig b/drivers/reset/uniphier/Kconfig new file mode 100644 index 0000000..e82f7a7 --- /dev/null +++ b/drivers/reset/uniphier/Kconfig @@ -0,0 +1,9 @@ +menuconfig RESET_UNIPHIER + bool "Reset drivers for UniPhier SoCs" + depends on (ARCH_UNIPHIER && MFD_UNIPHIER) || COMPILE_TEST + depends on OF && MFD_CORE && MFD_SYSCON + default ARCH_UNIPHIER && MFD_UNIPHIER + +if RESET_UNIPHIER + +endif diff --git a/drivers/reset/uniphier/Makefile b/drivers/reset/uniphier/Makefile new file mode 100644 index 0000000..ba660bc --- /dev/null +++ b/drivers/reset/uniphier/Makefile @@ -0,0 +1 @@ +obj-y += reset-uniphier-core.o diff --git a/drivers/reset/uniphier/reset-uniphier-core.c b/drivers/reset/uniphier/reset-uniphier-core.c new file mode 100644 index 0000000..95217d5 --- /dev/null +++ b/drivers/reset/uniphier/reset-uniphier-core.c @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2016 Socionext Inc. + * Author: Masahiro Yamada + * + * This program 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 program 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. + */ + +#include +#include +#include +#include +#include + +#include "reset-uniphier.h" + +struct uniphier_reset_priv { + struct reset_controller_dev rcdev; + struct device *dev; + struct regmap *regmap; + const struct uniphier_reset_data *data; + unsigned int nr_ids; +}; + +#define to_uniphier_reset_priv(_rcdev) \ + container_of(_rcdev, struct uniphier_reset_priv, rcdev) + +static int uniphier_reset_update(struct reset_controller_dev *rcdev, + unsigned long id, bool assert) +{ + struct uniphier_reset_priv *priv = to_uniphier_reset_priv(rcdev); + const struct uniphier_reset_data *p; + bool handled = false; + + for (p = priv->data; p->id != UNIPHIER_RESET_ID_END; p++) { + unsigned int val; + int ret; + + if (p->id != id) + continue; + + val = p->deassert_val; + if (assert) + val = ~val; + + ret = regmap_write_bits(priv->regmap, p->reg, p->mask, val); + if (ret) + return ret; + + handled = true; + } + + if (!handled) { + dev_err(priv->dev, "reset_id=%lu was not handled\n", id); + return -EINVAL; + } + + return 0; +} + +static int uniphier_reset_assert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + return uniphier_reset_update(rcdev, id, true); +} + +static int uniphier_reset_deassert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + return uniphier_reset_update(rcdev, id, false); +} + +static int uniphier_reset_status(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct uniphier_reset_priv *priv = to_uniphier_reset_priv(rcdev); + const struct uniphier_reset_data *p; + bool handled = false; + + for (p = priv->data; p->id != UNIPHIER_RESET_ID_END; p++) { + unsigned int val; + int ret; + + if (p->id != id) + continue; + + ret = regmap_read(priv->regmap, p->reg, &val); + if (ret) + return ret; + + if ((val & p->mask) != p->deassert_val) + return 1; + + handled = true; + } + + if (!handled) { + dev_err(priv->dev, "reset_id=%lu was not found\n", id); + return -EINVAL; + } + + return 0; +} + +static const struct reset_control_ops uniphier_reset_ops = { + .assert = uniphier_reset_assert, + .deassert = uniphier_reset_deassert, + .status = uniphier_reset_status, +}; + +int uniphier_reset_probe(struct platform_device *pdev, + const struct uniphier_reset_data *data) +{ + struct device *dev = &pdev->dev; + struct uniphier_reset_priv *priv; + const struct uniphier_reset_data *p; + struct regmap *regmap; + unsigned int nr_resets = 0; + + /* parent should be MFD and syscon node */ + regmap = syscon_node_to_regmap(dev->parent->of_node); + if (IS_ERR(regmap)) { + dev_err(dev, "failed to get regmap\n"); + return PTR_ERR(regmap); + } + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + for (p = data; p->id != UNIPHIER_RESET_ID_END; p++) + nr_resets = max(nr_resets, p->id + 1); + + priv->rcdev.ops = &uniphier_reset_ops; + priv->rcdev.owner = dev->driver->owner; + priv->rcdev.of_node = dev->parent->of_node; + priv->rcdev.nr_resets = nr_resets; + priv->dev = dev; + priv->regmap = regmap; + priv->data = data; + + return devm_reset_controller_register(&pdev->dev, &priv->rcdev); +} +EXPORT_SYMBOL_GPL(uniphier_reset_probe); diff --git a/drivers/reset/uniphier/reset-uniphier.h b/drivers/reset/uniphier/reset-uniphier.h new file mode 100644 index 0000000..1b26efd --- /dev/null +++ b/drivers/reset/uniphier/reset-uniphier.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2016 Socionext Inc. + * Author: Masahiro Yamada + * + * This program 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 program 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. + */ + +#ifndef __RESET_UNIPHIER_H__ +#define __RESET_UNIPHIER_H__ + +struct platform_device; + +struct uniphier_reset_data { + unsigned int id; + unsigned int reg; + unsigned int mask; + unsigned int deassert_val; +}; + +#define UNIPHIER_RESET_ID_END (unsigned int)(-1) + +int uniphier_reset_probe(struct platform_device *pdev, + const struct uniphier_reset_data *data); + +#endif /* __RESET_UNIPHIER_H__ */