Skip to content

Commit ebb3b9a

Browse files
Linus Walleijbroonie
authored andcommitted
spi: efm32: Convert to use GPIO descriptors
This switches the EFM32 driver over to use the GPIO descriptor handling in the core. The GPIO handling in this driver is pretty simplistic so this should just work. Drop the GPIO headers and insert the implicitly included <linux/of.h> header. Signed-off-by: Linus Walleij <[email protected]> Cc: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 6960b03 commit ebb3b9a

File tree

1 file changed

+3
-41
lines changed

1 file changed

+3
-41
lines changed

drivers/spi/spi-efm32.c

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
#include <linux/io.h>
77
#include <linux/spi/spi.h>
88
#include <linux/spi/spi_bitbang.h>
9-
#include <linux/gpio.h>
109
#include <linux/interrupt.h>
1110
#include <linux/platform_device.h>
1211
#include <linux/clk.h>
1312
#include <linux/err.h>
1413
#include <linux/module.h>
15-
#include <linux/of_gpio.h>
1614
#include <linux/platform_data/efm32-spi.h>
15+
#include <linux/of.h>
1716

1817
#define DRIVER_NAME "efm32-spi"
1918

@@ -82,9 +81,6 @@ struct efm32_spi_ddata {
8281
const u8 *tx_buf;
8382
u8 *rx_buf;
8483
unsigned tx_len, rx_len;
85-
86-
/* chip selects */
87-
unsigned csgpio[];
8884
};
8985

9086
#define ddata_to_dev(ddata) (&(ddata->bitbang.master->dev))
@@ -102,14 +98,6 @@ static u32 efm32_spi_read32(struct efm32_spi_ddata *ddata, unsigned offset)
10298
return readl_relaxed(ddata->base + offset);
10399
}
104100

105-
static void efm32_spi_chipselect(struct spi_device *spi, int is_on)
106-
{
107-
struct efm32_spi_ddata *ddata = spi_master_get_devdata(spi->master);
108-
int value = !(spi->mode & SPI_CS_HIGH) == !(is_on == BITBANG_CS_ACTIVE);
109-
110-
gpio_set_value(ddata->csgpio[spi->chip_select], value);
111-
}
112-
113101
static int efm32_spi_setup_transfer(struct spi_device *spi,
114102
struct spi_transfer *t)
115103
{
@@ -320,17 +308,11 @@ static int efm32_spi_probe(struct platform_device *pdev)
320308
int ret;
321309
struct spi_master *master;
322310
struct device_node *np = pdev->dev.of_node;
323-
int num_cs, i;
324311

325312
if (!np)
326313
return -EINVAL;
327314

328-
num_cs = of_gpio_named_count(np, "cs-gpios");
329-
if (num_cs < 0)
330-
return num_cs;
331-
332-
master = spi_alloc_master(&pdev->dev,
333-
sizeof(*ddata) + num_cs * sizeof(unsigned));
315+
master = spi_alloc_master(&pdev->dev, sizeof(*ddata));
334316
if (!master) {
335317
dev_dbg(&pdev->dev,
336318
"failed to allocate spi master controller\n");
@@ -340,14 +322,13 @@ static int efm32_spi_probe(struct platform_device *pdev)
340322

341323
master->dev.of_node = pdev->dev.of_node;
342324

343-
master->num_chipselect = num_cs;
344325
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
345326
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
327+
master->use_gpio_descriptors = true;
346328

347329
ddata = spi_master_get_devdata(master);
348330

349331
ddata->bitbang.master = master;
350-
ddata->bitbang.chipselect = efm32_spi_chipselect;
351332
ddata->bitbang.setup_transfer = efm32_spi_setup_transfer;
352333
ddata->bitbang.txrx_bufs = efm32_spi_txrx_bufs;
353334

@@ -361,25 +342,6 @@ static int efm32_spi_probe(struct platform_device *pdev)
361342
goto err;
362343
}
363344

364-
for (i = 0; i < num_cs; ++i) {
365-
ret = of_get_named_gpio(np, "cs-gpios", i);
366-
if (ret < 0) {
367-
dev_err(&pdev->dev, "failed to get csgpio#%u (%d)\n",
368-
i, ret);
369-
goto err;
370-
}
371-
ddata->csgpio[i] = ret;
372-
dev_dbg(&pdev->dev, "csgpio#%u = %u\n", i, ddata->csgpio[i]);
373-
ret = devm_gpio_request_one(&pdev->dev, ddata->csgpio[i],
374-
GPIOF_OUT_INIT_LOW, DRIVER_NAME);
375-
if (ret < 0) {
376-
dev_err(&pdev->dev,
377-
"failed to configure csgpio#%u (%d)\n",
378-
i, ret);
379-
goto err;
380-
}
381-
}
382-
383345
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
384346
if (!res) {
385347
ret = -ENODEV;

0 commit comments

Comments
 (0)