20 #include <linux/kernel.h>
21 #include <linux/module.h>
80 #define DRIVER_NAME "spi_gpio"
82 #define GENERIC_BITBANG
85 #define SPI_MISO_GPIO ((pdata)->miso)
86 #define SPI_MOSI_GPIO ((pdata)->mosi)
87 #define SPI_SCK_GPIO ((pdata)->sck)
89 #define SPI_N_CHIPSEL ((pdata)->num_chipselect)
101 bang = spi_master_get_devdata(spi->
master);
109 return &spi_to_spi_gpio(spi)->pdata;
113 #define pdata spi_to_pdata(spi)
115 static inline void setsck(
const struct spi_device *
spi,
int is_on)
120 static inline void setmosi(
const struct spi_device *
spi,
int is_on)
138 #define spidelay(nsecs) do {} while (0)
159 return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
165 return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
171 return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
177 return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
194 return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits);
201 return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits);
208 return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits);
215 return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits);
235 static int spi_gpio_setup(
struct spi_device *spi)
239 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
280 static void spi_gpio_cleanup(
struct spi_device *spi)
282 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
369 pdata->
sck = of_get_named_gpio(np,
"gpio-sck", 0);
370 pdata->
miso = of_get_named_gpio(np,
"gpio-miso", 0);
371 pdata->
mosi = of_get_named_gpio(np,
"gpio-mosi", 0);
373 ret = of_property_read_u32(np,
"num-chipselects", &tmp);
375 dev_err(&pdev->
dev,
"num-chipselects property not found\n");
399 struct spi_gpio *spi_gpio;
401 u16 master_flags = 0;
404 status = spi_gpio_probe_dt(pdev);
410 pdata = pdev->
dev.platform_data;
411 #ifdef GENERIC_BITBANG
416 status = spi_gpio_request(pdata, dev_name(&pdev->
dev), &master_flags);
426 spi_gpio = spi_master_get_devdata(master);
427 platform_set_drvdata(pdev, spi_gpio);
429 spi_gpio->
pdev = pdev;
433 master->
flags = master_flags;
436 master->
setup = spi_gpio_setup;
437 master->
cleanup = spi_gpio_cleanup;
439 master->
dev.of_node = pdev->
dev.of_node;
452 of_get_named_gpio(np,
"cs-gpios", i);
456 spi_gpio->
bitbang.master = spi_master_get(master);
457 spi_gpio->
bitbang.chipselect = spi_gpio_chipselect;
475 spi_master_put(spi_gpio->
bitbang.master);
482 spi_master_put(master);
490 struct spi_gpio *spi_gpio;
494 spi_gpio = platform_get_drvdata(pdev);
495 pdata = pdev->
dev.platform_data;
499 spi_master_put(spi_gpio->
bitbang.master);
501 platform_set_drvdata(pdev,
NULL);
520 .probe = spi_gpio_probe,