blob: 11367b45d5115a16c90288a00b8f93473293d650 [file] [log] [blame]
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001/*
2 * Driver for the NXP ISP1760 chip
3 *
4 * However, the code might contain some bugs. What doesn't work for sure is:
5 * - ISO
6 * - OTG
7 e The interrupt line is configured as active low, level.
8 *
9 * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de>
10 *
Arvid Brodin71a9f9d2011-04-26 21:48:30 +020011 * (c) 2011 Arvid Brodin <arvid.brodin@enea.com>
12 *
Sebastian Siewiordb11e472008-04-24 00:37:04 +020013 */
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/slab.h>
17#include <linux/list.h>
18#include <linux/usb.h>
Eric Lescouet27729aa2010-04-24 23:21:52 +020019#include <linux/usb/hcd.h>
Sebastian Siewiordb11e472008-04-24 00:37:04 +020020#include <linux/debugfs.h>
21#include <linux/uaccess.h>
22#include <linux/io.h>
Catalin Marinasdb8516f2010-02-02 15:31:02 +000023#include <linux/mm.h>
Arvid Brodin6d50c602011-08-21 08:29:26 +020024#include <linux/timer.h>
Sebastian Siewiordb11e472008-04-24 00:37:04 +020025#include <asm/unaligned.h>
Catalin Marinasdb8516f2010-02-02 15:31:02 +000026#include <asm/cacheflush.h>
Sebastian Siewiordb11e472008-04-24 00:37:04 +020027
Sebastian Siewiordb11e472008-04-24 00:37:04 +020028#include "isp1760-hcd.h"
29
30static struct kmem_cache *qtd_cachep;
31static struct kmem_cache *qh_cachep;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +020032static struct kmem_cache *urb_listitem_cachep;
Sebastian Siewiordb11e472008-04-24 00:37:04 +020033
34struct isp1760_hcd {
35 u32 hcs_params;
36 spinlock_t lock;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +020037 struct slotinfo atl_slots[32];
Arvid Brodind05b6ec2011-05-20 00:17:45 +020038 int atl_done_map;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +020039 struct slotinfo int_slots[32];
Arvid Brodind05b6ec2011-05-20 00:17:45 +020040 int int_done_map;
Sebastian Siewiordb11e472008-04-24 00:37:04 +020041 struct memory_chunk memory_pool[BLOCKS];
Arvid Brodin71a9f9d2011-04-26 21:48:30 +020042 struct list_head controlqhs, bulkqhs, interruptqhs;
Sebastian Siewiordb11e472008-04-24 00:37:04 +020043
44 /* periodic schedule support */
45#define DEFAULT_I_TDPS 1024
46 unsigned periodic_size;
47 unsigned i_thresh;
48 unsigned long reset_done;
49 unsigned long next_statechange;
Nate Case3faefc82008-06-17 11:11:38 -050050 unsigned int devflags;
Sebastian Siewiordb11e472008-04-24 00:37:04 +020051};
52
53static inline struct isp1760_hcd *hcd_to_priv(struct usb_hcd *hcd)
54{
55 return (struct isp1760_hcd *) (hcd->hcd_priv);
56}
Sebastian Siewiordb11e472008-04-24 00:37:04 +020057
58/* Section 2.2 Host Controller Capability Registers */
59#define HC_LENGTH(p) (((p)>>00)&0x00ff) /* bits 7:0 */
60#define HC_VERSION(p) (((p)>>16)&0xffff) /* bits 31:16 */
61#define HCS_INDICATOR(p) ((p)&(1 << 16)) /* true: has port indicators */
62#define HCS_PPC(p) ((p)&(1 << 4)) /* true: port power control */
63#define HCS_N_PORTS(p) (((p)>>0)&0xf) /* bits 3:0, ports on HC */
64#define HCC_ISOC_CACHE(p) ((p)&(1 << 7)) /* true: can cache isoc frame */
65#define HCC_ISOC_THRES(p) (((p)>>4)&0x7) /* bits 6:4, uframes cached */
66
67/* Section 2.3 Host Controller Operational Registers */
68#define CMD_LRESET (1<<7) /* partial reset (no ports, etc) */
69#define CMD_RESET (1<<1) /* reset HC not bus */
70#define CMD_RUN (1<<0) /* start/stop HC */
71#define STS_PCD (1<<2) /* port change detect */
72#define FLAG_CF (1<<0) /* true: we'll support "high speed" */
73
74#define PORT_OWNER (1<<13) /* true: companion hc owns this port */
75#define PORT_POWER (1<<12) /* true: has power (see PPC) */
76#define PORT_USB11(x) (((x) & (3 << 10)) == (1 << 10)) /* USB 1.1 device */
77#define PORT_RESET (1<<8) /* reset port */
78#define PORT_SUSPEND (1<<7) /* suspend port */
79#define PORT_RESUME (1<<6) /* resume it */
80#define PORT_PE (1<<2) /* port enable */
81#define PORT_CSC (1<<1) /* connect status change */
82#define PORT_CONNECT (1<<0) /* device connected */
83#define PORT_RWC_BITS (PORT_CSC)
84
85struct isp1760_qtd {
Sebastian Siewiordb11e472008-04-24 00:37:04 +020086 u8 packet_type;
Sebastian Siewiordb11e472008-04-24 00:37:04 +020087 void *data_buffer;
Arvid Brodina041d8e2011-02-26 22:04:40 +010088 u32 payload_addr;
89
Sebastian Siewiordb11e472008-04-24 00:37:04 +020090 /* the rest is HCD-private */
91 struct list_head qtd_list;
92 struct urb *urb;
93 size_t length;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +020094 size_t actual_length;
Sebastian Siewiordb11e472008-04-24 00:37:04 +020095
Arvid Brodin71a9f9d2011-04-26 21:48:30 +020096 /* QTD_ENQUEUED: waiting for transfer (inactive) */
97 /* QTD_PAYLOAD_ALLOC: chip mem has been allocated for payload */
98 /* QTD_XFER_STARTED: valid ptd has been written to isp176x - only
99 interrupt handler may touch this qtd! */
100 /* QTD_XFER_COMPLETE: payload has been transferred successfully */
101 /* QTD_RETIRE: transfer error/abort qtd */
102#define QTD_ENQUEUED 0
103#define QTD_PAYLOAD_ALLOC 1
104#define QTD_XFER_STARTED 2
105#define QTD_XFER_COMPLETE 3
106#define QTD_RETIRE 4
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200107 u32 status;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200108};
109
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200110/* Queue head, one for each active endpoint */
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200111struct isp1760_qh {
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200112 struct list_head qh_list;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200113 struct list_head qtd_list;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200114 u32 toggle;
115 u32 ping;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200116 int slot;
117};
118
119struct urb_listitem {
120 struct list_head urb_list;
121 struct urb *urb;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200122};
123
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100124/*
125 * Access functions for isp176x registers (addresses 0..0x03FF).
126 */
127static u32 reg_read32(void __iomem *base, u32 reg)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200128{
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100129 return readl(base + reg);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200130}
131
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100132static void reg_write32(void __iomem *base, u32 reg, u32 val)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200133{
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100134 writel(val, base + reg);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200135}
136
137/*
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100138 * Access functions for isp176x memory (offset >= 0x0400).
139 *
140 * bank_reads8() reads memory locations prefetched by an earlier write to
141 * HC_MEMORY_REG (see isp176x datasheet). Unless you want to do fancy multi-
142 * bank optimizations, you should use the more generic mem_reads8() below.
143 *
144 * For access to ptd memory, use the specialized ptd_read() and ptd_write()
145 * below.
146 *
147 * These functions copy via MMIO data to/from the device. memcpy_{to|from}io()
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200148 * doesn't quite work because some people have to enforce 32-bit access
149 */
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100150static void bank_reads8(void __iomem *src_base, u32 src_offset, u32 bank_addr,
151 __u32 *dst, u32 bytes)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200152{
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100153 __u32 __iomem *src;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200154 u32 val;
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100155 __u8 *src_byteptr;
156 __u8 *dst_byteptr;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200157
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100158 src = src_base + (bank_addr | src_offset);
159
160 if (src_offset < PAYLOAD_OFFSET) {
161 while (bytes >= 4) {
162 *dst = le32_to_cpu(__raw_readl(src));
163 bytes -= 4;
164 src++;
165 dst++;
166 }
167 } else {
168 while (bytes >= 4) {
169 *dst = __raw_readl(src);
170 bytes -= 4;
171 src++;
172 dst++;
173 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200174 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200175
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100176 if (!bytes)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200177 return;
178
179 /* in case we have 3, 2 or 1 by left. The dst buffer may not be fully
180 * allocated.
181 */
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100182 if (src_offset < PAYLOAD_OFFSET)
183 val = le32_to_cpu(__raw_readl(src));
184 else
185 val = __raw_readl(src);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200186
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100187 dst_byteptr = (void *) dst;
188 src_byteptr = (void *) &val;
189 while (bytes > 0) {
190 *dst_byteptr = *src_byteptr;
191 dst_byteptr++;
192 src_byteptr++;
193 bytes--;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200194 }
195}
196
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100197static void mem_reads8(void __iomem *src_base, u32 src_offset, void *dst,
198 u32 bytes)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200199{
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100200 reg_write32(src_base, HC_MEMORY_REG, src_offset + ISP_BANK(0));
201 ndelay(90);
202 bank_reads8(src_base, src_offset, ISP_BANK(0), dst, bytes);
203}
204
205static void mem_writes8(void __iomem *dst_base, u32 dst_offset,
206 __u32 const *src, u32 bytes)
207{
208 __u32 __iomem *dst;
209
210 dst = dst_base + dst_offset;
211
212 if (dst_offset < PAYLOAD_OFFSET) {
213 while (bytes >= 4) {
214 __raw_writel(cpu_to_le32(*src), dst);
215 bytes -= 4;
216 src++;
217 dst++;
218 }
219 } else {
220 while (bytes >= 4) {
221 __raw_writel(*src, dst);
222 bytes -= 4;
223 src++;
224 dst++;
225 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200226 }
227
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100228 if (!bytes)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200229 return;
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100230 /* in case we have 3, 2 or 1 bytes left. The buffer is allocated and the
231 * extra bytes should not be read by the HW.
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200232 */
233
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100234 if (dst_offset < PAYLOAD_OFFSET)
235 __raw_writel(cpu_to_le32(*src), dst);
236 else
237 __raw_writel(*src, dst);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200238}
239
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100240/*
241 * Read and write ptds. 'ptd_offset' should be one of ISO_PTD_OFFSET,
242 * INT_PTD_OFFSET, and ATL_PTD_OFFSET. 'slot' should be less than 32.
243 */
244static void ptd_read(void __iomem *base, u32 ptd_offset, u32 slot,
245 struct ptd *ptd)
246{
247 reg_write32(base, HC_MEMORY_REG,
248 ISP_BANK(0) + ptd_offset + slot*sizeof(*ptd));
249 ndelay(90);
250 bank_reads8(base, ptd_offset + slot*sizeof(*ptd), ISP_BANK(0),
251 (void *) ptd, sizeof(*ptd));
252}
253
254static void ptd_write(void __iomem *base, u32 ptd_offset, u32 slot,
255 struct ptd *ptd)
256{
257 mem_writes8(base, ptd_offset + slot*sizeof(*ptd) + sizeof(ptd->dw0),
258 &ptd->dw1, 7*sizeof(ptd->dw1));
259 /* Make sure dw0 gets written last (after other dw's and after payload)
260 since it contains the enable bit */
261 wmb();
262 mem_writes8(base, ptd_offset + slot*sizeof(*ptd), &ptd->dw0,
263 sizeof(ptd->dw0));
264}
265
266
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200267/* memory management of the 60kb on the chip from 0x1000 to 0xffff */
268static void init_memory(struct isp1760_hcd *priv)
269{
Arvid Brodina041d8e2011-02-26 22:04:40 +0100270 int i, curr;
271 u32 payload_addr;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200272
Arvid Brodina041d8e2011-02-26 22:04:40 +0100273 payload_addr = PAYLOAD_OFFSET;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200274 for (i = 0; i < BLOCK_1_NUM; i++) {
Arvid Brodina041d8e2011-02-26 22:04:40 +0100275 priv->memory_pool[i].start = payload_addr;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200276 priv->memory_pool[i].size = BLOCK_1_SIZE;
277 priv->memory_pool[i].free = 1;
Arvid Brodina041d8e2011-02-26 22:04:40 +0100278 payload_addr += priv->memory_pool[i].size;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200279 }
280
Arvid Brodina041d8e2011-02-26 22:04:40 +0100281 curr = i;
282 for (i = 0; i < BLOCK_2_NUM; i++) {
283 priv->memory_pool[curr + i].start = payload_addr;
284 priv->memory_pool[curr + i].size = BLOCK_2_SIZE;
285 priv->memory_pool[curr + i].free = 1;
286 payload_addr += priv->memory_pool[curr + i].size;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200287 }
288
Arvid Brodina041d8e2011-02-26 22:04:40 +0100289 curr = i;
290 for (i = 0; i < BLOCK_3_NUM; i++) {
291 priv->memory_pool[curr + i].start = payload_addr;
292 priv->memory_pool[curr + i].size = BLOCK_3_SIZE;
293 priv->memory_pool[curr + i].free = 1;
294 payload_addr += priv->memory_pool[curr + i].size;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200295 }
296
Arvid Brodin34537732011-04-26 21:47:37 +0200297 WARN_ON(payload_addr - priv->memory_pool[0].start > PAYLOAD_AREA_SIZE);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200298}
299
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100300static void alloc_mem(struct usb_hcd *hcd, struct isp1760_qtd *qtd)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200301{
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100302 struct isp1760_hcd *priv = hcd_to_priv(hcd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200303 int i;
304
Arvid Brodin34537732011-04-26 21:47:37 +0200305 WARN_ON(qtd->payload_addr);
Arvid Brodina041d8e2011-02-26 22:04:40 +0100306
307 if (!qtd->length)
308 return;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200309
310 for (i = 0; i < BLOCKS; i++) {
Arvid Brodina041d8e2011-02-26 22:04:40 +0100311 if (priv->memory_pool[i].size >= qtd->length &&
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200312 priv->memory_pool[i].free) {
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200313 priv->memory_pool[i].free = 0;
Arvid Brodina041d8e2011-02-26 22:04:40 +0100314 qtd->payload_addr = priv->memory_pool[i].start;
315 return;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200316 }
317 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200318}
319
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100320static void free_mem(struct usb_hcd *hcd, struct isp1760_qtd *qtd)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200321{
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100322 struct isp1760_hcd *priv = hcd_to_priv(hcd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200323 int i;
324
Arvid Brodina041d8e2011-02-26 22:04:40 +0100325 if (!qtd->payload_addr)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200326 return;
327
328 for (i = 0; i < BLOCKS; i++) {
Arvid Brodina041d8e2011-02-26 22:04:40 +0100329 if (priv->memory_pool[i].start == qtd->payload_addr) {
Arvid Brodin34537732011-04-26 21:47:37 +0200330 WARN_ON(priv->memory_pool[i].free);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200331 priv->memory_pool[i].free = 1;
Arvid Brodina041d8e2011-02-26 22:04:40 +0100332 qtd->payload_addr = 0;
333 return;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200334 }
335 }
336
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100337 dev_err(hcd->self.controller, "%s: Invalid pointer: %08x\n",
338 __func__, qtd->payload_addr);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200339 WARN_ON(1);
340 qtd->payload_addr = 0;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200341}
342
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100343static int handshake(struct usb_hcd *hcd, u32 reg,
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200344 u32 mask, u32 done, int usec)
345{
346 u32 result;
347
348 do {
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100349 result = reg_read32(hcd->regs, reg);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200350 if (result == ~0)
351 return -ENODEV;
352 result &= mask;
353 if (result == done)
354 return 0;
355 udelay(1);
356 usec--;
357 } while (usec > 0);
358 return -ETIMEDOUT;
359}
360
361/* reset a non-running (STS_HALT == 1) controller */
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100362static int ehci_reset(struct usb_hcd *hcd)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200363{
364 int retval;
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100365 struct isp1760_hcd *priv = hcd_to_priv(hcd);
366
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100367 u32 command = reg_read32(hcd->regs, HC_USBCMD);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200368
369 command |= CMD_RESET;
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100370 reg_write32(hcd->regs, HC_USBCMD, command);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200371 hcd->state = HC_STATE_HALT;
372 priv->next_statechange = jiffies;
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100373 retval = handshake(hcd, HC_USBCMD,
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200374 CMD_RESET, 0, 250 * 1000);
375 return retval;
376}
377
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200378static struct isp1760_qh *qh_alloc(gfp_t flags)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200379{
380 struct isp1760_qh *qh;
381
382 qh = kmem_cache_zalloc(qh_cachep, flags);
383 if (!qh)
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200384 return NULL;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200385
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200386 INIT_LIST_HEAD(&qh->qh_list);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200387 INIT_LIST_HEAD(&qh->qtd_list);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200388 qh->slot = -1;
389
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200390 return qh;
391}
392
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200393static void qh_free(struct isp1760_qh *qh)
394{
395 WARN_ON(!list_empty(&qh->qtd_list));
396 WARN_ON(qh->slot > -1);
397 kmem_cache_free(qh_cachep, qh);
398}
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200399
400/* one-time init, only for memory state */
401static int priv_init(struct usb_hcd *hcd)
402{
403 struct isp1760_hcd *priv = hcd_to_priv(hcd);
404 u32 hcc_params;
405
406 spin_lock_init(&priv->lock);
407
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200408 INIT_LIST_HEAD(&priv->interruptqhs);
409 INIT_LIST_HEAD(&priv->controlqhs);
410 INIT_LIST_HEAD(&priv->bulkqhs);
411
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200412 /*
413 * hw default: 1K periodic list heads, one per frame.
414 * periodic_size can shrink by USBCMD update if hcc_params allows.
415 */
416 priv->periodic_size = DEFAULT_I_TDPS;
417
418 /* controllers may cache some of the periodic schedule ... */
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100419 hcc_params = reg_read32(hcd->regs, HC_HCCPARAMS);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200420 /* full frame cache */
421 if (HCC_ISOC_CACHE(hcc_params))
422 priv->i_thresh = 8;
423 else /* N microframes cached */
424 priv->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
425
426 return 0;
427}
428
429static int isp1760_hc_setup(struct usb_hcd *hcd)
430{
431 struct isp1760_hcd *priv = hcd_to_priv(hcd);
432 int result;
Nate Case3faefc82008-06-17 11:11:38 -0500433 u32 scratch, hwmode;
434
435 /* Setup HW Mode Control: This assumes a level active-low interrupt */
436 hwmode = HW_DATA_BUS_32BIT;
437
438 if (priv->devflags & ISP1760_FLAG_BUS_WIDTH_16)
439 hwmode &= ~HW_DATA_BUS_32BIT;
440 if (priv->devflags & ISP1760_FLAG_ANALOG_OC)
441 hwmode |= HW_ANA_DIGI_OC;
442 if (priv->devflags & ISP1760_FLAG_DACK_POL_HIGH)
443 hwmode |= HW_DACK_POL_HIGH;
444 if (priv->devflags & ISP1760_FLAG_DREQ_POL_HIGH)
445 hwmode |= HW_DREQ_POL_HIGH;
Michael Hennerich9da69c62009-07-15 23:22:54 -0400446 if (priv->devflags & ISP1760_FLAG_INTR_POL_HIGH)
447 hwmode |= HW_INTR_HIGH_ACT;
448 if (priv->devflags & ISP1760_FLAG_INTR_EDGE_TRIG)
449 hwmode |= HW_INTR_EDGE_TRIG;
Nate Case3faefc82008-06-17 11:11:38 -0500450
451 /*
452 * We have to set this first in case we're in 16-bit mode.
453 * Write it twice to ensure correct upper bits if switching
454 * to 16-bit mode.
455 */
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100456 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode);
457 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200458
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100459 reg_write32(hcd->regs, HC_SCRATCH_REG, 0xdeadbabe);
Nate Case3faefc82008-06-17 11:11:38 -0500460 /* Change bus pattern */
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100461 scratch = reg_read32(hcd->regs, HC_CHIP_ID_REG);
462 scratch = reg_read32(hcd->regs, HC_SCRATCH_REG);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200463 if (scratch != 0xdeadbabe) {
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100464 dev_err(hcd->self.controller, "Scratch test failed.\n");
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200465 return -ENODEV;
466 }
467
468 /* pre reset */
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200469 reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, 0);
470 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE);
471 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE);
472 reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200473
474 /* reset */
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100475 reg_write32(hcd->regs, HC_RESET_REG, SW_RESET_RESET_ALL);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200476 mdelay(100);
477
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100478 reg_write32(hcd->regs, HC_RESET_REG, SW_RESET_RESET_HC);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200479 mdelay(100);
480
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100481 result = ehci_reset(hcd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200482 if (result)
483 return result;
484
485 /* Step 11 passed */
486
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100487 dev_info(hcd->self.controller, "bus width: %d, oc: %s\n",
Nate Case3faefc82008-06-17 11:11:38 -0500488 (priv->devflags & ISP1760_FLAG_BUS_WIDTH_16) ?
489 16 : 32, (priv->devflags & ISP1760_FLAG_ANALOG_OC) ?
490 "analog" : "digital");
491
492 /* ATL reset */
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100493 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode | ALL_ATX_RESET);
Nate Case3faefc82008-06-17 11:11:38 -0500494 mdelay(10);
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100495 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode);
Nate Case3faefc82008-06-17 11:11:38 -0500496
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100497 reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, INTERRUPT_ENABLE_MASK);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200498
Nate Case3faefc82008-06-17 11:11:38 -0500499 /*
500 * PORT 1 Control register of the ISP1760 is the OTG control
Thomas Hommel42c65392008-12-18 10:31:40 +0100501 * register on ISP1761. Since there is no OTG or device controller
502 * support in this driver, we use port 1 as a "normal" USB host port on
503 * both chips.
Nate Case3faefc82008-06-17 11:11:38 -0500504 */
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100505 reg_write32(hcd->regs, HC_PORT1_CTRL, PORT1_POWER | PORT1_INIT2);
Thomas Hommel42c65392008-12-18 10:31:40 +0100506 mdelay(10);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200507
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100508 priv->hcs_params = reg_read32(hcd->regs, HC_HCSPARAMS);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200509
510 return priv_init(hcd);
511}
512
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200513static u32 base_to_chip(u32 base)
514{
515 return ((base - 0x400) >> 3);
516}
517
Arvid Brodin7adc14b2011-02-26 22:08:47 +0100518static int last_qtd_of_urb(struct isp1760_qtd *qtd, struct isp1760_qh *qh)
519{
520 struct urb *urb;
521
522 if (list_is_last(&qtd->qtd_list, &qh->qtd_list))
523 return 1;
524
525 urb = qtd->urb;
526 qtd = list_entry(qtd->qtd_list.next, typeof(*qtd), qtd_list);
527 return (qtd->urb != urb);
528}
529
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200530/* magic numbers that can affect system performance */
531#define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
532#define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
533#define EHCI_TUNE_RL_TT 0
534#define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
535#define EHCI_TUNE_MULT_TT 1
536#define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */
537
538static void create_ptd_atl(struct isp1760_qh *qh,
Arvid Brodina041d8e2011-02-26 22:04:40 +0100539 struct isp1760_qtd *qtd, struct ptd *ptd)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200540{
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200541 u32 maxpacket;
542 u32 multi;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200543 u32 rl = RL_COUNTER;
544 u32 nak = NAK_COUNTER;
545
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100546 memset(ptd, 0, sizeof(*ptd));
547
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200548 /* according to 3.6.2, max packet len can not be > 0x400 */
Arvid Brodina041d8e2011-02-26 22:04:40 +0100549 maxpacket = usb_maxpacket(qtd->urb->dev, qtd->urb->pipe,
550 usb_pipeout(qtd->urb->pipe));
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200551 multi = 1 + ((maxpacket >> 11) & 0x3);
552 maxpacket &= 0x7ff;
553
554 /* DW0 */
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200555 ptd->dw0 = DW0_VALID_BIT;
556 ptd->dw0 |= TO_DW0_LENGTH(qtd->length);
557 ptd->dw0 |= TO_DW0_MAXPACKET(maxpacket);
558 ptd->dw0 |= TO_DW0_ENDPOINT(usb_pipeendpoint(qtd->urb->pipe));
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200559
560 /* DW1 */
Arvid Brodina041d8e2011-02-26 22:04:40 +0100561 ptd->dw1 = usb_pipeendpoint(qtd->urb->pipe) >> 1;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200562 ptd->dw1 |= TO_DW1_DEVICE_ADDR(usb_pipedevice(qtd->urb->pipe));
563 ptd->dw1 |= TO_DW1_PID_TOKEN(qtd->packet_type);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200564
Arvid Brodina041d8e2011-02-26 22:04:40 +0100565 if (usb_pipebulk(qtd->urb->pipe))
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200566 ptd->dw1 |= DW1_TRANS_BULK;
Arvid Brodina041d8e2011-02-26 22:04:40 +0100567 else if (usb_pipeint(qtd->urb->pipe))
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200568 ptd->dw1 |= DW1_TRANS_INT;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200569
Arvid Brodina041d8e2011-02-26 22:04:40 +0100570 if (qtd->urb->dev->speed != USB_SPEED_HIGH) {
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200571 /* split transaction */
572
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200573 ptd->dw1 |= DW1_TRANS_SPLIT;
Arvid Brodina041d8e2011-02-26 22:04:40 +0100574 if (qtd->urb->dev->speed == USB_SPEED_LOW)
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200575 ptd->dw1 |= DW1_SE_USB_LOSPEED;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200576
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200577 ptd->dw1 |= TO_DW1_PORT_NUM(qtd->urb->dev->ttport);
578 ptd->dw1 |= TO_DW1_HUB_NUM(qtd->urb->dev->tt->hub->devnum);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200579
580 /* SE bit for Split INT transfers */
Arvid Brodina041d8e2011-02-26 22:04:40 +0100581 if (usb_pipeint(qtd->urb->pipe) &&
582 (qtd->urb->dev->speed == USB_SPEED_LOW))
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100583 ptd->dw1 |= 2 << 16;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200584
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200585 rl = 0;
586 nak = 0;
587 } else {
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200588 ptd->dw0 |= TO_DW0_MULTI(multi);
Arvid Brodina041d8e2011-02-26 22:04:40 +0100589 if (usb_pipecontrol(qtd->urb->pipe) ||
590 usb_pipebulk(qtd->urb->pipe))
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200591 ptd->dw3 |= TO_DW3_PING(qh->ping);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200592 }
593 /* DW2 */
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100594 ptd->dw2 = 0;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200595 ptd->dw2 |= TO_DW2_DATA_START_ADDR(base_to_chip(qtd->payload_addr));
596 ptd->dw2 |= TO_DW2_RL(rl);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200597
598 /* DW3 */
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200599 ptd->dw3 |= TO_DW3_NAKCOUNT(nak);
600 ptd->dw3 |= TO_DW3_DATA_TOGGLE(qh->toggle);
Arvid Brodin7adc14b2011-02-26 22:08:47 +0100601 if (usb_pipecontrol(qtd->urb->pipe)) {
602 if (qtd->data_buffer == qtd->urb->setup_packet)
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200603 ptd->dw3 &= ~TO_DW3_DATA_TOGGLE(1);
Arvid Brodin7adc14b2011-02-26 22:08:47 +0100604 else if (last_qtd_of_urb(qtd, qh))
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200605 ptd->dw3 |= TO_DW3_DATA_TOGGLE(1);
Arvid Brodin7adc14b2011-02-26 22:08:47 +0100606 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200607
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200608 ptd->dw3 |= DW3_ACTIVE_BIT;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200609 /* Cerr */
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200610 ptd->dw3 |= TO_DW3_CERR(ERR_COUNTER);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200611}
612
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100613static void transform_add_int(struct isp1760_qh *qh,
Arvid Brodina041d8e2011-02-26 22:04:40 +0100614 struct isp1760_qtd *qtd, struct ptd *ptd)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200615{
Arvid Brodin65f1b522011-02-26 22:07:35 +0100616 u32 usof;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200617 u32 period;
618
Arvid Brodin65f1b522011-02-26 22:07:35 +0100619 /*
620 * Most of this is guessing. ISP1761 datasheet is quite unclear, and
621 * the algorithm from the original Philips driver code, which was
622 * pretty much used in this driver before as well, is quite horrendous
623 * and, i believe, incorrect. The code below follows the datasheet and
624 * USB2.0 spec as far as I can tell, and plug/unplug seems to be much
625 * more reliable this way (fingers crossed...).
626 */
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200627
Arvid Brodin65f1b522011-02-26 22:07:35 +0100628 if (qtd->urb->dev->speed == USB_SPEED_HIGH) {
629 /* urb->interval is in units of microframes (1/8 ms) */
630 period = qtd->urb->interval >> 3;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200631
Arvid Brodin65f1b522011-02-26 22:07:35 +0100632 if (qtd->urb->interval > 4)
633 usof = 0x01; /* One bit set =>
634 interval 1 ms * uFrame-match */
635 else if (qtd->urb->interval > 2)
636 usof = 0x22; /* Two bits set => interval 1/2 ms */
637 else if (qtd->urb->interval > 1)
638 usof = 0x55; /* Four bits set => interval 1/4 ms */
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200639 else
Arvid Brodin65f1b522011-02-26 22:07:35 +0100640 usof = 0xff; /* All bits set => interval 1/8 ms */
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200641 } else {
Arvid Brodin65f1b522011-02-26 22:07:35 +0100642 /* urb->interval is in units of frames (1 ms) */
643 period = qtd->urb->interval;
644 usof = 0x0f; /* Execute Start Split on any of the
645 four first uFrames */
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200646
Arvid Brodin65f1b522011-02-26 22:07:35 +0100647 /*
648 * First 8 bits in dw5 is uSCS and "specifies which uSOF the
649 * complete split needs to be sent. Valid only for IN." Also,
650 * "All bits can be set to one for every transfer." (p 82,
651 * ISP1761 data sheet.) 0x1c is from Philips driver. Where did
652 * that number come from? 0xff seems to work fine...
653 */
654 /* ptd->dw5 = 0x1c; */
655 ptd->dw5 = 0xff; /* Execute Complete Split on any uFrame */
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200656 }
657
Arvid Brodin65f1b522011-02-26 22:07:35 +0100658 period = period >> 1;/* Ensure equal or shorter period than requested */
659 period &= 0xf8; /* Mask off too large values and lowest unused 3 bits */
660
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100661 ptd->dw2 |= period;
662 ptd->dw4 = usof;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200663}
664
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200665static void create_ptd_int(struct isp1760_qh *qh,
Arvid Brodina041d8e2011-02-26 22:04:40 +0100666 struct isp1760_qtd *qtd, struct ptd *ptd)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200667{
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200668 create_ptd_atl(qh, qtd, ptd);
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100669 transform_add_int(qh, qtd, ptd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200670}
671
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100672static void isp1760_urb_done(struct usb_hcd *hcd, struct urb *urb)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200673__releases(priv->lock)
674__acquires(priv->lock)
675{
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100676 struct isp1760_hcd *priv = hcd_to_priv(hcd);
677
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200678 if (!urb->unlinked) {
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100679 if (urb->status == -EINPROGRESS)
680 urb->status = 0;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200681 }
682
Catalin Marinasdb8516f2010-02-02 15:31:02 +0000683 if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) {
684 void *ptr;
685 for (ptr = urb->transfer_buffer;
686 ptr < urb->transfer_buffer + urb->transfer_buffer_length;
687 ptr += PAGE_SIZE)
688 flush_dcache_page(virt_to_page(ptr));
689 }
690
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200691 /* complete() can reenter this HCD */
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100692 usb_hcd_unlink_urb_from_ep(hcd, urb);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200693 spin_unlock(&priv->lock);
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100694 usb_hcd_giveback_urb(hcd, urb, urb->status);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200695 spin_lock(&priv->lock);
696}
697
Arvid Brodin34537732011-04-26 21:47:37 +0200698static struct isp1760_qtd *qtd_alloc(gfp_t flags, struct urb *urb,
699 u8 packet_type)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200700{
Arvid Brodin34537732011-04-26 21:47:37 +0200701 struct isp1760_qtd *qtd;
702
703 qtd = kmem_cache_zalloc(qtd_cachep, flags);
704 if (!qtd)
705 return NULL;
706
707 INIT_LIST_HEAD(&qtd->qtd_list);
708 qtd->urb = urb;
709 qtd->packet_type = packet_type;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200710 qtd->status = QTD_ENQUEUED;
711 qtd->actual_length = 0;
Arvid Brodin34537732011-04-26 21:47:37 +0200712
713 return qtd;
714}
715
716static void qtd_free(struct isp1760_qtd *qtd)
717{
718 WARN_ON(qtd->payload_addr);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200719 kmem_cache_free(qtd_cachep, qtd);
720}
721
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200722static void start_bus_transfer(struct usb_hcd *hcd, u32 ptd_offset, int slot,
723 struct slotinfo *slots, struct isp1760_qtd *qtd,
724 struct isp1760_qh *qh, struct ptd *ptd)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200725{
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100726 struct isp1760_hcd *priv = hcd_to_priv(hcd);
Arvid Brodind05b6ec2011-05-20 00:17:45 +0200727 int skip_map;
728
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200729 WARN_ON((slot < 0) || (slot > 31));
730 WARN_ON(qtd->length && !qtd->payload_addr);
731 WARN_ON(slots[slot].qtd);
732 WARN_ON(slots[slot].qh);
733 WARN_ON(qtd->status != QTD_PAYLOAD_ALLOC);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200734
Arvid Brodind05b6ec2011-05-20 00:17:45 +0200735 /* Make sure done map has not triggered from some unlinked transfer */
736 if (ptd_offset == ATL_PTD_OFFSET) {
737 priv->atl_done_map |= reg_read32(hcd->regs,
738 HC_ATL_PTD_DONEMAP_REG);
Arvid Brodin6477acc2011-08-21 08:29:28 +0200739 priv->atl_done_map &= ~(1 << slot);
740 } else {
741 priv->int_done_map |= reg_read32(hcd->regs,
742 HC_INT_PTD_DONEMAP_REG);
743 priv->int_done_map &= ~(1 << slot);
744 }
Arvid Brodind05b6ec2011-05-20 00:17:45 +0200745
Arvid Brodin6477acc2011-08-21 08:29:28 +0200746 qh->slot = slot;
747 qtd->status = QTD_XFER_STARTED;
748 slots[slot].timestamp = jiffies;
749 slots[slot].qtd = qtd;
750 slots[slot].qh = qh;
751 ptd_write(hcd->regs, ptd_offset, slot, ptd);
752
753 if (ptd_offset == ATL_PTD_OFFSET) {
Arvid Brodind05b6ec2011-05-20 00:17:45 +0200754 skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG);
755 skip_map &= ~(1 << qh->slot);
756 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map);
757 } else {
Arvid Brodind05b6ec2011-05-20 00:17:45 +0200758 skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG);
759 skip_map &= ~(1 << qh->slot);
760 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map);
761 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200762}
763
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200764static int is_short_bulk(struct isp1760_qtd *qtd)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200765{
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200766 return (usb_pipebulk(qtd->urb->pipe) &&
767 (qtd->actual_length < qtd->length));
768}
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200769
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200770static void collect_qtds(struct usb_hcd *hcd, struct isp1760_qh *qh,
771 struct list_head *urb_list)
772{
773 int last_qtd;
774 struct isp1760_qtd *qtd, *qtd_next;
775 struct urb_listitem *urb_listitem;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200776
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200777 list_for_each_entry_safe(qtd, qtd_next, &qh->qtd_list, qtd_list) {
778 if (qtd->status < QTD_XFER_COMPLETE)
779 break;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200780
Arvid Brodin38679b72011-08-21 08:29:27 +0200781 last_qtd = last_qtd_of_urb(qtd, qh);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200782
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200783 if ((!last_qtd) && (qtd->status == QTD_RETIRE))
784 qtd_next->status = QTD_RETIRE;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200785
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200786 if (qtd->status == QTD_XFER_COMPLETE) {
787 if (qtd->actual_length) {
788 switch (qtd->packet_type) {
789 case IN_PID:
790 mem_reads8(hcd->regs, qtd->payload_addr,
791 qtd->data_buffer,
792 qtd->actual_length);
793 /* Fall through (?) */
794 case OUT_PID:
795 qtd->urb->actual_length +=
796 qtd->actual_length;
797 /* Fall through ... */
798 case SETUP_PID:
799 break;
800 }
801 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200802
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200803 if (is_short_bulk(qtd)) {
804 if (qtd->urb->transfer_flags & URB_SHORT_NOT_OK)
805 qtd->urb->status = -EREMOTEIO;
806 if (!last_qtd)
807 qtd_next->status = QTD_RETIRE;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200808 }
809 }
810
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200811 if (qtd->payload_addr)
812 free_mem(hcd, qtd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200813
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200814 if (last_qtd) {
815 if ((qtd->status == QTD_RETIRE) &&
816 (qtd->urb->status == -EINPROGRESS))
817 qtd->urb->status = -EPIPE;
818 /* Defer calling of urb_done() since it releases lock */
819 urb_listitem = kmem_cache_zalloc(urb_listitem_cachep,
820 GFP_ATOMIC);
821 if (unlikely(!urb_listitem))
Arvid Brodin38679b72011-08-21 08:29:27 +0200822 break; /* Try again on next call */
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200823 urb_listitem->urb = qtd->urb;
824 list_add_tail(&urb_listitem->urb_list, urb_list);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200825 }
826
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200827 list_del(&qtd->qtd_list);
828 qtd_free(qtd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200829 }
830}
831
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200832#define ENQUEUE_DEPTH 2
833static void enqueue_qtds(struct usb_hcd *hcd, struct isp1760_qh *qh)
834{
835 struct isp1760_hcd *priv = hcd_to_priv(hcd);
836 int ptd_offset;
837 struct slotinfo *slots;
838 int curr_slot, free_slot;
839 int n;
840 struct ptd ptd;
841 struct isp1760_qtd *qtd;
842
843 if (unlikely(list_empty(&qh->qtd_list))) {
844 WARN_ON(1);
845 return;
846 }
847
848 if (usb_pipeint(list_entry(qh->qtd_list.next, struct isp1760_qtd,
849 qtd_list)->urb->pipe)) {
850 ptd_offset = INT_PTD_OFFSET;
851 slots = priv->int_slots;
852 } else {
853 ptd_offset = ATL_PTD_OFFSET;
854 slots = priv->atl_slots;
855 }
856
857 free_slot = -1;
858 for (curr_slot = 0; curr_slot < 32; curr_slot++) {
859 if ((free_slot == -1) && (slots[curr_slot].qtd == NULL))
860 free_slot = curr_slot;
861 if (slots[curr_slot].qh == qh)
862 break;
863 }
864
865 n = 0;
866 list_for_each_entry(qtd, &qh->qtd_list, qtd_list) {
867 if (qtd->status == QTD_ENQUEUED) {
868 WARN_ON(qtd->payload_addr);
869 alloc_mem(hcd, qtd);
870 if ((qtd->length) && (!qtd->payload_addr))
871 break;
872
873 if ((qtd->length) &&
874 ((qtd->packet_type == SETUP_PID) ||
875 (qtd->packet_type == OUT_PID))) {
876 mem_writes8(hcd->regs, qtd->payload_addr,
877 qtd->data_buffer, qtd->length);
878 }
879
880 qtd->status = QTD_PAYLOAD_ALLOC;
881 }
882
883 if (qtd->status == QTD_PAYLOAD_ALLOC) {
884/*
885 if ((curr_slot > 31) && (free_slot == -1))
886 dev_dbg(hcd->self.controller, "%s: No slot "
887 "available for transfer\n", __func__);
888*/
889 /* Start xfer for this endpoint if not already done */
890 if ((curr_slot > 31) && (free_slot > -1)) {
891 if (usb_pipeint(qtd->urb->pipe))
892 create_ptd_int(qh, qtd, &ptd);
893 else
894 create_ptd_atl(qh, qtd, &ptd);
895
896 start_bus_transfer(hcd, ptd_offset, free_slot,
897 slots, qtd, qh, &ptd);
898 curr_slot = free_slot;
899 }
900
901 n++;
902 if (n >= ENQUEUE_DEPTH)
903 break;
904 }
905 }
906}
907
908void schedule_ptds(struct usb_hcd *hcd)
909{
910 struct isp1760_hcd *priv;
911 struct isp1760_qh *qh, *qh_next;
912 struct list_head *ep_queue;
913 struct usb_host_endpoint *ep;
914 LIST_HEAD(urb_list);
915 struct urb_listitem *urb_listitem, *urb_listitem_next;
916
917 if (!hcd) {
918 WARN_ON(1);
919 return;
920 }
921
922 priv = hcd_to_priv(hcd);
923
924 /*
925 * check finished/retired xfers, transfer payloads, call urb_done()
926 */
927 ep_queue = &priv->interruptqhs;
928 while (ep_queue) {
929 list_for_each_entry_safe(qh, qh_next, ep_queue, qh_list) {
930 ep = list_entry(qh->qtd_list.next, struct isp1760_qtd,
931 qtd_list)->urb->ep;
932 collect_qtds(hcd, qh, &urb_list);
933 if (list_empty(&qh->qtd_list)) {
934 list_del(&qh->qh_list);
935 if (ep->hcpriv == NULL) {
936 /* Endpoint has been disabled, so we
937 can free the associated queue head. */
938 qh_free(qh);
939 }
940 }
941 }
942
943 if (ep_queue == &priv->interruptqhs)
944 ep_queue = &priv->controlqhs;
945 else if (ep_queue == &priv->controlqhs)
946 ep_queue = &priv->bulkqhs;
947 else
948 ep_queue = NULL;
949 }
950
951 list_for_each_entry_safe(urb_listitem, urb_listitem_next, &urb_list,
952 urb_list) {
953 isp1760_urb_done(hcd, urb_listitem->urb);
954 kmem_cache_free(urb_listitem_cachep, urb_listitem);
955 }
956
957 /*
958 * Schedule packets for transfer.
959 *
960 * According to USB2.0 specification:
961 *
962 * 1st prio: interrupt xfers, up to 80 % of bandwidth
963 * 2nd prio: control xfers
964 * 3rd prio: bulk xfers
965 *
966 * ... but let's use a simpler scheme here (mostly because ISP1761 doc
967 * is very unclear on how to prioritize traffic):
968 *
969 * 1) Enqueue any queued control transfers, as long as payload chip mem
970 * and PTD ATL slots are available.
971 * 2) Enqueue any queued INT transfers, as long as payload chip mem
972 * and PTD INT slots are available.
973 * 3) Enqueue any queued bulk transfers, as long as payload chip mem
974 * and PTD ATL slots are available.
975 *
976 * Use double buffering (ENQUEUE_DEPTH==2) as a compromise between
977 * conservation of chip mem and performance.
978 *
979 * I'm sure this scheme could be improved upon!
980 */
981 ep_queue = &priv->controlqhs;
982 while (ep_queue) {
983 list_for_each_entry_safe(qh, qh_next, ep_queue, qh_list)
984 enqueue_qtds(hcd, qh);
985
986 if (ep_queue == &priv->controlqhs)
987 ep_queue = &priv->interruptqhs;
988 else if (ep_queue == &priv->interruptqhs)
989 ep_queue = &priv->bulkqhs;
990 else
991 ep_queue = NULL;
992 }
993}
994
995#define PTD_STATE_QTD_DONE 1
996#define PTD_STATE_QTD_RELOAD 2
997#define PTD_STATE_URB_RETIRE 3
998
999static int check_int_transfer(struct usb_hcd *hcd, struct ptd *ptd,
1000 struct urb *urb)
1001{
1002 __dw dw4;
1003 int i;
1004
1005 dw4 = ptd->dw4;
1006 dw4 >>= 8;
1007
1008 /* FIXME: ISP1761 datasheet does not say what to do with these. Do we
1009 need to handle these errors? Is it done in hardware? */
1010
1011 if (ptd->dw3 & DW3_HALT_BIT) {
1012
1013 urb->status = -EPROTO; /* Default unknown error */
1014
1015 for (i = 0; i < 8; i++) {
1016 switch (dw4 & 0x7) {
1017 case INT_UNDERRUN:
1018 dev_dbg(hcd->self.controller, "%s: underrun "
1019 "during uFrame %d\n",
1020 __func__, i);
1021 urb->status = -ECOMM; /* Could not write data */
1022 break;
1023 case INT_EXACT:
1024 dev_dbg(hcd->self.controller, "%s: transaction "
1025 "error during uFrame %d\n",
1026 __func__, i);
1027 urb->status = -EPROTO; /* timeout, bad CRC, PID
1028 error etc. */
1029 break;
1030 case INT_BABBLE:
1031 dev_dbg(hcd->self.controller, "%s: babble "
1032 "error during uFrame %d\n",
1033 __func__, i);
1034 urb->status = -EOVERFLOW;
1035 break;
1036 }
1037 dw4 >>= 3;
1038 }
1039
1040 return PTD_STATE_URB_RETIRE;
1041 }
1042
1043 return PTD_STATE_QTD_DONE;
1044}
1045
1046static int check_atl_transfer(struct usb_hcd *hcd, struct ptd *ptd,
1047 struct urb *urb)
1048{
1049 WARN_ON(!ptd);
1050 if (ptd->dw3 & DW3_HALT_BIT) {
1051 if (ptd->dw3 & DW3_BABBLE_BIT)
1052 urb->status = -EOVERFLOW;
1053 else if (FROM_DW3_CERR(ptd->dw3))
1054 urb->status = -EPIPE; /* Stall */
1055 else if (ptd->dw3 & DW3_ERROR_BIT)
1056 urb->status = -EPROTO; /* XactErr */
1057 else
1058 urb->status = -EPROTO; /* Unknown */
1059/*
1060 dev_dbg(hcd->self.controller, "%s: ptd error:\n"
1061 " dw0: %08x dw1: %08x dw2: %08x dw3: %08x\n"
1062 " dw4: %08x dw5: %08x dw6: %08x dw7: %08x\n",
1063 __func__,
1064 ptd->dw0, ptd->dw1, ptd->dw2, ptd->dw3,
1065 ptd->dw4, ptd->dw5, ptd->dw6, ptd->dw7);
1066*/
1067 return PTD_STATE_URB_RETIRE;
1068 }
1069
1070 if ((ptd->dw3 & DW3_ERROR_BIT) && (ptd->dw3 & DW3_ACTIVE_BIT)) {
1071 /* Transfer Error, *but* active and no HALT -> reload */
1072 dev_dbg(hcd->self.controller, "PID error; reloading ptd\n");
1073 return PTD_STATE_QTD_RELOAD;
1074 }
1075
1076 if (!FROM_DW3_NAKCOUNT(ptd->dw3) && (ptd->dw3 & DW3_ACTIVE_BIT)) {
1077 /*
1078 * NAKs are handled in HW by the chip. Usually if the
1079 * device is not able to send data fast enough.
1080 * This happens mostly on slower hardware.
1081 */
1082 return PTD_STATE_QTD_RELOAD;
1083 }
1084
1085 return PTD_STATE_QTD_DONE;
1086}
1087
Arvid Brodin6d50c602011-08-21 08:29:26 +02001088static void handle_done_ptds(struct usb_hcd *hcd)
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001089{
1090 struct isp1760_hcd *priv = hcd_to_priv(hcd);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001091 struct ptd ptd;
1092 struct isp1760_qh *qh;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001093 int slot;
1094 int state;
1095 struct slotinfo *slots;
1096 u32 ptd_offset;
1097 struct isp1760_qtd *qtd;
1098 int modified;
Arvid Brodin6d50c602011-08-21 08:29:26 +02001099 int skip_map;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001100
Arvid Brodin6d50c602011-08-21 08:29:26 +02001101 skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG);
1102 priv->int_done_map &= ~skip_map;
1103 skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG);
1104 priv->atl_done_map &= ~skip_map;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001105
Arvid Brodin6d50c602011-08-21 08:29:26 +02001106 modified = priv->int_done_map || priv->atl_done_map;
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001107
1108 while (priv->int_done_map || priv->atl_done_map) {
1109 if (priv->int_done_map) {
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001110 /* INT ptd */
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001111 slot = __ffs(priv->int_done_map);
1112 priv->int_done_map &= ~(1 << slot);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001113 slots = priv->int_slots;
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001114 /* This should not trigger, and could be removed if
1115 noone have any problems with it triggering: */
1116 if (!slots[slot].qh) {
1117 WARN_ON(1);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001118 continue;
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001119 }
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001120 ptd_offset = INT_PTD_OFFSET;
1121 ptd_read(hcd->regs, INT_PTD_OFFSET, slot, &ptd);
1122 state = check_int_transfer(hcd, &ptd,
1123 slots[slot].qtd->urb);
1124 } else {
1125 /* ATL ptd */
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001126 slot = __ffs(priv->atl_done_map);
1127 priv->atl_done_map &= ~(1 << slot);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001128 slots = priv->atl_slots;
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001129 /* This should not trigger, and could be removed if
1130 noone have any problems with it triggering: */
1131 if (!slots[slot].qh) {
1132 WARN_ON(1);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001133 continue;
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001134 }
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001135 ptd_offset = ATL_PTD_OFFSET;
1136 ptd_read(hcd->regs, ATL_PTD_OFFSET, slot, &ptd);
1137 state = check_atl_transfer(hcd, &ptd,
1138 slots[slot].qtd->urb);
1139 }
1140
1141 qtd = slots[slot].qtd;
1142 slots[slot].qtd = NULL;
1143 qh = slots[slot].qh;
1144 slots[slot].qh = NULL;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001145 qh->slot = -1;
1146
1147 WARN_ON(qtd->status != QTD_XFER_STARTED);
1148
1149 switch (state) {
1150 case PTD_STATE_QTD_DONE:
1151 if ((usb_pipeint(qtd->urb->pipe)) &&
1152 (qtd->urb->dev->speed != USB_SPEED_HIGH))
1153 qtd->actual_length =
1154 FROM_DW3_SCS_NRBYTESTRANSFERRED(ptd.dw3);
1155 else
1156 qtd->actual_length =
1157 FROM_DW3_NRBYTESTRANSFERRED(ptd.dw3);
1158
1159 qtd->status = QTD_XFER_COMPLETE;
1160 if (list_is_last(&qtd->qtd_list, &qh->qtd_list) ||
1161 is_short_bulk(qtd))
1162 qtd = NULL;
1163 else
1164 qtd = list_entry(qtd->qtd_list.next,
1165 typeof(*qtd), qtd_list);
1166
1167 qh->toggle = FROM_DW3_DATA_TOGGLE(ptd.dw3);
1168 qh->ping = FROM_DW3_PING(ptd.dw3);
1169 break;
1170
1171 case PTD_STATE_QTD_RELOAD: /* QTD_RETRY, for atls only */
1172 qtd->status = QTD_PAYLOAD_ALLOC;
1173 ptd.dw0 |= DW0_VALID_BIT;
1174 /* RL counter = ERR counter */
1175 ptd.dw3 &= ~TO_DW3_NAKCOUNT(0xf);
1176 ptd.dw3 |= TO_DW3_NAKCOUNT(FROM_DW2_RL(ptd.dw2));
1177 ptd.dw3 &= ~TO_DW3_CERR(3);
1178 ptd.dw3 |= TO_DW3_CERR(ERR_COUNTER);
1179 qh->toggle = FROM_DW3_DATA_TOGGLE(ptd.dw3);
1180 qh->ping = FROM_DW3_PING(ptd.dw3);
1181 break;
1182
1183 case PTD_STATE_URB_RETIRE:
1184 qtd->status = QTD_RETIRE;
1185 qtd = NULL;
1186 qh->toggle = 0;
1187 qh->ping = 0;
1188 break;
1189
1190 default:
1191 WARN_ON(1);
1192 continue;
1193 }
1194
1195 if (qtd && (qtd->status == QTD_PAYLOAD_ALLOC)) {
1196 if (slots == priv->int_slots) {
1197 if (state == PTD_STATE_QTD_RELOAD)
1198 dev_err(hcd->self.controller,
1199 "%s: PTD_STATE_QTD_RELOAD on "
1200 "interrupt packet\n", __func__);
1201 if (state != PTD_STATE_QTD_RELOAD)
1202 create_ptd_int(qh, qtd, &ptd);
1203 } else {
1204 if (state != PTD_STATE_QTD_RELOAD)
1205 create_ptd_atl(qh, qtd, &ptd);
1206 }
1207
1208 start_bus_transfer(hcd, ptd_offset, slot, slots, qtd,
1209 qh, &ptd);
1210 }
1211 }
1212
1213 if (modified)
1214 schedule_ptds(hcd);
Arvid Brodin6d50c602011-08-21 08:29:26 +02001215}
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001216
Arvid Brodin6d50c602011-08-21 08:29:26 +02001217static irqreturn_t isp1760_irq(struct usb_hcd *hcd)
1218{
1219 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1220 u32 imask;
1221 irqreturn_t irqret = IRQ_NONE;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001222
Arvid Brodin6d50c602011-08-21 08:29:26 +02001223 spin_lock(&priv->lock);
1224
1225 if (!(hcd->state & HC_STATE_RUNNING))
1226 goto leave;
1227
1228 imask = reg_read32(hcd->regs, HC_INTERRUPT_REG);
1229 if (unlikely(!imask))
1230 goto leave;
1231 reg_write32(hcd->regs, HC_INTERRUPT_REG, imask); /* Clear */
1232
1233 priv->int_done_map |= reg_read32(hcd->regs, HC_INT_PTD_DONEMAP_REG);
1234 priv->atl_done_map |= reg_read32(hcd->regs, HC_ATL_PTD_DONEMAP_REG);
1235
1236 handle_done_ptds(hcd);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001237
1238 irqret = IRQ_HANDLED;
1239leave:
1240 spin_unlock(&priv->lock);
1241
1242 return irqret;
1243}
1244
Arvid Brodin6d50c602011-08-21 08:29:26 +02001245/*
1246 * Workaround for problem described in chip errata 2:
1247 *
1248 * Sometimes interrupts are not generated when ATL (not INT?) completion occurs.
1249 * One solution suggested in the errata is to use SOF interrupts _instead_of_
1250 * ATL done interrupts (the "instead of" might be important since it seems
1251 * enabling ATL interrupts also causes the chip to sometimes - rarely - "forget"
1252 * to set the PTD's done bit in addition to not generating an interrupt!).
1253 *
1254 * So if we use SOF + ATL interrupts, we sometimes get stale PTDs since their
1255 * done bit is not being set. This is bad - it blocks the endpoint until reboot.
1256 *
1257 * If we use SOF interrupts only, we get latency between ptd completion and the
1258 * actual handling. This is very noticeable in testusb runs which takes several
1259 * minutes longer without ATL interrupts.
1260 *
1261 * A better solution is to run the code below every SLOT_CHECK_PERIOD ms. If it
1262 * finds active ATL slots which are older than SLOT_TIMEOUT ms, it checks the
1263 * slot's ACTIVE and VALID bits. If these are not set, the ptd is considered
1264 * completed and its done map bit is set.
1265 *
1266 * The values of SLOT_TIMEOUT and SLOT_CHECK_PERIOD have been arbitrarily chosen
1267 * not to cause too much lag when this HW bug occurs, while still hopefully
1268 * ensuring that the check does not falsely trigger.
1269 */
Arvid Brodin6477acc2011-08-21 08:29:28 +02001270#define SLOT_TIMEOUT 300
Arvid Brodin6d50c602011-08-21 08:29:26 +02001271#define SLOT_CHECK_PERIOD 200
1272static struct timer_list errata2_timer;
1273
1274void errata2_function(unsigned long data)
1275{
1276 struct usb_hcd *hcd = (struct usb_hcd *) data;
1277 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1278 int slot;
1279 struct ptd ptd;
1280 unsigned long spinflags;
1281
1282 spin_lock_irqsave(&priv->lock, spinflags);
1283
1284 for (slot = 0; slot < 32; slot++)
Arvid Brodin6477acc2011-08-21 08:29:28 +02001285 if (priv->atl_slots[slot].qh && time_after(jiffies,
1286 priv->atl_slots[slot].timestamp +
1287 SLOT_TIMEOUT * HZ / 1000)) {
Arvid Brodin6d50c602011-08-21 08:29:26 +02001288 ptd_read(hcd->regs, ATL_PTD_OFFSET, slot, &ptd);
1289 if (!FROM_DW0_VALID(ptd.dw0) &&
1290 !FROM_DW3_ACTIVE(ptd.dw3))
1291 priv->atl_done_map |= 1 << slot;
1292 }
1293
Arvid Brodin6477acc2011-08-21 08:29:28 +02001294 if (priv->atl_done_map)
1295 handle_done_ptds(hcd);
Arvid Brodin6d50c602011-08-21 08:29:26 +02001296
1297 spin_unlock_irqrestore(&priv->lock, spinflags);
1298
1299 errata2_timer.expires = jiffies + SLOT_CHECK_PERIOD * HZ / 1000;
1300 add_timer(&errata2_timer);
1301}
1302
Arvid Brodin0ba79052011-08-21 08:29:25 +02001303static int isp1760_run(struct usb_hcd *hcd)
1304{
1305 int retval;
1306 u32 temp;
1307 u32 command;
1308 u32 chipid;
1309
1310 hcd->uses_new_polling = 1;
1311
1312 hcd->state = HC_STATE_RUNNING;
1313
1314 /* Set PTD interrupt AND & OR maps */
1315 reg_write32(hcd->regs, HC_ATL_IRQ_MASK_AND_REG, 0);
1316 reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, 0xffffffff);
1317 reg_write32(hcd->regs, HC_INT_IRQ_MASK_AND_REG, 0);
1318 reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, 0xffffffff);
1319 reg_write32(hcd->regs, HC_ISO_IRQ_MASK_AND_REG, 0);
1320 reg_write32(hcd->regs, HC_ISO_IRQ_MASK_OR_REG, 0xffffffff);
1321 /* step 23 passed */
1322
1323 temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL);
1324 reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp | HW_GLOBAL_INTR_EN);
1325
1326 command = reg_read32(hcd->regs, HC_USBCMD);
1327 command &= ~(CMD_LRESET|CMD_RESET);
1328 command |= CMD_RUN;
1329 reg_write32(hcd->regs, HC_USBCMD, command);
1330
1331 retval = handshake(hcd, HC_USBCMD, CMD_RUN, CMD_RUN, 250 * 1000);
1332 if (retval)
1333 return retval;
1334
1335 /*
1336 * XXX
1337 * Spec says to write FLAG_CF as last config action, priv code grabs
1338 * the semaphore while doing so.
1339 */
1340 down_write(&ehci_cf_port_reset_rwsem);
1341 reg_write32(hcd->regs, HC_CONFIGFLAG, FLAG_CF);
1342
1343 retval = handshake(hcd, HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 250 * 1000);
1344 up_write(&ehci_cf_port_reset_rwsem);
1345 if (retval)
1346 return retval;
1347
Arvid Brodin6d50c602011-08-21 08:29:26 +02001348 init_timer(&errata2_timer);
1349 errata2_timer.function = errata2_function;
1350 errata2_timer.data = (unsigned long) hcd;
1351 errata2_timer.expires = jiffies + SLOT_CHECK_PERIOD * HZ / 1000;
1352 add_timer(&errata2_timer);
1353
Arvid Brodin0ba79052011-08-21 08:29:25 +02001354 chipid = reg_read32(hcd->regs, HC_CHIP_ID_REG);
1355 dev_info(hcd->self.controller, "USB ISP %04x HW rev. %d started\n",
1356 chipid & 0xffff, chipid >> 16);
1357
1358 /* PTD Register Init Part 2, Step 28 */
1359
1360 /* Setup registers controlling PTD checking */
1361 reg_write32(hcd->regs, HC_ATL_PTD_LASTPTD_REG, 0x80000000);
1362 reg_write32(hcd->regs, HC_INT_PTD_LASTPTD_REG, 0x80000000);
1363 reg_write32(hcd->regs, HC_ISO_PTD_LASTPTD_REG, 0x00000001);
1364 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, 0xffffffff);
1365 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, 0xffffffff);
1366 reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, 0xffffffff);
1367 reg_write32(hcd->regs, HC_BUFFER_STATUS_REG,
1368 ATL_BUF_FILL | INT_BUF_FILL);
1369
1370 /* GRR this is run-once init(), being done every time the HC starts.
1371 * So long as they're part of class devices, we can't do it init()
1372 * since the class device isn't created that early.
1373 */
1374 return 0;
1375}
1376
Arvid Brodin34537732011-04-26 21:47:37 +02001377static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len)
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001378{
Arvid Brodin34537732011-04-26 21:47:37 +02001379 qtd->data_buffer = databuffer;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001380
Arvid Brodin34537732011-04-26 21:47:37 +02001381 if (len > MAX_PAYLOAD_SIZE)
1382 len = MAX_PAYLOAD_SIZE;
1383 qtd->length = len;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001384
Arvid Brodin34537732011-04-26 21:47:37 +02001385 return qtd->length;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001386}
1387
Arvid Brodin34537732011-04-26 21:47:37 +02001388static void qtd_list_free(struct list_head *qtd_list)
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001389{
Arvid Brodin34537732011-04-26 21:47:37 +02001390 struct isp1760_qtd *qtd, *qtd_next;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001391
Arvid Brodin34537732011-04-26 21:47:37 +02001392 list_for_each_entry_safe(qtd, qtd_next, qtd_list, qtd_list) {
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001393 list_del(&qtd->qtd_list);
Arvid Brodin34537732011-04-26 21:47:37 +02001394 qtd_free(qtd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001395 }
1396}
1397
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001398/*
Arvid Brodin34537732011-04-26 21:47:37 +02001399 * Packetize urb->transfer_buffer into list of packets of size wMaxPacketSize.
1400 * Also calculate the PID type (SETUP/IN/OUT) for each packet.
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001401 */
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001402#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
Arvid Brodin34537732011-04-26 21:47:37 +02001403static void packetize_urb(struct usb_hcd *hcd,
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001404 struct urb *urb, struct list_head *head, gfp_t flags)
1405{
Arvid Brodinfd436ae2011-02-26 22:03:49 +01001406 struct isp1760_qtd *qtd;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001407 void *buf;
Arvid Brodin34537732011-04-26 21:47:37 +02001408 int len, maxpacketsize;
1409 u8 packet_type;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001410
1411 /*
1412 * URBs map to sequences of QTDs: one logical transaction
1413 */
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001414
Arvid Brodin34537732011-04-26 21:47:37 +02001415 if (!urb->transfer_buffer && urb->transfer_buffer_length) {
1416 /* XXX This looks like usb storage / SCSI bug */
1417 dev_err(hcd->self.controller,
1418 "buf is null, dma is %08lx len is %d\n",
1419 (long unsigned)urb->transfer_dma,
1420 urb->transfer_buffer_length);
1421 WARN_ON(1);
1422 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001423
Arvid Brodin34537732011-04-26 21:47:37 +02001424 if (usb_pipein(urb->pipe))
1425 packet_type = IN_PID;
1426 else
1427 packet_type = OUT_PID;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001428
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001429 if (usb_pipecontrol(urb->pipe)) {
Arvid Brodin34537732011-04-26 21:47:37 +02001430 qtd = qtd_alloc(flags, urb, SETUP_PID);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001431 if (!qtd)
1432 goto cleanup;
Arvid Brodin34537732011-04-26 21:47:37 +02001433 qtd_fill(qtd, urb->setup_packet, sizeof(struct usb_ctrlrequest));
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001434 list_add_tail(&qtd->qtd_list, head);
1435
1436 /* for zero length DATA stages, STATUS is always IN */
Arvid Brodin34537732011-04-26 21:47:37 +02001437 if (urb->transfer_buffer_length == 0)
1438 packet_type = IN_PID;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001439 }
1440
Arvid Brodin34537732011-04-26 21:47:37 +02001441 maxpacketsize = max_packet(usb_maxpacket(urb->dev, urb->pipe,
1442 usb_pipeout(urb->pipe)));
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001443
1444 /*
1445 * buffer gets wrapped in one or more qtds;
1446 * last one may be "short" (including zero len)
1447 * and may serve as a control status ack
1448 */
Arvid Brodin34537732011-04-26 21:47:37 +02001449 buf = urb->transfer_buffer;
1450 len = urb->transfer_buffer_length;
1451
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001452 for (;;) {
1453 int this_qtd_len;
1454
Arvid Brodin34537732011-04-26 21:47:37 +02001455 qtd = qtd_alloc(flags, urb, packet_type);
1456 if (!qtd)
1457 goto cleanup;
1458 this_qtd_len = qtd_fill(qtd, buf, len);
1459 list_add_tail(&qtd->qtd_list, head);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001460
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001461 len -= this_qtd_len;
1462 buf += this_qtd_len;
1463
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001464 if (len <= 0)
1465 break;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001466 }
1467
1468 /*
1469 * control requests may need a terminating data "status" ack;
1470 * bulk ones may need a terminating short packet (zero length).
1471 */
1472 if (urb->transfer_buffer_length != 0) {
1473 int one_more = 0;
1474
1475 if (usb_pipecontrol(urb->pipe)) {
1476 one_more = 1;
Arvid Brodin34537732011-04-26 21:47:37 +02001477 if (packet_type == IN_PID)
1478 packet_type = OUT_PID;
1479 else
1480 packet_type = IN_PID;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001481 } else if (usb_pipebulk(urb->pipe)
1482 && (urb->transfer_flags & URB_ZERO_PACKET)
Arvid Brodin34537732011-04-26 21:47:37 +02001483 && !(urb->transfer_buffer_length %
1484 maxpacketsize)) {
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001485 one_more = 1;
1486 }
1487 if (one_more) {
Arvid Brodin34537732011-04-26 21:47:37 +02001488 qtd = qtd_alloc(flags, urb, packet_type);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001489 if (!qtd)
1490 goto cleanup;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001491
1492 /* never any data in such packets */
Arvid Brodin34537732011-04-26 21:47:37 +02001493 qtd_fill(qtd, NULL, 0);
1494 list_add_tail(&qtd->qtd_list, head);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001495 }
1496 }
1497
Arvid Brodin34537732011-04-26 21:47:37 +02001498 return;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001499
1500cleanup:
Arvid Brodin34537732011-04-26 21:47:37 +02001501 qtd_list_free(head);
1502}
1503
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001504static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1505 gfp_t mem_flags)
1506{
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001507 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1508 struct list_head *ep_queue;
1509 struct isp1760_qh *qh, *qhit;
1510 unsigned long spinflags;
1511 LIST_HEAD(new_qtds);
1512 int retval;
1513 int qh_in_queue;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001514
1515 switch (usb_pipetype(urb->pipe)) {
1516 case PIPE_CONTROL:
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001517 ep_queue = &priv->controlqhs;
1518 break;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001519 case PIPE_BULK:
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001520 ep_queue = &priv->bulkqhs;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001521 break;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001522 case PIPE_INTERRUPT:
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001523 if (urb->interval < 0)
1524 return -EINVAL;
1525 /* FIXME: Check bandwidth */
1526 ep_queue = &priv->interruptqhs;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001527 break;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001528 case PIPE_ISOCHRONOUS:
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001529 dev_err(hcd->self.controller, "%s: isochronous USB packets "
1530 "not yet supported\n",
1531 __func__);
1532 return -EPIPE;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001533 default:
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001534 dev_err(hcd->self.controller, "%s: unknown pipe type\n",
1535 __func__);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001536 return -EPIPE;
1537 }
1538
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001539 if (usb_pipein(urb->pipe))
1540 urb->actual_length = 0;
1541
1542 packetize_urb(hcd, urb, &new_qtds, mem_flags);
1543 if (list_empty(&new_qtds))
Arvid Brodin34537732011-04-26 21:47:37 +02001544 return -ENOMEM;
1545
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001546 retval = 0;
1547 spin_lock_irqsave(&priv->lock, spinflags);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001548
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001549 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
1550 retval = -ESHUTDOWN;
1551 goto out;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001552 }
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001553 retval = usb_hcd_link_urb_to_ep(hcd, urb);
1554 if (retval)
1555 goto out;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001556
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001557 qh = urb->ep->hcpriv;
1558 if (qh) {
1559 qh_in_queue = 0;
1560 list_for_each_entry(qhit, ep_queue, qh_list) {
1561 if (qhit == qh) {
1562 qh_in_queue = 1;
Warren Free0afb20e2009-05-08 10:27:08 +02001563 break;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001564 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001565 }
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001566 if (!qh_in_queue)
1567 list_add_tail(&qh->qh_list, ep_queue);
1568 } else {
1569 qh = qh_alloc(GFP_ATOMIC);
1570 if (!qh) {
1571 retval = -ENOMEM;
Arvid Brodin38679b72011-08-21 08:29:27 +02001572 usb_hcd_unlink_urb_from_ep(hcd, urb);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001573 goto out;
1574 }
1575 list_add_tail(&qh->qh_list, ep_queue);
1576 urb->ep->hcpriv = qh;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001577 }
1578
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001579 list_splice_tail(&new_qtds, &qh->qtd_list);
1580 schedule_ptds(hcd);
1581
1582out:
1583 spin_unlock_irqrestore(&priv->lock, spinflags);
1584 return retval;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001585}
1586
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001587static void kill_transfer(struct usb_hcd *hcd, struct urb *urb,
1588 struct isp1760_qh *qh)
1589{
1590 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1591 int skip_map;
1592
1593 WARN_ON(qh->slot == -1);
1594
1595 /* We need to forcefully reclaim the slot since some transfers never
1596 return, e.g. interrupt transfers and NAKed bulk transfers. */
Arvid Brodin8b1ab602011-06-17 18:45:37 +02001597 if (usb_pipecontrol(urb->pipe) || usb_pipebulk(urb->pipe)) {
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001598 skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG);
1599 skip_map |= (1 << qh->slot);
1600 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map);
1601 priv->atl_slots[qh->slot].qh = NULL;
1602 priv->atl_slots[qh->slot].qtd = NULL;
1603 } else {
1604 skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG);
1605 skip_map |= (1 << qh->slot);
1606 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map);
1607 priv->int_slots[qh->slot].qh = NULL;
1608 priv->int_slots[qh->slot].qtd = NULL;
1609 }
1610
1611 qh->slot = -1;
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001612}
1613
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001614static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1615 int status)
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001616{
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001617 struct isp1760_hcd *priv = hcd_to_priv(hcd);
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001618 unsigned long spinflags;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001619 struct isp1760_qh *qh;
1620 struct isp1760_qtd *qtd;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001621 int retval = 0;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001622
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001623 spin_lock_irqsave(&priv->lock, spinflags);
Arvid Brodin17d3e142011-07-20 03:13:46 +02001624 retval = usb_hcd_check_unlink_urb(hcd, urb, status);
1625 if (retval)
1626 goto out;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001627
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001628 qh = urb->ep->hcpriv;
1629 if (!qh) {
1630 retval = -EINVAL;
1631 goto out;
1632 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001633
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001634 list_for_each_entry(qtd, &qh->qtd_list, qtd_list)
1635 if (qtd->urb == urb) {
1636 if (qtd->status == QTD_XFER_STARTED)
1637 kill_transfer(hcd, urb, qh);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001638 qtd->status = QTD_RETIRE;
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001639 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001640
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001641 urb->status = status;
1642 schedule_ptds(hcd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001643
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001644out:
1645 spin_unlock_irqrestore(&priv->lock, spinflags);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001646 return retval;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001647}
1648
Arvid Brodin079cdb02011-05-20 00:17:34 +02001649static void isp1760_endpoint_disable(struct usb_hcd *hcd,
1650 struct usb_host_endpoint *ep)
1651{
1652 struct isp1760_hcd *priv = hcd_to_priv(hcd);
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001653 unsigned long spinflags;
Arvid Brodin079cdb02011-05-20 00:17:34 +02001654 struct isp1760_qh *qh;
1655 struct isp1760_qtd *qtd;
Arvid Brodin079cdb02011-05-20 00:17:34 +02001656
1657 spin_lock_irqsave(&priv->lock, spinflags);
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001658
Arvid Brodin079cdb02011-05-20 00:17:34 +02001659 qh = ep->hcpriv;
1660 if (!qh)
1661 goto out;
1662
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001663 list_for_each_entry(qtd, &qh->qtd_list, qtd_list) {
1664 if (qtd->status == QTD_XFER_STARTED)
1665 kill_transfer(hcd, qtd->urb, qh);
1666 qtd->status = QTD_RETIRE;
1667 qtd->urb->status = -ECONNRESET;
Arvid Brodin079cdb02011-05-20 00:17:34 +02001668 }
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001669
Arvid Brodin079cdb02011-05-20 00:17:34 +02001670 ep->hcpriv = NULL;
1671 /* Cannot free qh here since it will be parsed by schedule_ptds() */
1672
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001673 schedule_ptds(hcd);
1674
Arvid Brodin079cdb02011-05-20 00:17:34 +02001675out:
1676 spin_unlock_irqrestore(&priv->lock, spinflags);
1677}
1678
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001679static int isp1760_hub_status_data(struct usb_hcd *hcd, char *buf)
1680{
1681 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1682 u32 temp, status = 0;
1683 u32 mask;
1684 int retval = 1;
1685 unsigned long flags;
1686
1687 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
1688 if (!HC_IS_RUNNING(hcd->state))
1689 return 0;
1690
1691 /* init status to no-changes */
1692 buf[0] = 0;
1693 mask = PORT_CSC;
1694
1695 spin_lock_irqsave(&priv->lock, flags);
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001696 temp = reg_read32(hcd->regs, HC_PORTSC1);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001697
1698 if (temp & PORT_OWNER) {
1699 if (temp & PORT_CSC) {
1700 temp &= ~PORT_CSC;
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001701 reg_write32(hcd->regs, HC_PORTSC1, temp);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001702 goto done;
1703 }
1704 }
1705
1706 /*
1707 * Return status information even for ports with OWNER set.
1708 * Otherwise khubd wouldn't see the disconnect event when a
1709 * high-speed device is switched over to the companion
1710 * controller by the user.
1711 */
1712
1713 if ((temp & mask) != 0
1714 || ((temp & PORT_RESUME) != 0
1715 && time_after_eq(jiffies,
1716 priv->reset_done))) {
1717 buf [0] |= 1 << (0 + 1);
1718 status = STS_PCD;
1719 }
1720 /* FIXME autosuspend idle root hubs */
1721done:
1722 spin_unlock_irqrestore(&priv->lock, flags);
1723 return status ? retval : 0;
1724}
1725
1726static void isp1760_hub_descriptor(struct isp1760_hcd *priv,
1727 struct usb_hub_descriptor *desc)
1728{
1729 int ports = HCS_N_PORTS(priv->hcs_params);
1730 u16 temp;
1731
1732 desc->bDescriptorType = 0x29;
1733 /* priv 1.0, 2.3.9 says 20ms max */
1734 desc->bPwrOn2PwrGood = 10;
1735 desc->bHubContrCurrent = 0;
1736
1737 desc->bNbrPorts = ports;
1738 temp = 1 + (ports / 8);
1739 desc->bDescLength = 7 + 2 * temp;
1740
Sarah Sharpda130512010-11-30 15:55:51 -08001741 /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */
John Youndbe79bb2001-09-17 00:00:00 -07001742 memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
1743 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001744
1745 /* per-port overcurrent reporting */
1746 temp = 0x0008;
1747 if (HCS_PPC(priv->hcs_params))
1748 /* per-port power control */
1749 temp |= 0x0001;
1750 else
1751 /* no power switching */
1752 temp |= 0x0002;
1753 desc->wHubCharacteristics = cpu_to_le16(temp);
1754}
1755
1756#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
1757
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001758static int check_reset_complete(struct usb_hcd *hcd, int index,
1759 int port_status)
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001760{
1761 if (!(port_status & PORT_CONNECT))
1762 return port_status;
1763
1764 /* if reset finished and it's still not enabled -- handoff */
1765 if (!(port_status & PORT_PE)) {
1766
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001767 dev_info(hcd->self.controller,
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001768 "port %d full speed --> companion\n",
1769 index + 1);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001770
1771 port_status |= PORT_OWNER;
1772 port_status &= ~PORT_RWC_BITS;
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001773 reg_write32(hcd->regs, HC_PORTSC1, port_status);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001774
1775 } else
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001776 dev_info(hcd->self.controller, "port %d high speed\n",
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001777 index + 1);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001778
1779 return port_status;
1780}
1781
1782static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1783 u16 wValue, u16 wIndex, char *buf, u16 wLength)
1784{
1785 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1786 int ports = HCS_N_PORTS(priv->hcs_params);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001787 u32 temp, status;
1788 unsigned long flags;
1789 int retval = 0;
1790 unsigned selector;
1791
1792 /*
1793 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
1794 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
1795 * (track current state ourselves) ... blink for diagnostics,
1796 * power, "this is the one", etc. EHCI spec supports this.
1797 */
1798
1799 spin_lock_irqsave(&priv->lock, flags);
1800 switch (typeReq) {
1801 case ClearHubFeature:
1802 switch (wValue) {
1803 case C_HUB_LOCAL_POWER:
1804 case C_HUB_OVER_CURRENT:
1805 /* no hub-wide feature/status flags */
1806 break;
1807 default:
1808 goto error;
1809 }
1810 break;
1811 case ClearPortFeature:
1812 if (!wIndex || wIndex > ports)
1813 goto error;
1814 wIndex--;
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001815 temp = reg_read32(hcd->regs, HC_PORTSC1);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001816
1817 /*
1818 * Even if OWNER is set, so the port is owned by the
1819 * companion controller, khubd needs to be able to clear
1820 * the port-change status bits (especially
Alan Stern749da5f2010-03-04 17:05:08 -05001821 * USB_PORT_STAT_C_CONNECTION).
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001822 */
1823
1824 switch (wValue) {
1825 case USB_PORT_FEAT_ENABLE:
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001826 reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_PE);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001827 break;
1828 case USB_PORT_FEAT_C_ENABLE:
1829 /* XXX error? */
1830 break;
1831 case USB_PORT_FEAT_SUSPEND:
1832 if (temp & PORT_RESET)
1833 goto error;
1834
1835 if (temp & PORT_SUSPEND) {
1836 if ((temp & PORT_PE) == 0)
1837 goto error;
1838 /* resume signaling for 20 msec */
1839 temp &= ~(PORT_RWC_BITS);
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001840 reg_write32(hcd->regs, HC_PORTSC1,
1841 temp | PORT_RESUME);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001842 priv->reset_done = jiffies +
1843 msecs_to_jiffies(20);
1844 }
1845 break;
1846 case USB_PORT_FEAT_C_SUSPEND:
1847 /* we auto-clear this feature */
1848 break;
1849 case USB_PORT_FEAT_POWER:
1850 if (HCS_PPC(priv->hcs_params))
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001851 reg_write32(hcd->regs, HC_PORTSC1,
1852 temp & ~PORT_POWER);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001853 break;
1854 case USB_PORT_FEAT_C_CONNECTION:
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001855 reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_CSC);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001856 break;
1857 case USB_PORT_FEAT_C_OVER_CURRENT:
1858 /* XXX error ?*/
1859 break;
1860 case USB_PORT_FEAT_C_RESET:
1861 /* GetPortStatus clears reset */
1862 break;
1863 default:
1864 goto error;
1865 }
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001866 reg_read32(hcd->regs, HC_USBCMD);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001867 break;
1868 case GetHubDescriptor:
1869 isp1760_hub_descriptor(priv, (struct usb_hub_descriptor *)
1870 buf);
1871 break;
1872 case GetHubStatus:
1873 /* no hub-wide feature/status flags */
1874 memset(buf, 0, 4);
1875 break;
1876 case GetPortStatus:
1877 if (!wIndex || wIndex > ports)
1878 goto error;
1879 wIndex--;
1880 status = 0;
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001881 temp = reg_read32(hcd->regs, HC_PORTSC1);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001882
1883 /* wPortChange bits */
1884 if (temp & PORT_CSC)
Alan Stern749da5f2010-03-04 17:05:08 -05001885 status |= USB_PORT_STAT_C_CONNECTION << 16;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001886
1887
1888 /* whoever resumes must GetPortStatus to complete it!! */
1889 if (temp & PORT_RESUME) {
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001890 dev_err(hcd->self.controller, "Port resume should be skipped.\n");
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001891
1892 /* Remote Wakeup received? */
1893 if (!priv->reset_done) {
1894 /* resume signaling for 20 msec */
1895 priv->reset_done = jiffies
1896 + msecs_to_jiffies(20);
1897 /* check the port again */
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001898 mod_timer(&hcd->rh_timer, priv->reset_done);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001899 }
1900
1901 /* resume completed? */
1902 else if (time_after_eq(jiffies,
1903 priv->reset_done)) {
Alan Stern749da5f2010-03-04 17:05:08 -05001904 status |= USB_PORT_STAT_C_SUSPEND << 16;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001905 priv->reset_done = 0;
1906
1907 /* stop resume signaling */
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001908 temp = reg_read32(hcd->regs, HC_PORTSC1);
1909 reg_write32(hcd->regs, HC_PORTSC1,
1910 temp & ~(PORT_RWC_BITS | PORT_RESUME));
1911 retval = handshake(hcd, HC_PORTSC1,
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001912 PORT_RESUME, 0, 2000 /* 2msec */);
1913 if (retval != 0) {
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001914 dev_err(hcd->self.controller,
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001915 "port %d resume error %d\n",
1916 wIndex + 1, retval);
1917 goto error;
1918 }
1919 temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10));
1920 }
1921 }
1922
1923 /* whoever resets must GetPortStatus to complete it!! */
1924 if ((temp & PORT_RESET)
1925 && time_after_eq(jiffies,
1926 priv->reset_done)) {
Alan Stern749da5f2010-03-04 17:05:08 -05001927 status |= USB_PORT_STAT_C_RESET << 16;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001928 priv->reset_done = 0;
1929
1930 /* force reset to complete */
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001931 reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_RESET);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001932 /* REVISIT: some hardware needs 550+ usec to clear
1933 * this bit; seems too long to spin routinely...
1934 */
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001935 retval = handshake(hcd, HC_PORTSC1,
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001936 PORT_RESET, 0, 750);
1937 if (retval != 0) {
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001938 dev_err(hcd->self.controller, "port %d reset error %d\n",
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001939 wIndex + 1, retval);
1940 goto error;
1941 }
1942
1943 /* see what we found out */
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001944 temp = check_reset_complete(hcd, wIndex,
1945 reg_read32(hcd->regs, HC_PORTSC1));
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001946 }
1947 /*
1948 * Even if OWNER is set, there's no harm letting khubd
1949 * see the wPortStatus values (they should all be 0 except
1950 * for PORT_POWER anyway).
1951 */
1952
1953 if (temp & PORT_OWNER)
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001954 dev_err(hcd->self.controller, "PORT_OWNER is set\n");
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001955
1956 if (temp & PORT_CONNECT) {
Alan Stern749da5f2010-03-04 17:05:08 -05001957 status |= USB_PORT_STAT_CONNECTION;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001958 /* status may be from integrated TT */
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001959 status |= USB_PORT_STAT_HIGH_SPEED;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001960 }
1961 if (temp & PORT_PE)
Alan Stern749da5f2010-03-04 17:05:08 -05001962 status |= USB_PORT_STAT_ENABLE;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001963 if (temp & (PORT_SUSPEND|PORT_RESUME))
Alan Stern749da5f2010-03-04 17:05:08 -05001964 status |= USB_PORT_STAT_SUSPEND;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001965 if (temp & PORT_RESET)
Alan Stern749da5f2010-03-04 17:05:08 -05001966 status |= USB_PORT_STAT_RESET;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001967 if (temp & PORT_POWER)
Alan Stern749da5f2010-03-04 17:05:08 -05001968 status |= USB_PORT_STAT_POWER;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001969
1970 put_unaligned(cpu_to_le32(status), (__le32 *) buf);
1971 break;
1972 case SetHubFeature:
1973 switch (wValue) {
1974 case C_HUB_LOCAL_POWER:
1975 case C_HUB_OVER_CURRENT:
1976 /* no hub-wide feature/status flags */
1977 break;
1978 default:
1979 goto error;
1980 }
1981 break;
1982 case SetPortFeature:
1983 selector = wIndex >> 8;
1984 wIndex &= 0xff;
1985 if (!wIndex || wIndex > ports)
1986 goto error;
1987 wIndex--;
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001988 temp = reg_read32(hcd->regs, HC_PORTSC1);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001989 if (temp & PORT_OWNER)
1990 break;
1991
1992/* temp &= ~PORT_RWC_BITS; */
1993 switch (wValue) {
1994 case USB_PORT_FEAT_ENABLE:
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001995 reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_PE);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001996 break;
1997
1998 case USB_PORT_FEAT_SUSPEND:
1999 if ((temp & PORT_PE) == 0
2000 || (temp & PORT_RESET) != 0)
2001 goto error;
2002
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002003 reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_SUSPEND);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002004 break;
2005 case USB_PORT_FEAT_POWER:
2006 if (HCS_PPC(priv->hcs_params))
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002007 reg_write32(hcd->regs, HC_PORTSC1,
2008 temp | PORT_POWER);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002009 break;
2010 case USB_PORT_FEAT_RESET:
2011 if (temp & PORT_RESUME)
2012 goto error;
2013 /* line status bits may report this as low speed,
2014 * which can be fine if this root hub has a
2015 * transaction translator built in.
2016 */
2017 if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
2018 && PORT_USB11(temp)) {
2019 temp |= PORT_OWNER;
2020 } else {
2021 temp |= PORT_RESET;
2022 temp &= ~PORT_PE;
2023
2024 /*
2025 * caller must wait, then call GetPortStatus
2026 * usb 2.0 spec says 50 ms resets on root
2027 */
2028 priv->reset_done = jiffies +
2029 msecs_to_jiffies(50);
2030 }
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002031 reg_write32(hcd->regs, HC_PORTSC1, temp);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002032 break;
2033 default:
2034 goto error;
2035 }
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002036 reg_read32(hcd->regs, HC_USBCMD);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002037 break;
2038
2039 default:
2040error:
2041 /* "stall" on error */
2042 retval = -EPIPE;
2043 }
2044 spin_unlock_irqrestore(&priv->lock, flags);
2045 return retval;
2046}
2047
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002048static int isp1760_get_frame(struct usb_hcd *hcd)
2049{
2050 struct isp1760_hcd *priv = hcd_to_priv(hcd);
2051 u32 fr;
2052
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002053 fr = reg_read32(hcd->regs, HC_FRINDEX);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002054 return (fr >> 3) % priv->periodic_size;
2055}
2056
2057static void isp1760_stop(struct usb_hcd *hcd)
2058{
2059 struct isp1760_hcd *priv = hcd_to_priv(hcd);
Nate Case3faefc82008-06-17 11:11:38 -05002060 u32 temp;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002061
Arvid Brodin6d50c602011-08-21 08:29:26 +02002062 del_timer(&errata2_timer);
2063
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002064 isp1760_hub_control(hcd, ClearPortFeature, USB_PORT_FEAT_POWER, 1,
2065 NULL, 0);
2066 mdelay(20);
2067
2068 spin_lock_irq(&priv->lock);
Arvid Brodin6bda21b2011-02-26 22:06:37 +01002069 ehci_reset(hcd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002070 /* Disable IRQ */
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002071 temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL);
2072 reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp &= ~HW_GLOBAL_INTR_EN);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002073 spin_unlock_irq(&priv->lock);
2074
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002075 reg_write32(hcd->regs, HC_CONFIGFLAG, 0);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002076}
2077
2078static void isp1760_shutdown(struct usb_hcd *hcd)
2079{
Nate Case3faefc82008-06-17 11:11:38 -05002080 u32 command, temp;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002081
2082 isp1760_stop(hcd);
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002083 temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL);
2084 reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp &= ~HW_GLOBAL_INTR_EN);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002085
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002086 command = reg_read32(hcd->regs, HC_USBCMD);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002087 command &= ~CMD_RUN;
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002088 reg_write32(hcd->regs, HC_USBCMD, command);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002089}
2090
2091static const struct hc_driver isp1760_hc_driver = {
2092 .description = "isp1760-hcd",
2093 .product_desc = "NXP ISP1760 USB Host Controller",
2094 .hcd_priv_size = sizeof(struct isp1760_hcd),
2095 .irq = isp1760_irq,
2096 .flags = HCD_MEMORY | HCD_USB2,
2097 .reset = isp1760_hc_setup,
2098 .start = isp1760_run,
2099 .stop = isp1760_stop,
2100 .shutdown = isp1760_shutdown,
2101 .urb_enqueue = isp1760_urb_enqueue,
2102 .urb_dequeue = isp1760_urb_dequeue,
2103 .endpoint_disable = isp1760_endpoint_disable,
2104 .get_frame_number = isp1760_get_frame,
2105 .hub_status_data = isp1760_hub_status_data,
2106 .hub_control = isp1760_hub_control,
2107};
2108
2109int __init init_kmem_once(void)
2110{
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02002111 urb_listitem_cachep = kmem_cache_create("isp1760 urb_listitem",
2112 sizeof(struct urb_listitem), 0, SLAB_TEMPORARY |
2113 SLAB_MEM_SPREAD, NULL);
2114
2115 if (!urb_listitem_cachep)
2116 return -ENOMEM;
2117
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002118 qtd_cachep = kmem_cache_create("isp1760_qtd",
2119 sizeof(struct isp1760_qtd), 0, SLAB_TEMPORARY |
2120 SLAB_MEM_SPREAD, NULL);
2121
2122 if (!qtd_cachep)
2123 return -ENOMEM;
2124
2125 qh_cachep = kmem_cache_create("isp1760_qh", sizeof(struct isp1760_qh),
2126 0, SLAB_TEMPORARY | SLAB_MEM_SPREAD, NULL);
2127
2128 if (!qh_cachep) {
2129 kmem_cache_destroy(qtd_cachep);
2130 return -ENOMEM;
2131 }
2132
2133 return 0;
2134}
2135
2136void deinit_kmem_cache(void)
2137{
2138 kmem_cache_destroy(qtd_cachep);
2139 kmem_cache_destroy(qh_cachep);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02002140 kmem_cache_destroy(urb_listitem_cachep);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002141}
2142
Catalin Marinasf9031f22009-02-10 16:55:45 +00002143struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len,
2144 int irq, unsigned long irqflags,
2145 struct device *dev, const char *busname,
2146 unsigned int devflags)
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002147{
2148 struct usb_hcd *hcd;
2149 struct isp1760_hcd *priv;
2150 int ret;
2151
2152 if (usb_disabled())
2153 return ERR_PTR(-ENODEV);
2154
2155 /* prevent usb-core allocating DMA pages */
2156 dev->dma_mask = NULL;
2157
Kay Sievers0031a062008-05-02 06:02:41 +02002158 hcd = usb_create_hcd(&isp1760_hc_driver, dev, dev_name(dev));
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002159 if (!hcd)
2160 return ERR_PTR(-ENOMEM);
2161
2162 priv = hcd_to_priv(hcd);
Nate Case3faefc82008-06-17 11:11:38 -05002163 priv->devflags = devflags;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002164 init_memory(priv);
2165 hcd->regs = ioremap(res_start, res_len);
2166 if (!hcd->regs) {
2167 ret = -EIO;
2168 goto err_put;
2169 }
2170
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002171 hcd->irq = irq;
2172 hcd->rsrc_start = res_start;
2173 hcd->rsrc_len = res_len;
2174
Nate Casee6942d62008-05-21 16:28:20 -05002175 ret = usb_add_hcd(hcd, irq, irqflags);
2176 if (ret)
2177 goto err_unmap;
2178
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002179 return hcd;
2180
2181err_unmap:
2182 iounmap(hcd->regs);
2183
2184err_put:
2185 usb_put_hcd(hcd);
2186
2187 return ERR_PTR(ret);
2188}
2189
2190MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP");
2191MODULE_AUTHOR("Sebastian Siewior <bigeasy@linuxtronix.de>");
2192MODULE_LICENSE("GPL v2");