From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (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 299853783C7 for ; Wed, 17 Jun 2026 22:18:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781734740; cv=none; b=HwEJrlbqpDsdjaYlmLn8nrqGSVO8pYUjXVNFifdXnGacJWzcOwnXkNTTTPteWAV6LHflH8wUwyGLef+UqV2x3WhqSt9KjV4YTUih5yq/bny9DGSjtW4AmkUvyJ28gZX1uowlDXDKBUROANs2PZJI+9qv4L0lyMRpDbdnFO0gVNM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781734740; c=relaxed/simple; bh=XmadC3jjanZdVIoOxf4obLCYzmNZJcjJ+JmN4lZXX2g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=i2IbjTAU3ioc0dQ6JjqY3HuUCY9uytD9FN6+CZT8WaivAX/WzJ/XlRGfSb6092nUc81Yy6a7jK4zoV32WImcegbtH7UY6WLnnEfYaogF3Nx6lPJ0BG9UlZfKgnvV/dwHX4f588AxAW5uD96zTdfWFFxN8aClfLFh1ebFssOg430= 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 header.i=@baylibre.com header.b=bAUxOWgw; arc=none smtp.client-ip=209.85.161.51 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 header.i=@baylibre.com header.b="bAUxOWgw" Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-6a0c7c4f55fso249433eaf.2 for ; Wed, 17 Jun 2026 15:18:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre.com; s=google; t=1781734737; x=1782339537; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=tGSAX6SJosLEq+XA2blfrGkbQdqeFnb2GRKEkQRBDgI=; b=bAUxOWgw91upVyTIEAktPhs+3CG9KDH9rCtsXfq4eI2WaQ7RSacCWVcOst4F4sFg8S JosD5u4EXlW9YOO1kCOnuII1ybMTtwpSAIUqKcskXdbHcAuW1Bsjg8qjEmdr9OmhMYLw mtnwnOyPiIOaN1UHz6tPLrJcKPAPswQqvbO9GUfy5kCDUaouhK/mXUBYneFlKKnhckK5 jTbsj0pGdgrPIFnGzkqsCeoVM76DgzatudNjMqcnPUwx16G8X5O9/yu8OP+DCCq2JBcq mhPT9hUUfve5KjxcOWDCKKwDQAQsJIs3Fz7ChQ8CY0ufNmvKA+W8Zz8d2yESKRzcoCZ9 CGfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781734737; x=1782339537; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tGSAX6SJosLEq+XA2blfrGkbQdqeFnb2GRKEkQRBDgI=; b=lAZf4PW32o3MU+K41r8Fxsu7yP8rlWT3nFZiBnZnvA6ePPvkDMNc1xcAvQR4LsSDMc KpvNVMZCH6X/gYmW45J5o4IA/RneFfrpb/KoteZAkb0J3qjKoF2i7Wpu+79DwLaHWUOT xMMaPPcpXZJ1mLXsQA2q9brQFhq7AXG0z+2O4cFA4fBDOnStD8oo5YEFh4OEBC5jOoi8 PFcHTkAqIS4DlEU6+8oWOTfRT09AMsUiXWcbtj2MkutZ+gROqFmkJN4dZm6uUkMC37K8 jXHSV+58fU8aGCB4yKCL1k/sJkD8NOf8JDYF+CVvBkngj9oJDu19pBEmDpY4LbyMg9qD A8PA== X-Forwarded-Encrypted: i=1; AFNElJ9/B7WGU+tAtu0AfXlB3XKKmW+UKJGJJ4CsNppsQejzRcYNyPFiVjFXD3qhZ5OT29HcQWKFzkK1oOMvI/Y=@vger.kernel.org X-Gm-Message-State: AOJu0YxZQs+T4Z7VYabBr5Lh6z2aI7VL+WHBDf9hvBT1zAXn54Itvn0m qIzEhTiTb68Gnnc0CpUvrnN4C26wwBCm+BgZk0wZbNS5J5LkmgSr/d6amvnL3kL/mU8Kgw9hkg8 k/dU2sMs= X-Gm-Gg: Acq92OHcJfAzgkVUX4YVB++T7mdSxp+Gni6hxmVY4OYV8DzJBIrJft0PilpxnNpDQKp IZb9bhv7qtESk06q1PM868IeADovayiP3xT+U2OdJcxzyTBaKMtf8GR1b79Oi23WAdccWkdcU7/ cQDmhU0D2Rab3MnPQAO0cyNSlPl3IkIEnPLVawxXqXbbEJNsM0R9zsqKD485aD6dPq1CPiDGBOL pakzFF6M+UxfOlr8C0/wpQeKfdpFP4Z7vaBBWrm/wQb3be6tm56Mx1OrhA/6IlGU6wQfTktvLlq aWvAx2Kg9oXNNrCzcMRY+3uvEfJlykzk9aglxFUV7YsLYl3MG6OSwMKZfG3b/l2ZZ3Vyp48UDyk 5Tyx+GAj01YktAEyEntjE6N3yUthKU6Mbcld5JK/aJ7B+J0Xr2XykQzVKNLaC/+TrKGZ67pRM4o 5ctGbufmFrciOvkYw0qL/H3gIc2kplYEb85Jp/TVyLhpARWwvgwWIv/mAYB1SJkAI= X-Received: by 2002:a05:6820:80c8:b0:69e:4008:13e4 with SMTP id 006d021491bc7-6a0c75f70a9mr1066623eaf.17.1781734737030; Wed, 17 Jun 2026 15:18:57 -0700 (PDT) Received: from ?IPV6:2600:8803:e7e4:500:9458:d356:778c:22ac? ([2600:8803:e7e4:500:9458:d356:778c:22ac]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-69f00d609e9sm7325069eaf.7.2026.06.17.15.18.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Jun 2026 15:18:56 -0700 (PDT) Message-ID: Date: Wed, 17 Jun 2026 17:18:55 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/5] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs To: Marcelo Schmitt , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, nuno.sa@analog.com, Michael.Hennerich@analog.com, andy@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, pop.ioan-daniel@analog.com, marcelo.schmitt1@gmail.com References: <5c18e7a370119ddfd5faefe147b294b39f78894a.1781661028.git.marcelo.schmitt@analog.com> Content-Language: en-US From: David Lechner In-Reply-To: <5c18e7a370119ddfd5faefe147b294b39f78894a.1781661028.git.marcelo.schmitt@analog.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 6/16/26 9:03 PM, Marcelo Schmitt wrote: > Support for LTC2378-20 and similar analog-to-digital converters. > ... > +static int ltc2378_probe(struct spi_device *spi) > +{ > + struct device *dev = &spi->dev; > + struct iio_dev *indio_dev; > + struct ltc2378_state *st; > + int ret; > + > + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); > + if (!indio_dev) > + return -ENOMEM; > + > + st = iio_priv(indio_dev); > + st->spi = spi; > + > + ret = devm_regulator_get_enable_read_voltage(dev, "ref"); > + if (ret < 0) > + return dev_err_probe(dev, ret, "failed to read ref regulator\n"); > + > + st->ref_uV = ret; add blank line here > + st->info = spi_get_device_match_data(spi); > + if (!st->info) > + return -EINVAL; > + > + indio_dev->name = st->info->name; > + indio_dev->info = <c2378_iio_info; > + indio_dev->modes = INDIO_DIRECT_MODE; > + > + st->cnv_gpio = devm_gpiod_get(dev, "cnv", GPIOD_OUT_LOW); > + if (IS_ERR(st->cnv_gpio)) > + return dev_err_probe(dev, PTR_ERR(st->cnv_gpio), > + "failed to get CNV GPIO"); > + > + st->num_iio_chans = 0; > + st->chans[st->num_iio_chans++] = (struct iio_chan_spec) { Why can't we make this static const (part of chip info) like we do in most drivers? > + .type = IIO_VOLTAGE, > + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | > + BIT(IIO_CHAN_INFO_SCALE), > + .scan_index = 0, > + .scan_type = { > + .format = st->info->bipolar ? IIO_SCAN_FORMAT_SIGNED_INT : > + IIO_SCAN_FORMAT_UNSIGNED_INT, > + .realbits = st->info->resolution, > + /* > + * Buffer elements could be 16-bit for low precision > + * parts. Though, using more storage bits allows keeping > + * the same scan_type configuration for both types of > + * buffer support. > + */ Won't this make non-SPI offload buffered reads more complicated later? I.e. have to shift the value or not before pushing to buffers depending on CPU endianness. > + .storagebits = 32, > + }, > + }; > + > + st->xfer.rx_buf = &st->scan.data; > + st->xfer.len = st->info->resolution > 16 ? 4 : 2; Can use spi_bpw_to_bytes() here. > + st->xfer.bits_per_word = st->info->resolution; > + > + indio_dev->channels = st->chans; > + indio_dev->num_channels = st->num_iio_chans; > + > + return devm_iio_device_register(&spi->dev, indio_dev); > +} > + ... > diff --git a/drivers/iio/adc/ltc2378.h b/drivers/iio/adc/ltc2378.h > new file mode 100644 > index 000000000000..a3a69351de6c > --- /dev/null > +++ b/drivers/iio/adc/ltc2378.h > @@ -0,0 +1,63 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Analog Devices LTC2378 and similar ADCs common definitions and properties > + * Copyright (C) 2026 Analog Devices, Inc. > + * Author: Marcelo Schmitt > + */ > + > +#ifndef __DRIVERS_IIO_ADC_LTC2378_H__ > +#define __DRIVERS_IIO_ADC_LTC2378_H__ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define LTC2378_TDSDOBUSYL_NS 5 > +#define LTC2378_TBUSYLH_NS 13 > +#define LTC2378_TCNV_HIGH_NS 20 > + > +struct ltc2378_chip_info { > + const char *name; > + int resolution; > + bool bipolar; > +}; > + > +struct ltc2378_state { > + const struct ltc2378_chip_info *info; > + struct gpio_desc *cnv_gpio; > + struct spi_device *spi; > + struct spi_transfer xfer; > + unsigned int num_iio_chans; > + struct iio_chan_spec chans[2]; /* 1 physical chan + 1 timestamp chan */ > + int ref_uV; > + > + /* > + * DMA (thus cache coherency maintenance) requires the > + * transfer buffers to live in their own cache lines. > + */ > + struct { > + union { > + u16 sample_buf16; > + u32 sample_buf32; > + } data; > + aligned_s64 timestamp; > + } scan __aligned(IIO_DMA_MINALIGN); > +}; > + > +static inline int ltc2378_convert_and_acquire(struct ltc2378_state *st) > +{ > + int ret; > + > + /* Cause a rising edge of CNV to initiate a new ADC conversion */ > + gpiod_set_value_cansleep(st->cnv_gpio, 1); > + fsleep(4); > + ret = spi_sync_transfer(st->spi, &st->xfer, 1); > + gpiod_set_value_cansleep(st->cnv_gpio, 0); > + > + return ret; > +} > + > +#endif /* __DRIVERS_IIO_ADC_LTC2378_H__ */ Why do we need a header for this stuff? If there is a good reason the commit message should explain it. Otherwise, it makes the driver harder to read.