Lines Matching refs:fotg210
92 #define fotg210_dbg(fotg210, fmt, args...) \ argument
93 dev_dbg(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
94 #define fotg210_err(fotg210, fmt, args...) \ argument
95 dev_err(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
96 #define fotg210_info(fotg210, fmt, args...) \ argument
97 dev_info(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
98 #define fotg210_warn(fotg210, fmt, args...) \ argument
99 dev_warn(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
104 static void dbg_hcs_params(struct fotg210_hcd *fotg210, char *label) in dbg_hcs_params() argument
106 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcs_params); in dbg_hcs_params()
108 fotg210_dbg(fotg210, "%s hcs_params 0x%x ports=%d\n", label, params, in dbg_hcs_params()
115 static void dbg_hcc_params(struct fotg210_hcd *fotg210, char *label) in dbg_hcc_params() argument
117 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in dbg_hcc_params()
119 fotg210_dbg(fotg210, "%s hcc_params %04x uframes %s%s\n", label, in dbg_hcc_params()
126 dbg_qtd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd) in dbg_qtd() argument
128 fotg210_dbg(fotg210, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd, in dbg_qtd()
129 hc32_to_cpup(fotg210, &qtd->hw_next), in dbg_qtd()
130 hc32_to_cpup(fotg210, &qtd->hw_alt_next), in dbg_qtd()
131 hc32_to_cpup(fotg210, &qtd->hw_token), in dbg_qtd()
132 hc32_to_cpup(fotg210, &qtd->hw_buf[0])); in dbg_qtd()
134 fotg210_dbg(fotg210, " p1=%08x p2=%08x p3=%08x p4=%08x\n", in dbg_qtd()
135 hc32_to_cpup(fotg210, &qtd->hw_buf[1]), in dbg_qtd()
136 hc32_to_cpup(fotg210, &qtd->hw_buf[2]), in dbg_qtd()
137 hc32_to_cpup(fotg210, &qtd->hw_buf[3]), in dbg_qtd()
138 hc32_to_cpup(fotg210, &qtd->hw_buf[4])); in dbg_qtd()
142 dbg_qh(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in dbg_qh() argument
146 fotg210_dbg(fotg210, "%s qh %p n%08x info %x %x qtd %x\n", label, qh, in dbg_qh()
150 dbg_qtd("overlay", fotg210, (struct fotg210_qtd *) &hw->hw_qtd_next); in dbg_qh()
154 dbg_itd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_itd *itd) in dbg_itd() argument
156 fotg210_dbg(fotg210, "%s[%d] itd %p, next %08x, urb %p\n", label, in dbg_itd()
157 itd->frame, itd, hc32_to_cpu(fotg210, itd->hw_next), in dbg_itd()
160 fotg210_dbg(fotg210, in dbg_itd()
162 hc32_to_cpu(fotg210, itd->hw_transaction[0]), in dbg_itd()
163 hc32_to_cpu(fotg210, itd->hw_transaction[1]), in dbg_itd()
164 hc32_to_cpu(fotg210, itd->hw_transaction[2]), in dbg_itd()
165 hc32_to_cpu(fotg210, itd->hw_transaction[3]), in dbg_itd()
166 hc32_to_cpu(fotg210, itd->hw_transaction[4]), in dbg_itd()
167 hc32_to_cpu(fotg210, itd->hw_transaction[5]), in dbg_itd()
168 hc32_to_cpu(fotg210, itd->hw_transaction[6]), in dbg_itd()
169 hc32_to_cpu(fotg210, itd->hw_transaction[7])); in dbg_itd()
171 fotg210_dbg(fotg210, in dbg_itd()
173 hc32_to_cpu(fotg210, itd->hw_bufp[0]), in dbg_itd()
174 hc32_to_cpu(fotg210, itd->hw_bufp[1]), in dbg_itd()
175 hc32_to_cpu(fotg210, itd->hw_bufp[2]), in dbg_itd()
176 hc32_to_cpu(fotg210, itd->hw_bufp[3]), in dbg_itd()
177 hc32_to_cpu(fotg210, itd->hw_bufp[4]), in dbg_itd()
178 hc32_to_cpu(fotg210, itd->hw_bufp[5]), in dbg_itd()
179 hc32_to_cpu(fotg210, itd->hw_bufp[6])); in dbg_itd()
181 fotg210_dbg(fotg210, " index: %d %d %d %d %d %d %d %d\n", in dbg_itd()
273 #define dbg_status(fotg210, label, status) { \ argument
276 fotg210_dbg(fotg210, "%s\n", _buf); \
279 #define dbg_cmd(fotg210, label, command) { \ argument
282 fotg210_dbg(fotg210, "%s\n", _buf); \
285 #define dbg_port(fotg210, label, port, status) { \ argument
287 fotg210_dbg(fotg210, "%s\n", \
350 static inline char token_mark(struct fotg210_hcd *fotg210, __hc32 token) in token_mark() argument
352 __u32 v = hc32_to_cpu(fotg210, token); in token_mark()
364 static void qh_lines(struct fotg210_hcd *fotg210, struct fotg210_qh *qh, in qh_lines() argument
374 __le32 list_end = FOTG210_LIST_END(fotg210); in qh_lines()
380 mark = token_mark(fotg210, hw->hw_token); in qh_lines()
382 if ((hw->hw_alt_next & QTD_MASK(fotg210)) == in qh_lines()
383 fotg210->async->hw->hw_alt_next) in qh_lines()
389 scratch = hc32_to_cpup(fotg210, &hw->hw_info1); in qh_lines()
390 hw_curr = (mark == '*') ? hc32_to_cpup(fotg210, &hw->hw_current) : 0; in qh_lines()
396 scratch, hc32_to_cpup(fotg210, &hw->hw_info2), in qh_lines()
397 hc32_to_cpup(fotg210, &hw->hw_token), mark, in qh_lines()
398 (cpu_to_hc32(fotg210, QTD_TOGGLE) & hw->hw_token) in qh_lines()
400 (hc32_to_cpup(fotg210, &hw->hw_alt_next) >> 1) & 0x0f); in qh_lines()
406 scratch = hc32_to_cpup(fotg210, &td->hw_token); in qh_lines()
410 else if (hw->hw_qtd_next == cpu_to_hc32(fotg210, td->qtd_dma)) in qh_lines()
413 if (td->hw_alt_next == fotg210->async->hw->hw_alt_next) in qh_lines()
461 struct fotg210_hcd *fotg210; in fill_async_buffer() local
468 fotg210 = hcd_to_fotg210(hcd); in fill_async_buffer()
478 spin_lock_irqsave(&fotg210->lock, flags); in fill_async_buffer()
479 for (qh = fotg210->async->qh_next.qh; size > 0 && qh; in fill_async_buffer()
481 qh_lines(fotg210, qh, &next, &size); in fill_async_buffer()
482 if (fotg210->async_unlink && size > 0) { in fill_async_buffer()
487 for (qh = fotg210->async_unlink; size > 0 && qh; in fill_async_buffer()
489 qh_lines(fotg210, qh, &next, &size); in fill_async_buffer()
491 spin_unlock_irqrestore(&fotg210->lock, flags); in fill_async_buffer()
497 static unsigned output_buf_tds_dir(char *buf, struct fotg210_hcd *fotg210, in output_buf_tds_dir() argument
500 u32 scratch = hc32_to_cpup(fotg210, &hw->hw_info1); in output_buf_tds_dir()
508 switch ((hc32_to_cpu(fotg210, qtd->hw_token) >> 8) & 0x03) { in output_buf_tds_dir()
528 struct fotg210_hcd *fotg210; in fill_periodic_buffer() local
543 fotg210 = hcd_to_fotg210(hcd); in fill_periodic_buffer()
547 temp = scnprintf(next, size, "size = %d\n", fotg210->periodic_size); in fill_periodic_buffer()
554 spin_lock_irqsave(&fotg210->lock, flags); in fill_periodic_buffer()
555 for (i = 0; i < fotg210->periodic_size; i++) { in fill_periodic_buffer()
556 p = fotg210->pshadow[i]; in fill_periodic_buffer()
560 tag = Q_NEXT_TYPE(fotg210, fotg210->periodic[i]); in fill_periodic_buffer()
569 switch (hc32_to_cpu(fotg210, tag)) { in fill_periodic_buffer()
574 hc32_to_cpup(fotg210, in fill_periodic_buffer()
596 fotg210, hw, in fill_periodic_buffer()
603 tag = Q_NEXT_TYPE(fotg210, hw->hw_next); in fill_periodic_buffer()
610 tag = Q_NEXT_TYPE(fotg210, p.fstn->hw_next); in fill_periodic_buffer()
616 tag = Q_NEXT_TYPE(fotg210, p.itd->hw_next); in fill_periodic_buffer()
628 spin_unlock_irqrestore(&fotg210->lock, flags); in fill_periodic_buffer()
635 static const char *rh_state_string(struct fotg210_hcd *fotg210) in rh_state_string() argument
637 switch (fotg210->rh_state) { in rh_state_string()
653 struct fotg210_hcd *fotg210; in fill_registers_buffer() local
661 fotg210 = hcd_to_fotg210(hcd); in fill_registers_buffer()
665 spin_lock_irqsave(&fotg210->lock, flags); in fill_registers_buffer()
679 i = HC_VERSION(fotg210, fotg210_readl(fotg210, in fill_registers_buffer()
680 &fotg210->caps->hc_capbase)); in fill_registers_buffer()
688 i >> 8, i & 0x0ff, rh_state_string(fotg210)); in fill_registers_buffer()
693 i = fotg210_readl(fotg210, &fotg210->caps->hcs_params); in fill_registers_buffer()
698 i = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in fill_registers_buffer()
705 fotg210_readl(fotg210, &fotg210->regs->status)); in fill_registers_buffer()
711 fotg210_readl(fotg210, &fotg210->regs->command)); in fill_registers_buffer()
717 fotg210_readl(fotg210, &fotg210->regs->intr_enable)); in fill_registers_buffer()
723 fotg210_read_frame_index(fotg210)); in fill_registers_buffer()
727 if (fotg210->async_unlink) { in fill_registers_buffer()
729 fotg210->async_unlink); in fill_registers_buffer()
737 fotg210->stats.normal, fotg210->stats.error, in fill_registers_buffer()
738 fotg210->stats.iaa, fotg210->stats.lost_iaa); in fill_registers_buffer()
743 fotg210->stats.complete, fotg210->stats.unlink); in fill_registers_buffer()
749 spin_unlock_irqrestore(&fotg210->lock, flags); in fill_registers_buffer()
857 static inline void create_debug_files(struct fotg210_hcd *fotg210) in create_debug_files() argument
859 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self; in create_debug_files()
861 fotg210->debug_dir = debugfs_create_dir(bus->bus_name, in create_debug_files()
863 if (!fotg210->debug_dir) in create_debug_files()
866 if (!debugfs_create_file("async", S_IRUGO, fotg210->debug_dir, bus, in create_debug_files()
870 if (!debugfs_create_file("periodic", S_IRUGO, fotg210->debug_dir, bus, in create_debug_files()
874 if (!debugfs_create_file("registers", S_IRUGO, fotg210->debug_dir, bus, in create_debug_files()
881 debugfs_remove_recursive(fotg210->debug_dir); in create_debug_files()
884 static inline void remove_debug_files(struct fotg210_hcd *fotg210) in remove_debug_files() argument
886 debugfs_remove_recursive(fotg210->debug_dir); in remove_debug_files()
905 static int handshake(struct fotg210_hcd *fotg210, void __iomem *ptr, in handshake() argument
911 result = fotg210_readl(fotg210, ptr); in handshake()
926 static int fotg210_halt(struct fotg210_hcd *fotg210) in fotg210_halt() argument
930 spin_lock_irq(&fotg210->lock); in fotg210_halt()
933 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable); in fotg210_halt()
939 fotg210->command &= ~CMD_RUN; in fotg210_halt()
940 temp = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_halt()
942 fotg210_writel(fotg210, temp, &fotg210->regs->command); in fotg210_halt()
944 spin_unlock_irq(&fotg210->lock); in fotg210_halt()
945 synchronize_irq(fotg210_to_hcd(fotg210)->irq); in fotg210_halt()
947 return handshake(fotg210, &fotg210->regs->status, in fotg210_halt()
954 static int fotg210_reset(struct fotg210_hcd *fotg210) in fotg210_reset() argument
957 u32 command = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_reset()
962 if (fotg210->debug && !dbgp_reset_prep(fotg210_to_hcd(fotg210))) in fotg210_reset()
963 fotg210->debug = NULL; in fotg210_reset()
966 dbg_cmd(fotg210, "reset", command); in fotg210_reset()
967 fotg210_writel(fotg210, command, &fotg210->regs->command); in fotg210_reset()
968 fotg210->rh_state = FOTG210_RH_HALTED; in fotg210_reset()
969 fotg210->next_statechange = jiffies; in fotg210_reset()
970 retval = handshake(fotg210, &fotg210->regs->command, in fotg210_reset()
976 if (fotg210->debug) in fotg210_reset()
977 dbgp_external_startup(fotg210_to_hcd(fotg210)); in fotg210_reset()
979 fotg210->port_c_suspend = fotg210->suspended_ports = in fotg210_reset()
980 fotg210->resuming_ports = 0; in fotg210_reset()
987 static void fotg210_quiesce(struct fotg210_hcd *fotg210) in fotg210_quiesce() argument
991 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_quiesce()
995 temp = (fotg210->command << 10) & (STS_ASS | STS_PSS); in fotg210_quiesce()
996 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, temp, in fotg210_quiesce()
1000 spin_lock_irq(&fotg210->lock); in fotg210_quiesce()
1001 fotg210->command &= ~(CMD_ASE | CMD_PSE); in fotg210_quiesce()
1002 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_quiesce()
1003 spin_unlock_irq(&fotg210->lock); in fotg210_quiesce()
1006 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, 0, in fotg210_quiesce()
1010 static void end_unlink_async(struct fotg210_hcd *fotg210);
1011 static void unlink_empty_async(struct fotg210_hcd *fotg210);
1012 static void fotg210_work(struct fotg210_hcd *fotg210);
1013 static void start_unlink_intr(struct fotg210_hcd *fotg210,
1015 static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
1018 static void fotg210_set_command_bit(struct fotg210_hcd *fotg210, u32 bit) in fotg210_set_command_bit() argument
1020 fotg210->command |= bit; in fotg210_set_command_bit()
1021 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_set_command_bit()
1024 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_set_command_bit()
1028 static void fotg210_clear_command_bit(struct fotg210_hcd *fotg210, u32 bit) in fotg210_clear_command_bit() argument
1030 fotg210->command &= ~bit; in fotg210_clear_command_bit()
1031 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_clear_command_bit()
1034 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_clear_command_bit()
1077 static void fotg210_enable_event(struct fotg210_hcd *fotg210, unsigned event, in fotg210_enable_event() argument
1080 ktime_t *timeout = &fotg210->hr_timeouts[event]; in fotg210_enable_event()
1085 fotg210->enabled_hrtimer_events |= (1 << event); in fotg210_enable_event()
1088 if (event < fotg210->next_hrtimer_event) { in fotg210_enable_event()
1089 fotg210->next_hrtimer_event = event; in fotg210_enable_event()
1090 hrtimer_start_range_ns(&fotg210->hrtimer, *timeout, in fotg210_enable_event()
1097 static void fotg210_poll_ASS(struct fotg210_hcd *fotg210) in fotg210_poll_ASS() argument
1102 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_poll_ASS()
1105 want = (fotg210->command & CMD_ASE) ? STS_ASS : 0; in fotg210_poll_ASS()
1106 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_ASS; in fotg210_poll_ASS()
1111 if (fotg210->ASS_poll_count++ < 20) { in fotg210_poll_ASS()
1112 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_ASS, in fotg210_poll_ASS()
1116 fotg210_dbg(fotg210, "Waited too long for the async schedule status (%x/%x), giving up\n", in fotg210_poll_ASS()
1119 fotg210->ASS_poll_count = 0; in fotg210_poll_ASS()
1123 if (fotg210->async_count > 0) in fotg210_poll_ASS()
1124 fotg210_set_command_bit(fotg210, CMD_ASE); in fotg210_poll_ASS()
1127 if (fotg210->async_count == 0) { in fotg210_poll_ASS()
1130 fotg210_enable_event(fotg210, in fotg210_poll_ASS()
1138 static void fotg210_disable_ASE(struct fotg210_hcd *fotg210) in fotg210_disable_ASE() argument
1140 fotg210_clear_command_bit(fotg210, CMD_ASE); in fotg210_disable_ASE()
1145 static void fotg210_poll_PSS(struct fotg210_hcd *fotg210) in fotg210_poll_PSS() argument
1150 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_poll_PSS()
1153 want = (fotg210->command & CMD_PSE) ? STS_PSS : 0; in fotg210_poll_PSS()
1154 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_PSS; in fotg210_poll_PSS()
1159 if (fotg210->PSS_poll_count++ < 20) { in fotg210_poll_PSS()
1160 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_PSS, in fotg210_poll_PSS()
1164 fotg210_dbg(fotg210, "Waited too long for the periodic schedule status (%x/%x), giving up\n", in fotg210_poll_PSS()
1167 fotg210->PSS_poll_count = 0; in fotg210_poll_PSS()
1171 if (fotg210->periodic_count > 0) in fotg210_poll_PSS()
1172 fotg210_set_command_bit(fotg210, CMD_PSE); in fotg210_poll_PSS()
1175 if (fotg210->periodic_count == 0) { in fotg210_poll_PSS()
1178 fotg210_enable_event(fotg210, in fotg210_poll_PSS()
1186 static void fotg210_disable_PSE(struct fotg210_hcd *fotg210) in fotg210_disable_PSE() argument
1188 fotg210_clear_command_bit(fotg210, CMD_PSE); in fotg210_disable_PSE()
1193 static void fotg210_handle_controller_death(struct fotg210_hcd *fotg210) in fotg210_handle_controller_death() argument
1195 if (!(fotg210_readl(fotg210, &fotg210->regs->status) & STS_HALT)) { in fotg210_handle_controller_death()
1198 if (fotg210->died_poll_count++ < 5) { in fotg210_handle_controller_death()
1200 fotg210_enable_event(fotg210, in fotg210_handle_controller_death()
1204 fotg210_warn(fotg210, "Waited too long for the controller to stop, giving up\n"); in fotg210_handle_controller_death()
1208 fotg210->rh_state = FOTG210_RH_HALTED; in fotg210_handle_controller_death()
1209 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable); in fotg210_handle_controller_death()
1210 fotg210_work(fotg210); in fotg210_handle_controller_death()
1211 end_unlink_async(fotg210); in fotg210_handle_controller_death()
1218 static void fotg210_handle_intr_unlinks(struct fotg210_hcd *fotg210) in fotg210_handle_intr_unlinks() argument
1220 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING); in fotg210_handle_intr_unlinks()
1229 fotg210->intr_unlinking = true; in fotg210_handle_intr_unlinks()
1230 while (fotg210->intr_unlink) { in fotg210_handle_intr_unlinks()
1231 struct fotg210_qh *qh = fotg210->intr_unlink; in fotg210_handle_intr_unlinks()
1233 if (!stopped && qh->unlink_cycle == fotg210->intr_unlink_cycle) in fotg210_handle_intr_unlinks()
1235 fotg210->intr_unlink = qh->unlink_next; in fotg210_handle_intr_unlinks()
1237 end_unlink_intr(fotg210, qh); in fotg210_handle_intr_unlinks()
1241 if (fotg210->intr_unlink) { in fotg210_handle_intr_unlinks()
1242 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR, in fotg210_handle_intr_unlinks()
1244 ++fotg210->intr_unlink_cycle; in fotg210_handle_intr_unlinks()
1246 fotg210->intr_unlinking = false; in fotg210_handle_intr_unlinks()
1251 static void start_free_itds(struct fotg210_hcd *fotg210) in start_free_itds() argument
1253 if (!(fotg210->enabled_hrtimer_events & in start_free_itds()
1255 fotg210->last_itd_to_free = list_entry( in start_free_itds()
1256 fotg210->cached_itd_list.prev, in start_free_itds()
1258 fotg210_enable_event(fotg210, FOTG210_HRTIMER_FREE_ITDS, true); in start_free_itds()
1263 static void end_free_itds(struct fotg210_hcd *fotg210) in end_free_itds() argument
1267 if (fotg210->rh_state < FOTG210_RH_RUNNING) in end_free_itds()
1268 fotg210->last_itd_to_free = NULL; in end_free_itds()
1270 list_for_each_entry_safe(itd, n, &fotg210->cached_itd_list, itd_list) { in end_free_itds()
1272 dma_pool_free(fotg210->itd_pool, itd, itd->itd_dma); in end_free_itds()
1273 if (itd == fotg210->last_itd_to_free) in end_free_itds()
1277 if (!list_empty(&fotg210->cached_itd_list)) in end_free_itds()
1278 start_free_itds(fotg210); in end_free_itds()
1283 static void fotg210_iaa_watchdog(struct fotg210_hcd *fotg210) in fotg210_iaa_watchdog() argument
1285 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_iaa_watchdog()
1294 if (fotg210->async_iaa) { in fotg210_iaa_watchdog()
1303 cmd = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_iaa_watchdog()
1312 status = fotg210_readl(fotg210, &fotg210->regs->status); in fotg210_iaa_watchdog()
1314 COUNT(fotg210->stats.lost_iaa); in fotg210_iaa_watchdog()
1315 fotg210_writel(fotg210, STS_IAA, in fotg210_iaa_watchdog()
1316 &fotg210->regs->status); in fotg210_iaa_watchdog()
1319 fotg210_dbg(fotg210, "IAA watchdog: status %x cmd %x\n", in fotg210_iaa_watchdog()
1321 end_unlink_async(fotg210); in fotg210_iaa_watchdog()
1327 static void turn_on_io_watchdog(struct fotg210_hcd *fotg210) in turn_on_io_watchdog() argument
1330 if (fotg210->rh_state != FOTG210_RH_RUNNING || in turn_on_io_watchdog()
1331 (fotg210->enabled_hrtimer_events & in turn_on_io_watchdog()
1339 if (fotg210->isoc_count > 0 || (fotg210->need_io_watchdog && in turn_on_io_watchdog()
1340 fotg210->async_count + fotg210->intr_count > 0)) in turn_on_io_watchdog()
1341 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IO_WATCHDOG, in turn_on_io_watchdog()
1365 struct fotg210_hcd *fotg210 = in fotg210_hrtimer_func() local
1372 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hrtimer_func()
1374 events = fotg210->enabled_hrtimer_events; in fotg210_hrtimer_func()
1375 fotg210->enabled_hrtimer_events = 0; in fotg210_hrtimer_func()
1376 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT; in fotg210_hrtimer_func()
1384 if (now.tv64 >= fotg210->hr_timeouts[e].tv64) in fotg210_hrtimer_func()
1385 event_handlers[e](fotg210); in fotg210_hrtimer_func()
1387 fotg210_enable_event(fotg210, e, false); in fotg210_hrtimer_func()
1390 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hrtimer_func()
1397 static int check_reset_complete(struct fotg210_hcd *fotg210, int index, in check_reset_complete() argument
1406 fotg210_dbg(fotg210, "Failed to enable port %d on root hub TT\n", in check_reset_complete()
1409 fotg210_dbg(fotg210, "port %d reset complete, port enabled\n", in check_reset_complete()
1420 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_hub_status_data() local
1432 status = fotg210->resuming_ports; in fotg210_hub_status_data()
1440 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_status_data()
1442 temp = fotg210_readl(fotg210, &fotg210->regs->port_status); in fotg210_hub_status_data()
1451 if ((temp & mask) != 0 || test_bit(0, &fotg210->port_c_suspend) || in fotg210_hub_status_data()
1452 (fotg210->reset_done[0] && in fotg210_hub_status_data()
1453 time_after_eq(jiffies, fotg210->reset_done[0]))) { in fotg210_hub_status_data()
1458 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_status_data()
1462 static void fotg210_hub_descriptor(struct fotg210_hcd *fotg210, in fotg210_hub_descriptor() argument
1465 int ports = HCS_N_PORTS(fotg210->hcs_params); in fotg210_hub_descriptor()
1488 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_hub_control() local
1489 int ports = HCS_N_PORTS(fotg210->hcs_params); in fotg210_hub_control()
1490 u32 __iomem *status_reg = &fotg210->regs->port_status; in fotg210_hub_control()
1503 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_control()
1519 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1531 fotg210_writel(fotg210, temp & ~PORT_PE, status_reg); in fotg210_hub_control()
1534 fotg210_writel(fotg210, temp | PORT_PEC, status_reg); in fotg210_hub_control()
1545 fotg210_writel(fotg210, temp | PORT_RESUME, status_reg); in fotg210_hub_control()
1546 fotg210->reset_done[wIndex] = jiffies in fotg210_hub_control()
1550 clear_bit(wIndex, &fotg210->port_c_suspend); in fotg210_hub_control()
1553 fotg210_writel(fotg210, temp | PORT_CSC, status_reg); in fotg210_hub_control()
1556 fotg210_writel(fotg210, temp | OTGISR_OVC, in fotg210_hub_control()
1557 &fotg210->regs->otgisr); in fotg210_hub_control()
1565 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_hub_control()
1568 fotg210_hub_descriptor(fotg210, (struct usb_hub_descriptor *) in fotg210_hub_control()
1581 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1589 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr); in fotg210_hub_control()
1597 if (!fotg210->reset_done[wIndex]) { in fotg210_hub_control()
1599 fotg210->reset_done[wIndex] = jiffies in fotg210_hub_control()
1602 mod_timer(&fotg210_to_hcd(fotg210)->rh_timer, in fotg210_hub_control()
1603 fotg210->reset_done[wIndex]); in fotg210_hub_control()
1608 fotg210->reset_done[wIndex])) { in fotg210_hub_control()
1609 clear_bit(wIndex, &fotg210->suspended_ports); in fotg210_hub_control()
1610 set_bit(wIndex, &fotg210->port_c_suspend); in fotg210_hub_control()
1611 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1614 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1615 fotg210_writel(fotg210, temp & in fotg210_hub_control()
1618 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1619 retval = handshake(fotg210, status_reg, in fotg210_hub_control()
1622 fotg210_err(fotg210, in fotg210_hub_control()
1633 fotg210->reset_done[wIndex])) { in fotg210_hub_control()
1635 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1636 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1639 fotg210_writel(fotg210, in fotg210_hub_control()
1645 retval = handshake(fotg210, status_reg, in fotg210_hub_control()
1648 fotg210_err(fotg210, "port %d reset error %d\n", in fotg210_hub_control()
1654 temp = check_reset_complete(fotg210, wIndex, status_reg, in fotg210_hub_control()
1655 fotg210_readl(fotg210, status_reg)); in fotg210_hub_control()
1659 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1660 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1665 test_bit(wIndex, &fotg210->companion_ports)) { in fotg210_hub_control()
1667 fotg210_writel(fotg210, temp, status_reg); in fotg210_hub_control()
1668 fotg210_dbg(fotg210, "port %d --> companion\n", in fotg210_hub_control()
1670 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1681 status |= fotg210_port_speed(fotg210, temp); in fotg210_hub_control()
1689 } else if (test_bit(wIndex, &fotg210->suspended_ports)) { in fotg210_hub_control()
1690 clear_bit(wIndex, &fotg210->suspended_ports); in fotg210_hub_control()
1691 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1692 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1694 set_bit(wIndex, &fotg210->port_c_suspend); in fotg210_hub_control()
1697 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr); in fotg210_hub_control()
1702 if (test_bit(wIndex, &fotg210->port_c_suspend)) in fotg210_hub_control()
1706 dbg_port(fotg210, "GetStatus", wIndex + 1, temp); in fotg210_hub_control()
1726 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1738 fotg210_writel(fotg210, temp | PORT_SUSPEND, in fotg210_hub_control()
1740 set_bit(wIndex, &fotg210->suspended_ports); in fotg210_hub_control()
1749 fotg210_dbg(fotg210, "port %d reset\n", wIndex + 1); in fotg210_hub_control()
1757 fotg210->reset_done[wIndex] = jiffies in fotg210_hub_control()
1759 fotg210_writel(fotg210, temp, status_reg); in fotg210_hub_control()
1771 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_control()
1772 fotg210_quiesce(fotg210); in fotg210_hub_control()
1773 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_control()
1776 temp = fotg210_readl(fotg210, status_reg) & in fotg210_hub_control()
1779 fotg210_writel(fotg210, temp | PORT_SUSPEND, in fotg210_hub_control()
1782 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_control()
1783 fotg210_halt(fotg210); in fotg210_hub_control()
1784 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_control()
1786 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1788 fotg210_writel(fotg210, temp, status_reg); in fotg210_hub_control()
1794 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_hub_control()
1802 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_control()
1829 static inline void fotg210_qtd_init(struct fotg210_hcd *fotg210, in fotg210_qtd_init() argument
1834 qtd->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT); in fotg210_qtd_init()
1835 qtd->hw_next = FOTG210_LIST_END(fotg210); in fotg210_qtd_init()
1836 qtd->hw_alt_next = FOTG210_LIST_END(fotg210); in fotg210_qtd_init()
1840 static struct fotg210_qtd *fotg210_qtd_alloc(struct fotg210_hcd *fotg210, in fotg210_qtd_alloc() argument
1846 qtd = dma_pool_alloc(fotg210->qtd_pool, flags, &dma); in fotg210_qtd_alloc()
1848 fotg210_qtd_init(fotg210, qtd, dma); in fotg210_qtd_alloc()
1853 static inline void fotg210_qtd_free(struct fotg210_hcd *fotg210, in fotg210_qtd_free() argument
1856 dma_pool_free(fotg210->qtd_pool, qtd, qtd->qtd_dma); in fotg210_qtd_free()
1860 static void qh_destroy(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_destroy() argument
1864 fotg210_dbg(fotg210, "unused qh not empty!\n"); in qh_destroy()
1868 fotg210_qtd_free(fotg210, qh->dummy); in qh_destroy()
1869 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma); in qh_destroy()
1873 static struct fotg210_qh *fotg210_qh_alloc(struct fotg210_hcd *fotg210, in fotg210_qh_alloc() argument
1883 dma_pool_alloc(fotg210->qh_pool, flags, &dma); in fotg210_qh_alloc()
1891 qh->dummy = fotg210_qtd_alloc(fotg210, flags); in fotg210_qh_alloc()
1893 fotg210_dbg(fotg210, "no dummy td\n"); in fotg210_qh_alloc()
1899 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma); in fotg210_qh_alloc()
1910 static void fotg210_mem_cleanup(struct fotg210_hcd *fotg210) in fotg210_mem_cleanup() argument
1912 if (fotg210->async) in fotg210_mem_cleanup()
1913 qh_destroy(fotg210, fotg210->async); in fotg210_mem_cleanup()
1914 fotg210->async = NULL; in fotg210_mem_cleanup()
1916 if (fotg210->dummy) in fotg210_mem_cleanup()
1917 qh_destroy(fotg210, fotg210->dummy); in fotg210_mem_cleanup()
1918 fotg210->dummy = NULL; in fotg210_mem_cleanup()
1921 dma_pool_destroy(fotg210->qtd_pool); in fotg210_mem_cleanup()
1922 fotg210->qtd_pool = NULL; in fotg210_mem_cleanup()
1924 dma_pool_destroy(fotg210->qh_pool); in fotg210_mem_cleanup()
1925 fotg210->qh_pool = NULL; in fotg210_mem_cleanup()
1927 dma_pool_destroy(fotg210->itd_pool); in fotg210_mem_cleanup()
1928 fotg210->itd_pool = NULL; in fotg210_mem_cleanup()
1930 if (fotg210->periodic) in fotg210_mem_cleanup()
1931 dma_free_coherent(fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_cleanup()
1932 fotg210->periodic_size * sizeof(u32), in fotg210_mem_cleanup()
1933 fotg210->periodic, fotg210->periodic_dma); in fotg210_mem_cleanup()
1934 fotg210->periodic = NULL; in fotg210_mem_cleanup()
1937 kfree(fotg210->pshadow); in fotg210_mem_cleanup()
1938 fotg210->pshadow = NULL; in fotg210_mem_cleanup()
1942 static int fotg210_mem_init(struct fotg210_hcd *fotg210, gfp_t flags) in fotg210_mem_init() argument
1947 fotg210->qtd_pool = dma_pool_create("fotg210_qtd", in fotg210_mem_init()
1948 fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1952 if (!fotg210->qtd_pool) in fotg210_mem_init()
1956 fotg210->qh_pool = dma_pool_create("fotg210_qh", in fotg210_mem_init()
1957 fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1961 if (!fotg210->qh_pool) in fotg210_mem_init()
1964 fotg210->async = fotg210_qh_alloc(fotg210, flags); in fotg210_mem_init()
1965 if (!fotg210->async) in fotg210_mem_init()
1969 fotg210->itd_pool = dma_pool_create("fotg210_itd", in fotg210_mem_init()
1970 fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1974 if (!fotg210->itd_pool) in fotg210_mem_init()
1978 fotg210->periodic = (__le32 *) in fotg210_mem_init()
1979 dma_alloc_coherent(fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1980 fotg210->periodic_size * sizeof(__le32), in fotg210_mem_init()
1981 &fotg210->periodic_dma, 0); in fotg210_mem_init()
1982 if (fotg210->periodic == NULL) in fotg210_mem_init()
1985 for (i = 0; i < fotg210->periodic_size; i++) in fotg210_mem_init()
1986 fotg210->periodic[i] = FOTG210_LIST_END(fotg210); in fotg210_mem_init()
1989 fotg210->pshadow = kcalloc(fotg210->periodic_size, sizeof(void *), in fotg210_mem_init()
1991 if (fotg210->pshadow != NULL) in fotg210_mem_init()
1995 fotg210_dbg(fotg210, "couldn't init memory\n"); in fotg210_mem_init()
1996 fotg210_mem_cleanup(fotg210); in fotg210_mem_init()
2017 static int qtd_fill(struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd, in qtd_fill() argument
2024 qtd->hw_buf[0] = cpu_to_hc32(fotg210, (u32)addr); in qtd_fill()
2025 qtd->hw_buf_hi[0] = cpu_to_hc32(fotg210, (u32)(addr >> 32)); in qtd_fill()
2036 qtd->hw_buf[i] = cpu_to_hc32(fotg210, (u32)addr); in qtd_fill()
2037 qtd->hw_buf_hi[i] = cpu_to_hc32(fotg210, in qtd_fill()
2050 qtd->hw_token = cpu_to_hc32(fotg210, (count << 16) | token); in qtd_fill()
2056 static inline void qh_update(struct fotg210_hcd *fotg210, in qh_update() argument
2064 hw->hw_qtd_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_update()
2065 hw->hw_alt_next = FOTG210_LIST_END(fotg210); in qh_update()
2072 if (!(hw->hw_info1 & cpu_to_hc32(fotg210, QH_TOGGLE_CTL))) { in qh_update()
2076 epnum = (hc32_to_cpup(fotg210, &hw->hw_info1) >> 8) & 0x0f; in qh_update()
2078 hw->hw_token &= ~cpu_to_hc32(fotg210, QTD_TOGGLE); in qh_update()
2083 hw->hw_token &= cpu_to_hc32(fotg210, QTD_TOGGLE | QTD_STS_PING); in qh_update()
2090 static void qh_refresh(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_refresh() argument
2106 if (cpu_to_hc32(fotg210, qtd->qtd_dma) == qh->hw->hw_current) { in qh_refresh()
2113 qh_update(fotg210, qh, qtd); in qh_refresh()
2116 static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2121 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_clear_tt_buffer_complete() local
2125 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_clear_tt_buffer_complete()
2128 && fotg210->rh_state == FOTG210_RH_RUNNING) in fotg210_clear_tt_buffer_complete()
2129 qh_link_async(fotg210, qh); in fotg210_clear_tt_buffer_complete()
2130 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_clear_tt_buffer_complete()
2133 static void fotg210_clear_tt_buffer(struct fotg210_hcd *fotg210, in fotg210_clear_tt_buffer() argument
2152 fotg210_to_hcd(fotg210)->self.root_hub) { in fotg210_clear_tt_buffer()
2159 static int qtd_copy_status(struct fotg210_hcd *fotg210, struct urb *urb, in qtd_copy_status() argument
2198 fotg210_dbg(fotg210, "devpath %s ep%d%s 3strikes\n", in qtd_copy_status()
2207 fotg210_dbg(fotg210, in qtd_copy_status()
2218 static void fotg210_urb_done(struct fotg210_hcd *fotg210, struct urb *urb, in fotg210_urb_done() argument
2220 __releases(fotg210->lock) in fotg210_urb_done()
2221 __acquires(fotg210->lock) in fotg210_urb_done()
2227 if ((qh->hw->hw_info2 & cpu_to_hc32(fotg210, QH_SMASK)) != 0) { in fotg210_urb_done()
2230 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs--; in fotg210_urb_done()
2235 COUNT(fotg210->stats.unlink); in fotg210_urb_done()
2240 COUNT(fotg210->stats.complete); in fotg210_urb_done()
2244 fotg210_dbg(fotg210, in fotg210_urb_done()
2254 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb); in fotg210_urb_done()
2255 spin_unlock(&fotg210->lock); in fotg210_urb_done()
2256 usb_hcd_giveback_urb(fotg210_to_hcd(fotg210), urb, status); in fotg210_urb_done()
2257 spin_lock(&fotg210->lock); in fotg210_urb_done()
2260 static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2266 static unsigned qh_completions(struct fotg210_hcd *fotg210, in qh_completions() argument
2315 fotg210_urb_done(fotg210, last->urb, in qh_completions()
2320 fotg210_qtd_free(fotg210, last); in qh_completions()
2330 token = hc32_to_cpu(fotg210, qtd->hw_token); in qh_completions()
2338 fotg210_dbg(fotg210, in qh_completions()
2357 fotg210_dbg(fotg210, in qh_completions()
2371 qtd->hw_token = cpu_to_hc32(fotg210, in qh_completions()
2374 hw->hw_token = cpu_to_hc32(fotg210, in qh_completions()
2391 FOTG210_LIST_END(fotg210))) { in qh_completions()
2397 && fotg210->rh_state >= FOTG210_RH_RUNNING)) { in qh_completions()
2405 if (fotg210->rh_state < FOTG210_RH_RUNNING) in qh_completions()
2416 cpu_to_hc32(fotg210, qtd->qtd_dma) in qh_completions()
2418 token = hc32_to_cpu(fotg210, hw->hw_token); in qh_completions()
2424 fotg210_clear_tt_buffer(fotg210, qh, urb, in qh_completions()
2437 last_status = qtd_copy_status(fotg210, urb, in qh_completions()
2441 FOTG210_LIST_END(fotg210))) in qh_completions()
2459 fotg210_clear_tt_buffer(fotg210, qh, in qh_completions()
2483 fotg210_urb_done(fotg210, last->urb, last_status); in qh_completions()
2485 fotg210_qtd_free(fotg210, last); in qh_completions()
2510 if (stopped != 0 || hw->hw_qtd_next == FOTG210_LIST_END(fotg210)) { in qh_completions()
2513 qh_refresh(fotg210, qh); in qh_completions()
2546 static void qtd_list_free(struct fotg210_hcd *fotg210, struct urb *urb, in qtd_list_free() argument
2556 fotg210_qtd_free(fotg210, qtd); in qtd_list_free()
2562 static struct list_head *qh_urb_transaction(struct fotg210_hcd *fotg210, in qh_urb_transaction() argument
2576 qtd = fotg210_qtd_alloc(fotg210, flags); in qh_urb_transaction()
2590 qtd_fill(fotg210, qtd, urb->setup_dma, in qh_urb_transaction()
2597 qtd = fotg210_qtd_alloc(fotg210, flags); in qh_urb_transaction()
2601 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_urb_transaction()
2641 this_qtd_len = qtd_fill(fotg210, qtd, buf, this_sg_len, token, in qh_urb_transaction()
2653 qtd->hw_alt_next = fotg210->async->hw->hw_alt_next; in qh_urb_transaction()
2668 qtd = fotg210_qtd_alloc(fotg210, flags); in qh_urb_transaction()
2672 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_urb_transaction()
2683 qtd->hw_alt_next = FOTG210_LIST_END(fotg210); in qh_urb_transaction()
2704 qtd = fotg210_qtd_alloc(fotg210, flags); in qh_urb_transaction()
2708 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_urb_transaction()
2712 qtd_fill(fotg210, qtd, 0, 0, token, 0); in qh_urb_transaction()
2718 qtd->hw_token |= cpu_to_hc32(fotg210, QTD_IOC); in qh_urb_transaction()
2722 qtd_list_free(fotg210, urb, head); in qh_urb_transaction()
2741 static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb, in qh_make() argument
2744 struct fotg210_qh *qh = fotg210_qh_alloc(fotg210, flags); in qh_make()
2768 fotg210_dbg(fotg210, "bogus qh maxpacket %d\n", in qh_make()
2798 } else if (qh->period > fotg210->periodic_size) { in qh_make()
2799 qh->period = fotg210->periodic_size; in qh_make()
2823 if (qh->period > fotg210->periodic_size) { in qh_make()
2824 qh->period = fotg210->periodic_size; in qh_make()
2854 if (fotg210_has_fsl_portno_bug(fotg210)) in qh_make()
2862 if (tt && tt->hub != fotg210_to_hcd(fotg210)->self.root_hub) in qh_make()
2892 fotg210_dbg(fotg210, "bogus dev %p speed %d\n", urb->dev, in qh_make()
2895 qh_destroy(fotg210, qh); in qh_make()
2904 hw->hw_info1 = cpu_to_hc32(fotg210, info1); in qh_make()
2905 hw->hw_info2 = cpu_to_hc32(fotg210, info2); in qh_make()
2908 qh_refresh(fotg210, qh); in qh_make()
2912 static void enable_async(struct fotg210_hcd *fotg210) in enable_async() argument
2914 if (fotg210->async_count++) in enable_async()
2918 fotg210->enabled_hrtimer_events &= ~BIT(FOTG210_HRTIMER_DISABLE_ASYNC); in enable_async()
2921 fotg210_poll_ASS(fotg210); in enable_async()
2922 turn_on_io_watchdog(fotg210); in enable_async()
2925 static void disable_async(struct fotg210_hcd *fotg210) in disable_async() argument
2927 if (--fotg210->async_count) in disable_async()
2931 WARN_ON(fotg210->async->qh_next.qh || fotg210->async_unlink); in disable_async()
2934 fotg210_poll_ASS(fotg210); in disable_async()
2939 static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_link_async() argument
2941 __hc32 dma = QH_NEXT(fotg210, qh->qh_dma); in qh_link_async()
2951 qh_refresh(fotg210, qh); in qh_link_async()
2954 head = fotg210->async; in qh_link_async()
2966 enable_async(fotg210); in qh_link_async()
2974 static struct fotg210_qh *qh_append_tds(struct fotg210_hcd *fotg210, in qh_append_tds() argument
2979 __hc32 qh_addr_mask = cpu_to_hc32(fotg210, 0x7f); in qh_append_tds()
2984 qh = qh_make(fotg210, urb, GFP_ATOMIC); in qh_append_tds()
3017 qtd->hw_token = HALT_BIT(fotg210); in qh_append_tds()
3029 fotg210_qtd_init(fotg210, qtd, qtd->qtd_dma); in qh_append_tds()
3036 qtd->hw_next = QTD_NEXT(fotg210, dma); in qh_append_tds()
3048 static int submit_async(struct fotg210_hcd *fotg210, struct urb *urb, in submit_async() argument
3063 fotg210_dbg(fotg210, in submit_async()
3073 spin_lock_irqsave(&fotg210->lock, flags); in submit_async()
3074 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) { in submit_async()
3078 rc = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb); in submit_async()
3082 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv); in submit_async()
3084 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb); in submit_async()
3093 qh_link_async(fotg210, qh); in submit_async()
3095 spin_unlock_irqrestore(&fotg210->lock, flags); in submit_async()
3097 qtd_list_free(fotg210, urb, qtd_list); in submit_async()
3101 static void single_unlink_async(struct fotg210_hcd *fotg210, in single_unlink_async() argument
3108 if (fotg210->async_unlink) in single_unlink_async()
3109 fotg210->async_unlink_last->unlink_next = qh; in single_unlink_async()
3111 fotg210->async_unlink = qh; in single_unlink_async()
3112 fotg210->async_unlink_last = qh; in single_unlink_async()
3115 prev = fotg210->async; in single_unlink_async()
3121 if (fotg210->qh_scan_next == qh) in single_unlink_async()
3122 fotg210->qh_scan_next = qh->qh_next.qh; in single_unlink_async()
3125 static void start_iaa_cycle(struct fotg210_hcd *fotg210, bool nested) in start_iaa_cycle() argument
3131 if (fotg210->async_iaa || fotg210->async_unlinking) in start_iaa_cycle()
3135 fotg210->async_iaa = fotg210->async_unlink; in start_iaa_cycle()
3136 fotg210->async_unlink = NULL; in start_iaa_cycle()
3139 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING)) { in start_iaa_cycle()
3141 end_unlink_async(fotg210); in start_iaa_cycle()
3144 } else if (likely(fotg210->rh_state == FOTG210_RH_RUNNING)) { in start_iaa_cycle()
3148 fotg210_writel(fotg210, fotg210->command | CMD_IAAD, in start_iaa_cycle()
3149 &fotg210->regs->command); in start_iaa_cycle()
3150 fotg210_readl(fotg210, &fotg210->regs->command); in start_iaa_cycle()
3151 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IAA_WATCHDOG, in start_iaa_cycle()
3158 static void end_unlink_async(struct fotg210_hcd *fotg210) in end_unlink_async() argument
3164 fotg210->async_unlinking = true; in end_unlink_async()
3165 while (fotg210->async_iaa) { in end_unlink_async()
3166 qh = fotg210->async_iaa; in end_unlink_async()
3167 fotg210->async_iaa = qh->unlink_next; in end_unlink_async()
3173 qh_completions(fotg210, qh); in end_unlink_async()
3175 fotg210->rh_state == FOTG210_RH_RUNNING) in end_unlink_async()
3176 qh_link_async(fotg210, qh); in end_unlink_async()
3177 disable_async(fotg210); in end_unlink_async()
3179 fotg210->async_unlinking = false; in end_unlink_async()
3182 if (fotg210->async_unlink) { in end_unlink_async()
3183 start_iaa_cycle(fotg210, true); in end_unlink_async()
3184 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING)) in end_unlink_async()
3189 static void unlink_empty_async(struct fotg210_hcd *fotg210) in unlink_empty_async() argument
3192 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING); in unlink_empty_async()
3196 next = fotg210->async->qh_next.qh; in unlink_empty_async()
3204 fotg210->async_unlink_cycle) in unlink_empty_async()
3207 single_unlink_async(fotg210, qh); in unlink_empty_async()
3212 if (fotg210->async_unlink) in unlink_empty_async()
3213 start_iaa_cycle(fotg210, false); in unlink_empty_async()
3217 fotg210_enable_event(fotg210, FOTG210_HRTIMER_ASYNC_UNLINKS, in unlink_empty_async()
3219 ++fotg210->async_unlink_cycle; in unlink_empty_async()
3226 static void start_unlink_async(struct fotg210_hcd *fotg210, in start_unlink_async() argument
3240 single_unlink_async(fotg210, qh); in start_unlink_async()
3241 start_iaa_cycle(fotg210, false); in start_unlink_async()
3244 static void scan_async(struct fotg210_hcd *fotg210) in scan_async() argument
3249 fotg210->qh_scan_next = fotg210->async->qh_next.qh; in scan_async()
3250 while (fotg210->qh_scan_next) { in scan_async()
3251 qh = fotg210->qh_scan_next; in scan_async()
3252 fotg210->qh_scan_next = qh->qh_next.qh; in scan_async()
3265 temp = qh_completions(fotg210, qh); in scan_async()
3267 start_unlink_async(fotg210, qh); in scan_async()
3270 qh->unlink_cycle = fotg210->async_unlink_cycle; in scan_async()
3283 if (check_unlinks_later && fotg210->rh_state == FOTG210_RH_RUNNING && in scan_async()
3284 !(fotg210->enabled_hrtimer_events & in scan_async()
3286 fotg210_enable_event(fotg210, in scan_async()
3288 ++fotg210->async_unlink_cycle; in scan_async()
3308 static union fotg210_shadow *periodic_next_shadow(struct fotg210_hcd *fotg210, in periodic_next_shadow() argument
3311 switch (hc32_to_cpu(fotg210, tag)) { in periodic_next_shadow()
3321 static __hc32 *shadow_next_periodic(struct fotg210_hcd *fotg210, in shadow_next_periodic() argument
3324 switch (hc32_to_cpu(fotg210, tag)) { in shadow_next_periodic()
3335 static void periodic_unlink(struct fotg210_hcd *fotg210, unsigned frame, in periodic_unlink() argument
3338 union fotg210_shadow *prev_p = &fotg210->pshadow[frame]; in periodic_unlink()
3339 __hc32 *hw_p = &fotg210->periodic[frame]; in periodic_unlink()
3344 prev_p = periodic_next_shadow(fotg210, prev_p, in periodic_unlink()
3345 Q_NEXT_TYPE(fotg210, *hw_p)); in periodic_unlink()
3346 hw_p = shadow_next_periodic(fotg210, &here, in periodic_unlink()
3347 Q_NEXT_TYPE(fotg210, *hw_p)); in periodic_unlink()
3357 *prev_p = *periodic_next_shadow(fotg210, &here, in periodic_unlink()
3358 Q_NEXT_TYPE(fotg210, *hw_p)); in periodic_unlink()
3360 *hw_p = *shadow_next_periodic(fotg210, &here, in periodic_unlink()
3361 Q_NEXT_TYPE(fotg210, *hw_p)); in periodic_unlink()
3365 static unsigned short periodic_usecs(struct fotg210_hcd *fotg210, in periodic_usecs() argument
3368 __hc32 *hw_p = &fotg210->periodic[frame]; in periodic_usecs()
3369 union fotg210_shadow *q = &fotg210->pshadow[frame]; in periodic_usecs()
3374 switch (hc32_to_cpu(fotg210, Q_NEXT_TYPE(fotg210, *hw_p))) { in periodic_usecs()
3378 if (hw->hw_info2 & cpu_to_hc32(fotg210, 1 << uframe)) in periodic_usecs()
3381 if (hw->hw_info2 & cpu_to_hc32(fotg210, in periodic_usecs()
3392 if (q->fstn->hw_prev != FOTG210_LIST_END(fotg210)) in periodic_usecs()
3393 fotg210_dbg(fotg210, "ignoring FSTN cost ...\n"); in periodic_usecs()
3406 if (usecs > fotg210->uframe_periodic_max) in periodic_usecs()
3407 fotg210_err(fotg210, "uframe %d sched overrun: %d usecs\n", in periodic_usecs()
3428 static int tt_no_collision(struct fotg210_hcd *fotg210, unsigned period, in tt_no_collision() argument
3438 for (; frame < fotg210->periodic_size; frame += period) { in tt_no_collision()
3443 here = fotg210->pshadow[frame]; in tt_no_collision()
3444 type = Q_NEXT_TYPE(fotg210, fotg210->periodic[frame]); in tt_no_collision()
3446 switch (hc32_to_cpu(fotg210, type)) { in tt_no_collision()
3448 type = Q_NEXT_TYPE(fotg210, here.itd->hw_next); in tt_no_collision()
3456 mask = hc32_to_cpu(fotg210, in tt_no_collision()
3463 type = Q_NEXT_TYPE(fotg210, hw->hw_next); in tt_no_collision()
3468 fotg210_dbg(fotg210, in tt_no_collision()
3482 static void enable_periodic(struct fotg210_hcd *fotg210) in enable_periodic() argument
3484 if (fotg210->periodic_count++) in enable_periodic()
3488 fotg210->enabled_hrtimer_events &= in enable_periodic()
3492 fotg210_poll_PSS(fotg210); in enable_periodic()
3493 turn_on_io_watchdog(fotg210); in enable_periodic()
3496 static void disable_periodic(struct fotg210_hcd *fotg210) in disable_periodic() argument
3498 if (--fotg210->periodic_count) in disable_periodic()
3502 fotg210_poll_PSS(fotg210); in disable_periodic()
3511 static void qh_link_periodic(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_link_periodic() argument
3518 hc32_to_cpup(fotg210, &qh->hw->hw_info2) & in qh_link_periodic()
3526 for (i = qh->start; i < fotg210->periodic_size; i += period) { in qh_link_periodic()
3527 union fotg210_shadow *prev = &fotg210->pshadow[i]; in qh_link_periodic()
3528 __hc32 *hw_p = &fotg210->periodic[i]; in qh_link_periodic()
3534 type = Q_NEXT_TYPE(fotg210, *hw_p); in qh_link_periodic()
3535 if (type == cpu_to_hc32(fotg210, Q_TYPE_QH)) in qh_link_periodic()
3537 prev = periodic_next_shadow(fotg210, prev, type); in qh_link_periodic()
3538 hw_p = shadow_next_periodic(fotg210, &here, type); in qh_link_periodic()
3559 *hw_p = QH_NEXT(fotg210, qh->qh_dma); in qh_link_periodic()
3566 fotg210_to_hcd(fotg210)->self.bandwidth_allocated += qh->period in qh_link_periodic()
3570 list_add(&qh->intr_node, &fotg210->intr_qh_list); in qh_link_periodic()
3573 ++fotg210->intr_count; in qh_link_periodic()
3574 enable_periodic(fotg210); in qh_link_periodic()
3577 static void qh_unlink_periodic(struct fotg210_hcd *fotg210, in qh_unlink_periodic() argument
3603 for (i = qh->start; i < fotg210->periodic_size; i += period) in qh_unlink_periodic()
3604 periodic_unlink(fotg210, i, qh); in qh_unlink_periodic()
3607 fotg210_to_hcd(fotg210)->self.bandwidth_allocated -= qh->period in qh_unlink_periodic()
3613 qh->period, hc32_to_cpup(fotg210, &qh->hw->hw_info2) & in qh_unlink_periodic()
3621 if (fotg210->qh_scan_next == qh) in qh_unlink_periodic()
3622 fotg210->qh_scan_next = list_entry(qh->intr_node.next, in qh_unlink_periodic()
3627 static void start_unlink_intr(struct fotg210_hcd *fotg210, in start_unlink_intr() argument
3640 qh_unlink_periodic(fotg210, qh); in start_unlink_intr()
3650 qh->unlink_cycle = fotg210->intr_unlink_cycle; in start_unlink_intr()
3653 if (fotg210->intr_unlink) in start_unlink_intr()
3654 fotg210->intr_unlink_last->unlink_next = qh; in start_unlink_intr()
3656 fotg210->intr_unlink = qh; in start_unlink_intr()
3657 fotg210->intr_unlink_last = qh; in start_unlink_intr()
3659 if (fotg210->intr_unlinking) in start_unlink_intr()
3661 else if (fotg210->rh_state < FOTG210_RH_RUNNING) in start_unlink_intr()
3662 fotg210_handle_intr_unlinks(fotg210); in start_unlink_intr()
3663 else if (fotg210->intr_unlink == qh) { in start_unlink_intr()
3664 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR, in start_unlink_intr()
3666 ++fotg210->intr_unlink_cycle; in start_unlink_intr()
3670 static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in end_unlink_intr() argument
3676 hw->hw_next = FOTG210_LIST_END(fotg210); in end_unlink_intr()
3678 qh_completions(fotg210, qh); in end_unlink_intr()
3682 fotg210->rh_state == FOTG210_RH_RUNNING) { in end_unlink_intr()
3683 rc = qh_schedule(fotg210, qh); in end_unlink_intr()
3692 fotg210_err(fotg210, "can't reschedule qh %p, err %d\n", in end_unlink_intr()
3697 --fotg210->intr_count; in end_unlink_intr()
3698 disable_periodic(fotg210); in end_unlink_intr()
3701 static int check_period(struct fotg210_hcd *fotg210, unsigned frame, in check_period() argument
3713 usecs = fotg210->uframe_periodic_max - usecs; in check_period()
3721 claimed = periodic_usecs(fotg210, frame, in check_period()
3726 } while ((frame += 1) < fotg210->periodic_size); in check_period()
3731 claimed = periodic_usecs(fotg210, frame, uframe); in check_period()
3734 } while ((frame += period) < fotg210->periodic_size); in check_period()
3741 static int check_intr_schedule(struct fotg210_hcd *fotg210, unsigned frame, in check_intr_schedule() argument
3750 if (!check_period(fotg210, frame, uframe, qh->period, qh->usecs)) in check_intr_schedule()
3766 *c_maskp = cpu_to_hc32(fotg210, mask << 8); in check_intr_schedule()
3769 if (tt_no_collision(fotg210, qh->period, qh->dev, frame, mask)) { in check_intr_schedule()
3770 if (!check_period(fotg210, frame, uframe + qh->gap_uf + 1, in check_intr_schedule()
3773 if (!check_period(fotg210, frame, uframe + qh->gap_uf, in check_intr_schedule()
3785 static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_schedule() argument
3793 qh_refresh(fotg210, qh); in qh_schedule()
3794 hw->hw_next = FOTG210_LIST_END(fotg210); in qh_schedule()
3799 uframe = ffs(hc32_to_cpup(fotg210, &hw->hw_info2) & QH_SMASK); in qh_schedule()
3800 status = check_intr_schedule(fotg210, frame, --uframe, in qh_schedule()
3817 frame = ++fotg210->random_frame % qh->period; in qh_schedule()
3819 status = check_intr_schedule(fotg210, in qh_schedule()
3830 status = check_intr_schedule(fotg210, 0, 0, qh, in qh_schedule()
3838 hw->hw_info2 &= cpu_to_hc32(fotg210, ~(QH_CMASK | QH_SMASK)); in qh_schedule()
3840 ? cpu_to_hc32(fotg210, 1 << uframe) in qh_schedule()
3841 : cpu_to_hc32(fotg210, QH_SMASK); in qh_schedule()
3844 fotg210_dbg(fotg210, "reused qh %p schedule\n", qh); in qh_schedule()
3847 qh_link_periodic(fotg210, qh); in qh_schedule()
3852 static int intr_submit(struct fotg210_hcd *fotg210, struct urb *urb, in intr_submit() argument
3864 spin_lock_irqsave(&fotg210->lock, flags); in intr_submit()
3866 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) { in intr_submit()
3870 status = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb); in intr_submit()
3876 qh = qh_append_tds(fotg210, urb, &empty, epnum, &urb->ep->hcpriv); in intr_submit()
3882 status = qh_schedule(fotg210, qh); in intr_submit()
3888 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv); in intr_submit()
3892 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs++; in intr_submit()
3896 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb); in intr_submit()
3898 spin_unlock_irqrestore(&fotg210->lock, flags); in intr_submit()
3900 qtd_list_free(fotg210, urb, qtd_list); in intr_submit()
3905 static void scan_intr(struct fotg210_hcd *fotg210) in scan_intr() argument
3909 list_for_each_entry_safe(qh, fotg210->qh_scan_next, in scan_intr()
3910 &fotg210->intr_qh_list, intr_node) { in scan_intr()
3923 temp = qh_completions(fotg210, qh); in scan_intr()
3927 start_unlink_intr(fotg210, qh); in scan_intr()
3949 static void iso_stream_init(struct fotg210_hcd *fotg210, in iso_stream_init() argument
3976 stream->buf0 = cpu_to_hc32(fotg210, (epnum << 8) | dev->devnum); in iso_stream_init()
3977 stream->buf1 = cpu_to_hc32(fotg210, buf1); in iso_stream_init()
3978 stream->buf2 = cpu_to_hc32(fotg210, multi); in iso_stream_init()
4002 static struct fotg210_iso_stream *iso_stream_find(struct fotg210_hcd *fotg210, in iso_stream_find() argument
4016 spin_lock_irqsave(&fotg210->lock, flags); in iso_stream_find()
4024 iso_stream_init(fotg210, stream, urb->dev, urb->pipe, in iso_stream_find()
4030 fotg210_dbg(fotg210, "dev %s ep%d%s, not iso??\n", in iso_stream_find()
4036 spin_unlock_irqrestore(&fotg210->lock, flags); in iso_stream_find()
4056 static inline void itd_sched_init(struct fotg210_hcd *fotg210, in itd_sched_init() argument
4084 uframe->transaction = cpu_to_hc32(fotg210, trans); in itd_sched_init()
4105 struct fotg210_hcd *fotg210, struct urb *urb, gfp_t mem_flags) in itd_urb_transaction() argument
4118 itd_sched_init(fotg210, sched, stream, urb); in itd_urb_transaction()
4126 spin_lock_irqsave(&fotg210->lock, flags); in itd_urb_transaction()
4136 if (itd->frame == fotg210->now_frame) in itd_urb_transaction()
4142 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_urb_transaction()
4143 itd = dma_pool_alloc(fotg210->itd_pool, mem_flags, in itd_urb_transaction()
4145 spin_lock_irqsave(&fotg210->lock, flags); in itd_urb_transaction()
4148 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_urb_transaction()
4157 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_urb_transaction()
4165 static inline int itd_slot_ok(struct fotg210_hcd *fotg210, u32 mod, u32 uframe, in itd_slot_ok() argument
4171 if (periodic_usecs(fotg210, uframe >> 3, uframe & 0x7) in itd_slot_ok()
4172 > (fotg210->uframe_periodic_max - usecs)) in itd_slot_ok()
4193 static int iso_stream_schedule(struct fotg210_hcd *fotg210, struct urb *urb, in iso_stream_schedule() argument
4198 unsigned mod = fotg210->periodic_size << 3; in iso_stream_schedule()
4205 fotg210_dbg(fotg210, "iso request %p too long\n", urb); in iso_stream_schedule()
4210 now = fotg210_read_frame_index(fotg210) & (mod - 1); in iso_stream_schedule()
4225 if (!stream->highspeed && fotg210->fs_i_thresh) in iso_stream_schedule()
4226 next = now + fotg210->i_thresh; in iso_stream_schedule()
4241 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n", in iso_stream_schedule()
4272 if (itd_slot_ok(fotg210, mod, start, in iso_stream_schedule()
4279 fotg210_dbg(fotg210, "iso resched full %p (now %d max %d)\n", in iso_stream_schedule()
4289 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n", in iso_stream_schedule()
4304 if (fotg210->isoc_count == 0) in iso_stream_schedule()
4305 fotg210->next_frame = now >> 3; in iso_stream_schedule()
4314 static inline void itd_init(struct fotg210_hcd *fotg210, in itd_init() argument
4320 itd->hw_next = FOTG210_LIST_END(fotg210); in itd_init()
4331 static inline void itd_patch(struct fotg210_hcd *fotg210, in itd_patch() argument
4342 itd->hw_transaction[uframe] |= cpu_to_hc32(fotg210, pg << 12); in itd_patch()
4343 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, uf->bufp & ~(u32)0); in itd_patch()
4344 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(uf->bufp >> 32)); in itd_patch()
4351 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, bufp & ~(u32)0); in itd_patch()
4352 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(bufp >> 32)); in itd_patch()
4356 static inline void itd_link(struct fotg210_hcd *fotg210, unsigned frame, in itd_link() argument
4359 union fotg210_shadow *prev = &fotg210->pshadow[frame]; in itd_link()
4360 __hc32 *hw_p = &fotg210->periodic[frame]; in itd_link()
4366 type = Q_NEXT_TYPE(fotg210, *hw_p); in itd_link()
4367 if (type == cpu_to_hc32(fotg210, Q_TYPE_QH)) in itd_link()
4369 prev = periodic_next_shadow(fotg210, prev, type); in itd_link()
4370 hw_p = shadow_next_periodic(fotg210, &here, type); in itd_link()
4379 *hw_p = cpu_to_hc32(fotg210, itd->itd_dma | Q_TYPE_ITD); in itd_link()
4383 static void itd_link_urb(struct fotg210_hcd *fotg210, struct urb *urb, in itd_link_urb() argument
4394 fotg210_to_hcd(fotg210)->self.bandwidth_allocated in itd_link_urb()
4396 fotg210_dbg(fotg210, in itd_link_urb()
4416 itd_init(fotg210, stream, itd); in itd_link_urb()
4422 itd_patch(fotg210, itd, iso_sched, packet, uframe); in itd_link_urb()
4431 itd_link(fotg210, frame & (fotg210->periodic_size - 1), in itd_link_urb()
4442 ++fotg210->isoc_count; in itd_link_urb()
4443 enable_periodic(fotg210); in itd_link_urb()
4459 static bool itd_complete(struct fotg210_hcd *fotg210, struct fotg210_itd *itd) in itd_complete() argument
4477 t = hc32_to_cpup(fotg210, &itd->hw_transaction[uframe]); in itd_complete()
4519 fotg210_urb_done(fotg210, urb, 0); in itd_complete()
4523 --fotg210->isoc_count; in itd_complete()
4524 disable_periodic(fotg210); in itd_complete()
4527 fotg210_to_hcd(fotg210)->self.bandwidth_allocated in itd_complete()
4529 fotg210_dbg(fotg210, in itd_complete()
4544 &fotg210->cached_itd_list); in itd_complete()
4545 start_free_itds(fotg210); in itd_complete()
4551 static int itd_submit(struct fotg210_hcd *fotg210, struct urb *urb, in itd_submit() argument
4559 stream = iso_stream_find(fotg210, urb); in itd_submit()
4561 fotg210_dbg(fotg210, "can't get iso stream\n"); in itd_submit()
4565 fotg210_port_speed(fotg210, 0) == in itd_submit()
4567 fotg210_dbg(fotg210, "can't change iso interval %d --> %d\n", in itd_submit()
4573 fotg210_dbg(fotg210, in itd_submit()
4584 status = itd_urb_transaction(stream, fotg210, urb, mem_flags); in itd_submit()
4586 fotg210_dbg(fotg210, "can't init itds\n"); in itd_submit()
4591 spin_lock_irqsave(&fotg210->lock, flags); in itd_submit()
4592 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) { in itd_submit()
4596 status = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb); in itd_submit()
4599 status = iso_stream_schedule(fotg210, urb, stream); in itd_submit()
4601 itd_link_urb(fotg210, urb, fotg210->periodic_size << 3, stream); in itd_submit()
4603 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb); in itd_submit()
4605 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_submit()
4610 static inline int scan_frame_queue(struct fotg210_hcd *fotg210, unsigned frame, in scan_frame_queue() argument
4619 q_p = &fotg210->pshadow[frame]; in scan_frame_queue()
4620 hw_p = &fotg210->periodic[frame]; in scan_frame_queue()
4622 type = Q_NEXT_TYPE(fotg210, *hw_p); in scan_frame_queue()
4626 switch (hc32_to_cpu(fotg210, type)) { in scan_frame_queue()
4637 ITD_ACTIVE(fotg210)) in scan_frame_queue()
4643 type = Q_NEXT_TYPE(fotg210, in scan_frame_queue()
4657 type = Q_NEXT_TYPE(fotg210, q.itd->hw_next); in scan_frame_queue()
4659 modified = itd_complete(fotg210, q.itd); in scan_frame_queue()
4663 fotg210_dbg(fotg210, "corrupt type %d frame %d shadow %p\n", in scan_frame_queue()
4674 if (unlikely(modified && fotg210->isoc_count > 0)) in scan_frame_queue()
4680 static void scan_isoc(struct fotg210_hcd *fotg210) in scan_isoc() argument
4683 unsigned fmask = fotg210->periodic_size - 1; in scan_isoc()
4691 if (fotg210->rh_state >= FOTG210_RH_RUNNING) { in scan_isoc()
4692 uf = fotg210_read_frame_index(fotg210); in scan_isoc()
4696 now_frame = (fotg210->next_frame - 1) & fmask; in scan_isoc()
4699 fotg210->now_frame = now_frame; in scan_isoc()
4701 frame = fotg210->next_frame; in scan_isoc()
4705 ret = scan_frame_queue(fotg210, frame, in scan_isoc()
4713 fotg210->next_frame = now_frame; in scan_isoc()
4721 struct fotg210_hcd *fotg210; in show_uframe_periodic_max() local
4724 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev))); in show_uframe_periodic_max()
4725 n = scnprintf(buf, PAGE_SIZE, "%d\n", fotg210->uframe_periodic_max); in show_uframe_periodic_max()
4733 struct fotg210_hcd *fotg210; in store_uframe_periodic_max() local
4740 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev))); in store_uframe_periodic_max()
4745 fotg210_info(fotg210, "rejecting invalid request for uframe_periodic_max=%u\n", in store_uframe_periodic_max()
4756 spin_lock_irqsave(&fotg210->lock, flags); in store_uframe_periodic_max()
4763 if (uframe_periodic_max < fotg210->uframe_periodic_max) { in store_uframe_periodic_max()
4766 for (frame = 0; frame < fotg210->periodic_size; ++frame) in store_uframe_periodic_max()
4769 periodic_usecs(fotg210, frame, in store_uframe_periodic_max()
4773 fotg210_info(fotg210, in store_uframe_periodic_max()
4782 fotg210_info(fotg210, in store_uframe_periodic_max()
4787 fotg210_warn(fotg210, "max periodic bandwidth set is non-standard\n"); in store_uframe_periodic_max()
4789 fotg210->uframe_periodic_max = uframe_periodic_max; in store_uframe_periodic_max()
4793 spin_unlock_irqrestore(&fotg210->lock, flags); in store_uframe_periodic_max()
4800 static inline int create_sysfs_files(struct fotg210_hcd *fotg210) in create_sysfs_files() argument
4802 struct device *controller = fotg210_to_hcd(fotg210)->self.controller; in create_sysfs_files()
4813 static inline void remove_sysfs_files(struct fotg210_hcd *fotg210) in remove_sysfs_files() argument
4815 struct device *controller = fotg210_to_hcd(fotg210)->self.controller; in remove_sysfs_files()
4823 static void fotg210_turn_off_all_ports(struct fotg210_hcd *fotg210) in fotg210_turn_off_all_ports() argument
4825 u32 __iomem *status_reg = &fotg210->regs->port_status; in fotg210_turn_off_all_ports()
4827 fotg210_writel(fotg210, PORT_RWC_BITS, status_reg); in fotg210_turn_off_all_ports()
4833 static void fotg210_silence_controller(struct fotg210_hcd *fotg210) in fotg210_silence_controller() argument
4835 fotg210_halt(fotg210); in fotg210_silence_controller()
4837 spin_lock_irq(&fotg210->lock); in fotg210_silence_controller()
4838 fotg210->rh_state = FOTG210_RH_HALTED; in fotg210_silence_controller()
4839 fotg210_turn_off_all_ports(fotg210); in fotg210_silence_controller()
4840 spin_unlock_irq(&fotg210->lock); in fotg210_silence_controller()
4849 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_shutdown() local
4851 spin_lock_irq(&fotg210->lock); in fotg210_shutdown()
4852 fotg210->shutdown = true; in fotg210_shutdown()
4853 fotg210->rh_state = FOTG210_RH_STOPPING; in fotg210_shutdown()
4854 fotg210->enabled_hrtimer_events = 0; in fotg210_shutdown()
4855 spin_unlock_irq(&fotg210->lock); in fotg210_shutdown()
4857 fotg210_silence_controller(fotg210); in fotg210_shutdown()
4859 hrtimer_cancel(&fotg210->hrtimer); in fotg210_shutdown()
4865 static void fotg210_work(struct fotg210_hcd *fotg210) in fotg210_work() argument
4871 if (fotg210->scanning) { in fotg210_work()
4872 fotg210->need_rescan = true; in fotg210_work()
4875 fotg210->scanning = true; in fotg210_work()
4878 fotg210->need_rescan = false; in fotg210_work()
4879 if (fotg210->async_count) in fotg210_work()
4880 scan_async(fotg210); in fotg210_work()
4881 if (fotg210->intr_count > 0) in fotg210_work()
4882 scan_intr(fotg210); in fotg210_work()
4883 if (fotg210->isoc_count > 0) in fotg210_work()
4884 scan_isoc(fotg210); in fotg210_work()
4885 if (fotg210->need_rescan) in fotg210_work()
4887 fotg210->scanning = false; in fotg210_work()
4893 turn_on_io_watchdog(fotg210); in fotg210_work()
4900 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_stop() local
4902 fotg210_dbg(fotg210, "stop\n"); in fotg210_stop()
4906 spin_lock_irq(&fotg210->lock); in fotg210_stop()
4907 fotg210->enabled_hrtimer_events = 0; in fotg210_stop()
4908 spin_unlock_irq(&fotg210->lock); in fotg210_stop()
4910 fotg210_quiesce(fotg210); in fotg210_stop()
4911 fotg210_silence_controller(fotg210); in fotg210_stop()
4912 fotg210_reset(fotg210); in fotg210_stop()
4914 hrtimer_cancel(&fotg210->hrtimer); in fotg210_stop()
4915 remove_sysfs_files(fotg210); in fotg210_stop()
4916 remove_debug_files(fotg210); in fotg210_stop()
4919 spin_lock_irq(&fotg210->lock); in fotg210_stop()
4920 end_free_itds(fotg210); in fotg210_stop()
4921 spin_unlock_irq(&fotg210->lock); in fotg210_stop()
4922 fotg210_mem_cleanup(fotg210); in fotg210_stop()
4925 fotg210_dbg(fotg210, "irq normal %ld err %ld iaa %ld (lost %ld)\n", in fotg210_stop()
4926 fotg210->stats.normal, fotg210->stats.error, in fotg210_stop()
4927 fotg210->stats.iaa, fotg210->stats.lost_iaa); in fotg210_stop()
4928 fotg210_dbg(fotg210, "complete %ld unlink %ld\n", in fotg210_stop()
4929 fotg210->stats.complete, fotg210->stats.unlink); in fotg210_stop()
4932 dbg_status(fotg210, "fotg210_stop completed", in fotg210_stop()
4933 fotg210_readl(fotg210, &fotg210->regs->status)); in fotg210_stop()
4939 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in hcd_fotg210_init() local
4945 spin_lock_init(&fotg210->lock); in hcd_fotg210_init()
4950 fotg210->need_io_watchdog = 1; in hcd_fotg210_init()
4952 hrtimer_init(&fotg210->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); in hcd_fotg210_init()
4953 fotg210->hrtimer.function = fotg210_hrtimer_func; in hcd_fotg210_init()
4954 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT; in hcd_fotg210_init()
4956 hcc_params = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in hcd_fotg210_init()
4962 fotg210->uframe_periodic_max = 100; in hcd_fotg210_init()
4968 fotg210->periodic_size = DEFAULT_I_TDPS; in hcd_fotg210_init()
4969 INIT_LIST_HEAD(&fotg210->intr_qh_list); in hcd_fotg210_init()
4970 INIT_LIST_HEAD(&fotg210->cached_itd_list); in hcd_fotg210_init()
4976 fotg210->periodic_size = 1024; in hcd_fotg210_init()
4979 fotg210->periodic_size = 512; in hcd_fotg210_init()
4982 fotg210->periodic_size = 256; in hcd_fotg210_init()
4988 retval = fotg210_mem_init(fotg210, GFP_KERNEL); in hcd_fotg210_init()
4993 fotg210->i_thresh = 2; in hcd_fotg210_init()
5002 fotg210->async->qh_next.qh = NULL; in hcd_fotg210_init()
5003 hw = fotg210->async->hw; in hcd_fotg210_init()
5004 hw->hw_next = QH_NEXT(fotg210, fotg210->async->qh_dma); in hcd_fotg210_init()
5005 hw->hw_info1 = cpu_to_hc32(fotg210, QH_HEAD); in hcd_fotg210_init()
5006 hw->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT); in hcd_fotg210_init()
5007 hw->hw_qtd_next = FOTG210_LIST_END(fotg210); in hcd_fotg210_init()
5008 fotg210->async->qh_state = QH_STATE_LINKED; in hcd_fotg210_init()
5009 hw->hw_alt_next = QTD_NEXT(fotg210, fotg210->async->dummy->qtd_dma); in hcd_fotg210_init()
5028 fotg210_dbg(fotg210, "park %d\n", park); in hcd_fotg210_init()
5035 fotg210->command = temp; in hcd_fotg210_init()
5046 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_run() local
5054 fotg210_writel(fotg210, fotg210->periodic_dma, in fotg210_run()
5055 &fotg210->regs->frame_list); in fotg210_run()
5056 fotg210_writel(fotg210, (u32)fotg210->async->qh_dma, in fotg210_run()
5057 &fotg210->regs->async_next); in fotg210_run()
5071 hcc_params = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in fotg210_run()
5077 fotg210->command &= ~(CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); in fotg210_run()
5078 fotg210->command |= CMD_RUN; in fotg210_run()
5079 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_run()
5080 dbg_cmd(fotg210, "init", fotg210->command); in fotg210_run()
5097 fotg210->rh_state = FOTG210_RH_RUNNING; in fotg210_run()
5099 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_run()
5102 fotg210->last_periodic_enable = ktime_get_real(); in fotg210_run()
5104 temp = HC_VERSION(fotg210, in fotg210_run()
5105 fotg210_readl(fotg210, &fotg210->caps->hc_capbase)); in fotg210_run()
5106 fotg210_info(fotg210, in fotg210_run()
5108 ((fotg210->sbrn & 0xf0) >> 4), (fotg210->sbrn & 0x0f), in fotg210_run()
5111 fotg210_writel(fotg210, INTR_MASK, in fotg210_run()
5112 &fotg210->regs->intr_enable); /* Turn On Interrupts */ in fotg210_run()
5118 create_debug_files(fotg210); in fotg210_run()
5119 create_sysfs_files(fotg210); in fotg210_run()
5126 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_setup() local
5129 fotg210->regs = (void __iomem *)fotg210->caps + in fotg210_setup()
5130 HC_LENGTH(fotg210, in fotg210_setup()
5131 fotg210_readl(fotg210, &fotg210->caps->hc_capbase)); in fotg210_setup()
5132 dbg_hcs_params(fotg210, "reset"); in fotg210_setup()
5133 dbg_hcc_params(fotg210, "reset"); in fotg210_setup()
5136 fotg210->hcs_params = fotg210_readl(fotg210, in fotg210_setup()
5137 &fotg210->caps->hcs_params); in fotg210_setup()
5139 fotg210->sbrn = HCD_USB2; in fotg210_setup()
5146 retval = fotg210_halt(fotg210); in fotg210_setup()
5150 fotg210_reset(fotg210); in fotg210_setup()
5157 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_irq() local
5161 spin_lock(&fotg210->lock); in fotg210_irq()
5163 status = fotg210_readl(fotg210, &fotg210->regs->status); in fotg210_irq()
5167 fotg210_dbg(fotg210, "device removed\n"); in fotg210_irq()
5179 unlikely(fotg210->rh_state == FOTG210_RH_HALTED)) { in fotg210_irq()
5180 spin_unlock(&fotg210->lock); in fotg210_irq()
5185 fotg210_writel(fotg210, masked_status, &fotg210->regs->status); in fotg210_irq()
5186 cmd = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_irq()
5190 dbg_status(fotg210, "irq", status); in fotg210_irq()
5197 COUNT(fotg210->stats.normal); in fotg210_irq()
5199 COUNT(fotg210->stats.error); in fotg210_irq()
5207 fotg210->enabled_hrtimer_events &= in fotg210_irq()
5217 if (fotg210->next_hrtimer_event == FOTG210_HRTIMER_IAA_WATCHDOG) in fotg210_irq()
5218 ++fotg210->next_hrtimer_event; in fotg210_irq()
5222 fotg210_dbg(fotg210, "IAA with IAAD still set?\n"); in fotg210_irq()
5223 if (fotg210->async_iaa) { in fotg210_irq()
5224 COUNT(fotg210->stats.iaa); in fotg210_irq()
5225 end_unlink_async(fotg210); in fotg210_irq()
5227 fotg210_dbg(fotg210, "IAA with nothing unlinked?\n"); in fotg210_irq()
5233 u32 __iomem *status_reg = &fotg210->regs->port_status; in fotg210_irq()
5239 if (fotg210->rh_state == FOTG210_RH_SUSPENDED) in fotg210_irq()
5242 pstatus = fotg210_readl(fotg210, status_reg); in fotg210_irq()
5244 if (test_bit(0, &fotg210->suspended_ports) && in fotg210_irq()
5248 fotg210->reset_done[0] == 0) { in fotg210_irq()
5255 fotg210->reset_done[0] = jiffies + msecs_to_jiffies(25); in fotg210_irq()
5256 set_bit(0, &fotg210->resuming_ports); in fotg210_irq()
5257 fotg210_dbg(fotg210, "port 1 remote wakeup\n"); in fotg210_irq()
5258 mod_timer(&hcd->rh_timer, fotg210->reset_done[0]); in fotg210_irq()
5264 fotg210_err(fotg210, "fatal error\n"); in fotg210_irq()
5265 dbg_cmd(fotg210, "fatal", cmd); in fotg210_irq()
5266 dbg_status(fotg210, "fatal", status); in fotg210_irq()
5271 fotg210->shutdown = true; in fotg210_irq()
5272 fotg210->rh_state = FOTG210_RH_STOPPING; in fotg210_irq()
5273 fotg210->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE); in fotg210_irq()
5274 fotg210_writel(fotg210, fotg210->command, in fotg210_irq()
5275 &fotg210->regs->command); in fotg210_irq()
5276 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable); in fotg210_irq()
5277 fotg210_handle_controller_death(fotg210); in fotg210_irq()
5284 fotg210_work(fotg210); in fotg210_irq()
5285 spin_unlock(&fotg210->lock); in fotg210_irq()
5305 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_urb_enqueue() local
5320 if (!qh_urb_transaction(fotg210, urb, &qtd_list, mem_flags)) in fotg210_urb_enqueue()
5322 return submit_async(fotg210, urb, &qtd_list, mem_flags); in fotg210_urb_enqueue()
5325 if (!qh_urb_transaction(fotg210, urb, &qtd_list, mem_flags)) in fotg210_urb_enqueue()
5327 return intr_submit(fotg210, urb, &qtd_list, mem_flags); in fotg210_urb_enqueue()
5330 return itd_submit(fotg210, urb, mem_flags); in fotg210_urb_enqueue()
5340 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_urb_dequeue() local
5345 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_urb_dequeue()
5360 start_unlink_async(fotg210, qh); in fotg210_urb_dequeue()
5368 qh_completions(fotg210, qh); in fotg210_urb_dequeue()
5380 start_unlink_intr(fotg210, qh); in fotg210_urb_dequeue()
5383 qh_completions(fotg210, qh); in fotg210_urb_dequeue()
5386 fotg210_dbg(fotg210, "bogus qh %p state %d\n", in fotg210_urb_dequeue()
5400 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_urb_dequeue()
5409 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_endpoint_disable() local
5417 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_endpoint_disable()
5436 if (fotg210->rh_state < FOTG210_RH_RUNNING) in fotg210_endpoint_disable()
5441 for (tmp = fotg210->async->qh_next.qh; in fotg210_endpoint_disable()
5449 start_unlink_async(fotg210, qh); in fotg210_endpoint_disable()
5454 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_endpoint_disable()
5461 qh_destroy(fotg210, qh); in fotg210_endpoint_disable()
5469 fotg210_err(fotg210, "qh %p (#%02x) state %d%s\n", in fotg210_endpoint_disable()
5476 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_endpoint_disable()
5482 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_endpoint_reset() local
5492 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_endpoint_reset()
5512 start_unlink_async(fotg210, qh); in fotg210_endpoint_reset()
5514 start_unlink_intr(fotg210, qh); in fotg210_endpoint_reset()
5517 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_endpoint_reset()
5522 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_get_frame() local
5524 return (fotg210_read_frame_index(fotg210) >> 3) % in fotg210_get_frame()
5525 fotg210->periodic_size; in fotg210_get_frame()
5583 static void fotg210_init(struct fotg210_hcd *fotg210) in fotg210_init() argument
5588 &fotg210->regs->gmir); in fotg210_init()
5590 value = ioread32(&fotg210->regs->otgcsr); in fotg210_init()
5593 iowrite32(value, &fotg210->regs->otgcsr); in fotg210_init()
5610 struct fotg210_hcd *fotg210; in fotg210_hcd_probe() local
5646 fotg210 = hcd_to_fotg210(hcd); in fotg210_hcd_probe()
5648 fotg210->caps = hcd->regs; in fotg210_hcd_probe()
5654 fotg210_init(fotg210); in fotg210_hcd_probe()