Lines Matching +full:wuc +full:- +full:base
4 * SPDX-License-Identifier: Apache-2.0
18 #include <zephyr/dt-bindings/interrupt-controller/it8xxx2-wuc.h>
81 #define DC_CONNECT_TO_HOST BIT(6) /* internal pull-up */
126 /* WUC control device structure */
128 /* WUC pin mask */
133 struct usb_it82xx2_regs *const base; member
144 .base = (struct usb_it82xx2_regs *)DT_INST_REG_ADDR(0),
193 const struct usb_it82xx2_config *cfg = dev->config; in it82xx2_get_usb_regs()
194 struct usb_it82xx2_regs *const usb_regs = cfg->base; in it82xx2_get_usb_regs()
203 usb_regs->dc_interrupt_status = DC_SOF_RECEIVED; in it82xx2_enable_sof_int()
205 usb_regs->dc_interrupt_mask |= DC_SOF_RECEIVED; in it82xx2_enable_sof_int()
207 usb_regs->dc_interrupt_mask &= ~DC_SOF_RECEIVED; in it82xx2_enable_sof_int()
215 usb_regs->dc_interrupt_status = DC_RESUME_INT; in it82xx2_enable_resume_int()
217 usb_regs->dc_interrupt_mask |= DC_RESUME_INT; in it82xx2_enable_resume_int()
219 usb_regs->dc_interrupt_mask &= ~DC_RESUME_INT; in it82xx2_enable_resume_int()
236 const struct usb_it82xx2_config *cfg = dev->config; in it82xx2_enable_wu90_irq()
239 it8xxx2_wuc_clear_status(cfg->wuc_list[0].wucs, cfg->wuc_list[0].mask); in it82xx2_enable_wu90_irq()
258 const struct usb_it82xx2_config *cfg = dev->config; in it8xxx2_usb_dc_wuc_init()
261 it8xxx2_wuc_set_polarity(cfg->wuc_list[0].wucs, in it8xxx2_usb_dc_wuc_init()
262 cfg->wuc_list[0].mask, in it8xxx2_usb_dc_wuc_init()
264 it8xxx2_wuc_clear_status(cfg->wuc_list[0].wucs, in it8xxx2_usb_dc_wuc_init()
265 cfg->wuc_list[0].mask); in it8xxx2_usb_dc_wuc_init()
268 it8xxx2_wuc_enable(cfg->wuc_list[0].wucs, cfg->wuc_list[0].mask); in it8xxx2_usb_dc_wuc_init()
277 volatile uint8_t *ep_fifo_ctrl = usb_regs->fifo_regs[EP_EXT_REGS_BX].fifo_ctrl.ep_fifo_ctrl; in it82xx2_usb_fifo_ctrl()
279 uint8_t fifon_ctrl = (ep_fifo_res[ep_idx % FIFO_NUM] - 1) * 2; in it82xx2_usb_fifo_ctrl()
285 return -EINVAL; in it82xx2_usb_fifo_ctrl()
301 ep_fifo_ctrl[fifon_ctrl + 1] = BIT(ep_idx - 8); in it82xx2_usb_fifo_ctrl()
308 ep_fifo_ctrl[fifon_ctrl + 1] |= BIT(ep_idx - 8); in it82xx2_usb_fifo_ctrl()
312 ret = -EINVAL; in it82xx2_usb_fifo_ctrl()
325 usb_regs->fifo_regs[EP_EXT_REGS_9X].ext_4_15.epn0n1_ext_ctrl; in it82xx2_get_ext_ctrl()
327 usb_regs->fifo_regs[EP_EXT_REGS_DX].ext_0_3.epn_ext_ctrl; in it82xx2_get_ext_ctrl()
330 idx = ((ep_idx - 4) % 3) + 1; in it82xx2_get_ext_ctrl()
334 idx = (ep_idx - 4) / 2; in it82xx2_get_ext_ctrl()
341 struct it82xx2_usb_ep_regs *ep_regs = usb_regs->usb_ep_regs; in it82xx2_usb_extend_ep_ctrl()
343 usb_regs->fifo_regs[EP_EXT_REGS_DX].ext_0_3.epn_ext_ctrl; in it82xx2_usb_extend_ep_ctrl()
350 return -EINVAL; in it82xx2_usb_extend_ep_ctrl()
363 epn0n1_ext_ctrl->fields.epn1_send_stall_bit = enable; in it82xx2_usb_extend_ep_ctrl()
365 epn0n1_ext_ctrl->fields.epn0_send_stall_bit = enable; in it82xx2_usb_extend_ep_ctrl()
370 return epn0n1_ext_ctrl->fields.epn1_send_stall_bit; in it82xx2_usb_extend_ep_ctrl()
372 return epn0n1_ext_ctrl->fields.epn0_send_stall_bit; in it82xx2_usb_extend_ep_ctrl()
377 epn0n1_ext_ctrl->fields.epn1_iso_enable_bit = enable; in it82xx2_usb_extend_ep_ctrl()
379 epn0n1_ext_ctrl->fields.epn0_iso_enable_bit = enable; in it82xx2_usb_extend_ep_ctrl()
384 epn0n1_ext_ctrl->fields.epn1_outdata_sequence_bit = enable; in it82xx2_usb_extend_ep_ctrl()
386 epn0n1_ext_ctrl->fields.epn0_outdata_sequence_bit = enable; in it82xx2_usb_extend_ep_ctrl()
394 if (epn0n1_ext_ctrl->fields.epn1_outdata_sequence_bit) { in it82xx2_usb_extend_ep_ctrl()
395 epn0n1_ext_ctrl->fields.epn1_outdata_sequence_bit = 0; in it82xx2_usb_extend_ep_ctrl()
397 epn0n1_ext_ctrl->fields.epn1_outdata_sequence_bit = 1; in it82xx2_usb_extend_ep_ctrl()
400 if (epn0n1_ext_ctrl->fields.epn0_outdata_sequence_bit) { in it82xx2_usb_extend_ep_ctrl()
401 epn0n1_ext_ctrl->fields.epn0_outdata_sequence_bit = 0; in it82xx2_usb_extend_ep_ctrl()
403 epn0n1_ext_ctrl->fields.epn0_outdata_sequence_bit = 1; in it82xx2_usb_extend_ep_ctrl()
408 if (((ep_idx - 4) / 3 == 0)) { in it82xx2_usb_extend_ep_ctrl()
409 epn_ext_ctrl1->fields.epn0_direction_bit = enable; in it82xx2_usb_extend_ep_ctrl()
410 } else if (((ep_idx - 4) / 3 == 1)) { in it82xx2_usb_extend_ep_ctrl()
411 epn_ext_ctrl1->fields.epn3_direction_bit = enable; in it82xx2_usb_extend_ep_ctrl()
412 } else if (((ep_idx - 4) / 3 == 2)) { in it82xx2_usb_extend_ep_ctrl()
413 epn_ext_ctrl1->fields.epn6_direction_bit = enable; in it82xx2_usb_extend_ep_ctrl()
414 } else if (((ep_idx - 4) / 3 == 3)) { in it82xx2_usb_extend_ep_ctrl()
415 epn_ext_ctrl1->fields.epn9_direction_bit = enable; in it82xx2_usb_extend_ep_ctrl()
418 return -EINVAL; in it82xx2_usb_extend_ep_ctrl()
422 if (((ep_idx - 4) / 3 == 0)) { in it82xx2_usb_extend_ep_ctrl()
423 epn_ext_ctrl1->fields.epn0_enable_bit = enable; in it82xx2_usb_extend_ep_ctrl()
424 } else if (((ep_idx - 4) / 3 == 1)) { in it82xx2_usb_extend_ep_ctrl()
425 epn_ext_ctrl1->fields.epn3_enable_bit = enable; in it82xx2_usb_extend_ep_ctrl()
426 } else if (((ep_idx - 4) / 3 == 2)) { in it82xx2_usb_extend_ep_ctrl()
427 epn_ext_ctrl1->fields.epn6_enable_bit = enable; in it82xx2_usb_extend_ep_ctrl()
428 } else if (((ep_idx - 4) / 3 == 3)) { in it82xx2_usb_extend_ep_ctrl()
429 epn_ext_ctrl1->fields.epn9_enable_bit = enable; in it82xx2_usb_extend_ep_ctrl()
432 return -EINVAL; in it82xx2_usb_extend_ep_ctrl()
436 int idx = ((ep_idx - 4) % 3) + 1; in it82xx2_usb_extend_ep_ctrl()
438 (enable) ? (ext_ctrl[idx].epn_ext_ctrl2 |= BIT((ep_idx - 4) / 3)) in it82xx2_usb_extend_ep_ctrl()
439 : (ext_ctrl[idx].epn_ext_ctrl2 &= ~BIT((ep_idx - 4) / 3)); in it82xx2_usb_extend_ep_ctrl()
444 return -EINVAL; in it82xx2_usb_extend_ep_ctrl()
453 struct it82xx2_usb_ep_regs *ep_regs = usb_regs->usb_ep_regs; in it82xx2_usb_ep_ctrl()
458 return -EINVAL; in it82xx2_usb_ep_ctrl()
516 return -EINVAL; in it82xx2_usb_ep_ctrl()
544 usb_regs->host_device_control = RESET_CORE; in it82xx2_usb_dc_ip_init()
546 usb_regs->port0_misc_control &= ~(PULL_DOWN_EN); in it82xx2_usb_dc_ip_init()
547 usb_regs->port1_misc_control &= ~(PULL_DOWN_EN); in it82xx2_usb_dc_ip_init()
549 usb_regs->host_device_control = 0; in it82xx2_usb_dc_ip_init()
551 usb_regs->dc_interrupt_status = in it82xx2_usb_dc_ip_init()
554 usb_regs->dc_interrupt_mask = 0x00; in it82xx2_usb_dc_ip_init()
555 usb_regs->dc_interrupt_mask = in it82xx2_usb_dc_ip_init()
558 usb_regs->dc_address = DC_ADDR_NULL; in it82xx2_usb_dc_ip_init()
570 gctrl_regs->GCTRL_MCCR &= ~(IT8XXX2_GCTRL_MCCR_USB_EN); in it82xx2_usb_dc_attach_init()
571 gctrl_regs->gctrl_pmer2 |= IT8XXX2_GCTRL_PMER2_USB_PAD_EN; in it82xx2_usb_dc_attach_init()
580 struct it82xx2_usb_ep_regs *ep_regs = usb_regs->usb_ep_regs; in it82xx2_check_setup_following_out()
581 struct it82xx2_usb_ep_fifo_regs *ff_regs = usb_regs->fifo_regs; in it82xx2_check_setup_following_out()
591 struct it82xx2_usb_ep_regs *ep_regs = usb_regs->usb_ep_regs; in it82xx2_handler_setup()
592 struct it82xx2_usb_ep_fifo_regs *ff_regs = usb_regs->fifo_regs; in it82xx2_handler_setup()
605 /* setup -> in(data) -> out(status) */ in it82xx2_handler_setup()
612 /* setup -> out(data) -> in(status) in it82xx2_handler_setup()
614 * setup -> in(status) in it82xx2_handler_setup()
629 /* Set ready bit to no-data control in */ in it82xx2_handler_setup()
639 struct it82xx2_usb_ep_regs *ep_regs = usb_regs->usb_ep_regs; in it82xx2_handler_in()
657 udata0.addr != usb_regs->dc_address) { in it82xx2_handler_in()
658 usb_regs->dc_address = udata0.addr; in it82xx2_handler_in()
663 /* setup -> out(data) -> in(status) */ in it82xx2_handler_in()
668 /* setup -> in(status) */ in it82xx2_handler_in()
671 /* setup -> in(data) */ in it82xx2_handler_in()
687 k_sem_give(&udata0.fifo_sem[ep_fifo - 1]); in it82xx2_handler_in()
707 /* setup -> out(data) */ in it82xx2_handler_out()
710 /* setup -> in(data) -> out(status) */ in it82xx2_handler_out()
742 if (((ep_idx - 4) / 3 == 0)) { in get_extend_enable_bit()
743 enable = (epn_ext_ctrl1->fields.epn0_enable_bit != 0); in get_extend_enable_bit()
744 } else if (((ep_idx - 4) / 3 == 1)) { in get_extend_enable_bit()
745 enable = (epn_ext_ctrl1->fields.epn3_enable_bit != 0); in get_extend_enable_bit()
746 } else if (((ep_idx - 4) / 3 == 2)) { in get_extend_enable_bit()
747 enable = (epn_ext_ctrl1->fields.epn6_enable_bit != 0); in get_extend_enable_bit()
749 enable = (epn_ext_ctrl1->fields.epn9_enable_bit != 0); in get_extend_enable_bit()
759 usb_regs->fifo_regs[EP_EXT_REGS_DX].ext_0_3.epn_ext_ctrl; in get_extend_ready_bit()
760 int idx = ((ep_idx - 4) % 3) + 1; in get_extend_ready_bit()
762 return ((ext_ctrl[idx].epn_ext_ctrl2 & BIT((ep_idx - 4) / 3)) != 0); in get_extend_ready_bit()
768 volatile uint8_t *ep_fifo_ctrl = usb_regs->fifo_regs[EP_EXT_REGS_BX].fifo_ctrl.ep_fifo_ctrl; in get_fifo_ctrl()
769 uint8_t fifon_ctrl = (fifo_idx - 1) * 2; in get_fifo_ctrl()
782 struct it82xx2_usb_ep_regs *ep_regs = usb_regs->usb_ep_regs; in it82xx2_usb_fake_token()
816 if (!udata0.fifo_ready[ep_fifo - 1] || in it82xx2_usb_fake_token()
820 udata0.fifo_ready[ep_fifo - 1] = false; in it82xx2_usb_fake_token()
837 usb_regs->fifo_regs[EP_EXT_REGS_DX].ext_0_3.epn_ext_ctrl; in it82xx2_usb_dc_trans_done()
884 uint8_t status = usb_regs->dc_interrupt_status & in it82xx2_usb_dc_isr()
885 usb_regs->dc_interrupt_mask; /* mask non enable int */ in it82xx2_usb_dc_isr()
889 if ((usb_regs->dc_line_status & RX_LINE_STATE_MASK) == in it82xx2_usb_dc_isr()
892 usb_regs->dc_interrupt_status = DC_RESET_EVENT; in it82xx2_usb_dc_isr()
895 usb_regs->dc_interrupt_status = DC_RESET_EVENT; in it82xx2_usb_dc_isr()
913 usb_regs->dc_interrupt_status = DC_TRANS_DONE; in it82xx2_usb_dc_isr()
929 if (usb_regs->dc_interrupt_status & DC_SOF_RECEIVED) { in suspended_check_handler()
930 usb_regs->dc_interrupt_status = DC_SOF_RECEIVED; in suspended_check_handler()
931 k_work_reschedule(&udata->check_suspended_work, K_MSEC(5)); in suspended_check_handler()
936 if (!udata->suspended) { in suspended_check_handler()
937 if (udata->usb_status_cb) { in suspended_check_handler()
938 (*(udata->usb_status_cb))(USB_DC_SUSPEND, NULL); in suspended_check_handler()
940 udata->suspended = true; in suspended_check_handler()
941 it82xx2_enable_wu90_irq(udata->dev, true); in suspended_check_handler()
944 k_sem_reset(&udata->suspended_sem); in suspended_check_handler()
994 usb_regs->dc_control = in usb_dc_attach()
1017 /* stop pull-up D+ D-*/ in usb_dc_detach()
1018 usb_regs->dc_control &= ~DC_CONNECT_TO_HOST; in usb_dc_detach()
1027 struct it82xx2_usb_ep_regs *ep_regs = usb_regs->usb_ep_regs; in usb_dc_reset()
1028 struct it82xx2_usb_ep_fifo_regs *ff_regs = usb_regs->fifo_regs; in usb_dc_reset()
1043 usb_regs->dc_address = DC_ADDR_NULL; in usb_dc_reset()
1045 usb_regs->dc_interrupt_status = DC_NAK_SENT_INT | DC_SOF_RECEIVED; in usb_dc_reset()
1068 uint8_t ep_idx = USB_EP_GET_IDX(cfg->ep_addr); in usb_dc_ep_check_cap()
1069 bool in = USB_EP_DIR_IS_IN(cfg->ep_addr); in usb_dc_ep_check_cap()
1071 if ((cfg->ep_type == USB_DC_EP_CONTROL) && ep_idx > EP0) { in usb_dc_ep_check_cap()
1073 return -EINVAL; in usb_dc_ep_check_cap()
1077 LOG_WRN("Invalid Endpoint Number 0x%02x", cfg->ep_addr); in usb_dc_ep_check_cap()
1078 return -EINVAL; in usb_dc_ep_check_cap()
1082 LOG_WRN("Invalid Endpoint Number 0x%02x", cfg->ep_addr); in usb_dc_ep_check_cap()
1083 return -EINVAL; in usb_dc_ep_check_cap()
1087 LOG_WRN("Invalid Endpoint Number 0x%02x", cfg->ep_addr); in usb_dc_ep_check_cap()
1088 return -EINVAL; in usb_dc_ep_check_cap()
1093 return -EINVAL; in usb_dc_ep_check_cap()
1097 udata0.ep_data[ep_idx].mps = cfg->ep_mps; in usb_dc_ep_check_cap()
1101 LOG_DBG("Check cap(%02x)", cfg->ep_addr); in usb_dc_ep_check_cap()
1108 uint8_t ep_idx = USB_EP_GET_IDX(cfg->ep_addr); in usb_dc_ep_configure()
1109 bool in = USB_EP_DIR_IS_IN(cfg->ep_addr); in usb_dc_ep_configure()
1112 LOG_DBG("Not attached / Invalid Endpoint: 0x%X", cfg->ep_addr); in usb_dc_ep_configure()
1113 return -EINVAL; in usb_dc_ep_configure()
1116 if (!cfg->ep_mps) { in usb_dc_ep_configure()
1118 return -EINVAL; in usb_dc_ep_configure()
1122 udata0.ep_data[ep_idx].mps = cfg->ep_mps; in usb_dc_ep_configure()
1138 it82xx2_usb_fifo_ctrl(cfg->ep_addr, false); in usb_dc_ep_configure()
1141 switch (cfg->ep_type) { in usb_dc_ep_configure()
1143 return -EINVAL; in usb_dc_ep_configure()
1156 udata0.ep_data[ep_idx].ep_type = cfg->ep_type; in usb_dc_ep_configure()
1158 LOG_DBG("EP%d Configured: 0x%2X(%d)", ep_idx, !!(in), cfg->ep_type); in usb_dc_ep_configure()
1169 return -EINVAL; in usb_dc_ep_set_callback()
1174 return -EINVAL; in usb_dc_ep_set_callback()
1195 return -EINVAL; in usb_dc_ep_enable()
1220 return -EINVAL; in usb_dc_ep_disable()
1230 struct it82xx2_usb_ep_regs *ep_regs = usb_regs->usb_ep_regs; in usb_dc_ep_set_stall()
1236 return -EINVAL; in usb_dc_ep_set_stall()
1249 gctrl_regs->GCTRL_WNCKR = 0; in usb_dc_ep_set_stall()
1272 return -EINVAL; in usb_dc_ep_clear_stall()
1286 return -EINVAL; in usb_dc_ep_is_stalled()
1302 struct it82xx2_usb_ep_fifo_regs *ff_regs = usb_regs->fifo_regs; in usb_dc_ep_flush()
1308 return -EINVAL; in usb_dc_ep_flush()
1324 struct it82xx2_usb_ep_fifo_regs *ff_regs = usb_regs->fifo_regs; in usb_dc_ep_write()
1330 return -EINVAL; in usb_dc_ep_write()
1344 k_sem_take(&udata0.fifo_sem[ep_fifo - 1], K_FOREVER); in usb_dc_ep_write()
1357 data_len - udata0.ep_data[ep_idx].mps; in usb_dc_ep_write()
1386 struct it82xx2_usb_ep_regs *ep_regs = usb_regs->usb_ep_regs; in usb_dc_ep_read()
1387 struct it82xx2_usb_ep_fifo_regs *ff_regs = usb_regs->fifo_regs; in usb_dc_ep_read()
1394 return -EINVAL; in usb_dc_ep_read()
1414 udata0.fifo_ready[ep_fifo - 1] = true; in usb_dc_ep_read()
1435 return -EIO; in usb_dc_ep_read()
1463 udata0.fifo_ready[ep_fifo - 1] = true; in usb_dc_ep_read()
1467 /* request type: host-to-device transfer direction */ in usb_dc_ep_read()
1488 struct it82xx2_usb_ep_regs *ep_regs = usb_regs->usb_ep_regs; in usb_dc_ep_read_wait()
1489 struct it82xx2_usb_ep_fifo_regs *ff_regs = usb_regs->fifo_regs; in usb_dc_ep_read_wait()
1497 return -EINVAL; in usb_dc_ep_read_wait()
1502 return -EINVAL; in usb_dc_ep_read_wait()
1533 return -EINVAL; in usb_dc_ep_read_continue()
1538 return -EINVAL; in usb_dc_ep_read_continue()
1541 udata0.fifo_ready[ep_fifo - 1] = true; in usb_dc_ep_read_continue()
1554 return -EINVAL; in usb_dc_ep_mps()
1572 usb_regs->dc_control = in usb_dc_wakeup_request()
1581 usb_regs->dc_control = in usb_dc_wakeup_request()
1595 const struct usb_it82xx2_config *cfg = dev->config; in it82xx2_usb_dc_init()
1597 int status = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); in it82xx2_usb_dc_init()