3838#define AR_SWITCH_TABLE_ALL (0xfff)
3939#define AR_SWITCH_TABLE_ALL_S (0)
4040
41+ #define LE16 (x ) __constant_cpu_to_le16(x)
42+ #define LE32 (x ) __constant_cpu_to_le32(x)
43+
4144static const struct ar9300_eeprom ar9300_default = {
4245 .eepromVersion = 2 ,
4346 .templateVersion = 2 ,
4447 .macAddr = {1 , 2 , 3 , 4 , 5 , 6 },
4548 .custData = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4649 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
4750 .baseEepHeader = {
48- .regDmn = {0 , 0x1f },
51+ .regDmn = { LE16 ( 0 ), LE16 ( 0x1f ) },
4952 .txrxMask = 0x77 , /* 4 bits tx and 4 bits rx */
5053 .opCapFlags = {
5154 .opFlags = AR9300_OPFLAGS_11G | AR9300_OPFLAGS_11A ,
@@ -76,15 +79,15 @@ static const struct ar9300_eeprom ar9300_default = {
7679 .modalHeader2G = {
7780 /* ar9300_modal_eep_header 2g */
7881 /* 4 idle,t1,t2,b(4 bits per setting) */
79- .antCtrlCommon = 0x110 ,
82+ .antCtrlCommon = LE32 ( 0x110 ) ,
8083 /* 4 ra1l1, ra2l1, ra1l2, ra2l2, ra12 */
81- .antCtrlCommon2 = 0x22222 ,
84+ .antCtrlCommon2 = LE32 ( 0x22222 ) ,
8285
8386 /*
8487 * antCtrlChain[AR9300_MAX_CHAINS]; 6 idle, t, r,
8588 * rx1, rx12, b (2 bits each)
8689 */
87- .antCtrlChain = {0x150 , 0x150 , 0x150 },
90+ .antCtrlChain = { LE16 ( 0x150 ), LE16 ( 0x150 ), LE16 ( 0x150 ) },
8891
8992 /*
9093 * xatten1DB[AR9300_MAX_CHAINS]; 3 xatten1_db
@@ -287,12 +290,12 @@ static const struct ar9300_eeprom ar9300_default = {
287290 },
288291 .modalHeader5G = {
289292 /* 4 idle,t1,t2,b (4 bits per setting) */
290- .antCtrlCommon = 0x110 ,
293+ .antCtrlCommon = LE32 ( 0x110 ) ,
291294 /* 4 ra1l1, ra2l1, ra1l2,ra2l2,ra12 */
292- .antCtrlCommon2 = 0x22222 ,
295+ .antCtrlCommon2 = LE32 ( 0x22222 ) ,
293296 /* antCtrlChain 6 idle, t,r,rx1,rx12,b (2 bits each) */
294297 .antCtrlChain = {
295- 0x000 , 0x000 , 0x000 ,
298+ LE16 ( 0x000 ), LE16 ( 0x000 ), LE16 ( 0x000 ) ,
296299 },
297300 /* xatten1DB 3 xatten1_db for AR9280 (0xa20c/b20c 5:0) */
298301 .xatten1DB = {0 , 0 , 0 },
@@ -620,9 +623,9 @@ static u32 ath9k_hw_ar9300_get_eeprom(struct ath_hw *ah,
620623 case EEP_MAC_MSW :
621624 return eep -> macAddr [4 ] << 8 | eep -> macAddr [5 ];
622625 case EEP_REG_0 :
623- return pBase -> regDmn [0 ];
626+ return le16_to_cpu ( pBase -> regDmn [0 ]) ;
624627 case EEP_REG_1 :
625- return pBase -> regDmn [1 ];
628+ return le16_to_cpu ( pBase -> regDmn [1 ]) ;
626629 case EEP_OP_CAP :
627630 return pBase -> deviceCap ;
628631 case EEP_OP_MODE :
@@ -640,93 +643,80 @@ static u32 ath9k_hw_ar9300_get_eeprom(struct ath_hw *ah,
640643 /* Bit 4 is internal regulator flag */
641644 return (pBase -> featureEnable & 0x10 ) >> 4 ;
642645 case EEP_SWREG :
643- return pBase -> swreg ;
646+ return le32_to_cpu ( pBase -> swreg ) ;
644647 default :
645648 return 0 ;
646649 }
647650}
648651
649- #ifdef __BIG_ENDIAN
650- static void ar9300_swap_eeprom ( struct ar9300_eeprom * eep )
652+ static bool ar9300_eeprom_read_byte ( struct ath_common * common , int address ,
653+ u8 * buffer )
651654{
652- u32 dword ;
653- u16 word ;
654- int i ;
655-
656- word = swab16 (eep -> baseEepHeader .regDmn [0 ]);
657- eep -> baseEepHeader .regDmn [0 ] = word ;
658-
659- word = swab16 (eep -> baseEepHeader .regDmn [1 ]);
660- eep -> baseEepHeader .regDmn [1 ] = word ;
661-
662- dword = swab32 (eep -> baseEepHeader .swreg );
663- eep -> baseEepHeader .swreg = dword ;
655+ u16 val ;
664656
665- dword = swab32 ( eep -> modalHeader2G . antCtrlCommon );
666- eep -> modalHeader2G . antCtrlCommon = dword ;
657+ if ( unlikely (! ath9k_hw_nvram_read ( common , address / 2 , & val )))
658+ return false ;
667659
668- dword = swab32 (eep -> modalHeader2G .antCtrlCommon2 );
669- eep -> modalHeader2G .antCtrlCommon2 = dword ;
660+ * buffer = (val >> (8 * (address % 2 ))) & 0xff ;
661+ return true;
662+ }
670663
671- dword = swab32 (eep -> modalHeader5G .antCtrlCommon );
672- eep -> modalHeader5G .antCtrlCommon = dword ;
664+ static bool ar9300_eeprom_read_word (struct ath_common * common , int address ,
665+ u8 * buffer )
666+ {
667+ u16 val ;
673668
674- dword = swab32 ( eep -> modalHeader5G . antCtrlCommon2 );
675- eep -> modalHeader5G . antCtrlCommon2 = dword ;
669+ if ( unlikely (! ath9k_hw_nvram_read ( common , address / 2 , & val )))
670+ return false ;
676671
677- for (i = 0 ; i < AR9300_MAX_CHAINS ; i ++ ) {
678- word = swab16 (eep -> modalHeader2G .antCtrlChain [i ]);
679- eep -> modalHeader2G .antCtrlChain [i ] = word ;
672+ buffer [0 ] = val >> 8 ;
673+ buffer [1 ] = val & 0xff ;
680674
681- word = swab16 (eep -> modalHeader5G .antCtrlChain [i ]);
682- eep -> modalHeader5G .antCtrlChain [i ] = word ;
683- }
675+ return true;
684676}
685- #endif
686677
687- static bool ar9300_hw_read_eeprom (struct ath_hw * ah ,
688- long address , u8 * buffer , int many )
678+ static bool ar9300_read_eeprom (struct ath_hw * ah , int address , u8 * buffer ,
679+ int count )
689680{
690- int i ;
691- u8 value [2 ];
692- unsigned long eepAddr ;
693- unsigned long byteAddr ;
694- u16 * svalue ;
695681 struct ath_common * common = ath9k_hw_common (ah );
682+ int i ;
696683
697- if ((address < 0 ) || ((address + many ) > AR9300_EEPROM_SIZE - 1 )) {
684+ if ((address < 0 ) || ((address + count ) / 2 > AR9300_EEPROM_SIZE - 1 )) {
698685 ath_print (common , ATH_DBG_EEPROM ,
699686 "eeprom address not in range\n" );
700687 return false;
701688 }
702689
703- for (i = 0 ; i < many ; i ++ ) {
704- eepAddr = (u16 ) (address + i ) / 2 ;
705- byteAddr = (u16 ) (address + i ) % 2 ;
706- svalue = (u16 * ) value ;
707- if (!ath9k_hw_nvram_read (common , eepAddr , svalue )) {
708- ath_print (common , ATH_DBG_EEPROM ,
709- "unable to read eeprom region\n" );
710- return false;
711- }
712- * svalue = le16_to_cpu (* svalue );
713- buffer [i ] = value [byteAddr ];
690+ /*
691+ * Since we're reading the bytes in reverse order from a little-endian
692+ * word stream, an even address means we only use the lower half of
693+ * the 16-bit word at that address
694+ */
695+ if (address % 2 == 0 ) {
696+ if (!ar9300_eeprom_read_byte (common , address -- , buffer ++ ))
697+ goto error ;
698+
699+ count -- ;
714700 }
715701
716- return true;
717- }
702+ for (i = 0 ; i < count / 2 ; i ++ ) {
703+ if (!ar9300_eeprom_read_word (common , address , buffer ))
704+ goto error ;
718705
719- static bool ar9300_read_eeprom (struct ath_hw * ah ,
720- int address , u8 * buffer , int many )
721- {
722- int it ;
706+ address -= 2 ;
707+ buffer += 2 ;
708+ }
709+
710+ if (count % 2 )
711+ if (!ar9300_eeprom_read_byte (common , address , buffer ))
712+ goto error ;
723713
724- for (it = 0 ; it < many ; it ++ )
725- if (!ar9300_hw_read_eeprom (ah ,
726- (address - it ),
727- (buffer + it ), 1 ))
728- return false;
729714 return true;
715+
716+ error :
717+ ath_print (common , ATH_DBG_EEPROM ,
718+ "unable to read eeprom region at offset %d\n" , address );
719+ return false;
730720}
731721
732722static void ar9300_comp_hdr_unpack (u8 * best , int * code , int * reference ,
@@ -927,30 +917,13 @@ static int ar9300_eeprom_restore_internal(struct ath_hw *ah,
927917 */
928918static bool ath9k_hw_ar9300_fill_eeprom (struct ath_hw * ah )
929919{
930- u8 * mptr = NULL ;
931- int mdata_size ;
920+ u8 * mptr = (u8 * ) & ah -> eeprom .ar9300_eep ;
932921
933- mptr = (u8 * ) & ah -> eeprom .ar9300_eep ;
934- mdata_size = sizeof (struct ar9300_eeprom );
922+ if (ar9300_eeprom_restore_internal (ah , mptr ,
923+ sizeof (struct ar9300_eeprom )) < 0 )
924+ return false;
935925
936- if (mptr && mdata_size > 0 ) {
937- /* At this point, mptr points to the eeprom data structure
938- * in it's "default" state. If this is big endian, swap the
939- * data structures back to "little endian"
940- */
941- /* First swap, default to Little Endian */
942- #ifdef __BIG_ENDIAN
943- ar9300_swap_eeprom ((struct ar9300_eeprom * )mptr );
944- #endif
945- if (ar9300_eeprom_restore_internal (ah , mptr , mdata_size ) >= 0 )
946- return true;
947-
948- /* Second Swap, back to Big Endian */
949- #ifdef __BIG_ENDIAN
950- ar9300_swap_eeprom ((struct ar9300_eeprom * )mptr );
951- #endif
952- }
953- return false;
926+ return true;
954927}
955928
956929/* XXX: review hardware docs */
@@ -998,37 +971,42 @@ static void ar9003_hw_xpa_bias_level_apply(struct ath_hw *ah, bool is2ghz)
998971static u32 ar9003_hw_ant_ctrl_common_get (struct ath_hw * ah , bool is2ghz )
999972{
1000973 struct ar9300_eeprom * eep = & ah -> eeprom .ar9300_eep ;
974+ __le32 val ;
1001975
1002976 if (is2ghz )
1003- return eep -> modalHeader2G .antCtrlCommon ;
977+ val = eep -> modalHeader2G .antCtrlCommon ;
1004978 else
1005- return eep -> modalHeader5G .antCtrlCommon ;
979+ val = eep -> modalHeader5G .antCtrlCommon ;
980+ return le32_to_cpu (val );
1006981}
1007982
1008983static u32 ar9003_hw_ant_ctrl_common_2_get (struct ath_hw * ah , bool is2ghz )
1009984{
1010985 struct ar9300_eeprom * eep = & ah -> eeprom .ar9300_eep ;
986+ __le32 val ;
1011987
1012988 if (is2ghz )
1013- return eep -> modalHeader2G .antCtrlCommon2 ;
989+ val = eep -> modalHeader2G .antCtrlCommon2 ;
1014990 else
1015- return eep -> modalHeader5G .antCtrlCommon2 ;
991+ val = eep -> modalHeader5G .antCtrlCommon2 ;
992+ return le32_to_cpu (val );
1016993}
1017994
1018995static u16 ar9003_hw_ant_ctrl_chain_get (struct ath_hw * ah ,
1019996 int chain ,
1020997 bool is2ghz )
1021998{
1022999 struct ar9300_eeprom * eep = & ah -> eeprom .ar9300_eep ;
1000+ __le16 val = 0 ;
10231001
10241002 if (chain >= 0 && chain < AR9300_MAX_CHAINS ) {
10251003 if (is2ghz )
1026- return eep -> modalHeader2G .antCtrlChain [chain ];
1004+ val = eep -> modalHeader2G .antCtrlChain [chain ];
10271005 else
1028- return eep -> modalHeader5G .antCtrlChain [chain ];
1006+ val = eep -> modalHeader5G .antCtrlChain [chain ];
10291007 }
10301008
1031- return 0 ;
1009+ return le16_to_cpu ( val ) ;
10321010}
10331011
10341012static void ar9003_hw_ant_ctrl_apply (struct ath_hw * ah , bool is2ghz )
0 commit comments