Lines Matching refs:fotg210
79 #define fotg210_dbg(fotg210, fmt, args...) \ argument
80 dev_dbg(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
81 #define fotg210_err(fotg210, fmt, args...) \ argument
82 dev_err(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
83 #define fotg210_info(fotg210, fmt, args...) \ argument
84 dev_info(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
85 #define fotg210_warn(fotg210, fmt, args...) \ argument
86 dev_warn(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
91 static void dbg_hcs_params(struct fotg210_hcd *fotg210, char *label) in dbg_hcs_params() argument
93 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcs_params); in dbg_hcs_params()
95 fotg210_dbg(fotg210, "%s hcs_params 0x%x ports=%d\n", label, params, in dbg_hcs_params()
102 static void dbg_hcc_params(struct fotg210_hcd *fotg210, char *label) in dbg_hcc_params() argument
104 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in dbg_hcc_params()
106 fotg210_dbg(fotg210, "%s hcc_params %04x uframes %s%s\n", label, in dbg_hcc_params()
113 dbg_qtd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd) in dbg_qtd() argument
115 fotg210_dbg(fotg210, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd, in dbg_qtd()
116 hc32_to_cpup(fotg210, &qtd->hw_next), in dbg_qtd()
117 hc32_to_cpup(fotg210, &qtd->hw_alt_next), in dbg_qtd()
118 hc32_to_cpup(fotg210, &qtd->hw_token), in dbg_qtd()
119 hc32_to_cpup(fotg210, &qtd->hw_buf[0])); in dbg_qtd()
121 fotg210_dbg(fotg210, " p1=%08x p2=%08x p3=%08x p4=%08x\n", in dbg_qtd()
122 hc32_to_cpup(fotg210, &qtd->hw_buf[1]), in dbg_qtd()
123 hc32_to_cpup(fotg210, &qtd->hw_buf[2]), in dbg_qtd()
124 hc32_to_cpup(fotg210, &qtd->hw_buf[3]), in dbg_qtd()
125 hc32_to_cpup(fotg210, &qtd->hw_buf[4])); in dbg_qtd()
129 dbg_qh(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in dbg_qh() argument
133 fotg210_dbg(fotg210, "%s qh %p n%08x info %x %x qtd %x\n", label, qh, in dbg_qh()
137 dbg_qtd("overlay", fotg210, (struct fotg210_qtd *) &hw->hw_qtd_next); in dbg_qh()
141 dbg_itd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_itd *itd) in dbg_itd() argument
143 fotg210_dbg(fotg210, "%s[%d] itd %p, next %08x, urb %p\n", label, in dbg_itd()
144 itd->frame, itd, hc32_to_cpu(fotg210, itd->hw_next), in dbg_itd()
147 fotg210_dbg(fotg210, in dbg_itd()
149 hc32_to_cpu(fotg210, itd->hw_transaction[0]), in dbg_itd()
150 hc32_to_cpu(fotg210, itd->hw_transaction[1]), in dbg_itd()
151 hc32_to_cpu(fotg210, itd->hw_transaction[2]), in dbg_itd()
152 hc32_to_cpu(fotg210, itd->hw_transaction[3]), in dbg_itd()
153 hc32_to_cpu(fotg210, itd->hw_transaction[4]), in dbg_itd()
154 hc32_to_cpu(fotg210, itd->hw_transaction[5]), in dbg_itd()
155 hc32_to_cpu(fotg210, itd->hw_transaction[6]), in dbg_itd()
156 hc32_to_cpu(fotg210, itd->hw_transaction[7])); in dbg_itd()
158 fotg210_dbg(fotg210, in dbg_itd()
160 hc32_to_cpu(fotg210, itd->hw_bufp[0]), in dbg_itd()
161 hc32_to_cpu(fotg210, itd->hw_bufp[1]), in dbg_itd()
162 hc32_to_cpu(fotg210, itd->hw_bufp[2]), in dbg_itd()
163 hc32_to_cpu(fotg210, itd->hw_bufp[3]), in dbg_itd()
164 hc32_to_cpu(fotg210, itd->hw_bufp[4]), in dbg_itd()
165 hc32_to_cpu(fotg210, itd->hw_bufp[5]), in dbg_itd()
166 hc32_to_cpu(fotg210, itd->hw_bufp[6])); in dbg_itd()
168 fotg210_dbg(fotg210, " index: %d %d %d %d %d %d %d %d\n", in dbg_itd()
260 #define dbg_status(fotg210, label, status) { \ argument
263 fotg210_dbg(fotg210, "%s\n", _buf); \
266 #define dbg_cmd(fotg210, label, command) { \ argument
269 fotg210_dbg(fotg210, "%s\n", _buf); \
272 #define dbg_port(fotg210, label, port, status) { \ argument
274 fotg210_dbg(fotg210, "%s\n", \
337 static inline char token_mark(struct fotg210_hcd *fotg210, __hc32 token) in token_mark() argument
339 __u32 v = hc32_to_cpu(fotg210, token); in token_mark()
351 static void qh_lines(struct fotg210_hcd *fotg210, struct fotg210_qh *qh, in qh_lines() argument
361 __le32 list_end = FOTG210_LIST_END(fotg210); in qh_lines()
367 mark = token_mark(fotg210, hw->hw_token); in qh_lines()
369 if ((hw->hw_alt_next & QTD_MASK(fotg210)) == in qh_lines()
370 fotg210->async->hw->hw_alt_next) in qh_lines()
376 scratch = hc32_to_cpup(fotg210, &hw->hw_info1); in qh_lines()
377 hw_curr = (mark == '*') ? hc32_to_cpup(fotg210, &hw->hw_current) : 0; in qh_lines()
383 scratch, hc32_to_cpup(fotg210, &hw->hw_info2), in qh_lines()
384 hc32_to_cpup(fotg210, &hw->hw_token), mark, in qh_lines()
385 (cpu_to_hc32(fotg210, QTD_TOGGLE) & hw->hw_token) in qh_lines()
387 (hc32_to_cpup(fotg210, &hw->hw_alt_next) >> 1) & 0x0f); in qh_lines()
393 scratch = hc32_to_cpup(fotg210, &td->hw_token); in qh_lines()
397 else if (hw->hw_qtd_next == cpu_to_hc32(fotg210, td->qtd_dma)) in qh_lines()
400 if (td->hw_alt_next == fotg210->async->hw->hw_alt_next) in qh_lines()
448 struct fotg210_hcd *fotg210; in fill_async_buffer() local
455 fotg210 = hcd_to_fotg210(hcd); in fill_async_buffer()
465 spin_lock_irqsave(&fotg210->lock, flags); in fill_async_buffer()
466 for (qh = fotg210->async->qh_next.qh; size > 0 && qh; in fill_async_buffer()
468 qh_lines(fotg210, qh, &next, &size); in fill_async_buffer()
469 if (fotg210->async_unlink && size > 0) { in fill_async_buffer()
474 for (qh = fotg210->async_unlink; size > 0 && qh; in fill_async_buffer()
476 qh_lines(fotg210, qh, &next, &size); in fill_async_buffer()
478 spin_unlock_irqrestore(&fotg210->lock, flags); in fill_async_buffer()
484 static unsigned output_buf_tds_dir(char *buf, struct fotg210_hcd *fotg210, in output_buf_tds_dir() argument
487 u32 scratch = hc32_to_cpup(fotg210, &hw->hw_info1); in output_buf_tds_dir()
495 switch ((hc32_to_cpu(fotg210, qtd->hw_token) >> 8) & 0x03) { in output_buf_tds_dir()
515 struct fotg210_hcd *fotg210; in fill_periodic_buffer() local
530 fotg210 = hcd_to_fotg210(hcd); in fill_periodic_buffer()
534 temp = scnprintf(next, size, "size = %d\n", fotg210->periodic_size); in fill_periodic_buffer()
541 spin_lock_irqsave(&fotg210->lock, flags); in fill_periodic_buffer()
542 for (i = 0; i < fotg210->periodic_size; i++) { in fill_periodic_buffer()
543 p = fotg210->pshadow[i]; in fill_periodic_buffer()
547 tag = Q_NEXT_TYPE(fotg210, fotg210->periodic[i]); in fill_periodic_buffer()
556 switch (hc32_to_cpu(fotg210, tag)) { in fill_periodic_buffer()
561 hc32_to_cpup(fotg210, in fill_periodic_buffer()
583 fotg210, hw, in fill_periodic_buffer()
590 tag = Q_NEXT_TYPE(fotg210, hw->hw_next); in fill_periodic_buffer()
597 tag = Q_NEXT_TYPE(fotg210, p.fstn->hw_next); in fill_periodic_buffer()
603 tag = Q_NEXT_TYPE(fotg210, p.itd->hw_next); in fill_periodic_buffer()
615 spin_unlock_irqrestore(&fotg210->lock, flags); in fill_periodic_buffer()
622 static const char *rh_state_string(struct fotg210_hcd *fotg210) in rh_state_string() argument
624 switch (fotg210->rh_state) { in rh_state_string()
640 struct fotg210_hcd *fotg210; in fill_registers_buffer() local
648 fotg210 = hcd_to_fotg210(hcd); in fill_registers_buffer()
652 spin_lock_irqsave(&fotg210->lock, flags); in fill_registers_buffer()
666 i = HC_VERSION(fotg210, fotg210_readl(fotg210, in fill_registers_buffer()
667 &fotg210->caps->hc_capbase)); in fill_registers_buffer()
675 i >> 8, i & 0x0ff, rh_state_string(fotg210)); in fill_registers_buffer()
680 i = fotg210_readl(fotg210, &fotg210->caps->hcs_params); in fill_registers_buffer()
685 i = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in fill_registers_buffer()
692 fotg210_readl(fotg210, &fotg210->regs->status)); in fill_registers_buffer()
698 fotg210_readl(fotg210, &fotg210->regs->command)); in fill_registers_buffer()
704 fotg210_readl(fotg210, &fotg210->regs->intr_enable)); in fill_registers_buffer()
710 fotg210_read_frame_index(fotg210)); in fill_registers_buffer()
714 if (fotg210->async_unlink) { in fill_registers_buffer()
716 fotg210->async_unlink); in fill_registers_buffer()
724 fotg210->stats.normal, fotg210->stats.error, in fill_registers_buffer()
725 fotg210->stats.iaa, fotg210->stats.lost_iaa); in fill_registers_buffer()
730 fotg210->stats.complete, fotg210->stats.unlink); in fill_registers_buffer()
736 spin_unlock_irqrestore(&fotg210->lock, flags); in fill_registers_buffer()
844 static inline void create_debug_files(struct fotg210_hcd *fotg210) in create_debug_files() argument
846 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self; in create_debug_files()
850 fotg210->debug_dir = root; in create_debug_files()
859 static inline void remove_debug_files(struct fotg210_hcd *fotg210) in remove_debug_files() argument
861 debugfs_remove_recursive(fotg210->debug_dir); in remove_debug_files()
880 static int handshake(struct fotg210_hcd *fotg210, void __iomem *ptr, in handshake() argument
886 result = fotg210_readl(fotg210, ptr); in handshake()
901 static int fotg210_halt(struct fotg210_hcd *fotg210) in fotg210_halt() argument
905 spin_lock_irq(&fotg210->lock); in fotg210_halt()
908 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable); in fotg210_halt()
914 fotg210->command &= ~CMD_RUN; in fotg210_halt()
915 temp = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_halt()
917 fotg210_writel(fotg210, temp, &fotg210->regs->command); in fotg210_halt()
919 spin_unlock_irq(&fotg210->lock); in fotg210_halt()
920 synchronize_irq(fotg210_to_hcd(fotg210)->irq); in fotg210_halt()
922 return handshake(fotg210, &fotg210->regs->status, in fotg210_halt()
929 static int fotg210_reset(struct fotg210_hcd *fotg210) in fotg210_reset() argument
932 u32 command = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_reset()
937 if (fotg210->debug && !dbgp_reset_prep(fotg210_to_hcd(fotg210))) in fotg210_reset()
938 fotg210->debug = NULL; in fotg210_reset()
941 dbg_cmd(fotg210, "reset", command); in fotg210_reset()
942 fotg210_writel(fotg210, command, &fotg210->regs->command); in fotg210_reset()
943 fotg210->rh_state = FOTG210_RH_HALTED; in fotg210_reset()
944 fotg210->next_statechange = jiffies; in fotg210_reset()
945 retval = handshake(fotg210, &fotg210->regs->command, in fotg210_reset()
951 if (fotg210->debug) in fotg210_reset()
952 dbgp_external_startup(fotg210_to_hcd(fotg210)); in fotg210_reset()
954 fotg210->port_c_suspend = fotg210->suspended_ports = in fotg210_reset()
955 fotg210->resuming_ports = 0; in fotg210_reset()
962 static void fotg210_quiesce(struct fotg210_hcd *fotg210) in fotg210_quiesce() argument
966 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_quiesce()
970 temp = (fotg210->command << 10) & (STS_ASS | STS_PSS); in fotg210_quiesce()
971 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, temp, in fotg210_quiesce()
975 spin_lock_irq(&fotg210->lock); in fotg210_quiesce()
976 fotg210->command &= ~(CMD_ASE | CMD_PSE); in fotg210_quiesce()
977 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_quiesce()
978 spin_unlock_irq(&fotg210->lock); in fotg210_quiesce()
981 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, 0, in fotg210_quiesce()
985 static void end_unlink_async(struct fotg210_hcd *fotg210);
986 static void unlink_empty_async(struct fotg210_hcd *fotg210);
987 static void fotg210_work(struct fotg210_hcd *fotg210);
988 static void start_unlink_intr(struct fotg210_hcd *fotg210,
990 static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
993 static void fotg210_set_command_bit(struct fotg210_hcd *fotg210, u32 bit) in fotg210_set_command_bit() argument
995 fotg210->command |= bit; in fotg210_set_command_bit()
996 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_set_command_bit()
999 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_set_command_bit()
1003 static void fotg210_clear_command_bit(struct fotg210_hcd *fotg210, u32 bit) in fotg210_clear_command_bit() argument
1005 fotg210->command &= ~bit; in fotg210_clear_command_bit()
1006 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_clear_command_bit()
1009 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_clear_command_bit()
1052 static void fotg210_enable_event(struct fotg210_hcd *fotg210, unsigned event, in fotg210_enable_event() argument
1055 ktime_t *timeout = &fotg210->hr_timeouts[event]; in fotg210_enable_event()
1059 fotg210->enabled_hrtimer_events |= (1 << event); in fotg210_enable_event()
1062 if (event < fotg210->next_hrtimer_event) { in fotg210_enable_event()
1063 fotg210->next_hrtimer_event = event; in fotg210_enable_event()
1064 hrtimer_start_range_ns(&fotg210->hrtimer, *timeout, in fotg210_enable_event()
1071 static void fotg210_poll_ASS(struct fotg210_hcd *fotg210) in fotg210_poll_ASS() argument
1076 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_poll_ASS()
1079 want = (fotg210->command & CMD_ASE) ? STS_ASS : 0; in fotg210_poll_ASS()
1080 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_ASS; in fotg210_poll_ASS()
1085 if (fotg210->ASS_poll_count++ < 20) { in fotg210_poll_ASS()
1086 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_ASS, in fotg210_poll_ASS()
1090 fotg210_dbg(fotg210, "Waited too long for the async schedule status (%x/%x), giving up\n", in fotg210_poll_ASS()
1093 fotg210->ASS_poll_count = 0; in fotg210_poll_ASS()
1097 if (fotg210->async_count > 0) in fotg210_poll_ASS()
1098 fotg210_set_command_bit(fotg210, CMD_ASE); in fotg210_poll_ASS()
1101 if (fotg210->async_count == 0) { in fotg210_poll_ASS()
1104 fotg210_enable_event(fotg210, in fotg210_poll_ASS()
1112 static void fotg210_disable_ASE(struct fotg210_hcd *fotg210) in fotg210_disable_ASE() argument
1114 fotg210_clear_command_bit(fotg210, CMD_ASE); in fotg210_disable_ASE()
1119 static void fotg210_poll_PSS(struct fotg210_hcd *fotg210) in fotg210_poll_PSS() argument
1124 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_poll_PSS()
1127 want = (fotg210->command & CMD_PSE) ? STS_PSS : 0; in fotg210_poll_PSS()
1128 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_PSS; in fotg210_poll_PSS()
1133 if (fotg210->PSS_poll_count++ < 20) { in fotg210_poll_PSS()
1134 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_PSS, in fotg210_poll_PSS()
1138 fotg210_dbg(fotg210, "Waited too long for the periodic schedule status (%x/%x), giving up\n", in fotg210_poll_PSS()
1141 fotg210->PSS_poll_count = 0; in fotg210_poll_PSS()
1145 if (fotg210->periodic_count > 0) in fotg210_poll_PSS()
1146 fotg210_set_command_bit(fotg210, CMD_PSE); in fotg210_poll_PSS()
1149 if (fotg210->periodic_count == 0) { in fotg210_poll_PSS()
1152 fotg210_enable_event(fotg210, in fotg210_poll_PSS()
1160 static void fotg210_disable_PSE(struct fotg210_hcd *fotg210) in fotg210_disable_PSE() argument
1162 fotg210_clear_command_bit(fotg210, CMD_PSE); in fotg210_disable_PSE()
1167 static void fotg210_handle_controller_death(struct fotg210_hcd *fotg210) in fotg210_handle_controller_death() argument
1169 if (!(fotg210_readl(fotg210, &fotg210->regs->status) & STS_HALT)) { in fotg210_handle_controller_death()
1172 if (fotg210->died_poll_count++ < 5) { in fotg210_handle_controller_death()
1174 fotg210_enable_event(fotg210, in fotg210_handle_controller_death()
1178 fotg210_warn(fotg210, "Waited too long for the controller to stop, giving up\n"); in fotg210_handle_controller_death()
1182 fotg210->rh_state = FOTG210_RH_HALTED; in fotg210_handle_controller_death()
1183 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable); in fotg210_handle_controller_death()
1184 fotg210_work(fotg210); in fotg210_handle_controller_death()
1185 end_unlink_async(fotg210); in fotg210_handle_controller_death()
1192 static void fotg210_handle_intr_unlinks(struct fotg210_hcd *fotg210) in fotg210_handle_intr_unlinks() argument
1194 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING); in fotg210_handle_intr_unlinks()
1203 fotg210->intr_unlinking = true; in fotg210_handle_intr_unlinks()
1204 while (fotg210->intr_unlink) { in fotg210_handle_intr_unlinks()
1205 struct fotg210_qh *qh = fotg210->intr_unlink; in fotg210_handle_intr_unlinks()
1207 if (!stopped && qh->unlink_cycle == fotg210->intr_unlink_cycle) in fotg210_handle_intr_unlinks()
1209 fotg210->intr_unlink = qh->unlink_next; in fotg210_handle_intr_unlinks()
1211 end_unlink_intr(fotg210, qh); in fotg210_handle_intr_unlinks()
1215 if (fotg210->intr_unlink) { in fotg210_handle_intr_unlinks()
1216 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR, in fotg210_handle_intr_unlinks()
1218 ++fotg210->intr_unlink_cycle; in fotg210_handle_intr_unlinks()
1220 fotg210->intr_unlinking = false; in fotg210_handle_intr_unlinks()
1225 static void start_free_itds(struct fotg210_hcd *fotg210) in start_free_itds() argument
1227 if (!(fotg210->enabled_hrtimer_events & in start_free_itds()
1229 fotg210->last_itd_to_free = list_entry( in start_free_itds()
1230 fotg210->cached_itd_list.prev, in start_free_itds()
1232 fotg210_enable_event(fotg210, FOTG210_HRTIMER_FREE_ITDS, true); in start_free_itds()
1237 static void end_free_itds(struct fotg210_hcd *fotg210) in end_free_itds() argument
1241 if (fotg210->rh_state < FOTG210_RH_RUNNING) in end_free_itds()
1242 fotg210->last_itd_to_free = NULL; in end_free_itds()
1244 list_for_each_entry_safe(itd, n, &fotg210->cached_itd_list, itd_list) { in end_free_itds()
1246 dma_pool_free(fotg210->itd_pool, itd, itd->itd_dma); in end_free_itds()
1247 if (itd == fotg210->last_itd_to_free) in end_free_itds()
1251 if (!list_empty(&fotg210->cached_itd_list)) in end_free_itds()
1252 start_free_itds(fotg210); in end_free_itds()
1257 static void fotg210_iaa_watchdog(struct fotg210_hcd *fotg210) in fotg210_iaa_watchdog() argument
1259 if (fotg210->rh_state != FOTG210_RH_RUNNING) in fotg210_iaa_watchdog()
1268 if (fotg210->async_iaa) { in fotg210_iaa_watchdog()
1277 cmd = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_iaa_watchdog()
1286 status = fotg210_readl(fotg210, &fotg210->regs->status); in fotg210_iaa_watchdog()
1288 COUNT(fotg210->stats.lost_iaa); in fotg210_iaa_watchdog()
1289 fotg210_writel(fotg210, STS_IAA, in fotg210_iaa_watchdog()
1290 &fotg210->regs->status); in fotg210_iaa_watchdog()
1293 fotg210_dbg(fotg210, "IAA watchdog: status %x cmd %x\n", in fotg210_iaa_watchdog()
1295 end_unlink_async(fotg210); in fotg210_iaa_watchdog()
1301 static void turn_on_io_watchdog(struct fotg210_hcd *fotg210) in turn_on_io_watchdog() argument
1304 if (fotg210->rh_state != FOTG210_RH_RUNNING || in turn_on_io_watchdog()
1305 (fotg210->enabled_hrtimer_events & in turn_on_io_watchdog()
1313 if (fotg210->isoc_count > 0 || (fotg210->need_io_watchdog && in turn_on_io_watchdog()
1314 fotg210->async_count + fotg210->intr_count > 0)) in turn_on_io_watchdog()
1315 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IO_WATCHDOG, in turn_on_io_watchdog()
1339 struct fotg210_hcd *fotg210 = in fotg210_hrtimer_func() local
1346 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hrtimer_func()
1348 events = fotg210->enabled_hrtimer_events; in fotg210_hrtimer_func()
1349 fotg210->enabled_hrtimer_events = 0; in fotg210_hrtimer_func()
1350 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT; in fotg210_hrtimer_func()
1358 if (ktime_compare(now, fotg210->hr_timeouts[e]) >= 0) in fotg210_hrtimer_func()
1359 event_handlers[e](fotg210); in fotg210_hrtimer_func()
1361 fotg210_enable_event(fotg210, e, false); in fotg210_hrtimer_func()
1364 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hrtimer_func()
1371 static int check_reset_complete(struct fotg210_hcd *fotg210, int index, in check_reset_complete() argument
1380 fotg210_dbg(fotg210, "Failed to enable port %d on root hub TT\n", in check_reset_complete()
1383 fotg210_dbg(fotg210, "port %d reset complete, port enabled\n", in check_reset_complete()
1394 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_hub_status_data() local
1406 status = fotg210->resuming_ports; in fotg210_hub_status_data()
1414 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_status_data()
1416 temp = fotg210_readl(fotg210, &fotg210->regs->port_status); in fotg210_hub_status_data()
1425 if ((temp & mask) != 0 || test_bit(0, &fotg210->port_c_suspend) || in fotg210_hub_status_data()
1426 (fotg210->reset_done[0] && in fotg210_hub_status_data()
1427 time_after_eq(jiffies, fotg210->reset_done[0]))) { in fotg210_hub_status_data()
1432 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_status_data()
1436 static void fotg210_hub_descriptor(struct fotg210_hcd *fotg210, in fotg210_hub_descriptor() argument
1439 int ports = HCS_N_PORTS(fotg210->hcs_params); in fotg210_hub_descriptor()
1462 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_hub_control() local
1463 int ports = HCS_N_PORTS(fotg210->hcs_params); in fotg210_hub_control()
1464 u32 __iomem *status_reg = &fotg210->regs->port_status; in fotg210_hub_control()
1477 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_control()
1493 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1505 fotg210_writel(fotg210, temp & ~PORT_PE, status_reg); in fotg210_hub_control()
1508 fotg210_writel(fotg210, temp | PORT_PEC, status_reg); in fotg210_hub_control()
1519 fotg210_writel(fotg210, temp | PORT_RESUME, status_reg); in fotg210_hub_control()
1520 fotg210->reset_done[wIndex] = jiffies in fotg210_hub_control()
1524 clear_bit(wIndex, &fotg210->port_c_suspend); in fotg210_hub_control()
1527 fotg210_writel(fotg210, temp | PORT_CSC, status_reg); in fotg210_hub_control()
1530 fotg210_writel(fotg210, temp | OTGISR_OVC, in fotg210_hub_control()
1531 &fotg210->regs->otgisr); in fotg210_hub_control()
1539 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_hub_control()
1542 fotg210_hub_descriptor(fotg210, (struct usb_hub_descriptor *) in fotg210_hub_control()
1555 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1563 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr); in fotg210_hub_control()
1571 if (!fotg210->reset_done[wIndex]) { in fotg210_hub_control()
1573 fotg210->reset_done[wIndex] = jiffies in fotg210_hub_control()
1576 mod_timer(&fotg210_to_hcd(fotg210)->rh_timer, in fotg210_hub_control()
1577 fotg210->reset_done[wIndex]); in fotg210_hub_control()
1582 fotg210->reset_done[wIndex])) { in fotg210_hub_control()
1583 clear_bit(wIndex, &fotg210->suspended_ports); in fotg210_hub_control()
1584 set_bit(wIndex, &fotg210->port_c_suspend); in fotg210_hub_control()
1585 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1588 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1589 fotg210_writel(fotg210, temp & in fotg210_hub_control()
1592 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1593 retval = handshake(fotg210, status_reg, in fotg210_hub_control()
1596 fotg210_err(fotg210, in fotg210_hub_control()
1607 fotg210->reset_done[wIndex])) { in fotg210_hub_control()
1609 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1610 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1613 fotg210_writel(fotg210, in fotg210_hub_control()
1619 retval = handshake(fotg210, status_reg, in fotg210_hub_control()
1622 fotg210_err(fotg210, "port %d reset error %d\n", in fotg210_hub_control()
1628 temp = check_reset_complete(fotg210, wIndex, status_reg, in fotg210_hub_control()
1629 fotg210_readl(fotg210, status_reg)); in fotg210_hub_control()
1633 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1634 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1639 test_bit(wIndex, &fotg210->companion_ports)) { in fotg210_hub_control()
1641 fotg210_writel(fotg210, temp, status_reg); in fotg210_hub_control()
1642 fotg210_dbg(fotg210, "port %d --> companion\n", in fotg210_hub_control()
1644 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1655 status |= fotg210_port_speed(fotg210, temp); in fotg210_hub_control()
1663 } else if (test_bit(wIndex, &fotg210->suspended_ports)) { in fotg210_hub_control()
1664 clear_bit(wIndex, &fotg210->suspended_ports); in fotg210_hub_control()
1665 clear_bit(wIndex, &fotg210->resuming_ports); in fotg210_hub_control()
1666 fotg210->reset_done[wIndex] = 0; in fotg210_hub_control()
1668 set_bit(wIndex, &fotg210->port_c_suspend); in fotg210_hub_control()
1671 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr); in fotg210_hub_control()
1676 if (test_bit(wIndex, &fotg210->port_c_suspend)) in fotg210_hub_control()
1680 dbg_port(fotg210, "GetStatus", wIndex + 1, temp); in fotg210_hub_control()
1700 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1712 fotg210_writel(fotg210, temp | PORT_SUSPEND, in fotg210_hub_control()
1714 set_bit(wIndex, &fotg210->suspended_ports); in fotg210_hub_control()
1723 fotg210_dbg(fotg210, "port %d reset\n", wIndex + 1); in fotg210_hub_control()
1731 fotg210->reset_done[wIndex] = jiffies in fotg210_hub_control()
1733 fotg210_writel(fotg210, temp, status_reg); in fotg210_hub_control()
1745 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_control()
1746 fotg210_quiesce(fotg210); in fotg210_hub_control()
1747 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_control()
1750 temp = fotg210_readl(fotg210, status_reg) & in fotg210_hub_control()
1753 fotg210_writel(fotg210, temp | PORT_SUSPEND, in fotg210_hub_control()
1756 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_control()
1757 fotg210_halt(fotg210); in fotg210_hub_control()
1758 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_hub_control()
1760 temp = fotg210_readl(fotg210, status_reg); in fotg210_hub_control()
1762 fotg210_writel(fotg210, temp, status_reg); in fotg210_hub_control()
1768 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_hub_control()
1776 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_hub_control()
1803 static inline void fotg210_qtd_init(struct fotg210_hcd *fotg210, in fotg210_qtd_init() argument
1808 qtd->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT); in fotg210_qtd_init()
1809 qtd->hw_next = FOTG210_LIST_END(fotg210); in fotg210_qtd_init()
1810 qtd->hw_alt_next = FOTG210_LIST_END(fotg210); in fotg210_qtd_init()
1814 static struct fotg210_qtd *fotg210_qtd_alloc(struct fotg210_hcd *fotg210, in fotg210_qtd_alloc() argument
1820 qtd = dma_pool_alloc(fotg210->qtd_pool, flags, &dma); in fotg210_qtd_alloc()
1822 fotg210_qtd_init(fotg210, qtd, dma); in fotg210_qtd_alloc()
1827 static inline void fotg210_qtd_free(struct fotg210_hcd *fotg210, in fotg210_qtd_free() argument
1830 dma_pool_free(fotg210->qtd_pool, qtd, qtd->qtd_dma); in fotg210_qtd_free()
1834 static void qh_destroy(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_destroy() argument
1838 fotg210_dbg(fotg210, "unused qh not empty!\n"); in qh_destroy()
1842 fotg210_qtd_free(fotg210, qh->dummy); in qh_destroy()
1843 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma); in qh_destroy()
1847 static struct fotg210_qh *fotg210_qh_alloc(struct fotg210_hcd *fotg210, in fotg210_qh_alloc() argument
1856 qh->hw = dma_pool_zalloc(fotg210->qh_pool, flags, &dma); in fotg210_qh_alloc()
1863 qh->dummy = fotg210_qtd_alloc(fotg210, flags); in fotg210_qh_alloc()
1865 fotg210_dbg(fotg210, "no dummy td\n"); in fotg210_qh_alloc()
1871 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma); in fotg210_qh_alloc()
1882 static void fotg210_mem_cleanup(struct fotg210_hcd *fotg210) in fotg210_mem_cleanup() argument
1884 if (fotg210->async) in fotg210_mem_cleanup()
1885 qh_destroy(fotg210, fotg210->async); in fotg210_mem_cleanup()
1886 fotg210->async = NULL; in fotg210_mem_cleanup()
1888 if (fotg210->dummy) in fotg210_mem_cleanup()
1889 qh_destroy(fotg210, fotg210->dummy); in fotg210_mem_cleanup()
1890 fotg210->dummy = NULL; in fotg210_mem_cleanup()
1893 dma_pool_destroy(fotg210->qtd_pool); in fotg210_mem_cleanup()
1894 fotg210->qtd_pool = NULL; in fotg210_mem_cleanup()
1896 dma_pool_destroy(fotg210->qh_pool); in fotg210_mem_cleanup()
1897 fotg210->qh_pool = NULL; in fotg210_mem_cleanup()
1899 dma_pool_destroy(fotg210->itd_pool); in fotg210_mem_cleanup()
1900 fotg210->itd_pool = NULL; in fotg210_mem_cleanup()
1902 if (fotg210->periodic) in fotg210_mem_cleanup()
1903 dma_free_coherent(fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_cleanup()
1904 fotg210->periodic_size * sizeof(u32), in fotg210_mem_cleanup()
1905 fotg210->periodic, fotg210->periodic_dma); in fotg210_mem_cleanup()
1906 fotg210->periodic = NULL; in fotg210_mem_cleanup()
1909 kfree(fotg210->pshadow); in fotg210_mem_cleanup()
1910 fotg210->pshadow = NULL; in fotg210_mem_cleanup()
1914 static int fotg210_mem_init(struct fotg210_hcd *fotg210, gfp_t flags) in fotg210_mem_init() argument
1919 fotg210->qtd_pool = dma_pool_create("fotg210_qtd", in fotg210_mem_init()
1920 fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1924 if (!fotg210->qtd_pool) in fotg210_mem_init()
1928 fotg210->qh_pool = dma_pool_create("fotg210_qh", in fotg210_mem_init()
1929 fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1933 if (!fotg210->qh_pool) in fotg210_mem_init()
1936 fotg210->async = fotg210_qh_alloc(fotg210, flags); in fotg210_mem_init()
1937 if (!fotg210->async) in fotg210_mem_init()
1941 fotg210->itd_pool = dma_pool_create("fotg210_itd", in fotg210_mem_init()
1942 fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1946 if (!fotg210->itd_pool) in fotg210_mem_init()
1950 fotg210->periodic = (__le32 *) in fotg210_mem_init()
1951 dma_alloc_coherent(fotg210_to_hcd(fotg210)->self.controller, in fotg210_mem_init()
1952 fotg210->periodic_size * sizeof(__le32), in fotg210_mem_init()
1953 &fotg210->periodic_dma, 0); in fotg210_mem_init()
1954 if (fotg210->periodic == NULL) in fotg210_mem_init()
1957 for (i = 0; i < fotg210->periodic_size; i++) in fotg210_mem_init()
1958 fotg210->periodic[i] = FOTG210_LIST_END(fotg210); in fotg210_mem_init()
1961 fotg210->pshadow = kcalloc(fotg210->periodic_size, sizeof(void *), in fotg210_mem_init()
1963 if (fotg210->pshadow != NULL) in fotg210_mem_init()
1967 fotg210_dbg(fotg210, "couldn't init memory\n"); in fotg210_mem_init()
1968 fotg210_mem_cleanup(fotg210); in fotg210_mem_init()
1989 static int qtd_fill(struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd, in qtd_fill() argument
1996 qtd->hw_buf[0] = cpu_to_hc32(fotg210, (u32)addr); in qtd_fill()
1997 qtd->hw_buf_hi[0] = cpu_to_hc32(fotg210, (u32)(addr >> 32)); in qtd_fill()
2008 qtd->hw_buf[i] = cpu_to_hc32(fotg210, (u32)addr); in qtd_fill()
2009 qtd->hw_buf_hi[i] = cpu_to_hc32(fotg210, in qtd_fill()
2022 qtd->hw_token = cpu_to_hc32(fotg210, (count << 16) | token); in qtd_fill()
2028 static inline void qh_update(struct fotg210_hcd *fotg210, in qh_update() argument
2036 hw->hw_qtd_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_update()
2037 hw->hw_alt_next = FOTG210_LIST_END(fotg210); in qh_update()
2044 if (!(hw->hw_info1 & cpu_to_hc32(fotg210, QH_TOGGLE_CTL))) { in qh_update()
2048 epnum = (hc32_to_cpup(fotg210, &hw->hw_info1) >> 8) & 0x0f; in qh_update()
2050 hw->hw_token &= ~cpu_to_hc32(fotg210, QTD_TOGGLE); in qh_update()
2055 hw->hw_token &= cpu_to_hc32(fotg210, QTD_TOGGLE | QTD_STS_PING); in qh_update()
2062 static void qh_refresh(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_refresh() argument
2078 if (cpu_to_hc32(fotg210, qtd->qtd_dma) == qh->hw->hw_current) { in qh_refresh()
2085 qh_update(fotg210, qh, qtd); in qh_refresh()
2088 static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2093 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_clear_tt_buffer_complete() local
2097 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_clear_tt_buffer_complete()
2100 && fotg210->rh_state == FOTG210_RH_RUNNING) in fotg210_clear_tt_buffer_complete()
2101 qh_link_async(fotg210, qh); in fotg210_clear_tt_buffer_complete()
2102 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_clear_tt_buffer_complete()
2105 static void fotg210_clear_tt_buffer(struct fotg210_hcd *fotg210, in fotg210_clear_tt_buffer() argument
2124 fotg210_to_hcd(fotg210)->self.root_hub) { in fotg210_clear_tt_buffer()
2131 static int qtd_copy_status(struct fotg210_hcd *fotg210, struct urb *urb, in qtd_copy_status() argument
2170 fotg210_dbg(fotg210, "devpath %s ep%d%s 3strikes\n", in qtd_copy_status()
2179 fotg210_dbg(fotg210, in qtd_copy_status()
2190 static void fotg210_urb_done(struct fotg210_hcd *fotg210, struct urb *urb, in fotg210_urb_done() argument
2192 __releases(fotg210->lock) in fotg210_urb_done()
2193 __acquires(fotg210->lock) in fotg210_urb_done()
2199 if ((qh->hw->hw_info2 & cpu_to_hc32(fotg210, QH_SMASK)) != 0) { in fotg210_urb_done()
2202 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs--; in fotg210_urb_done()
2207 COUNT(fotg210->stats.unlink); in fotg210_urb_done()
2212 COUNT(fotg210->stats.complete); in fotg210_urb_done()
2216 fotg210_dbg(fotg210, in fotg210_urb_done()
2226 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb); in fotg210_urb_done()
2227 spin_unlock(&fotg210->lock); in fotg210_urb_done()
2228 usb_hcd_giveback_urb(fotg210_to_hcd(fotg210), urb, status); in fotg210_urb_done()
2229 spin_lock(&fotg210->lock); in fotg210_urb_done()
2232 static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2238 static unsigned qh_completions(struct fotg210_hcd *fotg210, in qh_completions() argument
2285 fotg210_urb_done(fotg210, last->urb, in qh_completions()
2290 fotg210_qtd_free(fotg210, last); in qh_completions()
2300 token = hc32_to_cpu(fotg210, qtd->hw_token); in qh_completions()
2308 fotg210_dbg(fotg210, in qh_completions()
2327 fotg210_dbg(fotg210, in qh_completions()
2341 qtd->hw_token = cpu_to_hc32(fotg210, in qh_completions()
2344 hw->hw_token = cpu_to_hc32(fotg210, in qh_completions()
2361 FOTG210_LIST_END(fotg210))) { in qh_completions()
2367 && fotg210->rh_state >= FOTG210_RH_RUNNING)) { in qh_completions()
2375 if (fotg210->rh_state < FOTG210_RH_RUNNING) in qh_completions()
2386 cpu_to_hc32(fotg210, qtd->qtd_dma) in qh_completions()
2388 token = hc32_to_cpu(fotg210, hw->hw_token); in qh_completions()
2394 fotg210_clear_tt_buffer(fotg210, qh, urb, in qh_completions()
2407 last_status = qtd_copy_status(fotg210, urb, in qh_completions()
2411 FOTG210_LIST_END(fotg210))) in qh_completions()
2429 fotg210_clear_tt_buffer(fotg210, qh, in qh_completions()
2453 fotg210_urb_done(fotg210, last->urb, last_status); in qh_completions()
2455 fotg210_qtd_free(fotg210, last); in qh_completions()
2480 if (stopped != 0 || hw->hw_qtd_next == FOTG210_LIST_END(fotg210)) { in qh_completions()
2483 qh_refresh(fotg210, qh); in qh_completions()
2516 static void qtd_list_free(struct fotg210_hcd *fotg210, struct urb *urb, in qtd_list_free() argument
2523 fotg210_qtd_free(fotg210, qtd); in qtd_list_free()
2529 static struct list_head *qh_urb_transaction(struct fotg210_hcd *fotg210, in qh_urb_transaction() argument
2543 qtd = fotg210_qtd_alloc(fotg210, flags); in qh_urb_transaction()
2557 qtd_fill(fotg210, qtd, urb->setup_dma, in qh_urb_transaction()
2564 qtd = fotg210_qtd_alloc(fotg210, flags); in qh_urb_transaction()
2568 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_urb_transaction()
2608 this_qtd_len = qtd_fill(fotg210, qtd, buf, this_sg_len, token, in qh_urb_transaction()
2620 qtd->hw_alt_next = fotg210->async->hw->hw_alt_next; in qh_urb_transaction()
2635 qtd = fotg210_qtd_alloc(fotg210, flags); in qh_urb_transaction()
2639 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_urb_transaction()
2650 qtd->hw_alt_next = FOTG210_LIST_END(fotg210); in qh_urb_transaction()
2671 qtd = fotg210_qtd_alloc(fotg210, flags); in qh_urb_transaction()
2675 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma); in qh_urb_transaction()
2679 qtd_fill(fotg210, qtd, 0, 0, token, 0); in qh_urb_transaction()
2685 qtd->hw_token |= cpu_to_hc32(fotg210, QTD_IOC); in qh_urb_transaction()
2689 qtd_list_free(fotg210, urb, head); in qh_urb_transaction()
2708 static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb, in qh_make() argument
2711 struct fotg210_qh *qh = fotg210_qh_alloc(fotg210, flags); in qh_make()
2735 fotg210_dbg(fotg210, "bogus qh maxpacket %d\n", in qh_make()
2765 } else if (qh->period > fotg210->periodic_size) { in qh_make()
2766 qh->period = fotg210->periodic_size; in qh_make()
2790 if (qh->period > fotg210->periodic_size) { in qh_make()
2791 qh->period = fotg210->periodic_size; in qh_make()
2821 if (fotg210_has_fsl_portno_bug(fotg210)) in qh_make()
2829 if (tt && tt->hub != fotg210_to_hcd(fotg210)->self.root_hub) in qh_make()
2859 fotg210_dbg(fotg210, "bogus dev %p speed %d\n", urb->dev, in qh_make()
2862 qh_destroy(fotg210, qh); in qh_make()
2871 hw->hw_info1 = cpu_to_hc32(fotg210, info1); in qh_make()
2872 hw->hw_info2 = cpu_to_hc32(fotg210, info2); in qh_make()
2875 qh_refresh(fotg210, qh); in qh_make()
2879 static void enable_async(struct fotg210_hcd *fotg210) in enable_async() argument
2881 if (fotg210->async_count++) in enable_async()
2885 fotg210->enabled_hrtimer_events &= ~BIT(FOTG210_HRTIMER_DISABLE_ASYNC); in enable_async()
2888 fotg210_poll_ASS(fotg210); in enable_async()
2889 turn_on_io_watchdog(fotg210); in enable_async()
2892 static void disable_async(struct fotg210_hcd *fotg210) in disable_async() argument
2894 if (--fotg210->async_count) in disable_async()
2898 WARN_ON(fotg210->async->qh_next.qh || fotg210->async_unlink); in disable_async()
2901 fotg210_poll_ASS(fotg210); in disable_async()
2906 static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_link_async() argument
2908 __hc32 dma = QH_NEXT(fotg210, qh->qh_dma); in qh_link_async()
2918 qh_refresh(fotg210, qh); in qh_link_async()
2921 head = fotg210->async; in qh_link_async()
2933 enable_async(fotg210); in qh_link_async()
2941 static struct fotg210_qh *qh_append_tds(struct fotg210_hcd *fotg210, in qh_append_tds() argument
2946 __hc32 qh_addr_mask = cpu_to_hc32(fotg210, 0x7f); in qh_append_tds()
2951 qh = qh_make(fotg210, urb, GFP_ATOMIC); in qh_append_tds()
2984 qtd->hw_token = HALT_BIT(fotg210); in qh_append_tds()
2996 fotg210_qtd_init(fotg210, qtd, qtd->qtd_dma); in qh_append_tds()
3003 qtd->hw_next = QTD_NEXT(fotg210, dma); in qh_append_tds()
3015 static int submit_async(struct fotg210_hcd *fotg210, struct urb *urb, in submit_async() argument
3030 fotg210_dbg(fotg210, in submit_async()
3040 spin_lock_irqsave(&fotg210->lock, flags); in submit_async()
3041 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) { in submit_async()
3045 rc = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb); in submit_async()
3049 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv); in submit_async()
3051 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb); in submit_async()
3060 qh_link_async(fotg210, qh); in submit_async()
3062 spin_unlock_irqrestore(&fotg210->lock, flags); in submit_async()
3064 qtd_list_free(fotg210, urb, qtd_list); in submit_async()
3068 static void single_unlink_async(struct fotg210_hcd *fotg210, in single_unlink_async() argument
3075 if (fotg210->async_unlink) in single_unlink_async()
3076 fotg210->async_unlink_last->unlink_next = qh; in single_unlink_async()
3078 fotg210->async_unlink = qh; in single_unlink_async()
3079 fotg210->async_unlink_last = qh; in single_unlink_async()
3082 prev = fotg210->async; in single_unlink_async()
3088 if (fotg210->qh_scan_next == qh) in single_unlink_async()
3089 fotg210->qh_scan_next = qh->qh_next.qh; in single_unlink_async()
3092 static void start_iaa_cycle(struct fotg210_hcd *fotg210, bool nested) in start_iaa_cycle() argument
3098 if (fotg210->async_iaa || fotg210->async_unlinking) in start_iaa_cycle()
3102 fotg210->async_iaa = fotg210->async_unlink; in start_iaa_cycle()
3103 fotg210->async_unlink = NULL; in start_iaa_cycle()
3106 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING)) { in start_iaa_cycle()
3108 end_unlink_async(fotg210); in start_iaa_cycle()
3111 } else if (likely(fotg210->rh_state == FOTG210_RH_RUNNING)) { in start_iaa_cycle()
3115 fotg210_writel(fotg210, fotg210->command | CMD_IAAD, in start_iaa_cycle()
3116 &fotg210->regs->command); in start_iaa_cycle()
3117 fotg210_readl(fotg210, &fotg210->regs->command); in start_iaa_cycle()
3118 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IAA_WATCHDOG, in start_iaa_cycle()
3125 static void end_unlink_async(struct fotg210_hcd *fotg210) in end_unlink_async() argument
3131 fotg210->async_unlinking = true; in end_unlink_async()
3132 while (fotg210->async_iaa) { in end_unlink_async()
3133 qh = fotg210->async_iaa; in end_unlink_async()
3134 fotg210->async_iaa = qh->unlink_next; in end_unlink_async()
3140 qh_completions(fotg210, qh); in end_unlink_async()
3142 fotg210->rh_state == FOTG210_RH_RUNNING) in end_unlink_async()
3143 qh_link_async(fotg210, qh); in end_unlink_async()
3144 disable_async(fotg210); in end_unlink_async()
3146 fotg210->async_unlinking = false; in end_unlink_async()
3149 if (fotg210->async_unlink) { in end_unlink_async()
3150 start_iaa_cycle(fotg210, true); in end_unlink_async()
3151 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING)) in end_unlink_async()
3156 static void unlink_empty_async(struct fotg210_hcd *fotg210) in unlink_empty_async() argument
3159 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING); in unlink_empty_async()
3163 next = fotg210->async->qh_next.qh; in unlink_empty_async()
3171 fotg210->async_unlink_cycle) in unlink_empty_async()
3174 single_unlink_async(fotg210, qh); in unlink_empty_async()
3179 if (fotg210->async_unlink) in unlink_empty_async()
3180 start_iaa_cycle(fotg210, false); in unlink_empty_async()
3184 fotg210_enable_event(fotg210, FOTG210_HRTIMER_ASYNC_UNLINKS, in unlink_empty_async()
3186 ++fotg210->async_unlink_cycle; in unlink_empty_async()
3193 static void start_unlink_async(struct fotg210_hcd *fotg210, in start_unlink_async() argument
3207 single_unlink_async(fotg210, qh); in start_unlink_async()
3208 start_iaa_cycle(fotg210, false); in start_unlink_async()
3211 static void scan_async(struct fotg210_hcd *fotg210) in scan_async() argument
3216 fotg210->qh_scan_next = fotg210->async->qh_next.qh; in scan_async()
3217 while (fotg210->qh_scan_next) { in scan_async()
3218 qh = fotg210->qh_scan_next; in scan_async()
3219 fotg210->qh_scan_next = qh->qh_next.qh; in scan_async()
3232 temp = qh_completions(fotg210, qh); in scan_async()
3234 start_unlink_async(fotg210, qh); in scan_async()
3237 qh->unlink_cycle = fotg210->async_unlink_cycle; in scan_async()
3250 if (check_unlinks_later && fotg210->rh_state == FOTG210_RH_RUNNING && in scan_async()
3251 !(fotg210->enabled_hrtimer_events & in scan_async()
3253 fotg210_enable_event(fotg210, in scan_async()
3255 ++fotg210->async_unlink_cycle; in scan_async()
3275 static union fotg210_shadow *periodic_next_shadow(struct fotg210_hcd *fotg210, in periodic_next_shadow() argument
3278 switch (hc32_to_cpu(fotg210, tag)) { in periodic_next_shadow()
3288 static __hc32 *shadow_next_periodic(struct fotg210_hcd *fotg210, in shadow_next_periodic() argument
3291 switch (hc32_to_cpu(fotg210, tag)) { in shadow_next_periodic()
3302 static void periodic_unlink(struct fotg210_hcd *fotg210, unsigned frame, in periodic_unlink() argument
3305 union fotg210_shadow *prev_p = &fotg210->pshadow[frame]; in periodic_unlink()
3306 __hc32 *hw_p = &fotg210->periodic[frame]; in periodic_unlink()
3311 prev_p = periodic_next_shadow(fotg210, prev_p, in periodic_unlink()
3312 Q_NEXT_TYPE(fotg210, *hw_p)); in periodic_unlink()
3313 hw_p = shadow_next_periodic(fotg210, &here, in periodic_unlink()
3314 Q_NEXT_TYPE(fotg210, *hw_p)); in periodic_unlink()
3324 *prev_p = *periodic_next_shadow(fotg210, &here, in periodic_unlink()
3325 Q_NEXT_TYPE(fotg210, *hw_p)); in periodic_unlink()
3327 *hw_p = *shadow_next_periodic(fotg210, &here, in periodic_unlink()
3328 Q_NEXT_TYPE(fotg210, *hw_p)); in periodic_unlink()
3332 static unsigned short periodic_usecs(struct fotg210_hcd *fotg210, in periodic_usecs() argument
3335 __hc32 *hw_p = &fotg210->periodic[frame]; in periodic_usecs()
3336 union fotg210_shadow *q = &fotg210->pshadow[frame]; in periodic_usecs()
3341 switch (hc32_to_cpu(fotg210, Q_NEXT_TYPE(fotg210, *hw_p))) { in periodic_usecs()
3345 if (hw->hw_info2 & cpu_to_hc32(fotg210, 1 << uframe)) in periodic_usecs()
3348 if (hw->hw_info2 & cpu_to_hc32(fotg210, in periodic_usecs()
3359 if (q->fstn->hw_prev != FOTG210_LIST_END(fotg210)) in periodic_usecs()
3360 fotg210_dbg(fotg210, "ignoring FSTN cost ...\n"); in periodic_usecs()
3373 if (usecs > fotg210->uframe_periodic_max) in periodic_usecs()
3374 fotg210_err(fotg210, "uframe %d sched overrun: %d usecs\n", in periodic_usecs()
3395 static int tt_no_collision(struct fotg210_hcd *fotg210, unsigned period, in tt_no_collision() argument
3405 for (; frame < fotg210->periodic_size; frame += period) { in tt_no_collision()
3410 here = fotg210->pshadow[frame]; in tt_no_collision()
3411 type = Q_NEXT_TYPE(fotg210, fotg210->periodic[frame]); in tt_no_collision()
3413 switch (hc32_to_cpu(fotg210, type)) { in tt_no_collision()
3415 type = Q_NEXT_TYPE(fotg210, here.itd->hw_next); in tt_no_collision()
3423 mask = hc32_to_cpu(fotg210, in tt_no_collision()
3430 type = Q_NEXT_TYPE(fotg210, hw->hw_next); in tt_no_collision()
3435 fotg210_dbg(fotg210, in tt_no_collision()
3449 static void enable_periodic(struct fotg210_hcd *fotg210) in enable_periodic() argument
3451 if (fotg210->periodic_count++) in enable_periodic()
3455 fotg210->enabled_hrtimer_events &= in enable_periodic()
3459 fotg210_poll_PSS(fotg210); in enable_periodic()
3460 turn_on_io_watchdog(fotg210); in enable_periodic()
3463 static void disable_periodic(struct fotg210_hcd *fotg210) in disable_periodic() argument
3465 if (--fotg210->periodic_count) in disable_periodic()
3469 fotg210_poll_PSS(fotg210); in disable_periodic()
3478 static void qh_link_periodic(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_link_periodic() argument
3485 hc32_to_cpup(fotg210, &qh->hw->hw_info2) & in qh_link_periodic()
3493 for (i = qh->start; i < fotg210->periodic_size; i += period) { in qh_link_periodic()
3494 union fotg210_shadow *prev = &fotg210->pshadow[i]; in qh_link_periodic()
3495 __hc32 *hw_p = &fotg210->periodic[i]; in qh_link_periodic()
3501 type = Q_NEXT_TYPE(fotg210, *hw_p); in qh_link_periodic()
3502 if (type == cpu_to_hc32(fotg210, Q_TYPE_QH)) in qh_link_periodic()
3504 prev = periodic_next_shadow(fotg210, prev, type); in qh_link_periodic()
3505 hw_p = shadow_next_periodic(fotg210, &here, type); in qh_link_periodic()
3526 *hw_p = QH_NEXT(fotg210, qh->qh_dma); in qh_link_periodic()
3533 fotg210_to_hcd(fotg210)->self.bandwidth_allocated += qh->period in qh_link_periodic()
3537 list_add(&qh->intr_node, &fotg210->intr_qh_list); in qh_link_periodic()
3540 ++fotg210->intr_count; in qh_link_periodic()
3541 enable_periodic(fotg210); in qh_link_periodic()
3544 static void qh_unlink_periodic(struct fotg210_hcd *fotg210, in qh_unlink_periodic() argument
3570 for (i = qh->start; i < fotg210->periodic_size; i += period) in qh_unlink_periodic()
3571 periodic_unlink(fotg210, i, qh); in qh_unlink_periodic()
3574 fotg210_to_hcd(fotg210)->self.bandwidth_allocated -= qh->period in qh_unlink_periodic()
3580 qh->period, hc32_to_cpup(fotg210, &qh->hw->hw_info2) & in qh_unlink_periodic()
3588 if (fotg210->qh_scan_next == qh) in qh_unlink_periodic()
3589 fotg210->qh_scan_next = list_entry(qh->intr_node.next, in qh_unlink_periodic()
3594 static void start_unlink_intr(struct fotg210_hcd *fotg210, in start_unlink_intr() argument
3607 qh_unlink_periodic(fotg210, qh); in start_unlink_intr()
3617 qh->unlink_cycle = fotg210->intr_unlink_cycle; in start_unlink_intr()
3620 if (fotg210->intr_unlink) in start_unlink_intr()
3621 fotg210->intr_unlink_last->unlink_next = qh; in start_unlink_intr()
3623 fotg210->intr_unlink = qh; in start_unlink_intr()
3624 fotg210->intr_unlink_last = qh; in start_unlink_intr()
3626 if (fotg210->intr_unlinking) in start_unlink_intr()
3628 else if (fotg210->rh_state < FOTG210_RH_RUNNING) in start_unlink_intr()
3629 fotg210_handle_intr_unlinks(fotg210); in start_unlink_intr()
3630 else if (fotg210->intr_unlink == qh) { in start_unlink_intr()
3631 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR, in start_unlink_intr()
3633 ++fotg210->intr_unlink_cycle; in start_unlink_intr()
3637 static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in end_unlink_intr() argument
3643 hw->hw_next = FOTG210_LIST_END(fotg210); in end_unlink_intr()
3645 qh_completions(fotg210, qh); in end_unlink_intr()
3649 fotg210->rh_state == FOTG210_RH_RUNNING) { in end_unlink_intr()
3650 rc = qh_schedule(fotg210, qh); in end_unlink_intr()
3659 fotg210_err(fotg210, "can't reschedule qh %p, err %d\n", in end_unlink_intr()
3664 --fotg210->intr_count; in end_unlink_intr()
3665 disable_periodic(fotg210); in end_unlink_intr()
3668 static int check_period(struct fotg210_hcd *fotg210, unsigned frame, in check_period() argument
3680 usecs = fotg210->uframe_periodic_max - usecs; in check_period()
3688 claimed = periodic_usecs(fotg210, frame, in check_period()
3693 } while ((frame += 1) < fotg210->periodic_size); in check_period()
3698 claimed = periodic_usecs(fotg210, frame, uframe); in check_period()
3701 } while ((frame += period) < fotg210->periodic_size); in check_period()
3708 static int check_intr_schedule(struct fotg210_hcd *fotg210, unsigned frame, in check_intr_schedule() argument
3717 if (!check_period(fotg210, frame, uframe, qh->period, qh->usecs)) in check_intr_schedule()
3733 *c_maskp = cpu_to_hc32(fotg210, mask << 8); in check_intr_schedule()
3736 if (tt_no_collision(fotg210, qh->period, qh->dev, frame, mask)) { in check_intr_schedule()
3737 if (!check_period(fotg210, frame, uframe + qh->gap_uf + 1, in check_intr_schedule()
3740 if (!check_period(fotg210, frame, uframe + qh->gap_uf, in check_intr_schedule()
3752 static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) in qh_schedule() argument
3760 qh_refresh(fotg210, qh); in qh_schedule()
3761 hw->hw_next = FOTG210_LIST_END(fotg210); in qh_schedule()
3766 uframe = ffs(hc32_to_cpup(fotg210, &hw->hw_info2) & QH_SMASK); in qh_schedule()
3767 status = check_intr_schedule(fotg210, frame, --uframe, in qh_schedule()
3784 frame = ++fotg210->random_frame % qh->period; in qh_schedule()
3786 status = check_intr_schedule(fotg210, in qh_schedule()
3797 status = check_intr_schedule(fotg210, 0, 0, qh, in qh_schedule()
3805 hw->hw_info2 &= cpu_to_hc32(fotg210, ~(QH_CMASK | QH_SMASK)); in qh_schedule()
3807 ? cpu_to_hc32(fotg210, 1 << uframe) in qh_schedule()
3808 : cpu_to_hc32(fotg210, QH_SMASK); in qh_schedule()
3811 fotg210_dbg(fotg210, "reused qh %p schedule\n", qh); in qh_schedule()
3814 qh_link_periodic(fotg210, qh); in qh_schedule()
3819 static int intr_submit(struct fotg210_hcd *fotg210, struct urb *urb, in intr_submit() argument
3831 spin_lock_irqsave(&fotg210->lock, flags); in intr_submit()
3833 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) { in intr_submit()
3837 status = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb); in intr_submit()
3843 qh = qh_append_tds(fotg210, urb, &empty, epnum, &urb->ep->hcpriv); in intr_submit()
3849 status = qh_schedule(fotg210, qh); in intr_submit()
3855 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv); in intr_submit()
3859 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs++; in intr_submit()
3863 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb); in intr_submit()
3865 spin_unlock_irqrestore(&fotg210->lock, flags); in intr_submit()
3867 qtd_list_free(fotg210, urb, qtd_list); in intr_submit()
3872 static void scan_intr(struct fotg210_hcd *fotg210) in scan_intr() argument
3876 list_for_each_entry_safe(qh, fotg210->qh_scan_next, in scan_intr()
3877 &fotg210->intr_qh_list, intr_node) { in scan_intr()
3890 temp = qh_completions(fotg210, qh); in scan_intr()
3894 start_unlink_intr(fotg210, qh); in scan_intr()
3916 static void iso_stream_init(struct fotg210_hcd *fotg210, in iso_stream_init() argument
3943 stream->buf0 = cpu_to_hc32(fotg210, (epnum << 8) | dev->devnum); in iso_stream_init()
3944 stream->buf1 = cpu_to_hc32(fotg210, buf1); in iso_stream_init()
3945 stream->buf2 = cpu_to_hc32(fotg210, multi); in iso_stream_init()
3969 static struct fotg210_iso_stream *iso_stream_find(struct fotg210_hcd *fotg210, in iso_stream_find() argument
3983 spin_lock_irqsave(&fotg210->lock, flags); in iso_stream_find()
3991 iso_stream_init(fotg210, stream, urb->dev, urb->pipe, in iso_stream_find()
3997 fotg210_dbg(fotg210, "dev %s ep%d%s, not iso??\n", in iso_stream_find()
4003 spin_unlock_irqrestore(&fotg210->lock, flags); in iso_stream_find()
4023 static inline void itd_sched_init(struct fotg210_hcd *fotg210, in itd_sched_init() argument
4051 uframe->transaction = cpu_to_hc32(fotg210, trans); in itd_sched_init()
4072 struct fotg210_hcd *fotg210, struct urb *urb, gfp_t mem_flags) in itd_urb_transaction() argument
4085 itd_sched_init(fotg210, sched, stream, urb); in itd_urb_transaction()
4093 spin_lock_irqsave(&fotg210->lock, flags); in itd_urb_transaction()
4103 if (itd->frame == fotg210->now_frame) in itd_urb_transaction()
4109 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_urb_transaction()
4110 itd = dma_pool_zalloc(fotg210->itd_pool, mem_flags, in itd_urb_transaction()
4112 spin_lock_irqsave(&fotg210->lock, flags); in itd_urb_transaction()
4115 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_urb_transaction()
4123 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_urb_transaction()
4131 static inline int itd_slot_ok(struct fotg210_hcd *fotg210, u32 mod, u32 uframe, in itd_slot_ok() argument
4137 if (periodic_usecs(fotg210, uframe >> 3, uframe & 0x7) in itd_slot_ok()
4138 > (fotg210->uframe_periodic_max - usecs)) in itd_slot_ok()
4159 static int iso_stream_schedule(struct fotg210_hcd *fotg210, struct urb *urb, in iso_stream_schedule() argument
4164 unsigned mod = fotg210->periodic_size << 3; in iso_stream_schedule()
4171 fotg210_dbg(fotg210, "iso request %p too long\n", urb); in iso_stream_schedule()
4176 now = fotg210_read_frame_index(fotg210) & (mod - 1); in iso_stream_schedule()
4191 if (!stream->highspeed && fotg210->fs_i_thresh) in iso_stream_schedule()
4192 next = now + fotg210->i_thresh; in iso_stream_schedule()
4207 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n", in iso_stream_schedule()
4238 if (itd_slot_ok(fotg210, mod, start, in iso_stream_schedule()
4245 fotg210_dbg(fotg210, "iso resched full %p (now %d max %d)\n", in iso_stream_schedule()
4255 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n", in iso_stream_schedule()
4270 if (fotg210->isoc_count == 0) in iso_stream_schedule()
4271 fotg210->next_frame = now >> 3; in iso_stream_schedule()
4280 static inline void itd_init(struct fotg210_hcd *fotg210, in itd_init() argument
4286 itd->hw_next = FOTG210_LIST_END(fotg210); in itd_init()
4297 static inline void itd_patch(struct fotg210_hcd *fotg210, in itd_patch() argument
4308 itd->hw_transaction[uframe] |= cpu_to_hc32(fotg210, pg << 12); in itd_patch()
4309 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, uf->bufp & ~(u32)0); in itd_patch()
4310 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(uf->bufp >> 32)); in itd_patch()
4317 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, bufp & ~(u32)0); in itd_patch()
4318 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(bufp >> 32)); in itd_patch()
4322 static inline void itd_link(struct fotg210_hcd *fotg210, unsigned frame, in itd_link() argument
4325 union fotg210_shadow *prev = &fotg210->pshadow[frame]; in itd_link()
4326 __hc32 *hw_p = &fotg210->periodic[frame]; in itd_link()
4332 type = Q_NEXT_TYPE(fotg210, *hw_p); in itd_link()
4333 if (type == cpu_to_hc32(fotg210, Q_TYPE_QH)) in itd_link()
4335 prev = periodic_next_shadow(fotg210, prev, type); in itd_link()
4336 hw_p = shadow_next_periodic(fotg210, &here, type); in itd_link()
4345 *hw_p = cpu_to_hc32(fotg210, itd->itd_dma | Q_TYPE_ITD); in itd_link()
4349 static void itd_link_urb(struct fotg210_hcd *fotg210, struct urb *urb, in itd_link_urb() argument
4360 fotg210_to_hcd(fotg210)->self.bandwidth_allocated in itd_link_urb()
4362 fotg210_dbg(fotg210, in itd_link_urb()
4382 itd_init(fotg210, stream, itd); in itd_link_urb()
4388 itd_patch(fotg210, itd, iso_sched, packet, uframe); in itd_link_urb()
4397 itd_link(fotg210, frame & (fotg210->periodic_size - 1), in itd_link_urb()
4408 ++fotg210->isoc_count; in itd_link_urb()
4409 enable_periodic(fotg210); in itd_link_urb()
4425 static bool itd_complete(struct fotg210_hcd *fotg210, struct fotg210_itd *itd) in itd_complete() argument
4443 t = hc32_to_cpup(fotg210, &itd->hw_transaction[uframe]); in itd_complete()
4485 fotg210_urb_done(fotg210, urb, 0); in itd_complete()
4489 --fotg210->isoc_count; in itd_complete()
4490 disable_periodic(fotg210); in itd_complete()
4493 fotg210_to_hcd(fotg210)->self.bandwidth_allocated in itd_complete()
4495 fotg210_dbg(fotg210, in itd_complete()
4510 &fotg210->cached_itd_list); in itd_complete()
4511 start_free_itds(fotg210); in itd_complete()
4517 static int itd_submit(struct fotg210_hcd *fotg210, struct urb *urb, in itd_submit() argument
4525 stream = iso_stream_find(fotg210, urb); in itd_submit()
4527 fotg210_dbg(fotg210, "can't get iso stream\n"); in itd_submit()
4531 fotg210_port_speed(fotg210, 0) == in itd_submit()
4533 fotg210_dbg(fotg210, "can't change iso interval %d --> %d\n", in itd_submit()
4539 fotg210_dbg(fotg210, in itd_submit()
4550 status = itd_urb_transaction(stream, fotg210, urb, mem_flags); in itd_submit()
4552 fotg210_dbg(fotg210, "can't init itds\n"); in itd_submit()
4557 spin_lock_irqsave(&fotg210->lock, flags); in itd_submit()
4558 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) { in itd_submit()
4562 status = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb); in itd_submit()
4565 status = iso_stream_schedule(fotg210, urb, stream); in itd_submit()
4567 itd_link_urb(fotg210, urb, fotg210->periodic_size << 3, stream); in itd_submit()
4569 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb); in itd_submit()
4571 spin_unlock_irqrestore(&fotg210->lock, flags); in itd_submit()
4576 static inline int scan_frame_queue(struct fotg210_hcd *fotg210, unsigned frame, in scan_frame_queue() argument
4585 q_p = &fotg210->pshadow[frame]; in scan_frame_queue()
4586 hw_p = &fotg210->periodic[frame]; in scan_frame_queue()
4588 type = Q_NEXT_TYPE(fotg210, *hw_p); in scan_frame_queue()
4592 switch (hc32_to_cpu(fotg210, type)) { in scan_frame_queue()
4603 ITD_ACTIVE(fotg210)) in scan_frame_queue()
4609 type = Q_NEXT_TYPE(fotg210, in scan_frame_queue()
4623 type = Q_NEXT_TYPE(fotg210, q.itd->hw_next); in scan_frame_queue()
4625 modified = itd_complete(fotg210, q.itd); in scan_frame_queue()
4629 fotg210_dbg(fotg210, "corrupt type %d frame %d shadow %p\n", in scan_frame_queue()
4640 if (unlikely(modified && fotg210->isoc_count > 0)) in scan_frame_queue()
4646 static void scan_isoc(struct fotg210_hcd *fotg210) in scan_isoc() argument
4649 unsigned fmask = fotg210->periodic_size - 1; in scan_isoc()
4657 if (fotg210->rh_state >= FOTG210_RH_RUNNING) { in scan_isoc()
4658 uf = fotg210_read_frame_index(fotg210); in scan_isoc()
4662 now_frame = (fotg210->next_frame - 1) & fmask; in scan_isoc()
4665 fotg210->now_frame = now_frame; in scan_isoc()
4667 frame = fotg210->next_frame; in scan_isoc()
4671 ret = scan_frame_queue(fotg210, frame, in scan_isoc()
4679 fotg210->next_frame = now_frame; in scan_isoc()
4687 struct fotg210_hcd *fotg210; in uframe_periodic_max_show() local
4690 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev))); in uframe_periodic_max_show()
4691 n = scnprintf(buf, PAGE_SIZE, "%d\n", fotg210->uframe_periodic_max); in uframe_periodic_max_show()
4699 struct fotg210_hcd *fotg210; in uframe_periodic_max_store() local
4706 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev))); in uframe_periodic_max_store()
4711 fotg210_info(fotg210, "rejecting invalid request for uframe_periodic_max=%u\n", in uframe_periodic_max_store()
4722 spin_lock_irqsave(&fotg210->lock, flags); in uframe_periodic_max_store()
4729 if (uframe_periodic_max < fotg210->uframe_periodic_max) { in uframe_periodic_max_store()
4732 for (frame = 0; frame < fotg210->periodic_size; ++frame) in uframe_periodic_max_store()
4735 periodic_usecs(fotg210, frame, in uframe_periodic_max_store()
4739 fotg210_info(fotg210, in uframe_periodic_max_store()
4748 fotg210_info(fotg210, in uframe_periodic_max_store()
4753 fotg210_warn(fotg210, "max periodic bandwidth set is non-standard\n"); in uframe_periodic_max_store()
4755 fotg210->uframe_periodic_max = uframe_periodic_max; in uframe_periodic_max_store()
4759 spin_unlock_irqrestore(&fotg210->lock, flags); in uframe_periodic_max_store()
4765 static inline int create_sysfs_files(struct fotg210_hcd *fotg210) in create_sysfs_files() argument
4767 struct device *controller = fotg210_to_hcd(fotg210)->self.controller; in create_sysfs_files()
4772 static inline void remove_sysfs_files(struct fotg210_hcd *fotg210) in remove_sysfs_files() argument
4774 struct device *controller = fotg210_to_hcd(fotg210)->self.controller; in remove_sysfs_files()
4782 static void fotg210_turn_off_all_ports(struct fotg210_hcd *fotg210) in fotg210_turn_off_all_ports() argument
4784 u32 __iomem *status_reg = &fotg210->regs->port_status; in fotg210_turn_off_all_ports()
4786 fotg210_writel(fotg210, PORT_RWC_BITS, status_reg); in fotg210_turn_off_all_ports()
4792 static void fotg210_silence_controller(struct fotg210_hcd *fotg210) in fotg210_silence_controller() argument
4794 fotg210_halt(fotg210); in fotg210_silence_controller()
4796 spin_lock_irq(&fotg210->lock); in fotg210_silence_controller()
4797 fotg210->rh_state = FOTG210_RH_HALTED; in fotg210_silence_controller()
4798 fotg210_turn_off_all_ports(fotg210); in fotg210_silence_controller()
4799 spin_unlock_irq(&fotg210->lock); in fotg210_silence_controller()
4808 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_shutdown() local
4810 spin_lock_irq(&fotg210->lock); in fotg210_shutdown()
4811 fotg210->shutdown = true; in fotg210_shutdown()
4812 fotg210->rh_state = FOTG210_RH_STOPPING; in fotg210_shutdown()
4813 fotg210->enabled_hrtimer_events = 0; in fotg210_shutdown()
4814 spin_unlock_irq(&fotg210->lock); in fotg210_shutdown()
4816 fotg210_silence_controller(fotg210); in fotg210_shutdown()
4818 hrtimer_cancel(&fotg210->hrtimer); in fotg210_shutdown()
4824 static void fotg210_work(struct fotg210_hcd *fotg210) in fotg210_work() argument
4830 if (fotg210->scanning) { in fotg210_work()
4831 fotg210->need_rescan = true; in fotg210_work()
4834 fotg210->scanning = true; in fotg210_work()
4837 fotg210->need_rescan = false; in fotg210_work()
4838 if (fotg210->async_count) in fotg210_work()
4839 scan_async(fotg210); in fotg210_work()
4840 if (fotg210->intr_count > 0) in fotg210_work()
4841 scan_intr(fotg210); in fotg210_work()
4842 if (fotg210->isoc_count > 0) in fotg210_work()
4843 scan_isoc(fotg210); in fotg210_work()
4844 if (fotg210->need_rescan) in fotg210_work()
4846 fotg210->scanning = false; in fotg210_work()
4852 turn_on_io_watchdog(fotg210); in fotg210_work()
4859 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_stop() local
4861 fotg210_dbg(fotg210, "stop\n"); in fotg210_stop()
4865 spin_lock_irq(&fotg210->lock); in fotg210_stop()
4866 fotg210->enabled_hrtimer_events = 0; in fotg210_stop()
4867 spin_unlock_irq(&fotg210->lock); in fotg210_stop()
4869 fotg210_quiesce(fotg210); in fotg210_stop()
4870 fotg210_silence_controller(fotg210); in fotg210_stop()
4871 fotg210_reset(fotg210); in fotg210_stop()
4873 hrtimer_cancel(&fotg210->hrtimer); in fotg210_stop()
4874 remove_sysfs_files(fotg210); in fotg210_stop()
4875 remove_debug_files(fotg210); in fotg210_stop()
4878 spin_lock_irq(&fotg210->lock); in fotg210_stop()
4879 end_free_itds(fotg210); in fotg210_stop()
4880 spin_unlock_irq(&fotg210->lock); in fotg210_stop()
4881 fotg210_mem_cleanup(fotg210); in fotg210_stop()
4884 fotg210_dbg(fotg210, "irq normal %ld err %ld iaa %ld (lost %ld)\n", in fotg210_stop()
4885 fotg210->stats.normal, fotg210->stats.error, in fotg210_stop()
4886 fotg210->stats.iaa, fotg210->stats.lost_iaa); in fotg210_stop()
4887 fotg210_dbg(fotg210, "complete %ld unlink %ld\n", in fotg210_stop()
4888 fotg210->stats.complete, fotg210->stats.unlink); in fotg210_stop()
4891 dbg_status(fotg210, "fotg210_stop completed", in fotg210_stop()
4892 fotg210_readl(fotg210, &fotg210->regs->status)); in fotg210_stop()
4898 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in hcd_fotg210_init() local
4904 spin_lock_init(&fotg210->lock); in hcd_fotg210_init()
4909 fotg210->need_io_watchdog = 1; in hcd_fotg210_init()
4911 hrtimer_init(&fotg210->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); in hcd_fotg210_init()
4912 fotg210->hrtimer.function = fotg210_hrtimer_func; in hcd_fotg210_init()
4913 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT; in hcd_fotg210_init()
4915 hcc_params = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in hcd_fotg210_init()
4921 fotg210->uframe_periodic_max = 100; in hcd_fotg210_init()
4927 fotg210->periodic_size = DEFAULT_I_TDPS; in hcd_fotg210_init()
4928 INIT_LIST_HEAD(&fotg210->intr_qh_list); in hcd_fotg210_init()
4929 INIT_LIST_HEAD(&fotg210->cached_itd_list); in hcd_fotg210_init()
4935 fotg210->periodic_size = 1024; in hcd_fotg210_init()
4938 fotg210->periodic_size = 512; in hcd_fotg210_init()
4941 fotg210->periodic_size = 256; in hcd_fotg210_init()
4947 retval = fotg210_mem_init(fotg210, GFP_KERNEL); in hcd_fotg210_init()
4952 fotg210->i_thresh = 2; in hcd_fotg210_init()
4961 fotg210->async->qh_next.qh = NULL; in hcd_fotg210_init()
4962 hw = fotg210->async->hw; in hcd_fotg210_init()
4963 hw->hw_next = QH_NEXT(fotg210, fotg210->async->qh_dma); in hcd_fotg210_init()
4964 hw->hw_info1 = cpu_to_hc32(fotg210, QH_HEAD); in hcd_fotg210_init()
4965 hw->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT); in hcd_fotg210_init()
4966 hw->hw_qtd_next = FOTG210_LIST_END(fotg210); in hcd_fotg210_init()
4967 fotg210->async->qh_state = QH_STATE_LINKED; in hcd_fotg210_init()
4968 hw->hw_alt_next = QTD_NEXT(fotg210, fotg210->async->dummy->qtd_dma); in hcd_fotg210_init()
4987 fotg210_dbg(fotg210, "park %d\n", park); in hcd_fotg210_init()
4994 fotg210->command = temp; in hcd_fotg210_init()
5005 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_run() local
5013 fotg210_writel(fotg210, fotg210->periodic_dma, in fotg210_run()
5014 &fotg210->regs->frame_list); in fotg210_run()
5015 fotg210_writel(fotg210, (u32)fotg210->async->qh_dma, in fotg210_run()
5016 &fotg210->regs->async_next); in fotg210_run()
5030 hcc_params = fotg210_readl(fotg210, &fotg210->caps->hcc_params); in fotg210_run()
5036 fotg210->command &= ~(CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); in fotg210_run()
5037 fotg210->command |= CMD_RUN; in fotg210_run()
5038 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command); in fotg210_run()
5039 dbg_cmd(fotg210, "init", fotg210->command); in fotg210_run()
5056 fotg210->rh_state = FOTG210_RH_RUNNING; in fotg210_run()
5058 fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_run()
5061 fotg210->last_periodic_enable = ktime_get_real(); in fotg210_run()
5063 temp = HC_VERSION(fotg210, in fotg210_run()
5064 fotg210_readl(fotg210, &fotg210->caps->hc_capbase)); in fotg210_run()
5065 fotg210_info(fotg210, in fotg210_run()
5067 ((fotg210->sbrn & 0xf0) >> 4), (fotg210->sbrn & 0x0f), in fotg210_run()
5070 fotg210_writel(fotg210, INTR_MASK, in fotg210_run()
5071 &fotg210->regs->intr_enable); /* Turn On Interrupts */ in fotg210_run()
5077 create_debug_files(fotg210); in fotg210_run()
5078 create_sysfs_files(fotg210); in fotg210_run()
5085 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_setup() local
5088 fotg210->regs = (void __iomem *)fotg210->caps + in fotg210_setup()
5089 HC_LENGTH(fotg210, in fotg210_setup()
5090 fotg210_readl(fotg210, &fotg210->caps->hc_capbase)); in fotg210_setup()
5091 dbg_hcs_params(fotg210, "reset"); in fotg210_setup()
5092 dbg_hcc_params(fotg210, "reset"); in fotg210_setup()
5095 fotg210->hcs_params = fotg210_readl(fotg210, in fotg210_setup()
5096 &fotg210->caps->hcs_params); in fotg210_setup()
5098 fotg210->sbrn = HCD_USB2; in fotg210_setup()
5105 retval = fotg210_halt(fotg210); in fotg210_setup()
5109 fotg210_reset(fotg210); in fotg210_setup()
5116 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_irq() local
5120 spin_lock(&fotg210->lock); in fotg210_irq()
5122 status = fotg210_readl(fotg210, &fotg210->regs->status); in fotg210_irq()
5126 fotg210_dbg(fotg210, "device removed\n"); in fotg210_irq()
5138 unlikely(fotg210->rh_state == FOTG210_RH_HALTED)) { in fotg210_irq()
5139 spin_unlock(&fotg210->lock); in fotg210_irq()
5144 fotg210_writel(fotg210, masked_status, &fotg210->regs->status); in fotg210_irq()
5145 cmd = fotg210_readl(fotg210, &fotg210->regs->command); in fotg210_irq()
5149 dbg_status(fotg210, "irq", status); in fotg210_irq()
5156 COUNT(fotg210->stats.normal); in fotg210_irq()
5158 COUNT(fotg210->stats.error); in fotg210_irq()
5166 fotg210->enabled_hrtimer_events &= in fotg210_irq()
5176 if (fotg210->next_hrtimer_event == FOTG210_HRTIMER_IAA_WATCHDOG) in fotg210_irq()
5177 ++fotg210->next_hrtimer_event; in fotg210_irq()
5181 fotg210_dbg(fotg210, "IAA with IAAD still set?\n"); in fotg210_irq()
5182 if (fotg210->async_iaa) { in fotg210_irq()
5183 COUNT(fotg210->stats.iaa); in fotg210_irq()
5184 end_unlink_async(fotg210); in fotg210_irq()
5186 fotg210_dbg(fotg210, "IAA with nothing unlinked?\n"); in fotg210_irq()
5192 u32 __iomem *status_reg = &fotg210->regs->port_status; in fotg210_irq()
5198 if (fotg210->rh_state == FOTG210_RH_SUSPENDED) in fotg210_irq()
5201 pstatus = fotg210_readl(fotg210, status_reg); in fotg210_irq()
5203 if (test_bit(0, &fotg210->suspended_ports) && in fotg210_irq()
5207 fotg210->reset_done[0] == 0) { in fotg210_irq()
5214 fotg210->reset_done[0] = jiffies + msecs_to_jiffies(25); in fotg210_irq()
5215 set_bit(0, &fotg210->resuming_ports); in fotg210_irq()
5216 fotg210_dbg(fotg210, "port 1 remote wakeup\n"); in fotg210_irq()
5217 mod_timer(&hcd->rh_timer, fotg210->reset_done[0]); in fotg210_irq()
5223 fotg210_err(fotg210, "fatal error\n"); in fotg210_irq()
5224 dbg_cmd(fotg210, "fatal", cmd); in fotg210_irq()
5225 dbg_status(fotg210, "fatal", status); in fotg210_irq()
5230 fotg210->shutdown = true; in fotg210_irq()
5231 fotg210->rh_state = FOTG210_RH_STOPPING; in fotg210_irq()
5232 fotg210->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE); in fotg210_irq()
5233 fotg210_writel(fotg210, fotg210->command, in fotg210_irq()
5234 &fotg210->regs->command); in fotg210_irq()
5235 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable); in fotg210_irq()
5236 fotg210_handle_controller_death(fotg210); in fotg210_irq()
5243 fotg210_work(fotg210); in fotg210_irq()
5244 spin_unlock(&fotg210->lock); in fotg210_irq()
5264 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_urb_enqueue() local
5279 if (!qh_urb_transaction(fotg210, urb, &qtd_list, mem_flags)) in fotg210_urb_enqueue()
5281 return submit_async(fotg210, urb, &qtd_list, mem_flags); in fotg210_urb_enqueue()
5284 if (!qh_urb_transaction(fotg210, urb, &qtd_list, mem_flags)) in fotg210_urb_enqueue()
5286 return intr_submit(fotg210, urb, &qtd_list, mem_flags); in fotg210_urb_enqueue()
5289 return itd_submit(fotg210, urb, mem_flags); in fotg210_urb_enqueue()
5299 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_urb_dequeue() local
5304 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_urb_dequeue()
5319 start_unlink_async(fotg210, qh); in fotg210_urb_dequeue()
5327 qh_completions(fotg210, qh); in fotg210_urb_dequeue()
5339 start_unlink_intr(fotg210, qh); in fotg210_urb_dequeue()
5342 qh_completions(fotg210, qh); in fotg210_urb_dequeue()
5345 fotg210_dbg(fotg210, "bogus qh %p state %d\n", in fotg210_urb_dequeue()
5359 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_urb_dequeue()
5368 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_endpoint_disable() local
5376 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_endpoint_disable()
5395 if (fotg210->rh_state < FOTG210_RH_RUNNING) in fotg210_endpoint_disable()
5400 for (tmp = fotg210->async->qh_next.qh; in fotg210_endpoint_disable()
5408 start_unlink_async(fotg210, qh); in fotg210_endpoint_disable()
5413 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_endpoint_disable()
5420 qh_destroy(fotg210, qh); in fotg210_endpoint_disable()
5428 fotg210_err(fotg210, "qh %p (#%02x) state %d%s\n", in fotg210_endpoint_disable()
5435 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_endpoint_disable()
5441 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_endpoint_reset() local
5451 spin_lock_irqsave(&fotg210->lock, flags); in fotg210_endpoint_reset()
5471 start_unlink_async(fotg210, qh); in fotg210_endpoint_reset()
5473 start_unlink_intr(fotg210, qh); in fotg210_endpoint_reset()
5476 spin_unlock_irqrestore(&fotg210->lock, flags); in fotg210_endpoint_reset()
5481 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); in fotg210_get_frame() local
5483 return (fotg210_read_frame_index(fotg210) >> 3) % in fotg210_get_frame()
5484 fotg210->periodic_size; in fotg210_get_frame()
5542 static void fotg210_init(struct fotg210_hcd *fotg210) in fotg210_init() argument
5547 &fotg210->regs->gmir); in fotg210_init()
5549 value = ioread32(&fotg210->regs->otgcsr); in fotg210_init()
5552 iowrite32(value, &fotg210->regs->otgcsr); in fotg210_init()
5569 struct fotg210_hcd *fotg210; in fotg210_hcd_probe() local
5605 fotg210 = hcd_to_fotg210(hcd); in fotg210_hcd_probe()
5607 fotg210->caps = hcd->regs; in fotg210_hcd_probe()
5613 fotg210_init(fotg210); in fotg210_hcd_probe()