diff options
author | Gabor Juhos <juhosg@openwrt.org> | 2013-07-08 05:25:55 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2013-07-22 16:54:28 -0400 |
commit | 379448fe34e289fdcc473399d4f6cac19e757fb8 (patch) | |
tree | c2989b0994d67f1500a7a07f4403f8a19309a9d4 | |
parent | 022138ca93f016374d5d3f69c070c75596c5ecac (diff) |
rt2x00: rt2800lib: introduce rt2800_eeprom_word_index helper
Instead of assign the offset value to the
enum directly use a new helper function to
convert a rt2800_eeprom_word enum into an
index of the rt2x00_dev->eeprom array.
The patch does not change the existing
behaviour, but makes it possible to add
support for three-chain devices which are
using a different EEPROM layout.
Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Acked-by: Gertjan van Wingerde <gwingerde@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2800.h | 76 | ||||
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2800lib.c | 87 |
2 files changed, 122 insertions, 41 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2800.h b/drivers/net/wireless/rt2x00/rt2800.h index 064703933f7c..bc5c69558ea2 100644 --- a/drivers/net/wireless/rt2x00/rt2800.h +++ b/drivers/net/wireless/rt2x00/rt2800.h | |||
@@ -2207,43 +2207,45 @@ struct mac_iveiv_entry { | |||
2207 | */ | 2207 | */ |
2208 | 2208 | ||
2209 | enum rt2800_eeprom_word { | 2209 | enum rt2800_eeprom_word { |
2210 | EEPROM_CHIP_ID = 0x0000, | 2210 | EEPROM_CHIP_ID = 0, |
2211 | EEPROM_VERSION = 0x0001, | 2211 | EEPROM_VERSION, |
2212 | EEPROM_MAC_ADDR_0 = 0x0002, | 2212 | EEPROM_MAC_ADDR_0, |
2213 | EEPROM_MAC_ADDR_1 = 0x0003, | 2213 | EEPROM_MAC_ADDR_1, |
2214 | EEPROM_MAC_ADDR_2 = 0x0004, | 2214 | EEPROM_MAC_ADDR_2, |
2215 | EEPROM_NIC_CONF0 = 0x001a, | 2215 | EEPROM_NIC_CONF0, |
2216 | EEPROM_NIC_CONF1 = 0x001b, | 2216 | EEPROM_NIC_CONF1, |
2217 | EEPROM_FREQ = 0x001d, | 2217 | EEPROM_FREQ, |
2218 | EEPROM_LED_AG_CONF = 0x001e, | 2218 | EEPROM_LED_AG_CONF, |
2219 | EEPROM_LED_ACT_CONF = 0x001f, | 2219 | EEPROM_LED_ACT_CONF, |
2220 | EEPROM_LED_POLARITY = 0x0020, | 2220 | EEPROM_LED_POLARITY, |
2221 | EEPROM_NIC_CONF2 = 0x0021, | 2221 | EEPROM_NIC_CONF2, |
2222 | EEPROM_LNA = 0x0022, | 2222 | EEPROM_LNA, |
2223 | EEPROM_RSSI_BG = 0x0023, | 2223 | EEPROM_RSSI_BG, |
2224 | EEPROM_RSSI_BG2 = 0x0024, | 2224 | EEPROM_RSSI_BG2, |
2225 | EEPROM_TXMIXER_GAIN_BG = 0x0024, /* overlaps with RSSI_BG2 */ | 2225 | EEPROM_TXMIXER_GAIN_BG, |
2226 | EEPROM_RSSI_A = 0x0025, | 2226 | EEPROM_RSSI_A, |
2227 | EEPROM_RSSI_A2 = 0x0026, | 2227 | EEPROM_RSSI_A2, |
2228 | EEPROM_TXMIXER_GAIN_A = 0x0026, /* overlaps with RSSI_A2 */ | 2228 | EEPROM_TXMIXER_GAIN_A, |
2229 | EEPROM_EIRP_MAX_TX_POWER = 0x0027, | 2229 | EEPROM_EIRP_MAX_TX_POWER, |
2230 | EEPROM_TXPOWER_DELTA = 0x0028, | 2230 | EEPROM_TXPOWER_DELTA, |
2231 | EEPROM_TXPOWER_BG1 = 0x0029, | 2231 | EEPROM_TXPOWER_BG1, |
2232 | EEPROM_TXPOWER_BG2 = 0x0030, | 2232 | EEPROM_TXPOWER_BG2, |
2233 | EEPROM_TSSI_BOUND_BG1 = 0x0037, | 2233 | EEPROM_TSSI_BOUND_BG1, |
2234 | EEPROM_TSSI_BOUND_BG2 = 0x0038, | 2234 | EEPROM_TSSI_BOUND_BG2, |
2235 | EEPROM_TSSI_BOUND_BG3 = 0x0039, | 2235 | EEPROM_TSSI_BOUND_BG3, |
2236 | EEPROM_TSSI_BOUND_BG4 = 0x003a, | 2236 | EEPROM_TSSI_BOUND_BG4, |
2237 | EEPROM_TSSI_BOUND_BG5 = 0x003b, | 2237 | EEPROM_TSSI_BOUND_BG5, |
2238 | EEPROM_TXPOWER_A1 = 0x003c, | 2238 | EEPROM_TXPOWER_A1, |
2239 | EEPROM_TXPOWER_A2 = 0x0053, | 2239 | EEPROM_TXPOWER_A2, |
2240 | EEPROM_TSSI_BOUND_A1 = 0x006a, | 2240 | EEPROM_TSSI_BOUND_A1, |
2241 | EEPROM_TSSI_BOUND_A2 = 0x006b, | 2241 | EEPROM_TSSI_BOUND_A2, |
2242 | EEPROM_TSSI_BOUND_A3 = 0x006c, | 2242 | EEPROM_TSSI_BOUND_A3, |
2243 | EEPROM_TSSI_BOUND_A4 = 0x006d, | 2243 | EEPROM_TSSI_BOUND_A4, |
2244 | EEPROM_TSSI_BOUND_A5 = 0x006e, | 2244 | EEPROM_TSSI_BOUND_A5, |
2245 | EEPROM_TXPOWER_BYRATE = 0x006f, | 2245 | EEPROM_TXPOWER_BYRATE, |
2246 | EEPROM_BBP_START = 0x0078, | 2246 | EEPROM_BBP_START, |
2247 | /* New values must be added before this */ | ||
2248 | EEPROM_WORD_COUNT | ||
2247 | }; | 2249 | }; |
2248 | 2250 | ||
2249 | /* | 2251 | /* |
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.c b/drivers/net/wireless/rt2x00/rt2800lib.c index b59772a71b8b..41a34de4a3e2 100644 --- a/drivers/net/wireless/rt2x00/rt2800lib.c +++ b/drivers/net/wireless/rt2x00/rt2800lib.c | |||
@@ -221,22 +221,98 @@ static void rt2800_rf_write(struct rt2x00_dev *rt2x00dev, | |||
221 | mutex_unlock(&rt2x00dev->csr_mutex); | 221 | mutex_unlock(&rt2x00dev->csr_mutex); |
222 | } | 222 | } |
223 | 223 | ||
224 | static const unsigned int rt2800_eeprom_map[EEPROM_WORD_COUNT] = { | ||
225 | [EEPROM_CHIP_ID] = 0x0000, | ||
226 | [EEPROM_VERSION] = 0x0001, | ||
227 | [EEPROM_MAC_ADDR_0] = 0x0002, | ||
228 | [EEPROM_MAC_ADDR_1] = 0x0003, | ||
229 | [EEPROM_MAC_ADDR_2] = 0x0004, | ||
230 | [EEPROM_NIC_CONF0] = 0x001a, | ||
231 | [EEPROM_NIC_CONF1] = 0x001b, | ||
232 | [EEPROM_FREQ] = 0x001d, | ||
233 | [EEPROM_LED_AG_CONF] = 0x001e, | ||
234 | [EEPROM_LED_ACT_CONF] = 0x001f, | ||
235 | [EEPROM_LED_POLARITY] = 0x0020, | ||
236 | [EEPROM_NIC_CONF2] = 0x0021, | ||
237 | [EEPROM_LNA] = 0x0022, | ||
238 | [EEPROM_RSSI_BG] = 0x0023, | ||
239 | [EEPROM_RSSI_BG2] = 0x0024, | ||
240 | [EEPROM_TXMIXER_GAIN_BG] = 0x0024, /* overlaps with RSSI_BG2 */ | ||
241 | [EEPROM_RSSI_A] = 0x0025, | ||
242 | [EEPROM_RSSI_A2] = 0x0026, | ||
243 | [EEPROM_TXMIXER_GAIN_A] = 0x0026, /* overlaps with RSSI_A2 */ | ||
244 | [EEPROM_EIRP_MAX_TX_POWER] = 0x0027, | ||
245 | [EEPROM_TXPOWER_DELTA] = 0x0028, | ||
246 | [EEPROM_TXPOWER_BG1] = 0x0029, | ||
247 | [EEPROM_TXPOWER_BG2] = 0x0030, | ||
248 | [EEPROM_TSSI_BOUND_BG1] = 0x0037, | ||
249 | [EEPROM_TSSI_BOUND_BG2] = 0x0038, | ||
250 | [EEPROM_TSSI_BOUND_BG3] = 0x0039, | ||
251 | [EEPROM_TSSI_BOUND_BG4] = 0x003a, | ||
252 | [EEPROM_TSSI_BOUND_BG5] = 0x003b, | ||
253 | [EEPROM_TXPOWER_A1] = 0x003c, | ||
254 | [EEPROM_TXPOWER_A2] = 0x0053, | ||
255 | [EEPROM_TSSI_BOUND_A1] = 0x006a, | ||
256 | [EEPROM_TSSI_BOUND_A2] = 0x006b, | ||
257 | [EEPROM_TSSI_BOUND_A3] = 0x006c, | ||
258 | [EEPROM_TSSI_BOUND_A4] = 0x006d, | ||
259 | [EEPROM_TSSI_BOUND_A5] = 0x006e, | ||
260 | [EEPROM_TXPOWER_BYRATE] = 0x006f, | ||
261 | [EEPROM_BBP_START] = 0x0078, | ||
262 | }; | ||
263 | |||
264 | static unsigned int rt2800_eeprom_word_index(struct rt2x00_dev *rt2x00dev, | ||
265 | const enum rt2800_eeprom_word word) | ||
266 | { | ||
267 | const unsigned int *map; | ||
268 | unsigned int index; | ||
269 | |||
270 | if (WARN_ONCE(word >= EEPROM_WORD_COUNT, | ||
271 | "%s: invalid EEPROM word %d\n", | ||
272 | wiphy_name(rt2x00dev->hw->wiphy), word)) | ||
273 | return 0; | ||
274 | |||
275 | map = rt2800_eeprom_map; | ||
276 | index = map[word]; | ||
277 | |||
278 | /* Index 0 is valid only for EEPROM_CHIP_ID. | ||
279 | * Otherwise it means that the offset of the | ||
280 | * given word is not initialized in the map, | ||
281 | * or that the field is not usable on the | ||
282 | * actual chipset. | ||
283 | */ | ||
284 | WARN_ONCE(word != EEPROM_CHIP_ID && index == 0, | ||
285 | "%s: invalid access of EEPROM word %d\n", | ||
286 | wiphy_name(rt2x00dev->hw->wiphy), word); | ||
287 | |||
288 | return index; | ||
289 | } | ||
290 | |||
224 | static void *rt2800_eeprom_addr(struct rt2x00_dev *rt2x00dev, | 291 | static void *rt2800_eeprom_addr(struct rt2x00_dev *rt2x00dev, |
225 | const enum rt2800_eeprom_word word) | 292 | const enum rt2800_eeprom_word word) |
226 | { | 293 | { |
227 | return rt2x00_eeprom_addr(rt2x00dev, word); | 294 | unsigned int index; |
295 | |||
296 | index = rt2800_eeprom_word_index(rt2x00dev, word); | ||
297 | return rt2x00_eeprom_addr(rt2x00dev, index); | ||
228 | } | 298 | } |
229 | 299 | ||
230 | static void rt2800_eeprom_read(struct rt2x00_dev *rt2x00dev, | 300 | static void rt2800_eeprom_read(struct rt2x00_dev *rt2x00dev, |
231 | const enum rt2800_eeprom_word word, u16 *data) | 301 | const enum rt2800_eeprom_word word, u16 *data) |
232 | { | 302 | { |
233 | rt2x00_eeprom_read(rt2x00dev, word, data); | 303 | unsigned int index; |
304 | |||
305 | index = rt2800_eeprom_word_index(rt2x00dev, word); | ||
306 | rt2x00_eeprom_read(rt2x00dev, index, data); | ||
234 | } | 307 | } |
235 | 308 | ||
236 | static void rt2800_eeprom_write(struct rt2x00_dev *rt2x00dev, | 309 | static void rt2800_eeprom_write(struct rt2x00_dev *rt2x00dev, |
237 | const enum rt2800_eeprom_word word, u16 data) | 310 | const enum rt2800_eeprom_word word, u16 data) |
238 | { | 311 | { |
239 | rt2x00_eeprom_write(rt2x00dev, word, data); | 312 | unsigned int index; |
313 | |||
314 | index = rt2800_eeprom_word_index(rt2x00dev, word); | ||
315 | rt2x00_eeprom_write(rt2x00dev, index, data); | ||
240 | } | 316 | } |
241 | 317 | ||
242 | static void rt2800_eeprom_read_from_array(struct rt2x00_dev *rt2x00dev, | 318 | static void rt2800_eeprom_read_from_array(struct rt2x00_dev *rt2x00dev, |
@@ -244,7 +320,10 @@ static void rt2800_eeprom_read_from_array(struct rt2x00_dev *rt2x00dev, | |||
244 | unsigned int offset, | 320 | unsigned int offset, |
245 | u16 *data) | 321 | u16 *data) |
246 | { | 322 | { |
247 | rt2x00_eeprom_read(rt2x00dev, array + offset, data); | 323 | unsigned int index; |
324 | |||
325 | index = rt2800_eeprom_word_index(rt2x00dev, array); | ||
326 | rt2x00_eeprom_read(rt2x00dev, index + offset, data); | ||
248 | } | 327 | } |
249 | 328 | ||
250 | static int rt2800_enable_wlan_rt3290(struct rt2x00_dev *rt2x00dev) | 329 | static int rt2800_enable_wlan_rt3290(struct rt2x00_dev *rt2x00dev) |