1 /******************************************************************************
2  *
3  * Copyright(c) 2009-2012  Realtek Corporation.
4  *
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.
8  *
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
12  * more details.
13  *
14  * The full GNU General Public License is included in this distribution in the
15  * file called LICENSE.
16  *
17  * Contact Information:
18  * wlanfae <wlanfae@realtek.com>
19  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20  * Hsinchu 300, Taiwan.
21  *
22  * Larry Finger <Larry.Finger@lwfinger.net>
23  *
24  *****************************************************************************/
25 
26 #ifndef __RTL_EFUSE_H_
27 #define __RTL_EFUSE_H_
28 
29 #define EFUSE_IC_ID_OFFSET		506
30 
31 #define EFUSE_MAX_WORD_UNIT		4
32 
33 #define EFUSE_INIT_MAP			0
34 #define EFUSE_MODIFY_MAP		1
35 
36 #define PG_STATE_HEADER			0x01
37 #define PG_STATE_WORD_0			0x02
38 #define PG_STATE_WORD_1			0x04
39 #define PG_STATE_WORD_2			0x08
40 #define PG_STATE_WORD_3			0x10
41 #define PG_STATE_DATA			0x20
42 
43 #define EFUSE_REPEAT_THRESHOLD_		3
44 #define EFUSE_ERROE_HANDLE		1
45 
46 struct efuse_map {
47 	u8 offset;
48 	u8 word_start;
49 	u8 byte_start;
50 	u8 byte_cnts;
51 };
52 
53 struct pgpkt_struct {
54 	u8 offset;
55 	u8 word_en;
56 	u8 data[8];
57 };
58 
59 enum efuse_data_item {
60 	EFUSE_CHIP_ID = 0,
61 	EFUSE_LDO_SETTING,
62 	EFUSE_CLK_SETTING,
63 	EFUSE_SDIO_SETTING,
64 	EFUSE_CCCR,
65 	EFUSE_SDIO_MODE,
66 	EFUSE_OCR,
67 	EFUSE_F0CIS,
68 	EFUSE_F1CIS,
69 	EFUSE_MAC_ADDR,
70 	EFUSE_EEPROM_VER,
71 	EFUSE_CHAN_PLAN,
72 	EFUSE_TXPW_TAB
73 };
74 
75 enum {
76 	VOLTAGE_V25 = 0x03,
77 	LDOE25_SHIFT = 28,
78 };
79 
80 struct efuse_priv {
81 	u8 id[2];
82 	u8 ldo_setting[2];
83 	u8 clk_setting[2];
84 	u8 cccr;
85 	u8 sdio_mode;
86 	u8 ocr[3];
87 	u8 cis0[17];
88 	u8 cis1[48];
89 	u8 mac_addr[6];
90 	u8 eeprom_verno;
91 	u8 channel_plan;
92 	u8 tx_power_b[14];
93 	u8 tx_power_g[14];
94 };
95 
96 void read_efuse_byte(struct ieee80211_hw *hw, u16 _offset, u8 *pbuf);
97 void efuse_initialize(struct ieee80211_hw *hw);
98 u8 efuse_read_1byte(struct ieee80211_hw *hw, u16 address);
99 int efuse_one_byte_read(struct ieee80211_hw *hw, u16 addr, u8 *data);
100 void efuse_write_1byte(struct ieee80211_hw *hw, u16 address, u8 value);
101 void read_efuse(struct ieee80211_hw *hw, u16 _offset,
102 		u16 _size_byte, u8 *pbuf);
103 void efuse_shadow_read(struct ieee80211_hw *hw, u8 type,
104 		       u16 offset, u32 *value);
105 void efuse_shadow_write(struct ieee80211_hw *hw, u8 type,
106 			u16 offset, u32 value);
107 bool efuse_shadow_update(struct ieee80211_hw *hw);
108 bool efuse_shadow_update_chk(struct ieee80211_hw *hw);
109 void rtl_efuse_shadow_map_update(struct ieee80211_hw *hw);
110 void efuse_force_write_vendor_Id(struct ieee80211_hw *hw);
111 void efuse_re_pg_section(struct ieee80211_hw *hw, u8 section_idx);
112 
113 #endif
114