Commit 7d4b829a authored by Andrea Merello's avatar Andrea Merello Committed by John W. Linville

rtl8180: move eeprom read stuff in a separate function

Eeprom read operations are mixed in the probe function.
Make the code more readable and clean by extracting this code and
moving it in a dedicated function.

The variable eeprom_cck_table_adr, now useless, is here because
it will be needed for rtl8187se support, that I hope to add soon.
Signed-off-by: default avatarAndrea Merello <andrea.merello@gmail.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 9069af79
...@@ -1041,8 +1041,7 @@ static const struct ieee80211_ops rtl8180_ops = { ...@@ -1041,8 +1041,7 @@ static const struct ieee80211_ops rtl8180_ops = {
static void rtl8180_eeprom_register_read(struct eeprom_93cx6 *eeprom) static void rtl8180_eeprom_register_read(struct eeprom_93cx6 *eeprom)
{ {
struct ieee80211_hw *dev = eeprom->data; struct rtl8180_priv *priv = eeprom->data;
struct rtl8180_priv *priv = dev->priv;
u8 reg = rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); u8 reg = rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
eeprom->reg_data_in = reg & RTL818X_EEPROM_CMD_WRITE; eeprom->reg_data_in = reg & RTL818X_EEPROM_CMD_WRITE;
...@@ -1053,8 +1052,7 @@ static void rtl8180_eeprom_register_read(struct eeprom_93cx6 *eeprom) ...@@ -1053,8 +1052,7 @@ static void rtl8180_eeprom_register_read(struct eeprom_93cx6 *eeprom)
static void rtl8180_eeprom_register_write(struct eeprom_93cx6 *eeprom) static void rtl8180_eeprom_register_write(struct eeprom_93cx6 *eeprom)
{ {
struct ieee80211_hw *dev = eeprom->data; struct rtl8180_priv *priv = eeprom->data;
struct rtl8180_priv *priv = dev->priv;
u8 reg = 2 << 6; u8 reg = 2 << 6;
if (eeprom->reg_data_in) if (eeprom->reg_data_in)
...@@ -1071,6 +1069,67 @@ static void rtl8180_eeprom_register_write(struct eeprom_93cx6 *eeprom) ...@@ -1071,6 +1069,67 @@ static void rtl8180_eeprom_register_write(struct eeprom_93cx6 *eeprom)
udelay(10); udelay(10);
} }
static void rtl8180_eeprom_read(struct rtl8180_priv *priv)
{
struct eeprom_93cx6 eeprom;
int eeprom_cck_table_adr;
u16 eeprom_val;
int i;
eeprom.data = priv;
eeprom.register_read = rtl8180_eeprom_register_read;
eeprom.register_write = rtl8180_eeprom_register_write;
if (rtl818x_ioread32(priv, &priv->map->RX_CONF) & (1 << 6))
eeprom.width = PCI_EEPROM_WIDTH_93C66;
else
eeprom.width = PCI_EEPROM_WIDTH_93C46;
rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD,
RTL818X_EEPROM_CMD_PROGRAM);
rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
udelay(10);
eeprom_93cx6_read(&eeprom, 0x06, &eeprom_val);
eeprom_val &= 0xFF;
priv->rf_type = eeprom_val;
eeprom_93cx6_read(&eeprom, 0x17, &eeprom_val);
priv->csthreshold = eeprom_val >> 8;
eeprom_93cx6_multiread(&eeprom, 0x7, (__le16 *)priv->mac_addr, 3);
eeprom_cck_table_adr = 0x10;
/* CCK TX power */
for (i = 0; i < 14; i += 2) {
u16 txpwr;
eeprom_93cx6_read(&eeprom, eeprom_cck_table_adr + (i >> 1),
&txpwr);
priv->channels[i].hw_value = txpwr & 0xFF;
priv->channels[i + 1].hw_value = txpwr >> 8;
}
/* OFDM TX power */
if (priv->chip_family != RTL818X_CHIP_FAMILY_RTL8180) {
for (i = 0; i < 14; i += 2) {
u16 txpwr;
eeprom_93cx6_read(&eeprom, 0x20 + (i >> 1), &txpwr);
priv->channels[i].hw_value |= (txpwr & 0xFF) << 8;
priv->channels[i + 1].hw_value |= txpwr & 0xFF00;
}
}
if (priv->chip_family == RTL818X_CHIP_FAMILY_RTL8180) {
__le32 anaparam;
eeprom_93cx6_multiread(&eeprom, 0xD, (__le16 *)&anaparam, 2);
priv->anaparam = le32_to_cpu(anaparam);
eeprom_93cx6_read(&eeprom, 0x19, &priv->rfparam);
}
rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD,
RTL818X_EEPROM_CMD_NORMAL);
}
static int rtl8180_probe(struct pci_dev *pdev, static int rtl8180_probe(struct pci_dev *pdev,
const struct pci_device_id *id) const struct pci_device_id *id)
{ {
...@@ -1078,12 +1137,9 @@ static int rtl8180_probe(struct pci_dev *pdev, ...@@ -1078,12 +1137,9 @@ static int rtl8180_probe(struct pci_dev *pdev,
struct rtl8180_priv *priv; struct rtl8180_priv *priv;
unsigned long mem_addr, mem_len; unsigned long mem_addr, mem_len;
unsigned int io_addr, io_len; unsigned int io_addr, io_len;
int err, i; int err;
struct eeprom_93cx6 eeprom;
const char *chip_name, *rf_name = NULL; const char *chip_name, *rf_name = NULL;
u32 reg; u32 reg;
u16 eeprom_val;
u8 mac_addr[ETH_ALEN];
err = pci_enable_device(pdev); err = pci_enable_device(pdev);
if (err) { if (err) {
...@@ -1201,21 +1257,9 @@ static int rtl8180_probe(struct pci_dev *pdev, ...@@ -1201,21 +1257,9 @@ static int rtl8180_probe(struct pci_dev *pdev,
pci_try_set_mwi(pdev); pci_try_set_mwi(pdev);
} }
eeprom.data = dev; rtl8180_eeprom_read(priv);
eeprom.register_read = rtl8180_eeprom_register_read;
eeprom.register_write = rtl8180_eeprom_register_write;
if (rtl818x_ioread32(priv, &priv->map->RX_CONF) & (1 << 6))
eeprom.width = PCI_EEPROM_WIDTH_93C66;
else
eeprom.width = PCI_EEPROM_WIDTH_93C46;
rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_PROGRAM);
rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
udelay(10);
eeprom_93cx6_read(&eeprom, 0x06, &eeprom_val); switch (priv->rf_type) {
eeprom_val &= 0xFF;
switch (eeprom_val) {
case 1: rf_name = "Intersil"; case 1: rf_name = "Intersil";
break; break;
case 2: rf_name = "RFMD"; case 2: rf_name = "RFMD";
...@@ -1233,7 +1277,7 @@ static int rtl8180_probe(struct pci_dev *pdev, ...@@ -1233,7 +1277,7 @@ static int rtl8180_probe(struct pci_dev *pdev,
break; break;
default: default:
printk(KERN_ERR "%s (rtl8180): Unknown RF! (0x%x)\n", printk(KERN_ERR "%s (rtl8180): Unknown RF! (0x%x)\n",
pci_name(pdev), eeprom_val); pci_name(pdev), priv->rf_type);
goto err_iounmap; goto err_iounmap;
} }
...@@ -1243,42 +1287,12 @@ static int rtl8180_probe(struct pci_dev *pdev, ...@@ -1243,42 +1287,12 @@ static int rtl8180_probe(struct pci_dev *pdev,
goto err_iounmap; goto err_iounmap;
} }
eeprom_93cx6_read(&eeprom, 0x17, &eeprom_val); if (!is_valid_ether_addr(priv->mac_addr)) {
priv->csthreshold = eeprom_val >> 8;
if (priv->chip_family != RTL818X_CHIP_FAMILY_RTL8185) {
__le32 anaparam;
eeprom_93cx6_multiread(&eeprom, 0xD, (__le16 *)&anaparam, 2);
priv->anaparam = le32_to_cpu(anaparam);
eeprom_93cx6_read(&eeprom, 0x19, &priv->rfparam);
}
eeprom_93cx6_multiread(&eeprom, 0x7, (__le16 *)mac_addr, 3);
if (!is_valid_ether_addr(mac_addr)) {
printk(KERN_WARNING "%s (rtl8180): Invalid hwaddr! Using" printk(KERN_WARNING "%s (rtl8180): Invalid hwaddr! Using"
" randomly generated MAC addr\n", pci_name(pdev)); " randomly generated MAC addr\n", pci_name(pdev));
eth_random_addr(mac_addr); eth_random_addr(priv->mac_addr);
}
SET_IEEE80211_PERM_ADDR(dev, mac_addr);
/* CCK TX power */
for (i = 0; i < 14; i += 2) {
u16 txpwr;
eeprom_93cx6_read(&eeprom, 0x10 + (i >> 1), &txpwr);
priv->channels[i].hw_value = txpwr & 0xFF;
priv->channels[i + 1].hw_value = txpwr >> 8;
}
/* OFDM TX power */
if (priv->chip_family != RTL818X_CHIP_FAMILY_RTL8180) {
for (i = 0; i < 14; i += 2) {
u16 txpwr;
eeprom_93cx6_read(&eeprom, 0x20 + (i >> 1), &txpwr);
priv->channels[i].hw_value |= (txpwr & 0xFF) << 8;
priv->channels[i + 1].hw_value |= txpwr & 0xFF00;
}
} }
SET_IEEE80211_PERM_ADDR(dev, priv->mac_addr);
rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
spin_lock_init(&priv->lock); spin_lock_init(&priv->lock);
...@@ -1290,7 +1304,7 @@ static int rtl8180_probe(struct pci_dev *pdev, ...@@ -1290,7 +1304,7 @@ static int rtl8180_probe(struct pci_dev *pdev,
} }
wiphy_info(dev->wiphy, "hwaddr %pm, %s + %s\n", wiphy_info(dev->wiphy, "hwaddr %pm, %s + %s\n",
mac_addr, chip_name, priv->rf->name); priv->mac_addr, chip_name, priv->rf->name);
return 0; return 0;
......
...@@ -91,7 +91,8 @@ struct rtl8180_priv { ...@@ -91,7 +91,8 @@ struct rtl8180_priv {
u32 anaparam; u32 anaparam;
u16 rfparam; u16 rfparam;
u8 csthreshold; u8 csthreshold;
u8 mac_addr[ETH_ALEN];
u8 rf_type;
/* sequence # */ /* sequence # */
u16 seqno; u16 seqno;
}; };
......
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