xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8821cs/include/usb_ops_linux.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun  *
3*4882a593Smuzhiyun  * Copyright(c) 2007 - 2017 Realtek Corporation.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify it
6*4882a593Smuzhiyun  * under the terms of version 2 of the GNU General Public License as
7*4882a593Smuzhiyun  * published by the Free Software Foundation.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful, but WITHOUT
10*4882a593Smuzhiyun  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12*4882a593Smuzhiyun  * more details.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  *****************************************************************************/
15*4882a593Smuzhiyun #ifndef __USB_OPS_LINUX_H__
16*4882a593Smuzhiyun #define __USB_OPS_LINUX_H__
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #define VENDOR_CMD_MAX_DATA_LEN	254
19*4882a593Smuzhiyun #define FW_START_ADDRESS	0x1000
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #define RTW_USB_CONTROL_MSG_TIMEOUT_TEST	10/* ms */
22*4882a593Smuzhiyun #define RTW_USB_CONTROL_MSG_TIMEOUT	500/* ms */
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #define RECV_BULK_IN_ADDR		0x80/* assign by drv, not real address */
25*4882a593Smuzhiyun #define RECV_INT_IN_ADDR		0x81/* assign by drv, not real address */
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #define INTERRUPT_MSG_FORMAT_LEN 60
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #if defined(CONFIG_VENDOR_REQ_RETRY) && defined(CONFIG_USB_VENDOR_REQ_MUTEX)
30*4882a593Smuzhiyun 	/* vendor req retry should be in the situation when each vendor req is atomically submitted from others */
31*4882a593Smuzhiyun 	#define MAX_USBCTRL_VENDORREQ_TIMES	10
32*4882a593Smuzhiyun #else
33*4882a593Smuzhiyun 	#define MAX_USBCTRL_VENDORREQ_TIMES	1
34*4882a593Smuzhiyun #endif
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #define RTW_USB_BULKOUT_TIMEOUT	5000/* ms */
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)) || (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
39*4882a593Smuzhiyun #define _usbctrl_vendorreq_async_callback(urb, regs)	_usbctrl_vendorreq_async_callback(urb)
40*4882a593Smuzhiyun #define usb_bulkout_zero_complete(purb, regs)	usb_bulkout_zero_complete(purb)
41*4882a593Smuzhiyun #define usb_write_mem_complete(purb, regs)	usb_write_mem_complete(purb)
42*4882a593Smuzhiyun #define usb_write_port_complete(purb, regs)	usb_write_port_complete(purb)
43*4882a593Smuzhiyun #define usb_read_port_complete(purb, regs)	usb_read_port_complete(purb)
44*4882a593Smuzhiyun #define usb_read_interrupt_complete(purb, regs)	usb_read_interrupt_complete(purb)
45*4882a593Smuzhiyun #endif
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 12))
48*4882a593Smuzhiyun #define rtw_usb_control_msg(dev, pipe, request, requesttype, value, index, data, size, timeout_ms) \
49*4882a593Smuzhiyun 	usb_control_msg((dev), (pipe), (request), (requesttype), (value), (index), (data), (size), (timeout_ms))
50*4882a593Smuzhiyun #define rtw_usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout_ms) \
51*4882a593Smuzhiyun 	usb_bulk_msg((usb_dev), (pipe), (data), (len), (actual_length), (timeout_ms))
52*4882a593Smuzhiyun #else
53*4882a593Smuzhiyun #define rtw_usb_control_msg(dev, pipe, request, requesttype, value, index, data, size, timeout_ms) \
54*4882a593Smuzhiyun 	usb_control_msg((dev), (pipe), (request), (requesttype), (value), (index), (data), (size), \
55*4882a593Smuzhiyun 		((timeout_ms) == 0) || ((timeout_ms) * HZ / 1000 > 0) ? ((timeout_ms) * HZ / 1000) : 1)
56*4882a593Smuzhiyun #define rtw_usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout_ms) \
57*4882a593Smuzhiyun 	usb_bulk_msg((usb_dev), (pipe), (data), (len), (actual_length), \
58*4882a593Smuzhiyun 		((timeout_ms) == 0) || ((timeout_ms) * HZ / 1000 > 0) ? ((timeout_ms) * HZ / 1000) : 1)
59*4882a593Smuzhiyun #endif
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun #ifdef CONFIG_USB_SUPPORT_ASYNC_VDN_REQ
63*4882a593Smuzhiyun int usb_async_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val);
64*4882a593Smuzhiyun int usb_async_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val);
65*4882a593Smuzhiyun int usb_async_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val);
66*4882a593Smuzhiyun #endif /* CONFIG_USB_SUPPORT_ASYNC_VDN_REQ */
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun unsigned int ffaddr2pipehdl(struct dvobj_priv *pdvobj, u32 addr);
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun void usb_read_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem);
71*4882a593Smuzhiyun void usb_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem);
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun void usb_read_port_cancel(struct intf_hdl *pintfhdl);
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun u32 usb_write_port(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem);
76*4882a593Smuzhiyun void usb_write_port_cancel(struct intf_hdl *pintfhdl);
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u8 request, u16 value, u16 index, void *pdata, u16 len, u8 requesttype);
79*4882a593Smuzhiyun #ifdef CONFIG_USB_SUPPORT_ASYNC_VDN_REQ
80*4882a593Smuzhiyun int _usbctrl_vendorreq_async_write(struct usb_device *udev, u8 request,
81*4882a593Smuzhiyun 		u16 value, u16 index, void *pdata, u16 len, u8 requesttype);
82*4882a593Smuzhiyun #endif /* CONFIG_USB_SUPPORT_ASYNC_VDN_REQ */
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun u8 usb_read8(struct intf_hdl *pintfhdl, u32 addr);
85*4882a593Smuzhiyun u16 usb_read16(struct intf_hdl *pintfhdl, u32 addr);
86*4882a593Smuzhiyun u32 usb_read32(struct intf_hdl *pintfhdl, u32 addr);
87*4882a593Smuzhiyun int usb_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val);
88*4882a593Smuzhiyun int usb_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val);
89*4882a593Smuzhiyun int usb_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val);
90*4882a593Smuzhiyun int usb_writeN(struct intf_hdl *pintfhdl, u32 addr, u32 length, u8 *pdata);
91*4882a593Smuzhiyun u32 usb_read_port(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem);
92*4882a593Smuzhiyun void usb_recv_tasklet(unsigned long priv);
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
95*4882a593Smuzhiyun void usb_read_interrupt_complete(struct urb *purb, struct pt_regs *regs);
96*4882a593Smuzhiyun u32 usb_read_interrupt(struct intf_hdl *pintfhdl, u32 addr);
97*4882a593Smuzhiyun #endif
98*4882a593Smuzhiyun #endif
99