usb_ops.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /******************************************************************************
  2. * usb_ops.c
  3. *
  4. * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
  5. * Linux device driver for RTL8192SU
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  19. *
  20. * Modifications for inclusion into the Linux staging tree are
  21. * Copyright(c) 2010 Larry Finger. All rights reserved.
  22. *
  23. * Contact information:
  24. * WLAN FAE <wlanfae@realtek.com>
  25. * Larry Finger <Larry.Finger@lwfinger.net>
  26. *
  27. ******************************************************************************/
  28. #define _HCI_OPS_C_
  29. #include "osdep_service.h"
  30. #include "drv_types.h"
  31. #include "osdep_intf.h"
  32. #include "usb_ops.h"
  33. #include "recv_osdep.h"
  34. static u8 usb_read8(struct intf_hdl *pintfhdl, u32 addr)
  35. {
  36. u8 request;
  37. u8 requesttype;
  38. u16 wvalue;
  39. u16 index;
  40. u16 len;
  41. u32 data;
  42. struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
  43. request = 0x05;
  44. requesttype = 0x01; /* read_in */
  45. index = 0;
  46. wvalue = (u16)(addr & 0x0000ffff);
  47. len = 1;
  48. r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
  49. requesttype);
  50. return (u8)(le32_to_cpu(data) & 0x0ff);
  51. }
  52. static u16 usb_read16(struct intf_hdl *pintfhdl, u32 addr)
  53. {
  54. u8 request;
  55. u8 requesttype;
  56. u16 wvalue;
  57. u16 index;
  58. u16 len;
  59. u32 data;
  60. struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
  61. request = 0x05;
  62. requesttype = 0x01; /* read_in */
  63. index = 0;
  64. wvalue = (u16)(addr & 0x0000ffff);
  65. len = 2;
  66. r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
  67. requesttype);
  68. return (u16)(le32_to_cpu(data) & 0xffff);
  69. }
  70. static u32 usb_read32(struct intf_hdl *pintfhdl, u32 addr)
  71. {
  72. u8 request;
  73. u8 requesttype;
  74. u16 wvalue;
  75. u16 index;
  76. u16 len;
  77. u32 data;
  78. struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
  79. request = 0x05;
  80. requesttype = 0x01; /* read_in */
  81. index = 0;
  82. wvalue = (u16)(addr & 0x0000ffff);
  83. len = 4;
  84. r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
  85. requesttype);
  86. return le32_to_cpu(data);
  87. }
  88. static void usb_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
  89. {
  90. u8 request;
  91. u8 requesttype;
  92. u16 wvalue;
  93. u16 index;
  94. u16 len;
  95. u32 data;
  96. struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
  97. request = 0x05;
  98. requesttype = 0x00; /* write_out */
  99. index = 0;
  100. wvalue = (u16)(addr & 0x0000ffff);
  101. len = 1;
  102. data = val;
  103. data = cpu_to_le32(data & 0x000000ff);
  104. r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
  105. requesttype);
  106. }
  107. static void usb_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
  108. {
  109. u8 request;
  110. u8 requesttype;
  111. u16 wvalue;
  112. u16 index;
  113. u16 len;
  114. u32 data;
  115. struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
  116. request = 0x05;
  117. requesttype = 0x00; /* write_out */
  118. index = 0;
  119. wvalue = (u16)(addr & 0x0000ffff);
  120. len = 2;
  121. data = val;
  122. data = cpu_to_le32(data & 0x0000ffff);
  123. r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
  124. requesttype);
  125. }
  126. static void usb_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
  127. {
  128. u8 request;
  129. u8 requesttype;
  130. u16 wvalue;
  131. u16 index;
  132. u16 len;
  133. u32 data;
  134. struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
  135. request = 0x05;
  136. requesttype = 0x00; /* write_out */
  137. index = 0;
  138. wvalue = (u16)(addr & 0x0000ffff);
  139. len = 4;
  140. data = cpu_to_le32(val);
  141. r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
  142. requesttype);
  143. }
  144. void r8712_usb_set_intf_option(u32 *poption)
  145. {
  146. *poption = ((*poption) | _INTF_ASYNC_);
  147. }
  148. static void usb_intf_hdl_init(u8 *priv)
  149. {
  150. }
  151. static void usb_intf_hdl_unload(u8 *priv)
  152. {
  153. }
  154. static void usb_intf_hdl_open(u8 *priv)
  155. {
  156. }
  157. static void usb_intf_hdl_close(u8 *priv)
  158. {
  159. }
  160. void r8712_usb_set_intf_funs(struct intf_hdl *pintf_hdl)
  161. {
  162. pintf_hdl->intf_hdl_init = &usb_intf_hdl_init;
  163. pintf_hdl->intf_hdl_unload = &usb_intf_hdl_unload;
  164. pintf_hdl->intf_hdl_open = &usb_intf_hdl_open;
  165. pintf_hdl->intf_hdl_close = &usb_intf_hdl_close;
  166. }
  167. void r8712_usb_set_intf_ops(struct _io_ops *pops)
  168. {
  169. memset((u8 *)pops, 0, sizeof(struct _io_ops));
  170. pops->_read8 = &usb_read8;
  171. pops->_read16 = &usb_read16;
  172. pops->_read32 = &usb_read32;
  173. pops->_read_port = &r8712_usb_read_port;
  174. pops->_write8 = &usb_write8;
  175. pops->_write16 = &usb_write16;
  176. pops->_write32 = &usb_write32;
  177. pops->_write_mem = &r8712_usb_write_mem;
  178. pops->_write_port = &r8712_usb_write_port;
  179. }