Make global variables that are specific for each UDC instance part of struct ci13xxx. Signed-off-by: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx> --- drivers/usb/gadget/ci13xxx_udc.c | 486 +++++++++++++++++++------------------- drivers/usb/gadget/ci13xxx_udc.h | 14 +- 2 files changed, 252 insertions(+), 248 deletions(-) diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c index 9da5044..a9d7737 100644 --- a/drivers/usb/gadget/ci13xxx_udc.c +++ b/drivers/usb/gadget/ci13xxx_udc.c @@ -74,9 +74,6 @@ #define DMA_ADDR_INVALID (~(dma_addr_t)0) -/* ctrl register bank access */ -static DEFINE_SPINLOCK(udc_lock); - /* control endpoint description */ static const struct usb_endpoint_descriptor ctrl_endpt_out_desc = { @@ -134,14 +131,6 @@ static int ffs_nr(u32 x) /****************************************************************************** * HW block *****************************************************************************/ -/* register bank descriptor */ -static struct { - unsigned lpm; /* is LPM? */ - void __iomem *abs; /* bus map offset */ - void __iomem *cap; /* bus map offset + CAP offset */ - void __iomem *op; /* bus map offset + OP offset */ - size_t size; /* bank size */ -} hw_bank; /* MSM specific */ #define ABS_AHBBURST (0x0090UL) @@ -150,7 +139,7 @@ static struct { #define CAP_CAPLENGTH (0x000UL) #define CAP_HCCPARAMS (0x008UL) #define CAP_DCCPARAMS (0x024UL) -#define ABS_TESTMODE (hw_bank.lpm ? 0x0FCUL : 0x138UL) +#define ABS_TESTMODE (udc->hw_bank.lpm ? 0x0FCUL : 0x138UL) /* offset to CAPLENTGH (addr + data) */ #define OP_USBCMD (0x000UL) #define OP_USBSTS (0x004UL) @@ -159,17 +148,14 @@ static struct { #define OP_ENDPTLISTADDR (0x018UL) #define OP_PORTSC (0x044UL) #define OP_DEVLC (0x084UL) -#define OP_USBMODE (hw_bank.lpm ? 0x0C8UL : 0x068UL) -#define OP_ENDPTSETUPSTAT (hw_bank.lpm ? 0x0D8UL : 0x06CUL) -#define OP_ENDPTPRIME (hw_bank.lpm ? 0x0DCUL : 0x070UL) -#define OP_ENDPTFLUSH (hw_bank.lpm ? 0x0E0UL : 0x074UL) -#define OP_ENDPTSTAT (hw_bank.lpm ? 0x0E4UL : 0x078UL) -#define OP_ENDPTCOMPLETE (hw_bank.lpm ? 0x0E8UL : 0x07CUL) -#define OP_ENDPTCTRL (hw_bank.lpm ? 0x0ECUL : 0x080UL) -#define OP_LAST (hw_bank.lpm ? 0x12CUL : 0x0C0UL) - -/* maximum number of enpoints: valid only after hw_device_reset() */ -static unsigned hw_ep_max; +#define OP_USBMODE (udc->hw_bank.lpm ? 0x0C8UL : 0x068UL) +#define OP_ENDPTSETUPSTAT (udc->hw_bank.lpm ? 0x0D8UL : 0x06CUL) +#define OP_ENDPTPRIME (udc->hw_bank.lpm ? 0x0DCUL : 0x070UL) +#define OP_ENDPTFLUSH (udc->hw_bank.lpm ? 0x0E0UL : 0x074UL) +#define OP_ENDPTSTAT (udc->hw_bank.lpm ? 0x0E4UL : 0x078UL) +#define OP_ENDPTCOMPLETE (udc->hw_bank.lpm ? 0x0E8UL : 0x07CUL) +#define OP_ENDPTCTRL (udc->hw_bank.lpm ? 0x0ECUL : 0x080UL) +#define OP_LAST (udc->hw_bank.lpm ? 0x12CUL : 0x0C0UL) /** * hw_ep_bit: calculates the bit number @@ -183,11 +169,11 @@ static inline int hw_ep_bit(int num, int dir) return num + (dir ? 16 : 0); } -static int ep_to_bit(int n) +static int ep_to_bit(struct ci13xxx *udc, int n) { - int fill = 16 - hw_ep_max / 2; + int fill = 16 - udc->hw_ep_max / 2; - if (n >= hw_ep_max / 2) + if (n >= udc->hw_ep_max / 2) n += fill; return n; @@ -200,9 +186,9 @@ static int ep_to_bit(int n) * * This function returns register bitfield data */ -static u32 hw_cread(u32 addr, u32 mask) +static u32 hw_cread(struct ci13xxx *udc, u32 addr, u32 mask) { - return ioread32(addr + hw_bank.cap) & mask; + return ioread32(addr + udc->hw_bank.cap) & mask; } /** @@ -211,10 +197,10 @@ static u32 hw_cread(u32 addr, u32 mask) * @mask: bitfield mask * @data: new data */ -static void hw_cwrite(u32 addr, u32 mask, u32 data) +static void hw_cwrite(struct ci13xxx *udc, u32 addr, u32 mask, u32 data) { - iowrite32(hw_cread(addr, ~mask) | (data & mask), - addr + hw_bank.cap); + iowrite32(hw_cread(udc, addr, ~mask) | (data & mask), + addr + udc->hw_bank.cap); } /** @@ -224,9 +210,9 @@ static void hw_cwrite(u32 addr, u32 mask, u32 data) * * This function returns register bitfield data */ -static u32 hw_oread(u32 addr, u32 mask) +static u32 hw_oread(struct ci13xxx *udc, u32 addr, u32 mask) { - return ioread32(addr + hw_bank.op) & mask; + return ioread32(addr + udc->hw_bank.op) & mask; } /** @@ -235,10 +221,10 @@ static u32 hw_oread(u32 addr, u32 mask) * @mask: bitfield mask * @data: new data */ -static void hw_owrite(u32 addr, u32 mask, u32 data) +static void hw_owrite(struct ci13xxx *udc, u32 addr, u32 mask, u32 data) { - iowrite32(hw_oread(addr, ~mask) | (data & mask), - addr + hw_bank.op); + iowrite32(hw_oread(udc, addr, ~mask) | (data & mask), + addr + udc->hw_bank.op); } /** @@ -248,11 +234,11 @@ static void hw_owrite(u32 addr, u32 mask, u32 data) * * This function returns register bitfield data */ -static u32 hw_otest_and_clear(u32 addr, u32 mask) +static u32 hw_otest_and_clear(struct ci13xxx *udc, u32 addr, u32 mask) { - u32 reg = hw_oread(addr, mask); + u32 reg = hw_oread(udc, addr, mask); - iowrite32(reg, addr + hw_bank.op); + iowrite32(reg, addr + udc->hw_bank.op); return reg; } @@ -264,35 +250,38 @@ static u32 hw_otest_and_clear(u32 addr, u32 mask) * * This function returns register bitfield data */ -static u32 hw_otest_and_write(u32 addr, u32 mask, u32 data) +static u32 hw_otest_and_write(struct ci13xxx *udc, u32 addr, u32 mask, u32 data) { - u32 reg = hw_oread(addr, ~0); + u32 reg = hw_oread(udc, addr, ~0); - iowrite32((reg & ~mask) | (data & mask), addr + hw_bank.op); + iowrite32((reg & ~mask) | (data & mask), addr + udc->hw_bank.op); return (reg & mask) >> ffs_nr(mask); } -static int hw_device_init(void __iomem *base, uintptr_t cap_offset) +static int hw_device_init(struct ci13xxx *udc, void __iomem *base, + uintptr_t cap_offset) { u32 reg; /* bank is a module variable */ - hw_bank.abs = base; + udc->hw_bank.abs = base; - hw_bank.cap = hw_bank.abs; - hw_bank.cap += cap_offset; - hw_bank.op = hw_bank.cap + ioread8(hw_bank.cap); + udc->hw_bank.cap = udc->hw_bank.abs; + udc->hw_bank.cap += cap_offset; + udc->hw_bank.op = udc->hw_bank.cap + ioread8(udc->hw_bank.cap); - reg = hw_cread(CAP_HCCPARAMS, HCCPARAMS_LEN) >> ffs_nr(HCCPARAMS_LEN); - hw_bank.lpm = reg; - hw_bank.size = hw_bank.op - hw_bank.abs; - hw_bank.size += OP_LAST; - hw_bank.size /= sizeof(u32); + reg = hw_cread(udc, CAP_HCCPARAMS, HCCPARAMS_LEN) >> + ffs_nr(HCCPARAMS_LEN); + udc->hw_bank.lpm = reg; + udc->hw_bank.size = udc->hw_bank.op - udc->hw_bank.abs; + udc->hw_bank.size += OP_LAST; + udc->hw_bank.size /= sizeof(u32); - reg = hw_cread(CAP_DCCPARAMS, DCCPARAMS_DEN) >> ffs_nr(DCCPARAMS_DEN); - hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ + reg = hw_cread(udc, CAP_DCCPARAMS, DCCPARAMS_DEN) >> + ffs_nr(DCCPARAMS_DEN); + udc->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ - if (hw_ep_max == 0 || hw_ep_max > ENDPT_MAX) + if (udc->hw_ep_max == 0 || udc->hw_ep_max > ENDPT_MAX) return -ENODEV; /* setup lock mode ? */ @@ -312,11 +301,11 @@ static int hw_device_init(void __iomem *base, uintptr_t cap_offset) static int hw_device_reset(struct ci13xxx *udc) { /* should flush & stop before reset */ - hw_owrite(OP_ENDPTFLUSH, ~0, ~0); - hw_owrite(OP_USBCMD, USBCMD_RS, 0); + hw_owrite(udc, OP_ENDPTFLUSH, ~0, ~0); + hw_owrite(udc, OP_USBCMD, USBCMD_RS, 0); - hw_owrite(OP_USBCMD, USBCMD_RST, USBCMD_RST); - while (hw_oread(OP_USBCMD, USBCMD_RST)) + hw_owrite(udc, OP_USBCMD, USBCMD_RST, USBCMD_RST); + while (hw_oread(udc, OP_USBCMD, USBCMD_RST)) udelay(10); /* not RTOS friendly */ @@ -325,16 +314,16 @@ static int hw_device_reset(struct ci13xxx *udc) CI13XXX_CONTROLLER_RESET_EVENT); if (udc->udc_driver->flags & CI13XXX_DISABLE_STREAMING) - hw_owrite(OP_USBMODE, USBMODE_SDIS, USBMODE_SDIS); + hw_owrite(udc, OP_USBMODE, USBMODE_SDIS, USBMODE_SDIS); /* USBMODE should be configured step by step */ - hw_owrite(OP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE); - hw_owrite(OP_USBMODE, USBMODE_CM, USBMODE_CM_DEVICE); - hw_owrite(OP_USBMODE, USBMODE_SLOM, USBMODE_SLOM); /* HW >= 2.3 */ + hw_owrite(udc, OP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE); + hw_owrite(udc, OP_USBMODE, USBMODE_CM, USBMODE_CM_DEVICE); + hw_owrite(udc, OP_USBMODE, USBMODE_SLOM, USBMODE_SLOM); /* HW >= 2.3 */ - if (hw_oread(OP_USBMODE, USBMODE_CM) != USBMODE_CM_DEVICE) { + if (hw_oread(udc, OP_USBMODE, USBMODE_CM) != USBMODE_CM_DEVICE) { pr_err("cannot enter in device mode"); - pr_err("lpm = %i", hw_bank.lpm); + pr_err("lpm = %i", udc->hw_bank.lpm); return -ENODEV; } @@ -348,17 +337,17 @@ static int hw_device_reset(struct ci13xxx *udc) * * This function returns an error code */ -static int hw_device_state(u32 dma) +static int hw_device_state(struct ci13xxx *udc, u32 dma) { if (dma) { - hw_owrite(OP_ENDPTLISTADDR, ~0, dma); + hw_owrite(udc, OP_ENDPTLISTADDR, ~0, dma); /* interrupt, error, port change, reset, sleep/suspend */ - hw_owrite(OP_USBINTR, ~0, + hw_owrite(udc, OP_USBINTR, ~0, USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); - hw_owrite(OP_USBCMD, USBCMD_RS, USBCMD_RS); + hw_owrite(udc, OP_USBCMD, USBCMD_RS, USBCMD_RS); } else { - hw_owrite(OP_USBCMD, USBCMD_RS, 0); - hw_owrite(OP_USBINTR, ~0, 0); + hw_owrite(udc, OP_USBCMD, USBCMD_RS, 0); + hw_owrite(udc, OP_USBINTR, ~0, 0); } return 0; } @@ -370,16 +359,16 @@ static int hw_device_state(u32 dma) * * This function returns an error code */ -static int hw_ep_flush(int num, int dir) +static int hw_ep_flush(struct ci13xxx *udc, int num, int dir) { int n = hw_ep_bit(num, dir); do { /* flush any pending transfer */ - hw_owrite(OP_ENDPTFLUSH, BIT(n), BIT(n)); - while (hw_oread(OP_ENDPTFLUSH, BIT(n))) + hw_owrite(udc, OP_ENDPTFLUSH, BIT(n), BIT(n)); + while (hw_oread(udc, OP_ENDPTFLUSH, BIT(n))) cpu_relax(); - } while (hw_oread(OP_ENDPTSTAT, BIT(n))); + } while (hw_oread(udc, OP_ENDPTSTAT, BIT(n))); return 0; } @@ -391,10 +380,10 @@ static int hw_ep_flush(int num, int dir) * * This function returns an error code */ -static int hw_ep_disable(int num, int dir) +static int hw_ep_disable(struct ci13xxx *udc, int num, int dir) { - hw_ep_flush(num, dir); - hw_owrite(OP_ENDPTCTRL + num * sizeof(u32), + hw_ep_flush(udc, num, dir); + hw_owrite(udc, OP_ENDPTCTRL + num * sizeof(u32), dir ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0); return 0; } @@ -407,7 +396,7 @@ static int hw_ep_disable(int num, int dir) * * This function returns an error code */ -static int hw_ep_enable(int num, int dir, int type) +static int hw_ep_enable(struct ci13xxx *udc, int num, int dir, int type) { u32 mask, data; @@ -430,7 +419,7 @@ static int hw_ep_enable(int num, int dir, int type) mask |= ENDPTCTRL_RXE; /* enable */ data |= ENDPTCTRL_RXE; } - hw_owrite(OP_ENDPTCTRL + num * sizeof(u32), mask, data); + hw_owrite(udc, OP_ENDPTCTRL + num * sizeof(u32), mask, data); return 0; } @@ -441,11 +430,11 @@ static int hw_ep_enable(int num, int dir, int type) * * This function returns 1 if endpoint halted */ -static int hw_ep_get_halt(int num, int dir) +static int hw_ep_get_halt(struct ci13xxx *udc, int num, int dir) { u32 mask = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; - return hw_oread(OP_ENDPTCTRL + num * sizeof(u32), mask) ? 1 : 0; + return hw_oread(udc, OP_ENDPTCTRL + num * sizeof(u32), mask) ? 1 : 0; } /** @@ -455,10 +444,10 @@ static int hw_ep_get_halt(int num, int dir) * * This function returns setup status */ -static int hw_test_and_clear_setup_status(int n) +static int hw_test_and_clear_setup_status(struct ci13xxx *udc, int n) { - n = ep_to_bit(n); - return hw_otest_and_clear(OP_ENDPTSETUPSTAT, BIT(n)); + n = ep_to_bit(udc, n); + return hw_otest_and_clear(udc, OP_ENDPTSETUPSTAT, BIT(n)); } /** @@ -469,18 +458,18 @@ static int hw_test_and_clear_setup_status(int n) * * This function returns an error code */ -static int hw_ep_prime(int num, int dir, int is_ctrl) +static int hw_ep_prime(struct ci13xxx *udc, int num, int dir, int is_ctrl) { int n = hw_ep_bit(num, dir); - if (is_ctrl && dir == RX && hw_oread(OP_ENDPTSETUPSTAT, BIT(num))) + if (is_ctrl && dir == RX && hw_oread(udc, OP_ENDPTSETUPSTAT, BIT(num))) return -EAGAIN; - hw_owrite(OP_ENDPTPRIME, BIT(n), BIT(n)); + hw_owrite(udc, OP_ENDPTPRIME, BIT(n), BIT(n)); - while (hw_oread(OP_ENDPTPRIME, BIT(n))) + while (hw_oread(udc, OP_ENDPTPRIME, BIT(n))) cpu_relax(); - if (is_ctrl && dir == RX && hw_oread(OP_ENDPTSETUPSTAT, BIT(num))) + if (is_ctrl && dir == RX && hw_oread(udc, OP_ENDPTSETUPSTAT, BIT(num))) return -EAGAIN; /* status shoult be tested according with manual but it doesn't work */ @@ -496,7 +485,7 @@ static int hw_ep_prime(int num, int dir, int is_ctrl) * * This function returns an error code */ -static int hw_ep_set_halt(int num, int dir, int value) +static int hw_ep_set_halt(struct ci13xxx *udc, int num, int dir, int value) { if (value != 0 && value != 1) return -EINVAL; @@ -507,9 +496,9 @@ static int hw_ep_set_halt(int num, int dir, int value) u32 mask_xr = dir ? ENDPTCTRL_TXR : ENDPTCTRL_RXR; /* data toggle - reserved for EP0 but it's in ESS */ - hw_owrite(addr, mask_xs|mask_xr, value ? mask_xs : mask_xr); - - } while (value != hw_ep_get_halt(num, dir)); + hw_owrite(udc, addr, mask_xs|mask_xr, + value ? mask_xs : mask_xr); + } while (value != hw_ep_get_halt(udc, num, dir)); return 0; } @@ -521,13 +510,13 @@ static int hw_ep_set_halt(int num, int dir, int value) * * This function returns an error code */ -static int hw_intr_clear(int n) +static int hw_intr_clear(struct ci13xxx *udc, int n) { if (n >= REG_BITS) return -EINVAL; - hw_owrite(OP_USBINTR, BIT(n), 0); - hw_owrite(OP_USBSTS, BIT(n), BIT(n)); + hw_owrite(udc, OP_USBINTR, BIT(n), 0); + hw_owrite(udc, OP_USBSTS, BIT(n), BIT(n)); return 0; } @@ -538,15 +527,15 @@ static int hw_intr_clear(int n) * * This function returns an error code */ -static int hw_intr_force(int n) +static int hw_intr_force(struct ci13xxx *udc, int n) { if (n >= REG_BITS) return -EINVAL; - hw_cwrite(ABS_TESTMODE, TESTMODE_FORCE, TESTMODE_FORCE); - hw_owrite(OP_USBINTR, BIT(n), BIT(n)); - hw_owrite(OP_USBSTS, BIT(n), BIT(n)); - hw_cwrite(ABS_TESTMODE, TESTMODE_FORCE, 0); + hw_cwrite(udc, ABS_TESTMODE, TESTMODE_FORCE, TESTMODE_FORCE); + hw_owrite(udc, OP_USBINTR, BIT(n), BIT(n)); + hw_owrite(udc, OP_USBSTS, BIT(n), BIT(n)); + hw_cwrite(udc, ABS_TESTMODE, TESTMODE_FORCE, 0); return 0; } @@ -555,10 +544,10 @@ static int hw_intr_force(int n) * * This function returns true if high speed port */ -static int hw_port_is_high_speed(void) +static int hw_port_is_high_speed(struct ci13xxx *udc) { - return hw_bank.lpm ? hw_oread(OP_DEVLC, DEVLC_PSPD) : - hw_oread(OP_PORTSC, PORTSC_HSP); + return udc->hw_bank.lpm ? hw_oread(udc, OP_DEVLC, DEVLC_PSPD) : + hw_oread(udc, OP_PORTSC, PORTSC_HSP); } /** @@ -566,9 +555,9 @@ static int hw_port_is_high_speed(void) * * This function returns port test mode value */ -static u8 hw_port_test_get(void) +static u8 hw_port_test_get(struct ci13xxx *udc) { - return hw_oread(OP_PORTSC, PORTSC_PTC) >> ffs_nr(PORTSC_PTC); + return hw_oread(udc, OP_PORTSC, PORTSC_PTC) >> ffs_nr(PORTSC_PTC); } /** @@ -577,14 +566,14 @@ static u8 hw_port_test_get(void) * * This function returns an error code */ -static int hw_port_test_set(u8 mode) +static int hw_port_test_set(struct ci13xxx *udc, u8 mode) { const u8 TEST_MODE_MAX = 7; if (mode > TEST_MODE_MAX) return -EINVAL; - hw_owrite(OP_PORTSC, PORTSC_PTC, mode << ffs_nr(PORTSC_PTC)); + hw_owrite(udc, OP_PORTSC, PORTSC_PTC, mode << ffs_nr(PORTSC_PTC)); return 0; } @@ -593,9 +582,9 @@ static int hw_port_test_set(u8 mode) * * This function returns register data */ -static u32 hw_read_intr_enable(void) +static u32 hw_read_intr_enable(struct ci13xxx *udc) { - return hw_oread(OP_USBINTR, ~0); + return hw_oread(udc, OP_USBINTR, ~0); } /** @@ -603,9 +592,9 @@ static u32 hw_read_intr_enable(void) * * This function returns register data */ -static u32 hw_read_intr_status(void) +static u32 hw_read_intr_status(struct ci13xxx *udc) { - return hw_oread(OP_USBSTS, ~0); + return hw_oread(udc, OP_USBSTS, ~0); } /** @@ -615,15 +604,15 @@ static u32 hw_read_intr_status(void) * * This function returns number of registers read */ -static size_t hw_register_read(u32 *buf, size_t size) +static size_t hw_register_read(struct ci13xxx *udc, u32 *buf, size_t size) { unsigned i; - if (size > hw_bank.size) - size = hw_bank.size; + if (size > udc->hw_bank.size) + size = udc->hw_bank.size; for (i = 0; i < size; i++) - buf[i] = hw_cread(i * sizeof(u32), ~0); + buf[i] = hw_cread(udc, i * sizeof(u32), ~0); return size; } @@ -635,18 +624,18 @@ static size_t hw_register_read(u32 *buf, size_t size) * * This function returns an error code */ -static int hw_register_write(u16 addr, u32 data) +static int hw_register_write(struct ci13xxx *udc, u16 addr, u32 data) { /* align */ addr /= sizeof(u32); - if (addr >= hw_bank.size) + if (addr >= udc->hw_bank.size) return -EINVAL; /* align */ addr *= sizeof(u32); - hw_cwrite(addr, ~0, data); + hw_cwrite(udc, addr, ~0, data); return 0; } @@ -657,10 +646,10 @@ static int hw_register_write(u16 addr, u32 data) * * This function returns complete status */ -static int hw_test_and_clear_complete(int n) +static int hw_test_and_clear_complete(struct ci13xxx *udc, int n) { - n = ep_to_bit(n); - return hw_otest_and_clear(OP_ENDPTCOMPLETE, BIT(n)); + n = ep_to_bit(udc, n); + return hw_otest_and_clear(udc, OP_ENDPTCOMPLETE, BIT(n)); } /** @@ -669,11 +658,11 @@ static int hw_test_and_clear_complete(int n) * * This function returns active interrutps */ -static u32 hw_test_and_clear_intr_active(void) +static u32 hw_test_and_clear_intr_active(struct ci13xxx *udc) { - u32 reg = hw_read_intr_status() & hw_read_intr_enable(); + u32 reg = hw_read_intr_status(udc) & hw_read_intr_enable(udc); - hw_owrite(OP_USBSTS, ~0, reg); + hw_owrite(udc, OP_USBSTS, ~0, reg); return reg; } @@ -683,9 +672,9 @@ static u32 hw_test_and_clear_intr_active(void) * * This function returns guard value */ -static int hw_test_and_clear_setup_guard(void) +static int hw_test_and_clear_setup_guard(struct ci13xxx *udc) { - return hw_otest_and_write(OP_USBCMD, USBCMD_SUTW, 0); + return hw_otest_and_write(udc, OP_USBCMD, USBCMD_SUTW, 0); } /** @@ -694,9 +683,9 @@ static int hw_test_and_clear_setup_guard(void) * * This function returns guard value */ -static int hw_test_and_set_setup_guard(void) +static int hw_test_and_set_setup_guard(struct ci13xxx *udc) { - return hw_otest_and_write(OP_USBCMD, USBCMD_SUTW, USBCMD_SUTW); + return hw_otest_and_write(udc, OP_USBCMD, USBCMD_SUTW, USBCMD_SUTW); } /** @@ -705,10 +694,10 @@ static int hw_test_and_set_setup_guard(void) * * This function returns an error code */ -static int hw_usb_set_address(u8 value) +static int hw_usb_set_address(struct ci13xxx *udc, u8 value) { /* advance */ - hw_owrite(OP_DEVICEADDR, DEVICEADDR_USBADR | DEVICEADDR_USBADRA, + hw_owrite(udc, OP_DEVICEADDR, DEVICEADDR_USBADR | DEVICEADDR_USBADRA, value << ffs_nr(DEVICEADDR_USBADR) | DEVICEADDR_USBADRA); return 0; } @@ -719,21 +708,21 @@ static int hw_usb_set_address(u8 value) * * This function returns an error code */ -static int hw_usb_reset(void) +static int hw_usb_reset(struct ci13xxx *udc) { - hw_usb_set_address(0); + hw_usb_set_address(udc, 0); /* ESS flushes only at end?!? */ - hw_owrite(OP_ENDPTFLUSH, ~0, ~0); /* flush all EPs */ + hw_owrite(udc, OP_ENDPTFLUSH, ~0, ~0); /* flush all EPs */ /* clear setup token semaphores */ - hw_owrite(OP_ENDPTSETUPSTAT, 0, 0); /* writes its content */ + hw_owrite(udc, OP_ENDPTSETUPSTAT, 0, 0); /* writes its content */ /* clear complete status */ - hw_owrite(OP_ENDPTCOMPLETE, 0, 0); /* writes its content */ + hw_owrite(udc, OP_ENDPTCOMPLETE, 0, 0); /* writes its content */ /* wait until all bits cleared */ - while (hw_oread(OP_ENDPTPRIME, ~0)) + while (hw_oread(udc, OP_ENDPTPRIME, ~0)) udelay(10); /* not RTOS friendly */ /* reset all endpoints ? */ @@ -1035,12 +1024,12 @@ static ssize_t show_inters(struct device *dev, struct device_attribute *attr, return 0; } - spin_lock_irqsave(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); n += scnprintf(buf + n, PAGE_SIZE - n, - "status = %08x\n", hw_read_intr_status()); + "status = %08x\n", hw_read_intr_status(udc)); n += scnprintf(buf + n, PAGE_SIZE - n, - "enable = %08x\n", hw_read_intr_enable()); + "enable = %08x\n", hw_read_intr_enable(udc)); n += scnprintf(buf + n, PAGE_SIZE - n, "*test = %d\n", isr_statistics.test); @@ -1084,7 +1073,7 @@ static ssize_t show_inters(struct device *dev, struct device_attribute *attr, n += scnprintf(buf + n, PAGE_SIZE - n, "\n"); } - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); return n; } @@ -1113,17 +1102,17 @@ static ssize_t store_inters(struct device *dev, struct device_attribute *attr, goto done; } - spin_lock_irqsave(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); if (en) { - if (hw_intr_force(bit)) + if (hw_intr_force(udc, bit)) dev_err(dev, "invalid bit number\n"); else isr_statistics.test++; } else { - if (hw_intr_clear(bit)) + if (hw_intr_clear(udc, bit)) dev_err(dev, "invalid bit number\n"); } - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); done: return count; @@ -1148,9 +1137,9 @@ static ssize_t show_port_test(struct device *dev, return 0; } - spin_lock_irqsave(udc->lock, flags); - mode = hw_port_test_get(); - spin_unlock_irqrestore(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); + mode = hw_port_test_get(udc); + spin_unlock_irqrestore(&udc->lock, flags); return scnprintf(buf, PAGE_SIZE, "mode = %u\n", mode); } @@ -1179,10 +1168,10 @@ static ssize_t store_port_test(struct device *dev, goto done; } - spin_lock_irqsave(udc->lock, flags); - if (hw_port_test_set(mode)) + spin_lock_irqsave(&udc->lock, flags); + if (hw_port_test_set(udc, mode)) dev_err(dev, "invalid mode\n"); - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); done: return count; @@ -1208,10 +1197,11 @@ static ssize_t show_qheads(struct device *dev, struct device_attribute *attr, return 0; } - spin_lock_irqsave(udc->lock, flags); - for (i = 0; i < hw_ep_max/2; i++) { + spin_lock_irqsave(&udc->lock, flags); + for (i = 0; i < udc->hw_ep_max/2; i++) { struct ci13xxx_ep *mEpRx = &udc->ci13xxx_ep[i]; - struct ci13xxx_ep *mEpTx = &udc->ci13xxx_ep[i + hw_ep_max/2]; + struct ci13xxx_ep *mEpTx = + &udc->ci13xxx_ep[i + udc->hw_ep_max/2]; n += scnprintf(buf + n, PAGE_SIZE - n, "EP=%02i: RX=%08X TX=%08X\n", i, (u32)mEpRx->qh.dma, (u32)mEpTx->qh.dma); @@ -1222,7 +1212,7 @@ static ssize_t show_qheads(struct device *dev, struct device_attribute *attr, *((u32 *)mEpTx->qh.ptr + j)); } } - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); return n; } @@ -1254,9 +1244,9 @@ static ssize_t show_registers(struct device *dev, return 0; } - spin_lock_irqsave(udc->lock, flags); - k = hw_register_read(dump, DUMP_ENTRIES); - spin_unlock_irqrestore(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); + k = hw_register_read(udc, dump, DUMP_ENTRIES); + spin_unlock_irqrestore(&udc->lock, flags); for (i = 0; i < k; i++) { n += scnprintf(buf + n, PAGE_SIZE - n, @@ -1291,10 +1281,10 @@ static ssize_t store_registers(struct device *dev, goto done; } - spin_lock_irqsave(udc->lock, flags); - if (hw_register_write(addr, data)) + spin_lock_irqsave(&udc->lock, flags); + if (hw_register_write(udc, addr, data)) dev_err(dev, "invalid address range\n"); - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); done: return count; @@ -1322,23 +1312,23 @@ static ssize_t show_requests(struct device *dev, struct device_attribute *attr, return 0; } - spin_lock_irqsave(udc->lock, flags); - for (i = 0; i < hw_ep_max; i++) + spin_lock_irqsave(&udc->lock, flags); + for (i = 0; i < udc->hw_ep_max; i++) list_for_each(ptr, &udc->ci13xxx_ep[i].qh.queue) { req = list_entry(ptr, struct ci13xxx_req, queue); n += scnprintf(buf + n, PAGE_SIZE - n, "EP=%02i: TD=%08X %s\n", - i % hw_ep_max/2, (u32)req->dma, - ((i < hw_ep_max/2) ? "RX" : "TX")); + i % udc->hw_ep_max/2, (u32)req->dma, + ((i < udc->hw_ep_max/2) ? "RX" : "TX")); for (j = 0; j < qSize; j++) n += scnprintf(buf + n, PAGE_SIZE - n, " %04X: %08X\n", j, *((u32 *)req->ptr + j)); } - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); return n; } @@ -1442,6 +1432,7 @@ static inline u8 _usb_addr(struct ci13xxx_ep *ep) */ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) { + struct ci13xxx *udc = mEp->udc; unsigned i; int ret = 0; unsigned length = mReq->req.length; @@ -1515,13 +1506,13 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) else mReqPrev->ptr->next = mReq->dma & TD_ADDR_MASK; wmb(); - if (hw_oread(OP_ENDPTPRIME, BIT(n))) + if (hw_oread(udc, OP_ENDPTPRIME, BIT(n))) goto done; do { - hw_owrite(OP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW); - tmp_stat = hw_oread(OP_ENDPTSTAT, BIT(n)); - } while (!hw_oread(OP_USBCMD, USBCMD_ATDTW)); - hw_owrite(OP_USBCMD, USBCMD_ATDTW, 0); + hw_owrite(udc, OP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW); + tmp_stat = hw_oread(udc, OP_ENDPTSTAT, BIT(n)); + } while (!hw_oread(udc, OP_USBCMD, USBCMD_ATDTW)); + hw_owrite(udc, OP_USBCMD, USBCMD_ATDTW, 0); if (tmp_stat) goto done; } @@ -1533,7 +1524,7 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) wmb(); /* synchronize before ep prime */ - ret = hw_ep_prime(mEp->num, mEp->dir, + ret = hw_ep_prime(udc, mEp->num, mEp->dir, mEp->type == USB_ENDPOINT_XFER_CONTROL); done: return ret; @@ -1604,7 +1595,7 @@ __acquires(mEp->lock) if (mEp == NULL) return -EINVAL; - hw_ep_flush(mEp->num, mEp->dir); + hw_ep_flush(mEp->udc, mEp->num, mEp->dir); while (!list_empty(&mEp->qh.queue)) { @@ -1641,11 +1632,11 @@ static int _gadget_stop_activity(struct usb_gadget *gadget) if (gadget == NULL) return -EINVAL; - spin_lock_irqsave(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); udc->gadget.speed = USB_SPEED_UNKNOWN; udc->remote_wakeup = 0; udc->suspended = 0; - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); /* flush all endpoints */ gadget_for_each_ep(ep, gadget) { @@ -1693,12 +1684,12 @@ __acquires(udc->lock) dbg_event(0xFF, "BUS RST", 0); - spin_unlock(udc->lock); + spin_unlock(&udc->lock); retval = _gadget_stop_activity(&udc->gadget); if (retval) goto done; - retval = hw_usb_reset(); + retval = hw_usb_reset(udc); if (retval) goto done; @@ -1706,7 +1697,7 @@ __acquires(udc->lock) if (udc->status == NULL) retval = -ENOMEM; - spin_lock(udc->lock); + spin_lock(&udc->lock); done: if (retval) @@ -1778,7 +1769,7 @@ __acquires(mEp->lock) dir = (le16_to_cpu(setup->wIndex) & USB_ENDPOINT_DIR_MASK) ? TX : RX; num = le16_to_cpu(setup->wIndex) & USB_ENDPOINT_NUMBER_MASK; - *((u16 *)req->buf) = hw_ep_get_halt(num, dir); + *((u16 *)req->buf) = hw_ep_get_halt(udc, num, dir); } /* else do nothing; reserved for future use */ @@ -1815,10 +1806,10 @@ isr_setup_status_complete(struct usb_ep *ep, struct usb_request *req) trace("%p, %p", ep, req); - spin_lock_irqsave(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); if (udc->test_mode) - hw_port_test_set(udc->test_mode); - spin_unlock_irqrestore(udc->lock, flags); + hw_port_test_set(udc, udc->test_mode); + spin_unlock_irqrestore(&udc->lock, flags); } /** @@ -1912,7 +1903,7 @@ __acquires(udc->lock) return; } - for (i = 0; i < hw_ep_max; i++) { + for (i = 0; i < udc->hw_ep_max; i++) { struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; int type, num, dir, err = -EINVAL; struct usb_ctrlrequest req; @@ -1920,7 +1911,7 @@ __acquires(udc->lock) if (mEp->desc == NULL) continue; /* not configured */ - if (hw_test_and_clear_complete(i)) { + if (hw_test_and_clear_complete(udc, i)) { err = isr_tr_complete_low(mEp); if (mEp->type == USB_ENDPOINT_XFER_CONTROL) { if (err > 0) /* needs status phase */ @@ -1928,16 +1919,16 @@ __acquires(udc->lock) if (err < 0) { dbg_event(_usb_addr(mEp), "ERROR", err); - spin_unlock(udc->lock); + spin_unlock(&udc->lock); if (usb_ep_set_halt(&mEp->ep)) err("error: ep_set_halt"); - spin_lock(udc->lock); + spin_lock(&udc->lock); } } } if (mEp->type != USB_ENDPOINT_XFER_CONTROL || - !hw_test_and_clear_setup_status(i)) + !hw_test_and_clear_setup_status(udc, i)) continue; if (i != 0) { @@ -1954,9 +1945,9 @@ __acquires(udc->lock) /* read_setup_packet */ do { - hw_test_and_set_setup_guard(); + hw_test_and_set_setup_guard(udc); memcpy(&req, &mEp->qh.ptr->setup, sizeof(req)); - } while (!hw_test_and_clear_setup_guard()); + } while (!hw_test_and_clear_setup_guard(udc)); type = req.bRequestType; @@ -1975,12 +1966,12 @@ __acquires(udc->lock) dir = num & USB_ENDPOINT_DIR_MASK; num &= USB_ENDPOINT_NUMBER_MASK; if (dir) /* TX */ - num += hw_ep_max/2; + num += udc->hw_ep_max/2; if (!udc->ci13xxx_ep[num].wedge) { - spin_unlock(udc->lock); + spin_unlock(&udc->lock); err = usb_ep_clear_halt( &udc->ci13xxx_ep[num].ep); - spin_lock(udc->lock); + spin_lock(&udc->lock); if (err) break; } @@ -2012,7 +2003,7 @@ __acquires(udc->lock) if (le16_to_cpu(req.wLength) != 0 || le16_to_cpu(req.wIndex) != 0) break; - err = hw_usb_set_address((u8)le16_to_cpu(req.wValue)); + err = hw_usb_set_address(udc, (u8)le16_to_cpu(req.wValue)); if (err) break; err = isr_setup_status_phase(udc); @@ -2027,11 +2018,11 @@ __acquires(udc->lock) dir = num & USB_ENDPOINT_DIR_MASK; num &= USB_ENDPOINT_NUMBER_MASK; if (dir) /* TX */ - num += hw_ep_max/2; + num += udc->hw_ep_max/2; - spin_unlock(udc->lock); + spin_unlock(&udc->lock); err = usb_ep_set_halt(&udc->ci13xxx_ep[num].ep); - spin_lock(udc->lock); + spin_lock(&udc->lock); if (!err) isr_setup_status_phase(udc); } else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE)) { @@ -2069,19 +2060,19 @@ delegate: if (req.wLength == 0) /* no data phase */ udc->ep0_dir = TX; - spin_unlock(udc->lock); + spin_unlock(&udc->lock); err = udc->driver->setup(&udc->gadget, &req); - spin_lock(udc->lock); + spin_lock(&udc->lock); break; } if (err < 0) { dbg_event(_usb_addr(mEp), "ERROR", err); - spin_unlock(udc->lock); + spin_unlock(&udc->lock); if (usb_ep_set_halt(&mEp->ep)) err("error: ep_set_halt"); - spin_lock(udc->lock); + spin_lock(&udc->lock); } } } @@ -2141,7 +2132,7 @@ static int ep_enable(struct usb_ep *ep, * is always enabled */ if (mEp->num) - retval |= hw_ep_enable(mEp->num, mEp->dir, mEp->type); + retval |= hw_ep_enable(mEp->udc, mEp->num, mEp->dir, mEp->type); spin_unlock_irqrestore(mEp->lock, flags); return retval; @@ -2174,7 +2165,7 @@ static int ep_disable(struct usb_ep *ep) dbg_event(_usb_addr(mEp), "DISABLE", 0); retval |= _ep_nuke(mEp); - retval |= hw_ep_disable(mEp->num, mEp->dir); + retval |= hw_ep_disable(mEp->udc, mEp->num, mEp->dir); if (mEp->type == USB_ENDPOINT_XFER_CONTROL) mEp->dir = (mEp->dir == TX) ? RX : TX; @@ -2341,7 +2332,7 @@ static int ep_dequeue(struct usb_ep *ep, struct usb_request *req) dbg_event(_usb_addr(mEp), "DEQUEUE", 0); - hw_ep_flush(mEp->num, mEp->dir); + hw_ep_flush(mEp->udc, mEp->num, mEp->dir); /* pop request */ list_del_init(&mReq->queue); @@ -2393,7 +2384,7 @@ static int ep_set_halt(struct usb_ep *ep, int value) direction = mEp->dir; do { dbg_event(_usb_addr(mEp), "HALT", value); - retval |= hw_ep_set_halt(mEp->num, mEp->dir, value); + retval |= hw_ep_set_halt(mEp->udc, mEp->num, mEp->dir, value); if (!value) mEp->wedge = 0; @@ -2452,7 +2443,7 @@ static void ep_fifo_flush(struct usb_ep *ep) spin_lock_irqsave(mEp->lock, flags); dbg_event(_usb_addr(mEp), "FFLUSH", 0); - hw_ep_flush(mEp->num, mEp->dir); + hw_ep_flush(mEp->udc, mEp->num, mEp->dir); spin_unlock_irqrestore(mEp->lock, flags); } @@ -2485,19 +2476,19 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active) if (!(udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS)) return -EOPNOTSUPP; - spin_lock_irqsave(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); udc->vbus_active = is_active; if (udc->driver) gadget_ready = 1; - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); if (gadget_ready) { if (is_active) { pm_runtime_get_sync(&_gadget->dev); hw_device_reset(udc); - hw_device_state(udc->ep0out->qh.dma); + hw_device_state(udc, udc->ep0out->qh.dma); } else { - hw_device_state(0); + hw_device_state(udc, 0); if (udc->udc_driver->notify_event) udc->udc_driver->notify_event(udc, CI13XXX_CONTROLLER_STOPPED_EVENT); @@ -2517,20 +2508,20 @@ static int ci13xxx_wakeup(struct usb_gadget *_gadget) trace(); - spin_lock_irqsave(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); if (!udc->remote_wakeup) { ret = -EOPNOTSUPP; trace("remote wakeup feature is not enabled\n"); goto out; } - if (!hw_oread(OP_PORTSC, PORTSC_SUSP)) { + if (!hw_oread(udc, OP_PORTSC, PORTSC_SUSP)) { ret = -EINVAL; trace("port is not suspended\n"); goto out; } - hw_owrite(OP_PORTSC, PORTSC_FPR, PORTSC_FPR); + hw_owrite(udc, OP_PORTSC, PORTSC_FPR, PORTSC_FPR); out: - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); return ret; } @@ -2603,22 +2594,23 @@ static int ci13xxx_start(struct usb_gadget_driver *driver, return -ENOMEM; } - spin_lock_irqsave(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); - info("hw_ep_max = %d", hw_ep_max); + info("hw_ep_max = %d", udc->hw_ep_max); udc->gadget.dev.driver = NULL; retval = 0; - for (i = 0; i < hw_ep_max/2; i++) { + for (i = 0; i < udc->hw_ep_max/2; i++) { for (j = RX; j <= TX; j++) { - int k = i + j * hw_ep_max/2; + int k = i + j * udc->hw_ep_max/2; struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[k]; scnprintf(mEp->name, sizeof(mEp->name), "ep%i%s", i, (j == TX) ? "in" : "out"); - mEp->lock = udc->lock; + mEp->udc = udc; + mEp->lock = &udc->lock; mEp->device = &udc->gadget.dev; mEp->td_pool = udc->td_pool; @@ -2627,10 +2619,10 @@ static int ci13xxx_start(struct usb_gadget_driver *driver, mEp->ep.maxpacket = CTRL_PAYLOAD_MAX; INIT_LIST_HEAD(&mEp->qh.queue); - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); mEp->qh.ptr = dma_pool_alloc(udc->qh_pool, GFP_KERNEL, &mEp->qh.dma); - spin_lock_irqsave(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); if (mEp->qh.ptr == NULL) retval = -ENOMEM; else @@ -2655,7 +2647,7 @@ static int ci13xxx_start(struct usb_gadget_driver *driver, if (retval) goto done; - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); udc->ep0out->ep.desc = &ctrl_endpt_out_desc; retval = usb_ep_enable(&udc->ep0out->ep); if (retval) @@ -2665,16 +2657,16 @@ static int ci13xxx_start(struct usb_gadget_driver *driver, retval = usb_ep_enable(&udc->ep0in->ep); if (retval) return retval; - spin_lock_irqsave(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); udc->gadget.ep0 = &udc->ep0in->ep; /* bind gadget */ driver->driver.bus = NULL; udc->gadget.dev.driver = &driver->driver; - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); retval = bind(&udc->gadget); /* MAY SLEEP */ - spin_lock_irqsave(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); if (retval) { udc->gadget.dev.driver = NULL; @@ -2693,12 +2685,12 @@ static int ci13xxx_start(struct usb_gadget_driver *driver, } } - retval = hw_device_state(udc->ep0out->qh.dma); + retval = hw_device_state(udc, udc->ep0out->qh.dma); if (retval) pm_runtime_put_sync(&udc->gadget.dev); done: - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); return retval; } @@ -2721,29 +2713,29 @@ static int ci13xxx_stop(struct usb_gadget_driver *driver) driver != udc->driver) return -EINVAL; - spin_lock_irqsave(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); if (!(udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS) || udc->vbus_active) { - hw_device_state(0); + hw_device_state(udc, 0); if (udc->udc_driver->notify_event) udc->udc_driver->notify_event(udc, CI13XXX_CONTROLLER_STOPPED_EVENT); - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); _gadget_stop_activity(&udc->gadget); - spin_lock_irqsave(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); pm_runtime_put(&udc->gadget.dev); } /* unbind gadget */ - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); driver->unbind(&udc->gadget); /* MAY SLEEP */ - spin_lock_irqsave(udc->lock, flags); + spin_lock_irqsave(&udc->lock, flags); udc->gadget.dev.driver = NULL; /* free resources */ - for (i = 0; i < hw_ep_max; i++) { + for (i = 0; i < udc->hw_ep_max; i++) { struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; if (mEp->num) @@ -2756,7 +2748,7 @@ static int ci13xxx_stop(struct usb_gadget_driver *driver) udc->gadget.ep0 = NULL; udc->driver = NULL; - spin_unlock_irqrestore(udc->lock, flags); + spin_unlock_irqrestore(&udc->lock, flags); if (udc->td_pool != NULL) { dma_pool_destroy(udc->td_pool); @@ -2792,16 +2784,16 @@ static irqreturn_t udc_irq(void) return IRQ_HANDLED; } - spin_lock(udc->lock); + spin_lock(&udc->lock); if (udc->udc_driver->flags & CI13XXX_REGS_SHARED) { - if (hw_oread(OP_USBMODE, USBMODE_CM) != + if (hw_oread(udc, OP_USBMODE, USBMODE_CM) != USBMODE_CM_DEVICE) { - spin_unlock(udc->lock); + spin_unlock(&udc->lock); return IRQ_NONE; } } - intr = hw_test_and_clear_intr_active(); + intr = hw_test_and_clear_intr_active(udc); if (intr) { isr_statistics.hndl.buf[isr_statistics.hndl.idx++] = intr; isr_statistics.hndl.idx &= ISR_MASK; @@ -2814,12 +2806,12 @@ static irqreturn_t udc_irq(void) } if (USBi_PCI & intr) { isr_statistics.pci++; - udc->gadget.speed = hw_port_is_high_speed() ? + udc->gadget.speed = hw_port_is_high_speed(udc) ? USB_SPEED_HIGH : USB_SPEED_FULL; if (udc->suspended && udc->driver->resume) { - spin_unlock(udc->lock); + spin_unlock(&udc->lock); udc->driver->resume(&udc->gadget); - spin_lock(udc->lock); + spin_lock(&udc->lock); udc->suspended = 0; } } @@ -2833,9 +2825,9 @@ static irqreturn_t udc_irq(void) if (udc->gadget.speed != USB_SPEED_UNKNOWN && udc->driver->suspend) { udc->suspended = 1; - spin_unlock(udc->lock); + spin_unlock(&udc->lock); udc->driver->suspend(&udc->gadget); - spin_lock(udc->lock); + spin_lock(&udc->lock); } isr_statistics.sli++; } @@ -2844,7 +2836,7 @@ static irqreturn_t udc_irq(void) isr_statistics.none++; retval = IRQ_NONE; } - spin_unlock(udc->lock); + spin_unlock(&udc->lock); return retval; } @@ -2889,7 +2881,7 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev, if (udc == NULL) return -ENOMEM; - udc->lock = &udc_lock; + spin_lock_init(&udc->lock); udc->regs = regs; udc->udc_driver = driver; @@ -2908,7 +2900,7 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev, udc->gadget.dev.parent = dev; udc->gadget.dev.release = udc_release; - retval = hw_device_init(regs, capoffset); + retval = hw_device_init(udc, regs, capoffset); if (retval < 0) goto free_udc; diff --git a/drivers/usb/gadget/ci13xxx_udc.h b/drivers/usb/gadget/ci13xxx_udc.h index d3c9a63..56a6a2c 100644 --- a/drivers/usb/gadget/ci13xxx_udc.h +++ b/drivers/usb/gadget/ci13xxx_udc.h @@ -95,6 +95,7 @@ struct ci13xxx_ep { int wedge; /* global resources */ + struct ci13xxx *udc; spinlock_t *lock; struct device *device; struct dma_pool *td_pool; @@ -114,9 +115,17 @@ struct ci13xxx_udc_driver { void (*notify_event) (struct ci13xxx *udc, unsigned event); }; +struct hw_bank { + unsigned lpm; /* is LPM? */ + void __iomem *abs; /* bus map offset */ + void __iomem *cap; /* bus map offset + CAP offset */ + void __iomem *op; /* bus map offset + OP offset */ + size_t size; /* bank size */ +}; + /* CI13XXX UDC descriptor & global resources */ struct ci13xxx { - spinlock_t *lock; /* ctrl register bank access */ + spinlock_t lock; /* ctrl register bank access */ void __iomem *regs; /* registers address space */ struct dma_pool *qh_pool; /* DMA pool for queue heads */ @@ -127,11 +136,14 @@ struct ci13xxx { struct ci13xxx_ep ci13xxx_ep[ENDPT_MAX]; /* extended endpts */ u32 ep0_dir; /* ep0 direction */ struct ci13xxx_ep *ep0out, *ep0in; + unsigned hw_ep_max; /* number of hw endpoints */ + u8 remote_wakeup; /* Is remote wakeup feature enabled by the host? */ u8 suspended; /* suspended by the host */ u8 test_mode; /* the selected test mode */ + struct hw_bank hw_bank; struct usb_gadget_driver *driver; /* 3rd party gadget driver */ struct ci13xxx_udc_driver *udc_driver; /* device controller driver */ int vbus_active; /* is VBUS active */ -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html