2 * ZTE's zx2967 family reset controller driver
4 * Copyright (C) 2017 ZTE Ltd.
6 * Author: Baoyou Xie <baoyou.xie@linaro.org>
8 * License terms: GNU General Public License (GPL) version 2
11 #include <linux/of_address.h>
12 #include <linux/platform_device.h>
13 #include <linux/reset-controller.h>
16 void __iomem *reg_base;
18 struct reset_controller_dev rcdev;
21 static int zx2967_reset_act(struct reset_controller_dev *rcdev,
22 unsigned long id, bool assert)
24 struct zx2967_reset *reset = NULL;
30 reset = container_of(rcdev, struct zx2967_reset, rcdev);
32 spin_lock_irqsave(&reset->lock, flags);
34 reg = readl_relaxed(reset->reg_base + (bank * 4));
39 writel_relaxed(reg, reset->reg_base + (bank * 4));
41 spin_unlock_irqrestore(&reset->lock, flags);
46 static int zx2967_reset_assert(struct reset_controller_dev *rcdev,
49 return zx2967_reset_act(rcdev, id, true);
52 static int zx2967_reset_deassert(struct reset_controller_dev *rcdev,
55 return zx2967_reset_act(rcdev, id, false);
58 static const struct reset_control_ops zx2967_reset_ops = {
59 .assert = zx2967_reset_assert,
60 .deassert = zx2967_reset_deassert,
63 static int zx2967_reset_probe(struct platform_device *pdev)
65 struct zx2967_reset *reset;
68 reset = devm_kzalloc(&pdev->dev, sizeof(*reset), GFP_KERNEL);
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);
77 spin_lock_init(&reset->lock);
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;
84 return devm_reset_controller_register(&pdev->dev, &reset->rcdev);
87 static const struct of_device_id zx2967_reset_dt_ids[] = {
88 { .compatible = "zte,zx296718-reset", },
92 static struct platform_driver zx2967_reset_driver = {
93 .probe = zx2967_reset_probe,
95 .name = "zx2967-reset",
96 .of_match_table = zx2967_reset_dt_ids,
99 builtin_platform_driver(zx2967_reset_driver);