linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi/pl022: compare bitwidth to enums
@ 2010-09-30  9:57 Linus Walleij
  2010-09-30 11:34 ` Linus Walleij
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2010-09-30  9:57 UTC (permalink / raw)
  To: Grant Likely, spi-devel-general; +Cc: Linus Walleij, linux-arm-kernel

The enums from <linux/amba/pl022.h> are actually off-by-one
since bitwidth 4 is defined as 0x03, causing weirdness when
we were trying out some 9-bit peripheral. Fix this by
comparing to the enum values rather than hardcoded values
and also fixing the enum to something reasonable.

Signed-off-by: Linus Walleij <linus.walleij@stericsson.com>
---
 drivers/spi/amba-pl022.c   |    4 ++--
 include/linux/amba/pl022.h |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/amba-pl022.c b/drivers/spi/amba-pl022.c
index 90a7e5d..981f78d 100644
--- a/drivers/spi/amba-pl022.c
+++ b/drivers/spi/amba-pl022.c
@@ -1605,12 +1605,12 @@ static int pl022_setup(struct spi_device *spi)
 	chip->xfer_type = chip_info->com_mode;
 	chip->cs_control = chip_info->cs_control;
 
-	if (chip_info->data_size <= 8) {
+	if (chip_info->data_size <= SSP_DATA_BITS_8) {
 		dev_dbg(&spi->dev, "1 <= n <=8 bits per word\n");
 		chip->n_bytes = 1;
 		chip->read = READING_U8;
 		chip->write = WRITING_U8;
-	} else if (chip_info->data_size <= 16) {
+	} else if (chip_info->data_size <= SSP_DATA_BITS_16) {
 		dev_dbg(&spi->dev, "9 <= n <= 16 bits per word\n");
 		chip->n_bytes = 2;
 		chip->read = READING_U16;
diff --git a/include/linux/amba/pl022.h b/include/linux/amba/pl022.h
index abf26cc..3c83c62 100644
--- a/include/linux/amba/pl022.h
+++ b/include/linux/amba/pl022.h
@@ -90,7 +90,7 @@ enum ssp_tx_endian {
  * enum ssp_data_size - number of bits in one data element
  */
 enum ssp_data_size {
-	SSP_DATA_BITS_4 = 0x03, SSP_DATA_BITS_5, SSP_DATA_BITS_6,
+	SSP_DATA_BITS_4 = 0x04, SSP_DATA_BITS_5, SSP_DATA_BITS_6,
 	SSP_DATA_BITS_7, SSP_DATA_BITS_8, SSP_DATA_BITS_9,
 	SSP_DATA_BITS_10, SSP_DATA_BITS_11, SSP_DATA_BITS_12,
 	SSP_DATA_BITS_13, SSP_DATA_BITS_14, SSP_DATA_BITS_15,
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi/pl022: compare bitwidth to enums
  2010-09-30  9:57 [PATCH] spi/pl022: compare bitwidth to enums Linus Walleij
@ 2010-09-30 11:34 ` Linus Walleij
  2010-09-30 14:37   ` Grant Likely
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2010-09-30 11:34 UTC (permalink / raw)
  To: Grant Likely, spi-devel-general; +Cc: Linus Walleij, linux-arm-kernel

2010/9/30 Linus Walleij <linus.walleij@stericsson.com>:

> The enums from <linux/amba/pl022.h> are actually off-by-one
> since bitwidth 4 is defined as 0x03, causing weirdness when
> we were trying out some 9-bit peripheral. Fix this by
> comparing to the enum values rather than hardcoded values
> and also fixing the enum to something reasonable.
>
> Signed-off-by: Linus Walleij <linus.walleij@stericsson.com>
> (...)
> -       if (chip_info->data_size <= 8) {
> +       if (chip_info->data_size <= SSP_DATA_BITS_8) {
>                dev_dbg(&spi->dev, "1 <= n <=8 bits per word\n");
>                chip->n_bytes = 1;
>                chip->read = READING_U8;
>                chip->write = WRITING_U8;
> -       } else if (chip_info->data_size <= 16) {
> +       } else if (chip_info->data_size <= SSP_DATA_BITS_16) {

I just realized that Kevin Wells patch actually patch away this problem
so merge his patch and disregard this for the optimal solution.

>  enum ssp_data_size {
> -       SSP_DATA_BITS_4 = 0x03, SSP_DATA_BITS_5, SSP_DATA_BITS_6,
> +       SSP_DATA_BITS_4 = 0x04, SSP_DATA_BITS_5, SSP_DATA_BITS_6,

This is not good because this is used for default register
settings too (I didn't notice, typical).

If anyone still wants a patch for older kernels I can provide a
patch against 2.6.36-rc6 with just the first two hunks.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi/pl022: compare bitwidth to enums
  2010-09-30 11:34 ` Linus Walleij
@ 2010-09-30 14:37   ` Grant Likely
  2010-09-30 16:21     ` Kevin Wells
  0 siblings, 1 reply; 4+ messages in thread
From: Grant Likely @ 2010-09-30 14:37 UTC (permalink / raw)
  To: Linus Walleij; +Cc: spi-devel-general, Linus Walleij, linux-arm-kernel

On Thu, Sep 30, 2010 at 8:34 PM, Linus Walleij
<linus.ml.walleij@gmail.com> wrote:
> 2010/9/30 Linus Walleij <linus.walleij@stericsson.com>:
>
>> The enums from <linux/amba/pl022.h> are actually off-by-one
>> since bitwidth 4 is defined as 0x03, causing weirdness when
>> we were trying out some 9-bit peripheral. Fix this by
>> comparing to the enum values rather than hardcoded values
>> and also fixing the enum to something reasonable.
>>
>> Signed-off-by: Linus Walleij <linus.walleij@stericsson.com>
>> (...)
>> -       if (chip_info->data_size <= 8) {
>> +       if (chip_info->data_size <= SSP_DATA_BITS_8) {
>>                dev_dbg(&spi->dev, "1 <= n <=8 bits per word\n");
>>                chip->n_bytes = 1;
>>                chip->read = READING_U8;
>>                chip->write = WRITING_U8;
>> -       } else if (chip_info->data_size <= 16) {
>> +       } else if (chip_info->data_size <= SSP_DATA_BITS_16) {
>
> I just realized that Kevin Wells patch actually patch away this problem
> so merge his patch and disregard this for the optimal solution.
>
>>  enum ssp_data_size {
>> -       SSP_DATA_BITS_4 = 0x03, SSP_DATA_BITS_5, SSP_DATA_BITS_6,
>> +       SSP_DATA_BITS_4 = 0x04, SSP_DATA_BITS_5, SSP_DATA_BITS_6,
>
> This is not good because this is used for default register
> settings too (I didn't notice, typical).

And it creates a 1:1 mapping of name to the same number.  Insane!
Just use the integer number directly.  :-)

>
> If anyone still wants a patch for older kernels I can provide a
> patch against 2.6.36-rc6 with just the first two hunks.
>
> Yours,
> Linus Walleij
>



-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] spi/pl022: compare bitwidth to enums
  2010-09-30 14:37   ` Grant Likely
@ 2010-09-30 16:21     ` Kevin Wells
  0 siblings, 0 replies; 4+ messages in thread
From: Kevin Wells @ 2010-09-30 16:21 UTC (permalink / raw)
  To: Grant Likely, Linus Walleij
  Cc: spi-devel-general@lists.sourceforge.net, Linus Walleij,
	linux-arm-kernel@lists.infradead.org


> >> The enums from <linux/amba/pl022.h> are actually off-by-one
> >> since bitwidth 4 is defined as 0x03, causing weirdness when
> >> we were trying out some 9-bit peripheral. Fix this by
> >> comparing to the enum values rather than hardcoded values
> >> and also fixing the enum to something reasonable.
> >>
> >> Signed-off-by: Linus Walleij <linus.walleij@stericsson.com>
> >> (...)
> >> -       if (chip_info->data_size <= 8) {
> >> +       if (chip_info->data_size <= SSP_DATA_BITS_8) {
> >>                dev_dbg(&spi->dev, "1 <= n <=8 bits per word\n");
> >>                chip->n_bytes = 1;
> >>                chip->read = READING_U8;
> >>                chip->write = WRITING_U8;
> >> -       } else if (chip_info->data_size <= 16) {
> >> +       } else if (chip_info->data_size <= SSP_DATA_BITS_16) {
> >
> > I just realized that Kevin Wells patch actually patch away this problem
> > so merge his patch and disregard this for the optimal solution.
> >
> >>  enum ssp_data_size {
> >> -       SSP_DATA_BITS_4 = 0x03, SSP_DATA_BITS_5, SSP_DATA_BITS_6,
> >> +       SSP_DATA_BITS_4 = 0x04, SSP_DATA_BITS_5, SSP_DATA_BITS_6,
> >
> > This is not good because this is used for default register
> > settings too (I didn't notice, typical).
> 
> And it creates a 1:1 mapping of name to the same number.  Insane!
> Just use the integer number directly.  :-)

The spi->mode patch I submitted a few weeks ago actually removed the
data_size field from chip_info and uses spi->data_bus_bits instead.
The values passed into the dss field for the control0 register
subtracts 1 from the spi->data_bus_bits to get the correct value now.

Reference: 09/16/2010
[PATCH] spi: amba_pl022: Add spi->mode support to AMBA SPI driver

> 
> >
> > If anyone still wants a patch for older kernels I can provide a
> > patch against 2.6.36-rc6 with just the first two hunks.
> >
> > Yours,
> > Linus Walleij
> >
> 
> 
> 
> --
> Grant Likely, B.Sc., P.Eng.
> Secret Lab Technologies Ltd.
> 
> --------------------------------------------------------------------------
> ----
> Start uncovering the many advantages of virtual appliances
> and start using them to simplify application deployment and
> accelerate your shift to cloud computing.
> http://p.sf.net/sfu/novell-sfdev2dev
> _______________________________________________
> spi-devel-general mailing list
> spi-devel-general@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/spi-devel-general

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-09-30 16:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-30  9:57 [PATCH] spi/pl022: compare bitwidth to enums Linus Walleij
2010-09-30 11:34 ` Linus Walleij
2010-09-30 14:37   ` Grant Likely
2010-09-30 16:21     ` Kevin Wells

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).