Merge tag 'seccomp-v4.14-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees...
[platform/kernel/linux-exynos.git] / drivers / reset / reset-zx2967.c
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/of_address.h>
12 #include <linux/platform_device.h>
13 #include <linux/reset-controller.h>
14
15 struct zx2967_reset {
16         void __iomem                    *reg_base;
17         spinlock_t                      lock;
18         struct reset_controller_dev     rcdev;
19 };
20
21 static 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
46 static int zx2967_reset_assert(struct reset_controller_dev *rcdev,
47                                unsigned long id)
48 {
49         return zx2967_reset_act(rcdev, id, true);
50 }
51
52 static int zx2967_reset_deassert(struct reset_controller_dev *rcdev,
53                                  unsigned long id)
54 {
55         return zx2967_reset_act(rcdev, id, false);
56 }
57
58 static const struct reset_control_ops zx2967_reset_ops = {
59         .assert         = zx2967_reset_assert,
60         .deassert       = zx2967_reset_deassert,
61 };
62
63 static 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
87 static const struct of_device_id zx2967_reset_dt_ids[] = {
88          { .compatible = "zte,zx296718-reset", },
89          {},
90 };
91
92 static 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 };
99 builtin_platform_driver(zx2967_reset_driver);