Lines Matching +full:r8a7795 +full:- +full:usb3 +full:- +full:phy

1 // SPDX-License-Identifier: GPL-2.0
3 * Renesas USB3.0 Peripheral driver (USB gadget)
5 * Copyright (C) 2015-2017 Renesas Electronics Corporation
10 #include <linux/dma-mapping.h>
12 #include <linux/extcon-provider.h>
17 #include <linux/phy/phy.h>
36 #define USB3_DMA_CH0_CON(n) (0x030 + ((n) - 1) * 0x10) /* n = 1 to 4 */
37 #define USB3_DMA_CH0_PRD_ADR(n) (0x034 + ((n) - 1) * 0x10) /* n = 1 to 4 */
42 #define USB3_DRD_CON(p) ((p)->is_rzv2m ? 0x400 : 0x218)
49 #define USB3_USB_OTG_STA(p) ((p)->is_rzv2m ? 0x410 : 0x268)
50 #define USB3_USB_OTG_INT_STA(p) ((p)->is_rzv2m ? 0x414 : 0x26c)
51 #define USB3_USB_OTG_INT_ENA(p) ((p)->is_rzv2m ? 0x418 : 0x270)
76 #define AXI_INT_PRDEN_CLR_STA_SHIFT(n) (16 + (n) - 1)
77 #define AXI_INT_PRDERR_STA_SHIFT(n) (0 + (n) - 1)
161 #define USB_OTG_IDMON(p) ((p)->is_rzv2m ? BIT(0) : BIT(4))
261 #define USB3_MAX_NUM_PIPES(p) ((p)->is_rzv2m ? 16 : 6) /* This includes PIPE 0 */
265 * To avoid double-meaning of "0" (xferred 65536 bytes or received zlp if
315 struct renesas_usb3 *usb3; member
344 struct phy *phy; member
377 #define renesas_usb3_to_gadget(renesas_usb3) (&renesas_usb3->gadget)
378 #define usb3_to_dev(_usb3) (_usb3->gadget.dev.parent)
381 #define usb3_ep_to_usb3(_usb3_ep) (_usb3_ep->usb3)
385 #define usb3_get_ep(usb3, n) ((usb3)->usb3_ep + (n)) argument
386 #define usb3_for_each_ep(usb3_ep, usb3, i) \ argument
387 for ((i) = 0, usb3_ep = usb3_get_ep(usb3, (i)); \
388 (i) < (usb3)->num_usb3_eps; \
389 (i)++, usb3_ep = usb3_get_ep(usb3, (i)))
391 #define usb3_get_dma(usb3, i) (&(usb3)->dma[i]) argument
392 #define usb3_for_each_dma(usb3, dma, i) \ argument
393 for ((i) = 0, dma = usb3_get_dma((usb3), (i)); \
395 (i)++, dma = usb3_get_dma((usb3), (i)))
403 static void usb3_write(struct renesas_usb3 *usb3, u32 data, u32 offs) in usb3_write() argument
405 iowrite32(data, usb3->reg + offs); in usb3_write()
408 static u32 usb3_read(struct renesas_usb3 *usb3, u32 offs) in usb3_read() argument
410 return ioread32(usb3->reg + offs); in usb3_read()
413 static void usb3_set_bit(struct renesas_usb3 *usb3, u32 bits, u32 offs) in usb3_set_bit() argument
415 u32 val = usb3_read(usb3, offs); in usb3_set_bit()
418 usb3_write(usb3, val, offs); in usb3_set_bit()
421 static void usb3_clear_bit(struct renesas_usb3 *usb3, u32 bits, u32 offs) in usb3_clear_bit() argument
423 u32 val = usb3_read(usb3, offs); in usb3_clear_bit()
426 usb3_write(usb3, val, offs); in usb3_clear_bit()
429 static int usb3_wait(struct renesas_usb3 *usb3, u32 reg, u32 mask, in usb3_wait() argument
435 if ((usb3_read(usb3, reg) & mask) == expected) in usb3_wait()
440 dev_dbg(usb3_to_dev(usb3), "%s: timed out (%8x, %08x, %08x)\n", in usb3_wait()
443 return -EBUSY; in usb3_wait()
448 struct renesas_usb3 *usb3 = container_of(work, struct renesas_usb3, in renesas_usb3_extcon_work() local
451 extcon_set_state_sync(usb3->extcon, EXTCON_USB_HOST, usb3->extcon_host); in renesas_usb3_extcon_work()
452 extcon_set_state_sync(usb3->extcon, EXTCON_USB, usb3->extcon_usb); in renesas_usb3_extcon_work()
455 static void usb3_enable_irq_1(struct renesas_usb3 *usb3, u32 bits) in usb3_enable_irq_1() argument
457 usb3_set_bit(usb3, bits, USB3_USB_INT_ENA_1); in usb3_enable_irq_1()
460 static void usb3_disable_irq_1(struct renesas_usb3 *usb3, u32 bits) in usb3_disable_irq_1() argument
462 usb3_clear_bit(usb3, bits, USB3_USB_INT_ENA_1); in usb3_disable_irq_1()
465 static void usb3_enable_pipe_irq(struct renesas_usb3 *usb3, int num) in usb3_enable_pipe_irq() argument
467 usb3_set_bit(usb3, USB_INT_2_PIPE(num), USB3_USB_INT_ENA_2); in usb3_enable_pipe_irq()
470 static void usb3_disable_pipe_irq(struct renesas_usb3 *usb3, int num) in usb3_disable_pipe_irq() argument
472 usb3_clear_bit(usb3, USB_INT_2_PIPE(num), USB3_USB_INT_ENA_2); in usb3_disable_pipe_irq()
475 static bool usb3_is_host(struct renesas_usb3 *usb3) in usb3_is_host() argument
477 return !(usb3_read(usb3, USB3_DRD_CON(usb3)) & DRD_CON_PERI_CON); in usb3_is_host()
480 static void usb3_init_axi_bridge(struct renesas_usb3 *usb3) in usb3_init_axi_bridge() argument
483 usb3_write(usb3, ~0, USB3_DMA_INT_STA); in usb3_init_axi_bridge()
484 usb3_write(usb3, 0, USB3_DMA_INT_ENA); in usb3_init_axi_bridge()
485 usb3_set_bit(usb3, AXI_INT_DMAINT | AXI_INT_EPCINT, USB3_AXI_INT_ENA); in usb3_init_axi_bridge()
488 static void usb3_init_epc_registers(struct renesas_usb3 *usb3) in usb3_init_epc_registers() argument
490 usb3_write(usb3, ~0, USB3_USB_INT_STA_1); in usb3_init_epc_registers()
491 if (!usb3->workaround_for_vbus) in usb3_init_epc_registers()
492 usb3_enable_irq_1(usb3, USB_INT_1_VBUS_CNG); in usb3_init_epc_registers()
495 static bool usb3_wakeup_usb2_phy(struct renesas_usb3 *usb3) in usb3_wakeup_usb2_phy() argument
497 if (!(usb3_read(usb3, USB3_USB20_CON) & USB20_CON_B2_SUSPEND)) in usb3_wakeup_usb2_phy()
500 usb3_clear_bit(usb3, USB20_CON_B2_SUSPEND, USB3_USB20_CON); in usb3_wakeup_usb2_phy()
501 usb3_enable_irq_1(usb3, USB_INT_1_B2_RSUM); in usb3_wakeup_usb2_phy()
506 static void usb3_usb2_pullup(struct renesas_usb3 *usb3, int pullup) in usb3_usb2_pullup() argument
510 if (usb3->softconnect && pullup) in usb3_usb2_pullup()
511 usb3_set_bit(usb3, bits, USB3_USB20_CON); in usb3_usb2_pullup()
513 usb3_clear_bit(usb3, bits, USB3_USB20_CON); in usb3_usb2_pullup()
516 static void usb3_set_test_mode(struct renesas_usb3 *usb3) in usb3_set_test_mode() argument
518 u32 val = usb3_read(usb3, USB3_USB20_CON); in usb3_set_test_mode()
521 val |= USB20_CON_B2_TSTMOD(usb3->test_mode); in usb3_set_test_mode()
522 usb3_write(usb3, val | USB20_CON_B2_TSTMOD_EN, USB3_USB20_CON); in usb3_set_test_mode()
523 if (!usb3->test_mode) in usb3_set_test_mode()
524 usb3_clear_bit(usb3, USB20_CON_B2_TSTMOD_EN, USB3_USB20_CON); in usb3_set_test_mode()
527 static void usb3_start_usb2_connection(struct renesas_usb3 *usb3) in usb3_start_usb2_connection() argument
529 usb3->disabled_count++; in usb3_start_usb2_connection()
530 usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_start_usb2_connection()
531 usb3_set_bit(usb3, USB_COM_CON_SPD_MODE, USB3_USB_COM_CON); in usb3_start_usb2_connection()
532 usb3_usb2_pullup(usb3, 1); in usb3_start_usb2_connection()
535 static int usb3_is_usb3_phy_in_u3(struct renesas_usb3 *usb3) in usb3_is_usb3_phy_in_u3() argument
537 return usb3_read(usb3, USB3_USB30_CON) & USB30_CON_POW_SEL_IN_U3; in usb3_is_usb3_phy_in_u3()
540 static bool usb3_wakeup_usb3_phy(struct renesas_usb3 *usb3) in usb3_wakeup_usb3_phy() argument
542 if (!usb3_is_usb3_phy_in_u3(usb3)) in usb3_wakeup_usb3_phy()
545 usb3_set_bit(usb3, USB30_CON_B3_PLLWAKE, USB3_USB30_CON); in usb3_wakeup_usb3_phy()
546 usb3_enable_irq_1(usb3, USB_INT_1_B3_PLLWKUP); in usb3_wakeup_usb3_phy()
551 static u16 usb3_feature_get_un_enabled(struct renesas_usb3 *usb3) in usb3_feature_get_un_enabled() argument
555 u32 val = usb3_read(usb3, USB3_SSIFCMD); in usb3_feature_get_un_enabled()
567 static void usb3_feature_u2_enable(struct renesas_usb3 *usb3, bool enable) in usb3_feature_u2_enable() argument
573 usb3_clear_bit(usb3, bits, USB3_SSIFCMD); in usb3_feature_u2_enable()
575 usb3_set_bit(usb3, bits, USB3_SSIFCMD); in usb3_feature_u2_enable()
578 static void usb3_feature_u1_enable(struct renesas_usb3 *usb3, bool enable) in usb3_feature_u1_enable() argument
584 usb3_clear_bit(usb3, bits, USB3_SSIFCMD); in usb3_feature_u1_enable()
586 usb3_set_bit(usb3, bits, USB3_SSIFCMD); in usb3_feature_u1_enable()
589 static void usb3_start_operation_for_usb3(struct renesas_usb3 *usb3) in usb3_start_operation_for_usb3() argument
591 usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_start_operation_for_usb3()
592 usb3_clear_bit(usb3, USB_COM_CON_SPD_MODE, USB3_USB_COM_CON); in usb3_start_operation_for_usb3()
593 usb3_set_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); in usb3_start_operation_for_usb3()
596 static void usb3_start_usb3_connection(struct renesas_usb3 *usb3) in usb3_start_usb3_connection() argument
598 usb3_start_operation_for_usb3(usb3); in usb3_start_usb3_connection()
599 usb3_set_bit(usb3, USB_COM_CON_RX_DETECTION, USB3_USB_COM_CON); in usb3_start_usb3_connection()
601 usb3_enable_irq_1(usb3, USB_INT_1_B3_LUPSUCS | USB_INT_1_B3_DISABLE | in usb3_start_usb3_connection()
605 static void usb3_stop_usb3_connection(struct renesas_usb3 *usb3) in usb3_stop_usb3_connection() argument
607 usb3_clear_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); in usb3_stop_usb3_connection()
610 static void usb3_transition_to_default_state(struct renesas_usb3 *usb3, in usb3_transition_to_default_state() argument
613 usb3_set_bit(usb3, USB_INT_2_PIPE(0), USB3_USB_INT_ENA_2); in usb3_transition_to_default_state()
614 usb3_write(usb3, P0_INT_ALL_BITS, USB3_P0_INT_STA); in usb3_transition_to_default_state()
615 usb3_set_bit(usb3, P0_INT_ALL_BITS, USB3_P0_INT_ENA); in usb3_transition_to_default_state()
618 usb3_enable_irq_1(usb3, USB_INT_1_B3_WRMRST | in usb3_transition_to_default_state()
621 usb3_enable_irq_1(usb3, USB_INT_1_B2_SPND | in usb3_transition_to_default_state()
625 static void usb3_connect(struct renesas_usb3 *usb3) in usb3_connect() argument
627 if (usb3_wakeup_usb3_phy(usb3)) in usb3_connect()
628 usb3_start_usb3_connection(usb3); in usb3_connect()
631 static void usb3_reset_epc(struct renesas_usb3 *usb3) in usb3_reset_epc() argument
633 usb3_clear_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); in usb3_reset_epc()
634 usb3_clear_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_reset_epc()
635 usb3_set_bit(usb3, USB_COM_CON_PIPE_CLR, USB3_USB_COM_CON); in usb3_reset_epc()
636 usb3->test_mode = 0; in usb3_reset_epc()
637 usb3_set_test_mode(usb3); in usb3_reset_epc()
640 static void usb3_disconnect(struct renesas_usb3 *usb3) in usb3_disconnect() argument
642 usb3->disabled_count = 0; in usb3_disconnect()
643 usb3_usb2_pullup(usb3, 0); in usb3_disconnect()
644 usb3_clear_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); in usb3_disconnect()
645 usb3_reset_epc(usb3); in usb3_disconnect()
646 usb3_disable_irq_1(usb3, USB_INT_1_B2_RSUM | USB_INT_1_B3_PLLWKUP | in usb3_disconnect()
651 usb3_clear_bit(usb3, USB_COM_CON_SPD_MODE, USB3_USB_COM_CON); in usb3_disconnect()
652 usb3_init_epc_registers(usb3); in usb3_disconnect()
654 if (usb3->driver) in usb3_disconnect()
655 usb3->driver->disconnect(&usb3->gadget); in usb3_disconnect()
658 static void usb3_check_vbus(struct renesas_usb3 *usb3) in usb3_check_vbus() argument
660 if (usb3->workaround_for_vbus) { in usb3_check_vbus()
661 usb3_connect(usb3); in usb3_check_vbus()
663 usb3->extcon_usb = !!(usb3_read(usb3, USB3_USB_STA) & in usb3_check_vbus()
665 if (usb3->extcon_usb) in usb3_check_vbus()
666 usb3_connect(usb3); in usb3_check_vbus()
668 usb3_disconnect(usb3); in usb3_check_vbus()
670 schedule_work(&usb3->extcon_work); in usb3_check_vbus()
676 struct renesas_usb3 *usb3 = in renesas_usb3_role_work() local
679 usb_role_switch_set_role(usb3->role_sw, usb3->role); in renesas_usb3_role_work()
682 static void usb3_set_mode(struct renesas_usb3 *usb3, bool host) in usb3_set_mode() argument
684 if (usb3->is_rzv2m) { in usb3_set_mode()
686 usb3_set_bit(usb3, DRD_CON_PERI_RST, USB3_DRD_CON(usb3)); in usb3_set_mode()
687 usb3_clear_bit(usb3, DRD_CON_HOST_RST, USB3_DRD_CON(usb3)); in usb3_set_mode()
689 usb3_set_bit(usb3, DRD_CON_HOST_RST, USB3_DRD_CON(usb3)); in usb3_set_mode()
690 usb3_clear_bit(usb3, DRD_CON_PERI_RST, USB3_DRD_CON(usb3)); in usb3_set_mode()
695 usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON(usb3)); in usb3_set_mode()
697 usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON(usb3)); in usb3_set_mode()
700 static void usb3_set_mode_by_role_sw(struct renesas_usb3 *usb3, bool host) in usb3_set_mode_by_role_sw() argument
702 if (usb3->role_sw) { in usb3_set_mode_by_role_sw()
703 usb3->role = host ? USB_ROLE_HOST : USB_ROLE_DEVICE; in usb3_set_mode_by_role_sw()
704 schedule_work(&usb3->role_work); in usb3_set_mode_by_role_sw()
706 usb3_set_mode(usb3, host); in usb3_set_mode_by_role_sw()
710 static void usb3_vbus_out(struct renesas_usb3 *usb3, bool enable) in usb3_vbus_out() argument
713 usb3_set_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON(usb3)); in usb3_vbus_out()
715 usb3_clear_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON(usb3)); in usb3_vbus_out()
718 static void usb3_mode_config(struct renesas_usb3 *usb3, bool host, bool a_dev) in usb3_mode_config() argument
722 spin_lock_irqsave(&usb3->lock, flags); in usb3_mode_config()
723 if (!usb3->role_sw_by_connector || in usb3_mode_config()
724 usb3->connection_state != USB_ROLE_NONE) { in usb3_mode_config()
725 usb3_set_mode_by_role_sw(usb3, host); in usb3_mode_config()
726 usb3_vbus_out(usb3, a_dev); in usb3_mode_config()
728 /* for A-Peripheral or forced B-device mode */ in usb3_mode_config()
729 if ((!host && a_dev) || usb3->start_to_connect) in usb3_mode_config()
730 usb3_connect(usb3); in usb3_mode_config()
731 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_mode_config()
734 static bool usb3_is_a_device(struct renesas_usb3 *usb3) in usb3_is_a_device() argument
736 return !(usb3_read(usb3, USB3_USB_OTG_STA(usb3)) & USB_OTG_IDMON(usb3)); in usb3_is_a_device()
739 static void usb3_check_id(struct renesas_usb3 *usb3) in usb3_check_id() argument
741 usb3->extcon_host = usb3_is_a_device(usb3); in usb3_check_id()
743 if ((!usb3->role_sw_by_connector && usb3->extcon_host && in usb3_check_id()
744 !usb3->forced_b_device) || usb3->connection_state == USB_ROLE_HOST) in usb3_check_id()
745 usb3_mode_config(usb3, true, true); in usb3_check_id()
747 usb3_mode_config(usb3, false, false); in usb3_check_id()
749 schedule_work(&usb3->extcon_work); in usb3_check_id()
752 static void renesas_usb3_init_controller(struct renesas_usb3 *usb3) in renesas_usb3_init_controller() argument
754 usb3_init_axi_bridge(usb3); in renesas_usb3_init_controller()
755 usb3_init_epc_registers(usb3); in renesas_usb3_init_controller()
756 usb3_set_bit(usb3, USB_COM_CON_PN_WDATAIF_NL | in renesas_usb3_init_controller()
759 usb3_write(usb3, USB_OTG_IDMON(usb3), USB3_USB_OTG_INT_STA(usb3)); in renesas_usb3_init_controller()
760 usb3_write(usb3, USB_OTG_IDMON(usb3), USB3_USB_OTG_INT_ENA(usb3)); in renesas_usb3_init_controller()
762 usb3_check_id(usb3); in renesas_usb3_init_controller()
763 usb3_check_vbus(usb3); in renesas_usb3_init_controller()
766 static void renesas_usb3_stop_controller(struct renesas_usb3 *usb3) in renesas_usb3_stop_controller() argument
768 usb3_disconnect(usb3); in renesas_usb3_stop_controller()
769 usb3_write(usb3, 0, USB3_P0_INT_ENA); in renesas_usb3_stop_controller()
770 usb3_write(usb3, 0, USB3_USB_OTG_INT_ENA(usb3)); in renesas_usb3_stop_controller()
771 usb3_write(usb3, 0, USB3_USB_INT_ENA_1); in renesas_usb3_stop_controller()
772 usb3_write(usb3, 0, USB3_USB_INT_ENA_2); in renesas_usb3_stop_controller()
773 usb3_write(usb3, 0, USB3_AXI_INT_ENA); in renesas_usb3_stop_controller()
776 static void usb3_irq_epc_int_1_pll_wakeup(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_pll_wakeup() argument
778 usb3_disable_irq_1(usb3, USB_INT_1_B3_PLLWKUP); in usb3_irq_epc_int_1_pll_wakeup()
779 usb3_clear_bit(usb3, USB30_CON_B3_PLLWAKE, USB3_USB30_CON); in usb3_irq_epc_int_1_pll_wakeup()
780 usb3_start_usb3_connection(usb3); in usb3_irq_epc_int_1_pll_wakeup()
783 static void usb3_irq_epc_int_1_linkup_success(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_linkup_success() argument
785 usb3_transition_to_default_state(usb3, true); in usb3_irq_epc_int_1_linkup_success()
788 static void usb3_irq_epc_int_1_resume(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_resume() argument
790 usb3_disable_irq_1(usb3, USB_INT_1_B2_RSUM); in usb3_irq_epc_int_1_resume()
791 usb3_start_usb2_connection(usb3); in usb3_irq_epc_int_1_resume()
792 usb3_transition_to_default_state(usb3, false); in usb3_irq_epc_int_1_resume()
795 static void usb3_irq_epc_int_1_suspend(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_suspend() argument
797 usb3_disable_irq_1(usb3, USB_INT_1_B2_SPND); in usb3_irq_epc_int_1_suspend()
799 if (usb3->gadget.speed != USB_SPEED_UNKNOWN && in usb3_irq_epc_int_1_suspend()
800 usb3->gadget.state != USB_STATE_NOTATTACHED) { in usb3_irq_epc_int_1_suspend()
801 if (usb3->driver && usb3->driver->suspend) in usb3_irq_epc_int_1_suspend()
802 usb3->driver->suspend(&usb3->gadget); in usb3_irq_epc_int_1_suspend()
803 usb_gadget_set_state(&usb3->gadget, USB_STATE_SUSPENDED); in usb3_irq_epc_int_1_suspend()
807 static void usb3_irq_epc_int_1_disable(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_disable() argument
809 usb3_stop_usb3_connection(usb3); in usb3_irq_epc_int_1_disable()
810 if (usb3_wakeup_usb2_phy(usb3)) in usb3_irq_epc_int_1_disable()
811 usb3_irq_epc_int_1_resume(usb3); in usb3_irq_epc_int_1_disable()
814 static void usb3_irq_epc_int_1_bus_reset(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_bus_reset() argument
816 usb3_reset_epc(usb3); in usb3_irq_epc_int_1_bus_reset()
817 if (usb3->disabled_count < 3) in usb3_irq_epc_int_1_bus_reset()
818 usb3_start_usb3_connection(usb3); in usb3_irq_epc_int_1_bus_reset()
820 usb3_start_usb2_connection(usb3); in usb3_irq_epc_int_1_bus_reset()
823 static void usb3_irq_epc_int_1_vbus_change(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_vbus_change() argument
825 usb3_check_vbus(usb3); in usb3_irq_epc_int_1_vbus_change()
828 static void usb3_irq_epc_int_1_hot_reset(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_hot_reset() argument
830 usb3_reset_epc(usb3); in usb3_irq_epc_int_1_hot_reset()
831 usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_irq_epc_int_1_hot_reset()
834 usb3_set_bit(usb3, USB30_CON_B3_HOTRST_CMP, USB3_USB30_CON); in usb3_irq_epc_int_1_hot_reset()
837 static void usb3_irq_epc_int_1_warm_reset(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_warm_reset() argument
839 usb3_reset_epc(usb3); in usb3_irq_epc_int_1_warm_reset()
840 usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_irq_epc_int_1_warm_reset()
842 usb3_start_operation_for_usb3(usb3); in usb3_irq_epc_int_1_warm_reset()
843 usb3_enable_irq_1(usb3, USB_INT_1_SPEED); in usb3_irq_epc_int_1_warm_reset()
846 static void usb3_irq_epc_int_1_speed(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_speed() argument
848 u32 speed = usb3_read(usb3, USB3_USB_STA) & USB_STA_SPEED_MASK; in usb3_irq_epc_int_1_speed()
852 usb3->gadget.speed = USB_SPEED_SUPER; in usb3_irq_epc_int_1_speed()
853 usb3->gadget.ep0->maxpacket = USB3_EP0_SS_MAX_PACKET_SIZE; in usb3_irq_epc_int_1_speed()
856 usb3->gadget.speed = USB_SPEED_HIGH; in usb3_irq_epc_int_1_speed()
857 usb3->gadget.ep0->maxpacket = USB3_EP0_HSFS_MAX_PACKET_SIZE; in usb3_irq_epc_int_1_speed()
860 usb3->gadget.speed = USB_SPEED_FULL; in usb3_irq_epc_int_1_speed()
861 usb3->gadget.ep0->maxpacket = USB3_EP0_HSFS_MAX_PACKET_SIZE; in usb3_irq_epc_int_1_speed()
864 usb3->gadget.speed = USB_SPEED_UNKNOWN; in usb3_irq_epc_int_1_speed()
869 static void usb3_irq_epc_int_1(struct renesas_usb3 *usb3, u32 int_sta_1) in usb3_irq_epc_int_1() argument
872 usb3_irq_epc_int_1_pll_wakeup(usb3); in usb3_irq_epc_int_1()
875 usb3_irq_epc_int_1_linkup_success(usb3); in usb3_irq_epc_int_1()
878 usb3_irq_epc_int_1_hot_reset(usb3); in usb3_irq_epc_int_1()
881 usb3_irq_epc_int_1_warm_reset(usb3); in usb3_irq_epc_int_1()
884 usb3_irq_epc_int_1_disable(usb3); in usb3_irq_epc_int_1()
887 usb3_irq_epc_int_1_bus_reset(usb3); in usb3_irq_epc_int_1()
890 usb3_irq_epc_int_1_resume(usb3); in usb3_irq_epc_int_1()
893 usb3_irq_epc_int_1_suspend(usb3); in usb3_irq_epc_int_1()
896 usb3_irq_epc_int_1_speed(usb3); in usb3_irq_epc_int_1()
899 usb3_irq_epc_int_1_vbus_change(usb3); in usb3_irq_epc_int_1()
905 return list_first_entry_or_null(&usb3_ep->queue, in __usb3_get_request()
912 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_get_request() local
916 spin_lock_irqsave(&usb3->lock, flags); in usb3_get_request()
918 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_get_request()
927 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in __usb3_request_done() local
929 dev_dbg(usb3_to_dev(usb3), "giveback: ep%2d, %u, %u, %d\n", in __usb3_request_done()
930 usb3_ep->num, usb3_req->req.length, usb3_req->req.actual, in __usb3_request_done()
932 usb3_req->req.status = status; in __usb3_request_done()
933 usb3_ep->started = false; in __usb3_request_done()
934 list_del_init(&usb3_req->queue); in __usb3_request_done()
935 spin_unlock(&usb3->lock); in __usb3_request_done()
936 usb_gadget_giveback_request(&usb3_ep->ep, &usb3_req->req); in __usb3_request_done()
937 spin_lock(&usb3->lock); in __usb3_request_done()
943 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_request_done() local
946 spin_lock_irqsave(&usb3->lock, flags); in usb3_request_done()
948 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_request_done()
951 static void usb3_irq_epc_pipe0_status_end(struct renesas_usb3 *usb3) in usb3_irq_epc_pipe0_status_end() argument
953 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_irq_epc_pipe0_status_end()
958 if (usb3->test_mode) in usb3_irq_epc_pipe0_status_end()
959 usb3_set_test_mode(usb3); in usb3_irq_epc_pipe0_status_end()
962 static void usb3_get_setup_data(struct renesas_usb3 *usb3, in usb3_get_setup_data() argument
965 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_get_setup_data()
968 *data++ = usb3_read(usb3, USB3_STUP_DAT_0); in usb3_get_setup_data()
969 *data = usb3_read(usb3, USB3_STUP_DAT_1); in usb3_get_setup_data()
972 usb3_ep->dir_in = !!(ctrl->bRequestType & USB_DIR_IN); in usb3_get_setup_data()
975 static void usb3_set_p0_con_update_res(struct renesas_usb3 *usb3, u32 res) in usb3_set_p0_con_update_res() argument
977 u32 val = usb3_read(usb3, USB3_P0_CON); in usb3_set_p0_con_update_res()
981 usb3_write(usb3, val, USB3_P0_CON); in usb3_set_p0_con_update_res()
984 static void usb3_set_p0_con_for_ctrl_read_data(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_ctrl_read_data() argument
986 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | in usb3_set_p0_con_for_ctrl_read_data()
991 static void usb3_set_p0_con_for_ctrl_read_status(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_ctrl_read_status() argument
993 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | in usb3_set_p0_con_for_ctrl_read_status()
998 static void usb3_set_p0_con_for_ctrl_write_data(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_ctrl_write_data() argument
1000 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | in usb3_set_p0_con_for_ctrl_write_data()
1005 static void usb3_set_p0_con_for_ctrl_write_status(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_ctrl_write_status() argument
1007 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | in usb3_set_p0_con_for_ctrl_write_status()
1012 static void usb3_set_p0_con_for_no_data(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_no_data() argument
1014 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | in usb3_set_p0_con_for_no_data()
1019 static void usb3_set_p0_con_stall(struct renesas_usb3 *usb3) in usb3_set_p0_con_stall() argument
1021 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_STALL | in usb3_set_p0_con_stall()
1026 static void usb3_set_p0_con_stop(struct renesas_usb3 *usb3) in usb3_set_p0_con_stop() argument
1028 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | in usb3_set_p0_con_stop()
1033 static int usb3_pn_change(struct renesas_usb3 *usb3, int num) in usb3_pn_change() argument
1035 if (num == 0 || num > usb3->num_usb3_eps) in usb3_pn_change()
1036 return -ENXIO; in usb3_pn_change()
1038 usb3_write(usb3, num, USB3_PIPE_COM); in usb3_pn_change()
1043 static void usb3_set_pn_con_update_res(struct renesas_usb3 *usb3, u32 res) in usb3_set_pn_con_update_res() argument
1045 u32 val = usb3_read(usb3, USB3_PN_CON); in usb3_set_pn_con_update_res()
1050 usb3_write(usb3, val, USB3_PN_CON); in usb3_set_pn_con_update_res()
1053 static void usb3_pn_start(struct renesas_usb3 *usb3) in usb3_pn_start() argument
1055 usb3_set_pn_con_update_res(usb3, PN_CON_RES_NORMAL); in usb3_pn_start()
1058 static void usb3_pn_stop(struct renesas_usb3 *usb3) in usb3_pn_stop() argument
1060 usb3_set_pn_con_update_res(usb3, PN_CON_RES_FORCE_NRDY); in usb3_pn_stop()
1063 static void usb3_pn_stall(struct renesas_usb3 *usb3) in usb3_pn_stall() argument
1065 usb3_set_pn_con_update_res(usb3, PN_CON_RES_FORCE_STALL); in usb3_pn_stall()
1068 static int usb3_pn_con_clear(struct renesas_usb3 *usb3) in usb3_pn_con_clear() argument
1070 usb3_set_bit(usb3, PN_CON_CLR, USB3_PN_CON); in usb3_pn_con_clear()
1072 return usb3_wait(usb3, USB3_PN_CON, PN_CON_CLR, 0); in usb3_pn_con_clear()
1078 struct usb_request *req = &usb3_req->req; in usb3_is_transfer_complete()
1080 if ((!req->zero && req->actual == req->length) || in usb3_is_transfer_complete()
1081 (req->actual % usb3_ep->ep.maxpacket) || (req->length == 0)) in usb3_is_transfer_complete()
1089 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_wait_pipe_status() local
1090 u32 sta_reg = usb3_ep->num ? USB3_PN_STA : USB3_P0_STA; in usb3_wait_pipe_status()
1092 return usb3_wait(usb3, sta_reg, mask, mask); in usb3_wait_pipe_status()
1098 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_set_px_con_send() local
1099 u32 con_reg = usb3_ep->num ? USB3_PN_CON : USB3_P0_CON; in usb3_set_px_con_send()
1100 u32 val = usb3_read(usb3, con_reg); in usb3_set_px_con_send()
1103 val |= (usb3_ep->num && last) ? PN_CON_LAST : 0; in usb3_set_px_con_send()
1104 usb3_write(usb3, val, con_reg); in usb3_set_px_con_send()
1111 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_write_pipe() local
1113 int len = min_t(unsigned, usb3_req->req.length - usb3_req->req.actual, in usb3_write_pipe()
1114 usb3_ep->ep.maxpacket); in usb3_write_pipe()
1115 u8 *buf = usb3_req->req.buf + usb3_req->req.actual; in usb3_write_pipe()
1120 return -EBUSY; in usb3_write_pipe()
1123 usb3_req->req.actual += len; in usb3_write_pipe()
1127 iowrite32_rep(usb3->reg + fifo_reg, buf, len / 4); in usb3_write_pipe()
1135 usb3_write(usb3, tmp, fifo_reg); in usb3_write_pipe()
1143 return is_last ? 0 : -EAGAIN; in usb3_write_pipe()
1148 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_get_received_length() local
1149 u32 lng_reg = usb3_ep->num ? USB3_PN_LNG : USB3_P0_LNG; in usb3_get_received_length()
1151 return usb3_read(usb3, lng_reg); in usb3_get_received_length()
1157 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_read_pipe() local
1159 int len = min_t(unsigned, usb3_req->req.length - usb3_req->req.actual, in usb3_read_pipe()
1161 u8 *buf = usb3_req->req.buf + usb3_req->req.actual; in usb3_read_pipe()
1168 usb3_req->req.actual += len; in usb3_read_pipe()
1172 ioread32_rep(usb3->reg + fifo_reg, buf, len / 4); in usb3_read_pipe()
1178 tmp = usb3_read(usb3, fifo_reg); in usb3_read_pipe()
1183 return usb3_is_transfer_complete(usb3_ep, usb3_req) ? 0 : -EAGAIN; in usb3_read_pipe()
1189 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_set_status_stage() local
1191 if (usb3_ep->dir_in) { in usb3_set_status_stage()
1192 usb3_set_p0_con_for_ctrl_read_status(usb3); in usb3_set_status_stage()
1194 if (!usb3_req->req.length) in usb3_set_status_stage()
1195 usb3_set_p0_con_for_no_data(usb3); in usb3_set_status_stage()
1197 usb3_set_p0_con_for_ctrl_write_status(usb3); in usb3_set_status_stage()
1206 if (usb3_ep->dir_in) in usb3_p0_xfer()
1218 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_start_pipe0() local
1220 if (usb3_ep->started) in usb3_start_pipe0()
1223 usb3_ep->started = true; in usb3_start_pipe0()
1225 if (usb3_ep->dir_in) { in usb3_start_pipe0()
1226 usb3_set_bit(usb3, P0_MOD_DIR, USB3_P0_MOD); in usb3_start_pipe0()
1227 usb3_set_p0_con_for_ctrl_read_data(usb3); in usb3_start_pipe0()
1229 usb3_clear_bit(usb3, P0_MOD_DIR, USB3_P0_MOD); in usb3_start_pipe0()
1230 if (usb3_req->req.length) in usb3_start_pipe0()
1231 usb3_set_p0_con_for_ctrl_write_data(usb3); in usb3_start_pipe0()
1237 static void usb3_enable_dma_pipen(struct renesas_usb3 *usb3) in usb3_enable_dma_pipen() argument
1239 usb3_set_bit(usb3, PN_CON_DATAIF_EN, USB3_PN_CON); in usb3_enable_dma_pipen()
1242 static void usb3_disable_dma_pipen(struct renesas_usb3 *usb3) in usb3_disable_dma_pipen() argument
1244 usb3_clear_bit(usb3, PN_CON_DATAIF_EN, USB3_PN_CON); in usb3_disable_dma_pipen()
1247 static void usb3_enable_dma_irq(struct renesas_usb3 *usb3, int num) in usb3_enable_dma_irq() argument
1249 usb3_set_bit(usb3, DMA_INT(num), USB3_DMA_INT_ENA); in usb3_enable_dma_irq()
1252 static void usb3_disable_dma_irq(struct renesas_usb3 *usb3, int num) in usb3_disable_dma_irq() argument
1254 usb3_clear_bit(usb3, DMA_INT(num), USB3_DMA_INT_ENA); in usb3_disable_dma_irq()
1259 switch (usb3_ep->ep.maxpacket) { in usb3_dma_mps_to_prd_word1()
1280 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_dma_get_setting_area() local
1285 if (usb3_req->req.length > USB3_DMA_MAX_XFER_SIZE_ALL_PRDS) { in usb3_dma_get_setting_area()
1286 dev_dbg(usb3_to_dev(usb3), "%s: the length is too big (%d)\n", in usb3_dma_get_setting_area()
1287 __func__, usb3_req->req.length); in usb3_dma_get_setting_area()
1291 /* The driver doesn't handle zero-length packet via dmac */ in usb3_dma_get_setting_area()
1292 if (!usb3_req->req.length) in usb3_dma_get_setting_area()
1298 usb3_for_each_dma(usb3, dma, i) { in usb3_dma_get_setting_area()
1299 if (dma->used) in usb3_dma_get_setting_area()
1302 if (usb_gadget_map_request(&usb3->gadget, &usb3_req->req, in usb3_dma_get_setting_area()
1303 usb3_ep->dir_in) < 0) in usb3_dma_get_setting_area()
1306 dma->used = true; in usb3_dma_get_setting_area()
1307 usb3_ep->dma = dma; in usb3_dma_get_setting_area()
1318 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_dma_put_setting_area() local
1322 usb3_for_each_dma(usb3, dma, i) { in usb3_dma_put_setting_area()
1323 if (usb3_ep->dma == dma) { in usb3_dma_put_setting_area()
1324 usb_gadget_unmap_request(&usb3->gadget, &usb3_req->req, in usb3_dma_put_setting_area()
1325 usb3_ep->dir_in); in usb3_dma_put_setting_area()
1326 dma->used = false; in usb3_dma_put_setting_area()
1327 usb3_ep->dma = NULL; in usb3_dma_put_setting_area()
1336 struct renesas_usb3_prd *cur_prd = usb3_ep->dma->prd; in usb3_dma_fill_prd()
1337 u32 remain = usb3_req->req.length; in usb3_dma_fill_prd()
1338 u32 dma = usb3_req->req.dma; in usb3_dma_fill_prd()
1345 cur_prd->word1 = usb3_dma_mps_to_prd_word1(usb3_ep) | in usb3_dma_fill_prd()
1347 cur_prd->bap = dma; in usb3_dma_fill_prd()
1348 remain -= len; in usb3_dma_fill_prd()
1357 cur_prd->word1 |= USB3_PRD1_E | USB3_PRD1_INT; in usb3_dma_fill_prd()
1358 if (usb3_ep->dir_in) in usb3_dma_fill_prd()
1359 cur_prd->word1 |= USB3_PRD1_LST; in usb3_dma_fill_prd()
1364 struct renesas_usb3_dma *dma = usb3_ep->dma; in usb3_dma_kick_prd()
1365 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_dma_kick_prd() local
1366 u32 dma_con = DMA_COM_PIPE_NO(usb3_ep->num) | DMA_CON_PRD_EN; in usb3_dma_kick_prd()
1368 if (usb3_ep->dir_in) in usb3_dma_kick_prd()
1373 usb3_write(usb3, 1 << usb3_ep->num, USB3_DMA_INT_STA); in usb3_dma_kick_prd()
1374 usb3_write(usb3, AXI_INT_PRDEN_CLR_STA(dma->num) | in usb3_dma_kick_prd()
1375 AXI_INT_PRDERR_STA(dma->num), USB3_AXI_INT_STA); in usb3_dma_kick_prd()
1377 usb3_write(usb3, dma->prd_dma, USB3_DMA_CH0_PRD_ADR(dma->num)); in usb3_dma_kick_prd()
1378 usb3_write(usb3, dma_con, USB3_DMA_CH0_CON(dma->num)); in usb3_dma_kick_prd()
1379 usb3_enable_dma_irq(usb3, usb3_ep->num); in usb3_dma_kick_prd()
1384 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_dma_stop_prd() local
1385 struct renesas_usb3_dma *dma = usb3_ep->dma; in usb3_dma_stop_prd()
1387 usb3_disable_dma_irq(usb3, usb3_ep->num); in usb3_dma_stop_prd()
1388 usb3_write(usb3, 0, USB3_DMA_CH0_CON(dma->num)); in usb3_dma_stop_prd()
1394 struct renesas_usb3_prd *cur_prd = usb3_ep->dma->prd; in usb3_dma_update_status()
1395 struct usb_request *req = &usb3_req->req; in usb3_dma_update_status()
1403 if (cur_prd->word1 & USB3_PRD1_D) in usb3_dma_update_status()
1404 status = -EIO; in usb3_dma_update_status()
1405 if (cur_prd->word1 & USB3_PRD1_E) in usb3_dma_update_status()
1406 len = req->length % USB3_DMA_MAX_XFER_SIZE; in usb3_dma_update_status()
1409 remain = cur_prd->word1 & USB3_PRD1_SIZE_MASK; in usb3_dma_update_status()
1410 req->actual += len - remain; in usb3_dma_update_status()
1412 if (cur_prd->word1 & USB3_PRD1_E || in usb3_dma_update_status()
1426 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_dma_try_start() local
1432 usb3_pn_stop(usb3); in usb3_dma_try_start()
1433 usb3_enable_dma_pipen(usb3); in usb3_dma_try_start()
1436 usb3_pn_start(usb3); in usb3_dma_try_start()
1446 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_dma_try_stop() local
1450 spin_lock_irqsave(&usb3->lock, flags); in usb3_dma_try_stop()
1451 if (!usb3_ep->dma) in usb3_dma_try_stop()
1454 if (!usb3_pn_change(usb3, usb3_ep->num)) in usb3_dma_try_stop()
1455 usb3_disable_dma_pipen(usb3); in usb3_dma_try_stop()
1461 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_dma_try_stop()
1465 static int renesas_usb3_dma_free_prd(struct renesas_usb3 *usb3, in renesas_usb3_dma_free_prd() argument
1471 usb3_for_each_dma(usb3, dma, i) { in renesas_usb3_dma_free_prd()
1472 if (dma->prd) { in renesas_usb3_dma_free_prd()
1474 dma->prd, dma->prd_dma); in renesas_usb3_dma_free_prd()
1475 dma->prd = NULL; in renesas_usb3_dma_free_prd()
1482 static int renesas_usb3_dma_alloc_prd(struct renesas_usb3 *usb3, in renesas_usb3_dma_alloc_prd() argument
1491 usb3_for_each_dma(usb3, dma, i) { in renesas_usb3_dma_alloc_prd()
1492 dma->prd = dma_alloc_coherent(dev, USB3_DMA_PRD_SIZE, in renesas_usb3_dma_alloc_prd()
1493 &dma->prd_dma, GFP_KERNEL); in renesas_usb3_dma_alloc_prd()
1494 if (!dma->prd) { in renesas_usb3_dma_alloc_prd()
1495 renesas_usb3_dma_free_prd(usb3, dev); in renesas_usb3_dma_alloc_prd()
1496 return -ENOMEM; in renesas_usb3_dma_alloc_prd()
1498 dma->num = i + 1; in renesas_usb3_dma_alloc_prd()
1507 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_start_pipen() local
1510 int ret = -EAGAIN; in usb3_start_pipen()
1513 spin_lock_irqsave(&usb3->lock, flags); in usb3_start_pipen()
1514 if (usb3_ep->halt || usb3_ep->started) in usb3_start_pipen()
1520 if (usb3_pn_change(usb3, usb3_ep->num) < 0) in usb3_start_pipen()
1523 usb3_ep->started = true; in usb3_start_pipen()
1528 usb3_pn_start(usb3); in usb3_start_pipen()
1530 if (usb3_ep->dir_in) { in usb3_start_pipen()
1539 usb3_set_bit(usb3, enable_bits, USB3_PN_INT_ENA); in usb3_start_pipen()
1540 usb3_enable_pipe_irq(usb3, usb3_ep->num); in usb3_start_pipen()
1543 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_start_pipen()
1551 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in renesas_usb3_ep_queue() local
1554 dev_dbg(usb3_to_dev(usb3), "ep_queue: ep%2d, %u\n", usb3_ep->num, in renesas_usb3_ep_queue()
1555 _req->length); in renesas_usb3_ep_queue()
1557 _req->status = -EINPROGRESS; in renesas_usb3_ep_queue()
1558 _req->actual = 0; in renesas_usb3_ep_queue()
1559 spin_lock_irqsave(&usb3->lock, flags); in renesas_usb3_ep_queue()
1560 list_add_tail(&usb3_req->queue, &usb3_ep->queue); in renesas_usb3_ep_queue()
1561 spin_unlock_irqrestore(&usb3->lock, flags); in renesas_usb3_ep_queue()
1563 if (!usb3_ep->num) in renesas_usb3_ep_queue()
1571 static void usb3_set_device_address(struct renesas_usb3 *usb3, u16 addr) in usb3_set_device_address() argument
1574 usb3_set_bit(usb3, USB_COM_CON_DEV_ADDR(addr), USB3_USB_COM_CON); in usb3_set_device_address()
1577 static bool usb3_std_req_set_address(struct renesas_usb3 *usb3, in usb3_std_req_set_address() argument
1580 if (le16_to_cpu(ctrl->wValue) >= 128) in usb3_std_req_set_address()
1583 usb3_set_device_address(usb3, le16_to_cpu(ctrl->wValue)); in usb3_std_req_set_address()
1584 usb3_set_p0_con_for_no_data(usb3); in usb3_std_req_set_address()
1589 static void usb3_pipe0_internal_xfer(struct renesas_usb3 *usb3, in usb3_pipe0_internal_xfer() argument
1594 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_pipe0_internal_xfer()
1597 memcpy(usb3->ep0_buf, tx_data, in usb3_pipe0_internal_xfer()
1600 usb3->ep0_req->buf = &usb3->ep0_buf; in usb3_pipe0_internal_xfer()
1601 usb3->ep0_req->length = len; in usb3_pipe0_internal_xfer()
1602 usb3->ep0_req->complete = complete; in usb3_pipe0_internal_xfer()
1603 renesas_usb3_ep_queue(&usb3_ep->ep, usb3->ep0_req, GFP_ATOMIC); in usb3_pipe0_internal_xfer()
1611 static bool usb3_std_req_get_status(struct renesas_usb3 *usb3, in usb3_std_req_get_status() argument
1620 switch (ctrl->bRequestType & USB_RECIP_MASK) { in usb3_std_req_get_status()
1622 if (usb3->gadget.is_selfpowered) in usb3_std_req_get_status()
1624 if (usb3->gadget.speed == USB_SPEED_SUPER) in usb3_std_req_get_status()
1625 status |= usb3_feature_get_un_enabled(usb3); in usb3_std_req_get_status()
1630 num = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK; in usb3_std_req_get_status()
1631 usb3_ep = usb3_get_ep(usb3, num); in usb3_std_req_get_status()
1632 if (usb3_ep->halt) in usb3_std_req_get_status()
1642 dev_dbg(usb3_to_dev(usb3), "get_status: req = %p\n", in usb3_std_req_get_status()
1643 usb_req_to_usb3_req(usb3->ep0_req)); in usb3_std_req_get_status()
1644 usb3_pipe0_internal_xfer(usb3, &tx_data, sizeof(tx_data), in usb3_std_req_get_status()
1651 static bool usb3_std_req_feature_device(struct renesas_usb3 *usb3, in usb3_std_req_feature_device() argument
1655 u16 w_value = le16_to_cpu(ctrl->wValue); in usb3_std_req_feature_device()
1661 usb3->test_mode = le16_to_cpu(ctrl->wIndex) >> 8; in usb3_std_req_feature_device()
1666 if (usb3->gadget.speed != USB_SPEED_SUPER) in usb3_std_req_feature_device()
1669 usb3_feature_u1_enable(usb3, set); in usb3_std_req_feature_device()
1671 usb3_feature_u2_enable(usb3, set); in usb3_std_req_feature_device()
1683 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_set_halt_p0() local
1685 if (unlikely(usb3_ep->num)) in usb3_set_halt_p0()
1686 return -EINVAL; in usb3_set_halt_p0()
1688 usb3_ep->halt = halt; in usb3_set_halt_p0()
1690 usb3_set_p0_con_stall(usb3); in usb3_set_halt_p0()
1692 usb3_set_p0_con_stop(usb3); in usb3_set_halt_p0()
1700 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_set_halt_pn() local
1703 spin_lock_irqsave(&usb3->lock, flags); in usb3_set_halt_pn()
1704 if (!usb3_pn_change(usb3, usb3_ep->num)) { in usb3_set_halt_pn()
1705 usb3_ep->halt = halt; in usb3_set_halt_pn()
1707 usb3_pn_stall(usb3); in usb3_set_halt_pn()
1708 } else if (!is_clear_feature || !usb3_ep->wedge) { in usb3_set_halt_pn()
1709 usb3_pn_con_clear(usb3); in usb3_set_halt_pn()
1710 usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); in usb3_set_halt_pn()
1711 usb3_pn_stop(usb3); in usb3_set_halt_pn()
1714 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_set_halt_pn()
1724 if (halt && usb3_ep->started) in usb3_set_halt()
1725 return -EAGAIN; in usb3_set_halt()
1727 if (usb3_ep->num) in usb3_set_halt()
1735 static bool usb3_std_req_feature_endpoint(struct renesas_usb3 *usb3, in usb3_std_req_feature_endpoint() argument
1739 int num = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK; in usb3_std_req_feature_endpoint()
1743 if (le16_to_cpu(ctrl->wValue) != USB_ENDPOINT_HALT) in usb3_std_req_feature_endpoint()
1746 usb3_ep = usb3_get_ep(usb3, num); in usb3_std_req_feature_endpoint()
1751 usb3_ep->started = false; in usb3_std_req_feature_endpoint()
1760 static bool usb3_std_req_feature(struct renesas_usb3 *usb3, in usb3_std_req_feature() argument
1765 switch (ctrl->bRequestType & USB_RECIP_MASK) { in usb3_std_req_feature()
1767 stall = usb3_std_req_feature_device(usb3, ctrl, set); in usb3_std_req_feature()
1772 stall = usb3_std_req_feature_endpoint(usb3, ctrl, set); in usb3_std_req_feature()
1780 usb3_set_p0_con_for_no_data(usb3); in usb3_std_req_feature()
1791 static bool usb3_std_req_set_sel(struct renesas_usb3 *usb3, in usb3_std_req_set_sel() argument
1794 u16 w_length = le16_to_cpu(ctrl->wLength); in usb3_std_req_set_sel()
1799 dev_dbg(usb3_to_dev(usb3), "set_sel: req = %p\n", in usb3_std_req_set_sel()
1800 usb_req_to_usb3_req(usb3->ep0_req)); in usb3_std_req_set_sel()
1801 usb3_pipe0_internal_xfer(usb3, NULL, 6, usb3_pipe0_set_sel_completion); in usb3_std_req_set_sel()
1806 static bool usb3_std_req_set_configuration(struct renesas_usb3 *usb3, in usb3_std_req_set_configuration() argument
1809 if (le16_to_cpu(ctrl->wValue) > 0) in usb3_std_req_set_configuration()
1810 usb3_set_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); in usb3_std_req_set_configuration()
1812 usb3_clear_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); in usb3_std_req_set_configuration()
1818 * usb3_handle_standard_request - handle some standard requests
1819 * @usb3: the renesas_usb3 pointer
1824 static bool usb3_handle_standard_request(struct renesas_usb3 *usb3, in usb3_handle_standard_request() argument
1830 if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { in usb3_handle_standard_request()
1831 switch (ctrl->bRequest) { in usb3_handle_standard_request()
1833 stall = usb3_std_req_set_address(usb3, ctrl); in usb3_handle_standard_request()
1837 stall = usb3_std_req_get_status(usb3, ctrl); in usb3_handle_standard_request()
1841 stall = usb3_std_req_feature(usb3, ctrl, false); in usb3_handle_standard_request()
1845 stall = usb3_std_req_feature(usb3, ctrl, true); in usb3_handle_standard_request()
1849 stall = usb3_std_req_set_sel(usb3, ctrl); in usb3_handle_standard_request()
1858 usb3_std_req_set_configuration(usb3, ctrl); in usb3_handle_standard_request()
1866 usb3_set_p0_con_stall(usb3); in usb3_handle_standard_request()
1871 static int usb3_p0_con_clear_buffer(struct renesas_usb3 *usb3) in usb3_p0_con_clear_buffer() argument
1873 usb3_set_bit(usb3, P0_CON_BCLR, USB3_P0_CON); in usb3_p0_con_clear_buffer()
1875 return usb3_wait(usb3, USB3_P0_CON, P0_CON_BCLR, 0); in usb3_p0_con_clear_buffer()
1878 static void usb3_irq_epc_pipe0_setup(struct renesas_usb3 *usb3) in usb3_irq_epc_pipe0_setup() argument
1881 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_irq_epc_pipe0_setup()
1884 if (usb3_ep->started) in usb3_irq_epc_pipe0_setup()
1886 -ECONNRESET); in usb3_irq_epc_pipe0_setup()
1888 usb3_p0_con_clear_buffer(usb3); in usb3_irq_epc_pipe0_setup()
1889 usb3_get_setup_data(usb3, &ctrl); in usb3_irq_epc_pipe0_setup()
1890 if (!usb3_handle_standard_request(usb3, &ctrl)) in usb3_irq_epc_pipe0_setup()
1891 if (usb3->driver->setup(&usb3->gadget, &ctrl) < 0) in usb3_irq_epc_pipe0_setup()
1892 usb3_set_p0_con_stall(usb3); in usb3_irq_epc_pipe0_setup()
1895 static void usb3_irq_epc_pipe0_bfrdy(struct renesas_usb3 *usb3) in usb3_irq_epc_pipe0_bfrdy() argument
1897 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_irq_epc_pipe0_bfrdy()
1906 static void usb3_irq_epc_pipe0(struct renesas_usb3 *usb3) in usb3_irq_epc_pipe0() argument
1908 u32 p0_int_sta = usb3_read(usb3, USB3_P0_INT_STA); in usb3_irq_epc_pipe0()
1910 p0_int_sta &= usb3_read(usb3, USB3_P0_INT_ENA); in usb3_irq_epc_pipe0()
1911 usb3_write(usb3, p0_int_sta, USB3_P0_INT_STA); in usb3_irq_epc_pipe0()
1913 usb3_irq_epc_pipe0_status_end(usb3); in usb3_irq_epc_pipe0()
1915 usb3_irq_epc_pipe0_setup(usb3); in usb3_irq_epc_pipe0()
1917 usb3_irq_epc_pipe0_bfrdy(usb3); in usb3_irq_epc_pipe0()
1920 static void usb3_request_done_pipen(struct renesas_usb3 *usb3, in usb3_request_done_pipen() argument
1927 spin_lock_irqsave(&usb3->lock, flags); in usb3_request_done_pipen()
1928 if (usb3_pn_change(usb3, usb3_ep->num)) in usb3_request_done_pipen()
1929 usb3_pn_stop(usb3); in usb3_request_done_pipen()
1930 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_request_done_pipen()
1932 usb3_disable_pipe_irq(usb3, usb3_ep->num); in usb3_request_done_pipen()
1941 static void usb3_irq_epc_pipen_lsttr(struct renesas_usb3 *usb3, int num) in usb3_irq_epc_pipen_lsttr() argument
1943 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num); in usb3_irq_epc_pipen_lsttr()
1949 if (usb3_ep->dir_in) { in usb3_irq_epc_pipen_lsttr()
1950 dev_dbg(usb3_to_dev(usb3), "%s: len = %u, actual = %u\n", in usb3_irq_epc_pipen_lsttr()
1951 __func__, usb3_req->req.length, usb3_req->req.actual); in usb3_irq_epc_pipen_lsttr()
1952 usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0); in usb3_irq_epc_pipen_lsttr()
1956 static void usb3_irq_epc_pipen_bfrdy(struct renesas_usb3 *usb3, int num) in usb3_irq_epc_pipen_bfrdy() argument
1958 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num); in usb3_irq_epc_pipen_bfrdy()
1965 spin_lock(&usb3->lock); in usb3_irq_epc_pipen_bfrdy()
1966 if (usb3_pn_change(usb3, num)) in usb3_irq_epc_pipen_bfrdy()
1969 if (usb3_ep->dir_in) { in usb3_irq_epc_pipen_bfrdy()
1972 usb3_clear_bit(usb3, PN_INT_BFRDY, USB3_PN_INT_ENA); in usb3_irq_epc_pipen_bfrdy()
1980 spin_unlock(&usb3->lock); in usb3_irq_epc_pipen_bfrdy()
1983 usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0); in usb3_irq_epc_pipen_bfrdy()
1986 static void usb3_irq_epc_pipen(struct renesas_usb3 *usb3, int num) in usb3_irq_epc_pipen() argument
1990 spin_lock(&usb3->lock); in usb3_irq_epc_pipen()
1991 if (usb3_pn_change(usb3, num) < 0) { in usb3_irq_epc_pipen()
1992 spin_unlock(&usb3->lock); in usb3_irq_epc_pipen()
1996 pn_int_sta = usb3_read(usb3, USB3_PN_INT_STA); in usb3_irq_epc_pipen()
1997 pn_int_sta &= usb3_read(usb3, USB3_PN_INT_ENA); in usb3_irq_epc_pipen()
1998 usb3_write(usb3, pn_int_sta, USB3_PN_INT_STA); in usb3_irq_epc_pipen()
1999 spin_unlock(&usb3->lock); in usb3_irq_epc_pipen()
2001 usb3_irq_epc_pipen_lsttr(usb3, num); in usb3_irq_epc_pipen()
2003 usb3_irq_epc_pipen_bfrdy(usb3, num); in usb3_irq_epc_pipen()
2006 static void usb3_irq_epc_int_2(struct renesas_usb3 *usb3, u32 int_sta_2) in usb3_irq_epc_int_2() argument
2010 for (i = 0; i < usb3->num_usb3_eps; i++) { in usb3_irq_epc_int_2()
2013 usb3_irq_epc_pipe0(usb3); in usb3_irq_epc_int_2()
2015 usb3_irq_epc_pipen(usb3, i); in usb3_irq_epc_int_2()
2020 static void usb3_irq_idmon_change(struct renesas_usb3 *usb3) in usb3_irq_idmon_change() argument
2022 usb3_check_id(usb3); in usb3_irq_idmon_change()
2025 static void usb3_irq_otg_int(struct renesas_usb3 *usb3) in usb3_irq_otg_int() argument
2027 u32 otg_int_sta = usb3_read(usb3, USB3_USB_OTG_INT_STA(usb3)); in usb3_irq_otg_int()
2029 otg_int_sta &= usb3_read(usb3, USB3_USB_OTG_INT_ENA(usb3)); in usb3_irq_otg_int()
2031 usb3_write(usb3, otg_int_sta, USB3_USB_OTG_INT_STA(usb3)); in usb3_irq_otg_int()
2033 if (otg_int_sta & USB_OTG_IDMON(usb3)) in usb3_irq_otg_int()
2034 usb3_irq_idmon_change(usb3); in usb3_irq_otg_int()
2037 static void usb3_irq_epc(struct renesas_usb3 *usb3) in usb3_irq_epc() argument
2039 u32 int_sta_1 = usb3_read(usb3, USB3_USB_INT_STA_1); in usb3_irq_epc()
2040 u32 int_sta_2 = usb3_read(usb3, USB3_USB_INT_STA_2); in usb3_irq_epc()
2042 int_sta_1 &= usb3_read(usb3, USB3_USB_INT_ENA_1); in usb3_irq_epc()
2044 usb3_write(usb3, int_sta_1, USB3_USB_INT_STA_1); in usb3_irq_epc()
2045 usb3_irq_epc_int_1(usb3, int_sta_1); in usb3_irq_epc()
2048 int_sta_2 &= usb3_read(usb3, USB3_USB_INT_ENA_2); in usb3_irq_epc()
2050 usb3_irq_epc_int_2(usb3, int_sta_2); in usb3_irq_epc()
2052 if (!usb3->is_rzv2m) in usb3_irq_epc()
2053 usb3_irq_otg_int(usb3); in usb3_irq_epc()
2056 static void usb3_irq_dma_int(struct renesas_usb3 *usb3, u32 dma_sta) in usb3_irq_dma_int() argument
2062 for (i = 0; i < usb3->num_usb3_eps; i++) { in usb3_irq_dma_int()
2066 usb3_ep = usb3_get_ep(usb3, i); in usb3_irq_dma_int()
2067 if (!(usb3_read(usb3, USB3_AXI_INT_STA) & in usb3_irq_dma_int()
2068 AXI_INT_PRDEN_CLR_STA(usb3_ep->dma->num))) in usb3_irq_dma_int()
2073 usb3_request_done_pipen(usb3, usb3_ep, usb3_req, status); in usb3_irq_dma_int()
2077 static void usb3_irq_dma(struct renesas_usb3 *usb3) in usb3_irq_dma() argument
2079 u32 dma_sta = usb3_read(usb3, USB3_DMA_INT_STA); in usb3_irq_dma()
2081 dma_sta &= usb3_read(usb3, USB3_DMA_INT_ENA); in usb3_irq_dma()
2083 usb3_write(usb3, dma_sta, USB3_DMA_INT_STA); in usb3_irq_dma()
2084 usb3_irq_dma_int(usb3, dma_sta); in usb3_irq_dma()
2090 struct renesas_usb3 *usb3 = _usb3; in renesas_usb3_irq() local
2092 u32 axi_int_sta = usb3_read(usb3, USB3_AXI_INT_STA); in renesas_usb3_irq()
2095 usb3_irq_dma(usb3); in renesas_usb3_irq()
2100 usb3_irq_epc(usb3); in renesas_usb3_irq()
2109 struct renesas_usb3 *usb3 = _usb3; in renesas_usb3_otg_irq() local
2111 usb3_irq_otg_int(usb3); in renesas_usb3_otg_irq()
2119 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_write_pn_mod() local
2122 val |= usb3_ep->dir_in ? PN_MOD_DIR : 0; in usb3_write_pn_mod()
2125 usb3_write(usb3, val, USB3_PN_MOD); in usb3_write_pn_mod()
2156 return usb3_ep->rammap_val | mpkt; in usb3_calc_rammap_val()
2162 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_enable_pipe_n() local
2165 usb3_ep->dir_in = usb_endpoint_dir_in(desc); in usb3_enable_pipe_n()
2167 spin_lock_irqsave(&usb3->lock, flags); in usb3_enable_pipe_n()
2168 if (!usb3_pn_change(usb3, usb3_ep->num)) { in usb3_enable_pipe_n()
2170 usb3_write(usb3, usb3_calc_rammap_val(usb3_ep, desc), in usb3_enable_pipe_n()
2172 usb3_pn_con_clear(usb3); in usb3_enable_pipe_n()
2173 usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); in usb3_enable_pipe_n()
2175 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_enable_pipe_n()
2182 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_disable_pipe_n() local
2185 usb3_ep->halt = false; in usb3_disable_pipe_n()
2187 spin_lock_irqsave(&usb3->lock, flags); in usb3_disable_pipe_n()
2188 if (!usb3_pn_change(usb3, usb3_ep->num)) { in usb3_disable_pipe_n()
2189 usb3_write(usb3, 0, USB3_PN_INT_ENA); in usb3_disable_pipe_n()
2190 usb3_write(usb3, 0, USB3_PN_RAMMAP); in usb3_disable_pipe_n()
2191 usb3_clear_bit(usb3, PN_CON_EN, USB3_PN_CON); in usb3_disable_pipe_n()
2193 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_disable_pipe_n()
2198 /*------- usb_ep_ops -----------------------------------------------------*/
2217 usb3_request_done(usb3_ep, usb3_req, -ESHUTDOWN); in renesas_usb3_ep_disable()
2231 INIT_LIST_HEAD(&usb3_req->queue); in __renesas_usb3_ep_alloc_request()
2233 return &usb3_req->req; in __renesas_usb3_ep_alloc_request()
2259 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in renesas_usb3_ep_dequeue() local
2261 dev_dbg(usb3_to_dev(usb3), "ep_dequeue: ep%2d, %u\n", usb3_ep->num, in renesas_usb3_ep_dequeue()
2262 _req->length); in renesas_usb3_ep_dequeue()
2265 usb3_request_done_pipen(usb3, usb3_ep, usb3_req, -ECONNRESET); in renesas_usb3_ep_dequeue()
2279 usb3_ep->wedge = true; in renesas_usb3_ep_set_wedge()
2286 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in renesas_usb3_ep_fifo_flush() local
2289 if (usb3_ep->num) { in renesas_usb3_ep_fifo_flush()
2290 spin_lock_irqsave(&usb3->lock, flags); in renesas_usb3_ep_fifo_flush()
2291 if (!usb3_pn_change(usb3, usb3_ep->num)) { in renesas_usb3_ep_fifo_flush()
2292 usb3_pn_con_clear(usb3); in renesas_usb3_ep_fifo_flush()
2293 usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); in renesas_usb3_ep_fifo_flush()
2295 spin_unlock_irqrestore(&usb3->lock, flags); in renesas_usb3_ep_fifo_flush()
2297 usb3_p0_con_clear_buffer(usb3); in renesas_usb3_ep_fifo_flush()
2316 /*------- usb_gadget_ops -------------------------------------------------*/
2320 struct renesas_usb3 *usb3; in renesas_usb3_start() local
2322 if (!driver || driver->max_speed < USB_SPEED_FULL || in renesas_usb3_start()
2323 !driver->setup) in renesas_usb3_start()
2324 return -EINVAL; in renesas_usb3_start()
2326 usb3 = gadget_to_renesas_usb3(gadget); in renesas_usb3_start()
2329 usb3->driver = driver; in renesas_usb3_start()
2331 if (usb3->phy) in renesas_usb3_start()
2332 phy_init(usb3->phy); in renesas_usb3_start()
2334 pm_runtime_get_sync(usb3_to_dev(usb3)); in renesas_usb3_start()
2336 renesas_usb3_init_controller(usb3); in renesas_usb3_start()
2343 struct renesas_usb3 *usb3 = gadget_to_renesas_usb3(gadget); in renesas_usb3_stop() local
2345 usb3->softconnect = false; in renesas_usb3_stop()
2346 usb3->gadget.speed = USB_SPEED_UNKNOWN; in renesas_usb3_stop()
2347 usb3->driver = NULL; in renesas_usb3_stop()
2348 renesas_usb3_stop_controller(usb3); in renesas_usb3_stop()
2350 if (usb3->phy) in renesas_usb3_stop()
2351 phy_exit(usb3->phy); in renesas_usb3_stop()
2353 pm_runtime_put(usb3_to_dev(usb3)); in renesas_usb3_stop()
2360 return -EOPNOTSUPP; in renesas_usb3_get_frame()
2365 struct renesas_usb3 *usb3 = gadget_to_renesas_usb3(gadget); in renesas_usb3_pullup() local
2367 usb3->softconnect = !!is_on; in renesas_usb3_pullup()
2374 gadget->is_selfpowered = !!is_self; in renesas_usb3_set_selfpowered()
2389 struct renesas_usb3 *usb3 = usb_role_switch_get_drvdata(sw); in renesas_usb3_role_switch_get() local
2392 pm_runtime_get_sync(usb3_to_dev(usb3)); in renesas_usb3_role_switch_get()
2393 cur_role = usb3_is_host(usb3) ? USB_ROLE_HOST : USB_ROLE_DEVICE; in renesas_usb3_role_switch_get()
2394 pm_runtime_put(usb3_to_dev(usb3)); in renesas_usb3_role_switch_get()
2402 struct renesas_usb3 *usb3 = dev_get_drvdata(dev); in handle_ext_role_switch_states() local
2403 struct device *host = usb3->host_dev; in handle_ext_role_switch_states()
2404 enum usb_role cur_role = renesas_usb3_role_switch_get(usb3->role_sw); in handle_ext_role_switch_states()
2408 usb3->connection_state = USB_ROLE_NONE; in handle_ext_role_switch_states()
2411 if (usb3->driver) in handle_ext_role_switch_states()
2412 usb3_disconnect(usb3); in handle_ext_role_switch_states()
2413 usb3_vbus_out(usb3, false); in handle_ext_role_switch_states()
2416 if (usb3->connection_state == USB_ROLE_NONE) { in handle_ext_role_switch_states()
2417 usb3->connection_state = USB_ROLE_DEVICE; in handle_ext_role_switch_states()
2418 usb3_set_mode(usb3, false); in handle_ext_role_switch_states()
2419 if (usb3->driver) in handle_ext_role_switch_states()
2420 usb3_connect(usb3); in handle_ext_role_switch_states()
2423 usb3_set_mode(usb3, false); in handle_ext_role_switch_states()
2424 if (usb3->driver) in handle_ext_role_switch_states()
2425 usb3_connect(usb3); in handle_ext_role_switch_states()
2427 usb3_vbus_out(usb3, false); in handle_ext_role_switch_states()
2430 if (usb3->connection_state == USB_ROLE_NONE) { in handle_ext_role_switch_states()
2431 if (usb3->driver) in handle_ext_role_switch_states()
2432 usb3_disconnect(usb3); in handle_ext_role_switch_states()
2434 usb3->connection_state = USB_ROLE_HOST; in handle_ext_role_switch_states()
2435 usb3_set_mode(usb3, true); in handle_ext_role_switch_states()
2436 usb3_vbus_out(usb3, true); in handle_ext_role_switch_states()
2440 usb3_disconnect(usb3); in handle_ext_role_switch_states()
2442 usb3_set_mode(usb3, true); in handle_ext_role_switch_states()
2456 struct renesas_usb3 *usb3 = dev_get_drvdata(dev); in handle_role_switch_states() local
2457 struct device *host = usb3->host_dev; in handle_role_switch_states()
2458 enum usb_role cur_role = renesas_usb3_role_switch_get(usb3->role_sw); in handle_role_switch_states()
2462 usb3_set_mode(usb3, false); in handle_role_switch_states()
2465 usb3_set_mode(usb3, true); in handle_role_switch_states()
2475 struct renesas_usb3 *usb3 = usb_role_switch_get_drvdata(sw); in renesas_usb3_role_switch_set() local
2477 pm_runtime_get_sync(usb3_to_dev(usb3)); in renesas_usb3_role_switch_set()
2479 if (usb3->role_sw_by_connector) in renesas_usb3_role_switch_set()
2480 handle_ext_role_switch_states(usb3_to_dev(usb3), role); in renesas_usb3_role_switch_set()
2482 handle_role_switch_states(usb3_to_dev(usb3), role); in renesas_usb3_role_switch_set()
2484 pm_runtime_put(usb3_to_dev(usb3)); in renesas_usb3_role_switch_set()
2492 struct renesas_usb3 *usb3 = dev_get_drvdata(dev); in role_store() local
2495 if (!usb3->driver) in role_store()
2496 return -ENODEV; in role_store()
2498 if (usb3->forced_b_device) in role_store()
2499 return -EBUSY; in role_store()
2506 return -EINVAL; in role_store()
2508 if (new_mode_is_host == usb3_is_host(usb3)) in role_store()
2509 return -EINVAL; in role_store()
2511 usb3_mode_config(usb3, new_mode_is_host, usb3_is_a_device(usb3)); in role_store()
2519 struct renesas_usb3 *usb3 = dev_get_drvdata(dev); in role_show() local
2521 if (!usb3->driver) in role_show()
2522 return -ENODEV; in role_show()
2524 return sprintf(buf, "%s\n", usb3_is_host(usb3) ? "host" : "peripheral"); in role_show()
2530 struct renesas_usb3 *usb3 = s->private; in renesas_usb3_b_device_show() local
2532 seq_printf(s, "%d\n", usb3->forced_b_device); in renesas_usb3_b_device_show()
2539 return single_open(file, renesas_usb3_b_device_show, inode->i_private); in renesas_usb3_b_device_open()
2546 struct seq_file *s = file->private_data; in renesas_usb3_b_device_write()
2547 struct renesas_usb3 *usb3 = s->private; in renesas_usb3_b_device_write() local
2550 if (!usb3->driver) in renesas_usb3_b_device_write()
2551 return -ENODEV; in renesas_usb3_b_device_write()
2553 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) in renesas_usb3_b_device_write()
2554 return -EFAULT; in renesas_usb3_b_device_write()
2556 usb3->start_to_connect = false; in renesas_usb3_b_device_write()
2557 if (usb3->workaround_for_vbus && usb3->forced_b_device && in renesas_usb3_b_device_write()
2559 usb3->start_to_connect = true; in renesas_usb3_b_device_write()
2561 usb3->forced_b_device = true; in renesas_usb3_b_device_write()
2563 usb3->forced_b_device = false; in renesas_usb3_b_device_write()
2565 if (usb3->workaround_for_vbus) in renesas_usb3_b_device_write()
2566 usb3_disconnect(usb3); in renesas_usb3_b_device_write()
2569 usb3_check_id(usb3); in renesas_usb3_b_device_write()
2582 static void renesas_usb3_debugfs_init(struct renesas_usb3 *usb3, in renesas_usb3_debugfs_init() argument
2585 usb3->dentry = debugfs_create_dir(dev_name(dev), usb_debug_root); in renesas_usb3_debugfs_init()
2587 debugfs_create_file("b_device", 0644, usb3->dentry, usb3, in renesas_usb3_debugfs_init()
2591 /*------- platform_driver ------------------------------------------------*/
2594 struct renesas_usb3 *usb3 = platform_get_drvdata(pdev); in renesas_usb3_remove() local
2596 debugfs_remove_recursive(usb3->dentry); in renesas_usb3_remove()
2597 device_remove_file(&pdev->dev, &dev_attr_role); in renesas_usb3_remove()
2599 usb_role_switch_unregister(usb3->role_sw); in renesas_usb3_remove()
2601 usb_del_gadget_udc(&usb3->gadget); in renesas_usb3_remove()
2602 reset_control_assert(usb3->usbp_rstc); in renesas_usb3_remove()
2603 reset_control_assert(usb3->drd_rstc); in renesas_usb3_remove()
2604 renesas_usb3_dma_free_prd(usb3, &pdev->dev); in renesas_usb3_remove()
2606 __renesas_usb3_ep_free_request(usb3->ep0_req); in renesas_usb3_remove()
2607 pm_runtime_disable(&pdev->dev); in renesas_usb3_remove()
2612 static int renesas_usb3_init_ep(struct renesas_usb3 *usb3, struct device *dev, in renesas_usb3_init_ep() argument
2619 usb3->num_usb3_eps = priv->ramsize_per_ramif * priv->num_ramif * 2 / in renesas_usb3_init_ep()
2620 priv->ramsize_per_pipe + 1; in renesas_usb3_init_ep()
2622 if (usb3->num_usb3_eps > USB3_MAX_NUM_PIPES(usb3)) in renesas_usb3_init_ep()
2623 usb3->num_usb3_eps = USB3_MAX_NUM_PIPES(usb3); in renesas_usb3_init_ep()
2625 usb3->usb3_ep = devm_kcalloc(dev, in renesas_usb3_init_ep()
2626 usb3->num_usb3_eps, sizeof(*usb3_ep), in renesas_usb3_init_ep()
2628 if (!usb3->usb3_ep) in renesas_usb3_init_ep()
2629 return -ENOMEM; in renesas_usb3_init_ep()
2631 dev_dbg(dev, "%s: num_usb3_eps = %d\n", __func__, usb3->num_usb3_eps); in renesas_usb3_init_ep()
2634 * - odd pipes = IN pipe in renesas_usb3_init_ep()
2635 * - even pipes = OUT pipe (except pipe 0) in renesas_usb3_init_ep()
2637 usb3_for_each_ep(usb3_ep, usb3, i) { in renesas_usb3_init_ep()
2638 snprintf(usb3_ep->ep_name, sizeof(usb3_ep->ep_name), "ep%d", i); in renesas_usb3_init_ep()
2639 usb3_ep->usb3 = usb3; in renesas_usb3_init_ep()
2640 usb3_ep->num = i; in renesas_usb3_init_ep()
2641 usb3_ep->ep.name = usb3_ep->ep_name; in renesas_usb3_init_ep()
2642 usb3_ep->ep.ops = &renesas_usb3_ep_ops; in renesas_usb3_init_ep()
2643 INIT_LIST_HEAD(&usb3_ep->queue); in renesas_usb3_init_ep()
2644 INIT_LIST_HEAD(&usb3_ep->ep.ep_list); in renesas_usb3_init_ep()
2647 usb3->gadget.ep0 = &usb3_ep->ep; in renesas_usb3_init_ep()
2648 usb_ep_set_maxpacket_limit(&usb3_ep->ep, in renesas_usb3_init_ep()
2650 usb3_ep->ep.caps.type_control = true; in renesas_usb3_init_ep()
2651 usb3_ep->ep.caps.dir_in = true; in renesas_usb3_init_ep()
2652 usb3_ep->ep.caps.dir_out = true; in renesas_usb3_init_ep()
2657 usb_ep_set_maxpacket_limit(&usb3_ep->ep, ~0); in renesas_usb3_init_ep()
2658 list_add_tail(&usb3_ep->ep.ep_list, &usb3->gadget.ep_list); in renesas_usb3_init_ep()
2659 usb3_ep->ep.caps.type_bulk = true; in renesas_usb3_init_ep()
2660 usb3_ep->ep.caps.type_int = true; in renesas_usb3_init_ep()
2662 usb3_ep->ep.caps.dir_in = true; in renesas_usb3_init_ep()
2664 usb3_ep->ep.caps.dir_out = true; in renesas_usb3_init_ep()
2670 static void renesas_usb3_init_ram(struct renesas_usb3 *usb3, struct device *dev, in renesas_usb3_init_ram() argument
2684 * - all pipes = the same size as "ramsize_per_pipe" in renesas_usb3_init_ram()
2687 usb3_for_each_ep(usb3_ep, usb3, i) { in renesas_usb3_init_ram()
2690 if (usb3_ep->ep.caps.dir_in) { in renesas_usb3_init_ram()
2698 if (*cur_basead > priv->ramsize_per_ramif) in renesas_usb3_init_ram()
2703 val |= usb3_calc_ramarea(priv->ramsize_per_pipe); in renesas_usb3_init_ram()
2705 usb3_ep->rammap_val = val; in renesas_usb3_init_ram()
2711 if (*cur_ramif + 1 == priv->num_ramif) { in renesas_usb3_init_ram()
2713 *cur_basead += priv->ramsize_per_pipe; in renesas_usb3_init_ram()
2749 .compatible = "renesas,r8a774c0-usb3-peri",
2752 .compatible = "renesas,r8a7795-usb3-peri",
2755 .compatible = "renesas,r8a77990-usb3-peri",
2758 .compatible = "renesas,rzv2m-usb3-peri",
2761 .compatible = "renesas,rcar-gen3-usb3-peri",
2770 .soc_id = "r8a7795", .revision = "ES1.*",
2790 struct renesas_usb3 *usb3; in renesas_usb3_probe() local
2797 priv = attr->data; in renesas_usb3_probe()
2799 priv = of_device_get_match_data(&pdev->dev); in renesas_usb3_probe()
2805 if (priv->is_rzv2m) { in renesas_usb3_probe()
2811 usb3 = devm_kzalloc(&pdev->dev, sizeof(*usb3), GFP_KERNEL); in renesas_usb3_probe()
2812 if (!usb3) in renesas_usb3_probe()
2813 return -ENOMEM; in renesas_usb3_probe()
2815 usb3->is_rzv2m = priv->is_rzv2m; in renesas_usb3_probe()
2817 usb3->reg = devm_platform_ioremap_resource(pdev, 0); in renesas_usb3_probe()
2818 if (IS_ERR(usb3->reg)) in renesas_usb3_probe()
2819 return PTR_ERR(usb3->reg); in renesas_usb3_probe()
2821 platform_set_drvdata(pdev, usb3); in renesas_usb3_probe()
2822 spin_lock_init(&usb3->lock); in renesas_usb3_probe()
2824 usb3->gadget.ops = &renesas_usb3_gadget_ops; in renesas_usb3_probe()
2825 usb3->gadget.name = udc_name; in renesas_usb3_probe()
2826 usb3->gadget.max_speed = USB_SPEED_SUPER; in renesas_usb3_probe()
2827 INIT_LIST_HEAD(&usb3->gadget.ep_list); in renesas_usb3_probe()
2828 ret = renesas_usb3_init_ep(usb3, &pdev->dev, priv); in renesas_usb3_probe()
2831 renesas_usb3_init_ram(usb3, &pdev->dev, priv); in renesas_usb3_probe()
2833 ret = devm_request_irq(&pdev->dev, irq, renesas_usb3_irq, 0, in renesas_usb3_probe()
2834 dev_name(&pdev->dev), usb3); in renesas_usb3_probe()
2838 if (usb3->is_rzv2m) { in renesas_usb3_probe()
2839 ret = devm_request_irq(&pdev->dev, drd_irq, in renesas_usb3_probe()
2841 dev_name(&pdev->dev), usb3); in renesas_usb3_probe()
2846 INIT_WORK(&usb3->extcon_work, renesas_usb3_extcon_work); in renesas_usb3_probe()
2847 usb3->extcon = devm_extcon_dev_allocate(&pdev->dev, renesas_usb3_cable); in renesas_usb3_probe()
2848 if (IS_ERR(usb3->extcon)) in renesas_usb3_probe()
2849 return PTR_ERR(usb3->extcon); in renesas_usb3_probe()
2851 ret = devm_extcon_dev_register(&pdev->dev, usb3->extcon); in renesas_usb3_probe()
2853 dev_err(&pdev->dev, "Failed to register extcon\n"); in renesas_usb3_probe()
2858 usb3->ep0_req = __renesas_usb3_ep_alloc_request(GFP_KERNEL); in renesas_usb3_probe()
2859 if (!usb3->ep0_req) in renesas_usb3_probe()
2860 return -ENOMEM; in renesas_usb3_probe()
2862 ret = renesas_usb3_dma_alloc_prd(usb3, &pdev->dev); in renesas_usb3_probe()
2867 * This is optional. So, if this driver cannot get a phy, in renesas_usb3_probe()
2868 * this driver will not handle a phy anymore. in renesas_usb3_probe()
2870 usb3->phy = devm_phy_optional_get(&pdev->dev, "usb"); in renesas_usb3_probe()
2871 if (IS_ERR(usb3->phy)) { in renesas_usb3_probe()
2872 ret = PTR_ERR(usb3->phy); in renesas_usb3_probe()
2876 usb3->drd_rstc = devm_reset_control_get_optional_shared(&pdev->dev, in renesas_usb3_probe()
2878 if (IS_ERR(usb3->drd_rstc)) { in renesas_usb3_probe()
2879 ret = PTR_ERR(usb3->drd_rstc); in renesas_usb3_probe()
2883 usb3->usbp_rstc = devm_reset_control_get_optional_shared(&pdev->dev, in renesas_usb3_probe()
2885 if (IS_ERR(usb3->usbp_rstc)) { in renesas_usb3_probe()
2886 ret = PTR_ERR(usb3->usbp_rstc); in renesas_usb3_probe()
2890 reset_control_deassert(usb3->drd_rstc); in renesas_usb3_probe()
2891 reset_control_deassert(usb3->usbp_rstc); in renesas_usb3_probe()
2893 pm_runtime_enable(&pdev->dev); in renesas_usb3_probe()
2894 ret = usb_add_gadget_udc(&pdev->dev, &usb3->gadget); in renesas_usb3_probe()
2898 ret = device_create_file(&pdev->dev, &dev_attr_role); in renesas_usb3_probe()
2902 if (device_property_read_bool(&pdev->dev, "usb-role-switch")) { in renesas_usb3_probe()
2903 usb3->role_sw_by_connector = true; in renesas_usb3_probe()
2904 renesas_usb3_role_switch_desc.fwnode = dev_fwnode(&pdev->dev); in renesas_usb3_probe()
2907 renesas_usb3_role_switch_desc.driver_data = usb3; in renesas_usb3_probe()
2909 INIT_WORK(&usb3->role_work, renesas_usb3_role_work); in renesas_usb3_probe()
2910 usb3->role_sw = usb_role_switch_register(&pdev->dev, in renesas_usb3_probe()
2912 if (!IS_ERR(usb3->role_sw)) { in renesas_usb3_probe()
2913 usb3->host_dev = usb_of_get_companion_dev(&pdev->dev); in renesas_usb3_probe()
2914 if (!usb3->host_dev) { in renesas_usb3_probe()
2916 usb_role_switch_unregister(usb3->role_sw); in renesas_usb3_probe()
2917 usb3->role_sw = NULL; in renesas_usb3_probe()
2920 usb3->role_sw = NULL; in renesas_usb3_probe()
2923 usb3->workaround_for_vbus = priv->workaround_for_vbus; in renesas_usb3_probe()
2925 renesas_usb3_debugfs_init(usb3, &pdev->dev); in renesas_usb3_probe()
2927 dev_info(&pdev->dev, "probed%s\n", usb3->phy ? " with phy" : ""); in renesas_usb3_probe()
2932 usb_del_gadget_udc(&usb3->gadget); in renesas_usb3_probe()
2935 reset_control_assert(usb3->usbp_rstc); in renesas_usb3_probe()
2936 reset_control_assert(usb3->drd_rstc); in renesas_usb3_probe()
2939 renesas_usb3_dma_free_prd(usb3, &pdev->dev); in renesas_usb3_probe()
2942 __renesas_usb3_ep_free_request(usb3->ep0_req); in renesas_usb3_probe()
2950 struct renesas_usb3 *usb3 = dev_get_drvdata(dev); in renesas_usb3_suspend() local
2953 if (!usb3->driver) in renesas_usb3_suspend()
2956 renesas_usb3_stop_controller(usb3); in renesas_usb3_suspend()
2957 if (usb3->phy) in renesas_usb3_suspend()
2958 phy_exit(usb3->phy); in renesas_usb3_suspend()
2966 struct renesas_usb3 *usb3 = dev_get_drvdata(dev); in renesas_usb3_resume() local
2969 if (!usb3->driver) in renesas_usb3_resume()
2972 if (usb3->phy) in renesas_usb3_resume()
2973 phy_init(usb3->phy); in renesas_usb3_resume()
2975 renesas_usb3_init_controller(usb3); in renesas_usb3_resume()
2995 MODULE_DESCRIPTION("Renesas USB3.0 Peripheral driver");