Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1 | /* |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 2 | Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com> |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 3 | <http://rt2x00.serialmonkey.com> |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
Jeff Kirsher | a05b8c5 | 2013-12-06 03:32:11 -0800 | [diff] [blame] | 16 | along with this program; if not, see <http://www.gnu.org/licenses/>. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | /* |
| 20 | Module: rt2x00usb |
| 21 | Abstract: Data structures for the rt2x00usb module. |
| 22 | */ |
| 23 | |
| 24 | #ifndef RT2X00USB_H |
| 25 | #define RT2X00USB_H |
| 26 | |
Gertjan van Wingerde | ac9d1a7 | 2009-11-09 23:38:35 +0100 | [diff] [blame] | 27 | #include <linux/usb.h> |
| 28 | |
Ivo van Doorn | c1d35df | 2008-06-16 19:57:11 +0200 | [diff] [blame] | 29 | #define to_usb_device_intf(d) \ |
| 30 | ({ \ |
| 31 | struct usb_interface *intf = to_usb_interface(d); \ |
| 32 | interface_to_usbdev(intf); \ |
| 33 | }) |
| 34 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 35 | /* |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 36 | * For USB vendor requests we need to pass a timeout |
| 37 | * time in ms, for this we use the REGISTER_TIMEOUT, |
| 38 | * however when loading firmware a higher value is |
| 39 | * required. In that case we use the REGISTER_TIMEOUT_FIRMWARE. |
| 40 | */ |
Ivo van Doorn | e913655 | 2007-09-25 20:54:20 +0200 | [diff] [blame] | 41 | #define REGISTER_TIMEOUT 500 |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 42 | #define REGISTER_TIMEOUT_FIRMWARE 1000 |
| 43 | |
Ivo van Doorn | bd394a7 | 2008-04-21 19:01:58 +0200 | [diff] [blame] | 44 | /** |
| 45 | * REGISTER_TIMEOUT16 - Determine the timeout for 16bit register access |
| 46 | * @__datalen: Data length |
| 47 | */ |
| 48 | #define REGISTER_TIMEOUT16(__datalen) \ |
| 49 | ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u16)) ) |
| 50 | |
| 51 | /** |
| 52 | * REGISTER_TIMEOUT32 - Determine the timeout for 32bit register access |
| 53 | * @__datalen: Data length |
| 54 | */ |
| 55 | #define REGISTER_TIMEOUT32(__datalen) \ |
| 56 | ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u32)) ) |
| 57 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 58 | /* |
| 59 | * Cache size |
| 60 | */ |
Iwo Mergler | ed0dbee | 2008-07-19 16:16:54 +0200 | [diff] [blame] | 61 | #define CSR_CACHE_SIZE 64 |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 62 | |
| 63 | /* |
| 64 | * USB request types. |
| 65 | */ |
| 66 | #define USB_VENDOR_REQUEST ( USB_TYPE_VENDOR | USB_RECIP_DEVICE ) |
| 67 | #define USB_VENDOR_REQUEST_IN ( USB_DIR_IN | USB_VENDOR_REQUEST ) |
| 68 | #define USB_VENDOR_REQUEST_OUT ( USB_DIR_OUT | USB_VENDOR_REQUEST ) |
| 69 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 70 | /** |
| 71 | * enum rt2x00usb_vendor_request: USB vendor commands. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 72 | */ |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 73 | enum rt2x00usb_vendor_request { |
| 74 | USB_DEVICE_MODE = 1, |
| 75 | USB_SINGLE_WRITE = 2, |
| 76 | USB_SINGLE_READ = 3, |
| 77 | USB_MULTI_WRITE = 6, |
| 78 | USB_MULTI_READ = 7, |
| 79 | USB_EEPROM_WRITE = 8, |
| 80 | USB_EEPROM_READ = 9, |
| 81 | USB_LED_CONTROL = 10, /* RT73USB */ |
| 82 | USB_RX_CONTROL = 12, |
| 83 | }; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 84 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 85 | /** |
| 86 | * enum rt2x00usb_mode_offset: Device modes offset. |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 87 | */ |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 88 | enum rt2x00usb_mode_offset { |
| 89 | USB_MODE_RESET = 1, |
| 90 | USB_MODE_UNPLUG = 2, |
| 91 | USB_MODE_FUNCTION = 3, |
| 92 | USB_MODE_TEST = 4, |
| 93 | USB_MODE_SLEEP = 7, /* RT73USB */ |
| 94 | USB_MODE_FIRMWARE = 8, /* RT73USB */ |
| 95 | USB_MODE_WAKEUP = 9, /* RT73USB */ |
| 96 | }; |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 97 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 98 | /** |
| 99 | * rt2x00usb_vendor_request - Send register command to device |
| 100 | * @rt2x00dev: Pointer to &struct rt2x00_dev |
| 101 | * @request: USB vendor command (See &enum rt2x00usb_vendor_request) |
| 102 | * @requesttype: Request type &USB_VENDOR_REQUEST_* |
| 103 | * @offset: Register offset to perform action on |
| 104 | * @value: Value to write to device |
| 105 | * @buffer: Buffer where information will be read/written to by device |
| 106 | * @buffer_length: Size of &buffer |
| 107 | * @timeout: Operation timeout |
| 108 | * |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 109 | * This is the main function to communicate with the device, |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 110 | * the &buffer argument _must_ either be NULL or point to |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 111 | * a buffer allocated by kmalloc. Failure to do so can lead |
| 112 | * to unexpected behavior depending on the architecture. |
| 113 | */ |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 114 | int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 115 | const u8 request, const u8 requesttype, |
| 116 | const u16 offset, const u16 value, |
| 117 | void *buffer, const u16 buffer_length, |
Ivo van Doorn | e913655 | 2007-09-25 20:54:20 +0200 | [diff] [blame] | 118 | const int timeout); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 119 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 120 | /** |
| 121 | * rt2x00usb_vendor_request_buff - Send register command to device (buffered) |
| 122 | * @rt2x00dev: Pointer to &struct rt2x00_dev |
| 123 | * @request: USB vendor command (See &enum rt2x00usb_vendor_request) |
| 124 | * @requesttype: Request type &USB_VENDOR_REQUEST_* |
| 125 | * @offset: Register offset to perform action on |
| 126 | * @buffer: Buffer where information will be read/written to by device |
| 127 | * @buffer_length: Size of &buffer |
| 128 | * @timeout: Operation timeout |
| 129 | * |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 130 | * This function will use a previously with kmalloc allocated cache |
| 131 | * to communicate with the device. The contents of the buffer pointer |
| 132 | * will be copied to this cache when writing, or read from the cache |
| 133 | * when reading. |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 134 | * Buffers send to &rt2x00usb_vendor_request _must_ be allocated with |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 135 | * kmalloc. Hence the reason for using a previously allocated cache |
| 136 | * which has been allocated properly. |
| 137 | */ |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 138 | int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 139 | const u8 request, const u8 requesttype, |
| 140 | const u16 offset, void *buffer, |
Ivo van Doorn | e913655 | 2007-09-25 20:54:20 +0200 | [diff] [blame] | 141 | const u16 buffer_length, const int timeout); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 142 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 143 | /** |
| 144 | * rt2x00usb_vendor_request_buff - Send register command to device (buffered) |
| 145 | * @rt2x00dev: Pointer to &struct rt2x00_dev |
| 146 | * @request: USB vendor command (See &enum rt2x00usb_vendor_request) |
| 147 | * @requesttype: Request type &USB_VENDOR_REQUEST_* |
| 148 | * @offset: Register offset to perform action on |
| 149 | * @buffer: Buffer where information will be read/written to by device |
| 150 | * @buffer_length: Size of &buffer |
| 151 | * @timeout: Operation timeout |
| 152 | * |
| 153 | * A version of &rt2x00usb_vendor_request_buff which must be called |
| 154 | * if the usb_cache_mutex is already held. |
| 155 | */ |
Adam Baker | 3d82346 | 2007-10-27 13:43:29 +0200 | [diff] [blame] | 156 | int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev *rt2x00dev, |
| 157 | const u8 request, const u8 requesttype, |
| 158 | const u16 offset, void *buffer, |
| 159 | const u16 buffer_length, const int timeout); |
| 160 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 161 | /** |
| 162 | * rt2x00usb_vendor_request_sw - Send single register command to device |
| 163 | * @rt2x00dev: Pointer to &struct rt2x00_dev |
| 164 | * @request: USB vendor command (See &enum rt2x00usb_vendor_request) |
| 165 | * @offset: Register offset to perform action on |
| 166 | * @value: Value to write to device |
| 167 | * @timeout: Operation timeout |
| 168 | * |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 169 | * Simple wrapper around rt2x00usb_vendor_request to write a single |
| 170 | * command to the device. Since we don't use the buffer argument we |
| 171 | * don't have to worry about kmalloc here. |
| 172 | */ |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 173 | static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 174 | const u8 request, |
| 175 | const u16 offset, |
| 176 | const u16 value, |
Ivo van Doorn | e913655 | 2007-09-25 20:54:20 +0200 | [diff] [blame] | 177 | const int timeout) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 178 | { |
| 179 | return rt2x00usb_vendor_request(rt2x00dev, request, |
| 180 | USB_VENDOR_REQUEST_OUT, offset, |
| 181 | value, NULL, 0, timeout); |
| 182 | } |
| 183 | |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 184 | /** |
| 185 | * rt2x00usb_eeprom_read - Read eeprom from device |
| 186 | * @rt2x00dev: Pointer to &struct rt2x00_dev |
| 187 | * @eeprom: Pointer to eeprom array to store the information in |
| 188 | * @length: Number of bytes to read from the eeprom |
| 189 | * |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 190 | * Simple wrapper around rt2x00usb_vendor_request to read the eeprom |
| 191 | * from the device. Note that the eeprom argument _must_ be allocated using |
| 192 | * kmalloc for correct handling inside the kernel USB layer. |
| 193 | */ |
Adam Baker | 0e14f6d | 2007-10-27 13:41:25 +0200 | [diff] [blame] | 194 | static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | 9a46d44 | 2008-04-21 19:02:17 +0200 | [diff] [blame] | 195 | __le16 *eeprom, const u16 length) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 196 | { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 197 | return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ, |
Ivo van Doorn | 3b640f2 | 2008-02-03 15:54:11 +0100 | [diff] [blame] | 198 | USB_VENDOR_REQUEST_IN, 0, 0, |
Ivo van Doorn | 9a46d44 | 2008-04-21 19:02:17 +0200 | [diff] [blame] | 199 | eeprom, length, |
| 200 | REGISTER_TIMEOUT16(length)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Ivo van Doorn | 0f829b1 | 2008-11-10 19:42:18 +0100 | [diff] [blame] | 203 | /** |
Bartlomiej Zolnierkiewicz | 02a39c2 | 2009-11-04 18:32:50 +0100 | [diff] [blame] | 204 | * rt2x00usb_register_read - Read 32bit register word |
Ivo van Doorn | 0f829b1 | 2008-11-10 19:42:18 +0100 | [diff] [blame] | 205 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. |
| 206 | * @offset: Register offset |
| 207 | * @value: Pointer to where register contents should be stored |
| 208 | * |
| 209 | * This function is a simple wrapper for 32bit register access |
| 210 | * through rt2x00usb_vendor_request_buff(). |
| 211 | */ |
| 212 | static inline void rt2x00usb_register_read(struct rt2x00_dev *rt2x00dev, |
| 213 | const unsigned int offset, |
| 214 | u32 *value) |
| 215 | { |
| 216 | __le32 reg; |
| 217 | rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ, |
| 218 | USB_VENDOR_REQUEST_IN, offset, |
| 219 | ®, sizeof(reg), REGISTER_TIMEOUT); |
| 220 | *value = le32_to_cpu(reg); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * rt2x00usb_register_read_lock - Read 32bit register word |
| 225 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. |
| 226 | * @offset: Register offset |
| 227 | * @value: Pointer to where register contents should be stored |
| 228 | * |
| 229 | * This function is a simple wrapper for 32bit register access |
| 230 | * through rt2x00usb_vendor_req_buff_lock(). |
| 231 | */ |
| 232 | static inline void rt2x00usb_register_read_lock(struct rt2x00_dev *rt2x00dev, |
| 233 | const unsigned int offset, |
| 234 | u32 *value) |
| 235 | { |
| 236 | __le32 reg; |
| 237 | rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_READ, |
| 238 | USB_VENDOR_REQUEST_IN, offset, |
| 239 | ®, sizeof(reg), REGISTER_TIMEOUT); |
| 240 | *value = le32_to_cpu(reg); |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * rt2x00usb_register_multiread - Read 32bit register words |
| 245 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. |
| 246 | * @offset: Register offset |
| 247 | * @value: Pointer to where register contents should be stored |
| 248 | * @length: Length of the data |
| 249 | * |
| 250 | * This function is a simple wrapper for 32bit register access |
| 251 | * through rt2x00usb_vendor_request_buff(). |
| 252 | */ |
| 253 | static inline void rt2x00usb_register_multiread(struct rt2x00_dev *rt2x00dev, |
| 254 | const unsigned int offset, |
| 255 | void *value, const u32 length) |
| 256 | { |
| 257 | rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ, |
| 258 | USB_VENDOR_REQUEST_IN, offset, |
| 259 | value, length, |
| 260 | REGISTER_TIMEOUT32(length)); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * rt2x00usb_register_write - Write 32bit register word |
| 265 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. |
| 266 | * @offset: Register offset |
| 267 | * @value: Data which should be written |
| 268 | * |
| 269 | * This function is a simple wrapper for 32bit register access |
| 270 | * through rt2x00usb_vendor_request_buff(). |
| 271 | */ |
| 272 | static inline void rt2x00usb_register_write(struct rt2x00_dev *rt2x00dev, |
| 273 | const unsigned int offset, |
| 274 | u32 value) |
| 275 | { |
| 276 | __le32 reg = cpu_to_le32(value); |
| 277 | rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE, |
| 278 | USB_VENDOR_REQUEST_OUT, offset, |
| 279 | ®, sizeof(reg), REGISTER_TIMEOUT); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * rt2x00usb_register_write_lock - Write 32bit register word |
| 284 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. |
| 285 | * @offset: Register offset |
| 286 | * @value: Data which should be written |
| 287 | * |
| 288 | * This function is a simple wrapper for 32bit register access |
| 289 | * through rt2x00usb_vendor_req_buff_lock(). |
| 290 | */ |
| 291 | static inline void rt2x00usb_register_write_lock(struct rt2x00_dev *rt2x00dev, |
| 292 | const unsigned int offset, |
| 293 | u32 value) |
| 294 | { |
| 295 | __le32 reg = cpu_to_le32(value); |
| 296 | rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_WRITE, |
| 297 | USB_VENDOR_REQUEST_OUT, offset, |
| 298 | ®, sizeof(reg), REGISTER_TIMEOUT); |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * rt2x00usb_register_multiwrite - Write 32bit register words |
| 303 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. |
| 304 | * @offset: Register offset |
| 305 | * @value: Data which should be written |
| 306 | * @length: Length of the data |
| 307 | * |
| 308 | * This function is a simple wrapper for 32bit register access |
| 309 | * through rt2x00usb_vendor_request_buff(). |
| 310 | */ |
| 311 | static inline void rt2x00usb_register_multiwrite(struct rt2x00_dev *rt2x00dev, |
Bartlomiej Zolnierkiewicz | 5b10b09 | 2009-11-04 18:35:10 +0100 | [diff] [blame] | 312 | const unsigned int offset, |
| 313 | const void *value, |
| 314 | const u32 length) |
Ivo van Doorn | 0f829b1 | 2008-11-10 19:42:18 +0100 | [diff] [blame] | 315 | { |
| 316 | rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE, |
| 317 | USB_VENDOR_REQUEST_OUT, offset, |
Bartlomiej Zolnierkiewicz | 5b10b09 | 2009-11-04 18:35:10 +0100 | [diff] [blame] | 318 | (void *)value, length, |
Ivo van Doorn | 0f829b1 | 2008-11-10 19:42:18 +0100 | [diff] [blame] | 319 | REGISTER_TIMEOUT32(length)); |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * rt2x00usb_regbusy_read - Read from register with busy check |
| 324 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. |
| 325 | * @offset: Register offset |
| 326 | * @field: Field to check if register is busy |
| 327 | * @reg: Pointer to where register contents should be stored |
| 328 | * |
| 329 | * This function will read the given register, and checks if the |
| 330 | * register is busy. If it is, it will sleep for a couple of |
| 331 | * microseconds before reading the register again. If the register |
| 332 | * is not read after a certain timeout, this function will return |
| 333 | * FALSE. |
| 334 | */ |
| 335 | int rt2x00usb_regbusy_read(struct rt2x00_dev *rt2x00dev, |
| 336 | const unsigned int offset, |
Bartlomiej Zolnierkiewicz | f255b92 | 2009-11-04 18:35:18 +0100 | [diff] [blame] | 337 | const struct rt2x00_field32 field, |
Ivo van Doorn | 0f829b1 | 2008-11-10 19:42:18 +0100 | [diff] [blame] | 338 | u32 *reg); |
| 339 | |
Johannes Stezenbach | 0e0d39e | 2011-04-18 15:29:12 +0200 | [diff] [blame] | 340 | /** |
| 341 | * rt2x00usb_register_read_async - Asynchronously read 32bit register word |
| 342 | * @rt2x00dev: Device pointer, see &struct rt2x00_dev. |
| 343 | * @offset: Register offset |
| 344 | * @callback: Functon to call when read completes. |
| 345 | * |
| 346 | * Submit a control URB to read a 32bit register. This safe to |
| 347 | * be called from atomic context. The callback will be called |
| 348 | * when the URB completes. Otherwise the function is similar |
| 349 | * to rt2x00usb_register_read(). |
Ivo van Doorn | a073fde | 2011-04-30 17:14:23 +0200 | [diff] [blame] | 350 | * When the callback function returns false, the memory will be cleaned up, |
| 351 | * when it returns true, the urb will be fired again. |
Johannes Stezenbach | 0e0d39e | 2011-04-18 15:29:12 +0200 | [diff] [blame] | 352 | */ |
| 353 | void rt2x00usb_register_read_async(struct rt2x00_dev *rt2x00dev, |
| 354 | const unsigned int offset, |
Ivo van Doorn | a073fde | 2011-04-30 17:14:23 +0200 | [diff] [blame] | 355 | bool (*callback)(struct rt2x00_dev*, int, u32)); |
Johannes Stezenbach | 0e0d39e | 2011-04-18 15:29:12 +0200 | [diff] [blame] | 356 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 357 | /* |
| 358 | * Radio handlers |
| 359 | */ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 360 | void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev); |
| 361 | |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 362 | /** |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 363 | * struct queue_entry_priv_usb: Per entry USB specific information |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 364 | * |
| 365 | * @urb: Urb structure used for device communication. |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 366 | */ |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 367 | struct queue_entry_priv_usb { |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 368 | struct urb *urb; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 369 | }; |
| 370 | |
| 371 | /** |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 372 | * struct queue_entry_priv_usb_bcn: Per TX entry USB specific information |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 373 | * |
Ivo van Doorn | b8be63f | 2008-05-10 13:46:03 +0200 | [diff] [blame] | 374 | * The first section should match &struct queue_entry_priv_usb exactly. |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 375 | * rt2500usb can use this structure to send a guardian byte when working |
| 376 | * with beacons. |
| 377 | * |
| 378 | * @urb: Urb structure used for device communication. |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 379 | * @guardian_data: Set to 0, used for sending the guardian data. |
| 380 | * @guardian_urb: Urb structure used to send the guardian data. |
| 381 | */ |
| 382 | struct queue_entry_priv_usb_bcn { |
| 383 | struct urb *urb; |
| 384 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 385 | unsigned int guardian_data; |
| 386 | struct urb *guardian_urb; |
| 387 | }; |
| 388 | |
Ivo van Doorn | f019d51 | 2008-06-06 22:47:39 +0200 | [diff] [blame] | 389 | /** |
Ivo van Doorn | dbba306 | 2010-12-13 12:34:54 +0100 | [diff] [blame] | 390 | * rt2x00usb_kick_queue - Kick data queue |
Ivo van Doorn | 9333145 | 2010-08-23 19:53:39 +0200 | [diff] [blame] | 391 | * @queue: Data queue to kick |
Ivo van Doorn | f019d51 | 2008-06-06 22:47:39 +0200 | [diff] [blame] | 392 | * |
| 393 | * This will walk through all entries of the queue and push all pending |
| 394 | * frames to the hardware as a single burst. |
| 395 | */ |
Ivo van Doorn | dbba306 | 2010-12-13 12:34:54 +0100 | [diff] [blame] | 396 | void rt2x00usb_kick_queue(struct data_queue *queue); |
Ivo van Doorn | f019d51 | 2008-06-06 22:47:39 +0200 | [diff] [blame] | 397 | |
Ivo van Doorn | a2c9b65 | 2009-01-28 00:32:33 +0100 | [diff] [blame] | 398 | /** |
Ivo van Doorn | 5be6560 | 2010-12-13 12:35:40 +0100 | [diff] [blame] | 399 | * rt2x00usb_flush_queue - Flush data queue |
Ivo van Doorn | 5450b7e | 2010-12-13 12:34:22 +0100 | [diff] [blame] | 400 | * @queue: Data queue to stop |
Ivo van Doorn | 152a599 | 2011-04-18 15:31:02 +0200 | [diff] [blame] | 401 | * @drop: True to drop all pending frames. |
Ivo van Doorn | a2c9b65 | 2009-01-28 00:32:33 +0100 | [diff] [blame] | 402 | * |
Ivo van Doorn | 152a599 | 2011-04-18 15:31:02 +0200 | [diff] [blame] | 403 | * This will walk through all entries of the queue and will optionally |
| 404 | * kill all URB's which were send to the device, or at least wait until |
| 405 | * they have been returned from the device.. |
Ivo van Doorn | a2c9b65 | 2009-01-28 00:32:33 +0100 | [diff] [blame] | 406 | */ |
Ivo van Doorn | 152a599 | 2011-04-18 15:31:02 +0200 | [diff] [blame] | 407 | void rt2x00usb_flush_queue(struct data_queue *queue, bool drop); |
Ivo van Doorn | a2c9b65 | 2009-01-28 00:32:33 +0100 | [diff] [blame] | 408 | |
Ivo van Doorn | c965c74 | 2010-07-11 12:25:46 +0200 | [diff] [blame] | 409 | /** |
| 410 | * rt2x00usb_watchdog - Watchdog for USB communication |
| 411 | * @rt2x00dev: Pointer to &struct rt2x00_dev |
| 412 | * |
| 413 | * Check the health of the USB communication and determine |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 414 | * if timeouts have occurred. If this is the case, this function |
Ivo van Doorn | c965c74 | 2010-07-11 12:25:46 +0200 | [diff] [blame] | 415 | * will reset all communication to restore functionality again. |
| 416 | */ |
| 417 | void rt2x00usb_watchdog(struct rt2x00_dev *rt2x00dev); |
| 418 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 419 | /* |
| 420 | * Device initialization handlers. |
| 421 | */ |
Ivo van Doorn | 798b7ad | 2008-11-08 15:25:33 +0100 | [diff] [blame] | 422 | void rt2x00usb_clear_entry(struct queue_entry *entry); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 423 | int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev); |
| 424 | void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev); |
| 425 | |
| 426 | /* |
| 427 | * USB driver handlers. |
| 428 | */ |
| 429 | int rt2x00usb_probe(struct usb_interface *usb_intf, |
Gertjan van Wingerde | e01ae27 | 2011-04-18 15:32:13 +0200 | [diff] [blame] | 430 | const struct rt2x00_ops *ops); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 431 | void rt2x00usb_disconnect(struct usb_interface *usb_intf); |
| 432 | #ifdef CONFIG_PM |
| 433 | int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state); |
| 434 | int rt2x00usb_resume(struct usb_interface *usb_intf); |
| 435 | #else |
| 436 | #define rt2x00usb_suspend NULL |
| 437 | #define rt2x00usb_resume NULL |
| 438 | #endif /* CONFIG_PM */ |
| 439 | |
| 440 | #endif /* RT2X00USB_H */ |