1 // SPDX-License-Identifier: GPL-2.0
3 // reset-uniphier-glue.c - Glue layer reset driver for UniPhier
4 // Copyright 2018 Socionext Inc.
5 // Author: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
8 #include <linux/module.h>
9 #include <linux/of_device.h>
10 #include <linux/platform_device.h>
11 #include <linux/reset.h>
12 #include <linux/reset/reset-simple.h>
17 struct uniphier_glue_reset_soc_data {
19 const char * const *clock_names;
21 const char * const *reset_names;
24 struct uniphier_glue_reset_priv {
25 struct clk_bulk_data clk[MAX_CLKS];
26 struct reset_control *rst[MAX_RSTS];
27 struct reset_simple_data rdata;
28 const struct uniphier_glue_reset_soc_data *data;
31 static int uniphier_glue_reset_probe(struct platform_device *pdev)
33 struct device *dev = &pdev->dev;
34 struct uniphier_glue_reset_priv *priv;
40 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
44 priv->data = of_device_get_match_data(dev);
45 if (WARN_ON(!priv->data || priv->data->nclks > MAX_CLKS ||
46 priv->data->nrsts > MAX_RSTS))
49 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
50 size = resource_size(res);
51 priv->rdata.membase = devm_ioremap_resource(dev, res);
52 if (IS_ERR(priv->rdata.membase))
53 return PTR_ERR(priv->rdata.membase);
55 for (i = 0; i < priv->data->nclks; i++)
56 priv->clk[i].id = priv->data->clock_names[i];
57 ret = devm_clk_bulk_get(dev, priv->data->nclks, priv->clk);
61 for (i = 0; i < priv->data->nrsts; i++) {
62 name = priv->data->reset_names[i];
63 priv->rst[i] = devm_reset_control_get_shared(dev, name);
64 if (IS_ERR(priv->rst[i]))
65 return PTR_ERR(priv->rst[i]);
68 ret = clk_bulk_prepare_enable(priv->data->nclks, priv->clk);
72 for (nr = 0; nr < priv->data->nrsts; nr++) {
73 ret = reset_control_deassert(priv->rst[nr]);
78 spin_lock_init(&priv->rdata.lock);
79 priv->rdata.rcdev.owner = THIS_MODULE;
80 priv->rdata.rcdev.nr_resets = size * BITS_PER_BYTE;
81 priv->rdata.rcdev.ops = &reset_simple_ops;
82 priv->rdata.rcdev.of_node = dev->of_node;
83 priv->rdata.active_low = true;
85 platform_set_drvdata(pdev, priv);
87 ret = devm_reset_controller_register(dev, &priv->rdata.rcdev);
95 reset_control_assert(priv->rst[nr]);
97 clk_bulk_disable_unprepare(priv->data->nclks, priv->clk);
102 static int uniphier_glue_reset_remove(struct platform_device *pdev)
104 struct uniphier_glue_reset_priv *priv = platform_get_drvdata(pdev);
107 for (i = 0; i < priv->data->nrsts; i++)
108 reset_control_assert(priv->rst[i]);
110 clk_bulk_disable_unprepare(priv->data->nclks, priv->clk);
115 static const char * const uniphier_pro4_clock_reset_names[] = {
119 static const struct uniphier_glue_reset_soc_data uniphier_pro4_data = {
120 .nclks = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
121 .clock_names = uniphier_pro4_clock_reset_names,
122 .nrsts = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
123 .reset_names = uniphier_pro4_clock_reset_names,
126 static const char * const uniphier_pxs2_clock_reset_names[] = {
130 static const struct uniphier_glue_reset_soc_data uniphier_pxs2_data = {
131 .nclks = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
132 .clock_names = uniphier_pxs2_clock_reset_names,
133 .nrsts = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
134 .reset_names = uniphier_pxs2_clock_reset_names,
137 static const struct of_device_id uniphier_glue_reset_match[] = {
139 .compatible = "socionext,uniphier-pro4-usb3-reset",
140 .data = &uniphier_pro4_data,
143 .compatible = "socionext,uniphier-pro5-usb3-reset",
144 .data = &uniphier_pro4_data,
147 .compatible = "socionext,uniphier-pxs2-usb3-reset",
148 .data = &uniphier_pxs2_data,
151 .compatible = "socionext,uniphier-ld20-usb3-reset",
152 .data = &uniphier_pxs2_data,
155 .compatible = "socionext,uniphier-pxs3-usb3-reset",
156 .data = &uniphier_pxs2_data,
159 .compatible = "socionext,uniphier-pro4-ahci-reset",
160 .data = &uniphier_pro4_data,
163 .compatible = "socionext,uniphier-pxs2-ahci-reset",
164 .data = &uniphier_pxs2_data,
167 .compatible = "socionext,uniphier-pxs3-ahci-reset",
168 .data = &uniphier_pxs2_data,
172 MODULE_DEVICE_TABLE(of, uniphier_glue_reset_match);
174 static struct platform_driver uniphier_glue_reset_driver = {
175 .probe = uniphier_glue_reset_probe,
176 .remove = uniphier_glue_reset_remove,
178 .name = "uniphier-glue-reset",
179 .of_match_table = uniphier_glue_reset_match,
182 module_platform_driver(uniphier_glue_reset_driver);
184 MODULE_AUTHOR("Kunihiko Hayashi <hayashi.kunihiko@socionext.com>");
185 MODULE_DESCRIPTION("UniPhier Glue layer reset driver");
186 MODULE_LICENSE("GPL");