zd_usb.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /* zd_usb.h: Header for USB interface implemented by ZD1211 chip
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  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. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #ifndef _ZD_USB_H
  18. #define _ZD_USB_H
  19. #include <linux/completion.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/skbuff.h>
  23. #include <linux/usb.h>
  24. #include "zd_def.h"
  25. enum devicetype {
  26. DEVICE_ZD1211 = 0,
  27. DEVICE_ZD1211B = 1,
  28. DEVICE_INSTALLER = 2,
  29. };
  30. enum endpoints {
  31. EP_CTRL = 0,
  32. EP_DATA_OUT = 1,
  33. EP_DATA_IN = 2,
  34. EP_INT_IN = 3,
  35. EP_REGS_OUT = 4,
  36. };
  37. enum {
  38. USB_MAX_TRANSFER_SIZE = 4096, /* bytes */
  39. /* FIXME: The original driver uses this value. We have to check,
  40. * whether the MAX_TRANSFER_SIZE is sufficient and this needs only be
  41. * used if one combined frame is split over two USB transactions.
  42. */
  43. USB_MAX_RX_SIZE = 4800, /* bytes */
  44. USB_MAX_IOWRITE16_COUNT = 15,
  45. USB_MAX_IOWRITE32_COUNT = USB_MAX_IOWRITE16_COUNT/2,
  46. USB_MAX_IOREAD16_COUNT = 15,
  47. USB_MAX_IOREAD32_COUNT = USB_MAX_IOREAD16_COUNT/2,
  48. USB_MIN_RFWRITE_BIT_COUNT = 16,
  49. USB_MAX_RFWRITE_BIT_COUNT = 28,
  50. USB_MAX_EP_INT_BUFFER = 64,
  51. USB_ZD1211B_BCD_DEVICE = 0x4810,
  52. };
  53. enum control_requests {
  54. USB_REQ_WRITE_REGS = 0x21,
  55. USB_REQ_READ_REGS = 0x22,
  56. USB_REQ_WRITE_RF = 0x23,
  57. USB_REQ_PROG_FLASH = 0x24,
  58. USB_REQ_EEPROM_START = 0x0128, /* ? request is a byte */
  59. USB_REQ_EEPROM_MID = 0x28,
  60. USB_REQ_EEPROM_END = 0x0228, /* ? request is a byte */
  61. USB_REQ_FIRMWARE_DOWNLOAD = 0x30,
  62. USB_REQ_FIRMWARE_CONFIRM = 0x31,
  63. USB_REQ_FIRMWARE_READ_DATA = 0x32,
  64. };
  65. struct usb_req_read_regs {
  66. __le16 id;
  67. __le16 addr[0];
  68. } __attribute__((packed));
  69. struct reg_data {
  70. __le16 addr;
  71. __le16 value;
  72. } __attribute__((packed));
  73. struct usb_req_write_regs {
  74. __le16 id;
  75. struct reg_data reg_writes[0];
  76. } __attribute__((packed));
  77. enum {
  78. RF_IF_LE = 0x02,
  79. RF_CLK = 0x04,
  80. RF_DATA = 0x08,
  81. };
  82. struct usb_req_rfwrite {
  83. __le16 id;
  84. __le16 value;
  85. /* 1: 3683a */
  86. /* 2: other (default) */
  87. __le16 bits;
  88. /* RF2595: 24 */
  89. __le16 bit_values[0];
  90. /* (CR203 & ~(RF_IF_LE | RF_CLK | RF_DATA)) | (bit ? RF_DATA : 0) */
  91. } __attribute__((packed));
  92. /* USB interrupt */
  93. enum usb_int_id {
  94. USB_INT_TYPE = 0x01,
  95. USB_INT_ID_REGS = 0x90,
  96. USB_INT_ID_RETRY_FAILED = 0xa0,
  97. };
  98. enum usb_int_flags {
  99. USB_INT_READ_REGS_EN = 0x01,
  100. };
  101. struct usb_int_header {
  102. u8 type; /* must always be 1 */
  103. u8 id;
  104. } __attribute__((packed));
  105. struct usb_int_regs {
  106. struct usb_int_header hdr;
  107. struct reg_data regs[0];
  108. } __attribute__((packed));
  109. struct usb_int_retry_fail {
  110. struct usb_int_header hdr;
  111. u8 new_rate;
  112. u8 _dummy;
  113. u8 addr[ETH_ALEN];
  114. u8 ibss_wakeup_dest;
  115. } __attribute__((packed));
  116. struct read_regs_int {
  117. struct completion completion;
  118. /* Stores the USB int structure and contains the USB address of the
  119. * first requested register before request.
  120. */
  121. u8 buffer[USB_MAX_EP_INT_BUFFER];
  122. int length;
  123. __le16 cr_int_addr;
  124. };
  125. struct zd_ioreq16 {
  126. zd_addr_t addr;
  127. u16 value;
  128. };
  129. struct zd_ioreq32 {
  130. zd_addr_t addr;
  131. u32 value;
  132. };
  133. struct zd_usb_interrupt {
  134. struct read_regs_int read_regs;
  135. spinlock_t lock;
  136. struct urb *urb;
  137. int interval;
  138. u8 read_regs_enabled:1;
  139. };
  140. static inline struct usb_int_regs *get_read_regs(struct zd_usb_interrupt *intr)
  141. {
  142. return (struct usb_int_regs *)intr->read_regs.buffer;
  143. }
  144. #define URBS_COUNT 5
  145. struct zd_usb_rx {
  146. spinlock_t lock;
  147. u8 fragment[2*USB_MAX_RX_SIZE];
  148. unsigned int fragment_length;
  149. unsigned int usb_packet_size;
  150. struct urb **urbs;
  151. int urbs_count;
  152. };
  153. struct zd_usb_tx {
  154. spinlock_t lock;
  155. };
  156. /* Contains the usb parts. The structure doesn't require a lock because intf
  157. * will not be changed after initialization.
  158. */
  159. struct zd_usb {
  160. struct zd_usb_interrupt intr;
  161. struct zd_usb_rx rx;
  162. struct zd_usb_tx tx;
  163. struct usb_interface *intf;
  164. };
  165. #define zd_usb_dev(usb) (&usb->intf->dev)
  166. static inline struct usb_device *zd_usb_to_usbdev(struct zd_usb *usb)
  167. {
  168. return interface_to_usbdev(usb->intf);
  169. }
  170. static inline struct net_device *zd_intf_to_netdev(struct usb_interface *intf)
  171. {
  172. return usb_get_intfdata(intf);
  173. }
  174. static inline struct net_device *zd_usb_to_netdev(struct zd_usb *usb)
  175. {
  176. return zd_intf_to_netdev(usb->intf);
  177. }
  178. void zd_usb_init(struct zd_usb *usb, struct net_device *netdev,
  179. struct usb_interface *intf);
  180. int zd_usb_init_hw(struct zd_usb *usb);
  181. void zd_usb_clear(struct zd_usb *usb);
  182. int zd_usb_scnprint_id(struct zd_usb *usb, char *buffer, size_t size);
  183. int zd_usb_enable_int(struct zd_usb *usb);
  184. void zd_usb_disable_int(struct zd_usb *usb);
  185. int zd_usb_enable_rx(struct zd_usb *usb);
  186. void zd_usb_disable_rx(struct zd_usb *usb);
  187. int zd_usb_tx(struct zd_usb *usb, const u8 *frame, unsigned int length);
  188. int zd_usb_ioread16v(struct zd_usb *usb, u16 *values,
  189. const zd_addr_t *addresses, unsigned int count);
  190. static inline int zd_usb_ioread16(struct zd_usb *usb, u16 *value,
  191. const zd_addr_t addr)
  192. {
  193. return zd_usb_ioread16v(usb, value, (const zd_addr_t *)&addr, 1);
  194. }
  195. int zd_usb_iowrite16v(struct zd_usb *usb, const struct zd_ioreq16 *ioreqs,
  196. unsigned int count);
  197. int zd_usb_rfwrite(struct zd_usb *usb, u32 value, u8 bits);
  198. extern struct workqueue_struct *zd_workqueue;
  199. #endif /* _ZD_USB_H */