1/* |
2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting |
3 * Copyright (c) 2002-2008 Atheros Communications, Inc. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * |
17 * $FreeBSD: head/sys/dev/ath/ath_hal/ar5212/ar5413.c 187831 2009-01-28 18:00:22Z sam $ |
18 */ 19#include "opt_ah.h" 20 21#include "ah.h" 22#include "ah_internal.h" 23 24#include "ah_eeprom_v3.h" 25 --- 44 unchanged lines hidden (view full) --- 70} 71 72/* 73 * Take the MHz channel value and set the Channel value 74 * 75 * ASSUMES: Writes enabled to analog bus 76 */ 77static HAL_BOOL |
78ar5413SetChannel(struct ath_hal *ah, const struct ieee80211_channel *chan) |
79{ |
80 uint16_t freq = ath_hal_gethwchannel(ah, chan); |
81 uint32_t channelSel = 0; 82 uint32_t bModeSynth = 0; 83 uint32_t aModeRefSel = 0; 84 uint32_t reg32 = 0; |
85 |
86 OS_MARK(ah, AH_MARK_SETCHANNEL, freq); |
87 |
88 if (freq < 4800) { |
89 uint32_t txctl; 90 |
91 if (((freq - 2192) % 5) == 0) { 92 channelSel = ((freq - 672) * 2 - 3040)/10; |
93 bModeSynth = 0; |
94 } else if (((freq - 2224) % 5) == 0) { 95 channelSel = ((freq - 704) * 2 - 3040) / 10; |
96 bModeSynth = 1; 97 } else { 98 HALDEBUG(ah, HAL_DEBUG_ANY, 99 "%s: invalid channel %u MHz\n", |
100 __func__, freq); |
101 return AH_FALSE; 102 } 103 104 channelSel = (channelSel << 2) & 0xff; 105 channelSel = ath_hal_reverseBits(channelSel, 8); 106 107 txctl = OS_REG_READ(ah, AR_PHY_CCK_TX_CTRL); |
108 if (freq == 2484) { |
109 /* Enable channel spreading for channel 14 */ 110 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL, 111 txctl | AR_PHY_CCK_TX_CTRL_JAPAN); 112 } else { 113 OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL, 114 txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN); 115 } |
116 } else if (((freq % 5) == 2) && (freq <= 5435)) { 117 freq = freq - 2; /* Align to even 5MHz raster */ |
118 channelSel = ath_hal_reverseBits( 119 (uint32_t)(((freq - 4800)*10)/25 + 1), 8); 120 aModeRefSel = ath_hal_reverseBits(0, 2); |
121 } else if ((freq % 20) == 0 && freq >= 5120) { |
122 channelSel = ath_hal_reverseBits( |
123 ((freq - 4800) / 20 << 2), 8); |
124 aModeRefSel = ath_hal_reverseBits(1, 2); |
125 } else if ((freq % 10) == 0) { |
126 channelSel = ath_hal_reverseBits( |
127 ((freq - 4800) / 10 << 1), 8); |
128 aModeRefSel = ath_hal_reverseBits(1, 2); |
129 } else if ((freq % 5) == 0) { |
130 channelSel = ath_hal_reverseBits( |
131 (freq - 4800) / 5, 8); |
132 aModeRefSel = ath_hal_reverseBits(1, 2); 133 } else { 134 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel %u MHz\n", |
135 __func__, freq); |
136 return AH_FALSE; 137 } 138 139 reg32 = (channelSel << 4) | (aModeRefSel << 2) | (bModeSynth << 1) | 140 (1 << 12) | 0x1; 141 OS_REG_WRITE(ah, AR_PHY(0x27), reg32 & 0xff); 142 143 reg32 >>= 8; --- 5 unchanged lines hidden (view full) --- 149 150/* 151 * Reads EEPROM header info from device structure and programs 152 * all rf registers 153 * 154 * REQUIRES: Access to the analog rf device 155 */ 156static HAL_BOOL |
157ar5413SetRfRegs(struct ath_hal *ah, 158 const struct ieee80211_channel *chan, 159 uint16_t modesIndex, uint16_t *rfXpdGain) |
160{ 161#define RF_BANK_SETUP(_priv, _ix, _col) do { \ 162 int i; \ 163 for (i = 0; i < N(ar5212Bank##_ix##_5413); i++) \ 164 (_priv)->Bank##_ix##Data[i] = ar5212Bank##_ix##_5413[i][_col];\ 165} while (0) 166 struct ath_hal_5212 *ahp = AH5212(ah); |
167 uint16_t freq = ath_hal_gethwchannel(ah, chan); |
168 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom; 169 uint16_t ob5GHz = 0, db5GHz = 0; 170 uint16_t ob2GHz = 0, db2GHz = 0; 171 struct ar5413State *priv = AR5413(ah); 172 int regWrites = 0; 173 |
174 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan %u/0x%x modesIndex %u\n", 175 __func__, chan->ic_freq, chan->ic_flags, modesIndex); |
176 177 HALASSERT(priv != AH_NULL); 178 179 /* Setup rf parameters */ |
180 switch (chan->ic_flags & IEEE80211_CHAN_ALLFULL) { 181 case IEEE80211_CHAN_A: 182 if (freq > 4000 && freq < 5260) { |
183 ob5GHz = ee->ee_ob1; 184 db5GHz = ee->ee_db1; |
185 } else if (freq >= 5260 && freq < 5500) { |
186 ob5GHz = ee->ee_ob2; 187 db5GHz = ee->ee_db2; |
188 } else if (freq >= 5500 && freq < 5725) { |
189 ob5GHz = ee->ee_ob3; 190 db5GHz = ee->ee_db3; |
191 } else if (freq >= 5725) { |
192 ob5GHz = ee->ee_ob4; 193 db5GHz = ee->ee_db4; 194 } else { 195 /* XXX else */ 196 } 197 break; |
198 case IEEE80211_CHAN_B: |
199 ob2GHz = ee->ee_obFor24; 200 db2GHz = ee->ee_dbFor24; 201 break; |
202 case IEEE80211_CHAN_G: 203 case IEEE80211_CHAN_PUREG: /* NB: really 108G */ |
204 ob2GHz = ee->ee_obFor24g; 205 db2GHz = ee->ee_dbFor24g; 206 break; 207 default: 208 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel flags 0x%x\n", |
209 __func__, chan->ic_flags); |
210 return AH_FALSE; 211 } 212 213 /* Bank 1 Write */ 214 RF_BANK_SETUP(priv, 1, 1); 215 216 /* Bank 2 Write */ 217 RF_BANK_SETUP(priv, 2, modesIndex); 218 219 /* Bank 3 Write */ 220 RF_BANK_SETUP(priv, 3, modesIndex); 221 222 /* Bank 6 Write */ 223 RF_BANK_SETUP(priv, 6, modesIndex); 224 225 /* Only the 5 or 2 GHz OB/DB need to be set for a mode */ |
226 if (IEEE80211_IS_CHAN_2GHZ(chan)) { |
227 ar5212ModifyRfBuffer(priv->Bank6Data, ob2GHz, 3, 241, 0); 228 ar5212ModifyRfBuffer(priv->Bank6Data, db2GHz, 3, 238, 0); 229 230 /* TODO - only for Eagle 1.0 2GHz - remove for production */ 231 /* XXX: but without this bit G doesn't work. */ 232 ar5212ModifyRfBuffer(priv->Bank6Data, 1 , 1, 291, 2); 233 234 /* Optimum value for rf_pwd_iclobuf2G for PCIe chips only */ --- 298 unchanged lines hidden (view full) --- 533 return numPdGainsUsed; 534#undef VpdTable_L 535#undef VpdTable_R 536#undef VpdTable_I 537} 538 539static HAL_BOOL 540ar5413SetPowerTable(struct ath_hal *ah, |
541 int16_t *minPower, int16_t *maxPower, 542 const struct ieee80211_channel *chan, |
543 uint16_t *rfXpdGain) 544{ 545 struct ath_hal_5212 *ahp = AH5212(ah); |
546 uint16_t freq = ath_hal_gethwchannel(ah, chan); |
547 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom; 548 const RAW_DATA_STRUCT_2413 *pRawDataset = AH_NULL; 549 uint16_t pdGainOverlap_t2; 550 int16_t minCalPower5413_t2; 551 uint16_t *pdadcValues = ahp->ah_pcdacTable; 552 uint16_t gainBoundaries[4]; 553 uint32_t reg32, regoffset; 554 int i, numPdGainsUsed; 555#ifndef AH_USE_INIPDGAIN 556 uint32_t tpcrg1; 557#endif 558 559 HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan 0x%x flag 0x%x\n", |
560 __func__, chan->ic_freq, chan->ic_flags); |
561 |
562 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan)) |
563 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G]; |
564 else if (IEEE80211_IS_CHAN_B(chan)) |
565 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B]; 566 else { |
567 HALASSERT(IEEE80211_IS_CHAN_5GHZ(chan)); |
568 pRawDataset = &ee->ee_rawDataset2413[headerInfo11A]; 569 } 570 571 pdGainOverlap_t2 = (uint16_t) SM(OS_REG_READ(ah, AR_PHY_TPCRG5), 572 AR_PHY_TPCRG5_PD_GAIN_OVERLAP); 573 574 numPdGainsUsed = ar5413getGainBoundariesAndPdadcsForPowers(ah, |
575 freq, pRawDataset, pdGainOverlap_t2, |
576 &minCalPower5413_t2,gainBoundaries, rfXpdGain, pdadcValues); 577 HALASSERT(1 <= numPdGainsUsed && numPdGainsUsed <= 3); 578 579#ifdef AH_USE_INIPDGAIN 580 /* 581 * Use pd_gains curve from eeprom; Atheros always uses 582 * the default curve from the ini file but some vendors 583 * (e.g. Zcomax) want to override this curve and not --- 90 unchanged lines hidden (view full) --- 674 Pmax = data->pDataPerPDGain[ii].pwr_t4[numVpd-1]; 675 return(Pmax); 676 } 677 } 678 return(Pmax); 679} 680 681static HAL_BOOL |
682ar5413GetChannelMaxMinPower(struct ath_hal *ah, 683 const struct ieee80211_channel *chan, |
684 int16_t *maxPow, int16_t *minPow) 685{ |
686 uint16_t freq = chan->ic_freq; /* NB: never mapped */ |
687 const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom; 688 const RAW_DATA_STRUCT_2413 *pRawDataset = AH_NULL; 689 const RAW_DATA_PER_CHANNEL_2413 *data=AH_NULL; 690 uint16_t numChannels; 691 int totalD,totalF, totalMin,last, i; 692 693 *maxPow = 0; 694 |
695 if (IEEE80211_IS_CHAN_G(chan) || IEEE80211_IS_CHAN_108G(chan)) |
696 pRawDataset = &ee->ee_rawDataset2413[headerInfo11G]; |
697 else if (IEEE80211_IS_CHAN_B(chan)) |
698 pRawDataset = &ee->ee_rawDataset2413[headerInfo11B]; 699 else { |
700 HALASSERT(IEEE80211_IS_CHAN_5GHZ(chan)); |
701 pRawDataset = &ee->ee_rawDataset2413[headerInfo11A]; 702 } 703 704 numChannels = pRawDataset->numChannels; 705 data = pRawDataset->pDataPerChannel; 706 707 /* Make sure the channel is in the range of the TP values 708 * (freq piers) 709 */ 710 if (numChannels < 1) 711 return(AH_FALSE); 712 |
713 if ((freq < data[0].channelValue) || 714 (freq > data[numChannels-1].channelValue)) { 715 if (freq < data[0].channelValue) { |
716 *maxPow = ar5413GetMaxPower(ah, &data[0]); 717 *minPow = ar5413GetMinPower(ah, &data[0]); 718 return(AH_TRUE); 719 } else { 720 *maxPow = ar5413GetMaxPower(ah, &data[numChannels - 1]); 721 *minPow = ar5413GetMinPower(ah, &data[numChannels - 1]); 722 return(AH_TRUE); 723 } 724 } 725 726 /* Linearly interpolate the power value now */ |
727 for (last=0,i=0; (i<numChannels) && (freq > data[i].channelValue); |
728 last = i++); 729 totalD = data[i].channelValue - data[last].channelValue; 730 if (totalD > 0) { 731 totalF = ar5413GetMaxPower(ah, &data[i]) - ar5413GetMaxPower(ah, &data[last]); |
732 *maxPow = (int8_t) ((totalF*(freq-data[last].channelValue) + |
733 ar5413GetMaxPower(ah, &data[last])*totalD)/totalD); 734 totalMin = ar5413GetMinPower(ah, &data[i]) - ar5413GetMinPower(ah, &data[last]); |
735 *minPow = (int8_t) ((totalMin*(freq-data[last].channelValue) + |
736 ar5413GetMinPower(ah, &data[last])*totalD)/totalD); 737 return(AH_TRUE); 738 } else { |
739 if (freq == data[i].channelValue) { |
740 *maxPow = ar5413GetMaxPower(ah, &data[i]); 741 *minPow = ar5413GetMinPower(ah, &data[i]); 742 return(AH_TRUE); 743 } else 744 return(AH_FALSE); 745 } 746} 747 --- 55 unchanged lines hidden --- |