Linux 4.19.133
[linux/fpc-iii.git] / drivers / reset / reset-oxnas.c
blobcf5b9742b86ecf4ebc8aa8f53fd5ffb3f607d6b1
1 /*
2 * drivers/reset/reset-oxnas.c
4 * Copyright (C) 2016 Neil Armstrong <narmstrong@baylibre.com>
5 * Copyright (C) 2014 Ma Haijun <mahaijuns@gmail.com>
6 * Copyright (C) 2009 Oxford Semiconductor Ltd
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <linux/err.h>
21 #include <linux/init.h>
22 #include <linux/of.h>
23 #include <linux/platform_device.h>
24 #include <linux/reset-controller.h>
25 #include <linux/slab.h>
26 #include <linux/delay.h>
27 #include <linux/types.h>
28 #include <linux/regmap.h>
29 #include <linux/mfd/syscon.h>
31 /* Regmap offsets */
32 #define RST_SET_REGOFFSET 0x34
33 #define RST_CLR_REGOFFSET 0x38
35 struct oxnas_reset {
36 struct regmap *regmap;
37 struct reset_controller_dev rcdev;
40 static int oxnas_reset_reset(struct reset_controller_dev *rcdev,
41 unsigned long id)
43 struct oxnas_reset *data =
44 container_of(rcdev, struct oxnas_reset, rcdev);
46 regmap_write(data->regmap, RST_SET_REGOFFSET, BIT(id));
47 msleep(50);
48 regmap_write(data->regmap, RST_CLR_REGOFFSET, BIT(id));
50 return 0;
53 static int oxnas_reset_assert(struct reset_controller_dev *rcdev,
54 unsigned long id)
56 struct oxnas_reset *data =
57 container_of(rcdev, struct oxnas_reset, rcdev);
59 regmap_write(data->regmap, RST_SET_REGOFFSET, BIT(id));
61 return 0;
64 static int oxnas_reset_deassert(struct reset_controller_dev *rcdev,
65 unsigned long id)
67 struct oxnas_reset *data =
68 container_of(rcdev, struct oxnas_reset, rcdev);
70 regmap_write(data->regmap, RST_CLR_REGOFFSET, BIT(id));
72 return 0;
75 static const struct reset_control_ops oxnas_reset_ops = {
76 .reset = oxnas_reset_reset,
77 .assert = oxnas_reset_assert,
78 .deassert = oxnas_reset_deassert,
81 static const struct of_device_id oxnas_reset_dt_ids[] = {
82 { .compatible = "oxsemi,ox810se-reset", },
83 { .compatible = "oxsemi,ox820-reset", },
84 { /* sentinel */ },
87 static int oxnas_reset_probe(struct platform_device *pdev)
89 struct oxnas_reset *data;
90 struct device *parent;
92 parent = pdev->dev.parent;
93 if (!parent) {
94 dev_err(&pdev->dev, "no parent\n");
95 return -ENODEV;
98 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
99 if (!data)
100 return -ENOMEM;
102 data->regmap = syscon_node_to_regmap(parent->of_node);
103 if (IS_ERR(data->regmap)) {
104 dev_err(&pdev->dev, "failed to get parent regmap\n");
105 return PTR_ERR(data->regmap);
108 platform_set_drvdata(pdev, data);
110 data->rcdev.owner = THIS_MODULE;
111 data->rcdev.nr_resets = 32;
112 data->rcdev.ops = &oxnas_reset_ops;
113 data->rcdev.of_node = pdev->dev.of_node;
115 return devm_reset_controller_register(&pdev->dev, &data->rcdev);
118 static struct platform_driver oxnas_reset_driver = {
119 .probe = oxnas_reset_probe,
120 .driver = {
121 .name = "oxnas-reset",
122 .of_match_table = oxnas_reset_dt_ids,
125 builtin_platform_driver(oxnas_reset_driver);