blob: 15abac9fc72c074adaeec0a8f98ce73d1355d26a [file] [log] [blame]
Kunihiko Hayashi499fef02018-07-10 10:14:17 +09001// SPDX-License-Identifier: GPL-2.0
2//
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +09003// reset-uniphier-glue.c - Glue layer reset driver for UniPhier
Kunihiko Hayashi499fef02018-07-10 10:14:17 +09004// Copyright 2018 Socionext Inc.
5// Author: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
6
7#include <linux/clk.h>
8#include <linux/module.h>
9#include <linux/of_device.h>
10#include <linux/platform_device.h>
11#include <linux/reset.h>
Maxime Ripard9357b0462020-05-27 17:47:31 +020012#include <linux/reset/reset-simple.h>
Kunihiko Hayashi499fef02018-07-10 10:14:17 +090013
14#define MAX_CLKS 2
15#define MAX_RSTS 2
16
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +090017struct uniphier_glue_reset_soc_data {
Kunihiko Hayashi499fef02018-07-10 10:14:17 +090018 int nclks;
19 const char * const *clock_names;
20 int nrsts;
21 const char * const *reset_names;
22};
23
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +090024struct uniphier_glue_reset_priv {
Kunihiko Hayashi499fef02018-07-10 10:14:17 +090025 struct clk_bulk_data clk[MAX_CLKS];
Philipp Zabel176cae32021-12-15 10:38:28 +010026 struct reset_control_bulk_data rst[MAX_RSTS];
Kunihiko Hayashi499fef02018-07-10 10:14:17 +090027 struct reset_simple_data rdata;
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +090028 const struct uniphier_glue_reset_soc_data *data;
Kunihiko Hayashi499fef02018-07-10 10:14:17 +090029};
30
Philipp Zabel72bb7312021-12-15 10:38:29 +010031static void uniphier_clk_disable(void *_priv)
32{
33 struct uniphier_glue_reset_priv *priv = _priv;
34
35 clk_bulk_disable_unprepare(priv->data->nclks, priv->clk);
36}
37
38static void uniphier_rst_assert(void *_priv)
39{
40 struct uniphier_glue_reset_priv *priv = _priv;
41
42 reset_control_bulk_assert(priv->data->nrsts, priv->rst);
43}
44
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +090045static int uniphier_glue_reset_probe(struct platform_device *pdev)
Kunihiko Hayashi499fef02018-07-10 10:14:17 +090046{
47 struct device *dev = &pdev->dev;
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +090048 struct uniphier_glue_reset_priv *priv;
Kunihiko Hayashi499fef02018-07-10 10:14:17 +090049 struct resource *res;
Philipp Zabel176cae32021-12-15 10:38:28 +010050 int i, ret;
Kunihiko Hayashi499fef02018-07-10 10:14:17 +090051
52 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
53 if (!priv)
54 return -ENOMEM;
55
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))
59 return -EINVAL;
60
61 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Kunihiko Hayashi499fef02018-07-10 10:14:17 +090062 priv->rdata.membase = devm_ioremap_resource(dev, res);
63 if (IS_ERR(priv->rdata.membase))
64 return PTR_ERR(priv->rdata.membase);
65
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);
69 if (ret)
70 return ret;
71
Philipp Zabel176cae32021-12-15 10:38:28 +010072 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,
75 priv->rst);
76 if (ret)
77 return ret;
Kunihiko Hayashi499fef02018-07-10 10:14:17 +090078
79 ret = clk_bulk_prepare_enable(priv->data->nclks, priv->clk);
80 if (ret)
81 return ret;
82
Philipp Zabel72bb7312021-12-15 10:38:29 +010083 ret = devm_add_action_or_reset(dev, uniphier_clk_disable, priv);
84 if (ret)
85 return ret;
86
Philipp Zabel176cae32021-12-15 10:38:28 +010087 ret = reset_control_bulk_deassert(priv->data->nrsts, priv->rst);
88 if (ret)
Philipp Zabel72bb7312021-12-15 10:38:29 +010089 return ret;
90
91 ret = devm_add_action_or_reset(dev, uniphier_rst_assert, priv);
92 if (ret)
93 return ret;
Kunihiko Hayashi499fef02018-07-10 10:14:17 +090094
95 spin_lock_init(&priv->rdata.lock);
96 priv->rdata.rcdev.owner = THIS_MODULE;
Hui Tang3a2390c2022-11-14 08:49:58 +080097 priv->rdata.rcdev.nr_resets = resource_size(res) * BITS_PER_BYTE;
Kunihiko Hayashi499fef02018-07-10 10:14:17 +090098 priv->rdata.rcdev.ops = &reset_simple_ops;
99 priv->rdata.rcdev.of_node = dev->of_node;
100 priv->rdata.active_low = true;
101
102 platform_set_drvdata(pdev, priv);
103
Philipp Zabel72bb7312021-12-15 10:38:29 +0100104 return devm_reset_controller_register(dev, &priv->rdata.rcdev);
Kunihiko Hayashi499fef02018-07-10 10:14:17 +0900105}
106
107static const char * const uniphier_pro4_clock_reset_names[] = {
108 "gio", "link",
109};
110
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +0900111static const struct uniphier_glue_reset_soc_data uniphier_pro4_data = {
Kunihiko Hayashi499fef02018-07-10 10:14:17 +0900112 .nclks = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
113 .clock_names = uniphier_pro4_clock_reset_names,
114 .nrsts = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
115 .reset_names = uniphier_pro4_clock_reset_names,
116};
117
118static const char * const uniphier_pxs2_clock_reset_names[] = {
119 "link",
120};
121
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +0900122static const struct uniphier_glue_reset_soc_data uniphier_pxs2_data = {
Kunihiko Hayashi499fef02018-07-10 10:14:17 +0900123 .nclks = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
124 .clock_names = uniphier_pxs2_clock_reset_names,
125 .nrsts = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
126 .reset_names = uniphier_pxs2_clock_reset_names,
127};
128
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +0900129static const struct of_device_id uniphier_glue_reset_match[] = {
Kunihiko Hayashi499fef02018-07-10 10:14:17 +0900130 {
131 .compatible = "socionext,uniphier-pro4-usb3-reset",
132 .data = &uniphier_pro4_data,
133 },
134 {
Kunihiko Hayashi8c2def02019-09-10 10:55:27 +0900135 .compatible = "socionext,uniphier-pro5-usb3-reset",
136 .data = &uniphier_pro4_data,
137 },
138 {
Kunihiko Hayashi499fef02018-07-10 10:14:17 +0900139 .compatible = "socionext,uniphier-pxs2-usb3-reset",
140 .data = &uniphier_pxs2_data,
141 },
142 {
143 .compatible = "socionext,uniphier-ld20-usb3-reset",
144 .data = &uniphier_pxs2_data,
145 },
146 {
147 .compatible = "socionext,uniphier-pxs3-usb3-reset",
148 .data = &uniphier_pxs2_data,
149 },
Kunihiko Hayashid0c2d212018-11-09 10:42:07 +0900150 {
Kunihiko Hayashi3440b8f2021-10-05 11:10:42 +0900151 .compatible = "socionext,uniphier-nx1-usb3-reset",
152 .data = &uniphier_pxs2_data,
153 },
154 {
Kunihiko Hayashid0c2d212018-11-09 10:42:07 +0900155 .compatible = "socionext,uniphier-pro4-ahci-reset",
156 .data = &uniphier_pro4_data,
157 },
158 {
159 .compatible = "socionext,uniphier-pxs2-ahci-reset",
160 .data = &uniphier_pxs2_data,
161 },
162 {
163 .compatible = "socionext,uniphier-pxs3-ahci-reset",
164 .data = &uniphier_pxs2_data,
165 },
Kunihiko Hayashi499fef02018-07-10 10:14:17 +0900166 { /* Sentinel */ }
167};
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +0900168MODULE_DEVICE_TABLE(of, uniphier_glue_reset_match);
Kunihiko Hayashi499fef02018-07-10 10:14:17 +0900169
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +0900170static struct platform_driver uniphier_glue_reset_driver = {
171 .probe = uniphier_glue_reset_probe,
Kunihiko Hayashi499fef02018-07-10 10:14:17 +0900172 .driver = {
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +0900173 .name = "uniphier-glue-reset",
174 .of_match_table = uniphier_glue_reset_match,
Kunihiko Hayashi499fef02018-07-10 10:14:17 +0900175 },
176};
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +0900177module_platform_driver(uniphier_glue_reset_driver);
Kunihiko Hayashi499fef02018-07-10 10:14:17 +0900178
179MODULE_AUTHOR("Kunihiko Hayashi <hayashi.kunihiko@socionext.com>");
Kunihiko Hayashi3eb8f762018-11-09 10:42:05 +0900180MODULE_DESCRIPTION("UniPhier Glue layer reset driver");
Kunihiko Hayashi499fef02018-07-10 10:14:17 +0900181MODULE_LICENSE("GPL");