hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/spi/spi-efm32.c
....@@ -1,22 +1,18 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2012-2013 Uwe Kleine-Koenig for Pengutronix
3
- *
4
- * This program is free software; you can redistribute it and/or modify it under
5
- * the terms of the GNU General Public License version 2 as published by the
6
- * Free Software Foundation.
74 */
85 #include <linux/kernel.h>
96 #include <linux/io.h>
107 #include <linux/spi/spi.h>
118 #include <linux/spi/spi_bitbang.h>
12
-#include <linux/gpio.h>
139 #include <linux/interrupt.h>
1410 #include <linux/platform_device.h>
1511 #include <linux/clk.h>
1612 #include <linux/err.h>
1713 #include <linux/module.h>
18
-#include <linux/of_gpio.h>
1914 #include <linux/platform_data/efm32-spi.h>
15
+#include <linux/of.h>
2016
2117 #define DRIVER_NAME "efm32-spi"
2218
....@@ -85,9 +81,6 @@
8581 const u8 *tx_buf;
8682 u8 *rx_buf;
8783 unsigned tx_len, rx_len;
88
-
89
- /* chip selects */
90
- unsigned csgpio[];
9184 };
9285
9386 #define ddata_to_dev(ddata) (&(ddata->bitbang.master->dev))
....@@ -103,14 +96,6 @@
10396 static u32 efm32_spi_read32(struct efm32_spi_ddata *ddata, unsigned offset)
10497 {
10598 return readl_relaxed(ddata->base + offset);
106
-}
107
-
108
-static void efm32_spi_chipselect(struct spi_device *spi, int is_on)
109
-{
110
- struct efm32_spi_ddata *ddata = spi_master_get_devdata(spi->master);
111
- int value = !(spi->mode & SPI_CS_HIGH) == !(is_on == BITBANG_CS_ACTIVE);
112
-
113
- gpio_set_value(ddata->csgpio[spi->chip_select], value);
11499 }
115100
116101 static int efm32_spi_setup_transfer(struct spi_device *spi,
....@@ -323,17 +308,11 @@
323308 int ret;
324309 struct spi_master *master;
325310 struct device_node *np = pdev->dev.of_node;
326
- int num_cs, i;
327311
328312 if (!np)
329313 return -EINVAL;
330314
331
- num_cs = of_gpio_named_count(np, "cs-gpios");
332
- if (num_cs < 0)
333
- return num_cs;
334
-
335
- master = spi_alloc_master(&pdev->dev,
336
- sizeof(*ddata) + num_cs * sizeof(unsigned));
315
+ master = spi_alloc_master(&pdev->dev, sizeof(*ddata));
337316 if (!master) {
338317 dev_dbg(&pdev->dev,
339318 "failed to allocate spi master controller\n");
....@@ -343,14 +322,13 @@
343322
344323 master->dev.of_node = pdev->dev.of_node;
345324
346
- master->num_chipselect = num_cs;
347325 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
348326 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
327
+ master->use_gpio_descriptors = true;
349328
350329 ddata = spi_master_get_devdata(master);
351330
352331 ddata->bitbang.master = master;
353
- ddata->bitbang.chipselect = efm32_spi_chipselect;
354332 ddata->bitbang.setup_transfer = efm32_spi_setup_transfer;
355333 ddata->bitbang.txrx_bufs = efm32_spi_txrx_bufs;
356334
....@@ -362,25 +340,6 @@
362340 ret = PTR_ERR(ddata->clk);
363341 dev_err(&pdev->dev, "failed to get clock: %d\n", ret);
364342 goto err;
365
- }
366
-
367
- for (i = 0; i < num_cs; ++i) {
368
- ret = of_get_named_gpio(np, "cs-gpios", i);
369
- if (ret < 0) {
370
- dev_err(&pdev->dev, "failed to get csgpio#%u (%d)\n",
371
- i, ret);
372
- goto err;
373
- }
374
- ddata->csgpio[i] = ret;
375
- dev_dbg(&pdev->dev, "csgpio#%u = %u\n", i, ddata->csgpio[i]);
376
- ret = devm_gpio_request_one(&pdev->dev, ddata->csgpio[i],
377
- GPIOF_OUT_INIT_LOW, DRIVER_NAME);
378
- if (ret < 0) {
379
- dev_err(&pdev->dev,
380
- "failed to configure csgpio#%u (%d)\n",
381
- i, ret);
382
- goto err;
383
- }
384343 }
385344
386345 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
....@@ -403,10 +362,8 @@
403362 }
404363
405364 ret = platform_get_irq(pdev, 0);
406
- if (ret <= 0) {
407
- dev_err(&pdev->dev, "failed to get rx irq (%d)\n", ret);
365
+ if (ret <= 0)
408366 goto err;
409
- }
410367
411368 ddata->rxirq = ret;
412369