spi: lpspi: SS function related changes
Subsystems (2)
cover spi: lpspi: SS function related changes
Hi Mark,
These three patches do some code clean up works and fix a problem when use multi SS in PIO mode.
Clark Wang (3):
spi: lpspi: add NULL check when probe device
spi: lpspi: add multi SS support in PIO mode
spi: lpspi: remove fsl_lpspi->chipselect
drivers/spi/spi-fsl-lpspi.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 spi: lpspi: add NULL check when probe device
Add a NULL check for device node and lpspi_platform_info when lpspi device probe.
--- drivers/spi/spi-fsl-lpspi.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/spi/spi-fsl-lpspi.c +5 -0
@@ -845,6 +845,11 @@ static int fsl_lpspi_probe(struct platform_device *pdev)u32 temp;bool is_slave; +if (!np && !lpspi_platform_info) { +dev_err (&pdev->dev,"can't get the platform data\n" ); +return -EINVAL ; + } + is_slave =of_property_read_bool ((&pdev->dev)->of_node,"spi-slave" );if (is_slave) controller = spi_alloc_slave(&pdev->dev,
Signature · 1 line
2.17.1
Re: [PATCH 1/3] spi: lpspi: add NULL check when probe device
Hi Clark,
Quoted 3 lines · Clark Wang
Add a NULL check for device node and
lpspi_platform_infowhen lpspi device probe.
Please explain why you are adding such check.
PATCH 2/3 spi: lpspi: add multi SS support in PIO mode
In reply to Clark WangAdd "fsl,spi-num-chipselects" check to support multi SS function in PIO mode.
--- drivers/spi/spi-fsl-lpspi.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/spi/spi-fsl-lpspi.c +11 -1
@@ -841,7 +841,7 @@ static int fsl_lpspi_probe(struct platform_device *pdev)struct spi_imx_master *lpspi_platform_info =dev_get_platdata (&pdev->dev);struct resource *res; -int i, ret, irq; +int i, ret, irq, num_cs;u32 temp;bool is_slave;
@@ -863,6 +863,16 @@ static int fsl_lpspi_probe(struct platform_device *pdev)platform_set_drvdata (pdev, controller); + ret =of_property_read_u32 (np,"fsl,spi-num-chipselects" , &num_cs); +if (ret <0 ) { +if (lpspi_platform_info) { + num_cs = lpspi_platform_info->num_chipselect; + controller->num_chipselect = num_cs; + } + }else { + controller->num_chipselect = num_cs; + } + fsl_lpspi =spi_controller_get_devdata (controller); fsl_lpspi->dev = &pdev->dev; fsl_lpspi->is_slave = is_slave;
Signature · 1 line
2.17.1
Re: [PATCH 2/3] spi: lpspi: add multi SS support in PIO mode
Quoted 3 lines · Clark Wang
Add "fsl,spi-num-chipselects" check to support multi SS function in PIO mode.
This custom property does not seem to be needed as the number of chip selects can be parsed from the devicetree file directly.
We got rid of "fsl,spi-num-chipselects" property in the spi-imx driver in this commit:
commit b36581df7e788b674a4efbb8da7fe4a00c207e8b
Author: Alexander Shiyan <[email protected]> Date: Wed Jun 8 20:02:06 2016 +0300
spi: imx: Using existing properties for chipselects
Patch reuse existing "chip_select" and "cs_gpio(s)" fields from SPI core.
and we should try to also avoid such property in spi-fsl-lpspi as well.
PATCH 3/3 spi: lpspi: remove fsl_lpspi->chipselect
In reply to Clark WangReplace fsl_lpspi->chipselect by controller->cs_gpios. Clean up the code.
--- drivers/spi/spi-fsl-lpspi.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/spi/spi-fsl-lpspi.c +6 -8
@@ -124,8 +124,6 @@ struct fsl_lpspi_data {bool usedma;struct completion dma_rx_completion;struct completion dma_tx_completion; - -int chipselect[0 ]; };static const struct of_device_id fsl_lpspi_dt_ids[] = {
@@ -230,10 +228,8 @@ static int lpspi_unprepare_xfer_hardware(struct spi_controller *controller)static int fsl_lpspi_prepare_message (struct spi_controller *controller,struct spi_message *msg) { -struct fsl_lpspi_data *fsl_lpspi = -spi_controller_get_devdata (controller);struct spi_device *spi = msg->spi; -int gpio = fsl_lpspi->chipselect[spi->chip_select]; +int gpio = controller->cs_gpios[spi->chip_select];if (gpio_is_valid (gpio))gpio_direction_output (gpio, spi->mode &SPI_CS_HIGH ?0 :1 );
@@ -877,6 +873,9 @@ static int fsl_lpspi_probe(struct platform_device *pdev) fsl_lpspi->dev = &pdev->dev; fsl_lpspi->is_slave = is_slave; + controller->cs_gpios =devm_kzalloc (&controller->dev, +sizeof (int ) * controller->num_chipselect,GFP_KERNEL ); +if (!fsl_lpspi->is_slave) {for (i =0 ; i < controller->num_chipselect; i++) {int cs_gpio =of_get_named_gpio (np,"cs-gpios" , i);
@@ -884,19 +883,18 @@ static int fsl_lpspi_probe(struct platform_device *pdev)if (!gpio_is_valid (cs_gpio) && lpspi_platform_info) cs_gpio = lpspi_platform_info->chipselect[i]; - fsl_lpspi->chipselect[i] = cs_gpio; + controller->cs_gpios[i] = cs_gpio;if (!gpio_is_valid (cs_gpio))continue ; ret =devm_gpio_request (&pdev->dev, - fsl_lpspi->chipselect[i], + controller->cs_gpios[i],DRIVER_NAME );if (ret) {dev_err (&pdev->dev,"can't get cs gpios\n" ); goto out_controller_put; } } - controller->cs_gpios = fsl_lpspi->chipselect; controller->prepare_message = fsl_lpspi_prepare_message; }
Signature · 1 line
2.17.1