]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - embedded/libs4c/usb/lpcusb/lpcusb.c
Update of system-less architecture and board support code to actual uLAN.sf.net version.
[lincan.git] / embedded / libs4c / usb / lpcusb / lpcusb.c
index 09b1eacdcafc0a280668bc36fa70d17923bbdb90..4041371cac03d849dd6c5abeb8267d6af71deb86 100644 (file)
@@ -8,6 +8,23 @@
 #include <usb/usb.h>
 #include <usb/lpcusb.h>
 
 #include <usb/usb.h>
 #include <usb/lpcusb.h>
 
+#ifdef MACH_LPC17XX
+ #include <LPC17xx.h>
+ #include <lpcUSB.h>
+ #ifndef PINSEL1
+  #define PINSEL1 (PINCON->PINSEL1)
+  #define PINSEL3 (PINCON->PINSEL3)
+  #define PINSEL4 (PINCON->PINSEL4)
+ #endif
+ #ifndef PCONP
+  #define PCONP (SC->PCONP)
+ #endif
+#endif
+
+#ifndef USB_VBUS_PIN_USED
+#define USB_VBUS_PIN_USED 1
+#endif
+
 unsigned int lpc_ep2addr(unsigned int ep_num) 
 {
   unsigned int val;
 unsigned int lpc_ep2addr(unsigned int ep_num) 
 {
   unsigned int val;
@@ -103,6 +120,7 @@ void lpc_usb_reset(void)
 void lpc_usb_hw_init (void) 
 {
 
 void lpc_usb_hw_init (void) 
 {
 
+#if defined(INC_LPC214x_H) || defined(MACH_LPC21XX)
   PINSEL1 &= ~0xC000C000;
 //  PINSEL1 |=  0x40004000;                   /* Select USB Link, VBUS */
   PINSEL1 |=  0x80000000;                   /* Select USB Link, VBUS */
   PINSEL1 &= ~0xC000C000;
 //  PINSEL1 |=  0x40004000;                   /* Select USB Link, VBUS */
   PINSEL1 |=  0x80000000;                   /* Select USB Link, VBUS */
@@ -122,6 +140,31 @@ void lpc_usb_hw_init (void)
   PLLFEED48 = 0x55;                         /* Feed Sequence 2 */
 
   USBDevIntEn  = USBDevInt_DEV_STAT;        /* Enable Device Status Interrupt */
   PLLFEED48 = 0x55;                         /* Feed Sequence 2 */
 
   USBDevIntEn  = USBDevInt_DEV_STAT;        /* Enable Device Status Interrupt */
+#endif /* MACH_LPC21XX */
+
+#if defined(MACH_LPC23XX) || defined(MACH_LPC17XX)
+  /**
+   ** ** ATTENTION **
+   ** USB clock (48MHz) should be set up externally before calling this fn
+   ** by setting USBCLKCFG (eg. USBCLKCFG = 5 for f_cco=288MHz).
+   ** If some of the pins shared with USB device are to be used for
+   ** different purpose, following PINSELs must be changed after retutn
+   ** 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 */
+  USBClkCtrl = 0x12;
+  while ((USBClkSt & 0x12) != 0x12);
+
+#endif /* MACH_LPC23XX */
 
   /* Partial Manual Reset since Automatic Bus Reset is not working */
   lpc_usb_reset();
 
   /* Partial Manual Reset since Automatic Bus Reset is not working */
   lpc_usb_reset();