blob: f7309057b9124ae6f7a185616110fa8eb98b3135 [file] [log] [blame]
Jagan Teki67685942018-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 Teki089ffd02018-08-06 12:16:39 +053014#include <clk.h>
Jagan Teki67685942018-05-07 13:03:26 +053015#include <dm.h>
16#include <dm/device.h>
17#include <generic-phy.h>
Jagan Teki129c45c2018-05-07 13:03:27 +053018#include <phy-sun4i-usb.h>
Jagan Teki089ffd02018-08-06 12:16:39 +053019#include <reset.h>
Jagan Teki67685942018-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>
24
25#define REG_ISCR 0x00
26#define REG_PHYCTL_A10 0x04
27#define REG_PHYBIST 0x08
28#define REG_PHYTUNE 0x0c
29#define REG_PHYCTL_A33 0x10
30#define REG_PHY_OTGCTL 0x20
31#define REG_PMU_UNK1 0x10
32
33/* Common Control Bits for Both PHYs */
34#define PHY_PLL_BW 0x03
35#define PHY_RES45_CAL_EN 0x0c
36
37/* Private Control Bits for Each PHY */
38#define PHY_TX_AMPLITUDE_TUNE 0x20
39#define PHY_TX_SLEWRATE_TUNE 0x22
40#define PHY_DISCON_TH_SEL 0x2a
Jagan Tekiaa29b112018-05-07 13:03:37 +053041#define PHY_SQUELCH_DETECT 0x3c
Jagan Teki67685942018-05-07 13:03:26 +053042
43#define PHYCTL_DATA BIT(7)
44#define OTGCTL_ROUTE_MUSB BIT(0)
45
46#define PHY_TX_RATE BIT(4)
47#define PHY_TX_MAGNITUDE BIT(2)
48#define PHY_TX_AMPLITUDE_LEN 5
49
50#define PHY_RES45_CAL_DATA BIT(0)
51#define PHY_RES45_CAL_LEN 1
52#define PHY_DISCON_TH_LEN 2
53
54#define SUNXI_AHB_ICHR8_EN BIT(10)
55#define SUNXI_AHB_INCR4_BURST_EN BIT(9)
56#define SUNXI_AHB_INCRX_ALIGN_EN BIT(8)
57#define SUNXI_ULPI_BYPASS_EN BIT(0)
58
Jagan Teki5f646bf2018-05-07 13:03:30 +053059/* A83T specific control bits for PHY0 */
60#define PHY_CTL_VBUSVLDEXT BIT(5)
61#define PHY_CTL_SIDDQ BIT(3)
62
63/* A83T specific control bits for PHY2 HSIC */
64#define SUNXI_EHCI_HS_FORCE BIT(20)
65#define SUNXI_HSIC_CONNECT_INT BIT(16)
66#define SUNXI_HSIC BIT(1)
67
Jagan Teki67685942018-05-07 13:03:26 +053068#define MAX_PHYS 4
69
70enum sun4i_usb_phy_type {
Jagan Teki7f90b552018-05-07 13:03:31 +053071 sun4i_a10_phy,
Jagan Tekibf986d12018-05-07 13:03:32 +053072 sun6i_a31_phy,
Jagan Teki61bf0ed2018-05-07 13:03:33 +053073 sun8i_a33_phy,
Jagan Teki5f646bf2018-05-07 13:03:30 +053074 sun8i_a83t_phy,
Jagan Teki43519c42018-05-07 13:03:28 +053075 sun8i_h3_phy,
Andre Przywaraa2f729f2020-01-01 23:44:48 +000076 sun8i_r40_phy,
Jagan Tekibafe5e32018-05-07 13:03:29 +053077 sun8i_v3s_phy,
Jagan Teki67685942018-05-07 13:03:26 +053078 sun50i_a64_phy,
Andre Przywara35fa6732019-06-23 15:09:49 +010079 sun50i_h6_phy,
Jagan Teki67685942018-05-07 13:03:26 +053080};
81
82struct sun4i_usb_phy_cfg {
83 int num_phys;
84 enum sun4i_usb_phy_type type;
85 u32 disc_thresh;
86 u8 phyctl_offset;
Jagan Teki089ffd02018-08-06 12:16:39 +053087 bool dedicated_clocks;
Jagan Teki67685942018-05-07 13:03:26 +053088 bool enable_pmu_unk1;
89 bool phy0_dual_route;
Andre Przywara35fa6732019-06-23 15:09:49 +010090 int missing_phys;
Jagan Teki67685942018-05-07 13:03:26 +053091};
92
93struct sun4i_usb_phy_info {
94 const char *gpio_vbus;
95 const char *gpio_vbus_det;
96 const char *gpio_id_det;
Jagan Teki67685942018-05-07 13:03:26 +053097} phy_info[] = {
98 {
99 .gpio_vbus = CONFIG_USB0_VBUS_PIN,
100 .gpio_vbus_det = CONFIG_USB0_VBUS_DET,
101 .gpio_id_det = CONFIG_USB0_ID_DET,
Jagan Teki67685942018-05-07 13:03:26 +0530102 },
103 {
104 .gpio_vbus = CONFIG_USB1_VBUS_PIN,
105 .gpio_vbus_det = NULL,
106 .gpio_id_det = NULL,
Jagan Teki67685942018-05-07 13:03:26 +0530107 },
108 {
109 .gpio_vbus = CONFIG_USB2_VBUS_PIN,
110 .gpio_vbus_det = NULL,
111 .gpio_id_det = NULL,
Jagan Teki67685942018-05-07 13:03:26 +0530112 },
113 {
114 .gpio_vbus = CONFIG_USB3_VBUS_PIN,
115 .gpio_vbus_det = NULL,
116 .gpio_id_det = NULL,
Jagan Teki67685942018-05-07 13:03:26 +0530117 },
118};
119
120struct sun4i_usb_phy_plat {
121 void __iomem *pmu;
122 int power_on_count;
123 int gpio_vbus;
124 int gpio_vbus_det;
125 int gpio_id_det;
Jagan Teki089ffd02018-08-06 12:16:39 +0530126 struct clk clocks;
127 struct reset_ctl resets;
Jagan Teki67685942018-05-07 13:03:26 +0530128 int id;
129};
130
131struct sun4i_usb_phy_data {
132 void __iomem *base;
Jagan Teki67685942018-05-07 13:03:26 +0530133 const struct sun4i_usb_phy_cfg *cfg;
134 struct sun4i_usb_phy_plat *usb_phy;
135};
136
137static int initial_usb_scan_delay = CONFIG_INITIAL_USB_SCAN_DELAY;
138
139static void sun4i_usb_phy_write(struct phy *phy, u32 addr, u32 data, int len)
140{
141 struct sun4i_usb_phy_data *phy_data = dev_get_priv(phy->dev);
142 struct sun4i_usb_phy_plat *usb_phy = &phy_data->usb_phy[phy->id];
143 u32 temp, usbc_bit = BIT(usb_phy->id * 2);
144 void __iomem *phyctl = phy_data->base + phy_data->cfg->phyctl_offset;
145 int i;
146
147 if (phy_data->cfg->phyctl_offset == REG_PHYCTL_A33) {
148 /* SoCs newer than A33 need us to set phyctl to 0 explicitly */
149 writel(0, phyctl);
150 }
151
152 for (i = 0; i < len; i++) {
153 temp = readl(phyctl);
154
155 /* clear the address portion */
156 temp &= ~(0xff << 8);
157
158 /* set the address */
159 temp |= ((addr + i) << 8);
160 writel(temp, phyctl);
161
162 /* set the data bit and clear usbc bit*/
163 temp = readb(phyctl);
164 if (data & 0x1)
165 temp |= PHYCTL_DATA;
166 else
167 temp &= ~PHYCTL_DATA;
168 temp &= ~usbc_bit;
169 writeb(temp, phyctl);
170
171 /* pulse usbc_bit */
172 temp = readb(phyctl);
173 temp |= usbc_bit;
174 writeb(temp, phyctl);
175
176 temp = readb(phyctl);
177 temp &= ~usbc_bit;
178 writeb(temp, phyctl);
179
180 data >>= 1;
181 }
182}
183
Jagan Teki5f646bf2018-05-07 13:03:30 +0530184static void sun4i_usb_phy_passby(struct phy *phy, bool enable)
Jagan Teki67685942018-05-07 13:03:26 +0530185{
Jagan Teki5f646bf2018-05-07 13:03:30 +0530186 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
187 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
Jagan Teki67685942018-05-07 13:03:26 +0530188 u32 bits, reg_value;
189
190 if (!usb_phy->pmu)
191 return;
192
193 bits = SUNXI_AHB_ICHR8_EN | SUNXI_AHB_INCR4_BURST_EN |
194 SUNXI_AHB_INCRX_ALIGN_EN | SUNXI_ULPI_BYPASS_EN;
Jagan Teki5f646bf2018-05-07 13:03:30 +0530195
196 /* A83T USB2 is HSIC */
197 if (data->cfg->type == sun8i_a83t_phy && usb_phy->id == 2)
198 bits |= SUNXI_EHCI_HS_FORCE | SUNXI_HSIC_CONNECT_INT |
199 SUNXI_HSIC;
200
Jagan Teki67685942018-05-07 13:03:26 +0530201 reg_value = readl(usb_phy->pmu);
202
203 if (enable)
204 reg_value |= bits;
205 else
206 reg_value &= ~bits;
207
208 writel(reg_value, usb_phy->pmu);
209}
210
211static int sun4i_usb_phy_power_on(struct phy *phy)
212{
213 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
214 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
215
216 if (initial_usb_scan_delay) {
217 mdelay(initial_usb_scan_delay);
218 initial_usb_scan_delay = 0;
219 }
220
221 usb_phy->power_on_count++;
222 if (usb_phy->power_on_count != 1)
223 return 0;
224
225 if (usb_phy->gpio_vbus >= 0)
226 gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_UP);
227
228 return 0;
229}
230
231static int sun4i_usb_phy_power_off(struct phy *phy)
232{
233 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
234 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
235
236 usb_phy->power_on_count--;
237 if (usb_phy->power_on_count != 0)
238 return 0;
239
240 if (usb_phy->gpio_vbus >= 0)
241 gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_DISABLE);
242
243 return 0;
244}
245
246static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, bool id_det)
247{
248 u32 regval;
249
250 regval = readl(data->base + REG_PHY_OTGCTL);
251 if (!id_det) {
252 /* Host mode. Route phy0 to EHCI/OHCI */
253 regval &= ~OTGCTL_ROUTE_MUSB;
254 } else {
255 /* Peripheral mode. Route phy0 to MUSB */
256 regval |= OTGCTL_ROUTE_MUSB;
257 }
258 writel(regval, data->base + REG_PHY_OTGCTL);
259}
260
261static int sun4i_usb_phy_init(struct phy *phy)
262{
263 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
264 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
265 u32 val;
Jagan Teki089ffd02018-08-06 12:16:39 +0530266 int ret;
Jagan Teki67685942018-05-07 13:03:26 +0530267
Jagan Teki089ffd02018-08-06 12:16:39 +0530268 ret = clk_enable(&usb_phy->clocks);
269 if (ret) {
270 dev_err(dev, "failed to enable usb_%ldphy clock\n", phy->id);
271 return ret;
272 }
273
274 ret = reset_deassert(&usb_phy->resets);
275 if (ret) {
276 dev_err(dev, "failed to deassert usb_%ldreset reset\n", phy->id);
277 return ret;
278 }
Jagan Teki67685942018-05-07 13:03:26 +0530279
Jagan Teki5f646bf2018-05-07 13:03:30 +0530280 if (data->cfg->type == sun8i_a83t_phy) {
281 if (phy->id == 0) {
282 val = readl(data->base + data->cfg->phyctl_offset);
283 val |= PHY_CTL_VBUSVLDEXT;
284 val &= ~PHY_CTL_SIDDQ;
285 writel(val, data->base + data->cfg->phyctl_offset);
286 }
287 } else {
288 if (usb_phy->pmu && data->cfg->enable_pmu_unk1) {
289 val = readl(usb_phy->pmu + REG_PMU_UNK1);
290 writel(val & ~2, usb_phy->pmu + REG_PMU_UNK1);
291 }
292
293 if (usb_phy->id == 0)
294 sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN,
295 PHY_RES45_CAL_DATA,
296 PHY_RES45_CAL_LEN);
297
298 /* Adjust PHY's magnitude and rate */
299 sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE,
300 PHY_TX_MAGNITUDE | PHY_TX_RATE,
301 PHY_TX_AMPLITUDE_LEN);
302
303 /* Disconnect threshold adjustment */
304 sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
305 data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
Jagan Teki67685942018-05-07 13:03:26 +0530306 }
307
Jagan Teki0bfcb472018-07-20 12:34:20 +0530308 sun4i_usb_phy_passby(phy, true);
Jagan Teki67685942018-05-07 13:03:26 +0530309
310 sun4i_usb_phy0_reroute(data, true);
311
312 return 0;
313}
314
315static int sun4i_usb_phy_exit(struct phy *phy)
316{
317 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
318 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
Jagan Teki089ffd02018-08-06 12:16:39 +0530319 int ret;
Jagan Teki67685942018-05-07 13:03:26 +0530320
Jagan Teki5f646bf2018-05-07 13:03:30 +0530321 if (phy->id == 0) {
322 if (data->cfg->type == sun8i_a83t_phy) {
323 void __iomem *phyctl = data->base +
324 data->cfg->phyctl_offset;
325
326 writel(readl(phyctl) | PHY_CTL_SIDDQ, phyctl);
327 }
328 }
329
330 sun4i_usb_phy_passby(phy, false);
Jagan Teki67685942018-05-07 13:03:26 +0530331
Jagan Teki089ffd02018-08-06 12:16:39 +0530332 ret = clk_disable(&usb_phy->clocks);
333 if (ret) {
334 dev_err(dev, "failed to disable usb_%ldphy clock\n", phy->id);
335 return ret;
336 }
337
338 ret = reset_assert(&usb_phy->resets);
339 if (ret) {
340 dev_err(dev, "failed to assert usb_%ldreset reset\n", phy->id);
341 return ret;
342 }
Jagan Teki67685942018-05-07 13:03:26 +0530343
344 return 0;
345}
346
347static int sun4i_usb_phy_xlate(struct phy *phy,
348 struct ofnode_phandle_args *args)
349{
350 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
351
352 if (args->args_count >= data->cfg->num_phys)
353 return -EINVAL;
354
Andre Przywara35fa6732019-06-23 15:09:49 +0100355 if (data->cfg->missing_phys & BIT(args->args[0]))
356 return -ENODEV;
357
Jagan Teki67685942018-05-07 13:03:26 +0530358 if (args->args_count)
359 phy->id = args->args[0];
360 else
361 phy->id = 0;
362
363 debug("%s: phy_id = %ld\n", __func__, phy->id);
364 return 0;
365}
366
Jagan Teki129c45c2018-05-07 13:03:27 +0530367int sun4i_usb_phy_vbus_detect(struct phy *phy)
368{
369 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
370 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
371 int err, retries = 3;
372
373 debug("%s: id_det = %d\n", __func__, usb_phy->gpio_id_det);
374
375 if (usb_phy->gpio_vbus_det < 0)
376 return usb_phy->gpio_vbus_det;
377
378 err = gpio_get_value(usb_phy->gpio_vbus_det);
379 /*
380 * Vbus may have been provided by the board and just been turned of
381 * some milliseconds ago on reset, what we're measuring then is a
382 * residual charge on Vbus, sleep a bit and try again.
383 */
384 while (err > 0 && retries--) {
385 mdelay(100);
386 err = gpio_get_value(usb_phy->gpio_vbus_det);
387 }
388
389 return err;
390}
391
392int sun4i_usb_phy_id_detect(struct phy *phy)
393{
394 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
395 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
396
397 debug("%s: id_det = %d\n", __func__, usb_phy->gpio_id_det);
398
399 if (usb_phy->gpio_id_det < 0)
400 return usb_phy->gpio_id_det;
401
402 return gpio_get_value(usb_phy->gpio_id_det);
403}
404
Jagan Tekiaa29b112018-05-07 13:03:37 +0530405void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled)
406{
407 sun4i_usb_phy_write(phy, PHY_SQUELCH_DETECT, enabled ? 0 : 2, 2);
408}
409
Jagan Teki67685942018-05-07 13:03:26 +0530410static struct phy_ops sun4i_usb_phy_ops = {
411 .of_xlate = sun4i_usb_phy_xlate,
412 .init = sun4i_usb_phy_init,
413 .power_on = sun4i_usb_phy_power_on,
414 .power_off = sun4i_usb_phy_power_off,
415 .exit = sun4i_usb_phy_exit,
416};
417
418static int sun4i_usb_phy_probe(struct udevice *dev)
419{
420 struct sun4i_usb_phy_plat *plat = dev_get_platdata(dev);
421 struct sun4i_usb_phy_data *data = dev_get_priv(dev);
422 int i, ret;
423
424 data->cfg = (const struct sun4i_usb_phy_cfg *)dev_get_driver_data(dev);
425 if (!data->cfg)
426 return -EINVAL;
427
428 data->base = (void __iomem *)devfdt_get_addr_name(dev, "phy_ctrl");
429 if (IS_ERR(data->base))
430 return PTR_ERR(data->base);
431
Jagan Teki67685942018-05-07 13:03:26 +0530432 data->usb_phy = plat;
433 for (i = 0; i < data->cfg->num_phys; i++) {
434 struct sun4i_usb_phy_plat *phy = &plat[i];
435 struct sun4i_usb_phy_info *info = &phy_info[i];
436 char name[16];
437
Andre Przywara35fa6732019-06-23 15:09:49 +0100438 if (data->cfg->missing_phys & BIT(i))
439 continue;
440
Jagan Teki67685942018-05-07 13:03:26 +0530441 phy->gpio_vbus = sunxi_name_to_gpio(info->gpio_vbus);
442 if (phy->gpio_vbus >= 0) {
443 ret = gpio_request(phy->gpio_vbus, "usb_vbus");
444 if (ret)
445 return ret;
446 ret = gpio_direction_output(phy->gpio_vbus, 0);
447 if (ret)
448 return ret;
449 }
450
451 phy->gpio_vbus_det = sunxi_name_to_gpio(info->gpio_vbus_det);
452 if (phy->gpio_vbus_det >= 0) {
453 ret = gpio_request(phy->gpio_vbus_det, "usb_vbus_det");
454 if (ret)
455 return ret;
456 ret = gpio_direction_input(phy->gpio_vbus_det);
457 if (ret)
458 return ret;
459 }
460
461 phy->gpio_id_det = sunxi_name_to_gpio(info->gpio_id_det);
462 if (phy->gpio_id_det >= 0) {
463 ret = gpio_request(phy->gpio_id_det, "usb_id_det");
464 if (ret)
465 return ret;
466 ret = gpio_direction_input(phy->gpio_id_det);
467 if (ret)
468 return ret;
469 sunxi_gpio_set_pull(phy->gpio_id_det, SUNXI_GPIO_PULL_UP);
470 }
471
Jagan Teki089ffd02018-08-06 12:16:39 +0530472 if (data->cfg->dedicated_clocks)
473 snprintf(name, sizeof(name), "usb%d_phy", i);
474 else
475 strlcpy(name, "usb_phy", sizeof(name));
476
477 ret = clk_get_by_name(dev, name, &phy->clocks);
478 if (ret) {
479 dev_err(dev, "failed to get usb%d_phy clock phandle\n", i);
480 return ret;
481 }
482
483 snprintf(name, sizeof(name), "usb%d_reset", i);
484 ret = reset_get_by_name(dev, name, &phy->resets);
485 if (ret) {
486 dev_err(dev, "failed to get usb%d_reset reset phandle\n", i);
487 return ret;
488 }
489
Jagan Teki67685942018-05-07 13:03:26 +0530490 if (i || data->cfg->phy0_dual_route) {
491 snprintf(name, sizeof(name), "pmu%d", i);
492 phy->pmu = (void __iomem *)devfdt_get_addr_name(dev, name);
493 if (IS_ERR(phy->pmu))
494 return PTR_ERR(phy->pmu);
495 }
496
497 phy->id = i;
Jagan Teki67685942018-05-07 13:03:26 +0530498 };
499
Jagan Teki67685942018-05-07 13:03:26 +0530500 debug("Allwinner Sun4I USB PHY driver loaded\n");
501 return 0;
502}
503
Jagan Teki7f90b552018-05-07 13:03:31 +0530504static const struct sun4i_usb_phy_cfg sun4i_a10_cfg = {
505 .num_phys = 3,
506 .type = sun4i_a10_phy,
507 .disc_thresh = 3,
508 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530509 .dedicated_clocks = false,
Jagan Teki7f90b552018-05-07 13:03:31 +0530510 .enable_pmu_unk1 = false,
511};
512
513static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = {
514 .num_phys = 2,
515 .type = sun4i_a10_phy,
516 .disc_thresh = 2,
517 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530518 .dedicated_clocks = false,
Jagan Teki7f90b552018-05-07 13:03:31 +0530519 .enable_pmu_unk1 = false,
520};
521
Jagan Tekibf986d12018-05-07 13:03:32 +0530522static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = {
523 .num_phys = 3,
524 .type = sun6i_a31_phy,
525 .disc_thresh = 3,
526 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530527 .dedicated_clocks = true,
Jagan Tekibf986d12018-05-07 13:03:32 +0530528 .enable_pmu_unk1 = false,
529};
530
Jagan Teki7f90b552018-05-07 13:03:31 +0530531static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = {
532 .num_phys = 3,
533 .type = sun4i_a10_phy,
534 .disc_thresh = 2,
535 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530536 .dedicated_clocks = false,
Jagan Teki7f90b552018-05-07 13:03:31 +0530537 .enable_pmu_unk1 = false,
538};
539
Jagan Teki194ccb92018-05-07 13:03:34 +0530540static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = {
541 .num_phys = 2,
542 .type = sun4i_a10_phy,
543 .disc_thresh = 3,
544 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530545 .dedicated_clocks = true,
Jagan Teki194ccb92018-05-07 13:03:34 +0530546 .enable_pmu_unk1 = false,
547};
548
Jagan Teki61bf0ed2018-05-07 13:03:33 +0530549static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = {
550 .num_phys = 2,
551 .type = sun8i_a33_phy,
552 .disc_thresh = 3,
553 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530554 .dedicated_clocks = true,
Jagan Teki61bf0ed2018-05-07 13:03:33 +0530555 .enable_pmu_unk1 = false,
556};
557
Jagan Teki5f646bf2018-05-07 13:03:30 +0530558static const struct sun4i_usb_phy_cfg sun8i_a83t_cfg = {
559 .num_phys = 3,
560 .type = sun8i_a83t_phy,
561 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530562 .dedicated_clocks = true,
Jagan Teki5f646bf2018-05-07 13:03:30 +0530563};
564
Jagan Teki43519c42018-05-07 13:03:28 +0530565static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
566 .num_phys = 4,
567 .type = sun8i_h3_phy,
568 .disc_thresh = 3,
569 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530570 .dedicated_clocks = true,
Jagan Teki43519c42018-05-07 13:03:28 +0530571 .enable_pmu_unk1 = true,
572 .phy0_dual_route = true,
573};
574
Andre Przywaraa2f729f2020-01-01 23:44:48 +0000575static const struct sun4i_usb_phy_cfg sun8i_r40_cfg = {
576 .num_phys = 3,
577 .type = sun8i_r40_phy,
578 .disc_thresh = 3,
579 .phyctl_offset = REG_PHYCTL_A33,
580 .dedicated_clocks = true,
581 .enable_pmu_unk1 = true,
582 .phy0_dual_route = true,
583};
584
Jagan Tekibafe5e32018-05-07 13:03:29 +0530585static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
586 .num_phys = 1,
587 .type = sun8i_v3s_phy,
588 .disc_thresh = 3,
589 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530590 .dedicated_clocks = true,
Jagan Tekibafe5e32018-05-07 13:03:29 +0530591 .enable_pmu_unk1 = true,
592 .phy0_dual_route = true,
593};
594
Jagan Teki67685942018-05-07 13:03:26 +0530595static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = {
596 .num_phys = 2,
597 .type = sun50i_a64_phy,
598 .disc_thresh = 3,
599 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530600 .dedicated_clocks = true,
Jagan Teki67685942018-05-07 13:03:26 +0530601 .enable_pmu_unk1 = true,
602 .phy0_dual_route = true,
603};
604
Andre Przywara35fa6732019-06-23 15:09:49 +0100605static const struct sun4i_usb_phy_cfg sun50i_h6_cfg = {
606 .num_phys = 4,
607 .type = sun50i_h6_phy,
608 .disc_thresh = 3,
609 .phyctl_offset = REG_PHYCTL_A33,
610 .dedicated_clocks = true,
611 .enable_pmu_unk1 = true,
612 .phy0_dual_route = true,
613 .missing_phys = BIT(1) | BIT(2),
614};
615
Jagan Teki67685942018-05-07 13:03:26 +0530616static const struct udevice_id sun4i_usb_phy_ids[] = {
Jagan Teki7f90b552018-05-07 13:03:31 +0530617 { .compatible = "allwinner,sun4i-a10-usb-phy", .data = (ulong)&sun4i_a10_cfg },
618 { .compatible = "allwinner,sun5i-a13-usb-phy", .data = (ulong)&sun5i_a13_cfg },
Jagan Tekibf986d12018-05-07 13:03:32 +0530619 { .compatible = "allwinner,sun6i-a31-usb-phy", .data = (ulong)&sun6i_a31_cfg },
Jagan Teki7f90b552018-05-07 13:03:31 +0530620 { .compatible = "allwinner,sun7i-a20-usb-phy", .data = (ulong)&sun7i_a20_cfg },
Jagan Teki194ccb92018-05-07 13:03:34 +0530621 { .compatible = "allwinner,sun8i-a23-usb-phy", .data = (ulong)&sun8i_a23_cfg },
Jagan Teki61bf0ed2018-05-07 13:03:33 +0530622 { .compatible = "allwinner,sun8i-a33-usb-phy", .data = (ulong)&sun8i_a33_cfg },
Jagan Teki5f646bf2018-05-07 13:03:30 +0530623 { .compatible = "allwinner,sun8i-a83t-usb-phy", .data = (ulong)&sun8i_a83t_cfg },
Jagan Teki43519c42018-05-07 13:03:28 +0530624 { .compatible = "allwinner,sun8i-h3-usb-phy", .data = (ulong)&sun8i_h3_cfg },
Andre Przywaraa2f729f2020-01-01 23:44:48 +0000625 { .compatible = "allwinner,sun8i-r40-usb-phy", .data = (ulong)&sun8i_r40_cfg },
Jagan Tekibafe5e32018-05-07 13:03:29 +0530626 { .compatible = "allwinner,sun8i-v3s-usb-phy", .data = (ulong)&sun8i_v3s_cfg },
Jagan Teki67685942018-05-07 13:03:26 +0530627 { .compatible = "allwinner,sun50i-a64-usb-phy", .data = (ulong)&sun50i_a64_cfg},
Andre Przywara35fa6732019-06-23 15:09:49 +0100628 { .compatible = "allwinner,sun50i-h6-usb-phy", .data = (ulong)&sun50i_h6_cfg},
Jagan Teki67685942018-05-07 13:03:26 +0530629 { }
630};
631
632U_BOOT_DRIVER(sun4i_usb_phy) = {
633 .name = "sun4i_usb_phy",
634 .id = UCLASS_PHY,
635 .of_match = sun4i_usb_phy_ids,
636 .ops = &sun4i_usb_phy_ops,
637 .probe = sun4i_usb_phy_probe,
638 .platdata_auto_alloc_size = sizeof(struct sun4i_usb_phy_plat[MAX_PHYS]),
639 .priv_auto_alloc_size = sizeof(struct sun4i_usb_phy_data),
640};