From patchwork Mon Feb 19 22:33:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13563149 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 57438C48BC3 for ; Mon, 19 Feb 2024 22:35:34 +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=kLhdTvXS1yLFX93jelSCVLIeZbhTTjaD1vo1ryBHrJM=; b=W5D5/A8NHc2XoG Uy3yjxnqzZsKX0mnEpQRh4bLflHC93hR/b0TVG71OrdEUCmexV7C5/MN1wad7w34YuUKyS8G6VAzK 1SEOatssznMTSPBfrrfv9fOcECM6Cd+dowd4kady1h9Xq06qq7L4xZoK3v38/+qvef1KZlM2w2wyI SYRlpLpAX+1uhPDdueUD0jS0kmO02iRgp+n8wnGKUZzEGuK1AeaIi/MYwjsRSEoiRMmHyRIMdWa0O sKPPir7rqtydKABoLUCm+5NJXyeRIseN/RVs7gI09oy6DfVSeVwpKXpy1Ro2S1j49ohc7d/9Sc3Lj FRsmcWrmfWhesvpbbbLw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcCEJ-0000000CP7U-14DX; Mon, 19 Feb 2024 22:35:19 +0000 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcCE1-0000000COri-3k1k for linux-arm-kernel@lists.infradead.org; Mon, 19 Feb 2024 22:35:03 +0000 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-6e125818649so2465611a34.1 for ; Mon, 19 Feb 2024 14:35:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1708382101; x=1708986901; 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=nguAE7f5YcWI/h5umYjj7eHdUyvOtkK6QQpK6mXXbx4=; b=xI0GQJlX7zR0BgiFYcWPbiynY/El44exEE4f0jvkzpjlPB10ddCCqMwlbaIzdocebH Uv3KI+iXA4uhaa9lYbrqcqgH9/aq93851NyY1F8mgcrPjl3/SgHhpTKE4x1YPMPM3+Fs BJlxh90oZgolRIpjWOsoRT7GVMJfz8AEvSa84K5am6DiY5tepx2bjLBLb35uLOhR7gFi WgUuifb8Fg9NGcoCkgSAzxA6VGnNQ0+Dd4Y6sWM7GEMETI1VUor4yiS0WNleB2mwvXYJ LYH/adUKruOEIh+EgUybzaDh5l+gYeELOf3bIMNPg0uzNf22l9Siw69J5ScvqJs8AA3l F9uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708382101; x=1708986901; 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=nguAE7f5YcWI/h5umYjj7eHdUyvOtkK6QQpK6mXXbx4=; b=M3ZiDWqxzrrLv4CLxNeUerIGSLMZ0ZBR/7o2mK/TJ4SQvYh3gv0iDViPRhqtYXhMe2 8G9K18AhbFox0c4lBw6KVWsfsh19/eURnlm9xokPCm4cHuZqR8oTLkbaoGwrbNfRLy/5 3rWO6C1HwDfPse3DvnmhA7kOWXsgxcLP4uiYAyzuKKzltBo9O5QycOCwUTK4GBkWW7u4 HIGpLaqRtOHvVM6VcaU1MKgP2rwbpicwlH4znJh6W1F7BfPQHrB9XRFuY6oEYx3x0a11 o8k2dEAQsdbemRkbyhvHtVV/THX/k0hidhVHdjAXLoAdQ8pOYeH6fnWaYlYakzhzoS92 Yb0g== X-Forwarded-Encrypted: i=1; AJvYcCWBR5Ysyp7pdXOzZFjQMJKy6ZQ3yeNp/5636nf1Jsnk4gTwXIWa+UkiyNcLjW1r183treYai8jRophxkdotdXSaqcvg+tR3HQJ1nsBsoD+kMzgTvr4= X-Gm-Message-State: AOJu0Yw1ZigG1Rk7Eod1BJfq4DBK7C2K4WR4K5XRXCKyGQlHV2vkqOoc lRF/PY5pa/lxF4MtnEbrm3JOfl2Zo2UGE3+y2vvJM5eAF0Cbsvitd4zzCeiyl1leIzskKta5Sa8 p X-Google-Smtp-Source: AGHT+IEKk7jzI/qkme4zk/gFRVTVBf/1nLdJFY+y7tiRySbZb046arGF15DJiOZ4ycZjN+0TNGVe+A== X-Received: by 2002:a9d:7494:0:b0:6e2:e5a3:1732 with SMTP id t20-20020a9d7494000000b006e2e5a31732mr3221609otk.37.1708382101127; Mon, 19 Feb 2024 14:35:01 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id h25-20020a9d6419000000b006e45a5f0a70sm171776otl.49.2024.02.19.14.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 14:35:00 -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, Julien Stephan Subject: [PATCH v2 5/5] iio: adc: ad7380: use spi_optimize_message() Date: Mon, 19 Feb 2024 16:33:22 -0600 Message-ID: <20240219-mainline-spi-precook-message-v2-5-4a762c6701b9@baylibre.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219-mainline-spi-precook-message-v2-0-4a762c6701b9@baylibre.com> References: <20240219-mainline-spi-precook-message-v2-0-4a762c6701b9@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-20240219_143502_104077_F5B5F859 X-CRM114-Status: GOOD ( 17.34 ) 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 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 drivers/iio/adc/ad7380.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) 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 { struct spi_device *spi; struct regulator *vref; struct regmap *regmap; + /* xfer and msg for buffer reads */ + struct spi_transfer xfer; + struct spi_message msg; /* * DMA (thus cache coherency maintenance) requires the * transfer buffers to live in their own cache lines. @@ -236,14 +239,9 @@ 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; @@ -335,6 +333,28 @@ static const struct iio_info ad7380_info = { .debugfs_reg_access = &ad7380_debugfs_reg_access, }; +static void ad7380_unoptimize_spi_msg(void *msg) +{ + spi_unoptimize_message(msg); +} + +static int devm_ad7380_setup_spi_msg(struct device *dev, struct ad7380_state *st) +{ + int ret; + + st->xfer.bits_per_word = st->chip_info->channels[0].scan_type.realbits; + st->xfer.len = 4; + st->xfer.rx_buf = st->scan_data.raw; + + spi_message_init_with_transfers(&st->msg, &st->xfer, 1); + + ret = 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->msg); +} + static int ad7380_init(struct ad7380_state *st) { int ret; @@ -411,6 +431,10 @@ static int ad7380_probe(struct spi_device *spi) return dev_err_probe(&spi->dev, PTR_ERR(st->regmap), "failed to allocate register map\n"); + ret = devm_ad7380_setup_spi_msg(&spi->dev, st); + if (ret) + return ret; + indio_dev->channels = st->chip_info->channels; indio_dev->num_channels = st->chip_info->num_channels; indio_dev->name = st->chip_info->name;