[PATCH] spi: imx: Fix the number of chipselects count

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On an imx6q-sabresd board, which has one single GPIO chipselect used
for SPI, the SPI core now reports that it has 3 chipselects.

This happens since commit 8cdcd8aeee281 ("spi: imx/fsl-lpspi: Convert to
GPIO descriptors"), which assigned master->num_chipselect as 3 when
'num-cs' is absent.

However, 'num-cs' property is not used in any in-tree devicetree, leading
to an incorrect count of chipselects.

Fix the number of chipselects count by only assigning
master->num_chipselect in the unlikely case when the "cs-gpios" property
is absent.

Print a warning in this case, since using native chipselects in
several i.MX SoCs is known to be problematic.

While at it, use 4 as the maximum number of native chip-select supported
by this controller.

Fixes: 8cdcd8aeee281 ("spi: imx/fsl-lpspi: Convert to GPIO descriptors")
Signed-off-by: Fabio Estevam <festevam@xxxxxxxxx>
---
 drivers/spi/spi-imx.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 197f60632072..968c868cf17f 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -13,6 +13,7 @@
 #include <linux/irq.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of_gpio.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
@@ -1581,7 +1582,7 @@ static int spi_imx_probe(struct platform_device *pdev)
 	const struct spi_imx_devtype_data *devtype_data = of_id ? of_id->data :
 		(struct spi_imx_devtype_data *)pdev->id_entry->driver_data;
 	bool slave_mode;
-	u32 val;
+	int num_cs_gpios;
 
 	slave_mode = devtype_data->has_slavemode &&
 			of_property_read_bool(np, "spi-slave");
@@ -1613,16 +1614,12 @@ static int spi_imx_probe(struct platform_device *pdev)
 
 	spi_imx->devtype_data = devtype_data;
 
-	/*
-	 * Get number of chip selects from device properties. This can be
-	 * coming from device tree or boardfiles, if it is not defined,
-	 * a default value of 3 chip selects will be used, as all the legacy
-	 * board files have <= 3 chip selects.
-	 */
-	if (!device_property_read_u32(&pdev->dev, "num-cs", &val))
-		master->num_chipselect = val;
-	else
-		master->num_chipselect = 3;
+	num_cs_gpios = gpiod_count(&pdev->dev, "cs");
+	if ((num_cs_gpios == 0) || (num_cs_gpios == -ENOENT)) {
+		dev_warn(&pdev->dev,
+			 "cs-gpios not found. Using native chipselect with this SPI controller is known to be problematic\n");
+		master->num_chipselect = 4;
+	}
 
 	spi_imx->bitbang.setup_transfer = spi_imx_setupxfer;
 	spi_imx->bitbang.txrx_bufs = spi_imx_transfer;
-- 
2.17.1




[Index of Archives]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux