Lines Matching full:spi
2 * SPI init/core code
29 #include <linux/spi/spi.h>
36 struct spi_device *spi = to_spi_device(dev); in spidev_release() local
38 /* spi masters may cleanup for released devices */ in spidev_release()
39 if (spi->master->cleanup) in spidev_release()
40 spi->master->cleanup(spi); in spidev_release()
42 spi_master_put(spi->master); in spidev_release()
43 kfree(spi); in spidev_release()
49 const struct spi_device *spi = to_spi_device(dev); in modalias_show() local
51 return sprintf(buf, "%s\n", spi->modalias); in modalias_show()
84 const struct spi_device *spi = to_spi_device(dev); in spi_match_device() local
92 return !!spi_match_id(sdrv->id_table, spi); in spi_match_device()
94 return strcmp(spi->modalias, drv->name) == 0; in spi_match_device()
99 const struct spi_device *spi = to_spi_device(dev); in spi_uevent() local
101 add_uevent_var(env, "MODALIAS=%s%s", SPI_MODULE_PREFIX, spi->modalias); in spi_uevent()
219 .name = "spi",
250 * spi_register_driver - register a SPI driver
269 /* SPI devices should normally not be created by SPI device drivers; that
270 * would make them board-specific. Similarly with SPI master drivers.
290 * spi_alloc_device - Allocate a new SPI device
300 * spi_device structure to add it to the SPI master. If the caller
308 struct spi_device *spi; in spi_alloc_device() local
314 spi = kzalloc(sizeof *spi, GFP_KERNEL); in spi_alloc_device()
315 if (!spi) { in spi_alloc_device()
321 spi->master = master; in spi_alloc_device()
322 spi->dev.parent = &master->dev; in spi_alloc_device()
323 spi->dev.bus = &spi_bus_type; in spi_alloc_device()
324 spi->dev.release = spidev_release; in spi_alloc_device()
325 device_initialize(&spi->dev); in spi_alloc_device()
326 return spi; in spi_alloc_device()
332 * @spi: spi_device to register
335 * spi_alloc_device can be added onto the spi bus with this function.
339 int spi_add_device(struct spi_device *spi) in spi_add_device() argument
342 struct device *dev = spi->master->dev.parent; in spi_add_device()
347 if (spi->chip_select >= spi->master->num_chipselect) { in spi_add_device()
349 spi->chip_select, in spi_add_device()
350 spi->master->num_chipselect); in spi_add_device()
355 dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev), in spi_add_device()
356 spi->chip_select); in spi_add_device()
365 d = bus_find_device_by_name(&spi_bus_type, NULL, dev_name(&spi->dev)); in spi_add_device()
368 spi->chip_select); in spi_add_device()
378 status = spi_setup(spi); in spi_add_device()
381 dev_name(&spi->dev), status); in spi_add_device()
386 status = device_add(&spi->dev); in spi_add_device()
389 dev_name(&spi->dev), status); in spi_add_device()
391 dev_dbg(dev, "registered child %s\n", dev_name(&spi->dev)); in spi_add_device()
400 * spi_new_device - instantiate one new SPI device
402 * @chip: Describes the SPI device
466 * spi_register_board_info - register SPI devices for a given board
472 * with segments of the SPI device table. Any device nodes are created later,
473 * after the relevant parent SPI controller (bus_num) is defined. We keep
478 * SPI devices through its expansion connector, so code initializing that board
479 * would naturally declare its SPI devices.
526 * spi_alloc_master - allocate SPI master controller
533 * This call is used only by SPI master controller drivers, which are the
537 * This must be called from context that can sleep. It returns the SPI
565 * spi_register_master - register SPI master controller
569 * SPI master controllers connect to their drivers using some non-SPI bus,
571 * includes calling spi_register_master() to hook up to this SPI bus glue.
573 * SPI controllers use board specific (often SOC specific) bus numbers,
574 * and board-specific addressing for SPI devices combines those numbers
575 * with chip select numbers. Since SPI does not directly support dynamic
617 dev_set_name(&master->dev, "spi%u", master->bus_num); in spi_register_master()
647 * spi_unregister_master - unregister SPI master controller
651 * This call is used only by SPI master controller drivers, which are the
705 /* Core methods for SPI master protocol drivers. Some of the
710 * spi_setup - setup SPI mode and clock rate
711 * @spi: the device whose settings are being modified
714 * SPI protocol drivers may need to update the transfer mode if the
720 * or from it. When this function returns, the spi device is deselected.
727 int spi_setup(struct spi_device *spi) in spi_setup() argument
735 bad_bits = spi->mode & ~spi->master->mode_bits; in spi_setup()
737 dev_err(&spi->dev, "setup: unsupported mode bits %x\n", in spi_setup()
742 if (!spi->bits_per_word) in spi_setup()
743 spi->bits_per_word = 8; in spi_setup()
745 status = spi->master->setup(spi); in spi_setup()
747 dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s" in spi_setup()
749 (int) (spi->mode & (SPI_CPOL | SPI_CPHA)), in spi_setup()
750 (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "", in spi_setup()
751 (spi->mode & SPI_LSB_FIRST) ? "lsb, " : "", in spi_setup()
752 (spi->mode & SPI_3WIRE) ? "3wire, " : "", in spi_setup()
753 (spi->mode & SPI_LOOP) ? "loopback, " : "", in spi_setup()
754 spi->bits_per_word, spi->max_speed_hz, in spi_setup()
761 static int __spi_async(struct spi_device *spi, struct spi_message *message) in __spi_async() argument
763 struct spi_master *master = spi->master; in __spi_async()
771 || (spi->mode & SPI_3WIRE)) { in __spi_async()
785 message->spi = spi; in __spi_async()
787 return master->transfer(spi, message); in __spi_async()
791 * spi_async - asynchronous SPI transfer
792 * @spi: device with which data will be exchanged
804 * deallocate the associated memory; it's no longer in use by any SPI
819 int spi_async(struct spi_device *spi, struct spi_message *message) in spi_async() argument
821 struct spi_master *master = spi->master; in spi_async()
830 ret = __spi_async(spi, message); in spi_async()
840 * @spi: device with which data will be exchanged
852 * deallocate the associated memory; it's no longer in use by any SPI
867 int spi_async_locked(struct spi_device *spi, struct spi_message *message) in spi_async_locked() argument
869 struct spi_master *master = spi->master; in spi_async_locked()
875 ret = __spi_async(spi, message); in spi_async_locked()
887 /* Utility methods for SPI master protocol drivers, layered on
897 static int __spi_sync(struct spi_device *spi, struct spi_message *message, in __spi_sync() argument
902 struct spi_master *master = spi->master; in __spi_sync()
910 status = spi_async_locked(spi, message); in __spi_sync()
924 * spi_sync - blocking/synchronous SPI data transfers
925 * @spi: device with which data will be exchanged
933 * Note that the SPI device's chip select is active during the message,
944 int spi_sync(struct spi_device *spi, struct spi_message *message) in spi_sync() argument
946 return __spi_sync(spi, message, 0); in spi_sync()
952 * @spi: device with which data will be exchanged
961 * SPI bus. It has to be preceded by a spi_bus_lock call. The SPI bus must
966 int spi_sync_locked(struct spi_device *spi, struct spi_message *message) in spi_sync_locked() argument
968 return __spi_sync(spi, message, 1); in spi_sync_locked()
973 * spi_bus_lock - obtain a lock for exclusive SPI bus usage
974 * @master: SPI bus master that should be locked for exclusive bus access
981 * SPI bus. The SPI bus must be released by a spi_bus_unlock call when the
983 * and spi_async_locked calls when the SPI bus lock is held.
1004 * spi_bus_unlock - release the lock for exclusive SPI bus usage
1005 * @master: SPI bus master that was locked for exclusive bus access
1011 * This call releases an SPI bus lock previously obtained by an spi_bus_lock
1032 * spi_write_then_read - SPI synchronous write followed by read
1033 * @spi: device with which data will be exchanged
1050 int spi_write_then_read(struct spi_device *spi, in spi_write_then_read() argument
1092 status = spi_sync(spi, &message); in spi_write_then_read()