diff options
author | Alexander Shishkin <alexander.shishkin@linux.intel.com> | 2012-05-08 16:28:59 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-05-09 17:51:24 -0400 |
commit | 262c16320a915c26c927c9f7ddb0e1fe42fa0267 (patch) | |
tree | 99ed755e312bf2728823db8360319d339c48a675 | |
parent | d3595d132b9f8641501fcc84d831a5d6fed2b29d (diff) |
usb: gadget: ci13xxx: redo register access
Use lookup table instead of conditional macrodefinitions of register
addresses. With two different possible register layouts and different
register offsets, it's easiest to build a table with register addresses
at probe time, based on the information supplied from the platform and
device capabilities. This way we get rid of branch-per-register-access.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/usb/gadget/ci13xxx_udc.c | 293 | ||||
-rw-r--r-- | drivers/usb/gadget/ci13xxx_udc.h | 26 |
2 files changed, 191 insertions, 128 deletions
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c index 02739707aabc..3b47ca1b64ee 100644 --- a/drivers/usb/gadget/ci13xxx_udc.c +++ b/drivers/usb/gadget/ci13xxx_udc.c | |||
@@ -136,26 +136,73 @@ static int ffs_nr(u32 x) | |||
136 | #define ABS_AHBBURST (0x0090UL) | 136 | #define ABS_AHBBURST (0x0090UL) |
137 | #define ABS_AHBMODE (0x0098UL) | 137 | #define ABS_AHBMODE (0x0098UL) |
138 | /* UDC register map */ | 138 | /* UDC register map */ |
139 | #define CAP_CAPLENGTH (0x000UL) | 139 | static uintptr_t ci_regs_nolpm[] = { |
140 | #define CAP_HCCPARAMS (0x008UL) | 140 | [CAP_CAPLENGTH] = 0x000UL, |
141 | #define CAP_DCCPARAMS (0x024UL) | 141 | [CAP_HCCPARAMS] = 0x008UL, |
142 | #define ABS_TESTMODE (udc->hw_bank.lpm ? 0x0FCUL : 0x138UL) | 142 | [CAP_DCCPARAMS] = 0x024UL, |
143 | /* offset to CAPLENTGH (addr + data) */ | 143 | [CAP_TESTMODE] = 0x038UL, |
144 | #define OP_USBCMD (0x000UL) | 144 | [OP_USBCMD] = 0x000UL, |
145 | #define OP_USBSTS (0x004UL) | 145 | [OP_USBSTS] = 0x004UL, |
146 | #define OP_USBINTR (0x008UL) | 146 | [OP_USBINTR] = 0x008UL, |
147 | #define OP_DEVICEADDR (0x014UL) | 147 | [OP_DEVICEADDR] = 0x014UL, |
148 | #define OP_ENDPTLISTADDR (0x018UL) | 148 | [OP_ENDPTLISTADDR] = 0x018UL, |
149 | #define OP_PORTSC (0x044UL) | 149 | [OP_PORTSC] = 0x044UL, |
150 | #define OP_DEVLC (0x084UL) | 150 | [OP_DEVLC] = 0x084UL, |
151 | #define OP_USBMODE (udc->hw_bank.lpm ? 0x0C8UL : 0x068UL) | 151 | [OP_USBMODE] = 0x068UL, |
152 | #define OP_ENDPTSETUPSTAT (udc->hw_bank.lpm ? 0x0D8UL : 0x06CUL) | 152 | [OP_ENDPTSETUPSTAT] = 0x06CUL, |
153 | #define OP_ENDPTPRIME (udc->hw_bank.lpm ? 0x0DCUL : 0x070UL) | 153 | [OP_ENDPTPRIME] = 0x070UL, |
154 | #define OP_ENDPTFLUSH (udc->hw_bank.lpm ? 0x0E0UL : 0x074UL) | 154 | [OP_ENDPTFLUSH] = 0x074UL, |
155 | #define OP_ENDPTSTAT (udc->hw_bank.lpm ? 0x0E4UL : 0x078UL) | 155 | [OP_ENDPTSTAT] = 0x078UL, |
156 | #define OP_ENDPTCOMPLETE (udc->hw_bank.lpm ? 0x0E8UL : 0x07CUL) | 156 | [OP_ENDPTCOMPLETE] = 0x07CUL, |
157 | #define OP_ENDPTCTRL (udc->hw_bank.lpm ? 0x0ECUL : 0x080UL) | 157 | [OP_ENDPTCTRL] = 0x080UL, |
158 | #define OP_LAST (udc->hw_bank.lpm ? 0x12CUL : 0x0C0UL) | 158 | }; |
159 | |||
160 | static uintptr_t ci_regs_lpm[] = { | ||
161 | [CAP_CAPLENGTH] = 0x000UL, | ||
162 | [CAP_HCCPARAMS] = 0x008UL, | ||
163 | [CAP_DCCPARAMS] = 0x024UL, | ||
164 | [CAP_TESTMODE] = 0x0FCUL, | ||
165 | [OP_USBCMD] = 0x000UL, | ||
166 | [OP_USBSTS] = 0x004UL, | ||
167 | [OP_USBINTR] = 0x008UL, | ||
168 | [OP_DEVICEADDR] = 0x014UL, | ||
169 | [OP_ENDPTLISTADDR] = 0x018UL, | ||
170 | [OP_PORTSC] = 0x044UL, | ||
171 | [OP_DEVLC] = 0x084UL, | ||
172 | [OP_USBMODE] = 0x0C8UL, | ||
173 | [OP_ENDPTSETUPSTAT] = 0x0D8UL, | ||
174 | [OP_ENDPTPRIME] = 0x0DCUL, | ||
175 | [OP_ENDPTFLUSH] = 0x0E0UL, | ||
176 | [OP_ENDPTSTAT] = 0x0E4UL, | ||
177 | [OP_ENDPTCOMPLETE] = 0x0E8UL, | ||
178 | [OP_ENDPTCTRL] = 0x0ECUL, | ||
179 | }; | ||
180 | |||
181 | static int hw_alloc_regmap(struct ci13xxx *udc, bool is_lpm) | ||
182 | { | ||
183 | int i; | ||
184 | |||
185 | kfree(udc->hw_bank.regmap); | ||
186 | |||
187 | udc->hw_bank.regmap = kzalloc((OP_LAST + 1) * sizeof(void *), | ||
188 | GFP_KERNEL); | ||
189 | if (!udc->hw_bank.regmap) | ||
190 | return -ENOMEM; | ||
191 | |||
192 | for (i = 0; i < OP_ENDPTCTRL; i++) | ||
193 | udc->hw_bank.regmap[i] = | ||
194 | (i <= CAP_LAST ? udc->hw_bank.cap : udc->hw_bank.op) + | ||
195 | (is_lpm ? ci_regs_lpm[i] : ci_regs_nolpm[i]); | ||
196 | |||
197 | for (; i <= OP_LAST; i++) | ||
198 | udc->hw_bank.regmap[i] = udc->hw_bank.op + | ||
199 | 4 * (i - OP_ENDPTCTRL) + | ||
200 | (is_lpm | ||
201 | ? ci_regs_lpm[OP_ENDPTCTRL] | ||
202 | : ci_regs_nolpm[OP_ENDPTCTRL]); | ||
203 | |||
204 | return 0; | ||
205 | } | ||
159 | 206 | ||
160 | /** | 207 | /** |
161 | * hw_ep_bit: calculates the bit number | 208 | * hw_ep_bit: calculates the bit number |
@@ -180,62 +227,64 @@ static int ep_to_bit(struct ci13xxx *udc, int n) | |||
180 | } | 227 | } |
181 | 228 | ||
182 | /** | 229 | /** |
183 | * hw_read: reads from a register bitfield | 230 | * hw_read: reads from a hw register |
184 | * @base: register block address | 231 | * @reg: register index |
185 | * @addr: address relative to operational register base | ||
186 | * @mask: bitfield mask | 232 | * @mask: bitfield mask |
187 | * | 233 | * |
188 | * This function returns register bitfield data | 234 | * This function returns register contents |
189 | */ | 235 | */ |
190 | static u32 hw_read(void __iomem *base, u32 addr, u32 mask) | 236 | static u32 hw_read(struct ci13xxx *udc, enum ci13xxx_regs reg, u32 mask) |
191 | { | 237 | { |
192 | return ioread32(addr + base) & mask; | 238 | return ioread32(udc->hw_bank.regmap[reg]) & mask; |
193 | } | 239 | } |
194 | 240 | ||
195 | /** | 241 | /** |
196 | * hw_write: writes to a register bitfield | 242 | * hw_write: writes to a hw register |
197 | * @base: register block address | 243 | * @reg: register index |
198 | * @addr: address relative to operational register base | ||
199 | * @mask: bitfield mask | 244 | * @mask: bitfield mask |
200 | * @data: new data | 245 | * @data: new value |
201 | */ | 246 | */ |
202 | static void hw_write(void __iomem *base, u32 addr, u32 mask, u32 data) | 247 | static void hw_write(struct ci13xxx *udc, enum ci13xxx_regs reg, u32 mask, |
248 | u32 data) | ||
203 | { | 249 | { |
204 | iowrite32(hw_read(base, addr, ~mask) | (data & mask), | 250 | if (~mask) |
205 | addr + base); | 251 | data = (ioread32(udc->hw_bank.regmap[reg]) & ~mask) |
252 | | (data & mask); | ||
253 | |||
254 | iowrite32(data, udc->hw_bank.regmap[reg]); | ||
206 | } | 255 | } |
207 | 256 | ||
208 | /** | 257 | /** |
209 | * hw_test_and_clear: tests & clears operational register bitfield | 258 | * hw_test_and_clear: tests & clears a hw register |
210 | * @base: register block address | 259 | * @reg: register index |
211 | * @addr: address relative to operational register base | ||
212 | * @mask: bitfield mask | 260 | * @mask: bitfield mask |
213 | * | 261 | * |
214 | * This function returns register bitfield data | 262 | * This function returns register contents |
215 | */ | 263 | */ |
216 | static u32 hw_test_and_clear(void __iomem *base, u32 addr, u32 mask) | 264 | static u32 hw_test_and_clear(struct ci13xxx *udc, enum ci13xxx_regs reg, |
265 | u32 mask) | ||
217 | { | 266 | { |
218 | u32 reg = hw_read(base, addr, mask); | 267 | u32 val = ioread32(udc->hw_bank.regmap[reg]) & mask; |
219 | 268 | ||
220 | iowrite32(reg, addr + base); | 269 | iowrite32(val, udc->hw_bank.regmap[reg]); |
221 | return reg; | 270 | return val; |
222 | } | 271 | } |
223 | 272 | ||
224 | /** | 273 | /** |
225 | * hw_test_and_write: tests & writes operational register bitfield | 274 | * hw_test_and_write: tests & writes a hw register |
226 | * @base: register block address | 275 | * @reg: register index |
227 | * @addr: address relative to operational register base | ||
228 | * @mask: bitfield mask | 276 | * @mask: bitfield mask |
229 | * @data: new data | 277 | * @data: new value |
230 | * | 278 | * |
231 | * This function returns register bitfield data | 279 | * This function returns register contents |
232 | */ | 280 | */ |
233 | static u32 hw_test_and_write(void __iomem *base, u32 addr, u32 mask, u32 data) | 281 | static u32 hw_test_and_write(struct ci13xxx *udc, enum ci13xxx_regs reg, |
282 | u32 mask, u32 data) | ||
234 | { | 283 | { |
235 | u32 reg = hw_read(base, addr, ~0); | 284 | u32 val = hw_read(udc, reg, ~0); |
236 | 285 | ||
237 | iowrite32((reg & ~mask) | (data & mask), addr + base); | 286 | hw_write(udc, reg, mask, data); |
238 | return (reg & mask) >> ffs_nr(mask); | 287 | return (val & mask) >> ffs_nr(mask); |
239 | } | 288 | } |
240 | 289 | ||
241 | static int hw_device_init(struct ci13xxx *udc, void __iomem *base, | 290 | static int hw_device_init(struct ci13xxx *udc, void __iomem *base, |
@@ -250,14 +299,16 @@ static int hw_device_init(struct ci13xxx *udc, void __iomem *base, | |||
250 | udc->hw_bank.cap += cap_offset; | 299 | udc->hw_bank.cap += cap_offset; |
251 | udc->hw_bank.op = udc->hw_bank.cap + ioread8(udc->hw_bank.cap); | 300 | udc->hw_bank.op = udc->hw_bank.cap + ioread8(udc->hw_bank.cap); |
252 | 301 | ||
253 | reg = hw_read(udc->hw_bank.cap, CAP_HCCPARAMS, HCCPARAMS_LEN) >> | 302 | hw_alloc_regmap(udc, false); |
303 | reg = hw_read(udc, CAP_HCCPARAMS, HCCPARAMS_LEN) >> | ||
254 | ffs_nr(HCCPARAMS_LEN); | 304 | ffs_nr(HCCPARAMS_LEN); |
255 | udc->hw_bank.lpm = reg; | 305 | udc->hw_bank.lpm = reg; |
306 | hw_alloc_regmap(udc, !!reg); | ||
256 | udc->hw_bank.size = udc->hw_bank.op - udc->hw_bank.abs; | 307 | udc->hw_bank.size = udc->hw_bank.op - udc->hw_bank.abs; |
257 | udc->hw_bank.size += OP_LAST; | 308 | udc->hw_bank.size += OP_LAST; |
258 | udc->hw_bank.size /= sizeof(u32); | 309 | udc->hw_bank.size /= sizeof(u32); |
259 | 310 | ||
260 | reg = hw_read(udc->hw_bank.cap, CAP_DCCPARAMS, DCCPARAMS_DEN) >> | 311 | reg = hw_read(udc, CAP_DCCPARAMS, DCCPARAMS_DEN) >> |
261 | ffs_nr(DCCPARAMS_DEN); | 312 | ffs_nr(DCCPARAMS_DEN); |
262 | udc->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ | 313 | udc->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ |
263 | 314 | ||
@@ -281,11 +332,11 @@ static int hw_device_init(struct ci13xxx *udc, void __iomem *base, | |||
281 | static int hw_device_reset(struct ci13xxx *udc) | 332 | static int hw_device_reset(struct ci13xxx *udc) |
282 | { | 333 | { |
283 | /* should flush & stop before reset */ | 334 | /* should flush & stop before reset */ |
284 | hw_write(udc->hw_bank.op, OP_ENDPTFLUSH, ~0, ~0); | 335 | hw_write(udc, OP_ENDPTFLUSH, ~0, ~0); |
285 | hw_write(udc->hw_bank.op, OP_USBCMD, USBCMD_RS, 0); | 336 | hw_write(udc, OP_USBCMD, USBCMD_RS, 0); |
286 | 337 | ||
287 | hw_write(udc->hw_bank.op, OP_USBCMD, USBCMD_RST, USBCMD_RST); | 338 | hw_write(udc, OP_USBCMD, USBCMD_RST, USBCMD_RST); |
288 | while (hw_read(udc->hw_bank.op, OP_USBCMD, USBCMD_RST)) | 339 | while (hw_read(udc, OP_USBCMD, USBCMD_RST)) |
289 | udelay(10); /* not RTOS friendly */ | 340 | udelay(10); /* not RTOS friendly */ |
290 | 341 | ||
291 | 342 | ||
@@ -294,17 +345,15 @@ static int hw_device_reset(struct ci13xxx *udc) | |||
294 | CI13XXX_CONTROLLER_RESET_EVENT); | 345 | CI13XXX_CONTROLLER_RESET_EVENT); |
295 | 346 | ||
296 | if (udc->udc_driver->flags & CI13XXX_DISABLE_STREAMING) | 347 | if (udc->udc_driver->flags & CI13XXX_DISABLE_STREAMING) |
297 | hw_write(udc->hw_bank.op, OP_USBMODE, USBMODE_SDIS, | 348 | hw_write(udc, OP_USBMODE, USBMODE_SDIS, USBMODE_SDIS); |
298 | USBMODE_SDIS); | ||
299 | 349 | ||
300 | /* USBMODE should be configured step by step */ | 350 | /* USBMODE should be configured step by step */ |
301 | hw_write(udc->hw_bank.op, OP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE); | 351 | hw_write(udc, OP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE); |
302 | hw_write(udc->hw_bank.op, OP_USBMODE, USBMODE_CM, USBMODE_CM_DEVICE); | 352 | hw_write(udc, OP_USBMODE, USBMODE_CM, USBMODE_CM_DEVICE); |
303 | /* HW >= 2.3 */ | 353 | /* HW >= 2.3 */ |
304 | hw_write(udc->hw_bank.op, OP_USBMODE, USBMODE_SLOM, USBMODE_SLOM); | 354 | hw_write(udc, OP_USBMODE, USBMODE_SLOM, USBMODE_SLOM); |
305 | 355 | ||
306 | if (hw_read(udc->hw_bank.op, OP_USBMODE, USBMODE_CM) != | 356 | if (hw_read(udc, OP_USBMODE, USBMODE_CM) != USBMODE_CM_DEVICE) { |
307 | USBMODE_CM_DEVICE) { | ||
308 | pr_err("cannot enter in device mode"); | 357 | pr_err("cannot enter in device mode"); |
309 | pr_err("lpm = %i", udc->hw_bank.lpm); | 358 | pr_err("lpm = %i", udc->hw_bank.lpm); |
310 | return -ENODEV; | 359 | return -ENODEV; |
@@ -323,14 +372,14 @@ static int hw_device_reset(struct ci13xxx *udc) | |||
323 | static int hw_device_state(struct ci13xxx *udc, u32 dma) | 372 | static int hw_device_state(struct ci13xxx *udc, u32 dma) |
324 | { | 373 | { |
325 | if (dma) { | 374 | if (dma) { |
326 | hw_write(udc->hw_bank.op, OP_ENDPTLISTADDR, ~0, dma); | 375 | hw_write(udc, OP_ENDPTLISTADDR, ~0, dma); |
327 | /* interrupt, error, port change, reset, sleep/suspend */ | 376 | /* interrupt, error, port change, reset, sleep/suspend */ |
328 | hw_write(udc->hw_bank.op, OP_USBINTR, ~0, | 377 | hw_write(udc, OP_USBINTR, ~0, |
329 | USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); | 378 | USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); |
330 | hw_write(udc->hw_bank.op, OP_USBCMD, USBCMD_RS, USBCMD_RS); | 379 | hw_write(udc, OP_USBCMD, USBCMD_RS, USBCMD_RS); |
331 | } else { | 380 | } else { |
332 | hw_write(udc->hw_bank.op, OP_USBCMD, USBCMD_RS, 0); | 381 | hw_write(udc, OP_USBCMD, USBCMD_RS, 0); |
333 | hw_write(udc->hw_bank.op, OP_USBINTR, ~0, 0); | 382 | hw_write(udc, OP_USBINTR, ~0, 0); |
334 | } | 383 | } |
335 | return 0; | 384 | return 0; |
336 | } | 385 | } |
@@ -348,10 +397,10 @@ static int hw_ep_flush(struct ci13xxx *udc, int num, int dir) | |||
348 | 397 | ||
349 | do { | 398 | do { |
350 | /* flush any pending transfer */ | 399 | /* flush any pending transfer */ |
351 | hw_write(udc->hw_bank.op, OP_ENDPTFLUSH, BIT(n), BIT(n)); | 400 | hw_write(udc, OP_ENDPTFLUSH, BIT(n), BIT(n)); |
352 | while (hw_read(udc->hw_bank.op, OP_ENDPTFLUSH, BIT(n))) | 401 | while (hw_read(udc, OP_ENDPTFLUSH, BIT(n))) |
353 | cpu_relax(); | 402 | cpu_relax(); |
354 | } while (hw_read(udc->hw_bank.op, OP_ENDPTSTAT, BIT(n))); | 403 | } while (hw_read(udc, OP_ENDPTSTAT, BIT(n))); |
355 | 404 | ||
356 | return 0; | 405 | return 0; |
357 | } | 406 | } |
@@ -366,7 +415,7 @@ static int hw_ep_flush(struct ci13xxx *udc, int num, int dir) | |||
366 | static int hw_ep_disable(struct ci13xxx *udc, int num, int dir) | 415 | static int hw_ep_disable(struct ci13xxx *udc, int num, int dir) |
367 | { | 416 | { |
368 | hw_ep_flush(udc, num, dir); | 417 | hw_ep_flush(udc, num, dir); |
369 | hw_write(udc->hw_bank.op, OP_ENDPTCTRL + num * sizeof(u32), | 418 | hw_write(udc, OP_ENDPTCTRL + num, |
370 | dir ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0); | 419 | dir ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0); |
371 | return 0; | 420 | return 0; |
372 | } | 421 | } |
@@ -402,7 +451,7 @@ static int hw_ep_enable(struct ci13xxx *udc, int num, int dir, int type) | |||
402 | mask |= ENDPTCTRL_RXE; /* enable */ | 451 | mask |= ENDPTCTRL_RXE; /* enable */ |
403 | data |= ENDPTCTRL_RXE; | 452 | data |= ENDPTCTRL_RXE; |
404 | } | 453 | } |
405 | hw_write(udc->hw_bank.op, OP_ENDPTCTRL + num * sizeof(u32), mask, data); | 454 | hw_write(udc, OP_ENDPTCTRL + num, mask, data); |
406 | return 0; | 455 | return 0; |
407 | } | 456 | } |
408 | 457 | ||
@@ -417,8 +466,7 @@ static int hw_ep_get_halt(struct ci13xxx *udc, int num, int dir) | |||
417 | { | 466 | { |
418 | u32 mask = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; | 467 | u32 mask = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; |
419 | 468 | ||
420 | return !!hw_read(udc->hw_bank.op, OP_ENDPTCTRL + num * sizeof(u32), | 469 | return hw_read(udc, OP_ENDPTCTRL + num, mask) ? 1 : 0; |
421 | mask); | ||
422 | } | 470 | } |
423 | 471 | ||
424 | /** | 472 | /** |
@@ -431,7 +479,7 @@ static int hw_ep_get_halt(struct ci13xxx *udc, int num, int dir) | |||
431 | static int hw_test_and_clear_setup_status(struct ci13xxx *udc, int n) | 479 | static int hw_test_and_clear_setup_status(struct ci13xxx *udc, int n) |
432 | { | 480 | { |
433 | n = ep_to_bit(udc, n); | 481 | n = ep_to_bit(udc, n); |
434 | return hw_test_and_clear(udc->hw_bank.op, OP_ENDPTSETUPSTAT, BIT(n)); | 482 | return hw_test_and_clear(udc, OP_ENDPTSETUPSTAT, BIT(n)); |
435 | } | 483 | } |
436 | 484 | ||
437 | /** | 485 | /** |
@@ -446,16 +494,14 @@ static int hw_ep_prime(struct ci13xxx *udc, int num, int dir, int is_ctrl) | |||
446 | { | 494 | { |
447 | int n = hw_ep_bit(num, dir); | 495 | int n = hw_ep_bit(num, dir); |
448 | 496 | ||
449 | if (is_ctrl && dir == RX && | 497 | if (is_ctrl && dir == RX && hw_read(udc, OP_ENDPTSETUPSTAT, BIT(num))) |
450 | hw_read(udc->hw_bank.op, OP_ENDPTSETUPSTAT, BIT(num))) | ||
451 | return -EAGAIN; | 498 | return -EAGAIN; |
452 | 499 | ||
453 | hw_write(udc->hw_bank.op, OP_ENDPTPRIME, BIT(n), BIT(n)); | 500 | hw_write(udc, OP_ENDPTPRIME, BIT(n), BIT(n)); |
454 | 501 | ||
455 | while (hw_read(udc->hw_bank.op, OP_ENDPTPRIME, BIT(n))) | 502 | while (hw_read(udc, OP_ENDPTPRIME, BIT(n))) |
456 | cpu_relax(); | 503 | cpu_relax(); |
457 | if (is_ctrl && dir == RX && | 504 | if (is_ctrl && dir == RX && hw_read(udc, OP_ENDPTSETUPSTAT, BIT(num))) |
458 | hw_read(udc->hw_bank.op, OP_ENDPTSETUPSTAT, BIT(num))) | ||
459 | return -EAGAIN; | 505 | return -EAGAIN; |
460 | 506 | ||
461 | /* status shoult be tested according with manual but it doesn't work */ | 507 | /* status shoult be tested according with manual but it doesn't work */ |
@@ -477,14 +523,13 @@ static int hw_ep_set_halt(struct ci13xxx *udc, int num, int dir, int value) | |||
477 | return -EINVAL; | 523 | return -EINVAL; |
478 | 524 | ||
479 | do { | 525 | do { |
480 | u32 addr = OP_ENDPTCTRL + num * sizeof(u32); | 526 | enum ci13xxx_regs reg = OP_ENDPTCTRL + num; |
481 | u32 mask_xs = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; | 527 | u32 mask_xs = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; |
482 | u32 mask_xr = dir ? ENDPTCTRL_TXR : ENDPTCTRL_RXR; | 528 | u32 mask_xr = dir ? ENDPTCTRL_TXR : ENDPTCTRL_RXR; |
483 | 529 | ||
484 | /* data toggle - reserved for EP0 but it's in ESS */ | 530 | /* data toggle - reserved for EP0 but it's in ESS */ |
485 | hw_write(udc->hw_bank.op, addr, mask_xs|mask_xr, | 531 | hw_write(udc, reg, mask_xs|mask_xr, |
486 | value ? mask_xs : mask_xr); | 532 | value ? mask_xs : mask_xr); |
487 | |||
488 | } while (value != hw_ep_get_halt(udc, num, dir)); | 533 | } while (value != hw_ep_get_halt(udc, num, dir)); |
489 | 534 | ||
490 | return 0; | 535 | return 0; |
@@ -502,9 +547,8 @@ static int hw_intr_clear(struct ci13xxx *udc, int n) | |||
502 | if (n >= REG_BITS) | 547 | if (n >= REG_BITS) |
503 | return -EINVAL; | 548 | return -EINVAL; |
504 | 549 | ||
505 | hw_write(udc->hw_bank.op, OP_USBINTR, BIT(n), 0); | 550 | hw_write(udc, OP_USBINTR, BIT(n), 0); |
506 | hw_write(udc->hw_bank.op, OP_USBSTS, BIT(n), BIT(n)); | 551 | hw_write(udc, OP_USBSTS, BIT(n), BIT(n)); |
507 | |||
508 | return 0; | 552 | return 0; |
509 | } | 553 | } |
510 | 554 | ||
@@ -520,11 +564,10 @@ static int hw_intr_force(struct ci13xxx *udc, int n) | |||
520 | if (n >= REG_BITS) | 564 | if (n >= REG_BITS) |
521 | return -EINVAL; | 565 | return -EINVAL; |
522 | 566 | ||
523 | hw_write(udc->hw_bank.cap, ABS_TESTMODE, TESTMODE_FORCE, | 567 | hw_write(udc, CAP_TESTMODE, TESTMODE_FORCE, TESTMODE_FORCE); |
524 | TESTMODE_FORCE); | 568 | hw_write(udc, OP_USBINTR, BIT(n), BIT(n)); |
525 | hw_write(udc->hw_bank.op, OP_USBINTR, BIT(n), BIT(n)); | 569 | hw_write(udc, OP_USBSTS, BIT(n), BIT(n)); |
526 | hw_write(udc->hw_bank.op, OP_USBSTS, BIT(n), BIT(n)); | 570 | hw_write(udc, CAP_TESTMODE, TESTMODE_FORCE, 0); |
527 | hw_write(udc->hw_bank.cap, ABS_TESTMODE, TESTMODE_FORCE, 0); | ||
528 | return 0; | 571 | return 0; |
529 | } | 572 | } |
530 | 573 | ||
@@ -535,9 +578,8 @@ static int hw_intr_force(struct ci13xxx *udc, int n) | |||
535 | */ | 578 | */ |
536 | static int hw_port_is_high_speed(struct ci13xxx *udc) | 579 | static int hw_port_is_high_speed(struct ci13xxx *udc) |
537 | { | 580 | { |
538 | return udc->hw_bank.lpm | 581 | return udc->hw_bank.lpm ? hw_read(udc, OP_DEVLC, DEVLC_PSPD) : |
539 | ? hw_read(udc->hw_bank.op, OP_DEVLC, DEVLC_PSPD) | 582 | hw_read(udc, OP_PORTSC, PORTSC_HSP); |
540 | : hw_read(udc->hw_bank.op, OP_PORTSC, PORTSC_HSP); | ||
541 | } | 583 | } |
542 | 584 | ||
543 | /** | 585 | /** |
@@ -547,8 +589,7 @@ static int hw_port_is_high_speed(struct ci13xxx *udc) | |||
547 | */ | 589 | */ |
548 | static u8 hw_port_test_get(struct ci13xxx *udc) | 590 | static u8 hw_port_test_get(struct ci13xxx *udc) |
549 | { | 591 | { |
550 | return hw_read(udc->hw_bank.op, OP_PORTSC, PORTSC_PTC) >> | 592 | return hw_read(udc, OP_PORTSC, PORTSC_PTC) >> ffs_nr(PORTSC_PTC); |
551 | ffs_nr(PORTSC_PTC); | ||
552 | } | 593 | } |
553 | 594 | ||
554 | /** | 595 | /** |
@@ -564,8 +605,7 @@ static int hw_port_test_set(struct ci13xxx *udc, u8 mode) | |||
564 | if (mode > TEST_MODE_MAX) | 605 | if (mode > TEST_MODE_MAX) |
565 | return -EINVAL; | 606 | return -EINVAL; |
566 | 607 | ||
567 | hw_write(udc->hw_bank.op, OP_PORTSC, PORTSC_PTC, | 608 | hw_write(udc, OP_PORTSC, PORTSC_PTC, mode << ffs_nr(PORTSC_PTC)); |
568 | mode << ffs_nr(PORTSC_PTC)); | ||
569 | return 0; | 609 | return 0; |
570 | } | 610 | } |
571 | 611 | ||
@@ -576,7 +616,7 @@ static int hw_port_test_set(struct ci13xxx *udc, u8 mode) | |||
576 | */ | 616 | */ |
577 | static u32 hw_read_intr_enable(struct ci13xxx *udc) | 617 | static u32 hw_read_intr_enable(struct ci13xxx *udc) |
578 | { | 618 | { |
579 | return hw_read(udc->hw_bank.op, OP_USBINTR, ~0); | 619 | return hw_read(udc, OP_USBINTR, ~0); |
580 | } | 620 | } |
581 | 621 | ||
582 | /** | 622 | /** |
@@ -586,7 +626,7 @@ static u32 hw_read_intr_enable(struct ci13xxx *udc) | |||
586 | */ | 626 | */ |
587 | static u32 hw_read_intr_status(struct ci13xxx *udc) | 627 | static u32 hw_read_intr_status(struct ci13xxx *udc) |
588 | { | 628 | { |
589 | return hw_read(udc->hw_bank.op, OP_USBSTS, ~0); | 629 | return hw_read(udc, OP_USBSTS, ~0); |
590 | } | 630 | } |
591 | 631 | ||
592 | /** | 632 | /** |
@@ -604,7 +644,7 @@ static size_t hw_register_read(struct ci13xxx *udc, u32 *buf, size_t size) | |||
604 | size = udc->hw_bank.size; | 644 | size = udc->hw_bank.size; |
605 | 645 | ||
606 | for (i = 0; i < size; i++) | 646 | for (i = 0; i < size; i++) |
607 | buf[i] = hw_read(udc->hw_bank.cap, i * sizeof(u32), ~0); | 647 | buf[i] = hw_read(udc, i * sizeof(u32), ~0); |
608 | 648 | ||
609 | return size; | 649 | return size; |
610 | } | 650 | } |
@@ -627,7 +667,7 @@ static int hw_register_write(struct ci13xxx *udc, u16 addr, u32 data) | |||
627 | /* align */ | 667 | /* align */ |
628 | addr *= sizeof(u32); | 668 | addr *= sizeof(u32); |
629 | 669 | ||
630 | hw_write(udc->hw_bank.cap, addr, ~0, data); | 670 | hw_write(udc, addr, ~0, data); |
631 | return 0; | 671 | return 0; |
632 | } | 672 | } |
633 | 673 | ||
@@ -641,7 +681,7 @@ static int hw_register_write(struct ci13xxx *udc, u16 addr, u32 data) | |||
641 | static int hw_test_and_clear_complete(struct ci13xxx *udc, int n) | 681 | static int hw_test_and_clear_complete(struct ci13xxx *udc, int n) |
642 | { | 682 | { |
643 | n = ep_to_bit(udc, n); | 683 | n = ep_to_bit(udc, n); |
644 | return hw_test_and_clear(udc->hw_bank.op, OP_ENDPTCOMPLETE, BIT(n)); | 684 | return hw_test_and_clear(udc, OP_ENDPTCOMPLETE, BIT(n)); |
645 | } | 685 | } |
646 | 686 | ||
647 | /** | 687 | /** |
@@ -654,7 +694,7 @@ static u32 hw_test_and_clear_intr_active(struct ci13xxx *udc) | |||
654 | { | 694 | { |
655 | u32 reg = hw_read_intr_status(udc) & hw_read_intr_enable(udc); | 695 | u32 reg = hw_read_intr_status(udc) & hw_read_intr_enable(udc); |
656 | 696 | ||
657 | hw_write(udc->hw_bank.op, OP_USBSTS, ~0, reg); | 697 | hw_write(udc, OP_USBSTS, ~0, reg); |
658 | return reg; | 698 | return reg; |
659 | } | 699 | } |
660 | 700 | ||
@@ -666,7 +706,7 @@ static u32 hw_test_and_clear_intr_active(struct ci13xxx *udc) | |||
666 | */ | 706 | */ |
667 | static int hw_test_and_clear_setup_guard(struct ci13xxx *udc) | 707 | static int hw_test_and_clear_setup_guard(struct ci13xxx *udc) |
668 | { | 708 | { |
669 | return hw_test_and_write(udc->hw_bank.op, OP_USBCMD, USBCMD_SUTW, 0); | 709 | return hw_test_and_write(udc, OP_USBCMD, USBCMD_SUTW, 0); |
670 | } | 710 | } |
671 | 711 | ||
672 | /** | 712 | /** |
@@ -677,8 +717,7 @@ static int hw_test_and_clear_setup_guard(struct ci13xxx *udc) | |||
677 | */ | 717 | */ |
678 | static int hw_test_and_set_setup_guard(struct ci13xxx *udc) | 718 | static int hw_test_and_set_setup_guard(struct ci13xxx *udc) |
679 | { | 719 | { |
680 | return hw_test_and_write(udc->hw_bank.op, OP_USBCMD, USBCMD_SUTW, | 720 | return hw_test_and_write(udc, OP_USBCMD, USBCMD_SUTW, USBCMD_SUTW); |
681 | USBCMD_SUTW); | ||
682 | } | 721 | } |
683 | 722 | ||
684 | /** | 723 | /** |
@@ -690,9 +729,8 @@ static int hw_test_and_set_setup_guard(struct ci13xxx *udc) | |||
690 | static int hw_usb_set_address(struct ci13xxx *udc, u8 value) | 729 | static int hw_usb_set_address(struct ci13xxx *udc, u8 value) |
691 | { | 730 | { |
692 | /* advance */ | 731 | /* advance */ |
693 | hw_write(udc->hw_bank.op, OP_DEVICEADDR, | 732 | hw_write(udc, OP_DEVICEADDR, DEVICEADDR_USBADR | DEVICEADDR_USBADRA, |
694 | DEVICEADDR_USBADR | DEVICEADDR_USBADRA, | 733 | value << ffs_nr(DEVICEADDR_USBADR) | DEVICEADDR_USBADRA); |
695 | value << ffs_nr(DEVICEADDR_USBADR) | DEVICEADDR_USBADRA); | ||
696 | return 0; | 734 | return 0; |
697 | } | 735 | } |
698 | 736 | ||
@@ -707,16 +745,16 @@ static int hw_usb_reset(struct ci13xxx *udc) | |||
707 | hw_usb_set_address(udc, 0); | 745 | hw_usb_set_address(udc, 0); |
708 | 746 | ||
709 | /* ESS flushes only at end?!? */ | 747 | /* ESS flushes only at end?!? */ |
710 | hw_write(udc->hw_bank.op, OP_ENDPTFLUSH, ~0, ~0); | 748 | hw_write(udc, OP_ENDPTFLUSH, ~0, ~0); |
711 | 749 | ||
712 | /* clear setup token semaphores */ | 750 | /* clear setup token semaphores */ |
713 | hw_write(udc->hw_bank.op, OP_ENDPTSETUPSTAT, 0, 0); | 751 | hw_write(udc, OP_ENDPTSETUPSTAT, 0, 0); |
714 | 752 | ||
715 | /* clear complete status */ | 753 | /* clear complete status */ |
716 | hw_write(udc->hw_bank.op, OP_ENDPTCOMPLETE, 0, 0); | 754 | hw_write(udc, OP_ENDPTCOMPLETE, 0, 0); |
717 | 755 | ||
718 | /* wait until all bits cleared */ | 756 | /* wait until all bits cleared */ |
719 | while (hw_read(udc->hw_bank.op, OP_ENDPTPRIME, ~0)) | 757 | while (hw_read(udc, OP_ENDPTPRIME, ~0)) |
720 | udelay(10); /* not RTOS friendly */ | 758 | udelay(10); /* not RTOS friendly */ |
721 | 759 | ||
722 | /* reset all endpoints ? */ | 760 | /* reset all endpoints ? */ |
@@ -1500,15 +1538,13 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) | |||
1500 | else | 1538 | else |
1501 | mReqPrev->ptr->next = mReq->dma & TD_ADDR_MASK; | 1539 | mReqPrev->ptr->next = mReq->dma & TD_ADDR_MASK; |
1502 | wmb(); | 1540 | wmb(); |
1503 | if (hw_read(udc->hw_bank.op, OP_ENDPTPRIME, BIT(n))) | 1541 | if (hw_read(udc, OP_ENDPTPRIME, BIT(n))) |
1504 | goto done; | 1542 | goto done; |
1505 | do { | 1543 | do { |
1506 | hw_write(udc->hw_bank.op, OP_USBCMD, USBCMD_ATDTW, | 1544 | hw_write(udc, OP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW); |
1507 | USBCMD_ATDTW); | 1545 | tmp_stat = hw_read(udc, OP_ENDPTSTAT, BIT(n)); |
1508 | tmp_stat = hw_read(udc->hw_bank.op, OP_ENDPTSTAT, | 1546 | } while (!hw_read(udc, OP_USBCMD, USBCMD_ATDTW)); |
1509 | BIT(n)); | 1547 | hw_write(udc, OP_USBCMD, USBCMD_ATDTW, 0); |
1510 | } while (!hw_read(udc->hw_bank.op, OP_USBCMD, USBCMD_ATDTW)); | ||
1511 | hw_write(udc->hw_bank.op, OP_USBCMD, USBCMD_ATDTW, 0); | ||
1512 | if (tmp_stat) | 1548 | if (tmp_stat) |
1513 | goto done; | 1549 | goto done; |
1514 | } | 1550 | } |
@@ -2513,12 +2549,12 @@ static int ci13xxx_wakeup(struct usb_gadget *_gadget) | |||
2513 | trace("remote wakeup feature is not enabled\n"); | 2549 | trace("remote wakeup feature is not enabled\n"); |
2514 | goto out; | 2550 | goto out; |
2515 | } | 2551 | } |
2516 | if (!hw_read(udc->hw_bank.op, OP_PORTSC, PORTSC_SUSP)) { | 2552 | if (!hw_read(udc, OP_PORTSC, PORTSC_SUSP)) { |
2517 | ret = -EINVAL; | 2553 | ret = -EINVAL; |
2518 | trace("port is not suspended\n"); | 2554 | trace("port is not suspended\n"); |
2519 | goto out; | 2555 | goto out; |
2520 | } | 2556 | } |
2521 | hw_write(udc->hw_bank.op, OP_PORTSC, PORTSC_FPR, PORTSC_FPR); | 2557 | hw_write(udc, OP_PORTSC, PORTSC_FPR, PORTSC_FPR); |
2522 | out: | 2558 | out: |
2523 | spin_unlock_irqrestore(&udc->lock, flags); | 2559 | spin_unlock_irqrestore(&udc->lock, flags); |
2524 | return ret; | 2560 | return ret; |
@@ -2786,8 +2822,8 @@ static irqreturn_t udc_irq(void) | |||
2786 | spin_lock(&udc->lock); | 2822 | spin_lock(&udc->lock); |
2787 | 2823 | ||
2788 | if (udc->udc_driver->flags & CI13XXX_REGS_SHARED) { | 2824 | if (udc->udc_driver->flags & CI13XXX_REGS_SHARED) { |
2789 | if (hw_read(udc->hw_bank.op, OP_USBMODE, USBMODE_CM) != | 2825 | if (hw_read(udc, OP_USBMODE, USBMODE_CM) != |
2790 | USBMODE_CM_DEVICE) { | 2826 | USBMODE_CM_DEVICE) { |
2791 | spin_unlock(&udc->lock); | 2827 | spin_unlock(&udc->lock); |
2792 | return IRQ_NONE; | 2828 | return IRQ_NONE; |
2793 | } | 2829 | } |
@@ -2993,6 +3029,7 @@ static void udc_remove(void) | |||
2993 | #endif | 3029 | #endif |
2994 | device_unregister(&udc->gadget.dev); | 3030 | device_unregister(&udc->gadget.dev); |
2995 | 3031 | ||
3032 | kfree(udc->hw_bank.regmap); | ||
2996 | kfree(udc); | 3033 | kfree(udc); |
2997 | _udc = NULL; | 3034 | _udc = NULL; |
2998 | } | 3035 | } |
diff --git a/drivers/usb/gadget/ci13xxx_udc.h b/drivers/usb/gadget/ci13xxx_udc.h index c48be0516d98..f17ffecc36c2 100644 --- a/drivers/usb/gadget/ci13xxx_udc.h +++ b/drivers/usb/gadget/ci13xxx_udc.h | |||
@@ -120,6 +120,7 @@ struct hw_bank { | |||
120 | void __iomem *cap; /* bus map offset + CAP offset */ | 120 | void __iomem *cap; /* bus map offset + CAP offset */ |
121 | void __iomem *op; /* bus map offset + OP offset */ | 121 | void __iomem *op; /* bus map offset + OP offset */ |
122 | size_t size; /* bank size */ | 122 | size_t size; /* bank size */ |
123 | void *__iomem *regmap; | ||
123 | }; | 124 | }; |
124 | 125 | ||
125 | /* CI13XXX UDC descriptor & global resources */ | 126 | /* CI13XXX UDC descriptor & global resources */ |
@@ -158,6 +159,31 @@ struct ci13xxx { | |||
158 | /* register size */ | 159 | /* register size */ |
159 | #define REG_BITS (32) | 160 | #define REG_BITS (32) |
160 | 161 | ||
162 | /* register indices */ | ||
163 | enum ci13xxx_regs { | ||
164 | CAP_CAPLENGTH, | ||
165 | CAP_HCCPARAMS, | ||
166 | CAP_DCCPARAMS, | ||
167 | CAP_TESTMODE, | ||
168 | CAP_LAST = CAP_TESTMODE, | ||
169 | OP_USBCMD, | ||
170 | OP_USBSTS, | ||
171 | OP_USBINTR, | ||
172 | OP_DEVICEADDR, | ||
173 | OP_ENDPTLISTADDR, | ||
174 | OP_PORTSC, | ||
175 | OP_DEVLC, | ||
176 | OP_USBMODE, | ||
177 | OP_ENDPTSETUPSTAT, | ||
178 | OP_ENDPTPRIME, | ||
179 | OP_ENDPTFLUSH, | ||
180 | OP_ENDPTSTAT, | ||
181 | OP_ENDPTCOMPLETE, | ||
182 | OP_ENDPTCTRL, | ||
183 | /* endptctrl1..15 follow */ | ||
184 | OP_LAST = OP_ENDPTCTRL + ENDPT_MAX / 2, | ||
185 | }; | ||
186 | |||
161 | /* HCCPARAMS */ | 187 | /* HCCPARAMS */ |
162 | #define HCCPARAMS_LEN BIT(17) | 188 | #define HCCPARAMS_LEN BIT(17) |
163 | 189 | ||