Dynamically allocate USB controller structures.
[seabios.git] / src / usb-ohci.h
1 #ifndef __USB_OHCI_H
2 #define __USB_OHCI_H
3
4 // usb-ohci.c
5 void ohci_init(u16 bdf, int busid);
6 struct usb_pipe;
7 void ohci_free_pipe(struct usb_pipe *p);
8 struct usb_pipe *ohci_alloc_control_pipe(struct usb_pipe *dummy);
9 int ohci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize
10                  , void *data, int datasize);
11 struct usb_pipe *ohci_alloc_intr_pipe(struct usb_pipe *dummy, int frameexp);
12 int ohci_poll_intr(struct usb_pipe *p, void *data);
13
14
15 /****************************************************************
16  * ohci structs and flags
17  ****************************************************************/
18
19 struct ohci_ed {
20     u32 hwINFO;
21     u32 hwTailP;
22     u32 hwHeadP;
23     u32 hwNextED;
24 } PACKED;
25
26 #define ED_ISO          (1 << 15)
27 #define ED_SKIP         (1 << 14)
28 #define ED_LOWSPEED     (1 << 13)
29 #define ED_OUT          (0x01 << 11)
30 #define ED_IN           (0x02 << 11)
31
32 #define ED_C            (0x02)
33 #define ED_H            (0x01)
34
35 struct ohci_td {
36     u32 hwINFO;
37     u32 hwCBP;
38     u32 hwNextTD;
39     u32 hwBE;
40 } PACKED;
41
42 #define TD_CC       0xf0000000
43 #define TD_CC_GET(td_p) ((td_p >>28) & 0x0f)
44 #define TD_DI       0x00E00000
45
46 #define TD_DONE     0x00020000
47 #define TD_ISO      0x00010000
48
49 #define TD_EC       0x0C000000
50 #define TD_T        0x03000000
51 #define TD_T_DATA0  0x02000000
52 #define TD_T_DATA1  0x03000000
53 #define TD_T_TOGGLE 0x00000000
54 #define TD_DP       0x00180000
55 #define TD_DP_SETUP 0x00000000
56 #define TD_DP_IN    0x00100000
57 #define TD_DP_OUT   0x00080000
58
59 #define TD_R        0x00040000
60
61 struct ohci_hcca {
62     u32  int_table[32];
63     u32  frame_no;
64     u32  done_head;
65     u8   reserved[120];
66 } PACKED;
67
68 struct ohci_regs {
69     u32  revision;
70     u32  control;
71     u32  cmdstatus;
72     u32  intrstatus;
73     u32  intrenable;
74     u32  intrdisable;
75
76     u32  hcca;
77     u32  ed_periodcurrent;
78     u32  ed_controlhead;
79     u32  ed_controlcurrent;
80     u32  ed_bulkhead;
81     u32  ed_bulkcurrent;
82     u32  donehead;
83
84     u32  fminterval;
85     u32  fmremaining;
86     u32  fmnumber;
87     u32  periodicstart;
88     u32  lsthresh;
89
90     u32  roothub_a;
91     u32  roothub_b;
92     u32  roothub_status;
93     u32  roothub_portstatus[15];
94 } PACKED;
95
96 #define OHCI_CTRL_CBSR  (3 << 0)
97 #define OHCI_CTRL_PLE   (1 << 2)
98 #define OHCI_CTRL_CLE   (1 << 4)
99 #define OHCI_CTRL_BLE   (1 << 5)
100 #define OHCI_CTRL_HCFS  (3 << 6)
101 #       define OHCI_USB_RESET   (0 << 6)
102 #       define OHCI_USB_OPER    (2 << 6)
103 #define OHCI_CTRL_RWC   (1 << 9)
104
105 #define OHCI_HCR        (1 << 0)
106 #define OHCI_CLF        (1 << 1)
107
108 #define OHCI_INTR_MIE   (1 << 31)
109
110 #define RH_PS_CCS            0x00000001
111 #define RH_PS_PES            0x00000002
112 #define RH_PS_PSS            0x00000004
113 #define RH_PS_POCI           0x00000008
114 #define RH_PS_PRS            0x00000010
115 #define RH_PS_PPS            0x00000100
116 #define RH_PS_LSDA           0x00000200
117 #define RH_PS_CSC            0x00010000
118 #define RH_PS_PESC           0x00020000
119 #define RH_PS_PSSC           0x00040000
120 #define RH_PS_OCIC           0x00080000
121 #define RH_PS_PRSC           0x00100000
122
123 #define RH_HS_LPS            0x00000001
124 #define RH_HS_OCI            0x00000002
125 #define RH_HS_DRWE           0x00008000
126 #define RH_HS_LPSC           0x00010000
127 #define RH_HS_OCIC           0x00020000
128 #define RH_HS_CRWE           0x80000000
129
130 #define RH_B_DR         0x0000ffff
131 #define RH_B_PPCM       0xffff0000
132
133 #define RH_A_NDP        (0xff << 0)
134 #define RH_A_PSM        (1 << 8)
135 #define RH_A_NPS        (1 << 9)
136 #define RH_A_DT         (1 << 10)
137 #define RH_A_OCPM       (1 << 11)
138 #define RH_A_NOCP       (1 << 12)
139 #define RH_A_POTPGT     (0xff << 24)
140
141 #endif // usb-ohci.h