[PATCH 10/19] staging/wilc1000: unify device pointer

2015-11-16 Thread Arnd Bergmann
struct wilc has two pointers to store the device, one for sdio_func
and one for spi_device. By changing the pointer to a 'struct device',
we can simplify the logic and avoid a few #ifdefs.

Signed-off-by: Arnd Bergmann 
---
 drivers/staging/wilc1000/linux_wlan.c | 25 +++-
 drivers/staging/wilc1000/linux_wlan_sdio.c| 33 +--
 drivers/staging/wilc1000/linux_wlan_spi.c | 22 --
 drivers/staging/wilc1000/wilc_wfi_netdevice.h |  6 +
 4 files changed, 30 insertions(+), 56 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index 876bcfb3b546..faad01f6f2d1 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -453,19 +453,11 @@ int wilc_wlan_get_firmware(struct net_device *dev)
goto _fail_;
}
 
-#ifdef WILC_SDIO
-   if (request_firmware(_firmware, firmware, 
>wilc_sdio_func->dev) != 0) {
-   PRINT_ER("%s - firmare not available\n", firmware);
-   ret = -1;
-   goto _fail_;
-   }
-#else
-   if (request_firmware(_firmware, firmware, >wilc_spidev->dev) 
!= 0) {
+   if (request_firmware(_firmware, firmware, wilc->dev) != 0) {
PRINT_ER("%s - firmare not available\n", firmware);
ret = -1;
goto _fail_;
}
-#endif
wilc->firmware = wilc_firmware;
 
 _fail_:
@@ -1015,12 +1007,11 @@ int wilc_mac_open(struct net_device *ndev)
nic = netdev_priv(ndev);
wl = nic->wilc;
 
-#ifdef WILC_SPI
-   if (!wl || !wl->wilc_spidev) {
+   if (!wl|| !wl->dev) {
netdev_err(ndev, "wilc1000: SPI device not ready\n");
return -ENODEV;
}
-#endif
+
nic = netdev_priv(ndev);
priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev);
@@ -1505,15 +1496,5 @@ int wilc_netdev_init(struct wilc **wilc)
nic->mac_opened = 0;
}
 
-   #ifndef WILC_SDIO
-   if (!wilc_spi_init()) {
-   PRINT_ER("Can't initialize SPI\n");
-   return -1;
-   }
-   wilc_dev->wilc_spidev = wilc_spi_dev;
-   #else
-   wilc_dev->wilc_sdio_func = wilc_sdio_func;
-   #endif
-
return 0;
 }
diff --git a/drivers/staging/wilc1000/linux_wlan_sdio.c 
b/drivers/staging/wilc1000/linux_wlan_sdio.c
index 06fd0e600c2a..8df69b2aff2d 100644
--- a/drivers/staging/wilc1000/linux_wlan_sdio.c
+++ b/drivers/staging/wilc1000/linux_wlan_sdio.c
@@ -21,13 +21,7 @@
  #define MAX_SPEED (6 * 100) /* Max 50M */
 #endif
 
-struct wilc_sdio {
-   struct sdio_func *func;
-   struct wilc *wilc;
-};
-
 struct sdio_func *wilc_sdio_func;
-
 static unsigned int sdio_default_speed;
 
 #define SDIO_VENDOR_ID_WILC 0x0296
@@ -42,12 +36,8 @@ static const struct sdio_device_id wilc_sdio_ids[] = {
 #ifndef WILC_SDIO_IRQ_GPIO
 static void wilc_sdio_interrupt(struct sdio_func *func)
 {
-   struct wilc_sdio *wl_sdio;
-
-   wl_sdio = sdio_get_drvdata(func);
-
sdio_release_host(func);
-   wilc_handle_isr(wl_sdio->wilc);
+   wilc_handle_isr(sdio_get_drvdata(func));
sdio_claim_host(func);
 }
 #endif
@@ -55,7 +45,7 @@ static void wilc_sdio_interrupt(struct sdio_func *func)
 
 int wilc_sdio_cmd52(sdio_cmd52_t *cmd)
 {
-   struct sdio_func *func = wilc_dev->wilc_sdio_func;
+   struct sdio_func *func = container_of(wilc_dev->dev, struct sdio_func, 
dev);
int ret;
u8 data;
 
@@ -87,7 +77,7 @@ int wilc_sdio_cmd52(sdio_cmd52_t *cmd)
 
 int wilc_sdio_cmd53(sdio_cmd53_t *cmd)
 {
-   struct sdio_func *func = wilc_dev->wilc_sdio_func;
+   struct sdio_func *func = container_of(wilc_dev->dev, struct sdio_func, 
dev);
int size, ret;
 
sdio_claim_host(func);
@@ -118,24 +108,17 @@ int wilc_sdio_cmd53(sdio_cmd53_t *cmd)
 
 static int linux_sdio_probe(struct sdio_func *func, const struct 
sdio_device_id *id)
 {
-   struct wilc_sdio *wl_sdio;
struct wilc *wilc;
 
-   PRINT_D(INIT_DBG, "probe function\n");
-   wl_sdio = kzalloc(sizeof(struct wilc_sdio), GFP_KERNEL);
-   if (!wl_sdio)
-   return -ENOMEM;
 
PRINT_D(INIT_DBG, "Initializing netdev\n");
wilc_sdio_func = func;
if (wilc_netdev_init()) {
PRINT_ER("Couldn't initialize netdev\n");
-   kfree(wl_sdio);
return -1;
}
-   wl_sdio->func = func;
-   wl_sdio->wilc = wilc;
-   sdio_set_drvdata(func, wl_sdio);
+   sdio_set_drvdata(func, wilc);
+   wilc->dev = >dev;
 
printk("Driver Initializing success\n");
return 0;
@@ -143,11 +126,7 @@ static int linux_sdio_probe(struct sdio_func *func, const 
struct sdio_device_id
 
 static void linux_sdio_remove(struct sdio_func *func)
 {
-   struct wilc_sdio *wl_sdio;
-
-   wl_sdio = 

[PATCH 10/19] staging/wilc1000: unify device pointer

2015-10-20 Thread Arnd Bergmann
struct wilc has two pointers to store the device, one for sdio_func
and one for spi_device. By changing the pointer to a 'struct device',
we can simplify the logic and avoid a few #ifdefs.

Signed-off-by: Arnd Bergmann 
---
 drivers/staging/wilc1000/linux_wlan.c | 29 +--
 drivers/staging/wilc1000/linux_wlan_sdio.c|  5 +++--
 drivers/staging/wilc1000/linux_wlan_spi.c | 17 +++-
 drivers/staging/wilc1000/wilc_wfi_netdevice.h |  6 +-
 4 files changed, 25 insertions(+), 32 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index caa85442c12d..4ca045bcf537 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -474,19 +474,11 @@ int wilc1000_wlan_get_firmware(perInterface_wlan_t *p_nic)
/*  the firmare should be located in /lib/firmware in
 *  root file system with the name specified above */
 
-#ifdef WILC_SDIO
-   if (request_firmware(_firmware, firmware, 
_dev->wilc_sdio_func->dev) != 0) {
+   if (request_firmware(_firmware, firmware, wilc1000_dev->dev) != 0) 
{
PRINT_ER("%s - firmare not available\n", firmware);
ret = -1;
goto _fail_;
}
-#else
-   if (request_firmware(_firmware, firmware, 
_dev->wilc_spidev->dev) != 0) {
-   PRINT_ER("%s - firmare not available\n", firmware);
-   ret = -1;
-   goto _fail_;
-   }
-#endif
wilc1000_dev->wilc_firmware = wilc_firmware;
 
 _fail_:
@@ -1008,7 +1000,7 @@ static u8 wilc1000_prepare_11b_core(struct wilc *nic)
while (!wilc1000_probe)
msleep(100);
wilc1000_probe = 0;
-   wilc1000_dev->wilc_sdio_func = wilc1000_sdio_func;
+   wilc1000_dev->dev = _sdio_func->dev;
nic->ops = _sdio_ops;
wilc_wlan_init(nic);
}
@@ -1031,7 +1023,7 @@ static int repeat_power_cycle(perInterface_wlan_t *nic)
while (!wilc1000_probe)
msleep(100);
wilc1000_probe = 0;
-   wilc1000_dev->wilc_sdio_func = wilc1000_sdio_func;
+   wilc1000_dev->dev = _sdio_func->dev;
wilc1000_dev->ops = _sdio_ops;
ret = wilc_wlan_init(wilc1000_dev);
 
@@ -1214,12 +1206,11 @@ int wilc1000_mac_open(struct net_device *ndev)
int i = 0;
struct wilc_priv *priv;
 
-#ifdef WILC_SPI
-   if (!wilc1000_dev || !wilc1000_dev->wilc_spidev) {
+   if (!wilc1000_dev || !wilc1000_dev->dev) {
netdev_err(ndev, "wilc1000: SPI device not ready\n");
return -ENODEV;
}
-#endif
+
nic = netdev_priv(ndev);
priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev);
@@ -1712,16 +1703,6 @@ int wilc_netdev_init(void)
 
}
 
-   #ifndef WILC_SDIO
-   if (!wilc1000_spi_init(_dev->wilc_spidev)) {
-   PRINT_ER("Can't initialize SPI\n");
-   return -1; /* ERROR */
-   }
-   wilc1000_dev->wilc_spidev = wilc_spi_dev;
-   #else
-   wilc1000_dev->wilc_sdio_func = wilc1000_sdio_func;
-   #endif
-
return 0;
 }
 
diff --git a/drivers/staging/wilc1000/linux_wlan_sdio.c 
b/drivers/staging/wilc1000/linux_wlan_sdio.c
index badcae57875c..a6ae26739dd8 100644
--- a/drivers/staging/wilc1000/linux_wlan_sdio.c
+++ b/drivers/staging/wilc1000/linux_wlan_sdio.c
@@ -46,7 +46,7 @@ static void wilc_sdio_interrupt(struct sdio_func *func)
 
 int wilc1000_sdio_cmd52(sdio_cmd52_t *cmd)
 {
-   struct sdio_func *func = wilc1000_dev->wilc_sdio_func;
+   struct sdio_func *func = container_of(wilc1000_dev->dev, struct 
sdio_func, dev);
int ret;
u8 data;
 
@@ -78,7 +78,7 @@ int wilc1000_sdio_cmd52(sdio_cmd52_t *cmd)
 
 int wilc1000_sdio_cmd53(sdio_cmd53_t *cmd)
 {
-   struct sdio_func *func = wilc1000_dev->wilc_sdio_func;
+   struct sdio_func *func = container_of(wilc1000_dev->dev, struct 
sdio_func, dev);
int size, ret;
 
sdio_claim_host(func);
@@ -126,6 +126,7 @@ static int linux_sdio_probe(struct sdio_func *func, const 
struct sdio_device_id
PRINT_ER("Couldn't initialize netdev\n");
return -1;
}
+   wilc1000_dev->dev = _sdio_func->dev;
 
printk("Driver Initializing success\n");
return 0;
diff --git a/drivers/staging/wilc1000/linux_wlan_spi.c 
b/drivers/staging/wilc1000/linux_wlan_spi.c
index c90b741824dc..b5e9a1b9f509 100644
--- a/drivers/staging/wilc1000/linux_wlan_spi.c
+++ b/drivers/staging/wilc1000/linux_wlan_spi.c
@@ -9,8 +9,11 @@
 #include 
 #include 
 
+#include "wilc_wfi_netdevice.h"
 #include "linux_wlan_common.h"
 #include "linux_wlan_spi.h"
+#include "wilc_wlan_if.h"
+#include "wilc_wlan.h"
 
 #define USE_SPI_DMA 0   /* johnny add */
 
@@ -409,8 +412,20 @@ int wilc1000_spi_set_max_speed(void)