blob: f206fa3f5d48250512c89881bf20ddf4860f9c37 [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,
Jagan Tekibafe5e32018-05-07 13:03:29 +053076 sun8i_v3s_phy,
Jagan Teki67685942018-05-07 13:03:26 +053077 sun50i_a64_phy,
78};
79
80struct sun4i_usb_phy_cfg {
81 int num_phys;
82 enum sun4i_usb_phy_type type;
83 u32 disc_thresh;
84 u8 phyctl_offset;
Jagan Teki089ffd02018-08-06 12:16:39 +053085 bool dedicated_clocks;
Jagan Teki67685942018-05-07 13:03:26 +053086 bool enable_pmu_unk1;
87 bool phy0_dual_route;
88};
89
90struct sun4i_usb_phy_info {
91 const char *gpio_vbus;
92 const char *gpio_vbus_det;
93 const char *gpio_id_det;
Jagan Teki67685942018-05-07 13:03:26 +053094} phy_info[] = {
95 {
96 .gpio_vbus = CONFIG_USB0_VBUS_PIN,
97 .gpio_vbus_det = CONFIG_USB0_VBUS_DET,
98 .gpio_id_det = CONFIG_USB0_ID_DET,
Jagan Teki67685942018-05-07 13:03:26 +053099 },
100 {
101 .gpio_vbus = CONFIG_USB1_VBUS_PIN,
102 .gpio_vbus_det = NULL,
103 .gpio_id_det = NULL,
Jagan Teki67685942018-05-07 13:03:26 +0530104 },
105 {
106 .gpio_vbus = CONFIG_USB2_VBUS_PIN,
107 .gpio_vbus_det = NULL,
108 .gpio_id_det = NULL,
Jagan Teki67685942018-05-07 13:03:26 +0530109 },
110 {
111 .gpio_vbus = CONFIG_USB3_VBUS_PIN,
112 .gpio_vbus_det = NULL,
113 .gpio_id_det = NULL,
Jagan Teki67685942018-05-07 13:03:26 +0530114 },
115};
116
117struct sun4i_usb_phy_plat {
118 void __iomem *pmu;
119 int power_on_count;
120 int gpio_vbus;
121 int gpio_vbus_det;
122 int gpio_id_det;
Jagan Teki089ffd02018-08-06 12:16:39 +0530123 struct clk clocks;
124 struct reset_ctl resets;
Jagan Teki67685942018-05-07 13:03:26 +0530125 int id;
126};
127
128struct sun4i_usb_phy_data {
129 void __iomem *base;
Jagan Teki67685942018-05-07 13:03:26 +0530130 const struct sun4i_usb_phy_cfg *cfg;
131 struct sun4i_usb_phy_plat *usb_phy;
132};
133
134static int initial_usb_scan_delay = CONFIG_INITIAL_USB_SCAN_DELAY;
135
136static void sun4i_usb_phy_write(struct phy *phy, u32 addr, u32 data, int len)
137{
138 struct sun4i_usb_phy_data *phy_data = dev_get_priv(phy->dev);
139 struct sun4i_usb_phy_plat *usb_phy = &phy_data->usb_phy[phy->id];
140 u32 temp, usbc_bit = BIT(usb_phy->id * 2);
141 void __iomem *phyctl = phy_data->base + phy_data->cfg->phyctl_offset;
142 int i;
143
144 if (phy_data->cfg->phyctl_offset == REG_PHYCTL_A33) {
145 /* SoCs newer than A33 need us to set phyctl to 0 explicitly */
146 writel(0, phyctl);
147 }
148
149 for (i = 0; i < len; i++) {
150 temp = readl(phyctl);
151
152 /* clear the address portion */
153 temp &= ~(0xff << 8);
154
155 /* set the address */
156 temp |= ((addr + i) << 8);
157 writel(temp, phyctl);
158
159 /* set the data bit and clear usbc bit*/
160 temp = readb(phyctl);
161 if (data & 0x1)
162 temp |= PHYCTL_DATA;
163 else
164 temp &= ~PHYCTL_DATA;
165 temp &= ~usbc_bit;
166 writeb(temp, phyctl);
167
168 /* pulse usbc_bit */
169 temp = readb(phyctl);
170 temp |= usbc_bit;
171 writeb(temp, phyctl);
172
173 temp = readb(phyctl);
174 temp &= ~usbc_bit;
175 writeb(temp, phyctl);
176
177 data >>= 1;
178 }
179}
180
Jagan Teki5f646bf2018-05-07 13:03:30 +0530181static void sun4i_usb_phy_passby(struct phy *phy, bool enable)
Jagan Teki67685942018-05-07 13:03:26 +0530182{
Jagan Teki5f646bf2018-05-07 13:03:30 +0530183 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
184 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
Jagan Teki67685942018-05-07 13:03:26 +0530185 u32 bits, reg_value;
186
187 if (!usb_phy->pmu)
188 return;
189
190 bits = SUNXI_AHB_ICHR8_EN | SUNXI_AHB_INCR4_BURST_EN |
191 SUNXI_AHB_INCRX_ALIGN_EN | SUNXI_ULPI_BYPASS_EN;
Jagan Teki5f646bf2018-05-07 13:03:30 +0530192
193 /* A83T USB2 is HSIC */
194 if (data->cfg->type == sun8i_a83t_phy && usb_phy->id == 2)
195 bits |= SUNXI_EHCI_HS_FORCE | SUNXI_HSIC_CONNECT_INT |
196 SUNXI_HSIC;
197
Jagan Teki67685942018-05-07 13:03:26 +0530198 reg_value = readl(usb_phy->pmu);
199
200 if (enable)
201 reg_value |= bits;
202 else
203 reg_value &= ~bits;
204
205 writel(reg_value, usb_phy->pmu);
206}
207
208static int sun4i_usb_phy_power_on(struct phy *phy)
209{
210 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
211 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
212
213 if (initial_usb_scan_delay) {
214 mdelay(initial_usb_scan_delay);
215 initial_usb_scan_delay = 0;
216 }
217
218 usb_phy->power_on_count++;
219 if (usb_phy->power_on_count != 1)
220 return 0;
221
222 if (usb_phy->gpio_vbus >= 0)
223 gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_UP);
224
225 return 0;
226}
227
228static int sun4i_usb_phy_power_off(struct phy *phy)
229{
230 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
231 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
232
233 usb_phy->power_on_count--;
234 if (usb_phy->power_on_count != 0)
235 return 0;
236
237 if (usb_phy->gpio_vbus >= 0)
238 gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_DISABLE);
239
240 return 0;
241}
242
243static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, bool id_det)
244{
245 u32 regval;
246
247 regval = readl(data->base + REG_PHY_OTGCTL);
248 if (!id_det) {
249 /* Host mode. Route phy0 to EHCI/OHCI */
250 regval &= ~OTGCTL_ROUTE_MUSB;
251 } else {
252 /* Peripheral mode. Route phy0 to MUSB */
253 regval |= OTGCTL_ROUTE_MUSB;
254 }
255 writel(regval, data->base + REG_PHY_OTGCTL);
256}
257
258static int sun4i_usb_phy_init(struct phy *phy)
259{
260 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
261 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
262 u32 val;
Jagan Teki089ffd02018-08-06 12:16:39 +0530263 int ret;
Jagan Teki67685942018-05-07 13:03:26 +0530264
Jagan Teki089ffd02018-08-06 12:16:39 +0530265 ret = clk_enable(&usb_phy->clocks);
266 if (ret) {
267 dev_err(dev, "failed to enable usb_%ldphy clock\n", phy->id);
268 return ret;
269 }
270
271 ret = reset_deassert(&usb_phy->resets);
272 if (ret) {
273 dev_err(dev, "failed to deassert usb_%ldreset reset\n", phy->id);
274 return ret;
275 }
Jagan Teki67685942018-05-07 13:03:26 +0530276
Jagan Teki5f646bf2018-05-07 13:03:30 +0530277 if (data->cfg->type == sun8i_a83t_phy) {
278 if (phy->id == 0) {
279 val = readl(data->base + data->cfg->phyctl_offset);
280 val |= PHY_CTL_VBUSVLDEXT;
281 val &= ~PHY_CTL_SIDDQ;
282 writel(val, data->base + data->cfg->phyctl_offset);
283 }
284 } else {
285 if (usb_phy->pmu && data->cfg->enable_pmu_unk1) {
286 val = readl(usb_phy->pmu + REG_PMU_UNK1);
287 writel(val & ~2, usb_phy->pmu + REG_PMU_UNK1);
288 }
289
290 if (usb_phy->id == 0)
291 sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN,
292 PHY_RES45_CAL_DATA,
293 PHY_RES45_CAL_LEN);
294
295 /* Adjust PHY's magnitude and rate */
296 sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE,
297 PHY_TX_MAGNITUDE | PHY_TX_RATE,
298 PHY_TX_AMPLITUDE_LEN);
299
300 /* Disconnect threshold adjustment */
301 sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
302 data->cfg->disc_thresh, PHY_DISCON_TH_LEN);
Jagan Teki67685942018-05-07 13:03:26 +0530303 }
304
Jagan Teki0bfcb472018-07-20 12:34:20 +0530305 sun4i_usb_phy_passby(phy, true);
Jagan Teki67685942018-05-07 13:03:26 +0530306
307 sun4i_usb_phy0_reroute(data, true);
308
309 return 0;
310}
311
312static int sun4i_usb_phy_exit(struct phy *phy)
313{
314 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
315 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
Jagan Teki089ffd02018-08-06 12:16:39 +0530316 int ret;
Jagan Teki67685942018-05-07 13:03:26 +0530317
Jagan Teki5f646bf2018-05-07 13:03:30 +0530318 if (phy->id == 0) {
319 if (data->cfg->type == sun8i_a83t_phy) {
320 void __iomem *phyctl = data->base +
321 data->cfg->phyctl_offset;
322
323 writel(readl(phyctl) | PHY_CTL_SIDDQ, phyctl);
324 }
325 }
326
327 sun4i_usb_phy_passby(phy, false);
Jagan Teki67685942018-05-07 13:03:26 +0530328
Jagan Teki089ffd02018-08-06 12:16:39 +0530329 ret = clk_disable(&usb_phy->clocks);
330 if (ret) {
331 dev_err(dev, "failed to disable usb_%ldphy clock\n", phy->id);
332 return ret;
333 }
334
335 ret = reset_assert(&usb_phy->resets);
336 if (ret) {
337 dev_err(dev, "failed to assert usb_%ldreset reset\n", phy->id);
338 return ret;
339 }
Jagan Teki67685942018-05-07 13:03:26 +0530340
341 return 0;
342}
343
344static int sun4i_usb_phy_xlate(struct phy *phy,
345 struct ofnode_phandle_args *args)
346{
347 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
348
349 if (args->args_count >= data->cfg->num_phys)
350 return -EINVAL;
351
352 if (args->args_count)
353 phy->id = args->args[0];
354 else
355 phy->id = 0;
356
357 debug("%s: phy_id = %ld\n", __func__, phy->id);
358 return 0;
359}
360
Jagan Teki129c45c2018-05-07 13:03:27 +0530361int sun4i_usb_phy_vbus_detect(struct phy *phy)
362{
363 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
364 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
365 int err, retries = 3;
366
367 debug("%s: id_det = %d\n", __func__, usb_phy->gpio_id_det);
368
369 if (usb_phy->gpio_vbus_det < 0)
370 return usb_phy->gpio_vbus_det;
371
372 err = gpio_get_value(usb_phy->gpio_vbus_det);
373 /*
374 * Vbus may have been provided by the board and just been turned of
375 * some milliseconds ago on reset, what we're measuring then is a
376 * residual charge on Vbus, sleep a bit and try again.
377 */
378 while (err > 0 && retries--) {
379 mdelay(100);
380 err = gpio_get_value(usb_phy->gpio_vbus_det);
381 }
382
383 return err;
384}
385
386int sun4i_usb_phy_id_detect(struct phy *phy)
387{
388 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
389 struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
390
391 debug("%s: id_det = %d\n", __func__, usb_phy->gpio_id_det);
392
393 if (usb_phy->gpio_id_det < 0)
394 return usb_phy->gpio_id_det;
395
396 return gpio_get_value(usb_phy->gpio_id_det);
397}
398
Jagan Tekiaa29b112018-05-07 13:03:37 +0530399void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled)
400{
401 sun4i_usb_phy_write(phy, PHY_SQUELCH_DETECT, enabled ? 0 : 2, 2);
402}
403
Jagan Teki67685942018-05-07 13:03:26 +0530404static struct phy_ops sun4i_usb_phy_ops = {
405 .of_xlate = sun4i_usb_phy_xlate,
406 .init = sun4i_usb_phy_init,
407 .power_on = sun4i_usb_phy_power_on,
408 .power_off = sun4i_usb_phy_power_off,
409 .exit = sun4i_usb_phy_exit,
410};
411
412static int sun4i_usb_phy_probe(struct udevice *dev)
413{
414 struct sun4i_usb_phy_plat *plat = dev_get_platdata(dev);
415 struct sun4i_usb_phy_data *data = dev_get_priv(dev);
416 int i, ret;
417
418 data->cfg = (const struct sun4i_usb_phy_cfg *)dev_get_driver_data(dev);
419 if (!data->cfg)
420 return -EINVAL;
421
422 data->base = (void __iomem *)devfdt_get_addr_name(dev, "phy_ctrl");
423 if (IS_ERR(data->base))
424 return PTR_ERR(data->base);
425
Jagan Teki67685942018-05-07 13:03:26 +0530426 data->usb_phy = plat;
427 for (i = 0; i < data->cfg->num_phys; i++) {
428 struct sun4i_usb_phy_plat *phy = &plat[i];
429 struct sun4i_usb_phy_info *info = &phy_info[i];
430 char name[16];
431
432 phy->gpio_vbus = sunxi_name_to_gpio(info->gpio_vbus);
433 if (phy->gpio_vbus >= 0) {
434 ret = gpio_request(phy->gpio_vbus, "usb_vbus");
435 if (ret)
436 return ret;
437 ret = gpio_direction_output(phy->gpio_vbus, 0);
438 if (ret)
439 return ret;
440 }
441
442 phy->gpio_vbus_det = sunxi_name_to_gpio(info->gpio_vbus_det);
443 if (phy->gpio_vbus_det >= 0) {
444 ret = gpio_request(phy->gpio_vbus_det, "usb_vbus_det");
445 if (ret)
446 return ret;
447 ret = gpio_direction_input(phy->gpio_vbus_det);
448 if (ret)
449 return ret;
450 }
451
452 phy->gpio_id_det = sunxi_name_to_gpio(info->gpio_id_det);
453 if (phy->gpio_id_det >= 0) {
454 ret = gpio_request(phy->gpio_id_det, "usb_id_det");
455 if (ret)
456 return ret;
457 ret = gpio_direction_input(phy->gpio_id_det);
458 if (ret)
459 return ret;
460 sunxi_gpio_set_pull(phy->gpio_id_det, SUNXI_GPIO_PULL_UP);
461 }
462
Jagan Teki089ffd02018-08-06 12:16:39 +0530463 if (data->cfg->dedicated_clocks)
464 snprintf(name, sizeof(name), "usb%d_phy", i);
465 else
466 strlcpy(name, "usb_phy", sizeof(name));
467
468 ret = clk_get_by_name(dev, name, &phy->clocks);
469 if (ret) {
470 dev_err(dev, "failed to get usb%d_phy clock phandle\n", i);
471 return ret;
472 }
473
474 snprintf(name, sizeof(name), "usb%d_reset", i);
475 ret = reset_get_by_name(dev, name, &phy->resets);
476 if (ret) {
477 dev_err(dev, "failed to get usb%d_reset reset phandle\n", i);
478 return ret;
479 }
480
Jagan Teki67685942018-05-07 13:03:26 +0530481 if (i || data->cfg->phy0_dual_route) {
482 snprintf(name, sizeof(name), "pmu%d", i);
483 phy->pmu = (void __iomem *)devfdt_get_addr_name(dev, name);
484 if (IS_ERR(phy->pmu))
485 return PTR_ERR(phy->pmu);
486 }
487
488 phy->id = i;
Jagan Teki67685942018-05-07 13:03:26 +0530489 };
490
Jagan Teki67685942018-05-07 13:03:26 +0530491 debug("Allwinner Sun4I USB PHY driver loaded\n");
492 return 0;
493}
494
Jagan Teki7f90b552018-05-07 13:03:31 +0530495static const struct sun4i_usb_phy_cfg sun4i_a10_cfg = {
496 .num_phys = 3,
497 .type = sun4i_a10_phy,
498 .disc_thresh = 3,
499 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530500 .dedicated_clocks = false,
Jagan Teki7f90b552018-05-07 13:03:31 +0530501 .enable_pmu_unk1 = false,
502};
503
504static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = {
505 .num_phys = 2,
506 .type = sun4i_a10_phy,
507 .disc_thresh = 2,
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
Jagan Tekibf986d12018-05-07 13:03:32 +0530513static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = {
514 .num_phys = 3,
515 .type = sun6i_a31_phy,
516 .disc_thresh = 3,
517 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530518 .dedicated_clocks = true,
Jagan Tekibf986d12018-05-07 13:03:32 +0530519 .enable_pmu_unk1 = false,
520};
521
Jagan Teki7f90b552018-05-07 13:03:31 +0530522static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = {
523 .num_phys = 3,
524 .type = sun4i_a10_phy,
525 .disc_thresh = 2,
526 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530527 .dedicated_clocks = false,
Jagan Teki7f90b552018-05-07 13:03:31 +0530528 .enable_pmu_unk1 = false,
529};
530
Jagan Teki194ccb92018-05-07 13:03:34 +0530531static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = {
532 .num_phys = 2,
533 .type = sun4i_a10_phy,
534 .disc_thresh = 3,
535 .phyctl_offset = REG_PHYCTL_A10,
Jagan Teki089ffd02018-08-06 12:16:39 +0530536 .dedicated_clocks = true,
Jagan Teki194ccb92018-05-07 13:03:34 +0530537 .enable_pmu_unk1 = false,
538};
539
Jagan Teki61bf0ed2018-05-07 13:03:33 +0530540static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = {
541 .num_phys = 2,
542 .type = sun8i_a33_phy,
543 .disc_thresh = 3,
544 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530545 .dedicated_clocks = true,
Jagan Teki61bf0ed2018-05-07 13:03:33 +0530546 .enable_pmu_unk1 = false,
547};
548
Jagan Teki5f646bf2018-05-07 13:03:30 +0530549static const struct sun4i_usb_phy_cfg sun8i_a83t_cfg = {
550 .num_phys = 3,
551 .type = sun8i_a83t_phy,
552 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530553 .dedicated_clocks = true,
Jagan Teki5f646bf2018-05-07 13:03:30 +0530554};
555
Jagan Teki43519c42018-05-07 13:03:28 +0530556static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
557 .num_phys = 4,
558 .type = sun8i_h3_phy,
559 .disc_thresh = 3,
560 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530561 .dedicated_clocks = true,
Jagan Teki43519c42018-05-07 13:03:28 +0530562 .enable_pmu_unk1 = true,
563 .phy0_dual_route = true,
564};
565
Jagan Tekibafe5e32018-05-07 13:03:29 +0530566static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
567 .num_phys = 1,
568 .type = sun8i_v3s_phy,
569 .disc_thresh = 3,
570 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530571 .dedicated_clocks = true,
Jagan Tekibafe5e32018-05-07 13:03:29 +0530572 .enable_pmu_unk1 = true,
573 .phy0_dual_route = true,
574};
575
Jagan Teki67685942018-05-07 13:03:26 +0530576static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = {
577 .num_phys = 2,
578 .type = sun50i_a64_phy,
579 .disc_thresh = 3,
580 .phyctl_offset = REG_PHYCTL_A33,
Jagan Teki089ffd02018-08-06 12:16:39 +0530581 .dedicated_clocks = true,
Jagan Teki67685942018-05-07 13:03:26 +0530582 .enable_pmu_unk1 = true,
583 .phy0_dual_route = true,
584};
585
586static const struct udevice_id sun4i_usb_phy_ids[] = {
Jagan Teki7f90b552018-05-07 13:03:31 +0530587 { .compatible = "allwinner,sun4i-a10-usb-phy", .data = (ulong)&sun4i_a10_cfg },
588 { .compatible = "allwinner,sun5i-a13-usb-phy", .data = (ulong)&sun5i_a13_cfg },
Jagan Tekibf986d12018-05-07 13:03:32 +0530589 { .compatible = "allwinner,sun6i-a31-usb-phy", .data = (ulong)&sun6i_a31_cfg },
Jagan Teki7f90b552018-05-07 13:03:31 +0530590 { .compatible = "allwinner,sun7i-a20-usb-phy", .data = (ulong)&sun7i_a20_cfg },
Jagan Teki194ccb92018-05-07 13:03:34 +0530591 { .compatible = "allwinner,sun8i-a23-usb-phy", .data = (ulong)&sun8i_a23_cfg },
Jagan Teki61bf0ed2018-05-07 13:03:33 +0530592 { .compatible = "allwinner,sun8i-a33-usb-phy", .data = (ulong)&sun8i_a33_cfg },
Jagan Teki5f646bf2018-05-07 13:03:30 +0530593 { .compatible = "allwinner,sun8i-a83t-usb-phy", .data = (ulong)&sun8i_a83t_cfg },
Jagan Teki43519c42018-05-07 13:03:28 +0530594 { .compatible = "allwinner,sun8i-h3-usb-phy", .data = (ulong)&sun8i_h3_cfg },
Jagan Tekibafe5e32018-05-07 13:03:29 +0530595 { .compatible = "allwinner,sun8i-v3s-usb-phy", .data = (ulong)&sun8i_v3s_cfg },
Jagan Teki67685942018-05-07 13:03:26 +0530596 { .compatible = "allwinner,sun50i-a64-usb-phy", .data = (ulong)&sun50i_a64_cfg},
597 { }
598};
599
600U_BOOT_DRIVER(sun4i_usb_phy) = {
601 .name = "sun4i_usb_phy",
602 .id = UCLASS_PHY,
603 .of_match = sun4i_usb_phy_ids,
604 .ops = &sun4i_usb_phy_ops,
605 .probe = sun4i_usb_phy_probe,
606 .platdata_auto_alloc_size = sizeof(struct sun4i_usb_phy_plat[MAX_PHYS]),
607 .priv_auto_alloc_size = sizeof(struct sun4i_usb_phy_data),
608};