aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath/ath9k/hw.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/ath/ath9k/hw.c')
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c384
1 files changed, 209 insertions, 175 deletions
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index c95bc5cc1a1f..b75b5dca4e29 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -130,6 +130,20 @@ bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
130} 130}
131EXPORT_SYMBOL(ath9k_hw_wait); 131EXPORT_SYMBOL(ath9k_hw_wait);
132 132
133void ath9k_hw_write_array(struct ath_hw *ah, struct ar5416IniArray *array,
134 int column, unsigned int *writecnt)
135{
136 int r;
137
138 ENABLE_REGWRITE_BUFFER(ah);
139 for (r = 0; r < array->ia_rows; r++) {
140 REG_WRITE(ah, INI_RA(array, r, 0),
141 INI_RA(array, r, column));
142 DO_DELAY(*writecnt);
143 }
144 REGWRITE_BUFFER_FLUSH(ah);
145}
146
133u32 ath9k_hw_reverse_bits(u32 val, u32 n) 147u32 ath9k_hw_reverse_bits(u32 val, u32 n)
134{ 148{
135 u32 retval; 149 u32 retval;
@@ -142,25 +156,6 @@ u32 ath9k_hw_reverse_bits(u32 val, u32 n)
142 return retval; 156 return retval;
143} 157}
144 158
145bool ath9k_get_channel_edges(struct ath_hw *ah,
146 u16 flags, u16 *low,
147 u16 *high)
148{
149 struct ath9k_hw_capabilities *pCap = &ah->caps;
150
151 if (flags & CHANNEL_5GHZ) {
152 *low = pCap->low_5ghz_chan;
153 *high = pCap->high_5ghz_chan;
154 return true;
155 }
156 if ((flags & CHANNEL_2GHZ)) {
157 *low = pCap->low_2ghz_chan;
158 *high = pCap->high_2ghz_chan;
159 return true;
160 }
161 return false;
162}
163
164u16 ath9k_hw_computetxtime(struct ath_hw *ah, 159u16 ath9k_hw_computetxtime(struct ath_hw *ah,
165 u8 phy, int kbps, 160 u8 phy, int kbps,
166 u32 frameLen, u16 rateix, 161 u32 frameLen, u16 rateix,
@@ -252,6 +247,17 @@ static void ath9k_hw_read_revisions(struct ath_hw *ah)
252{ 247{
253 u32 val; 248 u32 val;
254 249
250 switch (ah->hw_version.devid) {
251 case AR5416_AR9100_DEVID:
252 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
253 break;
254 case AR9300_DEVID_AR9340:
255 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
256 val = REG_READ(ah, AR_SREV);
257 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
258 return;
259 }
260
255 val = REG_READ(ah, AR_SREV) & AR_SREV_ID; 261 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
256 262
257 if (val == 0xFF) { 263 if (val == 0xFF) {
@@ -364,11 +370,6 @@ static void ath9k_hw_init_config(struct ath_hw *ah)
364 ah->config.spurchans[i][1] = AR_NO_SPUR; 370 ah->config.spurchans[i][1] = AR_NO_SPUR;
365 } 371 }
366 372
367 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
368 ah->config.ht_enable = 1;
369 else
370 ah->config.ht_enable = 0;
371
372 /* PAPRD needs some more work to be enabled */ 373 /* PAPRD needs some more work to be enabled */
373 ah->config.paprd_disable = 1; 374 ah->config.paprd_disable = 1;
374 375
@@ -410,6 +411,8 @@ static void ath9k_hw_init_defaults(struct ath_hw *ah)
410 ah->sta_id1_defaults = 411 ah->sta_id1_defaults =
411 AR_STA_ID1_CRPT_MIC_ENABLE | 412 AR_STA_ID1_CRPT_MIC_ENABLE |
412 AR_STA_ID1_MCAST_KSRCH; 413 AR_STA_ID1_MCAST_KSRCH;
414 if (AR_SREV_9100(ah))
415 ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
413 ah->enable_32kHz_clock = DONT_USE_32KHZ; 416 ah->enable_32kHz_clock = DONT_USE_32KHZ;
414 ah->slottime = 20; 417 ah->slottime = 20;
415 ah->globaltxtimeout = (u32) -1; 418 ah->globaltxtimeout = (u32) -1;
@@ -470,7 +473,7 @@ static int ath9k_hw_post_init(struct ath_hw *ah)
470 return ecode; 473 return ecode;
471 } 474 }
472 475
473 if (!AR_SREV_9100(ah)) { 476 if (!AR_SREV_9100(ah) && !AR_SREV_9340(ah)) {
474 ath9k_hw_ani_setup(ah); 477 ath9k_hw_ani_setup(ah);
475 ath9k_hw_ani_init(ah); 478 ath9k_hw_ani_init(ah);
476 } 479 }
@@ -492,9 +495,6 @@ static int __ath9k_hw_init(struct ath_hw *ah)
492 struct ath_common *common = ath9k_hw_common(ah); 495 struct ath_common *common = ath9k_hw_common(ah);
493 int r = 0; 496 int r = 0;
494 497
495 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
496 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
497
498 ath9k_hw_read_revisions(ah); 498 ath9k_hw_read_revisions(ah);
499 499
500 /* 500 /*
@@ -552,6 +552,7 @@ static int __ath9k_hw_init(struct ath_hw *ah)
552 case AR_SREV_VERSION_9271: 552 case AR_SREV_VERSION_9271:
553 case AR_SREV_VERSION_9300: 553 case AR_SREV_VERSION_9300:
554 case AR_SREV_VERSION_9485: 554 case AR_SREV_VERSION_9485:
555 case AR_SREV_VERSION_9340:
555 break; 556 break;
556 default: 557 default:
557 ath_err(common, 558 ath_err(common,
@@ -560,7 +561,7 @@ static int __ath9k_hw_init(struct ath_hw *ah)
560 return -EOPNOTSUPP; 561 return -EOPNOTSUPP;
561 } 562 }
562 563
563 if (AR_SREV_9271(ah) || AR_SREV_9100(ah)) 564 if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah))
564 ah->is_pciexpress = false; 565 ah->is_pciexpress = false;
565 566
566 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID); 567 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
@@ -629,6 +630,7 @@ int ath9k_hw_init(struct ath_hw *ah)
629 case AR2427_DEVID_PCIE: 630 case AR2427_DEVID_PCIE:
630 case AR9300_DEVID_PCIE: 631 case AR9300_DEVID_PCIE:
631 case AR9300_DEVID_AR9485_PCIE: 632 case AR9300_DEVID_AR9485_PCIE:
633 case AR9300_DEVID_AR9340:
632 break; 634 break;
633 default: 635 default:
634 if (common->bus_ops->ath_bus_type == ATH_USB) 636 if (common->bus_ops->ath_bus_type == ATH_USB)
@@ -671,48 +673,89 @@ static void ath9k_hw_init_qos(struct ath_hw *ah)
671 REGWRITE_BUFFER_FLUSH(ah); 673 REGWRITE_BUFFER_FLUSH(ah);
672} 674}
673 675
674unsigned long ar9003_get_pll_sqsum_dvc(struct ath_hw *ah) 676u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
675{ 677{
676 REG_WRITE(ah, PLL3, (REG_READ(ah, PLL3) & ~(PLL3_DO_MEAS_MASK))); 678 REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
677 udelay(100); 679 udelay(100);
678 REG_WRITE(ah, PLL3, (REG_READ(ah, PLL3) | PLL3_DO_MEAS_MASK)); 680 REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
679 681
680 while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0) 682 while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0)
681 udelay(100); 683 udelay(100);
682 684
683 return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3; 685 return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
684} 686}
685EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc); 687EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc);
686 688
687#define DPLL2_KD_VAL 0x3D
688#define DPLL2_KI_VAL 0x06
689#define DPLL3_PHASE_SHIFT_VAL 0x1
690
691static void ath9k_hw_init_pll(struct ath_hw *ah, 689static void ath9k_hw_init_pll(struct ath_hw *ah,
692 struct ath9k_channel *chan) 690 struct ath9k_channel *chan)
693{ 691{
694 u32 pll; 692 u32 pll;
695 693
696 if (AR_SREV_9485(ah)) { 694 if (AR_SREV_9485(ah)) {
697 REG_WRITE(ah, AR_RTC_PLL_CONTROL2, 0x886666);
698 REG_WRITE(ah, AR_CH0_DDR_DPLL2, 0x19e82f01);
699 695
700 REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3, 696 /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
701 AR_CH0_DPLL3_PHASE_SHIFT, DPLL3_PHASE_SHIFT_VAL); 697 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
702 698 AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
703 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c); 699 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
704 udelay(1000); 700 AR_CH0_DPLL2_KD, 0x40);
701 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
702 AR_CH0_DPLL2_KI, 0x4);
705 703
706 REG_WRITE(ah, AR_RTC_PLL_CONTROL2, 0x886666); 704 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
705 AR_CH0_BB_DPLL1_REFDIV, 0x5);
706 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
707 AR_CH0_BB_DPLL1_NINI, 0x58);
708 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
709 AR_CH0_BB_DPLL1_NFRAC, 0x0);
707 710
708 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, 711 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
709 AR_CH0_DPLL2_KD, DPLL2_KD_VAL); 712 AR_CH0_BB_DPLL2_OUTDIV, 0x1);
713 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
714 AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
710 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, 715 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
711 AR_CH0_DPLL2_KI, DPLL2_KI_VAL); 716 AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
712 717
718 /* program BB PLL phase_shift to 0x6 */
713 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3, 719 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
714 AR_CH0_DPLL3_PHASE_SHIFT, DPLL3_PHASE_SHIFT_VAL); 720 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
715 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x142c); 721
722 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
723 AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
724 udelay(1000);
725 } else if (AR_SREV_9340(ah)) {
726 u32 regval, pll2_divint, pll2_divfrac, refdiv;
727
728 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
729 udelay(1000);
730
731 REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
732 udelay(100);
733
734 if (ah->is_clk_25mhz) {
735 pll2_divint = 0x54;
736 pll2_divfrac = 0x1eb85;
737 refdiv = 3;
738 } else {
739 pll2_divint = 88;
740 pll2_divfrac = 0;
741 refdiv = 5;
742 }
743
744 regval = REG_READ(ah, AR_PHY_PLL_MODE);
745 regval |= (0x1 << 16);
746 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
747 udelay(100);
748
749 REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
750 (pll2_divint << 18) | pll2_divfrac);
751 udelay(100);
752
753 regval = REG_READ(ah, AR_PHY_PLL_MODE);
754 regval = (regval & 0x80071fff) | (0x1 << 30) | (0x1 << 13) |
755 (0x4 << 26) | (0x18 << 19);
756 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
757 REG_WRITE(ah, AR_PHY_PLL_MODE,
758 REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
716 udelay(1000); 759 udelay(1000);
717 } 760 }
718 761
@@ -720,6 +763,9 @@ static void ath9k_hw_init_pll(struct ath_hw *ah,
720 763
721 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll); 764 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
722 765
766 if (AR_SREV_9485(ah) || AR_SREV_9340(ah))
767 udelay(1000);
768
723 /* Switch the core clock for ar9271 to 117Mhz */ 769 /* Switch the core clock for ar9271 to 117Mhz */
724 if (AR_SREV_9271(ah)) { 770 if (AR_SREV_9271(ah)) {
725 udelay(500); 771 udelay(500);
@@ -729,17 +775,34 @@ static void ath9k_hw_init_pll(struct ath_hw *ah,
729 udelay(RTC_PLL_SETTLE_DELAY); 775 udelay(RTC_PLL_SETTLE_DELAY);
730 776
731 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK); 777 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
778
779 if (AR_SREV_9340(ah)) {
780 if (ah->is_clk_25mhz) {
781 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
782 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
783 REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
784 } else {
785 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
786 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
787 REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
788 }
789 udelay(100);
790 }
732} 791}
733 792
734static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah, 793static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
735 enum nl80211_iftype opmode) 794 enum nl80211_iftype opmode)
736{ 795{
796 u32 sync_default = AR_INTR_SYNC_DEFAULT;
737 u32 imr_reg = AR_IMR_TXERR | 797 u32 imr_reg = AR_IMR_TXERR |
738 AR_IMR_TXURN | 798 AR_IMR_TXURN |
739 AR_IMR_RXERR | 799 AR_IMR_RXERR |
740 AR_IMR_RXORN | 800 AR_IMR_RXORN |
741 AR_IMR_BCNMISC; 801 AR_IMR_BCNMISC;
742 802
803 if (AR_SREV_9340(ah))
804 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
805
743 if (AR_SREV_9300_20_OR_LATER(ah)) { 806 if (AR_SREV_9300_20_OR_LATER(ah)) {
744 imr_reg |= AR_IMR_RXOK_HP; 807 imr_reg |= AR_IMR_RXOK_HP;
745 if (ah->config.rx_intr_mitigation) 808 if (ah->config.rx_intr_mitigation)
@@ -770,7 +833,7 @@ static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
770 833
771 if (!AR_SREV_9100(ah)) { 834 if (!AR_SREV_9100(ah)) {
772 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF); 835 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
773 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT); 836 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
774 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0); 837 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
775 } 838 }
776 839
@@ -830,8 +893,7 @@ void ath9k_hw_init_global_settings(struct ath_hw *ah)
830 ah->misc_mode); 893 ah->misc_mode);
831 894
832 if (ah->misc_mode != 0) 895 if (ah->misc_mode != 0)
833 REG_WRITE(ah, AR_PCU_MISC, 896 REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
834 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
835 897
836 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ) 898 if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
837 sifstime = 16; 899 sifstime = 16;
@@ -899,23 +961,19 @@ u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
899static inline void ath9k_hw_set_dma(struct ath_hw *ah) 961static inline void ath9k_hw_set_dma(struct ath_hw *ah)
900{ 962{
901 struct ath_common *common = ath9k_hw_common(ah); 963 struct ath_common *common = ath9k_hw_common(ah);
902 u32 regval;
903 964
904 ENABLE_REGWRITE_BUFFER(ah); 965 ENABLE_REGWRITE_BUFFER(ah);
905 966
906 /* 967 /*
907 * set AHB_MODE not to do cacheline prefetches 968 * set AHB_MODE not to do cacheline prefetches
908 */ 969 */
909 if (!AR_SREV_9300_20_OR_LATER(ah)) { 970 if (!AR_SREV_9300_20_OR_LATER(ah))
910 regval = REG_READ(ah, AR_AHB_MODE); 971 REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
911 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
912 }
913 972
914 /* 973 /*
915 * let mac dma reads be in 128 byte chunks 974 * let mac dma reads be in 128 byte chunks
916 */ 975 */
917 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK; 976 REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
918 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
919 977
920 REGWRITE_BUFFER_FLUSH(ah); 978 REGWRITE_BUFFER_FLUSH(ah);
921 979
@@ -932,8 +990,7 @@ static inline void ath9k_hw_set_dma(struct ath_hw *ah)
932 /* 990 /*
933 * let mac dma writes be in 128 byte chunks 991 * let mac dma writes be in 128 byte chunks
934 */ 992 */
935 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK; 993 REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
936 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
937 994
938 /* 995 /*
939 * Setup receive FIFO threshold to hold off TX activities 996 * Setup receive FIFO threshold to hold off TX activities
@@ -972,30 +1029,27 @@ static inline void ath9k_hw_set_dma(struct ath_hw *ah)
972 1029
973static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode) 1030static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
974{ 1031{
975 u32 val; 1032 u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
1033 u32 set = AR_STA_ID1_KSRCH_MODE;
976 1034
977 val = REG_READ(ah, AR_STA_ID1);
978 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
979 switch (opmode) { 1035 switch (opmode) {
980 case NL80211_IFTYPE_AP:
981 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
982 | AR_STA_ID1_KSRCH_MODE);
983 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
984 break;
985 case NL80211_IFTYPE_ADHOC: 1036 case NL80211_IFTYPE_ADHOC:
986 case NL80211_IFTYPE_MESH_POINT: 1037 case NL80211_IFTYPE_MESH_POINT:
987 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC 1038 set |= AR_STA_ID1_ADHOC;
988 | AR_STA_ID1_KSRCH_MODE);
989 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION); 1039 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
990 break; 1040 break;
1041 case NL80211_IFTYPE_AP:
1042 set |= AR_STA_ID1_STA_AP;
1043 /* fall through */
991 case NL80211_IFTYPE_STATION: 1044 case NL80211_IFTYPE_STATION:
992 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE); 1045 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
993 break; 1046 break;
994 default: 1047 default:
995 if (ah->is_monitoring) 1048 if (!ah->is_monitoring)
996 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE); 1049 set = 0;
997 break; 1050 break;
998 } 1051 }
1052 REG_RMW(ah, AR_STA_ID1, set, mask);
999} 1053}
1000 1054
1001void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled, 1055void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
@@ -1021,10 +1075,8 @@ static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
1021 u32 tmpReg; 1075 u32 tmpReg;
1022 1076
1023 if (AR_SREV_9100(ah)) { 1077 if (AR_SREV_9100(ah)) {
1024 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK); 1078 REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
1025 val &= ~AR_RTC_DERIVED_CLK_PERIOD; 1079 AR_RTC_DERIVED_CLK_PERIOD, 1);
1026 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1027 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1028 (void)REG_READ(ah, AR_RTC_DERIVED_CLK); 1080 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1029 } 1081 }
1030 1082
@@ -1212,6 +1264,20 @@ static bool ath9k_hw_channel_change(struct ath_hw *ah,
1212 return true; 1264 return true;
1213} 1265}
1214 1266
1267static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
1268{
1269 u32 gpio_mask = ah->gpio_mask;
1270 int i;
1271
1272 for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
1273 if (!(gpio_mask & 1))
1274 continue;
1275
1276 ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1277 ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
1278 }
1279}
1280
1215bool ath9k_hw_check_alive(struct ath_hw *ah) 1281bool ath9k_hw_check_alive(struct ath_hw *ah)
1216{ 1282{
1217 int count = 50; 1283 int count = 50;
@@ -1409,7 +1475,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1409 REGWRITE_BUFFER_FLUSH(ah); 1475 REGWRITE_BUFFER_FLUSH(ah);
1410 1476
1411 ah->intr_txqs = 0; 1477 ah->intr_txqs = 0;
1412 for (i = 0; i < ah->caps.total_queues; i++) 1478 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1413 ath9k_hw_resettxqueue(ah, i); 1479 ath9k_hw_resettxqueue(ah, i);
1414 1480
1415 ath9k_hw_init_interrupt_masks(ah, ah->opmode); 1481 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
@@ -1426,8 +1492,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1426 ar9002_hw_enable_wep_aggregation(ah); 1492 ar9002_hw_enable_wep_aggregation(ah);
1427 } 1493 }
1428 1494
1429 REG_WRITE(ah, AR_STA_ID1, 1495 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
1430 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
1431 1496
1432 ath9k_hw_set_dma(ah); 1497 ath9k_hw_set_dma(ah);
1433 1498
@@ -1480,7 +1545,9 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1480 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD); 1545 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1481 } 1546 }
1482#ifdef __BIG_ENDIAN 1547#ifdef __BIG_ENDIAN
1483 else 1548 else if (AR_SREV_9340(ah))
1549 REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
1550 else
1484 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD); 1551 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1485#endif 1552#endif
1486 } 1553 }
@@ -1491,6 +1558,8 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1491 if (AR_SREV_9300_20_OR_LATER(ah)) 1558 if (AR_SREV_9300_20_OR_LATER(ah))
1492 ar9003_hw_bb_watchdog_config(ah); 1559 ar9003_hw_bb_watchdog_config(ah);
1493 1560
1561 ath9k_hw_apply_gpio_override(ah);
1562
1494 return 0; 1563 return 0;
1495} 1564}
1496EXPORT_SYMBOL(ath9k_hw_reset); 1565EXPORT_SYMBOL(ath9k_hw_reset);
@@ -1670,21 +1739,15 @@ void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
1670 case NL80211_IFTYPE_MESH_POINT: 1739 case NL80211_IFTYPE_MESH_POINT:
1671 REG_SET_BIT(ah, AR_TXCFG, 1740 REG_SET_BIT(ah, AR_TXCFG,
1672 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY); 1741 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
1673 REG_WRITE(ah, AR_NEXT_NDP_TIMER, 1742 REG_WRITE(ah, AR_NEXT_NDP_TIMER, next_beacon +
1674 TU_TO_USEC(next_beacon + 1743 TU_TO_USEC(ah->atim_window ? ah->atim_window : 1));
1675 (ah->atim_window ? ah->
1676 atim_window : 1)));
1677 flags |= AR_NDP_TIMER_EN; 1744 flags |= AR_NDP_TIMER_EN;
1678 case NL80211_IFTYPE_AP: 1745 case NL80211_IFTYPE_AP:
1679 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon)); 1746 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
1680 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 1747 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
1681 TU_TO_USEC(next_beacon - 1748 TU_TO_USEC(ah->config.dma_beacon_response_time));
1682 ah->config. 1749 REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
1683 dma_beacon_response_time)); 1750 TU_TO_USEC(ah->config.sw_beacon_response_time));
1684 REG_WRITE(ah, AR_NEXT_SWBA,
1685 TU_TO_USEC(next_beacon -
1686 ah->config.
1687 sw_beacon_response_time));
1688 flags |= 1751 flags |=
1689 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN; 1752 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
1690 break; 1753 break;
@@ -1696,18 +1759,13 @@ void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
1696 break; 1759 break;
1697 } 1760 }
1698 1761
1699 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period)); 1762 REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
1700 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period)); 1763 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
1701 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period)); 1764 REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
1702 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period)); 1765 REG_WRITE(ah, AR_NDP_PERIOD, beacon_period);
1703 1766
1704 REGWRITE_BUFFER_FLUSH(ah); 1767 REGWRITE_BUFFER_FLUSH(ah);
1705 1768
1706 beacon_period &= ~ATH9K_BEACON_ENA;
1707 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
1708 ath9k_hw_reset_tsf(ah);
1709 }
1710
1711 REG_SET_BIT(ah, AR_TIMER_MODE, flags); 1769 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
1712} 1770}
1713EXPORT_SYMBOL(ath9k_hw_beaconinit); 1771EXPORT_SYMBOL(ath9k_hw_beaconinit);
@@ -1795,7 +1853,7 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
1795 struct ath_common *common = ath9k_hw_common(ah); 1853 struct ath_common *common = ath9k_hw_common(ah);
1796 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw; 1854 struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
1797 1855
1798 u16 capField = 0, eeval; 1856 u16 eeval;
1799 u8 ant_div_ctl1, tx_chainmask, rx_chainmask; 1857 u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
1800 1858
1801 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0); 1859 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
@@ -1806,8 +1864,6 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
1806 eeval |= AR9285_RDEXT_DEFAULT; 1864 eeval |= AR9285_RDEXT_DEFAULT;
1807 regulatory->current_rd_ext = eeval; 1865 regulatory->current_rd_ext = eeval;
1808 1866
1809 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
1810
1811 if (ah->opmode != NL80211_IFTYPE_AP && 1867 if (ah->opmode != NL80211_IFTYPE_AP &&
1812 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) { 1868 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
1813 if (regulatory->current_rd == 0x64 || 1869 if (regulatory->current_rd == 0x64 ||
@@ -1842,6 +1898,8 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
1842 !(AR_SREV_9271(ah))) 1898 !(AR_SREV_9271(ah)))
1843 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */ 1899 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
1844 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7; 1900 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
1901 else if (AR_SREV_9100(ah))
1902 pCap->rx_chainmask = 0x7;
1845 else 1903 else
1846 /* Use rx_chainmask from EEPROM. */ 1904 /* Use rx_chainmask from EEPROM. */
1847 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK); 1905 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
@@ -1852,36 +1910,13 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
1852 if (AR_SREV_9300_20_OR_LATER(ah)) 1910 if (AR_SREV_9300_20_OR_LATER(ah))
1853 ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH; 1911 ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
1854 1912
1855 pCap->low_2ghz_chan = 2312;
1856 pCap->high_2ghz_chan = 2732;
1857
1858 pCap->low_5ghz_chan = 4920;
1859 pCap->high_5ghz_chan = 6100;
1860
1861 common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM; 1913 common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
1862 1914
1863 if (ah->config.ht_enable) 1915 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
1864 pCap->hw_caps |= ATH9K_HW_CAP_HT; 1916 pCap->hw_caps |= ATH9K_HW_CAP_HT;
1865 else 1917 else
1866 pCap->hw_caps &= ~ATH9K_HW_CAP_HT; 1918 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
1867 1919
1868 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
1869 pCap->total_queues =
1870 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
1871 else
1872 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
1873
1874 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
1875 pCap->keycache_size =
1876 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
1877 else
1878 pCap->keycache_size = AR_KEYTABLE_SIZE;
1879
1880 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
1881 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
1882 else
1883 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
1884
1885 if (AR_SREV_9271(ah)) 1920 if (AR_SREV_9271(ah))
1886 pCap->num_gpio_pins = AR9271_NUM_GPIO; 1921 pCap->num_gpio_pins = AR9271_NUM_GPIO;
1887 else if (AR_DEVID_7010(ah)) 1922 else if (AR_DEVID_7010(ah))
@@ -1900,8 +1935,6 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
1900 pCap->rts_aggr_limit = (8 * 1024); 1935 pCap->rts_aggr_limit = (8 * 1024);
1901 } 1936 }
1902 1937
1903 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
1904
1905#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) 1938#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
1906 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT); 1939 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
1907 if (ah->rfsilent & EEP_RFSILENT_ENABLED) { 1940 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
@@ -1923,32 +1956,23 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
1923 else 1956 else
1924 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS; 1957 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
1925 1958
1926 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) { 1959 if (common->btcoex_enabled) {
1927 pCap->reg_cap = 1960 if (AR_SREV_9300_20_OR_LATER(ah)) {
1928 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
1929 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
1930 AR_EEPROM_EEREGCAP_EN_KK_U2 |
1931 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
1932 } else {
1933 pCap->reg_cap =
1934 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
1935 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
1936 }
1937
1938 /* Advertise midband for AR5416 with FCC midband set in eeprom */
1939 if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
1940 AR_SREV_5416(ah))
1941 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
1942
1943 if (AR_SREV_9280_20_OR_LATER(ah) && common->btcoex_enabled) {
1944 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
1945 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
1946
1947 if (AR_SREV_9285(ah)) {
1948 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE; 1961 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
1949 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO; 1962 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO_9300;
1950 } else { 1963 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO_9300;
1951 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE; 1964 btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO_9300;
1965 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
1966 btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO_9280;
1967 btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO_9280;
1968
1969 if (AR_SREV_9285(ah)) {
1970 btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
1971 btcoex_hw->btpriority_gpio =
1972 ATH_BTPRIORITY_GPIO_9285;
1973 } else {
1974 btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
1975 }
1952 } 1976 }
1953 } else { 1977 } else {
1954 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE; 1978 btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
@@ -1998,6 +2022,22 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
1998 } 2022 }
1999 2023
2000 2024
2025 if (AR_SREV_9485(ah)) {
2026 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2027 /*
2028 * enable the diversity-combining algorithm only when
2029 * both enable_lna_div and enable_fast_div are set
2030 * Table for Diversity
2031 * ant_div_alt_lnaconf bit 0-1
2032 * ant_div_main_lnaconf bit 2-3
2033 * ant_div_alt_gaintb bit 4
2034 * ant_div_main_gaintb bit 5
2035 * enable_ant_div_lnadiv bit 6
2036 * enable_ant_fast_div bit 7
2037 */
2038 if ((ant_div_ctl1 >> 0x6) == 0x3)
2039 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2040 }
2001 2041
2002 if (AR_SREV_9485_10(ah)) { 2042 if (AR_SREV_9485_10(ah)) {
2003 pCap->pcie_lcr_extsync_en = true; 2043 pCap->pcie_lcr_extsync_en = true;
@@ -2186,11 +2226,9 @@ void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
2186 REG_WRITE(ah, AR_PHY_ERR, phybits); 2226 REG_WRITE(ah, AR_PHY_ERR, phybits);
2187 2227
2188 if (phybits) 2228 if (phybits)
2189 REG_WRITE(ah, AR_RXCFG, 2229 REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
2190 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
2191 else 2230 else
2192 REG_WRITE(ah, AR_RXCFG, 2231 REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
2193 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
2194 2232
2195 REGWRITE_BUFFER_FLUSH(ah); 2233 REGWRITE_BUFFER_FLUSH(ah);
2196} 2234}
@@ -2366,10 +2404,11 @@ static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
2366 return timer_table->gen_timer_index[b]; 2404 return timer_table->gen_timer_index[b];
2367} 2405}
2368 2406
2369static u32 ath9k_hw_gettsf32(struct ath_hw *ah) 2407u32 ath9k_hw_gettsf32(struct ath_hw *ah)
2370{ 2408{
2371 return REG_READ(ah, AR_TSF_L32); 2409 return REG_READ(ah, AR_TSF_L32);
2372} 2410}
2411EXPORT_SYMBOL(ath9k_hw_gettsf32);
2373 2412
2374struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah, 2413struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2375 void (*trigger)(void *), 2414 void (*trigger)(void *),
@@ -2402,11 +2441,11 @@ EXPORT_SYMBOL(ath_gen_timer_alloc);
2402 2441
2403void ath9k_hw_gen_timer_start(struct ath_hw *ah, 2442void ath9k_hw_gen_timer_start(struct ath_hw *ah,
2404 struct ath_gen_timer *timer, 2443 struct ath_gen_timer *timer,
2405 u32 timer_next, 2444 u32 trig_timeout,
2406 u32 timer_period) 2445 u32 timer_period)
2407{ 2446{
2408 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers; 2447 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2409 u32 tsf; 2448 u32 tsf, timer_next;
2410 2449
2411 BUG_ON(!timer_period); 2450 BUG_ON(!timer_period);
2412 2451
@@ -2414,18 +2453,13 @@ void ath9k_hw_gen_timer_start(struct ath_hw *ah,
2414 2453
2415 tsf = ath9k_hw_gettsf32(ah); 2454 tsf = ath9k_hw_gettsf32(ah);
2416 2455
2456 timer_next = tsf + trig_timeout;
2457
2417 ath_dbg(ath9k_hw_common(ah), ATH_DBG_HWTIMER, 2458 ath_dbg(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
2418 "current tsf %x period %x timer_next %x\n", 2459 "current tsf %x period %x timer_next %x\n",
2419 tsf, timer_period, timer_next); 2460 tsf, timer_period, timer_next);
2420 2461
2421 /* 2462 /*
2422 * Pull timer_next forward if the current TSF already passed it
2423 * because of software latency
2424 */
2425 if (timer_next < tsf)
2426 timer_next = tsf + timer_period;
2427
2428 /*
2429 * Program generic timer registers 2463 * Program generic timer registers
2430 */ 2464 */
2431 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr, 2465 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,