linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] spi: lpspi: SS function related changes
@ 2019-04-23 10:46 Clark Wang
  2019-04-23 10:46 ` [PATCH 1/3] spi: lpspi: add NULL check when probe device Clark Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Clark Wang @ 2019-04-23 10:46 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi, linux-kernel

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


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

* [PATCH 1/3] spi: lpspi: add NULL check when probe device
  2019-04-23 10:46 [PATCH 0/3] spi: lpspi: SS function related changes Clark Wang
@ 2019-04-23 10:46 ` Clark Wang
  2019-04-23 11:14   ` Fabio Estevam
  2019-04-23 10:46 ` [PATCH 2/3] spi: lpspi: add multi SS support in PIO mode Clark Wang
  2019-04-23 10:46 ` [PATCH 3/3] spi: lpspi: remove fsl_lpspi->chipselect Clark Wang
  2 siblings, 1 reply; 6+ messages in thread
From: Clark Wang @ 2019-04-23 10:46 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi, linux-kernel

Add a NULL check for device node and lpspi_platform_info when lpspi
device probe.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Acked-by: Fugang Duan <fugang.duan@nxp.com>
---
 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


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

* [PATCH 2/3] spi: lpspi: add multi SS support in PIO mode
  2019-04-23 10:46 [PATCH 0/3] spi: lpspi: SS function related changes Clark Wang
  2019-04-23 10:46 ` [PATCH 1/3] spi: lpspi: add NULL check when probe device Clark Wang
@ 2019-04-23 10:46 ` Clark Wang
  2019-04-23 11:21   ` Fabio Estevam
  2019-04-23 10:46 ` [PATCH 3/3] spi: lpspi: remove fsl_lpspi->chipselect Clark Wang
  2 siblings, 1 reply; 6+ messages in thread
From: Clark Wang @ 2019-04-23 10:46 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi, linux-kernel

Add "fsl,spi-num-chipselects" check to support multi SS function in PIO
mode.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Acked-by: Fugang Duan <fugang.duan@nxp.com>
---
 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


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

* [PATCH 3/3] spi: lpspi: remove fsl_lpspi->chipselect
  2019-04-23 10:46 [PATCH 0/3] spi: lpspi: SS function related changes Clark Wang
  2019-04-23 10:46 ` [PATCH 1/3] spi: lpspi: add NULL check when probe device Clark Wang
  2019-04-23 10:46 ` [PATCH 2/3] spi: lpspi: add multi SS support in PIO mode Clark Wang
@ 2019-04-23 10:46 ` Clark Wang
  2 siblings, 0 replies; 6+ messages in thread
From: Clark Wang @ 2019-04-23 10:46 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi, linux-kernel

Replace fsl_lpspi->chipselect by controller->cs_gpios. Clean up the
code.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Acked-by: Fugang Duan <fugang.duan@nxp.com>
---
 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


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

* Re: [PATCH 1/3] spi: lpspi: add NULL check when probe device
  2019-04-23 10:46 ` [PATCH 1/3] spi: lpspi: add NULL check when probe device Clark Wang
@ 2019-04-23 11:14   ` Fabio Estevam
  0 siblings, 0 replies; 6+ messages in thread
From: Fabio Estevam @ 2019-04-23 11:14 UTC (permalink / raw)
  To: Clark Wang; +Cc: broonie, linux-spi, linux-kernel

Hi Clark,

On Tue, Apr 23, 2019 at 7:47 AM Clark Wang <xiaoning.wang@nxp.com> wrote:
>
> Add a NULL check for device node and lpspi_platform_info when lpspi
> device probe.

Please explain why you are adding such check.

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

* Re: [PATCH 2/3] spi: lpspi: add multi SS support in PIO mode
  2019-04-23 10:46 ` [PATCH 2/3] spi: lpspi: add multi SS support in PIO mode Clark Wang
@ 2019-04-23 11:21   ` Fabio Estevam
  0 siblings, 0 replies; 6+ messages in thread
From: Fabio Estevam @ 2019-04-23 11:21 UTC (permalink / raw)
  To: Clark Wang; +Cc: broonie, linux-spi, linux-kernel

On Tue, Apr 23, 2019 at 7:48 AM Clark Wang <xiaoning.wang@nxp.com> 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 <shc_work@mail.ru>
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 <shc_work@mail.ru>
    Signed-off-by: Mark Brown <broonie@kernel.org>

and we should try to also avoid such property in spi-fsl-lpspi as well.

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

end of thread, other threads:[~2019-04-23 11:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-23 10:46 [PATCH 0/3] spi: lpspi: SS function related changes Clark Wang
2019-04-23 10:46 ` [PATCH 1/3] spi: lpspi: add NULL check when probe device Clark Wang
2019-04-23 11:14   ` Fabio Estevam
2019-04-23 10:46 ` [PATCH 2/3] spi: lpspi: add multi SS support in PIO mode Clark Wang
2019-04-23 11:21   ` Fabio Estevam
2019-04-23 10:46 ` [PATCH 3/3] spi: lpspi: remove fsl_lpspi->chipselect Clark Wang

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