spi: ep93xx: Convert to use CS GPIO descriptors
authorLinus Walleij <linus.walleij@linaro.org>
Sat, 20 Apr 2019 11:05:59 +0000 (13:05 +0200)
committerMark Brown <broonie@kernel.org>
Thu, 2 May 2019 01:37:59 +0000 (10:37 +0900)
This converts the EP93xx SPI master driver to use GPIO
descriptors for chip select handling.

EP93xx was using platform data to pass in GPIO lines,
by converting all board files to use GPIO descriptor
tables the core will look up the GPIO lines from the
SPI device in the same manner as for device tree.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
arch/arm/mach-ep93xx/edb93xx.c
arch/arm/mach-ep93xx/simone.c
arch/arm/mach-ep93xx/ts72xx.c
arch/arm/mach-ep93xx/vision_ep9307.c
drivers/spi/spi-ep93xx.c
include/linux/platform_data/spi-ep93xx.h

index 8e89ec8b6f0ff535eab78436c44f75fa92ff581e..34e18e9556d9b928b3505594dd5583835743a0d8 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/platform_device.h>
 #include <linux/i2c.h>
 #include <linux/spi/spi.h>
+#include <linux/gpio/machine.h>
 
 #include <sound/cs4271.h>
 
@@ -105,13 +106,16 @@ static struct spi_board_info edb93xx_spi_board_info[] __initdata = {
        },
 };
 
-static int edb93xx_spi_chipselects[] __initdata = {
-       EP93XX_GPIO_LINE_EGPIO6,
+static struct gpiod_lookup_table edb93xx_spi_cs_gpio_table = {
+       .dev_id = "ep93xx-spi.0",
+       .table = {
+               GPIO_LOOKUP("A", 6, "cs", GPIO_ACTIVE_LOW),
+               { },
+       },
 };
 
 static struct ep93xx_spi_info edb93xx_spi_info __initdata = {
-       .chipselect     = edb93xx_spi_chipselects,
-       .num_chipselect = ARRAY_SIZE(edb93xx_spi_chipselects),
+       /* Intentionally left blank */
 };
 
 static void __init edb93xx_register_spi(void)
@@ -123,6 +127,7 @@ static void __init edb93xx_register_spi(void)
        else if (machine_is_edb9315a())
                edb93xx_cs4271_data.gpio_nreset = EP93XX_GPIO_LINE_EGPIO14;
 
+       gpiod_add_lookup_table(&edb93xx_spi_cs_gpio_table);
        ep93xx_register_spi(&edb93xx_spi_info, edb93xx_spi_board_info,
                            ARRAY_SIZE(edb93xx_spi_board_info));
 }
index 80ccb984d521eccc7cff0e491cba65b67afbd522..f0f38c0dba527572428c05474955c734ba360945 100644 (file)
@@ -77,13 +77,15 @@ static struct spi_board_info simone_spi_devices[] __initdata = {
  * low between multi-message command blocks. From v1.4, it uses a GPIO instead.
  * v1.3 parts will still work, since the signal on SFRMOUT is automatic.
  */
-static int simone_spi_chipselects[] __initdata = {
-       EP93XX_GPIO_LINE_EGPIO1,
+static struct gpiod_lookup_table simone_spi_cs_gpio_table = {
+       .dev_id = "ep93xx-spi.0",
+       .table = {
+               GPIO_LOOKUP("A", 1, "cs", GPIO_ACTIVE_LOW),
+               { },
+       },
 };
 
 static struct ep93xx_spi_info simone_spi_info __initdata = {
-       .chipselect     = simone_spi_chipselects,
-       .num_chipselect = ARRAY_SIZE(simone_spi_chipselects),
        .use_dma = 1,
 };
 
@@ -113,6 +115,7 @@ static void __init simone_init_machine(void)
        ep93xx_register_i2c(simone_i2c_board_info,
                            ARRAY_SIZE(simone_i2c_board_info));
        gpiod_add_lookup_table(&simone_mmc_spi_gpio_table);
+       gpiod_add_lookup_table(&simone_spi_cs_gpio_table);
        ep93xx_register_spi(&simone_spi_info, simone_spi_devices,
                            ARRAY_SIZE(simone_spi_devices));
        simone_register_audio();
index 85b74ac943f010de744264e737b4c8d7f8f3f194..a3a20c83c6b8f930f2ea45955d965dc16842917b 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/spi/mmc_spi.h>
 #include <linux/mmc/host.h>
 #include <linux/platform_data/spi-ep93xx.h>
+#include <linux/gpio/machine.h>
 
 #include <mach/gpio-ep93xx.h>
 #include <mach/hardware.h>
@@ -269,13 +270,15 @@ static struct spi_board_info bk3_spi_board_info[] __initdata = {
  * The all work is performed automatically by !SPI_FRAME (SFRM1) and
  * goes through CPLD
  */
-static int bk3_spi_chipselects[] __initdata = {
-       EP93XX_GPIO_LINE_F(3),
+static struct gpiod_lookup_table bk3_spi_cs_gpio_table = {
+       .dev_id = "ep93xx-spi.0",
+       .table = {
+               GPIO_LOOKUP("F", 3, "cs", GPIO_ACTIVE_LOW),
+               { },
+       },
 };
 
 static struct ep93xx_spi_info bk3_spi_master __initdata = {
-       .chipselect     = bk3_spi_chipselects,
-       .num_chipselect = ARRAY_SIZE(bk3_spi_chipselects),
        .use_dma        = 1,
 };
 
@@ -316,13 +319,17 @@ static struct spi_board_info ts72xx_spi_devices[] __initdata = {
        },
 };
 
-static int ts72xx_spi_chipselects[] __initdata = {
-       EP93XX_GPIO_LINE_F(2),          /* DIO_17 */
+static struct gpiod_lookup_table ts72xx_spi_cs_gpio_table = {
+       .dev_id = "ep93xx-spi.0",
+       .table = {
+               /* DIO_17 */
+               GPIO_LOOKUP("F", 2, "cs", GPIO_ACTIVE_LOW),
+               { },
+       },
 };
 
 static struct ep93xx_spi_info ts72xx_spi_info __initdata = {
-       .chipselect     = ts72xx_spi_chipselects,
-       .num_chipselect = ARRAY_SIZE(ts72xx_spi_chipselects),
+       /* Intentionally left blank */
 };
 
 static void __init ts72xx_init_machine(void)
@@ -339,6 +346,7 @@ static void __init ts72xx_init_machine(void)
        if (board_is_ts7300())
                platform_device_register(&ts73xx_fpga_device);
 #endif
+       gpiod_add_lookup_table(&ts72xx_spi_cs_gpio_table);
        ep93xx_register_spi(&ts72xx_spi_info, ts72xx_spi_devices,
                            ARRAY_SIZE(ts72xx_spi_devices));
 }
@@ -398,6 +406,7 @@ static void __init bk3_init_machine(void)
 
        ep93xx_register_eth(&ts72xx_eth_data, 1);
 
+       gpiod_add_lookup_table(&bk3_spi_cs_gpio_table);
        ep93xx_register_spi(&bk3_spi_master, bk3_spi_board_info,
                            ARRAY_SIZE(bk3_spi_board_info));
 
index 767ee64628dc352e3b6df6175a2a41918ad9ac04..f95a644769e485b939f190790c803c416880ee06 100644 (file)
@@ -245,15 +245,17 @@ static struct spi_board_info vision_spi_board_info[] __initdata = {
        },
 };
 
-static int vision_spi_chipselects[] __initdata = {
-       EP93XX_GPIO_LINE_EGPIO6,
-       EP93XX_GPIO_LINE_EGPIO7,
-       EP93XX_GPIO_LINE_G(2),
+static struct gpiod_lookup_table vision_spi_cs_gpio_table = {
+       .dev_id = "ep93xx-spi.0",
+       .table = {
+               GPIO_LOOKUP_IDX("A", 6, "cs", 0, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX("A", 7, "cs", 1, GPIO_ACTIVE_LOW),
+               GPIO_LOOKUP_IDX("G", 2, "cs", 2, GPIO_ACTIVE_LOW),
+               { },
+       },
 };
 
 static struct ep93xx_spi_info vision_spi_master __initdata = {
-       .chipselect     = vision_spi_chipselects,
-       .num_chipselect = ARRAY_SIZE(vision_spi_chipselects),
        .use_dma        = 1,
 };
 
@@ -295,6 +297,7 @@ static void __init vision_init_machine(void)
        ep93xx_register_i2c(vision_i2c_info,
                                ARRAY_SIZE(vision_i2c_info));
        gpiod_add_lookup_table(&vision_spi_mmc_gpio_table);
+       gpiod_add_lookup_table(&vision_spi_cs_gpio_table);
        ep93xx_register_spi(&vision_spi_master, vision_spi_board_info,
                                ARRAY_SIZE(vision_spi_board_info));
        vision_register_i2s();
index 79fc3940245a461129e333b2d1e1ff107115faa0..47e39251bad9dd22e3f21bc79dc428e458e72393 100644 (file)
@@ -28,7 +28,6 @@
 #include <linux/platform_device.h>
 #include <linux/sched.h>
 #include <linux/scatterlist.h>
-#include <linux/gpio.h>
 #include <linux/spi/spi.h>
 
 #include <linux/platform_data/dma-ep93xx.h>
@@ -676,6 +675,7 @@ static int ep93xx_spi_probe(struct platform_device *pdev)
        if (!master)
                return -ENOMEM;
 
+       master->use_gpio_descriptors = true;
        master->prepare_transfer_hardware = ep93xx_spi_prepare_hardware;
        master->unprepare_transfer_hardware = ep93xx_spi_unprepare_hardware;
        master->prepare_message = ep93xx_spi_prepare_message;
@@ -683,31 +683,11 @@ static int ep93xx_spi_probe(struct platform_device *pdev)
        master->bus_num = pdev->id;
        master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
        master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
-
-       master->num_chipselect = info->num_chipselect;
-       master->cs_gpios = devm_kcalloc(&master->dev,
-                                       master->num_chipselect, sizeof(int),
-                                       GFP_KERNEL);
-       if (!master->cs_gpios) {
-               error = -ENOMEM;
-               goto fail_release_master;
-       }
-
-       for (i = 0; i < master->num_chipselect; i++) {
-               master->cs_gpios[i] = info->chipselect[i];
-
-               if (!gpio_is_valid(master->cs_gpios[i]))
-                       continue;
-
-               error = devm_gpio_request_one(&pdev->dev, master->cs_gpios[i],
-                                             GPIOF_OUT_INIT_HIGH,
-                                             "ep93xx-spi");
-               if (error) {
-                       dev_err(&pdev->dev, "could not request cs gpio %d\n",
-                               master->cs_gpios[i]);
-                       goto fail_release_master;
-               }
-       }
+       /*
+        * The SPI core will count the number of GPIO descriptors to figure
+        * out the number of chip selects available on the platform.
+        */
+       master->num_chipselect = 0;
 
        platform_set_drvdata(pdev, master);
 
index eb16c6739ac2aadd91dd22193bc786b1a9cd2bdd..b439f2a896e08eaa201f8bc2966417e1fc1271d1 100644 (file)
@@ -6,13 +6,9 @@ struct spi_device;
 
 /**
  * struct ep93xx_spi_info - EP93xx specific SPI descriptor
- * @chipselect: array of gpio numbers to use as chip selects
- * @num_chipselect: ARRAY_SIZE(chipselect)
  * @use_dma: use DMA for the transfers
  */
 struct ep93xx_spi_info {
-       int     *chipselect;
-       int     num_chipselect;
        bool    use_dma;
 };