1 From 5941741f36a3870e8d22760e290ae7ea45293cdd Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Mon, 5 Jan 2009 11:05:05 +0100
4 Subject: [PATCH v3 07/11] ath9k: get EEPROM contents from platform data on AHB bus
6 On the AR913x SOCs we have to provide EEPROM contents via platform_data,
7 because accessing the flash via MMIO is not safe. Additionally different
8 boards may store the radio calibration data at different locations.
10 Changes-licensed-under: ISC
12 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
13 Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
15 drivers/net/wireless/ath9k/ahb.c | 27 ++++++++++++++++++
16 drivers/net/wireless/ath9k/core.h | 1 +
17 drivers/net/wireless/ath9k/eeprom.c | 51 ++--------------------------------
18 drivers/net/wireless/ath9k/pci.c | 18 ++++++++++++
19 include/linux/ath9k_platform.h | 28 +++++++++++++++++++
20 5 files changed, 77 insertions(+), 48 deletions(-)
21 create mode 100644 include/linux/ath9k_platform.h
23 --- a/drivers/net/wireless/ath9k/ahb.c
24 +++ b/drivers/net/wireless/ath9k/ahb.c
27 #include <linux/nl80211.h>
28 #include <linux/platform_device.h>
29 +#include <linux/ath9k_platform.h>
33 @@ -33,9 +34,29 @@ static void ath_ahb_cleanup(struct ath_s
37 +static bool ath_ahb_eeprom_read(struct ath_hal *ah, u32 off, u16 *data)
39 + struct ath_softc *sc = ah->ah_sc;
40 + struct platform_device *pdev = to_platform_device(sc->dev);
41 + struct ath9k_platform_data *pdata;
43 + pdata = (struct ath9k_platform_data *) pdev->dev.platform_data;
44 + if (off >= (ARRAY_SIZE(pdata->eeprom_data))) {
45 + DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
46 + "%s: flash read failed, offset %08x is out of range\n",
51 + *data = pdata->eeprom_data[off];
55 static struct ath_bus_ops ath_ahb_bus_ops = {
56 .read_cachesize = ath_ahb_read_cachesize,
57 .cleanup = ath_ahb_cleanup,
59 + .eeprom_read = ath_ahb_eeprom_read,
62 static int ath_ahb_probe(struct platform_device *pdev)
63 @@ -48,6 +69,12 @@ static int ath_ahb_probe(struct platform
67 + if (!pdev->dev.platform_data) {
68 + dev_err(&pdev->dev, "no platform data specified\n");
73 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
75 dev_err(&pdev->dev, "no memory resource found\n");
76 --- a/drivers/net/wireless/ath9k/core.h
77 +++ b/drivers/net/wireless/ath9k/core.h
78 @@ -696,6 +696,7 @@ enum PROT_MODE {
80 void (*read_cachesize)(struct ath_softc *sc, int *csz);
81 void (*cleanup)(struct ath_softc *sc);
82 + bool (*eeprom_read)(struct ath_hal *ah, u32 off, u16 *data);
86 --- a/drivers/net/wireless/ath9k/eeprom.c
87 +++ b/drivers/net/wireless/ath9k/eeprom.c
88 @@ -91,53 +91,11 @@ static inline bool ath9k_hw_get_lower_up
92 -static bool ath9k_hw_eeprom_read(struct ath_hal *ah, u32 off, u16 *data)
94 - (void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
96 - if (!ath9k_hw_wait(ah,
97 - AR_EEPROM_STATUS_DATA,
98 - AR_EEPROM_STATUS_DATA_BUSY |
99 - AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0)) {
103 - *data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
104 - AR_EEPROM_STATUS_DATA_VAL);
109 -static int ath9k_hw_flash_map(struct ath_hal *ah)
111 - struct ath_hal_5416 *ahp = AH5416(ah);
113 - ahp->ah_cal_mem = ioremap(AR5416_EEPROM_START_ADDR, AR5416_EEPROM_MAX);
115 - if (!ahp->ah_cal_mem) {
116 - DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
117 - "cannot remap eeprom region \n");
124 -static bool ath9k_hw_flash_read(struct ath_hal *ah, u32 off, u16 *data)
126 - struct ath_hal_5416 *ahp = AH5416(ah);
128 - *data = ioread16(ahp->ah_cal_mem + off);
133 static inline bool ath9k_hw_nvram_read(struct ath_hal *ah, u32 off, u16 *data)
135 - if (ath9k_hw_use_flash(ah))
136 - return ath9k_hw_flash_read(ah, off, data);
138 - return ath9k_hw_eeprom_read(ah, off, data);
139 + struct ath_softc *sc = ah->ah_sc;
141 + return sc->bus_ops->eeprom_read(ah, off, data);
144 static bool ath9k_hw_fill_4k_eeprom(struct ath_hal *ah)
145 @@ -2825,9 +2783,6 @@ int ath9k_hw_eeprom_attach(struct ath_ha
147 struct ath_hal_5416 *ahp = AH5416(ah);
149 - if (ath9k_hw_use_flash(ah))
150 - ath9k_hw_flash_map(ah);
152 if (AR_SREV_9285(ah))
153 ahp->ah_eep_map = EEP_MAP_4KBITS;
155 --- a/drivers/net/wireless/ath9k/pci.c
156 +++ b/drivers/net/wireless/ath9k/pci.c
157 @@ -58,9 +58,27 @@ static void ath_pci_cleanup(struct ath_s
158 pci_disable_device(pdev);
161 +static bool ath_pci_eeprom_read(struct ath_hal *ah, u32 off, u16 *data)
163 + (void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
165 + if (!ath9k_hw_wait(ah,
166 + AR_EEPROM_STATUS_DATA,
167 + AR_EEPROM_STATUS_DATA_BUSY |
168 + AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0)) {
172 + *data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
173 + AR_EEPROM_STATUS_DATA_VAL);
178 static struct ath_bus_ops ath_pci_bus_ops = {
179 .read_cachesize = ath_pci_read_cachesize,
180 .cleanup = ath_pci_cleanup,
181 + .eeprom_read = ath_pci_eeprom_read,
184 static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
186 +++ b/include/linux/ath9k_platform.h
189 + * Copyright (c) 2008 Atheros Communications Inc.
190 + * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
191 + * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
193 + * Permission to use, copy, modify, and/or distribute this software for any
194 + * purpose with or without fee is hereby granted, provided that the above
195 + * copyright notice and this permission notice appear in all copies.
197 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
198 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
199 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
200 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
201 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
202 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
203 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
206 +#ifndef _LINUX_ATH9K_PLATFORM_H
207 +#define _LINUX_ATH9K_PLATFORM_H
209 +#define ATH9K_PLAT_EEP_MAX_WORDS 2048
211 +struct ath9k_platform_data {
212 + u16 eeprom_data[ATH9K_PLAT_EEP_MAX_WORDS];
215 +#endif /* _LINUX_ATH9K_PLATFORM_H */