Debian Codegraph @

carlfw/include/usb.h

raw symbols SCIP
1 /*
2 * carl9170 firmware - used by the ar9170 wireless device
3 *
4 * USB definitions
5 *
6 * Copyright (c) 2000-2005 ZyDAS Technology Corporation
7 * Copyright (c) 2007-2009 Atheros Communications, Inc.
8 * Copyright 2009 Johannes Berg <[email protected]>
9 * Copyright 2009-2011 Christian Lamparter <[email protected]>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; If not, see <http://www.gnu.org/licenses/>.
23 */
24
25 #ifndef __CARL9170FW_USB_H
26 #define __CARL9170FW_USB_H
27
28 #include "config.h"
29 #include "types.h"
30 #include "io.h"
31 #include "hw.h"
32 #include "ch9.h"
33
34 struct ar9170_usb_config {
35 struct usb_config_descriptor cfg;
36 struct usb_interface_descriptor intf;
37 struct usb_endpoint_descriptor ep[AR9170_USB_NUM_EXTRA_EP];
38 } __packed;
39
40 static inline __inline bool usb_detect_highspeed(void)
41 {
42 return !!(getb(AR9170_USB_REG_MAIN_CTRL) &
43 AR9170_USB_MAIN_CTRL_HIGHSPEED);
44 }
45
46 static inline __inline bool usb_configured(void)
47 {
48 return !!(getb(AR9170_USB_REG_DEVICE_ADDRESS) &
49 AR9170_USB_DEVICE_ADDRESS_CONFIGURE);
50 }
51
52 static inline __inline void usb_enable_remote_wakeup(void)
53 {
54 orb(AR9170_USB_REG_MAIN_CTRL, AR9170_USB_MAIN_CTRL_REMOTE_WAKEUP);
55 }
56
57 static inline __inline void usb_disable_remote_wakeup(void)
58 {
59 andb(AR9170_USB_REG_MAIN_CTRL, ~AR9170_USB_MAIN_CTRL_REMOTE_WAKEUP);
60 }
61
62 static inline __inline void usb_enable_global_int(void)
63 {
64 orb(AR9170_USB_REG_MAIN_CTRL, AR9170_USB_MAIN_CTRL_ENABLE_GLOBAL_INT);
65 }
66
67 static inline __inline void usb_trigger_out(void)
68 {
69 andb(AR9170_USB_REG_INTR_MASK_BYTE_4,
70 (uint8_t) ~AR9170_USB_INTR_DISABLE_OUT_INT);
71 }
72
73 static inline __inline void usb_reset_out(void)
74 {
75 orb(AR9170_USB_REG_INTR_MASK_BYTE_4, AR9170_USB_INTR_DISABLE_OUT_INT);
76 }
77
78 static inline __inline void usb_trigger_in(void)
79 {
80 andb(AR9170_USB_REG_INTR_MASK_BYTE_6, ~AR9170_USB_INTR_DISABLE_IN_INT);
81 }
82
83 static inline __inline void usb_reset_in(void)
84 {
85 orb(AR9170_USB_REG_INTR_MASK_BYTE_6, AR9170_USB_INTR_DISABLE_IN_INT);
86 }
87
88 static inline __inline void usb_ep3_xfer_done(void)
89 {
90 orb(AR9170_USB_REG_EP3_BYTE_COUNT_HIGH, 0x08);
91 }
92
93 static inline __inline void usb_suspend_ack(void)
94 {
95 /*
96 * uP must do-over everything it should handle
97 * and do before into the suspend mode
98 */
99 andb(AR9170_USB_REG_INTR_SOURCE_7, ~BIT(2));
100 }
101
102 static inline __inline void usb_resume_ack(void)
103 {
104 /*
105 * uP must do-over everything it should handle
106 * and do before into the suspend mode
107 */
108
109 andb(AR9170_USB_REG_INTR_SOURCE_7, ~BIT(3));
110 }
111
112 static inline __inline void usb_reset_ack(void)
113 {
114 andb(AR9170_USB_REG_INTR_SOURCE_7, ~BIT(1));
115 }
116
117 static inline __inline void usb_data_out0Byte(void)
118 {
119 andb(AR9170_USB_REG_INTR_SOURCE_7, (uint8_t) ~BIT(7));
120 }
121
122 static inline __inline void usb_data_in0Byte(void)
123 {
124 andb(AR9170_USB_REG_INTR_SOURCE_7, ~BIT(6));
125 }
126
127 static inline __inline void usb_stop_down_queue(void)
128 {
129 andl(AR9170_USB_REG_DMA_CTL, ~AR9170_USB_DMA_CTL_ENABLE_TO_DEVICE);
130 }
131
132 static inline __inline void usb_start_down_queue(void)
133 {
134 orl(AR9170_USB_REG_DMA_CTL, AR9170_USB_DMA_CTL_ENABLE_TO_DEVICE);
135 }
136
137 static inline __inline void usb_clear_input_ep_toggle(unsigned int ep)
138 {
139 andl(AR9170_USB_REG_EP_IN_MAX_SIZE_HIGH + (ep << 1),
140 ~AR9170_USB_EP_IN_TOGGLE);
141 }
142
143 static inline __inline void usb_clear_input_ep_stall(unsigned int ep)
144 {
145 andl(AR9170_USB_REG_EP_IN_MAX_SIZE_HIGH + (ep << 1),
146 ~AR9170_USB_EP_IN_STALL);
147 }
148
149 static inline __inline void usb_set_input_ep_toggle(unsigned int ep)
150 {
151 orl(AR9170_USB_REG_EP_IN_MAX_SIZE_HIGH + (ep << 1),
152 AR9170_USB_EP_IN_TOGGLE);
153 }
154
155 static inline __inline void usb_clear_output_ep_toggle(unsigned int ep)
156 {
157 andl(AR9170_USB_REG_EP_OUT_MAX_SIZE_HIGH + (ep << 1),
158 ~AR9170_USB_EP_OUT_TOGGLE);
159 }
160
161 static inline __inline void usb_set_output_ep_toggle(unsigned int ep)
162 {
163 orl(AR9170_USB_REG_EP_OUT_MAX_SIZE_HIGH + (ep << 1),
164 AR9170_USB_EP_OUT_TOGGLE);
165 }
166
167 static inline __inline void usb_clear_output_ep_stall(unsigned int ep)
168 {
169 andl(AR9170_USB_REG_EP_OUT_MAX_SIZE_HIGH + (ep << 1),
170 ~AR9170_USB_EP_OUT_STALL);
171 }
172
173 static inline void usb_structure_check(void)
174 {
175 BUILD_BUG_ON(sizeof(struct usb_config_descriptor) != USB_DT_CONFIG_SIZE);
176 BUILD_BUG_ON(sizeof(struct usb_device_descriptor) != USB_DT_DEVICE_SIZE);
177 BUILD_BUG_ON(sizeof(struct usb_endpoint_descriptor) != USB_DT_ENDPOINT_SIZE);
178 BUILD_BUG_ON(sizeof(struct usb_interface_descriptor) != USB_DT_INTERFACE_SIZE);
179 }
180
181 void __noreturn jump_to_bootcode(void);
182
183 void send_cmd_to_host(const uint8_t len, const uint8_t type,
184 const uint8_t ext, const uint8_t *body);
185
186 void usb_reset_eps(void);
187 void usb_init(void);
188 void usb_ep0rx(void);
189 void usb_ep0tx(void);
190 void usb_ep0setup(void);
191 void handle_usb(void);
192
193 void usb_timer(void);
194 void usb_putc(const char c);
195 void usb_print_hex_dump(const void *buf, int len);
196
197 void usb_init_highspeed_fifo_cfg(void);
198 void usb_init_fullspeed_fifo_cfg(void);
199
200 void __noreturn start(void);
201 void __noreturn reboot(void);
202
203 #endif /* __CARL9170FW_USB_H */