blob: 4dabb9ec48418011d55a3dc6b96a513bb2ae54cd [file] [log] [blame]
Baoyou Xieb38386f2017-01-17 11:22:57 +08001/*
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
Baoyou Xieb38386f2017-01-17 11:22:57 +080011#include <linux/of_address.h>
12#include <linux/platform_device.h>
13#include <linux/reset-controller.h>
14
15struct zx2967_reset {
16 void __iomem *reg_base;
17 spinlock_t lock;
18 struct reset_controller_dev rcdev;
19};
20
21static int zx2967_reset_act(struct reset_controller_dev *rcdev,
22 unsigned long id, bool assert)
23{
24 struct zx2967_reset *reset = NULL;
25 int bank = id / 32;
26 int offset = id % 32;
27 u32 reg;
28 unsigned long flags;
29
30 reset = container_of(rcdev, struct zx2967_reset, rcdev);
31
32 spin_lock_irqsave(&reset->lock, flags);
33
34 reg = readl_relaxed(reset->reg_base + (bank * 4));
35 if (assert)
36 reg &= ~BIT(offset);
37 else
38 reg |= BIT(offset);
39 writel_relaxed(reg, reset->reg_base + (bank * 4));
40
41 spin_unlock_irqrestore(&reset->lock, flags);
42
43 return 0;
44}
45
46static int zx2967_reset_assert(struct reset_controller_dev *rcdev,
47 unsigned long id)
48{
49 return zx2967_reset_act(rcdev, id, true);
50}
51
52static int zx2967_reset_deassert(struct reset_controller_dev *rcdev,
53 unsigned long id)
54{
55 return zx2967_reset_act(rcdev, id, false);
56}
57
58static struct reset_control_ops zx2967_reset_ops = {
59 .assert = zx2967_reset_assert,
60 .deassert = zx2967_reset_deassert,
61};
62
63static int zx2967_reset_probe(struct platform_device *pdev)
64{
65 struct zx2967_reset *reset;
66 struct resource *res;
67
68 reset = devm_kzalloc(&pdev->dev, sizeof(*reset), GFP_KERNEL);
69 if (!reset)
70 return -ENOMEM;
71
72 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
73 reset->reg_base = devm_ioremap_resource(&pdev->dev, res);
74 if (IS_ERR(reset->reg_base))
75 return PTR_ERR(reset->reg_base);
76
77 spin_lock_init(&reset->lock);
78
79 reset->rcdev.owner = THIS_MODULE;
80 reset->rcdev.nr_resets = resource_size(res) * 8;
81 reset->rcdev.ops = &zx2967_reset_ops;
82 reset->rcdev.of_node = pdev->dev.of_node;
83
84 return devm_reset_controller_register(&pdev->dev, &reset->rcdev);
85}
86
87static const struct of_device_id zx2967_reset_dt_ids[] = {
88 { .compatible = "zte,zx296718-reset", },
89 {},
90};
Baoyou Xieb38386f2017-01-17 11:22:57 +080091
92static struct platform_driver zx2967_reset_driver = {
93 .probe = zx2967_reset_probe,
94 .driver = {
95 .name = "zx2967-reset",
96 .of_match_table = zx2967_reset_dt_ids,
97 },
98};
Baoyou Xieb38386f2017-01-17 11:22:57 +080099builtin_platform_driver(zx2967_reset_driver);