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/spinlock.h>
44 #include <linux/usb/of.h>
45 #include <linux/workqueue.h>
48 #define REG_PHYCTL_A10 0x04
49 #define REG_PHYBIST 0x08
50 #define REG_PHYTUNE 0x0c
51 #define REG_PHYCTL_A33 0x10
52 #define REG_PHY_OTGCTL 0x20
54 #define REG_PMU_UNK1 0x10
56 #define PHYCTL_DATA BIT(7)
58 #define OTGCTL_ROUTE_MUSB BIT(0)
60 #define SUNXI_AHB_ICHR8_EN BIT(10)
61 #define SUNXI_AHB_INCR4_BURST_EN BIT(9)
62 #define SUNXI_AHB_INCRX_ALIGN_EN BIT(8)
63 #define SUNXI_ULPI_BYPASS_EN BIT(0)
65 /* ISCR, Interface Status and Control bits */
66 #define ISCR_ID_PULLUP_EN (1 << 17)
67 #define ISCR_DPDM_PULLUP_EN (1 << 16)
68 /* sunxi has the phy id/vbus pins not connected, so we use the force bits */
69 #define ISCR_FORCE_ID_MASK (3 << 14)
70 #define ISCR_FORCE_ID_LOW (2 << 14)
71 #define ISCR_FORCE_ID_HIGH (3 << 14)
72 #define ISCR_FORCE_VBUS_MASK (3 << 12)
73 #define ISCR_FORCE_VBUS_LOW (2 << 12)
74 #define ISCR_FORCE_VBUS_HIGH (3 << 12)
76 /* Common Control Bits for Both PHYs */
77 #define PHY_PLL_BW 0x03
78 #define PHY_RES45_CAL_EN 0x0c
80 /* Private Control Bits for Each PHY */
81 #define PHY_TX_AMPLITUDE_TUNE 0x20
82 #define PHY_TX_SLEWRATE_TUNE 0x22
83 #define PHY_VBUSVALID_TH_SEL 0x25
84 #define PHY_PULLUP_RES_SEL 0x27
85 #define PHY_OTG_FUNC_EN 0x28
86 #define PHY_VBUS_DET_EN 0x29
87 #define PHY_DISCON_TH_SEL 0x2a
88 #define PHY_SQUELCH_DETECT 0x3c
93 * Note do not raise the debounce time, we must report Vusb high within 100ms
94 * otherwise we get Vbus errors
96 #define DEBOUNCE_TIME msecs_to_jiffies(50)
97 #define POLL_TIME msecs_to_jiffies(250)
99 enum sun4i_usb_phy_type {
108 struct sun4i_usb_phy_cfg {
110 enum sun4i_usb_phy_type type;
113 bool dedicated_clocks;
114 bool enable_pmu_unk1;
115 bool phy0_dual_route;
118 struct sun4i_usb_phy_data {
120 const struct sun4i_usb_phy_cfg *cfg;
121 enum usb_dr_mode dr_mode;
122 spinlock_t reg_lock; /* guard access to phyctl reg */
123 struct sun4i_usb_phy {
126 struct regulator *vbus;
127 struct reset_control *reset;
132 /* phy0 / otg related variables */
133 struct extcon_dev *extcon;
135 struct gpio_desc *id_det_gpio;
136 struct gpio_desc *vbus_det_gpio;
137 struct power_supply *vbus_power_supply;
138 struct notifier_block vbus_power_nb;
139 bool vbus_power_nb_registered;
140 bool force_session_end;
145 struct delayed_work detect;
148 #define to_sun4i_usb_phy_data(phy) \
149 container_of((phy), struct sun4i_usb_phy_data, phys[(phy)->index])
151 static void sun4i_usb_phy0_update_iscr(struct phy *_phy, u32 clr, u32 set)
153 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
154 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
157 iscr = readl(data->base + REG_ISCR);
160 writel(iscr, data->base + REG_ISCR);
163 static void sun4i_usb_phy0_set_id_detect(struct phy *phy, u32 val)
166 val = ISCR_FORCE_ID_HIGH;
168 val = ISCR_FORCE_ID_LOW;
170 sun4i_usb_phy0_update_iscr(phy, ISCR_FORCE_ID_MASK, val);
173 static void sun4i_usb_phy0_set_vbus_detect(struct phy *phy, u32 val)
176 val = ISCR_FORCE_VBUS_HIGH;
178 val = ISCR_FORCE_VBUS_LOW;
180 sun4i_usb_phy0_update_iscr(phy, ISCR_FORCE_VBUS_MASK, val);
183 static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data,
186 struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy);
187 u32 temp, usbc_bit = BIT(phy->index * 2);
188 void __iomem *phyctl = phy_data->base + phy_data->cfg->phyctl_offset;
192 spin_lock_irqsave(&phy_data->reg_lock, flags);
194 if (phy_data->cfg->phyctl_offset == REG_PHYCTL_A33) {
195 /* SoCs newer than A33 need us to set phyctl to 0 explicitly */
199 for (i = 0; i < len; i++) {
200 temp = readl(phyctl);
202 /* clear the address portion */
203 temp &= ~(0xff << 8);
205 /* set the address */
206 temp |= ((addr + i) << 8);
207 writel(temp, phyctl);
209 /* set the data bit and clear usbc bit*/
210 temp = readb(phyctl);
214 temp &= ~PHYCTL_DATA;
216 writeb(temp, phyctl);
219 temp = readb(phyctl);
221 writeb(temp, phyctl);
223 temp = readb(phyctl);
225 writeb(temp, phyctl);
230 spin_unlock_irqrestore(&phy_data->reg_lock, flags);
233 static void sun4i_usb_phy_passby(struct sun4i_usb_phy *phy, int enable)
240 bits = SUNXI_AHB_ICHR8_EN | SUNXI_AHB_INCR4_BURST_EN |
241 SUNXI_AHB_INCRX_ALIGN_EN | SUNXI_ULPI_BYPASS_EN;
243 reg_value = readl(phy->pmu);
250 writel(reg_value, phy->pmu);
253 static int sun4i_usb_phy_init(struct phy *_phy)
255 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
256 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
260 ret = clk_prepare_enable(phy->clk);
264 ret = reset_control_deassert(phy->reset);
266 clk_disable_unprepare(phy->clk);
270 if (phy->pmu && data->cfg->enable_pmu_unk1) {
271 val = readl(phy->pmu + REG_PMU_UNK1);
272 writel(val & ~2, phy->pmu + REG_PMU_UNK1);
275 /* Enable USB 45 Ohm resistor calibration */
277 sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
279 /* Adjust PHY's magnitude and rate */
280 sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
282 /* Disconnect threshold adjustment */
283 sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
284 data->cfg->disc_thresh, 2);
286 sun4i_usb_phy_passby(phy, 1);
288 if (phy->index == 0) {
289 data->phy0_init = true;
291 /* Enable pull-ups */
292 sun4i_usb_phy0_update_iscr(_phy, 0, ISCR_DPDM_PULLUP_EN);
293 sun4i_usb_phy0_update_iscr(_phy, 0, ISCR_ID_PULLUP_EN);
295 /* Force ISCR and cable state updates */
298 queue_delayed_work(system_wq, &data->detect, 0);
304 static int sun4i_usb_phy_exit(struct phy *_phy)
306 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
307 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
309 if (phy->index == 0) {
310 /* Disable pull-ups */
311 sun4i_usb_phy0_update_iscr(_phy, ISCR_DPDM_PULLUP_EN, 0);
312 sun4i_usb_phy0_update_iscr(_phy, ISCR_ID_PULLUP_EN, 0);
313 data->phy0_init = false;
316 sun4i_usb_phy_passby(phy, 0);
317 reset_control_assert(phy->reset);
318 clk_disable_unprepare(phy->clk);
323 static int sun4i_usb_phy0_get_id_det(struct sun4i_usb_phy_data *data)
325 switch (data->dr_mode) {
326 case USB_DR_MODE_OTG:
327 if (data->id_det_gpio)
328 return gpiod_get_value_cansleep(data->id_det_gpio);
330 return 1; /* Fallback to peripheral mode */
331 case USB_DR_MODE_HOST:
333 case USB_DR_MODE_PERIPHERAL:
339 static int sun4i_usb_phy0_get_vbus_det(struct sun4i_usb_phy_data *data)
341 if (data->vbus_det_gpio)
342 return gpiod_get_value_cansleep(data->vbus_det_gpio);
344 if (data->vbus_power_supply) {
345 union power_supply_propval val;
348 r = power_supply_get_property(data->vbus_power_supply,
349 POWER_SUPPLY_PROP_PRESENT, &val);
354 /* Fallback: report vbus as high */
358 static bool sun4i_usb_phy0_have_vbus_det(struct sun4i_usb_phy_data *data)
360 return data->vbus_det_gpio || data->vbus_power_supply;
363 static bool sun4i_usb_phy0_poll(struct sun4i_usb_phy_data *data)
365 if ((data->id_det_gpio && data->id_det_irq <= 0) ||
366 (data->vbus_det_gpio && data->vbus_det_irq <= 0))
370 * The A31 companion pmic (axp221) does not generate vbus change
371 * interrupts when the board is driving vbus, so we must poll
372 * when using the pmic for vbus-det _and_ we're driving vbus.
374 if (data->cfg->type == sun6i_a31_phy &&
375 data->vbus_power_supply && data->phys[0].regulator_on)
381 static int sun4i_usb_phy_power_on(struct phy *_phy)
383 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
384 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
387 if (!phy->vbus || phy->regulator_on)
390 /* For phy0 only turn on Vbus if we don't have an ext. Vbus */
391 if (phy->index == 0 && sun4i_usb_phy0_have_vbus_det(data) &&
393 dev_warn(&_phy->dev, "External vbus detected, not enabling our own vbus\n");
397 ret = regulator_enable(phy->vbus);
401 phy->regulator_on = true;
403 /* We must report Vbus high within OTG_TIME_A_WAIT_VRISE msec. */
404 if (phy->index == 0 && sun4i_usb_phy0_poll(data))
405 mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
410 static int sun4i_usb_phy_power_off(struct phy *_phy)
412 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
413 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
415 if (!phy->vbus || !phy->regulator_on)
418 regulator_disable(phy->vbus);
419 phy->regulator_on = false;
422 * phy0 vbus typically slowly discharges, sometimes this causes the
423 * Vbus gpio to not trigger an edge irq on Vbus off, so force a rescan.
425 if (phy->index == 0 && !sun4i_usb_phy0_poll(data))
426 mod_delayed_work(system_wq, &data->detect, POLL_TIME);
431 static int sun4i_usb_phy_set_mode(struct phy *_phy, enum phy_mode mode)
433 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
434 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
441 case PHY_MODE_USB_HOST:
442 new_mode = USB_DR_MODE_HOST;
444 case PHY_MODE_USB_DEVICE:
445 new_mode = USB_DR_MODE_PERIPHERAL;
447 case PHY_MODE_USB_OTG:
448 new_mode = USB_DR_MODE_OTG;
454 if (new_mode != data->dr_mode) {
455 dev_info(&_phy->dev, "Changing dr_mode to %d\n", new_mode);
456 data->dr_mode = new_mode;
459 data->id_det = -1; /* Force reprocessing of id */
460 data->force_session_end = true;
461 queue_delayed_work(system_wq, &data->detect, 0);
466 void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled)
468 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
470 sun4i_usb_phy_write(phy, PHY_SQUELCH_DETECT, enabled ? 0 : 2, 2);
472 EXPORT_SYMBOL_GPL(sun4i_usb_phy_set_squelch_detect);
474 static const struct phy_ops sun4i_usb_phy_ops = {
475 .init = sun4i_usb_phy_init,
476 .exit = sun4i_usb_phy_exit,
477 .power_on = sun4i_usb_phy_power_on,
478 .power_off = sun4i_usb_phy_power_off,
479 .set_mode = sun4i_usb_phy_set_mode,
480 .owner = THIS_MODULE,
483 static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, int id_det)
487 regval = readl(data->base + REG_PHY_OTGCTL);
489 /* Host mode. Route phy0 to EHCI/OHCI */
490 regval &= ~OTGCTL_ROUTE_MUSB;
492 /* Peripheral mode. Route phy0 to MUSB */
493 regval |= OTGCTL_ROUTE_MUSB;
495 writel(regval, data->base + REG_PHY_OTGCTL);
498 static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
500 struct sun4i_usb_phy_data *data =
501 container_of(work, struct sun4i_usb_phy_data, detect.work);
502 struct phy *phy0 = data->phys[0].phy;
503 bool force_session_end, id_notify = false, vbus_notify = false;
504 int id_det, vbus_det;
509 id_det = sun4i_usb_phy0_get_id_det(data);
510 vbus_det = sun4i_usb_phy0_get_vbus_det(data);
512 mutex_lock(&phy0->mutex);
514 if (!data->phy0_init) {
515 mutex_unlock(&phy0->mutex);
519 force_session_end = data->force_session_end;
520 data->force_session_end = false;
522 if (id_det != data->id_det) {
523 /* id-change, force session end if we've no vbus detection */
524 if (data->dr_mode == USB_DR_MODE_OTG &&
525 !sun4i_usb_phy0_have_vbus_det(data))
526 force_session_end = true;
528 /* When entering host mode (id = 0) force end the session now */
529 if (force_session_end && id_det == 0) {
530 sun4i_usb_phy0_set_vbus_detect(phy0, 0);
532 sun4i_usb_phy0_set_vbus_detect(phy0, 1);
534 sun4i_usb_phy0_set_id_detect(phy0, id_det);
535 data->id_det = id_det;
539 if (vbus_det != data->vbus_det) {
540 sun4i_usb_phy0_set_vbus_detect(phy0, vbus_det);
541 data->vbus_det = vbus_det;
545 mutex_unlock(&phy0->mutex);
548 extcon_set_state_sync(data->extcon, EXTCON_USB_HOST,
550 /* When leaving host mode force end the session here */
551 if (force_session_end && id_det == 1) {
552 mutex_lock(&phy0->mutex);
553 sun4i_usb_phy0_set_vbus_detect(phy0, 0);
555 sun4i_usb_phy0_set_vbus_detect(phy0, 1);
556 mutex_unlock(&phy0->mutex);
559 /* Re-route PHY0 if necessary */
560 if (data->cfg->phy0_dual_route)
561 sun4i_usb_phy0_reroute(data, id_det);
565 extcon_set_state_sync(data->extcon, EXTCON_USB, vbus_det);
567 if (sun4i_usb_phy0_poll(data))
568 queue_delayed_work(system_wq, &data->detect, POLL_TIME);
571 static irqreturn_t sun4i_usb_phy0_id_vbus_det_irq(int irq, void *dev_id)
573 struct sun4i_usb_phy_data *data = dev_id;
575 /* vbus or id changed, let the pins settle and then scan them */
576 mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
581 static int sun4i_usb_phy0_vbus_notify(struct notifier_block *nb,
582 unsigned long val, void *v)
584 struct sun4i_usb_phy_data *data =
585 container_of(nb, struct sun4i_usb_phy_data, vbus_power_nb);
586 struct power_supply *psy = v;
588 /* Properties on the vbus_power_supply changed, scan vbus_det */
589 if (val == PSY_EVENT_PROP_CHANGED && psy == data->vbus_power_supply)
590 mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
595 static struct phy *sun4i_usb_phy_xlate(struct device *dev,
596 struct of_phandle_args *args)
598 struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
600 if (args->args[0] >= data->cfg->num_phys)
601 return ERR_PTR(-ENODEV);
603 return data->phys[args->args[0]].phy;
606 static int sun4i_usb_phy_remove(struct platform_device *pdev)
608 struct device *dev = &pdev->dev;
609 struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
611 if (data->vbus_power_nb_registered)
612 power_supply_unreg_notifier(&data->vbus_power_nb);
613 if (data->id_det_irq > 0)
614 devm_free_irq(dev, data->id_det_irq, data);
615 if (data->vbus_det_irq > 0)
616 devm_free_irq(dev, data->vbus_det_irq, data);
618 cancel_delayed_work_sync(&data->detect);
623 static const unsigned int sun4i_usb_phy0_cable[] = {
629 static int sun4i_usb_phy_probe(struct platform_device *pdev)
631 struct sun4i_usb_phy_data *data;
632 struct device *dev = &pdev->dev;
633 struct device_node *np = dev->of_node;
634 struct phy_provider *phy_provider;
635 struct resource *res;
638 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
642 spin_lock_init(&data->reg_lock);
643 INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan);
644 dev_set_drvdata(dev, data);
645 data->cfg = of_device_get_match_data(dev);
649 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_ctrl");
650 data->base = devm_ioremap_resource(dev, res);
651 if (IS_ERR(data->base))
652 return PTR_ERR(data->base);
654 data->id_det_gpio = devm_gpiod_get_optional(dev, "usb0_id_det",
656 if (IS_ERR(data->id_det_gpio))
657 return PTR_ERR(data->id_det_gpio);
659 data->vbus_det_gpio = devm_gpiod_get_optional(dev, "usb0_vbus_det",
661 if (IS_ERR(data->vbus_det_gpio))
662 return PTR_ERR(data->vbus_det_gpio);
664 if (of_find_property(np, "usb0_vbus_power-supply", NULL)) {
665 data->vbus_power_supply = devm_power_supply_get_by_phandle(dev,
666 "usb0_vbus_power-supply");
667 if (IS_ERR(data->vbus_power_supply))
668 return PTR_ERR(data->vbus_power_supply);
670 if (!data->vbus_power_supply)
671 return -EPROBE_DEFER;
674 data->dr_mode = of_usb_get_dr_mode_by_phy(np, 0);
676 data->extcon = devm_extcon_dev_allocate(dev, sun4i_usb_phy0_cable);
677 if (IS_ERR(data->extcon))
678 return PTR_ERR(data->extcon);
680 ret = devm_extcon_dev_register(dev, data->extcon);
682 dev_err(dev, "failed to register extcon: %d\n", ret);
686 for (i = 0; i < data->cfg->num_phys; i++) {
687 struct sun4i_usb_phy *phy = data->phys + i;
690 snprintf(name, sizeof(name), "usb%d_vbus", i);
691 phy->vbus = devm_regulator_get_optional(dev, name);
692 if (IS_ERR(phy->vbus)) {
693 if (PTR_ERR(phy->vbus) == -EPROBE_DEFER)
694 return -EPROBE_DEFER;
698 if (data->cfg->dedicated_clocks)
699 snprintf(name, sizeof(name), "usb%d_phy", i);
701 strlcpy(name, "usb_phy", sizeof(name));
703 phy->clk = devm_clk_get(dev, name);
704 if (IS_ERR(phy->clk)) {
705 dev_err(dev, "failed to get clock %s\n", name);
706 return PTR_ERR(phy->clk);
709 snprintf(name, sizeof(name), "usb%d_reset", i);
710 phy->reset = devm_reset_control_get(dev, name);
711 if (IS_ERR(phy->reset)) {
712 dev_err(dev, "failed to get reset %s\n", name);
713 return PTR_ERR(phy->reset);
716 if (i || data->cfg->phy0_dual_route) { /* No pmu for musb */
717 snprintf(name, sizeof(name), "pmu%d", i);
718 res = platform_get_resource_byname(pdev,
719 IORESOURCE_MEM, name);
720 phy->pmu = devm_ioremap_resource(dev, res);
721 if (IS_ERR(phy->pmu))
722 return PTR_ERR(phy->pmu);
725 phy->phy = devm_phy_create(dev, NULL, &sun4i_usb_phy_ops);
726 if (IS_ERR(phy->phy)) {
727 dev_err(dev, "failed to create PHY %d\n", i);
728 return PTR_ERR(phy->phy);
732 phy_set_drvdata(phy->phy, &data->phys[i]);
735 data->id_det_irq = gpiod_to_irq(data->id_det_gpio);
736 if (data->id_det_irq > 0) {
737 ret = devm_request_irq(dev, data->id_det_irq,
738 sun4i_usb_phy0_id_vbus_det_irq,
739 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
740 "usb0-id-det", data);
742 dev_err(dev, "Err requesting id-det-irq: %d\n", ret);
747 data->vbus_det_irq = gpiod_to_irq(data->vbus_det_gpio);
748 if (data->vbus_det_irq > 0) {
749 ret = devm_request_irq(dev, data->vbus_det_irq,
750 sun4i_usb_phy0_id_vbus_det_irq,
751 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
752 "usb0-vbus-det", data);
754 dev_err(dev, "Err requesting vbus-det-irq: %d\n", ret);
755 data->vbus_det_irq = -1;
756 sun4i_usb_phy_remove(pdev); /* Stop detect work */
761 if (data->vbus_power_supply) {
762 data->vbus_power_nb.notifier_call = sun4i_usb_phy0_vbus_notify;
763 data->vbus_power_nb.priority = 0;
764 ret = power_supply_reg_notifier(&data->vbus_power_nb);
766 sun4i_usb_phy_remove(pdev); /* Stop detect work */
769 data->vbus_power_nb_registered = true;
772 phy_provider = devm_of_phy_provider_register(dev, sun4i_usb_phy_xlate);
773 if (IS_ERR(phy_provider)) {
774 sun4i_usb_phy_remove(pdev); /* Stop detect work */
775 return PTR_ERR(phy_provider);
781 static const struct sun4i_usb_phy_cfg sun4i_a10_cfg = {
783 .type = sun4i_a10_phy,
785 .phyctl_offset = REG_PHYCTL_A10,
786 .dedicated_clocks = false,
787 .enable_pmu_unk1 = false,
790 static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = {
792 .type = sun4i_a10_phy,
794 .phyctl_offset = REG_PHYCTL_A10,
795 .dedicated_clocks = false,
796 .enable_pmu_unk1 = false,
799 static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = {
801 .type = sun6i_a31_phy,
803 .phyctl_offset = REG_PHYCTL_A10,
804 .dedicated_clocks = true,
805 .enable_pmu_unk1 = false,
808 static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = {
810 .type = sun4i_a10_phy,
812 .phyctl_offset = REG_PHYCTL_A10,
813 .dedicated_clocks = false,
814 .enable_pmu_unk1 = false,
817 static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = {
819 .type = sun4i_a10_phy,
821 .phyctl_offset = REG_PHYCTL_A10,
822 .dedicated_clocks = true,
823 .enable_pmu_unk1 = false,
826 static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = {
828 .type = sun8i_a33_phy,
830 .phyctl_offset = REG_PHYCTL_A33,
831 .dedicated_clocks = true,
832 .enable_pmu_unk1 = false,
835 static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
837 .type = sun8i_h3_phy,
839 .phyctl_offset = REG_PHYCTL_A33,
840 .dedicated_clocks = true,
841 .enable_pmu_unk1 = true,
842 .phy0_dual_route = true,
845 static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
847 .type = sun8i_v3s_phy,
849 .phyctl_offset = REG_PHYCTL_A33,
850 .dedicated_clocks = true,
851 .enable_pmu_unk1 = true,
854 static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = {
856 .type = sun50i_a64_phy,
858 .phyctl_offset = REG_PHYCTL_A33,
859 .dedicated_clocks = true,
860 .enable_pmu_unk1 = true,
861 .phy0_dual_route = true,
864 static const struct of_device_id sun4i_usb_phy_of_match[] = {
865 { .compatible = "allwinner,sun4i-a10-usb-phy", .data = &sun4i_a10_cfg },
866 { .compatible = "allwinner,sun5i-a13-usb-phy", .data = &sun5i_a13_cfg },
867 { .compatible = "allwinner,sun6i-a31-usb-phy", .data = &sun6i_a31_cfg },
868 { .compatible = "allwinner,sun7i-a20-usb-phy", .data = &sun7i_a20_cfg },
869 { .compatible = "allwinner,sun8i-a23-usb-phy", .data = &sun8i_a23_cfg },
870 { .compatible = "allwinner,sun8i-a33-usb-phy", .data = &sun8i_a33_cfg },
871 { .compatible = "allwinner,sun8i-h3-usb-phy", .data = &sun8i_h3_cfg },
872 { .compatible = "allwinner,sun8i-v3s-usb-phy", .data = &sun8i_v3s_cfg },
873 { .compatible = "allwinner,sun50i-a64-usb-phy",
874 .data = &sun50i_a64_cfg},
877 MODULE_DEVICE_TABLE(of, sun4i_usb_phy_of_match);
879 static struct platform_driver sun4i_usb_phy_driver = {
880 .probe = sun4i_usb_phy_probe,
881 .remove = sun4i_usb_phy_remove,
883 .of_match_table = sun4i_usb_phy_of_match,
884 .name = "sun4i-usb-phy",
887 module_platform_driver(sun4i_usb_phy_driver);
889 MODULE_DESCRIPTION("Allwinner sun4i USB phy driver");
890 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
891 MODULE_LICENSE("GPL v2");