Lines Matching +full:sck +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0-or-later
26 * platform_device->driver_data ... points to spi_gpio
28 * spi->controller_state ... reserved for bitbang framework code
30 * spi->master->dev.driver_data ... points to spi_gpio->bitbang
35 struct gpio_desc *sck; member
41 /*----------------------------------------------------------------------*/
48 * - The slow generic way: set up platform_data to hold the GPIO
49 * numbers used for MISO/MOSI/SCK, and issue procedure calls for
52 * - The quicker inlined way: only helps with platform GPIO code
53 * that inlines operations for constant GPIOs. This can give
63 * #include "spi-gpio.c"
73 /*----------------------------------------------------------------------*/
81 bang = spi_master_get_devdata(spi->master); in spi_to_spi_gpio()
91 gpiod_set_value_cansleep(spi_gpio->sck, is_on); in setsck()
98 gpiod_set_value_cansleep(spi_gpio->mosi, is_on); in setmosi()
105 if (spi->mode & SPI_3WIRE) in getmiso()
106 return !!gpiod_get_value_cansleep(spi_gpio->mosi); in getmiso()
108 return !!gpiod_get_value_cansleep(spi_gpio->miso); in getmiso()
115 * we'll just assume we never need additional per-bit slowdowns.
119 #include "spi-bitbang-txrx.h"
125 * even with default 8-bit words.
138 if (unlikely(spi->mode & SPI_LSB_FIRST)) in spi_gpio_txrx_word_mode0()
147 if (unlikely(spi->mode & SPI_LSB_FIRST)) in spi_gpio_txrx_word_mode1()
156 if (unlikely(spi->mode & SPI_LSB_FIRST)) in spi_gpio_txrx_word_mode2()
165 if (unlikely(spi->mode & SPI_LSB_FIRST)) in spi_gpio_txrx_word_mode3()
184 flags = spi->master->flags; in spi_gpio_spec_txrx_word_mode0()
185 if (unlikely(spi->mode & SPI_LSB_FIRST)) in spi_gpio_spec_txrx_word_mode0()
194 flags = spi->master->flags; in spi_gpio_spec_txrx_word_mode1()
195 if (unlikely(spi->mode & SPI_LSB_FIRST)) in spi_gpio_spec_txrx_word_mode1()
204 flags = spi->master->flags; in spi_gpio_spec_txrx_word_mode2()
205 if (unlikely(spi->mode & SPI_LSB_FIRST)) in spi_gpio_spec_txrx_word_mode2()
214 flags = spi->master->flags; in spi_gpio_spec_txrx_word_mode3()
215 if (unlikely(spi->mode & SPI_LSB_FIRST)) in spi_gpio_spec_txrx_word_mode3()
221 /*----------------------------------------------------------------------*/
229 gpiod_set_value_cansleep(spi_gpio->sck, spi->mode & SPI_CPOL); in spi_gpio_chipselect()
232 if (spi_gpio->cs_gpios) { in spi_gpio_chipselect()
233 struct gpio_desc *cs = spi_gpio->cs_gpios[spi->chip_select]; in spi_gpio_chipselect()
235 /* SPI chip selects are normally active-low */ in spi_gpio_chipselect()
236 gpiod_set_value_cansleep(cs, (spi->mode & SPI_CS_HIGH) ? is_active : !is_active); in spi_gpio_chipselect()
247 * The CS GPIOs have already been in spi_gpio_setup()
250 if (spi_gpio->cs_gpios) { in spi_gpio_setup()
251 cs = spi_gpio->cs_gpios[spi->chip_select]; in spi_gpio_setup()
252 if (!spi->controller_state && cs) in spi_gpio_setup()
254 !(spi->mode & SPI_CS_HIGH)); in spi_gpio_setup()
269 return gpiod_direction_output(spi_gpio->mosi, 1); in spi_gpio_set_direction()
271 ret = gpiod_direction_input(spi_gpio->mosi); in spi_gpio_set_direction()
278 * nsec delay function for bit-banged GPIO is simply in spi_gpio_set_direction()
279 * {} because bit-banging just doesn't get fast enough in spi_gpio_set_direction()
282 if (spi->mode & SPI_3WIRE_HIZ) { in spi_gpio_set_direction()
283 gpiod_set_value_cansleep(spi_gpio->sck, in spi_gpio_set_direction()
284 !(spi->mode & SPI_CPOL)); in spi_gpio_set_direction()
285 gpiod_set_value_cansleep(spi_gpio->sck, in spi_gpio_set_direction()
286 !!(spi->mode & SPI_CPOL)); in spi_gpio_set_direction()
304 * drivers expect to see all-ones data as the no slave "response".)
308 spi_gpio->mosi = devm_gpiod_get_optional(dev, "mosi", GPIOD_OUT_LOW); in spi_gpio_request()
309 if (IS_ERR(spi_gpio->mosi)) in spi_gpio_request()
310 return PTR_ERR(spi_gpio->mosi); in spi_gpio_request()
312 spi_gpio->miso = devm_gpiod_get_optional(dev, "miso", GPIOD_IN); in spi_gpio_request()
313 if (IS_ERR(spi_gpio->miso)) in spi_gpio_request()
314 return PTR_ERR(spi_gpio->miso); in spi_gpio_request()
316 spi_gpio->sck = devm_gpiod_get(dev, "sck", GPIOD_OUT_LOW); in spi_gpio_request()
317 return PTR_ERR_OR_ZERO(spi_gpio->sck); in spi_gpio_request()
322 { .compatible = "spi-gpio" },
330 master->dev.of_node = pdev->dev.of_node; in spi_gpio_probe_dt()
331 master->use_gpio_descriptors = true; in spi_gpio_probe_dt()
346 struct device *dev = &pdev->dev; in spi_gpio_probe_pdata()
352 if (!pdata || !pdata->num_chipselect) in spi_gpio_probe_pdata()
353 return -ENODEV; in spi_gpio_probe_pdata()
359 master->num_chipselect = pdata->num_chipselect ?: 1; in spi_gpio_probe_pdata()
361 spi_gpio->cs_gpios = devm_kcalloc(dev, master->num_chipselect, in spi_gpio_probe_pdata()
362 sizeof(*spi_gpio->cs_gpios), in spi_gpio_probe_pdata()
364 if (!spi_gpio->cs_gpios) in spi_gpio_probe_pdata()
365 return -ENOMEM; in spi_gpio_probe_pdata()
367 for (i = 0; i < master->num_chipselect; i++) { in spi_gpio_probe_pdata()
368 spi_gpio->cs_gpios[i] = devm_gpiod_get_index(dev, "cs", i, in spi_gpio_probe_pdata()
370 if (IS_ERR(spi_gpio->cs_gpios[i])) in spi_gpio_probe_pdata()
371 return PTR_ERR(spi_gpio->cs_gpios[i]); in spi_gpio_probe_pdata()
382 struct device *dev = &pdev->dev; in spi_gpio_probe()
387 return -ENOMEM; in spi_gpio_probe()
389 if (pdev->dev.of_node) in spi_gpio_probe()
403 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); in spi_gpio_probe()
404 master->mode_bits = SPI_3WIRE | SPI_3WIRE_HIZ | SPI_CPHA | SPI_CPOL | in spi_gpio_probe()
406 if (!spi_gpio->mosi) { in spi_gpio_probe()
409 * No setting SPI_MASTER_NO_RX here - if there is only in spi_gpio_probe()
413 master->flags = SPI_MASTER_NO_TX; in spi_gpio_probe()
416 master->bus_num = pdev->id; in spi_gpio_probe()
417 master->setup = spi_gpio_setup; in spi_gpio_probe()
418 master->cleanup = spi_gpio_cleanup; in spi_gpio_probe()
420 bb = &spi_gpio->bitbang; in spi_gpio_probe()
421 bb->master = master; in spi_gpio_probe()
427 master->flags |= SPI_MASTER_GPIO_SS; in spi_gpio_probe()
428 bb->chipselect = spi_gpio_chipselect; in spi_gpio_probe()
429 bb->set_line_direction = spi_gpio_set_direction; in spi_gpio_probe()
431 if (master->flags & SPI_MASTER_NO_TX) { in spi_gpio_probe()
432 bb->txrx_word[SPI_MODE_0] = spi_gpio_spec_txrx_word_mode0; in spi_gpio_probe()
433 bb->txrx_word[SPI_MODE_1] = spi_gpio_spec_txrx_word_mode1; in spi_gpio_probe()
434 bb->txrx_word[SPI_MODE_2] = spi_gpio_spec_txrx_word_mode2; in spi_gpio_probe()
435 bb->txrx_word[SPI_MODE_3] = spi_gpio_spec_txrx_word_mode3; in spi_gpio_probe()
437 bb->txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; in spi_gpio_probe()
438 bb->txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1; in spi_gpio_probe()
439 bb->txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2; in spi_gpio_probe()
440 bb->txrx_word[SPI_MODE_3] = spi_gpio_txrx_word_mode3; in spi_gpio_probe()
442 bb->setup_transfer = spi_bitbang_setup_transfer; in spi_gpio_probe()
444 status = spi_bitbang_init(&spi_gpio->bitbang); in spi_gpio_probe()
448 return devm_spi_register_master(&pdev->dev, master); in spi_gpio_probe()