Skip to content

Commit 1dfbf33

Browse files
linuswbroonie
authored andcommitted
spi: ep93xx: Convert to use CS GPIO descriptors
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 <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 2a168e1 commit 1dfbf33

File tree

6 files changed

+48
-52
lines changed

6 files changed

+48
-52
lines changed

arch/arm/mach-ep93xx/edb93xx.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/platform_device.h>
3030
#include <linux/i2c.h>
3131
#include <linux/spi/spi.h>
32+
#include <linux/gpio/machine.h>
3233

3334
#include <sound/cs4271.h>
3435

@@ -105,13 +106,16 @@ static struct spi_board_info edb93xx_spi_board_info[] __initdata = {
105106
},
106107
};
107108

108-
static int edb93xx_spi_chipselects[] __initdata = {
109-
EP93XX_GPIO_LINE_EGPIO6,
109+
static struct gpiod_lookup_table edb93xx_spi_cs_gpio_table = {
110+
.dev_id = "ep93xx-spi.0",
111+
.table = {
112+
GPIO_LOOKUP("A", 6, "cs", GPIO_ACTIVE_LOW),
113+
{ },
114+
},
110115
};
111116

112117
static struct ep93xx_spi_info edb93xx_spi_info __initdata = {
113-
.chipselect = edb93xx_spi_chipselects,
114-
.num_chipselect = ARRAY_SIZE(edb93xx_spi_chipselects),
118+
/* Intentionally left blank */
115119
};
116120

117121
static void __init edb93xx_register_spi(void)
@@ -123,6 +127,7 @@ static void __init edb93xx_register_spi(void)
123127
else if (machine_is_edb9315a())
124128
edb93xx_cs4271_data.gpio_nreset = EP93XX_GPIO_LINE_EGPIO14;
125129

130+
gpiod_add_lookup_table(&edb93xx_spi_cs_gpio_table);
126131
ep93xx_register_spi(&edb93xx_spi_info, edb93xx_spi_board_info,
127132
ARRAY_SIZE(edb93xx_spi_board_info));
128133
}

arch/arm/mach-ep93xx/simone.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@ static struct spi_board_info simone_spi_devices[] __initdata = {
7777
* low between multi-message command blocks. From v1.4, it uses a GPIO instead.
7878
* v1.3 parts will still work, since the signal on SFRMOUT is automatic.
7979
*/
80-
static int simone_spi_chipselects[] __initdata = {
81-
EP93XX_GPIO_LINE_EGPIO1,
80+
static struct gpiod_lookup_table simone_spi_cs_gpio_table = {
81+
.dev_id = "ep93xx-spi.0",
82+
.table = {
83+
GPIO_LOOKUP("A", 1, "cs", GPIO_ACTIVE_LOW),
84+
{ },
85+
},
8286
};
8387

8488
static struct ep93xx_spi_info simone_spi_info __initdata = {
85-
.chipselect = simone_spi_chipselects,
86-
.num_chipselect = ARRAY_SIZE(simone_spi_chipselects),
8789
.use_dma = 1,
8890
};
8991

@@ -113,6 +115,7 @@ static void __init simone_init_machine(void)
113115
ep93xx_register_i2c(simone_i2c_board_info,
114116
ARRAY_SIZE(simone_i2c_board_info));
115117
gpiod_add_lookup_table(&simone_mmc_spi_gpio_table);
118+
gpiod_add_lookup_table(&simone_spi_cs_gpio_table);
116119
ep93xx_register_spi(&simone_spi_info, simone_spi_devices,
117120
ARRAY_SIZE(simone_spi_devices));
118121
simone_register_audio();

arch/arm/mach-ep93xx/ts72xx.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/spi/mmc_spi.h>
2323
#include <linux/mmc/host.h>
2424
#include <linux/platform_data/spi-ep93xx.h>
25+
#include <linux/gpio/machine.h>
2526

2627
#include <mach/gpio-ep93xx.h>
2728
#include <mach/hardware.h>
@@ -269,13 +270,15 @@ static struct spi_board_info bk3_spi_board_info[] __initdata = {
269270
* The all work is performed automatically by !SPI_FRAME (SFRM1) and
270271
* goes through CPLD
271272
*/
272-
static int bk3_spi_chipselects[] __initdata = {
273-
EP93XX_GPIO_LINE_F(3),
273+
static struct gpiod_lookup_table bk3_spi_cs_gpio_table = {
274+
.dev_id = "ep93xx-spi.0",
275+
.table = {
276+
GPIO_LOOKUP("F", 3, "cs", GPIO_ACTIVE_LOW),
277+
{ },
278+
},
274279
};
275280

276281
static struct ep93xx_spi_info bk3_spi_master __initdata = {
277-
.chipselect = bk3_spi_chipselects,
278-
.num_chipselect = ARRAY_SIZE(bk3_spi_chipselects),
279282
.use_dma = 1,
280283
};
281284

@@ -316,13 +319,17 @@ static struct spi_board_info ts72xx_spi_devices[] __initdata = {
316319
},
317320
};
318321

319-
static int ts72xx_spi_chipselects[] __initdata = {
320-
EP93XX_GPIO_LINE_F(2), /* DIO_17 */
322+
static struct gpiod_lookup_table ts72xx_spi_cs_gpio_table = {
323+
.dev_id = "ep93xx-spi.0",
324+
.table = {
325+
/* DIO_17 */
326+
GPIO_LOOKUP("F", 2, "cs", GPIO_ACTIVE_LOW),
327+
{ },
328+
},
321329
};
322330

323331
static struct ep93xx_spi_info ts72xx_spi_info __initdata = {
324-
.chipselect = ts72xx_spi_chipselects,
325-
.num_chipselect = ARRAY_SIZE(ts72xx_spi_chipselects),
332+
/* Intentionally left blank */
326333
};
327334

328335
static void __init ts72xx_init_machine(void)
@@ -339,6 +346,7 @@ static void __init ts72xx_init_machine(void)
339346
if (board_is_ts7300())
340347
platform_device_register(&ts73xx_fpga_device);
341348
#endif
349+
gpiod_add_lookup_table(&ts72xx_spi_cs_gpio_table);
342350
ep93xx_register_spi(&ts72xx_spi_info, ts72xx_spi_devices,
343351
ARRAY_SIZE(ts72xx_spi_devices));
344352
}
@@ -398,6 +406,7 @@ static void __init bk3_init_machine(void)
398406

399407
ep93xx_register_eth(&ts72xx_eth_data, 1);
400408

409+
gpiod_add_lookup_table(&bk3_spi_cs_gpio_table);
401410
ep93xx_register_spi(&bk3_spi_master, bk3_spi_board_info,
402411
ARRAY_SIZE(bk3_spi_board_info));
403412

arch/arm/mach-ep93xx/vision_ep9307.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,17 @@ static struct spi_board_info vision_spi_board_info[] __initdata = {
245245
},
246246
};
247247

248-
static int vision_spi_chipselects[] __initdata = {
249-
EP93XX_GPIO_LINE_EGPIO6,
250-
EP93XX_GPIO_LINE_EGPIO7,
251-
EP93XX_GPIO_LINE_G(2),
248+
static struct gpiod_lookup_table vision_spi_cs_gpio_table = {
249+
.dev_id = "ep93xx-spi.0",
250+
.table = {
251+
GPIO_LOOKUP_IDX("A", 6, "cs", 0, GPIO_ACTIVE_LOW),
252+
GPIO_LOOKUP_IDX("A", 7, "cs", 1, GPIO_ACTIVE_LOW),
253+
GPIO_LOOKUP_IDX("G", 2, "cs", 2, GPIO_ACTIVE_LOW),
254+
{ },
255+
},
252256
};
253257

254258
static struct ep93xx_spi_info vision_spi_master __initdata = {
255-
.chipselect = vision_spi_chipselects,
256-
.num_chipselect = ARRAY_SIZE(vision_spi_chipselects),
257259
.use_dma = 1,
258260
};
259261

@@ -295,6 +297,7 @@ static void __init vision_init_machine(void)
295297
ep93xx_register_i2c(vision_i2c_info,
296298
ARRAY_SIZE(vision_i2c_info));
297299
gpiod_add_lookup_table(&vision_spi_mmc_gpio_table);
300+
gpiod_add_lookup_table(&vision_spi_cs_gpio_table);
298301
ep93xx_register_spi(&vision_spi_master, vision_spi_board_info,
299302
ARRAY_SIZE(vision_spi_board_info));
300303
vision_register_i2s();

drivers/spi/spi-ep93xx.c

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <linux/platform_device.h>
2929
#include <linux/sched.h>
3030
#include <linux/scatterlist.h>
31-
#include <linux/gpio.h>
3231
#include <linux/spi/spi.h>
3332

3433
#include <linux/platform_data/dma-ep93xx.h>
@@ -676,38 +675,19 @@ static int ep93xx_spi_probe(struct platform_device *pdev)
676675
if (!master)
677676
return -ENOMEM;
678677

678+
master->use_gpio_descriptors = true;
679679
master->prepare_transfer_hardware = ep93xx_spi_prepare_hardware;
680680
master->unprepare_transfer_hardware = ep93xx_spi_unprepare_hardware;
681681
master->prepare_message = ep93xx_spi_prepare_message;
682682
master->transfer_one = ep93xx_spi_transfer_one;
683683
master->bus_num = pdev->id;
684684
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
685685
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
686-
687-
master->num_chipselect = info->num_chipselect;
688-
master->cs_gpios = devm_kcalloc(&master->dev,
689-
master->num_chipselect, sizeof(int),
690-
GFP_KERNEL);
691-
if (!master->cs_gpios) {
692-
error = -ENOMEM;
693-
goto fail_release_master;
694-
}
695-
696-
for (i = 0; i < master->num_chipselect; i++) {
697-
master->cs_gpios[i] = info->chipselect[i];
698-
699-
if (!gpio_is_valid(master->cs_gpios[i]))
700-
continue;
701-
702-
error = devm_gpio_request_one(&pdev->dev, master->cs_gpios[i],
703-
GPIOF_OUT_INIT_HIGH,
704-
"ep93xx-spi");
705-
if (error) {
706-
dev_err(&pdev->dev, "could not request cs gpio %d\n",
707-
master->cs_gpios[i]);
708-
goto fail_release_master;
709-
}
710-
}
686+
/*
687+
* The SPI core will count the number of GPIO descriptors to figure
688+
* out the number of chip selects available on the platform.
689+
*/
690+
master->num_chipselect = 0;
711691

712692
platform_set_drvdata(pdev, master);
713693

include/linux/platform_data/spi-ep93xx.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@ struct spi_device;
66

77
/**
88
* struct ep93xx_spi_info - EP93xx specific SPI descriptor
9-
* @chipselect: array of gpio numbers to use as chip selects
10-
* @num_chipselect: ARRAY_SIZE(chipselect)
119
* @use_dma: use DMA for the transfers
1210
*/
1311
struct ep93xx_spi_info {
14-
int *chipselect;
15-
int num_chipselect;
1612
bool use_dma;
1713
};
1814

0 commit comments

Comments
 (0)