23 #include <linux/module.h>
24 #include <linux/pci.h>
26 #include <linux/kernel.h>
29 #include <linux/sched.h>
30 #include <linux/slab.h>
31 #include <linux/errno.h>
34 #include <linux/list.h>
43 #include <asm/unaligned.h>
50 #define DRIVER_VERSION "0.0.50"
56 #define oxu_dbg(oxu, fmt, args...) \
57 dev_dbg(oxu_to_hcd(oxu)->self.controller , fmt , ## args)
58 #define oxu_err(oxu, fmt, args...) \
59 dev_err(oxu_to_hcd(oxu)->self.controller , fmt , ## args)
60 #define oxu_info(oxu, fmt, args...) \
61 dev_info(oxu_to_hcd(oxu)->self.controller , fmt , ## args)
63 static inline struct usb_hcd *oxu_to_hcd(
struct oxu_hcd *
oxu)
65 return container_of((
void *) oxu,
struct usb_hcd, hcd_priv);
68 static inline struct oxu_hcd *hcd_to_oxu(
struct usb_hcd *hcd)
70 return (
struct oxu_hcd *) (hcd->hcd_priv);
78 #undef OXU_VERBOSE_DEBUG
80 #ifdef OXU_VERBOSE_DEBUG
81 #define oxu_vdbg oxu_dbg
83 #define oxu_vdbg(oxu, fmt, args...)
91 return scnprintf(buf, len,
"%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s",
92 label, label[0] ?
" " :
"", status,
93 (status &
STS_ASS) ?
" Async" :
"",
94 (status &
STS_PSS) ?
" Periodic" :
"",
97 (status &
STS_IAA) ?
" IAA" :
"",
99 (status &
STS_FLR) ?
" FLR" :
"",
100 (status &
STS_PCD) ?
" PCD" :
"",
101 (status &
STS_ERR) ?
" ERR" :
"",
102 (status &
STS_INT) ?
" INT" :
""
109 return scnprintf(buf, len,
"%s%sintrenable %02x%s%s%s%s%s%s",
110 label, label[0] ?
" " :
"", enable,
111 (enable &
STS_IAA) ?
" IAA" :
"",
113 (enable &
STS_FLR) ?
" FLR" :
"",
114 (enable &
STS_PCD) ?
" PCD" :
"",
115 (enable &
STS_ERR) ?
" ERR" :
"",
116 (enable &
STS_INT) ?
" INT" :
""
120 static const char *
const fls_strings[] =
121 {
"1024",
"512",
"256",
"??" };
123 static int dbg_command_buf(
char *buf,
unsigned len,
127 "%s%scommand %06x %s=%d ithresh=%d%s%s%s%s period=%s%s %s",
128 label, label[0] ?
" " :
"", command,
129 (command &
CMD_PARK) ?
"park" :
"(park)",
131 (command >> 16) & 0x3f,
133 (command &
CMD_IAAD) ?
" IAAD" :
"",
134 (command &
CMD_ASE) ?
" Async" :
"",
135 (command &
CMD_PSE) ?
" Periodic" :
"",
136 fls_strings[(command >> 2) & 0x3],
138 (command &
CMD_RUN) ?
"RUN" :
"HALT"
142 static int dbg_port_buf(
char *buf,
unsigned len,
const char *label,
148 switch (status & (3 << 10)) {
164 "%s%sport %d status %06x%s%s sig=%s%s%s%s%s%s%s%s%s%s",
165 label, label[0] ?
" " :
"", port, status,
173 (status &
PORT_OC) ?
" OC" :
"",
175 (status &
PORT_PE) ?
" PE" :
"",
184 dbg_status_buf(
char *buf,
unsigned len,
const char *label,
u32 status)
188 dbg_command_buf(
char *buf,
unsigned len,
const char *label,
u32 command)
192 dbg_intr_buf(
char *buf,
unsigned len,
const char *label,
u32 enable)
196 dbg_port_buf(
char *buf,
unsigned len,
const char *label,
int port,
u32 status)
202 #define dbg_status(oxu, label, status) { \
204 dbg_status_buf(_buf, sizeof _buf, label, status); \
205 oxu_dbg(oxu, "%s\n", _buf); \
208 #define dbg_cmd(oxu, label, command) { \
210 dbg_command_buf(_buf, sizeof _buf, label, command); \
211 oxu_dbg(oxu, "%s\n", _buf); \
214 #define dbg_port(oxu, label, port, status) { \
216 dbg_port_buf(_buf, sizeof _buf, label, port, status); \
217 oxu_dbg(oxu, "%s\n", _buf); \
225 static int log2_irq_thresh;
230 static unsigned park;
235 static bool ignore_oc;
237 MODULE_PARM_DESC(ignore_oc,
"ignore bogus hardware overcurrent indications");
241 static int oxu_hub_control(
struct usb_hcd *hcd,
250 static inline u32 oxu_readl(
void *base,
u32 reg)
252 return readl(base + reg);
255 static inline void oxu_writel(
void *base,
u32 reg,
u32 val)
260 static inline void timer_action_done(
struct oxu_hcd *
oxu,
266 static inline void timer_action(
struct oxu_hcd *
oxu,
325 if (result == ~(
u32)0)
337 static int ehci_halt(
struct oxu_hcd *oxu)
351 STS_HALT, STS_HALT, 16 * 125);
355 static void tdi_reset(
struct oxu_hcd *oxu)
361 tmp =
readl(reg_ptr);
367 static int ehci_reset(
struct oxu_hcd *oxu)
373 dbg_cmd(oxu,
"reset", command);
375 oxu_to_hcd(oxu)->state = HC_STATE_HALT;
389 static void ehci_quiesce(
struct oxu_hcd *oxu)
394 if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->
state))
402 temp, 16 * 125) != 0) {
403 oxu_to_hcd(oxu)->state = HC_STATE_HALT;
409 temp &= ~(CMD_ASE | CMD_IAAD |
CMD_PSE);
415 oxu_to_hcd(oxu)->state = HC_STATE_HALT;
420 static int check_reset_complete(
struct oxu_hcd *oxu,
int index,
429 if (!(port_status & PORT_PE)) {
430 oxu_dbg(oxu,
"Failed to enable port %d on root hub TT\n",
434 oxu_dbg(oxu,
"port %d high speed\n", index + 1);
439 static void ehci_hub_descriptor(
struct oxu_hcd *oxu,
450 temp = 1 + (ports / 8);
488 oxu_err(oxu,
"buffer too big (%d)\n", len);
498 for (a_blocks = 1; a_blocks <
n_blocks; a_blocks <<= 1)
506 for (j = 0; j < a_blocks; j++)
514 qtd->
buffer = (
void *) &oxu->
mem->db_pool[i];
538 index = (qtd->
buffer - (
void *) &oxu->
mem->db_pool[0])
550 memset(qtd, 0,
sizeof *qtd);
558 static inline void oxu_qtd_free(
struct oxu_hcd *oxu,
struct ehci_qtd *qtd)
563 oxu_buf_free(oxu, qtd);
567 index = qtd - &oxu->
mem->qtd_pool[0];
586 memset(qtd, 0,
sizeof *qtd);
609 index = qh - &oxu->
mem->qh_pool[0];
615 static void qh_destroy(
struct kref *
kref)
622 oxu_dbg(oxu,
"unused qh not empty!\n");
626 oxu_qtd_free(oxu, qh->
dummy);
627 oxu_qh_free(oxu, qh);
642 qh = (
struct ehci_qh *) &oxu->
mem->qh_pool[i];
643 memset(qh, 0,
sizeof *qh);
645 kref_init(&qh->
kref);
651 qh->
dummy = ehci_qtd_alloc(oxu);
674 static inline void qh_put(
struct ehci_qh *qh)
676 kref_put(&qh->
kref, qh_destroy);
718 static void ehci_mem_cleanup(
struct oxu_hcd *oxu)
756 oxu->
async = oxu_qh_alloc(oxu);
772 oxu_dbg(oxu,
"couldn't init memory\n");
773 ehci_mem_cleanup(oxu);
780 int token,
int maxpacket)
788 count = 0x1000 - (buf & 0x0fff);
796 for (i = 1; count < len && i < 5; i++) {
801 if ((count + 0x1000) < len)
809 count -= (count % maxpacket);
817 static inline void qh_update(
struct oxu_hcd *oxu,
832 unsigned is_out, epnum;
836 if (
unlikely(!usb_gettoggle(qh->
dev, epnum, is_out))) {
838 usb_settoggle(qh->
dev, epnum, is_out, 1);
866 qh_update(oxu, qh, qtd);
869 static void qtd_copy_status(
struct oxu_hcd *oxu,
struct urb *
urb,
874 urb->actual_length += length -
QTD_LENGTH(token);
893 urb->status = (
QTD_PID(token) == 1)
899 urb->status = -
EPIPE;
901 oxu_dbg(oxu,
"devpath %s ep%d%s 3strikes\n",
903 usb_pipeendpoint(urb->pipe),
904 usb_pipein(urb->pipe) ?
"in" :
"out");
909 urb->status = -
EPIPE;
913 oxu_vdbg(oxu,
"dev%d ep%d%s qtd token %08x --> status %d\n",
914 usb_pipedevice(urb->pipe),
915 usb_pipeendpoint(urb->pipe),
916 usb_pipein(urb->pipe) ?
"in" :
"out",
921 static void ehci_urb_done(
struct oxu_hcd *oxu,
struct urb *urb)
932 oxu_to_hcd(oxu)->self.bandwidth_int_reqs--;
938 switch (urb->status) {
944 if (!(urb->transfer_flags & URB_SHORT_NOT_OK))
953 oxu_dbg(oxu,
"%s %s urb %p ep%d%s status %d len %d/%d\n",
954 __func__, urb->dev->devpath, urb,
955 usb_pipeendpoint(urb->pipe),
956 usb_pipein(urb->pipe) ?
"in" :
"out",
958 urb->actual_length, urb->transfer_buffer_length);
962 spin_unlock(&oxu->
lock);
964 spin_lock(&oxu->
lock);
967 static void start_unlink_async(
struct oxu_hcd *oxu,
struct ehci_qh *qh);
968 static void unlink_async(
struct oxu_hcd *oxu,
struct ehci_qh *qh);
970 static void intr_deschedule(
struct oxu_hcd *oxu,
struct ehci_qh *qh);
973 #define HALT_BIT cpu_to_le32(QTD_STS_HALT)
979 static unsigned qh_completions(
struct oxu_hcd *oxu,
struct ehci_qh *qh)
1018 if (last->
urb->complete ==
NULL) {
1022 ehci_urb_done(oxu, last->
urb);
1025 oxu_murb_free(oxu, murb);
1027 ehci_urb_done(oxu, last->
urb);
1031 oxu_qtd_free(oxu, last);
1046 if ((token & QTD_STS_HALT) != 0) {
1059 }
else if (
likely(!stopped &&
1060 HC_IS_RUNNING(oxu_to_hcd(oxu)->state))) {
1066 if (
unlikely(!HC_IS_RUNNING(oxu_to_hcd(oxu)->state)))
1101 qtd_copy_status(oxu, urb->complete ?
1102 urb : ((
struct oxu_murb *) urb)->main,
1104 if ((usb_pipein(qtd->
urb->pipe)) &&
1108 && usb_pipecontrol(urb->pipe);
1121 if (last->
urb->complete ==
NULL) {
1125 ehci_urb_done(oxu, last->
urb);
1128 oxu_murb_free(oxu, murb);
1130 ehci_urb_done(oxu, last->
urb);
1133 oxu_qtd_free(oxu, last);
1146 qh_refresh(oxu, qh);
1154 intr_deschedule(oxu, qh);
1155 (
void) qh_schedule(oxu, qh);
1157 unlink_async(oxu, qh);
1167 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
1169 #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
1174 static void qtd_list_free(
struct oxu_hcd *oxu,
1184 oxu_qtd_free(oxu, qtd);
1200 void *transfer_buf =
NULL;
1206 qtd = ehci_qtd_alloc(oxu);
1216 len = urb->transfer_buffer_length;
1217 is_input = usb_pipein(urb->pipe);
1218 if (!urb->transfer_buffer && urb->transfer_buffer_length && is_input)
1219 urb->transfer_buffer =
phys_to_virt(urb->transfer_dma);
1221 if (usb_pipecontrol(urb->pipe)) {
1228 token | (2 << 8), 8);
1235 qtd = ehci_qtd_alloc(oxu);
1251 ret = oxu_buf_alloc(oxu, qtd, len);
1256 transfer_buf = urb->transfer_buffer;
1265 maxpacket =
max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input));
1275 this_qtd_len = qtd_fill(qtd, buf, len, token, maxpacket);
1277 len -= this_qtd_len;
1278 buf += this_qtd_len;
1279 transfer_buf += this_qtd_len;
1284 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0)
1291 qtd = ehci_qtd_alloc(oxu);
1295 ret = oxu_buf_alloc(oxu, qtd, len);
1307 if (
likely((urb->transfer_flags & URB_SHORT_NOT_OK) == 0
1308 || usb_pipecontrol(urb->pipe)))
1315 if (
likely(urb->transfer_buffer_length != 0)) {
1318 if (usb_pipecontrol(urb->pipe)) {
1322 }
else if (usb_pipebulk(urb->pipe)
1323 && (urb->transfer_flags & URB_ZERO_PACKET)
1324 && !(urb->transfer_buffer_length % maxpacket)) {
1329 qtd = ehci_qtd_alloc(oxu);
1337 qtd_fill(qtd, 0, 0, token, 0);
1346 qtd_list_free(oxu, urb, head);
1358 struct urb *urb,
gfp_t flags)
1360 struct ehci_qh *qh = oxu_qh_alloc(oxu);
1371 info1 |= usb_pipeendpoint(urb->pipe) << 8;
1372 info1 |= usb_pipedevice(urb->pipe) << 0;
1374 is_input = usb_pipein(urb->pipe);
1375 type = usb_pipetype(urb->pipe);
1376 maxp = usb_maxpacket(urb->dev, urb->pipe, !is_input);
1386 if (type == PIPE_INTERRUPT) {
1396 qh->
period = urb->interval >> 3;
1397 if (qh->
period == 0 && urb->interval != 1) {
1402 oxu_dbg(oxu,
"intr period %d uframes, NYET!\n",
1407 struct usb_tt *
tt = urb->dev->tt;
1412 is_input, 0, maxp) / (125 * 1000);
1417 qh->
usecs = HS_USECS(1);
1419 qh->
usecs += HS_USECS(1);
1423 think_time = tt ? tt->think_time : 0;
1424 qh->
tt_usecs = NS_TO_US(think_time +
1427 qh->
period = urb->interval;
1435 switch (urb->dev->speed) {
1442 if (type != PIPE_INTERRUPT)
1444 if (type == PIPE_CONTROL) {
1448 info1 |= maxp << 16;
1451 info2 |= urb->dev->ttport << 23;
1459 if (type == PIPE_CONTROL) {
1464 }
else if (type == PIPE_BULK) {
1474 oxu_dbg(oxu,
"bogus dev %p speed %d\n", urb->dev, urb->dev->speed);
1486 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, 1);
1487 qh_refresh(oxu, qh);
1493 static void qh_link_async(
struct oxu_hcd *oxu,
struct ehci_qh *qh)
1504 if (!(cmd & CMD_ASE)) {
1510 oxu_to_hcd(oxu)->state = HC_STATE_RUNNING;
1517 qh_refresh(oxu, qh);
1531 #define QH_ADDR_MASK cpu_to_le32(0x7f)
1541 int epnum,
void **ptr)
1554 if (
unlikely(list_empty(qtd_list)))
1564 if (usb_pipedevice(urb->pipe) == 0)
1591 list_add(&dummy->
qtd_list, qtd_list);
1592 list_splice(qtd_list, qh->
qtd_list.prev);
1594 ehci_qtd_init(qtd, qtd->
qtd_dma);
1604 dummy->
hw_token = (token & ~(0x80));
1608 urb->hcpriv = qh_get(qh);
1614 static int submit_async(
struct oxu_hcd *oxu,
struct urb *urb,
1619 unsigned long flags;
1624 epnum = urb->ep->desc.bEndpointAddress;
1626 #ifdef OXU_URB_TRACE
1627 oxu_dbg(oxu,
"%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n",
1628 __func__, urb->dev->devpath, urb,
1629 epnum & 0x0f, (epnum &
USB_DIR_IN) ?
"in" :
"out",
1630 urb->transfer_buffer_length,
1631 qtd, urb->ep->hcpriv);
1635 if (
unlikely(!HCD_HW_ACCESSIBLE(oxu_to_hcd(oxu)))) {
1640 qh = qh_append_tds(oxu, urb, qtd_list, epnum, &urb->ep->hcpriv);
1650 qh_link_async(oxu, qh_get(qh));
1652 spin_unlock_irqrestore(&oxu->
lock, flags);
1654 qtd_list_free(oxu, urb, qtd_list);
1660 static void end_unlink_async(
struct oxu_hcd *oxu)
1677 qh_completions(oxu, qh);
1680 && HC_IS_RUNNING(oxu_to_hcd(oxu)->
state))
1681 qh_link_async(oxu, qh);
1688 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->
state)
1695 start_unlink_async(oxu, next);
1702 static void start_unlink_async(
struct oxu_hcd *oxu,
struct ehci_qh *qh)
1717 if (oxu_to_hcd(oxu)->
state != HC_STATE_HALT
1729 oxu->
reclaim = qh = qh_get(qh);
1743 end_unlink_async(oxu);
1754 static void scan_async(
struct oxu_hcd *oxu)
1759 if (!++(oxu->
stamp))
1763 qh = oxu->
async->qh_next.qh;
1778 temp = qh_completions(oxu, qh);
1795 start_unlink_async(oxu, qh);
1816 return &periodic->
qh->qh_next;
1821 static void periodic_unlink(
struct oxu_hcd *oxu,
unsigned frame,
void *ptr)
1828 while (here.
ptr && here.
ptr != ptr) {
1829 prev_p = periodic_next_shadow(prev_p,
Q_NEXT_TYPE(*hw_p));
1840 *prev_p = *periodic_next_shadow(&here,
Q_NEXT_TYPE(*hw_p));
1845 static unsigned short periodic_usecs(
struct oxu_hcd *oxu,
1846 unsigned frame,
unsigned uframe)
1858 usecs += q->
qh->usecs;
1861 usecs += q->
qh->c_usecs;
1862 hw_p = &q->
qh->hw_next;
1863 q = &q->
qh->qh_next;
1869 oxu_err(oxu,
"uframe %d sched overrun: %d usecs\n",
1870 frame * 8 + uframe, usecs);
1875 static int enable_periodic(
struct oxu_hcd *oxu)
1885 oxu_to_hcd(oxu)->state = HC_STATE_HALT;
1893 oxu_to_hcd(oxu)->state = HC_STATE_RUNNING;
1901 static int disable_periodic(
struct oxu_hcd *oxu)
1911 oxu_to_hcd(oxu)->state = HC_STATE_HALT;
1916 cmd =
readl(&oxu->
regs->command) & ~CMD_PSE;
1930 static int qh_link_periodic(
struct oxu_hcd *oxu,
struct ehci_qh *qh)
1936 "link qh%d-%04x/%p start %d [%d/%d us]\n",
1944 for (i = qh->
start; i < oxu->periodic_size; i += period) {
1955 prev = periodic_next_shadow(prev, type);
1956 hw_p = &here.
qh->hw_next;
1963 while (here.
ptr && qh != here.
qh) {
1966 prev = &here.
qh->qh_next;
1967 hw_p = &here.
qh->hw_next;
1971 if (qh != here.
qh) {
1984 oxu_to_hcd(oxu)->self.bandwidth_allocated += qh->
period
1990 return enable_periodic(oxu);
1995 static void qh_unlink_periodic(
struct oxu_hcd *oxu,
struct ehci_qh *qh)
2013 for (i = qh->
start; i < oxu->periodic_size; i += period)
2014 periodic_unlink(oxu, i, qh);
2017 oxu_to_hcd(oxu)->self.bandwidth_allocated -= qh->
period
2022 "unlink qh%d-%04x/%p start %d [%d/%d us]\n",
2035 (
void) disable_periodic(oxu);
2038 static void intr_deschedule(
struct oxu_hcd *oxu,
struct ehci_qh *qh)
2042 qh_unlink_periodic(oxu, qh);
2061 static int check_period(
struct oxu_hcd *oxu,
2062 unsigned frame,
unsigned uframe,
2063 unsigned period,
unsigned usecs)
2077 usecs = 100 -
usecs;
2084 for (uframe = 0; uframe < 7; uframe++) {
2085 claimed = periodic_usecs(oxu, frame, uframe);
2086 if (claimed > usecs)
2094 claimed = periodic_usecs(oxu, frame, uframe);
2095 if (claimed > usecs)
2103 static int check_intr_schedule(
struct oxu_hcd *oxu,
2104 unsigned frame,
unsigned uframe,
2109 if (qh->
c_usecs && uframe >= 6)
2112 if (!check_period(oxu, frame, uframe, qh->
period, qh->
usecs))
2134 qh_refresh(oxu, qh);
2141 status = check_intr_schedule(oxu, frame, --uframe,
2157 for (uframe = 0; uframe < 8; uframe++) {
2158 status = check_intr_schedule(oxu,
2164 }
while (status && frame--);
2169 status = check_intr_schedule(oxu, 0, 0, qh, &c_mask);
2182 oxu_dbg(oxu,
"reused qh %p schedule\n", qh);
2185 status = qh_link_periodic(oxu, qh);
2190 static int intr_submit(
struct oxu_hcd *oxu,
struct urb *urb,
2194 unsigned long flags;
2200 epnum = urb->ep->desc.bEndpointAddress;
2204 if (
unlikely(!HCD_HW_ACCESSIBLE(oxu_to_hcd(oxu)))) {
2210 INIT_LIST_HEAD(&
empty);
2211 qh = qh_append_tds(oxu, urb, &
empty, epnum, &urb->ep->hcpriv);
2217 status = qh_schedule(oxu, qh);
2223 qh = qh_append_tds(oxu, urb, qtd_list, epnum, &urb->ep->hcpriv);
2227 oxu_to_hcd(oxu)->self.bandwidth_int_reqs++;
2230 spin_unlock_irqrestore(&oxu->
lock, flags);
2232 qtd_list_free(oxu, urb, qtd_list);
2237 static inline int itd_submit(
struct oxu_hcd *oxu,
struct urb *urb,
2240 oxu_dbg(oxu,
"iso support is missing!\n");
2244 static inline int sitd_submit(
struct oxu_hcd *oxu,
struct urb *urb,
2247 oxu_dbg(oxu,
"split iso support is missing!\n");
2251 static void scan_periodic(
struct oxu_hcd *oxu)
2264 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->
state))
2267 clock = now_uframe + mod - 1;
2276 frame = now_uframe >> 3;
2277 if (frame == (clock >> 3))
2278 uframes = now_uframe & 0x07;
2297 live = HC_IS_RUNNING(oxu_to_hcd(oxu)->
state);
2301 temp.qh = qh_get(q.
qh);
2304 modified = qh_completions(oxu, temp.qh);
2305 if (
unlikely(list_empty(&temp.qh->qtd_list)))
2306 intr_deschedule(oxu, temp.qh);
2310 oxu_dbg(oxu,
"corrupt type %d frame %d shadow %p\n",
2311 type, frame, q.
ptr);
2331 if (now_uframe == clock) {
2334 if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->
state))
2338 if (now_uframe == now)
2354 static void ehci_turn_off_all_ports(
struct oxu_hcd *oxu)
2362 static void ehci_port_power(
struct oxu_hcd *oxu,
int is_on)
2369 oxu_dbg(oxu,
"...power%s ports...\n", is_on ?
"up" :
"down");
2371 (
void) oxu_hub_control(oxu_to_hcd(oxu),
2372 is_on ? SetPortFeature : ClearPortFeature,
2381 static void ehci_work(
struct oxu_hcd *oxu)
2385 end_unlink_async(oxu);
2403 if (HC_IS_RUNNING(oxu_to_hcd(oxu)->
state) &&
2409 static void unlink_async(
struct oxu_hcd *oxu,
struct ehci_qh *qh)
2414 && HC_IS_RUNNING(oxu_to_hcd(oxu)->
state)) {
2425 }
else if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->
state) && oxu->
reclaim)
2426 end_unlink_async(oxu);
2430 start_unlink_async(oxu, qh);
2437 static irqreturn_t oxu210_hcd_irq(
struct usb_hcd *hcd)
2439 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
2443 spin_lock(&oxu->
lock);
2448 if (status == ~(
u32) 0) {
2449 oxu_dbg(oxu,
"device removed\n");
2455 if (!status ||
unlikely(hcd->state == HC_STATE_HALT)) {
2456 spin_unlock(&oxu->
lock);
2465 #ifdef OXU_VERBOSE_DEBUG
2477 if (status & STS_IAA) {
2483 if (status & STS_PCD) {
2489 usb_hcd_resume_root_hub(hcd);
2492 int pstatus =
readl(&oxu->
regs->port_status[i]);
2494 if (pstatus & PORT_OWNER)
2496 if (!(pstatus & PORT_RESUME)
2505 oxu_dbg(oxu,
"port %d remote wakeup\n", i + 1);
2511 if (
unlikely((status & STS_FATAL) != 0)) {
2517 oxu_err(oxu,
"fatal error\n");
2531 spin_unlock(&oxu->
lock);
2532 if (pcd_status & STS_PCD)
2539 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
2550 oxu210_hcd_irq(hcd);
2560 static void oxu_watchdog(
unsigned long param)
2563 unsigned long flags;
2570 if (status & STS_IAA) {
2579 start_unlink_async(oxu, oxu->
async);
2584 spin_unlock_irqrestore(&oxu->
lock, flags);
2589 static int oxu_hcd_init(
struct usb_hcd *hcd)
2591 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
2599 oxu->
watchdog.function = oxu_watchdog;
2612 hcc_params =
readl(&oxu->
caps->hcc_params);
2638 if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
2639 log2_irq_thresh = 0;
2640 temp = 1 << (16 + log2_irq_thresh);
2650 park =
min(park, (
unsigned) 3);
2654 oxu_dbg(oxu,
"park %d\n", park);
2668 static int oxu_reset(
struct usb_hcd *hcd)
2670 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
2678 hcd->self.controller->dma_mask =
NULL;
2683 HC_LENGTH(
readl(&oxu->
caps->hc_capbase));
2689 HC_LENGTH(
readl(&oxu->
caps->hc_capbase));
2697 ret = oxu_hcd_init(hcd);
2704 static int oxu_run(
struct usb_hcd *hcd)
2706 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
2710 hcd->uses_new_polling = 1;
2713 retval = ehci_reset(oxu);
2715 ehci_mem_cleanup(oxu);
2732 hcc_params =
readl(&oxu->
caps->hcc_params);
2736 oxu->
command &= ~(CMD_LRESET | CMD_IAAD | CMD_PSE |
2748 hcd->state = HC_STATE_RUNNING;
2753 oxu_info(oxu,
"USB %x.%x started, quasi-EHCI %x.%02x, driver %s%s\n",
2754 ((oxu->
sbrn & 0xf0)>>4), (oxu->
sbrn & 0x0f),
2756 ignore_oc ?
", overcurrent ignored" :
"");
2763 static void oxu_stop(
struct usb_hcd *hcd)
2765 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
2768 ehci_port_power(oxu, 0);
2773 spin_lock_irq(&oxu->
lock);
2774 if (HC_IS_RUNNING(hcd->state))
2779 spin_unlock_irq(&oxu->
lock);
2785 spin_lock_irq(&oxu->
lock);
2788 spin_unlock_irq(&oxu->
lock);
2789 ehci_mem_cleanup(oxu);
2798 static void oxu_shutdown(
struct usb_hcd *hcd)
2800 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
2802 (
void) ehci_halt(oxu);
2803 ehci_turn_off_all_ports(oxu);
2823 static int __oxu_urb_enqueue(
struct usb_hcd *hcd,
struct urb *urb,
2826 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
2829 INIT_LIST_HEAD(&qtd_list);
2831 switch (usb_pipetype(urb->pipe)) {
2835 if (!qh_urb_transaction(oxu, urb, &qtd_list, mem_flags))
2837 return submit_async(oxu, urb, &qtd_list, mem_flags);
2839 case PIPE_INTERRUPT:
2840 if (!qh_urb_transaction(oxu, urb, &qtd_list, mem_flags))
2842 return intr_submit(oxu, urb, &qtd_list, mem_flags);
2844 case PIPE_ISOCHRONOUS:
2846 return itd_submit(oxu, urb, mem_flags);
2848 return sitd_submit(oxu, urb, mem_flags);
2855 static int oxu_urb_enqueue(
struct usb_hcd *hcd,
struct urb *urb,
2858 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
2860 int transfer_buffer_length;
2866 if (!usb_pipebulk(urb->pipe))
2867 return __oxu_urb_enqueue(hcd, urb, mem_flags);
2870 transfer_buffer = urb->transfer_buffer;
2871 transfer_buffer_length = urb->transfer_buffer_length;
2873 num = urb->transfer_buffer_length / 4096;
2874 rem = urb->transfer_buffer_length % 4096;
2880 return __oxu_urb_enqueue(hcd, urb, mem_flags);
2884 for (i = 0; i < num - 1; i++) {
2888 murb = (
struct urb *) oxu_murb_alloc(oxu);
2894 memcpy(murb, urb,
sizeof(
struct urb));
2896 murb->transfer_buffer_length = 4096;
2897 murb->transfer_buffer = transfer_buffer + i * 4096;
2900 murb->complete =
NULL;
2903 ((
struct oxu_murb *) murb)->last = 0;
2909 ret = __oxu_urb_enqueue(hcd, murb, mem_flags);
2919 murb = (
struct urb *) oxu_murb_alloc(oxu);
2925 memcpy(murb, urb,
sizeof(
struct urb));
2927 murb->transfer_buffer_length = rem > 0 ? rem : 4096;
2928 murb->transfer_buffer = transfer_buffer + (num - 1) * 4096;
2931 murb->complete =
NULL;
2934 ((
struct oxu_murb *) murb)->last = 1;
2937 ret = __oxu_urb_enqueue(hcd, murb, mem_flags);
2948 static int oxu_urb_dequeue(
struct usb_hcd *hcd,
struct urb *urb,
int status)
2950 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
2952 unsigned long flags;
2955 switch (usb_pipetype(urb->pipe)) {
2959 qh = (
struct ehci_qh *) urb->hcpriv;
2962 unlink_async(oxu, qh);
2965 case PIPE_INTERRUPT:
2966 qh = (
struct ehci_qh *) urb->hcpriv;
2971 intr_deschedule(oxu, qh);
2974 qh_completions(oxu, qh);
2977 oxu_dbg(oxu,
"bogus qh %p state %d\n",
2984 && HC_IS_RUNNING(hcd->state)) {
2987 status = qh_schedule(oxu, qh);
2988 spin_unlock_irqrestore(&oxu->
lock, flags);
2995 "can't reschedule qh %p, err %d\n", qh,
3003 spin_unlock_irqrestore(&oxu->
lock, flags);
3008 static void oxu_endpoint_disable(
struct usb_hcd *hcd,
3009 struct usb_host_endpoint *ep)
3011 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
3012 unsigned long flags;
3032 if (!HC_IS_RUNNING(hcd->state))
3036 for (tmp = oxu->
async->qh_next.qh;
3043 unlink_async(oxu, qh);
3047 spin_unlock_irqrestore(&oxu->
lock, flags);
3061 oxu_err(oxu,
"qh %p (#%02x) state %d%s\n",
3062 qh, ep->desc.bEndpointAddress, qh->
qh_state,
3063 list_empty(&qh->
qtd_list) ?
"" :
"(has tds)");
3068 spin_unlock_irqrestore(&oxu->
lock, flags);
3071 static int oxu_get_frame(
struct usb_hcd *hcd)
3073 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
3075 return (
readl(&oxu->
regs->frame_index) >> 3) %
3080 static int oxu_hub_status_data(
struct usb_hcd *hcd,
char *buf)
3082 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
3084 int ports,
i, retval = 1;
3085 unsigned long flags;
3088 if (!HC_IS_RUNNING(hcd->state))
3114 for (i = 0; i < ports; i++) {
3115 temp =
readl(&oxu->
regs->port_status[i]);
3124 if (!(temp & PORT_CONNECT))
3126 if ((temp & mask) != 0 || ((temp & PORT_RESUME) != 0 &&
3129 buf[0] |= 1 << (i + 1);
3131 buf[1] |= 1 << (i - 7);
3136 spin_unlock_irqrestore(&oxu->
lock, flags);
3137 return status ? retval : 0;
3141 static inline unsigned int oxu_port_speed(
struct oxu_hcd *oxu,
3142 unsigned int portsc)
3144 switch ((portsc >> 26) & 3) {
3155 #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
3156 static int oxu_hub_control(
struct usb_hcd *hcd,
u16 typeReq,
3159 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
3163 unsigned long flags;
3176 case ClearHubFeature:
3186 case ClearPortFeature:
3187 if (!wIndex || wIndex > ports)
3190 temp =
readl(status_reg);
3201 writel(temp & ~PORT_PE, status_reg);
3207 if (temp & PORT_RESET)
3209 if (temp & PORT_SUSPEND) {
3210 if ((temp & PORT_PE) == 0)
3214 writel(temp | PORT_RESUME, status_reg);
3241 case GetHubDescriptor:
3250 if (!wIndex || wIndex > ports)
3254 temp =
readl(status_reg);
3259 if (temp & PORT_PEC)
3261 if ((temp & PORT_OCC) && !ignore_oc)
3265 if (temp & PORT_RESUME) {
3284 temp =
readl(status_reg);
3288 PORT_RESUME, 0, 2000 );
3291 "port %d resume error %d\n",
3292 wIndex + 1, retval);
3295 temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10));
3300 if ((temp & PORT_RESET)
3313 PORT_RESET, 0, 750);
3315 oxu_err(oxu,
"port %d reset error %d\n",
3316 wIndex + 1, retval);
3321 temp = check_reset_complete(oxu, wIndex, status_reg,
3326 if ((temp & PORT_CONNECT) &&
3330 writel(temp, status_reg);
3331 oxu_dbg(oxu,
"port %d --> companion\n", wIndex + 1);
3332 temp =
readl(status_reg);
3341 if (temp & PORT_CONNECT) {
3344 status |= oxu_port_speed(oxu, temp);
3348 if (temp & (PORT_SUSPEND|PORT_RESUME))
3352 if (temp & PORT_RESET)
3354 if (temp & PORT_POWER)
3357 #ifndef OXU_VERBOSE_DEBUG
3358 if (status & ~0xffff)
3360 dbg_port(oxu,
"GetStatus", wIndex + 1, temp);
3373 case SetPortFeature:
3374 selector = wIndex >> 8;
3376 if (!wIndex || wIndex > ports)
3379 temp =
readl(status_reg);
3380 if (temp & PORT_OWNER)
3386 if ((temp & PORT_PE) == 0
3387 || (temp & PORT_RESET) != 0)
3389 if (device_may_wakeup(&hcd->self.root_hub->dev))
3391 writel(temp | PORT_SUSPEND, status_reg);
3395 writel(temp | PORT_POWER, status_reg);
3398 if (temp & PORT_RESUME)
3404 oxu_vdbg(oxu,
"port %d reset\n", wIndex + 1);
3414 writel(temp, status_reg);
3424 if (!selector || selector > 5)
3428 temp |= selector << 16;
3429 writel(temp, status_reg);
3443 spin_unlock_irqrestore(&oxu->
lock, flags);
3449 static int oxu_bus_suspend(
struct usb_hcd *hcd)
3451 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
3455 oxu_dbg(oxu,
"suspend root hub\n");
3461 spin_lock_irq(&oxu->
lock);
3464 if (HC_IS_RUNNING(hcd->state)) {
3466 hcd->state = HC_STATE_QUIESCING;
3485 if ((t1 & PORT_PE) && !(t1 & PORT_OWNER) &&
3486 !(t1 & PORT_SUSPEND)) {
3492 if (device_may_wakeup(&hcd->self.root_hub->dev))
3498 oxu_vdbg(oxu,
"port %d, %08x -> %08x\n",
3507 hcd->state = HC_STATE_SUSPENDED;
3511 if (!device_may_wakeup(&hcd->self.root_hub->dev))
3517 spin_unlock_irq(&oxu->
lock);
3522 static int oxu_bus_resume(
struct usb_hcd *hcd)
3524 struct oxu_hcd *oxu = hcd_to_oxu(hcd);
3530 spin_lock_irq(&oxu->
lock);
3539 oxu_dbg(oxu,
"resume root hub%s\n", temp ?
"" :
" after power loss");
3561 temp =
readl(&oxu->
regs->port_status[i]);
3573 temp =
readl(&oxu->
regs->port_status[i]);
3577 oxu_vdbg(oxu,
"resumed port %d\n", i + 1);
3584 if (oxu->
async->qh_next.qh)
3594 hcd->state = HC_STATE_RUNNING;
3599 spin_unlock_irq(&oxu->
lock);
3605 static int oxu_bus_suspend(
struct usb_hcd *hcd)
3610 static int oxu_bus_resume(
struct usb_hcd *hcd)
3617 static const struct hc_driver oxu_hc_driver = {
3618 .description =
"oxu210hp_hcd",
3619 .product_desc =
"oxu210hp HCD",
3620 .hcd_priv_size =
sizeof(
struct oxu_hcd),
3626 .flags = HCD_MEMORY | HCD_USB2,
3634 .shutdown = oxu_shutdown,
3639 .urb_enqueue = oxu_urb_enqueue,
3640 .urb_dequeue = oxu_urb_dequeue,
3641 .endpoint_disable = oxu_endpoint_disable,
3646 .get_frame_number = oxu_get_frame,
3651 .hub_status_data = oxu_hub_status_data,
3652 .hub_control = oxu_hub_control,
3653 .bus_suspend = oxu_bus_suspend,
3654 .bus_resume = oxu_bus_resume,
3661 static void oxu_configuration(
struct platform_device *pdev,
void *base)
3694 static const char *
const bo[] = {
3707 dev_info(&pdev->
dev,
"found device %x %s (%04x:%04x)\n",
3716 static const struct hc_driver oxu_hc_driver;
3718 unsigned long memstart,
unsigned long memlen,
3719 void *base,
int irq,
int otg)
3723 struct usb_hcd *hcd;
3733 otg ?
"oxu210hp_otg" :
"oxu210hp_sph");
3737 hcd->rsrc_start = memstart;
3738 hcd->rsrc_len = memlen;
3741 hcd->state = HC_STATE_HALT;
3743 oxu = hcd_to_oxu(hcd);
3748 return ERR_PTR(ret);
3754 unsigned long memstart,
unsigned long memlen,
3755 void *base,
int irq)
3758 struct usb_hcd *hcd;
3762 oxu_configuration(pdev, base);
3764 ret = oxu_verify_id(pdev, base);
3771 hcd = oxu_create(pdev, memstart, memlen, base, irq, 1);
3773 dev_err(&pdev->
dev,
"cannot create OTG controller!\n");
3775 goto error_create_otg;
3780 hcd = oxu_create(pdev, memstart, memlen, base, irq, 0);
3782 dev_err(&pdev->
dev,
"cannot create SPH controller!\n");
3784 goto error_create_sph;
3805 unsigned long memstart, memlen;
3818 "no IRQ! Check %s setup!\n", dev_name(&pdev->
dev));
3822 dev_dbg(&pdev->
dev,
"IRQ resource %d\n", irq);
3826 dev_err(&pdev->
dev,
"no registers address! Check %s setup!\n",
3827 dev_name(&pdev->
dev));
3830 memstart = res->
start;
3831 memlen = resource_size(res);
3832 dev_dbg(&pdev->
dev,
"MEM resource %lx-%lx\n", memstart, memlen);
3834 oxu_hc_driver.description)) {
3835 dev_dbg(&pdev->
dev,
"memory area already in use\n");
3841 dev_err(&pdev->
dev,
"error setting irq type\n");
3843 goto error_set_irq_type;
3846 base =
ioremap(memstart, memlen);
3848 dev_dbg(&pdev->
dev,
"error mapping memory\n");
3858 dev_dbg(&pdev->
dev,
"error allocating memory\n");
3862 platform_set_drvdata(pdev, info);
3864 ret = oxu_init(pdev, memstart, memlen, base, irq);
3866 dev_dbg(&pdev->
dev,
"cannot init USB devices\n");
3870 dev_info(&pdev->
dev,
"devices enabled and running\n");
3871 platform_set_drvdata(pdev, info);
3877 platform_set_drvdata(pdev,
NULL);
3886 dev_err(&pdev->
dev,
"init %s fail, %d\n", dev_name(&pdev->
dev), ret);
3890 static void oxu_remove(
struct platform_device *pdev,
struct usb_hcd *hcd)
3898 struct oxu_info *info = platform_get_drvdata(pdev);
3899 unsigned long memstart = info->
hcd[0]->rsrc_start,
3900 memlen = info->
hcd[0]->rsrc_len;
3901 void *base = info->
hcd[0]->regs;
3903 oxu_remove(pdev, info->
hcd[0]);
3904 oxu_remove(pdev, info->
hcd[1]);
3910 platform_set_drvdata(pdev,
NULL);
3917 oxu_drv_remove(pdev);
3938 #define oxu_drv_suspend NULL
3939 #define oxu_drv_resume NULL
3943 .probe = oxu_drv_probe,
3944 .remove = oxu_drv_remove,
3945 .shutdown = oxu_drv_shutdown,
3949 .name =
"oxu210hp-hcd",