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> |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 24 | #include <asm/unaligned.h> |
Catalin Marinas | db8516f | 2010-02-02 15:31:02 +0000 | [diff] [blame] | 25 | #include <asm/cacheflush.h> |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 26 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 27 | #include "isp1760-hcd.h" |
| 28 | |
| 29 | static struct kmem_cache *qtd_cachep; |
| 30 | static struct kmem_cache *qh_cachep; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 31 | static struct kmem_cache *urb_listitem_cachep; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 32 | |
| 33 | struct isp1760_hcd { |
| 34 | u32 hcs_params; |
| 35 | spinlock_t lock; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 36 | struct slotinfo atl_slots[32]; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 37 | int atl_done_map; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 38 | struct slotinfo int_slots[32]; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 39 | int int_done_map; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 40 | struct memory_chunk memory_pool[BLOCKS]; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 41 | struct list_head controlqhs, bulkqhs, interruptqhs; |
| 42 | int active_ptds; |
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 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 492 | /* This is weird: at the first plug-in of a device there seems to be |
| 493 | one packet queued that never gets returned? */ |
| 494 | priv->active_ptds = -1; |
| 495 | |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 496 | /* ATL reset */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 497 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode | ALL_ATX_RESET); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 498 | mdelay(10); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 499 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 500 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 501 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, INTERRUPT_ENABLE_MASK); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 502 | |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 503 | /* |
| 504 | * PORT 1 Control register of the ISP1760 is the OTG control |
Thomas Hommel | 42c6539 | 2008-12-18 10:31:40 +0100 | [diff] [blame] | 505 | * register on ISP1761. Since there is no OTG or device controller |
| 506 | * support in this driver, we use port 1 as a "normal" USB host port on |
| 507 | * both chips. |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 508 | */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 509 | reg_write32(hcd->regs, HC_PORT1_CTRL, PORT1_POWER | PORT1_INIT2); |
Thomas Hommel | 42c6539 | 2008-12-18 10:31:40 +0100 | [diff] [blame] | 510 | mdelay(10); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 511 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 512 | priv->hcs_params = reg_read32(hcd->regs, HC_HCSPARAMS); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 513 | |
| 514 | return priv_init(hcd); |
| 515 | } |
| 516 | |
| 517 | static void isp1760_init_maps(struct usb_hcd *hcd) |
| 518 | { |
| 519 | /*set last maps, for iso its only 1, else 32 tds bitmap*/ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 520 | reg_write32(hcd->regs, HC_ATL_PTD_LASTPTD_REG, 0x80000000); |
| 521 | reg_write32(hcd->regs, HC_INT_PTD_LASTPTD_REG, 0x80000000); |
| 522 | reg_write32(hcd->regs, HC_ISO_PTD_LASTPTD_REG, 0x00000001); |
Arvid Brodin | eb1a796 | 2011-04-26 21:48:02 +0200 | [diff] [blame] | 523 | |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 524 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, 0xffffffff); |
| 525 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, 0xffffffff); |
| 526 | reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, 0xffffffff); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 527 | |
Arvid Brodin | eb1a796 | 2011-04-26 21:48:02 +0200 | [diff] [blame] | 528 | reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, |
| 529 | ATL_BUF_FILL | INT_BUF_FILL); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | static void isp1760_enable_interrupts(struct usb_hcd *hcd) |
| 533 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 534 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_AND_REG, 0); |
Arvid Brodin | eb1a796 | 2011-04-26 21:48:02 +0200 | [diff] [blame] | 535 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, 0xffffffff); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 536 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_AND_REG, 0); |
Arvid Brodin | eb1a796 | 2011-04-26 21:48:02 +0200 | [diff] [blame] | 537 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, 0xffffffff); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 538 | reg_write32(hcd->regs, HC_ISO_IRQ_MASK_AND_REG, 0); |
| 539 | reg_write32(hcd->regs, HC_ISO_IRQ_MASK_OR_REG, 0xffffffff); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 540 | /* step 23 passed */ |
| 541 | } |
| 542 | |
| 543 | static int isp1760_run(struct usb_hcd *hcd) |
| 544 | { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 545 | int retval; |
| 546 | u32 temp; |
| 547 | u32 command; |
| 548 | u32 chipid; |
| 549 | |
| 550 | hcd->uses_new_polling = 1; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 551 | |
| 552 | hcd->state = HC_STATE_RUNNING; |
| 553 | isp1760_enable_interrupts(hcd); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 554 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); |
| 555 | 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] | 556 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 557 | command = reg_read32(hcd->regs, HC_USBCMD); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 558 | command &= ~(CMD_LRESET|CMD_RESET); |
| 559 | command |= CMD_RUN; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 560 | reg_write32(hcd->regs, HC_USBCMD, command); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 561 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 562 | retval = handshake(hcd, HC_USBCMD, CMD_RUN, CMD_RUN, 250 * 1000); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 563 | if (retval) |
| 564 | return retval; |
| 565 | |
| 566 | /* |
| 567 | * XXX |
| 568 | * Spec says to write FLAG_CF as last config action, priv code grabs |
| 569 | * the semaphore while doing so. |
| 570 | */ |
| 571 | down_write(&ehci_cf_port_reset_rwsem); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 572 | reg_write32(hcd->regs, HC_CONFIGFLAG, FLAG_CF); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 573 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 574 | retval = handshake(hcd, HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 250 * 1000); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 575 | up_write(&ehci_cf_port_reset_rwsem); |
| 576 | if (retval) |
| 577 | return retval; |
| 578 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 579 | chipid = reg_read32(hcd->regs, HC_CHIP_ID_REG); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 580 | dev_info(hcd->self.controller, "USB ISP %04x HW rev. %d started\n", |
| 581 | chipid & 0xffff, chipid >> 16); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 582 | |
| 583 | /* PTD Register Init Part 2, Step 28 */ |
| 584 | /* enable INTs */ |
| 585 | isp1760_init_maps(hcd); |
| 586 | |
| 587 | /* GRR this is run-once init(), being done every time the HC starts. |
| 588 | * So long as they're part of class devices, we can't do it init() |
| 589 | * since the class device isn't created that early. |
| 590 | */ |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | static u32 base_to_chip(u32 base) |
| 595 | { |
| 596 | return ((base - 0x400) >> 3); |
| 597 | } |
| 598 | |
Arvid Brodin | 7adc14b | 2011-02-26 22:08:47 +0100 | [diff] [blame] | 599 | static int last_qtd_of_urb(struct isp1760_qtd *qtd, struct isp1760_qh *qh) |
| 600 | { |
| 601 | struct urb *urb; |
| 602 | |
| 603 | if (list_is_last(&qtd->qtd_list, &qh->qtd_list)) |
| 604 | return 1; |
| 605 | |
| 606 | urb = qtd->urb; |
| 607 | qtd = list_entry(qtd->qtd_list.next, typeof(*qtd), qtd_list); |
| 608 | return (qtd->urb != urb); |
| 609 | } |
| 610 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 611 | /* magic numbers that can affect system performance */ |
| 612 | #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */ |
| 613 | #define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */ |
| 614 | #define EHCI_TUNE_RL_TT 0 |
| 615 | #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */ |
| 616 | #define EHCI_TUNE_MULT_TT 1 |
| 617 | #define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */ |
| 618 | |
| 619 | static void create_ptd_atl(struct isp1760_qh *qh, |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 620 | struct isp1760_qtd *qtd, struct ptd *ptd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 621 | { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 622 | u32 maxpacket; |
| 623 | u32 multi; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 624 | u32 rl = RL_COUNTER; |
| 625 | u32 nak = NAK_COUNTER; |
| 626 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 627 | memset(ptd, 0, sizeof(*ptd)); |
| 628 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 629 | /* according to 3.6.2, max packet len can not be > 0x400 */ |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 630 | maxpacket = usb_maxpacket(qtd->urb->dev, qtd->urb->pipe, |
| 631 | usb_pipeout(qtd->urb->pipe)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 632 | multi = 1 + ((maxpacket >> 11) & 0x3); |
| 633 | maxpacket &= 0x7ff; |
| 634 | |
| 635 | /* DW0 */ |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 636 | ptd->dw0 = DW0_VALID_BIT; |
| 637 | ptd->dw0 |= TO_DW0_LENGTH(qtd->length); |
| 638 | ptd->dw0 |= TO_DW0_MAXPACKET(maxpacket); |
| 639 | ptd->dw0 |= TO_DW0_ENDPOINT(usb_pipeendpoint(qtd->urb->pipe)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 640 | |
| 641 | /* DW1 */ |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 642 | ptd->dw1 = usb_pipeendpoint(qtd->urb->pipe) >> 1; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 643 | ptd->dw1 |= TO_DW1_DEVICE_ADDR(usb_pipedevice(qtd->urb->pipe)); |
| 644 | ptd->dw1 |= TO_DW1_PID_TOKEN(qtd->packet_type); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 645 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 646 | if (usb_pipebulk(qtd->urb->pipe)) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 647 | ptd->dw1 |= DW1_TRANS_BULK; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 648 | else if (usb_pipeint(qtd->urb->pipe)) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 649 | ptd->dw1 |= DW1_TRANS_INT; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 650 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 651 | if (qtd->urb->dev->speed != USB_SPEED_HIGH) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 652 | /* split transaction */ |
| 653 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 654 | ptd->dw1 |= DW1_TRANS_SPLIT; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 655 | if (qtd->urb->dev->speed == USB_SPEED_LOW) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 656 | ptd->dw1 |= DW1_SE_USB_LOSPEED; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 657 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 658 | ptd->dw1 |= TO_DW1_PORT_NUM(qtd->urb->dev->ttport); |
| 659 | ptd->dw1 |= TO_DW1_HUB_NUM(qtd->urb->dev->tt->hub->devnum); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 660 | |
| 661 | /* SE bit for Split INT transfers */ |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 662 | if (usb_pipeint(qtd->urb->pipe) && |
| 663 | (qtd->urb->dev->speed == USB_SPEED_LOW)) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 664 | ptd->dw1 |= 2 << 16; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 665 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 666 | rl = 0; |
| 667 | nak = 0; |
| 668 | } else { |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 669 | ptd->dw0 |= TO_DW0_MULTI(multi); |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 670 | if (usb_pipecontrol(qtd->urb->pipe) || |
| 671 | usb_pipebulk(qtd->urb->pipe)) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 672 | ptd->dw3 |= TO_DW3_PING(qh->ping); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 673 | } |
| 674 | /* DW2 */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 675 | ptd->dw2 = 0; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 676 | ptd->dw2 |= TO_DW2_DATA_START_ADDR(base_to_chip(qtd->payload_addr)); |
| 677 | ptd->dw2 |= TO_DW2_RL(rl); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 678 | |
| 679 | /* DW3 */ |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 680 | ptd->dw3 |= TO_DW3_NAKCOUNT(nak); |
| 681 | ptd->dw3 |= TO_DW3_DATA_TOGGLE(qh->toggle); |
Arvid Brodin | 7adc14b | 2011-02-26 22:08:47 +0100 | [diff] [blame] | 682 | if (usb_pipecontrol(qtd->urb->pipe)) { |
| 683 | if (qtd->data_buffer == qtd->urb->setup_packet) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 684 | ptd->dw3 &= ~TO_DW3_DATA_TOGGLE(1); |
Arvid Brodin | 7adc14b | 2011-02-26 22:08:47 +0100 | [diff] [blame] | 685 | else if (last_qtd_of_urb(qtd, qh)) |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 686 | ptd->dw3 |= TO_DW3_DATA_TOGGLE(1); |
Arvid Brodin | 7adc14b | 2011-02-26 22:08:47 +0100 | [diff] [blame] | 687 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 688 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 689 | ptd->dw3 |= DW3_ACTIVE_BIT; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 690 | /* Cerr */ |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 691 | ptd->dw3 |= TO_DW3_CERR(ERR_COUNTER); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 692 | } |
| 693 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 694 | static void transform_add_int(struct isp1760_qh *qh, |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 695 | struct isp1760_qtd *qtd, struct ptd *ptd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 696 | { |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 697 | u32 usof; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 698 | u32 period; |
| 699 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 700 | /* |
| 701 | * Most of this is guessing. ISP1761 datasheet is quite unclear, and |
| 702 | * the algorithm from the original Philips driver code, which was |
| 703 | * pretty much used in this driver before as well, is quite horrendous |
| 704 | * and, i believe, incorrect. The code below follows the datasheet and |
| 705 | * USB2.0 spec as far as I can tell, and plug/unplug seems to be much |
| 706 | * more reliable this way (fingers crossed...). |
| 707 | */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 708 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 709 | if (qtd->urb->dev->speed == USB_SPEED_HIGH) { |
| 710 | /* urb->interval is in units of microframes (1/8 ms) */ |
| 711 | period = qtd->urb->interval >> 3; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 712 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 713 | if (qtd->urb->interval > 4) |
| 714 | usof = 0x01; /* One bit set => |
| 715 | interval 1 ms * uFrame-match */ |
| 716 | else if (qtd->urb->interval > 2) |
| 717 | usof = 0x22; /* Two bits set => interval 1/2 ms */ |
| 718 | else if (qtd->urb->interval > 1) |
| 719 | usof = 0x55; /* Four bits set => interval 1/4 ms */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 720 | else |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 721 | usof = 0xff; /* All bits set => interval 1/8 ms */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 722 | } else { |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 723 | /* urb->interval is in units of frames (1 ms) */ |
| 724 | period = qtd->urb->interval; |
| 725 | usof = 0x0f; /* Execute Start Split on any of the |
| 726 | four first uFrames */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 727 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 728 | /* |
| 729 | * First 8 bits in dw5 is uSCS and "specifies which uSOF the |
| 730 | * complete split needs to be sent. Valid only for IN." Also, |
| 731 | * "All bits can be set to one for every transfer." (p 82, |
| 732 | * ISP1761 data sheet.) 0x1c is from Philips driver. Where did |
| 733 | * that number come from? 0xff seems to work fine... |
| 734 | */ |
| 735 | /* ptd->dw5 = 0x1c; */ |
| 736 | ptd->dw5 = 0xff; /* Execute Complete Split on any uFrame */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 737 | } |
| 738 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame] | 739 | period = period >> 1;/* Ensure equal or shorter period than requested */ |
| 740 | period &= 0xf8; /* Mask off too large values and lowest unused 3 bits */ |
| 741 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 742 | ptd->dw2 |= period; |
| 743 | ptd->dw4 = usof; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 744 | } |
| 745 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 746 | static void create_ptd_int(struct isp1760_qh *qh, |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 747 | struct isp1760_qtd *qtd, struct ptd *ptd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 748 | { |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 749 | create_ptd_atl(qh, qtd, ptd); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 750 | transform_add_int(qh, qtd, ptd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 751 | } |
| 752 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 753 | static void isp1760_urb_done(struct usb_hcd *hcd, struct urb *urb) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 754 | __releases(priv->lock) |
| 755 | __acquires(priv->lock) |
| 756 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 757 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 758 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 759 | if (!urb->unlinked) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 760 | if (urb->status == -EINPROGRESS) |
| 761 | urb->status = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 762 | } |
| 763 | |
Catalin Marinas | db8516f | 2010-02-02 15:31:02 +0000 | [diff] [blame] | 764 | if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) { |
| 765 | void *ptr; |
| 766 | for (ptr = urb->transfer_buffer; |
| 767 | ptr < urb->transfer_buffer + urb->transfer_buffer_length; |
| 768 | ptr += PAGE_SIZE) |
| 769 | flush_dcache_page(virt_to_page(ptr)); |
| 770 | } |
| 771 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 772 | /* complete() can reenter this HCD */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 773 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 774 | spin_unlock(&priv->lock); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 775 | usb_hcd_giveback_urb(hcd, urb, urb->status); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 776 | spin_lock(&priv->lock); |
| 777 | } |
| 778 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 779 | static struct isp1760_qtd *qtd_alloc(gfp_t flags, struct urb *urb, |
| 780 | u8 packet_type) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 781 | { |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 782 | struct isp1760_qtd *qtd; |
| 783 | |
| 784 | qtd = kmem_cache_zalloc(qtd_cachep, flags); |
| 785 | if (!qtd) |
| 786 | return NULL; |
| 787 | |
| 788 | INIT_LIST_HEAD(&qtd->qtd_list); |
| 789 | qtd->urb = urb; |
| 790 | qtd->packet_type = packet_type; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 791 | qtd->status = QTD_ENQUEUED; |
| 792 | qtd->actual_length = 0; |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 793 | |
| 794 | return qtd; |
| 795 | } |
| 796 | |
| 797 | static void qtd_free(struct isp1760_qtd *qtd) |
| 798 | { |
| 799 | WARN_ON(qtd->payload_addr); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 800 | kmem_cache_free(qtd_cachep, qtd); |
| 801 | } |
| 802 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 803 | static void start_bus_transfer(struct usb_hcd *hcd, u32 ptd_offset, int slot, |
| 804 | struct slotinfo *slots, struct isp1760_qtd *qtd, |
| 805 | struct isp1760_qh *qh, struct ptd *ptd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 806 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 807 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 808 | int skip_map; |
| 809 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 810 | WARN_ON((slot < 0) || (slot > 31)); |
| 811 | WARN_ON(qtd->length && !qtd->payload_addr); |
| 812 | WARN_ON(slots[slot].qtd); |
| 813 | WARN_ON(slots[slot].qh); |
| 814 | WARN_ON(qtd->status != QTD_PAYLOAD_ALLOC); |
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 | slots[slot].qtd = qtd; |
| 817 | slots[slot].qh = qh; |
| 818 | qh->slot = slot; |
| 819 | qtd->status = QTD_XFER_STARTED; /* Set this before writing ptd, since |
| 820 | interrupt routine may preempt and expects this value. */ |
| 821 | ptd_write(hcd->regs, ptd_offset, slot, ptd); |
| 822 | priv->active_ptds++; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 823 | |
| 824 | /* Make sure done map has not triggered from some unlinked transfer */ |
| 825 | if (ptd_offset == ATL_PTD_OFFSET) { |
| 826 | priv->atl_done_map |= reg_read32(hcd->regs, |
| 827 | HC_ATL_PTD_DONEMAP_REG); |
| 828 | priv->atl_done_map &= ~(1 << qh->slot); |
| 829 | |
| 830 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
| 831 | skip_map &= ~(1 << qh->slot); |
| 832 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map); |
| 833 | } else { |
| 834 | priv->int_done_map |= reg_read32(hcd->regs, |
| 835 | HC_INT_PTD_DONEMAP_REG); |
| 836 | priv->int_done_map &= ~(1 << qh->slot); |
| 837 | |
| 838 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
| 839 | skip_map &= ~(1 << qh->slot); |
| 840 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map); |
| 841 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 842 | } |
| 843 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 844 | static int is_short_bulk(struct isp1760_qtd *qtd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 845 | { |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 846 | return (usb_pipebulk(qtd->urb->pipe) && |
| 847 | (qtd->actual_length < qtd->length)); |
| 848 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 849 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 850 | static void collect_qtds(struct usb_hcd *hcd, struct isp1760_qh *qh, |
| 851 | struct list_head *urb_list) |
| 852 | { |
| 853 | int last_qtd; |
| 854 | struct isp1760_qtd *qtd, *qtd_next; |
| 855 | struct urb_listitem *urb_listitem; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 856 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 857 | list_for_each_entry_safe(qtd, qtd_next, &qh->qtd_list, qtd_list) { |
| 858 | if (qtd->status < QTD_XFER_COMPLETE) |
| 859 | break; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 860 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 861 | if (list_is_last(&qtd->qtd_list, &qh->qtd_list)) |
| 862 | last_qtd = 1; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 863 | else |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 864 | last_qtd = qtd->urb != qtd_next->urb; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 865 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 866 | if ((!last_qtd) && (qtd->status == QTD_RETIRE)) |
| 867 | qtd_next->status = QTD_RETIRE; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 868 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 869 | if (qtd->status == QTD_XFER_COMPLETE) { |
| 870 | if (qtd->actual_length) { |
| 871 | switch (qtd->packet_type) { |
| 872 | case IN_PID: |
| 873 | mem_reads8(hcd->regs, qtd->payload_addr, |
| 874 | qtd->data_buffer, |
| 875 | qtd->actual_length); |
| 876 | /* Fall through (?) */ |
| 877 | case OUT_PID: |
| 878 | qtd->urb->actual_length += |
| 879 | qtd->actual_length; |
| 880 | /* Fall through ... */ |
| 881 | case SETUP_PID: |
| 882 | break; |
| 883 | } |
| 884 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 885 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 886 | if (is_short_bulk(qtd)) { |
| 887 | if (qtd->urb->transfer_flags & URB_SHORT_NOT_OK) |
| 888 | qtd->urb->status = -EREMOTEIO; |
| 889 | if (!last_qtd) |
| 890 | qtd_next->status = QTD_RETIRE; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 894 | if (qtd->payload_addr) |
| 895 | free_mem(hcd, qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 896 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 897 | if (last_qtd) { |
| 898 | if ((qtd->status == QTD_RETIRE) && |
| 899 | (qtd->urb->status == -EINPROGRESS)) |
| 900 | qtd->urb->status = -EPIPE; |
| 901 | /* Defer calling of urb_done() since it releases lock */ |
| 902 | urb_listitem = kmem_cache_zalloc(urb_listitem_cachep, |
| 903 | GFP_ATOMIC); |
| 904 | if (unlikely(!urb_listitem)) |
| 905 | break; |
| 906 | urb_listitem->urb = qtd->urb; |
| 907 | list_add_tail(&urb_listitem->urb_list, urb_list); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 908 | } |
| 909 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 910 | list_del(&qtd->qtd_list); |
| 911 | qtd_free(qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 915 | #define ENQUEUE_DEPTH 2 |
| 916 | static void enqueue_qtds(struct usb_hcd *hcd, struct isp1760_qh *qh) |
| 917 | { |
| 918 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 919 | int ptd_offset; |
| 920 | struct slotinfo *slots; |
| 921 | int curr_slot, free_slot; |
| 922 | int n; |
| 923 | struct ptd ptd; |
| 924 | struct isp1760_qtd *qtd; |
| 925 | |
| 926 | if (unlikely(list_empty(&qh->qtd_list))) { |
| 927 | WARN_ON(1); |
| 928 | return; |
| 929 | } |
| 930 | |
| 931 | if (usb_pipeint(list_entry(qh->qtd_list.next, struct isp1760_qtd, |
| 932 | qtd_list)->urb->pipe)) { |
| 933 | ptd_offset = INT_PTD_OFFSET; |
| 934 | slots = priv->int_slots; |
| 935 | } else { |
| 936 | ptd_offset = ATL_PTD_OFFSET; |
| 937 | slots = priv->atl_slots; |
| 938 | } |
| 939 | |
| 940 | free_slot = -1; |
| 941 | for (curr_slot = 0; curr_slot < 32; curr_slot++) { |
| 942 | if ((free_slot == -1) && (slots[curr_slot].qtd == NULL)) |
| 943 | free_slot = curr_slot; |
| 944 | if (slots[curr_slot].qh == qh) |
| 945 | break; |
| 946 | } |
| 947 | |
| 948 | n = 0; |
| 949 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list) { |
| 950 | if (qtd->status == QTD_ENQUEUED) { |
| 951 | WARN_ON(qtd->payload_addr); |
| 952 | alloc_mem(hcd, qtd); |
| 953 | if ((qtd->length) && (!qtd->payload_addr)) |
| 954 | break; |
| 955 | |
| 956 | if ((qtd->length) && |
| 957 | ((qtd->packet_type == SETUP_PID) || |
| 958 | (qtd->packet_type == OUT_PID))) { |
| 959 | mem_writes8(hcd->regs, qtd->payload_addr, |
| 960 | qtd->data_buffer, qtd->length); |
| 961 | } |
| 962 | |
| 963 | qtd->status = QTD_PAYLOAD_ALLOC; |
| 964 | } |
| 965 | |
| 966 | if (qtd->status == QTD_PAYLOAD_ALLOC) { |
| 967 | /* |
| 968 | if ((curr_slot > 31) && (free_slot == -1)) |
| 969 | dev_dbg(hcd->self.controller, "%s: No slot " |
| 970 | "available for transfer\n", __func__); |
| 971 | */ |
| 972 | /* Start xfer for this endpoint if not already done */ |
| 973 | if ((curr_slot > 31) && (free_slot > -1)) { |
| 974 | if (usb_pipeint(qtd->urb->pipe)) |
| 975 | create_ptd_int(qh, qtd, &ptd); |
| 976 | else |
| 977 | create_ptd_atl(qh, qtd, &ptd); |
| 978 | |
| 979 | start_bus_transfer(hcd, ptd_offset, free_slot, |
| 980 | slots, qtd, qh, &ptd); |
| 981 | curr_slot = free_slot; |
| 982 | } |
| 983 | |
| 984 | n++; |
| 985 | if (n >= ENQUEUE_DEPTH) |
| 986 | break; |
| 987 | } |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | void schedule_ptds(struct usb_hcd *hcd) |
| 992 | { |
| 993 | struct isp1760_hcd *priv; |
| 994 | struct isp1760_qh *qh, *qh_next; |
| 995 | struct list_head *ep_queue; |
| 996 | struct usb_host_endpoint *ep; |
| 997 | LIST_HEAD(urb_list); |
| 998 | struct urb_listitem *urb_listitem, *urb_listitem_next; |
| 999 | |
| 1000 | if (!hcd) { |
| 1001 | WARN_ON(1); |
| 1002 | return; |
| 1003 | } |
| 1004 | |
| 1005 | priv = hcd_to_priv(hcd); |
| 1006 | |
| 1007 | /* |
| 1008 | * check finished/retired xfers, transfer payloads, call urb_done() |
| 1009 | */ |
| 1010 | ep_queue = &priv->interruptqhs; |
| 1011 | while (ep_queue) { |
| 1012 | list_for_each_entry_safe(qh, qh_next, ep_queue, qh_list) { |
| 1013 | ep = list_entry(qh->qtd_list.next, struct isp1760_qtd, |
| 1014 | qtd_list)->urb->ep; |
| 1015 | collect_qtds(hcd, qh, &urb_list); |
| 1016 | if (list_empty(&qh->qtd_list)) { |
| 1017 | list_del(&qh->qh_list); |
| 1018 | if (ep->hcpriv == NULL) { |
| 1019 | /* Endpoint has been disabled, so we |
| 1020 | can free the associated queue head. */ |
| 1021 | qh_free(qh); |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | if (ep_queue == &priv->interruptqhs) |
| 1027 | ep_queue = &priv->controlqhs; |
| 1028 | else if (ep_queue == &priv->controlqhs) |
| 1029 | ep_queue = &priv->bulkqhs; |
| 1030 | else |
| 1031 | ep_queue = NULL; |
| 1032 | } |
| 1033 | |
| 1034 | list_for_each_entry_safe(urb_listitem, urb_listitem_next, &urb_list, |
| 1035 | urb_list) { |
| 1036 | isp1760_urb_done(hcd, urb_listitem->urb); |
| 1037 | kmem_cache_free(urb_listitem_cachep, urb_listitem); |
| 1038 | } |
| 1039 | |
| 1040 | /* |
| 1041 | * Schedule packets for transfer. |
| 1042 | * |
| 1043 | * According to USB2.0 specification: |
| 1044 | * |
| 1045 | * 1st prio: interrupt xfers, up to 80 % of bandwidth |
| 1046 | * 2nd prio: control xfers |
| 1047 | * 3rd prio: bulk xfers |
| 1048 | * |
| 1049 | * ... but let's use a simpler scheme here (mostly because ISP1761 doc |
| 1050 | * is very unclear on how to prioritize traffic): |
| 1051 | * |
| 1052 | * 1) Enqueue any queued control transfers, as long as payload chip mem |
| 1053 | * and PTD ATL slots are available. |
| 1054 | * 2) Enqueue any queued INT transfers, as long as payload chip mem |
| 1055 | * and PTD INT slots are available. |
| 1056 | * 3) Enqueue any queued bulk transfers, as long as payload chip mem |
| 1057 | * and PTD ATL slots are available. |
| 1058 | * |
| 1059 | * Use double buffering (ENQUEUE_DEPTH==2) as a compromise between |
| 1060 | * conservation of chip mem and performance. |
| 1061 | * |
| 1062 | * I'm sure this scheme could be improved upon! |
| 1063 | */ |
| 1064 | ep_queue = &priv->controlqhs; |
| 1065 | while (ep_queue) { |
| 1066 | list_for_each_entry_safe(qh, qh_next, ep_queue, qh_list) |
| 1067 | enqueue_qtds(hcd, qh); |
| 1068 | |
| 1069 | if (ep_queue == &priv->controlqhs) |
| 1070 | ep_queue = &priv->interruptqhs; |
| 1071 | else if (ep_queue == &priv->interruptqhs) |
| 1072 | ep_queue = &priv->bulkqhs; |
| 1073 | else |
| 1074 | ep_queue = NULL; |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | #define PTD_STATE_QTD_DONE 1 |
| 1079 | #define PTD_STATE_QTD_RELOAD 2 |
| 1080 | #define PTD_STATE_URB_RETIRE 3 |
| 1081 | |
| 1082 | static int check_int_transfer(struct usb_hcd *hcd, struct ptd *ptd, |
| 1083 | struct urb *urb) |
| 1084 | { |
| 1085 | __dw dw4; |
| 1086 | int i; |
| 1087 | |
| 1088 | dw4 = ptd->dw4; |
| 1089 | dw4 >>= 8; |
| 1090 | |
| 1091 | /* FIXME: ISP1761 datasheet does not say what to do with these. Do we |
| 1092 | need to handle these errors? Is it done in hardware? */ |
| 1093 | |
| 1094 | if (ptd->dw3 & DW3_HALT_BIT) { |
| 1095 | |
| 1096 | urb->status = -EPROTO; /* Default unknown error */ |
| 1097 | |
| 1098 | for (i = 0; i < 8; i++) { |
| 1099 | switch (dw4 & 0x7) { |
| 1100 | case INT_UNDERRUN: |
| 1101 | dev_dbg(hcd->self.controller, "%s: underrun " |
| 1102 | "during uFrame %d\n", |
| 1103 | __func__, i); |
| 1104 | urb->status = -ECOMM; /* Could not write data */ |
| 1105 | break; |
| 1106 | case INT_EXACT: |
| 1107 | dev_dbg(hcd->self.controller, "%s: transaction " |
| 1108 | "error during uFrame %d\n", |
| 1109 | __func__, i); |
| 1110 | urb->status = -EPROTO; /* timeout, bad CRC, PID |
| 1111 | error etc. */ |
| 1112 | break; |
| 1113 | case INT_BABBLE: |
| 1114 | dev_dbg(hcd->self.controller, "%s: babble " |
| 1115 | "error during uFrame %d\n", |
| 1116 | __func__, i); |
| 1117 | urb->status = -EOVERFLOW; |
| 1118 | break; |
| 1119 | } |
| 1120 | dw4 >>= 3; |
| 1121 | } |
| 1122 | |
| 1123 | return PTD_STATE_URB_RETIRE; |
| 1124 | } |
| 1125 | |
| 1126 | return PTD_STATE_QTD_DONE; |
| 1127 | } |
| 1128 | |
| 1129 | static int check_atl_transfer(struct usb_hcd *hcd, struct ptd *ptd, |
| 1130 | struct urb *urb) |
| 1131 | { |
| 1132 | WARN_ON(!ptd); |
| 1133 | if (ptd->dw3 & DW3_HALT_BIT) { |
| 1134 | if (ptd->dw3 & DW3_BABBLE_BIT) |
| 1135 | urb->status = -EOVERFLOW; |
| 1136 | else if (FROM_DW3_CERR(ptd->dw3)) |
| 1137 | urb->status = -EPIPE; /* Stall */ |
| 1138 | else if (ptd->dw3 & DW3_ERROR_BIT) |
| 1139 | urb->status = -EPROTO; /* XactErr */ |
| 1140 | else |
| 1141 | urb->status = -EPROTO; /* Unknown */ |
| 1142 | /* |
| 1143 | dev_dbg(hcd->self.controller, "%s: ptd error:\n" |
| 1144 | " dw0: %08x dw1: %08x dw2: %08x dw3: %08x\n" |
| 1145 | " dw4: %08x dw5: %08x dw6: %08x dw7: %08x\n", |
| 1146 | __func__, |
| 1147 | ptd->dw0, ptd->dw1, ptd->dw2, ptd->dw3, |
| 1148 | ptd->dw4, ptd->dw5, ptd->dw6, ptd->dw7); |
| 1149 | */ |
| 1150 | return PTD_STATE_URB_RETIRE; |
| 1151 | } |
| 1152 | |
| 1153 | if ((ptd->dw3 & DW3_ERROR_BIT) && (ptd->dw3 & DW3_ACTIVE_BIT)) { |
| 1154 | /* Transfer Error, *but* active and no HALT -> reload */ |
| 1155 | dev_dbg(hcd->self.controller, "PID error; reloading ptd\n"); |
| 1156 | return PTD_STATE_QTD_RELOAD; |
| 1157 | } |
| 1158 | |
| 1159 | if (!FROM_DW3_NAKCOUNT(ptd->dw3) && (ptd->dw3 & DW3_ACTIVE_BIT)) { |
| 1160 | /* |
| 1161 | * NAKs are handled in HW by the chip. Usually if the |
| 1162 | * device is not able to send data fast enough. |
| 1163 | * This happens mostly on slower hardware. |
| 1164 | */ |
| 1165 | return PTD_STATE_QTD_RELOAD; |
| 1166 | } |
| 1167 | |
| 1168 | return PTD_STATE_QTD_DONE; |
| 1169 | } |
| 1170 | |
| 1171 | static irqreturn_t isp1760_irq(struct usb_hcd *hcd) |
| 1172 | { |
| 1173 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1174 | u32 imask; |
| 1175 | irqreturn_t irqret = IRQ_NONE; |
| 1176 | struct ptd ptd; |
| 1177 | struct isp1760_qh *qh; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1178 | int slot; |
| 1179 | int state; |
| 1180 | struct slotinfo *slots; |
| 1181 | u32 ptd_offset; |
| 1182 | struct isp1760_qtd *qtd; |
| 1183 | int modified; |
| 1184 | static int last_active_ptds; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1185 | int int_skip_map, atl_skip_map; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1186 | |
| 1187 | spin_lock(&priv->lock); |
| 1188 | |
| 1189 | if (!(hcd->state & HC_STATE_RUNNING)) |
| 1190 | goto leave; |
| 1191 | |
| 1192 | imask = reg_read32(hcd->regs, HC_INTERRUPT_REG); |
| 1193 | if (unlikely(!imask)) |
| 1194 | goto leave; |
| 1195 | reg_write32(hcd->regs, HC_INTERRUPT_REG, imask); /* Clear */ |
| 1196 | |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1197 | int_skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
| 1198 | atl_skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
| 1199 | priv->int_done_map |= reg_read32(hcd->regs, HC_INT_PTD_DONEMAP_REG); |
| 1200 | priv->atl_done_map |= reg_read32(hcd->regs, HC_ATL_PTD_DONEMAP_REG); |
| 1201 | priv->int_done_map &= ~int_skip_map; |
| 1202 | priv->atl_done_map &= ~atl_skip_map; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1203 | |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1204 | modified = priv->int_done_map | priv->atl_done_map; |
| 1205 | |
| 1206 | while (priv->int_done_map || priv->atl_done_map) { |
| 1207 | if (priv->int_done_map) { |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1208 | /* INT ptd */ |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1209 | slot = __ffs(priv->int_done_map); |
| 1210 | priv->int_done_map &= ~(1 << slot); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1211 | slots = priv->int_slots; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1212 | /* This should not trigger, and could be removed if |
| 1213 | noone have any problems with it triggering: */ |
| 1214 | if (!slots[slot].qh) { |
| 1215 | WARN_ON(1); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1216 | continue; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1217 | } |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1218 | ptd_offset = INT_PTD_OFFSET; |
| 1219 | ptd_read(hcd->regs, INT_PTD_OFFSET, slot, &ptd); |
| 1220 | state = check_int_transfer(hcd, &ptd, |
| 1221 | slots[slot].qtd->urb); |
| 1222 | } else { |
| 1223 | /* ATL ptd */ |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1224 | slot = __ffs(priv->atl_done_map); |
| 1225 | priv->atl_done_map &= ~(1 << slot); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1226 | slots = priv->atl_slots; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1227 | /* This should not trigger, and could be removed if |
| 1228 | noone have any problems with it triggering: */ |
| 1229 | if (!slots[slot].qh) { |
| 1230 | WARN_ON(1); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1231 | continue; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1232 | } |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1233 | ptd_offset = ATL_PTD_OFFSET; |
| 1234 | ptd_read(hcd->regs, ATL_PTD_OFFSET, slot, &ptd); |
| 1235 | state = check_atl_transfer(hcd, &ptd, |
| 1236 | slots[slot].qtd->urb); |
| 1237 | } |
| 1238 | |
| 1239 | qtd = slots[slot].qtd; |
| 1240 | slots[slot].qtd = NULL; |
| 1241 | qh = slots[slot].qh; |
| 1242 | slots[slot].qh = NULL; |
| 1243 | priv->active_ptds--; |
| 1244 | qh->slot = -1; |
| 1245 | |
| 1246 | WARN_ON(qtd->status != QTD_XFER_STARTED); |
| 1247 | |
| 1248 | switch (state) { |
| 1249 | case PTD_STATE_QTD_DONE: |
| 1250 | if ((usb_pipeint(qtd->urb->pipe)) && |
| 1251 | (qtd->urb->dev->speed != USB_SPEED_HIGH)) |
| 1252 | qtd->actual_length = |
| 1253 | FROM_DW3_SCS_NRBYTESTRANSFERRED(ptd.dw3); |
| 1254 | else |
| 1255 | qtd->actual_length = |
| 1256 | FROM_DW3_NRBYTESTRANSFERRED(ptd.dw3); |
| 1257 | |
| 1258 | qtd->status = QTD_XFER_COMPLETE; |
| 1259 | if (list_is_last(&qtd->qtd_list, &qh->qtd_list) || |
| 1260 | is_short_bulk(qtd)) |
| 1261 | qtd = NULL; |
| 1262 | else |
| 1263 | qtd = list_entry(qtd->qtd_list.next, |
| 1264 | typeof(*qtd), qtd_list); |
| 1265 | |
| 1266 | qh->toggle = FROM_DW3_DATA_TOGGLE(ptd.dw3); |
| 1267 | qh->ping = FROM_DW3_PING(ptd.dw3); |
| 1268 | break; |
| 1269 | |
| 1270 | case PTD_STATE_QTD_RELOAD: /* QTD_RETRY, for atls only */ |
| 1271 | qtd->status = QTD_PAYLOAD_ALLOC; |
| 1272 | ptd.dw0 |= DW0_VALID_BIT; |
| 1273 | /* RL counter = ERR counter */ |
| 1274 | ptd.dw3 &= ~TO_DW3_NAKCOUNT(0xf); |
| 1275 | ptd.dw3 |= TO_DW3_NAKCOUNT(FROM_DW2_RL(ptd.dw2)); |
| 1276 | ptd.dw3 &= ~TO_DW3_CERR(3); |
| 1277 | ptd.dw3 |= TO_DW3_CERR(ERR_COUNTER); |
| 1278 | qh->toggle = FROM_DW3_DATA_TOGGLE(ptd.dw3); |
| 1279 | qh->ping = FROM_DW3_PING(ptd.dw3); |
| 1280 | break; |
| 1281 | |
| 1282 | case PTD_STATE_URB_RETIRE: |
| 1283 | qtd->status = QTD_RETIRE; |
| 1284 | qtd = NULL; |
| 1285 | qh->toggle = 0; |
| 1286 | qh->ping = 0; |
| 1287 | break; |
| 1288 | |
| 1289 | default: |
| 1290 | WARN_ON(1); |
| 1291 | continue; |
| 1292 | } |
| 1293 | |
| 1294 | if (qtd && (qtd->status == QTD_PAYLOAD_ALLOC)) { |
| 1295 | if (slots == priv->int_slots) { |
| 1296 | if (state == PTD_STATE_QTD_RELOAD) |
| 1297 | dev_err(hcd->self.controller, |
| 1298 | "%s: PTD_STATE_QTD_RELOAD on " |
| 1299 | "interrupt packet\n", __func__); |
| 1300 | if (state != PTD_STATE_QTD_RELOAD) |
| 1301 | create_ptd_int(qh, qtd, &ptd); |
| 1302 | } else { |
| 1303 | if (state != PTD_STATE_QTD_RELOAD) |
| 1304 | create_ptd_atl(qh, qtd, &ptd); |
| 1305 | } |
| 1306 | |
| 1307 | start_bus_transfer(hcd, ptd_offset, slot, slots, qtd, |
| 1308 | qh, &ptd); |
| 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | if (modified) |
| 1313 | schedule_ptds(hcd); |
| 1314 | |
| 1315 | /* ISP1760 Errata 2 explains that interrupts may be missed (or not |
| 1316 | happen?) if two USB devices are running simultaneously. Perhaps |
| 1317 | this happens when a PTD is finished during interrupt handling; |
| 1318 | enable SOF interrupts if PTDs are still scheduled when exiting this |
| 1319 | interrupt handler, just to be safe. */ |
| 1320 | |
| 1321 | if (priv->active_ptds != last_active_ptds) { |
| 1322 | if (priv->active_ptds > 0) |
| 1323 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, |
| 1324 | INTERRUPT_ENABLE_SOT_MASK); |
| 1325 | else |
| 1326 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, |
| 1327 | INTERRUPT_ENABLE_MASK); |
| 1328 | last_active_ptds = priv->active_ptds; |
| 1329 | } |
| 1330 | |
| 1331 | irqret = IRQ_HANDLED; |
| 1332 | leave: |
| 1333 | spin_unlock(&priv->lock); |
| 1334 | |
| 1335 | return irqret; |
| 1336 | } |
| 1337 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1338 | 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] | 1339 | { |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1340 | qtd->data_buffer = databuffer; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1341 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1342 | if (len > MAX_PAYLOAD_SIZE) |
| 1343 | len = MAX_PAYLOAD_SIZE; |
| 1344 | qtd->length = len; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1345 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1346 | return qtd->length; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1347 | } |
| 1348 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1349 | static void qtd_list_free(struct list_head *qtd_list) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1350 | { |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1351 | struct isp1760_qtd *qtd, *qtd_next; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1352 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1353 | list_for_each_entry_safe(qtd, qtd_next, qtd_list, qtd_list) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1354 | list_del(&qtd->qtd_list); |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1355 | qtd_free(qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1359 | /* |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1360 | * Packetize urb->transfer_buffer into list of packets of size wMaxPacketSize. |
| 1361 | * Also calculate the PID type (SETUP/IN/OUT) for each packet. |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1362 | */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1363 | #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff) |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1364 | static void packetize_urb(struct usb_hcd *hcd, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1365 | struct urb *urb, struct list_head *head, gfp_t flags) |
| 1366 | { |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1367 | struct isp1760_qtd *qtd; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1368 | void *buf; |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1369 | int len, maxpacketsize; |
| 1370 | u8 packet_type; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1371 | |
| 1372 | /* |
| 1373 | * URBs map to sequences of QTDs: one logical transaction |
| 1374 | */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1375 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1376 | if (!urb->transfer_buffer && urb->transfer_buffer_length) { |
| 1377 | /* XXX This looks like usb storage / SCSI bug */ |
| 1378 | dev_err(hcd->self.controller, |
| 1379 | "buf is null, dma is %08lx len is %d\n", |
| 1380 | (long unsigned)urb->transfer_dma, |
| 1381 | urb->transfer_buffer_length); |
| 1382 | WARN_ON(1); |
| 1383 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1384 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1385 | if (usb_pipein(urb->pipe)) |
| 1386 | packet_type = IN_PID; |
| 1387 | else |
| 1388 | packet_type = OUT_PID; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1389 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1390 | if (usb_pipecontrol(urb->pipe)) { |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1391 | qtd = qtd_alloc(flags, urb, SETUP_PID); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1392 | if (!qtd) |
| 1393 | goto cleanup; |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1394 | qtd_fill(qtd, urb->setup_packet, sizeof(struct usb_ctrlrequest)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1395 | list_add_tail(&qtd->qtd_list, head); |
| 1396 | |
| 1397 | /* for zero length DATA stages, STATUS is always IN */ |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1398 | if (urb->transfer_buffer_length == 0) |
| 1399 | packet_type = IN_PID; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1400 | } |
| 1401 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1402 | maxpacketsize = max_packet(usb_maxpacket(urb->dev, urb->pipe, |
| 1403 | usb_pipeout(urb->pipe))); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1404 | |
| 1405 | /* |
| 1406 | * buffer gets wrapped in one or more qtds; |
| 1407 | * last one may be "short" (including zero len) |
| 1408 | * and may serve as a control status ack |
| 1409 | */ |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1410 | buf = urb->transfer_buffer; |
| 1411 | len = urb->transfer_buffer_length; |
| 1412 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1413 | for (;;) { |
| 1414 | int this_qtd_len; |
| 1415 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1416 | qtd = qtd_alloc(flags, urb, packet_type); |
| 1417 | if (!qtd) |
| 1418 | goto cleanup; |
| 1419 | this_qtd_len = qtd_fill(qtd, buf, len); |
| 1420 | list_add_tail(&qtd->qtd_list, head); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1421 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1422 | len -= this_qtd_len; |
| 1423 | buf += this_qtd_len; |
| 1424 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1425 | if (len <= 0) |
| 1426 | break; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | /* |
| 1430 | * control requests may need a terminating data "status" ack; |
| 1431 | * bulk ones may need a terminating short packet (zero length). |
| 1432 | */ |
| 1433 | if (urb->transfer_buffer_length != 0) { |
| 1434 | int one_more = 0; |
| 1435 | |
| 1436 | if (usb_pipecontrol(urb->pipe)) { |
| 1437 | one_more = 1; |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1438 | if (packet_type == IN_PID) |
| 1439 | packet_type = OUT_PID; |
| 1440 | else |
| 1441 | packet_type = IN_PID; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1442 | } else if (usb_pipebulk(urb->pipe) |
| 1443 | && (urb->transfer_flags & URB_ZERO_PACKET) |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1444 | && !(urb->transfer_buffer_length % |
| 1445 | maxpacketsize)) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1446 | one_more = 1; |
| 1447 | } |
| 1448 | if (one_more) { |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1449 | qtd = qtd_alloc(flags, urb, packet_type); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1450 | if (!qtd) |
| 1451 | goto cleanup; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1452 | |
| 1453 | /* never any data in such packets */ |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1454 | qtd_fill(qtd, NULL, 0); |
| 1455 | list_add_tail(&qtd->qtd_list, head); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1456 | } |
| 1457 | } |
| 1458 | |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1459 | return; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1460 | |
| 1461 | cleanup: |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1462 | qtd_list_free(head); |
| 1463 | } |
| 1464 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1465 | static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, |
| 1466 | gfp_t mem_flags) |
| 1467 | { |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1468 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1469 | struct list_head *ep_queue; |
| 1470 | struct isp1760_qh *qh, *qhit; |
| 1471 | unsigned long spinflags; |
| 1472 | LIST_HEAD(new_qtds); |
| 1473 | int retval; |
| 1474 | int qh_in_queue; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1475 | |
| 1476 | switch (usb_pipetype(urb->pipe)) { |
| 1477 | case PIPE_CONTROL: |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1478 | ep_queue = &priv->controlqhs; |
| 1479 | break; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1480 | case PIPE_BULK: |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1481 | ep_queue = &priv->bulkqhs; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1482 | break; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1483 | case PIPE_INTERRUPT: |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1484 | if (urb->interval < 0) |
| 1485 | return -EINVAL; |
| 1486 | /* FIXME: Check bandwidth */ |
| 1487 | ep_queue = &priv->interruptqhs; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1488 | break; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1489 | case PIPE_ISOCHRONOUS: |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1490 | dev_err(hcd->self.controller, "%s: isochronous USB packets " |
| 1491 | "not yet supported\n", |
| 1492 | __func__); |
| 1493 | return -EPIPE; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1494 | default: |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1495 | dev_err(hcd->self.controller, "%s: unknown pipe type\n", |
| 1496 | __func__); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1497 | return -EPIPE; |
| 1498 | } |
| 1499 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1500 | if (usb_pipein(urb->pipe)) |
| 1501 | urb->actual_length = 0; |
| 1502 | |
| 1503 | packetize_urb(hcd, urb, &new_qtds, mem_flags); |
| 1504 | if (list_empty(&new_qtds)) |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1505 | return -ENOMEM; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1506 | urb->hcpriv = NULL; /* Used to signal unlink to interrupt handler */ |
Arvid Brodin | 3453773 | 2011-04-26 21:47:37 +0200 | [diff] [blame] | 1507 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1508 | retval = 0; |
| 1509 | spin_lock_irqsave(&priv->lock, spinflags); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1510 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1511 | if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { |
| 1512 | retval = -ESHUTDOWN; |
| 1513 | goto out; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1514 | } |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1515 | retval = usb_hcd_link_urb_to_ep(hcd, urb); |
| 1516 | if (retval) |
| 1517 | goto out; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1518 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1519 | qh = urb->ep->hcpriv; |
| 1520 | if (qh) { |
| 1521 | qh_in_queue = 0; |
| 1522 | list_for_each_entry(qhit, ep_queue, qh_list) { |
| 1523 | if (qhit == qh) { |
| 1524 | qh_in_queue = 1; |
Warren Free | 0afb20e | 2009-05-08 10:27:08 +0200 | [diff] [blame] | 1525 | break; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1526 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1527 | } |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1528 | if (!qh_in_queue) |
| 1529 | list_add_tail(&qh->qh_list, ep_queue); |
| 1530 | } else { |
| 1531 | qh = qh_alloc(GFP_ATOMIC); |
| 1532 | if (!qh) { |
| 1533 | retval = -ENOMEM; |
| 1534 | goto out; |
| 1535 | } |
| 1536 | list_add_tail(&qh->qh_list, ep_queue); |
| 1537 | urb->ep->hcpriv = qh; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1538 | } |
| 1539 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1540 | list_splice_tail(&new_qtds, &qh->qtd_list); |
| 1541 | schedule_ptds(hcd); |
| 1542 | |
| 1543 | out: |
| 1544 | spin_unlock_irqrestore(&priv->lock, spinflags); |
| 1545 | return retval; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1546 | } |
| 1547 | |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1548 | static void kill_transfer(struct usb_hcd *hcd, struct urb *urb, |
| 1549 | struct isp1760_qh *qh) |
| 1550 | { |
| 1551 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1552 | int skip_map; |
| 1553 | |
| 1554 | WARN_ON(qh->slot == -1); |
| 1555 | |
| 1556 | /* We need to forcefully reclaim the slot since some transfers never |
| 1557 | return, e.g. interrupt transfers and NAKed bulk transfers. */ |
| 1558 | if (usb_pipebulk(urb->pipe)) { |
| 1559 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
| 1560 | skip_map |= (1 << qh->slot); |
| 1561 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map); |
| 1562 | priv->atl_slots[qh->slot].qh = NULL; |
| 1563 | priv->atl_slots[qh->slot].qtd = NULL; |
| 1564 | } else { |
| 1565 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
| 1566 | skip_map |= (1 << qh->slot); |
| 1567 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map); |
| 1568 | priv->int_slots[qh->slot].qh = NULL; |
| 1569 | priv->int_slots[qh->slot].qtd = NULL; |
| 1570 | } |
| 1571 | |
| 1572 | qh->slot = -1; |
| 1573 | priv->active_ptds--; |
| 1574 | } |
| 1575 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1576 | static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, |
| 1577 | int status) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1578 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1579 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1580 | unsigned long spinflags; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1581 | struct isp1760_qh *qh; |
| 1582 | struct isp1760_qtd *qtd; |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1583 | int retval = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1584 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1585 | spin_lock_irqsave(&priv->lock, spinflags); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1586 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1587 | qh = urb->ep->hcpriv; |
| 1588 | if (!qh) { |
| 1589 | retval = -EINVAL; |
| 1590 | goto out; |
| 1591 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1592 | |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1593 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list) |
| 1594 | if (qtd->urb == urb) { |
| 1595 | if (qtd->status == QTD_XFER_STARTED) |
| 1596 | kill_transfer(hcd, urb, qh); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1597 | qtd->status = QTD_RETIRE; |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1598 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1599 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1600 | urb->status = status; |
| 1601 | schedule_ptds(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1602 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1603 | out: |
| 1604 | spin_unlock_irqrestore(&priv->lock, spinflags); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1605 | return retval; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1606 | } |
| 1607 | |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1608 | static void isp1760_endpoint_disable(struct usb_hcd *hcd, |
| 1609 | struct usb_host_endpoint *ep) |
| 1610 | { |
| 1611 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1612 | unsigned long spinflags; |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1613 | struct isp1760_qh *qh; |
| 1614 | struct isp1760_qtd *qtd; |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1615 | |
| 1616 | spin_lock_irqsave(&priv->lock, spinflags); |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1617 | |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1618 | qh = ep->hcpriv; |
| 1619 | if (!qh) |
| 1620 | goto out; |
| 1621 | |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1622 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list) { |
| 1623 | if (qtd->status == QTD_XFER_STARTED) |
| 1624 | kill_transfer(hcd, qtd->urb, qh); |
| 1625 | qtd->status = QTD_RETIRE; |
| 1626 | qtd->urb->status = -ECONNRESET; |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1627 | } |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1628 | |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1629 | ep->hcpriv = NULL; |
| 1630 | /* Cannot free qh here since it will be parsed by schedule_ptds() */ |
| 1631 | |
Arvid Brodin | d05b6ec | 2011-05-20 00:17:45 +0200 | [diff] [blame] | 1632 | schedule_ptds(hcd); |
| 1633 | |
Arvid Brodin | 079cdb0 | 2011-05-20 00:17:34 +0200 | [diff] [blame] | 1634 | out: |
| 1635 | spin_unlock_irqrestore(&priv->lock, spinflags); |
| 1636 | } |
| 1637 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1638 | static int isp1760_hub_status_data(struct usb_hcd *hcd, char *buf) |
| 1639 | { |
| 1640 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1641 | u32 temp, status = 0; |
| 1642 | u32 mask; |
| 1643 | int retval = 1; |
| 1644 | unsigned long flags; |
| 1645 | |
| 1646 | /* if !USB_SUSPEND, root hub timers won't get shut down ... */ |
| 1647 | if (!HC_IS_RUNNING(hcd->state)) |
| 1648 | return 0; |
| 1649 | |
| 1650 | /* init status to no-changes */ |
| 1651 | buf[0] = 0; |
| 1652 | mask = PORT_CSC; |
| 1653 | |
| 1654 | spin_lock_irqsave(&priv->lock, flags); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1655 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1656 | |
| 1657 | if (temp & PORT_OWNER) { |
| 1658 | if (temp & PORT_CSC) { |
| 1659 | temp &= ~PORT_CSC; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1660 | reg_write32(hcd->regs, HC_PORTSC1, temp); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1661 | goto done; |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | /* |
| 1666 | * Return status information even for ports with OWNER set. |
| 1667 | * Otherwise khubd wouldn't see the disconnect event when a |
| 1668 | * high-speed device is switched over to the companion |
| 1669 | * controller by the user. |
| 1670 | */ |
| 1671 | |
| 1672 | if ((temp & mask) != 0 |
| 1673 | || ((temp & PORT_RESUME) != 0 |
| 1674 | && time_after_eq(jiffies, |
| 1675 | priv->reset_done))) { |
| 1676 | buf [0] |= 1 << (0 + 1); |
| 1677 | status = STS_PCD; |
| 1678 | } |
| 1679 | /* FIXME autosuspend idle root hubs */ |
| 1680 | done: |
| 1681 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1682 | return status ? retval : 0; |
| 1683 | } |
| 1684 | |
| 1685 | static void isp1760_hub_descriptor(struct isp1760_hcd *priv, |
| 1686 | struct usb_hub_descriptor *desc) |
| 1687 | { |
| 1688 | int ports = HCS_N_PORTS(priv->hcs_params); |
| 1689 | u16 temp; |
| 1690 | |
| 1691 | desc->bDescriptorType = 0x29; |
| 1692 | /* priv 1.0, 2.3.9 says 20ms max */ |
| 1693 | desc->bPwrOn2PwrGood = 10; |
| 1694 | desc->bHubContrCurrent = 0; |
| 1695 | |
| 1696 | desc->bNbrPorts = ports; |
| 1697 | temp = 1 + (ports / 8); |
| 1698 | desc->bDescLength = 7 + 2 * temp; |
| 1699 | |
Sarah Sharp | da13051 | 2010-11-30 15:55:51 -0800 | [diff] [blame] | 1700 | /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */ |
John Youn | dbe79bb | 2001-09-17 00:00:00 -0700 | [diff] [blame] | 1701 | memset(&desc->u.hs.DeviceRemovable[0], 0, temp); |
| 1702 | memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1703 | |
| 1704 | /* per-port overcurrent reporting */ |
| 1705 | temp = 0x0008; |
| 1706 | if (HCS_PPC(priv->hcs_params)) |
| 1707 | /* per-port power control */ |
| 1708 | temp |= 0x0001; |
| 1709 | else |
| 1710 | /* no power switching */ |
| 1711 | temp |= 0x0002; |
| 1712 | desc->wHubCharacteristics = cpu_to_le16(temp); |
| 1713 | } |
| 1714 | |
| 1715 | #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) |
| 1716 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1717 | static int check_reset_complete(struct usb_hcd *hcd, int index, |
| 1718 | int port_status) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1719 | { |
| 1720 | if (!(port_status & PORT_CONNECT)) |
| 1721 | return port_status; |
| 1722 | |
| 1723 | /* if reset finished and it's still not enabled -- handoff */ |
| 1724 | if (!(port_status & PORT_PE)) { |
| 1725 | |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1726 | dev_info(hcd->self.controller, |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1727 | "port %d full speed --> companion\n", |
| 1728 | index + 1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1729 | |
| 1730 | port_status |= PORT_OWNER; |
| 1731 | port_status &= ~PORT_RWC_BITS; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1732 | reg_write32(hcd->regs, HC_PORTSC1, port_status); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1733 | |
| 1734 | } else |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 1735 | dev_info(hcd->self.controller, "port %d high speed\n", |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1736 | index + 1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1737 | |
| 1738 | return port_status; |
| 1739 | } |
| 1740 | |
| 1741 | static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, |
| 1742 | u16 wValue, u16 wIndex, char *buf, u16 wLength) |
| 1743 | { |
| 1744 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1745 | int ports = HCS_N_PORTS(priv->hcs_params); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1746 | u32 temp, status; |
| 1747 | unsigned long flags; |
| 1748 | int retval = 0; |
| 1749 | unsigned selector; |
| 1750 | |
| 1751 | /* |
| 1752 | * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR. |
| 1753 | * HCS_INDICATOR may say we can change LEDs to off/amber/green. |
| 1754 | * (track current state ourselves) ... blink for diagnostics, |
| 1755 | * power, "this is the one", etc. EHCI spec supports this. |
| 1756 | */ |
| 1757 | |
| 1758 | spin_lock_irqsave(&priv->lock, flags); |
| 1759 | switch (typeReq) { |
| 1760 | case ClearHubFeature: |
| 1761 | switch (wValue) { |
| 1762 | case C_HUB_LOCAL_POWER: |
| 1763 | case C_HUB_OVER_CURRENT: |
| 1764 | /* no hub-wide feature/status flags */ |
| 1765 | break; |
| 1766 | default: |
| 1767 | goto error; |
| 1768 | } |
| 1769 | break; |
| 1770 | case ClearPortFeature: |
| 1771 | if (!wIndex || wIndex > ports) |
| 1772 | goto error; |
| 1773 | wIndex--; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1774 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1775 | |
| 1776 | /* |
| 1777 | * Even if OWNER is set, so the port is owned by the |
| 1778 | * companion controller, khubd needs to be able to clear |
| 1779 | * the port-change status bits (especially |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1780 | * USB_PORT_STAT_C_CONNECTION). |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1781 | */ |
| 1782 | |
| 1783 | switch (wValue) { |
| 1784 | case USB_PORT_FEAT_ENABLE: |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1785 | reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_PE); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1786 | break; |
| 1787 | case USB_PORT_FEAT_C_ENABLE: |
| 1788 | /* XXX error? */ |
| 1789 | break; |
| 1790 | case USB_PORT_FEAT_SUSPEND: |
| 1791 | if (temp & PORT_RESET) |
| 1792 | goto error; |
| 1793 | |
| 1794 | if (temp & PORT_SUSPEND) { |
| 1795 | if ((temp & PORT_PE) == 0) |
| 1796 | goto error; |
| 1797 | /* resume signaling for 20 msec */ |
| 1798 | temp &= ~(PORT_RWC_BITS); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1799 | reg_write32(hcd->regs, HC_PORTSC1, |
| 1800 | temp | PORT_RESUME); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1801 | priv->reset_done = jiffies + |
| 1802 | msecs_to_jiffies(20); |
| 1803 | } |
| 1804 | break; |
| 1805 | case USB_PORT_FEAT_C_SUSPEND: |
| 1806 | /* we auto-clear this feature */ |
| 1807 | break; |
| 1808 | case USB_PORT_FEAT_POWER: |
| 1809 | if (HCS_PPC(priv->hcs_params)) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1810 | reg_write32(hcd->regs, HC_PORTSC1, |
| 1811 | temp & ~PORT_POWER); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1812 | break; |
| 1813 | case USB_PORT_FEAT_C_CONNECTION: |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1814 | reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_CSC); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1815 | break; |
| 1816 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 1817 | /* XXX error ?*/ |
| 1818 | break; |
| 1819 | case USB_PORT_FEAT_C_RESET: |
| 1820 | /* GetPortStatus clears reset */ |
| 1821 | break; |
| 1822 | default: |
| 1823 | goto error; |
| 1824 | } |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1825 | reg_read32(hcd->regs, HC_USBCMD); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1826 | break; |
| 1827 | case GetHubDescriptor: |
| 1828 | isp1760_hub_descriptor(priv, (struct usb_hub_descriptor *) |
| 1829 | buf); |
| 1830 | break; |
| 1831 | case GetHubStatus: |
| 1832 | /* no hub-wide feature/status flags */ |
| 1833 | memset(buf, 0, 4); |
| 1834 | break; |
| 1835 | case GetPortStatus: |
| 1836 | if (!wIndex || wIndex > ports) |
| 1837 | goto error; |
| 1838 | wIndex--; |
| 1839 | status = 0; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1840 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1841 | |
| 1842 | /* wPortChange bits */ |
| 1843 | if (temp & PORT_CSC) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1844 | status |= USB_PORT_STAT_C_CONNECTION << 16; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1845 | |
| 1846 | |
| 1847 | /* whoever resumes must GetPortStatus to complete it!! */ |
| 1848 | if (temp & PORT_RESUME) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1849 | dev_err(hcd->self.controller, "Port resume should be skipped.\n"); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1850 | |
| 1851 | /* Remote Wakeup received? */ |
| 1852 | if (!priv->reset_done) { |
| 1853 | /* resume signaling for 20 msec */ |
| 1854 | priv->reset_done = jiffies |
| 1855 | + msecs_to_jiffies(20); |
| 1856 | /* check the port again */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1857 | mod_timer(&hcd->rh_timer, priv->reset_done); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | /* resume completed? */ |
| 1861 | else if (time_after_eq(jiffies, |
| 1862 | priv->reset_done)) { |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1863 | status |= USB_PORT_STAT_C_SUSPEND << 16; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1864 | priv->reset_done = 0; |
| 1865 | |
| 1866 | /* stop resume signaling */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1867 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
| 1868 | reg_write32(hcd->regs, HC_PORTSC1, |
| 1869 | temp & ~(PORT_RWC_BITS | PORT_RESUME)); |
| 1870 | retval = handshake(hcd, HC_PORTSC1, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1871 | PORT_RESUME, 0, 2000 /* 2msec */); |
| 1872 | if (retval != 0) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1873 | dev_err(hcd->self.controller, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1874 | "port %d resume error %d\n", |
| 1875 | wIndex + 1, retval); |
| 1876 | goto error; |
| 1877 | } |
| 1878 | temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10)); |
| 1879 | } |
| 1880 | } |
| 1881 | |
| 1882 | /* whoever resets must GetPortStatus to complete it!! */ |
| 1883 | if ((temp & PORT_RESET) |
| 1884 | && time_after_eq(jiffies, |
| 1885 | priv->reset_done)) { |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1886 | status |= USB_PORT_STAT_C_RESET << 16; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1887 | priv->reset_done = 0; |
| 1888 | |
| 1889 | /* force reset to complete */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1890 | reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_RESET); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1891 | /* REVISIT: some hardware needs 550+ usec to clear |
| 1892 | * this bit; seems too long to spin routinely... |
| 1893 | */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1894 | retval = handshake(hcd, HC_PORTSC1, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1895 | PORT_RESET, 0, 750); |
| 1896 | if (retval != 0) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1897 | dev_err(hcd->self.controller, "port %d reset error %d\n", |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1898 | wIndex + 1, retval); |
| 1899 | goto error; |
| 1900 | } |
| 1901 | |
| 1902 | /* see what we found out */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1903 | temp = check_reset_complete(hcd, wIndex, |
| 1904 | reg_read32(hcd->regs, HC_PORTSC1)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1905 | } |
| 1906 | /* |
| 1907 | * Even if OWNER is set, there's no harm letting khubd |
| 1908 | * see the wPortStatus values (they should all be 0 except |
| 1909 | * for PORT_POWER anyway). |
| 1910 | */ |
| 1911 | |
| 1912 | if (temp & PORT_OWNER) |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1913 | dev_err(hcd->self.controller, "PORT_OWNER is set\n"); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1914 | |
| 1915 | if (temp & PORT_CONNECT) { |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1916 | status |= USB_PORT_STAT_CONNECTION; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1917 | /* status may be from integrated TT */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1918 | status |= USB_PORT_STAT_HIGH_SPEED; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1919 | } |
| 1920 | if (temp & PORT_PE) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1921 | status |= USB_PORT_STAT_ENABLE; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1922 | if (temp & (PORT_SUSPEND|PORT_RESUME)) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1923 | status |= USB_PORT_STAT_SUSPEND; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1924 | if (temp & PORT_RESET) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1925 | status |= USB_PORT_STAT_RESET; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1926 | if (temp & PORT_POWER) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1927 | status |= USB_PORT_STAT_POWER; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1928 | |
| 1929 | put_unaligned(cpu_to_le32(status), (__le32 *) buf); |
| 1930 | break; |
| 1931 | case SetHubFeature: |
| 1932 | switch (wValue) { |
| 1933 | case C_HUB_LOCAL_POWER: |
| 1934 | case C_HUB_OVER_CURRENT: |
| 1935 | /* no hub-wide feature/status flags */ |
| 1936 | break; |
| 1937 | default: |
| 1938 | goto error; |
| 1939 | } |
| 1940 | break; |
| 1941 | case SetPortFeature: |
| 1942 | selector = wIndex >> 8; |
| 1943 | wIndex &= 0xff; |
| 1944 | if (!wIndex || wIndex > ports) |
| 1945 | goto error; |
| 1946 | wIndex--; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1947 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1948 | if (temp & PORT_OWNER) |
| 1949 | break; |
| 1950 | |
| 1951 | /* temp &= ~PORT_RWC_BITS; */ |
| 1952 | switch (wValue) { |
| 1953 | case USB_PORT_FEAT_ENABLE: |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1954 | reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_PE); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1955 | break; |
| 1956 | |
| 1957 | case USB_PORT_FEAT_SUSPEND: |
| 1958 | if ((temp & PORT_PE) == 0 |
| 1959 | || (temp & PORT_RESET) != 0) |
| 1960 | goto error; |
| 1961 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1962 | reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_SUSPEND); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1963 | break; |
| 1964 | case USB_PORT_FEAT_POWER: |
| 1965 | if (HCS_PPC(priv->hcs_params)) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1966 | reg_write32(hcd->regs, HC_PORTSC1, |
| 1967 | temp | PORT_POWER); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1968 | break; |
| 1969 | case USB_PORT_FEAT_RESET: |
| 1970 | if (temp & PORT_RESUME) |
| 1971 | goto error; |
| 1972 | /* line status bits may report this as low speed, |
| 1973 | * which can be fine if this root hub has a |
| 1974 | * transaction translator built in. |
| 1975 | */ |
| 1976 | if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT |
| 1977 | && PORT_USB11(temp)) { |
| 1978 | temp |= PORT_OWNER; |
| 1979 | } else { |
| 1980 | temp |= PORT_RESET; |
| 1981 | temp &= ~PORT_PE; |
| 1982 | |
| 1983 | /* |
| 1984 | * caller must wait, then call GetPortStatus |
| 1985 | * usb 2.0 spec says 50 ms resets on root |
| 1986 | */ |
| 1987 | priv->reset_done = jiffies + |
| 1988 | msecs_to_jiffies(50); |
| 1989 | } |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1990 | reg_write32(hcd->regs, HC_PORTSC1, temp); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1991 | break; |
| 1992 | default: |
| 1993 | goto error; |
| 1994 | } |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1995 | reg_read32(hcd->regs, HC_USBCMD); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1996 | break; |
| 1997 | |
| 1998 | default: |
| 1999 | error: |
| 2000 | /* "stall" on error */ |
| 2001 | retval = -EPIPE; |
| 2002 | } |
| 2003 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2004 | return retval; |
| 2005 | } |
| 2006 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2007 | static int isp1760_get_frame(struct usb_hcd *hcd) |
| 2008 | { |
| 2009 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 2010 | u32 fr; |
| 2011 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2012 | fr = reg_read32(hcd->regs, HC_FRINDEX); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2013 | return (fr >> 3) % priv->periodic_size; |
| 2014 | } |
| 2015 | |
| 2016 | static void isp1760_stop(struct usb_hcd *hcd) |
| 2017 | { |
| 2018 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 2019 | u32 temp; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2020 | |
| 2021 | isp1760_hub_control(hcd, ClearPortFeature, USB_PORT_FEAT_POWER, 1, |
| 2022 | NULL, 0); |
| 2023 | mdelay(20); |
| 2024 | |
| 2025 | spin_lock_irq(&priv->lock); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 2026 | ehci_reset(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2027 | /* Disable IRQ */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2028 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); |
| 2029 | 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] | 2030 | spin_unlock_irq(&priv->lock); |
| 2031 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2032 | reg_write32(hcd->regs, HC_CONFIGFLAG, 0); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | static void isp1760_shutdown(struct usb_hcd *hcd) |
| 2036 | { |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 2037 | u32 command, temp; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2038 | |
| 2039 | isp1760_stop(hcd); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2040 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); |
| 2041 | 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] | 2042 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2043 | command = reg_read32(hcd->regs, HC_USBCMD); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2044 | command &= ~CMD_RUN; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2045 | reg_write32(hcd->regs, HC_USBCMD, command); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | static const struct hc_driver isp1760_hc_driver = { |
| 2049 | .description = "isp1760-hcd", |
| 2050 | .product_desc = "NXP ISP1760 USB Host Controller", |
| 2051 | .hcd_priv_size = sizeof(struct isp1760_hcd), |
| 2052 | .irq = isp1760_irq, |
| 2053 | .flags = HCD_MEMORY | HCD_USB2, |
| 2054 | .reset = isp1760_hc_setup, |
| 2055 | .start = isp1760_run, |
| 2056 | .stop = isp1760_stop, |
| 2057 | .shutdown = isp1760_shutdown, |
| 2058 | .urb_enqueue = isp1760_urb_enqueue, |
| 2059 | .urb_dequeue = isp1760_urb_dequeue, |
| 2060 | .endpoint_disable = isp1760_endpoint_disable, |
| 2061 | .get_frame_number = isp1760_get_frame, |
| 2062 | .hub_status_data = isp1760_hub_status_data, |
| 2063 | .hub_control = isp1760_hub_control, |
| 2064 | }; |
| 2065 | |
| 2066 | int __init init_kmem_once(void) |
| 2067 | { |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 2068 | urb_listitem_cachep = kmem_cache_create("isp1760 urb_listitem", |
| 2069 | sizeof(struct urb_listitem), 0, SLAB_TEMPORARY | |
| 2070 | SLAB_MEM_SPREAD, NULL); |
| 2071 | |
| 2072 | if (!urb_listitem_cachep) |
| 2073 | return -ENOMEM; |
| 2074 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2075 | qtd_cachep = kmem_cache_create("isp1760_qtd", |
| 2076 | sizeof(struct isp1760_qtd), 0, SLAB_TEMPORARY | |
| 2077 | SLAB_MEM_SPREAD, NULL); |
| 2078 | |
| 2079 | if (!qtd_cachep) |
| 2080 | return -ENOMEM; |
| 2081 | |
| 2082 | qh_cachep = kmem_cache_create("isp1760_qh", sizeof(struct isp1760_qh), |
| 2083 | 0, SLAB_TEMPORARY | SLAB_MEM_SPREAD, NULL); |
| 2084 | |
| 2085 | if (!qh_cachep) { |
| 2086 | kmem_cache_destroy(qtd_cachep); |
| 2087 | return -ENOMEM; |
| 2088 | } |
| 2089 | |
| 2090 | return 0; |
| 2091 | } |
| 2092 | |
| 2093 | void deinit_kmem_cache(void) |
| 2094 | { |
| 2095 | kmem_cache_destroy(qtd_cachep); |
| 2096 | kmem_cache_destroy(qh_cachep); |
Arvid Brodin | 71a9f9d | 2011-04-26 21:48:30 +0200 | [diff] [blame] | 2097 | kmem_cache_destroy(urb_listitem_cachep); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2098 | } |
| 2099 | |
Catalin Marinas | f9031f2 | 2009-02-10 16:55:45 +0000 | [diff] [blame] | 2100 | struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len, |
| 2101 | int irq, unsigned long irqflags, |
| 2102 | struct device *dev, const char *busname, |
| 2103 | unsigned int devflags) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2104 | { |
| 2105 | struct usb_hcd *hcd; |
| 2106 | struct isp1760_hcd *priv; |
| 2107 | int ret; |
| 2108 | |
| 2109 | if (usb_disabled()) |
| 2110 | return ERR_PTR(-ENODEV); |
| 2111 | |
| 2112 | /* prevent usb-core allocating DMA pages */ |
| 2113 | dev->dma_mask = NULL; |
| 2114 | |
Kay Sievers | 0031a06 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 2115 | hcd = usb_create_hcd(&isp1760_hc_driver, dev, dev_name(dev)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2116 | if (!hcd) |
| 2117 | return ERR_PTR(-ENOMEM); |
| 2118 | |
| 2119 | priv = hcd_to_priv(hcd); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 2120 | priv->devflags = devflags; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2121 | init_memory(priv); |
| 2122 | hcd->regs = ioremap(res_start, res_len); |
| 2123 | if (!hcd->regs) { |
| 2124 | ret = -EIO; |
| 2125 | goto err_put; |
| 2126 | } |
| 2127 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2128 | hcd->irq = irq; |
| 2129 | hcd->rsrc_start = res_start; |
| 2130 | hcd->rsrc_len = res_len; |
| 2131 | |
Nate Case | e6942d6 | 2008-05-21 16:28:20 -0500 | [diff] [blame] | 2132 | ret = usb_add_hcd(hcd, irq, irqflags); |
| 2133 | if (ret) |
| 2134 | goto err_unmap; |
| 2135 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2136 | return hcd; |
| 2137 | |
| 2138 | err_unmap: |
| 2139 | iounmap(hcd->regs); |
| 2140 | |
| 2141 | err_put: |
| 2142 | usb_put_hcd(hcd); |
| 2143 | |
| 2144 | return ERR_PTR(ret); |
| 2145 | } |
| 2146 | |
| 2147 | MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP"); |
| 2148 | MODULE_AUTHOR("Sebastian Siewior <bigeasy@linuxtronix.de>"); |
| 2149 | MODULE_LICENSE("GPL v2"); |