Lines Matching defs:fotg210

80 #include "fotg210.h"
82 #define fotg210_dbg(fotg210, fmt, args...) \
83 dev_dbg(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
84 #define fotg210_err(fotg210, fmt, args...) \
85 dev_err(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
86 #define fotg210_info(fotg210, fmt, args...) \
87 dev_info(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
88 #define fotg210_warn(fotg210, fmt, args...) \
89 dev_warn(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
94 static void dbg_hcs_params(struct fotg210_hcd *fotg210, char *label)
96 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcs_params);
98 fotg210_dbg(fotg210, "%s hcs_params 0x%x ports=%d\n", label, params,
105 static void dbg_hcc_params(struct fotg210_hcd *fotg210, char *label)
107 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
109 fotg210_dbg(fotg210, "%s hcc_params %04x uframes %s%s\n", label,
116 dbg_qtd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd)
118 fotg210_dbg(fotg210, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
119 hc32_to_cpup(fotg210, &qtd->hw_next),
120 hc32_to_cpup(fotg210, &qtd->hw_alt_next),
121 hc32_to_cpup(fotg210, &qtd->hw_token),
122 hc32_to_cpup(fotg210, &qtd->hw_buf[0]));
124 fotg210_dbg(fotg210, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
125 hc32_to_cpup(fotg210, &qtd->hw_buf[1]),
126 hc32_to_cpup(fotg210, &qtd->hw_buf[2]),
127 hc32_to_cpup(fotg210, &qtd->hw_buf[3]),
128 hc32_to_cpup(fotg210, &qtd->hw_buf[4]));
132 dbg_qh(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
136 fotg210_dbg(fotg210, "%s qh %p n%08x info %x %x qtd %x\n", label, qh,
140 dbg_qtd("overlay", fotg210, (struct fotg210_qtd *) &hw->hw_qtd_next);
144 dbg_itd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_itd *itd)
146 fotg210_dbg(fotg210, "%s[%d] itd %p, next %08x, urb %p\n", label,
147 itd->frame, itd, hc32_to_cpu(fotg210, itd->hw_next),
150 fotg210_dbg(fotg210,
152 hc32_to_cpu(fotg210, itd->hw_transaction[0]),
153 hc32_to_cpu(fotg210, itd->hw_transaction[1]),
154 hc32_to_cpu(fotg210, itd->hw_transaction[2]),
155 hc32_to_cpu(fotg210, itd->hw_transaction[3]),
156 hc32_to_cpu(fotg210, itd->hw_transaction[4]),
157 hc32_to_cpu(fotg210, itd->hw_transaction[5]),
158 hc32_to_cpu(fotg210, itd->hw_transaction[6]),
159 hc32_to_cpu(fotg210, itd->hw_transaction[7]));
161 fotg210_dbg(fotg210,
163 hc32_to_cpu(fotg210, itd->hw_bufp[0]),
164 hc32_to_cpu(fotg210, itd->hw_bufp[1]),
165 hc32_to_cpu(fotg210, itd->hw_bufp[2]),
166 hc32_to_cpu(fotg210, itd->hw_bufp[3]),
167 hc32_to_cpu(fotg210, itd->hw_bufp[4]),
168 hc32_to_cpu(fotg210, itd->hw_bufp[5]),
169 hc32_to_cpu(fotg210, itd->hw_bufp[6]));
171 fotg210_dbg(fotg210, " index: %d %d %d %d %d %d %d %d\n",
263 #define dbg_status(fotg210, label, status) { \
266 fotg210_dbg(fotg210, "%s\n", _buf); \
269 #define dbg_cmd(fotg210, label, command) { \
272 fotg210_dbg(fotg210, "%s\n", _buf); \
275 #define dbg_port(fotg210, label, port, status) { \
277 fotg210_dbg(fotg210, "%s\n", \
340 static inline char token_mark(struct fotg210_hcd *fotg210, __hc32 token)
342 __u32 v = hc32_to_cpu(fotg210, token);
354 static void qh_lines(struct fotg210_hcd *fotg210, struct fotg210_qh *qh,
364 __le32 list_end = FOTG210_LIST_END(fotg210);
370 mark = token_mark(fotg210, hw->hw_token);
372 if ((hw->hw_alt_next & QTD_MASK(fotg210)) ==
373 fotg210->async->hw->hw_alt_next)
379 scratch = hc32_to_cpup(fotg210, &hw->hw_info1);
380 hw_curr = (mark == '*') ? hc32_to_cpup(fotg210, &hw->hw_current) : 0;
386 scratch, hc32_to_cpup(fotg210, &hw->hw_info2),
387 hc32_to_cpup(fotg210, &hw->hw_token), mark,
388 (cpu_to_hc32(fotg210, QTD_TOGGLE) & hw->hw_token)
390 (hc32_to_cpup(fotg210, &hw->hw_alt_next) >> 1) & 0x0f);
396 scratch = hc32_to_cpup(fotg210, &td->hw_token);
400 else if (hw->hw_qtd_next == cpu_to_hc32(fotg210, td->qtd_dma))
403 if (td->hw_alt_next == fotg210->async->hw->hw_alt_next)
448 struct fotg210_hcd *fotg210;
455 fotg210 = hcd_to_fotg210(hcd);
465 spin_lock_irqsave(&fotg210->lock, flags);
466 for (qh = fotg210->async->qh_next.qh; size > 0 && qh;
468 qh_lines(fotg210, qh, &next, &size);
469 if (fotg210->async_unlink && size > 0) {
474 for (qh = fotg210->async_unlink; size > 0 && qh;
476 qh_lines(fotg210, qh, &next, &size);
478 spin_unlock_irqrestore(&fotg210->lock, flags);
484 static unsigned output_buf_tds_dir(char *buf, struct fotg210_hcd *fotg210,
487 u32 scratch = hc32_to_cpup(fotg210, &hw->hw_info1);
495 switch ((hc32_to_cpu(fotg210, qtd->hw_token) >> 8) & 0x03) {
515 struct fotg210_hcd *fotg210;
530 fotg210 = hcd_to_fotg210(hcd);
534 temp = scnprintf(next, size, "size = %d\n", fotg210->periodic_size);
541 spin_lock_irqsave(&fotg210->lock, flags);
542 for (i = 0; i < fotg210->periodic_size; i++) {
543 p = fotg210->pshadow[i];
547 tag = Q_NEXT_TYPE(fotg210, fotg210->periodic[i]);
556 switch (hc32_to_cpu(fotg210, tag)) {
561 hc32_to_cpup(fotg210,
583 fotg210, hw,
590 tag = Q_NEXT_TYPE(fotg210, hw->hw_next);
597 tag = Q_NEXT_TYPE(fotg210, p.fstn->hw_next);
603 tag = Q_NEXT_TYPE(fotg210, p.itd->hw_next);
615 spin_unlock_irqrestore(&fotg210->lock, flags);
622 static const char *rh_state_string(struct fotg210_hcd *fotg210)
624 switch (fotg210->rh_state) {
640 struct fotg210_hcd *fotg210;
648 fotg210 = hcd_to_fotg210(hcd);
652 spin_lock_irqsave(&fotg210->lock, flags);
666 i = HC_VERSION(fotg210, fotg210_readl(fotg210,
667 &fotg210->caps->hc_capbase));
675 i >> 8, i & 0x0ff, rh_state_string(fotg210));
680 i = fotg210_readl(fotg210, &fotg210->caps->hcs_params);
685 i = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
692 fotg210_readl(fotg210, &fotg210->regs->status));
698 fotg210_readl(fotg210, &fotg210->regs->command));
704 fotg210_readl(fotg210, &fotg210->regs->intr_enable));
710 fotg210_read_frame_index(fotg210));
714 if (fotg210->async_unlink) {
716 fotg210->async_unlink);
724 fotg210->stats.normal, fotg210->stats.error,
725 fotg210->stats.iaa, fotg210->stats.lost_iaa);
730 fotg210->stats.complete, fotg210->stats.unlink);
736 spin_unlock_irqrestore(&fotg210->lock, flags);
844 static inline void create_debug_files(struct fotg210_hcd *fotg210)
846 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self;
850 fotg210->debug_dir = root;
859 static inline void remove_debug_files(struct fotg210_hcd *fotg210)
861 debugfs_remove_recursive(fotg210->debug_dir);
880 static int handshake(struct fotg210_hcd *fotg210, void __iomem *ptr,
898 static int fotg210_halt(struct fotg210_hcd *fotg210)
902 spin_lock_irq(&fotg210->lock);
905 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable);
908 * This routine gets called during probe before fotg210->command
911 fotg210->command &= ~CMD_RUN;
912 temp = fotg210_readl(fotg210, &fotg210->regs->command);
914 fotg210_writel(fotg210, temp, &fotg210->regs->command);
916 spin_unlock_irq(&fotg210->lock);
917 synchronize_irq(fotg210_to_hcd(fotg210)->irq);
919 return handshake(fotg210, &fotg210->regs->status,
926 static int fotg210_reset(struct fotg210_hcd *fotg210)
929 u32 command = fotg210_readl(fotg210, &fotg210->regs->command);
934 if (fotg210->debug && !dbgp_reset_prep(fotg210_to_hcd(fotg210)))
935 fotg210->debug = NULL;
938 dbg_cmd(fotg210, "reset", command);
939 fotg210_writel(fotg210, command, &fotg210->regs->command);
940 fotg210->rh_state = FOTG210_RH_HALTED;
941 fotg210->next_statechange = jiffies;
942 retval = handshake(fotg210, &fotg210->regs->command,
948 if (fotg210->debug)
949 dbgp_external_startup(fotg210_to_hcd(fotg210));
951 fotg210->port_c_suspend = fotg210->suspended_ports =
952 fotg210->resuming_ports = 0;
959 static void fotg210_quiesce(struct fotg210_hcd *fotg210)
963 if (fotg210->rh_state != FOTG210_RH_RUNNING)
967 temp = (fotg210->command << 10) & (STS_ASS | STS_PSS);
968 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, temp,
972 spin_lock_irq(&fotg210->lock);
973 fotg210->command &= ~(CMD_ASE | CMD_PSE);
974 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
975 spin_unlock_irq(&fotg210->lock);
978 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, 0,
982 static void end_unlink_async(struct fotg210_hcd *fotg210);
983 static void unlink_empty_async(struct fotg210_hcd *fotg210);
984 static void fotg210_work(struct fotg210_hcd *fotg210);
985 static void start_unlink_intr(struct fotg210_hcd *fotg210,
987 static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
990 static void fotg210_set_command_bit(struct fotg210_hcd *fotg210, u32 bit)
992 fotg210->command |= bit;
993 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
996 fotg210_readl(fotg210, &fotg210->regs->command);
1000 static void fotg210_clear_command_bit(struct fotg210_hcd *fotg210, u32 bit)
1002 fotg210->command &= ~bit;
1003 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
1006 fotg210_readl(fotg210, &fotg210->regs->command);
1011 * Lots of different events are triggered from fotg210->hrtimer. Whenever
1015 * fotg210->enabled_hrtimer_events, and they are numbered in order of
1020 * fotg210->next_hrtimer_event. Whenever fotg210->hrtimer gets restarted, its
1033 * the event types indexed by enum fotg210_hrtimer_event in fotg210.h.
1049 static void fotg210_enable_event(struct fotg210_hcd *fotg210, unsigned event,
1052 ktime_t *timeout = &fotg210->hr_timeouts[event];
1056 fotg210->enabled_hrtimer_events |= (1 << event);
1059 if (event < fotg210->next_hrtimer_event) {
1060 fotg210->next_hrtimer_event = event;
1061 hrtimer_start_range_ns(&fotg210->hrtimer, *timeout,
1068 static void fotg210_poll_ASS(struct fotg210_hcd *fotg210)
1073 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1076 want = (fotg210->command & CMD_ASE) ? STS_ASS : 0;
1077 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_ASS;
1082 if (fotg210->ASS_poll_count++ < 20) {
1083 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_ASS,
1087 fotg210_dbg(fotg210, "Waited too long for the async schedule status (%x/%x), giving up\n",
1090 fotg210->ASS_poll_count = 0;
1094 if (fotg210->async_count > 0)
1095 fotg210_set_command_bit(fotg210, CMD_ASE);
1098 if (fotg210->async_count == 0) {
1101 fotg210_enable_event(fotg210,
1109 static void fotg210_disable_ASE(struct fotg210_hcd *fotg210)
1111 fotg210_clear_command_bit(fotg210, CMD_ASE);
1116 static void fotg210_poll_PSS(struct fotg210_hcd *fotg210)
1121 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1124 want = (fotg210->command & CMD_PSE) ? STS_PSS : 0;
1125 actual = fotg210_readl(fotg210, &fotg210->regs->status) & STS_PSS;
1130 if (fotg210->PSS_poll_count++ < 20) {
1131 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_PSS,
1135 fotg210_dbg(fotg210, "Waited too long for the periodic schedule status (%x/%x), giving up\n",
1138 fotg210->PSS_poll_count = 0;
1142 if (fotg210->periodic_count > 0)
1143 fotg210_set_command_bit(fotg210, CMD_PSE);
1146 if (fotg210->periodic_count == 0) {
1149 fotg210_enable_event(fotg210,
1157 static void fotg210_disable_PSE(struct fotg210_hcd *fotg210)
1159 fotg210_clear_command_bit(fotg210, CMD_PSE);
1164 static void fotg210_handle_controller_death(struct fotg210_hcd *fotg210)
1166 if (!(fotg210_readl(fotg210, &fotg210->regs->status) & STS_HALT)) {
1169 if (fotg210->died_poll_count++ < 5) {
1171 fotg210_enable_event(fotg210,
1175 fotg210_warn(fotg210, "Waited too long for the controller to stop, giving up\n");
1179 fotg210->rh_state = FOTG210_RH_HALTED;
1180 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable);
1181 fotg210_work(fotg210);
1182 end_unlink_async(fotg210);
1189 static void fotg210_handle_intr_unlinks(struct fotg210_hcd *fotg210)
1191 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING);
1200 fotg210->intr_unlinking = true;
1201 while (fotg210->intr_unlink) {
1202 struct fotg210_qh *qh = fotg210->intr_unlink;
1204 if (!stopped && qh->unlink_cycle == fotg210->intr_unlink_cycle)
1206 fotg210->intr_unlink = qh->unlink_next;
1208 end_unlink_intr(fotg210, qh);
1212 if (fotg210->intr_unlink) {
1213 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR,
1215 ++fotg210->intr_unlink_cycle;
1217 fotg210->intr_unlinking = false;
1222 static void start_free_itds(struct fotg210_hcd *fotg210)
1224 if (!(fotg210->enabled_hrtimer_events &
1226 fotg210->last_itd_to_free = list_entry(
1227 fotg210->cached_itd_list.prev,
1229 fotg210_enable_event(fotg210, FOTG210_HRTIMER_FREE_ITDS, true);
1234 static void end_free_itds(struct fotg210_hcd *fotg210)
1238 if (fotg210->rh_state < FOTG210_RH_RUNNING)
1239 fotg210->last_itd_to_free = NULL;
1241 list_for_each_entry_safe(itd, n, &fotg210->cached_itd_list, itd_list) {
1243 dma_pool_free(fotg210->itd_pool, itd, itd->itd_dma);
1244 if (itd == fotg210->last_itd_to_free)
1248 if (!list_empty(&fotg210->cached_itd_list))
1249 start_free_itds(fotg210);
1254 static void fotg210_iaa_watchdog(struct fotg210_hcd *fotg210)
1256 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1265 if (fotg210->async_iaa) {
1274 cmd = fotg210_readl(fotg210, &fotg210->regs->command);
1283 status = fotg210_readl(fotg210, &fotg210->regs->status);
1285 INCR(fotg210->stats.lost_iaa);
1286 fotg210_writel(fotg210, STS_IAA,
1287 &fotg210->regs->status);
1290 fotg210_dbg(fotg210, "IAA watchdog: status %x cmd %x\n",
1292 end_unlink_async(fotg210);
1298 static void turn_on_io_watchdog(struct fotg210_hcd *fotg210)
1301 if (fotg210->rh_state != FOTG210_RH_RUNNING ||
1302 (fotg210->enabled_hrtimer_events &
1310 if (fotg210->isoc_count > 0 || (fotg210->need_io_watchdog &&
1311 fotg210->async_count + fotg210->intr_count > 0))
1312 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IO_WATCHDOG,
1319 * enum fotg210_hrtimer_event in fotg210.h.
1336 struct fotg210_hcd *fotg210 =
1343 spin_lock_irqsave(&fotg210->lock, flags);
1345 events = fotg210->enabled_hrtimer_events;
1346 fotg210->enabled_hrtimer_events = 0;
1347 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT;
1355 if (ktime_compare(now, fotg210->hr_timeouts[e]) >= 0)
1356 event_handlers[e](fotg210);
1358 fotg210_enable_event(fotg210, e, false);
1361 spin_unlock_irqrestore(&fotg210->lock, flags);
1368 static int check_reset_complete(struct fotg210_hcd *fotg210, int index,
1377 fotg210_dbg(fotg210, "Failed to enable port %d on root hub TT\n",
1380 fotg210_dbg(fotg210, "port %d reset complete, port enabled\n",
1391 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
1403 status = fotg210->resuming_ports;
1411 spin_lock_irqsave(&fotg210->lock, flags);
1413 temp = fotg210_readl(fotg210, &fotg210->regs->port_status);
1422 if ((temp & mask) != 0 || test_bit(0, &fotg210->port_c_suspend) ||
1423 (fotg210->reset_done[0] &&
1424 time_after_eq(jiffies, fotg210->reset_done[0]))) {
1429 spin_unlock_irqrestore(&fotg210->lock, flags);
1433 static void fotg210_hub_descriptor(struct fotg210_hcd *fotg210,
1436 int ports = HCS_N_PORTS(fotg210->hcs_params);
1440 desc->bPwrOn2PwrGood = 10; /* fotg210 1.0, 2.3.9 says 20ms max */
1459 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
1460 int ports = HCS_N_PORTS(fotg210->hcs_params);
1461 u32 __iomem *status_reg = &fotg210->regs->port_status;
1474 spin_lock_irqsave(&fotg210->lock, flags);
1490 temp = fotg210_readl(fotg210, status_reg);
1502 fotg210_writel(fotg210, temp & ~PORT_PE, status_reg);
1505 fotg210_writel(fotg210, temp | PORT_PEC, status_reg);
1516 fotg210_writel(fotg210, temp | PORT_RESUME, status_reg);
1517 fotg210->reset_done[wIndex] = jiffies
1521 clear_bit(wIndex, &fotg210->port_c_suspend);
1524 fotg210_writel(fotg210, temp | PORT_CSC, status_reg);
1527 fotg210_writel(fotg210, temp | OTGISR_OVC,
1528 &fotg210->regs->otgisr);
1536 fotg210_readl(fotg210, &fotg210->regs->command);
1539 fotg210_hub_descriptor(fotg210, (struct usb_hub_descriptor *)
1552 temp = fotg210_readl(fotg210, status_reg);
1560 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr);
1568 if (!fotg210->reset_done[wIndex]) {
1570 fotg210->reset_done[wIndex] = jiffies
1573 mod_timer(&fotg210_to_hcd(fotg210)->rh_timer,
1574 fotg210->reset_done[wIndex]);
1579 fotg210->reset_done[wIndex])) {
1580 clear_bit(wIndex, &fotg210->suspended_ports);
1581 set_bit(wIndex, &fotg210->port_c_suspend);
1582 fotg210->reset_done[wIndex] = 0;
1585 temp = fotg210_readl(fotg210, status_reg);
1586 fotg210_writel(fotg210, temp &
1589 clear_bit(wIndex, &fotg210->resuming_ports);
1590 retval = handshake(fotg210, status_reg,
1593 fotg210_err(fotg210,
1604 fotg210->reset_done[wIndex])) {
1606 fotg210->reset_done[wIndex] = 0;
1607 clear_bit(wIndex, &fotg210->resuming_ports);
1610 fotg210_writel(fotg210,
1616 retval = handshake(fotg210, status_reg,
1619 fotg210_err(fotg210, "port %d reset error %d\n",
1625 temp = check_reset_complete(fotg210, wIndex, status_reg,
1626 fotg210_readl(fotg210, status_reg));
1629 fotg210->command |= CMD_RUN;
1630 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
1634 fotg210->reset_done[wIndex] = 0;
1635 clear_bit(wIndex, &fotg210->resuming_ports);
1640 test_bit(wIndex, &fotg210->companion_ports)) {
1642 fotg210_writel(fotg210, temp, status_reg);
1643 fotg210_dbg(fotg210, "port %d --> companion\n",
1645 temp = fotg210_readl(fotg210, status_reg);
1656 status |= fotg210_port_speed(fotg210, temp);
1664 } else if (test_bit(wIndex, &fotg210->suspended_ports)) {
1665 clear_bit(wIndex, &fotg210->suspended_ports);
1666 clear_bit(wIndex, &fotg210->resuming_ports);
1667 fotg210->reset_done[wIndex] = 0;
1669 set_bit(wIndex, &fotg210->port_c_suspend);
1672 temp1 = fotg210_readl(fotg210, &fotg210->regs->otgisr);
1677 if (test_bit(wIndex, &fotg210->port_c_suspend))
1681 dbg_port(fotg210, "GetStatus", wIndex + 1, temp);
1701 temp = fotg210_readl(fotg210, status_reg);
1713 fotg210_writel(fotg210, temp | PORT_SUSPEND,
1715 set_bit(wIndex, &fotg210->suspended_ports);
1724 fotg210_dbg(fotg210, "port %d reset\n", wIndex + 1);
1732 fotg210->reset_done[wIndex] = jiffies
1734 fotg210_writel(fotg210, temp, status_reg);
1746 spin_unlock_irqrestore(&fotg210->lock, flags);
1747 fotg210_quiesce(fotg210);
1748 spin_lock_irqsave(&fotg210->lock, flags);
1751 temp = fotg210_readl(fotg210, status_reg) &
1754 fotg210_writel(fotg210, temp | PORT_SUSPEND,
1757 spin_unlock_irqrestore(&fotg210->lock, flags);
1758 fotg210_halt(fotg210);
1759 spin_lock_irqsave(&fotg210->lock, flags);
1761 temp = fotg210_readl(fotg210, status_reg);
1763 fotg210_writel(fotg210, temp, status_reg);
1769 fotg210_readl(fotg210, &fotg210->regs->command);
1777 spin_unlock_irqrestore(&fotg210->lock, flags);
1804 static inline void fotg210_qtd_init(struct fotg210_hcd *fotg210,
1809 qtd->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT);
1810 qtd->hw_next = FOTG210_LIST_END(fotg210);
1811 qtd->hw_alt_next = FOTG210_LIST_END(fotg210);
1815 static struct fotg210_qtd *fotg210_qtd_alloc(struct fotg210_hcd *fotg210,
1821 qtd = dma_pool_alloc(fotg210->qtd_pool, flags, &dma);
1823 fotg210_qtd_init(fotg210, qtd, dma);
1828 static inline void fotg210_qtd_free(struct fotg210_hcd *fotg210,
1831 dma_pool_free(fotg210->qtd_pool, qtd, qtd->qtd_dma);
1835 static void qh_destroy(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
1839 fotg210_dbg(fotg210, "unused qh not empty!\n");
1843 fotg210_qtd_free(fotg210, qh->dummy);
1844 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma);
1848 static struct fotg210_qh *fotg210_qh_alloc(struct fotg210_hcd *fotg210,
1857 qh->hw = dma_pool_zalloc(fotg210->qh_pool, flags, &dma);
1864 qh->dummy = fotg210_qtd_alloc(fotg210, flags);
1866 fotg210_dbg(fotg210, "no dummy td\n");
1872 dma_pool_free(fotg210->qh_pool, qh->hw, qh->qh_dma);
1883 static void fotg210_mem_cleanup(struct fotg210_hcd *fotg210)
1885 if (fotg210->async)
1886 qh_destroy(fotg210, fotg210->async);
1887 fotg210->async = NULL;
1889 if (fotg210->dummy)
1890 qh_destroy(fotg210, fotg210->dummy);
1891 fotg210->dummy = NULL;
1894 dma_pool_destroy(fotg210->qtd_pool);
1895 fotg210->qtd_pool = NULL;
1897 dma_pool_destroy(fotg210->qh_pool);
1898 fotg210->qh_pool = NULL;
1900 dma_pool_destroy(fotg210->itd_pool);
1901 fotg210->itd_pool = NULL;
1903 if (fotg210->periodic)
1904 dma_free_coherent(fotg210_to_hcd(fotg210)->self.controller,
1905 fotg210->periodic_size * sizeof(u32),
1906 fotg210->periodic, fotg210->periodic_dma);
1907 fotg210->periodic = NULL;
1910 kfree(fotg210->pshadow);
1911 fotg210->pshadow = NULL;
1915 static int fotg210_mem_init(struct fotg210_hcd *fotg210, gfp_t flags)
1920 fotg210->qtd_pool = dma_pool_create("fotg210_qtd",
1921 fotg210_to_hcd(fotg210)->self.controller,
1925 if (!fotg210->qtd_pool)
1929 fotg210->qh_pool = dma_pool_create("fotg210_qh",
1930 fotg210_to_hcd(fotg210)->self.controller,
1934 if (!fotg210->qh_pool)
1937 fotg210->async = fotg210_qh_alloc(fotg210, flags);
1938 if (!fotg210->async)
1942 fotg210->itd_pool = dma_pool_create("fotg210_itd",
1943 fotg210_to_hcd(fotg210)->self.controller,
1947 if (!fotg210->itd_pool)
1951 fotg210->periodic = (__le32 *)
1952 dma_alloc_coherent(fotg210_to_hcd(fotg210)->self.controller,
1953 fotg210->periodic_size * sizeof(__le32),
1954 &fotg210->periodic_dma, 0);
1955 if (fotg210->periodic == NULL)
1958 for (i = 0; i < fotg210->periodic_size; i++)
1959 fotg210->periodic[i] = FOTG210_LIST_END(fotg210);
1962 fotg210->pshadow = kcalloc(fotg210->periodic_size, sizeof(void *),
1964 if (fotg210->pshadow != NULL)
1968 fotg210_dbg(fotg210, "couldn't init memory\n");
1969 fotg210_mem_cleanup(fotg210);
1990 static int qtd_fill(struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd,
1997 qtd->hw_buf[0] = cpu_to_hc32(fotg210, (u32)addr);
1998 qtd->hw_buf_hi[0] = cpu_to_hc32(fotg210, (u32)(addr >> 32));
2009 qtd->hw_buf[i] = cpu_to_hc32(fotg210, (u32)addr);
2010 qtd->hw_buf_hi[i] = cpu_to_hc32(fotg210,
2023 qtd->hw_token = cpu_to_hc32(fotg210, (count << 16) | token);
2029 static inline void qh_update(struct fotg210_hcd *fotg210,
2037 hw->hw_qtd_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2038 hw->hw_alt_next = FOTG210_LIST_END(fotg210);
2045 if (!(hw->hw_info1 & cpu_to_hc32(fotg210, QH_TOGGLE_CTL))) {
2049 epnum = (hc32_to_cpup(fotg210, &hw->hw_info1) >> 8) & 0x0f;
2051 hw->hw_token &= ~cpu_to_hc32(fotg210, QTD_TOGGLE);
2056 hw->hw_token &= cpu_to_hc32(fotg210, QTD_TOGGLE | QTD_STS_PING);
2063 static void qh_refresh(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2079 if (cpu_to_hc32(fotg210, qtd->qtd_dma) == qh->hw->hw_current) {
2086 qh_update(fotg210, qh, qtd);
2089 static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2094 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
2098 spin_lock_irqsave(&fotg210->lock, flags);
2101 && fotg210->rh_state == FOTG210_RH_RUNNING)
2102 qh_link_async(fotg210, qh);
2103 spin_unlock_irqrestore(&fotg210->lock, flags);
2106 static void fotg210_clear_tt_buffer(struct fotg210_hcd *fotg210,
2125 fotg210_to_hcd(fotg210)->self.root_hub) {
2132 static int qtd_copy_status(struct fotg210_hcd *fotg210, struct urb *urb,
2171 fotg210_dbg(fotg210, "devpath %s ep%d%s 3strikes\n",
2180 fotg210_dbg(fotg210,
2191 static void fotg210_urb_done(struct fotg210_hcd *fotg210, struct urb *urb,
2193 __releases(fotg210->lock)
2194 __acquires(fotg210->lock)
2200 if ((qh->hw->hw_info2 & cpu_to_hc32(fotg210, QH_SMASK)) != 0) {
2203 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs--;
2208 INCR(fotg210->stats.unlink);
2213 INCR(fotg210->stats.complete);
2217 fotg210_dbg(fotg210,
2227 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb);
2228 spin_unlock(&fotg210->lock);
2229 usb_hcd_giveback_urb(fotg210_to_hcd(fotg210), urb, status);
2230 spin_lock(&fotg210->lock);
2233 static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2239 static unsigned qh_completions(struct fotg210_hcd *fotg210,
2286 fotg210_urb_done(fotg210, last->urb,
2291 fotg210_qtd_free(fotg210, last);
2301 token = hc32_to_cpu(fotg210, qtd->hw_token);
2309 fotg210_dbg(fotg210,
2328 fotg210_dbg(fotg210,
2342 qtd->hw_token = cpu_to_hc32(fotg210,
2345 hw->hw_token = cpu_to_hc32(fotg210,
2362 FOTG210_LIST_END(fotg210))) {
2368 && fotg210->rh_state >= FOTG210_RH_RUNNING)) {
2376 if (fotg210->rh_state < FOTG210_RH_RUNNING)
2387 cpu_to_hc32(fotg210, qtd->qtd_dma)
2389 token = hc32_to_cpu(fotg210, hw->hw_token);
2395 fotg210_clear_tt_buffer(fotg210, qh, urb,
2408 last_status = qtd_copy_status(fotg210, urb,
2412 FOTG210_LIST_END(fotg210)))
2430 fotg210_clear_tt_buffer(fotg210, qh,
2454 fotg210_urb_done(fotg210, last->urb, last_status);
2456 fotg210_qtd_free(fotg210, last);
2481 if (stopped != 0 || hw->hw_qtd_next == FOTG210_LIST_END(fotg210)) {
2484 qh_refresh(fotg210, qh);
2512 static void qtd_list_free(struct fotg210_hcd *fotg210, struct urb *urb,
2519 fotg210_qtd_free(fotg210, qtd);
2525 static struct list_head *qh_urb_transaction(struct fotg210_hcd *fotg210,
2539 qtd = fotg210_qtd_alloc(fotg210, flags);
2553 qtd_fill(fotg210, qtd, urb->setup_dma,
2560 qtd = fotg210_qtd_alloc(fotg210, flags);
2564 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2604 this_qtd_len = qtd_fill(fotg210, qtd, buf, this_sg_len, token,
2616 qtd->hw_alt_next = fotg210->async->hw->hw_alt_next;
2631 qtd = fotg210_qtd_alloc(fotg210, flags);
2635 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2646 qtd->hw_alt_next = FOTG210_LIST_END(fotg210);
2667 qtd = fotg210_qtd_alloc(fotg210, flags);
2671 qtd_prev->hw_next = QTD_NEXT(fotg210, qtd->qtd_dma);
2675 qtd_fill(fotg210, qtd, 0, 0, token, 0);
2681 qtd->hw_token |= cpu_to_hc32(fotg210, QTD_IOC);
2685 qtd_list_free(fotg210, urb, head);
2704 static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb,
2707 struct fotg210_qh *qh = fotg210_qh_alloc(fotg210, flags);
2735 fotg210_dbg(fotg210, "bogus qh maxpacket %d\n", maxp);
2763 } else if (qh->period > fotg210->periodic_size) {
2764 qh->period = fotg210->periodic_size;
2788 if (qh->period > fotg210->periodic_size) {
2789 qh->period = fotg210->periodic_size;
2819 if (fotg210_has_fsl_portno_bug(fotg210))
2827 if (tt && tt->hub != fotg210_to_hcd(fotg210)->self.root_hub)
2857 fotg210_dbg(fotg210, "bogus dev %p speed %d\n", urb->dev,
2860 qh_destroy(fotg210, qh);
2869 hw->hw_info1 = cpu_to_hc32(fotg210, info1);
2870 hw->hw_info2 = cpu_to_hc32(fotg210, info2);
2873 qh_refresh(fotg210, qh);
2877 static void enable_async(struct fotg210_hcd *fotg210)
2879 if (fotg210->async_count++)
2883 fotg210->enabled_hrtimer_events &= ~BIT(FOTG210_HRTIMER_DISABLE_ASYNC);
2886 fotg210_poll_ASS(fotg210);
2887 turn_on_io_watchdog(fotg210);
2890 static void disable_async(struct fotg210_hcd *fotg210)
2892 if (--fotg210->async_count)
2896 WARN_ON(fotg210->async->qh_next.qh || fotg210->async_unlink);
2899 fotg210_poll_ASS(fotg210);
2904 static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2906 __hc32 dma = QH_NEXT(fotg210, qh->qh_dma);
2916 qh_refresh(fotg210, qh);
2919 head = fotg210->async;
2931 enable_async(fotg210);
2939 static struct fotg210_qh *qh_append_tds(struct fotg210_hcd *fotg210,
2944 __hc32 qh_addr_mask = cpu_to_hc32(fotg210, 0x7f);
2948 /* can't sleep here, we have fotg210->lock... */
2949 qh = qh_make(fotg210, urb, GFP_ATOMIC);
2982 qtd->hw_token = HALT_BIT(fotg210);
2994 fotg210_qtd_init(fotg210, qtd, qtd->qtd_dma);
3001 qtd->hw_next = QTD_NEXT(fotg210, dma);
3013 static int submit_async(struct fotg210_hcd *fotg210, struct urb *urb,
3028 fotg210_dbg(fotg210,
3038 spin_lock_irqsave(&fotg210->lock, flags);
3039 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) {
3043 rc = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb);
3047 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv);
3049 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb);
3058 qh_link_async(fotg210, qh);
3060 spin_unlock_irqrestore(&fotg210->lock, flags);
3062 qtd_list_free(fotg210, urb, qtd_list);
3066 static void single_unlink_async(struct fotg210_hcd *fotg210,
3073 if (fotg210->async_unlink)
3074 fotg210->async_unlink_last->unlink_next = qh;
3076 fotg210->async_unlink = qh;
3077 fotg210->async_unlink_last = qh;
3080 prev = fotg210->async;
3086 if (fotg210->qh_scan_next == qh)
3087 fotg210->qh_scan_next = qh->qh_next.qh;
3090 static void start_iaa_cycle(struct fotg210_hcd *fotg210, bool nested)
3096 if (fotg210->async_iaa || fotg210->async_unlinking)
3100 fotg210->async_iaa = fotg210->async_unlink;
3101 fotg210->async_unlink = NULL;
3104 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING)) {
3106 end_unlink_async(fotg210);
3109 } else if (likely(fotg210->rh_state == FOTG210_RH_RUNNING)) {
3113 fotg210_writel(fotg210, fotg210->command | CMD_IAAD,
3114 &fotg210->regs->command);
3115 fotg210_readl(fotg210, &fotg210->regs->command);
3116 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IAA_WATCHDOG,
3123 static void end_unlink_async(struct fotg210_hcd *fotg210)
3129 fotg210->async_unlinking = true;
3130 while (fotg210->async_iaa) {
3131 qh = fotg210->async_iaa;
3132 fotg210->async_iaa = qh->unlink_next;
3138 qh_completions(fotg210, qh);
3140 fotg210->rh_state == FOTG210_RH_RUNNING)
3141 qh_link_async(fotg210, qh);
3142 disable_async(fotg210);
3144 fotg210->async_unlinking = false;
3147 if (fotg210->async_unlink) {
3148 start_iaa_cycle(fotg210, true);
3149 if (unlikely(fotg210->rh_state < FOTG210_RH_RUNNING))
3154 static void unlink_empty_async(struct fotg210_hcd *fotg210)
3157 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING);
3161 next = fotg210->async->qh_next.qh;
3169 fotg210->async_unlink_cycle)
3172 single_unlink_async(fotg210, qh);
3177 if (fotg210->async_unlink)
3178 start_iaa_cycle(fotg210, false);
3182 fotg210_enable_event(fotg210, FOTG210_HRTIMER_ASYNC_UNLINKS,
3184 ++fotg210->async_unlink_cycle;
3189 /* caller must own fotg210->lock */
3191 static void start_unlink_async(struct fotg210_hcd *fotg210,
3205 single_unlink_async(fotg210, qh);
3206 start_iaa_cycle(fotg210, false);
3209 static void scan_async(struct fotg210_hcd *fotg210)
3214 fotg210->qh_scan_next = fotg210->async->qh_next.qh;
3215 while (fotg210->qh_scan_next) {
3216 qh = fotg210->qh_scan_next;
3217 fotg210->qh_scan_next = qh->qh_next.qh;
3225 * drops the lock. That's why fotg210->qh_scan_next
3227 * gets unlinked then fotg210->qh_scan_next is adjusted
3230 temp = qh_completions(fotg210, qh);
3232 start_unlink_async(fotg210, qh);
3235 qh->unlink_cycle = fotg210->async_unlink_cycle;
3248 if (check_unlinks_later && fotg210->rh_state == FOTG210_RH_RUNNING &&
3249 !(fotg210->enabled_hrtimer_events &
3251 fotg210_enable_event(fotg210,
3253 ++fotg210->async_unlink_cycle;
3273 static union fotg210_shadow *periodic_next_shadow(struct fotg210_hcd *fotg210,
3276 switch (hc32_to_cpu(fotg210, tag)) {
3286 static __hc32 *shadow_next_periodic(struct fotg210_hcd *fotg210,
3289 switch (hc32_to_cpu(fotg210, tag)) {
3299 /* caller must hold fotg210->lock */
3300 static void periodic_unlink(struct fotg210_hcd *fotg210, unsigned frame,
3303 union fotg210_shadow *prev_p = &fotg210->pshadow[frame];
3304 __hc32 *hw_p = &fotg210->periodic[frame];
3309 prev_p = periodic_next_shadow(fotg210, prev_p,
3310 Q_NEXT_TYPE(fotg210, *hw_p));
3311 hw_p = shadow_next_periodic(fotg210, &here,
3312 Q_NEXT_TYPE(fotg210, *hw_p));
3322 *prev_p = *periodic_next_shadow(fotg210, &here,
3323 Q_NEXT_TYPE(fotg210, *hw_p));
3325 *hw_p = *shadow_next_periodic(fotg210, &here,
3326 Q_NEXT_TYPE(fotg210, *hw_p));
3330 static unsigned short periodic_usecs(struct fotg210_hcd *fotg210,
3333 __hc32 *hw_p = &fotg210->periodic[frame];
3334 union fotg210_shadow *q = &fotg210->pshadow[frame];
3339 switch (hc32_to_cpu(fotg210, Q_NEXT_TYPE(fotg210, *hw_p))) {
3343 if (hw->hw_info2 & cpu_to_hc32(fotg210, 1 << uframe))
3346 if (hw->hw_info2 & cpu_to_hc32(fotg210,
3357 if (q->fstn->hw_prev != FOTG210_LIST_END(fotg210))
3358 fotg210_dbg(fotg210, "ignoring FSTN cost ...\n");
3371 if (usecs > fotg210->uframe_periodic_max)
3372 fotg210_err(fotg210, "uframe %d sched overrun: %d usecs\n",
3393 static int tt_no_collision(struct fotg210_hcd *fotg210, unsigned period,
3403 for (; frame < fotg210->periodic_size; frame += period) {
3408 here = fotg210->pshadow[frame];
3409 type = Q_NEXT_TYPE(fotg210, fotg210->periodic[frame]);
3411 switch (hc32_to_cpu(fotg210, type)) {
3413 type = Q_NEXT_TYPE(fotg210, here.itd->hw_next);
3421 mask = hc32_to_cpu(fotg210,
3428 type = Q_NEXT_TYPE(fotg210, hw->hw_next);
3433 fotg210_dbg(fotg210,
3447 static void enable_periodic(struct fotg210_hcd *fotg210)
3449 if (fotg210->periodic_count++)
3453 fotg210->enabled_hrtimer_events &=
3457 fotg210_poll_PSS(fotg210);
3458 turn_on_io_watchdog(fotg210);
3461 static void disable_periodic(struct fotg210_hcd *fotg210)
3463 if (--fotg210->periodic_count)
3467 fotg210_poll_PSS(fotg210);
3474 * no FSTN support (yet; fotg210 0.96+)
3476 static void qh_link_periodic(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3483 hc32_to_cpup(fotg210, &qh->hw->hw_info2) &
3491 for (i = qh->start; i < fotg210->periodic_size; i += period) {
3492 union fotg210_shadow *prev = &fotg210->pshadow[i];
3493 __hc32 *hw_p = &fotg210->periodic[i];
3499 type = Q_NEXT_TYPE(fotg210, *hw_p);
3500 if (type == cpu_to_hc32(fotg210, Q_TYPE_QH))
3502 prev = periodic_next_shadow(fotg210, prev, type);
3503 hw_p = shadow_next_periodic(fotg210, &here, type);
3524 *hw_p = QH_NEXT(fotg210, qh->qh_dma);
3531 fotg210_to_hcd(fotg210)->self.bandwidth_allocated += qh->period
3535 list_add(&qh->intr_node, &fotg210->intr_qh_list);
3538 ++fotg210->intr_count;
3539 enable_periodic(fotg210);
3542 static void qh_unlink_periodic(struct fotg210_hcd *fotg210,
3568 for (i = qh->start; i < fotg210->periodic_size; i += period)
3569 periodic_unlink(fotg210, i, qh);
3572 fotg210_to_hcd(fotg210)->self.bandwidth_allocated -= qh->period
3578 qh->period, hc32_to_cpup(fotg210, &qh->hw->hw_info2) &
3586 if (fotg210->qh_scan_next == qh)
3587 fotg210->qh_scan_next = list_entry(qh->intr_node.next,
3592 static void start_unlink_intr(struct fotg210_hcd *fotg210,
3605 qh_unlink_periodic(fotg210, qh);
3615 qh->unlink_cycle = fotg210->intr_unlink_cycle;
3618 if (fotg210->intr_unlink)
3619 fotg210->intr_unlink_last->unlink_next = qh;
3621 fotg210->intr_unlink = qh;
3622 fotg210->intr_unlink_last = qh;
3624 if (fotg210->intr_unlinking)
3626 else if (fotg210->rh_state < FOTG210_RH_RUNNING)
3627 fotg210_handle_intr_unlinks(fotg210);
3628 else if (fotg210->intr_unlink == qh) {
3629 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR,
3631 ++fotg210->intr_unlink_cycle;
3635 static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3641 hw->hw_next = FOTG210_LIST_END(fotg210);
3643 qh_completions(fotg210, qh);
3647 fotg210->rh_state == FOTG210_RH_RUNNING) {
3648 rc = qh_schedule(fotg210, qh);
3657 fotg210_err(fotg210, "can't reschedule qh %p, err %d\n",
3662 --fotg210->intr_count;
3663 disable_periodic(fotg210);
3666 static int check_period(struct fotg210_hcd *fotg210, unsigned frame,
3678 usecs = fotg210->uframe_periodic_max - usecs;
3686 claimed = periodic_usecs(fotg210, frame,
3691 } while ((frame += 1) < fotg210->periodic_size);
3696 claimed = periodic_usecs(fotg210, frame, uframe);
3699 } while ((frame += period) < fotg210->periodic_size);
3706 static int check_intr_schedule(struct fotg210_hcd *fotg210, unsigned frame,
3715 if (!check_period(fotg210, frame, uframe, qh->period, qh->usecs))
3731 *c_maskp = cpu_to_hc32(fotg210, mask << 8);
3734 if (tt_no_collision(fotg210, qh->period, qh->dev, frame, mask)) {
3735 if (!check_period(fotg210, frame, uframe + qh->gap_uf + 1,
3738 if (!check_period(fotg210, frame, uframe + qh->gap_uf,
3750 static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3758 qh_refresh(fotg210, qh);
3759 hw->hw_next = FOTG210_LIST_END(fotg210);
3764 uframe = ffs(hc32_to_cpup(fotg210, &hw->hw_info2) & QH_SMASK);
3765 status = check_intr_schedule(fotg210, frame, --uframe,
3782 frame = ++fotg210->random_frame % qh->period;
3784 status = check_intr_schedule(fotg210,
3795 status = check_intr_schedule(fotg210, 0, 0, qh,
3803 hw->hw_info2 &= cpu_to_hc32(fotg210, ~(QH_CMASK | QH_SMASK));
3805 ? cpu_to_hc32(fotg210, 1 << uframe)
3806 : cpu_to_hc32(fotg210, QH_SMASK);
3809 fotg210_dbg(fotg210, "reused qh %p schedule\n", qh);
3812 qh_link_periodic(fotg210, qh);
3817 static int intr_submit(struct fotg210_hcd *fotg210, struct urb *urb,
3829 spin_lock_irqsave(&fotg210->lock, flags);
3831 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) {
3835 status = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb);
3841 qh = qh_append_tds(fotg210, urb, &empty, epnum, &urb->ep->hcpriv);
3847 status = qh_schedule(fotg210, qh);
3853 qh = qh_append_tds(fotg210, urb, qtd_list, epnum, &urb->ep->hcpriv);
3857 fotg210_to_hcd(fotg210)->self.bandwidth_int_reqs++;
3861 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb);
3863 spin_unlock_irqrestore(&fotg210->lock, flags);
3865 qtd_list_free(fotg210, urb, qtd_list);
3870 static void scan_intr(struct fotg210_hcd *fotg210)
3874 list_for_each_entry_safe(qh, fotg210->qh_scan_next,
3875 &fotg210->intr_qh_list, intr_node) {
3883 * drops the lock. That's why fotg210->qh_scan_next
3885 * gets unlinked then fotg210->qh_scan_next is adjusted
3888 temp = qh_completions(fotg210, qh);
3892 start_unlink_intr(fotg210, qh);
3914 static void iso_stream_init(struct fotg210_hcd *fotg210,
3942 stream->buf0 = cpu_to_hc32(fotg210, (epnum << 8) | dev->devnum);
3943 stream->buf1 = cpu_to_hc32(fotg210, buf1);
3944 stream->buf2 = cpu_to_hc32(fotg210, multi);
3968 static struct fotg210_iso_stream *iso_stream_find(struct fotg210_hcd *fotg210,
3982 spin_lock_irqsave(&fotg210->lock, flags);
3990 iso_stream_init(fotg210, stream, urb->dev, urb->pipe,
3996 fotg210_dbg(fotg210, "dev %s ep%d%s, not iso??\n",
4002 spin_unlock_irqrestore(&fotg210->lock, flags);
4022 static inline void itd_sched_init(struct fotg210_hcd *fotg210,
4050 uframe->transaction = cpu_to_hc32(fotg210, trans);
4065 /* caller must hold fotg210->lock!*/
4071 struct fotg210_hcd *fotg210, struct urb *urb, gfp_t mem_flags)
4084 itd_sched_init(fotg210, sched, stream, urb);
4092 spin_lock_irqsave(&fotg210->lock, flags);
4102 if (itd->frame == fotg210->now_frame)
4108 spin_unlock_irqrestore(&fotg210->lock, flags);
4109 itd = dma_pool_zalloc(fotg210->itd_pool, mem_flags,
4111 spin_lock_irqsave(&fotg210->lock, flags);
4114 spin_unlock_irqrestore(&fotg210->lock, flags);
4122 spin_unlock_irqrestore(&fotg210->lock, flags);
4130 static inline int itd_slot_ok(struct fotg210_hcd *fotg210, u32 mod, u32 uframe,
4136 if (periodic_usecs(fotg210, uframe >> 3, uframe & 0x7)
4137 > (fotg210->uframe_periodic_max - usecs))
4150 * Also avoid queue depths of less than fotg210's worst irq latency (affected
4158 static int iso_stream_schedule(struct fotg210_hcd *fotg210, struct urb *urb,
4163 unsigned mod = fotg210->periodic_size << 3;
4170 fotg210_dbg(fotg210, "iso request %p too long\n", urb);
4175 now = fotg210_read_frame_index(fotg210) & (mod - 1);
4190 if (!stream->highspeed && fotg210->fs_i_thresh)
4191 next = now + fotg210->i_thresh;
4206 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n",
4215 * this is bigger than fotg210->i_thresh allows; scheduling itself
4237 if (itd_slot_ok(fotg210, mod, start,
4244 fotg210_dbg(fotg210, "iso resched full %p (now %d max %d)\n",
4254 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n",
4269 if (fotg210->isoc_count == 0)
4270 fotg210->next_frame = now >> 3;
4279 static inline void itd_init(struct fotg210_hcd *fotg210,
4285 itd->hw_next = FOTG210_LIST_END(fotg210);
4296 static inline void itd_patch(struct fotg210_hcd *fotg210,
4307 itd->hw_transaction[uframe] |= cpu_to_hc32(fotg210, pg << 12);
4308 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, uf->bufp & ~(u32)0);
4309 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(uf->bufp >> 32));
4316 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, bufp & ~(u32)0);
4317 itd->hw_bufp_hi[pg] |= cpu_to_hc32(fotg210, (u32)(bufp >> 32));
4321 static inline void itd_link(struct fotg210_hcd *fotg210, unsigned frame,
4324 union fotg210_shadow *prev = &fotg210->pshadow[frame];
4325 __hc32 *hw_p = &fotg210->periodic[frame];
4331 type = Q_NEXT_TYPE(fotg210, *hw_p);
4332 if (type == cpu_to_hc32(fotg210, Q_TYPE_QH))
4334 prev = periodic_next_shadow(fotg210, prev, type);
4335 hw_p = shadow_next_periodic(fotg210, &here, type);
4344 *hw_p = cpu_to_hc32(fotg210, itd->itd_dma | Q_TYPE_ITD);
4348 static void itd_link_urb(struct fotg210_hcd *fotg210, struct urb *urb,
4359 fotg210_to_hcd(fotg210)->self.bandwidth_allocated
4361 fotg210_dbg(fotg210,
4381 itd_init(fotg210, stream, itd);
4387 itd_patch(fotg210, itd, iso_sched, packet, uframe);
4396 itd_link(fotg210, frame & (fotg210->periodic_size - 1),
4407 ++fotg210->isoc_count;
4408 enable_periodic(fotg210);
4424 static bool itd_complete(struct fotg210_hcd *fotg210, struct fotg210_itd *itd)
4442 t = hc32_to_cpup(fotg210, &itd->hw_transaction[uframe]);
4483 fotg210_urb_done(fotg210, urb, 0);
4487 --fotg210->isoc_count;
4488 disable_periodic(fotg210);
4491 fotg210_to_hcd(fotg210)->self.bandwidth_allocated
4493 fotg210_dbg(fotg210,
4508 &fotg210->cached_itd_list);
4509 start_free_itds(fotg210);
4515 static int itd_submit(struct fotg210_hcd *fotg210, struct urb *urb,
4523 stream = iso_stream_find(fotg210, urb);
4525 fotg210_dbg(fotg210, "can't get iso stream\n");
4529 fotg210_port_speed(fotg210, 0) ==
4531 fotg210_dbg(fotg210, "can't change iso interval %d --> %d\n",
4537 fotg210_dbg(fotg210,
4548 status = itd_urb_transaction(stream, fotg210, urb, mem_flags);
4550 fotg210_dbg(fotg210, "can't init itds\n");
4555 spin_lock_irqsave(&fotg210->lock, flags);
4556 if (unlikely(!HCD_HW_ACCESSIBLE(fotg210_to_hcd(fotg210)))) {
4560 status = usb_hcd_link_urb_to_ep(fotg210_to_hcd(fotg210), urb);
4563 status = iso_stream_schedule(fotg210, urb, stream);
4565 itd_link_urb(fotg210, urb, fotg210->periodic_size << 3, stream);
4567 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb);
4569 spin_unlock_irqrestore(&fotg210->lock, flags);
4574 static inline int scan_frame_queue(struct fotg210_hcd *fotg210, unsigned frame,
4583 q_p = &fotg210->pshadow[frame];
4584 hw_p = &fotg210->periodic[frame];
4586 type = Q_NEXT_TYPE(fotg210, *hw_p);
4590 switch (hc32_to_cpu(fotg210, type)) {
4601 ITD_ACTIVE(fotg210))
4607 type = Q_NEXT_TYPE(fotg210,
4621 type = Q_NEXT_TYPE(fotg210, q.itd->hw_next);
4623 modified = itd_complete(fotg210, q.itd);
4627 fotg210_dbg(fotg210, "corrupt type %d frame %d shadow %p\n",
4638 if (unlikely(modified && fotg210->isoc_count > 0))
4644 static void scan_isoc(struct fotg210_hcd *fotg210)
4647 unsigned fmask = fotg210->periodic_size - 1;
4655 if (fotg210->rh_state >= FOTG210_RH_RUNNING) {
4656 uf = fotg210_read_frame_index(fotg210);
4660 now_frame = (fotg210->next_frame - 1) & fmask;
4663 fotg210->now_frame = now_frame;
4665 frame = fotg210->next_frame;
4669 ret = scan_frame_queue(fotg210, frame,
4677 fotg210->next_frame = now_frame;
4685 struct fotg210_hcd *fotg210;
4688 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev)));
4689 n = scnprintf(buf, PAGE_SIZE, "%d\n", fotg210->uframe_periodic_max);
4697 struct fotg210_hcd *fotg210;
4704 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev)));
4709 fotg210_info(fotg210, "rejecting invalid request for uframe_periodic_max=%u\n",
4720 spin_lock_irqsave(&fotg210->lock, flags);
4727 if (uframe_periodic_max < fotg210->uframe_periodic_max) {
4730 for (frame = 0; frame < fotg210->periodic_size; ++frame)
4733 periodic_usecs(fotg210, frame,
4737 fotg210_info(fotg210,
4746 fotg210_info(fotg210,
4751 fotg210_warn(fotg210, "max periodic bandwidth set is non-standard\n");
4753 fotg210->uframe_periodic_max = uframe_periodic_max;
4757 spin_unlock_irqrestore(&fotg210->lock, flags);
4763 static inline int create_sysfs_files(struct fotg210_hcd *fotg210)
4765 struct device *controller = fotg210_to_hcd(fotg210)->self.controller;
4770 static inline void remove_sysfs_files(struct fotg210_hcd *fotg210)
4772 struct device *controller = fotg210_to_hcd(fotg210)->self.controller;
4780 static void fotg210_turn_off_all_ports(struct fotg210_hcd *fotg210)
4782 u32 __iomem *status_reg = &fotg210->regs->port_status;
4784 fotg210_writel(fotg210, PORT_RWC_BITS, status_reg);
4790 static void fotg210_silence_controller(struct fotg210_hcd *fotg210)
4792 fotg210_halt(fotg210);
4794 spin_lock_irq(&fotg210->lock);
4795 fotg210->rh_state = FOTG210_RH_HALTED;
4796 fotg210_turn_off_all_ports(fotg210);
4797 spin_unlock_irq(&fotg210->lock);
4806 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
4808 spin_lock_irq(&fotg210->lock);
4809 fotg210->shutdown = true;
4810 fotg210->rh_state = FOTG210_RH_STOPPING;
4811 fotg210->enabled_hrtimer_events = 0;
4812 spin_unlock_irq(&fotg210->lock);
4814 fotg210_silence_controller(fotg210);
4816 hrtimer_cancel(&fotg210->hrtimer);
4820 * it calls driver completion functions, after dropping fotg210->lock.
4822 static void fotg210_work(struct fotg210_hcd *fotg210)
4824 /* another CPU may drop fotg210->lock during a schedule scan while
4828 if (fotg210->scanning) {
4829 fotg210->need_rescan = true;
4832 fotg210->scanning = true;
4835 fotg210->need_rescan = false;
4836 if (fotg210->async_count)
4837 scan_async(fotg210);
4838 if (fotg210->intr_count > 0)
4839 scan_intr(fotg210);
4840 if (fotg210->isoc_count > 0)
4841 scan_isoc(fotg210);
4842 if (fotg210->need_rescan)
4844 fotg210->scanning = false;
4850 turn_on_io_watchdog(fotg210);
4857 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
4859 fotg210_dbg(fotg210, "stop\n");
4863 spin_lock_irq(&fotg210->lock);
4864 fotg210->enabled_hrtimer_events = 0;
4865 spin_unlock_irq(&fotg210->lock);
4867 fotg210_quiesce(fotg210);
4868 fotg210_silence_controller(fotg210);
4869 fotg210_reset(fotg210);
4871 hrtimer_cancel(&fotg210->hrtimer);
4872 remove_sysfs_files(fotg210);
4873 remove_debug_files(fotg210);
4876 spin_lock_irq(&fotg210->lock);
4877 end_free_itds(fotg210);
4878 spin_unlock_irq(&fotg210->lock);
4879 fotg210_mem_cleanup(fotg210);
4882 fotg210_dbg(fotg210, "irq normal %ld err %ld iaa %ld (lost %ld)\n",
4883 fotg210->stats.normal, fotg210->stats.error,
4884 fotg210->stats.iaa, fotg210->stats.lost_iaa);
4885 fotg210_dbg(fotg210, "complete %ld unlink %ld\n",
4886 fotg210->stats.complete, fotg210->stats.unlink);
4889 dbg_status(fotg210, "fotg210_stop completed",
4890 fotg210_readl(fotg210, &fotg210->regs->status));
4896 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
4902 spin_lock_init(&fotg210->lock);
4907 fotg210->need_io_watchdog = 1;
4909 hrtimer_init(&fotg210->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
4910 fotg210->hrtimer.function = fotg210_hrtimer_func;
4911 fotg210->next_hrtimer_event = FOTG210_HRTIMER_NO_EVENT;
4913 hcc_params = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
4919 fotg210->uframe_periodic_max = 100;
4925 fotg210->periodic_size = DEFAULT_I_TDPS;
4926 INIT_LIST_HEAD(&fotg210->intr_qh_list);
4927 INIT_LIST_HEAD(&fotg210->cached_itd_list);
4933 fotg210->periodic_size = 1024;
4936 fotg210->periodic_size = 512;
4939 fotg210->periodic_size = 256;
4945 retval = fotg210_mem_init(fotg210, GFP_KERNEL);
4950 fotg210->i_thresh = 2;
4959 fotg210->async->qh_next.qh = NULL;
4960 hw = fotg210->async->hw;
4961 hw->hw_next = QH_NEXT(fotg210, fotg210->async->qh_dma);
4962 hw->hw_info1 = cpu_to_hc32(fotg210, QH_HEAD);
4963 hw->hw_token = cpu_to_hc32(fotg210, QTD_STS_HALT);
4964 hw->hw_qtd_next = FOTG210_LIST_END(fotg210);
4965 fotg210->async->qh_state = QH_STATE_LINKED;
4966 hw->hw_alt_next = QTD_NEXT(fotg210, fotg210->async->dummy->qtd_dma);
4985 fotg210_dbg(fotg210, "park %d\n", park);
4992 fotg210->command = temp;
5003 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5010 fotg210_writel(fotg210, fotg210->periodic_dma,
5011 &fotg210->regs->frame_list);
5012 fotg210_writel(fotg210, (u32)fotg210->async->qh_dma,
5013 &fotg210->regs->async_next);
5016 * hcc_params controls whether fotg210->regs->segment must (!!!)
5027 fotg210_readl(fotg210, &fotg210->caps->hcc_params);
5033 fotg210->command &= ~(CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET);
5034 fotg210->command |= CMD_RUN;
5035 fotg210_writel(fotg210, fotg210->command, &fotg210->regs->command);
5036 dbg_cmd(fotg210, "init", fotg210->command);
5053 fotg210->rh_state = FOTG210_RH_RUNNING;
5055 fotg210_readl(fotg210, &fotg210->regs->command);
5058 fotg210->last_periodic_enable = ktime_get_real();
5060 temp = HC_VERSION(fotg210,
5061 fotg210_readl(fotg210, &fotg210->caps->hc_capbase));
5062 fotg210_info(fotg210,
5064 ((fotg210->sbrn & 0xf0) >> 4), (fotg210->sbrn & 0x0f),
5067 fotg210_writel(fotg210, INTR_MASK,
5068 &fotg210->regs->intr_enable); /* Turn On Interrupts */
5074 create_debug_files(fotg210);
5075 create_sysfs_files(fotg210);
5082 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5085 fotg210->regs = (void __iomem *)fotg210->caps +
5086 HC_LENGTH(fotg210,
5087 fotg210_readl(fotg210, &fotg210->caps->hc_capbase));
5088 dbg_hcs_params(fotg210, "reset");
5089 dbg_hcc_params(fotg210, "reset");
5092 fotg210->hcs_params = fotg210_readl(fotg210,
5093 &fotg210->caps->hcs_params);
5095 fotg210->sbrn = HCD_USB2;
5102 retval = fotg210_halt(fotg210);
5106 fotg210_reset(fotg210);
5113 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5117 spin_lock(&fotg210->lock);
5119 status = fotg210_readl(fotg210, &fotg210->regs->status);
5123 fotg210_dbg(fotg210, "device removed\n");
5135 unlikely(fotg210->rh_state == FOTG210_RH_HALTED)) {
5136 spin_unlock(&fotg210->lock);
5141 fotg210_writel(fotg210, masked_status, &fotg210->regs->status);
5142 cmd = fotg210_readl(fotg210, &fotg210->regs->command);
5146 dbg_status(fotg210, "irq", status);
5153 INCR(fotg210->stats.normal);
5155 INCR(fotg210->stats.error);
5163 fotg210->enabled_hrtimer_events &=
5173 if (fotg210->next_hrtimer_event == FOTG210_HRTIMER_IAA_WATCHDOG)
5174 ++fotg210->next_hrtimer_event;
5178 fotg210_dbg(fotg210, "IAA with IAAD still set?\n");
5179 if (fotg210->async_iaa) {
5180 INCR(fotg210->stats.iaa);
5181 end_unlink_async(fotg210);
5183 fotg210_dbg(fotg210, "IAA with nothing unlinked?\n");
5189 u32 __iomem *status_reg = &fotg210->regs->port_status;
5195 if (fotg210->rh_state == FOTG210_RH_SUSPENDED)
5198 pstatus = fotg210_readl(fotg210, status_reg);
5200 if (test_bit(0, &fotg210->suspended_ports) &&
5204 fotg210->reset_done[0] == 0) {
5211 fotg210->reset_done[0] = jiffies + msecs_to_jiffies(25);
5212 set_bit(0, &fotg210->resuming_ports);
5213 fotg210_dbg(fotg210, "port 1 remote wakeup\n");
5214 mod_timer(&hcd->rh_timer, fotg210->reset_done[0]);
5220 fotg210_err(fotg210, "fatal error\n");
5221 dbg_cmd(fotg210, "fatal", cmd);
5222 dbg_status(fotg210, "fatal", status);
5227 fotg210->shutdown = true;
5228 fotg210->rh_state = FOTG210_RH_STOPPING;
5229 fotg210->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE);
5230 fotg210_writel(fotg210, fotg210->command,
5231 &fotg210->regs->command);
5232 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable);
5233 fotg210_handle_controller_death(fotg210);
5240 fotg210_work(fotg210);
5241 spin_unlock(&fotg210->lock);
5261 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5276 if (!qh_urb_transaction(fotg210, urb, &qtd_list, mem_flags))
5278 return submit_async(fotg210, urb, &qtd_list, mem_flags);
5281 if (!qh_urb_transaction(fotg210, urb, &qtd_list, mem_flags))
5283 return intr_submit(fotg210, urb, &qtd_list, mem_flags);
5286 return itd_submit(fotg210, urb, mem_flags);
5296 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5301 spin_lock_irqsave(&fotg210->lock, flags);
5316 start_unlink_async(fotg210, qh);
5324 qh_completions(fotg210, qh);
5336 start_unlink_intr(fotg210, qh);
5339 qh_completions(fotg210, qh);
5342 fotg210_dbg(fotg210, "bogus qh %p state %d\n",
5356 spin_unlock_irqrestore(&fotg210->lock, flags);
5365 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5373 spin_lock_irqsave(&fotg210->lock, flags);
5392 if (fotg210->rh_state < FOTG210_RH_RUNNING)
5397 for (tmp = fotg210->async->qh_next.qh;
5405 start_unlink_async(fotg210, qh);
5410 spin_unlock_irqrestore(&fotg210->lock, flags);
5417 qh_destroy(fotg210, qh);
5425 fotg210_err(fotg210, "qh %p (#%02x) state %d%s\n",
5432 spin_unlock_irqrestore(&fotg210->lock, flags);
5438 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5448 spin_lock_irqsave(&fotg210->lock, flags);
5468 start_unlink_async(fotg210, qh);
5470 start_unlink_intr(fotg210, qh);
5473 spin_unlock_irqrestore(&fotg210->lock, flags);
5478 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5480 return (fotg210_read_frame_index(fotg210) >> 3) %
5481 fotg210->periodic_size;
5487 * give the fotg210 driver exclusive access to those.
5539 static void fotg210_init(struct fotg210_hcd *fotg210)
5544 &fotg210->regs->gmir);
5546 value = ioread32(&fotg210->regs->otgcsr);
5549 iowrite32(value, &fotg210->regs->otgcsr);
5566 struct fotg210_hcd *fotg210;
5602 fotg210 = hcd_to_fotg210(hcd);
5604 fotg210->caps = hcd->regs;
5607 fotg210->pclk = clk_get(dev, "PCLK");
5608 if (!IS_ERR(fotg210->pclk)) {
5609 retval = clk_prepare_enable(fotg210->pclk);
5614 } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
5619 retval = PTR_ERR(fotg210->pclk);
5627 fotg210_init(fotg210);
5640 if (!IS_ERR(fotg210->pclk)) {
5641 clk_disable_unprepare(fotg210->pclk);
5642 clk_put(fotg210->pclk);
5659 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5661 if (!IS_ERR(fotg210->pclk)) {
5662 clk_disable_unprepare(fotg210->pclk);
5663 clk_put(fotg210->pclk);
5674 { .compatible = "faraday,fotg210" },
5682 .name = "fotg210-hcd",
5707 fotg210_debug_root = debugfs_create_dir("fotg210", usb_debug_root);