blob: 2c12fa6976d59ba5b553cfaf85d535ab74705afe [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>
Simon Glass61b29b82020-02-03 07:36:15 -070024#include <linux/err.h>
Jagan Teki67685942018-05-07 13:03:26 +053025
26#define REG_ISCR 0x00
27#define REG_PHYCTL_A10 0x04
28#define REG_PHYBIST 0x08
29#define REG_PHYTUNE 0x0c
30#define REG_PHYCTL_A33 0x10
31#define REG_PHY_OTGCTL 0x20
32#define REG_PMU_UNK1 0x10
33
34/* Common Control Bits for Both PHYs */
35#define PHY_PLL_BW 0x03
36#define PHY_RES45_CAL_EN 0x0c
37
38/* Private Control Bits for Each PHY */
39#define PHY_TX_AMPLITUDE_TUNE 0x20
40#define PHY_TX_SLEWRATE_TUNE 0x22
41#define PHY_DISCON_TH_SEL 0x2a
Jagan Tekiaa29b112018-05-07 13:03:37 +053042#define PHY_SQUELCH_DETECT 0x3c
Jagan Teki67685942018-05-07 13:03:26 +053043
44#define PHYCTL_DATA BIT(7)
45#define OTGCTL_ROUTE_MUSB BIT(0)
46
47#define PHY_TX_RATE BIT(4)
48#define PHY_TX_MAGNITUDE BIT(2)
49#define PHY_TX_AMPLITUDE_LEN 5
50
51#define PHY_RES45_CAL_DATA BIT(0)
52#define PHY_RES45_CAL_LEN 1
53#define PHY_DISCON_TH_LEN 2
54
55#define SUNXI_AHB_ICHR8_EN BIT(10)
56#define SUNXI_AHB_INCR4_BURST_EN BIT(9)
57#define SUNXI_AHB_INCRX_ALIGN_EN BIT(8)
58#define SUNXI_ULPI_BYPASS_EN BIT(0)
59
Jagan Teki5f646bf2018-05-07 13:03:30 +053060/* A83T specific control bits for PHY0 */
61#define PHY_CTL_VBUSVLDEXT BIT(5)
62#define PHY_CTL_SIDDQ BIT(3)
63
64/* A83T specific control bits for PHY2 HSIC */
65#define SUNXI_EHCI_HS_FORCE BIT(20)
66#define SUNXI_HSIC_CONNECT_INT BIT(16)
67#define SUNXI_HSIC BIT(1)
68
Jagan Teki67685942018-05-07 13:03:26 +053069#define MAX_PHYS 4
70
71enum sun4i_usb_phy_type {
Jagan Teki7f90b552018-05-07 13:03:31 +053072 sun4i_a10_phy,
Jagan Tekibf986d12018-05-07 13:03:32 +053073 sun6i_a31_phy,
Jagan Teki61bf0ed2018-05-07 13:03:33 +053074 sun8i_a33_phy,
Jagan Teki5f646bf2018-05-07 13:03:30 +053075 sun8i_a83t_phy,
Jagan Teki43519c42018-05-07 13:03:28 +053076 sun8i_h3_phy,
Andre Przywaraa2f729f2020-01-01 23:44:48 +000077 sun8i_r40_phy,
Jagan Tekibafe5e32018-05-07 13:03:29 +053078 sun8i_v3s_phy,
Jagan Teki67685942018-05-07 13:03:26 +053079 sun50i_a64_phy,
Andre Przywara35fa6732019-06-23 15:09:49 +010080 sun50i_h6_phy,
Jagan Teki67685942018-05-07 13:03:26 +053081};
82
83struct sun4i_usb_phy_cfg {
84 int num_phys;
85 enum sun4i_usb_phy_type type;
86 u32 disc_thresh;
87 u8 phyctl_offset;
Jagan Teki089ffd02018-08-06 12:16:39 +053088 bool dedicated_clocks;
Jagan Teki67685942018-05-07 13:03:26 +053089 bool enable_pmu_unk1;
90 bool phy0_dual_route;
Andre Przywara35fa6732019-06-23 15:09:49 +010091 int missing_phys;
Jagan Teki67685942018-05-07 13:03:26 +053092};
93
94struct sun4i_usb_phy_info {
95 const char *gpio_vbus;
96 const char *gpio_vbus_det;
97 const char *gpio_id_det;
Jagan Teki67685942018-05-07 13:03:26 +053098} phy_info[] = {
99 {
100 .gpio_vbus = CONFIG_USB0_VBUS_PIN,
101 .gpio_vbus_det = CONFIG_USB0_VBUS_DET,
102 .gpio_id_det = CONFIG_USB0_ID_DET,
Jagan Teki67685942018-05-07 13:03:26 +0530103 },
104 {
105 .gpio_vbus = CONFIG_USB1_VBUS_PIN,
106 .gpio_vbus_det = NULL,
107 .gpio_id_det = NULL,
Jagan Teki67685942018-05-07 13:03:26 +0530108 },
109 {
110 .gpio_vbus = CONFIG_USB2_VBUS_PIN,
111 .gpio_vbus_det = NULL,
112 .gpio_id_det = NULL,
Jagan Teki67685942018-05-07 13:03:26 +0530113 },
114 {
115 .gpio_vbus = CONFIG_USB3_VBUS_PIN,
116 .gpio_vbus_det = NULL,
117 .gpio_id_det = NULL,
Jagan Teki67685942018-05-07 13:03:26 +0530118 },
119};
120
121struct sun4i_usb_phy_plat {
122 void __iomem *pmu;
123 int power_on_count;
124 int gpio_vbus;
125 int gpio_vbus_det;
126 int gpio_id_det;
Jagan Teki089ffd02018-08-06 12:16:39 +0530127 struct clk clocks;
128 struct reset_ctl resets;
Jagan Teki67685942018-05-07 13:03:26 +0530129 int id;
130};
131
132struct sun4i_usb_phy_data {
133 void __iomem *base;
Jagan Teki67685942018-05-07 13:03:26 +0530134 const struct sun4i_usb_phy_cfg *cfg;
135 struct sun4i_usb_phy_plat *usb_phy;
136};
137
138static int initial_usb_scan_delay = CONFIG_INITIAL_USB_SCAN_DELAY;
139
140static void sun4i_usb_phy_write(struct phy *phy, u32 addr, u32 data, int len)
141{
142 struct sun4i_usb_phy_data *phy_data = dev_get_priv(phy->dev);
143 struct sun4i_usb_phy_plat *usb_phy = &phy_data->usb_phy[phy->id];
144 u32 temp, usbc_bit = BIT(usb_phy->id * 2);
145 void __iomem *phyctl = phy_data->base + phy_data->cfg->phyctl_offset;
146 int i;
147
148 if (phy_data->cfg->phyctl_offset == REG_PHYCTL_A33) {
149 /* SoCs newer than A33 need us to set phyctl to 0 explicitly */
150 writel(0, phyctl);
151 }
152
153 for (i = 0; i < len; i++) {
154 temp = readl(phyctl);
155
156 /* clear the address portion */
157 temp &= ~(0xff << 8);
158
159 /* set the address */
160 temp |= ((addr + i) << 8);
161 writel(temp, phyctl);
162
163 /* set the data bit and clear usbc bit*/
164 temp = readb(phyctl);
165 if (data & 0x1)
166 temp |= PHYCTL_DATA;
167 else
168 temp &= ~PHYCTL_DATA;
169 temp &= ~usbc_bit;
170 writeb(temp, phyctl);
171
172 /* pulse usbc_bit */
173 temp = readb(phyctl);
174 temp |= usbc_bit;
175 writeb(temp, phyctl);
176
177 temp = readb(phyctl);
178 temp &= ~usbc_bit;
179 writeb(temp, phyctl);
180
181 data >>= 1;
182 }
183}
184
Jagan Teki5f646bf2018-05-07 13:03:30 +0530185static void sun4i_usb_phy_passby(struct phy *phy, bool enable)
Jagan Teki67685942018-05-07 13:03:26 +0530186{
Jagan Teki5f646bf2018-05-07 13:03:30 +0530187 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
188 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
Jagan Teki67685942018-05-07 13:03:26 +0530189 u32 bits, reg_value;
190
191 if (!usb_phy->pmu)
192 return;
193
194 bits = SUNXI_AHB_ICHR8_EN | SUNXI_AHB_INCR4_BURST_EN |
195 SUNXI_AHB_INCRX_ALIGN_EN | SUNXI_ULPI_BYPASS_EN;
Jagan Teki5f646bf2018-05-07 13:03:30 +0530196
197 /* A83T USB2 is HSIC */
198 if (data->cfg->type == sun8i_a83t_phy && usb_phy->id == 2)
199 bits |= SUNXI_EHCI_HS_FORCE | SUNXI_HSIC_CONNECT_INT |
200 SUNXI_HSIC;
201
Jagan Teki67685942018-05-07 13:03:26 +0530202 reg_value = readl(usb_phy->pmu);
203
204 if (enable)
205 reg_value |= bits;
206 else
207 reg_value &= ~bits;
208
209 writel(reg_value, usb_phy->pmu);
210}
211
212static int sun4i_usb_phy_power_on(struct phy *phy)
213{
214 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
215 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
216
217 if (initial_usb_scan_delay) {
218 mdelay(initial_usb_scan_delay);
219 initial_usb_scan_delay = 0;
220 }
221
222 usb_phy->power_on_count++;
223 if (usb_phy->power_on_count != 1)
224 return 0;
225
226 if (usb_phy->gpio_vbus >= 0)
227 gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_UP);
228
229 return 0;
230}
231
232static int sun4i_usb_phy_power_off(struct phy *phy)
233{
234 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
235 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
236
237 usb_phy->power_on_count--;
238 if (usb_phy->power_on_count != 0)
239 return 0;
240
241 if (usb_phy->gpio_vbus >= 0)
242 gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_DISABLE);
243
244 return 0;
245}
246
247static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, bool id_det)
248{
249 u32 regval;
250
251 regval = readl(data->base + REG_PHY_OTGCTL);
252 if (!id_det) {
253 /* Host mode. Route phy0 to EHCI/OHCI */
254 regval &= ~OTGCTL_ROUTE_MUSB;
255 } else {
256 /* Peripheral mode. Route phy0 to MUSB */
257 regval |= OTGCTL_ROUTE_MUSB;
258 }
259 writel(regval, data->base + REG_PHY_OTGCTL);
260}
261
262static int sun4i_usb_phy_init(struct phy *phy)
263{
264 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
265 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
266 u32 val;
Jagan Teki089ffd02018-08-06 12:16:39 +0530267 int ret;
Jagan Teki67685942018-05-07 13:03:26 +0530268
Jagan Teki089ffd02018-08-06 12:16:39 +0530269 ret = clk_enable(&usb_phy->clocks);
270 if (ret) {
271 dev_err(dev, "failed to enable usb_%ldphy clock\n", phy->id);
272 return ret;
273 }
274
275 ret = reset_deassert(&usb_phy->resets);
276 if (ret) {
277 dev_err(dev, "failed to deassert usb_%ldreset reset\n", phy->id);
278 return ret;
279 }
Jagan Teki67685942018-05-07 13:03:26 +0530280
Jagan Teki5f646bf2018-05-07 13:03:30 +0530281 if (data->cfg->type == sun8i_a83t_phy) {
282 if (phy->id == 0) {
283 val = readl(data->base + data->cfg->phyctl_offset);
284 val |= PHY_CTL_VBUSVLDEXT;
285 val &= ~PHY_CTL_SIDDQ;
286 writel(val, data->base + data->cfg->phyctl_offset);
287 }
288 } else {
289 if (usb_phy->pmu && data->cfg->enable_pmu_unk1) {
290 val = readl(usb_phy->pmu + REG_PMU_UNK1);
291 writel(val & ~2, usb_phy->pmu + REG_PMU_UNK1);
292 }
293
294 if (usb_phy->id == 0)
295 sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN,
296 PHY_RES45_CAL_DATA,
297 PHY_RES45_CAL_LEN);
298
299 /* Adjust PHY's magnitude and rate */
300 sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE,
301 PHY_TX_MAGNITUDE | PHY_TX_RATE,
302 PHY_TX_AMPLITUDE_LEN);
303
304 /* Disconnect threshold adjustment */
305 sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
306 data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
Jagan Teki67685942018-05-07 13:03:26 +0530307 }
308
Jagan Teki0bfcb472018-07-20 12:34:20 +0530309 sun4i_usb_phy_passby(phy, true);
Jagan Teki67685942018-05-07 13:03:26 +0530310
311 sun4i_usb_phy0_reroute(data, true);
312
313 return 0;
314}
315
316static int sun4i_usb_phy_exit(struct phy *phy)
317{
318 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
319 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
Jagan Teki089ffd02018-08-06 12:16:39 +0530320 int ret;
Jagan Teki67685942018-05-07 13:03:26 +0530321
Jagan Teki5f646bf2018-05-07 13:03:30 +0530322 if (phy->id == 0) {
323 if (data->cfg->type == sun8i_a83t_phy) {
324 void __iomem *phyctl = data->base +
325 data->cfg->phyctl_offset;
326
327 writel(readl(phyctl) | PHY_CTL_SIDDQ, phyctl);
328 }
329 }
330
331 sun4i_usb_phy_passby(phy, false);
Jagan Teki67685942018-05-07 13:03:26 +0530332
Jagan Teki089ffd02018-08-06 12:16:39 +0530333 ret = clk_disable(&usb_phy->clocks);
334 if (ret) {
335 dev_err(dev, "failed to disable usb_%ldphy clock\n", phy->id);
336 return ret;
337 }
338
339 ret = reset_assert(&usb_phy->resets);
340 if (ret) {
341 dev_err(dev, "failed to assert usb_%ldreset reset\n", phy->id);
342 return ret;
343 }
Jagan Teki67685942018-05-07 13:03:26 +0530344
345 return 0;
346}
347
348static int sun4i_usb_phy_xlate(struct phy *phy,
349 struct ofnode_phandle_args *args)
350{
351 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
352
353 if (args->args_count >= data->cfg->num_phys)
354 return -EINVAL;
355
Andre Przywara35fa6732019-06-23 15:09:49 +0100356 if (data->cfg->missing_phys & BIT(args->args[0]))
357 return -ENODEV;
358
Jagan Teki67685942018-05-07 13:03:26 +0530359 if (args->args_count)
360 phy->id = args->args[0];
361 else
362 phy->id = 0;
363
364 debug("%s: phy_id = %ld\n", __func__, phy->id);
365 return 0;
366}
367
Jagan Teki129c45c2018-05-07 13:03:27 +0530368int sun4i_usb_phy_vbus_detect(struct phy *phy)
369{
370 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
371 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
372 int err, retries = 3;
373
374 debug("%s: id_det = %d\n", __func__, usb_phy->gpio_id_det);
375
376 if (usb_phy->gpio_vbus_det < 0)
377 return usb_phy->gpio_vbus_det;
378
379 err = gpio_get_value(usb_phy->gpio_vbus_det);
380 /*
381 * Vbus may have been provided by the board and just been turned of
382 * some milliseconds ago on reset, what we're measuring then is a
383 * residual charge on Vbus, sleep a bit and try again.
384 */
385 while (err > 0 && retries--) {
386 mdelay(100);
387 err = gpio_get_value(usb_phy->gpio_vbus_det);
388 }
389
390 return err;
391}
392
393int sun4i_usb_phy_id_detect(struct phy *phy)
394{
395 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
396 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
397
398 debug("%s: id_det = %d\n", __func__, usb_phy->gpio_id_det);
399
400 if (usb_phy->gpio_id_det < 0)
401 return usb_phy->gpio_id_det;
402
403 return gpio_get_value(usb_phy->gpio_id_det);
404}
405
Jagan Tekiaa29b112018-05-07 13:03:37 +0530406void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled)
407{
408 sun4i_usb_phy_write(phy, PHY_SQUELCH_DETECT, enabled ? 0 : 2, 2);
409}
410
Jagan Teki67685942018-05-07 13:03:26 +0530411static struct phy_ops sun4i_usb_phy_ops = {
412 .of_xlate = sun4i_usb_phy_xlate,
413 .init = sun4i_usb_phy_init,
414 .power_on = sun4i_usb_phy_power_on,
415 .power_off = sun4i_usb_phy_power_off,
416 .exit = sun4i_usb_phy_exit,
417};
418
419static int sun4i_usb_phy_probe(struct udevice *dev)
420{
421 struct sun4i_usb_phy_plat *plat = dev_get_platdata(dev);
422 struct sun4i_usb_phy_data *data = dev_get_priv(dev);
423 int i, ret;
424
425 data->cfg = (const struct sun4i_usb_phy_cfg *)dev_get_driver_data(dev);
426 if (!data->cfg)
427 return -EINVAL;
428
429 data->base = (void __iomem *)devfdt_get_addr_name(dev, "phy_ctrl");
430 if (IS_ERR(data->base))
431 return PTR_ERR(data->base);
432
Jagan Teki67685942018-05-07 13:03:26 +0530433 data->usb_phy = plat;
434 for (i = 0; i < data->cfg->num_phys; i++) {
435 struct sun4i_usb_phy_plat *phy = &plat[i];
436 struct sun4i_usb_phy_info *info = &phy_info[i];
437 char name[16];
438
Andre Przywara35fa6732019-06-23 15:09:49 +0100439 if (data->cfg->missing_phys & BIT(i))
440 continue;
441
Jagan Teki67685942018-05-07 13:03:26 +0530442 phy->gpio_vbus = sunxi_name_to_gpio(info->gpio_vbus);
443 if (phy->gpio_vbus >= 0) {
444 ret = gpio_request(phy->gpio_vbus, "usb_vbus");
445 if (ret)
446 return ret;
447 ret = gpio_direction_output(phy->gpio_vbus, 0);
448 if (ret)
449 return ret;
450 }
451
452 phy->gpio_vbus_det = sunxi_name_to_gpio(info->gpio_vbus_det);
453 if (phy->gpio_vbus_det >= 0) {
454 ret = gpio_request(phy->gpio_vbus_det, "usb_vbus_det");
455 if (ret)
456 return ret;
457 ret = gpio_direction_input(phy->gpio_vbus_det);
458 if (ret)
459 return ret;
460 }
461
462 phy->gpio_id_det = sunxi_name_to_gpio(info->gpio_id_det);
463 if (phy->gpio_id_det >= 0) {
464 ret = gpio_request(phy->gpio_id_det, "usb_id_det");
465 if (ret)
466 return ret;
467 ret = gpio_direction_input(phy->gpio_id_det);
468 if (ret)
469 return ret;
470 sunxi_gpio_set_pull(phy->gpio_id_det, SUNXI_GPIO_PULL_UP);
471 }
472
Jagan Teki089ffd02018-08-06 12:16:39 +0530473 if (data->cfg->dedicated_clocks)
474 snprintf(name, sizeof(name), "usb%d_phy", i);
475 else
476 strlcpy(name, "usb_phy", sizeof(name));
477
478 ret = clk_get_by_name(dev, name, &phy->clocks);
479 if (ret) {
480 dev_err(dev, "failed to get usb%d_phy clock phandle\n", i);
481 return ret;
482 }
483
484 snprintf(name, sizeof(name), "usb%d_reset", i);
485 ret = reset_get_by_name(dev, name, &phy->resets);
486 if (ret) {
487 dev_err(dev, "failed to get usb%d_reset reset phandle\n", i);
488 return ret;
489 }
490
Jagan Teki67685942018-05-07 13:03:26 +0530491 if (i || data->cfg->phy0_dual_route) {
492 snprintf(name, sizeof(name), "pmu%d", i);
493 phy->pmu = (void __iomem *)devfdt_get_addr_name(dev, name);
494 if (IS_ERR(phy->pmu))
495 return PTR_ERR(phy->pmu);
496 }
497
498 phy->id = i;
Jagan Teki67685942018-05-07 13:03:26 +0530499 };
500
Jagan Teki67685942018-05-07 13:03:26 +0530501 debug("Allwinner Sun4I USB PHY driver loaded\n");
502 return 0;
503}
504
Jagan Teki7f90b552018-05-07 13:03:31 +0530505static const struct sun4i_usb_phy_cfg sun4i_a10_cfg = {
506 .num_phys = 3,
507 .type = sun4i_a10_phy,
508 .disc_thresh = 3,
509 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530510 .dedicated_clocks = false,
Jagan Teki7f90b552018-05-07 13:03:31 +0530511 .enable_pmu_unk1 = false,
512};
513
514static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = {
515 .num_phys = 2,
516 .type = sun4i_a10_phy,
517 .disc_thresh = 2,
518 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530519 .dedicated_clocks = false,
Jagan Teki7f90b552018-05-07 13:03:31 +0530520 .enable_pmu_unk1 = false,
521};
522
Jagan Tekibf986d12018-05-07 13:03:32 +0530523static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = {
524 .num_phys = 3,
525 .type = sun6i_a31_phy,
526 .disc_thresh = 3,
527 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530528 .dedicated_clocks = true,
Jagan Tekibf986d12018-05-07 13:03:32 +0530529 .enable_pmu_unk1 = false,
530};
531
Jagan Teki7f90b552018-05-07 13:03:31 +0530532static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = {
533 .num_phys = 3,
534 .type = sun4i_a10_phy,
535 .disc_thresh = 2,
536 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530537 .dedicated_clocks = false,
Jagan Teki7f90b552018-05-07 13:03:31 +0530538 .enable_pmu_unk1 = false,
539};
540
Jagan Teki194ccb92018-05-07 13:03:34 +0530541static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = {
542 .num_phys = 2,
543 .type = sun4i_a10_phy,
544 .disc_thresh = 3,
545 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530546 .dedicated_clocks = true,
Jagan Teki194ccb92018-05-07 13:03:34 +0530547 .enable_pmu_unk1 = false,
548};
549
Jagan Teki61bf0ed2018-05-07 13:03:33 +0530550static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = {
551 .num_phys = 2,
552 .type = sun8i_a33_phy,
553 .disc_thresh = 3,
554 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530555 .dedicated_clocks = true,
Jagan Teki61bf0ed2018-05-07 13:03:33 +0530556 .enable_pmu_unk1 = false,
557};
558
Jagan Teki5f646bf2018-05-07 13:03:30 +0530559static const struct sun4i_usb_phy_cfg sun8i_a83t_cfg = {
560 .num_phys = 3,
561 .type = sun8i_a83t_phy,
562 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530563 .dedicated_clocks = true,
Jagan Teki5f646bf2018-05-07 13:03:30 +0530564};
565
Jagan Teki43519c42018-05-07 13:03:28 +0530566static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
567 .num_phys = 4,
568 .type = sun8i_h3_phy,
569 .disc_thresh = 3,
570 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530571 .dedicated_clocks = true,
Jagan Teki43519c42018-05-07 13:03:28 +0530572 .enable_pmu_unk1 = true,
573 .phy0_dual_route = true,
574};
575
Andre Przywaraa2f729f2020-01-01 23:44:48 +0000576static const struct sun4i_usb_phy_cfg sun8i_r40_cfg = {
577 .num_phys = 3,
578 .type = sun8i_r40_phy,
579 .disc_thresh = 3,
580 .phyctl_offset = REG_PHYCTL_A33,
581 .dedicated_clocks = true,
582 .enable_pmu_unk1 = true,
583 .phy0_dual_route = true,
584};
585
Jagan Tekibafe5e32018-05-07 13:03:29 +0530586static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
587 .num_phys = 1,
588 .type = sun8i_v3s_phy,
589 .disc_thresh = 3,
590 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530591 .dedicated_clocks = true,
Jagan Tekibafe5e32018-05-07 13:03:29 +0530592 .enable_pmu_unk1 = true,
593 .phy0_dual_route = true,
594};
595
Jagan Teki67685942018-05-07 13:03:26 +0530596static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = {
597 .num_phys = 2,
598 .type = sun50i_a64_phy,
599 .disc_thresh = 3,
600 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530601 .dedicated_clocks = true,
Jagan Teki67685942018-05-07 13:03:26 +0530602 .enable_pmu_unk1 = true,
603 .phy0_dual_route = true,
604};
605
Andre Przywara35fa6732019-06-23 15:09:49 +0100606static const struct sun4i_usb_phy_cfg sun50i_h6_cfg = {
607 .num_phys = 4,
608 .type = sun50i_h6_phy,
609 .disc_thresh = 3,
610 .phyctl_offset = REG_PHYCTL_A33,
611 .dedicated_clocks = true,
612 .enable_pmu_unk1 = true,
613 .phy0_dual_route = true,
614 .missing_phys = BIT(1) | BIT(2),
615};
616
Jagan Teki67685942018-05-07 13:03:26 +0530617static const struct udevice_id sun4i_usb_phy_ids[] = {
Jagan Teki7f90b552018-05-07 13:03:31 +0530618 { .compatible = "allwinner,sun4i-a10-usb-phy", .data = (ulong)&sun4i_a10_cfg },
619 { .compatible = "allwinner,sun5i-a13-usb-phy", .data = (ulong)&sun5i_a13_cfg },
Jagan Tekibf986d12018-05-07 13:03:32 +0530620 { .compatible = "allwinner,sun6i-a31-usb-phy", .data = (ulong)&sun6i_a31_cfg },
Jagan Teki7f90b552018-05-07 13:03:31 +0530621 { .compatible = "allwinner,sun7i-a20-usb-phy", .data = (ulong)&sun7i_a20_cfg },
Jagan Teki194ccb92018-05-07 13:03:34 +0530622 { .compatible = "allwinner,sun8i-a23-usb-phy", .data = (ulong)&sun8i_a23_cfg },
Jagan Teki61bf0ed2018-05-07 13:03:33 +0530623 { .compatible = "allwinner,sun8i-a33-usb-phy", .data = (ulong)&sun8i_a33_cfg },
Jagan Teki5f646bf2018-05-07 13:03:30 +0530624 { .compatible = "allwinner,sun8i-a83t-usb-phy", .data = (ulong)&sun8i_a83t_cfg },
Jagan Teki43519c42018-05-07 13:03:28 +0530625 { .compatible = "allwinner,sun8i-h3-usb-phy", .data = (ulong)&sun8i_h3_cfg },
Andre Przywaraa2f729f2020-01-01 23:44:48 +0000626 { .compatible = "allwinner,sun8i-r40-usb-phy", .data = (ulong)&sun8i_r40_cfg },
Jagan Tekibafe5e32018-05-07 13:03:29 +0530627 { .compatible = "allwinner,sun8i-v3s-usb-phy", .data = (ulong)&sun8i_v3s_cfg },
Jagan Teki67685942018-05-07 13:03:26 +0530628 { .compatible = "allwinner,sun50i-a64-usb-phy", .data = (ulong)&sun50i_a64_cfg},
Andre Przywara35fa6732019-06-23 15:09:49 +0100629 { .compatible = "allwinner,sun50i-h6-usb-phy", .data = (ulong)&sun50i_h6_cfg},
Jagan Teki67685942018-05-07 13:03:26 +0530630 { }
631};
632
633U_BOOT_DRIVER(sun4i_usb_phy) = {
634 .name = "sun4i_usb_phy",
635 .id = UCLASS_PHY,
636 .of_match = sun4i_usb_phy_ids,
637 .ops = &sun4i_usb_phy_ops,
638 .probe = sun4i_usb_phy_probe,
639 .platdata_auto_alloc_size = sizeof(struct sun4i_usb_phy_plat[MAX_PHYS]),
640 .priv_auto_alloc_size = sizeof(struct sun4i_usb_phy_data),
641};