2 * carl9170 firmware - used by the ar9170 wireless device
6 * Copyright (c) 2000-2005 ZyDAS Technology Corporation
7 * Copyright (c) 2007-2009 Atheros Communications, Inc.
8 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
9 * Copyright 2009, 2010 Christian Lamparter <chunkeey@googlemail.com>
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.
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.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #ifndef __CARL9170FW_USB_H
27 #define __CARL9170FW_USB_H
35 struct ar9170_usb_config {
36 struct usb_config_descriptor cfg;
37 struct usb_interface_descriptor intf;
38 struct usb_endpoint_descriptor ep[AR9170_USB_NUM_EXTRA_EP];
41 static inline __inline bool usb_detect_highspeed(void)
43 return !!(getb(AR9170_USB_REG_MAIN_CTRL) &
44 AR9170_USB_MAIN_CTRL_HIGHSPEED);
47 static inline __inline bool usb_configured(void)
49 return !!(getb(AR9170_USB_REG_DEVICE_ADDRESS) &
50 AR9170_USB_DEVICE_ADDRESS_CONFIGURE);
53 static inline __inline void usb_remote_wakeup(void)
55 orb(AR9170_USB_REG_MAIN_CTRL, AR9170_USB_MAIN_CTRL_REMOTE_WAKEUP);
58 static inline __inline void usb_enable_global_int(void)
60 orb(AR9170_USB_REG_MAIN_CTRL, AR9170_USB_MAIN_CTRL_ENABLE_GLOBAL_INT);
63 static inline __inline void usb_trigger_out(void)
65 andb(AR9170_USB_REG_INTR_MASK_BYTE_4,
66 (uint8_t) ~AR9170_USB_INTR_DISABLE_OUT_INT);
69 static inline __inline void usb_reset_out(void)
71 orb(AR9170_USB_REG_INTR_MASK_BYTE_4, AR9170_USB_INTR_DISABLE_OUT_INT);
74 static inline __inline void usb_trigger_in(void)
76 andb(AR9170_USB_REG_INTR_MASK_BYTE_6, ~AR9170_USB_INTR_DISABLE_IN_INT);
79 static inline __inline void usb_reset_in(void)
81 orb(AR9170_USB_REG_INTR_MASK_BYTE_6, AR9170_USB_INTR_DISABLE_IN_INT);
84 static inline __inline void usb_ep3_xfer_done(void)
86 orb(AR9170_USB_REG_EP3_BYTE_COUNT_HIGH, 0x08);
89 static inline __inline void usb_suspend_ack(void)
92 * uP must do-over everything it should handle
93 * and do before into the suspend mode
95 andb(AR9170_USB_REG_INTR_SOURCE_7, ~BIT(2));
98 static inline __inline void usb_resume_ack(void)
101 * uP must do-over everything it should handle
102 * and do before into the suspend mode
105 andb(AR9170_USB_REG_INTR_SOURCE_7, ~BIT(3));
108 static inline __inline void usb_reset_ack(void)
110 andb(AR9170_USB_REG_INTR_SOURCE_7, ~BIT(1));
113 static inline __inline void usb_data_out0Byte(void)
115 andb(AR9170_USB_REG_INTR_SOURCE_7, (uint8_t) ~BIT(7));
118 static inline __inline void usb_data_in0Byte(void)
120 andb(AR9170_USB_REG_INTR_SOURCE_7, ~BIT(6));
123 static inline __inline void usb_stop_down_queue(void)
125 andl(AR9170_USB_REG_DMA_CTL, ~AR9170_USB_DMA_CTL_ENABLE_TO_DEVICE);
128 static inline __inline void usb_start_down_queue(void)
130 orl(AR9170_USB_REG_DMA_CTL, AR9170_USB_DMA_CTL_ENABLE_TO_DEVICE);
133 static inline __inline void usb_clear_input_ep_toggle(unsigned int ep)
135 andl(AR9170_USB_REG_EP_IN_MAX_SIZE_HIGH + (ep << 1),
136 ~AR9170_USB_EP_IN_TOGGLE);
139 static inline __inline void usb_set_input_ep_toggle(unsigned int ep)
141 orl(AR9170_USB_REG_EP_IN_MAX_SIZE_HIGH + (ep << 1),
142 AR9170_USB_EP_IN_TOGGLE);
145 static inline __inline void usb_clear_output_ep_toggle(unsigned int ep)
147 andl(AR9170_USB_REG_EP_OUT_MAX_SIZE_HIGH + (ep << 1),
148 ~AR9170_USB_EP_OUT_TOGGLE);
151 static inline __inline void usb_set_output_ep_toggle(unsigned int ep)
153 orl(AR9170_USB_REG_EP_OUT_MAX_SIZE_HIGH + (ep << 1),
154 AR9170_USB_EP_OUT_TOGGLE);
157 static inline void usb_structure_check(void)
159 BUILD_BUG_ON(sizeof(struct usb_config_descriptor) != USB_DT_CONFIG_SIZE);
160 BUILD_BUG_ON(sizeof(struct usb_device_descriptor) != USB_DT_DEVICE_SIZE);
161 BUILD_BUG_ON(sizeof(struct usb_endpoint_descriptor) != USB_DT_ENDPOINT_SIZE);
162 BUILD_BUG_ON(sizeof(struct usb_interface_descriptor) != USB_DT_INTERFACE_SIZE);
165 void __noreturn jump_to_bootcode(void);
167 void send_cmd_to_host(const uint8_t len, const uint8_t type,
168 const uint8_t ext, const uint8_t *body);
171 void usb_ep0rx(void);
172 void usb_ep0tx(void);
173 void usb_ep0setup(void);
174 void handle_usb(void);
176 void usb_timer(void);
177 void usb_putc(const char c);
178 void usb_print_hex_dump(const void *buf, int len);
180 void usb_init_highspeed_fifo_cfg(void);
181 void usb_init_fullspeed_fifo_cfg(void);
183 void __noreturn start(void);
184 void __noreturn reboot(void);
186 #endif /* __CARL9170FW_USB_H */