Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1 | /* |
| 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 Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 11 | * (c) 2011 Arvid Brodin <arvid.brodin@enea.com> |
| 12 | * |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 13 | */ |
| 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 Lescouet | 27729aa | 2010-04-24 23:21:52 +0200 | [diff] [blame] | 19 | #include <linux/usb/hcd.h> |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 20 | #include <linux/debugfs.h> |
| 21 | #include <linux/uaccess.h> |
| 22 | #include <linux/io.h> |
Catalin Marinas | db8516f | 2010-02-02 15:31:02 +0000 | [diff] [blame] | 23 | #include <linux/mm.h> |
Arvid Brodin | 6d50c60 | 2011-08-21 08:29:26 +0200 | [diff] [blame^] | 24 | #include <linux/timer.h> |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 25 | #include <asm/unaligned.h> |
Catalin Marinas | db8516f | 2010-02-02 15:31:02 +0000 | [diff] [blame] | 26 | #include <asm/cacheflush.h> |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 27 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 28 | #include "isp1760-hcd.h" |
| 29 | |
| 30 | static struct kmem_cache *qtd_cachep; |
| 31 | static struct kmem_cache *qh_cachep; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 32 | static struct kmem_cache *urb_listitem_cachep; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 33 | |
| 34 | struct isp1760_hcd { |
| 35 | u32 hcs_params; |
| 36 | spinlock_t lock; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 37 | struct slotinfo atl_slots[32]; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 38 | int atl_done_map; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 39 | struct slotinfo int_slots[32]; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 40 | int int_done_map; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 41 | struct memory_chunk memory_pool[BLOCKS]; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 42 | struct list_head controlqhs, bulkqhs, interruptqhs; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 43 | |
| 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 Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 50 | unsigned int devflags; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | static inline struct isp1760_hcd *hcd_to_priv(struct usb_hcd *hcd) |
| 54 | { |
| 55 | return (struct isp1760_hcd *) (hcd->hcd_priv); |
| 56 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 57 | |
| 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 | |
| 85 | struct isp1760_qtd { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 86 | u8 packet_type; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 87 | void *data_buffer; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 88 | u32 payload_addr; |
| 89 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 90 | /* the rest is HCD-private */ |
| 91 | struct list_head qtd_list; |
| 92 | struct urb *urb; |
| 93 | size_t length; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 94 | size_t actual_length; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 95 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 96 | /* 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 107 | u32 status; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 108 | }; |
| 109 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 110 | /* Queue head, one for each active endpoint */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 111 | struct isp1760_qh { |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 112 | struct list_head qh_list; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 113 | struct list_head qtd_list; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 114 | u32 toggle; |
| 115 | u32 ping; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 116 | int slot; |
| 117 | }; |
| 118 | |
| 119 | struct urb_listitem { |
| 120 | struct list_head urb_list; |
| 121 | struct urb *urb; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 122 | }; |
| 123 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 124 | /* |
| 125 | * Access functions for isp176x registers (addresses 0..0x03FF). |
| 126 | */ |
| 127 | static u32 reg_read32(void __iomem *base, u32 reg) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 128 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 129 | return readl(base + reg); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 130 | } |
| 131 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 132 | static void reg_write32(void __iomem *base, u32 reg, u32 val) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 133 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 134 | writel(val, base + reg); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /* |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 138 | * 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 148 | * doesn't quite work because some people have to enforce 32-bit access |
| 149 | */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 150 | static void bank_reads8(void __iomem *src_base, u32 src_offset, u32 bank_addr, |
| 151 | __u32 *dst, u32 bytes) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 152 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 153 | __u32 __iomem *src; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 154 | u32 val; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 155 | __u8 *src_byteptr; |
| 156 | __u8 *dst_byteptr; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 157 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 158 | 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 174 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 175 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 176 | if (!bytes) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 177 | return; |
| 178 | |
| 179 | /* in case we have 3, 2 or 1 by left. The dst buffer may not be fully |
| 180 | * allocated. |
| 181 | */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 182 | if (src_offset < PAYLOAD_OFFSET) |
| 183 | val = le32_to_cpu(__raw_readl(src)); |
| 184 | else |
| 185 | val = __raw_readl(src); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 186 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 187 | 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 197 | static void mem_reads8(void __iomem *src_base, u32 src_offset, void *dst, |
| 198 | u32 bytes) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 199 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 200 | 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 | |
| 205 | static 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 226 | } |
| 227 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 228 | if (!bytes) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 229 | return; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 230 | /* 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 232 | */ |
| 233 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 234 | if (dst_offset < PAYLOAD_OFFSET) |
| 235 | __raw_writel(cpu_to_le32(*src), dst); |
| 236 | else |
| 237 | __raw_writel(*src, dst); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 238 | } |
| 239 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 240 | /* |
| 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 | */ |
| 244 | static 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 | |
| 254 | static 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 267 | /* memory management of the 60kb on the chip from 0x1000 to 0xffff */ |
| 268 | static void init_memory(struct isp1760_hcd *priv) |
| 269 | { |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 270 | int i, curr; |
| 271 | u32 payload_addr; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 272 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 273 | payload_addr = PAYLOAD_OFFSET; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 274 | for (i = 0; i < BLOCK_1_NUM; i++) { |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 275 | priv->memory_pool[i].start = payload_addr; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 276 | priv->memory_pool[i].size = BLOCK_1_SIZE; |
| 277 | priv->memory_pool[i].free = 1; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 278 | payload_addr += priv->memory_pool[i].size; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 279 | } |
| 280 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 281 | 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 287 | } |
| 288 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 289 | 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 295 | } |
| 296 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 297 | WARN_ON(payload_addr - priv->memory_pool[0].start > PAYLOAD_AREA_SIZE); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 298 | } |
| 299 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 300 | static void alloc_mem(struct usb_hcd *hcd, struct isp1760_qtd *qtd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 301 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 302 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 303 | int i; |
| 304 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 305 | WARN_ON(qtd->payload_addr); |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 306 | |
| 307 | if (!qtd->length) |
| 308 | return; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 309 | |
| 310 | for (i = 0; i < BLOCKS; i++) { |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 311 | if (priv->memory_pool[i].size >= qtd->length && |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 312 | priv->memory_pool[i].free) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 313 | priv->memory_pool[i].free = 0; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 314 | qtd->payload_addr = priv->memory_pool[i].start; |
| 315 | return; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 316 | } |
| 317 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 318 | } |
| 319 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 320 | static void free_mem(struct usb_hcd *hcd, struct isp1760_qtd *qtd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 321 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 322 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 323 | int i; |
| 324 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 325 | if (!qtd->payload_addr) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 326 | return; |
| 327 | |
| 328 | for (i = 0; i < BLOCKS; i++) { |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 329 | if (priv->memory_pool[i].start == qtd->payload_addr) { |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 330 | WARN_ON(priv->memory_pool[i].free); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 331 | priv->memory_pool[i].free = 1; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 332 | qtd->payload_addr = 0; |
| 333 | return; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 337 | dev_err(hcd->self.controller, "%s: Invalid pointer: %08x\n", |
| 338 | __func__, qtd->payload_addr); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 339 | WARN_ON(1); |
| 340 | qtd->payload_addr = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 341 | } |
| 342 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 343 | static int handshake(struct usb_hcd *hcd, u32 reg, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 344 | u32 mask, u32 done, int usec) |
| 345 | { |
| 346 | u32 result; |
| 347 | |
| 348 | do { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 349 | result = reg_read32(hcd->regs, reg); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 350 | 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 Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 362 | static int ehci_reset(struct usb_hcd *hcd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 363 | { |
| 364 | int retval; |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 365 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 366 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 367 | u32 command = reg_read32(hcd->regs, HC_USBCMD); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 368 | |
| 369 | command |= CMD_RESET; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 370 | reg_write32(hcd->regs, HC_USBCMD, command); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 371 | hcd->state = HC_STATE_HALT; |
| 372 | priv->next_statechange = jiffies; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 373 | retval = handshake(hcd, HC_USBCMD, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 374 | CMD_RESET, 0, 250 * 1000); |
| 375 | return retval; |
| 376 | } |
| 377 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 378 | static struct isp1760_qh *qh_alloc(gfp_t flags) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 379 | { |
| 380 | struct isp1760_qh *qh; |
| 381 | |
| 382 | qh = kmem_cache_zalloc(qh_cachep, flags); |
| 383 | if (!qh) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 384 | return NULL; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 385 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 386 | INIT_LIST_HEAD(&qh->qh_list); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 387 | INIT_LIST_HEAD(&qh->qtd_list); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 388 | qh->slot = -1; |
| 389 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 390 | return qh; |
| 391 | } |
| 392 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 393 | static 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 399 | |
| 400 | /* one-time init, only for memory state */ |
| 401 | static 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 Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 408 | INIT_LIST_HEAD(&priv->interruptqhs); |
| 409 | INIT_LIST_HEAD(&priv->controlqhs); |
| 410 | INIT_LIST_HEAD(&priv->bulkqhs); |
| 411 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 412 | /* |
| 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 Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 419 | hcc_params = reg_read32(hcd->regs, HC_HCCPARAMS); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 420 | /* 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 | |
| 429 | static int isp1760_hc_setup(struct usb_hcd *hcd) |
| 430 | { |
| 431 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 432 | int result; |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 433 | 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 Hennerich | 9da69c6 | 2009-07-15 23:22:54 -0400 | [diff] [blame] | 446 | 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 Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 450 | |
| 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 Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 456 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode); |
| 457 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 458 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 459 | reg_write32(hcd->regs, HC_SCRATCH_REG, 0xdeadbabe); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 460 | /* Change bus pattern */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 461 | scratch = reg_read32(hcd->regs, HC_CHIP_ID_REG); |
| 462 | scratch = reg_read32(hcd->regs, HC_SCRATCH_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 463 | if (scratch != 0xdeadbabe) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 464 | dev_err(hcd->self.controller, "Scratch test failed.\n"); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 465 | return -ENODEV; |
| 466 | } |
| 467 | |
| 468 | /* pre reset */ |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 469 | 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 473 | |
| 474 | /* reset */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 475 | reg_write32(hcd->regs, HC_RESET_REG, SW_RESET_RESET_ALL); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 476 | mdelay(100); |
| 477 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 478 | reg_write32(hcd->regs, HC_RESET_REG, SW_RESET_RESET_HC); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 479 | mdelay(100); |
| 480 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 481 | result = ehci_reset(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 482 | if (result) |
| 483 | return result; |
| 484 | |
| 485 | /* Step 11 passed */ |
| 486 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 487 | dev_info(hcd->self.controller, "bus width: %d, oc: %s\n", |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 488 | (priv->devflags & ISP1760_FLAG_BUS_WIDTH_16) ? |
| 489 | 16 : 32, (priv->devflags & ISP1760_FLAG_ANALOG_OC) ? |
| 490 | "analog" : "digital"); |
| 491 | |
| 492 | /* ATL reset */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 493 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode | ALL_ATX_RESET); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 494 | mdelay(10); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 495 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 496 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 497 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, INTERRUPT_ENABLE_MASK); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 498 | |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 499 | /* |
| 500 | * PORT 1 Control register of the ISP1760 is the OTG control |
Thomas Hommel | 42c6539 | 2008-12-18 10:31:40 +0100 | [diff] [blame] | 501 | * 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 Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 504 | */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 505 | reg_write32(hcd->regs, HC_PORT1_CTRL, PORT1_POWER | PORT1_INIT2); |
Thomas Hommel | 42c6539 | 2008-12-18 10:31:40 +0100 | [diff] [blame] | 506 | mdelay(10); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 507 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 508 | priv->hcs_params = reg_read32(hcd->regs, HC_HCSPARAMS); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 509 | |
| 510 | return priv_init(hcd); |
| 511 | } |
| 512 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 513 | static u32 base_to_chip(u32 base) |
| 514 | { |
| 515 | return ((base - 0x400) >> 3); |
| 516 | } |
| 517 | |
Arvid Brodin | 7adc14b1 | 2011-02-26 22:08:47 +0100 | [diff] [blame] | 518 | static 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 Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 530 | /* 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 | |
| 538 | static void create_ptd_atl(struct isp1760_qh *qh, |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 539 | struct isp1760_qtd *qtd, struct ptd *ptd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 540 | { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 541 | u32 maxpacket; |
| 542 | u32 multi; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 543 | u32 rl = RL_COUNTER; |
| 544 | u32 nak = NAK_COUNTER; |
| 545 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 546 | memset(ptd, 0, sizeof(*ptd)); |
| 547 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 548 | /* according to 3.6.2, max packet len can not be > 0x400 */ |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 549 | maxpacket = usb_maxpacket(qtd->urb->dev, qtd->urb->pipe, |
| 550 | usb_pipeout(qtd->urb->pipe)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 551 | multi = 1 + ((maxpacket >> 11) & 0x3); |
| 552 | maxpacket &= 0x7ff; |
| 553 | |
| 554 | /* DW0 */ |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 555 | 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 559 | |
| 560 | /* DW1 */ |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 561 | ptd->dw1 = usb_pipeendpoint(qtd->urb->pipe) >> 1; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 562 | ptd->dw1 |= TO_DW1_DEVICE_ADDR(usb_pipedevice(qtd->urb->pipe)); |
| 563 | ptd->dw1 |= TO_DW1_PID_TOKEN(qtd->packet_type); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 564 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 565 | if (usb_pipebulk(qtd->urb->pipe)) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 566 | ptd->dw1 |= DW1_TRANS_BULK; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 567 | else if (usb_pipeint(qtd->urb->pipe)) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 568 | ptd->dw1 |= DW1_TRANS_INT; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 569 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 570 | if (qtd->urb->dev->speed != USB_SPEED_HIGH) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 571 | /* split transaction */ |
| 572 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 573 | ptd->dw1 |= DW1_TRANS_SPLIT; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 574 | if (qtd->urb->dev->speed == USB_SPEED_LOW) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 575 | ptd->dw1 |= DW1_SE_USB_LOSPEED; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 576 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 577 | ptd->dw1 |= TO_DW1_PORT_NUM(qtd->urb->dev->ttport); |
| 578 | ptd->dw1 |= TO_DW1_HUB_NUM(qtd->urb->dev->tt->hub->devnum); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 579 | |
| 580 | /* SE bit for Split INT transfers */ |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 581 | if (usb_pipeint(qtd->urb->pipe) && |
| 582 | (qtd->urb->dev->speed == USB_SPEED_LOW)) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 583 | ptd->dw1 |= 2 << 16; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 584 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 585 | rl = 0; |
| 586 | nak = 0; |
| 587 | } else { |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 588 | ptd->dw0 |= TO_DW0_MULTI(multi); |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 589 | if (usb_pipecontrol(qtd->urb->pipe) || |
| 590 | usb_pipebulk(qtd->urb->pipe)) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 591 | ptd->dw3 |= TO_DW3_PING(qh->ping); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 592 | } |
| 593 | /* DW2 */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 594 | ptd->dw2 = 0; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 595 | ptd->dw2 |= TO_DW2_DATA_START_ADDR(base_to_chip(qtd->payload_addr)); |
| 596 | ptd->dw2 |= TO_DW2_RL(rl); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 597 | |
| 598 | /* DW3 */ |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 599 | ptd->dw3 |= TO_DW3_NAKCOUNT(nak); |
| 600 | ptd->dw3 |= TO_DW3_DATA_TOGGLE(qh->toggle); |
Arvid Brodin | 7adc14b1 | 2011-02-26 22:08:47 +0100 | [diff] [blame] | 601 | if (usb_pipecontrol(qtd->urb->pipe)) { |
| 602 | if (qtd->data_buffer == qtd->urb->setup_packet) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 603 | ptd->dw3 &= ~TO_DW3_DATA_TOGGLE(1); |
Arvid Brodin | 7adc14b1 | 2011-02-26 22:08:47 +0100 | [diff] [blame] | 604 | else if (last_qtd_of_urb(qtd, qh)) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 605 | ptd->dw3 |= TO_DW3_DATA_TOGGLE(1); |
Arvid Brodin | 7adc14b1 | 2011-02-26 22:08:47 +0100 | [diff] [blame] | 606 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 607 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 608 | ptd->dw3 |= DW3_ACTIVE_BIT; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 609 | /* Cerr */ |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 610 | ptd->dw3 |= TO_DW3_CERR(ERR_COUNTER); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 611 | } |
| 612 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 613 | static void transform_add_int(struct isp1760_qh *qh, |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 614 | struct isp1760_qtd *qtd, struct ptd *ptd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 615 | { |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 616 | u32 usof; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 617 | u32 period; |
| 618 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 619 | /* |
| 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 627 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 628 | 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 631 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 632 | 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 639 | else |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 640 | usof = 0xff; /* All bits set => interval 1/8 ms */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 641 | } else { |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 642 | /* 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 646 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 647 | /* |
| 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 656 | } |
| 657 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 658 | 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 Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 661 | ptd->dw2 |= period; |
| 662 | ptd->dw4 = usof; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 663 | } |
| 664 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 665 | static void create_ptd_int(struct isp1760_qh *qh, |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 666 | struct isp1760_qtd *qtd, struct ptd *ptd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 667 | { |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 668 | create_ptd_atl(qh, qtd, ptd); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 669 | transform_add_int(qh, qtd, ptd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 670 | } |
| 671 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 672 | static void isp1760_urb_done(struct usb_hcd *hcd, struct urb *urb) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 673 | __releases(priv->lock) |
| 674 | __acquires(priv->lock) |
| 675 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 676 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 677 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 678 | if (!urb->unlinked) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 679 | if (urb->status == -EINPROGRESS) |
| 680 | urb->status = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 681 | } |
| 682 | |
Catalin Marinas | db8516f | 2010-02-02 15:31:02 +0000 | [diff] [blame] | 683 | 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 691 | /* complete() can reenter this HCD */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 692 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 693 | spin_unlock(&priv->lock); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 694 | usb_hcd_giveback_urb(hcd, urb, urb->status); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 695 | spin_lock(&priv->lock); |
| 696 | } |
| 697 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 698 | static struct isp1760_qtd *qtd_alloc(gfp_t flags, struct urb *urb, |
| 699 | u8 packet_type) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 700 | { |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 701 | 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 Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 710 | qtd->status = QTD_ENQUEUED; |
| 711 | qtd->actual_length = 0; |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 712 | |
| 713 | return qtd; |
| 714 | } |
| 715 | |
| 716 | static void qtd_free(struct isp1760_qtd *qtd) |
| 717 | { |
| 718 | WARN_ON(qtd->payload_addr); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 719 | kmem_cache_free(qtd_cachep, qtd); |
| 720 | } |
| 721 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 722 | static 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 725 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 726 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 727 | int skip_map; |
| 728 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 729 | 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 Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 734 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 735 | slots[slot].qtd = qtd; |
| 736 | slots[slot].qh = qh; |
| 737 | qh->slot = slot; |
| 738 | qtd->status = QTD_XFER_STARTED; /* Set this before writing ptd, since |
| 739 | interrupt routine may preempt and expects this value. */ |
Arvid Brodin | 6d50c60 | 2011-08-21 08:29:26 +0200 | [diff] [blame^] | 740 | slots[slot].timestamp = jiffies; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 741 | ptd_write(hcd->regs, ptd_offset, slot, ptd); |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 742 | |
| 743 | /* Make sure done map has not triggered from some unlinked transfer */ |
| 744 | if (ptd_offset == ATL_PTD_OFFSET) { |
| 745 | priv->atl_done_map |= reg_read32(hcd->regs, |
| 746 | HC_ATL_PTD_DONEMAP_REG); |
| 747 | priv->atl_done_map &= ~(1 << qh->slot); |
| 748 | |
| 749 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
| 750 | skip_map &= ~(1 << qh->slot); |
| 751 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map); |
| 752 | } else { |
| 753 | priv->int_done_map |= reg_read32(hcd->regs, |
| 754 | HC_INT_PTD_DONEMAP_REG); |
| 755 | priv->int_done_map &= ~(1 << qh->slot); |
| 756 | |
| 757 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
| 758 | skip_map &= ~(1 << qh->slot); |
| 759 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map); |
| 760 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 761 | } |
| 762 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 763 | static int is_short_bulk(struct isp1760_qtd *qtd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 764 | { |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 765 | return (usb_pipebulk(qtd->urb->pipe) && |
| 766 | (qtd->actual_length < qtd->length)); |
| 767 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 768 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 769 | static void collect_qtds(struct usb_hcd *hcd, struct isp1760_qh *qh, |
| 770 | struct list_head *urb_list) |
| 771 | { |
| 772 | int last_qtd; |
| 773 | struct isp1760_qtd *qtd, *qtd_next; |
| 774 | struct urb_listitem *urb_listitem; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 775 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 776 | list_for_each_entry_safe(qtd, qtd_next, &qh->qtd_list, qtd_list) { |
| 777 | if (qtd->status < QTD_XFER_COMPLETE) |
| 778 | break; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 779 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 780 | if (list_is_last(&qtd->qtd_list, &qh->qtd_list)) |
| 781 | last_qtd = 1; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 782 | else |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 783 | last_qtd = qtd->urb != qtd_next->urb; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 784 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 785 | if ((!last_qtd) && (qtd->status == QTD_RETIRE)) |
| 786 | qtd_next->status = QTD_RETIRE; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 787 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 788 | if (qtd->status == QTD_XFER_COMPLETE) { |
| 789 | if (qtd->actual_length) { |
| 790 | switch (qtd->packet_type) { |
| 791 | case IN_PID: |
| 792 | mem_reads8(hcd->regs, qtd->payload_addr, |
| 793 | qtd->data_buffer, |
| 794 | qtd->actual_length); |
| 795 | /* Fall through (?) */ |
| 796 | case OUT_PID: |
| 797 | qtd->urb->actual_length += |
| 798 | qtd->actual_length; |
| 799 | /* Fall through ... */ |
| 800 | case SETUP_PID: |
| 801 | break; |
| 802 | } |
| 803 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 804 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 805 | if (is_short_bulk(qtd)) { |
| 806 | if (qtd->urb->transfer_flags & URB_SHORT_NOT_OK) |
| 807 | qtd->urb->status = -EREMOTEIO; |
| 808 | if (!last_qtd) |
| 809 | qtd_next->status = QTD_RETIRE; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 810 | } |
| 811 | } |
| 812 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 813 | if (qtd->payload_addr) |
| 814 | free_mem(hcd, qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 815 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 816 | if (last_qtd) { |
| 817 | if ((qtd->status == QTD_RETIRE) && |
| 818 | (qtd->urb->status == -EINPROGRESS)) |
| 819 | qtd->urb->status = -EPIPE; |
| 820 | /* Defer calling of urb_done() since it releases lock */ |
| 821 | urb_listitem = kmem_cache_zalloc(urb_listitem_cachep, |
| 822 | GFP_ATOMIC); |
| 823 | if (unlikely(!urb_listitem)) |
| 824 | break; |
| 825 | urb_listitem->urb = qtd->urb; |
| 826 | list_add_tail(&urb_listitem->urb_list, urb_list); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 827 | } |
| 828 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 829 | list_del(&qtd->qtd_list); |
| 830 | qtd_free(qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 831 | } |
| 832 | } |
| 833 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 834 | #define ENQUEUE_DEPTH 2 |
| 835 | static void enqueue_qtds(struct usb_hcd *hcd, struct isp1760_qh *qh) |
| 836 | { |
| 837 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 838 | int ptd_offset; |
| 839 | struct slotinfo *slots; |
| 840 | int curr_slot, free_slot; |
| 841 | int n; |
| 842 | struct ptd ptd; |
| 843 | struct isp1760_qtd *qtd; |
| 844 | |
| 845 | if (unlikely(list_empty(&qh->qtd_list))) { |
| 846 | WARN_ON(1); |
| 847 | return; |
| 848 | } |
| 849 | |
| 850 | if (usb_pipeint(list_entry(qh->qtd_list.next, struct isp1760_qtd, |
| 851 | qtd_list)->urb->pipe)) { |
| 852 | ptd_offset = INT_PTD_OFFSET; |
| 853 | slots = priv->int_slots; |
| 854 | } else { |
| 855 | ptd_offset = ATL_PTD_OFFSET; |
| 856 | slots = priv->atl_slots; |
| 857 | } |
| 858 | |
| 859 | free_slot = -1; |
| 860 | for (curr_slot = 0; curr_slot < 32; curr_slot++) { |
| 861 | if ((free_slot == -1) && (slots[curr_slot].qtd == NULL)) |
| 862 | free_slot = curr_slot; |
| 863 | if (slots[curr_slot].qh == qh) |
| 864 | break; |
| 865 | } |
| 866 | |
| 867 | n = 0; |
| 868 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list) { |
| 869 | if (qtd->status == QTD_ENQUEUED) { |
| 870 | WARN_ON(qtd->payload_addr); |
| 871 | alloc_mem(hcd, qtd); |
| 872 | if ((qtd->length) && (!qtd->payload_addr)) |
| 873 | break; |
| 874 | |
| 875 | if ((qtd->length) && |
| 876 | ((qtd->packet_type == SETUP_PID) || |
| 877 | (qtd->packet_type == OUT_PID))) { |
| 878 | mem_writes8(hcd->regs, qtd->payload_addr, |
| 879 | qtd->data_buffer, qtd->length); |
| 880 | } |
| 881 | |
| 882 | qtd->status = QTD_PAYLOAD_ALLOC; |
| 883 | } |
| 884 | |
| 885 | if (qtd->status == QTD_PAYLOAD_ALLOC) { |
| 886 | /* |
| 887 | if ((curr_slot > 31) && (free_slot == -1)) |
| 888 | dev_dbg(hcd->self.controller, "%s: No slot " |
| 889 | "available for transfer\n", __func__); |
| 890 | */ |
| 891 | /* Start xfer for this endpoint if not already done */ |
| 892 | if ((curr_slot > 31) && (free_slot > -1)) { |
| 893 | if (usb_pipeint(qtd->urb->pipe)) |
| 894 | create_ptd_int(qh, qtd, &ptd); |
| 895 | else |
| 896 | create_ptd_atl(qh, qtd, &ptd); |
| 897 | |
| 898 | start_bus_transfer(hcd, ptd_offset, free_slot, |
| 899 | slots, qtd, qh, &ptd); |
| 900 | curr_slot = free_slot; |
| 901 | } |
| 902 | |
| 903 | n++; |
| 904 | if (n >= ENQUEUE_DEPTH) |
| 905 | break; |
| 906 | } |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | void schedule_ptds(struct usb_hcd *hcd) |
| 911 | { |
| 912 | struct isp1760_hcd *priv; |
| 913 | struct isp1760_qh *qh, *qh_next; |
| 914 | struct list_head *ep_queue; |
| 915 | struct usb_host_endpoint *ep; |
| 916 | LIST_HEAD(urb_list); |
| 917 | struct urb_listitem *urb_listitem, *urb_listitem_next; |
| 918 | |
| 919 | if (!hcd) { |
| 920 | WARN_ON(1); |
| 921 | return; |
| 922 | } |
| 923 | |
| 924 | priv = hcd_to_priv(hcd); |
| 925 | |
| 926 | /* |
| 927 | * check finished/retired xfers, transfer payloads, call urb_done() |
| 928 | */ |
| 929 | ep_queue = &priv->interruptqhs; |
| 930 | while (ep_queue) { |
| 931 | list_for_each_entry_safe(qh, qh_next, ep_queue, qh_list) { |
| 932 | ep = list_entry(qh->qtd_list.next, struct isp1760_qtd, |
| 933 | qtd_list)->urb->ep; |
| 934 | collect_qtds(hcd, qh, &urb_list); |
| 935 | if (list_empty(&qh->qtd_list)) { |
| 936 | list_del(&qh->qh_list); |
| 937 | if (ep->hcpriv == NULL) { |
| 938 | /* Endpoint has been disabled, so we |
| 939 | can free the associated queue head. */ |
| 940 | qh_free(qh); |
| 941 | } |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | if (ep_queue == &priv->interruptqhs) |
| 946 | ep_queue = &priv->controlqhs; |
| 947 | else if (ep_queue == &priv->controlqhs) |
| 948 | ep_queue = &priv->bulkqhs; |
| 949 | else |
| 950 | ep_queue = NULL; |
| 951 | } |
| 952 | |
| 953 | list_for_each_entry_safe(urb_listitem, urb_listitem_next, &urb_list, |
| 954 | urb_list) { |
| 955 | isp1760_urb_done(hcd, urb_listitem->urb); |
| 956 | kmem_cache_free(urb_listitem_cachep, urb_listitem); |
| 957 | } |
| 958 | |
| 959 | /* |
| 960 | * Schedule packets for transfer. |
| 961 | * |
| 962 | * According to USB2.0 specification: |
| 963 | * |
| 964 | * 1st prio: interrupt xfers, up to 80 % of bandwidth |
| 965 | * 2nd prio: control xfers |
| 966 | * 3rd prio: bulk xfers |
| 967 | * |
| 968 | * ... but let's use a simpler scheme here (mostly because ISP1761 doc |
| 969 | * is very unclear on how to prioritize traffic): |
| 970 | * |
| 971 | * 1) Enqueue any queued control transfers, as long as payload chip mem |
| 972 | * and PTD ATL slots are available. |
| 973 | * 2) Enqueue any queued INT transfers, as long as payload chip mem |
| 974 | * and PTD INT slots are available. |
| 975 | * 3) Enqueue any queued bulk transfers, as long as payload chip mem |
| 976 | * and PTD ATL slots are available. |
| 977 | * |
| 978 | * Use double buffering (ENQUEUE_DEPTH==2) as a compromise between |
| 979 | * conservation of chip mem and performance. |
| 980 | * |
| 981 | * I'm sure this scheme could be improved upon! |
| 982 | */ |
| 983 | ep_queue = &priv->controlqhs; |
| 984 | while (ep_queue) { |
| 985 | list_for_each_entry_safe(qh, qh_next, ep_queue, qh_list) |
| 986 | enqueue_qtds(hcd, qh); |
| 987 | |
| 988 | if (ep_queue == &priv->controlqhs) |
| 989 | ep_queue = &priv->interruptqhs; |
| 990 | else if (ep_queue == &priv->interruptqhs) |
| 991 | ep_queue = &priv->bulkqhs; |
| 992 | else |
| 993 | ep_queue = NULL; |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | #define PTD_STATE_QTD_DONE 1 |
| 998 | #define PTD_STATE_QTD_RELOAD 2 |
| 999 | #define PTD_STATE_URB_RETIRE 3 |
| 1000 | |
| 1001 | static int check_int_transfer(struct usb_hcd *hcd, struct ptd *ptd, |
| 1002 | struct urb *urb) |
| 1003 | { |
| 1004 | __dw dw4; |
| 1005 | int i; |
| 1006 | |
| 1007 | dw4 = ptd->dw4; |
| 1008 | dw4 >>= 8; |
| 1009 | |
| 1010 | /* FIXME: ISP1761 datasheet does not say what to do with these. Do we |
| 1011 | need to handle these errors? Is it done in hardware? */ |
| 1012 | |
| 1013 | if (ptd->dw3 & DW3_HALT_BIT) { |
| 1014 | |
| 1015 | urb->status = -EPROTO; /* Default unknown error */ |
| 1016 | |
| 1017 | for (i = 0; i < 8; i++) { |
| 1018 | switch (dw4 & 0x7) { |
| 1019 | case INT_UNDERRUN: |
| 1020 | dev_dbg(hcd->self.controller, "%s: underrun " |
| 1021 | "during uFrame %d\n", |
| 1022 | __func__, i); |
| 1023 | urb->status = -ECOMM; /* Could not write data */ |
| 1024 | break; |
| 1025 | case INT_EXACT: |
| 1026 | dev_dbg(hcd->self.controller, "%s: transaction " |
| 1027 | "error during uFrame %d\n", |
| 1028 | __func__, i); |
| 1029 | urb->status = -EPROTO; /* timeout, bad CRC, PID |
| 1030 | error etc. */ |
| 1031 | break; |
| 1032 | case INT_BABBLE: |
| 1033 | dev_dbg(hcd->self.controller, "%s: babble " |
| 1034 | "error during uFrame %d\n", |
| 1035 | __func__, i); |
| 1036 | urb->status = -EOVERFLOW; |
| 1037 | break; |
| 1038 | } |
| 1039 | dw4 >>= 3; |
| 1040 | } |
| 1041 | |
| 1042 | return PTD_STATE_URB_RETIRE; |
| 1043 | } |
| 1044 | |
| 1045 | return PTD_STATE_QTD_DONE; |
| 1046 | } |
| 1047 | |
| 1048 | static int check_atl_transfer(struct usb_hcd *hcd, struct ptd *ptd, |
| 1049 | struct urb *urb) |
| 1050 | { |
| 1051 | WARN_ON(!ptd); |
| 1052 | if (ptd->dw3 & DW3_HALT_BIT) { |
| 1053 | if (ptd->dw3 & DW3_BABBLE_BIT) |
| 1054 | urb->status = -EOVERFLOW; |
| 1055 | else if (FROM_DW3_CERR(ptd->dw3)) |
| 1056 | urb->status = -EPIPE; /* Stall */ |
| 1057 | else if (ptd->dw3 & DW3_ERROR_BIT) |
| 1058 | urb->status = -EPROTO; /* XactErr */ |
| 1059 | else |
| 1060 | urb->status = -EPROTO; /* Unknown */ |
| 1061 | /* |
| 1062 | dev_dbg(hcd->self.controller, "%s: ptd error:\n" |
| 1063 | " dw0: %08x dw1: %08x dw2: %08x dw3: %08x\n" |
| 1064 | " dw4: %08x dw5: %08x dw6: %08x dw7: %08x\n", |
| 1065 | __func__, |
| 1066 | ptd->dw0, ptd->dw1, ptd->dw2, ptd->dw3, |
| 1067 | ptd->dw4, ptd->dw5, ptd->dw6, ptd->dw7); |
| 1068 | */ |
| 1069 | return PTD_STATE_URB_RETIRE; |
| 1070 | } |
| 1071 | |
| 1072 | if ((ptd->dw3 & DW3_ERROR_BIT) && (ptd->dw3 & DW3_ACTIVE_BIT)) { |
| 1073 | /* Transfer Error, *but* active and no HALT -> reload */ |
| 1074 | dev_dbg(hcd->self.controller, "PID error; reloading ptd\n"); |
| 1075 | return PTD_STATE_QTD_RELOAD; |
| 1076 | } |
| 1077 | |
| 1078 | if (!FROM_DW3_NAKCOUNT(ptd->dw3) && (ptd->dw3 & DW3_ACTIVE_BIT)) { |
| 1079 | /* |
| 1080 | * NAKs are handled in HW by the chip. Usually if the |
| 1081 | * device is not able to send data fast enough. |
| 1082 | * This happens mostly on slower hardware. |
| 1083 | */ |
| 1084 | return PTD_STATE_QTD_RELOAD; |
| 1085 | } |
| 1086 | |
| 1087 | return PTD_STATE_QTD_DONE; |
| 1088 | } |
| 1089 | |
Arvid Brodin | 6d50c60 | 2011-08-21 08:29:26 +0200 | [diff] [blame^] | 1090 | static void handle_done_ptds(struct usb_hcd *hcd) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1091 | { |
| 1092 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1093 | struct ptd ptd; |
| 1094 | struct isp1760_qh *qh; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1095 | int slot; |
| 1096 | int state; |
| 1097 | struct slotinfo *slots; |
| 1098 | u32 ptd_offset; |
| 1099 | struct isp1760_qtd *qtd; |
| 1100 | int modified; |
Arvid Brodin | 6d50c60 | 2011-08-21 08:29:26 +0200 | [diff] [blame^] | 1101 | int skip_map; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1102 | |
Arvid Brodin | 6d50c60 | 2011-08-21 08:29:26 +0200 | [diff] [blame^] | 1103 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
| 1104 | priv->int_done_map &= ~skip_map; |
| 1105 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
| 1106 | priv->atl_done_map &= ~skip_map; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1107 | |
Arvid Brodin | 6d50c60 | 2011-08-21 08:29:26 +0200 | [diff] [blame^] | 1108 | modified = priv->int_done_map || priv->atl_done_map; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1109 | |
| 1110 | while (priv->int_done_map || priv->atl_done_map) { |
| 1111 | if (priv->int_done_map) { |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1112 | /* INT ptd */ |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1113 | slot = __ffs(priv->int_done_map); |
| 1114 | priv->int_done_map &= ~(1 << slot); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1115 | slots = priv->int_slots; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1116 | /* This should not trigger, and could be removed if |
| 1117 | noone have any problems with it triggering: */ |
| 1118 | if (!slots[slot].qh) { |
| 1119 | WARN_ON(1); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1120 | continue; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1121 | } |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1122 | ptd_offset = INT_PTD_OFFSET; |
| 1123 | ptd_read(hcd->regs, INT_PTD_OFFSET, slot, &ptd); |
| 1124 | state = check_int_transfer(hcd, &ptd, |
| 1125 | slots[slot].qtd->urb); |
| 1126 | } else { |
| 1127 | /* ATL ptd */ |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1128 | slot = __ffs(priv->atl_done_map); |
| 1129 | priv->atl_done_map &= ~(1 << slot); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1130 | slots = priv->atl_slots; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1131 | /* This should not trigger, and could be removed if |
| 1132 | noone have any problems with it triggering: */ |
| 1133 | if (!slots[slot].qh) { |
| 1134 | WARN_ON(1); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1135 | continue; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1136 | } |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1137 | ptd_offset = ATL_PTD_OFFSET; |
| 1138 | ptd_read(hcd->regs, ATL_PTD_OFFSET, slot, &ptd); |
| 1139 | state = check_atl_transfer(hcd, &ptd, |
| 1140 | slots[slot].qtd->urb); |
| 1141 | } |
| 1142 | |
| 1143 | qtd = slots[slot].qtd; |
| 1144 | slots[slot].qtd = NULL; |
| 1145 | qh = slots[slot].qh; |
| 1146 | slots[slot].qh = NULL; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1147 | qh->slot = -1; |
| 1148 | |
| 1149 | WARN_ON(qtd->status != QTD_XFER_STARTED); |
| 1150 | |
| 1151 | switch (state) { |
| 1152 | case PTD_STATE_QTD_DONE: |
| 1153 | if ((usb_pipeint(qtd->urb->pipe)) && |
| 1154 | (qtd->urb->dev->speed != USB_SPEED_HIGH)) |
| 1155 | qtd->actual_length = |
| 1156 | FROM_DW3_SCS_NRBYTESTRANSFERRED(ptd.dw3); |
| 1157 | else |
| 1158 | qtd->actual_length = |
| 1159 | FROM_DW3_NRBYTESTRANSFERRED(ptd.dw3); |
| 1160 | |
| 1161 | qtd->status = QTD_XFER_COMPLETE; |
| 1162 | if (list_is_last(&qtd->qtd_list, &qh->qtd_list) || |
| 1163 | is_short_bulk(qtd)) |
| 1164 | qtd = NULL; |
| 1165 | else |
| 1166 | qtd = list_entry(qtd->qtd_list.next, |
| 1167 | typeof(*qtd), qtd_list); |
| 1168 | |
| 1169 | qh->toggle = FROM_DW3_DATA_TOGGLE(ptd.dw3); |
| 1170 | qh->ping = FROM_DW3_PING(ptd.dw3); |
| 1171 | break; |
| 1172 | |
| 1173 | case PTD_STATE_QTD_RELOAD: /* QTD_RETRY, for atls only */ |
| 1174 | qtd->status = QTD_PAYLOAD_ALLOC; |
| 1175 | ptd.dw0 |= DW0_VALID_BIT; |
| 1176 | /* RL counter = ERR counter */ |
| 1177 | ptd.dw3 &= ~TO_DW3_NAKCOUNT(0xf); |
| 1178 | ptd.dw3 |= TO_DW3_NAKCOUNT(FROM_DW2_RL(ptd.dw2)); |
| 1179 | ptd.dw3 &= ~TO_DW3_CERR(3); |
| 1180 | ptd.dw3 |= TO_DW3_CERR(ERR_COUNTER); |
| 1181 | qh->toggle = FROM_DW3_DATA_TOGGLE(ptd.dw3); |
| 1182 | qh->ping = FROM_DW3_PING(ptd.dw3); |
| 1183 | break; |
| 1184 | |
| 1185 | case PTD_STATE_URB_RETIRE: |
| 1186 | qtd->status = QTD_RETIRE; |
| 1187 | qtd = NULL; |
| 1188 | qh->toggle = 0; |
| 1189 | qh->ping = 0; |
| 1190 | break; |
| 1191 | |
| 1192 | default: |
| 1193 | WARN_ON(1); |
| 1194 | continue; |
| 1195 | } |
| 1196 | |
| 1197 | if (qtd && (qtd->status == QTD_PAYLOAD_ALLOC)) { |
| 1198 | if (slots == priv->int_slots) { |
| 1199 | if (state == PTD_STATE_QTD_RELOAD) |
| 1200 | dev_err(hcd->self.controller, |
| 1201 | "%s: PTD_STATE_QTD_RELOAD on " |
| 1202 | "interrupt packet\n", __func__); |
| 1203 | if (state != PTD_STATE_QTD_RELOAD) |
| 1204 | create_ptd_int(qh, qtd, &ptd); |
| 1205 | } else { |
| 1206 | if (state != PTD_STATE_QTD_RELOAD) |
| 1207 | create_ptd_atl(qh, qtd, &ptd); |
| 1208 | } |
| 1209 | |
| 1210 | start_bus_transfer(hcd, ptd_offset, slot, slots, qtd, |
| 1211 | qh, &ptd); |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | if (modified) |
| 1216 | schedule_ptds(hcd); |
Arvid Brodin | 6d50c60 | 2011-08-21 08:29:26 +0200 | [diff] [blame^] | 1217 | } |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1218 | |
Arvid Brodin | 6d50c60 | 2011-08-21 08:29:26 +0200 | [diff] [blame^] | 1219 | static irqreturn_t isp1760_irq(struct usb_hcd *hcd) |
| 1220 | { |
| 1221 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1222 | u32 imask; |
| 1223 | irqreturn_t irqret = IRQ_NONE; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1224 | |
Arvid Brodin | 6d50c60 | 2011-08-21 08:29:26 +0200 | [diff] [blame^] | 1225 | spin_lock(&priv->lock); |
| 1226 | |
| 1227 | if (!(hcd->state & HC_STATE_RUNNING)) |
| 1228 | goto leave; |
| 1229 | |
| 1230 | imask = reg_read32(hcd->regs, HC_INTERRUPT_REG); |
| 1231 | if (unlikely(!imask)) |
| 1232 | goto leave; |
| 1233 | reg_write32(hcd->regs, HC_INTERRUPT_REG, imask); /* Clear */ |
| 1234 | |
| 1235 | priv->int_done_map |= reg_read32(hcd->regs, HC_INT_PTD_DONEMAP_REG); |
| 1236 | priv->atl_done_map |= reg_read32(hcd->regs, HC_ATL_PTD_DONEMAP_REG); |
| 1237 | |
| 1238 | handle_done_ptds(hcd); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1239 | |
| 1240 | irqret = IRQ_HANDLED; |
| 1241 | leave: |
| 1242 | spin_unlock(&priv->lock); |
| 1243 | |
| 1244 | return irqret; |
| 1245 | } |
| 1246 | |
Arvid Brodin | 6d50c60 | 2011-08-21 08:29:26 +0200 | [diff] [blame^] | 1247 | /* |
| 1248 | * Workaround for problem described in chip errata 2: |
| 1249 | * |
| 1250 | * Sometimes interrupts are not generated when ATL (not INT?) completion occurs. |
| 1251 | * One solution suggested in the errata is to use SOF interrupts _instead_of_ |
| 1252 | * ATL done interrupts (the "instead of" might be important since it seems |
| 1253 | * enabling ATL interrupts also causes the chip to sometimes - rarely - "forget" |
| 1254 | * to set the PTD's done bit in addition to not generating an interrupt!). |
| 1255 | * |
| 1256 | * So if we use SOF + ATL interrupts, we sometimes get stale PTDs since their |
| 1257 | * done bit is not being set. This is bad - it blocks the endpoint until reboot. |
| 1258 | * |
| 1259 | * If we use SOF interrupts only, we get latency between ptd completion and the |
| 1260 | * actual handling. This is very noticeable in testusb runs which takes several |
| 1261 | * minutes longer without ATL interrupts. |
| 1262 | * |
| 1263 | * A better solution is to run the code below every SLOT_CHECK_PERIOD ms. If it |
| 1264 | * finds active ATL slots which are older than SLOT_TIMEOUT ms, it checks the |
| 1265 | * slot's ACTIVE and VALID bits. If these are not set, the ptd is considered |
| 1266 | * completed and its done map bit is set. |
| 1267 | * |
| 1268 | * The values of SLOT_TIMEOUT and SLOT_CHECK_PERIOD have been arbitrarily chosen |
| 1269 | * not to cause too much lag when this HW bug occurs, while still hopefully |
| 1270 | * ensuring that the check does not falsely trigger. |
| 1271 | */ |
| 1272 | #define SLOT_TIMEOUT 180 |
| 1273 | #define SLOT_CHECK_PERIOD 200 |
| 1274 | static struct timer_list errata2_timer; |
| 1275 | |
| 1276 | void errata2_function(unsigned long data) |
| 1277 | { |
| 1278 | struct usb_hcd *hcd = (struct usb_hcd *) data; |
| 1279 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1280 | int slot; |
| 1281 | struct ptd ptd; |
| 1282 | unsigned long spinflags; |
| 1283 | |
| 1284 | spin_lock_irqsave(&priv->lock, spinflags); |
| 1285 | |
| 1286 | for (slot = 0; slot < 32; slot++) |
| 1287 | if ((priv->atl_slots[slot].qh || priv->atl_slots[slot].qtd) && |
| 1288 | time_after(jiffies + SLOT_TIMEOUT * HZ / 1000, |
| 1289 | priv->atl_slots[slot].timestamp)) { |
| 1290 | ptd_read(hcd->regs, ATL_PTD_OFFSET, slot, &ptd); |
| 1291 | if (!FROM_DW0_VALID(ptd.dw0) && |
| 1292 | !FROM_DW3_ACTIVE(ptd.dw3)) |
| 1293 | priv->atl_done_map |= 1 << slot; |
| 1294 | } |
| 1295 | |
| 1296 | handle_done_ptds(hcd); |
| 1297 | |
| 1298 | spin_unlock_irqrestore(&priv->lock, spinflags); |
| 1299 | |
| 1300 | errata2_timer.expires = jiffies + SLOT_CHECK_PERIOD * HZ / 1000; |
| 1301 | add_timer(&errata2_timer); |
| 1302 | } |
| 1303 | |
Arvid Brodin | 0ba7905 | 2011-08-21 08:29:25 +0200 | [diff] [blame] | 1304 | static int isp1760_run(struct usb_hcd *hcd) |
| 1305 | { |
| 1306 | int retval; |
| 1307 | u32 temp; |
| 1308 | u32 command; |
| 1309 | u32 chipid; |
| 1310 | |
| 1311 | hcd->uses_new_polling = 1; |
| 1312 | |
| 1313 | hcd->state = HC_STATE_RUNNING; |
| 1314 | |
| 1315 | /* Set PTD interrupt AND & OR maps */ |
| 1316 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_AND_REG, 0); |
| 1317 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, 0xffffffff); |
| 1318 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_AND_REG, 0); |
| 1319 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, 0xffffffff); |
| 1320 | reg_write32(hcd->regs, HC_ISO_IRQ_MASK_AND_REG, 0); |
| 1321 | reg_write32(hcd->regs, HC_ISO_IRQ_MASK_OR_REG, 0xffffffff); |
| 1322 | /* step 23 passed */ |
| 1323 | |
| 1324 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); |
| 1325 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp | HW_GLOBAL_INTR_EN); |
| 1326 | |
| 1327 | command = reg_read32(hcd->regs, HC_USBCMD); |
| 1328 | command &= ~(CMD_LRESET|CMD_RESET); |
| 1329 | command |= CMD_RUN; |
| 1330 | reg_write32(hcd->regs, HC_USBCMD, command); |
| 1331 | |
| 1332 | retval = handshake(hcd, HC_USBCMD, CMD_RUN, CMD_RUN, 250 * 1000); |
| 1333 | if (retval) |
| 1334 | return retval; |
| 1335 | |
| 1336 | /* |
| 1337 | * XXX |
| 1338 | * Spec says to write FLAG_CF as last config action, priv code grabs |
| 1339 | * the semaphore while doing so. |
| 1340 | */ |
| 1341 | down_write(&ehci_cf_port_reset_rwsem); |
| 1342 | reg_write32(hcd->regs, HC_CONFIGFLAG, FLAG_CF); |
| 1343 | |
| 1344 | retval = handshake(hcd, HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 250 * 1000); |
| 1345 | up_write(&ehci_cf_port_reset_rwsem); |
| 1346 | if (retval) |
| 1347 | return retval; |
| 1348 | |
Arvid Brodin | 6d50c60 | 2011-08-21 08:29:26 +0200 | [diff] [blame^] | 1349 | init_timer(&errata2_timer); |
| 1350 | errata2_timer.function = errata2_function; |
| 1351 | errata2_timer.data = (unsigned long) hcd; |
| 1352 | errata2_timer.expires = jiffies + SLOT_CHECK_PERIOD * HZ / 1000; |
| 1353 | add_timer(&errata2_timer); |
| 1354 | |
Arvid Brodin | 0ba7905 | 2011-08-21 08:29:25 +0200 | [diff] [blame] | 1355 | chipid = reg_read32(hcd->regs, HC_CHIP_ID_REG); |
| 1356 | dev_info(hcd->self.controller, "USB ISP %04x HW rev. %d started\n", |
| 1357 | chipid & 0xffff, chipid >> 16); |
| 1358 | |
| 1359 | /* PTD Register Init Part 2, Step 28 */ |
| 1360 | |
| 1361 | /* Setup registers controlling PTD checking */ |
| 1362 | reg_write32(hcd->regs, HC_ATL_PTD_LASTPTD_REG, 0x80000000); |
| 1363 | reg_write32(hcd->regs, HC_INT_PTD_LASTPTD_REG, 0x80000000); |
| 1364 | reg_write32(hcd->regs, HC_ISO_PTD_LASTPTD_REG, 0x00000001); |
| 1365 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, 0xffffffff); |
| 1366 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, 0xffffffff); |
| 1367 | reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, 0xffffffff); |
| 1368 | reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, |
| 1369 | ATL_BUF_FILL | INT_BUF_FILL); |
| 1370 | |
| 1371 | /* GRR this is run-once init(), being done every time the HC starts. |
| 1372 | * So long as they're part of class devices, we can't do it init() |
| 1373 | * since the class device isn't created that early. |
| 1374 | */ |
| 1375 | return 0; |
| 1376 | } |
| 1377 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1378 | static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1379 | { |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1380 | qtd->data_buffer = databuffer; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1381 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1382 | if (len > MAX_PAYLOAD_SIZE) |
| 1383 | len = MAX_PAYLOAD_SIZE; |
| 1384 | qtd->length = len; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1385 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1386 | return qtd->length; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1387 | } |
| 1388 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1389 | static void qtd_list_free(struct list_head *qtd_list) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1390 | { |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1391 | struct isp1760_qtd *qtd, *qtd_next; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1392 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1393 | list_for_each_entry_safe(qtd, qtd_next, qtd_list, qtd_list) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1394 | list_del(&qtd->qtd_list); |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1395 | qtd_free(qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1396 | } |
| 1397 | } |
| 1398 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1399 | /* |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1400 | * Packetize urb->transfer_buffer into list of packets of size wMaxPacketSize. |
| 1401 | * Also calculate the PID type (SETUP/IN/OUT) for each packet. |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1402 | */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1403 | #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff) |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1404 | static void packetize_urb(struct usb_hcd *hcd, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1405 | struct urb *urb, struct list_head *head, gfp_t flags) |
| 1406 | { |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1407 | struct isp1760_qtd *qtd; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1408 | void *buf; |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1409 | int len, maxpacketsize; |
| 1410 | u8 packet_type; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1411 | |
| 1412 | /* |
| 1413 | * URBs map to sequences of QTDs: one logical transaction |
| 1414 | */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1415 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1416 | if (!urb->transfer_buffer && urb->transfer_buffer_length) { |
| 1417 | /* XXX This looks like usb storage / SCSI bug */ |
| 1418 | dev_err(hcd->self.controller, |
| 1419 | "buf is null, dma is %08lx len is %d\n", |
| 1420 | (long unsigned)urb->transfer_dma, |
| 1421 | urb->transfer_buffer_length); |
| 1422 | WARN_ON(1); |
| 1423 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1424 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1425 | if (usb_pipein(urb->pipe)) |
| 1426 | packet_type = IN_PID; |
| 1427 | else |
| 1428 | packet_type = OUT_PID; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1429 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1430 | if (usb_pipecontrol(urb->pipe)) { |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1431 | qtd = qtd_alloc(flags, urb, SETUP_PID); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1432 | if (!qtd) |
| 1433 | goto cleanup; |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1434 | qtd_fill(qtd, urb->setup_packet, sizeof(struct usb_ctrlrequest)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1435 | list_add_tail(&qtd->qtd_list, head); |
| 1436 | |
| 1437 | /* for zero length DATA stages, STATUS is always IN */ |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1438 | if (urb->transfer_buffer_length == 0) |
| 1439 | packet_type = IN_PID; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1440 | } |
| 1441 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1442 | maxpacketsize = max_packet(usb_maxpacket(urb->dev, urb->pipe, |
| 1443 | usb_pipeout(urb->pipe))); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1444 | |
| 1445 | /* |
| 1446 | * buffer gets wrapped in one or more qtds; |
| 1447 | * last one may be "short" (including zero len) |
| 1448 | * and may serve as a control status ack |
| 1449 | */ |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1450 | buf = urb->transfer_buffer; |
| 1451 | len = urb->transfer_buffer_length; |
| 1452 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1453 | for (;;) { |
| 1454 | int this_qtd_len; |
| 1455 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1456 | qtd = qtd_alloc(flags, urb, packet_type); |
| 1457 | if (!qtd) |
| 1458 | goto cleanup; |
| 1459 | this_qtd_len = qtd_fill(qtd, buf, len); |
| 1460 | list_add_tail(&qtd->qtd_list, head); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1461 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1462 | len -= this_qtd_len; |
| 1463 | buf += this_qtd_len; |
| 1464 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1465 | if (len <= 0) |
| 1466 | break; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | /* |
| 1470 | * control requests may need a terminating data "status" ack; |
| 1471 | * bulk ones may need a terminating short packet (zero length). |
| 1472 | */ |
| 1473 | if (urb->transfer_buffer_length != 0) { |
| 1474 | int one_more = 0; |
| 1475 | |
| 1476 | if (usb_pipecontrol(urb->pipe)) { |
| 1477 | one_more = 1; |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1478 | if (packet_type == IN_PID) |
| 1479 | packet_type = OUT_PID; |
| 1480 | else |
| 1481 | packet_type = IN_PID; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1482 | } else if (usb_pipebulk(urb->pipe) |
| 1483 | && (urb->transfer_flags & URB_ZERO_PACKET) |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1484 | && !(urb->transfer_buffer_length % |
| 1485 | maxpacketsize)) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1486 | one_more = 1; |
| 1487 | } |
| 1488 | if (one_more) { |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1489 | qtd = qtd_alloc(flags, urb, packet_type); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1490 | if (!qtd) |
| 1491 | goto cleanup; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1492 | |
| 1493 | /* never any data in such packets */ |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1494 | qtd_fill(qtd, NULL, 0); |
| 1495 | list_add_tail(&qtd->qtd_list, head); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1496 | } |
| 1497 | } |
| 1498 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1499 | return; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1500 | |
| 1501 | cleanup: |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1502 | qtd_list_free(head); |
| 1503 | } |
| 1504 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1505 | static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, |
| 1506 | gfp_t mem_flags) |
| 1507 | { |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1508 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1509 | struct list_head *ep_queue; |
| 1510 | struct isp1760_qh *qh, *qhit; |
| 1511 | unsigned long spinflags; |
| 1512 | LIST_HEAD(new_qtds); |
| 1513 | int retval; |
| 1514 | int qh_in_queue; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1515 | |
| 1516 | switch (usb_pipetype(urb->pipe)) { |
| 1517 | case PIPE_CONTROL: |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1518 | ep_queue = &priv->controlqhs; |
| 1519 | break; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1520 | case PIPE_BULK: |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1521 | ep_queue = &priv->bulkqhs; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1522 | break; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1523 | case PIPE_INTERRUPT: |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1524 | if (urb->interval < 0) |
| 1525 | return -EINVAL; |
| 1526 | /* FIXME: Check bandwidth */ |
| 1527 | ep_queue = &priv->interruptqhs; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1528 | break; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1529 | case PIPE_ISOCHRONOUS: |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1530 | dev_err(hcd->self.controller, "%s: isochronous USB packets " |
| 1531 | "not yet supported\n", |
| 1532 | __func__); |
| 1533 | return -EPIPE; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1534 | default: |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1535 | dev_err(hcd->self.controller, "%s: unknown pipe type\n", |
| 1536 | __func__); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1537 | return -EPIPE; |
| 1538 | } |
| 1539 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1540 | if (usb_pipein(urb->pipe)) |
| 1541 | urb->actual_length = 0; |
| 1542 | |
| 1543 | packetize_urb(hcd, urb, &new_qtds, mem_flags); |
| 1544 | if (list_empty(&new_qtds)) |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1545 | return -ENOMEM; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1546 | urb->hcpriv = NULL; /* Used to signal unlink to interrupt handler */ |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1547 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1548 | retval = 0; |
| 1549 | spin_lock_irqsave(&priv->lock, spinflags); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1550 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1551 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { |
| 1552 | retval = -ESHUTDOWN; |
| 1553 | goto out; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1554 | } |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1555 | retval = usb_hcd_link_urb_to_ep(hcd, urb); |
| 1556 | if (retval) |
| 1557 | goto out; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1558 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1559 | qh = urb->ep->hcpriv; |
| 1560 | if (qh) { |
| 1561 | qh_in_queue = 0; |
| 1562 | list_for_each_entry(qhit, ep_queue, qh_list) { |
| 1563 | if (qhit == qh) { |
| 1564 | qh_in_queue = 1; |
Warren Free | 0afb20e | 2009-05-08 10:27:08 +0200 | [diff] [blame] | 1565 | break; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1566 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1567 | } |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1568 | if (!qh_in_queue) |
| 1569 | list_add_tail(&qh->qh_list, ep_queue); |
| 1570 | } else { |
| 1571 | qh = qh_alloc(GFP_ATOMIC); |
| 1572 | if (!qh) { |
| 1573 | retval = -ENOMEM; |
| 1574 | goto out; |
| 1575 | } |
| 1576 | list_add_tail(&qh->qh_list, ep_queue); |
| 1577 | urb->ep->hcpriv = qh; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1578 | } |
| 1579 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1580 | list_splice_tail(&new_qtds, &qh->qtd_list); |
| 1581 | schedule_ptds(hcd); |
| 1582 | |
| 1583 | out: |
| 1584 | spin_unlock_irqrestore(&priv->lock, spinflags); |
| 1585 | return retval; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1586 | } |
| 1587 | |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1588 | static void kill_transfer(struct usb_hcd *hcd, struct urb *urb, |
| 1589 | struct isp1760_qh *qh) |
| 1590 | { |
| 1591 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1592 | int skip_map; |
| 1593 | |
| 1594 | WARN_ON(qh->slot == -1); |
| 1595 | |
| 1596 | /* We need to forcefully reclaim the slot since some transfers never |
| 1597 | return, e.g. interrupt transfers and NAKed bulk transfers. */ |
Arvid Brodin | 8b1ab60 | 2011-06-17 18:45:37 +0200 | [diff] [blame] | 1598 | if (usb_pipecontrol(urb->pipe) || usb_pipebulk(urb->pipe)) { |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1599 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
| 1600 | skip_map |= (1 << qh->slot); |
| 1601 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map); |
| 1602 | priv->atl_slots[qh->slot].qh = NULL; |
| 1603 | priv->atl_slots[qh->slot].qtd = NULL; |
| 1604 | } else { |
| 1605 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
| 1606 | skip_map |= (1 << qh->slot); |
| 1607 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map); |
| 1608 | priv->int_slots[qh->slot].qh = NULL; |
| 1609 | priv->int_slots[qh->slot].qtd = NULL; |
| 1610 | } |
| 1611 | |
| 1612 | qh->slot = -1; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1613 | } |
| 1614 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1615 | static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, |
| 1616 | int status) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1617 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1618 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1619 | unsigned long spinflags; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1620 | struct isp1760_qh *qh; |
| 1621 | struct isp1760_qtd *qtd; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1622 | int retval = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1623 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1624 | spin_lock_irqsave(&priv->lock, spinflags); |
Arvid Brodin | 17d3e14 | 2011-07-20 03:13:46 +0200 | [diff] [blame] | 1625 | retval = usb_hcd_check_unlink_urb(hcd, urb, status); |
| 1626 | if (retval) |
| 1627 | goto out; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1628 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1629 | qh = urb->ep->hcpriv; |
| 1630 | if (!qh) { |
| 1631 | retval = -EINVAL; |
| 1632 | goto out; |
| 1633 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1634 | |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1635 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list) |
| 1636 | if (qtd->urb == urb) { |
| 1637 | if (qtd->status == QTD_XFER_STARTED) |
| 1638 | kill_transfer(hcd, urb, qh); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1639 | qtd->status = QTD_RETIRE; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1640 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1641 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1642 | urb->status = status; |
| 1643 | schedule_ptds(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1644 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1645 | out: |
| 1646 | spin_unlock_irqrestore(&priv->lock, spinflags); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1647 | return retval; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1648 | } |
| 1649 | |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1650 | static void isp1760_endpoint_disable(struct usb_hcd *hcd, |
| 1651 | struct usb_host_endpoint *ep) |
| 1652 | { |
| 1653 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1654 | unsigned long spinflags; |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1655 | struct isp1760_qh *qh; |
| 1656 | struct isp1760_qtd *qtd; |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1657 | |
| 1658 | spin_lock_irqsave(&priv->lock, spinflags); |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1659 | |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1660 | qh = ep->hcpriv; |
| 1661 | if (!qh) |
| 1662 | goto out; |
| 1663 | |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1664 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list) { |
| 1665 | if (qtd->status == QTD_XFER_STARTED) |
| 1666 | kill_transfer(hcd, qtd->urb, qh); |
| 1667 | qtd->status = QTD_RETIRE; |
| 1668 | qtd->urb->status = -ECONNRESET; |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1669 | } |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1670 | |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1671 | ep->hcpriv = NULL; |
| 1672 | /* Cannot free qh here since it will be parsed by schedule_ptds() */ |
| 1673 | |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1674 | schedule_ptds(hcd); |
| 1675 | |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1676 | out: |
| 1677 | spin_unlock_irqrestore(&priv->lock, spinflags); |
| 1678 | } |
| 1679 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1680 | static int isp1760_hub_status_data(struct usb_hcd *hcd, char *buf) |
| 1681 | { |
| 1682 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1683 | u32 temp, status = 0; |
| 1684 | u32 mask; |
| 1685 | int retval = 1; |
| 1686 | unsigned long flags; |
| 1687 | |
| 1688 | /* if !USB_SUSPEND, root hub timers won't get shut down ... */ |
| 1689 | if (!HC_IS_RUNNING(hcd->state)) |
| 1690 | return 0; |
| 1691 | |
| 1692 | /* init status to no-changes */ |
| 1693 | buf[0] = 0; |
| 1694 | mask = PORT_CSC; |
| 1695 | |
| 1696 | spin_lock_irqsave(&priv->lock, flags); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1697 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1698 | |
| 1699 | if (temp & PORT_OWNER) { |
| 1700 | if (temp & PORT_CSC) { |
| 1701 | temp &= ~PORT_CSC; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1702 | reg_write32(hcd->regs, HC_PORTSC1, temp); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1703 | goto done; |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | /* |
| 1708 | * Return status information even for ports with OWNER set. |
| 1709 | * Otherwise khubd wouldn't see the disconnect event when a |
| 1710 | * high-speed device is switched over to the companion |
| 1711 | * controller by the user. |
| 1712 | */ |
| 1713 | |
| 1714 | if ((temp & mask) != 0 |
| 1715 | || ((temp & PORT_RESUME) != 0 |
| 1716 | && time_after_eq(jiffies, |
| 1717 | priv->reset_done))) { |
| 1718 | buf [0] |= 1 << (0 + 1); |
| 1719 | status = STS_PCD; |
| 1720 | } |
| 1721 | /* FIXME autosuspend idle root hubs */ |
| 1722 | done: |
| 1723 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1724 | return status ? retval : 0; |
| 1725 | } |
| 1726 | |
| 1727 | static void isp1760_hub_descriptor(struct isp1760_hcd *priv, |
| 1728 | struct usb_hub_descriptor *desc) |
| 1729 | { |
| 1730 | int ports = HCS_N_PORTS(priv->hcs_params); |
| 1731 | u16 temp; |
| 1732 | |
| 1733 | desc->bDescriptorType = 0x29; |
| 1734 | /* priv 1.0, 2.3.9 says 20ms max */ |
| 1735 | desc->bPwrOn2PwrGood = 10; |
| 1736 | desc->bHubContrCurrent = 0; |
| 1737 | |
| 1738 | desc->bNbrPorts = ports; |
| 1739 | temp = 1 + (ports / 8); |
| 1740 | desc->bDescLength = 7 + 2 * temp; |
| 1741 | |
Sarah Sharp | da13051 | 2010-11-30 15:55:51 -0800 | [diff] [blame] | 1742 | /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */ |
John Youn | dbe79bb | 2001-09-17 00:00:00 -0700 | [diff] [blame] | 1743 | memset(&desc->u.hs.DeviceRemovable[0], 0, temp); |
| 1744 | memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1745 | |
| 1746 | /* per-port overcurrent reporting */ |
| 1747 | temp = 0x0008; |
| 1748 | if (HCS_PPC(priv->hcs_params)) |
| 1749 | /* per-port power control */ |
| 1750 | temp |= 0x0001; |
| 1751 | else |
| 1752 | /* no power switching */ |
| 1753 | temp |= 0x0002; |
| 1754 | desc->wHubCharacteristics = cpu_to_le16(temp); |
| 1755 | } |
| 1756 | |
| 1757 | #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) |
| 1758 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1759 | static int check_reset_complete(struct usb_hcd *hcd, int index, |
| 1760 | int port_status) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1761 | { |
| 1762 | if (!(port_status & PORT_CONNECT)) |
| 1763 | return port_status; |
| 1764 | |
| 1765 | /* if reset finished and it's still not enabled -- handoff */ |
| 1766 | if (!(port_status & PORT_PE)) { |
| 1767 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1768 | dev_info(hcd->self.controller, |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1769 | "port %d full speed --> companion\n", |
| 1770 | index + 1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1771 | |
| 1772 | port_status |= PORT_OWNER; |
| 1773 | port_status &= ~PORT_RWC_BITS; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1774 | reg_write32(hcd->regs, HC_PORTSC1, port_status); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1775 | |
| 1776 | } else |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1777 | dev_info(hcd->self.controller, "port %d high speed\n", |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1778 | index + 1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1779 | |
| 1780 | return port_status; |
| 1781 | } |
| 1782 | |
| 1783 | static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, |
| 1784 | u16 wValue, u16 wIndex, char *buf, u16 wLength) |
| 1785 | { |
| 1786 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1787 | int ports = HCS_N_PORTS(priv->hcs_params); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1788 | u32 temp, status; |
| 1789 | unsigned long flags; |
| 1790 | int retval = 0; |
| 1791 | unsigned selector; |
| 1792 | |
| 1793 | /* |
| 1794 | * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR. |
| 1795 | * HCS_INDICATOR may say we can change LEDs to off/amber/green. |
| 1796 | * (track current state ourselves) ... blink for diagnostics, |
| 1797 | * power, "this is the one", etc. EHCI spec supports this. |
| 1798 | */ |
| 1799 | |
| 1800 | spin_lock_irqsave(&priv->lock, flags); |
| 1801 | switch (typeReq) { |
| 1802 | case ClearHubFeature: |
| 1803 | switch (wValue) { |
| 1804 | case C_HUB_LOCAL_POWER: |
| 1805 | case C_HUB_OVER_CURRENT: |
| 1806 | /* no hub-wide feature/status flags */ |
| 1807 | break; |
| 1808 | default: |
| 1809 | goto error; |
| 1810 | } |
| 1811 | break; |
| 1812 | case ClearPortFeature: |
| 1813 | if (!wIndex || wIndex > ports) |
| 1814 | goto error; |
| 1815 | wIndex--; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1816 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1817 | |
| 1818 | /* |
| 1819 | * Even if OWNER is set, so the port is owned by the |
| 1820 | * companion controller, khubd needs to be able to clear |
| 1821 | * the port-change status bits (especially |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1822 | * USB_PORT_STAT_C_CONNECTION). |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1823 | */ |
| 1824 | |
| 1825 | switch (wValue) { |
| 1826 | case USB_PORT_FEAT_ENABLE: |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1827 | reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_PE); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1828 | break; |
| 1829 | case USB_PORT_FEAT_C_ENABLE: |
| 1830 | /* XXX error? */ |
| 1831 | break; |
| 1832 | case USB_PORT_FEAT_SUSPEND: |
| 1833 | if (temp & PORT_RESET) |
| 1834 | goto error; |
| 1835 | |
| 1836 | if (temp & PORT_SUSPEND) { |
| 1837 | if ((temp & PORT_PE) == 0) |
| 1838 | goto error; |
| 1839 | /* resume signaling for 20 msec */ |
| 1840 | temp &= ~(PORT_RWC_BITS); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1841 | reg_write32(hcd->regs, HC_PORTSC1, |
| 1842 | temp | PORT_RESUME); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1843 | priv->reset_done = jiffies + |
| 1844 | msecs_to_jiffies(20); |
| 1845 | } |
| 1846 | break; |
| 1847 | case USB_PORT_FEAT_C_SUSPEND: |
| 1848 | /* we auto-clear this feature */ |
| 1849 | break; |
| 1850 | case USB_PORT_FEAT_POWER: |
| 1851 | if (HCS_PPC(priv->hcs_params)) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1852 | reg_write32(hcd->regs, HC_PORTSC1, |
| 1853 | temp & ~PORT_POWER); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1854 | break; |
| 1855 | case USB_PORT_FEAT_C_CONNECTION: |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1856 | reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_CSC); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1857 | break; |
| 1858 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 1859 | /* XXX error ?*/ |
| 1860 | break; |
| 1861 | case USB_PORT_FEAT_C_RESET: |
| 1862 | /* GetPortStatus clears reset */ |
| 1863 | break; |
| 1864 | default: |
| 1865 | goto error; |
| 1866 | } |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1867 | reg_read32(hcd->regs, HC_USBCMD); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1868 | break; |
| 1869 | case GetHubDescriptor: |
| 1870 | isp1760_hub_descriptor(priv, (struct usb_hub_descriptor *) |
| 1871 | buf); |
| 1872 | break; |
| 1873 | case GetHubStatus: |
| 1874 | /* no hub-wide feature/status flags */ |
| 1875 | memset(buf, 0, 4); |
| 1876 | break; |
| 1877 | case GetPortStatus: |
| 1878 | if (!wIndex || wIndex > ports) |
| 1879 | goto error; |
| 1880 | wIndex--; |
| 1881 | status = 0; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1882 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1883 | |
| 1884 | /* wPortChange bits */ |
| 1885 | if (temp & PORT_CSC) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1886 | status |= USB_PORT_STAT_C_CONNECTION << 16; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1887 | |
| 1888 | |
| 1889 | /* whoever resumes must GetPortStatus to complete it!! */ |
| 1890 | if (temp & PORT_RESUME) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1891 | dev_err(hcd->self.controller, "Port resume should be skipped.\n"); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1892 | |
| 1893 | /* Remote Wakeup received? */ |
| 1894 | if (!priv->reset_done) { |
| 1895 | /* resume signaling for 20 msec */ |
| 1896 | priv->reset_done = jiffies |
| 1897 | + msecs_to_jiffies(20); |
| 1898 | /* check the port again */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1899 | mod_timer(&hcd->rh_timer, priv->reset_done); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | /* resume completed? */ |
| 1903 | else if (time_after_eq(jiffies, |
| 1904 | priv->reset_done)) { |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1905 | status |= USB_PORT_STAT_C_SUSPEND << 16; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1906 | priv->reset_done = 0; |
| 1907 | |
| 1908 | /* stop resume signaling */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1909 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
| 1910 | reg_write32(hcd->regs, HC_PORTSC1, |
| 1911 | temp & ~(PORT_RWC_BITS | PORT_RESUME)); |
| 1912 | retval = handshake(hcd, HC_PORTSC1, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1913 | PORT_RESUME, 0, 2000 /* 2msec */); |
| 1914 | if (retval != 0) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1915 | dev_err(hcd->self.controller, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1916 | "port %d resume error %d\n", |
| 1917 | wIndex + 1, retval); |
| 1918 | goto error; |
| 1919 | } |
| 1920 | temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10)); |
| 1921 | } |
| 1922 | } |
| 1923 | |
| 1924 | /* whoever resets must GetPortStatus to complete it!! */ |
| 1925 | if ((temp & PORT_RESET) |
| 1926 | && time_after_eq(jiffies, |
| 1927 | priv->reset_done)) { |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1928 | status |= USB_PORT_STAT_C_RESET << 16; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1929 | priv->reset_done = 0; |
| 1930 | |
| 1931 | /* force reset to complete */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1932 | reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_RESET); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1933 | /* REVISIT: some hardware needs 550+ usec to clear |
| 1934 | * this bit; seems too long to spin routinely... |
| 1935 | */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1936 | retval = handshake(hcd, HC_PORTSC1, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1937 | PORT_RESET, 0, 750); |
| 1938 | if (retval != 0) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1939 | dev_err(hcd->self.controller, "port %d reset error %d\n", |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1940 | wIndex + 1, retval); |
| 1941 | goto error; |
| 1942 | } |
| 1943 | |
| 1944 | /* see what we found out */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1945 | temp = check_reset_complete(hcd, wIndex, |
| 1946 | reg_read32(hcd->regs, HC_PORTSC1)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1947 | } |
| 1948 | /* |
| 1949 | * Even if OWNER is set, there's no harm letting khubd |
| 1950 | * see the wPortStatus values (they should all be 0 except |
| 1951 | * for PORT_POWER anyway). |
| 1952 | */ |
| 1953 | |
| 1954 | if (temp & PORT_OWNER) |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1955 | dev_err(hcd->self.controller, "PORT_OWNER is set\n"); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1956 | |
| 1957 | if (temp & PORT_CONNECT) { |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1958 | status |= USB_PORT_STAT_CONNECTION; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1959 | /* status may be from integrated TT */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1960 | status |= USB_PORT_STAT_HIGH_SPEED; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1961 | } |
| 1962 | if (temp & PORT_PE) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1963 | status |= USB_PORT_STAT_ENABLE; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1964 | if (temp & (PORT_SUSPEND|PORT_RESUME)) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1965 | status |= USB_PORT_STAT_SUSPEND; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1966 | if (temp & PORT_RESET) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1967 | status |= USB_PORT_STAT_RESET; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1968 | if (temp & PORT_POWER) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1969 | status |= USB_PORT_STAT_POWER; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1970 | |
| 1971 | put_unaligned(cpu_to_le32(status), (__le32 *) buf); |
| 1972 | break; |
| 1973 | case SetHubFeature: |
| 1974 | switch (wValue) { |
| 1975 | case C_HUB_LOCAL_POWER: |
| 1976 | case C_HUB_OVER_CURRENT: |
| 1977 | /* no hub-wide feature/status flags */ |
| 1978 | break; |
| 1979 | default: |
| 1980 | goto error; |
| 1981 | } |
| 1982 | break; |
| 1983 | case SetPortFeature: |
| 1984 | selector = wIndex >> 8; |
| 1985 | wIndex &= 0xff; |
| 1986 | if (!wIndex || wIndex > ports) |
| 1987 | goto error; |
| 1988 | wIndex--; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1989 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1990 | if (temp & PORT_OWNER) |
| 1991 | break; |
| 1992 | |
| 1993 | /* temp &= ~PORT_RWC_BITS; */ |
| 1994 | switch (wValue) { |
| 1995 | case USB_PORT_FEAT_ENABLE: |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1996 | reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_PE); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1997 | break; |
| 1998 | |
| 1999 | case USB_PORT_FEAT_SUSPEND: |
| 2000 | if ((temp & PORT_PE) == 0 |
| 2001 | || (temp & PORT_RESET) != 0) |
| 2002 | goto error; |
| 2003 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2004 | reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_SUSPEND); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2005 | break; |
| 2006 | case USB_PORT_FEAT_POWER: |
| 2007 | if (HCS_PPC(priv->hcs_params)) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2008 | reg_write32(hcd->regs, HC_PORTSC1, |
| 2009 | temp | PORT_POWER); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2010 | break; |
| 2011 | case USB_PORT_FEAT_RESET: |
| 2012 | if (temp & PORT_RESUME) |
| 2013 | goto error; |
| 2014 | /* line status bits may report this as low speed, |
| 2015 | * which can be fine if this root hub has a |
| 2016 | * transaction translator built in. |
| 2017 | */ |
| 2018 | if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT |
| 2019 | && PORT_USB11(temp)) { |
| 2020 | temp |= PORT_OWNER; |
| 2021 | } else { |
| 2022 | temp |= PORT_RESET; |
| 2023 | temp &= ~PORT_PE; |
| 2024 | |
| 2025 | /* |
| 2026 | * caller must wait, then call GetPortStatus |
| 2027 | * usb 2.0 spec says 50 ms resets on root |
| 2028 | */ |
| 2029 | priv->reset_done = jiffies + |
| 2030 | msecs_to_jiffies(50); |
| 2031 | } |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2032 | reg_write32(hcd->regs, HC_PORTSC1, temp); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2033 | break; |
| 2034 | default: |
| 2035 | goto error; |
| 2036 | } |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2037 | reg_read32(hcd->regs, HC_USBCMD); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2038 | break; |
| 2039 | |
| 2040 | default: |
| 2041 | error: |
| 2042 | /* "stall" on error */ |
| 2043 | retval = -EPIPE; |
| 2044 | } |
| 2045 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2046 | return retval; |
| 2047 | } |
| 2048 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2049 | static int isp1760_get_frame(struct usb_hcd *hcd) |
| 2050 | { |
| 2051 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 2052 | u32 fr; |
| 2053 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2054 | fr = reg_read32(hcd->regs, HC_FRINDEX); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2055 | return (fr >> 3) % priv->periodic_size; |
| 2056 | } |
| 2057 | |
| 2058 | static void isp1760_stop(struct usb_hcd *hcd) |
| 2059 | { |
| 2060 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 2061 | u32 temp; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2062 | |
Arvid Brodin | 6d50c60 | 2011-08-21 08:29:26 +0200 | [diff] [blame^] | 2063 | del_timer(&errata2_timer); |
| 2064 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2065 | isp1760_hub_control(hcd, ClearPortFeature, USB_PORT_FEAT_POWER, 1, |
| 2066 | NULL, 0); |
| 2067 | mdelay(20); |
| 2068 | |
| 2069 | spin_lock_irq(&priv->lock); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 2070 | ehci_reset(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2071 | /* Disable IRQ */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2072 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); |
| 2073 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp &= ~HW_GLOBAL_INTR_EN); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2074 | spin_unlock_irq(&priv->lock); |
| 2075 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2076 | reg_write32(hcd->regs, HC_CONFIGFLAG, 0); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | static void isp1760_shutdown(struct usb_hcd *hcd) |
| 2080 | { |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 2081 | u32 command, temp; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2082 | |
| 2083 | isp1760_stop(hcd); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2084 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); |
| 2085 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp &= ~HW_GLOBAL_INTR_EN); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2086 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2087 | command = reg_read32(hcd->regs, HC_USBCMD); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2088 | command &= ~CMD_RUN; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2089 | reg_write32(hcd->regs, HC_USBCMD, command); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | static const struct hc_driver isp1760_hc_driver = { |
| 2093 | .description = "isp1760-hcd", |
| 2094 | .product_desc = "NXP ISP1760 USB Host Controller", |
| 2095 | .hcd_priv_size = sizeof(struct isp1760_hcd), |
| 2096 | .irq = isp1760_irq, |
| 2097 | .flags = HCD_MEMORY | HCD_USB2, |
| 2098 | .reset = isp1760_hc_setup, |
| 2099 | .start = isp1760_run, |
| 2100 | .stop = isp1760_stop, |
| 2101 | .shutdown = isp1760_shutdown, |
| 2102 | .urb_enqueue = isp1760_urb_enqueue, |
| 2103 | .urb_dequeue = isp1760_urb_dequeue, |
| 2104 | .endpoint_disable = isp1760_endpoint_disable, |
| 2105 | .get_frame_number = isp1760_get_frame, |
| 2106 | .hub_status_data = isp1760_hub_status_data, |
| 2107 | .hub_control = isp1760_hub_control, |
| 2108 | }; |
| 2109 | |
| 2110 | int __init init_kmem_once(void) |
| 2111 | { |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 2112 | urb_listitem_cachep = kmem_cache_create("isp1760 urb_listitem", |
| 2113 | sizeof(struct urb_listitem), 0, SLAB_TEMPORARY | |
| 2114 | SLAB_MEM_SPREAD, NULL); |
| 2115 | |
| 2116 | if (!urb_listitem_cachep) |
| 2117 | return -ENOMEM; |
| 2118 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2119 | qtd_cachep = kmem_cache_create("isp1760_qtd", |
| 2120 | sizeof(struct isp1760_qtd), 0, SLAB_TEMPORARY | |
| 2121 | SLAB_MEM_SPREAD, NULL); |
| 2122 | |
| 2123 | if (!qtd_cachep) |
| 2124 | return -ENOMEM; |
| 2125 | |
| 2126 | qh_cachep = kmem_cache_create("isp1760_qh", sizeof(struct isp1760_qh), |
| 2127 | 0, SLAB_TEMPORARY | SLAB_MEM_SPREAD, NULL); |
| 2128 | |
| 2129 | if (!qh_cachep) { |
| 2130 | kmem_cache_destroy(qtd_cachep); |
| 2131 | return -ENOMEM; |
| 2132 | } |
| 2133 | |
| 2134 | return 0; |
| 2135 | } |
| 2136 | |
| 2137 | void deinit_kmem_cache(void) |
| 2138 | { |
| 2139 | kmem_cache_destroy(qtd_cachep); |
| 2140 | kmem_cache_destroy(qh_cachep); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 2141 | kmem_cache_destroy(urb_listitem_cachep); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2142 | } |
| 2143 | |
Catalin Marinas | f9031f2 | 2009-02-10 16:55:45 +0000 | [diff] [blame] | 2144 | struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len, |
| 2145 | int irq, unsigned long irqflags, |
| 2146 | struct device *dev, const char *busname, |
| 2147 | unsigned int devflags) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2148 | { |
| 2149 | struct usb_hcd *hcd; |
| 2150 | struct isp1760_hcd *priv; |
| 2151 | int ret; |
| 2152 | |
| 2153 | if (usb_disabled()) |
| 2154 | return ERR_PTR(-ENODEV); |
| 2155 | |
| 2156 | /* prevent usb-core allocating DMA pages */ |
| 2157 | dev->dma_mask = NULL; |
| 2158 | |
Kay Sievers | 0031a06 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 2159 | hcd = usb_create_hcd(&isp1760_hc_driver, dev, dev_name(dev)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2160 | if (!hcd) |
| 2161 | return ERR_PTR(-ENOMEM); |
| 2162 | |
| 2163 | priv = hcd_to_priv(hcd); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 2164 | priv->devflags = devflags; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2165 | init_memory(priv); |
| 2166 | hcd->regs = ioremap(res_start, res_len); |
| 2167 | if (!hcd->regs) { |
| 2168 | ret = -EIO; |
| 2169 | goto err_put; |
| 2170 | } |
| 2171 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2172 | hcd->irq = irq; |
| 2173 | hcd->rsrc_start = res_start; |
| 2174 | hcd->rsrc_len = res_len; |
| 2175 | |
Nate Case | e6942d6 | 2008-05-21 16:28:20 -0500 | [diff] [blame] | 2176 | ret = usb_add_hcd(hcd, irq, irqflags); |
| 2177 | if (ret) |
| 2178 | goto err_unmap; |
| 2179 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2180 | return hcd; |
| 2181 | |
| 2182 | err_unmap: |
| 2183 | iounmap(hcd->regs); |
| 2184 | |
| 2185 | err_put: |
| 2186 | usb_put_hcd(hcd); |
| 2187 | |
| 2188 | return ERR_PTR(ret); |
| 2189 | } |
| 2190 | |
| 2191 | MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP"); |
| 2192 | MODULE_AUTHOR("Sebastian Siewior <bigeasy@linuxtronix.de>"); |
| 2193 | MODULE_LICENSE("GPL v2"); |