Skip to content

Commit 9bbbf33

Browse files
committed
spi: gpio: Enable a single always-selected device
Merge series from Andy Shevchenko <[email protected]>: Enable a single always-selected device hardware setup for SPI GPIO driver, so some custom SPI bitbang code may be replaced with the generic implementation in the future (e.g. Up Board FPGA driver).
2 parents 215705d + 25fac20 commit 9bbbf33

File tree

1 file changed

+7
-38
lines changed

1 file changed

+7
-38
lines changed

drivers/spi/spi-gpio.c

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,8 @@ struct spi_gpio {
3939

4040
/*----------------------------------------------------------------------*/
4141

42-
/*
43-
* Because the overhead of going through four GPIO procedure calls
44-
* per transferred bit can make performance a problem, this code
45-
* is set up so that you can use it in either of two ways:
46-
*
47-
* - The slow generic way: set up platform_data to hold the GPIO
48-
* numbers used for MISO/MOSI/SCK, and issue procedure calls for
49-
* each of them. This driver can handle several such busses.
50-
*
51-
* - The quicker inlined way: only helps with platform GPIO code
52-
* that inlines operations for constant GPIOs. This can give
53-
* you tight (fast!) inner loops, but each such bus needs a
54-
* new driver. You'll define a new C file, with Makefile and
55-
* Kconfig support; the C code can be a total of six lines:
56-
*
57-
* #define DRIVER_NAME "myboard_spi2"
58-
* #define SPI_MISO_GPIO 119
59-
* #define SPI_MOSI_GPIO 120
60-
* #define SPI_SCK_GPIO 121
61-
* #define SPI_N_CHIPSEL 4
62-
* #include "spi-gpio.c"
63-
*/
64-
65-
#ifndef DRIVER_NAME
6642
#define DRIVER_NAME "spi_gpio"
6743

68-
#define GENERIC_BITBANG /* vs tight inlines */
69-
70-
#endif
71-
7244
/*----------------------------------------------------------------------*/
7345

7446
static inline struct spi_gpio *__pure
@@ -341,16 +313,14 @@ static int spi_gpio_probe_pdata(struct platform_device *pdev,
341313
struct spi_gpio *spi_gpio = spi_controller_get_devdata(host);
342314
int i;
343315

344-
#ifdef GENERIC_BITBANG
345-
if (!pdata || !pdata->num_chipselect)
316+
if (!pdata)
346317
return -ENODEV;
347-
#endif
348-
/*
349-
* The host needs to think there is a chipselect even if not
350-
* connected
351-
*/
352-
host->num_chipselect = pdata->num_chipselect ?: 1;
353318

319+
/* It's just one always-selected device, fine to continue */
320+
if (!pdata->num_chipselect)
321+
return 0;
322+
323+
host->num_chipselect = pdata->num_chipselect;
354324
spi_gpio->cs_gpios = devm_kcalloc(dev, host->num_chipselect,
355325
sizeof(*spi_gpio->cs_gpios),
356326
GFP_KERNEL);
@@ -445,8 +415,6 @@ static int spi_gpio_probe(struct platform_device *pdev)
445415
return devm_spi_register_controller(&pdev->dev, host);
446416
}
447417

448-
MODULE_ALIAS("platform:" DRIVER_NAME);
449-
450418
static const struct of_device_id spi_gpio_dt_ids[] = {
451419
{ .compatible = "spi-gpio" },
452420
{}
@@ -465,3 +433,4 @@ module_platform_driver(spi_gpio_driver);
465433
MODULE_DESCRIPTION("SPI host driver using generic bitbanged GPIO ");
466434
MODULE_AUTHOR("David Brownell");
467435
MODULE_LICENSE("GPL");
436+
MODULE_ALIAS("platform:" DRIVER_NAME);

0 commit comments

Comments
 (0)