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_UNK_H3 0x20
54 #define REG_PMU_UNK1 0x10
56 #define PHYCTL_DATA BIT(7)
58 #define SUNXI_AHB_ICHR8_EN BIT(10)
59 #define SUNXI_AHB_INCR4_BURST_EN BIT(9)
60 #define SUNXI_AHB_INCRX_ALIGN_EN BIT(8)
61 #define SUNXI_ULPI_BYPASS_EN BIT(0)
63 /* ISCR, Interface Status and Control bits */
64 #define ISCR_ID_PULLUP_EN (1 << 17)
65 #define ISCR_DPDM_PULLUP_EN (1 << 16)
66 /* sunxi has the phy id/vbus pins not connected, so we use the force bits */
67 #define ISCR_FORCE_ID_MASK (3 << 14)
68 #define ISCR_FORCE_ID_LOW (2 << 14)
69 #define ISCR_FORCE_ID_HIGH (3 << 14)
70 #define ISCR_FORCE_VBUS_MASK (3 << 12)
71 #define ISCR_FORCE_VBUS_LOW (2 << 12)
72 #define ISCR_FORCE_VBUS_HIGH (3 << 12)
74 /* Common Control Bits for Both PHYs */
75 #define PHY_PLL_BW 0x03
76 #define PHY_RES45_CAL_EN 0x0c
78 /* Private Control Bits for Each PHY */
79 #define PHY_TX_AMPLITUDE_TUNE 0x20
80 #define PHY_TX_SLEWRATE_TUNE 0x22
81 #define PHY_VBUSVALID_TH_SEL 0x25
82 #define PHY_PULLUP_RES_SEL 0x27
83 #define PHY_OTG_FUNC_EN 0x28
84 #define PHY_VBUS_DET_EN 0x29
85 #define PHY_DISCON_TH_SEL 0x2a
86 #define PHY_SQUELCH_DETECT 0x3c
91 * Note do not raise the debounce time, we must report Vusb high within 100ms
92 * otherwise we get Vbus errors
94 #define DEBOUNCE_TIME msecs_to_jiffies(50)
95 #define POLL_TIME msecs_to_jiffies(250)
97 enum sun4i_usb_phy_type {
106 struct sun4i_usb_phy_cfg {
108 enum sun4i_usb_phy_type type;
111 bool dedicated_clocks;
112 bool enable_pmu_unk1;
115 struct sun4i_usb_phy_data {
117 const struct sun4i_usb_phy_cfg *cfg;
118 enum usb_dr_mode dr_mode;
119 spinlock_t reg_lock; /* guard access to phyctl reg */
120 struct sun4i_usb_phy {
123 struct regulator *vbus;
124 struct reset_control *reset;
129 /* phy0 / otg related variables */
130 struct extcon_dev *extcon;
132 struct gpio_desc *id_det_gpio;
133 struct gpio_desc *vbus_det_gpio;
134 struct power_supply *vbus_power_supply;
135 struct notifier_block vbus_power_nb;
136 bool vbus_power_nb_registered;
137 bool force_session_end;
142 struct delayed_work detect;
145 #define to_sun4i_usb_phy_data(phy) \
146 container_of((phy), struct sun4i_usb_phy_data, phys[(phy)->index])
148 static void sun4i_usb_phy0_update_iscr(struct phy *_phy, u32 clr, u32 set)
150 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
151 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
154 iscr = readl(data->base + REG_ISCR);
157 writel(iscr, data->base + REG_ISCR);
160 static void sun4i_usb_phy0_set_id_detect(struct phy *phy, u32 val)
163 val = ISCR_FORCE_ID_HIGH;
165 val = ISCR_FORCE_ID_LOW;
167 sun4i_usb_phy0_update_iscr(phy, ISCR_FORCE_ID_MASK, val);
170 static void sun4i_usb_phy0_set_vbus_detect(struct phy *phy, u32 val)
173 val = ISCR_FORCE_VBUS_HIGH;
175 val = ISCR_FORCE_VBUS_LOW;
177 sun4i_usb_phy0_update_iscr(phy, ISCR_FORCE_VBUS_MASK, val);
180 static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data,
183 struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy);
184 u32 temp, usbc_bit = BIT(phy->index * 2);
185 void __iomem *phyctl = phy_data->base + phy_data->cfg->phyctl_offset;
189 spin_lock_irqsave(&phy_data->reg_lock, flags);
191 if (phy_data->cfg->type == sun8i_a33_phy ||
192 phy_data->cfg->type == sun50i_a64_phy ||
193 phy_data->cfg->type == sun8i_v3s_phy) {
194 /* A33 or A64 needs us to set phyctl to 0 explicitly */
198 for (i = 0; i < len; i++) {
199 temp = readl(phyctl);
201 /* clear the address portion */
202 temp &= ~(0xff << 8);
204 /* set the address */
205 temp |= ((addr + i) << 8);
206 writel(temp, phyctl);
208 /* set the data bit and clear usbc bit*/
209 temp = readb(phyctl);
213 temp &= ~PHYCTL_DATA;
215 writeb(temp, phyctl);
218 temp = readb(phyctl);
220 writeb(temp, phyctl);
222 temp = readb(phyctl);
224 writeb(temp, phyctl);
229 spin_unlock_irqrestore(&phy_data->reg_lock, flags);
232 static void sun4i_usb_phy_passby(struct sun4i_usb_phy *phy, int enable)
239 bits = SUNXI_AHB_ICHR8_EN | SUNXI_AHB_INCR4_BURST_EN |
240 SUNXI_AHB_INCRX_ALIGN_EN | SUNXI_ULPI_BYPASS_EN;
242 reg_value = readl(phy->pmu);
249 writel(reg_value, phy->pmu);
252 static int sun4i_usb_phy_init(struct phy *_phy)
254 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
255 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
259 ret = clk_prepare_enable(phy->clk);
263 ret = reset_control_deassert(phy->reset);
265 clk_disable_unprepare(phy->clk);
269 if (phy->pmu && data->cfg->enable_pmu_unk1) {
270 val = readl(phy->pmu + REG_PMU_UNK1);
271 writel(val & ~2, phy->pmu + REG_PMU_UNK1);
274 if (data->cfg->type == sun8i_h3_phy) {
275 if (phy->index == 0) {
276 val = readl(data->base + REG_PHY_UNK_H3);
277 writel(val & ~1, data->base + REG_PHY_UNK_H3);
280 /* Enable USB 45 Ohm resistor calibration */
282 sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
284 /* Adjust PHY's magnitude and rate */
285 sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
287 /* Disconnect threshold adjustment */
288 sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
289 data->cfg->disc_thresh, 2);
292 sun4i_usb_phy_passby(phy, 1);
294 if (phy->index == 0) {
295 data->phy0_init = true;
297 /* Enable pull-ups */
298 sun4i_usb_phy0_update_iscr(_phy, 0, ISCR_DPDM_PULLUP_EN);
299 sun4i_usb_phy0_update_iscr(_phy, 0, ISCR_ID_PULLUP_EN);
301 /* Force ISCR and cable state updates */
304 queue_delayed_work(system_wq, &data->detect, 0);
310 static int sun4i_usb_phy_exit(struct phy *_phy)
312 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
313 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
315 if (phy->index == 0) {
316 /* Disable pull-ups */
317 sun4i_usb_phy0_update_iscr(_phy, ISCR_DPDM_PULLUP_EN, 0);
318 sun4i_usb_phy0_update_iscr(_phy, ISCR_ID_PULLUP_EN, 0);
319 data->phy0_init = false;
322 sun4i_usb_phy_passby(phy, 0);
323 reset_control_assert(phy->reset);
324 clk_disable_unprepare(phy->clk);
329 static int sun4i_usb_phy0_get_id_det(struct sun4i_usb_phy_data *data)
331 switch (data->dr_mode) {
332 case USB_DR_MODE_OTG:
333 if (data->id_det_gpio)
334 return gpiod_get_value_cansleep(data->id_det_gpio);
336 return 1; /* Fallback to peripheral mode */
337 case USB_DR_MODE_HOST:
339 case USB_DR_MODE_PERIPHERAL:
345 static int sun4i_usb_phy0_get_vbus_det(struct sun4i_usb_phy_data *data)
347 if (data->vbus_det_gpio)
348 return gpiod_get_value_cansleep(data->vbus_det_gpio);
350 if (data->vbus_power_supply) {
351 union power_supply_propval val;
354 r = power_supply_get_property(data->vbus_power_supply,
355 POWER_SUPPLY_PROP_PRESENT, &val);
360 /* Fallback: report vbus as high */
364 static bool sun4i_usb_phy0_have_vbus_det(struct sun4i_usb_phy_data *data)
366 return data->vbus_det_gpio || data->vbus_power_supply;
369 static bool sun4i_usb_phy0_poll(struct sun4i_usb_phy_data *data)
371 if ((data->id_det_gpio && data->id_det_irq <= 0) ||
372 (data->vbus_det_gpio && data->vbus_det_irq <= 0))
376 * The A31 companion pmic (axp221) does not generate vbus change
377 * interrupts when the board is driving vbus, so we must poll
378 * when using the pmic for vbus-det _and_ we're driving vbus.
380 if (data->cfg->type == sun6i_a31_phy &&
381 data->vbus_power_supply && data->phys[0].regulator_on)
387 static int sun4i_usb_phy_power_on(struct phy *_phy)
389 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
390 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
393 if (!phy->vbus || phy->regulator_on)
396 /* For phy0 only turn on Vbus if we don't have an ext. Vbus */
397 if (phy->index == 0 && sun4i_usb_phy0_have_vbus_det(data) &&
399 dev_warn(&_phy->dev, "External vbus detected, not enabling our own vbus\n");
403 ret = regulator_enable(phy->vbus);
407 phy->regulator_on = true;
409 /* We must report Vbus high within OTG_TIME_A_WAIT_VRISE msec. */
410 if (phy->index == 0 && sun4i_usb_phy0_poll(data))
411 mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
416 static int sun4i_usb_phy_power_off(struct phy *_phy)
418 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
419 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
421 if (!phy->vbus || !phy->regulator_on)
424 regulator_disable(phy->vbus);
425 phy->regulator_on = false;
428 * phy0 vbus typically slowly discharges, sometimes this causes the
429 * Vbus gpio to not trigger an edge irq on Vbus off, so force a rescan.
431 if (phy->index == 0 && !sun4i_usb_phy0_poll(data))
432 mod_delayed_work(system_wq, &data->detect, POLL_TIME);
437 static int sun4i_usb_phy_set_mode(struct phy *_phy, enum phy_mode mode)
439 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
440 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
447 case PHY_MODE_USB_HOST:
448 new_mode = USB_DR_MODE_HOST;
450 case PHY_MODE_USB_DEVICE:
451 new_mode = USB_DR_MODE_PERIPHERAL;
453 case PHY_MODE_USB_OTG:
454 new_mode = USB_DR_MODE_OTG;
460 if (new_mode != data->dr_mode) {
461 dev_info(&_phy->dev, "Changing dr_mode to %d\n", new_mode);
462 data->dr_mode = new_mode;
465 data->id_det = -1; /* Force reprocessing of id */
466 data->force_session_end = true;
467 queue_delayed_work(system_wq, &data->detect, 0);
472 void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled)
474 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
476 sun4i_usb_phy_write(phy, PHY_SQUELCH_DETECT, enabled ? 0 : 2, 2);
478 EXPORT_SYMBOL_GPL(sun4i_usb_phy_set_squelch_detect);
480 static const struct phy_ops sun4i_usb_phy_ops = {
481 .init = sun4i_usb_phy_init,
482 .exit = sun4i_usb_phy_exit,
483 .power_on = sun4i_usb_phy_power_on,
484 .power_off = sun4i_usb_phy_power_off,
485 .set_mode = sun4i_usb_phy_set_mode,
486 .owner = THIS_MODULE,
489 static void sun4i_usb_phy0_id_vbus_det_scan(struct work_struct *work)
491 struct sun4i_usb_phy_data *data =
492 container_of(work, struct sun4i_usb_phy_data, detect.work);
493 struct phy *phy0 = data->phys[0].phy;
494 bool force_session_end, id_notify = false, vbus_notify = false;
495 int id_det, vbus_det;
500 id_det = sun4i_usb_phy0_get_id_det(data);
501 vbus_det = sun4i_usb_phy0_get_vbus_det(data);
503 mutex_lock(&phy0->mutex);
505 if (!data->phy0_init) {
506 mutex_unlock(&phy0->mutex);
510 force_session_end = data->force_session_end;
511 data->force_session_end = false;
513 if (id_det != data->id_det) {
514 /* id-change, force session end if we've no vbus detection */
515 if (data->dr_mode == USB_DR_MODE_OTG &&
516 !sun4i_usb_phy0_have_vbus_det(data))
517 force_session_end = true;
519 /* When entering host mode (id = 0) force end the session now */
520 if (force_session_end && id_det == 0) {
521 sun4i_usb_phy0_set_vbus_detect(phy0, 0);
523 sun4i_usb_phy0_set_vbus_detect(phy0, 1);
525 sun4i_usb_phy0_set_id_detect(phy0, id_det);
526 data->id_det = id_det;
530 if (vbus_det != data->vbus_det) {
531 sun4i_usb_phy0_set_vbus_detect(phy0, vbus_det);
532 data->vbus_det = vbus_det;
536 mutex_unlock(&phy0->mutex);
539 extcon_set_state_sync(data->extcon, EXTCON_USB_HOST,
541 /* When leaving host mode force end the session here */
542 if (force_session_end && id_det == 1) {
543 mutex_lock(&phy0->mutex);
544 sun4i_usb_phy0_set_vbus_detect(phy0, 0);
546 sun4i_usb_phy0_set_vbus_detect(phy0, 1);
547 mutex_unlock(&phy0->mutex);
552 extcon_set_state_sync(data->extcon, EXTCON_USB, vbus_det);
554 if (sun4i_usb_phy0_poll(data))
555 queue_delayed_work(system_wq, &data->detect, POLL_TIME);
558 static irqreturn_t sun4i_usb_phy0_id_vbus_det_irq(int irq, void *dev_id)
560 struct sun4i_usb_phy_data *data = dev_id;
562 /* vbus or id changed, let the pins settle and then scan them */
563 mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
568 static int sun4i_usb_phy0_vbus_notify(struct notifier_block *nb,
569 unsigned long val, void *v)
571 struct sun4i_usb_phy_data *data =
572 container_of(nb, struct sun4i_usb_phy_data, vbus_power_nb);
573 struct power_supply *psy = v;
575 /* Properties on the vbus_power_supply changed, scan vbus_det */
576 if (val == PSY_EVENT_PROP_CHANGED && psy == data->vbus_power_supply)
577 mod_delayed_work(system_wq, &data->detect, DEBOUNCE_TIME);
582 static struct phy *sun4i_usb_phy_xlate(struct device *dev,
583 struct of_phandle_args *args)
585 struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
587 if (args->args[0] >= data->cfg->num_phys)
588 return ERR_PTR(-ENODEV);
590 return data->phys[args->args[0]].phy;
593 static int sun4i_usb_phy_remove(struct platform_device *pdev)
595 struct device *dev = &pdev->dev;
596 struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
598 if (data->vbus_power_nb_registered)
599 power_supply_unreg_notifier(&data->vbus_power_nb);
600 if (data->id_det_irq > 0)
601 devm_free_irq(dev, data->id_det_irq, data);
602 if (data->vbus_det_irq > 0)
603 devm_free_irq(dev, data->vbus_det_irq, data);
605 cancel_delayed_work_sync(&data->detect);
610 static const unsigned int sun4i_usb_phy0_cable[] = {
616 static int sun4i_usb_phy_probe(struct platform_device *pdev)
618 struct sun4i_usb_phy_data *data;
619 struct device *dev = &pdev->dev;
620 struct device_node *np = dev->of_node;
621 struct phy_provider *phy_provider;
622 struct resource *res;
625 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
629 spin_lock_init(&data->reg_lock);
630 INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan);
631 dev_set_drvdata(dev, data);
632 data->cfg = of_device_get_match_data(dev);
636 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_ctrl");
637 data->base = devm_ioremap_resource(dev, res);
638 if (IS_ERR(data->base))
639 return PTR_ERR(data->base);
641 data->id_det_gpio = devm_gpiod_get_optional(dev, "usb0_id_det",
643 if (IS_ERR(data->id_det_gpio))
644 return PTR_ERR(data->id_det_gpio);
646 data->vbus_det_gpio = devm_gpiod_get_optional(dev, "usb0_vbus_det",
648 if (IS_ERR(data->vbus_det_gpio))
649 return PTR_ERR(data->vbus_det_gpio);
651 if (of_find_property(np, "usb0_vbus_power-supply", NULL)) {
652 data->vbus_power_supply = devm_power_supply_get_by_phandle(dev,
653 "usb0_vbus_power-supply");
654 if (IS_ERR(data->vbus_power_supply))
655 return PTR_ERR(data->vbus_power_supply);
657 if (!data->vbus_power_supply)
658 return -EPROBE_DEFER;
661 data->dr_mode = of_usb_get_dr_mode_by_phy(np, 0);
663 data->extcon = devm_extcon_dev_allocate(dev, sun4i_usb_phy0_cable);
664 if (IS_ERR(data->extcon))
665 return PTR_ERR(data->extcon);
667 ret = devm_extcon_dev_register(dev, data->extcon);
669 dev_err(dev, "failed to register extcon: %d\n", ret);
673 for (i = 0; i < data->cfg->num_phys; i++) {
674 struct sun4i_usb_phy *phy = data->phys + i;
677 snprintf(name, sizeof(name), "usb%d_vbus", i);
678 phy->vbus = devm_regulator_get_optional(dev, name);
679 if (IS_ERR(phy->vbus)) {
680 if (PTR_ERR(phy->vbus) == -EPROBE_DEFER)
681 return -EPROBE_DEFER;
685 if (data->cfg->dedicated_clocks)
686 snprintf(name, sizeof(name), "usb%d_phy", i);
688 strlcpy(name, "usb_phy", sizeof(name));
690 phy->clk = devm_clk_get(dev, name);
691 if (IS_ERR(phy->clk)) {
692 dev_err(dev, "failed to get clock %s\n", name);
693 return PTR_ERR(phy->clk);
696 snprintf(name, sizeof(name), "usb%d_reset", i);
697 phy->reset = devm_reset_control_get(dev, name);
698 if (IS_ERR(phy->reset)) {
699 dev_err(dev, "failed to get reset %s\n", name);
700 return PTR_ERR(phy->reset);
703 if (i) { /* No pmu for usbc0 */
704 snprintf(name, sizeof(name), "pmu%d", i);
705 res = platform_get_resource_byname(pdev,
706 IORESOURCE_MEM, name);
707 phy->pmu = devm_ioremap_resource(dev, res);
708 if (IS_ERR(phy->pmu))
709 return PTR_ERR(phy->pmu);
712 phy->phy = devm_phy_create(dev, NULL, &sun4i_usb_phy_ops);
713 if (IS_ERR(phy->phy)) {
714 dev_err(dev, "failed to create PHY %d\n", i);
715 return PTR_ERR(phy->phy);
719 phy_set_drvdata(phy->phy, &data->phys[i]);
722 data->id_det_irq = gpiod_to_irq(data->id_det_gpio);
723 if (data->id_det_irq > 0) {
724 ret = devm_request_irq(dev, data->id_det_irq,
725 sun4i_usb_phy0_id_vbus_det_irq,
726 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
727 "usb0-id-det", data);
729 dev_err(dev, "Err requesting id-det-irq: %d\n", ret);
734 data->vbus_det_irq = gpiod_to_irq(data->vbus_det_gpio);
735 if (data->vbus_det_irq > 0) {
736 ret = devm_request_irq(dev, data->vbus_det_irq,
737 sun4i_usb_phy0_id_vbus_det_irq,
738 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
739 "usb0-vbus-det", data);
741 dev_err(dev, "Err requesting vbus-det-irq: %d\n", ret);
742 data->vbus_det_irq = -1;
743 sun4i_usb_phy_remove(pdev); /* Stop detect work */
748 if (data->vbus_power_supply) {
749 data->vbus_power_nb.notifier_call = sun4i_usb_phy0_vbus_notify;
750 data->vbus_power_nb.priority = 0;
751 ret = power_supply_reg_notifier(&data->vbus_power_nb);
753 sun4i_usb_phy_remove(pdev); /* Stop detect work */
756 data->vbus_power_nb_registered = true;
759 phy_provider = devm_of_phy_provider_register(dev, sun4i_usb_phy_xlate);
760 if (IS_ERR(phy_provider)) {
761 sun4i_usb_phy_remove(pdev); /* Stop detect work */
762 return PTR_ERR(phy_provider);
768 static const struct sun4i_usb_phy_cfg sun4i_a10_cfg = {
770 .type = sun4i_a10_phy,
772 .phyctl_offset = REG_PHYCTL_A10,
773 .dedicated_clocks = false,
774 .enable_pmu_unk1 = false,
777 static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = {
779 .type = sun4i_a10_phy,
781 .phyctl_offset = REG_PHYCTL_A10,
782 .dedicated_clocks = false,
783 .enable_pmu_unk1 = false,
786 static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = {
788 .type = sun6i_a31_phy,
790 .phyctl_offset = REG_PHYCTL_A10,
791 .dedicated_clocks = true,
792 .enable_pmu_unk1 = false,
795 static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = {
797 .type = sun4i_a10_phy,
799 .phyctl_offset = REG_PHYCTL_A10,
800 .dedicated_clocks = false,
801 .enable_pmu_unk1 = false,
804 static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = {
806 .type = sun4i_a10_phy,
808 .phyctl_offset = REG_PHYCTL_A10,
809 .dedicated_clocks = true,
810 .enable_pmu_unk1 = false,
813 static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = {
815 .type = sun8i_a33_phy,
817 .phyctl_offset = REG_PHYCTL_A33,
818 .dedicated_clocks = true,
819 .enable_pmu_unk1 = false,
822 static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
824 .type = sun8i_h3_phy,
826 .dedicated_clocks = true,
827 .enable_pmu_unk1 = true,
830 static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = {
832 .type = sun8i_v3s_phy,
834 .phyctl_offset = REG_PHYCTL_A33,
835 .dedicated_clocks = true,
836 .enable_pmu_unk1 = true,
839 static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = {
841 .type = sun50i_a64_phy,
843 .phyctl_offset = REG_PHYCTL_A33,
844 .dedicated_clocks = true,
845 .enable_pmu_unk1 = true,
848 static const struct of_device_id sun4i_usb_phy_of_match[] = {
849 { .compatible = "allwinner,sun4i-a10-usb-phy", .data = &sun4i_a10_cfg },
850 { .compatible = "allwinner,sun5i-a13-usb-phy", .data = &sun5i_a13_cfg },
851 { .compatible = "allwinner,sun6i-a31-usb-phy", .data = &sun6i_a31_cfg },
852 { .compatible = "allwinner,sun7i-a20-usb-phy", .data = &sun7i_a20_cfg },
853 { .compatible = "allwinner,sun8i-a23-usb-phy", .data = &sun8i_a23_cfg },
854 { .compatible = "allwinner,sun8i-a33-usb-phy", .data = &sun8i_a33_cfg },
855 { .compatible = "allwinner,sun8i-h3-usb-phy", .data = &sun8i_h3_cfg },
856 { .compatible = "allwinner,sun8i-v3s-usb-phy", .data = &sun8i_v3s_cfg },
857 { .compatible = "allwinner,sun50i-a64-usb-phy",
858 .data = &sun50i_a64_cfg},
861 MODULE_DEVICE_TABLE(of, sun4i_usb_phy_of_match);
863 static struct platform_driver sun4i_usb_phy_driver = {
864 .probe = sun4i_usb_phy_probe,
865 .remove = sun4i_usb_phy_remove,
867 .of_match_table = sun4i_usb_phy_of_match,
868 .name = "sun4i-usb-phy",
871 module_platform_driver(sun4i_usb_phy_driver);
873 MODULE_DESCRIPTION("Allwinner sun4i USB phy driver");
874 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
875 MODULE_LICENSE("GPL v2");