From patchwork Tue Sep 13 13:38:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 9329137 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8EF356077F for ; Tue, 13 Sep 2016 13:38:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8190429458 for ; Tue, 13 Sep 2016 13:38:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7610F2945F; Tue, 13 Sep 2016 13:38:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 282602945B for ; Tue, 13 Sep 2016 13:38:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757355AbcIMNi3 (ORCPT ); Tue, 13 Sep 2016 09:38:29 -0400 Received: from albert.telenet-ops.be ([195.130.137.90]:46933 "EHLO albert.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751442AbcIMNiZ (ORCPT ); Tue, 13 Sep 2016 09:38:25 -0400 Received: from ayla.of.borg ([84.193.137.253]) by albert.telenet-ops.be with bizsmtp id j1eN1t00i5UCtCs061eNtX; Tue, 13 Sep 2016 15:38:23 +0200 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1bjnuo-0004au-Hr; Tue, 13 Sep 2016 15:38:22 +0200 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1bjnus-00041q-QJ; Tue, 13 Sep 2016 15:38:26 +0200 From: Geert Uytterhoeven To: Mark Brown Cc: Lars-Peter Clausen , Jonathan Cameron , linux-spi@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] spi: core: Use spi_sync_transfer() in spi_write()/spi_read() Date: Tue, 13 Sep 2016 15:38:25 +0200 Message-Id: <1473773905-15451-1-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Simplify spi_write() and spi_read() using the spi_sync_transfer() helper. This requires moving spi_sync_transfer() up. Signed-off-by: Geert Uytterhoeven --- include/linux/spi/spi.h | 58 ++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index de8ae3d92e94c440..3d498110d3e68f5e 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -1010,6 +1010,30 @@ extern int spi_bus_lock(struct spi_master *master); extern int spi_bus_unlock(struct spi_master *master); /** + * spi_sync_transfer - synchronous SPI data transfer + * @spi: device with which data will be exchanged + * @xfers: An array of spi_transfers + * @num_xfers: Number of items in the xfer array + * Context: can sleep + * + * Does a synchronous SPI data transfer of the given spi_transfer array. + * + * For more specific semantics see spi_sync(). + * + * Return: Return: zero on success, else a negative error code. + */ +static inline int +spi_sync_transfer(struct spi_device *spi, struct spi_transfer *xfers, + unsigned int num_xfers) +{ + struct spi_message msg; + + spi_message_init_with_transfers(&msg, xfers, num_xfers); + + return spi_sync(spi, &msg); +} + +/** * spi_write - SPI synchronous write * @spi: device to which data will be written * @buf: data buffer @@ -1028,11 +1052,8 @@ spi_write(struct spi_device *spi, const void *buf, size_t len) .tx_buf = buf, .len = len, }; - struct spi_message m; - spi_message_init(&m); - spi_message_add_tail(&t, &m); - return spi_sync(spi, &m); + return spi_sync_transfer(spi, &t, 1); } /** @@ -1054,35 +1075,8 @@ spi_read(struct spi_device *spi, void *buf, size_t len) .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 - * @xfers: An array of spi_transfers - * @num_xfers: Number of items in the xfer array - * Context: can sleep - * - * Does a synchronous SPI data transfer of the given spi_transfer array. - * - * For more specific semantics see spi_sync(). - * - * Return: Return: zero on success, else a negative error code. - */ -static inline int -spi_sync_transfer(struct spi_device *spi, struct spi_transfer *xfers, - unsigned int num_xfers) -{ - struct spi_message msg; - - spi_message_init_with_transfers(&msg, xfers, num_xfers); - - return spi_sync(spi, &msg); + return spi_sync_transfer(spi, &t, 1); } /* this copies txbuf and rxbuf data; for small transfers only! */