rt2x00usb.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2x00usb
  19. Abstract: Data structures for the rt2x00usb module.
  20. */
  21. #ifndef RT2X00USB_H
  22. #define RT2X00USB_H
  23. /*
  24. * This variable should be used with the
  25. * usb_driver structure initialization.
  26. */
  27. #define USB_DEVICE_DATA(__ops) .driver_info = (kernel_ulong_t)(__ops)
  28. /*
  29. * Register defines.
  30. * Some registers require multiple attempts before success,
  31. * in those cases REGISTER_BUSY_COUNT attempts should be
  32. * taken with a REGISTER_BUSY_DELAY interval.
  33. * For USB vendor requests we need to pass a timeout
  34. * time in ms, for this we use the REGISTER_TIMEOUT,
  35. * however when loading firmware a higher value is
  36. * required. In that case we use the REGISTER_TIMEOUT_FIRMWARE.
  37. */
  38. #define REGISTER_BUSY_COUNT 5
  39. #define REGISTER_BUSY_DELAY 100
  40. #define REGISTER_TIMEOUT 500
  41. #define REGISTER_TIMEOUT_FIRMWARE 1000
  42. /*
  43. * Cache size
  44. */
  45. #define CSR_CACHE_SIZE 8
  46. #define CSR_CACHE_SIZE_FIRMWARE 64
  47. /*
  48. * USB request types.
  49. */
  50. #define USB_VENDOR_REQUEST ( USB_TYPE_VENDOR | USB_RECIP_DEVICE )
  51. #define USB_VENDOR_REQUEST_IN ( USB_DIR_IN | USB_VENDOR_REQUEST )
  52. #define USB_VENDOR_REQUEST_OUT ( USB_DIR_OUT | USB_VENDOR_REQUEST )
  53. /*
  54. * USB vendor commands.
  55. */
  56. #define USB_DEVICE_MODE 0x01
  57. #define USB_SINGLE_WRITE 0x02
  58. #define USB_SINGLE_READ 0x03
  59. #define USB_MULTI_WRITE 0x06
  60. #define USB_MULTI_READ 0x07
  61. #define USB_EEPROM_WRITE 0x08
  62. #define USB_EEPROM_READ 0x09
  63. #define USB_LED_CONTROL 0x0a /* RT73USB */
  64. #define USB_RX_CONTROL 0x0c
  65. /*
  66. * Device modes offset
  67. */
  68. #define USB_MODE_RESET 0x01
  69. #define USB_MODE_UNPLUG 0x02
  70. #define USB_MODE_FUNCTION 0x03
  71. #define USB_MODE_TEST 0x04
  72. #define USB_MODE_SLEEP 0x07 /* RT73USB */
  73. #define USB_MODE_FIRMWARE 0x08 /* RT73USB */
  74. #define USB_MODE_WAKEUP 0x09 /* RT73USB */
  75. /*
  76. * Used to read/write from/to the device.
  77. * This is the main function to communicate with the device,
  78. * the buffer argument _must_ either be NULL or point to
  79. * a buffer allocated by kmalloc. Failure to do so can lead
  80. * to unexpected behavior depending on the architecture.
  81. */
  82. int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
  83. const u8 request, const u8 requesttype,
  84. const u16 offset, const u16 value,
  85. void *buffer, const u16 buffer_length,
  86. const int timeout);
  87. /*
  88. * Used to read/write from/to the device.
  89. * This function will use a previously with kmalloc allocated cache
  90. * to communicate with the device. The contents of the buffer pointer
  91. * will be copied to this cache when writing, or read from the cache
  92. * when reading.
  93. * Buffers send to rt2x00usb_vendor_request _must_ be allocated with
  94. * kmalloc. Hence the reason for using a previously allocated cache
  95. * which has been allocated properly.
  96. */
  97. int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
  98. const u8 request, const u8 requesttype,
  99. const u16 offset, void *buffer,
  100. const u16 buffer_length, const int timeout);
  101. /*
  102. * A version of rt2x00usb_vendor_request_buff which must be called
  103. * if the usb_cache_mutex is already held. */
  104. int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev *rt2x00dev,
  105. const u8 request, const u8 requesttype,
  106. const u16 offset, void *buffer,
  107. const u16 buffer_length, const int timeout);
  108. /*
  109. * Simple wrapper around rt2x00usb_vendor_request to write a single
  110. * command to the device. Since we don't use the buffer argument we
  111. * don't have to worry about kmalloc here.
  112. */
  113. static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
  114. const u8 request,
  115. const u16 offset,
  116. const u16 value,
  117. const int timeout)
  118. {
  119. return rt2x00usb_vendor_request(rt2x00dev, request,
  120. USB_VENDOR_REQUEST_OUT, offset,
  121. value, NULL, 0, timeout);
  122. }
  123. /*
  124. * Simple wrapper around rt2x00usb_vendor_request to read the eeprom
  125. * from the device. Note that the eeprom argument _must_ be allocated using
  126. * kmalloc for correct handling inside the kernel USB layer.
  127. */
  128. static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
  129. __le16 *eeprom, const u16 lenght)
  130. {
  131. int timeout = REGISTER_TIMEOUT * (lenght / sizeof(u16));
  132. return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
  133. USB_VENDOR_REQUEST_IN, 0x0000,
  134. 0x0000, eeprom, lenght, timeout);
  135. }
  136. /*
  137. * Radio handlers
  138. */
  139. void rt2x00usb_enable_radio(struct rt2x00_dev *rt2x00dev);
  140. void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
  141. /*
  142. * TX data handlers.
  143. */
  144. int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
  145. struct data_ring *ring, struct sk_buff *skb,
  146. struct ieee80211_tx_control *control);
  147. /*
  148. * Device initialization handlers.
  149. */
  150. int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
  151. void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
  152. /*
  153. * USB driver handlers.
  154. */
  155. int rt2x00usb_probe(struct usb_interface *usb_intf,
  156. const struct usb_device_id *id);
  157. void rt2x00usb_disconnect(struct usb_interface *usb_intf);
  158. #ifdef CONFIG_PM
  159. int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
  160. int rt2x00usb_resume(struct usb_interface *usb_intf);
  161. #else
  162. #define rt2x00usb_suspend NULL
  163. #define rt2x00usb_resume NULL
  164. #endif /* CONFIG_PM */
  165. #endif /* RT2X00USB_H */