diff options
author | Baoyou Xie <baoyou.xie@linaro.org> | 2017-01-16 22:22:57 -0500 |
---|---|---|
committer | Philipp Zabel <p.zabel@pengutronix.de> | 2017-01-20 04:36:12 -0500 |
commit | b38386f46bc7b8871665d863246476c9b6eb89ec (patch) | |
tree | d4ccd160c0066fd5a422c85e185917172451dcde /drivers | |
parent | 8041311cbfd63c242e3f004f3202047a5b5e309f (diff) |
reset: zx2967: add reset controller driver for ZTE's zx2967 family
This patch adds reset controller driver for ZTE's zx2967 family.
Signed-off-by: Baoyou Xie <baoyou.xie@linaro.org>
Reviewed-by: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/reset/Kconfig | 6 | ||||
-rw-r--r-- | drivers/reset/Makefile | 1 | ||||
-rw-r--r-- | drivers/reset/reset-zx2967.c | 106 |
3 files changed, 113 insertions, 0 deletions
diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig index 172dc966a01f..f4cdfe94b9ec 100644 --- a/drivers/reset/Kconfig +++ b/drivers/reset/Kconfig | |||
@@ -86,6 +86,12 @@ config RESET_UNIPHIER | |||
86 | Say Y if you want to control reset signals provided by System Control | 86 | Say Y if you want to control reset signals provided by System Control |
87 | block, Media I/O block, Peripheral Block. | 87 | block, Media I/O block, Peripheral Block. |
88 | 88 | ||
89 | config RESET_ZX2967 | ||
90 | bool "ZTE ZX2967 Reset Driver" | ||
91 | depends on ARCH_ZX || COMPILE_TEST | ||
92 | help | ||
93 | This enables the reset controller driver for ZTE's zx2967 family. | ||
94 | |||
89 | config RESET_ZYNQ | 95 | config RESET_ZYNQ |
90 | bool "ZYNQ Reset Driver" if COMPILE_TEST | 96 | bool "ZYNQ Reset Driver" if COMPILE_TEST |
91 | default ARCH_ZYNQ | 97 | default ARCH_ZYNQ |
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile index 13b346e03d84..2cd3f6c45165 100644 --- a/drivers/reset/Makefile +++ b/drivers/reset/Makefile | |||
@@ -13,4 +13,5 @@ obj-$(CONFIG_RESET_STM32) += reset-stm32.o | |||
13 | obj-$(CONFIG_RESET_SUNXI) += reset-sunxi.o | 13 | obj-$(CONFIG_RESET_SUNXI) += reset-sunxi.o |
14 | obj-$(CONFIG_TI_SYSCON_RESET) += reset-ti-syscon.o | 14 | obj-$(CONFIG_TI_SYSCON_RESET) += reset-ti-syscon.o |
15 | obj-$(CONFIG_RESET_UNIPHIER) += reset-uniphier.o | 15 | obj-$(CONFIG_RESET_UNIPHIER) += reset-uniphier.o |
16 | obj-$(CONFIG_RESET_ZX2967) += reset-zx2967.o | ||
16 | obj-$(CONFIG_RESET_ZYNQ) += reset-zynq.o | 17 | obj-$(CONFIG_RESET_ZYNQ) += reset-zynq.o |
diff --git a/drivers/reset/reset-zx2967.c b/drivers/reset/reset-zx2967.c new file mode 100644 index 000000000000..5d821513aa3e --- /dev/null +++ b/drivers/reset/reset-zx2967.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /* | ||
2 | * ZTE's zx2967 family reset controller driver | ||
3 | * | ||
4 | * Copyright (C) 2017 ZTE Ltd. | ||
5 | * | ||
6 | * Author: Baoyou Xie <baoyou.xie@linaro.org> | ||
7 | * | ||
8 | * License terms: GNU General Public License (GPL) version 2 | ||
9 | */ | ||
10 | |||
11 | #include <linux/module.h> | ||
12 | #include <linux/of_address.h> | ||
13 | #include <linux/platform_device.h> | ||
14 | #include <linux/reset-controller.h> | ||
15 | |||
16 | struct zx2967_reset { | ||
17 | void __iomem *reg_base; | ||
18 | spinlock_t lock; | ||
19 | struct reset_controller_dev rcdev; | ||
20 | }; | ||
21 | |||
22 | static int zx2967_reset_act(struct reset_controller_dev *rcdev, | ||
23 | unsigned long id, bool assert) | ||
24 | { | ||
25 | struct zx2967_reset *reset = NULL; | ||
26 | int bank = id / 32; | ||
27 | int offset = id % 32; | ||
28 | u32 reg; | ||
29 | unsigned long flags; | ||
30 | |||
31 | reset = container_of(rcdev, struct zx2967_reset, rcdev); | ||
32 | |||
33 | spin_lock_irqsave(&reset->lock, flags); | ||
34 | |||
35 | reg = readl_relaxed(reset->reg_base + (bank * 4)); | ||
36 | if (assert) | ||
37 | reg &= ~BIT(offset); | ||
38 | else | ||
39 | reg |= BIT(offset); | ||
40 | writel_relaxed(reg, reset->reg_base + (bank * 4)); | ||
41 | |||
42 | spin_unlock_irqrestore(&reset->lock, flags); | ||
43 | |||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | static int zx2967_reset_assert(struct reset_controller_dev *rcdev, | ||
48 | unsigned long id) | ||
49 | { | ||
50 | return zx2967_reset_act(rcdev, id, true); | ||
51 | } | ||
52 | |||
53 | static int zx2967_reset_deassert(struct reset_controller_dev *rcdev, | ||
54 | unsigned long id) | ||
55 | { | ||
56 | return zx2967_reset_act(rcdev, id, false); | ||
57 | } | ||
58 | |||
59 | static struct reset_control_ops zx2967_reset_ops = { | ||
60 | .assert = zx2967_reset_assert, | ||
61 | .deassert = zx2967_reset_deassert, | ||
62 | }; | ||
63 | |||
64 | static int zx2967_reset_probe(struct platform_device *pdev) | ||
65 | { | ||
66 | struct zx2967_reset *reset; | ||
67 | struct resource *res; | ||
68 | |||
69 | reset = devm_kzalloc(&pdev->dev, sizeof(*reset), GFP_KERNEL); | ||
70 | if (!reset) | ||
71 | return -ENOMEM; | ||
72 | |||
73 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
74 | reset->reg_base = devm_ioremap_resource(&pdev->dev, res); | ||
75 | if (IS_ERR(reset->reg_base)) | ||
76 | return PTR_ERR(reset->reg_base); | ||
77 | |||
78 | spin_lock_init(&reset->lock); | ||
79 | |||
80 | reset->rcdev.owner = THIS_MODULE; | ||
81 | reset->rcdev.nr_resets = resource_size(res) * 8; | ||
82 | reset->rcdev.ops = &zx2967_reset_ops; | ||
83 | reset->rcdev.of_node = pdev->dev.of_node; | ||
84 | |||
85 | return devm_reset_controller_register(&pdev->dev, &reset->rcdev); | ||
86 | } | ||
87 | |||
88 | static const struct of_device_id zx2967_reset_dt_ids[] = { | ||
89 | { .compatible = "zte,zx296718-reset", }, | ||
90 | {}, | ||
91 | }; | ||
92 | MODULE_DEVICE_TABLE(of, zx2967_reset_dt_ids); | ||
93 | |||
94 | static struct platform_driver zx2967_reset_driver = { | ||
95 | .probe = zx2967_reset_probe, | ||
96 | .driver = { | ||
97 | .name = "zx2967-reset", | ||
98 | .of_match_table = zx2967_reset_dt_ids, | ||
99 | }, | ||
100 | }; | ||
101 | |||
102 | builtin_platform_driver(zx2967_reset_driver); | ||
103 | |||
104 | MODULE_AUTHOR("Baoyou Xie <baoyou.xie@linaro.org>"); | ||
105 | MODULE_DESCRIPTION("ZTE zx2967 Reset Controller Driver"); | ||
106 | MODULE_LICENSE("GPL"); | ||