xref: /openbmc/linux/drivers/staging/vt6656/channel.c (revision 6b4c6ce8)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
4  * All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  *
17  * File: channel.c
18  *
19  * Purpose: Channel number mapping
20  *
21  * Author: Lucas Lin
22  *
23  * Date: Dec 24, 2004
24  *
25  *
26  *
27  * Revision History:
28  *	01-18-2005	RobertYu:	remove the for loop searching in
29  *					ChannelValid, change ChannelRuleTab
30  *					to lookup-type, reorder table items.
31  *
32  *
33  */
34 
35 #include "device.h"
36 #include "channel.h"
37 #include "rf.h"
38 
39 static struct ieee80211_rate vnt_rates_bg[] = {
40 	{ .bitrate = 10,  .hw_value = RATE_1M },
41 	{ .bitrate = 20,  .hw_value = RATE_2M },
42 	{ .bitrate = 55,  .hw_value = RATE_5M },
43 	{ .bitrate = 110, .hw_value = RATE_11M },
44 	{ .bitrate = 60,  .hw_value = RATE_6M },
45 	{ .bitrate = 90,  .hw_value = RATE_9M },
46 	{ .bitrate = 120, .hw_value = RATE_12M },
47 	{ .bitrate = 180, .hw_value = RATE_18M },
48 	{ .bitrate = 240, .hw_value = RATE_24M },
49 	{ .bitrate = 360, .hw_value = RATE_36M },
50 	{ .bitrate = 480, .hw_value = RATE_48M },
51 	{ .bitrate = 540, .hw_value = RATE_54M },
52 };
53 
54 static struct ieee80211_rate vnt_rates_a[] = {
55 	{ .bitrate = 60,  .hw_value = RATE_6M },
56 	{ .bitrate = 90,  .hw_value = RATE_9M },
57 	{ .bitrate = 120, .hw_value = RATE_12M },
58 	{ .bitrate = 180, .hw_value = RATE_18M },
59 	{ .bitrate = 240, .hw_value = RATE_24M },
60 	{ .bitrate = 360, .hw_value = RATE_36M },
61 	{ .bitrate = 480, .hw_value = RATE_48M },
62 	{ .bitrate = 540, .hw_value = RATE_54M },
63 };
64 
65 static struct ieee80211_channel vnt_channels_2ghz[] = {
66 	{ .center_freq = 2412, .hw_value = 1 },
67 	{ .center_freq = 2417, .hw_value = 2 },
68 	{ .center_freq = 2422, .hw_value = 3 },
69 	{ .center_freq = 2427, .hw_value = 4 },
70 	{ .center_freq = 2432, .hw_value = 5 },
71 	{ .center_freq = 2437, .hw_value = 6 },
72 	{ .center_freq = 2442, .hw_value = 7 },
73 	{ .center_freq = 2447, .hw_value = 8 },
74 	{ .center_freq = 2452, .hw_value = 9 },
75 	{ .center_freq = 2457, .hw_value = 10 },
76 	{ .center_freq = 2462, .hw_value = 11 },
77 	{ .center_freq = 2467, .hw_value = 12 },
78 	{ .center_freq = 2472, .hw_value = 13 },
79 	{ .center_freq = 2484, .hw_value = 14 }
80 };
81 
82 static struct ieee80211_channel vnt_channels_5ghz[] = {
83 	{ .center_freq = 4915, .hw_value = 15 },
84 	{ .center_freq = 4920, .hw_value = 16 },
85 	{ .center_freq = 4925, .hw_value = 17 },
86 	{ .center_freq = 4935, .hw_value = 18 },
87 	{ .center_freq = 4940, .hw_value = 19 },
88 	{ .center_freq = 4945, .hw_value = 20 },
89 	{ .center_freq = 4960, .hw_value = 21 },
90 	{ .center_freq = 4980, .hw_value = 22 },
91 	{ .center_freq = 5035, .hw_value = 23 },
92 	{ .center_freq = 5040, .hw_value = 24 },
93 	{ .center_freq = 5045, .hw_value = 25 },
94 	{ .center_freq = 5055, .hw_value = 26 },
95 	{ .center_freq = 5060, .hw_value = 27 },
96 	{ .center_freq = 5080, .hw_value = 28 },
97 	{ .center_freq = 5170, .hw_value = 29 },
98 	{ .center_freq = 5180, .hw_value = 30 },
99 	{ .center_freq = 5190, .hw_value = 31 },
100 	{ .center_freq = 5200, .hw_value = 32 },
101 	{ .center_freq = 5210, .hw_value = 33 },
102 	{ .center_freq = 5220, .hw_value = 34 },
103 	{ .center_freq = 5230, .hw_value = 35 },
104 	{ .center_freq = 5240, .hw_value = 36 },
105 	{ .center_freq = 5260, .hw_value = 37 },
106 	{ .center_freq = 5280, .hw_value = 38 },
107 	{ .center_freq = 5300, .hw_value = 39 },
108 	{ .center_freq = 5320, .hw_value = 40 },
109 	{ .center_freq = 5500, .hw_value = 41 },
110 	{ .center_freq = 5520, .hw_value = 42 },
111 	{ .center_freq = 5540, .hw_value = 43 },
112 	{ .center_freq = 5560, .hw_value = 44 },
113 	{ .center_freq = 5580, .hw_value = 45 },
114 	{ .center_freq = 5600, .hw_value = 46 },
115 	{ .center_freq = 5620, .hw_value = 47 },
116 	{ .center_freq = 5640, .hw_value = 48 },
117 	{ .center_freq = 5660, .hw_value = 49 },
118 	{ .center_freq = 5680, .hw_value = 50 },
119 	{ .center_freq = 5700, .hw_value = 51 },
120 	{ .center_freq = 5745, .hw_value = 52 },
121 	{ .center_freq = 5765, .hw_value = 53 },
122 	{ .center_freq = 5785, .hw_value = 54 },
123 	{ .center_freq = 5805, .hw_value = 55 },
124 	{ .center_freq = 5825, .hw_value = 56 }
125 };
126 
127 static struct ieee80211_supported_band vnt_supported_2ghz_band = {
128 	.channels = vnt_channels_2ghz,
129 	.n_channels = ARRAY_SIZE(vnt_channels_2ghz),
130 	.bitrates = vnt_rates_bg,
131 	.n_bitrates = ARRAY_SIZE(vnt_rates_bg),
132 };
133 
134 static struct ieee80211_supported_band vnt_supported_5ghz_band = {
135 	.channels = vnt_channels_5ghz,
136 	.n_channels = ARRAY_SIZE(vnt_channels_5ghz),
137 	.bitrates = vnt_rates_a,
138 	.n_bitrates = ARRAY_SIZE(vnt_rates_a),
139 };
140 
141 void vnt_init_bands(struct vnt_private *priv)
142 {
143 	struct ieee80211_channel *ch;
144 	int i;
145 
146 	switch (priv->rf_type) {
147 	case RF_AIROHA7230:
148 	case RF_VT3342A0:
149 	default:
150 		ch = vnt_channels_5ghz;
151 
152 		for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) {
153 			ch[i].max_power = VNT_RF_MAX_POWER;
154 			ch[i].flags = IEEE80211_CHAN_NO_HT40;
155 		}
156 
157 		priv->hw->wiphy->bands[NL80211_BAND_5GHZ] =
158 						&vnt_supported_5ghz_band;
159 	/* fallthrough */
160 	case RF_AL2230:
161 	case RF_AL2230S:
162 	case RF_VT3226:
163 	case RF_VT3226D0:
164 		ch = vnt_channels_2ghz;
165 
166 		for (i = 0; i < ARRAY_SIZE(vnt_channels_2ghz); i++) {
167 			ch[i].max_power = VNT_RF_MAX_POWER;
168 			ch[i].flags = IEEE80211_CHAN_NO_HT40;
169 		}
170 
171 		priv->hw->wiphy->bands[NL80211_BAND_2GHZ] =
172 						&vnt_supported_2ghz_band;
173 		break;
174 	}
175 }
176