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
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/module.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>
32 #define RST_SET_REGOFFSET 0x34
33 #define RST_CLR_REGOFFSET 0x38
36 struct regmap
*regmap
;
37 struct reset_controller_dev rcdev
;
40 static int oxnas_reset_reset(struct reset_controller_dev
*rcdev
,
43 struct oxnas_reset
*data
=
44 container_of(rcdev
, struct oxnas_reset
, rcdev
);
46 regmap_write(data
->regmap
, RST_SET_REGOFFSET
, BIT(id
));
48 regmap_write(data
->regmap
, RST_CLR_REGOFFSET
, BIT(id
));
53 static int oxnas_reset_assert(struct reset_controller_dev
*rcdev
,
56 struct oxnas_reset
*data
=
57 container_of(rcdev
, struct oxnas_reset
, rcdev
);
59 regmap_write(data
->regmap
, RST_SET_REGOFFSET
, BIT(id
));
64 static int oxnas_reset_deassert(struct reset_controller_dev
*rcdev
,
67 struct oxnas_reset
*data
=
68 container_of(rcdev
, struct oxnas_reset
, rcdev
);
70 regmap_write(data
->regmap
, RST_CLR_REGOFFSET
, BIT(id
));
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", },
85 MODULE_DEVICE_TABLE(of
, oxnas_reset_dt_ids
);
87 static int oxnas_reset_probe(struct platform_device
*pdev
)
89 struct oxnas_reset
*data
;
90 struct device
*parent
;
92 parent
= pdev
->dev
.parent
;
94 dev_err(&pdev
->dev
, "no parent\n");
98 data
= devm_kzalloc(&pdev
->dev
, sizeof(*data
), GFP_KERNEL
);
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 reset_controller_register(&data
->rcdev
);
118 static int oxnas_reset_remove(struct platform_device
*pdev
)
120 struct oxnas_reset
*data
= platform_get_drvdata(pdev
);
122 reset_controller_unregister(&data
->rcdev
);
127 static struct platform_driver oxnas_reset_driver
= {
128 .probe
= oxnas_reset_probe
,
129 .remove
= oxnas_reset_remove
,
131 .name
= "oxnas-reset",
132 .of_match_table
= oxnas_reset_dt_ids
,
136 module_platform_driver(oxnas_reset_driver
);