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 <geert+renesas@glider.be> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
29b4817d40
commit
323117ab60
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue