Lines Matching refs:fotg210

82 #define fotg210_dbg(fotg210, fmt, args...) \  argument
83 dev_dbg(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
84 #define fotg210_err(fotg210, fmt, args...) \ argument
85 dev_err(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
86 #define fotg210_info(fotg210, fmt, args...) \ argument
87 dev_info(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
88 #define fotg210_warn(fotg210, fmt, args...) \ argument
89 dev_warn(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
94 static void dbg_hcs_params(struct fotg210_hcd *fotg210, char *label) in dbg_hcs_params() argument
96 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcs_params); in dbg_hcs_params()
98 fotg210_dbg(fotg210, "%s hcs_params 0x%x ports=%d\n", label, params, in dbg_hcs_params()
105 static void dbg_hcc_params(struct fotg210_hcd *fotg210, char *label) in dbg_hcc_params() argument
107 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in dbg_hcc_params()
109 fotg210_dbg(fotg210, "%s hcc_params %04x uframes %s%s\n", label, in dbg_hcc_params()
116 dbg_qtd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd) in dbg_qtd() argument
118 fotg210_dbg(fotg210, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd, in dbg_qtd()
119 hc32_to_cpup(fotg210, &qtd->hw_next), in dbg_qtd()
120 hc32_to_cpup(fotg210, &qtd->hw_alt_next), in dbg_qtd()
121 hc32_to_cpup(fotg210, &qtd->hw_token), in dbg_qtd()
122 hc32_to_cpup(fotg210, &qtd->hw_buf[0])); in dbg_qtd()
124 fotg210_dbg(fotg210, " p1=%08x p2=%08x p3=%08x p4=%08x\n", in dbg_qtd()
125 hc32_to_cpup(fotg210, &qtd->hw_buf[1]), in dbg_qtd()
126 hc32_to_cpup(fotg210, &qtd->hw_buf[2]), in dbg_qtd()
127 hc32_to_cpup(fotg210, &qtd->hw_buf[3]), in dbg_qtd()
128 hc32_to_cpup(fotg210, &qtd->hw_buf[4])); in dbg_qtd()
132 dbg_qh(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in dbg_qh() argument
136 fotg210_dbg(fotg210, "%s qh %p n%08x info %x %x qtd %x\n", label, qh, in dbg_qh()
140 dbg_qtd("overlay", fotg210, (struct fotg210_qtd *) &hw->hw_qtd_next); in dbg_qh()
144 dbg_itd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_itd *itd) in dbg_itd() argument
146 fotg210_dbg(fotg210, "%s[%d] itd %p, next %08x, urb %p\n", label, in dbg_itd()
147 itd->frame, itd, hc32_to_cpu(fotg210, itd->hw_next), in dbg_itd()
150 fotg210_dbg(fotg210, in dbg_itd()
152 hc32_to_cpu(fotg210, itd->hw_transaction[0]), in dbg_itd()
153 hc32_to_cpu(fotg210, itd->hw_transaction[1]), in dbg_itd()
154 hc32_to_cpu(fotg210, itd->hw_transaction[2]), in dbg_itd()
155 hc32_to_cpu(fotg210, itd->hw_transaction[3]), in dbg_itd()
156 hc32_to_cpu(fotg210, itd->hw_transaction[4]), in dbg_itd()
157 hc32_to_cpu(fotg210, itd->hw_transaction[5]), in dbg_itd()
158 hc32_to_cpu(fotg210, itd->hw_transaction[6]), in dbg_itd()
159 hc32_to_cpu(fotg210, itd->hw_transaction[7])); in dbg_itd()
161 fotg210_dbg(fotg210, in dbg_itd()
163 hc32_to_cpu(fotg210, itd->hw_bufp[0]), in dbg_itd()
164 hc32_to_cpu(fotg210, itd->hw_bufp[1]), in dbg_itd()
165 hc32_to_cpu(fotg210, itd->hw_bufp[2]), in dbg_itd()
166 hc32_to_cpu(fotg210, itd->hw_bufp[3]), in dbg_itd()
167 hc32_to_cpu(fotg210, itd->hw_bufp[4]), in dbg_itd()
168 hc32_to_cpu(fotg210, itd->hw_bufp[5]), in dbg_itd()
169 hc32_to_cpu(fotg210, itd->hw_bufp[6])); in dbg_itd()
171 fotg210_dbg(fotg210, " index: %d %d %d %d %d %d %d %d\n", in dbg_itd()
263 #define dbg_status(fotg210, label, status) { \ argument
266 fotg210_dbg(fotg210, "%s\n", _buf); \
269 #define dbg_cmd(fotg210, label, command) { \ argument
272 fotg210_dbg(fotg210, "%s\n", _buf); \
275 #define dbg_port(fotg210, label, port, status) { \ argument
277 fotg210_dbg(fotg210, "%s\n", \
340 static inline char token_mark(struct fotg210_hcd *fotg210, __hc32 token) in token_mark() argument
342 __u32 v = hc32_to_cpu(fotg210, token); in token_mark()
354 static void qh_lines(struct fotg210_hcd *fotg210, struct fotg210_qh *qh, in qh_lines() argument
364 __le32 list_end = FOTG210_LIST_END(fotg210); in qh_lines()
370 mark = token_mark(fotg210, hw->hw_token); in qh_lines()
372 if ((hw->hw_alt_next & QTD_MASK(fotg210)) == in qh_lines()
373 fotg210->async->hw->hw_alt_next) in qh_lines()
379 scratch = hc32_to_cpup(fotg210, &hw->hw_info1); in qh_lines()
380 hw_curr = (mark == '*') ? hc32_to_cpup(fotg210, &hw->hw_current) : 0; in qh_lines()
386 scratch, hc32_to_cpup(fotg210, &hw->hw_info2), in qh_lines()
387 hc32_to_cpup(fotg210, &hw->hw_token), mark, in qh_lines()
388 (cpu_to_hc32(fotg210, QTD_TOGGLE) & hw->hw_token) in qh_lines()
390 (hc32_to_cpup(fotg210, &hw->hw_alt_next) >> 1) & 0x0f); in qh_lines()
396 scratch = hc32_to_cpup(fotg210, &td->hw_token); in qh_lines()
400 else if (hw->hw_qtd_next == cpu_to_hc32(fotg210, td->qtd_dma)) in qh_lines()
403 if (td->hw_alt_next == fotg210->async->hw->hw_alt_next) in qh_lines()
451 struct fotg210_hcd *fotg210; in fill_async_buffer() local
458 fotg210 = hcd_to_fotg210(hcd); in fill_async_buffer()
468 spin_lock_irqsave(&fotg210->lock, flags); in fill_async_buffer()
469 for (qh = fotg210->async->qh_next.qh; size > 0 && qh; in fill_async_buffer()
471 qh_lines(fotg210, qh, &next, &size); in fill_async_buffer()
472 if (fotg210->async_unlink && size > 0) { in fill_async_buffer()
477 for (qh = fotg210->async_unlink; size > 0 && qh; in fill_async_buffer()
479 qh_lines(fotg210, qh, &next, &size); in fill_async_buffer()
481 spin_unlock_irqrestore(&fotg210->lock, flags); in fill_async_buffer()
487 static unsigned output_buf_tds_dir(char *buf, struct fotg210_hcd *fotg210, in output_buf_tds_dir() argument
490 u32 scratch = hc32_to_cpup(fotg210, &hw->hw_info1); in output_buf_tds_dir()
498 switch ((hc32_to_cpu(fotg210, qtd->hw_token) >> 8) & 0x03) { in output_buf_tds_dir()
518 struct fotg210_hcd *fotg210; in fill_periodic_buffer() local
533 fotg210 = hcd_to_fotg210(hcd); in fill_periodic_buffer()
537 temp = scnprintf(next, size, "size = %d\n", fotg210->periodic_size); in fill_periodic_buffer()
544 spin_lock_irqsave(&fotg210->lock, flags); in fill_periodic_buffer()
545 for (i = 0; i < fotg210->periodic_size; i++) { in fill_periodic_buffer()
546 p = fotg210->pshadow[i]; in fill_periodic_buffer()
550 tag = Q_NEXT_TYPE(fotg210, fotg210->periodic[i]); in fill_periodic_buffer()
559 switch (hc32_to_cpu(fotg210, tag)) { in fill_periodic_buffer()
564 hc32_to_cpup(fotg210, in fill_periodic_buffer()
586 fotg210, hw, in fill_periodic_buffer()
593 tag = Q_NEXT_TYPE(fotg210, hw->hw_next); in fill_periodic_buffer()
600 tag = Q_NEXT_TYPE(fotg210, p.fstn->hw_next); in fill_periodic_buffer()
606 tag = Q_NEXT_TYPE(fotg210, p.itd->hw_next); in fill_periodic_buffer()
618 spin_unlock_irqrestore(&fotg210->lock, flags); in fill_periodic_buffer()
625 static const char *rh_state_string(struct fotg210_hcd *fotg210) in rh_state_string() argument
627 switch (fotg210->rh_state) { in rh_state_string()
643 struct fotg210_hcd *fotg210; in fill_registers_buffer() local
651 fotg210 = hcd_to_fotg210(hcd); in fill_registers_buffer()
655 spin_lock_irqsave(&fotg210->lock, flags); in fill_registers_buffer()
669 i = HC_VERSION(fotg210, fotg210_readl(fotg210, in fill_registers_buffer()
670 &fotg210->caps->hc_capbase)); in fill_registers_buffer()
678 i >> 8, i & 0x0ff, rh_state_string(fotg210)); in fill_registers_buffer()
683 i = fotg210_readl(fotg210, &fotg210->caps->hcs_params); in fill_registers_buffer()
688 i = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in fill_registers_buffer()
695 fotg210_readl(fotg210, &fotg210->regs->status)); in fill_registers_buffer()
701 fotg210_readl(fotg210, &fotg210->regs->command)); in fill_registers_buffer()
707 fotg210_readl(fotg210, &fotg210->regs->intr_enable)); in fill_registers_buffer()
713 fotg210_read_frame_index(fotg210)); in fill_registers_buffer()
717 if (fotg210->async_unlink) { in fill_registers_buffer()
719 fotg210->async_unlink); in fill_registers_buffer()
727 fotg210->stats.normal, fotg210->stats.error, in fill_registers_buffer()
728 fotg210->stats.iaa, fotg210->stats.lost_iaa); in fill_registers_buffer()
733 fotg210->stats.complete, fotg210->stats.unlink); in fill_registers_buffer()
739 spin_unlock_irqrestore(&fotg210->lock, flags); in fill_registers_buffer()
847 static inline void create_debug_files(struct fotg210_hcd *fotg210) in create_debug_files() argument
849 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self; in create_debug_files()
861 static inline void remove_debug_files(struct fotg210_hcd *fotg210) in remove_debug_files() argument
863 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self; in remove_debug_files()
884 static int handshake(struct fotg210_hcd *fotg210, void __iomem *ptr, in handshake() argument
902 static int fotg210_halt(struct fotg210_hcd *fotg210) in fotg210_halt() argument
906 spin_lock_irq(&fotg210->lock); in fotg210_halt()
909 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable); in fotg210_halt()
915 fotg210->command &= ~CMD_RUN; in fotg210_halt()
916 temp = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_halt()
918 fotg210_writel(fotg210, temp, &fotg210->regs->command); in fotg210_halt()
920 spin_unlock_irq(&fotg210->lock); in fotg210_halt()
921 synchronize_irq(fotg210_to_hcd(fotg210)->irq); in fotg210_halt()
923 return handshake(fotg210, &fotg210->regs->status, in fotg210_halt()
930 static int fotg210_reset(struct fotg210_hcd *fotg210) in fotg210_reset() argument
933 u32 command = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_reset()
938 if (fotg210->debug && !dbgp_reset_prep(fotg210_to_hcd(fotg210))) in fotg210_reset()
939 fotg210->debug = NULL; in fotg210_reset()
942 dbg_cmd(fotg210, "reset", command); in fotg210_reset()
943 fotg210_writel(fotg210, command, &fotg210->regs->command); in fotg210_reset()
944 fotg210->rh_state = FOTG210_RH_HALTED; in fotg210_reset()
945 fotg210->next_statechange = jiffies; in fotg210_reset()
946 retval = handshake(fotg210, &fotg210->regs->command, in fotg210_reset()
952 if (fotg210->debug) in fotg210_reset()
953 dbgp_external_startup(fotg210_to_hcd(fotg210)); in fotg210_reset()
955 fotg210->port_c_suspend = fotg210->suspended_ports = in fotg210_reset()
956 fotg210->resuming_ports = 0; in fotg210_reset()
963 static void fotg210_quiesce(struct fotg210_hcd *fotg210) in fotg210_quiesce() argument
967 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_quiesce()
971 temp = (fotg210->command << 10) & (STS_ASS | STS_PSS); in fotg210_quiesce()
972 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, temp, in fotg210_quiesce()
976 spin_lock_irq(&fotg210->lock); in fotg210_quiesce()
977 fotg210->command &= ~(CMD_ASE | CMD_PSE); in fotg210_quiesce()
978 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_quiesce()
979 spin_unlock_irq(&fotg210->lock); in fotg210_quiesce()
982 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, 0, in fotg210_quiesce()
986 static void end_unlink_async(struct fotg210_hcd *fotg210);
987 static void unlink_empty_async(struct fotg210_hcd *fotg210);
988 static void fotg210_work(struct fotg210_hcd *fotg210);
989 static void start_unlink_intr(struct fotg210_hcd *fotg210,
991 static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
994 static void fotg210_set_command_bit(struct fotg210_hcd *fotg210, u32 bit) in fotg210_set_command_bit() argument
996 fotg210->command |= bit; in fotg210_set_command_bit()
997 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_set_command_bit()
1000 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_set_command_bit()
1004 static void fotg210_clear_command_bit(struct fotg210_hcd *fotg210, u32 bit) in fotg210_clear_command_bit() argument
1006 fotg210->command &= ~bit; in fotg210_clear_command_bit()
1007 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_clear_command_bit()
1010 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_clear_command_bit()
1053 static void fotg210_enable_event(struct fotg210_hcd *fotg210, unsigned event, in fotg210_enable_event() argument
1056 ktime_t *timeout = &fotg210->hr_timeouts[event]; in fotg210_enable_event()
1060 fotg210->enabled_hrtimer_events |= (1 << event); in fotg210_enable_event()
1063 if (event < fotg210->next_hrtimer_event) { in fotg210_enable_event()
1064 fotg210->next_hrtimer_event = event; in fotg210_enable_event()
1065 hrtimer_start_range_ns(&fotg210->hrtimer, *timeout, in fotg210_enable_event()
1072 static void fotg210_poll_ASS(struct fotg210_hcd *fotg210) in fotg210_poll_ASS() argument
1077 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_poll_ASS()
1080 want = (fotg210->command & CMD_ASE) ? STS_ASS : 0; in fotg210_poll_ASS()
1081 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_ASS; in fotg210_poll_ASS()
1086 if (fotg210->ASS_poll_count++ < 20) { in fotg210_poll_ASS()
1087 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_ASS, in fotg210_poll_ASS()
1091 fotg210_dbg(fotg210, "Waited too long for the async schedule status (%x/%x), giving up\n", in fotg210_poll_ASS()
1094 fotg210->ASS_poll_count = 0; in fotg210_poll_ASS()
1098 if (fotg210->async_count > 0) in fotg210_poll_ASS()
1099 fotg210_set_command_bit(fotg210, CMD_ASE); in fotg210_poll_ASS()
1102 if (fotg210->async_count == 0) { in fotg210_poll_ASS()
1105 fotg210_enable_event(fotg210, in fotg210_poll_ASS()
1113 static void fotg210_disable_ASE(struct fotg210_hcd *fotg210) in fotg210_disable_ASE() argument
1115 fotg210_clear_command_bit(fotg210, CMD_ASE); in fotg210_disable_ASE()
1120 static void fotg210_poll_PSS(struct fotg210_hcd *fotg210) in fotg210_poll_PSS() argument
1125 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_poll_PSS()
1128 want = (fotg210->command & CMD_PSE) ? STS_PSS : 0; in fotg210_poll_PSS()
1129 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_PSS; in fotg210_poll_PSS()
1134 if (fotg210->PSS_poll_count++ < 20) { in fotg210_poll_PSS()
1135 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_PSS, in fotg210_poll_PSS()
1139 fotg210_dbg(fotg210, "Waited too long for the periodic schedule status (%x/%x), giving up\n", in fotg210_poll_PSS()
1142 fotg210->PSS_poll_count = 0; in fotg210_poll_PSS()
1146 if (fotg210->periodic_count > 0) in fotg210_poll_PSS()
1147 fotg210_set_command_bit(fotg210, CMD_PSE); in fotg210_poll_PSS()
1150 if (fotg210->periodic_count == 0) { in fotg210_poll_PSS()
1153 fotg210_enable_event(fotg210, in fotg210_poll_PSS()
1161 static void fotg210_disable_PSE(struct fotg210_hcd *fotg210) in fotg210_disable_PSE() argument
1163 fotg210_clear_command_bit(fotg210, CMD_PSE); in fotg210_disable_PSE()
1168 static void fotg210_handle_controller_death(struct fotg210_hcd *fotg210) in fotg210_handle_controller_death() argument
1170 if (!(fotg210_readl(fotg210, &fotg210->regs->status) & STS_HALT)) { in fotg210_handle_controller_death()
1173 if (fotg210->died_poll_count++ < 5) { in fotg210_handle_controller_death()
1175 fotg210_enable_event(fotg210, in fotg210_handle_controller_death()
1179 fotg210_warn(fotg210, "Waited too long for the controller to stop, giving up\n"); in fotg210_handle_controller_death()
1183 fotg210->rh_state = FOTG210_RH_HALTED; in fotg210_handle_controller_death()
1184 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable); in fotg210_handle_controller_death()
1185 fotg210_work(fotg210); in fotg210_handle_controller_death()
1186 end_unlink_async(fotg210); in fotg210_handle_controller_death()
1193 static void fotg210_handle_intr_unlinks(struct fotg210_hcd *fotg210) in fotg210_handle_intr_unlinks() argument
1195 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING); in fotg210_handle_intr_unlinks()
1204 fotg210->intr_unlinking = true; in fotg210_handle_intr_unlinks()
1205 while (fotg210->intr_unlink) { in fotg210_handle_intr_unlinks()
1206 struct fotg210_qh *qh = fotg210->intr_unlink; in fotg210_handle_intr_unlinks()
1208 if (!stopped && qh->unlink_cycle == fotg210->intr_unlink_cycle) in fotg210_handle_intr_unlinks()
1210 fotg210->intr_unlink = qh->unlink_next; in fotg210_handle_intr_unlinks()
1212 end_unlink_intr(fotg210, qh); in fotg210_handle_intr_unlinks()
1216 if (fotg210->intr_unlink) { in fotg210_handle_intr_unlinks()
1217 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR, in fotg210_handle_intr_unlinks()
1219 ++fotg210->intr_unlink_cycle; in fotg210_handle_intr_unlinks()
1221 fotg210->intr_unlinking = false; in fotg210_handle_intr_unlinks()
1226 static void start_free_itds(struct fotg210_hcd *fotg210) in start_free_itds() argument
1228 if (!(fotg210->enabled_hrtimer_events & in start_free_itds()
1230 fotg210->last_itd_to_free = list_entry( in start_free_itds()
1231 fotg210->cached_itd_list.prev, in start_free_itds()
1233 fotg210_enable_event(fotg210, FOTG210_HRTIMER_FREE_ITDS, true); in start_free_itds()
1238 static void end_free_itds(struct fotg210_hcd *fotg210) in end_free_itds() argument
1242 if (fotg210->rh_state < FOTG210_RH_RUNNING) in end_free_itds()
1243 fotg210->last_itd_to_free = NULL; in end_free_itds()
1245 list_for_each_entry_safe(itd, n, &fotg210->cached_itd_list, itd_list) { in end_free_itds()
1247 dma_pool_free(fotg210->itd_pool, itd, itd->itd_dma); in end_free_itds()
1248 if (itd == fotg210->last_itd_to_free) in end_free_itds()
1252 if (!list_empty(&fotg210->cached_itd_list)) in end_free_itds()
1253 start_free_itds(fotg210); in end_free_itds()
1258 static void fotg210_iaa_watchdog(struct fotg210_hcd *fotg210) in fotg210_iaa_watchdog() argument
1260 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_iaa_watchdog()
1269 if (fotg210->async_iaa) { in fotg210_iaa_watchdog()
1278 cmd = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_iaa_watchdog()
1287 status = fotg210_readl(fotg210, &fotg210->regs->status); in fotg210_iaa_watchdog()
1289 INCR(fotg210->stats.lost_iaa); in fotg210_iaa_watchdog()
1290 fotg210_writel(fotg210, STS_IAA, in fotg210_iaa_watchdog()
1291 &fotg210->regs->status); in fotg210_iaa_watchdog()
1294 fotg210_dbg(fotg210, "IAA watchdog: status %x cmd %x\n", in fotg210_iaa_watchdog()
1296 end_unlink_async(fotg210); in fotg210_iaa_watchdog()
1302 static void turn_on_io_watchdog(struct fotg210_hcd *fotg210) in turn_on_io_watchdog() argument
1305 if (fotg210->rh_state != FOTG210_RH_RUNNING || in turn_on_io_watchdog()
1306 (fotg210->enabled_hrtimer_events & in turn_on_io_watchdog()
1314 if (fotg210->isoc_count > 0 || (fotg210->need_io_watchdog && in turn_on_io_watchdog()
1315 fotg210->async_count + fotg210->intr_count > 0)) in turn_on_io_watchdog()
1316 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IO_WATCHDOG, in turn_on_io_watchdog()
1340 struct fotg210_hcd *fotg210 = in fotg210_hrtimer_func() local
1347 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hrtimer_func()
1349 events = fotg210->enabled_hrtimer_events; in fotg210_hrtimer_func()
1350 fotg210->enabled_hrtimer_events = 0; in fotg210_hrtimer_func()
1351 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT; in fotg210_hrtimer_func()
1359 if (ktime_compare(now, fotg210->hr_timeouts[e]) >= 0) in fotg210_hrtimer_func()
1360 event_handlers[e](fotg210); in fotg210_hrtimer_func()
1362 fotg210_enable_event(fotg210, e, false); in fotg210_hrtimer_func()
1365 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hrtimer_func()
1372 static int check_reset_complete(struct fotg210_hcd *fotg210, int index, in check_reset_complete() argument
1381 fotg210_dbg(fotg210, "Failed to enable port %d on root hub TT\n", in check_reset_complete()
1384 fotg210_dbg(fotg210, "port %d reset complete, port enabled\n", in check_reset_complete()
1395 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_hub_status_data() local
1407 status = fotg210->resuming_ports; in fotg210_hub_status_data()
1415 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_status_data()
1417 temp = fotg210_readl(fotg210, &fotg210->regs->port_status); in fotg210_hub_status_data()
1426 if ((temp & mask) != 0 || test_bit(0, &fotg210->port_c_suspend) || in fotg210_hub_status_data()
1427 (fotg210->reset_done[0] && in fotg210_hub_status_data()
1428 time_after_eq(jiffies, fotg210->reset_done[0]))) { in fotg210_hub_status_data()
1433 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_status_data()
1437 static void fotg210_hub_descriptor(struct fotg210_hcd *fotg210, in fotg210_hub_descriptor() argument
1440 int ports = HCS_N_PORTS(fotg210->hcs_params); in fotg210_hub_descriptor()
1463 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_hub_control() local
1464 int ports = HCS_N_PORTS(fotg210->hcs_params); in fotg210_hub_control()
1465 u32 __iomem *status_reg = &fotg210->regs->port_status; in fotg210_hub_control()
1478 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_control()
1494 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1506 fotg210_writel(fotg210, temp & ~PORT_PE, status_reg); in fotg210_hub_control()
1509 fotg210_writel(fotg210, temp | PORT_PEC, status_reg); in fotg210_hub_control()
1520 fotg210_writel(fotg210, temp | PORT_RESUME, status_reg); in fotg210_hub_control()
1521 fotg210->reset_done[wIndex] = jiffies in fotg210_hub_control()
1525 clear_bit(wIndex, &fotg210->port_c_suspend); in fotg210_hub_control()
1528 fotg210_writel(fotg210, temp | PORT_CSC, status_reg); in fotg210_hub_control()
1531 fotg210_writel(fotg210, temp | OTGISR_OVC, in fotg210_hub_control()
1532 &fotg210->regs->otgisr); in fotg210_hub_control()
1540 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_hub_control()
1543 fotg210_hub_descriptor(fotg210, (struct usb_hub_descriptor *) in fotg210_hub_control()
1556 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1564 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr); in fotg210_hub_control()
1572 if (!fotg210->reset_done[wIndex]) { in fotg210_hub_control()
1574 fotg210->reset_done[wIndex] = jiffies in fotg210_hub_control()
1577 mod_timer(&fotg210_to_hcd(fotg210)->rh_timer, in fotg210_hub_control()
1578 fotg210->reset_done[wIndex]); in fotg210_hub_control()
1583 fotg210->reset_done[wIndex])) { in fotg210_hub_control()
1584 clear_bit(wIndex, &fotg210->suspended_ports); in fotg210_hub_control()
1585 set_bit(wIndex, &fotg210->port_c_suspend); in fotg210_hub_control()
1586 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1589 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1590 fotg210_writel(fotg210, temp & in fotg210_hub_control()
1593 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1594 retval = handshake(fotg210, status_reg, in fotg210_hub_control()
1597 fotg210_err(fotg210, in fotg210_hub_control()
1608 fotg210->reset_done[wIndex])) { in fotg210_hub_control()
1610 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1611 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1614 fotg210_writel(fotg210, in fotg210_hub_control()
1620 retval = handshake(fotg210, status_reg, in fotg210_hub_control()
1623 fotg210_err(fotg210, "port %d reset error %d\n", in fotg210_hub_control()
1629 temp = check_reset_complete(fotg210, wIndex, status_reg, in fotg210_hub_control()
1630 fotg210_readl(fotg210, status_reg)); in fotg210_hub_control()
1633 fotg210->command |= CMD_RUN; in fotg210_hub_control()
1634 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_hub_control()
1638 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1639 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1644 test_bit(wIndex, &fotg210->companion_ports)) { in fotg210_hub_control()
1646 fotg210_writel(fotg210, temp, status_reg); in fotg210_hub_control()
1647 fotg210_dbg(fotg210, "port %d --> companion\n", in fotg210_hub_control()
1649 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1660 status |= fotg210_port_speed(fotg210, temp); in fotg210_hub_control()
1668 } else if (test_bit(wIndex, &fotg210->suspended_ports)) { in fotg210_hub_control()
1669 clear_bit(wIndex, &fotg210->suspended_ports); in fotg210_hub_control()
1670 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1671 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1673 set_bit(wIndex, &fotg210->port_c_suspend); in fotg210_hub_control()
1676 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr); in fotg210_hub_control()
1681 if (test_bit(wIndex, &fotg210->port_c_suspend)) in fotg210_hub_control()
1685 dbg_port(fotg210, "GetStatus", wIndex + 1, temp); in fotg210_hub_control()
1705 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1717 fotg210_writel(fotg210, temp | PORT_SUSPEND, in fotg210_hub_control()
1719 set_bit(wIndex, &fotg210->suspended_ports); in fotg210_hub_control()
1728 fotg210_dbg(fotg210, "port %d reset\n", wIndex + 1); in fotg210_hub_control()
1736 fotg210->reset_done[wIndex] = jiffies in fotg210_hub_control()
1738 fotg210_writel(fotg210, temp, status_reg); in fotg210_hub_control()
1750 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_control()
1751 fotg210_quiesce(fotg210); in fotg210_hub_control()
1752 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_control()
1755 temp = fotg210_readl(fotg210, status_reg) & in fotg210_hub_control()
1758 fotg210_writel(fotg210, temp | PORT_SUSPEND, in fotg210_hub_control()
1761 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_control()
1762 fotg210_halt(fotg210); in fotg210_hub_control()
1763 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_control()
1765 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1767 fotg210_writel(fotg210, temp, status_reg); in fotg210_hub_control()
1773 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_hub_control()
1781 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_control()
1808 static inline void fotg210_qtd_init(struct fotg210_hcd *fotg210, in fotg210_qtd_init() argument
1813 qtd->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT); in fotg210_qtd_init()
1814 qtd->hw_next = FOTG210_LIST_END(fotg210); in fotg210_qtd_init()
1815 qtd->hw_alt_next = FOTG210_LIST_END(fotg210); in fotg210_qtd_init()
1819 static struct fotg210_qtd *fotg210_qtd_alloc(struct fotg210_hcd *fotg210, in fotg210_qtd_alloc() argument
1825 qtd = dma_pool_alloc(fotg210->qtd_pool, flags, &dma); in fotg210_qtd_alloc()
1827 fotg210_qtd_init(fotg210, qtd, dma); in fotg210_qtd_alloc()
1832 static inline void fotg210_qtd_free(struct fotg210_hcd *fotg210, in fotg210_qtd_free() argument
1835 dma_pool_free(fotg210->qtd_pool, qtd, qtd->qtd_dma); in fotg210_qtd_free()
1839 static void qh_destroy(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_destroy() argument
1843 fotg210_dbg(fotg210, "unused qh not empty!\n"); in qh_destroy()
1847 fotg210_qtd_free(fotg210, qh->dummy); in qh_destroy()
1848 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma); in qh_destroy()
1852 static struct fotg210_qh *fotg210_qh_alloc(struct fotg210_hcd *fotg210, in fotg210_qh_alloc() argument
1862 dma_pool_zalloc(fotg210->qh_pool, flags, &dma); in fotg210_qh_alloc()
1869 qh->dummy = fotg210_qtd_alloc(fotg210, flags); in fotg210_qh_alloc()
1871 fotg210_dbg(fotg210, "no dummy td\n"); in fotg210_qh_alloc()
1877 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma); in fotg210_qh_alloc()
1888 static void fotg210_mem_cleanup(struct fotg210_hcd *fotg210) in fotg210_mem_cleanup() argument
1890 if (fotg210->async) in fotg210_mem_cleanup()
1891 qh_destroy(fotg210, fotg210->async); in fotg210_mem_cleanup()
1892 fotg210->async = NULL; in fotg210_mem_cleanup()
1894 if (fotg210->dummy) in fotg210_mem_cleanup()
1895 qh_destroy(fotg210, fotg210->dummy); in fotg210_mem_cleanup()
1896 fotg210->dummy = NULL; in fotg210_mem_cleanup()
1899 dma_pool_destroy(fotg210->qtd_pool); in fotg210_mem_cleanup()
1900 fotg210->qtd_pool = NULL; in fotg210_mem_cleanup()
1902 dma_pool_destroy(fotg210->qh_pool); in fotg210_mem_cleanup()
1903 fotg210->qh_pool = NULL; in fotg210_mem_cleanup()
1905 dma_pool_destroy(fotg210->itd_pool); in fotg210_mem_cleanup()
1906 fotg210->itd_pool = NULL; in fotg210_mem_cleanup()
1908 if (fotg210->periodic) in fotg210_mem_cleanup()
1909 dma_free_coherent(fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_cleanup()
1910 fotg210->periodic_size * sizeof(u32), in fotg210_mem_cleanup()
1911 fotg210->periodic, fotg210->periodic_dma); in fotg210_mem_cleanup()
1912 fotg210->periodic = NULL; in fotg210_mem_cleanup()
1915 kfree(fotg210->pshadow); in fotg210_mem_cleanup()
1916 fotg210->pshadow = NULL; in fotg210_mem_cleanup()
1920 static int fotg210_mem_init(struct fotg210_hcd *fotg210, gfp_t flags) in fotg210_mem_init() argument
1925 fotg210->qtd_pool = dma_pool_create("fotg210_qtd", in fotg210_mem_init()
1926 fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1930 if (!fotg210->qtd_pool) in fotg210_mem_init()
1934 fotg210->qh_pool = dma_pool_create("fotg210_qh", in fotg210_mem_init()
1935 fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1939 if (!fotg210->qh_pool) in fotg210_mem_init()
1942 fotg210->async = fotg210_qh_alloc(fotg210, flags); in fotg210_mem_init()
1943 if (!fotg210->async) in fotg210_mem_init()
1947 fotg210->itd_pool = dma_pool_create("fotg210_itd", in fotg210_mem_init()
1948 fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1952 if (!fotg210->itd_pool) in fotg210_mem_init()
1956 fotg210->periodic = in fotg210_mem_init()
1957 dma_alloc_coherent(fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1958 fotg210->periodic_size * sizeof(__le32), in fotg210_mem_init()
1959 &fotg210->periodic_dma, 0); in fotg210_mem_init()
1960 if (fotg210->periodic == NULL) in fotg210_mem_init()
1963 for (i = 0; i < fotg210->periodic_size; i++) in fotg210_mem_init()
1964 fotg210->periodic[i] = FOTG210_LIST_END(fotg210); in fotg210_mem_init()
1967 fotg210->pshadow = kcalloc(fotg210->periodic_size, sizeof(void *), in fotg210_mem_init()
1969 if (fotg210->pshadow != NULL) in fotg210_mem_init()
1973 fotg210_dbg(fotg210, "couldn't init memory\n"); in fotg210_mem_init()
1974 fotg210_mem_cleanup(fotg210); in fotg210_mem_init()
1995 static int qtd_fill(struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd, in qtd_fill() argument
2002 qtd->hw_buf[0] = cpu_to_hc32(fotg210, (u32)addr); in qtd_fill()
2003 qtd->hw_buf_hi[0] = cpu_to_hc32(fotg210, (u32)(addr >> 32)); in qtd_fill()
2014 qtd->hw_buf[i] = cpu_to_hc32(fotg210, (u32)addr); in qtd_fill()
2015 qtd->hw_buf_hi[i] = cpu_to_hc32(fotg210, in qtd_fill()
2028 qtd->hw_token = cpu_to_hc32(fotg210, (count << 16) | token); in qtd_fill()
2034 static inline void qh_update(struct fotg210_hcd *fotg210, in qh_update() argument
2042 hw->hw_qtd_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_update()
2043 hw->hw_alt_next = FOTG210_LIST_END(fotg210); in qh_update()
2050 if (!(hw->hw_info1 & cpu_to_hc32(fotg210, QH_TOGGLE_CTL))) { in qh_update()
2054 epnum = (hc32_to_cpup(fotg210, &hw->hw_info1) >> 8) & 0x0f; in qh_update()
2056 hw->hw_token &= ~cpu_to_hc32(fotg210, QTD_TOGGLE); in qh_update()
2061 hw->hw_token &= cpu_to_hc32(fotg210, QTD_TOGGLE | QTD_STS_PING); in qh_update()
2068 static void qh_refresh(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_refresh() argument
2084 if (cpu_to_hc32(fotg210, qtd->qtd_dma) == qh->hw->hw_current) { in qh_refresh()
2091 qh_update(fotg210, qh, qtd); in qh_refresh()
2094 static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2099 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_clear_tt_buffer_complete() local
2103 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_clear_tt_buffer_complete()
2106 && fotg210->rh_state == FOTG210_RH_RUNNING) in fotg210_clear_tt_buffer_complete()
2107 qh_link_async(fotg210, qh); in fotg210_clear_tt_buffer_complete()
2108 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_clear_tt_buffer_complete()
2111 static void fotg210_clear_tt_buffer(struct fotg210_hcd *fotg210, in fotg210_clear_tt_buffer() argument
2130 fotg210_to_hcd(fotg210)->self.root_hub) { in fotg210_clear_tt_buffer()
2137 static int qtd_copy_status(struct fotg210_hcd *fotg210, struct urb *urb, in qtd_copy_status() argument
2176 fotg210_dbg(fotg210, "devpath %s ep%d%s 3strikes\n", in qtd_copy_status()
2185 fotg210_dbg(fotg210, in qtd_copy_status()
2196 static void fotg210_urb_done(struct fotg210_hcd *fotg210, struct urb *urb, in fotg210_urb_done() argument
2198 __releases(fotg210->lock) in fotg210_urb_done()
2199 __acquires(fotg210->lock) in fotg210_urb_done()
2205 if ((qh->hw->hw_info2 & cpu_to_hc32(fotg210, QH_SMASK)) != 0) { in fotg210_urb_done()
2208 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs--; in fotg210_urb_done()
2213 INCR(fotg210->stats.unlink); in fotg210_urb_done()
2218 INCR(fotg210->stats.complete); in fotg210_urb_done()
2222 fotg210_dbg(fotg210, in fotg210_urb_done()
2232 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb); in fotg210_urb_done()
2233 spin_unlock(&fotg210->lock); in fotg210_urb_done()
2234 usb_hcd_giveback_urb(fotg210_to_hcd(fotg210), urb, status); in fotg210_urb_done()
2235 spin_lock(&fotg210->lock); in fotg210_urb_done()
2238 static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2244 static unsigned qh_completions(struct fotg210_hcd *fotg210, in qh_completions() argument
2291 fotg210_urb_done(fotg210, last->urb, in qh_completions()
2296 fotg210_qtd_free(fotg210, last); in qh_completions()
2306 token = hc32_to_cpu(fotg210, qtd->hw_token); in qh_completions()
2314 fotg210_dbg(fotg210, in qh_completions()
2333 fotg210_dbg(fotg210, in qh_completions()
2347 qtd->hw_token = cpu_to_hc32(fotg210, in qh_completions()
2350 hw->hw_token = cpu_to_hc32(fotg210, in qh_completions()
2367 FOTG210_LIST_END(fotg210))) { in qh_completions()
2373 && fotg210->rh_state >= FOTG210_RH_RUNNING)) { in qh_completions()
2381 if (fotg210->rh_state < FOTG210_RH_RUNNING) in qh_completions()
2392 cpu_to_hc32(fotg210, qtd->qtd_dma) in qh_completions()
2394 token = hc32_to_cpu(fotg210, hw->hw_token); in qh_completions()
2400 fotg210_clear_tt_buffer(fotg210, qh, urb, in qh_completions()
2413 last_status = qtd_copy_status(fotg210, urb, in qh_completions()
2417 FOTG210_LIST_END(fotg210))) in qh_completions()
2435 fotg210_clear_tt_buffer(fotg210, qh, in qh_completions()
2459 fotg210_urb_done(fotg210, last->urb, last_status); in qh_completions()
2461 fotg210_qtd_free(fotg210, last); in qh_completions()
2486 if (stopped != 0 || hw->hw_qtd_next == FOTG210_LIST_END(fotg210)) { in qh_completions()
2489 qh_refresh(fotg210, qh); in qh_completions()
2517 static void qtd_list_free(struct fotg210_hcd *fotg210, struct urb *urb, in qtd_list_free() argument
2524 fotg210_qtd_free(fotg210, qtd); in qtd_list_free()
2530 static struct list_head *qh_urb_transaction(struct fotg210_hcd *fotg210, in qh_urb_transaction() argument
2544 qtd = fotg210_qtd_alloc(fotg210, flags); in qh_urb_transaction()
2558 qtd_fill(fotg210, qtd, urb->setup_dma, in qh_urb_transaction()
2565 qtd = fotg210_qtd_alloc(fotg210, flags); in qh_urb_transaction()
2569 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_urb_transaction()
2609 this_qtd_len = qtd_fill(fotg210, qtd, buf, this_sg_len, token, in qh_urb_transaction()
2621 qtd->hw_alt_next = fotg210->async->hw->hw_alt_next; in qh_urb_transaction()
2636 qtd = fotg210_qtd_alloc(fotg210, flags); in qh_urb_transaction()
2640 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_urb_transaction()
2651 qtd->hw_alt_next = FOTG210_LIST_END(fotg210); in qh_urb_transaction()
2672 qtd = fotg210_qtd_alloc(fotg210, flags); in qh_urb_transaction()
2676 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_urb_transaction()
2680 qtd_fill(fotg210, qtd, 0, 0, token, 0); in qh_urb_transaction()
2686 qtd->hw_token |= cpu_to_hc32(fotg210, QTD_IOC); in qh_urb_transaction()
2690 qtd_list_free(fotg210, urb, head); in qh_urb_transaction()
2709 static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb, in qh_make() argument
2712 struct fotg210_qh *qh = fotg210_qh_alloc(fotg210, flags); in qh_make()
2740 fotg210_dbg(fotg210, "bogus qh maxpacket %d\n", maxp); in qh_make()
2768 } else if (qh->period > fotg210->periodic_size) { in qh_make()
2769 qh->period = fotg210->periodic_size; in qh_make()
2793 if (qh->period > fotg210->periodic_size) { in qh_make()
2794 qh->period = fotg210->periodic_size; in qh_make()
2824 if (fotg210_has_fsl_portno_bug(fotg210)) in qh_make()
2832 if (tt && tt->hub != fotg210_to_hcd(fotg210)->self.root_hub) in qh_make()
2862 fotg210_dbg(fotg210, "bogus dev %p speed %d\n", urb->dev, in qh_make()
2865 qh_destroy(fotg210, qh); in qh_make()
2874 hw->hw_info1 = cpu_to_hc32(fotg210, info1); in qh_make()
2875 hw->hw_info2 = cpu_to_hc32(fotg210, info2); in qh_make()
2878 qh_refresh(fotg210, qh); in qh_make()
2882 static void enable_async(struct fotg210_hcd *fotg210) in enable_async() argument
2884 if (fotg210->async_count++) in enable_async()
2888 fotg210->enabled_hrtimer_events &= ~BIT(FOTG210_HRTIMER_DISABLE_ASYNC); in enable_async()
2891 fotg210_poll_ASS(fotg210); in enable_async()
2892 turn_on_io_watchdog(fotg210); in enable_async()
2895 static void disable_async(struct fotg210_hcd *fotg210) in disable_async() argument
2897 if (--fotg210->async_count) in disable_async()
2901 WARN_ON(fotg210->async->qh_next.qh || fotg210->async_unlink); in disable_async()
2904 fotg210_poll_ASS(fotg210); in disable_async()
2909 static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_link_async() argument
2911 __hc32 dma = QH_NEXT(fotg210, qh->qh_dma); in qh_link_async()
2921 qh_refresh(fotg210, qh); in qh_link_async()
2924 head = fotg210->async; in qh_link_async()
2936 enable_async(fotg210); in qh_link_async()
2944 static struct fotg210_qh *qh_append_tds(struct fotg210_hcd *fotg210, in qh_append_tds() argument
2949 __hc32 qh_addr_mask = cpu_to_hc32(fotg210, 0x7f); in qh_append_tds()
2954 qh = qh_make(fotg210, urb, GFP_ATOMIC); in qh_append_tds()
2987 qtd->hw_token = HALT_BIT(fotg210); in qh_append_tds()
2999 fotg210_qtd_init(fotg210, qtd, qtd->qtd_dma); in qh_append_tds()
3006 qtd->hw_next = QTD_NEXT(fotg210, dma); in qh_append_tds()
3018 static int submit_async(struct fotg210_hcd *fotg210, struct urb *urb, in submit_async() argument
3033 fotg210_dbg(fotg210, in submit_async()
3043 spin_lock_irqsave(&fotg210->lock, flags); in submit_async()
3044 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) { in submit_async()
3048 rc = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb); in submit_async()
3052 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv); in submit_async()
3054 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb); in submit_async()
3063 qh_link_async(fotg210, qh); in submit_async()
3065 spin_unlock_irqrestore(&fotg210->lock, flags); in submit_async()
3067 qtd_list_free(fotg210, urb, qtd_list); in submit_async()
3071 static void single_unlink_async(struct fotg210_hcd *fotg210, in single_unlink_async() argument
3078 if (fotg210->async_unlink) in single_unlink_async()
3079 fotg210->async_unlink_last->unlink_next = qh; in single_unlink_async()
3081 fotg210->async_unlink = qh; in single_unlink_async()
3082 fotg210->async_unlink_last = qh; in single_unlink_async()
3085 prev = fotg210->async; in single_unlink_async()
3091 if (fotg210->qh_scan_next == qh) in single_unlink_async()
3092 fotg210->qh_scan_next = qh->qh_next.qh; in single_unlink_async()
3095 static void start_iaa_cycle(struct fotg210_hcd *fotg210, bool nested) in start_iaa_cycle() argument
3101 if (fotg210->async_iaa || fotg210->async_unlinking) in start_iaa_cycle()
3105 fotg210->async_iaa = fotg210->async_unlink; in start_iaa_cycle()
3106 fotg210->async_unlink = NULL; in start_iaa_cycle()
3109 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING)) { in start_iaa_cycle()
3111 end_unlink_async(fotg210); in start_iaa_cycle()
3114 } else if (likely(fotg210->rh_state == FOTG210_RH_RUNNING)) { in start_iaa_cycle()
3118 fotg210_writel(fotg210, fotg210->command | CMD_IAAD, in start_iaa_cycle()
3119 &fotg210->regs->command); in start_iaa_cycle()
3120 fotg210_readl(fotg210, &fotg210->regs->command); in start_iaa_cycle()
3121 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IAA_WATCHDOG, in start_iaa_cycle()
3128 static void end_unlink_async(struct fotg210_hcd *fotg210) in end_unlink_async() argument
3134 fotg210->async_unlinking = true; in end_unlink_async()
3135 while (fotg210->async_iaa) { in end_unlink_async()
3136 qh = fotg210->async_iaa; in end_unlink_async()
3137 fotg210->async_iaa = qh->unlink_next; in end_unlink_async()
3143 qh_completions(fotg210, qh); in end_unlink_async()
3145 fotg210->rh_state == FOTG210_RH_RUNNING) in end_unlink_async()
3146 qh_link_async(fotg210, qh); in end_unlink_async()
3147 disable_async(fotg210); in end_unlink_async()
3149 fotg210->async_unlinking = false; in end_unlink_async()
3152 if (fotg210->async_unlink) { in end_unlink_async()
3153 start_iaa_cycle(fotg210, true); in end_unlink_async()
3154 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING)) in end_unlink_async()
3159 static void unlink_empty_async(struct fotg210_hcd *fotg210) in unlink_empty_async() argument
3162 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING); in unlink_empty_async()
3166 next = fotg210->async->qh_next.qh; in unlink_empty_async()
3174 fotg210->async_unlink_cycle) in unlink_empty_async()
3177 single_unlink_async(fotg210, qh); in unlink_empty_async()
3182 if (fotg210->async_unlink) in unlink_empty_async()
3183 start_iaa_cycle(fotg210, false); in unlink_empty_async()
3187 fotg210_enable_event(fotg210, FOTG210_HRTIMER_ASYNC_UNLINKS, in unlink_empty_async()
3189 ++fotg210->async_unlink_cycle; in unlink_empty_async()
3196 static void start_unlink_async(struct fotg210_hcd *fotg210, in start_unlink_async() argument
3210 single_unlink_async(fotg210, qh); in start_unlink_async()
3211 start_iaa_cycle(fotg210, false); in start_unlink_async()
3214 static void scan_async(struct fotg210_hcd *fotg210) in scan_async() argument
3219 fotg210->qh_scan_next = fotg210->async->qh_next.qh; in scan_async()
3220 while (fotg210->qh_scan_next) { in scan_async()
3221 qh = fotg210->qh_scan_next; in scan_async()
3222 fotg210->qh_scan_next = qh->qh_next.qh; in scan_async()
3235 temp = qh_completions(fotg210, qh); in scan_async()
3237 start_unlink_async(fotg210, qh); in scan_async()
3240 qh->unlink_cycle = fotg210->async_unlink_cycle; in scan_async()
3253 if (check_unlinks_later && fotg210->rh_state == FOTG210_RH_RUNNING && in scan_async()
3254 !(fotg210->enabled_hrtimer_events & in scan_async()
3256 fotg210_enable_event(fotg210, in scan_async()
3258 ++fotg210->async_unlink_cycle; in scan_async()
3278 static union fotg210_shadow *periodic_next_shadow(struct fotg210_hcd *fotg210, in periodic_next_shadow() argument
3281 switch (hc32_to_cpu(fotg210, tag)) { in periodic_next_shadow()
3291 static __hc32 *shadow_next_periodic(struct fotg210_hcd *fotg210, in shadow_next_periodic() argument
3294 switch (hc32_to_cpu(fotg210, tag)) { in shadow_next_periodic()
3305 static void periodic_unlink(struct fotg210_hcd *fotg210, unsigned frame, in periodic_unlink() argument
3308 union fotg210_shadow *prev_p = &fotg210->pshadow[frame]; in periodic_unlink()
3309 __hc32 *hw_p = &fotg210->periodic[frame]; in periodic_unlink()
3314 prev_p = periodic_next_shadow(fotg210, prev_p, in periodic_unlink()
3315 Q_NEXT_TYPE(fotg210, *hw_p)); in periodic_unlink()
3316 hw_p = shadow_next_periodic(fotg210, &here, in periodic_unlink()
3317 Q_NEXT_TYPE(fotg210, *hw_p)); in periodic_unlink()
3327 *prev_p = *periodic_next_shadow(fotg210, &here, in periodic_unlink()
3328 Q_NEXT_TYPE(fotg210, *hw_p)); in periodic_unlink()
3330 *hw_p = *shadow_next_periodic(fotg210, &here, in periodic_unlink()
3331 Q_NEXT_TYPE(fotg210, *hw_p)); in periodic_unlink()
3335 static unsigned short periodic_usecs(struct fotg210_hcd *fotg210, in periodic_usecs() argument
3338 __hc32 *hw_p = &fotg210->periodic[frame]; in periodic_usecs()
3339 union fotg210_shadow *q = &fotg210->pshadow[frame]; in periodic_usecs()
3344 switch (hc32_to_cpu(fotg210, Q_NEXT_TYPE(fotg210, *hw_p))) { in periodic_usecs()
3348 if (hw->hw_info2 & cpu_to_hc32(fotg210, 1 << uframe)) in periodic_usecs()
3351 if (hw->hw_info2 & cpu_to_hc32(fotg210, in periodic_usecs()
3362 if (q->fstn->hw_prev != FOTG210_LIST_END(fotg210)) in periodic_usecs()
3363 fotg210_dbg(fotg210, "ignoring FSTN cost ...\n"); in periodic_usecs()
3376 if (usecs > fotg210->uframe_periodic_max) in periodic_usecs()
3377 fotg210_err(fotg210, "uframe %d sched overrun: %d usecs\n", in periodic_usecs()
3398 static int tt_no_collision(struct fotg210_hcd *fotg210, unsigned period, in tt_no_collision() argument
3408 for (; frame < fotg210->periodic_size; frame += period) { in tt_no_collision()
3413 here = fotg210->pshadow[frame]; in tt_no_collision()
3414 type = Q_NEXT_TYPE(fotg210, fotg210->periodic[frame]); in tt_no_collision()
3416 switch (hc32_to_cpu(fotg210, type)) { in tt_no_collision()
3418 type = Q_NEXT_TYPE(fotg210, here.itd->hw_next); in tt_no_collision()
3426 mask = hc32_to_cpu(fotg210, in tt_no_collision()
3433 type = Q_NEXT_TYPE(fotg210, hw->hw_next); in tt_no_collision()
3438 fotg210_dbg(fotg210, in tt_no_collision()
3452 static void enable_periodic(struct fotg210_hcd *fotg210) in enable_periodic() argument
3454 if (fotg210->periodic_count++) in enable_periodic()
3458 fotg210->enabled_hrtimer_events &= in enable_periodic()
3462 fotg210_poll_PSS(fotg210); in enable_periodic()
3463 turn_on_io_watchdog(fotg210); in enable_periodic()
3466 static void disable_periodic(struct fotg210_hcd *fotg210) in disable_periodic() argument
3468 if (--fotg210->periodic_count) in disable_periodic()
3472 fotg210_poll_PSS(fotg210); in disable_periodic()
3481 static void qh_link_periodic(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_link_periodic() argument
3488 hc32_to_cpup(fotg210, &qh->hw->hw_info2) & in qh_link_periodic()
3496 for (i = qh->start; i < fotg210->periodic_size; i += period) { in qh_link_periodic()
3497 union fotg210_shadow *prev = &fotg210->pshadow[i]; in qh_link_periodic()
3498 __hc32 *hw_p = &fotg210->periodic[i]; in qh_link_periodic()
3504 type = Q_NEXT_TYPE(fotg210, *hw_p); in qh_link_periodic()
3505 if (type == cpu_to_hc32(fotg210, Q_TYPE_QH)) in qh_link_periodic()
3507 prev = periodic_next_shadow(fotg210, prev, type); in qh_link_periodic()
3508 hw_p = shadow_next_periodic(fotg210, &here, type); in qh_link_periodic()
3529 *hw_p = QH_NEXT(fotg210, qh->qh_dma); in qh_link_periodic()
3536 fotg210_to_hcd(fotg210)->self.bandwidth_allocated += qh->period in qh_link_periodic()
3540 list_add(&qh->intr_node, &fotg210->intr_qh_list); in qh_link_periodic()
3543 ++fotg210->intr_count; in qh_link_periodic()
3544 enable_periodic(fotg210); in qh_link_periodic()
3547 static void qh_unlink_periodic(struct fotg210_hcd *fotg210, in qh_unlink_periodic() argument
3573 for (i = qh->start; i < fotg210->periodic_size; i += period) in qh_unlink_periodic()
3574 periodic_unlink(fotg210, i, qh); in qh_unlink_periodic()
3577 fotg210_to_hcd(fotg210)->self.bandwidth_allocated -= qh->period in qh_unlink_periodic()
3583 qh->period, hc32_to_cpup(fotg210, &qh->hw->hw_info2) & in qh_unlink_periodic()
3591 if (fotg210->qh_scan_next == qh) in qh_unlink_periodic()
3592 fotg210->qh_scan_next = list_entry(qh->intr_node.next, in qh_unlink_periodic()
3597 static void start_unlink_intr(struct fotg210_hcd *fotg210, in start_unlink_intr() argument
3610 qh_unlink_periodic(fotg210, qh); in start_unlink_intr()
3620 qh->unlink_cycle = fotg210->intr_unlink_cycle; in start_unlink_intr()
3623 if (fotg210->intr_unlink) in start_unlink_intr()
3624 fotg210->intr_unlink_last->unlink_next = qh; in start_unlink_intr()
3626 fotg210->intr_unlink = qh; in start_unlink_intr()
3627 fotg210->intr_unlink_last = qh; in start_unlink_intr()
3629 if (fotg210->intr_unlinking) in start_unlink_intr()
3631 else if (fotg210->rh_state < FOTG210_RH_RUNNING) in start_unlink_intr()
3632 fotg210_handle_intr_unlinks(fotg210); in start_unlink_intr()
3633 else if (fotg210->intr_unlink == qh) { in start_unlink_intr()
3634 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR, in start_unlink_intr()
3636 ++fotg210->intr_unlink_cycle; in start_unlink_intr()
3640 static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in end_unlink_intr() argument
3646 hw->hw_next = FOTG210_LIST_END(fotg210); in end_unlink_intr()
3648 qh_completions(fotg210, qh); in end_unlink_intr()
3652 fotg210->rh_state == FOTG210_RH_RUNNING) { in end_unlink_intr()
3653 rc = qh_schedule(fotg210, qh); in end_unlink_intr()
3662 fotg210_err(fotg210, "can't reschedule qh %p, err %d\n", in end_unlink_intr()
3667 --fotg210->intr_count; in end_unlink_intr()
3668 disable_periodic(fotg210); in end_unlink_intr()
3671 static int check_period(struct fotg210_hcd *fotg210, unsigned frame, in check_period() argument
3683 usecs = fotg210->uframe_periodic_max - usecs; in check_period()
3691 claimed = periodic_usecs(fotg210, frame, in check_period()
3696 } while ((frame += 1) < fotg210->periodic_size); in check_period()
3701 claimed = periodic_usecs(fotg210, frame, uframe); in check_period()
3704 } while ((frame += period) < fotg210->periodic_size); in check_period()
3711 static int check_intr_schedule(struct fotg210_hcd *fotg210, unsigned frame, in check_intr_schedule() argument
3720 if (!check_period(fotg210, frame, uframe, qh->period, qh->usecs)) in check_intr_schedule()
3736 *c_maskp = cpu_to_hc32(fotg210, mask << 8); in check_intr_schedule()
3739 if (tt_no_collision(fotg210, qh->period, qh->dev, frame, mask)) { in check_intr_schedule()
3740 if (!check_period(fotg210, frame, uframe + qh->gap_uf + 1, in check_intr_schedule()
3743 if (!check_period(fotg210, frame, uframe + qh->gap_uf, in check_intr_schedule()
3755 static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_schedule() argument
3763 qh_refresh(fotg210, qh); in qh_schedule()
3764 hw->hw_next = FOTG210_LIST_END(fotg210); in qh_schedule()
3769 uframe = ffs(hc32_to_cpup(fotg210, &hw->hw_info2) & QH_SMASK); in qh_schedule()
3770 status = check_intr_schedule(fotg210, frame, --uframe, in qh_schedule()
3787 frame = ++fotg210->random_frame % qh->period; in qh_schedule()
3789 status = check_intr_schedule(fotg210, in qh_schedule()
3800 status = check_intr_schedule(fotg210, 0, 0, qh, in qh_schedule()
3808 hw->hw_info2 &= cpu_to_hc32(fotg210, ~(QH_CMASK | QH_SMASK)); in qh_schedule()
3810 ? cpu_to_hc32(fotg210, 1 << uframe) in qh_schedule()
3811 : cpu_to_hc32(fotg210, QH_SMASK); in qh_schedule()
3814 fotg210_dbg(fotg210, "reused qh %p schedule\n", qh); in qh_schedule()
3817 qh_link_periodic(fotg210, qh); in qh_schedule()
3822 static int intr_submit(struct fotg210_hcd *fotg210, struct urb *urb, in intr_submit() argument
3834 spin_lock_irqsave(&fotg210->lock, flags); in intr_submit()
3836 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) { in intr_submit()
3840 status = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb); in intr_submit()
3846 qh = qh_append_tds(fotg210, urb, &empty, epnum, &urb->ep->hcpriv); in intr_submit()
3852 status = qh_schedule(fotg210, qh); in intr_submit()
3858 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv); in intr_submit()
3862 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs++; in intr_submit()
3866 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb); in intr_submit()
3868 spin_unlock_irqrestore(&fotg210->lock, flags); in intr_submit()
3870 qtd_list_free(fotg210, urb, qtd_list); in intr_submit()
3875 static void scan_intr(struct fotg210_hcd *fotg210) in scan_intr() argument
3879 list_for_each_entry_safe(qh, fotg210->qh_scan_next, in scan_intr()
3880 &fotg210->intr_qh_list, intr_node) { in scan_intr()
3893 temp = qh_completions(fotg210, qh); in scan_intr()
3897 start_unlink_intr(fotg210, qh); in scan_intr()
3919 static void iso_stream_init(struct fotg210_hcd *fotg210, in iso_stream_init() argument
3947 stream->buf0 = cpu_to_hc32(fotg210, (epnum << 8) | dev->devnum); in iso_stream_init()
3948 stream->buf1 = cpu_to_hc32(fotg210, buf1); in iso_stream_init()
3949 stream->buf2 = cpu_to_hc32(fotg210, multi); in iso_stream_init()
3973 static struct fotg210_iso_stream *iso_stream_find(struct fotg210_hcd *fotg210, in iso_stream_find() argument
3987 spin_lock_irqsave(&fotg210->lock, flags); in iso_stream_find()
3995 iso_stream_init(fotg210, stream, urb->dev, urb->pipe, in iso_stream_find()
4001 fotg210_dbg(fotg210, "dev %s ep%d%s, not iso??\n", in iso_stream_find()
4007 spin_unlock_irqrestore(&fotg210->lock, flags); in iso_stream_find()
4025 static inline void itd_sched_init(struct fotg210_hcd *fotg210, in itd_sched_init() argument
4053 uframe->transaction = cpu_to_hc32(fotg210, trans); in itd_sched_init()
4074 struct fotg210_hcd *fotg210, struct urb *urb, gfp_t mem_flags) in itd_urb_transaction() argument
4087 itd_sched_init(fotg210, sched, stream, urb); in itd_urb_transaction()
4095 spin_lock_irqsave(&fotg210->lock, flags); in itd_urb_transaction()
4105 if (itd->frame == fotg210->now_frame) in itd_urb_transaction()
4111 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_urb_transaction()
4112 itd = dma_pool_alloc(fotg210->itd_pool, mem_flags, in itd_urb_transaction()
4114 spin_lock_irqsave(&fotg210->lock, flags); in itd_urb_transaction()
4117 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_urb_transaction()
4126 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_urb_transaction()
4134 static inline int itd_slot_ok(struct fotg210_hcd *fotg210, u32 mod, u32 uframe, in itd_slot_ok() argument
4140 if (periodic_usecs(fotg210, uframe >> 3, uframe & 0x7) in itd_slot_ok()
4141 > (fotg210->uframe_periodic_max - usecs)) in itd_slot_ok()
4162 static int iso_stream_schedule(struct fotg210_hcd *fotg210, struct urb *urb, in iso_stream_schedule() argument
4167 unsigned mod = fotg210->periodic_size << 3; in iso_stream_schedule()
4174 fotg210_dbg(fotg210, "iso request %p too long\n", urb); in iso_stream_schedule()
4179 now = fotg210_read_frame_index(fotg210) & (mod - 1); in iso_stream_schedule()
4194 if (!stream->highspeed && fotg210->fs_i_thresh) in iso_stream_schedule()
4195 next = now + fotg210->i_thresh; in iso_stream_schedule()
4210 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n", in iso_stream_schedule()
4241 if (itd_slot_ok(fotg210, mod, start, in iso_stream_schedule()
4248 fotg210_dbg(fotg210, "iso resched full %p (now %d max %d)\n", in iso_stream_schedule()
4258 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n", in iso_stream_schedule()
4273 if (fotg210->isoc_count == 0) in iso_stream_schedule()
4274 fotg210->next_frame = now >> 3; in iso_stream_schedule()
4283 static inline void itd_init(struct fotg210_hcd *fotg210, in itd_init() argument
4289 itd->hw_next = FOTG210_LIST_END(fotg210); in itd_init()
4300 static inline void itd_patch(struct fotg210_hcd *fotg210, in itd_patch() argument
4311 itd->hw_transaction[uframe] |= cpu_to_hc32(fotg210, pg << 12); in itd_patch()
4312 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, uf->bufp & ~(u32)0); in itd_patch()
4313 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(uf->bufp >> 32)); in itd_patch()
4320 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, bufp & ~(u32)0); in itd_patch()
4321 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(bufp >> 32)); in itd_patch()
4325 static inline void itd_link(struct fotg210_hcd *fotg210, unsigned frame, in itd_link() argument
4328 union fotg210_shadow *prev = &fotg210->pshadow[frame]; in itd_link()
4329 __hc32 *hw_p = &fotg210->periodic[frame]; in itd_link()
4335 type = Q_NEXT_TYPE(fotg210, *hw_p); in itd_link()
4336 if (type == cpu_to_hc32(fotg210, Q_TYPE_QH)) in itd_link()
4338 prev = periodic_next_shadow(fotg210, prev, type); in itd_link()
4339 hw_p = shadow_next_periodic(fotg210, &here, type); in itd_link()
4348 *hw_p = cpu_to_hc32(fotg210, itd->itd_dma | Q_TYPE_ITD); in itd_link()
4352 static void itd_link_urb(struct fotg210_hcd *fotg210, struct urb *urb, in itd_link_urb() argument
4363 fotg210_to_hcd(fotg210)->self.bandwidth_allocated in itd_link_urb()
4365 fotg210_dbg(fotg210, in itd_link_urb()
4385 itd_init(fotg210, stream, itd); in itd_link_urb()
4391 itd_patch(fotg210, itd, iso_sched, packet, uframe); in itd_link_urb()
4400 itd_link(fotg210, frame & (fotg210->periodic_size - 1), in itd_link_urb()
4411 ++fotg210->isoc_count; in itd_link_urb()
4412 enable_periodic(fotg210); in itd_link_urb()
4428 static bool itd_complete(struct fotg210_hcd *fotg210, struct fotg210_itd *itd) in itd_complete() argument
4446 t = hc32_to_cpup(fotg210, &itd->hw_transaction[uframe]); in itd_complete()
4487 fotg210_urb_done(fotg210, urb, 0); in itd_complete()
4491 --fotg210->isoc_count; in itd_complete()
4492 disable_periodic(fotg210); in itd_complete()
4495 fotg210_to_hcd(fotg210)->self.bandwidth_allocated in itd_complete()
4497 fotg210_dbg(fotg210, in itd_complete()
4512 &fotg210->cached_itd_list); in itd_complete()
4513 start_free_itds(fotg210); in itd_complete()
4519 static int itd_submit(struct fotg210_hcd *fotg210, struct urb *urb, in itd_submit() argument
4527 stream = iso_stream_find(fotg210, urb); in itd_submit()
4529 fotg210_dbg(fotg210, "can't get iso stream\n"); in itd_submit()
4533 fotg210_port_speed(fotg210, 0) == in itd_submit()
4535 fotg210_dbg(fotg210, "can't change iso interval %d --> %d\n", in itd_submit()
4541 fotg210_dbg(fotg210, in itd_submit()
4552 status = itd_urb_transaction(stream, fotg210, urb, mem_flags); in itd_submit()
4554 fotg210_dbg(fotg210, "can't init itds\n"); in itd_submit()
4559 spin_lock_irqsave(&fotg210->lock, flags); in itd_submit()
4560 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) { in itd_submit()
4564 status = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb); in itd_submit()
4567 status = iso_stream_schedule(fotg210, urb, stream); in itd_submit()
4569 itd_link_urb(fotg210, urb, fotg210->periodic_size << 3, stream); in itd_submit()
4571 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb); in itd_submit()
4573 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_submit()
4578 static inline int scan_frame_queue(struct fotg210_hcd *fotg210, unsigned frame, in scan_frame_queue() argument
4587 q_p = &fotg210->pshadow[frame]; in scan_frame_queue()
4588 hw_p = &fotg210->periodic[frame]; in scan_frame_queue()
4590 type = Q_NEXT_TYPE(fotg210, *hw_p); in scan_frame_queue()
4594 switch (hc32_to_cpu(fotg210, type)) { in scan_frame_queue()
4605 ITD_ACTIVE(fotg210)) in scan_frame_queue()
4611 type = Q_NEXT_TYPE(fotg210, in scan_frame_queue()
4625 type = Q_NEXT_TYPE(fotg210, q.itd->hw_next); in scan_frame_queue()
4627 modified = itd_complete(fotg210, q.itd); in scan_frame_queue()
4631 fotg210_dbg(fotg210, "corrupt type %d frame %d shadow %p\n", in scan_frame_queue()
4642 if (unlikely(modified && fotg210->isoc_count > 0)) in scan_frame_queue()
4648 static void scan_isoc(struct fotg210_hcd *fotg210) in scan_isoc() argument
4651 unsigned fmask = fotg210->periodic_size - 1; in scan_isoc()
4659 if (fotg210->rh_state >= FOTG210_RH_RUNNING) { in scan_isoc()
4660 uf = fotg210_read_frame_index(fotg210); in scan_isoc()
4664 now_frame = (fotg210->next_frame - 1) & fmask; in scan_isoc()
4667 fotg210->now_frame = now_frame; in scan_isoc()
4669 frame = fotg210->next_frame; in scan_isoc()
4673 ret = scan_frame_queue(fotg210, frame, in scan_isoc()
4681 fotg210->next_frame = now_frame; in scan_isoc()
4689 struct fotg210_hcd *fotg210; in uframe_periodic_max_show() local
4692 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev))); in uframe_periodic_max_show()
4693 n = scnprintf(buf, PAGE_SIZE, "%d\n", fotg210->uframe_periodic_max); in uframe_periodic_max_show()
4701 struct fotg210_hcd *fotg210; in uframe_periodic_max_store() local
4708 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev))); in uframe_periodic_max_store()
4713 fotg210_info(fotg210, "rejecting invalid request for uframe_periodic_max=%u\n", in uframe_periodic_max_store()
4724 spin_lock_irqsave(&fotg210->lock, flags); in uframe_periodic_max_store()
4731 if (uframe_periodic_max < fotg210->uframe_periodic_max) { in uframe_periodic_max_store()
4734 for (frame = 0; frame < fotg210->periodic_size; ++frame) in uframe_periodic_max_store()
4737 periodic_usecs(fotg210, frame, in uframe_periodic_max_store()
4741 fotg210_info(fotg210, in uframe_periodic_max_store()
4750 fotg210_info(fotg210, in uframe_periodic_max_store()
4755 fotg210_warn(fotg210, "max periodic bandwidth set is non-standard\n"); in uframe_periodic_max_store()
4757 fotg210->uframe_periodic_max = uframe_periodic_max; in uframe_periodic_max_store()
4761 spin_unlock_irqrestore(&fotg210->lock, flags); in uframe_periodic_max_store()
4767 static inline int create_sysfs_files(struct fotg210_hcd *fotg210) in create_sysfs_files() argument
4769 struct device *controller = fotg210_to_hcd(fotg210)->self.controller; in create_sysfs_files()
4774 static inline void remove_sysfs_files(struct fotg210_hcd *fotg210) in remove_sysfs_files() argument
4776 struct device *controller = fotg210_to_hcd(fotg210)->self.controller; in remove_sysfs_files()
4784 static void fotg210_turn_off_all_ports(struct fotg210_hcd *fotg210) in fotg210_turn_off_all_ports() argument
4786 u32 __iomem *status_reg = &fotg210->regs->port_status; in fotg210_turn_off_all_ports()
4788 fotg210_writel(fotg210, PORT_RWC_BITS, status_reg); in fotg210_turn_off_all_ports()
4794 static void fotg210_silence_controller(struct fotg210_hcd *fotg210) in fotg210_silence_controller() argument
4796 fotg210_halt(fotg210); in fotg210_silence_controller()
4798 spin_lock_irq(&fotg210->lock); in fotg210_silence_controller()
4799 fotg210->rh_state = FOTG210_RH_HALTED; in fotg210_silence_controller()
4800 fotg210_turn_off_all_ports(fotg210); in fotg210_silence_controller()
4801 spin_unlock_irq(&fotg210->lock); in fotg210_silence_controller()
4810 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_shutdown() local
4812 spin_lock_irq(&fotg210->lock); in fotg210_shutdown()
4813 fotg210->shutdown = true; in fotg210_shutdown()
4814 fotg210->rh_state = FOTG210_RH_STOPPING; in fotg210_shutdown()
4815 fotg210->enabled_hrtimer_events = 0; in fotg210_shutdown()
4816 spin_unlock_irq(&fotg210->lock); in fotg210_shutdown()
4818 fotg210_silence_controller(fotg210); in fotg210_shutdown()
4820 hrtimer_cancel(&fotg210->hrtimer); in fotg210_shutdown()
4826 static void fotg210_work(struct fotg210_hcd *fotg210) in fotg210_work() argument
4832 if (fotg210->scanning) { in fotg210_work()
4833 fotg210->need_rescan = true; in fotg210_work()
4836 fotg210->scanning = true; in fotg210_work()
4839 fotg210->need_rescan = false; in fotg210_work()
4840 if (fotg210->async_count) in fotg210_work()
4841 scan_async(fotg210); in fotg210_work()
4842 if (fotg210->intr_count > 0) in fotg210_work()
4843 scan_intr(fotg210); in fotg210_work()
4844 if (fotg210->isoc_count > 0) in fotg210_work()
4845 scan_isoc(fotg210); in fotg210_work()
4846 if (fotg210->need_rescan) in fotg210_work()
4848 fotg210->scanning = false; in fotg210_work()
4854 turn_on_io_watchdog(fotg210); in fotg210_work()
4861 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_stop() local
4863 fotg210_dbg(fotg210, "stop\n"); in fotg210_stop()
4867 spin_lock_irq(&fotg210->lock); in fotg210_stop()
4868 fotg210->enabled_hrtimer_events = 0; in fotg210_stop()
4869 spin_unlock_irq(&fotg210->lock); in fotg210_stop()
4871 fotg210_quiesce(fotg210); in fotg210_stop()
4872 fotg210_silence_controller(fotg210); in fotg210_stop()
4873 fotg210_reset(fotg210); in fotg210_stop()
4875 hrtimer_cancel(&fotg210->hrtimer); in fotg210_stop()
4876 remove_sysfs_files(fotg210); in fotg210_stop()
4877 remove_debug_files(fotg210); in fotg210_stop()
4880 spin_lock_irq(&fotg210->lock); in fotg210_stop()
4881 end_free_itds(fotg210); in fotg210_stop()
4882 spin_unlock_irq(&fotg210->lock); in fotg210_stop()
4883 fotg210_mem_cleanup(fotg210); in fotg210_stop()
4886 fotg210_dbg(fotg210, "irq normal %ld err %ld iaa %ld (lost %ld)\n", in fotg210_stop()
4887 fotg210->stats.normal, fotg210->stats.error, in fotg210_stop()
4888 fotg210->stats.iaa, fotg210->stats.lost_iaa); in fotg210_stop()
4889 fotg210_dbg(fotg210, "complete %ld unlink %ld\n", in fotg210_stop()
4890 fotg210->stats.complete, fotg210->stats.unlink); in fotg210_stop()
4893 dbg_status(fotg210, "fotg210_stop completed", in fotg210_stop()
4894 fotg210_readl(fotg210, &fotg210->regs->status)); in fotg210_stop()
4900 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in hcd_fotg210_init() local
4906 spin_lock_init(&fotg210->lock); in hcd_fotg210_init()
4911 fotg210->need_io_watchdog = 1; in hcd_fotg210_init()
4913 hrtimer_init(&fotg210->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); in hcd_fotg210_init()
4914 fotg210->hrtimer.function = fotg210_hrtimer_func; in hcd_fotg210_init()
4915 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT; in hcd_fotg210_init()
4917 hcc_params = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in hcd_fotg210_init()
4923 fotg210->uframe_periodic_max = 100; in hcd_fotg210_init()
4929 fotg210->periodic_size = DEFAULT_I_TDPS; in hcd_fotg210_init()
4930 INIT_LIST_HEAD(&fotg210->intr_qh_list); in hcd_fotg210_init()
4931 INIT_LIST_HEAD(&fotg210->cached_itd_list); in hcd_fotg210_init()
4937 fotg210->periodic_size = 1024; in hcd_fotg210_init()
4940 fotg210->periodic_size = 512; in hcd_fotg210_init()
4943 fotg210->periodic_size = 256; in hcd_fotg210_init()
4949 retval = fotg210_mem_init(fotg210, GFP_KERNEL); in hcd_fotg210_init()
4954 fotg210->i_thresh = 2; in hcd_fotg210_init()
4963 fotg210->async->qh_next.qh = NULL; in hcd_fotg210_init()
4964 hw = fotg210->async->hw; in hcd_fotg210_init()
4965 hw->hw_next = QH_NEXT(fotg210, fotg210->async->qh_dma); in hcd_fotg210_init()
4966 hw->hw_info1 = cpu_to_hc32(fotg210, QH_HEAD); in hcd_fotg210_init()
4967 hw->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT); in hcd_fotg210_init()
4968 hw->hw_qtd_next = FOTG210_LIST_END(fotg210); in hcd_fotg210_init()
4969 fotg210->async->qh_state = QH_STATE_LINKED; in hcd_fotg210_init()
4970 hw->hw_alt_next = QTD_NEXT(fotg210, fotg210->async->dummy->qtd_dma); in hcd_fotg210_init()
4989 fotg210_dbg(fotg210, "park %d\n", park); in hcd_fotg210_init()
4996 fotg210->command = temp; in hcd_fotg210_init()
5007 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_run() local
5014 fotg210_writel(fotg210, fotg210->periodic_dma, in fotg210_run()
5015 &fotg210->regs->frame_list); in fotg210_run()
5016 fotg210_writel(fotg210, (u32)fotg210->async->qh_dma, in fotg210_run()
5017 &fotg210->regs->async_next); in fotg210_run()
5031 fotg210_readl(fotg210, &fotg210->caps->hcc_params); in fotg210_run()
5037 fotg210->command &= ~(CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); in fotg210_run()
5038 fotg210->command |= CMD_RUN; in fotg210_run()
5039 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_run()
5040 dbg_cmd(fotg210, "init", fotg210->command); in fotg210_run()
5057 fotg210->rh_state = FOTG210_RH_RUNNING; in fotg210_run()
5059 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_run()
5062 fotg210->last_periodic_enable = ktime_get_real(); in fotg210_run()
5064 temp = HC_VERSION(fotg210, in fotg210_run()
5065 fotg210_readl(fotg210, &fotg210->caps->hc_capbase)); in fotg210_run()
5066 fotg210_info(fotg210, in fotg210_run()
5068 ((fotg210->sbrn & 0xf0) >> 4), (fotg210->sbrn & 0x0f), in fotg210_run()
5071 fotg210_writel(fotg210, INTR_MASK, in fotg210_run()
5072 &fotg210->regs->intr_enable); /* Turn On Interrupts */ in fotg210_run()
5078 create_debug_files(fotg210); in fotg210_run()
5079 create_sysfs_files(fotg210); in fotg210_run()
5086 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_setup() local
5089 fotg210->regs = (void __iomem *)fotg210->caps + in fotg210_setup()
5090 HC_LENGTH(fotg210, in fotg210_setup()
5091 fotg210_readl(fotg210, &fotg210->caps->hc_capbase)); in fotg210_setup()
5092 dbg_hcs_params(fotg210, "reset"); in fotg210_setup()
5093 dbg_hcc_params(fotg210, "reset"); in fotg210_setup()
5096 fotg210->hcs_params = fotg210_readl(fotg210, in fotg210_setup()
5097 &fotg210->caps->hcs_params); in fotg210_setup()
5099 fotg210->sbrn = HCD_USB2; in fotg210_setup()
5106 retval = fotg210_halt(fotg210); in fotg210_setup()
5110 fotg210_reset(fotg210); in fotg210_setup()
5117 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_irq() local
5121 spin_lock(&fotg210->lock); in fotg210_irq()
5123 status = fotg210_readl(fotg210, &fotg210->regs->status); in fotg210_irq()
5127 fotg210_dbg(fotg210, "device removed\n"); in fotg210_irq()
5139 unlikely(fotg210->rh_state == FOTG210_RH_HALTED)) { in fotg210_irq()
5140 spin_unlock(&fotg210->lock); in fotg210_irq()
5145 fotg210_writel(fotg210, masked_status, &fotg210->regs->status); in fotg210_irq()
5146 cmd = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_irq()
5150 dbg_status(fotg210, "irq", status); in fotg210_irq()
5157 INCR(fotg210->stats.normal); in fotg210_irq()
5159 INCR(fotg210->stats.error); in fotg210_irq()
5167 fotg210->enabled_hrtimer_events &= in fotg210_irq()
5177 if (fotg210->next_hrtimer_event == FOTG210_HRTIMER_IAA_WATCHDOG) in fotg210_irq()
5178 ++fotg210->next_hrtimer_event; in fotg210_irq()
5182 fotg210_dbg(fotg210, "IAA with IAAD still set?\n"); in fotg210_irq()
5183 if (fotg210->async_iaa) { in fotg210_irq()
5184 INCR(fotg210->stats.iaa); in fotg210_irq()
5185 end_unlink_async(fotg210); in fotg210_irq()
5187 fotg210_dbg(fotg210, "IAA with nothing unlinked?\n"); in fotg210_irq()
5193 u32 __iomem *status_reg = &fotg210->regs->port_status; in fotg210_irq()
5199 if (fotg210->rh_state == FOTG210_RH_SUSPENDED) in fotg210_irq()
5202 pstatus = fotg210_readl(fotg210, status_reg); in fotg210_irq()
5204 if (test_bit(0, &fotg210->suspended_ports) && in fotg210_irq()
5208 fotg210->reset_done[0] == 0) { in fotg210_irq()
5215 fotg210->reset_done[0] = jiffies + msecs_to_jiffies(25); in fotg210_irq()
5216 set_bit(0, &fotg210->resuming_ports); in fotg210_irq()
5217 fotg210_dbg(fotg210, "port 1 remote wakeup\n"); in fotg210_irq()
5218 mod_timer(&hcd->rh_timer, fotg210->reset_done[0]); in fotg210_irq()
5224 fotg210_err(fotg210, "fatal error\n"); in fotg210_irq()
5225 dbg_cmd(fotg210, "fatal", cmd); in fotg210_irq()
5226 dbg_status(fotg210, "fatal", status); in fotg210_irq()
5231 fotg210->shutdown = true; in fotg210_irq()
5232 fotg210->rh_state = FOTG210_RH_STOPPING; in fotg210_irq()
5233 fotg210->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE); in fotg210_irq()
5234 fotg210_writel(fotg210, fotg210->command, in fotg210_irq()
5235 &fotg210->regs->command); in fotg210_irq()
5236 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable); in fotg210_irq()
5237 fotg210_handle_controller_death(fotg210); in fotg210_irq()
5244 fotg210_work(fotg210); in fotg210_irq()
5245 spin_unlock(&fotg210->lock); in fotg210_irq()
5265 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_urb_enqueue() local
5280 if (!qh_urb_transaction(fotg210, urb, &qtd_list, mem_flags)) in fotg210_urb_enqueue()
5282 return submit_async(fotg210, urb, &qtd_list, mem_flags); in fotg210_urb_enqueue()
5285 if (!qh_urb_transaction(fotg210, urb, &qtd_list, mem_flags)) in fotg210_urb_enqueue()
5287 return intr_submit(fotg210, urb, &qtd_list, mem_flags); in fotg210_urb_enqueue()
5290 return itd_submit(fotg210, urb, mem_flags); in fotg210_urb_enqueue()
5300 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_urb_dequeue() local
5305 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_urb_dequeue()
5320 start_unlink_async(fotg210, qh); in fotg210_urb_dequeue()
5328 qh_completions(fotg210, qh); in fotg210_urb_dequeue()
5340 start_unlink_intr(fotg210, qh); in fotg210_urb_dequeue()
5343 qh_completions(fotg210, qh); in fotg210_urb_dequeue()
5346 fotg210_dbg(fotg210, "bogus qh %p state %d\n", in fotg210_urb_dequeue()
5360 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_urb_dequeue()
5369 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_endpoint_disable() local
5377 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_endpoint_disable()
5396 if (fotg210->rh_state < FOTG210_RH_RUNNING) in fotg210_endpoint_disable()
5401 for (tmp = fotg210->async->qh_next.qh; in fotg210_endpoint_disable()
5409 start_unlink_async(fotg210, qh); in fotg210_endpoint_disable()
5414 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_endpoint_disable()
5421 qh_destroy(fotg210, qh); in fotg210_endpoint_disable()
5429 fotg210_err(fotg210, "qh %p (#%02x) state %d%s\n", in fotg210_endpoint_disable()
5436 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_endpoint_disable()
5442 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_endpoint_reset() local
5452 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_endpoint_reset()
5472 start_unlink_async(fotg210, qh); in fotg210_endpoint_reset()
5474 start_unlink_intr(fotg210, qh); in fotg210_endpoint_reset()
5477 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_endpoint_reset()
5482 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_get_frame() local
5484 return (fotg210_read_frame_index(fotg210) >> 3) % in fotg210_get_frame()
5485 fotg210->periodic_size; in fotg210_get_frame()
5543 static void fotg210_init(struct fotg210_hcd *fotg210) in fotg210_init() argument
5548 &fotg210->regs->gmir); in fotg210_init()
5550 value = ioread32(&fotg210->regs->otgcsr); in fotg210_init()
5553 iowrite32(value, &fotg210->regs->otgcsr); in fotg210_init()
5570 struct fotg210_hcd *fotg210; in fotg210_hcd_probe() local
5601 fotg210 = hcd_to_fotg210(hcd); in fotg210_hcd_probe()
5603 fotg210->caps = hcd->regs; in fotg210_hcd_probe()
5606 fotg210->pclk = clk_get(dev, "PCLK"); in fotg210_hcd_probe()
5607 if (!IS_ERR(fotg210->pclk)) { in fotg210_hcd_probe()
5608 retval = clk_prepare_enable(fotg210->pclk); in fotg210_hcd_probe()
5613 } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) { in fotg210_hcd_probe()
5618 retval = PTR_ERR(fotg210->pclk); in fotg210_hcd_probe()
5626 fotg210_init(fotg210); in fotg210_hcd_probe()
5639 if (!IS_ERR(fotg210->pclk)) { in fotg210_hcd_probe()
5640 clk_disable_unprepare(fotg210->pclk); in fotg210_hcd_probe()
5641 clk_put(fotg210->pclk); in fotg210_hcd_probe()
5658 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_hcd_remove() local
5660 if (!IS_ERR(fotg210->pclk)) { in fotg210_hcd_remove()
5661 clk_disable_unprepare(fotg210->pclk); in fotg210_hcd_remove()
5662 clk_put(fotg210->pclk); in fotg210_hcd_remove()