1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3  * usb_ops.c
4  *
5  * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
6  * Linux device driver for RTL8192SU
7  *
8  * Modifications for inclusion into the Linux staging tree are
9  * Copyright(c) 2010 Larry Finger. All rights reserved.
10  *
11  * Contact information:
12  * WLAN FAE <wlanfae@realtek.com>
13  * Larry Finger <Larry.Finger@lwfinger.net>
14  *
15  ******************************************************************************/
16 
17 #define _HCI_OPS_C_
18 
19 #include "osdep_service.h"
20 #include "drv_types.h"
21 #include "osdep_intf.h"
22 #include "usb_ops.h"
23 #include "recv_osdep.h"
24 
usb_read8(struct intf_hdl * intfhdl,u32 addr)25 static u8 usb_read8(struct intf_hdl *intfhdl, u32 addr)
26 {
27 	u8 request;
28 	u8 requesttype;
29 	u16 wvalue;
30 	u16 index;
31 	u16 len;
32 	int status;
33 	__le32 data = 0;
34 	struct intf_priv *intfpriv = intfhdl->pintfpriv;
35 
36 	request = 0x05;
37 	requesttype = 0x01; /* read_in */
38 	index = 0;
39 	wvalue = (u16)(addr & 0x0000ffff);
40 	len = 1;
41 	status = r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index,
42 					 &data, len, requesttype);
43 	if (status < 0)
44 		return 0;
45 	return (u8)(le32_to_cpu(data) & 0x0ff);
46 }
47 
usb_read16(struct intf_hdl * intfhdl,u32 addr)48 static u16 usb_read16(struct intf_hdl *intfhdl, u32 addr)
49 {
50 	u8 request;
51 	u8 requesttype;
52 	u16 wvalue;
53 	u16 index;
54 	u16 len;
55 	int status;
56 	__le32 data = 0;
57 	struct intf_priv *intfpriv = intfhdl->pintfpriv;
58 
59 	request = 0x05;
60 	requesttype = 0x01; /* read_in */
61 	index = 0;
62 	wvalue = (u16)(addr & 0x0000ffff);
63 	len = 2;
64 	status = r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index,
65 					 &data, len, requesttype);
66 	if (status < 0)
67 		return 0;
68 	return (u16)(le32_to_cpu(data) & 0xffff);
69 }
70 
usb_read32(struct intf_hdl * intfhdl,u32 addr)71 static u32 usb_read32(struct intf_hdl *intfhdl, u32 addr)
72 {
73 	u8 request;
74 	u8 requesttype;
75 	u16 wvalue;
76 	u16 index;
77 	u16 len;
78 	int status;
79 	__le32 data = 0;
80 	struct intf_priv *intfpriv = intfhdl->pintfpriv;
81 
82 	request = 0x05;
83 	requesttype = 0x01; /* read_in */
84 	index = 0;
85 	wvalue = (u16)(addr & 0x0000ffff);
86 	len = 4;
87 	status = r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index,
88 					 &data, len, requesttype);
89 	if (status < 0)
90 		return 0;
91 	return le32_to_cpu(data);
92 }
93 
usb_write8(struct intf_hdl * intfhdl,u32 addr,u8 val)94 static void usb_write8(struct intf_hdl *intfhdl, u32 addr, u8 val)
95 {
96 	u8 request;
97 	u8 requesttype;
98 	u16 wvalue;
99 	u16 index;
100 	u16 len;
101 	__le32 data;
102 	struct intf_priv *intfpriv = intfhdl->pintfpriv;
103 
104 	request = 0x05;
105 	requesttype = 0x00; /* write_out */
106 	index = 0;
107 	wvalue = (u16)(addr & 0x0000ffff);
108 	len = 1;
109 	data = cpu_to_le32((u32)val & 0x000000ff);
110 	r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
111 				requesttype);
112 }
113 
usb_write16(struct intf_hdl * intfhdl,u32 addr,u16 val)114 static void usb_write16(struct intf_hdl *intfhdl, u32 addr, u16 val)
115 {
116 	u8 request;
117 	u8 requesttype;
118 	u16 wvalue;
119 	u16 index;
120 	u16 len;
121 	__le32 data;
122 	struct intf_priv *intfpriv = intfhdl->pintfpriv;
123 
124 	request = 0x05;
125 	requesttype = 0x00; /* write_out */
126 	index = 0;
127 	wvalue = (u16)(addr & 0x0000ffff);
128 	len = 2;
129 	data = cpu_to_le32((u32)val & 0x0000ffff);
130 	r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
131 				requesttype);
132 }
133 
usb_write32(struct intf_hdl * intfhdl,u32 addr,u32 val)134 static void usb_write32(struct intf_hdl *intfhdl, u32 addr, u32 val)
135 {
136 	u8 request;
137 	u8 requesttype;
138 	u16 wvalue;
139 	u16 index;
140 	u16 len;
141 	__le32 data;
142 	struct intf_priv *intfpriv = intfhdl->pintfpriv;
143 
144 	request = 0x05;
145 	requesttype = 0x00; /* write_out */
146 	index = 0;
147 	wvalue = (u16)(addr & 0x0000ffff);
148 	len = 4;
149 	data = cpu_to_le32(val);
150 	r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
151 				requesttype);
152 }
153 
r8712_usb_set_intf_option(u32 * option)154 void r8712_usb_set_intf_option(u32 *option)
155 {
156 	*option = ((*option) | _INTF_ASYNC_);
157 }
158 
usb_intf_hdl_init(u8 * priv)159 static void usb_intf_hdl_init(u8 *priv)
160 {
161 }
162 
usb_intf_hdl_unload(u8 * priv)163 static void usb_intf_hdl_unload(u8 *priv)
164 {
165 }
166 
usb_intf_hdl_open(u8 * priv)167 static void usb_intf_hdl_open(u8 *priv)
168 {
169 }
170 
usb_intf_hdl_close(u8 * priv)171 static void usb_intf_hdl_close(u8 *priv)
172 {
173 }
174 
r8712_usb_set_intf_funs(struct intf_hdl * intfhdl)175 void r8712_usb_set_intf_funs(struct intf_hdl *intfhdl)
176 {
177 	intfhdl->intf_hdl_init = usb_intf_hdl_init;
178 	intfhdl->intf_hdl_unload = usb_intf_hdl_unload;
179 	intfhdl->intf_hdl_open = usb_intf_hdl_open;
180 	intfhdl->intf_hdl_close = usb_intf_hdl_close;
181 }
182 
r8712_usb_set_intf_ops(struct _io_ops * ops)183 void r8712_usb_set_intf_ops(struct _io_ops *ops)
184 {
185 	memset((u8 *)ops, 0, sizeof(struct _io_ops));
186 	ops->_read8 = usb_read8;
187 	ops->_read16 = usb_read16;
188 	ops->_read32 = usb_read32;
189 	ops->_read_port = r8712_usb_read_port;
190 	ops->_write8 = usb_write8;
191 	ops->_write16 = usb_write16;
192 	ops->_write32 = usb_write32;
193 	ops->_write_mem = r8712_usb_write_mem;
194 	ops->_write_port = r8712_usb_write_port;
195 }
196