From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) (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 AF1F132ED20 for ; Tue, 2 Sep 2025 15:44:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756827875; cv=none; b=cLhWHO8l0xJStCmtFRv4HT1boKuDPHqkZib3fmlgIac5K46cpfk42T0zNMImhFS5zQ3g3LMg3FWSTA7/s238RSOagUBax3OQUoSxyn0sZ/vyeETTcGIUBvJmkhGjPLtPJC/8wh611VwtrwAaDIVfbslyFBhiV1P1GBbcMJCdby0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756827875; c=relaxed/simple; bh=c/sOlfEq2OA3IZtcXh3gz5AiRMiBPf2jLUCCS2VdNXc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=mSnaAu9HZzWPvTdw3N++YZg25Tj29MTqnVtSL6lmKJoA7zl5NJdIhChyYOCPCXw6mZV/9vvlQc4jdftui2K/6MpI/Xtn4kVlvjSEk8cSg6ITYE2I58x57OZ+JXw0Bc0YmxM8jUWxyixiC2KCGUeSW/EiovEpbqxdOkyy6OYO0Gs= 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.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=uRFzey+Q; arc=none smtp.client-ip=209.85.160.44 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.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="uRFzey+Q" Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-315bab2917bso4013259fac.1 for ; Tue, 02 Sep 2025 08:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1756827871; x=1757432671; 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=mLE488gYyvEzSAPfgpQZfVUn1BUOU/Tj59M3I7iYh5Q=; b=uRFzey+Quh/Vij2k/PKpJgu6Hwrh/LmNdUdAByurAnTuX/yK1eW16ycYE40HIWu4OF N4U/V2O+qf9r1CpxSBScAHDd680asMPP4jXmIAPQTzSUfmxHdFcrsZUGWYW+6ycnfnjH EQCIZF9Pt4hpMts72wqDxzgAwvOXF4U8E+PHE2MSXIrayYbuNN96C0kMXb1zvZxqGWMZ 6T/tRFwdArLghZQbtobvUD+5fV/NC4uYCxVVGdo/HxLXSlm9R9eWPf10q4OqZPJiXHjB +y/4eI0tRC7l4Q77XU/lg57tvoVbq6x1pR0D07TFMqeFX/n2aYVwybCN4I2NXEEc5UDO px9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756827871; x=1757432671; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mLE488gYyvEzSAPfgpQZfVUn1BUOU/Tj59M3I7iYh5Q=; b=LaFZ1UiHMgfeD/AMQ+DP1ob/CbRuAy0wbibGUYNYnjr7Njrpkuuu/SakU3SGLGfsxh kyn7g3ljMv7XljcL52IiaUqyY6+ebVRlfzIX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:5227:b0:30b:ae4c:2e82 with SMTP id 586e51a60fabf-31963364100mr5777995fac.12.1756827870648; Tue, 02 Sep 2025 08:44:30 -0700 (PDT) Received: from ?IPV6:2600:8803:e7e4:1d00:8d95:114e:b6f:bf5b? ([2600:8803:e7e4:1d00:8d95:114e:b6f:bf5b]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7457428c153sm1634614a34.8.2025.09.02.08.44.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Sep 2025 08:44:30 -0700 (PDT) Message-ID: <525a44e7-8e38-48fd-af84-4c56a6a0ffe7@baylibre.com> Date: Tue, 2 Sep 2025 10:44:28 -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 v10 2/2] iio: adc: max14001: New driver To: Marilene Andrade Garcia , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Kim Seer Paller , Jonathan Cameron , =?UTF-8?Q?Nuno_S=C3=A1?= , Andy Shevchenko , Lars-Peter Clausen , Michael Hennerich , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Marcelo Schmitt , Marcelo Schmitt , Ceclan Dumitru , Jonathan Santos , Dragos Bogdan References: Content-Language: en-US From: David Lechner In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 9/2/25 8:16 AM, Marilene Andrade Garcia wrote: > The MAX14001/MAX14002 is configurable, isolated 10-bit ADCs for multi-range > binary inputs. In addition to ADC readings, the MAX14001/MAX14002 offers > more features, like a binary comparator, a filtered reading that can > provide the average of the last 2, 4, or 8 ADC readings, and an inrush > comparator that triggers the inrush current. There is also a fault feature > that can diagnose seven possible fault conditions. And an option to select > an external or internal ADC voltage reference. > > MAX14001/MAX14002 features implemented so far: > - Raw ADC reading. > - Filtered ADC average reading with the default configuration. > - MV fault disable. > - Selection of external or internal ADC voltage reference, depending on > whether it is declared in the device tree. > > Co-developed-by: Marilene Andrade Garcia > Signed-off-by: Marilene Andrade Garcia > Signed-off-by: Kim Seer Paller > --- > MAINTAINERS | 1 + > drivers/iio/adc/Kconfig | 10 ++ > drivers/iio/adc/Makefile | 1 + > drivers/iio/adc/max14001.c | 355 +++++++++++++++++++++++++++++++++++++ > 4 files changed, 367 insertions(+) > create mode 100644 drivers/iio/adc/max14001.c > > diff --git a/MAINTAINERS b/MAINTAINERS > index f145f0204407..b6457063da6c 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -14976,6 +14976,7 @@ L: linux-iio@vger.kernel.org > S: Maintained > W: https://ez.analog.com/linux-software-drivers > F: Documentation/devicetree/bindings/iio/adc/adi,max14001.yaml > +F: drivers/iio/adc/max14001.c > > MAXBOTIX ULTRASONIC RANGER IIO DRIVER > M: Andreas Klinger > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig > index e3d3826c3357..11e911ceab4c 100644 > --- a/drivers/iio/adc/Kconfig > +++ b/drivers/iio/adc/Kconfig > @@ -958,6 +958,16 @@ config MAX11410 > To compile this driver as a module, choose M here: the module will be > called max11410. > > +config MAX14001 > + tristate "Analog Devices MAX14001/MAX14002 ADC driver" > + depends on SPI > + help > + Say yes here to build support for Analog Devices MAX14001/MAX14002 > + Configurable, Isolated 10-bit ADCs for Multi-Range Binary Inputs. > + > + To compile this driver as a module, choose M here: the module will be > + called max14001. > + > config MAX1241 > tristate "Maxim max1241 ADC driver" > depends on SPI_MASTER > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile > index 89d72bf9ce70..569f2f5613d4 100644 > --- a/drivers/iio/adc/Makefile > +++ b/drivers/iio/adc/Makefile > @@ -85,6 +85,7 @@ obj-$(CONFIG_MAX11100) += max11100.o > obj-$(CONFIG_MAX1118) += max1118.o > obj-$(CONFIG_MAX11205) += max11205.o > obj-$(CONFIG_MAX11410) += max11410.o > +obj-$(CONFIG_MAX14001) += max14001.o > obj-$(CONFIG_MAX1241) += max1241.o > obj-$(CONFIG_MAX1363) += max1363.o > obj-$(CONFIG_MAX34408) += max34408.o > diff --git a/drivers/iio/adc/max14001.c b/drivers/iio/adc/max14001.c > new file mode 100644 > index 000000000000..6755df152976 > --- /dev/null > +++ b/drivers/iio/adc/max14001.c > @@ -0,0 +1,355 @@ > +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) > +/* > + * Analog Devices MAX14001/MAX14002 ADC driver > + * > + * Copyright (C) 2023-2025 Analog Devices Inc. > + * Copyright (C) 2023 Kim Seer Paller > + * Copyright (c) 2025 Marilene Andrade Garcia > + * > + * Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/MAX14001-MAX14002.pdf > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* MAX14001 Registers Address */ > +#define MAX14001_REG_ADC 0x00 > +#define MAX14001_REG_FADC 0x01 > +#define MAX14001_REG_FLAGS 0x02 > +#define MAX14001_REG_FLTEN 0x03 > +#define MAX14001_REG_THL 0x04 > +#define MAX14001_REG_THU 0x05 > +#define MAX14001_REG_INRR 0x06 > +#define MAX14001_REG_INRT 0x07 > +#define MAX14001_REG_INRP 0x08 > +#define MAX14001_REG_CFG 0x09 > +#define MAX14001_REG_ENBL 0x0A > +#define MAX14001_REG_ACT 0x0B > +#define MAX14001_REG_WEN 0x0C > + > +#define MAX14001_REG_VERIFICATION(x) ((x) + 0x10) > + > +#define MAX14001_REG_CFG_EXRF BIT(5) > + > +#define MAX14001_MASK_ADDR GENMASK(15, 11) > +#define MAX14001_MASK_DATA GENMASK(9, 0) > + > +#define MAX14001_SET_WRITE_BIT BIT(10) > +#define MAX14001_WRITE_WEN 0x294 > + > +enum max14001_chip_model { > + max14001, > + max14002, > +}; > + > +struct max14001_chip_info { > + const char *name; > +}; > + > +struct max14001_state { > + const struct max14001_chip_info *chip_info; > + struct spi_device *spi; > + int vref_mv; > + /* > + * lock protect against multiple concurrent accesses, RMW sequence, > + * and SPI transfer. > + */ > + struct mutex lock; > + /* > + * The following buffers will be bit-reversed during device > + * communication, because the device transmits and receives data > + * LSB-first. Some SPI controllers may be able to handle LSB first without us having to reverse things in the driver. Search the kernel for SPI_LSB_FIRST to see what I mean. By setting `spi-lsb-first;` in the devicetree, the core SPI code will check if the controller supports it and let the hardare handle everything so we don't need to reverse bits here in this driver. If we need to make this work on a SPI controller that doesn't support SPI_LSB_FIRST, then we should add something in the core SPI code that does the reversing during __spi_optimize_message() so that every peripheral driver doesn't have to do this. For example, search spi.c for SPI_CS_WORD to see how it handles that flag for controllers that don't support it. > + * DMA (thus cache coherency maintenance) requires the transfer > + * buffers to live in their own cache lines. > + */ > + __be16 spi_tx_buffer __aligned(IIO_DMA_MINALIGN); > + __be16 spi_rx_buffer; > +}; > + > +static int max14001_probe(struct spi_device *spi) > +{ ... > + ret = devm_mutex_init(dev, &st->lock); > + if (ret) > + return dev_err_probe(dev, ret, > + "Failed to init the mutex\n"); > + The only possible error here is -ENOMEM, which we don't print messages for. So just `return ret;` on this one.