devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhangfei Gao <zhangfei.gao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
To: Philipp Zabel <p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
	Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	haojian.zhuang-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
	xuwei5-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org,
	Chen Feng <puck.chen-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>,
	Xinliang Liu
	<xinliang.liu-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	Xia Qing <saberlily.xia-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>,
	Jiancheng Xue
	<xuejiancheng-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org>
Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Zhangfei Gao
	<zhangfei.gao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Subject: [PATCH 1/6] reset: hisilicon: add reset core
Date: Tue, 22 Nov 2016 15:49:16 +0800	[thread overview]
Message-ID: <1479800961-6249-2-git-send-email-zhangfei.gao@linaro.org> (raw)
In-Reply-To: <1479800961-6249-1-git-send-email-zhangfei.gao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>

reset.c will be shared by hisilicon chips like hi3660 and hi6220

Signed-off-by: Zhangfei Gao <zhangfei.gao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
---
 drivers/reset/Makefile           |   2 +-
 drivers/reset/hisilicon/Makefile |   1 +
 drivers/reset/hisilicon/reset.c  | 108 +++++++++++++++++++++++++++++++++++++++
 drivers/reset/hisilicon/reset.h  |  37 ++++++++++++++
 4 files changed, 147 insertions(+), 1 deletion(-)
 create mode 100644 drivers/reset/hisilicon/reset.c
 create mode 100644 drivers/reset/hisilicon/reset.h

diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index bbe7026..7e3dc4e 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -1,8 +1,8 @@
 obj-y += core.o
-obj-y += hisilicon/
 obj-$(CONFIG_ARCH_STI) += sti/
 obj-$(CONFIG_RESET_ATH79) += reset-ath79.o
 obj-$(CONFIG_RESET_BERLIN) += reset-berlin.o
+obj-$(CONFIG_ARCH_HISI) += hisilicon/
 obj-$(CONFIG_RESET_LPC18XX) += reset-lpc18xx.o
 obj-$(CONFIG_RESET_MESON) += reset-meson.o
 obj-$(CONFIG_RESET_OXNAS) += reset-oxnas.o
diff --git a/drivers/reset/hisilicon/Makefile b/drivers/reset/hisilicon/Makefile
index c932f86..df511f5 100644
--- a/drivers/reset/hisilicon/Makefile
+++ b/drivers/reset/hisilicon/Makefile
@@ -1 +1,2 @@
+obj-y	+= reset.o
 obj-$(CONFIG_COMMON_RESET_HI6220) += hi6220_reset.o
diff --git a/drivers/reset/hisilicon/reset.c b/drivers/reset/hisilicon/reset.c
new file mode 100644
index 0000000..c4971c9
--- /dev/null
+++ b/drivers/reset/hisilicon/reset.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2016-2017 Linaro Ltd.
+ * Copyright (c) 2016-2017 HiSilicon Technologies Co., Ltd.
+ *
+ * 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.
+ */
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/types.h>
+#include <linux/of_device.h>
+#include <linux/mfd/syscon.h>
+
+#include "reset.h"
+
+struct hisi_reset_controller {
+	struct reset_controller_dev rst;
+	const struct hisi_reset_channel_data *channels;
+	struct regmap *map;
+};
+
+#define to_hisi_reset_controller(_rst) \
+	container_of(_rst, struct hisi_reset_controller, rst)
+
+static int hisi_reset_program_hw(struct reset_controller_dev *rcdev,
+				 unsigned long idx, bool assert)
+{
+	struct hisi_reset_controller *rc = to_hisi_reset_controller(rcdev);
+	const struct hisi_reset_channel_data *ch;
+
+	if (idx >= rcdev->nr_resets)
+		return -EINVAL;
+
+	ch = &rc->channels[idx];
+
+	if (assert)
+		return regmap_write(rc->map, ch->enable.reg,
+				    GENMASK(ch->enable.msb, ch->enable.lsb));
+	else
+		return regmap_write(rc->map, ch->disable.reg,
+				    GENMASK(ch->disable.msb, ch->disable.lsb));
+}
+
+static int hisi_reset_assert(struct reset_controller_dev *rcdev,
+			     unsigned long idx)
+{
+	return hisi_reset_program_hw(rcdev, idx, true);
+}
+
+static int hisi_reset_deassert(struct reset_controller_dev *rcdev,
+			       unsigned long idx)
+{
+	return hisi_reset_program_hw(rcdev, idx, false);
+}
+
+static int hisi_reset_dev(struct reset_controller_dev *rcdev,
+			  unsigned long idx)
+{
+	int err;
+
+	err = hisi_reset_assert(rcdev, idx);
+	if (err)
+		return err;
+
+	return hisi_reset_deassert(rcdev, idx);
+}
+
+static struct reset_control_ops hisi_reset_ops = {
+	.reset    = hisi_reset_dev,
+	.assert   = hisi_reset_assert,
+	.deassert = hisi_reset_deassert,
+};
+
+int hisi_reset_probe(struct platform_device *pdev)
+{
+	struct hisi_reset_controller *rc;
+	struct device_node *np = pdev->dev.of_node;
+	struct hisi_reset_controller_data *d;
+	struct device *dev = &pdev->dev;
+	const struct of_device_id *match;
+
+	match = of_match_device(dev->driver->of_match_table, dev);
+	if (!match || !match->data)
+		return -EINVAL;
+
+	d = (struct hisi_reset_controller_data *)match->data;
+	rc = devm_kzalloc(dev, sizeof(*rc), GFP_KERNEL);
+	if (!rc)
+		return -ENOMEM;
+
+	rc->map = syscon_regmap_lookup_by_phandle(np, "hisi,rst-syscon");
+	if (IS_ERR(rc->map)) {
+		dev_err(dev, "failed to get hisi,rst-syscon\n");
+		return PTR_ERR(rc->map);
+	}
+
+	rc->rst.ops = &hisi_reset_ops,
+	rc->rst.of_node = np;
+	rc->rst.nr_resets = d->nr_channels;
+	rc->channels = d->channels;
+
+	return reset_controller_register(&rc->rst);
+}
+EXPORT_SYMBOL_GPL(hisi_reset_probe);
diff --git a/drivers/reset/hisilicon/reset.h b/drivers/reset/hisilicon/reset.h
new file mode 100644
index 0000000..77259ee
--- /dev/null
+++ b/drivers/reset/hisilicon/reset.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016-2017 Linaro Ltd.
+ * Copyright (c) 2016-2017 HiSilicon Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __HISILICON_RESET_H
+#define __HISILICON_RESET_H
+
+#include <linux/device.h>
+#include <linux/regmap.h>
+#include <linux/reset-controller.h>
+
+/* reset separated register offset is 0x4 */
+#define HISI_RST_SEP(off, bit)					\
+	{ .enable	= REG_FIELD(off, bit, bit),		\
+	  .disable	= REG_FIELD(off + 0x4, bit, bit),	\
+	  .status	= REG_FIELD(off + 0x8, bit, bit), }
+
+struct hisi_reset_channel_data {
+	struct reg_field enable;
+	struct reg_field disable;
+	struct reg_field status;
+};
+
+struct hisi_reset_controller_data {
+	int nr_channels;
+	const struct hisi_reset_channel_data *channels;
+};
+
+int hisi_reset_probe(struct platform_device *pdev);
+
+#endif /* __HISILICON_RESET_H */
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2016-11-22  7:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-22  7:49 [PATCH 0/6] add hisilicon reset Zhangfei Gao
     [not found] ` <1479800961-6249-1-git-send-email-zhangfei.gao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-11-22  7:49   ` Zhangfei Gao [this message]
     [not found]     ` <1479800961-6249-2-git-send-email-zhangfei.gao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-11-22  8:45       ` [PATCH 1/6] reset: hisilicon: add reset core Arnd Bergmann
2016-11-22  9:22         ` zhangfei
     [not found]           ` <0084ef53-c0e6-51e8-afa5-07264dfce529-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-11-22  9:41             ` Arnd Bergmann
2016-11-22 10:22       ` Philipp Zabel
2016-11-22 10:22       ` Philipp Zabel
2016-11-22  7:49   ` [PATCH 2/6] dt-bindings: Document the hi3660 reset bindings Zhangfei Gao
2016-11-22  7:49   ` [PATCH 3/6] reset: hisilicon: add reset-hi3660 Zhangfei Gao
     [not found]     ` <1479800961-6249-4-git-send-email-zhangfei.gao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-11-22  8:50       ` Arnd Bergmann
2016-11-22  9:34         ` zhangfei
     [not found]           ` <d6e602c0-70e9-0309-86b5-bfd006d86028-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-11-22  9:42             ` Arnd Bergmann
2016-11-22 10:02               ` zhangfei
2016-11-22 10:22               ` Philipp Zabel
     [not found]                 ` <1479810156.13701.1.camel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2016-11-23  8:02                   ` zhangfei
2016-11-22  7:49   ` [PATCH 4/6] dt-bindings: change hi6220-reset.txt according to reset-hi6220.c Zhangfei Gao
     [not found]     ` <1479800961-6249-5-git-send-email-zhangfei.gao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-11-22  8:48       ` Arnd Bergmann
2016-11-23 23:06         ` Rob Herring
2016-11-24  0:41           ` zhangfei
2016-11-22  7:49   ` [PATCH 5/6] reset: hisilicon: Use new driver reset-hi6222 Zhangfei Gao
     [not found]     ` <1479800961-6249-6-git-send-email-zhangfei.gao-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-11-22  8:49       ` Arnd Bergmann
2016-11-22  9:46         ` zhangfei
     [not found]           ` <0dcef3c7-7406-0728-5a18-c277bb8915ad-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-11-22  9:55             ` Arnd Bergmann
2016-11-22  7:49   ` [PATCH 6/6] arm64: dts: hi6220: update reset node according to reset-hi6220.c Zhangfei Gao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1479800961-6249-2-git-send-email-zhangfei.gao@linaro.org \
    --to=zhangfei.gao-qsej5fyqhm4dnm+yrofe0a@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=haojian.zhuang-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
    --cc=puck.chen-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
    --cc=robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=saberlily.xia-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
    --cc=xinliang.liu-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=xuejiancheng-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
    --cc=xuwei5-C8/M+/jPZTeaMJb+Lgu22Q@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).