1 // SPDX-License-Identifier: GPL-2.0
3 // reset-uniphier-glue.c - Glue layer reset driver for UniPhier
4 // Copyright 2018 Socionext Inc.
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 int uniphier_glue_reset_probe(struct platform_device *pdev)
40 struct device *dev = &pdev->dev;
41 struct uniphier_glue_reset_priv *priv;
45 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
49 priv->data = of_device_get_match_data(dev);
50 if (WARN_ON(!priv->data || priv->data->nclks > MAX_CLKS ||
51 priv->data->nrsts > MAX_RSTS))
54 priv->rdata.membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
55 if (IS_ERR(priv->rdata.membase))
56 return PTR_ERR(priv->rdata.membase);
58 for (i = 0; i < priv->data->nclks; i++)
59 priv->clk[i].id = priv->data->clock_names[i];
60 ret = devm_clk_bulk_get(dev, priv->data->nclks, priv->clk);
64 ret = clk_bulk_prepare_enable(priv->data->nclks, priv->clk);
68 ret = devm_add_action_or_reset(dev, uniphier_clk_disable, priv);
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_deasserted(dev,
80 spin_lock_init(&priv->rdata.lock);
81 priv->rdata.rcdev.owner = THIS_MODULE;
82 priv->rdata.rcdev.nr_resets = resource_size(res) * BITS_PER_BYTE;
83 priv->rdata.rcdev.ops = &reset_simple_ops;
84 priv->rdata.rcdev.of_node = dev->of_node;
85 priv->rdata.active_low = true;
87 return devm_reset_controller_register(dev, &priv->rdata.rcdev);
90 static const char * const uniphier_pro4_clock_reset_names[] = {
94 static const struct uniphier_glue_reset_soc_data uniphier_pro4_data = {
95 .nclks = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
96 .clock_names = uniphier_pro4_clock_reset_names,
97 .nrsts = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
98 .reset_names = uniphier_pro4_clock_reset_names,
101 static const char * const uniphier_pxs2_clock_reset_names[] = {
105 static const struct uniphier_glue_reset_soc_data uniphier_pxs2_data = {
106 .nclks = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
107 .clock_names = uniphier_pxs2_clock_reset_names,
108 .nrsts = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
109 .reset_names = uniphier_pxs2_clock_reset_names,
112 static const struct of_device_id uniphier_glue_reset_match[] = {
114 .compatible = "socionext,uniphier-pro4-usb3-reset",
115 .data = &uniphier_pro4_data,
118 .compatible = "socionext,uniphier-pro5-usb3-reset",
119 .data = &uniphier_pro4_data,
122 .compatible = "socionext,uniphier-pxs2-usb3-reset",
123 .data = &uniphier_pxs2_data,
126 .compatible = "socionext,uniphier-ld20-usb3-reset",
127 .data = &uniphier_pxs2_data,
130 .compatible = "socionext,uniphier-pxs3-usb3-reset",
131 .data = &uniphier_pxs2_data,
134 .compatible = "socionext,uniphier-nx1-usb3-reset",
135 .data = &uniphier_pxs2_data,
138 .compatible = "socionext,uniphier-pro4-ahci-reset",
139 .data = &uniphier_pro4_data,
142 .compatible = "socionext,uniphier-pxs2-ahci-reset",
143 .data = &uniphier_pxs2_data,
146 .compatible = "socionext,uniphier-pxs3-ahci-reset",
147 .data = &uniphier_pxs2_data,
151 MODULE_DEVICE_TABLE(of, uniphier_glue_reset_match);
153 static struct platform_driver uniphier_glue_reset_driver = {
154 .probe = uniphier_glue_reset_probe,
156 .name = "uniphier-glue-reset",
157 .of_match_table = uniphier_glue_reset_match,
160 module_platform_driver(uniphier_glue_reset_driver);
163 MODULE_DESCRIPTION("UniPhier Glue layer reset driver");
164 MODULE_LICENSE("GPL");