ipq40xx: 5.10: copy patches
[openwrt/openwrt.git] / target / linux / ipq40xx / patches-5.10 / 0017-v5.8-phy-add-driver-for-Qualcomm-IPQ40xx-USB-PHY.patch
1 From 3c9d8f6c03a2cda1849ec3c84f82ec030d1f49ef Mon Sep 17 00:00:00 2001
2 From: Robert Marko <robert.marko@sartura.hr>
3 Date: Sun, 3 May 2020 22:18:22 +0200
4 Subject: [PATCH] phy: add driver for Qualcomm IPQ40xx USB PHY
5
6 Add a driver to setup the USB PHY-s on Qualcom m IPQ40xx series SoCs.
7 The driver sets up HS and SS phys.
8
9 Signed-off-by: John Crispin <john@phrozen.org>
10 Signed-off-by: Robert Marko <robert.marko@sartura.hr>
11 Cc: Luka Perkov <luka.perkov@sartura.hr>
12 Link: https://lore.kernel.org/r/20200503201823.531757-1-robert.marko@sartura.hr
13 Signed-off-by: Vinod Koul <vkoul@kernel.org>
14 ---
15 drivers/phy/qualcomm/Kconfig | 7 +
16 drivers/phy/qualcomm/Makefile | 1 +
17 drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c | 148 ++++++++++++++++++++
18 3 files changed, 156 insertions(+)
19 create mode 100644 drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c
20
21 --- a/drivers/phy/qualcomm/Kconfig
22 +++ b/drivers/phy/qualcomm/Kconfig
23 @@ -18,6 +18,13 @@ config PHY_QCOM_APQ8064_SATA
24 depends on OF
25 select GENERIC_PHY
26
27 +config PHY_QCOM_IPQ4019_USB
28 + tristate "Qualcomm IPQ4019 USB PHY driver"
29 + depends on OF && (ARCH_QCOM || COMPILE_TEST)
30 + select GENERIC_PHY
31 + help
32 + Support for the USB PHY-s on Qualcomm IPQ40xx SoC-s.
33 +
34 config PHY_QCOM_IPQ806X_SATA
35 tristate "Qualcomm IPQ806x SATA SerDes/PHY driver"
36 depends on ARCH_QCOM
37 --- a/drivers/phy/qualcomm/Makefile
38 +++ b/drivers/phy/qualcomm/Makefile
39 @@ -1,6 +1,7 @@
40 # SPDX-License-Identifier: GPL-2.0
41 obj-$(CONFIG_PHY_ATH79_USB) += phy-ath79-usb.o
42 obj-$(CONFIG_PHY_QCOM_APQ8064_SATA) += phy-qcom-apq8064-sata.o
43 +obj-$(CONFIG_PHY_QCOM_IPQ4019_USB) += phy-qcom-ipq4019-usb.o
44 obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o
45 obj-$(CONFIG_PHY_QCOM_PCIE2) += phy-qcom-pcie2.o
46 obj-$(CONFIG_PHY_QCOM_QMP) += phy-qcom-qmp.o
47 --- /dev/null
48 +++ b/drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c
49 @@ -0,0 +1,148 @@
50 +// SPDX-License-Identifier: GPL-2.0-or-later
51 +/*
52 + * Copyright (C) 2018 John Crispin <john@phrozen.org>
53 + *
54 + * Based on code from
55 + * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
56 + *
57 + */
58 +
59 +#include <linux/delay.h>
60 +#include <linux/err.h>
61 +#include <linux/io.h>
62 +#include <linux/kernel.h>
63 +#include <linux/module.h>
64 +#include <linux/mutex.h>
65 +#include <linux/of_platform.h>
66 +#include <linux/of_device.h>
67 +#include <linux/phy/phy.h>
68 +#include <linux/platform_device.h>
69 +#include <linux/reset.h>
70 +
71 +struct ipq4019_usb_phy {
72 + struct device *dev;
73 + struct phy *phy;
74 + void __iomem *base;
75 + struct reset_control *por_rst;
76 + struct reset_control *srif_rst;
77 +};
78 +
79 +static int ipq4019_ss_phy_power_off(struct phy *_phy)
80 +{
81 + struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
82 +
83 + reset_control_assert(phy->por_rst);
84 + msleep(10);
85 +
86 + return 0;
87 +}
88 +
89 +static int ipq4019_ss_phy_power_on(struct phy *_phy)
90 +{
91 + struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
92 +
93 + ipq4019_ss_phy_power_off(_phy);
94 +
95 + reset_control_deassert(phy->por_rst);
96 +
97 + return 0;
98 +}
99 +
100 +static struct phy_ops ipq4019_usb_ss_phy_ops = {
101 + .power_on = ipq4019_ss_phy_power_on,
102 + .power_off = ipq4019_ss_phy_power_off,
103 +};
104 +
105 +static int ipq4019_hs_phy_power_off(struct phy *_phy)
106 +{
107 + struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
108 +
109 + reset_control_assert(phy->por_rst);
110 + msleep(10);
111 +
112 + reset_control_assert(phy->srif_rst);
113 + msleep(10);
114 +
115 + return 0;
116 +}
117 +
118 +static int ipq4019_hs_phy_power_on(struct phy *_phy)
119 +{
120 + struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
121 +
122 + ipq4019_hs_phy_power_off(_phy);
123 +
124 + reset_control_deassert(phy->srif_rst);
125 + msleep(10);
126 +
127 + reset_control_deassert(phy->por_rst);
128 +
129 + return 0;
130 +}
131 +
132 +static struct phy_ops ipq4019_usb_hs_phy_ops = {
133 + .power_on = ipq4019_hs_phy_power_on,
134 + .power_off = ipq4019_hs_phy_power_off,
135 +};
136 +
137 +static const struct of_device_id ipq4019_usb_phy_of_match[] = {
138 + { .compatible = "qcom,usb-hs-ipq4019-phy", .data = &ipq4019_usb_hs_phy_ops},
139 + { .compatible = "qcom,usb-ss-ipq4019-phy", .data = &ipq4019_usb_ss_phy_ops},
140 + { },
141 +};
142 +MODULE_DEVICE_TABLE(of, ipq4019_usb_phy_of_match);
143 +
144 +static int ipq4019_usb_phy_probe(struct platform_device *pdev)
145 +{
146 + struct device *dev = &pdev->dev;
147 + struct resource *res;
148 + struct phy_provider *phy_provider;
149 + struct ipq4019_usb_phy *phy;
150 +
151 + phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
152 + if (!phy)
153 + return -ENOMEM;
154 +
155 + phy->dev = &pdev->dev;
156 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
157 + phy->base = devm_ioremap_resource(&pdev->dev, res);
158 + if (IS_ERR(phy->base)) {
159 + dev_err(dev, "failed to remap register memory\n");
160 + return PTR_ERR(phy->base);
161 + }
162 +
163 + phy->por_rst = devm_reset_control_get(phy->dev, "por_rst");
164 + if (IS_ERR(phy->por_rst)) {
165 + if (PTR_ERR(phy->por_rst) != -EPROBE_DEFER)
166 + dev_err(dev, "POR reset is missing\n");
167 + return PTR_ERR(phy->por_rst);
168 + }
169 +
170 + phy->srif_rst = devm_reset_control_get_optional(phy->dev, "srif_rst");
171 + if (IS_ERR(phy->srif_rst))
172 + return PTR_ERR(phy->srif_rst);
173 +
174 + phy->phy = devm_phy_create(dev, NULL, of_device_get_match_data(dev));
175 + if (IS_ERR(phy->phy)) {
176 + dev_err(dev, "failed to create PHY\n");
177 + return PTR_ERR(phy->phy);
178 + }
179 + phy_set_drvdata(phy->phy, phy);
180 +
181 + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
182 +
183 + return PTR_ERR_OR_ZERO(phy_provider);
184 +}
185 +
186 +static struct platform_driver ipq4019_usb_phy_driver = {
187 + .probe = ipq4019_usb_phy_probe,
188 + .driver = {
189 + .of_match_table = ipq4019_usb_phy_of_match,
190 + .name = "ipq4019-usb-phy",
191 + }
192 +};
193 +module_platform_driver(ipq4019_usb_phy_driver);
194 +
195 +MODULE_DESCRIPTION("QCOM/IPQ4019 USB phy driver");
196 +MODULE_AUTHOR("John Crispin <john@phrozen.org>");
197 +MODULE_LICENSE("GPL v2");