1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
22 #include <drv_types.h>
26 #ifdef CONFIG_USB_SUPPORT_ASYNC_VDN_REQ
27 int usb_write_async(struct usb_device *udev, u32 addr, void *pdata, u16 len)
35 requesttype = VENDOR_WRITE;//write_out
36 request = REALTEK_USB_VENQT_CMD_REQ;
37 index = REALTEK_USB_VENQT_CMD_IDX;//n/a
39 wvalue = (u16)(addr&0x0000ffff);
41 ret = _usbctrl_vendorreq_async_write(udev, request, wvalue, index, pdata, len, requesttype);
46 int usb_async_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
50 struct dvobj_priv *pdvobjpriv = (struct dvobj_priv *)pintfhdl->pintf_dev;
51 struct usb_device *udev=pdvobjpriv->pusbdev;
55 ret = usb_write_async(udev, addr, &data, 1);
61 int usb_async_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
65 struct dvobj_priv *pdvobjpriv = (struct dvobj_priv *)pintfhdl->pintf_dev;
66 struct usb_device *udev=pdvobjpriv->pusbdev;
70 ret = usb_write_async(udev, addr, &data, 2);
76 int usb_async_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
80 struct dvobj_priv *pdvobjpriv = (struct dvobj_priv *)pintfhdl->pintf_dev;
81 struct usb_device *udev=pdvobjpriv->pusbdev;
85 ret = usb_write_async(udev, addr, &data, 4);
90 #endif /* CONFIG_USB_SUPPORT_ASYNC_VDN_REQ */
94 #ifdef CONFIG_RTL8192D
95 /* This function only works in 92DU chip. */
96 void usb_read_reg_rf_byfw(struct intf_hdl *pintfhdl,
101 u16 wPage = 0x0000, offset;
102 u32 BufferLengthRead;
103 PADAPTER Adapter = pintfhdl->padapter;
104 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
107 RFPath =(u8) ((registerIndex&0xff0000)>>16);
109 if (pHalData->interfaceIndex!=0)
112 if(registerIndex&MAC1_ACCESS_PHY0)// MAC1 need to access PHY0
117 if(registerIndex&MAC0_ACCESS_PHY1)
120 registerIndex &= 0xFF;
121 wPage = ((nPHY<<7)|(RFPath<<5)|8)<<8;
122 offset = (u16)registerIndex;
125 // IN a vendor request to read back MAC register.
127 usbctrl_vendorreq(pintfhdl, 0x05, offset, wPage, buffer, byteCount, 0x01);
133 92DU chip needs to remask "value" parameter, this function only works in 92DU chip.
135 static inline void usb_value_remask(struct intf_hdl *pintfhdl, u16 *value)
137 #ifdef CONFIG_RTL8192D
138 _adapter *padapter = pintfhdl->padapter;
139 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
141 if ((IS_HARDWARE_TYPE_8192DU(padapter)) && (pHalData->interfaceIndex!=0))
145 else if ((*value&MAC1_ACCESS_PHY0) && !(*value&0x8000)) // MAC1 need to access PHY0
151 u8 usb_read8(struct intf_hdl *pintfhdl, u32 addr)
163 requesttype = 0x01;//read_in
166 wvalue = (u16)(addr&0x0000ffff);
168 usb_value_remask(pintfhdl, &wvalue);
169 usbctrl_vendorreq(pintfhdl, request, wvalue, index,
170 &data, len, requesttype);
177 u16 usb_read16(struct intf_hdl *pintfhdl, u32 addr)
189 requesttype = 0x01;//read_in
192 wvalue = (u16)(addr&0x0000ffff);
194 usb_value_remask(pintfhdl, &wvalue);
195 usbctrl_vendorreq(pintfhdl, request, wvalue, index,
196 &data, len, requesttype);
204 u32 usb_read32(struct intf_hdl *pintfhdl, u32 addr)
216 requesttype = 0x01;//read_in
219 wvalue = (u16)(addr&0x0000ffff);
221 #ifdef CONFIG_RTL8192D
222 if ((IS_HARDWARE_TYPE_8192DU(pintfhdl->padapter)) && ((addr&0xff000000)>>24 == 0x66)) {
223 usb_read_reg_rf_byfw(pintfhdl, len, addr, &data);
227 usb_value_remask(pintfhdl, &wvalue);
228 usbctrl_vendorreq(pintfhdl, request, wvalue, index,
229 &data, len, requesttype);
237 int usb_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
250 requesttype = 0x00;//write_out
253 wvalue = (u16)(addr&0x0000ffff);
257 usb_value_remask(pintfhdl, &wvalue);
258 ret = usbctrl_vendorreq(pintfhdl, request, wvalue, index,
259 &data, len, requesttype);
266 int usb_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
279 requesttype = 0x00;//write_out
282 wvalue = (u16)(addr&0x0000ffff);
286 usb_value_remask(pintfhdl, &wvalue);
287 ret = usbctrl_vendorreq(pintfhdl, request, wvalue, index,
288 &data, len, requesttype);
296 int usb_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
309 requesttype = 0x00;//write_out
312 wvalue = (u16)(addr&0x0000ffff);
315 usb_value_remask(pintfhdl, &wvalue);
316 ret = usbctrl_vendorreq(pintfhdl, request, wvalue, index,
317 &data, len, requesttype);
325 int usb_writeN(struct intf_hdl *pintfhdl, u32 addr, u32 length, u8 *pdata)
332 u8 buf[VENDOR_CMD_MAX_DATA_LEN]={0};
338 requesttype = 0x00;//write_out
341 wvalue = (u16)(addr&0x0000ffff);
343 _rtw_memcpy(buf, pdata, len );
344 usb_value_remask(pintfhdl, &wvalue);
345 ret = usbctrl_vendorreq(pintfhdl, request, wvalue, index,
346 buf, len, requesttype);