diff options
Diffstat (limited to 'drivers/usb/host')
-rw-r--r-- | drivers/usb/host/Kconfig | 28 | ||||
-rw-r--r-- | drivers/usb/host/Makefile | 2 | ||||
-rw-r--r-- | drivers/usb/host/ehci-dbg.c | 183 | ||||
-rw-r--r-- | drivers/usb/host/ehci-fsl.c | 10 | ||||
-rw-r--r-- | drivers/usb/host/ehci-hcd.c | 118 | ||||
-rw-r--r-- | drivers/usb/host/ehci-hub.c | 122 | ||||
-rw-r--r-- | drivers/usb/host/ehci-mem.c | 27 | ||||
-rw-r--r-- | drivers/usb/host/ehci-pci.c | 7 | ||||
-rw-r--r-- | drivers/usb/host/ehci-ppc-soc.c | 182 | ||||
-rw-r--r-- | drivers/usb/host/ehci-ps3.c | 86 | ||||
-rw-r--r-- | drivers/usb/host/ehci-q.c | 96 | ||||
-rw-r--r-- | drivers/usb/host/ehci-sched.c | 339 | ||||
-rw-r--r-- | drivers/usb/host/ehci.h | 234 | ||||
-rw-r--r-- | drivers/usb/host/ohci-dbg.c | 4 | ||||
-rw-r--r-- | drivers/usb/host/ohci-hcd.c | 92 | ||||
-rw-r--r-- | drivers/usb/host/ohci-hub.c | 5 | ||||
-rw-r--r-- | drivers/usb/host/ohci-mem.c | 1 | ||||
-rw-r--r-- | drivers/usb/host/ohci-pci.c | 57 | ||||
-rw-r--r-- | drivers/usb/host/ohci-pnx4008.c | 2 | ||||
-rw-r--r-- | drivers/usb/host/ohci-ps3.c | 87 | ||||
-rw-r--r-- | drivers/usb/host/ohci.h | 2 | ||||
-rw-r--r-- | drivers/usb/host/r8a66597-hcd.c | 2244 | ||||
-rw-r--r-- | drivers/usb/host/r8a66597.h | 634 | ||||
-rw-r--r-- | drivers/usb/host/uhci-hcd.c | 5 |
24 files changed, 4157 insertions, 410 deletions
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 62711870f8ee..2f529828c74d 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig | |||
@@ -69,8 +69,20 @@ config USB_EHCI_TT_NEWSCHED | |||
69 | 69 | ||
70 | config USB_EHCI_BIG_ENDIAN_MMIO | 70 | config USB_EHCI_BIG_ENDIAN_MMIO |
71 | bool | 71 | bool |
72 | depends on USB_EHCI_HCD | 72 | depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX) |
73 | default n | 73 | default y |
74 | |||
75 | config USB_EHCI_BIG_ENDIAN_DESC | ||
76 | bool | ||
77 | depends on USB_EHCI_HCD && 440EPX | ||
78 | default y | ||
79 | |||
80 | config USB_EHCI_FSL | ||
81 | bool | ||
82 | select USB_EHCI_ROOT_HUB_TT | ||
83 | default y if MPC834x || PPC_MPC831x | ||
84 | ---help--- | ||
85 | Variation of ARC USB block used in some Freescale chips. | ||
74 | 86 | ||
75 | config USB_ISP116X_HCD | 87 | config USB_ISP116X_HCD |
76 | tristate "ISP116X HCD support" | 88 | tristate "ISP116X HCD support" |
@@ -224,3 +236,15 @@ config USB_SL811_CS | |||
224 | To compile this driver as a module, choose M here: the | 236 | To compile this driver as a module, choose M here: the |
225 | module will be called "sl811_cs". | 237 | module will be called "sl811_cs". |
226 | 238 | ||
239 | config USB_R8A66597_HCD | ||
240 | tristate "R8A66597 HCD suppoort" | ||
241 | depends on USB | ||
242 | help | ||
243 | The R8A66597 is a USB 2.0 host and peripheral controller. | ||
244 | |||
245 | Enable this option if your board has this chip, and you want | ||
246 | to use it as a host controller. If unsure, say N. | ||
247 | |||
248 | To compile this driver as a module, choose M here: the | ||
249 | module will be called r8a66597-hcd. | ||
250 | |||
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 2ff396bd180f..bb8e9d44f371 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile | |||
@@ -15,3 +15,5 @@ obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o | |||
15 | obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o | 15 | obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o |
16 | obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o | 16 | obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o |
17 | obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o | 17 | obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o |
18 | obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o | ||
19 | |||
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c index 43eddaecc3dd..c9cc4413198e 100644 --- a/drivers/usb/host/ehci-dbg.c +++ b/drivers/usb/host/ehci-dbg.c | |||
@@ -52,7 +52,7 @@ static void dbg_hcs_params (struct ehci_hcd *ehci, char *label) | |||
52 | HCS_INDICATOR (params) ? " ind" : "", | 52 | HCS_INDICATOR (params) ? " ind" : "", |
53 | HCS_N_CC (params), | 53 | HCS_N_CC (params), |
54 | HCS_N_PCC (params), | 54 | HCS_N_PCC (params), |
55 | HCS_PORTROUTED (params) ? "" : " ordered", | 55 | HCS_PORTROUTED (params) ? "" : " ordered", |
56 | HCS_PPC (params) ? "" : " !ppc", | 56 | HCS_PPC (params) ? "" : " !ppc", |
57 | HCS_N_PORTS (params) | 57 | HCS_N_PORTS (params) |
58 | ); | 58 | ); |
@@ -91,20 +91,20 @@ static void dbg_hcc_params (struct ehci_hcd *ehci, char *label) | |||
91 | 91 | ||
92 | if (HCC_ISOC_CACHE (params)) { | 92 | if (HCC_ISOC_CACHE (params)) { |
93 | ehci_dbg (ehci, | 93 | ehci_dbg (ehci, |
94 | "%s hcc_params %04x caching frame %s%s%s\n", | 94 | "%s hcc_params %04x caching frame %s%s%s\n", |
95 | label, params, | 95 | label, params, |
96 | HCC_PGM_FRAMELISTLEN (params) ? "256/512/1024" : "1024", | 96 | HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", |
97 | HCC_CANPARK (params) ? " park" : "", | 97 | HCC_CANPARK(params) ? " park" : "", |
98 | HCC_64BIT_ADDR (params) ? " 64 bit addr" : ""); | 98 | HCC_64BIT_ADDR(params) ? " 64 bit addr" : ""); |
99 | } else { | 99 | } else { |
100 | ehci_dbg (ehci, | 100 | ehci_dbg (ehci, |
101 | "%s hcc_params %04x thresh %d uframes %s%s%s\n", | 101 | "%s hcc_params %04x thresh %d uframes %s%s%s\n", |
102 | label, | 102 | label, |
103 | params, | 103 | params, |
104 | HCC_ISOC_THRES (params), | 104 | HCC_ISOC_THRES(params), |
105 | HCC_PGM_FRAMELISTLEN (params) ? "256/512/1024" : "1024", | 105 | HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", |
106 | HCC_CANPARK (params) ? " park" : "", | 106 | HCC_CANPARK(params) ? " park" : "", |
107 | HCC_64BIT_ADDR (params) ? " 64 bit addr" : ""); | 107 | HCC_64BIT_ADDR(params) ? " 64 bit addr" : ""); |
108 | } | 108 | } |
109 | } | 109 | } |
110 | #else | 110 | #else |
@@ -115,23 +115,23 @@ static inline void dbg_hcc_params (struct ehci_hcd *ehci, char *label) {} | |||
115 | 115 | ||
116 | #ifdef DEBUG | 116 | #ifdef DEBUG |
117 | 117 | ||
118 | static void __attribute__((__unused__)) | 118 | static void __maybe_unused |
119 | dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd) | 119 | dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd) |
120 | { | 120 | { |
121 | ehci_dbg (ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd, | 121 | ehci_dbg(ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd, |
122 | le32_to_cpup (&qtd->hw_next), | 122 | hc32_to_cpup(ehci, &qtd->hw_next), |
123 | le32_to_cpup (&qtd->hw_alt_next), | 123 | hc32_to_cpup(ehci, &qtd->hw_alt_next), |
124 | le32_to_cpup (&qtd->hw_token), | 124 | hc32_to_cpup(ehci, &qtd->hw_token), |
125 | le32_to_cpup (&qtd->hw_buf [0])); | 125 | hc32_to_cpup(ehci, &qtd->hw_buf [0])); |
126 | if (qtd->hw_buf [1]) | 126 | if (qtd->hw_buf [1]) |
127 | ehci_dbg (ehci, " p1=%08x p2=%08x p3=%08x p4=%08x\n", | 127 | ehci_dbg(ehci, " p1=%08x p2=%08x p3=%08x p4=%08x\n", |
128 | le32_to_cpup (&qtd->hw_buf [1]), | 128 | hc32_to_cpup(ehci, &qtd->hw_buf[1]), |
129 | le32_to_cpup (&qtd->hw_buf [2]), | 129 | hc32_to_cpup(ehci, &qtd->hw_buf[2]), |
130 | le32_to_cpup (&qtd->hw_buf [3]), | 130 | hc32_to_cpup(ehci, &qtd->hw_buf[3]), |
131 | le32_to_cpup (&qtd->hw_buf [4])); | 131 | hc32_to_cpup(ehci, &qtd->hw_buf[4])); |
132 | } | 132 | } |
133 | 133 | ||
134 | static void __attribute__((__unused__)) | 134 | static void __maybe_unused |
135 | dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) | 135 | dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) |
136 | { | 136 | { |
137 | ehci_dbg (ehci, "%s qh %p n%08x info %x %x qtd %x\n", label, | 137 | ehci_dbg (ehci, "%s qh %p n%08x info %x %x qtd %x\n", label, |
@@ -140,51 +140,53 @@ dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
140 | dbg_qtd ("overlay", ehci, (struct ehci_qtd *) &qh->hw_qtd_next); | 140 | dbg_qtd ("overlay", ehci, (struct ehci_qtd *) &qh->hw_qtd_next); |
141 | } | 141 | } |
142 | 142 | ||
143 | static void __attribute__((__unused__)) | 143 | static void __maybe_unused |
144 | dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd) | 144 | dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd) |
145 | { | 145 | { |
146 | ehci_dbg (ehci, "%s [%d] itd %p, next %08x, urb %p\n", | 146 | ehci_dbg (ehci, "%s [%d] itd %p, next %08x, urb %p\n", |
147 | label, itd->frame, itd, le32_to_cpu(itd->hw_next), itd->urb); | 147 | label, itd->frame, itd, hc32_to_cpu(ehci, itd->hw_next), |
148 | itd->urb); | ||
148 | ehci_dbg (ehci, | 149 | ehci_dbg (ehci, |
149 | " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n", | 150 | " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n", |
150 | le32_to_cpu(itd->hw_transaction[0]), | 151 | hc32_to_cpu(ehci, itd->hw_transaction[0]), |
151 | le32_to_cpu(itd->hw_transaction[1]), | 152 | hc32_to_cpu(ehci, itd->hw_transaction[1]), |
152 | le32_to_cpu(itd->hw_transaction[2]), | 153 | hc32_to_cpu(ehci, itd->hw_transaction[2]), |
153 | le32_to_cpu(itd->hw_transaction[3]), | 154 | hc32_to_cpu(ehci, itd->hw_transaction[3]), |
154 | le32_to_cpu(itd->hw_transaction[4]), | 155 | hc32_to_cpu(ehci, itd->hw_transaction[4]), |
155 | le32_to_cpu(itd->hw_transaction[5]), | 156 | hc32_to_cpu(ehci, itd->hw_transaction[5]), |
156 | le32_to_cpu(itd->hw_transaction[6]), | 157 | hc32_to_cpu(ehci, itd->hw_transaction[6]), |
157 | le32_to_cpu(itd->hw_transaction[7])); | 158 | hc32_to_cpu(ehci, itd->hw_transaction[7])); |
158 | ehci_dbg (ehci, | 159 | ehci_dbg (ehci, |
159 | " buf: %08x %08x %08x %08x %08x %08x %08x\n", | 160 | " buf: %08x %08x %08x %08x %08x %08x %08x\n", |
160 | le32_to_cpu(itd->hw_bufp[0]), | 161 | hc32_to_cpu(ehci, itd->hw_bufp[0]), |
161 | le32_to_cpu(itd->hw_bufp[1]), | 162 | hc32_to_cpu(ehci, itd->hw_bufp[1]), |
162 | le32_to_cpu(itd->hw_bufp[2]), | 163 | hc32_to_cpu(ehci, itd->hw_bufp[2]), |
163 | le32_to_cpu(itd->hw_bufp[3]), | 164 | hc32_to_cpu(ehci, itd->hw_bufp[3]), |
164 | le32_to_cpu(itd->hw_bufp[4]), | 165 | hc32_to_cpu(ehci, itd->hw_bufp[4]), |
165 | le32_to_cpu(itd->hw_bufp[5]), | 166 | hc32_to_cpu(ehci, itd->hw_bufp[5]), |
166 | le32_to_cpu(itd->hw_bufp[6])); | 167 | hc32_to_cpu(ehci, itd->hw_bufp[6])); |
167 | ehci_dbg (ehci, " index: %d %d %d %d %d %d %d %d\n", | 168 | ehci_dbg (ehci, " index: %d %d %d %d %d %d %d %d\n", |
168 | itd->index[0], itd->index[1], itd->index[2], | 169 | itd->index[0], itd->index[1], itd->index[2], |
169 | itd->index[3], itd->index[4], itd->index[5], | 170 | itd->index[3], itd->index[4], itd->index[5], |
170 | itd->index[6], itd->index[7]); | 171 | itd->index[6], itd->index[7]); |
171 | } | 172 | } |
172 | 173 | ||
173 | static void __attribute__((__unused__)) | 174 | static void __maybe_unused |
174 | dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd) | 175 | dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd) |
175 | { | 176 | { |
176 | ehci_dbg (ehci, "%s [%d] sitd %p, next %08x, urb %p\n", | 177 | ehci_dbg (ehci, "%s [%d] sitd %p, next %08x, urb %p\n", |
177 | label, sitd->frame, sitd, le32_to_cpu(sitd->hw_next), sitd->urb); | 178 | label, sitd->frame, sitd, hc32_to_cpu(ehci, sitd->hw_next), |
179 | sitd->urb); | ||
178 | ehci_dbg (ehci, | 180 | ehci_dbg (ehci, |
179 | " addr %08x sched %04x result %08x buf %08x %08x\n", | 181 | " addr %08x sched %04x result %08x buf %08x %08x\n", |
180 | le32_to_cpu(sitd->hw_fullspeed_ep), | 182 | hc32_to_cpu(ehci, sitd->hw_fullspeed_ep), |
181 | le32_to_cpu(sitd->hw_uframe), | 183 | hc32_to_cpu(ehci, sitd->hw_uframe), |
182 | le32_to_cpu(sitd->hw_results), | 184 | hc32_to_cpu(ehci, sitd->hw_results), |
183 | le32_to_cpu(sitd->hw_buf [0]), | 185 | hc32_to_cpu(ehci, sitd->hw_buf[0]), |
184 | le32_to_cpu(sitd->hw_buf [1])); | 186 | hc32_to_cpu(ehci, sitd->hw_buf[1])); |
185 | } | 187 | } |
186 | 188 | ||
187 | static int __attribute__((__unused__)) | 189 | static int __maybe_unused |
188 | dbg_status_buf (char *buf, unsigned len, const char *label, u32 status) | 190 | dbg_status_buf (char *buf, unsigned len, const char *label, u32 status) |
189 | { | 191 | { |
190 | return scnprintf (buf, len, | 192 | return scnprintf (buf, len, |
@@ -203,7 +205,7 @@ dbg_status_buf (char *buf, unsigned len, const char *label, u32 status) | |||
203 | ); | 205 | ); |
204 | } | 206 | } |
205 | 207 | ||
206 | static int __attribute__((__unused__)) | 208 | static int __maybe_unused |
207 | dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable) | 209 | dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable) |
208 | { | 210 | { |
209 | return scnprintf (buf, len, | 211 | return scnprintf (buf, len, |
@@ -267,28 +269,27 @@ dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status) | |||
267 | (status & PORT_PEC) ? " PEC" : "", | 269 | (status & PORT_PEC) ? " PEC" : "", |
268 | (status & PORT_PE) ? " PE" : "", | 270 | (status & PORT_PE) ? " PE" : "", |
269 | (status & PORT_CSC) ? " CSC" : "", | 271 | (status & PORT_CSC) ? " CSC" : "", |
270 | (status & PORT_CONNECT) ? " CONNECT" : "" | 272 | (status & PORT_CONNECT) ? " CONNECT" : ""); |
271 | ); | ||
272 | } | 273 | } |
273 | 274 | ||
274 | #else | 275 | #else |
275 | static inline void __attribute__((__unused__)) | 276 | static inline void __maybe_unused |
276 | dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) | 277 | dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) |
277 | {} | 278 | {} |
278 | 279 | ||
279 | static inline int __attribute__((__unused__)) | 280 | static inline int __maybe_unused |
280 | dbg_status_buf (char *buf, unsigned len, const char *label, u32 status) | 281 | dbg_status_buf (char *buf, unsigned len, const char *label, u32 status) |
281 | { return 0; } | 282 | { return 0; } |
282 | 283 | ||
283 | static inline int __attribute__((__unused__)) | 284 | static inline int __maybe_unused |
284 | dbg_command_buf (char *buf, unsigned len, const char *label, u32 command) | 285 | dbg_command_buf (char *buf, unsigned len, const char *label, u32 command) |
285 | { return 0; } | 286 | { return 0; } |
286 | 287 | ||
287 | static inline int __attribute__((__unused__)) | 288 | static inline int __maybe_unused |
288 | dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable) | 289 | dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable) |
289 | { return 0; } | 290 | { return 0; } |
290 | 291 | ||
291 | static inline int __attribute__((__unused__)) | 292 | static inline int __maybe_unused |
292 | dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status) | 293 | dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status) |
293 | { return 0; } | 294 | { return 0; } |
294 | 295 | ||
@@ -332,9 +333,10 @@ static inline void remove_debug_files (struct ehci_hcd *bus) { } | |||
332 | default: tmp = '?'; break; \ | 333 | default: tmp = '?'; break; \ |
333 | }; tmp; }) | 334 | }; tmp; }) |
334 | 335 | ||
335 | static inline char token_mark (__le32 token) | 336 | static inline char token_mark(struct ehci_hcd *ehci, __hc32 token) |
336 | { | 337 | { |
337 | __u32 v = le32_to_cpu (token); | 338 | __u32 v = hc32_to_cpu(ehci, token); |
339 | |||
338 | if (v & QTD_STS_ACTIVE) | 340 | if (v & QTD_STS_ACTIVE) |
339 | return '*'; | 341 | return '*'; |
340 | if (v & QTD_STS_HALT) | 342 | if (v & QTD_STS_HALT) |
@@ -360,46 +362,48 @@ static void qh_lines ( | |||
360 | unsigned size = *sizep; | 362 | unsigned size = *sizep; |
361 | char *next = *nextp; | 363 | char *next = *nextp; |
362 | char mark; | 364 | char mark; |
365 | u32 list_end = EHCI_LIST_END(ehci); | ||
363 | 366 | ||
364 | if (qh->hw_qtd_next == EHCI_LIST_END) /* NEC does this */ | 367 | if (qh->hw_qtd_next == list_end) /* NEC does this */ |
365 | mark = '@'; | 368 | mark = '@'; |
366 | else | 369 | else |
367 | mark = token_mark (qh->hw_token); | 370 | mark = token_mark(ehci, qh->hw_token); |
368 | if (mark == '/') { /* qh_alt_next controls qh advance? */ | 371 | if (mark == '/') { /* qh_alt_next controls qh advance? */ |
369 | if ((qh->hw_alt_next & QTD_MASK) == ehci->async->hw_alt_next) | 372 | if ((qh->hw_alt_next & QTD_MASK(ehci)) |
373 | == ehci->async->hw_alt_next) | ||
370 | mark = '#'; /* blocked */ | 374 | mark = '#'; /* blocked */ |
371 | else if (qh->hw_alt_next == EHCI_LIST_END) | 375 | else if (qh->hw_alt_next == list_end) |
372 | mark = '.'; /* use hw_qtd_next */ | 376 | mark = '.'; /* use hw_qtd_next */ |
373 | /* else alt_next points to some other qtd */ | 377 | /* else alt_next points to some other qtd */ |
374 | } | 378 | } |
375 | scratch = le32_to_cpup (&qh->hw_info1); | 379 | scratch = hc32_to_cpup(ehci, &qh->hw_info1); |
376 | hw_curr = (mark == '*') ? le32_to_cpup (&qh->hw_current) : 0; | 380 | hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &qh->hw_current) : 0; |
377 | temp = scnprintf (next, size, | 381 | temp = scnprintf (next, size, |
378 | "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)", | 382 | "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)", |
379 | qh, scratch & 0x007f, | 383 | qh, scratch & 0x007f, |
380 | speed_char (scratch), | 384 | speed_char (scratch), |
381 | (scratch >> 8) & 0x000f, | 385 | (scratch >> 8) & 0x000f, |
382 | scratch, le32_to_cpup (&qh->hw_info2), | 386 | scratch, hc32_to_cpup(ehci, &qh->hw_info2), |
383 | le32_to_cpup (&qh->hw_token), mark, | 387 | hc32_to_cpup(ehci, &qh->hw_token), mark, |
384 | (__constant_cpu_to_le32 (QTD_TOGGLE) & qh->hw_token) | 388 | (cpu_to_hc32(ehci, QTD_TOGGLE) & qh->hw_token) |
385 | ? "data1" : "data0", | 389 | ? "data1" : "data0", |
386 | (le32_to_cpup (&qh->hw_alt_next) >> 1) & 0x0f); | 390 | (hc32_to_cpup(ehci, &qh->hw_alt_next) >> 1) & 0x0f); |
387 | size -= temp; | 391 | size -= temp; |
388 | next += temp; | 392 | next += temp; |
389 | 393 | ||
390 | /* hc may be modifying the list as we read it ... */ | 394 | /* hc may be modifying the list as we read it ... */ |
391 | list_for_each (entry, &qh->qtd_list) { | 395 | list_for_each (entry, &qh->qtd_list) { |
392 | td = list_entry (entry, struct ehci_qtd, qtd_list); | 396 | td = list_entry (entry, struct ehci_qtd, qtd_list); |
393 | scratch = le32_to_cpup (&td->hw_token); | 397 | scratch = hc32_to_cpup(ehci, &td->hw_token); |
394 | mark = ' '; | 398 | mark = ' '; |
395 | if (hw_curr == td->qtd_dma) | 399 | if (hw_curr == td->qtd_dma) |
396 | mark = '*'; | 400 | mark = '*'; |
397 | else if (qh->hw_qtd_next == cpu_to_le32(td->qtd_dma)) | 401 | else if (qh->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma)) |
398 | mark = '+'; | 402 | mark = '+'; |
399 | else if (QTD_LENGTH (scratch)) { | 403 | else if (QTD_LENGTH (scratch)) { |
400 | if (td->hw_alt_next == ehci->async->hw_alt_next) | 404 | if (td->hw_alt_next == ehci->async->hw_alt_next) |
401 | mark = '#'; | 405 | mark = '#'; |
402 | else if (td->hw_alt_next != EHCI_LIST_END) | 406 | else if (td->hw_alt_next != list_end) |
403 | mark = '/'; | 407 | mark = '/'; |
404 | } | 408 | } |
405 | temp = snprintf (next, size, | 409 | temp = snprintf (next, size, |
@@ -490,7 +494,7 @@ show_periodic (struct class_device *class_dev, char *buf) | |||
490 | unsigned temp, size, seen_count; | 494 | unsigned temp, size, seen_count; |
491 | char *next; | 495 | char *next; |
492 | unsigned i; | 496 | unsigned i; |
493 | __le32 tag; | 497 | __hc32 tag; |
494 | 498 | ||
495 | if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC))) | 499 | if (!(seen = kmalloc (DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC))) |
496 | return 0; | 500 | return 0; |
@@ -514,18 +518,19 @@ show_periodic (struct class_device *class_dev, char *buf) | |||
514 | p = ehci->pshadow [i]; | 518 | p = ehci->pshadow [i]; |
515 | if (likely (!p.ptr)) | 519 | if (likely (!p.ptr)) |
516 | continue; | 520 | continue; |
517 | tag = Q_NEXT_TYPE (ehci->periodic [i]); | 521 | tag = Q_NEXT_TYPE(ehci, ehci->periodic [i]); |
518 | 522 | ||
519 | temp = scnprintf (next, size, "%4d: ", i); | 523 | temp = scnprintf (next, size, "%4d: ", i); |
520 | size -= temp; | 524 | size -= temp; |
521 | next += temp; | 525 | next += temp; |
522 | 526 | ||
523 | do { | 527 | do { |
524 | switch (tag) { | 528 | switch (hc32_to_cpu(ehci, tag)) { |
525 | case Q_TYPE_QH: | 529 | case Q_TYPE_QH: |
526 | temp = scnprintf (next, size, " qh%d-%04x/%p", | 530 | temp = scnprintf (next, size, " qh%d-%04x/%p", |
527 | p.qh->period, | 531 | p.qh->period, |
528 | le32_to_cpup (&p.qh->hw_info2) | 532 | hc32_to_cpup(ehci, |
533 | &p.qh->hw_info2) | ||
529 | /* uframe masks */ | 534 | /* uframe masks */ |
530 | & (QH_CMASK | QH_SMASK), | 535 | & (QH_CMASK | QH_SMASK), |
531 | p.qh); | 536 | p.qh); |
@@ -543,7 +548,7 @@ show_periodic (struct class_device *class_dev, char *buf) | |||
543 | } | 548 | } |
544 | /* show more info the first time around */ | 549 | /* show more info the first time around */ |
545 | if (temp == seen_count && p.ptr) { | 550 | if (temp == seen_count && p.ptr) { |
546 | u32 scratch = le32_to_cpup ( | 551 | u32 scratch = hc32_to_cpup(ehci, |
547 | &p.qh->hw_info1); | 552 | &p.qh->hw_info1); |
548 | struct ehci_qtd *qtd; | 553 | struct ehci_qtd *qtd; |
549 | char *type = ""; | 554 | char *type = ""; |
@@ -554,7 +559,8 @@ show_periodic (struct class_device *class_dev, char *buf) | |||
554 | &p.qh->qtd_list, | 559 | &p.qh->qtd_list, |
555 | qtd_list) { | 560 | qtd_list) { |
556 | temp++; | 561 | temp++; |
557 | switch (0x03 & (le32_to_cpu ( | 562 | switch (0x03 & (hc32_to_cpu( |
563 | ehci, | ||
558 | qtd->hw_token) >> 8)) { | 564 | qtd->hw_token) >> 8)) { |
559 | case 0: type = "out"; continue; | 565 | case 0: type = "out"; continue; |
560 | case 1: type = "in"; continue; | 566 | case 1: type = "in"; continue; |
@@ -576,7 +582,7 @@ show_periodic (struct class_device *class_dev, char *buf) | |||
576 | } else | 582 | } else |
577 | temp = 0; | 583 | temp = 0; |
578 | if (p.qh) { | 584 | if (p.qh) { |
579 | tag = Q_NEXT_TYPE (p.qh->hw_next); | 585 | tag = Q_NEXT_TYPE(ehci, p.qh->hw_next); |
580 | p = p.qh->qh_next; | 586 | p = p.qh->qh_next; |
581 | } | 587 | } |
582 | break; | 588 | break; |
@@ -584,23 +590,23 @@ show_periodic (struct class_device *class_dev, char *buf) | |||
584 | temp = scnprintf (next, size, | 590 | temp = scnprintf (next, size, |
585 | " fstn-%8x/%p", p.fstn->hw_prev, | 591 | " fstn-%8x/%p", p.fstn->hw_prev, |
586 | p.fstn); | 592 | p.fstn); |
587 | tag = Q_NEXT_TYPE (p.fstn->hw_next); | 593 | tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next); |
588 | p = p.fstn->fstn_next; | 594 | p = p.fstn->fstn_next; |
589 | break; | 595 | break; |
590 | case Q_TYPE_ITD: | 596 | case Q_TYPE_ITD: |
591 | temp = scnprintf (next, size, | 597 | temp = scnprintf (next, size, |
592 | " itd/%p", p.itd); | 598 | " itd/%p", p.itd); |
593 | tag = Q_NEXT_TYPE (p.itd->hw_next); | 599 | tag = Q_NEXT_TYPE(ehci, p.itd->hw_next); |
594 | p = p.itd->itd_next; | 600 | p = p.itd->itd_next; |
595 | break; | 601 | break; |
596 | case Q_TYPE_SITD: | 602 | case Q_TYPE_SITD: |
597 | temp = scnprintf (next, size, | 603 | temp = scnprintf (next, size, |
598 | " sitd%d-%04x/%p", | 604 | " sitd%d-%04x/%p", |
599 | p.sitd->stream->interval, | 605 | p.sitd->stream->interval, |
600 | le32_to_cpup (&p.sitd->hw_uframe) | 606 | hc32_to_cpup(ehci, &p.sitd->hw_uframe) |
601 | & 0x0000ffff, | 607 | & 0x0000ffff, |
602 | p.sitd); | 608 | p.sitd); |
603 | tag = Q_NEXT_TYPE (p.sitd->hw_next); | 609 | tag = Q_NEXT_TYPE(ehci, p.sitd->hw_next); |
604 | p = p.sitd->sitd_next; | 610 | p = p.sitd->sitd_next; |
605 | break; | 611 | break; |
606 | } | 612 | } |
@@ -673,7 +679,8 @@ show_registers (struct class_device *class_dev, char *buf) | |||
673 | unsigned count = 256/4; | 679 | unsigned count = 256/4; |
674 | 680 | ||
675 | pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller); | 681 | pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller); |
676 | offset = HCC_EXT_CAPS (ehci_readl(ehci, &ehci->caps->hcc_params)); | 682 | offset = HCC_EXT_CAPS(ehci_readl(ehci, |
683 | &ehci->caps->hcc_params)); | ||
677 | while (offset && count--) { | 684 | while (offset && count--) { |
678 | pci_read_config_dword (pdev, offset, &cap); | 685 | pci_read_config_dword (pdev, offset, &cap); |
679 | switch (cap & 0xff) { | 686 | switch (cap & 0xff) { |
@@ -740,14 +747,16 @@ show_registers (struct class_device *class_dev, char *buf) | |||
740 | 747 | ||
741 | for (i = 1; i <= HCS_N_PORTS (ehci->hcs_params); i++) { | 748 | for (i = 1; i <= HCS_N_PORTS (ehci->hcs_params); i++) { |
742 | temp = dbg_port_buf (scratch, sizeof scratch, label, i, | 749 | temp = dbg_port_buf (scratch, sizeof scratch, label, i, |
743 | ehci_readl(ehci, &ehci->regs->port_status [i - 1])); | 750 | ehci_readl(ehci, |
751 | &ehci->regs->port_status[i - 1])); | ||
744 | temp = scnprintf (next, size, fmt, temp, scratch); | 752 | temp = scnprintf (next, size, fmt, temp, scratch); |
745 | size -= temp; | 753 | size -= temp; |
746 | next += temp; | 754 | next += temp; |
747 | if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) { | 755 | if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) { |
748 | temp = scnprintf (next, size, | 756 | temp = scnprintf (next, size, |
749 | " debug control %08x\n", | 757 | " debug control %08x\n", |
750 | ehci_readl(ehci, &ehci->debug->control)); | 758 | ehci_readl(ehci, |
759 | &ehci->debug->control)); | ||
751 | size -= temp; | 760 | size -= temp; |
752 | next += temp; | 761 | next += temp; |
753 | } | 762 | } |
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c index c7a7c590426f..b7b7bfbce527 100644 --- a/drivers/usb/host/ehci-fsl.c +++ b/drivers/usb/host/ehci-fsl.c | |||
@@ -67,7 +67,8 @@ int usb_hcd_fsl_probe(const struct hc_driver *driver, | |||
67 | * in host mode. | 67 | * in host mode. |
68 | */ | 68 | */ |
69 | if (!((pdata->operating_mode == FSL_USB2_DR_HOST) || | 69 | if (!((pdata->operating_mode == FSL_USB2_DR_HOST) || |
70 | (pdata->operating_mode == FSL_USB2_MPH_HOST))) { | 70 | (pdata->operating_mode == FSL_USB2_MPH_HOST) || |
71 | (pdata->operating_mode == FSL_USB2_DR_OTG))) { | ||
71 | dev_err(&pdev->dev, | 72 | dev_err(&pdev->dev, |
72 | "Non Host Mode configured for %s. Wrong driver linked.\n", | 73 | "Non Host Mode configured for %s. Wrong driver linked.\n", |
73 | pdev->dev.bus_id); | 74 | pdev->dev.bus_id); |
@@ -185,12 +186,14 @@ static void mpc83xx_usb_setup(struct usb_hcd *hcd) | |||
185 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | 186 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
186 | struct fsl_usb2_platform_data *pdata; | 187 | struct fsl_usb2_platform_data *pdata; |
187 | void __iomem *non_ehci = hcd->regs; | 188 | void __iomem *non_ehci = hcd->regs; |
189 | u32 temp; | ||
188 | 190 | ||
189 | pdata = | 191 | pdata = |
190 | (struct fsl_usb2_platform_data *)hcd->self.controller-> | 192 | (struct fsl_usb2_platform_data *)hcd->self.controller-> |
191 | platform_data; | 193 | platform_data; |
192 | /* Enable PHY interface in the control reg. */ | 194 | /* Enable PHY interface in the control reg. */ |
193 | out_be32(non_ehci + FSL_SOC_USB_CTRL, 0x00000004); | 195 | temp = in_be32(non_ehci + FSL_SOC_USB_CTRL); |
196 | out_be32(non_ehci + FSL_SOC_USB_CTRL, temp | 0x00000004); | ||
194 | out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0000001b); | 197 | out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0000001b); |
195 | 198 | ||
196 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) | 199 | #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE) |
@@ -206,7 +209,8 @@ static void mpc83xx_usb_setup(struct usb_hcd *hcd) | |||
206 | out_be32(non_ehci + FSL_SOC_USB_SNOOP2, 0x80000000 | SNOOP_SIZE_2GB); | 209 | out_be32(non_ehci + FSL_SOC_USB_SNOOP2, 0x80000000 | SNOOP_SIZE_2GB); |
207 | #endif | 210 | #endif |
208 | 211 | ||
209 | if (pdata->operating_mode == FSL_USB2_DR_HOST) | 212 | if ((pdata->operating_mode == FSL_USB2_DR_HOST) || |
213 | (pdata->operating_mode == FSL_USB2_DR_OTG)) | ||
210 | mpc83xx_setup_phy(ehci, pdata->phy_mode, 0); | 214 | mpc83xx_setup_phy(ehci, pdata->phy_mode, 0); |
211 | 215 | ||
212 | if (pdata->operating_mode == FSL_USB2_MPH_HOST) { | 216 | if (pdata->operating_mode == FSL_USB2_MPH_HOST) { |
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 099aff64f536..c4e15ed1405a 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c | |||
@@ -41,10 +41,6 @@ | |||
41 | #include <asm/irq.h> | 41 | #include <asm/irq.h> |
42 | #include <asm/system.h> | 42 | #include <asm/system.h> |
43 | #include <asm/unaligned.h> | 43 | #include <asm/unaligned.h> |
44 | #ifdef CONFIG_PPC_PS3 | ||
45 | #include <asm/firmware.h> | ||
46 | #endif | ||
47 | |||
48 | 44 | ||
49 | /*-------------------------------------------------------------------------*/ | 45 | /*-------------------------------------------------------------------------*/ |
50 | 46 | ||
@@ -201,9 +197,15 @@ static void tdi_reset (struct ehci_hcd *ehci) | |||
201 | u32 __iomem *reg_ptr; | 197 | u32 __iomem *reg_ptr; |
202 | u32 tmp; | 198 | u32 tmp; |
203 | 199 | ||
204 | reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + 0x68); | 200 | reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + USBMODE); |
205 | tmp = ehci_readl(ehci, reg_ptr); | 201 | tmp = ehci_readl(ehci, reg_ptr); |
206 | tmp |= 0x3; | 202 | tmp |= USBMODE_CM_HC; |
203 | /* The default byte access to MMR space is LE after | ||
204 | * controller reset. Set the required endian mode | ||
205 | * for transfer buffers to match the host microprocessor | ||
206 | */ | ||
207 | if (ehci_big_endian_mmio(ehci)) | ||
208 | tmp |= USBMODE_BE; | ||
207 | ehci_writel(ehci, tmp, reg_ptr); | 209 | ehci_writel(ehci, tmp, reg_ptr); |
208 | } | 210 | } |
209 | 211 | ||
@@ -273,6 +275,58 @@ static void ehci_work(struct ehci_hcd *ehci); | |||
273 | 275 | ||
274 | /*-------------------------------------------------------------------------*/ | 276 | /*-------------------------------------------------------------------------*/ |
275 | 277 | ||
278 | #ifdef CONFIG_CPU_FREQ | ||
279 | |||
280 | #include <linux/cpufreq.h> | ||
281 | |||
282 | static void ehci_cpufreq_pause (struct ehci_hcd *ehci) | ||
283 | { | ||
284 | unsigned long flags; | ||
285 | |||
286 | spin_lock_irqsave(&ehci->lock, flags); | ||
287 | if (!ehci->cpufreq_changing++) | ||
288 | qh_inactivate_split_intr_qhs(ehci); | ||
289 | spin_unlock_irqrestore(&ehci->lock, flags); | ||
290 | } | ||
291 | |||
292 | static void ehci_cpufreq_unpause (struct ehci_hcd *ehci) | ||
293 | { | ||
294 | unsigned long flags; | ||
295 | |||
296 | spin_lock_irqsave(&ehci->lock, flags); | ||
297 | if (!--ehci->cpufreq_changing) | ||
298 | qh_reactivate_split_intr_qhs(ehci); | ||
299 | spin_unlock_irqrestore(&ehci->lock, flags); | ||
300 | } | ||
301 | |||
302 | /* | ||
303 | * ehci_cpufreq_notifier is needed to avoid MMF errors that occur when | ||
304 | * EHCI controllers that don't cache many uframes get delayed trying to | ||
305 | * read main memory during CPU frequency transitions. This can cause | ||
306 | * split interrupt transactions to not be completed in the required uframe. | ||
307 | * This has been observed on the Broadcom/ServerWorks HT1000 controller. | ||
308 | */ | ||
309 | static int ehci_cpufreq_notifier(struct notifier_block *nb, unsigned long val, | ||
310 | void *data) | ||
311 | { | ||
312 | struct ehci_hcd *ehci = container_of(nb, struct ehci_hcd, | ||
313 | cpufreq_transition); | ||
314 | |||
315 | switch (val) { | ||
316 | case CPUFREQ_PRECHANGE: | ||
317 | ehci_cpufreq_pause(ehci); | ||
318 | break; | ||
319 | case CPUFREQ_POSTCHANGE: | ||
320 | ehci_cpufreq_unpause(ehci); | ||
321 | break; | ||
322 | } | ||
323 | return 0; | ||
324 | } | ||
325 | |||
326 | #endif | ||
327 | |||
328 | /*-------------------------------------------------------------------------*/ | ||
329 | |||
276 | static void ehci_watchdog (unsigned long param) | 330 | static void ehci_watchdog (unsigned long param) |
277 | { | 331 | { |
278 | struct ehci_hcd *ehci = (struct ehci_hcd *) param; | 332 | struct ehci_hcd *ehci = (struct ehci_hcd *) param; |
@@ -347,6 +401,8 @@ static void ehci_port_power (struct ehci_hcd *ehci, int is_on) | |||
347 | is_on ? SetPortFeature : ClearPortFeature, | 401 | is_on ? SetPortFeature : ClearPortFeature, |
348 | USB_PORT_FEAT_POWER, | 402 | USB_PORT_FEAT_POWER, |
349 | port--, NULL, 0); | 403 | port--, NULL, 0); |
404 | /* Flush those writes */ | ||
405 | ehci_readl(ehci, &ehci->regs->command); | ||
350 | msleep(20); | 406 | msleep(20); |
351 | } | 407 | } |
352 | 408 | ||
@@ -404,6 +460,10 @@ static void ehci_stop (struct usb_hcd *hcd) | |||
404 | ehci_writel(ehci, 0, &ehci->regs->intr_enable); | 460 | ehci_writel(ehci, 0, &ehci->regs->intr_enable); |
405 | spin_unlock_irq(&ehci->lock); | 461 | spin_unlock_irq(&ehci->lock); |
406 | 462 | ||
463 | #ifdef CONFIG_CPU_FREQ | ||
464 | cpufreq_unregister_notifier(&ehci->cpufreq_transition, | ||
465 | CPUFREQ_TRANSITION_NOTIFIER); | ||
466 | #endif | ||
407 | /* let companion controllers work when we aren't */ | 467 | /* let companion controllers work when we aren't */ |
408 | ehci_writel(ehci, 0, &ehci->regs->configured_flag); | 468 | ehci_writel(ehci, 0, &ehci->regs->configured_flag); |
409 | 469 | ||
@@ -470,12 +530,12 @@ static int ehci_init(struct usb_hcd *hcd) | |||
470 | * from automatically advancing to the next td after short reads. | 530 | * from automatically advancing to the next td after short reads. |
471 | */ | 531 | */ |
472 | ehci->async->qh_next.qh = NULL; | 532 | ehci->async->qh_next.qh = NULL; |
473 | ehci->async->hw_next = QH_NEXT(ehci->async->qh_dma); | 533 | ehci->async->hw_next = QH_NEXT(ehci, ehci->async->qh_dma); |
474 | ehci->async->hw_info1 = cpu_to_le32(QH_HEAD); | 534 | ehci->async->hw_info1 = cpu_to_hc32(ehci, QH_HEAD); |
475 | ehci->async->hw_token = cpu_to_le32(QTD_STS_HALT); | 535 | ehci->async->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT); |
476 | ehci->async->hw_qtd_next = EHCI_LIST_END; | 536 | ehci->async->hw_qtd_next = EHCI_LIST_END(ehci); |
477 | ehci->async->qh_state = QH_STATE_LINKED; | 537 | ehci->async->qh_state = QH_STATE_LINKED; |
478 | ehci->async->hw_alt_next = QTD_NEXT(ehci->async->dummy->qtd_dma); | 538 | ehci->async->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma); |
479 | 539 | ||
480 | /* clear interrupt enables, set irq latency */ | 540 | /* clear interrupt enables, set irq latency */ |
481 | if (log2_irq_thresh < 0 || log2_irq_thresh > 6) | 541 | if (log2_irq_thresh < 0 || log2_irq_thresh > 6) |
@@ -509,6 +569,17 @@ static int ehci_init(struct usb_hcd *hcd) | |||
509 | } | 569 | } |
510 | ehci->command = temp; | 570 | ehci->command = temp; |
511 | 571 | ||
572 | #ifdef CONFIG_CPU_FREQ | ||
573 | INIT_LIST_HEAD(&ehci->split_intr_qhs); | ||
574 | /* | ||
575 | * If the EHCI controller caches enough uframes, this probably | ||
576 | * isn't needed unless there are so many low/full speed devices | ||
577 | * that the controller's can't cache it all. | ||
578 | */ | ||
579 | ehci->cpufreq_transition.notifier_call = ehci_cpufreq_notifier; | ||
580 | cpufreq_register_notifier(&ehci->cpufreq_transition, | ||
581 | CPUFREQ_TRANSITION_NOTIFIER); | ||
582 | #endif | ||
512 | return 0; | 583 | return 0; |
513 | } | 584 | } |
514 | 585 | ||
@@ -925,7 +996,7 @@ MODULE_LICENSE ("GPL"); | |||
925 | #define PCI_DRIVER ehci_pci_driver | 996 | #define PCI_DRIVER ehci_pci_driver |
926 | #endif | 997 | #endif |
927 | 998 | ||
928 | #ifdef CONFIG_MPC834x | 999 | #ifdef CONFIG_USB_EHCI_FSL |
929 | #include "ehci-fsl.c" | 1000 | #include "ehci-fsl.c" |
930 | #define PLATFORM_DRIVER ehci_fsl_driver | 1001 | #define PLATFORM_DRIVER ehci_fsl_driver |
931 | #endif | 1002 | #endif |
@@ -937,7 +1008,12 @@ MODULE_LICENSE ("GPL"); | |||
937 | 1008 | ||
938 | #ifdef CONFIG_PPC_PS3 | 1009 | #ifdef CONFIG_PPC_PS3 |
939 | #include "ehci-ps3.c" | 1010 | #include "ehci-ps3.c" |
940 | #define PS3_SYSTEM_BUS_DRIVER ps3_ehci_sb_driver | 1011 | #define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver |
1012 | #endif | ||
1013 | |||
1014 | #ifdef CONFIG_440EPX | ||
1015 | #include "ehci-ppc-soc.c" | ||
1016 | #define PLATFORM_DRIVER ehci_ppc_soc_driver | ||
941 | #endif | 1017 | #endif |
942 | 1018 | ||
943 | #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ | 1019 | #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ |
@@ -971,18 +1047,15 @@ static int __init ehci_hcd_init(void) | |||
971 | #endif | 1047 | #endif |
972 | 1048 | ||
973 | #ifdef PS3_SYSTEM_BUS_DRIVER | 1049 | #ifdef PS3_SYSTEM_BUS_DRIVER |
974 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) { | 1050 | retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER); |
975 | retval = ps3_system_bus_driver_register( | 1051 | if (retval < 0) { |
976 | &PS3_SYSTEM_BUS_DRIVER); | ||
977 | if (retval < 0) { | ||
978 | #ifdef PLATFORM_DRIVER | 1052 | #ifdef PLATFORM_DRIVER |
979 | platform_driver_unregister(&PLATFORM_DRIVER); | 1053 | platform_driver_unregister(&PLATFORM_DRIVER); |
980 | #endif | 1054 | #endif |
981 | #ifdef PCI_DRIVER | 1055 | #ifdef PCI_DRIVER |
982 | pci_unregister_driver(&PCI_DRIVER); | 1056 | pci_unregister_driver(&PCI_DRIVER); |
983 | #endif | 1057 | #endif |
984 | return retval; | 1058 | return retval; |
985 | } | ||
986 | } | 1059 | } |
987 | #endif | 1060 | #endif |
988 | 1061 | ||
@@ -999,8 +1072,7 @@ static void __exit ehci_hcd_cleanup(void) | |||
999 | pci_unregister_driver(&PCI_DRIVER); | 1072 | pci_unregister_driver(&PCI_DRIVER); |
1000 | #endif | 1073 | #endif |
1001 | #ifdef PS3_SYSTEM_BUS_DRIVER | 1074 | #ifdef PS3_SYSTEM_BUS_DRIVER |
1002 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) | 1075 | ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); |
1003 | ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); | ||
1004 | #endif | 1076 | #endif |
1005 | } | 1077 | } |
1006 | module_exit(ehci_hcd_cleanup); | 1078 | module_exit(ehci_hcd_cleanup); |
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index f4d301bc83b9..0dcb4164dc83 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c | |||
@@ -28,6 +28,89 @@ | |||
28 | 28 | ||
29 | /*-------------------------------------------------------------------------*/ | 29 | /*-------------------------------------------------------------------------*/ |
30 | 30 | ||
31 | #ifdef CONFIG_USB_PERSIST | ||
32 | |||
33 | static int ehci_hub_control( | ||
34 | struct usb_hcd *hcd, | ||
35 | u16 typeReq, | ||
36 | u16 wValue, | ||
37 | u16 wIndex, | ||
38 | char *buf, | ||
39 | u16 wLength | ||
40 | ); | ||
41 | |||
42 | /* After a power loss, ports that were owned by the companion must be | ||
43 | * reset so that the companion can still own them. | ||
44 | */ | ||
45 | static void ehci_handover_companion_ports(struct ehci_hcd *ehci) | ||
46 | { | ||
47 | u32 __iomem *reg; | ||
48 | u32 status; | ||
49 | int port; | ||
50 | __le32 buf; | ||
51 | struct usb_hcd *hcd = ehci_to_hcd(ehci); | ||
52 | |||
53 | if (!ehci->owned_ports) | ||
54 | return; | ||
55 | |||
56 | /* Give the connections some time to appear */ | ||
57 | msleep(20); | ||
58 | |||
59 | port = HCS_N_PORTS(ehci->hcs_params); | ||
60 | while (port--) { | ||
61 | if (test_bit(port, &ehci->owned_ports)) { | ||
62 | reg = &ehci->regs->port_status[port]; | ||
63 | status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; | ||
64 | |||
65 | /* Port already owned by companion? */ | ||
66 | if (status & PORT_OWNER) | ||
67 | clear_bit(port, &ehci->owned_ports); | ||
68 | else if (test_bit(port, &ehci->companion_ports)) | ||
69 | ehci_writel(ehci, status & ~PORT_PE, reg); | ||
70 | else | ||
71 | ehci_hub_control(hcd, SetPortFeature, | ||
72 | USB_PORT_FEAT_RESET, port + 1, | ||
73 | NULL, 0); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | if (!ehci->owned_ports) | ||
78 | return; | ||
79 | msleep(90); /* Wait for resets to complete */ | ||
80 | |||
81 | port = HCS_N_PORTS(ehci->hcs_params); | ||
82 | while (port--) { | ||
83 | if (test_bit(port, &ehci->owned_ports)) { | ||
84 | ehci_hub_control(hcd, GetPortStatus, | ||
85 | 0, port + 1, | ||
86 | (char *) &buf, sizeof(buf)); | ||
87 | |||
88 | /* The companion should now own the port, | ||
89 | * but if something went wrong the port must not | ||
90 | * remain enabled. | ||
91 | */ | ||
92 | reg = &ehci->regs->port_status[port]; | ||
93 | status = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; | ||
94 | if (status & PORT_OWNER) | ||
95 | ehci_writel(ehci, status | PORT_CSC, reg); | ||
96 | else { | ||
97 | ehci_dbg(ehci, "failed handover port %d: %x\n", | ||
98 | port + 1, status); | ||
99 | ehci_writel(ehci, status & ~PORT_PE, reg); | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | |||
104 | ehci->owned_ports = 0; | ||
105 | } | ||
106 | |||
107 | #else /* CONFIG_USB_PERSIST */ | ||
108 | |||
109 | static inline void ehci_handover_companion_ports(struct ehci_hcd *ehci) | ||
110 | { } | ||
111 | |||
112 | #endif | ||
113 | |||
31 | #ifdef CONFIG_PM | 114 | #ifdef CONFIG_PM |
32 | 115 | ||
33 | static int ehci_bus_suspend (struct usb_hcd *hcd) | 116 | static int ehci_bus_suspend (struct usb_hcd *hcd) |
@@ -60,14 +143,16 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) | |||
60 | * then manually resume them in the bus_resume() routine. | 143 | * then manually resume them in the bus_resume() routine. |
61 | */ | 144 | */ |
62 | ehci->bus_suspended = 0; | 145 | ehci->bus_suspended = 0; |
146 | ehci->owned_ports = 0; | ||
63 | while (port--) { | 147 | while (port--) { |
64 | u32 __iomem *reg = &ehci->regs->port_status [port]; | 148 | u32 __iomem *reg = &ehci->regs->port_status [port]; |
65 | u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; | 149 | u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; |
66 | u32 t2 = t1; | 150 | u32 t2 = t1; |
67 | 151 | ||
68 | /* keep track of which ports we suspend */ | 152 | /* keep track of which ports we suspend */ |
69 | if ((t1 & PORT_PE) && !(t1 & PORT_OWNER) && | 153 | if (t1 & PORT_OWNER) |
70 | !(t1 & PORT_SUSPEND)) { | 154 | set_bit(port, &ehci->owned_ports); |
155 | else if ((t1 & PORT_PE) && !(t1 & PORT_SUSPEND)) { | ||
71 | t2 |= PORT_SUSPEND; | 156 | t2 |= PORT_SUSPEND; |
72 | set_bit(port, &ehci->bus_suspended); | 157 | set_bit(port, &ehci->bus_suspended); |
73 | } | 158 | } |
@@ -108,11 +193,16 @@ static int ehci_bus_resume (struct usb_hcd *hcd) | |||
108 | { | 193 | { |
109 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); | 194 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
110 | u32 temp; | 195 | u32 temp; |
196 | u32 power_okay; | ||
111 | int i; | 197 | int i; |
112 | 198 | ||
113 | if (time_before (jiffies, ehci->next_statechange)) | 199 | if (time_before (jiffies, ehci->next_statechange)) |
114 | msleep(5); | 200 | msleep(5); |
115 | spin_lock_irq (&ehci->lock); | 201 | spin_lock_irq (&ehci->lock); |
202 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { | ||
203 | spin_unlock_irq(&ehci->lock); | ||
204 | return -ESHUTDOWN; | ||
205 | } | ||
116 | 206 | ||
117 | /* Ideally and we've got a real resume here, and no port's power | 207 | /* Ideally and we've got a real resume here, and no port's power |
118 | * was lost. (For PCI, that means Vaux was maintained.) But we | 208 | * was lost. (For PCI, that means Vaux was maintained.) But we |
@@ -120,8 +210,9 @@ static int ehci_bus_resume (struct usb_hcd *hcd) | |||
120 | * the last user of the controller, not reset/pm hardware keeping | 210 | * the last user of the controller, not reset/pm hardware keeping |
121 | * state we gave to it. | 211 | * state we gave to it. |
122 | */ | 212 | */ |
123 | temp = ehci_readl(ehci, &ehci->regs->intr_enable); | 213 | power_okay = ehci_readl(ehci, &ehci->regs->intr_enable); |
124 | ehci_dbg(ehci, "resume root hub%s\n", temp ? "" : " after power loss"); | 214 | ehci_dbg(ehci, "resume root hub%s\n", |
215 | power_okay ? "" : " after power loss"); | ||
125 | 216 | ||
126 | /* at least some APM implementations will try to deliver | 217 | /* at least some APM implementations will try to deliver |
127 | * IRQs right away, so delay them until we're ready. | 218 | * IRQs right away, so delay them until we're ready. |
@@ -184,6 +275,9 @@ static int ehci_bus_resume (struct usb_hcd *hcd) | |||
184 | ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); | 275 | ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); |
185 | 276 | ||
186 | spin_unlock_irq (&ehci->lock); | 277 | spin_unlock_irq (&ehci->lock); |
278 | |||
279 | if (!power_okay) | ||
280 | ehci_handover_companion_ports(ehci); | ||
187 | return 0; | 281 | return 0; |
188 | } | 282 | } |
189 | 283 | ||
@@ -448,7 +542,8 @@ static int ehci_hub_control ( | |||
448 | ) { | 542 | ) { |
449 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); | 543 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
450 | int ports = HCS_N_PORTS (ehci->hcs_params); | 544 | int ports = HCS_N_PORTS (ehci->hcs_params); |
451 | u32 __iomem *status_reg = &ehci->regs->port_status[wIndex - 1]; | 545 | u32 __iomem *status_reg = &ehci->regs->port_status[ |
546 | (wIndex & 0xff) - 1]; | ||
452 | u32 temp, status; | 547 | u32 temp, status; |
453 | unsigned long flags; | 548 | unsigned long flags; |
454 | int retval = 0; | 549 | int retval = 0; |
@@ -556,9 +651,24 @@ static int ehci_hub_control ( | |||
556 | status |= 1 << USB_PORT_FEAT_C_CONNECTION; | 651 | status |= 1 << USB_PORT_FEAT_C_CONNECTION; |
557 | if (temp & PORT_PEC) | 652 | if (temp & PORT_PEC) |
558 | status |= 1 << USB_PORT_FEAT_C_ENABLE; | 653 | status |= 1 << USB_PORT_FEAT_C_ENABLE; |
559 | if ((temp & PORT_OCC) && !ignore_oc) | 654 | |
655 | if ((temp & PORT_OCC) && !ignore_oc){ | ||
560 | status |= 1 << USB_PORT_FEAT_C_OVER_CURRENT; | 656 | status |= 1 << USB_PORT_FEAT_C_OVER_CURRENT; |
561 | 657 | ||
658 | /* | ||
659 | * Hubs should disable port power on over-current. | ||
660 | * However, not all EHCI implementations do this | ||
661 | * automatically, even if they _do_ support per-port | ||
662 | * power switching; they're allowed to just limit the | ||
663 | * current. khubd will turn the power back on. | ||
664 | */ | ||
665 | if (HCS_PPC (ehci->hcs_params)){ | ||
666 | ehci_writel(ehci, | ||
667 | temp & ~(PORT_RWC_BITS | PORT_POWER), | ||
668 | status_reg); | ||
669 | } | ||
670 | } | ||
671 | |||
562 | /* whoever resumes must GetPortStatus to complete it!! */ | 672 | /* whoever resumes must GetPortStatus to complete it!! */ |
563 | if (temp & PORT_RESUME) { | 673 | if (temp & PORT_RESUME) { |
564 | 674 | ||
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c index a8ba2e1497a4..8816d09903d0 100644 --- a/drivers/usb/host/ehci-mem.c +++ b/drivers/usb/host/ehci-mem.c | |||
@@ -27,7 +27,7 @@ | |||
27 | * need to use dma_pool or dma_alloc_coherent | 27 | * need to use dma_pool or dma_alloc_coherent |
28 | * - driver buffers, read/written by HC ... single shot DMA mapped | 28 | * - driver buffers, read/written by HC ... single shot DMA mapped |
29 | * | 29 | * |
30 | * There's also PCI "register" data, which is memory mapped. | 30 | * There's also "register" data (e.g. PCI or SOC), which is memory mapped. |
31 | * No memory seen by this driver is pageable. | 31 | * No memory seen by this driver is pageable. |
32 | */ | 32 | */ |
33 | 33 | ||
@@ -35,13 +35,14 @@ | |||
35 | 35 | ||
36 | /* Allocate the key transfer structures from the previously allocated pool */ | 36 | /* Allocate the key transfer structures from the previously allocated pool */ |
37 | 37 | ||
38 | static inline void ehci_qtd_init (struct ehci_qtd *qtd, dma_addr_t dma) | 38 | static inline void ehci_qtd_init(struct ehci_hcd *ehci, struct ehci_qtd *qtd, |
39 | dma_addr_t dma) | ||
39 | { | 40 | { |
40 | memset (qtd, 0, sizeof *qtd); | 41 | memset (qtd, 0, sizeof *qtd); |
41 | qtd->qtd_dma = dma; | 42 | qtd->qtd_dma = dma; |
42 | qtd->hw_token = cpu_to_le32 (QTD_STS_HALT); | 43 | qtd->hw_token = cpu_to_le32 (QTD_STS_HALT); |
43 | qtd->hw_next = EHCI_LIST_END; | 44 | qtd->hw_next = EHCI_LIST_END(ehci); |
44 | qtd->hw_alt_next = EHCI_LIST_END; | 45 | qtd->hw_alt_next = EHCI_LIST_END(ehci); |
45 | INIT_LIST_HEAD (&qtd->qtd_list); | 46 | INIT_LIST_HEAD (&qtd->qtd_list); |
46 | } | 47 | } |
47 | 48 | ||
@@ -52,7 +53,7 @@ static struct ehci_qtd *ehci_qtd_alloc (struct ehci_hcd *ehci, gfp_t flags) | |||
52 | 53 | ||
53 | qtd = dma_pool_alloc (ehci->qtd_pool, flags, &dma); | 54 | qtd = dma_pool_alloc (ehci->qtd_pool, flags, &dma); |
54 | if (qtd != NULL) { | 55 | if (qtd != NULL) { |
55 | ehci_qtd_init (qtd, dma); | 56 | ehci_qtd_init(ehci, qtd, dma); |
56 | } | 57 | } |
57 | return qtd; | 58 | return qtd; |
58 | } | 59 | } |
@@ -63,9 +64,8 @@ static inline void ehci_qtd_free (struct ehci_hcd *ehci, struct ehci_qtd *qtd) | |||
63 | } | 64 | } |
64 | 65 | ||
65 | 66 | ||
66 | static void qh_destroy (struct kref *kref) | 67 | static void qh_destroy(struct ehci_qh *qh) |
67 | { | 68 | { |
68 | struct ehci_qh *qh = container_of(kref, struct ehci_qh, kref); | ||
69 | struct ehci_hcd *ehci = qh->ehci; | 69 | struct ehci_hcd *ehci = qh->ehci; |
70 | 70 | ||
71 | /* clean qtds first, and know this is not linked */ | 71 | /* clean qtds first, and know this is not linked */ |
@@ -89,11 +89,14 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags) | |||
89 | return qh; | 89 | return qh; |
90 | 90 | ||
91 | memset (qh, 0, sizeof *qh); | 91 | memset (qh, 0, sizeof *qh); |
92 | kref_init(&qh->kref); | 92 | qh->refcount = 1; |
93 | qh->ehci = ehci; | 93 | qh->ehci = ehci; |
94 | qh->qh_dma = dma; | 94 | qh->qh_dma = dma; |
95 | // INIT_LIST_HEAD (&qh->qh_list); | 95 | // INIT_LIST_HEAD (&qh->qh_list); |
96 | INIT_LIST_HEAD (&qh->qtd_list); | 96 | INIT_LIST_HEAD (&qh->qtd_list); |
97 | #ifdef CONFIG_CPU_FREQ | ||
98 | INIT_LIST_HEAD (&qh->split_intr_qhs); | ||
99 | #endif | ||
97 | 100 | ||
98 | /* dummy td enables safe urb queuing */ | 101 | /* dummy td enables safe urb queuing */ |
99 | qh->dummy = ehci_qtd_alloc (ehci, flags); | 102 | qh->dummy = ehci_qtd_alloc (ehci, flags); |
@@ -108,13 +111,15 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags) | |||
108 | /* to share a qh (cpu threads, or hc) */ | 111 | /* to share a qh (cpu threads, or hc) */ |
109 | static inline struct ehci_qh *qh_get (struct ehci_qh *qh) | 112 | static inline struct ehci_qh *qh_get (struct ehci_qh *qh) |
110 | { | 113 | { |
111 | kref_get(&qh->kref); | 114 | WARN_ON(!qh->refcount); |
115 | qh->refcount++; | ||
112 | return qh; | 116 | return qh; |
113 | } | 117 | } |
114 | 118 | ||
115 | static inline void qh_put (struct ehci_qh *qh) | 119 | static inline void qh_put (struct ehci_qh *qh) |
116 | { | 120 | { |
117 | kref_put(&qh->kref, qh_destroy); | 121 | if (!--qh->refcount) |
122 | qh_destroy(qh); | ||
118 | } | 123 | } |
119 | 124 | ||
120 | /*-------------------------------------------------------------------------*/ | 125 | /*-------------------------------------------------------------------------*/ |
@@ -217,7 +222,7 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags) | |||
217 | goto fail; | 222 | goto fail; |
218 | } | 223 | } |
219 | for (i = 0; i < ehci->periodic_size; i++) | 224 | for (i = 0; i < ehci->periodic_size; i++) |
220 | ehci->periodic [i] = EHCI_LIST_END; | 225 | ehci->periodic [i] = EHCI_LIST_END(ehci); |
221 | 226 | ||
222 | /* software shadow of hardware table */ | 227 | /* software shadow of hardware table */ |
223 | ehci->pshadow = kcalloc(ehci->periodic_size, sizeof(void *), flags); | 228 | ehci->pshadow = kcalloc(ehci->periodic_size, sizeof(void *), flags); |
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c index 966965f72338..a7816e392a85 100644 --- a/drivers/usb/host/ehci-pci.c +++ b/drivers/usb/host/ehci-pci.c | |||
@@ -312,13 +312,14 @@ static int ehci_pci_resume(struct usb_hcd *hcd) | |||
312 | ehci_work(ehci); | 312 | ehci_work(ehci); |
313 | spin_unlock_irq(&ehci->lock); | 313 | spin_unlock_irq(&ehci->lock); |
314 | 314 | ||
315 | /* here we "know" root ports should always stay powered */ | ||
316 | ehci_port_power(ehci, 1); | ||
317 | |||
318 | ehci_writel(ehci, ehci->command, &ehci->regs->command); | 315 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
319 | ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); | 316 | ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); |
320 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ | 317 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ |
321 | 318 | ||
319 | /* here we "know" root ports should always stay powered */ | ||
320 | ehci_port_power(ehci, 1); | ||
321 | ehci_handover_companion_ports(ehci); | ||
322 | |||
322 | hcd->state = HC_STATE_SUSPENDED; | 323 | hcd->state = HC_STATE_SUSPENDED; |
323 | return 0; | 324 | return 0; |
324 | } | 325 | } |
diff --git a/drivers/usb/host/ehci-ppc-soc.c b/drivers/usb/host/ehci-ppc-soc.c new file mode 100644 index 000000000000..c2cedb09ed8b --- /dev/null +++ b/drivers/usb/host/ehci-ppc-soc.c | |||
@@ -0,0 +1,182 @@ | |||
1 | /* | ||
2 | * EHCI HCD (Host Controller Driver) for USB. | ||
3 | * | ||
4 | * (C) Copyright 2006-2007 Stefan Roese <sr@denx.de>, DENX Software Engineering | ||
5 | * | ||
6 | * Bus Glue for PPC On-Chip EHCI driver | ||
7 | * Tested on AMCC 440EPx | ||
8 | * | ||
9 | * Based on "ehci-au12xx.c" by David Brownell <dbrownell@users.sourceforge.net> | ||
10 | * | ||
11 | * This file is licenced under the GPL. | ||
12 | */ | ||
13 | |||
14 | #include <linux/platform_device.h> | ||
15 | |||
16 | extern int usb_disabled(void); | ||
17 | |||
18 | /** | ||
19 | * usb_ehci_ppc_soc_probe - initialize PPC-SoC-based HCDs | ||
20 | * Context: !in_interrupt() | ||
21 | * | ||
22 | * Allocates basic resources for this USB host controller, and | ||
23 | * then invokes the start() method for the HCD associated with it | ||
24 | * through the hotplug entry's driver_data. | ||
25 | * | ||
26 | */ | ||
27 | int usb_ehci_ppc_soc_probe(const struct hc_driver *driver, | ||
28 | struct usb_hcd **hcd_out, | ||
29 | struct platform_device *dev) | ||
30 | { | ||
31 | int retval; | ||
32 | struct usb_hcd *hcd; | ||
33 | struct ehci_hcd *ehci; | ||
34 | |||
35 | if (dev->resource[1].flags != IORESOURCE_IRQ) { | ||
36 | pr_debug("resource[1] is not IORESOURCE_IRQ"); | ||
37 | retval = -ENOMEM; | ||
38 | } | ||
39 | hcd = usb_create_hcd(driver, &dev->dev, "PPC-SOC EHCI"); | ||
40 | if (!hcd) | ||
41 | return -ENOMEM; | ||
42 | hcd->rsrc_start = dev->resource[0].start; | ||
43 | hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1; | ||
44 | |||
45 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { | ||
46 | pr_debug("request_mem_region failed"); | ||
47 | retval = -EBUSY; | ||
48 | goto err1; | ||
49 | } | ||
50 | |||
51 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | ||
52 | if (!hcd->regs) { | ||
53 | pr_debug("ioremap failed"); | ||
54 | retval = -ENOMEM; | ||
55 | goto err2; | ||
56 | } | ||
57 | |||
58 | ehci = hcd_to_ehci(hcd); | ||
59 | ehci->big_endian_mmio = 1; | ||
60 | ehci->big_endian_desc = 1; | ||
61 | ehci->caps = hcd->regs; | ||
62 | ehci->regs = hcd->regs + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); | ||
63 | |||
64 | /* cache this readonly data; minimize chip reads */ | ||
65 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | ||
66 | |||
67 | #if defined(CONFIG_440EPX) | ||
68 | /* | ||
69 | * 440EPx Errata USBH_3 | ||
70 | * Fix: Enable Break Memory Transfer (BMT) in INSNREG3 | ||
71 | */ | ||
72 | out_be32((void *)((ulong)(&ehci->regs->command) + 0x8c), (1 << 0)); | ||
73 | ehci_dbg(ehci, "Break Memory Transfer (BMT) has beed enabled!\n"); | ||
74 | #endif | ||
75 | |||
76 | retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED); | ||
77 | if (retval == 0) | ||
78 | return retval; | ||
79 | |||
80 | iounmap(hcd->regs); | ||
81 | err2: | ||
82 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
83 | err1: | ||
84 | usb_put_hcd(hcd); | ||
85 | return retval; | ||
86 | } | ||
87 | |||
88 | /* may be called without controller electrically present */ | ||
89 | /* may be called with controller, bus, and devices active */ | ||
90 | |||
91 | /** | ||
92 | * usb_ehci_hcd_ppc_soc_remove - shutdown processing for PPC-SoC-based HCDs | ||
93 | * @dev: USB Host Controller being removed | ||
94 | * Context: !in_interrupt() | ||
95 | * | ||
96 | * Reverses the effect of usb_ehci_hcd_ppc_soc_probe(), first invoking | ||
97 | * the HCD's stop() method. It is always called from a thread | ||
98 | * context, normally "rmmod", "apmd", or something similar. | ||
99 | * | ||
100 | */ | ||
101 | void usb_ehci_ppc_soc_remove(struct usb_hcd *hcd, struct platform_device *dev) | ||
102 | { | ||
103 | usb_remove_hcd(hcd); | ||
104 | iounmap(hcd->regs); | ||
105 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
106 | usb_put_hcd(hcd); | ||
107 | } | ||
108 | |||
109 | static const struct hc_driver ehci_ppc_soc_hc_driver = { | ||
110 | .description = hcd_name, | ||
111 | .product_desc = "PPC-SOC EHCI", | ||
112 | .hcd_priv_size = sizeof(struct ehci_hcd), | ||
113 | |||
114 | /* | ||
115 | * generic hardware linkage | ||
116 | */ | ||
117 | .irq = ehci_irq, | ||
118 | .flags = HCD_MEMORY | HCD_USB2, | ||
119 | |||
120 | /* | ||
121 | * basic lifecycle operations | ||
122 | */ | ||
123 | .reset = ehci_init, | ||
124 | .start = ehci_run, | ||
125 | .stop = ehci_stop, | ||
126 | .shutdown = ehci_shutdown, | ||
127 | |||
128 | /* | ||
129 | * managing i/o requests and associated device resources | ||
130 | */ | ||
131 | .urb_enqueue = ehci_urb_enqueue, | ||
132 | .urb_dequeue = ehci_urb_dequeue, | ||
133 | .endpoint_disable = ehci_endpoint_disable, | ||
134 | |||
135 | /* | ||
136 | * scheduling support | ||
137 | */ | ||
138 | .get_frame_number = ehci_get_frame, | ||
139 | |||
140 | /* | ||
141 | * root hub support | ||
142 | */ | ||
143 | .hub_status_data = ehci_hub_status_data, | ||
144 | .hub_control = ehci_hub_control, | ||
145 | #ifdef CONFIG_PM | ||
146 | .hub_suspend = ehci_hub_suspend, | ||
147 | .hub_resume = ehci_hub_resume, | ||
148 | #endif | ||
149 | }; | ||
150 | |||
151 | static int ehci_hcd_ppc_soc_drv_probe(struct platform_device *pdev) | ||
152 | { | ||
153 | struct usb_hcd *hcd = NULL; | ||
154 | int ret; | ||
155 | |||
156 | pr_debug("In ehci_hcd_ppc_soc_drv_probe\n"); | ||
157 | |||
158 | if (usb_disabled()) | ||
159 | return -ENODEV; | ||
160 | |||
161 | ret = usb_ehci_ppc_soc_probe(&ehci_ppc_soc_hc_driver, &hcd, pdev); | ||
162 | return ret; | ||
163 | } | ||
164 | |||
165 | static int ehci_hcd_ppc_soc_drv_remove(struct platform_device *pdev) | ||
166 | { | ||
167 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
168 | |||
169 | usb_ehci_ppc_soc_remove(hcd, pdev); | ||
170 | return 0; | ||
171 | } | ||
172 | |||
173 | MODULE_ALIAS("ppc-soc-ehci"); | ||
174 | static struct platform_driver ehci_ppc_soc_driver = { | ||
175 | .probe = ehci_hcd_ppc_soc_drv_probe, | ||
176 | .remove = ehci_hcd_ppc_soc_drv_remove, | ||
177 | .shutdown = usb_hcd_platform_shutdown, | ||
178 | .driver = { | ||
179 | .name = "ppc-soc-ehci", | ||
180 | .bus = &platform_bus_type | ||
181 | } | ||
182 | }; | ||
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c index 37b83ba09969..829fe649a981 100644 --- a/drivers/usb/host/ehci-ps3.c +++ b/drivers/usb/host/ehci-ps3.c | |||
@@ -18,6 +18,7 @@ | |||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <asm/firmware.h> | ||
21 | #include <asm/ps3.h> | 22 | #include <asm/ps3.h> |
22 | 23 | ||
23 | static int ps3_ehci_hc_reset(struct usb_hcd *hcd) | 24 | static int ps3_ehci_hc_reset(struct usb_hcd *hcd) |
@@ -73,7 +74,7 @@ static const struct hc_driver ps3_ehci_hc_driver = { | |||
73 | #endif | 74 | #endif |
74 | }; | 75 | }; |
75 | 76 | ||
76 | static int ps3_ehci_sb_probe(struct ps3_system_bus_device *dev) | 77 | static int ps3_ehci_probe(struct ps3_system_bus_device *dev) |
77 | { | 78 | { |
78 | int result; | 79 | int result; |
79 | struct usb_hcd *hcd; | 80 | struct usb_hcd *hcd; |
@@ -85,13 +86,30 @@ static int ps3_ehci_sb_probe(struct ps3_system_bus_device *dev) | |||
85 | goto fail_start; | 86 | goto fail_start; |
86 | } | 87 | } |
87 | 88 | ||
89 | result = ps3_open_hv_device(dev); | ||
90 | |||
91 | if (result) { | ||
92 | dev_dbg(&dev->core, "%s:%d: ps3_open_hv_device failed\n", | ||
93 | __func__, __LINE__); | ||
94 | goto fail_open; | ||
95 | } | ||
96 | |||
97 | result = ps3_dma_region_create(dev->d_region); | ||
98 | |||
99 | if (result) { | ||
100 | dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: " | ||
101 | "(%d)\n", __func__, __LINE__, result); | ||
102 | BUG_ON("check region type"); | ||
103 | goto fail_dma_region; | ||
104 | } | ||
105 | |||
88 | result = ps3_mmio_region_create(dev->m_region); | 106 | result = ps3_mmio_region_create(dev->m_region); |
89 | 107 | ||
90 | if (result) { | 108 | if (result) { |
91 | dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n", | 109 | dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n", |
92 | __func__, __LINE__); | 110 | __func__, __LINE__); |
93 | result = -EPERM; | 111 | result = -EPERM; |
94 | goto fail_mmio; | 112 | goto fail_mmio_region; |
95 | } | 113 | } |
96 | 114 | ||
97 | dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__, | 115 | dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__, |
@@ -120,6 +138,11 @@ static int ps3_ehci_sb_probe(struct ps3_system_bus_device *dev) | |||
120 | 138 | ||
121 | hcd->rsrc_start = dev->m_region->lpar_addr; | 139 | hcd->rsrc_start = dev->m_region->lpar_addr; |
122 | hcd->rsrc_len = dev->m_region->len; | 140 | hcd->rsrc_len = dev->m_region->len; |
141 | |||
142 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) | ||
143 | dev_dbg(&dev->core, "%s:%d: request_mem_region failed\n", | ||
144 | __func__, __LINE__); | ||
145 | |||
123 | hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len); | 146 | hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len); |
124 | 147 | ||
125 | if (!hcd->regs) { | 148 | if (!hcd->regs) { |
@@ -153,34 +176,73 @@ static int ps3_ehci_sb_probe(struct ps3_system_bus_device *dev) | |||
153 | fail_add_hcd: | 176 | fail_add_hcd: |
154 | iounmap(hcd->regs); | 177 | iounmap(hcd->regs); |
155 | fail_ioremap: | 178 | fail_ioremap: |
179 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
156 | usb_put_hcd(hcd); | 180 | usb_put_hcd(hcd); |
157 | fail_create_hcd: | 181 | fail_create_hcd: |
158 | ps3_io_irq_destroy(virq); | 182 | ps3_io_irq_destroy(virq); |
159 | fail_irq: | 183 | fail_irq: |
160 | ps3_free_mmio_region(dev->m_region); | 184 | ps3_free_mmio_region(dev->m_region); |
161 | fail_mmio: | 185 | fail_mmio_region: |
186 | ps3_dma_region_free(dev->d_region); | ||
187 | fail_dma_region: | ||
188 | ps3_close_hv_device(dev); | ||
189 | fail_open: | ||
162 | fail_start: | 190 | fail_start: |
163 | return result; | 191 | return result; |
164 | } | 192 | } |
165 | 193 | ||
166 | static int ps3_ehci_sb_remove(struct ps3_system_bus_device *dev) | 194 | static int ps3_ehci_remove(struct ps3_system_bus_device *dev) |
167 | { | 195 | { |
196 | unsigned int tmp; | ||
168 | struct usb_hcd *hcd = | 197 | struct usb_hcd *hcd = |
169 | (struct usb_hcd *)ps3_system_bus_get_driver_data(dev); | 198 | (struct usb_hcd *)ps3_system_bus_get_driver_data(dev); |
170 | 199 | ||
171 | usb_put_hcd(hcd); | 200 | BUG_ON(!hcd); |
201 | |||
202 | dev_dbg(&dev->core, "%s:%d: regs %p\n", __func__, __LINE__, hcd->regs); | ||
203 | dev_dbg(&dev->core, "%s:%d: irq %u\n", __func__, __LINE__, hcd->irq); | ||
204 | |||
205 | tmp = hcd->irq; | ||
206 | |||
207 | usb_remove_hcd(hcd); | ||
208 | |||
172 | ps3_system_bus_set_driver_data(dev, NULL); | 209 | ps3_system_bus_set_driver_data(dev, NULL); |
173 | 210 | ||
211 | BUG_ON(!hcd->regs); | ||
212 | iounmap(hcd->regs); | ||
213 | |||
214 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
215 | usb_put_hcd(hcd); | ||
216 | |||
217 | ps3_io_irq_destroy(tmp); | ||
218 | ps3_free_mmio_region(dev->m_region); | ||
219 | |||
220 | ps3_dma_region_free(dev->d_region); | ||
221 | ps3_close_hv_device(dev); | ||
222 | |||
174 | return 0; | 223 | return 0; |
175 | } | 224 | } |
176 | 225 | ||
177 | MODULE_ALIAS("ps3-ehci"); | 226 | static int ps3_ehci_driver_register(struct ps3_system_bus_driver *drv) |
227 | { | ||
228 | return firmware_has_feature(FW_FEATURE_PS3_LV1) | ||
229 | ? ps3_system_bus_driver_register(drv) | ||
230 | : 0; | ||
231 | } | ||
232 | |||
233 | static void ps3_ehci_driver_unregister(struct ps3_system_bus_driver *drv) | ||
234 | { | ||
235 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) | ||
236 | ps3_system_bus_driver_unregister(drv); | ||
237 | } | ||
238 | |||
239 | MODULE_ALIAS(PS3_MODULE_ALIAS_EHCI); | ||
178 | 240 | ||
179 | static struct ps3_system_bus_driver ps3_ehci_sb_driver = { | 241 | static struct ps3_system_bus_driver ps3_ehci_driver = { |
242 | .core.name = "ps3-ehci-driver", | ||
243 | .core.owner = THIS_MODULE, | ||
180 | .match_id = PS3_MATCH_ID_EHCI, | 244 | .match_id = PS3_MATCH_ID_EHCI, |
181 | .core = { | 245 | .probe = ps3_ehci_probe, |
182 | .name = "ps3-ehci-driver", | 246 | .remove = ps3_ehci_remove, |
183 | }, | 247 | .shutdown = ps3_ehci_remove, |
184 | .probe = ps3_ehci_sb_probe, | ||
185 | .remove = ps3_ehci_sb_remove, | ||
186 | }; | 248 | }; |
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c index e7fbbd00e7cd..2284028f8aa5 100644 --- a/drivers/usb/host/ehci-q.c +++ b/drivers/usb/host/ehci-q.c | |||
@@ -43,15 +43,15 @@ | |||
43 | /* fill a qtd, returning how much of the buffer we were able to queue up */ | 43 | /* fill a qtd, returning how much of the buffer we were able to queue up */ |
44 | 44 | ||
45 | static int | 45 | static int |
46 | qtd_fill (struct ehci_qtd *qtd, dma_addr_t buf, size_t len, | 46 | qtd_fill(struct ehci_hcd *ehci, struct ehci_qtd *qtd, dma_addr_t buf, |
47 | int token, int maxpacket) | 47 | size_t len, int token, int maxpacket) |
48 | { | 48 | { |
49 | int i, count; | 49 | int i, count; |
50 | u64 addr = buf; | 50 | u64 addr = buf; |
51 | 51 | ||
52 | /* one buffer entry per 4K ... first might be short or unaligned */ | 52 | /* one buffer entry per 4K ... first might be short or unaligned */ |
53 | qtd->hw_buf [0] = cpu_to_le32 ((u32)addr); | 53 | qtd->hw_buf[0] = cpu_to_hc32(ehci, (u32)addr); |
54 | qtd->hw_buf_hi [0] = cpu_to_le32 ((u32)(addr >> 32)); | 54 | qtd->hw_buf_hi[0] = cpu_to_hc32(ehci, (u32)(addr >> 32)); |
55 | count = 0x1000 - (buf & 0x0fff); /* rest of that page */ | 55 | count = 0x1000 - (buf & 0x0fff); /* rest of that page */ |
56 | if (likely (len < count)) /* ... iff needed */ | 56 | if (likely (len < count)) /* ... iff needed */ |
57 | count = len; | 57 | count = len; |
@@ -62,8 +62,9 @@ qtd_fill (struct ehci_qtd *qtd, dma_addr_t buf, size_t len, | |||
62 | /* per-qtd limit: from 16K to 20K (best alignment) */ | 62 | /* per-qtd limit: from 16K to 20K (best alignment) */ |
63 | for (i = 1; count < len && i < 5; i++) { | 63 | for (i = 1; count < len && i < 5; i++) { |
64 | addr = buf; | 64 | addr = buf; |
65 | qtd->hw_buf [i] = cpu_to_le32 ((u32)addr); | 65 | qtd->hw_buf[i] = cpu_to_hc32(ehci, (u32)addr); |
66 | qtd->hw_buf_hi [i] = cpu_to_le32 ((u32)(addr >> 32)); | 66 | qtd->hw_buf_hi[i] = cpu_to_hc32(ehci, |
67 | (u32)(addr >> 32)); | ||
67 | buf += 0x1000; | 68 | buf += 0x1000; |
68 | if ((count + 0x1000) < len) | 69 | if ((count + 0x1000) < len) |
69 | count += 0x1000; | 70 | count += 0x1000; |
@@ -75,7 +76,7 @@ qtd_fill (struct ehci_qtd *qtd, dma_addr_t buf, size_t len, | |||
75 | if (count != len) | 76 | if (count != len) |
76 | count -= (count % maxpacket); | 77 | count -= (count % maxpacket); |
77 | } | 78 | } |
78 | qtd->hw_token = cpu_to_le32 ((count << 16) | token); | 79 | qtd->hw_token = cpu_to_hc32(ehci, (count << 16) | token); |
79 | qtd->length = count; | 80 | qtd->length = count; |
80 | 81 | ||
81 | return count; | 82 | return count; |
@@ -89,28 +90,28 @@ qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd) | |||
89 | /* writes to an active overlay are unsafe */ | 90 | /* writes to an active overlay are unsafe */ |
90 | BUG_ON(qh->qh_state != QH_STATE_IDLE); | 91 | BUG_ON(qh->qh_state != QH_STATE_IDLE); |
91 | 92 | ||
92 | qh->hw_qtd_next = QTD_NEXT (qtd->qtd_dma); | 93 | qh->hw_qtd_next = QTD_NEXT(ehci, qtd->qtd_dma); |
93 | qh->hw_alt_next = EHCI_LIST_END; | 94 | qh->hw_alt_next = EHCI_LIST_END(ehci); |
94 | 95 | ||
95 | /* Except for control endpoints, we make hardware maintain data | 96 | /* Except for control endpoints, we make hardware maintain data |
96 | * toggle (like OHCI) ... here (re)initialize the toggle in the QH, | 97 | * toggle (like OHCI) ... here (re)initialize the toggle in the QH, |
97 | * and set the pseudo-toggle in udev. Only usb_clear_halt() will | 98 | * and set the pseudo-toggle in udev. Only usb_clear_halt() will |
98 | * ever clear it. | 99 | * ever clear it. |
99 | */ | 100 | */ |
100 | if (!(qh->hw_info1 & cpu_to_le32(1 << 14))) { | 101 | if (!(qh->hw_info1 & cpu_to_hc32(ehci, 1 << 14))) { |
101 | unsigned is_out, epnum; | 102 | unsigned is_out, epnum; |
102 | 103 | ||
103 | is_out = !(qtd->hw_token & cpu_to_le32(1 << 8)); | 104 | is_out = !(qtd->hw_token & cpu_to_hc32(ehci, 1 << 8)); |
104 | epnum = (le32_to_cpup(&qh->hw_info1) >> 8) & 0x0f; | 105 | epnum = (hc32_to_cpup(ehci, &qh->hw_info1) >> 8) & 0x0f; |
105 | if (unlikely (!usb_gettoggle (qh->dev, epnum, is_out))) { | 106 | if (unlikely (!usb_gettoggle (qh->dev, epnum, is_out))) { |
106 | qh->hw_token &= ~__constant_cpu_to_le32 (QTD_TOGGLE); | 107 | qh->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE); |
107 | usb_settoggle (qh->dev, epnum, is_out, 1); | 108 | usb_settoggle (qh->dev, epnum, is_out, 1); |
108 | } | 109 | } |
109 | } | 110 | } |
110 | 111 | ||
111 | /* HC must see latest qtd and qh data before we clear ACTIVE+HALT */ | 112 | /* HC must see latest qtd and qh data before we clear ACTIVE+HALT */ |
112 | wmb (); | 113 | wmb (); |
113 | qh->hw_token &= __constant_cpu_to_le32 (QTD_TOGGLE | QTD_STS_PING); | 114 | qh->hw_token &= cpu_to_hc32(ehci, QTD_TOGGLE | QTD_STS_PING); |
114 | } | 115 | } |
115 | 116 | ||
116 | /* if it weren't for a common silicon quirk (writing the dummy into the qh | 117 | /* if it weren't for a common silicon quirk (writing the dummy into the qh |
@@ -128,7 +129,7 @@ qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
128 | qtd = list_entry (qh->qtd_list.next, | 129 | qtd = list_entry (qh->qtd_list.next, |
129 | struct ehci_qtd, qtd_list); | 130 | struct ehci_qtd, qtd_list); |
130 | /* first qtd may already be partially processed */ | 131 | /* first qtd may already be partially processed */ |
131 | if (cpu_to_le32 (qtd->qtd_dma) == qh->hw_current) | 132 | if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw_current) |
132 | qtd = NULL; | 133 | qtd = NULL; |
133 | } | 134 | } |
134 | 135 | ||
@@ -222,7 +223,7 @@ __acquires(ehci->lock) | |||
222 | struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv; | 223 | struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv; |
223 | 224 | ||
224 | /* S-mask in a QH means it's an interrupt urb */ | 225 | /* S-mask in a QH means it's an interrupt urb */ |
225 | if ((qh->hw_info2 & __constant_cpu_to_le32 (QH_SMASK)) != 0) { | 226 | if ((qh->hw_info2 & cpu_to_hc32(ehci, QH_SMASK)) != 0) { |
226 | 227 | ||
227 | /* ... update hc-wide periodic stats (for usbfs) */ | 228 | /* ... update hc-wide periodic stats (for usbfs) */ |
228 | ehci_to_hcd(ehci)->self.bandwidth_int_reqs--; | 229 | ehci_to_hcd(ehci)->self.bandwidth_int_reqs--; |
@@ -277,7 +278,6 @@ static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh); | |||
277 | * Chases up to qh->hw_current. Returns number of completions called, | 278 | * Chases up to qh->hw_current. Returns number of completions called, |
278 | * indicating how much "real" work we did. | 279 | * indicating how much "real" work we did. |
279 | */ | 280 | */ |
280 | #define HALT_BIT __constant_cpu_to_le32(QTD_STS_HALT) | ||
281 | static unsigned | 281 | static unsigned |
282 | qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) | 282 | qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) |
283 | { | 283 | { |
@@ -287,6 +287,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
287 | unsigned count = 0; | 287 | unsigned count = 0; |
288 | int do_status = 0; | 288 | int do_status = 0; |
289 | u8 state; | 289 | u8 state; |
290 | u32 halt = HALT_BIT(ehci); | ||
290 | 291 | ||
291 | if (unlikely (list_empty (&qh->qtd_list))) | 292 | if (unlikely (list_empty (&qh->qtd_list))) |
292 | return count; | 293 | return count; |
@@ -311,6 +312,10 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
311 | struct urb *urb; | 312 | struct urb *urb; |
312 | u32 token = 0; | 313 | u32 token = 0; |
313 | 314 | ||
315 | /* ignore QHs that are currently inactive */ | ||
316 | if (qh->hw_info1 & __constant_cpu_to_le32(QH_INACTIVATE)) | ||
317 | break; | ||
318 | |||
314 | qtd = list_entry (entry, struct ehci_qtd, qtd_list); | 319 | qtd = list_entry (entry, struct ehci_qtd, qtd_list); |
315 | urb = qtd->urb; | 320 | urb = qtd->urb; |
316 | 321 | ||
@@ -330,7 +335,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
330 | 335 | ||
331 | /* hardware copies qtd out of qh overlay */ | 336 | /* hardware copies qtd out of qh overlay */ |
332 | rmb (); | 337 | rmb (); |
333 | token = le32_to_cpu (qtd->hw_token); | 338 | token = hc32_to_cpu(ehci, qtd->hw_token); |
334 | 339 | ||
335 | /* always clean up qtds the hc de-activated */ | 340 | /* always clean up qtds the hc de-activated */ |
336 | if ((token & QTD_STS_ACTIVE) == 0) { | 341 | if ((token & QTD_STS_ACTIVE) == 0) { |
@@ -342,7 +347,8 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
342 | * that silicon quirk can kick in with this dummy too. | 347 | * that silicon quirk can kick in with this dummy too. |
343 | */ | 348 | */ |
344 | } else if (IS_SHORT_READ (token) | 349 | } else if (IS_SHORT_READ (token) |
345 | && !(qtd->hw_alt_next & EHCI_LIST_END)) { | 350 | && !(qtd->hw_alt_next |
351 | & EHCI_LIST_END(ehci))) { | ||
346 | stopped = 1; | 352 | stopped = 1; |
347 | goto halt; | 353 | goto halt; |
348 | } | 354 | } |
@@ -374,17 +380,17 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
374 | 380 | ||
375 | /* token in overlay may be most current */ | 381 | /* token in overlay may be most current */ |
376 | if (state == QH_STATE_IDLE | 382 | if (state == QH_STATE_IDLE |
377 | && cpu_to_le32 (qtd->qtd_dma) | 383 | && cpu_to_hc32(ehci, qtd->qtd_dma) |
378 | == qh->hw_current) | 384 | == qh->hw_current) |
379 | token = le32_to_cpu (qh->hw_token); | 385 | token = hc32_to_cpu(ehci, qh->hw_token); |
380 | 386 | ||
381 | /* force halt for unlinked or blocked qh, so we'll | 387 | /* force halt for unlinked or blocked qh, so we'll |
382 | * patch the qh later and so that completions can't | 388 | * patch the qh later and so that completions can't |
383 | * activate it while we "know" it's stopped. | 389 | * activate it while we "know" it's stopped. |
384 | */ | 390 | */ |
385 | if ((HALT_BIT & qh->hw_token) == 0) { | 391 | if ((halt & qh->hw_token) == 0) { |
386 | halt: | 392 | halt: |
387 | qh->hw_token |= HALT_BIT; | 393 | qh->hw_token |= halt; |
388 | wmb (); | 394 | wmb (); |
389 | } | 395 | } |
390 | } | 396 | } |
@@ -419,7 +425,7 @@ halt: | |||
419 | * it after fault cleanup, or recovering from silicon wrongly | 425 | * it after fault cleanup, or recovering from silicon wrongly |
420 | * overlaying the dummy qtd (which reduces DMA chatter). | 426 | * overlaying the dummy qtd (which reduces DMA chatter). |
421 | */ | 427 | */ |
422 | if (stopped != 0 || qh->hw_qtd_next == EHCI_LIST_END) { | 428 | if (stopped != 0 || qh->hw_qtd_next == EHCI_LIST_END(ehci)) { |
423 | switch (state) { | 429 | switch (state) { |
424 | case QH_STATE_IDLE: | 430 | case QH_STATE_IDLE: |
425 | qh_refresh(ehci, qh); | 431 | qh_refresh(ehci, qh); |
@@ -428,7 +434,7 @@ halt: | |||
428 | /* should be rare for periodic transfers, | 434 | /* should be rare for periodic transfers, |
429 | * except maybe high bandwidth ... | 435 | * except maybe high bandwidth ... |
430 | */ | 436 | */ |
431 | if ((__constant_cpu_to_le32 (QH_SMASK) | 437 | if ((cpu_to_hc32(ehci, QH_SMASK) |
432 | & qh->hw_info2) != 0) { | 438 | & qh->hw_info2) != 0) { |
433 | intr_deschedule (ehci, qh); | 439 | intr_deschedule (ehci, qh); |
434 | (void) qh_schedule (ehci, qh); | 440 | (void) qh_schedule (ehci, qh); |
@@ -502,8 +508,9 @@ qh_urb_transaction ( | |||
502 | is_input = usb_pipein (urb->pipe); | 508 | is_input = usb_pipein (urb->pipe); |
503 | if (usb_pipecontrol (urb->pipe)) { | 509 | if (usb_pipecontrol (urb->pipe)) { |
504 | /* SETUP pid */ | 510 | /* SETUP pid */ |
505 | qtd_fill (qtd, urb->setup_dma, sizeof (struct usb_ctrlrequest), | 511 | qtd_fill(ehci, qtd, urb->setup_dma, |
506 | token | (2 /* "setup" */ << 8), 8); | 512 | sizeof (struct usb_ctrlrequest), |
513 | token | (2 /* "setup" */ << 8), 8); | ||
507 | 514 | ||
508 | /* ... and always at least one more pid */ | 515 | /* ... and always at least one more pid */ |
509 | token ^= QTD_TOGGLE; | 516 | token ^= QTD_TOGGLE; |
@@ -512,7 +519,7 @@ qh_urb_transaction ( | |||
512 | if (unlikely (!qtd)) | 519 | if (unlikely (!qtd)) |
513 | goto cleanup; | 520 | goto cleanup; |
514 | qtd->urb = urb; | 521 | qtd->urb = urb; |
515 | qtd_prev->hw_next = QTD_NEXT (qtd->qtd_dma); | 522 | qtd_prev->hw_next = QTD_NEXT(ehci, qtd->qtd_dma); |
516 | list_add_tail (&qtd->qtd_list, head); | 523 | list_add_tail (&qtd->qtd_list, head); |
517 | 524 | ||
518 | /* for zero length DATA stages, STATUS is always IN */ | 525 | /* for zero length DATA stages, STATUS is always IN */ |
@@ -539,7 +546,7 @@ qh_urb_transaction ( | |||
539 | for (;;) { | 546 | for (;;) { |
540 | int this_qtd_len; | 547 | int this_qtd_len; |
541 | 548 | ||
542 | this_qtd_len = qtd_fill (qtd, buf, len, token, maxpacket); | 549 | this_qtd_len = qtd_fill(ehci, qtd, buf, len, token, maxpacket); |
543 | len -= this_qtd_len; | 550 | len -= this_qtd_len; |
544 | buf += this_qtd_len; | 551 | buf += this_qtd_len; |
545 | if (is_input) | 552 | if (is_input) |
@@ -557,7 +564,7 @@ qh_urb_transaction ( | |||
557 | if (unlikely (!qtd)) | 564 | if (unlikely (!qtd)) |
558 | goto cleanup; | 565 | goto cleanup; |
559 | qtd->urb = urb; | 566 | qtd->urb = urb; |
560 | qtd_prev->hw_next = QTD_NEXT (qtd->qtd_dma); | 567 | qtd_prev->hw_next = QTD_NEXT(ehci, qtd->qtd_dma); |
561 | list_add_tail (&qtd->qtd_list, head); | 568 | list_add_tail (&qtd->qtd_list, head); |
562 | } | 569 | } |
563 | 570 | ||
@@ -566,7 +573,7 @@ qh_urb_transaction ( | |||
566 | */ | 573 | */ |
567 | if (likely ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0 | 574 | if (likely ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0 |
568 | || usb_pipecontrol (urb->pipe))) | 575 | || usb_pipecontrol (urb->pipe))) |
569 | qtd->hw_alt_next = EHCI_LIST_END; | 576 | qtd->hw_alt_next = EHCI_LIST_END(ehci); |
570 | 577 | ||
571 | /* | 578 | /* |
572 | * control requests may need a terminating data "status" ack; | 579 | * control requests may need a terminating data "status" ack; |
@@ -590,17 +597,17 @@ qh_urb_transaction ( | |||
590 | if (unlikely (!qtd)) | 597 | if (unlikely (!qtd)) |
591 | goto cleanup; | 598 | goto cleanup; |
592 | qtd->urb = urb; | 599 | qtd->urb = urb; |
593 | qtd_prev->hw_next = QTD_NEXT (qtd->qtd_dma); | 600 | qtd_prev->hw_next = QTD_NEXT(ehci, qtd->qtd_dma); |
594 | list_add_tail (&qtd->qtd_list, head); | 601 | list_add_tail (&qtd->qtd_list, head); |
595 | 602 | ||
596 | /* never any data in such packets */ | 603 | /* never any data in such packets */ |
597 | qtd_fill (qtd, 0, 0, token, 0); | 604 | qtd_fill(ehci, qtd, 0, 0, token, 0); |
598 | } | 605 | } |
599 | } | 606 | } |
600 | 607 | ||
601 | /* by default, enable interrupt on urb completion */ | 608 | /* by default, enable interrupt on urb completion */ |
602 | if (likely (!(urb->transfer_flags & URB_NO_INTERRUPT))) | 609 | if (likely (!(urb->transfer_flags & URB_NO_INTERRUPT))) |
603 | qtd->hw_token |= __constant_cpu_to_le32 (QTD_IOC); | 610 | qtd->hw_token |= cpu_to_hc32(ehci, QTD_IOC); |
604 | return head; | 611 | return head; |
605 | 612 | ||
606 | cleanup: | 613 | cleanup: |
@@ -769,8 +776,8 @@ done: | |||
769 | 776 | ||
770 | /* init as live, toggle clear, advance to dummy */ | 777 | /* init as live, toggle clear, advance to dummy */ |
771 | qh->qh_state = QH_STATE_IDLE; | 778 | qh->qh_state = QH_STATE_IDLE; |
772 | qh->hw_info1 = cpu_to_le32 (info1); | 779 | qh->hw_info1 = cpu_to_hc32(ehci, info1); |
773 | qh->hw_info2 = cpu_to_le32 (info2); | 780 | qh->hw_info2 = cpu_to_hc32(ehci, info2); |
774 | usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1); | 781 | usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1); |
775 | qh_refresh (ehci, qh); | 782 | qh_refresh (ehci, qh); |
776 | return qh; | 783 | return qh; |
@@ -782,7 +789,7 @@ done: | |||
782 | 789 | ||
783 | static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh) | 790 | static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh) |
784 | { | 791 | { |
785 | __le32 dma = QH_NEXT (qh->qh_dma); | 792 | __hc32 dma = QH_NEXT(ehci, qh->qh_dma); |
786 | struct ehci_qh *head; | 793 | struct ehci_qh *head; |
787 | 794 | ||
788 | /* (re)start the async schedule? */ | 795 | /* (re)start the async schedule? */ |
@@ -820,8 +827,6 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
820 | 827 | ||
821 | /*-------------------------------------------------------------------------*/ | 828 | /*-------------------------------------------------------------------------*/ |
822 | 829 | ||
823 | #define QH_ADDR_MASK __constant_cpu_to_le32(0x7f) | ||
824 | |||
825 | /* | 830 | /* |
826 | * For control/bulk/interrupt, return QH with these TDs appended. | 831 | * For control/bulk/interrupt, return QH with these TDs appended. |
827 | * Allocates and initializes the QH if necessary. | 832 | * Allocates and initializes the QH if necessary. |
@@ -837,6 +842,7 @@ static struct ehci_qh *qh_append_tds ( | |||
837 | ) | 842 | ) |
838 | { | 843 | { |
839 | struct ehci_qh *qh = NULL; | 844 | struct ehci_qh *qh = NULL; |
845 | u32 qh_addr_mask = cpu_to_hc32(ehci, 0x7f); | ||
840 | 846 | ||
841 | qh = (struct ehci_qh *) *ptr; | 847 | qh = (struct ehci_qh *) *ptr; |
842 | if (unlikely (qh == NULL)) { | 848 | if (unlikely (qh == NULL)) { |
@@ -858,7 +864,7 @@ static struct ehci_qh *qh_append_tds ( | |||
858 | 864 | ||
859 | /* usb_reset_device() briefly reverts to address 0 */ | 865 | /* usb_reset_device() briefly reverts to address 0 */ |
860 | if (usb_pipedevice (urb->pipe) == 0) | 866 | if (usb_pipedevice (urb->pipe) == 0) |
861 | qh->hw_info1 &= ~QH_ADDR_MASK; | 867 | qh->hw_info1 &= ~qh_addr_mask; |
862 | } | 868 | } |
863 | 869 | ||
864 | /* just one way to queue requests: swap with the dummy qtd. | 870 | /* just one way to queue requests: swap with the dummy qtd. |
@@ -867,7 +873,7 @@ static struct ehci_qh *qh_append_tds ( | |||
867 | if (likely (qtd != NULL)) { | 873 | if (likely (qtd != NULL)) { |
868 | struct ehci_qtd *dummy; | 874 | struct ehci_qtd *dummy; |
869 | dma_addr_t dma; | 875 | dma_addr_t dma; |
870 | __le32 token; | 876 | __hc32 token; |
871 | 877 | ||
872 | /* to avoid racing the HC, use the dummy td instead of | 878 | /* to avoid racing the HC, use the dummy td instead of |
873 | * the first td of our list (becomes new dummy). both | 879 | * the first td of our list (becomes new dummy). both |
@@ -875,7 +881,7 @@ static struct ehci_qh *qh_append_tds ( | |||
875 | * HC is allowed to fetch the old dummy (4.10.2). | 881 | * HC is allowed to fetch the old dummy (4.10.2). |
876 | */ | 882 | */ |
877 | token = qtd->hw_token; | 883 | token = qtd->hw_token; |
878 | qtd->hw_token = HALT_BIT; | 884 | qtd->hw_token = HALT_BIT(ehci); |
879 | wmb (); | 885 | wmb (); |
880 | dummy = qh->dummy; | 886 | dummy = qh->dummy; |
881 | 887 | ||
@@ -887,14 +893,14 @@ static struct ehci_qh *qh_append_tds ( | |||
887 | list_add (&dummy->qtd_list, qtd_list); | 893 | list_add (&dummy->qtd_list, qtd_list); |
888 | __list_splice (qtd_list, qh->qtd_list.prev); | 894 | __list_splice (qtd_list, qh->qtd_list.prev); |
889 | 895 | ||
890 | ehci_qtd_init (qtd, qtd->qtd_dma); | 896 | ehci_qtd_init(ehci, qtd, qtd->qtd_dma); |
891 | qh->dummy = qtd; | 897 | qh->dummy = qtd; |
892 | 898 | ||
893 | /* hc must see the new dummy at list end */ | 899 | /* hc must see the new dummy at list end */ |
894 | dma = qtd->qtd_dma; | 900 | dma = qtd->qtd_dma; |
895 | qtd = list_entry (qh->qtd_list.prev, | 901 | qtd = list_entry (qh->qtd_list.prev, |
896 | struct ehci_qtd, qtd_list); | 902 | struct ehci_qtd, qtd_list); |
897 | qtd->hw_next = QTD_NEXT (dma); | 903 | qtd->hw_next = QTD_NEXT(ehci, dma); |
898 | 904 | ||
899 | /* let the hc process these next qtds */ | 905 | /* let the hc process these next qtds */ |
900 | wmb (); | 906 | wmb (); |
@@ -970,7 +976,7 @@ static void end_unlink_async (struct ehci_hcd *ehci) | |||
970 | 976 | ||
971 | timer_action_done (ehci, TIMER_IAA_WATCHDOG); | 977 | timer_action_done (ehci, TIMER_IAA_WATCHDOG); |
972 | 978 | ||
973 | // qh->hw_next = cpu_to_le32 (qh->qh_dma); | 979 | // qh->hw_next = cpu_to_hc32(qh->qh_dma); |
974 | qh->qh_state = QH_STATE_IDLE; | 980 | qh->qh_state = QH_STATE_IDLE; |
975 | qh->qh_next.qh = NULL; | 981 | qh->qh_next.qh = NULL; |
976 | qh_put (qh); // refcount from reclaim | 982 | qh_put (qh); // refcount from reclaim |
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index 7b5ae7111f23..d4a8ace49676 100644 --- a/drivers/usb/host/ehci-sched.c +++ b/drivers/usb/host/ehci-sched.c | |||
@@ -44,9 +44,10 @@ static int ehci_get_frame (struct usb_hcd *hcd); | |||
44 | * @tag: hardware tag for type of this record | 44 | * @tag: hardware tag for type of this record |
45 | */ | 45 | */ |
46 | static union ehci_shadow * | 46 | static union ehci_shadow * |
47 | periodic_next_shadow (union ehci_shadow *periodic, __le32 tag) | 47 | periodic_next_shadow(struct ehci_hcd *ehci, union ehci_shadow *periodic, |
48 | __hc32 tag) | ||
48 | { | 49 | { |
49 | switch (tag) { | 50 | switch (hc32_to_cpu(ehci, tag)) { |
50 | case Q_TYPE_QH: | 51 | case Q_TYPE_QH: |
51 | return &periodic->qh->qh_next; | 52 | return &periodic->qh->qh_next; |
52 | case Q_TYPE_FSTN: | 53 | case Q_TYPE_FSTN: |
@@ -62,13 +63,14 @@ periodic_next_shadow (union ehci_shadow *periodic, __le32 tag) | |||
62 | /* caller must hold ehci->lock */ | 63 | /* caller must hold ehci->lock */ |
63 | static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr) | 64 | static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr) |
64 | { | 65 | { |
65 | union ehci_shadow *prev_p = &ehci->pshadow [frame]; | 66 | union ehci_shadow *prev_p = &ehci->pshadow[frame]; |
66 | __le32 *hw_p = &ehci->periodic [frame]; | 67 | __hc32 *hw_p = &ehci->periodic[frame]; |
67 | union ehci_shadow here = *prev_p; | 68 | union ehci_shadow here = *prev_p; |
68 | 69 | ||
69 | /* find predecessor of "ptr"; hw and shadow lists are in sync */ | 70 | /* find predecessor of "ptr"; hw and shadow lists are in sync */ |
70 | while (here.ptr && here.ptr != ptr) { | 71 | while (here.ptr && here.ptr != ptr) { |
71 | prev_p = periodic_next_shadow (prev_p, Q_NEXT_TYPE (*hw_p)); | 72 | prev_p = periodic_next_shadow(ehci, prev_p, |
73 | Q_NEXT_TYPE(ehci, *hw_p)); | ||
72 | hw_p = here.hw_next; | 74 | hw_p = here.hw_next; |
73 | here = *prev_p; | 75 | here = *prev_p; |
74 | } | 76 | } |
@@ -79,7 +81,8 @@ static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr) | |||
79 | /* update shadow and hardware lists ... the old "next" pointers | 81 | /* update shadow and hardware lists ... the old "next" pointers |
80 | * from ptr may still be in use, the caller updates them. | 82 | * from ptr may still be in use, the caller updates them. |
81 | */ | 83 | */ |
82 | *prev_p = *periodic_next_shadow (&here, Q_NEXT_TYPE (*hw_p)); | 84 | *prev_p = *periodic_next_shadow(ehci, &here, |
85 | Q_NEXT_TYPE(ehci, *hw_p)); | ||
83 | *hw_p = *here.hw_next; | 86 | *hw_p = *here.hw_next; |
84 | } | 87 | } |
85 | 88 | ||
@@ -87,18 +90,19 @@ static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr) | |||
87 | static unsigned short | 90 | static unsigned short |
88 | periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe) | 91 | periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe) |
89 | { | 92 | { |
90 | __le32 *hw_p = &ehci->periodic [frame]; | 93 | __hc32 *hw_p = &ehci->periodic [frame]; |
91 | union ehci_shadow *q = &ehci->pshadow [frame]; | 94 | union ehci_shadow *q = &ehci->pshadow [frame]; |
92 | unsigned usecs = 0; | 95 | unsigned usecs = 0; |
93 | 96 | ||
94 | while (q->ptr) { | 97 | while (q->ptr) { |
95 | switch (Q_NEXT_TYPE (*hw_p)) { | 98 | switch (hc32_to_cpu(ehci, Q_NEXT_TYPE(ehci, *hw_p))) { |
96 | case Q_TYPE_QH: | 99 | case Q_TYPE_QH: |
97 | /* is it in the S-mask? */ | 100 | /* is it in the S-mask? */ |
98 | if (q->qh->hw_info2 & cpu_to_le32 (1 << uframe)) | 101 | if (q->qh->hw_info2 & cpu_to_hc32(ehci, 1 << uframe)) |
99 | usecs += q->qh->usecs; | 102 | usecs += q->qh->usecs; |
100 | /* ... or C-mask? */ | 103 | /* ... or C-mask? */ |
101 | if (q->qh->hw_info2 & cpu_to_le32 (1 << (8 + uframe))) | 104 | if (q->qh->hw_info2 & cpu_to_hc32(ehci, |
105 | 1 << (8 + uframe))) | ||
102 | usecs += q->qh->c_usecs; | 106 | usecs += q->qh->c_usecs; |
103 | hw_p = &q->qh->hw_next; | 107 | hw_p = &q->qh->hw_next; |
104 | q = &q->qh->qh_next; | 108 | q = &q->qh->qh_next; |
@@ -108,7 +112,7 @@ periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe) | |||
108 | /* for "save place" FSTNs, count the relevant INTR | 112 | /* for "save place" FSTNs, count the relevant INTR |
109 | * bandwidth from the previous frame | 113 | * bandwidth from the previous frame |
110 | */ | 114 | */ |
111 | if (q->fstn->hw_prev != EHCI_LIST_END) { | 115 | if (q->fstn->hw_prev != EHCI_LIST_END(ehci)) { |
112 | ehci_dbg (ehci, "ignoring FSTN cost ...\n"); | 116 | ehci_dbg (ehci, "ignoring FSTN cost ...\n"); |
113 | } | 117 | } |
114 | hw_p = &q->fstn->hw_next; | 118 | hw_p = &q->fstn->hw_next; |
@@ -121,9 +125,10 @@ periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe) | |||
121 | break; | 125 | break; |
122 | case Q_TYPE_SITD: | 126 | case Q_TYPE_SITD: |
123 | /* is it in the S-mask? (count SPLIT, DATA) */ | 127 | /* is it in the S-mask? (count SPLIT, DATA) */ |
124 | if (q->sitd->hw_uframe & cpu_to_le32 (1 << uframe)) { | 128 | if (q->sitd->hw_uframe & cpu_to_hc32(ehci, |
129 | 1 << uframe)) { | ||
125 | if (q->sitd->hw_fullspeed_ep & | 130 | if (q->sitd->hw_fullspeed_ep & |
126 | __constant_cpu_to_le32 (1<<31)) | 131 | cpu_to_hc32(ehci, 1<<31)) |
127 | usecs += q->sitd->stream->usecs; | 132 | usecs += q->sitd->stream->usecs; |
128 | else /* worst case for OUT start-split */ | 133 | else /* worst case for OUT start-split */ |
129 | usecs += HS_USECS_ISO (188); | 134 | usecs += HS_USECS_ISO (188); |
@@ -131,7 +136,7 @@ periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe) | |||
131 | 136 | ||
132 | /* ... C-mask? (count CSPLIT, DATA) */ | 137 | /* ... C-mask? (count CSPLIT, DATA) */ |
133 | if (q->sitd->hw_uframe & | 138 | if (q->sitd->hw_uframe & |
134 | cpu_to_le32 (1 << (8 + uframe))) { | 139 | cpu_to_hc32(ehci, 1 << (8 + uframe))) { |
135 | /* worst case for IN complete-split */ | 140 | /* worst case for IN complete-split */ |
136 | usecs += q->sitd->stream->c_usecs; | 141 | usecs += q->sitd->stream->c_usecs; |
137 | } | 142 | } |
@@ -173,9 +178,9 @@ static int same_tt (struct usb_device *dev1, struct usb_device *dev2) | |||
173 | * will cause a transfer in "B-frame" uframe 0. "B-frames" lag | 178 | * will cause a transfer in "B-frame" uframe 0. "B-frames" lag |
174 | * "H-frames" by 1 uframe. See the EHCI spec sec 4.5 and figure 4.7. | 179 | * "H-frames" by 1 uframe. See the EHCI spec sec 4.5 and figure 4.7. |
175 | */ | 180 | */ |
176 | static inline unsigned char tt_start_uframe(struct ehci_hcd *ehci, __le32 mask) | 181 | static inline unsigned char tt_start_uframe(struct ehci_hcd *ehci, __hc32 mask) |
177 | { | 182 | { |
178 | unsigned char smask = QH_SMASK & le32_to_cpu(mask); | 183 | unsigned char smask = QH_SMASK & hc32_to_cpu(ehci, mask); |
179 | if (!smask) { | 184 | if (!smask) { |
180 | ehci_err(ehci, "invalid empty smask!\n"); | 185 | ehci_err(ehci, "invalid empty smask!\n"); |
181 | /* uframe 7 can't have bw so this will indicate failure */ | 186 | /* uframe 7 can't have bw so this will indicate failure */ |
@@ -217,14 +222,14 @@ periodic_tt_usecs ( | |||
217 | unsigned short tt_usecs[8] | 222 | unsigned short tt_usecs[8] |
218 | ) | 223 | ) |
219 | { | 224 | { |
220 | __le32 *hw_p = &ehci->periodic [frame]; | 225 | __hc32 *hw_p = &ehci->periodic [frame]; |
221 | union ehci_shadow *q = &ehci->pshadow [frame]; | 226 | union ehci_shadow *q = &ehci->pshadow [frame]; |
222 | unsigned char uf; | 227 | unsigned char uf; |
223 | 228 | ||
224 | memset(tt_usecs, 0, 16); | 229 | memset(tt_usecs, 0, 16); |
225 | 230 | ||
226 | while (q->ptr) { | 231 | while (q->ptr) { |
227 | switch (Q_NEXT_TYPE(*hw_p)) { | 232 | switch (hc32_to_cpu(ehci, Q_NEXT_TYPE(ehci, *hw_p))) { |
228 | case Q_TYPE_ITD: | 233 | case Q_TYPE_ITD: |
229 | hw_p = &q->itd->hw_next; | 234 | hw_p = &q->itd->hw_next; |
230 | q = &q->itd->itd_next; | 235 | q = &q->itd->itd_next; |
@@ -247,8 +252,8 @@ periodic_tt_usecs ( | |||
247 | continue; | 252 | continue; |
248 | // case Q_TYPE_FSTN: | 253 | // case Q_TYPE_FSTN: |
249 | default: | 254 | default: |
250 | ehci_dbg(ehci, | 255 | ehci_dbg(ehci, "ignoring periodic frame %d FSTN\n", |
251 | "ignoring periodic frame %d FSTN\n", frame); | 256 | frame); |
252 | hw_p = &q->fstn->hw_next; | 257 | hw_p = &q->fstn->hw_next; |
253 | q = &q->fstn->fstn_next; | 258 | q = &q->fstn->fstn_next; |
254 | } | 259 | } |
@@ -368,41 +373,42 @@ static int tt_no_collision ( | |||
368 | */ | 373 | */ |
369 | for (; frame < ehci->periodic_size; frame += period) { | 374 | for (; frame < ehci->periodic_size; frame += period) { |
370 | union ehci_shadow here; | 375 | union ehci_shadow here; |
371 | __le32 type; | 376 | __hc32 type; |
372 | 377 | ||
373 | here = ehci->pshadow [frame]; | 378 | here = ehci->pshadow [frame]; |
374 | type = Q_NEXT_TYPE (ehci->periodic [frame]); | 379 | type = Q_NEXT_TYPE(ehci, ehci->periodic [frame]); |
375 | while (here.ptr) { | 380 | while (here.ptr) { |
376 | switch (type) { | 381 | switch (hc32_to_cpu(ehci, type)) { |
377 | case Q_TYPE_ITD: | 382 | case Q_TYPE_ITD: |
378 | type = Q_NEXT_TYPE (here.itd->hw_next); | 383 | type = Q_NEXT_TYPE(ehci, here.itd->hw_next); |
379 | here = here.itd->itd_next; | 384 | here = here.itd->itd_next; |
380 | continue; | 385 | continue; |
381 | case Q_TYPE_QH: | 386 | case Q_TYPE_QH: |
382 | if (same_tt (dev, here.qh->dev)) { | 387 | if (same_tt (dev, here.qh->dev)) { |
383 | u32 mask; | 388 | u32 mask; |
384 | 389 | ||
385 | mask = le32_to_cpu (here.qh->hw_info2); | 390 | mask = hc32_to_cpu(ehci, |
391 | here.qh->hw_info2); | ||
386 | /* "knows" no gap is needed */ | 392 | /* "knows" no gap is needed */ |
387 | mask |= mask >> 8; | 393 | mask |= mask >> 8; |
388 | if (mask & uf_mask) | 394 | if (mask & uf_mask) |
389 | break; | 395 | break; |
390 | } | 396 | } |
391 | type = Q_NEXT_TYPE (here.qh->hw_next); | 397 | type = Q_NEXT_TYPE(ehci, here.qh->hw_next); |
392 | here = here.qh->qh_next; | 398 | here = here.qh->qh_next; |
393 | continue; | 399 | continue; |
394 | case Q_TYPE_SITD: | 400 | case Q_TYPE_SITD: |
395 | if (same_tt (dev, here.sitd->urb->dev)) { | 401 | if (same_tt (dev, here.sitd->urb->dev)) { |
396 | u16 mask; | 402 | u16 mask; |
397 | 403 | ||
398 | mask = le32_to_cpu (here.sitd | 404 | mask = hc32_to_cpu(ehci, here.sitd |
399 | ->hw_uframe); | 405 | ->hw_uframe); |
400 | /* FIXME assumes no gap for IN! */ | 406 | /* FIXME assumes no gap for IN! */ |
401 | mask |= mask >> 8; | 407 | mask |= mask >> 8; |
402 | if (mask & uf_mask) | 408 | if (mask & uf_mask) |
403 | break; | 409 | break; |
404 | } | 410 | } |
405 | type = Q_NEXT_TYPE (here.sitd->hw_next); | 411 | type = Q_NEXT_TYPE(ehci, here.sitd->hw_next); |
406 | here = here.sitd->sitd_next; | 412 | here = here.sitd->sitd_next; |
407 | continue; | 413 | continue; |
408 | // case Q_TYPE_FSTN: | 414 | // case Q_TYPE_FSTN: |
@@ -473,6 +479,109 @@ static int disable_periodic (struct ehci_hcd *ehci) | |||
473 | } | 479 | } |
474 | 480 | ||
475 | /*-------------------------------------------------------------------------*/ | 481 | /*-------------------------------------------------------------------------*/ |
482 | #ifdef CONFIG_CPU_FREQ | ||
483 | |||
484 | static int safe_to_modify_i (struct ehci_hcd *ehci, struct ehci_qh *qh) | ||
485 | { | ||
486 | int now; /* current (frame * 8) + uframe */ | ||
487 | int prev_start, next_start; /* uframes from/to split start */ | ||
488 | int start_uframe = ffs(le32_to_cpup (&qh->hw_info2) & QH_SMASK); | ||
489 | int end_uframe = fls((le32_to_cpup (&qh->hw_info2) & QH_CMASK) >> 8); | ||
490 | int split_duration = end_uframe - start_uframe; | ||
491 | |||
492 | now = readl(&ehci->regs->frame_index) % (ehci->periodic_size << 3); | ||
493 | |||
494 | next_start = ((1024 << 3) + (qh->start << 3) + start_uframe - now) | ||
495 | % (qh->period << 3); | ||
496 | prev_start = (qh->period << 3) - next_start; | ||
497 | |||
498 | /* | ||
499 | * Make sure there will be at least one uframe when qh is safe. | ||
500 | */ | ||
501 | if ((qh->period << 3) <= (ehci->i_thresh + 2 + split_duration)) | ||
502 | /* never safe */ | ||
503 | return -EINVAL; | ||
504 | |||
505 | /* | ||
506 | * Wait 1 uframe after transaction should have started, to make | ||
507 | * sure controller has time to write back overlay, so we can | ||
508 | * check QTD_STS_STS to see if transaction is in progress. | ||
509 | */ | ||
510 | if ((next_start > ehci->i_thresh) && (prev_start > 1)) | ||
511 | /* safe to set "i" bit if split isn't in progress */ | ||
512 | return (qh->hw_token & STATUS_BIT(ehci)) ? 0 : 1; | ||
513 | else | ||
514 | return 0; | ||
515 | } | ||
516 | |||
517 | /* Set inactivate bit for all the split interrupt QHs. */ | ||
518 | static void qh_inactivate_split_intr_qhs (struct ehci_hcd *ehci) | ||
519 | { | ||
520 | struct ehci_qh *qh; | ||
521 | int not_done, safe; | ||
522 | u32 inactivate = INACTIVATE_BIT(ehci); | ||
523 | u32 active = ACTIVE_BIT(ehci); | ||
524 | |||
525 | do { | ||
526 | not_done = 0; | ||
527 | list_for_each_entry(qh, &ehci->split_intr_qhs, | ||
528 | split_intr_qhs) { | ||
529 | if (qh->hw_info1 & inactivate) | ||
530 | /* already off */ | ||
531 | continue; | ||
532 | /* | ||
533 | * To avoid setting "I" after the start split happens, | ||
534 | * don't set it if the QH might be cached in the | ||
535 | * controller. Some HCs (Broadcom/ServerWorks HT1000) | ||
536 | * will stop in the middle of a split transaction when | ||
537 | * the "I" bit is set. | ||
538 | */ | ||
539 | safe = safe_to_modify_i(ehci, qh); | ||
540 | if (safe == 0) { | ||
541 | not_done = 1; | ||
542 | } else if (safe > 0) { | ||
543 | qh->was_active = qh->hw_token & active; | ||
544 | qh->hw_info1 |= inactivate; | ||
545 | } | ||
546 | } | ||
547 | } while (not_done); | ||
548 | wmb(); | ||
549 | } | ||
550 | |||
551 | static void qh_reactivate_split_intr_qhs (struct ehci_hcd *ehci) | ||
552 | { | ||
553 | struct ehci_qh *qh; | ||
554 | u32 token; | ||
555 | int not_done, safe; | ||
556 | u32 inactivate = INACTIVATE_BIT(ehci); | ||
557 | u32 active = ACTIVE_BIT(ehci); | ||
558 | u32 halt = HALT_BIT(ehci); | ||
559 | |||
560 | do { | ||
561 | not_done = 0; | ||
562 | list_for_each_entry(qh, &ehci->split_intr_qhs, split_intr_qhs) { | ||
563 | if (!(qh->hw_info1 & inactivate)) /* already on */ | ||
564 | continue; | ||
565 | /* | ||
566 | * Don't reactivate if cached, or controller might | ||
567 | * overwrite overlay after we modify it! | ||
568 | */ | ||
569 | safe = safe_to_modify_i(ehci, qh); | ||
570 | if (safe == 0) { | ||
571 | not_done = 1; | ||
572 | } else if (safe > 0) { | ||
573 | /* See EHCI 1.0 section 4.15.2.4. */ | ||
574 | token = qh->hw_token; | ||
575 | qh->hw_token = (token | halt) & ~active; | ||
576 | wmb(); | ||
577 | qh->hw_info1 &= ~inactivate; | ||
578 | wmb(); | ||
579 | qh->hw_token = (token & ~halt) | qh->was_active; | ||
580 | } | ||
581 | } | ||
582 | } while (not_done); | ||
583 | } | ||
584 | #endif | ||
476 | 585 | ||
477 | /* periodic schedule slots have iso tds (normal or split) first, then a | 586 | /* periodic schedule slots have iso tds (normal or split) first, then a |
478 | * sparse tree for active interrupt transfers. | 587 | * sparse tree for active interrupt transfers. |
@@ -487,25 +596,36 @@ static int qh_link_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
487 | 596 | ||
488 | dev_dbg (&qh->dev->dev, | 597 | dev_dbg (&qh->dev->dev, |
489 | "link qh%d-%04x/%p start %d [%d/%d us]\n", | 598 | "link qh%d-%04x/%p start %d [%d/%d us]\n", |
490 | period, le32_to_cpup (&qh->hw_info2) & (QH_CMASK | QH_SMASK), | 599 | period, hc32_to_cpup(ehci, &qh->hw_info2) & (QH_CMASK | QH_SMASK), |
491 | qh, qh->start, qh->usecs, qh->c_usecs); | 600 | qh, qh->start, qh->usecs, qh->c_usecs); |
492 | 601 | ||
602 | #ifdef CONFIG_CPU_FREQ | ||
603 | /* | ||
604 | * If low/full speed interrupt QHs are inactive (because of | ||
605 | * cpufreq changing processor speeds), start QH with I flag set-- | ||
606 | * it will automatically be cleared when cpufreq is done. | ||
607 | */ | ||
608 | if (ehci->cpufreq_changing) | ||
609 | if (!(qh->hw_info1 & (cpu_to_le32(1 << 13)))) | ||
610 | qh->hw_info1 |= INACTIVATE_BIT(ehci); | ||
611 | #endif | ||
612 | |||
493 | /* high bandwidth, or otherwise every microframe */ | 613 | /* high bandwidth, or otherwise every microframe */ |
494 | if (period == 0) | 614 | if (period == 0) |
495 | period = 1; | 615 | period = 1; |
496 | 616 | ||
497 | for (i = qh->start; i < ehci->periodic_size; i += period) { | 617 | for (i = qh->start; i < ehci->periodic_size; i += period) { |
498 | union ehci_shadow *prev = &ehci->pshadow [i]; | 618 | union ehci_shadow *prev = &ehci->pshadow[i]; |
499 | __le32 *hw_p = &ehci->periodic [i]; | 619 | __hc32 *hw_p = &ehci->periodic[i]; |
500 | union ehci_shadow here = *prev; | 620 | union ehci_shadow here = *prev; |
501 | __le32 type = 0; | 621 | __hc32 type = 0; |
502 | 622 | ||
503 | /* skip the iso nodes at list head */ | 623 | /* skip the iso nodes at list head */ |
504 | while (here.ptr) { | 624 | while (here.ptr) { |
505 | type = Q_NEXT_TYPE (*hw_p); | 625 | type = Q_NEXT_TYPE(ehci, *hw_p); |
506 | if (type == Q_TYPE_QH) | 626 | if (type == cpu_to_hc32(ehci, Q_TYPE_QH)) |
507 | break; | 627 | break; |
508 | prev = periodic_next_shadow (prev, type); | 628 | prev = periodic_next_shadow(ehci, prev, type); |
509 | hw_p = &here.qh->hw_next; | 629 | hw_p = &here.qh->hw_next; |
510 | here = *prev; | 630 | here = *prev; |
511 | } | 631 | } |
@@ -527,7 +647,7 @@ static int qh_link_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
527 | qh->hw_next = *hw_p; | 647 | qh->hw_next = *hw_p; |
528 | wmb (); | 648 | wmb (); |
529 | prev->qh = qh; | 649 | prev->qh = qh; |
530 | *hw_p = QH_NEXT (qh->qh_dma); | 650 | *hw_p = QH_NEXT (ehci, qh->qh_dma); |
531 | } | 651 | } |
532 | } | 652 | } |
533 | qh->qh_state = QH_STATE_LINKED; | 653 | qh->qh_state = QH_STATE_LINKED; |
@@ -538,6 +658,12 @@ static int qh_link_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
538 | ? ((qh->usecs + qh->c_usecs) / qh->period) | 658 | ? ((qh->usecs + qh->c_usecs) / qh->period) |
539 | : (qh->usecs * 8); | 659 | : (qh->usecs * 8); |
540 | 660 | ||
661 | #ifdef CONFIG_CPU_FREQ | ||
662 | /* add qh to list of low/full speed interrupt QHs, if applicable */ | ||
663 | if (!(qh->hw_info1 & (cpu_to_le32(1 << 13)))) { | ||
664 | list_add(&qh->split_intr_qhs, &ehci->split_intr_qhs); | ||
665 | } | ||
666 | #endif | ||
541 | /* maybe enable periodic schedule processing */ | 667 | /* maybe enable periodic schedule processing */ |
542 | if (!ehci->periodic_sched++) | 668 | if (!ehci->periodic_sched++) |
543 | return enable_periodic (ehci); | 669 | return enable_periodic (ehci); |
@@ -555,7 +681,14 @@ static void qh_unlink_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
555 | // and this qh is active in the current uframe | 681 | // and this qh is active in the current uframe |
556 | // (and overlay token SplitXstate is false?) | 682 | // (and overlay token SplitXstate is false?) |
557 | // THEN | 683 | // THEN |
558 | // qh->hw_info1 |= __constant_cpu_to_le32 (1 << 7 /* "ignore" */); | 684 | // qh->hw_info1 |= __constant_cpu_to_hc32(1 << 7 /* "ignore" */); |
685 | |||
686 | #ifdef CONFIG_CPU_FREQ | ||
687 | /* remove qh from list of low/full speed interrupt QHs */ | ||
688 | if (!(qh->hw_info1 & (cpu_to_le32(1 << 13)))) { | ||
689 | list_del_init(&qh->split_intr_qhs); | ||
690 | } | ||
691 | #endif | ||
559 | 692 | ||
560 | /* high bandwidth, or otherwise part of every microframe */ | 693 | /* high bandwidth, or otherwise part of every microframe */ |
561 | if ((period = qh->period) == 0) | 694 | if ((period = qh->period) == 0) |
@@ -572,7 +705,7 @@ static void qh_unlink_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
572 | dev_dbg (&qh->dev->dev, | 705 | dev_dbg (&qh->dev->dev, |
573 | "unlink qh%d-%04x/%p start %d [%d/%d us]\n", | 706 | "unlink qh%d-%04x/%p start %d [%d/%d us]\n", |
574 | qh->period, | 707 | qh->period, |
575 | le32_to_cpup (&qh->hw_info2) & (QH_CMASK | QH_SMASK), | 708 | hc32_to_cpup(ehci, &qh->hw_info2) & (QH_CMASK | QH_SMASK), |
576 | qh, qh->start, qh->usecs, qh->c_usecs); | 709 | qh, qh->start, qh->usecs, qh->c_usecs); |
577 | 710 | ||
578 | /* qh->qh_next still "live" to HC */ | 711 | /* qh->qh_next still "live" to HC */ |
@@ -598,7 +731,7 @@ static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
598 | * active high speed queues may need bigger delays... | 731 | * active high speed queues may need bigger delays... |
599 | */ | 732 | */ |
600 | if (list_empty (&qh->qtd_list) | 733 | if (list_empty (&qh->qtd_list) |
601 | || (__constant_cpu_to_le32 (QH_CMASK) | 734 | || (cpu_to_hc32(ehci, QH_CMASK) |
602 | & qh->hw_info2) != 0) | 735 | & qh->hw_info2) != 0) |
603 | wait = 2; | 736 | wait = 2; |
604 | else | 737 | else |
@@ -606,7 +739,7 @@ static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
606 | 739 | ||
607 | udelay (wait); | 740 | udelay (wait); |
608 | qh->qh_state = QH_STATE_IDLE; | 741 | qh->qh_state = QH_STATE_IDLE; |
609 | qh->hw_next = EHCI_LIST_END; | 742 | qh->hw_next = EHCI_LIST_END(ehci); |
610 | wmb (); | 743 | wmb (); |
611 | } | 744 | } |
612 | 745 | ||
@@ -663,7 +796,7 @@ static int check_intr_schedule ( | |||
663 | unsigned frame, | 796 | unsigned frame, |
664 | unsigned uframe, | 797 | unsigned uframe, |
665 | const struct ehci_qh *qh, | 798 | const struct ehci_qh *qh, |
666 | __le32 *c_maskp | 799 | __hc32 *c_maskp |
667 | ) | 800 | ) |
668 | { | 801 | { |
669 | int retval = -ENOSPC; | 802 | int retval = -ENOSPC; |
@@ -695,7 +828,7 @@ static int check_intr_schedule ( | |||
695 | 828 | ||
696 | retval = 0; | 829 | retval = 0; |
697 | 830 | ||
698 | *c_maskp = cpu_to_le32 (mask << 8); | 831 | *c_maskp = cpu_to_hc32(ehci, mask << 8); |
699 | } | 832 | } |
700 | #else | 833 | #else |
701 | /* Make sure this tt's buffer is also available for CSPLITs. | 834 | /* Make sure this tt's buffer is also available for CSPLITs. |
@@ -706,7 +839,7 @@ static int check_intr_schedule ( | |||
706 | * one smart pass... | 839 | * one smart pass... |
707 | */ | 840 | */ |
708 | mask = 0x03 << (uframe + qh->gap_uf); | 841 | mask = 0x03 << (uframe + qh->gap_uf); |
709 | *c_maskp = cpu_to_le32 (mask << 8); | 842 | *c_maskp = cpu_to_hc32(ehci, mask << 8); |
710 | 843 | ||
711 | mask |= 1 << uframe; | 844 | mask |= 1 << uframe; |
712 | if (tt_no_collision (ehci, qh->period, qh->dev, frame, mask)) { | 845 | if (tt_no_collision (ehci, qh->period, qh->dev, frame, mask)) { |
@@ -726,20 +859,20 @@ done: | |||
726 | /* "first fit" scheduling policy used the first time through, | 859 | /* "first fit" scheduling policy used the first time through, |
727 | * or when the previous schedule slot can't be re-used. | 860 | * or when the previous schedule slot can't be re-used. |
728 | */ | 861 | */ |
729 | static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh) | 862 | static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh) |
730 | { | 863 | { |
731 | int status; | 864 | int status; |
732 | unsigned uframe; | 865 | unsigned uframe; |
733 | __le32 c_mask; | 866 | __hc32 c_mask; |
734 | unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ | 867 | unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ |
735 | 868 | ||
736 | qh_refresh(ehci, qh); | 869 | qh_refresh(ehci, qh); |
737 | qh->hw_next = EHCI_LIST_END; | 870 | qh->hw_next = EHCI_LIST_END(ehci); |
738 | frame = qh->start; | 871 | frame = qh->start; |
739 | 872 | ||
740 | /* reuse the previous schedule slots, if we can */ | 873 | /* reuse the previous schedule slots, if we can */ |
741 | if (frame < qh->period) { | 874 | if (frame < qh->period) { |
742 | uframe = ffs (le32_to_cpup (&qh->hw_info2) & QH_SMASK); | 875 | uframe = ffs(hc32_to_cpup(ehci, &qh->hw_info2) & QH_SMASK); |
743 | status = check_intr_schedule (ehci, frame, --uframe, | 876 | status = check_intr_schedule (ehci, frame, --uframe, |
744 | qh, &c_mask); | 877 | qh, &c_mask); |
745 | } else { | 878 | } else { |
@@ -775,10 +908,10 @@ static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
775 | qh->start = frame; | 908 | qh->start = frame; |
776 | 909 | ||
777 | /* reset S-frame and (maybe) C-frame masks */ | 910 | /* reset S-frame and (maybe) C-frame masks */ |
778 | qh->hw_info2 &= __constant_cpu_to_le32(~(QH_CMASK | QH_SMASK)); | 911 | qh->hw_info2 &= cpu_to_hc32(ehci, ~(QH_CMASK | QH_SMASK)); |
779 | qh->hw_info2 |= qh->period | 912 | qh->hw_info2 |= qh->period |
780 | ? cpu_to_le32 (1 << uframe) | 913 | ? cpu_to_hc32(ehci, 1 << uframe) |
781 | : __constant_cpu_to_le32 (QH_SMASK); | 914 | : cpu_to_hc32(ehci, QH_SMASK); |
782 | qh->hw_info2 |= c_mask; | 915 | qh->hw_info2 |= c_mask; |
783 | } else | 916 | } else |
784 | ehci_dbg (ehci, "reused qh %p schedule\n", qh); | 917 | ehci_dbg (ehci, "reused qh %p schedule\n", qh); |
@@ -808,7 +941,7 @@ static int intr_submit ( | |||
808 | spin_lock_irqsave (&ehci->lock, flags); | 941 | spin_lock_irqsave (&ehci->lock, flags); |
809 | 942 | ||
810 | if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, | 943 | if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, |
811 | &ehci_to_hcd(ehci)->flags))) { | 944 | &ehci_to_hcd(ehci)->flags))) { |
812 | status = -ESHUTDOWN; | 945 | status = -ESHUTDOWN; |
813 | goto done; | 946 | goto done; |
814 | } | 947 | } |
@@ -898,9 +1031,9 @@ iso_stream_init ( | |||
898 | buf1 |= maxp; | 1031 | buf1 |= maxp; |
899 | maxp *= multi; | 1032 | maxp *= multi; |
900 | 1033 | ||
901 | stream->buf0 = cpu_to_le32 ((epnum << 8) | dev->devnum); | 1034 | stream->buf0 = cpu_to_hc32(ehci, (epnum << 8) | dev->devnum); |
902 | stream->buf1 = cpu_to_le32 (buf1); | 1035 | stream->buf1 = cpu_to_hc32(ehci, buf1); |
903 | stream->buf2 = cpu_to_le32 (multi); | 1036 | stream->buf2 = cpu_to_hc32(ehci, multi); |
904 | 1037 | ||
905 | /* usbfs wants to report the average usecs per frame tied up | 1038 | /* usbfs wants to report the average usecs per frame tied up |
906 | * when transfers on this endpoint are scheduled ... | 1039 | * when transfers on this endpoint are scheduled ... |
@@ -943,7 +1076,7 @@ iso_stream_init ( | |||
943 | bandwidth /= 1 << (interval + 2); | 1076 | bandwidth /= 1 << (interval + 2); |
944 | 1077 | ||
945 | /* stream->splits gets created from raw_mask later */ | 1078 | /* stream->splits gets created from raw_mask later */ |
946 | stream->address = cpu_to_le32 (addr); | 1079 | stream->address = cpu_to_hc32(ehci, addr); |
947 | } | 1080 | } |
948 | stream->bandwidth = bandwidth; | 1081 | stream->bandwidth = bandwidth; |
949 | 1082 | ||
@@ -1077,7 +1210,8 @@ iso_sched_alloc (unsigned packets, gfp_t mem_flags) | |||
1077 | } | 1210 | } |
1078 | 1211 | ||
1079 | static inline void | 1212 | static inline void |
1080 | itd_sched_init ( | 1213 | itd_sched_init( |
1214 | struct ehci_hcd *ehci, | ||
1081 | struct ehci_iso_sched *iso_sched, | 1215 | struct ehci_iso_sched *iso_sched, |
1082 | struct ehci_iso_stream *stream, | 1216 | struct ehci_iso_stream *stream, |
1083 | struct urb *urb | 1217 | struct urb *urb |
@@ -1107,7 +1241,7 @@ itd_sched_init ( | |||
1107 | && !(urb->transfer_flags & URB_NO_INTERRUPT)) | 1241 | && !(urb->transfer_flags & URB_NO_INTERRUPT)) |
1108 | trans |= EHCI_ITD_IOC; | 1242 | trans |= EHCI_ITD_IOC; |
1109 | trans |= length << 16; | 1243 | trans |= length << 16; |
1110 | uframe->transaction = cpu_to_le32 (trans); | 1244 | uframe->transaction = cpu_to_hc32(ehci, trans); |
1111 | 1245 | ||
1112 | /* might need to cross a buffer page within a uframe */ | 1246 | /* might need to cross a buffer page within a uframe */ |
1113 | uframe->bufp = (buf & ~(u64)0x0fff); | 1247 | uframe->bufp = (buf & ~(u64)0x0fff); |
@@ -1149,7 +1283,7 @@ itd_urb_transaction ( | |||
1149 | if (unlikely (sched == NULL)) | 1283 | if (unlikely (sched == NULL)) |
1150 | return -ENOMEM; | 1284 | return -ENOMEM; |
1151 | 1285 | ||
1152 | itd_sched_init (sched, stream, urb); | 1286 | itd_sched_init(ehci, sched, stream, urb); |
1153 | 1287 | ||
1154 | if (urb->interval < 8) | 1288 | if (urb->interval < 8) |
1155 | num_itds = 1 + (sched->span + 7) / 8; | 1289 | num_itds = 1 + (sched->span + 7) / 8; |
@@ -1167,7 +1301,7 @@ itd_urb_transaction ( | |||
1167 | /* prefer previously-allocated itds */ | 1301 | /* prefer previously-allocated itds */ |
1168 | if (likely (!list_empty(&stream->free_list))) { | 1302 | if (likely (!list_empty(&stream->free_list))) { |
1169 | itd = list_entry (stream->free_list.prev, | 1303 | itd = list_entry (stream->free_list.prev, |
1170 | struct ehci_itd, itd_list); | 1304 | struct ehci_itd, itd_list); |
1171 | list_del (&itd->itd_list); | 1305 | list_del (&itd->itd_list); |
1172 | itd_dma = itd->itd_dma; | 1306 | itd_dma = itd->itd_dma; |
1173 | } else | 1307 | } else |
@@ -1294,7 +1428,7 @@ sitd_slot_ok ( | |||
1294 | uframe += period_uframes; | 1428 | uframe += period_uframes; |
1295 | } while (uframe < mod); | 1429 | } while (uframe < mod); |
1296 | 1430 | ||
1297 | stream->splits = cpu_to_le32(stream->raw_mask << (uframe & 7)); | 1431 | stream->splits = cpu_to_hc32(ehci, stream->raw_mask << (uframe & 7)); |
1298 | return 1; | 1432 | return 1; |
1299 | } | 1433 | } |
1300 | 1434 | ||
@@ -1415,12 +1549,13 @@ ready: | |||
1415 | /*-------------------------------------------------------------------------*/ | 1549 | /*-------------------------------------------------------------------------*/ |
1416 | 1550 | ||
1417 | static inline void | 1551 | static inline void |
1418 | itd_init (struct ehci_iso_stream *stream, struct ehci_itd *itd) | 1552 | itd_init(struct ehci_hcd *ehci, struct ehci_iso_stream *stream, |
1553 | struct ehci_itd *itd) | ||
1419 | { | 1554 | { |
1420 | int i; | 1555 | int i; |
1421 | 1556 | ||
1422 | /* it's been recently zeroed */ | 1557 | /* it's been recently zeroed */ |
1423 | itd->hw_next = EHCI_LIST_END; | 1558 | itd->hw_next = EHCI_LIST_END(ehci); |
1424 | itd->hw_bufp [0] = stream->buf0; | 1559 | itd->hw_bufp [0] = stream->buf0; |
1425 | itd->hw_bufp [1] = stream->buf1; | 1560 | itd->hw_bufp [1] = stream->buf1; |
1426 | itd->hw_bufp [2] = stream->buf2; | 1561 | itd->hw_bufp [2] = stream->buf2; |
@@ -1432,7 +1567,8 @@ itd_init (struct ehci_iso_stream *stream, struct ehci_itd *itd) | |||
1432 | } | 1567 | } |
1433 | 1568 | ||
1434 | static inline void | 1569 | static inline void |
1435 | itd_patch ( | 1570 | itd_patch( |
1571 | struct ehci_hcd *ehci, | ||
1436 | struct ehci_itd *itd, | 1572 | struct ehci_itd *itd, |
1437 | struct ehci_iso_sched *iso_sched, | 1573 | struct ehci_iso_sched *iso_sched, |
1438 | unsigned index, | 1574 | unsigned index, |
@@ -1447,17 +1583,18 @@ itd_patch ( | |||
1447 | uframe &= 0x07; | 1583 | uframe &= 0x07; |
1448 | itd->index [uframe] = index; | 1584 | itd->index [uframe] = index; |
1449 | 1585 | ||
1450 | itd->hw_transaction [uframe] = uf->transaction; | 1586 | itd->hw_transaction[uframe] = uf->transaction; |
1451 | itd->hw_transaction [uframe] |= cpu_to_le32 (pg << 12); | 1587 | itd->hw_transaction[uframe] |= cpu_to_hc32(ehci, pg << 12); |
1452 | itd->hw_bufp [pg] |= cpu_to_le32 (uf->bufp & ~(u32)0); | 1588 | itd->hw_bufp[pg] |= cpu_to_hc32(ehci, uf->bufp & ~(u32)0); |
1453 | itd->hw_bufp_hi [pg] |= cpu_to_le32 ((u32)(uf->bufp >> 32)); | 1589 | itd->hw_bufp_hi[pg] |= cpu_to_hc32(ehci, (u32)(uf->bufp >> 32)); |
1454 | 1590 | ||
1455 | /* iso_frame_desc[].offset must be strictly increasing */ | 1591 | /* iso_frame_desc[].offset must be strictly increasing */ |
1456 | if (unlikely (uf->cross)) { | 1592 | if (unlikely (uf->cross)) { |
1457 | u64 bufp = uf->bufp + 4096; | 1593 | u64 bufp = uf->bufp + 4096; |
1594 | |||
1458 | itd->pg = ++pg; | 1595 | itd->pg = ++pg; |
1459 | itd->hw_bufp [pg] |= cpu_to_le32 (bufp & ~(u32)0); | 1596 | itd->hw_bufp[pg] |= cpu_to_hc32(ehci, bufp & ~(u32)0); |
1460 | itd->hw_bufp_hi [pg] |= cpu_to_le32 ((u32)(bufp >> 32)); | 1597 | itd->hw_bufp_hi[pg] |= cpu_to_hc32(ehci, (u32)(bufp >> 32)); |
1461 | } | 1598 | } |
1462 | } | 1599 | } |
1463 | 1600 | ||
@@ -1470,7 +1607,7 @@ itd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_itd *itd) | |||
1470 | ehci->pshadow [frame].itd = itd; | 1607 | ehci->pshadow [frame].itd = itd; |
1471 | itd->frame = frame; | 1608 | itd->frame = frame; |
1472 | wmb (); | 1609 | wmb (); |
1473 | ehci->periodic [frame] = cpu_to_le32 (itd->itd_dma) | Q_TYPE_ITD; | 1610 | ehci->periodic[frame] = cpu_to_hc32(ehci, itd->itd_dma | Q_TYPE_ITD); |
1474 | } | 1611 | } |
1475 | 1612 | ||
1476 | /* fit urb's itds into the selected schedule slot; activate as needed */ | 1613 | /* fit urb's itds into the selected schedule slot; activate as needed */ |
@@ -1515,14 +1652,14 @@ itd_link_urb ( | |||
1515 | list_move_tail (&itd->itd_list, &stream->td_list); | 1652 | list_move_tail (&itd->itd_list, &stream->td_list); |
1516 | itd->stream = iso_stream_get (stream); | 1653 | itd->stream = iso_stream_get (stream); |
1517 | itd->urb = usb_get_urb (urb); | 1654 | itd->urb = usb_get_urb (urb); |
1518 | itd_init (stream, itd); | 1655 | itd_init (ehci, stream, itd); |
1519 | } | 1656 | } |
1520 | 1657 | ||
1521 | uframe = next_uframe & 0x07; | 1658 | uframe = next_uframe & 0x07; |
1522 | frame = next_uframe >> 3; | 1659 | frame = next_uframe >> 3; |
1523 | 1660 | ||
1524 | itd->usecs [uframe] = stream->usecs; | 1661 | itd->usecs [uframe] = stream->usecs; |
1525 | itd_patch (itd, iso_sched, packet, uframe); | 1662 | itd_patch(ehci, itd, iso_sched, packet, uframe); |
1526 | 1663 | ||
1527 | next_uframe += stream->interval; | 1664 | next_uframe += stream->interval; |
1528 | stream->depth += stream->interval; | 1665 | stream->depth += stream->interval; |
@@ -1570,7 +1707,7 @@ itd_complete ( | |||
1570 | urb_index = itd->index[uframe]; | 1707 | urb_index = itd->index[uframe]; |
1571 | desc = &urb->iso_frame_desc [urb_index]; | 1708 | desc = &urb->iso_frame_desc [urb_index]; |
1572 | 1709 | ||
1573 | t = le32_to_cpup (&itd->hw_transaction [uframe]); | 1710 | t = hc32_to_cpup(ehci, &itd->hw_transaction [uframe]); |
1574 | itd->hw_transaction [uframe] = 0; | 1711 | itd->hw_transaction [uframe] = 0; |
1575 | stream->depth -= stream->interval; | 1712 | stream->depth -= stream->interval; |
1576 | 1713 | ||
@@ -1700,7 +1837,8 @@ done: | |||
1700 | */ | 1837 | */ |
1701 | 1838 | ||
1702 | static inline void | 1839 | static inline void |
1703 | sitd_sched_init ( | 1840 | sitd_sched_init( |
1841 | struct ehci_hcd *ehci, | ||
1704 | struct ehci_iso_sched *iso_sched, | 1842 | struct ehci_iso_sched *iso_sched, |
1705 | struct ehci_iso_stream *stream, | 1843 | struct ehci_iso_stream *stream, |
1706 | struct urb *urb | 1844 | struct urb *urb |
@@ -1729,7 +1867,7 @@ sitd_sched_init ( | |||
1729 | && !(urb->transfer_flags & URB_NO_INTERRUPT)) | 1867 | && !(urb->transfer_flags & URB_NO_INTERRUPT)) |
1730 | trans |= SITD_IOC; | 1868 | trans |= SITD_IOC; |
1731 | trans |= length << 16; | 1869 | trans |= length << 16; |
1732 | packet->transaction = cpu_to_le32 (trans); | 1870 | packet->transaction = cpu_to_hc32(ehci, trans); |
1733 | 1871 | ||
1734 | /* might need to cross a buffer page within a td */ | 1872 | /* might need to cross a buffer page within a td */ |
1735 | packet->bufp = buf; | 1873 | packet->bufp = buf; |
@@ -1765,7 +1903,7 @@ sitd_urb_transaction ( | |||
1765 | if (iso_sched == NULL) | 1903 | if (iso_sched == NULL) |
1766 | return -ENOMEM; | 1904 | return -ENOMEM; |
1767 | 1905 | ||
1768 | sitd_sched_init (iso_sched, stream, urb); | 1906 | sitd_sched_init(ehci, iso_sched, stream, urb); |
1769 | 1907 | ||
1770 | /* allocate/init sITDs */ | 1908 | /* allocate/init sITDs */ |
1771 | spin_lock_irqsave (&ehci->lock, flags); | 1909 | spin_lock_irqsave (&ehci->lock, flags); |
@@ -1817,7 +1955,8 @@ sitd_urb_transaction ( | |||
1817 | /*-------------------------------------------------------------------------*/ | 1955 | /*-------------------------------------------------------------------------*/ |
1818 | 1956 | ||
1819 | static inline void | 1957 | static inline void |
1820 | sitd_patch ( | 1958 | sitd_patch( |
1959 | struct ehci_hcd *ehci, | ||
1821 | struct ehci_iso_stream *stream, | 1960 | struct ehci_iso_stream *stream, |
1822 | struct ehci_sitd *sitd, | 1961 | struct ehci_sitd *sitd, |
1823 | struct ehci_iso_sched *iso_sched, | 1962 | struct ehci_iso_sched *iso_sched, |
@@ -1827,20 +1966,20 @@ sitd_patch ( | |||
1827 | struct ehci_iso_packet *uf = &iso_sched->packet [index]; | 1966 | struct ehci_iso_packet *uf = &iso_sched->packet [index]; |
1828 | u64 bufp = uf->bufp; | 1967 | u64 bufp = uf->bufp; |
1829 | 1968 | ||
1830 | sitd->hw_next = EHCI_LIST_END; | 1969 | sitd->hw_next = EHCI_LIST_END(ehci); |
1831 | sitd->hw_fullspeed_ep = stream->address; | 1970 | sitd->hw_fullspeed_ep = stream->address; |
1832 | sitd->hw_uframe = stream->splits; | 1971 | sitd->hw_uframe = stream->splits; |
1833 | sitd->hw_results = uf->transaction; | 1972 | sitd->hw_results = uf->transaction; |
1834 | sitd->hw_backpointer = EHCI_LIST_END; | 1973 | sitd->hw_backpointer = EHCI_LIST_END(ehci); |
1835 | 1974 | ||
1836 | bufp = uf->bufp; | 1975 | bufp = uf->bufp; |
1837 | sitd->hw_buf [0] = cpu_to_le32 (bufp); | 1976 | sitd->hw_buf[0] = cpu_to_hc32(ehci, bufp); |
1838 | sitd->hw_buf_hi [0] = cpu_to_le32 (bufp >> 32); | 1977 | sitd->hw_buf_hi[0] = cpu_to_hc32(ehci, bufp >> 32); |
1839 | 1978 | ||
1840 | sitd->hw_buf [1] = cpu_to_le32 (uf->buf1); | 1979 | sitd->hw_buf[1] = cpu_to_hc32(ehci, uf->buf1); |
1841 | if (uf->cross) | 1980 | if (uf->cross) |
1842 | bufp += 4096; | 1981 | bufp += 4096; |
1843 | sitd->hw_buf_hi [1] = cpu_to_le32 (bufp >> 32); | 1982 | sitd->hw_buf_hi[1] = cpu_to_hc32(ehci, bufp >> 32); |
1844 | sitd->index = index; | 1983 | sitd->index = index; |
1845 | } | 1984 | } |
1846 | 1985 | ||
@@ -1853,7 +1992,7 @@ sitd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_sitd *sitd) | |||
1853 | ehci->pshadow [frame].sitd = sitd; | 1992 | ehci->pshadow [frame].sitd = sitd; |
1854 | sitd->frame = frame; | 1993 | sitd->frame = frame; |
1855 | wmb (); | 1994 | wmb (); |
1856 | ehci->periodic [frame] = cpu_to_le32 (sitd->sitd_dma) | Q_TYPE_SITD; | 1995 | ehci->periodic[frame] = cpu_to_hc32(ehci, sitd->sitd_dma | Q_TYPE_SITD); |
1857 | } | 1996 | } |
1858 | 1997 | ||
1859 | /* fit urb's sitds into the selected schedule slot; activate as needed */ | 1998 | /* fit urb's sitds into the selected schedule slot; activate as needed */ |
@@ -1881,7 +2020,7 @@ sitd_link_urb ( | |||
1881 | urb->dev->devpath, stream->bEndpointAddress & 0x0f, | 2020 | urb->dev->devpath, stream->bEndpointAddress & 0x0f, |
1882 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", | 2021 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", |
1883 | (next_uframe >> 3) % ehci->periodic_size, | 2022 | (next_uframe >> 3) % ehci->periodic_size, |
1884 | stream->interval, le32_to_cpu (stream->splits)); | 2023 | stream->interval, hc32_to_cpu(ehci, stream->splits)); |
1885 | stream->start = jiffies; | 2024 | stream->start = jiffies; |
1886 | } | 2025 | } |
1887 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; | 2026 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; |
@@ -1902,7 +2041,7 @@ sitd_link_urb ( | |||
1902 | sitd->stream = iso_stream_get (stream); | 2041 | sitd->stream = iso_stream_get (stream); |
1903 | sitd->urb = usb_get_urb (urb); | 2042 | sitd->urb = usb_get_urb (urb); |
1904 | 2043 | ||
1905 | sitd_patch (stream, sitd, sched, packet); | 2044 | sitd_patch(ehci, stream, sitd, sched, packet); |
1906 | sitd_link (ehci, (next_uframe >> 3) % ehci->periodic_size, | 2045 | sitd_link (ehci, (next_uframe >> 3) % ehci->periodic_size, |
1907 | sitd); | 2046 | sitd); |
1908 | 2047 | ||
@@ -1940,7 +2079,7 @@ sitd_complete ( | |||
1940 | 2079 | ||
1941 | urb_index = sitd->index; | 2080 | urb_index = sitd->index; |
1942 | desc = &urb->iso_frame_desc [urb_index]; | 2081 | desc = &urb->iso_frame_desc [urb_index]; |
1943 | t = le32_to_cpup (&sitd->hw_results); | 2082 | t = hc32_to_cpup(ehci, &sitd->hw_results); |
1944 | 2083 | ||
1945 | /* report transfer status */ | 2084 | /* report transfer status */ |
1946 | if (t & SITD_ERRS) { | 2085 | if (t & SITD_ERRS) { |
@@ -2095,7 +2234,7 @@ scan_periodic (struct ehci_hcd *ehci) | |||
2095 | 2234 | ||
2096 | for (;;) { | 2235 | for (;;) { |
2097 | union ehci_shadow q, *q_p; | 2236 | union ehci_shadow q, *q_p; |
2098 | __le32 type, *hw_p; | 2237 | __hc32 type, *hw_p; |
2099 | unsigned uframes; | 2238 | unsigned uframes; |
2100 | 2239 | ||
2101 | /* don't scan past the live uframe */ | 2240 | /* don't scan past the live uframe */ |
@@ -2113,7 +2252,7 @@ restart: | |||
2113 | q_p = &ehci->pshadow [frame]; | 2252 | q_p = &ehci->pshadow [frame]; |
2114 | hw_p = &ehci->periodic [frame]; | 2253 | hw_p = &ehci->periodic [frame]; |
2115 | q.ptr = q_p->ptr; | 2254 | q.ptr = q_p->ptr; |
2116 | type = Q_NEXT_TYPE (*hw_p); | 2255 | type = Q_NEXT_TYPE(ehci, *hw_p); |
2117 | modified = 0; | 2256 | modified = 0; |
2118 | 2257 | ||
2119 | while (q.ptr != NULL) { | 2258 | while (q.ptr != NULL) { |
@@ -2122,11 +2261,11 @@ restart: | |||
2122 | int live; | 2261 | int live; |
2123 | 2262 | ||
2124 | live = HC_IS_RUNNING (ehci_to_hcd(ehci)->state); | 2263 | live = HC_IS_RUNNING (ehci_to_hcd(ehci)->state); |
2125 | switch (type) { | 2264 | switch (hc32_to_cpu(ehci, type)) { |
2126 | case Q_TYPE_QH: | 2265 | case Q_TYPE_QH: |
2127 | /* handle any completions */ | 2266 | /* handle any completions */ |
2128 | temp.qh = qh_get (q.qh); | 2267 | temp.qh = qh_get (q.qh); |
2129 | type = Q_NEXT_TYPE (q.qh->hw_next); | 2268 | type = Q_NEXT_TYPE(ehci, q.qh->hw_next); |
2130 | q = q.qh->qh_next; | 2269 | q = q.qh->qh_next; |
2131 | modified = qh_completions (ehci, temp.qh); | 2270 | modified = qh_completions (ehci, temp.qh); |
2132 | if (unlikely (list_empty (&temp.qh->qtd_list))) | 2271 | if (unlikely (list_empty (&temp.qh->qtd_list))) |
@@ -2137,10 +2276,10 @@ restart: | |||
2137 | /* for "save place" FSTNs, look at QH entries | 2276 | /* for "save place" FSTNs, look at QH entries |
2138 | * in the previous frame for completions. | 2277 | * in the previous frame for completions. |
2139 | */ | 2278 | */ |
2140 | if (q.fstn->hw_prev != EHCI_LIST_END) { | 2279 | if (q.fstn->hw_prev != EHCI_LIST_END(ehci)) { |
2141 | dbg ("ignoring completions from FSTNs"); | 2280 | dbg ("ignoring completions from FSTNs"); |
2142 | } | 2281 | } |
2143 | type = Q_NEXT_TYPE (q.fstn->hw_next); | 2282 | type = Q_NEXT_TYPE(ehci, q.fstn->hw_next); |
2144 | q = q.fstn->fstn_next; | 2283 | q = q.fstn->fstn_next; |
2145 | break; | 2284 | break; |
2146 | case Q_TYPE_ITD: | 2285 | case Q_TYPE_ITD: |
@@ -2148,11 +2287,12 @@ restart: | |||
2148 | rmb (); | 2287 | rmb (); |
2149 | for (uf = live ? uframes : 8; uf < 8; uf++) { | 2288 | for (uf = live ? uframes : 8; uf < 8; uf++) { |
2150 | if (0 == (q.itd->hw_transaction [uf] | 2289 | if (0 == (q.itd->hw_transaction [uf] |
2151 | & ITD_ACTIVE)) | 2290 | & ITD_ACTIVE(ehci))) |
2152 | continue; | 2291 | continue; |
2153 | q_p = &q.itd->itd_next; | 2292 | q_p = &q.itd->itd_next; |
2154 | hw_p = &q.itd->hw_next; | 2293 | hw_p = &q.itd->hw_next; |
2155 | type = Q_NEXT_TYPE (q.itd->hw_next); | 2294 | type = Q_NEXT_TYPE(ehci, |
2295 | q.itd->hw_next); | ||
2156 | q = *q_p; | 2296 | q = *q_p; |
2157 | break; | 2297 | break; |
2158 | } | 2298 | } |
@@ -2164,23 +2304,24 @@ restart: | |||
2164 | */ | 2304 | */ |
2165 | *q_p = q.itd->itd_next; | 2305 | *q_p = q.itd->itd_next; |
2166 | *hw_p = q.itd->hw_next; | 2306 | *hw_p = q.itd->hw_next; |
2167 | type = Q_NEXT_TYPE (q.itd->hw_next); | 2307 | type = Q_NEXT_TYPE(ehci, q.itd->hw_next); |
2168 | wmb(); | 2308 | wmb(); |
2169 | modified = itd_complete (ehci, q.itd); | 2309 | modified = itd_complete (ehci, q.itd); |
2170 | q = *q_p; | 2310 | q = *q_p; |
2171 | break; | 2311 | break; |
2172 | case Q_TYPE_SITD: | 2312 | case Q_TYPE_SITD: |
2173 | if ((q.sitd->hw_results & SITD_ACTIVE) | 2313 | if ((q.sitd->hw_results & SITD_ACTIVE(ehci)) |
2174 | && live) { | 2314 | && live) { |
2175 | q_p = &q.sitd->sitd_next; | 2315 | q_p = &q.sitd->sitd_next; |
2176 | hw_p = &q.sitd->hw_next; | 2316 | hw_p = &q.sitd->hw_next; |
2177 | type = Q_NEXT_TYPE (q.sitd->hw_next); | 2317 | type = Q_NEXT_TYPE(ehci, |
2318 | q.sitd->hw_next); | ||
2178 | q = *q_p; | 2319 | q = *q_p; |
2179 | break; | 2320 | break; |
2180 | } | 2321 | } |
2181 | *q_p = q.sitd->sitd_next; | 2322 | *q_p = q.sitd->sitd_next; |
2182 | *hw_p = q.sitd->hw_next; | 2323 | *hw_p = q.sitd->hw_next; |
2183 | type = Q_NEXT_TYPE (q.sitd->hw_next); | 2324 | type = Q_NEXT_TYPE(ehci, q.sitd->hw_next); |
2184 | wmb(); | 2325 | wmb(); |
2185 | modified = sitd_complete (ehci, q.sitd); | 2326 | modified = sitd_complete (ehci, q.sitd); |
2186 | q = *q_p; | 2327 | q = *q_p; |
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index 46fa57a520d0..2c68a04230c1 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h | |||
@@ -21,6 +21,22 @@ | |||
21 | 21 | ||
22 | /* definitions used for the EHCI driver */ | 22 | /* definitions used for the EHCI driver */ |
23 | 23 | ||
24 | /* | ||
25 | * __hc32 and __hc16 are "Host Controller" types, they may be equivalent to | ||
26 | * __leXX (normally) or __beXX (given EHCI_BIG_ENDIAN_DESC), depending on | ||
27 | * the host controller implementation. | ||
28 | * | ||
29 | * To facilitate the strongest possible byte-order checking from "sparse" | ||
30 | * and so on, we use __leXX unless that's not practical. | ||
31 | */ | ||
32 | #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC | ||
33 | typedef __u32 __bitwise __hc32; | ||
34 | typedef __u16 __bitwise __hc16; | ||
35 | #else | ||
36 | #define __hc32 __le32 | ||
37 | #define __hc16 __le16 | ||
38 | #endif | ||
39 | |||
24 | /* statistics can be kept for for tuning/monitoring */ | 40 | /* statistics can be kept for for tuning/monitoring */ |
25 | struct ehci_stats { | 41 | struct ehci_stats { |
26 | /* irq usage */ | 42 | /* irq usage */ |
@@ -55,6 +71,12 @@ struct ehci_hcd { /* one per controller */ | |||
55 | __u32 hcs_params; /* cached register copy */ | 71 | __u32 hcs_params; /* cached register copy */ |
56 | spinlock_t lock; | 72 | spinlock_t lock; |
57 | 73 | ||
74 | #ifdef CONFIG_CPU_FREQ | ||
75 | struct notifier_block cpufreq_transition; | ||
76 | int cpufreq_changing; | ||
77 | struct list_head split_intr_qhs; | ||
78 | #endif | ||
79 | |||
58 | /* async schedule support */ | 80 | /* async schedule support */ |
59 | struct ehci_qh *async; | 81 | struct ehci_qh *async; |
60 | struct ehci_qh *reclaim; | 82 | struct ehci_qh *reclaim; |
@@ -64,7 +86,7 @@ struct ehci_hcd { /* one per controller */ | |||
64 | /* periodic schedule support */ | 86 | /* periodic schedule support */ |
65 | #define DEFAULT_I_TDPS 1024 /* some HCs can do less */ | 87 | #define DEFAULT_I_TDPS 1024 /* some HCs can do less */ |
66 | unsigned periodic_size; | 88 | unsigned periodic_size; |
67 | __le32 *periodic; /* hw periodic table */ | 89 | __hc32 *periodic; /* hw periodic table */ |
68 | dma_addr_t periodic_dma; | 90 | dma_addr_t periodic_dma; |
69 | unsigned i_thresh; /* uframes HC might cache */ | 91 | unsigned i_thresh; /* uframes HC might cache */ |
70 | 92 | ||
@@ -74,11 +96,14 @@ struct ehci_hcd { /* one per controller */ | |||
74 | 96 | ||
75 | /* per root hub port */ | 97 | /* per root hub port */ |
76 | unsigned long reset_done [EHCI_MAX_ROOT_PORTS]; | 98 | unsigned long reset_done [EHCI_MAX_ROOT_PORTS]; |
99 | |||
77 | /* bit vectors (one bit per port) */ | 100 | /* bit vectors (one bit per port) */ |
78 | unsigned long bus_suspended; /* which ports were | 101 | unsigned long bus_suspended; /* which ports were |
79 | already suspended at the start of a bus suspend */ | 102 | already suspended at the start of a bus suspend */ |
80 | unsigned long companion_ports; /* which ports are | 103 | unsigned long companion_ports; /* which ports are |
81 | dedicated to the companion controller */ | 104 | dedicated to the companion controller */ |
105 | unsigned long owned_ports; /* which ports are | ||
106 | owned by the companion during a bus suspend */ | ||
82 | 107 | ||
83 | /* per-HC memory pools (could be per-bus, but ...) */ | 108 | /* per-HC memory pools (could be per-bus, but ...) */ |
84 | struct dma_pool *qh_pool; /* qh per active urb */ | 109 | struct dma_pool *qh_pool; /* qh per active urb */ |
@@ -97,6 +122,7 @@ struct ehci_hcd { /* one per controller */ | |||
97 | unsigned no_selective_suspend:1; | 122 | unsigned no_selective_suspend:1; |
98 | unsigned has_fsl_port_bug:1; /* FreeScale */ | 123 | unsigned has_fsl_port_bug:1; /* FreeScale */ |
99 | unsigned big_endian_mmio:1; | 124 | unsigned big_endian_mmio:1; |
125 | unsigned big_endian_desc:1; | ||
100 | 126 | ||
101 | u8 sbrn; /* packed release number */ | 127 | u8 sbrn; /* packed release number */ |
102 | 128 | ||
@@ -276,6 +302,12 @@ struct ehci_regs { | |||
276 | #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) | 302 | #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) |
277 | } __attribute__ ((packed)); | 303 | } __attribute__ ((packed)); |
278 | 304 | ||
305 | #define USBMODE 0x68 /* USB Device mode */ | ||
306 | #define USBMODE_SDIS (1<<3) /* Stream disable */ | ||
307 | #define USBMODE_BE (1<<2) /* BE/LE endianness select */ | ||
308 | #define USBMODE_CM_HC (3<<0) /* host controller mode */ | ||
309 | #define USBMODE_CM_IDLE (0<<0) /* idle state */ | ||
310 | |||
279 | /* Appendix C, Debug port ... intended for use with special "debug devices" | 311 | /* Appendix C, Debug port ... intended for use with special "debug devices" |
280 | * that can help if there's no serial console. (nonstandard enumeration.) | 312 | * that can help if there's no serial console. (nonstandard enumeration.) |
281 | */ | 313 | */ |
@@ -303,7 +335,7 @@ struct ehci_dbg_port { | |||
303 | 335 | ||
304 | /*-------------------------------------------------------------------------*/ | 336 | /*-------------------------------------------------------------------------*/ |
305 | 337 | ||
306 | #define QTD_NEXT(dma) cpu_to_le32((u32)dma) | 338 | #define QTD_NEXT(ehci, dma) cpu_to_hc32(ehci, (u32)dma) |
307 | 339 | ||
308 | /* | 340 | /* |
309 | * EHCI Specification 0.95 Section 3.5 | 341 | * EHCI Specification 0.95 Section 3.5 |
@@ -315,9 +347,9 @@ struct ehci_dbg_port { | |||
315 | */ | 347 | */ |
316 | struct ehci_qtd { | 348 | struct ehci_qtd { |
317 | /* first part defined by EHCI spec */ | 349 | /* first part defined by EHCI spec */ |
318 | __le32 hw_next; /* see EHCI 3.5.1 */ | 350 | __hc32 hw_next; /* see EHCI 3.5.1 */ |
319 | __le32 hw_alt_next; /* see EHCI 3.5.2 */ | 351 | __hc32 hw_alt_next; /* see EHCI 3.5.2 */ |
320 | __le32 hw_token; /* see EHCI 3.5.3 */ | 352 | __hc32 hw_token; /* see EHCI 3.5.3 */ |
321 | #define QTD_TOGGLE (1 << 31) /* data toggle */ | 353 | #define QTD_TOGGLE (1 << 31) /* data toggle */ |
322 | #define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff) | 354 | #define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff) |
323 | #define QTD_IOC (1 << 15) /* interrupt on complete */ | 355 | #define QTD_IOC (1 << 15) /* interrupt on complete */ |
@@ -331,8 +363,13 @@ struct ehci_qtd { | |||
331 | #define QTD_STS_MMF (1 << 2) /* incomplete split transaction */ | 363 | #define QTD_STS_MMF (1 << 2) /* incomplete split transaction */ |
332 | #define QTD_STS_STS (1 << 1) /* split transaction state */ | 364 | #define QTD_STS_STS (1 << 1) /* split transaction state */ |
333 | #define QTD_STS_PING (1 << 0) /* issue PING? */ | 365 | #define QTD_STS_PING (1 << 0) /* issue PING? */ |
334 | __le32 hw_buf [5]; /* see EHCI 3.5.4 */ | 366 | |
335 | __le32 hw_buf_hi [5]; /* Appendix B */ | 367 | #define ACTIVE_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_ACTIVE) |
368 | #define HALT_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_HALT) | ||
369 | #define STATUS_BIT(ehci) cpu_to_hc32(ehci, QTD_STS_STS) | ||
370 | |||
371 | __hc32 hw_buf [5]; /* see EHCI 3.5.4 */ | ||
372 | __hc32 hw_buf_hi [5]; /* Appendix B */ | ||
336 | 373 | ||
337 | /* the rest is HCD-private */ | 374 | /* the rest is HCD-private */ |
338 | dma_addr_t qtd_dma; /* qtd address */ | 375 | dma_addr_t qtd_dma; /* qtd address */ |
@@ -342,26 +379,33 @@ struct ehci_qtd { | |||
342 | } __attribute__ ((aligned (32))); | 379 | } __attribute__ ((aligned (32))); |
343 | 380 | ||
344 | /* mask NakCnt+T in qh->hw_alt_next */ | 381 | /* mask NakCnt+T in qh->hw_alt_next */ |
345 | #define QTD_MASK __constant_cpu_to_le32 (~0x1f) | 382 | #define QTD_MASK(ehci) cpu_to_hc32 (ehci, ~0x1f) |
346 | 383 | ||
347 | #define IS_SHORT_READ(token) (QTD_LENGTH (token) != 0 && QTD_PID (token) == 1) | 384 | #define IS_SHORT_READ(token) (QTD_LENGTH (token) != 0 && QTD_PID (token) == 1) |
348 | 385 | ||
349 | /*-------------------------------------------------------------------------*/ | 386 | /*-------------------------------------------------------------------------*/ |
350 | 387 | ||
351 | /* type tag from {qh,itd,sitd,fstn}->hw_next */ | 388 | /* type tag from {qh,itd,sitd,fstn}->hw_next */ |
352 | #define Q_NEXT_TYPE(dma) ((dma) & __constant_cpu_to_le32 (3 << 1)) | 389 | #define Q_NEXT_TYPE(ehci,dma) ((dma) & cpu_to_hc32(ehci, 3 << 1)) |
353 | 390 | ||
391 | /* | ||
392 | * Now the following defines are not converted using the | ||
393 | * __constant_cpu_to_le32() macro anymore, since we have to support | ||
394 | * "dynamic" switching between be and le support, so that the driver | ||
395 | * can be used on one system with SoC EHCI controller using big-endian | ||
396 | * descriptors as well as a normal little-endian PCI EHCI controller. | ||
397 | */ | ||
354 | /* values for that type tag */ | 398 | /* values for that type tag */ |
355 | #define Q_TYPE_ITD __constant_cpu_to_le32 (0 << 1) | 399 | #define Q_TYPE_ITD (0 << 1) |
356 | #define Q_TYPE_QH __constant_cpu_to_le32 (1 << 1) | 400 | #define Q_TYPE_QH (1 << 1) |
357 | #define Q_TYPE_SITD __constant_cpu_to_le32 (2 << 1) | 401 | #define Q_TYPE_SITD (2 << 1) |
358 | #define Q_TYPE_FSTN __constant_cpu_to_le32 (3 << 1) | 402 | #define Q_TYPE_FSTN (3 << 1) |
359 | 403 | ||
360 | /* next async queue entry, or pointer to interrupt/periodic QH */ | 404 | /* next async queue entry, or pointer to interrupt/periodic QH */ |
361 | #define QH_NEXT(dma) (cpu_to_le32(((u32)dma)&~0x01f)|Q_TYPE_QH) | 405 | #define QH_NEXT(ehci,dma) (cpu_to_hc32(ehci, (((u32)dma)&~0x01f)|Q_TYPE_QH)) |
362 | 406 | ||
363 | /* for periodic/async schedules and qtd lists, mark end of list */ | 407 | /* for periodic/async schedules and qtd lists, mark end of list */ |
364 | #define EHCI_LIST_END __constant_cpu_to_le32(1) /* "null pointer" to hw */ | 408 | #define EHCI_LIST_END(ehci) cpu_to_hc32(ehci, 1) /* "null pointer" to hw */ |
365 | 409 | ||
366 | /* | 410 | /* |
367 | * Entries in periodic shadow table are pointers to one of four kinds | 411 | * Entries in periodic shadow table are pointers to one of four kinds |
@@ -376,7 +420,7 @@ union ehci_shadow { | |||
376 | struct ehci_itd *itd; /* Q_TYPE_ITD */ | 420 | struct ehci_itd *itd; /* Q_TYPE_ITD */ |
377 | struct ehci_sitd *sitd; /* Q_TYPE_SITD */ | 421 | struct ehci_sitd *sitd; /* Q_TYPE_SITD */ |
378 | struct ehci_fstn *fstn; /* Q_TYPE_FSTN */ | 422 | struct ehci_fstn *fstn; /* Q_TYPE_FSTN */ |
379 | __le32 *hw_next; /* (all types) */ | 423 | __hc32 *hw_next; /* (all types) */ |
380 | void *ptr; | 424 | void *ptr; |
381 | }; | 425 | }; |
382 | 426 | ||
@@ -392,23 +436,27 @@ union ehci_shadow { | |||
392 | 436 | ||
393 | struct ehci_qh { | 437 | struct ehci_qh { |
394 | /* first part defined by EHCI spec */ | 438 | /* first part defined by EHCI spec */ |
395 | __le32 hw_next; /* see EHCI 3.6.1 */ | 439 | __hc32 hw_next; /* see EHCI 3.6.1 */ |
396 | __le32 hw_info1; /* see EHCI 3.6.2 */ | 440 | __hc32 hw_info1; /* see EHCI 3.6.2 */ |
397 | #define QH_HEAD 0x00008000 | 441 | #define QH_HEAD 0x00008000 |
398 | __le32 hw_info2; /* see EHCI 3.6.2 */ | 442 | #define QH_INACTIVATE 0x00000080 |
443 | |||
444 | #define INACTIVATE_BIT(ehci) cpu_to_hc32(ehci, QH_INACTIVATE) | ||
445 | |||
446 | __hc32 hw_info2; /* see EHCI 3.6.2 */ | ||
399 | #define QH_SMASK 0x000000ff | 447 | #define QH_SMASK 0x000000ff |
400 | #define QH_CMASK 0x0000ff00 | 448 | #define QH_CMASK 0x0000ff00 |
401 | #define QH_HUBADDR 0x007f0000 | 449 | #define QH_HUBADDR 0x007f0000 |
402 | #define QH_HUBPORT 0x3f800000 | 450 | #define QH_HUBPORT 0x3f800000 |
403 | #define QH_MULT 0xc0000000 | 451 | #define QH_MULT 0xc0000000 |
404 | __le32 hw_current; /* qtd list - see EHCI 3.6.4 */ | 452 | __hc32 hw_current; /* qtd list - see EHCI 3.6.4 */ |
405 | 453 | ||
406 | /* qtd overlay (hardware parts of a struct ehci_qtd) */ | 454 | /* qtd overlay (hardware parts of a struct ehci_qtd) */ |
407 | __le32 hw_qtd_next; | 455 | __hc32 hw_qtd_next; |
408 | __le32 hw_alt_next; | 456 | __hc32 hw_alt_next; |
409 | __le32 hw_token; | 457 | __hc32 hw_token; |
410 | __le32 hw_buf [5]; | 458 | __hc32 hw_buf [5]; |
411 | __le32 hw_buf_hi [5]; | 459 | __hc32 hw_buf_hi [5]; |
412 | 460 | ||
413 | /* the rest is HCD-private */ | 461 | /* the rest is HCD-private */ |
414 | dma_addr_t qh_dma; /* address of qh */ | 462 | dma_addr_t qh_dma; /* address of qh */ |
@@ -418,7 +466,14 @@ struct ehci_qh { | |||
418 | struct ehci_qh *reclaim; /* next to reclaim */ | 466 | struct ehci_qh *reclaim; /* next to reclaim */ |
419 | 467 | ||
420 | struct ehci_hcd *ehci; | 468 | struct ehci_hcd *ehci; |
421 | struct kref kref; | 469 | |
470 | /* | ||
471 | * Do NOT use atomic operations for QH refcounting. On some CPUs | ||
472 | * (PPC7448 for example), atomic operations cannot be performed on | ||
473 | * memory that is cache-inhibited (i.e. being used for DMA). | ||
474 | * Spinlocks are used to protect all QH fields. | ||
475 | */ | ||
476 | u32 refcount; | ||
422 | unsigned stamp; | 477 | unsigned stamp; |
423 | 478 | ||
424 | u8 qh_state; | 479 | u8 qh_state; |
@@ -437,6 +492,10 @@ struct ehci_qh { | |||
437 | unsigned short start; /* where polling starts */ | 492 | unsigned short start; /* where polling starts */ |
438 | #define NO_FRAME ((unsigned short)~0) /* pick new start */ | 493 | #define NO_FRAME ((unsigned short)~0) /* pick new start */ |
439 | struct usb_device *dev; /* access to TT */ | 494 | struct usb_device *dev; /* access to TT */ |
495 | #ifdef CONFIG_CPU_FREQ | ||
496 | struct list_head split_intr_qhs; /* list of split qhs */ | ||
497 | __le32 was_active; /* active bit before "i" set */ | ||
498 | #endif | ||
440 | } __attribute__ ((aligned (32))); | 499 | } __attribute__ ((aligned (32))); |
441 | 500 | ||
442 | /*-------------------------------------------------------------------------*/ | 501 | /*-------------------------------------------------------------------------*/ |
@@ -445,7 +504,7 @@ struct ehci_qh { | |||
445 | struct ehci_iso_packet { | 504 | struct ehci_iso_packet { |
446 | /* These will be copied to iTD when scheduling */ | 505 | /* These will be copied to iTD when scheduling */ |
447 | u64 bufp; /* itd->hw_bufp{,_hi}[pg] |= */ | 506 | u64 bufp; /* itd->hw_bufp{,_hi}[pg] |= */ |
448 | __le32 transaction; /* itd->hw_transaction[i] |= */ | 507 | __hc32 transaction; /* itd->hw_transaction[i] |= */ |
449 | u8 cross; /* buf crosses pages */ | 508 | u8 cross; /* buf crosses pages */ |
450 | /* for full speed OUT splits */ | 509 | /* for full speed OUT splits */ |
451 | u32 buf1; | 510 | u32 buf1; |
@@ -467,8 +526,8 @@ struct ehci_iso_sched { | |||
467 | */ | 526 | */ |
468 | struct ehci_iso_stream { | 527 | struct ehci_iso_stream { |
469 | /* first two fields match QH, but info1 == 0 */ | 528 | /* first two fields match QH, but info1 == 0 */ |
470 | __le32 hw_next; | 529 | __hc32 hw_next; |
471 | __le32 hw_info1; | 530 | __hc32 hw_info1; |
472 | 531 | ||
473 | u32 refcount; | 532 | u32 refcount; |
474 | u8 bEndpointAddress; | 533 | u8 bEndpointAddress; |
@@ -483,7 +542,7 @@ struct ehci_iso_stream { | |||
483 | unsigned long start; /* jiffies */ | 542 | unsigned long start; /* jiffies */ |
484 | unsigned long rescheduled; | 543 | unsigned long rescheduled; |
485 | int next_uframe; | 544 | int next_uframe; |
486 | __le32 splits; | 545 | __hc32 splits; |
487 | 546 | ||
488 | /* the rest is derived from the endpoint descriptor, | 547 | /* the rest is derived from the endpoint descriptor, |
489 | * trusting urb->interval == f(epdesc->bInterval) and | 548 | * trusting urb->interval == f(epdesc->bInterval) and |
@@ -497,12 +556,12 @@ struct ehci_iso_stream { | |||
497 | unsigned bandwidth; | 556 | unsigned bandwidth; |
498 | 557 | ||
499 | /* This is used to initialize iTD's hw_bufp fields */ | 558 | /* This is used to initialize iTD's hw_bufp fields */ |
500 | __le32 buf0; | 559 | __hc32 buf0; |
501 | __le32 buf1; | 560 | __hc32 buf1; |
502 | __le32 buf2; | 561 | __hc32 buf2; |
503 | 562 | ||
504 | /* this is used to initialize sITD's tt info */ | 563 | /* this is used to initialize sITD's tt info */ |
505 | __le32 address; | 564 | __hc32 address; |
506 | }; | 565 | }; |
507 | 566 | ||
508 | /*-------------------------------------------------------------------------*/ | 567 | /*-------------------------------------------------------------------------*/ |
@@ -515,8 +574,8 @@ struct ehci_iso_stream { | |||
515 | */ | 574 | */ |
516 | struct ehci_itd { | 575 | struct ehci_itd { |
517 | /* first part defined by EHCI spec */ | 576 | /* first part defined by EHCI spec */ |
518 | __le32 hw_next; /* see EHCI 3.3.1 */ | 577 | __hc32 hw_next; /* see EHCI 3.3.1 */ |
519 | __le32 hw_transaction [8]; /* see EHCI 3.3.2 */ | 578 | __hc32 hw_transaction [8]; /* see EHCI 3.3.2 */ |
520 | #define EHCI_ISOC_ACTIVE (1<<31) /* activate transfer this slot */ | 579 | #define EHCI_ISOC_ACTIVE (1<<31) /* activate transfer this slot */ |
521 | #define EHCI_ISOC_BUF_ERR (1<<30) /* Data buffer error */ | 580 | #define EHCI_ISOC_BUF_ERR (1<<30) /* Data buffer error */ |
522 | #define EHCI_ISOC_BABBLE (1<<29) /* babble detected */ | 581 | #define EHCI_ISOC_BABBLE (1<<29) /* babble detected */ |
@@ -524,10 +583,10 @@ struct ehci_itd { | |||
524 | #define EHCI_ITD_LENGTH(tok) (((tok)>>16) & 0x0fff) | 583 | #define EHCI_ITD_LENGTH(tok) (((tok)>>16) & 0x0fff) |
525 | #define EHCI_ITD_IOC (1 << 15) /* interrupt on complete */ | 584 | #define EHCI_ITD_IOC (1 << 15) /* interrupt on complete */ |
526 | 585 | ||
527 | #define ITD_ACTIVE __constant_cpu_to_le32(EHCI_ISOC_ACTIVE) | 586 | #define ITD_ACTIVE(ehci) cpu_to_hc32(ehci, EHCI_ISOC_ACTIVE) |
528 | 587 | ||
529 | __le32 hw_bufp [7]; /* see EHCI 3.3.3 */ | 588 | __hc32 hw_bufp [7]; /* see EHCI 3.3.3 */ |
530 | __le32 hw_bufp_hi [7]; /* Appendix B */ | 589 | __hc32 hw_bufp_hi [7]; /* Appendix B */ |
531 | 590 | ||
532 | /* the rest is HCD-private */ | 591 | /* the rest is HCD-private */ |
533 | dma_addr_t itd_dma; /* for this itd */ | 592 | dma_addr_t itd_dma; /* for this itd */ |
@@ -554,11 +613,11 @@ struct ehci_itd { | |||
554 | */ | 613 | */ |
555 | struct ehci_sitd { | 614 | struct ehci_sitd { |
556 | /* first part defined by EHCI spec */ | 615 | /* first part defined by EHCI spec */ |
557 | __le32 hw_next; | 616 | __hc32 hw_next; |
558 | /* uses bit field macros above - see EHCI 0.95 Table 3-8 */ | 617 | /* uses bit field macros above - see EHCI 0.95 Table 3-8 */ |
559 | __le32 hw_fullspeed_ep; /* EHCI table 3-9 */ | 618 | __hc32 hw_fullspeed_ep; /* EHCI table 3-9 */ |
560 | __le32 hw_uframe; /* EHCI table 3-10 */ | 619 | __hc32 hw_uframe; /* EHCI table 3-10 */ |
561 | __le32 hw_results; /* EHCI table 3-11 */ | 620 | __hc32 hw_results; /* EHCI table 3-11 */ |
562 | #define SITD_IOC (1 << 31) /* interrupt on completion */ | 621 | #define SITD_IOC (1 << 31) /* interrupt on completion */ |
563 | #define SITD_PAGE (1 << 30) /* buffer 0/1 */ | 622 | #define SITD_PAGE (1 << 30) /* buffer 0/1 */ |
564 | #define SITD_LENGTH(x) (0x3ff & ((x)>>16)) | 623 | #define SITD_LENGTH(x) (0x3ff & ((x)>>16)) |
@@ -570,11 +629,11 @@ struct ehci_sitd { | |||
570 | #define SITD_STS_MMF (1 << 2) /* incomplete split transaction */ | 629 | #define SITD_STS_MMF (1 << 2) /* incomplete split transaction */ |
571 | #define SITD_STS_STS (1 << 1) /* split transaction state */ | 630 | #define SITD_STS_STS (1 << 1) /* split transaction state */ |
572 | 631 | ||
573 | #define SITD_ACTIVE __constant_cpu_to_le32(SITD_STS_ACTIVE) | 632 | #define SITD_ACTIVE(ehci) cpu_to_hc32(ehci, SITD_STS_ACTIVE) |
574 | 633 | ||
575 | __le32 hw_buf [2]; /* EHCI table 3-12 */ | 634 | __hc32 hw_buf [2]; /* EHCI table 3-12 */ |
576 | __le32 hw_backpointer; /* EHCI table 3-13 */ | 635 | __hc32 hw_backpointer; /* EHCI table 3-13 */ |
577 | __le32 hw_buf_hi [2]; /* Appendix B */ | 636 | __hc32 hw_buf_hi [2]; /* Appendix B */ |
578 | 637 | ||
579 | /* the rest is HCD-private */ | 638 | /* the rest is HCD-private */ |
580 | dma_addr_t sitd_dma; | 639 | dma_addr_t sitd_dma; |
@@ -599,8 +658,8 @@ struct ehci_sitd { | |||
599 | * it hits a "restore" FSTN; then it returns to finish other uframe 0/1 work. | 658 | * it hits a "restore" FSTN; then it returns to finish other uframe 0/1 work. |
600 | */ | 659 | */ |
601 | struct ehci_fstn { | 660 | struct ehci_fstn { |
602 | __le32 hw_next; /* any periodic q entry */ | 661 | __hc32 hw_next; /* any periodic q entry */ |
603 | __le32 hw_prev; /* qh or EHCI_LIST_END */ | 662 | __hc32 hw_prev; /* qh or EHCI_LIST_END */ |
604 | 663 | ||
605 | /* the rest is HCD-private */ | 664 | /* the rest is HCD-private */ |
606 | dma_addr_t fstn_dma; | 665 | dma_addr_t fstn_dma; |
@@ -672,8 +731,21 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc) | |||
672 | #define ehci_big_endian_mmio(e) 0 | 731 | #define ehci_big_endian_mmio(e) 0 |
673 | #endif | 732 | #endif |
674 | 733 | ||
675 | static inline unsigned int ehci_readl (const struct ehci_hcd *ehci, | 734 | /* |
676 | __u32 __iomem * regs) | 735 | * Big-endian read/write functions are arch-specific. |
736 | * Other arches can be added if/when they're needed. | ||
737 | * | ||
738 | * REVISIT: arch/powerpc now has readl/writel_be, so the | ||
739 | * definition below can die once the 4xx support is | ||
740 | * finally ported over. | ||
741 | */ | ||
742 | #if defined(CONFIG_PPC) | ||
743 | #define readl_be(addr) in_be32((__force unsigned *)addr) | ||
744 | #define writel_be(val, addr) out_be32((__force unsigned *)addr, val) | ||
745 | #endif | ||
746 | |||
747 | static inline unsigned int ehci_readl(const struct ehci_hcd *ehci, | ||
748 | __u32 __iomem * regs) | ||
677 | { | 749 | { |
678 | #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO | 750 | #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO |
679 | return ehci_big_endian_mmio(ehci) ? | 751 | return ehci_big_endian_mmio(ehci) ? |
@@ -684,8 +756,8 @@ static inline unsigned int ehci_readl (const struct ehci_hcd *ehci, | |||
684 | #endif | 756 | #endif |
685 | } | 757 | } |
686 | 758 | ||
687 | static inline void ehci_writel (const struct ehci_hcd *ehci, | 759 | static inline void ehci_writel(const struct ehci_hcd *ehci, |
688 | const unsigned int val, __u32 __iomem *regs) | 760 | const unsigned int val, __u32 __iomem *regs) |
689 | { | 761 | { |
690 | #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO | 762 | #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO |
691 | ehci_big_endian_mmio(ehci) ? | 763 | ehci_big_endian_mmio(ehci) ? |
@@ -698,6 +770,62 @@ static inline void ehci_writel (const struct ehci_hcd *ehci, | |||
698 | 770 | ||
699 | /*-------------------------------------------------------------------------*/ | 771 | /*-------------------------------------------------------------------------*/ |
700 | 772 | ||
773 | /* | ||
774 | * The AMCC 440EPx not only implements its EHCI registers in big-endian | ||
775 | * format, but also its DMA data structures (descriptors). | ||
776 | * | ||
777 | * EHCI controllers accessed through PCI work normally (little-endian | ||
778 | * everywhere), so we won't bother supporting a BE-only mode for now. | ||
779 | */ | ||
780 | #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC | ||
781 | #define ehci_big_endian_desc(e) ((e)->big_endian_desc) | ||
782 | |||
783 | /* cpu to ehci */ | ||
784 | static inline __hc32 cpu_to_hc32 (const struct ehci_hcd *ehci, const u32 x) | ||
785 | { | ||
786 | return ehci_big_endian_desc(ehci) | ||
787 | ? (__force __hc32)cpu_to_be32(x) | ||
788 | : (__force __hc32)cpu_to_le32(x); | ||
789 | } | ||
790 | |||
791 | /* ehci to cpu */ | ||
792 | static inline u32 hc32_to_cpu (const struct ehci_hcd *ehci, const __hc32 x) | ||
793 | { | ||
794 | return ehci_big_endian_desc(ehci) | ||
795 | ? be32_to_cpu((__force __be32)x) | ||
796 | : le32_to_cpu((__force __le32)x); | ||
797 | } | ||
798 | |||
799 | static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x) | ||
800 | { | ||
801 | return ehci_big_endian_desc(ehci) | ||
802 | ? be32_to_cpup((__force __be32 *)x) | ||
803 | : le32_to_cpup((__force __le32 *)x); | ||
804 | } | ||
805 | |||
806 | #else | ||
807 | |||
808 | /* cpu to ehci */ | ||
809 | static inline __hc32 cpu_to_hc32 (const struct ehci_hcd *ehci, const u32 x) | ||
810 | { | ||
811 | return cpu_to_le32(x); | ||
812 | } | ||
813 | |||
814 | /* ehci to cpu */ | ||
815 | static inline u32 hc32_to_cpu (const struct ehci_hcd *ehci, const __hc32 x) | ||
816 | { | ||
817 | return le32_to_cpu(x); | ||
818 | } | ||
819 | |||
820 | static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x) | ||
821 | { | ||
822 | return le32_to_cpup(x); | ||
823 | } | ||
824 | |||
825 | #endif | ||
826 | |||
827 | /*-------------------------------------------------------------------------*/ | ||
828 | |||
701 | #ifndef DEBUG | 829 | #ifndef DEBUG |
702 | #define STUB_DEBUG_FILES | 830 | #define STUB_DEBUG_FILES |
703 | #endif /* DEBUG */ | 831 | #endif /* DEBUG */ |
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c index 273d5ddb72be..6f9e43e9a6ca 100644 --- a/drivers/usb/host/ohci-dbg.c +++ b/drivers/usb/host/ohci-dbg.c | |||
@@ -23,7 +23,7 @@ | |||
23 | /* debug| print the main components of an URB | 23 | /* debug| print the main components of an URB |
24 | * small: 0) header + data packets 1) just header | 24 | * small: 0) header + data packets 1) just header |
25 | */ | 25 | */ |
26 | static void __attribute__((unused)) | 26 | static void __maybe_unused |
27 | urb_print (struct urb * urb, char * str, int small) | 27 | urb_print (struct urb * urb, char * str, int small) |
28 | { | 28 | { |
29 | unsigned int pipe= urb->pipe; | 29 | unsigned int pipe= urb->pipe; |
@@ -338,7 +338,7 @@ static void ohci_dump_td (const struct ohci_hcd *ohci, const char *label, | |||
338 | } | 338 | } |
339 | 339 | ||
340 | /* caller MUST own hcd spinlock if verbose is set! */ | 340 | /* caller MUST own hcd spinlock if verbose is set! */ |
341 | static void __attribute__((unused)) | 341 | static void __maybe_unused |
342 | ohci_dump_ed (const struct ohci_hcd *ohci, const char *label, | 342 | ohci_dump_ed (const struct ohci_hcd *ohci, const char *label, |
343 | const struct ed *ed, int verbose) | 343 | const struct ed *ed, int verbose) |
344 | { | 344 | { |
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index a66637e725f3..2038125b7f8c 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c | |||
@@ -35,15 +35,13 @@ | |||
35 | #include <linux/dma-mapping.h> | 35 | #include <linux/dma-mapping.h> |
36 | #include <linux/dmapool.h> | 36 | #include <linux/dmapool.h> |
37 | #include <linux/reboot.h> | 37 | #include <linux/reboot.h> |
38 | #include <linux/workqueue.h> | ||
38 | 39 | ||
39 | #include <asm/io.h> | 40 | #include <asm/io.h> |
40 | #include <asm/irq.h> | 41 | #include <asm/irq.h> |
41 | #include <asm/system.h> | 42 | #include <asm/system.h> |
42 | #include <asm/unaligned.h> | 43 | #include <asm/unaligned.h> |
43 | #include <asm/byteorder.h> | 44 | #include <asm/byteorder.h> |
44 | #ifdef CONFIG_PPC_PS3 | ||
45 | #include <asm/firmware.h> | ||
46 | #endif | ||
47 | 45 | ||
48 | #include "../core/hcd.h" | 46 | #include "../core/hcd.h" |
49 | 47 | ||
@@ -82,6 +80,8 @@ static const char hcd_name [] = "ohci_hcd"; | |||
82 | static void ohci_dump (struct ohci_hcd *ohci, int verbose); | 80 | static void ohci_dump (struct ohci_hcd *ohci, int verbose); |
83 | static int ohci_init (struct ohci_hcd *ohci); | 81 | static int ohci_init (struct ohci_hcd *ohci); |
84 | static void ohci_stop (struct usb_hcd *hcd); | 82 | static void ohci_stop (struct usb_hcd *hcd); |
83 | static int ohci_restart (struct ohci_hcd *ohci); | ||
84 | static void ohci_quirk_nec_worker (struct work_struct *work); | ||
85 | 85 | ||
86 | #include "ohci-hub.c" | 86 | #include "ohci-hub.c" |
87 | #include "ohci-dbg.c" | 87 | #include "ohci-dbg.c" |
@@ -510,15 +510,7 @@ static int ohci_run (struct ohci_hcd *ohci) | |||
510 | // flush the writes | 510 | // flush the writes |
511 | (void) ohci_readl (ohci, &ohci->regs->control); | 511 | (void) ohci_readl (ohci, &ohci->regs->control); |
512 | msleep(temp); | 512 | msleep(temp); |
513 | temp = roothub_a (ohci); | 513 | |
514 | if (!(temp & RH_A_NPS)) { | ||
515 | /* power down each port */ | ||
516 | for (temp = 0; temp < ohci->num_ports; temp++) | ||
517 | ohci_writel (ohci, RH_PS_LSDA, | ||
518 | &ohci->regs->roothub.portstatus [temp]); | ||
519 | } | ||
520 | // flush those writes | ||
521 | (void) ohci_readl (ohci, &ohci->regs->control); | ||
522 | memset (ohci->hcca, 0, sizeof (struct ohci_hcca)); | 514 | memset (ohci->hcca, 0, sizeof (struct ohci_hcca)); |
523 | 515 | ||
524 | /* 2msec timelimit here means no irqs/preempt */ | 516 | /* 2msec timelimit here means no irqs/preempt */ |
@@ -659,9 +651,20 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd) | |||
659 | } | 651 | } |
660 | 652 | ||
661 | if (ints & OHCI_INTR_UE) { | 653 | if (ints & OHCI_INTR_UE) { |
662 | disable (ohci); | ||
663 | ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n"); | ||
664 | // e.g. due to PCI Master/Target Abort | 654 | // e.g. due to PCI Master/Target Abort |
655 | if (ohci->flags & OHCI_QUIRK_NEC) { | ||
656 | /* Workaround for a silicon bug in some NEC chips used | ||
657 | * in Apple's PowerBooks. Adapted from Darwin code. | ||
658 | */ | ||
659 | ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n"); | ||
660 | |||
661 | ohci_writel (ohci, OHCI_INTR_UE, ®s->intrdisable); | ||
662 | |||
663 | schedule_work (&ohci->nec_work); | ||
664 | } else { | ||
665 | disable (ohci); | ||
666 | ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n"); | ||
667 | } | ||
665 | 668 | ||
666 | ohci_dump (ohci, 1); | 669 | ohci_dump (ohci, 1); |
667 | ohci_usb_reset (ohci); | 670 | ohci_usb_reset (ohci); |
@@ -763,23 +766,16 @@ static void ohci_stop (struct usb_hcd *hcd) | |||
763 | /*-------------------------------------------------------------------------*/ | 766 | /*-------------------------------------------------------------------------*/ |
764 | 767 | ||
765 | /* must not be called from interrupt context */ | 768 | /* must not be called from interrupt context */ |
766 | |||
767 | #ifdef CONFIG_PM | ||
768 | |||
769 | static int ohci_restart (struct ohci_hcd *ohci) | 769 | static int ohci_restart (struct ohci_hcd *ohci) |
770 | { | 770 | { |
771 | int temp; | 771 | int temp; |
772 | int i; | 772 | int i; |
773 | struct urb_priv *priv; | 773 | struct urb_priv *priv; |
774 | 774 | ||
775 | /* mark any devices gone, so they do nothing till khubd disconnects. | ||
776 | * recycle any "live" eds/tds (and urbs) right away. | ||
777 | * later, khubd disconnect processing will recycle the other state, | ||
778 | * (either as disconnect/reconnect, or maybe someday as a reset). | ||
779 | */ | ||
780 | spin_lock_irq(&ohci->lock); | 775 | spin_lock_irq(&ohci->lock); |
781 | disable (ohci); | 776 | disable (ohci); |
782 | usb_root_hub_lost_power(ohci_to_hcd(ohci)->self.root_hub); | 777 | |
778 | /* Recycle any "live" eds/tds (and urbs). */ | ||
783 | if (!list_empty (&ohci->pending)) | 779 | if (!list_empty (&ohci->pending)) |
784 | ohci_dbg(ohci, "abort schedule...\n"); | 780 | ohci_dbg(ohci, "abort schedule...\n"); |
785 | list_for_each_entry (priv, &ohci->pending, pending) { | 781 | list_for_each_entry (priv, &ohci->pending, pending) { |
@@ -826,20 +822,31 @@ static int ohci_restart (struct ohci_hcd *ohci) | |||
826 | if ((temp = ohci_run (ohci)) < 0) { | 822 | if ((temp = ohci_run (ohci)) < 0) { |
827 | ohci_err (ohci, "can't restart, %d\n", temp); | 823 | ohci_err (ohci, "can't restart, %d\n", temp); |
828 | return temp; | 824 | return temp; |
829 | } else { | ||
830 | /* here we "know" root ports should always stay powered, | ||
831 | * and that if we try to turn them back on the root hub | ||
832 | * will respond to CSC processing. | ||
833 | */ | ||
834 | i = ohci->num_ports; | ||
835 | while (i--) | ||
836 | ohci_writel (ohci, RH_PS_PSS, | ||
837 | &ohci->regs->roothub.portstatus [i]); | ||
838 | ohci_dbg (ohci, "restart complete\n"); | ||
839 | } | 825 | } |
826 | ohci_dbg(ohci, "restart complete\n"); | ||
840 | return 0; | 827 | return 0; |
841 | } | 828 | } |
842 | #endif | 829 | |
830 | /*-------------------------------------------------------------------------*/ | ||
831 | |||
832 | /* NEC workaround */ | ||
833 | static void ohci_quirk_nec_worker(struct work_struct *work) | ||
834 | { | ||
835 | struct ohci_hcd *ohci = container_of(work, struct ohci_hcd, nec_work); | ||
836 | int status; | ||
837 | |||
838 | status = ohci_init(ohci); | ||
839 | if (status != 0) { | ||
840 | ohci_err(ohci, "Restarting NEC controller failed " | ||
841 | "in ohci_init, %d\n", status); | ||
842 | return; | ||
843 | } | ||
844 | |||
845 | status = ohci_restart(ohci); | ||
846 | if (status != 0) | ||
847 | ohci_err(ohci, "Restarting NEC controller failed " | ||
848 | "in ohci_restart, %d\n", status); | ||
849 | } | ||
843 | 850 | ||
844 | /*-------------------------------------------------------------------------*/ | 851 | /*-------------------------------------------------------------------------*/ |
845 | 852 | ||
@@ -917,7 +924,7 @@ MODULE_LICENSE ("GPL"); | |||
917 | 924 | ||
918 | #ifdef CONFIG_PPC_PS3 | 925 | #ifdef CONFIG_PPC_PS3 |
919 | #include "ohci-ps3.c" | 926 | #include "ohci-ps3.c" |
920 | #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_sb_driver | 927 | #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver |
921 | #endif | 928 | #endif |
922 | 929 | ||
923 | #if !defined(PCI_DRIVER) && \ | 930 | #if !defined(PCI_DRIVER) && \ |
@@ -940,12 +947,9 @@ static int __init ohci_hcd_mod_init(void) | |||
940 | sizeof (struct ed), sizeof (struct td)); | 947 | sizeof (struct ed), sizeof (struct td)); |
941 | 948 | ||
942 | #ifdef PS3_SYSTEM_BUS_DRIVER | 949 | #ifdef PS3_SYSTEM_BUS_DRIVER |
943 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) { | 950 | retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER); |
944 | retval = ps3_system_bus_driver_register( | 951 | if (retval < 0) |
945 | &PS3_SYSTEM_BUS_DRIVER); | 952 | goto error_ps3; |
946 | if (retval < 0) | ||
947 | goto error_ps3; | ||
948 | } | ||
949 | #endif | 953 | #endif |
950 | 954 | ||
951 | #ifdef PLATFORM_DRIVER | 955 | #ifdef PLATFORM_DRIVER |
@@ -991,8 +995,7 @@ static int __init ohci_hcd_mod_init(void) | |||
991 | error_platform: | 995 | error_platform: |
992 | #endif | 996 | #endif |
993 | #ifdef PS3_SYSTEM_BUS_DRIVER | 997 | #ifdef PS3_SYSTEM_BUS_DRIVER |
994 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) | 998 | ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); |
995 | ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); | ||
996 | error_ps3: | 999 | error_ps3: |
997 | #endif | 1000 | #endif |
998 | return retval; | 1001 | return retval; |
@@ -1014,8 +1017,7 @@ static void __exit ohci_hcd_mod_exit(void) | |||
1014 | platform_driver_unregister(&PLATFORM_DRIVER); | 1017 | platform_driver_unregister(&PLATFORM_DRIVER); |
1015 | #endif | 1018 | #endif |
1016 | #ifdef PS3_SYSTEM_BUS_DRIVER | 1019 | #ifdef PS3_SYSTEM_BUS_DRIVER |
1017 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) | 1020 | ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); |
1018 | ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); | ||
1019 | #endif | 1021 | #endif |
1020 | } | 1022 | } |
1021 | module_exit(ohci_hcd_mod_exit); | 1023 | module_exit(ohci_hcd_mod_exit); |
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c index bb9cc595219e..48e4b11f4d3e 100644 --- a/drivers/usb/host/ohci-hub.c +++ b/drivers/usb/host/ohci-hub.c | |||
@@ -55,8 +55,6 @@ static void dl_done_list (struct ohci_hcd *); | |||
55 | static void finish_unlinks (struct ohci_hcd *, u16); | 55 | static void finish_unlinks (struct ohci_hcd *, u16); |
56 | 56 | ||
57 | #ifdef CONFIG_PM | 57 | #ifdef CONFIG_PM |
58 | static int ohci_restart(struct ohci_hcd *ohci); | ||
59 | |||
60 | static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop) | 58 | static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop) |
61 | __releases(ohci->lock) | 59 | __releases(ohci->lock) |
62 | __acquires(ohci->lock) | 60 | __acquires(ohci->lock) |
@@ -191,6 +189,9 @@ __acquires(ohci->lock) | |||
191 | spin_unlock_irq (&ohci->lock); | 189 | spin_unlock_irq (&ohci->lock); |
192 | (void) ohci_init (ohci); | 190 | (void) ohci_init (ohci); |
193 | status = ohci_restart (ohci); | 191 | status = ohci_restart (ohci); |
192 | |||
193 | usb_root_hub_lost_power(hcd->self.root_hub); | ||
194 | |||
194 | spin_lock_irq (&ohci->lock); | 195 | spin_lock_irq (&ohci->lock); |
195 | } | 196 | } |
196 | return status; | 197 | return status; |
diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c index 2f20d3dc895b..450c7b460c5a 100644 --- a/drivers/usb/host/ohci-mem.c +++ b/drivers/usb/host/ohci-mem.c | |||
@@ -28,6 +28,7 @@ static void ohci_hcd_init (struct ohci_hcd *ohci) | |||
28 | ohci->next_statechange = jiffies; | 28 | ohci->next_statechange = jiffies; |
29 | spin_lock_init (&ohci->lock); | 29 | spin_lock_init (&ohci->lock); |
30 | INIT_LIST_HEAD (&ohci->pending); | 30 | INIT_LIST_HEAD (&ohci->pending); |
31 | INIT_WORK (&ohci->nec_work, ohci_quirk_nec_worker); | ||
31 | } | 32 | } |
32 | 33 | ||
33 | /*-------------------------------------------------------------------------*/ | 34 | /*-------------------------------------------------------------------------*/ |
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c index ca62cb583221..a5e2eb85d073 100644 --- a/drivers/usb/host/ohci-pci.c +++ b/drivers/usb/host/ohci-pci.c | |||
@@ -111,6 +111,18 @@ static int ohci_quirk_toshiba_scc(struct usb_hcd *hcd) | |||
111 | #endif | 111 | #endif |
112 | } | 112 | } |
113 | 113 | ||
114 | /* Check for NEC chip and apply quirk for allegedly lost interrupts. | ||
115 | */ | ||
116 | static int ohci_quirk_nec(struct usb_hcd *hcd) | ||
117 | { | ||
118 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | ||
119 | |||
120 | ohci->flags |= OHCI_QUIRK_NEC; | ||
121 | ohci_dbg (ohci, "enabled NEC chipset lost interrupt quirk\n"); | ||
122 | |||
123 | return 0; | ||
124 | } | ||
125 | |||
114 | /* List of quirks for OHCI */ | 126 | /* List of quirks for OHCI */ |
115 | static const struct pci_device_id ohci_pci_quirks[] = { | 127 | static const struct pci_device_id ohci_pci_quirks[] = { |
116 | { | 128 | { |
@@ -134,6 +146,10 @@ static const struct pci_device_id ohci_pci_quirks[] = { | |||
134 | .driver_data = (unsigned long)ohci_quirk_toshiba_scc, | 146 | .driver_data = (unsigned long)ohci_quirk_toshiba_scc, |
135 | }, | 147 | }, |
136 | { | 148 | { |
149 | PCI_DEVICE(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB), | ||
150 | .driver_data = (unsigned long)ohci_quirk_nec, | ||
151 | }, | ||
152 | { | ||
137 | /* Toshiba portege 4000 */ | 153 | /* Toshiba portege 4000 */ |
138 | .vendor = PCI_VENDOR_ID_AL, | 154 | .vendor = PCI_VENDOR_ID_AL, |
139 | .device = 0x5237, | 155 | .device = 0x5237, |
@@ -202,6 +218,42 @@ static int __devinit ohci_pci_start (struct usb_hcd *hcd) | |||
202 | return ret; | 218 | return ret; |
203 | } | 219 | } |
204 | 220 | ||
221 | #if defined(CONFIG_USB_PERSIST) && (defined(CONFIG_USB_EHCI_HCD) || \ | ||
222 | defined(CONFIG_USB_EHCI_HCD_MODULE)) | ||
223 | |||
224 | /* Following a power loss, we must prepare to regain control of the ports | ||
225 | * we used to own. This means turning on the port power before ehci-hcd | ||
226 | * tries to switch ownership. | ||
227 | * | ||
228 | * This isn't a 100% perfect solution. On most systems the OHCI controllers | ||
229 | * lie at lower PCI addresses than the EHCI controller, so they will be | ||
230 | * discovered (and hence resumed) first. But there is no guarantee things | ||
231 | * will always work this way. If the EHCI controller is resumed first and | ||
232 | * the OHCI ports are unpowered, then the handover will fail. | ||
233 | */ | ||
234 | static void prepare_for_handover(struct usb_hcd *hcd) | ||
235 | { | ||
236 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
237 | int port; | ||
238 | |||
239 | /* Here we "know" root ports should always stay powered */ | ||
240 | ohci_dbg(ohci, "powerup ports\n"); | ||
241 | for (port = 0; port < ohci->num_ports; port++) | ||
242 | ohci_writel(ohci, RH_PS_PPS, | ||
243 | &ohci->regs->roothub.portstatus[port]); | ||
244 | |||
245 | /* Flush those writes */ | ||
246 | ohci_readl(ohci, &ohci->regs->control); | ||
247 | msleep(20); | ||
248 | } | ||
249 | |||
250 | #else | ||
251 | |||
252 | static inline void prepare_for_handover(struct usb_hcd *hcd) | ||
253 | { } | ||
254 | |||
255 | #endif /* CONFIG_USB_PERSIST etc. */ | ||
256 | |||
205 | #ifdef CONFIG_PM | 257 | #ifdef CONFIG_PM |
206 | 258 | ||
207 | static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message) | 259 | static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message) |
@@ -241,7 +293,10 @@ static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message) | |||
241 | static int ohci_pci_resume (struct usb_hcd *hcd) | 293 | static int ohci_pci_resume (struct usb_hcd *hcd) |
242 | { | 294 | { |
243 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 295 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
244 | usb_hcd_resume_root_hub(hcd); | 296 | |
297 | /* FIXME: we should try to detect loss of VBUS power here */ | ||
298 | prepare_for_handover(hcd); | ||
299 | |||
245 | return 0; | 300 | return 0; |
246 | } | 301 | } |
247 | 302 | ||
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c index d601bbb9387b..ca2a6abbc117 100644 --- a/drivers/usb/host/ohci-pnx4008.c +++ b/drivers/usb/host/ohci-pnx4008.c | |||
@@ -134,7 +134,7 @@ static int isp1301_attach(struct i2c_adapter *adap, int addr, int kind) | |||
134 | { | 134 | { |
135 | struct i2c_client *c; | 135 | struct i2c_client *c; |
136 | 136 | ||
137 | c = (struct i2c_client *)kzalloc(sizeof(*c), GFP_KERNEL); | 137 | c = kzalloc(sizeof(*c), GFP_KERNEL); |
138 | 138 | ||
139 | if (!c) | 139 | if (!c) |
140 | return -ENOMEM; | 140 | return -ENOMEM; |
diff --git a/drivers/usb/host/ohci-ps3.c b/drivers/usb/host/ohci-ps3.c index d7cf07288b0b..01a0caeaa6bc 100644 --- a/drivers/usb/host/ohci-ps3.c +++ b/drivers/usb/host/ohci-ps3.c | |||
@@ -18,6 +18,7 @@ | |||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <asm/firmware.h> | ||
21 | #include <asm/ps3.h> | 22 | #include <asm/ps3.h> |
22 | 23 | ||
23 | static int ps3_ohci_hc_reset(struct usb_hcd *hcd) | 24 | static int ps3_ohci_hc_reset(struct usb_hcd *hcd) |
@@ -75,7 +76,7 @@ static const struct hc_driver ps3_ohci_hc_driver = { | |||
75 | #endif | 76 | #endif |
76 | }; | 77 | }; |
77 | 78 | ||
78 | static int ps3_ohci_sb_probe(struct ps3_system_bus_device *dev) | 79 | static int ps3_ohci_probe(struct ps3_system_bus_device *dev) |
79 | { | 80 | { |
80 | int result; | 81 | int result; |
81 | struct usb_hcd *hcd; | 82 | struct usb_hcd *hcd; |
@@ -87,13 +88,31 @@ static int ps3_ohci_sb_probe(struct ps3_system_bus_device *dev) | |||
87 | goto fail_start; | 88 | goto fail_start; |
88 | } | 89 | } |
89 | 90 | ||
91 | result = ps3_open_hv_device(dev); | ||
92 | |||
93 | if (result) { | ||
94 | dev_dbg(&dev->core, "%s:%d: ps3_open_hv_device failed: %s\n", | ||
95 | __func__, __LINE__, ps3_result(result)); | ||
96 | result = -EPERM; | ||
97 | goto fail_open; | ||
98 | } | ||
99 | |||
100 | result = ps3_dma_region_create(dev->d_region); | ||
101 | |||
102 | if (result) { | ||
103 | dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: " | ||
104 | "(%d)\n", __func__, __LINE__, result); | ||
105 | BUG_ON("check region type"); | ||
106 | goto fail_dma_region; | ||
107 | } | ||
108 | |||
90 | result = ps3_mmio_region_create(dev->m_region); | 109 | result = ps3_mmio_region_create(dev->m_region); |
91 | 110 | ||
92 | if (result) { | 111 | if (result) { |
93 | dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n", | 112 | dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n", |
94 | __func__, __LINE__); | 113 | __func__, __LINE__); |
95 | result = -EPERM; | 114 | result = -EPERM; |
96 | goto fail_mmio; | 115 | goto fail_mmio_region; |
97 | } | 116 | } |
98 | 117 | ||
99 | dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__, | 118 | dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__, |
@@ -122,6 +141,11 @@ static int ps3_ohci_sb_probe(struct ps3_system_bus_device *dev) | |||
122 | 141 | ||
123 | hcd->rsrc_start = dev->m_region->lpar_addr; | 142 | hcd->rsrc_start = dev->m_region->lpar_addr; |
124 | hcd->rsrc_len = dev->m_region->len; | 143 | hcd->rsrc_len = dev->m_region->len; |
144 | |||
145 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) | ||
146 | dev_dbg(&dev->core, "%s:%d: request_mem_region failed\n", | ||
147 | __func__, __LINE__); | ||
148 | |||
125 | hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len); | 149 | hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len); |
126 | 150 | ||
127 | if (!hcd->regs) { | 151 | if (!hcd->regs) { |
@@ -155,34 +179,73 @@ static int ps3_ohci_sb_probe(struct ps3_system_bus_device *dev) | |||
155 | fail_add_hcd: | 179 | fail_add_hcd: |
156 | iounmap(hcd->regs); | 180 | iounmap(hcd->regs); |
157 | fail_ioremap: | 181 | fail_ioremap: |
182 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
158 | usb_put_hcd(hcd); | 183 | usb_put_hcd(hcd); |
159 | fail_create_hcd: | 184 | fail_create_hcd: |
160 | ps3_io_irq_destroy(virq); | 185 | ps3_io_irq_destroy(virq); |
161 | fail_irq: | 186 | fail_irq: |
162 | ps3_free_mmio_region(dev->m_region); | 187 | ps3_free_mmio_region(dev->m_region); |
163 | fail_mmio: | 188 | fail_mmio_region: |
189 | ps3_dma_region_free(dev->d_region); | ||
190 | fail_dma_region: | ||
191 | ps3_close_hv_device(dev); | ||
192 | fail_open: | ||
164 | fail_start: | 193 | fail_start: |
165 | return result; | 194 | return result; |
166 | } | 195 | } |
167 | 196 | ||
168 | static int ps3_ohci_sb_remove (struct ps3_system_bus_device *dev) | 197 | static int ps3_ohci_remove (struct ps3_system_bus_device *dev) |
169 | { | 198 | { |
199 | unsigned int tmp; | ||
170 | struct usb_hcd *hcd = | 200 | struct usb_hcd *hcd = |
171 | (struct usb_hcd *)ps3_system_bus_get_driver_data(dev); | 201 | (struct usb_hcd *)ps3_system_bus_get_driver_data(dev); |
172 | 202 | ||
173 | usb_put_hcd(hcd); | 203 | BUG_ON(!hcd); |
204 | |||
205 | dev_dbg(&dev->core, "%s:%d: regs %p\n", __func__, __LINE__, hcd->regs); | ||
206 | dev_dbg(&dev->core, "%s:%d: irq %u\n", __func__, __LINE__, hcd->irq); | ||
207 | |||
208 | tmp = hcd->irq; | ||
209 | |||
210 | usb_remove_hcd(hcd); | ||
211 | |||
174 | ps3_system_bus_set_driver_data(dev, NULL); | 212 | ps3_system_bus_set_driver_data(dev, NULL); |
175 | 213 | ||
214 | BUG_ON(!hcd->regs); | ||
215 | iounmap(hcd->regs); | ||
216 | |||
217 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
218 | usb_put_hcd(hcd); | ||
219 | |||
220 | ps3_io_irq_destroy(tmp); | ||
221 | ps3_free_mmio_region(dev->m_region); | ||
222 | |||
223 | ps3_dma_region_free(dev->d_region); | ||
224 | ps3_close_hv_device(dev); | ||
225 | |||
176 | return 0; | 226 | return 0; |
177 | } | 227 | } |
178 | 228 | ||
179 | MODULE_ALIAS("ps3-ohci"); | 229 | static int ps3_ohci_driver_register(struct ps3_system_bus_driver *drv) |
230 | { | ||
231 | return firmware_has_feature(FW_FEATURE_PS3_LV1) | ||
232 | ? ps3_system_bus_driver_register(drv) | ||
233 | : 0; | ||
234 | } | ||
235 | |||
236 | static void ps3_ohci_driver_unregister(struct ps3_system_bus_driver *drv) | ||
237 | { | ||
238 | if (firmware_has_feature(FW_FEATURE_PS3_LV1)) | ||
239 | ps3_system_bus_driver_unregister(drv); | ||
240 | } | ||
241 | |||
242 | MODULE_ALIAS(PS3_MODULE_ALIAS_OHCI); | ||
180 | 243 | ||
181 | static struct ps3_system_bus_driver ps3_ohci_sb_driver = { | 244 | static struct ps3_system_bus_driver ps3_ohci_driver = { |
245 | .core.name = "ps3-ohci-driver", | ||
246 | .core.owner = THIS_MODULE, | ||
182 | .match_id = PS3_MATCH_ID_OHCI, | 247 | .match_id = PS3_MATCH_ID_OHCI, |
183 | .core = { | 248 | .probe = ps3_ohci_probe, |
184 | .name = "ps3-ohci-driver", | 249 | .remove = ps3_ohci_remove, |
185 | }, | 250 | .shutdown = ps3_ohci_remove, |
186 | .probe = ps3_ohci_sb_probe, | ||
187 | .remove = ps3_ohci_sb_remove, | ||
188 | }; | 251 | }; |
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h index c2b5ecfe5e9f..4ada43cf1387 100644 --- a/drivers/usb/host/ohci.h +++ b/drivers/usb/host/ohci.h | |||
@@ -397,8 +397,10 @@ struct ohci_hcd { | |||
397 | #define OHCI_QUIRK_BE_DESC 0x08 /* BE descriptors */ | 397 | #define OHCI_QUIRK_BE_DESC 0x08 /* BE descriptors */ |
398 | #define OHCI_QUIRK_BE_MMIO 0x10 /* BE registers */ | 398 | #define OHCI_QUIRK_BE_MMIO 0x10 /* BE registers */ |
399 | #define OHCI_QUIRK_ZFMICRO 0x20 /* Compaq ZFMicro chipset*/ | 399 | #define OHCI_QUIRK_ZFMICRO 0x20 /* Compaq ZFMicro chipset*/ |
400 | #define OHCI_QUIRK_NEC 0x40 /* lost interrupts */ | ||
400 | // there are also chip quirks/bugs in init logic | 401 | // there are also chip quirks/bugs in init logic |
401 | 402 | ||
403 | struct work_struct nec_work; /* Worker for NEC quirk */ | ||
402 | }; | 404 | }; |
403 | 405 | ||
404 | /* convert between an hcd pointer and the corresponding ohci_hcd */ | 406 | /* convert between an hcd pointer and the corresponding ohci_hcd */ |
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c new file mode 100644 index 000000000000..a7a7070c6e2a --- /dev/null +++ b/drivers/usb/host/r8a66597-hcd.c | |||
@@ -0,0 +1,2244 @@ | |||
1 | /* | ||
2 | * R8A66597 HCD (Host Controller Driver) | ||
3 | * | ||
4 | * Copyright (C) 2006-2007 Renesas Solutions Corp. | ||
5 | * Portions Copyright (C) 2004 Psion Teklogix (for NetBook PRO) | ||
6 | * Portions Copyright (C) 2004-2005 David Brownell | ||
7 | * Portions Copyright (C) 1999 Roman Weissgaerber | ||
8 | * | ||
9 | * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License as published by | ||
13 | * the Free Software Foundation; version 2 of the License. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #include <linux/module.h> | ||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/sched.h> | ||
29 | #include <linux/smp_lock.h> | ||
30 | #include <linux/errno.h> | ||
31 | #include <linux/init.h> | ||
32 | #include <linux/timer.h> | ||
33 | #include <linux/delay.h> | ||
34 | #include <linux/list.h> | ||
35 | #include <linux/interrupt.h> | ||
36 | #include <linux/usb.h> | ||
37 | #include <linux/platform_device.h> | ||
38 | |||
39 | #include <asm/io.h> | ||
40 | #include <asm/irq.h> | ||
41 | #include <asm/system.h> | ||
42 | |||
43 | #include "../core/hcd.h" | ||
44 | #include "r8a66597.h" | ||
45 | |||
46 | MODULE_DESCRIPTION("R8A66597 USB Host Controller Driver"); | ||
47 | MODULE_LICENSE("GPL"); | ||
48 | MODULE_AUTHOR("Yoshihiro Shimoda"); | ||
49 | |||
50 | #define DRIVER_VERSION "29 May 2007" | ||
51 | |||
52 | static const char hcd_name[] = "r8a66597_hcd"; | ||
53 | |||
54 | /* module parameters */ | ||
55 | static unsigned short clock = XTAL12; | ||
56 | module_param(clock, ushort, 0644); | ||
57 | MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0(default=0)"); | ||
58 | static unsigned short vif = LDRV; | ||
59 | module_param(vif, ushort, 0644); | ||
60 | MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0(default=32768)"); | ||
61 | static unsigned short endian = 0; | ||
62 | module_param(endian, ushort, 0644); | ||
63 | MODULE_PARM_DESC(endian, "data endian: big=256, little=0(default=0)"); | ||
64 | static unsigned short irq_sense = INTL; | ||
65 | module_param(irq_sense, ushort, 0644); | ||
66 | MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=32, falling edge=0(default=32)"); | ||
67 | |||
68 | static void packet_write(struct r8a66597 *r8a66597, u16 pipenum); | ||
69 | static int r8a66597_get_frame(struct usb_hcd *hcd); | ||
70 | |||
71 | /* this function must be called with interrupt disabled */ | ||
72 | static void enable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum, | ||
73 | unsigned long reg) | ||
74 | { | ||
75 | u16 tmp; | ||
76 | |||
77 | tmp = r8a66597_read(r8a66597, INTENB0); | ||
78 | r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0); | ||
79 | r8a66597_bset(r8a66597, 1 << pipenum, reg); | ||
80 | r8a66597_write(r8a66597, tmp, INTENB0); | ||
81 | } | ||
82 | |||
83 | /* this function must be called with interrupt disabled */ | ||
84 | static void disable_pipe_irq(struct r8a66597 *r8a66597, u16 pipenum, | ||
85 | unsigned long reg) | ||
86 | { | ||
87 | u16 tmp; | ||
88 | |||
89 | tmp = r8a66597_read(r8a66597, INTENB0); | ||
90 | r8a66597_bclr(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0); | ||
91 | r8a66597_bclr(r8a66597, 1 << pipenum, reg); | ||
92 | r8a66597_write(r8a66597, tmp, INTENB0); | ||
93 | } | ||
94 | |||
95 | static void set_devadd_reg(struct r8a66597 *r8a66597, u8 r8a66597_address, | ||
96 | u16 usbspd, u8 upphub, u8 hubport, int port) | ||
97 | { | ||
98 | u16 val; | ||
99 | unsigned long devadd_reg = get_devadd_addr(r8a66597_address); | ||
100 | |||
101 | val = (upphub << 11) | (hubport << 8) | (usbspd << 6) | (port & 0x0001); | ||
102 | r8a66597_write(r8a66597, val, devadd_reg); | ||
103 | } | ||
104 | |||
105 | static int enable_controller(struct r8a66597 *r8a66597) | ||
106 | { | ||
107 | u16 tmp; | ||
108 | int i = 0; | ||
109 | |||
110 | do { | ||
111 | r8a66597_write(r8a66597, USBE, SYSCFG0); | ||
112 | tmp = r8a66597_read(r8a66597, SYSCFG0); | ||
113 | if (i++ > 1000) { | ||
114 | err("register access fail."); | ||
115 | return -ENXIO; | ||
116 | } | ||
117 | } while ((tmp & USBE) != USBE); | ||
118 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); | ||
119 | r8a66597_mdfy(r8a66597, clock, XTAL, SYSCFG0); | ||
120 | |||
121 | i = 0; | ||
122 | r8a66597_bset(r8a66597, XCKE, SYSCFG0); | ||
123 | do { | ||
124 | msleep(1); | ||
125 | tmp = r8a66597_read(r8a66597, SYSCFG0); | ||
126 | if (i++ > 500) { | ||
127 | err("register access fail."); | ||
128 | return -ENXIO; | ||
129 | } | ||
130 | } while ((tmp & SCKE) != SCKE); | ||
131 | |||
132 | r8a66597_bset(r8a66597, DCFM | DRPD, SYSCFG0); | ||
133 | r8a66597_bset(r8a66597, DRPD, SYSCFG1); | ||
134 | |||
135 | r8a66597_bset(r8a66597, vif & LDRV, PINCFG); | ||
136 | r8a66597_bset(r8a66597, HSE, SYSCFG0); | ||
137 | r8a66597_bset(r8a66597, HSE, SYSCFG1); | ||
138 | r8a66597_bset(r8a66597, USBE, SYSCFG0); | ||
139 | |||
140 | r8a66597_bset(r8a66597, BEMPE | NRDYE | BRDYE, INTENB0); | ||
141 | r8a66597_bset(r8a66597, irq_sense & INTL, SOFCFG); | ||
142 | r8a66597_bset(r8a66597, BRDY0, BRDYENB); | ||
143 | r8a66597_bset(r8a66597, BEMP0, BEMPENB); | ||
144 | |||
145 | r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, DMA0CFG); | ||
146 | r8a66597_write(r8a66597, BURST | CPU_ADR_RD_WR, DMA1CFG); | ||
147 | |||
148 | r8a66597_bset(r8a66597, endian & BIGEND, CFIFOSEL); | ||
149 | r8a66597_bset(r8a66597, endian & BIGEND, D0FIFOSEL); | ||
150 | r8a66597_bset(r8a66597, endian & BIGEND, D1FIFOSEL); | ||
151 | |||
152 | r8a66597_bset(r8a66597, TRNENSEL, SOFCFG); | ||
153 | |||
154 | r8a66597_bset(r8a66597, SIGNE | SACKE, INTENB1); | ||
155 | r8a66597_bclr(r8a66597, DTCHE, INTENB1); | ||
156 | r8a66597_bset(r8a66597, ATTCHE, INTENB1); | ||
157 | r8a66597_bclr(r8a66597, DTCHE, INTENB2); | ||
158 | r8a66597_bset(r8a66597, ATTCHE, INTENB2); | ||
159 | |||
160 | return 0; | ||
161 | } | ||
162 | |||
163 | static void disable_controller(struct r8a66597 *r8a66597) | ||
164 | { | ||
165 | u16 tmp; | ||
166 | |||
167 | r8a66597_write(r8a66597, 0, INTENB0); | ||
168 | r8a66597_write(r8a66597, 0, INTENB1); | ||
169 | r8a66597_write(r8a66597, 0, INTENB2); | ||
170 | r8a66597_write(r8a66597, 0, INTSTS0); | ||
171 | r8a66597_write(r8a66597, 0, INTSTS1); | ||
172 | r8a66597_write(r8a66597, 0, INTSTS2); | ||
173 | |||
174 | r8a66597_port_power(r8a66597, 0, 0); | ||
175 | r8a66597_port_power(r8a66597, 1, 0); | ||
176 | |||
177 | do { | ||
178 | tmp = r8a66597_read(r8a66597, SOFCFG) & EDGESTS; | ||
179 | udelay(640); | ||
180 | } while (tmp == EDGESTS); | ||
181 | |||
182 | r8a66597_bclr(r8a66597, DCFM | DRPD, SYSCFG0); | ||
183 | r8a66597_bclr(r8a66597, DRPD, SYSCFG1); | ||
184 | r8a66597_bclr(r8a66597, HSE, SYSCFG0); | ||
185 | r8a66597_bclr(r8a66597, HSE, SYSCFG1); | ||
186 | |||
187 | r8a66597_bclr(r8a66597, SCKE, SYSCFG0); | ||
188 | udelay(1); | ||
189 | r8a66597_bclr(r8a66597, PLLC, SYSCFG0); | ||
190 | r8a66597_bclr(r8a66597, XCKE, SYSCFG0); | ||
191 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); | ||
192 | } | ||
193 | |||
194 | static int get_parent_r8a66597_address(struct r8a66597 *r8a66597, | ||
195 | struct usb_device *udev) | ||
196 | { | ||
197 | struct r8a66597_device *dev; | ||
198 | |||
199 | if (udev->parent && udev->parent->devnum != 1) | ||
200 | udev = udev->parent; | ||
201 | |||
202 | dev = dev_get_drvdata(&udev->dev); | ||
203 | if (dev) | ||
204 | return dev->address; | ||
205 | else | ||
206 | return 0; | ||
207 | } | ||
208 | |||
209 | static int is_child_device(char *devpath) | ||
210 | { | ||
211 | return (devpath[2] ? 1 : 0); | ||
212 | } | ||
213 | |||
214 | static int is_hub_limit(char *devpath) | ||
215 | { | ||
216 | return ((strlen(devpath) >= 4) ? 1 : 0); | ||
217 | } | ||
218 | |||
219 | static void get_port_number(char *devpath, u16 *root_port, u16 *hub_port) | ||
220 | { | ||
221 | if (root_port) { | ||
222 | *root_port = (devpath[0] & 0x0F) - 1; | ||
223 | if (*root_port >= R8A66597_MAX_ROOT_HUB) | ||
224 | err("illegal root port number"); | ||
225 | } | ||
226 | if (hub_port) | ||
227 | *hub_port = devpath[2] & 0x0F; | ||
228 | } | ||
229 | |||
230 | static u16 get_r8a66597_usb_speed(enum usb_device_speed speed) | ||
231 | { | ||
232 | u16 usbspd = 0; | ||
233 | |||
234 | switch (speed) { | ||
235 | case USB_SPEED_LOW: | ||
236 | usbspd = LSMODE; | ||
237 | break; | ||
238 | case USB_SPEED_FULL: | ||
239 | usbspd = FSMODE; | ||
240 | break; | ||
241 | case USB_SPEED_HIGH: | ||
242 | usbspd = HSMODE; | ||
243 | break; | ||
244 | default: | ||
245 | err("unknown speed"); | ||
246 | break; | ||
247 | } | ||
248 | |||
249 | return usbspd; | ||
250 | } | ||
251 | |||
252 | static void set_child_connect_map(struct r8a66597 *r8a66597, int address) | ||
253 | { | ||
254 | int idx; | ||
255 | |||
256 | idx = address / 32; | ||
257 | r8a66597->child_connect_map[idx] |= 1 << (address % 32); | ||
258 | } | ||
259 | |||
260 | static void put_child_connect_map(struct r8a66597 *r8a66597, int address) | ||
261 | { | ||
262 | int idx; | ||
263 | |||
264 | idx = address / 32; | ||
265 | r8a66597->child_connect_map[idx] &= ~(1 << (address % 32)); | ||
266 | } | ||
267 | |||
268 | static void set_pipe_reg_addr(struct r8a66597_pipe *pipe, u8 dma_ch) | ||
269 | { | ||
270 | u16 pipenum = pipe->info.pipenum; | ||
271 | unsigned long fifoaddr[] = {D0FIFO, D1FIFO, CFIFO}; | ||
272 | unsigned long fifosel[] = {D0FIFOSEL, D1FIFOSEL, CFIFOSEL}; | ||
273 | unsigned long fifoctr[] = {D0FIFOCTR, D1FIFOCTR, CFIFOCTR}; | ||
274 | |||
275 | if (dma_ch > R8A66597_PIPE_NO_DMA) /* dma fifo not use? */ | ||
276 | dma_ch = R8A66597_PIPE_NO_DMA; | ||
277 | |||
278 | pipe->fifoaddr = fifoaddr[dma_ch]; | ||
279 | pipe->fifosel = fifosel[dma_ch]; | ||
280 | pipe->fifoctr = fifoctr[dma_ch]; | ||
281 | |||
282 | if (pipenum == 0) | ||
283 | pipe->pipectr = DCPCTR; | ||
284 | else | ||
285 | pipe->pipectr = get_pipectr_addr(pipenum); | ||
286 | |||
287 | if (check_bulk_or_isoc(pipenum)) { | ||
288 | pipe->pipetre = get_pipetre_addr(pipenum); | ||
289 | pipe->pipetrn = get_pipetrn_addr(pipenum); | ||
290 | } else { | ||
291 | pipe->pipetre = 0; | ||
292 | pipe->pipetrn = 0; | ||
293 | } | ||
294 | } | ||
295 | |||
296 | static struct r8a66597_device * | ||
297 | get_urb_to_r8a66597_dev(struct r8a66597 *r8a66597, struct urb *urb) | ||
298 | { | ||
299 | if (usb_pipedevice(urb->pipe) == 0) | ||
300 | return &r8a66597->device0; | ||
301 | |||
302 | return dev_get_drvdata(&urb->dev->dev); | ||
303 | } | ||
304 | |||
305 | static int make_r8a66597_device(struct r8a66597 *r8a66597, | ||
306 | struct urb *urb, u8 addr) | ||
307 | { | ||
308 | struct r8a66597_device *dev; | ||
309 | int usb_address = urb->setup_packet[2]; /* urb->pipe is address 0 */ | ||
310 | |||
311 | dev = kzalloc(sizeof(struct r8a66597_device), GFP_KERNEL); | ||
312 | if (dev == NULL) | ||
313 | return -ENOMEM; | ||
314 | |||
315 | dev_set_drvdata(&urb->dev->dev, dev); | ||
316 | dev->udev = urb->dev; | ||
317 | dev->address = addr; | ||
318 | dev->usb_address = usb_address; | ||
319 | dev->state = USB_STATE_ADDRESS; | ||
320 | dev->ep_in_toggle = 0; | ||
321 | dev->ep_out_toggle = 0; | ||
322 | INIT_LIST_HEAD(&dev->device_list); | ||
323 | list_add_tail(&dev->device_list, &r8a66597->child_device); | ||
324 | |||
325 | get_port_number(urb->dev->devpath, &dev->root_port, &dev->hub_port); | ||
326 | if (!is_child_device(urb->dev->devpath)) | ||
327 | r8a66597->root_hub[dev->root_port].dev = dev; | ||
328 | |||
329 | set_devadd_reg(r8a66597, dev->address, | ||
330 | get_r8a66597_usb_speed(urb->dev->speed), | ||
331 | get_parent_r8a66597_address(r8a66597, urb->dev), | ||
332 | dev->hub_port, dev->root_port); | ||
333 | |||
334 | return 0; | ||
335 | } | ||
336 | |||
337 | /* this function must be called with interrupt disabled */ | ||
338 | static u8 alloc_usb_address(struct r8a66597 *r8a66597, struct urb *urb) | ||
339 | { | ||
340 | u8 addr; /* R8A66597's address */ | ||
341 | struct r8a66597_device *dev; | ||
342 | |||
343 | if (is_hub_limit(urb->dev->devpath)) { | ||
344 | err("Externel hub limit reached."); | ||
345 | return 0; | ||
346 | } | ||
347 | |||
348 | dev = get_urb_to_r8a66597_dev(r8a66597, urb); | ||
349 | if (dev && dev->state >= USB_STATE_ADDRESS) | ||
350 | return dev->address; | ||
351 | |||
352 | for (addr = 1; addr <= R8A66597_MAX_DEVICE; addr++) { | ||
353 | if (r8a66597->address_map & (1 << addr)) | ||
354 | continue; | ||
355 | |||
356 | dbg("alloc_address: r8a66597_addr=%d", addr); | ||
357 | r8a66597->address_map |= 1 << addr; | ||
358 | |||
359 | if (make_r8a66597_device(r8a66597, urb, addr) < 0) | ||
360 | return 0; | ||
361 | |||
362 | return addr; | ||
363 | } | ||
364 | |||
365 | err("cannot communicate with a USB device more than 10.(%x)", | ||
366 | r8a66597->address_map); | ||
367 | |||
368 | return 0; | ||
369 | } | ||
370 | |||
371 | /* this function must be called with interrupt disabled */ | ||
372 | static void free_usb_address(struct r8a66597 *r8a66597, | ||
373 | struct r8a66597_device *dev) | ||
374 | { | ||
375 | int port; | ||
376 | |||
377 | if (!dev) | ||
378 | return; | ||
379 | |||
380 | dbg("free_addr: addr=%d", dev->address); | ||
381 | |||
382 | dev->state = USB_STATE_DEFAULT; | ||
383 | r8a66597->address_map &= ~(1 << dev->address); | ||
384 | dev->address = 0; | ||
385 | dev_set_drvdata(&dev->udev->dev, NULL); | ||
386 | list_del(&dev->device_list); | ||
387 | kfree(dev); | ||
388 | |||
389 | for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) { | ||
390 | if (r8a66597->root_hub[port].dev == dev) { | ||
391 | r8a66597->root_hub[port].dev = NULL; | ||
392 | break; | ||
393 | } | ||
394 | } | ||
395 | } | ||
396 | |||
397 | static void r8a66597_reg_wait(struct r8a66597 *r8a66597, unsigned long reg, | ||
398 | u16 mask, u16 loop) | ||
399 | { | ||
400 | u16 tmp; | ||
401 | int i = 0; | ||
402 | |||
403 | do { | ||
404 | tmp = r8a66597_read(r8a66597, reg); | ||
405 | if (i++ > 1000000) { | ||
406 | err("register%lx, loop %x is timeout", reg, loop); | ||
407 | break; | ||
408 | } | ||
409 | ndelay(1); | ||
410 | } while ((tmp & mask) != loop); | ||
411 | } | ||
412 | |||
413 | /* this function must be called with interrupt disabled */ | ||
414 | static void pipe_start(struct r8a66597 *r8a66597, struct r8a66597_pipe *pipe) | ||
415 | { | ||
416 | u16 tmp; | ||
417 | |||
418 | tmp = r8a66597_read(r8a66597, pipe->pipectr) & PID; | ||
419 | if ((pipe->info.pipenum != 0) & ((tmp & PID_STALL) != 0)) /* stall? */ | ||
420 | r8a66597_mdfy(r8a66597, PID_NAK, PID, pipe->pipectr); | ||
421 | r8a66597_mdfy(r8a66597, PID_BUF, PID, pipe->pipectr); | ||
422 | } | ||
423 | |||
424 | /* this function must be called with interrupt disabled */ | ||
425 | static void pipe_stop(struct r8a66597 *r8a66597, struct r8a66597_pipe *pipe) | ||
426 | { | ||
427 | u16 tmp; | ||
428 | |||
429 | tmp = r8a66597_read(r8a66597, pipe->pipectr) & PID; | ||
430 | if ((tmp & PID_STALL11) != PID_STALL11) /* force stall? */ | ||
431 | r8a66597_mdfy(r8a66597, PID_STALL, PID, pipe->pipectr); | ||
432 | r8a66597_mdfy(r8a66597, PID_NAK, PID, pipe->pipectr); | ||
433 | r8a66597_reg_wait(r8a66597, pipe->pipectr, PBUSY, 0); | ||
434 | } | ||
435 | |||
436 | /* this function must be called with interrupt disabled */ | ||
437 | static void clear_all_buffer(struct r8a66597 *r8a66597, | ||
438 | struct r8a66597_pipe *pipe) | ||
439 | { | ||
440 | u16 tmp; | ||
441 | |||
442 | if (!pipe || pipe->info.pipenum == 0) | ||
443 | return; | ||
444 | |||
445 | pipe_stop(r8a66597, pipe); | ||
446 | r8a66597_bset(r8a66597, ACLRM, pipe->pipectr); | ||
447 | tmp = r8a66597_read(r8a66597, pipe->pipectr); | ||
448 | tmp = r8a66597_read(r8a66597, pipe->pipectr); | ||
449 | tmp = r8a66597_read(r8a66597, pipe->pipectr); | ||
450 | r8a66597_bclr(r8a66597, ACLRM, pipe->pipectr); | ||
451 | } | ||
452 | |||
453 | /* this function must be called with interrupt disabled */ | ||
454 | static void r8a66597_pipe_toggle(struct r8a66597 *r8a66597, | ||
455 | struct r8a66597_pipe *pipe, int toggle) | ||
456 | { | ||
457 | if (toggle) | ||
458 | r8a66597_bset(r8a66597, SQSET, pipe->pipectr); | ||
459 | else | ||
460 | r8a66597_bset(r8a66597, SQCLR, pipe->pipectr); | ||
461 | } | ||
462 | |||
463 | /* this function must be called with interrupt disabled */ | ||
464 | static inline void cfifo_change(struct r8a66597 *r8a66597, u16 pipenum) | ||
465 | { | ||
466 | r8a66597_mdfy(r8a66597, MBW | pipenum, MBW | CURPIPE, CFIFOSEL); | ||
467 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, pipenum); | ||
468 | } | ||
469 | |||
470 | /* this function must be called with interrupt disabled */ | ||
471 | static inline void fifo_change_from_pipe(struct r8a66597 *r8a66597, | ||
472 | struct r8a66597_pipe *pipe) | ||
473 | { | ||
474 | cfifo_change(r8a66597, 0); | ||
475 | r8a66597_mdfy(r8a66597, MBW | 0, MBW | CURPIPE, D0FIFOSEL); | ||
476 | r8a66597_mdfy(r8a66597, MBW | 0, MBW | CURPIPE, D1FIFOSEL); | ||
477 | |||
478 | r8a66597_mdfy(r8a66597, MBW | pipe->info.pipenum, MBW | CURPIPE, | ||
479 | pipe->fifosel); | ||
480 | r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE, pipe->info.pipenum); | ||
481 | } | ||
482 | |||
483 | static u16 r8a66597_get_pipenum(struct urb *urb, struct usb_host_endpoint *hep) | ||
484 | { | ||
485 | struct r8a66597_pipe *pipe = hep->hcpriv; | ||
486 | |||
487 | if (usb_pipeendpoint(urb->pipe) == 0) | ||
488 | return 0; | ||
489 | else | ||
490 | return pipe->info.pipenum; | ||
491 | } | ||
492 | |||
493 | static u16 get_urb_to_r8a66597_addr(struct r8a66597 *r8a66597, struct urb *urb) | ||
494 | { | ||
495 | struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb); | ||
496 | |||
497 | return (usb_pipedevice(urb->pipe) == 0) ? 0 : dev->address; | ||
498 | } | ||
499 | |||
500 | static unsigned short *get_toggle_pointer(struct r8a66597_device *dev, | ||
501 | int urb_pipe) | ||
502 | { | ||
503 | if (!dev) | ||
504 | return NULL; | ||
505 | |||
506 | return usb_pipein(urb_pipe) ? &dev->ep_in_toggle : &dev->ep_out_toggle; | ||
507 | } | ||
508 | |||
509 | /* this function must be called with interrupt disabled */ | ||
510 | static void pipe_toggle_set(struct r8a66597 *r8a66597, | ||
511 | struct r8a66597_pipe *pipe, | ||
512 | struct urb *urb, int set) | ||
513 | { | ||
514 | struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb); | ||
515 | unsigned char endpoint = usb_pipeendpoint(urb->pipe); | ||
516 | unsigned short *toggle = get_toggle_pointer(dev, urb->pipe); | ||
517 | |||
518 | if (!toggle) | ||
519 | return; | ||
520 | |||
521 | if (set) | ||
522 | *toggle |= 1 << endpoint; | ||
523 | else | ||
524 | *toggle &= ~(1 << endpoint); | ||
525 | } | ||
526 | |||
527 | /* this function must be called with interrupt disabled */ | ||
528 | static void pipe_toggle_save(struct r8a66597 *r8a66597, | ||
529 | struct r8a66597_pipe *pipe, | ||
530 | struct urb *urb) | ||
531 | { | ||
532 | if (r8a66597_read(r8a66597, pipe->pipectr) & SQMON) | ||
533 | pipe_toggle_set(r8a66597, pipe, urb, 1); | ||
534 | else | ||
535 | pipe_toggle_set(r8a66597, pipe, urb, 0); | ||
536 | } | ||
537 | |||
538 | /* this function must be called with interrupt disabled */ | ||
539 | static void pipe_toggle_restore(struct r8a66597 *r8a66597, | ||
540 | struct r8a66597_pipe *pipe, | ||
541 | struct urb *urb) | ||
542 | { | ||
543 | struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb); | ||
544 | unsigned char endpoint = usb_pipeendpoint(urb->pipe); | ||
545 | unsigned short *toggle = get_toggle_pointer(dev, urb->pipe); | ||
546 | |||
547 | if (!toggle) | ||
548 | return; | ||
549 | |||
550 | r8a66597_pipe_toggle(r8a66597, pipe, *toggle & (1 << endpoint)); | ||
551 | } | ||
552 | |||
553 | /* this function must be called with interrupt disabled */ | ||
554 | static void pipe_buffer_setting(struct r8a66597 *r8a66597, | ||
555 | struct r8a66597_pipe_info *info) | ||
556 | { | ||
557 | u16 val = 0; | ||
558 | |||
559 | if (info->pipenum == 0) | ||
560 | return; | ||
561 | |||
562 | r8a66597_bset(r8a66597, ACLRM, get_pipectr_addr(info->pipenum)); | ||
563 | r8a66597_bclr(r8a66597, ACLRM, get_pipectr_addr(info->pipenum)); | ||
564 | r8a66597_write(r8a66597, info->pipenum, PIPESEL); | ||
565 | if (!info->dir_in) | ||
566 | val |= R8A66597_DIR; | ||
567 | if (info->type == R8A66597_BULK && info->dir_in) | ||
568 | val |= R8A66597_DBLB | R8A66597_SHTNAK; | ||
569 | val |= info->type | info->epnum; | ||
570 | r8a66597_write(r8a66597, val, PIPECFG); | ||
571 | |||
572 | r8a66597_write(r8a66597, (info->buf_bsize << 10) | (info->bufnum), | ||
573 | PIPEBUF); | ||
574 | r8a66597_write(r8a66597, make_devsel(info->address) | info->maxpacket, | ||
575 | PIPEMAXP); | ||
576 | if (info->interval) | ||
577 | info->interval--; | ||
578 | r8a66597_write(r8a66597, info->interval, PIPEPERI); | ||
579 | } | ||
580 | |||
581 | |||
582 | |||
583 | /* this function must be called with interrupt disabled */ | ||
584 | static void pipe_setting(struct r8a66597 *r8a66597, struct r8a66597_td *td) | ||
585 | { | ||
586 | struct r8a66597_pipe_info *info; | ||
587 | struct urb *urb = td->urb; | ||
588 | |||
589 | if (td->pipenum > 0) { | ||
590 | info = &td->pipe->info; | ||
591 | cfifo_change(r8a66597, 0); | ||
592 | pipe_buffer_setting(r8a66597, info); | ||
593 | |||
594 | if (!usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe), | ||
595 | usb_pipeout(urb->pipe)) && | ||
596 | !usb_pipecontrol(urb->pipe)) { | ||
597 | r8a66597_pipe_toggle(r8a66597, td->pipe, 0); | ||
598 | pipe_toggle_set(r8a66597, td->pipe, urb, 0); | ||
599 | clear_all_buffer(r8a66597, td->pipe); | ||
600 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), | ||
601 | usb_pipeout(urb->pipe), 1); | ||
602 | } | ||
603 | pipe_toggle_restore(r8a66597, td->pipe, urb); | ||
604 | } | ||
605 | } | ||
606 | |||
607 | /* this function must be called with interrupt disabled */ | ||
608 | static u16 get_empty_pipenum(struct r8a66597 *r8a66597, | ||
609 | struct usb_endpoint_descriptor *ep) | ||
610 | { | ||
611 | u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min; | ||
612 | |||
613 | memset(array, 0, sizeof(array)); | ||
614 | switch(ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { | ||
615 | case USB_ENDPOINT_XFER_BULK: | ||
616 | if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | ||
617 | array[i++] = 4; | ||
618 | else { | ||
619 | array[i++] = 3; | ||
620 | array[i++] = 5; | ||
621 | } | ||
622 | break; | ||
623 | case USB_ENDPOINT_XFER_INT: | ||
624 | if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) { | ||
625 | array[i++] = 6; | ||
626 | array[i++] = 7; | ||
627 | array[i++] = 8; | ||
628 | } else | ||
629 | array[i++] = 9; | ||
630 | break; | ||
631 | case USB_ENDPOINT_XFER_ISOC: | ||
632 | if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | ||
633 | array[i++] = 2; | ||
634 | else | ||
635 | array[i++] = 1; | ||
636 | break; | ||
637 | default: | ||
638 | err("Illegal type"); | ||
639 | return 0; | ||
640 | } | ||
641 | |||
642 | i = 1; | ||
643 | min = array[0]; | ||
644 | while (array[i] != 0) { | ||
645 | if (r8a66597->pipe_cnt[min] > r8a66597->pipe_cnt[array[i]]) | ||
646 | min = array[i]; | ||
647 | i++; | ||
648 | } | ||
649 | |||
650 | return min; | ||
651 | } | ||
652 | |||
653 | static u16 get_r8a66597_type(__u8 type) | ||
654 | { | ||
655 | u16 r8a66597_type; | ||
656 | |||
657 | switch(type) { | ||
658 | case USB_ENDPOINT_XFER_BULK: | ||
659 | r8a66597_type = R8A66597_BULK; | ||
660 | break; | ||
661 | case USB_ENDPOINT_XFER_INT: | ||
662 | r8a66597_type = R8A66597_INT; | ||
663 | break; | ||
664 | case USB_ENDPOINT_XFER_ISOC: | ||
665 | r8a66597_type = R8A66597_ISO; | ||
666 | break; | ||
667 | default: | ||
668 | err("Illegal type"); | ||
669 | r8a66597_type = 0x0000; | ||
670 | break; | ||
671 | } | ||
672 | |||
673 | return r8a66597_type; | ||
674 | } | ||
675 | |||
676 | static u16 get_bufnum(u16 pipenum) | ||
677 | { | ||
678 | u16 bufnum = 0; | ||
679 | |||
680 | if (pipenum == 0) | ||
681 | bufnum = 0; | ||
682 | else if (check_bulk_or_isoc(pipenum)) | ||
683 | bufnum = 8 + (pipenum - 1) * R8A66597_BUF_BSIZE*2; | ||
684 | else if (check_interrupt(pipenum)) | ||
685 | bufnum = 4 + (pipenum - 6); | ||
686 | else | ||
687 | err("Illegal pipenum (%d)", pipenum); | ||
688 | |||
689 | return bufnum; | ||
690 | } | ||
691 | |||
692 | static u16 get_buf_bsize(u16 pipenum) | ||
693 | { | ||
694 | u16 buf_bsize = 0; | ||
695 | |||
696 | if (pipenum == 0) | ||
697 | buf_bsize = 3; | ||
698 | else if (check_bulk_or_isoc(pipenum)) | ||
699 | buf_bsize = R8A66597_BUF_BSIZE - 1; | ||
700 | else if (check_interrupt(pipenum)) | ||
701 | buf_bsize = 0; | ||
702 | else | ||
703 | err("Illegal pipenum (%d)", pipenum); | ||
704 | |||
705 | return buf_bsize; | ||
706 | } | ||
707 | |||
708 | /* this function must be called with interrupt disabled */ | ||
709 | static void enable_r8a66597_pipe_dma(struct r8a66597 *r8a66597, | ||
710 | struct r8a66597_device *dev, | ||
711 | struct r8a66597_pipe *pipe, | ||
712 | struct urb *urb) | ||
713 | { | ||
714 | int i; | ||
715 | struct r8a66597_pipe_info *info = &pipe->info; | ||
716 | |||
717 | if ((pipe->info.pipenum != 0) && (info->type != R8A66597_INT)) { | ||
718 | for (i = 0; i < R8A66597_MAX_DMA_CHANNEL; i++) { | ||
719 | if ((r8a66597->dma_map & (1 << i)) != 0) | ||
720 | continue; | ||
721 | |||
722 | info("address %d, EndpointAddress 0x%02x use DMA FIFO", | ||
723 | usb_pipedevice(urb->pipe), | ||
724 | info->dir_in ? USB_ENDPOINT_DIR_MASK + info->epnum | ||
725 | : info->epnum); | ||
726 | |||
727 | r8a66597->dma_map |= 1 << i; | ||
728 | dev->dma_map |= 1 << i; | ||
729 | set_pipe_reg_addr(pipe, i); | ||
730 | |||
731 | cfifo_change(r8a66597, 0); | ||
732 | r8a66597_mdfy(r8a66597, MBW | pipe->info.pipenum, | ||
733 | MBW | CURPIPE, pipe->fifosel); | ||
734 | |||
735 | r8a66597_reg_wait(r8a66597, pipe->fifosel, CURPIPE, | ||
736 | pipe->info.pipenum); | ||
737 | r8a66597_bset(r8a66597, BCLR, pipe->fifoctr); | ||
738 | break; | ||
739 | } | ||
740 | } | ||
741 | } | ||
742 | |||
743 | /* this function must be called with interrupt disabled */ | ||
744 | static void enable_r8a66597_pipe(struct r8a66597 *r8a66597, struct urb *urb, | ||
745 | struct usb_host_endpoint *hep, | ||
746 | struct r8a66597_pipe_info *info) | ||
747 | { | ||
748 | struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb); | ||
749 | struct r8a66597_pipe *pipe = hep->hcpriv; | ||
750 | |||
751 | dbg("enable_pipe:"); | ||
752 | |||
753 | pipe->info = *info; | ||
754 | set_pipe_reg_addr(pipe, R8A66597_PIPE_NO_DMA); | ||
755 | r8a66597->pipe_cnt[pipe->info.pipenum]++; | ||
756 | dev->pipe_cnt[pipe->info.pipenum]++; | ||
757 | |||
758 | enable_r8a66597_pipe_dma(r8a66597, dev, pipe, urb); | ||
759 | } | ||
760 | |||
761 | /* this function must be called with interrupt disabled */ | ||
762 | static void force_dequeue(struct r8a66597 *r8a66597, u16 pipenum, u16 address) | ||
763 | { | ||
764 | struct r8a66597_td *td, *next; | ||
765 | struct urb *urb; | ||
766 | struct list_head *list = &r8a66597->pipe_queue[pipenum]; | ||
767 | |||
768 | if (list_empty(list)) | ||
769 | return; | ||
770 | |||
771 | list_for_each_entry_safe(td, next, list, queue) { | ||
772 | if (!td) | ||
773 | continue; | ||
774 | if (td->address != address) | ||
775 | continue; | ||
776 | |||
777 | urb = td->urb; | ||
778 | list_del(&td->queue); | ||
779 | kfree(td); | ||
780 | |||
781 | if (urb) { | ||
782 | urb->status = -ENODEV; | ||
783 | urb->hcpriv = NULL; | ||
784 | spin_unlock(&r8a66597->lock); | ||
785 | usb_hcd_giveback_urb(r8a66597_to_hcd(r8a66597), urb); | ||
786 | spin_lock(&r8a66597->lock); | ||
787 | } | ||
788 | break; | ||
789 | } | ||
790 | } | ||
791 | |||
792 | /* this function must be called with interrupt disabled */ | ||
793 | static void disable_r8a66597_pipe_all(struct r8a66597 *r8a66597, | ||
794 | struct r8a66597_device *dev) | ||
795 | { | ||
796 | int check_ep0 = 0; | ||
797 | u16 pipenum; | ||
798 | |||
799 | if (!dev) | ||
800 | return; | ||
801 | |||
802 | for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { | ||
803 | if (!dev->pipe_cnt[pipenum]) | ||
804 | continue; | ||
805 | |||
806 | if (!check_ep0) { | ||
807 | check_ep0 = 1; | ||
808 | force_dequeue(r8a66597, 0, dev->address); | ||
809 | } | ||
810 | |||
811 | r8a66597->pipe_cnt[pipenum] -= dev->pipe_cnt[pipenum]; | ||
812 | dev->pipe_cnt[pipenum] = 0; | ||
813 | force_dequeue(r8a66597, pipenum, dev->address); | ||
814 | } | ||
815 | |||
816 | dbg("disable_pipe"); | ||
817 | |||
818 | r8a66597->dma_map &= ~(dev->dma_map); | ||
819 | dev->dma_map = 0; | ||
820 | } | ||
821 | |||
822 | /* this function must be called with interrupt disabled */ | ||
823 | static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb, | ||
824 | struct usb_host_endpoint *hep, | ||
825 | struct usb_endpoint_descriptor *ep) | ||
826 | { | ||
827 | struct r8a66597_pipe_info info; | ||
828 | |||
829 | info.pipenum = get_empty_pipenum(r8a66597, ep); | ||
830 | info.address = get_urb_to_r8a66597_addr(r8a66597, urb); | ||
831 | info.epnum = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; | ||
832 | info.maxpacket = ep->wMaxPacketSize; | ||
833 | info.type = get_r8a66597_type(ep->bmAttributes | ||
834 | & USB_ENDPOINT_XFERTYPE_MASK); | ||
835 | info.bufnum = get_bufnum(info.pipenum); | ||
836 | info.buf_bsize = get_buf_bsize(info.pipenum); | ||
837 | info.interval = ep->bInterval; | ||
838 | if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | ||
839 | info.dir_in = 1; | ||
840 | else | ||
841 | info.dir_in = 0; | ||
842 | |||
843 | enable_r8a66597_pipe(r8a66597, urb, hep, &info); | ||
844 | } | ||
845 | |||
846 | static void init_pipe_config(struct r8a66597 *r8a66597, struct urb *urb) | ||
847 | { | ||
848 | struct r8a66597_device *dev; | ||
849 | |||
850 | dev = get_urb_to_r8a66597_dev(r8a66597, urb); | ||
851 | dev->state = USB_STATE_CONFIGURED; | ||
852 | } | ||
853 | |||
854 | static void pipe_irq_enable(struct r8a66597 *r8a66597, struct urb *urb, | ||
855 | u16 pipenum) | ||
856 | { | ||
857 | if (pipenum == 0 && usb_pipeout(urb->pipe)) | ||
858 | enable_irq_empty(r8a66597, pipenum); | ||
859 | else | ||
860 | enable_irq_ready(r8a66597, pipenum); | ||
861 | |||
862 | if (!usb_pipeisoc(urb->pipe)) | ||
863 | enable_irq_nrdy(r8a66597, pipenum); | ||
864 | } | ||
865 | |||
866 | static void pipe_irq_disable(struct r8a66597 *r8a66597, u16 pipenum) | ||
867 | { | ||
868 | disable_irq_ready(r8a66597, pipenum); | ||
869 | disable_irq_nrdy(r8a66597, pipenum); | ||
870 | } | ||
871 | |||
872 | /* this function must be called with interrupt disabled */ | ||
873 | static void r8a66597_usb_preconnect(struct r8a66597 *r8a66597, int port) | ||
874 | { | ||
875 | r8a66597->root_hub[port].port |= (1 << USB_PORT_FEAT_CONNECTION) | ||
876 | | (1 << USB_PORT_FEAT_C_CONNECTION); | ||
877 | r8a66597_write(r8a66597, (u16)~DTCH, get_intsts_reg(port)); | ||
878 | r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port)); | ||
879 | } | ||
880 | |||
881 | /* this function must be called with interrupt disabled */ | ||
882 | static void r8a66597_usb_connect(struct r8a66597 *r8a66597, int port) | ||
883 | { | ||
884 | u16 speed = get_rh_usb_speed(r8a66597, port); | ||
885 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; | ||
886 | |||
887 | if (speed == HSMODE) | ||
888 | rh->port |= (1 << USB_PORT_FEAT_HIGHSPEED); | ||
889 | else if (speed == LSMODE) | ||
890 | rh->port |= (1 << USB_PORT_FEAT_LOWSPEED); | ||
891 | |||
892 | rh->port &= ~(1 << USB_PORT_FEAT_RESET); | ||
893 | rh->port |= 1 << USB_PORT_FEAT_ENABLE; | ||
894 | } | ||
895 | |||
896 | /* this function must be called with interrupt disabled */ | ||
897 | static void r8a66597_usb_disconnect(struct r8a66597 *r8a66597, int port) | ||
898 | { | ||
899 | struct r8a66597_device *dev = r8a66597->root_hub[port].dev; | ||
900 | |||
901 | r8a66597->root_hub[port].port &= ~(1 << USB_PORT_FEAT_CONNECTION); | ||
902 | r8a66597->root_hub[port].port |= (1 << USB_PORT_FEAT_C_CONNECTION); | ||
903 | |||
904 | disable_r8a66597_pipe_all(r8a66597, dev); | ||
905 | free_usb_address(r8a66597, dev); | ||
906 | |||
907 | r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port)); | ||
908 | } | ||
909 | |||
910 | /* this function must be called with interrupt disabled */ | ||
911 | static void prepare_setup_packet(struct r8a66597 *r8a66597, | ||
912 | struct r8a66597_td *td) | ||
913 | { | ||
914 | int i; | ||
915 | u16 *p = (u16 *)td->urb->setup_packet; | ||
916 | unsigned long setup_addr = USBREQ; | ||
917 | |||
918 | r8a66597_write(r8a66597, make_devsel(td->address) | td->maxpacket, | ||
919 | DCPMAXP); | ||
920 | r8a66597_write(r8a66597, (u16)~(SIGN | SACK), INTSTS1); | ||
921 | |||
922 | for (i = 0; i < 4; i++) { | ||
923 | r8a66597_write(r8a66597, p[i], setup_addr); | ||
924 | setup_addr += 2; | ||
925 | } | ||
926 | r8a66597_write(r8a66597, SUREQ, DCPCTR); | ||
927 | } | ||
928 | |||
929 | /* this function must be called with interrupt disabled */ | ||
930 | static void prepare_packet_read(struct r8a66597 *r8a66597, | ||
931 | struct r8a66597_td *td) | ||
932 | { | ||
933 | struct urb *urb = td->urb; | ||
934 | |||
935 | if (usb_pipecontrol(urb->pipe)) { | ||
936 | r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG); | ||
937 | r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL); | ||
938 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); | ||
939 | if (urb->actual_length == 0) { | ||
940 | r8a66597_pipe_toggle(r8a66597, td->pipe, 1); | ||
941 | r8a66597_write(r8a66597, BCLR, CFIFOCTR); | ||
942 | } | ||
943 | pipe_irq_disable(r8a66597, td->pipenum); | ||
944 | pipe_start(r8a66597, td->pipe); | ||
945 | pipe_irq_enable(r8a66597, urb, td->pipenum); | ||
946 | } else { | ||
947 | if (urb->actual_length == 0) { | ||
948 | pipe_irq_disable(r8a66597, td->pipenum); | ||
949 | pipe_setting(r8a66597, td); | ||
950 | pipe_stop(r8a66597, td->pipe); | ||
951 | r8a66597_write(r8a66597, (u16)~(1 << td->pipenum), | ||
952 | BRDYSTS); | ||
953 | |||
954 | if (td->pipe->pipetre) { | ||
955 | r8a66597_write(r8a66597, TRCLR, | ||
956 | td->pipe->pipetre); | ||
957 | r8a66597_write(r8a66597, | ||
958 | (urb->transfer_buffer_length | ||
959 | + td->maxpacket - 1) | ||
960 | / td->maxpacket, | ||
961 | td->pipe->pipetrn); | ||
962 | r8a66597_bset(r8a66597, TRENB, | ||
963 | td->pipe->pipetre); | ||
964 | } | ||
965 | |||
966 | pipe_start(r8a66597, td->pipe); | ||
967 | pipe_irq_enable(r8a66597, urb, td->pipenum); | ||
968 | } | ||
969 | } | ||
970 | } | ||
971 | |||
972 | /* this function must be called with interrupt disabled */ | ||
973 | static void prepare_packet_write(struct r8a66597 *r8a66597, | ||
974 | struct r8a66597_td *td) | ||
975 | { | ||
976 | u16 tmp; | ||
977 | struct urb *urb = td->urb; | ||
978 | |||
979 | if (usb_pipecontrol(urb->pipe)) { | ||
980 | pipe_stop(r8a66597, td->pipe); | ||
981 | r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG); | ||
982 | r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL); | ||
983 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); | ||
984 | if (urb->actual_length == 0) { | ||
985 | r8a66597_pipe_toggle(r8a66597, td->pipe, 1); | ||
986 | r8a66597_write(r8a66597, BCLR, CFIFOCTR); | ||
987 | } | ||
988 | } else { | ||
989 | if (urb->actual_length == 0) | ||
990 | pipe_setting(r8a66597, td); | ||
991 | if (td->pipe->pipetre) | ||
992 | r8a66597_bclr(r8a66597, TRENB, td->pipe->pipetre); | ||
993 | } | ||
994 | r8a66597_write(r8a66597, (u16)~(1 << td->pipenum), BRDYSTS); | ||
995 | |||
996 | fifo_change_from_pipe(r8a66597, td->pipe); | ||
997 | tmp = r8a66597_read(r8a66597, td->pipe->fifoctr); | ||
998 | if (unlikely((tmp & FRDY) == 0)) | ||
999 | pipe_irq_enable(r8a66597, urb, td->pipenum); | ||
1000 | else | ||
1001 | packet_write(r8a66597, td->pipenum); | ||
1002 | pipe_start(r8a66597, td->pipe); | ||
1003 | } | ||
1004 | |||
1005 | /* this function must be called with interrupt disabled */ | ||
1006 | static void prepare_status_packet(struct r8a66597 *r8a66597, | ||
1007 | struct r8a66597_td *td) | ||
1008 | { | ||
1009 | struct urb *urb = td->urb; | ||
1010 | |||
1011 | r8a66597_pipe_toggle(r8a66597, td->pipe, 1); | ||
1012 | |||
1013 | if (urb->setup_packet[0] & USB_ENDPOINT_DIR_MASK) { | ||
1014 | r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG); | ||
1015 | r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL); | ||
1016 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); | ||
1017 | r8a66597_write(r8a66597, BVAL | BCLR, CFIFOCTR); | ||
1018 | r8a66597_write(r8a66597, (u16)~BEMP0, BEMPSTS); | ||
1019 | enable_irq_empty(r8a66597, 0); | ||
1020 | } else { | ||
1021 | r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG); | ||
1022 | r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL); | ||
1023 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); | ||
1024 | r8a66597_write(r8a66597, BCLR, CFIFOCTR); | ||
1025 | r8a66597_write(r8a66597, (u16)~BRDY0, BRDYSTS); | ||
1026 | r8a66597_write(r8a66597, (u16)~BEMP0, BEMPSTS); | ||
1027 | enable_irq_ready(r8a66597, 0); | ||
1028 | } | ||
1029 | enable_irq_nrdy(r8a66597, 0); | ||
1030 | pipe_start(r8a66597, td->pipe); | ||
1031 | } | ||
1032 | |||
1033 | /* this function must be called with interrupt disabled */ | ||
1034 | static int start_transfer(struct r8a66597 *r8a66597, struct r8a66597_td *td) | ||
1035 | { | ||
1036 | BUG_ON(!td); | ||
1037 | |||
1038 | switch (td->type) { | ||
1039 | case USB_PID_SETUP: | ||
1040 | if (td->urb->setup_packet[1] == USB_REQ_SET_ADDRESS) { | ||
1041 | td->set_address = 1; | ||
1042 | td->urb->setup_packet[2] = alloc_usb_address(r8a66597, | ||
1043 | td->urb); | ||
1044 | if (td->urb->setup_packet[2] == 0) | ||
1045 | return -EPIPE; | ||
1046 | } | ||
1047 | prepare_setup_packet(r8a66597, td); | ||
1048 | break; | ||
1049 | case USB_PID_IN: | ||
1050 | prepare_packet_read(r8a66597, td); | ||
1051 | break; | ||
1052 | case USB_PID_OUT: | ||
1053 | prepare_packet_write(r8a66597, td); | ||
1054 | break; | ||
1055 | case USB_PID_ACK: | ||
1056 | prepare_status_packet(r8a66597, td); | ||
1057 | break; | ||
1058 | default: | ||
1059 | err("invalid type."); | ||
1060 | break; | ||
1061 | } | ||
1062 | |||
1063 | return 0; | ||
1064 | } | ||
1065 | |||
1066 | static int check_transfer_finish(struct r8a66597_td *td, struct urb *urb) | ||
1067 | { | ||
1068 | if (usb_pipeisoc(urb->pipe)) { | ||
1069 | if (urb->number_of_packets == td->iso_cnt) | ||
1070 | return 1; | ||
1071 | } | ||
1072 | |||
1073 | /* control or bulk or interrupt */ | ||
1074 | if ((urb->transfer_buffer_length <= urb->actual_length) || | ||
1075 | (td->short_packet) || (td->zero_packet)) | ||
1076 | return 1; | ||
1077 | |||
1078 | return 0; | ||
1079 | } | ||
1080 | |||
1081 | /* this function must be called with interrupt disabled */ | ||
1082 | static void set_td_timer(struct r8a66597 *r8a66597, struct r8a66597_td *td) | ||
1083 | { | ||
1084 | unsigned long time; | ||
1085 | |||
1086 | BUG_ON(!td); | ||
1087 | |||
1088 | if (!list_empty(&r8a66597->pipe_queue[td->pipenum]) && | ||
1089 | !usb_pipecontrol(td->urb->pipe) && usb_pipein(td->urb->pipe)) { | ||
1090 | r8a66597->timeout_map |= 1 << td->pipenum; | ||
1091 | switch (usb_pipetype(td->urb->pipe)) { | ||
1092 | case PIPE_INTERRUPT: | ||
1093 | case PIPE_ISOCHRONOUS: | ||
1094 | time = 30; | ||
1095 | break; | ||
1096 | default: | ||
1097 | time = 300; | ||
1098 | break; | ||
1099 | } | ||
1100 | |||
1101 | mod_timer(&r8a66597->td_timer[td->pipenum], | ||
1102 | jiffies + msecs_to_jiffies(time)); | ||
1103 | } | ||
1104 | } | ||
1105 | |||
1106 | /* this function must be called with interrupt disabled */ | ||
1107 | static void done(struct r8a66597 *r8a66597, struct r8a66597_td *td, | ||
1108 | u16 pipenum, struct urb *urb) | ||
1109 | { | ||
1110 | int restart = 0; | ||
1111 | struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597); | ||
1112 | |||
1113 | r8a66597->timeout_map &= ~(1 << pipenum); | ||
1114 | |||
1115 | if (likely(td)) { | ||
1116 | if (td->set_address && urb->status != 0) | ||
1117 | r8a66597->address_map &= ~(1 << urb->setup_packet[2]); | ||
1118 | |||
1119 | pipe_toggle_save(r8a66597, td->pipe, urb); | ||
1120 | list_del(&td->queue); | ||
1121 | kfree(td); | ||
1122 | } | ||
1123 | |||
1124 | if (!list_empty(&r8a66597->pipe_queue[pipenum])) | ||
1125 | restart = 1; | ||
1126 | |||
1127 | if (likely(urb)) { | ||
1128 | if (usb_pipeisoc(urb->pipe)) | ||
1129 | urb->start_frame = r8a66597_get_frame(hcd); | ||
1130 | |||
1131 | urb->hcpriv = NULL; | ||
1132 | spin_unlock(&r8a66597->lock); | ||
1133 | usb_hcd_giveback_urb(hcd, urb); | ||
1134 | spin_lock(&r8a66597->lock); | ||
1135 | } | ||
1136 | |||
1137 | if (restart) { | ||
1138 | td = r8a66597_get_td(r8a66597, pipenum); | ||
1139 | if (unlikely(!td)) | ||
1140 | return; | ||
1141 | |||
1142 | start_transfer(r8a66597, td); | ||
1143 | set_td_timer(r8a66597, td); | ||
1144 | } | ||
1145 | } | ||
1146 | |||
1147 | /* this function must be called with interrupt disabled */ | ||
1148 | static void finish_request(struct r8a66597 *r8a66597, struct r8a66597_td *td, | ||
1149 | u16 pipenum, struct urb *urb) | ||
1150 | __releases(r8a66597->lock) __acquires(r8a66597->lock) | ||
1151 | { | ||
1152 | done(r8a66597, td, pipenum, urb); | ||
1153 | } | ||
1154 | |||
1155 | static void packet_read(struct r8a66597 *r8a66597, u16 pipenum) | ||
1156 | { | ||
1157 | u16 tmp; | ||
1158 | int rcv_len, bufsize, urb_len, size; | ||
1159 | u16 *buf; | ||
1160 | struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum); | ||
1161 | struct urb *urb; | ||
1162 | int finish = 0; | ||
1163 | |||
1164 | if (unlikely(!td)) | ||
1165 | return; | ||
1166 | urb = td->urb; | ||
1167 | |||
1168 | fifo_change_from_pipe(r8a66597, td->pipe); | ||
1169 | tmp = r8a66597_read(r8a66597, td->pipe->fifoctr); | ||
1170 | if (unlikely((tmp & FRDY) == 0)) { | ||
1171 | urb->status = -EPIPE; | ||
1172 | pipe_stop(r8a66597, td->pipe); | ||
1173 | pipe_irq_disable(r8a66597, pipenum); | ||
1174 | err("in fifo not ready (%d)", pipenum); | ||
1175 | finish_request(r8a66597, td, pipenum, td->urb); | ||
1176 | return; | ||
1177 | } | ||
1178 | |||
1179 | /* prepare parameters */ | ||
1180 | rcv_len = tmp & DTLN; | ||
1181 | bufsize = td->maxpacket; | ||
1182 | if (usb_pipeisoc(urb->pipe)) { | ||
1183 | buf = (u16 *)(urb->transfer_buffer + | ||
1184 | urb->iso_frame_desc[td->iso_cnt].offset); | ||
1185 | urb_len = urb->iso_frame_desc[td->iso_cnt].length; | ||
1186 | } else { | ||
1187 | buf = (void *)urb->transfer_buffer + urb->actual_length; | ||
1188 | urb_len = urb->transfer_buffer_length - urb->actual_length; | ||
1189 | } | ||
1190 | if (rcv_len < bufsize) | ||
1191 | size = min(rcv_len, urb_len); | ||
1192 | else | ||
1193 | size = min(bufsize, urb_len); | ||
1194 | |||
1195 | /* update parameters */ | ||
1196 | urb->actual_length += size; | ||
1197 | if (rcv_len == 0) | ||
1198 | td->zero_packet = 1; | ||
1199 | if ((size % td->maxpacket) > 0) { | ||
1200 | td->short_packet = 1; | ||
1201 | if (urb->transfer_buffer_length != urb->actual_length && | ||
1202 | urb->transfer_flags & URB_SHORT_NOT_OK) | ||
1203 | td->urb->status = -EREMOTEIO; | ||
1204 | } | ||
1205 | if (usb_pipeisoc(urb->pipe)) { | ||
1206 | urb->iso_frame_desc[td->iso_cnt].actual_length = size; | ||
1207 | urb->iso_frame_desc[td->iso_cnt].status = 0; | ||
1208 | td->iso_cnt++; | ||
1209 | } | ||
1210 | |||
1211 | /* check transfer finish */ | ||
1212 | if (check_transfer_finish(td, urb)) { | ||
1213 | pipe_stop(r8a66597, td->pipe); | ||
1214 | pipe_irq_disable(r8a66597, pipenum); | ||
1215 | finish = 1; | ||
1216 | } | ||
1217 | |||
1218 | /* read fifo */ | ||
1219 | if (urb->transfer_buffer) { | ||
1220 | if (size == 0) | ||
1221 | r8a66597_write(r8a66597, BCLR, td->pipe->fifoctr); | ||
1222 | else | ||
1223 | r8a66597_read_fifo(r8a66597, td->pipe->fifoaddr, | ||
1224 | buf, size); | ||
1225 | } | ||
1226 | |||
1227 | if (finish && pipenum != 0) { | ||
1228 | if (td->urb->status == -EINPROGRESS) | ||
1229 | td->urb->status = 0; | ||
1230 | finish_request(r8a66597, td, pipenum, urb); | ||
1231 | } | ||
1232 | } | ||
1233 | |||
1234 | static void packet_write(struct r8a66597 *r8a66597, u16 pipenum) | ||
1235 | { | ||
1236 | u16 tmp; | ||
1237 | int bufsize, size; | ||
1238 | u16 *buf; | ||
1239 | struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum); | ||
1240 | struct urb *urb; | ||
1241 | |||
1242 | if (unlikely(!td)) | ||
1243 | return; | ||
1244 | urb = td->urb; | ||
1245 | |||
1246 | fifo_change_from_pipe(r8a66597, td->pipe); | ||
1247 | tmp = r8a66597_read(r8a66597, td->pipe->fifoctr); | ||
1248 | if (unlikely((tmp & FRDY) == 0)) { | ||
1249 | urb->status = -EPIPE; | ||
1250 | pipe_stop(r8a66597, td->pipe); | ||
1251 | pipe_irq_disable(r8a66597, pipenum); | ||
1252 | err("out write fifo not ready. (%d)", pipenum); | ||
1253 | finish_request(r8a66597, td, pipenum, td->urb); | ||
1254 | return; | ||
1255 | } | ||
1256 | |||
1257 | /* prepare parameters */ | ||
1258 | bufsize = td->maxpacket; | ||
1259 | if (usb_pipeisoc(urb->pipe)) { | ||
1260 | buf = (u16 *)(urb->transfer_buffer + | ||
1261 | urb->iso_frame_desc[td->iso_cnt].offset); | ||
1262 | size = min(bufsize, | ||
1263 | (int)urb->iso_frame_desc[td->iso_cnt].length); | ||
1264 | } else { | ||
1265 | buf = (u16 *)(urb->transfer_buffer + urb->actual_length); | ||
1266 | size = min((int)bufsize, | ||
1267 | urb->transfer_buffer_length - urb->actual_length); | ||
1268 | } | ||
1269 | |||
1270 | /* write fifo */ | ||
1271 | if (pipenum > 0) | ||
1272 | r8a66597_write(r8a66597, (u16)~(1 << pipenum), BEMPSTS); | ||
1273 | if (urb->transfer_buffer) { | ||
1274 | r8a66597_write_fifo(r8a66597, td->pipe->fifoaddr, buf, size); | ||
1275 | if (!usb_pipebulk(urb->pipe) || td->maxpacket != size) | ||
1276 | r8a66597_write(r8a66597, BVAL, td->pipe->fifoctr); | ||
1277 | } | ||
1278 | |||
1279 | /* update parameters */ | ||
1280 | urb->actual_length += size; | ||
1281 | if (usb_pipeisoc(urb->pipe)) { | ||
1282 | urb->iso_frame_desc[td->iso_cnt].actual_length = size; | ||
1283 | urb->iso_frame_desc[td->iso_cnt].status = 0; | ||
1284 | td->iso_cnt++; | ||
1285 | } | ||
1286 | |||
1287 | /* check transfer finish */ | ||
1288 | if (check_transfer_finish(td, urb)) { | ||
1289 | disable_irq_ready(r8a66597, pipenum); | ||
1290 | enable_irq_empty(r8a66597, pipenum); | ||
1291 | if (!usb_pipeisoc(urb->pipe)) | ||
1292 | enable_irq_nrdy(r8a66597, pipenum); | ||
1293 | } else | ||
1294 | pipe_irq_enable(r8a66597, urb, pipenum); | ||
1295 | } | ||
1296 | |||
1297 | |||
1298 | static void check_next_phase(struct r8a66597 *r8a66597) | ||
1299 | { | ||
1300 | struct r8a66597_td *td = r8a66597_get_td(r8a66597, 0); | ||
1301 | struct urb *urb; | ||
1302 | u8 finish = 0; | ||
1303 | |||
1304 | if (unlikely(!td)) | ||
1305 | return; | ||
1306 | urb = td->urb; | ||
1307 | |||
1308 | switch (td->type) { | ||
1309 | case USB_PID_IN: | ||
1310 | case USB_PID_OUT: | ||
1311 | if (urb->status != -EINPROGRESS) { | ||
1312 | finish = 1; | ||
1313 | break; | ||
1314 | } | ||
1315 | if (check_transfer_finish(td, urb)) | ||
1316 | td->type = USB_PID_ACK; | ||
1317 | break; | ||
1318 | case USB_PID_SETUP: | ||
1319 | if (urb->status != -EINPROGRESS) | ||
1320 | finish = 1; | ||
1321 | else if (urb->transfer_buffer_length == urb->actual_length) { | ||
1322 | td->type = USB_PID_ACK; | ||
1323 | urb->status = 0; | ||
1324 | } else if (usb_pipeout(urb->pipe)) | ||
1325 | td->type = USB_PID_OUT; | ||
1326 | else | ||
1327 | td->type = USB_PID_IN; | ||
1328 | break; | ||
1329 | case USB_PID_ACK: | ||
1330 | finish = 1; | ||
1331 | if (urb->status == -EINPROGRESS) | ||
1332 | urb->status = 0; | ||
1333 | break; | ||
1334 | } | ||
1335 | |||
1336 | if (finish) | ||
1337 | finish_request(r8a66597, td, 0, urb); | ||
1338 | else | ||
1339 | start_transfer(r8a66597, td); | ||
1340 | } | ||
1341 | |||
1342 | static void set_urb_error(struct r8a66597 *r8a66597, u16 pipenum) | ||
1343 | { | ||
1344 | struct r8a66597_td *td = r8a66597_get_td(r8a66597, pipenum); | ||
1345 | |||
1346 | if (td && td->urb) { | ||
1347 | u16 pid = r8a66597_read(r8a66597, td->pipe->pipectr) & PID; | ||
1348 | |||
1349 | if (pid == PID_NAK) | ||
1350 | td->urb->status = -ECONNRESET; | ||
1351 | else | ||
1352 | td->urb->status = -EPIPE; | ||
1353 | } | ||
1354 | } | ||
1355 | |||
1356 | static void irq_pipe_ready(struct r8a66597 *r8a66597) | ||
1357 | { | ||
1358 | u16 check; | ||
1359 | u16 pipenum; | ||
1360 | u16 mask; | ||
1361 | struct r8a66597_td *td; | ||
1362 | |||
1363 | mask = r8a66597_read(r8a66597, BRDYSTS) | ||
1364 | & r8a66597_read(r8a66597, BRDYENB); | ||
1365 | r8a66597_write(r8a66597, (u16)~mask, BRDYSTS); | ||
1366 | if (mask & BRDY0) { | ||
1367 | td = r8a66597_get_td(r8a66597, 0); | ||
1368 | if (td && td->type == USB_PID_IN) | ||
1369 | packet_read(r8a66597, 0); | ||
1370 | else | ||
1371 | pipe_irq_disable(r8a66597, 0); | ||
1372 | check_next_phase(r8a66597); | ||
1373 | } | ||
1374 | |||
1375 | for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { | ||
1376 | check = 1 << pipenum; | ||
1377 | if (mask & check) { | ||
1378 | td = r8a66597_get_td(r8a66597, pipenum); | ||
1379 | if (unlikely(!td)) | ||
1380 | continue; | ||
1381 | |||
1382 | if (td->type == USB_PID_IN) | ||
1383 | packet_read(r8a66597, pipenum); | ||
1384 | else if (td->type == USB_PID_OUT) | ||
1385 | packet_write(r8a66597, pipenum); | ||
1386 | } | ||
1387 | } | ||
1388 | } | ||
1389 | |||
1390 | static void irq_pipe_empty(struct r8a66597 *r8a66597) | ||
1391 | { | ||
1392 | u16 tmp; | ||
1393 | u16 check; | ||
1394 | u16 pipenum; | ||
1395 | u16 mask; | ||
1396 | struct r8a66597_td *td; | ||
1397 | |||
1398 | mask = r8a66597_read(r8a66597, BEMPSTS) | ||
1399 | & r8a66597_read(r8a66597, BEMPENB); | ||
1400 | r8a66597_write(r8a66597, (u16)~mask, BEMPSTS); | ||
1401 | if (mask & BEMP0) { | ||
1402 | cfifo_change(r8a66597, 0); | ||
1403 | td = r8a66597_get_td(r8a66597, 0); | ||
1404 | if (td && td->type != USB_PID_OUT) | ||
1405 | disable_irq_empty(r8a66597, 0); | ||
1406 | check_next_phase(r8a66597); | ||
1407 | } | ||
1408 | |||
1409 | for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { | ||
1410 | check = 1 << pipenum; | ||
1411 | if (mask & check) { | ||
1412 | struct r8a66597_td *td; | ||
1413 | td = r8a66597_get_td(r8a66597, pipenum); | ||
1414 | if (unlikely(!td)) | ||
1415 | continue; | ||
1416 | |||
1417 | tmp = r8a66597_read(r8a66597, td->pipe->pipectr); | ||
1418 | if ((tmp & INBUFM) == 0) { | ||
1419 | disable_irq_empty(r8a66597, pipenum); | ||
1420 | pipe_irq_disable(r8a66597, pipenum); | ||
1421 | if (td->urb->status == -EINPROGRESS) | ||
1422 | td->urb->status = 0; | ||
1423 | finish_request(r8a66597, td, pipenum, td->urb); | ||
1424 | } | ||
1425 | } | ||
1426 | } | ||
1427 | } | ||
1428 | |||
1429 | static void irq_pipe_nrdy(struct r8a66597 *r8a66597) | ||
1430 | { | ||
1431 | u16 check; | ||
1432 | u16 pipenum; | ||
1433 | u16 mask; | ||
1434 | |||
1435 | mask = r8a66597_read(r8a66597, NRDYSTS) | ||
1436 | & r8a66597_read(r8a66597, NRDYENB); | ||
1437 | r8a66597_write(r8a66597, (u16)~mask, NRDYSTS); | ||
1438 | if (mask & NRDY0) { | ||
1439 | cfifo_change(r8a66597, 0); | ||
1440 | set_urb_error(r8a66597, 0); | ||
1441 | pipe_irq_disable(r8a66597, 0); | ||
1442 | check_next_phase(r8a66597); | ||
1443 | } | ||
1444 | |||
1445 | for (pipenum = 1; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { | ||
1446 | check = 1 << pipenum; | ||
1447 | if (mask & check) { | ||
1448 | struct r8a66597_td *td; | ||
1449 | td = r8a66597_get_td(r8a66597, pipenum); | ||
1450 | if (unlikely(!td)) | ||
1451 | continue; | ||
1452 | |||
1453 | set_urb_error(r8a66597, pipenum); | ||
1454 | pipe_irq_disable(r8a66597, pipenum); | ||
1455 | pipe_stop(r8a66597, td->pipe); | ||
1456 | finish_request(r8a66597, td, pipenum, td->urb); | ||
1457 | } | ||
1458 | } | ||
1459 | } | ||
1460 | |||
1461 | static void start_root_hub_sampling(struct r8a66597 *r8a66597, int port) | ||
1462 | { | ||
1463 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; | ||
1464 | |||
1465 | rh->old_syssts = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST; | ||
1466 | rh->scount = R8A66597_MAX_SAMPLING; | ||
1467 | mod_timer(&r8a66597->rh_timer, jiffies + msecs_to_jiffies(50)); | ||
1468 | } | ||
1469 | |||
1470 | static irqreturn_t r8a66597_irq(struct usb_hcd *hcd) | ||
1471 | { | ||
1472 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); | ||
1473 | u16 intsts0, intsts1, intsts2; | ||
1474 | u16 intenb0, intenb1, intenb2; | ||
1475 | u16 mask0, mask1, mask2; | ||
1476 | |||
1477 | spin_lock(&r8a66597->lock); | ||
1478 | |||
1479 | intsts0 = r8a66597_read(r8a66597, INTSTS0); | ||
1480 | intsts1 = r8a66597_read(r8a66597, INTSTS1); | ||
1481 | intsts2 = r8a66597_read(r8a66597, INTSTS2); | ||
1482 | intenb0 = r8a66597_read(r8a66597, INTENB0); | ||
1483 | intenb1 = r8a66597_read(r8a66597, INTENB1); | ||
1484 | intenb2 = r8a66597_read(r8a66597, INTENB2); | ||
1485 | |||
1486 | mask2 = intsts2 & intenb2; | ||
1487 | mask1 = intsts1 & intenb1; | ||
1488 | mask0 = intsts0 & intenb0 & (BEMP | NRDY | BRDY); | ||
1489 | if (mask2) { | ||
1490 | if (mask2 & ATTCH) { | ||
1491 | r8a66597_write(r8a66597, (u16)~ATTCH, INTSTS2); | ||
1492 | r8a66597_bclr(r8a66597, ATTCHE, INTENB2); | ||
1493 | |||
1494 | /* start usb bus sampling */ | ||
1495 | start_root_hub_sampling(r8a66597, 1); | ||
1496 | } | ||
1497 | if (mask2 & DTCH) { | ||
1498 | r8a66597_write(r8a66597, (u16)~DTCH, INTSTS2); | ||
1499 | r8a66597_bclr(r8a66597, DTCHE, INTENB2); | ||
1500 | r8a66597_usb_disconnect(r8a66597, 1); | ||
1501 | } | ||
1502 | } | ||
1503 | |||
1504 | if (mask1) { | ||
1505 | if (mask1 & ATTCH) { | ||
1506 | r8a66597_write(r8a66597, (u16)~ATTCH, INTSTS1); | ||
1507 | r8a66597_bclr(r8a66597, ATTCHE, INTENB1); | ||
1508 | |||
1509 | /* start usb bus sampling */ | ||
1510 | start_root_hub_sampling(r8a66597, 0); | ||
1511 | } | ||
1512 | if (mask1 & DTCH) { | ||
1513 | r8a66597_write(r8a66597, (u16)~DTCH, INTSTS1); | ||
1514 | r8a66597_bclr(r8a66597, DTCHE, INTENB1); | ||
1515 | r8a66597_usb_disconnect(r8a66597, 0); | ||
1516 | } | ||
1517 | if (mask1 & SIGN) { | ||
1518 | r8a66597_write(r8a66597, (u16)~SIGN, INTSTS1); | ||
1519 | set_urb_error(r8a66597, 0); | ||
1520 | check_next_phase(r8a66597); | ||
1521 | } | ||
1522 | if (mask1 & SACK) { | ||
1523 | r8a66597_write(r8a66597, (u16)~SACK, INTSTS1); | ||
1524 | check_next_phase(r8a66597); | ||
1525 | } | ||
1526 | } | ||
1527 | if (mask0) { | ||
1528 | if (mask0 & BRDY) | ||
1529 | irq_pipe_ready(r8a66597); | ||
1530 | if (mask0 & BEMP) | ||
1531 | irq_pipe_empty(r8a66597); | ||
1532 | if (mask0 & NRDY) | ||
1533 | irq_pipe_nrdy(r8a66597); | ||
1534 | } | ||
1535 | |||
1536 | spin_unlock(&r8a66597->lock); | ||
1537 | return IRQ_HANDLED; | ||
1538 | } | ||
1539 | |||
1540 | /* this function must be called with interrupt disabled */ | ||
1541 | static void r8a66597_root_hub_control(struct r8a66597 *r8a66597, int port) | ||
1542 | { | ||
1543 | u16 tmp; | ||
1544 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; | ||
1545 | |||
1546 | if (rh->port & (1 << USB_PORT_FEAT_RESET)) { | ||
1547 | unsigned long dvstctr_reg = get_dvstctr_reg(port); | ||
1548 | |||
1549 | tmp = r8a66597_read(r8a66597, dvstctr_reg); | ||
1550 | if ((tmp & USBRST) == USBRST) { | ||
1551 | r8a66597_mdfy(r8a66597, UACT, USBRST | UACT, | ||
1552 | dvstctr_reg); | ||
1553 | mod_timer(&r8a66597->rh_timer, | ||
1554 | jiffies + msecs_to_jiffies(50)); | ||
1555 | } else | ||
1556 | r8a66597_usb_connect(r8a66597, port); | ||
1557 | } | ||
1558 | |||
1559 | if (rh->scount > 0) { | ||
1560 | tmp = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST; | ||
1561 | if (tmp == rh->old_syssts) { | ||
1562 | rh->scount--; | ||
1563 | if (rh->scount == 0) { | ||
1564 | if (tmp == FS_JSTS) { | ||
1565 | r8a66597_bset(r8a66597, HSE, | ||
1566 | get_syscfg_reg(port)); | ||
1567 | r8a66597_usb_preconnect(r8a66597, port); | ||
1568 | } else if (tmp == LS_JSTS) { | ||
1569 | r8a66597_bclr(r8a66597, HSE, | ||
1570 | get_syscfg_reg(port)); | ||
1571 | r8a66597_usb_preconnect(r8a66597, port); | ||
1572 | } else if (tmp == SE0) | ||
1573 | r8a66597_bset(r8a66597, ATTCHE, | ||
1574 | get_intenb_reg(port)); | ||
1575 | } else { | ||
1576 | mod_timer(&r8a66597->rh_timer, | ||
1577 | jiffies + msecs_to_jiffies(50)); | ||
1578 | } | ||
1579 | } else { | ||
1580 | rh->scount = R8A66597_MAX_SAMPLING; | ||
1581 | rh->old_syssts = tmp; | ||
1582 | mod_timer(&r8a66597->rh_timer, | ||
1583 | jiffies + msecs_to_jiffies(50)); | ||
1584 | } | ||
1585 | } | ||
1586 | } | ||
1587 | |||
1588 | static void r8a66597_td_timer(unsigned long _r8a66597) | ||
1589 | { | ||
1590 | struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597; | ||
1591 | unsigned long flags; | ||
1592 | u16 pipenum; | ||
1593 | struct r8a66597_td *td, *new_td = NULL; | ||
1594 | struct r8a66597_pipe *pipe; | ||
1595 | |||
1596 | spin_lock_irqsave(&r8a66597->lock, flags); | ||
1597 | for (pipenum = 0; pipenum < R8A66597_MAX_NUM_PIPE; pipenum++) { | ||
1598 | if (!(r8a66597->timeout_map & (1 << pipenum))) | ||
1599 | continue; | ||
1600 | if (timer_pending(&r8a66597->td_timer[pipenum])) | ||
1601 | continue; | ||
1602 | |||
1603 | td = r8a66597_get_td(r8a66597, pipenum); | ||
1604 | if (!td) { | ||
1605 | r8a66597->timeout_map &= ~(1 << pipenum); | ||
1606 | continue; | ||
1607 | } | ||
1608 | |||
1609 | if (td->urb->actual_length) { | ||
1610 | set_td_timer(r8a66597, td); | ||
1611 | break; | ||
1612 | } | ||
1613 | |||
1614 | pipe = td->pipe; | ||
1615 | pipe_stop(r8a66597, pipe); | ||
1616 | |||
1617 | new_td = td; | ||
1618 | do { | ||
1619 | list_move_tail(&new_td->queue, | ||
1620 | &r8a66597->pipe_queue[pipenum]); | ||
1621 | new_td = r8a66597_get_td(r8a66597, pipenum); | ||
1622 | if (!new_td) { | ||
1623 | new_td = td; | ||
1624 | break; | ||
1625 | } | ||
1626 | } while (td != new_td && td->address == new_td->address); | ||
1627 | |||
1628 | start_transfer(r8a66597, new_td); | ||
1629 | |||
1630 | if (td == new_td) | ||
1631 | r8a66597->timeout_map &= ~(1 << pipenum); | ||
1632 | else | ||
1633 | set_td_timer(r8a66597, new_td); | ||
1634 | break; | ||
1635 | } | ||
1636 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1637 | } | ||
1638 | |||
1639 | static void r8a66597_timer(unsigned long _r8a66597) | ||
1640 | { | ||
1641 | struct r8a66597 *r8a66597 = (struct r8a66597 *)_r8a66597; | ||
1642 | unsigned long flags; | ||
1643 | |||
1644 | spin_lock_irqsave(&r8a66597->lock, flags); | ||
1645 | |||
1646 | r8a66597_root_hub_control(r8a66597, 0); | ||
1647 | r8a66597_root_hub_control(r8a66597, 1); | ||
1648 | |||
1649 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1650 | } | ||
1651 | |||
1652 | static int check_pipe_config(struct r8a66597 *r8a66597, struct urb *urb) | ||
1653 | { | ||
1654 | struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb); | ||
1655 | |||
1656 | if (dev && dev->address && dev->state != USB_STATE_CONFIGURED && | ||
1657 | (urb->dev->state == USB_STATE_CONFIGURED)) | ||
1658 | return 1; | ||
1659 | else | ||
1660 | return 0; | ||
1661 | } | ||
1662 | |||
1663 | static int r8a66597_start(struct usb_hcd *hcd) | ||
1664 | { | ||
1665 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); | ||
1666 | int ret; | ||
1667 | |||
1668 | hcd->state = HC_STATE_RUNNING; | ||
1669 | if ((ret = enable_controller(r8a66597)) < 0) | ||
1670 | return ret; | ||
1671 | |||
1672 | return 0; | ||
1673 | } | ||
1674 | |||
1675 | static void r8a66597_stop(struct usb_hcd *hcd) | ||
1676 | { | ||
1677 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); | ||
1678 | |||
1679 | disable_controller(r8a66597); | ||
1680 | } | ||
1681 | |||
1682 | static void set_address_zero(struct r8a66597 *r8a66597, struct urb *urb) | ||
1683 | { | ||
1684 | unsigned int usb_address = usb_pipedevice(urb->pipe); | ||
1685 | u16 root_port, hub_port; | ||
1686 | |||
1687 | if (usb_address == 0) { | ||
1688 | get_port_number(urb->dev->devpath, | ||
1689 | &root_port, &hub_port); | ||
1690 | set_devadd_reg(r8a66597, 0, | ||
1691 | get_r8a66597_usb_speed(urb->dev->speed), | ||
1692 | get_parent_r8a66597_address(r8a66597, urb->dev), | ||
1693 | hub_port, root_port); | ||
1694 | } | ||
1695 | } | ||
1696 | |||
1697 | static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597, | ||
1698 | struct urb *urb, | ||
1699 | struct usb_host_endpoint *hep, | ||
1700 | gfp_t mem_flags) | ||
1701 | { | ||
1702 | struct r8a66597_td *td; | ||
1703 | u16 pipenum; | ||
1704 | |||
1705 | td = kzalloc(sizeof(struct r8a66597_td), mem_flags); | ||
1706 | if (td == NULL) | ||
1707 | return NULL; | ||
1708 | |||
1709 | pipenum = r8a66597_get_pipenum(urb, hep); | ||
1710 | td->pipenum = pipenum; | ||
1711 | td->pipe = hep->hcpriv; | ||
1712 | td->urb = urb; | ||
1713 | td->address = get_urb_to_r8a66597_addr(r8a66597, urb); | ||
1714 | td->maxpacket = usb_maxpacket(urb->dev, urb->pipe, | ||
1715 | !usb_pipein(urb->pipe)); | ||
1716 | if (usb_pipecontrol(urb->pipe)) | ||
1717 | td->type = USB_PID_SETUP; | ||
1718 | else if (usb_pipein(urb->pipe)) | ||
1719 | td->type = USB_PID_IN; | ||
1720 | else | ||
1721 | td->type = USB_PID_OUT; | ||
1722 | INIT_LIST_HEAD(&td->queue); | ||
1723 | |||
1724 | return td; | ||
1725 | } | ||
1726 | |||
1727 | static int r8a66597_urb_enqueue(struct usb_hcd *hcd, | ||
1728 | struct usb_host_endpoint *hep, | ||
1729 | struct urb *urb, | ||
1730 | gfp_t mem_flags) | ||
1731 | { | ||
1732 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); | ||
1733 | struct r8a66597_td *td = NULL; | ||
1734 | int ret = 0, request = 0; | ||
1735 | unsigned long flags; | ||
1736 | |||
1737 | spin_lock_irqsave(&r8a66597->lock, flags); | ||
1738 | if (!get_urb_to_r8a66597_dev(r8a66597, urb)) { | ||
1739 | ret = -ENODEV; | ||
1740 | goto error; | ||
1741 | } | ||
1742 | |||
1743 | if (!hep->hcpriv) { | ||
1744 | hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe), mem_flags); | ||
1745 | if (!hep->hcpriv) { | ||
1746 | ret = -ENOMEM; | ||
1747 | goto error; | ||
1748 | } | ||
1749 | set_pipe_reg_addr(hep->hcpriv, R8A66597_PIPE_NO_DMA); | ||
1750 | if (usb_pipeendpoint(urb->pipe)) | ||
1751 | init_pipe_info(r8a66597, urb, hep, &hep->desc); | ||
1752 | } | ||
1753 | |||
1754 | if (unlikely(check_pipe_config(r8a66597, urb))) | ||
1755 | init_pipe_config(r8a66597, urb); | ||
1756 | |||
1757 | set_address_zero(r8a66597, urb); | ||
1758 | td = r8a66597_make_td(r8a66597, urb, hep, mem_flags); | ||
1759 | if (td == NULL) { | ||
1760 | ret = -ENOMEM; | ||
1761 | goto error; | ||
1762 | } | ||
1763 | if (list_empty(&r8a66597->pipe_queue[td->pipenum])) | ||
1764 | request = 1; | ||
1765 | list_add_tail(&td->queue, &r8a66597->pipe_queue[td->pipenum]); | ||
1766 | |||
1767 | spin_lock(&urb->lock); | ||
1768 | if (urb->status != -EINPROGRESS) { | ||
1769 | spin_unlock(&urb->lock); | ||
1770 | ret = -EPIPE; | ||
1771 | goto error; | ||
1772 | } | ||
1773 | urb->hcpriv = td; | ||
1774 | spin_unlock(&urb->lock); | ||
1775 | |||
1776 | if (request) { | ||
1777 | ret = start_transfer(r8a66597, td); | ||
1778 | if (ret < 0) { | ||
1779 | list_del(&td->queue); | ||
1780 | kfree(td); | ||
1781 | } | ||
1782 | } else | ||
1783 | set_td_timer(r8a66597, td); | ||
1784 | |||
1785 | error: | ||
1786 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1787 | return ret; | ||
1788 | } | ||
1789 | |||
1790 | static int r8a66597_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) | ||
1791 | { | ||
1792 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); | ||
1793 | struct r8a66597_td *td; | ||
1794 | unsigned long flags; | ||
1795 | |||
1796 | spin_lock_irqsave(&r8a66597->lock, flags); | ||
1797 | if (urb->hcpriv) { | ||
1798 | td = urb->hcpriv; | ||
1799 | pipe_stop(r8a66597, td->pipe); | ||
1800 | pipe_irq_disable(r8a66597, td->pipenum); | ||
1801 | disable_irq_empty(r8a66597, td->pipenum); | ||
1802 | done(r8a66597, td, td->pipenum, urb); | ||
1803 | } | ||
1804 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1805 | return 0; | ||
1806 | } | ||
1807 | |||
1808 | static void r8a66597_endpoint_disable(struct usb_hcd *hcd, | ||
1809 | struct usb_host_endpoint *hep) | ||
1810 | { | ||
1811 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); | ||
1812 | struct r8a66597_pipe *pipe = (struct r8a66597_pipe *)hep->hcpriv; | ||
1813 | struct r8a66597_td *td; | ||
1814 | struct urb *urb = NULL; | ||
1815 | u16 pipenum; | ||
1816 | unsigned long flags; | ||
1817 | |||
1818 | if (pipe == NULL) | ||
1819 | return; | ||
1820 | pipenum = pipe->info.pipenum; | ||
1821 | |||
1822 | if (pipenum == 0) { | ||
1823 | kfree(hep->hcpriv); | ||
1824 | hep->hcpriv = NULL; | ||
1825 | return; | ||
1826 | } | ||
1827 | |||
1828 | spin_lock_irqsave(&r8a66597->lock, flags); | ||
1829 | pipe_stop(r8a66597, pipe); | ||
1830 | pipe_irq_disable(r8a66597, pipenum); | ||
1831 | disable_irq_empty(r8a66597, pipenum); | ||
1832 | td = r8a66597_get_td(r8a66597, pipenum); | ||
1833 | if (td) | ||
1834 | urb = td->urb; | ||
1835 | done(r8a66597, td, pipenum, urb); | ||
1836 | kfree(hep->hcpriv); | ||
1837 | hep->hcpriv = NULL; | ||
1838 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1839 | } | ||
1840 | |||
1841 | static int r8a66597_get_frame(struct usb_hcd *hcd) | ||
1842 | { | ||
1843 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); | ||
1844 | return r8a66597_read(r8a66597, FRMNUM) & 0x03FF; | ||
1845 | } | ||
1846 | |||
1847 | static void collect_usb_address_map(struct usb_device *udev, unsigned long *map) | ||
1848 | { | ||
1849 | int chix; | ||
1850 | |||
1851 | if (udev->state == USB_STATE_CONFIGURED && | ||
1852 | udev->parent && udev->parent->devnum > 1 && | ||
1853 | udev->parent->descriptor.bDeviceClass == USB_CLASS_HUB) | ||
1854 | map[udev->devnum/32] |= (1 << (udev->devnum % 32)); | ||
1855 | |||
1856 | for (chix = 0; chix < udev->maxchild; chix++) { | ||
1857 | struct usb_device *childdev = udev->children[chix]; | ||
1858 | |||
1859 | if (childdev) | ||
1860 | collect_usb_address_map(childdev, map); | ||
1861 | } | ||
1862 | } | ||
1863 | |||
1864 | /* this function must be called with interrupt disabled */ | ||
1865 | static struct r8a66597_device *get_r8a66597_device(struct r8a66597 *r8a66597, | ||
1866 | int addr) | ||
1867 | { | ||
1868 | struct r8a66597_device *dev; | ||
1869 | struct list_head *list = &r8a66597->child_device; | ||
1870 | |||
1871 | list_for_each_entry(dev, list, device_list) { | ||
1872 | if (!dev) | ||
1873 | continue; | ||
1874 | if (dev->usb_address != addr) | ||
1875 | continue; | ||
1876 | |||
1877 | return dev; | ||
1878 | } | ||
1879 | |||
1880 | err("get_r8a66597_device fail.(%d)\n", addr); | ||
1881 | return NULL; | ||
1882 | } | ||
1883 | |||
1884 | static void update_usb_address_map(struct r8a66597 *r8a66597, | ||
1885 | struct usb_device *root_hub, | ||
1886 | unsigned long *map) | ||
1887 | { | ||
1888 | int i, j, addr; | ||
1889 | unsigned long diff; | ||
1890 | unsigned long flags; | ||
1891 | |||
1892 | for (i = 0; i < 4; i++) { | ||
1893 | diff = r8a66597->child_connect_map[i] ^ map[i]; | ||
1894 | if (!diff) | ||
1895 | continue; | ||
1896 | |||
1897 | for (j = 0; j < 32; j++) { | ||
1898 | if (!(diff & (1 << j))) | ||
1899 | continue; | ||
1900 | |||
1901 | addr = i * 32 + j; | ||
1902 | if (map[i] & (1 << j)) | ||
1903 | set_child_connect_map(r8a66597, addr); | ||
1904 | else { | ||
1905 | struct r8a66597_device *dev; | ||
1906 | |||
1907 | spin_lock_irqsave(&r8a66597->lock, flags); | ||
1908 | dev = get_r8a66597_device(r8a66597, addr); | ||
1909 | disable_r8a66597_pipe_all(r8a66597, dev); | ||
1910 | free_usb_address(r8a66597, dev); | ||
1911 | put_child_connect_map(r8a66597, addr); | ||
1912 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1913 | } | ||
1914 | } | ||
1915 | } | ||
1916 | } | ||
1917 | |||
1918 | static void r8a66597_check_detect_child(struct r8a66597 *r8a66597, | ||
1919 | struct usb_hcd *hcd) | ||
1920 | { | ||
1921 | struct usb_bus *bus; | ||
1922 | unsigned long now_map[4]; | ||
1923 | |||
1924 | memset(now_map, 0, sizeof(now_map)); | ||
1925 | |||
1926 | list_for_each_entry(bus, &usb_bus_list, bus_list) { | ||
1927 | if (!bus->root_hub) | ||
1928 | continue; | ||
1929 | |||
1930 | if (bus->busnum != hcd->self.busnum) | ||
1931 | continue; | ||
1932 | |||
1933 | collect_usb_address_map(bus->root_hub, now_map); | ||
1934 | update_usb_address_map(r8a66597, bus->root_hub, now_map); | ||
1935 | } | ||
1936 | } | ||
1937 | |||
1938 | static int r8a66597_hub_status_data(struct usb_hcd *hcd, char *buf) | ||
1939 | { | ||
1940 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); | ||
1941 | unsigned long flags; | ||
1942 | int i; | ||
1943 | |||
1944 | r8a66597_check_detect_child(r8a66597, hcd); | ||
1945 | |||
1946 | spin_lock_irqsave(&r8a66597->lock, flags); | ||
1947 | |||
1948 | *buf = 0; /* initialize (no change) */ | ||
1949 | |||
1950 | for (i = 0; i < R8A66597_MAX_ROOT_HUB; i++) { | ||
1951 | if (r8a66597->root_hub[i].port & 0xffff0000) | ||
1952 | *buf |= 1 << (i + 1); | ||
1953 | } | ||
1954 | |||
1955 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1956 | |||
1957 | return (*buf != 0); | ||
1958 | } | ||
1959 | |||
1960 | static void r8a66597_hub_descriptor(struct r8a66597 *r8a66597, | ||
1961 | struct usb_hub_descriptor *desc) | ||
1962 | { | ||
1963 | desc->bDescriptorType = 0x29; | ||
1964 | desc->bHubContrCurrent = 0; | ||
1965 | desc->bNbrPorts = R8A66597_MAX_ROOT_HUB; | ||
1966 | desc->bDescLength = 9; | ||
1967 | desc->bPwrOn2PwrGood = 0; | ||
1968 | desc->wHubCharacteristics = cpu_to_le16(0x0011); | ||
1969 | desc->bitmap[0] = ((1 << R8A66597_MAX_ROOT_HUB) - 1) << 1; | ||
1970 | desc->bitmap[1] = ~0; | ||
1971 | } | ||
1972 | |||
1973 | static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | ||
1974 | u16 wIndex, char *buf, u16 wLength) | ||
1975 | { | ||
1976 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); | ||
1977 | int ret; | ||
1978 | int port = (wIndex & 0x00FF) - 1; | ||
1979 | struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; | ||
1980 | unsigned long flags; | ||
1981 | |||
1982 | ret = 0; | ||
1983 | |||
1984 | spin_lock_irqsave(&r8a66597->lock, flags); | ||
1985 | switch (typeReq) { | ||
1986 | case ClearHubFeature: | ||
1987 | case SetHubFeature: | ||
1988 | switch (wValue) { | ||
1989 | case C_HUB_OVER_CURRENT: | ||
1990 | case C_HUB_LOCAL_POWER: | ||
1991 | break; | ||
1992 | default: | ||
1993 | goto error; | ||
1994 | } | ||
1995 | break; | ||
1996 | case ClearPortFeature: | ||
1997 | if (wIndex > R8A66597_MAX_ROOT_HUB) | ||
1998 | goto error; | ||
1999 | if (wLength != 0) | ||
2000 | goto error; | ||
2001 | |||
2002 | switch (wValue) { | ||
2003 | case USB_PORT_FEAT_ENABLE: | ||
2004 | rh->port &= (1 << USB_PORT_FEAT_POWER); | ||
2005 | break; | ||
2006 | case USB_PORT_FEAT_SUSPEND: | ||
2007 | break; | ||
2008 | case USB_PORT_FEAT_POWER: | ||
2009 | r8a66597_port_power(r8a66597, port, 0); | ||
2010 | break; | ||
2011 | case USB_PORT_FEAT_C_ENABLE: | ||
2012 | case USB_PORT_FEAT_C_SUSPEND: | ||
2013 | case USB_PORT_FEAT_C_CONNECTION: | ||
2014 | case USB_PORT_FEAT_C_OVER_CURRENT: | ||
2015 | case USB_PORT_FEAT_C_RESET: | ||
2016 | break; | ||
2017 | default: | ||
2018 | goto error; | ||
2019 | } | ||
2020 | rh->port &= ~(1 << wValue); | ||
2021 | break; | ||
2022 | case GetHubDescriptor: | ||
2023 | r8a66597_hub_descriptor(r8a66597, | ||
2024 | (struct usb_hub_descriptor *)buf); | ||
2025 | break; | ||
2026 | case GetHubStatus: | ||
2027 | *buf = 0x00; | ||
2028 | break; | ||
2029 | case GetPortStatus: | ||
2030 | if (wIndex > R8A66597_MAX_ROOT_HUB) | ||
2031 | goto error; | ||
2032 | *(u32 *)buf = rh->port; | ||
2033 | break; | ||
2034 | case SetPortFeature: | ||
2035 | if (wIndex > R8A66597_MAX_ROOT_HUB) | ||
2036 | goto error; | ||
2037 | if (wLength != 0) | ||
2038 | goto error; | ||
2039 | |||
2040 | switch (wValue) { | ||
2041 | case USB_PORT_FEAT_SUSPEND: | ||
2042 | break; | ||
2043 | case USB_PORT_FEAT_POWER: | ||
2044 | r8a66597_port_power(r8a66597, port, 1); | ||
2045 | rh->port |= (1 << USB_PORT_FEAT_POWER); | ||
2046 | break; | ||
2047 | case USB_PORT_FEAT_RESET: { | ||
2048 | struct r8a66597_device *dev = rh->dev; | ||
2049 | |||
2050 | rh->port |= (1 << USB_PORT_FEAT_RESET); | ||
2051 | |||
2052 | disable_r8a66597_pipe_all(r8a66597, dev); | ||
2053 | free_usb_address(r8a66597, dev); | ||
2054 | |||
2055 | r8a66597_mdfy(r8a66597, USBRST, USBRST | UACT, | ||
2056 | get_dvstctr_reg(port)); | ||
2057 | mod_timer(&r8a66597->rh_timer, | ||
2058 | jiffies + msecs_to_jiffies(50)); | ||
2059 | } | ||
2060 | break; | ||
2061 | default: | ||
2062 | goto error; | ||
2063 | } | ||
2064 | rh->port |= 1 << wValue; | ||
2065 | break; | ||
2066 | default: | ||
2067 | error: | ||
2068 | ret = -EPIPE; | ||
2069 | break; | ||
2070 | } | ||
2071 | |||
2072 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
2073 | return ret; | ||
2074 | } | ||
2075 | |||
2076 | static struct hc_driver r8a66597_hc_driver = { | ||
2077 | .description = hcd_name, | ||
2078 | .hcd_priv_size = sizeof(struct r8a66597), | ||
2079 | .irq = r8a66597_irq, | ||
2080 | |||
2081 | /* | ||
2082 | * generic hardware linkage | ||
2083 | */ | ||
2084 | .flags = HCD_USB2, | ||
2085 | |||
2086 | .start = r8a66597_start, | ||
2087 | .stop = r8a66597_stop, | ||
2088 | |||
2089 | /* | ||
2090 | * managing i/o requests and associated device resources | ||
2091 | */ | ||
2092 | .urb_enqueue = r8a66597_urb_enqueue, | ||
2093 | .urb_dequeue = r8a66597_urb_dequeue, | ||
2094 | .endpoint_disable = r8a66597_endpoint_disable, | ||
2095 | |||
2096 | /* | ||
2097 | * periodic schedule support | ||
2098 | */ | ||
2099 | .get_frame_number = r8a66597_get_frame, | ||
2100 | |||
2101 | /* | ||
2102 | * root hub support | ||
2103 | */ | ||
2104 | .hub_status_data = r8a66597_hub_status_data, | ||
2105 | .hub_control = r8a66597_hub_control, | ||
2106 | }; | ||
2107 | |||
2108 | #if defined(CONFIG_PM) | ||
2109 | static int r8a66597_suspend(struct platform_device *pdev, pm_message_t state) | ||
2110 | { | ||
2111 | pdev->dev.power.power_state = state; | ||
2112 | return 0; | ||
2113 | } | ||
2114 | |||
2115 | static int r8a66597_resume(struct platform_device *pdev) | ||
2116 | { | ||
2117 | pdev->dev.power.power_state = PMSG_ON; | ||
2118 | return 0; | ||
2119 | } | ||
2120 | #else /* if defined(CONFIG_PM) */ | ||
2121 | #define r8a66597_suspend NULL | ||
2122 | #define r8a66597_resume NULL | ||
2123 | #endif | ||
2124 | |||
2125 | static int __init_or_module r8a66597_remove(struct platform_device *pdev) | ||
2126 | { | ||
2127 | struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev); | ||
2128 | struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597); | ||
2129 | |||
2130 | del_timer_sync(&r8a66597->rh_timer); | ||
2131 | iounmap((void *)r8a66597->reg); | ||
2132 | usb_remove_hcd(hcd); | ||
2133 | usb_put_hcd(hcd); | ||
2134 | return 0; | ||
2135 | } | ||
2136 | |||
2137 | #define resource_len(r) (((r)->end - (r)->start) + 1) | ||
2138 | static int __init r8a66597_probe(struct platform_device *pdev) | ||
2139 | { | ||
2140 | struct resource *res = NULL; | ||
2141 | int irq = -1; | ||
2142 | void __iomem *reg = NULL; | ||
2143 | struct usb_hcd *hcd = NULL; | ||
2144 | struct r8a66597 *r8a66597; | ||
2145 | int ret = 0; | ||
2146 | int i; | ||
2147 | |||
2148 | if (pdev->dev.dma_mask) { | ||
2149 | ret = -EINVAL; | ||
2150 | err("dma not support"); | ||
2151 | goto clean_up; | ||
2152 | } | ||
2153 | |||
2154 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, | ||
2155 | (char *)hcd_name); | ||
2156 | if (!res) { | ||
2157 | ret = -ENODEV; | ||
2158 | err("platform_get_resource_byname error."); | ||
2159 | goto clean_up; | ||
2160 | } | ||
2161 | |||
2162 | irq = platform_get_irq(pdev, 0); | ||
2163 | if (irq < 0) { | ||
2164 | ret = -ENODEV; | ||
2165 | err("platform_get_irq error."); | ||
2166 | goto clean_up; | ||
2167 | } | ||
2168 | |||
2169 | reg = ioremap(res->start, resource_len(res)); | ||
2170 | if (reg == NULL) { | ||
2171 | ret = -ENOMEM; | ||
2172 | err("ioremap error."); | ||
2173 | goto clean_up; | ||
2174 | } | ||
2175 | |||
2176 | /* initialize hcd */ | ||
2177 | hcd = usb_create_hcd(&r8a66597_hc_driver, &pdev->dev, (char *)hcd_name); | ||
2178 | if (!hcd) { | ||
2179 | ret = -ENOMEM; | ||
2180 | err("Failed to create hcd"); | ||
2181 | goto clean_up; | ||
2182 | } | ||
2183 | r8a66597 = hcd_to_r8a66597(hcd); | ||
2184 | memset(r8a66597, 0, sizeof(struct r8a66597)); | ||
2185 | dev_set_drvdata(&pdev->dev, r8a66597); | ||
2186 | |||
2187 | spin_lock_init(&r8a66597->lock); | ||
2188 | init_timer(&r8a66597->rh_timer); | ||
2189 | r8a66597->rh_timer.function = r8a66597_timer; | ||
2190 | r8a66597->rh_timer.data = (unsigned long)r8a66597; | ||
2191 | r8a66597->reg = (unsigned long)reg; | ||
2192 | |||
2193 | for (i = 0; i < R8A66597_MAX_NUM_PIPE; i++) { | ||
2194 | INIT_LIST_HEAD(&r8a66597->pipe_queue[i]); | ||
2195 | init_timer(&r8a66597->td_timer[i]); | ||
2196 | r8a66597->td_timer[i].function = r8a66597_td_timer; | ||
2197 | r8a66597->td_timer[i].data = (unsigned long)r8a66597; | ||
2198 | } | ||
2199 | INIT_LIST_HEAD(&r8a66597->child_device); | ||
2200 | |||
2201 | hcd->rsrc_start = res->start; | ||
2202 | ret = usb_add_hcd(hcd, irq, 0); | ||
2203 | if (ret != 0) { | ||
2204 | err("Failed to add hcd"); | ||
2205 | goto clean_up; | ||
2206 | } | ||
2207 | |||
2208 | return 0; | ||
2209 | |||
2210 | clean_up: | ||
2211 | if (reg) | ||
2212 | iounmap(reg); | ||
2213 | if (res) | ||
2214 | release_mem_region(res->start, 1); | ||
2215 | |||
2216 | return ret; | ||
2217 | } | ||
2218 | |||
2219 | static struct platform_driver r8a66597_driver = { | ||
2220 | .probe = r8a66597_probe, | ||
2221 | .remove = r8a66597_remove, | ||
2222 | .suspend = r8a66597_suspend, | ||
2223 | .resume = r8a66597_resume, | ||
2224 | .driver = { | ||
2225 | .name = (char *) hcd_name, | ||
2226 | }, | ||
2227 | }; | ||
2228 | |||
2229 | static int __init r8a66597_init(void) | ||
2230 | { | ||
2231 | if (usb_disabled()) | ||
2232 | return -ENODEV; | ||
2233 | |||
2234 | info("driver %s, %s", hcd_name, DRIVER_VERSION); | ||
2235 | return platform_driver_register(&r8a66597_driver); | ||
2236 | } | ||
2237 | module_init(r8a66597_init); | ||
2238 | |||
2239 | static void __exit r8a66597_cleanup(void) | ||
2240 | { | ||
2241 | platform_driver_unregister(&r8a66597_driver); | ||
2242 | } | ||
2243 | module_exit(r8a66597_cleanup); | ||
2244 | |||
diff --git a/drivers/usb/host/r8a66597.h b/drivers/usb/host/r8a66597.h new file mode 100644 index 000000000000..97c2a71ac7a1 --- /dev/null +++ b/drivers/usb/host/r8a66597.h | |||
@@ -0,0 +1,634 @@ | |||
1 | /* | ||
2 | * R8A66597 HCD (Host Controller Driver) | ||
3 | * | ||
4 | * Copyright (C) 2006-2007 Renesas Solutions Corp. | ||
5 | * Portions Copyright (C) 2004 Psion Teklogix (for NetBook PRO) | ||
6 | * Portions Copyright (C) 2004-2005 David Brownell | ||
7 | * Portions Copyright (C) 1999 Roman Weissgaerber | ||
8 | * | ||
9 | * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License as published by | ||
13 | * the Free Software Foundation; version 2 of the License. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #ifndef __R8A66597_H__ | ||
27 | #define __R8A66597_H__ | ||
28 | |||
29 | #define SYSCFG0 0x00 | ||
30 | #define SYSCFG1 0x02 | ||
31 | #define SYSSTS0 0x04 | ||
32 | #define SYSSTS1 0x06 | ||
33 | #define DVSTCTR0 0x08 | ||
34 | #define DVSTCTR1 0x0A | ||
35 | #define TESTMODE 0x0C | ||
36 | #define PINCFG 0x0E | ||
37 | #define DMA0CFG 0x10 | ||
38 | #define DMA1CFG 0x12 | ||
39 | #define CFIFO 0x14 | ||
40 | #define D0FIFO 0x18 | ||
41 | #define D1FIFO 0x1C | ||
42 | #define CFIFOSEL 0x20 | ||
43 | #define CFIFOCTR 0x22 | ||
44 | #define CFIFOSIE 0x24 | ||
45 | #define D0FIFOSEL 0x28 | ||
46 | #define D0FIFOCTR 0x2A | ||
47 | #define D1FIFOSEL 0x2C | ||
48 | #define D1FIFOCTR 0x2E | ||
49 | #define INTENB0 0x30 | ||
50 | #define INTENB1 0x32 | ||
51 | #define INTENB2 0x34 | ||
52 | #define BRDYENB 0x36 | ||
53 | #define NRDYENB 0x38 | ||
54 | #define BEMPENB 0x3A | ||
55 | #define SOFCFG 0x3C | ||
56 | #define INTSTS0 0x40 | ||
57 | #define INTSTS1 0x42 | ||
58 | #define INTSTS2 0x44 | ||
59 | #define BRDYSTS 0x46 | ||
60 | #define NRDYSTS 0x48 | ||
61 | #define BEMPSTS 0x4A | ||
62 | #define FRMNUM 0x4C | ||
63 | #define UFRMNUM 0x4E | ||
64 | #define USBADDR 0x50 | ||
65 | #define USBREQ 0x54 | ||
66 | #define USBVAL 0x56 | ||
67 | #define USBINDX 0x58 | ||
68 | #define USBLENG 0x5A | ||
69 | #define DCPCFG 0x5C | ||
70 | #define DCPMAXP 0x5E | ||
71 | #define DCPCTR 0x60 | ||
72 | #define PIPESEL 0x64 | ||
73 | #define PIPECFG 0x68 | ||
74 | #define PIPEBUF 0x6A | ||
75 | #define PIPEMAXP 0x6C | ||
76 | #define PIPEPERI 0x6E | ||
77 | #define PIPE1CTR 0x70 | ||
78 | #define PIPE2CTR 0x72 | ||
79 | #define PIPE3CTR 0x74 | ||
80 | #define PIPE4CTR 0x76 | ||
81 | #define PIPE5CTR 0x78 | ||
82 | #define PIPE6CTR 0x7A | ||
83 | #define PIPE7CTR 0x7C | ||
84 | #define PIPE8CTR 0x7E | ||
85 | #define PIPE9CTR 0x80 | ||
86 | #define PIPE1TRE 0x90 | ||
87 | #define PIPE1TRN 0x92 | ||
88 | #define PIPE2TRE 0x94 | ||
89 | #define PIPE2TRN 0x96 | ||
90 | #define PIPE3TRE 0x98 | ||
91 | #define PIPE3TRN 0x9A | ||
92 | #define PIPE4TRE 0x9C | ||
93 | #define PIPE4TRN 0x9E | ||
94 | #define PIPE5TRE 0xA0 | ||
95 | #define PIPE5TRN 0xA2 | ||
96 | #define DEVADD0 0xD0 | ||
97 | #define DEVADD1 0xD2 | ||
98 | #define DEVADD2 0xD4 | ||
99 | #define DEVADD3 0xD6 | ||
100 | #define DEVADD4 0xD8 | ||
101 | #define DEVADD5 0xDA | ||
102 | #define DEVADD6 0xDC | ||
103 | #define DEVADD7 0xDE | ||
104 | #define DEVADD8 0xE0 | ||
105 | #define DEVADD9 0xE2 | ||
106 | #define DEVADDA 0xE4 | ||
107 | |||
108 | /* System Configuration Control Register */ | ||
109 | #define XTAL 0xC000 /* b15-14: Crystal selection */ | ||
110 | #define XTAL48 0x8000 /* 48MHz */ | ||
111 | #define XTAL24 0x4000 /* 24MHz */ | ||
112 | #define XTAL12 0x0000 /* 12MHz */ | ||
113 | #define XCKE 0x2000 /* b13: External clock enable */ | ||
114 | #define PLLC 0x0800 /* b11: PLL control */ | ||
115 | #define SCKE 0x0400 /* b10: USB clock enable */ | ||
116 | #define PCSDIS 0x0200 /* b9: not CS wakeup */ | ||
117 | #define LPSME 0x0100 /* b8: Low power sleep mode */ | ||
118 | #define HSE 0x0080 /* b7: Hi-speed enable */ | ||
119 | #define DCFM 0x0040 /* b6: Controller function select */ | ||
120 | #define DRPD 0x0020 /* b5: D+/- pull down control */ | ||
121 | #define DPRPU 0x0010 /* b4: D+ pull up control */ | ||
122 | #define USBE 0x0001 /* b0: USB module operation enable */ | ||
123 | |||
124 | /* System Configuration Status Register */ | ||
125 | #define OVCBIT 0x8000 /* b15-14: Over-current bit */ | ||
126 | #define OVCMON 0xC000 /* b15-14: Over-current monitor */ | ||
127 | #define SOFEA 0x0020 /* b5: SOF monitor */ | ||
128 | #define IDMON 0x0004 /* b3: ID-pin monitor */ | ||
129 | #define LNST 0x0003 /* b1-0: D+, D- line status */ | ||
130 | #define SE1 0x0003 /* SE1 */ | ||
131 | #define FS_KSTS 0x0002 /* Full-Speed K State */ | ||
132 | #define FS_JSTS 0x0001 /* Full-Speed J State */ | ||
133 | #define LS_JSTS 0x0002 /* Low-Speed J State */ | ||
134 | #define LS_KSTS 0x0001 /* Low-Speed K State */ | ||
135 | #define SE0 0x0000 /* SE0 */ | ||
136 | |||
137 | /* Device State Control Register */ | ||
138 | #define EXTLP0 0x0400 /* b10: External port */ | ||
139 | #define VBOUT 0x0200 /* b9: VBUS output */ | ||
140 | #define WKUP 0x0100 /* b8: Remote wakeup */ | ||
141 | #define RWUPE 0x0080 /* b7: Remote wakeup sense */ | ||
142 | #define USBRST 0x0040 /* b6: USB reset enable */ | ||
143 | #define RESUME 0x0020 /* b5: Resume enable */ | ||
144 | #define UACT 0x0010 /* b4: USB bus enable */ | ||
145 | #define RHST 0x0007 /* b1-0: Reset handshake status */ | ||
146 | #define HSPROC 0x0004 /* HS handshake is processing */ | ||
147 | #define HSMODE 0x0003 /* Hi-Speed mode */ | ||
148 | #define FSMODE 0x0002 /* Full-Speed mode */ | ||
149 | #define LSMODE 0x0001 /* Low-Speed mode */ | ||
150 | #define UNDECID 0x0000 /* Undecided */ | ||
151 | |||
152 | /* Test Mode Register */ | ||
153 | #define UTST 0x000F /* b3-0: Test select */ | ||
154 | #define H_TST_PACKET 0x000C /* HOST TEST Packet */ | ||
155 | #define H_TST_SE0_NAK 0x000B /* HOST TEST SE0 NAK */ | ||
156 | #define H_TST_K 0x000A /* HOST TEST K */ | ||
157 | #define H_TST_J 0x0009 /* HOST TEST J */ | ||
158 | #define H_TST_NORMAL 0x0000 /* HOST Normal Mode */ | ||
159 | #define P_TST_PACKET 0x0004 /* PERI TEST Packet */ | ||
160 | #define P_TST_SE0_NAK 0x0003 /* PERI TEST SE0 NAK */ | ||
161 | #define P_TST_K 0x0002 /* PERI TEST K */ | ||
162 | #define P_TST_J 0x0001 /* PERI TEST J */ | ||
163 | #define P_TST_NORMAL 0x0000 /* PERI Normal Mode */ | ||
164 | |||
165 | /* Data Pin Configuration Register */ | ||
166 | #define LDRV 0x8000 /* b15: Drive Current Adjust */ | ||
167 | #define VIF1 0x0000 /* VIF = 1.8V */ | ||
168 | #define VIF3 0x8000 /* VIF = 3.3V */ | ||
169 | #define INTA 0x0001 /* b1: USB INT-pin active */ | ||
170 | |||
171 | /* DMAx Pin Configuration Register */ | ||
172 | #define DREQA 0x4000 /* b14: Dreq active select */ | ||
173 | #define BURST 0x2000 /* b13: Burst mode */ | ||
174 | #define DACKA 0x0400 /* b10: Dack active select */ | ||
175 | #define DFORM 0x0380 /* b9-7: DMA mode select */ | ||
176 | #define CPU_ADR_RD_WR 0x0000 /* Address + RD/WR mode (CPU bus) */ | ||
177 | #define CPU_DACK_RD_WR 0x0100 /* DACK + RD/WR mode (CPU bus) */ | ||
178 | #define CPU_DACK_ONLY 0x0180 /* DACK only mode (CPU bus) */ | ||
179 | #define SPLIT_DACK_ONLY 0x0200 /* DACK only mode (SPLIT bus) */ | ||
180 | #define DENDA 0x0040 /* b6: Dend active select */ | ||
181 | #define PKTM 0x0020 /* b5: Packet mode */ | ||
182 | #define DENDE 0x0010 /* b4: Dend enable */ | ||
183 | #define OBUS 0x0004 /* b2: OUTbus mode */ | ||
184 | |||
185 | /* CFIFO/DxFIFO Port Select Register */ | ||
186 | #define RCNT 0x8000 /* b15: Read count mode */ | ||
187 | #define REW 0x4000 /* b14: Buffer rewind */ | ||
188 | #define DCLRM 0x2000 /* b13: DMA buffer clear mode */ | ||
189 | #define DREQE 0x1000 /* b12: DREQ output enable */ | ||
190 | #define MBW 0x0400 /* b10: Maximum bit width for FIFO access */ | ||
191 | #define MBW_8 0x0000 /* 8bit */ | ||
192 | #define MBW_16 0x0400 /* 16bit */ | ||
193 | #define BIGEND 0x0100 /* b8: Big endian mode */ | ||
194 | #define BYTE_LITTLE 0x0000 /* little dendian */ | ||
195 | #define BYTE_BIG 0x0100 /* big endifan */ | ||
196 | #define ISEL 0x0020 /* b5: DCP FIFO port direction select */ | ||
197 | #define CURPIPE 0x000F /* b2-0: PIPE select */ | ||
198 | |||
199 | /* CFIFO/DxFIFO Port Control Register */ | ||
200 | #define BVAL 0x8000 /* b15: Buffer valid flag */ | ||
201 | #define BCLR 0x4000 /* b14: Buffer clear */ | ||
202 | #define FRDY 0x2000 /* b13: FIFO ready */ | ||
203 | #define DTLN 0x0FFF /* b11-0: FIFO received data length */ | ||
204 | |||
205 | /* Interrupt Enable Register 0 */ | ||
206 | #define VBSE 0x8000 /* b15: VBUS interrupt */ | ||
207 | #define RSME 0x4000 /* b14: Resume interrupt */ | ||
208 | #define SOFE 0x2000 /* b13: Frame update interrupt */ | ||
209 | #define DVSE 0x1000 /* b12: Device state transition interrupt */ | ||
210 | #define CTRE 0x0800 /* b11: Control transfer stage transition interrupt */ | ||
211 | #define BEMPE 0x0400 /* b10: Buffer empty interrupt */ | ||
212 | #define NRDYE 0x0200 /* b9: Buffer not ready interrupt */ | ||
213 | #define BRDYE 0x0100 /* b8: Buffer ready interrupt */ | ||
214 | |||
215 | /* Interrupt Enable Register 1 */ | ||
216 | #define OVRCRE 0x8000 /* b15: Over-current interrupt */ | ||
217 | #define BCHGE 0x4000 /* b14: USB us chenge interrupt */ | ||
218 | #define DTCHE 0x1000 /* b12: Detach sense interrupt */ | ||
219 | #define ATTCHE 0x0800 /* b11: Attach sense interrupt */ | ||
220 | #define EOFERRE 0x0040 /* b6: EOF error interrupt */ | ||
221 | #define SIGNE 0x0020 /* b5: SETUP IGNORE interrupt */ | ||
222 | #define SACKE 0x0010 /* b4: SETUP ACK interrupt */ | ||
223 | |||
224 | /* BRDY Interrupt Enable/Status Register */ | ||
225 | #define BRDY9 0x0200 /* b9: PIPE9 */ | ||
226 | #define BRDY8 0x0100 /* b8: PIPE8 */ | ||
227 | #define BRDY7 0x0080 /* b7: PIPE7 */ | ||
228 | #define BRDY6 0x0040 /* b6: PIPE6 */ | ||
229 | #define BRDY5 0x0020 /* b5: PIPE5 */ | ||
230 | #define BRDY4 0x0010 /* b4: PIPE4 */ | ||
231 | #define BRDY3 0x0008 /* b3: PIPE3 */ | ||
232 | #define BRDY2 0x0004 /* b2: PIPE2 */ | ||
233 | #define BRDY1 0x0002 /* b1: PIPE1 */ | ||
234 | #define BRDY0 0x0001 /* b1: PIPE0 */ | ||
235 | |||
236 | /* NRDY Interrupt Enable/Status Register */ | ||
237 | #define NRDY9 0x0200 /* b9: PIPE9 */ | ||
238 | #define NRDY8 0x0100 /* b8: PIPE8 */ | ||
239 | #define NRDY7 0x0080 /* b7: PIPE7 */ | ||
240 | #define NRDY6 0x0040 /* b6: PIPE6 */ | ||
241 | #define NRDY5 0x0020 /* b5: PIPE5 */ | ||
242 | #define NRDY4 0x0010 /* b4: PIPE4 */ | ||
243 | #define NRDY3 0x0008 /* b3: PIPE3 */ | ||
244 | #define NRDY2 0x0004 /* b2: PIPE2 */ | ||
245 | #define NRDY1 0x0002 /* b1: PIPE1 */ | ||
246 | #define NRDY0 0x0001 /* b1: PIPE0 */ | ||
247 | |||
248 | /* BEMP Interrupt Enable/Status Register */ | ||
249 | #define BEMP9 0x0200 /* b9: PIPE9 */ | ||
250 | #define BEMP8 0x0100 /* b8: PIPE8 */ | ||
251 | #define BEMP7 0x0080 /* b7: PIPE7 */ | ||
252 | #define BEMP6 0x0040 /* b6: PIPE6 */ | ||
253 | #define BEMP5 0x0020 /* b5: PIPE5 */ | ||
254 | #define BEMP4 0x0010 /* b4: PIPE4 */ | ||
255 | #define BEMP3 0x0008 /* b3: PIPE3 */ | ||
256 | #define BEMP2 0x0004 /* b2: PIPE2 */ | ||
257 | #define BEMP1 0x0002 /* b1: PIPE1 */ | ||
258 | #define BEMP0 0x0001 /* b0: PIPE0 */ | ||
259 | |||
260 | /* SOF Pin Configuration Register */ | ||
261 | #define TRNENSEL 0x0100 /* b8: Select transaction enable period */ | ||
262 | #define BRDYM 0x0040 /* b6: BRDY clear timing */ | ||
263 | #define INTL 0x0020 /* b5: Interrupt sense select */ | ||
264 | #define EDGESTS 0x0010 /* b4: */ | ||
265 | #define SOFMODE 0x000C /* b3-2: SOF pin select */ | ||
266 | #define SOF_125US 0x0008 /* SOF OUT 125us Frame Signal */ | ||
267 | #define SOF_1MS 0x0004 /* SOF OUT 1ms Frame Signal */ | ||
268 | #define SOF_DISABLE 0x0000 /* SOF OUT Disable */ | ||
269 | |||
270 | /* Interrupt Status Register 0 */ | ||
271 | #define VBINT 0x8000 /* b15: VBUS interrupt */ | ||
272 | #define RESM 0x4000 /* b14: Resume interrupt */ | ||
273 | #define SOFR 0x2000 /* b13: SOF frame update interrupt */ | ||
274 | #define DVST 0x1000 /* b12: Device state transition interrupt */ | ||
275 | #define CTRT 0x0800 /* b11: Control transfer stage transition interrupt */ | ||
276 | #define BEMP 0x0400 /* b10: Buffer empty interrupt */ | ||
277 | #define NRDY 0x0200 /* b9: Buffer not ready interrupt */ | ||
278 | #define BRDY 0x0100 /* b8: Buffer ready interrupt */ | ||
279 | #define VBSTS 0x0080 /* b7: VBUS input port */ | ||
280 | #define DVSQ 0x0070 /* b6-4: Device state */ | ||
281 | #define DS_SPD_CNFG 0x0070 /* Suspend Configured */ | ||
282 | #define DS_SPD_ADDR 0x0060 /* Suspend Address */ | ||
283 | #define DS_SPD_DFLT 0x0050 /* Suspend Default */ | ||
284 | #define DS_SPD_POWR 0x0040 /* Suspend Powered */ | ||
285 | #define DS_SUSP 0x0040 /* Suspend */ | ||
286 | #define DS_CNFG 0x0030 /* Configured */ | ||
287 | #define DS_ADDS 0x0020 /* Address */ | ||
288 | #define DS_DFLT 0x0010 /* Default */ | ||
289 | #define DS_POWR 0x0000 /* Powered */ | ||
290 | #define DVSQS 0x0030 /* b5-4: Device state */ | ||
291 | #define VALID 0x0008 /* b3: Setup packet detected flag */ | ||
292 | #define CTSQ 0x0007 /* b2-0: Control transfer stage */ | ||
293 | #define CS_SQER 0x0006 /* Sequence error */ | ||
294 | #define CS_WRND 0x0005 /* Control write nodata status stage */ | ||
295 | #define CS_WRSS 0x0004 /* Control write status stage */ | ||
296 | #define CS_WRDS 0x0003 /* Control write data stage */ | ||
297 | #define CS_RDSS 0x0002 /* Control read status stage */ | ||
298 | #define CS_RDDS 0x0001 /* Control read data stage */ | ||
299 | #define CS_IDST 0x0000 /* Idle or setup stage */ | ||
300 | |||
301 | /* Interrupt Status Register 1 */ | ||
302 | #define OVRCR 0x8000 /* b15: Over-current interrupt */ | ||
303 | #define BCHG 0x4000 /* b14: USB bus chenge interrupt */ | ||
304 | #define DTCH 0x1000 /* b12: Detach sense interrupt */ | ||
305 | #define ATTCH 0x0800 /* b11: Attach sense interrupt */ | ||
306 | #define EOFERR 0x0040 /* b6: EOF-error interrupt */ | ||
307 | #define SIGN 0x0020 /* b5: Setup ignore interrupt */ | ||
308 | #define SACK 0x0010 /* b4: Setup acknowledge interrupt */ | ||
309 | |||
310 | /* Frame Number Register */ | ||
311 | #define OVRN 0x8000 /* b15: Overrun error */ | ||
312 | #define CRCE 0x4000 /* b14: Received data error */ | ||
313 | #define FRNM 0x07FF /* b10-0: Frame number */ | ||
314 | |||
315 | /* Micro Frame Number Register */ | ||
316 | #define UFRNM 0x0007 /* b2-0: Micro frame number */ | ||
317 | |||
318 | /* USB Address / Low Power Status Recovery Register */ | ||
319 | //#define USBADDR 0x007F /* b6-0: USB address */ | ||
320 | |||
321 | /* Default Control Pipe Maxpacket Size Register */ | ||
322 | /* Pipe Maxpacket Size Register */ | ||
323 | #define DEVSEL 0xF000 /* b15-14: Device address select */ | ||
324 | #define MAXP 0x007F /* b6-0: Maxpacket size of default control pipe */ | ||
325 | |||
326 | /* Default Control Pipe Control Register */ | ||
327 | #define BSTS 0x8000 /* b15: Buffer status */ | ||
328 | #define SUREQ 0x4000 /* b14: Send USB request */ | ||
329 | #define CSCLR 0x2000 /* b13: complete-split status clear */ | ||
330 | #define CSSTS 0x1000 /* b12: complete-split status */ | ||
331 | #define SUREQCLR 0x0800 /* b11: stop setup request */ | ||
332 | #define SQCLR 0x0100 /* b8: Sequence toggle bit clear */ | ||
333 | #define SQSET 0x0080 /* b7: Sequence toggle bit set */ | ||
334 | #define SQMON 0x0040 /* b6: Sequence toggle bit monitor */ | ||
335 | #define PBUSY 0x0020 /* b5: pipe busy */ | ||
336 | #define PINGE 0x0010 /* b4: ping enable */ | ||
337 | #define CCPL 0x0004 /* b2: Enable control transfer complete */ | ||
338 | #define PID 0x0003 /* b1-0: Response PID */ | ||
339 | #define PID_STALL11 0x0003 /* STALL */ | ||
340 | #define PID_STALL 0x0002 /* STALL */ | ||
341 | #define PID_BUF 0x0001 /* BUF */ | ||
342 | #define PID_NAK 0x0000 /* NAK */ | ||
343 | |||
344 | /* Pipe Window Select Register */ | ||
345 | #define PIPENM 0x0007 /* b2-0: Pipe select */ | ||
346 | |||
347 | /* Pipe Configuration Register */ | ||
348 | #define R8A66597_TYP 0xC000 /* b15-14: Transfer type */ | ||
349 | #define R8A66597_ISO 0xC000 /* Isochronous */ | ||
350 | #define R8A66597_INT 0x8000 /* Interrupt */ | ||
351 | #define R8A66597_BULK 0x4000 /* Bulk */ | ||
352 | #define R8A66597_BFRE 0x0400 /* b10: Buffer ready interrupt mode select */ | ||
353 | #define R8A66597_DBLB 0x0200 /* b9: Double buffer mode select */ | ||
354 | #define R8A66597_CNTMD 0x0100 /* b8: Continuous transfer mode select */ | ||
355 | #define R8A66597_SHTNAK 0x0080 /* b7: Transfer end NAK */ | ||
356 | #define R8A66597_DIR 0x0010 /* b4: Transfer direction select */ | ||
357 | #define R8A66597_EPNUM 0x000F /* b3-0: Eendpoint number select */ | ||
358 | |||
359 | /* Pipe Buffer Configuration Register */ | ||
360 | #define BUFSIZE 0x7C00 /* b14-10: Pipe buffer size */ | ||
361 | #define BUFNMB 0x007F /* b6-0: Pipe buffer number */ | ||
362 | #define PIPE0BUF 256 | ||
363 | #define PIPExBUF 64 | ||
364 | |||
365 | /* Pipe Maxpacket Size Register */ | ||
366 | #define MXPS 0x07FF /* b10-0: Maxpacket size */ | ||
367 | |||
368 | /* Pipe Cycle Configuration Register */ | ||
369 | #define IFIS 0x1000 /* b12: Isochronous in-buffer flush mode select */ | ||
370 | #define IITV 0x0007 /* b2-0: Isochronous interval */ | ||
371 | |||
372 | /* Pipex Control Register */ | ||
373 | #define BSTS 0x8000 /* b15: Buffer status */ | ||
374 | #define INBUFM 0x4000 /* b14: IN buffer monitor (Only for PIPE1 to 5) */ | ||
375 | #define CSCLR 0x2000 /* b13: complete-split status clear */ | ||
376 | #define CSSTS 0x1000 /* b12: complete-split status */ | ||
377 | #define ATREPM 0x0400 /* b10: Auto repeat mode */ | ||
378 | #define ACLRM 0x0200 /* b9: Out buffer auto clear mode */ | ||
379 | #define SQCLR 0x0100 /* b8: Sequence toggle bit clear */ | ||
380 | #define SQSET 0x0080 /* b7: Sequence toggle bit set */ | ||
381 | #define SQMON 0x0040 /* b6: Sequence toggle bit monitor */ | ||
382 | #define PBUSY 0x0020 /* b5: pipe busy */ | ||
383 | #define PID 0x0003 /* b1-0: Response PID */ | ||
384 | |||
385 | /* PIPExTRE */ | ||
386 | #define TRENB 0x0200 /* b9: Transaction counter enable */ | ||
387 | #define TRCLR 0x0100 /* b8: Transaction counter clear */ | ||
388 | |||
389 | /* PIPExTRN */ | ||
390 | #define TRNCNT 0xFFFF /* b15-0: Transaction counter */ | ||
391 | |||
392 | /* DEVADDx */ | ||
393 | #define UPPHUB 0x7800 | ||
394 | #define HUBPORT 0x0700 | ||
395 | #define USBSPD 0x00C0 | ||
396 | #define RTPORT 0x0001 | ||
397 | |||
398 | #define R8A66597_MAX_NUM_PIPE 10 | ||
399 | #define R8A66597_BUF_BSIZE 8 | ||
400 | #define R8A66597_MAX_DEVICE 10 | ||
401 | #define R8A66597_MAX_ROOT_HUB 2 | ||
402 | #define R8A66597_MAX_SAMPLING 10 | ||
403 | #define R8A66597_MAX_DMA_CHANNEL 2 | ||
404 | #define R8A66597_PIPE_NO_DMA R8A66597_MAX_DMA_CHANNEL | ||
405 | #define check_bulk_or_isoc(pipenum) ((pipenum >= 1 && pipenum <= 5)) | ||
406 | #define check_interrupt(pipenum) ((pipenum >= 6 && pipenum <= 9)) | ||
407 | #define make_devsel(addr) (addr << 12) | ||
408 | |||
409 | struct r8a66597_pipe_info { | ||
410 | u16 pipenum; | ||
411 | u16 address; /* R8A66597 HCD usb addres */ | ||
412 | u16 epnum; | ||
413 | u16 maxpacket; | ||
414 | u16 type; | ||
415 | u16 bufnum; | ||
416 | u16 buf_bsize; | ||
417 | u16 interval; | ||
418 | u16 dir_in; | ||
419 | }; | ||
420 | |||
421 | struct r8a66597_pipe { | ||
422 | struct r8a66597_pipe_info info; | ||
423 | |||
424 | unsigned long fifoaddr; | ||
425 | unsigned long fifosel; | ||
426 | unsigned long fifoctr; | ||
427 | unsigned long pipectr; | ||
428 | unsigned long pipetre; | ||
429 | unsigned long pipetrn; | ||
430 | }; | ||
431 | |||
432 | struct r8a66597_td { | ||
433 | struct r8a66597_pipe *pipe; | ||
434 | struct urb *urb; | ||
435 | struct list_head queue; | ||
436 | |||
437 | u16 type; | ||
438 | u16 pipenum; | ||
439 | int iso_cnt; | ||
440 | |||
441 | u16 address; /* R8A66597's USB address */ | ||
442 | u16 maxpacket; | ||
443 | |||
444 | unsigned zero_packet:1; | ||
445 | unsigned short_packet:1; | ||
446 | unsigned set_address:1; | ||
447 | }; | ||
448 | |||
449 | struct r8a66597_device { | ||
450 | u16 address; /* R8A66597's USB address */ | ||
451 | u16 hub_port; | ||
452 | u16 root_port; | ||
453 | |||
454 | unsigned short ep_in_toggle; | ||
455 | unsigned short ep_out_toggle; | ||
456 | unsigned char pipe_cnt[R8A66597_MAX_NUM_PIPE]; | ||
457 | unsigned char dma_map; | ||
458 | |||
459 | enum usb_device_state state; | ||
460 | |||
461 | struct usb_device *udev; | ||
462 | int usb_address; | ||
463 | struct list_head device_list; | ||
464 | }; | ||
465 | |||
466 | struct r8a66597_root_hub { | ||
467 | u32 port; | ||
468 | u16 old_syssts; | ||
469 | int scount; | ||
470 | |||
471 | struct r8a66597_device *dev; | ||
472 | }; | ||
473 | |||
474 | struct r8a66597 { | ||
475 | spinlock_t lock; | ||
476 | unsigned long reg; | ||
477 | |||
478 | struct r8a66597_device device0; | ||
479 | struct r8a66597_root_hub root_hub[R8A66597_MAX_ROOT_HUB]; | ||
480 | struct list_head pipe_queue[R8A66597_MAX_NUM_PIPE]; | ||
481 | |||
482 | struct timer_list rh_timer; | ||
483 | struct timer_list td_timer[R8A66597_MAX_NUM_PIPE]; | ||
484 | |||
485 | unsigned short address_map; | ||
486 | unsigned short timeout_map; | ||
487 | unsigned char pipe_cnt[R8A66597_MAX_NUM_PIPE]; | ||
488 | unsigned char dma_map; | ||
489 | |||
490 | struct list_head child_device; | ||
491 | unsigned long child_connect_map[4]; | ||
492 | }; | ||
493 | |||
494 | static inline struct r8a66597 *hcd_to_r8a66597(struct usb_hcd *hcd) | ||
495 | { | ||
496 | return (struct r8a66597 *)(hcd->hcd_priv); | ||
497 | } | ||
498 | |||
499 | static inline struct usb_hcd *r8a66597_to_hcd(struct r8a66597 *r8a66597) | ||
500 | { | ||
501 | return container_of((void *)r8a66597, struct usb_hcd, hcd_priv); | ||
502 | } | ||
503 | |||
504 | static inline struct r8a66597_td *r8a66597_get_td(struct r8a66597 *r8a66597, | ||
505 | u16 pipenum) | ||
506 | { | ||
507 | if (unlikely(list_empty(&r8a66597->pipe_queue[pipenum]))) | ||
508 | return NULL; | ||
509 | |||
510 | return list_entry(r8a66597->pipe_queue[pipenum].next, | ||
511 | struct r8a66597_td, queue); | ||
512 | } | ||
513 | |||
514 | static inline struct urb *r8a66597_get_urb(struct r8a66597 *r8a66597, | ||
515 | u16 pipenum) | ||
516 | { | ||
517 | struct r8a66597_td *td; | ||
518 | |||
519 | td = r8a66597_get_td(r8a66597, pipenum); | ||
520 | return (td ? td->urb : NULL); | ||
521 | } | ||
522 | |||
523 | static inline u16 r8a66597_read(struct r8a66597 *r8a66597, unsigned long offset) | ||
524 | { | ||
525 | return inw(r8a66597->reg + offset); | ||
526 | } | ||
527 | |||
528 | static inline void r8a66597_read_fifo(struct r8a66597 *r8a66597, | ||
529 | unsigned long offset, u16 *buf, | ||
530 | int len) | ||
531 | { | ||
532 | len = (len + 1) / 2; | ||
533 | insw(r8a66597->reg + offset, buf, len); | ||
534 | } | ||
535 | |||
536 | static inline void r8a66597_write(struct r8a66597 *r8a66597, u16 val, | ||
537 | unsigned long offset) | ||
538 | { | ||
539 | outw(val, r8a66597->reg + offset); | ||
540 | } | ||
541 | |||
542 | static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597, | ||
543 | unsigned long offset, u16 *buf, | ||
544 | int len) | ||
545 | { | ||
546 | unsigned long fifoaddr = r8a66597->reg + offset; | ||
547 | int odd = len & 0x0001; | ||
548 | |||
549 | len = len / 2; | ||
550 | outsw(fifoaddr, buf, len); | ||
551 | if (unlikely(odd)) { | ||
552 | buf = &buf[len]; | ||
553 | outb((unsigned char)*buf, fifoaddr); | ||
554 | } | ||
555 | } | ||
556 | |||
557 | static inline void r8a66597_mdfy(struct r8a66597 *r8a66597, | ||
558 | u16 val, u16 pat, unsigned long offset) | ||
559 | { | ||
560 | u16 tmp; | ||
561 | tmp = r8a66597_read(r8a66597, offset); | ||
562 | tmp = tmp & (~pat); | ||
563 | tmp = tmp | val; | ||
564 | r8a66597_write(r8a66597, tmp, offset); | ||
565 | } | ||
566 | |||
567 | #define r8a66597_bclr(r8a66597, val, offset) \ | ||
568 | r8a66597_mdfy(r8a66597, 0, val, offset) | ||
569 | #define r8a66597_bset(r8a66597, val, offset) \ | ||
570 | r8a66597_mdfy(r8a66597, val, 0, offset) | ||
571 | |||
572 | static inline unsigned long get_syscfg_reg(int port) | ||
573 | { | ||
574 | return port == 0 ? SYSCFG0 : SYSCFG1; | ||
575 | } | ||
576 | |||
577 | static inline unsigned long get_syssts_reg(int port) | ||
578 | { | ||
579 | return port == 0 ? SYSSTS0 : SYSSTS1; | ||
580 | } | ||
581 | |||
582 | static inline unsigned long get_dvstctr_reg(int port) | ||
583 | { | ||
584 | return port == 0 ? DVSTCTR0 : DVSTCTR1; | ||
585 | } | ||
586 | |||
587 | static inline unsigned long get_intenb_reg(int port) | ||
588 | { | ||
589 | return port == 0 ? INTENB1 : INTENB2; | ||
590 | } | ||
591 | |||
592 | static inline unsigned long get_intsts_reg(int port) | ||
593 | { | ||
594 | return port == 0 ? INTSTS1 : INTSTS2; | ||
595 | } | ||
596 | |||
597 | static inline u16 get_rh_usb_speed(struct r8a66597 *r8a66597, int port) | ||
598 | { | ||
599 | unsigned long dvstctr_reg = get_dvstctr_reg(port); | ||
600 | |||
601 | return r8a66597_read(r8a66597, dvstctr_reg) & RHST; | ||
602 | } | ||
603 | |||
604 | static inline void r8a66597_port_power(struct r8a66597 *r8a66597, int port, | ||
605 | int power) | ||
606 | { | ||
607 | unsigned long dvstctr_reg = get_dvstctr_reg(port); | ||
608 | |||
609 | if (power) | ||
610 | r8a66597_bset(r8a66597, VBOUT, dvstctr_reg); | ||
611 | else | ||
612 | r8a66597_bclr(r8a66597, VBOUT, dvstctr_reg); | ||
613 | } | ||
614 | |||
615 | #define get_pipectr_addr(pipenum) (PIPE1CTR + (pipenum - 1) * 2) | ||
616 | #define get_pipetre_addr(pipenum) (PIPE1TRE + (pipenum - 1) * 4) | ||
617 | #define get_pipetrn_addr(pipenum) (PIPE1TRN + (pipenum - 1) * 4) | ||
618 | #define get_devadd_addr(address) (DEVADD0 + address * 2) | ||
619 | |||
620 | #define enable_irq_ready(r8a66597, pipenum) \ | ||
621 | enable_pipe_irq(r8a66597, pipenum, BRDYENB) | ||
622 | #define disable_irq_ready(r8a66597, pipenum) \ | ||
623 | disable_pipe_irq(r8a66597, pipenum, BRDYENB) | ||
624 | #define enable_irq_empty(r8a66597, pipenum) \ | ||
625 | enable_pipe_irq(r8a66597, pipenum, BEMPENB) | ||
626 | #define disable_irq_empty(r8a66597, pipenum) \ | ||
627 | disable_pipe_irq(r8a66597, pipenum, BEMPENB) | ||
628 | #define enable_irq_nrdy(r8a66597, pipenum) \ | ||
629 | enable_pipe_irq(r8a66597, pipenum, NRDYENB) | ||
630 | #define disable_irq_nrdy(r8a66597, pipenum) \ | ||
631 | disable_pipe_irq(r8a66597, pipenum, NRDYENB) | ||
632 | |||
633 | #endif /* __R8A66597_H__ */ | ||
634 | |||
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c index d22da26ff167..76c555a67dac 100644 --- a/drivers/usb/host/uhci-hcd.c +++ b/drivers/usb/host/uhci-hcd.c | |||
@@ -730,10 +730,9 @@ static int uhci_rh_resume(struct usb_hcd *hcd) | |||
730 | int rc = 0; | 730 | int rc = 0; |
731 | 731 | ||
732 | spin_lock_irq(&uhci->lock); | 732 | spin_lock_irq(&uhci->lock); |
733 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { | 733 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) |
734 | dev_warn(&hcd->self.root_hub->dev, "HC isn't running!\n"); | ||
735 | rc = -ESHUTDOWN; | 734 | rc = -ESHUTDOWN; |
736 | } else if (!uhci->dead) | 735 | else if (!uhci->dead) |
737 | wakeup_rh(uhci); | 736 | wakeup_rh(uhci); |
738 | spin_unlock_irq(&uhci->lock); | 737 | spin_unlock_irq(&uhci->lock); |
739 | return rc; | 738 | return rc; |