blob: 612c428cf56888bda0362ca2e6f7c8542378b4c5 [file] [log] [blame]
Jagan Tekid3c38282018-05-07 13:03:26 +05301/*
2 * Allwinner sun4i USB PHY driver
3 *
4 * Copyright (C) 2017 Jagan Teki <jagan@amarulasolutions.com>
5 * Copyright (C) 2015 Hans de Goede <hdegoede@redhat.com>
6 * Copyright (C) 2014 Roman Byshko <rbyshko@gmail.com>
7 *
8 * Modelled arch/arm/mach-sunxi/usb_phy.c to compatible with generic-phy.
9 *
10 * SPDX-License-Identifier: GPL-2.0+
11 */
12
13#include <common.h>
Jagan Teki0dc33332018-08-06 12:16:39 +053014#include <clk.h>
Jagan Tekid3c38282018-05-07 13:03:26 +053015#include <dm.h>
16#include <dm/device.h>
17#include <generic-phy.h>
Jagan Teki21fc42d2018-05-07 13:03:27 +053018#include <phy-sun4i-usb.h>
Jagan Teki0dc33332018-08-06 12:16:39 +053019#include <reset.h>
Jagan Tekid3c38282018-05-07 13:03:26 +053020#include <asm/gpio.h>
21#include <asm/io.h>
22#include <asm/arch/clock.h>
23#include <asm/arch/cpu.h>
Simon Glass9bc15642020-02-03 07:36:16 -070024#include <dm/device_compat.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070025#include <linux/err.h>
Jagan Tekid3c38282018-05-07 13:03:26 +053026
27#define REG_ISCR 0x00
28#define REG_PHYCTL_A10 0x04
29#define REG_PHYBIST 0x08
30#define REG_PHYTUNE 0x0c
31#define REG_PHYCTL_A33 0x10
32#define REG_PHY_OTGCTL 0x20
33#define REG_PMU_UNK1 0x10
34
35/* Common Control Bits for Both PHYs */
36#define PHY_PLL_BW 0x03
37#define PHY_RES45_CAL_EN 0x0c
38
39/* Private Control Bits for Each PHY */
40#define PHY_TX_AMPLITUDE_TUNE 0x20
41#define PHY_TX_SLEWRATE_TUNE 0x22
42#define PHY_DISCON_TH_SEL 0x2a
Jagan Teki37671e12018-05-07 13:03:37 +053043#define PHY_SQUELCH_DETECT 0x3c
Jagan Tekid3c38282018-05-07 13:03:26 +053044
45#define PHYCTL_DATA BIT(7)
46#define OTGCTL_ROUTE_MUSB BIT(0)
47
48#define PHY_TX_RATE BIT(4)
49#define PHY_TX_MAGNITUDE BIT(2)
50#define PHY_TX_AMPLITUDE_LEN 5
51
52#define PHY_RES45_CAL_DATA BIT(0)
53#define PHY_RES45_CAL_LEN 1
54#define PHY_DISCON_TH_LEN 2
55
56#define SUNXI_AHB_ICHR8_EN BIT(10)
57#define SUNXI_AHB_INCR4_BURST_EN BIT(9)
58#define SUNXI_AHB_INCRX_ALIGN_EN BIT(8)
59#define SUNXI_ULPI_BYPASS_EN BIT(0)
60
Jagan Teki05a7b9f2018-05-07 13:03:30 +053061/* A83T specific control bits for PHY0 */
62#define PHY_CTL_VBUSVLDEXT BIT(5)
63#define PHY_CTL_SIDDQ BIT(3)
64
65/* A83T specific control bits for PHY2 HSIC */
66#define SUNXI_EHCI_HS_FORCE BIT(20)
67#define SUNXI_HSIC_CONNECT_INT BIT(16)
68#define SUNXI_HSIC BIT(1)
69
Jagan Tekid3c38282018-05-07 13:03:26 +053070#define MAX_PHYS 4
71
72enum sun4i_usb_phy_type {
Jagan Teki5a3000f2018-05-07 13:03:31 +053073 sun4i_a10_phy,
Jagan Teki1cbc80c2018-05-07 13:03:32 +053074 sun6i_a31_phy,
Jagan Teki0e574bb2018-05-07 13:03:33 +053075 sun8i_a33_phy,
Jagan Teki05a7b9f2018-05-07 13:03:30 +053076 sun8i_a83t_phy,
Jagan Tekic1b0e5a2018-05-07 13:03:28 +053077 sun8i_h3_phy,
Andre Przywara47d49972020-01-01 23:44:48 +000078 sun8i_r40_phy,
Jagan Tekiac4bab42018-05-07 13:03:29 +053079 sun8i_v3s_phy,
Jagan Tekid3c38282018-05-07 13:03:26 +053080 sun50i_a64_phy,
Andre Przywarab2f0f312019-06-23 15:09:49 +010081 sun50i_h6_phy,
Jagan Tekid3c38282018-05-07 13:03:26 +053082};
83
84struct sun4i_usb_phy_cfg {
85 int num_phys;
86 enum sun4i_usb_phy_type type;
87 u32 disc_thresh;
88 u8 phyctl_offset;
Jagan Teki0dc33332018-08-06 12:16:39 +053089 bool dedicated_clocks;
Jagan Tekid3c38282018-05-07 13:03:26 +053090 bool enable_pmu_unk1;
91 bool phy0_dual_route;
Andre Przywarab2f0f312019-06-23 15:09:49 +010092 int missing_phys;
Jagan Tekid3c38282018-05-07 13:03:26 +053093};
94
95struct sun4i_usb_phy_info {
96 const char *gpio_vbus;
97 const char *gpio_vbus_det;
98 const char *gpio_id_det;
Jagan Tekid3c38282018-05-07 13:03:26 +053099} phy_info[] = {
100 {
101 .gpio_vbus = CONFIG_USB0_VBUS_PIN,
102 .gpio_vbus_det = CONFIG_USB0_VBUS_DET,
103 .gpio_id_det = CONFIG_USB0_ID_DET,
Jagan Tekid3c38282018-05-07 13:03:26 +0530104 },
105 {
106 .gpio_vbus = CONFIG_USB1_VBUS_PIN,
107 .gpio_vbus_det = NULL,
108 .gpio_id_det = NULL,
Jagan Tekid3c38282018-05-07 13:03:26 +0530109 },
110 {
111 .gpio_vbus = CONFIG_USB2_VBUS_PIN,
112 .gpio_vbus_det = NULL,
113 .gpio_id_det = NULL,
Jagan Tekid3c38282018-05-07 13:03:26 +0530114 },
115 {
116 .gpio_vbus = CONFIG_USB3_VBUS_PIN,
117 .gpio_vbus_det = NULL,
118 .gpio_id_det = NULL,
Jagan Tekid3c38282018-05-07 13:03:26 +0530119 },
120};
121
122struct sun4i_usb_phy_plat {
123 void __iomem *pmu;
124 int power_on_count;
125 int gpio_vbus;
126 int gpio_vbus_det;
127 int gpio_id_det;
Jagan Teki0dc33332018-08-06 12:16:39 +0530128 struct clk clocks;
129 struct reset_ctl resets;
Jagan Tekid3c38282018-05-07 13:03:26 +0530130 int id;
131};
132
133struct sun4i_usb_phy_data {
134 void __iomem *base;
Jagan Tekid3c38282018-05-07 13:03:26 +0530135 const struct sun4i_usb_phy_cfg *cfg;
136 struct sun4i_usb_phy_plat *usb_phy;
137};
138
139static int initial_usb_scan_delay = CONFIG_INITIAL_USB_SCAN_DELAY;
140
141static void sun4i_usb_phy_write(struct phy *phy, u32 addr, u32 data, int len)
142{
143 struct sun4i_usb_phy_data *phy_data = dev_get_priv(phy->dev);
144 struct sun4i_usb_phy_plat *usb_phy = &phy_data->usb_phy[phy->id];
145 u32 temp, usbc_bit = BIT(usb_phy->id * 2);
146 void __iomem *phyctl = phy_data->base + phy_data->cfg->phyctl_offset;
147 int i;
148
149 if (phy_data->cfg->phyctl_offset == REG_PHYCTL_A33) {
150 /* SoCs newer than A33 need us to set phyctl to 0 explicitly */
151 writel(0, phyctl);
152 }
153
154 for (i = 0; i < len; i++) {
155 temp = readl(phyctl);
156
157 /* clear the address portion */
158 temp &= ~(0xff << 8);
159
160 /* set the address */
161 temp |= ((addr + i) << 8);
162 writel(temp, phyctl);
163
164 /* set the data bit and clear usbc bit*/
165 temp = readb(phyctl);
166 if (data & 0x1)
167 temp |= PHYCTL_DATA;
168 else
169 temp &= ~PHYCTL_DATA;
170 temp &= ~usbc_bit;
171 writeb(temp, phyctl);
172
173 /* pulse usbc_bit */
174 temp = readb(phyctl);
175 temp |= usbc_bit;
176 writeb(temp, phyctl);
177
178 temp = readb(phyctl);
179 temp &= ~usbc_bit;
180 writeb(temp, phyctl);
181
182 data >>= 1;
183 }
184}
185
Jagan Teki05a7b9f2018-05-07 13:03:30 +0530186static void sun4i_usb_phy_passby(struct phy *phy, bool enable)
Jagan Tekid3c38282018-05-07 13:03:26 +0530187{
Jagan Teki05a7b9f2018-05-07 13:03:30 +0530188 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
189 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
Jagan Tekid3c38282018-05-07 13:03:26 +0530190 u32 bits, reg_value;
191
192 if (!usb_phy->pmu)
193 return;
194
195 bits = SUNXI_AHB_ICHR8_EN | SUNXI_AHB_INCR4_BURST_EN |
196 SUNXI_AHB_INCRX_ALIGN_EN | SUNXI_ULPI_BYPASS_EN;
Jagan Teki05a7b9f2018-05-07 13:03:30 +0530197
198 /* A83T USB2 is HSIC */
199 if (data->cfg->type == sun8i_a83t_phy && usb_phy->id == 2)
200 bits |= SUNXI_EHCI_HS_FORCE | SUNXI_HSIC_CONNECT_INT |
201 SUNXI_HSIC;
202
Jagan Tekid3c38282018-05-07 13:03:26 +0530203 reg_value = readl(usb_phy->pmu);
204
205 if (enable)
206 reg_value |= bits;
207 else
208 reg_value &= ~bits;
209
210 writel(reg_value, usb_phy->pmu);
211}
212
213static int sun4i_usb_phy_power_on(struct phy *phy)
214{
215 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
216 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
217
218 if (initial_usb_scan_delay) {
219 mdelay(initial_usb_scan_delay);
220 initial_usb_scan_delay = 0;
221 }
222
223 usb_phy->power_on_count++;
224 if (usb_phy->power_on_count != 1)
225 return 0;
226
227 if (usb_phy->gpio_vbus >= 0)
228 gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_UP);
229
230 return 0;
231}
232
233static int sun4i_usb_phy_power_off(struct phy *phy)
234{
235 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
236 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
237
238 usb_phy->power_on_count--;
239 if (usb_phy->power_on_count != 0)
240 return 0;
241
242 if (usb_phy->gpio_vbus >= 0)
243 gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_DISABLE);
244
245 return 0;
246}
247
248static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, bool id_det)
249{
250 u32 regval;
251
252 regval = readl(data->base + REG_PHY_OTGCTL);
253 if (!id_det) {
254 /* Host mode. Route phy0 to EHCI/OHCI */
255 regval &= ~OTGCTL_ROUTE_MUSB;
256 } else {
257 /* Peripheral mode. Route phy0 to MUSB */
258 regval |= OTGCTL_ROUTE_MUSB;
259 }
260 writel(regval, data->base + REG_PHY_OTGCTL);
261}
262
263static int sun4i_usb_phy_init(struct phy *phy)
264{
265 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
266 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
267 u32 val;
Jagan Teki0dc33332018-08-06 12:16:39 +0530268 int ret;
Jagan Tekid3c38282018-05-07 13:03:26 +0530269
Jagan Teki0dc33332018-08-06 12:16:39 +0530270 ret = clk_enable(&usb_phy->clocks);
271 if (ret) {
272 dev_err(dev, "failed to enable usb_%ldphy clock\n", phy->id);
273 return ret;
274 }
275
276 ret = reset_deassert(&usb_phy->resets);
277 if (ret) {
278 dev_err(dev, "failed to deassert usb_%ldreset reset\n", phy->id);
279 return ret;
280 }
Jagan Tekid3c38282018-05-07 13:03:26 +0530281
Jagan Teki05a7b9f2018-05-07 13:03:30 +0530282 if (data->cfg->type == sun8i_a83t_phy) {
283 if (phy->id == 0) {
284 val = readl(data->base + data->cfg->phyctl_offset);
285 val |= PHY_CTL_VBUSVLDEXT;
286 val &= ~PHY_CTL_SIDDQ;
287 writel(val, data->base + data->cfg->phyctl_offset);
288 }
289 } else {
290 if (usb_phy->pmu && data->cfg->enable_pmu_unk1) {
291 val = readl(usb_phy->pmu + REG_PMU_UNK1);
292 writel(val & ~2, usb_phy->pmu + REG_PMU_UNK1);
293 }
Jagan Tekid3c38282018-05-07 13:03:26 +0530294
Jagan Teki05a7b9f2018-05-07 13:03:30 +0530295 if (usb_phy->id == 0)
296 sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN,
297 PHY_RES45_CAL_DATA,
298 PHY_RES45_CAL_LEN);
Jagan Tekid3c38282018-05-07 13:03:26 +0530299
Jagan Teki05a7b9f2018-05-07 13:03:30 +0530300 /* Adjust PHY's magnitude and rate */
301 sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE,
302 PHY_TX_MAGNITUDE | PHY_TX_RATE,
303 PHY_TX_AMPLITUDE_LEN);
Jagan Tekid3c38282018-05-07 13:03:26 +0530304
Jagan Teki05a7b9f2018-05-07 13:03:30 +0530305 /* Disconnect threshold adjustment */
306 sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
307 data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
308 }
Jagan Tekid3c38282018-05-07 13:03:26 +0530309
Jagan Tekib8cbf9d2018-07-20 12:34:20 +0530310 sun4i_usb_phy_passby(phy, true);
Jagan Tekid3c38282018-05-07 13:03:26 +0530311
312 sun4i_usb_phy0_reroute(data, true);
313
314 return 0;
315}
316
317static int sun4i_usb_phy_exit(struct phy *phy)
318{
319 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
320 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
Jagan Teki0dc33332018-08-06 12:16:39 +0530321 int ret;
Jagan Tekid3c38282018-05-07 13:03:26 +0530322
Jagan Teki05a7b9f2018-05-07 13:03:30 +0530323 if (phy->id == 0) {
324 if (data->cfg->type == sun8i_a83t_phy) {
325 void __iomem *phyctl = data->base +
326 data->cfg->phyctl_offset;
327
328 writel(readl(phyctl) | PHY_CTL_SIDDQ, phyctl);
329 }
330 }
331
332 sun4i_usb_phy_passby(phy, false);
Jagan Tekid3c38282018-05-07 13:03:26 +0530333
Jagan Teki0dc33332018-08-06 12:16:39 +0530334 ret = clk_disable(&usb_phy->clocks);
335 if (ret) {
336 dev_err(dev, "failed to disable usb_%ldphy clock\n", phy->id);
337 return ret;
338 }
339
340 ret = reset_assert(&usb_phy->resets);
341 if (ret) {
342 dev_err(dev, "failed to assert usb_%ldreset reset\n", phy->id);
343 return ret;
344 }
Jagan Tekid3c38282018-05-07 13:03:26 +0530345
346 return 0;
347}
348
349static int sun4i_usb_phy_xlate(struct phy *phy,
350 struct ofnode_phandle_args *args)
351{
352 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
353
354 if (args->args_count >= data->cfg->num_phys)
355 return -EINVAL;
356
Andre Przywarab2f0f312019-06-23 15:09:49 +0100357 if (data->cfg->missing_phys & BIT(args->args[0]))
358 return -ENODEV;
359
Jagan Tekid3c38282018-05-07 13:03:26 +0530360 if (args->args_count)
361 phy->id = args->args[0];
362 else
363 phy->id = 0;
364
365 debug("%s: phy_id = %ld\n", __func__, phy->id);
366 return 0;
367}
368
Jagan Teki21fc42d2018-05-07 13:03:27 +0530369int sun4i_usb_phy_vbus_detect(struct phy *phy)
370{
371 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
372 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
373 int err, retries = 3;
374
375 debug("%s: id_det = %d\n", __func__, usb_phy->gpio_id_det);
376
377 if (usb_phy->gpio_vbus_det < 0)
378 return usb_phy->gpio_vbus_det;
379
380 err = gpio_get_value(usb_phy->gpio_vbus_det);
381 /*
382 * Vbus may have been provided by the board and just been turned of
383 * some milliseconds ago on reset, what we're measuring then is a
384 * residual charge on Vbus, sleep a bit and try again.
385 */
386 while (err > 0 && retries--) {
387 mdelay(100);
388 err = gpio_get_value(usb_phy->gpio_vbus_det);
389 }
390
391 return err;
392}
393
394int sun4i_usb_phy_id_detect(struct phy *phy)
395{
396 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
397 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
398
399 debug("%s: id_det = %d\n", __func__, usb_phy->gpio_id_det);
400
401 if (usb_phy->gpio_id_det < 0)
402 return usb_phy->gpio_id_det;
403
404 return gpio_get_value(usb_phy->gpio_id_det);
405}
406
Jagan Teki37671e12018-05-07 13:03:37 +0530407void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled)
408{
409 sun4i_usb_phy_write(phy, PHY_SQUELCH_DETECT, enabled ? 0 : 2, 2);
410}
411
Jagan Tekid3c38282018-05-07 13:03:26 +0530412static struct phy_ops sun4i_usb_phy_ops = {
413 .of_xlate = sun4i_usb_phy_xlate,
414 .init = sun4i_usb_phy_init,
415 .power_on = sun4i_usb_phy_power_on,
416 .power_off = sun4i_usb_phy_power_off,
417 .exit = sun4i_usb_phy_exit,
418};
419
420static int sun4i_usb_phy_probe(struct udevice *dev)
421{
422 struct sun4i_usb_phy_plat *plat = dev_get_platdata(dev);
423 struct sun4i_usb_phy_data *data = dev_get_priv(dev);
424 int i, ret;
425
426 data->cfg = (const struct sun4i_usb_phy_cfg *)dev_get_driver_data(dev);
427 if (!data->cfg)
428 return -EINVAL;
429
430 data->base = (void __iomem *)devfdt_get_addr_name(dev, "phy_ctrl");
431 if (IS_ERR(data->base))
432 return PTR_ERR(data->base);
433
Jagan Tekid3c38282018-05-07 13:03:26 +0530434 data->usb_phy = plat;
435 for (i = 0; i < data->cfg->num_phys; i++) {
436 struct sun4i_usb_phy_plat *phy = &plat[i];
437 struct sun4i_usb_phy_info *info = &phy_info[i];
438 char name[16];
439
Andre Przywarab2f0f312019-06-23 15:09:49 +0100440 if (data->cfg->missing_phys & BIT(i))
441 continue;
442
Jagan Tekid3c38282018-05-07 13:03:26 +0530443 phy->gpio_vbus = sunxi_name_to_gpio(info->gpio_vbus);
444 if (phy->gpio_vbus >= 0) {
445 ret = gpio_request(phy->gpio_vbus, "usb_vbus");
446 if (ret)
447 return ret;
448 ret = gpio_direction_output(phy->gpio_vbus, 0);
449 if (ret)
450 return ret;
451 }
452
453 phy->gpio_vbus_det = sunxi_name_to_gpio(info->gpio_vbus_det);
454 if (phy->gpio_vbus_det >= 0) {
455 ret = gpio_request(phy->gpio_vbus_det, "usb_vbus_det");
456 if (ret)
457 return ret;
458 ret = gpio_direction_input(phy->gpio_vbus_det);
459 if (ret)
460 return ret;
461 }
462
463 phy->gpio_id_det = sunxi_name_to_gpio(info->gpio_id_det);
464 if (phy->gpio_id_det >= 0) {
465 ret = gpio_request(phy->gpio_id_det, "usb_id_det");
466 if (ret)
467 return ret;
468 ret = gpio_direction_input(phy->gpio_id_det);
469 if (ret)
470 return ret;
471 sunxi_gpio_set_pull(phy->gpio_id_det, SUNXI_GPIO_PULL_UP);
472 }
473
Jagan Teki0dc33332018-08-06 12:16:39 +0530474 if (data->cfg->dedicated_clocks)
475 snprintf(name, sizeof(name), "usb%d_phy", i);
476 else
477 strlcpy(name, "usb_phy", sizeof(name));
478
479 ret = clk_get_by_name(dev, name, &phy->clocks);
480 if (ret) {
481 dev_err(dev, "failed to get usb%d_phy clock phandle\n", i);
482 return ret;
483 }
484
485 snprintf(name, sizeof(name), "usb%d_reset", i);
486 ret = reset_get_by_name(dev, name, &phy->resets);
487 if (ret) {
488 dev_err(dev, "failed to get usb%d_reset reset phandle\n", i);
489 return ret;
490 }
491
Jagan Tekid3c38282018-05-07 13:03:26 +0530492 if (i || data->cfg->phy0_dual_route) {
493 snprintf(name, sizeof(name), "pmu%d", i);
494 phy->pmu = (void __iomem *)devfdt_get_addr_name(dev, name);
495 if (IS_ERR(phy->pmu))
496 return PTR_ERR(phy->pmu);
497 }
498
499 phy->id = i;
Jagan Tekid3c38282018-05-07 13:03:26 +0530500 };
501
Jagan Tekid3c38282018-05-07 13:03:26 +0530502 debug("Allwinner Sun4I USB PHY driver loaded\n");
503 return 0;
504}
505
Jagan Teki5a3000f2018-05-07 13:03:31 +0530506static const struct sun4i_usb_phy_cfg sun4i_a10_cfg = {
507 .num_phys = 3,
508 .type = sun4i_a10_phy,
509 .disc_thresh = 3,
510 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki0dc33332018-08-06 12:16:39 +0530511 .dedicated_clocks = false,
Jagan Teki5a3000f2018-05-07 13:03:31 +0530512 .enable_pmu_unk1 = false,
513};
514
515static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = {
516 .num_phys = 2,
517 .type = sun4i_a10_phy,
518 .disc_thresh = 2,
519 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki0dc33332018-08-06 12:16:39 +0530520 .dedicated_clocks = false,
Jagan Teki5a3000f2018-05-07 13:03:31 +0530521 .enable_pmu_unk1 = false,
522};
523
Jagan Teki1cbc80c2018-05-07 13:03:32 +0530524static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = {
525 .num_phys = 3,
526 .type = sun6i_a31_phy,
527 .disc_thresh = 3,
528 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki0dc33332018-08-06 12:16:39 +0530529 .dedicated_clocks = true,
Jagan Teki1cbc80c2018-05-07 13:03:32 +0530530 .enable_pmu_unk1 = false,
531};
532
Jagan Teki5a3000f2018-05-07 13:03:31 +0530533static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = {
534 .num_phys = 3,
535 .type = sun4i_a10_phy,
536 .disc_thresh = 2,
537 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki0dc33332018-08-06 12:16:39 +0530538 .dedicated_clocks = false,
Jagan Teki5a3000f2018-05-07 13:03:31 +0530539 .enable_pmu_unk1 = false,
540};
541
Jagan Teki00f9f6b2018-05-07 13:03:34 +0530542static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = {
543 .num_phys = 2,
544 .type = sun4i_a10_phy,
545 .disc_thresh = 3,
546 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki0dc33332018-08-06 12:16:39 +0530547 .dedicated_clocks = true,
Jagan Teki00f9f6b2018-05-07 13:03:34 +0530548 .enable_pmu_unk1 = false,
549};
550
Jagan Teki0e574bb2018-05-07 13:03:33 +0530551static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = {
552 .num_phys = 2,
553 .type = sun8i_a33_phy,
554 .disc_thresh = 3,
555 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki0dc33332018-08-06 12:16:39 +0530556 .dedicated_clocks = true,
Jagan Teki0e574bb2018-05-07 13:03:33 +0530557 .enable_pmu_unk1 = false,
558};
559
Jagan Teki05a7b9f2018-05-07 13:03:30 +0530560static const struct sun4i_usb_phy_cfg sun8i_a83t_cfg = {
561 .num_phys = 3,
562 .type = sun8i_a83t_phy,
563 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki0dc33332018-08-06 12:16:39 +0530564 .dedicated_clocks = true,
Jagan Teki05a7b9f2018-05-07 13:03:30 +0530565};
566
Jagan Tekic1b0e5a2018-05-07 13:03:28 +0530567static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
568 .num_phys = 4,
569 .type = sun8i_h3_phy,
570 .disc_thresh = 3,
571 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki0dc33332018-08-06 12:16:39 +0530572 .dedicated_clocks = true,
Jagan Tekic1b0e5a2018-05-07 13:03:28 +0530573 .enable_pmu_unk1 = true,
574 .phy0_dual_route = true,
575};
576
Andre Przywara47d49972020-01-01 23:44:48 +0000577static const struct sun4i_usb_phy_cfg sun8i_r40_cfg = {
578 .num_phys = 3,
579 .type = sun8i_r40_phy,
580 .disc_thresh = 3,
581 .phyctl_offset = REG_PHYCTL_A33,
582 .dedicated_clocks = true,
583 .enable_pmu_unk1 = true,
584 .phy0_dual_route = true,
585};
586
Jagan Tekiac4bab42018-05-07 13:03:29 +0530587static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
588 .num_phys = 1,
589 .type = sun8i_v3s_phy,
590 .disc_thresh = 3,
591 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki0dc33332018-08-06 12:16:39 +0530592 .dedicated_clocks = true,
Jagan Tekiac4bab42018-05-07 13:03:29 +0530593 .enable_pmu_unk1 = true,
594 .phy0_dual_route = true,
595};
596
Jagan Tekid3c38282018-05-07 13:03:26 +0530597static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = {
598 .num_phys = 2,
599 .type = sun50i_a64_phy,
600 .disc_thresh = 3,
601 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki0dc33332018-08-06 12:16:39 +0530602 .dedicated_clocks = true,
Jagan Tekid3c38282018-05-07 13:03:26 +0530603 .enable_pmu_unk1 = true,
604 .phy0_dual_route = true,
Andre Przywarab2f0f312019-06-23 15:09:49 +0100605};
606
607static const struct sun4i_usb_phy_cfg sun50i_h6_cfg = {
608 .num_phys = 4,
609 .type = sun50i_h6_phy,
610 .disc_thresh = 3,
611 .phyctl_offset = REG_PHYCTL_A33,
612 .dedicated_clocks = true,
613 .enable_pmu_unk1 = true,
614 .phy0_dual_route = true,
615 .missing_phys = BIT(1) | BIT(2),
Jagan Tekid3c38282018-05-07 13:03:26 +0530616};
617
618static const struct udevice_id sun4i_usb_phy_ids[] = {
Jagan Teki5a3000f2018-05-07 13:03:31 +0530619 { .compatible = "allwinner,sun4i-a10-usb-phy", .data = (ulong)&sun4i_a10_cfg },
620 { .compatible = "allwinner,sun5i-a13-usb-phy", .data = (ulong)&sun5i_a13_cfg },
Jagan Teki1cbc80c2018-05-07 13:03:32 +0530621 { .compatible = "allwinner,sun6i-a31-usb-phy", .data = (ulong)&sun6i_a31_cfg },
Jagan Teki5a3000f2018-05-07 13:03:31 +0530622 { .compatible = "allwinner,sun7i-a20-usb-phy", .data = (ulong)&sun7i_a20_cfg },
Jagan Teki00f9f6b2018-05-07 13:03:34 +0530623 { .compatible = "allwinner,sun8i-a23-usb-phy", .data = (ulong)&sun8i_a23_cfg },
Jagan Teki0e574bb2018-05-07 13:03:33 +0530624 { .compatible = "allwinner,sun8i-a33-usb-phy", .data = (ulong)&sun8i_a33_cfg },
Jagan Teki05a7b9f2018-05-07 13:03:30 +0530625 { .compatible = "allwinner,sun8i-a83t-usb-phy", .data = (ulong)&sun8i_a83t_cfg },
Jagan Tekic1b0e5a2018-05-07 13:03:28 +0530626 { .compatible = "allwinner,sun8i-h3-usb-phy", .data = (ulong)&sun8i_h3_cfg },
Andre Przywara47d49972020-01-01 23:44:48 +0000627 { .compatible = "allwinner,sun8i-r40-usb-phy", .data = (ulong)&sun8i_r40_cfg },
Jagan Tekiac4bab42018-05-07 13:03:29 +0530628 { .compatible = "allwinner,sun8i-v3s-usb-phy", .data = (ulong)&sun8i_v3s_cfg },
Jagan Tekid3c38282018-05-07 13:03:26 +0530629 { .compatible = "allwinner,sun50i-a64-usb-phy", .data = (ulong)&sun50i_a64_cfg},
Andre Przywarab2f0f312019-06-23 15:09:49 +0100630 { .compatible = "allwinner,sun50i-h6-usb-phy", .data = (ulong)&sun50i_h6_cfg},
Jagan Tekid3c38282018-05-07 13:03:26 +0530631 { }
632};
633
634U_BOOT_DRIVER(sun4i_usb_phy) = {
635 .name = "sun4i_usb_phy",
636 .id = UCLASS_PHY,
637 .of_match = sun4i_usb_phy_ids,
638 .ops = &sun4i_usb_phy_ops,
639 .probe = sun4i_usb_phy_probe,
640 .platdata_auto_alloc_size = sizeof(struct sun4i_usb_phy_plat[MAX_PHYS]),
641 .priv_auto_alloc_size = sizeof(struct sun4i_usb_phy_data),
642};