Lines Matching +full:miso +full:- +full:pins

1 /*-
74 device_set_desc(dev, "GPIO SPI bit-banging driver"); in gpio_spi_probe()
83 d = sc->sc_freq / 1000000; in gpio_delay()
97 sc->sc_dev = dev; in gpio_spi_attach()
98 sc->sc_busdev = device_get_parent(dev); in gpio_spi_attach()
104 sc->sc_sclk = value & 0xff; in gpio_spi_attach()
109 sc->sc_mosi = value & 0xff; in gpio_spi_attach()
111 /* Handle no miso; we just never read back from the device */ in gpio_spi_attach()
113 device_get_unit(dev), "miso", &value)) in gpio_spi_attach()
115 sc->sc_miso = value & 0xff; in gpio_spi_attach()
120 sc->sc_cs0 = value & 0xff; in gpio_spi_attach()
126 sc->sc_cs1 = value & 0xff; in gpio_spi_attach()
131 sc->sc_cs2 = value & 0xff; in gpio_spi_attach()
136 sc->sc_cs3 = value & 0xff; in gpio_spi_attach()
143 sc->sc_freq = value; in gpio_spi_attach()
147 sc->sc_freq); in gpio_spi_attach()
149 "Use GPIO pins: sclk=%d, mosi=%d, miso=%d, " in gpio_spi_attach()
151 sc->sc_sclk, sc->sc_mosi, sc->sc_miso, in gpio_spi_attach()
152 sc->sc_cs0, sc->sc_cs1, sc->sc_cs2, sc->sc_cs3); in gpio_spi_attach()
156 GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sc_sclk, in gpio_spi_attach()
158 GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sc_mosi, in gpio_spi_attach()
160 if (sc->sc_miso != 0xff) { in gpio_spi_attach()
161 GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sc_miso, in gpio_spi_attach()
165 GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sc_cs0, in gpio_spi_attach()
168 if (sc->sc_cs1 != 0xff) in gpio_spi_attach()
169 GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sc_cs1, in gpio_spi_attach()
171 if (sc->sc_cs2 != 0xff) in gpio_spi_attach()
172 GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sc_cs2, in gpio_spi_attach()
174 if (sc->sc_cs3 != 0xff) in gpio_spi_attach()
175 GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sc_cs3, in gpio_spi_attach()
178 gpio_spi_chip_deactivate(sc, -1); in gpio_spi_attach()
199 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_chip_activate()
200 sc->sc_cs0, 0); in gpio_spi_chip_activate()
203 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_chip_activate()
204 sc->sc_cs1, 0); in gpio_spi_chip_activate()
207 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_chip_activate()
208 sc->sc_cs2, 0); in gpio_spi_chip_activate()
211 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_chip_activate()
212 sc->sc_cs3, 0); in gpio_spi_chip_activate()
215 device_printf(sc->sc_dev, "don't have CS%d\n", cs); in gpio_spi_chip_activate()
230 case -1: in gpio_spi_chip_deactivate()
232 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_chip_deactivate()
233 sc->sc_cs0, 1); in gpio_spi_chip_deactivate()
234 if (sc->sc_cs1 == 0xff) break; in gpio_spi_chip_deactivate()
235 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_chip_deactivate()
236 sc->sc_cs1, 1); in gpio_spi_chip_deactivate()
237 if (sc->sc_cs2 == 0xff) break; in gpio_spi_chip_deactivate()
238 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_chip_deactivate()
239 sc->sc_cs2, 1); in gpio_spi_chip_deactivate()
240 if (sc->sc_cs3 == 0xff) break; in gpio_spi_chip_deactivate()
241 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_chip_deactivate()
242 sc->sc_cs3, 1); in gpio_spi_chip_deactivate()
245 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_chip_deactivate()
246 sc->sc_cs0, 1); in gpio_spi_chip_deactivate()
249 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_chip_deactivate()
250 sc->sc_cs1, 1); in gpio_spi_chip_deactivate()
253 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_chip_deactivate()
254 sc->sc_cs2, 1); in gpio_spi_chip_deactivate()
257 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_chip_deactivate()
258 sc->sc_cs3, 1); in gpio_spi_chip_deactivate()
261 device_printf(sc->sc_dev, "don't have CS%d\n", cs); in gpio_spi_chip_deactivate()
280 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_txrx()
281 sc->sc_mosi, (data & mask)?1:0); in gpio_spi_txrx()
282 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_txrx()
283 sc->sc_sclk, 0); in gpio_spi_txrx()
286 if (sc->sc_miso != 0xff) { in gpio_spi_txrx()
287 GPIOBUS_PIN_GET(sc->sc_busdev, sc->sc_dev, in gpio_spi_txrx()
288 sc->sc_miso, &bit); in gpio_spi_txrx()
293 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_txrx()
294 sc->sc_sclk, 1); in gpio_spi_txrx()
300 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_txrx()
301 sc->sc_mosi, (data & mask)?1:0); in gpio_spi_txrx()
302 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_txrx()
303 sc->sc_sclk, 1); in gpio_spi_txrx()
306 if (sc->sc_miso != 0xff) { in gpio_spi_txrx()
307 GPIOBUS_PIN_GET(sc->sc_busdev, sc->sc_dev, in gpio_spi_txrx()
308 sc->sc_miso, &bit); in gpio_spi_txrx()
313 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_txrx()
314 sc->sc_sclk, 0); in gpio_spi_txrx()
332 KASSERT(cmd->tx_cmd_sz == cmd->rx_cmd_sz, in gpio_spi_transfer()
334 KASSERT(cmd->tx_data_sz == cmd->rx_data_sz, in gpio_spi_transfer()
337 gpio_spi_chip_activate(sc, devi->cs); in gpio_spi_transfer()
339 /* Preset pins */ in gpio_spi_transfer()
340 if ((devi->mode == SPIBUS_MODE_CPOL) || in gpio_spi_transfer()
341 (devi->mode == SPIBUS_MODE_CPHA)) { in gpio_spi_transfer()
342 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_transfer()
343 sc->sc_sclk, 1); in gpio_spi_transfer()
345 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_transfer()
346 sc->sc_sclk, 0); in gpio_spi_transfer()
352 buf_out = (uint8_t *)cmd->tx_cmd; in gpio_spi_transfer()
353 buf_in = (uint8_t *)cmd->rx_cmd; in gpio_spi_transfer()
355 for (i = 0; i < cmd->tx_cmd_sz; i++) in gpio_spi_transfer()
356 buf_in[i] = gpio_spi_txrx(sc, devi->cs, devi->mode, buf_out[i]); in gpio_spi_transfer()
361 buf_out = (uint8_t *)cmd->tx_data; in gpio_spi_transfer()
362 buf_in = (uint8_t *)cmd->rx_data; in gpio_spi_transfer()
363 for (i = 0; i < cmd->tx_data_sz; i++) in gpio_spi_transfer()
364 buf_in[i] = gpio_spi_txrx(sc, devi->cs, devi->mode, buf_out[i]); in gpio_spi_transfer()
366 /* Return pins to mode default */ in gpio_spi_transfer()
367 if ((devi->mode == SPIBUS_MODE_CPOL) || in gpio_spi_transfer()
368 (devi->mode == SPIBUS_MODE_CPHA)) { in gpio_spi_transfer()
369 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_transfer()
370 sc->sc_sclk, 1); in gpio_spi_transfer()
372 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, in gpio_spi_transfer()
373 sc->sc_sclk, 0); in gpio_spi_transfer()
376 gpio_spi_chip_deactivate(sc, devi->cs); in gpio_spi_transfer()