[ar71xx] fix Ubiquiti RouterStation images
[openwrt/svn-archive/archive.git] / package / mac80211 / patches / 407-ath9k-get-EEPROM-contents-from-platform-data-on-AHB.patch
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
5
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.
9
10 Changes-licensed-under: ISC
11
12 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
13 Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
14 ---
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
22
23 --- a/drivers/net/wireless/ath9k/ahb.c
24 +++ b/drivers/net/wireless/ath9k/ahb.c
25 @@ -18,6 +18,7 @@
26
27 #include <linux/nl80211.h>
28 #include <linux/platform_device.h>
29 +#include <linux/ath9k_platform.h>
30 #include "core.h"
31 #include "reg.h"
32 #include "hw.h"
33 @@ -33,9 +34,29 @@ static void ath_ahb_cleanup(struct ath_s
34 iounmap(sc->mem);
35 }
36
37 +static bool ath_ahb_eeprom_read(struct ath_hal *ah, u32 off, u16 *data)
38 +{
39 + struct ath_softc *sc = ah->ah_sc;
40 + struct platform_device *pdev = to_platform_device(sc->dev);
41 + struct ath9k_platform_data *pdata;
42 +
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",
47 + __func__, off);
48 + return false;
49 + }
50 +
51 + *data = pdata->eeprom_data[off];
52 + return true;
53 +}
54 +
55 static struct ath_bus_ops ath_ahb_bus_ops = {
56 .read_cachesize = ath_ahb_read_cachesize,
57 .cleanup = ath_ahb_cleanup,
58 +
59 + .eeprom_read = ath_ahb_eeprom_read,
60 };
61
62 static int ath_ahb_probe(struct platform_device *pdev)
63 @@ -48,6 +69,12 @@ static int ath_ahb_probe(struct platform
64 int ret = 0;
65 struct ath_hal *ah;
66
67 + if (!pdev->dev.platform_data) {
68 + dev_err(&pdev->dev, "no platform data specified\n");
69 + ret = -EINVAL;
70 + goto err_out;
71 + }
72 +
73 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
74 if (res == NULL) {
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 {
79 struct ath_bus_ops {
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);
83 };
84
85 struct ath_softc {
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
89 return false;
90 }
91
92 -static bool ath9k_hw_eeprom_read(struct ath_hal *ah, u32 off, u16 *data)
93 -{
94 - (void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
95 -
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)) {
100 - return false;
101 - }
102 -
103 - *data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
104 - AR_EEPROM_STATUS_DATA_VAL);
105 -
106 - return true;
107 -}
108 -
109 -static int ath9k_hw_flash_map(struct ath_hal *ah)
110 -{
111 - struct ath_hal_5416 *ahp = AH5416(ah);
112 -
113 - ahp->ah_cal_mem = ioremap(AR5416_EEPROM_START_ADDR, AR5416_EEPROM_MAX);
114 -
115 - if (!ahp->ah_cal_mem) {
116 - DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
117 - "cannot remap eeprom region \n");
118 - return -EIO;
119 - }
120 -
121 - return 0;
122 -}
123 -
124 -static bool ath9k_hw_flash_read(struct ath_hal *ah, u32 off, u16 *data)
125 -{
126 - struct ath_hal_5416 *ahp = AH5416(ah);
127 -
128 - *data = ioread16(ahp->ah_cal_mem + off);
129 -
130 - return true;
131 -}
132 -
133 static inline bool ath9k_hw_nvram_read(struct ath_hal *ah, u32 off, u16 *data)
134 {
135 - if (ath9k_hw_use_flash(ah))
136 - return ath9k_hw_flash_read(ah, off, data);
137 - else
138 - return ath9k_hw_eeprom_read(ah, off, data);
139 + struct ath_softc *sc = ah->ah_sc;
140 +
141 + return sc->bus_ops->eeprom_read(ah, off, data);
142 }
143
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
146 int status;
147 struct ath_hal_5416 *ahp = AH5416(ah);
148
149 - if (ath9k_hw_use_flash(ah))
150 - ath9k_hw_flash_map(ah);
151 -
152 if (AR_SREV_9285(ah))
153 ahp->ah_eep_map = EEP_MAP_4KBITS;
154 else
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);
159 }
160
161 +static bool ath_pci_eeprom_read(struct ath_hal *ah, u32 off, u16 *data)
162 +{
163 + (void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
164 +
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)) {
169 + return false;
170 + }
171 +
172 + *data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
173 + AR_EEPROM_STATUS_DATA_VAL);
174 +
175 + return true;
176 +}
177 +
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,
182 };
183
184 static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
185 --- /dev/null
186 +++ b/include/linux/ath9k_platform.h
187 @@ -0,0 +1,28 @@
188 +/*
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>
192 + *
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.
196 + *
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.
204 + */
205 +
206 +#ifndef _LINUX_ATH9K_PLATFORM_H
207 +#define _LINUX_ATH9K_PLATFORM_H
208 +
209 +#define ATH9K_PLAT_EEP_MAX_WORDS 2048
210 +
211 +struct ath9k_platform_data {
212 + u16 eeprom_data[ATH9K_PLAT_EEP_MAX_WORDS];
213 +};
214 +
215 +#endif /* _LINUX_ATH9K_PLATFORM_H */