aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-gpio.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-08-14 15:01:08 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-14 15:01:08 -0400
commit010b0e708e08727d38b82accb21832b63fe2c250 (patch)
tree29f110982a25675c02346320b2529ffd82aef244 /drivers/spi/spi-gpio.c
parent792adb90fa724ce07c0171cbc96b9215af4b1045 (diff)
parentc1acb21b32a3bb601453764c9eac9fc8fbb3a81d (diff)
Merge tag 'spi-v4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
Pull spi updates from Mark Brown: "Quite an active release for the SPI subsystem, lots of small updates and fixes scattered about with highlights including: - 3-wire support in the GPIO driver. - support for setting a custom memory name in the memory mapped flash drivers. - support for extended mode in the Freescale DSPI controller. - support for the non-standard integration with the Microsemi Ocelot platform in the DesignWare driver. - new driver for the SocioNext UniPhier" * tag 'spi-v4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (47 commits) spi: davinci: fix a NULL pointer dereference spi: spi-mem: Constify spi_mem->name mtd: m25p80: Call spi_mem_get_name() to let controller set a custom name spi: spi-mem: Extend the SPI mem interface to set a custom memory name spi: spi-mem: Fix a typo in the documentation of struct spi_mem spi: uniphier: remove unnecessary include headers spi: spi-gpio: add SPI_3WIRE support spi: add flags parameter to txrx_word function pointers spi: add SPI controller driver for UniPhier SoC spi: add DT bindings for UniPhier SPI controller spi: dw: document Microsemi integration spi: img-spfi: Set device select bits for SPFI port state spi: omap2-mcspi: remove several redundant variables spi: dw-mmio: add MSCC Ocelot support spi: dw: export dw_spi_set_cs spi: spi-fsl-espi: Log fifo counters on error spi: imx: Use the longuest possible burst size when in dynamic_burst spi: imx: remove unnecessary check in spi_imx_can_dma spi: imx: Use correct number of bytes per words spi: imx: Use dynamic bursts only when bits_per_word is 8, 16 or 32 ...
Diffstat (limited to 'drivers/spi/spi-gpio.c')
-rw-r--r--drivers/spi/spi-gpio.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
index 6ae92d4dca19..0626e6e3ea0c 100644
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -121,7 +121,10 @@ static inline int getmiso(const struct spi_device *spi)
121{ 121{
122 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); 122 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
123 123
124 return !!gpiod_get_value_cansleep(spi_gpio->miso); 124 if (spi->mode & SPI_3WIRE)
125 return !!gpiod_get_value_cansleep(spi_gpio->mosi);
126 else
127 return !!gpiod_get_value_cansleep(spi_gpio->miso);
125} 128}
126 129
127/* 130/*
@@ -149,27 +152,27 @@ static inline int getmiso(const struct spi_device *spi)
149 */ 152 */
150 153
151static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi, 154static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi,
152 unsigned nsecs, u32 word, u8 bits) 155 unsigned nsecs, u32 word, u8 bits, unsigned flags)
153{ 156{
154 return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); 157 return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits);
155} 158}
156 159
157static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi, 160static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi,
158 unsigned nsecs, u32 word, u8 bits) 161 unsigned nsecs, u32 word, u8 bits, unsigned flags)
159{ 162{
160 return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits); 163 return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits);
161} 164}
162 165
163static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi, 166static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi,
164 unsigned nsecs, u32 word, u8 bits) 167 unsigned nsecs, u32 word, u8 bits, unsigned flags)
165{ 168{
166 return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits); 169 return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits);
167} 170}
168 171
169static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi, 172static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi,
170 unsigned nsecs, u32 word, u8 bits) 173 unsigned nsecs, u32 word, u8 bits, unsigned flags)
171{ 174{
172 return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits); 175 return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits);
173} 176}
174 177
175/* 178/*
@@ -183,30 +186,30 @@ static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi,
183 */ 186 */
184 187
185static u32 spi_gpio_spec_txrx_word_mode0(struct spi_device *spi, 188static u32 spi_gpio_spec_txrx_word_mode0(struct spi_device *spi,
186 unsigned nsecs, u32 word, u8 bits) 189 unsigned nsecs, u32 word, u8 bits, unsigned flags)
187{ 190{
188 unsigned flags = spi->master->flags; 191 flags = spi->master->flags;
189 return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits); 192 return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits);
190} 193}
191 194
192static u32 spi_gpio_spec_txrx_word_mode1(struct spi_device *spi, 195static u32 spi_gpio_spec_txrx_word_mode1(struct spi_device *spi,
193 unsigned nsecs, u32 word, u8 bits) 196 unsigned nsecs, u32 word, u8 bits, unsigned flags)
194{ 197{
195 unsigned flags = spi->master->flags; 198 flags = spi->master->flags;
196 return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits); 199 return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits);
197} 200}
198 201
199static u32 spi_gpio_spec_txrx_word_mode2(struct spi_device *spi, 202static u32 spi_gpio_spec_txrx_word_mode2(struct spi_device *spi,
200 unsigned nsecs, u32 word, u8 bits) 203 unsigned nsecs, u32 word, u8 bits, unsigned flags)
201{ 204{
202 unsigned flags = spi->master->flags; 205 flags = spi->master->flags;
203 return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits); 206 return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits);
204} 207}
205 208
206static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi, 209static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi,
207 unsigned nsecs, u32 word, u8 bits) 210 unsigned nsecs, u32 word, u8 bits, unsigned flags)
208{ 211{
209 unsigned flags = spi->master->flags; 212 flags = spi->master->flags;
210 return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits); 213 return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits);
211} 214}
212 215
@@ -250,6 +253,16 @@ static int spi_gpio_setup(struct spi_device *spi)
250 return status; 253 return status;
251} 254}
252 255
256static int spi_gpio_set_direction(struct spi_device *spi, bool output)
257{
258 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
259
260 if (output)
261 return gpiod_direction_output(spi_gpio->mosi, 1);
262 else
263 return gpiod_direction_input(spi_gpio->mosi);
264}
265
253static void spi_gpio_cleanup(struct spi_device *spi) 266static void spi_gpio_cleanup(struct spi_device *spi)
254{ 267{
255 spi_bitbang_cleanup(spi); 268 spi_bitbang_cleanup(spi);
@@ -395,6 +408,7 @@ static int spi_gpio_probe(struct platform_device *pdev)
395 return status; 408 return status;
396 409
397 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); 410 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
411 master->mode_bits = SPI_3WIRE | SPI_CPHA | SPI_CPOL;
398 master->flags = master_flags; 412 master->flags = master_flags;
399 master->bus_num = pdev->id; 413 master->bus_num = pdev->id;
400 /* The master needs to think there is a chipselect even if not connected */ 414 /* The master needs to think there is a chipselect even if not connected */
@@ -407,6 +421,7 @@ static int spi_gpio_probe(struct platform_device *pdev)
407 421
408 spi_gpio->bitbang.master = master; 422 spi_gpio->bitbang.master = master;
409 spi_gpio->bitbang.chipselect = spi_gpio_chipselect; 423 spi_gpio->bitbang.chipselect = spi_gpio_chipselect;
424 spi_gpio->bitbang.set_line_direction = spi_gpio_set_direction;
410 425
411 if ((master_flags & (SPI_MASTER_NO_TX | SPI_MASTER_NO_RX)) == 0) { 426 if ((master_flags & (SPI_MASTER_NO_TX | SPI_MASTER_NO_RX)) == 0) {
412 spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; 427 spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0;