/******************************************************************************
*
* Copyright(c) 2009-2012 Realtek Corporation.
*
* Tmis program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* Tmis program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* tmis program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*
* Tme full GNU General Public License is included in this distribution in the
* file called LICENSE.
*
* Contact Information:
* wlanfae <wlanfae@realtek.com>
* Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
* Hsinchu 300, Taiwan.
*
* Larry Finger <Larry.Finger@lwfinger.net>
*
*****************************************************************************/
#include <linux/export.h>
#include "wifi.h"
#include "efuse.h"
static const u8 MAX_PGPKT_SIZE = 9;
static const u8 PGPKT_DATA_SIZE = 8;
static const int EFUSE_MAX_SIZE = 512;
static const u8 EFUSE_OOB_PROTECT_BYTES = 15;
static const struct efuse_map RTL8712_SDIO_EFUSE_TABLE[] = {
{0, 0, 0, 2},
{0, 1, 0, 2},
{0, 2, 0, 2},
{1, 0, 0, 1},
{1, 0, 1, 1},
{1, 1, 0, 1},
{1, 1, 1, 3},
{1, 3, 0, 17},
{3, 3, 1, 48},
{10, 0, 0, 6},
{10, 3, 0, 1},
{10, 3, 1, 1},
{11, 0, 0, 28}
};
static void efuse_shadow_read_1byte(struct ieee80211_hw *hw, u16 offset,
u8 *value);
static void efuse_shadow_read_2byte(struct ieee80211_hw *hw, u16 offset,
u16 *value);
static void efuse_shadow_read_4byte(struct ieee80211_hw *hw, u16 offset,
u32 *value);
static void efuse_shadow_write_1byte(struct ieee80211_hw *hw, u16 offset,
u8 value);
static void efuse_shadow_write_2byte(struct ieee80211_hw *hw, u16 offset,
u16 value);
static void efuse_shadow_write_4byte(struct ieee80211_hw *hw, u16 offset,
u32 value);
static int efuse_one_byte_read(struct ieee80211_hw *hw, u16 addr,
u8 *data);
static int efuse_one_byte_write(struct ieee80211_hw *hw, u16 addr,
u8 data);
static void efuse_read_all_map(struct ieee80211_hw *hw, u8 *efuse);
static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset,
u8 *data);
static int efuse_pg_packet_write(struct ieee80211_hw *hw, u8 offset,
u8 word_en, u8 *data);
static void efuse_word_enable_data_read(u8 word_en, u8 *sourdata,
u8 *targetdata);
static u8 efuse_word_enable_data_write(struct ieee80211_hw *hw,
u16 efuse_addr, u8 word_en, u8 *data);
static void efuse_power_switch(struct ieee80211_hw *hw, u8 write,
u8 pwrstate);
static u16 efuse_get_current_size(struct ieee80211_hw *hw);
static u8 efuse_calculate_word_cnts(u8 word_en);
void efuse_initialize(struct ieee80211_hw *hw)
{
struct rtl_priv *rtlpriv = rtl_priv(hw);
u8 bytetemp;
u8 temp;
bytetemp = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[SYS_FUNC_EN] + 1);
temp = bytetemp | 0x20;
rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[SYS_FUNC_EN] + 1, temp);
bytetemp = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[SYS_ISO_CTRL] + 1);
temp = bytetemp & 0xFE;
rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[SYS_ISO_CTRL] + 1, temp);
bytetemp = rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST] + 3);
temp = bytetemp | 0x80;
rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST] + 3, temp);
rtl_write_byte(rtlpriv, 0x2F8, 0x3);
rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3, 0x72);
}
u8 efuse_read_1byte(struct ieee80211_hw *hw, u16 address)
{
struct rtl_priv *rtlpriv = rtl_priv(hw);
u8 data;
u8 bytetemp;
u8 temp;
u32 k = 0;
const u32 efuse_len =
rtlpriv->cfg->maps[EFUSE_REAL_CONTENT_SIZE];
if (address < efuse_len) {
temp = address & 0xFF;
rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1,
temp);
bytetemp = rtl_read_byte(rtlpriv,
rtlpriv->cfg->maps[EFUSE_CTRL] + 2);
temp = ((address >> 8) & 0x03) | (bytetemp & 0xFC);
rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 2,
temp);
bytetemp = rtl_read_byte(rtlpriv,
rtlpriv->cfg->maps[EFUSE_CTRL] + 3);
temp = bytetemp & 0x7F;
rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 3,
temp);
bytetemp = rtl_read_byte(rtlpriv,
rtlpriv->cfg->maps[EFUSE_CTRL] + 3);
while (!(bytetemp &<
|