1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2012 Realtek Corporation.*/
7 #include <linux/export.h>
9 static const u8 PGPKT_DATA_SIZE
= 8;
10 static const int EFUSE_MAX_SIZE
= 512;
12 #define START_ADDRESS 0x1000
13 #define REG_MCUFWDL 0x0080
15 static const struct rtl_efuse_ops efuse_ops
= {
16 .efuse_onebyte_read
= efuse_one_byte_read
,
17 .efuse_logical_map_read
= efuse_shadow_read
,
20 static void efuse_shadow_read_1byte(struct ieee80211_hw
*hw
, u16 offset
,
22 static void efuse_shadow_read_2byte(struct ieee80211_hw
*hw
, u16 offset
,
24 static void efuse_shadow_read_4byte(struct ieee80211_hw
*hw
, u16 offset
,
26 static void efuse_shadow_write_1byte(struct ieee80211_hw
*hw
, u16 offset
,
28 static void efuse_shadow_write_2byte(struct ieee80211_hw
*hw
, u16 offset
,
30 static void efuse_shadow_write_4byte(struct ieee80211_hw
*hw
, u16 offset
,
32 static int efuse_one_byte_write(struct ieee80211_hw
*hw
, u16 addr
,
34 static void efuse_read_all_map(struct ieee80211_hw
*hw
, u8
*efuse
);
35 static int efuse_pg_packet_read(struct ieee80211_hw
*hw
, u8 offset
,
37 static int efuse_pg_packet_write(struct ieee80211_hw
*hw
, u8 offset
,
38 u8 word_en
, u8
*data
);
39 static void efuse_word_enable_data_read(u8 word_en
, u8
*sourdata
,
41 static u8
enable_efuse_data_write(struct ieee80211_hw
*hw
,
42 u16 efuse_addr
, u8 word_en
, u8
*data
);
43 static u16
efuse_get_current_size(struct ieee80211_hw
*hw
);
44 static u8
efuse_calculate_word_cnts(u8 word_en
);
46 void efuse_initialize(struct ieee80211_hw
*hw
)
48 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
52 bytetemp
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_FUNC_EN
] + 1);
53 temp
= bytetemp
| 0x20;
54 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_FUNC_EN
] + 1, temp
);
56 bytetemp
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
] + 1);
57 temp
= bytetemp
& 0xFE;
58 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
] + 1, temp
);
60 bytetemp
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3);
61 temp
= bytetemp
| 0x80;
62 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3, temp
);
64 rtl_write_byte(rtlpriv
, 0x2F8, 0x3);
66 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, 0x72);
70 u8
efuse_read_1byte(struct ieee80211_hw
*hw
, u16 address
)
72 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
78 rtlpriv
->cfg
->maps
[EFUSE_REAL_CONTENT_SIZE
];
80 if (address
< efuse_len
) {
81 temp
= address
& 0xFF;
82 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1,
84 bytetemp
= rtl_read_byte(rtlpriv
,
85 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2);
86 temp
= ((address
>> 8) & 0x03) | (bytetemp
& 0xFC);
87 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
90 bytetemp
= rtl_read_byte(rtlpriv
,
91 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
92 temp
= bytetemp
& 0x7F;
93 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3,
96 bytetemp
= rtl_read_byte(rtlpriv
,
97 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
98 while (!(bytetemp
& 0x80)) {
99 bytetemp
= rtl_read_byte(rtlpriv
,
101 maps
[EFUSE_CTRL
] + 3);
106 data
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
112 EXPORT_SYMBOL(efuse_read_1byte
);
114 void efuse_write_1byte(struct ieee80211_hw
*hw
, u16 address
, u8 value
)
116 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
120 const u32 efuse_len
=
121 rtlpriv
->cfg
->maps
[EFUSE_REAL_CONTENT_SIZE
];
123 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
, "Addr=%x Data =%x\n",
126 if (address
< efuse_len
) {
127 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
], value
);
129 temp
= address
& 0xFF;
130 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1,
132 bytetemp
= rtl_read_byte(rtlpriv
,
133 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2);
135 temp
= ((address
>> 8) & 0x03) | (bytetemp
& 0xFC);
136 rtl_write_byte(rtlpriv
,
137 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2, temp
);
139 bytetemp
= rtl_read_byte(rtlpriv
,
140 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
141 temp
= bytetemp
| 0x80;
142 rtl_write_byte(rtlpriv
,
143 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, temp
);
145 bytetemp
= rtl_read_byte(rtlpriv
,
146 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
148 while (bytetemp
& 0x80) {
149 bytetemp
= rtl_read_byte(rtlpriv
,
151 maps
[EFUSE_CTRL
] + 3);
162 void read_efuse_byte(struct ieee80211_hw
*hw
, u16 _offset
, u8
*pbuf
)
164 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
169 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1,
171 readbyte
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2);
172 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
173 ((_offset
>> 8) & 0x03) | (readbyte
& 0xfc));
175 readbyte
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3);
176 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3,
180 value32
= rtl_read_dword(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
181 while (!(((value32
>> 24) & 0xff) & 0x80) && (retry
< 10000)) {
182 value32
= rtl_read_dword(rtlpriv
,
183 rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
188 value32
= rtl_read_dword(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
190 *pbuf
= (u8
) (value32
& 0xff);
192 EXPORT_SYMBOL_GPL(read_efuse_byte
);
194 void read_efuse(struct ieee80211_hw
*hw
, u16 _offset
, u16 _size_byte
, u8
*pbuf
)
196 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
197 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
205 const u16 efuse_max_section
=
206 rtlpriv
->cfg
->maps
[EFUSE_MAX_SECTION_MAP
];
207 const u32 efuse_len
=
208 rtlpriv
->cfg
->maps
[EFUSE_REAL_CONTENT_SIZE
];
210 u16 efuse_utilized
= 0;
213 if ((_offset
+ _size_byte
) > rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]) {
214 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
215 "read_efuse(): Invalid offset(%#x) with read bytes(%#x)!!\n",
216 _offset
, _size_byte
);
220 /* allocate memory for efuse_tbl and efuse_word */
221 efuse_tbl
= kzalloc(rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
],
225 efuse_word
= kcalloc(EFUSE_MAX_WORD_UNIT
, sizeof(u16
*), GFP_ATOMIC
);
228 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++) {
229 efuse_word
[i
] = kcalloc(efuse_max_section
, sizeof(u16
),
235 for (i
= 0; i
< efuse_max_section
; i
++)
236 for (j
= 0; j
< EFUSE_MAX_WORD_UNIT
; j
++)
237 efuse_word
[j
][i
] = 0xFFFF;
239 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
240 if (*rtemp8
!= 0xFF) {
242 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_READ_ALL
,
243 "Addr=%d\n", efuse_addr
);
247 while ((*rtemp8
!= 0xFF) && (efuse_addr
< efuse_len
)) {
248 /* Check PG header for section num. */
249 if ((*rtemp8
& 0x1F) == 0x0F) {/* extended header */
250 u1temp
= ((*rtemp8
& 0xE0) >> 5);
251 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
253 if ((*rtemp8
& 0x0F) == 0x0F) {
255 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
257 if (*rtemp8
!= 0xFF &&
258 (efuse_addr
< efuse_len
)) {
263 offset
= ((*rtemp8
& 0xF0) >> 1) | u1temp
;
264 wren
= (*rtemp8
& 0x0F);
268 offset
= ((*rtemp8
>> 4) & 0x0f);
269 wren
= (*rtemp8
& 0x0f);
272 if (offset
< efuse_max_section
) {
273 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_READ_ALL
,
274 "offset-%d Worden=%x\n", offset
, wren
);
276 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++) {
277 if (!(wren
& 0x01)) {
278 RTPRINT(rtlpriv
, FEEPROM
,
280 "Addr=%d\n", efuse_addr
);
282 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
285 efuse_word
[i
][offset
] =
288 if (efuse_addr
>= efuse_len
)
291 RTPRINT(rtlpriv
, FEEPROM
,
293 "Addr=%d\n", efuse_addr
);
295 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
298 efuse_word
[i
][offset
] |=
299 (((u16
)*rtemp8
<< 8) & 0xff00);
301 if (efuse_addr
>= efuse_len
)
309 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_READ_ALL
,
310 "Addr=%d\n", efuse_addr
);
311 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
312 if (*rtemp8
!= 0xFF && (efuse_addr
< efuse_len
)) {
318 for (i
= 0; i
< efuse_max_section
; i
++) {
319 for (j
= 0; j
< EFUSE_MAX_WORD_UNIT
; j
++) {
320 efuse_tbl
[(i
* 8) + (j
* 2)] =
321 (efuse_word
[j
][i
] & 0xff);
322 efuse_tbl
[(i
* 8) + ((j
* 2) + 1)] =
323 ((efuse_word
[j
][i
] >> 8) & 0xff);
327 for (i
= 0; i
< _size_byte
; i
++)
328 pbuf
[i
] = efuse_tbl
[_offset
+ i
];
330 rtlefuse
->efuse_usedbytes
= efuse_utilized
;
331 efuse_usage
= (u8
) ((efuse_utilized
* 100) / efuse_len
);
332 rtlefuse
->efuse_usedpercentage
= efuse_usage
;
333 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_EFUSE_BYTES
,
334 (u8
*)&efuse_utilized
);
335 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_EFUSE_USAGE
,
338 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++)
339 kfree(efuse_word
[i
]);
345 bool efuse_shadow_update_chk(struct ieee80211_hw
*hw
)
347 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
348 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
349 u8 section_idx
, i
, base
;
350 u16 words_need
= 0, hdr_num
= 0, totalbytes
, efuse_used
;
351 bool wordchanged
, result
= true;
353 for (section_idx
= 0; section_idx
< 16; section_idx
++) {
354 base
= section_idx
* 8;
357 for (i
= 0; i
< 8; i
= i
+ 2) {
358 if (rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] !=
359 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
] ||
360 rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
+ 1] !=
361 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
+
372 totalbytes
= hdr_num
+ words_need
* 2;
373 efuse_used
= rtlefuse
->efuse_usedbytes
;
375 if ((totalbytes
+ efuse_used
) >=
376 (EFUSE_MAX_SIZE
- rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
]))
379 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
380 "efuse_shadow_update_chk(): totalbytes(%#x), hdr_num(%#x), words_need(%#x), efuse_used(%d)\n",
381 totalbytes
, hdr_num
, words_need
, efuse_used
);
386 void efuse_shadow_read(struct ieee80211_hw
*hw
, u8 type
,
387 u16 offset
, u32
*value
)
390 efuse_shadow_read_1byte(hw
, offset
, (u8
*)value
);
392 efuse_shadow_read_2byte(hw
, offset
, (u16
*)value
);
394 efuse_shadow_read_4byte(hw
, offset
, value
);
397 EXPORT_SYMBOL(efuse_shadow_read
);
399 void efuse_shadow_write(struct ieee80211_hw
*hw
, u8 type
, u16 offset
,
403 efuse_shadow_write_1byte(hw
, offset
, (u8
) value
);
405 efuse_shadow_write_2byte(hw
, offset
, (u16
) value
);
407 efuse_shadow_write_4byte(hw
, offset
, value
);
411 bool efuse_shadow_update(struct ieee80211_hw
*hw
)
413 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
414 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
419 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
, "\n");
421 if (!efuse_shadow_update_chk(hw
)) {
422 efuse_read_all_map(hw
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]);
423 memcpy(&rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][0],
424 &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
425 rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
427 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
428 "efuse out of capacity!!\n");
431 efuse_power_switch(hw
, true, true);
433 for (offset
= 0; offset
< 16; offset
++) {
438 for (i
= 0; i
< 8; i
++) {
440 word_en
&= ~(BIT(i
/ 2));
442 rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] =
443 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
];
446 if (rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] !=
447 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
]) {
448 word_en
&= ~(BIT(i
/ 2));
450 rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] =
451 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
];
456 if (word_en
!= 0x0F) {
460 &rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
],
462 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_LOUD
,
463 "U-efuse\n", tmpdata
, 8);
465 if (!efuse_pg_packet_write(hw
, (u8
) offset
, word_en
,
467 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
468 "PG section(%#x) fail!!\n", offset
);
474 efuse_power_switch(hw
, true, false);
475 efuse_read_all_map(hw
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]);
477 memcpy(&rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][0],
478 &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
479 rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
481 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
, "\n");
485 void rtl_efuse_shadow_map_update(struct ieee80211_hw
*hw
)
487 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
488 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
490 if (rtlefuse
->autoload_failflag
)
491 memset((&rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]),
492 0xFF, rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
494 efuse_read_all_map(hw
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]);
496 memcpy(&rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][0],
497 &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
498 rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
501 EXPORT_SYMBOL(rtl_efuse_shadow_map_update
);
503 void efuse_force_write_vendor_id(struct ieee80211_hw
*hw
)
505 u8 tmpdata
[8] = { 0xFF, 0xFF, 0xEC, 0x10, 0xFF, 0xFF, 0xFF, 0xFF };
507 efuse_power_switch(hw
, true, true);
509 efuse_pg_packet_write(hw
, 1, 0xD, tmpdata
);
511 efuse_power_switch(hw
, true, false);
515 void efuse_re_pg_section(struct ieee80211_hw
*hw
, u8 section_idx
)
519 static void efuse_shadow_read_1byte(struct ieee80211_hw
*hw
,
520 u16 offset
, u8
*value
)
522 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
523 *value
= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
];
526 static void efuse_shadow_read_2byte(struct ieee80211_hw
*hw
,
527 u16 offset
, u16
*value
)
529 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
531 *value
= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
];
532 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] << 8;
536 static void efuse_shadow_read_4byte(struct ieee80211_hw
*hw
,
537 u16 offset
, u32
*value
)
539 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
541 *value
= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
];
542 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] << 8;
543 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 2] << 16;
544 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 3] << 24;
547 static void efuse_shadow_write_1byte(struct ieee80211_hw
*hw
,
548 u16 offset
, u8 value
)
550 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
552 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
] = value
;
555 static void efuse_shadow_write_2byte(struct ieee80211_hw
*hw
,
556 u16 offset
, u16 value
)
558 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
560 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
] = value
& 0x00FF;
561 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] = value
>> 8;
565 static void efuse_shadow_write_4byte(struct ieee80211_hw
*hw
,
566 u16 offset
, u32 value
)
568 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
570 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
] =
571 (u8
) (value
& 0x000000FF);
572 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] =
573 (u8
) ((value
>> 8) & 0x0000FF);
574 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 2] =
575 (u8
) ((value
>> 16) & 0x00FF);
576 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 3] =
577 (u8
) ((value
>> 24) & 0xFF);
581 int efuse_one_byte_read(struct ieee80211_hw
*hw
, u16 addr
, u8
*data
)
583 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
587 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1,
589 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
590 ((u8
) ((addr
>> 8) & 0x03)) |
591 (rtl_read_byte(rtlpriv
,
592 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2) &
595 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, 0x72);
597 while (!(0x80 & rtl_read_byte(rtlpriv
,
598 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3))
604 *data
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
612 EXPORT_SYMBOL(efuse_one_byte_read
);
614 static int efuse_one_byte_write(struct ieee80211_hw
*hw
, u16 addr
, u8 data
)
616 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
619 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
620 "Addr = %x Data=%x\n", addr
, data
);
622 rtl_write_byte(rtlpriv
,
623 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1, (u8
) (addr
& 0xff));
624 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
625 (rtl_read_byte(rtlpriv
,
626 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] +
627 2) & 0xFC) | (u8
) ((addr
>> 8) & 0x03));
629 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
], data
);
630 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, 0xF2);
632 while ((0x80 & rtl_read_byte(rtlpriv
,
633 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3))
643 static void efuse_read_all_map(struct ieee80211_hw
*hw
, u8
*efuse
)
645 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
647 efuse_power_switch(hw
, false, true);
648 read_efuse(hw
, 0, rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
], efuse
);
649 efuse_power_switch(hw
, false, false);
652 static void efuse_read_data_case1(struct ieee80211_hw
*hw
, u16
*efuse_addr
,
653 u8 efuse_data
, u8 offset
, u8
*tmpdata
,
656 bool dataempty
= true;
662 hoffset
= (efuse_data
>> 4) & 0x0F;
663 hworden
= efuse_data
& 0x0F;
664 word_cnts
= efuse_calculate_word_cnts(hworden
);
666 if (hoffset
== offset
) {
667 for (tmpidx
= 0; tmpidx
< word_cnts
* 2; tmpidx
++) {
668 if (efuse_one_byte_read(hw
, *efuse_addr
+ 1 + tmpidx
,
670 tmpdata
[tmpidx
] = efuse_data
;
671 if (efuse_data
!= 0xff)
677 *readstate
= PG_STATE_DATA
;
679 *efuse_addr
= *efuse_addr
+ (word_cnts
* 2) + 1;
680 *readstate
= PG_STATE_HEADER
;
684 *efuse_addr
= *efuse_addr
+ (word_cnts
* 2) + 1;
685 *readstate
= PG_STATE_HEADER
;
689 static int efuse_pg_packet_read(struct ieee80211_hw
*hw
, u8 offset
, u8
*data
)
691 u8 readstate
= PG_STATE_HEADER
;
693 bool continual
= true;
695 u8 efuse_data
, word_cnts
= 0;
704 memset(data
, 0xff, PGPKT_DATA_SIZE
* sizeof(u8
));
705 memset(tmpdata
, 0xff, PGPKT_DATA_SIZE
* sizeof(u8
));
707 while (continual
&& (efuse_addr
< EFUSE_MAX_SIZE
)) {
708 if (readstate
& PG_STATE_HEADER
) {
709 if (efuse_one_byte_read(hw
, efuse_addr
, &efuse_data
)
710 && (efuse_data
!= 0xFF))
711 efuse_read_data_case1(hw
, &efuse_addr
,
713 tmpdata
, &readstate
);
716 } else if (readstate
& PG_STATE_DATA
) {
717 efuse_word_enable_data_read(0, tmpdata
, data
);
718 efuse_addr
= efuse_addr
+ (word_cnts
* 2) + 1;
719 readstate
= PG_STATE_HEADER
;
724 if ((data
[0] == 0xff) && (data
[1] == 0xff) &&
725 (data
[2] == 0xff) && (data
[3] == 0xff) &&
726 (data
[4] == 0xff) && (data
[5] == 0xff) &&
727 (data
[6] == 0xff) && (data
[7] == 0xff))
734 static void efuse_write_data_case1(struct ieee80211_hw
*hw
, u16
*efuse_addr
,
735 u8 efuse_data
, u8 offset
,
736 int *continual
, u8
*write_state
,
737 struct pgpkt_struct
*target_pkt
,
738 int *repeat_times
, int *result
, u8 word_en
)
740 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
741 struct pgpkt_struct tmp_pkt
;
742 int dataempty
= true;
743 u8 originaldata
[8 * sizeof(u8
)];
745 u8 match_word_en
, tmp_word_en
;
747 u8 tmp_header
= efuse_data
;
750 tmp_pkt
.offset
= (tmp_header
>> 4) & 0x0F;
751 tmp_pkt
.word_en
= tmp_header
& 0x0F;
752 tmp_word_cnts
= efuse_calculate_word_cnts(tmp_pkt
.word_en
);
754 if (tmp_pkt
.offset
!= target_pkt
->offset
) {
755 *efuse_addr
= *efuse_addr
+ (tmp_word_cnts
* 2) + 1;
756 *write_state
= PG_STATE_HEADER
;
758 for (tmpindex
= 0; tmpindex
< (tmp_word_cnts
* 2); tmpindex
++) {
759 if (efuse_one_byte_read(hw
,
760 (*efuse_addr
+ 1 + tmpindex
),
762 (efuse_data
!= 0xFF))
767 *efuse_addr
= *efuse_addr
+ (tmp_word_cnts
* 2) + 1;
768 *write_state
= PG_STATE_HEADER
;
770 match_word_en
= 0x0F;
771 if (!((target_pkt
->word_en
& BIT(0)) |
772 (tmp_pkt
.word_en
& BIT(0))))
773 match_word_en
&= (~BIT(0));
775 if (!((target_pkt
->word_en
& BIT(1)) |
776 (tmp_pkt
.word_en
& BIT(1))))
777 match_word_en
&= (~BIT(1));
779 if (!((target_pkt
->word_en
& BIT(2)) |
780 (tmp_pkt
.word_en
& BIT(2))))
781 match_word_en
&= (~BIT(2));
783 if (!((target_pkt
->word_en
& BIT(3)) |
784 (tmp_pkt
.word_en
& BIT(3))))
785 match_word_en
&= (~BIT(3));
787 if ((match_word_en
& 0x0F) != 0x0F) {
789 enable_efuse_data_write(hw
,
794 if (0x0F != (badworden
& 0x0F)) {
795 u8 reorg_offset
= offset
;
796 u8 reorg_worden
= badworden
;
798 efuse_pg_packet_write(hw
, reorg_offset
,
804 if ((target_pkt
->word_en
& BIT(0)) ^
805 (match_word_en
& BIT(0)))
806 tmp_word_en
&= (~BIT(0));
808 if ((target_pkt
->word_en
& BIT(1)) ^
809 (match_word_en
& BIT(1)))
810 tmp_word_en
&= (~BIT(1));
812 if ((target_pkt
->word_en
& BIT(2)) ^
813 (match_word_en
& BIT(2)))
814 tmp_word_en
&= (~BIT(2));
816 if ((target_pkt
->word_en
& BIT(3)) ^
817 (match_word_en
& BIT(3)))
818 tmp_word_en
&= (~BIT(3));
820 if ((tmp_word_en
& 0x0F) != 0x0F) {
821 *efuse_addr
= efuse_get_current_size(hw
);
822 target_pkt
->offset
= offset
;
823 target_pkt
->word_en
= tmp_word_en
;
827 *write_state
= PG_STATE_HEADER
;
829 if (*repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
834 *efuse_addr
+= (2 * tmp_word_cnts
) + 1;
835 target_pkt
->offset
= offset
;
836 target_pkt
->word_en
= word_en
;
837 *write_state
= PG_STATE_HEADER
;
841 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
, "efuse PG_STATE_HEADER-1\n");
844 static void efuse_write_data_case2(struct ieee80211_hw
*hw
, u16
*efuse_addr
,
845 int *continual
, u8
*write_state
,
846 struct pgpkt_struct target_pkt
,
847 int *repeat_times
, int *result
)
849 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
850 struct pgpkt_struct tmp_pkt
;
853 u8 originaldata
[8 * sizeof(u8
)];
857 pg_header
= ((target_pkt
.offset
<< 4) & 0xf0) | target_pkt
.word_en
;
858 efuse_one_byte_write(hw
, *efuse_addr
, pg_header
);
859 efuse_one_byte_read(hw
, *efuse_addr
, &tmp_header
);
861 if (tmp_header
== pg_header
) {
862 *write_state
= PG_STATE_DATA
;
863 } else if (tmp_header
== 0xFF) {
864 *write_state
= PG_STATE_HEADER
;
866 if (*repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
871 tmp_pkt
.offset
= (tmp_header
>> 4) & 0x0F;
872 tmp_pkt
.word_en
= tmp_header
& 0x0F;
874 tmp_word_cnts
= efuse_calculate_word_cnts(tmp_pkt
.word_en
);
876 memset(originaldata
, 0xff, 8 * sizeof(u8
));
878 if (efuse_pg_packet_read(hw
, tmp_pkt
.offset
, originaldata
)) {
879 badworden
= enable_efuse_data_write(hw
,
884 if (0x0F != (badworden
& 0x0F)) {
885 u8 reorg_offset
= tmp_pkt
.offset
;
886 u8 reorg_worden
= badworden
;
888 efuse_pg_packet_write(hw
, reorg_offset
,
891 *efuse_addr
= efuse_get_current_size(hw
);
893 *efuse_addr
= *efuse_addr
+
894 (tmp_word_cnts
* 2) + 1;
897 *efuse_addr
= *efuse_addr
+ (tmp_word_cnts
* 2) + 1;
900 *write_state
= PG_STATE_HEADER
;
902 if (*repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
907 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
908 "efuse PG_STATE_HEADER-2\n");
912 static int efuse_pg_packet_write(struct ieee80211_hw
*hw
,
913 u8 offset
, u8 word_en
, u8
*data
)
915 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
916 struct pgpkt_struct target_pkt
;
917 u8 write_state
= PG_STATE_HEADER
;
918 int continual
= true, result
= true;
921 u8 target_word_cnts
= 0;
923 static int repeat_times
;
925 if (efuse_get_current_size(hw
) >= (EFUSE_MAX_SIZE
-
926 rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
])) {
927 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
928 "efuse_pg_packet_write error\n");
932 target_pkt
.offset
= offset
;
933 target_pkt
.word_en
= word_en
;
935 memset(target_pkt
.data
, 0xFF, 8 * sizeof(u8
));
937 efuse_word_enable_data_read(word_en
, data
, target_pkt
.data
);
938 target_word_cnts
= efuse_calculate_word_cnts(target_pkt
.word_en
);
940 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
, "efuse Power ON\n");
942 while (continual
&& (efuse_addr
< (EFUSE_MAX_SIZE
-
943 rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
]))) {
944 if (write_state
== PG_STATE_HEADER
) {
946 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
947 "efuse PG_STATE_HEADER\n");
949 if (efuse_one_byte_read(hw
, efuse_addr
, &efuse_data
) &&
950 (efuse_data
!= 0xFF))
951 efuse_write_data_case1(hw
, &efuse_addr
,
956 &repeat_times
, &result
,
959 efuse_write_data_case2(hw
, &efuse_addr
,
966 } else if (write_state
== PG_STATE_DATA
) {
967 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
968 "efuse PG_STATE_DATA\n");
970 enable_efuse_data_write(hw
, efuse_addr
+ 1,
974 if ((badworden
& 0x0F) == 0x0F) {
978 efuse_addr
+ (2 * target_word_cnts
) + 1;
980 target_pkt
.offset
= offset
;
981 target_pkt
.word_en
= badworden
;
983 efuse_calculate_word_cnts(target_pkt
.
985 write_state
= PG_STATE_HEADER
;
987 if (repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
991 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
992 "efuse PG_STATE_HEADER-3\n");
997 if (efuse_addr
>= (EFUSE_MAX_SIZE
-
998 rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
])) {
999 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
1000 "efuse_addr(%#x) Out of size!!\n", efuse_addr
);
1006 static void efuse_word_enable_data_read(u8 word_en
, u8
*sourdata
,
1009 if (!(word_en
& BIT(0))) {
1010 targetdata
[0] = sourdata
[0];
1011 targetdata
[1] = sourdata
[1];
1014 if (!(word_en
& BIT(1))) {
1015 targetdata
[2] = sourdata
[2];
1016 targetdata
[3] = sourdata
[3];
1019 if (!(word_en
& BIT(2))) {
1020 targetdata
[4] = sourdata
[4];
1021 targetdata
[5] = sourdata
[5];
1024 if (!(word_en
& BIT(3))) {
1025 targetdata
[6] = sourdata
[6];
1026 targetdata
[7] = sourdata
[7];
1030 static u8
enable_efuse_data_write(struct ieee80211_hw
*hw
,
1031 u16 efuse_addr
, u8 word_en
, u8
*data
)
1033 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1035 u16 start_addr
= efuse_addr
;
1036 u8 badworden
= 0x0F;
1039 memset(tmpdata
, 0xff, PGPKT_DATA_SIZE
);
1040 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
1041 "word_en = %x efuse_addr=%x\n", word_en
, efuse_addr
);
1043 if (!(word_en
& BIT(0))) {
1044 tmpaddr
= start_addr
;
1045 efuse_one_byte_write(hw
, start_addr
++, data
[0]);
1046 efuse_one_byte_write(hw
, start_addr
++, data
[1]);
1048 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[0]);
1049 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[1]);
1050 if ((data
[0] != tmpdata
[0]) || (data
[1] != tmpdata
[1]))
1051 badworden
&= (~BIT(0));
1054 if (!(word_en
& BIT(1))) {
1055 tmpaddr
= start_addr
;
1056 efuse_one_byte_write(hw
, start_addr
++, data
[2]);
1057 efuse_one_byte_write(hw
, start_addr
++, data
[3]);
1059 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[2]);
1060 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[3]);
1061 if ((data
[2] != tmpdata
[2]) || (data
[3] != tmpdata
[3]))
1062 badworden
&= (~BIT(1));
1065 if (!(word_en
& BIT(2))) {
1066 tmpaddr
= start_addr
;
1067 efuse_one_byte_write(hw
, start_addr
++, data
[4]);
1068 efuse_one_byte_write(hw
, start_addr
++, data
[5]);
1070 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[4]);
1071 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[5]);
1072 if ((data
[4] != tmpdata
[4]) || (data
[5] != tmpdata
[5]))
1073 badworden
&= (~BIT(2));
1076 if (!(word_en
& BIT(3))) {
1077 tmpaddr
= start_addr
;
1078 efuse_one_byte_write(hw
, start_addr
++, data
[6]);
1079 efuse_one_byte_write(hw
, start_addr
++, data
[7]);
1081 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[6]);
1082 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[7]);
1083 if ((data
[6] != tmpdata
[6]) || (data
[7] != tmpdata
[7]))
1084 badworden
&= (~BIT(3));
1090 void efuse_power_switch(struct ieee80211_hw
*hw
, u8 write
, u8 pwrstate
)
1092 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1093 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1097 if (pwrstate
&& (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192SE
)) {
1098 if (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192CE
&&
1099 rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192DE
) {
1100 rtl_write_byte(rtlpriv
,
1101 rtlpriv
->cfg
->maps
[EFUSE_ACCESS
], 0x69);
1104 rtl_read_word(rtlpriv
,
1105 rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
]);
1106 if (!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_PWC_EV12V
])) {
1107 tmpv16
|= rtlpriv
->cfg
->maps
[EFUSE_PWC_EV12V
];
1108 rtl_write_word(rtlpriv
,
1109 rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
],
1113 tmpv16
= rtl_read_word(rtlpriv
,
1114 rtlpriv
->cfg
->maps
[SYS_FUNC_EN
]);
1115 if (!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_FEN_ELDR
])) {
1116 tmpv16
|= rtlpriv
->cfg
->maps
[EFUSE_FEN_ELDR
];
1117 rtl_write_word(rtlpriv
,
1118 rtlpriv
->cfg
->maps
[SYS_FUNC_EN
], tmpv16
);
1121 tmpv16
= rtl_read_word(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_CLK
]);
1122 if ((!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_LOADER_CLK_EN
])) ||
1123 (!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_ANA8M
]))) {
1124 tmpv16
|= (rtlpriv
->cfg
->maps
[EFUSE_LOADER_CLK_EN
] |
1125 rtlpriv
->cfg
->maps
[EFUSE_ANA8M
]);
1126 rtl_write_word(rtlpriv
,
1127 rtlpriv
->cfg
->maps
[SYS_CLK
], tmpv16
);
1133 tempval
= rtl_read_byte(rtlpriv
,
1134 rtlpriv
->cfg
->maps
[EFUSE_TEST
] +
1137 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
1138 tempval
&= ~(BIT(3) | BIT(4) | BIT(5) | BIT(6));
1139 tempval
|= (VOLTAGE_V25
<< 3);
1140 } else if (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192SE
) {
1142 tempval
|= (VOLTAGE_V25
<< 4);
1145 rtl_write_byte(rtlpriv
,
1146 rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3,
1150 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8192SE
) {
1151 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CLK
],
1155 if (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192CE
&&
1156 rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192DE
)
1157 rtl_write_byte(rtlpriv
,
1158 rtlpriv
->cfg
->maps
[EFUSE_ACCESS
], 0);
1161 tempval
= rtl_read_byte(rtlpriv
,
1162 rtlpriv
->cfg
->maps
[EFUSE_TEST
] +
1164 rtl_write_byte(rtlpriv
,
1165 rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3,
1169 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8192SE
) {
1170 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CLK
],
1175 EXPORT_SYMBOL(efuse_power_switch
);
1177 static u16
efuse_get_current_size(struct ieee80211_hw
*hw
)
1179 int continual
= true;
1182 u8 efuse_data
, word_cnts
;
1184 while (continual
&& efuse_one_byte_read(hw
, efuse_addr
, &efuse_data
) &&
1185 (efuse_addr
< EFUSE_MAX_SIZE
)) {
1186 if (efuse_data
!= 0xFF) {
1187 hworden
= efuse_data
& 0x0F;
1188 word_cnts
= efuse_calculate_word_cnts(hworden
);
1189 efuse_addr
= efuse_addr
+ (word_cnts
* 2) + 1;
1198 static u8
efuse_calculate_word_cnts(u8 word_en
)
1202 if (!(word_en
& BIT(0)))
1204 if (!(word_en
& BIT(1)))
1206 if (!(word_en
& BIT(2)))
1208 if (!(word_en
& BIT(3)))
1213 int rtl_get_hwinfo(struct ieee80211_hw
*hw
, struct rtl_priv
*rtlpriv
,
1214 int max_size
, u8
*hwinfo
, int *params
)
1216 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1217 struct rtl_pci_priv
*rtlpcipriv
= rtl_pcipriv(hw
);
1218 struct device
*dev
= &rtlpcipriv
->dev
.pdev
->dev
;
1222 switch (rtlefuse
->epromtype
) {
1223 case EEPROM_BOOT_EFUSE
:
1224 rtl_efuse_shadow_map_update(hw
);
1228 pr_err("RTL8XXX did not boot from eeprom, check it !!\n");
1232 dev_warn(dev
, "no efuse data\n");
1236 memcpy(hwinfo
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0], max_size
);
1238 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
, "MAP",
1241 eeprom_id
= *((u16
*)&hwinfo
[0]);
1242 if (eeprom_id
!= params
[0]) {
1243 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1244 "EEPROM ID(%#x) is invalid!!\n", eeprom_id
);
1245 rtlefuse
->autoload_failflag
= true;
1247 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1248 rtlefuse
->autoload_failflag
= false;
1251 if (rtlefuse
->autoload_failflag
)
1254 rtlefuse
->eeprom_vid
= *(u16
*)&hwinfo
[params
[1]];
1255 rtlefuse
->eeprom_did
= *(u16
*)&hwinfo
[params
[2]];
1256 rtlefuse
->eeprom_svid
= *(u16
*)&hwinfo
[params
[3]];
1257 rtlefuse
->eeprom_smid
= *(u16
*)&hwinfo
[params
[4]];
1258 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1259 "EEPROMId = 0x%4x\n", eeprom_id
);
1260 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1261 "EEPROM VID = 0x%4x\n", rtlefuse
->eeprom_vid
);
1262 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1263 "EEPROM DID = 0x%4x\n", rtlefuse
->eeprom_did
);
1264 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1265 "EEPROM SVID = 0x%4x\n", rtlefuse
->eeprom_svid
);
1266 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1267 "EEPROM SMID = 0x%4x\n", rtlefuse
->eeprom_smid
);
1269 for (i
= 0; i
< 6; i
+= 2) {
1270 usvalue
= *(u16
*)&hwinfo
[params
[5] + i
];
1271 *((u16
*)(&rtlefuse
->dev_addr
[i
])) = usvalue
;
1273 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "%pM\n", rtlefuse
->dev_addr
);
1275 rtlefuse
->eeprom_channelplan
= *&hwinfo
[params
[6]];
1276 rtlefuse
->eeprom_version
= *(u16
*)&hwinfo
[params
[7]];
1277 rtlefuse
->txpwr_fromeprom
= true;
1278 rtlefuse
->eeprom_oemid
= *&hwinfo
[params
[8]];
1280 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1281 "EEPROM Customer ID: 0x%2x\n", rtlefuse
->eeprom_oemid
);
1283 /* set channel plan to world wide 13 */
1284 rtlefuse
->channel_plan
= params
[9];
1288 EXPORT_SYMBOL_GPL(rtl_get_hwinfo
);
1290 void rtl_fw_block_write(struct ieee80211_hw
*hw
, const u8
*buffer
, u32 size
)
1292 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1293 u8
*pu4byteptr
= (u8
*)buffer
;
1296 for (i
= 0; i
< size
; i
++)
1297 rtl_write_byte(rtlpriv
, (START_ADDRESS
+ i
), *(pu4byteptr
+ i
));
1299 EXPORT_SYMBOL_GPL(rtl_fw_block_write
);
1301 void rtl_fw_page_write(struct ieee80211_hw
*hw
, u32 page
, const u8
*buffer
,
1304 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1306 u8 u8page
= (u8
)(page
& 0x07);
1308 value8
= (rtl_read_byte(rtlpriv
, REG_MCUFWDL
+ 2) & 0xF8) | u8page
;
1310 rtl_write_byte(rtlpriv
, (REG_MCUFWDL
+ 2), value8
);
1311 rtl_fw_block_write(hw
, buffer
, size
);
1313 EXPORT_SYMBOL_GPL(rtl_fw_page_write
);
1315 void rtl_fill_dummy(u8
*pfwbuf
, u32
*pfwlen
)
1317 u32 fwlen
= *pfwlen
;
1318 u8 remain
= (u8
)(fwlen
% 4);
1320 remain
= (remain
== 0) ? 0 : (4 - remain
);
1322 while (remain
> 0) {
1330 EXPORT_SYMBOL_GPL(rtl_fill_dummy
);
1332 void rtl_efuse_ops_init(struct ieee80211_hw
*hw
)
1334 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1336 rtlpriv
->efuse
.efuse_ops
= &efuse_ops
;
1338 EXPORT_SYMBOL_GPL(rtl_efuse_ops_init
);