blob: a46ccf97a5c9cf876277a60d0f57d3a913c64d09 [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>
Sebastian Siewiordb11e472008-04-24 00:37:04 +020024#include <asm/unaligned.h>
Catalin Marinasdb8516f2010-02-02 15:31:02 +000025#include <asm/cacheflush.h>
Sebastian Siewiordb11e472008-04-24 00:37:04 +020026
Sebastian Siewiordb11e472008-04-24 00:37:04 +020027#include "isp1760-hcd.h"
28
29static struct kmem_cache *qtd_cachep;
30static struct kmem_cache *qh_cachep;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +020031static struct kmem_cache *urb_listitem_cachep;
Sebastian Siewiordb11e472008-04-24 00:37:04 +020032
33struct isp1760_hcd {
34 u32 hcs_params;
35 spinlock_t lock;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +020036 struct slotinfo atl_slots[32];
Arvid Brodind05b6ec2011-05-20 00:17:45 +020037 int atl_done_map;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +020038 struct slotinfo int_slots[32];
Arvid Brodind05b6ec2011-05-20 00:17:45 +020039 int int_done_map;
Sebastian Siewiordb11e472008-04-24 00:37:04 +020040 struct memory_chunk memory_pool[BLOCKS];
Arvid Brodin71a9f9d2011-04-26 21:48:30 +020041 struct list_head controlqhs, bulkqhs, interruptqhs;
42 int active_ptds;
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
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200492 /* This is weird: at the first plug-in of a device there seems to be
493 one packet queued that never gets returned? */
494 priv->active_ptds = -1;
495
Nate Case3faefc82008-06-17 11:11:38 -0500496 /* ATL reset */
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100497 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode | ALL_ATX_RESET);
Nate Case3faefc82008-06-17 11:11:38 -0500498 mdelay(10);
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100499 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode);
Nate Case3faefc82008-06-17 11:11:38 -0500500
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100501 reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, INTERRUPT_ENABLE_MASK);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200502
Nate Case3faefc82008-06-17 11:11:38 -0500503 /*
504 * PORT 1 Control register of the ISP1760 is the OTG control
Thomas Hommel42c65392008-12-18 10:31:40 +0100505 * register on ISP1761. Since there is no OTG or device controller
506 * support in this driver, we use port 1 as a "normal" USB host port on
507 * both chips.
Nate Case3faefc82008-06-17 11:11:38 -0500508 */
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100509 reg_write32(hcd->regs, HC_PORT1_CTRL, PORT1_POWER | PORT1_INIT2);
Thomas Hommel42c65392008-12-18 10:31:40 +0100510 mdelay(10);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200511
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100512 priv->hcs_params = reg_read32(hcd->regs, HC_HCSPARAMS);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200513
514 return priv_init(hcd);
515}
516
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200517static int isp1760_run(struct usb_hcd *hcd)
518{
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200519 int retval;
520 u32 temp;
521 u32 command;
522 u32 chipid;
523
524 hcd->uses_new_polling = 1;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200525
526 hcd->state = HC_STATE_RUNNING;
Arvid Brodine25e0eb2011-08-21 08:29:24 +0200527
528 /* Set PTD interrupt AND & OR maps */
529 reg_write32(hcd->regs, HC_ATL_IRQ_MASK_AND_REG, 0);
530 reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, 0xffffffff);
531 reg_write32(hcd->regs, HC_INT_IRQ_MASK_AND_REG, 0);
532 reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, 0xffffffff);
533 reg_write32(hcd->regs, HC_ISO_IRQ_MASK_AND_REG, 0);
534 reg_write32(hcd->regs, HC_ISO_IRQ_MASK_OR_REG, 0xffffffff);
535 /* step 23 passed */
536
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100537 temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL);
538 reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp | HW_GLOBAL_INTR_EN);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200539
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100540 command = reg_read32(hcd->regs, HC_USBCMD);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200541 command &= ~(CMD_LRESET|CMD_RESET);
542 command |= CMD_RUN;
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100543 reg_write32(hcd->regs, HC_USBCMD, command);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200544
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200545 retval = handshake(hcd, HC_USBCMD, CMD_RUN, CMD_RUN, 250 * 1000);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200546 if (retval)
547 return retval;
548
549 /*
550 * XXX
551 * Spec says to write FLAG_CF as last config action, priv code grabs
552 * the semaphore while doing so.
553 */
554 down_write(&ehci_cf_port_reset_rwsem);
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100555 reg_write32(hcd->regs, HC_CONFIGFLAG, FLAG_CF);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200556
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100557 retval = handshake(hcd, HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 250 * 1000);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200558 up_write(&ehci_cf_port_reset_rwsem);
559 if (retval)
560 return retval;
561
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100562 chipid = reg_read32(hcd->regs, HC_CHIP_ID_REG);
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100563 dev_info(hcd->self.controller, "USB ISP %04x HW rev. %d started\n",
564 chipid & 0xffff, chipid >> 16);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200565
566 /* PTD Register Init Part 2, Step 28 */
Arvid Brodine25e0eb2011-08-21 08:29:24 +0200567
568 /* Setup registers controlling PTD checking */
569 reg_write32(hcd->regs, HC_ATL_PTD_LASTPTD_REG, 0x80000000);
570 reg_write32(hcd->regs, HC_INT_PTD_LASTPTD_REG, 0x80000000);
571 reg_write32(hcd->regs, HC_ISO_PTD_LASTPTD_REG, 0x00000001);
572 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, 0xffffffff);
573 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, 0xffffffff);
574 reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, 0xffffffff);
575 reg_write32(hcd->regs, HC_BUFFER_STATUS_REG,
576 ATL_BUF_FILL | INT_BUF_FILL);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200577
578 /* GRR this is run-once init(), being done every time the HC starts.
579 * So long as they're part of class devices, we can't do it init()
580 * since the class device isn't created that early.
581 */
582 return 0;
583}
584
585static u32 base_to_chip(u32 base)
586{
587 return ((base - 0x400) >> 3);
588}
589
Arvid Brodin7adc14b2011-02-26 22:08:47 +0100590static int last_qtd_of_urb(struct isp1760_qtd *qtd, struct isp1760_qh *qh)
591{
592 struct urb *urb;
593
594 if (list_is_last(&qtd->qtd_list, &qh->qtd_list))
595 return 1;
596
597 urb = qtd->urb;
598 qtd = list_entry(qtd->qtd_list.next, typeof(*qtd), qtd_list);
599 return (qtd->urb != urb);
600}
601
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200602/* magic numbers that can affect system performance */
603#define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
604#define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
605#define EHCI_TUNE_RL_TT 0
606#define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
607#define EHCI_TUNE_MULT_TT 1
608#define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */
609
610static void create_ptd_atl(struct isp1760_qh *qh,
Arvid Brodina041d8e2011-02-26 22:04:40 +0100611 struct isp1760_qtd *qtd, struct ptd *ptd)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200612{
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200613 u32 maxpacket;
614 u32 multi;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200615 u32 rl = RL_COUNTER;
616 u32 nak = NAK_COUNTER;
617
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100618 memset(ptd, 0, sizeof(*ptd));
619
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200620 /* according to 3.6.2, max packet len can not be > 0x400 */
Arvid Brodina041d8e2011-02-26 22:04:40 +0100621 maxpacket = usb_maxpacket(qtd->urb->dev, qtd->urb->pipe,
622 usb_pipeout(qtd->urb->pipe));
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200623 multi = 1 + ((maxpacket >> 11) & 0x3);
624 maxpacket &= 0x7ff;
625
626 /* DW0 */
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200627 ptd->dw0 = DW0_VALID_BIT;
628 ptd->dw0 |= TO_DW0_LENGTH(qtd->length);
629 ptd->dw0 |= TO_DW0_MAXPACKET(maxpacket);
630 ptd->dw0 |= TO_DW0_ENDPOINT(usb_pipeendpoint(qtd->urb->pipe));
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200631
632 /* DW1 */
Arvid Brodina041d8e2011-02-26 22:04:40 +0100633 ptd->dw1 = usb_pipeendpoint(qtd->urb->pipe) >> 1;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200634 ptd->dw1 |= TO_DW1_DEVICE_ADDR(usb_pipedevice(qtd->urb->pipe));
635 ptd->dw1 |= TO_DW1_PID_TOKEN(qtd->packet_type);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200636
Arvid Brodina041d8e2011-02-26 22:04:40 +0100637 if (usb_pipebulk(qtd->urb->pipe))
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200638 ptd->dw1 |= DW1_TRANS_BULK;
Arvid Brodina041d8e2011-02-26 22:04:40 +0100639 else if (usb_pipeint(qtd->urb->pipe))
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200640 ptd->dw1 |= DW1_TRANS_INT;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200641
Arvid Brodina041d8e2011-02-26 22:04:40 +0100642 if (qtd->urb->dev->speed != USB_SPEED_HIGH) {
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200643 /* split transaction */
644
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200645 ptd->dw1 |= DW1_TRANS_SPLIT;
Arvid Brodina041d8e2011-02-26 22:04:40 +0100646 if (qtd->urb->dev->speed == USB_SPEED_LOW)
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200647 ptd->dw1 |= DW1_SE_USB_LOSPEED;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200648
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200649 ptd->dw1 |= TO_DW1_PORT_NUM(qtd->urb->dev->ttport);
650 ptd->dw1 |= TO_DW1_HUB_NUM(qtd->urb->dev->tt->hub->devnum);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200651
652 /* SE bit for Split INT transfers */
Arvid Brodina041d8e2011-02-26 22:04:40 +0100653 if (usb_pipeint(qtd->urb->pipe) &&
654 (qtd->urb->dev->speed == USB_SPEED_LOW))
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100655 ptd->dw1 |= 2 << 16;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200656
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200657 rl = 0;
658 nak = 0;
659 } else {
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200660 ptd->dw0 |= TO_DW0_MULTI(multi);
Arvid Brodina041d8e2011-02-26 22:04:40 +0100661 if (usb_pipecontrol(qtd->urb->pipe) ||
662 usb_pipebulk(qtd->urb->pipe))
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200663 ptd->dw3 |= TO_DW3_PING(qh->ping);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200664 }
665 /* DW2 */
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100666 ptd->dw2 = 0;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200667 ptd->dw2 |= TO_DW2_DATA_START_ADDR(base_to_chip(qtd->payload_addr));
668 ptd->dw2 |= TO_DW2_RL(rl);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200669
670 /* DW3 */
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200671 ptd->dw3 |= TO_DW3_NAKCOUNT(nak);
672 ptd->dw3 |= TO_DW3_DATA_TOGGLE(qh->toggle);
Arvid Brodin7adc14b2011-02-26 22:08:47 +0100673 if (usb_pipecontrol(qtd->urb->pipe)) {
674 if (qtd->data_buffer == qtd->urb->setup_packet)
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200675 ptd->dw3 &= ~TO_DW3_DATA_TOGGLE(1);
Arvid Brodin7adc14b2011-02-26 22:08:47 +0100676 else if (last_qtd_of_urb(qtd, qh))
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200677 ptd->dw3 |= TO_DW3_DATA_TOGGLE(1);
Arvid Brodin7adc14b2011-02-26 22:08:47 +0100678 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200679
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200680 ptd->dw3 |= DW3_ACTIVE_BIT;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200681 /* Cerr */
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200682 ptd->dw3 |= TO_DW3_CERR(ERR_COUNTER);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200683}
684
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100685static void transform_add_int(struct isp1760_qh *qh,
Arvid Brodina041d8e2011-02-26 22:04:40 +0100686 struct isp1760_qtd *qtd, struct ptd *ptd)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200687{
Arvid Brodin65f1b522011-02-26 22:07:35 +0100688 u32 usof;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200689 u32 period;
690
Arvid Brodin65f1b522011-02-26 22:07:35 +0100691 /*
692 * Most of this is guessing. ISP1761 datasheet is quite unclear, and
693 * the algorithm from the original Philips driver code, which was
694 * pretty much used in this driver before as well, is quite horrendous
695 * and, i believe, incorrect. The code below follows the datasheet and
696 * USB2.0 spec as far as I can tell, and plug/unplug seems to be much
697 * more reliable this way (fingers crossed...).
698 */
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200699
Arvid Brodin65f1b522011-02-26 22:07:35 +0100700 if (qtd->urb->dev->speed == USB_SPEED_HIGH) {
701 /* urb->interval is in units of microframes (1/8 ms) */
702 period = qtd->urb->interval >> 3;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200703
Arvid Brodin65f1b522011-02-26 22:07:35 +0100704 if (qtd->urb->interval > 4)
705 usof = 0x01; /* One bit set =>
706 interval 1 ms * uFrame-match */
707 else if (qtd->urb->interval > 2)
708 usof = 0x22; /* Two bits set => interval 1/2 ms */
709 else if (qtd->urb->interval > 1)
710 usof = 0x55; /* Four bits set => interval 1/4 ms */
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200711 else
Arvid Brodin65f1b522011-02-26 22:07:35 +0100712 usof = 0xff; /* All bits set => interval 1/8 ms */
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200713 } else {
Arvid Brodin65f1b522011-02-26 22:07:35 +0100714 /* urb->interval is in units of frames (1 ms) */
715 period = qtd->urb->interval;
716 usof = 0x0f; /* Execute Start Split on any of the
717 four first uFrames */
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200718
Arvid Brodin65f1b522011-02-26 22:07:35 +0100719 /*
720 * First 8 bits in dw5 is uSCS and "specifies which uSOF the
721 * complete split needs to be sent. Valid only for IN." Also,
722 * "All bits can be set to one for every transfer." (p 82,
723 * ISP1761 data sheet.) 0x1c is from Philips driver. Where did
724 * that number come from? 0xff seems to work fine...
725 */
726 /* ptd->dw5 = 0x1c; */
727 ptd->dw5 = 0xff; /* Execute Complete Split on any uFrame */
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200728 }
729
Arvid Brodin65f1b522011-02-26 22:07:35 +0100730 period = period >> 1;/* Ensure equal or shorter period than requested */
731 period &= 0xf8; /* Mask off too large values and lowest unused 3 bits */
732
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100733 ptd->dw2 |= period;
734 ptd->dw4 = usof;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200735}
736
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200737static void create_ptd_int(struct isp1760_qh *qh,
Arvid Brodina041d8e2011-02-26 22:04:40 +0100738 struct isp1760_qtd *qtd, struct ptd *ptd)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200739{
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200740 create_ptd_atl(qh, qtd, ptd);
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100741 transform_add_int(qh, qtd, ptd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200742}
743
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100744static void isp1760_urb_done(struct usb_hcd *hcd, struct urb *urb)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200745__releases(priv->lock)
746__acquires(priv->lock)
747{
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100748 struct isp1760_hcd *priv = hcd_to_priv(hcd);
749
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200750 if (!urb->unlinked) {
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100751 if (urb->status == -EINPROGRESS)
752 urb->status = 0;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200753 }
754
Catalin Marinasdb8516f2010-02-02 15:31:02 +0000755 if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) {
756 void *ptr;
757 for (ptr = urb->transfer_buffer;
758 ptr < urb->transfer_buffer + urb->transfer_buffer_length;
759 ptr += PAGE_SIZE)
760 flush_dcache_page(virt_to_page(ptr));
761 }
762
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200763 /* complete() can reenter this HCD */
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100764 usb_hcd_unlink_urb_from_ep(hcd, urb);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200765 spin_unlock(&priv->lock);
Arvid Brodin6bda21b2011-02-26 22:06:37 +0100766 usb_hcd_giveback_urb(hcd, urb, urb->status);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200767 spin_lock(&priv->lock);
768}
769
Arvid Brodin34537732011-04-26 21:47:37 +0200770static struct isp1760_qtd *qtd_alloc(gfp_t flags, struct urb *urb,
771 u8 packet_type)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200772{
Arvid Brodin34537732011-04-26 21:47:37 +0200773 struct isp1760_qtd *qtd;
774
775 qtd = kmem_cache_zalloc(qtd_cachep, flags);
776 if (!qtd)
777 return NULL;
778
779 INIT_LIST_HEAD(&qtd->qtd_list);
780 qtd->urb = urb;
781 qtd->packet_type = packet_type;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200782 qtd->status = QTD_ENQUEUED;
783 qtd->actual_length = 0;
Arvid Brodin34537732011-04-26 21:47:37 +0200784
785 return qtd;
786}
787
788static void qtd_free(struct isp1760_qtd *qtd)
789{
790 WARN_ON(qtd->payload_addr);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200791 kmem_cache_free(qtd_cachep, qtd);
792}
793
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200794static void start_bus_transfer(struct usb_hcd *hcd, u32 ptd_offset, int slot,
795 struct slotinfo *slots, struct isp1760_qtd *qtd,
796 struct isp1760_qh *qh, struct ptd *ptd)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200797{
Arvid Brodinbedc0c32011-02-26 22:02:57 +0100798 struct isp1760_hcd *priv = hcd_to_priv(hcd);
Arvid Brodind05b6ec2011-05-20 00:17:45 +0200799 int skip_map;
800
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200801 WARN_ON((slot < 0) || (slot > 31));
802 WARN_ON(qtd->length && !qtd->payload_addr);
803 WARN_ON(slots[slot].qtd);
804 WARN_ON(slots[slot].qh);
805 WARN_ON(qtd->status != QTD_PAYLOAD_ALLOC);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200806
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200807 slots[slot].qtd = qtd;
808 slots[slot].qh = qh;
809 qh->slot = slot;
810 qtd->status = QTD_XFER_STARTED; /* Set this before writing ptd, since
811 interrupt routine may preempt and expects this value. */
812 ptd_write(hcd->regs, ptd_offset, slot, ptd);
813 priv->active_ptds++;
Arvid Brodind05b6ec2011-05-20 00:17:45 +0200814
815 /* Make sure done map has not triggered from some unlinked transfer */
816 if (ptd_offset == ATL_PTD_OFFSET) {
817 priv->atl_done_map |= reg_read32(hcd->regs,
818 HC_ATL_PTD_DONEMAP_REG);
819 priv->atl_done_map &= ~(1 << qh->slot);
820
821 skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG);
822 skip_map &= ~(1 << qh->slot);
823 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map);
824 } else {
825 priv->int_done_map |= reg_read32(hcd->regs,
826 HC_INT_PTD_DONEMAP_REG);
827 priv->int_done_map &= ~(1 << qh->slot);
828
829 skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG);
830 skip_map &= ~(1 << qh->slot);
831 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map);
832 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200833}
834
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200835static int is_short_bulk(struct isp1760_qtd *qtd)
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200836{
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200837 return (usb_pipebulk(qtd->urb->pipe) &&
838 (qtd->actual_length < qtd->length));
839}
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200840
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200841static void collect_qtds(struct usb_hcd *hcd, struct isp1760_qh *qh,
842 struct list_head *urb_list)
843{
844 int last_qtd;
845 struct isp1760_qtd *qtd, *qtd_next;
846 struct urb_listitem *urb_listitem;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200847
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200848 list_for_each_entry_safe(qtd, qtd_next, &qh->qtd_list, qtd_list) {
849 if (qtd->status < QTD_XFER_COMPLETE)
850 break;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200851
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200852 if (list_is_last(&qtd->qtd_list, &qh->qtd_list))
853 last_qtd = 1;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200854 else
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200855 last_qtd = qtd->urb != qtd_next->urb;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200856
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200857 if ((!last_qtd) && (qtd->status == QTD_RETIRE))
858 qtd_next->status = QTD_RETIRE;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200859
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200860 if (qtd->status == QTD_XFER_COMPLETE) {
861 if (qtd->actual_length) {
862 switch (qtd->packet_type) {
863 case IN_PID:
864 mem_reads8(hcd->regs, qtd->payload_addr,
865 qtd->data_buffer,
866 qtd->actual_length);
867 /* Fall through (?) */
868 case OUT_PID:
869 qtd->urb->actual_length +=
870 qtd->actual_length;
871 /* Fall through ... */
872 case SETUP_PID:
873 break;
874 }
875 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200876
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200877 if (is_short_bulk(qtd)) {
878 if (qtd->urb->transfer_flags & URB_SHORT_NOT_OK)
879 qtd->urb->status = -EREMOTEIO;
880 if (!last_qtd)
881 qtd_next->status = QTD_RETIRE;
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200882 }
883 }
884
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200885 if (qtd->payload_addr)
886 free_mem(hcd, qtd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200887
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200888 if (last_qtd) {
889 if ((qtd->status == QTD_RETIRE) &&
890 (qtd->urb->status == -EINPROGRESS))
891 qtd->urb->status = -EPIPE;
892 /* Defer calling of urb_done() since it releases lock */
893 urb_listitem = kmem_cache_zalloc(urb_listitem_cachep,
894 GFP_ATOMIC);
895 if (unlikely(!urb_listitem))
896 break;
897 urb_listitem->urb = qtd->urb;
898 list_add_tail(&urb_listitem->urb_list, urb_list);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200899 }
900
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200901 list_del(&qtd->qtd_list);
902 qtd_free(qtd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +0200903 }
904}
905
Arvid Brodin71a9f9d2011-04-26 21:48:30 +0200906#define ENQUEUE_DEPTH 2
907static void enqueue_qtds(struct usb_hcd *hcd, struct isp1760_qh *qh)
908{
909 struct isp1760_hcd *priv = hcd_to_priv(hcd);
910 int ptd_offset;
911 struct slotinfo *slots;
912 int curr_slot, free_slot;
913 int n;
914 struct ptd ptd;
915 struct isp1760_qtd *qtd;
916
917 if (unlikely(list_empty(&qh->qtd_list))) {
918 WARN_ON(1);
919 return;
920 }
921
922 if (usb_pipeint(list_entry(qh->qtd_list.next, struct isp1760_qtd,
923 qtd_list)->urb->pipe)) {
924 ptd_offset = INT_PTD_OFFSET;
925 slots = priv->int_slots;
926 } else {
927 ptd_offset = ATL_PTD_OFFSET;
928 slots = priv->atl_slots;
929 }
930
931 free_slot = -1;
932 for (curr_slot = 0; curr_slot < 32; curr_slot++) {
933 if ((free_slot == -1) && (slots[curr_slot].qtd == NULL))
934 free_slot = curr_slot;
935 if (slots[curr_slot].qh == qh)
936 break;
937 }
938
939 n = 0;
940 list_for_each_entry(qtd, &qh->qtd_list, qtd_list) {
941 if (qtd->status == QTD_ENQUEUED) {
942 WARN_ON(qtd->payload_addr);
943 alloc_mem(hcd, qtd);
944 if ((qtd->length) && (!qtd->payload_addr))
945 break;
946
947 if ((qtd->length) &&
948 ((qtd->packet_type == SETUP_PID) ||
949 (qtd->packet_type == OUT_PID))) {
950 mem_writes8(hcd->regs, qtd->payload_addr,
951 qtd->data_buffer, qtd->length);
952 }
953
954 qtd->status = QTD_PAYLOAD_ALLOC;
955 }
956
957 if (qtd->status == QTD_PAYLOAD_ALLOC) {
958/*
959 if ((curr_slot > 31) && (free_slot == -1))
960 dev_dbg(hcd->self.controller, "%s: No slot "
961 "available for transfer\n", __func__);
962*/
963 /* Start xfer for this endpoint if not already done */
964 if ((curr_slot > 31) && (free_slot > -1)) {
965 if (usb_pipeint(qtd->urb->pipe))
966 create_ptd_int(qh, qtd, &ptd);
967 else
968 create_ptd_atl(qh, qtd, &ptd);
969
970 start_bus_transfer(hcd, ptd_offset, free_slot,
971 slots, qtd, qh, &ptd);
972 curr_slot = free_slot;
973 }
974
975 n++;
976 if (n >= ENQUEUE_DEPTH)
977 break;
978 }
979 }
980}
981
982void schedule_ptds(struct usb_hcd *hcd)
983{
984 struct isp1760_hcd *priv;
985 struct isp1760_qh *qh, *qh_next;
986 struct list_head *ep_queue;
987 struct usb_host_endpoint *ep;
988 LIST_HEAD(urb_list);
989 struct urb_listitem *urb_listitem, *urb_listitem_next;
990
991 if (!hcd) {
992 WARN_ON(1);
993 return;
994 }
995
996 priv = hcd_to_priv(hcd);
997
998 /*
999 * check finished/retired xfers, transfer payloads, call urb_done()
1000 */
1001 ep_queue = &priv->interruptqhs;
1002 while (ep_queue) {
1003 list_for_each_entry_safe(qh, qh_next, ep_queue, qh_list) {
1004 ep = list_entry(qh->qtd_list.next, struct isp1760_qtd,
1005 qtd_list)->urb->ep;
1006 collect_qtds(hcd, qh, &urb_list);
1007 if (list_empty(&qh->qtd_list)) {
1008 list_del(&qh->qh_list);
1009 if (ep->hcpriv == NULL) {
1010 /* Endpoint has been disabled, so we
1011 can free the associated queue head. */
1012 qh_free(qh);
1013 }
1014 }
1015 }
1016
1017 if (ep_queue == &priv->interruptqhs)
1018 ep_queue = &priv->controlqhs;
1019 else if (ep_queue == &priv->controlqhs)
1020 ep_queue = &priv->bulkqhs;
1021 else
1022 ep_queue = NULL;
1023 }
1024
1025 list_for_each_entry_safe(urb_listitem, urb_listitem_next, &urb_list,
1026 urb_list) {
1027 isp1760_urb_done(hcd, urb_listitem->urb);
1028 kmem_cache_free(urb_listitem_cachep, urb_listitem);
1029 }
1030
1031 /*
1032 * Schedule packets for transfer.
1033 *
1034 * According to USB2.0 specification:
1035 *
1036 * 1st prio: interrupt xfers, up to 80 % of bandwidth
1037 * 2nd prio: control xfers
1038 * 3rd prio: bulk xfers
1039 *
1040 * ... but let's use a simpler scheme here (mostly because ISP1761 doc
1041 * is very unclear on how to prioritize traffic):
1042 *
1043 * 1) Enqueue any queued control transfers, as long as payload chip mem
1044 * and PTD ATL slots are available.
1045 * 2) Enqueue any queued INT transfers, as long as payload chip mem
1046 * and PTD INT slots are available.
1047 * 3) Enqueue any queued bulk transfers, as long as payload chip mem
1048 * and PTD ATL slots are available.
1049 *
1050 * Use double buffering (ENQUEUE_DEPTH==2) as a compromise between
1051 * conservation of chip mem and performance.
1052 *
1053 * I'm sure this scheme could be improved upon!
1054 */
1055 ep_queue = &priv->controlqhs;
1056 while (ep_queue) {
1057 list_for_each_entry_safe(qh, qh_next, ep_queue, qh_list)
1058 enqueue_qtds(hcd, qh);
1059
1060 if (ep_queue == &priv->controlqhs)
1061 ep_queue = &priv->interruptqhs;
1062 else if (ep_queue == &priv->interruptqhs)
1063 ep_queue = &priv->bulkqhs;
1064 else
1065 ep_queue = NULL;
1066 }
1067}
1068
1069#define PTD_STATE_QTD_DONE 1
1070#define PTD_STATE_QTD_RELOAD 2
1071#define PTD_STATE_URB_RETIRE 3
1072
1073static int check_int_transfer(struct usb_hcd *hcd, struct ptd *ptd,
1074 struct urb *urb)
1075{
1076 __dw dw4;
1077 int i;
1078
1079 dw4 = ptd->dw4;
1080 dw4 >>= 8;
1081
1082 /* FIXME: ISP1761 datasheet does not say what to do with these. Do we
1083 need to handle these errors? Is it done in hardware? */
1084
1085 if (ptd->dw3 & DW3_HALT_BIT) {
1086
1087 urb->status = -EPROTO; /* Default unknown error */
1088
1089 for (i = 0; i < 8; i++) {
1090 switch (dw4 & 0x7) {
1091 case INT_UNDERRUN:
1092 dev_dbg(hcd->self.controller, "%s: underrun "
1093 "during uFrame %d\n",
1094 __func__, i);
1095 urb->status = -ECOMM; /* Could not write data */
1096 break;
1097 case INT_EXACT:
1098 dev_dbg(hcd->self.controller, "%s: transaction "
1099 "error during uFrame %d\n",
1100 __func__, i);
1101 urb->status = -EPROTO; /* timeout, bad CRC, PID
1102 error etc. */
1103 break;
1104 case INT_BABBLE:
1105 dev_dbg(hcd->self.controller, "%s: babble "
1106 "error during uFrame %d\n",
1107 __func__, i);
1108 urb->status = -EOVERFLOW;
1109 break;
1110 }
1111 dw4 >>= 3;
1112 }
1113
1114 return PTD_STATE_URB_RETIRE;
1115 }
1116
1117 return PTD_STATE_QTD_DONE;
1118}
1119
1120static int check_atl_transfer(struct usb_hcd *hcd, struct ptd *ptd,
1121 struct urb *urb)
1122{
1123 WARN_ON(!ptd);
1124 if (ptd->dw3 & DW3_HALT_BIT) {
1125 if (ptd->dw3 & DW3_BABBLE_BIT)
1126 urb->status = -EOVERFLOW;
1127 else if (FROM_DW3_CERR(ptd->dw3))
1128 urb->status = -EPIPE; /* Stall */
1129 else if (ptd->dw3 & DW3_ERROR_BIT)
1130 urb->status = -EPROTO; /* XactErr */
1131 else
1132 urb->status = -EPROTO; /* Unknown */
1133/*
1134 dev_dbg(hcd->self.controller, "%s: ptd error:\n"
1135 " dw0: %08x dw1: %08x dw2: %08x dw3: %08x\n"
1136 " dw4: %08x dw5: %08x dw6: %08x dw7: %08x\n",
1137 __func__,
1138 ptd->dw0, ptd->dw1, ptd->dw2, ptd->dw3,
1139 ptd->dw4, ptd->dw5, ptd->dw6, ptd->dw7);
1140*/
1141 return PTD_STATE_URB_RETIRE;
1142 }
1143
1144 if ((ptd->dw3 & DW3_ERROR_BIT) && (ptd->dw3 & DW3_ACTIVE_BIT)) {
1145 /* Transfer Error, *but* active and no HALT -> reload */
1146 dev_dbg(hcd->self.controller, "PID error; reloading ptd\n");
1147 return PTD_STATE_QTD_RELOAD;
1148 }
1149
1150 if (!FROM_DW3_NAKCOUNT(ptd->dw3) && (ptd->dw3 & DW3_ACTIVE_BIT)) {
1151 /*
1152 * NAKs are handled in HW by the chip. Usually if the
1153 * device is not able to send data fast enough.
1154 * This happens mostly on slower hardware.
1155 */
1156 return PTD_STATE_QTD_RELOAD;
1157 }
1158
1159 return PTD_STATE_QTD_DONE;
1160}
1161
1162static irqreturn_t isp1760_irq(struct usb_hcd *hcd)
1163{
1164 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1165 u32 imask;
1166 irqreturn_t irqret = IRQ_NONE;
1167 struct ptd ptd;
1168 struct isp1760_qh *qh;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001169 int slot;
1170 int state;
1171 struct slotinfo *slots;
1172 u32 ptd_offset;
1173 struct isp1760_qtd *qtd;
1174 int modified;
1175 static int last_active_ptds;
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001176 int int_skip_map, atl_skip_map;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001177
1178 spin_lock(&priv->lock);
1179
1180 if (!(hcd->state & HC_STATE_RUNNING))
1181 goto leave;
1182
1183 imask = reg_read32(hcd->regs, HC_INTERRUPT_REG);
1184 if (unlikely(!imask))
1185 goto leave;
1186 reg_write32(hcd->regs, HC_INTERRUPT_REG, imask); /* Clear */
1187
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001188 int_skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG);
1189 atl_skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG);
1190 priv->int_done_map |= reg_read32(hcd->regs, HC_INT_PTD_DONEMAP_REG);
1191 priv->atl_done_map |= reg_read32(hcd->regs, HC_ATL_PTD_DONEMAP_REG);
1192 priv->int_done_map &= ~int_skip_map;
1193 priv->atl_done_map &= ~atl_skip_map;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001194
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001195 modified = priv->int_done_map | priv->atl_done_map;
1196
1197 while (priv->int_done_map || priv->atl_done_map) {
1198 if (priv->int_done_map) {
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001199 /* INT ptd */
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001200 slot = __ffs(priv->int_done_map);
1201 priv->int_done_map &= ~(1 << slot);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001202 slots = priv->int_slots;
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001203 /* This should not trigger, and could be removed if
1204 noone have any problems with it triggering: */
1205 if (!slots[slot].qh) {
1206 WARN_ON(1);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001207 continue;
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001208 }
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001209 ptd_offset = INT_PTD_OFFSET;
1210 ptd_read(hcd->regs, INT_PTD_OFFSET, slot, &ptd);
1211 state = check_int_transfer(hcd, &ptd,
1212 slots[slot].qtd->urb);
1213 } else {
1214 /* ATL ptd */
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001215 slot = __ffs(priv->atl_done_map);
1216 priv->atl_done_map &= ~(1 << slot);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001217 slots = priv->atl_slots;
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001218 /* This should not trigger, and could be removed if
1219 noone have any problems with it triggering: */
1220 if (!slots[slot].qh) {
1221 WARN_ON(1);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001222 continue;
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001223 }
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001224 ptd_offset = ATL_PTD_OFFSET;
1225 ptd_read(hcd->regs, ATL_PTD_OFFSET, slot, &ptd);
1226 state = check_atl_transfer(hcd, &ptd,
1227 slots[slot].qtd->urb);
1228 }
1229
1230 qtd = slots[slot].qtd;
1231 slots[slot].qtd = NULL;
1232 qh = slots[slot].qh;
1233 slots[slot].qh = NULL;
1234 priv->active_ptds--;
1235 qh->slot = -1;
1236
1237 WARN_ON(qtd->status != QTD_XFER_STARTED);
1238
1239 switch (state) {
1240 case PTD_STATE_QTD_DONE:
1241 if ((usb_pipeint(qtd->urb->pipe)) &&
1242 (qtd->urb->dev->speed != USB_SPEED_HIGH))
1243 qtd->actual_length =
1244 FROM_DW3_SCS_NRBYTESTRANSFERRED(ptd.dw3);
1245 else
1246 qtd->actual_length =
1247 FROM_DW3_NRBYTESTRANSFERRED(ptd.dw3);
1248
1249 qtd->status = QTD_XFER_COMPLETE;
1250 if (list_is_last(&qtd->qtd_list, &qh->qtd_list) ||
1251 is_short_bulk(qtd))
1252 qtd = NULL;
1253 else
1254 qtd = list_entry(qtd->qtd_list.next,
1255 typeof(*qtd), qtd_list);
1256
1257 qh->toggle = FROM_DW3_DATA_TOGGLE(ptd.dw3);
1258 qh->ping = FROM_DW3_PING(ptd.dw3);
1259 break;
1260
1261 case PTD_STATE_QTD_RELOAD: /* QTD_RETRY, for atls only */
1262 qtd->status = QTD_PAYLOAD_ALLOC;
1263 ptd.dw0 |= DW0_VALID_BIT;
1264 /* RL counter = ERR counter */
1265 ptd.dw3 &= ~TO_DW3_NAKCOUNT(0xf);
1266 ptd.dw3 |= TO_DW3_NAKCOUNT(FROM_DW2_RL(ptd.dw2));
1267 ptd.dw3 &= ~TO_DW3_CERR(3);
1268 ptd.dw3 |= TO_DW3_CERR(ERR_COUNTER);
1269 qh->toggle = FROM_DW3_DATA_TOGGLE(ptd.dw3);
1270 qh->ping = FROM_DW3_PING(ptd.dw3);
1271 break;
1272
1273 case PTD_STATE_URB_RETIRE:
1274 qtd->status = QTD_RETIRE;
1275 qtd = NULL;
1276 qh->toggle = 0;
1277 qh->ping = 0;
1278 break;
1279
1280 default:
1281 WARN_ON(1);
1282 continue;
1283 }
1284
1285 if (qtd && (qtd->status == QTD_PAYLOAD_ALLOC)) {
1286 if (slots == priv->int_slots) {
1287 if (state == PTD_STATE_QTD_RELOAD)
1288 dev_err(hcd->self.controller,
1289 "%s: PTD_STATE_QTD_RELOAD on "
1290 "interrupt packet\n", __func__);
1291 if (state != PTD_STATE_QTD_RELOAD)
1292 create_ptd_int(qh, qtd, &ptd);
1293 } else {
1294 if (state != PTD_STATE_QTD_RELOAD)
1295 create_ptd_atl(qh, qtd, &ptd);
1296 }
1297
1298 start_bus_transfer(hcd, ptd_offset, slot, slots, qtd,
1299 qh, &ptd);
1300 }
1301 }
1302
1303 if (modified)
1304 schedule_ptds(hcd);
1305
1306 /* ISP1760 Errata 2 explains that interrupts may be missed (or not
1307 happen?) if two USB devices are running simultaneously. Perhaps
1308 this happens when a PTD is finished during interrupt handling;
1309 enable SOF interrupts if PTDs are still scheduled when exiting this
1310 interrupt handler, just to be safe. */
1311
1312 if (priv->active_ptds != last_active_ptds) {
1313 if (priv->active_ptds > 0)
1314 reg_write32(hcd->regs, HC_INTERRUPT_ENABLE,
1315 INTERRUPT_ENABLE_SOT_MASK);
1316 else
1317 reg_write32(hcd->regs, HC_INTERRUPT_ENABLE,
1318 INTERRUPT_ENABLE_MASK);
1319 last_active_ptds = priv->active_ptds;
1320 }
1321
1322 irqret = IRQ_HANDLED;
1323leave:
1324 spin_unlock(&priv->lock);
1325
1326 return irqret;
1327}
1328
Arvid Brodin34537732011-04-26 21:47:37 +02001329static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len)
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001330{
Arvid Brodin34537732011-04-26 21:47:37 +02001331 qtd->data_buffer = databuffer;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001332
Arvid Brodin34537732011-04-26 21:47:37 +02001333 if (len > MAX_PAYLOAD_SIZE)
1334 len = MAX_PAYLOAD_SIZE;
1335 qtd->length = len;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001336
Arvid Brodin34537732011-04-26 21:47:37 +02001337 return qtd->length;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001338}
1339
Arvid Brodin34537732011-04-26 21:47:37 +02001340static void qtd_list_free(struct list_head *qtd_list)
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001341{
Arvid Brodin34537732011-04-26 21:47:37 +02001342 struct isp1760_qtd *qtd, *qtd_next;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001343
Arvid Brodin34537732011-04-26 21:47:37 +02001344 list_for_each_entry_safe(qtd, qtd_next, qtd_list, qtd_list) {
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001345 list_del(&qtd->qtd_list);
Arvid Brodin34537732011-04-26 21:47:37 +02001346 qtd_free(qtd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001347 }
1348}
1349
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001350/*
Arvid Brodin34537732011-04-26 21:47:37 +02001351 * Packetize urb->transfer_buffer into list of packets of size wMaxPacketSize.
1352 * Also calculate the PID type (SETUP/IN/OUT) for each packet.
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001353 */
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001354#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
Arvid Brodin34537732011-04-26 21:47:37 +02001355static void packetize_urb(struct usb_hcd *hcd,
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001356 struct urb *urb, struct list_head *head, gfp_t flags)
1357{
Arvid Brodinfd436ae2011-02-26 22:03:49 +01001358 struct isp1760_qtd *qtd;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001359 void *buf;
Arvid Brodin34537732011-04-26 21:47:37 +02001360 int len, maxpacketsize;
1361 u8 packet_type;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001362
1363 /*
1364 * URBs map to sequences of QTDs: one logical transaction
1365 */
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001366
Arvid Brodin34537732011-04-26 21:47:37 +02001367 if (!urb->transfer_buffer && urb->transfer_buffer_length) {
1368 /* XXX This looks like usb storage / SCSI bug */
1369 dev_err(hcd->self.controller,
1370 "buf is null, dma is %08lx len is %d\n",
1371 (long unsigned)urb->transfer_dma,
1372 urb->transfer_buffer_length);
1373 WARN_ON(1);
1374 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001375
Arvid Brodin34537732011-04-26 21:47:37 +02001376 if (usb_pipein(urb->pipe))
1377 packet_type = IN_PID;
1378 else
1379 packet_type = OUT_PID;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001380
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001381 if (usb_pipecontrol(urb->pipe)) {
Arvid Brodin34537732011-04-26 21:47:37 +02001382 qtd = qtd_alloc(flags, urb, SETUP_PID);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001383 if (!qtd)
1384 goto cleanup;
Arvid Brodin34537732011-04-26 21:47:37 +02001385 qtd_fill(qtd, urb->setup_packet, sizeof(struct usb_ctrlrequest));
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001386 list_add_tail(&qtd->qtd_list, head);
1387
1388 /* for zero length DATA stages, STATUS is always IN */
Arvid Brodin34537732011-04-26 21:47:37 +02001389 if (urb->transfer_buffer_length == 0)
1390 packet_type = IN_PID;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001391 }
1392
Arvid Brodin34537732011-04-26 21:47:37 +02001393 maxpacketsize = max_packet(usb_maxpacket(urb->dev, urb->pipe,
1394 usb_pipeout(urb->pipe)));
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001395
1396 /*
1397 * buffer gets wrapped in one or more qtds;
1398 * last one may be "short" (including zero len)
1399 * and may serve as a control status ack
1400 */
Arvid Brodin34537732011-04-26 21:47:37 +02001401 buf = urb->transfer_buffer;
1402 len = urb->transfer_buffer_length;
1403
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001404 for (;;) {
1405 int this_qtd_len;
1406
Arvid Brodin34537732011-04-26 21:47:37 +02001407 qtd = qtd_alloc(flags, urb, packet_type);
1408 if (!qtd)
1409 goto cleanup;
1410 this_qtd_len = qtd_fill(qtd, buf, len);
1411 list_add_tail(&qtd->qtd_list, head);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001412
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001413 len -= this_qtd_len;
1414 buf += this_qtd_len;
1415
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001416 if (len <= 0)
1417 break;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001418 }
1419
1420 /*
1421 * control requests may need a terminating data "status" ack;
1422 * bulk ones may need a terminating short packet (zero length).
1423 */
1424 if (urb->transfer_buffer_length != 0) {
1425 int one_more = 0;
1426
1427 if (usb_pipecontrol(urb->pipe)) {
1428 one_more = 1;
Arvid Brodin34537732011-04-26 21:47:37 +02001429 if (packet_type == IN_PID)
1430 packet_type = OUT_PID;
1431 else
1432 packet_type = IN_PID;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001433 } else if (usb_pipebulk(urb->pipe)
1434 && (urb->transfer_flags & URB_ZERO_PACKET)
Arvid Brodin34537732011-04-26 21:47:37 +02001435 && !(urb->transfer_buffer_length %
1436 maxpacketsize)) {
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001437 one_more = 1;
1438 }
1439 if (one_more) {
Arvid Brodin34537732011-04-26 21:47:37 +02001440 qtd = qtd_alloc(flags, urb, packet_type);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001441 if (!qtd)
1442 goto cleanup;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001443
1444 /* never any data in such packets */
Arvid Brodin34537732011-04-26 21:47:37 +02001445 qtd_fill(qtd, NULL, 0);
1446 list_add_tail(&qtd->qtd_list, head);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001447 }
1448 }
1449
Arvid Brodin34537732011-04-26 21:47:37 +02001450 return;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001451
1452cleanup:
Arvid Brodin34537732011-04-26 21:47:37 +02001453 qtd_list_free(head);
1454}
1455
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001456static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1457 gfp_t mem_flags)
1458{
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001459 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1460 struct list_head *ep_queue;
1461 struct isp1760_qh *qh, *qhit;
1462 unsigned long spinflags;
1463 LIST_HEAD(new_qtds);
1464 int retval;
1465 int qh_in_queue;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001466
1467 switch (usb_pipetype(urb->pipe)) {
1468 case PIPE_CONTROL:
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001469 ep_queue = &priv->controlqhs;
1470 break;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001471 case PIPE_BULK:
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001472 ep_queue = &priv->bulkqhs;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001473 break;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001474 case PIPE_INTERRUPT:
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001475 if (urb->interval < 0)
1476 return -EINVAL;
1477 /* FIXME: Check bandwidth */
1478 ep_queue = &priv->interruptqhs;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001479 break;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001480 case PIPE_ISOCHRONOUS:
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001481 dev_err(hcd->self.controller, "%s: isochronous USB packets "
1482 "not yet supported\n",
1483 __func__);
1484 return -EPIPE;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001485 default:
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001486 dev_err(hcd->self.controller, "%s: unknown pipe type\n",
1487 __func__);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001488 return -EPIPE;
1489 }
1490
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001491 if (usb_pipein(urb->pipe))
1492 urb->actual_length = 0;
1493
1494 packetize_urb(hcd, urb, &new_qtds, mem_flags);
1495 if (list_empty(&new_qtds))
Arvid Brodin34537732011-04-26 21:47:37 +02001496 return -ENOMEM;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001497 urb->hcpriv = NULL; /* Used to signal unlink to interrupt handler */
Arvid Brodin34537732011-04-26 21:47:37 +02001498
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001499 retval = 0;
1500 spin_lock_irqsave(&priv->lock, spinflags);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001501
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001502 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
1503 retval = -ESHUTDOWN;
1504 goto out;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001505 }
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001506 retval = usb_hcd_link_urb_to_ep(hcd, urb);
1507 if (retval)
1508 goto out;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001509
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001510 qh = urb->ep->hcpriv;
1511 if (qh) {
1512 qh_in_queue = 0;
1513 list_for_each_entry(qhit, ep_queue, qh_list) {
1514 if (qhit == qh) {
1515 qh_in_queue = 1;
Warren Free0afb20e2009-05-08 10:27:08 +02001516 break;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001517 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001518 }
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001519 if (!qh_in_queue)
1520 list_add_tail(&qh->qh_list, ep_queue);
1521 } else {
1522 qh = qh_alloc(GFP_ATOMIC);
1523 if (!qh) {
1524 retval = -ENOMEM;
1525 goto out;
1526 }
1527 list_add_tail(&qh->qh_list, ep_queue);
1528 urb->ep->hcpriv = qh;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001529 }
1530
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001531 list_splice_tail(&new_qtds, &qh->qtd_list);
1532 schedule_ptds(hcd);
1533
1534out:
1535 spin_unlock_irqrestore(&priv->lock, spinflags);
1536 return retval;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001537}
1538
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001539static void kill_transfer(struct usb_hcd *hcd, struct urb *urb,
1540 struct isp1760_qh *qh)
1541{
1542 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1543 int skip_map;
1544
1545 WARN_ON(qh->slot == -1);
1546
1547 /* We need to forcefully reclaim the slot since some transfers never
1548 return, e.g. interrupt transfers and NAKed bulk transfers. */
Arvid Brodin8b1ab602011-06-17 18:45:37 +02001549 if (usb_pipecontrol(urb->pipe) || usb_pipebulk(urb->pipe)) {
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001550 skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG);
1551 skip_map |= (1 << qh->slot);
1552 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map);
1553 priv->atl_slots[qh->slot].qh = NULL;
1554 priv->atl_slots[qh->slot].qtd = NULL;
1555 } else {
1556 skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG);
1557 skip_map |= (1 << qh->slot);
1558 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map);
1559 priv->int_slots[qh->slot].qh = NULL;
1560 priv->int_slots[qh->slot].qtd = NULL;
1561 }
1562
1563 qh->slot = -1;
1564 priv->active_ptds--;
1565}
1566
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001567static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1568 int status)
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001569{
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001570 struct isp1760_hcd *priv = hcd_to_priv(hcd);
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001571 unsigned long spinflags;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001572 struct isp1760_qh *qh;
1573 struct isp1760_qtd *qtd;
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001574 int retval = 0;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001575
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001576 spin_lock_irqsave(&priv->lock, spinflags);
Arvid Brodin17d3e142011-07-20 03:13:46 +02001577 retval = usb_hcd_check_unlink_urb(hcd, urb, status);
1578 if (retval)
1579 goto out;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001580
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001581 qh = urb->ep->hcpriv;
1582 if (!qh) {
1583 retval = -EINVAL;
1584 goto out;
1585 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001586
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001587 list_for_each_entry(qtd, &qh->qtd_list, qtd_list)
1588 if (qtd->urb == urb) {
1589 if (qtd->status == QTD_XFER_STARTED)
1590 kill_transfer(hcd, urb, qh);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001591 qtd->status = QTD_RETIRE;
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001592 }
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001593
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001594 urb->status = status;
1595 schedule_ptds(hcd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001596
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001597out:
1598 spin_unlock_irqrestore(&priv->lock, spinflags);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001599 return retval;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001600}
1601
Arvid Brodin079cdb02011-05-20 00:17:34 +02001602static void isp1760_endpoint_disable(struct usb_hcd *hcd,
1603 struct usb_host_endpoint *ep)
1604{
1605 struct isp1760_hcd *priv = hcd_to_priv(hcd);
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001606 unsigned long spinflags;
Arvid Brodin079cdb02011-05-20 00:17:34 +02001607 struct isp1760_qh *qh;
1608 struct isp1760_qtd *qtd;
Arvid Brodin079cdb02011-05-20 00:17:34 +02001609
1610 spin_lock_irqsave(&priv->lock, spinflags);
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001611
Arvid Brodin079cdb02011-05-20 00:17:34 +02001612 qh = ep->hcpriv;
1613 if (!qh)
1614 goto out;
1615
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001616 list_for_each_entry(qtd, &qh->qtd_list, qtd_list) {
1617 if (qtd->status == QTD_XFER_STARTED)
1618 kill_transfer(hcd, qtd->urb, qh);
1619 qtd->status = QTD_RETIRE;
1620 qtd->urb->status = -ECONNRESET;
Arvid Brodin079cdb02011-05-20 00:17:34 +02001621 }
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001622
Arvid Brodin079cdb02011-05-20 00:17:34 +02001623 ep->hcpriv = NULL;
1624 /* Cannot free qh here since it will be parsed by schedule_ptds() */
1625
Arvid Brodind05b6ec2011-05-20 00:17:45 +02001626 schedule_ptds(hcd);
1627
Arvid Brodin079cdb02011-05-20 00:17:34 +02001628out:
1629 spin_unlock_irqrestore(&priv->lock, spinflags);
1630}
1631
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001632static int isp1760_hub_status_data(struct usb_hcd *hcd, char *buf)
1633{
1634 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1635 u32 temp, status = 0;
1636 u32 mask;
1637 int retval = 1;
1638 unsigned long flags;
1639
1640 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
1641 if (!HC_IS_RUNNING(hcd->state))
1642 return 0;
1643
1644 /* init status to no-changes */
1645 buf[0] = 0;
1646 mask = PORT_CSC;
1647
1648 spin_lock_irqsave(&priv->lock, flags);
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001649 temp = reg_read32(hcd->regs, HC_PORTSC1);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001650
1651 if (temp & PORT_OWNER) {
1652 if (temp & PORT_CSC) {
1653 temp &= ~PORT_CSC;
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001654 reg_write32(hcd->regs, HC_PORTSC1, temp);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001655 goto done;
1656 }
1657 }
1658
1659 /*
1660 * Return status information even for ports with OWNER set.
1661 * Otherwise khubd wouldn't see the disconnect event when a
1662 * high-speed device is switched over to the companion
1663 * controller by the user.
1664 */
1665
1666 if ((temp & mask) != 0
1667 || ((temp & PORT_RESUME) != 0
1668 && time_after_eq(jiffies,
1669 priv->reset_done))) {
1670 buf [0] |= 1 << (0 + 1);
1671 status = STS_PCD;
1672 }
1673 /* FIXME autosuspend idle root hubs */
1674done:
1675 spin_unlock_irqrestore(&priv->lock, flags);
1676 return status ? retval : 0;
1677}
1678
1679static void isp1760_hub_descriptor(struct isp1760_hcd *priv,
1680 struct usb_hub_descriptor *desc)
1681{
1682 int ports = HCS_N_PORTS(priv->hcs_params);
1683 u16 temp;
1684
1685 desc->bDescriptorType = 0x29;
1686 /* priv 1.0, 2.3.9 says 20ms max */
1687 desc->bPwrOn2PwrGood = 10;
1688 desc->bHubContrCurrent = 0;
1689
1690 desc->bNbrPorts = ports;
1691 temp = 1 + (ports / 8);
1692 desc->bDescLength = 7 + 2 * temp;
1693
Sarah Sharpda130512010-11-30 15:55:51 -08001694 /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */
John Youndbe79bb2001-09-17 00:00:00 -07001695 memset(&desc->u.hs.DeviceRemovable[0], 0, temp);
1696 memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001697
1698 /* per-port overcurrent reporting */
1699 temp = 0x0008;
1700 if (HCS_PPC(priv->hcs_params))
1701 /* per-port power control */
1702 temp |= 0x0001;
1703 else
1704 /* no power switching */
1705 temp |= 0x0002;
1706 desc->wHubCharacteristics = cpu_to_le16(temp);
1707}
1708
1709#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
1710
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001711static int check_reset_complete(struct usb_hcd *hcd, int index,
1712 int port_status)
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001713{
1714 if (!(port_status & PORT_CONNECT))
1715 return port_status;
1716
1717 /* if reset finished and it's still not enabled -- handoff */
1718 if (!(port_status & PORT_PE)) {
1719
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001720 dev_info(hcd->self.controller,
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001721 "port %d full speed --> companion\n",
1722 index + 1);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001723
1724 port_status |= PORT_OWNER;
1725 port_status &= ~PORT_RWC_BITS;
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001726 reg_write32(hcd->regs, HC_PORTSC1, port_status);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001727
1728 } else
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02001729 dev_info(hcd->self.controller, "port %d high speed\n",
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001730 index + 1);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001731
1732 return port_status;
1733}
1734
1735static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1736 u16 wValue, u16 wIndex, char *buf, u16 wLength)
1737{
1738 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1739 int ports = HCS_N_PORTS(priv->hcs_params);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001740 u32 temp, status;
1741 unsigned long flags;
1742 int retval = 0;
1743 unsigned selector;
1744
1745 /*
1746 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
1747 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
1748 * (track current state ourselves) ... blink for diagnostics,
1749 * power, "this is the one", etc. EHCI spec supports this.
1750 */
1751
1752 spin_lock_irqsave(&priv->lock, flags);
1753 switch (typeReq) {
1754 case ClearHubFeature:
1755 switch (wValue) {
1756 case C_HUB_LOCAL_POWER:
1757 case C_HUB_OVER_CURRENT:
1758 /* no hub-wide feature/status flags */
1759 break;
1760 default:
1761 goto error;
1762 }
1763 break;
1764 case ClearPortFeature:
1765 if (!wIndex || wIndex > ports)
1766 goto error;
1767 wIndex--;
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001768 temp = reg_read32(hcd->regs, HC_PORTSC1);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001769
1770 /*
1771 * Even if OWNER is set, so the port is owned by the
1772 * companion controller, khubd needs to be able to clear
1773 * the port-change status bits (especially
Alan Stern749da5f2010-03-04 17:05:08 -05001774 * USB_PORT_STAT_C_CONNECTION).
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001775 */
1776
1777 switch (wValue) {
1778 case USB_PORT_FEAT_ENABLE:
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001779 reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_PE);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001780 break;
1781 case USB_PORT_FEAT_C_ENABLE:
1782 /* XXX error? */
1783 break;
1784 case USB_PORT_FEAT_SUSPEND:
1785 if (temp & PORT_RESET)
1786 goto error;
1787
1788 if (temp & PORT_SUSPEND) {
1789 if ((temp & PORT_PE) == 0)
1790 goto error;
1791 /* resume signaling for 20 msec */
1792 temp &= ~(PORT_RWC_BITS);
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001793 reg_write32(hcd->regs, HC_PORTSC1,
1794 temp | PORT_RESUME);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001795 priv->reset_done = jiffies +
1796 msecs_to_jiffies(20);
1797 }
1798 break;
1799 case USB_PORT_FEAT_C_SUSPEND:
1800 /* we auto-clear this feature */
1801 break;
1802 case USB_PORT_FEAT_POWER:
1803 if (HCS_PPC(priv->hcs_params))
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001804 reg_write32(hcd->regs, HC_PORTSC1,
1805 temp & ~PORT_POWER);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001806 break;
1807 case USB_PORT_FEAT_C_CONNECTION:
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001808 reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_CSC);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001809 break;
1810 case USB_PORT_FEAT_C_OVER_CURRENT:
1811 /* XXX error ?*/
1812 break;
1813 case USB_PORT_FEAT_C_RESET:
1814 /* GetPortStatus clears reset */
1815 break;
1816 default:
1817 goto error;
1818 }
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001819 reg_read32(hcd->regs, HC_USBCMD);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001820 break;
1821 case GetHubDescriptor:
1822 isp1760_hub_descriptor(priv, (struct usb_hub_descriptor *)
1823 buf);
1824 break;
1825 case GetHubStatus:
1826 /* no hub-wide feature/status flags */
1827 memset(buf, 0, 4);
1828 break;
1829 case GetPortStatus:
1830 if (!wIndex || wIndex > ports)
1831 goto error;
1832 wIndex--;
1833 status = 0;
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001834 temp = reg_read32(hcd->regs, HC_PORTSC1);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001835
1836 /* wPortChange bits */
1837 if (temp & PORT_CSC)
Alan Stern749da5f2010-03-04 17:05:08 -05001838 status |= USB_PORT_STAT_C_CONNECTION << 16;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001839
1840
1841 /* whoever resumes must GetPortStatus to complete it!! */
1842 if (temp & PORT_RESUME) {
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001843 dev_err(hcd->self.controller, "Port resume should be skipped.\n");
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001844
1845 /* Remote Wakeup received? */
1846 if (!priv->reset_done) {
1847 /* resume signaling for 20 msec */
1848 priv->reset_done = jiffies
1849 + msecs_to_jiffies(20);
1850 /* check the port again */
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001851 mod_timer(&hcd->rh_timer, priv->reset_done);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001852 }
1853
1854 /* resume completed? */
1855 else if (time_after_eq(jiffies,
1856 priv->reset_done)) {
Alan Stern749da5f2010-03-04 17:05:08 -05001857 status |= USB_PORT_STAT_C_SUSPEND << 16;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001858 priv->reset_done = 0;
1859
1860 /* stop resume signaling */
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001861 temp = reg_read32(hcd->regs, HC_PORTSC1);
1862 reg_write32(hcd->regs, HC_PORTSC1,
1863 temp & ~(PORT_RWC_BITS | PORT_RESUME));
1864 retval = handshake(hcd, HC_PORTSC1,
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001865 PORT_RESUME, 0, 2000 /* 2msec */);
1866 if (retval != 0) {
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001867 dev_err(hcd->self.controller,
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001868 "port %d resume error %d\n",
1869 wIndex + 1, retval);
1870 goto error;
1871 }
1872 temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10));
1873 }
1874 }
1875
1876 /* whoever resets must GetPortStatus to complete it!! */
1877 if ((temp & PORT_RESET)
1878 && time_after_eq(jiffies,
1879 priv->reset_done)) {
Alan Stern749da5f2010-03-04 17:05:08 -05001880 status |= USB_PORT_STAT_C_RESET << 16;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001881 priv->reset_done = 0;
1882
1883 /* force reset to complete */
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001884 reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_RESET);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001885 /* REVISIT: some hardware needs 550+ usec to clear
1886 * this bit; seems too long to spin routinely...
1887 */
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001888 retval = handshake(hcd, HC_PORTSC1,
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001889 PORT_RESET, 0, 750);
1890 if (retval != 0) {
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001891 dev_err(hcd->self.controller, "port %d reset error %d\n",
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001892 wIndex + 1, retval);
1893 goto error;
1894 }
1895
1896 /* see what we found out */
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001897 temp = check_reset_complete(hcd, wIndex,
1898 reg_read32(hcd->regs, HC_PORTSC1));
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001899 }
1900 /*
1901 * Even if OWNER is set, there's no harm letting khubd
1902 * see the wPortStatus values (they should all be 0 except
1903 * for PORT_POWER anyway).
1904 */
1905
1906 if (temp & PORT_OWNER)
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001907 dev_err(hcd->self.controller, "PORT_OWNER is set\n");
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001908
1909 if (temp & PORT_CONNECT) {
Alan Stern749da5f2010-03-04 17:05:08 -05001910 status |= USB_PORT_STAT_CONNECTION;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001911 /* status may be from integrated TT */
Arvid Brodin6bda21b2011-02-26 22:06:37 +01001912 status |= USB_PORT_STAT_HIGH_SPEED;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001913 }
1914 if (temp & PORT_PE)
Alan Stern749da5f2010-03-04 17:05:08 -05001915 status |= USB_PORT_STAT_ENABLE;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001916 if (temp & (PORT_SUSPEND|PORT_RESUME))
Alan Stern749da5f2010-03-04 17:05:08 -05001917 status |= USB_PORT_STAT_SUSPEND;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001918 if (temp & PORT_RESET)
Alan Stern749da5f2010-03-04 17:05:08 -05001919 status |= USB_PORT_STAT_RESET;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001920 if (temp & PORT_POWER)
Alan Stern749da5f2010-03-04 17:05:08 -05001921 status |= USB_PORT_STAT_POWER;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001922
1923 put_unaligned(cpu_to_le32(status), (__le32 *) buf);
1924 break;
1925 case SetHubFeature:
1926 switch (wValue) {
1927 case C_HUB_LOCAL_POWER:
1928 case C_HUB_OVER_CURRENT:
1929 /* no hub-wide feature/status flags */
1930 break;
1931 default:
1932 goto error;
1933 }
1934 break;
1935 case SetPortFeature:
1936 selector = wIndex >> 8;
1937 wIndex &= 0xff;
1938 if (!wIndex || wIndex > ports)
1939 goto error;
1940 wIndex--;
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001941 temp = reg_read32(hcd->regs, HC_PORTSC1);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001942 if (temp & PORT_OWNER)
1943 break;
1944
1945/* temp &= ~PORT_RWC_BITS; */
1946 switch (wValue) {
1947 case USB_PORT_FEAT_ENABLE:
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001948 reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_PE);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001949 break;
1950
1951 case USB_PORT_FEAT_SUSPEND:
1952 if ((temp & PORT_PE) == 0
1953 || (temp & PORT_RESET) != 0)
1954 goto error;
1955
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001956 reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_SUSPEND);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001957 break;
1958 case USB_PORT_FEAT_POWER:
1959 if (HCS_PPC(priv->hcs_params))
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001960 reg_write32(hcd->regs, HC_PORTSC1,
1961 temp | PORT_POWER);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001962 break;
1963 case USB_PORT_FEAT_RESET:
1964 if (temp & PORT_RESUME)
1965 goto error;
1966 /* line status bits may report this as low speed,
1967 * which can be fine if this root hub has a
1968 * transaction translator built in.
1969 */
1970 if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
1971 && PORT_USB11(temp)) {
1972 temp |= PORT_OWNER;
1973 } else {
1974 temp |= PORT_RESET;
1975 temp &= ~PORT_PE;
1976
1977 /*
1978 * caller must wait, then call GetPortStatus
1979 * usb 2.0 spec says 50 ms resets on root
1980 */
1981 priv->reset_done = jiffies +
1982 msecs_to_jiffies(50);
1983 }
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001984 reg_write32(hcd->regs, HC_PORTSC1, temp);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001985 break;
1986 default:
1987 goto error;
1988 }
Arvid Brodinbedc0c32011-02-26 22:02:57 +01001989 reg_read32(hcd->regs, HC_USBCMD);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02001990 break;
1991
1992 default:
1993error:
1994 /* "stall" on error */
1995 retval = -EPIPE;
1996 }
1997 spin_unlock_irqrestore(&priv->lock, flags);
1998 return retval;
1999}
2000
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002001static int isp1760_get_frame(struct usb_hcd *hcd)
2002{
2003 struct isp1760_hcd *priv = hcd_to_priv(hcd);
2004 u32 fr;
2005
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002006 fr = reg_read32(hcd->regs, HC_FRINDEX);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002007 return (fr >> 3) % priv->periodic_size;
2008}
2009
2010static void isp1760_stop(struct usb_hcd *hcd)
2011{
2012 struct isp1760_hcd *priv = hcd_to_priv(hcd);
Nate Case3faefc82008-06-17 11:11:38 -05002013 u32 temp;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002014
2015 isp1760_hub_control(hcd, ClearPortFeature, USB_PORT_FEAT_POWER, 1,
2016 NULL, 0);
2017 mdelay(20);
2018
2019 spin_lock_irq(&priv->lock);
Arvid Brodin6bda21b2011-02-26 22:06:37 +01002020 ehci_reset(hcd);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002021 /* Disable IRQ */
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002022 temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL);
2023 reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp &= ~HW_GLOBAL_INTR_EN);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002024 spin_unlock_irq(&priv->lock);
2025
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002026 reg_write32(hcd->regs, HC_CONFIGFLAG, 0);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002027}
2028
2029static void isp1760_shutdown(struct usb_hcd *hcd)
2030{
Nate Case3faefc82008-06-17 11:11:38 -05002031 u32 command, temp;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002032
2033 isp1760_stop(hcd);
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002034 temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL);
2035 reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp &= ~HW_GLOBAL_INTR_EN);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002036
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002037 command = reg_read32(hcd->regs, HC_USBCMD);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002038 command &= ~CMD_RUN;
Arvid Brodinbedc0c32011-02-26 22:02:57 +01002039 reg_write32(hcd->regs, HC_USBCMD, command);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002040}
2041
2042static const struct hc_driver isp1760_hc_driver = {
2043 .description = "isp1760-hcd",
2044 .product_desc = "NXP ISP1760 USB Host Controller",
2045 .hcd_priv_size = sizeof(struct isp1760_hcd),
2046 .irq = isp1760_irq,
2047 .flags = HCD_MEMORY | HCD_USB2,
2048 .reset = isp1760_hc_setup,
2049 .start = isp1760_run,
2050 .stop = isp1760_stop,
2051 .shutdown = isp1760_shutdown,
2052 .urb_enqueue = isp1760_urb_enqueue,
2053 .urb_dequeue = isp1760_urb_dequeue,
2054 .endpoint_disable = isp1760_endpoint_disable,
2055 .get_frame_number = isp1760_get_frame,
2056 .hub_status_data = isp1760_hub_status_data,
2057 .hub_control = isp1760_hub_control,
2058};
2059
2060int __init init_kmem_once(void)
2061{
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02002062 urb_listitem_cachep = kmem_cache_create("isp1760 urb_listitem",
2063 sizeof(struct urb_listitem), 0, SLAB_TEMPORARY |
2064 SLAB_MEM_SPREAD, NULL);
2065
2066 if (!urb_listitem_cachep)
2067 return -ENOMEM;
2068
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002069 qtd_cachep = kmem_cache_create("isp1760_qtd",
2070 sizeof(struct isp1760_qtd), 0, SLAB_TEMPORARY |
2071 SLAB_MEM_SPREAD, NULL);
2072
2073 if (!qtd_cachep)
2074 return -ENOMEM;
2075
2076 qh_cachep = kmem_cache_create("isp1760_qh", sizeof(struct isp1760_qh),
2077 0, SLAB_TEMPORARY | SLAB_MEM_SPREAD, NULL);
2078
2079 if (!qh_cachep) {
2080 kmem_cache_destroy(qtd_cachep);
2081 return -ENOMEM;
2082 }
2083
2084 return 0;
2085}
2086
2087void deinit_kmem_cache(void)
2088{
2089 kmem_cache_destroy(qtd_cachep);
2090 kmem_cache_destroy(qh_cachep);
Arvid Brodin71a9f9d2011-04-26 21:48:30 +02002091 kmem_cache_destroy(urb_listitem_cachep);
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002092}
2093
Catalin Marinasf9031f22009-02-10 16:55:45 +00002094struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len,
2095 int irq, unsigned long irqflags,
2096 struct device *dev, const char *busname,
2097 unsigned int devflags)
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002098{
2099 struct usb_hcd *hcd;
2100 struct isp1760_hcd *priv;
2101 int ret;
2102
2103 if (usb_disabled())
2104 return ERR_PTR(-ENODEV);
2105
2106 /* prevent usb-core allocating DMA pages */
2107 dev->dma_mask = NULL;
2108
Kay Sievers0031a062008-05-02 06:02:41 +02002109 hcd = usb_create_hcd(&isp1760_hc_driver, dev, dev_name(dev));
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002110 if (!hcd)
2111 return ERR_PTR(-ENOMEM);
2112
2113 priv = hcd_to_priv(hcd);
Nate Case3faefc82008-06-17 11:11:38 -05002114 priv->devflags = devflags;
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002115 init_memory(priv);
2116 hcd->regs = ioremap(res_start, res_len);
2117 if (!hcd->regs) {
2118 ret = -EIO;
2119 goto err_put;
2120 }
2121
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002122 hcd->irq = irq;
2123 hcd->rsrc_start = res_start;
2124 hcd->rsrc_len = res_len;
2125
Nate Casee6942d62008-05-21 16:28:20 -05002126 ret = usb_add_hcd(hcd, irq, irqflags);
2127 if (ret)
2128 goto err_unmap;
2129
Sebastian Siewiordb11e472008-04-24 00:37:04 +02002130 return hcd;
2131
2132err_unmap:
2133 iounmap(hcd->regs);
2134
2135err_put:
2136 usb_put_hcd(hcd);
2137
2138 return ERR_PTR(ret);
2139}
2140
2141MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP");
2142MODULE_AUTHOR("Sebastian Siewior <bigeasy@linuxtronix.de>");
2143MODULE_LICENSE("GPL v2");