Lines Matching full:usb3
3 * Renesas USB3.0 Peripheral driver (USB gadget)
312 struct renesas_usb3 *usb3; member
374 #define usb3_ep_to_usb3(_usb3_ep) (_usb3_ep->usb3)
378 #define usb3_get_ep(usb3, n) ((usb3)->usb3_ep + (n)) argument
379 #define usb3_for_each_ep(usb3_ep, usb3, i) \ argument
380 for ((i) = 0, usb3_ep = usb3_get_ep(usb3, (i)); \
381 (i) < (usb3)->num_usb3_eps; \
382 (i)++, usb3_ep = usb3_get_ep(usb3, (i)))
384 #define usb3_get_dma(usb3, i) (&(usb3)->dma[i]) argument
385 #define usb3_for_each_dma(usb3, dma, i) \ argument
386 for ((i) = 0, dma = usb3_get_dma((usb3), (i)); \
388 (i)++, dma = usb3_get_dma((usb3), (i)))
396 static void usb3_write(struct renesas_usb3 *usb3, u32 data, u32 offs) in usb3_write() argument
398 iowrite32(data, usb3->reg + offs); in usb3_write()
401 static u32 usb3_read(struct renesas_usb3 *usb3, u32 offs) in usb3_read() argument
403 return ioread32(usb3->reg + offs); in usb3_read()
406 static void usb3_set_bit(struct renesas_usb3 *usb3, u32 bits, u32 offs) in usb3_set_bit() argument
408 u32 val = usb3_read(usb3, offs); in usb3_set_bit()
411 usb3_write(usb3, val, offs); in usb3_set_bit()
414 static void usb3_clear_bit(struct renesas_usb3 *usb3, u32 bits, u32 offs) in usb3_clear_bit() argument
416 u32 val = usb3_read(usb3, offs); in usb3_clear_bit()
419 usb3_write(usb3, val, offs); in usb3_clear_bit()
422 static int usb3_wait(struct renesas_usb3 *usb3, u32 reg, u32 mask, in usb3_wait() argument
428 if ((usb3_read(usb3, reg) & mask) == expected) in usb3_wait()
433 dev_dbg(usb3_to_dev(usb3), "%s: timed out (%8x, %08x, %08x)\n", in usb3_wait()
441 struct renesas_usb3 *usb3 = container_of(work, struct renesas_usb3, in renesas_usb3_extcon_work() local
444 extcon_set_state_sync(usb3->extcon, EXTCON_USB_HOST, usb3->extcon_host); in renesas_usb3_extcon_work()
445 extcon_set_state_sync(usb3->extcon, EXTCON_USB, usb3->extcon_usb); in renesas_usb3_extcon_work()
448 static void usb3_enable_irq_1(struct renesas_usb3 *usb3, u32 bits) in usb3_enable_irq_1() argument
450 usb3_set_bit(usb3, bits, USB3_USB_INT_ENA_1); in usb3_enable_irq_1()
453 static void usb3_disable_irq_1(struct renesas_usb3 *usb3, u32 bits) in usb3_disable_irq_1() argument
455 usb3_clear_bit(usb3, bits, USB3_USB_INT_ENA_1); in usb3_disable_irq_1()
458 static void usb3_enable_pipe_irq(struct renesas_usb3 *usb3, int num) in usb3_enable_pipe_irq() argument
460 usb3_set_bit(usb3, USB_INT_2_PIPE(num), USB3_USB_INT_ENA_2); in usb3_enable_pipe_irq()
463 static void usb3_disable_pipe_irq(struct renesas_usb3 *usb3, int num) in usb3_disable_pipe_irq() argument
465 usb3_clear_bit(usb3, USB_INT_2_PIPE(num), USB3_USB_INT_ENA_2); in usb3_disable_pipe_irq()
468 static bool usb3_is_host(struct renesas_usb3 *usb3) in usb3_is_host() argument
470 return !(usb3_read(usb3, USB3_DRD_CON) & DRD_CON_PERI_CON); in usb3_is_host()
473 static void usb3_init_axi_bridge(struct renesas_usb3 *usb3) in usb3_init_axi_bridge() argument
476 usb3_write(usb3, ~0, USB3_DMA_INT_STA); in usb3_init_axi_bridge()
477 usb3_write(usb3, 0, USB3_DMA_INT_ENA); in usb3_init_axi_bridge()
478 usb3_set_bit(usb3, AXI_INT_DMAINT | AXI_INT_EPCINT, USB3_AXI_INT_ENA); in usb3_init_axi_bridge()
481 static void usb3_init_epc_registers(struct renesas_usb3 *usb3) in usb3_init_epc_registers() argument
483 usb3_write(usb3, ~0, USB3_USB_INT_STA_1); in usb3_init_epc_registers()
484 if (!usb3->workaround_for_vbus) in usb3_init_epc_registers()
485 usb3_enable_irq_1(usb3, USB_INT_1_VBUS_CNG); in usb3_init_epc_registers()
488 static bool usb3_wakeup_usb2_phy(struct renesas_usb3 *usb3) in usb3_wakeup_usb2_phy() argument
490 if (!(usb3_read(usb3, USB3_USB20_CON) & USB20_CON_B2_SUSPEND)) in usb3_wakeup_usb2_phy()
493 usb3_clear_bit(usb3, USB20_CON_B2_SUSPEND, USB3_USB20_CON); in usb3_wakeup_usb2_phy()
494 usb3_enable_irq_1(usb3, USB_INT_1_B2_RSUM); in usb3_wakeup_usb2_phy()
499 static void usb3_usb2_pullup(struct renesas_usb3 *usb3, int pullup) in usb3_usb2_pullup() argument
503 if (usb3->softconnect && pullup) in usb3_usb2_pullup()
504 usb3_set_bit(usb3, bits, USB3_USB20_CON); in usb3_usb2_pullup()
506 usb3_clear_bit(usb3, bits, USB3_USB20_CON); in usb3_usb2_pullup()
509 static void usb3_set_test_mode(struct renesas_usb3 *usb3) in usb3_set_test_mode() argument
511 u32 val = usb3_read(usb3, USB3_USB20_CON); in usb3_set_test_mode()
514 val |= USB20_CON_B2_TSTMOD(usb3->test_mode); in usb3_set_test_mode()
515 usb3_write(usb3, val | USB20_CON_B2_TSTMOD_EN, USB3_USB20_CON); in usb3_set_test_mode()
516 if (!usb3->test_mode) in usb3_set_test_mode()
517 usb3_clear_bit(usb3, USB20_CON_B2_TSTMOD_EN, USB3_USB20_CON); in usb3_set_test_mode()
520 static void usb3_start_usb2_connection(struct renesas_usb3 *usb3) in usb3_start_usb2_connection() argument
522 usb3->disabled_count++; in usb3_start_usb2_connection()
523 usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_start_usb2_connection()
524 usb3_set_bit(usb3, USB_COM_CON_SPD_MODE, USB3_USB_COM_CON); in usb3_start_usb2_connection()
525 usb3_usb2_pullup(usb3, 1); in usb3_start_usb2_connection()
528 static int usb3_is_usb3_phy_in_u3(struct renesas_usb3 *usb3) in usb3_is_usb3_phy_in_u3() argument
530 return usb3_read(usb3, USB3_USB30_CON) & USB30_CON_POW_SEL_IN_U3; in usb3_is_usb3_phy_in_u3()
533 static bool usb3_wakeup_usb3_phy(struct renesas_usb3 *usb3) in usb3_wakeup_usb3_phy() argument
535 if (!usb3_is_usb3_phy_in_u3(usb3)) in usb3_wakeup_usb3_phy()
538 usb3_set_bit(usb3, USB30_CON_B3_PLLWAKE, USB3_USB30_CON); in usb3_wakeup_usb3_phy()
539 usb3_enable_irq_1(usb3, USB_INT_1_B3_PLLWKUP); in usb3_wakeup_usb3_phy()
544 static u16 usb3_feature_get_un_enabled(struct renesas_usb3 *usb3) in usb3_feature_get_un_enabled() argument
548 u32 val = usb3_read(usb3, USB3_SSIFCMD); in usb3_feature_get_un_enabled()
560 static void usb3_feature_u2_enable(struct renesas_usb3 *usb3, bool enable) in usb3_feature_u2_enable() argument
566 usb3_clear_bit(usb3, bits, USB3_SSIFCMD); in usb3_feature_u2_enable()
568 usb3_set_bit(usb3, bits, USB3_SSIFCMD); in usb3_feature_u2_enable()
571 static void usb3_feature_u1_enable(struct renesas_usb3 *usb3, bool enable) in usb3_feature_u1_enable() argument
577 usb3_clear_bit(usb3, bits, USB3_SSIFCMD); in usb3_feature_u1_enable()
579 usb3_set_bit(usb3, bits, USB3_SSIFCMD); in usb3_feature_u1_enable()
582 static void usb3_start_operation_for_usb3(struct renesas_usb3 *usb3) in usb3_start_operation_for_usb3() argument
584 usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_start_operation_for_usb3()
585 usb3_clear_bit(usb3, USB_COM_CON_SPD_MODE, USB3_USB_COM_CON); in usb3_start_operation_for_usb3()
586 usb3_set_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); in usb3_start_operation_for_usb3()
589 static void usb3_start_usb3_connection(struct renesas_usb3 *usb3) in usb3_start_usb3_connection() argument
591 usb3_start_operation_for_usb3(usb3); in usb3_start_usb3_connection()
592 usb3_set_bit(usb3, USB_COM_CON_RX_DETECTION, USB3_USB_COM_CON); in usb3_start_usb3_connection()
594 usb3_enable_irq_1(usb3, USB_INT_1_B3_LUPSUCS | USB_INT_1_B3_DISABLE | in usb3_start_usb3_connection()
598 static void usb3_stop_usb3_connection(struct renesas_usb3 *usb3) in usb3_stop_usb3_connection() argument
600 usb3_clear_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); in usb3_stop_usb3_connection()
603 static void usb3_transition_to_default_state(struct renesas_usb3 *usb3, in usb3_transition_to_default_state() argument
606 usb3_set_bit(usb3, USB_INT_2_PIPE(0), USB3_USB_INT_ENA_2); in usb3_transition_to_default_state()
607 usb3_write(usb3, P0_INT_ALL_BITS, USB3_P0_INT_STA); in usb3_transition_to_default_state()
608 usb3_set_bit(usb3, P0_INT_ALL_BITS, USB3_P0_INT_ENA); in usb3_transition_to_default_state()
611 usb3_enable_irq_1(usb3, USB_INT_1_B3_WRMRST | in usb3_transition_to_default_state()
614 usb3_enable_irq_1(usb3, USB_INT_1_B2_SPND | in usb3_transition_to_default_state()
618 static void usb3_connect(struct renesas_usb3 *usb3) in usb3_connect() argument
620 if (usb3_wakeup_usb3_phy(usb3)) in usb3_connect()
621 usb3_start_usb3_connection(usb3); in usb3_connect()
624 static void usb3_reset_epc(struct renesas_usb3 *usb3) in usb3_reset_epc() argument
626 usb3_clear_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); in usb3_reset_epc()
627 usb3_clear_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_reset_epc()
628 usb3_set_bit(usb3, USB_COM_CON_PIPE_CLR, USB3_USB_COM_CON); in usb3_reset_epc()
629 usb3->test_mode = 0; in usb3_reset_epc()
630 usb3_set_test_mode(usb3); in usb3_reset_epc()
633 static void usb3_disconnect(struct renesas_usb3 *usb3) in usb3_disconnect() argument
635 usb3->disabled_count = 0; in usb3_disconnect()
636 usb3_usb2_pullup(usb3, 0); in usb3_disconnect()
637 usb3_clear_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); in usb3_disconnect()
638 usb3_reset_epc(usb3); in usb3_disconnect()
639 usb3_disable_irq_1(usb3, USB_INT_1_B2_RSUM | USB_INT_1_B3_PLLWKUP | in usb3_disconnect()
644 usb3_clear_bit(usb3, USB_COM_CON_SPD_MODE, USB3_USB_COM_CON); in usb3_disconnect()
645 usb3_init_epc_registers(usb3); in usb3_disconnect()
647 if (usb3->driver) in usb3_disconnect()
648 usb3->driver->disconnect(&usb3->gadget); in usb3_disconnect()
651 static void usb3_check_vbus(struct renesas_usb3 *usb3) in usb3_check_vbus() argument
653 if (usb3->workaround_for_vbus) { in usb3_check_vbus()
654 usb3_connect(usb3); in usb3_check_vbus()
656 usb3->extcon_usb = !!(usb3_read(usb3, USB3_USB_STA) & in usb3_check_vbus()
658 if (usb3->extcon_usb) in usb3_check_vbus()
659 usb3_connect(usb3); in usb3_check_vbus()
661 usb3_disconnect(usb3); in usb3_check_vbus()
663 schedule_work(&usb3->extcon_work); in usb3_check_vbus()
669 struct renesas_usb3 *usb3 = in renesas_usb3_role_work() local
672 usb_role_switch_set_role(usb3->role_sw, usb3->role); in renesas_usb3_role_work()
675 static void usb3_set_mode(struct renesas_usb3 *usb3, bool host) in usb3_set_mode() argument
678 usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); in usb3_set_mode()
680 usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); in usb3_set_mode()
683 static void usb3_set_mode_by_role_sw(struct renesas_usb3 *usb3, bool host) in usb3_set_mode_by_role_sw() argument
685 if (usb3->role_sw) { in usb3_set_mode_by_role_sw()
686 usb3->role = host ? USB_ROLE_HOST : USB_ROLE_DEVICE; in usb3_set_mode_by_role_sw()
687 schedule_work(&usb3->role_work); in usb3_set_mode_by_role_sw()
689 usb3_set_mode(usb3, host); in usb3_set_mode_by_role_sw()
693 static void usb3_vbus_out(struct renesas_usb3 *usb3, bool enable) in usb3_vbus_out() argument
696 usb3_set_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON); in usb3_vbus_out()
698 usb3_clear_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON); in usb3_vbus_out()
701 static void usb3_mode_config(struct renesas_usb3 *usb3, bool host, bool a_dev) in usb3_mode_config() argument
705 spin_lock_irqsave(&usb3->lock, flags); in usb3_mode_config()
706 if (!usb3->role_sw_by_connector || in usb3_mode_config()
707 usb3->connection_state != USB_ROLE_NONE) { in usb3_mode_config()
708 usb3_set_mode_by_role_sw(usb3, host); in usb3_mode_config()
709 usb3_vbus_out(usb3, a_dev); in usb3_mode_config()
712 if ((!host && a_dev) || usb3->start_to_connect) in usb3_mode_config()
713 usb3_connect(usb3); in usb3_mode_config()
714 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_mode_config()
717 static bool usb3_is_a_device(struct renesas_usb3 *usb3) in usb3_is_a_device() argument
719 return !(usb3_read(usb3, USB3_USB_OTG_STA) & USB_OTG_IDMON); in usb3_is_a_device()
722 static void usb3_check_id(struct renesas_usb3 *usb3) in usb3_check_id() argument
724 usb3->extcon_host = usb3_is_a_device(usb3); in usb3_check_id()
726 if ((!usb3->role_sw_by_connector && usb3->extcon_host && in usb3_check_id()
727 !usb3->forced_b_device) || usb3->connection_state == USB_ROLE_HOST) in usb3_check_id()
728 usb3_mode_config(usb3, true, true); in usb3_check_id()
730 usb3_mode_config(usb3, false, false); in usb3_check_id()
732 schedule_work(&usb3->extcon_work); in usb3_check_id()
735 static void renesas_usb3_init_controller(struct renesas_usb3 *usb3) in renesas_usb3_init_controller() argument
737 usb3_init_axi_bridge(usb3); in renesas_usb3_init_controller()
738 usb3_init_epc_registers(usb3); in renesas_usb3_init_controller()
739 usb3_set_bit(usb3, USB_COM_CON_PN_WDATAIF_NL | in renesas_usb3_init_controller()
742 usb3_write(usb3, USB_OTG_IDMON, USB3_USB_OTG_INT_STA); in renesas_usb3_init_controller()
743 usb3_write(usb3, USB_OTG_IDMON, USB3_USB_OTG_INT_ENA); in renesas_usb3_init_controller()
745 usb3_check_id(usb3); in renesas_usb3_init_controller()
746 usb3_check_vbus(usb3); in renesas_usb3_init_controller()
749 static void renesas_usb3_stop_controller(struct renesas_usb3 *usb3) in renesas_usb3_stop_controller() argument
751 usb3_disconnect(usb3); in renesas_usb3_stop_controller()
752 usb3_write(usb3, 0, USB3_P0_INT_ENA); in renesas_usb3_stop_controller()
753 usb3_write(usb3, 0, USB3_USB_OTG_INT_ENA); in renesas_usb3_stop_controller()
754 usb3_write(usb3, 0, USB3_USB_INT_ENA_1); in renesas_usb3_stop_controller()
755 usb3_write(usb3, 0, USB3_USB_INT_ENA_2); in renesas_usb3_stop_controller()
756 usb3_write(usb3, 0, USB3_AXI_INT_ENA); in renesas_usb3_stop_controller()
759 static void usb3_irq_epc_int_1_pll_wakeup(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_pll_wakeup() argument
761 usb3_disable_irq_1(usb3, USB_INT_1_B3_PLLWKUP); in usb3_irq_epc_int_1_pll_wakeup()
762 usb3_clear_bit(usb3, USB30_CON_B3_PLLWAKE, USB3_USB30_CON); in usb3_irq_epc_int_1_pll_wakeup()
763 usb3_start_usb3_connection(usb3); in usb3_irq_epc_int_1_pll_wakeup()
766 static void usb3_irq_epc_int_1_linkup_success(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_linkup_success() argument
768 usb3_transition_to_default_state(usb3, true); in usb3_irq_epc_int_1_linkup_success()
771 static void usb3_irq_epc_int_1_resume(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_resume() argument
773 usb3_disable_irq_1(usb3, USB_INT_1_B2_RSUM); in usb3_irq_epc_int_1_resume()
774 usb3_start_usb2_connection(usb3); in usb3_irq_epc_int_1_resume()
775 usb3_transition_to_default_state(usb3, false); in usb3_irq_epc_int_1_resume()
778 static void usb3_irq_epc_int_1_suspend(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_suspend() argument
780 usb3_disable_irq_1(usb3, USB_INT_1_B2_SPND); in usb3_irq_epc_int_1_suspend()
782 if (usb3->gadget.speed != USB_SPEED_UNKNOWN && in usb3_irq_epc_int_1_suspend()
783 usb3->gadget.state != USB_STATE_NOTATTACHED) { in usb3_irq_epc_int_1_suspend()
784 if (usb3->driver && usb3->driver->suspend) in usb3_irq_epc_int_1_suspend()
785 usb3->driver->suspend(&usb3->gadget); in usb3_irq_epc_int_1_suspend()
786 usb_gadget_set_state(&usb3->gadget, USB_STATE_SUSPENDED); in usb3_irq_epc_int_1_suspend()
790 static void usb3_irq_epc_int_1_disable(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_disable() argument
792 usb3_stop_usb3_connection(usb3); in usb3_irq_epc_int_1_disable()
793 if (usb3_wakeup_usb2_phy(usb3)) in usb3_irq_epc_int_1_disable()
794 usb3_irq_epc_int_1_resume(usb3); in usb3_irq_epc_int_1_disable()
797 static void usb3_irq_epc_int_1_bus_reset(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_bus_reset() argument
799 usb3_reset_epc(usb3); in usb3_irq_epc_int_1_bus_reset()
800 if (usb3->disabled_count < 3) in usb3_irq_epc_int_1_bus_reset()
801 usb3_start_usb3_connection(usb3); in usb3_irq_epc_int_1_bus_reset()
803 usb3_start_usb2_connection(usb3); in usb3_irq_epc_int_1_bus_reset()
806 static void usb3_irq_epc_int_1_vbus_change(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_vbus_change() argument
808 usb3_check_vbus(usb3); in usb3_irq_epc_int_1_vbus_change()
811 static void usb3_irq_epc_int_1_hot_reset(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_hot_reset() argument
813 usb3_reset_epc(usb3); in usb3_irq_epc_int_1_hot_reset()
814 usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_irq_epc_int_1_hot_reset()
817 usb3_set_bit(usb3, USB30_CON_B3_HOTRST_CMP, USB3_USB30_CON); in usb3_irq_epc_int_1_hot_reset()
820 static void usb3_irq_epc_int_1_warm_reset(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_warm_reset() argument
822 usb3_reset_epc(usb3); in usb3_irq_epc_int_1_warm_reset()
823 usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_irq_epc_int_1_warm_reset()
825 usb3_start_operation_for_usb3(usb3); in usb3_irq_epc_int_1_warm_reset()
826 usb3_enable_irq_1(usb3, USB_INT_1_SPEED); in usb3_irq_epc_int_1_warm_reset()
829 static void usb3_irq_epc_int_1_speed(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_speed() argument
831 u32 speed = usb3_read(usb3, USB3_USB_STA) & USB_STA_SPEED_MASK; in usb3_irq_epc_int_1_speed()
835 usb3->gadget.speed = USB_SPEED_SUPER; in usb3_irq_epc_int_1_speed()
836 usb3->gadget.ep0->maxpacket = USB3_EP0_SS_MAX_PACKET_SIZE; in usb3_irq_epc_int_1_speed()
839 usb3->gadget.speed = USB_SPEED_HIGH; in usb3_irq_epc_int_1_speed()
840 usb3->gadget.ep0->maxpacket = USB3_EP0_HSFS_MAX_PACKET_SIZE; in usb3_irq_epc_int_1_speed()
843 usb3->gadget.speed = USB_SPEED_FULL; in usb3_irq_epc_int_1_speed()
844 usb3->gadget.ep0->maxpacket = USB3_EP0_HSFS_MAX_PACKET_SIZE; in usb3_irq_epc_int_1_speed()
847 usb3->gadget.speed = USB_SPEED_UNKNOWN; in usb3_irq_epc_int_1_speed()
852 static void usb3_irq_epc_int_1(struct renesas_usb3 *usb3, u32 int_sta_1) in usb3_irq_epc_int_1() argument
855 usb3_irq_epc_int_1_pll_wakeup(usb3); in usb3_irq_epc_int_1()
858 usb3_irq_epc_int_1_linkup_success(usb3); in usb3_irq_epc_int_1()
861 usb3_irq_epc_int_1_hot_reset(usb3); in usb3_irq_epc_int_1()
864 usb3_irq_epc_int_1_warm_reset(usb3); in usb3_irq_epc_int_1()
867 usb3_irq_epc_int_1_disable(usb3); in usb3_irq_epc_int_1()
870 usb3_irq_epc_int_1_bus_reset(usb3); in usb3_irq_epc_int_1()
873 usb3_irq_epc_int_1_resume(usb3); in usb3_irq_epc_int_1()
876 usb3_irq_epc_int_1_suspend(usb3); in usb3_irq_epc_int_1()
879 usb3_irq_epc_int_1_speed(usb3); in usb3_irq_epc_int_1()
882 usb3_irq_epc_int_1_vbus_change(usb3); in usb3_irq_epc_int_1()
895 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_get_request() local
899 spin_lock_irqsave(&usb3->lock, flags); in usb3_get_request()
901 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_get_request()
910 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in __usb3_request_done() local
912 dev_dbg(usb3_to_dev(usb3), "giveback: ep%2d, %u, %u, %d\n", in __usb3_request_done()
918 spin_unlock(&usb3->lock); in __usb3_request_done()
920 spin_lock(&usb3->lock); in __usb3_request_done()
926 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_request_done() local
929 spin_lock_irqsave(&usb3->lock, flags); in usb3_request_done()
931 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_request_done()
934 static void usb3_irq_epc_pipe0_status_end(struct renesas_usb3 *usb3) in usb3_irq_epc_pipe0_status_end() argument
936 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_irq_epc_pipe0_status_end()
941 if (usb3->test_mode) in usb3_irq_epc_pipe0_status_end()
942 usb3_set_test_mode(usb3); in usb3_irq_epc_pipe0_status_end()
945 static void usb3_get_setup_data(struct renesas_usb3 *usb3, in usb3_get_setup_data() argument
948 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_get_setup_data()
951 *data++ = usb3_read(usb3, USB3_STUP_DAT_0); in usb3_get_setup_data()
952 *data = usb3_read(usb3, USB3_STUP_DAT_1); in usb3_get_setup_data()
958 static void usb3_set_p0_con_update_res(struct renesas_usb3 *usb3, u32 res) in usb3_set_p0_con_update_res() argument
960 u32 val = usb3_read(usb3, USB3_P0_CON); in usb3_set_p0_con_update_res()
964 usb3_write(usb3, val, USB3_P0_CON); in usb3_set_p0_con_update_res()
967 static void usb3_set_p0_con_for_ctrl_read_data(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_ctrl_read_data() argument
969 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | in usb3_set_p0_con_for_ctrl_read_data()
974 static void usb3_set_p0_con_for_ctrl_read_status(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_ctrl_read_status() argument
976 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | in usb3_set_p0_con_for_ctrl_read_status()
981 static void usb3_set_p0_con_for_ctrl_write_data(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_ctrl_write_data() argument
983 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | in usb3_set_p0_con_for_ctrl_write_data()
988 static void usb3_set_p0_con_for_ctrl_write_status(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_ctrl_write_status() argument
990 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | in usb3_set_p0_con_for_ctrl_write_status()
995 static void usb3_set_p0_con_for_no_data(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_no_data() argument
997 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | in usb3_set_p0_con_for_no_data()
1002 static void usb3_set_p0_con_stall(struct renesas_usb3 *usb3) in usb3_set_p0_con_stall() argument
1004 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_STALL | in usb3_set_p0_con_stall()
1009 static void usb3_set_p0_con_stop(struct renesas_usb3 *usb3) in usb3_set_p0_con_stop() argument
1011 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | in usb3_set_p0_con_stop()
1016 static int usb3_pn_change(struct renesas_usb3 *usb3, int num) in usb3_pn_change() argument
1018 if (num == 0 || num > usb3->num_usb3_eps) in usb3_pn_change()
1021 usb3_write(usb3, num, USB3_PIPE_COM); in usb3_pn_change()
1026 static void usb3_set_pn_con_update_res(struct renesas_usb3 *usb3, u32 res) in usb3_set_pn_con_update_res() argument
1028 u32 val = usb3_read(usb3, USB3_PN_CON); in usb3_set_pn_con_update_res()
1033 usb3_write(usb3, val, USB3_PN_CON); in usb3_set_pn_con_update_res()
1036 static void usb3_pn_start(struct renesas_usb3 *usb3) in usb3_pn_start() argument
1038 usb3_set_pn_con_update_res(usb3, PN_CON_RES_NORMAL); in usb3_pn_start()
1041 static void usb3_pn_stop(struct renesas_usb3 *usb3) in usb3_pn_stop() argument
1043 usb3_set_pn_con_update_res(usb3, PN_CON_RES_FORCE_NRDY); in usb3_pn_stop()
1046 static void usb3_pn_stall(struct renesas_usb3 *usb3) in usb3_pn_stall() argument
1048 usb3_set_pn_con_update_res(usb3, PN_CON_RES_FORCE_STALL); in usb3_pn_stall()
1051 static int usb3_pn_con_clear(struct renesas_usb3 *usb3) in usb3_pn_con_clear() argument
1053 usb3_set_bit(usb3, PN_CON_CLR, USB3_PN_CON); in usb3_pn_con_clear()
1055 return usb3_wait(usb3, USB3_PN_CON, PN_CON_CLR, 0); in usb3_pn_con_clear()
1072 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_wait_pipe_status() local
1075 return usb3_wait(usb3, sta_reg, mask, mask); in usb3_wait_pipe_status()
1081 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_set_px_con_send() local
1083 u32 val = usb3_read(usb3, con_reg); in usb3_set_px_con_send()
1087 usb3_write(usb3, val, con_reg); in usb3_set_px_con_send()
1094 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_write_pipe() local
1110 iowrite32_rep(usb3->reg + fifo_reg, buf, len / 4); in usb3_write_pipe()
1118 usb3_write(usb3, tmp, fifo_reg); in usb3_write_pipe()
1131 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_get_received_length() local
1134 return usb3_read(usb3, lng_reg); in usb3_get_received_length()
1140 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_read_pipe() local
1155 ioread32_rep(usb3->reg + fifo_reg, buf, len / 4); in usb3_read_pipe()
1161 tmp = usb3_read(usb3, fifo_reg); in usb3_read_pipe()
1172 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_set_status_stage() local
1175 usb3_set_p0_con_for_ctrl_read_status(usb3); in usb3_set_status_stage()
1178 usb3_set_p0_con_for_no_data(usb3); in usb3_set_status_stage()
1180 usb3_set_p0_con_for_ctrl_write_status(usb3); in usb3_set_status_stage()
1201 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_start_pipe0() local
1209 usb3_set_bit(usb3, P0_MOD_DIR, USB3_P0_MOD); in usb3_start_pipe0()
1210 usb3_set_p0_con_for_ctrl_read_data(usb3); in usb3_start_pipe0()
1212 usb3_clear_bit(usb3, P0_MOD_DIR, USB3_P0_MOD); in usb3_start_pipe0()
1214 usb3_set_p0_con_for_ctrl_write_data(usb3); in usb3_start_pipe0()
1220 static void usb3_enable_dma_pipen(struct renesas_usb3 *usb3) in usb3_enable_dma_pipen() argument
1222 usb3_set_bit(usb3, PN_CON_DATAIF_EN, USB3_PN_CON); in usb3_enable_dma_pipen()
1225 static void usb3_disable_dma_pipen(struct renesas_usb3 *usb3) in usb3_disable_dma_pipen() argument
1227 usb3_clear_bit(usb3, PN_CON_DATAIF_EN, USB3_PN_CON); in usb3_disable_dma_pipen()
1230 static void usb3_enable_dma_irq(struct renesas_usb3 *usb3, int num) in usb3_enable_dma_irq() argument
1232 usb3_set_bit(usb3, DMA_INT(num), USB3_DMA_INT_ENA); in usb3_enable_dma_irq()
1235 static void usb3_disable_dma_irq(struct renesas_usb3 *usb3, int num) in usb3_disable_dma_irq() argument
1237 usb3_clear_bit(usb3, DMA_INT(num), USB3_DMA_INT_ENA); in usb3_disable_dma_irq()
1263 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_dma_get_setting_area() local
1269 dev_dbg(usb3_to_dev(usb3), "%s: the length is too big (%d)\n", in usb3_dma_get_setting_area()
1281 usb3_for_each_dma(usb3, dma, i) { in usb3_dma_get_setting_area()
1285 if (usb_gadget_map_request(&usb3->gadget, &usb3_req->req, in usb3_dma_get_setting_area()
1301 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_dma_put_setting_area() local
1305 usb3_for_each_dma(usb3, dma, i) { in usb3_dma_put_setting_area()
1307 usb_gadget_unmap_request(&usb3->gadget, &usb3_req->req, in usb3_dma_put_setting_area()
1348 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_dma_kick_prd() local
1356 usb3_write(usb3, 1 << usb3_ep->num, USB3_DMA_INT_STA); in usb3_dma_kick_prd()
1357 usb3_write(usb3, AXI_INT_PRDEN_CLR_STA(dma->num) | in usb3_dma_kick_prd()
1360 usb3_write(usb3, dma->prd_dma, USB3_DMA_CH0_PRD_ADR(dma->num)); in usb3_dma_kick_prd()
1361 usb3_write(usb3, dma_con, USB3_DMA_CH0_CON(dma->num)); in usb3_dma_kick_prd()
1362 usb3_enable_dma_irq(usb3, usb3_ep->num); in usb3_dma_kick_prd()
1367 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_dma_stop_prd() local
1370 usb3_disable_dma_irq(usb3, usb3_ep->num); in usb3_dma_stop_prd()
1371 usb3_write(usb3, 0, USB3_DMA_CH0_CON(dma->num)); in usb3_dma_stop_prd()
1409 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_dma_try_start() local
1415 usb3_pn_stop(usb3); in usb3_dma_try_start()
1416 usb3_enable_dma_pipen(usb3); in usb3_dma_try_start()
1419 usb3_pn_start(usb3); in usb3_dma_try_start()
1429 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_dma_try_stop() local
1433 spin_lock_irqsave(&usb3->lock, flags); in usb3_dma_try_stop()
1437 if (!usb3_pn_change(usb3, usb3_ep->num)) in usb3_dma_try_stop()
1438 usb3_disable_dma_pipen(usb3); in usb3_dma_try_stop()
1444 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_dma_try_stop()
1448 static int renesas_usb3_dma_free_prd(struct renesas_usb3 *usb3, in renesas_usb3_dma_free_prd() argument
1454 usb3_for_each_dma(usb3, dma, i) { in renesas_usb3_dma_free_prd()
1465 static int renesas_usb3_dma_alloc_prd(struct renesas_usb3 *usb3, in renesas_usb3_dma_alloc_prd() argument
1474 usb3_for_each_dma(usb3, dma, i) { in renesas_usb3_dma_alloc_prd()
1478 renesas_usb3_dma_free_prd(usb3, dev); in renesas_usb3_dma_alloc_prd()
1490 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_start_pipen() local
1496 spin_lock_irqsave(&usb3->lock, flags); in usb3_start_pipen()
1503 if (usb3_pn_change(usb3, usb3_ep->num) < 0) in usb3_start_pipen()
1511 usb3_pn_start(usb3); in usb3_start_pipen()
1522 usb3_set_bit(usb3, enable_bits, USB3_PN_INT_ENA); in usb3_start_pipen()
1523 usb3_enable_pipe_irq(usb3, usb3_ep->num); in usb3_start_pipen()
1526 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_start_pipen()
1534 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in renesas_usb3_ep_queue() local
1537 dev_dbg(usb3_to_dev(usb3), "ep_queue: ep%2d, %u\n", usb3_ep->num, in renesas_usb3_ep_queue()
1542 spin_lock_irqsave(&usb3->lock, flags); in renesas_usb3_ep_queue()
1544 spin_unlock_irqrestore(&usb3->lock, flags); in renesas_usb3_ep_queue()
1554 static void usb3_set_device_address(struct renesas_usb3 *usb3, u16 addr) in usb3_set_device_address() argument
1557 usb3_set_bit(usb3, USB_COM_CON_DEV_ADDR(addr), USB3_USB_COM_CON); in usb3_set_device_address()
1560 static bool usb3_std_req_set_address(struct renesas_usb3 *usb3, in usb3_std_req_set_address() argument
1566 usb3_set_device_address(usb3, le16_to_cpu(ctrl->wValue)); in usb3_std_req_set_address()
1567 usb3_set_p0_con_for_no_data(usb3); in usb3_std_req_set_address()
1572 static void usb3_pipe0_internal_xfer(struct renesas_usb3 *usb3, in usb3_pipe0_internal_xfer() argument
1577 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_pipe0_internal_xfer()
1580 memcpy(usb3->ep0_buf, tx_data, in usb3_pipe0_internal_xfer()
1583 usb3->ep0_req->buf = &usb3->ep0_buf; in usb3_pipe0_internal_xfer()
1584 usb3->ep0_req->length = len; in usb3_pipe0_internal_xfer()
1585 usb3->ep0_req->complete = complete; in usb3_pipe0_internal_xfer()
1586 renesas_usb3_ep_queue(&usb3_ep->ep, usb3->ep0_req, GFP_ATOMIC); in usb3_pipe0_internal_xfer()
1594 static bool usb3_std_req_get_status(struct renesas_usb3 *usb3, in usb3_std_req_get_status() argument
1605 if (usb3->gadget.is_selfpowered) in usb3_std_req_get_status()
1607 if (usb3->gadget.speed == USB_SPEED_SUPER) in usb3_std_req_get_status()
1608 status |= usb3_feature_get_un_enabled(usb3); in usb3_std_req_get_status()
1614 usb3_ep = usb3_get_ep(usb3, num); in usb3_std_req_get_status()
1625 dev_dbg(usb3_to_dev(usb3), "get_status: req = %p\n", in usb3_std_req_get_status()
1626 usb_req_to_usb3_req(usb3->ep0_req)); in usb3_std_req_get_status()
1627 usb3_pipe0_internal_xfer(usb3, &tx_data, sizeof(tx_data), in usb3_std_req_get_status()
1634 static bool usb3_std_req_feature_device(struct renesas_usb3 *usb3, in usb3_std_req_feature_device() argument
1644 usb3->test_mode = le16_to_cpu(ctrl->wIndex) >> 8; in usb3_std_req_feature_device()
1649 if (usb3->gadget.speed != USB_SPEED_SUPER) in usb3_std_req_feature_device()
1652 usb3_feature_u1_enable(usb3, set); in usb3_std_req_feature_device()
1654 usb3_feature_u2_enable(usb3, set); in usb3_std_req_feature_device()
1666 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_set_halt_p0() local
1673 usb3_set_p0_con_stall(usb3); in usb3_set_halt_p0()
1675 usb3_set_p0_con_stop(usb3); in usb3_set_halt_p0()
1683 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_set_halt_pn() local
1686 spin_lock_irqsave(&usb3->lock, flags); in usb3_set_halt_pn()
1687 if (!usb3_pn_change(usb3, usb3_ep->num)) { in usb3_set_halt_pn()
1690 usb3_pn_stall(usb3); in usb3_set_halt_pn()
1692 usb3_pn_con_clear(usb3); in usb3_set_halt_pn()
1693 usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); in usb3_set_halt_pn()
1694 usb3_pn_stop(usb3); in usb3_set_halt_pn()
1697 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_set_halt_pn()
1718 static bool usb3_std_req_feature_endpoint(struct renesas_usb3 *usb3, in usb3_std_req_feature_endpoint() argument
1729 usb3_ep = usb3_get_ep(usb3, num); in usb3_std_req_feature_endpoint()
1743 static bool usb3_std_req_feature(struct renesas_usb3 *usb3, in usb3_std_req_feature() argument
1750 stall = usb3_std_req_feature_device(usb3, ctrl, set); in usb3_std_req_feature()
1755 stall = usb3_std_req_feature_endpoint(usb3, ctrl, set); in usb3_std_req_feature()
1763 usb3_set_p0_con_for_no_data(usb3); in usb3_std_req_feature()
1774 static bool usb3_std_req_set_sel(struct renesas_usb3 *usb3, in usb3_std_req_set_sel() argument
1782 dev_dbg(usb3_to_dev(usb3), "set_sel: req = %p\n", in usb3_std_req_set_sel()
1783 usb_req_to_usb3_req(usb3->ep0_req)); in usb3_std_req_set_sel()
1784 usb3_pipe0_internal_xfer(usb3, NULL, 6, usb3_pipe0_set_sel_completion); in usb3_std_req_set_sel()
1789 static bool usb3_std_req_set_configuration(struct renesas_usb3 *usb3, in usb3_std_req_set_configuration() argument
1793 usb3_set_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); in usb3_std_req_set_configuration()
1795 usb3_clear_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); in usb3_std_req_set_configuration()
1802 * @usb3: the renesas_usb3 pointer
1807 static bool usb3_handle_standard_request(struct renesas_usb3 *usb3, in usb3_handle_standard_request() argument
1816 stall = usb3_std_req_set_address(usb3, ctrl); in usb3_handle_standard_request()
1820 stall = usb3_std_req_get_status(usb3, ctrl); in usb3_handle_standard_request()
1824 stall = usb3_std_req_feature(usb3, ctrl, false); in usb3_handle_standard_request()
1828 stall = usb3_std_req_feature(usb3, ctrl, true); in usb3_handle_standard_request()
1832 stall = usb3_std_req_set_sel(usb3, ctrl); in usb3_handle_standard_request()
1841 usb3_std_req_set_configuration(usb3, ctrl); in usb3_handle_standard_request()
1849 usb3_set_p0_con_stall(usb3); in usb3_handle_standard_request()
1854 static int usb3_p0_con_clear_buffer(struct renesas_usb3 *usb3) in usb3_p0_con_clear_buffer() argument
1856 usb3_set_bit(usb3, P0_CON_BCLR, USB3_P0_CON); in usb3_p0_con_clear_buffer()
1858 return usb3_wait(usb3, USB3_P0_CON, P0_CON_BCLR, 0); in usb3_p0_con_clear_buffer()
1861 static void usb3_irq_epc_pipe0_setup(struct renesas_usb3 *usb3) in usb3_irq_epc_pipe0_setup() argument
1864 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_irq_epc_pipe0_setup()
1871 usb3_p0_con_clear_buffer(usb3); in usb3_irq_epc_pipe0_setup()
1872 usb3_get_setup_data(usb3, &ctrl); in usb3_irq_epc_pipe0_setup()
1873 if (!usb3_handle_standard_request(usb3, &ctrl)) in usb3_irq_epc_pipe0_setup()
1874 if (usb3->driver->setup(&usb3->gadget, &ctrl) < 0) in usb3_irq_epc_pipe0_setup()
1875 usb3_set_p0_con_stall(usb3); in usb3_irq_epc_pipe0_setup()
1878 static void usb3_irq_epc_pipe0_bfrdy(struct renesas_usb3 *usb3) in usb3_irq_epc_pipe0_bfrdy() argument
1880 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_irq_epc_pipe0_bfrdy()
1889 static void usb3_irq_epc_pipe0(struct renesas_usb3 *usb3) in usb3_irq_epc_pipe0() argument
1891 u32 p0_int_sta = usb3_read(usb3, USB3_P0_INT_STA); in usb3_irq_epc_pipe0()
1893 p0_int_sta &= usb3_read(usb3, USB3_P0_INT_ENA); in usb3_irq_epc_pipe0()
1894 usb3_write(usb3, p0_int_sta, USB3_P0_INT_STA); in usb3_irq_epc_pipe0()
1896 usb3_irq_epc_pipe0_status_end(usb3); in usb3_irq_epc_pipe0()
1898 usb3_irq_epc_pipe0_setup(usb3); in usb3_irq_epc_pipe0()
1900 usb3_irq_epc_pipe0_bfrdy(usb3); in usb3_irq_epc_pipe0()
1903 static void usb3_request_done_pipen(struct renesas_usb3 *usb3, in usb3_request_done_pipen() argument
1910 spin_lock_irqsave(&usb3->lock, flags); in usb3_request_done_pipen()
1911 if (usb3_pn_change(usb3, usb3_ep->num)) in usb3_request_done_pipen()
1912 usb3_pn_stop(usb3); in usb3_request_done_pipen()
1913 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_request_done_pipen()
1915 usb3_disable_pipe_irq(usb3, usb3_ep->num); in usb3_request_done_pipen()
1924 static void usb3_irq_epc_pipen_lsttr(struct renesas_usb3 *usb3, int num) in usb3_irq_epc_pipen_lsttr() argument
1926 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num); in usb3_irq_epc_pipen_lsttr()
1933 dev_dbg(usb3_to_dev(usb3), "%s: len = %u, actual = %u\n", in usb3_irq_epc_pipen_lsttr()
1935 usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0); in usb3_irq_epc_pipen_lsttr()
1939 static void usb3_irq_epc_pipen_bfrdy(struct renesas_usb3 *usb3, int num) in usb3_irq_epc_pipen_bfrdy() argument
1941 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num); in usb3_irq_epc_pipen_bfrdy()
1948 spin_lock(&usb3->lock); in usb3_irq_epc_pipen_bfrdy()
1949 if (usb3_pn_change(usb3, num)) in usb3_irq_epc_pipen_bfrdy()
1955 usb3_clear_bit(usb3, PN_INT_BFRDY, USB3_PN_INT_ENA); in usb3_irq_epc_pipen_bfrdy()
1963 spin_unlock(&usb3->lock); in usb3_irq_epc_pipen_bfrdy()
1966 usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0); in usb3_irq_epc_pipen_bfrdy()
1969 static void usb3_irq_epc_pipen(struct renesas_usb3 *usb3, int num) in usb3_irq_epc_pipen() argument
1973 spin_lock(&usb3->lock); in usb3_irq_epc_pipen()
1974 if (usb3_pn_change(usb3, num) < 0) { in usb3_irq_epc_pipen()
1975 spin_unlock(&usb3->lock); in usb3_irq_epc_pipen()
1979 pn_int_sta = usb3_read(usb3, USB3_PN_INT_STA); in usb3_irq_epc_pipen()
1980 pn_int_sta &= usb3_read(usb3, USB3_PN_INT_ENA); in usb3_irq_epc_pipen()
1981 usb3_write(usb3, pn_int_sta, USB3_PN_INT_STA); in usb3_irq_epc_pipen()
1982 spin_unlock(&usb3->lock); in usb3_irq_epc_pipen()
1984 usb3_irq_epc_pipen_lsttr(usb3, num); in usb3_irq_epc_pipen()
1986 usb3_irq_epc_pipen_bfrdy(usb3, num); in usb3_irq_epc_pipen()
1989 static void usb3_irq_epc_int_2(struct renesas_usb3 *usb3, u32 int_sta_2) in usb3_irq_epc_int_2() argument
1993 for (i = 0; i < usb3->num_usb3_eps; i++) { in usb3_irq_epc_int_2()
1996 usb3_irq_epc_pipe0(usb3); in usb3_irq_epc_int_2()
1998 usb3_irq_epc_pipen(usb3, i); in usb3_irq_epc_int_2()
2003 static void usb3_irq_idmon_change(struct renesas_usb3 *usb3) in usb3_irq_idmon_change() argument
2005 usb3_check_id(usb3); in usb3_irq_idmon_change()
2008 static void usb3_irq_otg_int(struct renesas_usb3 *usb3, u32 otg_int_sta) in usb3_irq_otg_int() argument
2011 usb3_irq_idmon_change(usb3); in usb3_irq_otg_int()
2014 static void usb3_irq_epc(struct renesas_usb3 *usb3) in usb3_irq_epc() argument
2016 u32 int_sta_1 = usb3_read(usb3, USB3_USB_INT_STA_1); in usb3_irq_epc()
2017 u32 int_sta_2 = usb3_read(usb3, USB3_USB_INT_STA_2); in usb3_irq_epc()
2018 u32 otg_int_sta = usb3_read(usb3, USB3_USB_OTG_INT_STA); in usb3_irq_epc()
2020 int_sta_1 &= usb3_read(usb3, USB3_USB_INT_ENA_1); in usb3_irq_epc()
2022 usb3_write(usb3, int_sta_1, USB3_USB_INT_STA_1); in usb3_irq_epc()
2023 usb3_irq_epc_int_1(usb3, int_sta_1); in usb3_irq_epc()
2026 int_sta_2 &= usb3_read(usb3, USB3_USB_INT_ENA_2); in usb3_irq_epc()
2028 usb3_irq_epc_int_2(usb3, int_sta_2); in usb3_irq_epc()
2030 otg_int_sta &= usb3_read(usb3, USB3_USB_OTG_INT_ENA); in usb3_irq_epc()
2032 usb3_write(usb3, otg_int_sta, USB3_USB_OTG_INT_STA); in usb3_irq_epc()
2033 usb3_irq_otg_int(usb3, otg_int_sta); in usb3_irq_epc()
2037 static void usb3_irq_dma_int(struct renesas_usb3 *usb3, u32 dma_sta) in usb3_irq_dma_int() argument
2043 for (i = 0; i < usb3->num_usb3_eps; i++) { in usb3_irq_dma_int()
2047 usb3_ep = usb3_get_ep(usb3, i); in usb3_irq_dma_int()
2048 if (!(usb3_read(usb3, USB3_AXI_INT_STA) & in usb3_irq_dma_int()
2054 usb3_request_done_pipen(usb3, usb3_ep, usb3_req, status); in usb3_irq_dma_int()
2058 static void usb3_irq_dma(struct renesas_usb3 *usb3) in usb3_irq_dma() argument
2060 u32 dma_sta = usb3_read(usb3, USB3_DMA_INT_STA); in usb3_irq_dma()
2062 dma_sta &= usb3_read(usb3, USB3_DMA_INT_ENA); in usb3_irq_dma()
2064 usb3_write(usb3, dma_sta, USB3_DMA_INT_STA); in usb3_irq_dma()
2065 usb3_irq_dma_int(usb3, dma_sta); in usb3_irq_dma()
2071 struct renesas_usb3 *usb3 = _usb3; in renesas_usb3_irq() local
2073 u32 axi_int_sta = usb3_read(usb3, USB3_AXI_INT_STA); in renesas_usb3_irq()
2076 usb3_irq_dma(usb3); in renesas_usb3_irq()
2081 usb3_irq_epc(usb3); in renesas_usb3_irq()
2091 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_write_pn_mod() local
2097 usb3_write(usb3, val, USB3_PN_MOD); in usb3_write_pn_mod()
2134 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_enable_pipe_n() local
2139 spin_lock_irqsave(&usb3->lock, flags); in usb3_enable_pipe_n()
2140 if (!usb3_pn_change(usb3, usb3_ep->num)) { in usb3_enable_pipe_n()
2142 usb3_write(usb3, usb3_calc_rammap_val(usb3_ep, desc), in usb3_enable_pipe_n()
2144 usb3_pn_con_clear(usb3); in usb3_enable_pipe_n()
2145 usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); in usb3_enable_pipe_n()
2147 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_enable_pipe_n()
2154 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_disable_pipe_n() local
2159 spin_lock_irqsave(&usb3->lock, flags); in usb3_disable_pipe_n()
2160 if (!usb3_pn_change(usb3, usb3_ep->num)) { in usb3_disable_pipe_n()
2161 usb3_write(usb3, 0, USB3_PN_INT_ENA); in usb3_disable_pipe_n()
2162 usb3_write(usb3, 0, USB3_PN_RAMMAP); in usb3_disable_pipe_n()
2163 usb3_clear_bit(usb3, PN_CON_EN, USB3_PN_CON); in usb3_disable_pipe_n()
2165 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_disable_pipe_n()
2231 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in renesas_usb3_ep_dequeue() local
2233 dev_dbg(usb3_to_dev(usb3), "ep_dequeue: ep%2d, %u\n", usb3_ep->num, in renesas_usb3_ep_dequeue()
2237 usb3_request_done_pipen(usb3, usb3_ep, usb3_req, -ECONNRESET); in renesas_usb3_ep_dequeue()
2258 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in renesas_usb3_ep_fifo_flush() local
2262 spin_lock_irqsave(&usb3->lock, flags); in renesas_usb3_ep_fifo_flush()
2263 if (!usb3_pn_change(usb3, usb3_ep->num)) { in renesas_usb3_ep_fifo_flush()
2264 usb3_pn_con_clear(usb3); in renesas_usb3_ep_fifo_flush()
2265 usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); in renesas_usb3_ep_fifo_flush()
2267 spin_unlock_irqrestore(&usb3->lock, flags); in renesas_usb3_ep_fifo_flush()
2269 usb3_p0_con_clear_buffer(usb3); in renesas_usb3_ep_fifo_flush()
2292 struct renesas_usb3 *usb3; in renesas_usb3_start() local
2298 usb3 = gadget_to_renesas_usb3(gadget); in renesas_usb3_start()
2301 usb3->driver = driver; in renesas_usb3_start()
2303 if (usb3->phy) in renesas_usb3_start()
2304 phy_init(usb3->phy); in renesas_usb3_start()
2306 pm_runtime_get_sync(usb3_to_dev(usb3)); in renesas_usb3_start()
2308 renesas_usb3_init_controller(usb3); in renesas_usb3_start()
2315 struct renesas_usb3 *usb3 = gadget_to_renesas_usb3(gadget); in renesas_usb3_stop() local
2317 usb3->softconnect = false; in renesas_usb3_stop()
2318 usb3->gadget.speed = USB_SPEED_UNKNOWN; in renesas_usb3_stop()
2319 usb3->driver = NULL; in renesas_usb3_stop()
2320 renesas_usb3_stop_controller(usb3); in renesas_usb3_stop()
2322 if (usb3->phy) in renesas_usb3_stop()
2323 phy_exit(usb3->phy); in renesas_usb3_stop()
2325 pm_runtime_put(usb3_to_dev(usb3)); in renesas_usb3_stop()
2337 struct renesas_usb3 *usb3 = gadget_to_renesas_usb3(gadget); in renesas_usb3_pullup() local
2339 usb3->softconnect = !!is_on; in renesas_usb3_pullup()
2361 struct renesas_usb3 *usb3 = usb_role_switch_get_drvdata(sw); in renesas_usb3_role_switch_get() local
2364 pm_runtime_get_sync(usb3_to_dev(usb3)); in renesas_usb3_role_switch_get()
2365 cur_role = usb3_is_host(usb3) ? USB_ROLE_HOST : USB_ROLE_DEVICE; in renesas_usb3_role_switch_get()
2366 pm_runtime_put(usb3_to_dev(usb3)); in renesas_usb3_role_switch_get()
2374 struct renesas_usb3 *usb3 = dev_get_drvdata(dev); in handle_ext_role_switch_states() local
2375 struct device *host = usb3->host_dev; in handle_ext_role_switch_states()
2376 enum usb_role cur_role = renesas_usb3_role_switch_get(usb3->role_sw); in handle_ext_role_switch_states()
2380 usb3->connection_state = USB_ROLE_NONE; in handle_ext_role_switch_states()
2383 if (usb3->driver) in handle_ext_role_switch_states()
2384 usb3_disconnect(usb3); in handle_ext_role_switch_states()
2385 usb3_vbus_out(usb3, false); in handle_ext_role_switch_states()
2388 if (usb3->connection_state == USB_ROLE_NONE) { in handle_ext_role_switch_states()
2389 usb3->connection_state = USB_ROLE_DEVICE; in handle_ext_role_switch_states()
2390 usb3_set_mode(usb3, false); in handle_ext_role_switch_states()
2391 if (usb3->driver) in handle_ext_role_switch_states()
2392 usb3_connect(usb3); in handle_ext_role_switch_states()
2395 usb3_set_mode(usb3, false); in handle_ext_role_switch_states()
2396 if (usb3->driver) in handle_ext_role_switch_states()
2397 usb3_connect(usb3); in handle_ext_role_switch_states()
2399 usb3_vbus_out(usb3, false); in handle_ext_role_switch_states()
2402 if (usb3->connection_state == USB_ROLE_NONE) { in handle_ext_role_switch_states()
2403 if (usb3->driver) in handle_ext_role_switch_states()
2404 usb3_disconnect(usb3); in handle_ext_role_switch_states()
2406 usb3->connection_state = USB_ROLE_HOST; in handle_ext_role_switch_states()
2407 usb3_set_mode(usb3, true); in handle_ext_role_switch_states()
2408 usb3_vbus_out(usb3, true); in handle_ext_role_switch_states()
2412 usb3_disconnect(usb3); in handle_ext_role_switch_states()
2414 usb3_set_mode(usb3, true); in handle_ext_role_switch_states()
2428 struct renesas_usb3 *usb3 = dev_get_drvdata(dev); in handle_role_switch_states() local
2429 struct device *host = usb3->host_dev; in handle_role_switch_states()
2430 enum usb_role cur_role = renesas_usb3_role_switch_get(usb3->role_sw); in handle_role_switch_states()
2434 usb3_set_mode(usb3, false); in handle_role_switch_states()
2437 usb3_set_mode(usb3, true); in handle_role_switch_states()
2447 struct renesas_usb3 *usb3 = usb_role_switch_get_drvdata(sw); in renesas_usb3_role_switch_set() local
2449 pm_runtime_get_sync(usb3_to_dev(usb3)); in renesas_usb3_role_switch_set()
2451 if (usb3->role_sw_by_connector) in renesas_usb3_role_switch_set()
2452 handle_ext_role_switch_states(usb3_to_dev(usb3), role); in renesas_usb3_role_switch_set()
2454 handle_role_switch_states(usb3_to_dev(usb3), role); in renesas_usb3_role_switch_set()
2456 pm_runtime_put(usb3_to_dev(usb3)); in renesas_usb3_role_switch_set()
2464 struct renesas_usb3 *usb3 = dev_get_drvdata(dev); in role_store() local
2467 if (!usb3->driver) in role_store()
2470 if (usb3->forced_b_device) in role_store()
2480 if (new_mode_is_host == usb3_is_host(usb3)) in role_store()
2483 usb3_mode_config(usb3, new_mode_is_host, usb3_is_a_device(usb3)); in role_store()
2491 struct renesas_usb3 *usb3 = dev_get_drvdata(dev); in role_show() local
2493 if (!usb3->driver) in role_show()
2496 return sprintf(buf, "%s\n", usb3_is_host(usb3) ? "host" : "peripheral"); in role_show()
2502 struct renesas_usb3 *usb3 = s->private; in renesas_usb3_b_device_show() local
2504 seq_printf(s, "%d\n", usb3->forced_b_device); in renesas_usb3_b_device_show()
2519 struct renesas_usb3 *usb3 = s->private; in renesas_usb3_b_device_write() local
2522 if (!usb3->driver) in renesas_usb3_b_device_write()
2528 usb3->start_to_connect = false; in renesas_usb3_b_device_write()
2529 if (usb3->workaround_for_vbus && usb3->forced_b_device && in renesas_usb3_b_device_write()
2531 usb3->start_to_connect = true; in renesas_usb3_b_device_write()
2533 usb3->forced_b_device = true; in renesas_usb3_b_device_write()
2535 usb3->forced_b_device = false; in renesas_usb3_b_device_write()
2537 if (usb3->workaround_for_vbus) in renesas_usb3_b_device_write()
2538 usb3_disconnect(usb3); in renesas_usb3_b_device_write()
2541 usb3_check_id(usb3); in renesas_usb3_b_device_write()
2554 static void renesas_usb3_debugfs_init(struct renesas_usb3 *usb3, in renesas_usb3_debugfs_init() argument
2557 usb3->dentry = debugfs_create_dir(dev_name(dev), usb_debug_root); in renesas_usb3_debugfs_init()
2559 debugfs_create_file("b_device", 0644, usb3->dentry, usb3, in renesas_usb3_debugfs_init()
2566 struct renesas_usb3 *usb3 = platform_get_drvdata(pdev); in renesas_usb3_remove() local
2568 debugfs_remove_recursive(usb3->dentry); in renesas_usb3_remove()
2571 cancel_work_sync(&usb3->role_work); in renesas_usb3_remove()
2572 usb_role_switch_unregister(usb3->role_sw); in renesas_usb3_remove()
2574 usb_del_gadget_udc(&usb3->gadget); in renesas_usb3_remove()
2575 renesas_usb3_dma_free_prd(usb3, &pdev->dev); in renesas_usb3_remove()
2577 __renesas_usb3_ep_free_request(usb3->ep0_req); in renesas_usb3_remove()
2583 static int renesas_usb3_init_ep(struct renesas_usb3 *usb3, struct device *dev, in renesas_usb3_init_ep() argument
2590 usb3->num_usb3_eps = priv->ramsize_per_ramif * priv->num_ramif * 2 / in renesas_usb3_init_ep()
2593 if (usb3->num_usb3_eps > USB3_MAX_NUM_PIPES) in renesas_usb3_init_ep()
2594 usb3->num_usb3_eps = USB3_MAX_NUM_PIPES; in renesas_usb3_init_ep()
2596 usb3->usb3_ep = devm_kcalloc(dev, in renesas_usb3_init_ep()
2597 usb3->num_usb3_eps, sizeof(*usb3_ep), in renesas_usb3_init_ep()
2599 if (!usb3->usb3_ep) in renesas_usb3_init_ep()
2602 dev_dbg(dev, "%s: num_usb3_eps = %d\n", __func__, usb3->num_usb3_eps); in renesas_usb3_init_ep()
2608 usb3_for_each_ep(usb3_ep, usb3, i) { in renesas_usb3_init_ep()
2610 usb3_ep->usb3 = usb3; in renesas_usb3_init_ep()
2618 usb3->gadget.ep0 = &usb3_ep->ep; in renesas_usb3_init_ep()
2629 list_add_tail(&usb3_ep->ep.ep_list, &usb3->gadget.ep_list); in renesas_usb3_init_ep()
2641 static void renesas_usb3_init_ram(struct renesas_usb3 *usb3, struct device *dev, in renesas_usb3_init_ram() argument
2658 usb3_for_each_ep(usb3_ep, usb3, i) { in renesas_usb3_init_ram()
2713 .compatible = "renesas,r8a774c0-usb3-peri",
2716 .compatible = "renesas,r8a7795-usb3-peri",
2719 .compatible = "renesas,r8a77990-usb3-peri",
2722 .compatible = "renesas,rcar-gen3-usb3-peri",
2751 struct renesas_usb3 *usb3; in renesas_usb3_probe() local
2766 usb3 = devm_kzalloc(&pdev->dev, sizeof(*usb3), GFP_KERNEL); in renesas_usb3_probe()
2767 if (!usb3) in renesas_usb3_probe()
2770 usb3->reg = devm_platform_ioremap_resource(pdev, 0); in renesas_usb3_probe()
2771 if (IS_ERR(usb3->reg)) in renesas_usb3_probe()
2772 return PTR_ERR(usb3->reg); in renesas_usb3_probe()
2774 platform_set_drvdata(pdev, usb3); in renesas_usb3_probe()
2775 spin_lock_init(&usb3->lock); in renesas_usb3_probe()
2777 usb3->gadget.ops = &renesas_usb3_gadget_ops; in renesas_usb3_probe()
2778 usb3->gadget.name = udc_name; in renesas_usb3_probe()
2779 usb3->gadget.max_speed = USB_SPEED_SUPER; in renesas_usb3_probe()
2780 INIT_LIST_HEAD(&usb3->gadget.ep_list); in renesas_usb3_probe()
2781 ret = renesas_usb3_init_ep(usb3, &pdev->dev, priv); in renesas_usb3_probe()
2784 renesas_usb3_init_ram(usb3, &pdev->dev, priv); in renesas_usb3_probe()
2787 dev_name(&pdev->dev), usb3); in renesas_usb3_probe()
2791 INIT_WORK(&usb3->extcon_work, renesas_usb3_extcon_work); in renesas_usb3_probe()
2792 usb3->extcon = devm_extcon_dev_allocate(&pdev->dev, renesas_usb3_cable); in renesas_usb3_probe()
2793 if (IS_ERR(usb3->extcon)) in renesas_usb3_probe()
2794 return PTR_ERR(usb3->extcon); in renesas_usb3_probe()
2796 ret = devm_extcon_dev_register(&pdev->dev, usb3->extcon); in renesas_usb3_probe()
2803 usb3->ep0_req = __renesas_usb3_ep_alloc_request(GFP_KERNEL); in renesas_usb3_probe()
2804 if (!usb3->ep0_req) in renesas_usb3_probe()
2807 ret = renesas_usb3_dma_alloc_prd(usb3, &pdev->dev); in renesas_usb3_probe()
2815 usb3->phy = devm_phy_optional_get(&pdev->dev, "usb"); in renesas_usb3_probe()
2816 if (IS_ERR(usb3->phy)) { in renesas_usb3_probe()
2817 ret = PTR_ERR(usb3->phy); in renesas_usb3_probe()
2822 ret = usb_add_gadget_udc(&pdev->dev, &usb3->gadget); in renesas_usb3_probe()
2831 usb3->role_sw_by_connector = true; in renesas_usb3_probe()
2835 renesas_usb3_role_switch_desc.driver_data = usb3; in renesas_usb3_probe()
2837 INIT_WORK(&usb3->role_work, renesas_usb3_role_work); in renesas_usb3_probe()
2838 usb3->role_sw = usb_role_switch_register(&pdev->dev, in renesas_usb3_probe()
2840 if (!IS_ERR(usb3->role_sw)) { in renesas_usb3_probe()
2841 usb3->host_dev = usb_of_get_companion_dev(&pdev->dev); in renesas_usb3_probe()
2842 if (!usb3->host_dev) { in renesas_usb3_probe()
2844 usb_role_switch_unregister(usb3->role_sw); in renesas_usb3_probe()
2845 usb3->role_sw = NULL; in renesas_usb3_probe()
2848 usb3->role_sw = NULL; in renesas_usb3_probe()
2851 usb3->workaround_for_vbus = priv->workaround_for_vbus; in renesas_usb3_probe()
2853 renesas_usb3_debugfs_init(usb3, &pdev->dev); in renesas_usb3_probe()
2855 dev_info(&pdev->dev, "probed%s\n", usb3->phy ? " with phy" : ""); in renesas_usb3_probe()
2860 usb_del_gadget_udc(&usb3->gadget); in renesas_usb3_probe()
2863 renesas_usb3_dma_free_prd(usb3, &pdev->dev); in renesas_usb3_probe()
2866 __renesas_usb3_ep_free_request(usb3->ep0_req); in renesas_usb3_probe()
2874 struct renesas_usb3 *usb3 = dev_get_drvdata(dev); in renesas_usb3_suspend() local
2877 if (!usb3->driver) in renesas_usb3_suspend()
2880 renesas_usb3_stop_controller(usb3); in renesas_usb3_suspend()
2881 if (usb3->phy) in renesas_usb3_suspend()
2882 phy_exit(usb3->phy); in renesas_usb3_suspend()
2890 struct renesas_usb3 *usb3 = dev_get_drvdata(dev); in renesas_usb3_resume() local
2893 if (!usb3->driver) in renesas_usb3_resume()
2896 if (usb3->phy) in renesas_usb3_resume()
2897 phy_init(usb3->phy); in renesas_usb3_resume()
2899 renesas_usb3_init_controller(usb3); in renesas_usb3_resume()
2919 MODULE_DESCRIPTION("Renesas USB3.0 Peripheral driver");