Lines Matching +full:phy +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (C) 2010-2013 ST-Ericsson AB
22 #include <linux/usb/musb-ux500.h>
121 /* Driver is using the ab-iddet driver*/
127 struct usb_phy phy; member
132 enum ab8500_usb_mode mode; member
147 return container_of(x, struct ab8500_usb, phy); in phy_to_ab()
152 abx500_set_register_interruptible(ab->dev, in ab8500_usb_wd_workaround()
159 abx500_set_register_interruptible(ab->dev, in ab8500_usb_wd_workaround()
167 abx500_set_register_interruptible(ab->dev, in ab8500_usb_wd_workaround()
177 ret = regulator_enable(ab->v_ape); in ab8500_usb_regulator_enable()
179 dev_err(ab->dev, "Failed to enable v-ape\n"); in ab8500_usb_regulator_enable()
181 if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) { in ab8500_usb_regulator_enable()
182 ab->saved_v_ulpi = regulator_get_voltage(ab->v_ulpi); in ab8500_usb_regulator_enable()
183 if (ab->saved_v_ulpi < 0) in ab8500_usb_regulator_enable()
184 dev_err(ab->dev, "Failed to get v_ulpi voltage\n"); in ab8500_usb_regulator_enable()
186 ret = regulator_set_voltage(ab->v_ulpi, 1300000, 1350000); in ab8500_usb_regulator_enable()
188 dev_err(ab->dev, "Failed to set the Vintcore to 1.3V, ret=%d\n", in ab8500_usb_regulator_enable()
191 ret = regulator_set_load(ab->v_ulpi, 28000); in ab8500_usb_regulator_enable()
193 dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n", in ab8500_usb_regulator_enable()
197 ret = regulator_enable(ab->v_ulpi); in ab8500_usb_regulator_enable()
199 dev_err(ab->dev, "Failed to enable vddulpivio18\n"); in ab8500_usb_regulator_enable()
201 if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) { in ab8500_usb_regulator_enable()
202 volt = regulator_get_voltage(ab->v_ulpi); in ab8500_usb_regulator_enable()
204 dev_err(ab->dev, "Vintcore is not set to 1.3V volt=%d\n", in ab8500_usb_regulator_enable()
208 ret = regulator_enable(ab->v_musb); in ab8500_usb_regulator_enable()
210 dev_err(ab->dev, "Failed to enable musb_1v8\n"); in ab8500_usb_regulator_enable()
217 regulator_disable(ab->v_musb); in ab8500_usb_regulator_disable()
219 regulator_disable(ab->v_ulpi); in ab8500_usb_regulator_disable()
222 if (ab->flags & AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE) { in ab8500_usb_regulator_disable()
223 if (ab->saved_v_ulpi > 0) { in ab8500_usb_regulator_disable()
224 ret = regulator_set_voltage(ab->v_ulpi, in ab8500_usb_regulator_disable()
225 ab->saved_v_ulpi, ab->saved_v_ulpi); in ab8500_usb_regulator_disable()
227 dev_err(ab->dev, "Failed to set the Vintcore to %duV, ret=%d\n", in ab8500_usb_regulator_disable()
228 ab->saved_v_ulpi, ret); in ab8500_usb_regulator_disable()
231 ret = regulator_set_load(ab->v_ulpi, 0); in ab8500_usb_regulator_disable()
233 dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n", in ab8500_usb_regulator_disable()
237 regulator_disable(ab->v_ape); in ab8500_usb_regulator_disable()
243 if (is_ab8500_2p0(ab->ab8500)) { in ab8500_usb_wd_linkstatus()
244 abx500_mask_and_set_register_interruptible(ab->dev, in ab8500_usb_wd_linkstatus()
258 ab->pinctrl = pinctrl_get_select(ab->dev, PINCTRL_STATE_DEFAULT); in ab8500_usb_phy_enable()
259 if (IS_ERR(ab->pinctrl)) in ab8500_usb_phy_enable()
260 dev_err(ab->dev, "could not get/set default pinstate\n"); in ab8500_usb_phy_enable()
262 if (clk_prepare_enable(ab->sysclk)) in ab8500_usb_phy_enable()
263 dev_err(ab->dev, "can't prepare/enable clock\n"); in ab8500_usb_phy_enable()
267 abx500_mask_and_set_register_interruptible(ab->dev, in ab8500_usb_phy_enable()
280 abx500_mask_and_set_register_interruptible(ab->dev, in ab8500_usb_phy_disable()
284 /* Needed to disable the phy.*/ in ab8500_usb_phy_disable()
287 clk_disable_unprepare(ab->sysclk); in ab8500_usb_phy_disable()
291 if (!IS_ERR(ab->pinctrl)) { in ab8500_usb_phy_disable()
293 ab->pins_sleep = pinctrl_lookup_state(ab->pinctrl, in ab8500_usb_phy_disable()
296 if (IS_ERR(ab->pins_sleep)) in ab8500_usb_phy_disable()
297 dev_dbg(ab->dev, "could not get sleep pinstate\n"); in ab8500_usb_phy_disable()
298 else if (pinctrl_select_state(ab->pinctrl, ab->pins_sleep)) in ab8500_usb_phy_disable()
299 dev_err(ab->dev, "could not set pins to sleep state\n"); in ab8500_usb_phy_disable()
305 pinctrl_put(ab->pinctrl); in ab8500_usb_phy_disable()
319 dev_dbg(ab->dev, "ab8505_usb_link_status_update %d\n", lsts); in ab8505_usb_link_status_update()
325 if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8505 && in ab8505_usb_link_status_update()
329 ab->previous_link_status_state = lsts; in ab8505_usb_link_status_update()
340 ab->mode = USB_IDLE; in ab8505_usb_link_status_update()
341 ab->phy.otg->default_a = false; in ab8505_usb_link_status_update()
342 ab->vbus_draw = 0; in ab8505_usb_link_status_update()
349 ab->phy.otg->state = OTG_STATE_B_IDLE; in ab8505_usb_link_status_update()
350 usb_phy_set_event(&ab->phy, USB_EVENT_NONE); in ab8505_usb_link_status_update()
360 if (ab->mode == USB_IDLE) { in ab8505_usb_link_status_update()
361 ab->mode = USB_PERIPHERAL; in ab8505_usb_link_status_update()
363 atomic_notifier_call_chain(&ab->phy.notifier, in ab8505_usb_link_status_update()
364 UX500_MUSB_PREPARE, &ab->vbus_draw); in ab8505_usb_link_status_update()
365 usb_phy_set_event(&ab->phy, USB_EVENT_ENUMERATED); in ab8505_usb_link_status_update()
376 if (ab->mode == USB_IDLE) { in ab8505_usb_link_status_update()
377 ab->mode = USB_HOST; in ab8505_usb_link_status_update()
379 atomic_notifier_call_chain(&ab->phy.notifier, in ab8505_usb_link_status_update()
380 UX500_MUSB_PREPARE, &ab->vbus_draw); in ab8505_usb_link_status_update()
382 ab->phy.otg->default_a = true; in ab8505_usb_link_status_update()
385 atomic_notifier_call_chain(&ab->phy.notifier, in ab8505_usb_link_status_update()
386 event, &ab->vbus_draw); in ab8505_usb_link_status_update()
390 ab->mode = USB_DEDICATED_CHG; in ab8505_usb_link_status_update()
392 atomic_notifier_call_chain(&ab->phy.notifier, in ab8505_usb_link_status_update()
393 event, &ab->vbus_draw); in ab8505_usb_link_status_update()
394 usb_phy_set_event(&ab->phy, USB_EVENT_CHARGER); in ab8505_usb_link_status_update()
399 * PHY/pin configuration for UART mode. in ab8505_usb_link_status_update()
408 if (ab->mode == USB_IDLE) { in ab8505_usb_link_status_update()
409 ab->mode = USB_UART; in ab8505_usb_link_status_update()
427 dev_dbg(ab->dev, "ab8500_usb_link_status_update %d\n", lsts); in ab8500_usb_link_status_update()
433 if (ab->previous_link_status_state == USB_LINK_HM_IDGND_8500 && in ab8500_usb_link_status_update()
438 if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8500 && in ab8500_usb_link_status_update()
442 ab->previous_link_status_state = lsts; in ab8500_usb_link_status_update()
450 ab->mode = USB_IDLE; in ab8500_usb_link_status_update()
451 ab->phy.otg->default_a = false; in ab8500_usb_link_status_update()
452 ab->vbus_draw = 0; in ab8500_usb_link_status_update()
456 ab->phy.otg->state = OTG_STATE_B_IDLE; in ab8500_usb_link_status_update()
457 usb_phy_set_event(&ab->phy, USB_EVENT_NONE); in ab8500_usb_link_status_update()
471 if (ab->mode == USB_IDLE) { in ab8500_usb_link_status_update()
472 ab->mode = USB_PERIPHERAL; in ab8500_usb_link_status_update()
474 atomic_notifier_call_chain(&ab->phy.notifier, in ab8500_usb_link_status_update()
475 UX500_MUSB_PREPARE, &ab->vbus_draw); in ab8500_usb_link_status_update()
476 usb_phy_set_event(&ab->phy, USB_EVENT_ENUMERATED); in ab8500_usb_link_status_update()
486 if (ab->mode == USB_IDLE) { in ab8500_usb_link_status_update()
487 ab->mode = USB_HOST; in ab8500_usb_link_status_update()
489 atomic_notifier_call_chain(&ab->phy.notifier, in ab8500_usb_link_status_update()
490 UX500_MUSB_PREPARE, &ab->vbus_draw); in ab8500_usb_link_status_update()
492 ab->phy.otg->default_a = true; in ab8500_usb_link_status_update()
495 atomic_notifier_call_chain(&ab->phy.notifier, in ab8500_usb_link_status_update()
496 event, &ab->vbus_draw); in ab8500_usb_link_status_update()
500 ab->mode = USB_DEDICATED_CHG; in ab8500_usb_link_status_update()
502 atomic_notifier_call_chain(&ab->phy.notifier, in ab8500_usb_link_status_update()
503 event, &ab->vbus_draw); in ab8500_usb_link_status_update()
504 usb_phy_set_event(&ab->phy, USB_EVENT_CHARGER); in ab8500_usb_link_status_update()
519 * 4. Enable USB phy
521 * 6. Switch the ULPI GPIO pins to function mode
530 if (is_ab8500(ab->ab8500)) { in abx500_usb_link_status_update()
533 ret = abx500_get_register_interruptible(ab->dev, in abx500_usb_link_status_update()
539 } else if (is_ab8505(ab->ab8500)) { in abx500_usb_link_status_update()
542 ret = abx500_get_register_interruptible(ab->dev, in abx500_usb_link_status_update()
558 * 4. Disable the Phy
567 /* Link status will not be updated till phy is disabled. */ in ab8500_usb_disconnect_irq()
568 if (ab->mode == USB_HOST) { in ab8500_usb_disconnect_irq()
569 ab->phy.otg->default_a = false; in ab8500_usb_disconnect_irq()
570 ab->vbus_draw = 0; in ab8500_usb_disconnect_irq()
571 atomic_notifier_call_chain(&ab->phy.notifier, in ab8500_usb_disconnect_irq()
572 event, &ab->vbus_draw); in ab8500_usb_disconnect_irq()
574 ab->mode = USB_IDLE; in ab8500_usb_disconnect_irq()
577 if (ab->mode == USB_PERIPHERAL) { in ab8500_usb_disconnect_irq()
578 atomic_notifier_call_chain(&ab->phy.notifier, in ab8500_usb_disconnect_irq()
579 event, &ab->vbus_draw); in ab8500_usb_disconnect_irq()
581 atomic_notifier_call_chain(&ab->phy.notifier, in ab8500_usb_disconnect_irq()
582 UX500_MUSB_CLEAN, &ab->vbus_draw); in ab8500_usb_disconnect_irq()
583 ab->mode = USB_IDLE; in ab8500_usb_disconnect_irq()
584 ab->phy.otg->default_a = false; in ab8500_usb_disconnect_irq()
585 ab->vbus_draw = 0; in ab8500_usb_disconnect_irq()
588 if (ab->mode == USB_UART) { in ab8500_usb_disconnect_irq()
590 ab->mode = USB_IDLE; in ab8500_usb_disconnect_irq()
593 if (is_ab8500_2p0(ab->ab8500)) { in ab8500_usb_disconnect_irq()
594 if (ab->mode == USB_DEDICATED_CHG) { in ab8500_usb_disconnect_irq()
597 abx500_mask_and_set_register_interruptible(ab->dev, in ab8500_usb_disconnect_irq()
620 if (!ab->phy.otg->host) in ab8500_usb_phy_disable_work()
623 if (!ab->phy.otg->gadget) in ab8500_usb_phy_disable_work()
639 return -ENODEV; in ab8500_usb_set_peripheral()
641 ab = phy_to_ab(otg->usb_phy); in ab8500_usb_set_peripheral()
643 ab->phy.otg->gadget = gadget; in ab8500_usb_set_peripheral()
650 if ((ab->mode != USB_IDLE) && !gadget) { in ab8500_usb_set_peripheral()
651 ab->mode = USB_IDLE; in ab8500_usb_set_peripheral()
652 schedule_work(&ab->phy_dis_work); in ab8500_usb_set_peripheral()
663 return -ENODEV; in ab8500_usb_set_host()
665 ab = phy_to_ab(otg->usb_phy); in ab8500_usb_set_host()
667 ab->phy.otg->host = host; in ab8500_usb_set_host()
674 if ((ab->mode != USB_IDLE) && !host) { in ab8500_usb_set_host()
675 ab->mode = USB_IDLE; in ab8500_usb_set_host()
676 schedule_work(&ab->phy_dis_work); in ab8500_usb_set_host()
684 abx500_mask_and_set_register_interruptible(ab->dev, in ab8500_usb_restart_phy()
691 abx500_mask_and_set_register_interruptible(ab->dev, in ab8500_usb_restart_phy()
696 abx500_mask_and_set_register_interruptible(ab->dev, in ab8500_usb_restart_phy()
703 abx500_mask_and_set_register_interruptible(ab->dev, in ab8500_usb_restart_phy()
713 ab->v_ape = devm_regulator_get(ab->dev, "v-ape"); in ab8500_usb_regulator_get()
714 if (IS_ERR(ab->v_ape)) { in ab8500_usb_regulator_get()
715 dev_err(ab->dev, "Could not get v-ape supply\n"); in ab8500_usb_regulator_get()
716 err = PTR_ERR(ab->v_ape); in ab8500_usb_regulator_get()
720 ab->v_ulpi = devm_regulator_get(ab->dev, "vddulpivio18"); in ab8500_usb_regulator_get()
721 if (IS_ERR(ab->v_ulpi)) { in ab8500_usb_regulator_get()
722 dev_err(ab->dev, "Could not get vddulpivio18 supply\n"); in ab8500_usb_regulator_get()
723 err = PTR_ERR(ab->v_ulpi); in ab8500_usb_regulator_get()
727 ab->v_musb = devm_regulator_get(ab->dev, "musb_1v8"); in ab8500_usb_regulator_get()
728 if (IS_ERR(ab->v_musb)) { in ab8500_usb_regulator_get()
729 dev_err(ab->dev, "Could not get musb_1v8 supply\n"); in ab8500_usb_regulator_get()
730 err = PTR_ERR(ab->v_musb); in ab8500_usb_regulator_get()
743 if (ab->flags & AB8500_USB_FLAG_USE_LINK_STATUS_IRQ) { in ab8500_usb_irq_setup()
747 err = devm_request_threaded_irq(&pdev->dev, irq, NULL, in ab8500_usb_irq_setup()
750 "usb-link-status", ab); in ab8500_usb_irq_setup()
752 dev_err(ab->dev, "request_irq failed for link status irq\n"); in ab8500_usb_irq_setup()
757 if (ab->flags & AB8500_USB_FLAG_USE_ID_WAKEUP_IRQ) { in ab8500_usb_irq_setup()
761 err = devm_request_threaded_irq(&pdev->dev, irq, NULL, in ab8500_usb_irq_setup()
764 "usb-id-fall", ab); in ab8500_usb_irq_setup()
766 dev_err(ab->dev, "request_irq failed for ID fall irq\n"); in ab8500_usb_irq_setup()
771 if (ab->flags & AB8500_USB_FLAG_USE_VBUS_DET_IRQ) { in ab8500_usb_irq_setup()
775 err = devm_request_threaded_irq(&pdev->dev, irq, NULL, in ab8500_usb_irq_setup()
778 "usb-vbus-fall", ab); in ab8500_usb_irq_setup()
780 dev_err(ab->dev, "request_irq failed for Vbus fall irq\n"); in ab8500_usb_irq_setup()
793 err = abx500_set_register_interruptible(ab->dev, in ab8500_usb_set_ab8500_tuning_values()
796 dev_err(ab->dev, "Failed to enable bank12 access err=%d\n", in ab8500_usb_set_ab8500_tuning_values()
799 err = abx500_set_register_interruptible(ab->dev, in ab8500_usb_set_ab8500_tuning_values()
802 dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n", in ab8500_usb_set_ab8500_tuning_values()
805 err = abx500_set_register_interruptible(ab->dev, in ab8500_usb_set_ab8500_tuning_values()
808 dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n", in ab8500_usb_set_ab8500_tuning_values()
811 err = abx500_set_register_interruptible(ab->dev, in ab8500_usb_set_ab8500_tuning_values()
814 dev_err(ab->dev, "Failed to set PHY_TUNE3 register err=%d\n", in ab8500_usb_set_ab8500_tuning_values()
817 /* Switch to normal mode/disable Bank 0x12 access */ in ab8500_usb_set_ab8500_tuning_values()
818 err = abx500_set_register_interruptible(ab->dev, in ab8500_usb_set_ab8500_tuning_values()
821 dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", in ab8500_usb_set_ab8500_tuning_values()
830 err = abx500_mask_and_set_register_interruptible(ab->dev, in ab8500_usb_set_ab8505_tuning_values()
834 dev_err(ab->dev, "Failed to enable bank12 access err=%d\n", in ab8500_usb_set_ab8505_tuning_values()
837 err = abx500_mask_and_set_register_interruptible(ab->dev, in ab8500_usb_set_ab8505_tuning_values()
841 dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n", in ab8500_usb_set_ab8505_tuning_values()
844 err = abx500_mask_and_set_register_interruptible(ab->dev, in ab8500_usb_set_ab8505_tuning_values()
848 dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n", in ab8500_usb_set_ab8505_tuning_values()
851 err = abx500_mask_and_set_register_interruptible(ab->dev, in ab8500_usb_set_ab8505_tuning_values()
856 dev_err(ab->dev, "Failed to set PHY_TUNE3 register err=%d\n", in ab8500_usb_set_ab8505_tuning_values()
859 /* Switch to normal mode/disable Bank 0x12 access */ in ab8500_usb_set_ab8505_tuning_values()
860 err = abx500_mask_and_set_register_interruptible(ab->dev, in ab8500_usb_set_ab8505_tuning_values()
864 dev_err(ab->dev, "Failed to switch bank12 access err=%d\n", in ab8500_usb_set_ab8505_tuning_values()
876 ab8500 = dev_get_drvdata(pdev->dev.parent); in ab8500_usb_probe()
877 rev = abx500_get_chip_id(&pdev->dev); in ab8500_usb_probe()
880 dev_err(&pdev->dev, "Unsupported AB8500 chip rev=%d\n", rev); in ab8500_usb_probe()
881 return -ENODEV; in ab8500_usb_probe()
884 ab = devm_kzalloc(&pdev->dev, sizeof(*ab), GFP_KERNEL); in ab8500_usb_probe()
886 return -ENOMEM; in ab8500_usb_probe()
888 otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); in ab8500_usb_probe()
890 return -ENOMEM; in ab8500_usb_probe()
892 ab->dev = &pdev->dev; in ab8500_usb_probe()
893 ab->ab8500 = ab8500; in ab8500_usb_probe()
894 ab->phy.dev = ab->dev; in ab8500_usb_probe()
895 ab->phy.otg = otg; in ab8500_usb_probe()
896 ab->phy.label = "ab8500"; in ab8500_usb_probe()
897 ab->phy.set_suspend = ab8500_usb_set_suspend; in ab8500_usb_probe()
898 ab->phy.otg->state = OTG_STATE_UNDEFINED; in ab8500_usb_probe()
900 otg->usb_phy = &ab->phy; in ab8500_usb_probe()
901 otg->set_host = ab8500_usb_set_host; in ab8500_usb_probe()
902 otg->set_peripheral = ab8500_usb_set_peripheral; in ab8500_usb_probe()
904 if (is_ab8500(ab->ab8500)) { in ab8500_usb_probe()
905 ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ | in ab8500_usb_probe()
909 } else if (is_ab8505(ab->ab8500)) { in ab8500_usb_probe()
910 ab->flags |= AB8500_USB_FLAG_USE_LINK_STATUS_IRQ | in ab8500_usb_probe()
917 if (is_ab8500_2p0_or_earlier(ab->ab8500)) in ab8500_usb_probe()
918 ab->flags &= ~AB8500_USB_FLAG_REGULATOR_SET_VOLTAGE; in ab8500_usb_probe()
922 /* all: Disable phy when called from set_host and set_peripheral */ in ab8500_usb_probe()
923 INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work); in ab8500_usb_probe()
929 ab->sysclk = devm_clk_get(ab->dev, "sysclk"); in ab8500_usb_probe()
930 if (IS_ERR(ab->sysclk)) { in ab8500_usb_probe()
931 dev_err(ab->dev, "Could not get sysclk.\n"); in ab8500_usb_probe()
932 return PTR_ERR(ab->sysclk); in ab8500_usb_probe()
939 err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2); in ab8500_usb_probe()
941 dev_err(&pdev->dev, "Can't register transceiver\n"); in ab8500_usb_probe()
945 if (is_ab8500(ab->ab8500) && !is_ab8500_2p0_or_earlier(ab->ab8500)) in ab8500_usb_probe()
946 /* Phy tuning values for AB8500 > v2.0 */ in ab8500_usb_probe()
948 else if (is_ab8505(ab->ab8500)) in ab8500_usb_probe()
949 /* Phy tuning values for AB8505 */ in ab8500_usb_probe()
956 * This is required for usb-link-status to work properly when a in ab8500_usb_probe()
963 dev_info(&pdev->dev, "revision 0x%2x driver initialized\n", rev); in ab8500_usb_probe()
972 cancel_work_sync(&ab->phy_dis_work); in ab8500_usb_remove()
974 usb_remove_phy(&ab->phy); in ab8500_usb_remove()
976 if (ab->mode == USB_HOST) in ab8500_usb_remove()
978 else if (ab->mode == USB_PERIPHERAL) in ab8500_usb_remove()
985 { .name = "ab8500-usb", },
995 .name = "abx5x0-usb",
1011 MODULE_AUTHOR("ST-Ericsson AB");