From patchwork Mon Feb 12 23:26:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13554145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 959DAC4829D for ; Mon, 12 Feb 2024 23:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=V9XoaYHzja9/mbdA3Y1Q9ZDKfYDHucB0iAxGzkENXzs=; b=bTUlLUbQ+K1yTZ PJsguMZ4HUMdTokvqHPxGg9dSJBnThSmOV6g+lgx16I8JpKKZk6w92k8Iy1Yn8aiDsGbhVm54+Wrs FYj7QSM5hGZBevvffoL8u6hm+C7D/6vBfwZK2bQhV8saitnLLUssRVbFLyvAOOuCrH42DNvIwflnB Y+uGifLy1cWkarDeWKJDlkUBNAZCNuXrpStYLGdiX2Ct4h6vDg3XqwhMz+5vt3MqeWK0fcbhA5AIw X1n4iPAy/JY3/pZopjuTNBZeBe/HoOxzQNC60AXy3QPonsCfygeDK1Istty6bCxp9HYiahKrm58go FkNSPYVObxFg2kYQAYPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZfiT-00000007Grt-0o3Q; Mon, 12 Feb 2024 23:28:01 +0000 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZfiO-00000007Gor-0XUM for linux-arm-kernel@lists.infradead.org; Mon, 12 Feb 2024 23:27:58 +0000 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-21922481a2fso2788947fac.0 for ; Mon, 12 Feb 2024 15:27:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707780475; x=1708385275; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y5nlvb7whNQtUeaLVoTHbqmwre6mZQsRGTnIbxan8M0=; b=GQjnCpp9Pnc/e3pnrbrd8sl0xWTbTHciDBp3qkIkvxwEyPJodkbekvJ7AxZQ1Jpyet 42S8pTHmp6Xtc9yLC3kael/aQfTYdXxE7ozN3gKo5PqJisOuszYh+DzZ+tF5rHCdySF7 AE8/deCLxqCyGIjJVqG/hYD/2IRKkZ1FIQeMb5W0cdleZOE3sMMVP/+/CPENuNB8n3QV DrhTRHwXbJTgFf+mGU9hYohciusGTrGWbrtl7uOnLjh8TgO65TF0hU8botqXoJh/mtX9 mMFKr1jsvCSkuLz3pMJE7Pbpt/u57+JSbq6mVc1sdyubsTNSBOi0x/chkbzF1B81kcd0 cI1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707780475; x=1708385275; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y5nlvb7whNQtUeaLVoTHbqmwre6mZQsRGTnIbxan8M0=; b=Vwlu/uxaHu9zG8lR41pE2kUCNexamkm9hnxUHRgNDnWxMlIVpu3tGlbeasddmqwIf/ 9mNOFRAbQvjfZmq6xIAttjdnrBN+TXwQyU973bujQl0/vrDl1Z+Qx0CxuDPBl5qvQqKF LEigT3S3bMzqgh5GPRfShgBwYIZLW4EWxdQAHVxKUc1M342bDv+pweBQpULn91LJeRVW aaXAox5/dxp5ApvHdQrkb0ZEJxteuxWSzsnY8nlUAc4HB4DIEagiQKUB8ehIxZbNK761 5RDknZDokX+8DoHm10gNqmkMjTxoEr6qosENwJqD7WJmPqOKtzotilgG/MN/WOtasioj 33rg== X-Gm-Message-State: AOJu0YzuN0blM+PUliQ7j1WPDAV/9HBFYGBQnroe4TtnB3yfP6oJUf+X V9VHljCP8kvPiKrs3qAZYVsqOEd6oijwbrnNAsPLggmUtyBdU0LmX7NgQNp+K9M= X-Google-Smtp-Source: AGHT+IGvxMcOWZ2Dv756kXDAUlvzBSoSeQYwyeWZHoJaRDJmyJNey3V4uJB8Ovv52qzdBiAy2PaaGQ== X-Received: by 2002:a05:6870:fb86:b0:21a:34e1:bfd3 with SMTP id kv6-20020a056870fb8600b0021a34e1bfd3mr7547301oab.25.1707780474781; Mon, 12 Feb 2024 15:27:54 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVzhfZUuDWw4nNUdfIipHha2QvzEVJ76dXh2uwDGgQ+rFZOzT0PLSSkaWrB2H3bUw8a0n29HmiZAzDDSB0lhM/X5/S1OScQmG4U2gnkCboLBYHdwNUwIQTk9+8690fwmVyg1tAsEMX4cDQFTkDuOE7UNJLJdPZf779SrJwKwtsLLnq6HhsMwuV9HHlz81Re62ptX4dI5uPC1G0x3YZkgGPOU2DGQkeSEkjhN6fIR/a1GTScqced6k8YMphov6T9cfjsZPqf5L0ez1xk88FNiZbcC5jN+LKGW9lnk+8orNIDMCzU/tRBt4o5oVSLxngvZYiG0hlWfqbJfdUPau3lsnGT4GsZrDJVLsygXVR/Ogg8QyCzSHxg8BgxVuq/bpyQcp8ZpAW4iCvWiSwaw3e+1ILVtFO2TZN0tfNh75CSeNy/oZgnrvsKdlNzXmhFawU5t//LwrcguwbB13qIcxQMM3hLn1oRRdoicOlsuw1HCzyI6lksBbscW9Hnw0anWzfkZFG2ZOtAVCGCYwLMYIbjhvcAco81fmo= Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id pk17-20020a0568704c1100b0021a7a45e0b1sm330141oab.35.2024.02.12.15.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 15:27:54 -0800 (PST) From: David Lechner To: Mark Brown Cc: David Lechner , Martin Sperl , David Jander , Jonathan Cameron , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Alain Volmat , Maxime Coquelin , Alexandre Torgue , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-iio@vger.kernel.org Subject: [PATCH 1/5] spi: add spi_optimize_message() APIs Date: Mon, 12 Feb 2024 17:26:41 -0600 Message-ID: <20240212-mainline-spi-precook-message-v1-1-a2373cd72d36@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212-mainline-spi-precook-message-v1-0-a2373cd72d36@baylibre.com> References: <20240212-mainline-spi-precook-message-v1-0-a2373cd72d36@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240212_152756_222665_5596DFB5 X-CRM114-Status: GOOD ( 33.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This adds a new spi_optimize_message() function that can be used to optimize SPI messages that are used more than once. Peripheral drivers that use the same message multiple times can use this API to perform SPI message validation and controller-specific optimizations once and then reuse the message while avoiding the overhead of revalidating the message on each spi_(a)sync() call. Internally, the SPI core will also call this function for each message if the peripheral driver did not explicitly call it. This is done to so that controller drivers don't have to have multiple code paths for optimized and non-optimized messages. A hook is provided for controller drivers to perform controller-specific optimizations. Suggested-by: Martin Sperl Link: https://lore.kernel.org/linux-spi/39DEC004-10A1-47EF-9D77-276188D2580C@martin.sperl.org/ Signed-off-by: David Lechner --- drivers/spi/spi.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++-- include/linux/spi/spi.h | 19 +++++++ 2 files changed, 160 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index c2b10e2c75f0..5bac215d7009 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2106,6 +2106,41 @@ struct spi_message *spi_get_next_queued_message(struct spi_controller *ctlr) } EXPORT_SYMBOL_GPL(spi_get_next_queued_message); +/** + * __spi_unoptimize_message - shared implementation of spi_unoptimize_message() + * and spi_maybe_unoptimize_message() + * @msg: the message to unoptimize + * + * Periperhal drivers should use spi_unoptimize_message() and callers inside + * core should use spi_maybe_unoptimize_message() rather than calling this + * function directly. + * + * It is not valid to call this on a message that is not currently optimized. + */ +static void __spi_unoptimize_message(struct spi_message *msg) +{ + struct spi_controller *ctlr = msg->spi->controller; + + if (ctlr->unoptimize_message) + ctlr->unoptimize_message(msg); + + msg->optimized = false; + msg->opt_state = NULL; +} + +/** + * spi_maybe_unoptimize_message - unoptimize msg not managed by a peripheral + * @msg: the message to unoptimize + * + * This function is used to unoptimize a message if and only if it was + * optimized by the core (via spi_maybe_optimize_message()). + */ +static void spi_maybe_unoptimize_message(struct spi_message *msg) +{ + if (!msg->pre_optimized && msg->optimized) + __spi_unoptimize_message(msg); +} + /** * spi_finalize_current_message() - the current message is complete * @ctlr: the controller to return the message to @@ -2153,6 +2188,8 @@ void spi_finalize_current_message(struct spi_controller *ctlr) mesg->prepared = false; + spi_maybe_unoptimize_message(mesg); + WRITE_ONCE(ctlr->cur_msg_incomplete, false); smp_mb(); /* See __spi_pump_transfer_message()... */ if (READ_ONCE(ctlr->cur_msg_need_completion)) @@ -4194,6 +4231,99 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) return 0; } +/** + * __spi_optimize_message - shared implementation for spi_optimize_message() + * and spi_maybe_optimize_message() + * @spi: the device that will be used for the message + * @msg: the message to optimize + * @pre_optimized: whether the message is considered pre-optimized or not + * + * Peripheral drivers will call spi_optimize_message() and the spi core will + * call spi_maybe_optimize_message() instead of calling this directly. + * + * It is not valid to call this on a message that has already been optimized. + * + * Return: zero on success, else a negative error code + */ +static int __spi_optimize_message(struct spi_device *spi, + struct spi_message *msg, + bool pre_optimized) +{ + struct spi_controller *ctlr = spi->controller; + int ret; + + ret = __spi_validate(spi, msg); + if (ret) + return ret; + + if (ctlr->optimize_message) { + ret = ctlr->optimize_message(msg); + if (ret) + return ret; + } + + msg->pre_optimized = pre_optimized; + msg->optimized = true; + + return 0; +} + +/** + * spi_maybe_optimize_message - optimize message if it isn't already pre-optimized + * @spi: the device that will be used for the message + * @msg: the message to optimize + * Return: zero on success, else a negative error code + */ +static int spi_maybe_optimize_message(struct spi_device *spi, + struct spi_message *msg) +{ + if (msg->pre_optimized) + return 0; + + return __spi_optimize_message(spi, msg, false); +} + +/** + * spi_optimize_message - do any one-time validation and setup for a SPI message + * @spi: the device that will be used for the message + * @msg: the message to optimize + * + * Peripheral drivers that reuse the same message repeatedly may call this to + * perform as much message prep as possible once, rather than repeating it each + * time a message transfer is performed to improve throughput and reduce CPU + * usage. + * + * Once a message has been optimized, it cannot be modified with the exception + * of updating the contents of any xfer->tx_buf (the pointer can't be changed, + * only the data in the memory it points to). + * + * Calls to this function must be balanced with calls to spi_unoptimize_message() + * to avoid leaking resources. + * + * Context: can sleep + * Return: zero on success, else a negative error code + */ +int spi_optimize_message(struct spi_device *spi, struct spi_message *msg) +{ + return __spi_optimize_message(spi, msg, true); +} +EXPORT_SYMBOL_GPL(spi_optimize_message); + +/** + * spi_unoptimize_message - releases any resources allocated by spi_optimize_message() + * @msg: the message to unoptimize + * + * Calls to this function must be balanced with calls to spi_optimize_message(). + * + * Context: can sleep + */ +void spi_unoptimize_message(struct spi_message *msg) +{ + __spi_unoptimize_message(msg); + msg->pre_optimized = false; +} +EXPORT_SYMBOL_GPL(spi_unoptimize_message); + static int __spi_async(struct spi_device *spi, struct spi_message *message) { struct spi_controller *ctlr = spi->controller; @@ -4258,8 +4388,8 @@ int spi_async(struct spi_device *spi, struct spi_message *message) int ret; unsigned long flags; - ret = __spi_validate(spi, message); - if (ret != 0) + ret = spi_maybe_optimize_message(spi, message); + if (ret) return ret; spin_lock_irqsave(&ctlr->bus_lock_spinlock, flags); @@ -4271,6 +4401,8 @@ int spi_async(struct spi_device *spi, struct spi_message *message) spin_unlock_irqrestore(&ctlr->bus_lock_spinlock, flags); + spi_maybe_unoptimize_message(message); + return ret; } EXPORT_SYMBOL_GPL(spi_async); @@ -4331,10 +4463,15 @@ static int __spi_sync(struct spi_device *spi, struct spi_message *message) return -ESHUTDOWN; } - status = __spi_validate(spi, message); - if (status != 0) + status = spi_maybe_optimize_message(spi, message); + if (status) return status; + /* + * NB: all return paths after this point must ensure that + * spi_finalize_current_message() is called to avoid leaking resources. + */ + SPI_STATISTICS_INCREMENT_FIELD(ctlr->pcpu_statistics, spi_sync); SPI_STATISTICS_INCREMENT_FIELD(spi->pcpu_statistics, spi_sync); diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 2b8e2746769a..f7a269f4956b 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -475,6 +475,8 @@ extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 ch * * @set_cs: set the logic level of the chip select line. May be called * from interrupt context. + * @optimize_message: optimize the message for reuse + * @unoptimize_message: release resources allocated by optimize_message * @prepare_message: set up the controller to transfer a single message, * for example doing DMA mapping. Called from threaded * context. @@ -715,6 +717,8 @@ struct spi_controller { struct completion xfer_completion; size_t max_dma_len; + int (*optimize_message)(struct spi_message *msg); + int (*unoptimize_message)(struct spi_message *msg); int (*prepare_transfer_hardware)(struct spi_controller *ctlr); int (*transfer_one_message)(struct spi_controller *ctlr, struct spi_message *mesg); @@ -1111,6 +1115,7 @@ struct spi_transfer { * @spi: SPI device to which the transaction is queued * @is_dma_mapped: if true, the caller provided both DMA and CPU virtual * addresses for each transfer buffer + * @optimized: spi_optimize_message was called for the this message * @prepared: spi_prepare_message was called for the this message * @status: zero for success, else negative errno * @complete: called to report transaction completions @@ -1120,6 +1125,7 @@ struct spi_transfer { * successful segments * @queue: for use by whichever driver currently owns the message * @state: for use by whichever driver currently owns the message + * @opt_state: for use by whichever driver currently owns the message * @resources: for resource management when the SPI message is processed * * A @spi_message is used to execute an atomic sequence of data transfers, @@ -1143,6 +1149,11 @@ struct spi_message { unsigned is_dma_mapped:1; + /* spi_optimize_message() was called for this message */ + bool pre_optimized; + /* __spi_optimize_message() was called for this message */ + bool optimized; + /* spi_prepare_message() was called for this message */ bool prepared; @@ -1172,6 +1183,11 @@ struct spi_message { */ struct list_head queue; void *state; + /* + * Optional state for use by controller driver between calls to + * spi_optimize_message() and spi_unoptimize_message(). + */ + void *opt_state; /* List of spi_res resources when the SPI message is processed */ struct list_head resources; @@ -1255,6 +1271,9 @@ static inline void spi_message_free(struct spi_message *m) kfree(m); } +extern int spi_optimize_message(struct spi_device *spi, struct spi_message *msg); +extern void spi_unoptimize_message(struct spi_message *msg); + extern int spi_setup(struct spi_device *spi); extern int spi_async(struct spi_device *spi, struct spi_message *message); extern int spi_slave_abort(struct spi_device *spi); From patchwork Mon Feb 12 23:26:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13554146 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB643C4829E for ; Mon, 12 Feb 2024 23:28:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KyUAlcKO+vHzSjt//IJq3gheXBTeG8FVShzeTmiykOA=; b=ZPbIHJBJyBXJSS m0fbTDXC5juURf/aDb36VbCajV8krJsp0mnl/VYf2oWuI2AxlYqc5xUwDElJ1GPTwZ058gPqZocwo UTeiG+IFol4ZBGYmsdFgeV9TLvEwD7t+UAWA8n1KpV26jfaOnZBR6ImdtbYOoXQVKPrLVDlP4Idy2 2xap/GcytnGqW2KtESTE8rAw0xHKbxbR1kFoqML+QZf15w2f+KHSiVxw/nT72jOZGuqFAUKMOZ6Wy zBhKUCUWRNZp0gIThyyJ4aXN4pWopbzicCR2EtH5X1IgB7D+/kdbR2oxwNQD51H2XPn3IkFMHmweO V1Wd+89GyjeeSzN2ZL+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZfiZ-00000007Gtv-3xBG; Mon, 12 Feb 2024 23:28:07 +0000 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZfiP-00000007GpI-0VUY for linux-arm-kernel@lists.infradead.org; Mon, 12 Feb 2024 23:27:59 +0000 Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3bba0ac2e88so2760264b6e.0 for ; Mon, 12 Feb 2024 15:27:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707780476; x=1708385276; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eLX74Fa9d90V9VkLwpCR7m/vmZr63zncboWNam9EPB0=; b=ailF5tzD8xMc5gnULfsj8vgALn3nLLv7iBH2baYRpDT3xPGGnScuG+OloQNoh9g52p 4d95iyk32cyHocIjsaAEmUnSgW/0nz9a3AGZR2reydJy6H3chm2fHMBca6lkruvUDKW8 9WmTJ3sBmomcVxjUyUVoY6ulb9vTOo8gNoNcY7AISdzQQK4mKb0YmvQM7MIq0rHKnQ28 Q1LePgVMhtD2vcWBKw/otTQMarZMKAAeqqvl9c1Wt3wOn9RdxSDpWQXXoalpxzH9mQ9O HaNFb8cDHB8kQp9US951DjucGeVtLP8PpT38XY0gnViILLwT45KBLBhAdLRKPhT3Sd3H t7DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707780476; x=1708385276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eLX74Fa9d90V9VkLwpCR7m/vmZr63zncboWNam9EPB0=; b=GAgNlt3jrAtzPbKgfAifJ+H6jgvAGfBGd+y3tjAYIiO80EB0iRrHPoM+Z6hEatEGCv kU9xFazO3uwHJFaTLX42hoKxnoQ+5pqfM6PjXffP08NCMlmSF6pjwoESHGrWK1QEsW+d YnKs8Nw5C/XQjSspB6ozI27tJnGb8T37tfCYUEm/CcurHh6/AzKdekG9Reyr5foytqSV MFjHsbD603GskB5QS1RYBF0XgujFf6N6Z+tCTuB3En7eh9i1X9rS6E1uh6FaNsgDKUYV GinyxMgUCNUMFyxbuVzheVreHnJky+5EBMyMCDmubzdJd6q+GQbxuj8lpPvJSdQ1aUDW Cx2Q== X-Gm-Message-State: AOJu0Yzf5JIUwZaaT0PA1ClLBWfCdMxLWhtxkcI/VZGTPYM3ZzqKyhV9 O8/klhi7ZZX5+VpPjlucRGSHAnsIbN6PYkTWmkuuMUON2itNRHbk+zrJ734KaDE= X-Google-Smtp-Source: AGHT+IENcG0sbm+FxGSeKQ32xuud3iecYncceHk8taz1sm4Yg2pNVJ8oAzK4Wiliu88pFCNfDotmDQ== X-Received: by 2002:a05:6808:4396:b0:3c0:370c:69ea with SMTP id dz22-20020a056808439600b003c0370c69eamr307850oib.21.1707780475807; Mon, 12 Feb 2024 15:27:55 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWi+s6AcBtZ0faJKmtDS0VKFmvby7nAC38w75GOULRX0y9EwEx7+1J4H9ouW6lZvgCfSXJzdPrc7yhgO3q+HjZI/gPHESEeDPCRuQ/REyCrDkMkJv6LRwKg8Uo1Z/VP7UB+maV2po+cRkt1zHUDomud4hHTEjSVKo1VkbhcHLieCmVmF2Kqam/A9G7dQDDYuHW3eZu0brg+uTKK5AOlNYmeZqIkCCWu/Ru3v84yl6XJsbYnZIzbE/3z1ezjezL0f3AVzKT0610T2R7bCmORiIn8vdONSIM4qGQPMyXP2+xGeKXDtJmU3qIhddqUByKFCCmhPITsVmEHZTV0ZSu8DVluKLVxz1yE5CfaNKZvbiXWUs23Kk2xX6o8l7x0L0Qd833OSHTRbjkeyEpqTy4qxYTtzlOeYpDvj2A4mdKBAdNI1R54Zt5oK87Z4zOTALUFtihDq2C6VC2RX68xgia+zTecW9/zY1uVG4ALoFCXhgqXknkJMDkVxR86w/jjgiv2Vy35XT8Hk8V4JXrFtvGU82GTiScVHa4= Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id pk17-20020a0568704c1100b0021a7a45e0b1sm330141oab.35.2024.02.12.15.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 15:27:55 -0800 (PST) From: David Lechner To: Mark Brown Cc: David Lechner , Martin Sperl , David Jander , Jonathan Cameron , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Alain Volmat , Maxime Coquelin , Alexandre Torgue , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-iio@vger.kernel.org Subject: [PATCH 2/5] spi: move splitting transfers to spi_optimize_message() Date: Mon, 12 Feb 2024 17:26:42 -0600 Message-ID: <20240212-mainline-spi-precook-message-v1-2-a2373cd72d36@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212-mainline-spi-precook-message-v1-0-a2373cd72d36@baylibre.com> References: <20240212-mainline-spi-precook-message-v1-0-a2373cd72d36@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240212_152757_191369_4C02B187 X-CRM114-Status: GOOD ( 27.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Splitting transfers is an expensive operation so we can potentially optimize it by doing it only once per optimization of the message instead of repeating each time the message is transferred. The transfer splitting functions are currently the only user of spi_res_alloc() so spi_res_release() can be safely moved at this time from spi_finalize_current_message() to spi_unoptimize_message(). The doc comments of the public functions for splitting transfers are also updated so that callers will know when it is safe to call them to ensure proper resource management. Signed-off-by: David Lechner Reviewed-by: Jonathan Cameron --- drivers/spi/spi.c | 110 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 42 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 5bac215d7009..8a21fa5bd4b9 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1747,38 +1747,6 @@ static int __spi_pump_transfer_message(struct spi_controller *ctlr, trace_spi_message_start(msg); - /* - * If an SPI controller does not support toggling the CS line on each - * transfer (indicated by the SPI_CS_WORD flag) or we are using a GPIO - * for the CS line, we can emulate the CS-per-word hardware function by - * splitting transfers into one-word transfers and ensuring that - * cs_change is set for each transfer. - */ - if ((msg->spi->mode & SPI_CS_WORD) && (!(ctlr->mode_bits & SPI_CS_WORD) || - spi_is_csgpiod(msg->spi))) { - ret = spi_split_transfers_maxwords(ctlr, msg, 1); - if (ret) { - msg->status = ret; - spi_finalize_current_message(ctlr); - return ret; - } - - list_for_each_entry(xfer, &msg->transfers, transfer_list) { - /* Don't change cs_change on the last entry in the list */ - if (list_is_last(&xfer->transfer_list, &msg->transfers)) - break; - xfer->cs_change = 1; - } - } else { - ret = spi_split_transfers_maxsize(ctlr, msg, - spi_max_transfer_size(msg->spi)); - if (ret) { - msg->status = ret; - spi_finalize_current_message(ctlr); - return ret; - } - } - if (ctlr->prepare_message) { ret = ctlr->prepare_message(ctlr, msg); if (ret) { @@ -2124,6 +2092,8 @@ static void __spi_unoptimize_message(struct spi_message *msg) if (ctlr->unoptimize_message) ctlr->unoptimize_message(msg); + spi_res_release(ctlr, msg); + msg->optimized = false; msg->opt_state = NULL; } @@ -2169,15 +2139,6 @@ void spi_finalize_current_message(struct spi_controller *ctlr) spi_unmap_msg(ctlr, mesg); - /* - * In the prepare_messages callback the SPI bus has the opportunity - * to split a transfer to smaller chunks. - * - * Release the split transfers here since spi_map_msg() is done on - * the split transfers. - */ - spi_res_release(ctlr, mesg); - if (mesg->prepared && ctlr->unprepare_message) { ret = ctlr->unprepare_message(ctlr, mesg); if (ret) { @@ -3819,6 +3780,10 @@ static int __spi_split_transfer_maxsize(struct spi_controller *ctlr, * @msg: the @spi_message to transform * @maxsize: the maximum when to apply this * + * This function allocates resources that are automatically freed during the + * spi message unoptimize phase so this function should only be called from + * optimize_message callbacks. + * * Return: status of transformation */ int spi_split_transfers_maxsize(struct spi_controller *ctlr, @@ -3857,6 +3822,10 @@ EXPORT_SYMBOL_GPL(spi_split_transfers_maxsize); * @msg: the @spi_message to transform * @maxwords: the number of words to limit each transfer to * + * This function allocates resources that are automatically freed during the + * spi message unoptimize phase so this function should only be called from + * optimize_message callbacks. + * * Return: status of transformation */ int spi_split_transfers_maxwords(struct spi_controller *ctlr, @@ -4231,6 +4200,57 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) return 0; } +/** + * spi_split_transfers - generic handling of transfer splitting + * @msg: the message to split + * + * Under certain conditions, a SPI controller may not support arbitrary + * transfer sizes or other features required by a peripheral. This function + * will split the transfers in the message into smaller transfers that are + * supported by the controller. + * + * Controllers with special requirements not covered here can also split + * transfers in the optimize_message() callback. + * + * Context: can sleep + * Return: zero on success, else a negative error code + */ +static int spi_split_transfers(struct spi_message *msg) +{ + struct spi_controller *ctlr = msg->spi->controller; + struct spi_transfer *xfer; + int ret; + + /* + * If an SPI controller does not support toggling the CS line on each + * transfer (indicated by the SPI_CS_WORD flag) or we are using a GPIO + * for the CS line, we can emulate the CS-per-word hardware function by + * splitting transfers into one-word transfers and ensuring that + * cs_change is set for each transfer. + */ + if ((msg->spi->mode & SPI_CS_WORD) && (!(ctlr->mode_bits & SPI_CS_WORD) || + spi_is_csgpiod(msg->spi))) { + ret = spi_split_transfers_maxwords(ctlr, msg, 1); + if (ret) + return ret; + + list_for_each_entry(xfer, &msg->transfers, transfer_list) { + /* Don't change cs_change on the last entry in the list */ + if (list_is_last(&xfer->transfer_list, &msg->transfers)) + break; + + xfer->cs_change = 1; + } + } else { + ret = spi_split_transfers_maxsize(ctlr, msg, + spi_max_transfer_size(msg->spi)); + if (ret) + return ret; + } + + return 0; +} + /** * __spi_optimize_message - shared implementation for spi_optimize_message() * and spi_maybe_optimize_message() @@ -4256,10 +4276,16 @@ static int __spi_optimize_message(struct spi_device *spi, if (ret) return ret; + ret = spi_split_transfers(msg); + if (ret) + return ret; + if (ctlr->optimize_message) { ret = ctlr->optimize_message(msg); - if (ret) + if (ret) { + spi_res_release(ctlr, msg); return ret; + } } msg->pre_optimized = pre_optimized; From patchwork Mon Feb 12 23:26:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13554148 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D5A1C48BC4 for ; Mon, 12 Feb 2024 23:28:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Tf7QB+qgUvEZgJbj29JFYioyNPeOqYpHDzOT/NhngXI=; b=Oz02t5OC1TYMFj 8kXTvd7k9Q5xO7EKxzrw2ryvI8lcST8P+4oPWTmQzx/r7V5XMb3xpxL5R2YQiKZ3H8yEHPr5ZwsX+ DJTeGzGvc974YupcBTX5vmZmpZfevXMIM0tmcMCmQ2IZvcnpn14W6WgYPWXV3+T4dtVMnQu8zJu0m bQkFQMdkMj8Kz/ZvEbjhrZ6yQyzJ4ADodnANC5UCw90UJj9K1ISxsRmRb4IeyrZWeEzvkIi3kwh+e AJubqUb3t8PBliuquHngLwUS8uPcybVeCdl70SIb5YhD9N/kE2drlUO1e3GC1011QnsuQ0nMbNHWX lwqFycO/fFY1XmJj0QWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZfia-00000007GuS-2oQL; Mon, 12 Feb 2024 23:28:08 +0000 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZfiP-00000007GpR-1yaM for linux-arm-kernel@lists.infradead.org; Mon, 12 Feb 2024 23:27:59 +0000 Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3bfff8c4b94so1878146b6e.2 for ; Mon, 12 Feb 2024 15:27:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707780477; x=1708385277; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Wgg1LuqsL+txmWYsX1bhtUmhJO0NDo1N/7wvtQZvjZE=; b=H9LvvYvuC1kEFGiolYqtI43xLOlvAD1gWFMjNaZHBY9Jly8QRyvjaeA9iEIE1HFAbi awgRjLE4c0I0HLkDAL3yEyMO/C6I4YkEfFPJpnZys0RI2QD21So1yUustSUQR5Je0+fO ZOlyKtu6AjkHFx52slZ2lcaC2SWpLpQS0hN/KYRmHpM4Gvi/5IOV5O/SPtCIRqXrWD0+ RH0EE1C/nO3qpbKRmk6Zt4M2zykQsQ6P860oJccBuLj8unEjs1D3EIkF2v1QL2iOL1sM ejSO/ciV7jFJu0FKuvQPVoEmp+sNaXTTnwy9Bkx5sszCzZp2jwqre/C3UofZcvQAjilj 8uiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707780477; x=1708385277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wgg1LuqsL+txmWYsX1bhtUmhJO0NDo1N/7wvtQZvjZE=; b=YzH0d4q3nFTv6AsA325zFbn45ClQRy/pm+tZ4Azj/qxLIk8fHcekRwMQedMag2l8mq ss7ziwiWLATvdLmbRhwJR/9Wt7KhulxLAOmYcwT0LLEW7xZWy0Y18M7oQUROO54O0+2S MPUUiayHcbXWtNuf9wQhlpz6Y1g0PZxiOCIPKmvnU2znkxCMlC8FM6Bv7WYoFcTMbKkr wGjdQ4cBGJuiEgxGfJqS8q9DRw98CEAHXIYkzf6gFFr+dlSSCD79TTI4c7D4hqiKZtwu R15bu7YY+qyA8DPkZ5OLaNnJkjz1rwXVLya7He8HhDiIGci7JK5L3us7qFdpb1cbiPSo LJxA== X-Gm-Message-State: AOJu0Yy55OHUopsJa8slTCzTy1qzNZyZMCM0/iQCCZ+luRdzVSoPxkKZ f12ylRrmaGtqqGiHULVjViBQzf8WEPa0WdzecdivsoZUVaPiYKJqhlUWx64lPL8= X-Google-Smtp-Source: AGHT+IELT5R44AE8dFtwqd5bl+J3kkdcmv8gPvy1/OPh7cRterQinbELctzOchigcD1RHaK44PYXvQ== X-Received: by 2002:a05:6871:20a:b0:219:77b5:efea with SMTP id t10-20020a056871020a00b0021977b5efeamr9731725oad.52.1707780476826; Mon, 12 Feb 2024 15:27:56 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVC+/BMjkbKS/YbJkbW+yDdREhJQUURkROBdWkmvdgRrc4cmkOXx308t4GOolDYtSDjDM4HHnBMbUlxYSyyBsZcnfq1pLOJPF1oWxWk+zFOQY+ub9Z3iflpRl3q/QflYQh9UbrZtPKEPnnZMGKjsTCpXvqIH2flK1o/rPQYVBd3YfK7H7H8RABG1U8jTCfjhFL7DiRSQZNeelRZRZmhWBzsFEUhtOu1564EhwvNzr/gDVT5spJByD6wHVyvHex1sasvrnGLyi2jxwKPJgBwlUK2wXNw5vuat3K3S9Nk2vra0WgOf+JOXZndnhfTDdJgm51LYnCIPmwumgUzRD0jAlbH9vEkRHDdfw5S+8hrGkbFiIWX/SBpaUaaBJiL8cZ54jW8JcRGdKHmm5dQd76JHjX78uoX8NMgKNMpcTxmzHSk2zqGRh8/Xqeaa+fcMSfACkuZ9BVZjuGOUo0ZyHGGGAqhme0nqmaSTsP34XSiGFNloQm86nymrhYFEvhsUyYbchCU8/NnRS6yWt7hJiblyWzf44YQ/3Y= Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id pk17-20020a0568704c1100b0021a7a45e0b1sm330141oab.35.2024.02.12.15.27.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 15:27:56 -0800 (PST) From: David Lechner To: Mark Brown Cc: David Lechner , Martin Sperl , David Jander , Jonathan Cameron , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Alain Volmat , Maxime Coquelin , Alexandre Torgue , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-iio@vger.kernel.org Subject: [PATCH 3/5] spi: stm32: move splitting transfers to optimize_message Date: Mon, 12 Feb 2024 17:26:43 -0600 Message-ID: <20240212-mainline-spi-precook-message-v1-3-a2373cd72d36@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212-mainline-spi-precook-message-v1-0-a2373cd72d36@baylibre.com> References: <20240212-mainline-spi-precook-message-v1-0-a2373cd72d36@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240212_152757_536497_007CA911 X-CRM114-Status: GOOD ( 17.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since splitting transfers was moved to spi_optimize_message() in the core SPI code, we now need to use the optimize_message callback in the STM32 SPI driver to ensure that the operation is only performed once when spi_optimize_message() is used by peripheral drivers explicitly. Signed-off-by: David Lechner --- drivers/spi/spi-stm32.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c index c32e57bb38bd..e4e7ddb7524a 100644 --- a/drivers/spi/spi-stm32.c +++ b/drivers/spi/spi-stm32.c @@ -1118,6 +1118,21 @@ static irqreturn_t stm32h7_spi_irq_thread(int irq, void *dev_id) return IRQ_HANDLED; } +static int stm32_spi_optimize_message(struct spi_message *msg) +{ + struct spi_controller *ctrl = msg->spi->controller; + struct stm32_spi *spi = spi_controller_get_devdata(ctrl); + + /* On STM32H7, messages should not exceed a maximum size set + * later via the set_number_of_data function. In order to + * ensure that, split large messages into several messages + */ + if (spi->cfg->set_number_of_data) + return spi_split_transfers_maxwords(ctrl, msg, spi->t_size_max); + + return 0; +} + /** * stm32_spi_prepare_msg - set up the controller to transfer a single message * @ctrl: controller interface @@ -1163,18 +1178,6 @@ static int stm32_spi_prepare_msg(struct spi_controller *ctrl, !!(spi_dev->mode & SPI_LSB_FIRST), !!(spi_dev->mode & SPI_CS_HIGH)); - /* On STM32H7, messages should not exceed a maximum size setted - * afterward via the set_number_of_data function. In order to - * ensure that, split large messages into several messages - */ - if (spi->cfg->set_number_of_data) { - int ret; - - ret = spi_split_transfers_maxwords(ctrl, msg, spi->t_size_max); - if (ret) - return ret; - } - spin_lock_irqsave(&spi->lock, flags); /* CPOL, CPHA and LSB FIRST bits have common register */ @@ -2180,6 +2183,7 @@ static int stm32_spi_probe(struct platform_device *pdev) ctrl->max_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_min; ctrl->min_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_max; ctrl->use_gpio_descriptors = true; + ctrl->optimize_message = stm32_spi_optimize_message; ctrl->prepare_message = stm32_spi_prepare_msg; ctrl->transfer_one = stm32_spi_transfer_one; ctrl->unprepare_message = stm32_spi_unprepare_msg; From patchwork Mon Feb 12 23:26:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13554147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2527BC4829D for ; Mon, 12 Feb 2024 23:28:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jCnVQHadDw3toWl900SuMjNIk7GOAJIGiQpYdhOvIb8=; b=FHZnrTmiasT4m4 pQJUPjh0D350p8IPDQi4J5mfP2Bvsx/hWkOVp5F1136sfaJ5sse+WupcK4g/Gb9HjgQ/bu6uCUWYq 3tzhxnPrRMYtdoOM7XuVjaQGKQu8tbk9+lP+FW9Yu/I3w23FaO1/kwZK9Qs05VTgvutNJZasTiYtm tgU1OWzQwnbIkiHAYu3jvF1HWUvNpRLY8Yjfv+sa8txAITSspQasFWT2xWQcYzwh4eo8UkSQaD2Ty voWzHqtZxVj9DcAUdjhARPl4tT1DDhIz5KzouDwc+EatVKf36zDm1R8n1eQsjfpsGC4/32kiKqc9/ Lm/CsQ47/EdBNxxBTI6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZfib-00000007Guz-2K8T; Mon, 12 Feb 2024 23:28:09 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZfiR-00000007Gpu-02RP for linux-arm-kernel@lists.infradead.org; Mon, 12 Feb 2024 23:28:00 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-2046b2cd2d3so3049207fac.0 for ; Mon, 12 Feb 2024 15:27:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707780477; x=1708385277; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/CDnTfe6nvQ55r7IK52xXS4oQavI5ZjAWN4vgbC1X28=; b=qlL8ULBTCZlZFwpRoOd7j3qu2AEnnBwo/ftAORBL0TkOB8QoAitCHnXgElKBF9Pozq MUSmoHrh4970aQg5/OCWTGyp8mNDOy3N+DITPLmw95Tmct1iTGw8lofxCaSluaD1kyfc qel+7okD/PUW5gYM0d0wKqxkohIP1x01rLlFB2oDonrcOzwFYATR38Y1BgquA+z2N7vd w00jRCan7KwkbupsAZYtju0DQ0YwYjcNMQ3Zv26rVlLw9T328K/2FAYy8pe1PEc7OvTt 3MH649JQ4AslCWcSJbgALk35lpeSnyZgJE3fOyMD7Q5tGNTHywPju3+s2MpDQOIy0uFq od8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707780477; x=1708385277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/CDnTfe6nvQ55r7IK52xXS4oQavI5ZjAWN4vgbC1X28=; b=bneeZ65a1ukfnallJj7VgxwbB+56HXeqf32IPph1gGLQZx+8b1xhgXGjxVz9LF336i 0OAzqBJ/6NGUkeL/SB1G8GqcGOsqv9nfY/TprGAhccUcYonDPGjmp24uU2ni0HiVcP/w CfCnPyHYMyj/IqjO67Q+ljAAX9cpsfTEZ2fFY/JLCxoHYgXTe9SRW/zf20L/uCbAv8Va e0qj2SC5RNfeGzAgYoqO+MSn1fP++YvbZoite7NzNzaYZZ0fTwwxGpN4hvGgedVnmf0X NoY9rXiJLcXrQJpK9COSkQizWTmxCg+q1WcIm27i9HmKOAJ1ZbsWcyDGQvIaEwtALm7C hyfA== X-Forwarded-Encrypted: i=1; AJvYcCVeDca2e/r2XwqN+4i0RLi6OUlV7J2dPG9iOPP75JxjVVQbzV74hh+aozpYGwcQFRr5Aoqu9l7LMmzdddKU27th+CUtu7bBqSawvphuFDkiEewNUS4= X-Gm-Message-State: AOJu0YyZlhsylup/w6xVY4F/gvX4vXr/P/zYIgMwF+i46gag4mj2IoUR r0BskgowhKeppnEd+0Avq5502GvjvySpz0nroDvBMPqKWErDsYTVe2tHCesihWQ= X-Google-Smtp-Source: AGHT+IFB5BMY94ESp7KJjpv5JdpAU/tpvbuYuXHw2+mNPbkI1Ukm6LHnu4zxTlzwR9ndeIJuVaW/DQ== X-Received: by 2002:a05:6870:c98e:b0:21a:47fc:4bcf with SMTP id hi14-20020a056870c98e00b0021a47fc4bcfmr8244258oab.29.1707780477681; Mon, 12 Feb 2024 15:27:57 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXmAThv/8juXzf9mfLJyIKEgmDljh/Todw+KLIUx9gxl6haVS4PiqGhAXBBBtWjETVMr9PyQP32dLRyjAN/ELx2NsQX+J2CVBwF7rElKMmqRAGrSWTy0bpITdFHUKav9sX2g1m8B0PokQONqbek1aATCqIPG/6OFwYqjxh54DYpJRslItxMr0xXT4k+OBtPQbk2PgR2SVYRDiI51YKp6Jpnm5q2He9K2KJq+ige12IGcyYJeq+AwC2gZ+pPlZijbO9dCkgHWU2QaDWASE5mDCJgc7/+NAkeTE2Sg+nxaXR8yMtF3KBGjGwDYOPJNPzy3s6rFm79s5zxIUH/Hv/qqxwC4pPjC8ta645ynQAqa3XhikPFza9zF6ALx05/XuhBaHG34Nwq3bz2U88bl5uAqU5N00yJRy4KNq3i07oDEtSGUHhtHsSZngncZ99/PaGJxD/5JnvbkC19EZftclOQobnbO8MfFWmK1ghtKjQ7vnSJQ3jQvFbx/KMC+PNXlrmxOucutnfCsfbOmFY7bhwXgoZckU2oVao= Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id pk17-20020a0568704c1100b0021a7a45e0b1sm330141oab.35.2024.02.12.15.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 15:27:57 -0800 (PST) From: David Lechner To: Mark Brown Cc: David Lechner , Martin Sperl , David Jander , Jonathan Cameron , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Alain Volmat , Maxime Coquelin , Alexandre Torgue , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-iio@vger.kernel.org Subject: [PATCH 4/5] spi: axi-spi-engine: move message compile to optimize_message Date: Mon, 12 Feb 2024 17:26:44 -0600 Message-ID: <20240212-mainline-spi-precook-message-v1-4-a2373cd72d36@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212-mainline-spi-precook-message-v1-0-a2373cd72d36@baylibre.com> References: <20240212-mainline-spi-precook-message-v1-0-a2373cd72d36@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240212_152759_082118_09392994 X-CRM114-Status: GOOD ( 24.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In the AXI SPI Engine driver, compiling the message is an expensive operation. Previously, it was done per message transfer in the prepare_message hook. This patch moves the message compile to the optimize_message hook so that it is only done once per message in cases where the peripheral driver calls spi_optimize_message(). This can be a significant performance improvement for some peripherals. For example, the ad7380 driver saw a 13% improvement in throughput when using the AXI SPI Engine driver with this patch. Since we now need two message states, one for the optimization stage that doesn't change for the lifetime of the message and one that is reset on each transfer for managing the current transfer state, the old msg->state is split into msg->opt_state and spi_engine->msg_state. The latter is included in the driver struct now since there is only one current message at a time that can ever use it and it is in a hot path so avoiding allocating a new one on each message transfer saves a few cpu cycles and lets us get rid of the prepare_message callback. Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index ca66d202f0e2..6177c1a8d56e 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -109,6 +109,7 @@ struct spi_engine { spinlock_t lock; void __iomem *base; + struct spi_engine_message_state msg_state; struct completion msg_complete; unsigned int int_enable; }; @@ -499,17 +500,11 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) return IRQ_HANDLED; } -static int spi_engine_prepare_message(struct spi_controller *host, - struct spi_message *msg) +static int spi_engine_optimize_message(struct spi_message *msg) { struct spi_engine_program p_dry, *p; - struct spi_engine_message_state *st; size_t size; - st = kzalloc(sizeof(*st), GFP_KERNEL); - if (!st) - return -ENOMEM; - spi_engine_precompile_message(msg); p_dry.length = 0; @@ -517,31 +512,22 @@ static int spi_engine_prepare_message(struct spi_controller *host, size = sizeof(*p->instructions) * (p_dry.length + 1); p = kzalloc(sizeof(*p) + size, GFP_KERNEL); - if (!p) { - kfree(st); + if (!p) return -ENOMEM; - } spi_engine_compile_message(msg, false, p); spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC( AXI_SPI_ENGINE_CUR_MSG_SYNC_ID)); - st->p = p; - st->cmd_buf = p->instructions; - st->cmd_length = p->length; - msg->state = st; + msg->opt_state = p; return 0; } -static int spi_engine_unprepare_message(struct spi_controller *host, - struct spi_message *msg) +static int spi_engine_unoptimize_message(struct spi_message *msg) { - struct spi_engine_message_state *st = msg->state; - - kfree(st->p); - kfree(st); + kfree(msg->opt_state); return 0; } @@ -550,10 +536,18 @@ static int spi_engine_transfer_one_message(struct spi_controller *host, struct spi_message *msg) { struct spi_engine *spi_engine = spi_controller_get_devdata(host); - struct spi_engine_message_state *st = msg->state; + struct spi_engine_message_state *st = &spi_engine->msg_state; + struct spi_engine_program *p = msg->opt_state; unsigned int int_enable = 0; unsigned long flags; + /* reinitialize message state for this transfer */ + memset(st, 0, sizeof(*st)); + st->p = p; + st->cmd_buf = p->instructions; + st->cmd_length = p->length; + msg->state = st; + reinit_completion(&spi_engine->msg_complete); spin_lock_irqsave(&spi_engine->lock, flags); @@ -658,8 +652,8 @@ static int spi_engine_probe(struct platform_device *pdev) host->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); host->max_speed_hz = clk_get_rate(spi_engine->ref_clk) / 2; host->transfer_one_message = spi_engine_transfer_one_message; - host->prepare_message = spi_engine_prepare_message; - host->unprepare_message = spi_engine_unprepare_message; + host->optimize_message = spi_engine_optimize_message; + host->unoptimize_message = spi_engine_unoptimize_message; host->num_chipselect = 8; if (host->max_speed_hz == 0) From patchwork Mon Feb 12 23:26:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13554149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 058B4C4829E for ; Mon, 12 Feb 2024 23:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=A69Yr7n8pXR6fB7ZujMpa4OtTGguxPns8nllioXl3lU=; b=0xC60T8Bsq6yI0 bUsoeZNZHqu1AjMrRhvdN69fmzzpfjAJh1/j3+kdZyQShyzeHN1YS7KmK0imzSso91BZp+qkk5o0v jqbbS4yvF75yAqhsjhKEdTf9TqK9ArmJ5xD2aFL84rdI9C9PgdXBUhXVbB32biWFYLkBAf8eJHgux 8AsM4vNJS+4ndIyF8VWdHf1xehXlArszt2kuKsj4LnROZXJpA795G1NW5nC8aqmSLm+4ak+ySntIQ fgtlQdFc+rLCOpg1SxedZJ8wH7fTNDfLSnh3xmz8Scg1/FBUjIIiG8JZxZfEAmt3EqU/0P6MS0mX9 Eoyi0sgn/dqRv5h4dTPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZfic-00000007Gvb-1cGC; Mon, 12 Feb 2024 23:28:10 +0000 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZfiR-00000007GqV-3lQY for linux-arm-kernel@lists.infradead.org; Mon, 12 Feb 2024 23:28:01 +0000 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-2185739b64cso2470738fac.0 for ; Mon, 12 Feb 2024 15:27:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707780478; x=1708385278; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NPDb6hVtEhiljZHBpIuJ6/eQfkiQhhMGNrzlPsHzoEA=; b=QhhCiOFGhLXSTc9lBUyG2vGRi6B/1m5VYCgWkGLR53i2CskULDPc2sgdRxpFgRKusU fZpZwQCvUuxa2YDa+m98sYPbDTB/sOm+KRqthH0R2LfgjJN3ZWCDJ9c6z6WFPdQ+muBw GKWf8A9tkQlF6j+wV2LZuPmmKLnN+MRDCpc/TefDaEFeamKHum0YfrvDMC7Nlewuejm7 OuYppOY1FdpatokLtGg17uhf/EEOpnXMPtGNg3LKmbwmXPoG93Hr9yDEcgXBckcKFOqA 8LUDmh/+fkSofI3m+67tB6RJ4+ZDLVNk4VJoL7iy4TWKBbx5KiIg8WaPKf3fDJ5ScIvS mhNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707780478; x=1708385278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NPDb6hVtEhiljZHBpIuJ6/eQfkiQhhMGNrzlPsHzoEA=; b=H1dD4R5Tc9g91Iu7mSPuJBrUy+qcd8y+yNhIUQh8ESsWe9JXM3m+JI6JlNNumnc4FY u7lOQ3Ak+i3jBmGqH7+RLGjdUKLDvrS9O1M2PWfkxJyMPiUTaGj1oE5EhjFHEr7DE4Rp bl53fSLXQDUIEh2c+Rn/QOzif+HdWtm78rJDFT6aZO7GurKVlG61fMsw7zmyn5QLc2GO 6MFibcENOwWeuYTrNS+EMVd5nL5gItcoW/xt6JkGj4DXNYAzgDmBfohgRLQjupyOdqrD /8nwIImrGjba2tCVdr9u0b5wJxpJz6QlzMZKkqa80rLHH6h2+FES4ZnRVWnclQZnZOeF KWUw== X-Forwarded-Encrypted: i=1; AJvYcCV046OnBUiA44pCPUtmQDCFBg3VkrbBBzkWjgWtAqS1LY9TEAE5iiW6px1wUhq+yc2dX/qyRt9ENjQgxD2+TmsLMiP8vt4EIv74VmslrDtU6dMcqI4= X-Gm-Message-State: AOJu0YyzNnIyvcW5xkpVP66VPEQ4oR9UADgcCkOWAFd5El7Gqizf7l/y RhRq1QXs6FJcHdKC7r5NuH0JOpKkwDfIc30C+NFB6WLD/FOnKj4VeUHoxo1J+IA= X-Google-Smtp-Source: AGHT+IH9erOJCDaYbmQDWF2K81JN0GKgiq54irJeN5yLR/tg4FUJhNIMhrIkifdGOu4oAL5TJZcC0Q== X-Received: by 2002:a05:6871:5c48:b0:219:c8ea:ecfd with SMTP id os8-20020a0568715c4800b00219c8eaecfdmr10850888oac.15.1707780478627; Mon, 12 Feb 2024 15:27:58 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCU/sChhyo7/S+ePAw+fUTZa4Fa+c+iizdHVFXCth9k0UVOZs5C2WlgRtbyufn7EOEddQq5CkoNbtZtOlCdXpnzPXFGf760G/g1P4jT3D2BZM851R0PtrDuAkl06AR06eLUGEITPtV1UK0F65cIlm7ccxGgZLoQPiwMwsyuL5+SNLnL+D8pJj8ktyPxbGY2KEjPfVcWo3aru0369a6RMQJWdab/0ibpad8aRXTQjKE2CY2ZgZKHfkTlJl+JJ28mwL2pNejLLTSSa4B9k3zuc4nDciUgdcuwoMeHfxozDYXDiKfMYPfC3BEJVdK3sFLpvz5Z2Y6K087Zk6+hLDN3ceLH0IZuGlif8dpiVSs2aw4qqhk80aOpu703oSYX2fa2Zy04rdtzhykVvL9yVQLic9YrrrC+2SmVp0ygbRulhgWff+wuEJGaDvt46o+YtUGYq2F+yoofZRk2mrtpYLyyJ/fhAMTQctHXdcSryftOnYMqxIPwVdTitM4q3WhWgmLLWBe+3CCel/7DU5WydgyihQ23lXKvMWqg= Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id pk17-20020a0568704c1100b0021a7a45e0b1sm330141oab.35.2024.02.12.15.27.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 15:27:58 -0800 (PST) From: David Lechner To: Mark Brown Cc: David Lechner , Martin Sperl , David Jander , Jonathan Cameron , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Alain Volmat , Maxime Coquelin , Alexandre Torgue , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-iio@vger.kernel.org Subject: [PATCH 5/5] iio: adc: ad7380: use spi_optimize_message() Date: Mon, 12 Feb 2024 17:26:45 -0600 Message-ID: <20240212-mainline-spi-precook-message-v1-5-a2373cd72d36@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212-mainline-spi-precook-message-v1-0-a2373cd72d36@baylibre.com> References: <20240212-mainline-spi-precook-message-v1-0-a2373cd72d36@baylibre.com> MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240212_152759_970302_666F3FCD X-CRM114-Status: GOOD ( 16.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This modifies the ad7380 ADC driver to use spi_optimize_message() to optimize the SPI message for the buffered read operation. Since buffered reads reuse the same SPI message for each read, this can improve performance by reducing the overhead of setting up some parts the SPI message in each spi_sync() call. Signed-off-by: David Lechner --- drivers/iio/adc/ad7380.c | 52 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c index abd746aef868..5c5d2642a474 100644 --- a/drivers/iio/adc/ad7380.c +++ b/drivers/iio/adc/ad7380.c @@ -133,6 +133,7 @@ struct ad7380_state { struct spi_device *spi; struct regulator *vref; struct regmap *regmap; + struct spi_message *msg; /* * DMA (thus cache coherency maintenance) requires the * transfer buffers to live in their own cache lines. @@ -231,19 +232,55 @@ static int ad7380_debugfs_reg_access(struct iio_dev *indio_dev, u32 reg, return ret; } +static int ad7380_buffer_preenable(struct iio_dev *indio_dev) +{ + struct ad7380_state *st = iio_priv(indio_dev); + struct spi_transfer *xfer; + int ret; + + st->msg = spi_message_alloc(1, GFP_KERNEL); + if (!st->msg) + return -ENOMEM; + + xfer = list_first_entry(&st->msg->transfers, struct spi_transfer, + transfer_list); + + xfer->bits_per_word = st->chip_info->channels[0].scan_type.realbits; + xfer->len = 4; + xfer->rx_buf = st->scan_data.raw; + + ret = spi_optimize_message(st->spi, st->msg); + if (ret) { + spi_message_free(st->msg); + return ret; + } + + return 0; +} + +static int ad7380_buffer_postdisable(struct iio_dev *indio_dev) +{ + struct ad7380_state *st = iio_priv(indio_dev); + + spi_unoptimize_message(st->msg); + spi_message_free(st->msg); + + return 0; +} + +static const struct iio_buffer_setup_ops ad7380_buffer_setup_ops = { + .preenable = ad7380_buffer_preenable, + .postdisable = ad7380_buffer_postdisable, +}; + static irqreturn_t ad7380_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct ad7380_state *st = iio_priv(indio_dev); - struct spi_transfer xfer = { - .bits_per_word = st->chip_info->channels[0].scan_type.realbits, - .len = 4, - .rx_buf = st->scan_data.raw, - }; int ret; - ret = spi_sync_transfer(st->spi, &xfer, 1); + ret = spi_sync(st->spi, st->msg); if (ret) goto out; @@ -420,7 +457,8 @@ static int ad7380_probe(struct spi_device *spi) ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, iio_pollfunc_store_time, - ad7380_trigger_handler, NULL); + ad7380_trigger_handler, + &ad7380_buffer_setup_ops); if (ret) return ret;