diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-03-27 23:21:18 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-03-27 23:26:01 -0400 |
commit | 82268da1b130f763d22d04f7d016bbf6fc8815c2 (patch) | |
tree | 9803f361556d10708313e980428e63a18162e667 /drivers/net/wireless/ath5k | |
parent | 6e15cf04860074ad032e88c306bea656bbdd0f22 (diff) | |
parent | 5d80f8e5a9dc9c9a94d4aeaa567e219a808b8a4a (diff) |
Merge branch 'linus' into percpu-cpumask-x86-for-linus-2
Conflicts:
arch/sparc/kernel/time_64.c
drivers/gpu/drm/drm_proc.c
Manual merge to resolve build warning due to phys_addr_t type change
on x86:
drivers/gpu/drm/drm_info.c
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'drivers/net/wireless/ath5k')
-rw-r--r-- | drivers/net/wireless/ath5k/ath5k.h | 35 | ||||
-rw-r--r-- | drivers/net/wireless/ath5k/attach.c | 2 | ||||
-rw-r--r-- | drivers/net/wireless/ath5k/base.c | 46 | ||||
-rw-r--r-- | drivers/net/wireless/ath5k/base.h | 2 | ||||
-rw-r--r-- | drivers/net/wireless/ath5k/desc.c | 4 | ||||
-rw-r--r-- | drivers/net/wireless/ath5k/eeprom.c | 774 | ||||
-rw-r--r-- | drivers/net/wireless/ath5k/eeprom.h | 128 | ||||
-rw-r--r-- | drivers/net/wireless/ath5k/initvals.c | 4 | ||||
-rw-r--r-- | drivers/net/wireless/ath5k/led.c | 2 | ||||
-rw-r--r-- | drivers/net/wireless/ath5k/phy.c | 1170 | ||||
-rw-r--r-- | drivers/net/wireless/ath5k/reg.h | 19 | ||||
-rw-r--r-- | drivers/net/wireless/ath5k/reset.c | 35 |
12 files changed, 1833 insertions, 388 deletions
diff --git a/drivers/net/wireless/ath5k/ath5k.h b/drivers/net/wireless/ath5k/ath5k.h index 0dc2c7321c8b..0b616e72fe05 100644 --- a/drivers/net/wireless/ath5k/ath5k.h +++ b/drivers/net/wireless/ath5k/ath5k.h | |||
@@ -204,9 +204,9 @@ | |||
204 | #define AR5K_TUNE_CWMAX_11B 1023 | 204 | #define AR5K_TUNE_CWMAX_11B 1023 |
205 | #define AR5K_TUNE_CWMAX_XR 7 | 205 | #define AR5K_TUNE_CWMAX_XR 7 |
206 | #define AR5K_TUNE_NOISE_FLOOR -72 | 206 | #define AR5K_TUNE_NOISE_FLOOR -72 |
207 | #define AR5K_TUNE_MAX_TXPOWER 60 | 207 | #define AR5K_TUNE_MAX_TXPOWER 63 |
208 | #define AR5K_TUNE_DEFAULT_TXPOWER 30 | 208 | #define AR5K_TUNE_DEFAULT_TXPOWER 25 |
209 | #define AR5K_TUNE_TPC_TXPOWER true | 209 | #define AR5K_TUNE_TPC_TXPOWER false |
210 | #define AR5K_TUNE_ANT_DIVERSITY true | 210 | #define AR5K_TUNE_ANT_DIVERSITY true |
211 | #define AR5K_TUNE_HWTXTRIES 4 | 211 | #define AR5K_TUNE_HWTXTRIES 4 |
212 | 212 | ||
@@ -551,11 +551,11 @@ enum ath5k_pkt_type { | |||
551 | */ | 551 | */ |
552 | #define AR5K_TXPOWER_OFDM(_r, _v) ( \ | 552 | #define AR5K_TXPOWER_OFDM(_r, _v) ( \ |
553 | ((0 & 1) << ((_v) + 6)) | \ | 553 | ((0 & 1) << ((_v) + 6)) | \ |
554 | (((ah->ah_txpower.txp_rates[(_r)]) & 0x3f) << (_v)) \ | 554 | (((ah->ah_txpower.txp_rates_power_table[(_r)]) & 0x3f) << (_v)) \ |
555 | ) | 555 | ) |
556 | 556 | ||
557 | #define AR5K_TXPOWER_CCK(_r, _v) ( \ | 557 | #define AR5K_TXPOWER_CCK(_r, _v) ( \ |
558 | (ah->ah_txpower.txp_rates[(_r)] & 0x3f) << (_v) \ | 558 | (ah->ah_txpower.txp_rates_power_table[(_r)] & 0x3f) << (_v) \ |
559 | ) | 559 | ) |
560 | 560 | ||
561 | /* | 561 | /* |
@@ -1085,13 +1085,25 @@ struct ath5k_hw { | |||
1085 | struct ath5k_gain ah_gain; | 1085 | struct ath5k_gain ah_gain; |
1086 | u8 ah_offset[AR5K_MAX_RF_BANKS]; | 1086 | u8 ah_offset[AR5K_MAX_RF_BANKS]; |
1087 | 1087 | ||
1088 | |||
1088 | struct { | 1089 | struct { |
1089 | u16 txp_pcdac[AR5K_EEPROM_POWER_TABLE_SIZE]; | 1090 | /* Temporary tables used for interpolation */ |
1090 | u16 txp_rates[AR5K_MAX_RATES]; | 1091 | u8 tmpL[AR5K_EEPROM_N_PD_GAINS] |
1091 | s16 txp_min; | 1092 | [AR5K_EEPROM_POWER_TABLE_SIZE]; |
1092 | s16 txp_max; | 1093 | u8 tmpR[AR5K_EEPROM_N_PD_GAINS] |
1094 | [AR5K_EEPROM_POWER_TABLE_SIZE]; | ||
1095 | u8 txp_pd_table[AR5K_EEPROM_POWER_TABLE_SIZE * 2]; | ||
1096 | u16 txp_rates_power_table[AR5K_MAX_RATES]; | ||
1097 | u8 txp_min_idx; | ||
1093 | bool txp_tpc; | 1098 | bool txp_tpc; |
1099 | /* Values in 0.25dB units */ | ||
1100 | s16 txp_min_pwr; | ||
1101 | s16 txp_max_pwr; | ||
1102 | s16 txp_offset; | ||
1094 | s16 txp_ofdm; | 1103 | s16 txp_ofdm; |
1104 | /* Values in dB units */ | ||
1105 | s16 txp_cck_ofdm_pwr_delta; | ||
1106 | s16 txp_cck_ofdm_gainf_delta; | ||
1095 | } ah_txpower; | 1107 | } ah_txpower; |
1096 | 1108 | ||
1097 | struct { | 1109 | struct { |
@@ -1161,6 +1173,7 @@ extern void ath5k_hw_update_mib_counters(struct ath5k_hw *ah, struct ieee80211_l | |||
1161 | 1173 | ||
1162 | /* EEPROM access functions */ | 1174 | /* EEPROM access functions */ |
1163 | extern int ath5k_eeprom_init(struct ath5k_hw *ah); | 1175 | extern int ath5k_eeprom_init(struct ath5k_hw *ah); |
1176 | extern void ath5k_eeprom_detach(struct ath5k_hw *ah); | ||
1164 | extern int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac); | 1177 | extern int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac); |
1165 | extern bool ath5k_eeprom_is_hb63(struct ath5k_hw *ah); | 1178 | extern bool ath5k_eeprom_is_hb63(struct ath5k_hw *ah); |
1166 | 1179 | ||
@@ -1256,8 +1269,8 @@ extern void ath5k_hw_set_def_antenna(struct ath5k_hw *ah, unsigned int ant); | |||
1256 | extern unsigned int ath5k_hw_get_def_antenna(struct ath5k_hw *ah); | 1269 | extern unsigned int ath5k_hw_get_def_antenna(struct ath5k_hw *ah); |
1257 | extern int ath5k_hw_phy_disable(struct ath5k_hw *ah); | 1270 | extern int ath5k_hw_phy_disable(struct ath5k_hw *ah); |
1258 | /* TX power setup */ | 1271 | /* TX power setup */ |
1259 | extern int ath5k_hw_txpower(struct ath5k_hw *ah, struct ieee80211_channel *channel, unsigned int txpower); | 1272 | extern int ath5k_hw_txpower(struct ath5k_hw *ah, struct ieee80211_channel *channel, u8 ee_mode, u8 txpower); |
1260 | extern int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, unsigned int power); | 1273 | extern int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 ee_mode, u8 txpower); |
1261 | 1274 | ||
1262 | /* | 1275 | /* |
1263 | * Functions used internaly | 1276 | * Functions used internaly |
diff --git a/drivers/net/wireless/ath5k/attach.c b/drivers/net/wireless/ath5k/attach.c index 656cb9dc833b..70d376c63aac 100644 --- a/drivers/net/wireless/ath5k/attach.c +++ b/drivers/net/wireless/ath5k/attach.c | |||
@@ -341,6 +341,8 @@ void ath5k_hw_detach(struct ath5k_hw *ah) | |||
341 | if (ah->ah_rf_banks != NULL) | 341 | if (ah->ah_rf_banks != NULL) |
342 | kfree(ah->ah_rf_banks); | 342 | kfree(ah->ah_rf_banks); |
343 | 343 | ||
344 | ath5k_eeprom_detach(ah); | ||
345 | |||
344 | /* assume interrupts are down */ | 346 | /* assume interrupts are down */ |
345 | kfree(ah); | 347 | kfree(ah); |
346 | } | 348 | } |
diff --git a/drivers/net/wireless/ath5k/base.c b/drivers/net/wireless/ath5k/base.c index cad3ccf61b00..5d57d774e466 100644 --- a/drivers/net/wireless/ath5k/base.c +++ b/drivers/net/wireless/ath5k/base.c | |||
@@ -685,13 +685,6 @@ ath5k_pci_resume(struct pci_dev *pdev) | |||
685 | if (err) | 685 | if (err) |
686 | return err; | 686 | return err; |
687 | 687 | ||
688 | /* | ||
689 | * Suspend/Resume resets the PCI configuration space, so we have to | ||
690 | * re-disable the RETRY_TIMEOUT register (0x41) to keep | ||
691 | * PCI Tx retries from interfering with C3 CPU state | ||
692 | */ | ||
693 | pci_write_config_byte(pdev, 0x41, 0); | ||
694 | |||
695 | err = request_irq(pdev->irq, ath5k_intr, IRQF_SHARED, "ath", sc); | 688 | err = request_irq(pdev->irq, ath5k_intr, IRQF_SHARED, "ath", sc); |
696 | if (err) { | 689 | if (err) { |
697 | ATH5K_ERR(sc, "request_irq failed\n"); | 690 | ATH5K_ERR(sc, "request_irq failed\n"); |
@@ -1095,9 +1088,18 @@ ath5k_mode_setup(struct ath5k_softc *sc) | |||
1095 | static inline int | 1088 | static inline int |
1096 | ath5k_hw_to_driver_rix(struct ath5k_softc *sc, int hw_rix) | 1089 | ath5k_hw_to_driver_rix(struct ath5k_softc *sc, int hw_rix) |
1097 | { | 1090 | { |
1098 | WARN(hw_rix < 0 || hw_rix >= AR5K_MAX_RATES, | 1091 | int rix; |
1099 | "hw_rix out of bounds: %x\n", hw_rix); | 1092 | |
1100 | return sc->rate_idx[sc->curband->band][hw_rix]; | 1093 | /* return base rate on errors */ |
1094 | if (WARN(hw_rix < 0 || hw_rix >= AR5K_MAX_RATES, | ||
1095 | "hw_rix out of bounds: %x\n", hw_rix)) | ||
1096 | return 0; | ||
1097 | |||
1098 | rix = sc->rate_idx[sc->curband->band][hw_rix]; | ||
1099 | if (WARN(rix < 0, "invalid hw_rix: %x\n", hw_rix)) | ||
1100 | rix = 0; | ||
1101 | |||
1102 | return rix; | ||
1101 | } | 1103 | } |
1102 | 1104 | ||
1103 | /***************\ | 1105 | /***************\ |
@@ -1216,6 +1218,9 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf) | |||
1216 | 1218 | ||
1217 | pktlen = skb->len; | 1219 | pktlen = skb->len; |
1218 | 1220 | ||
1221 | /* FIXME: If we are in g mode and rate is a CCK rate | ||
1222 | * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta | ||
1223 | * from tx power (value is in dB units already) */ | ||
1219 | if (info->control.hw_key) { | 1224 | if (info->control.hw_key) { |
1220 | keyidx = info->control.hw_key->hw_key_idx; | 1225 | keyidx = info->control.hw_key->hw_key_idx; |
1221 | pktlen += info->control.hw_key->icv_len; | 1226 | pktlen += info->control.hw_key->icv_len; |
@@ -2044,6 +2049,9 @@ ath5k_beacon_setup(struct ath5k_softc *sc, struct ath5k_buf *bf) | |||
2044 | antenna = sc->bsent & 4 ? 2 : 1; | 2049 | antenna = sc->bsent & 4 ? 2 : 1; |
2045 | } | 2050 | } |
2046 | 2051 | ||
2052 | /* FIXME: If we are in g mode and rate is a CCK rate | ||
2053 | * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta | ||
2054 | * from tx power (value is in dB units already) */ | ||
2047 | ds->ds_data = bf->skbaddr; | 2055 | ds->ds_data = bf->skbaddr; |
2048 | ret = ah->ah_setup_tx_desc(ah, ds, skb->len, | 2056 | ret = ah->ah_setup_tx_desc(ah, ds, skb->len, |
2049 | ieee80211_get_hdrlen_from_skb(skb), | 2057 | ieee80211_get_hdrlen_from_skb(skb), |
@@ -2305,7 +2313,7 @@ ath5k_init(struct ath5k_softc *sc) | |||
2305 | sc->curband = &sc->sbands[sc->curchan->band]; | 2313 | sc->curband = &sc->sbands[sc->curchan->band]; |
2306 | sc->imask = AR5K_INT_RXOK | AR5K_INT_RXERR | AR5K_INT_RXEOL | | 2314 | sc->imask = AR5K_INT_RXOK | AR5K_INT_RXERR | AR5K_INT_RXEOL | |
2307 | AR5K_INT_RXORN | AR5K_INT_TXDESC | AR5K_INT_TXEOL | | 2315 | AR5K_INT_RXORN | AR5K_INT_TXDESC | AR5K_INT_TXEOL | |
2308 | AR5K_INT_FATAL | AR5K_INT_GLOBAL | AR5K_INT_MIB; | 2316 | AR5K_INT_FATAL | AR5K_INT_GLOBAL; |
2309 | ret = ath5k_reset(sc, false, false); | 2317 | ret = ath5k_reset(sc, false, false); |
2310 | if (ret) | 2318 | if (ret) |
2311 | goto done; | 2319 | goto done; |
@@ -2554,7 +2562,7 @@ ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb) | |||
2554 | if (skb_headroom(skb) < padsize) { | 2562 | if (skb_headroom(skb) < padsize) { |
2555 | ATH5K_ERR(sc, "tx hdrlen not %%4: %d not enough" | 2563 | ATH5K_ERR(sc, "tx hdrlen not %%4: %d not enough" |
2556 | " headroom to pad %d\n", hdrlen, padsize); | 2564 | " headroom to pad %d\n", hdrlen, padsize); |
2557 | return NETDEV_TX_BUSY; | 2565 | goto drop_packet; |
2558 | } | 2566 | } |
2559 | skb_push(skb, padsize); | 2567 | skb_push(skb, padsize); |
2560 | memmove(skb->data, skb->data+padsize, hdrlen); | 2568 | memmove(skb->data, skb->data+padsize, hdrlen); |
@@ -2565,7 +2573,7 @@ ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb) | |||
2565 | ATH5K_ERR(sc, "no further txbuf available, dropping packet\n"); | 2573 | ATH5K_ERR(sc, "no further txbuf available, dropping packet\n"); |
2566 | spin_unlock_irqrestore(&sc->txbuflock, flags); | 2574 | spin_unlock_irqrestore(&sc->txbuflock, flags); |
2567 | ieee80211_stop_queue(hw, skb_get_queue_mapping(skb)); | 2575 | ieee80211_stop_queue(hw, skb_get_queue_mapping(skb)); |
2568 | return NETDEV_TX_BUSY; | 2576 | goto drop_packet; |
2569 | } | 2577 | } |
2570 | bf = list_first_entry(&sc->txbuf, struct ath5k_buf, list); | 2578 | bf = list_first_entry(&sc->txbuf, struct ath5k_buf, list); |
2571 | list_del(&bf->list); | 2579 | list_del(&bf->list); |
@@ -2582,10 +2590,12 @@ ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb) | |||
2582 | list_add_tail(&bf->list, &sc->txbuf); | 2590 | list_add_tail(&bf->list, &sc->txbuf); |
2583 | sc->txbuf_len++; | 2591 | sc->txbuf_len++; |
2584 | spin_unlock_irqrestore(&sc->txbuflock, flags); | 2592 | spin_unlock_irqrestore(&sc->txbuflock, flags); |
2585 | dev_kfree_skb_any(skb); | 2593 | goto drop_packet; |
2586 | return NETDEV_TX_OK; | ||
2587 | } | 2594 | } |
2595 | return NETDEV_TX_OK; | ||
2588 | 2596 | ||
2597 | drop_packet: | ||
2598 | dev_kfree_skb_any(skb); | ||
2589 | return NETDEV_TX_OK; | 2599 | return NETDEV_TX_OK; |
2590 | } | 2600 | } |
2591 | 2601 | ||
@@ -2608,12 +2618,6 @@ ath5k_reset(struct ath5k_softc *sc, bool stop, bool change_channel) | |||
2608 | goto err; | 2618 | goto err; |
2609 | } | 2619 | } |
2610 | 2620 | ||
2611 | /* | ||
2612 | * This is needed only to setup initial state | ||
2613 | * but it's best done after a reset. | ||
2614 | */ | ||
2615 | ath5k_hw_set_txpower_limit(sc->ah, 0); | ||
2616 | |||
2617 | ret = ath5k_rx_start(sc); | 2621 | ret = ath5k_rx_start(sc); |
2618 | if (ret) { | 2622 | if (ret) { |
2619 | ATH5K_ERR(sc, "can't start recv logic\n"); | 2623 | ATH5K_ERR(sc, "can't start recv logic\n"); |
diff --git a/drivers/net/wireless/ath5k/base.h b/drivers/net/wireless/ath5k/base.h index 20e0d14b41ec..822956114cd7 100644 --- a/drivers/net/wireless/ath5k/base.h +++ b/drivers/net/wireless/ath5k/base.h | |||
@@ -112,7 +112,7 @@ struct ath5k_softc { | |||
112 | struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS]; | 112 | struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS]; |
113 | struct ieee80211_channel channels[ATH_CHAN_MAX]; | 113 | struct ieee80211_channel channels[ATH_CHAN_MAX]; |
114 | struct ieee80211_rate rates[IEEE80211_NUM_BANDS][AR5K_MAX_RATES]; | 114 | struct ieee80211_rate rates[IEEE80211_NUM_BANDS][AR5K_MAX_RATES]; |
115 | u8 rate_idx[IEEE80211_NUM_BANDS][AR5K_MAX_RATES]; | 115 | s8 rate_idx[IEEE80211_NUM_BANDS][AR5K_MAX_RATES]; |
116 | enum nl80211_iftype opmode; | 116 | enum nl80211_iftype opmode; |
117 | struct ath5k_hw *ah; /* Atheros HW */ | 117 | struct ath5k_hw *ah; /* Atheros HW */ |
118 | 118 | ||
diff --git a/drivers/net/wireless/ath5k/desc.c b/drivers/net/wireless/ath5k/desc.c index b40a9287a39a..dc30a2b70a6b 100644 --- a/drivers/net/wireless/ath5k/desc.c +++ b/drivers/net/wireless/ath5k/desc.c | |||
@@ -194,6 +194,10 @@ static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah, | |||
194 | return -EINVAL; | 194 | return -EINVAL; |
195 | } | 195 | } |
196 | 196 | ||
197 | tx_power += ah->ah_txpower.txp_offset; | ||
198 | if (tx_power > AR5K_TUNE_MAX_TXPOWER) | ||
199 | tx_power = AR5K_TUNE_MAX_TXPOWER; | ||
200 | |||
197 | /* Clear descriptor */ | 201 | /* Clear descriptor */ |
198 | memset(&desc->ud.ds_tx5212, 0, sizeof(struct ath5k_hw_5212_tx_desc)); | 202 | memset(&desc->ud.ds_tx5212, 0, sizeof(struct ath5k_hw_5212_tx_desc)); |
199 | 203 | ||
diff --git a/drivers/net/wireless/ath5k/eeprom.c b/drivers/net/wireless/ath5k/eeprom.c index ac45ca47ca87..c0fb3b09ba45 100644 --- a/drivers/net/wireless/ath5k/eeprom.c +++ b/drivers/net/wireless/ath5k/eeprom.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org> | 2 | * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org> |
3 | * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com> | 3 | * Copyright (c) 2006-2009 Nick Kossifidis <mickflemm@gmail.com> |
4 | * Copyright (c) 2008 Felix Fietkau <nbd@openwrt.org> | 4 | * Copyright (c) 2008-2009 Felix Fietkau <nbd@openwrt.org> |
5 | * | 5 | * |
6 | * Permission to use, copy, modify, and distribute this software for any | 6 | * Permission to use, copy, modify, and distribute this software for any |
7 | * purpose with or without fee is hereby granted, provided that the above | 7 | * purpose with or without fee is hereby granted, provided that the above |
@@ -98,11 +98,6 @@ ath5k_eeprom_init_header(struct ath5k_hw *ah) | |||
98 | int ret; | 98 | int ret; |
99 | u16 val; | 99 | u16 val; |
100 | 100 | ||
101 | /* Initial TX thermal adjustment values */ | ||
102 | ee->ee_tx_clip = 4; | ||
103 | ee->ee_pwd_84 = ee->ee_pwd_90 = 1; | ||
104 | ee->ee_gain_select = 1; | ||
105 | |||
106 | /* | 101 | /* |
107 | * Read values from EEPROM and store them in the capability structure | 102 | * Read values from EEPROM and store them in the capability structure |
108 | */ | 103 | */ |
@@ -241,22 +236,22 @@ static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset, | |||
241 | ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff); | 236 | ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff); |
242 | switch(mode) { | 237 | switch(mode) { |
243 | case AR5K_EEPROM_MODE_11A: | 238 | case AR5K_EEPROM_MODE_11A: |
244 | ee->ee_ob[mode][3] = (val >> 5) & 0x7; | 239 | ee->ee_ob[mode][3] = (val >> 5) & 0x7; |
245 | ee->ee_db[mode][3] = (val >> 2) & 0x7; | 240 | ee->ee_db[mode][3] = (val >> 2) & 0x7; |
246 | ee->ee_ob[mode][2] = (val << 1) & 0x7; | 241 | ee->ee_ob[mode][2] = (val << 1) & 0x7; |
247 | 242 | ||
248 | AR5K_EEPROM_READ(o++, val); | 243 | AR5K_EEPROM_READ(o++, val); |
249 | ee->ee_ob[mode][2] |= (val >> 15) & 0x1; | 244 | ee->ee_ob[mode][2] |= (val >> 15) & 0x1; |
250 | ee->ee_db[mode][2] = (val >> 12) & 0x7; | 245 | ee->ee_db[mode][2] = (val >> 12) & 0x7; |
251 | ee->ee_ob[mode][1] = (val >> 9) & 0x7; | 246 | ee->ee_ob[mode][1] = (val >> 9) & 0x7; |
252 | ee->ee_db[mode][1] = (val >> 6) & 0x7; | 247 | ee->ee_db[mode][1] = (val >> 6) & 0x7; |
253 | ee->ee_ob[mode][0] = (val >> 3) & 0x7; | 248 | ee->ee_ob[mode][0] = (val >> 3) & 0x7; |
254 | ee->ee_db[mode][0] = val & 0x7; | 249 | ee->ee_db[mode][0] = val & 0x7; |
255 | break; | 250 | break; |
256 | case AR5K_EEPROM_MODE_11G: | 251 | case AR5K_EEPROM_MODE_11G: |
257 | case AR5K_EEPROM_MODE_11B: | 252 | case AR5K_EEPROM_MODE_11B: |
258 | ee->ee_ob[mode][1] = (val >> 4) & 0x7; | 253 | ee->ee_ob[mode][1] = (val >> 4) & 0x7; |
259 | ee->ee_db[mode][1] = val & 0x7; | 254 | ee->ee_db[mode][1] = val & 0x7; |
260 | break; | 255 | break; |
261 | } | 256 | } |
262 | 257 | ||
@@ -504,35 +499,6 @@ ath5k_eeprom_init_modes(struct ath5k_hw *ah) | |||
504 | return 0; | 499 | return 0; |
505 | } | 500 | } |
506 | 501 | ||
507 | /* Used to match PCDAC steps with power values on RF5111 chips | ||
508 | * (eeprom versions < 4). For RF5111 we have 10 pre-defined PCDAC | ||
509 | * steps that match with the power values we read from eeprom. On | ||
510 | * older eeprom versions (< 3.2) these steps are equaly spaced at | ||
511 | * 10% of the pcdac curve -until the curve reaches it's maximum- | ||
512 | * (10 steps from 0 to 100%) but on newer eeprom versions (>= 3.2) | ||
513 | * these 10 steps are spaced in a different way. This function returns | ||
514 | * the pcdac steps based on eeprom version and curve min/max so that we | ||
515 | * can have pcdac/pwr points. | ||
516 | */ | ||
517 | static inline void | ||
518 | ath5k_get_pcdac_intercepts(struct ath5k_hw *ah, u8 min, u8 max, u8 *vp) | ||
519 | { | ||
520 | static const u16 intercepts3[] = | ||
521 | { 0, 5, 10, 20, 30, 50, 70, 85, 90, 95, 100 }; | ||
522 | static const u16 intercepts3_2[] = | ||
523 | { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; | ||
524 | const u16 *ip; | ||
525 | int i; | ||
526 | |||
527 | if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_2) | ||
528 | ip = intercepts3_2; | ||
529 | else | ||
530 | ip = intercepts3; | ||
531 | |||
532 | for (i = 0; i < ARRAY_SIZE(intercepts3); i++) | ||
533 | *vp++ = (ip[i] * max + (100 - ip[i]) * min) / 100; | ||
534 | } | ||
535 | |||
536 | /* Read the frequency piers for each mode (mostly used on newer eeproms with 0xff | 502 | /* Read the frequency piers for each mode (mostly used on newer eeproms with 0xff |
537 | * frequency mask) */ | 503 | * frequency mask) */ |
538 | static inline int | 504 | static inline int |
@@ -546,26 +512,25 @@ ath5k_eeprom_read_freq_list(struct ath5k_hw *ah, int *offset, int max, | |||
546 | int ret; | 512 | int ret; |
547 | u16 val; | 513 | u16 val; |
548 | 514 | ||
515 | ee->ee_n_piers[mode] = 0; | ||
549 | while(i < max) { | 516 | while(i < max) { |
550 | AR5K_EEPROM_READ(o++, val); | 517 | AR5K_EEPROM_READ(o++, val); |
551 | 518 | ||
552 | freq1 = (val >> 8) & 0xff; | 519 | freq1 = val & 0xff; |
553 | freq2 = val & 0xff; | 520 | if (!freq1) |
554 | 521 | break; | |
555 | if (freq1) { | ||
556 | pc[i++].freq = ath5k_eeprom_bin2freq(ee, | ||
557 | freq1, mode); | ||
558 | ee->ee_n_piers[mode]++; | ||
559 | } | ||
560 | 522 | ||
561 | if (freq2) { | 523 | pc[i++].freq = ath5k_eeprom_bin2freq(ee, |
562 | pc[i++].freq = ath5k_eeprom_bin2freq(ee, | 524 | freq1, mode); |
563 | freq2, mode); | 525 | ee->ee_n_piers[mode]++; |
564 | ee->ee_n_piers[mode]++; | ||
565 | } | ||
566 | 526 | ||
567 | if (!freq1 || !freq2) | 527 | freq2 = (val >> 8) & 0xff; |
528 | if (!freq2) | ||
568 | break; | 529 | break; |
530 | |||
531 | pc[i++].freq = ath5k_eeprom_bin2freq(ee, | ||
532 | freq2, mode); | ||
533 | ee->ee_n_piers[mode]++; | ||
569 | } | 534 | } |
570 | 535 | ||
571 | /* return new offset */ | 536 | /* return new offset */ |
@@ -652,13 +617,122 @@ ath5k_eeprom_init_11bg_2413(struct ath5k_hw *ah, unsigned int mode, int offset) | |||
652 | return 0; | 617 | return 0; |
653 | } | 618 | } |
654 | 619 | ||
655 | /* Read power calibration for RF5111 chips | 620 | /* |
621 | * Read power calibration for RF5111 chips | ||
622 | * | ||
656 | * For RF5111 we have an XPD -eXternal Power Detector- curve | 623 | * For RF5111 we have an XPD -eXternal Power Detector- curve |
657 | * for each calibrated channel. Each curve has PCDAC steps on | 624 | * for each calibrated channel. Each curve has 0,5dB Power steps |
658 | * x axis and power on y axis and looks like a logarithmic | 625 | * on x axis and PCDAC steps (offsets) on y axis and looks like an |
659 | * function. To recreate the curve and pass the power values | 626 | * exponential function. To recreate the curve we read 11 points |
660 | * on the pcdac table, we read 10 points here and interpolate later. | 627 | * here and interpolate later. |
661 | */ | 628 | */ |
629 | |||
630 | /* Used to match PCDAC steps with power values on RF5111 chips | ||
631 | * (eeprom versions < 4). For RF5111 we have 11 pre-defined PCDAC | ||
632 | * steps that match with the power values we read from eeprom. On | ||
633 | * older eeprom versions (< 3.2) these steps are equaly spaced at | ||
634 | * 10% of the pcdac curve -until the curve reaches it's maximum- | ||
635 | * (11 steps from 0 to 100%) but on newer eeprom versions (>= 3.2) | ||
636 | * these 11 steps are spaced in a different way. This function returns | ||
637 | * the pcdac steps based on eeprom version and curve min/max so that we | ||
638 | * can have pcdac/pwr points. | ||
639 | */ | ||
640 | static inline void | ||
641 | ath5k_get_pcdac_intercepts(struct ath5k_hw *ah, u8 min, u8 max, u8 *vp) | ||
642 | { | ||
643 | const static u16 intercepts3[] = | ||
644 | { 0, 5, 10, 20, 30, 50, 70, 85, 90, 95, 100 }; | ||
645 | const static u16 intercepts3_2[] = | ||
646 | { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; | ||
647 | const u16 *ip; | ||
648 | int i; | ||
649 | |||
650 | if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_2) | ||
651 | ip = intercepts3_2; | ||
652 | else | ||
653 | ip = intercepts3; | ||
654 | |||
655 | for (i = 0; i < ARRAY_SIZE(intercepts3); i++) | ||
656 | vp[i] = (ip[i] * max + (100 - ip[i]) * min) / 100; | ||
657 | } | ||
658 | |||
659 | /* Convert RF5111 specific data to generic raw data | ||
660 | * used by interpolation code */ | ||
661 | static int | ||
662 | ath5k_eeprom_convert_pcal_info_5111(struct ath5k_hw *ah, int mode, | ||
663 | struct ath5k_chan_pcal_info *chinfo) | ||
664 | { | ||
665 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; | ||
666 | struct ath5k_chan_pcal_info_rf5111 *pcinfo; | ||
667 | struct ath5k_pdgain_info *pd; | ||
668 | u8 pier, point, idx; | ||
669 | u8 *pdgain_idx = ee->ee_pdc_to_idx[mode]; | ||
670 | |||
671 | /* Fill raw data for each calibration pier */ | ||
672 | for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) { | ||
673 | |||
674 | pcinfo = &chinfo[pier].rf5111_info; | ||
675 | |||
676 | /* Allocate pd_curves for this cal pier */ | ||
677 | chinfo[pier].pd_curves = | ||
678 | kcalloc(AR5K_EEPROM_N_PD_CURVES, | ||
679 | sizeof(struct ath5k_pdgain_info), | ||
680 | GFP_KERNEL); | ||
681 | |||
682 | if (!chinfo[pier].pd_curves) | ||
683 | return -ENOMEM; | ||
684 | |||
685 | /* Only one curve for RF5111 | ||
686 | * find out which one and place | ||
687 | * in in pd_curves. | ||
688 | * Note: ee_x_gain is reversed here */ | ||
689 | for (idx = 0; idx < AR5K_EEPROM_N_PD_CURVES; idx++) { | ||
690 | |||
691 | if (!((ee->ee_x_gain[mode] >> idx) & 0x1)) { | ||
692 | pdgain_idx[0] = idx; | ||
693 | break; | ||
694 | } | ||
695 | } | ||
696 | |||
697 | ee->ee_pd_gains[mode] = 1; | ||
698 | |||
699 | pd = &chinfo[pier].pd_curves[idx]; | ||
700 | |||
701 | pd->pd_points = AR5K_EEPROM_N_PWR_POINTS_5111; | ||
702 | |||
703 | /* Allocate pd points for this curve */ | ||
704 | pd->pd_step = kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111, | ||
705 | sizeof(u8), GFP_KERNEL); | ||
706 | if (!pd->pd_step) | ||
707 | return -ENOMEM; | ||
708 | |||
709 | pd->pd_pwr = kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111, | ||
710 | sizeof(s16), GFP_KERNEL); | ||
711 | if (!pd->pd_pwr) | ||
712 | return -ENOMEM; | ||
713 | |||
714 | /* Fill raw dataset | ||
715 | * (convert power to 0.25dB units | ||
716 | * for RF5112 combatibility) */ | ||
717 | for (point = 0; point < pd->pd_points; point++) { | ||
718 | |||
719 | /* Absolute values */ | ||
720 | pd->pd_pwr[point] = 2 * pcinfo->pwr[point]; | ||
721 | |||
722 | /* Already sorted */ | ||
723 | pd->pd_step[point] = pcinfo->pcdac[point]; | ||
724 | } | ||
725 | |||
726 | /* Set min/max pwr */ | ||
727 | chinfo[pier].min_pwr = pd->pd_pwr[0]; | ||
728 | chinfo[pier].max_pwr = pd->pd_pwr[10]; | ||
729 | |||
730 | } | ||
731 | |||
732 | return 0; | ||
733 | } | ||
734 | |||
735 | /* Parse EEPROM data */ | ||
662 | static int | 736 | static int |
663 | ath5k_eeprom_read_pcal_info_5111(struct ath5k_hw *ah, int mode) | 737 | ath5k_eeprom_read_pcal_info_5111(struct ath5k_hw *ah, int mode) |
664 | { | 738 | { |
@@ -747,30 +821,165 @@ ath5k_eeprom_read_pcal_info_5111(struct ath5k_hw *ah, int mode) | |||
747 | cdata->pcdac_max, cdata->pcdac); | 821 | cdata->pcdac_max, cdata->pcdac); |
748 | } | 822 | } |
749 | 823 | ||
750 | return 0; | 824 | return ath5k_eeprom_convert_pcal_info_5111(ah, mode, pcal); |
751 | } | 825 | } |
752 | 826 | ||
753 | /* Read power calibration for RF5112 chips | 827 | |
828 | /* | ||
829 | * Read power calibration for RF5112 chips | ||
830 | * | ||
754 | * For RF5112 we have 4 XPD -eXternal Power Detector- curves | 831 | * For RF5112 we have 4 XPD -eXternal Power Detector- curves |
755 | * for each calibrated channel on 0, -6, -12 and -18dbm but we only | 832 | * for each calibrated channel on 0, -6, -12 and -18dbm but we only |
756 | * use the higher (3) and the lower (0) curves. Each curve has PCDAC | 833 | * use the higher (3) and the lower (0) curves. Each curve has 0.5dB |
757 | * steps on x axis and power on y axis and looks like a linear | 834 | * power steps on x axis and PCDAC steps on y axis and looks like a |
758 | * function. To recreate the curve and pass the power values | 835 | * linear function. To recreate the curve and pass the power values |
759 | * on the pcdac table, we read 4 points for xpd 0 and 3 points | 836 | * on hw, we read 4 points for xpd 0 (lower gain -> max power) |
760 | * for xpd 3 here and interpolate later. | 837 | * and 3 points for xpd 3 (higher gain -> lower power) here and |
838 | * interpolate later. | ||
761 | * | 839 | * |
762 | * Note: Many vendors just use xpd 0 so xpd 3 is zeroed. | 840 | * Note: Many vendors just use xpd 0 so xpd 3 is zeroed. |
763 | */ | 841 | */ |
842 | |||
843 | /* Convert RF5112 specific data to generic raw data | ||
844 | * used by interpolation code */ | ||
845 | static int | ||
846 | ath5k_eeprom_convert_pcal_info_5112(struct ath5k_hw *ah, int mode, | ||
847 | struct ath5k_chan_pcal_info *chinfo) | ||
848 | { | ||
849 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; | ||
850 | struct ath5k_chan_pcal_info_rf5112 *pcinfo; | ||
851 | u8 *pdgain_idx = ee->ee_pdc_to_idx[mode]; | ||
852 | unsigned int pier, pdg, point; | ||
853 | |||
854 | /* Fill raw data for each calibration pier */ | ||
855 | for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) { | ||
856 | |||
857 | pcinfo = &chinfo[pier].rf5112_info; | ||
858 | |||
859 | /* Allocate pd_curves for this cal pier */ | ||
860 | chinfo[pier].pd_curves = | ||
861 | kcalloc(AR5K_EEPROM_N_PD_CURVES, | ||
862 | sizeof(struct ath5k_pdgain_info), | ||
863 | GFP_KERNEL); | ||
864 | |||
865 | if (!chinfo[pier].pd_curves) | ||
866 | return -ENOMEM; | ||
867 | |||
868 | /* Fill pd_curves */ | ||
869 | for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) { | ||
870 | |||
871 | u8 idx = pdgain_idx[pdg]; | ||
872 | struct ath5k_pdgain_info *pd = | ||
873 | &chinfo[pier].pd_curves[idx]; | ||
874 | |||
875 | /* Lowest gain curve (max power) */ | ||
876 | if (pdg == 0) { | ||
877 | /* One more point for better accuracy */ | ||
878 | pd->pd_points = AR5K_EEPROM_N_XPD0_POINTS; | ||
879 | |||
880 | /* Allocate pd points for this curve */ | ||
881 | pd->pd_step = kcalloc(pd->pd_points, | ||
882 | sizeof(u8), GFP_KERNEL); | ||
883 | |||
884 | if (!pd->pd_step) | ||
885 | return -ENOMEM; | ||
886 | |||
887 | pd->pd_pwr = kcalloc(pd->pd_points, | ||
888 | sizeof(s16), GFP_KERNEL); | ||
889 | |||
890 | if (!pd->pd_pwr) | ||
891 | return -ENOMEM; | ||
892 | |||
893 | |||
894 | /* Fill raw dataset | ||
895 | * (all power levels are in 0.25dB units) */ | ||
896 | pd->pd_step[0] = pcinfo->pcdac_x0[0]; | ||
897 | pd->pd_pwr[0] = pcinfo->pwr_x0[0]; | ||
898 | |||
899 | for (point = 1; point < pd->pd_points; | ||
900 | point++) { | ||
901 | /* Absolute values */ | ||
902 | pd->pd_pwr[point] = | ||
903 | pcinfo->pwr_x0[point]; | ||
904 | |||
905 | /* Deltas */ | ||
906 | pd->pd_step[point] = | ||
907 | pd->pd_step[point - 1] + | ||
908 | pcinfo->pcdac_x0[point]; | ||
909 | } | ||
910 | |||
911 | /* Set min power for this frequency */ | ||
912 | chinfo[pier].min_pwr = pd->pd_pwr[0]; | ||
913 | |||
914 | /* Highest gain curve (min power) */ | ||
915 | } else if (pdg == 1) { | ||
916 | |||
917 | pd->pd_points = AR5K_EEPROM_N_XPD3_POINTS; | ||
918 | |||
919 | /* Allocate pd points for this curve */ | ||
920 | pd->pd_step = kcalloc(pd->pd_points, | ||
921 | sizeof(u8), GFP_KERNEL); | ||
922 | |||
923 | if (!pd->pd_step) | ||
924 | return -ENOMEM; | ||
925 | |||
926 | pd->pd_pwr = kcalloc(pd->pd_points, | ||
927 | sizeof(s16), GFP_KERNEL); | ||
928 | |||
929 | if (!pd->pd_pwr) | ||
930 | return -ENOMEM; | ||
931 | |||
932 | /* Fill raw dataset | ||
933 | * (all power levels are in 0.25dB units) */ | ||
934 | for (point = 0; point < pd->pd_points; | ||
935 | point++) { | ||
936 | /* Absolute values */ | ||
937 | pd->pd_pwr[point] = | ||
938 | pcinfo->pwr_x3[point]; | ||
939 | |||
940 | /* Fixed points */ | ||
941 | pd->pd_step[point] = | ||
942 | pcinfo->pcdac_x3[point]; | ||
943 | } | ||
944 | |||
945 | /* Since we have a higher gain curve | ||
946 | * override min power */ | ||
947 | chinfo[pier].min_pwr = pd->pd_pwr[0]; | ||
948 | } | ||
949 | } | ||
950 | } | ||
951 | |||
952 | return 0; | ||
953 | } | ||
954 | |||
955 | /* Parse EEPROM data */ | ||
764 | static int | 956 | static int |
765 | ath5k_eeprom_read_pcal_info_5112(struct ath5k_hw *ah, int mode) | 957 | ath5k_eeprom_read_pcal_info_5112(struct ath5k_hw *ah, int mode) |
766 | { | 958 | { |
767 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; | 959 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; |
768 | struct ath5k_chan_pcal_info_rf5112 *chan_pcal_info; | 960 | struct ath5k_chan_pcal_info_rf5112 *chan_pcal_info; |
769 | struct ath5k_chan_pcal_info *gen_chan_info; | 961 | struct ath5k_chan_pcal_info *gen_chan_info; |
962 | u8 *pdgain_idx = ee->ee_pdc_to_idx[mode]; | ||
770 | u32 offset; | 963 | u32 offset; |
771 | unsigned int i, c; | 964 | u8 i, c; |
772 | u16 val; | 965 | u16 val; |
773 | int ret; | 966 | int ret; |
967 | u8 pd_gains = 0; | ||
968 | |||
969 | /* Count how many curves we have and | ||
970 | * identify them (which one of the 4 | ||
971 | * available curves we have on each count). | ||
972 | * Curves are stored from lower (x0) to | ||
973 | * higher (x3) gain */ | ||
974 | for (i = 0; i < AR5K_EEPROM_N_PD_CURVES; i++) { | ||
975 | /* ee_x_gain[mode] is x gain mask */ | ||
976 | if ((ee->ee_x_gain[mode] >> i) & 0x1) | ||
977 | pdgain_idx[pd_gains++] = i; | ||
978 | } | ||
979 | ee->ee_pd_gains[mode] = pd_gains; | ||
980 | |||
981 | if (pd_gains == 0 || pd_gains > 2) | ||
982 | return -EINVAL; | ||
774 | 983 | ||
775 | switch (mode) { | 984 | switch (mode) { |
776 | case AR5K_EEPROM_MODE_11A: | 985 | case AR5K_EEPROM_MODE_11A: |
@@ -808,13 +1017,13 @@ ath5k_eeprom_read_pcal_info_5112(struct ath5k_hw *ah, int mode) | |||
808 | for (i = 0; i < ee->ee_n_piers[mode]; i++) { | 1017 | for (i = 0; i < ee->ee_n_piers[mode]; i++) { |
809 | chan_pcal_info = &gen_chan_info[i].rf5112_info; | 1018 | chan_pcal_info = &gen_chan_info[i].rf5112_info; |
810 | 1019 | ||
811 | /* Power values in dBm * 4 | 1020 | /* Power values in quarter dB |
812 | * for the lower xpd gain curve | 1021 | * for the lower xpd gain curve |
813 | * (0 dBm -> higher output power) */ | 1022 | * (0 dBm -> higher output power) */ |
814 | for (c = 0; c < AR5K_EEPROM_N_XPD0_POINTS; c++) { | 1023 | for (c = 0; c < AR5K_EEPROM_N_XPD0_POINTS; c++) { |
815 | AR5K_EEPROM_READ(offset++, val); | 1024 | AR5K_EEPROM_READ(offset++, val); |
816 | chan_pcal_info->pwr_x0[c] = (val & 0xff); | 1025 | chan_pcal_info->pwr_x0[c] = (s8) (val & 0xff); |
817 | chan_pcal_info->pwr_x0[++c] = ((val >> 8) & 0xff); | 1026 | chan_pcal_info->pwr_x0[++c] = (s8) ((val >> 8) & 0xff); |
818 | } | 1027 | } |
819 | 1028 | ||
820 | /* PCDAC steps | 1029 | /* PCDAC steps |
@@ -825,12 +1034,12 @@ ath5k_eeprom_read_pcal_info_5112(struct ath5k_hw *ah, int mode) | |||
825 | chan_pcal_info->pcdac_x0[2] = ((val >> 5) & 0x1f); | 1034 | chan_pcal_info->pcdac_x0[2] = ((val >> 5) & 0x1f); |
826 | chan_pcal_info->pcdac_x0[3] = ((val >> 10) & 0x1f); | 1035 | chan_pcal_info->pcdac_x0[3] = ((val >> 10) & 0x1f); |
827 | 1036 | ||
828 | /* Power values in dBm * 4 | 1037 | /* Power values in quarter dB |
829 | * for the higher xpd gain curve | 1038 | * for the higher xpd gain curve |
830 | * (18 dBm -> lower output power) */ | 1039 | * (18 dBm -> lower output power) */ |
831 | AR5K_EEPROM_READ(offset++, val); | 1040 | AR5K_EEPROM_READ(offset++, val); |
832 | chan_pcal_info->pwr_x3[0] = (val & 0xff); | 1041 | chan_pcal_info->pwr_x3[0] = (s8) (val & 0xff); |
833 | chan_pcal_info->pwr_x3[1] = ((val >> 8) & 0xff); | 1042 | chan_pcal_info->pwr_x3[1] = (s8) ((val >> 8) & 0xff); |
834 | 1043 | ||
835 | AR5K_EEPROM_READ(offset++, val); | 1044 | AR5K_EEPROM_READ(offset++, val); |
836 | chan_pcal_info->pwr_x3[2] = (val & 0xff); | 1045 | chan_pcal_info->pwr_x3[2] = (val & 0xff); |
@@ -843,24 +1052,36 @@ ath5k_eeprom_read_pcal_info_5112(struct ath5k_hw *ah, int mode) | |||
843 | chan_pcal_info->pcdac_x3[2] = 63; | 1052 | chan_pcal_info->pcdac_x3[2] = 63; |
844 | 1053 | ||
845 | if (ee->ee_version >= AR5K_EEPROM_VERSION_4_3) { | 1054 | if (ee->ee_version >= AR5K_EEPROM_VERSION_4_3) { |
846 | chan_pcal_info->pcdac_x0[0] = ((val >> 8) & 0xff); | 1055 | chan_pcal_info->pcdac_x0[0] = ((val >> 8) & 0x3f); |
847 | 1056 | ||
848 | /* Last xpd0 power level is also channel maximum */ | 1057 | /* Last xpd0 power level is also channel maximum */ |
849 | gen_chan_info[i].max_pwr = chan_pcal_info->pwr_x0[3]; | 1058 | gen_chan_info[i].max_pwr = chan_pcal_info->pwr_x0[3]; |
850 | } else { | 1059 | } else { |
851 | chan_pcal_info->pcdac_x0[0] = 1; | 1060 | chan_pcal_info->pcdac_x0[0] = 1; |
852 | gen_chan_info[i].max_pwr = ((val >> 8) & 0xff); | 1061 | gen_chan_info[i].max_pwr = (s8) ((val >> 8) & 0xff); |
853 | } | 1062 | } |
854 | 1063 | ||
855 | /* Recreate pcdac_x0 table for this channel using pcdac steps */ | ||
856 | chan_pcal_info->pcdac_x0[1] += chan_pcal_info->pcdac_x0[0]; | ||
857 | chan_pcal_info->pcdac_x0[2] += chan_pcal_info->pcdac_x0[1]; | ||
858 | chan_pcal_info->pcdac_x0[3] += chan_pcal_info->pcdac_x0[2]; | ||
859 | } | 1064 | } |
860 | 1065 | ||
861 | return 0; | 1066 | return ath5k_eeprom_convert_pcal_info_5112(ah, mode, gen_chan_info); |
862 | } | 1067 | } |
863 | 1068 | ||
1069 | |||
1070 | /* | ||
1071 | * Read power calibration for RF2413 chips | ||
1072 | * | ||
1073 | * For RF2413 we have a Power to PDDAC table (Power Detector) | ||
1074 | * instead of a PCDAC and 4 pd gain curves for each calibrated channel. | ||
1075 | * Each curve has power on x axis in 0.5 db steps and PDDADC steps on y | ||
1076 | * axis and looks like an exponential function like the RF5111 curve. | ||
1077 | * | ||
1078 | * To recreate the curves we read here the points and interpolate | ||
1079 | * later. Note that in most cases only 2 (higher and lower) curves are | ||
1080 | * used (like RF5112) but vendors have the oportunity to include all | ||
1081 | * 4 curves on eeprom. The final curve (higher power) has an extra | ||
1082 | * point for better accuracy like RF5112. | ||
1083 | */ | ||
1084 | |||
864 | /* For RF2413 power calibration data doesn't start on a fixed location and | 1085 | /* For RF2413 power calibration data doesn't start on a fixed location and |
865 | * if a mode is not supported, it's section is missing -not zeroed-. | 1086 | * if a mode is not supported, it's section is missing -not zeroed-. |
866 | * So we need to calculate the starting offset for each section by using | 1087 | * So we need to calculate the starting offset for each section by using |
@@ -890,13 +1111,15 @@ ath5k_cal_data_offset_2413(struct ath5k_eeprom_info *ee, int mode) | |||
890 | switch(mode) { | 1111 | switch(mode) { |
891 | case AR5K_EEPROM_MODE_11G: | 1112 | case AR5K_EEPROM_MODE_11G: |
892 | if (AR5K_EEPROM_HDR_11B(ee->ee_header)) | 1113 | if (AR5K_EEPROM_HDR_11B(ee->ee_header)) |
893 | offset += ath5k_pdgains_size_2413(ee, AR5K_EEPROM_MODE_11B) + | 1114 | offset += ath5k_pdgains_size_2413(ee, |
894 | AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2; | 1115 | AR5K_EEPROM_MODE_11B) + |
1116 | AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2; | ||
895 | /* fall through */ | 1117 | /* fall through */ |
896 | case AR5K_EEPROM_MODE_11B: | 1118 | case AR5K_EEPROM_MODE_11B: |
897 | if (AR5K_EEPROM_HDR_11A(ee->ee_header)) | 1119 | if (AR5K_EEPROM_HDR_11A(ee->ee_header)) |
898 | offset += ath5k_pdgains_size_2413(ee, AR5K_EEPROM_MODE_11A) + | 1120 | offset += ath5k_pdgains_size_2413(ee, |
899 | AR5K_EEPROM_N_5GHZ_CHAN / 2; | 1121 | AR5K_EEPROM_MODE_11A) + |
1122 | AR5K_EEPROM_N_5GHZ_CHAN / 2; | ||
900 | /* fall through */ | 1123 | /* fall through */ |
901 | case AR5K_EEPROM_MODE_11A: | 1124 | case AR5K_EEPROM_MODE_11A: |
902 | break; | 1125 | break; |
@@ -907,37 +1130,118 @@ ath5k_cal_data_offset_2413(struct ath5k_eeprom_info *ee, int mode) | |||
907 | return offset; | 1130 | return offset; |
908 | } | 1131 | } |
909 | 1132 | ||
910 | /* Read power calibration for RF2413 chips | 1133 | /* Convert RF2413 specific data to generic raw data |
911 | * For RF2413 we have a PDDAC table (Power Detector) instead | 1134 | * used by interpolation code */ |
912 | * of a PCDAC and 4 pd gain curves for each calibrated channel. | 1135 | static int |
913 | * Each curve has PDDAC steps on x axis and power on y axis and | 1136 | ath5k_eeprom_convert_pcal_info_2413(struct ath5k_hw *ah, int mode, |
914 | * looks like an exponential function. To recreate the curves | 1137 | struct ath5k_chan_pcal_info *chinfo) |
915 | * we read here the points and interpolate later. Note that | 1138 | { |
916 | * in most cases only higher and lower curves are used (like | 1139 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; |
917 | * RF5112) but vendors have the oportunity to include all 4 | 1140 | struct ath5k_chan_pcal_info_rf2413 *pcinfo; |
918 | * curves on eeprom. The final curve (higher power) has an extra | 1141 | u8 *pdgain_idx = ee->ee_pdc_to_idx[mode]; |
919 | * point for better accuracy like RF5112. | 1142 | unsigned int pier, pdg, point; |
920 | */ | 1143 | |
1144 | /* Fill raw data for each calibration pier */ | ||
1145 | for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) { | ||
1146 | |||
1147 | pcinfo = &chinfo[pier].rf2413_info; | ||
1148 | |||
1149 | /* Allocate pd_curves for this cal pier */ | ||
1150 | chinfo[pier].pd_curves = | ||
1151 | kcalloc(AR5K_EEPROM_N_PD_CURVES, | ||
1152 | sizeof(struct ath5k_pdgain_info), | ||
1153 | GFP_KERNEL); | ||
1154 | |||
1155 | if (!chinfo[pier].pd_curves) | ||
1156 | return -ENOMEM; | ||
1157 | |||
1158 | /* Fill pd_curves */ | ||
1159 | for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) { | ||
1160 | |||
1161 | u8 idx = pdgain_idx[pdg]; | ||
1162 | struct ath5k_pdgain_info *pd = | ||
1163 | &chinfo[pier].pd_curves[idx]; | ||
1164 | |||
1165 | /* One more point for the highest power | ||
1166 | * curve (lowest gain) */ | ||
1167 | if (pdg == ee->ee_pd_gains[mode] - 1) | ||
1168 | pd->pd_points = AR5K_EEPROM_N_PD_POINTS; | ||
1169 | else | ||
1170 | pd->pd_points = AR5K_EEPROM_N_PD_POINTS - 1; | ||
1171 | |||
1172 | /* Allocate pd points for this curve */ | ||
1173 | pd->pd_step = kcalloc(pd->pd_points, | ||
1174 | sizeof(u8), GFP_KERNEL); | ||
1175 | |||
1176 | if (!pd->pd_step) | ||
1177 | return -ENOMEM; | ||
1178 | |||
1179 | pd->pd_pwr = kcalloc(pd->pd_points, | ||
1180 | sizeof(s16), GFP_KERNEL); | ||
1181 | |||
1182 | if (!pd->pd_pwr) | ||
1183 | return -ENOMEM; | ||
1184 | |||
1185 | /* Fill raw dataset | ||
1186 | * convert all pwr levels to | ||
1187 | * quarter dB for RF5112 combatibility */ | ||
1188 | pd->pd_step[0] = pcinfo->pddac_i[pdg]; | ||
1189 | pd->pd_pwr[0] = 4 * pcinfo->pwr_i[pdg]; | ||
1190 | |||
1191 | for (point = 1; point < pd->pd_points; point++) { | ||
1192 | |||
1193 | pd->pd_pwr[point] = pd->pd_pwr[point - 1] + | ||
1194 | 2 * pcinfo->pwr[pdg][point - 1]; | ||
1195 | |||
1196 | pd->pd_step[point] = pd->pd_step[point - 1] + | ||
1197 | pcinfo->pddac[pdg][point - 1]; | ||
1198 | |||
1199 | } | ||
1200 | |||
1201 | /* Highest gain curve -> min power */ | ||
1202 | if (pdg == 0) | ||
1203 | chinfo[pier].min_pwr = pd->pd_pwr[0]; | ||
1204 | |||
1205 | /* Lowest gain curve -> max power */ | ||
1206 | if (pdg == ee->ee_pd_gains[mode] - 1) | ||
1207 | chinfo[pier].max_pwr = | ||
1208 | pd->pd_pwr[pd->pd_points - 1]; | ||
1209 | } | ||
1210 | } | ||
1211 | |||
1212 | return 0; | ||
1213 | } | ||
1214 | |||
1215 | /* Parse EEPROM data */ | ||
921 | static int | 1216 | static int |
922 | ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode) | 1217 | ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode) |
923 | { | 1218 | { |
924 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; | 1219 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; |
925 | struct ath5k_chan_pcal_info_rf2413 *chan_pcal_info; | 1220 | struct ath5k_chan_pcal_info_rf2413 *pcinfo; |
926 | struct ath5k_chan_pcal_info *gen_chan_info; | 1221 | struct ath5k_chan_pcal_info *chinfo; |
927 | unsigned int i, c; | 1222 | u8 *pdgain_idx = ee->ee_pdc_to_idx[mode]; |
928 | u32 offset; | 1223 | u32 offset; |
929 | int ret; | 1224 | int idx, i, ret; |
930 | u16 val; | 1225 | u16 val; |
931 | u8 pd_gains = 0; | 1226 | u8 pd_gains = 0; |
932 | 1227 | ||
933 | if (ee->ee_x_gain[mode] & 0x1) pd_gains++; | 1228 | /* Count how many curves we have and |
934 | if ((ee->ee_x_gain[mode] >> 1) & 0x1) pd_gains++; | 1229 | * identify them (which one of the 4 |
935 | if ((ee->ee_x_gain[mode] >> 2) & 0x1) pd_gains++; | 1230 | * available curves we have on each count). |
936 | if ((ee->ee_x_gain[mode] >> 3) & 0x1) pd_gains++; | 1231 | * Curves are stored from higher to |
1232 | * lower gain so we go backwards */ | ||
1233 | for (idx = AR5K_EEPROM_N_PD_CURVES - 1; idx >= 0; idx--) { | ||
1234 | /* ee_x_gain[mode] is x gain mask */ | ||
1235 | if ((ee->ee_x_gain[mode] >> idx) & 0x1) | ||
1236 | pdgain_idx[pd_gains++] = idx; | ||
1237 | |||
1238 | } | ||
937 | ee->ee_pd_gains[mode] = pd_gains; | 1239 | ee->ee_pd_gains[mode] = pd_gains; |
938 | 1240 | ||
1241 | if (pd_gains == 0) | ||
1242 | return -EINVAL; | ||
1243 | |||
939 | offset = ath5k_cal_data_offset_2413(ee, mode); | 1244 | offset = ath5k_cal_data_offset_2413(ee, mode); |
940 | ee->ee_n_piers[mode] = 0; | ||
941 | switch (mode) { | 1245 | switch (mode) { |
942 | case AR5K_EEPROM_MODE_11A: | 1246 | case AR5K_EEPROM_MODE_11A: |
943 | if (!AR5K_EEPROM_HDR_11A(ee->ee_header)) | 1247 | if (!AR5K_EEPROM_HDR_11A(ee->ee_header)) |
@@ -945,7 +1249,7 @@ ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode) | |||
945 | 1249 | ||
946 | ath5k_eeprom_init_11a_pcal_freq(ah, offset); | 1250 | ath5k_eeprom_init_11a_pcal_freq(ah, offset); |
947 | offset += AR5K_EEPROM_N_5GHZ_CHAN / 2; | 1251 | offset += AR5K_EEPROM_N_5GHZ_CHAN / 2; |
948 | gen_chan_info = ee->ee_pwr_cal_a; | 1252 | chinfo = ee->ee_pwr_cal_a; |
949 | break; | 1253 | break; |
950 | case AR5K_EEPROM_MODE_11B: | 1254 | case AR5K_EEPROM_MODE_11B: |
951 | if (!AR5K_EEPROM_HDR_11B(ee->ee_header)) | 1255 | if (!AR5K_EEPROM_HDR_11B(ee->ee_header)) |
@@ -953,7 +1257,7 @@ ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode) | |||
953 | 1257 | ||
954 | ath5k_eeprom_init_11bg_2413(ah, mode, offset); | 1258 | ath5k_eeprom_init_11bg_2413(ah, mode, offset); |
955 | offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2; | 1259 | offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2; |
956 | gen_chan_info = ee->ee_pwr_cal_b; | 1260 | chinfo = ee->ee_pwr_cal_b; |
957 | break; | 1261 | break; |
958 | case AR5K_EEPROM_MODE_11G: | 1262 | case AR5K_EEPROM_MODE_11G: |
959 | if (!AR5K_EEPROM_HDR_11G(ee->ee_header)) | 1263 | if (!AR5K_EEPROM_HDR_11G(ee->ee_header)) |
@@ -961,41 +1265,35 @@ ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode) | |||
961 | 1265 | ||
962 | ath5k_eeprom_init_11bg_2413(ah, mode, offset); | 1266 | ath5k_eeprom_init_11bg_2413(ah, mode, offset); |
963 | offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2; | 1267 | offset += AR5K_EEPROM_N_2GHZ_CHAN_2413 / 2; |
964 | gen_chan_info = ee->ee_pwr_cal_g; | 1268 | chinfo = ee->ee_pwr_cal_g; |
965 | break; | 1269 | break; |
966 | default: | 1270 | default: |
967 | return -EINVAL; | 1271 | return -EINVAL; |
968 | } | 1272 | } |
969 | 1273 | ||
970 | if (pd_gains == 0) | ||
971 | return 0; | ||
972 | |||
973 | for (i = 0; i < ee->ee_n_piers[mode]; i++) { | 1274 | for (i = 0; i < ee->ee_n_piers[mode]; i++) { |
974 | chan_pcal_info = &gen_chan_info[i].rf2413_info; | 1275 | pcinfo = &chinfo[i].rf2413_info; |
975 | 1276 | ||
976 | /* | 1277 | /* |
977 | * Read pwr_i, pddac_i and the first | 1278 | * Read pwr_i, pddac_i and the first |
978 | * 2 pd points (pwr, pddac) | 1279 | * 2 pd points (pwr, pddac) |
979 | */ | 1280 | */ |
980 | AR5K_EEPROM_READ(offset++, val); | 1281 | AR5K_EEPROM_READ(offset++, val); |
981 | chan_pcal_info->pwr_i[0] = val & 0x1f; | 1282 | pcinfo->pwr_i[0] = val & 0x1f; |
982 | chan_pcal_info->pddac_i[0] = (val >> 5) & 0x7f; | 1283 | pcinfo->pddac_i[0] = (val >> 5) & 0x7f; |
983 | chan_pcal_info->pwr[0][0] = | 1284 | pcinfo->pwr[0][0] = (val >> 12) & 0xf; |
984 | (val >> 12) & 0xf; | ||
985 | 1285 | ||
986 | AR5K_EEPROM_READ(offset++, val); | 1286 | AR5K_EEPROM_READ(offset++, val); |
987 | chan_pcal_info->pddac[0][0] = val & 0x3f; | 1287 | pcinfo->pddac[0][0] = val & 0x3f; |
988 | chan_pcal_info->pwr[0][1] = (val >> 6) & 0xf; | 1288 | pcinfo->pwr[0][1] = (val >> 6) & 0xf; |
989 | chan_pcal_info->pddac[0][1] = | 1289 | pcinfo->pddac[0][1] = (val >> 10) & 0x3f; |
990 | (val >> 10) & 0x3f; | ||
991 | 1290 | ||
992 | AR5K_EEPROM_READ(offset++, val); | 1291 | AR5K_EEPROM_READ(offset++, val); |
993 | chan_pcal_info->pwr[0][2] = val & 0xf; | 1292 | pcinfo->pwr[0][2] = val & 0xf; |
994 | chan_pcal_info->pddac[0][2] = | 1293 | pcinfo->pddac[0][2] = (val >> 4) & 0x3f; |
995 | (val >> 4) & 0x3f; | ||
996 | 1294 | ||
997 | chan_pcal_info->pwr[0][3] = 0; | 1295 | pcinfo->pwr[0][3] = 0; |
998 | chan_pcal_info->pddac[0][3] = 0; | 1296 | pcinfo->pddac[0][3] = 0; |
999 | 1297 | ||
1000 | if (pd_gains > 1) { | 1298 | if (pd_gains > 1) { |
1001 | /* | 1299 | /* |
@@ -1003,44 +1301,36 @@ ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode) | |||
1003 | * so it only has 2 pd points. | 1301 | * so it only has 2 pd points. |
1004 | * Continue wih pd gain 1. | 1302 | * Continue wih pd gain 1. |
1005 | */ | 1303 | */ |
1006 | chan_pcal_info->pwr_i[1] = (val >> 10) & 0x1f; | 1304 | pcinfo->pwr_i[1] = (val >> 10) & 0x1f; |
1007 | 1305 | ||
1008 | chan_pcal_info->pddac_i[1] = (val >> 15) & 0x1; | 1306 | pcinfo->pddac_i[1] = (val >> 15) & 0x1; |
1009 | AR5K_EEPROM_READ(offset++, val); | 1307 | AR5K_EEPROM_READ(offset++, val); |
1010 | chan_pcal_info->pddac_i[1] |= (val & 0x3F) << 1; | 1308 | pcinfo->pddac_i[1] |= (val & 0x3F) << 1; |
1011 | 1309 | ||
1012 | chan_pcal_info->pwr[1][0] = (val >> 6) & 0xf; | 1310 | pcinfo->pwr[1][0] = (val >> 6) & 0xf; |
1013 | chan_pcal_info->pddac[1][0] = | 1311 | pcinfo->pddac[1][0] = (val >> 10) & 0x3f; |
1014 | (val >> 10) & 0x3f; | ||
1015 | 1312 | ||
1016 | AR5K_EEPROM_READ(offset++, val); | 1313 | AR5K_EEPROM_READ(offset++, val); |
1017 | chan_pcal_info->pwr[1][1] = val & 0xf; | 1314 | pcinfo->pwr[1][1] = val & 0xf; |
1018 | chan_pcal_info->pddac[1][1] = | 1315 | pcinfo->pddac[1][1] = (val >> 4) & 0x3f; |
1019 | (val >> 4) & 0x3f; | 1316 | pcinfo->pwr[1][2] = (val >> 10) & 0xf; |
1020 | chan_pcal_info->pwr[1][2] = | 1317 | |
1021 | (val >> 10) & 0xf; | 1318 | pcinfo->pddac[1][2] = (val >> 14) & 0x3; |
1022 | |||
1023 | chan_pcal_info->pddac[1][2] = | ||
1024 | (val >> 14) & 0x3; | ||
1025 | AR5K_EEPROM_READ(offset++, val); | 1319 | AR5K_EEPROM_READ(offset++, val); |
1026 | chan_pcal_info->pddac[1][2] |= | 1320 | pcinfo->pddac[1][2] |= (val & 0xF) << 2; |
1027 | (val & 0xF) << 2; | ||
1028 | 1321 | ||
1029 | chan_pcal_info->pwr[1][3] = 0; | 1322 | pcinfo->pwr[1][3] = 0; |
1030 | chan_pcal_info->pddac[1][3] = 0; | 1323 | pcinfo->pddac[1][3] = 0; |
1031 | } else if (pd_gains == 1) { | 1324 | } else if (pd_gains == 1) { |
1032 | /* | 1325 | /* |
1033 | * Pd gain 0 is the last one so | 1326 | * Pd gain 0 is the last one so |
1034 | * read the extra point. | 1327 | * read the extra point. |
1035 | */ | 1328 | */ |
1036 | chan_pcal_info->pwr[0][3] = | 1329 | pcinfo->pwr[0][3] = (val >> 10) & 0xf; |
1037 | (val >> 10) & 0xf; | ||
1038 | 1330 | ||
1039 | chan_pcal_info->pddac[0][3] = | 1331 | pcinfo->pddac[0][3] = (val >> 14) & 0x3; |
1040 | (val >> 14) & 0x3; | ||
1041 | AR5K_EEPROM_READ(offset++, val); | 1332 | AR5K_EEPROM_READ(offset++, val); |
1042 | chan_pcal_info->pddac[0][3] |= | 1333 | pcinfo->pddac[0][3] |= (val & 0xF) << 2; |
1043 | (val & 0xF) << 2; | ||
1044 | } | 1334 | } |
1045 | 1335 | ||
1046 | /* | 1336 | /* |
@@ -1048,105 +1338,65 @@ ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode) | |||
1048 | * as above. | 1338 | * as above. |
1049 | */ | 1339 | */ |
1050 | if (pd_gains > 2) { | 1340 | if (pd_gains > 2) { |
1051 | chan_pcal_info->pwr_i[2] = (val >> 4) & 0x1f; | 1341 | pcinfo->pwr_i[2] = (val >> 4) & 0x1f; |
1052 | chan_pcal_info->pddac_i[2] = (val >> 9) & 0x7f; | 1342 | pcinfo->pddac_i[2] = (val >> 9) & 0x7f; |
1053 | 1343 | ||
1054 | AR5K_EEPROM_READ(offset++, val); | 1344 | AR5K_EEPROM_READ(offset++, val); |
1055 | chan_pcal_info->pwr[2][0] = | 1345 | pcinfo->pwr[2][0] = (val >> 0) & 0xf; |
1056 | (val >> 0) & 0xf; | 1346 | pcinfo->pddac[2][0] = (val >> 4) & 0x3f; |
1057 | chan_pcal_info->pddac[2][0] = | 1347 | pcinfo->pwr[2][1] = (val >> 10) & 0xf; |
1058 | (val >> 4) & 0x3f; | 1348 | |
1059 | chan_pcal_info->pwr[2][1] = | 1349 | pcinfo->pddac[2][1] = (val >> 14) & 0x3; |
1060 | (val >> 10) & 0xf; | ||
1061 | |||
1062 | chan_pcal_info->pddac[2][1] = | ||
1063 | (val >> 14) & 0x3; | ||
1064 | AR5K_EEPROM_READ(offset++, val); | 1350 | AR5K_EEPROM_READ(offset++, val); |
1065 | chan_pcal_info->pddac[2][1] |= | 1351 | pcinfo->pddac[2][1] |= (val & 0xF) << 2; |
1066 | (val & 0xF) << 2; | ||
1067 | 1352 | ||
1068 | chan_pcal_info->pwr[2][2] = | 1353 | pcinfo->pwr[2][2] = (val >> 4) & 0xf; |
1069 | (val >> 4) & 0xf; | 1354 | pcinfo->pddac[2][2] = (val >> 8) & 0x3f; |
1070 | chan_pcal_info->pddac[2][2] = | ||
1071 | (val >> 8) & 0x3f; | ||
1072 | 1355 | ||
1073 | chan_pcal_info->pwr[2][3] = 0; | 1356 | pcinfo->pwr[2][3] = 0; |
1074 | chan_pcal_info->pddac[2][3] = 0; | 1357 | pcinfo->pddac[2][3] = 0; |
1075 | } else if (pd_gains == 2) { | 1358 | } else if (pd_gains == 2) { |
1076 | chan_pcal_info->pwr[1][3] = | 1359 | pcinfo->pwr[1][3] = (val >> 4) & 0xf; |
1077 | (val >> 4) & 0xf; | 1360 | pcinfo->pddac[1][3] = (val >> 8) & 0x3f; |
1078 | chan_pcal_info->pddac[1][3] = | ||
1079 | (val >> 8) & 0x3f; | ||
1080 | } | 1361 | } |
1081 | 1362 | ||
1082 | if (pd_gains > 3) { | 1363 | if (pd_gains > 3) { |
1083 | chan_pcal_info->pwr_i[3] = (val >> 14) & 0x3; | 1364 | pcinfo->pwr_i[3] = (val >> 14) & 0x3; |
1084 | AR5K_EEPROM_READ(offset++, val); | 1365 | AR5K_EEPROM_READ(offset++, val); |
1085 | chan_pcal_info->pwr_i[3] |= ((val >> 0) & 0x7) << 2; | 1366 | pcinfo->pwr_i[3] |= ((val >> 0) & 0x7) << 2; |
1086 | 1367 | ||
1087 | chan_pcal_info->pddac_i[3] = (val >> 3) & 0x7f; | 1368 | pcinfo->pddac_i[3] = (val >> 3) & 0x7f; |
1088 | chan_pcal_info->pwr[3][0] = | 1369 | pcinfo->pwr[3][0] = (val >> 10) & 0xf; |
1089 | (val >> 10) & 0xf; | 1370 | pcinfo->pddac[3][0] = (val >> 14) & 0x3; |
1090 | chan_pcal_info->pddac[3][0] = | ||
1091 | (val >> 14) & 0x3; | ||
1092 | 1371 | ||
1093 | AR5K_EEPROM_READ(offset++, val); | 1372 | AR5K_EEPROM_READ(offset++, val); |
1094 | chan_pcal_info->pddac[3][0] |= | 1373 | pcinfo->pddac[3][0] |= (val & 0xF) << 2; |
1095 | (val & 0xF) << 2; | 1374 | pcinfo->pwr[3][1] = (val >> 4) & 0xf; |
1096 | chan_pcal_info->pwr[3][1] = | 1375 | pcinfo->pddac[3][1] = (val >> 8) & 0x3f; |
1097 | (val >> 4) & 0xf; | 1376 | |
1098 | chan_pcal_info->pddac[3][1] = | 1377 | pcinfo->pwr[3][2] = (val >> 14) & 0x3; |
1099 | (val >> 8) & 0x3f; | ||
1100 | |||
1101 | chan_pcal_info->pwr[3][2] = | ||
1102 | (val >> 14) & 0x3; | ||
1103 | AR5K_EEPROM_READ(offset++, val); | 1378 | AR5K_EEPROM_READ(offset++, val); |
1104 | chan_pcal_info->pwr[3][2] |= | 1379 | pcinfo->pwr[3][2] |= ((val >> 0) & 0x3) << 2; |
1105 | ((val >> 0) & 0x3) << 2; | ||
1106 | 1380 | ||
1107 | chan_pcal_info->pddac[3][2] = | 1381 | pcinfo->pddac[3][2] = (val >> 2) & 0x3f; |
1108 | (val >> 2) & 0x3f; | 1382 | pcinfo->pwr[3][3] = (val >> 8) & 0xf; |
1109 | chan_pcal_info->pwr[3][3] = | ||
1110 | (val >> 8) & 0xf; | ||
1111 | 1383 | ||
1112 | chan_pcal_info->pddac[3][3] = | 1384 | pcinfo->pddac[3][3] = (val >> 12) & 0xF; |
1113 | (val >> 12) & 0xF; | ||
1114 | AR5K_EEPROM_READ(offset++, val); | 1385 | AR5K_EEPROM_READ(offset++, val); |
1115 | chan_pcal_info->pddac[3][3] |= | 1386 | pcinfo->pddac[3][3] |= ((val >> 0) & 0x3) << 4; |
1116 | ((val >> 0) & 0x3) << 4; | ||
1117 | } else if (pd_gains == 3) { | 1387 | } else if (pd_gains == 3) { |
1118 | chan_pcal_info->pwr[2][3] = | 1388 | pcinfo->pwr[2][3] = (val >> 14) & 0x3; |
1119 | (val >> 14) & 0x3; | ||
1120 | AR5K_EEPROM_READ(offset++, val); | 1389 | AR5K_EEPROM_READ(offset++, val); |
1121 | chan_pcal_info->pwr[2][3] |= | 1390 | pcinfo->pwr[2][3] |= ((val >> 0) & 0x3) << 2; |
1122 | ((val >> 0) & 0x3) << 2; | ||
1123 | |||
1124 | chan_pcal_info->pddac[2][3] = | ||
1125 | (val >> 2) & 0x3f; | ||
1126 | } | ||
1127 | 1391 | ||
1128 | for (c = 0; c < pd_gains; c++) { | 1392 | pcinfo->pddac[2][3] = (val >> 2) & 0x3f; |
1129 | /* Recreate pwr table for this channel using pwr steps */ | ||
1130 | chan_pcal_info->pwr[c][0] += chan_pcal_info->pwr_i[c] * 2; | ||
1131 | chan_pcal_info->pwr[c][1] += chan_pcal_info->pwr[c][0]; | ||
1132 | chan_pcal_info->pwr[c][2] += chan_pcal_info->pwr[c][1]; | ||
1133 | chan_pcal_info->pwr[c][3] += chan_pcal_info->pwr[c][2]; | ||
1134 | if (chan_pcal_info->pwr[c][3] == chan_pcal_info->pwr[c][2]) | ||
1135 | chan_pcal_info->pwr[c][3] = 0; | ||
1136 | |||
1137 | /* Recreate pddac table for this channel using pddac steps */ | ||
1138 | chan_pcal_info->pddac[c][0] += chan_pcal_info->pddac_i[c]; | ||
1139 | chan_pcal_info->pddac[c][1] += chan_pcal_info->pddac[c][0]; | ||
1140 | chan_pcal_info->pddac[c][2] += chan_pcal_info->pddac[c][1]; | ||
1141 | chan_pcal_info->pddac[c][3] += chan_pcal_info->pddac[c][2]; | ||
1142 | if (chan_pcal_info->pddac[c][3] == chan_pcal_info->pddac[c][2]) | ||
1143 | chan_pcal_info->pddac[c][3] = 0; | ||
1144 | } | 1393 | } |
1145 | } | 1394 | } |
1146 | 1395 | ||
1147 | return 0; | 1396 | return ath5k_eeprom_convert_pcal_info_2413(ah, mode, chinfo); |
1148 | } | 1397 | } |
1149 | 1398 | ||
1399 | |||
1150 | /* | 1400 | /* |
1151 | * Read per rate target power (this is the maximum tx power | 1401 | * Read per rate target power (this is the maximum tx power |
1152 | * supported by the card). This info is used when setting | 1402 | * supported by the card). This info is used when setting |
@@ -1154,11 +1404,12 @@ ath5k_eeprom_read_pcal_info_2413(struct ath5k_hw *ah, int mode) | |||
1154 | * | 1404 | * |
1155 | * This also works for v5 EEPROMs. | 1405 | * This also works for v5 EEPROMs. |
1156 | */ | 1406 | */ |
1157 | static int ath5k_eeprom_read_target_rate_pwr_info(struct ath5k_hw *ah, unsigned int mode) | 1407 | static int |
1408 | ath5k_eeprom_read_target_rate_pwr_info(struct ath5k_hw *ah, unsigned int mode) | ||
1158 | { | 1409 | { |
1159 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; | 1410 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; |
1160 | struct ath5k_rate_pcal_info *rate_pcal_info; | 1411 | struct ath5k_rate_pcal_info *rate_pcal_info; |
1161 | u16 *rate_target_pwr_num; | 1412 | u8 *rate_target_pwr_num; |
1162 | u32 offset; | 1413 | u32 offset; |
1163 | u16 val; | 1414 | u16 val; |
1164 | int ret, i; | 1415 | int ret, i; |
@@ -1264,7 +1515,9 @@ ath5k_eeprom_read_pcal_info(struct ath5k_hw *ah) | |||
1264 | else | 1515 | else |
1265 | read_pcal = ath5k_eeprom_read_pcal_info_5111; | 1516 | read_pcal = ath5k_eeprom_read_pcal_info_5111; |
1266 | 1517 | ||
1267 | for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; mode++) { | 1518 | |
1519 | for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; | ||
1520 | mode++) { | ||
1268 | err = read_pcal(ah, mode); | 1521 | err = read_pcal(ah, mode); |
1269 | if (err) | 1522 | if (err) |
1270 | return err; | 1523 | return err; |
@@ -1277,6 +1530,62 @@ ath5k_eeprom_read_pcal_info(struct ath5k_hw *ah) | |||
1277 | return 0; | 1530 | return 0; |
1278 | } | 1531 | } |
1279 | 1532 | ||
1533 | static int | ||
1534 | ath5k_eeprom_free_pcal_info(struct ath5k_hw *ah, int mode) | ||
1535 | { | ||
1536 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; | ||
1537 | struct ath5k_chan_pcal_info *chinfo; | ||
1538 | u8 pier, pdg; | ||
1539 | |||
1540 | switch (mode) { | ||
1541 | case AR5K_EEPROM_MODE_11A: | ||
1542 | if (!AR5K_EEPROM_HDR_11A(ee->ee_header)) | ||
1543 | return 0; | ||
1544 | chinfo = ee->ee_pwr_cal_a; | ||
1545 | break; | ||
1546 | case AR5K_EEPROM_MODE_11B: | ||
1547 | if (!AR5K_EEPROM_HDR_11B(ee->ee_header)) | ||
1548 | return 0; | ||
1549 | chinfo = ee->ee_pwr_cal_b; | ||
1550 | break; | ||
1551 | case AR5K_EEPROM_MODE_11G: | ||
1552 | if (!AR5K_EEPROM_HDR_11G(ee->ee_header)) | ||
1553 | return 0; | ||
1554 | chinfo = ee->ee_pwr_cal_g; | ||
1555 | break; | ||
1556 | default: | ||
1557 | return -EINVAL; | ||
1558 | } | ||
1559 | |||
1560 | for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) { | ||
1561 | if (!chinfo[pier].pd_curves) | ||
1562 | continue; | ||
1563 | |||
1564 | for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) { | ||
1565 | struct ath5k_pdgain_info *pd = | ||
1566 | &chinfo[pier].pd_curves[pdg]; | ||
1567 | |||
1568 | if (pd != NULL) { | ||
1569 | kfree(pd->pd_step); | ||
1570 | kfree(pd->pd_pwr); | ||
1571 | } | ||
1572 | } | ||
1573 | |||
1574 | kfree(chinfo[pier].pd_curves); | ||
1575 | } | ||
1576 | |||
1577 | return 0; | ||
1578 | } | ||
1579 | |||
1580 | void | ||
1581 | ath5k_eeprom_detach(struct ath5k_hw *ah) | ||
1582 | { | ||
1583 | u8 mode; | ||
1584 | |||
1585 | for (mode = AR5K_EEPROM_MODE_11A; mode <= AR5K_EEPROM_MODE_11G; mode++) | ||
1586 | ath5k_eeprom_free_pcal_info(ah, mode); | ||
1587 | } | ||
1588 | |||
1280 | /* Read conformance test limits used for regulatory control */ | 1589 | /* Read conformance test limits used for regulatory control */ |
1281 | static int | 1590 | static int |
1282 | ath5k_eeprom_read_ctl_info(struct ath5k_hw *ah) | 1591 | ath5k_eeprom_read_ctl_info(struct ath5k_hw *ah) |
@@ -1457,3 +1766,4 @@ bool ath5k_eeprom_is_hb63(struct ath5k_hw *ah) | |||
1457 | else | 1766 | else |
1458 | return false; | 1767 | return false; |
1459 | } | 1768 | } |
1769 | |||
diff --git a/drivers/net/wireless/ath5k/eeprom.h b/drivers/net/wireless/ath5k/eeprom.h index 1deebc0257d4..b0c0606dea0b 100644 --- a/drivers/net/wireless/ath5k/eeprom.h +++ b/drivers/net/wireless/ath5k/eeprom.h | |||
@@ -173,6 +173,7 @@ | |||
173 | #define AR5K_EEPROM_N_5GHZ_CHAN 10 | 173 | #define AR5K_EEPROM_N_5GHZ_CHAN 10 |
174 | #define AR5K_EEPROM_N_2GHZ_CHAN 3 | 174 | #define AR5K_EEPROM_N_2GHZ_CHAN 3 |
175 | #define AR5K_EEPROM_N_2GHZ_CHAN_2413 4 | 175 | #define AR5K_EEPROM_N_2GHZ_CHAN_2413 4 |
176 | #define AR5K_EEPROM_N_2GHZ_CHAN_MAX 4 | ||
176 | #define AR5K_EEPROM_MAX_CHAN 10 | 177 | #define AR5K_EEPROM_MAX_CHAN 10 |
177 | #define AR5K_EEPROM_N_PWR_POINTS_5111 11 | 178 | #define AR5K_EEPROM_N_PWR_POINTS_5111 11 |
178 | #define AR5K_EEPROM_N_PCDAC 11 | 179 | #define AR5K_EEPROM_N_PCDAC 11 |
@@ -193,7 +194,7 @@ | |||
193 | #define AR5K_EEPROM_SCALE_OC_DELTA(_x) (((_x) * 2) / 10) | 194 | #define AR5K_EEPROM_SCALE_OC_DELTA(_x) (((_x) * 2) / 10) |
194 | #define AR5K_EEPROM_N_CTLS(_v) AR5K_EEPROM_OFF(_v, 16, 32) | 195 | #define AR5K_EEPROM_N_CTLS(_v) AR5K_EEPROM_OFF(_v, 16, 32) |
195 | #define AR5K_EEPROM_MAX_CTLS 32 | 196 | #define AR5K_EEPROM_MAX_CTLS 32 |
196 | #define AR5K_EEPROM_N_XPD_PER_CHANNEL 4 | 197 | #define AR5K_EEPROM_N_PD_CURVES 4 |
197 | #define AR5K_EEPROM_N_XPD0_POINTS 4 | 198 | #define AR5K_EEPROM_N_XPD0_POINTS 4 |
198 | #define AR5K_EEPROM_N_XPD3_POINTS 3 | 199 | #define AR5K_EEPROM_N_XPD3_POINTS 3 |
199 | #define AR5K_EEPROM_N_PD_GAINS 4 | 200 | #define AR5K_EEPROM_N_PD_GAINS 4 |
@@ -232,7 +233,7 @@ enum ath5k_ctl_mode { | |||
232 | AR5K_CTL_11B = 1, | 233 | AR5K_CTL_11B = 1, |
233 | AR5K_CTL_11G = 2, | 234 | AR5K_CTL_11G = 2, |
234 | AR5K_CTL_TURBO = 3, | 235 | AR5K_CTL_TURBO = 3, |
235 | AR5K_CTL_108G = 4, | 236 | AR5K_CTL_TURBOG = 4, |
236 | AR5K_CTL_2GHT20 = 5, | 237 | AR5K_CTL_2GHT20 = 5, |
237 | AR5K_CTL_5GHT20 = 6, | 238 | AR5K_CTL_5GHT20 = 6, |
238 | AR5K_CTL_2GHT40 = 7, | 239 | AR5K_CTL_2GHT40 = 7, |
@@ -240,65 +241,114 @@ enum ath5k_ctl_mode { | |||
240 | AR5K_CTL_MODE_M = 15, | 241 | AR5K_CTL_MODE_M = 15, |
241 | }; | 242 | }; |
242 | 243 | ||
244 | /* Default CTL ids for the 3 main reg domains. | ||
245 | * Atheros only uses these by default but vendors | ||
246 | * can have up to 32 different CTLs for different | ||
247 | * scenarios. Note that theese values are ORed with | ||
248 | * the mode id (above) so we can have up to 24 CTL | ||
249 | * datasets out of these 3 main regdomains. That leaves | ||
250 | * 8 ids that can be used by vendors and since 0x20 is | ||
251 | * missing from HAL sources i guess this is the set of | ||
252 | * custom CTLs vendors can use. */ | ||
253 | #define AR5K_CTL_FCC 0x10 | ||
254 | #define AR5K_CTL_CUSTOM 0x20 | ||
255 | #define AR5K_CTL_ETSI 0x30 | ||
256 | #define AR5K_CTL_MKK 0x40 | ||
257 | |||
258 | /* Indicates a CTL with only mode set and | ||
259 | * no reg domain mapping, such CTLs are used | ||
260 | * for world roaming domains or simply when | ||
261 | * a reg domain is not set */ | ||
262 | #define AR5K_CTL_NO_REGDOMAIN 0xf0 | ||
263 | |||
264 | /* Indicates an empty (invalid) CTL */ | ||
265 | #define AR5K_CTL_NO_CTL 0xff | ||
266 | |||
243 | /* Per channel calibration data, used for power table setup */ | 267 | /* Per channel calibration data, used for power table setup */ |
244 | struct ath5k_chan_pcal_info_rf5111 { | 268 | struct ath5k_chan_pcal_info_rf5111 { |
245 | /* Power levels in half dbm units | 269 | /* Power levels in half dbm units |
246 | * for one power curve. */ | 270 | * for one power curve. */ |
247 | u8 pwr[AR5K_EEPROM_N_PWR_POINTS_5111]; | 271 | u8 pwr[AR5K_EEPROM_N_PWR_POINTS_5111]; |
248 | /* PCDAC table steps | 272 | /* PCDAC table steps |
249 | * for the above values */ | 273 | * for the above values */ |
250 | u8 pcdac[AR5K_EEPROM_N_PWR_POINTS_5111]; | 274 | u8 pcdac[AR5K_EEPROM_N_PWR_POINTS_5111]; |
251 | /* Starting PCDAC step */ | 275 | /* Starting PCDAC step */ |
252 | u8 pcdac_min; | 276 | u8 pcdac_min; |
253 | /* Final PCDAC step */ | 277 | /* Final PCDAC step */ |
254 | u8 pcdac_max; | 278 | u8 pcdac_max; |
255 | }; | 279 | }; |
256 | 280 | ||
257 | struct ath5k_chan_pcal_info_rf5112 { | 281 | struct ath5k_chan_pcal_info_rf5112 { |
258 | /* Power levels in quarter dBm units | 282 | /* Power levels in quarter dBm units |
259 | * for lower (0) and higher (3) | 283 | * for lower (0) and higher (3) |
260 | * level curves */ | 284 | * level curves in 0.25dB units */ |
261 | s8 pwr_x0[AR5K_EEPROM_N_XPD0_POINTS]; | 285 | s8 pwr_x0[AR5K_EEPROM_N_XPD0_POINTS]; |
262 | s8 pwr_x3[AR5K_EEPROM_N_XPD3_POINTS]; | 286 | s8 pwr_x3[AR5K_EEPROM_N_XPD3_POINTS]; |
263 | /* PCDAC table steps | 287 | /* PCDAC table steps |
264 | * for the above values */ | 288 | * for the above values */ |
265 | u8 pcdac_x0[AR5K_EEPROM_N_XPD0_POINTS]; | 289 | u8 pcdac_x0[AR5K_EEPROM_N_XPD0_POINTS]; |
266 | u8 pcdac_x3[AR5K_EEPROM_N_XPD3_POINTS]; | 290 | u8 pcdac_x3[AR5K_EEPROM_N_XPD3_POINTS]; |
267 | }; | 291 | }; |
268 | 292 | ||
269 | struct ath5k_chan_pcal_info_rf2413 { | 293 | struct ath5k_chan_pcal_info_rf2413 { |
270 | /* Starting pwr/pddac values */ | 294 | /* Starting pwr/pddac values */ |
271 | s8 pwr_i[AR5K_EEPROM_N_PD_GAINS]; | 295 | s8 pwr_i[AR5K_EEPROM_N_PD_GAINS]; |
272 | u8 pddac_i[AR5K_EEPROM_N_PD_GAINS]; | 296 | u8 pddac_i[AR5K_EEPROM_N_PD_GAINS]; |
273 | /* (pwr,pddac) points */ | 297 | /* (pwr,pddac) points |
274 | s8 pwr[AR5K_EEPROM_N_PD_GAINS] | 298 | * power levels in 0.5dB units */ |
275 | [AR5K_EEPROM_N_PD_POINTS]; | 299 | s8 pwr[AR5K_EEPROM_N_PD_GAINS] |
276 | u8 pddac[AR5K_EEPROM_N_PD_GAINS] | 300 | [AR5K_EEPROM_N_PD_POINTS]; |
277 | [AR5K_EEPROM_N_PD_POINTS]; | 301 | u8 pddac[AR5K_EEPROM_N_PD_GAINS] |
302 | [AR5K_EEPROM_N_PD_POINTS]; | ||
303 | }; | ||
304 | |||
305 | enum ath5k_powertable_type { | ||
306 | AR5K_PWRTABLE_PWR_TO_PCDAC = 0, | ||
307 | AR5K_PWRTABLE_LINEAR_PCDAC = 1, | ||
308 | AR5K_PWRTABLE_PWR_TO_PDADC = 2, | ||
309 | }; | ||
310 | |||
311 | struct ath5k_pdgain_info { | ||
312 | u8 pd_points; | ||
313 | u8 *pd_step; | ||
314 | /* Power values are in | ||
315 | * 0.25dB units */ | ||
316 | s16 *pd_pwr; | ||
278 | }; | 317 | }; |
279 | 318 | ||
280 | struct ath5k_chan_pcal_info { | 319 | struct ath5k_chan_pcal_info { |
281 | /* Frequency */ | 320 | /* Frequency */ |
282 | u16 freq; | 321 | u16 freq; |
283 | /* Max available power */ | 322 | /* Tx power boundaries */ |
284 | s8 max_pwr; | 323 | s16 max_pwr; |
324 | s16 min_pwr; | ||
285 | union { | 325 | union { |
286 | struct ath5k_chan_pcal_info_rf5111 rf5111_info; | 326 | struct ath5k_chan_pcal_info_rf5111 rf5111_info; |
287 | struct ath5k_chan_pcal_info_rf5112 rf5112_info; | 327 | struct ath5k_chan_pcal_info_rf5112 rf5112_info; |
288 | struct ath5k_chan_pcal_info_rf2413 rf2413_info; | 328 | struct ath5k_chan_pcal_info_rf2413 rf2413_info; |
289 | }; | 329 | }; |
330 | /* Raw values used by phy code | ||
331 | * Curves are stored in order from lower | ||
332 | * gain to higher gain (max txpower -> min txpower) */ | ||
333 | struct ath5k_pdgain_info *pd_curves; | ||
290 | }; | 334 | }; |
291 | 335 | ||
292 | /* Per rate calibration data for each mode, used for power table setup */ | 336 | /* Per rate calibration data for each mode, |
337 | * used for rate power table setup. | ||
338 | * Note: Values in 0.5dB units */ | ||
293 | struct ath5k_rate_pcal_info { | 339 | struct ath5k_rate_pcal_info { |
294 | u16 freq; /* Frequency */ | 340 | u16 freq; /* Frequency */ |
295 | /* Power level for 6-24Mbit/s rates */ | 341 | /* Power level for 6-24Mbit/s rates or |
342 | * 1Mb rate */ | ||
296 | u16 target_power_6to24; | 343 | u16 target_power_6to24; |
297 | /* Power level for 36Mbit rate */ | 344 | /* Power level for 36Mbit rate or |
345 | * 2Mb rate */ | ||
298 | u16 target_power_36; | 346 | u16 target_power_36; |
299 | /* Power level for 48Mbit rate */ | 347 | /* Power level for 48Mbit rate or |
348 | * 5.5Mbit rate */ | ||
300 | u16 target_power_48; | 349 | u16 target_power_48; |
301 | /* Power level for 54Mbit rate */ | 350 | /* Power level for 54Mbit rate or |
351 | * 11Mbit rate */ | ||
302 | u16 target_power_54; | 352 | u16 target_power_54; |
303 | }; | 353 | }; |
304 | 354 | ||
@@ -330,12 +380,6 @@ struct ath5k_eeprom_info { | |||
330 | u16 ee_cck_ofdm_power_delta; | 380 | u16 ee_cck_ofdm_power_delta; |
331 | u16 ee_scaled_cck_delta; | 381 | u16 ee_scaled_cck_delta; |
332 | 382 | ||
333 | /* Used for tx thermal adjustment (eeprom_init, rfregs) */ | ||
334 | u16 ee_tx_clip; | ||
335 | u16 ee_pwd_84; | ||
336 | u16 ee_pwd_90; | ||
337 | u16 ee_gain_select; | ||
338 | |||
339 | /* RF Calibration settings (reset, rfregs) */ | 383 | /* RF Calibration settings (reset, rfregs) */ |
340 | u16 ee_i_cal[AR5K_EEPROM_N_MODES]; | 384 | u16 ee_i_cal[AR5K_EEPROM_N_MODES]; |
341 | u16 ee_q_cal[AR5K_EEPROM_N_MODES]; | 385 | u16 ee_q_cal[AR5K_EEPROM_N_MODES]; |
@@ -363,23 +407,25 @@ struct ath5k_eeprom_info { | |||
363 | /* Power calibration data */ | 407 | /* Power calibration data */ |
364 | u16 ee_false_detect[AR5K_EEPROM_N_MODES]; | 408 | u16 ee_false_detect[AR5K_EEPROM_N_MODES]; |
365 | 409 | ||
366 | /* Number of pd gain curves per mode (RF2413) */ | 410 | /* Number of pd gain curves per mode */ |
367 | u8 ee_pd_gains[AR5K_EEPROM_N_MODES]; | 411 | u8 ee_pd_gains[AR5K_EEPROM_N_MODES]; |
412 | /* Back mapping pdcurve number -> pdcurve index in pd->pd_curves */ | ||
413 | u8 ee_pdc_to_idx[AR5K_EEPROM_N_MODES][AR5K_EEPROM_N_PD_GAINS]; | ||
368 | 414 | ||
369 | u8 ee_n_piers[AR5K_EEPROM_N_MODES]; | 415 | u8 ee_n_piers[AR5K_EEPROM_N_MODES]; |
370 | struct ath5k_chan_pcal_info ee_pwr_cal_a[AR5K_EEPROM_N_5GHZ_CHAN]; | 416 | struct ath5k_chan_pcal_info ee_pwr_cal_a[AR5K_EEPROM_N_5GHZ_CHAN]; |
371 | struct ath5k_chan_pcal_info ee_pwr_cal_b[AR5K_EEPROM_N_2GHZ_CHAN]; | 417 | struct ath5k_chan_pcal_info ee_pwr_cal_b[AR5K_EEPROM_N_2GHZ_CHAN_MAX]; |
372 | struct ath5k_chan_pcal_info ee_pwr_cal_g[AR5K_EEPROM_N_2GHZ_CHAN]; | 418 | struct ath5k_chan_pcal_info ee_pwr_cal_g[AR5K_EEPROM_N_2GHZ_CHAN_MAX]; |
373 | 419 | ||
374 | /* Per rate target power levels */ | 420 | /* Per rate target power levels */ |
375 | u16 ee_rate_target_pwr_num[AR5K_EEPROM_N_MODES]; | 421 | u8 ee_rate_target_pwr_num[AR5K_EEPROM_N_MODES]; |
376 | struct ath5k_rate_pcal_info ee_rate_tpwr_a[AR5K_EEPROM_N_5GHZ_CHAN]; | 422 | struct ath5k_rate_pcal_info ee_rate_tpwr_a[AR5K_EEPROM_N_5GHZ_CHAN]; |
377 | struct ath5k_rate_pcal_info ee_rate_tpwr_b[AR5K_EEPROM_N_2GHZ_CHAN]; | 423 | struct ath5k_rate_pcal_info ee_rate_tpwr_b[AR5K_EEPROM_N_2GHZ_CHAN_MAX]; |
378 | struct ath5k_rate_pcal_info ee_rate_tpwr_g[AR5K_EEPROM_N_2GHZ_CHAN]; | 424 | struct ath5k_rate_pcal_info ee_rate_tpwr_g[AR5K_EEPROM_N_2GHZ_CHAN_MAX]; |
379 | 425 | ||
380 | /* Conformance test limits (Unused) */ | 426 | /* Conformance test limits (Unused) */ |
381 | u16 ee_ctls; | 427 | u8 ee_ctls; |
382 | u16 ee_ctl[AR5K_EEPROM_MAX_CTLS]; | 428 | u8 ee_ctl[AR5K_EEPROM_MAX_CTLS]; |
383 | struct ath5k_edge_power ee_ctl_pwr[AR5K_EEPROM_N_EDGES * AR5K_EEPROM_MAX_CTLS]; | 429 | struct ath5k_edge_power ee_ctl_pwr[AR5K_EEPROM_N_EDGES * AR5K_EEPROM_MAX_CTLS]; |
384 | 430 | ||
385 | /* Noise Floor Calibration settings */ | 431 | /* Noise Floor Calibration settings */ |
diff --git a/drivers/net/wireless/ath5k/initvals.c b/drivers/net/wireless/ath5k/initvals.c index 44886434187b..61fb621ed20d 100644 --- a/drivers/net/wireless/ath5k/initvals.c +++ b/drivers/net/wireless/ath5k/initvals.c | |||
@@ -1510,8 +1510,8 @@ int ath5k_hw_write_initvals(struct ath5k_hw *ah, u8 mode, bool change_channel) | |||
1510 | rf2425_ini_mode_end, mode); | 1510 | rf2425_ini_mode_end, mode); |
1511 | 1511 | ||
1512 | ath5k_hw_ini_registers(ah, | 1512 | ath5k_hw_ini_registers(ah, |
1513 | ARRAY_SIZE(rf2413_ini_common_end), | 1513 | ARRAY_SIZE(rf2425_ini_common_end), |
1514 | rf2413_ini_common_end, change_channel); | 1514 | rf2425_ini_common_end, change_channel); |
1515 | 1515 | ||
1516 | ath5k_hw_ini_registers(ah, | 1516 | ath5k_hw_ini_registers(ah, |
1517 | ARRAY_SIZE(rf5112_ini_bbgain), | 1517 | ARRAY_SIZE(rf5112_ini_bbgain), |
diff --git a/drivers/net/wireless/ath5k/led.c b/drivers/net/wireless/ath5k/led.c index 0686e12738b3..19555fb79c9b 100644 --- a/drivers/net/wireless/ath5k/led.c +++ b/drivers/net/wireless/ath5k/led.c | |||
@@ -65,6 +65,8 @@ static const struct pci_device_id ath5k_led_devices[] = { | |||
65 | { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0422), ATH_LED(1, 1) }, | 65 | { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0422), ATH_LED(1, 1) }, |
66 | /* E-machines E510 (tuliom@gmail.com) */ | 66 | /* E-machines E510 (tuliom@gmail.com) */ |
67 | { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0428), ATH_LED(3, 0) }, | 67 | { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0428), ATH_LED(3, 0) }, |
68 | /* Acer Extensa 5620z (nekoreeve@gmail.com) */ | ||
69 | { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0105), ATH_LED(3, 0) }, | ||
68 | { } | 70 | { } |
69 | }; | 71 | }; |
70 | 72 | ||
diff --git a/drivers/net/wireless/ath5k/phy.c b/drivers/net/wireless/ath5k/phy.c index 81f5bebc48b1..9e2faae5ae94 100644 --- a/drivers/net/wireless/ath5k/phy.c +++ b/drivers/net/wireless/ath5k/phy.c | |||
@@ -4,6 +4,7 @@ | |||
4 | * Copyright (c) 2004-2007 Reyk Floeter <reyk@openbsd.org> | 4 | * Copyright (c) 2004-2007 Reyk Floeter <reyk@openbsd.org> |
5 | * Copyright (c) 2006-2009 Nick Kossifidis <mickflemm@gmail.com> | 5 | * Copyright (c) 2006-2009 Nick Kossifidis <mickflemm@gmail.com> |
6 | * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com> | 6 | * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com> |
7 | * Copyright (c) 2008-2009 Felix Fietkau <nbd@openwrt.org> | ||
7 | * | 8 | * |
8 | * Permission to use, copy, modify, and distribute this software for any | 9 | * Permission to use, copy, modify, and distribute this software for any |
9 | * purpose with or without fee is hereby granted, provided that the above | 10 | * purpose with or without fee is hereby granted, provided that the above |
@@ -183,7 +184,9 @@ static void ath5k_hw_request_rfgain_probe(struct ath5k_hw *ah) | |||
183 | if (ah->ah_gain.g_state != AR5K_RFGAIN_ACTIVE) | 184 | if (ah->ah_gain.g_state != AR5K_RFGAIN_ACTIVE) |
184 | return; | 185 | return; |
185 | 186 | ||
186 | ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txpower.txp_max, | 187 | /* Send the packet with 2dB below max power as |
188 | * patent doc suggest */ | ||
189 | ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txpower.txp_max_pwr - 4, | ||
187 | AR5K_PHY_PAPD_PROBE_TXPOWER) | | 190 | AR5K_PHY_PAPD_PROBE_TXPOWER) | |
188 | AR5K_PHY_PAPD_PROBE_TX_NEXT, AR5K_PHY_PAPD_PROBE); | 191 | AR5K_PHY_PAPD_PROBE_TX_NEXT, AR5K_PHY_PAPD_PROBE); |
189 | 192 | ||
@@ -1433,93 +1436,1120 @@ unsigned int ath5k_hw_get_def_antenna(struct ath5k_hw *ah) | |||
1433 | return false; /*XXX: What do we return for 5210 ?*/ | 1436 | return false; /*XXX: What do we return for 5210 ?*/ |
1434 | } | 1437 | } |
1435 | 1438 | ||
1439 | |||
1440 | /****************\ | ||
1441 | * TX power setup * | ||
1442 | \****************/ | ||
1443 | |||
1444 | /* | ||
1445 | * Helper functions | ||
1446 | */ | ||
1447 | |||
1448 | /* | ||
1449 | * Do linear interpolation between two given (x, y) points | ||
1450 | */ | ||
1451 | static s16 | ||
1452 | ath5k_get_interpolated_value(s16 target, s16 x_left, s16 x_right, | ||
1453 | s16 y_left, s16 y_right) | ||
1454 | { | ||
1455 | s16 ratio, result; | ||
1456 | |||
1457 | /* Avoid divide by zero and skip interpolation | ||
1458 | * if we have the same point */ | ||
1459 | if ((x_left == x_right) || (y_left == y_right)) | ||
1460 | return y_left; | ||
1461 | |||
1462 | /* | ||
1463 | * Since we use ints and not fps, we need to scale up in | ||
1464 | * order to get a sane ratio value (or else we 'll eg. get | ||
1465 | * always 1 instead of 1.25, 1.75 etc). We scale up by 100 | ||
1466 | * to have some accuracy both for 0.5 and 0.25 steps. | ||
1467 | */ | ||
1468 | ratio = ((100 * y_right - 100 * y_left)/(x_right - x_left)); | ||
1469 | |||
1470 | /* Now scale down to be in range */ | ||
1471 | result = y_left + (ratio * (target - x_left) / 100); | ||
1472 | |||
1473 | return result; | ||
1474 | } | ||
1475 | |||
1476 | /* | ||
1477 | * Find vertical boundary (min pwr) for the linear PCDAC curve. | ||
1478 | * | ||
1479 | * Since we have the top of the curve and we draw the line below | ||
1480 | * until we reach 1 (1 pcdac step) we need to know which point | ||
1481 | * (x value) that is so that we don't go below y axis and have negative | ||
1482 | * pcdac values when creating the curve, or fill the table with zeroes. | ||
1483 | */ | ||
1484 | static s16 | ||
1485 | ath5k_get_linear_pcdac_min(const u8 *stepL, const u8 *stepR, | ||
1486 | const s16 *pwrL, const s16 *pwrR) | ||
1487 | { | ||
1488 | s8 tmp; | ||
1489 | s16 min_pwrL, min_pwrR; | ||
1490 | s16 pwr_i = pwrL[0]; | ||
1491 | |||
1492 | do { | ||
1493 | pwr_i--; | ||
1494 | tmp = (s8) ath5k_get_interpolated_value(pwr_i, | ||
1495 | pwrL[0], pwrL[1], | ||
1496 | stepL[0], stepL[1]); | ||
1497 | |||
1498 | } while (tmp > 1); | ||
1499 | |||
1500 | min_pwrL = pwr_i; | ||
1501 | |||
1502 | pwr_i = pwrR[0]; | ||
1503 | do { | ||
1504 | pwr_i--; | ||
1505 | tmp = (s8) ath5k_get_interpolated_value(pwr_i, | ||
1506 | pwrR[0], pwrR[1], | ||
1507 | stepR[0], stepR[1]); | ||
1508 | |||
1509 | } while (tmp > 1); | ||
1510 | |||
1511 | min_pwrR = pwr_i; | ||
1512 | |||
1513 | /* Keep the right boundary so that it works for both curves */ | ||
1514 | return max(min_pwrL, min_pwrR); | ||
1515 | } | ||
1516 | |||
1517 | /* | ||
1518 | * Interpolate (pwr,vpd) points to create a Power to PDADC or a | ||
1519 | * Power to PCDAC curve. | ||
1520 | * | ||
1521 | * Each curve has power on x axis (in 0.5dB units) and PCDAC/PDADC | ||
1522 | * steps (offsets) on y axis. Power can go up to 31.5dB and max | ||
1523 | * PCDAC/PDADC step for each curve is 64 but we can write more than | ||
1524 | * one curves on hw so we can go up to 128 (which is the max step we | ||
1525 | * can write on the final table). | ||
1526 | * | ||
1527 | * We write y values (PCDAC/PDADC steps) on hw. | ||
1528 | */ | ||
1529 | static void | ||
1530 | ath5k_create_power_curve(s16 pmin, s16 pmax, | ||
1531 | const s16 *pwr, const u8 *vpd, | ||
1532 | u8 num_points, | ||
1533 | u8 *vpd_table, u8 type) | ||
1534 | { | ||
1535 | u8 idx[2] = { 0, 1 }; | ||
1536 | s16 pwr_i = 2*pmin; | ||
1537 | int i; | ||
1538 | |||
1539 | if (num_points < 2) | ||
1540 | return; | ||
1541 | |||
1542 | /* We want the whole line, so adjust boundaries | ||
1543 | * to cover the entire power range. Note that | ||
1544 | * power values are already 0.25dB so no need | ||
1545 | * to multiply pwr_i by 2 */ | ||
1546 | if (type == AR5K_PWRTABLE_LINEAR_PCDAC) { | ||
1547 | pwr_i = pmin; | ||
1548 | pmin = 0; | ||
1549 | pmax = 63; | ||
1550 | } | ||
1551 | |||
1552 | /* Find surrounding turning points (TPs) | ||
1553 | * and interpolate between them */ | ||
1554 | for (i = 0; (i <= (u16) (pmax - pmin)) && | ||
1555 | (i < AR5K_EEPROM_POWER_TABLE_SIZE); i++) { | ||
1556 | |||
1557 | /* We passed the right TP, move to the next set of TPs | ||
1558 | * if we pass the last TP, extrapolate above using the last | ||
1559 | * two TPs for ratio */ | ||
1560 | if ((pwr_i > pwr[idx[1]]) && (idx[1] < num_points - 1)) { | ||
1561 | idx[0]++; | ||
1562 | idx[1]++; | ||
1563 | } | ||
1564 | |||
1565 | vpd_table[i] = (u8) ath5k_get_interpolated_value(pwr_i, | ||
1566 | pwr[idx[0]], pwr[idx[1]], | ||
1567 | vpd[idx[0]], vpd[idx[1]]); | ||
1568 | |||
1569 | /* Increase by 0.5dB | ||
1570 | * (0.25 dB units) */ | ||
1571 | pwr_i += 2; | ||
1572 | } | ||
1573 | } | ||
1574 | |||
1575 | /* | ||
1576 | * Get the surrounding per-channel power calibration piers | ||
1577 | * for a given frequency so that we can interpolate between | ||
1578 | * them and come up with an apropriate dataset for our current | ||
1579 | * channel. | ||
1580 | */ | ||
1581 | static void | ||
1582 | ath5k_get_chan_pcal_surrounding_piers(struct ath5k_hw *ah, | ||
1583 | struct ieee80211_channel *channel, | ||
1584 | struct ath5k_chan_pcal_info **pcinfo_l, | ||
1585 | struct ath5k_chan_pcal_info **pcinfo_r) | ||
1586 | { | ||
1587 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; | ||
1588 | struct ath5k_chan_pcal_info *pcinfo; | ||
1589 | u8 idx_l, idx_r; | ||
1590 | u8 mode, max, i; | ||
1591 | u32 target = channel->center_freq; | ||
1592 | |||
1593 | idx_l = 0; | ||
1594 | idx_r = 0; | ||
1595 | |||
1596 | if (!(channel->hw_value & CHANNEL_OFDM)) { | ||
1597 | pcinfo = ee->ee_pwr_cal_b; | ||
1598 | mode = AR5K_EEPROM_MODE_11B; | ||
1599 | } else if (channel->hw_value & CHANNEL_2GHZ) { | ||
1600 | pcinfo = ee->ee_pwr_cal_g; | ||
1601 | mode = AR5K_EEPROM_MODE_11G; | ||
1602 | } else { | ||
1603 | pcinfo = ee->ee_pwr_cal_a; | ||
1604 | mode = AR5K_EEPROM_MODE_11A; | ||
1605 | } | ||
1606 | max = ee->ee_n_piers[mode] - 1; | ||
1607 | |||
1608 | /* Frequency is below our calibrated | ||
1609 | * range. Use the lowest power curve | ||
1610 | * we have */ | ||
1611 | if (target < pcinfo[0].freq) { | ||
1612 | idx_l = idx_r = 0; | ||
1613 | goto done; | ||
1614 | } | ||
1615 | |||
1616 | /* Frequency is above our calibrated | ||
1617 | * range. Use the highest power curve | ||
1618 | * we have */ | ||
1619 | if (target > pcinfo[max].freq) { | ||
1620 | idx_l = idx_r = max; | ||
1621 | goto done; | ||
1622 | } | ||
1623 | |||
1624 | /* Frequency is inside our calibrated | ||
1625 | * channel range. Pick the surrounding | ||
1626 | * calibration piers so that we can | ||
1627 | * interpolate */ | ||
1628 | for (i = 0; i <= max; i++) { | ||
1629 | |||
1630 | /* Frequency matches one of our calibration | ||
1631 | * piers, no need to interpolate, just use | ||
1632 | * that calibration pier */ | ||
1633 | if (pcinfo[i].freq == target) { | ||
1634 | idx_l = idx_r = i; | ||
1635 | goto done; | ||
1636 | } | ||
1637 | |||
1638 | /* We found a calibration pier that's above | ||
1639 | * frequency, use this pier and the previous | ||
1640 | * one to interpolate */ | ||
1641 | if (target < pcinfo[i].freq) { | ||
1642 | idx_r = i; | ||
1643 | idx_l = idx_r - 1; | ||
1644 | goto done; | ||
1645 | } | ||
1646 | } | ||
1647 | |||
1648 | done: | ||
1649 | *pcinfo_l = &pcinfo[idx_l]; | ||
1650 | *pcinfo_r = &pcinfo[idx_r]; | ||
1651 | |||
1652 | return; | ||
1653 | } | ||
1654 | |||
1655 | /* | ||
1656 | * Get the surrounding per-rate power calibration data | ||
1657 | * for a given frequency and interpolate between power | ||
1658 | * values to set max target power supported by hw for | ||
1659 | * each rate. | ||
1660 | */ | ||
1661 | static void | ||
1662 | ath5k_get_rate_pcal_data(struct ath5k_hw *ah, | ||
1663 | struct ieee80211_channel *channel, | ||
1664 | struct ath5k_rate_pcal_info *rates) | ||
1665 | { | ||
1666 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; | ||
1667 | struct ath5k_rate_pcal_info *rpinfo; | ||
1668 | u8 idx_l, idx_r; | ||
1669 | u8 mode, max, i; | ||
1670 | u32 target = channel->center_freq; | ||
1671 | |||
1672 | idx_l = 0; | ||
1673 | idx_r = 0; | ||
1674 | |||
1675 | if (!(channel->hw_value & CHANNEL_OFDM)) { | ||
1676 | rpinfo = ee->ee_rate_tpwr_b; | ||
1677 | mode = AR5K_EEPROM_MODE_11B; | ||
1678 | } else if (channel->hw_value & CHANNEL_2GHZ) { | ||
1679 | rpinfo = ee->ee_rate_tpwr_g; | ||
1680 | mode = AR5K_EEPROM_MODE_11G; | ||
1681 | } else { | ||
1682 | rpinfo = ee->ee_rate_tpwr_a; | ||
1683 | mode = AR5K_EEPROM_MODE_11A; | ||
1684 | } | ||
1685 | max = ee->ee_rate_target_pwr_num[mode] - 1; | ||
1686 | |||
1687 | /* Get the surrounding calibration | ||
1688 | * piers - same as above */ | ||
1689 | if (target < rpinfo[0].freq) { | ||
1690 | idx_l = idx_r = 0; | ||
1691 | goto done; | ||
1692 | } | ||
1693 | |||
1694 | if (target > rpinfo[max].freq) { | ||
1695 | idx_l = idx_r = max; | ||
1696 | goto done; | ||
1697 | } | ||
1698 | |||
1699 | for (i = 0; i <= max; i++) { | ||
1700 | |||
1701 | if (rpinfo[i].freq == target) { | ||
1702 | idx_l = idx_r = i; | ||
1703 | goto done; | ||
1704 | } | ||
1705 | |||
1706 | if (target < rpinfo[i].freq) { | ||
1707 | idx_r = i; | ||
1708 | idx_l = idx_r - 1; | ||
1709 | goto done; | ||
1710 | } | ||
1711 | } | ||
1712 | |||
1713 | done: | ||
1714 | /* Now interpolate power value, based on the frequency */ | ||
1715 | rates->freq = target; | ||
1716 | |||
1717 | rates->target_power_6to24 = | ||
1718 | ath5k_get_interpolated_value(target, rpinfo[idx_l].freq, | ||
1719 | rpinfo[idx_r].freq, | ||
1720 | rpinfo[idx_l].target_power_6to24, | ||
1721 | rpinfo[idx_r].target_power_6to24); | ||
1722 | |||
1723 | rates->target_power_36 = | ||
1724 | ath5k_get_interpolated_value(target, rpinfo[idx_l].freq, | ||
1725 | rpinfo[idx_r].freq, | ||
1726 | rpinfo[idx_l].target_power_36, | ||
1727 | rpinfo[idx_r].target_power_36); | ||
1728 | |||
1729 | rates->target_power_48 = | ||
1730 | ath5k_get_interpolated_value(target, rpinfo[idx_l].freq, | ||
1731 | rpinfo[idx_r].freq, | ||
1732 | rpinfo[idx_l].target_power_48, | ||
1733 | rpinfo[idx_r].target_power_48); | ||
1734 | |||
1735 | rates->target_power_54 = | ||
1736 | ath5k_get_interpolated_value(target, rpinfo[idx_l].freq, | ||
1737 | rpinfo[idx_r].freq, | ||
1738 | rpinfo[idx_l].target_power_54, | ||
1739 | rpinfo[idx_r].target_power_54); | ||
1740 | } | ||
1741 | |||
1742 | /* | ||
1743 | * Get the max edge power for this channel if | ||
1744 | * we have such data from EEPROM's Conformance Test | ||
1745 | * Limits (CTL), and limit max power if needed. | ||
1746 | * | ||
1747 | * FIXME: Only works for world regulatory domains | ||
1748 | */ | ||
1749 | static void | ||
1750 | ath5k_get_max_ctl_power(struct ath5k_hw *ah, | ||
1751 | struct ieee80211_channel *channel) | ||
1752 | { | ||
1753 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; | ||
1754 | struct ath5k_edge_power *rep = ee->ee_ctl_pwr; | ||
1755 | u8 *ctl_val = ee->ee_ctl; | ||
1756 | s16 max_chan_pwr = ah->ah_txpower.txp_max_pwr / 4; | ||
1757 | s16 edge_pwr = 0; | ||
1758 | u8 rep_idx; | ||
1759 | u8 i, ctl_mode; | ||
1760 | u8 ctl_idx = 0xFF; | ||
1761 | u32 target = channel->center_freq; | ||
1762 | |||
1763 | /* Find out a CTL for our mode that's not mapped | ||
1764 | * on a specific reg domain. | ||
1765 | * | ||
1766 | * TODO: Map our current reg domain to one of the 3 available | ||
1767 | * reg domain ids so that we can support more CTLs. */ | ||
1768 | switch (channel->hw_value & CHANNEL_MODES) { | ||
1769 | case CHANNEL_A: | ||
1770 | ctl_mode = AR5K_CTL_11A | AR5K_CTL_NO_REGDOMAIN; | ||
1771 | break; | ||
1772 | case CHANNEL_G: | ||
1773 | ctl_mode = AR5K_CTL_11G | AR5K_CTL_NO_REGDOMAIN; | ||
1774 | break; | ||
1775 | case CHANNEL_B: | ||
1776 | ctl_mode = AR5K_CTL_11B | AR5K_CTL_NO_REGDOMAIN; | ||
1777 | break; | ||
1778 | case CHANNEL_T: | ||
1779 | ctl_mode = AR5K_CTL_TURBO | AR5K_CTL_NO_REGDOMAIN; | ||
1780 | break; | ||
1781 | case CHANNEL_TG: | ||
1782 | ctl_mode = AR5K_CTL_TURBOG | AR5K_CTL_NO_REGDOMAIN; | ||
1783 | break; | ||
1784 | case CHANNEL_XR: | ||
1785 | /* Fall through */ | ||
1786 | default: | ||
1787 | return; | ||
1788 | } | ||
1789 | |||
1790 | for (i = 0; i < ee->ee_ctls; i++) { | ||
1791 | if (ctl_val[i] == ctl_mode) { | ||
1792 | ctl_idx = i; | ||
1793 | break; | ||
1794 | } | ||
1795 | } | ||
1796 | |||
1797 | /* If we have a CTL dataset available grab it and find the | ||
1798 | * edge power for our frequency */ | ||
1799 | if (ctl_idx == 0xFF) | ||
1800 | return; | ||
1801 | |||
1802 | /* Edge powers are sorted by frequency from lower | ||
1803 | * to higher. Each CTL corresponds to 8 edge power | ||
1804 | * measurements. */ | ||
1805 | rep_idx = ctl_idx * AR5K_EEPROM_N_EDGES; | ||
1806 | |||
1807 | /* Don't do boundaries check because we | ||
1808 | * might have more that one bands defined | ||
1809 | * for this mode */ | ||
1810 | |||
1811 | /* Get the edge power that's closer to our | ||
1812 | * frequency */ | ||
1813 | for (i = 0; i < AR5K_EEPROM_N_EDGES; i++) { | ||
1814 | rep_idx += i; | ||
1815 | if (target <= rep[rep_idx].freq) | ||
1816 | edge_pwr = (s16) rep[rep_idx].edge; | ||
1817 | } | ||
1818 | |||
1819 | if (edge_pwr) | ||
1820 | ah->ah_txpower.txp_max_pwr = 4*min(edge_pwr, max_chan_pwr); | ||
1821 | } | ||
1822 | |||
1823 | |||
1824 | /* | ||
1825 | * Power to PCDAC table functions | ||
1826 | */ | ||
1827 | |||
1436 | /* | 1828 | /* |
1437 | * TX power setup | 1829 | * Fill Power to PCDAC table on RF5111 |
1830 | * | ||
1831 | * No further processing is needed for RF5111, the only thing we have to | ||
1832 | * do is fill the values below and above calibration range since eeprom data | ||
1833 | * may not cover the entire PCDAC table. | ||
1438 | */ | 1834 | */ |
1835 | static void | ||
1836 | ath5k_fill_pwr_to_pcdac_table(struct ath5k_hw *ah, s16* table_min, | ||
1837 | s16 *table_max) | ||
1838 | { | ||
1839 | u8 *pcdac_out = ah->ah_txpower.txp_pd_table; | ||
1840 | u8 *pcdac_tmp = ah->ah_txpower.tmpL[0]; | ||
1841 | u8 pcdac_0, pcdac_n, pcdac_i, pwr_idx, i; | ||
1842 | s16 min_pwr, max_pwr; | ||
1843 | |||
1844 | /* Get table boundaries */ | ||
1845 | min_pwr = table_min[0]; | ||
1846 | pcdac_0 = pcdac_tmp[0]; | ||
1847 | |||
1848 | max_pwr = table_max[0]; | ||
1849 | pcdac_n = pcdac_tmp[table_max[0] - table_min[0]]; | ||
1850 | |||
1851 | /* Extrapolate below minimum using pcdac_0 */ | ||
1852 | pcdac_i = 0; | ||
1853 | for (i = 0; i < min_pwr; i++) | ||
1854 | pcdac_out[pcdac_i++] = pcdac_0; | ||
1855 | |||
1856 | /* Copy values from pcdac_tmp */ | ||
1857 | pwr_idx = min_pwr; | ||
1858 | for (i = 0 ; pwr_idx <= max_pwr && | ||
1859 | pcdac_i < AR5K_EEPROM_POWER_TABLE_SIZE; i++) { | ||
1860 | pcdac_out[pcdac_i++] = pcdac_tmp[i]; | ||
1861 | pwr_idx++; | ||
1862 | } | ||
1863 | |||
1864 | /* Extrapolate above maximum */ | ||
1865 | while (pcdac_i < AR5K_EEPROM_POWER_TABLE_SIZE) | ||
1866 | pcdac_out[pcdac_i++] = pcdac_n; | ||
1867 | |||
1868 | } | ||
1439 | 1869 | ||
1440 | /* | 1870 | /* |
1441 | * Initialize the tx power table (not fully implemented) | 1871 | * Combine available XPD Curves and fill Linear Power to PCDAC table |
1872 | * on RF5112 | ||
1873 | * | ||
1874 | * RFX112 can have up to 2 curves (one for low txpower range and one for | ||
1875 | * higher txpower range). We need to put them both on pcdac_out and place | ||
1876 | * them in the correct location. In case we only have one curve available | ||
1877 | * just fit it on pcdac_out (it's supposed to cover the entire range of | ||
1878 | * available pwr levels since it's always the higher power curve). Extrapolate | ||
1879 | * below and above final table if needed. | ||
1442 | */ | 1880 | */ |
1443 | static void ath5k_txpower_table(struct ath5k_hw *ah, | 1881 | static void |
1444 | struct ieee80211_channel *channel, s16 max_power) | 1882 | ath5k_combine_linear_pcdac_curves(struct ath5k_hw *ah, s16* table_min, |
1883 | s16 *table_max, u8 pdcurves) | ||
1445 | { | 1884 | { |
1446 | unsigned int i, min, max, n; | 1885 | u8 *pcdac_out = ah->ah_txpower.txp_pd_table; |
1447 | u16 txpower, *rates; | 1886 | u8 *pcdac_low_pwr; |
1448 | 1887 | u8 *pcdac_high_pwr; | |
1449 | rates = ah->ah_txpower.txp_rates; | 1888 | u8 *pcdac_tmp; |
1450 | 1889 | u8 pwr; | |
1451 | txpower = AR5K_TUNE_DEFAULT_TXPOWER * 2; | 1890 | s16 max_pwr_idx; |
1452 | if (max_power > txpower) | 1891 | s16 min_pwr_idx; |
1453 | txpower = max_power > AR5K_TUNE_MAX_TXPOWER ? | 1892 | s16 mid_pwr_idx = 0; |
1454 | AR5K_TUNE_MAX_TXPOWER : max_power; | 1893 | /* Edge flag turs on the 7nth bit on the PCDAC |
1455 | 1894 | * to delcare the higher power curve (force values | |
1456 | for (i = 0; i < AR5K_MAX_RATES; i++) | 1895 | * to be greater than 64). If we only have one curve |
1457 | rates[i] = txpower; | 1896 | * we don't need to set this, if we have 2 curves and |
1458 | 1897 | * fill the table backwards this can also be used to | |
1459 | /* XXX setup target powers by rate */ | 1898 | * switch from higher power curve to lower power curve */ |
1460 | 1899 | u8 edge_flag; | |
1461 | ah->ah_txpower.txp_min = rates[7]; | 1900 | int i; |
1462 | ah->ah_txpower.txp_max = rates[0]; | 1901 | |
1463 | ah->ah_txpower.txp_ofdm = rates[0]; | 1902 | /* When we have only one curve available |
1464 | 1903 | * that's the higher power curve. If we have | |
1465 | /* Calculate the power table */ | 1904 | * two curves the first is the high power curve |
1466 | n = ARRAY_SIZE(ah->ah_txpower.txp_pcdac); | 1905 | * and the next is the low power curve. */ |
1467 | min = AR5K_EEPROM_PCDAC_START; | 1906 | if (pdcurves > 1) { |
1468 | max = AR5K_EEPROM_PCDAC_STOP; | 1907 | pcdac_low_pwr = ah->ah_txpower.tmpL[1]; |
1469 | for (i = 0; i < n; i += AR5K_EEPROM_PCDAC_STEP) | 1908 | pcdac_high_pwr = ah->ah_txpower.tmpL[0]; |
1470 | ah->ah_txpower.txp_pcdac[i] = | 1909 | mid_pwr_idx = table_max[1] - table_min[1] - 1; |
1471 | #ifdef notyet | 1910 | max_pwr_idx = (table_max[0] - table_min[0]) / 2; |
1472 | min + ((i * (max - min)) / n); | 1911 | |
1473 | #else | 1912 | /* If table size goes beyond 31.5dB, keep the |
1474 | min; | 1913 | * upper 31.5dB range when setting tx power. |
1914 | * Note: 126 = 31.5 dB in quarter dB steps */ | ||
1915 | if (table_max[0] - table_min[1] > 126) | ||
1916 | min_pwr_idx = table_max[0] - 126; | ||
1917 | else | ||
1918 | min_pwr_idx = table_min[1]; | ||
1919 | |||
1920 | /* Since we fill table backwards | ||
1921 | * start from high power curve */ | ||
1922 | pcdac_tmp = pcdac_high_pwr; | ||
1923 | |||
1924 | edge_flag = 0x40; | ||
1925 | #if 0 | ||
1926 | /* If both min and max power limits are in lower | ||
1927 | * power curve's range, only use the low power curve. | ||
1928 | * TODO: min/max levels are related to target | ||
1929 | * power values requested from driver/user | ||
1930 | * XXX: Is this really needed ? */ | ||
1931 | if (min_pwr < table_max[1] && | ||
1932 | max_pwr < table_max[1]) { | ||
1933 | edge_flag = 0; | ||
1934 | pcdac_tmp = pcdac_low_pwr; | ||
1935 | max_pwr_idx = (table_max[1] - table_min[1])/2; | ||
1936 | } | ||
1475 | #endif | 1937 | #endif |
1938 | } else { | ||
1939 | pcdac_low_pwr = ah->ah_txpower.tmpL[1]; /* Zeroed */ | ||
1940 | pcdac_high_pwr = ah->ah_txpower.tmpL[0]; | ||
1941 | min_pwr_idx = table_min[0]; | ||
1942 | max_pwr_idx = (table_max[0] - table_min[0]) / 2; | ||
1943 | pcdac_tmp = pcdac_high_pwr; | ||
1944 | edge_flag = 0; | ||
1945 | } | ||
1946 | |||
1947 | /* This is used when setting tx power*/ | ||
1948 | ah->ah_txpower.txp_min_idx = min_pwr_idx/2; | ||
1949 | |||
1950 | /* Fill Power to PCDAC table backwards */ | ||
1951 | pwr = max_pwr_idx; | ||
1952 | for (i = 63; i >= 0; i--) { | ||
1953 | /* Entering lower power range, reset | ||
1954 | * edge flag and set pcdac_tmp to lower | ||
1955 | * power curve.*/ | ||
1956 | if (edge_flag == 0x40 && | ||
1957 | (2*pwr <= (table_max[1] - table_min[0]) || pwr == 0)) { | ||
1958 | edge_flag = 0x00; | ||
1959 | pcdac_tmp = pcdac_low_pwr; | ||
1960 | pwr = mid_pwr_idx/2; | ||
1961 | } | ||
1962 | |||
1963 | /* Don't go below 1, extrapolate below if we have | ||
1964 | * already swithced to the lower power curve -or | ||
1965 | * we only have one curve and edge_flag is zero | ||
1966 | * anyway */ | ||
1967 | if (pcdac_tmp[pwr] < 1 && (edge_flag == 0x00)) { | ||
1968 | while (i >= 0) { | ||
1969 | pcdac_out[i] = pcdac_out[i + 1]; | ||
1970 | i--; | ||
1971 | } | ||
1972 | break; | ||
1973 | } | ||
1974 | |||
1975 | pcdac_out[i] = pcdac_tmp[pwr] | edge_flag; | ||
1976 | |||
1977 | /* Extrapolate above if pcdac is greater than | ||
1978 | * 126 -this can happen because we OR pcdac_out | ||
1979 | * value with edge_flag on high power curve */ | ||
1980 | if (pcdac_out[i] > 126) | ||
1981 | pcdac_out[i] = 126; | ||
1982 | |||
1983 | /* Decrease by a 0.5dB step */ | ||
1984 | pwr--; | ||
1985 | } | ||
1476 | } | 1986 | } |
1477 | 1987 | ||
1988 | /* Write PCDAC values on hw */ | ||
1989 | static void | ||
1990 | ath5k_setup_pcdac_table(struct ath5k_hw *ah) | ||
1991 | { | ||
1992 | u8 *pcdac_out = ah->ah_txpower.txp_pd_table; | ||
1993 | int i; | ||
1994 | |||
1995 | /* | ||
1996 | * Write TX power values | ||
1997 | */ | ||
1998 | for (i = 0; i < (AR5K_EEPROM_POWER_TABLE_SIZE / 2); i++) { | ||
1999 | ath5k_hw_reg_write(ah, | ||
2000 | (((pcdac_out[2*i + 0] << 8 | 0xff) & 0xffff) << 0) | | ||
2001 | (((pcdac_out[2*i + 1] << 8 | 0xff) & 0xffff) << 16), | ||
2002 | AR5K_PHY_PCDAC_TXPOWER(i)); | ||
2003 | } | ||
2004 | } | ||
2005 | |||
2006 | |||
1478 | /* | 2007 | /* |
1479 | * Set transmition power | 2008 | * Power to PDADC table functions |
1480 | */ | 2009 | */ |
1481 | int /*O.K. - txpower_table is unimplemented so this doesn't work*/ | 2010 | |
1482 | ath5k_hw_txpower(struct ath5k_hw *ah, struct ieee80211_channel *channel, | 2011 | /* |
1483 | unsigned int txpower) | 2012 | * Set the gain boundaries and create final Power to PDADC table |
2013 | * | ||
2014 | * We can have up to 4 pd curves, we need to do a simmilar process | ||
2015 | * as we do for RF5112. This time we don't have an edge_flag but we | ||
2016 | * set the gain boundaries on a separate register. | ||
2017 | */ | ||
2018 | static void | ||
2019 | ath5k_combine_pwr_to_pdadc_curves(struct ath5k_hw *ah, | ||
2020 | s16 *pwr_min, s16 *pwr_max, u8 pdcurves) | ||
1484 | { | 2021 | { |
1485 | bool tpc = ah->ah_txpower.txp_tpc; | 2022 | u8 gain_boundaries[AR5K_EEPROM_N_PD_GAINS]; |
1486 | unsigned int i; | 2023 | u8 *pdadc_out = ah->ah_txpower.txp_pd_table; |
2024 | u8 *pdadc_tmp; | ||
2025 | s16 pdadc_0; | ||
2026 | u8 pdadc_i, pdadc_n, pwr_step, pdg, max_idx, table_size; | ||
2027 | u8 pd_gain_overlap; | ||
2028 | |||
2029 | /* Note: Register value is initialized on initvals | ||
2030 | * there is no feedback from hw. | ||
2031 | * XXX: What about pd_gain_overlap from EEPROM ? */ | ||
2032 | pd_gain_overlap = (u8) ath5k_hw_reg_read(ah, AR5K_PHY_TPC_RG5) & | ||
2033 | AR5K_PHY_TPC_RG5_PD_GAIN_OVERLAP; | ||
2034 | |||
2035 | /* Create final PDADC table */ | ||
2036 | for (pdg = 0, pdadc_i = 0; pdg < pdcurves; pdg++) { | ||
2037 | pdadc_tmp = ah->ah_txpower.tmpL[pdg]; | ||
2038 | |||
2039 | if (pdg == pdcurves - 1) | ||
2040 | /* 2 dB boundary stretch for last | ||
2041 | * (higher power) curve */ | ||
2042 | gain_boundaries[pdg] = pwr_max[pdg] + 4; | ||
2043 | else | ||
2044 | /* Set gain boundary in the middle | ||
2045 | * between this curve and the next one */ | ||
2046 | gain_boundaries[pdg] = | ||
2047 | (pwr_max[pdg] + pwr_min[pdg + 1]) / 2; | ||
2048 | |||
2049 | /* Sanity check in case our 2 db stretch got out of | ||
2050 | * range. */ | ||
2051 | if (gain_boundaries[pdg] > AR5K_TUNE_MAX_TXPOWER) | ||
2052 | gain_boundaries[pdg] = AR5K_TUNE_MAX_TXPOWER; | ||
2053 | |||
2054 | /* For the first curve (lower power) | ||
2055 | * start from 0 dB */ | ||
2056 | if (pdg == 0) | ||
2057 | pdadc_0 = 0; | ||
2058 | else | ||
2059 | /* For the other curves use the gain overlap */ | ||
2060 | pdadc_0 = (gain_boundaries[pdg - 1] - pwr_min[pdg]) - | ||
2061 | pd_gain_overlap; | ||
1487 | 2062 | ||
1488 | ATH5K_TRACE(ah->ah_sc); | 2063 | /* Force each power step to be at least 0.5 dB */ |
1489 | if (txpower > AR5K_TUNE_MAX_TXPOWER) { | 2064 | if ((pdadc_tmp[1] - pdadc_tmp[0]) > 1) |
1490 | ATH5K_ERR(ah->ah_sc, "invalid tx power: %u\n", txpower); | 2065 | pwr_step = pdadc_tmp[1] - pdadc_tmp[0]; |
1491 | return -EINVAL; | 2066 | else |
2067 | pwr_step = 1; | ||
2068 | |||
2069 | /* If pdadc_0 is negative, we need to extrapolate | ||
2070 | * below this pdgain by a number of pwr_steps */ | ||
2071 | while ((pdadc_0 < 0) && (pdadc_i < 128)) { | ||
2072 | s16 tmp = pdadc_tmp[0] + pdadc_0 * pwr_step; | ||
2073 | pdadc_out[pdadc_i++] = (tmp < 0) ? 0 : (u8) tmp; | ||
2074 | pdadc_0++; | ||
2075 | } | ||
2076 | |||
2077 | /* Set last pwr level, using gain boundaries */ | ||
2078 | pdadc_n = gain_boundaries[pdg] + pd_gain_overlap - pwr_min[pdg]; | ||
2079 | /* Limit it to be inside pwr range */ | ||
2080 | table_size = pwr_max[pdg] - pwr_min[pdg]; | ||
2081 | max_idx = (pdadc_n < table_size) ? pdadc_n : table_size; | ||
2082 | |||
2083 | /* Fill pdadc_out table */ | ||
2084 | while (pdadc_0 < max_idx) | ||
2085 | pdadc_out[pdadc_i++] = pdadc_tmp[pdadc_0++]; | ||
2086 | |||
2087 | /* Need to extrapolate above this pdgain? */ | ||
2088 | if (pdadc_n <= max_idx) | ||
2089 | continue; | ||
2090 | |||
2091 | /* Force each power step to be at least 0.5 dB */ | ||
2092 | if ((pdadc_tmp[table_size - 1] - pdadc_tmp[table_size - 2]) > 1) | ||
2093 | pwr_step = pdadc_tmp[table_size - 1] - | ||
2094 | pdadc_tmp[table_size - 2]; | ||
2095 | else | ||
2096 | pwr_step = 1; | ||
2097 | |||
2098 | /* Extrapolate above */ | ||
2099 | while ((pdadc_0 < (s16) pdadc_n) && | ||
2100 | (pdadc_i < AR5K_EEPROM_POWER_TABLE_SIZE * 2)) { | ||
2101 | s16 tmp = pdadc_tmp[table_size - 1] + | ||
2102 | (pdadc_0 - max_idx) * pwr_step; | ||
2103 | pdadc_out[pdadc_i++] = (tmp > 127) ? 127 : (u8) tmp; | ||
2104 | pdadc_0++; | ||
2105 | } | ||
1492 | } | 2106 | } |
1493 | 2107 | ||
2108 | while (pdg < AR5K_EEPROM_N_PD_GAINS) { | ||
2109 | gain_boundaries[pdg] = gain_boundaries[pdg - 1]; | ||
2110 | pdg++; | ||
2111 | } | ||
2112 | |||
2113 | while (pdadc_i < AR5K_EEPROM_POWER_TABLE_SIZE * 2) { | ||
2114 | pdadc_out[pdadc_i] = pdadc_out[pdadc_i - 1]; | ||
2115 | pdadc_i++; | ||
2116 | } | ||
2117 | |||
2118 | /* Set gain boundaries */ | ||
2119 | ath5k_hw_reg_write(ah, | ||
2120 | AR5K_REG_SM(pd_gain_overlap, | ||
2121 | AR5K_PHY_TPC_RG5_PD_GAIN_OVERLAP) | | ||
2122 | AR5K_REG_SM(gain_boundaries[0], | ||
2123 | AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_1) | | ||
2124 | AR5K_REG_SM(gain_boundaries[1], | ||
2125 | AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_2) | | ||
2126 | AR5K_REG_SM(gain_boundaries[2], | ||
2127 | AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_3) | | ||
2128 | AR5K_REG_SM(gain_boundaries[3], | ||
2129 | AR5K_PHY_TPC_RG5_PD_GAIN_BOUNDARY_4), | ||
2130 | AR5K_PHY_TPC_RG5); | ||
2131 | |||
2132 | /* Used for setting rate power table */ | ||
2133 | ah->ah_txpower.txp_min_idx = pwr_min[0]; | ||
2134 | |||
2135 | } | ||
2136 | |||
2137 | /* Write PDADC values on hw */ | ||
2138 | static void | ||
2139 | ath5k_setup_pwr_to_pdadc_table(struct ath5k_hw *ah, | ||
2140 | u8 pdcurves, u8 *pdg_to_idx) | ||
2141 | { | ||
2142 | u8 *pdadc_out = ah->ah_txpower.txp_pd_table; | ||
2143 | u32 reg; | ||
2144 | u8 i; | ||
2145 | |||
2146 | /* Select the right pdgain curves */ | ||
2147 | |||
2148 | /* Clear current settings */ | ||
2149 | reg = ath5k_hw_reg_read(ah, AR5K_PHY_TPC_RG1); | ||
2150 | reg &= ~(AR5K_PHY_TPC_RG1_PDGAIN_1 | | ||
2151 | AR5K_PHY_TPC_RG1_PDGAIN_2 | | ||
2152 | AR5K_PHY_TPC_RG1_PDGAIN_3 | | ||
2153 | AR5K_PHY_TPC_RG1_NUM_PD_GAIN); | ||
2154 | |||
1494 | /* | 2155 | /* |
1495 | * RF2413 for some reason can't | 2156 | * Use pd_gains curve from eeprom |
1496 | * transmit anything if we call | ||
1497 | * this funtion, so we skip it | ||
1498 | * until we fix txpower. | ||
1499 | * | 2157 | * |
1500 | * XXX: Assume same for RF2425 | 2158 | * This overrides the default setting from initvals |
1501 | * to be safe. | 2159 | * in case some vendors (e.g. Zcomax) don't use the default |
2160 | * curves. If we don't honor their settings we 'll get a | ||
2161 | * 5dB (1 * gain overlap ?) drop. | ||
1502 | */ | 2162 | */ |
1503 | if ((ah->ah_radio == AR5K_RF2413) || (ah->ah_radio == AR5K_RF2425)) | 2163 | reg |= AR5K_REG_SM(pdcurves, AR5K_PHY_TPC_RG1_NUM_PD_GAIN); |
1504 | return 0; | ||
1505 | 2164 | ||
1506 | /* Reset TX power values */ | 2165 | switch (pdcurves) { |
1507 | memset(&ah->ah_txpower, 0, sizeof(ah->ah_txpower)); | 2166 | case 3: |
1508 | ah->ah_txpower.txp_tpc = tpc; | 2167 | reg |= AR5K_REG_SM(pdg_to_idx[2], AR5K_PHY_TPC_RG1_PDGAIN_3); |
1509 | 2168 | /* Fall through */ | |
1510 | /* Initialize TX power table */ | 2169 | case 2: |
1511 | ath5k_txpower_table(ah, channel, txpower); | 2170 | reg |= AR5K_REG_SM(pdg_to_idx[1], AR5K_PHY_TPC_RG1_PDGAIN_2); |
2171 | /* Fall through */ | ||
2172 | case 1: | ||
2173 | reg |= AR5K_REG_SM(pdg_to_idx[0], AR5K_PHY_TPC_RG1_PDGAIN_1); | ||
2174 | break; | ||
2175 | } | ||
2176 | ath5k_hw_reg_write(ah, reg, AR5K_PHY_TPC_RG1); | ||
1512 | 2177 | ||
1513 | /* | 2178 | /* |
1514 | * Write TX power values | 2179 | * Write TX power values |
1515 | */ | 2180 | */ |
1516 | for (i = 0; i < (AR5K_EEPROM_POWER_TABLE_SIZE / 2); i++) { | 2181 | for (i = 0; i < (AR5K_EEPROM_POWER_TABLE_SIZE / 2); i++) { |
1517 | ath5k_hw_reg_write(ah, | 2182 | ath5k_hw_reg_write(ah, |
1518 | ((((ah->ah_txpower.txp_pcdac[(i << 1) + 1] << 8) | 0xff) & 0xffff) << 16) | | 2183 | ((pdadc_out[4*i + 0] & 0xff) << 0) | |
1519 | (((ah->ah_txpower.txp_pcdac[(i << 1) ] << 8) | 0xff) & 0xffff), | 2184 | ((pdadc_out[4*i + 1] & 0xff) << 8) | |
1520 | AR5K_PHY_PCDAC_TXPOWER(i)); | 2185 | ((pdadc_out[4*i + 2] & 0xff) << 16) | |
2186 | ((pdadc_out[4*i + 3] & 0xff) << 24), | ||
2187 | AR5K_PHY_PDADC_TXPOWER(i)); | ||
2188 | } | ||
2189 | } | ||
2190 | |||
2191 | |||
2192 | /* | ||
2193 | * Common code for PCDAC/PDADC tables | ||
2194 | */ | ||
2195 | |||
2196 | /* | ||
2197 | * This is the main function that uses all of the above | ||
2198 | * to set PCDAC/PDADC table on hw for the current channel. | ||
2199 | * This table is used for tx power calibration on the basband, | ||
2200 | * without it we get weird tx power levels and in some cases | ||
2201 | * distorted spectral mask | ||
2202 | */ | ||
2203 | static int | ||
2204 | ath5k_setup_channel_powertable(struct ath5k_hw *ah, | ||
2205 | struct ieee80211_channel *channel, | ||
2206 | u8 ee_mode, u8 type) | ||
2207 | { | ||
2208 | struct ath5k_pdgain_info *pdg_L, *pdg_R; | ||
2209 | struct ath5k_chan_pcal_info *pcinfo_L; | ||
2210 | struct ath5k_chan_pcal_info *pcinfo_R; | ||
2211 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; | ||
2212 | u8 *pdg_curve_to_idx = ee->ee_pdc_to_idx[ee_mode]; | ||
2213 | s16 table_min[AR5K_EEPROM_N_PD_GAINS]; | ||
2214 | s16 table_max[AR5K_EEPROM_N_PD_GAINS]; | ||
2215 | u8 *tmpL; | ||
2216 | u8 *tmpR; | ||
2217 | u32 target = channel->center_freq; | ||
2218 | int pdg, i; | ||
2219 | |||
2220 | /* Get surounding freq piers for this channel */ | ||
2221 | ath5k_get_chan_pcal_surrounding_piers(ah, channel, | ||
2222 | &pcinfo_L, | ||
2223 | &pcinfo_R); | ||
2224 | |||
2225 | /* Loop over pd gain curves on | ||
2226 | * surounding freq piers by index */ | ||
2227 | for (pdg = 0; pdg < ee->ee_pd_gains[ee_mode]; pdg++) { | ||
2228 | |||
2229 | /* Fill curves in reverse order | ||
2230 | * from lower power (max gain) | ||
2231 | * to higher power. Use curve -> idx | ||
2232 | * backmaping we did on eeprom init */ | ||
2233 | u8 idx = pdg_curve_to_idx[pdg]; | ||
2234 | |||
2235 | /* Grab the needed curves by index */ | ||
2236 | pdg_L = &pcinfo_L->pd_curves[idx]; | ||
2237 | pdg_R = &pcinfo_R->pd_curves[idx]; | ||
2238 | |||
2239 | /* Initialize the temp tables */ | ||
2240 | tmpL = ah->ah_txpower.tmpL[pdg]; | ||
2241 | tmpR = ah->ah_txpower.tmpR[pdg]; | ||
2242 | |||
2243 | /* Set curve's x boundaries and create | ||
2244 | * curves so that they cover the same | ||
2245 | * range (if we don't do that one table | ||
2246 | * will have values on some range and the | ||
2247 | * other one won't have any so interpolation | ||
2248 | * will fail) */ | ||
2249 | table_min[pdg] = min(pdg_L->pd_pwr[0], | ||
2250 | pdg_R->pd_pwr[0]) / 2; | ||
2251 | |||
2252 | table_max[pdg] = max(pdg_L->pd_pwr[pdg_L->pd_points - 1], | ||
2253 | pdg_R->pd_pwr[pdg_R->pd_points - 1]) / 2; | ||
2254 | |||
2255 | /* Now create the curves on surrounding channels | ||
2256 | * and interpolate if needed to get the final | ||
2257 | * curve for this gain on this channel */ | ||
2258 | switch (type) { | ||
2259 | case AR5K_PWRTABLE_LINEAR_PCDAC: | ||
2260 | /* Override min/max so that we don't loose | ||
2261 | * accuracy (don't divide by 2) */ | ||
2262 | table_min[pdg] = min(pdg_L->pd_pwr[0], | ||
2263 | pdg_R->pd_pwr[0]); | ||
2264 | |||
2265 | table_max[pdg] = | ||
2266 | max(pdg_L->pd_pwr[pdg_L->pd_points - 1], | ||
2267 | pdg_R->pd_pwr[pdg_R->pd_points - 1]); | ||
2268 | |||
2269 | /* Override minimum so that we don't get | ||
2270 | * out of bounds while extrapolating | ||
2271 | * below. Don't do this when we have 2 | ||
2272 | * curves and we are on the high power curve | ||
2273 | * because table_min is ok in this case */ | ||
2274 | if (!(ee->ee_pd_gains[ee_mode] > 1 && pdg == 0)) { | ||
2275 | |||
2276 | table_min[pdg] = | ||
2277 | ath5k_get_linear_pcdac_min(pdg_L->pd_step, | ||
2278 | pdg_R->pd_step, | ||
2279 | pdg_L->pd_pwr, | ||
2280 | pdg_R->pd_pwr); | ||
2281 | |||
2282 | /* Don't go too low because we will | ||
2283 | * miss the upper part of the curve. | ||
2284 | * Note: 126 = 31.5dB (max power supported) | ||
2285 | * in 0.25dB units */ | ||
2286 | if (table_max[pdg] - table_min[pdg] > 126) | ||
2287 | table_min[pdg] = table_max[pdg] - 126; | ||
2288 | } | ||
2289 | |||
2290 | /* Fall through */ | ||
2291 | case AR5K_PWRTABLE_PWR_TO_PCDAC: | ||
2292 | case AR5K_PWRTABLE_PWR_TO_PDADC: | ||
2293 | |||
2294 | ath5k_create_power_curve(table_min[pdg], | ||
2295 | table_max[pdg], | ||
2296 | pdg_L->pd_pwr, | ||
2297 | pdg_L->pd_step, | ||
2298 | pdg_L->pd_points, tmpL, type); | ||
2299 | |||
2300 | /* We are in a calibration | ||
2301 | * pier, no need to interpolate | ||
2302 | * between freq piers */ | ||
2303 | if (pcinfo_L == pcinfo_R) | ||
2304 | continue; | ||
2305 | |||
2306 | ath5k_create_power_curve(table_min[pdg], | ||
2307 | table_max[pdg], | ||
2308 | pdg_R->pd_pwr, | ||
2309 | pdg_R->pd_step, | ||
2310 | pdg_R->pd_points, tmpR, type); | ||
2311 | break; | ||
2312 | default: | ||
2313 | return -EINVAL; | ||
2314 | } | ||
2315 | |||
2316 | /* Interpolate between curves | ||
2317 | * of surounding freq piers to | ||
2318 | * get the final curve for this | ||
2319 | * pd gain. Re-use tmpL for interpolation | ||
2320 | * output */ | ||
2321 | for (i = 0; (i < (u16) (table_max[pdg] - table_min[pdg])) && | ||
2322 | (i < AR5K_EEPROM_POWER_TABLE_SIZE); i++) { | ||
2323 | tmpL[i] = (u8) ath5k_get_interpolated_value(target, | ||
2324 | (s16) pcinfo_L->freq, | ||
2325 | (s16) pcinfo_R->freq, | ||
2326 | (s16) tmpL[i], | ||
2327 | (s16) tmpR[i]); | ||
2328 | } | ||
1521 | } | 2329 | } |
1522 | 2330 | ||
2331 | /* Now we have a set of curves for this | ||
2332 | * channel on tmpL (x range is table_max - table_min | ||
2333 | * and y values are tmpL[pdg][]) sorted in the same | ||
2334 | * order as EEPROM (because we've used the backmaping). | ||
2335 | * So for RF5112 it's from higher power to lower power | ||
2336 | * and for RF2413 it's from lower power to higher power. | ||
2337 | * For RF5111 we only have one curve. */ | ||
2338 | |||
2339 | /* Fill min and max power levels for this | ||
2340 | * channel by interpolating the values on | ||
2341 | * surounding channels to complete the dataset */ | ||
2342 | ah->ah_txpower.txp_min_pwr = ath5k_get_interpolated_value(target, | ||
2343 | (s16) pcinfo_L->freq, | ||
2344 | (s16) pcinfo_R->freq, | ||
2345 | pcinfo_L->min_pwr, pcinfo_R->min_pwr); | ||
2346 | |||
2347 | ah->ah_txpower.txp_max_pwr = ath5k_get_interpolated_value(target, | ||
2348 | (s16) pcinfo_L->freq, | ||
2349 | (s16) pcinfo_R->freq, | ||
2350 | pcinfo_L->max_pwr, pcinfo_R->max_pwr); | ||
2351 | |||
2352 | /* We are ready to go, fill PCDAC/PDADC | ||
2353 | * table and write settings on hardware */ | ||
2354 | switch (type) { | ||
2355 | case AR5K_PWRTABLE_LINEAR_PCDAC: | ||
2356 | /* For RF5112 we can have one or two curves | ||
2357 | * and each curve covers a certain power lvl | ||
2358 | * range so we need to do some more processing */ | ||
2359 | ath5k_combine_linear_pcdac_curves(ah, table_min, table_max, | ||
2360 | ee->ee_pd_gains[ee_mode]); | ||
2361 | |||
2362 | /* Set txp.offset so that we can | ||
2363 | * match max power value with max | ||
2364 | * table index */ | ||
2365 | ah->ah_txpower.txp_offset = 64 - (table_max[0] / 2); | ||
2366 | |||
2367 | /* Write settings on hw */ | ||
2368 | ath5k_setup_pcdac_table(ah); | ||
2369 | break; | ||
2370 | case AR5K_PWRTABLE_PWR_TO_PCDAC: | ||
2371 | /* We are done for RF5111 since it has only | ||
2372 | * one curve, just fit the curve on the table */ | ||
2373 | ath5k_fill_pwr_to_pcdac_table(ah, table_min, table_max); | ||
2374 | |||
2375 | /* No rate powertable adjustment for RF5111 */ | ||
2376 | ah->ah_txpower.txp_min_idx = 0; | ||
2377 | ah->ah_txpower.txp_offset = 0; | ||
2378 | |||
2379 | /* Write settings on hw */ | ||
2380 | ath5k_setup_pcdac_table(ah); | ||
2381 | break; | ||
2382 | case AR5K_PWRTABLE_PWR_TO_PDADC: | ||
2383 | /* Set PDADC boundaries and fill | ||
2384 | * final PDADC table */ | ||
2385 | ath5k_combine_pwr_to_pdadc_curves(ah, table_min, table_max, | ||
2386 | ee->ee_pd_gains[ee_mode]); | ||
2387 | |||
2388 | /* Write settings on hw */ | ||
2389 | ath5k_setup_pwr_to_pdadc_table(ah, pdg, pdg_curve_to_idx); | ||
2390 | |||
2391 | /* Set txp.offset, note that table_min | ||
2392 | * can be negative */ | ||
2393 | ah->ah_txpower.txp_offset = table_min[0]; | ||
2394 | break; | ||
2395 | default: | ||
2396 | return -EINVAL; | ||
2397 | } | ||
2398 | |||
2399 | return 0; | ||
2400 | } | ||
2401 | |||
2402 | |||
2403 | /* | ||
2404 | * Per-rate tx power setting | ||
2405 | * | ||
2406 | * This is the code that sets the desired tx power (below | ||
2407 | * maximum) on hw for each rate (we also have TPC that sets | ||
2408 | * power per packet). We do that by providing an index on the | ||
2409 | * PCDAC/PDADC table we set up. | ||
2410 | */ | ||
2411 | |||
2412 | /* | ||
2413 | * Set rate power table | ||
2414 | * | ||
2415 | * For now we only limit txpower based on maximum tx power | ||
2416 | * supported by hw (what's inside rate_info). We need to limit | ||
2417 | * this even more, based on regulatory domain etc. | ||
2418 | * | ||
2419 | * Rate power table contains indices to PCDAC/PDADC table (0.5dB steps) | ||
2420 | * and is indexed as follows: | ||
2421 | * rates[0] - rates[7] -> OFDM rates | ||
2422 | * rates[8] - rates[14] -> CCK rates | ||
2423 | * rates[15] -> XR rates (they all have the same power) | ||
2424 | */ | ||
2425 | static void | ||
2426 | ath5k_setup_rate_powertable(struct ath5k_hw *ah, u16 max_pwr, | ||
2427 | struct ath5k_rate_pcal_info *rate_info, | ||
2428 | u8 ee_mode) | ||
2429 | { | ||
2430 | unsigned int i; | ||
2431 | u16 *rates; | ||
2432 | |||
2433 | /* max_pwr is power level we got from driver/user in 0.5dB | ||
2434 | * units, switch to 0.25dB units so we can compare */ | ||
2435 | max_pwr *= 2; | ||
2436 | max_pwr = min(max_pwr, (u16) ah->ah_txpower.txp_max_pwr) / 2; | ||
2437 | |||
2438 | /* apply rate limits */ | ||
2439 | rates = ah->ah_txpower.txp_rates_power_table; | ||
2440 | |||
2441 | /* OFDM rates 6 to 24Mb/s */ | ||
2442 | for (i = 0; i < 5; i++) | ||
2443 | rates[i] = min(max_pwr, rate_info->target_power_6to24); | ||
2444 | |||
2445 | /* Rest OFDM rates */ | ||
2446 | rates[5] = min(rates[0], rate_info->target_power_36); | ||
2447 | rates[6] = min(rates[0], rate_info->target_power_48); | ||
2448 | rates[7] = min(rates[0], rate_info->target_power_54); | ||
2449 | |||
2450 | /* CCK rates */ | ||
2451 | /* 1L */ | ||
2452 | rates[8] = min(rates[0], rate_info->target_power_6to24); | ||
2453 | /* 2L */ | ||
2454 | rates[9] = min(rates[0], rate_info->target_power_36); | ||
2455 | /* 2S */ | ||
2456 | rates[10] = min(rates[0], rate_info->target_power_36); | ||
2457 | /* 5L */ | ||
2458 | rates[11] = min(rates[0], rate_info->target_power_48); | ||
2459 | /* 5S */ | ||
2460 | rates[12] = min(rates[0], rate_info->target_power_48); | ||
2461 | /* 11L */ | ||
2462 | rates[13] = min(rates[0], rate_info->target_power_54); | ||
2463 | /* 11S */ | ||
2464 | rates[14] = min(rates[0], rate_info->target_power_54); | ||
2465 | |||
2466 | /* XR rates */ | ||
2467 | rates[15] = min(rates[0], rate_info->target_power_6to24); | ||
2468 | |||
2469 | /* CCK rates have different peak to average ratio | ||
2470 | * so we have to tweak their power so that gainf | ||
2471 | * correction works ok. For this we use OFDM to | ||
2472 | * CCK delta from eeprom */ | ||
2473 | if ((ee_mode == AR5K_EEPROM_MODE_11G) && | ||
2474 | (ah->ah_phy_revision < AR5K_SREV_PHY_5212A)) | ||
2475 | for (i = 8; i <= 15; i++) | ||
2476 | rates[i] -= ah->ah_txpower.txp_cck_ofdm_gainf_delta; | ||
2477 | |||
2478 | ah->ah_txpower.txp_min_pwr = rates[7]; | ||
2479 | ah->ah_txpower.txp_max_pwr = rates[0]; | ||
2480 | ah->ah_txpower.txp_ofdm = rates[7]; | ||
2481 | } | ||
2482 | |||
2483 | |||
2484 | /* | ||
2485 | * Set transmition power | ||
2486 | */ | ||
2487 | int | ||
2488 | ath5k_hw_txpower(struct ath5k_hw *ah, struct ieee80211_channel *channel, | ||
2489 | u8 ee_mode, u8 txpower) | ||
2490 | { | ||
2491 | struct ath5k_rate_pcal_info rate_info; | ||
2492 | u8 type; | ||
2493 | int ret; | ||
2494 | |||
2495 | ATH5K_TRACE(ah->ah_sc); | ||
2496 | if (txpower > AR5K_TUNE_MAX_TXPOWER) { | ||
2497 | ATH5K_ERR(ah->ah_sc, "invalid tx power: %u\n", txpower); | ||
2498 | return -EINVAL; | ||
2499 | } | ||
2500 | if (txpower == 0) | ||
2501 | txpower = AR5K_TUNE_DEFAULT_TXPOWER; | ||
2502 | |||
2503 | /* Reset TX power values */ | ||
2504 | memset(&ah->ah_txpower, 0, sizeof(ah->ah_txpower)); | ||
2505 | ah->ah_txpower.txp_tpc = AR5K_TUNE_TPC_TXPOWER; | ||
2506 | ah->ah_txpower.txp_min_pwr = 0; | ||
2507 | ah->ah_txpower.txp_max_pwr = AR5K_TUNE_MAX_TXPOWER; | ||
2508 | |||
2509 | /* Initialize TX power table */ | ||
2510 | switch (ah->ah_radio) { | ||
2511 | case AR5K_RF5111: | ||
2512 | type = AR5K_PWRTABLE_PWR_TO_PCDAC; | ||
2513 | break; | ||
2514 | case AR5K_RF5112: | ||
2515 | type = AR5K_PWRTABLE_LINEAR_PCDAC; | ||
2516 | break; | ||
2517 | case AR5K_RF2413: | ||
2518 | case AR5K_RF5413: | ||
2519 | case AR5K_RF2316: | ||
2520 | case AR5K_RF2317: | ||
2521 | case AR5K_RF2425: | ||
2522 | type = AR5K_PWRTABLE_PWR_TO_PDADC; | ||
2523 | break; | ||
2524 | default: | ||
2525 | return -EINVAL; | ||
2526 | } | ||
2527 | |||
2528 | /* FIXME: Only on channel/mode change */ | ||
2529 | ret = ath5k_setup_channel_powertable(ah, channel, ee_mode, type); | ||
2530 | if (ret) | ||
2531 | return ret; | ||
2532 | |||
2533 | /* Limit max power if we have a CTL available */ | ||
2534 | ath5k_get_max_ctl_power(ah, channel); | ||
2535 | |||
2536 | /* FIXME: Tx power limit for this regdomain | ||
2537 | * XXX: Mac80211/CRDA will do that anyway ? */ | ||
2538 | |||
2539 | /* FIXME: Antenna reduction stuff */ | ||
2540 | |||
2541 | /* FIXME: Limit power on turbo modes */ | ||
2542 | |||
2543 | /* FIXME: TPC scale reduction */ | ||
2544 | |||
2545 | /* Get surounding channels for per-rate power table | ||
2546 | * calibration */ | ||
2547 | ath5k_get_rate_pcal_data(ah, channel, &rate_info); | ||
2548 | |||
2549 | /* Setup rate power table */ | ||
2550 | ath5k_setup_rate_powertable(ah, txpower, &rate_info, ee_mode); | ||
2551 | |||
2552 | /* Write rate power table on hw */ | ||
1523 | ath5k_hw_reg_write(ah, AR5K_TXPOWER_OFDM(3, 24) | | 2553 | ath5k_hw_reg_write(ah, AR5K_TXPOWER_OFDM(3, 24) | |
1524 | AR5K_TXPOWER_OFDM(2, 16) | AR5K_TXPOWER_OFDM(1, 8) | | 2554 | AR5K_TXPOWER_OFDM(2, 16) | AR5K_TXPOWER_OFDM(1, 8) | |
1525 | AR5K_TXPOWER_OFDM(0, 0), AR5K_PHY_TXPOWER_RATE1); | 2555 | AR5K_TXPOWER_OFDM(0, 0), AR5K_PHY_TXPOWER_RATE1); |
@@ -1536,26 +2566,34 @@ ath5k_hw_txpower(struct ath5k_hw *ah, struct ieee80211_channel *channel, | |||
1536 | AR5K_TXPOWER_CCK(13, 16) | AR5K_TXPOWER_CCK(12, 8) | | 2566 | AR5K_TXPOWER_CCK(13, 16) | AR5K_TXPOWER_CCK(12, 8) | |
1537 | AR5K_TXPOWER_CCK(11, 0), AR5K_PHY_TXPOWER_RATE4); | 2567 | AR5K_TXPOWER_CCK(11, 0), AR5K_PHY_TXPOWER_RATE4); |
1538 | 2568 | ||
1539 | if (ah->ah_txpower.txp_tpc) | 2569 | /* FIXME: TPC support */ |
2570 | if (ah->ah_txpower.txp_tpc) { | ||
1540 | ath5k_hw_reg_write(ah, AR5K_PHY_TXPOWER_RATE_MAX_TPC_ENABLE | | 2571 | ath5k_hw_reg_write(ah, AR5K_PHY_TXPOWER_RATE_MAX_TPC_ENABLE | |
1541 | AR5K_TUNE_MAX_TXPOWER, AR5K_PHY_TXPOWER_RATE_MAX); | 2572 | AR5K_TUNE_MAX_TXPOWER, AR5K_PHY_TXPOWER_RATE_MAX); |
1542 | else | 2573 | |
2574 | ath5k_hw_reg_write(ah, | ||
2575 | AR5K_REG_MS(AR5K_TUNE_MAX_TXPOWER, AR5K_TPC_ACK) | | ||
2576 | AR5K_REG_MS(AR5K_TUNE_MAX_TXPOWER, AR5K_TPC_CTS) | | ||
2577 | AR5K_REG_MS(AR5K_TUNE_MAX_TXPOWER, AR5K_TPC_CHIRP), | ||
2578 | AR5K_TPC); | ||
2579 | } else { | ||
1543 | ath5k_hw_reg_write(ah, AR5K_PHY_TXPOWER_RATE_MAX | | 2580 | ath5k_hw_reg_write(ah, AR5K_PHY_TXPOWER_RATE_MAX | |
1544 | AR5K_TUNE_MAX_TXPOWER, AR5K_PHY_TXPOWER_RATE_MAX); | 2581 | AR5K_TUNE_MAX_TXPOWER, AR5K_PHY_TXPOWER_RATE_MAX); |
2582 | } | ||
1545 | 2583 | ||
1546 | return 0; | 2584 | return 0; |
1547 | } | 2585 | } |
1548 | 2586 | ||
1549 | int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, unsigned int power) | 2587 | int ath5k_hw_set_txpower_limit(struct ath5k_hw *ah, u8 mode, u8 txpower) |
1550 | { | 2588 | { |
1551 | /*Just a try M.F.*/ | 2589 | /*Just a try M.F.*/ |
1552 | struct ieee80211_channel *channel = &ah->ah_current_channel; | 2590 | struct ieee80211_channel *channel = &ah->ah_current_channel; |
1553 | 2591 | ||
1554 | ATH5K_TRACE(ah->ah_sc); | 2592 | ATH5K_TRACE(ah->ah_sc); |
1555 | ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_TXPOWER, | 2593 | ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_TXPOWER, |
1556 | "changing txpower to %d\n", power); | 2594 | "changing txpower to %d\n", txpower); |
1557 | 2595 | ||
1558 | return ath5k_hw_txpower(ah, channel, power); | 2596 | return ath5k_hw_txpower(ah, channel, mode, txpower); |
1559 | } | 2597 | } |
1560 | 2598 | ||
1561 | #undef _ATH5K_PHY | 2599 | #undef _ATH5K_PHY |
diff --git a/drivers/net/wireless/ath5k/reg.h b/drivers/net/wireless/ath5k/reg.h index 2dc008e10226..7070d1543cdc 100644 --- a/drivers/net/wireless/ath5k/reg.h +++ b/drivers/net/wireless/ath5k/reg.h | |||
@@ -1554,6 +1554,19 @@ | |||
1554 | /*===5212 Specific PCU registers===*/ | 1554 | /*===5212 Specific PCU registers===*/ |
1555 | 1555 | ||
1556 | /* | 1556 | /* |
1557 | * Transmit power control register | ||
1558 | */ | ||
1559 | #define AR5K_TPC 0x80e8 | ||
1560 | #define AR5K_TPC_ACK 0x0000003f /* ack frames */ | ||
1561 | #define AR5K_TPC_ACK_S 0 | ||
1562 | #define AR5K_TPC_CTS 0x00003f00 /* cts frames */ | ||
1563 | #define AR5K_TPC_CTS_S 8 | ||
1564 | #define AR5K_TPC_CHIRP 0x003f0000 /* chirp frames */ | ||
1565 | #define AR5K_TPC_CHIRP_S 16 | ||
1566 | #define AR5K_TPC_DOPPLER 0x0f000000 /* doppler chirp span */ | ||
1567 | #define AR5K_TPC_DOPPLER_S 24 | ||
1568 | |||
1569 | /* | ||
1557 | * XR (eXtended Range) mode register | 1570 | * XR (eXtended Range) mode register |
1558 | */ | 1571 | */ |
1559 | #define AR5K_XRMODE 0x80c0 /* Register Address */ | 1572 | #define AR5K_XRMODE 0x80c0 /* Register Address */ |
@@ -2550,6 +2563,12 @@ | |||
2550 | #define AR5K_PHY_TPC_RG1 0xa258 | 2563 | #define AR5K_PHY_TPC_RG1 0xa258 |
2551 | #define AR5K_PHY_TPC_RG1_NUM_PD_GAIN 0x0000c000 | 2564 | #define AR5K_PHY_TPC_RG1_NUM_PD_GAIN 0x0000c000 |
2552 | #define AR5K_PHY_TPC_RG1_NUM_PD_GAIN_S 14 | 2565 | #define AR5K_PHY_TPC_RG1_NUM_PD_GAIN_S 14 |
2566 | #define AR5K_PHY_TPC_RG1_PDGAIN_1 0x00030000 | ||
2567 | #define AR5K_PHY_TPC_RG1_PDGAIN_1_S 16 | ||
2568 | #define AR5K_PHY_TPC_RG1_PDGAIN_2 0x000c0000 | ||
2569 | #define AR5K_PHY_TPC_RG1_PDGAIN_2_S 18 | ||
2570 | #define AR5K_PHY_TPC_RG1_PDGAIN_3 0x00300000 | ||
2571 | #define AR5K_PHY_TPC_RG1_PDGAIN_3_S 20 | ||
2553 | 2572 | ||
2554 | #define AR5K_PHY_TPC_RG5 0xa26C | 2573 | #define AR5K_PHY_TPC_RG5 0xa26C |
2555 | #define AR5K_PHY_TPC_RG5_PD_GAIN_OVERLAP 0x0000000F | 2574 | #define AR5K_PHY_TPC_RG5_PD_GAIN_OVERLAP 0x0000000F |
diff --git a/drivers/net/wireless/ath5k/reset.c b/drivers/net/wireless/ath5k/reset.c index 685dc213edae..7a17d31b2fd9 100644 --- a/drivers/net/wireless/ath5k/reset.c +++ b/drivers/net/wireless/ath5k/reset.c | |||
@@ -664,29 +664,35 @@ static void ath5k_hw_commit_eeprom_settings(struct ath5k_hw *ah, | |||
664 | struct ieee80211_channel *channel, u8 *ant, u8 ee_mode) | 664 | struct ieee80211_channel *channel, u8 *ant, u8 ee_mode) |
665 | { | 665 | { |
666 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; | 666 | struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom; |
667 | s16 cck_ofdm_pwr_delta; | ||
667 | 668 | ||
668 | /* Set CCK to OFDM power delta */ | 669 | /* Adjust power delta for channel 14 */ |
669 | if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) { | 670 | if (channel->center_freq == 2484) |
670 | int16_t cck_ofdm_pwr_delta; | 671 | cck_ofdm_pwr_delta = |
671 | 672 | ((ee->ee_cck_ofdm_power_delta - | |
672 | /* Adjust power delta for channel 14 */ | 673 | ee->ee_scaled_cck_delta) * 2) / 10; |
673 | if (channel->center_freq == 2484) | 674 | else |
674 | cck_ofdm_pwr_delta = | 675 | cck_ofdm_pwr_delta = |
675 | ((ee->ee_cck_ofdm_power_delta - | 676 | (ee->ee_cck_ofdm_power_delta * 2) / 10; |
676 | ee->ee_scaled_cck_delta) * 2) / 10; | ||
677 | else | ||
678 | cck_ofdm_pwr_delta = | ||
679 | (ee->ee_cck_ofdm_power_delta * 2) / 10; | ||
680 | 677 | ||
678 | /* Set CCK to OFDM power delta on tx power | ||
679 | * adjustment register */ | ||
680 | if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) { | ||
681 | if (channel->hw_value == CHANNEL_G) | 681 | if (channel->hw_value == CHANNEL_G) |
682 | ath5k_hw_reg_write(ah, | 682 | ath5k_hw_reg_write(ah, |
683 | AR5K_REG_SM((ee->ee_cck_ofdm_power_delta * -1), | 683 | AR5K_REG_SM((ee->ee_cck_ofdm_gain_delta * -1), |
684 | AR5K_PHY_TX_PWR_ADJ_CCK_GAIN_DELTA) | | 684 | AR5K_PHY_TX_PWR_ADJ_CCK_GAIN_DELTA) | |
685 | AR5K_REG_SM((cck_ofdm_pwr_delta * -1), | 685 | AR5K_REG_SM((cck_ofdm_pwr_delta * -1), |
686 | AR5K_PHY_TX_PWR_ADJ_CCK_PCDAC_INDEX), | 686 | AR5K_PHY_TX_PWR_ADJ_CCK_PCDAC_INDEX), |
687 | AR5K_PHY_TX_PWR_ADJ); | 687 | AR5K_PHY_TX_PWR_ADJ); |
688 | else | 688 | else |
689 | ath5k_hw_reg_write(ah, 0, AR5K_PHY_TX_PWR_ADJ); | 689 | ath5k_hw_reg_write(ah, 0, AR5K_PHY_TX_PWR_ADJ); |
690 | } else { | ||
691 | /* For older revs we scale power on sw during tx power | ||
692 | * setup */ | ||
693 | ah->ah_txpower.txp_cck_ofdm_pwr_delta = cck_ofdm_pwr_delta; | ||
694 | ah->ah_txpower.txp_cck_ofdm_gainf_delta = | ||
695 | ee->ee_cck_ofdm_gain_delta; | ||
690 | } | 696 | } |
691 | 697 | ||
692 | /* Set antenna idle switch table */ | 698 | /* Set antenna idle switch table */ |
@@ -994,7 +1000,8 @@ int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode, | |||
994 | /* | 1000 | /* |
995 | * Set TX power (FIXME) | 1001 | * Set TX power (FIXME) |
996 | */ | 1002 | */ |
997 | ret = ath5k_hw_txpower(ah, channel, AR5K_TUNE_DEFAULT_TXPOWER); | 1003 | ret = ath5k_hw_txpower(ah, channel, ee_mode, |
1004 | AR5K_TUNE_DEFAULT_TXPOWER); | ||
998 | if (ret) | 1005 | if (ret) |
999 | return ret; | 1006 | return ret; |
1000 | 1007 | ||