2 * Allwinner sun4i USB phy driver
4 * Copyright (C) 2014-2015 Hans de Goede <hdegoede@redhat.com>
7 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
9 * Modelled after: Samsung S5P/EXYNOS SoC series MIPI CSIS/DSIM DPHY driver
10 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
11 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
24 #include <linux/clk.h>
25 #include <linux/delay.h>
26 #include <linux/err.h>
27 #include <linux/extcon.h>
29 #include <linux/interrupt.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/mutex.h>
34 #include <linux/of_address.h>
35 #include <linux/of_device.h>
36 #include <linux/of_gpio.h>
37 #include <linux/phy/phy.h>
38 #include <linux/phy/phy-sun4i-usb.h>
39 #include <linux/platform_device.h>
40 #include <linux/power_supply.h>
41 #include <linux/regulator/consumer.h>
42 #include <linux/reset.h>
43 #include <linux/usb/of.h>
44 #include <linux/workqueue.h>
47 #define REG_PHYCTL_A10 0x04
48 #define REG_PHYBIST 0x08
49 #define REG_PHYTUNE 0x0c
50 #define REG_PHYCTL_A33 0x10
51 #define REG_PHY_UNK_H3 0x20
53 #define REG_PMU_UNK_H3 0x10
55 #define PHYCTL_DATA BIT(7)
57 #define SUNXI_AHB_ICHR8_EN BIT(10)
58 #define SUNXI_AHB_INCR4_BURST_EN BIT(9)
59 #define SUNXI_AHB_INCRX_ALIGN_EN BIT(8)
60 #define SUNXI_ULPI_BYPASS_EN BIT(0)
62 /* ISCR, Interface Status and Control bits */
63 #define ISCR_ID_PULLUP_EN (1 << 17)
64 #define ISCR_DPDM_PULLUP_EN (1 << 16)
65 /* sunxi has the phy id/vbus pins not connected, so we use the force bits */
66 #define ISCR_FORCE_ID_MASK (3 << 14)
67 #define ISCR_FORCE_ID_LOW (2 << 14)
68 #define ISCR_FORCE_ID_HIGH (3 << 14)
69 #define ISCR_FORCE_VBUS_MASK (3 << 12)
70 #define ISCR_FORCE_VBUS_LOW (2 << 12)
71 #define ISCR_FORCE_VBUS_HIGH (3 << 12)
73 /* Common Control Bits for Both PHYs */
74 #define PHY_PLL_BW 0x03
75 #define PHY_RES45_CAL_EN 0x0c
77 /* Private Control Bits for Each PHY */
78 #define PHY_TX_AMPLITUDE_TUNE 0x20
79 #define PHY_TX_SLEWRATE_TUNE 0x22
80 #define PHY_VBUSVALID_TH_SEL 0x25
81 #define PHY_PULLUP_RES_SEL 0x27
82 #define PHY_OTG_FUNC_EN 0x28
83 #define PHY_VBUS_DET_EN 0x29
84 #define PHY_DISCON_TH_SEL 0x2a
85 #define PHY_SQUELCH_DETECT 0x3c
90 * Note do not raise the debounce time, we must report Vusb high within 100ms
91 * otherwise we get Vbus errors
93 #define DEBOUNCE_TIME msecs_to_jiffies(50)
94 #define POLL_TIME msecs_to_jiffies(250)
96 enum sun4i_usb_phy_type
{
103 struct sun4i_usb_phy_cfg
{
105 enum sun4i_usb_phy_type type
;
108 bool dedicated_clocks
;
111 struct sun4i_usb_phy_data
{
113 const struct sun4i_usb_phy_cfg
*cfg
;
114 enum usb_dr_mode dr_mode
;
116 struct sun4i_usb_phy
{
119 struct regulator
*vbus
;
120 struct reset_control
*reset
;
126 /* phy0 / otg related variables */
127 struct extcon_dev
*extcon
;
129 struct gpio_desc
*id_det_gpio
;
130 struct gpio_desc
*vbus_det_gpio
;
131 struct power_supply
*vbus_power_supply
;
132 struct notifier_block vbus_power_nb
;
133 bool vbus_power_nb_registered
;
138 struct delayed_work detect
;
141 #define to_sun4i_usb_phy_data(phy) \
142 container_of((phy), struct sun4i_usb_phy_data, phys[(phy)->index])
144 static void sun4i_usb_phy0_update_iscr(struct phy
*_phy
, u32 clr
, u32 set
)
146 struct sun4i_usb_phy
*phy
= phy_get_drvdata(_phy
);
147 struct sun4i_usb_phy_data
*data
= to_sun4i_usb_phy_data(phy
);
150 iscr
= readl(data
->base
+ REG_ISCR
);
153 writel(iscr
, data
->base
+ REG_ISCR
);
156 static void sun4i_usb_phy0_set_id_detect(struct phy
*phy
, u32 val
)
159 val
= ISCR_FORCE_ID_HIGH
;
161 val
= ISCR_FORCE_ID_LOW
;
163 sun4i_usb_phy0_update_iscr(phy
, ISCR_FORCE_ID_MASK
, val
);
166 static void sun4i_usb_phy0_set_vbus_detect(struct phy
*phy
, u32 val
)
169 val
= ISCR_FORCE_VBUS_HIGH
;
171 val
= ISCR_FORCE_VBUS_LOW
;
173 sun4i_usb_phy0_update_iscr(phy
, ISCR_FORCE_VBUS_MASK
, val
);
176 static void sun4i_usb_phy_write(struct sun4i_usb_phy
*phy
, u32 addr
, u32 data
,
179 struct sun4i_usb_phy_data
*phy_data
= to_sun4i_usb_phy_data(phy
);
180 u32 temp
, usbc_bit
= BIT(phy
->index
* 2);
181 void __iomem
*phyctl
= phy_data
->base
+ phy_data
->cfg
->phyctl_offset
;
184 mutex_lock(&phy_data
->mutex
);
186 if (phy_data
->cfg
->type
== sun8i_a33_phy
) {
187 /* A33 needs us to set phyctl to 0 explicitly */
191 for (i
= 0; i
< len
; i
++) {
192 temp
= readl(phyctl
);
194 /* clear the address portion */
195 temp
&= ~(0xff << 8);
197 /* set the address */
198 temp
|= ((addr
+ i
) << 8);
199 writel(temp
, phyctl
);
201 /* set the data bit and clear usbc bit*/
202 temp
= readb(phyctl
);
206 temp
&= ~PHYCTL_DATA
;
208 writeb(temp
, phyctl
);
211 temp
= readb(phyctl
);
213 writeb(temp
, phyctl
);
215 temp
= readb(phyctl
);
217 writeb(temp
, phyctl
);
221 mutex_unlock(&phy_data
->mutex
);
224 static void sun4i_usb_phy_passby(struct sun4i_usb_phy
*phy
, int enable
)
231 bits
= SUNXI_AHB_ICHR8_EN
| SUNXI_AHB_INCR4_BURST_EN
|
232 SUNXI_AHB_INCRX_ALIGN_EN
| SUNXI_ULPI_BYPASS_EN
;
234 reg_value
= readl(phy
->pmu
);
241 writel(reg_value
, phy
->pmu
);
244 static int sun4i_usb_phy_init(struct phy
*_phy
)
246 struct sun4i_usb_phy
*phy
= phy_get_drvdata(_phy
);
247 struct sun4i_usb_phy_data
*data
= to_sun4i_usb_phy_data(phy
);
251 ret
= clk_prepare_enable(phy
->clk
);
255 ret
= reset_control_deassert(phy
->reset
);
257 clk_disable_unprepare(phy
->clk
);
261 if (data
->cfg
->type
== sun8i_h3_phy
) {
262 if (phy
->index
== 0) {
263 val
= readl(data
->base
+ REG_PHY_UNK_H3
);
264 writel(val
& ~1, data
->base
+ REG_PHY_UNK_H3
);
267 val
= readl(phy
->pmu
+ REG_PMU_UNK_H3
);
268 writel(val
& ~2, phy
->pmu
+ REG_PMU_UNK_H3
);
270 /* Enable USB 45 Ohm resistor calibration */
272 sun4i_usb_phy_write(phy
, PHY_RES45_CAL_EN
, 0x01, 1);
274 /* Adjust PHY's magnitude and rate */
275 sun4i_usb_phy_write(phy
, PHY_TX_AMPLITUDE_TUNE
, 0x14, 5);
277 /* Disconnect threshold adjustment */
278 sun4i_usb_phy_write(phy
, PHY_DISCON_TH_SEL
,
279 data
->cfg
->disc_thresh
, 2);
282 sun4i_usb_phy_passby(phy
, 1);
284 if (phy
->index
== 0) {
285 data
->phy0_init
= true;
287 /* Enable pull-ups */
288 sun4i_usb_phy0_update_iscr(_phy
, 0, ISCR_DPDM_PULLUP_EN
);
289 sun4i_usb_phy0_update_iscr(_phy
, 0, ISCR_ID_PULLUP_EN
);
291 /* Force ISCR and cable state updates */
294 queue_delayed_work(system_wq
, &data
->detect
, 0);
300 static int sun4i_usb_phy_exit(struct phy
*_phy
)
302 struct sun4i_usb_phy
*phy
= phy_get_drvdata(_phy
);
303 struct sun4i_usb_phy_data
*data
= to_sun4i_usb_phy_data(phy
);
305 if (phy
->index
== 0) {
306 /* Disable pull-ups */
307 sun4i_usb_phy0_update_iscr(_phy
, ISCR_DPDM_PULLUP_EN
, 0);
308 sun4i_usb_phy0_update_iscr(_phy
, ISCR_ID_PULLUP_EN
, 0);
309 data
->phy0_init
= false;
312 sun4i_usb_phy_passby(phy
, 0);
313 reset_control_assert(phy
->reset
);
314 clk_disable_unprepare(phy
->clk
);
319 static int sun4i_usb_phy0_get_id_det(struct sun4i_usb_phy_data
*data
)
321 switch (data
->dr_mode
) {
322 case USB_DR_MODE_OTG
:
323 return gpiod_get_value_cansleep(data
->id_det_gpio
);
324 case USB_DR_MODE_HOST
:
326 case USB_DR_MODE_PERIPHERAL
:
332 static int sun4i_usb_phy0_get_vbus_det(struct sun4i_usb_phy_data
*data
)
334 if (data
->vbus_det_gpio
)
335 return gpiod_get_value_cansleep(data
->vbus_det_gpio
);
337 if (data
->vbus_power_supply
) {
338 union power_supply_propval val
;
341 r
= power_supply_get_property(data
->vbus_power_supply
,
342 POWER_SUPPLY_PROP_PRESENT
, &val
);
347 /* Fallback: report vbus as high */
351 static bool sun4i_usb_phy0_have_vbus_det(struct sun4i_usb_phy_data
*data
)
353 return data
->vbus_det_gpio
|| data
->vbus_power_supply
;
356 static bool sun4i_usb_phy0_poll(struct sun4i_usb_phy_data
*data
)
358 if ((data
->id_det_gpio
&& data
->id_det_irq
<= 0) ||
359 (data
->vbus_det_gpio
&& data
->vbus_det_irq
<= 0))
363 * The A31 companion pmic (axp221) does not generate vbus change
364 * interrupts when the board is driving vbus, so we must poll
365 * when using the pmic for vbus-det _and_ we're driving vbus.
367 if (data
->cfg
->type
== sun6i_a31_phy
&&
368 data
->vbus_power_supply
&& data
->phys
[0].regulator_on
)
374 static int sun4i_usb_phy_power_on(struct phy
*_phy
)
376 struct sun4i_usb_phy
*phy
= phy_get_drvdata(_phy
);
377 struct sun4i_usb_phy_data
*data
= to_sun4i_usb_phy_data(phy
);
380 if (!phy
->vbus
|| phy
->regulator_on
)
383 /* For phy0 only turn on Vbus if we don't have an ext. Vbus */
384 if (phy
->index
== 0 && sun4i_usb_phy0_have_vbus_det(data
) &&
388 ret
= regulator_enable(phy
->vbus
);
392 phy
->regulator_on
= true;
394 /* We must report Vbus high within OTG_TIME_A_WAIT_VRISE msec. */
395 if (phy
->index
== 0 && sun4i_usb_phy0_poll(data
))
396 mod_delayed_work(system_wq
, &data
->detect
, DEBOUNCE_TIME
);
401 static int sun4i_usb_phy_power_off(struct phy
*_phy
)
403 struct sun4i_usb_phy
*phy
= phy_get_drvdata(_phy
);
404 struct sun4i_usb_phy_data
*data
= to_sun4i_usb_phy_data(phy
);
406 if (!phy
->vbus
|| !phy
->regulator_on
)
409 regulator_disable(phy
->vbus
);
410 phy
->regulator_on
= false;
413 * phy0 vbus typically slowly discharges, sometimes this causes the
414 * Vbus gpio to not trigger an edge irq on Vbus off, so force a rescan.
416 if (phy
->index
== 0 && !sun4i_usb_phy0_poll(data
))
417 mod_delayed_work(system_wq
, &data
->detect
, POLL_TIME
);
422 void sun4i_usb_phy_set_squelch_detect(struct phy
*_phy
, bool enabled
)
424 struct sun4i_usb_phy
*phy
= phy_get_drvdata(_phy
);
426 sun4i_usb_phy_write(phy
, PHY_SQUELCH_DETECT
, enabled
? 0 : 2, 2);
428 EXPORT_SYMBOL_GPL(sun4i_usb_phy_set_squelch_detect
);
430 static const struct phy_ops sun4i_usb_phy_ops
= {
431 .init
= sun4i_usb_phy_init
,
432 .exit
= sun4i_usb_phy_exit
,
433 .power_on
= sun4i_usb_phy_power_on
,
434 .power_off
= sun4i_usb_phy_power_off
,
435 .owner
= THIS_MODULE
,
438 static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct
*work
)
440 struct sun4i_usb_phy_data
*data
=
441 container_of(work
, struct sun4i_usb_phy_data
, detect
.work
);
442 struct phy
*phy0
= data
->phys
[0].phy
;
443 int id_det
, vbus_det
, id_notify
= 0, vbus_notify
= 0;
448 id_det
= sun4i_usb_phy0_get_id_det(data
);
449 vbus_det
= sun4i_usb_phy0_get_vbus_det(data
);
451 mutex_lock(&phy0
->mutex
);
453 if (!data
->phy0_init
) {
454 mutex_unlock(&phy0
->mutex
);
458 if (id_det
!= data
->id_det
) {
460 * When a host cable (id == 0) gets plugged in on systems
461 * without vbus detection report vbus low for long enough for
462 * the musb-ip to end the current device session.
464 if (data
->dr_mode
== USB_DR_MODE_OTG
&&
465 !sun4i_usb_phy0_have_vbus_det(data
) && id_det
== 0) {
466 sun4i_usb_phy0_set_vbus_detect(phy0
, 0);
468 sun4i_usb_phy0_set_vbus_detect(phy0
, 1);
470 sun4i_usb_phy0_set_id_detect(phy0
, id_det
);
471 data
->id_det
= id_det
;
475 if (vbus_det
!= data
->vbus_det
) {
476 sun4i_usb_phy0_set_vbus_detect(phy0
, vbus_det
);
477 data
->vbus_det
= vbus_det
;
481 mutex_unlock(&phy0
->mutex
);
484 extcon_set_cable_state_(data
->extcon
, EXTCON_USB_HOST
,
487 * When a host cable gets unplugged (id == 1) on systems
488 * without vbus detection report vbus low for long enough to
489 * the musb-ip to end the current host session.
491 if (data
->dr_mode
== USB_DR_MODE_OTG
&&
492 !sun4i_usb_phy0_have_vbus_det(data
) && id_det
== 1) {
493 mutex_lock(&phy0
->mutex
);
494 sun4i_usb_phy0_set_vbus_detect(phy0
, 0);
496 sun4i_usb_phy0_set_vbus_detect(phy0
, 1);
497 mutex_unlock(&phy0
->mutex
);
502 extcon_set_cable_state_(data
->extcon
, EXTCON_USB
, vbus_det
);
504 if (sun4i_usb_phy0_poll(data
))
505 queue_delayed_work(system_wq
, &data
->detect
, POLL_TIME
);
508 static irqreturn_t
sun4i_usb_phy0_id_vbus_det_irq(int irq
, void *dev_id
)
510 struct sun4i_usb_phy_data
*data
= dev_id
;
512 /* vbus or id changed, let the pins settle and then scan them */
513 mod_delayed_work(system_wq
, &data
->detect
, DEBOUNCE_TIME
);
518 static int sun4i_usb_phy0_vbus_notify(struct notifier_block
*nb
,
519 unsigned long val
, void *v
)
521 struct sun4i_usb_phy_data
*data
=
522 container_of(nb
, struct sun4i_usb_phy_data
, vbus_power_nb
);
523 struct power_supply
*psy
= v
;
525 /* Properties on the vbus_power_supply changed, scan vbus_det */
526 if (val
== PSY_EVENT_PROP_CHANGED
&& psy
== data
->vbus_power_supply
)
527 mod_delayed_work(system_wq
, &data
->detect
, DEBOUNCE_TIME
);
532 static struct phy
*sun4i_usb_phy_xlate(struct device
*dev
,
533 struct of_phandle_args
*args
)
535 struct sun4i_usb_phy_data
*data
= dev_get_drvdata(dev
);
537 if (args
->args
[0] < data
->first_phy
||
538 args
->args
[0] >= data
->cfg
->num_phys
)
539 return ERR_PTR(-ENODEV
);
541 return data
->phys
[args
->args
[0]].phy
;
544 static int sun4i_usb_phy_remove(struct platform_device
*pdev
)
546 struct device
*dev
= &pdev
->dev
;
547 struct sun4i_usb_phy_data
*data
= dev_get_drvdata(dev
);
549 if (data
->vbus_power_nb_registered
)
550 power_supply_unreg_notifier(&data
->vbus_power_nb
);
551 if (data
->id_det_irq
> 0)
552 devm_free_irq(dev
, data
->id_det_irq
, data
);
553 if (data
->vbus_det_irq
> 0)
554 devm_free_irq(dev
, data
->vbus_det_irq
, data
);
556 cancel_delayed_work_sync(&data
->detect
);
561 static const unsigned int sun4i_usb_phy0_cable
[] = {
567 static int sun4i_usb_phy_probe(struct platform_device
*pdev
)
569 struct sun4i_usb_phy_data
*data
;
570 struct device
*dev
= &pdev
->dev
;
571 struct device_node
*np
= dev
->of_node
;
572 struct phy_provider
*phy_provider
;
573 struct resource
*res
;
576 data
= devm_kzalloc(dev
, sizeof(*data
), GFP_KERNEL
);
580 mutex_init(&data
->mutex
);
581 INIT_DELAYED_WORK(&data
->detect
, sun4i_usb_phy0_id_vbus_det_scan
);
582 dev_set_drvdata(dev
, data
);
583 data
->cfg
= of_device_get_match_data(dev
);
587 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "phy_ctrl");
588 data
->base
= devm_ioremap_resource(dev
, res
);
589 if (IS_ERR(data
->base
))
590 return PTR_ERR(data
->base
);
592 data
->id_det_gpio
= devm_gpiod_get_optional(dev
, "usb0_id_det",
594 if (IS_ERR(data
->id_det_gpio
))
595 return PTR_ERR(data
->id_det_gpio
);
597 data
->vbus_det_gpio
= devm_gpiod_get_optional(dev
, "usb0_vbus_det",
599 if (IS_ERR(data
->vbus_det_gpio
))
600 return PTR_ERR(data
->vbus_det_gpio
);
602 if (of_find_property(np
, "usb0_vbus_power-supply", NULL
)) {
603 data
->vbus_power_supply
= devm_power_supply_get_by_phandle(dev
,
604 "usb0_vbus_power-supply");
605 if (IS_ERR(data
->vbus_power_supply
))
606 return PTR_ERR(data
->vbus_power_supply
);
608 if (!data
->vbus_power_supply
)
609 return -EPROBE_DEFER
;
612 data
->dr_mode
= of_usb_get_dr_mode_by_phy(np
, 0);
613 switch (data
->dr_mode
) {
614 case USB_DR_MODE_OTG
:
615 /* otg without id_det makes no sense, and is not supported */
616 if (!data
->id_det_gpio
) {
617 dev_err(dev
, "usb0_id_det missing or invalid\n");
621 case USB_DR_MODE_HOST
:
622 case USB_DR_MODE_PERIPHERAL
:
623 data
->extcon
= devm_extcon_dev_allocate(dev
,
624 sun4i_usb_phy0_cable
);
625 if (IS_ERR(data
->extcon
))
626 return PTR_ERR(data
->extcon
);
628 ret
= devm_extcon_dev_register(dev
, data
->extcon
);
630 dev_err(dev
, "failed to register extcon: %d\n", ret
);
635 dev_info(dev
, "dr_mode unknown, not registering usb phy0\n");
639 for (i
= data
->first_phy
; i
< data
->cfg
->num_phys
; i
++) {
640 struct sun4i_usb_phy
*phy
= data
->phys
+ i
;
643 snprintf(name
, sizeof(name
), "usb%d_vbus", i
);
644 phy
->vbus
= devm_regulator_get_optional(dev
, name
);
645 if (IS_ERR(phy
->vbus
)) {
646 if (PTR_ERR(phy
->vbus
) == -EPROBE_DEFER
)
647 return -EPROBE_DEFER
;
651 if (data
->cfg
->dedicated_clocks
)
652 snprintf(name
, sizeof(name
), "usb%d_phy", i
);
654 strlcpy(name
, "usb_phy", sizeof(name
));
656 phy
->clk
= devm_clk_get(dev
, name
);
657 if (IS_ERR(phy
->clk
)) {
658 dev_err(dev
, "failed to get clock %s\n", name
);
659 return PTR_ERR(phy
->clk
);
662 snprintf(name
, sizeof(name
), "usb%d_reset", i
);
663 phy
->reset
= devm_reset_control_get(dev
, name
);
664 if (IS_ERR(phy
->reset
)) {
665 dev_err(dev
, "failed to get reset %s\n", name
);
666 return PTR_ERR(phy
->reset
);
669 if (i
) { /* No pmu for usbc0 */
670 snprintf(name
, sizeof(name
), "pmu%d", i
);
671 res
= platform_get_resource_byname(pdev
,
672 IORESOURCE_MEM
, name
);
673 phy
->pmu
= devm_ioremap_resource(dev
, res
);
674 if (IS_ERR(phy
->pmu
))
675 return PTR_ERR(phy
->pmu
);
678 phy
->phy
= devm_phy_create(dev
, NULL
, &sun4i_usb_phy_ops
);
679 if (IS_ERR(phy
->phy
)) {
680 dev_err(dev
, "failed to create PHY %d\n", i
);
681 return PTR_ERR(phy
->phy
);
685 phy_set_drvdata(phy
->phy
, &data
->phys
[i
]);
688 data
->id_det_irq
= gpiod_to_irq(data
->id_det_gpio
);
689 if (data
->id_det_irq
> 0) {
690 ret
= devm_request_irq(dev
, data
->id_det_irq
,
691 sun4i_usb_phy0_id_vbus_det_irq
,
692 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
,
693 "usb0-id-det", data
);
695 dev_err(dev
, "Err requesting id-det-irq: %d\n", ret
);
700 data
->vbus_det_irq
= gpiod_to_irq(data
->vbus_det_gpio
);
701 if (data
->vbus_det_irq
> 0) {
702 ret
= devm_request_irq(dev
, data
->vbus_det_irq
,
703 sun4i_usb_phy0_id_vbus_det_irq
,
704 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
,
705 "usb0-vbus-det", data
);
707 dev_err(dev
, "Err requesting vbus-det-irq: %d\n", ret
);
708 data
->vbus_det_irq
= -1;
709 sun4i_usb_phy_remove(pdev
); /* Stop detect work */
714 if (data
->vbus_power_supply
) {
715 data
->vbus_power_nb
.notifier_call
= sun4i_usb_phy0_vbus_notify
;
716 data
->vbus_power_nb
.priority
= 0;
717 ret
= power_supply_reg_notifier(&data
->vbus_power_nb
);
719 sun4i_usb_phy_remove(pdev
); /* Stop detect work */
722 data
->vbus_power_nb_registered
= true;
725 phy_provider
= devm_of_phy_provider_register(dev
, sun4i_usb_phy_xlate
);
726 if (IS_ERR(phy_provider
)) {
727 sun4i_usb_phy_remove(pdev
); /* Stop detect work */
728 return PTR_ERR(phy_provider
);
734 static const struct sun4i_usb_phy_cfg sun4i_a10_cfg
= {
736 .type
= sun4i_a10_phy
,
738 .phyctl_offset
= REG_PHYCTL_A10
,
739 .dedicated_clocks
= false,
742 static const struct sun4i_usb_phy_cfg sun5i_a13_cfg
= {
744 .type
= sun4i_a10_phy
,
746 .phyctl_offset
= REG_PHYCTL_A10
,
747 .dedicated_clocks
= false,
750 static const struct sun4i_usb_phy_cfg sun6i_a31_cfg
= {
752 .type
= sun6i_a31_phy
,
754 .phyctl_offset
= REG_PHYCTL_A10
,
755 .dedicated_clocks
= true,
758 static const struct sun4i_usb_phy_cfg sun7i_a20_cfg
= {
760 .type
= sun4i_a10_phy
,
762 .phyctl_offset
= REG_PHYCTL_A10
,
763 .dedicated_clocks
= false,
766 static const struct sun4i_usb_phy_cfg sun8i_a23_cfg
= {
768 .type
= sun4i_a10_phy
,
770 .phyctl_offset
= REG_PHYCTL_A10
,
771 .dedicated_clocks
= true,
774 static const struct sun4i_usb_phy_cfg sun8i_a33_cfg
= {
776 .type
= sun8i_a33_phy
,
778 .phyctl_offset
= REG_PHYCTL_A33
,
779 .dedicated_clocks
= true,
782 static const struct sun4i_usb_phy_cfg sun8i_h3_cfg
= {
784 .type
= sun8i_h3_phy
,
786 .dedicated_clocks
= true,
789 static const struct of_device_id sun4i_usb_phy_of_match
[] = {
790 { .compatible
= "allwinner,sun4i-a10-usb-phy", .data
= &sun4i_a10_cfg
},
791 { .compatible
= "allwinner,sun5i-a13-usb-phy", .data
= &sun5i_a13_cfg
},
792 { .compatible
= "allwinner,sun6i-a31-usb-phy", .data
= &sun6i_a31_cfg
},
793 { .compatible
= "allwinner,sun7i-a20-usb-phy", .data
= &sun7i_a20_cfg
},
794 { .compatible
= "allwinner,sun8i-a23-usb-phy", .data
= &sun8i_a23_cfg
},
795 { .compatible
= "allwinner,sun8i-a33-usb-phy", .data
= &sun8i_a33_cfg
},
796 { .compatible
= "allwinner,sun8i-h3-usb-phy", .data
= &sun8i_h3_cfg
},
799 MODULE_DEVICE_TABLE(of
, sun4i_usb_phy_of_match
);
801 static struct platform_driver sun4i_usb_phy_driver
= {
802 .probe
= sun4i_usb_phy_probe
,
803 .remove
= sun4i_usb_phy_remove
,
805 .of_match_table
= sun4i_usb_phy_of_match
,
806 .name
= "sun4i-usb-phy",
809 module_platform_driver(sun4i_usb_phy_driver
);
811 MODULE_DESCRIPTION("Allwinner sun4i USB phy driver");
812 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
813 MODULE_LICENSE("GPL v2");