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