Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1646680rdb; Tue, 20 Feb 2024 02:42:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVpSxPg2MWDtZ/IrlJFbX5O4iJWDiXmG3IVJj9S4YRHbJEeFLU5YzKAsvvjAva0+NtUUZCDsdA+i+htRpeDHMh8MD14xJG/CohfXHmyoQ== X-Google-Smtp-Source: AGHT+IEb+8zxUmBAW30pV/Bgv0uC0mcNAKBADzjyDxw5xFyyvXU+0Y321j0iC/dO8weUsFEfPjcB X-Received: by 2002:ac8:5401:0:b0:42d:e52e:d86f with SMTP id b1-20020ac85401000000b0042de52ed86fmr9931855qtq.46.1708425724496; Tue, 20 Feb 2024 02:42:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708425724; cv=pass; d=google.com; s=arc-20160816; b=hCIRUK+984illlts9VpuYWKs5M3505DzbR02sTnHX3QmJy5VrpAh7XIyc/Q7+64paU q1c9TQyQ9XVxbiXrdYdq2rlaKpUeL/1OcEtM8GkhsinPV+Y9hLwnB56kgHocnB/rHKp4 3ocFQgUfDob+W2rG+C24ZCb44P0QPMHmohOTSt0u/KQJDGfSSzcPgFr6XvG8i9d8Ytbv moUflRwEq+8yhBKTbs9Sr/+1CCQuq6jP/ZkvD/Or2i9iCo98PdebG2ZTL3pcOjI5DEJX o7EedGotQoahyUpb3Ei44oDUv8fNKFMcMLCrL1v7Np8ED3HfFPimPym4YAQ7jVPRp3EP 6qmA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id:dkim-signature; bh=1ffOH1itwl3Z/6WXt9S5kShMdP0MfLLwhwAMSm7CnAc=; fh=/izxGe91tHIEqTPmNDIZ7+37yeQ3RFA3PphR8lQAxRo=; b=AE4bmHrOOPXz3boslx0YwqQJwYKQFVOfPdzurP+A0QnL9c7WwFlw18sQGsUzdBCkQ6 veMw/LUaVAcHFdHDNB6+rEVABNu56kql48RvmhoBIfwB1BF+HqgGZwFsHsf1sLa6TjPy xz7Nurx3zU/aQp4dIaMy/QsOovu0RLk7UEygA24DsVidKWhwqr/MpYrpPn1xwxZR52/1 xntNqCjKDDQ7AArNH+4fgsHCZV4oxkWaXOF/T/OAtmSiOfR5V0lCwTh4uW01EiCuIeMW qs080oyqPEgeTNcJmBuu2xM4stj4yNbdTJ+yQQwoXGANce9mWkgCKcgFnZ3Bpq5vMgV2 Jorw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Uoq1mVIm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-72843-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72843-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i8-20020ac871c8000000b0042c68a9d728si7848010qtp.516.2024.02.20.02.42.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 02:42:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72843-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Uoq1mVIm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-72843-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72843-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E000A1C216EA for ; Tue, 20 Feb 2024 10:42:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 23B18657DE; Tue, 20 Feb 2024 10:41:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Uoq1mVIm" Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 751F160EE5; Tue, 20 Feb 2024 10:41:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708425694; cv=none; b=Q7wMBHowJluqAT0KhjB7UzDNa6z0q8FK0pRjFCUwSkDqx4Hg6OcF7Enkh5HL4Wwp23msrRA3SP+oFWfDDwJUlvVNcke+gY/gHJBHJ/1zcG4uNkLJJnACpOWtirbrPM7jVUt5d8BPbEi+sXRU4dj3aFromcrk2DCMDHxLiQTZFd8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708425694; c=relaxed/simple; bh=/B7Oqp6BZc9jTnP4hA6macWM61pXhIAWVi5ZSwt7fQo=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=qhn1RqRCUa3hXq0BJpnkTCRWHhM6M6Uxtg2rTIS9QHz1ewvlC9kuC7BL6ZP1daWrrM03RVzpbOAMU9jMVO1S+MSJDdvEls1Het2p+Dsehwd82eP4aQcTyYsrfkZ8sLP+lssVBgdKnYeOBp/tMuOApWwxVzWAD8GL8kwRdNVI7L8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Uoq1mVIm; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-412718a8ea7so155495e9.3; Tue, 20 Feb 2024 02:41:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708425691; x=1709030491; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=1ffOH1itwl3Z/6WXt9S5kShMdP0MfLLwhwAMSm7CnAc=; b=Uoq1mVIm62ed0/mg5pyshE0PwPbI+xjrmetFE4fvIUKB+qPUMevdIocw8Ri63/unLO xe7UFf4tDutcPE8ujd4DdEBHSxryFFnhwxXnz5zyhALMdNNHqfcNaPn7oxLJxKYYYGA7 HTat9MvyXhLfU8t9+QMNws+XW5MVHsvnAk9YJvv6IRmFNKTlNz5Jo/3hjHwpuaXB6FB/ 4nPGehWEikU16alESPFU/vlcpi62OvNGgAcB5Ye1+BESTfsa1B3WQh4ooKFKgTL5nKco +xr4UWLX/7K2uenUaCaspEgQE+q9vFLYsnm2ORSYDRj82R+hNpmii9JAo9KwyFshUnrO h/cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708425691; x=1709030491; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1ffOH1itwl3Z/6WXt9S5kShMdP0MfLLwhwAMSm7CnAc=; b=epggdKV8i08VI0pwQ51XtRdYX0F5Rs6hSgaBvPywMAR3SuYZm/j9Dg/r1FyglDLFH5 knUZJcqbURWc/wjrUTpZslP/FiV177pUiuwiza68gfsRQWvbSpnHxEiL+4judNjHpYTw m0gOd1l75W7HWZRY2mnzcN2ovrphHgYQiPQpiETdiL5YHbREhJDVzdF7/piSkYopE/gr bJd1oZKeLkXUod3n9pK/q+EfE/eA4N/m6w2+eDM8Rc5AIPvP6SKvuHHgrlh5I6XalgEH RZc6fBXJduvfqq/mX0xLmXmVPQM/w1mZXoMcerutuHN1i3+F4cW5xMxurTCYGZpRoSfV 87MA== X-Forwarded-Encrypted: i=1; AJvYcCWkr0JNQUfuiJNpAAAiuSwP2VReh1QaP6amTW0KbmoOyDO1RBulIK6n/zGTPE5kPvR5fDHOMWjtQAX4hHLstoY1xDYz8wTSlhOr3aDG6lPjaCUMfYgreMyIApIfb1NVEnz1M0aXOLDHSvxxQDONAj/EoRUkIl2QeotCSJtGtY8HSZ7o X-Gm-Message-State: AOJu0YzFYbueD+AHP/sFshCutj5tHdz+PguEqzeljQwf6NEjhckcVd51 ma2yjcbW3sotRWKsM1QgN4mmA+6iMmVaLhsBPSRImICx4BHxWEGO X-Received: by 2002:a05:6000:1a8a:b0:33d:3a00:554d with SMTP id f10-20020a0560001a8a00b0033d3a00554dmr6111440wry.8.1708425690688; Tue, 20 Feb 2024 02:41:30 -0800 (PST) Received: from ?IPv6:2001:a61:3456:4e01:6ae:b55a:bd1d:57fc? ([2001:a61:3456:4e01:6ae:b55a:bd1d:57fc]) by smtp.gmail.com with ESMTPSA id b7-20020adfe647000000b0033b406bc689sm13193409wrn.75.2024.02.20.02.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 02:41:30 -0800 (PST) Message-ID: <0ec567d7df3632a9c8104485c4207a47e159fdb9.camel@gmail.com> Subject: Re: [PATCH v2 5/5] iio: adc: ad7380: use spi_optimize_message() From: Nuno =?ISO-8859-1?Q?S=E1?= To: David Lechner , Mark Brown Cc: Martin Sperl , David Jander , Jonathan Cameron , Michael Hennerich , Nuno =?ISO-8859-1?Q?S=E1?= , 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, Julien Stephan Date: Tue, 20 Feb 2024 11:41:29 +0100 In-Reply-To: <20240219-mainline-spi-precook-message-v2-5-4a762c6701b9@baylibre.com> References: <20240219-mainline-spi-precook-message-v2-0-4a762c6701b9@baylibre.com> <20240219-mainline-spi-precook-message-v2-5-4a762c6701b9@baylibre.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.3 (3.50.3-1.fc39) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Mon, 2024-02-19 at 16:33 -0600, David Lechner wrote: > 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. >=20 > Signed-off-by: David Lechner > --- >=20 Reviewed-by: Nuno Sa > v2 changes: > - Removed dynamic allocation of spi xfer/msg > - Moved spi message optimization to probe function > - Dropped buffer pre/post callbacks >=20 > =C2=A0drivers/iio/adc/ad7380.c | 36 ++++++++++++++++++++++++++++++------ > =C2=A01 file changed, 30 insertions(+), 6 deletions(-) >=20 > diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c > index abd746aef868..6b3fd20c8f1f 100644 > --- a/drivers/iio/adc/ad7380.c > +++ b/drivers/iio/adc/ad7380.c > @@ -133,6 +133,9 @@ struct ad7380_state { > =C2=A0 struct spi_device *spi; > =C2=A0 struct regulator *vref; > =C2=A0 struct regmap *regmap; > + /* xfer and msg for buffer reads */ > + struct spi_transfer xfer; > + struct spi_message msg; > =C2=A0 /* > =C2=A0 * DMA (thus cache coherency maintenance) requires the > =C2=A0 * transfer buffers to live in their own cache lines. > @@ -236,14 +239,9 @@ static irqreturn_t ad7380_trigger_handler(int irq, v= oid *p) > =C2=A0 struct iio_poll_func *pf =3D p; > =C2=A0 struct iio_dev *indio_dev =3D pf->indio_dev; > =C2=A0 struct ad7380_state *st =3D iio_priv(indio_dev); > - struct spi_transfer xfer =3D { > - .bits_per_word =3D st->chip_info->channels[0].scan_type.realbits, > - .len =3D 4, > - .rx_buf =3D st->scan_data.raw, > - }; > =C2=A0 int ret; > =C2=A0 > - ret =3D spi_sync_transfer(st->spi, &xfer, 1); > + ret =3D spi_sync(st->spi, &st->msg); > =C2=A0 if (ret) > =C2=A0 goto out; > =C2=A0 > @@ -335,6 +333,28 @@ static const struct iio_info ad7380_info =3D { > =C2=A0 .debugfs_reg_access =3D &ad7380_debugfs_reg_access, > =C2=A0}; > =C2=A0 > +static void ad7380_unoptimize_spi_msg(void *msg) > +{ > + spi_unoptimize_message(msg); > +} > + > +static int devm_ad7380_setup_spi_msg(struct device *dev, struct ad7380_s= tate *st) > +{ > + int ret; > + > + st->xfer.bits_per_word =3D st->chip_info->channels[0].scan_type.realbit= s; > + st->xfer.len =3D 4; > + st->xfer.rx_buf =3D st->scan_data.raw; > + > + spi_message_init_with_transfers(&st->msg, &st->xfer, 1); > + > + ret =3D spi_optimize_message(st->spi, &st->msg); > + if (ret) > + return dev_err_probe(dev, ret, "failed to optimize message\n"); > + > + return devm_add_action_or_reset(dev, ad7380_unoptimize_spi_msg, &st->ms= g); > +} > + > =C2=A0static int ad7380_init(struct ad7380_state *st) > =C2=A0{ > =C2=A0 int ret; > @@ -411,6 +431,10 @@ static int ad7380_probe(struct spi_device *spi) > =C2=A0 return dev_err_probe(&spi->dev, PTR_ERR(st->regmap), > =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 "failed to allocate register map\n"); > =C2=A0 > + ret =3D devm_ad7380_setup_spi_msg(&spi->dev, st); > + if (ret) > + return ret; > + > =C2=A0 indio_dev->channels =3D st->chip_info->channels; > =C2=A0 indio_dev->num_channels =3D st->chip_info->num_channels; > =C2=A0 indio_dev->name =3D st->chip_info->name; >=20