xref: /openbmc/linux/drivers/staging/vt6656/channel.c (revision 9ef2184d)
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  *
20  * File: channel.c
21  *
22  * Purpose: Channel number mapping
23  *
24  * Author: Lucas Lin
25  *
26  * Date: Dec 24, 2004
27  *
28  *
29  *
30  * Revision History:
31  *      01-18-2005      RobertYu:  remove the for loop searching in ChannelValid,
32  *                                 change ChannelRuleTab to lookup-type, reorder table items.
33  *
34  *
35  */
36 
37 #include <linux/kernel.h>
38 #include "device.h"
39 #include "datarate.h"
40 #include "channel.h"
41 #include "rf.h"
42 
43 static SChannelTblElement sChannelTbl[CB_MAX_CHANNEL+1] =
44 {
45   {0,   0,    false},
46   {1,   2412, true},
47   {2,   2417, true},
48   {3,   2422, true},
49   {4,   2427, true},
50   {5,   2432, true},
51   {6,   2437, true},
52   {7,   2442, true},
53   {8,   2447, true},
54   {9,   2452, true},
55   {10,  2457, true},
56   {11,  2462, true},
57   {12,  2467, true},
58   {13,  2472, true},
59   {14,  2484, true},
60   {183, 4915, true}, //15
61   {184, 4920, true}, //16
62   {185, 4925, true}, //17
63   {187, 4935, true}, //18
64   {188, 4940, true}, //19
65   {189, 4945, true}, //20
66   {192, 4960, true}, //21
67   {196, 4980, true}, //22
68   {7,   5035, true}, //23
69   {8,   5040, true}, //24
70   {9,   5045, true}, //25
71   {11,  5055, true}, //26
72   {12,  5060, true}, //27
73   {16,  5080, true}, //28
74   {34,  5170, true}, //29
75   {36,  5180, true}, //30
76   {38,  5190, true}, //31
77   {40,  5200, true}, //32
78   {42,  5210, true}, //33
79   {44,  5220, true}, //34
80   {46,  5230, true}, //35
81   {48,  5240, true}, //36
82   {52,  5260, true}, //37
83   {56,  5280, true}, //38
84   {60,  5300, true}, //39
85   {64,  5320, true}, //40
86   {100, 5500, true}, //41
87   {104, 5520, true}, //42
88   {108, 5540, true}, //43
89   {112, 5560, true}, //44
90   {116, 5580, true}, //45
91   {120, 5600, true}, //46
92   {124, 5620, true}, //47
93   {128, 5640, true}, //48
94   {132, 5660, true}, //49
95   {136, 5680, true}, //50
96   {140, 5700, true}, //51
97   {149, 5745, true}, //52
98   {153, 5765, true}, //53
99   {157, 5785, true}, //54
100   {161, 5805, true}, //55
101   {165, 5825, true}  //56
102 };
103 
104 
105 /************************************************************************
106  * Country Channel Valid
107  *  Input:  CountryCode, ChannelNum
108  *          ChanneIndex is defined as VT3253 MAC channel:
109  *              1   = 2.4G channel 1
110  *              2   = 2.4G channel 2
111  *              ...
112  *              14  = 2.4G channel 14
113  *              15  = 4.9G channel 183
114  *              16  = 4.9G channel 184
115  *              .....
116  *  Output: true if the specified 5GHz band is allowed to be used.
117             False otherwise.
118 // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22)
119 
120 // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
121 // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56)
122  ************************************************************************/
123 bool
124 ChannelValid(unsigned int CountryCode, unsigned int ChannelIndex)
125 {
126     bool    bValid;
127 
128     bValid = false;
129     /*
130      * If Channel Index is invalid, return invalid
131      */
132     if ((ChannelIndex > CB_MAX_CHANNEL) ||
133         (ChannelIndex == 0))
134     {
135         bValid = false;
136         goto exit;
137     }
138 
139     bValid = sChannelTbl[ChannelIndex].bValid;
140 
141 exit:
142     return (bValid);
143 
144 } /* end ChannelValid */
145 
146 void CHvInitChannelTable(struct vnt_private *pDevice)
147 {
148 	bool bMultiBand = false;
149 	int ii;
150 
151     for (ii = 1; ii <= CB_MAX_CHANNEL; ii++)
152 	sChannelTbl[ii].bValid = false;
153 
154     switch (pDevice->byRFType) {
155         case RF_AL2230:
156         case RF_AL2230S:
157         case RF_VT3226:
158         case RF_VT3226D0:
159             bMultiBand = false;
160             break;
161         case RF_AIROHA7230:
162         case RF_VT3342A0:
163         default :
164             bMultiBand = true;
165             break;
166     }
167 
168         if (bMultiBand == true) {
169 		for (ii = 0; ii < CB_MAX_CHANNEL; ii++) {
170 			sChannelTbl[ii+1].bValid = true;
171 		}
172         } else {
173 		for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
174 			sChannelTbl[ii+1].bValid = true;
175 		}
176         }
177 }
178 
179 static struct ieee80211_rate vnt_rates_bg[] = {
180 	{ .bitrate = 10,  .hw_value = RATE_1M },
181 	{ .bitrate = 20,  .hw_value = RATE_2M },
182 	{ .bitrate = 55,  .hw_value = RATE_5M },
183 	{ .bitrate = 110, .hw_value = RATE_11M },
184 	{ .bitrate = 60,  .hw_value = RATE_6M },
185 	{ .bitrate = 90,  .hw_value = RATE_9M },
186 	{ .bitrate = 120, .hw_value = RATE_12M },
187 	{ .bitrate = 180, .hw_value = RATE_18M },
188 	{ .bitrate = 240, .hw_value = RATE_24M },
189 	{ .bitrate = 360, .hw_value = RATE_36M },
190 	{ .bitrate = 480, .hw_value = RATE_48M },
191 	{ .bitrate = 540, .hw_value = RATE_54M },
192 };
193 
194 static struct ieee80211_rate vnt_rates_a[] = {
195 	{ .bitrate = 60,  .hw_value = RATE_6M },
196 	{ .bitrate = 90,  .hw_value = RATE_9M },
197 	{ .bitrate = 120, .hw_value = RATE_12M },
198 	{ .bitrate = 180, .hw_value = RATE_18M },
199 	{ .bitrate = 240, .hw_value = RATE_24M },
200 	{ .bitrate = 360, .hw_value = RATE_36M },
201 	{ .bitrate = 480, .hw_value = RATE_48M },
202 	{ .bitrate = 540, .hw_value = RATE_54M },
203 };
204 
205 static struct ieee80211_channel vnt_channels_2ghz[] = {
206 	{ .center_freq = 2412, .hw_value = 1 },
207 	{ .center_freq = 2417, .hw_value = 2 },
208 	{ .center_freq = 2422, .hw_value = 3 },
209 	{ .center_freq = 2427, .hw_value = 4 },
210 	{ .center_freq = 2432, .hw_value = 5 },
211 	{ .center_freq = 2437, .hw_value = 6 },
212 	{ .center_freq = 2442, .hw_value = 7 },
213 	{ .center_freq = 2447, .hw_value = 8 },
214 	{ .center_freq = 2452, .hw_value = 9 },
215 	{ .center_freq = 2457, .hw_value = 10 },
216 	{ .center_freq = 2462, .hw_value = 11 },
217 	{ .center_freq = 2467, .hw_value = 12 },
218 	{ .center_freq = 2472, .hw_value = 13 },
219 	{ .center_freq = 2484, .hw_value = 14 }
220 };
221 
222 static struct ieee80211_channel vnt_channels_5ghz[] = {
223 	{ .center_freq = 4915, .hw_value = 15 },
224 	{ .center_freq = 4920, .hw_value = 16 },
225 	{ .center_freq = 4925, .hw_value = 17 },
226 	{ .center_freq = 4935, .hw_value = 18 },
227 	{ .center_freq = 4940, .hw_value = 19 },
228 	{ .center_freq = 4945, .hw_value = 20 },
229 	{ .center_freq = 4960, .hw_value = 21 },
230 	{ .center_freq = 4980, .hw_value = 22 },
231 	{ .center_freq = 5035, .hw_value = 23 },
232 	{ .center_freq = 5040, .hw_value = 24 },
233 	{ .center_freq = 5045, .hw_value = 25 },
234 	{ .center_freq = 5055, .hw_value = 26 },
235 	{ .center_freq = 5060, .hw_value = 27 },
236 	{ .center_freq = 5080, .hw_value = 28 },
237 	{ .center_freq = 5170, .hw_value = 29 },
238 	{ .center_freq = 5180, .hw_value = 30 },
239 	{ .center_freq = 5190, .hw_value = 31 },
240 	{ .center_freq = 5200, .hw_value = 32 },
241 	{ .center_freq = 5210, .hw_value = 33 },
242 	{ .center_freq = 5220, .hw_value = 34 },
243 	{ .center_freq = 5230, .hw_value = 35 },
244 	{ .center_freq = 5240, .hw_value = 36 },
245 	{ .center_freq = 5260, .hw_value = 37 },
246 	{ .center_freq = 5280, .hw_value = 38 },
247 	{ .center_freq = 5300, .hw_value = 39 },
248 	{ .center_freq = 5320, .hw_value = 40 },
249 	{ .center_freq = 5500, .hw_value = 41 },
250 	{ .center_freq = 5520, .hw_value = 42 },
251 	{ .center_freq = 5540, .hw_value = 43 },
252 	{ .center_freq = 5560, .hw_value = 44 },
253 	{ .center_freq = 5580, .hw_value = 45 },
254 	{ .center_freq = 5600, .hw_value = 46 },
255 	{ .center_freq = 5620, .hw_value = 47 },
256 	{ .center_freq = 5640, .hw_value = 48 },
257 	{ .center_freq = 5660, .hw_value = 49 },
258 	{ .center_freq = 5680, .hw_value = 50 },
259 	{ .center_freq = 5700, .hw_value = 51 },
260 	{ .center_freq = 5745, .hw_value = 52 },
261 	{ .center_freq = 5765, .hw_value = 53 },
262 	{ .center_freq = 5785, .hw_value = 54 },
263 	{ .center_freq = 5805, .hw_value = 55 },
264 	{ .center_freq = 5825, .hw_value = 56 }
265 };
266 
267 static struct ieee80211_supported_band vnt_supported_2ghz_band = {
268 	.channels = vnt_channels_2ghz,
269 	.n_channels = ARRAY_SIZE(vnt_channels_2ghz),
270 	.bitrates = vnt_rates_bg,
271 	.n_bitrates = ARRAY_SIZE(vnt_rates_bg),
272 };
273 
274 static struct ieee80211_supported_band vnt_supported_5ghz_band = {
275 	.channels = vnt_channels_5ghz,
276 	.n_channels = ARRAY_SIZE(vnt_channels_5ghz),
277 	.bitrates = vnt_rates_a,
278 	.n_bitrates = ARRAY_SIZE(vnt_rates_a),
279 };
280 
281 void vnt_init_bands(struct vnt_private *priv)
282 {
283 	struct ieee80211_channel *ch;
284 	int i;
285 
286 	switch (priv->byRFType) {
287 	case RF_AIROHA7230:
288 	case RF_VT3342A0:
289 		ch = vnt_channels_5ghz;
290 
291 		for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) {
292 			ch[i].max_power = VNT_RF_MAX_POWER;
293 			ch[i].flags = IEEE80211_CHAN_NO_HT40;
294 		}
295 
296 		priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
297 						&vnt_supported_5ghz_band;
298 	/* fallthrough */
299 	case RF_AL2230:
300 	case RF_AL2230S:
301 	case RF_VT3226:
302 	case RF_VT3226D0:
303 		ch = vnt_channels_2ghz;
304 
305 		for (i = 0; i < ARRAY_SIZE(vnt_channels_2ghz); i++) {
306 			ch[i].max_power = VNT_RF_MAX_POWER;
307 			ch[i].flags = IEEE80211_CHAN_NO_HT40;
308 		}
309 
310 		priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
311 						&vnt_supported_2ghz_band;
312 		break;
313 	}
314 }
315