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>
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_bulk_data rst[MAX_RSTS];
27 struct reset_simple_data rdata;
28 const struct uniphier_glue_reset_soc_data *data;
31 static void uniphier_clk_disable(void *_priv)
33 struct uniphier_glue_reset_priv *priv = _priv;
35 clk_bulk_disable_unprepare(priv->data->nclks, priv->clk);
38 static void uniphier_rst_assert(void *_priv)
40 struct uniphier_glue_reset_priv *priv = _priv;
42 reset_control_bulk_assert(priv->data->nrsts, priv->rst);
45 static int uniphier_glue_reset_probe(struct platform_device *pdev)
47 struct device *dev = &pdev->dev;
48 struct uniphier_glue_reset_priv *priv;
52 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
56 priv->data = of_device_get_match_data(dev);
57 if (WARN_ON(!priv->data || priv->data->nclks > MAX_CLKS ||
58 priv->data->nrsts > MAX_RSTS))
61 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
62 priv->rdata.membase = devm_ioremap_resource(dev, res);
63 if (IS_ERR(priv->rdata.membase))
64 return PTR_ERR(priv->rdata.membase);
66 for (i = 0; i < priv->data->nclks; i++)
67 priv->clk[i].id = priv->data->clock_names[i];
68 ret = devm_clk_bulk_get(dev, priv->data->nclks, priv->clk);
72 for (i = 0; i < priv->data->nrsts; i++)
73 priv->rst[i].id = priv->data->reset_names[i];
74 ret = devm_reset_control_bulk_get_shared(dev, priv->data->nrsts,
79 ret = clk_bulk_prepare_enable(priv->data->nclks, priv->clk);
83 ret = devm_add_action_or_reset(dev, uniphier_clk_disable, priv);
87 ret = reset_control_bulk_deassert(priv->data->nrsts, priv->rst);
91 ret = devm_add_action_or_reset(dev, uniphier_rst_assert, priv);
95 spin_lock_init(&priv->rdata.lock);
96 priv->rdata.rcdev.owner = THIS_MODULE;
97 priv->rdata.rcdev.nr_resets = resource_size(res) * BITS_PER_BYTE;
98 priv->rdata.rcdev.ops = &reset_simple_ops;
99 priv->rdata.rcdev.of_node = dev->of_node;
100 priv->rdata.active_low = true;
102 return devm_reset_controller_register(dev, &priv->rdata.rcdev);
105 static const char * const uniphier_pro4_clock_reset_names[] = {
109 static const struct uniphier_glue_reset_soc_data uniphier_pro4_data = {
110 .nclks = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
111 .clock_names = uniphier_pro4_clock_reset_names,
112 .nrsts = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
113 .reset_names = uniphier_pro4_clock_reset_names,
116 static const char * const uniphier_pxs2_clock_reset_names[] = {
120 static const struct uniphier_glue_reset_soc_data uniphier_pxs2_data = {
121 .nclks = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
122 .clock_names = uniphier_pxs2_clock_reset_names,
123 .nrsts = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
124 .reset_names = uniphier_pxs2_clock_reset_names,
127 static const struct of_device_id uniphier_glue_reset_match[] = {
129 .compatible = "socionext,uniphier-pro4-usb3-reset",
130 .data = &uniphier_pro4_data,
133 .compatible = "socionext,uniphier-pro5-usb3-reset",
134 .data = &uniphier_pro4_data,
137 .compatible = "socionext,uniphier-pxs2-usb3-reset",
138 .data = &uniphier_pxs2_data,
141 .compatible = "socionext,uniphier-ld20-usb3-reset",
142 .data = &uniphier_pxs2_data,
145 .compatible = "socionext,uniphier-pxs3-usb3-reset",
146 .data = &uniphier_pxs2_data,
149 .compatible = "socionext,uniphier-nx1-usb3-reset",
150 .data = &uniphier_pxs2_data,
153 .compatible = "socionext,uniphier-pro4-ahci-reset",
154 .data = &uniphier_pro4_data,
157 .compatible = "socionext,uniphier-pxs2-ahci-reset",
158 .data = &uniphier_pxs2_data,
161 .compatible = "socionext,uniphier-pxs3-ahci-reset",
162 .data = &uniphier_pxs2_data,
166 MODULE_DEVICE_TABLE(of, uniphier_glue_reset_match);
168 static struct platform_driver uniphier_glue_reset_driver = {
169 .probe = uniphier_glue_reset_probe,
171 .name = "uniphier-glue-reset",
172 .of_match_table = uniphier_glue_reset_match,
175 module_platform_driver(uniphier_glue_reset_driver);
177 MODULE_AUTHOR("Kunihiko Hayashi <hayashi.kunihiko@socionext.com>");
178 MODULE_DESCRIPTION("UniPhier Glue layer reset driver");
179 MODULE_LICENSE("GPL");