Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 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" |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 24 | #include "channel.h" |
| 25 | #include "device.h" |
| 26 | #include "rf.h" |
| 27 | |
Malcolm Priestley | 3d75b9e | 2014-10-29 17:43:44 +0000 | [diff] [blame] | 28 | static struct ieee80211_rate vnt_rates_bg[] = { |
| 29 | { .bitrate = 10, .hw_value = RATE_1M }, |
| 30 | { .bitrate = 20, .hw_value = RATE_2M }, |
| 31 | { .bitrate = 55, .hw_value = RATE_5M }, |
| 32 | { .bitrate = 110, .hw_value = RATE_11M }, |
| 33 | { .bitrate = 60, .hw_value = RATE_6M }, |
| 34 | { .bitrate = 90, .hw_value = RATE_9M }, |
| 35 | { .bitrate = 120, .hw_value = RATE_12M }, |
| 36 | { .bitrate = 180, .hw_value = RATE_18M }, |
| 37 | { .bitrate = 240, .hw_value = RATE_24M }, |
| 38 | { .bitrate = 360, .hw_value = RATE_36M }, |
| 39 | { .bitrate = 480, .hw_value = RATE_48M }, |
| 40 | { .bitrate = 540, .hw_value = RATE_54M }, |
| 41 | }; |
| 42 | |
| 43 | static struct ieee80211_rate vnt_rates_a[] = { |
| 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_channel vnt_channels_2ghz[] = { |
| 55 | { .center_freq = 2412, .hw_value = 1 }, |
| 56 | { .center_freq = 2417, .hw_value = 2 }, |
| 57 | { .center_freq = 2422, .hw_value = 3 }, |
| 58 | { .center_freq = 2427, .hw_value = 4 }, |
| 59 | { .center_freq = 2432, .hw_value = 5 }, |
| 60 | { .center_freq = 2437, .hw_value = 6 }, |
| 61 | { .center_freq = 2442, .hw_value = 7 }, |
| 62 | { .center_freq = 2447, .hw_value = 8 }, |
| 63 | { .center_freq = 2452, .hw_value = 9 }, |
| 64 | { .center_freq = 2457, .hw_value = 10 }, |
| 65 | { .center_freq = 2462, .hw_value = 11 }, |
| 66 | { .center_freq = 2467, .hw_value = 12 }, |
| 67 | { .center_freq = 2472, .hw_value = 13 }, |
| 68 | { .center_freq = 2484, .hw_value = 14 } |
| 69 | }; |
| 70 | |
| 71 | static struct ieee80211_channel vnt_channels_5ghz[] = { |
| 72 | { .center_freq = 4915, .hw_value = 15 }, |
| 73 | { .center_freq = 4920, .hw_value = 16 }, |
| 74 | { .center_freq = 4925, .hw_value = 17 }, |
| 75 | { .center_freq = 4935, .hw_value = 18 }, |
| 76 | { .center_freq = 4940, .hw_value = 19 }, |
| 77 | { .center_freq = 4945, .hw_value = 20 }, |
| 78 | { .center_freq = 4960, .hw_value = 21 }, |
| 79 | { .center_freq = 4980, .hw_value = 22 }, |
| 80 | { .center_freq = 5035, .hw_value = 23 }, |
| 81 | { .center_freq = 5040, .hw_value = 24 }, |
| 82 | { .center_freq = 5045, .hw_value = 25 }, |
| 83 | { .center_freq = 5055, .hw_value = 26 }, |
| 84 | { .center_freq = 5060, .hw_value = 27 }, |
| 85 | { .center_freq = 5080, .hw_value = 28 }, |
| 86 | { .center_freq = 5170, .hw_value = 29 }, |
| 87 | { .center_freq = 5180, .hw_value = 30 }, |
| 88 | { .center_freq = 5190, .hw_value = 31 }, |
| 89 | { .center_freq = 5200, .hw_value = 32 }, |
| 90 | { .center_freq = 5210, .hw_value = 33 }, |
| 91 | { .center_freq = 5220, .hw_value = 34 }, |
| 92 | { .center_freq = 5230, .hw_value = 35 }, |
| 93 | { .center_freq = 5240, .hw_value = 36 }, |
| 94 | { .center_freq = 5260, .hw_value = 37 }, |
| 95 | { .center_freq = 5280, .hw_value = 38 }, |
| 96 | { .center_freq = 5300, .hw_value = 39 }, |
| 97 | { .center_freq = 5320, .hw_value = 40 }, |
| 98 | { .center_freq = 5500, .hw_value = 41 }, |
| 99 | { .center_freq = 5520, .hw_value = 42 }, |
| 100 | { .center_freq = 5540, .hw_value = 43 }, |
| 101 | { .center_freq = 5560, .hw_value = 44 }, |
| 102 | { .center_freq = 5580, .hw_value = 45 }, |
| 103 | { .center_freq = 5600, .hw_value = 46 }, |
| 104 | { .center_freq = 5620, .hw_value = 47 }, |
| 105 | { .center_freq = 5640, .hw_value = 48 }, |
| 106 | { .center_freq = 5660, .hw_value = 49 }, |
| 107 | { .center_freq = 5680, .hw_value = 50 }, |
| 108 | { .center_freq = 5700, .hw_value = 51 }, |
| 109 | { .center_freq = 5745, .hw_value = 52 }, |
| 110 | { .center_freq = 5765, .hw_value = 53 }, |
| 111 | { .center_freq = 5785, .hw_value = 54 }, |
| 112 | { .center_freq = 5805, .hw_value = 55 }, |
| 113 | { .center_freq = 5825, .hw_value = 56 } |
| 114 | }; |
| 115 | |
| 116 | static struct ieee80211_supported_band vnt_supported_2ghz_band = { |
| 117 | .channels = vnt_channels_2ghz, |
| 118 | .n_channels = ARRAY_SIZE(vnt_channels_2ghz), |
| 119 | .bitrates = vnt_rates_bg, |
| 120 | .n_bitrates = ARRAY_SIZE(vnt_rates_bg), |
| 121 | }; |
| 122 | |
| 123 | static struct ieee80211_supported_band vnt_supported_5ghz_band = { |
| 124 | .channels = vnt_channels_5ghz, |
| 125 | .n_channels = ARRAY_SIZE(vnt_channels_5ghz), |
| 126 | .bitrates = vnt_rates_a, |
| 127 | .n_bitrates = ARRAY_SIZE(vnt_rates_a), |
| 128 | }; |
| 129 | |
| 130 | void vnt_init_bands(struct vnt_private *priv) |
| 131 | { |
| 132 | struct ieee80211_channel *ch; |
| 133 | int i; |
| 134 | |
| 135 | switch (priv->byRFType) { |
| 136 | case RF_AIROHA7230: |
| 137 | case RF_UW2452: |
| 138 | case RF_NOTHING: |
| 139 | default: |
| 140 | ch = vnt_channels_5ghz; |
| 141 | |
| 142 | for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) { |
| 143 | ch[i].max_power = 0x3f; |
| 144 | ch[i].flags = IEEE80211_CHAN_NO_HT40; |
| 145 | } |
| 146 | |
| 147 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 148 | &vnt_supported_5ghz_band; |
| 149 | /* fallthrough */ |
| 150 | case RF_RFMD2959: |
| 151 | case RF_AIROHA: |
| 152 | case RF_AL2230S: |
| 153 | case RF_UW2451: |
| 154 | case RF_VT3226: |
| 155 | ch = vnt_channels_2ghz; |
| 156 | |
| 157 | for (i = 0; i < ARRAY_SIZE(vnt_channels_2ghz); i++) { |
| 158 | ch[i].max_power = 0x3f; |
| 159 | ch[i].flags = IEEE80211_CHAN_NO_HT40; |
| 160 | } |
| 161 | |
| 162 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 163 | &vnt_supported_2ghz_band; |
| 164 | break; |
| 165 | } |
| 166 | } |
| 167 | |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 168 | /** |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 169 | * set_channel() - Set NIC media channel |
| 170 | * |
| 171 | * @pDeviceHandler: The adapter to be set |
| 172 | * @uConnectionChannel: Channel to be set |
| 173 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 174 | * Return Value: true if succeeded; false if failed. |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 175 | * |
| 176 | */ |
Joe Perches | 86fcb55 | 2013-03-18 10:44:41 -0700 | [diff] [blame] | 177 | bool set_channel(void *pDeviceHandler, unsigned int uConnectionChannel) |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 178 | { |
Malcolm Priestley | 0ffc587 | 2014-08-10 15:46:58 +0100 | [diff] [blame] | 179 | struct vnt_private *pDevice = pDeviceHandler; |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 180 | bool bResult = true; |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 181 | |
Guido Martínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 182 | if (pDevice->byCurrentCh == uConnectionChannel) |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 183 | return bResult; |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 184 | |
Veronika Kabatova | c834e76 | 2014-10-25 23:12:46 +0200 | [diff] [blame] | 185 | /* clear NAV */ |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 186 | MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MACCR, MACCR_CLRNAV); |
| 187 | |
Veronika Kabatova | c834e76 | 2014-10-25 23:12:46 +0200 | [diff] [blame] | 188 | /* TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput */ |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 189 | |
Guido Martínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 190 | if (pDevice->byRFType == RF_AIROHA7230) |
Malcolm Priestley | 817c985 | 2014-11-12 21:11:10 +0000 | [diff] [blame] | 191 | RFbAL7230SelectChannelPostProcess(pDevice, pDevice->byCurrentCh, |
| 192 | (unsigned char)uConnectionChannel); |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 193 | |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 194 | pDevice->byCurrentCh = (unsigned char)uConnectionChannel; |
Malcolm Priestley | 817c985 | 2014-11-12 21:11:10 +0000 | [diff] [blame] | 195 | bResult &= RFbSelectChannel(pDevice, pDevice->byRFType, |
| 196 | (unsigned char)uConnectionChannel); |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 197 | |
Veronika Kabatova | c834e76 | 2014-10-25 23:12:46 +0200 | [diff] [blame] | 198 | /* Init Synthesizer Table */ |
Teodora Baluta | 1208f14 | 2013-11-10 17:12:42 +0200 | [diff] [blame] | 199 | if (pDevice->bEnablePSMode) |
Malcolm Priestley | 817c985 | 2014-11-12 21:11:10 +0000 | [diff] [blame] | 200 | RFvWriteWakeProgSyn(pDevice, pDevice->byRFType, uConnectionChannel); |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 201 | |
Malcolm Priestley | a5f0eef | 2014-11-06 20:02:01 +0000 | [diff] [blame] | 202 | BBvSoftwareReset(pDevice); |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 203 | |
| 204 | if (pDevice->byLocalID > REV_ID_VT3253_B1) { |
Veronika Kabatova | c834e76 | 2014-10-25 23:12:46 +0200 | [diff] [blame] | 205 | /* set HW default power register */ |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 206 | MACvSelectPage1(pDevice->PortOffset); |
| 207 | RFbSetPower(pDevice, RATE_1M, pDevice->byCurrentCh); |
| 208 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_PWRCCK, pDevice->byCurPwr); |
| 209 | RFbSetPower(pDevice, RATE_6M, pDevice->byCurrentCh); |
| 210 | VNSvOutPortB(pDevice->PortOffset + MAC_REG_PWROFDM, pDevice->byCurPwr); |
| 211 | MACvSelectPage0(pDevice->PortOffset); |
| 212 | } |
| 213 | |
Malcolm Priestley | b956374 | 2014-10-29 17:43:49 +0000 | [diff] [blame] | 214 | if (pDevice->byBBType == BB_TYPE_11B) |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 215 | RFbSetPower(pDevice, RATE_1M, pDevice->byCurrentCh); |
Guido Martínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 216 | else |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 217 | RFbSetPower(pDevice, RATE_6M, pDevice->byCurrentCh); |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 218 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 219 | return bResult; |
Charles Clément | 79566eb | 2010-06-21 10:39:51 -0700 | [diff] [blame] | 220 | } |