Lines Matching full:spi

3  * SPI master driver using generic bitbanged GPIO
15 #include <linux/spi/spi.h>
16 #include <linux/spi/spi_bitbang.h>
17 #include <linux/spi/spi_gpio.h>
21 * This bitbanging SPI master driver should help make systems usable
22 * when a native hardware SPI engine is not available, perhaps because
28 * spi->controller_state ... reserved for bitbang framework code
30 * spi->master->dev.driver_data ... points to spi_gpio->bitbang
63 * #include "spi-gpio.c"
76 spi_to_spi_gpio(const struct spi_device *spi) in spi_to_spi_gpio() argument
81 bang = spi_master_get_devdata(spi->master); in spi_to_spi_gpio()
87 static inline void setsck(const struct spi_device *spi, int is_on) in setsck() argument
89 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); in setsck()
94 static inline void setmosi(const struct spi_device *spi, int is_on) in setmosi() argument
96 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); in setmosi()
101 static inline int getmiso(const struct spi_device *spi) in getmiso() argument
103 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); in getmiso()
105 if (spi->mode & SPI_3WIRE) in getmiso()
119 #include "spi-bitbang-txrx.h"
135 static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi, in spi_gpio_txrx_word_mode0() argument
138 if (unlikely(spi->mode & SPI_LSB_FIRST)) in spi_gpio_txrx_word_mode0()
139 return bitbang_txrx_le_cpha0(spi, nsecs, 0, flags, word, bits); in spi_gpio_txrx_word_mode0()
141 return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits); in spi_gpio_txrx_word_mode0()
144 static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi, in spi_gpio_txrx_word_mode1() argument
147 if (unlikely(spi->mode & SPI_LSB_FIRST)) in spi_gpio_txrx_word_mode1()
148 return bitbang_txrx_le_cpha1(spi, nsecs, 0, flags, word, bits); in spi_gpio_txrx_word_mode1()
150 return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits); in spi_gpio_txrx_word_mode1()
153 static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi, in spi_gpio_txrx_word_mode2() argument
156 if (unlikely(spi->mode & SPI_LSB_FIRST)) in spi_gpio_txrx_word_mode2()
157 return bitbang_txrx_le_cpha0(spi, nsecs, 1, flags, word, bits); in spi_gpio_txrx_word_mode2()
159 return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits); in spi_gpio_txrx_word_mode2()
162 static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi, in spi_gpio_txrx_word_mode3() argument
165 if (unlikely(spi->mode & SPI_LSB_FIRST)) in spi_gpio_txrx_word_mode3()
166 return bitbang_txrx_le_cpha1(spi, nsecs, 1, flags, word, bits); in spi_gpio_txrx_word_mode3()
168 return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits); in spi_gpio_txrx_word_mode3()
181 static u32 spi_gpio_spec_txrx_word_mode0(struct spi_device *spi, in spi_gpio_spec_txrx_word_mode0() argument
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()
186 return bitbang_txrx_le_cpha0(spi, nsecs, 0, flags, word, bits); in spi_gpio_spec_txrx_word_mode0()
188 return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits); in spi_gpio_spec_txrx_word_mode0()
191 static u32 spi_gpio_spec_txrx_word_mode1(struct spi_device *spi, in spi_gpio_spec_txrx_word_mode1() argument
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()
196 return bitbang_txrx_le_cpha1(spi, nsecs, 0, flags, word, bits); in spi_gpio_spec_txrx_word_mode1()
198 return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits); in spi_gpio_spec_txrx_word_mode1()
201 static u32 spi_gpio_spec_txrx_word_mode2(struct spi_device *spi, in spi_gpio_spec_txrx_word_mode2() argument
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()
206 return bitbang_txrx_le_cpha0(spi, nsecs, 1, flags, word, bits); in spi_gpio_spec_txrx_word_mode2()
208 return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits); in spi_gpio_spec_txrx_word_mode2()
211 static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi, in spi_gpio_spec_txrx_word_mode3() argument
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()
216 return bitbang_txrx_le_cpha1(spi, nsecs, 1, flags, word, bits); in spi_gpio_spec_txrx_word_mode3()
218 return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits); in spi_gpio_spec_txrx_word_mode3()
223 static void spi_gpio_chipselect(struct spi_device *spi, int is_active) in spi_gpio_chipselect() argument
225 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); in spi_gpio_chipselect()
229 gpiod_set_value_cansleep(spi_gpio->sck, spi->mode & SPI_CPOL); 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()
240 static int spi_gpio_setup(struct spi_device *spi) in spi_gpio_setup() argument
244 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); 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()
258 status = spi_bitbang_setup(spi); in spi_gpio_setup()
263 static int spi_gpio_set_direction(struct spi_device *spi, bool output) in spi_gpio_set_direction() argument
265 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); in spi_gpio_set_direction()
282 if (spi->mode & SPI_3WIRE_HIZ) { in spi_gpio_set_direction()
284 !(spi->mode & SPI_CPOL)); in spi_gpio_set_direction()
286 !!(spi->mode & SPI_CPOL)); in spi_gpio_set_direction()
291 static void spi_gpio_cleanup(struct spi_device *spi) in spi_gpio_cleanup() argument
293 spi_bitbang_cleanup(spi); in spi_gpio_cleanup()
298 * functions associated with a "native" SPI controller if a driver for that
322 { .compatible = "spi-gpio" },
462 MODULE_DESCRIPTION("SPI master driver using generic bitbanged GPIO ");