* [PATCH 1/2] spi: check bits_per_word in spi_setup
[not found] ` <1439278071-21110-1-git-send-email-stefan.bruens-vA1bhqPz9FBZXbeN9DUtxg@public.gmane.org>
@ 2015-08-11 7:27 ` Stefan Brüns
2015-08-11 7:27 ` [PATCH 2/2] staging/fbtft: use spi_setup instead of direct call to master->setup Stefan Brüns
` (2 subsequent siblings)
3 siblings, 0 replies; 4+ messages in thread
From: Stefan Brüns @ 2015-08-11 7:27 UTC (permalink / raw)
To: linux-spi-u79uwXL29TY76Z2rM5mHXA; +Cc: Stefan Brüns
This allows drivers for devices connected via SPI to check if the
controller supports a given bits_per_word value during setup.
Currently any BPW value is accepted durings setup, and transfers
are rejected later.
Signed-off-by: Stefan Brüns <stefan.bruens-vA1bhqPz9FBZXbeN9DUtxg@public.gmane.org>
---
drivers/spi/spi.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index cf8b91b..98aaa31 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1740,6 +1740,20 @@ EXPORT_SYMBOL_GPL(spi_busnum_to_master);
* other core methods are currently defined as inline functions.
*/
+static int __spi_validate_bits_per_word(struct spi_master *master, u8 bits_per_word)
+{
+ if (master->bits_per_word_mask) {
+ /* Only 32 bits fit in the mask */
+ if (bits_per_word > 32)
+ return -EINVAL;
+ if (!(master->bits_per_word_mask &
+ SPI_BPW_MASK(bits_per_word)))
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
/**
* spi_setup - setup SPI mode and clock rate
* @spi: the device whose settings are being modified
@@ -1798,6 +1812,9 @@ int spi_setup(struct spi_device *spi)
if (!spi->bits_per_word)
spi->bits_per_word = 8;
+ if (__spi_validate_bits_per_word(spi->master, spi->bits_per_word))
+ return -EINVAL;
+
if (!spi->max_speed_hz)
spi->max_speed_hz = spi->master->max_speed_hz;
@@ -1865,14 +1882,8 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
xfer->speed_hz > master->max_speed_hz)
xfer->speed_hz = master->max_speed_hz;
- if (master->bits_per_word_mask) {
- /* Only 32 bits fit in the mask */
- if (xfer->bits_per_word > 32)
- return -EINVAL;
- if (!(master->bits_per_word_mask &
- BIT(xfer->bits_per_word - 1)))
- return -EINVAL;
- }
+ if (__spi_validate_bits_per_word(master, xfer->bits_per_word))
+ return -EINVAL;
/*
* SPI transfer length should be multiple of SPI word size
--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] staging/fbtft: use spi_setup instead of direct call to master->setup
[not found] ` <1439278071-21110-1-git-send-email-stefan.bruens-vA1bhqPz9FBZXbeN9DUtxg@public.gmane.org>
2015-08-11 7:27 ` [PATCH 1/2] spi: check bits_per_word in spi_setup Stefan Brüns
@ 2015-08-11 7:27 ` Stefan Brüns
2015-08-15 18:30 ` [PATCH 0/2] Fix displays requiring 9 bit transfers on RPi Stefan Bruens
2015-08-18 20:41 ` Brüns, Stefan
3 siblings, 0 replies; 4+ messages in thread
From: Stefan Brüns @ 2015-08-11 7:27 UTC (permalink / raw)
To: linux-spi-u79uwXL29TY76Z2rM5mHXA; +Cc: Stefan Brüns
Avoid a crash, as master->setup may be NULL (e.g. xilinx controller).
Even if master->setup is set, spi_setup does several compatibility/
sanity checks which should not be skipped (fixes problems with
displays/controllers needing emulation for bits_per_word = 9).
Signed-off-by: Stefan Brüns <stefan.bruens-vA1bhqPz9FBZXbeN9DUtxg@public.gmane.org>
---
drivers/staging/fbtft/fb_watterott.c | 4 ++--
drivers/staging/fbtft/fbtft-core.c | 4 ++--
drivers/staging/fbtft/flexfb.c | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/fbtft/fb_watterott.c b/drivers/staging/fbtft/fb_watterott.c
index 88fb2c0..8eae6ef 100644
--- a/drivers/staging/fbtft/fb_watterott.c
+++ b/drivers/staging/fbtft/fb_watterott.c
@@ -169,7 +169,7 @@ static int init_display(struct fbtft_par *par)
/* enable SPI interface by having CS and MOSI low during reset */
save_mode = par->spi->mode;
par->spi->mode |= SPI_CS_HIGH;
- ret = par->spi->master->setup(par->spi); /* set CS inactive low */
+ ret = spi_setup(par->spi); /* set CS inactive low */
if (ret) {
dev_err(par->info->device, "Could not set SPI_CS_HIGH\n");
return ret;
@@ -180,7 +180,7 @@ static int init_display(struct fbtft_par *par)
par->fbtftops.reset(par);
mdelay(1000);
par->spi->mode = save_mode;
- ret = par->spi->master->setup(par->spi);
+ ret = spi_setup(par->spi);
if (ret) {
dev_err(par->info->device, "Could not restore SPI mode\n");
return ret;
diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c
index 9cc8141..ba08da3 100644
--- a/drivers/staging/fbtft/fbtft-core.c
+++ b/drivers/staging/fbtft/fbtft-core.c
@@ -1434,12 +1434,12 @@ int fbtft_probe_common(struct fbtft_display *display,
/* 9-bit SPI setup */
if (par->spi && display->buswidth == 9) {
par->spi->bits_per_word = 9;
- ret = par->spi->master->setup(par->spi);
+ ret = spi_setup(par->spi);
if (ret) {
dev_warn(&par->spi->dev,
"9-bit SPI not available, emulating using 8-bit.\n");
par->spi->bits_per_word = 8;
- ret = par->spi->master->setup(par->spi);
+ ret = spi_setup(par->spi);
if (ret)
goto out_release;
/* allocate buffer with room for dc bits */
diff --git a/drivers/staging/fbtft/flexfb.c b/drivers/staging/fbtft/flexfb.c
index 2c4ce07..fecf486 100644
--- a/drivers/staging/fbtft/flexfb.c
+++ b/drivers/staging/fbtft/flexfb.c
@@ -440,12 +440,12 @@ static int flexfb_probe_common(struct spi_device *sdev,
par->fbtftops.write_register = fbtft_write_reg8_bus9;
par->fbtftops.write_vmem = fbtft_write_vmem16_bus9;
sdev->bits_per_word = 9;
- ret = sdev->master->setup(sdev);
+ ret = spi_setup(sdev);
if (ret) {
dev_warn(dev,
"9-bit SPI not available, emulating using 8-bit.\n");
sdev->bits_per_word = 8;
- ret = sdev->master->setup(sdev);
+ ret = spi_setup(sdev);
if (ret)
goto out_release;
/* allocate buffer with room for dc bits */
--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] Fix displays requiring 9 bit transfers on RPi
[not found] ` <1439278071-21110-1-git-send-email-stefan.bruens-vA1bhqPz9FBZXbeN9DUtxg@public.gmane.org>
2015-08-11 7:27 ` [PATCH 1/2] spi: check bits_per_word in spi_setup Stefan Brüns
2015-08-11 7:27 ` [PATCH 2/2] staging/fbtft: use spi_setup instead of direct call to master->setup Stefan Brüns
@ 2015-08-15 18:30 ` Stefan Bruens
2015-08-18 20:41 ` Brüns, Stefan
3 siblings, 0 replies; 4+ messages in thread
From: Stefan Bruens @ 2015-08-15 18:30 UTC (permalink / raw)
To: linux-spi-u79uwXL29TY76Z2rM5mHXA
Hi,
any comments on these two patches?
Kind regards,
Stefan
On Tuesday 11 August 2015 09:27:49 you wrote:
> Some displays need 9 bit long SPI transfers (Command/Data flag plus
> 8 bit data). FBTFT has emulation code in case the controller only
> supports 8 bit transfers, but this is only used if the controller
> setup function report an error if bits_per_word is set to 9.
>
> Report unsupported bits_per_word settings in spi_setup Currently the
> SPI core only checks bits_per_word on transfer, but not on setup.
>
> Replace invocations of master->setup(...) with spi_setup(...).
>
> Tested on RPi B with an Ilitek9341 based TFT display in 9 bit mode.
>
> Stefan Brüns (2):
> spi: check bits_per_word in spi_setup
> staging/fbtft: use spi_setup instead of direct call to master->setup
>
> drivers/spi/spi.c | 27 +++++++++++++++++++--------
> drivers/staging/fbtft/fb_watterott.c | 4 ++--
> drivers/staging/fbtft/fbtft-core.c | 4 ++--
> drivers/staging/fbtft/flexfb.c | 4 ++--
> 4 files changed, 25 insertions(+), 14 deletions(-)
--
Stefan Brüns / Bergstraße 21 / 52062 Aachen
home: +49 241 53809034 mobile: +49 151 50412019
work: +49 2405 49936-424
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] Fix displays requiring 9 bit transfers on RPi
[not found] ` <1439278071-21110-1-git-send-email-stefan.bruens-vA1bhqPz9FBZXbeN9DUtxg@public.gmane.org>
` (2 preceding siblings ...)
2015-08-15 18:30 ` [PATCH 0/2] Fix displays requiring 9 bit transfers on RPi Stefan Bruens
@ 2015-08-18 20:41 ` Brüns, Stefan
3 siblings, 0 replies; 4+ messages in thread
From: Brüns, Stefan @ 2015-08-18 20:41 UTC (permalink / raw)
To: linux-spi-u79uwXL29TY76Z2rM5mHXA
Hi,
any comments on these two patches, please?
Kind regards,
Stefan
On Tuesday, August 11, 2015 09:27:49 you wrote:
> Some displays need 9 bit long SPI transfers (Command/Data flag plus
> 8 bit data). FBTFT has emulation code in case the controller only
> supports 8 bit transfers, but this is only used if the controller
> setup function report an error if bits_per_word is set to 9.
>
> Report unsupported bits_per_word settings in spi_setup Currently the
> SPI core only checks bits_per_word on transfer, but not on setup.
>
> Replace invocations of master->setup(...) with spi_setup(...).
>
> Tested on RPi B with an Ilitek9341 based TFT display in 9 bit mode.
>
> Stefan Brüns (2):
> spi: check bits_per_word in spi_setup
> staging/fbtft: use spi_setup instead of direct call to master->setup
>
> drivers/spi/spi.c | 27 +++++++++++++++++++--------
> drivers/staging/fbtft/fb_watterott.c | 4 ++--
> drivers/staging/fbtft/fbtft-core.c | 4 ++--
> drivers/staging/fbtft/flexfb.c | 4 ++--
> 4 files changed, 25 insertions(+), 14 deletions(-)
--
Stefan Brüns / Bergstraße 21 / 52062 Aachen
home: +49 241 53809034 mobile: +49 151 50412019
work: +49 2405 49936-424--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-08-18 20:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1439278071-21110-1-git-send-email-stefan.bruens@rwth-aachen.de>
[not found] ` <1439278071-21110-1-git-send-email-stefan.bruens-vA1bhqPz9FBZXbeN9DUtxg@public.gmane.org>
2015-08-11 7:27 ` [PATCH 1/2] spi: check bits_per_word in spi_setup Stefan Brüns
2015-08-11 7:27 ` [PATCH 2/2] staging/fbtft: use spi_setup instead of direct call to master->setup Stefan Brüns
2015-08-15 18:30 ` [PATCH 0/2] Fix displays requiring 9 bit transfers on RPi Stefan Bruens
2015-08-18 20:41 ` Brüns, Stefan
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).