From 323117ab60156d5ef021eeef260c4e7e0a7f520e Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 13 Sep 2016 15:38:25 +0200 Subject: [PATCH] spi: core: Use spi_sync_transfer() in spi_write()/spi_read() Simplify spi_write() and spi_read() using the spi_sync_transfer() helper. This requires moving spi_sync_transfer() up. Signed-off-by: Geert Uytterhoeven Signed-off-by: Mark Brown --- include/linux/spi/spi.h | 98 +++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 072cb2aa2413..74278c7d0f52 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -979,58 +979,6 @@ extern int spi_sync_locked(struct spi_device *spi, struct spi_message *message); extern int spi_bus_lock(struct spi_master *master); extern int spi_bus_unlock(struct spi_master *master); -/** - * spi_write - SPI synchronous write - * @spi: device to which data will be written - * @buf: data buffer - * @len: data buffer size - * Context: can sleep - * - * This function writes the buffer @buf. - * Callable only from contexts that can sleep. - * - * Return: zero on success, else a negative error code. - */ -static inline int -spi_write(struct spi_device *spi, const void *buf, size_t len) -{ - struct spi_transfer t = { - .tx_buf = buf, - .len = len, - }; - struct spi_message m; - - spi_message_init(&m); - spi_message_add_tail(&t, &m); - return spi_sync(spi, &m); -} - -/** - * spi_read - SPI synchronous read - * @spi: device from which data will be read - * @buf: data buffer - * @len: data buffer size - * Context: can sleep - * - * This function reads the buffer @buf. - * Callable only from contexts that can sleep. - * - * Return: zero on success, else a negative error code. - */ -static inline int -spi_read(struct spi_device *spi, void *buf, size_t len) -{ - struct spi_transfer t = { - .rx_buf = buf, - .len = len, - }; - struct spi_message m; - - spi_message_init(&m); - spi_message_add_tail(&t, &m); - return spi_sync(spi, &m); -} - /** * spi_sync_transfer - synchronous SPI data transfer * @spi: device with which data will be exchanged @@ -1055,6 +1003,52 @@ spi_sync_transfer(struct spi_device *spi, struct spi_transfer *xfers, return spi_sync(spi, &msg); } +/** + * spi_write - SPI synchronous write + * @spi: device to which data will be written + * @buf: data buffer + * @len: data buffer size + * Context: can sleep + * + * This function writes the buffer @buf. + * Callable only from contexts that can sleep. + * + * Return: zero on success, else a negative error code. + */ +static inline int +spi_write(struct spi_device *spi, const void *buf, size_t len) +{ + struct spi_transfer t = { + .tx_buf = buf, + .len = len, + }; + + return spi_sync_transfer(spi, &t, 1); +} + +/** + * spi_read - SPI synchronous read + * @spi: device from which data will be read + * @buf: data buffer + * @len: data buffer size + * Context: can sleep + * + * This function reads the buffer @buf. + * Callable only from contexts that can sleep. + * + * Return: zero on success, else a negative error code. + */ +static inline int +spi_read(struct spi_device *spi, void *buf, size_t len) +{ + struct spi_transfer t = { + .rx_buf = buf, + .len = len, + }; + + return spi_sync_transfer(spi, &t, 1); +} + /* this copies txbuf and rxbuf data; for small transfers only! */ extern int spi_write_then_read(struct spi_device *spi, const void *txbuf, unsigned n_tx,