xref: /openbmc/linux/drivers/staging/vt6655/channel.c (revision 8dda2eac)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
4  * All rights reserved.
5  *
6  * File: channel.c
7  *
8  */
9 
10 #include "baseband.h"
11 #include "channel.h"
12 #include "device.h"
13 #include "rf.h"
14 
15 static struct ieee80211_rate vnt_rates_bg[] = {
16 	{ .bitrate = 10,  .hw_value = RATE_1M },
17 	{ .bitrate = 20,  .hw_value = RATE_2M },
18 	{ .bitrate = 55,  .hw_value = RATE_5M },
19 	{ .bitrate = 110, .hw_value = RATE_11M },
20 	{ .bitrate = 60,  .hw_value = RATE_6M },
21 	{ .bitrate = 90,  .hw_value = RATE_9M },
22 	{ .bitrate = 120, .hw_value = RATE_12M },
23 	{ .bitrate = 180, .hw_value = RATE_18M },
24 	{ .bitrate = 240, .hw_value = RATE_24M },
25 	{ .bitrate = 360, .hw_value = RATE_36M },
26 	{ .bitrate = 480, .hw_value = RATE_48M },
27 	{ .bitrate = 540, .hw_value = RATE_54M },
28 };
29 
30 static struct ieee80211_rate vnt_rates_a[] = {
31 	{ .bitrate = 60,  .hw_value = RATE_6M },
32 	{ .bitrate = 90,  .hw_value = RATE_9M },
33 	{ .bitrate = 120, .hw_value = RATE_12M },
34 	{ .bitrate = 180, .hw_value = RATE_18M },
35 	{ .bitrate = 240, .hw_value = RATE_24M },
36 	{ .bitrate = 360, .hw_value = RATE_36M },
37 	{ .bitrate = 480, .hw_value = RATE_48M },
38 	{ .bitrate = 540, .hw_value = RATE_54M },
39 };
40 
41 static struct ieee80211_channel vnt_channels_2ghz[] = {
42 	{ .center_freq = 2412, .hw_value = 1 },
43 	{ .center_freq = 2417, .hw_value = 2 },
44 	{ .center_freq = 2422, .hw_value = 3 },
45 	{ .center_freq = 2427, .hw_value = 4 },
46 	{ .center_freq = 2432, .hw_value = 5 },
47 	{ .center_freq = 2437, .hw_value = 6 },
48 	{ .center_freq = 2442, .hw_value = 7 },
49 	{ .center_freq = 2447, .hw_value = 8 },
50 	{ .center_freq = 2452, .hw_value = 9 },
51 	{ .center_freq = 2457, .hw_value = 10 },
52 	{ .center_freq = 2462, .hw_value = 11 },
53 	{ .center_freq = 2467, .hw_value = 12 },
54 	{ .center_freq = 2472, .hw_value = 13 },
55 	{ .center_freq = 2484, .hw_value = 14 }
56 };
57 
58 static struct ieee80211_channel vnt_channels_5ghz[] = {
59 	{ .center_freq = 4915, .hw_value = 15 },
60 	{ .center_freq = 4920, .hw_value = 16 },
61 	{ .center_freq = 4925, .hw_value = 17 },
62 	{ .center_freq = 4935, .hw_value = 18 },
63 	{ .center_freq = 4940, .hw_value = 19 },
64 	{ .center_freq = 4945, .hw_value = 20 },
65 	{ .center_freq = 4960, .hw_value = 21 },
66 	{ .center_freq = 4980, .hw_value = 22 },
67 	{ .center_freq = 5035, .hw_value = 23 },
68 	{ .center_freq = 5040, .hw_value = 24 },
69 	{ .center_freq = 5045, .hw_value = 25 },
70 	{ .center_freq = 5055, .hw_value = 26 },
71 	{ .center_freq = 5060, .hw_value = 27 },
72 	{ .center_freq = 5080, .hw_value = 28 },
73 	{ .center_freq = 5170, .hw_value = 29 },
74 	{ .center_freq = 5180, .hw_value = 30 },
75 	{ .center_freq = 5190, .hw_value = 31 },
76 	{ .center_freq = 5200, .hw_value = 32 },
77 	{ .center_freq = 5210, .hw_value = 33 },
78 	{ .center_freq = 5220, .hw_value = 34 },
79 	{ .center_freq = 5230, .hw_value = 35 },
80 	{ .center_freq = 5240, .hw_value = 36 },
81 	{ .center_freq = 5260, .hw_value = 37 },
82 	{ .center_freq = 5280, .hw_value = 38 },
83 	{ .center_freq = 5300, .hw_value = 39 },
84 	{ .center_freq = 5320, .hw_value = 40 },
85 	{ .center_freq = 5500, .hw_value = 41 },
86 	{ .center_freq = 5520, .hw_value = 42 },
87 	{ .center_freq = 5540, .hw_value = 43 },
88 	{ .center_freq = 5560, .hw_value = 44 },
89 	{ .center_freq = 5580, .hw_value = 45 },
90 	{ .center_freq = 5600, .hw_value = 46 },
91 	{ .center_freq = 5620, .hw_value = 47 },
92 	{ .center_freq = 5640, .hw_value = 48 },
93 	{ .center_freq = 5660, .hw_value = 49 },
94 	{ .center_freq = 5680, .hw_value = 50 },
95 	{ .center_freq = 5700, .hw_value = 51 },
96 	{ .center_freq = 5745, .hw_value = 52 },
97 	{ .center_freq = 5765, .hw_value = 53 },
98 	{ .center_freq = 5785, .hw_value = 54 },
99 	{ .center_freq = 5805, .hw_value = 55 },
100 	{ .center_freq = 5825, .hw_value = 56 }
101 };
102 
103 static struct ieee80211_supported_band vnt_supported_2ghz_band = {
104 	.channels = vnt_channels_2ghz,
105 	.n_channels = ARRAY_SIZE(vnt_channels_2ghz),
106 	.bitrates = vnt_rates_bg,
107 	.n_bitrates = ARRAY_SIZE(vnt_rates_bg),
108 };
109 
110 static struct ieee80211_supported_band vnt_supported_5ghz_band = {
111 	.channels = vnt_channels_5ghz,
112 	.n_channels = ARRAY_SIZE(vnt_channels_5ghz),
113 	.bitrates = vnt_rates_a,
114 	.n_bitrates = ARRAY_SIZE(vnt_rates_a),
115 };
116 
117 static void vnt_init_band(struct vnt_private *priv,
118 			  struct ieee80211_supported_band *supported_band,
119 			  enum nl80211_band band)
120 {
121 	int i;
122 
123 	for (i = 0; i < supported_band->n_channels; i++) {
124 		supported_band->channels[i].max_power = 0x3f;
125 		supported_band->channels[i].flags =
126 			IEEE80211_CHAN_NO_HT40;
127 	}
128 
129 	priv->hw->wiphy->bands[band] = supported_band;
130 }
131 
132 void vnt_init_bands(struct vnt_private *priv)
133 {
134 	switch (priv->byRFType) {
135 	case RF_AIROHA7230:
136 	case RF_UW2452:
137 	case RF_NOTHING:
138 	default:
139 		vnt_init_band(priv, &vnt_supported_5ghz_band,
140 			      NL80211_BAND_5GHZ);
141 		fallthrough;
142 	case RF_RFMD2959:
143 	case RF_AIROHA:
144 	case RF_AL2230S:
145 	case RF_UW2451:
146 	case RF_VT3226:
147 		vnt_init_band(priv, &vnt_supported_2ghz_band,
148 			      NL80211_BAND_2GHZ);
149 		break;
150 	}
151 }
152 
153 /**
154  * set_channel() - Set NIC media channel
155  *
156  * @priv: The adapter to be set
157  * @ch: Channel to be set
158  *
159  * Return Value: true if succeeded; false if failed.
160  *
161  */
162 bool set_channel(struct vnt_private *priv, struct ieee80211_channel *ch)
163 {
164 	bool ret = true;
165 
166 	if (priv->byCurrentCh == ch->hw_value)
167 		return ret;
168 
169 	/* Set VGA to max sensitivity */
170 	if (priv->bUpdateBBVGA &&
171 	    priv->byBBVGACurrent != priv->abyBBVGA[0]) {
172 		priv->byBBVGACurrent = priv->abyBBVGA[0];
173 
174 		bb_set_vga_gain_offset(priv, priv->byBBVGACurrent);
175 	}
176 
177 	/* clear NAV */
178 	MACvRegBitsOn(priv->PortOffset, MAC_REG_MACCR, MACCR_CLRNAV);
179 
180 	/* TX_PE will reserve 3 us for MAX2829 A mode only,
181 	 * it is for better TX throughput
182 	 */
183 
184 	if (priv->byRFType == RF_AIROHA7230)
185 		RFbAL7230SelectChannelPostProcess(priv, priv->byCurrentCh,
186 						  ch->hw_value);
187 
188 	priv->byCurrentCh = ch->hw_value;
189 	ret &= RFbSelectChannel(priv, priv->byRFType,
190 				ch->hw_value);
191 
192 	/* Init Synthesizer Table */
193 	if (priv->bEnablePSMode)
194 		RFvWriteWakeProgSyn(priv, priv->byRFType, ch->hw_value);
195 
196 	bb_software_reset(priv);
197 
198 	if (priv->byLocalID > REV_ID_VT3253_B1) {
199 		unsigned long flags;
200 
201 		spin_lock_irqsave(&priv->lock, flags);
202 
203 		/* set HW default power register */
204 		MACvSelectPage1(priv->PortOffset);
205 		RFbSetPower(priv, RATE_1M, priv->byCurrentCh);
206 		VNSvOutPortB(priv->PortOffset + MAC_REG_PWRCCK,
207 			     priv->byCurPwr);
208 		RFbSetPower(priv, RATE_6M, priv->byCurrentCh);
209 		VNSvOutPortB(priv->PortOffset + MAC_REG_PWROFDM,
210 			     priv->byCurPwr);
211 		MACvSelectPage0(priv->PortOffset);
212 
213 		spin_unlock_irqrestore(&priv->lock, flags);
214 	}
215 
216 	if (priv->byBBType == BB_TYPE_11B)
217 		RFbSetPower(priv, RATE_1M, priv->byCurrentCh);
218 	else
219 		RFbSetPower(priv, RATE_6M, priv->byCurrentCh);
220 
221 	return ret;
222 }
223