Lines Matching refs:usb3
237 struct renesas_usb3 *usb3; member
280 #define usb3_ep_to_usb3(_usb3_ep) (_usb3_ep->usb3)
284 #define usb3_get_ep(usb3, n) ((usb3)->usb3_ep + (n)) argument
285 #define usb3_for_each_ep(usb3_ep, usb3, i) \ argument
286 for ((i) = 0, usb3_ep = usb3_get_ep(usb3, (i)); \
287 (i) < (usb3)->num_usb3_eps; \
288 (i)++, usb3_ep = usb3_get_ep(usb3, (i)))
292 static void usb3_write(struct renesas_usb3 *usb3, u32 data, u32 offs) in usb3_write() argument
294 iowrite32(data, usb3->reg + offs); in usb3_write()
297 static u32 usb3_read(struct renesas_usb3 *usb3, u32 offs) in usb3_read() argument
299 return ioread32(usb3->reg + offs); in usb3_read()
302 static void usb3_set_bit(struct renesas_usb3 *usb3, u32 bits, u32 offs) in usb3_set_bit() argument
304 u32 val = usb3_read(usb3, offs); in usb3_set_bit()
307 usb3_write(usb3, val, offs); in usb3_set_bit()
310 static void usb3_clear_bit(struct renesas_usb3 *usb3, u32 bits, u32 offs) in usb3_clear_bit() argument
312 u32 val = usb3_read(usb3, offs); in usb3_clear_bit()
315 usb3_write(usb3, val, offs); in usb3_clear_bit()
318 static int usb3_wait(struct renesas_usb3 *usb3, u32 reg, u32 mask, in usb3_wait() argument
324 if ((usb3_read(usb3, reg) & mask) == expected) in usb3_wait()
329 dev_dbg(usb3_to_dev(usb3), "%s: timed out (%8x, %08x, %08x)\n", in usb3_wait()
335 static void usb3_enable_irq_1(struct renesas_usb3 *usb3, u32 bits) in usb3_enable_irq_1() argument
337 usb3_set_bit(usb3, bits, USB3_USB_INT_ENA_1); in usb3_enable_irq_1()
340 static void usb3_disable_irq_1(struct renesas_usb3 *usb3, u32 bits) in usb3_disable_irq_1() argument
342 usb3_clear_bit(usb3, bits, USB3_USB_INT_ENA_1); in usb3_disable_irq_1()
345 static void usb3_enable_pipe_irq(struct renesas_usb3 *usb3, int num) in usb3_enable_pipe_irq() argument
347 usb3_set_bit(usb3, USB_INT_2_PIPE(num), USB3_USB_INT_ENA_2); in usb3_enable_pipe_irq()
350 static void usb3_disable_pipe_irq(struct renesas_usb3 *usb3, int num) in usb3_disable_pipe_irq() argument
352 usb3_clear_bit(usb3, USB_INT_2_PIPE(num), USB3_USB_INT_ENA_2); in usb3_disable_pipe_irq()
355 static void usb3_init_axi_bridge(struct renesas_usb3 *usb3) in usb3_init_axi_bridge() argument
358 usb3_write(usb3, ~0, USB3_DMA_INT_STA); in usb3_init_axi_bridge()
359 usb3_write(usb3, 0, USB3_DMA_INT_ENA); in usb3_init_axi_bridge()
360 usb3_set_bit(usb3, AXI_INT_DMAINT | AXI_INT_EPCINT, USB3_AXI_INT_ENA); in usb3_init_axi_bridge()
363 static void usb3_init_epc_registers(struct renesas_usb3 *usb3) in usb3_init_epc_registers() argument
366 usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); in usb3_init_epc_registers()
367 usb3_clear_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON); in usb3_init_epc_registers()
369 usb3_write(usb3, ~0, USB3_USB_INT_STA_1); in usb3_init_epc_registers()
370 usb3_enable_irq_1(usb3, USB_INT_1_VBUS_CNG); in usb3_init_epc_registers()
373 static bool usb3_wakeup_usb2_phy(struct renesas_usb3 *usb3) in usb3_wakeup_usb2_phy() argument
375 if (!(usb3_read(usb3, USB3_USB20_CON) & USB20_CON_B2_SUSPEND)) in usb3_wakeup_usb2_phy()
378 usb3_clear_bit(usb3, USB20_CON_B2_SUSPEND, USB3_USB20_CON); in usb3_wakeup_usb2_phy()
379 usb3_enable_irq_1(usb3, USB_INT_1_B2_RSUM); in usb3_wakeup_usb2_phy()
384 static void usb3_usb2_pullup(struct renesas_usb3 *usb3, int pullup) in usb3_usb2_pullup() argument
388 if (usb3->softconnect && pullup) in usb3_usb2_pullup()
389 usb3_set_bit(usb3, bits, USB3_USB20_CON); in usb3_usb2_pullup()
391 usb3_clear_bit(usb3, bits, USB3_USB20_CON); in usb3_usb2_pullup()
394 static void usb3_set_test_mode(struct renesas_usb3 *usb3) in usb3_set_test_mode() argument
396 u32 val = usb3_read(usb3, USB3_USB20_CON); in usb3_set_test_mode()
399 val |= USB20_CON_B2_TSTMOD(usb3->test_mode); in usb3_set_test_mode()
400 usb3_write(usb3, val | USB20_CON_B2_TSTMOD_EN, USB3_USB20_CON); in usb3_set_test_mode()
401 if (!usb3->test_mode) in usb3_set_test_mode()
402 usb3_clear_bit(usb3, USB20_CON_B2_TSTMOD_EN, USB3_USB20_CON); in usb3_set_test_mode()
405 static void usb3_start_usb2_connection(struct renesas_usb3 *usb3) in usb3_start_usb2_connection() argument
407 usb3->disabled_count++; in usb3_start_usb2_connection()
408 usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_start_usb2_connection()
409 usb3_set_bit(usb3, USB_COM_CON_SPD_MODE, USB3_USB_COM_CON); in usb3_start_usb2_connection()
410 usb3_usb2_pullup(usb3, 1); in usb3_start_usb2_connection()
413 static int usb3_is_usb3_phy_in_u3(struct renesas_usb3 *usb3) in usb3_is_usb3_phy_in_u3() argument
415 return usb3_read(usb3, USB3_USB30_CON) & USB30_CON_POW_SEL_IN_U3; in usb3_is_usb3_phy_in_u3()
418 static bool usb3_wakeup_usb3_phy(struct renesas_usb3 *usb3) in usb3_wakeup_usb3_phy() argument
420 if (!usb3_is_usb3_phy_in_u3(usb3)) in usb3_wakeup_usb3_phy()
423 usb3_set_bit(usb3, USB30_CON_B3_PLLWAKE, USB3_USB30_CON); in usb3_wakeup_usb3_phy()
424 usb3_enable_irq_1(usb3, USB_INT_1_B3_PLLWKUP); in usb3_wakeup_usb3_phy()
429 static u16 usb3_feature_get_un_enabled(struct renesas_usb3 *usb3) in usb3_feature_get_un_enabled() argument
433 u32 val = usb3_read(usb3, USB3_SSIFCMD); in usb3_feature_get_un_enabled()
445 static void usb3_feature_u2_enable(struct renesas_usb3 *usb3, bool enable) in usb3_feature_u2_enable() argument
451 usb3_clear_bit(usb3, bits, USB3_SSIFCMD); in usb3_feature_u2_enable()
453 usb3_set_bit(usb3, bits, USB3_SSIFCMD); in usb3_feature_u2_enable()
456 static void usb3_feature_u1_enable(struct renesas_usb3 *usb3, bool enable) in usb3_feature_u1_enable() argument
462 usb3_clear_bit(usb3, bits, USB3_SSIFCMD); in usb3_feature_u1_enable()
464 usb3_set_bit(usb3, bits, USB3_SSIFCMD); in usb3_feature_u1_enable()
467 static void usb3_start_operation_for_usb3(struct renesas_usb3 *usb3) in usb3_start_operation_for_usb3() argument
469 usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_start_operation_for_usb3()
470 usb3_clear_bit(usb3, USB_COM_CON_SPD_MODE, USB3_USB_COM_CON); in usb3_start_operation_for_usb3()
471 usb3_set_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); in usb3_start_operation_for_usb3()
474 static void usb3_start_usb3_connection(struct renesas_usb3 *usb3) in usb3_start_usb3_connection() argument
476 usb3_start_operation_for_usb3(usb3); in usb3_start_usb3_connection()
477 usb3_set_bit(usb3, USB_COM_CON_RX_DETECTION, USB3_USB_COM_CON); in usb3_start_usb3_connection()
479 usb3_enable_irq_1(usb3, USB_INT_1_B3_LUPSUCS | USB_INT_1_B3_DISABLE | in usb3_start_usb3_connection()
483 static void usb3_stop_usb3_connection(struct renesas_usb3 *usb3) in usb3_stop_usb3_connection() argument
485 usb3_clear_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); in usb3_stop_usb3_connection()
488 static void usb3_transition_to_default_state(struct renesas_usb3 *usb3, in usb3_transition_to_default_state() argument
491 usb3_set_bit(usb3, USB_INT_2_PIPE(0), USB3_USB_INT_ENA_2); in usb3_transition_to_default_state()
492 usb3_write(usb3, P0_INT_ALL_BITS, USB3_P0_INT_STA); in usb3_transition_to_default_state()
493 usb3_set_bit(usb3, P0_INT_ALL_BITS, USB3_P0_INT_ENA); in usb3_transition_to_default_state()
496 usb3_enable_irq_1(usb3, USB_INT_1_B3_WRMRST | in usb3_transition_to_default_state()
499 usb3_enable_irq_1(usb3, USB_INT_1_B2_SPND | in usb3_transition_to_default_state()
503 static void usb3_connect(struct renesas_usb3 *usb3) in usb3_connect() argument
505 if (usb3_wakeup_usb3_phy(usb3)) in usb3_connect()
506 usb3_start_usb3_connection(usb3); in usb3_connect()
509 static void usb3_reset_epc(struct renesas_usb3 *usb3) in usb3_reset_epc() argument
511 usb3_clear_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); in usb3_reset_epc()
512 usb3_clear_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_reset_epc()
513 usb3_set_bit(usb3, USB_COM_CON_PIPE_CLR, USB3_USB_COM_CON); in usb3_reset_epc()
514 usb3->test_mode = 0; in usb3_reset_epc()
515 usb3_set_test_mode(usb3); in usb3_reset_epc()
518 static void usb3_disconnect(struct renesas_usb3 *usb3) in usb3_disconnect() argument
520 usb3->disabled_count = 0; in usb3_disconnect()
521 usb3_usb2_pullup(usb3, 0); in usb3_disconnect()
522 usb3_clear_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); in usb3_disconnect()
523 usb3_reset_epc(usb3); in usb3_disconnect()
525 if (usb3->driver) in usb3_disconnect()
526 usb3->driver->disconnect(&usb3->gadget); in usb3_disconnect()
529 static void usb3_check_vbus(struct renesas_usb3 *usb3) in usb3_check_vbus() argument
531 if (usb3->workaround_for_vbus) { in usb3_check_vbus()
532 usb3_connect(usb3); in usb3_check_vbus()
534 if (usb3_read(usb3, USB3_USB_STA) & USB_STA_VBUS_STA) in usb3_check_vbus()
535 usb3_connect(usb3); in usb3_check_vbus()
537 usb3_disconnect(usb3); in usb3_check_vbus()
541 static void renesas_usb3_init_controller(struct renesas_usb3 *usb3) in renesas_usb3_init_controller() argument
543 usb3_init_axi_bridge(usb3); in renesas_usb3_init_controller()
544 usb3_init_epc_registers(usb3); in renesas_usb3_init_controller()
546 usb3_check_vbus(usb3); in renesas_usb3_init_controller()
549 static void renesas_usb3_stop_controller(struct renesas_usb3 *usb3) in renesas_usb3_stop_controller() argument
551 usb3_disconnect(usb3); in renesas_usb3_stop_controller()
552 usb3_write(usb3, 0, USB3_P0_INT_ENA); in renesas_usb3_stop_controller()
553 usb3_write(usb3, 0, USB3_PN_INT_ENA); in renesas_usb3_stop_controller()
554 usb3_write(usb3, 0, USB3_USB_INT_ENA_1); in renesas_usb3_stop_controller()
555 usb3_write(usb3, 0, USB3_USB_INT_ENA_2); in renesas_usb3_stop_controller()
556 usb3_write(usb3, 0, USB3_AXI_INT_ENA); in renesas_usb3_stop_controller()
559 static void usb3_irq_epc_int_1_pll_wakeup(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_pll_wakeup() argument
561 usb3_disable_irq_1(usb3, USB_INT_1_B3_PLLWKUP); in usb3_irq_epc_int_1_pll_wakeup()
562 usb3_clear_bit(usb3, USB30_CON_B3_PLLWAKE, USB3_USB30_CON); in usb3_irq_epc_int_1_pll_wakeup()
563 usb3_start_usb3_connection(usb3); in usb3_irq_epc_int_1_pll_wakeup()
566 static void usb3_irq_epc_int_1_linkup_success(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_linkup_success() argument
568 usb3_transition_to_default_state(usb3, true); in usb3_irq_epc_int_1_linkup_success()
571 static void usb3_irq_epc_int_1_resume(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_resume() argument
573 usb3_disable_irq_1(usb3, USB_INT_1_B2_RSUM); in usb3_irq_epc_int_1_resume()
574 usb3_start_usb2_connection(usb3); in usb3_irq_epc_int_1_resume()
575 usb3_transition_to_default_state(usb3, false); in usb3_irq_epc_int_1_resume()
578 static void usb3_irq_epc_int_1_disable(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_disable() argument
580 usb3_stop_usb3_connection(usb3); in usb3_irq_epc_int_1_disable()
581 if (usb3_wakeup_usb2_phy(usb3)) in usb3_irq_epc_int_1_disable()
582 usb3_irq_epc_int_1_resume(usb3); in usb3_irq_epc_int_1_disable()
585 static void usb3_irq_epc_int_1_bus_reset(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_bus_reset() argument
587 usb3_reset_epc(usb3); in usb3_irq_epc_int_1_bus_reset()
588 if (usb3->disabled_count < 3) in usb3_irq_epc_int_1_bus_reset()
589 usb3_start_usb3_connection(usb3); in usb3_irq_epc_int_1_bus_reset()
591 usb3_start_usb2_connection(usb3); in usb3_irq_epc_int_1_bus_reset()
594 static void usb3_irq_epc_int_1_vbus_change(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_vbus_change() argument
596 usb3_check_vbus(usb3); in usb3_irq_epc_int_1_vbus_change()
599 static void usb3_irq_epc_int_1_hot_reset(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_hot_reset() argument
601 usb3_reset_epc(usb3); in usb3_irq_epc_int_1_hot_reset()
602 usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_irq_epc_int_1_hot_reset()
605 usb3_set_bit(usb3, USB30_CON_B3_HOTRST_CMP, USB3_USB30_CON); in usb3_irq_epc_int_1_hot_reset()
608 static void usb3_irq_epc_int_1_warm_reset(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_warm_reset() argument
610 usb3_reset_epc(usb3); in usb3_irq_epc_int_1_warm_reset()
611 usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); in usb3_irq_epc_int_1_warm_reset()
613 usb3_start_operation_for_usb3(usb3); in usb3_irq_epc_int_1_warm_reset()
614 usb3_enable_irq_1(usb3, USB_INT_1_SPEED); in usb3_irq_epc_int_1_warm_reset()
617 static void usb3_irq_epc_int_1_speed(struct renesas_usb3 *usb3) in usb3_irq_epc_int_1_speed() argument
619 u32 speed = usb3_read(usb3, USB3_USB_STA) & USB_STA_SPEED_MASK; in usb3_irq_epc_int_1_speed()
623 usb3->gadget.speed = USB_SPEED_SUPER; in usb3_irq_epc_int_1_speed()
626 usb3->gadget.speed = USB_SPEED_HIGH; in usb3_irq_epc_int_1_speed()
629 usb3->gadget.speed = USB_SPEED_FULL; in usb3_irq_epc_int_1_speed()
632 usb3->gadget.speed = USB_SPEED_UNKNOWN; in usb3_irq_epc_int_1_speed()
637 static void usb3_irq_epc_int_1(struct renesas_usb3 *usb3, u32 int_sta_1) in usb3_irq_epc_int_1() argument
640 usb3_irq_epc_int_1_pll_wakeup(usb3); in usb3_irq_epc_int_1()
643 usb3_irq_epc_int_1_linkup_success(usb3); in usb3_irq_epc_int_1()
646 usb3_irq_epc_int_1_hot_reset(usb3); in usb3_irq_epc_int_1()
649 usb3_irq_epc_int_1_warm_reset(usb3); in usb3_irq_epc_int_1()
652 usb3_irq_epc_int_1_disable(usb3); in usb3_irq_epc_int_1()
655 usb3_irq_epc_int_1_bus_reset(usb3); in usb3_irq_epc_int_1()
658 usb3_irq_epc_int_1_resume(usb3); in usb3_irq_epc_int_1()
661 usb3_irq_epc_int_1_speed(usb3); in usb3_irq_epc_int_1()
664 usb3_irq_epc_int_1_vbus_change(usb3); in usb3_irq_epc_int_1()
677 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_get_request() local
681 spin_lock_irqsave(&usb3->lock, flags); in usb3_get_request()
683 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_get_request()
692 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in __usb3_request_done() local
694 dev_dbg(usb3_to_dev(usb3), "giveback: ep%2d, %u, %u, %d\n", in __usb3_request_done()
700 spin_unlock(&usb3->lock); in __usb3_request_done()
702 spin_lock(&usb3->lock); in __usb3_request_done()
708 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_request_done() local
711 spin_lock_irqsave(&usb3->lock, flags); in usb3_request_done()
713 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_request_done()
716 static void usb3_irq_epc_pipe0_status_end(struct renesas_usb3 *usb3) in usb3_irq_epc_pipe0_status_end() argument
718 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_irq_epc_pipe0_status_end()
723 if (usb3->test_mode) in usb3_irq_epc_pipe0_status_end()
724 usb3_set_test_mode(usb3); in usb3_irq_epc_pipe0_status_end()
727 static void usb3_get_setup_data(struct renesas_usb3 *usb3, in usb3_get_setup_data() argument
730 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_get_setup_data()
733 *data++ = usb3_read(usb3, USB3_STUP_DAT_0); in usb3_get_setup_data()
734 *data = usb3_read(usb3, USB3_STUP_DAT_1); in usb3_get_setup_data()
740 static void usb3_set_p0_con_update_res(struct renesas_usb3 *usb3, u32 res) in usb3_set_p0_con_update_res() argument
742 u32 val = usb3_read(usb3, USB3_P0_CON); in usb3_set_p0_con_update_res()
746 usb3_write(usb3, val, USB3_P0_CON); in usb3_set_p0_con_update_res()
749 static void usb3_set_p0_con_for_ctrl_read_data(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_ctrl_read_data() argument
751 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | in usb3_set_p0_con_for_ctrl_read_data()
756 static void usb3_set_p0_con_for_ctrl_read_status(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_ctrl_read_status() argument
758 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | in usb3_set_p0_con_for_ctrl_read_status()
763 static void usb3_set_p0_con_for_ctrl_write_data(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_ctrl_write_data() argument
765 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | in usb3_set_p0_con_for_ctrl_write_data()
770 static void usb3_set_p0_con_for_ctrl_write_status(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_ctrl_write_status() argument
772 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | in usb3_set_p0_con_for_ctrl_write_status()
777 static void usb3_set_p0_con_for_no_data(struct renesas_usb3 *usb3) in usb3_set_p0_con_for_no_data() argument
779 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | in usb3_set_p0_con_for_no_data()
784 static void usb3_set_p0_con_stall(struct renesas_usb3 *usb3) in usb3_set_p0_con_stall() argument
786 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_STALL | in usb3_set_p0_con_stall()
791 static void usb3_set_p0_con_stop(struct renesas_usb3 *usb3) in usb3_set_p0_con_stop() argument
793 usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | in usb3_set_p0_con_stop()
798 static int usb3_pn_change(struct renesas_usb3 *usb3, int num) in usb3_pn_change() argument
800 if (num == 0 || num > usb3->num_usb3_eps) in usb3_pn_change()
803 usb3_write(usb3, num, USB3_PIPE_COM); in usb3_pn_change()
808 static void usb3_set_pn_con_update_res(struct renesas_usb3 *usb3, u32 res) in usb3_set_pn_con_update_res() argument
810 u32 val = usb3_read(usb3, USB3_PN_CON); in usb3_set_pn_con_update_res()
815 usb3_write(usb3, val, USB3_PN_CON); in usb3_set_pn_con_update_res()
818 static void usb3_pn_start(struct renesas_usb3 *usb3) in usb3_pn_start() argument
820 usb3_set_pn_con_update_res(usb3, PN_CON_RES_NORMAL); in usb3_pn_start()
823 static void usb3_pn_stop(struct renesas_usb3 *usb3) in usb3_pn_stop() argument
825 usb3_set_pn_con_update_res(usb3, PN_CON_RES_FORCE_NRDY); in usb3_pn_stop()
828 static void usb3_pn_stall(struct renesas_usb3 *usb3) in usb3_pn_stall() argument
830 usb3_set_pn_con_update_res(usb3, PN_CON_RES_FORCE_STALL); in usb3_pn_stall()
833 static int usb3_pn_con_clear(struct renesas_usb3 *usb3) in usb3_pn_con_clear() argument
835 usb3_set_bit(usb3, PN_CON_CLR, USB3_PN_CON); in usb3_pn_con_clear()
837 return usb3_wait(usb3, USB3_PN_CON, PN_CON_CLR, 0); in usb3_pn_con_clear()
854 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_wait_pipe_status() local
857 return usb3_wait(usb3, sta_reg, mask, mask); in usb3_wait_pipe_status()
863 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_set_px_con_send() local
865 u32 val = usb3_read(usb3, con_reg); in usb3_set_px_con_send()
869 usb3_write(usb3, val, con_reg); in usb3_set_px_con_send()
876 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_write_pipe() local
892 iowrite32_rep(usb3->reg + fifo_reg, buf, len / 4); in usb3_write_pipe()
900 usb3_write(usb3, tmp, fifo_reg); in usb3_write_pipe()
913 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_get_received_length() local
916 return usb3_read(usb3, lng_reg); in usb3_get_received_length()
922 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_read_pipe() local
937 ioread32_rep(usb3->reg + fifo_reg, buf, len / 4); in usb3_read_pipe()
943 tmp = usb3_read(usb3, fifo_reg); in usb3_read_pipe()
954 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_set_status_stage() local
957 usb3_set_p0_con_for_ctrl_read_status(usb3); in usb3_set_status_stage()
960 usb3_set_p0_con_for_no_data(usb3); in usb3_set_status_stage()
962 usb3_set_p0_con_for_ctrl_write_status(usb3); in usb3_set_status_stage()
983 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_start_pipe0() local
991 usb3_set_bit(usb3, P0_MOD_DIR, USB3_P0_MOD); in usb3_start_pipe0()
992 usb3_set_p0_con_for_ctrl_read_data(usb3); in usb3_start_pipe0()
994 usb3_clear_bit(usb3, P0_MOD_DIR, USB3_P0_MOD); in usb3_start_pipe0()
996 usb3_set_p0_con_for_ctrl_write_data(usb3); in usb3_start_pipe0()
1005 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_start_pipen() local
1016 spin_lock_irqsave(&usb3->lock, flags); in usb3_start_pipen()
1017 if (usb3_pn_change(usb3, usb3_ep->num) < 0) in usb3_start_pipen()
1021 usb3_pn_start(usb3); in usb3_start_pipen()
1032 usb3_set_bit(usb3, enable_bits, USB3_PN_INT_ENA); in usb3_start_pipen()
1033 usb3_enable_pipe_irq(usb3, usb3_ep->num); in usb3_start_pipen()
1036 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_start_pipen()
1044 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in renesas_usb3_ep_queue() local
1047 dev_dbg(usb3_to_dev(usb3), "ep_queue: ep%2d, %u\n", usb3_ep->num, in renesas_usb3_ep_queue()
1052 spin_lock_irqsave(&usb3->lock, flags); in renesas_usb3_ep_queue()
1054 spin_unlock_irqrestore(&usb3->lock, flags); in renesas_usb3_ep_queue()
1064 static void usb3_set_device_address(struct renesas_usb3 *usb3, u16 addr) in usb3_set_device_address() argument
1067 usb3_set_bit(usb3, USB_COM_CON_DEV_ADDR(addr), USB3_USB_COM_CON); in usb3_set_device_address()
1070 static bool usb3_std_req_set_address(struct renesas_usb3 *usb3, in usb3_std_req_set_address() argument
1076 usb3_set_device_address(usb3, ctrl->wValue); in usb3_std_req_set_address()
1077 usb3_set_p0_con_for_no_data(usb3); in usb3_std_req_set_address()
1082 static void usb3_pipe0_internal_xfer(struct renesas_usb3 *usb3, in usb3_pipe0_internal_xfer() argument
1087 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_pipe0_internal_xfer()
1090 memcpy(usb3->ep0_buf, tx_data, in usb3_pipe0_internal_xfer()
1093 usb3->ep0_req->buf = &usb3->ep0_buf; in usb3_pipe0_internal_xfer()
1094 usb3->ep0_req->length = len; in usb3_pipe0_internal_xfer()
1095 usb3->ep0_req->complete = complete; in usb3_pipe0_internal_xfer()
1096 renesas_usb3_ep_queue(&usb3_ep->ep, usb3->ep0_req, GFP_ATOMIC); in usb3_pipe0_internal_xfer()
1104 static bool usb3_std_req_get_status(struct renesas_usb3 *usb3, in usb3_std_req_get_status() argument
1114 if (usb3->gadget.is_selfpowered) in usb3_std_req_get_status()
1116 if (usb3->gadget.speed == USB_SPEED_SUPER) in usb3_std_req_get_status()
1117 status |= usb3_feature_get_un_enabled(usb3); in usb3_std_req_get_status()
1123 usb3_ep = usb3_get_ep(usb3, num); in usb3_std_req_get_status()
1134 dev_dbg(usb3_to_dev(usb3), "get_status: req = %p\n", in usb3_std_req_get_status()
1135 usb_req_to_usb3_req(usb3->ep0_req)); in usb3_std_req_get_status()
1136 usb3_pipe0_internal_xfer(usb3, &status, sizeof(status), in usb3_std_req_get_status()
1143 static bool usb3_std_req_feature_device(struct renesas_usb3 *usb3, in usb3_std_req_feature_device() argument
1153 usb3->test_mode = le16_to_cpu(ctrl->wIndex) >> 8; in usb3_std_req_feature_device()
1158 if (usb3->gadget.speed != USB_SPEED_SUPER) in usb3_std_req_feature_device()
1161 usb3_feature_u1_enable(usb3, set); in usb3_std_req_feature_device()
1163 usb3_feature_u2_enable(usb3, set); in usb3_std_req_feature_device()
1175 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_set_halt_p0() local
1182 usb3_set_p0_con_stall(usb3); in usb3_set_halt_p0()
1184 usb3_set_p0_con_stop(usb3); in usb3_set_halt_p0()
1192 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_set_halt_pn() local
1195 spin_lock_irqsave(&usb3->lock, flags); in usb3_set_halt_pn()
1196 if (!usb3_pn_change(usb3, usb3_ep->num)) { in usb3_set_halt_pn()
1199 usb3_pn_stall(usb3); in usb3_set_halt_pn()
1201 usb3_pn_con_clear(usb3); in usb3_set_halt_pn()
1202 usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); in usb3_set_halt_pn()
1203 usb3_pn_stop(usb3); in usb3_set_halt_pn()
1206 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_set_halt_pn()
1227 static bool usb3_std_req_feature_endpoint(struct renesas_usb3 *usb3, in usb3_std_req_feature_endpoint() argument
1238 usb3_ep = usb3_get_ep(usb3, num); in usb3_std_req_feature_endpoint()
1252 static bool usb3_std_req_feature(struct renesas_usb3 *usb3, in usb3_std_req_feature() argument
1259 stall = usb3_std_req_feature_device(usb3, ctrl, set); in usb3_std_req_feature()
1264 stall = usb3_std_req_feature_endpoint(usb3, ctrl, set); in usb3_std_req_feature()
1272 usb3_set_p0_con_for_no_data(usb3); in usb3_std_req_feature()
1283 static bool usb3_std_req_set_sel(struct renesas_usb3 *usb3, in usb3_std_req_set_sel() argument
1291 dev_dbg(usb3_to_dev(usb3), "set_sel: req = %p\n", in usb3_std_req_set_sel()
1292 usb_req_to_usb3_req(usb3->ep0_req)); in usb3_std_req_set_sel()
1293 usb3_pipe0_internal_xfer(usb3, NULL, 6, usb3_pipe0_set_sel_completion); in usb3_std_req_set_sel()
1298 static bool usb3_std_req_set_configuration(struct renesas_usb3 *usb3, in usb3_std_req_set_configuration() argument
1302 usb3_set_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); in usb3_std_req_set_configuration()
1304 usb3_clear_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); in usb3_std_req_set_configuration()
1316 static bool usb3_handle_standard_request(struct renesas_usb3 *usb3, in usb3_handle_standard_request() argument
1325 stall = usb3_std_req_set_address(usb3, ctrl); in usb3_handle_standard_request()
1329 stall = usb3_std_req_get_status(usb3, ctrl); in usb3_handle_standard_request()
1333 stall = usb3_std_req_feature(usb3, ctrl, false); in usb3_handle_standard_request()
1337 stall = usb3_std_req_feature(usb3, ctrl, true); in usb3_handle_standard_request()
1341 stall = usb3_std_req_set_sel(usb3, ctrl); in usb3_handle_standard_request()
1350 usb3_std_req_set_configuration(usb3, ctrl); in usb3_handle_standard_request()
1358 usb3_set_p0_con_stall(usb3); in usb3_handle_standard_request()
1363 static int usb3_p0_con_clear_buffer(struct renesas_usb3 *usb3) in usb3_p0_con_clear_buffer() argument
1365 usb3_set_bit(usb3, P0_CON_BCLR, USB3_P0_CON); in usb3_p0_con_clear_buffer()
1367 return usb3_wait(usb3, USB3_P0_CON, P0_CON_BCLR, 0); in usb3_p0_con_clear_buffer()
1370 static void usb3_irq_epc_pipe0_setup(struct renesas_usb3 *usb3) in usb3_irq_epc_pipe0_setup() argument
1373 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_irq_epc_pipe0_setup()
1380 usb3_p0_con_clear_buffer(usb3); in usb3_irq_epc_pipe0_setup()
1381 usb3_get_setup_data(usb3, &ctrl); in usb3_irq_epc_pipe0_setup()
1382 if (!usb3_handle_standard_request(usb3, &ctrl)) in usb3_irq_epc_pipe0_setup()
1383 if (usb3->driver->setup(&usb3->gadget, &ctrl) < 0) in usb3_irq_epc_pipe0_setup()
1384 usb3_set_p0_con_stall(usb3); in usb3_irq_epc_pipe0_setup()
1387 static void usb3_irq_epc_pipe0_bfrdy(struct renesas_usb3 *usb3) in usb3_irq_epc_pipe0_bfrdy() argument
1389 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); in usb3_irq_epc_pipe0_bfrdy()
1398 static void usb3_irq_epc_pipe0(struct renesas_usb3 *usb3) in usb3_irq_epc_pipe0() argument
1400 u32 p0_int_sta = usb3_read(usb3, USB3_P0_INT_STA); in usb3_irq_epc_pipe0()
1402 p0_int_sta &= usb3_read(usb3, USB3_P0_INT_ENA); in usb3_irq_epc_pipe0()
1403 usb3_write(usb3, p0_int_sta, USB3_P0_INT_STA); in usb3_irq_epc_pipe0()
1405 usb3_irq_epc_pipe0_status_end(usb3); in usb3_irq_epc_pipe0()
1407 usb3_irq_epc_pipe0_setup(usb3); in usb3_irq_epc_pipe0()
1409 usb3_irq_epc_pipe0_bfrdy(usb3); in usb3_irq_epc_pipe0()
1412 static void usb3_request_done_pipen(struct renesas_usb3 *usb3, in usb3_request_done_pipen() argument
1419 spin_lock_irqsave(&usb3->lock, flags); in usb3_request_done_pipen()
1420 if (usb3_pn_change(usb3, usb3_ep->num)) in usb3_request_done_pipen()
1421 usb3_pn_stop(usb3); in usb3_request_done_pipen()
1422 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_request_done_pipen()
1424 usb3_disable_pipe_irq(usb3, usb3_ep->num); in usb3_request_done_pipen()
1433 static void usb3_irq_epc_pipen_lsttr(struct renesas_usb3 *usb3, int num) in usb3_irq_epc_pipen_lsttr() argument
1435 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num); in usb3_irq_epc_pipen_lsttr()
1442 dev_dbg(usb3_to_dev(usb3), "%s: len = %u, actual = %u\n", in usb3_irq_epc_pipen_lsttr()
1444 usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0); in usb3_irq_epc_pipen_lsttr()
1448 static void usb3_irq_epc_pipen_bfrdy(struct renesas_usb3 *usb3, int num) in usb3_irq_epc_pipen_bfrdy() argument
1450 struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num); in usb3_irq_epc_pipen_bfrdy()
1457 spin_lock(&usb3->lock); in usb3_irq_epc_pipen_bfrdy()
1458 if (usb3_pn_change(usb3, num)) in usb3_irq_epc_pipen_bfrdy()
1464 usb3_clear_bit(usb3, PN_INT_BFRDY, USB3_PN_INT_ENA); in usb3_irq_epc_pipen_bfrdy()
1472 spin_unlock(&usb3->lock); in usb3_irq_epc_pipen_bfrdy()
1475 usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0); in usb3_irq_epc_pipen_bfrdy()
1478 static void usb3_irq_epc_pipen(struct renesas_usb3 *usb3, int num) in usb3_irq_epc_pipen() argument
1482 spin_lock(&usb3->lock); in usb3_irq_epc_pipen()
1483 if (usb3_pn_change(usb3, num) < 0) { in usb3_irq_epc_pipen()
1484 spin_unlock(&usb3->lock); in usb3_irq_epc_pipen()
1488 pn_int_sta = usb3_read(usb3, USB3_PN_INT_STA); in usb3_irq_epc_pipen()
1489 pn_int_sta &= usb3_read(usb3, USB3_PN_INT_ENA); in usb3_irq_epc_pipen()
1490 usb3_write(usb3, pn_int_sta, USB3_PN_INT_STA); in usb3_irq_epc_pipen()
1491 spin_unlock(&usb3->lock); in usb3_irq_epc_pipen()
1493 usb3_irq_epc_pipen_lsttr(usb3, num); in usb3_irq_epc_pipen()
1495 usb3_irq_epc_pipen_bfrdy(usb3, num); in usb3_irq_epc_pipen()
1498 static void usb3_irq_epc_int_2(struct renesas_usb3 *usb3, u32 int_sta_2) in usb3_irq_epc_int_2() argument
1502 for (i = 0; i < usb3->num_usb3_eps; i++) { in usb3_irq_epc_int_2()
1505 usb3_irq_epc_pipe0(usb3); in usb3_irq_epc_int_2()
1507 usb3_irq_epc_pipen(usb3, i); in usb3_irq_epc_int_2()
1512 static void usb3_irq_epc(struct renesas_usb3 *usb3) in usb3_irq_epc() argument
1514 u32 int_sta_1 = usb3_read(usb3, USB3_USB_INT_STA_1); in usb3_irq_epc()
1515 u32 int_sta_2 = usb3_read(usb3, USB3_USB_INT_STA_2); in usb3_irq_epc()
1517 int_sta_1 &= usb3_read(usb3, USB3_USB_INT_ENA_1); in usb3_irq_epc()
1519 usb3_write(usb3, int_sta_1, USB3_USB_INT_STA_1); in usb3_irq_epc()
1520 usb3_irq_epc_int_1(usb3, int_sta_1); in usb3_irq_epc()
1523 int_sta_2 &= usb3_read(usb3, USB3_USB_INT_ENA_2); in usb3_irq_epc()
1525 usb3_irq_epc_int_2(usb3, int_sta_2); in usb3_irq_epc()
1530 struct renesas_usb3 *usb3 = _usb3; in renesas_usb3_irq() local
1532 u32 axi_int_sta = usb3_read(usb3, USB3_AXI_INT_STA); in renesas_usb3_irq()
1535 usb3_irq_epc(usb3); in renesas_usb3_irq()
1545 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_write_pn_mod() local
1551 usb3_write(usb3, val, USB3_PN_MOD); in usb3_write_pn_mod()
1588 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_enable_pipe_n() local
1593 spin_lock_irqsave(&usb3->lock, flags); in usb3_enable_pipe_n()
1594 if (!usb3_pn_change(usb3, usb3_ep->num)) { in usb3_enable_pipe_n()
1596 usb3_write(usb3, usb3_calc_rammap_val(usb3_ep, desc), in usb3_enable_pipe_n()
1598 usb3_pn_con_clear(usb3); in usb3_enable_pipe_n()
1599 usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); in usb3_enable_pipe_n()
1601 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_enable_pipe_n()
1608 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in usb3_disable_pipe_n() local
1613 spin_lock_irqsave(&usb3->lock, flags); in usb3_disable_pipe_n()
1614 if (!usb3_pn_change(usb3, usb3_ep->num)) { in usb3_disable_pipe_n()
1615 usb3_write(usb3, 0, USB3_PN_RAMMAP); in usb3_disable_pipe_n()
1616 usb3_clear_bit(usb3, PN_CON_EN, USB3_PN_CON); in usb3_disable_pipe_n()
1618 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_disable_pipe_n()
1683 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in renesas_usb3_ep_dequeue() local
1685 dev_dbg(usb3_to_dev(usb3), "ep_dequeue: ep%2d, %u\n", usb3_ep->num, in renesas_usb3_ep_dequeue()
1688 usb3_request_done_pipen(usb3, usb3_ep, usb3_req, -ECONNRESET); in renesas_usb3_ep_dequeue()
1709 struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); in renesas_usb3_ep_fifo_flush() local
1713 spin_lock_irqsave(&usb3->lock, flags); in renesas_usb3_ep_fifo_flush()
1714 if (!usb3_pn_change(usb3, usb3_ep->num)) { in renesas_usb3_ep_fifo_flush()
1715 usb3_pn_con_clear(usb3); in renesas_usb3_ep_fifo_flush()
1716 usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); in renesas_usb3_ep_fifo_flush()
1718 spin_unlock_irqrestore(&usb3->lock, flags); in renesas_usb3_ep_fifo_flush()
1720 usb3_p0_con_clear_buffer(usb3); in renesas_usb3_ep_fifo_flush()
1743 struct renesas_usb3 *usb3; in renesas_usb3_start() local
1749 usb3 = gadget_to_renesas_usb3(gadget); in renesas_usb3_start()
1752 usb3->driver = driver; in renesas_usb3_start()
1754 pm_runtime_enable(usb3_to_dev(usb3)); in renesas_usb3_start()
1755 pm_runtime_get_sync(usb3_to_dev(usb3)); in renesas_usb3_start()
1757 renesas_usb3_init_controller(usb3); in renesas_usb3_start()
1764 struct renesas_usb3 *usb3 = gadget_to_renesas_usb3(gadget); in renesas_usb3_stop() local
1766 usb3->softconnect = false; in renesas_usb3_stop()
1767 usb3->gadget.speed = USB_SPEED_UNKNOWN; in renesas_usb3_stop()
1768 usb3->driver = NULL; in renesas_usb3_stop()
1769 renesas_usb3_stop_controller(usb3); in renesas_usb3_stop()
1771 pm_runtime_put(usb3_to_dev(usb3)); in renesas_usb3_stop()
1772 pm_runtime_disable(usb3_to_dev(usb3)); in renesas_usb3_stop()
1784 struct renesas_usb3 *usb3 = gadget_to_renesas_usb3(gadget); in renesas_usb3_pullup() local
1786 usb3->softconnect = !!is_on; in renesas_usb3_pullup()
1809 struct renesas_usb3 *usb3 = platform_get_drvdata(pdev); in renesas_usb3_remove() local
1811 usb_del_gadget_udc(&usb3->gadget); in renesas_usb3_remove()
1813 __renesas_usb3_ep_free_request(usb3->ep0_req); in renesas_usb3_remove()
1818 static int renesas_usb3_init_ep(struct renesas_usb3 *usb3, struct device *dev, in renesas_usb3_init_ep() argument
1825 usb3->num_usb3_eps = priv->ramsize_per_ramif * priv->num_ramif * 2 / in renesas_usb3_init_ep()
1828 if (usb3->num_usb3_eps > USB3_MAX_NUM_PIPES) in renesas_usb3_init_ep()
1829 usb3->num_usb3_eps = USB3_MAX_NUM_PIPES; in renesas_usb3_init_ep()
1831 usb3->usb3_ep = devm_kzalloc(dev, sizeof(*usb3_ep) * usb3->num_usb3_eps, in renesas_usb3_init_ep()
1833 if (!usb3->usb3_ep) in renesas_usb3_init_ep()
1836 dev_dbg(dev, "%s: num_usb3_eps = %d\n", __func__, usb3->num_usb3_eps); in renesas_usb3_init_ep()
1842 usb3_for_each_ep(usb3_ep, usb3, i) { in renesas_usb3_init_ep()
1844 usb3_ep->usb3 = usb3; in renesas_usb3_init_ep()
1852 usb3->gadget.ep0 = &usb3_ep->ep; in renesas_usb3_init_ep()
1863 list_add_tail(&usb3_ep->ep.ep_list, &usb3->gadget.ep_list); in renesas_usb3_init_ep()
1875 static void renesas_usb3_init_ram(struct renesas_usb3 *usb3, struct device *dev, in renesas_usb3_init_ram() argument
1892 usb3_for_each_ep(usb3_ep, usb3, i) { in renesas_usb3_init_ram()
1943 struct renesas_usb3 *usb3; in renesas_usb3_probe() local
1958 usb3 = devm_kzalloc(&pdev->dev, sizeof(*usb3), GFP_KERNEL); in renesas_usb3_probe()
1959 if (!usb3) in renesas_usb3_probe()
1963 usb3->reg = devm_ioremap_resource(&pdev->dev, res); in renesas_usb3_probe()
1964 if (IS_ERR(usb3->reg)) in renesas_usb3_probe()
1965 return PTR_ERR(usb3->reg); in renesas_usb3_probe()
1967 platform_set_drvdata(pdev, usb3); in renesas_usb3_probe()
1968 spin_lock_init(&usb3->lock); in renesas_usb3_probe()
1970 usb3->gadget.ops = &renesas_usb3_gadget_ops; in renesas_usb3_probe()
1971 usb3->gadget.name = udc_name; in renesas_usb3_probe()
1972 usb3->gadget.max_speed = USB_SPEED_SUPER; in renesas_usb3_probe()
1973 INIT_LIST_HEAD(&usb3->gadget.ep_list); in renesas_usb3_probe()
1974 ret = renesas_usb3_init_ep(usb3, &pdev->dev, priv); in renesas_usb3_probe()
1977 renesas_usb3_init_ram(usb3, &pdev->dev, priv); in renesas_usb3_probe()
1980 dev_name(&pdev->dev), usb3); in renesas_usb3_probe()
1985 usb3->ep0_req = __renesas_usb3_ep_alloc_request(GFP_KERNEL); in renesas_usb3_probe()
1986 if (!usb3->ep0_req) in renesas_usb3_probe()
1989 ret = usb_add_gadget_udc(&pdev->dev, &usb3->gadget); in renesas_usb3_probe()
1993 usb3->workaround_for_vbus = priv->workaround_for_vbus; in renesas_usb3_probe()
2000 __renesas_usb3_ep_free_request(usb3->ep0_req); in renesas_usb3_probe()