1 /******************************************************************************
3 * Copyright(c) 2009-2012 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
28 #include <linux/export.h>
30 static const u8 MAX_PGPKT_SIZE
= 9;
31 static const u8 PGPKT_DATA_SIZE
= 8;
32 static const int EFUSE_MAX_SIZE
= 512;
34 #define START_ADDRESS 0x1000
35 #define REG_MCUFWDL 0x0080
37 static const struct efuse_map RTL8712_SDIO_EFUSE_TABLE
[] = {
53 static void efuse_shadow_read_1byte(struct ieee80211_hw
*hw
, u16 offset
,
55 static void efuse_shadow_read_2byte(struct ieee80211_hw
*hw
, u16 offset
,
57 static void efuse_shadow_read_4byte(struct ieee80211_hw
*hw
, u16 offset
,
59 static void efuse_shadow_write_1byte(struct ieee80211_hw
*hw
, u16 offset
,
61 static void efuse_shadow_write_2byte(struct ieee80211_hw
*hw
, u16 offset
,
63 static void efuse_shadow_write_4byte(struct ieee80211_hw
*hw
, u16 offset
,
65 static int efuse_one_byte_write(struct ieee80211_hw
*hw
, u16 addr
,
67 static void efuse_read_all_map(struct ieee80211_hw
*hw
, u8
*efuse
);
68 static int efuse_pg_packet_read(struct ieee80211_hw
*hw
, u8 offset
,
70 static int efuse_pg_packet_write(struct ieee80211_hw
*hw
, u8 offset
,
71 u8 word_en
, u8
*data
);
72 static void efuse_word_enable_data_read(u8 word_en
, u8
*sourdata
,
74 static u8
enable_efuse_data_write(struct ieee80211_hw
*hw
,
75 u16 efuse_addr
, u8 word_en
, u8
*data
);
76 static u16
efuse_get_current_size(struct ieee80211_hw
*hw
);
77 static u8
efuse_calculate_word_cnts(u8 word_en
);
79 void efuse_initialize(struct ieee80211_hw
*hw
)
81 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
85 bytetemp
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_FUNC_EN
] + 1);
86 temp
= bytetemp
| 0x20;
87 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_FUNC_EN
] + 1, temp
);
89 bytetemp
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
] + 1);
90 temp
= bytetemp
& 0xFE;
91 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
] + 1, temp
);
93 bytetemp
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3);
94 temp
= bytetemp
| 0x80;
95 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3, temp
);
97 rtl_write_byte(rtlpriv
, 0x2F8, 0x3);
99 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, 0x72);
102 u8
efuse_read_1byte(struct ieee80211_hw
*hw
, u16 address
)
104 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
109 const u32 efuse_len
=
110 rtlpriv
->cfg
->maps
[EFUSE_REAL_CONTENT_SIZE
];
112 if (address
< efuse_len
) {
113 temp
= address
& 0xFF;
114 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1,
116 bytetemp
= rtl_read_byte(rtlpriv
,
117 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2);
118 temp
= ((address
>> 8) & 0x03) | (bytetemp
& 0xFC);
119 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
122 bytetemp
= rtl_read_byte(rtlpriv
,
123 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
124 temp
= bytetemp
& 0x7F;
125 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3,
128 bytetemp
= rtl_read_byte(rtlpriv
,
129 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
130 while (!(bytetemp
& 0x80)) {
132 rtl_read_byte(rtlpriv
,
133 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
140 data
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
146 void efuse_write_1byte(struct ieee80211_hw
*hw
, u16 address
, u8 value
)
148 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
152 const u32 efuse_len
=
153 rtlpriv
->cfg
->maps
[EFUSE_REAL_CONTENT_SIZE
];
155 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
, "Addr=%x Data =%x\n",
158 if (address
< efuse_len
) {
159 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
], value
);
161 temp
= address
& 0xFF;
162 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1,
164 bytetemp
= rtl_read_byte(rtlpriv
,
165 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2);
167 temp
= ((address
>> 8) & 0x03) | (bytetemp
& 0xFC);
168 rtl_write_byte(rtlpriv
,
169 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2, temp
);
171 bytetemp
= rtl_read_byte(rtlpriv
,
172 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
173 temp
= bytetemp
| 0x80;
174 rtl_write_byte(rtlpriv
,
175 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, temp
);
177 bytetemp
= rtl_read_byte(rtlpriv
,
178 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
180 while (bytetemp
& 0x80) {
182 rtl_read_byte(rtlpriv
,
183 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
193 void read_efuse_byte(struct ieee80211_hw
*hw
, u16 _offset
, u8
*pbuf
)
195 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
200 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1,
202 readbyte
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2);
203 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
204 ((_offset
>> 8) & 0x03) | (readbyte
& 0xfc));
206 readbyte
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
207 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3,
211 value32
= rtl_read_dword(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
212 while (!(((value32
>> 24) & 0xff) & 0x80) && (retry
< 10000)) {
213 value32
= rtl_read_dword(rtlpriv
,
214 rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
219 value32
= rtl_read_dword(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
221 *pbuf
= (u8
)(value32
& 0xff);
224 void read_efuse(struct ieee80211_hw
*hw
, u16 _offset
, u16 _size_byte
, u8
*pbuf
)
226 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
227 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
235 const u16 efuse_max_section
=
236 rtlpriv
->cfg
->maps
[EFUSE_MAX_SECTION_MAP
];
237 const u32 efuse_len
=
238 rtlpriv
->cfg
->maps
[EFUSE_REAL_CONTENT_SIZE
];
240 u16 efuse_utilized
= 0;
243 if ((_offset
+ _size_byte
) > rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]) {
244 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
245 "%s(): Invalid offset(%#x) with read bytes(%#x)!!\n",
246 __func__
, _offset
, _size_byte
);
250 /* allocate memory for efuse_tbl and efuse_word */
251 efuse_tbl
= kzalloc(rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
] *
252 sizeof(u8
), GFP_ATOMIC
);
255 efuse_word
= kcalloc(EFUSE_MAX_WORD_UNIT
, sizeof(u16
*), GFP_ATOMIC
);
258 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++) {
259 efuse_word
[i
] = kcalloc(efuse_max_section
, sizeof(u16
), GFP_ATOMIC
);
264 for (i
= 0; i
< efuse_max_section
; i
++)
265 for (j
= 0; j
< EFUSE_MAX_WORD_UNIT
; j
++)
266 efuse_word
[j
][i
] = 0xFFFF;
268 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
269 if (*rtemp8
!= 0xFF) {
271 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_READ_ALL
,
272 "Addr=%d\n", efuse_addr
);
276 while ((*rtemp8
!= 0xFF) && (efuse_addr
< efuse_len
)) {
277 /* Check PG header for section num. */
278 if ((*rtemp8
& 0x1F) == 0x0F) {/* extended header */
279 u1temp
= ((*rtemp8
& 0xE0) >> 5);
280 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
282 if ((*rtemp8
& 0x0F) == 0x0F) {
284 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
286 if (*rtemp8
!= 0xFF &&
287 (efuse_addr
< efuse_len
)) {
292 offset
= ((*rtemp8
& 0xF0) >> 1) | u1temp
;
293 wren
= (*rtemp8
& 0x0F);
297 offset
= ((*rtemp8
>> 4) & 0x0f);
298 wren
= (*rtemp8
& 0x0f);
301 if (offset
< efuse_max_section
) {
302 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_READ_ALL
,
303 "offset-%d Worden=%x\n", offset
, wren
);
305 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++) {
306 if (!(wren
& 0x01)) {
307 RTPRINT(rtlpriv
, FEEPROM
,
309 "Addr=%d\n", efuse_addr
);
311 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
314 efuse_word
[i
][offset
] =
317 if (efuse_addr
>= efuse_len
)
320 RTPRINT(rtlpriv
, FEEPROM
,
322 "Addr=%d\n", efuse_addr
);
324 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
327 efuse_word
[i
][offset
] |=
328 (((u16
)*rtemp8
<< 8) & 0xff00);
330 if (efuse_addr
>= efuse_len
)
338 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_READ_ALL
,
339 "Addr=%d\n", efuse_addr
);
340 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
341 if (*rtemp8
!= 0xFF && (efuse_addr
< efuse_len
)) {
347 for (i
= 0; i
< efuse_max_section
; i
++) {
348 for (j
= 0; j
< EFUSE_MAX_WORD_UNIT
; j
++) {
349 efuse_tbl
[(i
* 8) + (j
* 2)] =
350 (efuse_word
[j
][i
] & 0xff);
351 efuse_tbl
[(i
* 8) + ((j
* 2) + 1)] =
352 ((efuse_word
[j
][i
] >> 8) & 0xff);
356 for (i
= 0; i
< _size_byte
; i
++)
357 pbuf
[i
] = efuse_tbl
[_offset
+ i
];
359 rtlefuse
->efuse_usedbytes
= efuse_utilized
;
360 efuse_usage
= (u8
)((efuse_utilized
* 100) / efuse_len
);
361 rtlefuse
->efuse_usedpercentage
= efuse_usage
;
362 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_EFUSE_BYTES
,
363 (u8
*)&efuse_utilized
);
364 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_EFUSE_USAGE
,
367 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++)
368 kfree(efuse_word
[i
]);
374 bool efuse_shadow_update_chk(struct ieee80211_hw
*hw
)
376 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
377 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
378 u8 section_idx
, i
, base
;
379 u16 words_need
= 0, hdr_num
= 0, totalbytes
, efuse_used
;
380 bool wordchanged
, result
= true;
382 for (section_idx
= 0; section_idx
< 16; section_idx
++) {
383 base
= section_idx
* 8;
386 for (i
= 0; i
< 8; i
= i
+ 2) {
387 if ((rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] !=
388 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
]) ||
389 (rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
+ 1] !=
390 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
+
401 totalbytes
= hdr_num
+ words_need
* 2;
402 efuse_used
= rtlefuse
->efuse_usedbytes
;
404 if ((totalbytes
+ efuse_used
) >=
405 (EFUSE_MAX_SIZE
- rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
]))
408 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
409 "%s(): totalbytes(%#x), hdr_num(%#x), words_need(%#x), efuse_used(%d)\n",
410 __func__
, totalbytes
, hdr_num
, words_need
, efuse_used
);
415 void efuse_shadow_read(struct ieee80211_hw
*hw
, u8 type
,
416 u16 offset
, u32
*value
)
419 efuse_shadow_read_1byte(hw
, offset
, (u8
*)value
);
421 efuse_shadow_read_2byte(hw
, offset
, (u16
*)value
);
423 efuse_shadow_read_4byte(hw
, offset
, value
);
426 void efuse_shadow_write(struct ieee80211_hw
*hw
, u8 type
, u16 offset
,
430 efuse_shadow_write_1byte(hw
, offset
, (u8
)value
);
432 efuse_shadow_write_2byte(hw
, offset
, (u16
)value
);
434 efuse_shadow_write_4byte(hw
, offset
, value
);
437 bool efuse_shadow_update(struct ieee80211_hw
*hw
)
439 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
440 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
445 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
, "\n");
447 if (!efuse_shadow_update_chk(hw
)) {
448 efuse_read_all_map(hw
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]);
449 memcpy(&rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][0],
450 &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
451 rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
453 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
454 "efuse out of capacity!!\n");
457 efuse_power_switch(hw
, true, true);
459 for (offset
= 0; offset
< 16; offset
++) {
463 for (i
= 0; i
< 8; i
++) {
465 word_en
&= ~(BIT(i
/ 2));
467 rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] =
468 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
];
470 if (rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] !=
471 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
]) {
472 word_en
&= ~(BIT(i
/ 2));
474 rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] =
475 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
];
479 if (word_en
!= 0x0F) {
483 &rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
],
485 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_LOUD
,
486 "U-efuse\n", tmpdata
, 8);
488 if (!efuse_pg_packet_write(hw
, (u8
)offset
, word_en
,
490 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
491 "PG section(%#x) fail!!\n", offset
);
497 efuse_power_switch(hw
, true, false);
498 efuse_read_all_map(hw
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]);
500 memcpy(&rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][0],
501 &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
502 rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
504 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
, "\n");
508 void rtl_efuse_shadow_map_update(struct ieee80211_hw
*hw
)
510 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
511 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
513 if (rtlefuse
->autoload_failflag
)
514 memset((&rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]),
515 0xFF, rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
517 efuse_read_all_map(hw
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]);
519 memcpy(&rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][0],
520 &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
521 rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
524 void efuse_force_write_vendor_id(struct ieee80211_hw
*hw
)
526 u8 tmpdata
[8] = { 0xFF, 0xFF, 0xEC, 0x10, 0xFF, 0xFF, 0xFF, 0xFF };
528 efuse_power_switch(hw
, true, true);
530 efuse_pg_packet_write(hw
, 1, 0xD, tmpdata
);
532 efuse_power_switch(hw
, true, false);
535 void efuse_re_pg_section(struct ieee80211_hw
*hw
, u8 section_idx
)
539 static void efuse_shadow_read_1byte(struct ieee80211_hw
*hw
,
540 u16 offset
, u8
*value
)
542 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
543 *value
= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
];
546 static void efuse_shadow_read_2byte(struct ieee80211_hw
*hw
,
547 u16 offset
, u16
*value
)
549 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
551 *value
= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
];
552 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] << 8;
555 static void efuse_shadow_read_4byte(struct ieee80211_hw
*hw
,
556 u16 offset
, u32
*value
)
558 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
560 *value
= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
];
561 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] << 8;
562 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 2] << 16;
563 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 3] << 24;
566 static void efuse_shadow_write_1byte(struct ieee80211_hw
*hw
,
567 u16 offset
, u8 value
)
569 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
571 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
] = value
;
574 static void efuse_shadow_write_2byte(struct ieee80211_hw
*hw
,
575 u16 offset
, u16 value
)
577 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
579 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
] = value
& 0x00FF;
580 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] = value
>> 8;
583 static void efuse_shadow_write_4byte(struct ieee80211_hw
*hw
,
584 u16 offset
, u32 value
)
586 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
588 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
] =
589 (u8
)(value
& 0x000000FF);
590 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] =
591 (u8
)((value
>> 8) & 0x0000FF);
592 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 2] =
593 (u8
)((value
>> 16) & 0x00FF);
594 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 3] =
595 (u8
)((value
>> 24) & 0xFF);
598 int efuse_one_byte_read(struct ieee80211_hw
*hw
, u16 addr
, u8
*data
)
600 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
604 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1,
606 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
607 ((u8
)((addr
>> 8) & 0x03)) |
608 (rtl_read_byte(rtlpriv
,
609 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2) &
612 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, 0x72);
614 while (!(0x80 & rtl_read_byte(rtlpriv
,
615 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3)) &&
621 *data
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
630 static int efuse_one_byte_write(struct ieee80211_hw
*hw
, u16 addr
, u8 data
)
632 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
635 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
636 "Addr = %x Data=%x\n", addr
, data
);
638 rtl_write_byte(rtlpriv
,
639 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1, (u8
)(addr
& 0xff));
640 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
641 (rtl_read_byte(rtlpriv
,
642 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] +
643 2) & 0xFC) | (u8
)((addr
>> 8) & 0x03));
645 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
], data
);
646 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, 0xF2);
649 rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3)) &&
659 static void efuse_read_all_map(struct ieee80211_hw
*hw
, u8
*efuse
)
661 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
663 efuse_power_switch(hw
, false, true);
664 read_efuse(hw
, 0, rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
], efuse
);
665 efuse_power_switch(hw
, false, false);
668 static void efuse_read_data_case1(struct ieee80211_hw
*hw
, u16
*efuse_addr
,
669 u8 efuse_data
, u8 offset
, u8
*tmpdata
,
672 bool dataempty
= true;
678 hoffset
= (efuse_data
>> 4) & 0x0F;
679 hworden
= efuse_data
& 0x0F;
680 word_cnts
= efuse_calculate_word_cnts(hworden
);
682 if (hoffset
== offset
) {
683 for (tmpidx
= 0; tmpidx
< word_cnts
* 2; tmpidx
++) {
684 if (efuse_one_byte_read(hw
, *efuse_addr
+ 1 + tmpidx
,
686 tmpdata
[tmpidx
] = efuse_data
;
687 if (efuse_data
!= 0xff)
693 *readstate
= PG_STATE_DATA
;
695 *efuse_addr
= *efuse_addr
+ (word_cnts
* 2) + 1;
696 *readstate
= PG_STATE_HEADER
;
700 *efuse_addr
= *efuse_addr
+ (word_cnts
* 2) + 1;
701 *readstate
= PG_STATE_HEADER
;
705 static int efuse_pg_packet_read(struct ieee80211_hw
*hw
, u8 offset
, u8
*data
)
707 u8 readstate
= PG_STATE_HEADER
;
709 bool continual
= true;
711 u8 efuse_data
, word_cnts
= 0;
720 memset(data
, 0xff, PGPKT_DATA_SIZE
* sizeof(u8
));
721 memset(tmpdata
, 0xff, PGPKT_DATA_SIZE
* sizeof(u8
));
723 while (continual
&& (efuse_addr
< EFUSE_MAX_SIZE
)) {
724 if (readstate
& PG_STATE_HEADER
) {
725 if (efuse_one_byte_read(hw
, efuse_addr
, &efuse_data
) &&
726 (efuse_data
!= 0xFF))
727 efuse_read_data_case1(hw
, &efuse_addr
,
729 tmpdata
, &readstate
);
732 } else if (readstate
& PG_STATE_DATA
) {
733 efuse_word_enable_data_read(0, tmpdata
, data
);
734 efuse_addr
= efuse_addr
+ (word_cnts
* 2) + 1;
735 readstate
= PG_STATE_HEADER
;
739 if ((data
[0] == 0xff) && (data
[1] == 0xff) &&
740 (data
[2] == 0xff) && (data
[3] == 0xff) &&
741 (data
[4] == 0xff) && (data
[5] == 0xff) &&
742 (data
[6] == 0xff) && (data
[7] == 0xff))
747 static void efuse_write_data_case1(struct ieee80211_hw
*hw
, u16
*efuse_addr
,
748 u8 efuse_data
, u8 offset
,
749 int *continual
, u8
*write_state
,
750 struct pgpkt_struct
*target_pkt
,
751 int *repeat_times
, int *result
, u8 word_en
)
753 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
754 struct pgpkt_struct tmp_pkt
;
755 int dataempty
= true;
756 u8 originaldata
[8 * sizeof(u8
)];
758 u8 match_word_en
, tmp_word_en
;
760 u8 tmp_header
= efuse_data
;
763 tmp_pkt
.offset
= (tmp_header
>> 4) & 0x0F;
764 tmp_pkt
.word_en
= tmp_header
& 0x0F;
765 tmp_word_cnts
= efuse_calculate_word_cnts(tmp_pkt
.word_en
);
767 if (tmp_pkt
.offset
!= target_pkt
->offset
) {
768 *efuse_addr
= *efuse_addr
+ (tmp_word_cnts
* 2) + 1;
769 *write_state
= PG_STATE_HEADER
;
771 for (tmpindex
= 0; tmpindex
< (tmp_word_cnts
* 2); tmpindex
++) {
772 if (efuse_one_byte_read(hw
,
773 (*efuse_addr
+ 1 + tmpindex
),
775 (efuse_data
!= 0xFF))
780 *efuse_addr
= *efuse_addr
+ (tmp_word_cnts
* 2) + 1;
781 *write_state
= PG_STATE_HEADER
;
783 match_word_en
= 0x0F;
784 if (!((target_pkt
->word_en
& BIT(0)) |
785 (tmp_pkt
.word_en
& BIT(0))))
786 match_word_en
&= (~BIT(0));
788 if (!((target_pkt
->word_en
& BIT(1)) |
789 (tmp_pkt
.word_en
& BIT(1))))
790 match_word_en
&= (~BIT(1));
792 if (!((target_pkt
->word_en
& BIT(2)) |
793 (tmp_pkt
.word_en
& BIT(2))))
794 match_word_en
&= (~BIT(2));
796 if (!((target_pkt
->word_en
& BIT(3)) |
797 (tmp_pkt
.word_en
& BIT(3))))
798 match_word_en
&= (~BIT(3));
800 if ((match_word_en
& 0x0F) != 0x0F) {
802 enable_efuse_data_write(hw
,
807 if (0x0F != (badworden
& 0x0F)) {
808 u8 reorg_offset
= offset
;
809 u8 reorg_worden
= badworden
;
811 efuse_pg_packet_write(hw
, reorg_offset
,
817 if ((target_pkt
->word_en
& BIT(0)) ^
818 (match_word_en
& BIT(0)))
819 tmp_word_en
&= (~BIT(0));
821 if ((target_pkt
->word_en
& BIT(1)) ^
822 (match_word_en
& BIT(1)))
823 tmp_word_en
&= (~BIT(1));
825 if ((target_pkt
->word_en
& BIT(2)) ^
826 (match_word_en
& BIT(2)))
827 tmp_word_en
&= (~BIT(2));
829 if ((target_pkt
->word_en
& BIT(3)) ^
830 (match_word_en
& BIT(3)))
831 tmp_word_en
&= (~BIT(3));
833 if ((tmp_word_en
& 0x0F) != 0x0F) {
835 efuse_get_current_size(hw
);
836 target_pkt
->offset
= offset
;
837 target_pkt
->word_en
= tmp_word_en
;
841 *write_state
= PG_STATE_HEADER
;
843 if (*repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
848 *efuse_addr
+= (2 * tmp_word_cnts
) + 1;
849 target_pkt
->offset
= offset
;
850 target_pkt
->word_en
= word_en
;
851 *write_state
= PG_STATE_HEADER
;
855 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
, "efuse PG_STATE_HEADER-1\n");
858 static void efuse_write_data_case2(struct ieee80211_hw
*hw
, u16
*efuse_addr
,
859 int *continual
, u8
*write_state
,
860 struct pgpkt_struct target_pkt
,
861 int *repeat_times
, int *result
)
863 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
864 struct pgpkt_struct tmp_pkt
;
867 u8 originaldata
[8 * sizeof(u8
)];
871 pg_header
= ((target_pkt
.offset
<< 4) & 0xf0) | target_pkt
.word_en
;
872 efuse_one_byte_write(hw
, *efuse_addr
, pg_header
);
873 efuse_one_byte_read(hw
, *efuse_addr
, &tmp_header
);
875 if (tmp_header
== pg_header
) {
876 *write_state
= PG_STATE_DATA
;
877 } else if (tmp_header
== 0xFF) {
878 *write_state
= PG_STATE_HEADER
;
880 if (*repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
885 tmp_pkt
.offset
= (tmp_header
>> 4) & 0x0F;
886 tmp_pkt
.word_en
= tmp_header
& 0x0F;
888 tmp_word_cnts
= efuse_calculate_word_cnts(tmp_pkt
.word_en
);
890 memset(originaldata
, 0xff, 8 * sizeof(u8
));
892 if (efuse_pg_packet_read(hw
, tmp_pkt
.offset
, originaldata
)) {
893 badworden
= enable_efuse_data_write(hw
,
898 if (0x0F != (badworden
& 0x0F)) {
899 u8 reorg_offset
= tmp_pkt
.offset
;
900 u8 reorg_worden
= badworden
;
902 efuse_pg_packet_write(hw
, reorg_offset
,
905 *efuse_addr
= efuse_get_current_size(hw
);
907 *efuse_addr
= *efuse_addr
+
908 (tmp_word_cnts
* 2) + 1;
911 *efuse_addr
= *efuse_addr
+ (tmp_word_cnts
* 2) + 1;
914 *write_state
= PG_STATE_HEADER
;
916 if (*repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
921 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
922 "efuse PG_STATE_HEADER-2\n");
926 static int efuse_pg_packet_write(struct ieee80211_hw
*hw
,
927 u8 offset
, u8 word_en
, u8
*data
)
929 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
930 struct pgpkt_struct target_pkt
;
931 u8 write_state
= PG_STATE_HEADER
;
932 int continual
= true, dataempty
= true, result
= true;
935 u8 target_word_cnts
= 0;
937 static int repeat_times
;
939 if (efuse_get_current_size(hw
) >= (EFUSE_MAX_SIZE
-
940 rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
])) {
941 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
942 "%s error\n", __func__
);
946 target_pkt
.offset
= offset
;
947 target_pkt
.word_en
= word_en
;
949 memset(target_pkt
.data
, 0xFF, 8 * sizeof(u8
));
951 efuse_word_enable_data_read(word_en
, data
, target_pkt
.data
);
952 target_word_cnts
= efuse_calculate_word_cnts(target_pkt
.word_en
);
954 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
, "efuse Power ON\n");
956 while (continual
&& (efuse_addr
< (EFUSE_MAX_SIZE
-
957 rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
]))) {
958 if (write_state
== PG_STATE_HEADER
) {
961 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
962 "efuse PG_STATE_HEADER\n");
964 if (efuse_one_byte_read(hw
, efuse_addr
, &efuse_data
) &&
965 (efuse_data
!= 0xFF))
966 efuse_write_data_case1(hw
, &efuse_addr
,
971 &repeat_times
, &result
,
974 efuse_write_data_case2(hw
, &efuse_addr
,
981 } else if (write_state
== PG_STATE_DATA
) {
982 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
983 "efuse PG_STATE_DATA\n");
986 enable_efuse_data_write(hw
, efuse_addr
+ 1,
990 if ((badworden
& 0x0F) == 0x0F) {
994 efuse_addr
+ (2 * target_word_cnts
) + 1;
996 target_pkt
.offset
= offset
;
997 target_pkt
.word_en
= badworden
;
999 efuse_calculate_word_cnts(target_pkt
.word_en
);
1000 write_state
= PG_STATE_HEADER
;
1002 if (repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
1006 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
1007 "efuse PG_STATE_HEADER-3\n");
1012 if (efuse_addr
>= (EFUSE_MAX_SIZE
-
1013 rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
])) {
1014 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
1015 "efuse_addr(%#x) Out of size!!\n", efuse_addr
);
1021 static void efuse_word_enable_data_read(u8 word_en
, u8
*sourdata
,
1024 if (!(word_en
& BIT(0))) {
1025 targetdata
[0] = sourdata
[0];
1026 targetdata
[1] = sourdata
[1];
1029 if (!(word_en
& BIT(1))) {
1030 targetdata
[2] = sourdata
[2];
1031 targetdata
[3] = sourdata
[3];
1034 if (!(word_en
& BIT(2))) {
1035 targetdata
[4] = sourdata
[4];
1036 targetdata
[5] = sourdata
[5];
1039 if (!(word_en
& BIT(3))) {
1040 targetdata
[6] = sourdata
[6];
1041 targetdata
[7] = sourdata
[7];
1045 static u8
enable_efuse_data_write(struct ieee80211_hw
*hw
,
1046 u16 efuse_addr
, u8 word_en
, u8
*data
)
1048 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1050 u16 start_addr
= efuse_addr
;
1051 u8 badworden
= 0x0F;
1054 memset(tmpdata
, 0xff, PGPKT_DATA_SIZE
);
1055 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
1056 "word_en = %x efuse_addr=%x\n", word_en
, efuse_addr
);
1058 if (!(word_en
& BIT(0))) {
1059 tmpaddr
= start_addr
;
1060 efuse_one_byte_write(hw
, start_addr
++, data
[0]);
1061 efuse_one_byte_write(hw
, start_addr
++, data
[1]);
1063 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[0]);
1064 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[1]);
1065 if ((data
[0] != tmpdata
[0]) || (data
[1] != tmpdata
[1]))
1066 badworden
&= (~BIT(0));
1069 if (!(word_en
& BIT(1))) {
1070 tmpaddr
= start_addr
;
1071 efuse_one_byte_write(hw
, start_addr
++, data
[2]);
1072 efuse_one_byte_write(hw
, start_addr
++, data
[3]);
1074 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[2]);
1075 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[3]);
1076 if ((data
[2] != tmpdata
[2]) || (data
[3] != tmpdata
[3]))
1077 badworden
&= (~BIT(1));
1080 if (!(word_en
& BIT(2))) {
1081 tmpaddr
= start_addr
;
1082 efuse_one_byte_write(hw
, start_addr
++, data
[4]);
1083 efuse_one_byte_write(hw
, start_addr
++, data
[5]);
1085 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[4]);
1086 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[5]);
1087 if ((data
[4] != tmpdata
[4]) || (data
[5] != tmpdata
[5]))
1088 badworden
&= (~BIT(2));
1091 if (!(word_en
& BIT(3))) {
1092 tmpaddr
= start_addr
;
1093 efuse_one_byte_write(hw
, start_addr
++, data
[6]);
1094 efuse_one_byte_write(hw
, start_addr
++, data
[7]);
1096 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[6]);
1097 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[7]);
1098 if ((data
[6] != tmpdata
[6]) || (data
[7] != tmpdata
[7]))
1099 badworden
&= (~BIT(3));
1105 void efuse_power_switch(struct ieee80211_hw
*hw
, u8 write
, u8 pwrstate
)
1107 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1108 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1112 if (pwrstate
&& (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192SE
)) {
1113 if (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192CE
&&
1114 rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192DE
) {
1115 rtl_write_byte(rtlpriv
,
1116 rtlpriv
->cfg
->maps
[EFUSE_ACCESS
], 0x69);
1119 rtl_read_word(rtlpriv
,
1120 rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
]);
1121 if (!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_PWC_EV12V
])) {
1122 tmpv16
|= rtlpriv
->cfg
->maps
[EFUSE_PWC_EV12V
];
1123 rtl_write_word(rtlpriv
,
1124 rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
],
1128 tmpv16
= rtl_read_word(rtlpriv
,
1129 rtlpriv
->cfg
->maps
[SYS_FUNC_EN
]);
1130 if (!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_FEN_ELDR
])) {
1131 tmpv16
|= rtlpriv
->cfg
->maps
[EFUSE_FEN_ELDR
];
1132 rtl_write_word(rtlpriv
,
1133 rtlpriv
->cfg
->maps
[SYS_FUNC_EN
], tmpv16
);
1136 tmpv16
= rtl_read_word(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_CLK
]);
1137 if ((!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_LOADER_CLK_EN
])) ||
1138 (!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_ANA8M
]))) {
1139 tmpv16
|= (rtlpriv
->cfg
->maps
[EFUSE_LOADER_CLK_EN
] |
1140 rtlpriv
->cfg
->maps
[EFUSE_ANA8M
]);
1141 rtl_write_word(rtlpriv
,
1142 rtlpriv
->cfg
->maps
[SYS_CLK
], tmpv16
);
1148 tempval
= rtl_read_byte(rtlpriv
,
1149 rtlpriv
->cfg
->maps
[EFUSE_TEST
] +
1152 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
1153 tempval
&= ~(BIT(3) | BIT(4) | BIT(5) | BIT(6));
1154 tempval
|= (VOLTAGE_V25
<< 3);
1155 } else if (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192SE
) {
1157 tempval
|= (VOLTAGE_V25
<< 4);
1160 rtl_write_byte(rtlpriv
,
1161 rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3,
1165 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8192SE
) {
1166 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CLK
],
1170 if (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192CE
&&
1171 rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192DE
)
1172 rtl_write_byte(rtlpriv
,
1173 rtlpriv
->cfg
->maps
[EFUSE_ACCESS
], 0);
1176 tempval
= rtl_read_byte(rtlpriv
,
1177 rtlpriv
->cfg
->maps
[EFUSE_TEST
] +
1179 rtl_write_byte(rtlpriv
,
1180 rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3,
1184 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8192SE
) {
1185 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CLK
],
1191 static u16
efuse_get_current_size(struct ieee80211_hw
*hw
)
1193 int continual
= true;
1195 u8 hoffset
, hworden
;
1196 u8 efuse_data
, word_cnts
;
1198 while (continual
&& efuse_one_byte_read(hw
, efuse_addr
, &efuse_data
) &&
1199 (efuse_addr
< EFUSE_MAX_SIZE
)) {
1200 if (efuse_data
!= 0xFF) {
1201 hoffset
= (efuse_data
>> 4) & 0x0F;
1202 hworden
= efuse_data
& 0x0F;
1203 word_cnts
= efuse_calculate_word_cnts(hworden
);
1204 efuse_addr
= efuse_addr
+ (word_cnts
* 2) + 1;
1213 static u8
efuse_calculate_word_cnts(u8 word_en
)
1217 if (!(word_en
& BIT(0)))
1219 if (!(word_en
& BIT(1)))
1221 if (!(word_en
& BIT(2)))
1223 if (!(word_en
& BIT(3)))
1228 int rtl_get_hwinfo(struct ieee80211_hw
*hw
, struct rtl_priv
*rtlpriv
,
1229 int max_size
, u8
*hwinfo
, int *params
)
1231 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1232 struct rtl_pci_priv
*rtlpcipriv
= rtl_pcipriv(hw
);
1233 struct device
*dev
= &rtlpcipriv
->dev
.pdev
->dev
;
1237 switch (rtlefuse
->epromtype
) {
1238 case EEPROM_BOOT_EFUSE
:
1239 rtl_efuse_shadow_map_update(hw
);
1243 pr_err("RTL8XXX did not boot from eeprom, check it !!\n");
1247 dev_warn(dev
, "no efuse data\n");
1251 memcpy(hwinfo
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0], max_size
);
1253 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
, "MAP",
1256 eeprom_id
= *((u16
*)&hwinfo
[0]);
1257 if (eeprom_id
!= params
[0]) {
1258 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1259 "EEPROM ID(%#x) is invalid!!\n", eeprom_id
);
1260 rtlefuse
->autoload_failflag
= true;
1262 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1263 rtlefuse
->autoload_failflag
= false;
1266 if (rtlefuse
->autoload_failflag
)
1269 rtlefuse
->eeprom_vid
= *(u16
*)&hwinfo
[params
[1]];
1270 rtlefuse
->eeprom_did
= *(u16
*)&hwinfo
[params
[2]];
1271 rtlefuse
->eeprom_svid
= *(u16
*)&hwinfo
[params
[3]];
1272 rtlefuse
->eeprom_smid
= *(u16
*)&hwinfo
[params
[4]];
1273 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1274 "EEPROMId = 0x%4x\n", eeprom_id
);
1275 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1276 "EEPROM VID = 0x%4x\n", rtlefuse
->eeprom_vid
);
1277 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1278 "EEPROM DID = 0x%4x\n", rtlefuse
->eeprom_did
);
1279 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1280 "EEPROM SVID = 0x%4x\n", rtlefuse
->eeprom_svid
);
1281 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1282 "EEPROM SMID = 0x%4x\n", rtlefuse
->eeprom_smid
);
1284 for (i
= 0; i
< 6; i
+= 2) {
1285 usvalue
= *(u16
*)&hwinfo
[params
[5] + i
];
1286 *((u16
*)(&rtlefuse
->dev_addr
[i
])) = usvalue
;
1288 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "%pM\n", rtlefuse
->dev_addr
);
1290 rtlefuse
->eeprom_channelplan
= *&hwinfo
[params
[6]];
1291 rtlefuse
->eeprom_version
= *(u16
*)&hwinfo
[params
[7]];
1292 rtlefuse
->txpwr_fromeprom
= true;
1293 rtlefuse
->eeprom_oemid
= *&hwinfo
[params
[8]];
1295 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1296 "EEPROM Customer ID: 0x%2x\n", rtlefuse
->eeprom_oemid
);
1298 /* set channel plan to world wide 13 */
1299 rtlefuse
->channel_plan
= params
[9];
1304 void rtl_fw_block_write(struct ieee80211_hw
*hw
, const u8
*buffer
, u32 size
)
1306 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1307 u8
*pu4byteptr
= (u8
*)buffer
;
1310 for (i
= 0; i
< size
; i
++)
1311 rtl_write_byte(rtlpriv
, (START_ADDRESS
+ i
), *(pu4byteptr
+ i
));
1314 void rtl_fw_page_write(struct ieee80211_hw
*hw
, u32 page
, const u8
*buffer
,
1317 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1319 u8 u8page
= (u8
)(page
& 0x07);
1321 value8
= (rtl_read_byte(rtlpriv
, REG_MCUFWDL
+ 2) & 0xF8) | u8page
;
1323 rtl_write_byte(rtlpriv
, (REG_MCUFWDL
+ 2), value8
);
1324 rtl_fw_block_write(hw
, buffer
, size
);
1327 void rtl_fill_dummy(u8
*pfwbuf
, u32
*pfwlen
)
1329 u32 fwlen
= *pfwlen
;
1330 u8 remain
= (u8
)(fwlen
% 4);
1332 remain
= (remain
== 0) ? 0 : (4 - remain
);
1334 while (remain
> 0) {