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 | * |
| 11 | */ |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/list.h> |
| 16 | #include <linux/usb.h> |
Eric Lescouet | 27729aa | 2010-04-24 23:21:52 +0200 | [diff] [blame] | 17 | #include <linux/usb/hcd.h> |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 18 | #include <linux/debugfs.h> |
| 19 | #include <linux/uaccess.h> |
| 20 | #include <linux/io.h> |
Catalin Marinas | db8516f | 2010-02-02 15:31:02 +0000 | [diff] [blame] | 21 | #include <linux/mm.h> |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 22 | #include <asm/unaligned.h> |
Catalin Marinas | db8516f | 2010-02-02 15:31:02 +0000 | [diff] [blame] | 23 | #include <asm/cacheflush.h> |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 24 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 25 | #include "isp1760-hcd.h" |
| 26 | |
| 27 | static struct kmem_cache *qtd_cachep; |
| 28 | static struct kmem_cache *qh_cachep; |
| 29 | |
| 30 | struct isp1760_hcd { |
| 31 | u32 hcs_params; |
| 32 | spinlock_t lock; |
| 33 | struct inter_packet_info atl_ints[32]; |
| 34 | struct inter_packet_info int_ints[32]; |
| 35 | struct memory_chunk memory_pool[BLOCKS]; |
Sebastian Andrzej Siewior | b14e840 | 2011-02-08 21:07:40 +0100 | [diff] [blame] | 36 | u32 atl_queued; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 37 | |
| 38 | /* periodic schedule support */ |
| 39 | #define DEFAULT_I_TDPS 1024 |
| 40 | unsigned periodic_size; |
| 41 | unsigned i_thresh; |
| 42 | unsigned long reset_done; |
| 43 | unsigned long next_statechange; |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 44 | unsigned int devflags; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | static inline struct isp1760_hcd *hcd_to_priv(struct usb_hcd *hcd) |
| 48 | { |
| 49 | return (struct isp1760_hcd *) (hcd->hcd_priv); |
| 50 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 51 | |
| 52 | /* Section 2.2 Host Controller Capability Registers */ |
| 53 | #define HC_LENGTH(p) (((p)>>00)&0x00ff) /* bits 7:0 */ |
| 54 | #define HC_VERSION(p) (((p)>>16)&0xffff) /* bits 31:16 */ |
| 55 | #define HCS_INDICATOR(p) ((p)&(1 << 16)) /* true: has port indicators */ |
| 56 | #define HCS_PPC(p) ((p)&(1 << 4)) /* true: port power control */ |
| 57 | #define HCS_N_PORTS(p) (((p)>>0)&0xf) /* bits 3:0, ports on HC */ |
| 58 | #define HCC_ISOC_CACHE(p) ((p)&(1 << 7)) /* true: can cache isoc frame */ |
| 59 | #define HCC_ISOC_THRES(p) (((p)>>4)&0x7) /* bits 6:4, uframes cached */ |
| 60 | |
| 61 | /* Section 2.3 Host Controller Operational Registers */ |
| 62 | #define CMD_LRESET (1<<7) /* partial reset (no ports, etc) */ |
| 63 | #define CMD_RESET (1<<1) /* reset HC not bus */ |
| 64 | #define CMD_RUN (1<<0) /* start/stop HC */ |
| 65 | #define STS_PCD (1<<2) /* port change detect */ |
| 66 | #define FLAG_CF (1<<0) /* true: we'll support "high speed" */ |
| 67 | |
| 68 | #define PORT_OWNER (1<<13) /* true: companion hc owns this port */ |
| 69 | #define PORT_POWER (1<<12) /* true: has power (see PPC) */ |
| 70 | #define PORT_USB11(x) (((x) & (3 << 10)) == (1 << 10)) /* USB 1.1 device */ |
| 71 | #define PORT_RESET (1<<8) /* reset port */ |
| 72 | #define PORT_SUSPEND (1<<7) /* suspend port */ |
| 73 | #define PORT_RESUME (1<<6) /* resume it */ |
| 74 | #define PORT_PE (1<<2) /* port enable */ |
| 75 | #define PORT_CSC (1<<1) /* connect status change */ |
| 76 | #define PORT_CONNECT (1<<0) /* device connected */ |
| 77 | #define PORT_RWC_BITS (PORT_CSC) |
| 78 | |
| 79 | struct isp1760_qtd { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 80 | u8 packet_type; |
| 81 | u8 toggle; |
| 82 | |
| 83 | void *data_buffer; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 84 | u32 payload_addr; |
| 85 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 86 | /* the rest is HCD-private */ |
| 87 | struct list_head qtd_list; |
| 88 | struct urb *urb; |
| 89 | size_t length; |
| 90 | |
| 91 | /* isp special*/ |
| 92 | u32 status; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 93 | #define URB_ENQUEUED (1 << 1) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | struct isp1760_qh { |
| 97 | /* first part defined by EHCI spec */ |
| 98 | struct list_head qtd_list; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 99 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 100 | u32 toggle; |
| 101 | u32 ping; |
| 102 | }; |
| 103 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 104 | /* |
| 105 | * Access functions for isp176x registers (addresses 0..0x03FF). |
| 106 | */ |
| 107 | static u32 reg_read32(void __iomem *base, u32 reg) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 108 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 109 | return readl(base + reg); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 112 | static void reg_write32(void __iomem *base, u32 reg, u32 val) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 113 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 114 | writel(val, base + reg); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 118 | * Access functions for isp176x memory (offset >= 0x0400). |
| 119 | * |
| 120 | * bank_reads8() reads memory locations prefetched by an earlier write to |
| 121 | * HC_MEMORY_REG (see isp176x datasheet). Unless you want to do fancy multi- |
| 122 | * bank optimizations, you should use the more generic mem_reads8() below. |
| 123 | * |
| 124 | * For access to ptd memory, use the specialized ptd_read() and ptd_write() |
| 125 | * below. |
| 126 | * |
| 127 | * 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] | 128 | * doesn't quite work because some people have to enforce 32-bit access |
| 129 | */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 130 | static void bank_reads8(void __iomem *src_base, u32 src_offset, u32 bank_addr, |
| 131 | __u32 *dst, u32 bytes) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 132 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 133 | __u32 __iomem *src; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 134 | u32 val; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 135 | __u8 *src_byteptr; |
| 136 | __u8 *dst_byteptr; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 137 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 138 | src = src_base + (bank_addr | src_offset); |
| 139 | |
| 140 | if (src_offset < PAYLOAD_OFFSET) { |
| 141 | while (bytes >= 4) { |
| 142 | *dst = le32_to_cpu(__raw_readl(src)); |
| 143 | bytes -= 4; |
| 144 | src++; |
| 145 | dst++; |
| 146 | } |
| 147 | } else { |
| 148 | while (bytes >= 4) { |
| 149 | *dst = __raw_readl(src); |
| 150 | bytes -= 4; |
| 151 | src++; |
| 152 | dst++; |
| 153 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 154 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 155 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 156 | if (!bytes) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 157 | return; |
| 158 | |
| 159 | /* in case we have 3, 2 or 1 by left. The dst buffer may not be fully |
| 160 | * allocated. |
| 161 | */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 162 | if (src_offset < PAYLOAD_OFFSET) |
| 163 | val = le32_to_cpu(__raw_readl(src)); |
| 164 | else |
| 165 | val = __raw_readl(src); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 166 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 167 | dst_byteptr = (void *) dst; |
| 168 | src_byteptr = (void *) &val; |
| 169 | while (bytes > 0) { |
| 170 | *dst_byteptr = *src_byteptr; |
| 171 | dst_byteptr++; |
| 172 | src_byteptr++; |
| 173 | bytes--; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 177 | static void mem_reads8(void __iomem *src_base, u32 src_offset, void *dst, |
| 178 | u32 bytes) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 179 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 180 | reg_write32(src_base, HC_MEMORY_REG, src_offset + ISP_BANK(0)); |
| 181 | ndelay(90); |
| 182 | bank_reads8(src_base, src_offset, ISP_BANK(0), dst, bytes); |
| 183 | } |
| 184 | |
| 185 | static void mem_writes8(void __iomem *dst_base, u32 dst_offset, |
| 186 | __u32 const *src, u32 bytes) |
| 187 | { |
| 188 | __u32 __iomem *dst; |
| 189 | |
| 190 | dst = dst_base + dst_offset; |
| 191 | |
| 192 | if (dst_offset < PAYLOAD_OFFSET) { |
| 193 | while (bytes >= 4) { |
| 194 | __raw_writel(cpu_to_le32(*src), dst); |
| 195 | bytes -= 4; |
| 196 | src++; |
| 197 | dst++; |
| 198 | } |
| 199 | } else { |
| 200 | while (bytes >= 4) { |
| 201 | __raw_writel(*src, dst); |
| 202 | bytes -= 4; |
| 203 | src++; |
| 204 | dst++; |
| 205 | } |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 206 | } |
| 207 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 208 | if (!bytes) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 209 | return; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 210 | /* in case we have 3, 2 or 1 bytes left. The buffer is allocated and the |
| 211 | * extra bytes should not be read by the HW. |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 212 | */ |
| 213 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 214 | if (dst_offset < PAYLOAD_OFFSET) |
| 215 | __raw_writel(cpu_to_le32(*src), dst); |
| 216 | else |
| 217 | __raw_writel(*src, dst); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 220 | /* |
| 221 | * Read and write ptds. 'ptd_offset' should be one of ISO_PTD_OFFSET, |
| 222 | * INT_PTD_OFFSET, and ATL_PTD_OFFSET. 'slot' should be less than 32. |
| 223 | */ |
| 224 | static void ptd_read(void __iomem *base, u32 ptd_offset, u32 slot, |
| 225 | struct ptd *ptd) |
| 226 | { |
| 227 | reg_write32(base, HC_MEMORY_REG, |
| 228 | ISP_BANK(0) + ptd_offset + slot*sizeof(*ptd)); |
| 229 | ndelay(90); |
| 230 | bank_reads8(base, ptd_offset + slot*sizeof(*ptd), ISP_BANK(0), |
| 231 | (void *) ptd, sizeof(*ptd)); |
| 232 | } |
| 233 | |
| 234 | static void ptd_write(void __iomem *base, u32 ptd_offset, u32 slot, |
| 235 | struct ptd *ptd) |
| 236 | { |
| 237 | mem_writes8(base, ptd_offset + slot*sizeof(*ptd) + sizeof(ptd->dw0), |
| 238 | &ptd->dw1, 7*sizeof(ptd->dw1)); |
| 239 | /* Make sure dw0 gets written last (after other dw's and after payload) |
| 240 | since it contains the enable bit */ |
| 241 | wmb(); |
| 242 | mem_writes8(base, ptd_offset + slot*sizeof(*ptd), &ptd->dw0, |
| 243 | sizeof(ptd->dw0)); |
| 244 | } |
| 245 | |
| 246 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 247 | /* memory management of the 60kb on the chip from 0x1000 to 0xffff */ |
| 248 | static void init_memory(struct isp1760_hcd *priv) |
| 249 | { |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 250 | int i, curr; |
| 251 | u32 payload_addr; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 252 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 253 | payload_addr = PAYLOAD_OFFSET; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 254 | for (i = 0; i < BLOCK_1_NUM; i++) { |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 255 | priv->memory_pool[i].start = payload_addr; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 256 | priv->memory_pool[i].size = BLOCK_1_SIZE; |
| 257 | priv->memory_pool[i].free = 1; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 258 | payload_addr += priv->memory_pool[i].size; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 259 | } |
| 260 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 261 | curr = i; |
| 262 | for (i = 0; i < BLOCK_2_NUM; i++) { |
| 263 | priv->memory_pool[curr + i].start = payload_addr; |
| 264 | priv->memory_pool[curr + i].size = BLOCK_2_SIZE; |
| 265 | priv->memory_pool[curr + i].free = 1; |
| 266 | payload_addr += priv->memory_pool[curr + i].size; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 269 | curr = i; |
| 270 | for (i = 0; i < BLOCK_3_NUM; i++) { |
| 271 | priv->memory_pool[curr + i].start = payload_addr; |
| 272 | priv->memory_pool[curr + i].size = BLOCK_3_SIZE; |
| 273 | priv->memory_pool[curr + i].free = 1; |
| 274 | payload_addr += priv->memory_pool[curr + i].size; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 275 | } |
| 276 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 277 | BUG_ON(payload_addr - priv->memory_pool[0].start > PAYLOAD_AREA_SIZE); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 278 | } |
| 279 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 280 | static void alloc_mem(struct usb_hcd *hcd, struct isp1760_qtd *qtd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 281 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 282 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 283 | int i; |
| 284 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 285 | BUG_ON(qtd->payload_addr); |
| 286 | |
| 287 | if (!qtd->length) |
| 288 | return; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 289 | |
| 290 | for (i = 0; i < BLOCKS; i++) { |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 291 | if (priv->memory_pool[i].size >= qtd->length && |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 292 | priv->memory_pool[i].free) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 293 | priv->memory_pool[i].free = 0; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 294 | qtd->payload_addr = priv->memory_pool[i].start; |
| 295 | return; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 299 | dev_err(hcd->self.controller, |
| 300 | "%s: Can not allocate %lu bytes of memory\n" |
| 301 | "Current memory map:\n", |
| 302 | __func__, qtd->length); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 303 | for (i = 0; i < BLOCKS; i++) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 304 | dev_err(hcd->self.controller, "Pool %2d size %4d status: %d\n", |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 305 | i, priv->memory_pool[i].size, |
| 306 | priv->memory_pool[i].free); |
| 307 | } |
| 308 | /* XXX maybe -ENOMEM could be possible */ |
| 309 | BUG(); |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 310 | return; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 311 | } |
| 312 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 313 | static void free_mem(struct usb_hcd *hcd, struct isp1760_qtd *qtd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 314 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 315 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 316 | int i; |
| 317 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 318 | if (!qtd->payload_addr) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 319 | return; |
| 320 | |
| 321 | for (i = 0; i < BLOCKS; i++) { |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 322 | if (priv->memory_pool[i].start == qtd->payload_addr) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 323 | BUG_ON(priv->memory_pool[i].free); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 324 | priv->memory_pool[i].free = 1; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 325 | qtd->payload_addr = 0; |
| 326 | return; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 330 | dev_err(hcd->self.controller, "%s: Invalid pointer: %08x\n", |
| 331 | __func__, qtd->payload_addr); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 332 | BUG(); |
| 333 | } |
| 334 | |
| 335 | static void isp1760_init_regs(struct usb_hcd *hcd) |
| 336 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 337 | reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, 0); |
| 338 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE); |
| 339 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE); |
| 340 | reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 341 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 342 | reg_write32(hcd->regs, HC_ATL_PTD_DONEMAP_REG, ~NO_TRANSFER_ACTIVE); |
| 343 | reg_write32(hcd->regs, HC_INT_PTD_DONEMAP_REG, ~NO_TRANSFER_ACTIVE); |
| 344 | reg_write32(hcd->regs, HC_ISO_PTD_DONEMAP_REG, ~NO_TRANSFER_ACTIVE); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 345 | } |
| 346 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 347 | static int handshake(struct usb_hcd *hcd, u32 reg, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 348 | u32 mask, u32 done, int usec) |
| 349 | { |
| 350 | u32 result; |
| 351 | |
| 352 | do { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 353 | result = reg_read32(hcd->regs, reg); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 354 | if (result == ~0) |
| 355 | return -ENODEV; |
| 356 | result &= mask; |
| 357 | if (result == done) |
| 358 | return 0; |
| 359 | udelay(1); |
| 360 | usec--; |
| 361 | } while (usec > 0); |
| 362 | return -ETIMEDOUT; |
| 363 | } |
| 364 | |
| 365 | /* reset a non-running (STS_HALT == 1) controller */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 366 | static int ehci_reset(struct usb_hcd *hcd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 367 | { |
| 368 | int retval; |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 369 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 370 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 371 | u32 command = reg_read32(hcd->regs, HC_USBCMD); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 372 | |
| 373 | command |= CMD_RESET; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 374 | reg_write32(hcd->regs, HC_USBCMD, command); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 375 | hcd->state = HC_STATE_HALT; |
| 376 | priv->next_statechange = jiffies; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 377 | retval = handshake(hcd, HC_USBCMD, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 378 | CMD_RESET, 0, 250 * 1000); |
| 379 | return retval; |
| 380 | } |
| 381 | |
| 382 | static void qh_destroy(struct isp1760_qh *qh) |
| 383 | { |
| 384 | BUG_ON(!list_empty(&qh->qtd_list)); |
| 385 | kmem_cache_free(qh_cachep, qh); |
| 386 | } |
| 387 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 388 | static struct isp1760_qh *isp1760_qh_alloc(gfp_t flags) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 389 | { |
| 390 | struct isp1760_qh *qh; |
| 391 | |
| 392 | qh = kmem_cache_zalloc(qh_cachep, flags); |
| 393 | if (!qh) |
| 394 | return qh; |
| 395 | |
| 396 | INIT_LIST_HEAD(&qh->qtd_list); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 397 | return qh; |
| 398 | } |
| 399 | |
| 400 | /* magic numbers that can affect system performance */ |
| 401 | #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */ |
| 402 | #define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */ |
| 403 | #define EHCI_TUNE_RL_TT 0 |
| 404 | #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */ |
| 405 | #define EHCI_TUNE_MULT_TT 1 |
| 406 | #define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */ |
| 407 | |
| 408 | /* one-time init, only for memory state */ |
| 409 | static int priv_init(struct usb_hcd *hcd) |
| 410 | { |
| 411 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 412 | u32 hcc_params; |
| 413 | |
| 414 | spin_lock_init(&priv->lock); |
| 415 | |
| 416 | /* |
| 417 | * hw default: 1K periodic list heads, one per frame. |
| 418 | * periodic_size can shrink by USBCMD update if hcc_params allows. |
| 419 | */ |
| 420 | priv->periodic_size = DEFAULT_I_TDPS; |
| 421 | |
| 422 | /* controllers may cache some of the periodic schedule ... */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 423 | hcc_params = reg_read32(hcd->regs, HC_HCCPARAMS); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 424 | /* full frame cache */ |
| 425 | if (HCC_ISOC_CACHE(hcc_params)) |
| 426 | priv->i_thresh = 8; |
| 427 | else /* N microframes cached */ |
| 428 | priv->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); |
| 429 | |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | static int isp1760_hc_setup(struct usb_hcd *hcd) |
| 434 | { |
| 435 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 436 | int result; |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 437 | u32 scratch, hwmode; |
| 438 | |
| 439 | /* Setup HW Mode Control: This assumes a level active-low interrupt */ |
| 440 | hwmode = HW_DATA_BUS_32BIT; |
| 441 | |
| 442 | if (priv->devflags & ISP1760_FLAG_BUS_WIDTH_16) |
| 443 | hwmode &= ~HW_DATA_BUS_32BIT; |
| 444 | if (priv->devflags & ISP1760_FLAG_ANALOG_OC) |
| 445 | hwmode |= HW_ANA_DIGI_OC; |
| 446 | if (priv->devflags & ISP1760_FLAG_DACK_POL_HIGH) |
| 447 | hwmode |= HW_DACK_POL_HIGH; |
| 448 | if (priv->devflags & ISP1760_FLAG_DREQ_POL_HIGH) |
| 449 | hwmode |= HW_DREQ_POL_HIGH; |
Michael Hennerich | 9da69c6 | 2009-07-15 23:22:54 -0400 | [diff] [blame] | 450 | if (priv->devflags & ISP1760_FLAG_INTR_POL_HIGH) |
| 451 | hwmode |= HW_INTR_HIGH_ACT; |
| 452 | if (priv->devflags & ISP1760_FLAG_INTR_EDGE_TRIG) |
| 453 | hwmode |= HW_INTR_EDGE_TRIG; |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 454 | |
| 455 | /* |
| 456 | * We have to set this first in case we're in 16-bit mode. |
| 457 | * Write it twice to ensure correct upper bits if switching |
| 458 | * to 16-bit mode. |
| 459 | */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 460 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode); |
| 461 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 462 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 463 | reg_write32(hcd->regs, HC_SCRATCH_REG, 0xdeadbabe); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 464 | /* Change bus pattern */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 465 | scratch = reg_read32(hcd->regs, HC_CHIP_ID_REG); |
| 466 | scratch = reg_read32(hcd->regs, HC_SCRATCH_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 467 | if (scratch != 0xdeadbabe) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 468 | dev_err(hcd->self.controller, "Scratch test failed.\n"); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 469 | return -ENODEV; |
| 470 | } |
| 471 | |
| 472 | /* pre reset */ |
| 473 | isp1760_init_regs(hcd); |
| 474 | |
| 475 | /* reset */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 476 | reg_write32(hcd->regs, HC_RESET_REG, SW_RESET_RESET_ALL); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 477 | mdelay(100); |
| 478 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 479 | reg_write32(hcd->regs, HC_RESET_REG, SW_RESET_RESET_HC); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 480 | mdelay(100); |
| 481 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 482 | result = ehci_reset(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 483 | if (result) |
| 484 | return result; |
| 485 | |
| 486 | /* Step 11 passed */ |
| 487 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 488 | dev_info(hcd->self.controller, "bus width: %d, oc: %s\n", |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 489 | (priv->devflags & ISP1760_FLAG_BUS_WIDTH_16) ? |
| 490 | 16 : 32, (priv->devflags & ISP1760_FLAG_ANALOG_OC) ? |
| 491 | "analog" : "digital"); |
| 492 | |
| 493 | /* ATL reset */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 494 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode | ALL_ATX_RESET); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 495 | mdelay(10); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 496 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 497 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 498 | reg_write32(hcd->regs, HC_INTERRUPT_REG, INTERRUPT_ENABLE_MASK); |
| 499 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, INTERRUPT_ENABLE_MASK); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 500 | |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 501 | /* |
| 502 | * PORT 1 Control register of the ISP1760 is the OTG control |
Thomas Hommel | 42c6539 | 2008-12-18 10:31:40 +0100 | [diff] [blame] | 503 | * register on ISP1761. Since there is no OTG or device controller |
| 504 | * support in this driver, we use port 1 as a "normal" USB host port on |
| 505 | * both chips. |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 506 | */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 507 | reg_write32(hcd->regs, HC_PORT1_CTRL, PORT1_POWER | PORT1_INIT2); |
Thomas Hommel | 42c6539 | 2008-12-18 10:31:40 +0100 | [diff] [blame] | 508 | mdelay(10); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 509 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 510 | priv->hcs_params = reg_read32(hcd->regs, HC_HCSPARAMS); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 511 | |
| 512 | return priv_init(hcd); |
| 513 | } |
| 514 | |
| 515 | static void isp1760_init_maps(struct usb_hcd *hcd) |
| 516 | { |
| 517 | /*set last maps, for iso its only 1, else 32 tds bitmap*/ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 518 | reg_write32(hcd->regs, HC_ATL_PTD_LASTPTD_REG, 0x80000000); |
| 519 | reg_write32(hcd->regs, HC_INT_PTD_LASTPTD_REG, 0x80000000); |
| 520 | reg_write32(hcd->regs, HC_ISO_PTD_LASTPTD_REG, 0x00000001); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | static void isp1760_enable_interrupts(struct usb_hcd *hcd) |
| 524 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 525 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_AND_REG, 0); |
| 526 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, 0); |
| 527 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_AND_REG, 0); |
| 528 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, 0); |
| 529 | reg_write32(hcd->regs, HC_ISO_IRQ_MASK_AND_REG, 0); |
| 530 | reg_write32(hcd->regs, HC_ISO_IRQ_MASK_OR_REG, 0xffffffff); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 531 | /* step 23 passed */ |
| 532 | } |
| 533 | |
| 534 | static int isp1760_run(struct usb_hcd *hcd) |
| 535 | { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 536 | int retval; |
| 537 | u32 temp; |
| 538 | u32 command; |
| 539 | u32 chipid; |
| 540 | |
| 541 | hcd->uses_new_polling = 1; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 542 | |
| 543 | hcd->state = HC_STATE_RUNNING; |
| 544 | isp1760_enable_interrupts(hcd); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 545 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); |
| 546 | 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] | 547 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 548 | command = reg_read32(hcd->regs, HC_USBCMD); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 549 | command &= ~(CMD_LRESET|CMD_RESET); |
| 550 | command |= CMD_RUN; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 551 | reg_write32(hcd->regs, HC_USBCMD, command); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 552 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 553 | retval = handshake(hcd, HC_USBCMD, CMD_RUN, CMD_RUN, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 554 | 250 * 1000); |
| 555 | if (retval) |
| 556 | return retval; |
| 557 | |
| 558 | /* |
| 559 | * XXX |
| 560 | * Spec says to write FLAG_CF as last config action, priv code grabs |
| 561 | * the semaphore while doing so. |
| 562 | */ |
| 563 | down_write(&ehci_cf_port_reset_rwsem); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 564 | reg_write32(hcd->regs, HC_CONFIGFLAG, FLAG_CF); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 565 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 566 | retval = handshake(hcd, HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 250 * 1000); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 567 | up_write(&ehci_cf_port_reset_rwsem); |
| 568 | if (retval) |
| 569 | return retval; |
| 570 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 571 | chipid = reg_read32(hcd->regs, HC_CHIP_ID_REG); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 572 | dev_info(hcd->self.controller, "USB ISP %04x HW rev. %d started\n", |
| 573 | chipid & 0xffff, chipid >> 16); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 574 | |
| 575 | /* PTD Register Init Part 2, Step 28 */ |
| 576 | /* enable INTs */ |
| 577 | isp1760_init_maps(hcd); |
| 578 | |
| 579 | /* GRR this is run-once init(), being done every time the HC starts. |
| 580 | * So long as they're part of class devices, we can't do it init() |
| 581 | * since the class device isn't created that early. |
| 582 | */ |
| 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | static u32 base_to_chip(u32 base) |
| 587 | { |
| 588 | return ((base - 0x400) >> 3); |
| 589 | } |
| 590 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 591 | static void transform_into_atl(struct isp1760_qh *qh, |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 592 | struct isp1760_qtd *qtd, struct ptd *ptd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 593 | { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 594 | u32 maxpacket; |
| 595 | u32 multi; |
| 596 | u32 pid_code; |
| 597 | u32 rl = RL_COUNTER; |
| 598 | u32 nak = NAK_COUNTER; |
| 599 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 600 | memset(ptd, 0, sizeof(*ptd)); |
| 601 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 602 | /* according to 3.6.2, max packet len can not be > 0x400 */ |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 603 | maxpacket = usb_maxpacket(qtd->urb->dev, qtd->urb->pipe, |
| 604 | usb_pipeout(qtd->urb->pipe)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 605 | multi = 1 + ((maxpacket >> 11) & 0x3); |
| 606 | maxpacket &= 0x7ff; |
| 607 | |
| 608 | /* DW0 */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 609 | ptd->dw0 = PTD_VALID; |
| 610 | ptd->dw0 |= PTD_LENGTH(qtd->length); |
| 611 | ptd->dw0 |= PTD_MAXPACKET(maxpacket); |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 612 | ptd->dw0 |= PTD_ENDPOINT(usb_pipeendpoint(qtd->urb->pipe)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 613 | |
| 614 | /* DW1 */ |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 615 | ptd->dw1 = usb_pipeendpoint(qtd->urb->pipe) >> 1; |
| 616 | ptd->dw1 |= PTD_DEVICE_ADDR(usb_pipedevice(qtd->urb->pipe)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 617 | |
| 618 | pid_code = qtd->packet_type; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 619 | ptd->dw1 |= PTD_PID_TOKEN(pid_code); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 620 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 621 | if (usb_pipebulk(qtd->urb->pipe)) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 622 | ptd->dw1 |= PTD_TRANS_BULK; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 623 | else if (usb_pipeint(qtd->urb->pipe)) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 624 | ptd->dw1 |= PTD_TRANS_INT; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 625 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 626 | if (qtd->urb->dev->speed != USB_SPEED_HIGH) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 627 | /* split transaction */ |
| 628 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 629 | ptd->dw1 |= PTD_TRANS_SPLIT; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 630 | if (qtd->urb->dev->speed == USB_SPEED_LOW) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 631 | ptd->dw1 |= PTD_SE_USB_LOSPEED; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 632 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 633 | ptd->dw1 |= PTD_PORT_NUM(qtd->urb->dev->ttport); |
| 634 | ptd->dw1 |= PTD_HUB_NUM(qtd->urb->dev->tt->hub->devnum); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 635 | |
| 636 | /* SE bit for Split INT transfers */ |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 637 | if (usb_pipeint(qtd->urb->pipe) && |
| 638 | (qtd->urb->dev->speed == USB_SPEED_LOW)) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 639 | ptd->dw1 |= 2 << 16; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 640 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 641 | ptd->dw3 = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 642 | rl = 0; |
| 643 | nak = 0; |
| 644 | } else { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 645 | ptd->dw0 |= PTD_MULTI(multi); |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 646 | if (usb_pipecontrol(qtd->urb->pipe) || |
| 647 | usb_pipebulk(qtd->urb->pipe)) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 648 | ptd->dw3 = qh->ping; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 649 | else |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 650 | ptd->dw3 = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 651 | } |
| 652 | /* DW2 */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 653 | ptd->dw2 = 0; |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 654 | ptd->dw2 |= PTD_DATA_START_ADDR(base_to_chip(qtd->payload_addr)); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 655 | ptd->dw2 |= PTD_RL_CNT(rl); |
| 656 | ptd->dw3 |= PTD_NAC_CNT(nak); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 657 | |
| 658 | /* DW3 */ |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 659 | if (usb_pipecontrol(qtd->urb->pipe)) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 660 | ptd->dw3 |= PTD_DATA_TOGGLE(qtd->toggle); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 661 | else |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 662 | ptd->dw3 |= qh->toggle; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 663 | |
| 664 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 665 | ptd->dw3 |= PTD_ACTIVE; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 666 | /* Cerr */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 667 | ptd->dw3 |= PTD_CERR(ERR_COUNTER); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 668 | } |
| 669 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 670 | static void transform_add_int(struct isp1760_qh *qh, |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 671 | struct isp1760_qtd *qtd, struct ptd *ptd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 672 | { |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame^] | 673 | u32 usof; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 674 | u32 period; |
| 675 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame^] | 676 | /* |
| 677 | * Most of this is guessing. ISP1761 datasheet is quite unclear, and |
| 678 | * the algorithm from the original Philips driver code, which was |
| 679 | * pretty much used in this driver before as well, is quite horrendous |
| 680 | * and, i believe, incorrect. The code below follows the datasheet and |
| 681 | * USB2.0 spec as far as I can tell, and plug/unplug seems to be much |
| 682 | * more reliable this way (fingers crossed...). |
| 683 | */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 684 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame^] | 685 | if (qtd->urb->dev->speed == USB_SPEED_HIGH) { |
| 686 | /* urb->interval is in units of microframes (1/8 ms) */ |
| 687 | period = qtd->urb->interval >> 3; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 688 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame^] | 689 | if (qtd->urb->interval > 4) |
| 690 | usof = 0x01; /* One bit set => |
| 691 | interval 1 ms * uFrame-match */ |
| 692 | else if (qtd->urb->interval > 2) |
| 693 | usof = 0x22; /* Two bits set => interval 1/2 ms */ |
| 694 | else if (qtd->urb->interval > 1) |
| 695 | usof = 0x55; /* Four bits set => interval 1/4 ms */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 696 | else |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame^] | 697 | usof = 0xff; /* All bits set => interval 1/8 ms */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 698 | } else { |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame^] | 699 | /* urb->interval is in units of frames (1 ms) */ |
| 700 | period = qtd->urb->interval; |
| 701 | usof = 0x0f; /* Execute Start Split on any of the |
| 702 | four first uFrames */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 703 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame^] | 704 | /* |
| 705 | * First 8 bits in dw5 is uSCS and "specifies which uSOF the |
| 706 | * complete split needs to be sent. Valid only for IN." Also, |
| 707 | * "All bits can be set to one for every transfer." (p 82, |
| 708 | * ISP1761 data sheet.) 0x1c is from Philips driver. Where did |
| 709 | * that number come from? 0xff seems to work fine... |
| 710 | */ |
| 711 | /* ptd->dw5 = 0x1c; */ |
| 712 | ptd->dw5 = 0xff; /* Execute Complete Split on any uFrame */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 713 | } |
| 714 | |
Arvid Brodin | 65f1b52 | 2011-02-26 22:07:35 +0100 | [diff] [blame^] | 715 | period = period >> 1;/* Ensure equal or shorter period than requested */ |
| 716 | period &= 0xf8; /* Mask off too large values and lowest unused 3 bits */ |
| 717 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 718 | ptd->dw2 |= period; |
| 719 | ptd->dw4 = usof; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 720 | } |
| 721 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 722 | static void transform_into_int(struct isp1760_qh *qh, |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 723 | struct isp1760_qtd *qtd, struct ptd *ptd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 724 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 725 | transform_into_atl(qh, qtd, ptd); |
| 726 | transform_add_int(qh, qtd, ptd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len, |
| 730 | u32 token) |
| 731 | { |
| 732 | int count; |
| 733 | |
| 734 | qtd->data_buffer = databuffer; |
| 735 | qtd->packet_type = GET_QTD_TOKEN_TYPE(token); |
| 736 | qtd->toggle = GET_DATA_TOGGLE(token); |
| 737 | |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 738 | if (len > MAX_PAYLOAD_SIZE) |
| 739 | count = MAX_PAYLOAD_SIZE; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 740 | else |
| 741 | count = len; |
| 742 | |
| 743 | qtd->length = count; |
| 744 | return count; |
| 745 | } |
| 746 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 747 | static int check_error(struct usb_hcd *hcd, struct ptd *ptd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 748 | { |
| 749 | int error = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 750 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 751 | if (ptd->dw3 & DW3_HALT_BIT) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 752 | error = -EPIPE; |
| 753 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 754 | if (ptd->dw3 & DW3_ERROR_BIT) |
Anton Vorontsov | 0954e1c | 2010-05-07 01:09:19 +0400 | [diff] [blame] | 755 | pr_err("error bit is set in DW3\n"); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 756 | } |
| 757 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 758 | if (ptd->dw3 & DW3_QTD_ACTIVE) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 759 | dev_err(hcd->self.controller, "Transfer active bit is set DW3\n" |
| 760 | "nak counter: %d, rl: %d\n", |
| 761 | (ptd->dw3 >> 19) & 0xf, (ptd->dw2 >> 25) & 0xf); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | return error; |
| 765 | } |
| 766 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 767 | static void check_int_err_status(struct usb_hcd *hcd, u32 dw4) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 768 | { |
| 769 | u32 i; |
| 770 | |
| 771 | dw4 >>= 8; |
| 772 | |
| 773 | for (i = 0; i < 8; i++) { |
| 774 | switch (dw4 & 0x7) { |
| 775 | case INT_UNDERRUN: |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 776 | dev_err(hcd->self.controller, "Underrun (%d)\n", i); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 777 | break; |
| 778 | |
| 779 | case INT_EXACT: |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 780 | dev_err(hcd->self.controller, |
| 781 | "Transaction error (%d)\n", i); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 782 | break; |
| 783 | |
| 784 | case INT_BABBLE: |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 785 | dev_err(hcd->self.controller, "Babble error (%d)\n", i); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 786 | break; |
| 787 | } |
| 788 | dw4 >>= 3; |
| 789 | } |
| 790 | } |
| 791 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 792 | static void enqueue_one_qtd(struct usb_hcd *hcd, struct isp1760_qtd *qtd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 793 | { |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 794 | if (qtd->length && (qtd->length <= MAX_PAYLOAD_SIZE)) { |
| 795 | switch (qtd->packet_type) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 796 | case IN_PID: |
| 797 | break; |
| 798 | case OUT_PID: |
| 799 | case SETUP_PID: |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 800 | mem_writes8(hcd->regs, qtd->payload_addr, |
| 801 | qtd->data_buffer, qtd->length); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | } |
| 805 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 806 | static void enqueue_one_atl_qtd(struct usb_hcd *hcd, struct isp1760_qh *qh, |
| 807 | u32 slot, struct isp1760_qtd *qtd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 808 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 809 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 810 | struct ptd ptd; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 811 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 812 | alloc_mem(hcd, qtd); |
| 813 | transform_into_atl(qh, qtd, &ptd); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 814 | ptd_write(hcd->regs, ATL_PTD_OFFSET, slot, &ptd); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 815 | enqueue_one_qtd(hcd, qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 816 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 817 | priv->atl_ints[slot].qh = qh; |
| 818 | priv->atl_ints[slot].qtd = qtd; |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 819 | qtd->status |= URB_ENQUEUED; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 820 | qtd->status |= slot << 16; |
| 821 | } |
| 822 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 823 | static void enqueue_one_int_qtd(struct usb_hcd *hcd, struct isp1760_qh *qh, |
| 824 | u32 slot, struct isp1760_qtd *qtd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 825 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 826 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 827 | struct ptd ptd; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 828 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 829 | alloc_mem(hcd, qtd); |
| 830 | transform_into_int(qh, qtd, &ptd); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 831 | ptd_write(hcd->regs, INT_PTD_OFFSET, slot, &ptd); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 832 | enqueue_one_qtd(hcd, qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 833 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 834 | priv->int_ints[slot].qh = qh; |
| 835 | priv->int_ints[slot].qtd = qtd; |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 836 | qtd->status |= URB_ENQUEUED; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 837 | qtd->status |= slot << 16; |
| 838 | } |
| 839 | |
Adrian Bunk | 473bca9 | 2008-05-05 21:25:33 +0300 | [diff] [blame] | 840 | static void enqueue_an_ATL_packet(struct usb_hcd *hcd, struct isp1760_qh *qh, |
| 841 | struct isp1760_qtd *qtd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 842 | { |
| 843 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 844 | u32 skip_map, or_map; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 845 | u32 slot; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 846 | u32 buffstatus; |
| 847 | |
Catalin Marinas | e6bdfe3 | 2009-03-23 12:38:16 +0000 | [diff] [blame] | 848 | /* |
| 849 | * When this function is called from the interrupt handler to enqueue |
| 850 | * a follow-up packet, the SKIP register gets written and read back |
| 851 | * almost immediately. With ISP1761, this register requires a delay of |
| 852 | * 195ns between a write and subsequent read (see section 15.1.1.3). |
| 853 | */ |
Michael Hennerich | ebb8a4e | 2010-08-05 17:53:57 -0400 | [diff] [blame] | 854 | mmiowb(); |
Catalin Marinas | e6bdfe3 | 2009-03-23 12:38:16 +0000 | [diff] [blame] | 855 | ndelay(195); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 856 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 857 | |
| 858 | BUG_ON(!skip_map); |
| 859 | slot = __ffs(skip_map); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 860 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 861 | enqueue_one_atl_qtd(hcd, qh, slot, qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 862 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 863 | or_map = reg_read32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 864 | or_map |= (1 << slot); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 865 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, or_map); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 866 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 867 | skip_map &= ~(1 << slot); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 868 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 869 | |
Sebastian Andrzej Siewior | b14e840 | 2011-02-08 21:07:40 +0100 | [diff] [blame] | 870 | priv->atl_queued++; |
| 871 | if (priv->atl_queued == 2) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 872 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, |
| 873 | INTERRUPT_ENABLE_SOT_MASK); |
Sebastian Andrzej Siewior | b14e840 | 2011-02-08 21:07:40 +0100 | [diff] [blame] | 874 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 875 | buffstatus = reg_read32(hcd->regs, HC_BUFFER_STATUS_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 876 | buffstatus |= ATL_BUFFER; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 877 | reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, buffstatus); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 878 | } |
| 879 | |
Adrian Bunk | 473bca9 | 2008-05-05 21:25:33 +0300 | [diff] [blame] | 880 | static void enqueue_an_INT_packet(struct usb_hcd *hcd, struct isp1760_qh *qh, |
| 881 | struct isp1760_qtd *qtd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 882 | { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 883 | u32 skip_map, or_map; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 884 | u32 slot; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 885 | u32 buffstatus; |
| 886 | |
Catalin Marinas | e6bdfe3 | 2009-03-23 12:38:16 +0000 | [diff] [blame] | 887 | /* |
| 888 | * When this function is called from the interrupt handler to enqueue |
| 889 | * a follow-up packet, the SKIP register gets written and read back |
| 890 | * almost immediately. With ISP1761, this register requires a delay of |
| 891 | * 195ns between a write and subsequent read (see section 15.1.1.3). |
| 892 | */ |
Michael Hennerich | ebb8a4e | 2010-08-05 17:53:57 -0400 | [diff] [blame] | 893 | mmiowb(); |
Catalin Marinas | e6bdfe3 | 2009-03-23 12:38:16 +0000 | [diff] [blame] | 894 | ndelay(195); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 895 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 896 | |
| 897 | BUG_ON(!skip_map); |
| 898 | slot = __ffs(skip_map); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 899 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 900 | enqueue_one_int_qtd(hcd, qh, slot, qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 901 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 902 | or_map = reg_read32(hcd->regs, HC_INT_IRQ_MASK_OR_REG); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 903 | or_map |= (1 << slot); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 904 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, or_map); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 905 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 906 | skip_map &= ~(1 << slot); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 907 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 908 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 909 | buffstatus = reg_read32(hcd->regs, HC_BUFFER_STATUS_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 910 | buffstatus |= INT_BUFFER; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 911 | reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, buffstatus); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 912 | } |
| 913 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 914 | static void isp1760_urb_done(struct usb_hcd *hcd, struct urb *urb) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 915 | __releases(priv->lock) |
| 916 | __acquires(priv->lock) |
| 917 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 918 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 919 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 920 | if (!urb->unlinked) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 921 | if (urb->status == -EINPROGRESS) |
| 922 | urb->status = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 923 | } |
| 924 | |
Catalin Marinas | db8516f | 2010-02-02 15:31:02 +0000 | [diff] [blame] | 925 | if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) { |
| 926 | void *ptr; |
| 927 | for (ptr = urb->transfer_buffer; |
| 928 | ptr < urb->transfer_buffer + urb->transfer_buffer_length; |
| 929 | ptr += PAGE_SIZE) |
| 930 | flush_dcache_page(virt_to_page(ptr)); |
| 931 | } |
| 932 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 933 | /* complete() can reenter this HCD */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 934 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 935 | spin_unlock(&priv->lock); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 936 | usb_hcd_giveback_urb(hcd, urb, urb->status); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 937 | spin_lock(&priv->lock); |
| 938 | } |
| 939 | |
| 940 | static void isp1760_qtd_free(struct isp1760_qtd *qtd) |
| 941 | { |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 942 | BUG_ON(qtd->payload_addr); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 943 | kmem_cache_free(qtd_cachep, qtd); |
| 944 | } |
| 945 | |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 946 | static struct isp1760_qtd *clean_this_qtd(struct isp1760_qtd *qtd, |
| 947 | struct isp1760_qh *qh) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 948 | { |
| 949 | struct isp1760_qtd *tmp_qtd; |
| 950 | |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 951 | if (list_is_last(&qtd->qtd_list, &qh->qtd_list)) |
| 952 | tmp_qtd = NULL; |
| 953 | else |
| 954 | tmp_qtd = list_entry(qtd->qtd_list.next, struct isp1760_qtd, |
| 955 | qtd_list); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 956 | list_del(&qtd->qtd_list); |
| 957 | isp1760_qtd_free(qtd); |
| 958 | return tmp_qtd; |
| 959 | } |
| 960 | |
| 961 | /* |
| 962 | * Remove this QTD from the QH list and free its memory. If this QTD |
| 963 | * isn't the last one than remove also his successor(s). |
| 964 | * Returns the QTD which is part of an new URB and should be enqueued. |
| 965 | */ |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 966 | static struct isp1760_qtd *clean_up_qtdlist(struct isp1760_qtd *qtd, |
| 967 | struct isp1760_qh *qh) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 968 | { |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 969 | struct urb *urb; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 970 | |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 971 | urb = qtd->urb; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 972 | do { |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 973 | qtd = clean_this_qtd(qtd, qh); |
| 974 | } while (qtd && (qtd->urb == urb)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 975 | |
| 976 | return qtd; |
| 977 | } |
| 978 | |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 979 | static int last_qtd_of_urb(struct isp1760_qtd *qtd, struct isp1760_qh *qh) |
| 980 | { |
| 981 | struct urb *urb; |
| 982 | |
| 983 | if (list_is_last(&qtd->qtd_list, &qh->qtd_list)) |
| 984 | return 1; |
| 985 | |
| 986 | urb = qtd->urb; |
| 987 | qtd = list_entry(qtd->qtd_list.next, typeof(*qtd), qtd_list); |
| 988 | return (qtd->urb != urb); |
| 989 | } |
| 990 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 991 | static void do_atl_int(struct usb_hcd *hcd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 992 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 993 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 994 | u32 done_map, skip_map; |
| 995 | struct ptd ptd; |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 996 | struct urb *urb; |
| 997 | u32 slot; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 998 | u32 length; |
| 999 | u32 or_map; |
| 1000 | u32 status = -EINVAL; |
| 1001 | int error; |
| 1002 | struct isp1760_qtd *qtd; |
| 1003 | struct isp1760_qh *qh; |
| 1004 | u32 rl; |
| 1005 | u32 nakcount; |
| 1006 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1007 | done_map = reg_read32(hcd->regs, HC_ATL_PTD_DONEMAP_REG); |
| 1008 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1009 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1010 | or_map = reg_read32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1011 | or_map &= ~done_map; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1012 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, or_map); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1013 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1014 | while (done_map) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1015 | status = 0; |
Sebastian Andrzej Siewior | b14e840 | 2011-02-08 21:07:40 +0100 | [diff] [blame] | 1016 | priv->atl_queued--; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1017 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1018 | slot = __ffs(done_map); |
| 1019 | done_map &= ~(1 << slot); |
| 1020 | skip_map |= (1 << slot); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1021 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1022 | qtd = priv->atl_ints[slot].qtd; |
| 1023 | qh = priv->atl_ints[slot].qh; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1024 | |
| 1025 | if (!qh) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1026 | dev_err(hcd->self.controller, "qh is 0\n"); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1027 | continue; |
| 1028 | } |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1029 | ptd_read(hcd->regs, ATL_PTD_OFFSET, slot, &ptd); |
Enrico Scholz | 3f02a95 | 2008-07-17 20:09:30 +0200 | [diff] [blame] | 1030 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1031 | rl = (ptd.dw2 >> 25) & 0x0f; |
| 1032 | nakcount = (ptd.dw3 >> 19) & 0xf; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1033 | |
| 1034 | /* Transfer Error, *but* active and no HALT -> reload */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1035 | if ((ptd.dw3 & DW3_ERROR_BIT) && (ptd.dw3 & DW3_QTD_ACTIVE) && |
| 1036 | !(ptd.dw3 & DW3_HALT_BIT)) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1037 | |
| 1038 | /* according to ppriv code, we have to |
| 1039 | * reload this one if trasfered bytes != requested bytes |
| 1040 | * else act like everything went smooth.. |
| 1041 | * XXX This just doesn't feel right and hasn't |
| 1042 | * triggered so far. |
| 1043 | */ |
| 1044 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1045 | length = PTD_XFERRED_LENGTH(ptd.dw3); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1046 | dev_err(hcd->self.controller, |
| 1047 | "Should reload now... transferred %d " |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1048 | "of %zu\n", length, qtd->length); |
| 1049 | BUG(); |
| 1050 | } |
| 1051 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1052 | if (!nakcount && (ptd.dw3 & DW3_QTD_ACTIVE)) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1053 | u32 buffstatus; |
| 1054 | |
Colin Tuckley | c0d7414 | 2010-01-07 11:22:47 +0000 | [diff] [blame] | 1055 | /* |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1056 | * NAKs are handled in HW by the chip. Usually if the |
| 1057 | * device is not able to send data fast enough. |
Colin Tuckley | c0d7414 | 2010-01-07 11:22:47 +0000 | [diff] [blame] | 1058 | * This happens mostly on slower hardware. |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1059 | */ |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1060 | |
| 1061 | /* RL counter = ERR counter */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1062 | ptd.dw3 &= ~(0xf << 19); |
| 1063 | ptd.dw3 |= rl << 19; |
| 1064 | ptd.dw3 &= ~(3 << (55 - 32)); |
| 1065 | ptd.dw3 |= ERR_COUNTER << (55 - 32); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1066 | |
| 1067 | /* |
| 1068 | * It is not needed to write skip map back because it |
| 1069 | * is unchanged. Just make sure that this entry is |
| 1070 | * unskipped once it gets written to the HW. |
| 1071 | */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1072 | skip_map &= ~(1 << slot); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1073 | or_map = reg_read32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1074 | or_map |= 1 << slot; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1075 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, or_map); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1076 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1077 | ptd.dw0 |= PTD_VALID; |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1078 | ptd_write(hcd->regs, ATL_PTD_OFFSET, slot, &ptd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1079 | |
Sebastian Andrzej Siewior | b14e840 | 2011-02-08 21:07:40 +0100 | [diff] [blame] | 1080 | priv->atl_queued++; |
| 1081 | if (priv->atl_queued == 2) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1082 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, |
| 1083 | INTERRUPT_ENABLE_SOT_MASK); |
Sebastian Andrzej Siewior | b14e840 | 2011-02-08 21:07:40 +0100 | [diff] [blame] | 1084 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1085 | buffstatus = reg_read32(hcd->regs, |
| 1086 | HC_BUFFER_STATUS_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1087 | buffstatus |= ATL_BUFFER; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1088 | reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, |
| 1089 | buffstatus); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1090 | continue; |
| 1091 | } |
| 1092 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1093 | error = check_error(hcd, &ptd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1094 | if (error) { |
| 1095 | status = error; |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1096 | priv->atl_ints[slot].qh->toggle = 0; |
| 1097 | priv->atl_ints[slot].qh->ping = 0; |
| 1098 | qtd->urb->status = -EPIPE; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1099 | |
| 1100 | #if 0 |
| 1101 | printk(KERN_ERR "Error in %s().\n", __func__); |
| 1102 | printk(KERN_ERR "IN dw0: %08x dw1: %08x dw2: %08x " |
| 1103 | "dw3: %08x dw4: %08x dw5: %08x dw6: " |
| 1104 | "%08x dw7: %08x\n", |
| 1105 | ptd.dw0, ptd.dw1, ptd.dw2, ptd.dw3, |
| 1106 | ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7); |
| 1107 | #endif |
| 1108 | } else { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1109 | if (usb_pipetype(qtd->urb->pipe) == PIPE_BULK) { |
| 1110 | priv->atl_ints[slot].qh->toggle = |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1111 | ptd.dw3 & (1 << 25); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1112 | priv->atl_ints[slot].qh->ping = |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1113 | ptd.dw3 & (1 << 26); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1117 | length = PTD_XFERRED_LENGTH(ptd.dw3); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1118 | if (length) { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1119 | switch (DW1_GET_PID(ptd.dw1)) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1120 | case IN_PID: |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 1121 | mem_reads8(hcd->regs, qtd->payload_addr, |
Arvid Brodin | bbaa387 | 2011-02-26 22:05:26 +0100 | [diff] [blame] | 1122 | qtd->data_buffer, length); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1123 | |
| 1124 | case OUT_PID: |
| 1125 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1126 | qtd->urb->actual_length += length; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1127 | |
| 1128 | case SETUP_PID: |
| 1129 | break; |
| 1130 | } |
| 1131 | } |
| 1132 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1133 | priv->atl_ints[slot].qtd = NULL; |
| 1134 | priv->atl_ints[slot].qh = NULL; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1135 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1136 | free_mem(hcd, qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1137 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1138 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1139 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1140 | if (qtd->urb->status == -EPIPE) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1141 | /* HALT was received */ |
| 1142 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1143 | urb = qtd->urb; |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1144 | qtd = clean_up_qtdlist(qtd, qh); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1145 | isp1760_urb_done(hcd, urb); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1146 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1147 | } else if (usb_pipebulk(qtd->urb->pipe) && |
| 1148 | (length < qtd->length)) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1149 | /* short BULK received */ |
| 1150 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1151 | if (qtd->urb->transfer_flags & URB_SHORT_NOT_OK) { |
| 1152 | qtd->urb->status = -EREMOTEIO; |
| 1153 | dev_dbg(hcd->self.controller, |
| 1154 | "short bulk, %d instead %zu " |
| 1155 | "with URB_SHORT_NOT_OK flag.\n", |
| 1156 | length, qtd->length); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1157 | } |
| 1158 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1159 | if (qtd->urb->status == -EINPROGRESS) |
| 1160 | qtd->urb->status = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1161 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1162 | urb = qtd->urb; |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1163 | qtd = clean_up_qtdlist(qtd, qh); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1164 | isp1760_urb_done(hcd, urb); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1165 | |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1166 | } else if (last_qtd_of_urb(qtd, qh)) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1167 | /* that was the last qtd of that URB */ |
| 1168 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1169 | if (qtd->urb->status == -EINPROGRESS) |
| 1170 | qtd->urb->status = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1171 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1172 | urb = qtd->urb; |
| 1173 | qtd = clean_up_qtdlist(qtd, qh); |
| 1174 | isp1760_urb_done(hcd, urb); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1175 | |
| 1176 | } else { |
| 1177 | /* next QTD of this URB */ |
| 1178 | |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1179 | qtd = clean_this_qtd(qtd, qh); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1180 | BUG_ON(!qtd); |
| 1181 | } |
| 1182 | |
| 1183 | if (qtd) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1184 | enqueue_an_ATL_packet(hcd, qh, qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1185 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1186 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1187 | } |
Sebastian Andrzej Siewior | b14e840 | 2011-02-08 21:07:40 +0100 | [diff] [blame] | 1188 | if (priv->atl_queued <= 1) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1189 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, |
| 1190 | INTERRUPT_ENABLE_MASK); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1191 | } |
| 1192 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1193 | static void do_intl_int(struct usb_hcd *hcd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1194 | { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1195 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1196 | u32 done_map, skip_map; |
| 1197 | struct ptd ptd; |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1198 | struct urb *urb; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1199 | u32 length; |
| 1200 | u32 or_map; |
| 1201 | int error; |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1202 | u32 slot; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1203 | struct isp1760_qtd *qtd; |
| 1204 | struct isp1760_qh *qh; |
| 1205 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1206 | done_map = reg_read32(hcd->regs, HC_INT_PTD_DONEMAP_REG); |
| 1207 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1208 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1209 | or_map = reg_read32(hcd->regs, HC_INT_IRQ_MASK_OR_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1210 | or_map &= ~done_map; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1211 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, or_map); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1212 | |
| 1213 | while (done_map) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1214 | slot = __ffs(done_map); |
| 1215 | done_map &= ~(1 << slot); |
| 1216 | skip_map |= (1 << slot); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1217 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1218 | qtd = priv->int_ints[slot].qtd; |
| 1219 | qh = priv->int_ints[slot].qh; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1220 | |
| 1221 | if (!qh) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1222 | dev_err(hcd->self.controller, "(INT) qh is 0\n"); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1223 | continue; |
| 1224 | } |
| 1225 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1226 | ptd_read(hcd->regs, INT_PTD_OFFSET, slot, &ptd); |
| 1227 | check_int_err_status(hcd, ptd.dw4); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1228 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1229 | error = check_error(hcd, &ptd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1230 | if (error) { |
| 1231 | #if 0 |
| 1232 | printk(KERN_ERR "Error in %s().\n", __func__); |
| 1233 | printk(KERN_ERR "IN dw0: %08x dw1: %08x dw2: %08x " |
| 1234 | "dw3: %08x dw4: %08x dw5: %08x dw6: " |
| 1235 | "%08x dw7: %08x\n", |
| 1236 | ptd.dw0, ptd.dw1, ptd.dw2, ptd.dw3, |
| 1237 | ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7); |
| 1238 | #endif |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1239 | qtd->urb->status = -EPIPE; |
| 1240 | priv->int_ints[slot].qh->toggle = 0; |
| 1241 | priv->int_ints[slot].qh->ping = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1242 | |
| 1243 | } else { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1244 | priv->int_ints[slot].qh->toggle = ptd.dw3 & (1 << 25); |
| 1245 | priv->int_ints[slot].qh->ping = ptd.dw3 & (1 << 26); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1246 | } |
| 1247 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1248 | if (qtd->urb->dev->speed != USB_SPEED_HIGH) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1249 | length = PTD_XFERRED_LENGTH_LO(ptd.dw3); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1250 | else |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1251 | length = PTD_XFERRED_LENGTH(ptd.dw3); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1252 | |
| 1253 | if (length) { |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1254 | switch (DW1_GET_PID(ptd.dw1)) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1255 | case IN_PID: |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 1256 | mem_reads8(hcd->regs, qtd->payload_addr, |
Arvid Brodin | bbaa387 | 2011-02-26 22:05:26 +0100 | [diff] [blame] | 1257 | qtd->data_buffer, length); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1258 | case OUT_PID: |
| 1259 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1260 | qtd->urb->actual_length += length; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1261 | |
| 1262 | case SETUP_PID: |
| 1263 | break; |
| 1264 | } |
| 1265 | } |
| 1266 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1267 | priv->int_ints[slot].qtd = NULL; |
| 1268 | priv->int_ints[slot].qh = NULL; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1269 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1270 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1271 | free_mem(hcd, qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1272 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1273 | if (qtd->urb->status == -EPIPE) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1274 | /* HALT received */ |
| 1275 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1276 | urb = qtd->urb; |
| 1277 | qtd = clean_up_qtdlist(qtd, qh); |
| 1278 | isp1760_urb_done(hcd, urb); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1279 | |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1280 | } else if (last_qtd_of_urb(qtd, qh)) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1281 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1282 | if (qtd->urb->status == -EINPROGRESS) |
| 1283 | qtd->urb->status = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1284 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1285 | urb = qtd->urb; |
| 1286 | qtd = clean_up_qtdlist(qtd, qh); |
| 1287 | isp1760_urb_done(hcd, urb); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1288 | |
| 1289 | } else { |
| 1290 | /* next QTD of this URB */ |
| 1291 | |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1292 | qtd = clean_this_qtd(qtd, qh); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1293 | BUG_ON(!qtd); |
| 1294 | } |
| 1295 | |
| 1296 | if (qtd) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1297 | enqueue_an_INT_packet(hcd, qh, qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1298 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1299 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1300 | } |
| 1301 | } |
| 1302 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1303 | static struct isp1760_qh *qh_make(struct usb_hcd *hcd, struct urb *urb, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1304 | gfp_t flags) |
| 1305 | { |
| 1306 | struct isp1760_qh *qh; |
| 1307 | int is_input, type; |
| 1308 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1309 | qh = isp1760_qh_alloc(flags); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1310 | if (!qh) |
| 1311 | return qh; |
| 1312 | |
| 1313 | /* |
| 1314 | * init endpoint/device data for this QH |
| 1315 | */ |
| 1316 | is_input = usb_pipein(urb->pipe); |
| 1317 | type = usb_pipetype(urb->pipe); |
| 1318 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1319 | if (!usb_pipecontrol(urb->pipe)) |
| 1320 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, |
| 1321 | 1); |
| 1322 | return qh; |
| 1323 | } |
| 1324 | |
| 1325 | /* |
| 1326 | * For control/bulk/interrupt, return QH with these TDs appended. |
| 1327 | * Allocates and initializes the QH if necessary. |
| 1328 | * Returns null if it can't allocate a QH it needs to. |
| 1329 | * If the QH has TDs (urbs) already, that's great. |
| 1330 | */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1331 | static struct isp1760_qh *qh_append_tds(struct usb_hcd *hcd, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1332 | struct urb *urb, struct list_head *qtd_list, int epnum, |
| 1333 | void **ptr) |
| 1334 | { |
| 1335 | struct isp1760_qh *qh; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1336 | |
| 1337 | qh = (struct isp1760_qh *)*ptr; |
| 1338 | if (!qh) { |
| 1339 | /* can't sleep here, we have priv->lock... */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1340 | qh = qh_make(hcd, urb, GFP_ATOMIC); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1341 | if (!qh) |
| 1342 | return qh; |
| 1343 | *ptr = qh; |
| 1344 | } |
| 1345 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1346 | list_splice(qtd_list, qh->qtd_list.prev); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1347 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1348 | return qh; |
| 1349 | } |
| 1350 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1351 | static void qtd_list_free(struct urb *urb, struct list_head *qtd_list) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1352 | { |
| 1353 | struct list_head *entry, *temp; |
| 1354 | |
| 1355 | list_for_each_safe(entry, temp, qtd_list) { |
| 1356 | struct isp1760_qtd *qtd; |
| 1357 | |
| 1358 | qtd = list_entry(entry, struct isp1760_qtd, qtd_list); |
| 1359 | list_del(&qtd->qtd_list); |
| 1360 | isp1760_qtd_free(qtd); |
| 1361 | } |
| 1362 | } |
| 1363 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1364 | static int isp1760_prepare_enqueue(struct usb_hcd *hcd, struct urb *urb, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1365 | struct list_head *qtd_list, gfp_t mem_flags, packet_enqueue *p) |
| 1366 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1367 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1368 | struct isp1760_qtd *qtd; |
| 1369 | int epnum; |
| 1370 | unsigned long flags; |
| 1371 | struct isp1760_qh *qh = NULL; |
| 1372 | int rc; |
| 1373 | int qh_busy; |
| 1374 | |
| 1375 | qtd = list_entry(qtd_list->next, struct isp1760_qtd, qtd_list); |
| 1376 | epnum = urb->ep->desc.bEndpointAddress; |
| 1377 | |
| 1378 | spin_lock_irqsave(&priv->lock, flags); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1379 | if (!HCD_HW_ACCESSIBLE(hcd)) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1380 | rc = -ESHUTDOWN; |
| 1381 | goto done; |
| 1382 | } |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1383 | rc = usb_hcd_link_urb_to_ep(hcd, urb); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1384 | if (rc) |
| 1385 | goto done; |
| 1386 | |
| 1387 | qh = urb->ep->hcpriv; |
| 1388 | if (qh) |
| 1389 | qh_busy = !list_empty(&qh->qtd_list); |
| 1390 | else |
| 1391 | qh_busy = 0; |
| 1392 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1393 | qh = qh_append_tds(hcd, urb, qtd_list, epnum, &urb->ep->hcpriv); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1394 | if (!qh) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1395 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1396 | rc = -ENOMEM; |
| 1397 | goto done; |
| 1398 | } |
| 1399 | |
| 1400 | if (!qh_busy) |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1401 | p(hcd, qh, qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1402 | |
| 1403 | done: |
| 1404 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1405 | if (!qh) |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1406 | qtd_list_free(urb, qtd_list); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1407 | return rc; |
| 1408 | } |
| 1409 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1410 | static struct isp1760_qtd *isp1760_qtd_alloc(gfp_t flags) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1411 | { |
| 1412 | struct isp1760_qtd *qtd; |
| 1413 | |
| 1414 | qtd = kmem_cache_zalloc(qtd_cachep, flags); |
| 1415 | if (qtd) |
| 1416 | INIT_LIST_HEAD(&qtd->qtd_list); |
| 1417 | |
| 1418 | return qtd; |
| 1419 | } |
| 1420 | |
| 1421 | /* |
| 1422 | * create a list of filled qtds for this URB; won't link into qh. |
| 1423 | */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1424 | #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff) |
| 1425 | static struct list_head *qh_urb_transaction(struct usb_hcd *hcd, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1426 | struct urb *urb, struct list_head *head, gfp_t flags) |
| 1427 | { |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1428 | struct isp1760_qtd *qtd; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1429 | void *buf; |
| 1430 | int len, maxpacket; |
| 1431 | int is_input; |
| 1432 | u32 token; |
| 1433 | |
| 1434 | /* |
| 1435 | * URBs map to sequences of QTDs: one logical transaction |
| 1436 | */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1437 | qtd = isp1760_qtd_alloc(flags); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1438 | if (!qtd) |
| 1439 | return NULL; |
| 1440 | |
| 1441 | list_add_tail(&qtd->qtd_list, head); |
| 1442 | qtd->urb = urb; |
| 1443 | urb->status = -EINPROGRESS; |
| 1444 | |
| 1445 | token = 0; |
| 1446 | /* for split transactions, SplitXState initialized to zero */ |
| 1447 | |
| 1448 | len = urb->transfer_buffer_length; |
| 1449 | is_input = usb_pipein(urb->pipe); |
| 1450 | if (usb_pipecontrol(urb->pipe)) { |
| 1451 | /* SETUP pid */ |
| 1452 | qtd_fill(qtd, urb->setup_packet, |
| 1453 | sizeof(struct usb_ctrlrequest), |
| 1454 | token | SETUP_PID); |
| 1455 | |
| 1456 | /* ... and always at least one more pid */ |
| 1457 | token ^= DATA_TOGGLE; |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1458 | qtd = isp1760_qtd_alloc(flags); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1459 | if (!qtd) |
| 1460 | goto cleanup; |
| 1461 | qtd->urb = urb; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1462 | list_add_tail(&qtd->qtd_list, head); |
| 1463 | |
| 1464 | /* for zero length DATA stages, STATUS is always IN */ |
| 1465 | if (len == 0) |
| 1466 | token |= IN_PID; |
| 1467 | } |
| 1468 | |
| 1469 | /* |
| 1470 | * data transfer stage: buffer setup |
| 1471 | */ |
| 1472 | buf = urb->transfer_buffer; |
| 1473 | |
| 1474 | if (is_input) |
| 1475 | token |= IN_PID; |
| 1476 | else |
| 1477 | token |= OUT_PID; |
| 1478 | |
| 1479 | maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input)); |
| 1480 | |
| 1481 | /* |
| 1482 | * buffer gets wrapped in one or more qtds; |
| 1483 | * last one may be "short" (including zero len) |
| 1484 | * and may serve as a control status ack |
| 1485 | */ |
| 1486 | for (;;) { |
| 1487 | int this_qtd_len; |
| 1488 | |
| 1489 | if (!buf && len) { |
| 1490 | /* XXX This looks like usb storage / SCSI bug */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1491 | dev_err(hcd->self.controller, "buf is null, dma is %08lx len is %d\n", |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1492 | (long unsigned)urb->transfer_dma, len); |
| 1493 | WARN_ON(1); |
| 1494 | } |
| 1495 | |
| 1496 | this_qtd_len = qtd_fill(qtd, buf, len, token); |
| 1497 | len -= this_qtd_len; |
| 1498 | buf += this_qtd_len; |
| 1499 | |
| 1500 | /* qh makes control packets use qtd toggle; maybe switch it */ |
| 1501 | if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0) |
| 1502 | token ^= DATA_TOGGLE; |
| 1503 | |
| 1504 | if (len <= 0) |
| 1505 | break; |
| 1506 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1507 | qtd = isp1760_qtd_alloc(flags); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1508 | if (!qtd) |
| 1509 | goto cleanup; |
| 1510 | qtd->urb = urb; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1511 | list_add_tail(&qtd->qtd_list, head); |
| 1512 | } |
| 1513 | |
| 1514 | /* |
| 1515 | * control requests may need a terminating data "status" ack; |
| 1516 | * bulk ones may need a terminating short packet (zero length). |
| 1517 | */ |
| 1518 | if (urb->transfer_buffer_length != 0) { |
| 1519 | int one_more = 0; |
| 1520 | |
| 1521 | if (usb_pipecontrol(urb->pipe)) { |
| 1522 | one_more = 1; |
| 1523 | /* "in" <--> "out" */ |
| 1524 | token ^= IN_PID; |
| 1525 | /* force DATA1 */ |
| 1526 | token |= DATA_TOGGLE; |
| 1527 | } else if (usb_pipebulk(urb->pipe) |
| 1528 | && (urb->transfer_flags & URB_ZERO_PACKET) |
| 1529 | && !(urb->transfer_buffer_length % maxpacket)) { |
| 1530 | one_more = 1; |
| 1531 | } |
| 1532 | if (one_more) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1533 | qtd = isp1760_qtd_alloc(flags); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1534 | if (!qtd) |
| 1535 | goto cleanup; |
| 1536 | qtd->urb = urb; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1537 | list_add_tail(&qtd->qtd_list, head); |
| 1538 | |
| 1539 | /* never any data in such packets */ |
| 1540 | qtd_fill(qtd, NULL, 0, token); |
| 1541 | } |
| 1542 | } |
| 1543 | |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1544 | qtd->status = 0; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1545 | return head; |
| 1546 | |
| 1547 | cleanup: |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1548 | qtd_list_free(urb, head); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1549 | return NULL; |
| 1550 | } |
| 1551 | |
| 1552 | static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, |
| 1553 | gfp_t mem_flags) |
| 1554 | { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1555 | struct list_head qtd_list; |
| 1556 | packet_enqueue *pe; |
| 1557 | |
| 1558 | INIT_LIST_HEAD(&qtd_list); |
| 1559 | |
| 1560 | switch (usb_pipetype(urb->pipe)) { |
| 1561 | case PIPE_CONTROL: |
| 1562 | case PIPE_BULK: |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1563 | if (!qh_urb_transaction(hcd, urb, &qtd_list, mem_flags)) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1564 | return -ENOMEM; |
| 1565 | pe = enqueue_an_ATL_packet; |
| 1566 | break; |
| 1567 | |
| 1568 | case PIPE_INTERRUPT: |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1569 | if (!qh_urb_transaction(hcd, urb, &qtd_list, mem_flags)) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1570 | return -ENOMEM; |
| 1571 | pe = enqueue_an_INT_packet; |
| 1572 | break; |
| 1573 | |
| 1574 | case PIPE_ISOCHRONOUS: |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1575 | dev_err(hcd->self.controller, "PIPE_ISOCHRONOUS ain't supported\n"); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1576 | default: |
| 1577 | return -EPIPE; |
| 1578 | } |
| 1579 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1580 | return isp1760_prepare_enqueue(hcd, urb, &qtd_list, mem_flags, pe); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1581 | } |
| 1582 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1583 | static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1584 | { |
| 1585 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1586 | struct inter_packet_info *ints; |
| 1587 | u32 i; |
| 1588 | u32 reg_base, or_reg, skip_reg; |
Andrew Morton | d249afd | 2008-06-09 16:39:52 -0700 | [diff] [blame] | 1589 | unsigned long flags; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1590 | struct ptd ptd; |
Warren Free | 0afb20e | 2009-05-08 10:27:08 +0200 | [diff] [blame] | 1591 | packet_enqueue *pe; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1592 | |
| 1593 | switch (usb_pipetype(urb->pipe)) { |
| 1594 | case PIPE_ISOCHRONOUS: |
| 1595 | return -EPIPE; |
| 1596 | break; |
| 1597 | |
| 1598 | case PIPE_INTERRUPT: |
| 1599 | ints = priv->int_ints; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1600 | reg_base = INT_PTD_OFFSET; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1601 | or_reg = HC_INT_IRQ_MASK_OR_REG; |
| 1602 | skip_reg = HC_INT_PTD_SKIPMAP_REG; |
Warren Free | 0afb20e | 2009-05-08 10:27:08 +0200 | [diff] [blame] | 1603 | pe = enqueue_an_INT_packet; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1604 | break; |
| 1605 | |
| 1606 | default: |
| 1607 | ints = priv->atl_ints; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1608 | reg_base = ATL_PTD_OFFSET; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1609 | or_reg = HC_ATL_IRQ_MASK_OR_REG; |
| 1610 | skip_reg = HC_ATL_PTD_SKIPMAP_REG; |
Warren Free | 0afb20e | 2009-05-08 10:27:08 +0200 | [diff] [blame] | 1611 | pe = enqueue_an_ATL_packet; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1612 | break; |
| 1613 | } |
| 1614 | |
| 1615 | memset(&ptd, 0, sizeof(ptd)); |
| 1616 | spin_lock_irqsave(&priv->lock, flags); |
| 1617 | |
| 1618 | for (i = 0; i < 32; i++) { |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1619 | if (!ints[i].qh) |
| 1620 | continue; |
| 1621 | BUG_ON(!ints[i].qtd); |
| 1622 | |
| 1623 | if (ints[i].qtd->urb == urb) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1624 | u32 skip_map; |
| 1625 | u32 or_map; |
| 1626 | struct isp1760_qtd *qtd; |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1627 | struct isp1760_qh *qh; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1628 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1629 | skip_map = reg_read32(hcd->regs, skip_reg); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1630 | skip_map |= 1 << i; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1631 | reg_write32(hcd->regs, skip_reg, skip_map); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1632 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1633 | or_map = reg_read32(hcd->regs, or_reg); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1634 | or_map &= ~(1 << i); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1635 | reg_write32(hcd->regs, or_reg, or_map); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1636 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1637 | ptd_write(hcd->regs, reg_base, i, &ptd); |
| 1638 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1639 | qtd = ints->qtd; |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1640 | qh = ints[i].qh; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1641 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1642 | free_mem(hcd, qtd); |
Arvid Brodin | a041d8e | 2011-02-26 22:04:40 +0100 | [diff] [blame] | 1643 | qtd = clean_up_qtdlist(qtd, qh); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1644 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1645 | ints->qh = NULL; |
| 1646 | ints->qtd = NULL; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1647 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1648 | isp1760_urb_done(hcd, urb); |
Warren Free | 0afb20e | 2009-05-08 10:27:08 +0200 | [diff] [blame] | 1649 | if (qtd) |
| 1650 | pe(hcd, qh, qtd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1651 | break; |
Warren Free | 0afb20e | 2009-05-08 10:27:08 +0200 | [diff] [blame] | 1652 | |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1653 | } else { |
| 1654 | struct isp1760_qtd *qtd; |
Warren Free | 0afb20e | 2009-05-08 10:27:08 +0200 | [diff] [blame] | 1655 | |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1656 | list_for_each_entry(qtd, &ints[i].qtd->qtd_list, |
| 1657 | qtd_list) { |
Warren Free | 0afb20e | 2009-05-08 10:27:08 +0200 | [diff] [blame] | 1658 | if (qtd->urb == urb) { |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1659 | clean_up_qtdlist(qtd, ints[i].qh); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1660 | isp1760_urb_done(hcd, urb); |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1661 | qtd = NULL; |
Warren Free | 0afb20e | 2009-05-08 10:27:08 +0200 | [diff] [blame] | 1662 | break; |
| 1663 | } |
Warren Free | 0afb20e | 2009-05-08 10:27:08 +0200 | [diff] [blame] | 1664 | } |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 1665 | |
| 1666 | /* We found the urb before the last slot */ |
| 1667 | if (!qtd) |
Warren Free | 0afb20e | 2009-05-08 10:27:08 +0200 | [diff] [blame] | 1668 | break; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1669 | } |
| 1670 | ints++; |
| 1671 | } |
| 1672 | |
| 1673 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1674 | return 0; |
| 1675 | } |
| 1676 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1677 | static irqreturn_t isp1760_irq(struct usb_hcd *hcd) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1678 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1679 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1680 | u32 imask; |
| 1681 | irqreturn_t irqret = IRQ_NONE; |
| 1682 | |
| 1683 | spin_lock(&priv->lock); |
| 1684 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1685 | if (!(hcd->state & HC_STATE_RUNNING)) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1686 | goto leave; |
| 1687 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1688 | imask = reg_read32(hcd->regs, HC_INTERRUPT_REG); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1689 | if (unlikely(!imask)) |
| 1690 | goto leave; |
| 1691 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1692 | reg_write32(hcd->regs, HC_INTERRUPT_REG, imask); |
Sebastian Andrzej Siewior | b14e840 | 2011-02-08 21:07:40 +0100 | [diff] [blame] | 1693 | if (imask & (HC_ATL_INT | HC_SOT_INT)) |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1694 | do_atl_int(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1695 | |
| 1696 | if (imask & HC_INTL_INT) |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1697 | do_intl_int(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1698 | |
| 1699 | irqret = IRQ_HANDLED; |
| 1700 | leave: |
| 1701 | spin_unlock(&priv->lock); |
| 1702 | return irqret; |
| 1703 | } |
| 1704 | |
| 1705 | static int isp1760_hub_status_data(struct usb_hcd *hcd, char *buf) |
| 1706 | { |
| 1707 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1708 | u32 temp, status = 0; |
| 1709 | u32 mask; |
| 1710 | int retval = 1; |
| 1711 | unsigned long flags; |
| 1712 | |
| 1713 | /* if !USB_SUSPEND, root hub timers won't get shut down ... */ |
| 1714 | if (!HC_IS_RUNNING(hcd->state)) |
| 1715 | return 0; |
| 1716 | |
| 1717 | /* init status to no-changes */ |
| 1718 | buf[0] = 0; |
| 1719 | mask = PORT_CSC; |
| 1720 | |
| 1721 | spin_lock_irqsave(&priv->lock, flags); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1722 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1723 | |
| 1724 | if (temp & PORT_OWNER) { |
| 1725 | if (temp & PORT_CSC) { |
| 1726 | temp &= ~PORT_CSC; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1727 | reg_write32(hcd->regs, HC_PORTSC1, temp); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1728 | goto done; |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | /* |
| 1733 | * Return status information even for ports with OWNER set. |
| 1734 | * Otherwise khubd wouldn't see the disconnect event when a |
| 1735 | * high-speed device is switched over to the companion |
| 1736 | * controller by the user. |
| 1737 | */ |
| 1738 | |
| 1739 | if ((temp & mask) != 0 |
| 1740 | || ((temp & PORT_RESUME) != 0 |
| 1741 | && time_after_eq(jiffies, |
| 1742 | priv->reset_done))) { |
| 1743 | buf [0] |= 1 << (0 + 1); |
| 1744 | status = STS_PCD; |
| 1745 | } |
| 1746 | /* FIXME autosuspend idle root hubs */ |
| 1747 | done: |
| 1748 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1749 | return status ? retval : 0; |
| 1750 | } |
| 1751 | |
| 1752 | static void isp1760_hub_descriptor(struct isp1760_hcd *priv, |
| 1753 | struct usb_hub_descriptor *desc) |
| 1754 | { |
| 1755 | int ports = HCS_N_PORTS(priv->hcs_params); |
| 1756 | u16 temp; |
| 1757 | |
| 1758 | desc->bDescriptorType = 0x29; |
| 1759 | /* priv 1.0, 2.3.9 says 20ms max */ |
| 1760 | desc->bPwrOn2PwrGood = 10; |
| 1761 | desc->bHubContrCurrent = 0; |
| 1762 | |
| 1763 | desc->bNbrPorts = ports; |
| 1764 | temp = 1 + (ports / 8); |
| 1765 | desc->bDescLength = 7 + 2 * temp; |
| 1766 | |
| 1767 | /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ |
| 1768 | memset(&desc->bitmap[0], 0, temp); |
| 1769 | memset(&desc->bitmap[temp], 0xff, temp); |
| 1770 | |
| 1771 | /* per-port overcurrent reporting */ |
| 1772 | temp = 0x0008; |
| 1773 | if (HCS_PPC(priv->hcs_params)) |
| 1774 | /* per-port power control */ |
| 1775 | temp |= 0x0001; |
| 1776 | else |
| 1777 | /* no power switching */ |
| 1778 | temp |= 0x0002; |
| 1779 | desc->wHubCharacteristics = cpu_to_le16(temp); |
| 1780 | } |
| 1781 | |
| 1782 | #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) |
| 1783 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1784 | static int check_reset_complete(struct usb_hcd *hcd, int index, |
| 1785 | int port_status) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1786 | { |
| 1787 | if (!(port_status & PORT_CONNECT)) |
| 1788 | return port_status; |
| 1789 | |
| 1790 | /* if reset finished and it's still not enabled -- handoff */ |
| 1791 | if (!(port_status & PORT_PE)) { |
| 1792 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1793 | dev_err(hcd->self.controller, |
| 1794 | "port %d full speed --> companion\n", |
| 1795 | index + 1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1796 | |
| 1797 | port_status |= PORT_OWNER; |
| 1798 | port_status &= ~PORT_RWC_BITS; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1799 | reg_write32(hcd->regs, HC_PORTSC1, port_status); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1800 | |
| 1801 | } else |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1802 | dev_err(hcd->self.controller, "port %d high speed\n", |
| 1803 | index + 1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1804 | |
| 1805 | return port_status; |
| 1806 | } |
| 1807 | |
| 1808 | static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, |
| 1809 | u16 wValue, u16 wIndex, char *buf, u16 wLength) |
| 1810 | { |
| 1811 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1812 | int ports = HCS_N_PORTS(priv->hcs_params); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1813 | u32 temp, status; |
| 1814 | unsigned long flags; |
| 1815 | int retval = 0; |
| 1816 | unsigned selector; |
| 1817 | |
| 1818 | /* |
| 1819 | * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR. |
| 1820 | * HCS_INDICATOR may say we can change LEDs to off/amber/green. |
| 1821 | * (track current state ourselves) ... blink for diagnostics, |
| 1822 | * power, "this is the one", etc. EHCI spec supports this. |
| 1823 | */ |
| 1824 | |
| 1825 | spin_lock_irqsave(&priv->lock, flags); |
| 1826 | switch (typeReq) { |
| 1827 | case ClearHubFeature: |
| 1828 | switch (wValue) { |
| 1829 | case C_HUB_LOCAL_POWER: |
| 1830 | case C_HUB_OVER_CURRENT: |
| 1831 | /* no hub-wide feature/status flags */ |
| 1832 | break; |
| 1833 | default: |
| 1834 | goto error; |
| 1835 | } |
| 1836 | break; |
| 1837 | case ClearPortFeature: |
| 1838 | if (!wIndex || wIndex > ports) |
| 1839 | goto error; |
| 1840 | wIndex--; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1841 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1842 | |
| 1843 | /* |
| 1844 | * Even if OWNER is set, so the port is owned by the |
| 1845 | * companion controller, khubd needs to be able to clear |
| 1846 | * the port-change status bits (especially |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1847 | * USB_PORT_STAT_C_CONNECTION). |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1848 | */ |
| 1849 | |
| 1850 | switch (wValue) { |
| 1851 | case USB_PORT_FEAT_ENABLE: |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1852 | reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_PE); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1853 | break; |
| 1854 | case USB_PORT_FEAT_C_ENABLE: |
| 1855 | /* XXX error? */ |
| 1856 | break; |
| 1857 | case USB_PORT_FEAT_SUSPEND: |
| 1858 | if (temp & PORT_RESET) |
| 1859 | goto error; |
| 1860 | |
| 1861 | if (temp & PORT_SUSPEND) { |
| 1862 | if ((temp & PORT_PE) == 0) |
| 1863 | goto error; |
| 1864 | /* resume signaling for 20 msec */ |
| 1865 | temp &= ~(PORT_RWC_BITS); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1866 | reg_write32(hcd->regs, HC_PORTSC1, |
| 1867 | temp | PORT_RESUME); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1868 | priv->reset_done = jiffies + |
| 1869 | msecs_to_jiffies(20); |
| 1870 | } |
| 1871 | break; |
| 1872 | case USB_PORT_FEAT_C_SUSPEND: |
| 1873 | /* we auto-clear this feature */ |
| 1874 | break; |
| 1875 | case USB_PORT_FEAT_POWER: |
| 1876 | if (HCS_PPC(priv->hcs_params)) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1877 | reg_write32(hcd->regs, HC_PORTSC1, |
| 1878 | temp & ~PORT_POWER); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1879 | break; |
| 1880 | case USB_PORT_FEAT_C_CONNECTION: |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1881 | reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_CSC); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1882 | break; |
| 1883 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 1884 | /* XXX error ?*/ |
| 1885 | break; |
| 1886 | case USB_PORT_FEAT_C_RESET: |
| 1887 | /* GetPortStatus clears reset */ |
| 1888 | break; |
| 1889 | default: |
| 1890 | goto error; |
| 1891 | } |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1892 | reg_read32(hcd->regs, HC_USBCMD); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1893 | break; |
| 1894 | case GetHubDescriptor: |
| 1895 | isp1760_hub_descriptor(priv, (struct usb_hub_descriptor *) |
| 1896 | buf); |
| 1897 | break; |
| 1898 | case GetHubStatus: |
| 1899 | /* no hub-wide feature/status flags */ |
| 1900 | memset(buf, 0, 4); |
| 1901 | break; |
| 1902 | case GetPortStatus: |
| 1903 | if (!wIndex || wIndex > ports) |
| 1904 | goto error; |
| 1905 | wIndex--; |
| 1906 | status = 0; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1907 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1908 | |
| 1909 | /* wPortChange bits */ |
| 1910 | if (temp & PORT_CSC) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1911 | status |= USB_PORT_STAT_C_CONNECTION << 16; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1912 | |
| 1913 | |
| 1914 | /* whoever resumes must GetPortStatus to complete it!! */ |
| 1915 | if (temp & PORT_RESUME) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1916 | dev_err(hcd->self.controller, "Port resume should be skipped.\n"); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1917 | |
| 1918 | /* Remote Wakeup received? */ |
| 1919 | if (!priv->reset_done) { |
| 1920 | /* resume signaling for 20 msec */ |
| 1921 | priv->reset_done = jiffies |
| 1922 | + msecs_to_jiffies(20); |
| 1923 | /* check the port again */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1924 | mod_timer(&hcd->rh_timer, priv->reset_done); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | /* resume completed? */ |
| 1928 | else if (time_after_eq(jiffies, |
| 1929 | priv->reset_done)) { |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1930 | status |= USB_PORT_STAT_C_SUSPEND << 16; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1931 | priv->reset_done = 0; |
| 1932 | |
| 1933 | /* stop resume signaling */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1934 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
| 1935 | reg_write32(hcd->regs, HC_PORTSC1, |
| 1936 | temp & ~(PORT_RWC_BITS | PORT_RESUME)); |
| 1937 | retval = handshake(hcd, HC_PORTSC1, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1938 | PORT_RESUME, 0, 2000 /* 2msec */); |
| 1939 | if (retval != 0) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1940 | dev_err(hcd->self.controller, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1941 | "port %d resume error %d\n", |
| 1942 | wIndex + 1, retval); |
| 1943 | goto error; |
| 1944 | } |
| 1945 | temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10)); |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | /* whoever resets must GetPortStatus to complete it!! */ |
| 1950 | if ((temp & PORT_RESET) |
| 1951 | && time_after_eq(jiffies, |
| 1952 | priv->reset_done)) { |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1953 | status |= USB_PORT_STAT_C_RESET << 16; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1954 | priv->reset_done = 0; |
| 1955 | |
| 1956 | /* force reset to complete */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1957 | reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_RESET); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1958 | /* REVISIT: some hardware needs 550+ usec to clear |
| 1959 | * this bit; seems too long to spin routinely... |
| 1960 | */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1961 | retval = handshake(hcd, HC_PORTSC1, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1962 | PORT_RESET, 0, 750); |
| 1963 | if (retval != 0) { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1964 | dev_err(hcd->self.controller, "port %d reset error %d\n", |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1965 | wIndex + 1, retval); |
| 1966 | goto error; |
| 1967 | } |
| 1968 | |
| 1969 | /* see what we found out */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 1970 | temp = check_reset_complete(hcd, wIndex, |
| 1971 | reg_read32(hcd->regs, HC_PORTSC1)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1972 | } |
| 1973 | /* |
| 1974 | * Even if OWNER is set, there's no harm letting khubd |
| 1975 | * see the wPortStatus values (they should all be 0 except |
| 1976 | * for PORT_POWER anyway). |
| 1977 | */ |
| 1978 | |
| 1979 | if (temp & PORT_OWNER) |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1980 | dev_err(hcd->self.controller, "PORT_OWNER is set\n"); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1981 | |
| 1982 | if (temp & PORT_CONNECT) { |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1983 | status |= USB_PORT_STAT_CONNECTION; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1984 | /* status may be from integrated TT */ |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 1985 | status |= USB_PORT_STAT_HIGH_SPEED; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1986 | } |
| 1987 | if (temp & PORT_PE) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1988 | status |= USB_PORT_STAT_ENABLE; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1989 | if (temp & (PORT_SUSPEND|PORT_RESUME)) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1990 | status |= USB_PORT_STAT_SUSPEND; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1991 | if (temp & PORT_RESET) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1992 | status |= USB_PORT_STAT_RESET; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1993 | if (temp & PORT_POWER) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 1994 | status |= USB_PORT_STAT_POWER; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 1995 | |
| 1996 | put_unaligned(cpu_to_le32(status), (__le32 *) buf); |
| 1997 | break; |
| 1998 | case SetHubFeature: |
| 1999 | switch (wValue) { |
| 2000 | case C_HUB_LOCAL_POWER: |
| 2001 | case C_HUB_OVER_CURRENT: |
| 2002 | /* no hub-wide feature/status flags */ |
| 2003 | break; |
| 2004 | default: |
| 2005 | goto error; |
| 2006 | } |
| 2007 | break; |
| 2008 | case SetPortFeature: |
| 2009 | selector = wIndex >> 8; |
| 2010 | wIndex &= 0xff; |
| 2011 | if (!wIndex || wIndex > ports) |
| 2012 | goto error; |
| 2013 | wIndex--; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2014 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2015 | if (temp & PORT_OWNER) |
| 2016 | break; |
| 2017 | |
| 2018 | /* temp &= ~PORT_RWC_BITS; */ |
| 2019 | switch (wValue) { |
| 2020 | case USB_PORT_FEAT_ENABLE: |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2021 | reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_PE); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2022 | break; |
| 2023 | |
| 2024 | case USB_PORT_FEAT_SUSPEND: |
| 2025 | if ((temp & PORT_PE) == 0 |
| 2026 | || (temp & PORT_RESET) != 0) |
| 2027 | goto error; |
| 2028 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2029 | reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_SUSPEND); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2030 | break; |
| 2031 | case USB_PORT_FEAT_POWER: |
| 2032 | if (HCS_PPC(priv->hcs_params)) |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2033 | reg_write32(hcd->regs, HC_PORTSC1, |
| 2034 | temp | PORT_POWER); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2035 | break; |
| 2036 | case USB_PORT_FEAT_RESET: |
| 2037 | if (temp & PORT_RESUME) |
| 2038 | goto error; |
| 2039 | /* line status bits may report this as low speed, |
| 2040 | * which can be fine if this root hub has a |
| 2041 | * transaction translator built in. |
| 2042 | */ |
| 2043 | if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT |
| 2044 | && PORT_USB11(temp)) { |
| 2045 | temp |= PORT_OWNER; |
| 2046 | } else { |
| 2047 | temp |= PORT_RESET; |
| 2048 | temp &= ~PORT_PE; |
| 2049 | |
| 2050 | /* |
| 2051 | * caller must wait, then call GetPortStatus |
| 2052 | * usb 2.0 spec says 50 ms resets on root |
| 2053 | */ |
| 2054 | priv->reset_done = jiffies + |
| 2055 | msecs_to_jiffies(50); |
| 2056 | } |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2057 | reg_write32(hcd->regs, HC_PORTSC1, temp); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2058 | break; |
| 2059 | default: |
| 2060 | goto error; |
| 2061 | } |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2062 | reg_read32(hcd->regs, HC_USBCMD); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2063 | break; |
| 2064 | |
| 2065 | default: |
| 2066 | error: |
| 2067 | /* "stall" on error */ |
| 2068 | retval = -EPIPE; |
| 2069 | } |
| 2070 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2071 | return retval; |
| 2072 | } |
| 2073 | |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 2074 | static void isp1760_endpoint_disable(struct usb_hcd *hcd, |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2075 | struct usb_host_endpoint *ep) |
| 2076 | { |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 2077 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2078 | struct isp1760_qh *qh; |
| 2079 | struct isp1760_qtd *qtd; |
Andrew Morton | d249afd | 2008-06-09 16:39:52 -0700 | [diff] [blame] | 2080 | unsigned long flags; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2081 | |
| 2082 | spin_lock_irqsave(&priv->lock, flags); |
| 2083 | qh = ep->hcpriv; |
| 2084 | if (!qh) |
| 2085 | goto out; |
| 2086 | |
| 2087 | ep->hcpriv = NULL; |
| 2088 | do { |
| 2089 | /* more than entry might get removed */ |
| 2090 | if (list_empty(&qh->qtd_list)) |
| 2091 | break; |
| 2092 | |
| 2093 | qtd = list_first_entry(&qh->qtd_list, struct isp1760_qtd, |
| 2094 | qtd_list); |
| 2095 | |
| 2096 | if (qtd->status & URB_ENQUEUED) { |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2097 | spin_unlock_irqrestore(&priv->lock, flags); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 2098 | isp1760_urb_dequeue(hcd, qtd->urb, -ECONNRESET); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2099 | spin_lock_irqsave(&priv->lock, flags); |
| 2100 | } else { |
| 2101 | struct urb *urb; |
| 2102 | |
| 2103 | urb = qtd->urb; |
Arvid Brodin | fd436ae | 2011-02-26 22:03:49 +0100 | [diff] [blame] | 2104 | clean_up_qtdlist(qtd, qh); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 2105 | urb->status = -ECONNRESET; |
| 2106 | isp1760_urb_done(hcd, urb); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2107 | } |
| 2108 | } while (1); |
| 2109 | |
| 2110 | qh_destroy(qh); |
| 2111 | /* remove requests and leak them. |
| 2112 | * ATL are pretty fast done, INT could take a while... |
| 2113 | * The latter shoule be removed |
| 2114 | */ |
| 2115 | out: |
| 2116 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2117 | } |
| 2118 | |
| 2119 | static int isp1760_get_frame(struct usb_hcd *hcd) |
| 2120 | { |
| 2121 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 2122 | u32 fr; |
| 2123 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2124 | fr = reg_read32(hcd->regs, HC_FRINDEX); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2125 | return (fr >> 3) % priv->periodic_size; |
| 2126 | } |
| 2127 | |
| 2128 | static void isp1760_stop(struct usb_hcd *hcd) |
| 2129 | { |
| 2130 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 2131 | u32 temp; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2132 | |
| 2133 | isp1760_hub_control(hcd, ClearPortFeature, USB_PORT_FEAT_POWER, 1, |
| 2134 | NULL, 0); |
| 2135 | mdelay(20); |
| 2136 | |
| 2137 | spin_lock_irq(&priv->lock); |
Arvid Brodin | 6bda21b | 2011-02-26 22:06:37 +0100 | [diff] [blame] | 2138 | ehci_reset(hcd); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2139 | /* Disable IRQ */ |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2140 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); |
| 2141 | 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] | 2142 | spin_unlock_irq(&priv->lock); |
| 2143 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2144 | reg_write32(hcd->regs, HC_CONFIGFLAG, 0); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | static void isp1760_shutdown(struct usb_hcd *hcd) |
| 2148 | { |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 2149 | u32 command, temp; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2150 | |
| 2151 | isp1760_stop(hcd); |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2152 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); |
| 2153 | 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] | 2154 | |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2155 | command = reg_read32(hcd->regs, HC_USBCMD); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2156 | command &= ~CMD_RUN; |
Arvid Brodin | bedc0c3 | 2011-02-26 22:02:57 +0100 | [diff] [blame] | 2157 | reg_write32(hcd->regs, HC_USBCMD, command); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | static const struct hc_driver isp1760_hc_driver = { |
| 2161 | .description = "isp1760-hcd", |
| 2162 | .product_desc = "NXP ISP1760 USB Host Controller", |
| 2163 | .hcd_priv_size = sizeof(struct isp1760_hcd), |
| 2164 | .irq = isp1760_irq, |
| 2165 | .flags = HCD_MEMORY | HCD_USB2, |
| 2166 | .reset = isp1760_hc_setup, |
| 2167 | .start = isp1760_run, |
| 2168 | .stop = isp1760_stop, |
| 2169 | .shutdown = isp1760_shutdown, |
| 2170 | .urb_enqueue = isp1760_urb_enqueue, |
| 2171 | .urb_dequeue = isp1760_urb_dequeue, |
| 2172 | .endpoint_disable = isp1760_endpoint_disable, |
| 2173 | .get_frame_number = isp1760_get_frame, |
| 2174 | .hub_status_data = isp1760_hub_status_data, |
| 2175 | .hub_control = isp1760_hub_control, |
| 2176 | }; |
| 2177 | |
| 2178 | int __init init_kmem_once(void) |
| 2179 | { |
| 2180 | qtd_cachep = kmem_cache_create("isp1760_qtd", |
| 2181 | sizeof(struct isp1760_qtd), 0, SLAB_TEMPORARY | |
| 2182 | SLAB_MEM_SPREAD, NULL); |
| 2183 | |
| 2184 | if (!qtd_cachep) |
| 2185 | return -ENOMEM; |
| 2186 | |
| 2187 | qh_cachep = kmem_cache_create("isp1760_qh", sizeof(struct isp1760_qh), |
| 2188 | 0, SLAB_TEMPORARY | SLAB_MEM_SPREAD, NULL); |
| 2189 | |
| 2190 | if (!qh_cachep) { |
| 2191 | kmem_cache_destroy(qtd_cachep); |
| 2192 | return -ENOMEM; |
| 2193 | } |
| 2194 | |
| 2195 | return 0; |
| 2196 | } |
| 2197 | |
| 2198 | void deinit_kmem_cache(void) |
| 2199 | { |
| 2200 | kmem_cache_destroy(qtd_cachep); |
| 2201 | kmem_cache_destroy(qh_cachep); |
| 2202 | } |
| 2203 | |
Catalin Marinas | f9031f2 | 2009-02-10 16:55:45 +0000 | [diff] [blame] | 2204 | struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len, |
| 2205 | int irq, unsigned long irqflags, |
| 2206 | struct device *dev, const char *busname, |
| 2207 | unsigned int devflags) |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2208 | { |
| 2209 | struct usb_hcd *hcd; |
| 2210 | struct isp1760_hcd *priv; |
| 2211 | int ret; |
| 2212 | |
| 2213 | if (usb_disabled()) |
| 2214 | return ERR_PTR(-ENODEV); |
| 2215 | |
| 2216 | /* prevent usb-core allocating DMA pages */ |
| 2217 | dev->dma_mask = NULL; |
| 2218 | |
Kay Sievers | 0031a06 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 2219 | hcd = usb_create_hcd(&isp1760_hc_driver, dev, dev_name(dev)); |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2220 | if (!hcd) |
| 2221 | return ERR_PTR(-ENOMEM); |
| 2222 | |
| 2223 | priv = hcd_to_priv(hcd); |
Nate Case | 3faefc8 | 2008-06-17 11:11:38 -0500 | [diff] [blame] | 2224 | priv->devflags = devflags; |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2225 | init_memory(priv); |
| 2226 | hcd->regs = ioremap(res_start, res_len); |
| 2227 | if (!hcd->regs) { |
| 2228 | ret = -EIO; |
| 2229 | goto err_put; |
| 2230 | } |
| 2231 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2232 | hcd->irq = irq; |
| 2233 | hcd->rsrc_start = res_start; |
| 2234 | hcd->rsrc_len = res_len; |
| 2235 | |
Nate Case | e6942d6 | 2008-05-21 16:28:20 -0500 | [diff] [blame] | 2236 | ret = usb_add_hcd(hcd, irq, irqflags); |
| 2237 | if (ret) |
| 2238 | goto err_unmap; |
| 2239 | |
Sebastian Siewior | db11e47 | 2008-04-24 00:37:04 +0200 | [diff] [blame] | 2240 | return hcd; |
| 2241 | |
| 2242 | err_unmap: |
| 2243 | iounmap(hcd->regs); |
| 2244 | |
| 2245 | err_put: |
| 2246 | usb_put_hcd(hcd); |
| 2247 | |
| 2248 | return ERR_PTR(ret); |
| 2249 | } |
| 2250 | |
| 2251 | MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP"); |
| 2252 | MODULE_AUTHOR("Sebastian Siewior <bigeasy@linuxtronix.de>"); |
| 2253 | MODULE_LICENSE("GPL v2"); |