OpenWrt – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | From 08c9d6ceef01893678a5d2e8a15517c745417f21 Mon Sep 17 00:00:00 2001 |
2 | From: John Crispin <john@phrozen.org> |
||
3 | Date: Tue, 6 Mar 2018 10:04:05 +0100 |
||
4 | Subject: [PATCH 04/27] phy: add ath79 usb phys |
||
5 | |||
6 | Signed-off-by: John Crispin <john@phrozen.org> |
||
7 | --- |
||
8 | drivers/phy/Kconfig | 16 ++++++ |
||
9 | drivers/phy/Makefile | 2 + |
||
10 | drivers/phy/phy-ar7100-usb.c | 124 +++++++++++++++++++++++++++++++++++++++++++ |
||
11 | drivers/phy/phy-ar7200-usb.c | 108 +++++++++++++++++++++++++++++++++++++ |
||
12 | 4 files changed, 250 insertions(+) |
||
13 | create mode 100644 drivers/phy/phy-ar7100-usb.c |
||
14 | create mode 100644 drivers/phy/phy-ar7200-usb.c |
||
15 | |||
16 | --- a/drivers/phy/Kconfig |
||
17 | +++ b/drivers/phy/Kconfig |
||
18 | @@ -15,6 +15,22 @@ config GENERIC_PHY |
||
19 | phy users can obtain reference to the PHY. All the users of this |
||
20 | framework should select this config. |
||
21 | |||
22 | +config PHY_AR7100_USB |
||
23 | + tristate "Atheros AR7100 USB PHY driver" |
||
24 | + depends on ATH79 || COMPILE_TEST |
||
25 | + default y if USB_EHCI_HCD_PLATFORM |
||
26 | + select PHY_SIMPLE |
||
27 | + help |
||
28 | + Enable this to support the USB PHY on Atheros AR7100 SoCs. |
||
29 | + |
||
30 | +config PHY_AR7200_USB |
||
31 | + tristate "Atheros AR7200 USB PHY driver" |
||
32 | + depends on ATH79 || COMPILE_TEST |
||
33 | + default y if USB_EHCI_HCD_PLATFORM |
||
34 | + select PHY_SIMPLE |
||
35 | + help |
||
36 | + Enable this to support the USB PHY on Atheros AR7200 SoCs. |
||
37 | + |
||
38 | config PHY_LPC18XX_USB_OTG |
||
39 | tristate "NXP LPC18xx/43xx SoC USB OTG PHY driver" |
||
40 | depends on OF && (ARCH_LPC18XX || COMPILE_TEST) |
||
41 | --- a/drivers/phy/Makefile |
||
42 | +++ b/drivers/phy/Makefile |
||
43 | @@ -4,6 +4,8 @@ |
||
44 | # |
||
45 | |||
46 | obj-$(CONFIG_GENERIC_PHY) += phy-core.o |
||
47 | +obj-$(CONFIG_PHY_AR7100_USB) += phy-ar7100-usb.o |
||
48 | +obj-$(CONFIG_PHY_AR7200_USB) += phy-ar7200-usb.o |
||
49 | obj-$(CONFIG_PHY_LPC18XX_USB_OTG) += phy-lpc18xx-usb-otg.o |
||
50 | obj-$(CONFIG_PHY_XGENE) += phy-xgene.o |
||
51 | obj-$(CONFIG_PHY_PISTACHIO_USB) += phy-pistachio-usb.o |
||
52 | --- /dev/null |
||
53 | +++ b/drivers/phy/phy-ar7100-usb.c |
||
54 | @@ -0,0 +1,140 @@ |
||
55 | +/* |
||
56 | + * Copyright (C) 2018 John Crispin <john@phrozen.org> |
||
57 | + * |
||
58 | + * This program is free software; you can redistribute it and/or modify |
||
59 | + * it under the terms of the GNU General Public License as published by |
||
60 | + * the Free Software Foundation; either version 2 of the License, or |
||
61 | + * (at your option) any later version. |
||
62 | + */ |
||
63 | + |
||
64 | +#include <linux/module.h> |
||
65 | +#include <linux/platform_device.h> |
||
66 | +#include <linux/phy/phy.h> |
||
67 | +#include <linux/delay.h> |
||
68 | +#include <linux/reset.h> |
||
69 | +#include <linux/of_gpio.h> |
||
70 | + |
||
71 | +#include <asm/mach-ath79/ath79.h> |
||
72 | +#include <asm/mach-ath79/ar71xx_regs.h> |
||
73 | + |
||
74 | +struct ar7100_usb_phy { |
||
75 | + struct reset_control *rst_phy; |
||
76 | + struct reset_control *rst_host; |
||
77 | + struct reset_control *rst_ohci_dll; |
||
78 | + void __iomem *io_base; |
||
79 | + struct phy *phy; |
||
80 | + int gpio; |
||
81 | +}; |
||
82 | + |
||
83 | +static int ar7100_usb_phy_power_off(struct phy *phy) |
||
84 | +{ |
||
85 | + struct ar7100_usb_phy *priv = phy_get_drvdata(phy); |
||
86 | + int err = 0; |
||
87 | + |
||
88 | + err |= reset_control_assert(priv->rst_host); |
||
89 | + err |= reset_control_assert(priv->rst_phy); |
||
90 | + err |= reset_control_assert(priv->rst_ohci_dll); |
||
91 | + |
||
92 | + return err; |
||
93 | +} |
||
94 | + |
||
95 | +static int ar7100_usb_phy_power_on(struct phy *phy) |
||
96 | +{ |
||
97 | + struct ar7100_usb_phy *priv = phy_get_drvdata(phy); |
||
98 | + int err = 0; |
||
99 | + |
||
100 | + err |= ar7100_usb_phy_power_off(phy); |
||
101 | + mdelay(100); |
||
102 | + err |= reset_control_deassert(priv->rst_ohci_dll); |
||
103 | + err |= reset_control_deassert(priv->rst_phy); |
||
104 | + err |= reset_control_deassert(priv->rst_host); |
||
105 | + mdelay(500); |
||
106 | + iowrite32(0xf0000, priv->io_base + AR71XX_USB_CTRL_REG_CONFIG); |
||
107 | + iowrite32(0x20c00, priv->io_base + AR71XX_USB_CTRL_REG_FLADJ); |
||
108 | + |
||
109 | + return err; |
||
110 | +} |
||
111 | + |
||
112 | +static const struct phy_ops ar7100_usb_phy_ops = { |
||
113 | + .power_on = ar7100_usb_phy_power_on, |
||
114 | + .power_off = ar7100_usb_phy_power_off, |
||
115 | + .owner = THIS_MODULE, |
||
116 | +}; |
||
117 | + |
||
118 | +static int ar7100_usb_phy_probe(struct platform_device *pdev) |
||
119 | +{ |
||
120 | + struct phy_provider *phy_provider; |
||
121 | + struct resource *res; |
||
122 | + struct ar7100_usb_phy *priv; |
||
123 | + |
||
124 | + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
||
125 | + if (!priv) |
||
126 | + return -ENOMEM; |
||
127 | + |
||
128 | + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
||
129 | + priv->io_base = devm_ioremap_resource(&pdev->dev, res); |
||
130 | + if (IS_ERR(priv->io_base)) |
||
131 | + return PTR_ERR(priv->io_base); |
||
132 | + |
||
133 | + priv->rst_phy = devm_reset_control_get(&pdev->dev, "usb-phy"); |
||
134 | + if (IS_ERR(priv->rst_phy)) { |
||
135 | + dev_err(&pdev->dev, "phy reset is missing\n"); |
||
136 | + return PTR_ERR(priv->rst_phy); |
||
137 | + } |
||
138 | + |
||
139 | + priv->rst_host = devm_reset_control_get(&pdev->dev, "usb-host"); |
||
140 | + if (IS_ERR(priv->rst_host)) { |
||
141 | + dev_err(&pdev->dev, "host reset is missing\n"); |
||
142 | + return PTR_ERR(priv->rst_host); |
||
143 | + } |
||
144 | + |
||
145 | + priv->rst_ohci_dll = devm_reset_control_get(&pdev->dev, "usb-ohci-dll"); |
||
146 | + if (IS_ERR(priv->rst_ohci_dll)) { |
||
147 | + dev_err(&pdev->dev, "ohci-dll reset is missing\n"); |
||
148 | + return PTR_ERR(priv->rst_host); |
||
149 | + } |
||
150 | + |
||
151 | + priv->phy = devm_phy_create(&pdev->dev, NULL, &ar7100_usb_phy_ops); |
||
152 | + if (IS_ERR(priv->phy)) { |
||
153 | + dev_err(&pdev->dev, "failed to create PHY\n"); |
||
154 | + return PTR_ERR(priv->phy); |
||
155 | + } |
||
156 | + |
||
157 | + priv->gpio = of_get_gpio(pdev->dev.of_node, 0); |
||
158 | + if (priv->gpio >= 0) { |
||
159 | + int ret = devm_gpio_request(&pdev->dev, priv->gpio, dev_name(&pdev->dev)); |
||
160 | + |
||
161 | + if (ret) { |
||
162 | + dev_err(&pdev->dev, "failed to request gpio\n"); |
||
163 | + return ret; |
||
164 | + } |
||
165 | + gpio_export_with_name(priv->gpio, 0, dev_name(&pdev->dev)); |
||
166 | + gpio_set_value(priv->gpio, 1); |
||
167 | + } |
||
168 | + |
||
169 | + phy_set_drvdata(priv->phy, priv); |
||
170 | + |
||
171 | + phy_provider = devm_of_phy_provider_register(&pdev->dev, of_phy_simple_xlate); |
||
172 | + |
||
173 | + |
||
174 | + return PTR_ERR_OR_ZERO(phy_provider); |
||
175 | +} |
||
176 | + |
||
177 | +static const struct of_device_id ar7100_usb_phy_of_match[] = { |
||
178 | + { .compatible = "qca,ar7100-usb-phy" }, |
||
179 | + {} |
||
180 | +}; |
||
181 | +MODULE_DEVICE_TABLE(of, ar7100_usb_phy_of_match); |
||
182 | + |
||
183 | +static struct platform_driver ar7100_usb_phy_driver = { |
||
184 | + .probe = ar7100_usb_phy_probe, |
||
185 | + .driver = { |
||
186 | + .of_match_table = ar7100_usb_phy_of_match, |
||
187 | + .name = "ar7100-usb-phy", |
||
188 | + } |
||
189 | +}; |
||
190 | +module_platform_driver(ar7100_usb_phy_driver); |
||
191 | + |
||
192 | +MODULE_DESCRIPTION("ATH79 USB PHY driver"); |
||
193 | +MODULE_AUTHOR("Alban Bedel <albeu@free.fr>"); |
||
194 | +MODULE_LICENSE("GPL"); |
||
195 | --- /dev/null |
||
196 | +++ b/drivers/phy/phy-ar7200-usb.c |
||
197 | @@ -0,0 +1,123 @@ |
||
198 | +/* |
||
199 | + * Copyright (C) 2015 Alban Bedel <albeu@free.fr> |
||
200 | + * |
||
201 | + * This program is free software; you can redistribute it and/or modify |
||
202 | + * it under the terms of the GNU General Public License as published by |
||
203 | + * the Free Software Foundation; either version 2 of the License, or |
||
204 | + * (at your option) any later version. |
||
205 | + */ |
||
206 | + |
||
207 | +#include <linux/module.h> |
||
208 | +#include <linux/platform_device.h> |
||
209 | +#include <linux/phy/phy.h> |
||
210 | +#include <linux/reset.h> |
||
211 | +#include <linux/of_gpio.h> |
||
212 | + |
||
213 | +struct ar7200_usb_phy { |
||
214 | + struct reset_control *rst_phy; |
||
215 | + struct reset_control *suspend_override; |
||
216 | + struct phy *phy; |
||
217 | + int gpio; |
||
218 | +}; |
||
219 | + |
||
220 | +static int ar7200_usb_phy_power_on(struct phy *phy) |
||
221 | +{ |
||
222 | + struct ar7200_usb_phy *priv = phy_get_drvdata(phy); |
||
223 | + int err = 0; |
||
224 | + |
||
225 | + if (priv->rst_phy) |
||
226 | + err = reset_control_deassert(priv->rst_phy); |
||
227 | + if (!err && priv->suspend_override) |
||
228 | + err = reset_control_assert(priv->suspend_override); |
||
229 | + if (err && priv->rst_phy) |
||
230 | + err = reset_control_assert(priv->rst_phy); |
||
231 | + |
||
232 | + return err; |
||
233 | +} |
||
234 | + |
||
235 | +static int ar7200_usb_phy_power_off(struct phy *phy) |
||
236 | +{ |
||
237 | + struct ar7200_usb_phy *priv = phy_get_drvdata(phy); |
||
238 | + int err = 0; |
||
239 | + |
||
240 | + if (priv->suspend_override) |
||
241 | + err = reset_control_deassert(priv->suspend_override); |
||
242 | + if (priv->rst_phy) |
||
243 | + err |= reset_control_assert(priv->rst_phy); |
||
244 | + |
||
245 | + return err; |
||
246 | +} |
||
247 | + |
||
248 | +static const struct phy_ops ar7200_usb_phy_ops = { |
||
249 | + .power_on = ar7200_usb_phy_power_on, |
||
250 | + .power_off = ar7200_usb_phy_power_off, |
||
251 | + .owner = THIS_MODULE, |
||
252 | +}; |
||
253 | + |
||
254 | +static int ar7200_usb_phy_probe(struct platform_device *pdev) |
||
255 | +{ |
||
256 | + struct phy_provider *phy_provider; |
||
257 | + struct ar7200_usb_phy *priv; |
||
258 | + |
||
259 | + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
||
260 | + if (!priv) |
||
261 | + return -ENOMEM; |
||
262 | + |
||
263 | + priv->rst_phy = devm_reset_control_get(&pdev->dev, "usb-phy"); |
||
264 | + if (IS_ERR(priv->rst_phy)) { |
||
265 | + dev_err(&pdev->dev, "phy reset is missing\n"); |
||
266 | + return PTR_ERR(priv->rst_phy); |
||
267 | + } |
||
268 | + |
||
269 | + priv->suspend_override = devm_reset_control_get_optional( |
||
270 | + &pdev->dev, "usb-suspend-override"); |
||
271 | + if (IS_ERR(priv->suspend_override)) { |
||
272 | + if (PTR_ERR(priv->suspend_override) == -ENOENT) |
||
273 | + priv->suspend_override = NULL; |
||
274 | + else |
||
275 | + return PTR_ERR(priv->suspend_override); |
||
276 | + } |
||
277 | + |
||
278 | + priv->phy = devm_phy_create(&pdev->dev, NULL, &ar7200_usb_phy_ops); |
||
279 | + if (IS_ERR(priv->phy)) { |
||
280 | + dev_err(&pdev->dev, "failed to create PHY\n"); |
||
281 | + return PTR_ERR(priv->phy); |
||
282 | + } |
||
283 | + |
||
284 | + priv->gpio = of_get_gpio(pdev->dev.of_node, 0); |
||
285 | + if (priv->gpio >= 0) { |
||
286 | + int ret = devm_gpio_request(&pdev->dev, priv->gpio, dev_name(&pdev->dev)); |
||
287 | + |
||
288 | + if (ret) { |
||
289 | + dev_err(&pdev->dev, "failed to request gpio\n"); |
||
290 | + return ret; |
||
291 | + } |
||
292 | + gpio_export_with_name(priv->gpio, 0, dev_name(&pdev->dev)); |
||
293 | + gpio_set_value(priv->gpio, 1); |
||
294 | + } |
||
295 | + |
||
296 | + phy_set_drvdata(priv->phy, priv); |
||
297 | + |
||
298 | + phy_provider = devm_of_phy_provider_register(&pdev->dev, of_phy_simple_xlate); |
||
299 | + |
||
300 | + return PTR_ERR_OR_ZERO(phy_provider); |
||
301 | +} |
||
302 | + |
||
303 | +static const struct of_device_id ar7200_usb_phy_of_match[] = { |
||
304 | + { .compatible = "qca,ar7200-usb-phy" }, |
||
305 | + {} |
||
306 | +}; |
||
307 | +MODULE_DEVICE_TABLE(of, ar7200_usb_phy_of_match); |
||
308 | + |
||
309 | +static struct platform_driver ar7200_usb_phy_driver = { |
||
310 | + .probe = ar7200_usb_phy_probe, |
||
311 | + .driver = { |
||
312 | + .of_match_table = ar7200_usb_phy_of_match, |
||
313 | + .name = "ar7200-usb-phy", |
||
314 | + } |
||
315 | +}; |
||
316 | +module_platform_driver(ar7200_usb_phy_driver); |
||
317 | + |
||
318 | +MODULE_DESCRIPTION("ATH79 USB PHY driver"); |
||
319 | +MODULE_AUTHOR("Alban Bedel <albeu@free.fr>"); |
||
320 | +MODULE_LICENSE("GPL"); |