blob: 369f3917fd8e384baf798d6a1f143e7ae59df737 [file] [log] [blame]
Antoine Ténartbd132512014-09-03 09:48:20 +02001/*
2 * Copyright (C) 2014 Marvell Technology Group Ltd.
3 *
4 * Antoine Tenart <antoine.tenart@free-electrons.com>
5 * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
6 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */
11
12#include <linux/delay.h>
13#include <linux/io.h>
Antoine Tenartaed6f3c2015-05-16 00:41:25 +020014#include <linux/mfd/syscon.h>
Antoine Ténartbd132512014-09-03 09:48:20 +020015#include <linux/module.h>
16#include <linux/of.h>
17#include <linux/of_address.h>
18#include <linux/platform_device.h>
Antoine Tenartaed6f3c2015-05-16 00:41:25 +020019#include <linux/regmap.h>
Antoine Ténartbd132512014-09-03 09:48:20 +020020#include <linux/reset-controller.h>
21#include <linux/slab.h>
22#include <linux/types.h>
23
24#define BERLIN_MAX_RESETS 32
25
26#define to_berlin_reset_priv(p) \
27 container_of((p), struct berlin_reset_priv, rcdev)
28
29struct berlin_reset_priv {
Antoine Tenartaed6f3c2015-05-16 00:41:25 +020030 struct regmap *regmap;
Antoine Ténartbd132512014-09-03 09:48:20 +020031 struct reset_controller_dev rcdev;
32};
33
34static int berlin_reset_reset(struct reset_controller_dev *rcdev,
35 unsigned long id)
36{
37 struct berlin_reset_priv *priv = to_berlin_reset_priv(rcdev);
38 int offset = id >> 8;
39 int mask = BIT(id & 0x1f);
40
Antoine Tenartbfff6292015-05-16 00:53:44 +020041 regmap_write(priv->regmap, offset, mask);
Antoine Ténartbd132512014-09-03 09:48:20 +020042
43 /* let the reset be effective */
44 udelay(10);
45
46 return 0;
47}
48
Philipp Zabelb7a90072016-01-17 15:12:48 +010049static const struct reset_control_ops berlin_reset_ops = {
Antoine Ténartbd132512014-09-03 09:48:20 +020050 .reset = berlin_reset_reset,
51};
52
53static int berlin_reset_xlate(struct reset_controller_dev *rcdev,
54 const struct of_phandle_args *reset_spec)
55{
Antoine Ténartbd132512014-09-03 09:48:20 +020056 unsigned offset, bit;
57
Antoine Ténartbd132512014-09-03 09:48:20 +020058 offset = reset_spec->args[0];
59 bit = reset_spec->args[1];
60
Antoine Ténartbd132512014-09-03 09:48:20 +020061 if (bit >= BERLIN_MAX_RESETS)
62 return -EINVAL;
63
64 return (offset << 8) | bit;
65}
66
Antoine Tenartaed6f3c2015-05-16 00:41:25 +020067static int berlin2_reset_probe(struct platform_device *pdev)
68{
69 struct device_node *parent_np = of_get_parent(pdev->dev.of_node);
70 struct berlin_reset_priv *priv;
71
72 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
73 if (!priv)
74 return -ENOMEM;
75
76 priv->regmap = syscon_node_to_regmap(parent_np);
77 of_node_put(parent_np);
78 if (IS_ERR(priv->regmap))
79 return PTR_ERR(priv->regmap);
80
81 priv->rcdev.owner = THIS_MODULE;
82 priv->rcdev.ops = &berlin_reset_ops;
83 priv->rcdev.of_node = pdev->dev.of_node;
84 priv->rcdev.of_reset_n_cells = 2;
85 priv->rcdev.of_xlate = berlin_reset_xlate;
86
Masahiro Yamadad1f15aa2015-11-05 14:54:56 +090087 return reset_controller_register(&priv->rcdev);
Antoine Tenartaed6f3c2015-05-16 00:41:25 +020088}
89
90static const struct of_device_id berlin_reset_dt_match[] = {
91 { .compatible = "marvell,berlin2-reset" },
92 { },
93};
94MODULE_DEVICE_TABLE(of, berlin_reset_dt_match);
95
96static struct platform_driver berlin_reset_driver = {
97 .probe = berlin2_reset_probe,
98 .driver = {
99 .name = "berlin2-reset",
100 .of_match_table = berlin_reset_dt_match,
101 },
102};
103module_platform_driver(berlin_reset_driver);
104
105MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
106MODULE_AUTHOR("Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>");
107MODULE_DESCRIPTION("Marvell Berlin reset driver");
108MODULE_LICENSE("GPL");