diff options
author | Teemu Paasikivi <ext-teemu.3.paasikivi@nokia.com> | 2010-02-22 01:38:23 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2010-03-09 15:02:57 -0500 |
commit | 8197b7118add28f9aaa99c1fb73c0e201c8cde52 (patch) | |
tree | ce6c7c4cb5cdb8113b19d17b98d04929eef5030e /drivers | |
parent | 54f7e5037c95f2beff0252bfcf288f711c185799 (diff) |
wl1271: Implemented abstraction of IO functions.
Changed the driver to use if_ops structure to abstract access to the IO
layer (SPI or SDIO).
Signed-off-by: Teemu Paasikivi <ext-teemu.3.paasikivi@nokia.com>
Reviewed-by: Juuso Oikarinen <juuso.oikarinen@nokia.com>
Signed-off-by: Juuso Oikarinen <juuso.oikarinen@nokia.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/wireless/wl12xx/wl1271.h | 16 | ||||
-rw-r--r-- | drivers/net/wireless/wl12xx/wl1271_io.c | 21 | ||||
-rw-r--r-- | drivers/net/wireless/wl12xx/wl1271_io.h | 2 | ||||
-rw-r--r-- | drivers/net/wireless/wl12xx/wl1271_main.c | 6 | ||||
-rw-r--r-- | drivers/net/wireless/wl12xx/wl1271_spi.c | 37 |
5 files changed, 62 insertions, 20 deletions
diff --git a/drivers/net/wireless/wl12xx/wl1271.h b/drivers/net/wireless/wl12xx/wl1271.h index 97ea5096bc8c..10135c94e20e 100644 --- a/drivers/net/wireless/wl12xx/wl1271.h +++ b/drivers/net/wireless/wl12xx/wl1271.h | |||
@@ -334,11 +334,25 @@ struct wl1271_scan { | |||
334 | u8 probe_requests; | 334 | u8 probe_requests; |
335 | }; | 335 | }; |
336 | 336 | ||
337 | struct wl1271_if_operations { | ||
338 | void (*read)(struct wl1271 *wl, int addr, void *buf, size_t len, | ||
339 | bool fixed); | ||
340 | void (*write)(struct wl1271 *wl, int addr, void *buf, size_t len, | ||
341 | bool fixed); | ||
342 | void (*reset)(struct wl1271 *wl); | ||
343 | void (*init)(struct wl1271 *wl); | ||
344 | struct device* (*dev)(struct wl1271 *wl); | ||
345 | void (*enable_irq)(struct wl1271 *wl); | ||
346 | void (*disable_irq)(struct wl1271 *wl); | ||
347 | }; | ||
348 | |||
337 | struct wl1271 { | 349 | struct wl1271 { |
338 | struct ieee80211_hw *hw; | 350 | struct ieee80211_hw *hw; |
339 | bool mac80211_registered; | 351 | bool mac80211_registered; |
340 | 352 | ||
341 | struct spi_device *spi; | 353 | void *if_priv; |
354 | |||
355 | struct wl1271_if_operations *if_ops; | ||
342 | 356 | ||
343 | void (*set_power)(bool enable); | 357 | void (*set_power)(bool enable); |
344 | int irq; | 358 | int irq; |
diff --git a/drivers/net/wireless/wl12xx/wl1271_io.c b/drivers/net/wireless/wl12xx/wl1271_io.c index b825cfa30ecf..d00f7ed7f21c 100644 --- a/drivers/net/wireless/wl12xx/wl1271_io.c +++ b/drivers/net/wireless/wl12xx/wl1271_io.c | |||
@@ -31,14 +31,19 @@ | |||
31 | #include "wl1271_spi.h" | 31 | #include "wl1271_spi.h" |
32 | #include "wl1271_io.h" | 32 | #include "wl1271_io.h" |
33 | 33 | ||
34 | struct device *wl1271_wl_to_dev(struct wl1271 *wl) | ||
35 | { | ||
36 | return wl->if_ops->dev(wl); | ||
37 | } | ||
38 | |||
34 | void wl1271_disable_interrupts(struct wl1271 *wl) | 39 | void wl1271_disable_interrupts(struct wl1271 *wl) |
35 | { | 40 | { |
36 | wl1271_spi_disable_interrupts(wl); | 41 | wl->if_ops->disable_irq(wl); |
37 | } | 42 | } |
38 | 43 | ||
39 | void wl1271_enable_interrupts(struct wl1271 *wl) | 44 | void wl1271_enable_interrupts(struct wl1271 *wl) |
40 | { | 45 | { |
41 | wl1271_spi_enable_interrupts(wl); | 46 | wl->if_ops->enable_irq(wl); |
42 | } | 47 | } |
43 | 48 | ||
44 | static int wl1271_translate_addr(struct wl1271 *wl, int addr) | 49 | static int wl1271_translate_addr(struct wl1271 *wl, int addr) |
@@ -127,24 +132,24 @@ int wl1271_set_partition(struct wl1271 *wl, | |||
127 | 132 | ||
128 | void wl1271_io_reset(struct wl1271 *wl) | 133 | void wl1271_io_reset(struct wl1271 *wl) |
129 | { | 134 | { |
130 | wl1271_spi_reset(wl); | 135 | wl->if_ops->reset(wl); |
131 | } | 136 | } |
132 | 137 | ||
133 | void wl1271_io_init(struct wl1271 *wl) | 138 | void wl1271_io_init(struct wl1271 *wl) |
134 | { | 139 | { |
135 | wl1271_spi_init(wl); | 140 | wl->if_ops->init(wl); |
136 | } | 141 | } |
137 | 142 | ||
138 | void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, | 143 | void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, |
139 | size_t len, bool fixed) | 144 | size_t len, bool fixed) |
140 | { | 145 | { |
141 | wl1271_spi_raw_write(wl, addr, buf, len, fixed); | 146 | wl->if_ops->write(wl, addr, buf, len, fixed); |
142 | } | 147 | } |
143 | 148 | ||
144 | void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf, | 149 | void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf, |
145 | size_t len, bool fixed) | 150 | size_t len, bool fixed) |
146 | { | 151 | { |
147 | wl1271_spi_raw_read(wl, addr, buf, len, fixed); | 152 | wl->if_ops->read(wl, addr, buf, len, fixed); |
148 | } | 153 | } |
149 | 154 | ||
150 | void wl1271_read(struct wl1271 *wl, int addr, void *buf, size_t len, | 155 | void wl1271_read(struct wl1271 *wl, int addr, void *buf, size_t len, |
@@ -154,7 +159,7 @@ void wl1271_read(struct wl1271 *wl, int addr, void *buf, size_t len, | |||
154 | 159 | ||
155 | physical = wl1271_translate_addr(wl, addr); | 160 | physical = wl1271_translate_addr(wl, addr); |
156 | 161 | ||
157 | wl1271_spi_raw_read(wl, physical, buf, len, fixed); | 162 | wl1271_raw_read(wl, physical, buf, len, fixed); |
158 | } | 163 | } |
159 | 164 | ||
160 | void wl1271_write(struct wl1271 *wl, int addr, void *buf, size_t len, | 165 | void wl1271_write(struct wl1271 *wl, int addr, void *buf, size_t len, |
@@ -164,7 +169,7 @@ void wl1271_write(struct wl1271 *wl, int addr, void *buf, size_t len, | |||
164 | 169 | ||
165 | physical = wl1271_translate_addr(wl, addr); | 170 | physical = wl1271_translate_addr(wl, addr); |
166 | 171 | ||
167 | wl1271_spi_raw_write(wl, physical, buf, len, fixed); | 172 | wl1271_raw_write(wl, physical, buf, len, fixed); |
168 | } | 173 | } |
169 | 174 | ||
170 | u32 wl1271_read32(struct wl1271 *wl, int addr) | 175 | u32 wl1271_read32(struct wl1271 *wl, int addr) |
diff --git a/drivers/net/wireless/wl12xx/wl1271_io.h b/drivers/net/wireless/wl12xx/wl1271_io.h index c8b09718e185..f2b6325ba2a7 100644 --- a/drivers/net/wireless/wl12xx/wl1271_io.h +++ b/drivers/net/wireless/wl12xx/wl1271_io.h | |||
@@ -33,6 +33,8 @@ void wl1271_enable_interrupts(struct wl1271 *wl); | |||
33 | void wl1271_io_reset(struct wl1271 *wl); | 33 | void wl1271_io_reset(struct wl1271 *wl); |
34 | void wl1271_io_init(struct wl1271 *wl); | 34 | void wl1271_io_init(struct wl1271 *wl); |
35 | 35 | ||
36 | struct device *wl1271_wl_to_dev(struct wl1271 *wl); | ||
37 | |||
36 | /* Raw target IO, address is not translated */ | 38 | /* Raw target IO, address is not translated */ |
37 | void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, | 39 | void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, |
38 | size_t len, bool fixed); | 40 | size_t len, bool fixed); |
diff --git a/drivers/net/wireless/wl12xx/wl1271_main.c b/drivers/net/wireless/wl12xx/wl1271_main.c index 18347c3a5e19..6b3fd0005ce0 100644 --- a/drivers/net/wireless/wl12xx/wl1271_main.c +++ b/drivers/net/wireless/wl12xx/wl1271_main.c | |||
@@ -480,7 +480,7 @@ static int wl1271_fetch_firmware(struct wl1271 *wl) | |||
480 | const struct firmware *fw; | 480 | const struct firmware *fw; |
481 | int ret; | 481 | int ret; |
482 | 482 | ||
483 | ret = request_firmware(&fw, WL1271_FW_NAME, &wl->spi->dev); | 483 | ret = request_firmware(&fw, WL1271_FW_NAME, wl1271_wl_to_dev(wl)); |
484 | 484 | ||
485 | if (ret < 0) { | 485 | if (ret < 0) { |
486 | wl1271_error("could not get firmware: %d", ret); | 486 | wl1271_error("could not get firmware: %d", ret); |
@@ -552,7 +552,7 @@ static int wl1271_fetch_nvs(struct wl1271 *wl) | |||
552 | const struct firmware *fw; | 552 | const struct firmware *fw; |
553 | int ret; | 553 | int ret; |
554 | 554 | ||
555 | ret = request_firmware(&fw, WL1271_NVS_NAME, &wl->spi->dev); | 555 | ret = request_firmware(&fw, WL1271_NVS_NAME, wl1271_wl_to_dev(wl)); |
556 | 556 | ||
557 | if (ret < 0) { | 557 | if (ret < 0) { |
558 | wl1271_error("could not get nvs file: %d", ret); | 558 | wl1271_error("could not get nvs file: %d", ret); |
@@ -1973,7 +1973,7 @@ int wl1271_init_ieee80211(struct wl1271 *wl) | |||
1973 | if (wl1271_11a_enabled()) | 1973 | if (wl1271_11a_enabled()) |
1974 | wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wl1271_band_5ghz; | 1974 | wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wl1271_band_5ghz; |
1975 | 1975 | ||
1976 | SET_IEEE80211_DEV(wl->hw, &wl->spi->dev); | 1976 | SET_IEEE80211_DEV(wl->hw, wl1271_wl_to_dev(wl)); |
1977 | 1977 | ||
1978 | return 0; | 1978 | return 0; |
1979 | } | 1979 | } |
diff --git a/drivers/net/wireless/wl12xx/wl1271_spi.c b/drivers/net/wireless/wl12xx/wl1271_spi.c index b422c9fdcd22..a0f416972be2 100644 --- a/drivers/net/wireless/wl12xx/wl1271_spi.c +++ b/drivers/net/wireless/wl12xx/wl1271_spi.c | |||
@@ -33,6 +33,15 @@ | |||
33 | #include "wl1271_spi.h" | 33 | #include "wl1271_spi.h" |
34 | #include "wl1271_io.h" | 34 | #include "wl1271_io.h" |
35 | 35 | ||
36 | static struct spi_device *wl_to_spi(struct wl1271 *wl) | ||
37 | { | ||
38 | return wl->if_priv; | ||
39 | } | ||
40 | |||
41 | static struct device *wl1271_spi_wl_to_dev(struct wl1271 *wl) | ||
42 | { | ||
43 | return &(wl_to_spi(wl)->dev); | ||
44 | } | ||
36 | 45 | ||
37 | void wl1271_spi_disable_interrupts(struct wl1271 *wl) | 46 | void wl1271_spi_disable_interrupts(struct wl1271 *wl) |
38 | { | 47 | { |
@@ -65,7 +74,7 @@ void wl1271_spi_reset(struct wl1271 *wl) | |||
65 | t.len = WSPI_INIT_CMD_LEN; | 74 | t.len = WSPI_INIT_CMD_LEN; |
66 | spi_message_add_tail(&t, &m); | 75 | spi_message_add_tail(&t, &m); |
67 | 76 | ||
68 | spi_sync(wl->spi, &m); | 77 | spi_sync(wl_to_spi(wl), &m); |
69 | 78 | ||
70 | wl1271_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN); | 79 | wl1271_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN); |
71 | } | 80 | } |
@@ -119,7 +128,7 @@ void wl1271_spi_init(struct wl1271 *wl) | |||
119 | t.len = WSPI_INIT_CMD_LEN; | 128 | t.len = WSPI_INIT_CMD_LEN; |
120 | spi_message_add_tail(&t, &m); | 129 | spi_message_add_tail(&t, &m); |
121 | 130 | ||
122 | spi_sync(wl->spi, &m); | 131 | spi_sync(wl_to_spi(wl), &m); |
123 | 132 | ||
124 | wl1271_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN); | 133 | wl1271_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN); |
125 | } | 134 | } |
@@ -151,7 +160,7 @@ static void wl1271_spi_read_busy(struct wl1271 *wl, void *buf, size_t len) | |||
151 | t[0].rx_buf = buf + (len - num_busy_bytes); | 160 | t[0].rx_buf = buf + (len - num_busy_bytes); |
152 | t[0].len = num_busy_bytes; | 161 | t[0].len = num_busy_bytes; |
153 | spi_message_add_tail(&t[0], &m); | 162 | spi_message_add_tail(&t[0], &m); |
154 | spi_sync(wl->spi, &m); | 163 | spi_sync(wl_to_spi(wl), &m); |
155 | return; | 164 | return; |
156 | } | 165 | } |
157 | } | 166 | } |
@@ -171,7 +180,7 @@ static void wl1271_spi_read_busy(struct wl1271 *wl, void *buf, size_t len) | |||
171 | t[0].rx_buf = busy_buf; | 180 | t[0].rx_buf = busy_buf; |
172 | t[0].len = sizeof(u32); | 181 | t[0].len = sizeof(u32); |
173 | spi_message_add_tail(&t[0], &m); | 182 | spi_message_add_tail(&t[0], &m); |
174 | spi_sync(wl->spi, &m); | 183 | spi_sync(wl_to_spi(wl), &m); |
175 | 184 | ||
176 | if (*busy_buf & 0x1) { | 185 | if (*busy_buf & 0x1) { |
177 | spi_message_init(&m); | 186 | spi_message_init(&m); |
@@ -179,7 +188,7 @@ static void wl1271_spi_read_busy(struct wl1271 *wl, void *buf, size_t len) | |||
179 | t[0].rx_buf = buf; | 188 | t[0].rx_buf = buf; |
180 | t[0].len = len; | 189 | t[0].len = len; |
181 | spi_message_add_tail(&t[0], &m); | 190 | spi_message_add_tail(&t[0], &m); |
182 | spi_sync(wl->spi, &m); | 191 | spi_sync(wl_to_spi(wl), &m); |
183 | return; | 192 | return; |
184 | } | 193 | } |
185 | } | 194 | } |
@@ -225,7 +234,7 @@ void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf, | |||
225 | t[2].len = len; | 234 | t[2].len = len; |
226 | spi_message_add_tail(&t[2], &m); | 235 | spi_message_add_tail(&t[2], &m); |
227 | 236 | ||
228 | spi_sync(wl->spi, &m); | 237 | spi_sync(wl_to_spi(wl), &m); |
229 | 238 | ||
230 | /* FIXME: Check busy words, removed due to SPI bug */ | 239 | /* FIXME: Check busy words, removed due to SPI bug */ |
231 | /* if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1)) | 240 | /* if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1)) |
@@ -263,7 +272,7 @@ void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf, | |||
263 | t[1].len = len; | 272 | t[1].len = len; |
264 | spi_message_add_tail(&t[1], &m); | 273 | spi_message_add_tail(&t[1], &m); |
265 | 274 | ||
266 | spi_sync(wl->spi, &m); | 275 | spi_sync(wl_to_spi(wl), &m); |
267 | 276 | ||
268 | wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd)); | 277 | wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd)); |
269 | wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, len); | 278 | wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, len); |
@@ -306,6 +315,16 @@ static struct platform_device wl1271_device = { | |||
306 | }, | 315 | }, |
307 | }; | 316 | }; |
308 | 317 | ||
318 | static struct wl1271_if_operations spi_ops = { | ||
319 | .read = wl1271_spi_raw_read, | ||
320 | .write = wl1271_spi_raw_write, | ||
321 | .reset = wl1271_spi_reset, | ||
322 | .init = wl1271_spi_init, | ||
323 | .dev = wl1271_spi_wl_to_dev, | ||
324 | .enable_irq = wl1271_spi_enable_interrupts, | ||
325 | .disable_irq = wl1271_spi_disable_interrupts | ||
326 | }; | ||
327 | |||
309 | static int __devinit wl1271_probe(struct spi_device *spi) | 328 | static int __devinit wl1271_probe(struct spi_device *spi) |
310 | { | 329 | { |
311 | struct wl12xx_platform_data *pdata; | 330 | struct wl12xx_platform_data *pdata; |
@@ -326,7 +345,9 @@ static int __devinit wl1271_probe(struct spi_device *spi) | |||
326 | wl = hw->priv; | 345 | wl = hw->priv; |
327 | 346 | ||
328 | dev_set_drvdata(&spi->dev, wl); | 347 | dev_set_drvdata(&spi->dev, wl); |
329 | wl->spi = spi; | 348 | wl->if_priv = spi; |
349 | |||
350 | wl->if_ops = &spi_ops; | ||
330 | 351 | ||
331 | /* This is the only SPI value that we need to set here, the rest | 352 | /* This is the only SPI value that we need to set here, the rest |
332 | * comes from the board-peripherals file */ | 353 | * comes from the board-peripherals file */ |