Commit f9df8395 authored by Alexander Shishkin's avatar Alexander Shishkin Committed by Greg Kroah-Hartman

usb: gadget: ci13xxx: rename register layouts

Currently, the register prefixes in the driver seem to be mixed: the
capability registers are the ones that contain capability information,
such as number of hardware endpoints, while the registers that are
used to program the controller are called operational registers.

Normally, capability registers start at 0x100 offset of the register
window and are followed by operational registers. In some versions,
however, capability registers start at 0x0 offset.

This patch renames the register and adjusts their offsets appropriately,
leaving the possibility of having a non-standard capability offset.

I couldn't find any mentions of the TESTMODE register anywhere, so I
suspect it might only be enabled in chipidea internal versions of the
controller and I'm really inclined to remove it from the driver or at
least hiding it behind a config option.
Signed-off-by: default avatarAlexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d36ade60
...@@ -79,7 +79,8 @@ static int ci13xxx_msm_probe(struct platform_device *pdev) ...@@ -79,7 +79,8 @@ static int ci13xxx_msm_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
} }
ret = udc_probe(&ci13xxx_msm_udc_driver, &pdev->dev, regs); ret = udc_probe(&ci13xxx_msm_udc_driver, &pdev->dev, regs,
DEF_CAPOFFSET);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "udc_probe failed\n"); dev_err(&pdev->dev, "udc_probe failed\n");
goto iounmap; goto iounmap;
......
...@@ -55,6 +55,7 @@ static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev, ...@@ -55,6 +55,7 @@ static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
const struct pci_device_id *id) const struct pci_device_id *id)
{ {
void __iomem *regs = NULL; void __iomem *regs = NULL;
uintptr_t capoffset = DEF_CAPOFFSET;
int retval = 0; int retval = 0;
if (id == NULL) if (id == NULL)
...@@ -86,7 +87,11 @@ static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev, ...@@ -86,7 +87,11 @@ static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
pci_set_master(pdev); pci_set_master(pdev);
pci_try_set_mwi(pdev); pci_try_set_mwi(pdev);
retval = udc_probe(&ci13xxx_pci_udc_driver, &pdev->dev, regs); if (pdev->vendor == PCI_VENDOR_ID_INTEL)
capoffset = 0;
retval = udc_probe(&ci13xxx_pci_udc_driver, &pdev->dev, regs,
capoffset);
if (retval) if (retval)
goto iounmap; goto iounmap;
......
...@@ -138,7 +138,8 @@ static int ffs_nr(u32 x) ...@@ -138,7 +138,8 @@ static int ffs_nr(u32 x)
static struct { static struct {
unsigned lpm; /* is LPM? */ unsigned lpm; /* is LPM? */
void __iomem *abs; /* bus map offset */ void __iomem *abs; /* bus map offset */
void __iomem *cap; /* bus map offset + CAP offset + CAP data */ void __iomem *cap; /* bus map offset + CAP offset */
void __iomem *op; /* bus map offset + OP offset */
size_t size; /* bank size */ size_t size; /* bank size */
} hw_bank; } hw_bank;
...@@ -146,26 +147,26 @@ static struct { ...@@ -146,26 +147,26 @@ static struct {
#define ABS_AHBBURST (0x0090UL) #define ABS_AHBBURST (0x0090UL)
#define ABS_AHBMODE (0x0098UL) #define ABS_AHBMODE (0x0098UL)
/* UDC register map */ /* UDC register map */
#define ABS_CAPLENGTH (0x100UL) #define CAP_CAPLENGTH (0x000UL)
#define ABS_HCCPARAMS (0x108UL) #define CAP_HCCPARAMS (0x008UL)
#define ABS_DCCPARAMS (0x124UL) #define CAP_DCCPARAMS (0x024UL)
#define ABS_TESTMODE (hw_bank.lpm ? 0x0FCUL : 0x138UL) #define ABS_TESTMODE (hw_bank.lpm ? 0x0FCUL : 0x138UL)
/* offset to CAPLENTGH (addr + data) */ /* offset to CAPLENTGH (addr + data) */
#define CAP_USBCMD (0x000UL) #define OP_USBCMD (0x000UL)
#define CAP_USBSTS (0x004UL) #define OP_USBSTS (0x004UL)
#define CAP_USBINTR (0x008UL) #define OP_USBINTR (0x008UL)
#define CAP_DEVICEADDR (0x014UL) #define OP_DEVICEADDR (0x014UL)
#define CAP_ENDPTLISTADDR (0x018UL) #define OP_ENDPTLISTADDR (0x018UL)
#define CAP_PORTSC (0x044UL) #define OP_PORTSC (0x044UL)
#define CAP_DEVLC (0x084UL) #define OP_DEVLC (0x084UL)
#define CAP_USBMODE (hw_bank.lpm ? 0x0C8UL : 0x068UL) #define OP_USBMODE (hw_bank.lpm ? 0x0C8UL : 0x068UL)
#define CAP_ENDPTSETUPSTAT (hw_bank.lpm ? 0x0D8UL : 0x06CUL) #define OP_ENDPTSETUPSTAT (hw_bank.lpm ? 0x0D8UL : 0x06CUL)
#define CAP_ENDPTPRIME (hw_bank.lpm ? 0x0DCUL : 0x070UL) #define OP_ENDPTPRIME (hw_bank.lpm ? 0x0DCUL : 0x070UL)
#define CAP_ENDPTFLUSH (hw_bank.lpm ? 0x0E0UL : 0x074UL) #define OP_ENDPTFLUSH (hw_bank.lpm ? 0x0E0UL : 0x074UL)
#define CAP_ENDPTSTAT (hw_bank.lpm ? 0x0E4UL : 0x078UL) #define OP_ENDPTSTAT (hw_bank.lpm ? 0x0E4UL : 0x078UL)
#define CAP_ENDPTCOMPLETE (hw_bank.lpm ? 0x0E8UL : 0x07CUL) #define OP_ENDPTCOMPLETE (hw_bank.lpm ? 0x0E8UL : 0x07CUL)
#define CAP_ENDPTCTRL (hw_bank.lpm ? 0x0ECUL : 0x080UL) #define OP_ENDPTCTRL (hw_bank.lpm ? 0x0ECUL : 0x080UL)
#define CAP_LAST (hw_bank.lpm ? 0x12CUL : 0x0C0UL) #define OP_LAST (hw_bank.lpm ? 0x12CUL : 0x0C0UL)
/* maximum number of enpoints: valid only after hw_device_reset() */ /* maximum number of enpoints: valid only after hw_device_reset() */
static unsigned hw_ep_max; static unsigned hw_ep_max;
...@@ -193,85 +194,65 @@ static int ep_to_bit(int n) ...@@ -193,85 +194,65 @@ static int ep_to_bit(int n)
} }
/** /**
* hw_aread: reads from register bitfield * hw_read: reads from a register bitfield
* @addr: address relative to bus map * @base: register block address
* @addr: address relative to operational register base
* @mask: bitfield mask * @mask: bitfield mask
* *
* This function returns register bitfield data * This function returns register bitfield data
*/ */
static u32 hw_aread(u32 addr, u32 mask) static u32 hw_read(void __iomem *base, u32 addr, u32 mask)
{ {
return ioread32(addr + hw_bank.abs) & mask; return ioread32(addr + base) & mask;
} }
/** /**
* hw_awrite: writes to register bitfield * hw_write: writes to a register bitfield
* @addr: address relative to bus map * @base: register block address
* @addr: address relative to operational register base
* @mask: bitfield mask * @mask: bitfield mask
* @data: new data * @data: new data
*/ */
static void hw_awrite(u32 addr, u32 mask, u32 data) static void hw_write(void __iomem *base, u32 addr, u32 mask, u32 data)
{ {
iowrite32(hw_aread(addr, ~mask) | (data & mask), iowrite32(hw_read(base, addr, ~mask) | (data & mask),
addr + hw_bank.abs); addr + base);
} }
/** /**
* hw_cread: reads from register bitfield * hw_test_and_clear: tests & clears operational register bitfield
* @addr: address relative to CAP offset plus content * @base: register block address
* @addr: address relative to operational register base
* @mask: bitfield mask * @mask: bitfield mask
* *
* This function returns register bitfield data * This function returns register bitfield data
*/ */
static u32 hw_cread(u32 addr, u32 mask) static u32 hw_test_and_clear(void __iomem *base, u32 addr, u32 mask)
{ {
return ioread32(addr + hw_bank.cap) & mask; u32 reg = hw_read(base, addr, mask);
}
/**
* hw_cwrite: writes to register bitfield
* @addr: address relative to CAP offset plus content
* @mask: bitfield mask
* @data: new data
*/
static void hw_cwrite(u32 addr, u32 mask, u32 data)
{
iowrite32(hw_cread(addr, ~mask) | (data & mask),
addr + hw_bank.cap);
}
/**
* hw_ctest_and_clear: tests & clears register bitfield
* @addr: address relative to CAP offset plus content
* @mask: bitfield mask
*
* This function returns register bitfield data
*/
static u32 hw_ctest_and_clear(u32 addr, u32 mask)
{
u32 reg = hw_cread(addr, mask);
iowrite32(reg, addr + hw_bank.cap); iowrite32(reg, addr + base);
return reg; return reg;
} }
/** /**
* hw_ctest_and_write: tests & writes register bitfield * hw_test_and_write: tests & writes operational register bitfield
* @addr: address relative to CAP offset plus content * @base: register block address
* @addr: address relative to operational register base
* @mask: bitfield mask * @mask: bitfield mask
* @data: new data * @data: new data
* *
* This function returns register bitfield data * This function returns register bitfield data
*/ */
static u32 hw_ctest_and_write(u32 addr, u32 mask, u32 data) static u32 hw_test_and_write(void __iomem *base, u32 addr, u32 mask, u32 data)
{ {
u32 reg = hw_cread(addr, ~0); u32 reg = hw_read(base, addr, ~0);
iowrite32((reg & ~mask) | (data & mask), addr + hw_bank.cap); iowrite32((reg & ~mask) | (data & mask), addr + base);
return (reg & mask) >> ffs_nr(mask); return (reg & mask) >> ffs_nr(mask);
} }
static int hw_device_init(void __iomem *base) static int hw_device_init(void __iomem *base, uintptr_t cap_offset)
{ {
u32 reg; u32 reg;
...@@ -279,16 +260,18 @@ static int hw_device_init(void __iomem *base) ...@@ -279,16 +260,18 @@ static int hw_device_init(void __iomem *base)
hw_bank.abs = base; hw_bank.abs = base;
hw_bank.cap = hw_bank.abs; hw_bank.cap = hw_bank.abs;
hw_bank.cap += ABS_CAPLENGTH; hw_bank.cap += cap_offset;
hw_bank.cap += ioread8(hw_bank.cap); hw_bank.op = hw_bank.cap + ioread8(hw_bank.cap);
reg = hw_aread(ABS_HCCPARAMS, HCCPARAMS_LEN) >> ffs_nr(HCCPARAMS_LEN); reg = hw_read(hw_bank.cap, CAP_HCCPARAMS, HCCPARAMS_LEN) >>
ffs_nr(HCCPARAMS_LEN);
hw_bank.lpm = reg; hw_bank.lpm = reg;
hw_bank.size = hw_bank.cap - hw_bank.abs; hw_bank.size = hw_bank.op - hw_bank.abs;
hw_bank.size += CAP_LAST; hw_bank.size += OP_LAST;
hw_bank.size /= sizeof(u32); hw_bank.size /= sizeof(u32);
reg = hw_aread(ABS_DCCPARAMS, DCCPARAMS_DEN) >> ffs_nr(DCCPARAMS_DEN); reg = hw_read(hw_bank.cap, CAP_DCCPARAMS, DCCPARAMS_DEN) >>
ffs_nr(DCCPARAMS_DEN);
hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */
if (hw_ep_max == 0 || hw_ep_max > ENDPT_MAX) if (hw_ep_max == 0 || hw_ep_max > ENDPT_MAX)
...@@ -311,11 +294,11 @@ static int hw_device_init(void __iomem *base) ...@@ -311,11 +294,11 @@ static int hw_device_init(void __iomem *base)
static int hw_device_reset(struct ci13xxx *udc) static int hw_device_reset(struct ci13xxx *udc)
{ {
/* should flush & stop before reset */ /* should flush & stop before reset */
hw_cwrite(CAP_ENDPTFLUSH, ~0, ~0); hw_write(hw_bank.op, OP_ENDPTFLUSH, ~0, ~0);
hw_cwrite(CAP_USBCMD, USBCMD_RS, 0); hw_write(hw_bank.op, OP_USBCMD, USBCMD_RS, 0);
hw_cwrite(CAP_USBCMD, USBCMD_RST, USBCMD_RST); hw_write(hw_bank.op, OP_USBCMD, USBCMD_RST, USBCMD_RST);
while (hw_cread(CAP_USBCMD, USBCMD_RST)) while (hw_read(hw_bank.op, OP_USBCMD, USBCMD_RST))
udelay(10); /* not RTOS friendly */ udelay(10); /* not RTOS friendly */
...@@ -324,14 +307,15 @@ static int hw_device_reset(struct ci13xxx *udc) ...@@ -324,14 +307,15 @@ static int hw_device_reset(struct ci13xxx *udc)
CI13XXX_CONTROLLER_RESET_EVENT); CI13XXX_CONTROLLER_RESET_EVENT);
if (udc->udc_driver->flags & CI13XXX_DISABLE_STREAMING) if (udc->udc_driver->flags & CI13XXX_DISABLE_STREAMING)
hw_cwrite(CAP_USBMODE, USBMODE_SDIS, USBMODE_SDIS); hw_write(hw_bank.op, OP_USBMODE, USBMODE_SDIS, USBMODE_SDIS);
/* USBMODE should be configured step by step */ /* USBMODE should be configured step by step */
hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE); hw_write(hw_bank.op, OP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE);
hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_DEVICE); hw_write(hw_bank.op, OP_USBMODE, USBMODE_CM, USBMODE_CM_DEVICE);
hw_cwrite(CAP_USBMODE, USBMODE_SLOM, USBMODE_SLOM); /* HW >= 2.3 */ /* HW >= 2.3 */
hw_write(hw_bank.op, OP_USBMODE, USBMODE_SLOM, USBMODE_SLOM);
if (hw_cread(CAP_USBMODE, USBMODE_CM) != USBMODE_CM_DEVICE) { if (hw_read(hw_bank.op, OP_USBMODE, USBMODE_CM) != USBMODE_CM_DEVICE) {
pr_err("cannot enter in device mode"); pr_err("cannot enter in device mode");
pr_err("lpm = %i", hw_bank.lpm); pr_err("lpm = %i", hw_bank.lpm);
return -ENODEV; return -ENODEV;
...@@ -350,14 +334,14 @@ static int hw_device_reset(struct ci13xxx *udc) ...@@ -350,14 +334,14 @@ static int hw_device_reset(struct ci13xxx *udc)
static int hw_device_state(u32 dma) static int hw_device_state(u32 dma)
{ {
if (dma) { if (dma) {
hw_cwrite(CAP_ENDPTLISTADDR, ~0, dma); hw_write(hw_bank.op, OP_ENDPTLISTADDR, ~0, dma);
/* interrupt, error, port change, reset, sleep/suspend */ /* interrupt, error, port change, reset, sleep/suspend */
hw_cwrite(CAP_USBINTR, ~0, hw_write(hw_bank.op, OP_USBINTR, ~0,
USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI);
hw_cwrite(CAP_USBCMD, USBCMD_RS, USBCMD_RS); hw_write(hw_bank.op, OP_USBCMD, USBCMD_RS, USBCMD_RS);
} else { } else {
hw_cwrite(CAP_USBCMD, USBCMD_RS, 0); hw_write(hw_bank.op, OP_USBCMD, USBCMD_RS, 0);
hw_cwrite(CAP_USBINTR, ~0, 0); hw_write(hw_bank.op, OP_USBINTR, ~0, 0);
} }
return 0; return 0;
} }
...@@ -375,10 +359,10 @@ static int hw_ep_flush(int num, int dir) ...@@ -375,10 +359,10 @@ static int hw_ep_flush(int num, int dir)
do { do {
/* flush any pending transfer */ /* flush any pending transfer */
hw_cwrite(CAP_ENDPTFLUSH, BIT(n), BIT(n)); hw_write(hw_bank.op, OP_ENDPTFLUSH, BIT(n), BIT(n));
while (hw_cread(CAP_ENDPTFLUSH, BIT(n))) while (hw_read(hw_bank.op, OP_ENDPTFLUSH, BIT(n)))
cpu_relax(); cpu_relax();
} while (hw_cread(CAP_ENDPTSTAT, BIT(n))); } while (hw_read(hw_bank.op, OP_ENDPTSTAT, BIT(n)));
return 0; return 0;
} }
...@@ -393,7 +377,7 @@ static int hw_ep_flush(int num, int dir) ...@@ -393,7 +377,7 @@ static int hw_ep_flush(int num, int dir)
static int hw_ep_disable(int num, int dir) static int hw_ep_disable(int num, int dir)
{ {
hw_ep_flush(num, dir); hw_ep_flush(num, dir);
hw_cwrite(CAP_ENDPTCTRL + num * sizeof(u32), hw_write(hw_bank.op, OP_ENDPTCTRL + num * sizeof(u32),
dir ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0); dir ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0);
return 0; return 0;
} }
...@@ -429,7 +413,7 @@ static int hw_ep_enable(int num, int dir, int type) ...@@ -429,7 +413,7 @@ static int hw_ep_enable(int num, int dir, int type)
mask |= ENDPTCTRL_RXE; /* enable */ mask |= ENDPTCTRL_RXE; /* enable */
data |= ENDPTCTRL_RXE; data |= ENDPTCTRL_RXE;
} }
hw_cwrite(CAP_ENDPTCTRL + num * sizeof(u32), mask, data); hw_write(hw_bank.op, OP_ENDPTCTRL + num * sizeof(u32), mask, data);
return 0; return 0;
} }
...@@ -444,7 +428,7 @@ static int hw_ep_get_halt(int num, int dir) ...@@ -444,7 +428,7 @@ static int hw_ep_get_halt(int num, int dir)
{ {
u32 mask = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; u32 mask = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS;
return hw_cread(CAP_ENDPTCTRL + num * sizeof(u32), mask) ? 1 : 0; return !!hw_read(hw_bank.op, OP_ENDPTCTRL + num * sizeof(u32), mask);
} }
/** /**
...@@ -457,7 +441,7 @@ static int hw_ep_get_halt(int num, int dir) ...@@ -457,7 +441,7 @@ static int hw_ep_get_halt(int num, int dir)
static int hw_test_and_clear_setup_status(int n) static int hw_test_and_clear_setup_status(int n)
{ {
n = ep_to_bit(n); n = ep_to_bit(n);
return hw_ctest_and_clear(CAP_ENDPTSETUPSTAT, BIT(n)); return hw_test_and_clear(hw_bank.op, OP_ENDPTSETUPSTAT, BIT(n));
} }
/** /**
...@@ -472,14 +456,16 @@ static int hw_ep_prime(int num, int dir, int is_ctrl) ...@@ -472,14 +456,16 @@ static int hw_ep_prime(int num, int dir, int is_ctrl)
{ {
int n = hw_ep_bit(num, dir); int n = hw_ep_bit(num, dir);
if (is_ctrl && dir == RX && hw_cread(CAP_ENDPTSETUPSTAT, BIT(num))) if (is_ctrl && dir == RX &&
hw_read(hw_bank.op, OP_ENDPTSETUPSTAT, BIT(num)))
return -EAGAIN; return -EAGAIN;
hw_cwrite(CAP_ENDPTPRIME, BIT(n), BIT(n)); hw_write(hw_bank.op, OP_ENDPTPRIME, BIT(n), BIT(n));
while (hw_cread(CAP_ENDPTPRIME, BIT(n))) while (hw_read(hw_bank.op, OP_ENDPTPRIME, BIT(n)))
cpu_relax(); cpu_relax();
if (is_ctrl && dir == RX && hw_cread(CAP_ENDPTSETUPSTAT, BIT(num))) if (is_ctrl && dir == RX &&
hw_read(hw_bank.op, OP_ENDPTSETUPSTAT, BIT(num)))
return -EAGAIN; return -EAGAIN;
/* status shoult be tested according with manual but it doesn't work */ /* status shoult be tested according with manual but it doesn't work */
...@@ -501,12 +487,13 @@ static int hw_ep_set_halt(int num, int dir, int value) ...@@ -501,12 +487,13 @@ static int hw_ep_set_halt(int num, int dir, int value)
return -EINVAL; return -EINVAL;
do { do {
u32 addr = CAP_ENDPTCTRL + num * sizeof(u32); u32 addr = OP_ENDPTCTRL + num * sizeof(u32);
u32 mask_xs = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; u32 mask_xs = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS;
u32 mask_xr = dir ? ENDPTCTRL_TXR : ENDPTCTRL_RXR; u32 mask_xr = dir ? ENDPTCTRL_TXR : ENDPTCTRL_RXR;
/* data toggle - reserved for EP0 but it's in ESS */ /* data toggle - reserved for EP0 but it's in ESS */
hw_cwrite(addr, mask_xs|mask_xr, value ? mask_xs : mask_xr); hw_write(hw_bank.op, addr, mask_xs|mask_xr,
value ? mask_xs : mask_xr);
} while (value != hw_ep_get_halt(num, dir)); } while (value != hw_ep_get_halt(num, dir));
...@@ -525,8 +512,8 @@ static int hw_intr_clear(int n) ...@@ -525,8 +512,8 @@ static int hw_intr_clear(int n)
if (n >= REG_BITS) if (n >= REG_BITS)
return -EINVAL; return -EINVAL;
hw_cwrite(CAP_USBINTR, BIT(n), 0); hw_write(hw_bank.op, OP_USBINTR, BIT(n), 0);
hw_cwrite(CAP_USBSTS, BIT(n), BIT(n)); hw_write(hw_bank.op, OP_USBSTS, BIT(n), BIT(n));
return 0; return 0;
} }
...@@ -542,10 +529,10 @@ static int hw_intr_force(int n) ...@@ -542,10 +529,10 @@ static int hw_intr_force(int n)
if (n >= REG_BITS) if (n >= REG_BITS)
return -EINVAL; return -EINVAL;
hw_awrite(ABS_TESTMODE, TESTMODE_FORCE, TESTMODE_FORCE); hw_write(hw_bank.cap, ABS_TESTMODE, TESTMODE_FORCE, TESTMODE_FORCE);
hw_cwrite(CAP_USBINTR, BIT(n), BIT(n)); hw_write(hw_bank.op, OP_USBINTR, BIT(n), BIT(n));
hw_cwrite(CAP_USBSTS, BIT(n), BIT(n)); hw_write(hw_bank.op, OP_USBSTS, BIT(n), BIT(n));
hw_awrite(ABS_TESTMODE, TESTMODE_FORCE, 0); hw_write(hw_bank.cap, ABS_TESTMODE, TESTMODE_FORCE, 0);
return 0; return 0;
} }
...@@ -556,8 +543,8 @@ static int hw_intr_force(int n) ...@@ -556,8 +543,8 @@ static int hw_intr_force(int n)
*/ */
static int hw_port_is_high_speed(void) static int hw_port_is_high_speed(void)
{ {
return hw_bank.lpm ? hw_cread(CAP_DEVLC, DEVLC_PSPD) : return hw_bank.lpm ? hw_read(hw_bank.op, OP_DEVLC, DEVLC_PSPD) :
hw_cread(CAP_PORTSC, PORTSC_HSP); hw_read(hw_bank.op, OP_PORTSC, PORTSC_HSP);
} }
/** /**
...@@ -567,7 +554,7 @@ static int hw_port_is_high_speed(void) ...@@ -567,7 +554,7 @@ static int hw_port_is_high_speed(void)
*/ */
static u8 hw_port_test_get(void) static u8 hw_port_test_get(void)
{ {
return hw_cread(CAP_PORTSC, PORTSC_PTC) >> ffs_nr(PORTSC_PTC); return hw_read(hw_bank.op, OP_PORTSC, PORTSC_PTC) >> ffs_nr(PORTSC_PTC);
} }
/** /**
...@@ -583,7 +570,7 @@ static int hw_port_test_set(u8 mode) ...@@ -583,7 +570,7 @@ static int hw_port_test_set(u8 mode)
if (mode > TEST_MODE_MAX) if (mode > TEST_MODE_MAX)
return -EINVAL; return -EINVAL;
hw_cwrite(CAP_PORTSC, PORTSC_PTC, mode << ffs_nr(PORTSC_PTC)); hw_write(hw_bank.op, OP_PORTSC, PORTSC_PTC, mode << ffs_nr(PORTSC_PTC));
return 0; return 0;
} }
...@@ -594,7 +581,7 @@ static int hw_port_test_set(u8 mode) ...@@ -594,7 +581,7 @@ static int hw_port_test_set(u8 mode)
*/ */
static u32 hw_read_intr_enable(void) static u32 hw_read_intr_enable(void)
{ {
return hw_cread(CAP_USBINTR, ~0); return hw_read(hw_bank.op, OP_USBINTR, ~0);
} }
/** /**
...@@ -604,7 +591,7 @@ static u32 hw_read_intr_enable(void) ...@@ -604,7 +591,7 @@ static u32 hw_read_intr_enable(void)
*/ */
static u32 hw_read_intr_status(void) static u32 hw_read_intr_status(void)
{ {
return hw_cread(CAP_USBSTS, ~0); return hw_read(hw_bank.op, OP_USBSTS, ~0);
} }
/** /**
...@@ -622,7 +609,7 @@ static size_t hw_register_read(u32 *buf, size_t size) ...@@ -622,7 +609,7 @@ static size_t hw_register_read(u32 *buf, size_t size)
size = hw_bank.size; size = hw_bank.size;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
buf[i] = hw_aread(i * sizeof(u32), ~0); buf[i] = hw_read(hw_bank.cap, i * sizeof(u32), ~0);
return size; return size;
} }
...@@ -645,7 +632,7 @@ static int hw_register_write(u16 addr, u32 data) ...@@ -645,7 +632,7 @@ static int hw_register_write(u16 addr, u32 data)
/* align */ /* align */
addr *= sizeof(u32); addr *= sizeof(u32);
hw_awrite(addr, ~0, data); hw_write(hw_bank.cap, addr, ~0, data);
return 0; return 0;
} }
...@@ -659,7 +646,7 @@ static int hw_register_write(u16 addr, u32 data) ...@@ -659,7 +646,7 @@ static int hw_register_write(u16 addr, u32 data)
static int hw_test_and_clear_complete(int n) static int hw_test_and_clear_complete(int n)
{ {
n = ep_to_bit(n); n = ep_to_bit(n);
return hw_ctest_and_clear(CAP_ENDPTCOMPLETE, BIT(n)); return hw_test_and_clear(hw_bank.op, OP_ENDPTCOMPLETE, BIT(n));
} }
/** /**
...@@ -672,7 +659,7 @@ static u32 hw_test_and_clear_intr_active(void) ...@@ -672,7 +659,7 @@ static u32 hw_test_and_clear_intr_active(void)
{ {
u32 reg = hw_read_intr_status() & hw_read_intr_enable(); u32 reg = hw_read_intr_status() & hw_read_intr_enable();
hw_cwrite(CAP_USBSTS, ~0, reg); hw_write(hw_bank.op, OP_USBSTS, ~0, reg);
return reg; return reg;
} }
...@@ -684,7 +671,7 @@ static u32 hw_test_and_clear_intr_active(void) ...@@ -684,7 +671,7 @@ static u32 hw_test_and_clear_intr_active(void)
*/ */
static int hw_test_and_clear_setup_guard(void) static int hw_test_and_clear_setup_guard(void)
{ {
return hw_ctest_and_write(CAP_USBCMD, USBCMD_SUTW, 0); return hw_test_and_write(hw_bank.op, OP_USBCMD, USBCMD_SUTW, 0);
} }
/** /**
...@@ -695,7 +682,8 @@ static int hw_test_and_clear_setup_guard(void) ...@@ -695,7 +682,8 @@ static int hw_test_and_clear_setup_guard(void)
*/ */
static int hw_test_and_set_setup_guard(void) static int hw_test_and_set_setup_guard(void)
{ {
return hw_ctest_and_write(CAP_USBCMD, USBCMD_SUTW, USBCMD_SUTW); return hw_test_and_write(hw_bank.op, OP_USBCMD, USBCMD_SUTW,
USBCMD_SUTW);
} }
/** /**
...@@ -707,8 +695,9 @@ static int hw_test_and_set_setup_guard(void) ...@@ -707,8 +695,9 @@ static int hw_test_and_set_setup_guard(void)
static int hw_usb_set_address(u8 value) static int hw_usb_set_address(u8 value)
{ {
/* advance */ /* advance */
hw_cwrite(CAP_DEVICEADDR, DEVICEADDR_USBADR | DEVICEADDR_USBADRA, hw_write(hw_bank.op, OP_DEVICEADDR,
value << ffs_nr(DEVICEADDR_USBADR) | DEVICEADDR_USBADRA); DEVICEADDR_USBADR | DEVICEADDR_USBADRA,
value << ffs_nr(DEVICEADDR_USBADR) | DEVICEADDR_USBADRA);
return 0; return 0;
} }
...@@ -723,16 +712,16 @@ static int hw_usb_reset(void) ...@@ -723,16 +712,16 @@ static int hw_usb_reset(void)
hw_usb_set_address(0); hw_usb_set_address(0);
/* ESS flushes only at end?!? */ /* ESS flushes only at end?!? */
hw_cwrite(CAP_ENDPTFLUSH, ~0, ~0); /* flush all EPs */ hw_write(hw_bank.op, OP_ENDPTFLUSH, ~0, ~0);
/* clear setup token semaphores */ /* clear setup token semaphores */
hw_cwrite(CAP_ENDPTSETUPSTAT, 0, 0); /* writes its content */ hw_write(hw_bank.op, OP_ENDPTSETUPSTAT, 0, 0);
/* clear complete status */ /* clear complete status */
hw_cwrite(CAP_ENDPTCOMPLETE, 0, 0); /* writes its content */ hw_write(hw_bank.op, OP_ENDPTCOMPLETE, 0, 0);
/* wait until all bits cleared */ /* wait until all bits cleared */
while (hw_cread(CAP_ENDPTPRIME, ~0)) while (hw_read(hw_bank.op, OP_ENDPTPRIME, ~0))
udelay(10); /* not RTOS friendly */ udelay(10); /* not RTOS friendly */
/* reset all endpoints ? */ /* reset all endpoints ? */
...@@ -1514,13 +1503,14 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) ...@@ -1514,13 +1503,14 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
else else
mReqPrev->ptr->next = mReq->dma & TD_ADDR_MASK; mReqPrev->ptr->next = mReq->dma & TD_ADDR_MASK;
wmb(); wmb();
if (hw_cread(CAP_ENDPTPRIME, BIT(n))) if (hw_read(hw_bank.op, OP_ENDPTPRIME, BIT(n)))
goto done; goto done;
do { do {
hw_cwrite(CAP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW); hw_write(hw_bank.op, OP_USBCMD, USBCMD_ATDTW,
tmp_stat = hw_cread(CAP_ENDPTSTAT, BIT(n)); USBCMD_ATDTW);
} while (!hw_cread(CAP_USBCMD, USBCMD_ATDTW)); tmp_stat = hw_read(hw_bank.op, OP_ENDPTSTAT, BIT(n));
hw_cwrite(CAP_USBCMD, USBCMD_ATDTW, 0); } while (!hw_read(hw_bank.op, OP_USBCMD, USBCMD_ATDTW));
hw_write(hw_bank.op, OP_USBCMD, USBCMD_ATDTW, 0);
if (tmp_stat) if (tmp_stat)
goto done; goto done;
} }
...@@ -2524,12 +2514,12 @@ static int ci13xxx_wakeup(struct usb_gadget *_gadget) ...@@ -2524,12 +2514,12 @@ static int ci13xxx_wakeup(struct usb_gadget *_gadget)
trace("remote wakeup feature is not enabled\n"); trace("remote wakeup feature is not enabled\n");
goto out; goto out;
} }
if (!hw_cread(CAP_PORTSC, PORTSC_SUSP)) { if (!hw_read(hw_bank.op, OP_PORTSC, PORTSC_SUSP)) {
ret = -EINVAL; ret = -EINVAL;
trace("port is not suspended\n"); trace("port is not suspended\n");
goto out; goto out;
} }
hw_cwrite(CAP_PORTSC, PORTSC_FPR, PORTSC_FPR); hw_write(hw_bank.op, OP_PORTSC, PORTSC_FPR, PORTSC_FPR);
out: out:
spin_unlock_irqrestore(udc->lock, flags); spin_unlock_irqrestore(udc->lock, flags);
return ret; return ret;
...@@ -2796,8 +2786,8 @@ static irqreturn_t udc_irq(void) ...@@ -2796,8 +2786,8 @@ static irqreturn_t udc_irq(void)
spin_lock(udc->lock); spin_lock(udc->lock);
if (udc->udc_driver->flags & CI13XXX_REGS_SHARED) { if (udc->udc_driver->flags & CI13XXX_REGS_SHARED) {
if (hw_cread(CAP_USBMODE, USBMODE_CM) != if (hw_read(hw_bank.op, OP_USBMODE, USBMODE_CM) !=
USBMODE_CM_DEVICE) { USBMODE_CM_DEVICE) {
spin_unlock(udc->lock); spin_unlock(udc->lock);
return IRQ_NONE; return IRQ_NONE;
} }
...@@ -2875,7 +2865,7 @@ static void udc_release(struct device *dev) ...@@ -2875,7 +2865,7 @@ static void udc_release(struct device *dev)
* Kernel assumes 32-bit DMA operations by default, no need to dma_set_mask * Kernel assumes 32-bit DMA operations by default, no need to dma_set_mask
*/ */
static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev, static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev,
void __iomem *regs) void __iomem *regs, uintptr_t capoffset)
{ {
struct ci13xxx *udc; struct ci13xxx *udc;
int retval = 0; int retval = 0;
...@@ -2909,7 +2899,7 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev, ...@@ -2909,7 +2899,7 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev,
udc->gadget.dev.parent = dev; udc->gadget.dev.parent = dev;
udc->gadget.dev.release = udc_release; udc->gadget.dev.release = udc_release;
retval = hw_device_init(regs); retval = hw_device_init(regs, capoffset);
if (retval < 0) if (retval < 0)
goto free_udc; goto free_udc;
......
...@@ -140,6 +140,9 @@ struct ci13xxx { ...@@ -140,6 +140,9 @@ struct ci13xxx {
/****************************************************************************** /******************************************************************************
* REGISTERS * REGISTERS
*****************************************************************************/ *****************************************************************************/
/* Default offset of capability registers */
#define DEF_CAPOFFSET 0x100
/* register size */ /* register size */
#define REG_BITS (32) #define REG_BITS (32)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment