Lines Matching +full:spi +full:- +full:3 +full:wire

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for LM70EVAL-LLP board for the LM70 sensor
19 #include <linux/spi/spi.h>
20 #include <linux/spi/spi_bitbang.h>
23 * The LM70 communicates with a host processor using a 3-wire variant of
24 * the SPI/Microwire bus interface. This driver specifically supports an
26 * port to bitbang an SPI-parport bridge. Accordingly, this is an SPI
27 * master controller driver. The hwmon/lm70 driver is a "SPI protocol
33 * The schematic for this particular board (the LM70EVAL-LLP) is
37 * Also see Documentation/spi/spi-lm70llp.rst. The SPI<->parport code here is
38 * (heavily) based on spi-butterfly by David Brownell.
44 * ----------- --------- ------------
45 * D0 2 - -
46 * D1 3 --> V+ 5
47 * D2 4 --> V+ 5
48 * D3 5 --> V+ 5
49 * D4 6 --> V+ 5
50 * D5 7 --> nCS 8
51 * D6 8 --> SCLK 3
52 * D7 9 --> SI/O 5
53 * GND 25 - GND 7
54 * Select 13 <-- SI/O 1
61 #define DRVNAME "spi-lm70llp"
68 /*-------------------------------------------------------------------------*/
82 /*-------------------------------------------------------------------*/
84 static inline struct spi_lm70llp *spidev_to_pp(struct spi_device *spi) in spidev_to_pp() argument
86 return spi->controller_data; in spidev_to_pp()
89 /*---------------------- LM70 LLP eval board-specific inlines follow */
93 * a ~1ms/operation delay; these SPI transfers could easily be faster.
98 u8 data = parport_read_data(pp->port); in deassertCS()
100 data &= ~0x80; /* pull D7/SI-out low while de-asserted */ in deassertCS()
101 parport_write_data(pp->port, data | nCS); in deassertCS()
106 u8 data = parport_read_data(pp->port); in assertCS()
108 data |= 0x80; /* pull D7/SI-out high so lm70 drives SO-in */ in assertCS()
109 parport_write_data(pp->port, data & ~nCS); in assertCS()
114 u8 data = parport_read_data(pp->port); in clkHigh()
116 parport_write_data(pp->port, data | SCLK); in clkHigh()
121 u8 data = parport_read_data(pp->port); in clkLow()
123 parport_write_data(pp->port, data & ~SCLK); in clkLow()
126 /*------------------------- SPI-LM70-specific inlines ----------------------*/
153 * Why do we return 0 when the SIO line is high and vice-versa?
156 * switches it to low reflecting this on the parport (pin 13), and vice-versa.
162 return ((SIO == (parport_read_status(pp->port) & SIO)) ? 0 : 1); in getmiso()
165 /*--------------------------------------------------------------------*/
167 #include "spi-bitbang-txrx.h"
169 static void lm70_chipselect(struct spi_device *spi, int value) in lm70_chipselect() argument
171 struct spi_lm70llp *pp = spidev_to_pp(spi); in lm70_chipselect()
182 static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits, in lm70_txrx() argument
185 return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits); in lm70_txrx()
205 master = spi_alloc_master(p->physport->dev, sizeof *pp); in spi_lm70llp_attach()
207 status = -ENOMEM; in spi_lm70llp_attach()
213 * SPI and bitbang hookup. in spi_lm70llp_attach()
215 pp->bitbang.master = master; in spi_lm70llp_attach()
216 pp->bitbang.chipselect = lm70_chipselect; in spi_lm70llp_attach()
217 pp->bitbang.txrx_word[SPI_MODE_0] = lm70_txrx; in spi_lm70llp_attach()
218 pp->bitbang.flags = SPI_3WIRE; in spi_lm70llp_attach()
223 pp->port = p; in spi_lm70llp_attach()
230 status = -ENOMEM; in spi_lm70llp_attach()
233 pp->pd = pd; in spi_lm70llp_attach()
240 * Start SPI ... in spi_lm70llp_attach()
242 status = spi_bitbang_start(&pp->bitbang); in spi_lm70llp_attach()
244 dev_warn(&pd->dev, "spi_bitbang_start failed with status %d\n", in spi_lm70llp_attach()
255 strcpy(pp->info.modalias, "lm70"); in spi_lm70llp_attach()
256 pp->info.max_speed_hz = 6 * 1000 * 1000; in spi_lm70llp_attach()
257 pp->info.chip_select = 0; in spi_lm70llp_attach()
258 pp->info.mode = SPI_3WIRE | SPI_MODE_0; in spi_lm70llp_attach()
261 parport_write_data(pp->port, lm70_INIT); in spi_lm70llp_attach()
266 pp->info.controller_data = pp; in spi_lm70llp_attach()
267 pp->spidev_lm70 = spi_new_device(pp->bitbang.master, &pp->info); in spi_lm70llp_attach()
268 if (pp->spidev_lm70) in spi_lm70llp_attach()
269 dev_dbg(&pp->spidev_lm70->dev, "spidev_lm70 at %s\n", in spi_lm70llp_attach()
270 dev_name(&pp->spidev_lm70->dev)); in spi_lm70llp_attach()
272 dev_warn(&pd->dev, "spi_new_device failed\n"); in spi_lm70llp_attach()
273 status = -ENODEV; in spi_lm70llp_attach()
276 pp->spidev_lm70->bits_per_word = 8; in spi_lm70llp_attach()
282 spi_bitbang_stop(&pp->bitbang); in spi_lm70llp_attach()
285 parport_write_data(pp->port, 0); in spi_lm70llp_attach()
287 parport_release(pp->pd); in spi_lm70llp_attach()
300 if (!lm70llp || lm70llp->port != p) in spi_lm70llp_detach()
304 spi_bitbang_stop(&pp->bitbang); in spi_lm70llp_detach()
307 parport_write_data(pp->port, 0); in spi_lm70llp_detach()
309 parport_release(pp->pd); in spi_lm70llp_detach()
310 parport_unregister_device(pp->pd); in spi_lm70llp_detach()
312 spi_master_put(pp->bitbang.master); in spi_lm70llp_detach()