From: Arnd Bergmann <arnd@arndb.de>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Johnny Kim <johnny.kim@atmel.com>,
Austin Shin <austin.shin@atmel.com>,
Chris Park <chris.park@atmel.com>, Tony Cho <tony.cho@atmel.com>,
Glen Lee <glen.lee@atmel.com>, Leo Kim <leo.kim@atmel.com>,
linux-wireless@vger.kernel.org, devel@driverdev.osuosl.org,
linux-kernel@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>
Subject: [PATCH 18/19] staging/wilc1000: use more regular probing
Date: Mon, 16 Nov 2015 15:05:09 +0100 [thread overview]
Message-ID: <1447682710-2908925-19-git-send-email-arnd@arndb.de> (raw)
In-Reply-To: <1447682710-2908925-1-git-send-email-arnd@arndb.de>
So far, my patches tried to do equivalent conversions of the
existing code. This one goes beyond that by restructuring
how the devices get probed. In particular, the spi driver
no longer creates the netdev until the device is probed,
and I've removed the global wilc_sdio_func and wilc_spi_dev
variables in favor of retrieving them from the wilc_dev
variable that will eventually get passed through all functions
instead of using a global.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/staging/wilc1000/linux_wlan.c | 6 +-
drivers/staging/wilc1000/linux_wlan_common.h | 12 ---
drivers/staging/wilc1000/linux_wlan_sdio.c | 30 +++----
drivers/staging/wilc1000/linux_wlan_spi.c | 122 +++++++++------------------
drivers/staging/wilc1000/wilc_debugfs.c | 6 +-
5 files changed, 58 insertions(+), 118 deletions(-)
diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 0d6c22ca7920..c3b521e085f2 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -1408,10 +1408,6 @@ void wilc_netdev_cleanup(struct wilc *wilc)
}
kfree(wilc);
-
-#if defined(WILC_DEBUGFS)
- wilc_debugfs_remove();
-#endif
}
EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
@@ -1491,3 +1487,5 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
return 0;
}
EXPORT_SYMBOL_GPL(wilc_netdev_init);
+
+MODULE_LICENSE("GPL");
diff --git a/drivers/staging/wilc1000/linux_wlan_common.h b/drivers/staging/wilc1000/linux_wlan_common.h
index f2ea8280b8f8..72b524a98cba 100644
--- a/drivers/staging/wilc1000/linux_wlan_common.h
+++ b/drivers/staging/wilc1000/linux_wlan_common.h
@@ -38,9 +38,6 @@ enum debug_region {
#define FIRM_DBG (1 << Firmware_debug)
#if defined (WILC_DEBUGFS)
-int wilc_debugfs_init(void);
-void wilc_debugfs_remove(void);
-
extern atomic_t WILC_REGION;
extern atomic_t WILC_DEBUG_LEVEL;
@@ -122,15 +119,6 @@ extern atomic_t WILC_DEBUG_LEVEL;
printk(__VA_ARGS__); \
} while (0)
-static inline int wilc_debugfs_init(void)
-{
- return 0;
-}
-
-static inline void wilc_debugfs_remove(void)
-{
-}
-
#endif
#define FN_IN /* PRINT_D(">>> \n") */
diff --git a/drivers/staging/wilc1000/linux_wlan_sdio.c b/drivers/staging/wilc1000/linux_wlan_sdio.c
index 9072de43bcd9..1f366b5f0d2d 100644
--- a/drivers/staging/wilc1000/linux_wlan_sdio.c
+++ b/drivers/staging/wilc1000/linux_wlan_sdio.c
@@ -135,12 +135,14 @@ static void linux_sdio_remove(struct sdio_func *func)
wilc_netdev_cleanup(sdio_get_drvdata(func));
}
-static struct sdio_driver wilc_bus = {
+static struct sdio_driver wilc1000_sdio_driver = {
.name = SDIO_MODALIAS,
.id_table = wilc_sdio_ids,
.probe = linux_sdio_probe,
.remove = linux_sdio_remove,
};
+module_driver(wilc1000_sdio_driver, sdio_register_driver, sdio_unregister_driver);
+MODULE_LICENSE("GPL");
int wilc_sdio_enable_interrupt(struct wilc *dev)
{
@@ -178,14 +180,15 @@ void wilc_sdio_disable_interrupt(struct wilc *dev)
static int linux_sdio_set_speed(int speed)
{
struct mmc_ios ios;
+ struct sdio_func *func = container_of(wilc_dev->dev, struct sdio_func, dev);
- sdio_claim_host(wilc_sdio_func);
+ sdio_claim_host(func);
- memcpy((void *)&ios, (void *)&wilc_sdio_func->card->host->ios, sizeof(struct mmc_ios));
- wilc_sdio_func->card->host->ios.clock = speed;
+ memcpy((void *)&ios, (void *)&func->card->host->ios, sizeof(struct mmc_ios));
+ func->card->host->ios.clock = speed;
ios.clock = speed;
- wilc_sdio_func->card->host->ops->set_ios(wilc_sdio_func->card->host, &ios);
- sdio_release_host(wilc_sdio_func);
+ func->card->host->ops->set_ios(func->card->host, &ios);
+ sdio_release_host(func);
PRINT_INFO(INIT_DBG, "@@@@@@@@@@@@ change SDIO speed to %d @@@@@@@@@\n", speed);
return 1;
@@ -193,7 +196,8 @@ static int linux_sdio_set_speed(int speed)
static int linux_sdio_get_speed(void)
{
- return wilc_sdio_func->card->host->ios.clock;
+ struct sdio_func *func = container_of(wilc_dev->dev, struct sdio_func, dev);
+ return func->card->host->ios.clock;
}
int wilc_sdio_init(void)
@@ -218,16 +222,4 @@ int wilc_sdio_set_default_speed(void)
return linux_sdio_set_speed(sdio_default_speed);
}
-static int __init init_wilc_sdio_driver(void)
-{
- return sdio_register_driver(&wilc_bus);
-}
-late_initcall(init_wilc_sdio_driver);
-
-static void __exit exit_wilc_sdio_driver(void)
-{
- sdio_unregister_driver(&wilc_bus);
-}
-module_exit(exit_wilc_sdio_driver);
-
MODULE_LICENSE("GPL");
diff --git a/drivers/staging/wilc1000/linux_wlan_spi.c b/drivers/staging/wilc1000/linux_wlan_spi.c
index a7a52593156a..1d8922d6eb6a 100644
--- a/drivers/staging/wilc1000/linux_wlan_spi.c
+++ b/drivers/staging/wilc1000/linux_wlan_spi.c
@@ -8,6 +8,7 @@
#include <linux/uaccess.h>
#include <linux/device.h>
#include <linux/spi/spi.h>
+#include <linux/of_gpio.h>
#include "linux_wlan_spi.h"
#include "wilc_wfi_netdevice.h"
@@ -43,59 +44,53 @@
static u32 SPEED = MIN_SPEED;
-struct spi_device *wilc_spi_dev;
+static const struct wilc1000_ops wilc1000_spi_ops;
-static int __init wilc_bus_probe(struct spi_device *spi)
+static int wilc_bus_probe(struct spi_device *spi)
{
+ int ret, gpio;
+ struct wilc *wilc;
- PRINT_D(BUS_DBG, "spiModalias: %s\n", spi->modalias);
- PRINT_D(BUS_DBG, "spiMax-Speed: %d\n", spi->max_speed_hz);
- wilc_spi_dev = spi;
+ gpio = of_get_gpio(spi->dev.of_node, 0);
+ if (gpio < 0)
+ gpio = GPIO_NUM;
+
+ ret = wilc_netdev_init(&wilc, NULL, HIF_SPI, GPIO_NUM, &wilc_hif_spi);
+ if (ret)
+ return ret;
+
+ spi_set_drvdata(spi, wilc);
+ wilc->dev = &spi->dev;
- printk("Driver Initializing success\n");
return 0;
}
-static int __exit wilc_bus_remove(struct spi_device *spi)
+static int wilc_bus_remove(struct spi_device *spi)
{
-
+ wilc_netdev_cleanup(spi_get_drvdata(spi));
return 0;
}
-#ifdef CONFIG_OF
static const struct of_device_id wilc1000_of_match[] = {
{ .compatible = "atmel,wilc_spi", },
{}
};
MODULE_DEVICE_TABLE(of, wilc1000_of_match);
-#endif
-static struct spi_driver wilc_bus __refdata = {
+struct spi_driver wilc1000_spi_driver = {
.driver = {
.name = MODALIAS,
-#ifdef CONFIG_OF
.of_match_table = wilc1000_of_match,
-#endif
},
.probe = wilc_bus_probe,
- .remove = __exit_p(wilc_bus_remove),
+ .remove = wilc_bus_remove,
};
+module_spi_driver(wilc1000_spi_driver);
+MODULE_LICENSE("GPL");
int wilc_spi_init(void)
{
- int ret = 1;
- static int called;
-
-
- if (called == 0) {
- called++;
- ret = spi_register_driver(&wilc_bus);
- }
-
- /* change return value to match WILC interface */
- (ret < 0) ? (ret = 0) : (ret = 1);
-
- return ret;
+ return 1;
}
#if defined(PLAT_WMS8304)
@@ -106,6 +101,7 @@ int wilc_spi_init(void)
int wilc_spi_write(u8 *b, u32 len)
{
+ struct spi_device *spi = to_spi_device(wilc_dev->dev);
int ret;
if (len > 0 && b != NULL) {
@@ -132,11 +128,11 @@ int wilc_spi_write(u8 *b, u32 len)
memset(&msg, 0, sizeof(msg));
spi_message_init(&msg);
- msg.spi = wilc_spi_dev;
+ msg.spi = spi;
msg.is_dma_mapped = USE_SPI_DMA;
spi_message_add_tail(&tr, &msg);
- ret = spi_sync(wilc_spi_dev, &msg);
+ ret = spi_sync(spi, &msg);
if (ret < 0) {
PRINT_ER("SPI transaction failed\n");
}
@@ -157,11 +153,11 @@ int wilc_spi_write(u8 *b, u32 len)
memset(&msg, 0, sizeof(msg));
spi_message_init(&msg);
- msg.spi = wilc_spi_dev;
+ msg.spi = spi;
msg.is_dma_mapped = USE_SPI_DMA; /* rachel */
spi_message_add_tail(&tr, &msg);
- ret = spi_sync(wilc_spi_dev, &msg);
+ ret = spi_sync(spi, &msg);
if (ret < 0) {
PRINT_ER("SPI transaction failed\n");
}
@@ -183,7 +179,7 @@ int wilc_spi_write(u8 *b, u32 len)
#else
int wilc_spi_write(u8 *b, u32 len)
{
-
+ struct spi_device *spi = to_spi_device(wilc_dev->dev);
int ret;
struct spi_message msg;
@@ -204,12 +200,12 @@ int wilc_spi_write(u8 *b, u32 len)
memset(&msg, 0, sizeof(msg));
spi_message_init(&msg);
/* [[johnny add */
- msg.spi = wilc_spi_dev;
+ msg.spi = spi;
msg.is_dma_mapped = USE_SPI_DMA;
/* ]] */
spi_message_add_tail(&tr, &msg);
- ret = spi_sync(wilc_spi_dev, &msg);
+ ret = spi_sync(spi, &msg);
if (ret < 0) {
PRINT_ER("SPI transaction failed\n");
}
@@ -234,6 +230,7 @@ int wilc_spi_write(u8 *b, u32 len)
int wilc_spi_read(u8 *rb, u32 rlen)
{
+ struct spi_device *spi = to_spi_device(wilc_dev->dev);
int ret;
if (rlen > 0) {
@@ -260,11 +257,11 @@ int wilc_spi_read(u8 *rb, u32 rlen)
memset(&msg, 0, sizeof(msg));
spi_message_init(&msg);
- msg.spi = wilc_spi_dev;
+ msg.spi = spi;
msg.is_dma_mapped = USE_SPI_DMA;
spi_message_add_tail(&tr, &msg);
- ret = spi_sync(wilc_spi_dev, &msg);
+ ret = spi_sync(spi, &msg);
if (ret < 0) {
PRINT_ER("SPI transaction failed\n");
}
@@ -284,11 +281,11 @@ int wilc_spi_read(u8 *rb, u32 rlen)
memset(&msg, 0, sizeof(msg));
spi_message_init(&msg);
- msg.spi = wilc_spi_dev;
+ msg.spi = spi;
msg.is_dma_mapped = USE_SPI_DMA; /* rachel */
spi_message_add_tail(&tr, &msg);
- ret = spi_sync(wilc_spi_dev, &msg);
+ ret = spi_sync(spi, &msg);
if (ret < 0) {
PRINT_ER("SPI transaction failed\n");
}
@@ -308,7 +305,7 @@ int wilc_spi_read(u8 *rb, u32 rlen)
#else
int wilc_spi_read(u8 *rb, u32 rlen)
{
-
+ struct spi_device *spi = to_spi_device(wilc_dev->dev);
int ret;
if (rlen > 0) {
@@ -329,12 +326,12 @@ int wilc_spi_read(u8 *rb, u32 rlen)
memset(&msg, 0, sizeof(msg));
spi_message_init(&msg);
/* [[ johnny add */
- msg.spi = wilc_spi_dev;
+ msg.spi = spi;
msg.is_dma_mapped = USE_SPI_DMA;
/* ]] */
spi_message_add_tail(&tr, &msg);
- ret = spi_sync(wilc_spi_dev, &msg);
+ ret = spi_sync(spi, &msg);
if (ret < 0) {
PRINT_ER("SPI transaction failed\n");
}
@@ -353,7 +350,7 @@ int wilc_spi_read(u8 *rb, u32 rlen)
int wilc_spi_write_read(u8 *wb, u8 *rb, u32 rlen)
{
-
+ struct spi_device *spi = to_spi_device(wilc_dev->dev);
int ret;
if (rlen > 0) {
@@ -370,11 +367,11 @@ int wilc_spi_write_read(u8 *wb, u8 *rb, u32 rlen)
memset(&msg, 0, sizeof(msg));
spi_message_init(&msg);
- msg.spi = wilc_spi_dev;
+ msg.spi = spi;
msg.is_dma_mapped = USE_SPI_DMA;
spi_message_add_tail(&tr, &msg);
- ret = spi_sync(wilc_spi_dev, &msg);
+ ret = spi_sync(spi, &msg);
if (ret < 0) {
PRINT_ER("SPI transaction failed\n");
}
@@ -395,40 +392,3 @@ int wilc_spi_set_max_speed(void)
PRINT_INFO(BUS_DBG, "@@@@@@@@@@@@ change SPI speed to %d @@@@@@@@@\n", SPEED);
return 1;
}
-
-static struct wilc *wilc;
-
-static int __init init_wilc_spi_driver(void)
-{
- int ret;
-
- wilc_debugfs_init();
-
- ret = wilc_netdev_init(&wilc, NULL, HIF_SPI, GPIO_NUM, &wilc_hif_spi);
- if (ret) {
- wilc_debugfs_remove();
- return ret;
- }
-
- if (!wilc_spi_init() || !wilc_spi_dev) {
- PRINT_ER("Can't initialize SPI\n");
- wilc_netdev_cleanup(wilc);
- wilc_debugfs_remove();
- return -ENXIO;
- }
- wilc_dev->dev = &wilc_spi_dev->dev;
-
- return ret;
-}
-late_initcall(init_wilc_spi_driver);
-
-static void __exit exit_wilc_spi_driver(void)
-{
- if (wilc)
- wilc_netdev_cleanup(wilc);
- spi_unregister_driver(&wilc_bus);
- wilc_debugfs_remove();
-}
-module_exit(exit_wilc_spi_driver);
-
-MODULE_LICENSE("GPL");
diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
index 158a1df17195..27c653a0cdf9 100644
--- a/drivers/staging/wilc1000/wilc_debugfs.c
+++ b/drivers/staging/wilc1000/wilc_debugfs.c
@@ -138,7 +138,7 @@ static struct wilc_debugfs_info_t debugfs_info[] = {
{ "wilc_debug_region", 0666, (INIT_DBG | GENERIC_DBG | CFG80211_DBG), FOPS(NULL, wilc_debug_region_read, wilc_debug_region_write, NULL), },
};
-int wilc_debugfs_init(void)
+static int __init wilc_debugfs_init(void)
{
int i;
@@ -173,11 +173,13 @@ int wilc_debugfs_init(void)
}
return 0;
}
+module_init(wilc_debugfs_init);
-void wilc_debugfs_remove(void)
+static void __exit wilc_debugfs_remove(void)
{
debugfs_remove_recursive(wilc_dir);
}
+module_exit(wilc_debugfs_remove);
#endif
--
2.1.0.rc2
next prev parent reply other threads:[~2015-11-16 14:10 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-16 14:04 [PATCH 00/19 v5] staging/wilc1000 cleanups Arnd Bergmann
2015-11-16 14:04 ` [PATCH 01/19] staging/wilc1000: remove unused functions Arnd Bergmann
2015-11-16 14:04 ` [PATCH 02/19] staging/wilc1000: make symbols static if possible Arnd Bergmann
2015-11-16 14:04 ` [PATCH 03/19] staging/wilc1000: use proper naming for global symbols Arnd Bergmann
2015-11-16 14:04 ` [PATCH 04/19] staging/wilc1000: move extern declarations to headers Arnd Bergmann
2015-11-16 14:04 ` [PATCH 05/19] staging/wilc1000: use NO_SECURITY instead of NO_ENCRYPT Arnd Bergmann
2015-11-16 14:04 ` [PATCH 06/19] staging/wilc1000: avoid static definitions in header Arnd Bergmann
2015-11-16 14:04 ` [PATCH 07/19] staging/wilc1000: remove linux_wlan_{device_power,device_detection} Arnd Bergmann
2015-11-16 14:04 ` [PATCH 08/19] staging/wilc1000: move wilc_wlan_inp_t into struct wilc Arnd Bergmann
2015-11-16 14:05 ` [PATCH 09/19] staging/wilc1000: move init/exit functions to driver files Arnd Bergmann
2015-11-17 9:27 ` kbuild test robot
2015-11-16 14:05 ` [PATCH 10/19] staging/wilc1000: unify device pointer Arnd Bergmann
2015-11-16 14:05 ` [PATCH 11/19] staging/wilc1000: pass io_type to wilc_netdev_init Arnd Bergmann
2015-11-16 14:05 ` [PATCH 12/19] staging/wilc1000: use device pointer for phy creation Arnd Bergmann
2015-11-16 14:05 ` [PATCH 13/19] staging/wilc1000: get rid of WILC_SDIO_IRQ_GPIO Arnd Bergmann
2015-11-16 14:05 ` [PATCH 14/19] staging/wilc1000: pass hif operations through initialization Arnd Bergmann
2015-11-16 14:05 ` [PATCH 15/19] staging/wilc1000: turn enable_irq/disable_irq into callbacks Arnd Bergmann
2015-11-16 14:05 ` [PATCH 16/19] staging/wilc1000: remove WILC_SDIO/WILC_SPI macros Arnd Bergmann
2015-11-16 14:05 ` [PATCH 17/19] staging/wilc1000: split out bus specific modules Arnd Bergmann
2015-11-16 14:05 ` Arnd Bergmann [this message]
2015-11-16 14:05 ` [PATCH 19/19] staging/wilc1000: pass struct wilc to most linux_wlan.c functions Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1447682710-2908925-19-git-send-email-arnd@arndb.de \
--to=arnd@arndb.de \
--cc=austin.shin@atmel.com \
--cc=chris.park@atmel.com \
--cc=devel@driverdev.osuosl.org \
--cc=glen.lee@atmel.com \
--cc=gregkh@linuxfoundation.org \
--cc=johnny.kim@atmel.com \
--cc=leo.kim@atmel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=tony.cho@atmel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®