From nobody Mon Jun 15 16:34:34 2026 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D88529B78B for ; Sat, 11 Apr 2026 22:13:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775945639; cv=none; b=Pl5utEexO0VZ1ue9U97dbRhxwJy92JDjG1khSHL0eyhHKIvqGpX0jpED7IieCWkTNq3Dn1+1bTRZqYJT/F5M0Bg1ZSvzDI3ALAbnEcdJFzYYt3Fp75srGaZXG1b4XA7S8+HNrpzZGt5ic5rmjUV7KmTnjsHfTx59wbaFo8L3hxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775945639; c=relaxed/simple; bh=trRkemWp5dWHUHDUM9KMQQolEfmLtt2uNpgKuvqDYfw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=rc4uJUB/eANGHyu3+ZrskDHRKpuuB6HQKydToUTxMQr9buo/QahUcT9di3Etrp8TONrDt6YprnNls2tQjU+L/28yw0eSHZBKt9kta0M1bZxsvP7cY76y5Q/71l+yn8IxcvddRMuYjtYJR/axqwj+ndSPoTLO5rGarbln/86HVJM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20251104.gappssmtp.com header.i=@baylibre-com.20251104.gappssmtp.com header.b=AgvyN4DR; arc=none smtp.client-ip=209.85.210.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20251104.gappssmtp.com header.i=@baylibre-com.20251104.gappssmtp.com header.b="AgvyN4DR" Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-7d7fdb922a5so2653369a34.3 for ; Sat, 11 Apr 2026 15:13:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20251104.gappssmtp.com; s=20251104; t=1775945636; x=1776550436; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=LmaKQJnZeZ/TFIGRnUXCFPtfqzkxWm8tTHvrFKsphJ8=; b=AgvyN4DRySuMgI+q6bm0UbSCFapiwrUshkVxDqjbQ0HGa3D9q8ZArxPFwpUpOfyPzg yuL/bMGDOFJ3jmI1Qd4RDZjBNEJ9mvaHTo26L+XyHYm5uJowMxsvED/L5VTJje2Z4Fv8 V8kM8VGRVpjvL+XVDWBYyhWPGhDWuyP5vutFZWRVl6BaMvbM5dSv3ehJkvP/WOCOee8U RtNibzf5lwWt5OAprLjQR9C2j0s4HPc6uWxUBuAzMJaEq0ypRTEo9+bCMh50GrLdVr8Z lx8C3PlfxuQEAd/6+UgKdrllcTjGGwm6+Xr28Uma/imZb734KyBmclYik0ULLSf734cd iZzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775945636; x=1776550436; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LmaKQJnZeZ/TFIGRnUXCFPtfqzkxWm8tTHvrFKsphJ8=; b=cf1RmJRlOfM94+XEt+aoNlcyeM79jj6qvpDNnrhCNKRsDtmBUBnKmKdiG/Av4YdkO9 9jAYvI0VQ0S1qyuVAQT9Epyf8JdkI1v5QB4OKwCeR5uI/PLUWe4HgUmllqVfsQPZ5CdD pSTTSyQ+Hv2iMVTfxdngscCuntb6S6K4SduAuFpEeYKcfuHW0VmKeaNRAuOAf/K1wn3E Fo3ZzVuzpROTOV4+yCEWc/wqOrN7+e4zimYY1fBe9S6UUQYsvkv7piDlmLJ2LfaWbnew SEcSyOfv3tnaLzh/9uakgv26Qo2bVFHevZK7ySoD0iMw9ueD8/cjss3/7MvAn1dZc0FB oD/w== X-Forwarded-Encrypted: i=1; AJvYcCXX/KLXlyIa8nq4XgedXp32/QDk0giUveQPU55Rud9yodr0WnplSg1ZPv/xtcH/BQIFkv7eTXc4nf2wMvo=@vger.kernel.org X-Gm-Message-State: AOJu0YyDuKS4oInN3KFc5WPwp2InShQSkx5IFcF8pV+GEHQlPtohzOiv vD6D/riU52YgG/Dtrpk66w/cz0Lz0DsmUFt9eIKuzw7p8vPI65kzIZlRBh2btb/Y92beYExHJEu ajhS0 X-Gm-Gg: AeBDiev279ya+968J9vv5MbgAKupZdnJ8uX7EF0sT4UZactoCX3aY+8rm4Ca1tuIzwy n+nk0pQ0msklZq6N4e/oVkPxh5ugr6WxAnEgIC4sdXCmAYEvHXzNPKGwPLM0hmxDa0rP09leLLe VydWZAn/2nGhz21DmW3+v5HacsZGkexOTrGQP+nMeLNA7Vz+3j+Er6geRrU9dD3155uoSeeOSbn RzEbcNFc3ofBnhIkDpwzRepv03uF2SaMcIltvulZH5h+xM26T28rx6zSSD3Wc5mP7uP79T5NE9E R3qW/xx32Ijs8s4C/7WGzoisYa4NF9kDqsDzRZT4inLWeziMYHxo8djFfN3fkmVpBN3Y6o3WesI T8QP/dlDtzipxgbG0GTV2NaxQYcBDhl5qUIZHdCjB88X/fMP1zk2lewMF3AKGxM3zY+j41NBf0S aVVhGoHjrrwebQrcN3LgIw+ccpH72Q X-Received: by 2002:a05:6830:4c0c:b0:7d9:b2ba:a35d with SMTP id 46e09a7af769-7dc27e878a0mr5021569a34.29.1775945636089; Sat, 11 Apr 2026 15:13:56 -0700 (PDT) Received: from [127.0.1.1] ([2600:8803:e7e4:500:d2e5:c81c:5b23:fe55]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7dc26965485sm5002303a34.22.2026.04.11.15.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 15:13:55 -0700 (PDT) From: David Lechner Date: Sat, 11 Apr 2026 17:13:33 -0500 Subject: [PATCH] iio: adc: ti-ads7950: use spi_optimize_message() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260411-iio-adc-ti-ads7950-spi-optimize-msg-v1-1-617766ef2e38@baylibre.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/02OQQ6CMBBFr0K6drQgoCXGeA/jopYpjqGAnWKIx rtbxYWryUv+/P+egtETsqiSp/B4J6a+i5AuEmEuumsQqI4sMpmVMk9TIOpB1wYCxcMbVUjggaA fAjl6IDhuoFRZrkpVm3yzFrFp8Ghp+q4cTzPzeL6iCZ/qX8LjbYzzYY6Js2YE0ztHoUpa6sYJO pzCymkO6D8/Dpn1V7BKdrOfLP69rDbYkg1wL0BCatVWYr02VuGhcZraZazfi9Pr9QZsHR4zBgE AAA== X-Change-ID: 20260411-iio-adc-ti-ads7950-spi-optimize-msg-6924969dc473 To: Jonathan Cameron , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4299; i=dlechner@baylibre.com; h=from:subject:message-id; bh=trRkemWp5dWHUHDUM9KMQQolEfmLtt2uNpgKuvqDYfw=; b=owEBbQGS/pANAwAKAcLMIAH/AY/AAcsmYgBp2seciyJONTRR+SWR9ycmv6qPOpsPAWXYG/6VQ hgbAkjSLT2JATMEAAEKAB0WIQTsGNmeYg6D1pzYaJjCzCAB/wGPwAUCadrHnAAKCRDCzCAB/wGP wIpYB/9ItC4NJ1ddVa/bULT8HX2L4RkXjyQAInZN+geDrMphH6ZtphI1L6r2oZ1gses9DubaFzz 8kxzIPZs9uUB9wQj8Tv9l+gVpmVVvnEbn+Fzi6jzH7AdrcB8HUoaqU/gU+g+gqoqlGYjFclLhhx J/Lj80rJwsVIPwZLJ84y5b+DtV9hA7cIhJqATu33/pQJiqN50w0qvx33w0kaFTafd3BZbo6gJtz TmILmaQH59OPwwnCynStp5eYsQSD3e0yQuRPwKS2crAd7XBPHyvxZXmcLPPoN8y5exgAmIAHoRX mJ4ZbKssFwqTeoT9d0B15pyKXLHY9LbGtwoJyaoEbiPNdudo X-Developer-Key: i=dlechner@baylibre.com; a=openpgp; fpr=8A73D82A6A1F509907F373881F8AF88C82F77C03 Use spi_optimize_message() to reduce CPU usage during buffered reads. On hardware with support for SPI_CS_WORD, this reduced the CPU usage of the threaded interrupt by about 5%. On hardware without support, this should reduce CPU usage even more since it won't have to split the SPI transfers each time the interrupt handler is called. The update_scan_mode callback hand to be moved to the buffer preenable callback since the SPI transfer mode can't be changed after spi_optimize_message() has been called. (The buffer postenable callback can't be used because it happens after the trigger is enabled, so the SPI message needs to be optimized before that.) The indent of ti_ads7950_read_raw is changed since there is no longer anything else in the struct to align with since we removed ti_ads7950_update_scan_mode. Signed-off-by: David Lechner --- drivers/iio/adc/ti-ads7950.c | 65 +++++++++++++++++++++++++---------------= ---- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c index 882b280d9e0b..39a074bce6d5 100644 --- a/drivers/iio/adc/ti-ads7950.c +++ b/drivers/iio/adc/ti-ads7950.c @@ -267,31 +267,6 @@ static const struct ti_ads7950_chip_info ti_ads7961_ch= ip_info =3D { .num_channels =3D ARRAY_SIZE(ti_ads7961_channels), }; =20 -/* - * ti_ads7950_update_scan_mode() setup the spi transfer buffer for the new - * scan mask - */ -static int ti_ads7950_update_scan_mode(struct iio_dev *indio_dev, - const unsigned long *active_scan_mask) -{ - struct ti_ads7950_state *st =3D iio_priv(indio_dev); - int i, cmd, len; - - len =3D 0; - for_each_set_bit(i, active_scan_mask, indio_dev->num_channels) { - cmd =3D TI_ADS7950_MAN_CMD(TI_ADS7950_CR_CHAN(i)); - st->tx_buf[len++] =3D cmd; - } - - /* Data for the 1st channel is not returned until the 3rd transfer */ - st->tx_buf[len++] =3D 0; - st->tx_buf[len++] =3D 0; - - st->ring_xfer.len =3D len * 2; - - return 0; -} - static irqreturn_t ti_ads7950_trigger_handler(int irq, void *p) { struct iio_poll_func *pf =3D p; @@ -375,8 +350,42 @@ static int ti_ads7950_read_raw(struct iio_dev *indio_d= ev, } =20 static const struct iio_info ti_ads7950_info =3D { - .read_raw =3D &ti_ads7950_read_raw, - .update_scan_mode =3D ti_ads7950_update_scan_mode, + .read_raw =3D &ti_ads7950_read_raw, +}; + +static int ti_ads7950_buffer_preenable(struct iio_dev *indio_dev) +{ + struct ti_ads7950_state *st =3D iio_priv(indio_dev); + u32 len =3D 0; + u32 i; + u16 cmd; + + for_each_set_bit(i, indio_dev->active_scan_mask, indio_dev->num_channels)= { + cmd =3D TI_ADS7950_MAN_CMD(TI_ADS7950_CR_CHAN(i)); + st->tx_buf[len++] =3D cmd; + } + + /* Data for the 1st channel is not returned until the 3rd transfer */ + st->tx_buf[len++] =3D 0; + st->tx_buf[len++] =3D 0; + + st->ring_xfer.len =3D len * 2; + + return spi_optimize_message(st->spi, &st->ring_msg); +} + +static int ti_ads7950_buffer_postdisable(struct iio_dev *indio_dev) +{ + struct ti_ads7950_state *st =3D iio_priv(indio_dev); + + spi_unoptimize_message(&st->ring_msg); + + return 0; +} + +static const struct iio_buffer_setup_ops ti_ads7950_buffer_setup_ops =3D { + .preenable =3D ti_ads7950_buffer_preenable, + .postdisable =3D ti_ads7950_buffer_postdisable, }; =20 static int ti_ads7950_set(struct gpio_chip *chip, unsigned int offset, @@ -573,7 +582,7 @@ static int ti_ads7950_probe(struct spi_device *spi) =20 ret =3D devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL, &ti_ads7950_trigger_handler, - NULL); + &ti_ads7950_buffer_setup_ops); if (ret) return dev_err_probe(&spi->dev, ret, "Failed to setup triggered buffer\n"); --- base-commit: 66672af7a095d89f082c5327f3b15bc2f93d558e change-id: 20260411-iio-adc-ti-ads7950-spi-optimize-msg-6924969dc473 prerequisite-message-id: <20260405-ti-ads7950-facelift-v5-0-1f980ed3cf9e@gm= ail.com> prerequisite-patch-id: 0606a4fc48f3fe7bf5f9156c93f434050898c309 prerequisite-patch-id: 1bb68480bcba4198e8b18b3ca7d8a0980fdd4bdd prerequisite-patch-id: 551390239268e710bdb14ae2629e287fa751cb62 prerequisite-patch-id: 1a5f202fc1b16f2aee0368cccda2a521a9c8af19 Best regards, -- =20 David Lechner