From 50aae86eeae6b108806ac05a0cc9594c38b5b2e3 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Fri, 21 Dec 2012 00:23:48 +0100 Subject: [PATCH] LPC178x: Update USB device support for new architecture. Signed-off-by: Pavel Pisa --- arch/arm/mach-lpc178x/defines/lpcUSB.h | 8 ++- libs4c/usb/lpcusb/lpcusb.c | 98 ++++++++++++++++++++++---- 2 files changed, 92 insertions(+), 14 deletions(-) diff --git a/arch/arm/mach-lpc178x/defines/lpcUSB.h b/arch/arm/mach-lpc178x/defines/lpcUSB.h index 0c7cd41..e8bb789 100644 --- a/arch/arm/mach-lpc178x/defines/lpcUSB.h +++ b/arch/arm/mach-lpc178x/defines/lpcUSB.h @@ -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) */ diff --git a/libs4c/usb/lpcusb/lpcusb.c b/libs4c/usb/lpcusb/lpcusb.c index 4041371..b0dbf64 100644 --- a/libs4c/usb/lpcusb/lpcusb.c +++ b/libs4c/usb/lpcusb/lpcusb.c @@ -8,7 +8,14 @@ #include #include -#ifdef MACH_LPC17XX +#if defined(MACH_LPC178X) + #include + #include + #include + #ifndef PCONP + #define PCONP (LPC_SC->PCONP) + #endif +#elif defined(MACH_LPC17XX) #include #include #ifndef PINSEL1 @@ -25,6 +32,78 @@ #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); -- 2.39.2