aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rtlwifi/efuse.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/rtlwifi/efuse.c')
-rw-r--r--drivers/net/wireless/rtlwifi/efuse.c106
1 files changed, 50 insertions, 56 deletions
diff --git a/drivers/net/wireless/rtlwifi/efuse.c b/drivers/net/wireless/rtlwifi/efuse.c
index f74a8701c67..5d73c0f7012 100644
--- a/drivers/net/wireless/rtlwifi/efuse.c
+++ b/drivers/net/wireless/rtlwifi/efuse.c
@@ -338,11 +338,11 @@ bool efuse_shadow_update_chk(struct ieee80211_hw *hw)
338 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 338 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
339 u8 section_idx, i, Base; 339 u8 section_idx, i, Base;
340 u16 words_need = 0, hdr_num = 0, totalbytes, efuse_used; 340 u16 words_need = 0, hdr_num = 0, totalbytes, efuse_used;
341 bool bwordchanged, bresult = true; 341 bool wordchanged, result = true;
342 342
343 for (section_idx = 0; section_idx < 16; section_idx++) { 343 for (section_idx = 0; section_idx < 16; section_idx++) {
344 Base = section_idx * 8; 344 Base = section_idx * 8;
345 bwordchanged = false; 345 wordchanged = false;
346 346
347 for (i = 0; i < 8; i = i + 2) { 347 for (i = 0; i < 8; i = i + 2) {
348 if ((rtlefuse->efuse_map[EFUSE_INIT_MAP][Base + i] != 348 if ((rtlefuse->efuse_map[EFUSE_INIT_MAP][Base + i] !=
@@ -351,11 +351,11 @@ bool efuse_shadow_update_chk(struct ieee80211_hw *hw)
351 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][Base + i + 351 rtlefuse->efuse_map[EFUSE_MODIFY_MAP][Base + i +
352 1])) { 352 1])) {
353 words_need++; 353 words_need++;
354 bwordchanged = true; 354 wordchanged = true;
355 } 355 }
356 } 356 }
357 357
358 if (bwordchanged == true) 358 if (wordchanged == true)
359 hdr_num++; 359 hdr_num++;
360 } 360 }
361 361
@@ -364,14 +364,14 @@ bool efuse_shadow_update_chk(struct ieee80211_hw *hw)
364 364
365 if ((totalbytes + efuse_used) >= 365 if ((totalbytes + efuse_used) >=
366 (EFUSE_MAX_SIZE - EFUSE_OOB_PROTECT_BYTES)) 366 (EFUSE_MAX_SIZE - EFUSE_OOB_PROTECT_BYTES))
367 bresult = false; 367 result = false;
368 368
369 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, 369 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
370 ("efuse_shadow_update_chk(): totalbytes(%#x), " 370 ("efuse_shadow_update_chk(): totalbytes(%#x), "
371 "hdr_num(%#x), words_need(%#x), efuse_used(%d)\n", 371 "hdr_num(%#x), words_need(%#x), efuse_used(%d)\n",
372 totalbytes, hdr_num, words_need, efuse_used)); 372 totalbytes, hdr_num, words_need, efuse_used));
373 373
374 return bresult; 374 return result;
375} 375}
376 376
377void efuse_shadow_read(struct ieee80211_hw *hw, u8 type, 377void efuse_shadow_read(struct ieee80211_hw *hw, u8 type,
@@ -394,7 +394,7 @@ void efuse_shadow_write(struct ieee80211_hw *hw, u8 type, u16 offset,
394 else if (type == 2) 394 else if (type == 2)
395 efuse_shadow_write_2byte(hw, offset, (u16) value); 395 efuse_shadow_write_2byte(hw, offset, (u16) value);
396 else if (type == 4) 396 else if (type == 4)
397 efuse_shadow_write_4byte(hw, offset, (u32) value); 397 efuse_shadow_write_4byte(hw, offset, value);
398 398
399} 399}
400 400
@@ -572,7 +572,7 @@ static int efuse_one_byte_read(struct ieee80211_hw *hw, u16 addr, u8 *data)
572{ 572{
573 struct rtl_priv *rtlpriv = rtl_priv(hw); 573 struct rtl_priv *rtlpriv = rtl_priv(hw);
574 u8 tmpidx = 0; 574 u8 tmpidx = 0;
575 int bresult; 575 int result;
576 576
577 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1, 577 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1,
578 (u8) (addr & 0xff)); 578 (u8) (addr & 0xff));
@@ -592,19 +592,18 @@ static int efuse_one_byte_read(struct ieee80211_hw *hw, u16 addr, u8 *data)
592 592
593 if (tmpidx < 100) { 593 if (tmpidx < 100) {
594 *data = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]); 594 *data = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL]);
595 bresult = true; 595 result = true;
596 } else { 596 } else {
597 *data = 0xff; 597 *data = 0xff;
598 bresult = false; 598 result = false;
599 } 599 }
600 return bresult; 600 return result;
601} 601}
602 602
603static int efuse_one_byte_write(struct ieee80211_hw *hw, u16 addr, u8 data) 603static int efuse_one_byte_write(struct ieee80211_hw *hw, u16 addr, u8 data)
604{ 604{
605 struct rtl_priv *rtlpriv = rtl_priv(hw); 605 struct rtl_priv *rtlpriv = rtl_priv(hw);
606 u8 tmpidx = 0; 606 u8 tmpidx = 0;
607 bool bresult;
608 607
609 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, 608 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
610 ("Addr = %x Data=%x\n", addr, data)); 609 ("Addr = %x Data=%x\n", addr, data));
@@ -626,11 +625,9 @@ static int efuse_one_byte_write(struct ieee80211_hw *hw, u16 addr, u8 data)
626 } 625 }
627 626
628 if (tmpidx < 100) 627 if (tmpidx < 100)
629 bresult = true; 628 return true;
630 else
631 bresult = false;
632 629
633 return bresult; 630 return false;
634} 631}
635 632
636static void efuse_read_all_map(struct ieee80211_hw *hw, u8 * efuse) 633static void efuse_read_all_map(struct ieee80211_hw *hw, u8 * efuse)
@@ -681,11 +678,10 @@ static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset, u8 *data)
681{ 678{
682 u8 readstate = PG_STATE_HEADER; 679 u8 readstate = PG_STATE_HEADER;
683 680
684 bool bcontinual = true; 681 bool continual = true;
685 682
686 u8 efuse_data, word_cnts = 0; 683 u8 efuse_data, word_cnts = 0;
687 u16 efuse_addr = 0; 684 u16 efuse_addr = 0;
688 u8 hworden;
689 u8 tmpdata[8]; 685 u8 tmpdata[8];
690 686
691 if (data == NULL) 687 if (data == NULL)
@@ -696,7 +692,7 @@ static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset, u8 *data)
696 memset(data, 0xff, PGPKT_DATA_SIZE * sizeof(u8)); 692 memset(data, 0xff, PGPKT_DATA_SIZE * sizeof(u8));
697 memset(tmpdata, 0xff, PGPKT_DATA_SIZE * sizeof(u8)); 693 memset(tmpdata, 0xff, PGPKT_DATA_SIZE * sizeof(u8));
698 694
699 while (bcontinual && (efuse_addr < EFUSE_MAX_SIZE)) { 695 while (continual && (efuse_addr < EFUSE_MAX_SIZE)) {
700 if (readstate & PG_STATE_HEADER) { 696 if (readstate & PG_STATE_HEADER) {
701 if (efuse_one_byte_read(hw, efuse_addr, &efuse_data) 697 if (efuse_one_byte_read(hw, efuse_addr, &efuse_data)
702 && (efuse_data != 0xFF)) 698 && (efuse_data != 0xFF))
@@ -705,9 +701,9 @@ static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset, u8 *data)
705 offset, tmpdata, 701 offset, tmpdata,
706 &readstate); 702 &readstate);
707 else 703 else
708 bcontinual = false; 704 continual = false;
709 } else if (readstate & PG_STATE_DATA) { 705 } else if (readstate & PG_STATE_DATA) {
710 efuse_word_enable_data_read(hworden, tmpdata, data); 706 efuse_word_enable_data_read(0, tmpdata, data);
711 efuse_addr = efuse_addr + (word_cnts * 2) + 1; 707 efuse_addr = efuse_addr + (word_cnts * 2) + 1;
712 readstate = PG_STATE_HEADER; 708 readstate = PG_STATE_HEADER;
713 } 709 }
@@ -725,13 +721,13 @@ static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset, u8 *data)
725} 721}
726 722
727static void efuse_write_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr, 723static void efuse_write_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr,
728 u8 efuse_data, u8 offset, int *bcontinual, 724 u8 efuse_data, u8 offset, int *continual,
729 u8 *write_state, struct pgpkt_struct *target_pkt, 725 u8 *write_state, struct pgpkt_struct *target_pkt,
730 int *repeat_times, int *bresult, u8 word_en) 726 int *repeat_times, int *result, u8 word_en)
731{ 727{
732 struct rtl_priv *rtlpriv = rtl_priv(hw); 728 struct rtl_priv *rtlpriv = rtl_priv(hw);
733 struct pgpkt_struct tmp_pkt; 729 struct pgpkt_struct tmp_pkt;
734 int bdataempty = true; 730 bool dataempty = true;
735 u8 originaldata[8 * sizeof(u8)]; 731 u8 originaldata[8 * sizeof(u8)];
736 u8 badworden = 0x0F; 732 u8 badworden = 0x0F;
737 u8 match_word_en, tmp_word_en; 733 u8 match_word_en, tmp_word_en;
@@ -751,10 +747,10 @@ static void efuse_write_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr,
751 u16 address = *efuse_addr + 1 + tmpindex; 747 u16 address = *efuse_addr + 1 + tmpindex;
752 if (efuse_one_byte_read(hw, address, 748 if (efuse_one_byte_read(hw, address,
753 &efuse_data) && (efuse_data != 0xFF)) 749 &efuse_data) && (efuse_data != 0xFF))
754 bdataempty = false; 750 dataempty = false;
755 } 751 }
756 752
757 if (bdataempty == false) { 753 if (dataempty == false) {
758 *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) + 1; 754 *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) + 1;
759 *write_state = PG_STATE_HEADER; 755 *write_state = PG_STATE_HEADER;
760 } else { 756 } else {
@@ -811,12 +807,12 @@ static void efuse_write_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr,
811 target_pkt->offset = offset; 807 target_pkt->offset = offset;
812 target_pkt->word_en = tmp_word_en; 808 target_pkt->word_en = tmp_word_en;
813 } else 809 } else
814 *bcontinual = false; 810 *continual = false;
815 *write_state = PG_STATE_HEADER; 811 *write_state = PG_STATE_HEADER;
816 *repeat_times += 1; 812 *repeat_times += 1;
817 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) { 813 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) {
818 *bcontinual = false; 814 *continual = false;
819 *bresult = false; 815 *result = false;
820 } 816 }
821 } else { 817 } else {
822 *efuse_addr += (2 * tmp_word_cnts) + 1; 818 *efuse_addr += (2 * tmp_word_cnts) + 1;
@@ -830,9 +826,9 @@ static void efuse_write_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr,
830} 826}
831 827
832static void efuse_write_data_case2(struct ieee80211_hw *hw, u16 *efuse_addr, 828static void efuse_write_data_case2(struct ieee80211_hw *hw, u16 *efuse_addr,
833 int *bcontinual, u8 *write_state, 829 int *continual, u8 *write_state,
834 struct pgpkt_struct target_pkt, 830 struct pgpkt_struct target_pkt,
835 int *repeat_times, int *bresult) 831 int *repeat_times, int *result)
836{ 832{
837 struct rtl_priv *rtlpriv = rtl_priv(hw); 833 struct rtl_priv *rtlpriv = rtl_priv(hw);
838 struct pgpkt_struct tmp_pkt; 834 struct pgpkt_struct tmp_pkt;
@@ -852,8 +848,8 @@ static void efuse_write_data_case2(struct ieee80211_hw *hw, u16 *efuse_addr,
852 *write_state = PG_STATE_HEADER; 848 *write_state = PG_STATE_HEADER;
853 *repeat_times += 1; 849 *repeat_times += 1;
854 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) { 850 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) {
855 *bcontinual = false; 851 *continual = false;
856 *bresult = false; 852 *result = false;
857 } 853 }
858 } else { 854 } else {
859 tmp_pkt.offset = (tmp_header >> 4) & 0x0F; 855 tmp_pkt.offset = (tmp_header >> 4) & 0x0F;
@@ -884,8 +880,8 @@ static void efuse_write_data_case2(struct ieee80211_hw *hw, u16 *efuse_addr,
884 *write_state = PG_STATE_HEADER; 880 *write_state = PG_STATE_HEADER;
885 *repeat_times += 1; 881 *repeat_times += 1;
886 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) { 882 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) {
887 *bcontinual = false; 883 *continual = false;
888 *bresult = false; 884 *result = false;
889 } 885 }
890 886
891 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, 887 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
@@ -899,7 +895,7 @@ static int efuse_pg_packet_write(struct ieee80211_hw *hw,
899 struct rtl_priv *rtlpriv = rtl_priv(hw); 895 struct rtl_priv *rtlpriv = rtl_priv(hw);
900 struct pgpkt_struct target_pkt; 896 struct pgpkt_struct target_pkt;
901 u8 write_state = PG_STATE_HEADER; 897 u8 write_state = PG_STATE_HEADER;
902 int bcontinual = true, bdataempty = true, bresult = true; 898 int continual = true, dataempty = true, result = true;
903 u16 efuse_addr = 0; 899 u16 efuse_addr = 0;
904 u8 efuse_data; 900 u8 efuse_data;
905 u8 target_word_cnts = 0; 901 u8 target_word_cnts = 0;
@@ -923,11 +919,11 @@ static int efuse_pg_packet_write(struct ieee80211_hw *hw,
923 919
924 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, ("efuse Power ON\n")); 920 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, ("efuse Power ON\n"));
925 921
926 while (bcontinual && (efuse_addr < 922 while (continual && (efuse_addr <
927 (EFUSE_MAX_SIZE - EFUSE_OOB_PROTECT_BYTES))) { 923 (EFUSE_MAX_SIZE - EFUSE_OOB_PROTECT_BYTES))) {
928 924
929 if (write_state == PG_STATE_HEADER) { 925 if (write_state == PG_STATE_HEADER) {
930 bdataempty = true; 926 dataempty = true;
931 badworden = 0x0F; 927 badworden = 0x0F;
932 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, 928 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
933 ("efuse PG_STATE_HEADER\n")); 929 ("efuse PG_STATE_HEADER\n"));
@@ -936,32 +932,30 @@ static int efuse_pg_packet_write(struct ieee80211_hw *hw,
936 (efuse_data != 0xFF)) 932 (efuse_data != 0xFF))
937 efuse_write_data_case1(hw, &efuse_addr, 933 efuse_write_data_case1(hw, &efuse_addr,
938 efuse_data, offset, 934 efuse_data, offset,
939 &bcontinual, 935 &continual,
940 &write_state, &target_pkt, 936 &write_state, &target_pkt,
941 &repeat_times, &bresult, 937 &repeat_times, &result,
942 word_en); 938 word_en);
943 else 939 else
944 efuse_write_data_case2(hw, &efuse_addr, 940 efuse_write_data_case2(hw, &efuse_addr,
945 &bcontinual, 941 &continual,
946 &write_state, 942 &write_state,
947 target_pkt, 943 target_pkt,
948 &repeat_times, 944 &repeat_times,
949 &bresult); 945 &result);
950 946
951 } else if (write_state == PG_STATE_DATA) { 947 } else if (write_state == PG_STATE_DATA) {
952 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, 948 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
953 ("efuse PG_STATE_DATA\n")); 949 ("efuse PG_STATE_DATA\n"));
954 badworden = 0x0f;
955 badworden = 950 badworden =
956 efuse_word_enable_data_write(hw, efuse_addr + 1, 951 efuse_word_enable_data_write(hw, efuse_addr + 1,
957 target_pkt.word_en, 952 target_pkt.word_en,
958 target_pkt.data); 953 target_pkt.data);
959 954
960 if ((badworden & 0x0F) == 0x0F) { 955 if ((badworden & 0x0F) == 0x0F) {
961 bcontinual = false; 956 continual = false;
962 } else { 957 } else {
963 efuse_addr = 958 efuse_addr += (2 * target_word_cnts) + 1;
964 efuse_addr + (2 * target_word_cnts) + 1;
965 959
966 target_pkt.offset = offset; 960 target_pkt.offset = offset;
967 target_pkt.word_en = badworden; 961 target_pkt.word_en = badworden;
@@ -971,8 +965,8 @@ static int efuse_pg_packet_write(struct ieee80211_hw *hw,
971 write_state = PG_STATE_HEADER; 965 write_state = PG_STATE_HEADER;
972 repeat_times++; 966 repeat_times++;
973 if (repeat_times > EFUSE_REPEAT_THRESHOLD_) { 967 if (repeat_times > EFUSE_REPEAT_THRESHOLD_) {
974 bcontinual = false; 968 continual = false;
975 bresult = false; 969 result = false;
976 } 970 }
977 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG, 971 RTPRINT(rtlpriv, FEEPROM, EFUSE_PG,
978 ("efuse PG_STATE_HEADER-3\n")); 972 ("efuse PG_STATE_HEADER-3\n"));
@@ -1072,13 +1066,13 @@ static u8 efuse_word_enable_data_write(struct ieee80211_hw *hw,
1072 return badworden; 1066 return badworden;
1073} 1067}
1074 1068
1075static void efuse_power_switch(struct ieee80211_hw *hw, u8 bwrite, u8 pwrstate) 1069static void efuse_power_switch(struct ieee80211_hw *hw, u8 write, u8 pwrstate)
1076{ 1070{
1077 struct rtl_priv *rtlpriv = rtl_priv(hw); 1071 struct rtl_priv *rtlpriv = rtl_priv(hw);
1078 u8 tempval; 1072 u8 tempval;
1079 u16 tmpV16; 1073 u16 tmpV16;
1080 1074
1081 if (pwrstate == true) { 1075 if (pwrstate) {
1082 tmpV16 = rtl_read_word(rtlpriv, 1076 tmpV16 = rtl_read_word(rtlpriv,
1083 rtlpriv->cfg->maps[SYS_ISO_CTRL]); 1077 rtlpriv->cfg->maps[SYS_ISO_CTRL]);
1084 if (!(tmpV16 & rtlpriv->cfg->maps[EFUSE_PWC_EV12V])) { 1078 if (!(tmpV16 & rtlpriv->cfg->maps[EFUSE_PWC_EV12V])) {
@@ -1106,8 +1100,8 @@ static void efuse_power_switch(struct ieee80211_hw *hw, u8 bwrite, u8 pwrstate)
1106 } 1100 }
1107 } 1101 }
1108 1102
1109 if (pwrstate == true) { 1103 if (pwrstate) {
1110 if (bwrite == true) { 1104 if (write) {
1111 tempval = rtl_read_byte(rtlpriv, 1105 tempval = rtl_read_byte(rtlpriv,
1112 rtlpriv->cfg->maps[EFUSE_TEST] + 1106 rtlpriv->cfg->maps[EFUSE_TEST] +
1113 3); 1107 3);
@@ -1119,7 +1113,7 @@ static void efuse_power_switch(struct ieee80211_hw *hw, u8 bwrite, u8 pwrstate)
1119 } 1113 }
1120 1114
1121 } else { 1115 } else {
1122 if (bwrite == true) { 1116 if (write) {
1123 tempval = rtl_read_byte(rtlpriv, 1117 tempval = rtl_read_byte(rtlpriv,
1124 rtlpriv->cfg->maps[EFUSE_TEST] + 1118 rtlpriv->cfg->maps[EFUSE_TEST] +
1125 3); 1119 3);
@@ -1134,12 +1128,12 @@ static void efuse_power_switch(struct ieee80211_hw *hw, u8 bwrite, u8 pwrstate)
1134 1128
1135static u16 efuse_get_current_size(struct ieee80211_hw *hw) 1129static u16 efuse_get_current_size(struct ieee80211_hw *hw)
1136{ 1130{
1137 int bcontinual = true; 1131 int continual = true;
1138 u16 efuse_addr = 0; 1132 u16 efuse_addr = 0;
1139 u8 hoffset, hworden; 1133 u8 hoffset, hworden;
1140 u8 efuse_data, word_cnts; 1134 u8 efuse_data, word_cnts;
1141 1135
1142 while (bcontinual && efuse_one_byte_read(hw, efuse_addr, &efuse_data) 1136 while (continual && efuse_one_byte_read(hw, efuse_addr, &efuse_data)
1143 && (efuse_addr < EFUSE_MAX_SIZE)) { 1137 && (efuse_addr < EFUSE_MAX_SIZE)) {
1144 if (efuse_data != 0xFF) { 1138 if (efuse_data != 0xFF) {
1145 hoffset = (efuse_data >> 4) & 0x0F; 1139 hoffset = (efuse_data >> 4) & 0x0F;
@@ -1147,7 +1141,7 @@ static u16 efuse_get_current_size(struct ieee80211_hw *hw)
1147 word_cnts = efuse_calculate_word_cnts(hworden); 1141 word_cnts = efuse_calculate_word_cnts(hworden);
1148 efuse_addr = efuse_addr + (word_cnts * 2) + 1; 1142 efuse_addr = efuse_addr + (word_cnts * 2) + 1;
1149 } else { 1143 } else {
1150 bcontinual = false; 1144 continual = false;
1151 } 1145 }
1152 } 1146 }
1153 1147