ath9k: add support for reading eeprom from platform data on PCI devices
authorFelix Fietkau <nbd@openwrt.org>
Wed, 17 Nov 2010 03:25:33 +0000 (04:25 +0100)
committerJohn W. Linville <linville@tuxdriver.com>
Thu, 18 Nov 2010 19:22:23 +0000 (14:22 -0500)
Some embedded boards store platform data for connected PCIe AR92xx
chips in the system flash instead of a separate EEPROM chip.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/ath/ath9k/hw.c
drivers/net/wireless/ath/ath9k/init.c
drivers/net/wireless/ath/ath9k/pci.c

index 75e23632b968659053291b947c3f49c9a0c14e7d..5a13a761c30c6010957f2baa913a0bc823fae4b9 100644 (file)
@@ -419,10 +419,6 @@ static void ath9k_hw_init_defaults(struct ath_hw *ah)
        ah->hw_version.magic = AR5416_MAGIC;
        ah->hw_version.subvendorid = 0;
 
-       ah->ah_flags = 0;
-       if (!AR_SREV_9100(ah))
-               ah->ah_flags = AH_USE_EEPROM;
-
        ah->atim_window = 0;
        ah->sta_id1_defaults =
                AR_STA_ID1_CRPT_MIC_ENABLE |
index 498f62180f1c591fee9d60d77236749fe391744c..e7764ce881df33dec180c0434946ae686e006390 100644 (file)
@@ -530,6 +530,9 @@ static int ath9k_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid,
        ah->hw_version.subsysid = subsysid;
        sc->sc_ah = ah;
 
+       if (!sc->dev->platform_data)
+               ah->ah_flags |= AH_USE_EEPROM;
+
        common = ath9k_hw_common(ah);
        common->ops = &ath9k_common_ops;
        common->bus_ops = bus_ops;
index 6605bc2c2036ad83591780b811659de1add95c92..09f69a9617f4996080941be8667792814755087e 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <linux/nl80211.h>
 #include <linux/pci.h>
+#include <linux/ath9k_platform.h>
 #include "ath9k.h"
 
 static DEFINE_PCI_DEVICE_TABLE(ath_pci_id_table) = {
@@ -53,21 +54,36 @@ static void ath_pci_read_cachesize(struct ath_common *common, int *csz)
 
 static bool ath_pci_eeprom_read(struct ath_common *common, u32 off, u16 *data)
 {
-       struct ath_hw *ah = (struct ath_hw *) common->ah;
-
-       common->ops->read(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
-
-       if (!ath9k_hw_wait(ah,
-                          AR_EEPROM_STATUS_DATA,
-                          AR_EEPROM_STATUS_DATA_BUSY |
-                          AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0,
-                          AH_WAIT_TIMEOUT)) {
-               return false;
+       struct ath_softc *sc = (struct ath_softc *) common->priv;
+       struct ath9k_platform_data *pdata = sc->dev->platform_data;
+
+       if (pdata) {
+               if (off >= (ARRAY_SIZE(pdata->eeprom_data))) {
+                       ath_print(common, ATH_DBG_FATAL,
+                                 "%s: eeprom read failed, offset %08x "
+                                 "is out of range\n",
+                                 __func__, off);
+               }
+
+               *data = pdata->eeprom_data[off];
+       } else {
+               struct ath_hw *ah = (struct ath_hw *) common->ah;
+
+               common->ops->read(ah, AR5416_EEPROM_OFFSET +
+                                     (off << AR5416_EEPROM_S));
+
+               if (!ath9k_hw_wait(ah,
+                                  AR_EEPROM_STATUS_DATA,
+                                  AR_EEPROM_STATUS_DATA_BUSY |
+                                  AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0,
+                                  AH_WAIT_TIMEOUT)) {
+                       return false;
+               }
+
+               *data = MS(common->ops->read(ah, AR_EEPROM_STATUS_DATA),
+                          AR_EEPROM_STATUS_DATA_VAL);
        }
 
-       *data = MS(common->ops->read(ah, AR_EEPROM_STATUS_DATA),
-                  AR_EEPROM_STATUS_DATA_VAL);
-
        return true;
 }