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
6 Signed-off-by: John Crispin <john@phrozen.org>
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
16 --- a/drivers/phy/Kconfig
17 +++ b/drivers/phy/Kconfig
18 @@ -24,6 +24,22 @@ config GENERIC_PHY_MIPI_DPHY
19 Provides a number of helpers a core functions for MIPI D-PHY
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
28 + Enable this to support the USB PHY on Atheros AR7100 SoCs.
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
36 + Enable this to support the USB PHY on Atheros AR7200 SoCs.
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
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_GENERIC_PHY_MIPI_DPHY) += phy-core-mipi-dphy.o
50 obj-$(CONFIG_PHY_LPC18XX_USB_OTG) += phy-lpc18xx-usb-otg.o
51 obj-$(CONFIG_PHY_XGENE) += phy-xgene.o
53 +++ b/drivers/phy/phy-ar7100-usb.c
56 + * Copyright (C) 2018 John Crispin <john@phrozen.org>
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.
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>
71 +#include <asm/mach-ath79/ath79.h>
72 +#include <asm/mach-ath79/ar71xx_regs.h>
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;
83 +static int ar7100_usb_phy_power_off(struct phy *phy)
85 + struct ar7100_usb_phy *priv = phy_get_drvdata(phy);
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);
95 +static int ar7100_usb_phy_power_on(struct phy *phy)
97 + struct ar7100_usb_phy *priv = phy_get_drvdata(phy);
100 + err |= ar7100_usb_phy_power_off(phy);
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);
106 + iowrite32(0xf0000, priv->io_base + AR71XX_USB_CTRL_REG_CONFIG);
107 + iowrite32(0x20c00, priv->io_base + AR71XX_USB_CTRL_REG_FLADJ);
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,
118 +static int ar7100_usb_phy_probe(struct platform_device *pdev)
120 + struct phy_provider *phy_provider;
121 + struct resource *res;
122 + struct ar7100_usb_phy *priv;
124 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
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);
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);
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);
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);
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);
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));
162 + dev_err(&pdev->dev, "failed to request gpio\n");
165 + gpio_export_with_name(priv->gpio, 0, dev_name(&pdev->dev));
166 + gpio_set_value(priv->gpio, 1);
169 + phy_set_drvdata(priv->phy, priv);
171 + phy_provider = devm_of_phy_provider_register(&pdev->dev, of_phy_simple_xlate);
174 + return PTR_ERR_OR_ZERO(phy_provider);
177 +static const struct of_device_id ar7100_usb_phy_of_match[] = {
178 + { .compatible = "qca,ar7100-usb-phy" },
181 +MODULE_DEVICE_TABLE(of, ar7100_usb_phy_of_match);
183 +static struct platform_driver ar7100_usb_phy_driver = {
184 + .probe = ar7100_usb_phy_probe,
186 + .of_match_table = ar7100_usb_phy_of_match,
187 + .name = "ar7100-usb-phy",
190 +module_platform_driver(ar7100_usb_phy_driver);
192 +MODULE_DESCRIPTION("ATH79 USB PHY driver");
193 +MODULE_AUTHOR("Alban Bedel <albeu@free.fr>");
194 +MODULE_LICENSE("GPL");
196 +++ b/drivers/phy/phy-ar7200-usb.c
199 + * Copyright (C) 2015 Alban Bedel <albeu@free.fr>
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.
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>
213 +struct ar7200_usb_phy {
214 + struct reset_control *rst_phy;
215 + struct reset_control *rst_phy_analog;
216 + struct reset_control *suspend_override;
221 +static int ar7200_usb_phy_power_on(struct phy *phy)
223 + struct ar7200_usb_phy *priv = phy_get_drvdata(phy);
226 + if (priv->suspend_override)
227 + err = reset_control_assert(priv->suspend_override);
229 + err |= reset_control_deassert(priv->rst_phy);
230 + if (priv->rst_phy_analog)
231 + err |= reset_control_deassert(priv->rst_phy_analog);
236 +static int ar7200_usb_phy_power_off(struct phy *phy)
238 + struct ar7200_usb_phy *priv = phy_get_drvdata(phy);
241 + if (priv->suspend_override)
242 + err = reset_control_deassert(priv->suspend_override);
244 + err |= reset_control_assert(priv->rst_phy);
245 + if (priv->rst_phy_analog)
246 + err |= reset_control_assert(priv->rst_phy_analog);
251 +static const struct phy_ops ar7200_usb_phy_ops = {
252 + .power_on = ar7200_usb_phy_power_on,
253 + .power_off = ar7200_usb_phy_power_off,
254 + .owner = THIS_MODULE,
257 +static int ar7200_usb_phy_probe(struct platform_device *pdev)
259 + struct phy_provider *phy_provider;
260 + struct ar7200_usb_phy *priv;
262 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
266 + priv->rst_phy = devm_reset_control_get(&pdev->dev, "usb-phy");
267 + if (IS_ERR(priv->rst_phy)) {
268 + if (PTR_ERR(priv->rst_phy) != -EPROBE_DEFER)
269 + dev_err(&pdev->dev, "phy reset is missing\n");
270 + return PTR_ERR(priv->rst_phy);
273 + priv->rst_phy_analog = devm_reset_control_get_optional(
274 + &pdev->dev, "usb-phy-analog");
275 + if (IS_ERR(priv->rst_phy_analog)) {
276 + if (PTR_ERR(priv->rst_phy_analog) == -ENOENT)
277 + priv->rst_phy_analog = NULL;
279 + return PTR_ERR(priv->rst_phy_analog);
282 + priv->suspend_override = devm_reset_control_get_optional(
283 + &pdev->dev, "usb-suspend-override");
284 + if (IS_ERR(priv->suspend_override)) {
285 + if (PTR_ERR(priv->suspend_override) == -ENOENT)
286 + priv->suspend_override = NULL;
288 + return PTR_ERR(priv->suspend_override);
291 + priv->phy = devm_phy_create(&pdev->dev, NULL, &ar7200_usb_phy_ops);
292 + if (IS_ERR(priv->phy)) {
293 + dev_err(&pdev->dev, "failed to create PHY\n");
294 + return PTR_ERR(priv->phy);
297 + priv->gpio = of_get_gpio(pdev->dev.of_node, 0);
298 + if (priv->gpio >= 0) {
299 + int ret = devm_gpio_request(&pdev->dev, priv->gpio, dev_name(&pdev->dev));
302 + dev_err(&pdev->dev, "failed to request gpio\n");
305 + gpio_export_with_name(priv->gpio, 0, dev_name(&pdev->dev));
306 + gpio_set_value(priv->gpio, 1);
309 + phy_set_drvdata(priv->phy, priv);
311 + phy_provider = devm_of_phy_provider_register(&pdev->dev, of_phy_simple_xlate);
313 + return PTR_ERR_OR_ZERO(phy_provider);
316 +static const struct of_device_id ar7200_usb_phy_of_match[] = {
317 + { .compatible = "qca,ar7200-usb-phy" },
320 +MODULE_DEVICE_TABLE(of, ar7200_usb_phy_of_match);
322 +static struct platform_driver ar7200_usb_phy_driver = {
323 + .probe = ar7200_usb_phy_probe,
325 + .of_match_table = ar7200_usb_phy_of_match,
326 + .name = "ar7200-usb-phy",
329 +module_platform_driver(ar7200_usb_phy_driver);
331 +MODULE_DESCRIPTION("ATH79 USB PHY driver");
332 +MODULE_AUTHOR("Alban Bedel <albeu@free.fr>");
333 +MODULE_LICENSE("GPL");