spi: davinci: add support for gpio cs through dt
Subsystems (2)
cover spi: davinci: add support for gpio cs through dt
This small series enables GPIO chip select feature for Davinci SPI when DT-boot mode is used.
This is actual for Keystone 2 which supports DT-boot mode only.
Murali Karicheri (2):
spi: davinci: fix to support more than 2 chip selects
spi: davinci: add support to configure GPIO CS through DT
.../devicetree/bindings/spi/spi-davinci.txt | 9 ++- drivers/spi/spi-davinci.c | 71 +++++++++++++++++--- 2 files changed, 68 insertions(+), 12 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/2 spi: davinci: fix to support more than 2 chip selects
From: Murali Karicheri <[email protected]>
Currently, the driver defines SPI_MAX_CHIPSELECT as 2 and use per device array bytes_per_word based on this. This breaks if num_chipselect per device is greater than 2. This patch fix this and allocate memory for this array based on num_chipselect.
It's preparation patch to enable GPIO CS feature for Davinci SPI.
--- drivers/spi/spi-davinci.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/spi/spi-davinci.c +9 -3
@@ -38,8 +38,6 @@#define SPI_NO_RESOURCE ((resource_size_t)-1) -#define SPI_MAX_CHIPSELECT 2 -#define CS_DEFAULT 0xFF#define SPIFMT_PHASE_MASK BIT(16)
@@ -142,7 +140,7 @@ struct davinci_spi {void (*get_rx)(u32 rx_data,struct davinci_spi *);u32 (*get_tx)(struct davinci_spi *); -u8 bytes_per_word[SPI_MAX_CHIPSELECT ]; +u8 *bytes_per_word; };static struct davinci_spi_config davinci_spi_default_cfg;
@@ -876,6 +874,14 @@ static int davinci_spi_probe(struct platform_device *pdev)/* pdata in dspi is now updated and point pdata to that */ pdata = &dspi->pdata; + dspi->bytes_per_word =devm_kzalloc (&pdev->dev, +sizeof (*dspi->bytes_per_word) * + pdata->num_chipselect,GFP_KERNEL ); +if (dspi->bytes_per_word ==NULL ) { + ret = -ENOMEM ; + goto free_master; + } + r =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (r ==NULL ) { ret = -ENOENT ;
Signature · 1 line
1.7.9.5
Mark Brown
maintainerPATCH 1/2 spi: davinci: fix to support more than 2 chip selects
Quoted 7 lines · Grygorii Strashko
From: Murali Karicheri <[email protected]>
Currently, the driver defines
SPI_MAX_CHIPSELECTas 2 and use per device arraybytes_per_wordbased on this. This breaks ifnum_chipselectper device is greater than 2. This patch fix this and allocate memory for this array based onnum_chipselect.
Applied, thanks.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140731/cfb4f923/attachment.sig>
PATCH 2/2 spi: davinci: add support to configure gpio cs through dt
In reply to Grygorii StrashkoFrom: Murali Karicheri <[email protected]>
Currently driver supports only configuration of GPIO CS through platform data. This patch enhances the driver to configure GPIO CS through DT. Also update the DT binding documentation to reflect the availability of cs-gpios.
--- .../devicetree/bindings/spi/spi-davinci.txt | 9 ++- drivers/spi/spi-davinci.c | 59 +++++++++++++++++--- 2 files changed, 59 insertions(+), 9 deletions(-)
Documentation/devicetree/bindings/spi/spi-davinci.txt +8 -1
@@ -8,7 +8,8 @@ Required properties: - "ti,dm6441-spi" for SPI used similar to that on DM644x SoC family - "ti,da830-spi" for SPI used similar to that on DA8xx SoC family - reg: Offset and length of SPI controller register space -- num-cs: Number of chip selects +- num-cs: Number of chip selects. This includes internal as well as + GPIO chip selects. - ti,davinci-spi-intr-line: interrupt line used to connect the SPI IP to the interrupt controller within the SoC. Possible values are 0 and 1. Manual says one of the two possible interrupt
@@ -17,6 +18,12 @@ Required properties: - interrupts: interrupt number mapped to CPU. - clocks: spi clk phandle +Optional: +- cs-gpios: gpio chip selects + For example to have 3 internal CS and 2 GPIO CS, user could define + cs-gpios = <0>, <0>, <0>, <&gpio1 30 0>, <&gpio1 31 0>; + where first three are internal CS and last two are GPIO CS. + Example of a NOR flash slave device (n25q032) connected to DaVinci SPI controller device over the SPI bus.
drivers/spi/spi-davinci.c +51 -8
118 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Mark Brown
maintainerPATCH 2/2 spi: davinci: add support to configure gpio cs through dt
drivers/spi/spi-davinci.c static inline void clear_io_bits(void __iomem *addr, u32 bits) · line 232
Quoted 11 lines · Grygorii Strashko
drivers/spi/spi-davinci.c +10
-0+if (np && master->cs_gpios !=NULL && spi->cs_gpio >=0 ) { +/* SPI core parse and update master->cs_gpio */ gpio_chipsel = true; + gpio = spi->cs_gpio; + }else if (pdata->chip_sel && + chip_sel < pdata->num_chipselect && + pdata->chip_sel[chip_sel] !=SPI_INTERN_CS ) { +/* platform data defines chip_sel */ + gpio_chipsel = true; + gpio = pdata->chip_sel[chip_sel]; + }
This would all be a lot simpler and more direct if you were to arrange to use cs_gpio in the struct spi_device, and move you closer to converting to use more of the core functionality.
drivers/spi/spi-davinci.c static int davinci_spi_setup(struct spi_device *spi) · line 424
Quoted 12 lines
drivers/spi/spi-davinci.c +12
-0+if (np && (master->cs_gpios !=NULL ) && (spi->cs_gpio >=0 )) { + retval = +gpio_request (spi->cs_gpio,dev_name (&spi->dev)); +if (retval) { +dev_err (&spi->dev, +"GPIO %d request failed\n" , + spi->cs_gpio); +return -ENODEV ; + } +gpio_direction_output (spi->cs_gpio, + !(spi->mode &SPI_CS_HIGH )); + internal_cs = false;
It's much better to use gpio_request_one() rather than usinggpio_request(), it's one function apart from anything else. The above
is also discarding the return code of gpio_request() meaning it's broken
for deferred probe. The error code should also appear in the error
message.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140731/9580c14e/attachment.sig>
PATCH 2/2 spi: davinci: add support to configure gpio cs through dt
Hi Mark,
Quoted 17 lines · Mark Brown
drivers/spi/spi-davinci.c static inline void clear_io_bits(void __iomem *addr, u32 bits) · line 232
Quoted 11 lines · Grygorii Strashko
drivers/spi/spi-davinci.c +10
-0+if (np && master->cs_gpios !=NULL && spi->cs_gpio >=0 ) { +/* SPI core parse and update master->cs_gpio */ gpio_chipsel = true; + gpio = spi->cs_gpio; + }else if (pdata->chip_sel && + chip_sel < pdata->num_chipselect && + pdata->chip_sel[chip_sel] !=SPI_INTERN_CS ) { +/* platform data defines chip_sel */ + gpio_chipsel = true; + gpio = pdata->chip_sel[chip_sel]; + }This would all be a lot simpler and more direct if you were to arrange to use
cs_gpioin the structspi_device, and move you closer to converting to use more of the core functionality.
Unfortunately, I'm not sure this is good idea, because this part of code is used by Davinci arch which is non-DT platform. As result, this code was kept mostly unchanged.
I can try to rework it, but I'd like to do it as standalone patch. Is it ok for you?
Quoted 11 lines
Quoted 11 lines
drivers/spi/spi-davinci.c +10
-0+if (np && (master->cs_gpios !=NULL ) && (spi->cs_gpio >=0 )) { + retval = +gpio_request (spi->cs_gpio,dev_name (&spi->dev)); +if (retval) { +dev_err (&spi->dev, +"GPIO %d request failed\n" , + spi->cs_gpio); +return -ENODEV ; + } + gpio_direction_output(spi->cs_gpio,
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ !(spi->mode & SPI_CS_HIGH)); + internal_cs = false;It's much better to use
gpio_request_one()rather than usinggpio_request(), it's one function apart from anything else. The above is also discarding the return code ofgpio_request()meaning it's broken for deferred probe. The error code should also appear in the error message.
Thanks, will update.
Regards,
-grygorii
PATCH 2/2 spi: davinci: add support to configure gpio cs through dt
Hi Mark,
Quoted 20 lines · Grygorii Strashko
Hi Mark,
Quoted 17 lines · Mark Brown
drivers/spi/spi-davinci.c static inline void clear_io_bits(void __iomem *addr, u32 bits) · line 232
Quoted 11 lines · Grygorii Strashko
drivers/spi/spi-davinci.c +10
-0+if (np && master->cs_gpios !=NULL && spi->cs_gpio >=0 ) { +/* SPI core parse and update master->cs_gpio */ gpio_chipsel = true; + gpio = spi->cs_gpio; + }else if (pdata->chip_sel && + chip_sel < pdata->num_chipselect && + pdata->chip_sel[chip_sel] !=SPI_INTERN_CS ) { +/* platform data defines chip_sel */ + gpio_chipsel = true; + gpio = pdata->chip_sel[chip_sel]; + }This would all be a lot simpler and more direct if you were to arrange to use
cs_gpioin the structspi_device, and move you closer to converting to use more of the core functionality.
Quoted 6 lines
Unfortunately, I'm not sure this is good idea, because this part of code is used by Davinci arch which is non-DT platform. As result, this code was kept mostly unchanged.
I can try to rework it, but I'd like to do it as standalone patch. Is it ok for you?
I've just sent updated version with additional patch where I reworked driver for using cs_gpio for both DT and non-DT cases.
http://www.spinics.net/lists/arm-kernel/msg352382.html
Regards,
-grygorii