Commit 8197b711 authored by Teemu Paasikivi's avatar Teemu Paasikivi Committed by John W. Linville

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: default avatarTeemu Paasikivi <ext-teemu.3.paasikivi@nokia.com>
Reviewed-by: default avatarJuuso Oikarinen <juuso.oikarinen@nokia.com>
Signed-off-by: default avatarJuuso Oikarinen <juuso.oikarinen@nokia.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 54f7e503
...@@ -334,11 +334,25 @@ struct wl1271_scan { ...@@ -334,11 +334,25 @@ struct wl1271_scan {
u8 probe_requests; u8 probe_requests;
}; };
struct wl1271_if_operations {
void (*read)(struct wl1271 *wl, int addr, void *buf, size_t len,
bool fixed);
void (*write)(struct wl1271 *wl, int addr, void *buf, size_t len,
bool fixed);
void (*reset)(struct wl1271 *wl);
void (*init)(struct wl1271 *wl);
struct device* (*dev)(struct wl1271 *wl);
void (*enable_irq)(struct wl1271 *wl);
void (*disable_irq)(struct wl1271 *wl);
};
struct wl1271 { struct wl1271 {
struct ieee80211_hw *hw; struct ieee80211_hw *hw;
bool mac80211_registered; bool mac80211_registered;
struct spi_device *spi; void *if_priv;
struct wl1271_if_operations *if_ops;
void (*set_power)(bool enable); void (*set_power)(bool enable);
int irq; int irq;
......
...@@ -31,14 +31,19 @@ ...@@ -31,14 +31,19 @@
#include "wl1271_spi.h" #include "wl1271_spi.h"
#include "wl1271_io.h" #include "wl1271_io.h"
struct device *wl1271_wl_to_dev(struct wl1271 *wl)
{
return wl->if_ops->dev(wl);
}
void wl1271_disable_interrupts(struct wl1271 *wl) void wl1271_disable_interrupts(struct wl1271 *wl)
{ {
wl1271_spi_disable_interrupts(wl); wl->if_ops->disable_irq(wl);
} }
void wl1271_enable_interrupts(struct wl1271 *wl) void wl1271_enable_interrupts(struct wl1271 *wl)
{ {
wl1271_spi_enable_interrupts(wl); wl->if_ops->enable_irq(wl);
} }
static int wl1271_translate_addr(struct wl1271 *wl, int addr) static int wl1271_translate_addr(struct wl1271 *wl, int addr)
...@@ -127,24 +132,24 @@ int wl1271_set_partition(struct wl1271 *wl, ...@@ -127,24 +132,24 @@ int wl1271_set_partition(struct wl1271 *wl,
void wl1271_io_reset(struct wl1271 *wl) void wl1271_io_reset(struct wl1271 *wl)
{ {
wl1271_spi_reset(wl); wl->if_ops->reset(wl);
} }
void wl1271_io_init(struct wl1271 *wl) void wl1271_io_init(struct wl1271 *wl)
{ {
wl1271_spi_init(wl); wl->if_ops->init(wl);
} }
void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
size_t len, bool fixed) size_t len, bool fixed)
{ {
wl1271_spi_raw_write(wl, addr, buf, len, fixed); wl->if_ops->write(wl, addr, buf, len, fixed);
} }
void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf, void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
size_t len, bool fixed) size_t len, bool fixed)
{ {
wl1271_spi_raw_read(wl, addr, buf, len, fixed); wl->if_ops->read(wl, addr, buf, len, fixed);
} }
void wl1271_read(struct wl1271 *wl, int addr, void *buf, size_t len, 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,7 +159,7 @@ void wl1271_read(struct wl1271 *wl, int addr, void *buf, size_t len,
physical = wl1271_translate_addr(wl, addr); physical = wl1271_translate_addr(wl, addr);
wl1271_spi_raw_read(wl, physical, buf, len, fixed); wl1271_raw_read(wl, physical, buf, len, fixed);
} }
void wl1271_write(struct wl1271 *wl, int addr, void *buf, size_t len, 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,7 +169,7 @@ void wl1271_write(struct wl1271 *wl, int addr, void *buf, size_t len,
physical = wl1271_translate_addr(wl, addr); physical = wl1271_translate_addr(wl, addr);
wl1271_spi_raw_write(wl, physical, buf, len, fixed); wl1271_raw_write(wl, physical, buf, len, fixed);
} }
u32 wl1271_read32(struct wl1271 *wl, int addr) u32 wl1271_read32(struct wl1271 *wl, int addr)
......
...@@ -33,6 +33,8 @@ void wl1271_enable_interrupts(struct wl1271 *wl); ...@@ -33,6 +33,8 @@ void wl1271_enable_interrupts(struct wl1271 *wl);
void wl1271_io_reset(struct wl1271 *wl); void wl1271_io_reset(struct wl1271 *wl);
void wl1271_io_init(struct wl1271 *wl); void wl1271_io_init(struct wl1271 *wl);
struct device *wl1271_wl_to_dev(struct wl1271 *wl);
/* Raw target IO, address is not translated */ /* Raw target IO, address is not translated */
void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
size_t len, bool fixed); size_t len, bool fixed);
......
...@@ -480,7 +480,7 @@ static int wl1271_fetch_firmware(struct wl1271 *wl) ...@@ -480,7 +480,7 @@ static int wl1271_fetch_firmware(struct wl1271 *wl)
const struct firmware *fw; const struct firmware *fw;
int ret; int ret;
ret = request_firmware(&fw, WL1271_FW_NAME, &wl->spi->dev); ret = request_firmware(&fw, WL1271_FW_NAME, wl1271_wl_to_dev(wl));
if (ret < 0) { if (ret < 0) {
wl1271_error("could not get firmware: %d", ret); wl1271_error("could not get firmware: %d", ret);
...@@ -552,7 +552,7 @@ static int wl1271_fetch_nvs(struct wl1271 *wl) ...@@ -552,7 +552,7 @@ static int wl1271_fetch_nvs(struct wl1271 *wl)
const struct firmware *fw; const struct firmware *fw;
int ret; int ret;
ret = request_firmware(&fw, WL1271_NVS_NAME, &wl->spi->dev); ret = request_firmware(&fw, WL1271_NVS_NAME, wl1271_wl_to_dev(wl));
if (ret < 0) { if (ret < 0) {
wl1271_error("could not get nvs file: %d", ret); wl1271_error("could not get nvs file: %d", ret);
...@@ -1973,7 +1973,7 @@ int wl1271_init_ieee80211(struct wl1271 *wl) ...@@ -1973,7 +1973,7 @@ int wl1271_init_ieee80211(struct wl1271 *wl)
if (wl1271_11a_enabled()) if (wl1271_11a_enabled())
wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wl1271_band_5ghz; wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wl1271_band_5ghz;
SET_IEEE80211_DEV(wl->hw, &wl->spi->dev); SET_IEEE80211_DEV(wl->hw, wl1271_wl_to_dev(wl));
return 0; return 0;
} }
......
...@@ -33,6 +33,15 @@ ...@@ -33,6 +33,15 @@
#include "wl1271_spi.h" #include "wl1271_spi.h"
#include "wl1271_io.h" #include "wl1271_io.h"
static struct spi_device *wl_to_spi(struct wl1271 *wl)
{
return wl->if_priv;
}
static struct device *wl1271_spi_wl_to_dev(struct wl1271 *wl)
{
return &(wl_to_spi(wl)->dev);
}
void wl1271_spi_disable_interrupts(struct wl1271 *wl) void wl1271_spi_disable_interrupts(struct wl1271 *wl)
{ {
...@@ -65,7 +74,7 @@ void wl1271_spi_reset(struct wl1271 *wl) ...@@ -65,7 +74,7 @@ void wl1271_spi_reset(struct wl1271 *wl)
t.len = WSPI_INIT_CMD_LEN; t.len = WSPI_INIT_CMD_LEN;
spi_message_add_tail(&t, &m); spi_message_add_tail(&t, &m);
spi_sync(wl->spi, &m); spi_sync(wl_to_spi(wl), &m);
wl1271_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN); wl1271_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
} }
...@@ -119,7 +128,7 @@ void wl1271_spi_init(struct wl1271 *wl) ...@@ -119,7 +128,7 @@ void wl1271_spi_init(struct wl1271 *wl)
t.len = WSPI_INIT_CMD_LEN; t.len = WSPI_INIT_CMD_LEN;
spi_message_add_tail(&t, &m); spi_message_add_tail(&t, &m);
spi_sync(wl->spi, &m); spi_sync(wl_to_spi(wl), &m);
wl1271_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN); wl1271_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
} }
...@@ -151,7 +160,7 @@ static void wl1271_spi_read_busy(struct wl1271 *wl, void *buf, size_t len) ...@@ -151,7 +160,7 @@ static void wl1271_spi_read_busy(struct wl1271 *wl, void *buf, size_t len)
t[0].rx_buf = buf + (len - num_busy_bytes); t[0].rx_buf = buf + (len - num_busy_bytes);
t[0].len = num_busy_bytes; t[0].len = num_busy_bytes;
spi_message_add_tail(&t[0], &m); spi_message_add_tail(&t[0], &m);
spi_sync(wl->spi, &m); spi_sync(wl_to_spi(wl), &m);
return; return;
} }
} }
...@@ -171,7 +180,7 @@ static void wl1271_spi_read_busy(struct wl1271 *wl, void *buf, size_t len) ...@@ -171,7 +180,7 @@ static void wl1271_spi_read_busy(struct wl1271 *wl, void *buf, size_t len)
t[0].rx_buf = busy_buf; t[0].rx_buf = busy_buf;
t[0].len = sizeof(u32); t[0].len = sizeof(u32);
spi_message_add_tail(&t[0], &m); spi_message_add_tail(&t[0], &m);
spi_sync(wl->spi, &m); spi_sync(wl_to_spi(wl), &m);
if (*busy_buf & 0x1) { if (*busy_buf & 0x1) {
spi_message_init(&m); spi_message_init(&m);
...@@ -179,7 +188,7 @@ static void wl1271_spi_read_busy(struct wl1271 *wl, void *buf, size_t len) ...@@ -179,7 +188,7 @@ static void wl1271_spi_read_busy(struct wl1271 *wl, void *buf, size_t len)
t[0].rx_buf = buf; t[0].rx_buf = buf;
t[0].len = len; t[0].len = len;
spi_message_add_tail(&t[0], &m); spi_message_add_tail(&t[0], &m);
spi_sync(wl->spi, &m); spi_sync(wl_to_spi(wl), &m);
return; return;
} }
} }
...@@ -225,7 +234,7 @@ void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf, ...@@ -225,7 +234,7 @@ void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
t[2].len = len; t[2].len = len;
spi_message_add_tail(&t[2], &m); spi_message_add_tail(&t[2], &m);
spi_sync(wl->spi, &m); spi_sync(wl_to_spi(wl), &m);
/* FIXME: Check busy words, removed due to SPI bug */ /* FIXME: Check busy words, removed due to SPI bug */
/* if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1)) /* 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,7 +272,7 @@ void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
t[1].len = len; t[1].len = len;
spi_message_add_tail(&t[1], &m); spi_message_add_tail(&t[1], &m);
spi_sync(wl->spi, &m); spi_sync(wl_to_spi(wl), &m);
wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd)); wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd));
wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, len); wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, len);
...@@ -306,6 +315,16 @@ static struct platform_device wl1271_device = { ...@@ -306,6 +315,16 @@ static struct platform_device wl1271_device = {
}, },
}; };
static struct wl1271_if_operations spi_ops = {
.read = wl1271_spi_raw_read,
.write = wl1271_spi_raw_write,
.reset = wl1271_spi_reset,
.init = wl1271_spi_init,
.dev = wl1271_spi_wl_to_dev,
.enable_irq = wl1271_spi_enable_interrupts,
.disable_irq = wl1271_spi_disable_interrupts
};
static int __devinit wl1271_probe(struct spi_device *spi) static int __devinit wl1271_probe(struct spi_device *spi)
{ {
struct wl12xx_platform_data *pdata; struct wl12xx_platform_data *pdata;
...@@ -326,7 +345,9 @@ static int __devinit wl1271_probe(struct spi_device *spi) ...@@ -326,7 +345,9 @@ static int __devinit wl1271_probe(struct spi_device *spi)
wl = hw->priv; wl = hw->priv;
dev_set_drvdata(&spi->dev, wl); dev_set_drvdata(&spi->dev, wl);
wl->spi = spi; wl->if_priv = spi;
wl->if_ops = &spi_ops;
/* This is the only SPI value that we need to set here, the rest /* This is the only SPI value that we need to set here, the rest
* comes from the board-peripherals file */ * comes from the board-peripherals file */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment