usbd.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. typedef struct Hub Hub;
  2. typedef struct Port Port;
  3. typedef struct DHub DHub;
  4. typedef struct Devtab Devtab;
  5. typedef struct Usbfs Usbfs;
  6. enum
  7. {
  8. Stack = 32*1024,
  9. Dhub = 0x29, /* hub descriptor type */
  10. Dhublen = 9, /* hub descriptor length */
  11. /* hub class feature selectors */
  12. Fhublocalpower = 0,
  13. Fhubovercurrent = 1,
  14. Fportconnection = 0,
  15. Fportenable = 1,
  16. Fportsuspend = 2,
  17. Fportovercurrent = 3,
  18. Fportreset = 4,
  19. Fportpower = 8,
  20. Fportlowspeed = 9,
  21. Fcportconnection = 16,
  22. Fcportenable = 17,
  23. Fcportsuspend = 18,
  24. Fcportovercurrent= 19,
  25. Fcportreset = 20,
  26. Fportindicator = 22,
  27. /* Port status and status change bits
  28. * Constants at /sys/src/9/pc/usb.h starting with HP-
  29. * must have the same values or root hubs won't work.
  30. */
  31. PSpresent = 0x0001,
  32. PSenable = 0x0002,
  33. PSsuspend = 0x0004,
  34. PSovercurrent = 0x0008,
  35. PSreset = 0x0010,
  36. PSpower = 0x0100,
  37. PSslow = 0x0200,
  38. PShigh = 0x0400,
  39. PSstatuschg = 0x10000, /* PSpresent changed */
  40. PSchange = 0x20000, /* PSenable changed */
  41. /* port/device state */
  42. Pdisabled = 0, /* must be 0 */
  43. Pattached,
  44. Pconfiged,
  45. /* Delays, timeouts (ms) */
  46. Spawndelay = 1000, /* how often may we re-spawn a driver */
  47. Connectdelay = 1000, /* how much to wait after a connect */
  48. Resetdelay = 20, /* how much to wait after a reset */
  49. Enabledelay = 20, /* how much to wait after an enable */
  50. Powerdelay = 100, /* after powering up ports */
  51. Pollms = 250, /* port poll interval */
  52. Chgdelay = 100, /* waiting for port become stable */
  53. Chgtmout = 1000, /* ...but at most this much */
  54. /*
  55. * device tab for embedded usb drivers.
  56. */
  57. DCL = 0x01000000, /* csp identifies just class */
  58. DSC = 0x02000000, /* csp identifies just subclass */
  59. DPT = 0x04000000, /* csp identifies just proto */
  60. };
  61. struct Hub
  62. {
  63. uchar pwrmode;
  64. uchar compound;
  65. uchar pwrms; /* time to wait in ms */
  66. uchar maxcurrent; /* after powering port*/
  67. int leds; /* has port indicators? */
  68. int maxpkt;
  69. uchar nport;
  70. Port *port;
  71. int failed; /* I/O error while enumerating */
  72. int isroot; /* set if root hub */
  73. Dev *dev; /* for this hub */
  74. Hub *next; /* in list of hubs */
  75. };
  76. struct Port
  77. {
  78. int state; /* state of the device */
  79. int sts; /* old port status */
  80. uchar removable;
  81. uchar pwrctl;
  82. Dev *dev; /* attached device (if non-nil) */
  83. Hub *hub; /* non-nil if hub attached */
  84. };
  85. /* USB HUB descriptor */
  86. struct DHub
  87. {
  88. uchar bLength;
  89. uchar bDescriptorType;
  90. uchar bNbrPorts;
  91. uchar wHubCharacteristics[2];
  92. uchar bPwrOn2PwrGood;
  93. uchar bHubContrCurrent;
  94. uchar DeviceRemovable[1]; /* variable length */
  95. };
  96. struct Devtab
  97. {
  98. char *name;
  99. int (*init)(Dev*, int, char**); /* nil if external */
  100. int csps[4];
  101. int vid;
  102. int did;
  103. char *args;
  104. };
  105. Hub* newhub(char *fn, Dev *d);
  106. int startdev(Port *pp);
  107. void threadmain(int argc, char **argv);
  108. extern Usbfs usbdfsops;