summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-07-17 02:55:04 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-07-17 02:55:04 +0000
commit2a84c64a4d42b3d8033c8f0c7677c5f437971158 (patch)
treee29235d281c6044305ad897a1ada7489d1cd7cde
parent8b47a53be49fecec1408ee5081f90c9be7b8c23e (diff)
downloadnuttx-2a84c64a4d42b3d8033c8f0c7677c5f437971158.tar.gz
nuttx-2a84c64a4d42b3d8033c8f0c7677c5f437971158.tar.bz2
nuttx-2a84c64a4d42b3d8033c8f0c7677c5f437971158.zip
Correct some USB initialization logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2807 42af7a65-404d-4744-a932-0658087f49c3
-rwxr-xr-xnuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c88
1 files changed, 54 insertions, 34 deletions
diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c b/nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c
index 6c584d513..6781c9092 100755
--- a/nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c
+++ b/nuttx/arch/arm/src/lpc17xx/lpc17_usbdev.c
@@ -1233,7 +1233,7 @@ static void lpc17_eprealize(struct lpc17_ep_s *privep, bool prio, uint32_t packe
{
struct lpc17_usbdev_s *priv = privep->dev;
uint32_t mask;
- uint32_t reg;
+ uint32_t regval;
/* Initialize endpoint software priority */
@@ -1253,9 +1253,9 @@ static void lpc17_eprealize(struct lpc17_ep_s *privep, bool prio, uint32_t packe
/* Realize the endpoint */
- reg = lpc17_getreg(LPC17_USBDEV_REEP);
- reg |= (1 << privep->epphy);
- lpc17_putreg(reg, LPC17_USBDEV_REEP);
+ regval = lpc17_getreg(LPC17_USBDEV_REEP);
+ regval |= (1 << privep->epphy);
+ lpc17_putreg(regval, LPC17_USBDEV_REEP);
/* Set endpoint maximum packet size */
@@ -2323,7 +2323,7 @@ static int lpc17_dmasetup(struct lpc17_usbdev_s *priv, uint8_t epphy,
bool isochronous);
{
struct lpc17_dmadesc_s *dmadesc = priv;
- uint32_t reg;
+ uint32_t regval;
#ifdef CONFIG_DEBUG
if (!priv || epphy < 2)
@@ -2378,10 +2378,10 @@ static int lpc17_dmasetup(struct lpc17_usbdev_s *priv, uint8_t epphy,
/* Check state of IN/OUT Ep buffer */
- reg = lpc17_usbcmd(CMD_USBDEV_EPSELECT | epphy, 0);
+ regval = lpc17_usbcmd(CMD_USBDEV_EPSELECT | epphy, 0);
- if ((LPC17_EPPHYIN(epphy) && (reg & 0x60) == 0) ||
- (LPC17_EPPHYOUT(epphy) && (reg & 0x60) == 0x60))
+ if ((LPC17_EPPHYIN(epphy) && (regval & 0x60) == 0) ||
+ (LPC17_EPPHYOUT(epphy) && (regval & 0x60) == 0x60))
{
/* DMA should be "being serviced" */
@@ -2408,7 +2408,7 @@ static int lpc17_dmasetup(struct lpc17_usbdev_s *priv, uint8_t epphy,
#ifdef CONFIG_LPC17_USBDEV_DMA
static void lpc17_dmarestart(uint8_t epphy, uint32_t descndx)
{
- uint32_t reg;
+ uint32_t regval;
/* Clear DMA descriptor status */
@@ -2420,9 +2420,9 @@ static void lpc17_dmarestart(uint8_t epphy, uint32_t descndx)
/* Check the state of IN/OUT EP buffer */
- uint32_t reg = lpc17_usbcmd(CMD_USBDEV_EPSELECT | epphy, 0);
- if ((LPC17_EPPHYIN(epphy) && (reg & 0x60) == 0) ||
- (LPC17_EPPHYIN(epphy) && (reg & 0x60) == 0x60))
+ uint32_t regval = lpc17_usbcmd(CMD_USBDEV_EPSELECT | epphy, 0);
+ if ((LPC17_EPPHYIN(epphy) && (regval & 0x60) == 0) ||
+ (LPC17_EPPHYIN(epphy) && (regval & 0x60) == 0x60))
{
/* Re-trigger the DMA Transfer */
@@ -2521,7 +2521,7 @@ static int lpc17_epdisable(FAR struct usbdev_ep_s *ep)
FAR struct lpc17_ep_s *privep = (FAR struct lpc17_ep_s *)ep;
irqstate_t flags;
uint32_t mask = (1 << privep->epphy);
- uint32_t reg;
+ uint32_t regval;
#ifdef CONFIG_DEBUG
if (!ep)
@@ -2539,15 +2539,15 @@ static int lpc17_epdisable(FAR struct usbdev_ep_s *ep)
/* Disable endpoint and interrupt */
- reg = lpc17_getreg(LPC17_USBDEV_REEP);
- reg &= ~mask;
- lpc17_putreg(reg, LPC17_USBDEV_REEP);
+ regval = lpc17_getreg(LPC17_USBDEV_REEP);
+ regval &= ~mask;
+ lpc17_putreg(regval, LPC17_USBDEV_REEP);
lpc17_putreg(mask, LPC17_USBDEV_EPDMADIS);
- reg = lpc17_getreg(LPC17_USBDEV_EPINTEN);
- reg &= ~mask;
- lpc17_putreg(reg, LPC17_USBDEV_EPINTEN);
+ regval = lpc17_getreg(LPC17_USBDEV_EPINTEN);
+ regval &= ~mask;
+ lpc17_putreg(regval, LPC17_USBDEV_EPINTEN);
irqrestore(flags);
return OK;
@@ -3078,14 +3078,12 @@ static int lpc17_pullup(struct usbdev_s *dev, bool enable)
void up_usbinitialize(void)
{
struct lpc17_usbdev_s *priv = &g_usbdev;
- uint32_t reg;
+ uint32_t regval;
+ irqstate_t flags;
int i;
usbtrace(TRACE_DEVINIT, 0);
- uint32_t regval;
- irqstate_t flags;
-
/* Step 1: Enable power by setting PCUSB in the PCONP register */
flags = irqsave();
@@ -3167,14 +3165,36 @@ void up_usbinitialize(void)
}
}
- /* Turn on USB power and clocking */
+ /* Turn on USB power */
flags = irqsave();
- reg = lpc17_getreg(LPC17_SYSCON_PCONP);
- reg |= SYSCON_PCONP_PCUSB;
- lpc17_putreg(reg, LPC17_SYSCON_PCONP);
+ regval = lpc17_getreg(LPC17_SYSCON_PCONP);
+ regval |= SYSCON_PCONP_PCUSB;
+ lpc17_putreg(regval, LPC17_SYSCON_PCONP);
irqrestore(flags);
+ /* Enable device and AHB clocking */
+
+ lpc17_putreg(USBDEV_CLK_DEVCLK|USBDEV_CLK_AHBCLK, LPC17_USBDEV_CLKCTRL);
+
+ /* And wait for the clocks to be reported as "ON" */
+
+ do
+ {
+ regval = lpc17_getreg(LPC17_USBDEV_CLKST);
+ }
+ while ((regval & (USBDEV_CLK_DEVCLK|USBDEV_CLK_AHBCLK)) != (USBDEV_CLK_DEVCLK|USBDEV_CLK_AHBCLK));
+
+ /* Make sure all USB interrupts are disabled and cleared */
+
+ lpc17_putreg(0, LPC17_USBDEV_INTEN);
+ lpc17_putreg(0xffffffff, LPC17_USBDEV_INTCLR);
+ lpc17_putreg(0, LPC17_USBDEV_INTPRI);
+
+ lpc17_putreg(0, LPC17_USBDEV_EPINTEN);
+ lpc17_putreg(0xffffffff, LPC17_USBDEV_EPINTCLR);
+ lpc17_putreg(0, LPC17_USBDEV_EPINTPRI);
+
/* Attach USB controller interrupt handler */
if (irq_attach(LPC17_IRQ_USB, lpc17_usbinterrupt) != 0)
@@ -3184,14 +3204,14 @@ void up_usbinitialize(void)
goto errout;
}
- /* Enable USB inerrupts at the controller -- but do not disable
+ /* Enable USB interrupts at the controller -- but do not enable
* the ARM interrupt until the device is bound to the class
* driver
*/
flags = irqsave();
- reg = lpc17_getreg(LPC17_SYSCON_USBINTST);
- reg |= SYSCON_USBINTST_ENINTS;
+ regval = lpc17_getreg(LPC17_SYSCON_USBINTST);
+ regval |= SYSCON_USBINTST_ENINTS;
lpc17_putreg(regval, LPC17_SYSCON_USBINTST);
irqrestore(flags);
@@ -3224,7 +3244,7 @@ errout:
void up_usbuninitialize(void)
{
struct lpc17_usbdev_s *priv = &g_usbdev;
- uint32_t reg;
+ uint32_t regval;
irqstate_t flags;
usbtrace(TRACE_DEVUNINIT, 0);
@@ -3249,9 +3269,9 @@ void up_usbuninitialize(void)
/* Turn off USB power and clocking */
- reg = lpc17_getreg(LPC17_SYSCON_PCONP);
- reg &= ~SYSCON_PCONP_PCUSB;
- lpc17_putreg(reg, LPC17_SYSCON_PCONP);
+ regval = lpc17_getreg(LPC17_SYSCON_PCONP);
+ regval &= ~SYSCON_PCONP_PCUSB;
+ lpc17_putreg(regval, LPC17_SYSCON_PCONP);
irqrestore(flags);
}