Commit 3d5717ad authored by Zhu, Yi's avatar Zhu, Yi Committed by John W. Linville

iwlwifi: use iwl_poll_direct_bit in EEPROM reading

The patch replaces the current reading EEPROM loop iterations with
iwl_poll_direct_bit(). It also fixes some comment error.
Signed-off-by: default avatarZhu Yi <yi.zhu@intel.com>
Signed-off-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 9c5f89b3
...@@ -103,7 +103,6 @@ ...@@ -103,7 +103,6 @@
* Driver reads 16-bit value from bits 31-16 of CSR_EEPROM_REG. * Driver reads 16-bit value from bits 31-16 of CSR_EEPROM_REG.
*/ */
#define IWL_EEPROM_ACCESS_TIMEOUT 5000 /* uSec */ #define IWL_EEPROM_ACCESS_TIMEOUT 5000 /* uSec */
#define IWL_EEPROM_ACCESS_DELAY 10 /* uSec */
/* /*
* Regulatory channel usage flags in EEPROM struct iwl_eeprom_channel.flags. * Regulatory channel usage flags in EEPROM struct iwl_eeprom_channel.flags.
......
...@@ -216,6 +216,8 @@ ...@@ -216,6 +216,8 @@
/* EEPROM REG */ /* EEPROM REG */
#define CSR_EEPROM_REG_READ_VALID_MSK (0x00000001) #define CSR_EEPROM_REG_READ_VALID_MSK (0x00000001)
#define CSR_EEPROM_REG_BIT_CMD (0x00000002) #define CSR_EEPROM_REG_BIT_CMD (0x00000002)
#define CSR_EEPROM_REG_MSK_ADDR (0x0000FFFC)
#define CSR_EEPROM_REG_MSK_DATA (0xFFFF0000)
/* EEPROM GP */ /* EEPROM GP */
#define CSR_EEPROM_GP_VALID_MSK (0x00000006) #define CSR_EEPROM_GP_VALID_MSK (0x00000006)
......
...@@ -209,10 +209,8 @@ int iwl_eeprom_init(struct iwl_priv *priv) ...@@ -209,10 +209,8 @@ int iwl_eeprom_init(struct iwl_priv *priv)
{ {
u16 *e; u16 *e;
u32 gp = iwl_read32(priv, CSR_EEPROM_GP); u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
u32 r;
int sz = priv->cfg->eeprom_size; int sz = priv->cfg->eeprom_size;
int ret; int ret;
int i;
u16 addr; u16 addr;
/* allocate eeprom */ /* allocate eeprom */
...@@ -240,22 +238,19 @@ int iwl_eeprom_init(struct iwl_priv *priv) ...@@ -240,22 +238,19 @@ int iwl_eeprom_init(struct iwl_priv *priv)
/* eeprom is an array of 16bit values */ /* eeprom is an array of 16bit values */
for (addr = 0; addr < sz; addr += sizeof(u16)) { for (addr = 0; addr < sz; addr += sizeof(u16)) {
_iwl_write32(priv, CSR_EEPROM_REG, addr << 1); u32 r;
_iwl_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT; _iwl_write32(priv, CSR_EEPROM_REG,
i += IWL_EEPROM_ACCESS_DELAY) { CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
if (r & CSR_EEPROM_REG_READ_VALID_MSK)
break;
udelay(IWL_EEPROM_ACCESS_DELAY);
}
if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) { ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG,
CSR_EEPROM_REG_READ_VALID_MSK,
IWL_EEPROM_ACCESS_TIMEOUT);
if (ret < 0) {
IWL_ERROR("Time out reading EEPROM[%d]\n", addr); IWL_ERROR("Time out reading EEPROM[%d]\n", addr);
ret = -ETIMEDOUT;
goto done; goto done;
} }
r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16)); e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
} }
ret = 0; ret = 0;
......
...@@ -68,17 +68,14 @@ struct iwl_priv; ...@@ -68,17 +68,14 @@ struct iwl_priv;
/* /*
* EEPROM access time values: * EEPROM access time values:
* *
* Driver initiates EEPROM read by writing byte address << 1 to CSR_EEPROM_REG, * Driver initiates EEPROM read by writing byte address << 1 to CSR_EEPROM_REG.
* then clearing (with subsequent read/modify/write) CSR_EEPROM_REG bit
* CSR_EEPROM_REG_BIT_CMD (0x2).
* Driver then polls CSR_EEPROM_REG for CSR_EEPROM_REG_READ_VALID_MSK (0x1). * Driver then polls CSR_EEPROM_REG for CSR_EEPROM_REG_READ_VALID_MSK (0x1).
* When polling, wait 10 uSec between polling loops, up to a maximum 5000 uSec. * When polling, wait 10 uSec between polling loops, up to a maximum 5000 uSec.
* Driver reads 16-bit value from bits 31-16 of CSR_EEPROM_REG. * Driver reads 16-bit value from bits 31-16 of CSR_EEPROM_REG.
*/ */
#define IWL_EEPROM_ACCESS_TIMEOUT 5000 /* uSec */ #define IWL_EEPROM_ACCESS_TIMEOUT 5000 /* uSec */
#define IWL_EEPROM_ACCESS_DELAY 10 /* uSec */
#define IWL_EEPROM_SEM_TIMEOUT 10 /* milliseconds */ #define IWL_EEPROM_SEM_TIMEOUT 10 /* microseconds */
#define IWL_EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */ #define IWL_EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
......
...@@ -1504,10 +1504,8 @@ int iwl3945_eeprom_init(struct iwl3945_priv *priv) ...@@ -1504,10 +1504,8 @@ int iwl3945_eeprom_init(struct iwl3945_priv *priv)
{ {
u16 *e = (u16 *)&priv->eeprom; u16 *e = (u16 *)&priv->eeprom;
u32 gp = iwl3945_read32(priv, CSR_EEPROM_GP); u32 gp = iwl3945_read32(priv, CSR_EEPROM_GP);
u32 r;
int sz = sizeof(priv->eeprom); int sz = sizeof(priv->eeprom);
int rc; int ret;
int i;
u16 addr; u16 addr;
/* The EEPROM structure has several padding buffers within it /* The EEPROM structure has several padding buffers within it
...@@ -1522,29 +1520,28 @@ int iwl3945_eeprom_init(struct iwl3945_priv *priv) ...@@ -1522,29 +1520,28 @@ int iwl3945_eeprom_init(struct iwl3945_priv *priv)
} }
/* Make sure driver (instead of uCode) is allowed to read EEPROM */ /* Make sure driver (instead of uCode) is allowed to read EEPROM */
rc = iwl3945_eeprom_acquire_semaphore(priv); ret = iwl3945_eeprom_acquire_semaphore(priv);
if (rc < 0) { if (ret < 0) {
IWL_ERROR("Failed to acquire EEPROM semaphore.\n"); IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
return -ENOENT; return -ENOENT;
} }
/* eeprom is an array of 16bit values */ /* eeprom is an array of 16bit values */
for (addr = 0; addr < sz; addr += sizeof(u16)) { for (addr = 0; addr < sz; addr += sizeof(u16)) {
_iwl3945_write32(priv, CSR_EEPROM_REG, addr << 1); u32 r;
_iwl3945_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
i += IWL_EEPROM_ACCESS_DELAY) {
r = _iwl3945_read_direct32(priv, CSR_EEPROM_REG);
if (r & CSR_EEPROM_REG_READ_VALID_MSK)
break;
udelay(IWL_EEPROM_ACCESS_DELAY);
}
if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) { _iwl3945_write32(priv, CSR_EEPROM_REG,
CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
_iwl3945_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
ret = iwl3945_poll_direct_bit(priv, CSR_EEPROM_REG,
CSR_EEPROM_REG_READ_VALID_MSK,
IWL_EEPROM_ACCESS_TIMEOUT);
if (ret < 0) {
IWL_ERROR("Time out reading EEPROM[%d]\n", addr); IWL_ERROR("Time out reading EEPROM[%d]\n", addr);
return -ETIMEDOUT; return ret;
} }
r = _iwl3945_read_direct32(priv, CSR_EEPROM_REG);
e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16)); e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment