blob: 2fa45c57a73fa812f050a6bc2df21b47aea92dc9 [file] [log] [blame]
Ivo van Doorn95ea3622007-09-25 17:57:13 -07001/*
2 Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 Module: rt2x00usb
23 Abstract: Data structures for the rt2x00usb module.
24 */
25
26#ifndef RT2X00USB_H
27#define RT2X00USB_H
28
29/*
30 * This variable should be used with the
31 * usb_driver structure initialization.
32 */
33#define USB_DEVICE_DATA(__ops) .driver_info = (kernel_ulong_t)(__ops)
34
35/*
36 * Register defines.
37 * Some registers require multiple attempts before success,
38 * in those cases REGISTER_BUSY_COUNT attempts should be
39 * taken with a REGISTER_BUSY_DELAY interval.
40 * For USB vendor requests we need to pass a timeout
41 * time in ms, for this we use the REGISTER_TIMEOUT,
42 * however when loading firmware a higher value is
43 * required. In that case we use the REGISTER_TIMEOUT_FIRMWARE.
44 */
45#define REGISTER_BUSY_COUNT 5
46#define REGISTER_BUSY_DELAY 100
Ivo van Doorne9136552007-09-25 20:54:20 +020047#define REGISTER_TIMEOUT 500
Ivo van Doorn95ea3622007-09-25 17:57:13 -070048#define REGISTER_TIMEOUT_FIRMWARE 1000
49
50/*
51 * Cache size
52 */
53#define CSR_CACHE_SIZE 8
54#define CSR_CACHE_SIZE_FIRMWARE 64
55
56/*
57 * USB request types.
58 */
59#define USB_VENDOR_REQUEST ( USB_TYPE_VENDOR | USB_RECIP_DEVICE )
60#define USB_VENDOR_REQUEST_IN ( USB_DIR_IN | USB_VENDOR_REQUEST )
61#define USB_VENDOR_REQUEST_OUT ( USB_DIR_OUT | USB_VENDOR_REQUEST )
62
63/*
64 * USB vendor commands.
65 */
66#define USB_DEVICE_MODE 0x01
67#define USB_SINGLE_WRITE 0x02
68#define USB_SINGLE_READ 0x03
69#define USB_MULTI_WRITE 0x06
70#define USB_MULTI_READ 0x07
71#define USB_EEPROM_WRITE 0x08
72#define USB_EEPROM_READ 0x09
73#define USB_LED_CONTROL 0x0a /* RT73USB */
74#define USB_RX_CONTROL 0x0c
75
76/*
77 * Device modes offset
78 */
79#define USB_MODE_RESET 0x01
80#define USB_MODE_UNPLUG 0x02
81#define USB_MODE_FUNCTION 0x03
82#define USB_MODE_TEST 0x04
83#define USB_MODE_SLEEP 0x07 /* RT73USB */
84#define USB_MODE_FIRMWARE 0x08 /* RT73USB */
85#define USB_MODE_WAKEUP 0x09 /* RT73USB */
86
87/*
88 * Used to read/write from/to the device.
89 * This is the main function to communicate with the device,
90 * the buffer argument _must_ either be NULL or point to
91 * a buffer allocated by kmalloc. Failure to do so can lead
92 * to unexpected behavior depending on the architecture.
93 */
Adam Baker0e14f6d2007-10-27 13:41:25 +020094int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -070095 const u8 request, const u8 requesttype,
96 const u16 offset, const u16 value,
97 void *buffer, const u16 buffer_length,
Ivo van Doorne9136552007-09-25 20:54:20 +020098 const int timeout);
Ivo van Doorn95ea3622007-09-25 17:57:13 -070099
100/*
101 * Used to read/write from/to the device.
102 * This function will use a previously with kmalloc allocated cache
103 * to communicate with the device. The contents of the buffer pointer
104 * will be copied to this cache when writing, or read from the cache
105 * when reading.
106 * Buffers send to rt2x00usb_vendor_request _must_ be allocated with
107 * kmalloc. Hence the reason for using a previously allocated cache
108 * which has been allocated properly.
109 */
Adam Baker0e14f6d2007-10-27 13:41:25 +0200110int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700111 const u8 request, const u8 requesttype,
112 const u16 offset, void *buffer,
Ivo van Doorne9136552007-09-25 20:54:20 +0200113 const u16 buffer_length, const int timeout);
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700114
115/*
Adam Baker3d823462007-10-27 13:43:29 +0200116 * A version of rt2x00usb_vendor_request_buff which must be called
117 * if the usb_cache_mutex is already held. */
118int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev *rt2x00dev,
119 const u8 request, const u8 requesttype,
120 const u16 offset, void *buffer,
121 const u16 buffer_length, const int timeout);
122
123/*
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700124 * Simple wrapper around rt2x00usb_vendor_request to write a single
125 * command to the device. Since we don't use the buffer argument we
126 * don't have to worry about kmalloc here.
127 */
Adam Baker0e14f6d2007-10-27 13:41:25 +0200128static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700129 const u8 request,
130 const u16 offset,
131 const u16 value,
Ivo van Doorne9136552007-09-25 20:54:20 +0200132 const int timeout)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700133{
134 return rt2x00usb_vendor_request(rt2x00dev, request,
135 USB_VENDOR_REQUEST_OUT, offset,
136 value, NULL, 0, timeout);
137}
138
139/*
140 * Simple wrapper around rt2x00usb_vendor_request to read the eeprom
141 * from the device. Note that the eeprom argument _must_ be allocated using
142 * kmalloc for correct handling inside the kernel USB layer.
143 */
Adam Baker0e14f6d2007-10-27 13:41:25 +0200144static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
145 __le16 *eeprom, const u16 lenght)
Ivo van Doorn95ea3622007-09-25 17:57:13 -0700146{
147 int timeout = REGISTER_TIMEOUT * (lenght / sizeof(u16));
148
149 return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
150 USB_VENDOR_REQUEST_IN, 0x0000,
151 0x0000, eeprom, lenght, timeout);
152}
153
154/*
155 * Radio handlers
156 */
157void rt2x00usb_enable_radio(struct rt2x00_dev *rt2x00dev);
158void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
159
160/*
161 * TX data handlers.
162 */
163int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
164 struct data_ring *ring, struct sk_buff *skb,
165 struct ieee80211_tx_control *control);
166
167/*
168 * Device initialization handlers.
169 */
170int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
171void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
172
173/*
174 * USB driver handlers.
175 */
176int rt2x00usb_probe(struct usb_interface *usb_intf,
177 const struct usb_device_id *id);
178void rt2x00usb_disconnect(struct usb_interface *usb_intf);
179#ifdef CONFIG_PM
180int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
181int rt2x00usb_resume(struct usb_interface *usb_intf);
182#else
183#define rt2x00usb_suspend NULL
184#define rt2x00usb_resume NULL
185#endif /* CONFIG_PM */
186
187#endif /* RT2X00USB_H */