Message ID | 1466034046-718-1-git-send-email-andi.shyti@samsung.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 06/16/2016 01:40 AM, Andi Shyti wrote: > The spi_sync_single_transfer function calls spi_sync_transfer > with a single spi_transfer element, instead of an array. So, what's the advantage of using this as opposed to calling spi_sync_transfer with a 1 for the number of transfers? -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Lars, > > The spi_sync_single_transfer function calls spi_sync_transfer > > with a single spi_transfer element, instead of an array. > > So, what's the advantage of using this as opposed to calling > spi_sync_transfer with a 1 for the number of transfers? Not much, but it keeps the code a bit nicer to read for those using spi_sync_transfer with only one spi_transfer. Besides it's also more understandable what the function itself does and there would not be any need to jump into the spi_sync_transfer to check what the number '1' is needed for (for example it's not a boolean 'true' value). I checked and there are quite many uses of spi_sync_transfer with only 1 transfer. Thanks, Andi -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Fri, Jun 17, 2016 at 09:43:11AM +0900, Andi Shyti wrote: > > > The spi_sync_single_transfer function calls spi_sync_transfer > > > with a single spi_transfer element, instead of an array. > > So, what's the advantage of using this as opposed to calling > > spi_sync_transfer with a 1 for the number of transfers? > Not much, but it keeps the code a bit nicer to read for those > using spi_sync_transfer with only one spi_transfer. Besides it's > also more understandable what the function itself does and there > would not be any need to jump into the spi_sync_transfer to check > what the number '1' is needed for (for example it's not a boolean > 'true' value). I really don't think this has been a big source of confusion for people.
On Fri, Jun 17, 2016 at 12:34:53PM +0100, Mark Brown wrote: > On Fri, Jun 17, 2016 at 09:43:11AM +0900, Andi Shyti wrote: > > > > > The spi_sync_single_transfer function calls spi_sync_transfer > > > > with a single spi_transfer element, instead of an array. > > > > So, what's the advantage of using this as opposed to calling > > > spi_sync_transfer with a 1 for the number of transfers? > > > Not much, but it keeps the code a bit nicer to read for those > > using spi_sync_transfer with only one spi_transfer. Besides it's > > also more understandable what the function itself does and there > > would not be any need to jump into the spi_sync_transfer to check > > what the number '1' is needed for (for example it's not a boolean > > 'true' value). > > I really don't think this has been a big source of confusion for people. OK, nevermind, then :) Thanks, Andi -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 1f03483..660f6a1 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -1051,6 +1051,24 @@ spi_sync_transfer(struct spi_device *spi, struct spi_transfer *xfers, return spi_sync(spi, &msg); } +/** + * spi_sync_single_transfer - synchronous SPI data transfer of one spi_transfer + * @spi: device with which data will be exchanged + * @xfers: One spi_transfer struct + * Context: can sleep + * + * Does a synchronous SPI data transfer of a given spi_transfer. + * + * For more specific semantics see spi_sync_transfer(). + * + * It returns zero on success, else a negative error code. + */ +static inline int +spi_sync_single_transfer(struct spi_device *spi, struct spi_transfer *xfers) +{ + return spi_sync_transfer(spi, xfers, 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,
The spi_sync_single_transfer function calls spi_sync_transfer with a single spi_transfer element, instead of an array. Signed-off-by: Andi Shyti <andi.shyti@samsung.com> --- include/linux/spi/spi.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)