staging: vt6655: dead code remove zones and channel table elements
[firefly-linux-kernel-4.4.55.git] / drivers / staging / vt6655 / channel.c
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * File: channel.c
20  *
21  */
22
23 #include "baseband.h"
24 #include "country.h"
25 #include "channel.h"
26 #include "device.h"
27 #include "rf.h"
28
29 static struct ieee80211_rate vnt_rates_bg[] = {
30         { .bitrate = 10,  .hw_value = RATE_1M },
31         { .bitrate = 20,  .hw_value = RATE_2M },
32         { .bitrate = 55,  .hw_value = RATE_5M },
33         { .bitrate = 110, .hw_value = RATE_11M },
34         { .bitrate = 60,  .hw_value = RATE_6M },
35         { .bitrate = 90,  .hw_value = RATE_9M },
36         { .bitrate = 120, .hw_value = RATE_12M },
37         { .bitrate = 180, .hw_value = RATE_18M },
38         { .bitrate = 240, .hw_value = RATE_24M },
39         { .bitrate = 360, .hw_value = RATE_36M },
40         { .bitrate = 480, .hw_value = RATE_48M },
41         { .bitrate = 540, .hw_value = RATE_54M },
42 };
43
44 static struct ieee80211_rate vnt_rates_a[] = {
45         { .bitrate = 60,  .hw_value = RATE_6M },
46         { .bitrate = 90,  .hw_value = RATE_9M },
47         { .bitrate = 120, .hw_value = RATE_12M },
48         { .bitrate = 180, .hw_value = RATE_18M },
49         { .bitrate = 240, .hw_value = RATE_24M },
50         { .bitrate = 360, .hw_value = RATE_36M },
51         { .bitrate = 480, .hw_value = RATE_48M },
52         { .bitrate = 540, .hw_value = RATE_54M },
53 };
54
55 static struct ieee80211_channel vnt_channels_2ghz[] = {
56         { .center_freq = 2412, .hw_value = 1 },
57         { .center_freq = 2417, .hw_value = 2 },
58         { .center_freq = 2422, .hw_value = 3 },
59         { .center_freq = 2427, .hw_value = 4 },
60         { .center_freq = 2432, .hw_value = 5 },
61         { .center_freq = 2437, .hw_value = 6 },
62         { .center_freq = 2442, .hw_value = 7 },
63         { .center_freq = 2447, .hw_value = 8 },
64         { .center_freq = 2452, .hw_value = 9 },
65         { .center_freq = 2457, .hw_value = 10 },
66         { .center_freq = 2462, .hw_value = 11 },
67         { .center_freq = 2467, .hw_value = 12 },
68         { .center_freq = 2472, .hw_value = 13 },
69         { .center_freq = 2484, .hw_value = 14 }
70 };
71
72 static struct ieee80211_channel vnt_channels_5ghz[] = {
73         { .center_freq = 4915, .hw_value = 15 },
74         { .center_freq = 4920, .hw_value = 16 },
75         { .center_freq = 4925, .hw_value = 17 },
76         { .center_freq = 4935, .hw_value = 18 },
77         { .center_freq = 4940, .hw_value = 19 },
78         { .center_freq = 4945, .hw_value = 20 },
79         { .center_freq = 4960, .hw_value = 21 },
80         { .center_freq = 4980, .hw_value = 22 },
81         { .center_freq = 5035, .hw_value = 23 },
82         { .center_freq = 5040, .hw_value = 24 },
83         { .center_freq = 5045, .hw_value = 25 },
84         { .center_freq = 5055, .hw_value = 26 },
85         { .center_freq = 5060, .hw_value = 27 },
86         { .center_freq = 5080, .hw_value = 28 },
87         { .center_freq = 5170, .hw_value = 29 },
88         { .center_freq = 5180, .hw_value = 30 },
89         { .center_freq = 5190, .hw_value = 31 },
90         { .center_freq = 5200, .hw_value = 32 },
91         { .center_freq = 5210, .hw_value = 33 },
92         { .center_freq = 5220, .hw_value = 34 },
93         { .center_freq = 5230, .hw_value = 35 },
94         { .center_freq = 5240, .hw_value = 36 },
95         { .center_freq = 5260, .hw_value = 37 },
96         { .center_freq = 5280, .hw_value = 38 },
97         { .center_freq = 5300, .hw_value = 39 },
98         { .center_freq = 5320, .hw_value = 40 },
99         { .center_freq = 5500, .hw_value = 41 },
100         { .center_freq = 5520, .hw_value = 42 },
101         { .center_freq = 5540, .hw_value = 43 },
102         { .center_freq = 5560, .hw_value = 44 },
103         { .center_freq = 5580, .hw_value = 45 },
104         { .center_freq = 5600, .hw_value = 46 },
105         { .center_freq = 5620, .hw_value = 47 },
106         { .center_freq = 5640, .hw_value = 48 },
107         { .center_freq = 5660, .hw_value = 49 },
108         { .center_freq = 5680, .hw_value = 50 },
109         { .center_freq = 5700, .hw_value = 51 },
110         { .center_freq = 5745, .hw_value = 52 },
111         { .center_freq = 5765, .hw_value = 53 },
112         { .center_freq = 5785, .hw_value = 54 },
113         { .center_freq = 5805, .hw_value = 55 },
114         { .center_freq = 5825, .hw_value = 56 }
115 };
116
117 static struct ieee80211_supported_band vnt_supported_2ghz_band = {
118         .channels = vnt_channels_2ghz,
119         .n_channels = ARRAY_SIZE(vnt_channels_2ghz),
120         .bitrates = vnt_rates_bg,
121         .n_bitrates = ARRAY_SIZE(vnt_rates_bg),
122 };
123
124 static struct ieee80211_supported_band vnt_supported_5ghz_band = {
125         .channels = vnt_channels_5ghz,
126         .n_channels = ARRAY_SIZE(vnt_channels_5ghz),
127         .bitrates = vnt_rates_a,
128         .n_bitrates = ARRAY_SIZE(vnt_rates_a),
129 };
130
131 void vnt_init_bands(struct vnt_private *priv)
132 {
133         struct ieee80211_channel *ch;
134         int i;
135
136         switch (priv->byRFType) {
137         case RF_AIROHA7230:
138         case RF_UW2452:
139         case RF_NOTHING:
140         default:
141                 ch = vnt_channels_5ghz;
142
143                 for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) {
144                         ch[i].max_power = 0x3f;
145                         ch[i].flags = IEEE80211_CHAN_NO_HT40;
146                 }
147
148                 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
149                                                 &vnt_supported_5ghz_band;
150         /* fallthrough */
151         case RF_RFMD2959:
152         case RF_AIROHA:
153         case RF_AL2230S:
154         case RF_UW2451:
155         case RF_VT3226:
156                 ch = vnt_channels_2ghz;
157
158                 for (i = 0; i < ARRAY_SIZE(vnt_channels_2ghz); i++) {
159                         ch[i].max_power = 0x3f;
160                         ch[i].flags = IEEE80211_CHAN_NO_HT40;
161                 }
162
163                 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
164                                                 &vnt_supported_2ghz_band;
165                 break;
166         }
167 }
168
169 /**
170  * is_channel_valid() - Is Country Channel Valid
171  *  @ChanneIndex: defined as VT3253 MAC channel:
172  *              1   = 2.4G channel 1
173  *              2   = 2.4G channel 2
174  *              ...
175  *              14  = 2.4G channel 14
176  *              15  = 4.9G channel 183
177  *              16  = 4.9G channel 184
178  *              .....
179  *  Output: true if the specified 5GHz band is allowed to be used,
180  *          false otherwise.
181  * 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22)
182  *
183  * 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
184  * 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56)
185  */
186
187 bool is_channel_valid(unsigned int ChannelIndex)
188 {
189         bool bValid;
190
191         bValid = false;
192         /* If Channel Index is invalid, return invalid */
193         if ((ChannelIndex > CB_MAX_CHANNEL) ||
194             (ChannelIndex == 0)) {
195                 bValid = false;
196                 goto exit;
197         }
198 exit:
199         return bValid;
200 }
201
202 /**
203  * channel_get_list() - Get Available Channel List for a given country
204  * @CountryCode: The country code defined in country.h
205  *
206  * Output:
207  *      pbyChannelTable:   (QWORD *) correspondent bit mask
208  *                          of available channels
209  *                          0x0000000000000001 means channel 1 is supported
210  *                          0x0000000000000003 means channel 1,2 are supported
211  *                          0x000000000000000F means channel 1,2,..15 are supported
212  */
213
214 bool channel_get_list(unsigned int uCountryCodeIdx, unsigned char *pbyChannelTable)
215 {
216         return true;
217 }
218
219 unsigned char get_channel_mapping(void *pDeviceHandler, unsigned char byChannelNumber, CARD_PHY_TYPE ePhyType)
220 {
221         return 0;
222 }
223
224 unsigned char get_channel_number(void *pDeviceHandler, unsigned char byChannelIndex)
225 {
226         return 0;
227 }
228
229 /**
230  * set_channel() - Set NIC media channel
231  *
232  * @pDeviceHandler: The adapter to be set
233  * @uConnectionChannel: Channel to be set
234  *
235  * Return Value: true if succeeded; false if failed.
236  *
237  */
238 bool set_channel(void *pDeviceHandler, unsigned int uConnectionChannel)
239 {
240         struct vnt_private *pDevice = pDeviceHandler;
241         bool bResult = true;
242
243         if (pDevice->byCurrentCh == uConnectionChannel)
244                 return bResult;
245
246         /* clear NAV */
247         MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MACCR, MACCR_CLRNAV);
248
249         /* TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput */
250
251         if (pDevice->byRFType == RF_AIROHA7230)
252                 RFbAL7230SelectChannelPostProcess(pDevice->PortOffset, pDevice->byCurrentCh, (unsigned char)uConnectionChannel);
253
254         pDevice->byCurrentCh = (unsigned char)uConnectionChannel;
255         bResult &= RFbSelectChannel(pDevice->PortOffset, pDevice->byRFType, (unsigned char)uConnectionChannel);
256
257         /* Init Synthesizer Table */
258         if (pDevice->bEnablePSMode)
259                 RFvWriteWakeProgSyn(pDevice->PortOffset, pDevice->byRFType, uConnectionChannel);
260
261         BBvSoftwareReset(pDevice->PortOffset);
262
263         if (pDevice->byLocalID > REV_ID_VT3253_B1) {
264                 /* set HW default power register */
265                 MACvSelectPage1(pDevice->PortOffset);
266                 RFbSetPower(pDevice, RATE_1M, pDevice->byCurrentCh);
267                 VNSvOutPortB(pDevice->PortOffset + MAC_REG_PWRCCK, pDevice->byCurPwr);
268                 RFbSetPower(pDevice, RATE_6M, pDevice->byCurrentCh);
269                 VNSvOutPortB(pDevice->PortOffset + MAC_REG_PWROFDM, pDevice->byCurPwr);
270                 MACvSelectPage0(pDevice->PortOffset);
271         }
272
273         if (pDevice->byBBType == BB_TYPE_11B)
274                 RFbSetPower(pDevice, RATE_1M, pDevice->byCurrentCh);
275         else
276                 RFbSetPower(pDevice, RATE_6M, pDevice->byCurrentCh);
277
278         return bResult;
279 }
280
281 /**
282  * set_country_info() - Set Channel Info of Country
283  *
284  * Return Value: none.
285  *
286  */
287
288 void set_country_info(void *pDeviceHandler, CARD_PHY_TYPE ePHYType, void *pIE)
289 {
290 }
291
292 /**
293  *
294  * set_support_channels() - Set Support Channels IE defined in 802.11h
295  *
296  * @hDeviceContext: device structure point
297  *
298  * Return Value: none.
299  *
300  */
301
302 unsigned char set_support_channels(void *pDeviceHandler, unsigned char *pbyIEs)
303 {
304         unsigned char byLen = 0;
305         return byLen;
306 }
307
308 void set_country_IE(void *pDeviceHandler, void *pIE)
309 {
310 }
311
312 bool get_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex,
313                           unsigned char *pbyChannelNumber, unsigned char *pbyMap)
314 {
315         return 0;
316 }
317
318 void set_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex,
319                           unsigned char byMap)
320 {
321 }
322
323 void clear_channel_map_info(void *pDeviceHandler)
324 {
325
326 }
327
328 unsigned char auto_channel_select(void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
329 {
330         unsigned char byOptionChannel = 0;
331         return byOptionChannel;
332 }