Delboy

Untitled

May 8th, 2011
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.85 KB | None | 0 0
  1. /*--------------------------------------------------------------------------*/
  2. /* {{{ initialization of the HC and the root hub: */
  3.  
  4. /*{{{*/
  5. static void
  6. dwc3884_power_on (void)
  7. {
  8. #ifdef CONFIG_PORTA_DANUBE
  9.     // set gpio's for controlling usb power and clock gating
  10. #if 0               // JR: Keep this active for real project ??? NO -> This is done by scm_app
  11. // #if 0 // JR: initial init is done by u-boot in demo project ...
  12.     // JR: usb power is on gpio 29
  13.     clear_bit (13, DANUBE_GPIO_P1_ALTSEL0);
  14.     clear_bit (13, DANUBE_GPIO_P1_ALTSEL1);
  15.     set_bit (13, DANUBE_GPIO_P1_OD);
  16.     set_bit (13, DANUBE_GPIO_P1_DIR);
  17.     clear_bit (13, DANUBE_GPIO_P1_PUDSEL);
  18.     clear_bit (13, DANUBE_GPIO_P1_PUDEN);
  19.     set_bit (13, DANUBE_GPIO_P1_OUT);
  20. #endif
  21.  
  22. #else // CONFIG_PORTA_DANUBE
  23.     // set gpio's for controlling usb power and clock gating
  24. #if 0
  25.     clear_bit (8, DANUBE_GPIO_P0_ALTSEL0);
  26.     clear_bit (8, DANUBE_GPIO_P0_ALTSEL1);
  27.     set_bit (8, DANUBE_GPIO_P0_OD);
  28.     set_bit (8, DANUBE_GPIO_P0_DIR);
  29.     clear_bit (8, DANUBE_GPIO_P0_PUDSEL);
  30.     clear_bit (8, DANUBE_GPIO_P0_PUDEN);
  31.     set_bit (8, DANUBE_GPIO_P0_OUT);
  32. #endif
  33.  
  34. #endif // CONFIG_PORTA_DANUBE
  35.  
  36.     // set clock gating
  37.     // JR: This means:: USB clock source is special internal clock generated from 36 MHz source
  38.     set_bit (4, DANUBE_CGU_IFCCR);
  39.     set_bit (5, DANUBE_CGU_IFCCR);
  40.  
  41.     // set power
  42.     clear_bit (0, DANUBE_PMU_PWDCR);
  43.     clear_bit (6, DANUBE_PMU_PWDCR);
  44.     clear_bit (15, DANUBE_PMU_PWDCR);
  45. }
  46.  
  47. /*}}}*/
  48.  
  49. static int
  50. dwc3884_reset (struct dwc3884_hcd *hcd)
  51. {
  52.     u32 tmp;
  53.     // make the hardware be a host controller (default)
  54.     clear_bit (DANUBE_USBCFG_HDSEL_BIT, DANUBE_RCU_UBSCFG);
  55.  
  56.     // set the HC's byte-order to big-endian
  57.     // TODO: this should probably be set to the CPUs byte-order?!?
  58.     set_bit (DANUBE_USBCFG_HOST_END_BIT, DANUBE_RCU_UBSCFG);
  59.  
  60.     set_bit (1, &hcd->global->rstctl);  // gl reset
  61.     mdelay (10);
  62.     set_bit (0, &hcd->global->rstctl);  // core reset
  63.     mdelay (100);
  64.     tmp = readl (&hcd->global->rstctl);
  65.     if (tmp & 0x3)
  66.         return -ETIMEDOUT;
  67.     return 0;
  68. }
  69.  
  70. static void complete_urbs (unsigned long param);
  71.  
  72. /**
  73.  * usb overcurrent irq
  74.  */
  75. static irqreturn_t
  76. dwc3884_overcurrent_irq (int _irq, void *__hcd, struct pt_regs *_r)
  77. {
  78.     int32_t retval = 0;
  79. #ifdef CONFIG_PORTA_DANUBE
  80.     // JR: FIXME: Do we have to do any actions...
  81.     // Kuepers: Yes, we have to do...fixed
  82.     struct dwc3884_hcd *dwc3884 = __hcd;
  83.  
  84.     // really for us ?
  85.     // ADSL "Get modem ready message" causes this IRQ, too
  86.     if (((*DANUBE_ICU_IM4_ISR) &
  87.          DANUBE_ICU_IM4_ISR_IR (DANUBE_USB_OC_INT - 128)) == 0) {
  88.         warn ("interrupt sharing: not for us");
  89.         dbg ("  intsts=%08x, intena=%08x", *DANUBE_ICU_IM4_ISR,
  90.              *DANUBE_ICU_IM4_IER);
  91.         return IRQ_RETVAL (retval);
  92.     }
  93.     // disable interrupt
  94.     // only call once:
  95.     disable_irq_nosync (DANUBE_USB_OC_INT);
  96.     if (dwc3884->port_oc == 0) {
  97.         err ("USB over current");
  98.         // The USB power is controlled by the application
  99.         // if we switch off the power now, we can't shutdown USB devices safetly
  100.         // so, we only disables the IRQs otherwise the system crashes
  101.         // the IRQ is enabled again when dwc3884->port_oc is set to 0
  102.         // GPIO29  output enables USB_PWR_EN-> switch off USB power
  103.         // Abschalten der 5V-USB-Spg.: Problem muss abhängig von der Konfig. 100|500mA gemacht werden
  104.         #if 0
  105.         *DANUBE_GPIO_P1_DIR     |=  (1<<13);
  106.         *DANUBE_GPIO_P1_ALTSEL0 &= ~(1<<13);
  107.         *DANUBE_GPIO_P1_ALTSEL1 &= ~(1<<13);
  108.         *DANUBE_GPIO_P1_OD      |=  (1<<13);
  109.         if(dwc3884->power_supply == USB_POWER_SUPPLY_100mA)
  110.         {
  111.             *DANUBE_GPIO_P1_OUT     |=  (1<<13);
  112.         }
  113.         else
  114.         {
  115.             *DANUBE_GPIO_P1_OUT     &= ~(1<<13);
  116.         }
  117.         #endif
  118.     }
  119.     else {
  120.         // boeeh... gickguck
  121.     }
  122.     dwc3884->port_oc = 1;
  123.  
  124. #else // CONFIG_PORTA_DANUBE
  125. #include <asm/danube/danube_led.h>
  126.  
  127.     struct led_config_param param = { 0 };
  128.     struct dwc3884_hcd *dwc3884 = __hcd;
  129.  
  130.     dwc3884->port_oc = 1;
  131.  
  132.     param.operation_mask = CONFIG_OPERATION_DATA;
  133.     param.data_mask = 1 << 5;
  134.     //param.data = 1 << 5; // high
  135.     param.data = 0;     // low
  136.     danube_led_config (&param);
  137. #endif // CONFIG_PORTA_DANUBE
  138.  
  139.     //printk("usb over current\n");
  140.     return IRQ_RETVAL (retval);
  141. }
  142.  
  143. /**
  144.  * start - called by the HCD-FW to initialize the
  145.  * driver/hardware at the start (after the call to the hcd_alloc())
  146.  */
  147. static int
  148. start (struct usb_hcd *hcd)
  149. {
  150.     struct dwc3884_hcd *dwc3884 =
  151.         list_entry (hcd, struct dwc3884_hcd, hcd);
  152.     struct usb_device *udev;
  153.     struct usb_bus *bus;
  154.     u32 tmp;
  155.     int status, i;
  156.  
  157.     dwc3884_power_on ();
  158.  
  159.     spin_lock_init (&dwc_hcd->lock);
  160.  
  161.     tasklet_init (&dwc3884->done_tasklet, complete_urbs,
  162.               (unsigned long) dwc3884);
  163.     INIT_LIST_HEAD (&dwc3884->done_urbs);
  164.  
  165.     dwc3884->prev_framenr = -1;
  166.     dwc3884->frame_counter = 0;
  167.  
  168.     dwc3884->port_oc = 0;
  169. #ifdef CONFIG_PORTA_DANUBE 
  170.     // USB power supply 0:100mA:1:500mA
  171.     // USBPowerSupply is a config value from nvram settings
  172.     dwc3884->power_supply = USBPowerSupply;
  173. #endif // CONFIG_PORTA_DANUBE
Advertisement
Add Comment
Please, Sign In to add comment