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 
29 #define _HCI_OPS_C_
30 
31 #include "osdep_service.h"
32 #include "drv_types.h"
33 #include "osdep_intf.h"
34 #include "usb_ops.h"
35 #include "recv_osdep.h"
36 #include "rtl871x_byteorder.h"
37 
usb_read8(struct intf_hdl * pintfhdl,u32 addr)38 static u8 usb_read8(struct intf_hdl *pintfhdl, u32 addr)
39 {
40 	u8 request;
41 	u8 requesttype;
42 	u16 wvalue;
43 	u16 index;
44 	u16 len;
45 	u32 data;
46 	struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
47 
48 	request = 0x05;
49 	requesttype = 0x01; /* read_in */
50 	index = 0;
51 	wvalue = (u16)(addr&0x0000ffff);
52 	len = 1;
53 	r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
54 			  requesttype);
55 	return (u8)(le32_to_cpu(data)&0x0ff);
56 }
57 
usb_read16(struct intf_hdl * pintfhdl,u32 addr)58 static u16 usb_read16(struct intf_hdl *pintfhdl, u32 addr)
59 {
60 	u8 request;
61 	u8 requesttype;
62 	u16 wvalue;
63 	u16 index;
64 	u16 len;
65 	u32 data;
66 	struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
67 
68 	request = 0x05;
69 	requesttype = 0x01; /* read_in */
70 	index = 0;
71 	wvalue = (u16)(addr&0x0000ffff);
72 	len = 2;
73 	r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
74 			  requesttype);
75 	return (u16)(le32_to_cpu(data)&0xffff);
76 }
77 
usb_read32(struct intf_hdl * pintfhdl,u32 addr)78 static u32 usb_read32(struct intf_hdl *pintfhdl, u32 addr)
79 {
80 	u8 request;
81 	u8 requesttype;
82 	u16 wvalue;
83 	u16 index;
84 	u16 len;
85 	u32 data;
86 	struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
87 
88 	request = 0x05;
89 	requesttype = 0x01; /* read_in */
90 	index = 0;
91 	wvalue = (u16)(addr&0x0000ffff);
92 	len = 4;
93 	r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
94 			  requesttype);
95 	return le32_to_cpu(data);
96 }
97 
usb_write8(struct intf_hdl * pintfhdl,u32 addr,u8 val)98 static void usb_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
99 {
100 	u8 request;
101 	u8 requesttype;
102 	u16 wvalue;
103 	u16 index;
104 	u16 len;
105 	u32 data;
106 	struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
107 
108 	request = 0x05;
109 	requesttype = 0x00; /* write_out */
110 	index = 0;
111 	wvalue = (u16)(addr&0x0000ffff);
112 	len = 1;
113 	data = val;
114 	data = cpu_to_le32(data&0x000000ff);
115 	r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
116 			  requesttype);
117 }
118 
usb_write16(struct intf_hdl * pintfhdl,u32 addr,u16 val)119 static void usb_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
120 {
121 	u8 request;
122 	u8 requesttype;
123 	u16 wvalue;
124 	u16 index;
125 	u16 len;
126 	u32 data;
127 	struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
128 
129 	request = 0x05;
130 	requesttype = 0x00; /* write_out */
131 	index = 0;
132 	wvalue = (u16)(addr&0x0000ffff);
133 	len = 2;
134 	data = val;
135 	data = cpu_to_le32(data&0x0000ffff);
136 	r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
137 			  requesttype);
138 }
139 
usb_write32(struct intf_hdl * pintfhdl,u32 addr,u32 val)140 static void usb_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
141 {
142 	u8 request;
143 	u8 requesttype;
144 	u16 wvalue;
145 	u16 index;
146 	u16 len;
147 	u32 data;
148 	struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
149 
150 	request = 0x05;
151 	requesttype = 0x00; /* write_out */
152 	index = 0;
153 	wvalue = (u16)(addr&0x0000ffff);
154 	len = 4;
155 	data = cpu_to_le32(val);
156 	r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
157 			  requesttype);
158 }
159 
r8712_usb_set_intf_option(u32 * poption)160 void r8712_usb_set_intf_option(u32 *poption)
161 {
162 	*poption = ((*poption) | _INTF_ASYNC_);
163 }
164 
usb_intf_hdl_init(u8 * priv)165 static void usb_intf_hdl_init(u8 *priv)
166 {
167 }
168 
usb_intf_hdl_unload(u8 * priv)169 static void usb_intf_hdl_unload(u8 *priv)
170 {
171 }
172 
usb_intf_hdl_open(u8 * priv)173 static void usb_intf_hdl_open(u8 *priv)
174 {
175 }
176 
usb_intf_hdl_close(u8 * priv)177 static void usb_intf_hdl_close(u8 *priv)
178 {
179 }
180 
r8712_usb_set_intf_funs(struct intf_hdl * pintf_hdl)181 void r8712_usb_set_intf_funs(struct intf_hdl *pintf_hdl)
182 {
183 	pintf_hdl->intf_hdl_init = &usb_intf_hdl_init;
184 	pintf_hdl->intf_hdl_unload = &usb_intf_hdl_unload;
185 	pintf_hdl->intf_hdl_open = &usb_intf_hdl_open;
186 	pintf_hdl->intf_hdl_close = &usb_intf_hdl_close;
187 }
188 
r8712_usb_set_intf_ops(struct _io_ops * pops)189 void r8712_usb_set_intf_ops(struct _io_ops	*pops)
190 {
191 	memset((u8 *)pops, 0, sizeof(struct _io_ops));
192 	pops->_read8 = &usb_read8;
193 	pops->_read16 = &usb_read16;
194 	pops->_read32 = &usb_read32;
195 	pops->_read_port = &r8712_usb_read_port;
196 	pops->_write8 = &usb_write8;
197 	pops->_write16 = &usb_write16;
198 	pops->_write32 = &usb_write32;
199 	pops->_write_mem = &r8712_usb_write_mem;
200 	pops->_write_port = &r8712_usb_write_port;
201 }
202