usbd.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. Spawndelay = 250, /* how often may we re-spawn a driver */
  48. // Connectdelay = 1000, /* how much to wait after a connect */
  49. Connectdelay = 500, /* how much to wait after a connect */
  50. Resetdelay = 20, /* how much to wait after a reset */
  51. Enabledelay = 20, /* how much to wait after an enable */
  52. Powerdelay = 100, /* after powering up ports */
  53. Pollms = 250, /* port poll interval */
  54. Chgdelay = 100, /* waiting for port become stable */
  55. Chgtmout = 1000, /* ...but at most this much */
  56. /*
  57. * device tab for embedded usb drivers.
  58. */
  59. DCL = 0x01000000, /* csp identifies just class */
  60. DSC = 0x02000000, /* csp identifies just subclass */
  61. DPT = 0x04000000, /* csp identifies just proto */
  62. };
  63. struct Hub
  64. {
  65. uchar pwrmode;
  66. uchar compound;
  67. uchar pwrms; /* time to wait in ms */
  68. uchar maxcurrent; /* after powering port*/
  69. int leds; /* has port indicators? */
  70. int maxpkt;
  71. uchar nport;
  72. Port *port;
  73. int failed; /* I/O error while enumerating */
  74. int isroot; /* set if root hub */
  75. Dev *dev; /* for this hub */
  76. Hub *next; /* in list of hubs */
  77. };
  78. struct Port
  79. {
  80. int state; /* state of the device */
  81. int sts; /* old port status */
  82. uchar removable;
  83. uchar pwrctl;
  84. Dev *dev; /* attached device (if non-nil) */
  85. Hub *hub; /* non-nil if hub attached */
  86. int devnb; /* device number */
  87. uvlong *devmaskp; /* ptr to dev mask */
  88. };
  89. /* USB HUB descriptor */
  90. struct DHub
  91. {
  92. uchar bLength;
  93. uchar bDescriptorType;
  94. uchar bNbrPorts;
  95. uchar wHubCharacteristics[2];
  96. uchar bPwrOn2PwrGood;
  97. uchar bHubContrCurrent;
  98. uchar DeviceRemovable[1]; /* variable length */
  99. };
  100. struct Devtab
  101. {
  102. char *name;
  103. int (*init)(Dev*, int, char**); /* nil if external */
  104. int csps[4];
  105. int vid;
  106. int did;
  107. char *args;
  108. uvlong devmask;
  109. int noauto;
  110. };
  111. Hub* newhub(char *fn, Dev *d);
  112. int startdev(Port *pp);
  113. int getdevnb(uvlong *maskp);
  114. void putdevnb(uvlong *maskp, int nb);
  115. void threadmain(int argc, char **argv);
  116. extern Usbfs usbdfsops;