All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@ti.com>
To: Luciano Coelho <coelho@ti.com>
Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Felipe Balbi <balbi@ti.com>
Subject: [RFC/PATCH 07/13] net: wl12xx: spi: add a context structure
Date: Sat, 14 May 2011 00:26:24 +0300	[thread overview]
Message-ID: <1305321990-22041-8-git-send-email-balbi@ti.com> (raw)
In-Reply-To: <1305321990-22041-1-git-send-email-balbi@ti.com>

this will help re-structuring the driver so
that we avoid all duplications which are
currently on this driver.

Signed-off-by: Felipe Balbi <balbi@ti.com>
---
 drivers/net/wireless/wl12xx/spi.c |  128 +++++++++++++++++++++++-------------
 1 files changed, 82 insertions(+), 46 deletions(-)

diff --git a/drivers/net/wireless/wl12xx/spi.c b/drivers/net/wireless/wl12xx/spi.c
index 382b79d..5dbd5b3 100644
--- a/drivers/net/wireless/wl12xx/spi.c
+++ b/drivers/net/wireless/wl12xx/spi.c
@@ -68,14 +68,19 @@
 
 #define WSPI_MAX_NUM_OF_CHUNKS (WL1271_AGGR_BUFFER_SIZE / WSPI_MAX_CHUNK_SIZE)
 
-static inline struct spi_device *wl_to_spi(struct wl1271 *wl)
+struct wl12xx_spi_glue {
+	struct device	*dev;
+	struct wl1271	*wl;
+};
+
+static inline struct wl12xx_spi_glue *wl_to_glue(struct wl1271 *wl)
 {
 	return wl->if_priv;
 }
 
 static struct device *wl1271_spi_wl_to_dev(struct wl1271 *wl)
 {
-	return &(wl_to_spi(wl)->dev);
+	return wl_to_glue(wl)->dev;
 }
 
 static void wl1271_spi_disable_interrupts(struct wl1271 *wl)
@@ -90,9 +95,10 @@ static void wl1271_spi_enable_interrupts(struct wl1271 *wl)
 
 static void wl1271_spi_reset(struct wl1271 *wl)
 {
-	u8 *cmd;
-	struct spi_transfer t;
-	struct spi_message m;
+	struct wl12xx_spi_glue	*glue = wl_to_glue(wl);
+	struct spi_transfer	t;
+	struct spi_message	m;
+	u8			*cmd;
 
 	cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
 	if (!cmd) {
@@ -109,7 +115,7 @@ static void wl1271_spi_reset(struct wl1271 *wl)
 	t.len = WSPI_INIT_CMD_LEN;
 	spi_message_add_tail(&t, &m);
 
-	spi_sync(wl_to_spi(wl), &m);
+	spi_sync(to_spi_device(glue->dev), &m);
 
 	wl1271_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
 	kfree(cmd);
@@ -117,9 +123,12 @@ static void wl1271_spi_reset(struct wl1271 *wl)
 
 static void wl1271_spi_init(struct wl1271 *wl)
 {
-	u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
-	struct spi_transfer t;
-	struct spi_message m;
+	struct wl12xx_spi_glue	*glue = wl_to_glue(wl);
+	struct spi_transfer	t;
+	struct spi_message	m;
+
+	u8			crc[WSPI_INIT_CMD_CRC_LEN];
+	u8			*cmd;
 
 	cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
 	if (!cmd) {
@@ -164,7 +173,7 @@ static void wl1271_spi_init(struct wl1271 *wl)
 	t.len = WSPI_INIT_CMD_LEN;
 	spi_message_add_tail(&t, &m);
 
-	spi_sync(wl_to_spi(wl), &m);
+	spi_sync(to_spi_device(glue->dev), &m);
 	wl1271_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
 	kfree(cmd);
 }
@@ -173,10 +182,12 @@ static void wl1271_spi_init(struct wl1271 *wl)
 
 static int wl1271_spi_read_busy(struct wl1271 *wl)
 {
-	struct spi_transfer t[1];
-	struct spi_message m;
-	u32 *busy_buf;
-	int num_busy_bytes = 0;
+	struct wl12xx_spi_glue	*glue = wl_to_glue(wl);
+	struct spi_transfer	t[1];
+	struct spi_message	m;
+
+	int			num_busy_bytes = 0;
+	u32			*busy_buf;
 
 	/*
 	 * Read further busy words from SPI until a non-busy word is
@@ -193,7 +204,7 @@ static int wl1271_spi_read_busy(struct wl1271 *wl)
 		t[0].len = sizeof(u32);
 		t[0].cs_change = true;
 		spi_message_add_tail(&t[0], &m);
-		spi_sync(wl_to_spi(wl), &m);
+		spi_sync(to_spi_device(glue->dev), &m);
 
 		if (*busy_buf & 0x1)
 			return 0;
@@ -207,11 +218,13 @@ static int wl1271_spi_read_busy(struct wl1271 *wl)
 static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
 				size_t len, bool fixed)
 {
-	struct spi_transfer t[2];
-	struct spi_message m;
-	u32 *busy_buf;
-	u32 *cmd;
-	u32 chunk_len;
+	struct wl12xx_spi_glue	*glue = wl_to_glue(wl);
+	struct spi_transfer	t[2];
+	struct spi_message	m;
+
+	u32			*busy_buf;
+	u32			*cmd;
+	u32			chunk_len;
 
 	while (len > 0) {
 		chunk_len = min((size_t)WSPI_MAX_CHUNK_SIZE, len);
@@ -242,7 +255,7 @@ static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
 		t[1].cs_change = true;
 		spi_message_add_tail(&t[1], &m);
 
-		spi_sync(wl_to_spi(wl), &m);
+		spi_sync(to_spi_device(glue->dev), &m);
 
 		if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) &&
 		    wl1271_spi_read_busy(wl)) {
@@ -258,7 +271,7 @@ static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
 		t[0].cs_change = true;
 		spi_message_add_tail(&t[0], &m);
 
-		spi_sync(wl_to_spi(wl), &m);
+		spi_sync(to_spi_device(glue->dev), &m);
 
 		wl1271_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd));
 		wl1271_dump(DEBUG_SPI, "spi_read buf <- ", buf, chunk_len);
@@ -273,12 +286,15 @@ static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
 static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
 			  size_t len, bool fixed)
 {
-	struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS];
-	struct spi_message m;
-	u32 commands[WSPI_MAX_NUM_OF_CHUNKS];
-	u32 *cmd;
-	u32 chunk_len;
-	int i;
+	struct wl12xx_spi_glue	*glue = wl_to_glue(wl);
+	struct spi_transfer	t[2 * WSPI_MAX_NUM_OF_CHUNKS];
+	struct spi_message	m;
+
+	u32			commands[WSPI_MAX_NUM_OF_CHUNKS];
+	u32			chunk_len;
+	u32			*cmd;
+
+	int			i;
 
 	WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
 
@@ -317,7 +333,7 @@ static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
 		cmd++;
 	}
 
-	spi_sync(wl_to_spi(wl), &m);
+	spi_sync(to_spi_device(glue->dev), &m);
 }
 
 static irqreturn_t wl1271_hardirq(int irq, void *cookie)
@@ -360,10 +376,13 @@ static struct wl1271_if_operations spi_ops = {
 
 static int __devinit wl1271_probe(struct spi_device *spi)
 {
-	struct wl12xx_platform_data *pdata;
-	struct ieee80211_hw *hw;
-	struct wl1271 *wl;
-	int ret;
+	struct wl12xx_platform_data	*pdata;
+
+	struct wl12xx_spi_glue		*glue;
+	struct ieee80211_hw		*hw;
+	struct wl1271			*wl;
+
+	int				ret = -ENOMEM;
 
 	pdata = spi->dev.platform_data;
 	if (!pdata) {
@@ -371,14 +390,25 @@ static int __devinit wl1271_probe(struct spi_device *spi)
 		return -ENODEV;
 	}
 
+	glue = kzalloc(sizeof(*glue), GFP_KERNEL);
+	if (!glue) {
+		dev_err(&spi->dev, "not enought memory\n");
+		goto err0;
+	}
+
 	hw = wl1271_alloc_hw();
-	if (IS_ERR(hw))
-		return PTR_ERR(hw);
+	if (IS_ERR(hw)) {
+		ret = PTR_ERR(hw);
+		goto err1;
+	}
 
 	wl = hw->priv;
 
-	dev_set_drvdata(&spi->dev, wl);
-	wl->if_priv = spi;
+	glue->dev = &spi->dev;
+	glue->wl = wl;
+
+	spi_set_drvdata(spi, glue);
+	wl->if_priv = glue;
 
 	wl->if_ops = &spi_ops;
 
@@ -389,14 +419,14 @@ static int __devinit wl1271_probe(struct spi_device *spi)
 	ret = spi_setup(spi);
 	if (ret < 0) {
 		wl1271_error("spi_setup failed");
-		goto out_free;
+		goto err2;
 	}
 
 	wl->set_power = pdata->set_power;
 	if (!wl->set_power) {
 		wl1271_error("set power function missing in platform data");
 		ret = -ENODEV;
-		goto out_free;
+		goto err2;
 	}
 
 	wl->ref_clock = pdata->board_ref_clock;
@@ -405,7 +435,7 @@ static int __devinit wl1271_probe(struct spi_device *spi)
 	if (wl->irq < 0) {
 		wl1271_error("irq missing in platform data");
 		ret = -ENODEV;
-		goto out_free;
+		goto err2;
 	}
 
 	ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq,
@@ -413,37 +443,43 @@ static int __devinit wl1271_probe(struct spi_device *spi)
 				   DRIVER_NAME, wl);
 	if (ret < 0) {
 		wl1271_error("request_irq() failed: %d", ret);
-		goto out_free;
+		goto err2;
 	}
 
 	disable_irq(wl->irq);
 
 	ret = wl1271_init_ieee80211(wl);
 	if (ret)
-		goto out_irq;
+		goto err3;
 
 	ret = wl1271_register_hw(wl);
 	if (ret)
-		goto out_irq;
+		goto err3;
 
 	return 0;
 
- out_irq:
+err3:
 	free_irq(wl->irq, wl);
 
- out_free:
+err2:
 	wl1271_free_hw(wl);
 
+err1:
+	kfree(glue);
+
+err0:
 	return ret;
 }
 
 static int __devexit wl1271_remove(struct spi_device *spi)
 {
-	struct wl1271 *wl = dev_get_drvdata(&spi->dev);
+	struct wl12xx_spi_glue	*glue = spi_get_drvdata(spi);
+	struct wl1271		*wl = glue->wl;
 
 	wl1271_unregister_hw(wl);
 	free_irq(wl->irq, wl);
 	wl1271_free_hw(wl);
+	kfree(glue);
 
 	return 0;
 }
-- 
1.7.4.1.343.ga91df


  parent reply	other threads:[~2011-05-13 21:27 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-13 21:26 [RFC/PATCH 00/13] wl12xx re-factor Felipe Balbi
2011-05-13 21:26 ` [RFC/PATCH 01/13] net: wl12xx: sdio: id_tables should be __devinitconst Felipe Balbi
2011-05-20 12:02   ` Luciano Coelho
2011-05-20 16:02   ` Ohad Ben-Cohen
2011-05-20 16:14     ` Michał Mirosław
2011-05-13 21:26 ` [RFC/PATCH 02/13] net: wl12xx: sdio: add a context structure Felipe Balbi
2011-05-13 21:26 ` [RFC/PATCH 03/13] net: wl12xx: remove some unnecessary prints Felipe Balbi
2011-05-13 21:26   ` Felipe Balbi
2011-05-20 12:03   ` Luciano Coelho
2011-05-22 12:34   ` Eliad Peller
2011-05-22 12:37     ` Eliad Peller
2011-05-22 17:30       ` Luciano Coelho
2011-05-22 21:57         ` Eliad Peller
2011-05-23  5:32           ` Luciano Coelho
2011-05-23  6:07             ` Felipe Balbi
2011-05-13 21:26 ` [RFC/PATCH 04/13] net: wl12xx: care for optional operations Felipe Balbi
2011-05-20 12:03   ` Luciano Coelho
2011-05-13 21:26 ` [RFC/PATCH 05/13] net: wl12xx: remove the nops Felipe Balbi
2011-05-20 12:04   ` Luciano Coelho
2011-05-13 21:26 ` [RFC/PATCH 06/13] net: wl12xx: remove unnecessary prints Felipe Balbi
2011-05-20 12:04   ` Luciano Coelho
2011-05-13 21:26 ` Felipe Balbi [this message]
2011-05-13 21:26 ` [RFC/PATCH 08/13] net: wl12xx: spi: add a platform_device Felipe Balbi
2011-05-13 21:26 ` [RFC/PATCH 09/13] net: wl12xx: sdio: " Felipe Balbi
2011-05-13 21:26 ` [RFC/PATCH 10/13] net: wl12xx: main: add platform device Felipe Balbi
2011-05-13 21:26   ` Felipe Balbi
2011-05-13 21:26 ` [RFC/PATCH 11/13] net: wireless: wl12xx: re-factor all drivers Felipe Balbi
2011-05-13 21:26 ` [RFC/PATCH 12/13] net: wireless: wl12xx: mark some symbols static Felipe Balbi
2011-05-13 21:26   ` Felipe Balbi
2011-05-13 21:26 ` [RFC/PATCH 13/13] net: wl12xx: main: drop unneded plat_dev Felipe Balbi
2011-05-19 12:49 ` [RFC/PATCH 00/13] wl12xx re-factor Luciano Coelho
2011-05-19 14:06   ` Felipe Balbi

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=1305321990-22041-8-git-send-email-balbi@ti.com \
    --to=balbi@ti.com \
    --cc=coelho@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.