spi: fsl-lpspi: fix only one cs-gpio working
authorPhilippe Schenker <philippe.schenker@toradex.com>
Wed, 4 Dec 2019 14:13:33 +0000 (14:13 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Feb 2020 07:36:28 +0000 (08:36 +0100)
[ Upstream commit bc3a8b295e5bca9d1ec2622a6ba38289f9fd3d8a ]

Why it does not work at the moment:
- num_chipselect sets the number of cs-gpios that are in the DT.
  This comes from drivers/spi/spi.c
- num_chipselect gets set with devm_spi_register_controller, that is
  called in drivers/spi/spi.c
- devm_spi_register_controller got called after num_chipselect has
  been used.

How this commit fixes the issue:
- devm_spi_register_controller gets called before num_chipselect is
  being used.

Fixes: c7a402599504 ("spi: lpspi: use the core way to implement cs-gpio function")
Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
Link: https://lore.kernel.org/r/20191204141312.1411251-1-philippe.schenker@toradex.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/spi/spi-fsl-lpspi.c

index 3528ed5..92e460d 100644 (file)
@@ -862,6 +862,22 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
        fsl_lpspi->dev = &pdev->dev;
        fsl_lpspi->is_slave = is_slave;
 
+       controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32);
+       controller->transfer_one = fsl_lpspi_transfer_one;
+       controller->prepare_transfer_hardware = lpspi_prepare_xfer_hardware;
+       controller->unprepare_transfer_hardware = lpspi_unprepare_xfer_hardware;
+       controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
+       controller->flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX;
+       controller->dev.of_node = pdev->dev.of_node;
+       controller->bus_num = pdev->id;
+       controller->slave_abort = fsl_lpspi_slave_abort;
+
+       ret = devm_spi_register_controller(&pdev->dev, controller);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "spi_register_controller error.\n");
+               goto out_controller_put;
+       }
+
        if (!fsl_lpspi->is_slave) {
                for (i = 0; i < controller->num_chipselect; i++) {
                        int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
@@ -885,16 +901,6 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
                controller->prepare_message = fsl_lpspi_prepare_message;
        }
 
-       controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32);
-       controller->transfer_one = fsl_lpspi_transfer_one;
-       controller->prepare_transfer_hardware = lpspi_prepare_xfer_hardware;
-       controller->unprepare_transfer_hardware = lpspi_unprepare_xfer_hardware;
-       controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
-       controller->flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX;
-       controller->dev.of_node = pdev->dev.of_node;
-       controller->bus_num = pdev->id;
-       controller->slave_abort = fsl_lpspi_slave_abort;
-
        init_completion(&fsl_lpspi->xfer_done);
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -952,12 +958,6 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
        if (ret < 0)
                dev_err(&pdev->dev, "dma setup error %d, use pio\n", ret);
 
-       ret = devm_spi_register_controller(&pdev->dev, controller);
-       if (ret < 0) {
-               dev_err(&pdev->dev, "spi_register_controller error.\n");
-               goto out_controller_put;
-       }
-
        return 0;
 
 out_controller_put: