Subversion Repositories Kolibri OS

Rev

Rev 1605 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #define UHCI_USBLEGSUP          0x00c0  /* legacy support */
  3. #define UHCI_USBLEGSUP_DEFAULT  0x2000  /* only PIRQ enable set */
  4. #define UHCI_USBLEGSUP_RWC      0x8f00  /* the R/WC bits */
  5. #define UHCI_USBLEGSUP_RO       0x5040  /* R/O and reserved bits */
  6.  
  7.  
  8. #define UHCI_USBCMD                  0  /* command register */
  9. #define UHCI_USBINTR                 4  /* interrupt register */
  10. #define UHCI_USBCMD_RUN         0x0001  /* RUN/STOP bit */
  11. #define UHCI_USBCMD_HCRESET     0x0002  /* Host Controller reset */
  12. #define UHCI_USBCMD_EGSM        0x0008  /* Global Suspend Mode */
  13. #define UHCI_USBCMD_CONFIGURE   0x0040  /* Config Flag */
  14. #define UHCI_USBINTR_RESUME     0x0002  /* Resume interrupt enable */
  15.  
  16.  
  17. #define USBCMD                       0
  18. #define  USBCMD_RS              0x0001  /* Run/Stop */
  19. #define  USBCMD_HCRESET         0x0002  /* Host reset */
  20. #define  USBCMD_GRESET          0x0004  /* Global reset */
  21. #define  USBCMD_EGSM            0x0008  /* Global Suspend Mode */
  22. #define  USBCMD_FGR             0x0010  /* Force Global Resume */
  23. #define  USBCMD_SWDBG           0x0020  /* SW Debug mode */
  24. #define  USBCMD_CF              0x0040  /* Config Flag (sw only) */
  25. #define  USBCMD_MAXP            0x0080  /* Max Packet (0 = 32, 1 = 64) */
  26.  
  27. #define  USBSTS                      2
  28. #define   USBSTS_USBINT         0x0001  /* Interrupt due to IOC */
  29. #define   USBSTS_ERROR          0x0002  /* Interrupt due to error */
  30. #define   USBSTS_RD             0x0004  /* Resume Detect */
  31. #define   USBSTS_HSE            0x0008  /* Host System Error: PCI problems */
  32. #define   USBSTS_HCPE           0x0010  /* Host Controller Process Error:
  33.                                          * the schedule is buggy */
  34. #define   USBSTS_HCH            0x0020  /* HC Halted */
  35.  
  36.  
  37. #define  USBFRNUM                    6
  38. #define  USBFLBASEADD                8
  39. #define  USBSOF                     12
  40. #define  USBSOF_DEFAULT             64  /* Frame length is exactly 1 ms */
  41.  
  42. #define  USBPORTSC1                 16
  43. #define  USBPORTSC2                 18
  44.  
  45. #define  UHCI_RH_MAXCHILD            7
  46.  
  47.  
  48. /*
  49.  * Make sure the controller is completely inactive, unable to
  50.  * generate interrupts or do DMA.
  51.  */
  52. void uhci_reset_hc(hc_t *hc)
  53. {
  54.         /* Turn off PIRQ enable and SMI enable.  (This also turns off the
  55.          * BIOS's USB Legacy Support.)  Turn off all the R/WC bits too.
  56.          */
  57.    pciWriteWord(hc->PciTag, UHCI_USBLEGSUP, UHCI_USBLEGSUP_RWC);
  58.  
  59.         /* Reset the HC - this will force us to get a
  60.          * new notification of any already connected
  61.          * ports due to the virtual disconnect that it
  62.          * implies.
  63.          */
  64.    out16(hc->iobase + UHCI_USBCMD, UHCI_USBCMD_HCRESET);
  65.    __asm__ __volatile__ ("":::"memory");
  66.  
  67.    delay(20/10);
  68.  
  69.    if (in16(hc->iobase + UHCI_USBCMD) & UHCI_USBCMD_HCRESET)
  70.        dbgprintf("HCRESET not completed yet!\n");
  71.  
  72.         /* Just to be safe, disable interrupt requests and
  73.          * make sure the controller is stopped.
  74.          */
  75.    out16(hc->iobase + UHCI_USBINTR, 0);
  76.    out16(hc->iobase + UHCI_USBCMD, 0);
  77. };
  78.  
  79. int uhci_check_and_reset_hc(hc_t *hc)
  80. {
  81.    u16_t legsup;
  82.         unsigned int cmd, intr;
  83.  
  84.         /*
  85.          * When restarting a suspended controller, we expect all the
  86.          * settings to be the same as we left them:
  87.          *
  88.          *      PIRQ and SMI disabled, no R/W bits set in USBLEGSUP;
  89.          *      Controller is stopped and configured with EGSM set;
  90.          *      No interrupts enabled except possibly Resume Detect.
  91.          *
  92.          * If any of these conditions are violated we do a complete reset.
  93.          */
  94.    legsup = pciReadWord(hc->PciTag, UHCI_USBLEGSUP);
  95.         if (legsup & ~(UHCI_USBLEGSUP_RO | UHCI_USBLEGSUP_RWC)) {
  96.        dbgprintf("%s: legsup = 0x%04x\n",__FUNCTION__, legsup);
  97.                 goto reset_needed;
  98.         }
  99.  
  100.    cmd = in16(hc->iobase + UHCI_USBCMD);
  101.    if ( (cmd & UHCI_USBCMD_RUN) ||
  102.        !(cmd & UHCI_USBCMD_CONFIGURE) ||
  103.        !(cmd & UHCI_USBCMD_EGSM))
  104.    {
  105.        dbgprintf("%s: cmd = 0x%04x\n", __FUNCTION__, cmd);
  106.                 goto reset_needed;
  107.         }
  108.  
  109.    intr = in16(hc->iobase + UHCI_USBINTR);
  110.    if (intr & (~UHCI_USBINTR_RESUME))
  111.    {
  112.        dbgprintf("%s: intr = 0x%04x\n", __FUNCTION__, intr);
  113.                 goto reset_needed;
  114.         }
  115.         return 0;
  116.  
  117. reset_needed:
  118.    dbgprintf("Performing full reset\n");
  119.    uhci_reset_hc(hc);
  120.         return 1;
  121. }
  122.  
  123. void hc_interrupt()
  124. {
  125.    hc_t   *hc;
  126.  
  127. //    printf("USB interrupt\n");
  128.  
  129.    hc = (hc_t*)hc_list.next;
  130.  
  131.    while( &hc->list != &hc_list)
  132.    {
  133.        hc_t       *htmp;
  134.        request_t  *rq;
  135.        u16_t  status;
  136.  
  137.        htmp = hc;
  138.  
  139.        hc = (hc_t*)hc->list.next;
  140.  
  141.        status = in16(htmp->iobase + USBSTS);
  142.        if (!(status & ~USBSTS_HCH))            /* shared interrupt, not mine */
  143.            continue;
  144.        out16(htmp->iobase + USBSTS, status);     /* Clear it */
  145.  
  146.        rq = (request_t*)htmp->rq_list.next;
  147.  
  148.        while( &rq->list != &htmp->rq_list)
  149.        {
  150.            request_t *rtmp;
  151.            td_t      *td;
  152.  
  153.            rtmp = rq;
  154.            rq = (request_t*)rq->list.next;
  155.  
  156.            td  = rtmp->td_tail;
  157.  
  158.            if( td->status & TD_CTRL_ACTIVE)
  159.                continue;
  160.  
  161.            list_del(&rtmp->list);
  162.  
  163.            RaiseEvent(rtmp->evh, 0, &rtmp->event);
  164.        };
  165.    }
  166. };
  167.  
  168.  
  169.  
  170. bool init_hc(hc_t *hc)
  171. {
  172.    int    port;
  173.    u32_t  ifl;
  174.    u16_t  dev_status;
  175.    td_t   *td;
  176.    int i;
  177.  
  178.    dbgprintf("\n\ninit uhci %x\n\n", hc->pciId);
  179.  
  180.    for(i=0;i<6;i++)
  181.    {
  182.        if(hc->ioBase[i]){
  183.           hc->iobase = hc->ioBase[i];
  184.       //    dbgprintf("Io base_%d 0x%x\n", i,hc->ioBase[i]);
  185.           break;
  186.        };
  187.    };
  188.  
  189.         /* The UHCI spec says devices must have 2 ports, and goes on to say
  190.          * they may have more but gives no way to determine how many there
  191.          * are.  However according to the UHCI spec, Bit 7 of the port
  192.          * status and control register is always set to 1.  So we try to
  193.          * use this to our advantage.  Another common failure mode when
  194.          * a nonexistent register is addressed is to return all ones, so
  195.          * we test for that also.
  196.          */
  197.    for (port = 0; port < 2; port++)
  198.    {
  199.        u32_t status;
  200.  
  201.        status = in16(hc->iobase + USBPORTSC1 + (port * 2));
  202.        dbgprintf("port%d status %x\n", port, status);
  203.        if (!(status & 0x0080) || status == 0xffff)
  204.                         break;
  205.         }
  206.    dbgprintf("detected %d ports\n\n", port);
  207.  
  208.    hc->numports = port;
  209.  
  210.         /* Kick BIOS off this hardware and reset if the controller
  211.          * isn't already safely quiescent.
  212.          */
  213.     uhci_check_and_reset_hc(hc);
  214.  
  215.     hc->frame_base   = (u32_t*)KernelAlloc(4096);
  216.     hc->frame_dma    = GetPgAddr(hc->frame_base);
  217.     hc->frame_number = 0;
  218.  
  219.  
  220.     for (i = 0; i < UHCI_NUM_SKELQH; i++)
  221.     {
  222.     qh_t *qh = alloc_qh();
  223.  
  224.     qh->qlink = 1;
  225.     qh->qelem = 1;
  226.  
  227.         hc->qh[i] = qh;
  228.     }
  229.     for (i = SKEL_ISO + 1; i < SKEL_ASYNC; ++i)
  230.         hc->qh[i]->qlink = hc->qh[SKEL_ASYNC]->dma | 2;
  231.  
  232. /*
  233.     td = alloc_td();
  234.  
  235.     td->link   = 1;
  236.     td->status =  (1<<24) | (1<<23) ;
  237.     td->token  = TOKEN( 0x7FF, DATA0, 0, 0, 0xE1);
  238.     td->buffer = 0;
  239.     td->bk     = NULL;
  240. */
  241.  
  242.     for (i = 0; i < 1024; i++)
  243.     {
  244.         int qnum;
  245.  
  246.         qnum = 8 - (int) __bsf( i | 1024);
  247.  
  248.         if (qnum <= 1)
  249.             qnum = 9;
  250.  
  251.         hc->frame_base[i] = hc->qh[qnum]->dma | 2;
  252.     }
  253.  
  254.     mb();
  255.  
  256.     /* Set the frame length to the default: 1 ms exactly */
  257.     out8(hc->iobase + USBSOF, USBSOF_DEFAULT);
  258.  
  259.         /* Store the frame list base address */
  260.     out32(hc->iobase + USBFLBASEADD, hc->frame_dma);
  261.  
  262.         /* Set the current frame number */
  263.     out16(hc->iobase + USBFRNUM, 0);
  264.  
  265.     out16(hc->iobase + USBSTS, 0x3F);
  266.  
  267.     out16(hc->iobase + UHCI_USBINTR, 4);
  268.  
  269.     AttachIntHandler(hc->irq_line, hc_interrupt, 0);
  270.  
  271.     pciWriteWord(hc->PciTag, UHCI_USBLEGSUP, UHCI_USBLEGSUP_DEFAULT);
  272.  
  273.     out16(hc->iobase + USBCMD, USBCMD_RS | USBCMD_CF |
  274.                                USBCMD_MAXP);
  275.  
  276.     for (port = 0; port < hc->numports; ++port)
  277.         out16(hc->iobase + USBPORTSC1 + (port * 2), 0x200);
  278.     delay(100/10);
  279.  
  280.     for (port = 0; port < 2; ++port)
  281.     {
  282.         time_t timeout;
  283.  
  284.         u32_t status = in16(hc->iobase + USBPORTSC1 + (port * 2));
  285.         dbgprintf("port%d status %x\n", port, status);
  286.  
  287.         out16(hc->iobase + USBPORTSC1 + (port * 2), 0);
  288.  
  289.         timeout = 100/10;
  290.         while(timeout--)
  291.         {
  292.             delay(10/10);
  293.             status = in16(hc->iobase + USBPORTSC1 + (port * 2));
  294.             if(status & 1)
  295.             {
  296.                 udev_t *dev = kmalloc(sizeof(udev_t),0);
  297.  
  298.                 out16(hc->iobase + USBPORTSC1 + (port * 2), 0x0E);
  299.  
  300.                 delay(20/10);
  301.  
  302.                 dbgprintf("enable port\n");
  303.                 status = in16(hc->iobase + USBPORTSC1 + (port * 2));
  304.                 dbgprintf("port%d status %x\n", port, status);
  305.  
  306.                 INIT_LIST_HEAD(&dev->list);
  307.  
  308.                 dev->host     = hc;
  309.                 dev->port     = port;
  310.                 dev->ep0_size = 8;
  311.                 dev->status   = status;
  312.  
  313.                 dbgprintf("port%d connected", port);
  314.                 if(status & 4)
  315.                     dbgprintf(" enabled");
  316.                 else
  317.                     dbgprintf(" disabled");
  318.                 if(status & 0x100){
  319.                     dev->speed = 0x4000000;
  320.                     dbgprintf(" low speed\n");
  321.                 } else {
  322.                     dev->speed = 0;
  323.                     dbgprintf(" full speed\n");
  324.                 };
  325.  
  326.                 if(set_address(dev)) {
  327.                     list_add_tail(&dev->list, &newdev_list);
  328.                     hc->port_map |= 1<<port;
  329.                 }
  330.                 else {
  331.                     free(dev);
  332.                     out16(hc->iobase + USBPORTSC1 + (port * 2), 0);
  333.                 }
  334.                 break;
  335.             };
  336.         };
  337.     };
  338.     return true;
  339. };
  340.  
  341. u16_t __attribute__((aligned(16)))
  342.       req_descr[4]  = {0x0680,0x0100,0x0000,8};
  343.  
  344. /*
  345. IN(69) OUT(E1) SETUP(2D)
  346. SETUP(0) IN(1)
  347. SETUP(0) OUT(1) OUT(0) OUT(1)...IN(1)
  348. SETUP(0) IN(1) IN(0) IN(1)...OUT(0)
  349. */
  350.  
  351.  
  352. bool set_address(udev_t *dev)
  353. {
  354.     static  udev_id   = 0;
  355.     static  udev_addr = 0;
  356.     static  u16_t __attribute__((aligned(16)))
  357.             req_addr[4] = {0x0500,0x0001,0x0000,0x0000};
  358.  
  359.     static  u16_t __attribute__((aligned(16)))
  360.             req_descr[4]  = {0x0680,0x0100,0x0000,8};
  361.  
  362.     static  u32_t   data[2] __attribute__((aligned(16)));
  363.  
  364.     qh_t  *qh;
  365.     td_t  *td0, *td1, *td2;
  366.     u32_t   dev_status;
  367.     count_t timeout;
  368.     int address;
  369.  
  370.     address   = ++udev_addr;
  371.  
  372.     req_addr[1] = address;
  373.  
  374.     if( !ctrl_request(dev, &req_addr, DOUT, NULL, 0))
  375.         return false;
  376.  
  377.     dev->addr = address;
  378.     dev->id   = (++udev_id << 8) | address;
  379.  
  380.     dbgprintf("set address %d\n", address);
  381.  
  382.     data[0] = 0;
  383.     data[1] = 0;
  384.  
  385.     if( !ctrl_request(dev, &req_descr, DIN, data, 8))
  386.         return false;
  387.  
  388.     dev_descr_t *descr = (dev_descr_t*)&data;
  389.     dev->ep0_size = descr->bMaxPacketSize0;
  390.  
  391.     return true;
  392. }
  393.  
  394. request_t *create_request(udev_t *dev, endp_t *enp, u32_t dir,
  395.                           void *data, size_t req_size)
  396. {
  397.     td_t  *td, *td_prev;
  398.     addr_t data_dma;
  399.  
  400.     size_t  packet_size = enp->size;
  401.     size_t  size = req_size;
  402.  
  403.     request_t *rq = (request_t*)kmalloc(sizeof(request_t),0);
  404.  
  405.     INIT_LIST_HEAD(&rq->list);
  406.  
  407.     rq->data = (addr_t)data;
  408.     rq->size = req_size;
  409.     rq->dev  = dev;
  410.  
  411.     if(data)
  412.         data_dma = DMA(data);
  413.  
  414.     td_prev = NULL;
  415.  
  416.     while(size > 0)
  417.     {
  418.         if ( size < packet_size)
  419.         {
  420.             packet_size = size;
  421.         };
  422.  
  423.         td = alloc_td();
  424.         td->link = 1;
  425.  
  426.         if(rq->td_head == NULL)
  427.             rq->td_head = td;
  428.  
  429.         if( td_prev )
  430.             td_prev->link   = td->dma | 4;
  431.         td->status = TD_CTRL_ACTIVE | dev->speed;
  432.         td->token  = TOKEN(packet_size,enp->toggle,enp->address,
  433.                            dev->addr,dir);
  434.         td->buffer = data_dma;
  435.         td->bk     = td_prev;
  436.  
  437.         td_prev = td;
  438.  
  439.         data_dma+= packet_size;
  440.         size-= packet_size;
  441.         enp->toggle ^= DATA1;
  442.     };
  443.  
  444.     td->status |= TD_CTRL_IOC;
  445.     rq->td_tail = td;
  446.  
  447.     rq->evh = CreateEvent(NULL, MANUAL_DESTROY);
  448.  
  449.     if(rq->evh.handle == 0)
  450.         printf("%s: epic fail\n", __FUNCTION__);
  451.  
  452.     rq->event.code    = 0xFF000001;
  453.     rq->event.data[0] = (addr_t)rq;
  454.  
  455.     return rq;
  456. }
  457.  
  458. bool ctrl_request(udev_t *dev, void *req, u32_t pid,
  459.                   void *data, size_t req_size)
  460. {
  461.     size_t  packet_size = dev->ep0_size;
  462.     size_t  size = req_size;
  463.     u32_t   toggle = DATA1;
  464.  
  465.     td_t   *td0, *td, *td_prev;
  466.     qh_t   *qh;
  467.     addr_t  data_dma = 0;
  468.     bool    retval;
  469.  
  470.  
  471.     request_t *rq = (request_t*)kmalloc(sizeof(request_t),0);
  472.  
  473.     INIT_LIST_HEAD(&rq->list);
  474.  
  475.     rq->data = (addr_t)data;
  476.     rq->size = req_size;
  477.     rq->dev  = dev;
  478.  
  479.     td0 = alloc_td();
  480.  
  481.     td0->status = 0x00800000 | dev->speed;
  482.     td0->token  = TOKEN( 8, DATA0, 0, dev->addr, 0x2D);
  483.     td0->buffer = DMA(req);
  484.     td0->bk     = NULL;
  485.  
  486.     if(data)
  487.         data_dma = DMA(data);
  488.  
  489.     td_prev = td0;
  490.  
  491.     while(size > 0)
  492.     {
  493.         if ( size < packet_size)
  494.         {
  495.             packet_size = size;
  496.         };
  497.  
  498.         td = alloc_td();
  499.         td_prev->link   = td->dma | 4;
  500.         td->status = TD_CTRL_ACTIVE | dev->speed;
  501.         td->token  = TOKEN(packet_size, toggle, 0,dev->addr, pid);
  502.         td->buffer = data_dma;
  503.         td->bk     = td_prev;
  504.  
  505.         td_prev = td;
  506.  
  507.         data_dma+= packet_size;
  508.         size-= packet_size;
  509.         toggle ^= DATA1;
  510.     }
  511.  
  512.     td = alloc_td();
  513.     td_prev->link   = td->dma | 4;
  514.  
  515.     pid = (pid == DIN) ? DOUT : DIN;
  516.  
  517.     td->link = 1;
  518.     td->status = TD_CTRL_ACTIVE | TD_CTRL_IOC | dev->speed ;
  519.     td->token  = (0x7FF<<21)|DATA1|(dev->addr<<8)|pid;
  520.     td->buffer = 0;
  521.     td->bk     = td_prev;
  522.  
  523.     rq->td_head = td0;
  524.     rq->td_tail = td;
  525.  
  526.     rq->evh = CreateEvent(NULL, MANUAL_DESTROY);
  527.  
  528.     if(rq->evh.handle == 0)
  529.         printf("%s: epic fail\n", __FUNCTION__);
  530.  
  531.     rq->event.code    = 0xFF000001;
  532.     rq->event.data[0] = (addr_t)rq;
  533.  
  534.     u32_t efl = safe_cli();
  535.  
  536.       list_add_tail(&rq->list, &dev->host->rq_list);
  537.  
  538.     qh = dev->host->qh[SKEL_ASYNC];
  539.  
  540.     qh->qelem = td0->dma;
  541.  
  542.     mb();
  543.  
  544.     safe_sti(efl);
  545.  
  546.     WaitEvent(rq->evh.handle, rq->evh.euid);
  547.  
  548.     dbgprintf("td0 status 0x%0x\n", td0->status);
  549.     dbgprintf("td  status 0x%0x\n", td->status);
  550.  
  551.     if( (td0->status & TD_ANY_ERROR) ||
  552.         (td_prev->status & TD_ANY_ERROR) ||
  553.         (td->status & TD_ANY_ERROR))
  554.     {
  555.         u32_t dev_status = in16(dev->host->iobase + USBSTS);
  556.  
  557.         dbgprintf("\nframe %x, cmd %x status %x\n",
  558.                    in16(dev->host->iobase + USBFRNUM),
  559.                    in16(dev->host->iobase + USBCMD),
  560.                     dev_status);
  561.         dbgprintf("td0 status %x\n",td0->status);
  562.         dbgprintf("td_prev status %x\n",td_prev->status);
  563.         dbgprintf("td status %x\n",td->status);
  564.         dbgprintf("qh %x \n", qh->qelem);
  565.  
  566.         retval = false;
  567.     } else retval = true;
  568.  
  569.     qh->qelem = 1;
  570.  
  571.     mb();
  572.  
  573.     do
  574.     {
  575.         td_prev = td->bk;
  576.         free_td(td);
  577.         td = td_prev;
  578.     }while( td != NULL);
  579.  
  580. /*
  581.     delete event;
  582. */
  583.     kfree(rq);
  584.  
  585.     return retval;
  586. };
  587.  
  588.  
  589. bool init_device(udev_t *dev)
  590. {
  591.     static  u16_t __attribute__((aligned(16)))
  592.             req_descr[4]  = {0x0680,0x0100,0x0000,18};
  593.  
  594.     static  u16_t __attribute__((aligned(16)))
  595.             req_conf[4]  = {0x0680,0x0200,0x0000,9};
  596.  
  597.     static dev_descr_t __attribute__((aligned(16))) descr;
  598.  
  599.     interface_descr_t *interface;
  600.  
  601.     u32_t  data[8];
  602.  
  603.     u8_t *dptr;
  604.     conf_descr_t      *conf;
  605.  
  606.     dbgprintf("\ninit device %x, host %x, port %d\n\n",
  607.                dev->id, dev->host->pciId, dev->port);
  608.  
  609.     if( !ctrl_request(dev, req_descr, DIN, &descr, 18))
  610.     {
  611.         dbgprintf("%s epic fail\n",__FUNCTION__);
  612.         return;
  613.     };
  614.  
  615.     dev->dev_descr = descr;
  616.  
  617.     dbgprintf("device descriptor:\n\n"
  618.               "bLength             %d\n"
  619.               "bDescriptorType     %d\n"
  620.               "bcdUSB              %x\n"
  621.               "bDeviceClass        %x\n"
  622.               "bDeviceSubClass     %x\n"
  623.               "bDeviceProtocol     %x\n"
  624.               "bMaxPacketSize0     %d\n"
  625.               "idVendor            %x\n"
  626.               "idProduct           %x\n"
  627.               "bcdDevice           %x\n"
  628.               "iManufacturer       %x\n"
  629.               "iProduct            %x\n"
  630.               "iSerialNumber       %x\n"
  631.               "bNumConfigurations  %d\n\n",
  632.               descr.bLength, descr.bDescriptorType,
  633.               descr.bcdUSB,  descr.bDeviceClass,
  634.               descr.bDeviceSubClass, descr.bDeviceProtocol,
  635.               descr.bMaxPacketSize0, descr.idVendor,
  636.               descr.idProduct, descr.bcdDevice,
  637.               descr.iManufacturer, descr.iProduct,
  638.               descr.iSerialNumber, descr.bNumConfigurations);
  639.  
  640.     req_conf[3] = 8;
  641.     if( !ctrl_request(dev, req_conf, DIN, &data, 8))
  642.         return;
  643.  
  644.     conf = (conf_descr_t*)&data;
  645.  
  646.     size_t conf_size = conf->wTotalLength;
  647.  
  648.     req_conf[3] = conf_size;
  649.     conf = malloc(conf_size);
  650.  
  651.     if( !ctrl_request(dev, req_conf, DIN, conf, conf_size))
  652.         return;
  653.  
  654.     dptr = (u8_t*)conf;
  655.     dptr+= conf->bLength;
  656.  
  657.     dbgprintf("configuration descriptor\n\n"
  658.               "bLength             %d\n"
  659.               "bDescriptorType     %d\n"
  660.               "wTotalLength        %d\n"
  661.               "bNumInterfaces      %d\n"
  662.               "bConfigurationValue %x\n"
  663.               "iConfiguration      %d\n"
  664.               "bmAttributes        %x\n"
  665.               "bMaxPower           %dmA\n\n",
  666.               conf->bLength,
  667.               conf->bDescriptorType,
  668.               conf->wTotalLength,
  669.               conf->bNumInterfaces,
  670.               conf->bConfigurationValue,
  671.               conf->iConfiguration,
  672.               conf->bmAttributes,
  673.               conf->bMaxPower*2);
  674.  
  675.         interface = (interface_descr_t*)dptr;
  676.  
  677.         switch(interface->bInterfaceClass)
  678.         {
  679.             case USB_CLASS_AUDIO:
  680.                 dbgprintf( "audio device\n");
  681.                 break;
  682.             case USB_CLASS_HID:
  683.                 dev->conf = conf;
  684.                 list_del(&dev->list);
  685.                 return init_hid(dev);
  686.  
  687.             case USB_CLASS_PRINTER:
  688.                 dbgprintf("printer\n");
  689.                 break;
  690.             case USB_CLASS_MASS_STORAGE:
  691.                 dbgprintf("mass storage device\n");
  692.                 break;
  693.             case USB_CLASS_HUB:
  694.                 dbgprintf("hub device\n");
  695.                 break;
  696.             default:
  697.                 dbgprintf("unknown device\n");
  698.         };
  699. };
  700.