Lines Matching full:udc

101 	struct lpc32xx_udc	*udc;  member
123 * Common UDC structure
188 dev_dbg(epp->udc->dev, "%s: " fmt, __func__, ## arg)
190 dev_err(epp->udc->dev, "%s: " fmt, __func__, ## arg)
192 dev_info(epp->udc->dev, "%s: " fmt, __func__, ## arg)
194 dev_warn(epp->udc->dev, "%s:" fmt, __func__, ## arg)
471 static const char debug_filename[] = "driver/udc";
499 struct lpc32xx_udc *udc = s->private; in udc_show() local
505 spin_lock_irqsave(&udc->lock, flags); in udc_show()
508 udc->vbus ? "present" : "off", in udc_show()
509 udc->enabled ? (udc->vbus ? "active" : "enabled") : in udc_show()
511 udc->gadget.is_selfpowered ? "self" : "VBUS", in udc_show()
512 udc->suspended ? ", suspended" : "", in udc_show()
513 udc->driver ? udc->driver->driver.name : "(none)"); in udc_show()
515 if (udc->enabled && udc->vbus) { in udc_show()
516 proc_ep_show(s, &udc->ep[0]); in udc_show()
517 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) in udc_show()
521 spin_unlock_irqrestore(&udc->lock, flags); in udc_show()
526 DEFINE_SHOW_ATTRIBUTE(udc);
528 static void create_debug_file(struct lpc32xx_udc *udc) in create_debug_file() argument
530 debugfs_create_file(debug_filename, 0, NULL, udc, &udc_fops); in create_debug_file()
533 static void remove_debug_file(struct lpc32xx_udc *udc) in remove_debug_file() argument
539 static inline void create_debug_file(struct lpc32xx_udc *udc) {} in create_debug_file() argument
540 static inline void remove_debug_file(struct lpc32xx_udc *udc) {} in remove_debug_file() argument
544 static void isp1301_udc_configure(struct lpc32xx_udc *udc) in isp1301_udc_configure() argument
549 vendor = i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x00); in isp1301_udc_configure()
550 product = i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x02); in isp1301_udc_configure()
553 udc->atx = STOTG04; in isp1301_udc_configure()
559 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
564 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
566 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
572 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
576 if (udc->atx != STOTG04) in isp1301_udc_configure()
578 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
582 if (udc->board->vbus_drv_pol != 0) in isp1301_udc_configure()
583 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
586 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
593 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
595 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
600 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
603 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
607 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
610 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
612 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
615 dev_info(udc->dev, "ISP1301 Vendor ID : 0x%04x\n", vendor); in isp1301_udc_configure()
616 dev_info(udc->dev, "ISP1301 Product ID : 0x%04x\n", product); in isp1301_udc_configure()
617 dev_info(udc->dev, "ISP1301 Version ID : 0x%04x\n", in isp1301_udc_configure()
618 i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x14)); in isp1301_udc_configure()
623 static void isp1301_pullup_set(struct lpc32xx_udc *udc) in isp1301_pullup_set() argument
625 if (udc->pullup) in isp1301_pullup_set()
627 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_pullup_set()
631 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_pullup_set()
638 struct lpc32xx_udc *udc = in pullup_work() local
641 isp1301_pullup_set(udc); in pullup_work()
644 static void isp1301_pullup_enable(struct lpc32xx_udc *udc, int en_pullup, in isp1301_pullup_enable() argument
647 if (en_pullup == udc->pullup) in isp1301_pullup_enable()
650 udc->pullup = en_pullup; in isp1301_pullup_enable()
652 isp1301_pullup_set(udc); in isp1301_pullup_enable()
655 schedule_work(&udc->pullup_job); in isp1301_pullup_enable()
660 static void isp1301_set_powerstate(struct lpc32xx_udc *udc, int enable) in isp1301_set_powerstate() argument
663 if (udc->atx == STOTG04) in isp1301_set_powerstate()
669 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_set_powerstate()
674 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_set_powerstate()
680 struct lpc32xx_udc *udc = in power_work() local
683 isp1301_set_powerstate(udc, udc->poweron); in power_work()
693 static void udc_protocol_cmd_w(struct lpc32xx_udc *udc, u32 cmd) in udc_protocol_cmd_w() argument
699 u32 tmp = readl(USBD_DEVINTST(udc->udp_baseaddr)); in udc_protocol_cmd_w()
703 writel(USBD_CCEMPTY, USBD_DEVINTCLR(udc->udp_baseaddr)); in udc_protocol_cmd_w()
706 writel(cmd, USBD_CMDCODE(udc->udp_baseaddr)); in udc_protocol_cmd_w()
708 while (((readl(USBD_DEVINTST(udc->udp_baseaddr)) & in udc_protocol_cmd_w()
721 static inline void udc_protocol_cmd_data_w(struct lpc32xx_udc *udc, u32 cmd, in udc_protocol_cmd_data_w() argument
724 udc_protocol_cmd_w(udc, cmd); in udc_protocol_cmd_data_w()
725 udc_protocol_cmd_w(udc, data); in udc_protocol_cmd_data_w()
730 static u32 udc_protocol_cmd_r(struct lpc32xx_udc *udc, u32 cmd) in udc_protocol_cmd_r() argument
736 USBD_DEVINTCLR(udc->udp_baseaddr)); in udc_protocol_cmd_r()
739 udc_protocol_cmd_w(udc, cmd); in udc_protocol_cmd_r()
741 while ((!(readl(USBD_DEVINTST(udc->udp_baseaddr)) & USBD_CDFULL)) in udc_protocol_cmd_r()
745 dev_dbg(udc->dev, in udc_protocol_cmd_r()
748 return readl(USBD_CMDDATA(udc->udp_baseaddr)); in udc_protocol_cmd_r()
757 static inline void uda_enable_devint(struct lpc32xx_udc *udc, u32 devmask) in uda_enable_devint() argument
759 udc->enabled_devints |= devmask; in uda_enable_devint()
760 writel(udc->enabled_devints, USBD_DEVINTEN(udc->udp_baseaddr)); in uda_enable_devint()
764 static inline void uda_disable_devint(struct lpc32xx_udc *udc, u32 mask) in uda_disable_devint() argument
766 udc->enabled_devints &= ~mask; in uda_disable_devint()
767 writel(udc->enabled_devints, USBD_DEVINTEN(udc->udp_baseaddr)); in uda_disable_devint()
771 static inline void uda_clear_devint(struct lpc32xx_udc *udc, u32 mask) in uda_clear_devint() argument
773 writel(mask, USBD_DEVINTCLR(udc->udp_baseaddr)); in uda_clear_devint()
782 static void uda_enable_hwepint(struct lpc32xx_udc *udc, u32 hwep) in uda_enable_hwepint() argument
784 udc->enabled_hwepints |= (1 << hwep); in uda_enable_hwepint()
785 writel(udc->enabled_hwepints, USBD_EPINTEN(udc->udp_baseaddr)); in uda_enable_hwepint()
789 static void uda_disable_hwepint(struct lpc32xx_udc *udc, u32 hwep) in uda_disable_hwepint() argument
791 udc->enabled_hwepints &= ~(1 << hwep); in uda_disable_hwepint()
792 writel(udc->enabled_hwepints, USBD_EPINTEN(udc->udp_baseaddr)); in uda_disable_hwepint()
796 static inline void uda_clear_hwepint(struct lpc32xx_udc *udc, u32 hwep) in uda_clear_hwepint() argument
798 writel((1 << hwep), USBD_EPINTCLR(udc->udp_baseaddr)); in uda_clear_hwepint()
802 static inline void udc_ep_dma_enable(struct lpc32xx_udc *udc, u32 hwep) in udc_ep_dma_enable() argument
804 writel((1 << hwep), USBD_EPDMAEN(udc->udp_baseaddr)); in udc_ep_dma_enable()
808 static inline void udc_ep_dma_disable(struct lpc32xx_udc *udc, u32 hwep) in udc_ep_dma_disable() argument
810 writel((1 << hwep), USBD_EPDMADIS(udc->udp_baseaddr)); in udc_ep_dma_disable()
821 static void udc_realize_hwep(struct lpc32xx_udc *udc, u32 hwep, in udc_realize_hwep() argument
826 writel(USBD_EP_RLZED, USBD_DEVINTCLR(udc->udp_baseaddr)); in udc_realize_hwep()
827 writel(hwep, USBD_EPIND(udc->udp_baseaddr)); in udc_realize_hwep()
828 udc->realized_eps |= (1 << hwep); in udc_realize_hwep()
829 writel(udc->realized_eps, USBD_REEP(udc->udp_baseaddr)); in udc_realize_hwep()
830 writel(maxpacket, USBD_EPMAXPSIZE(udc->udp_baseaddr)); in udc_realize_hwep()
833 while ((!(readl(USBD_DEVINTST(udc->udp_baseaddr)) & in udc_realize_hwep()
837 dev_dbg(udc->dev, "EP not correctly realized in hardware\n"); in udc_realize_hwep()
839 writel(USBD_EP_RLZED, USBD_DEVINTCLR(udc->udp_baseaddr)); in udc_realize_hwep()
843 static void udc_unrealize_hwep(struct lpc32xx_udc *udc, u32 hwep) in udc_unrealize_hwep() argument
845 udc->realized_eps &= ~(1 << hwep); in udc_unrealize_hwep()
846 writel(udc->realized_eps, USBD_REEP(udc->udp_baseaddr)); in udc_unrealize_hwep()
855 static u32 udc_selep_clrint(struct lpc32xx_udc *udc, u32 hwep) in udc_selep_clrint() argument
857 udc_protocol_cmd_w(udc, CMD_SEL_EP_CLRI(hwep)); in udc_selep_clrint()
858 return udc_protocol_cmd_r(udc, DAT_SEL_EP_CLRI(hwep)); in udc_selep_clrint()
862 static void udc_disable_hwep(struct lpc32xx_udc *udc, u32 hwep) in udc_disable_hwep() argument
864 udc_protocol_cmd_data_w(udc, CMD_SET_EP_STAT(hwep), in udc_disable_hwep()
869 static void udc_stall_hwep(struct lpc32xx_udc *udc, u32 hwep) in udc_stall_hwep() argument
871 udc_protocol_cmd_data_w(udc, CMD_SET_EP_STAT(hwep), in udc_stall_hwep()
876 static void udc_clrstall_hwep(struct lpc32xx_udc *udc, u32 hwep) in udc_clrstall_hwep() argument
878 udc_protocol_cmd_data_w(udc, CMD_SET_EP_STAT(hwep), in udc_clrstall_hwep()
883 static void udc_select_hwep(struct lpc32xx_udc *udc, u32 hwep) in udc_select_hwep() argument
885 udc_protocol_cmd_w(udc, CMD_SEL_EP(hwep)); in udc_select_hwep()
894 static void udc_clr_buffer_hwep(struct lpc32xx_udc *udc, u32 hwep) in udc_clr_buffer_hwep() argument
896 udc_select_hwep(udc, hwep); in udc_clr_buffer_hwep()
897 udc_protocol_cmd_w(udc, CMD_CLR_BUF); in udc_clr_buffer_hwep()
901 static void udc_val_buffer_hwep(struct lpc32xx_udc *udc, u32 hwep) in udc_val_buffer_hwep() argument
903 udc_select_hwep(udc, hwep); in udc_val_buffer_hwep()
904 udc_protocol_cmd_w(udc, CMD_VALID_BUF); in udc_val_buffer_hwep()
907 static inline u32 udc_clearep_getsts(struct lpc32xx_udc *udc, u32 hwep) in udc_clearep_getsts() argument
910 uda_clear_hwepint(udc, hwep); in udc_clearep_getsts()
911 return udc_selep_clrint(udc, hwep); in udc_clearep_getsts()
920 static struct lpc32xx_usbd_dd_gad *udc_dd_alloc(struct lpc32xx_udc *udc) in udc_dd_alloc() argument
925 dd = dma_pool_alloc(udc->dd_cache, GFP_ATOMIC | GFP_DMA, &dma); in udc_dd_alloc()
933 static void udc_dd_free(struct lpc32xx_udc *udc, struct lpc32xx_usbd_dd_gad *dd) in udc_dd_free() argument
935 dma_pool_free(udc->dd_cache, dd, dd->this_dma); in udc_dd_free()
946 static void udc_clk_set(struct lpc32xx_udc *udc, int enable) in udc_clk_set() argument
949 if (udc->clocked) in udc_clk_set()
952 udc->clocked = 1; in udc_clk_set()
953 clk_prepare_enable(udc->usb_slv_clk); in udc_clk_set()
955 if (!udc->clocked) in udc_clk_set()
958 udc->clocked = 0; in udc_clk_set()
959 clk_disable_unprepare(udc->usb_slv_clk); in udc_clk_set()
964 static void udc_set_address(struct lpc32xx_udc *udc, u32 addr) in udc_set_address() argument
968 udc_protocol_cmd_data_w(udc, CMD_SET_ADDR, in udc_set_address()
975 static int udc_ep_in_req_dma(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) in udc_ep_in_req_dma() argument
986 udc->udca_v_base[hwep] = req->dd_desc_ptr->this_dma; in udc_ep_in_req_dma()
989 udc_ep_dma_enable(udc, hwep); in udc_ep_in_req_dma()
1001 static int udc_ep_out_req_dma(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) in udc_ep_out_req_dma() argument
1012 udc->udca_v_base[hwep] = req->dd_desc_ptr->this_dma; in udc_ep_out_req_dma()
1015 udc_ep_dma_enable(udc, hwep); in udc_ep_out_req_dma()
1019 static void udc_disable(struct lpc32xx_udc *udc) in udc_disable() argument
1024 udc_protocol_cmd_data_w(udc, CMD_CFG_DEV, DAT_WR_BYTE(0)); in udc_disable()
1025 udc_protocol_cmd_data_w(udc, CMD_SET_DEV_STAT, DAT_WR_BYTE(0)); in udc_disable()
1028 uda_disable_devint(udc, 0x3FF); in udc_disable()
1032 uda_disable_hwepint(udc, i); in udc_disable()
1033 uda_clear_hwepint(udc, i); in udc_disable()
1034 udc_disable_hwep(udc, i); in udc_disable()
1035 udc_unrealize_hwep(udc, i); in udc_disable()
1036 udc->udca_v_base[i] = 0; in udc_disable()
1039 udc_ep_dma_disable(udc, i); in udc_disable()
1040 writel((1 << i), USBD_EOTINTCLR(udc->udp_baseaddr)); in udc_disable()
1041 writel((1 << i), USBD_NDDRTINTCLR(udc->udp_baseaddr)); in udc_disable()
1042 writel((1 << i), USBD_SYSERRTINTCLR(udc->udp_baseaddr)); in udc_disable()
1043 writel((1 << i), USBD_DMARCLR(udc->udp_baseaddr)); in udc_disable()
1047 writel(0, USBD_DMAINTEN(udc->udp_baseaddr)); in udc_disable()
1049 writel(0, USBD_UDCAH(udc->udp_baseaddr)); in udc_disable()
1052 static void udc_enable(struct lpc32xx_udc *udc) in udc_enable() argument
1055 struct lpc32xx_ep *ep = &udc->ep[0]; in udc_enable()
1058 udc_disable(udc); in udc_enable()
1061 udc_protocol_cmd_data_w(udc, CMD_SET_DEV_STAT, DAT_WR_BYTE(DEV_CON)); in udc_enable()
1064 writel(USBD_EP_FAST, USBD_DEVINTPRI(udc->udp_baseaddr)); in udc_enable()
1065 writel(0xFFFF, USBD_EPINTPRI(udc->udp_baseaddr)); in udc_enable()
1068 writel(0x3FF, USBD_DEVINTCLR(udc->udp_baseaddr)); in udc_enable()
1071 writel(udc->udca_p_base, USBD_UDCAH(udc->udp_baseaddr)); in udc_enable()
1075 udc_realize_hwep(udc, i, ep->ep.maxpacket); in udc_enable()
1076 uda_enable_hwepint(udc, i); in udc_enable()
1077 udc_select_hwep(udc, i); in udc_enable()
1078 udc_clrstall_hwep(udc, i); in udc_enable()
1079 udc_clr_buffer_hwep(udc, i); in udc_enable()
1083 uda_clear_devint(udc, (USBD_ERR_INT | USBD_DEV_STAT | USBD_EP_SLOW | in udc_enable()
1085 uda_enable_devint(udc, (USBD_ERR_INT | USBD_DEV_STAT | USBD_EP_SLOW | in udc_enable()
1090 udc_set_address(udc, 0); in udc_enable()
1091 udc_set_address(udc, 0); in udc_enable()
1095 USBD_DMAINTEN(udc->udp_baseaddr)); in udc_enable()
1097 udc->dev_status = 0; in udc_enable()
1106 static void uda_power_event(struct lpc32xx_udc *udc, u32 conn) in uda_power_event() argument
1109 if (udc->board->conn_chgb != NULL) in uda_power_event()
1110 udc->board->conn_chgb(conn); in uda_power_event()
1114 static void uda_resm_susp_event(struct lpc32xx_udc *udc, u32 conn) in uda_resm_susp_event() argument
1117 if (udc->board->susp_chgb != NULL) in uda_resm_susp_event()
1118 udc->board->susp_chgb(conn); in uda_resm_susp_event()
1121 udc->suspended = 0; in uda_resm_susp_event()
1123 udc->suspended = 1; in uda_resm_susp_event()
1127 static void uda_remwkp_cgh(struct lpc32xx_udc *udc) in uda_remwkp_cgh() argument
1129 if (udc->board->rmwk_chgb != NULL) in uda_remwkp_cgh()
1130 udc->board->rmwk_chgb(udc->dev_status & in uda_remwkp_cgh()
1135 static void udc_pop_fifo(struct lpc32xx_udc *udc, u8 *data, u32 bytes) in udc_pop_fifo() argument
1149 *p32++ = readl(USBD_RXDATA(udc->udp_baseaddr)); in udc_pop_fifo()
1154 tmp = readl(USBD_RXDATA(udc->udp_baseaddr)); in udc_pop_fifo()
1165 tmp = readl(USBD_RXDATA(udc->udp_baseaddr)); in udc_pop_fifo()
1182 tmp = readl(USBD_RXDATA(udc->udp_baseaddr)); in udc_pop_fifo()
1190 tmp = readl(USBD_RXDATA(udc->udp_baseaddr)); in udc_pop_fifo()
1202 static u32 udc_read_hwep(struct lpc32xx_udc *udc, u32 hwep, u32 *data, in udc_read_hwep() argument
1210 writel(hwrep, USBD_CTRL(udc->udp_baseaddr)); in udc_read_hwep()
1213 while ((((tmpv = readl(USBD_RXPLEN(udc->udp_baseaddr))) & in udc_read_hwep()
1217 dev_dbg(udc->dev, "No packet ready on FIFO EP read\n"); in udc_read_hwep()
1225 udc_pop_fifo(udc, (u8 *) data, tmp); in udc_read_hwep()
1227 writel(((hwep & 0x1E) << 1), USBD_CTRL(udc->udp_baseaddr)); in udc_read_hwep()
1230 udc_clr_buffer_hwep(udc, hwep); in udc_read_hwep()
1236 static void udc_stuff_fifo(struct lpc32xx_udc *udc, u8 *data, u32 bytes) in udc_stuff_fifo() argument
1250 writel(*p32++, USBD_TXDATA(udc->udp_baseaddr)); in udc_stuff_fifo()
1259 writel(tmp, USBD_TXDATA(udc->udp_baseaddr)); in udc_stuff_fifo()
1275 writel(tmp, USBD_TXDATA(udc->udp_baseaddr)); in udc_stuff_fifo()
1287 writel(tmp, USBD_TXDATA(udc->udp_baseaddr)); in udc_stuff_fifo()
1297 writel(tmp, USBD_TXDATA(udc->udp_baseaddr)); in udc_stuff_fifo()
1306 static void udc_write_hwep(struct lpc32xx_udc *udc, u32 hwep, u32 *data, in udc_write_hwep() argument
1315 writel(hwwep, USBD_CTRL(udc->udp_baseaddr)); in udc_write_hwep()
1317 writel(bytes, USBD_TXPLEN(udc->udp_baseaddr)); in udc_write_hwep()
1321 writel(0, USBD_TXDATA(udc->udp_baseaddr)); in udc_write_hwep()
1323 udc_stuff_fifo(udc, (u8 *) data, bytes); in udc_write_hwep()
1325 writel(((hwep & 0x1E) << 1), USBD_CTRL(udc->udp_baseaddr)); in udc_write_hwep()
1327 udc_val_buffer_hwep(udc, hwep); in udc_write_hwep()
1332 static void uda_usb_reset(struct lpc32xx_udc *udc) in uda_usb_reset() argument
1336 udc_enable(udc); in uda_usb_reset()
1337 udc->gadget.speed = USB_SPEED_FULL; in uda_usb_reset()
1340 struct lpc32xx_ep *ep = &udc->ep[i]; in uda_usb_reset()
1346 static void udc_ep0_send_zlp(struct lpc32xx_udc *udc) in udc_ep0_send_zlp() argument
1348 udc_write_hwep(udc, EP_IN, NULL, 0); in udc_ep0_send_zlp()
1352 static u16 udc_get_current_frame(struct lpc32xx_udc *udc) in udc_get_current_frame() argument
1356 udc_protocol_cmd_w(udc, CMD_RD_FRAME); in udc_get_current_frame()
1357 flo = (u16) udc_protocol_cmd_r(udc, DAT_RD_FRAME); in udc_get_current_frame()
1358 fhi = (u16) udc_protocol_cmd_r(udc, DAT_RD_FRAME); in udc_get_current_frame()
1364 static inline void udc_set_device_configured(struct lpc32xx_udc *udc) in udc_set_device_configured() argument
1366 udc_protocol_cmd_data_w(udc, CMD_CFG_DEV, DAT_WR_BYTE(CONF_DVICE)); in udc_set_device_configured()
1370 static inline void udc_set_device_unconfigured(struct lpc32xx_udc *udc) in udc_set_device_unconfigured() argument
1372 udc_protocol_cmd_data_w(udc, CMD_CFG_DEV, DAT_WR_BYTE(0)); in udc_set_device_unconfigured()
1376 static void udc_reinit(struct lpc32xx_udc *udc) in udc_reinit() argument
1380 INIT_LIST_HEAD(&udc->gadget.ep_list); in udc_reinit()
1381 INIT_LIST_HEAD(&udc->gadget.ep0->ep_list); in udc_reinit()
1384 struct lpc32xx_ep *ep = &udc->ep[i]; in udc_reinit()
1387 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); in udc_reinit()
1393 udc->ep0state = WAIT_FOR_SETUP; in udc_reinit()
1399 struct lpc32xx_udc *udc = ep->udc; in done() local
1408 usb_gadget_unmap_request(&udc->gadget, &req->req, ep->is_in); in done()
1411 udc_dd_free(udc, req->dd_desc_ptr); in done()
1418 spin_unlock(&udc->lock); in done()
1420 spin_lock(&udc->lock); in done()
1434 uda_disable_hwepint(ep->udc, ep->hwep_num); in nuke()
1435 udc_disable_hwep(ep->udc, ep->hwep_num); in nuke()
1440 static int udc_ep0_in_req(struct lpc32xx_udc *udc) in udc_ep0_in_req() argument
1443 struct lpc32xx_ep *ep0 = &udc->ep[0]; in udc_ep0_in_req()
1456 udc_ep0_send_zlp(udc); in udc_ep0_in_req()
1463 udc_write_hwep(udc, EP_IN, (req->req.buf + req->req.actual), ts); in udc_ep0_in_req()
1472 udc->ep0state = WAIT_FOR_SETUP; in udc_ep0_in_req()
1478 static int udc_ep0_out_req(struct lpc32xx_udc *udc) in udc_ep0_out_req() argument
1481 struct lpc32xx_ep *ep0 = &udc->ep[0]; in udc_ep0_out_req()
1493 udc->ep0state = WAIT_FOR_SETUP; in udc_ep0_out_req()
1504 tr = udc_read_hwep(udc, EP_OUT, req->req.buf + req->req.actual, in udc_ep0_out_req()
1511 udc->ep0state = WAIT_FOR_SETUP; in udc_ep0_out_req()
1519 static void stop_activity(struct lpc32xx_udc *udc) in stop_activity() argument
1521 struct usb_gadget_driver *driver = udc->driver; in stop_activity()
1524 if (udc->gadget.speed == USB_SPEED_UNKNOWN) in stop_activity()
1527 udc->gadget.speed = USB_SPEED_UNKNOWN; in stop_activity()
1528 udc->suspended = 0; in stop_activity()
1531 struct lpc32xx_ep *ep = &udc->ep[i]; in stop_activity()
1535 spin_unlock(&udc->lock); in stop_activity()
1536 driver->disconnect(&udc->gadget); in stop_activity()
1537 spin_lock(&udc->lock); in stop_activity()
1540 isp1301_pullup_enable(udc, 0, 0); in stop_activity()
1541 udc_disable(udc); in stop_activity()
1542 udc_reinit(udc); in stop_activity()
1549 static void pullup(struct lpc32xx_udc *udc, int is_on) in pullup() argument
1551 if (!udc->clocked) in pullup()
1554 if (!udc->enabled || !udc->vbus) in pullup()
1557 if (is_on != udc->pullup) in pullup()
1558 isp1301_pullup_enable(udc, is_on, 0); in pullup()
1565 struct lpc32xx_udc *udc = ep->udc; in lpc32xx_ep_disable() local
1570 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_ep_disable()
1575 udc_ep_dma_disable(udc, ep->hwep_num); in lpc32xx_ep_disable()
1576 writel(1 << ep->hwep_num, USBD_EOTINTCLR(udc->udp_baseaddr)); in lpc32xx_ep_disable()
1577 writel(1 << ep->hwep_num, USBD_NDDRTINTCLR(udc->udp_baseaddr)); in lpc32xx_ep_disable()
1578 writel(1 << ep->hwep_num, USBD_SYSERRTINTCLR(udc->udp_baseaddr)); in lpc32xx_ep_disable()
1579 writel(1 << ep->hwep_num, USBD_DMARCLR(udc->udp_baseaddr)); in lpc32xx_ep_disable()
1582 udc->udca_v_base[ep->hwep_num] = 0; in lpc32xx_ep_disable()
1585 uda_clear_hwepint(udc, ep->hwep_num); in lpc32xx_ep_disable()
1586 udc_unrealize_hwep(udc, ep->hwep_num); in lpc32xx_ep_disable()
1590 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_ep_disable()
1592 atomic_dec(&udc->enabled_ep_cnt); in lpc32xx_ep_disable()
1593 wake_up(&udc->ep_disable_wait_queue); in lpc32xx_ep_disable()
1603 struct lpc32xx_udc *udc; in lpc32xx_ep_enable() local
1613 udc = ep->udc; in lpc32xx_ep_enable()
1616 dev_dbg(udc->dev, "bad ep descriptor's packet size\n"); in lpc32xx_ep_enable()
1622 dev_dbg(udc->dev, "Can't re-enable EP0!!!\n"); in lpc32xx_ep_enable()
1627 if ((!udc->driver) || (udc->gadget.speed == USB_SPEED_UNKNOWN)) { in lpc32xx_ep_enable()
1628 dev_dbg(udc->dev, "bogus device state\n"); in lpc32xx_ep_enable()
1639 dev_dbg(udc->dev, in lpc32xx_ep_enable()
1654 dev_dbg(udc->dev, in lpc32xx_ep_enable()
1663 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_ep_enable()
1681 udc_realize_hwep(udc, ep->hwep_num, ep->ep.maxpacket); in lpc32xx_ep_enable()
1682 udc_clr_buffer_hwep(udc, ep->hwep_num); in lpc32xx_ep_enable()
1683 uda_disable_hwepint(udc, ep->hwep_num); in lpc32xx_ep_enable()
1684 udc_clrstall_hwep(udc, ep->hwep_num); in lpc32xx_ep_enable()
1687 udc_ep_dma_disable(udc, ep->hwep_num); in lpc32xx_ep_enable()
1688 writel(1 << ep->hwep_num, USBD_EOTINTCLR(udc->udp_baseaddr)); in lpc32xx_ep_enable()
1689 writel(1 << ep->hwep_num, USBD_NDDRTINTCLR(udc->udp_baseaddr)); in lpc32xx_ep_enable()
1690 writel(1 << ep->hwep_num, USBD_SYSERRTINTCLR(udc->udp_baseaddr)); in lpc32xx_ep_enable()
1691 writel(1 << ep->hwep_num, USBD_DMARCLR(udc->udp_baseaddr)); in lpc32xx_ep_enable()
1693 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_ep_enable()
1695 atomic_inc(&udc->enabled_ep_cnt); in lpc32xx_ep_enable()
1736 struct lpc32xx_udc *udc; in lpc32xx_ep_queue() local
1747 udc = ep->udc; in lpc32xx_ep_queue()
1749 if (udc->gadget.speed == USB_SPEED_UNKNOWN) in lpc32xx_ep_queue()
1755 status = usb_gadget_map_request(&udc->gadget, _req, ep->is_in); in lpc32xx_ep_queue()
1760 dd = udc_dd_alloc(udc); in lpc32xx_ep_queue()
1790 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_ep_queue()
1804 udc->ep0state = DATA_IN; in lpc32xx_ep_queue()
1805 status = udc_ep0_in_req(udc); in lpc32xx_ep_queue()
1808 udc->ep0state = DATA_OUT; in lpc32xx_ep_queue()
1809 status = udc_ep0_out_req(udc); in lpc32xx_ep_queue()
1814 udc_ep_in_req_dma(udc, ep); in lpc32xx_ep_queue()
1818 udc_ep_out_req_dma(udc, ep); in lpc32xx_ep_queue()
1822 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_ep_queue()
1838 spin_lock_irqsave(&ep->udc->lock, flags); in lpc32xx_ep_dequeue()
1848 spin_unlock_irqrestore(&ep->udc->lock, flags); in lpc32xx_ep_dequeue()
1854 spin_unlock_irqrestore(&ep->udc->lock, flags); in lpc32xx_ep_dequeue()
1863 struct lpc32xx_udc *udc; in lpc32xx_ep_set_halt() local
1873 udc = ep->udc; in lpc32xx_ep_set_halt()
1874 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_ep_set_halt()
1878 udc_protocol_cmd_data_w(udc, CMD_SET_EP_STAT(ep->hwep_num), in lpc32xx_ep_set_halt()
1883 udc_protocol_cmd_data_w(udc, CMD_SET_EP_STAT(ep->hwep_num), in lpc32xx_ep_set_halt()
1887 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_ep_set_halt()
1897 if (!_ep || !ep->udc) in lpc32xx_ep_set_wedge()
1917 static void udc_send_in_zlp(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) in udc_send_in_zlp() argument
1920 udc_clearep_getsts(udc, ep->hwep_num); in udc_send_in_zlp()
1923 udc_write_hwep(udc, ep->hwep_num, NULL, 0); in udc_send_in_zlp()
1931 static void udc_handle_eps(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) in udc_handle_eps() argument
1939 uda_clear_hwepint(udc, ep->hwep_num); in udc_handle_eps()
1942 if (!(udc->enabled_hwepints & (1 << ep->hwep_num))) in udc_handle_eps()
1946 epstatus = udc_clearep_getsts(udc, ep->hwep_num); in udc_handle_eps()
1956 udc_send_in_zlp(udc, ep); in udc_handle_eps()
1957 uda_disable_hwepint(udc, ep->hwep_num); in udc_handle_eps()
1969 udc_ep_in_req_dma(udc, ep); in udc_handle_eps()
1971 udc_ep_out_req_dma(udc, ep); in udc_handle_eps()
1978 static void udc_handle_dma_ep(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) in udc_handle_dma_ep() argument
1996 udc_ep_dma_disable(udc, ep->hwep_num); in udc_handle_dma_ep()
1997 writel((1 << ep->hwep_num), USBD_EOTINTCLR(udc->udp_baseaddr)); in udc_handle_dma_ep()
1998 writel((1 << ep->hwep_num), USBD_NDDRTINTCLR(udc->udp_baseaddr)); in udc_handle_dma_ep()
2001 if (readl(USBD_SYSERRTINTST(udc->udp_baseaddr)) & in udc_handle_dma_ep()
2004 USBD_SYSERRTINTCLR(udc->udp_baseaddr)); in udc_handle_dma_ep()
2067 if (udc_clearep_getsts(udc, ep->hwep_num) & EP_SEL_F) { in udc_handle_dma_ep()
2068 udc_clearep_getsts(udc, ep->hwep_num); in udc_handle_dma_ep()
2069 uda_enable_hwepint(udc, ep->hwep_num); in udc_handle_dma_ep()
2070 udc_clearep_getsts(udc, ep->hwep_num); in udc_handle_dma_ep()
2075 udc_send_in_zlp(udc, ep); in udc_handle_dma_ep()
2082 udc_clearep_getsts(udc, ep->hwep_num); in udc_handle_dma_ep()
2085 udc_ep_in_req_dma(udc, ep); in udc_handle_dma_ep()
2087 udc_ep_out_req_dma(udc, ep); in udc_handle_dma_ep()
2098 static void udc_handle_dev(struct lpc32xx_udc *udc) in udc_handle_dev() argument
2102 udc_protocol_cmd_w(udc, CMD_GET_DEV_STAT); in udc_handle_dev()
2103 tmp = udc_protocol_cmd_r(udc, DAT_GET_DEV_STAT); in udc_handle_dev()
2106 uda_usb_reset(udc); in udc_handle_dev()
2108 uda_power_event(udc, (tmp & DEV_CON)); in udc_handle_dev()
2111 if (udc->vbus == 0) in udc_handle_dev()
2112 stop_activity(udc); in udc_handle_dev()
2113 else if ((udc->gadget.speed != USB_SPEED_UNKNOWN) && in udc_handle_dev()
2114 udc->driver) { in udc_handle_dev()
2116 udc->poweron = 0; in udc_handle_dev()
2117 schedule_work(&udc->pullup_job); in udc_handle_dev()
2118 uda_resm_susp_event(udc, 1); in udc_handle_dev()
2120 } else if ((udc->gadget.speed != USB_SPEED_UNKNOWN) && in udc_handle_dev()
2121 udc->driver && udc->vbus) { in udc_handle_dev()
2122 uda_resm_susp_event(udc, 0); in udc_handle_dev()
2124 udc->poweron = 1; in udc_handle_dev()
2125 schedule_work(&udc->pullup_job); in udc_handle_dev()
2130 static int udc_get_status(struct lpc32xx_udc *udc, u16 reqtype, u16 wIndex) in udc_get_status() argument
2140 ep0buff = udc->gadget.is_selfpowered; in udc_get_status()
2141 if (udc->dev_status & (1 << USB_DEVICE_REMOTE_WAKEUP)) in udc_get_status()
2147 ep = &udc->ep[tmp]; in udc_get_status()
2158 udc_protocol_cmd_w(udc, CMD_SEL_EP(ep->hwep_num)); in udc_get_status()
2159 tmp = udc_protocol_cmd_r(udc, DAT_SEL_EP(ep->hwep_num)); in udc_get_status()
2172 udc_write_hwep(udc, EP_IN, &ep0buff, 2); in udc_get_status()
2177 static void udc_handle_ep0_setup(struct lpc32xx_udc *udc) in udc_handle_ep0_setup() argument
2179 struct lpc32xx_ep *ep, *ep0 = &udc->ep[0]; in udc_handle_ep0_setup()
2188 bytes = udc_read_hwep(udc, EP_OUT, (u32 *) &ctrlpkt, 8); in udc_handle_ep0_setup()
2218 udc->dev_status &= in udc_handle_ep0_setup()
2221 udc->dev_status |= in udc_handle_ep0_setup()
2223 uda_remwkp_cgh(udc); in udc_handle_ep0_setup()
2233 ep = &udc->ep[tmp]; in udc_handle_ep0_setup()
2239 udc_stall_hwep(udc, tmp); in udc_handle_ep0_setup()
2241 udc_clrstall_hwep(udc, tmp); in udc_handle_ep0_setup()
2252 udc_set_address(udc, wValue); in udc_handle_ep0_setup()
2258 udc_get_status(udc, reqtype, wIndex); in udc_handle_ep0_setup()
2265 if (likely(udc->driver)) { in udc_handle_ep0_setup()
2268 spin_unlock(&udc->lock); in udc_handle_ep0_setup()
2269 i = udc->driver->setup(&udc->gadget, &ctrlpkt); in udc_handle_ep0_setup()
2271 spin_lock(&udc->lock); in udc_handle_ep0_setup()
2276 udc_set_device_configured(udc); in udc_handle_ep0_setup()
2278 udc_protocol_cmd_data_w(udc, CMD_SET_MODE, in udc_handle_ep0_setup()
2283 udc_set_device_unconfigured(udc); in udc_handle_ep0_setup()
2286 udc_protocol_cmd_data_w(udc, CMD_SET_MODE, in udc_handle_ep0_setup()
2293 dev_dbg(udc->dev, in udc_handle_ep0_setup()
2296 udc->ep0state = WAIT_FOR_SETUP; in udc_handle_ep0_setup()
2302 udc_ep0_send_zlp(udc); /* ZLP IN packet on data phase */ in udc_handle_ep0_setup()
2307 udc_stall_hwep(udc, EP_IN); in udc_handle_ep0_setup()
2311 udc_ep0_send_zlp(udc); in udc_handle_ep0_setup()
2316 static void udc_handle_ep0_in(struct lpc32xx_udc *udc) in udc_handle_ep0_in() argument
2318 struct lpc32xx_ep *ep0 = &udc->ep[0]; in udc_handle_ep0_in()
2322 epstatus = udc_clearep_getsts(udc, EP_IN); in udc_handle_ep0_in()
2330 udc_clrstall_hwep(udc, EP_IN); in udc_handle_ep0_in()
2332 udc->ep0state = WAIT_FOR_SETUP; in udc_handle_ep0_in()
2339 if (udc->ep0state == DATA_IN) in udc_handle_ep0_in()
2340 udc_ep0_in_req(udc); in udc_handle_ep0_in()
2344 udc->ep0state = WAIT_FOR_SETUP; in udc_handle_ep0_in()
2350 static void udc_handle_ep0_out(struct lpc32xx_udc *udc) in udc_handle_ep0_out() argument
2352 struct lpc32xx_ep *ep0 = &udc->ep[0]; in udc_handle_ep0_out()
2356 epstatus = udc_clearep_getsts(udc, EP_OUT); in udc_handle_ep0_out()
2365 udc_clrstall_hwep(udc, EP_OUT); in udc_handle_ep0_out()
2367 udc->ep0state = WAIT_FOR_SETUP; in udc_handle_ep0_out()
2377 udc->ep0state = WAIT_FOR_SETUP; in udc_handle_ep0_out()
2383 switch (udc->ep0state) { in udc_handle_ep0_out()
2385 udc_handle_ep0_setup(udc); in udc_handle_ep0_out()
2389 udc_ep0_out_req(udc); in udc_handle_ep0_out()
2395 udc->ep0state = WAIT_FOR_SETUP; in udc_handle_ep0_out()
2404 struct lpc32xx_udc *udc = to_udc(gadget); in lpc32xx_get_frame() local
2406 if (!udc->clocked) in lpc32xx_get_frame()
2409 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_get_frame()
2411 frame = (int) udc_get_current_frame(udc); in lpc32xx_get_frame()
2413 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_get_frame()
2437 struct lpc32xx_udc *udc = to_udc(gadget); in lpc32xx_vbus_session() local
2439 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_vbus_session()
2442 if (udc->driver) { in lpc32xx_vbus_session()
2443 udc_clk_set(udc, 1); in lpc32xx_vbus_session()
2444 udc_enable(udc); in lpc32xx_vbus_session()
2445 pullup(udc, is_active); in lpc32xx_vbus_session()
2447 stop_activity(udc); in lpc32xx_vbus_session()
2448 pullup(udc, 0); in lpc32xx_vbus_session()
2450 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_vbus_session()
2456 if (atomic_read(&udc->enabled_ep_cnt)) in lpc32xx_vbus_session()
2457 wait_event_interruptible(udc->ep_disable_wait_queue, in lpc32xx_vbus_session()
2458 (atomic_read(&udc->enabled_ep_cnt) == 0)); in lpc32xx_vbus_session()
2460 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_vbus_session()
2462 udc_clk_set(udc, 0); in lpc32xx_vbus_session()
2465 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_vbus_session()
2473 struct lpc32xx_udc *udc = to_udc(gadget); in lpc32xx_pullup() local
2476 pullup(udc, is_on); in lpc32xx_pullup()
2722 struct lpc32xx_udc *udc = _udc; in lpc32xx_usb_lp_irq() local
2724 spin_lock(&udc->lock); in lpc32xx_usb_lp_irq()
2727 devstat = readl(USBD_DEVINTST(udc->udp_baseaddr)); in lpc32xx_usb_lp_irq()
2730 writel(devstat, USBD_DEVINTCLR(udc->udp_baseaddr)); in lpc32xx_usb_lp_irq()
2731 devstat = devstat & udc->enabled_devints; in lpc32xx_usb_lp_irq()
2735 udc_handle_dev(udc); in lpc32xx_usb_lp_irq()
2747 udc_protocol_cmd_w(udc, CMD_RD_ERR_STAT); in lpc32xx_usb_lp_irq()
2748 tmp = udc_protocol_cmd_r(udc, DAT_RD_ERR_STAT); in lpc32xx_usb_lp_irq()
2749 dev_dbg(udc->dev, "Device error (0x%x)!\n", tmp); in lpc32xx_usb_lp_irq()
2752 spin_unlock(&udc->lock); in lpc32xx_usb_lp_irq()
2761 struct lpc32xx_udc *udc = _udc; in lpc32xx_usb_hp_irq() local
2763 spin_lock(&udc->lock); in lpc32xx_usb_hp_irq()
2766 writel(USBD_EP_FAST, USBD_DEVINTCLR(udc->udp_baseaddr)); in lpc32xx_usb_hp_irq()
2769 tmp = readl(USBD_EPINTST(udc->udp_baseaddr)); in lpc32xx_usb_hp_irq()
2775 udc_handle_ep0_in(udc); in lpc32xx_usb_hp_irq()
2779 udc_handle_ep0_out(udc); in lpc32xx_usb_hp_irq()
2788 if (tmp & (1 << udc->ep[i].hwep_num)) in lpc32xx_usb_hp_irq()
2789 udc_handle_eps(udc, &udc->ep[i]); in lpc32xx_usb_hp_irq()
2793 spin_unlock(&udc->lock); in lpc32xx_usb_hp_irq()
2800 struct lpc32xx_udc *udc = _udc; in lpc32xx_usb_devdma_irq() local
2805 spin_lock(&udc->lock); in lpc32xx_usb_devdma_irq()
2808 tmp = readl(USBD_EOTINTST(udc->udp_baseaddr)) | in lpc32xx_usb_devdma_irq()
2809 (readl(USBD_EPDMAST(udc->udp_baseaddr)) & in lpc32xx_usb_devdma_irq()
2810 readl(USBD_NDDRTINTST(udc->udp_baseaddr))) | in lpc32xx_usb_devdma_irq()
2811 readl(USBD_SYSERRTINTST(udc->udp_baseaddr)); in lpc32xx_usb_devdma_irq()
2813 if (tmp & (1 << udc->ep[i].hwep_num)) in lpc32xx_usb_devdma_irq()
2814 udc_handle_dma_ep(udc, &udc->ep[i]); in lpc32xx_usb_devdma_irq()
2817 spin_unlock(&udc->lock); in lpc32xx_usb_devdma_irq()
2827 static void vbus_work(struct lpc32xx_udc *udc) in vbus_work() argument
2831 if (udc->enabled != 0) { in vbus_work()
2833 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in vbus_work()
2840 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in vbus_work()
2845 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in vbus_work()
2850 value = i2c_smbus_read_byte_data(udc->isp1301_i2c_client, in vbus_work()
2855 udc->vbus = 1; in vbus_work()
2857 udc->vbus = 0; in vbus_work()
2860 if (udc->last_vbus != udc->vbus) { in vbus_work()
2861 udc->last_vbus = udc->vbus; in vbus_work()
2862 lpc32xx_vbus_session(&udc->gadget, udc->vbus); in vbus_work()
2869 struct lpc32xx_udc *udc = _udc; in lpc32xx_usb_vbus_irq() local
2871 vbus_work(udc); in lpc32xx_usb_vbus_irq()
2879 struct lpc32xx_udc *udc = to_udc(gadget); in lpc32xx_start() local
2882 dev_err(udc->dev, "bad parameter.\n"); in lpc32xx_start()
2886 if (udc->driver) { in lpc32xx_start()
2887 dev_err(udc->dev, "UDC already has a gadget driver\n"); in lpc32xx_start()
2891 udc->driver = driver; in lpc32xx_start()
2892 udc->gadget.dev.of_node = udc->dev->of_node; in lpc32xx_start()
2893 udc->enabled = 1; in lpc32xx_start()
2894 udc->gadget.is_selfpowered = 1; in lpc32xx_start()
2895 udc->vbus = 0; in lpc32xx_start()
2898 udc->last_vbus = udc->vbus = 0; in lpc32xx_start()
2899 vbus_work(udc); in lpc32xx_start()
2902 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in lpc32xx_start()
2904 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in lpc32xx_start()
2912 struct lpc32xx_udc *udc = to_udc(gadget); in lpc32xx_stop() local
2914 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in lpc32xx_stop()
2916 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in lpc32xx_stop()
2919 if (udc->clocked) { in lpc32xx_stop()
2920 spin_lock(&udc->lock); in lpc32xx_stop()
2921 stop_activity(udc); in lpc32xx_stop()
2922 spin_unlock(&udc->lock); in lpc32xx_stop()
2929 if (atomic_read(&udc->enabled_ep_cnt)) in lpc32xx_stop()
2930 wait_event_interruptible(udc->ep_disable_wait_queue, in lpc32xx_stop()
2931 (atomic_read(&udc->enabled_ep_cnt) == 0)); in lpc32xx_stop()
2933 spin_lock(&udc->lock); in lpc32xx_stop()
2934 udc_clk_set(udc, 0); in lpc32xx_stop()
2935 spin_unlock(&udc->lock); in lpc32xx_stop()
2938 udc->enabled = 0; in lpc32xx_stop()
2939 udc->driver = NULL; in lpc32xx_stop()
2947 struct lpc32xx_udc *udc = platform_get_drvdata(dev); in lpc32xx_udc_shutdown() local
2949 pullup(udc, 0); in lpc32xx_udc_shutdown()
2985 struct lpc32xx_udc *udc; in lpc32xx_udc_probe() local
2990 udc = devm_kmemdup(dev, &controller_template, sizeof(*udc), GFP_KERNEL); in lpc32xx_udc_probe()
2991 if (!udc) in lpc32xx_udc_probe()
2995 udc->ep[i].udc = udc; in lpc32xx_udc_probe()
2996 udc->gadget.ep0 = &udc->ep[0].ep; in lpc32xx_udc_probe()
2999 udc->gadget.dev.parent = dev; in lpc32xx_udc_probe()
3000 udc->pdev = pdev; in lpc32xx_udc_probe()
3001 udc->dev = &pdev->dev; in lpc32xx_udc_probe()
3002 udc->enabled = 0; in lpc32xx_udc_probe()
3011 udc->isp1301_i2c_client = isp1301_get_client(isp1301_node); in lpc32xx_udc_probe()
3013 if (!udc->isp1301_i2c_client) { in lpc32xx_udc_probe()
3017 dev_info(udc->dev, "ISP1301 I2C device at address 0x%x\n", in lpc32xx_udc_probe()
3018 udc->isp1301_i2c_client->addr); in lpc32xx_udc_probe()
3025 udc->board = &lpc32xx_usbddata; in lpc32xx_udc_probe()
3036 spin_lock_init(&udc->lock); in lpc32xx_udc_probe()
3040 udc->udp_irq[i] = platform_get_irq(pdev, i); in lpc32xx_udc_probe()
3041 if (udc->udp_irq[i] < 0) in lpc32xx_udc_probe()
3042 return udc->udp_irq[i]; in lpc32xx_udc_probe()
3045 udc->udp_baseaddr = devm_platform_ioremap_resource(pdev, 0); in lpc32xx_udc_probe()
3046 if (IS_ERR(udc->udp_baseaddr)) { in lpc32xx_udc_probe()
3047 dev_err(udc->dev, "IO map failure\n"); in lpc32xx_udc_probe()
3048 return PTR_ERR(udc->udp_baseaddr); in lpc32xx_udc_probe()
3052 udc->usb_slv_clk = devm_clk_get(&pdev->dev, NULL); in lpc32xx_udc_probe()
3053 if (IS_ERR(udc->usb_slv_clk)) { in lpc32xx_udc_probe()
3054 dev_err(udc->dev, "failed to acquire USB device clock\n"); in lpc32xx_udc_probe()
3055 return PTR_ERR(udc->usb_slv_clk); in lpc32xx_udc_probe()
3059 retval = clk_prepare_enable(udc->usb_slv_clk); in lpc32xx_udc_probe()
3061 dev_err(udc->dev, "failed to start USB device clock\n"); in lpc32xx_udc_probe()
3066 udc->poweron = udc->pullup = 0; in lpc32xx_udc_probe()
3067 INIT_WORK(&udc->pullup_job, pullup_work); in lpc32xx_udc_probe()
3069 INIT_WORK(&udc->power_job, power_work); in lpc32xx_udc_probe()
3073 udc->clocked = 1; in lpc32xx_udc_probe()
3075 isp1301_udc_configure(udc); in lpc32xx_udc_probe()
3077 udc->udca_v_base = dma_alloc_coherent(&pdev->dev, UDCA_BUFF_SIZE, in lpc32xx_udc_probe()
3080 if (!udc->udca_v_base) { in lpc32xx_udc_probe()
3081 dev_err(udc->dev, "error getting UDCA region\n"); in lpc32xx_udc_probe()
3085 udc->udca_p_base = dma_handle; in lpc32xx_udc_probe()
3086 dev_dbg(udc->dev, "DMA buffer(0x%x bytes), P:0x%08x, V:0x%p\n", in lpc32xx_udc_probe()
3087 UDCA_BUFF_SIZE, udc->udca_p_base, udc->udca_v_base); in lpc32xx_udc_probe()
3090 udc->dd_cache = dma_pool_create("udc_dd", udc->dev, in lpc32xx_udc_probe()
3093 if (!udc->dd_cache) { in lpc32xx_udc_probe()
3094 dev_err(udc->dev, "error getting DD DMA region\n"); in lpc32xx_udc_probe()
3100 udc_disable(udc); in lpc32xx_udc_probe()
3101 udc_reinit(udc); in lpc32xx_udc_probe()
3105 retval = devm_request_irq(dev, udc->udp_irq[IRQ_USB_LP], in lpc32xx_udc_probe()
3106 lpc32xx_usb_lp_irq, 0, "udc_lp", udc); in lpc32xx_udc_probe()
3108 dev_err(udc->dev, "LP request irq %d failed\n", in lpc32xx_udc_probe()
3109 udc->udp_irq[IRQ_USB_LP]); in lpc32xx_udc_probe()
3112 retval = devm_request_irq(dev, udc->udp_irq[IRQ_USB_HP], in lpc32xx_udc_probe()
3113 lpc32xx_usb_hp_irq, 0, "udc_hp", udc); in lpc32xx_udc_probe()
3115 dev_err(udc->dev, "HP request irq %d failed\n", in lpc32xx_udc_probe()
3116 udc->udp_irq[IRQ_USB_HP]); in lpc32xx_udc_probe()
3120 retval = devm_request_irq(dev, udc->udp_irq[IRQ_USB_DEVDMA], in lpc32xx_udc_probe()
3121 lpc32xx_usb_devdma_irq, 0, "udc_dma", udc); in lpc32xx_udc_probe()
3123 dev_err(udc->dev, "DEV request irq %d failed\n", in lpc32xx_udc_probe()
3124 udc->udp_irq[IRQ_USB_DEVDMA]); in lpc32xx_udc_probe()
3130 retval = devm_request_threaded_irq(dev, udc->udp_irq[IRQ_USB_ATX], NULL, in lpc32xx_udc_probe()
3132 "udc_otg", udc); in lpc32xx_udc_probe()
3134 dev_err(udc->dev, "VBUS request irq %d failed\n", in lpc32xx_udc_probe()
3135 udc->udp_irq[IRQ_USB_ATX]); in lpc32xx_udc_probe()
3140 init_waitqueue_head(&udc->ep_disable_wait_queue); in lpc32xx_udc_probe()
3141 atomic_set(&udc->enabled_ep_cnt, 0); in lpc32xx_udc_probe()
3143 retval = usb_add_gadget_udc(dev, &udc->gadget); in lpc32xx_udc_probe()
3147 dev_set_drvdata(dev, udc); in lpc32xx_udc_probe()
3149 create_debug_file(udc); in lpc32xx_udc_probe()
3152 udc_clk_set(udc, 0); in lpc32xx_udc_probe()
3154 dev_info(udc->dev, "%s version %s\n", driver_name, DRIVER_VERSION); in lpc32xx_udc_probe()
3159 dma_pool_destroy(udc->dd_cache); in lpc32xx_udc_probe()
3162 udc->udca_v_base, udc->udca_p_base); in lpc32xx_udc_probe()
3164 clk_disable_unprepare(udc->usb_slv_clk); in lpc32xx_udc_probe()
3165 dev_err(udc->dev, "%s probe failed, %d\n", driver_name, retval); in lpc32xx_udc_probe()
3172 struct lpc32xx_udc *udc = platform_get_drvdata(pdev); in lpc32xx_udc_remove() local
3174 usb_del_gadget_udc(&udc->gadget); in lpc32xx_udc_remove()
3175 if (udc->driver) { in lpc32xx_udc_remove()
3181 udc_clk_set(udc, 1); in lpc32xx_udc_remove()
3182 udc_disable(udc); in lpc32xx_udc_remove()
3183 pullup(udc, 0); in lpc32xx_udc_remove()
3186 remove_debug_file(udc); in lpc32xx_udc_remove()
3188 dma_pool_destroy(udc->dd_cache); in lpc32xx_udc_remove()
3190 udc->udca_v_base, udc->udca_p_base); in lpc32xx_udc_remove()
3192 clk_disable_unprepare(udc->usb_slv_clk); in lpc32xx_udc_remove()
3198 struct lpc32xx_udc *udc = platform_get_drvdata(pdev); in lpc32xx_udc_suspend() local
3200 if (udc->clocked) { in lpc32xx_udc_suspend()
3202 udc->poweron = 0; in lpc32xx_udc_suspend()
3203 isp1301_set_powerstate(udc, 0); in lpc32xx_udc_suspend()
3206 udc_clk_set(udc, 0); in lpc32xx_udc_suspend()
3210 udc->clocked = 1; in lpc32xx_udc_suspend()
3213 clk_disable_unprepare(udc->usb_slv_clk); in lpc32xx_udc_suspend()
3221 struct lpc32xx_udc *udc = platform_get_drvdata(pdev); in lpc32xx_udc_resume() local
3223 if (udc->clocked) { in lpc32xx_udc_resume()
3225 clk_prepare_enable(udc->usb_slv_clk); in lpc32xx_udc_resume()
3228 udc_clk_set(udc, 1); in lpc32xx_udc_resume()
3231 udc->poweron = 1; in lpc32xx_udc_resume()
3232 isp1301_set_powerstate(udc, 1); in lpc32xx_udc_resume()
3244 { .compatible = "nxp,lpc3220-udc", },
3264 MODULE_DESCRIPTION("LPC32XX udc driver");