1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2009-2012 Realtek Corporation.
7 * wlanfae <wlanfae@realtek.com>
8 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
11 * Larry Finger <Larry.Finger@lwfinger.net>
13 *****************************************************************************/
17 #include <linux/export.h>
19 static const u8 MAX_PGPKT_SIZE
= 9;
20 static const u8 PGPKT_DATA_SIZE
= 8;
21 static const int EFUSE_MAX_SIZE
= 512;
23 #define START_ADDRESS 0x1000
24 #define REG_MCUFWDL 0x0080
26 static const struct efuse_map RTL8712_SDIO_EFUSE_TABLE
[] = {
42 static void efuse_shadow_read_1byte(struct ieee80211_hw
*hw
, u16 offset
,
44 static void efuse_shadow_read_2byte(struct ieee80211_hw
*hw
, u16 offset
,
46 static void efuse_shadow_read_4byte(struct ieee80211_hw
*hw
, u16 offset
,
48 static void efuse_shadow_write_1byte(struct ieee80211_hw
*hw
, u16 offset
,
50 static void efuse_shadow_write_2byte(struct ieee80211_hw
*hw
, u16 offset
,
52 static void efuse_shadow_write_4byte(struct ieee80211_hw
*hw
, u16 offset
,
54 static int efuse_one_byte_write(struct ieee80211_hw
*hw
, u16 addr
,
56 static void efuse_read_all_map(struct ieee80211_hw
*hw
, u8
*efuse
);
57 static int efuse_pg_packet_read(struct ieee80211_hw
*hw
, u8 offset
,
59 static int efuse_pg_packet_write(struct ieee80211_hw
*hw
, u8 offset
,
60 u8 word_en
, u8
*data
);
61 static void efuse_word_enable_data_read(u8 word_en
, u8
*sourdata
,
63 static u8
enable_efuse_data_write(struct ieee80211_hw
*hw
,
64 u16 efuse_addr
, u8 word_en
, u8
*data
);
65 static u16
efuse_get_current_size(struct ieee80211_hw
*hw
);
66 static u8
efuse_calculate_word_cnts(u8 word_en
);
68 void efuse_initialize(struct ieee80211_hw
*hw
)
70 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
74 bytetemp
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_FUNC_EN
] + 1);
75 temp
= bytetemp
| 0x20;
76 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_FUNC_EN
] + 1, temp
);
78 bytetemp
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
] + 1);
79 temp
= bytetemp
& 0xFE;
80 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
] + 1, temp
);
82 bytetemp
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3);
83 temp
= bytetemp
| 0x80;
84 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3, temp
);
86 rtl_write_byte(rtlpriv
, 0x2F8, 0x3);
88 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, 0x72);
91 u8
efuse_read_1byte(struct ieee80211_hw
*hw
, u16 address
)
93 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
99 rtlpriv
->cfg
->maps
[EFUSE_REAL_CONTENT_SIZE
];
101 if (address
< efuse_len
) {
102 temp
= address
& 0xFF;
103 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1,
105 bytetemp
= rtl_read_byte(rtlpriv
,
106 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2);
107 temp
= ((address
>> 8) & 0x03) | (bytetemp
& 0xFC);
108 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
111 bytetemp
= rtl_read_byte(rtlpriv
,
112 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
113 temp
= bytetemp
& 0x7F;
114 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3,
117 bytetemp
= rtl_read_byte(rtlpriv
,
118 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
119 while (!(bytetemp
& 0x80)) {
121 rtl_read_byte(rtlpriv
,
122 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
129 data
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
135 void efuse_write_1byte(struct ieee80211_hw
*hw
, u16 address
, u8 value
)
137 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
141 const u32 efuse_len
=
142 rtlpriv
->cfg
->maps
[EFUSE_REAL_CONTENT_SIZE
];
144 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
, "Addr=%x Data =%x\n",
147 if (address
< efuse_len
) {
148 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
], value
);
150 temp
= address
& 0xFF;
151 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1,
153 bytetemp
= rtl_read_byte(rtlpriv
,
154 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2);
156 temp
= ((address
>> 8) & 0x03) | (bytetemp
& 0xFC);
157 rtl_write_byte(rtlpriv
,
158 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2, temp
);
160 bytetemp
= rtl_read_byte(rtlpriv
,
161 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
162 temp
= bytetemp
| 0x80;
163 rtl_write_byte(rtlpriv
,
164 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, temp
);
166 bytetemp
= rtl_read_byte(rtlpriv
,
167 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
169 while (bytetemp
& 0x80) {
171 rtl_read_byte(rtlpriv
,
172 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
182 void read_efuse_byte(struct ieee80211_hw
*hw
, u16 _offset
, u8
*pbuf
)
184 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
189 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1,
191 readbyte
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2);
192 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
193 ((_offset
>> 8) & 0x03) | (readbyte
& 0xfc));
195 readbyte
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
196 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3,
200 value32
= rtl_read_dword(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
201 while (!(((value32
>> 24) & 0xff) & 0x80) && (retry
< 10000)) {
202 value32
= rtl_read_dword(rtlpriv
,
203 rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
208 value32
= rtl_read_dword(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
210 *pbuf
= (u8
)(value32
& 0xff);
213 void read_efuse(struct ieee80211_hw
*hw
, u16 _offset
, u16 _size_byte
, u8
*pbuf
)
215 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
216 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
224 const u16 efuse_max_section
=
225 rtlpriv
->cfg
->maps
[EFUSE_MAX_SECTION_MAP
];
226 const u32 efuse_len
=
227 rtlpriv
->cfg
->maps
[EFUSE_REAL_CONTENT_SIZE
];
229 u16 efuse_utilized
= 0;
232 if ((_offset
+ _size_byte
) > rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]) {
233 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
234 "%s(): Invalid offset(%#x) with read bytes(%#x)!!\n",
235 __func__
, _offset
, _size_byte
);
239 /* allocate memory for efuse_tbl and efuse_word */
240 efuse_tbl
= kzalloc(rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
],
244 efuse_word
= kcalloc(EFUSE_MAX_WORD_UNIT
, sizeof(u16
*), GFP_ATOMIC
);
247 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++) {
248 efuse_word
[i
] = kcalloc(efuse_max_section
, sizeof(u16
), GFP_ATOMIC
);
253 for (i
= 0; i
< efuse_max_section
; i
++)
254 for (j
= 0; j
< EFUSE_MAX_WORD_UNIT
; j
++)
255 efuse_word
[j
][i
] = 0xFFFF;
257 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
258 if (*rtemp8
!= 0xFF) {
260 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_READ_ALL
,
261 "Addr=%d\n", efuse_addr
);
265 while ((*rtemp8
!= 0xFF) && (efuse_addr
< efuse_len
)) {
266 /* Check PG header for section num. */
267 if ((*rtemp8
& 0x1F) == 0x0F) {/* extended header */
268 u1temp
= ((*rtemp8
& 0xE0) >> 5);
269 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
271 if ((*rtemp8
& 0x0F) == 0x0F) {
273 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
275 if (*rtemp8
!= 0xFF &&
276 (efuse_addr
< efuse_len
)) {
281 offset
= ((*rtemp8
& 0xF0) >> 1) | u1temp
;
282 wren
= (*rtemp8
& 0x0F);
286 offset
= ((*rtemp8
>> 4) & 0x0f);
287 wren
= (*rtemp8
& 0x0f);
290 if (offset
< efuse_max_section
) {
291 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_READ_ALL
,
292 "offset-%d Worden=%x\n", offset
, wren
);
294 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++) {
295 if (!(wren
& 0x01)) {
296 RTPRINT(rtlpriv
, FEEPROM
,
298 "Addr=%d\n", efuse_addr
);
300 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
303 efuse_word
[i
][offset
] =
306 if (efuse_addr
>= efuse_len
)
309 RTPRINT(rtlpriv
, FEEPROM
,
311 "Addr=%d\n", efuse_addr
);
313 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
316 efuse_word
[i
][offset
] |=
317 (((u16
)*rtemp8
<< 8) & 0xff00);
319 if (efuse_addr
>= efuse_len
)
327 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_READ_ALL
,
328 "Addr=%d\n", efuse_addr
);
329 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
330 if (*rtemp8
!= 0xFF && (efuse_addr
< efuse_len
)) {
336 for (i
= 0; i
< efuse_max_section
; i
++) {
337 for (j
= 0; j
< EFUSE_MAX_WORD_UNIT
; j
++) {
338 efuse_tbl
[(i
* 8) + (j
* 2)] =
339 (efuse_word
[j
][i
] & 0xff);
340 efuse_tbl
[(i
* 8) + ((j
* 2) + 1)] =
341 ((efuse_word
[j
][i
] >> 8) & 0xff);
345 for (i
= 0; i
< _size_byte
; i
++)
346 pbuf
[i
] = efuse_tbl
[_offset
+ i
];
348 rtlefuse
->efuse_usedbytes
= efuse_utilized
;
349 efuse_usage
= (u8
)((efuse_utilized
* 100) / efuse_len
);
350 rtlefuse
->efuse_usedpercentage
= efuse_usage
;
351 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_EFUSE_BYTES
,
352 (u8
*)&efuse_utilized
);
353 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_EFUSE_USAGE
,
356 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++)
357 kfree(efuse_word
[i
]);
363 bool efuse_shadow_update_chk(struct ieee80211_hw
*hw
)
365 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
366 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
367 u8 section_idx
, i
, base
;
368 u16 words_need
= 0, hdr_num
= 0, totalbytes
, efuse_used
;
369 bool wordchanged
, result
= true;
371 for (section_idx
= 0; section_idx
< 16; section_idx
++) {
372 base
= section_idx
* 8;
375 for (i
= 0; i
< 8; i
= i
+ 2) {
376 if ((rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] !=
377 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
]) ||
378 (rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
+ 1] !=
379 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
+
390 totalbytes
= hdr_num
+ words_need
* 2;
391 efuse_used
= rtlefuse
->efuse_usedbytes
;
393 if ((totalbytes
+ efuse_used
) >=
394 (EFUSE_MAX_SIZE
- rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
]))
397 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
398 "%s(): totalbytes(%#x), hdr_num(%#x), words_need(%#x), efuse_used(%d)\n",
399 __func__
, totalbytes
, hdr_num
, words_need
, efuse_used
);
404 void efuse_shadow_read(struct ieee80211_hw
*hw
, u8 type
,
405 u16 offset
, u32
*value
)
408 efuse_shadow_read_1byte(hw
, offset
, (u8
*)value
);
410 efuse_shadow_read_2byte(hw
, offset
, (u16
*)value
);
412 efuse_shadow_read_4byte(hw
, offset
, value
);
415 void efuse_shadow_write(struct ieee80211_hw
*hw
, u8 type
, u16 offset
,
419 efuse_shadow_write_1byte(hw
, offset
, (u8
)value
);
421 efuse_shadow_write_2byte(hw
, offset
, (u16
)value
);
423 efuse_shadow_write_4byte(hw
, offset
, value
);
426 bool efuse_shadow_update(struct ieee80211_hw
*hw
)
428 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
429 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
434 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
, "\n");
436 if (!efuse_shadow_update_chk(hw
)) {
437 efuse_read_all_map(hw
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]);
438 memcpy(&rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][0],
439 &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
440 rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
442 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
443 "efuse out of capacity!!\n");
446 efuse_power_switch(hw
, true, true);
448 for (offset
= 0; offset
< 16; offset
++) {
452 for (i
= 0; i
< 8; i
++) {
454 word_en
&= ~(BIT(i
/ 2));
456 rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] =
457 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
];
459 if (rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] !=
460 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
]) {
461 word_en
&= ~(BIT(i
/ 2));
463 rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] =
464 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
];
468 if (word_en
!= 0x0F) {
472 &rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
],
474 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_LOUD
,
475 "U-efuse\n", tmpdata
, 8);
477 if (!efuse_pg_packet_write(hw
, (u8
)offset
, word_en
,
479 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
480 "PG section(%#x) fail!!\n", offset
);
486 efuse_power_switch(hw
, true, false);
487 efuse_read_all_map(hw
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]);
489 memcpy(&rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][0],
490 &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
491 rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
493 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
, "\n");
497 void rtl_efuse_shadow_map_update(struct ieee80211_hw
*hw
)
499 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
500 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
502 if (rtlefuse
->autoload_failflag
)
503 memset((&rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]),
504 0xFF, rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
506 efuse_read_all_map(hw
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]);
508 memcpy(&rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][0],
509 &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
510 rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
513 void efuse_force_write_vendor_id(struct ieee80211_hw
*hw
)
515 u8 tmpdata
[8] = { 0xFF, 0xFF, 0xEC, 0x10, 0xFF, 0xFF, 0xFF, 0xFF };
517 efuse_power_switch(hw
, true, true);
519 efuse_pg_packet_write(hw
, 1, 0xD, tmpdata
);
521 efuse_power_switch(hw
, true, false);
524 void efuse_re_pg_section(struct ieee80211_hw
*hw
, u8 section_idx
)
528 static void efuse_shadow_read_1byte(struct ieee80211_hw
*hw
,
529 u16 offset
, u8
*value
)
531 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
532 *value
= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
];
535 static void efuse_shadow_read_2byte(struct ieee80211_hw
*hw
,
536 u16 offset
, u16
*value
)
538 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
540 *value
= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
];
541 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] << 8;
544 static void efuse_shadow_read_4byte(struct ieee80211_hw
*hw
,
545 u16 offset
, u32
*value
)
547 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
549 *value
= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
];
550 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] << 8;
551 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 2] << 16;
552 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 3] << 24;
555 static void efuse_shadow_write_1byte(struct ieee80211_hw
*hw
,
556 u16 offset
, u8 value
)
558 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
560 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
] = value
;
563 static void efuse_shadow_write_2byte(struct ieee80211_hw
*hw
,
564 u16 offset
, u16 value
)
566 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
568 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
] = value
& 0x00FF;
569 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] = value
>> 8;
572 static void efuse_shadow_write_4byte(struct ieee80211_hw
*hw
,
573 u16 offset
, u32 value
)
575 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
577 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
] =
578 (u8
)(value
& 0x000000FF);
579 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] =
580 (u8
)((value
>> 8) & 0x0000FF);
581 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 2] =
582 (u8
)((value
>> 16) & 0x00FF);
583 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 3] =
584 (u8
)((value
>> 24) & 0xFF);
587 int efuse_one_byte_read(struct ieee80211_hw
*hw
, u16 addr
, u8
*data
)
589 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
593 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1,
595 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
596 ((u8
)((addr
>> 8) & 0x03)) |
597 (rtl_read_byte(rtlpriv
,
598 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2) &
601 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, 0x72);
603 while (!(0x80 & rtl_read_byte(rtlpriv
,
604 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3)) &&
610 *data
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
619 static int efuse_one_byte_write(struct ieee80211_hw
*hw
, u16 addr
, u8 data
)
621 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
624 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
625 "Addr = %x Data=%x\n", addr
, data
);
627 rtl_write_byte(rtlpriv
,
628 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1, (u8
)(addr
& 0xff));
629 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
630 (rtl_read_byte(rtlpriv
,
631 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] +
632 2) & 0xFC) | (u8
)((addr
>> 8) & 0x03));
634 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
], data
);
635 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, 0xF2);
638 rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3)) &&
648 static void efuse_read_all_map(struct ieee80211_hw
*hw
, u8
*efuse
)
650 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
652 efuse_power_switch(hw
, false, true);
653 read_efuse(hw
, 0, rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
], efuse
);
654 efuse_power_switch(hw
, false, false);
657 static void efuse_read_data_case1(struct ieee80211_hw
*hw
, u16
*efuse_addr
,
658 u8 efuse_data
, u8 offset
, u8
*tmpdata
,
661 bool dataempty
= true;
667 hoffset
= (efuse_data
>> 4) & 0x0F;
668 hworden
= efuse_data
& 0x0F;
669 word_cnts
= efuse_calculate_word_cnts(hworden
);
671 if (hoffset
== offset
) {
672 for (tmpidx
= 0; tmpidx
< word_cnts
* 2; tmpidx
++) {
673 if (efuse_one_byte_read(hw
, *efuse_addr
+ 1 + tmpidx
,
675 tmpdata
[tmpidx
] = efuse_data
;
676 if (efuse_data
!= 0xff)
682 *readstate
= PG_STATE_DATA
;
684 *efuse_addr
= *efuse_addr
+ (word_cnts
* 2) + 1;
685 *readstate
= PG_STATE_HEADER
;
689 *efuse_addr
= *efuse_addr
+ (word_cnts
* 2) + 1;
690 *readstate
= PG_STATE_HEADER
;
694 static int efuse_pg_packet_read(struct ieee80211_hw
*hw
, u8 offset
, u8
*data
)
696 u8 readstate
= PG_STATE_HEADER
;
698 bool continual
= true;
700 u8 efuse_data
, word_cnts
= 0;
709 memset(data
, 0xff, PGPKT_DATA_SIZE
* sizeof(u8
));
710 memset(tmpdata
, 0xff, PGPKT_DATA_SIZE
* sizeof(u8
));
712 while (continual
&& (efuse_addr
< EFUSE_MAX_SIZE
)) {
713 if (readstate
& PG_STATE_HEADER
) {
714 if (efuse_one_byte_read(hw
, efuse_addr
, &efuse_data
) &&
715 (efuse_data
!= 0xFF))
716 efuse_read_data_case1(hw
, &efuse_addr
,
718 tmpdata
, &readstate
);
721 } else if (readstate
& PG_STATE_DATA
) {
722 efuse_word_enable_data_read(0, tmpdata
, data
);
723 efuse_addr
= efuse_addr
+ (word_cnts
* 2) + 1;
724 readstate
= PG_STATE_HEADER
;
728 if ((data
[0] == 0xff) && (data
[1] == 0xff) &&
729 (data
[2] == 0xff) && (data
[3] == 0xff) &&
730 (data
[4] == 0xff) && (data
[5] == 0xff) &&
731 (data
[6] == 0xff) && (data
[7] == 0xff))
736 static void efuse_write_data_case1(struct ieee80211_hw
*hw
, u16
*efuse_addr
,
737 u8 efuse_data
, u8 offset
,
738 int *continual
, u8
*write_state
,
739 struct pgpkt_struct
*target_pkt
,
740 int *repeat_times
, int *result
, u8 word_en
)
742 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
743 struct pgpkt_struct tmp_pkt
;
744 int dataempty
= true;
745 u8 originaldata
[8 * sizeof(u8
)];
747 u8 match_word_en
, tmp_word_en
;
749 u8 tmp_header
= efuse_data
;
752 tmp_pkt
.offset
= (tmp_header
>> 4) & 0x0F;
753 tmp_pkt
.word_en
= tmp_header
& 0x0F;
754 tmp_word_cnts
= efuse_calculate_word_cnts(tmp_pkt
.word_en
);
756 if (tmp_pkt
.offset
!= target_pkt
->offset
) {
757 *efuse_addr
= *efuse_addr
+ (tmp_word_cnts
* 2) + 1;
758 *write_state
= PG_STATE_HEADER
;
760 for (tmpindex
= 0; tmpindex
< (tmp_word_cnts
* 2); tmpindex
++) {
761 if (efuse_one_byte_read(hw
,
762 (*efuse_addr
+ 1 + tmpindex
),
764 (efuse_data
!= 0xFF))
769 *efuse_addr
= *efuse_addr
+ (tmp_word_cnts
* 2) + 1;
770 *write_state
= PG_STATE_HEADER
;
772 match_word_en
= 0x0F;
773 if (!((target_pkt
->word_en
& BIT(0)) |
774 (tmp_pkt
.word_en
& BIT(0))))
775 match_word_en
&= (~BIT(0));
777 if (!((target_pkt
->word_en
& BIT(1)) |
778 (tmp_pkt
.word_en
& BIT(1))))
779 match_word_en
&= (~BIT(1));
781 if (!((target_pkt
->word_en
& BIT(2)) |
782 (tmp_pkt
.word_en
& BIT(2))))
783 match_word_en
&= (~BIT(2));
785 if (!((target_pkt
->word_en
& BIT(3)) |
786 (tmp_pkt
.word_en
& BIT(3))))
787 match_word_en
&= (~BIT(3));
789 if ((match_word_en
& 0x0F) != 0x0F) {
791 enable_efuse_data_write(hw
,
796 if (0x0F != (badworden
& 0x0F)) {
797 u8 reorg_offset
= offset
;
798 u8 reorg_worden
= badworden
;
800 efuse_pg_packet_write(hw
, reorg_offset
,
806 if ((target_pkt
->word_en
& BIT(0)) ^
807 (match_word_en
& BIT(0)))
808 tmp_word_en
&= (~BIT(0));
810 if ((target_pkt
->word_en
& BIT(1)) ^
811 (match_word_en
& BIT(1)))
812 tmp_word_en
&= (~BIT(1));
814 if ((target_pkt
->word_en
& BIT(2)) ^
815 (match_word_en
& BIT(2)))
816 tmp_word_en
&= (~BIT(2));
818 if ((target_pkt
->word_en
& BIT(3)) ^
819 (match_word_en
& BIT(3)))
820 tmp_word_en
&= (~BIT(3));
822 if ((tmp_word_en
& 0x0F) != 0x0F) {
824 efuse_get_current_size(hw
);
825 target_pkt
->offset
= offset
;
826 target_pkt
->word_en
= tmp_word_en
;
830 *write_state
= PG_STATE_HEADER
;
832 if (*repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
837 *efuse_addr
+= (2 * tmp_word_cnts
) + 1;
838 target_pkt
->offset
= offset
;
839 target_pkt
->word_en
= word_en
;
840 *write_state
= PG_STATE_HEADER
;
844 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
, "efuse PG_STATE_HEADER-1\n");
847 static void efuse_write_data_case2(struct ieee80211_hw
*hw
, u16
*efuse_addr
,
848 int *continual
, u8
*write_state
,
849 struct pgpkt_struct target_pkt
,
850 int *repeat_times
, int *result
)
852 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
853 struct pgpkt_struct tmp_pkt
;
856 u8 originaldata
[8 * sizeof(u8
)];
860 pg_header
= ((target_pkt
.offset
<< 4) & 0xf0) | target_pkt
.word_en
;
861 efuse_one_byte_write(hw
, *efuse_addr
, pg_header
);
862 efuse_one_byte_read(hw
, *efuse_addr
, &tmp_header
);
864 if (tmp_header
== pg_header
) {
865 *write_state
= PG_STATE_DATA
;
866 } else if (tmp_header
== 0xFF) {
867 *write_state
= PG_STATE_HEADER
;
869 if (*repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
874 tmp_pkt
.offset
= (tmp_header
>> 4) & 0x0F;
875 tmp_pkt
.word_en
= tmp_header
& 0x0F;
877 tmp_word_cnts
= efuse_calculate_word_cnts(tmp_pkt
.word_en
);
879 memset(originaldata
, 0xff, 8 * sizeof(u8
));
881 if (efuse_pg_packet_read(hw
, tmp_pkt
.offset
, originaldata
)) {
882 badworden
= enable_efuse_data_write(hw
,
887 if (0x0F != (badworden
& 0x0F)) {
888 u8 reorg_offset
= tmp_pkt
.offset
;
889 u8 reorg_worden
= badworden
;
891 efuse_pg_packet_write(hw
, reorg_offset
,
894 *efuse_addr
= efuse_get_current_size(hw
);
896 *efuse_addr
= *efuse_addr
+
897 (tmp_word_cnts
* 2) + 1;
900 *efuse_addr
= *efuse_addr
+ (tmp_word_cnts
* 2) + 1;
903 *write_state
= PG_STATE_HEADER
;
905 if (*repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
910 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
911 "efuse PG_STATE_HEADER-2\n");
915 static int efuse_pg_packet_write(struct ieee80211_hw
*hw
,
916 u8 offset
, u8 word_en
, u8
*data
)
918 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
919 struct pgpkt_struct target_pkt
;
920 u8 write_state
= PG_STATE_HEADER
;
921 int continual
= true, dataempty
= true, result
= true;
924 u8 target_word_cnts
= 0;
926 static int repeat_times
;
928 if (efuse_get_current_size(hw
) >= (EFUSE_MAX_SIZE
-
929 rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
])) {
930 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
931 "%s error\n", __func__
);
935 target_pkt
.offset
= offset
;
936 target_pkt
.word_en
= word_en
;
938 memset(target_pkt
.data
, 0xFF, 8 * sizeof(u8
));
940 efuse_word_enable_data_read(word_en
, data
, target_pkt
.data
);
941 target_word_cnts
= efuse_calculate_word_cnts(target_pkt
.word_en
);
943 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
, "efuse Power ON\n");
945 while (continual
&& (efuse_addr
< (EFUSE_MAX_SIZE
-
946 rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
]))) {
947 if (write_state
== PG_STATE_HEADER
) {
950 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
951 "efuse PG_STATE_HEADER\n");
953 if (efuse_one_byte_read(hw
, efuse_addr
, &efuse_data
) &&
954 (efuse_data
!= 0xFF))
955 efuse_write_data_case1(hw
, &efuse_addr
,
960 &repeat_times
, &result
,
963 efuse_write_data_case2(hw
, &efuse_addr
,
970 } else if (write_state
== PG_STATE_DATA
) {
971 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
972 "efuse PG_STATE_DATA\n");
975 enable_efuse_data_write(hw
, efuse_addr
+ 1,
979 if ((badworden
& 0x0F) == 0x0F) {
983 efuse_addr
+ (2 * target_word_cnts
) + 1;
985 target_pkt
.offset
= offset
;
986 target_pkt
.word_en
= badworden
;
988 efuse_calculate_word_cnts(target_pkt
.word_en
);
989 write_state
= PG_STATE_HEADER
;
991 if (repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
995 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
996 "efuse PG_STATE_HEADER-3\n");
1001 if (efuse_addr
>= (EFUSE_MAX_SIZE
-
1002 rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
])) {
1003 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
1004 "efuse_addr(%#x) Out of size!!\n", efuse_addr
);
1010 static void efuse_word_enable_data_read(u8 word_en
, u8
*sourdata
,
1013 if (!(word_en
& BIT(0))) {
1014 targetdata
[0] = sourdata
[0];
1015 targetdata
[1] = sourdata
[1];
1018 if (!(word_en
& BIT(1))) {
1019 targetdata
[2] = sourdata
[2];
1020 targetdata
[3] = sourdata
[3];
1023 if (!(word_en
& BIT(2))) {
1024 targetdata
[4] = sourdata
[4];
1025 targetdata
[5] = sourdata
[5];
1028 if (!(word_en
& BIT(3))) {
1029 targetdata
[6] = sourdata
[6];
1030 targetdata
[7] = sourdata
[7];
1034 static u8
enable_efuse_data_write(struct ieee80211_hw
*hw
,
1035 u16 efuse_addr
, u8 word_en
, u8
*data
)
1037 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1039 u16 start_addr
= efuse_addr
;
1040 u8 badworden
= 0x0F;
1043 memset(tmpdata
, 0xff, PGPKT_DATA_SIZE
);
1044 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
1045 "word_en = %x efuse_addr=%x\n", word_en
, efuse_addr
);
1047 if (!(word_en
& BIT(0))) {
1048 tmpaddr
= start_addr
;
1049 efuse_one_byte_write(hw
, start_addr
++, data
[0]);
1050 efuse_one_byte_write(hw
, start_addr
++, data
[1]);
1052 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[0]);
1053 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[1]);
1054 if ((data
[0] != tmpdata
[0]) || (data
[1] != tmpdata
[1]))
1055 badworden
&= (~BIT(0));
1058 if (!(word_en
& BIT(1))) {
1059 tmpaddr
= start_addr
;
1060 efuse_one_byte_write(hw
, start_addr
++, data
[2]);
1061 efuse_one_byte_write(hw
, start_addr
++, data
[3]);
1063 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[2]);
1064 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[3]);
1065 if ((data
[2] != tmpdata
[2]) || (data
[3] != tmpdata
[3]))
1066 badworden
&= (~BIT(1));
1069 if (!(word_en
& BIT(2))) {
1070 tmpaddr
= start_addr
;
1071 efuse_one_byte_write(hw
, start_addr
++, data
[4]);
1072 efuse_one_byte_write(hw
, start_addr
++, data
[5]);
1074 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[4]);
1075 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[5]);
1076 if ((data
[4] != tmpdata
[4]) || (data
[5] != tmpdata
[5]))
1077 badworden
&= (~BIT(2));
1080 if (!(word_en
& BIT(3))) {
1081 tmpaddr
= start_addr
;
1082 efuse_one_byte_write(hw
, start_addr
++, data
[6]);
1083 efuse_one_byte_write(hw
, start_addr
++, data
[7]);
1085 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[6]);
1086 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[7]);
1087 if ((data
[6] != tmpdata
[6]) || (data
[7] != tmpdata
[7]))
1088 badworden
&= (~BIT(3));
1094 void efuse_power_switch(struct ieee80211_hw
*hw
, u8 write
, u8 pwrstate
)
1096 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1097 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1101 if (pwrstate
&& (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192SE
)) {
1102 if (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192CE
&&
1103 rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192DE
) {
1104 rtl_write_byte(rtlpriv
,
1105 rtlpriv
->cfg
->maps
[EFUSE_ACCESS
], 0x69);
1108 rtl_read_word(rtlpriv
,
1109 rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
]);
1110 if (!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_PWC_EV12V
])) {
1111 tmpv16
|= rtlpriv
->cfg
->maps
[EFUSE_PWC_EV12V
];
1112 rtl_write_word(rtlpriv
,
1113 rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
],
1117 tmpv16
= rtl_read_word(rtlpriv
,
1118 rtlpriv
->cfg
->maps
[SYS_FUNC_EN
]);
1119 if (!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_FEN_ELDR
])) {
1120 tmpv16
|= rtlpriv
->cfg
->maps
[EFUSE_FEN_ELDR
];
1121 rtl_write_word(rtlpriv
,
1122 rtlpriv
->cfg
->maps
[SYS_FUNC_EN
], tmpv16
);
1125 tmpv16
= rtl_read_word(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_CLK
]);
1126 if ((!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_LOADER_CLK_EN
])) ||
1127 (!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_ANA8M
]))) {
1128 tmpv16
|= (rtlpriv
->cfg
->maps
[EFUSE_LOADER_CLK_EN
] |
1129 rtlpriv
->cfg
->maps
[EFUSE_ANA8M
]);
1130 rtl_write_word(rtlpriv
,
1131 rtlpriv
->cfg
->maps
[SYS_CLK
], tmpv16
);
1137 tempval
= rtl_read_byte(rtlpriv
,
1138 rtlpriv
->cfg
->maps
[EFUSE_TEST
] +
1141 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
1142 tempval
&= ~(BIT(3) | BIT(4) | BIT(5) | BIT(6));
1143 tempval
|= (VOLTAGE_V25
<< 3);
1144 } else if (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192SE
) {
1146 tempval
|= (VOLTAGE_V25
<< 4);
1149 rtl_write_byte(rtlpriv
,
1150 rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3,
1154 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8192SE
) {
1155 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CLK
],
1159 if (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192CE
&&
1160 rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192DE
)
1161 rtl_write_byte(rtlpriv
,
1162 rtlpriv
->cfg
->maps
[EFUSE_ACCESS
], 0);
1165 tempval
= rtl_read_byte(rtlpriv
,
1166 rtlpriv
->cfg
->maps
[EFUSE_TEST
] +
1168 rtl_write_byte(rtlpriv
,
1169 rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3,
1173 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8192SE
) {
1174 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CLK
],
1180 static u16
efuse_get_current_size(struct ieee80211_hw
*hw
)
1182 int continual
= true;
1184 u8 hoffset
, hworden
;
1185 u8 efuse_data
, word_cnts
;
1187 while (continual
&& efuse_one_byte_read(hw
, efuse_addr
, &efuse_data
) &&
1188 (efuse_addr
< EFUSE_MAX_SIZE
)) {
1189 if (efuse_data
!= 0xFF) {
1190 hoffset
= (efuse_data
>> 4) & 0x0F;
1191 hworden
= efuse_data
& 0x0F;
1192 word_cnts
= efuse_calculate_word_cnts(hworden
);
1193 efuse_addr
= efuse_addr
+ (word_cnts
* 2) + 1;
1202 static u8
efuse_calculate_word_cnts(u8 word_en
)
1206 if (!(word_en
& BIT(0)))
1208 if (!(word_en
& BIT(1)))
1210 if (!(word_en
& BIT(2)))
1212 if (!(word_en
& BIT(3)))
1217 int rtl_get_hwinfo(struct ieee80211_hw
*hw
, struct rtl_priv
*rtlpriv
,
1218 int max_size
, u8
*hwinfo
, int *params
)
1220 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1221 struct rtl_pci_priv
*rtlpcipriv
= rtl_pcipriv(hw
);
1222 struct device
*dev
= &rtlpcipriv
->dev
.pdev
->dev
;
1226 switch (rtlefuse
->epromtype
) {
1227 case EEPROM_BOOT_EFUSE
:
1228 rtl_efuse_shadow_map_update(hw
);
1232 pr_err("RTL8XXX did not boot from eeprom, check it !!\n");
1236 dev_warn(dev
, "no efuse data\n");
1240 memcpy(hwinfo
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0], max_size
);
1242 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
, "MAP",
1245 eeprom_id
= *((u16
*)&hwinfo
[0]);
1246 if (eeprom_id
!= params
[0]) {
1247 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1248 "EEPROM ID(%#x) is invalid!!\n", eeprom_id
);
1249 rtlefuse
->autoload_failflag
= true;
1251 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1252 rtlefuse
->autoload_failflag
= false;
1255 if (rtlefuse
->autoload_failflag
)
1258 rtlefuse
->eeprom_vid
= *(u16
*)&hwinfo
[params
[1]];
1259 rtlefuse
->eeprom_did
= *(u16
*)&hwinfo
[params
[2]];
1260 rtlefuse
->eeprom_svid
= *(u16
*)&hwinfo
[params
[3]];
1261 rtlefuse
->eeprom_smid
= *(u16
*)&hwinfo
[params
[4]];
1262 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1263 "EEPROMId = 0x%4x\n", eeprom_id
);
1264 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1265 "EEPROM VID = 0x%4x\n", rtlefuse
->eeprom_vid
);
1266 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1267 "EEPROM DID = 0x%4x\n", rtlefuse
->eeprom_did
);
1268 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1269 "EEPROM SVID = 0x%4x\n", rtlefuse
->eeprom_svid
);
1270 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1271 "EEPROM SMID = 0x%4x\n", rtlefuse
->eeprom_smid
);
1273 for (i
= 0; i
< 6; i
+= 2) {
1274 usvalue
= *(u16
*)&hwinfo
[params
[5] + i
];
1275 *((u16
*)(&rtlefuse
->dev_addr
[i
])) = usvalue
;
1277 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "%pM\n", rtlefuse
->dev_addr
);
1279 rtlefuse
->eeprom_channelplan
= *&hwinfo
[params
[6]];
1280 rtlefuse
->eeprom_version
= *(u16
*)&hwinfo
[params
[7]];
1281 rtlefuse
->txpwr_fromeprom
= true;
1282 rtlefuse
->eeprom_oemid
= *&hwinfo
[params
[8]];
1284 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1285 "EEPROM Customer ID: 0x%2x\n", rtlefuse
->eeprom_oemid
);
1287 /* set channel plan to world wide 13 */
1288 rtlefuse
->channel_plan
= params
[9];
1293 void rtl_fw_block_write(struct ieee80211_hw
*hw
, const u8
*buffer
, u32 size
)
1295 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1296 u8
*pu4byteptr
= (u8
*)buffer
;
1299 for (i
= 0; i
< size
; i
++)
1300 rtl_write_byte(rtlpriv
, (START_ADDRESS
+ i
), *(pu4byteptr
+ i
));
1303 void rtl_fw_page_write(struct ieee80211_hw
*hw
, u32 page
, const u8
*buffer
,
1306 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1308 u8 u8page
= (u8
)(page
& 0x07);
1310 value8
= (rtl_read_byte(rtlpriv
, REG_MCUFWDL
+ 2) & 0xF8) | u8page
;
1312 rtl_write_byte(rtlpriv
, (REG_MCUFWDL
+ 2), value8
);
1313 rtl_fw_block_write(hw
, buffer
, size
);
1316 void rtl_fill_dummy(u8
*pfwbuf
, u32
*pfwlen
)
1318 u32 fwlen
= *pfwlen
;
1319 u8 remain
= (u8
)(fwlen
% 4);
1321 remain
= (remain
== 0) ? 0 : (4 - remain
);
1323 while (remain
> 0) {