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(-)
--
2.17.1
Add "fsl,spi-num-chipselects" check to support multi SS function in PIO
mode.
Signed-off-by: Clark Wang <[email protected]>
Acked-by: Fugang Duan <[email protected]>
---
drivers/spi/spi-fsl-lpspi.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index 19040b5ef349..a8e83cb96f61 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -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;
--
2.17.1
Replace fsl_lpspi->chipselect by controller->cs_gpios. Clean up the
code.
Signed-off-by: Clark Wang <[email protected]>
Acked-by: Fugang Duan <[email protected]>
---
drivers/spi/spi-fsl-lpspi.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index a8e83cb96f61..aa6218cbc9e8 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -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;
}
--
2.17.1
Add a NULL check for device node and lpspi_platform_info when lpspi
device probe.
Signed-off-by: Clark Wang <[email protected]>
Acked-by: Fugang Duan <[email protected]>
---
drivers/spi/spi-fsl-lpspi.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index d08e9324140e..19040b5ef349 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -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,
--
2.17.1
Hi Clark,
On Tue, Apr 23, 2019 at 7:47 AM Clark Wang <[email protected]> wrote:
>
> Add a NULL check for device node and lpspi_platform_info when lpspi
> device probe.
Please explain why you are adding such check.
On Tue, Apr 23, 2019 at 7:48 AM Clark Wang <[email protected]> wrote:
>
> 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.
Signed-off-by: Alexander Shiyan <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
and we should try to also avoid such property in spi-fsl-lpspi as well.