]> rtime.felk.cvut.cz Git - sysless.git/commitdiff
LPC178x: Update USB device support for new architecture.
authorPavel Pisa <pisa@cmp.felk.cvut.cz>
Thu, 20 Dec 2012 23:23:48 +0000 (00:23 +0100)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Thu, 20 Dec 2012 23:23:48 +0000 (00:23 +0100)
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
arch/arm/mach-lpc178x/defines/lpcUSB.h
libs4c/usb/lpcusb/lpcusb.c

index 0c7cd41277a2949c27fcb7f3df06c38fa9dfc492..e8bb789ad4609f5aad34552aad48bf8c41dacb8c 100644 (file)
@@ -272,9 +272,13 @@ typedef struct
   REG32 SysErrIntSet;  /* USB System Error Interrupt Set (WO) 00C0 */
 } usbRegs_t;
 
-#define USBIntSt (*(REG32*)0x400FC10) /* USB Interrupt Status (R/W) */
+#define USBIntSt (*(REG32*)0x400FC1C0) /* USB Interrupt Status (R/W) */
 
-#define USB_REGS_BASE  0x5000C000UL
+#ifdef MACH_LPC178X
+  #define USB_REGS_BASE        0x2008C000UL
+#else
+  #define USB_REGS_BASE        0x5000C000UL
+#endif
 
 #define HcControlHeadED_o      0x0020  /* PADDR of 1st EP desc. of control list (R/W) */
 #define HcControlCurrentED_o   0x0024  /* PADDR of curr. EP desc. of control list (R/W) */
index 4041371cac03d849dd6c5abeb8267d6af71deb86..b0dbf64bd7af68344d70289898092e321204cb12 100644 (file)
@@ -8,7 +8,14 @@
 #include <usb/usb.h>
 #include <usb/lpcusb.h>
 
-#ifdef MACH_LPC17XX
+#if defined(MACH_LPC178X)
+ #include <LPC177x_8x.h>
+ #include <lpcUSB.h>
+ #include <hal_gpio.h>
+ #ifndef PCONP
+  #define PCONP (LPC_SC->PCONP)
+ #endif
+#elif defined(MACH_LPC17XX)
  #include <LPC17xx.h>
  #include <lpcUSB.h>
  #ifndef PINSEL1
 #define USB_VBUS_PIN_USED 1
 #endif
 
+static void lpc_usb_configure_pins(void)
+{
+#ifdef USB_PPWR2_PIN
+ #define NEW_USB_PIN_CFG
+  hal_pin_conf(USB_PPWR2_PIN);
+#endif
+#ifdef USB_DPLUS_PIN
+ #define NEW_USB_PIN_CFG
+  hal_pin_conf(USB_DPLUS_PIN);
+#endif
+#ifdef USB_DMINUS_PIN
+ #define NEW_USB_PIN_CFG
+  hal_pin_conf(USB_DMINUS_PIN);
+#endif
+#ifdef USB1_DPLUS_PIN
+ #define NEW_USB_PIN_CFG
+  hal_pin_conf(USB1_DPLUS_PIN);
+#endif
+#ifdef USB1_DMINUS_PIN
+ #define NEW_USB_PIN_CFG
+  hal_pin_conf(USB1_DMINUS_PIN);
+#endif
+#ifdef USB2_DPLUS_PIN
+ #define NEW_USB_PIN_CFG
+  hal_pin_conf(USB2_DPLUS_PIN);
+#endif
+#ifdef USB2_DMINUS_PIN
+ #define NEW_USB_PIN_CFG
+  hal_pin_conf(USB2_DMINUS_PIN);
+#endif
+#ifdef USB2_OVRCR_PIN
+ #define NEW_USB_PIN_CFG
+  hal_pin_conf(USB2_OVRCR_PIN);
+#endif
+#ifdef USB_CONNECT_PIN
+ #define NEW_USB_PIN_CFG
+  hal_pin_conf(USB_CONNECT_PIN);
+#endif
+#ifdef USB1_CONNECT_PIN
+ #define NEW_USB_PIN_CFG
+  hal_pin_conf(USB1_CONNECT_PIN);
+#endif
+#ifdef USB1_PWR_SW_PIN
+ #define NEW_USB_PIN_CFG
+  hal_pin_conf(USB1_PWR_SW_PIN);
+#endif
+#ifdef USB1_ID_PIN
+ #define NEW_USB_PIN_CFG
+  hal_pin_conf(USB1_ID_PIN);
+#endif
+#if defined(USB_VBUS_PIN) && defined(USB_VBUS_PIN_USED)
+ #define NEW_USB_PIN_CFG
+  hal_pin_conf(USB_VBUS_PIN);
+#endif
+
+#ifndef NEW_USB_PIN_CFG
+#if defined(INC_LPC214x_H) || defined(MACH_LPC21XX)
+  PINSEL1 &= ~0xC000C000;
+//  PINSEL1 |=  0x40004000;                   /* Select USB Link, VBUS */
+  PINSEL1 |=  0x80000000;                   /* Select USB Link, VBUS */
+#endif /* MACH_LPC21XX */
+#if defined(MACH_LPC23XX) || defined(MACH_LPC17XX) || defined(MACH_LPC178X)
+  /* set up USB pins */
+  PINSEL1 = (PINSEL1 & ~(0x3<<26)) | (0x1<<26);  /* USB_D+,- @ P0.29,30 */
+  PINSEL4 = (PINSEL4 & ~(0x3<<18)) | (0x1<<18);  /* USB_CONNECT @ P2.9 */
+#if USB_VBUS_PIN_USED
+  PINSEL3 = (PINSEL3 & ~(0x3<<28)) | (0x2<<28);  /* Vbus @ P1.30 */
+#endif
+#endif /* Known LPC MACH */
+#endif /*NEW_USB_PIN_CFG*/
+}
+
 unsigned int lpc_ep2addr(unsigned int ep_num) 
 {
   unsigned int val;
@@ -119,12 +198,9 @@ void lpc_usb_reset(void)
 
 void lpc_usb_hw_init (void) 
 {
+  lpc_usb_configure_pins();
 
 #if defined(INC_LPC214x_H) || defined(MACH_LPC21XX)
-  PINSEL1 &= ~0xC000C000;
-//  PINSEL1 |=  0x40004000;                   /* Select USB Link, VBUS */
-  PINSEL1 |=  0x80000000;                   /* Select USB Link, VBUS */
-
   PCONP |= 0x80000000;                      /* Turn On USB PCLK */
 
   /* Configure 48MHz USB Clock;  FOsc = 12MHz, M = 4, P = 2 */
@@ -142,7 +218,7 @@ void lpc_usb_hw_init (void)
   USBDevIntEn  = USBDevInt_DEV_STAT;        /* Enable Device Status Interrupt */
 #endif /* MACH_LPC21XX */
 
-#if defined(MACH_LPC23XX) || defined(MACH_LPC17XX)
+#if defined(MACH_LPC23XX) || defined(MACH_LPC17XX) || defined(MACH_LPC178X)
   /**
    ** ** ATTENTION **
    ** USB clock (48MHz) should be set up externally before calling this fn
@@ -152,12 +228,6 @@ void lpc_usb_hw_init (void)
    ** from this fn.
    **/
 
-  /* set up USB pins */
-  PINSEL1 = (PINSEL1 & ~(0x3<<26)) | (0x1<<26);  /* USB_D+,- @ P0.29,30 */
-  PINSEL4 = (PINSEL4 & ~(0x3<<18)) | (0x1<<18);  /* USB_CONNECT @ P2.9 */
-#if USB_VBUS_PIN_USED
-  PINSEL3 = (PINSEL3 & ~(0x3<<28)) | (0x2<<28);  /* Vbus @ P1.30 */
-#endif
   /* switch USB power on */
   PCONP |= 1<<31;
   /* switch USB internal clock switch on */
@@ -166,6 +236,10 @@ void lpc_usb_hw_init (void)
 
 #endif /* MACH_LPC23XX */
 
+#if defined(MACH_LPC178X)
+//  OTGStCtrl &= ~3;
+#endif
+
   /* Partial Manual Reset since Automatic Bus Reset is not working */
   lpc_usb_reset();
   lpc_usb_set_addr(0);