Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rt2x00usb.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004 - 2009 Ivo van Doorn <[email protected]>
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
16  along with this program; if not, write to the
17  Free Software Foundation, Inc.,
18  59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20 
21 /*
22  Module: rt2x00usb
23  Abstract: Data structures for the rt2x00usb module.
24  */
25 
26 #ifndef RT2X00USB_H
27 #define RT2X00USB_H
28 
29 #include <linux/usb.h>
30 
31 #define to_usb_device_intf(d) \
32 ({ \
33  struct usb_interface *intf = to_usb_interface(d); \
34  interface_to_usbdev(intf); \
35 })
36 
37 /*
38  * For USB vendor requests we need to pass a timeout
39  * time in ms, for this we use the REGISTER_TIMEOUT,
40  * however when loading firmware a higher value is
41  * required. In that case we use the REGISTER_TIMEOUT_FIRMWARE.
42  */
43 #define REGISTER_TIMEOUT 500
44 #define REGISTER_TIMEOUT_FIRMWARE 1000
45 
50 #define REGISTER_TIMEOUT16(__datalen) \
51  ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u16)) )
52 
57 #define REGISTER_TIMEOUT32(__datalen) \
58  ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u32)) )
59 
60 /*
61  * Cache size
62  */
63 #define CSR_CACHE_SIZE 64
64 
65 /*
66  * USB request types.
67  */
68 #define USB_VENDOR_REQUEST ( USB_TYPE_VENDOR | USB_RECIP_DEVICE )
69 #define USB_VENDOR_REQUEST_IN ( USB_DIR_IN | USB_VENDOR_REQUEST )
70 #define USB_VENDOR_REQUEST_OUT ( USB_DIR_OUT | USB_VENDOR_REQUEST )
71 
83  USB_LED_CONTROL = 10, /* RT73USB */
85 };
86 
95  USB_MODE_SLEEP = 7, /* RT73USB */
96  USB_MODE_FIRMWARE = 8, /* RT73USB */
97  USB_MODE_WAKEUP = 9, /* RT73USB */
98 };
99 
116 int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
117  const u8 request, const u8 requesttype,
118  const u16 offset, const u16 value,
119  void *buffer, const u16 buffer_length,
120  const int timeout);
121 
140 int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
141  const u8 request, const u8 requesttype,
142  const u16 offset, void *buffer,
143  const u16 buffer_length, const int timeout);
144 
158 int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev *rt2x00dev,
159  const u8 request, const u8 requesttype,
160  const u16 offset, void *buffer,
161  const u16 buffer_length, const int timeout);
162 
175 static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
176  const u8 request,
177  const u16 offset,
178  const u16 value,
179  const int timeout)
180 {
181  return rt2x00usb_vendor_request(rt2x00dev, request,
182  USB_VENDOR_REQUEST_OUT, offset,
183  value, NULL, 0, timeout);
184 }
185 
196 static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
197  __le16 *eeprom, const u16 length)
198 {
199  return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
200  USB_VENDOR_REQUEST_IN, 0, 0,
201  eeprom, length,
202  REGISTER_TIMEOUT16(length));
203 }
204 
214 static inline void rt2x00usb_register_read(struct rt2x00_dev *rt2x00dev,
215  const unsigned int offset,
216  u32 *value)
217 {
218  __le32 reg;
220  USB_VENDOR_REQUEST_IN, offset,
221  &reg, sizeof(reg), REGISTER_TIMEOUT);
222  *value = le32_to_cpu(reg);
223 }
224 
234 static inline void rt2x00usb_register_read_lock(struct rt2x00_dev *rt2x00dev,
235  const unsigned int offset,
236  u32 *value)
237 {
238  __le32 reg;
240  USB_VENDOR_REQUEST_IN, offset,
241  &reg, sizeof(reg), REGISTER_TIMEOUT);
242  *value = le32_to_cpu(reg);
243 }
244 
255 static inline void rt2x00usb_register_multiread(struct rt2x00_dev *rt2x00dev,
256  const unsigned int offset,
257  void *value, const u32 length)
258 {
260  USB_VENDOR_REQUEST_IN, offset,
261  value, length,
262  REGISTER_TIMEOUT32(length));
263 }
264 
274 static inline void rt2x00usb_register_write(struct rt2x00_dev *rt2x00dev,
275  const unsigned int offset,
276  u32 value)
277 {
278  __le32 reg = cpu_to_le32(value);
280  USB_VENDOR_REQUEST_OUT, offset,
281  &reg, sizeof(reg), REGISTER_TIMEOUT);
282 }
283 
293 static inline void rt2x00usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
294  const unsigned int offset,
295  u32 value)
296 {
297  __le32 reg = cpu_to_le32(value);
299  USB_VENDOR_REQUEST_OUT, offset,
300  &reg, sizeof(reg), REGISTER_TIMEOUT);
301 }
302 
313 static inline void rt2x00usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
314  const unsigned int offset,
315  const void *value,
316  const u32 length)
317 {
319  USB_VENDOR_REQUEST_OUT, offset,
320  (void *)value, length,
321  REGISTER_TIMEOUT32(length));
322 }
323 
337 int rt2x00usb_regbusy_read(struct rt2x00_dev *rt2x00dev,
338  const unsigned int offset,
339  const struct rt2x00_field32 field,
340  u32 *reg);
341 
355 void rt2x00usb_register_read_async(struct rt2x00_dev *rt2x00dev,
356  const unsigned int offset,
357  bool (*callback)(struct rt2x00_dev*, int, u32));
358 
359 /*
360  * Radio handlers
361  */
362 void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
363 
370  struct urb *urb;
371 };
372 
385  struct urb *urb;
386 
387  unsigned int guardian_data;
388  struct urb *guardian_urb;
389 };
390 
399 
409 void rt2x00usb_flush_queue(struct data_queue *queue, bool drop);
410 
419 void rt2x00usb_watchdog(struct rt2x00_dev *rt2x00dev);
420 
421 /*
422  * Device initialization handlers.
423  */
424 void rt2x00usb_clear_entry(struct queue_entry *entry);
425 int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
426 void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
427 
428 /*
429  * USB driver handlers.
430  */
431 int rt2x00usb_probe(struct usb_interface *usb_intf,
432  const struct rt2x00_ops *ops);
433 void rt2x00usb_disconnect(struct usb_interface *usb_intf);
434 #ifdef CONFIG_PM
435 int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
436 int rt2x00usb_resume(struct usb_interface *usb_intf);
437 #else
438 #define rt2x00usb_suspend NULL
439 #define rt2x00usb_resume NULL
440 #endif /* CONFIG_PM */
441 
442 #endif /* RT2X00USB_H */