ohci.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /*
  2. * URB OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5. * (C) Copyright 2000-2001 David Brownell <dbrownell@users.sourceforge.net>
  6. *
  7. * usb-ohci.h
  8. */
  9. /*
  10. * e.g. PCI controllers need this
  11. */
  12. #ifdef CONFIG_SYS_OHCI_SWAP_REG_ACCESS
  13. # define ohci_readl(a) __swap_32(*((volatile u32 *)(a)))
  14. # define ohci_writel(a, b) (*((volatile u32 *)(b)) = __swap_32((volatile u32)a))
  15. #else
  16. # define ohci_readl(a) (*((volatile u32 *)(a)))
  17. # define ohci_writel(a, b) (*((volatile u32 *)(b)) = ((volatile u32)a))
  18. #endif /* CONFIG_SYS_OHCI_SWAP_REG_ACCESS */
  19. #if ARCH_DMA_MINALIGN > 16
  20. #define ED_ALIGNMENT ARCH_DMA_MINALIGN
  21. #else
  22. #define ED_ALIGNMENT 16
  23. #endif
  24. #if defined CONFIG_DM_USB && ARCH_DMA_MINALIGN > 32
  25. #define TD_ALIGNMENT ARCH_DMA_MINALIGN
  26. #else
  27. #define TD_ALIGNMENT 32
  28. #endif
  29. /* functions for doing board or CPU specific setup/cleanup */
  30. int usb_board_stop(void);
  31. int usb_cpu_init(void);
  32. int usb_cpu_stop(void);
  33. int usb_cpu_init_fail(void);
  34. /* ED States */
  35. #define ED_NEW 0x00
  36. #define ED_UNLINK 0x01
  37. #define ED_OPER 0x02
  38. #define ED_DEL 0x04
  39. #define ED_URB_DEL 0x08
  40. /* usb_ohci_ed */
  41. struct ed {
  42. __u32 hwINFO;
  43. __u32 hwTailP;
  44. __u32 hwHeadP;
  45. __u32 hwNextED;
  46. struct ed *ed_prev;
  47. __u8 int_period;
  48. __u8 int_branch;
  49. __u8 int_load;
  50. __u8 int_interval;
  51. __u8 state;
  52. __u8 type;
  53. __u16 last_iso;
  54. struct ed *ed_rm_list;
  55. struct usb_device *usb_dev;
  56. void *purb;
  57. __u32 unused[2];
  58. } __attribute__((aligned(ED_ALIGNMENT)));
  59. typedef struct ed ed_t;
  60. /* TD info field */
  61. #define TD_CC 0xf0000000
  62. #define TD_CC_GET(td_p) ((td_p >>28) & 0x0f)
  63. #define TD_CC_SET(td_p, cc) (td_p) = ((td_p) & 0x0fffffff) | (((cc) & 0x0f) << 28)
  64. #define TD_EC 0x0C000000
  65. #define TD_T 0x03000000
  66. #define TD_T_DATA0 0x02000000
  67. #define TD_T_DATA1 0x03000000
  68. #define TD_T_TOGGLE 0x00000000
  69. #define TD_R 0x00040000
  70. #define TD_DI 0x00E00000
  71. #define TD_DI_SET(X) (((X) & 0x07)<< 21)
  72. #define TD_DP 0x00180000
  73. #define TD_DP_SETUP 0x00000000
  74. #define TD_DP_IN 0x00100000
  75. #define TD_DP_OUT 0x00080000
  76. #define TD_ISO 0x00010000
  77. #define TD_DEL 0x00020000
  78. /* CC Codes */
  79. #define TD_CC_NOERROR 0x00
  80. #define TD_CC_CRC 0x01
  81. #define TD_CC_BITSTUFFING 0x02
  82. #define TD_CC_DATATOGGLEM 0x03
  83. #define TD_CC_STALL 0x04
  84. #define TD_DEVNOTRESP 0x05
  85. #define TD_PIDCHECKFAIL 0x06
  86. #define TD_UNEXPECTEDPID 0x07
  87. #define TD_DATAOVERRUN 0x08
  88. #define TD_DATAUNDERRUN 0x09
  89. #define TD_BUFFEROVERRUN 0x0C
  90. #define TD_BUFFERUNDERRUN 0x0D
  91. #define TD_NOTACCESSED 0x0F
  92. #define MAXPSW 1
  93. struct td {
  94. __u32 hwINFO;
  95. __u32 hwCBP; /* Current Buffer Pointer */
  96. __u32 hwNextTD; /* Next TD Pointer */
  97. __u32 hwBE; /* Memory Buffer End Pointer */
  98. /* #ifndef CONFIG_MPC5200 /\* this seems wrong *\/ */
  99. __u16 hwPSW[MAXPSW];
  100. /* #endif */
  101. __u8 unused;
  102. __u8 index;
  103. struct ed *ed;
  104. struct td *next_dl_td;
  105. struct usb_device *usb_dev;
  106. int transfer_len;
  107. __u32 data;
  108. __u32 unused2[2];
  109. } __attribute__((aligned(TD_ALIGNMENT)));
  110. typedef struct td td_t;
  111. #define OHCI_ED_SKIP (1 << 14)
  112. /*
  113. * The HCCA (Host Controller Communications Area) is a 256 byte
  114. * structure defined in the OHCI spec. that the host controller is
  115. * told the base address of. It must be 256-byte aligned.
  116. */
  117. #define NUM_INTS 32 /* part of the OHCI standard */
  118. struct ohci_hcca {
  119. __u32 int_table[NUM_INTS]; /* Interrupt ED table */
  120. #if defined(CONFIG_MPC5200)
  121. __u16 pad1; /* set to 0 on each frame_no change */
  122. __u16 frame_no; /* current frame number */
  123. #else
  124. __u16 frame_no; /* current frame number */
  125. __u16 pad1; /* set to 0 on each frame_no change */
  126. #endif
  127. __u32 done_head; /* info returned for an interrupt */
  128. u8 reserved_for_hc[116];
  129. } __attribute__((aligned(256)));
  130. /*
  131. * Maximum number of root hub ports.
  132. */
  133. #ifndef CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS
  134. # error "CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS undefined!"
  135. #endif
  136. /*
  137. * This is the structure of the OHCI controller's memory mapped I/O
  138. * region. This is Memory Mapped I/O. You must use the ohci_readl() and
  139. * ohci_writel() macros defined in this file to access these!!
  140. */
  141. struct ohci_regs {
  142. /* control and status registers */
  143. __u32 revision;
  144. __u32 control;
  145. __u32 cmdstatus;
  146. __u32 intrstatus;
  147. __u32 intrenable;
  148. __u32 intrdisable;
  149. /* memory pointers */
  150. __u32 hcca;
  151. __u32 ed_periodcurrent;
  152. __u32 ed_controlhead;
  153. __u32 ed_controlcurrent;
  154. __u32 ed_bulkhead;
  155. __u32 ed_bulkcurrent;
  156. __u32 donehead;
  157. /* frame counters */
  158. __u32 fminterval;
  159. __u32 fmremaining;
  160. __u32 fmnumber;
  161. __u32 periodicstart;
  162. __u32 lsthresh;
  163. /* Root hub ports */
  164. struct ohci_roothub_regs {
  165. __u32 a;
  166. __u32 b;
  167. __u32 status;
  168. __u32 portstatus[CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS];
  169. } roothub;
  170. } __attribute__((aligned(32)));
  171. /* Some EHCI controls */
  172. #define EHCI_USBCMD_OFF 0x20
  173. #define EHCI_USBCMD_HCRESET (1 << 1)
  174. /* OHCI CONTROL AND STATUS REGISTER MASKS */
  175. /*
  176. * HcControl (control) register masks
  177. */
  178. #define OHCI_CTRL_CBSR (3 << 0) /* control/bulk service ratio */
  179. #define OHCI_CTRL_PLE (1 << 2) /* periodic list enable */
  180. #define OHCI_CTRL_IE (1 << 3) /* isochronous enable */
  181. #define OHCI_CTRL_CLE (1 << 4) /* control list enable */
  182. #define OHCI_CTRL_BLE (1 << 5) /* bulk list enable */
  183. #define OHCI_CTRL_HCFS (3 << 6) /* host controller functional state */
  184. #define OHCI_CTRL_IR (1 << 8) /* interrupt routing */
  185. #define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */
  186. #define OHCI_CTRL_RWE (1 << 10) /* remote wakeup enable */
  187. /* pre-shifted values for HCFS */
  188. # define OHCI_USB_RESET (0 << 6)
  189. # define OHCI_USB_RESUME (1 << 6)
  190. # define OHCI_USB_OPER (2 << 6)
  191. # define OHCI_USB_SUSPEND (3 << 6)
  192. /*
  193. * HcCommandStatus (cmdstatus) register masks
  194. */
  195. #define OHCI_HCR (1 << 0) /* host controller reset */
  196. #define OHCI_CLF (1 << 1) /* control list filled */
  197. #define OHCI_BLF (1 << 2) /* bulk list filled */
  198. #define OHCI_OCR (1 << 3) /* ownership change request */
  199. #define OHCI_SOC (3 << 16) /* scheduling overrun count */
  200. /*
  201. * masks used with interrupt registers:
  202. * HcInterruptStatus (intrstatus)
  203. * HcInterruptEnable (intrenable)
  204. * HcInterruptDisable (intrdisable)
  205. */
  206. #define OHCI_INTR_SO (1 << 0) /* scheduling overrun */
  207. #define OHCI_INTR_WDH (1 << 1) /* writeback of done_head */
  208. #define OHCI_INTR_SF (1 << 2) /* start frame */
  209. #define OHCI_INTR_RD (1 << 3) /* resume detect */
  210. #define OHCI_INTR_UE (1 << 4) /* unrecoverable error */
  211. #define OHCI_INTR_FNO (1 << 5) /* frame number overflow */
  212. #define OHCI_INTR_RHSC (1 << 6) /* root hub status change */
  213. #define OHCI_INTR_OC (1 << 30) /* ownership change */
  214. #define OHCI_INTR_MIE (1 << 31) /* master interrupt enable */
  215. /* Virtual Root HUB */
  216. struct virt_root_hub {
  217. int devnum; /* Address of Root Hub endpoint */
  218. void *dev; /* was urb */
  219. void *int_addr;
  220. int send;
  221. int interval;
  222. };
  223. /* USB HUB CONSTANTS (not OHCI-specific; see hub.h) */
  224. /* destination of request */
  225. #define RH_INTERFACE 0x01
  226. #define RH_ENDPOINT 0x02
  227. #define RH_OTHER 0x03
  228. #define RH_CLASS 0x20
  229. #define RH_VENDOR 0x40
  230. /* Requests: bRequest << 8 | bmRequestType */
  231. #define RH_GET_STATUS 0x0080
  232. #define RH_CLEAR_FEATURE 0x0100
  233. #define RH_SET_FEATURE 0x0300
  234. #define RH_SET_ADDRESS 0x0500
  235. #define RH_GET_DESCRIPTOR 0x0680
  236. #define RH_SET_DESCRIPTOR 0x0700
  237. #define RH_GET_CONFIGURATION 0x0880
  238. #define RH_SET_CONFIGURATION 0x0900
  239. #define RH_GET_STATE 0x0280
  240. #define RH_GET_INTERFACE 0x0A80
  241. #define RH_SET_INTERFACE 0x0B00
  242. #define RH_SYNC_FRAME 0x0C80
  243. /* Our Vendor Specific Request */
  244. #define RH_SET_EP 0x2000
  245. /* Hub port features */
  246. #define RH_PORT_CONNECTION 0x00
  247. #define RH_PORT_ENABLE 0x01
  248. #define RH_PORT_SUSPEND 0x02
  249. #define RH_PORT_OVER_CURRENT 0x03
  250. #define RH_PORT_RESET 0x04
  251. #define RH_PORT_POWER 0x08
  252. #define RH_PORT_LOW_SPEED 0x09
  253. #define RH_C_PORT_CONNECTION 0x10
  254. #define RH_C_PORT_ENABLE 0x11
  255. #define RH_C_PORT_SUSPEND 0x12
  256. #define RH_C_PORT_OVER_CURRENT 0x13
  257. #define RH_C_PORT_RESET 0x14
  258. /* Hub features */
  259. #define RH_C_HUB_LOCAL_POWER 0x00
  260. #define RH_C_HUB_OVER_CURRENT 0x01
  261. #define RH_DEVICE_REMOTE_WAKEUP 0x00
  262. #define RH_ENDPOINT_STALL 0x01
  263. #define RH_ACK 0x01
  264. #define RH_REQ_ERR -1
  265. #define RH_NACK 0x00
  266. /* OHCI ROOT HUB REGISTER MASKS */
  267. /* roothub.portstatus [i] bits */
  268. #define RH_PS_CCS 0x00000001 /* current connect status */
  269. #define RH_PS_PES 0x00000002 /* port enable status*/
  270. #define RH_PS_PSS 0x00000004 /* port suspend status */
  271. #define RH_PS_POCI 0x00000008 /* port over current indicator */
  272. #define RH_PS_PRS 0x00000010 /* port reset status */
  273. #define RH_PS_PPS 0x00000100 /* port power status */
  274. #define RH_PS_LSDA 0x00000200 /* low speed device attached */
  275. #define RH_PS_CSC 0x00010000 /* connect status change */
  276. #define RH_PS_PESC 0x00020000 /* port enable status change */
  277. #define RH_PS_PSSC 0x00040000 /* port suspend status change */
  278. #define RH_PS_OCIC 0x00080000 /* over current indicator change */
  279. #define RH_PS_PRSC 0x00100000 /* port reset status change */
  280. /* roothub.status bits */
  281. #define RH_HS_LPS 0x00000001 /* local power status */
  282. #define RH_HS_OCI 0x00000002 /* over current indicator */
  283. #define RH_HS_DRWE 0x00008000 /* device remote wakeup enable */
  284. #define RH_HS_LPSC 0x00010000 /* local power status change */
  285. #define RH_HS_OCIC 0x00020000 /* over current indicator change */
  286. #define RH_HS_CRWE 0x80000000 /* clear remote wakeup enable */
  287. /* roothub.b masks */
  288. #define RH_B_DR 0x0000ffff /* device removable flags */
  289. #define RH_B_PPCM 0xffff0000 /* port power control mask */
  290. /* roothub.a masks */
  291. #define RH_A_NDP (0xff << 0) /* number of downstream ports */
  292. #define RH_A_PSM (1 << 8) /* power switching mode */
  293. #define RH_A_NPS (1 << 9) /* no power switching */
  294. #define RH_A_DT (1 << 10) /* device type (mbz) */
  295. #define RH_A_OCPM (1 << 11) /* over current protection mode */
  296. #define RH_A_NOCP (1 << 12) /* no over current protection */
  297. #define RH_A_POTPGT (0xff << 24) /* power on to power good time */
  298. /* urb */
  299. #define N_URB_TD 48
  300. typedef struct
  301. {
  302. ed_t *ed;
  303. __u16 length; /* number of tds associated with this request */
  304. __u16 td_cnt; /* number of tds already serviced */
  305. struct usb_device *dev;
  306. int state;
  307. unsigned long pipe;
  308. void *transfer_buffer;
  309. int transfer_buffer_length;
  310. int interval;
  311. int actual_length;
  312. int finished;
  313. td_t *td[N_URB_TD]; /* list pointer to all corresponding TDs associated with this request */
  314. } urb_priv_t;
  315. #define URB_DEL 1
  316. #define NUM_EDS 8 /* num of preallocated endpoint descriptors */
  317. #define NUM_TD 64 /* we need more TDs than EDs */
  318. #define NUM_INT_DEVS 8 /* num of ohci_dev structs for int endpoints */
  319. typedef struct ohci_device {
  320. ed_t ed[NUM_EDS] __aligned(ED_ALIGNMENT);
  321. td_t tds[NUM_TD] __aligned(TD_ALIGNMENT);
  322. int ed_cnt;
  323. int devnum;
  324. } ohci_dev_t;
  325. /*
  326. * This is the full ohci controller description
  327. *
  328. * Note how the "proper" USB information is just
  329. * a subset of what the full implementation needs. (Linus)
  330. */
  331. typedef struct ohci {
  332. /* this allocates EDs for all possible endpoints */
  333. struct ohci_device ohci_dev __aligned(TD_ALIGNMENT);
  334. struct ohci_device int_dev[NUM_INT_DEVS] __aligned(TD_ALIGNMENT);
  335. struct ohci_hcca *hcca; /* hcca */
  336. /*dma_addr_t hcca_dma;*/
  337. int irq;
  338. int disabled; /* e.g. got a UE, we're hung */
  339. int sleeping;
  340. unsigned long flags; /* for HC bugs */
  341. struct ohci_regs *regs; /* OHCI controller's memory */
  342. int ohci_int_load[32]; /* load of the 32 Interrupt Chains (for load balancing)*/
  343. ed_t *ed_rm_list[2]; /* lists of all endpoints to be removed */
  344. ed_t *ed_bulktail; /* last endpoint of bulk list */
  345. ed_t *ed_controltail; /* last endpoint of control list */
  346. int intrstatus;
  347. __u32 hc_control; /* copy of the hc control reg */
  348. struct usb_device *dev[32];
  349. struct virt_root_hub rh;
  350. const char *slot_name;
  351. } ohci_t;
  352. #ifdef CONFIG_DM_USB
  353. extern struct dm_usb_ops ohci_usb_ops;
  354. int ohci_register(struct udevice *dev, struct ohci_regs *regs);
  355. int ohci_deregister(struct udevice *dev);
  356. #endif