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