Skip to content

Commit b38386f

Browse files
Baoyou XiepH5
authored andcommitted
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>
1 parent 8041311 commit b38386f

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

drivers/reset/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ config RESET_UNIPHIER
8686
Say Y if you want to control reset signals provided by System Control
8787
block, Media I/O block, Peripheral Block.
8888

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+
8995
config RESET_ZYNQ
9096
bool "ZYNQ Reset Driver" if COMPILE_TEST
9197
default ARCH_ZYNQ

drivers/reset/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ obj-$(CONFIG_RESET_STM32) += reset-stm32.o
1313
obj-$(CONFIG_RESET_SUNXI) += reset-sunxi.o
1414
obj-$(CONFIG_TI_SYSCON_RESET) += reset-ti-syscon.o
1515
obj-$(CONFIG_RESET_UNIPHIER) += reset-uniphier.o
16+
obj-$(CONFIG_RESET_ZX2967) += reset-zx2967.o
1617
obj-$(CONFIG_RESET_ZYNQ) += reset-zynq.o

drivers/reset/reset-zx2967.c

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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");

0 commit comments

Comments
 (0)