Skip to content

Commit 499fef0

Browse files
khayash1pH5
authored andcommitted
reset: uniphier: add USB3 core reset control
Add a reset line to enable USB3 core implemented in UniPhier SoCs. This reuses only the reset operations in reset-simple, because the reset-simple doesn't handle any SoC-dependent clocks and resets. This reset line is included in the USB3 glue layer, and it's necessary to enable clocks and deassert resets of the layer before using this reset line. Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
1 parent ef8b023 commit 499fef0

3 files changed

Lines changed: 182 additions & 0 deletions

File tree

‎drivers/reset/Kconfig‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ config RESET_UNIPHIER
147147
Say Y if you want to control reset signals provided by System Control
148148
block, Media I/O block, Peripheral Block.
149149

150+
config RESET_UNIPHIER_USB3
151+
tristate "USB3 reset driver for UniPhier SoCs"
152+
depends on (ARCH_UNIPHIER || COMPILE_TEST) && OF
153+
default ARCH_UNIPHIER
154+
select RESET_SIMPLE
155+
help
156+
Support for the USB3 core reset on UniPhier SoCs.
157+
Say Y if you want to control reset signals provided by
158+
USB3 glue layer.
159+
150160
config RESET_ZYNQ
151161
bool "ZYNQ Reset Driver" if COMPILE_TEST
152162
default ARCH_ZYNQ

‎drivers/reset/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ obj-$(CONFIG_RESET_SUNXI) += reset-sunxi.o
2121
obj-$(CONFIG_RESET_TI_SCI) += reset-ti-sci.o
2222
obj-$(CONFIG_RESET_TI_SYSCON) += reset-ti-syscon.o
2323
obj-$(CONFIG_RESET_UNIPHIER) += reset-uniphier.o
24+
obj-$(CONFIG_RESET_UNIPHIER_USB3) += reset-uniphier-usb3.o
2425
obj-$(CONFIG_RESET_ZYNQ) += reset-zynq.o
2526

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
//
3+
// reset-uniphier-usb3.c - USB3 reset driver for UniPhier
4+
// 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>
12+
13+
#include "reset-simple.h"
14+
15+
#define MAX_CLKS 2
16+
#define MAX_RSTS 2
17+
18+
struct uniphier_usb3_reset_soc_data {
19+
int nclks;
20+
const char * const *clock_names;
21+
int nrsts;
22+
const char * const *reset_names;
23+
};
24+
25+
struct uniphier_usb3_reset_priv {
26+
struct clk_bulk_data clk[MAX_CLKS];
27+
struct reset_control *rst[MAX_RSTS];
28+
struct reset_simple_data rdata;
29+
const struct uniphier_usb3_reset_soc_data *data;
30+
};
31+
32+
static int uniphier_usb3_reset_probe(struct platform_device *pdev)
33+
{
34+
struct device *dev = &pdev->dev;
35+
struct uniphier_usb3_reset_priv *priv;
36+
struct resource *res;
37+
resource_size_t size;
38+
const char *name;
39+
int i, ret, nr;
40+
41+
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
42+
if (!priv)
43+
return -ENOMEM;
44+
45+
priv->data = of_device_get_match_data(dev);
46+
if (WARN_ON(!priv->data || priv->data->nclks > MAX_CLKS ||
47+
priv->data->nrsts > MAX_RSTS))
48+
return -EINVAL;
49+
50+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
51+
size = resource_size(res);
52+
priv->rdata.membase = devm_ioremap_resource(dev, res);
53+
if (IS_ERR(priv->rdata.membase))
54+
return PTR_ERR(priv->rdata.membase);
55+
56+
for (i = 0; i < priv->data->nclks; i++)
57+
priv->clk[i].id = priv->data->clock_names[i];
58+
ret = devm_clk_bulk_get(dev, priv->data->nclks, priv->clk);
59+
if (ret)
60+
return ret;
61+
62+
for (i = 0; i < priv->data->nrsts; i++) {
63+
name = priv->data->reset_names[i];
64+
priv->rst[i] = devm_reset_control_get_shared(dev, name);
65+
if (IS_ERR(priv->rst[i]))
66+
return PTR_ERR(priv->rst[i]);
67+
}
68+
69+
ret = clk_bulk_prepare_enable(priv->data->nclks, priv->clk);
70+
if (ret)
71+
return ret;
72+
73+
for (nr = 0; nr < priv->data->nrsts; nr++) {
74+
ret = reset_control_deassert(priv->rst[nr]);
75+
if (ret)
76+
goto out_rst_assert;
77+
}
78+
79+
spin_lock_init(&priv->rdata.lock);
80+
priv->rdata.rcdev.owner = THIS_MODULE;
81+
priv->rdata.rcdev.nr_resets = size * BITS_PER_BYTE;
82+
priv->rdata.rcdev.ops = &reset_simple_ops;
83+
priv->rdata.rcdev.of_node = dev->of_node;
84+
priv->rdata.active_low = true;
85+
86+
platform_set_drvdata(pdev, priv);
87+
88+
ret = devm_reset_controller_register(dev, &priv->rdata.rcdev);
89+
if (ret)
90+
goto out_rst_assert;
91+
92+
return 0;
93+
94+
out_rst_assert:
95+
while (nr--)
96+
reset_control_assert(priv->rst[nr]);
97+
98+
clk_bulk_disable_unprepare(priv->data->nclks, priv->clk);
99+
100+
return ret;
101+
}
102+
103+
static int uniphier_usb3_reset_remove(struct platform_device *pdev)
104+
{
105+
struct uniphier_usb3_reset_priv *priv = platform_get_drvdata(pdev);
106+
int i;
107+
108+
for (i = 0; i < priv->data->nrsts; i++)
109+
reset_control_assert(priv->rst[i]);
110+
111+
clk_bulk_disable_unprepare(priv->data->nclks, priv->clk);
112+
113+
return 0;
114+
}
115+
116+
static const char * const uniphier_pro4_clock_reset_names[] = {
117+
"gio", "link",
118+
};
119+
120+
static const struct uniphier_usb3_reset_soc_data uniphier_pro4_data = {
121+
.nclks = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
122+
.clock_names = uniphier_pro4_clock_reset_names,
123+
.nrsts = ARRAY_SIZE(uniphier_pro4_clock_reset_names),
124+
.reset_names = uniphier_pro4_clock_reset_names,
125+
};
126+
127+
static const char * const uniphier_pxs2_clock_reset_names[] = {
128+
"link",
129+
};
130+
131+
static const struct uniphier_usb3_reset_soc_data uniphier_pxs2_data = {
132+
.nclks = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
133+
.clock_names = uniphier_pxs2_clock_reset_names,
134+
.nrsts = ARRAY_SIZE(uniphier_pxs2_clock_reset_names),
135+
.reset_names = uniphier_pxs2_clock_reset_names,
136+
};
137+
138+
static const struct of_device_id uniphier_usb3_reset_match[] = {
139+
{
140+
.compatible = "socionext,uniphier-pro4-usb3-reset",
141+
.data = &uniphier_pro4_data,
142+
},
143+
{
144+
.compatible = "socionext,uniphier-pxs2-usb3-reset",
145+
.data = &uniphier_pxs2_data,
146+
},
147+
{
148+
.compatible = "socionext,uniphier-ld20-usb3-reset",
149+
.data = &uniphier_pxs2_data,
150+
},
151+
{
152+
.compatible = "socionext,uniphier-pxs3-usb3-reset",
153+
.data = &uniphier_pxs2_data,
154+
},
155+
{ /* Sentinel */ }
156+
};
157+
MODULE_DEVICE_TABLE(of, uniphier_usb3_reset_match);
158+
159+
static struct platform_driver uniphier_usb3_reset_driver = {
160+
.probe = uniphier_usb3_reset_probe,
161+
.remove = uniphier_usb3_reset_remove,
162+
.driver = {
163+
.name = "uniphier-usb3-reset",
164+
.of_match_table = uniphier_usb3_reset_match,
165+
},
166+
};
167+
module_platform_driver(uniphier_usb3_reset_driver);
168+
169+
MODULE_AUTHOR("Kunihiko Hayashi <hayashi.kunihiko@socionext.com>");
170+
MODULE_DESCRIPTION("UniPhier USB3 Reset Driver");
171+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)