1 // SPDX-License-Identifier: GPL-2.0-only
3 * drivers/reset/reset-oxnas.c
5 * Copyright (C) 2016 Neil Armstrong <narmstrong@baylibre.com>
6 * Copyright (C) 2014 Ma Haijun <mahaijuns@gmail.com>
7 * Copyright (C) 2009 Oxford Semiconductor Ltd
10 #include <linux/init.h>
12 #include <linux/platform_device.h>
13 #include <linux/reset-controller.h>
14 #include <linux/slab.h>
15 #include <linux/delay.h>
16 #include <linux/types.h>
17 #include <linux/regmap.h>
18 #include <linux/mfd/syscon.h>
21 #define RST_SET_REGOFFSET 0x34
22 #define RST_CLR_REGOFFSET 0x38
25 struct regmap *regmap;
26 struct reset_controller_dev rcdev;
29 static int oxnas_reset_reset(struct reset_controller_dev *rcdev,
32 struct oxnas_reset *data =
33 container_of(rcdev, struct oxnas_reset, rcdev);
35 regmap_write(data->regmap, RST_SET_REGOFFSET, BIT(id));
37 regmap_write(data->regmap, RST_CLR_REGOFFSET, BIT(id));
42 static int oxnas_reset_assert(struct reset_controller_dev *rcdev,
45 struct oxnas_reset *data =
46 container_of(rcdev, struct oxnas_reset, rcdev);
48 regmap_write(data->regmap, RST_SET_REGOFFSET, BIT(id));
53 static int oxnas_reset_deassert(struct reset_controller_dev *rcdev,
56 struct oxnas_reset *data =
57 container_of(rcdev, struct oxnas_reset, rcdev);
59 regmap_write(data->regmap, RST_CLR_REGOFFSET, BIT(id));
64 static const struct reset_control_ops oxnas_reset_ops = {
65 .reset = oxnas_reset_reset,
66 .assert = oxnas_reset_assert,
67 .deassert = oxnas_reset_deassert,
70 static const struct of_device_id oxnas_reset_dt_ids[] = {
71 { .compatible = "oxsemi,ox810se-reset", },
72 { .compatible = "oxsemi,ox820-reset", },
76 static int oxnas_reset_probe(struct platform_device *pdev)
78 struct oxnas_reset *data;
79 struct device *parent;
81 parent = pdev->dev.parent;
83 dev_err(&pdev->dev, "no parent\n");
87 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
91 data->regmap = syscon_node_to_regmap(parent->of_node);
92 if (IS_ERR(data->regmap)) {
93 dev_err(&pdev->dev, "failed to get parent regmap\n");
94 return PTR_ERR(data->regmap);
97 platform_set_drvdata(pdev, data);
99 data->rcdev.owner = THIS_MODULE;
100 data->rcdev.nr_resets = 32;
101 data->rcdev.ops = &oxnas_reset_ops;
102 data->rcdev.of_node = pdev->dev.of_node;
104 return devm_reset_controller_register(&pdev->dev, &data->rcdev);
107 static struct platform_driver oxnas_reset_driver = {
108 .probe = oxnas_reset_probe,
110 .name = "oxnas-reset",
111 .of_match_table = oxnas_reset_dt_ids,
114 builtin_platform_driver(oxnas_reset_driver);