wl1251: fix ELP_CTRL register accesses when using SDIO
authorGrazvydas Ignotas <notasas@gmail.com>
Thu, 11 Mar 2010 15:44:57 +0000 (17:44 +0200)
committerJohn W. Linville <linville@tuxdriver.com>
Mon, 15 Mar 2010 19:32:03 +0000 (15:32 -0400)
For some unknown reason ELP_CTRL can't be accesed using
sdio_memcpy_* functions (any attemts to do so result in timeouts):

 wl1251: ERROR sdio write failed (-110)
 wl1251: ERROR sdio read failed (-110)
 wl1251: WARNING WLAN not ready

To fix this, add special IO functions for ELP_CTRL access that are
using sdio_readb/sdio_writeb. Similar handling is done in TI
reference driver from Android code drop.

Signed-off-by: Grazvydas Ignotas <notasas@gmail.com>
Cc: Bob Copeland <me@bobcopeland.com>
Acked-by: Kalle Valo <kalle.valo@iki.fi>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/wl12xx/wl1251.h
drivers/net/wireless/wl12xx/wl1251_io.h
drivers/net/wireless/wl12xx/wl1251_main.c
drivers/net/wireless/wl12xx/wl1251_ps.c
drivers/net/wireless/wl12xx/wl1251_sdio.c

index 37c61c19cae5da8f99b95bc674abcd57c560ffb3..4f5f02a26e6272887fabf4f896915f8b916c782f 100644 (file)
@@ -256,6 +256,8 @@ struct wl1251_debugfs {
 struct wl1251_if_operations {
        void (*read)(struct wl1251 *wl, int addr, void *buf, size_t len);
        void (*write)(struct wl1251 *wl, int addr, void *buf, size_t len);
+       void (*read_elp)(struct wl1251 *wl, int addr, u32 *val);
+       void (*write_elp)(struct wl1251 *wl, int addr, u32 val);
        void (*reset)(struct wl1251 *wl);
        void (*enable_irq)(struct wl1251 *wl);
        void (*disable_irq)(struct wl1251 *wl);
index b89d2ac62efb04275e0e5f49073a31e3082d16c6..c545e9d5f512a34f2cc8a61e847f829dc74d73bc 100644 (file)
@@ -48,6 +48,26 @@ static inline void wl1251_write32(struct wl1251 *wl, int addr, u32 val)
        wl->if_ops->write(wl, addr, &val, sizeof(u32));
 }
 
+static inline u32 wl1251_read_elp(struct wl1251 *wl, int addr)
+{
+       u32 response;
+
+       if (wl->if_ops->read_elp)
+               wl->if_ops->read_elp(wl, addr, &response);
+       else
+               wl->if_ops->read(wl, addr, &response, sizeof(u32));
+
+       return response;
+}
+
+static inline void wl1251_write_elp(struct wl1251 *wl, int addr, u32 val)
+{
+       if (wl->if_ops->write_elp)
+               wl->if_ops->write_elp(wl, addr, val);
+       else
+               wl->if_ops->write(wl, addr, &val, sizeof(u32));
+}
+
 /* Memory target IO, address is translated to partition 0 */
 void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len);
 void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len);
index 24ae6a360ac8f6e09ca719e6f48bfede224df683..0155653b7105b6fc57afa52cb5ce7d7e4a321242 100644 (file)
@@ -146,8 +146,8 @@ static void wl1251_fw_wakeup(struct wl1251 *wl)
        u32 elp_reg;
 
        elp_reg = ELPCTRL_WAKE_UP;
-       wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
-       elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
+       wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
+       elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
 
        if (!(elp_reg & ELPCTRL_WLAN_READY))
                wl1251_warning("WLAN not ready");
index 851dfb65e474eb80a916a802a42b5e0d38b42a20..b55cb2bd459aa0d278556f3b81d5ca7701fe209d 100644 (file)
@@ -45,7 +45,7 @@ void wl1251_elp_work(struct work_struct *work)
                goto out;
 
        wl1251_debug(DEBUG_PSM, "chip to elp");
-       wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
+       wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
        wl->elp = true;
 
 out:
@@ -79,9 +79,9 @@ int wl1251_ps_elp_wakeup(struct wl1251 *wl)
        start = jiffies;
        timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT);
 
-       wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
+       wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
 
-       elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
+       elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
 
        /*
         * FIXME: we should wait for irq from chip but, as a temporary
@@ -93,7 +93,7 @@ int wl1251_ps_elp_wakeup(struct wl1251 *wl)
                        return -ETIMEDOUT;
                }
                msleep(1);
-               elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
+               elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
        }
 
        wl1251_debug(DEBUG_PSM, "wakeup time: %u ms",
index cfca232dc8cb30ef8ba246621346a0b064adcedf..2051ef06e9ecbf3650051495acb4e68c12add062 100644 (file)
@@ -82,6 +82,32 @@ static void wl1251_sdio_write(struct wl1251 *wl, int addr,
        sdio_release_host(func);
 }
 
+static void wl1251_sdio_read_elp(struct wl1251 *wl, int addr, u32 *val)
+{
+       int ret = 0;
+       struct sdio_func *func = wl_to_func(wl);
+
+       sdio_claim_host(func);
+       *val = sdio_readb(func, addr, &ret);
+       sdio_release_host(func);
+
+       if (ret)
+               wl1251_error("sdio_readb failed (%d)", ret);
+}
+
+static void wl1251_sdio_write_elp(struct wl1251 *wl, int addr, u32 val)
+{
+       int ret = 0;
+       struct sdio_func *func = wl_to_func(wl);
+
+       sdio_claim_host(func);
+       sdio_writeb(func, val, addr, &ret);
+       sdio_release_host(func);
+
+       if (ret)
+               wl1251_error("sdio_writeb failed (%d)", ret);
+}
+
 static void wl1251_sdio_reset(struct wl1251 *wl)
 {
 }
@@ -111,6 +137,8 @@ static void wl1251_sdio_set_power(bool enable)
 static const struct wl1251_if_operations wl1251_sdio_ops = {
        .read = wl1251_sdio_read,
        .write = wl1251_sdio_write,
+       .write_elp = wl1251_sdio_write_elp,
+       .read_elp = wl1251_sdio_read_elp,
        .reset = wl1251_sdio_reset,
        .enable_irq = wl1251_sdio_enable_irq,
        .disable_irq = wl1251_sdio_disable_irq,