usb_ctl.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:23k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  *  This program is derived from Extenex Corporation's SA-1100 usb
  3.  *  controller core driver by MIZI.
  4.  * 
  5.  *  usb_ctl.c
  6.  *
  7.  *  S3C2410 USB controller core driver.
  8.  *
  9.  *  This file provides interrupt routing and overall coordination
  10.  *  of the five endpoints.
  11.  *  
  12.  *  Seungbum Lim <shawn@mizi.com>
  13.  */
  14. /*
  15.  * ep0 - register
  16.  * ep2~4 - dual port async. RAM (interrupt or DMA)
  17.  *
  18.  * config:
  19.  *  ep0.
  20.  *  ep2 : input - DMA_CH0 ?
  21.  *  ep1 : output - DMA_CH3 ?
  22.  */
  23. #include <linux/config.h>
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/proc_fs.h>
  27. #include <linux/tqueue.h>
  28. #include <linux/delay.h>
  29. #include <linux/slab.h>
  30. #include <linux/pci.h>
  31. #include <asm/io.h>
  32. #include <asm/dma.h>
  33. #include <asm/irq.h>
  34. #include <asm/mach-types.h>
  35. #include "s3c2410_usb.h"
  36. #include "usb_ctl.h"
  37. //////////////////////////////////////////////////////////////////////////////
  38. // Prototypes
  39. //////////////////////////////////////////////////////////////////////////////
  40. int usbctl_next_state_on_event( int event );
  41. static void udc_int_hndlr(int, void *, struct pt_regs *);
  42. static void initialize_descriptors( void );
  43. void ChangeUPllValue(int mdiv, int pdiv, int sdiv);
  44. void reset_usbd(void);
  45. void reconfig_usbd(void);
  46. //#define USB_DEBUG 1
  47. #ifdef USB_DEBUG
  48. #define LOG(arg...) printk(__FILE__":"__FUNCTION__"(): " ##arg)
  49. #else
  50. #define LOG(arg...) (void)(0)
  51. #endif
  52. #if CONFIG_PROC_FS
  53. #define PROC_NODE_NAME "usb"
  54. static int usbctl_read_proc(char *page, char **start, off_t off,
  55. int count, int *eof, void *data);
  56. #endif
  57. //////////////////////////////////////////////////////////////////////////////
  58. // Globals
  59. //////////////////////////////////////////////////////////////////////////////
  60. static const char pszMe[] = "usbctl: ";
  61. struct usb_info_t usbd_info;  /* global to ep0, usb_recv, usb_send */
  62. //static int cnt=0;
  63. /* device descriptors */
  64. static desc_t desc;
  65. #define MAX_STRING_DESC 8
  66. static string_desc_t * string_desc_array[ MAX_STRING_DESC ];
  67. static string_desc_t sd_zero;  /* special sd_zero holds language codes */
  68. // called when configured
  69. static usb_notify_t configured_callback = NULL;
  70. enum { kStateZombie  = 0,  kStateZombieSuspend  = 1,
  71. kStateDefault = 2,  kStateDefaultSuspend = 3,
  72. kStateAddr    = 4,  kStateAddrSuspend    = 5,
  73. kStateConfig  = 6,  kStateConfigSuspend  = 7
  74. };
  75. static int device_state_machine[8][6] = {
  76. //                suspend               reset          resume     adddr config deconfig
  77. /* zombie */  {  kStateZombieSuspend,  kStateDefault, kError,    kError, kError, kError },
  78. /* zom sus */ {  kError, kStateDefault, kStateZombie, kError, kError, kError },
  79. /* default */ {  kStateDefaultSuspend, kError, kStateDefault, kStateAddr, kError, kError },
  80. /* def sus */ {  kError, kStateDefault, kStateDefault, kError, kError, kError },
  81. /* addr */    {  kStateAddrSuspend, kStateDefault, kError, kError, kStateConfig, kError },
  82. /* addr sus */{  kError, kStateDefault, kStateAddr, kError, kError, kError },
  83. /* config */  {  kStateConfigSuspend, kStateDefault, kError, kError, kError, kStateAddr },
  84. /* cfg sus */ {  kError, kStateDefault, kStateConfig, kError, kError, kError }
  85. };
  86. /* "device state" is the usb device framework state, as opposed to the
  87.    "state machine state" which is whatever the driver needs and is much
  88.    more fine grained
  89. */
  90. static int sm_state_to_device_state[8] =
  91. //  zombie           zom suspend          default            default sus
  92. { USB_STATE_POWERED, USB_STATE_SUSPENDED, USB_STATE_DEFAULT, USB_STATE_SUSPENDED,
  93. // addr              addr sus             config                config sus
  94.   USB_STATE_ADDRESS, USB_STATE_SUSPENDED, USB_STATE_CONFIGURED, USB_STATE_SUSPENDED
  95. };
  96. static char * state_names[8] =
  97. { "zombie", "zombie suspended", "default", "default suspended",
  98.   "address", "address suspended", "configured", "config suspended"
  99. };
  100. static char * event_names[6] =
  101. { "suspend", "reset", "resume",
  102.   "address assigned", "configure", "de-configure"
  103. };
  104. static char * device_state_names[] =
  105. { "not attached", "attached", "powered", "default",
  106.   "address", "configured", "suspended" };
  107. static int sm_state = kStateZombie;
  108. //////////////////////////////////////////////////////////////////////////////
  109. // Reset Fucntions
  110. //////////////////////////////////////////////////////////////////////////////
  111. void reset_usbd(void)
  112. {
  113.     int i;
  114.     UD_PWR = UD_PWR_DEFAULT | UD_PWR_RESET; /* UD_PWR default value, MCU_RESET */
  115.     UD_PWR;
  116.     UD_PWR = UD_PWR_DEFAULT;
  117. LOG("UD_PWR = 0x%08xn", UD_PWR);
  118.     for(i = 0; i< 0x100; i++) ;
  119. }
  120. void reconfig_usbd(void)
  121. {
  122. LOG("n");
  123.     /* sec like, shawn */
  124.     ep0_state = EP0_STATE_IDLE;
  125.     set_configuration = 1;
  126.     set_interface = 1;
  127.     device_status = 0;
  128.     ep0_status = 0;
  129.     ep_bulk_in_status = 0;
  130.     ep_bulk_out_status = 0;
  131.     
  132.         UD_PWR = UD_PWR_DEFAULT;
  133.         /* EP0 */
  134. UD_INDEX = UD_INDEX_EP0;       
  135. UD_MAXP = UD_MAXP_8; // 8 byte
  136. UD_INDEX = UD_INDEX_EP0;
  137. UD_ICSR1 = EP0_CSR_SOPKTRDY | EP0_CSR_SSE;
  138.         /* EP2 */
  139. UD_INDEX = UD_INDEX_EP2;           
  140. UD_MAXP = UD_MAXP_64; // 64 byte
  141. UD_INDEX = UD_INDEX_EP2;
  142. UD_ICSR1 = UD_ICSR1_FFLUSH | UD_ICSR1_CLRDT; // fifo flush, data toggle
  143. UD_INDEX = UD_INDEX_EP2;
  144. UD_ICSR2 = UD_ICSR2_MODEIN | UD_ICSR2_DMAIEN; // input mode, IN_PKT_RDY dis 
  145. #ifdef USE_USBD_DMA
  146. UD_ICSR2 &= ~UD_ICSR2_DMAIEN;
  147. #endif
  148. /* EP1 */
  149. UD_INDEX = UD_INDEX_EP1;            
  150. UD_MAXP = UD_MAXP_64; // 64 byte
  151. UD_INDEX = UD_INDEX_EP1;
  152. UD_ICSR1 = UD_ICSR1_FFLUSH | UD_ICSR1_CLRDT; // fifo flush, data toggle
  153. UD_INDEX = UD_INDEX_EP1;
  154. UD_ICSR2 = 0x0; // output mode
  155. UD_INDEX = UD_INDEX_EP1;
  156. UD_OCSR1 = UD_OCSR1_FFLUSH | UD_OCSR1_CLRDT; // fifo flush
  157. UD_INDEX = UD_INDEX_EP1;
  158. UD_OCSR2 = UD_OCSR2_DMAIEN; // OUT_PKT_RDY interrupt disable
  159. #ifdef USE_USBD_DMA
  160. UD_OCSR2 &= ~UD_OCSR2_DMAIEN; // OUT_PKT_RDY interrupt disable
  161. #endif
  162. UD_INTE = UD_INTE_EP0 | UD_INTE_EP2 | UD_INTE_EP1;
  163. UD_USBINTE = UD_USBINTE_RESET | UD_USBINTE_SUSPND;
  164.         initialize_descriptors();
  165.    bINTCTL(oINTMSK) &= ~(INT_USBD);
  166. }
  167.     
  168. static void
  169. udc_int_hndlr(int irq, void *dev_id, struct pt_regs *regs)
  170. {
  171.    __u8 saveIdx = UD_INDEX;
  172.      __u8 usb_status = UD_USBINT;
  173.    __u8 usbd_status = UD_INT;
  174. static int sb_debug_cnt = 1;
  175. LOG("usb_status = 0x%02x, usbd_status = 0x%02xn",
  176. usb_status, usbd_status);
  177. if ( usb_status & UD_USBINT_RESET ) {
  178.     LOG("n[%d]RESET interruptn",sb_debug_cnt++);
  179.     if( usbctl_next_state_on_event(kEvReset) != kError ) {
  180. LOG("%s Resettingn",pszMe);
  181. ep0_reset();
  182. ep1_reset();/* output */
  183. ep2_reset();/* input */
  184.     }
  185.    // reset_usbd();
  186.     reconfig_usbd();
  187.     UD_USBINT = UD_USBINT_RESET; //RESET_INT should be cleared after reconfig_usbd().- by samsung src
  188.     ep0_state = EP0_STATE_IDLE;
  189. }
  190. /* RESume Interrupt Request */
  191. if ( usb_status & UD_USBINT_RESUM ) {
  192.   LOG("[%d]RESUME interruptn", sb_debug_cnt++);
  193. UD_USBINT = UD_USBINT_RESUM;/* clear */
  194. usbctl_next_state_on_event( kEvResume );
  195. }
  196. /* SUSpend Interrupt Request */
  197. if ( usb_status & UD_USBINT_SUSPND ) { 
  198. LOG("[%d]SUSPEND interruptn", sb_debug_cnt++);
  199. UD_USBINT = UD_USBINT_SUSPND; /* clear */
  200. usbctl_next_state_on_event( kEvSuspend );
  201. }
  202. if ( usbd_status & UD_INT_EP0 ) {
  203. LOG("n[%d]EP0 interruptn",sb_debug_cnt++);
  204. UD_INT = UD_INT_EP0; /* clear */
  205. ep0_int_hndlr();
  206. }
  207.          /* output */
  208. if ( usbd_status & UD_INT_EP1 ) { 
  209. LOG("[%d]EP1 interruptn", sb_debug_cnt++);
  210. UD_INT = UD_INT_EP1;/* clear */
  211. ep1_int_hndlr(usbd_status);
  212. }
  213.         /* input */
  214. if ( usbd_status & UD_INT_EP2 ) {
  215. LOG("[%d]EP2 interruptn", sb_debug_cnt++); 
  216. UD_INT = UD_INT_EP2; /* clear */
  217. ep2_int_hndlr(usbd_status);
  218. }
  219. if(usbd_status & UD_INT_EP3) UD_INT = UD_INT_EP3;
  220. if(usbd_status & UD_INT_EP4) UD_INT = UD_INT_EP4;
  221.    Clear_pending(INT_USBD);
  222. UD_INDEX= saveIdx;
  223. }
  224. //////////////////////////////////////////////////////////////////////////////
  225. // Public Interface
  226. //////////////////////////////////////////////////////////////////////////////
  227. /* Open S3C2410 usb core on behalf of a client, but don't start running */
  228. int
  229. s3c2410_usb_open( const char * client )
  230. {
  231. LOG("n");
  232.  if ( usbd_info.client_name != NULL )
  233.   return -EBUSY;
  234.  usbd_info.client_name = (char*) client;
  235.  memset(&usbd_info.stats, 0, sizeof(struct usb_stats_t));
  236.  memset(string_desc_array, 0, sizeof(string_desc_array));
  237.  /* hack to start in zombie suspended state */
  238. #if 0
  239.  sm_state = kStateZombieSuspend;
  240.  usbd_info.state = USB_STATE_SUSPENDED;
  241. #endif
  242.  /* create descriptors for enumeration */
  243.  initialize_descriptors();
  244.  printk( "%sOpened for %sn", pszMe, client );
  245.  return 0;
  246. }
  247. /* Start running. Must have called usb_open (above) first */
  248. int
  249. s3c2410_usb_start( void )
  250. {
  251. unsigned long tmp;
  252. LOG("n");
  253.  if ( usbd_info.client_name == NULL ) {
  254.   printk( "%s%s - no client registeredn",
  255.   pszMe, __FUNCTION__ );
  256.   return -EPERM;
  257.  }
  258.  /* start UDC internal machinery running */
  259.  udelay( 100 );
  260.  /* clear stall - receiver seems to start stalled? */
  261. UD_INDEX = UD_INDEX_EP2; // EP2 input 
  262. tmp = UD_ICSR1; 
  263. tmp &= ~(UD_ICSR1_SENTSTL | UD_ICSR1_FFLUSH | UD_ICSR1_UNDRUN);
  264.         tmp &= ~(UD_ICSR1_PKTRDY | UD_ICSR1_SENDSTL);
  265. UD_ICSR1 = tmp;
  266. UD_INDEX = UD_INDEX_EP1; // EP1 output
  267. tmp = UD_OCSR1;
  268. tmp &= ~(UD_OCSR1_SENTSTL | UD_OCSR1_FFLUSH | UD_OCSR1_OVRRUN);
  269. tmp &= ~(UD_OCSR1_PKTRDY | UD_OCSR1_SENDSTL);
  270. UD_OCSR1 = tmp;
  271. /* flush DMA and fire through some -EAGAINs */
  272. ep2_init( usbd_info.dmach_tx );
  273. ep1_init( usbd_info.dmach_rx );
  274. /* clear all top-level sources */
  275. UD_INT = UD_INT_EP0 | UD_INT_EP1 | UD_INT_EP2;
  276. UD_USBINT = UD_USBINT_RESET | UD_USBINT_RESUM | UD_USBINT_SUSPND;
  277. printk( "%sStarted for %sn", pszMe, usbd_info.client_name );
  278. return 0;
  279. }
  280. /* Stop USB core from running */
  281. int
  282. s3c2410_usb_stop( void )
  283. {
  284. LOG("name=%sn", usbd_info.client_name ? usbd_info.client_name : "NULL");
  285.  if ( usbd_info.client_name == NULL ) {
  286.   printk( "%s%s - no client registeredn",
  287.   pszMe, __FUNCTION__ );
  288.   return -EPERM;
  289.  }
  290. #if 0
  291.  /* It may be default value of S3C2410 USBD and makes only RESET be enalble*/
  292.  UD_INTM = 0x13f;
  293. #endif
  294.  ep1_reset(); 
  295.  ep2_reset();
  296.  printk( "%sStopped n", pszMe );
  297.  return 0;
  298. }
  299. /* Tell S3C2410 core client is through using it */
  300. int
  301. s3c2410_usb_close( void )
  302. {
  303.  if ( usbd_info.client_name == NULL ) {
  304.   printk( "%s%s - no client registeredn",
  305.   pszMe, __FUNCTION__ );
  306.   return -EPERM;
  307.  }
  308.  usbd_info.client_name = NULL;
  309.  return 0;
  310. }
  311. /* set a proc to be called when device is configured */
  312. usb_notify_t s3c2410_set_configured_callback( usb_notify_t func )
  313. {
  314.  usb_notify_t retval = configured_callback;
  315. LOG("n");
  316.  configured_callback = func;
  317.  return retval;
  318. }
  319. /*====================================================
  320.  * Descriptor Manipulation.
  321.  * Use these between open() and start() above to setup
  322.  * the descriptors for your device.
  323.  *
  324.  */
  325. /* get pointer to static default descriptor */
  326. desc_t *
  327. s3c2410_usb_get_descriptor_ptr( void ) { return &desc; }
  328. /* optional: set a string descriptor */
  329. int
  330. s3c2410_usb_set_string_descriptor( int i, string_desc_t * p )
  331. {
  332.  int retval;
  333.  LOG("n");
  334.  if ( i < MAX_STRING_DESC ) {
  335.   string_desc_array[i] = p;
  336.   retval = 0;
  337.  } else {
  338.   retval = -EINVAL;
  339.  }
  340.  return retval;
  341. }
  342. /* optional: get a previously set string descriptor */
  343. string_desc_t *
  344. s3c2410_usb_get_string_descriptor( int i )
  345. {
  346. LOG("n");
  347.  return ( i < MAX_STRING_DESC )
  348.     ? string_desc_array[i]
  349.     : NULL;
  350. }
  351. /* optional: kmalloc and unicode up a string descriptor */
  352. string_desc_t *
  353. s3c2410_usb_kmalloc_string_descriptor( const char * p )
  354. {
  355.  string_desc_t * pResult = NULL;
  356.  LOG("n");
  357.  if ( p ) {
  358.   int len = strlen( p );
  359.   int uni_len = len * sizeof( __u16 );
  360.   pResult = (string_desc_t*) kmalloc( uni_len + 2, GFP_KERNEL ); /* ugh! */
  361.   if ( pResult != NULL ) {
  362.    int i;
  363.    pResult->bLength = uni_len + 2;
  364.    pResult->bDescriptorType = USB_DESC_STRING;
  365.    for( i = 0; i < len ; i++ ) {
  366. pResult->bString[i] = make_word( (__u16) p[i] );
  367.    }
  368.   }
  369.  }
  370.  return pResult;
  371. }
  372. //////////////////////////////////////////////////////////////////////////////
  373. // Exports to rest of driver
  374. //////////////////////////////////////////////////////////////////////////////
  375. /* called by the int handler here and the two endpoint files when interesting
  376.    .."events" happen */
  377. int
  378. usbctl_next_state_on_event( int event )
  379. {
  380. int next_state = device_state_machine[ sm_state ][ event ];
  381. LOG("n");
  382. if ( next_state != kError )
  383. {
  384. int next_device_state = sm_state_to_device_state[ next_state ];
  385. printk( "%s%s --> [%s] --> %s. Device in %s state.n",
  386. pszMe, state_names[ sm_state ], event_names[ event ],
  387. state_names[ next_state ], device_state_names[ next_device_state ] );
  388. sm_state = next_state;
  389. if ( usbd_info.state != next_device_state )
  390. {
  391. if ( configured_callback != NULL
  392.  &&
  393.  next_device_state == USB_STATE_CONFIGURED
  394.  &&
  395.  usbd_info.state != USB_STATE_SUSPENDED
  396.    ) {
  397.   configured_callback();
  398. }
  399. usbd_info.state = next_device_state;
  400. }
  401. }
  402. #if 0
  403. else
  404. printk( "%s%s --> [%s] --> ??? is an error.n",
  405. pszMe, state_names[ sm_state ], event_names[ event ] );
  406. #endif
  407. return next_state;
  408. }
  409. //////////////////////////////////////////////////////////////////////////////
  410. // Private Helpers
  411. //////////////////////////////////////////////////////////////////////////////
  412. //* setup default descriptors */
  413. static void
  414. initialize_descriptors(void)
  415. {
  416. LOG("n");
  417. desc.dev.bLength               = sizeof( device_desc_t );
  418. desc.dev.bDescriptorType       = USB_DESC_DEVICE;
  419. desc.dev.bcdUSB                = 0x100; /* 1.1 */
  420. desc.dev.bDeviceClass          = 0xFF; /* vendor specific */
  421. desc.dev.bDeviceSubClass       = 0x0;
  422. desc.dev.bDeviceProtocol       = 0x0;
  423. desc.dev.bMaxPacketSize0       = 0x8; /* ep0 max fifo size in s3c2410*/
  424. desc.dev.idVendor              = 0x49f; /* vendor ID undefined */
  425. desc.dev.idProduct             = 0x505a; /* product */
  426. desc.dev.bcdDevice             = 0x01 ; /* vendor assigned device release num */
  427. desc.dev.iManufacturer         = 0; /* index of manufacturer string */
  428. desc.dev.iProduct              = 0; /* index of product description string */
  429. desc.dev.iSerialNumber         = 0; /* index of string holding product s/n */
  430. desc.dev.bNumConfigurations    = 0x1;
  431. desc.b.cfg.bLength             = sizeof( config_desc_t );
  432. desc.b.cfg.bDescriptorType     = USB_DESC_CONFIG;
  433. desc.b.cfg.wTotalLength        = make_word_c( sizeof(struct cdb) );
  434. desc.b.cfg.bNumInterfaces      = 1;
  435. desc.b.cfg.bConfigurationValue = 1;
  436. desc.b.cfg.iConfiguration      = 0;
  437. desc.b.cfg.bmAttributes        = USB_CONFIG_BUSPOWERED;
  438. desc.b.cfg.MaxPower            = USB_POWER( 500 );
  439. desc.b.intf.bLength            = sizeof( intf_desc_t );
  440. desc.b.intf.bDescriptorType    = USB_DESC_INTERFACE;
  441. desc.b.intf.bInterfaceNumber   = 0x0; /* unique intf index*/
  442. desc.b.intf.bAlternateSetting  = 0x0;
  443. desc.b.intf.bNumEndpoints      = 2; /* endpoint number excluding ep0 */
  444. desc.b.intf.bInterfaceClass    = 0xFF; /* vendor specific */
  445. desc.b.intf.bInterfaceSubClass = 0x0;
  446. desc.b.intf.bInterfaceProtocol = 0x0;
  447. desc.b.intf.iInterface         = 0x0;
  448. desc.b.ep1.bLength             = sizeof( ep_desc_t );
  449.         desc.b.ep1.bDescriptorType     = USB_DESC_ENDPOINT;
  450.         desc.b.ep1.bEndpointAddress    = USB_EP_ADDRESS( 1, USB_OUT );
  451.         desc.b.ep1.bmAttributes        = USB_EP_BULK;
  452.         desc.b.ep1.wMaxPacketSize      = make_word_c( 64 );
  453.         desc.b.ep1.bInterval        = 0x0;
  454. desc.b.ep2.bLength             = sizeof( ep_desc_t );
  455. desc.b.ep2.bDescriptorType     = USB_DESC_ENDPOINT;
  456. desc.b.ep2.bEndpointAddress    = USB_EP_ADDRESS( 2, USB_IN );
  457. desc.b.ep2.bmAttributes        = USB_EP_BULK;
  458. desc.b.ep2.wMaxPacketSize      = make_word_c( 64 );
  459. desc.b.ep2.bInterval           = 0x0;
  460. /* set language */
  461. /* See: http://www.usb.org/developers/data/USB_LANGIDs.pdf */
  462. sd_zero.bDescriptorType = USB_DESC_STRING;
  463. sd_zero.bLength         = sizeof( string_desc_t );
  464. sd_zero.bString[0]      = make_word_c( 0x409 ); /* American English */
  465. s3c2410_usb_set_string_descriptor( 0, &sd_zero );
  466. }
  467. //////////////////////////////////////////////////////////////////////////////
  468. // Proc Filesystem Support
  469. //////////////////////////////////////////////////////////////////////////////
  470. #if CONFIG_PROC_FS
  471. #define SAY( fmt, args... )  p += sprintf(p, fmt, ## args )
  472. #define SAYV(  num )         p += sprintf(p, num_fmt, "Value", num )
  473. #define SAYC( label, yn )    p += sprintf(p, yn_fmt, label, yn )
  474. #define SAYS( label, v )     p += sprintf(p, cnt_fmt, label, v )
  475. static int usbctl_read_proc(char *page, char **start, off_t off,
  476.     int count, int *eof, void *data)
  477. {
  478. const char * num_fmt   = "%25.25s: %8.8lXn";
  479. const char * cnt_fmt   = "%25.25s: %lun";
  480. const char * yn_fmt    = "%25.25s: %sn";
  481. const char * yes       = "YES";
  482. const char * no        = "NO";
  483. const char * mask      = "MASK";
  484. const char * enable    = "ENABLE";
  485. unsigned long v;
  486. unsigned long backup;
  487. char * p = page;
  488. int len;
  489. SAY( "S3C2410 USB Controller Coren" );
  490. SAY( "USB state: %s (%s) %dn",
  491. device_state_names[ sm_state_to_device_state[ sm_state ] ],
  492. state_names[ sm_state ],
  493. sm_state );
  494. SAYS( "ep0 bytes read", usbd_info.stats.ep0_bytes_read );
  495. SAYS( "ep0 bytes written", usbd_info.stats.ep0_bytes_written );
  496. SAYS( "ep0 FIFO read failures", usbd_info.stats.ep0_fifo_write_failures );
  497. SAYS( "ep0 FIFO write failures", usbd_info.stats.ep0_fifo_write_failures );
  498.  
  499. v = UD_FIFO0;
  500. SAY( "%25.25s: 0x%8.8lX - %ldn", "EP_FIFO0", v, v );
  501.  
  502. SAY( "n" );
  503. v = UD_FUNC;
  504. SAY( "%25.25s: 0x%8.8lX - %ldn", "Address Register", v, v );
  505. backup = UD_INDEX;
  506. UD_INDEX = UD_INDEX_EP0;
  507. v = UD_MAXP;
  508. SAY( "%25.25s: %ld (%8.8lX)n", "EP0 size(EP0)", v, v );
  509.  
  510. UD_INDEX = UD_INDEX_EP2;
  511. v = UD_MAXP;
  512. SAY( "%25.25s: %ld (%8.8lX)n", "IN  max packet size(EP2)", v, v );
  513. UD_INDEX = UD_INDEX_EP1;
  514. v = UD_MAXP;
  515. SAY( "%25.25s: %ld (%8.8lX)n", "OUT max packet size(EP1)", v, v );
  516. UD_INDEX = backup;
  517. v = UD_PWR;
  518. SAY( "nUDC POWER Management Registern" );
  519. SAYV( v );
  520. SAYC( "ISO Update(R)",    ( v & UD_PWR_ISOUP )     ? yes : no );
  521. SAYC( "USB Reset(R)",   ( v & UD_PWR_RESET ) ? yes : no );
  522. SAYC( "MCU Resume(RW)",  ( v & UD_PWR_RESUME  ) ? yes : no );
  523. SAYC( "Suspend Mode(R)",( v & UD_PWR_SUSPND ) ? yes : no );
  524. SAYC( "Suspend Mode enable bit(RW)",  ( v & UD_PWR_ENSUSPND ) ? yes : no );
  525.  
  526.  
  527. v = UD_INT;
  528. SAY( "nUDC Interrupt Registern" );
  529. SAYV( v );
  530. SAYC( "EP4 pending",        ( v & UD_INT_EP4 )     ? yes : no );
  531. SAYC( "EP3 pending",        ( v & UD_INT_EP3 )     ? yes : no );
  532. SAYC( "EP2 pending",        ( v & UD_INT_EP2 )     ? yes : no );
  533. SAYC( "EP1 pending",        ( v & UD_INT_EP1 )     ? yes : no );
  534. SAYC( "EP0 pending",        ( v & UD_INT_EP0 )     ? yes : no );
  535. v = UD_USBINT;
  536. SAY( "nUSB Interrupt Registern" );
  537. SAYV( v );
  538. SAYC( "Reset",        ( v & UD_USBINT_RESET )     ? yes : no );
  539. SAYC( "Resume",        ( v & UD_USBINT_RESUM )     ? yes : no );
  540. SAYC( "Suspend",        ( v & UD_USBINT_SUSPND )     ? yes : no );
  541. v = UD_INTE;
  542. SAY( "nUDC Interrupt Enable Registern" );
  543. SAYV( v );
  544. SAYC( "EP4",                !( v & UD_INTE_EP4 )    ? mask : enable );
  545. SAYC( "EP3",                !( v & UD_INTE_EP3 )    ? mask : enable );
  546. SAYC( "EP2",                !( v & UD_INTE_EP2 )    ? mask : enable );
  547. SAYC( "EP1",                !( v & UD_INTE_EP1 )    ? mask : enable );
  548. SAYC( "EP0",                !( v & UD_INTE_EP0 )    ? mask : enable );
  549. v = UD_USBINTE;
  550. SAY( "nUSB Interrupt Enable Registern" );
  551. SAYV( v );
  552. SAYC( "Reset",              !( v & UD_USBINTE_RESET )    ? mask : enable );
  553. SAYC( "Suspend",            !( v & UD_USBINTE_SUSPND )  ? mask : enable );
  554. len = ( p - page ) - off;
  555. if ( len < 0 )
  556.      len = 0;
  557. *eof = ( len <=count ) ? 1 : 0;
  558. *start = page + off;
  559. return len;
  560. }
  561. #endif  /* CONFIG_PROC_FS */
  562. #if defined(CONFIG_PM) && defined(CONFIG_MIZI)
  563. void usbctl_suspend(void)
  564. {
  565. /* TODO: FIXME: */
  566. }
  567. void usbctl_resume(void)
  568. {
  569. /* TODO: FIXME: */
  570. }
  571. #endif
  572. //////////////////////////////////////////////////////////////////////////////
  573. // Module Initialization and Shutdown
  574. //////////////////////////////////////////////////////////////////////////////
  575. /*
  576.  * usbctl_init()
  577.  * Module load time. Allocate dma and interrupt resources. Setup /proc fs
  578.  * entry. Leave UDC disabled.
  579.  */
  580. int __init usbctl_init( void )
  581. {
  582. int retval = 0;
  583. #if CONFIG_MAX_ROOT_PORTS > 1
  584. printk("check your kernel config.n");
  585. return -ENODEV;
  586. #endif
  587. memset( &usbd_info, 0, sizeof( usbd_info ) );
  588. usbd_info.dmach_tx = DMA_CH3; // ep1
  589. usbd_info.dmach_rx = DMA_CH0; // ep2
  590. #if CONFIG_PROC_FS
  591. create_proc_read_entry ( PROC_NODE_NAME, 0, NULL, usbctl_read_proc, NULL);
  592. #endif
  593. #ifdef USE_USBD_DMA
  594. lsdkjflsdkjsdlkjflksdjf
  595. /* setup dma */
  596. #if 1
  597. retval = s3c2410_request_dma("USB", DMA_CH0, 
  598.  ep1_dma_callback, NULL);
  599. if (retval) {
  600. printk("%sunable to register for dma rc=%dn", pszMe, retval);
  601. goto err_dma;
  602. }
  603. retval = s3c2410_request_dma("USB", DMA_CH2, 
  604.  NULL, ep2_dma_callback);
  605. if (retval) {
  606. printk("%sunable to register for dma rc=%dn", pszMe, retval);
  607. goto err_dma;
  608. }
  609. #else
  610. retval = s3c2410_request_dma("USB", DMA_CH0, 
  611.  ep1_dma_callback, ep2_dma_callback);
  612. if (retval) {
  613. printk("%sunable to register for dma rc=%dn", pszMe, retval);
  614. goto err_dma;
  615. }
  616. #endif
  617. #endif // USE_USBD_DMA
  618. /* now allocate the IRQ. */
  619. retval = request_irq(IRQ_USBD, udc_int_hndlr, SA_INTERRUPT,
  620.   "S3C2410 USB core", NULL);
  621. if (retval) {
  622. printk("%sCouldn't request USB irq rc=%dn",pszMe, retval);
  623. goto err_irq;
  624. }
  625. /* MISC. register */
  626. MISCCR &= ~MISCCR_USBPAD;
  627. /* UPLLCON */
  628. UPLLCON = FInsrt(0x78, fPLL_MDIV) | FInsrt(0x02, fPLL_PDIV) 
  629. | FInsrt(0x03, fPLL_SDIV);
  630. /* CLKCON */
  631. CLKCON |= CLKCON_USBD;
  632.      Clear_pending(INT_USBD);
  633. printk( "S3C2410 USB Controller Core Initializedn");
  634. return 0;
  635. err_irq:
  636. #ifdef USE_USBD_DMA
  637. s3c2410_free_dma(DMA_CH0);
  638. s3c2410_free_dma(DMA_CH3);
  639. #endif 
  640. err_dma:
  641. usbd_info.dmach_tx = 0;
  642. usbd_info.dmach_rx = 0;
  643. return retval;
  644. }
  645. /*
  646.  * usbctl_exit()
  647.  * Release DMA and interrupt resources
  648.  */
  649. void __exit usbctl_exit( void )
  650. {
  651.     printk("Unloading S3C2410 USB Controllern");
  652. CLKCON &= ~CLKCON_USBD;
  653. #ifdef CONFIG_PROC_FS
  654.     remove_proc_entry ( PROC_NODE_NAME, NULL);
  655. #endif
  656. #ifdef USE_USBD_DMA
  657.     s3c2410_free_dma(usbd_info.dmach_rx);
  658.     s3c2410_free_dma(usbd_info.dmach_tx);
  659. #endif
  660.     free_irq(IRQ_USBD, NULL);
  661. }
  662. EXPORT_SYMBOL( s3c2410_usb_open );
  663. EXPORT_SYMBOL( s3c2410_usb_start );
  664. EXPORT_SYMBOL( s3c2410_usb_stop );
  665. EXPORT_SYMBOL( s3c2410_usb_close );
  666. EXPORT_SYMBOL( s3c2410_usb_get_descriptor_ptr );
  667. EXPORT_SYMBOL( s3c2410_usb_set_string_descriptor );
  668. EXPORT_SYMBOL( s3c2410_usb_get_string_descriptor );
  669. EXPORT_SYMBOL( s3c2410_usb_kmalloc_string_descriptor );
  670. #if defined(CONFIG_PM) && defined(CONFIG_MIZI)
  671. EXPORT_SYMBOL( usbctl_resume );
  672. EXPORT_SYMBOL( usbctl_suspend );
  673. #endif
  674. module_init( usbctl_init );
  675. module_exit( usbctl_exit );