From nobody Sat Nov 30 00:37:29 2024 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 6B2DE1DCB31 for ; Fri, 13 Sep 2024 13:57:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235875; cv=none; b=TMV9mzVP5kC8z97V1q3QM7elHa220dJwpMYPdat/3xfmYgNTo+LAM/6cm0L01Q0uyFD+WZIwp8sIq917wBMA2c33IBcI3X1i4jMy94Hvj96oH23SI2gDPKplUB591SfOTmsxA23vYBuruwmbOfAChFiOnG44GwEP8UrLuvc9KN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235875; c=relaxed/simple; bh=7jeDEErQ+xBSjvZ9RT/TEcexKXO8icQCIcZ4pRA2dbs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZON5gPp9Goj5Ecgf/JfP1nHG2IMgQZYvMIcF34TgAWcO5J7YL30BXmiqGlZuMnwbNspTa45HZ8exvqMAG2hxSQP74Lp2JH0Ka3l2EVEV8lCu+6lgTAPN4IJ9QjZTGD4k79R6nuIxtbLGiyBTDAZwiWaoE553Id/+NEPqpRXunXE= 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=f7vffjNL; arc=none smtp.client-ip=209.85.221.49 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="f7vffjNL" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-371ba7e46easo1659420f8f.0 for ; Fri, 13 Sep 2024 06:57:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726235872; x=1726840672; darn=vger.kernel.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=ZWLUgthTvXLTW08JjjEElu7+ziFuVs/iQEkeWDpV0KA=; b=f7vffjNLa2Uo8BHFJIkEb2c7KUVA3dEVwf4KVDYJRFkYNMJUGaeiZnUREap003S08A uA2Wmmec3HhQuQtEdOZbmwJmUrmMQbM7XFKlxfAjBiJnKusGgqc/IjYB0H68HrMZyTd5 sMUIzdApqXaQwtsiPxW+zFKpQJ14SmmsJaVGYOmO9UDPaIn7N4vhPpkEgUVRrBEkbsS1 G0XVbW373kX/v/FASKlRqa2+kE9CxG13mBqwNEWZb9Z2SuvmHF69rjsCJY+kete7O6d2 bdWNLab+cAAW8SU4H4Gmux/i0EnmxRmqqNlJ2xuKeiirEs8Y67lC9plBp3HEg1DfXgsU F6mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726235872; x=1726840672; 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=ZWLUgthTvXLTW08JjjEElu7+ziFuVs/iQEkeWDpV0KA=; b=YqcrYo/8BiRiqGW8PzO1OilNCVWaf4VpBwrp5WafK83Vz2l6G9AQ55qpK7LLNWFmgX MyA6/tE6lt0M2rLY49p/3DN+vUqb7ZhPXONX7+OFSwz0j+VvREk7IUhuZyW932bwrXqd YOfP5S6gXJEjgBUpFhOb9KoNQpgjvlayScCdiq+gS+Ertknk029BeKE2NFgDddFgao5g Spl+Ri3NleVxZZEyCPv8ZBNulBWOKXjE4ubWYggcNlL2TtE1ypQ/Q+3qSzxd3ayikBB0 H/0TMX2v9iKS8lFpZnNc2I+pEIx3Hz6xLv1J4hUPd3S6Iswl3RaCac5tLQ6vvUXLUvmp VtNQ== X-Forwarded-Encrypted: i=1; AJvYcCX2Ep/0Kl1tFauNHWrv8atjczFOLAfEM7HsITu9Joh2wtNBTar0uIorsSR9yKn14xlQKJHitXpnAWOebo8=@vger.kernel.org X-Gm-Message-State: AOJu0YwJpq14JeFvENeo3WrkWeik9wa2ChuPIXuP78jiSJKgPgor++Jr Eo/2eL8wkhdm/PlieI2JQ+B+MQ6AYfVEOkt0vMy0gT1WarJggfOOYVWmF/rRcJA= X-Google-Smtp-Source: AGHT+IG+OkIQ2PfAitpwrJHTaZB7u3SC6rFQQVsxZbK+lEsxaD5mTd98pNcYiRYKHuMBt7oR57Iznw== X-Received: by 2002:adf:a3d0:0:b0:368:64e:a7dd with SMTP id ffacd0b85a97d-378c2d55661mr3394962f8f.53.1726235870736; Fri, 13 Sep 2024 06:57:50 -0700 (PDT) Received: from neptune.lan ([188.27.129.88]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d3941sm17104749f8f.84.2024.09.13.06.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 06:57:50 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean Subject: [PATCH v6 1/8] iio: adc: ad7606: add 'bits' parameter to channels macros Date: Fri, 13 Sep 2024 16:57:36 +0300 Message-ID: <20240913135744.152669-2-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240913135744.152669-1-aardelean@baylibre.com> References: <20240913135744.152669-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There are some newer additions to the AD7606 family, which support 18 bit precision. Up until now, all chips were 16 bit. This change adds a 'bits' parameter to the AD760X_CHANNEL macro and renames 'ad7606_channels' -> 'ad7606_channels_16bit' for the current devices. The AD7606_SW_CHANNEL() macro is also introduced, as a short-hand for IIO channels in SW mode. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 58 ++++++++++++++++++------------------ drivers/iio/adc/ad7606.h | 18 ++++++----- drivers/iio/adc/ad7606_spi.c | 16 +++++----- 3 files changed, 47 insertions(+), 45 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 9b457472d49c..8ebfe8abc3f4 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -309,16 +309,16 @@ static const struct iio_chan_spec ad7605_channels[] = =3D { AD7605_CHANNEL(3), }; =20 -static const struct iio_chan_spec ad7606_channels[] =3D { +static const struct iio_chan_spec ad7606_channels_16bit[] =3D { IIO_CHAN_SOFT_TIMESTAMP(8), - AD7606_CHANNEL(0), - AD7606_CHANNEL(1), - AD7606_CHANNEL(2), - AD7606_CHANNEL(3), - AD7606_CHANNEL(4), - AD7606_CHANNEL(5), - AD7606_CHANNEL(6), - AD7606_CHANNEL(7), + AD7606_CHANNEL(0, 16), + AD7606_CHANNEL(1, 16), + AD7606_CHANNEL(2, 16), + AD7606_CHANNEL(3, 16), + AD7606_CHANNEL(4, 16), + AD7606_CHANNEL(5, 16), + AD7606_CHANNEL(6, 16), + AD7606_CHANNEL(7, 16), }; =20 /* @@ -333,22 +333,22 @@ static const struct iio_chan_spec ad7606_channels[] = =3D { */ static const struct iio_chan_spec ad7616_channels[] =3D { IIO_CHAN_SOFT_TIMESTAMP(16), - AD7606_CHANNEL(0), - AD7606_CHANNEL(1), - AD7606_CHANNEL(2), - AD7606_CHANNEL(3), - AD7606_CHANNEL(4), - AD7606_CHANNEL(5), - AD7606_CHANNEL(6), - AD7606_CHANNEL(7), - AD7606_CHANNEL(8), - AD7606_CHANNEL(9), - AD7606_CHANNEL(10), - AD7606_CHANNEL(11), - AD7606_CHANNEL(12), - AD7606_CHANNEL(13), - AD7606_CHANNEL(14), - AD7606_CHANNEL(15), + AD7606_CHANNEL(0, 16), + AD7606_CHANNEL(1, 16), + AD7606_CHANNEL(2, 16), + AD7606_CHANNEL(3, 16), + AD7606_CHANNEL(4, 16), + AD7606_CHANNEL(5, 16), + AD7606_CHANNEL(6, 16), + AD7606_CHANNEL(7, 16), + AD7606_CHANNEL(8, 16), + AD7606_CHANNEL(9, 16), + AD7606_CHANNEL(10, 16), + AD7606_CHANNEL(11, 16), + AD7606_CHANNEL(12, 16), + AD7606_CHANNEL(13, 16), + AD7606_CHANNEL(14, 16), + AD7606_CHANNEL(15, 16), }; =20 static const struct ad7606_chip_info ad7606_chip_info_tbl[] =3D { @@ -358,25 +358,25 @@ static const struct ad7606_chip_info ad7606_chip_info= _tbl[] =3D { .num_channels =3D 5, }, [ID_AD7606_8] =3D { - .channels =3D ad7606_channels, + .channels =3D ad7606_channels_16bit, .num_channels =3D 9, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), }, [ID_AD7606_6] =3D { - .channels =3D ad7606_channels, + .channels =3D ad7606_channels_16bit, .num_channels =3D 7, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), }, [ID_AD7606_4] =3D { - .channels =3D ad7606_channels, + .channels =3D ad7606_channels_16bit, .num_channels =3D 5, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), }, [ID_AD7606B] =3D { - .channels =3D ad7606_channels, + .channels =3D ad7606_channels_16bit, .num_channels =3D 9, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 6649e84d25de..204a343067e5 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -8,7 +8,7 @@ #ifndef IIO_ADC_AD7606_H_ #define IIO_ADC_AD7606_H_ =20 -#define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all) { \ +#define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all, bits) { \ .type =3D IIO_VOLTAGE, \ .indexed =3D 1, \ .channel =3D num, \ @@ -19,24 +19,26 @@ .scan_index =3D num, \ .scan_type =3D { \ .sign =3D 's', \ - .realbits =3D 16, \ - .storagebits =3D 16, \ + .realbits =3D (bits), \ + .storagebits =3D (bits) > 16 ? 32 : 16, \ .endianness =3D IIO_CPU, \ }, \ } =20 #define AD7605_CHANNEL(num) \ AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \ - BIT(IIO_CHAN_INFO_SCALE), 0) + BIT(IIO_CHAN_INFO_SCALE), 0, 16) =20 -#define AD7606_CHANNEL(num) \ +#define AD7606_CHANNEL(num, bits) \ AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \ BIT(IIO_CHAN_INFO_SCALE), \ - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO)) + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), bits) =20 -#define AD7616_CHANNEL(num) \ +#define AD7606_SW_CHANNEL(num, bits) \ AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),\ - 0, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO)) + 0, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), bits) + +#define AD7616_CHANNEL(num) AD7606_SW_CHANNEL(num, 16) =20 /** * struct ad7606_chip_info - chip specific information diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c index 62ec12195307..e00f58a6a0e9 100644 --- a/drivers/iio/adc/ad7606_spi.c +++ b/drivers/iio/adc/ad7606_spi.c @@ -67,14 +67,14 @@ static const struct iio_chan_spec ad7616_sw_channels[] = =3D { =20 static const struct iio_chan_spec ad7606b_sw_channels[] =3D { IIO_CHAN_SOFT_TIMESTAMP(8), - AD7616_CHANNEL(0), - AD7616_CHANNEL(1), - AD7616_CHANNEL(2), - AD7616_CHANNEL(3), - AD7616_CHANNEL(4), - AD7616_CHANNEL(5), - AD7616_CHANNEL(6), - AD7616_CHANNEL(7), + AD7606_SW_CHANNEL(0, 16), + AD7606_SW_CHANNEL(1, 16), + AD7606_SW_CHANNEL(2, 16), + AD7606_SW_CHANNEL(3, 16), + AD7606_SW_CHANNEL(4, 16), + AD7606_SW_CHANNEL(5, 16), + AD7606_SW_CHANNEL(6, 16), + AD7606_SW_CHANNEL(7, 16), }; =20 static const unsigned int ad7606B_oversampling_avail[9] =3D { --=20 2.46.0 From nobody Sat Nov 30 00:37:29 2024 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.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 D531A1DC047 for ; Fri, 13 Sep 2024 13:57:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235875; cv=none; b=AobnoBkwfCW1emCJvjw55nn1/eTYf5lGEywLHT2XmEIko0w3KXVXCq0KfhA7CNxfYGQ5uhn1fRjPMc9nQa2lPVcXBP7PstGp4bLUr8mcuLIUOjyIFW8TldnIC91djh4Ta4refNGhGK3hPaag0iB5M+31OI7n2FWcKLU6gccMfEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235875; c=relaxed/simple; bh=ykUyvmQc/5wbFyrFRMV34ty22I9dWMk9TBb47ILEe4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a9xXE8ZB0HFjgvoPeSOVbMOLC4j5ogGvNVy08dzOQmLdkv8TU8DB/7V+kK+AI9QjPXit/xmQbcNtuexLCS95njMlo40um68MrdB2ll7l4h82EaJfKMHtC61R+TOlWkDWixpGeYQDrtzNm9+rBZQ1yqW1Ieg9GY5uwSqEJmQBOFQ= 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=PNxrspRp; arc=none smtp.client-ip=209.85.128.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.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="PNxrspRp" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-42cb57f8b41so13000525e9.0 for ; Fri, 13 Sep 2024 06:57:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726235872; x=1726840672; darn=vger.kernel.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=B4rgjfNfx6m5HjjB8s+u7qEdTS2g8HjBiOKrDc5NZNs=; b=PNxrspRpc13iD1sNcrmh+vlfA30bQP+dBSSKqCwFDTRYJ/bqQv8h+08bQoB1QyzxPJ MtvHXTqtSheWngYZANTmeJ7HqXN0RUIRgrCKo3EHfQjcWL4JryUfFHHIx43Xn6oAlBWy QJgRzllQXNntOpv5ASwIsLxRtdVzU54ZkMmE5qa+DgLlB6YovuOA4twtIEBqvQS55EjE 5E4ip+hCjbh3ertfR2EhsPu0QnRpz9XzL6eiScDMrg327B82eEEQe4uxjv8nttEsRR3N Qohfy+88u/y5DtnXkqFDG1W7hPJUB8HURHaoKf/wg2QuqjKY2TW6vEGKT+svQSyP07jx 2JxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726235872; x=1726840672; 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=B4rgjfNfx6m5HjjB8s+u7qEdTS2g8HjBiOKrDc5NZNs=; b=XF9cyC2cZM63QlA47Et0KTvsNz4bVkoCRkzL+MCzJr9D8wBE3bev08fo05HQm5FQ1D b1H8+9x9bHx+sG5ehp2R+ySJXRPeH3GBDJSFILSuE9rcrM6YnKJcs9y4IYJDJWZrDMA+ fozg4FhOIX+bOIm5jbVLy2TtZIY+v6rXYayYGpCBJQzz04nU3if4BKKKc/FUUKYnzDdj L9KLtN4hm7n28DkRrD7FLwXjunJLbqWqbgI3EV/x7efiMpsg4gXPMNY4ugv2Ej24/lE4 eXLcaZpSEUXNl1Rb2WmR3HGvYnYd7gtRhpTSacNQd195rzBtLPAKC5gMdPefUEsiJQOO lo6g== X-Forwarded-Encrypted: i=1; AJvYcCWR1zTnBZUJ4KfnZYlzsotV029I5yuNFTaqbtP4Gfxq21zXif5RID/pbQ5AKcD/fmKK6Ayj/kG7XRtRsL8=@vger.kernel.org X-Gm-Message-State: AOJu0YxStM2LjB6su8M0FHjJo2QwDZH+sTwuFwj2sIPqpXgn81d61fsH rn3DwZ8XYLsUmPnU/IhQ8kG1Wjyzp0KxH8/33cSo6ONDamTSPJA4iGDQ+OXn/Hs= X-Google-Smtp-Source: AGHT+IHKl/sekJF8kry63CsXxWoyv5gAnBtahL/o0D2gWDcZ37fkQHvGiSnOeYrYCCK3s3dcaZ0Iug== X-Received: by 2002:a05:600c:46c9:b0:42c:a8cb:6a5a with SMTP id 5b1f17b1804b1-42d908267d1mr32500025e9.15.1726235872095; Fri, 13 Sep 2024 06:57:52 -0700 (PDT) Received: from neptune.lan ([188.27.129.88]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d3941sm17104749f8f.84.2024.09.13.06.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 06:57:51 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean Subject: [PATCH v6 2/8] iio: adc: ad7606: move 'val' pointer to ad7606_scan_direct() Date: Fri, 13 Sep 2024 16:57:37 +0300 Message-ID: <20240913135744.152669-3-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240913135744.152669-1-aardelean@baylibre.com> References: <20240913135744.152669-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The ad7606_scan_direct() function returns 'int', which is fine for 16-bit samples. But when going to 18-bit samples, these need to be implemented as 32-bit (or int) type. In that case when getting samples (which can be negative), we'd get random error codes. So, the easiest thing is to just move the 'val' pointer to 'ad7606_scan_direct()'. This doesn't qualify as a fix, it's just a preparation for 18-bit ADCs (of the AD7606 family). Reviewed-by: David Lechner Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 8ebfe8abc3f4..032a8135c912 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -114,7 +114,8 @@ static irqreturn_t ad7606_trigger_handler(int irq, void= *p) return IRQ_HANDLED; } =20 -static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch) +static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch, + int *val) { struct ad7606_state *st =3D iio_priv(indio_dev); int ret; @@ -128,8 +129,10 @@ static int ad7606_scan_direct(struct iio_dev *indio_de= v, unsigned int ch) } =20 ret =3D ad7606_read_samples(st); - if (ret =3D=3D 0) - ret =3D st->data[ch]; + if (ret) + goto error_ret; + + *val =3D sign_extend32(st->data[ch], 15); =20 error_ret: gpiod_set_value(st->gpio_convst, 0); @@ -149,10 +152,9 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, switch (m) { case IIO_CHAN_INFO_RAW: iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { - ret =3D ad7606_scan_direct(indio_dev, chan->address); + ret =3D ad7606_scan_direct(indio_dev, chan->address, val); if (ret < 0) return ret; - *val =3D (short) ret; return IIO_VAL_INT; } unreachable(); --=20 2.46.0 From nobody Sat Nov 30 00:37:29 2024 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 2148B1DEFDC for ; Fri, 13 Sep 2024 13:57:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235878; cv=none; b=I1qSpYWp75pPd0ef7jrZSDOvgSwBema+slwNBDFJOD/E+4yueZr8HxGelmhXtzDjbsYLka6oRDOCGO3bQg8vnEfcUL8cMryqkQpN3Cqkz+Ixsv1+ajYTQB+mWZJipgTNd/F8i1PK0CbV6roun7WZy+KuyG89C+O3TA/ASbes46Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235878; c=relaxed/simple; bh=63E+67ut4upizdiuiIAIWX+zYFAZeVjPavEhQ9/iZhs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kuRymXd02EKHgyO8w6G7CZ2V1bhTAWuFMaS8b8fHyGaOJeU/HYnElgL+erFxE4uWf+p76nfSK7Qa4YHmuKX3ufNeWvfQVfW5cI90dcIyZwzdzdlf77kY9rg0ksr/r2dk2TL8PPviUKxxBaAkTyyza8jqOgnYkOF3FPmYH9UiuIo= 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=pS0XT1WD; arc=none smtp.client-ip=209.85.221.47 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="pS0XT1WD" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3787ddbd5a2so1417573f8f.0 for ; Fri, 13 Sep 2024 06:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726235874; x=1726840674; darn=vger.kernel.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=SGwDN6q9n1jJb2Ms/M/RGF868EKCCN0sUCPfjspQZyM=; b=pS0XT1WDOmi8z0nadyu2eWeHa8IbvHvrJNJqagjJoNCjZAniRjpMhZn8kaEsfsYAAz gblLpOhpiS5BBHvhlt8VIKCGeRNbQQKQ8aPRVqyhjPtYEV/uVS7Gzk9rFC6CVdwrFbzj hSVieBjtsoF6eKviNNziK4hTT/OIZfaJg18gIUjG2YezDHdqODD4N6dGGo1hxQsbLg7E U/zFBnE5UEVPnseotI76F/Wl+cPSPPslnJ90jOqIgypwpFbxOohE7SYdkRoWf/bo4QqF 2lnboWb5oQpMCtnHNK+/qfQctfej5JmluakNGwnSGE1sqQ/ql7Xw6s0SN3q81bA5p0DI 5dsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726235874; x=1726840674; 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=SGwDN6q9n1jJb2Ms/M/RGF868EKCCN0sUCPfjspQZyM=; b=Qo1cUxE+yiBjYW9feM4pf+9FuPUGRKjfLLCUEh8DOtcnbHCHBboarNOwrflrGKPASc DA6qP+xEuR+s3Y+zU/xjER88ziV8zJC6h6h2/RtIgUBFtmgBV18iKXcfI79+fQeaVUdG McLyyYm7wy/4Ua7GdmsAB3EM2WpF/vFZqFzFSdg1JOV6uaM8kpYUYgdhQLKAMAgvO33T +7ObHfhJaYP2wtNr8AGNqweqLNxHQS/fnscaS64AC9sBaUwL5MbTcY1mD+1STclcy5qs wqAOs9Uhx78FkeqP3MKUebvHu2BrJZJcPprEq6Yc/kIW+DA0CiK3/zLj5JT7bAcvFfWg lQiA== X-Forwarded-Encrypted: i=1; AJvYcCVL3BWMlwP4WT3/8GfMZYXPwNazjyTLzkj7ihcDx7tNwlIiqxMEvp6oYdOYCFWbfQoPGEyDh9NUh39pA+c=@vger.kernel.org X-Gm-Message-State: AOJu0Yxebzgj7I6L+Bt9gQPVnalSAqbJ0N3641XsOs5NJAswvRbWwDen fSBidGVteomlnrCetyjE0w5CpNy58XAuhrWEXpjVfeXtn99rYKbg4aubjVbMXJA= X-Google-Smtp-Source: AGHT+IE2C5BhArLhucm6UxlBmoiLDdxw8C7i4rKFzo5wgmOoa0CgKS8hgyUnXY2IZU8JTxf53yhotA== X-Received: by 2002:a5d:4b82:0:b0:374:babf:ac4f with SMTP id ffacd0b85a97d-378c2cfec6bmr4144046f8f.12.1726235873516; Fri, 13 Sep 2024 06:57:53 -0700 (PDT) Received: from neptune.lan ([188.27.129.88]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d3941sm17104749f8f.84.2024.09.13.06.57.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 06:57:53 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean Subject: [PATCH v6 3/8] iio: adc: ad7606: move scale_setup as function pointer on chip-info Date: Fri, 13 Sep 2024 16:57:38 +0300 Message-ID: <20240913135744.152669-4-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240913135744.152669-1-aardelean@baylibre.com> References: <20240913135744.152669-1-aardelean@baylibre.com> 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 Up until now, all ADCs were 16-bit precision. With the addition of the AD7606C some things will change. For one thing, we'll need to setup available-scales for each channel. Also for the 18-bit precision variants, the scales will be different. This change adds a function-pointer to the chip-info struct to be able to set this up (differently) for the new parts. For the current parts, the scales are the same (for all parts) between HW and SW modes. Also creating a 'ad7606_sw_mode_setup()' function that must be called before the scale_setup callback. This is needed in case SW mode is enabled for some ADCs. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 84 +++++++++++++++++++++++++++++----------- drivers/iio/adc/ad7606.h | 6 +++ 2 files changed, 68 insertions(+), 22 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 032a8135c912..7dc299aeee15 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -32,12 +32,12 @@ * Scales are computed as 5000/32768 and 10000/32768 respectively, * so that when applied to the raw values they provide mV values */ -static const unsigned int ad7606_scale_avail[2] =3D { +static const unsigned int ad7606_16bit_hw_scale_avail[2] =3D { 152588, 305176 }; =20 =20 -static const unsigned int ad7616_sw_scale_avail[3] =3D { +static const unsigned int ad7606_16bit_sw_scale_avail[3] =3D { 76293, 152588, 305176 }; =20 @@ -62,6 +62,25 @@ int ad7606_reset(struct ad7606_state *st) } EXPORT_SYMBOL_NS_GPL(ad7606_reset, IIO_AD7606); =20 +static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st, int ch) +{ + if (!st->sw_mode_en) { + /* tied to logic low, analog input range is +/- 5V */ + st->range[ch] =3D 0; + st->scale_avail =3D ad7606_16bit_hw_scale_avail; + st->num_scales =3D ARRAY_SIZE(ad7606_16bit_hw_scale_avail); + return 0; + } + + /* Scale of 0.076293 is only available in sw mode */ + /* After reset, in software mode, =C2=B110 V is set by default */ + st->range[ch] =3D 2; + st->scale_avail =3D ad7606_16bit_sw_scale_avail; + st->num_scales =3D ARRAY_SIZE(ad7606_16bit_sw_scale_avail); + + return 0; +} + static int ad7606_reg_access(struct iio_dev *indio_dev, unsigned int reg, unsigned int writeval, @@ -358,34 +377,40 @@ static const struct ad7606_chip_info ad7606_chip_info= _tbl[] =3D { [ID_AD7605_4] =3D { .channels =3D ad7605_channels, .num_channels =3D 5, + .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, }, [ID_AD7606_8] =3D { .channels =3D ad7606_channels_16bit, .num_channels =3D 9, + .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), }, [ID_AD7606_6] =3D { .channels =3D ad7606_channels_16bit, .num_channels =3D 7, + .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), }, [ID_AD7606_4] =3D { .channels =3D ad7606_channels_16bit, .num_channels =3D 5, + .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), }, [ID_AD7606B] =3D { .channels =3D ad7606_channels_16bit, .num_channels =3D 9, + .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), }, [ID_AD7616] =3D { .channels =3D ad7616_channels, .num_channels =3D 17, + .scale_setup_cb =3D ad7606_16bit_chan_scale_setup, .oversampling_avail =3D ad7616_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7616_oversampling_avail), .os_req_reset =3D true, @@ -523,6 +548,35 @@ static const struct iio_trigger_ops ad7606_trigger_ops= =3D { .validate_device =3D iio_trigger_validate_own_device, }; =20 +static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + + st->sw_mode_en =3D st->bops->sw_mode_config && + device_property_present(st->dev, "adi,sw-mode"); + if (!st->sw_mode_en) + return 0; + + indio_dev->info =3D &ad7606_info_os_range_and_debug; + + return st->bops->sw_mode_config(indio_dev); +} + +static int ad7606_chan_scales_setup(struct iio_dev *indio_dev) +{ + unsigned int num_channels =3D indio_dev->num_channels - 1; + struct ad7606_state *st =3D iio_priv(indio_dev); + int ch, ret; + + for (ch =3D 0; ch < num_channels; ch++) { + ret =3D st->chip_info->scale_setup_cb(st, ch); + if (ret) + return ret; + } + + return 0; +} + int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, const char *name, unsigned int id, const struct ad7606_bus_ops *bops) @@ -542,11 +596,7 @@ int ad7606_probe(struct device *dev, int irq, void __i= omem *base_address, mutex_init(&st->lock); st->bops =3D bops; st->base_address =3D base_address; - /* tied to logic low, analog input range is +/- 5V */ - st->range[0] =3D 0; st->oversampling =3D 1; - st->scale_avail =3D ad7606_scale_avail; - st->num_scales =3D ARRAY_SIZE(ad7606_scale_avail); =20 ret =3D devm_regulator_get_enable(dev, "avcc"); if (ret) @@ -595,23 +645,13 @@ int ad7606_probe(struct device *dev, int irq, void __= iomem *base_address, st->write_scale =3D ad7606_write_scale_hw; st->write_os =3D ad7606_write_os_hw; =20 - if (st->bops->sw_mode_config) - st->sw_mode_en =3D device_property_present(st->dev, - "adi,sw-mode"); - - if (st->sw_mode_en) { - /* Scale of 0.076293 is only available in sw mode */ - st->scale_avail =3D ad7616_sw_scale_avail; - st->num_scales =3D ARRAY_SIZE(ad7616_sw_scale_avail); - - /* After reset, in software mode, =C2=B110 V is set by default */ - memset32(st->range, 2, ARRAY_SIZE(st->range)); - indio_dev->info =3D &ad7606_info_os_range_and_debug; + ret =3D ad7606_sw_mode_setup(indio_dev); + if (ret) + return ret; =20 - ret =3D st->bops->sw_mode_config(indio_dev); - if (ret < 0) - return ret; - } + ret =3D ad7606_chan_scales_setup(indio_dev); + if (ret) + return ret; =20 st->trig =3D devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 204a343067e5..95f3b3cb0be3 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -40,10 +40,15 @@ =20 #define AD7616_CHANNEL(num) AD7606_SW_CHANNEL(num, 16) =20 +struct ad7606_state; + +typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st, int ch); + /** * struct ad7606_chip_info - chip specific information * @channels: channel specification * @num_channels: number of channels + * @scale_setup_cb: callback to setup the scales for each channel * @oversampling_avail pointer to the array which stores the available * oversampling ratios. * @oversampling_num number of elements stored in oversampling_avail array @@ -54,6 +59,7 @@ struct ad7606_chip_info { const struct iio_chan_spec *channels; unsigned int num_channels; + ad7606_scale_setup_cb_t scale_setup_cb; const unsigned int *oversampling_avail; unsigned int oversampling_num; bool os_req_reset; --=20 2.46.0 From nobody Sat Nov 30 00:37:29 2024 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 1EE7C1DEFC8 for ; Fri, 13 Sep 2024 13:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235879; cv=none; b=nd8yS2etZCWyGXxqKmpSM3z0v6nc1vuiiDOXb3SwKzkY0lOHIkLSrTQiDHieKT9iFf6AWJdIy84beNU2amWjkN3eCOhOJa3tKvMXRJfeWigTKj9f0vD5z5TIjFXtG6rssR3tcN7Qf8DlQhjjUZ+3a7ceTx2fuxMlVnvXB+qVQl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235879; c=relaxed/simple; bh=AiPTW+eC15hy8WCQnEhvb/1uaDdvGFA0NbdJznajRXU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pLjkeRfndSUia9XZRBrc174c8t257P4aV3AP8aPRmfrzHTMMeL+4RP+FUmBdthGDSxahzWzF/MJFgpoNkcirFxoh09L6GmKtcOw+gNjxGYQgxTr8b3+ASETmDonRzlnblN9bvWsI+EOVvtHeBoupn9fSsBh4su7xZ/Q3qo+jfzo= 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=iBNbwzm1; arc=none smtp.client-ip=209.85.128.49 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="iBNbwzm1" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-42cb1758e41so8799945e9.1 for ; Fri, 13 Sep 2024 06:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726235875; x=1726840675; darn=vger.kernel.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=WyNNlkM7L3gokB2vnij6JW+A3TweMpCxgtAx8xE2ujg=; b=iBNbwzm1e/oZb/b4NeMJyl1AD4Nv1u7USwuoT4Uvby+m+Vw0yYVC8SqueWuvx7BAzl ZksB5Kg2JUlFMkJNiEer16c1in9CAh/TkPknC5KgWIJXvzBq84VquDen1tQxb2tIffxW HcUBLau6XtAWvIAFndStzuig7SqfFmvwTnI0R7NQrMSVXf6aUxaKjDaIuBkVc7FxrSpu 5Gwiw51ykI55tnwtWbxRyM4eAM3LVOw1m4BpMa4LiHWmZGFFpmHsH0j9TUBR/K0lBROa ROPx7qlE7FlBpZtUB6qkArOnttjAAzzI8mGAlptoxF0rUIc1wFqX8d1HA18tVHGFugnR Ej7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726235875; x=1726840675; 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=WyNNlkM7L3gokB2vnij6JW+A3TweMpCxgtAx8xE2ujg=; b=EdZgjh5QPIopqquOyd/pZ1k/tdG0KhZe/+hAe+kaBd5BViNuq/Wk/hZhqnbWKVG7ok H6pz7lXr9Pqy5de6XHkiGzQ4RltNaqDiGFOpAyNPQ+j9IMdjWAbDuaVwqPd59Q0xcalz pu83YxXYz70lA+fQYHVupEeDhak5bvwN3yJSwbVEvhLP5szgV1r0UHgSHRpHXnf54Yqg M9CsbNJvKAXe7FvCagSTX14i1U0dx9unhxxmy6oNsgCna7YSkleDdfI6NeFI7imBHcNw 2Iu+Efu4n/dYp5JD9xk9yR3uWAtxgZCrKPR/gpkYR/Yr+9u7Ezl4K5WRoobrCgr7bqos yoWw== X-Forwarded-Encrypted: i=1; AJvYcCUENkpEW2B5yXJhKZYdGHFmRnjqzvW9fqGzSTivmds/a8zQSZvzxnWDuiyp5XrqGNY4bDIbi2FsWnuYOgc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2Eiwst7DrDjqIdsAwRfV8uDRKkVd/WLRRcRWsJFtUwQN/0cH/ uGPpOex7/t8hIRlfZ0ekVrcBdtd6t3y5mlQ9QPh2XGBBD3f+5au2LTcjxPIH8XI= X-Google-Smtp-Source: AGHT+IGv8RHBWrECjrXOKldME62lsBmNivGoVXAKsUStftQtY+4xoTqDtKqRAyrttnbq0zXmAf9NpQ== X-Received: by 2002:a5d:6da6:0:b0:374:cd96:f73 with SMTP id ffacd0b85a97d-378d61d51bcmr1961956f8f.3.1726235875249; Fri, 13 Sep 2024 06:57:55 -0700 (PDT) Received: from neptune.lan ([188.27.129.88]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d3941sm17104749f8f.84.2024.09.13.06.57.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 06:57:54 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean Subject: [PATCH v6 4/8] iio: adc: ad7606: wrap channel ranges & scales into struct Date: Fri, 13 Sep 2024 16:57:39 +0300 Message-ID: <20240913135744.152669-5-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240913135744.152669-1-aardelean@baylibre.com> References: <20240913135744.152669-1-aardelean@baylibre.com> 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 With the addition of AD7606C-16,18 which have differential & bipolar channels (and ranges), which can vary from channel to channel, we'll need to keep more information about each channel range. To do that, we'll add a 'struct ad7606_chan_scale' type to hold just configuration for each channel. This includes the scales per channel (which can be different with AD7606C-16,18), as well as the range for each channel. This driver was already keeping the range value for each channel before, and since this is couple with the scales, it also makes sense to put them in the same struct. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 29 ++++++++++++++++++----------- drivers/iio/adc/ad7606.h | 22 ++++++++++++++++------ 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 7dc299aeee15..94a254c0725e 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -64,19 +64,21 @@ EXPORT_SYMBOL_NS_GPL(ad7606_reset, IIO_AD7606); =20 static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st, int ch) { + struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + if (!st->sw_mode_en) { /* tied to logic low, analog input range is +/- 5V */ - st->range[ch] =3D 0; - st->scale_avail =3D ad7606_16bit_hw_scale_avail; - st->num_scales =3D ARRAY_SIZE(ad7606_16bit_hw_scale_avail); + cs->range =3D 0; + cs->scale_avail =3D ad7606_16bit_hw_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7606_16bit_hw_scale_avail); return 0; } =20 /* Scale of 0.076293 is only available in sw mode */ /* After reset, in software mode, =C2=B110 V is set by default */ - st->range[ch] =3D 2; - st->scale_avail =3D ad7606_16bit_sw_scale_avail; - st->num_scales =3D ARRAY_SIZE(ad7606_16bit_sw_scale_avail); + cs->range =3D 2; + cs->scale_avail =3D ad7606_16bit_sw_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7606_16bit_sw_scale_avail); =20 return 0; } @@ -167,6 +169,7 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, { int ret, ch =3D 0; struct ad7606_state *st =3D iio_priv(indio_dev); + struct ad7606_chan_scale *cs; =20 switch (m) { case IIO_CHAN_INFO_RAW: @@ -180,8 +183,9 @@ static int ad7606_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_SCALE: if (st->sw_mode_en) ch =3D chan->address; + cs =3D &st->chan_scales[ch]; *val =3D 0; - *val2 =3D st->scale_avail[st->range[ch]]; + *val2 =3D cs->scale_avail[cs->range]; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: *val =3D st->oversampling; @@ -211,8 +215,9 @@ static ssize_t in_voltage_scale_available_show(struct d= evice *dev, { struct iio_dev *indio_dev =3D dev_to_iio_dev(dev); struct ad7606_state *st =3D iio_priv(indio_dev); + struct ad7606_chan_scale *cs =3D &st->chan_scales[0]; =20 - return ad7606_show_avail(buf, st->scale_avail, st->num_scales, true); + return ad7606_show_avail(buf, cs->scale_avail, cs->num_scales, true); } =20 static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0); @@ -250,19 +255,21 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, long mask) { struct ad7606_state *st =3D iio_priv(indio_dev); + struct ad7606_chan_scale *cs; int i, ret, ch =3D 0; =20 guard(mutex)(&st->lock); =20 switch (mask) { case IIO_CHAN_INFO_SCALE: - i =3D find_closest(val2, st->scale_avail, st->num_scales); if (st->sw_mode_en) ch =3D chan->address; + cs =3D &st->chan_scales[ch]; + i =3D find_closest(val2, cs->scale_avail, cs->num_scales); ret =3D st->write_scale(indio_dev, ch, i); if (ret < 0) return ret; - st->range[ch] =3D i; + cs->range =3D i; =20 return 0; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: @@ -707,7 +714,7 @@ static int ad7606_resume(struct device *dev) struct ad7606_state *st =3D iio_priv(indio_dev); =20 if (st->gpio_standby) { - gpiod_set_value(st->gpio_range, st->range[0]); + gpiod_set_value(st->gpio_range, st->chan_scales[0].range); gpiod_set_value(st->gpio_standby, 1); ad7606_reset(st); } diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 95f3b3cb0be3..2b90f52affba 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -8,6 +8,8 @@ #ifndef IIO_ADC_AD7606_H_ #define IIO_ADC_AD7606_H_ =20 +#define AD760X_MAX_CHANNELS 16 + #define AD760X_CHANNEL(num, mask_sep, mask_type, mask_all, bits) { \ .type =3D IIO_VOLTAGE, \ .indexed =3D 1, \ @@ -66,17 +68,27 @@ struct ad7606_chip_info { unsigned long init_delay_ms; }; =20 +/** + * struct ad7606_chan_scale - channel scale configuration + * @scale_avail pointer to the array which stores the available scales + * @num_scales number of elements stored in the scale_avail array + * @range voltage range selection, selects which scale to apply + */ +struct ad7606_chan_scale { + const unsigned int *scale_avail; + unsigned int num_scales; + unsigned int range; +}; + /** * struct ad7606_state - driver instance specific data * @dev pointer to kernel device * @chip_info entry in the table of chips that describes this device * @bops bus operations (SPI or parallel) - * @range voltage range selection, selects which scale to apply + * @chan_scales scale configuration for channels * @oversampling oversampling selection * @base_address address from where to read data in parallel operation * @sw_mode_en software mode enabled - * @scale_avail pointer to the array which stores the available scales - * @num_scales number of elements stored in the scale_avail array * @oversampling_avail pointer to the array which stores the available * oversampling ratios. * @num_os_ratios number of elements stored in oversampling_avail array @@ -100,12 +112,10 @@ struct ad7606_state { struct device *dev; const struct ad7606_chip_info *chip_info; const struct ad7606_bus_ops *bops; - unsigned int range[16]; + struct ad7606_chan_scale chan_scales[AD760X_MAX_CHANNELS]; unsigned int oversampling; void __iomem *base_address; bool sw_mode_en; - const unsigned int *scale_avail; - unsigned int num_scales; const unsigned int *oversampling_avail; unsigned int num_os_ratios; int (*write_scale)(struct iio_dev *indio_dev, int ch, int val); --=20 2.46.0 From nobody Sat Nov 30 00:37:29 2024 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 74D931DFE1A for ; Fri, 13 Sep 2024 13:57:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235880; cv=none; b=rNZnLDT8I36ysGiw9GUcV/Zid1BvKk+QNAEEzEdDx4bx9iTikSPAUt1XvvcLl/NMc5T4YPNqLUJXuKa9T8LWlhAAdUzskWEU7J//cTBc1xCAtAScAReh+lOZZMPwwjenOrF/E1hbC8sJPCrwwd1dtXos6EGm4dz1EPSFkl718oI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235880; c=relaxed/simple; bh=RzKqVRTlU4lc2tQgU6jZrPJ/xkgEk5frw6b90nEo2eQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SQO3+KIDkn8GIJSbVtBprhqyfDN+n7hgiEG8k3PXZm1aZOIF4Vyf9D64cmwCNFgUKoZz0sSkV01SmJR2Bca2g2SxF6UQULDyur8+9vYLGJz+o1/Bqx84CrX+gbLNk1UBVTjLgPsej9dVjTmpNcVvJSQa0mBFJb+KW1BhS0Hy9sk= 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=S1qNOCpR; arc=none smtp.client-ip=209.85.128.46 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="S1qNOCpR" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-42cb1e623d1so21448485e9.0 for ; Fri, 13 Sep 2024 06:57:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726235877; x=1726840677; darn=vger.kernel.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=d3L8FUnehujX20iEAFhi39bqT6dZ8dbQps0T02oejwI=; b=S1qNOCpRcSabwZOQQEvBZF1EndXw59hvqxTN/0GMheXoS7Iq9x+i66l104GO00sgCl TEjm3Es+729uhOjBgLirBtfHZEX+Ok9cGUovDIEEIAXPIC+zUERT3JJw79TuPHqJZabA Fbu4QGF12PgiN4j35KGe/SMBYr1zxbOSk/SL5/G/urMRPlw7esDAoIzwK92Us3y78hXj 2LrZDpGuV7OFLKt6rBiDtWPb4uN7NS/Tq42WKwA5m4ZhmtnFqFy0EtpaYetDD2Tm3rCr gyY3P9aIbM7l8Mr0TFQtzpLQPB4J8ZMQZavBIdKDd0ukxsNGPXoX8Rhf3eP39dVeDBfN A2TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726235877; x=1726840677; 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=d3L8FUnehujX20iEAFhi39bqT6dZ8dbQps0T02oejwI=; b=ruE3x3mr80jxyHiC7URL5LEeybKmU/aiLWt1m8O3IL6zSsZjyuRZKX4QyxVXbOXTmz loivdjFe1lw/N8tpRGAZQpqRcjqzHN8VB3SneCJHGCbsc//hpMw0Wf3zTRRijJc3m0W/ ga3R0oAtVlmDKDI6b4qYzFnuMw36/4yB1dlKwuFXsPxDfzsbPV8wwuPvCy4y5J/A035Y CSREqCSG1sU7Dj2uaXN9nu7841pjRyJV3vVkFCOV+8wOX6Z2g8hS4stSf3j8O3WYLd0c 8BIUzOuAdreB7mki8LsIu3vgAqGNGTRq8wzwvhNi7+ZsHiI7cp8t9Ls7c9cdu7XNHBBe Fmlg== X-Forwarded-Encrypted: i=1; AJvYcCVnGYjXhRr6uKtmKXyZlT9RPV1r6i2kgs2jO4v1/gZZC9qyFm09J9/zw73nMt1Cv0NljQBK4AqWTPjRMRg=@vger.kernel.org X-Gm-Message-State: AOJu0YzHwlLAgJygXArieRjdIiH0DokhWxRPobZNpqswnIHm6dCOm60/ xtrq1Lb54PPJ8YkTJzICEwkn4oezDeBZ6n18qVGrl9+pLSwEAqgikux6lrNbx7I= X-Google-Smtp-Source: AGHT+IEkI2KSw85IDTMbbhjtAvbfk8iwC6Thl/9VxphrlV2HxZV8p7CBZsprMsDXFbTh9L2M0wRbSw== X-Received: by 2002:adf:ed08:0:b0:377:2ce0:a760 with SMTP id ffacd0b85a97d-378c2d5530bmr3992276f8f.49.1726235876633; Fri, 13 Sep 2024 06:57:56 -0700 (PDT) Received: from neptune.lan ([188.27.129.88]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d3941sm17104749f8f.84.2024.09.13.06.57.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 06:57:56 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean Subject: [PATCH v6 5/8] iio: adc: ad7606: rework available attributes for SW channels Date: Fri, 13 Sep 2024 16:57:40 +0300 Message-ID: <20240913135744.152669-6-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240913135744.152669-1-aardelean@baylibre.com> References: <20240913135744.152669-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For SW mode, the oversampling and scales attributes are always present. So, they can be implemented via a 'read_avail' hook in iio_info. For HW mode, it's a bit tricky, as these attributes get assigned based on GPIO definitions. So, for SW mode, we define a separate AD7606_SW_CHANNEL() macro, and use that for the SW channels. And 'ad7606_info_os_range_and_debug' can be renamed to 'ad7606_info_sw_mode' as it is only used for SW mode. For the 'read_avail' hook, we'll need to allocate the SW scales, so that they are just returned userspace without any extra processing. The allocation will happen when then ad7606_state struct is allocated. The oversampling available parameters don't need any extra processing; they can just be passed back to userspace (as they are). Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 52 ++++++++++++++++++++++++++++++++++--- drivers/iio/adc/ad7606.h | 32 ++++++++++++++++++++--- drivers/iio/adc/ad7606_spi. | 0 3 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 drivers/iio/adc/ad7606_spi. diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 94a254c0725e..b909ee14fd81 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -512,6 +512,37 @@ static int ad7606_buffer_predisable(struct iio_dev *in= dio_dev) return 0; } =20 +static int ad7606_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long info) +{ + struct ad7606_state *st =3D iio_priv(indio_dev); + struct ad7606_chan_scale *cs; + unsigned int ch =3D 0; + + switch (info) { + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + *vals =3D st->oversampling_avail; + *length =3D st->num_os_ratios; + *type =3D IIO_VAL_INT; + + return IIO_AVAIL_LIST; + + case IIO_CHAN_INFO_SCALE: + if (st->sw_mode_en) + ch =3D chan->address; + + cs =3D &st->chan_scales[ch]; + *vals =3D cs->scale_avail_show; + *length =3D cs->num_scales * 2; + *type =3D IIO_VAL_INT_PLUS_MICRO; + + return IIO_AVAIL_LIST; + } + return -EINVAL; +} + static const struct iio_buffer_setup_ops ad7606_buffer_ops =3D { .postenable =3D &ad7606_buffer_postenable, .predisable =3D &ad7606_buffer_predisable, @@ -529,11 +560,11 @@ static const struct iio_info ad7606_info_os_and_range= =3D { .validate_trigger =3D &ad7606_validate_trigger, }; =20 -static const struct iio_info ad7606_info_os_range_and_debug =3D { +static const struct iio_info ad7606_info_sw_mode =3D { .read_raw =3D &ad7606_read_raw, .write_raw =3D &ad7606_write_raw, + .read_avail =3D &ad7606_read_avail, .debugfs_reg_access =3D &ad7606_reg_access, - .attrs =3D &ad7606_attribute_group_os_and_range, .validate_trigger =3D &ad7606_validate_trigger, }; =20 @@ -564,7 +595,7 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio_d= ev) if (!st->sw_mode_en) return 0; =20 - indio_dev->info =3D &ad7606_info_os_range_and_debug; + indio_dev->info =3D &ad7606_info_sw_mode; =20 return st->bops->sw_mode_config(indio_dev); } @@ -576,9 +607,24 @@ static int ad7606_chan_scales_setup(struct iio_dev *in= dio_dev) int ch, ret; =20 for (ch =3D 0; ch < num_channels; ch++) { + struct ad7606_chan_scale *cs; + int i; + ret =3D st->chip_info->scale_setup_cb(st, ch); if (ret) return ret; + + cs =3D &st->chan_scales[ch]; + + if (cs->num_scales * 2 > AD760X_MAX_SCALE_SHOW) + return dev_err_probe(st->dev, -ERANGE, + "Driver error: scale range too big"); + + /* Generate a scale_avail list for showing to userspace */ + for (i =3D 0; i < cs->num_scales; i++) { + cs->scale_avail_show[i * 2] =3D 0; + cs->scale_avail_show[i * 2 + 1] =3D cs->scale_avail[i]; + } } =20 return 0; diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 2b90f52affba..25e84efd15c3 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -27,6 +27,29 @@ }, \ } =20 +#define AD7606_SW_CHANNEL(num, bits) { \ + .type =3D IIO_VOLTAGE, \ + .indexed =3D 1, \ + .channel =3D num, \ + .address =3D num, \ + .info_mask_separate =3D \ + BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_separate_available =3D \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_all =3D \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .info_mask_shared_by_all_available =3D \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .scan_index =3D num, \ + .scan_type =3D { \ + .sign =3D 's', \ + .realbits =3D (bits), \ + .storagebits =3D (bits) > 16 ? 32 : 16, \ + .endianness =3D IIO_CPU, \ + }, \ +} + #define AD7605_CHANNEL(num) \ AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW), \ BIT(IIO_CHAN_INFO_SCALE), 0, 16) @@ -36,10 +59,6 @@ BIT(IIO_CHAN_INFO_SCALE), \ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), bits) =20 -#define AD7606_SW_CHANNEL(num, bits) \ - AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),\ - 0, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), bits) - #define AD7616_CHANNEL(num) AD7606_SW_CHANNEL(num, 16) =20 struct ad7606_state; @@ -71,11 +90,16 @@ struct ad7606_chip_info { /** * struct ad7606_chan_scale - channel scale configuration * @scale_avail pointer to the array which stores the available scales + * @scale_avail_show a duplicate of 'scale_avail' which is readily formatt= ed + * such that it can be read via the 'read_avail' hook * @num_scales number of elements stored in the scale_avail array * @range voltage range selection, selects which scale to apply */ struct ad7606_chan_scale { +#define AD760X_MAX_SCALES 16 +#define AD760X_MAX_SCALE_SHOW (AD760X_MAX_SCALES * 2) const unsigned int *scale_avail; + int scale_avail_show[AD760X_MAX_SCALE_SHOW]; unsigned int num_scales; unsigned int range; }; diff --git a/drivers/iio/adc/ad7606_spi. b/drivers/iio/adc/ad7606_spi. new file mode 100644 index 000000000000..e69de29bb2d1 --=20 2.46.0 From nobody Sat Nov 30 00:37:29 2024 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 BE1E21E0085 for ; Fri, 13 Sep 2024 13:57:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235881; cv=none; b=AwdzXkqfZyj0L9Qezm7DYc3yIlTITetx9iocuZIuRTEFYGmboOc/7sHrsTy/yJ1jsU4zGXijZY13iD4TT14qC1EZ04WVrgUjCtIGfxyszLNYxT+MqVIhcewy1zVlF+4THT1Bw4HYikjkMnsRXf11V9EpL0+WeyTzfdhPYgdhd+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235881; c=relaxed/simple; bh=/ovmFlVD/7j+ipJY0VPXyzdNP1zhe/wqKiyGk4ajqgM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eEWOv+OLKDjDYZwFa8Dy6aiuEWH38P9rXb2Woc4SyWz9Ov+7KN97qjbvpJigvXW/TlIoc/93RCVNEtXR9AJDCS6KvGhTPz1bt9AQIDJpEYGyN3kMGFyvpFm4psIVPJTx80DdH/Z76U+vvPEij6J+yggFcYYzq7SH1+XPm0LqlEQ= 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=qhrOy5Df; arc=none smtp.client-ip=209.85.221.46 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="qhrOy5Df" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-374b9761eecso1729178f8f.2 for ; Fri, 13 Sep 2024 06:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726235878; x=1726840678; darn=vger.kernel.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=g46xgvcRuzluvD9uFfVgOC6tB6SvIHIhrOwQLDjP3Ko=; b=qhrOy5DftY8E5YlAyhsJr4ch+KnN7MHNJ6zvz0N+JXZeqZjRbqA9ePTgU+p0GC5Tls +iCY7CMLEi5TS+2lCt1+T3OwqP0sh9VosbxQAOOvyiPmGTTHmQTNBWyrbkfMt5yPldjh fSBk67Zpffkf/HgPUy3rrw1soGe6BW3VPRIsQ3fRYxZ/W+dJjezMd1CM5t13SXtlCZ8e 5tnXBg/n5Ed+Q4v5w0NjINlIp+ajmXcoo1rFmo5EKnRZhAyskXlfh9k/31huzuZofA7d 7kyecAgLh69fNOiNNHlq9rq9Ypwe7O9G7bxZtJlSJ5gsD/giKxtdO6E4YuWzPsgM/4ei TZVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726235878; x=1726840678; 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=g46xgvcRuzluvD9uFfVgOC6tB6SvIHIhrOwQLDjP3Ko=; b=J888Kvo0Fh7wjWIb6FQxtAtTOHipIriL69zwZlqbW97ZsEeGFXmJlI1EahXvxFpUCX gTxGBdxDe4qnz5jn7NVAsWW23mPEwKz0TWZ+qIn59CpZlqGCoUinFaU5NjQO3SInNShF OlQ2MY2UPwJxfZ2ze/0YvyzFC7OyohJWjzGlT99l3Db8rrX7A9RRD2qH+TizIOANdcd4 wP4oYSXR94J7hxKMFfyG8dqyuXQAlZMwdX/1eg3E9Kd4e0vzEGnzkPs0z0gK6LbCQrT2 CyDi84r7CkVpxGiiYXZtAdannZSfsfrj6OjMfwXwdVwPxjCBxHG7VELaA2qakrdlA5rV EPMQ== X-Forwarded-Encrypted: i=1; AJvYcCUD9O8tCqBdnZVbKvD7EqAC+G58F4/eSZ1zlUDMwFKF1TuQKt4VDbhWQC59NcuJutk1Xs+WSAVCt1A8ZMo=@vger.kernel.org X-Gm-Message-State: AOJu0YzFl7Z1/Fhj1S3slkyF/ZCeE/tv8PdRma7CCEgUuvqy0FQO6Vu6 WGOjQuk6gMTBjuW4en9HX1DsVeL4oDhqGqdyaUKPkKFY8tRAuQtUqTcpf3d4x2Q= X-Google-Smtp-Source: AGHT+IFcysEod0NxncaxDd4SBio0xzbV0cHz5ucPvVZFdGqB2E7WOEJARnDjPv23bNoUkmOyAClF0w== X-Received: by 2002:adf:ea8c:0:b0:368:7583:54c7 with SMTP id ffacd0b85a97d-378c2cd3e6amr3985869f8f.8.1726235878002; Fri, 13 Sep 2024 06:57:58 -0700 (PDT) Received: from neptune.lan ([188.27.129.88]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d3941sm17104749f8f.84.2024.09.13.06.57.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 06:57:57 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean , Krzysztof Kozlowski Subject: [PATCH v6 6/8] dt-bindings: iio: adc: document diff-channels corner case for some ADCs Date: Fri, 13 Sep 2024 16:57:41 +0300 Message-ID: <20240913135744.152669-7-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240913135744.152669-1-aardelean@baylibre.com> References: <20240913135744.152669-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some ADCs have channels with negative and positive inputs, which can be used to measure differential voltage levels. These inputs/pins are dedicated (to the given channel) and cannot be muxed as with other ADCs. For those types of setups, the 'diff-channels' property can be specified to be used with the channel number (or reg property) for both negative and positive inputs/pins. Reviewed-by: Krzysztof Kozlowski Signed-off-by: Alexandru Ardelean --- Documentation/devicetree/bindings/iio/adc/adc.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/adc.yaml b/Documenta= tion/devicetree/bindings/iio/adc/adc.yaml index 8e7835cf36fd..b9bc02b5b07a 100644 --- a/Documentation/devicetree/bindings/iio/adc/adc.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adc.yaml @@ -37,6 +37,10 @@ properties: to both the positive and negative inputs of a differential ADC. The first value specifies the positive input pin, the second specifies the negative input pin. + There are also some ADCs, where the differential channel has dedicat= ed + positive and negative inputs which can be used to measure differenti= al + voltage levels. For those setups, this property can be configured wi= th + the 'reg' property for both inputs (i.e. diff-channels =3D = ). =20 single-channel: $ref: /schemas/types.yaml#/definitions/uint32 --=20 2.46.0 From nobody Sat Nov 30 00:37:29 2024 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 8A1971E00B0 for ; Fri, 13 Sep 2024 13:58:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235883; cv=none; b=TxHQBGX5i6onyCRJpUhUW/ZuB2xpKMoLn73JME2O9mNA9bmnTKF1tx8wKXjkiK08RX3ZGaoBe98yqJIvf4CyAkBA6hNlyqtfEMcjj2ycnm7mEA1EhY89B11/zaysLFbUoJh4Nu438ViSrvuYoUksJMtJWWv8Qk0v10k5yVzHooQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235883; c=relaxed/simple; bh=GQdyZWqzfnQT3hAZa3L+fZIM4t+AoyLa8IiB5e8peIs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WkuSNxHTgC/xM0bVV6Pxl9JhSvaO+EGY61l5X6PzbE+WK4x+WIki3RQF5htJg0+Z9q17V0DqbgQ+BadU7IMnJzhL4yQYq/kxVy8QNoK4tiP6z44B2Txfg98gAPjFWie6LwkIlvkThCfz1wyQnH9uBz3jFHMwUCpMD/aL8RHBoIo= 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=zAKV3ZPL; arc=none smtp.client-ip=209.85.221.52 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="zAKV3ZPL" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-374ca65cafdso675579f8f.2 for ; Fri, 13 Sep 2024 06:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726235880; x=1726840680; darn=vger.kernel.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=G7id2uNYW2O+D+9KmRKjfLk5jRelw+ydc8eaTsKnZHc=; b=zAKV3ZPLLWbewRoFvPloAhbvijnkgbxV32M2cXzSfv+JADXNnsvTUdtmMSK7mKhzMS aav+9ilRrISfetLpPRfFzy1iBg8GjKDiDbxuMAkteIgmb7E5QeedyATvipa2m7o0cZl6 6EFglQGr7NhKCJc9X7t1Pluy38MsZOnLiaziZs3FX043HRNs4OdkE8VHPw/P+WooS0vB XlckFHjcumUkbO0cnwSuJq+m/fElBQDb9icjDYT8sKpmlgOku1TEaLs9NrtxCsVf0ctx am8kNC4bwuPGzCNL+qZ+yR3HJlsfGFDUoSPU5AnpH7cKblM+V6eiMVYa16pvS+89qIUd g0Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726235880; x=1726840680; 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=G7id2uNYW2O+D+9KmRKjfLk5jRelw+ydc8eaTsKnZHc=; b=P7/gUvjpbBsBue6y42i+H5hQsTeI0Un2YA9BuTZBPg1Ii/gEm1NjC1pst/cPfg1+sY OtiLHr2OOnqf1OykrcfGAQqK8zpCcovXXA6MCzauzQADlyO2HDZ+7qJowYH/TqHhV6Zo hx+EFtEQaW2v0ofAWrAwFseT9Sn7IZxXBarDwqE9DPKElV+pqa5PUHe+k2gcOVc+UwZM qwmzuiPNR8Z+9QBXCZNRWY+iedWWuD1ay3YnLJHkBRZ0yVZ5Pg690nHha5jhIxLdEAoY bmvR1v8LOv0hWgcH1py772V+pD4rgt59J2YdtUNnebDJmgovBx9F1VMT+dPGiRljyqq/ pb/w== X-Forwarded-Encrypted: i=1; AJvYcCWyUvbkfJxRhzrAiEuPBjPNg6ZhrNAgQGtVyF48f4IpofGJ8xXxG53bYQKLOdvaBlU8u4k/toeiaRJNpq4=@vger.kernel.org X-Gm-Message-State: AOJu0YxK8+2wUE2yPu7FxduqmQwre51GtE1KoCygnjfRigssssneU9RQ ncqyQw/Cot/7sh+h/BZ9CnUQtjGY4fKXTrN3DxfDDq54L1LJr8w2ESdIkLkCVIS0CHWeugBORxW mAe0= X-Google-Smtp-Source: AGHT+IEnMOy/us1WMCDm1uQTWUXvboHtKWEVOeATyWAagk22igiC4OpFI/i1oBSsRNFaX/qPXg4Mjg== X-Received: by 2002:a05:6000:1802:b0:374:c9cd:9bf4 with SMTP id ffacd0b85a97d-378d62537demr1697313f8f.52.1726235879673; Fri, 13 Sep 2024 06:57:59 -0700 (PDT) Received: from neptune.lan ([188.27.129.88]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d3941sm17104749f8f.84.2024.09.13.06.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 06:57:59 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean , Krzysztof Kozlowski Subject: [PATCH v6 7/8] dt-bindings: iio: adc: add docs for AD7606C-{16,18} parts Date: Fri, 13 Sep 2024 16:57:42 +0300 Message-ID: <20240913135744.152669-8-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240913135744.152669-1-aardelean@baylibre.com> References: <20240913135744.152669-1-aardelean@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The driver will support the AD7606C-16 and AD7606C-18. This change adds the compatible strings for these devices. The AD7606C-16,18 channels also support these (individually configurable) types of channels: - bipolar single-ended - unipolar single-ended - bipolar differential Reviewed-by: Krzysztof Kozlowski Signed-off-by: Alexandru Ardelean --- .../bindings/iio/adc/adi,ad7606.yaml | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml b/Do= cumentation/devicetree/bindings/iio/adc/adi,ad7606.yaml index 69408cae3db9..bec7cfba52a7 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml @@ -14,6 +14,8 @@ description: | https://www.analog.com/media/en/technical-documentation/data-sheets/AD76= 05-4.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/ad76= 06_7606-6_7606-4.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD76= 06B.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad76= 06c-16.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/ad76= 06c-18.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD76= 16.pdf =20 properties: @@ -24,11 +26,19 @@ properties: - adi,ad7606-6 - adi,ad7606-8 # Referred to as AD7606 (without -8) in the datasheet - adi,ad7606b + - adi,ad7606c-16 + - adi,ad7606c-18 - adi,ad7616 =20 reg: maxItems: 1 =20 + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + spi-cpha: true =20 spi-cpol: true @@ -114,6 +124,47 @@ properties: assumed that the pins are hardwired to VDD. type: boolean =20 +patternProperties: + "^channel@[1-8]$": + type: object + $ref: adc.yaml + unevaluatedProperties: false + + properties: + reg: + description: + The channel number, as specified in the datasheet (from 1 to 8). + minimum: 1 + maximum: 8 + + diff-channels: + description: + Each channel can be configured as a bipolar differential channel. + The ADC uses the same positive and negative inputs for this. + This property must be specified as 'reg' (or the channel number)= for + both positive and negative inputs (i.e. diff-channels =3D ). + Since the configuration is bipolar differential, the 'bipolar' + property is required. + items: + minimum: 1 + maximum: 8 + + bipolar: + description: + The ADC channels can be configured as + * Bipolar single-ended + * Unipolar single-ended + * Bipolar differential + Therefore in the DT, if no channel node is specified, it is cons= idered + 'unipolar single-ended'. So for the other configurations the 'bi= polar' + property must be specified. If 'diff-channels' is specified, it = is + considered a bipolar differential channel. Otherwise it is bipol= ar + single-ended. + + required: + - reg + - bipolar + required: - compatible - reg @@ -170,6 +221,25 @@ allOf: adi,conversion-start-gpios: maxItems: 1 =20 + - if: + not: + required: + - adi,sw-mode + then: + patternProperties: + "^channel@[1-8]$": false + + - if: + not: + properties: + compatible: + enum: + - adi,ad7606c-16 + - adi,ad7606c-18 + then: + patternProperties: + "^channel@[1-8]$": false + unevaluatedProperties: false =20 examples: @@ -202,4 +272,54 @@ examples: standby-gpios =3D <&gpio 24 GPIO_ACTIVE_LOW>; }; }; + - | + #include + #include + spi { + #address-cells =3D <1>; + #size-cells =3D <0>; + + adc@0 { + compatible =3D "adi,ad7606c-18"; + reg =3D <0>; + + #address-cells =3D <1>; + #size-cells =3D <0>; + + spi-max-frequency =3D <1000000>; + spi-cpol; + spi-cpha; + + avcc-supply =3D <&adc_vref>; + vdrive-supply =3D <&vdd_supply>; + + interrupts =3D <25 IRQ_TYPE_EDGE_FALLING>; + interrupt-parent =3D <&gpio>; + + adi,conversion-start-gpios =3D <&gpio 17 GPIO_ACTIVE_HIGH>; + reset-gpios =3D <&gpio 27 GPIO_ACTIVE_HIGH>; + adi,first-data-gpios =3D <&gpio 22 GPIO_ACTIVE_HIGH>; + standby-gpios =3D <&gpio 24 GPIO_ACTIVE_LOW>; + + adi,sw-mode; + + channel@1 { + reg =3D <1>; + diff-channels =3D <1 1>; + bipolar; + }; + + channel@3 { + reg =3D <3>; + bipolar; + }; + + channel@8 { + reg =3D <8>; + diff-channels =3D <8 8>; + bipolar; + }; + + }; + }; ... --=20 2.46.0 From nobody Sat Nov 30 00:37:29 2024 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 14F051E0B80 for ; Fri, 13 Sep 2024 13:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235886; cv=none; b=GS+bmu+Dg2DX3zfJXrFGLNZRLVY78wgjpV338WVgCrp1UJ58JW7oWtHlEA2wacV4hi89I5LGpvMnQSFKMb06HtSU4YyRNjRoxj4Zew8UCesoCq3dQwAKDZ7d2TMMkQZkzNmb4Lb9x6jLN2kqOATuXiXRJrENPN2dvp/yqBWOc9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726235886; c=relaxed/simple; bh=XgpeTnvMDEHJ2up7eslboA9Mw83GfNdKf/s9hSi6q78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lhI+ZUWXV0LO+y275NITrGVvF79oqW65G56UbPCHtgRrCeK7sCvs5eKZTukf7FFt368YEtVZBY7apx9QfEueADZED1iLWveC6+qKvVU3ahKnbODK0aH5bp/zcKddas01MCJYm975yUYdZd7QMaSQydi2xY6+3lFWDXYe0f2Z8do= 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=v2BuMXoS; arc=none smtp.client-ip=209.85.128.49 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="v2BuMXoS" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-42cb57f8b41so13002865e9.0 for ; Fri, 13 Sep 2024 06:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726235881; x=1726840681; darn=vger.kernel.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=I8bsqmRCEvF7Nbt+K3TdbmlNSXTYPN2a62D7XH3DokY=; b=v2BuMXoSHXyKnY6LvPWyRRfr866ws9FhF1tA9baqEbe9SanQIVeSthAg3nLFlYfnQh +On+inoVWh5OEVvIyjA2QoiDTZgxjGv5vcdvV3Ghc+1TzszGrVIosDI3Uc0hFOtCaUXk 20zC80N3aSbwG1bUcx+xO83RhhLvO9pjuKbqwlxKLovdg40TDt0+D0VkbbxYyG/rDGl1 und9aT0JUZWAgaceNnmAICkg/XL4IBG99VBUZitG5VHrvlkL6Wz8VbNBJtAF5CKfBVY+ 4tw/tWwikkoyko/KsWq8OAgpx0udgecIrbGl+HCqEh/FI+qdvK28ZwoDLrLWFgTTYFl0 trJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726235881; x=1726840681; 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=I8bsqmRCEvF7Nbt+K3TdbmlNSXTYPN2a62D7XH3DokY=; b=dNA7LE6YzeeMLYGipcl8Jj/6qRKWnbm9ntlFKAcgZw0RqmVhhfP+PHsln+79V4460a iVR90owO+SR2qlszlcHWMZ02JVoPOGyT8MzhsDcQbmjh4vFHYq8vwepnPLUfEke3JkQX KjiMyAdfff0d21gNgtL4qWTvBV3kDSDPd98pqg86Hs/82QJ3MQLpzn694I6e/p6j+tmq +VJIqwxlu6Dp2xqq4lk/DDuTwrQhoMaVAIqhKQHg0rI+XfF5Po8F2HAR9ZgM2q91RoFQ BJbqklsN9tDZAiVNwqZ7x1GZnYJbL1UU4DLAeBZ/LXtIE/FxGXnzvsTPiiRIDtmoRpO+ pksg== X-Forwarded-Encrypted: i=1; AJvYcCUwyHPq0T2BCMr9ZH54jMOVK4F44xyX4QxBbLctVHtB2z3M0yGDo5E+v+C8nLioKEJZp3K0myI+ENMb6yc=@vger.kernel.org X-Gm-Message-State: AOJu0YxgzJ6DkVMEDzqbIHYvWDcciLj22MtWH2RyBpg8q5Rup2KaftyN 3XgaOf3+cH00luHzfloOSF4dmwOz9TKiU4MUnYWMvgkRGeEftj6VxRKdK113g48= X-Google-Smtp-Source: AGHT+IFflMFCS+xdBg642xa0xr8474DMWBegMZD96iruMYnsX1tOnCS8fBFd/nCvWVsO4HU9jrEloQ== X-Received: by 2002:a05:6000:c89:b0:374:c5b4:1be0 with SMTP id ffacd0b85a97d-378d62449c6mr1934680f8f.53.1726235881117; Fri, 13 Sep 2024 06:58:01 -0700 (PDT) Received: from neptune.lan ([188.27.129.88]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d3941sm17104749f8f.84.2024.09.13.06.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 06:58:00 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: jic23@kernel.org, krzk+dt@kernel.org, robh@kernel.org, lars@metafoo.de, michael.hennerich@analog.com, gstols@baylibre.com, dlechner@baylibre.com, Alexandru Ardelean Subject: [PATCH v6 8/8] iio: adc: ad7606: add support for AD7606C-{16,18} parts Date: Fri, 13 Sep 2024 16:57:43 +0300 Message-ID: <20240913135744.152669-9-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240913135744.152669-1-aardelean@baylibre.com> References: <20240913135744.152669-1-aardelean@baylibre.com> 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 The AD7606C-16 and AD7606C-18 are pretty similar with the AD7606B. The main difference between AD7606C-16 & AD7606C-18 is the precision in bits (16 vs 18). Because of that, some scales need to be defined for the 18-bit variants, as they need to be computed against 2**18 (vs 2**16 for the 16 bit-variants). Because the AD7606C-16,18 also supports bipolar & differential channels, for SW-mode, the default range of 10 V or =C2=B110V should be set at probe. On reset, the default range (in the registers) is set to value 0x3 which corresponds to '=C2=B110 V single-ended range', regardless of bipolar or differential configuration. Aside from the scale/ranges, the AD7606C-16 is similar to the AD7606B. The AD7606C-18 variant offers 18-bit precision. Because of this, the requirement to use this chip is that the SPI controller supports padding of 18-bit sequences to 32-bit arrays. Datasheet: https://www.analog.com/media/en/technical-documentation/data-she= ets/ad7606c-16.pdf Datasheet: https://www.analog.com/media/en/technical-documentation/data-she= ets/ad7606c-18.pdf Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 253 +++++++++++++++++++++++++++++++++-- drivers/iio/adc/ad7606.h | 16 ++- drivers/iio/adc/ad7606_spi.c | 55 ++++++++ 3 files changed, 312 insertions(+), 12 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index b909ee14fd81..c29512029bfb 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -36,6 +36,33 @@ static const unsigned int ad7606_16bit_hw_scale_avail[2]= =3D { 152588, 305176 }; =20 +static const unsigned int ad7606_18bit_hw_scale_avail[2] =3D { + 38147, 76294 +}; + +static const unsigned int ad7606c_16bit_single_ended_unipolar_scale_avail[= 3] =3D { + 76294, 152588, 190735, +}; + +static const unsigned int ad7606c_16bit_single_ended_bipolar_scale_avail[5= ] =3D { + 76294, 152588, 190735, 305176, 381470 +}; + +static const unsigned int ad7606c_16bit_differential_bipolar_scale_avail[4= ] =3D { + 152588, 305176, 381470, 610352 +}; + +static const unsigned int ad7606c_18bit_single_ended_unipolar_scale_avail[= 3] =3D { + 19073, 38147, 47684 +}; + +static const unsigned int ad7606c_18bit_single_ended_bipolar_scale_avail[5= ] =3D { + 19073, 38147, 47684, 76294, 95367 +}; + +static const unsigned int ad7606c_18bit_differential_bipolar_scale_avail[4= ] =3D { + 38147, 76294, 95367, 152588 +}; =20 static const unsigned int ad7606_16bit_sw_scale_avail[3] =3D { 76293, 152588, 305176 @@ -62,7 +89,8 @@ int ad7606_reset(struct ad7606_state *st) } EXPORT_SYMBOL_NS_GPL(ad7606_reset, IIO_AD7606); =20 -static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st, int ch) +static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st, + struct iio_chan_spec *chan, int ch) { struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; =20 @@ -83,6 +111,163 @@ static int ad7606_16bit_chan_scale_setup(struct ad7606= _state *st, int ch) return 0; } =20 +static int ad7606_get_chan_config(struct ad7606_state *st, int ch, + bool *bipolar, bool *differential) +{ + unsigned int num_channels =3D st->chip_info->num_channels - 1; + struct device *dev =3D st->dev; + int ret; + + *bipolar =3D false; + *differential =3D false; + + device_for_each_child_node_scoped(dev, child) { + u32 pins[2]; + int reg; + + ret =3D fwnode_property_read_u32(child, "reg", ®); + if (ret) + continue; + + /* channel number (here) is from 1 to num_channels */ + if (reg =3D=3D 0 || reg > num_channels) { + dev_warn(dev, + "Invalid channel number (ignoring): %d\n", reg); + continue; + } + + if (reg !=3D (ch + 1)) + continue; + + *bipolar =3D fwnode_property_read_bool(child, "bipolar"); + + ret =3D fwnode_property_read_u32_array(child, "diff-channels", + pins, ARRAY_SIZE(pins)); + /* Channel is differential, if pins are the same as 'reg' */ + if (ret =3D=3D 0 && (pins[0] !=3D reg || pins[1] !=3D reg)) { + dev_err(dev, + "Differential pins must be the same as 'reg'"); + return -EINVAL; + } + + *differential =3D (ret =3D=3D 0); + + if (*differential && !*bipolar) { + dev_err(dev, + "'bipolar' must be added for diff channel %d\n", + reg); + return -EINVAL; + } + + return 0; + } + + return 0; +} + +static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st, + struct iio_chan_spec *chan, int ch) +{ + struct ad7606_chan_scale *cs; + bool bipolar, differential; + int ret; + + ret =3D ad7606_get_chan_config(st, ch, &bipolar, &differential); + if (ret) + return ret; + + cs =3D &st->chan_scales[ch]; + + if (differential) { + cs->scale_avail =3D ad7606c_18bit_differential_bipolar_scale_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_18bit_differential_bipolar_scale_avail); + /* Bipolar differential ranges start at 8 (b1000) */ + cs->reg_offset =3D 8; + cs->range =3D 1; + chan->differential =3D 1; + chan->channel2 =3D chan->channel; + + return 0; + } + + chan->differential =3D 0; + + if (bipolar) { + cs->scale_avail =3D ad7606c_18bit_single_ended_bipolar_scale_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_18bit_single_ended_bipolar_scale_avail); + /* Bipolar single-ended ranges start at 0 (b0000) */ + cs->reg_offset =3D 0; + cs->range =3D 3; + chan->scan_type.sign =3D 's'; + + return 0; + } + + cs->scale_avail =3D ad7606c_18bit_single_ended_unipolar_scale_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_18bit_single_ended_unipolar_scale_avail); + /* Unipolar single-ended ranges start at 5 (b0101) */ + cs->reg_offset =3D 5; + cs->range =3D 1; + chan->scan_type.sign =3D 'u'; + + return 0; +} + +static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st, + struct iio_chan_spec *chan, int ch) +{ + struct ad7606_chan_scale *cs; + bool bipolar, differential; + int ret; + + ret =3D ad7606_get_chan_config(st, ch, &bipolar, &differential); + if (ret) + return ret; + + cs =3D &st->chan_scales[ch]; + + if (differential) { + cs->scale_avail =3D ad7606c_16bit_differential_bipolar_scale_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_16bit_differential_bipolar_scale_avail); + /* Bipolar differential ranges start at 8 (b1000) */ + cs->reg_offset =3D 8; + cs->range =3D 1; + chan->differential =3D 1; + chan->channel2 =3D chan->channel; + chan->scan_type.sign =3D 's'; + + return 0; + } + + chan->differential =3D 0; + + if (bipolar) { + cs->scale_avail =3D ad7606c_16bit_single_ended_bipolar_scale_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_16bit_single_ended_bipolar_scale_avail); + /* Bipolar single-ended ranges start at 0 (b0000) */ + cs->reg_offset =3D 0; + cs->range =3D 3; + chan->scan_type.sign =3D 's'; + + return 0; + } + + cs->scale_avail =3D ad7606c_16bit_single_ended_unipolar_scale_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_16bit_single_ended_unipolar_scale_avail); + /* Unipolar single-ended ranges start at 5 (b0101) */ + cs->reg_offset =3D 5; + cs->range =3D 1; + chan->scan_type.sign =3D 'u'; + + return 0; +} + static int ad7606_reg_access(struct iio_dev *indio_dev, unsigned int reg, unsigned int writeval, @@ -107,9 +292,8 @@ static int ad7606_reg_access(struct iio_dev *indio_dev, static int ad7606_read_samples(struct ad7606_state *st) { unsigned int num =3D st->chip_info->num_channels - 1; - u16 *data =3D st->data; =20 - return st->bops->read_block(st->dev, num, data); + return st->bops->read_block(st->dev, num, &st->data); } =20 static irqreturn_t ad7606_trigger_handler(int irq, void *p) @@ -125,7 +309,7 @@ static irqreturn_t ad7606_trigger_handler(int irq, void= *p) if (ret) goto error_ret; =20 - iio_push_to_buffers_with_timestamp(indio_dev, st->data, + iio_push_to_buffers_with_timestamp(indio_dev, &st->data, iio_get_time_ns(indio_dev)); error_ret: iio_trigger_notify_done(indio_dev->trig); @@ -139,6 +323,8 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev= , unsigned int ch, int *val) { struct ad7606_state *st =3D iio_priv(indio_dev); + unsigned int storagebits =3D st->chip_info->channels[1].scan_type.storage= bits; + const struct iio_chan_spec *chan; int ret; =20 gpiod_set_value(st->gpio_convst, 1); @@ -153,7 +339,19 @@ static int ad7606_scan_direct(struct iio_dev *indio_de= v, unsigned int ch, if (ret) goto error_ret; =20 - *val =3D sign_extend32(st->data[ch], 15); + chan =3D &indio_dev->channels[ch + 1]; + if (chan->scan_type.sign =3D=3D 'u') { + if (storagebits > 16) + *val =3D st->data.buf32[ch]; + else + *val =3D st->data.buf16[ch]; + return 0; + } + + if (storagebits > 16) + *val =3D sign_extend32(st->data.buf32[ch], 17); + else + *val =3D sign_extend32(st->data.buf16[ch], 15); =20 error_ret: gpiod_set_value(st->gpio_convst, 0); @@ -266,7 +464,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev, ch =3D chan->address; cs =3D &st->chan_scales[ch]; i =3D find_closest(val2, cs->scale_avail, cs->num_scales); - ret =3D st->write_scale(indio_dev, ch, i); + ret =3D st->write_scale(indio_dev, ch, i + cs->reg_offset); if (ret < 0) return ret; cs->range =3D i; @@ -349,6 +547,18 @@ static const struct iio_chan_spec ad7606_channels_16bi= t[] =3D { AD7606_CHANNEL(7, 16), }; =20 +static const struct iio_chan_spec ad7606_channels_18bit[] =3D { + IIO_CHAN_SOFT_TIMESTAMP(8), + AD7606_CHANNEL(0, 18), + AD7606_CHANNEL(1, 18), + AD7606_CHANNEL(2, 18), + AD7606_CHANNEL(3, 18), + AD7606_CHANNEL(4, 18), + AD7606_CHANNEL(5, 18), + AD7606_CHANNEL(6, 18), + AD7606_CHANNEL(7, 18), +}; + /* * The current assumption that this driver makes for AD7616, is that it's * working in Hardware Mode with Serial, Burst and Sequencer modes activat= ed. @@ -414,6 +624,20 @@ static const struct ad7606_chip_info ad7606_chip_info_= tbl[] =3D { .oversampling_avail =3D ad7606_oversampling_avail, .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), }, + [ID_AD7606C_16] =3D { + .channels =3D ad7606_channels_16bit, + .num_channels =3D 9, + .scale_setup_cb =3D ad7606c_16bit_chan_scale_setup, + .oversampling_avail =3D ad7606_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), + }, + [ID_AD7606C_18] =3D { + .channels =3D ad7606_channels_18bit, + .num_channels =3D 9, + .scale_setup_cb =3D ad7606c_18bit_chan_scale_setup, + .oversampling_avail =3D ad7606_oversampling_avail, + .oversampling_num =3D ARRAY_SIZE(ad7606_oversampling_avail), + }, [ID_AD7616] =3D { .channels =3D ad7616_channels, .num_channels =3D 17, @@ -586,7 +810,7 @@ static const struct iio_trigger_ops ad7606_trigger_ops = =3D { .validate_device =3D iio_trigger_validate_own_device, }; =20 -static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) +static int ad7606_sw_mode_setup(struct iio_dev *indio_dev, unsigned int id) { struct ad7606_state *st =3D iio_priv(indio_dev); =20 @@ -604,13 +828,24 @@ static int ad7606_chan_scales_setup(struct iio_dev *i= ndio_dev) { unsigned int num_channels =3D indio_dev->num_channels - 1; struct ad7606_state *st =3D iio_priv(indio_dev); + struct iio_chan_spec *chans; + size_t size; int ch, ret; =20 + /* Clone IIO channels, since some may be differential */ + size =3D indio_dev->num_channels * sizeof(*indio_dev->channels); + chans =3D devm_kzalloc(st->dev, size, GFP_KERNEL); + if (!chans) + return -ENOMEM; + + memcpy(chans, indio_dev->channels, size); + indio_dev->channels =3D chans; + for (ch =3D 0; ch < num_channels; ch++) { struct ad7606_chan_scale *cs; int i; =20 - ret =3D st->chip_info->scale_setup_cb(st, ch); + ret =3D st->chip_info->scale_setup_cb(st, &chans[ch + 1], ch); if (ret) return ret; =20 @@ -698,7 +933,7 @@ int ad7606_probe(struct device *dev, int irq, void __io= mem *base_address, st->write_scale =3D ad7606_write_scale_hw; st->write_os =3D ad7606_write_os_hw; =20 - ret =3D ad7606_sw_mode_setup(indio_dev); + ret =3D ad7606_sw_mode_setup(indio_dev, id); if (ret) return ret; =20 diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 25e84efd15c3..14ee75aa225b 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -63,7 +63,8 @@ =20 struct ad7606_state; =20 -typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st, int ch); +typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st, + struct iio_chan_spec *chan, int ch); =20 /** * struct ad7606_chip_info - chip specific information @@ -94,6 +95,8 @@ struct ad7606_chip_info { * such that it can be read via the 'read_avail' hook * @num_scales number of elements stored in the scale_avail array * @range voltage range selection, selects which scale to apply + * @reg_offset offset for the register value, to be applied when + * writing the value of 'range' to the register value */ struct ad7606_chan_scale { #define AD760X_MAX_SCALES 16 @@ -102,6 +105,7 @@ struct ad7606_chan_scale { int scale_avail_show[AD760X_MAX_SCALE_SHOW]; unsigned int num_scales; unsigned int range; + unsigned int reg_offset; }; =20 /** @@ -158,9 +162,13 @@ struct ad7606_state { /* * DMA (thus cache coherency maintenance) may require the * transfer buffers to live in their own cache lines. - * 16 * 16-bit samples + 64-bit timestamp + * 16 * 16-bit samples + 64-bit timestamp - for AD7616 + * 8 * 32-bit samples + 64-bit timestamp - for AD7616C-18 (and similar) */ - unsigned short data[20] __aligned(IIO_DMA_MINALIGN); + union { + u16 buf16[20]; + u32 buf32[10]; + } data __aligned(IIO_DMA_MINALIGN); __be16 d16[2]; }; =20 @@ -201,6 +209,8 @@ enum ad7606_supported_device_ids { ID_AD7606_6, ID_AD7606_4, ID_AD7606B, + ID_AD7606C_16, + ID_AD7606C_18, ID_AD7616, }; =20 diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c index e00f58a6a0e9..143440e73aab 100644 --- a/drivers/iio/adc/ad7606_spi.c +++ b/drivers/iio/adc/ad7606_spi.c @@ -77,6 +77,18 @@ static const struct iio_chan_spec ad7606b_sw_channels[] = =3D { AD7606_SW_CHANNEL(7, 16), }; =20 +static const struct iio_chan_spec ad7606c_18_sw_channels[] =3D { + IIO_CHAN_SOFT_TIMESTAMP(8), + AD7606_SW_CHANNEL(0, 18), + AD7606_SW_CHANNEL(1, 18), + AD7606_SW_CHANNEL(2, 18), + AD7606_SW_CHANNEL(3, 18), + AD7606_SW_CHANNEL(4, 18), + AD7606_SW_CHANNEL(5, 18), + AD7606_SW_CHANNEL(6, 18), + AD7606_SW_CHANNEL(7, 18), +}; + static const unsigned int ad7606B_oversampling_avail[9] =3D { 1, 2, 4, 8, 16, 32, 64, 128, 256 }; @@ -120,6 +132,19 @@ static int ad7606_spi_read_block(struct device *dev, return 0; } =20 +static int ad7606_spi_read_block18to32(struct device *dev, + int count, void *buf) +{ + struct spi_device *spi =3D to_spi_device(dev); + struct spi_transfer xfer =3D { + .bits_per_word =3D 18, + .len =3D count * sizeof(u32), + .rx_buf =3D buf, + }; + + return spi_sync_transfer(spi, &xfer, 1); +} + static int ad7606_spi_reg_read(struct ad7606_state *st, unsigned int addr) { struct spi_device *spi =3D to_spi_device(st->dev); @@ -283,6 +308,19 @@ static int ad7606B_sw_mode_config(struct iio_dev *indi= o_dev) return 0; } =20 +static int ad7606c_18_sw_mode_config(struct iio_dev *indio_dev) +{ + int ret; + + ret =3D ad7606B_sw_mode_config(indio_dev); + if (ret) + return ret; + + indio_dev->channels =3D ad7606c_18_sw_channels; + + return 0; +} + static const struct ad7606_bus_ops ad7606_spi_bops =3D { .read_block =3D ad7606_spi_read_block, }; @@ -305,6 +343,15 @@ static const struct ad7606_bus_ops ad7606B_spi_bops = =3D { .sw_mode_config =3D ad7606B_sw_mode_config, }; =20 +static const struct ad7606_bus_ops ad7606c_18_spi_bops =3D { + .read_block =3D ad7606_spi_read_block18to32, + .reg_read =3D ad7606_spi_reg_read, + .reg_write =3D ad7606_spi_reg_write, + .write_mask =3D ad7606_spi_write_mask, + .rd_wr_cmd =3D ad7606B_spi_rd_wr_cmd, + .sw_mode_config =3D ad7606c_18_sw_mode_config, +}; + static int ad7606_spi_probe(struct spi_device *spi) { const struct spi_device_id *id =3D spi_get_device_id(spi); @@ -315,8 +362,12 @@ static int ad7606_spi_probe(struct spi_device *spi) bops =3D &ad7616_spi_bops; break; case ID_AD7606B: + case ID_AD7606C_16: bops =3D &ad7606B_spi_bops; break; + case ID_AD7606C_18: + bops =3D &ad7606c_18_spi_bops; + break; default: bops =3D &ad7606_spi_bops; break; @@ -333,6 +384,8 @@ static const struct spi_device_id ad7606_id_table[] =3D= { { "ad7606-6", ID_AD7606_6 }, { "ad7606-8", ID_AD7606_8 }, { "ad7606b", ID_AD7606B }, + { "ad7606c-16", ID_AD7606C_16 }, + { "ad7606c-18", ID_AD7606C_18 }, { "ad7616", ID_AD7616 }, { } }; @@ -344,6 +397,8 @@ static const struct of_device_id ad7606_of_match[] =3D { { .compatible =3D "adi,ad7606-6" }, { .compatible =3D "adi,ad7606-8" }, { .compatible =3D "adi,ad7606b" }, + { .compatible =3D "adi,ad7606c-16" }, + { .compatible =3D "adi,ad7606c-18" }, { .compatible =3D "adi,ad7616" }, { } }; --=20 2.46.0