* [PATCH] spi: Allow using spi_bitbang_setup() with custom txrx_bufs()
@ 2009-11-25 8:26 Magnus Damm
2009-11-25 22:15 ` Grant Likely
0 siblings, 1 reply; 6+ messages in thread
From: Magnus Damm @ 2009-11-25 8:26 UTC (permalink / raw)
To: spi-devel-general
Cc: grant.likely, Magnus Damm, dbrownell, linux-kernel, akpm
From: Magnus Damm <damm@opensource.se>
This patch modifies the shared spi bitbanging code
to allow using spi_bitbang_setup() even though the
txrx_word[] callbacks are unset. Useful for drivers
that want to make use of spi_bitbang_setup() but
have their own txrx_bufs() callback.
While at it, drop the MSIOF driver workaround.
Signed-off-by: Magnus Damm <damm@opensource.se>
---
Depends on the MSIOF driver.
drivers/spi/spi_bitbang.c | 25 ++++++++++++++-----------
drivers/spi/spi_sh_msiof.c | 11 -----------
2 files changed, 14 insertions(+), 22 deletions(-)
--- 0001/drivers/spi/spi_bitbang.c
+++ work/drivers/spi/spi_bitbang.c 2009-11-25 15:30:45.000000000 +0900
@@ -176,6 +176,14 @@ int spi_bitbang_setup_transfer(struct sp
}
EXPORT_SYMBOL_GPL(spi_bitbang_setup_transfer);
+static int spi_bitbang_bufs(struct spi_device *spi, struct spi_transfer *t)
+{
+ struct spi_bitbang_cs *cs = spi->controller_state;
+ unsigned nsecs = cs->nsecs;
+
+ return cs->txrx_bufs(spi, cs->txrx_word, nsecs, t);
+}
+
/**
* spi_bitbang_setup - default setup for per-word I/O loops
*/
@@ -183,6 +191,7 @@ int spi_bitbang_setup(struct spi_device
{
struct spi_bitbang_cs *cs = spi->controller_state;
struct spi_bitbang *bitbang;
+ int mode_mask = SPI_CPOL | SPI_CPHA;
int retval;
unsigned long flags;
@@ -196,9 +205,11 @@ int spi_bitbang_setup(struct spi_device
}
/* per-word shift register access, in hardware or bitbanging */
- cs->txrx_word = bitbang->txrx_word[spi->mode & (SPI_CPOL|SPI_CPHA)];
- if (!cs->txrx_word)
- return -EINVAL;
+ if (bitbang->txrx_bufs == spi_bitbang_bufs) {
+ cs->txrx_word = bitbang->txrx_word[spi->mode & mode_mask];
+ if (!cs->txrx_word)
+ return -EINVAL;
+ }
retval = bitbang->setup_transfer(spi, NULL);
if (retval < 0)
@@ -232,14 +243,6 @@ void spi_bitbang_cleanup(struct spi_devi
}
EXPORT_SYMBOL_GPL(spi_bitbang_cleanup);
-static int spi_bitbang_bufs(struct spi_device *spi, struct spi_transfer *t)
-{
- struct spi_bitbang_cs *cs = spi->controller_state;
- unsigned nsecs = cs->nsecs;
-
- return cs->txrx_bufs(spi, cs->txrx_word, nsecs, t);
-}
-
/*----------------------------------------------------------------------*/
/*
--- 0002/drivers/spi/spi_sh_msiof.c
+++ work/drivers/spi/spi_sh_msiof.c 2009-11-25 15:25:32.000000000 +0900
@@ -510,13 +510,6 @@ static int sh_msiof_spi_txrx(struct spi_
return bytes_done;
}
-static u32 sh_msiof_spi_txrx_word(struct spi_device *spi, unsigned nsecs,
- u32 word, u8 bits)
-{
- BUG_ON(1); /* unused but needed by bitbang code */
- return 0;
-}
-
static int sh_msiof_spi_probe(struct platform_device *pdev)
{
struct resource *r;
@@ -594,10 +587,6 @@ static int sh_msiof_spi_probe(struct pla
p->bitbang.chipselect = sh_msiof_spi_chipselect;
p->bitbang.setup_transfer = sh_msiof_spi_setup_transfer;
p->bitbang.txrx_bufs = sh_msiof_spi_txrx;
- p->bitbang.txrx_word[SPI_MODE_0] = sh_msiof_spi_txrx_word;
- p->bitbang.txrx_word[SPI_MODE_1] = sh_msiof_spi_txrx_word;
- p->bitbang.txrx_word[SPI_MODE_2] = sh_msiof_spi_txrx_word;
- p->bitbang.txrx_word[SPI_MODE_3] = sh_msiof_spi_txrx_word;
ret = spi_bitbang_start(&p->bitbang);
if (ret == 0)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] spi: Allow using spi_bitbang_setup() with custom txrx_bufs()
2009-11-25 8:26 [PATCH] spi: Allow using spi_bitbang_setup() with custom txrx_bufs() Magnus Damm
@ 2009-11-25 22:15 ` Grant Likely
2009-11-26 6:47 ` Magnus Damm
0 siblings, 1 reply; 6+ messages in thread
From: Grant Likely @ 2009-11-25 22:15 UTC (permalink / raw)
To: Magnus Damm; +Cc: spi-devel-general, dbrownell, linux-kernel, akpm
On Wed, Nov 25, 2009 at 1:26 AM, Magnus Damm <magnus.damm@gmail.com> wrote:
> From: Magnus Damm <damm@opensource.se>
>
> This patch modifies the shared spi bitbanging code
> to allow using spi_bitbang_setup() even though the
> txrx_word[] callbacks are unset. Useful for drivers
> that want to make use of spi_bitbang_setup() but
> have their own txrx_bufs() callback.
>
> While at it, drop the MSIOF driver workaround.
>
> Signed-off-by: Magnus Damm <damm@opensource.se>
> ---
>
> Depends on the MSIOF driver.
>
> drivers/spi/spi_bitbang.c | 25 ++++++++++++++-----------
> drivers/spi/spi_sh_msiof.c | 11 -----------
> 2 files changed, 14 insertions(+), 22 deletions(-)
>
> --- 0001/drivers/spi/spi_bitbang.c
> +++ work/drivers/spi/spi_bitbang.c 2009-11-25 15:30:45.000000000 +0900
> @@ -176,6 +176,14 @@ int spi_bitbang_setup_transfer(struct sp
> }
> EXPORT_SYMBOL_GPL(spi_bitbang_setup_transfer);
>
> +static int spi_bitbang_bufs(struct spi_device *spi, struct spi_transfer *t)
> +{
> + struct spi_bitbang_cs *cs = spi->controller_state;
> + unsigned nsecs = cs->nsecs;
> +
> + return cs->txrx_bufs(spi, cs->txrx_word, nsecs, t);
> +}
> +
> /**
> * spi_bitbang_setup - default setup for per-word I/O loops
> */
> @@ -183,6 +191,7 @@ int spi_bitbang_setup(struct spi_device
> {
> struct spi_bitbang_cs *cs = spi->controller_state;
> struct spi_bitbang *bitbang;
> + int mode_mask = SPI_CPOL | SPI_CPHA;
> int retval;
> unsigned long flags;
>
> @@ -196,9 +205,11 @@ int spi_bitbang_setup(struct spi_device
> }
>
> /* per-word shift register access, in hardware or bitbanging */
> - cs->txrx_word = bitbang->txrx_word[spi->mode & (SPI_CPOL|SPI_CPHA)];
> - if (!cs->txrx_word)
> - return -EINVAL;
> + if (bitbang->txrx_bufs == spi_bitbang_bufs) {
> + cs->txrx_word = bitbang->txrx_word[spi->mode & mode_mask];
> + if (!cs->txrx_word)
> + return -EINVAL;
> + }
Hmmm... this smells like an ugly hack to me. It seems to me that if
some bitbang backend drivers don't want this code, then it should be
encoded into a callback so it can be overridden. Thoughts.
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] spi: Allow using spi_bitbang_setup() with custom txrx_bufs()
2009-11-25 22:15 ` Grant Likely
@ 2009-11-26 6:47 ` Magnus Damm
2009-11-26 7:21 ` Grant Likely
0 siblings, 1 reply; 6+ messages in thread
From: Magnus Damm @ 2009-11-26 6:47 UTC (permalink / raw)
To: Grant Likely; +Cc: spi-devel-general, dbrownell, linux-kernel, akpm
[-- Attachment #1: Type: text/plain, Size: 1761 bytes --]
Hi Grant,
On Thu, Nov 26, 2009 at 7:15 AM, Grant Likely <grant.likely@secretlab.ca> wrote:
> On Wed, Nov 25, 2009 at 1:26 AM, Magnus Damm <magnus.damm@gmail.com> wrote:
>> This patch modifies the shared spi bitbanging code
>> to allow using spi_bitbang_setup() even though the
>> txrx_word[] callbacks are unset. Useful for drivers
>> that want to make use of spi_bitbang_setup() but
>> have their own txrx_bufs() callback.
>> @@ -196,9 +205,11 @@ int spi_bitbang_setup(struct spi_device
>> }
>>
>> /* per-word shift register access, in hardware or bitbanging */
>> - cs->txrx_word = bitbang->txrx_word[spi->mode & (SPI_CPOL|SPI_CPHA)];
>> - if (!cs->txrx_word)
>> - return -EINVAL;
>> + if (bitbang->txrx_bufs == spi_bitbang_bufs) {
>> + cs->txrx_word = bitbang->txrx_word[spi->mode & mode_mask];
>> + if (!cs->txrx_word)
>> + return -EINVAL;
>> + }
>
> Hmmm... this smells like an ugly hack to me. It seems to me that if
> some bitbang backend drivers don't want this code, then it should be
> encoded into a callback so it can be overridden. Thoughts.
Yeah, it's far from clean. I want to make use of spi_bitbang_setup()
in my MSIOF driver, but I want to avoid dummy txtx_word[] callbacks
that will be unused since i'm using a driver specific
bitbang->txrx_bufs function.
I guess the attached patch is slightly cleaner? I like the idea of
letting bitbang drivers use shared code for
spi_bitbang_setup()/spi_bitbang_cleanup() with their private
setup_transfer() function which in turn calls
spi_bitbang_setup_transfer(). My impression is that there's quite a
bit of duplicated setup()/cleanup() code.
/ magnus
[-- Attachment #2: linux-2.6.33-pre-spi-word-mode-setup-20091126.patch --]
[-- Type: application/octet-stream, Size: 3503 bytes --]
From: Magnus Damm <damm@opensource.se>
Signed-off-by: Magnus Damm <damm@opensource.se>
---
drivers/spi/spi_bitbang.c | 37 ++++++++++++++++++++++++++++++-------
drivers/spi/spi_gpio.c | 2 +-
include/linux/spi/spi_bitbang.h | 1 +
3 files changed, 32 insertions(+), 8 deletions(-)
--- 0001/drivers/spi/spi_bitbang.c
+++ work/drivers/spi/spi_bitbang.c 2009-11-26 14:59:53.000000000 +0900
@@ -177,7 +177,7 @@ int spi_bitbang_setup_transfer(struct sp
EXPORT_SYMBOL_GPL(spi_bitbang_setup_transfer);
/**
- * spi_bitbang_setup - default setup for per-word I/O loops
+ * spi_bitbang_setup - setup function when bitbang->txrx_word[] are unused
*/
int spi_bitbang_setup(struct spi_device *spi)
{
@@ -195,11 +195,6 @@ int spi_bitbang_setup(struct spi_device
spi->controller_state = cs;
}
- /* per-word shift register access, in hardware or bitbanging */
- cs->txrx_word = bitbang->txrx_word[spi->mode & (SPI_CPOL|SPI_CPHA)];
- if (!cs->txrx_word)
- return -EINVAL;
-
retval = bitbang->setup_transfer(spi, NULL);
if (retval < 0)
return retval;
@@ -224,6 +219,32 @@ int spi_bitbang_setup(struct spi_device
EXPORT_SYMBOL_GPL(spi_bitbang_setup);
/**
+ * spi_bitbang_setup_word_mode - default setup for per-word I/O loops
+ */
+int spi_bitbang_setup_word_mode(struct spi_device *spi)
+{
+ struct spi_bitbang_cs *cs;
+ struct spi_bitbang *bitbang;
+ void *txrx_word;
+ int retval;
+
+ bitbang = spi_master_get_devdata(spi->master);
+
+ /* per-word shift register access, in hardware or bitbanging */
+ txrx_word = bitbang->txrx_word[spi->mode & (SPI_CPOL | SPI_CPHA)];
+ if (!txrx_word)
+ return -EINVAL;
+
+ retval = spi_bitbang_setup(spi);
+ if (!retval) {
+ cs = spi->controller_state;
+ cs->txrx_word = txrx_word;
+ }
+ return retval;
+}
+EXPORT_SYMBOL_GPL(spi_bitbang_setup_word_mode);
+
+/**
* spi_bitbang_cleanup - default cleanup for per-word I/O loops
*/
void spi_bitbang_cleanup(struct spi_device *spi)
@@ -455,6 +476,8 @@ int spi_bitbang_start(struct spi_bitbang
if (!bitbang->master->transfer)
bitbang->master->transfer = spi_bitbang_transfer;
+
+ /* "word mode" when spi_bitbang_bufs() are used */
if (!bitbang->txrx_bufs) {
bitbang->use_dma = 0;
bitbang->txrx_bufs = spi_bitbang_bufs;
@@ -462,7 +485,7 @@ int spi_bitbang_start(struct spi_bitbang
if (!bitbang->setup_transfer)
bitbang->setup_transfer =
spi_bitbang_setup_transfer;
- bitbang->master->setup = spi_bitbang_setup;
+ bitbang->master->setup = spi_bitbang_setup_word_mode;
bitbang->master->cleanup = spi_bitbang_cleanup;
}
} else if (!bitbang->master->setup)
--- 0001/drivers/spi/spi_gpio.c
+++ work/drivers/spi/spi_gpio.c 2009-11-26 14:53:37.000000000 +0900
@@ -201,7 +201,7 @@ static int spi_gpio_setup(struct spi_dev
}
}
if (!status)
- status = spi_bitbang_setup(spi);
+ status = spi_bitbang_setup_word_mode(spi);
if (status) {
if (!spi->controller_state && cs != SPI_GPIO_NO_CHIPSELECT)
gpio_free(cs);
--- 0001/include/linux/spi/spi_bitbang.h
+++ work/include/linux/spi/spi_bitbang.h 2009-11-26 14:54:08.000000000 +0900
@@ -58,6 +58,7 @@ struct spi_bitbang {
* methods, if you like.
*/
extern int spi_bitbang_setup(struct spi_device *spi);
+extern int spi_bitbang_setup_word_mode(struct spi_device *spi);
extern void spi_bitbang_cleanup(struct spi_device *spi);
extern int spi_bitbang_transfer(struct spi_device *spi, struct spi_message *m);
extern int spi_bitbang_setup_transfer(struct spi_device *spi,
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] spi: Allow using spi_bitbang_setup() with custom txrx_bufs()
2009-11-26 6:47 ` Magnus Damm
@ 2009-11-26 7:21 ` Grant Likely
2009-11-26 7:50 ` Magnus Damm
0 siblings, 1 reply; 6+ messages in thread
From: Grant Likely @ 2009-11-26 7:21 UTC (permalink / raw)
To: Magnus Damm; +Cc: spi-devel-general, dbrownell, linux-kernel, akpm
On Wed, Nov 25, 2009 at 11:47 PM, Magnus Damm <magnus.damm@gmail.com> wrote:
> Hi Grant,
>
> On Thu, Nov 26, 2009 at 7:15 AM, Grant Likely <grant.likely@secretlab.ca> wrote:
>> On Wed, Nov 25, 2009 at 1:26 AM, Magnus Damm <magnus.damm@gmail.com> wrote:
>>> /* per-word shift register access, in hardware or bitbanging */
>>> - cs->txrx_word = bitbang->txrx_word[spi->mode & (SPI_CPOL|SPI_CPHA)];
>>> - if (!cs->txrx_word)
>>> - return -EINVAL;
>>> + if (bitbang->txrx_bufs == spi_bitbang_bufs) {
>>> + cs->txrx_word = bitbang->txrx_word[spi->mode & mode_mask];
>>> + if (!cs->txrx_word)
>>> + return -EINVAL;
>>> + }
>>
>> Hmmm... this smells like an ugly hack to me. It seems to me that if
>> some bitbang backend drivers don't want this code, then it should be
>> encoded into a callback so it can be overridden. Thoughts.
>
> Yeah, it's far from clean. I want to make use of spi_bitbang_setup()
> in my MSIOF driver, but I want to avoid dummy txtx_word[] callbacks
> that will be unused since i'm using a driver specific
> bitbang->txrx_bufs function.
>
> I guess the attached patch is slightly cleaner? I like the idea of
> letting bitbang drivers use shared code for
> spi_bitbang_setup()/spi_bitbang_cleanup() with their private
> setup_transfer() function which in turn calls
> spi_bitbang_setup_transfer(). My impression is that there's quite a
> bit of duplicated setup()/cleanup() code.
This is certainly less ugly. But with the points brought up in the
other thread, I want to have a close look at spi-bitbang before I
start applying stuff. It seems nasty. Give me a few days.
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] spi: Allow using spi_bitbang_setup() with custom txrx_bufs()
2009-11-26 7:21 ` Grant Likely
@ 2009-11-26 7:50 ` Magnus Damm
2009-11-26 14:45 ` Grant Likely
0 siblings, 1 reply; 6+ messages in thread
From: Magnus Damm @ 2009-11-26 7:50 UTC (permalink / raw)
To: Grant Likely; +Cc: spi-devel-general, dbrownell, linux-kernel, akpm
On Thu, Nov 26, 2009 at 4:21 PM, Grant Likely <grant.likely@secretlab.ca> wrote:
> On Wed, Nov 25, 2009 at 11:47 PM, Magnus Damm <magnus.damm@gmail.com> wrote:
>> On Thu, Nov 26, 2009 at 7:15 AM, Grant Likely <grant.likely@secretlab.ca> wrote:
>>> On Wed, Nov 25, 2009 at 1:26 AM, Magnus Damm <magnus.damm@gmail.com> wrote:
>>>> /* per-word shift register access, in hardware or bitbanging */
>>>> - cs->txrx_word = bitbang->txrx_word[spi->mode & (SPI_CPOL|SPI_CPHA)];
>>>> - if (!cs->txrx_word)
>>>> - return -EINVAL;
>>>> + if (bitbang->txrx_bufs == spi_bitbang_bufs) {
>>>> + cs->txrx_word = bitbang->txrx_word[spi->mode & mode_mask];
>>>> + if (!cs->txrx_word)
>>>> + return -EINVAL;
>>>> + }
>>>
>>> Hmmm... this smells like an ugly hack to me. It seems to me that if
>>> some bitbang backend drivers don't want this code, then it should be
>>> encoded into a callback so it can be overridden. Thoughts.
>>
>> Yeah, it's far from clean. I want to make use of spi_bitbang_setup()
>> in my MSIOF driver, but I want to avoid dummy txtx_word[] callbacks
>> that will be unused since i'm using a driver specific
>> bitbang->txrx_bufs function.
>>
>> I guess the attached patch is slightly cleaner? I like the idea of
>> letting bitbang drivers use shared code for
>> spi_bitbang_setup()/spi_bitbang_cleanup() with their private
>> setup_transfer() function which in turn calls
>> spi_bitbang_setup_transfer(). My impression is that there's quite a
>> bit of duplicated setup()/cleanup() code.
>
> This is certainly less ugly. But with the points brought up in the
> other thread, I want to have a close look at spi-bitbang before I
> start applying stuff. It seems nasty. Give me a few days.
Sure, I plan on posting a V2 of the MSIOF driver. I plan to keep the
dummy txrx_word() function for now - this to disconnect the cleanup
from the driver integration, hope that sounds like a good plan.
Cheers,
/ magnus
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] spi: Allow using spi_bitbang_setup() with custom txrx_bufs()
2009-11-26 7:50 ` Magnus Damm
@ 2009-11-26 14:45 ` Grant Likely
0 siblings, 0 replies; 6+ messages in thread
From: Grant Likely @ 2009-11-26 14:45 UTC (permalink / raw)
To: Magnus Damm; +Cc: spi-devel-general, dbrownell, linux-kernel, akpm
On Thu, Nov 26, 2009 at 12:50 AM, Magnus Damm <magnus.damm@gmail.com> wrote:
> On Thu, Nov 26, 2009 at 4:21 PM, Grant Likely <grant.likely@secretlab.ca> wrote:
>> On Wed, Nov 25, 2009 at 11:47 PM, Magnus Damm <magnus.damm@gmail.com> wrote:
>>> On Thu, Nov 26, 2009 at 7:15 AM, Grant Likely <grant.likely@secretlab.ca> wrote:
>>>> On Wed, Nov 25, 2009 at 1:26 AM, Magnus Damm <magnus.damm@gmail.com> wrote:
>>>>> /* per-word shift register access, in hardware or bitbanging */
>>>>> - cs->txrx_word = bitbang->txrx_word[spi->mode & (SPI_CPOL|SPI_CPHA)];
>>>>> - if (!cs->txrx_word)
>>>>> - return -EINVAL;
>>>>> + if (bitbang->txrx_bufs == spi_bitbang_bufs) {
>>>>> + cs->txrx_word = bitbang->txrx_word[spi->mode & mode_mask];
>>>>> + if (!cs->txrx_word)
>>>>> + return -EINVAL;
>>>>> + }
>>>>
>>>> Hmmm... this smells like an ugly hack to me. It seems to me that if
>>>> some bitbang backend drivers don't want this code, then it should be
>>>> encoded into a callback so it can be overridden. Thoughts.
>>>
>>> Yeah, it's far from clean. I want to make use of spi_bitbang_setup()
>>> in my MSIOF driver, but I want to avoid dummy txtx_word[] callbacks
>>> that will be unused since i'm using a driver specific
>>> bitbang->txrx_bufs function.
>>>
>>> I guess the attached patch is slightly cleaner? I like the idea of
>>> letting bitbang drivers use shared code for
>>> spi_bitbang_setup()/spi_bitbang_cleanup() with their private
>>> setup_transfer() function which in turn calls
>>> spi_bitbang_setup_transfer(). My impression is that there's quite a
>>> bit of duplicated setup()/cleanup() code.
>>
>> This is certainly less ugly. But with the points brought up in the
>> other thread, I want to have a close look at spi-bitbang before I
>> start applying stuff. It seems nasty. Give me a few days.
>
> Sure, I plan on posting a V2 of the MSIOF driver. I plan to keep the
> dummy txrx_word() function for now - this to disconnect the cleanup
> from the driver integration, hope that sounds like a good plan.
Works for me. Now I just need to find someone with the time to
refactor spi-bitbang. :-)
g.
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-11-26 14:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-25 8:26 [PATCH] spi: Allow using spi_bitbang_setup() with custom txrx_bufs() Magnus Damm
2009-11-25 22:15 ` Grant Likely
2009-11-26 6:47 ` Magnus Damm
2009-11-26 7:21 ` Grant Likely
2009-11-26 7:50 ` Magnus Damm
2009-11-26 14:45 ` Grant Likely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).