Lines Matching +full:need +full:- +full:phy +full:- +full:for +full:- +full:wake
1 // SPDX-License-Identifier: GPL-2.0
159 /* For Tegra30 and above only, the address is different in Tegra20 */
221 static void set_pts(struct tegra_usb_phy *phy, u8 pts_val) in set_pts() argument
223 void __iomem *base = phy->regs; in set_pts()
226 if (phy->soc_config->has_hostpc) { in set_pts()
240 static void set_phcd(struct tegra_usb_phy *phy, bool enable) in set_phcd() argument
242 void __iomem *base = phy->regs; in set_phcd()
245 if (phy->soc_config->has_hostpc) { in set_phcd()
262 static int utmip_pad_open(struct tegra_usb_phy *phy) in utmip_pad_open() argument
266 ret = clk_prepare_enable(phy->pad_clk); in utmip_pad_open()
268 dev_err(phy->u_phy.dev, in utmip_pad_open()
269 "Failed to enable UTMI-pads clock: %d\n", ret); in utmip_pad_open()
275 ret = reset_control_deassert(phy->pad_rst); in utmip_pad_open()
277 dev_err(phy->u_phy.dev, in utmip_pad_open()
278 "Failed to initialize UTMI-pads reset: %d\n", ret); in utmip_pad_open()
282 ret = reset_control_assert(phy->pad_rst); in utmip_pad_open()
284 dev_err(phy->u_phy.dev, in utmip_pad_open()
285 "Failed to assert UTMI-pads reset: %d\n", ret); in utmip_pad_open()
291 ret = reset_control_deassert(phy->pad_rst); in utmip_pad_open()
293 dev_err(phy->u_phy.dev, in utmip_pad_open()
294 "Failed to deassert UTMI-pads reset: %d\n", ret); in utmip_pad_open()
298 clk_disable_unprepare(phy->pad_clk); in utmip_pad_open()
303 static int utmip_pad_close(struct tegra_usb_phy *phy) in utmip_pad_close() argument
307 ret = clk_prepare_enable(phy->pad_clk); in utmip_pad_close()
309 dev_err(phy->u_phy.dev, in utmip_pad_close()
310 "Failed to enable UTMI-pads clock: %d\n", ret); in utmip_pad_close()
314 ret = reset_control_assert(phy->pad_rst); in utmip_pad_close()
316 dev_err(phy->u_phy.dev, in utmip_pad_close()
317 "Failed to assert UTMI-pads reset: %d\n", ret); in utmip_pad_close()
321 clk_disable_unprepare(phy->pad_clk); in utmip_pad_close()
326 static int utmip_pad_power_on(struct tegra_usb_phy *phy) in utmip_pad_power_on() argument
328 struct tegra_utmip_config *config = phy->config; in utmip_pad_power_on()
329 void __iomem *base = phy->pad_regs; in utmip_pad_power_on()
333 err = clk_prepare_enable(phy->pad_clk); in utmip_pad_power_on()
343 if (phy->soc_config->requires_extra_tuning_parameters) { in utmip_pad_power_on()
348 val |= UTMIP_HSSQUELCH_LEVEL(config->hssquelch_level); in utmip_pad_power_on()
349 val |= UTMIP_HSDISCON_LEVEL(config->hsdiscon_level); in utmip_pad_power_on()
350 val |= UTMIP_HSDISCON_LEVEL_MSB(config->hsdiscon_level); in utmip_pad_power_on()
355 if (phy->pad_wakeup) { in utmip_pad_power_on()
356 phy->pad_wakeup = false; in utmip_pad_power_on()
357 utmip_pad_count--; in utmip_pad_power_on()
362 clk_disable_unprepare(phy->pad_clk); in utmip_pad_power_on()
367 static int utmip_pad_power_off(struct tegra_usb_phy *phy) in utmip_pad_power_off() argument
369 void __iomem *base = phy->pad_regs; in utmip_pad_power_off()
373 ret = clk_prepare_enable(phy->pad_clk); in utmip_pad_power_off()
380 dev_err(phy->u_phy.dev, "UTMIP pad already powered off\n"); in utmip_pad_power_off()
381 ret = -EINVAL; in utmip_pad_power_off()
387 * to save power if wake is enabled, but the VBUS-change detection in utmip_pad_power_off()
388 * method is board-specific and these circuits may need to be enabled in utmip_pad_power_off()
391 if (phy->wakeup_enabled) { in utmip_pad_power_off()
392 phy->pad_wakeup = true; in utmip_pad_power_off()
396 if (--utmip_pad_count == 0) { in utmip_pad_power_off()
404 clk_disable_unprepare(phy->pad_clk); in utmip_pad_power_off()
417 static void utmi_phy_clk_disable(struct tegra_usb_phy *phy) in utmi_phy_clk_disable() argument
419 void __iomem *base = phy->regs; in utmi_phy_clk_disable()
423 * The USB driver may have already initiated the phy clock in utmi_phy_clk_disable()
430 if (phy->is_legacy_phy) { in utmi_phy_clk_disable()
441 set_phcd(phy, true); in utmi_phy_clk_disable()
445 dev_err(phy->u_phy.dev, in utmi_phy_clk_disable()
446 "Timeout waiting for PHY to stabilize on disable\n"); in utmi_phy_clk_disable()
449 static void utmi_phy_clk_enable(struct tegra_usb_phy *phy) in utmi_phy_clk_enable() argument
451 void __iomem *base = phy->regs; in utmi_phy_clk_enable()
455 * The USB driver may have already initiated the phy clock in utmi_phy_clk_enable()
463 if (phy->is_legacy_phy) { in utmi_phy_clk_enable()
474 set_phcd(phy, false); in utmi_phy_clk_enable()
479 dev_err(phy->u_phy.dev, in utmi_phy_clk_enable()
480 "Timeout waiting for PHY to stabilize on enable\n"); in utmi_phy_clk_enable()
483 static int utmi_phy_power_on(struct tegra_usb_phy *phy) in utmi_phy_power_on() argument
485 struct tegra_utmip_config *config = phy->config; in utmi_phy_power_on()
486 void __iomem *base = phy->regs; in utmi_phy_power_on()
494 if (phy->is_legacy_phy) { in utmi_phy_power_on()
506 val |= UTMIP_IDLE_WAIT(config->idle_wait_delay); in utmi_phy_power_on()
507 val |= UTMIP_ELASTIC_LIMIT(config->elastic_limit); in utmi_phy_power_on()
512 val |= UTMIP_HS_SYNC_START_DLY(config->hssync_start_delay); in utmi_phy_power_on()
517 val |= UTMIP_BIAS_DEBOUNCE_A(phy->freq->debounce); in utmi_phy_power_on()
524 if (!phy->soc_config->utmi_pll_config_in_car_module) { in utmi_phy_power_on()
528 val |= UTMIP_PLL_ACTIVE_DLY_COUNT(phy->freq->active_delay) | in utmi_phy_power_on()
529 UTMIP_PLLU_STABLE_COUNT(phy->freq->stable_count); in utmi_phy_power_on()
535 val |= UTMIP_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count) | in utmi_phy_power_on()
536 UTMIP_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay); in utmi_phy_power_on()
544 if (phy->mode != USB_DR_MODE_HOST) { in utmi_phy_power_on()
568 err = utmip_pad_power_on(phy); in utmi_phy_power_on()
578 if (!config->xcvr_setup_use_fuses) { in utmi_phy_power_on()
579 val |= UTMIP_XCVR_SETUP(config->xcvr_setup); in utmi_phy_power_on()
580 val |= UTMIP_XCVR_SETUP_MSB(config->xcvr_setup); in utmi_phy_power_on()
582 val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew); in utmi_phy_power_on()
583 val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew); in utmi_phy_power_on()
585 if (phy->soc_config->requires_extra_tuning_parameters) { in utmi_phy_power_on()
587 val |= UTMIP_XCVR_HSSLEW(config->xcvr_hsslew); in utmi_phy_power_on()
588 val |= UTMIP_XCVR_HSSLEW_MSB(config->xcvr_hsslew); in utmi_phy_power_on()
595 val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj); in utmi_phy_power_on()
604 if (config->xcvr_setup_use_fuses) in utmi_phy_power_on()
610 if (!phy->is_legacy_phy) { in utmi_phy_power_on()
620 if (phy->is_legacy_phy) { in utmi_phy_power_on()
631 utmi_phy_clk_enable(phy); in utmi_phy_power_on()
633 if (phy->soc_config->requires_usbmode_setup) { in utmi_phy_power_on()
636 if (phy->mode == USB_DR_MODE_HOST) in utmi_phy_power_on()
643 if (!phy->is_legacy_phy) in utmi_phy_power_on()
644 set_pts(phy, 0); in utmi_phy_power_on()
649 static int utmi_phy_power_off(struct tegra_usb_phy *phy) in utmi_phy_power_off() argument
651 void __iomem *base = phy->regs; in utmi_phy_power_off()
656 * otherwise PHY will immediately wake up from suspend. in utmi_phy_power_off()
658 if (phy->wakeup_enabled && phy->mode != USB_DR_MODE_HOST) in utmi_phy_power_off()
663 utmi_phy_clk_disable(phy); in utmi_phy_power_off()
665 /* PHY won't resume if reset is asserted */ in utmi_phy_power_off()
666 if (!phy->wakeup_enabled) { in utmi_phy_power_off()
676 if (!phy->wakeup_enabled) { in utmi_phy_power_off()
688 if (phy->wakeup_enabled) { in utmi_phy_power_off()
696 * Ask VBUS sensor to generate wake event once cable is in utmi_phy_power_off()
699 if (phy->mode != USB_DR_MODE_HOST) { in utmi_phy_power_off()
711 return utmip_pad_power_off(phy); in utmi_phy_power_off()
714 static void utmi_phy_preresume(struct tegra_usb_phy *phy) in utmi_phy_preresume() argument
716 void __iomem *base = phy->regs; in utmi_phy_preresume()
724 static void utmi_phy_postresume(struct tegra_usb_phy *phy) in utmi_phy_postresume() argument
726 void __iomem *base = phy->regs; in utmi_phy_postresume()
734 static void utmi_phy_restore_start(struct tegra_usb_phy *phy, in utmi_phy_restore_start() argument
737 void __iomem *base = phy->regs; in utmi_phy_restore_start()
755 static void utmi_phy_restore_end(struct tegra_usb_phy *phy) in utmi_phy_restore_end() argument
757 void __iomem *base = phy->regs; in utmi_phy_restore_end()
766 static int ulpi_phy_power_on(struct tegra_usb_phy *phy) in ulpi_phy_power_on() argument
768 void __iomem *base = phy->regs; in ulpi_phy_power_on()
772 gpiod_set_value_cansleep(phy->reset_gpio, 1); in ulpi_phy_power_on()
774 err = clk_prepare_enable(phy->clk); in ulpi_phy_power_on()
780 gpiod_set_value_cansleep(phy->reset_gpio, 0); in ulpi_phy_power_on()
811 err = usb_phy_io_write(phy->ulpi, 0x40, 0x08); in ulpi_phy_power_on()
813 dev_err(phy->u_phy.dev, "ULPI write failed: %d\n", err); in ulpi_phy_power_on()
817 err = usb_phy_io_write(phy->ulpi, 0x80, 0x0B); in ulpi_phy_power_on()
819 dev_err(phy->u_phy.dev, "ULPI write failed: %d\n", err); in ulpi_phy_power_on()
835 clk_disable_unprepare(phy->clk); in ulpi_phy_power_on()
840 static int ulpi_phy_power_off(struct tegra_usb_phy *phy) in ulpi_phy_power_off() argument
842 gpiod_set_value_cansleep(phy->reset_gpio, 1); in ulpi_phy_power_off()
844 clk_disable_unprepare(phy->clk); in ulpi_phy_power_off()
847 * Wakeup currently unimplemented for ULPI, thus PHY needs to be in ulpi_phy_power_off()
848 * force-resumed. in ulpi_phy_power_off()
850 if (WARN_ON_ONCE(phy->wakeup_enabled)) { in ulpi_phy_power_off()
851 ulpi_phy_power_on(phy); in ulpi_phy_power_off()
852 return -EOPNOTSUPP; in ulpi_phy_power_off()
858 static int tegra_usb_phy_power_on(struct tegra_usb_phy *phy) in tegra_usb_phy_power_on() argument
862 if (phy->powered_on) in tegra_usb_phy_power_on()
865 if (phy->is_ulpi_phy) in tegra_usb_phy_power_on()
866 err = ulpi_phy_power_on(phy); in tegra_usb_phy_power_on()
868 err = utmi_phy_power_on(phy); in tegra_usb_phy_power_on()
872 phy->powered_on = true; in tegra_usb_phy_power_on()
874 /* Let PHY settle down */ in tegra_usb_phy_power_on()
880 static int tegra_usb_phy_power_off(struct tegra_usb_phy *phy) in tegra_usb_phy_power_off() argument
884 if (!phy->powered_on) in tegra_usb_phy_power_off()
887 if (phy->is_ulpi_phy) in tegra_usb_phy_power_off()
888 err = ulpi_phy_power_off(phy); in tegra_usb_phy_power_off()
890 err = utmi_phy_power_off(phy); in tegra_usb_phy_power_off()
894 phy->powered_on = false; in tegra_usb_phy_power_off()
901 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); in tegra_usb_phy_shutdown() local
903 if (WARN_ON(!phy->freq)) in tegra_usb_phy_shutdown()
907 tegra_usb_phy_power_off(phy); in tegra_usb_phy_shutdown()
909 if (!phy->is_ulpi_phy) in tegra_usb_phy_shutdown()
910 utmip_pad_close(phy); in tegra_usb_phy_shutdown()
912 regulator_disable(phy->vbus); in tegra_usb_phy_shutdown()
913 clk_disable_unprepare(phy->pll_u); in tegra_usb_phy_shutdown()
915 phy->freq = NULL; in tegra_usb_phy_shutdown()
921 struct tegra_usb_phy *phy = data; in tegra_usb_phy_isr() local
922 void __iomem *base = phy->regs; in tegra_usb_phy_isr()
925 * The PHY interrupt also wakes the USB controller driver since in tegra_usb_phy_isr()
926 * interrupt is shared. We don't do anything in the PHY driver, in tegra_usb_phy_isr()
937 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); in tegra_usb_phy_set_wakeup() local
938 void __iomem *base = phy->regs; in tegra_usb_phy_set_wakeup()
942 if (phy->wakeup_enabled && phy->mode != USB_DR_MODE_HOST && in tegra_usb_phy_set_wakeup()
943 phy->irq > 0) { in tegra_usb_phy_set_wakeup()
944 disable_irq(phy->irq); in tegra_usb_phy_set_wakeup()
950 enable_irq(phy->irq); in tegra_usb_phy_set_wakeup()
952 free_irq(phy->irq, phy); in tegra_usb_phy_set_wakeup()
954 phy->wakeup_enabled = false; in tegra_usb_phy_set_wakeup()
957 if (enable && phy->mode != USB_DR_MODE_HOST && phy->irq > 0) { in tegra_usb_phy_set_wakeup()
958 ret = request_irq(phy->irq, tegra_usb_phy_isr, IRQF_SHARED, in tegra_usb_phy_set_wakeup()
959 dev_name(phy->u_phy.dev), phy); in tegra_usb_phy_set_wakeup()
961 disable_irq(phy->irq); in tegra_usb_phy_set_wakeup()
964 * USB clock will be resumed once wake event will be in tegra_usb_phy_set_wakeup()
965 * generated. The ID-change event requires to have in tegra_usb_phy_set_wakeup()
972 enable_irq(phy->irq); in tegra_usb_phy_set_wakeup()
974 dev_err(phy->u_phy.dev, in tegra_usb_phy_set_wakeup()
980 phy->wakeup_enabled = enable; in tegra_usb_phy_set_wakeup()
987 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); in tegra_usb_phy_set_suspend() local
990 if (WARN_ON(!phy->freq)) in tegra_usb_phy_set_suspend()
991 return -EINVAL; in tegra_usb_phy_set_suspend()
994 * PHY is sharing IRQ with the CI driver, hence here we either in tegra_usb_phy_set_suspend()
995 * disable interrupt for both PHY and CI or for CI only. The in tegra_usb_phy_set_suspend()
1000 if (phy->irq > 0) in tegra_usb_phy_set_suspend()
1001 disable_irq(phy->irq); in tegra_usb_phy_set_suspend()
1004 ret = tegra_usb_phy_power_off(phy); in tegra_usb_phy_set_suspend()
1006 ret = tegra_usb_phy_power_on(phy); in tegra_usb_phy_set_suspend()
1008 if (phy->irq > 0) in tegra_usb_phy_set_suspend()
1009 enable_irq(phy->irq); in tegra_usb_phy_set_suspend()
1014 static int tegra_usb_phy_configure_pmc(struct tegra_usb_phy *phy) in tegra_usb_phy_configure_pmc() argument
1018 /* older device-trees don't have PMC regmap */ in tegra_usb_phy_configure_pmc()
1019 if (!phy->pmc_regmap) in tegra_usb_phy_configure_pmc()
1027 if (!phy->soc_config->requires_pmc_ao_power_up) in tegra_usb_phy_configure_pmc()
1030 /* enable VBUS wake-up detector */ in tegra_usb_phy_configure_pmc()
1031 if (phy->mode != USB_DR_MODE_HOST) in tegra_usb_phy_configure_pmc()
1032 val |= VBUS_WAKEUP_PD_P0 << phy->instance * 4; in tegra_usb_phy_configure_pmc()
1034 /* enable ID-pin ACC detector for OTG mode switching */ in tegra_usb_phy_configure_pmc()
1035 if (phy->mode == USB_DR_MODE_OTG) in tegra_usb_phy_configure_pmc()
1036 val |= ID_PD_P0 << phy->instance * 4; in tegra_usb_phy_configure_pmc()
1039 err = regmap_set_bits(phy->pmc_regmap, PMC_USB_AO, val); in tegra_usb_phy_configure_pmc()
1041 dev_err(phy->u_phy.dev, "Failed to disable PMC AO: %d\n", err); in tegra_usb_phy_configure_pmc()
1048 err = regmap_clear_bits(phy->pmc_regmap, PMC_USB_AO, val); in tegra_usb_phy_configure_pmc()
1050 dev_err(phy->u_phy.dev, "Failed to enable PMC AO: %d\n", err); in tegra_usb_phy_configure_pmc()
1062 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); in tegra_usb_phy_init() local
1067 if (WARN_ON(phy->freq)) in tegra_usb_phy_init()
1070 err = clk_prepare_enable(phy->pll_u); in tegra_usb_phy_init()
1074 parent_rate = clk_get_rate(clk_get_parent(phy->pll_u)); in tegra_usb_phy_init()
1075 for (i = 0; i < ARRAY_SIZE(tegra_freq_table); i++) { in tegra_usb_phy_init()
1077 phy->freq = &tegra_freq_table[i]; in tegra_usb_phy_init()
1081 if (!phy->freq) { in tegra_usb_phy_init()
1082 dev_err(phy->u_phy.dev, "Invalid pll_u parent rate %ld\n", in tegra_usb_phy_init()
1084 err = -EINVAL; in tegra_usb_phy_init()
1088 err = regulator_enable(phy->vbus); in tegra_usb_phy_init()
1090 dev_err(phy->u_phy.dev, in tegra_usb_phy_init()
1095 if (!phy->is_ulpi_phy) { in tegra_usb_phy_init()
1096 err = utmip_pad_open(phy); in tegra_usb_phy_init()
1101 err = tegra_usb_phy_configure_pmc(phy); in tegra_usb_phy_init()
1105 err = tegra_usb_phy_power_on(phy); in tegra_usb_phy_init()
1112 if (!phy->is_ulpi_phy) in tegra_usb_phy_init()
1113 utmip_pad_close(phy); in tegra_usb_phy_init()
1116 regulator_disable(phy->vbus); in tegra_usb_phy_init()
1119 clk_disable_unprepare(phy->pll_u); in tegra_usb_phy_init()
1121 phy->freq = NULL; in tegra_usb_phy_init()
1128 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); in tegra_usb_phy_preresume() local
1130 if (!phy->is_ulpi_phy) in tegra_usb_phy_preresume()
1131 utmi_phy_preresume(phy); in tegra_usb_phy_preresume()
1137 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); in tegra_usb_phy_postresume() local
1139 if (!phy->is_ulpi_phy) in tegra_usb_phy_postresume()
1140 utmi_phy_postresume(phy); in tegra_usb_phy_postresume()
1147 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); in tegra_ehci_phy_restore_start() local
1149 if (!phy->is_ulpi_phy) in tegra_ehci_phy_restore_start()
1150 utmi_phy_restore_start(phy, port_speed); in tegra_ehci_phy_restore_start()
1156 struct tegra_usb_phy *phy = to_tegra_usb_phy(u_phy); in tegra_ehci_phy_restore_end() local
1158 if (!phy->is_ulpi_phy) in tegra_ehci_phy_restore_end()
1159 utmi_phy_restore_end(phy); in tegra_ehci_phy_restore_end()
1169 err = of_property_read_u32(pdev->dev.of_node, param, &value); in read_utmi_param()
1171 dev_err(&pdev->dev, in read_utmi_param()
1187 tegra_phy->is_ulpi_phy = false; in utmi_phy_probe()
1191 dev_err(&pdev->dev, "Failed to get UTMI pad regs\n"); in utmi_phy_probe()
1192 return -ENXIO; in utmi_phy_probe()
1199 tegra_phy->pad_regs = devm_ioremap(&pdev->dev, res->start, in utmi_phy_probe()
1201 if (!tegra_phy->pad_regs) { in utmi_phy_probe()
1202 dev_err(&pdev->dev, "Failed to remap UTMI pad regs\n"); in utmi_phy_probe()
1203 return -ENOMEM; in utmi_phy_probe()
1206 tegra_phy->config = devm_kzalloc(&pdev->dev, sizeof(*config), in utmi_phy_probe()
1208 if (!tegra_phy->config) in utmi_phy_probe()
1209 return -ENOMEM; in utmi_phy_probe()
1211 config = tegra_phy->config; in utmi_phy_probe()
1213 err = read_utmi_param(pdev, "nvidia,hssync-start-delay", in utmi_phy_probe()
1214 &config->hssync_start_delay); in utmi_phy_probe()
1218 err = read_utmi_param(pdev, "nvidia,elastic-limit", in utmi_phy_probe()
1219 &config->elastic_limit); in utmi_phy_probe()
1223 err = read_utmi_param(pdev, "nvidia,idle-wait-delay", in utmi_phy_probe()
1224 &config->idle_wait_delay); in utmi_phy_probe()
1228 err = read_utmi_param(pdev, "nvidia,term-range-adj", in utmi_phy_probe()
1229 &config->term_range_adj); in utmi_phy_probe()
1233 err = read_utmi_param(pdev, "nvidia,xcvr-lsfslew", in utmi_phy_probe()
1234 &config->xcvr_lsfslew); in utmi_phy_probe()
1238 err = read_utmi_param(pdev, "nvidia,xcvr-lsrslew", in utmi_phy_probe()
1239 &config->xcvr_lsrslew); in utmi_phy_probe()
1243 if (tegra_phy->soc_config->requires_extra_tuning_parameters) { in utmi_phy_probe()
1244 err = read_utmi_param(pdev, "nvidia,xcvr-hsslew", in utmi_phy_probe()
1245 &config->xcvr_hsslew); in utmi_phy_probe()
1249 err = read_utmi_param(pdev, "nvidia,hssquelch-level", in utmi_phy_probe()
1250 &config->hssquelch_level); in utmi_phy_probe()
1254 err = read_utmi_param(pdev, "nvidia,hsdiscon-level", in utmi_phy_probe()
1255 &config->hsdiscon_level); in utmi_phy_probe()
1260 config->xcvr_setup_use_fuses = of_property_read_bool( in utmi_phy_probe()
1261 pdev->dev.of_node, "nvidia,xcvr-setup-use-fuses"); in utmi_phy_probe()
1263 if (!config->xcvr_setup_use_fuses) { in utmi_phy_probe()
1264 err = read_utmi_param(pdev, "nvidia,xcvr-setup", in utmi_phy_probe()
1265 &config->xcvr_setup); in utmi_phy_probe()
1279 struct tegra_usb_phy *phy) in tegra_usb_phy_parse_pmc() argument
1285 err = of_parse_phandle_with_fixed_args(dev->of_node, "nvidia,pmc", in tegra_usb_phy_parse_pmc()
1288 if (err != -ENOENT) in tegra_usb_phy_parse_pmc()
1291 dev_warn_once(dev, "nvidia,pmc is missing, please update your device-tree\n"); in tegra_usb_phy_parse_pmc()
1298 return -ENODEV; in tegra_usb_phy_parse_pmc()
1301 &pmc_pdev->dev); in tegra_usb_phy_parse_pmc()
1306 return -EPROBE_DEFER; in tegra_usb_phy_parse_pmc()
1308 phy->pmc_regmap = dev_get_regmap(&pmc_pdev->dev, "usb_sleepwalk"); in tegra_usb_phy_parse_pmc()
1309 if (!phy->pmc_regmap) in tegra_usb_phy_parse_pmc()
1310 return -EINVAL; in tegra_usb_phy_parse_pmc()
1312 phy->instance = args.args[0]; in tegra_usb_phy_parse_pmc()
1334 { .compatible = "nvidia,tegra30-usb-phy", .data = &tegra30_soc_config },
1335 { .compatible = "nvidia,tegra20-usb-phy", .data = &tegra20_soc_config },
1342 struct device_node *np = pdev->dev.of_node; in tegra_usb_phy_probe()
1348 struct usb_phy *phy; in tegra_usb_phy_probe() local
1351 tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL); in tegra_usb_phy_probe()
1353 return -ENOMEM; in tegra_usb_phy_probe()
1355 tegra_phy->soc_config = of_device_get_match_data(&pdev->dev); in tegra_usb_phy_probe()
1356 tegra_phy->irq = platform_get_irq_optional(pdev, 0); in tegra_usb_phy_probe()
1360 dev_err(&pdev->dev, "Failed to get I/O memory\n"); in tegra_usb_phy_probe()
1361 return -ENXIO; in tegra_usb_phy_probe()
1365 * Note that PHY and USB controller are using shared registers, in tegra_usb_phy_probe()
1368 tegra_phy->regs = devm_ioremap(&pdev->dev, res->start, in tegra_usb_phy_probe()
1370 if (!tegra_phy->regs) { in tegra_usb_phy_probe()
1371 dev_err(&pdev->dev, "Failed to remap I/O memory\n"); in tegra_usb_phy_probe()
1372 return -ENOMEM; in tegra_usb_phy_probe()
1375 tegra_phy->is_legacy_phy = in tegra_usb_phy_probe()
1376 of_property_read_bool(np, "nvidia,has-legacy-mode"); in tegra_usb_phy_probe()
1379 tegra_phy->mode = usb_get_dr_mode(&pdev->dev); in tegra_usb_phy_probe()
1381 tegra_phy->mode = USB_DR_MODE_HOST; in tegra_usb_phy_probe()
1383 if (tegra_phy->mode == USB_DR_MODE_UNKNOWN) { in tegra_usb_phy_probe()
1384 dev_err(&pdev->dev, "dr_mode is invalid\n"); in tegra_usb_phy_probe()
1385 return -EINVAL; in tegra_usb_phy_probe()
1388 /* On some boards, the VBUS regulator doesn't need to be controlled */ in tegra_usb_phy_probe()
1389 tegra_phy->vbus = devm_regulator_get(&pdev->dev, "vbus"); in tegra_usb_phy_probe()
1390 if (IS_ERR(tegra_phy->vbus)) in tegra_usb_phy_probe()
1391 return PTR_ERR(tegra_phy->vbus); in tegra_usb_phy_probe()
1393 tegra_phy->pll_u = devm_clk_get(&pdev->dev, "pll_u"); in tegra_usb_phy_probe()
1394 err = PTR_ERR_OR_ZERO(tegra_phy->pll_u); in tegra_usb_phy_probe()
1396 dev_err(&pdev->dev, "Failed to get pll_u clock: %d\n", err); in tegra_usb_phy_probe()
1400 err = tegra_usb_phy_parse_pmc(&pdev->dev, tegra_phy); in tegra_usb_phy_probe()
1402 dev_err_probe(&pdev->dev, err, "Failed to get PMC regmap\n"); in tegra_usb_phy_probe()
1413 tegra_phy->pad_clk = devm_clk_get(&pdev->dev, "utmi-pads"); in tegra_usb_phy_probe()
1414 err = PTR_ERR_OR_ZERO(tegra_phy->pad_clk); in tegra_usb_phy_probe()
1416 dev_err(&pdev->dev, in tegra_usb_phy_probe()
1421 reset = devm_reset_control_get_optional_shared(&pdev->dev, in tegra_usb_phy_probe()
1422 "utmi-pads"); in tegra_usb_phy_probe()
1425 dev_err(&pdev->dev, in tegra_usb_phy_probe()
1426 "Failed to get UTMI-pads reset: %d\n", err); in tegra_usb_phy_probe()
1429 tegra_phy->pad_rst = reset; in tegra_usb_phy_probe()
1433 tegra_phy->is_ulpi_phy = true; in tegra_usb_phy_probe()
1435 tegra_phy->clk = devm_clk_get(&pdev->dev, "ulpi-link"); in tegra_usb_phy_probe()
1436 err = PTR_ERR_OR_ZERO(tegra_phy->clk); in tegra_usb_phy_probe()
1438 dev_err(&pdev->dev, in tegra_usb_phy_probe()
1443 gpiod = devm_gpiod_get(&pdev->dev, "nvidia,phy-reset", in tegra_usb_phy_probe()
1447 dev_err(&pdev->dev, in tegra_usb_phy_probe()
1448 "Request failed for reset GPIO: %d\n", err); in tegra_usb_phy_probe()
1454 dev_err(&pdev->dev, in tegra_usb_phy_probe()
1459 tegra_phy->reset_gpio = gpiod; in tegra_usb_phy_probe()
1461 phy = devm_otg_ulpi_create(&pdev->dev, in tegra_usb_phy_probe()
1463 if (!phy) { in tegra_usb_phy_probe()
1464 dev_err(&pdev->dev, "Failed to create ULPI OTG\n"); in tegra_usb_phy_probe()
1465 return -ENOMEM; in tegra_usb_phy_probe()
1468 tegra_phy->ulpi = phy; in tegra_usb_phy_probe()
1469 tegra_phy->ulpi->io_priv = tegra_phy->regs + ULPI_VIEWPORT; in tegra_usb_phy_probe()
1473 dev_err(&pdev->dev, "phy_type %u is invalid or unsupported\n", in tegra_usb_phy_probe()
1475 return -EINVAL; in tegra_usb_phy_probe()
1478 tegra_phy->u_phy.dev = &pdev->dev; in tegra_usb_phy_probe()
1479 tegra_phy->u_phy.init = tegra_usb_phy_init; in tegra_usb_phy_probe()
1480 tegra_phy->u_phy.shutdown = tegra_usb_phy_shutdown; in tegra_usb_phy_probe()
1481 tegra_phy->u_phy.set_wakeup = tegra_usb_phy_set_wakeup; in tegra_usb_phy_probe()
1482 tegra_phy->u_phy.set_suspend = tegra_usb_phy_set_suspend; in tegra_usb_phy_probe()
1486 return usb_add_phy_dev(&tegra_phy->u_phy); in tegra_usb_phy_probe()
1493 usb_remove_phy(&tegra_phy->u_phy); in tegra_usb_phy_remove()
1500 .name = "tegra-phy",
1506 MODULE_DESCRIPTION("Tegra USB PHY driver");