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
= kzalloc(EFUSE_MAX_WORD_UNIT
* sizeof(u16
*), GFP_ATOMIC
);
258 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++) {
259 efuse_word
[i
] = kzalloc(efuse_max_section
* sizeof(u16
),
265 for (i
= 0; i
< efuse_max_section
; i
++)
266 for (j
= 0; j
< EFUSE_MAX_WORD_UNIT
; j
++)
267 efuse_word
[j
][i
] = 0xFFFF;
269 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
270 if (*rtemp8
!= 0xFF) {
272 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_READ_ALL
,
273 "Addr=%d\n", efuse_addr
);
277 while ((*rtemp8
!= 0xFF) && (efuse_addr
< efuse_len
)) {
278 /* Check PG header for section num. */
279 if ((*rtemp8
& 0x1F) == 0x0F) {/* extended header */
280 u1temp
= ((*rtemp8
& 0xE0) >> 5);
281 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
283 if ((*rtemp8
& 0x0F) == 0x0F) {
285 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
287 if (*rtemp8
!= 0xFF &&
288 (efuse_addr
< efuse_len
)) {
293 offset
= ((*rtemp8
& 0xF0) >> 1) | u1temp
;
294 wren
= (*rtemp8
& 0x0F);
298 offset
= ((*rtemp8
>> 4) & 0x0f);
299 wren
= (*rtemp8
& 0x0f);
302 if (offset
< efuse_max_section
) {
303 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_READ_ALL
,
304 "offset-%d Worden=%x\n", offset
, wren
);
306 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++) {
307 if (!(wren
& 0x01)) {
308 RTPRINT(rtlpriv
, FEEPROM
,
310 "Addr=%d\n", efuse_addr
);
312 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
315 efuse_word
[i
][offset
] =
318 if (efuse_addr
>= efuse_len
)
321 RTPRINT(rtlpriv
, FEEPROM
,
323 "Addr=%d\n", efuse_addr
);
325 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
328 efuse_word
[i
][offset
] |=
329 (((u16
)*rtemp8
<< 8) & 0xff00);
331 if (efuse_addr
>= efuse_len
)
339 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_READ_ALL
,
340 "Addr=%d\n", efuse_addr
);
341 read_efuse_byte(hw
, efuse_addr
, rtemp8
);
342 if (*rtemp8
!= 0xFF && (efuse_addr
< efuse_len
)) {
348 for (i
= 0; i
< efuse_max_section
; i
++) {
349 for (j
= 0; j
< EFUSE_MAX_WORD_UNIT
; j
++) {
350 efuse_tbl
[(i
* 8) + (j
* 2)] =
351 (efuse_word
[j
][i
] & 0xff);
352 efuse_tbl
[(i
* 8) + ((j
* 2) + 1)] =
353 ((efuse_word
[j
][i
] >> 8) & 0xff);
357 for (i
= 0; i
< _size_byte
; i
++)
358 pbuf
[i
] = efuse_tbl
[_offset
+ i
];
360 rtlefuse
->efuse_usedbytes
= efuse_utilized
;
361 efuse_usage
= (u8
)((efuse_utilized
* 100) / efuse_len
);
362 rtlefuse
->efuse_usedpercentage
= efuse_usage
;
363 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_EFUSE_BYTES
,
364 (u8
*)&efuse_utilized
);
365 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_EFUSE_USAGE
,
368 for (i
= 0; i
< EFUSE_MAX_WORD_UNIT
; i
++)
369 kfree(efuse_word
[i
]);
375 bool efuse_shadow_update_chk(struct ieee80211_hw
*hw
)
377 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
378 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
379 u8 section_idx
, i
, base
;
380 u16 words_need
= 0, hdr_num
= 0, totalbytes
, efuse_used
;
381 bool wordchanged
, result
= true;
383 for (section_idx
= 0; section_idx
< 16; section_idx
++) {
384 base
= section_idx
* 8;
387 for (i
= 0; i
< 8; i
= i
+ 2) {
388 if ((rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] !=
389 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
]) ||
390 (rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
+ 1] !=
391 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
+
402 totalbytes
= hdr_num
+ words_need
* 2;
403 efuse_used
= rtlefuse
->efuse_usedbytes
;
405 if ((totalbytes
+ efuse_used
) >=
406 (EFUSE_MAX_SIZE
- rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
]))
409 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
410 "%s(): totalbytes(%#x), hdr_num(%#x), words_need(%#x), efuse_used(%d)\n",
411 __func__
, totalbytes
, hdr_num
, words_need
, efuse_used
);
416 void efuse_shadow_read(struct ieee80211_hw
*hw
, u8 type
,
417 u16 offset
, u32
*value
)
420 efuse_shadow_read_1byte(hw
, offset
, (u8
*)value
);
422 efuse_shadow_read_2byte(hw
, offset
, (u16
*)value
);
424 efuse_shadow_read_4byte(hw
, offset
, value
);
427 void efuse_shadow_write(struct ieee80211_hw
*hw
, u8 type
, u16 offset
,
431 efuse_shadow_write_1byte(hw
, offset
, (u8
)value
);
433 efuse_shadow_write_2byte(hw
, offset
, (u16
)value
);
435 efuse_shadow_write_4byte(hw
, offset
, value
);
438 bool efuse_shadow_update(struct ieee80211_hw
*hw
)
440 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
441 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
446 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
, "\n");
448 if (!efuse_shadow_update_chk(hw
)) {
449 efuse_read_all_map(hw
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]);
450 memcpy(&rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][0],
451 &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
452 rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
454 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
455 "efuse out of capacity!!\n");
458 efuse_power_switch(hw
, true, true);
460 for (offset
= 0; offset
< 16; offset
++) {
464 for (i
= 0; i
< 8; i
++) {
466 word_en
&= ~(BIT(i
/ 2));
468 rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] =
469 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
];
471 if (rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] !=
472 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
]) {
473 word_en
&= ~(BIT(i
/ 2));
475 rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][base
+ i
] =
476 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
+ i
];
480 if (word_en
!= 0x0F) {
484 &rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][base
],
486 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_LOUD
,
487 "U-efuse\n", tmpdata
, 8);
489 if (!efuse_pg_packet_write(hw
, (u8
)offset
, word_en
,
491 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
492 "PG section(%#x) fail!!\n", offset
);
498 efuse_power_switch(hw
, true, false);
499 efuse_read_all_map(hw
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]);
501 memcpy(&rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][0],
502 &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
503 rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
505 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
, "\n");
509 void rtl_efuse_shadow_map_update(struct ieee80211_hw
*hw
)
511 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
512 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
514 if (rtlefuse
->autoload_failflag
)
515 memset((&rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]),
516 0xFF, rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
518 efuse_read_all_map(hw
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0]);
520 memcpy(&rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][0],
521 &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
522 rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
]);
525 void efuse_force_write_vendor_id(struct ieee80211_hw
*hw
)
527 u8 tmpdata
[8] = { 0xFF, 0xFF, 0xEC, 0x10, 0xFF, 0xFF, 0xFF, 0xFF };
529 efuse_power_switch(hw
, true, true);
531 efuse_pg_packet_write(hw
, 1, 0xD, tmpdata
);
533 efuse_power_switch(hw
, true, false);
536 void efuse_re_pg_section(struct ieee80211_hw
*hw
, u8 section_idx
)
540 static void efuse_shadow_read_1byte(struct ieee80211_hw
*hw
,
541 u16 offset
, u8
*value
)
543 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
544 *value
= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
];
547 static void efuse_shadow_read_2byte(struct ieee80211_hw
*hw
,
548 u16 offset
, u16
*value
)
550 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
552 *value
= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
];
553 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] << 8;
556 static void efuse_shadow_read_4byte(struct ieee80211_hw
*hw
,
557 u16 offset
, u32
*value
)
559 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
561 *value
= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
];
562 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] << 8;
563 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 2] << 16;
564 *value
|= rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 3] << 24;
567 static void efuse_shadow_write_1byte(struct ieee80211_hw
*hw
,
568 u16 offset
, u8 value
)
570 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
572 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
] = value
;
575 static void efuse_shadow_write_2byte(struct ieee80211_hw
*hw
,
576 u16 offset
, u16 value
)
578 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
580 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
] = value
& 0x00FF;
581 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] = value
>> 8;
584 static void efuse_shadow_write_4byte(struct ieee80211_hw
*hw
,
585 u16 offset
, u32 value
)
587 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
589 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
] =
590 (u8
)(value
& 0x000000FF);
591 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 1] =
592 (u8
)((value
>> 8) & 0x0000FF);
593 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 2] =
594 (u8
)((value
>> 16) & 0x00FF);
595 rtlefuse
->efuse_map
[EFUSE_MODIFY_MAP
][offset
+ 3] =
596 (u8
)((value
>> 24) & 0xFF);
599 int efuse_one_byte_read(struct ieee80211_hw
*hw
, u16 addr
, u8
*data
)
601 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
605 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1,
607 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
608 ((u8
)((addr
>> 8) & 0x03)) |
609 (rtl_read_byte(rtlpriv
,
610 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2) &
613 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, 0x72);
615 while (!(0x80 & rtl_read_byte(rtlpriv
,
616 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3)) &&
622 *data
= rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
]);
631 static int efuse_one_byte_write(struct ieee80211_hw
*hw
, u16 addr
, u8 data
)
633 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
636 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
637 "Addr = %x Data=%x\n", addr
, data
);
639 rtl_write_byte(rtlpriv
,
640 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 1, (u8
)(addr
& 0xff));
641 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 2,
642 (rtl_read_byte(rtlpriv
,
643 rtlpriv
->cfg
->maps
[EFUSE_CTRL
] +
644 2) & 0xFC) | (u8
)((addr
>> 8) & 0x03));
646 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
], data
);
647 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3, 0xF2);
650 rtl_read_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CTRL
] + 3)) &&
660 static void efuse_read_all_map(struct ieee80211_hw
*hw
, u8
*efuse
)
662 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
664 efuse_power_switch(hw
, false, true);
665 read_efuse(hw
, 0, rtlpriv
->cfg
->maps
[EFUSE_HWSET_MAX_SIZE
], efuse
);
666 efuse_power_switch(hw
, false, false);
669 static void efuse_read_data_case1(struct ieee80211_hw
*hw
, u16
*efuse_addr
,
670 u8 efuse_data
, u8 offset
, u8
*tmpdata
,
673 bool dataempty
= true;
679 hoffset
= (efuse_data
>> 4) & 0x0F;
680 hworden
= efuse_data
& 0x0F;
681 word_cnts
= efuse_calculate_word_cnts(hworden
);
683 if (hoffset
== offset
) {
684 for (tmpidx
= 0; tmpidx
< word_cnts
* 2; tmpidx
++) {
685 if (efuse_one_byte_read(hw
, *efuse_addr
+ 1 + tmpidx
,
687 tmpdata
[tmpidx
] = efuse_data
;
688 if (efuse_data
!= 0xff)
694 *readstate
= PG_STATE_DATA
;
696 *efuse_addr
= *efuse_addr
+ (word_cnts
* 2) + 1;
697 *readstate
= PG_STATE_HEADER
;
701 *efuse_addr
= *efuse_addr
+ (word_cnts
* 2) + 1;
702 *readstate
= PG_STATE_HEADER
;
706 static int efuse_pg_packet_read(struct ieee80211_hw
*hw
, u8 offset
, u8
*data
)
708 u8 readstate
= PG_STATE_HEADER
;
710 bool continual
= true;
712 u8 efuse_data
, word_cnts
= 0;
721 memset(data
, 0xff, PGPKT_DATA_SIZE
* sizeof(u8
));
722 memset(tmpdata
, 0xff, PGPKT_DATA_SIZE
* sizeof(u8
));
724 while (continual
&& (efuse_addr
< EFUSE_MAX_SIZE
)) {
725 if (readstate
& PG_STATE_HEADER
) {
726 if (efuse_one_byte_read(hw
, efuse_addr
, &efuse_data
) &&
727 (efuse_data
!= 0xFF))
728 efuse_read_data_case1(hw
, &efuse_addr
,
730 tmpdata
, &readstate
);
733 } else if (readstate
& PG_STATE_DATA
) {
734 efuse_word_enable_data_read(0, tmpdata
, data
);
735 efuse_addr
= efuse_addr
+ (word_cnts
* 2) + 1;
736 readstate
= PG_STATE_HEADER
;
740 if ((data
[0] == 0xff) && (data
[1] == 0xff) &&
741 (data
[2] == 0xff) && (data
[3] == 0xff) &&
742 (data
[4] == 0xff) && (data
[5] == 0xff) &&
743 (data
[6] == 0xff) && (data
[7] == 0xff))
748 static void efuse_write_data_case1(struct ieee80211_hw
*hw
, u16
*efuse_addr
,
749 u8 efuse_data
, u8 offset
,
750 int *continual
, u8
*write_state
,
751 struct pgpkt_struct
*target_pkt
,
752 int *repeat_times
, int *result
, u8 word_en
)
754 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
755 struct pgpkt_struct tmp_pkt
;
756 int dataempty
= true;
757 u8 originaldata
[8 * sizeof(u8
)];
759 u8 match_word_en
, tmp_word_en
;
761 u8 tmp_header
= efuse_data
;
764 tmp_pkt
.offset
= (tmp_header
>> 4) & 0x0F;
765 tmp_pkt
.word_en
= tmp_header
& 0x0F;
766 tmp_word_cnts
= efuse_calculate_word_cnts(tmp_pkt
.word_en
);
768 if (tmp_pkt
.offset
!= target_pkt
->offset
) {
769 *efuse_addr
= *efuse_addr
+ (tmp_word_cnts
* 2) + 1;
770 *write_state
= PG_STATE_HEADER
;
772 for (tmpindex
= 0; tmpindex
< (tmp_word_cnts
* 2); tmpindex
++) {
773 if (efuse_one_byte_read(hw
,
774 (*efuse_addr
+ 1 + tmpindex
),
776 (efuse_data
!= 0xFF))
781 *efuse_addr
= *efuse_addr
+ (tmp_word_cnts
* 2) + 1;
782 *write_state
= PG_STATE_HEADER
;
784 match_word_en
= 0x0F;
785 if (!((target_pkt
->word_en
& BIT(0)) |
786 (tmp_pkt
.word_en
& BIT(0))))
787 match_word_en
&= (~BIT(0));
789 if (!((target_pkt
->word_en
& BIT(1)) |
790 (tmp_pkt
.word_en
& BIT(1))))
791 match_word_en
&= (~BIT(1));
793 if (!((target_pkt
->word_en
& BIT(2)) |
794 (tmp_pkt
.word_en
& BIT(2))))
795 match_word_en
&= (~BIT(2));
797 if (!((target_pkt
->word_en
& BIT(3)) |
798 (tmp_pkt
.word_en
& BIT(3))))
799 match_word_en
&= (~BIT(3));
801 if ((match_word_en
& 0x0F) != 0x0F) {
803 enable_efuse_data_write(hw
,
808 if (0x0F != (badworden
& 0x0F)) {
809 u8 reorg_offset
= offset
;
810 u8 reorg_worden
= badworden
;
812 efuse_pg_packet_write(hw
, reorg_offset
,
818 if ((target_pkt
->word_en
& BIT(0)) ^
819 (match_word_en
& BIT(0)))
820 tmp_word_en
&= (~BIT(0));
822 if ((target_pkt
->word_en
& BIT(1)) ^
823 (match_word_en
& BIT(1)))
824 tmp_word_en
&= (~BIT(1));
826 if ((target_pkt
->word_en
& BIT(2)) ^
827 (match_word_en
& BIT(2)))
828 tmp_word_en
&= (~BIT(2));
830 if ((target_pkt
->word_en
& BIT(3)) ^
831 (match_word_en
& BIT(3)))
832 tmp_word_en
&= (~BIT(3));
834 if ((tmp_word_en
& 0x0F) != 0x0F) {
836 efuse_get_current_size(hw
);
837 target_pkt
->offset
= offset
;
838 target_pkt
->word_en
= tmp_word_en
;
842 *write_state
= PG_STATE_HEADER
;
844 if (*repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
849 *efuse_addr
+= (2 * tmp_word_cnts
) + 1;
850 target_pkt
->offset
= offset
;
851 target_pkt
->word_en
= word_en
;
852 *write_state
= PG_STATE_HEADER
;
856 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
, "efuse PG_STATE_HEADER-1\n");
859 static void efuse_write_data_case2(struct ieee80211_hw
*hw
, u16
*efuse_addr
,
860 int *continual
, u8
*write_state
,
861 struct pgpkt_struct target_pkt
,
862 int *repeat_times
, int *result
)
864 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
865 struct pgpkt_struct tmp_pkt
;
868 u8 originaldata
[8 * sizeof(u8
)];
872 pg_header
= ((target_pkt
.offset
<< 4) & 0xf0) | target_pkt
.word_en
;
873 efuse_one_byte_write(hw
, *efuse_addr
, pg_header
);
874 efuse_one_byte_read(hw
, *efuse_addr
, &tmp_header
);
876 if (tmp_header
== pg_header
) {
877 *write_state
= PG_STATE_DATA
;
878 } else if (tmp_header
== 0xFF) {
879 *write_state
= PG_STATE_HEADER
;
881 if (*repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
886 tmp_pkt
.offset
= (tmp_header
>> 4) & 0x0F;
887 tmp_pkt
.word_en
= tmp_header
& 0x0F;
889 tmp_word_cnts
= efuse_calculate_word_cnts(tmp_pkt
.word_en
);
891 memset(originaldata
, 0xff, 8 * sizeof(u8
));
893 if (efuse_pg_packet_read(hw
, tmp_pkt
.offset
, originaldata
)) {
894 badworden
= enable_efuse_data_write(hw
,
899 if (0x0F != (badworden
& 0x0F)) {
900 u8 reorg_offset
= tmp_pkt
.offset
;
901 u8 reorg_worden
= badworden
;
903 efuse_pg_packet_write(hw
, reorg_offset
,
906 *efuse_addr
= efuse_get_current_size(hw
);
908 *efuse_addr
= *efuse_addr
+
909 (tmp_word_cnts
* 2) + 1;
912 *efuse_addr
= *efuse_addr
+ (tmp_word_cnts
* 2) + 1;
915 *write_state
= PG_STATE_HEADER
;
917 if (*repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
922 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
923 "efuse PG_STATE_HEADER-2\n");
927 static int efuse_pg_packet_write(struct ieee80211_hw
*hw
,
928 u8 offset
, u8 word_en
, u8
*data
)
930 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
931 struct pgpkt_struct target_pkt
;
932 u8 write_state
= PG_STATE_HEADER
;
933 int continual
= true, dataempty
= true, result
= true;
936 u8 target_word_cnts
= 0;
938 static int repeat_times
;
940 if (efuse_get_current_size(hw
) >= (EFUSE_MAX_SIZE
-
941 rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
])) {
942 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
943 "%s error\n", __func__
);
947 target_pkt
.offset
= offset
;
948 target_pkt
.word_en
= word_en
;
950 memset(target_pkt
.data
, 0xFF, 8 * sizeof(u8
));
952 efuse_word_enable_data_read(word_en
, data
, target_pkt
.data
);
953 target_word_cnts
= efuse_calculate_word_cnts(target_pkt
.word_en
);
955 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
, "efuse Power ON\n");
957 while (continual
&& (efuse_addr
< (EFUSE_MAX_SIZE
-
958 rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
]))) {
959 if (write_state
== PG_STATE_HEADER
) {
962 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
963 "efuse PG_STATE_HEADER\n");
965 if (efuse_one_byte_read(hw
, efuse_addr
, &efuse_data
) &&
966 (efuse_data
!= 0xFF))
967 efuse_write_data_case1(hw
, &efuse_addr
,
972 &repeat_times
, &result
,
975 efuse_write_data_case2(hw
, &efuse_addr
,
982 } else if (write_state
== PG_STATE_DATA
) {
983 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
984 "efuse PG_STATE_DATA\n");
987 enable_efuse_data_write(hw
, efuse_addr
+ 1,
991 if ((badworden
& 0x0F) == 0x0F) {
995 efuse_addr
+ (2 * target_word_cnts
) + 1;
997 target_pkt
.offset
= offset
;
998 target_pkt
.word_en
= badworden
;
1000 efuse_calculate_word_cnts(target_pkt
.word_en
);
1001 write_state
= PG_STATE_HEADER
;
1003 if (repeat_times
> EFUSE_REPEAT_THRESHOLD_
) {
1007 RTPRINT(rtlpriv
, FEEPROM
, EFUSE_PG
,
1008 "efuse PG_STATE_HEADER-3\n");
1013 if (efuse_addr
>= (EFUSE_MAX_SIZE
-
1014 rtlpriv
->cfg
->maps
[EFUSE_OOB_PROTECT_BYTES_LEN
])) {
1015 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
1016 "efuse_addr(%#x) Out of size!!\n", efuse_addr
);
1022 static void efuse_word_enable_data_read(u8 word_en
, u8
*sourdata
,
1025 if (!(word_en
& BIT(0))) {
1026 targetdata
[0] = sourdata
[0];
1027 targetdata
[1] = sourdata
[1];
1030 if (!(word_en
& BIT(1))) {
1031 targetdata
[2] = sourdata
[2];
1032 targetdata
[3] = sourdata
[3];
1035 if (!(word_en
& BIT(2))) {
1036 targetdata
[4] = sourdata
[4];
1037 targetdata
[5] = sourdata
[5];
1040 if (!(word_en
& BIT(3))) {
1041 targetdata
[6] = sourdata
[6];
1042 targetdata
[7] = sourdata
[7];
1046 static u8
enable_efuse_data_write(struct ieee80211_hw
*hw
,
1047 u16 efuse_addr
, u8 word_en
, u8
*data
)
1049 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1051 u16 start_addr
= efuse_addr
;
1052 u8 badworden
= 0x0F;
1055 memset(tmpdata
, 0xff, PGPKT_DATA_SIZE
);
1056 RT_TRACE(rtlpriv
, COMP_EFUSE
, DBG_LOUD
,
1057 "word_en = %x efuse_addr=%x\n", word_en
, efuse_addr
);
1059 if (!(word_en
& BIT(0))) {
1060 tmpaddr
= start_addr
;
1061 efuse_one_byte_write(hw
, start_addr
++, data
[0]);
1062 efuse_one_byte_write(hw
, start_addr
++, data
[1]);
1064 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[0]);
1065 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[1]);
1066 if ((data
[0] != tmpdata
[0]) || (data
[1] != tmpdata
[1]))
1067 badworden
&= (~BIT(0));
1070 if (!(word_en
& BIT(1))) {
1071 tmpaddr
= start_addr
;
1072 efuse_one_byte_write(hw
, start_addr
++, data
[2]);
1073 efuse_one_byte_write(hw
, start_addr
++, data
[3]);
1075 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[2]);
1076 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[3]);
1077 if ((data
[2] != tmpdata
[2]) || (data
[3] != tmpdata
[3]))
1078 badworden
&= (~BIT(1));
1081 if (!(word_en
& BIT(2))) {
1082 tmpaddr
= start_addr
;
1083 efuse_one_byte_write(hw
, start_addr
++, data
[4]);
1084 efuse_one_byte_write(hw
, start_addr
++, data
[5]);
1086 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[4]);
1087 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[5]);
1088 if ((data
[4] != tmpdata
[4]) || (data
[5] != tmpdata
[5]))
1089 badworden
&= (~BIT(2));
1092 if (!(word_en
& BIT(3))) {
1093 tmpaddr
= start_addr
;
1094 efuse_one_byte_write(hw
, start_addr
++, data
[6]);
1095 efuse_one_byte_write(hw
, start_addr
++, data
[7]);
1097 efuse_one_byte_read(hw
, tmpaddr
, &tmpdata
[6]);
1098 efuse_one_byte_read(hw
, tmpaddr
+ 1, &tmpdata
[7]);
1099 if ((data
[6] != tmpdata
[6]) || (data
[7] != tmpdata
[7]))
1100 badworden
&= (~BIT(3));
1106 void efuse_power_switch(struct ieee80211_hw
*hw
, u8 write
, u8 pwrstate
)
1108 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1109 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1113 if (pwrstate
&& (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192SE
)) {
1114 if (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192CE
&&
1115 rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192DE
) {
1116 rtl_write_byte(rtlpriv
,
1117 rtlpriv
->cfg
->maps
[EFUSE_ACCESS
], 0x69);
1120 rtl_read_word(rtlpriv
,
1121 rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
]);
1122 if (!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_PWC_EV12V
])) {
1123 tmpv16
|= rtlpriv
->cfg
->maps
[EFUSE_PWC_EV12V
];
1124 rtl_write_word(rtlpriv
,
1125 rtlpriv
->cfg
->maps
[SYS_ISO_CTRL
],
1129 tmpv16
= rtl_read_word(rtlpriv
,
1130 rtlpriv
->cfg
->maps
[SYS_FUNC_EN
]);
1131 if (!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_FEN_ELDR
])) {
1132 tmpv16
|= rtlpriv
->cfg
->maps
[EFUSE_FEN_ELDR
];
1133 rtl_write_word(rtlpriv
,
1134 rtlpriv
->cfg
->maps
[SYS_FUNC_EN
], tmpv16
);
1137 tmpv16
= rtl_read_word(rtlpriv
, rtlpriv
->cfg
->maps
[SYS_CLK
]);
1138 if ((!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_LOADER_CLK_EN
])) ||
1139 (!(tmpv16
& rtlpriv
->cfg
->maps
[EFUSE_ANA8M
]))) {
1140 tmpv16
|= (rtlpriv
->cfg
->maps
[EFUSE_LOADER_CLK_EN
] |
1141 rtlpriv
->cfg
->maps
[EFUSE_ANA8M
]);
1142 rtl_write_word(rtlpriv
,
1143 rtlpriv
->cfg
->maps
[SYS_CLK
], tmpv16
);
1149 tempval
= rtl_read_byte(rtlpriv
,
1150 rtlpriv
->cfg
->maps
[EFUSE_TEST
] +
1153 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
) {
1154 tempval
&= ~(BIT(3) | BIT(4) | BIT(5) | BIT(6));
1155 tempval
|= (VOLTAGE_V25
<< 3);
1156 } else if (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192SE
) {
1158 tempval
|= (VOLTAGE_V25
<< 4);
1161 rtl_write_byte(rtlpriv
,
1162 rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3,
1166 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8192SE
) {
1167 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CLK
],
1171 if (rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192CE
&&
1172 rtlhal
->hw_type
!= HARDWARE_TYPE_RTL8192DE
)
1173 rtl_write_byte(rtlpriv
,
1174 rtlpriv
->cfg
->maps
[EFUSE_ACCESS
], 0);
1177 tempval
= rtl_read_byte(rtlpriv
,
1178 rtlpriv
->cfg
->maps
[EFUSE_TEST
] +
1180 rtl_write_byte(rtlpriv
,
1181 rtlpriv
->cfg
->maps
[EFUSE_TEST
] + 3,
1185 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8192SE
) {
1186 rtl_write_byte(rtlpriv
, rtlpriv
->cfg
->maps
[EFUSE_CLK
],
1192 static u16
efuse_get_current_size(struct ieee80211_hw
*hw
)
1194 int continual
= true;
1196 u8 hoffset
, hworden
;
1197 u8 efuse_data
, word_cnts
;
1199 while (continual
&& efuse_one_byte_read(hw
, efuse_addr
, &efuse_data
) &&
1200 (efuse_addr
< EFUSE_MAX_SIZE
)) {
1201 if (efuse_data
!= 0xFF) {
1202 hoffset
= (efuse_data
>> 4) & 0x0F;
1203 hworden
= efuse_data
& 0x0F;
1204 word_cnts
= efuse_calculate_word_cnts(hworden
);
1205 efuse_addr
= efuse_addr
+ (word_cnts
* 2) + 1;
1214 static u8
efuse_calculate_word_cnts(u8 word_en
)
1218 if (!(word_en
& BIT(0)))
1220 if (!(word_en
& BIT(1)))
1222 if (!(word_en
& BIT(2)))
1224 if (!(word_en
& BIT(3)))
1229 int rtl_get_hwinfo(struct ieee80211_hw
*hw
, struct rtl_priv
*rtlpriv
,
1230 int max_size
, u8
*hwinfo
, int *params
)
1232 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1233 struct rtl_pci_priv
*rtlpcipriv
= rtl_pcipriv(hw
);
1234 struct device
*dev
= &rtlpcipriv
->dev
.pdev
->dev
;
1238 switch (rtlefuse
->epromtype
) {
1239 case EEPROM_BOOT_EFUSE
:
1240 rtl_efuse_shadow_map_update(hw
);
1244 pr_err("RTL8XXX did not boot from eeprom, check it !!\n");
1248 dev_warn(dev
, "no efuse data\n");
1252 memcpy(hwinfo
, &rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0], max_size
);
1254 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
, "MAP",
1257 eeprom_id
= *((u16
*)&hwinfo
[0]);
1258 if (eeprom_id
!= params
[0]) {
1259 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1260 "EEPROM ID(%#x) is invalid!!\n", eeprom_id
);
1261 rtlefuse
->autoload_failflag
= true;
1263 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
1264 rtlefuse
->autoload_failflag
= false;
1267 if (rtlefuse
->autoload_failflag
)
1270 rtlefuse
->eeprom_vid
= *(u16
*)&hwinfo
[params
[1]];
1271 rtlefuse
->eeprom_did
= *(u16
*)&hwinfo
[params
[2]];
1272 rtlefuse
->eeprom_svid
= *(u16
*)&hwinfo
[params
[3]];
1273 rtlefuse
->eeprom_smid
= *(u16
*)&hwinfo
[params
[4]];
1274 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1275 "EEPROMId = 0x%4x\n", eeprom_id
);
1276 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1277 "EEPROM VID = 0x%4x\n", rtlefuse
->eeprom_vid
);
1278 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1279 "EEPROM DID = 0x%4x\n", rtlefuse
->eeprom_did
);
1280 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1281 "EEPROM SVID = 0x%4x\n", rtlefuse
->eeprom_svid
);
1282 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1283 "EEPROM SMID = 0x%4x\n", rtlefuse
->eeprom_smid
);
1285 for (i
= 0; i
< 6; i
+= 2) {
1286 usvalue
= *(u16
*)&hwinfo
[params
[5] + i
];
1287 *((u16
*)(&rtlefuse
->dev_addr
[i
])) = usvalue
;
1289 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "%pM\n", rtlefuse
->dev_addr
);
1291 rtlefuse
->eeprom_channelplan
= *&hwinfo
[params
[6]];
1292 rtlefuse
->eeprom_version
= *(u16
*)&hwinfo
[params
[7]];
1293 rtlefuse
->txpwr_fromeprom
= true;
1294 rtlefuse
->eeprom_oemid
= *&hwinfo
[params
[8]];
1296 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1297 "EEPROM Customer ID: 0x%2x\n", rtlefuse
->eeprom_oemid
);
1299 /* set channel plan to world wide 13 */
1300 rtlefuse
->channel_plan
= params
[9];
1305 void rtl_fw_block_write(struct ieee80211_hw
*hw
, const u8
*buffer
, u32 size
)
1307 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1308 u8
*pu4byteptr
= (u8
*)buffer
;
1311 for (i
= 0; i
< size
; i
++)
1312 rtl_write_byte(rtlpriv
, (START_ADDRESS
+ i
), *(pu4byteptr
+ i
));
1315 void rtl_fw_page_write(struct ieee80211_hw
*hw
, u32 page
, const u8
*buffer
,
1318 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1320 u8 u8page
= (u8
)(page
& 0x07);
1322 value8
= (rtl_read_byte(rtlpriv
, REG_MCUFWDL
+ 2) & 0xF8) | u8page
;
1324 rtl_write_byte(rtlpriv
, (REG_MCUFWDL
+ 2), value8
);
1325 rtl_fw_block_write(hw
, buffer
, size
);
1328 void rtl_fill_dummy(u8
*pfwbuf
, u32
*pfwlen
)
1330 u32 fwlen
= *pfwlen
;
1331 u8 remain
= (u8
)(fwlen
% 4);
1333 remain
= (remain
== 0) ? 0 : (4 - remain
);
1335 while (remain
> 0) {