From nobody Tue Feb 10 19:14:18 2026 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 6016B146018 for ; Wed, 4 Sep 2024 07:27:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434849; cv=none; b=HORTKwoJp6Z4jLnnMvIjDaRuuQcV2dIF4DE1eCUoMZLoXAxXS4q/3xM5U0V6hJeM590EvZiDHTTUFH+COm2qScf1pL8wFxIu/EeNX8is14bp+Sn7BhHMcrm2cRZnbaNKMvuHGS0YHrdWwL7iO1b/ceoOlJSOTq8Mn2w8eq9EjNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434849; c=relaxed/simple; bh=m+JDUAFze61TKUmqgjZi4kJQBJPi7r7Nl0ZvyJY2pOo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CQ6JtiR18kNWiHS7cU9nd4CtRYFY7+J/C8FRzzdMfwzzOyab/NnLUoYu3dX7YzwSjtIM5CYcEXPfvf+RAxvXL81Gr7gug+IMnLTP1oYL9hswmVPBZ35wrsxgZOQct+w8MDhv1X5pL4p6dj1jcu+bwM2cAhg3UnnqOz2OD4pO3Pk= 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=cuxE5Ozr; arc=none smtp.client-ip=209.85.218.43 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="cuxE5Ozr" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a8692bbec79so710986166b.3 for ; Wed, 04 Sep 2024 00:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725434846; x=1726039646; 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=zwFKX15TuB+lP2XuqgSDKuPw5N2dTeJWzE8YjtBx2Ck=; b=cuxE5OzrT+uKeYOt9zbThDT2okBBiIDVMWXhJ2bRCpMR6CBEEl71/ssJSOyJXM4YHh TR76G5VWwfAmtqbUM4CsrguJnATstYrU5E6nKjk5JiBzvT52lXh6rsG8geq1mL40Xv6O cIZZRTvgpUmLxh0lrwJj7wvavvd2rhM1DBiq6shVfFpjIMqR6yND16FsHRBnx3umShET m7bCZT2Q21rfBLQIilRy3JExVEhwhBvPjWfEKgjPduQEpozRRHquN9S7WfTwnQsth23g 2jRVJQrEl6sjuUMcMayaDGN48nOa0ZwIqAD+0Erqkq0CCZC3/3fn0YyLPXpJLAFrs/VQ Reow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725434846; x=1726039646; 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=zwFKX15TuB+lP2XuqgSDKuPw5N2dTeJWzE8YjtBx2Ck=; b=kLwKq3/ppY4JL/5CPSuQHygiN0xk/Z8cX0gnmXMJH2j49KdkW616c1uFPs8WwSMtGY BsGNuP52oo0XsGtXCGIb8nt+In+OYLe+K8qiAwOPwQllCv0z+Pr7zmaJZ7Chh3ARs0xc kB2TPatZ6uWEvObjwmFN6DWLLjwzyXy7m0nlC+kALUTEeNc3UBti8KzIgqXEzZPByihI UEvh0T9HKzCDmoR7Rih24SiZyjLqmd7oC/u/AY6x248o8OMAl5hQdBk4gXgRap7BOZXe 9K5Wa981ZmgylF2IHk4u/nG7gtCjL81PezSV/KtbNlMoWyNCFFgMTG2uO2pHwxwxT+P8 o2Mg== X-Forwarded-Encrypted: i=1; AJvYcCV4ufSnvpY0LEwOvrD3jKFaQizaqDetjyivAExc2Ei1YNQPa8oW7qSXcX5Dn00zz4WQXhbP3wWWkzS3weQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxproamZhCx62vps+TZyB/xxNbxOHUQbKSmt+0HKRp6AD6JFgTC aaeK950c1txFSnJfG+pgW4VAJMyHnoFS7ISIgGy2KLRZJ9cR99D47PQGLGi2J1s= X-Google-Smtp-Source: AGHT+IHdAnMtwj2cVJbtZC+1VjqYoA2vYtSW6YnnAqQZ+P2tzmJFo0NH4EeOchNQen+3iiA9+YRyVA== X-Received: by 2002:a17:906:478c:b0:a86:6fa8:c6a3 with SMTP id a640c23a62f3a-a89a36d084dmr1007250566b.39.1725434844861; Wed, 04 Sep 2024 00:27:24 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891d77fasm771151766b.167.2024.09.04.00.27.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 00:27:24 -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, Alexandru Ardelean Subject: [PATCH v3 1/8] iio: adc: ad7606: add 'bits' parameter to channels macros Date: Wed, 4 Sep 2024 10:27:09 +0300 Message-ID: <20240904072718.1143440-2-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904072718.1143440-1-aardelean@baylibre.com> References: <20240904072718.1143440-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 539e4a8621fe..dba1f28782e4 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -333,16 +333,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 /* @@ -357,22 +357,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 { @@ -382,25 +382,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 0c6a88cc4695..771121350f98 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), \ .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 Tue Feb 10 19:14:18 2026 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9B2514659C for ; Wed, 4 Sep 2024 07:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434850; cv=none; b=P0SThQCNE/6MCmjlpDi1nxKVhVtpmWp4hOHBDIFyD20cFCNCjNAJ6jZEMrwAZtMu6ayoQsMXJJk5EgKzUTprWexNXGjBo15ZRgS2fjQ9mOBlD/FGpy2zVTUb5DkvvGhtUj+fa5EpPcXYWcjOh83zKTGUxtiW8NtDPH/dOTedbRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434850; c=relaxed/simple; bh=IXqmhsQDt/RO+GElC8x8ywqYUr/3SWcgPZP7XLJrRH0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eUArpZQDyPtTlZvENcdfE0BseROw4Hs1o/oHWu7dFv7tuxl+uN15oXzPg5j0i5n5Vx/JGCtThDRc90oDOlPIJQfNonmd3uFnMvFGcAelA8acrAA8MwJnNGzRQgWnMNpo+ObPn78biTKzzTGNokzzTb/rl0Czg1s53gSTcPiLtjo= 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=CuZWI5Ri; arc=none smtp.client-ip=209.85.208.53 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="CuZWI5Ri" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5bf009cf4c0so6395860a12.1 for ; Wed, 04 Sep 2024 00:27:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725434847; x=1726039647; 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=Ui2lv4x9FTPWujQRhFdVeT4msHXJUFxc93RUhnH6Vdg=; b=CuZWI5RiSsScnilpQZiswcSvY7NnGjuXYSAihn+sh5yB70hV6V7KmiLbLk1a+nTF9N 3Nut73cW3Hf04xEvWZfaoxlG/WuV4PXtu6dWwQOqip992P/ymBVv26jwXsUPyt6z3nf5 kZF2giGD+Vsax0klE86QGNm459199pBXjeShbvKlTzYZrjnjAnV1f0a7upukvEf16ssS tmgnptpdMYY0P29CwWijaGr4DFIFoRThntJ4zJzWqliy3Wlur/R9pdQmjjRMxNPnE98e S1CYxDRkSbbl8iRCfsaLcuh07TDVYPSPy5Qtcod3q3Hy72d5lZplonzDs+vjOrPy4yQh irhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725434847; x=1726039647; 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=Ui2lv4x9FTPWujQRhFdVeT4msHXJUFxc93RUhnH6Vdg=; b=AaOiuC1Zk1fcipy+NchBkTgM1rXWnxC7UkM7JSBZte6eXVre2pw2hbATh+Z3HAjaUH /ROaQWL+D9d6LBdbIBZiz+IEyM6vrOXDsknUrGomICD4ibSQQW4xH29kJkkBLhjiYJMB /V0zO029mGaQVJMBoBVxOgzsflTT2riu0I2CdPwXjwOC4wLiui5t8+l/21iA6jz3dUxU GBmTBDXdryKYBJXjd29Mdk/dK4LYsuWuRLX02pi3T3awUlZZWYDRtdg2lVPOKNqVSA4t nDbfIh17nURpOOcMMU4EcTeXr2kC451pm0pIcXpBQXZOcQxNXEXP6hvn5R5j+1MZJw96 daUw== X-Forwarded-Encrypted: i=1; AJvYcCUsUSAH+H6usMIdO8BEcVdGgZ7pkwztEknSa2I6mBAgMVN/7LbOoBB3ROgmVtx+AZuTGE8zK7y22Cuaso4=@vger.kernel.org X-Gm-Message-State: AOJu0YySV5M0Jw3dOoFGtN/WdZgRmfSvhnpXkQG05DnuLlhfAF6sThPy M+VoQHP5RFpFunIy6ssgyzSc6IBPqHBHjFozDn5A0NqUJvcMRSKZZuPi2DwDdfQ= X-Google-Smtp-Source: AGHT+IG7ZUz0d27mzkHFX2vrDobji+u+YboJXBuFIuhuHllAkHsRZJmGUeMRB2xlKDbbonvARI+kbA== X-Received: by 2002:a17:907:7e88:b0:a86:af28:fc2b with SMTP id a640c23a62f3a-a8a32fa103emr281232066b.54.1725434846793; Wed, 04 Sep 2024 00:27:26 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891d77fasm771151766b.167.2024.09.04.00.27.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 00:27:26 -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, Alexandru Ardelean Subject: [PATCH v3 2/8] iio: adc: ad7606: move 'val' pointer to ad7606_scan_direct() Date: Wed, 4 Sep 2024 10:27:10 +0300 Message-ID: <20240904072718.1143440-3-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904072718.1143440-1-aardelean@baylibre.com> References: <20240904072718.1143440-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). Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index dba1f28782e4..5049e37f8393 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -138,7 +138,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; @@ -153,7 +154,7 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev= , unsigned int ch) =20 ret =3D ad7606_read_samples(st); if (ret =3D=3D 0) - ret =3D st->data[ch]; + *val =3D sign_extend32(st->data[ch], 15); =20 error_ret: gpiod_set_value(st->gpio_convst, 0); @@ -173,10 +174,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 Tue Feb 10 19:14:18 2026 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 0B6691474DA for ; Wed, 4 Sep 2024 07:27:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434852; cv=none; b=fIyCQg6AA6s6/CgxXTEVxncWgzToWjOwKMSunMgaM9U3c6AOS0rTn7nTagnNgIiKtiWojCAM3llcMa86SAFyb2AjRoSx1qH0cd8FM+6RSf4oXEks4fDuhiwus5mr1ogPdm5oNsMCVvXocHt88+wxmBsMKaZnQlg3YquiIKc97PQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434852; c=relaxed/simple; bh=9wWTe2RhHwvr6CPLWLyUmFQssffTJWZ48+UUgVNgMfA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dAFtVbWxw3zNSkoqId6ClRE5LB3uVuZkXJ7xB13AwB/9uujjgs6kkMgn/ISvy/BgLS5VVwnFY1ORrqJI/inwmd8DcZN+evP9yYKvaM6mGN5P4tamXNQfRg8iw01KmjPwBoBsDw5cLurvmMUkAVoys5sM2HpC9W6c3AoNaML7un8= 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=0eFx1Yrf; arc=none smtp.client-ip=209.85.218.43 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="0eFx1Yrf" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a86e5e9ff05so720148566b.1 for ; Wed, 04 Sep 2024 00:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725434849; x=1726039649; 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=WRucj7sLZEUBkFzhvRqpr3JKNs6+16Ez8lks/iAJ3Xo=; b=0eFx1Yrfw7N7xYhkkA5vHA88olJeRRpREO5IVGFHeOeGKhlR+cDpL4CrdBCZSGP/Rq Q7mx4hNQDRSaOl0rWMk5xeamzq/UapJMRn9XQn97iXoI8lpZqfs3DgvIaSWBK8z+iuQ5 hEoSm28blGaXPHA3vMhsnROScC25jRE08igNTXiahJtitAgT3YK/HQ4YBC5fcV1mDmhH QlSdAkRiraghgrhZKW0VvRGCLoOWINwtL5FoyWEbenkfniRi6tA/QWVEfA31E2OSPVLA f2B5NVsm4jCqbSHL554Drf8org3FZ6AydtRwyClRCBKaHQM351+c62ujTx8AESgftUlz inFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725434849; x=1726039649; 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=WRucj7sLZEUBkFzhvRqpr3JKNs6+16Ez8lks/iAJ3Xo=; b=sVdmLeAmskhI+Wr+owxJpvJq6S6JxAprpn67CCoh6F7fYmFYrlvEg7uJSwbbxztl8r xSWl2maGsrNqL+8lwgeDardxj3wXe4Pp6+VmYWP5xZw4wENO8pu6UhgCmYIo4DnNnDBH k+4rOj5biEtFgmy3rNMLBvh4I/wRjC+29kYexR9PjWMSyMSuKUzq4Z2PSSvsIUeLmiFw e2qDp67+onmJsmjFvNL98d5BXuigjKcrkZqQujcWFb6fV6xFvgkg4Bk5A65/xpXRrNSe wnAMlTwbJszvihHePsak/z959ManPpMi7fkavlMKoyINZgoHyFJx6NVrhHD8AQMTvQ4/ k8Zg== X-Forwarded-Encrypted: i=1; AJvYcCVQrD1JFvV57DD0Mi0QQb2SbqHpjbCGDBlPg+0CnBdgTir9YahMtsqS7GMPnAhbKsfrmji9HRQMTNKaB7M=@vger.kernel.org X-Gm-Message-State: AOJu0YyxVEzm8Gm4L3fQQYm4351oDdUm9+t/xZjehHsfDy9RBNT38135 u5YY4zbfK1f1efD9CyQfAknrDhh1X43jTmqEExRrGN/1OxxpzkqMIAsg2l+W+SA= X-Google-Smtp-Source: AGHT+IFxShxDEqQPCTID74bNivAq6VaYj90mx3GbIAXzgKUqBSXXWdkkh79iRCw/9aQKfxR56BcRyQ== X-Received: by 2002:a17:907:7e8b:b0:a86:6da9:72f4 with SMTP id a640c23a62f3a-a8a32e6dd5cmr265440566b.17.1725434848384; Wed, 04 Sep 2024 00:27:28 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891d77fasm771151766b.167.2024.09.04.00.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 00:27:28 -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, Alexandru Ardelean Subject: [PATCH v3 3/8] iio: adc: ad7606: split a 'ad7606_sw_mode_setup()' from probe Date: Wed, 4 Sep 2024 10:27:11 +0300 Message-ID: <20240904072718.1143440-4-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904072718.1143440-1-aardelean@baylibre.com> References: <20240904072718.1143440-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 This change moves the logic for setting up SW mode (during probe) into it's own function. With the addition of some newer parts, the SW-mode part can get a little more complicated. So it's a bit better to have a separate function for this. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 43 ++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 5049e37f8393..b400c9b2519d 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -545,6 +545,29 @@ 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); + + if (!st->bops->sw_mode_config) + return 0; + + st->sw_mode_en =3D 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; + + /* 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)); + + return st->bops->sw_mode_config(indio_dev); +} + int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, const char *name, unsigned int id, const struct ad7606_bus_ops *bops) @@ -617,23 +640,9 @@ int ad7606_probe(struct device *dev, int irq, void __i= omem *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 st->bops->sw_mode_config(indio_dev); - if (ret < 0) - return ret; - } + ret =3D ad7606_sw_mode_setup(indio_dev); + if (ret) + return ret; =20 st->trig =3D devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, --=20 2.46.0 From nobody Tue Feb 10 19:14:18 2026 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.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 68F321487CE for ; Wed, 4 Sep 2024 07:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434854; cv=none; b=oYo1JXjLEmNPTgbdnK26/kyR+DsqKpSrHhxviCNBtDUB2OosWf+HJ0+QCQ0gKNQCvLP0N9LamjvCnRiG8s6fqHrCwXTVD1DruEjB5wwFIKzDNGyXqxJ8qLZL+JVGYJ3I82Vsk8u08q8ACrdB4yUt4es6i4SLYoqj3pBFPq3tRPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434854; c=relaxed/simple; bh=ZK9Z1/Q4filbKX1kKWRghKSgUBwXpAJI26eeyznAt94=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YQ+LHljbfxhXZy7KxhKIXM8R5evJrUHgkHq4XOe7mR+VPcLafVR2vaH8KIIxg4PaPREmcgALbaDyyd1gjdHxN0rTuHmMpKrx9tfMWU6L2/TSmIuEqab43DkVv/Hrn9cgaimBA2O4J38/u1HSia7f/EAPZM0zjNs5nsVFXSHlhqU= 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=kn31VeNX; arc=none smtp.client-ip=209.85.218.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="kn31VeNX" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a8a16c53d3cso292919566b.1 for ; Wed, 04 Sep 2024 00:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725434850; x=1726039650; 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=OMjsY+V8C+xpLeayM52S92PbmAJB3Osj5meZbpqVaZk=; b=kn31VeNX2SENfFLwxlRKl60QSt3iLF1W5lER3EAM1nWSTFK2tOWq3gZhCxhzHMmkw8 fJiJIJQOC6+zV+gfda/J2GaZUrtdTvcqDas6U3lA37N7ouGQQbN7TPODV/0bUkLejkcI H86LuuMrPQebxv448HFcCuvgz64R4T2sdAgcmfVf7Fla0TU5TxfPQ3eV/RZUNak1ALoC EUswAQX8xxxLoSsvNeI6q8ztEQXyXQAIsybX9d26cWBfuHQFFdr6D0+tX/qmDT7X1X1Y JxugfxMRc4WJVrg3qNS38Xg9VTqujjT2KDL251r3PgoRIHFs5OHkWb93aBeGDkF5Napw P45w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725434850; x=1726039650; 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=OMjsY+V8C+xpLeayM52S92PbmAJB3Osj5meZbpqVaZk=; b=Cp3hwCEY4M2Q2oDxzsmAAZCQ0q3lORlw2Y/LE0zv25XV6LzBHX+ogqSvRBt76n6rv5 Dsh480KgNDBdumgWD+uMHmnwViXbtyQnf8XYznm5/AO8PnSo+J9s/eRqZDgjUuyOc3vG mfjecOfsuyVBdz5OvjBb9If08+Jfl1FwCiUUdlB7+KkuJcoKepulnTPYfCLBszaTV7HW xN8E6Na1oiL/FQVOQQFmF3jiFAMBrXYQJzWvhgYWfYuQKzQCcLrx/3GMzvw6RZkDHIeS Gl88cuRisXRPSybjCE/3xAZEgrRX0m8Ho9BrLAxw17vuRpjJn9HopmJSnGHpUwn+rZqh P+Qw== X-Forwarded-Encrypted: i=1; AJvYcCUS0ADiwmmibjfYoogQx4+d47WvjVwjSAzTY2dmmaoc6SpOzNQeGaQhrcImkpBhLkTcJp51MVembKsdlQg=@vger.kernel.org X-Gm-Message-State: AOJu0Ywcyl/vApRE6ZVofUCdzeMmGazY0xcLNMXvIIKIjV/busB6uLXF Rj3aCyOoZmKMfaQhPpu+Y81PlMCRUpHz32RVG2cdMmA43qJfgY4eCXKjkNBQhsY= X-Google-Smtp-Source: AGHT+IFsUgq0CpDUxU+jCRXnAz9i2A7gEDgikGOoHQIBWcwmlnwPMr1De5G+WsNXilZzytFkb6DiDg== X-Received: by 2002:a17:907:3208:b0:a87:31c:c6c4 with SMTP id a640c23a62f3a-a897f83623fmr1536620866b.24.1725434850445; Wed, 04 Sep 2024 00:27:30 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891d77fasm771151766b.167.2024.09.04.00.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 00:27:29 -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, Alexandru Ardelean Subject: [PATCH v3 4/8] iio: adc: ad7606: wrap channel ranges & scales into struct Date: Wed, 4 Sep 2024 10:27:12 +0300 Message-ID: <20240904072718.1143440-5-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904072718.1143440-1-aardelean@baylibre.com> References: <20240904072718.1143440-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 | 37 +++++++++++++++++++++++++------------ drivers/iio/adc/ad7606.h | 22 ++++++++++++++++------ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index b400c9b2519d..2554a4a4a9c0 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -170,6 +170,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: @@ -183,8 +184,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; @@ -214,8 +216,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); @@ -253,19 +256,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: @@ -547,7 +552,9 @@ static const struct iio_trigger_ops ad7606_trigger_ops = =3D { =20 static int ad7606_sw_mode_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; =20 if (!st->bops->sw_mode_config) return 0; @@ -559,11 +566,14 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio= _dev) indio_dev->info =3D &ad7606_info_os_range_and_debug; =20 /* 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)); + for (ch =3D 0; ch < num_channels; ch++) { + struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + + cs->scale_avail =3D ad7616_sw_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7616_sw_scale_avail); + cs->range =3D 2; + } =20 return st->bops->sw_mode_config(indio_dev); } @@ -572,6 +582,7 @@ int ad7606_probe(struct device *dev, int irq, void __io= mem *base_address, const char *name, unsigned int id, const struct ad7606_bus_ops *bops) { + struct ad7606_chan_scale *cs; struct ad7606_state *st; int ret; struct iio_dev *indio_dev; @@ -588,10 +599,12 @@ int ad7606_probe(struct device *dev, int irq, void __= iomem *base_address, 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); + + cs =3D &st->chan_scales[0]; + cs->range =3D 0; + cs->scale_avail =3D ad7606_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7606_scale_avail); =20 ret =3D devm_regulator_get_enable(dev, "avcc"); if (ret) @@ -698,7 +711,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 771121350f98..afe6a4030e0e 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, \ @@ -60,17 +62,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 @@ -94,12 +106,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 Tue Feb 10 19:14:18 2026 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 562A91494D4 for ; Wed, 4 Sep 2024 07:27:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434857; cv=none; b=Cc2xGeBYaUREu+EOSVZCgbAxJw1l7qYOrNU4s3RBaT8X2LCwXgs0VQjl8u8bNBNUHs663PW1Tz/EuiWclKJhJSb47vKOiYC5aOTrlzQBV4l4/WAUv8IpAx2cZ/udAJxzjz6yHN4PHzHBZULmcfa6+VWgZ8yrftLJdepGF8CoouA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434857; c=relaxed/simple; bh=nVbw190QbFvntpv2F3+c7kcWkCwggr81hIv8yKcYO0Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dn1ijnqX7T1sf+meTh/vWsf5uLEX1g5Jz3uWjf8A6/FRNhTZPOQTh/aB6xmmUWRTEKWdou6mNiZJUdNy+4VtrkbKH49T6p21nwVN9T/usWhP28eulK6ELOfCPitCz11zQbL/Hrjxw41pzA7JxEQyY+EtGXUBZB9Tv+KZznWLWHQ= 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=vttD+hDn; arc=none smtp.client-ip=209.85.167.50 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="vttD+hDn" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-53438aa64a4so7562090e87.3 for ; Wed, 04 Sep 2024 00:27:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725434852; x=1726039652; 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=VP40VYCR8trduWJE1JYza3M6qtnB5tUGujhHJKROTmg=; b=vttD+hDne2dAXcv4UhefUUVngRDn/JY7mCeBvybDN/5AeqSZFXfqZ1ovq+QPGlL1Ez MD7OQPPWI+4dOdSEwAAr+2mZfgcs/IWeX5xccL5Gq3TmbcaOHpGFZ3XG7EtSM4d93Aa4 pv1FGwFfZmTvI/xq086MaduA827PiDHnzfUPNaZwBrFwF3H+6bXS74jjtAQVytjYAcQa lpplDRNfVRSLyPsLEfyaX/kKwHv2jPMjGHX4Q22WeSqIkzvauKmUHI5eg/QqnW9oQdw/ EU+1Li6EHeuZhWSfPVxHBDoNt3AxK3ulmBsXewLfaum69lg9fx6J5SVLc7jUaHp9e2XU ykQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725434852; x=1726039652; 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=VP40VYCR8trduWJE1JYza3M6qtnB5tUGujhHJKROTmg=; b=ly8xi8485gF89e+j0VPTlLrT103bTkUf8+P/DqXxCDO3IGuinCw5mxgiOLe4jk7k6W bMypwb2PCTRK/K3BhhVXgoT4URTAe+S3XWE8i0SaA34m3pO2LMzsmU/SeKrHY+5YaOOz BGQ9rjRlzNiMZCW+yFGy6j1r4wb6HUSJDLDfZvOKv7SSh66gB18YBh+2A6u+E/kBkfRV QbEVECTRCy5E9o9Jrh+/gr2nh1G+shlYrdeHA7kOZRhvKWKChlusWrVN/8foLZYgjHBo UG1FV9jQUtpg/V9H87iI3866xqp38XkQ6J9pgkNifDi220Hu1jYYBAnjiRrYWUk6sOtm hjcg== X-Forwarded-Encrypted: i=1; AJvYcCWDNf8zgVwxU5Kt7tUQDctYmjVYXBKldvXT/TZs2Z42BWh/JjF8YWxpWHvEKr0vuBC4xL84IsevgtuoRLI=@vger.kernel.org X-Gm-Message-State: AOJu0YyeemyTB91rcCZf31WSADoxkCKpEJb3vq7nzNXUGRPAvdcJAMfN 6Fi05yKp7BlvhdIw4J8ugQXbGe481AefFVmytARe0rgSptinu8pIpDBh0fcdWAg= X-Google-Smtp-Source: AGHT+IHBDWSUfWh2iI0hlKtdvN+a5GYy6WXjsuNEDF7uKl0CsLCCVUmCq81WqE5zqRNmCwg0qOG9FQ== X-Received: by 2002:a05:6512:3194:b0:52c:9e82:a971 with SMTP id 2adb3069b0e04-53546af527emr10190412e87.7.1725434852293; Wed, 04 Sep 2024 00:27:32 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891d77fasm771151766b.167.2024.09.04.00.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 00:27:31 -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, Alexandru Ardelean Subject: [PATCH v3 5/8] iio: adc: ad7606: rework available attributes for SW channels Date: Wed, 4 Sep 2024 10:27:13 +0300 Message-ID: <20240904072718.1143440-6-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904072718.1143440-1-aardelean@baylibre.com> References: <20240904072718.1143440-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 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 | 63 ++++++++++++++++++++++++++++++++++++---- drivers/iio/adc/ad7606.h | 31 +++++++++++++++++--- 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 2554a4a4a9c0..4c3fbb28f790 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -507,6 +507,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, @@ -524,11 +555,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 @@ -554,7 +585,7 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio_d= ev) { unsigned int num_channels =3D indio_dev->num_channels - 1; struct ad7606_state *st =3D iio_priv(indio_dev); - int ch; + int ret, ch; =20 if (!st->bops->sw_mode_config) return 0; @@ -563,7 +594,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 /* Scale of 0.076293 is only available in sw mode */ /* After reset, in software mode, =C2=B110 V is set by default */ @@ -575,7 +606,29 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio_= dev) cs->range =3D 2; } =20 - return st->bops->sw_mode_config(indio_dev); + ret =3D st->bops->sw_mode_config(indio_dev); + if (ret) + return ret; + + for (ch =3D 0; ch < num_channels; ch++) { + struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + int i; + + cs =3D &st->chan_scales[ch]; + + if (cs->num_scales * 2 > AD760X_MAX_SCALE_SHOW) { + dev_err(st->dev, "Driver error: scale range too big"); + return -ERANGE; + } + + /* 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]; + } + } + + return 0; } =20 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index afe6a4030e0e..2113ad460c0f 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), \ + .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 /** @@ -65,11 +84,15 @@ 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_SCALE_SHOW (AD760X_MAX_CHANNELS * 2) const unsigned int *scale_avail; + int scale_avail_show[AD760X_MAX_SCALE_SHOW]; unsigned int num_scales; unsigned int range; }; --=20 2.46.0 From nobody Tue Feb 10 19:14:18 2026 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 AFC0514EC4E for ; Wed, 4 Sep 2024 07:27:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434858; cv=none; b=saVxWr2WKR5zRt38cszXWN7tTwO9YsGjP6BxJ80m6KukHdfHA9l1dnyWm/xozXx6O82fK9DcKPDqgtZHL7zmbHihvnzjP2qyPhn1yfDyIujtN81xBuCpNFZSdyXxZqSXwJMVzk4QYfd0DUIDnhgxxaqSDBlvvCAfZWvAJ4+rtfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434858; c=relaxed/simple; bh=HFKyY5jobT+EEiF3Y/0HETSYeKrn/igGtDbnGCiZFP8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SmG329SV3UlcD9+KG/G7HjRf6wf/8RacHLvflQd+sW6UbInp8dJQ6wCEGSGDpNYc04/Isnuirl8yfV/gGd0kv2x4lBNx0ojh0gQABnELdyFbTZ/JrtPB+Rz/mrzTFGJJbsFXRBWBOhVKqnV8mR8Gt8Fk1ENru6APb0s1yomlm2M= 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=ebEkPiDs; arc=none smtp.client-ip=209.85.218.42 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="ebEkPiDs" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a7aa086b077so41778666b.0 for ; Wed, 04 Sep 2024 00:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725434855; x=1726039655; 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=hYWMKG4k6/aCnq2O9xXhUdz5T7fph7bWB64VuOzrqxY=; b=ebEkPiDsLR/GtP9vui31LC3vHDF18hQOr8DGbGHqXvtsdslCY7xkojGs710lkVpgtV zSikKwDrPGmuXynWgmUfKb+mJeJM4XfzDICdS/2TTknI5CiVy5Mi9IhmBQzlAoO24n8D F/6aLSFfY9x/OTzf3/KqOERKHCbE50KD2A5QBz3eVh7yHqAANsOaLvSNJuu6O3fnMe0d djGE/4UKiqDKQEQ8pvlcN/2WD4RlP5pMPgz/RqTKHR8O7S0tgz6Olxd5Cla4U/qNrm5k cJGq4P0jHZugjH+paiUb4TmtyD7d2P1VcTwlEmz3inmrdlWlLv7dmLX9w+fRd0qYwXd3 FYkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725434855; x=1726039655; 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=hYWMKG4k6/aCnq2O9xXhUdz5T7fph7bWB64VuOzrqxY=; b=fgmlqS/Qhia4zj5EZBW9GZKtStT9/sdIhKh86Eu+HhwXJQHBkp+A8j4ienGqJUH81p GOq0u70/dgAig4IkPf6y81+YcUx42O1vE1Cu7HHzDKTiaTO1sGUFAfSXnPHvL9M6CnZg 0k26DKDR8fvW08LGsnxQuj6X+7XVtMBJbnl7k3CWlohxc3zlj7cMyb1oEzY9d0ElgVDC jg42rG2160xLQmfcjAncFoDdK598n1v17wqQiP8iLaBauzuZFfeUSC4FrTWMg6ZjTAoB cuyRHPOQVrD1tdfRgytWJ4kBU4/mf9EUruEniQ8E4YCTXOMHxRSLxrXo5vBvyCGcHRwS 4Qzg== X-Forwarded-Encrypted: i=1; AJvYcCU6nDfsLkgaeH43phDvEMNNHG3j4i/S2LzryCMd6u8KfB+MUblKW4oMo2Bnzowp+B+7iXSOYo/PAX55UHc=@vger.kernel.org X-Gm-Message-State: AOJu0YxDMSl04/QH7ZQu7rQAH01ZeX2f1FqC4HIfY8FLWNgFAdBUb1l2 hMjqC6f4BRAc+RXaE5N4Sz0VCW+r5qxTClXfGJFO3OXzAKX2XeK/LTdvVyj7FrU= X-Google-Smtp-Source: AGHT+IGLQXVdPTy6P4iJ6b9Hi7B3TbN9tg+qBPzfs/dxh4CRJsgPSaigTu3J+7vG3GRr4k+zsHFqhQ== X-Received: by 2002:a17:907:3f9c:b0:a7d:e956:ad51 with SMTP id a640c23a62f3a-a8a3f183312mr111185166b.21.1725434854106; Wed, 04 Sep 2024 00:27:34 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891d77fasm771151766b.167.2024.09.04.00.27.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 00:27:33 -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, Alexandru Ardelean Subject: [PATCH v3 6/8] dt-bindings: iio: adc: document diff-channels corner case for some ADCs Date: Wed, 4 Sep 2024 10:27:14 +0300 Message-ID: <20240904072718.1143440-7-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904072718.1143440-1-aardelean@baylibre.com> References: <20240904072718.1143440-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. Signed-off-by: Alexandru Ardelean Reviewed-by: Krzysztof Kozlowski --- 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 Tue Feb 10 19:14:18 2026 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 1EAF914F121 for ; Wed, 4 Sep 2024 07:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434859; cv=none; b=YKiIYOoRB1JweGD7cvXf7K2b4AyhVmz83O7emECXksXQ+Z/D2uRsKJg6ui1mjgbZiYqfffK1UQDhWRkpd9xUXwdO42kQJem+kVT3rtY7PnToral9Zz21V0nhlp72cA6SpeutCHxarp7f3yAl/Z04YCgzpAztPMJc3e5/L+CFWZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434859; c=relaxed/simple; bh=TpEbAOxLJo9X3Zeeh01HKv1eBJqkYuV62EEVQKT90Tg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UAbKcD2miAZXR2WMFtiOPZKYku3ICEzuV5v3qTrLbL4AKKnGxsmXAqGyEVj+xnIvMsyGFg25RkmBUybvHPqjVB+zDwe+eCzhSl6R1YZDg1TFt9xiuVO3PgZgGy0H0Dwm8rF5BskF+OPT7PpO+NxtYZehtSE++FoK+bwMR2O3JNE= 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=i0eNphas; arc=none smtp.client-ip=209.85.218.50 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="i0eNphas" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a83562f9be9so590816066b.0 for ; Wed, 04 Sep 2024 00:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725434856; x=1726039656; 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=jh5+8dfcxP1n12UyJdsCb2LbYKxVcZ8KkWJqqimBRgs=; b=i0eNphasexN6iAQD/37AoHqM9q/IRbcSahPvWCTEBb7mkC818hospyUNuW0doDW6jy m0JiJ04HTSoiSeyXs1puZtdJKXZ+trjd95+A2AzAGaKYILOVyavq5AT/BNLAa74Ve2mS 1A0PhAdLmG+r4rjNuRAL6nVeB2WZ6uj/eOphWaDWceTc3BQbWTiWenDEb0vBfQM/AEY0 o4VNib7OErSmtLkGXTdqgcLI9RDbimZKHo2N2caxIeTUswq6SrY/Dmyonjh3LOOO0mY5 R+zwPWBvMd4CdJfqseZK8qDkzHgbH6Ep1CruQiO/aRAfyex2UUKqKln37qSavbT+HYaW jkEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725434856; x=1726039656; 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=jh5+8dfcxP1n12UyJdsCb2LbYKxVcZ8KkWJqqimBRgs=; b=I30dQujzsHET2TrybyIeB6uB0YH0R+9aZna8/4QJpzyiQRXCpKitM4gUzziEVOCpP5 qEDihs6E1+wbmw+HHIF8drBeWjZm1u/UZ717Di/gB4mYAkv5PoM9sQzvUfiw/fuHxFMW 2FLZcj6GGXWyxDw8o66d2iPpYTxjdmwuh6mSZudqZMeozRSo7N7ARs11nGHirubZINAB NlYW9Igc8XBDYs3+TMKzXvAIrpUR0caO2Vr/tyJUQ7I/q72P0fa9KQQAptHoIG59APKJ pUgkUJgWKKY0ZcqVmzCErVXVCiyHerQjWp4IH6VrqvRGwRKbjiU0MiFzz+7visVM0FhH n3fA== X-Forwarded-Encrypted: i=1; AJvYcCV5MdgQDTyvNAs5ebtVtNML01WjJmbihGZOBVXHuqkRd2qsME6Zq5WCXtUEznJQbEvg8tGM+eFWBYkOUO0=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2UYZwKSswK7mUc8oSdqlnVv+Lh908IQ3Za7ch/WMZoJeo58qp pafrX+CoqLvaCR9QRLMBSNfejiDK7s5xqa3HLRbXbvaIxn5tAsZajP8/6Tc1+Nc= X-Google-Smtp-Source: AGHT+IF/mKU8VtKGw3txHXGLrkIcatKpJc6EndsKLR57NmvuX6ejS8m9dixlho5QXWEHWPCuOzFDMg== X-Received: by 2002:a17:907:7e82:b0:a86:6807:6c34 with SMTP id a640c23a62f3a-a89b9568e96mr956726466b.39.1725434856155; Wed, 04 Sep 2024 00:27:36 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891d77fasm771151766b.167.2024.09.04.00.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 00:27:35 -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, Alexandru Ardelean Subject: [PATCH v3 7/8] dt-bindings: iio: adc: add adi,ad7606c-{16,18} compatible strings Date: Wed, 4 Sep 2024 10:27:15 +0300 Message-ID: <20240904072718.1143440-8-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904072718.1143440-1-aardelean@baylibre.com> References: <20240904072718.1143440-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 Signed-off-by: Alexandru Ardelean --- .../bindings/iio/adc/adi,ad7606.yaml | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml b/Do= cumentation/devicetree/bindings/iio/adc/adi,ad7606.yaml index 69408cae3db9..f6fbc760d25d 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,45 @@ 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 differential bipolar 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 ). + items: + minimum: 1 + maximum: 8 + + bipolar: + description: + Each channel can be configured as a unipolar or bipolar single-e= nded. + When this property is not specified, it's unipolar, so the ADC w= ill + have only the positive input wired. + For this ADC the 'diff-channels' & 'bipolar' properties are mutu= ally + exclusive. + + oneOf: + - required: + - reg + - diff-channels + - required: + - reg + - bipolar + required: - compatible - reg @@ -170,6 +219,17 @@ allOf: adi,conversion-start-gpios: maxItems: 1 =20 + - if: + not: + properties: + compatible: + enum: + - adi,ad7606c-16 + - adi,ad7606c-18 + then: + patternProperties: + "^channel@[1-8]+$": false + unevaluatedProperties: false =20 examples: @@ -202,4 +262,52 @@ 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>; + }; + + channel@3 { + reg =3D <3>; + bipolar; + }; + + channel@8 { + reg =3D <8>; + diff-channels =3D <8 8>; + }; + + }; + }; ... --=20 2.46.0 From nobody Tue Feb 10 19:14:18 2026 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.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 39576146A93 for ; Wed, 4 Sep 2024 07:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434863; cv=none; b=rNce5iU1cj4yt2jGNwB7XHn1QAyxW429jNmAtNOOqUJRuFcxUBDua/yeH32OvArgNS6/cZEWhzZjjXv23lRBFRk7ACQb97lH3cmOSRlJ6aW0eAG9cTvfYgrLsqe8rfyuhUgOqTMGWGmOVtYrcc3+OQugtkL0/Lv6DZhRG96/I3U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725434863; c=relaxed/simple; bh=FCEF3DQauLwbuelWiyzYnUIiAJ4YoV06Rw2ecOgc+g4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BEC/1hwkZT6DWVNTJdrxUBmU4l4oEmGXxU02rMrU1WRy+pKTI7jBf98/JzKlba6Tf9FRgn8eEGPREcK2ksRZOpKPJqVAs7zHcm/wija8ZjE0UDWvlpmn+jSE6G896xWMoMuZkth5hEoLvR1X0RhmFL18C7sE57mvk9+JVjESvpU= 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=RwvF9YMF; arc=none smtp.client-ip=209.85.167.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="RwvF9YMF" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-533463f6b16so613969e87.1 for ; Wed, 04 Sep 2024 00:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725434858; x=1726039658; 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=lkYpWjHYFCY/21i91aWFXpsfKLY9KsXjMcsmRZHcUxA=; b=RwvF9YMFxnL1DacrbDSmYJc04zxtwwfb+iwKMgS+XnxpbEEPxucQGLrR9lhgIRBZex 9dXCFFQNHcszbMgu3jT7zd1o93XtbqOazzQM6z/Y5C3K0craZJbwh7ly/bPAEfytLVDp zDF1QqIn4OPkcfpCe1VDsKDMqcaUZAauwfkTuzbdKhJoRbc+BTK5FKmley9m2NoLXU6y AnzNVNqmDLNFmx+6ZjgkpFKRh5sDLOAcmxe30Poc2I32zxUUNrXB4U5YDL3xPQ0FbOi0 gqWktDMemT3xz/mI2eLjqgLMp3b5jlYmyA1ILjIpmQ29wxdNogdtW27E+Ha6PS0MkK2j fzvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725434858; x=1726039658; 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=lkYpWjHYFCY/21i91aWFXpsfKLY9KsXjMcsmRZHcUxA=; b=JPq1Fv0gKF8ROpocW5PNlnC/7D0dy1WX0VM/3cJnCsvL9RBz33o06YIF/TnsGi//Q/ PAxiHDKa7ErOuaHRYCe/YUQzB6I1OXAVxJNaFrJTkGfpjGEm2cuK0WjrhxpZnG+mrzCF dZC5fqHPM/4aeVplD7myHHxJw2QBrRvKIeETCehcGh1Z1DGWSDMegPT1TxGdrIaef1FH yjNpuzG5JMYyKtZ7sn+QvEq9HP4n3gP3nN5KwASWUzn0aXEcV/GdAoOiyhNhd5O5jJoi anaLHG/3iZ0X/JBJ7VbvAqzmvAfioqFigMknfuEDm7bzjgtnKDPzjfQ1LXZ9EyG4vYys Oeew== X-Forwarded-Encrypted: i=1; AJvYcCWuxIqUcYK3XzzMXSeOi15qSfLhZBCohevd8RCg/qHCXeITiR53BQIXTCszyFA9/ZBLrkHxdtEb/Kfkgk8=@vger.kernel.org X-Gm-Message-State: AOJu0YxDVeIDoycxkX5yCn37PYv+iM1ypmTvdYm2GaDOrOl7ein4LhUZ KFZy0SBvM7NcyDwfWnOA73ISR4Gms5fXzNiXbpSP9tuLouWqsqdfcqrfXrkI1tk= X-Google-Smtp-Source: AGHT+IFGKDKsdRlLIymAbs9bTeD+K3K5MI9AgZFw0RkI/G11MIQC7qMpJ9TZUrHeA5x2pKP+psVDbQ== X-Received: by 2002:a05:6512:1248:b0:531:4c6d:b8ef with SMTP id 2adb3069b0e04-53565f0f8bcmr1299859e87.6.1725434858157; Wed, 04 Sep 2024 00:27:38 -0700 (PDT) Received: from localhost.localdomain ([188.27.130.242]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891d77fasm771151766b.167.2024.09.04.00.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 00:27:37 -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, Alexandru Ardelean Subject: [PATCH v3 8/8] iio: adc: ad7606: add support for AD7606C-{16,18} parts Date: Wed, 4 Sep 2024 10:27:16 +0300 Message-ID: <20240904072718.1143440-9-aardelean@baylibre.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240904072718.1143440-1-aardelean@baylibre.com> References: <20240904072718.1143440-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 links: https://www.analog.com/media/en/technical-documentation/data-sheets/ad760= 6c-16.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/ad760= 6c-18.pdf Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7606.c | 266 +++++++++++++++++++++++++++++++---- drivers/iio/adc/ad7606.h | 17 ++- drivers/iio/adc/ad7606_spi.c | 55 ++++++++ 3 files changed, 309 insertions(+), 29 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index 4c3fbb28f790..999c4411859e 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -28,14 +28,44 @@ =20 #include "ad7606.h" =20 +typedef void (*ad7606c_chan_setup_cb_t)(struct ad7606_state *st, int ch, + bool bipolar, bool differential); + /* * 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 +static const unsigned int ad7606_18bit_hw_scale_avail[2] =3D { + 38147, 76294 +}; + +static const unsigned int ad7606c_16_scale_single_ended_unipolar_avail[3] = =3D { + 76294, 152588, 190735, +}; + +static const unsigned int ad7606c_16_scale_single_ended_bipolar_avail[5] = =3D { + 76294, 152588, 190735, 305176, 381470 +}; + +static const unsigned int ad7606c_16_scale_differential_bipolar_avail[4] = =3D { + 152588, 305176, 381470, 610352 +}; + +static const unsigned int ad7606c_18_scale_single_ended_unipolar_avail[3] = =3D { + 19073, 38147, 47684 +}; + +static const unsigned int ad7606c_18_scale_single_ended_bipolar_avail[5] = =3D { + 19073, 38147, 47684, 76294, 95367 +}; + +static const unsigned int ad7606c_18_scale_differential_bipolar_avail[4] = =3D { + 38147, 76294, 95367, 152588 +}; =20 static const unsigned int ad7616_sw_scale_avail[3] =3D { 76293, 152588, 305176 @@ -82,11 +112,19 @@ static int ad7606_reg_access(struct iio_dev *indio_dev, } } =20 -static int ad7606_read_samples(struct ad7606_state *st) +static int ad7606_read_samples(struct ad7606_state *st, bool sign_extend_s= amples) { + unsigned int storagebits =3D st->chip_info->channels[1].scan_type.storage= bits; unsigned int num =3D st->chip_info->num_channels - 1; - u16 *data =3D st->data; - int ret; + u32 *data32 =3D st->data.d32; + u16 *data16 =3D st->data.d16; + void *data; + int i, ret; + + if (storagebits > 16) + data =3D data32; + else + data =3D data16; =20 /* * The frstdata signal is set to high while and after reading the sample @@ -108,11 +146,25 @@ static int ad7606_read_samples(struct ad7606_state *s= t) return -EIO; } =20 - data++; + if (storagebits > 16) + data32++; + else + data16++; num--; } =20 - return st->bops->read_block(st->dev, num, data); + ret =3D st->bops->read_block(st->dev, num, data); + if (ret) + return ret; + + if (storagebits =3D=3D 16 || !sign_extend_samples) + return 0; + + /* For 18 bit samples, we need to sign-extend samples to 32 bits */ + for (i =3D 0; i < num; i++) + data32[i] =3D sign_extend32(data32[i], 17); + + return 0; } =20 static irqreturn_t ad7606_trigger_handler(int irq, void *p) @@ -124,11 +176,11 @@ static irqreturn_t ad7606_trigger_handler(int irq, vo= id *p) =20 guard(mutex)(&st->lock); =20 - ret =3D ad7606_read_samples(st); + ret =3D ad7606_read_samples(st, true); 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.d16, iio_get_time_ns(indio_dev)); error_ret: iio_trigger_notify_done(indio_dev->trig); @@ -142,6 +194,7 @@ 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; int ret; =20 gpiod_set_value(st->gpio_convst, 1); @@ -152,9 +205,13 @@ static int ad7606_scan_direct(struct iio_dev *indio_de= v, unsigned int ch, goto error_ret; } =20 - ret =3D ad7606_read_samples(st); - if (ret =3D=3D 0) - *val =3D sign_extend32(st->data[ch], 15); + ret =3D ad7606_read_samples(st, false); + if (ret =3D=3D 0) { + if (storagebits > 16) + *val =3D sign_extend32(st->data.d32[ch], 17); + else + *val =3D sign_extend32(st->data.d16[ch], 15); + } =20 error_ret: gpiod_set_value(st->gpio_convst, 0); @@ -267,7 +324,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; @@ -350,6 +407,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. @@ -410,6 +479,18 @@ 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, + .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, + .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, @@ -581,7 +662,122 @@ static const struct iio_trigger_ops ad7606_trigger_op= s =3D { .validate_device =3D iio_trigger_validate_own_device, }; =20 -static int ad7606_sw_mode_setup(struct iio_dev *indio_dev) +static void ad7606c_18_chan_setup(struct ad7606_state *st, int ch, + bool bipolar, bool differential) +{ + struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + + if (differential) { + cs->scale_avail =3D + ad7606c_18_scale_differential_bipolar_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_18_scale_differential_bipolar_avail); + /* Bipolar differential ranges start at 8 (b1000) */ + cs->reg_offset =3D 8; + cs->range =3D 1; + } else if (bipolar) { + cs->scale_avail =3D + ad7606c_18_scale_single_ended_bipolar_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_18_scale_single_ended_bipolar_avail); + cs->range =3D 3; + } else { + cs->scale_avail =3D + ad7606c_18_scale_single_ended_unipolar_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_18_scale_single_ended_unipolar_avail); + /* Unipolar single-ended ranges start at 5 (b0101) */ + cs->reg_offset =3D 5; + cs->range =3D 1; + } +} + +static void ad7606c_16_chan_setup(struct ad7606_state *st, int ch, + bool bipolar, bool differential) +{ + struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + + if (differential) { + cs->scale_avail =3D + ad7606c_16_scale_differential_bipolar_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_16_scale_differential_bipolar_avail); + /* Bipolar differential ranges start at 8 (b1000) */ + cs->reg_offset =3D 8; + cs->range =3D 1; + } else if (bipolar) { + cs->scale_avail =3D + ad7606c_16_scale_single_ended_bipolar_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_16_scale_single_ended_bipolar_avail); + cs->range =3D 3; + } else { + cs->scale_avail =3D + ad7606c_16_scale_single_ended_unipolar_avail; + cs->num_scales =3D + ARRAY_SIZE(ad7606c_16_scale_single_ended_unipolar_avail); + /* Unipolar single-ended ranges start at 5 (b0101) */ + cs->reg_offset =3D 5; + cs->range =3D 1; + } +} + +static int ad7606c_sw_mode_setup_channels(struct iio_dev *indio_dev, + ad7606c_chan_setup_cb_t chan_setup_cb) +{ + unsigned int num_channels =3D indio_dev->num_channels - 1; + struct ad7606_state *st =3D iio_priv(indio_dev); + bool chan_configured[AD760X_MAX_CHANNELS] =3D {}; + struct device *dev =3D st->dev; + int ret; + u32 ch; + + /* We need to hook this first */ + ret =3D st->bops->sw_mode_config(indio_dev); + if (ret) + return ret; + + device_for_each_child_node_scoped(dev, child) { + bool bipolar, differential; + u32 pins[2]; + + ret =3D fwnode_property_read_u32(child, "reg", &ch); + if (ret) + continue; + + /* channel number (here) is from 1 to num_channels */ + if (ch =3D=3D 0 || ch > num_channels) { + dev_warn(st->dev, + "Invalid channel number (ignoring): %d\n", ch); + continue; + } + + bipolar =3D fwnode_property_present(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=3D ch && pins[1] =3D=3D ch) + differential =3D true; + else + differential =3D false; + + ch--; + + chan_setup_cb(st, ch, bipolar, differential); + chan_configured[ch] =3D true; + } + + /* Apply default configuration to unconfigured (via DT) channels */ + for (ch =3D 0; ch < num_channels; ch++) { + if (!chan_configured[ch]) + chan_setup_cb(st, ch, false, false); + } + + return 0; +} + +static int ad7606_sw_mode_setup(struct iio_dev *indio_dev, unsigned int id) { unsigned int num_channels =3D indio_dev->num_channels - 1; struct ad7606_state *st =3D iio_priv(indio_dev); @@ -596,17 +792,30 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio= _dev) =20 indio_dev->info =3D &ad7606_info_sw_mode; =20 - /* Scale of 0.076293 is only available in sw mode */ - /* After reset, in software mode, =C2=B110 V is set by default */ - for (ch =3D 0; ch < num_channels; ch++) { - struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + switch (id) { + case ID_AD7606C_18: + ret =3D ad7606c_sw_mode_setup_channels(indio_dev, + ad7606c_18_chan_setup); + break; + case ID_AD7606C_16: + ret =3D ad7606c_sw_mode_setup_channels(indio_dev, + ad7606c_16_chan_setup); + break; + default: + /* Scale of 0.076293 is only available in sw mode */ + /* After reset, in software mode, =C2=B110 V is set by default */ + for (ch =3D 0; ch < num_channels; ch++) { + struct ad7606_chan_scale *cs =3D &st->chan_scales[ch]; + + cs->scale_avail =3D ad7616_sw_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7616_sw_scale_avail); + cs->range =3D 2; + } =20 - cs->scale_avail =3D ad7616_sw_scale_avail; - cs->num_scales =3D ARRAY_SIZE(ad7616_sw_scale_avail); - cs->range =3D 2; + ret =3D st->bops->sw_mode_config(indio_dev); + break; } =20 - ret =3D st->bops->sw_mode_config(indio_dev); if (ret) return ret; =20 @@ -655,9 +864,16 @@ int ad7606_probe(struct device *dev, int irq, void __i= omem *base_address, st->oversampling =3D 1; =20 cs =3D &st->chan_scales[0]; - cs->range =3D 0; - cs->scale_avail =3D ad7606_scale_avail; - cs->num_scales =3D ARRAY_SIZE(ad7606_scale_avail); + switch (id) { + case ID_AD7606C_18: + cs->scale_avail =3D ad7606_18bit_hw_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7606_18bit_hw_scale_avail); + break; + default: + cs->scale_avail =3D ad7606_16bit_hw_scale_avail; + cs->num_scales =3D ARRAY_SIZE(ad7606_16bit_hw_scale_avail); + break; + } =20 ret =3D devm_regulator_get_enable(dev, "avcc"); if (ret) @@ -706,7 +922,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 2113ad460c0f..6b0897aa2dc7 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -22,7 +22,7 @@ .scan_type =3D { \ .sign =3D 's', \ .realbits =3D (bits), \ - .storagebits =3D (bits), \ + .storagebits =3D (bits) > 16 ? 32 : 16, \ .endianness =3D IIO_CPU, \ }, \ } @@ -45,7 +45,7 @@ .scan_type =3D { \ .sign =3D 's', \ .realbits =3D (bits), \ - .storagebits =3D (bits), \ + .storagebits =3D (bits) > 16 ? 32 : 16, \ .endianness =3D IIO_CPU, \ }, \ } @@ -88,6 +88,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_SCALE_SHOW (AD760X_MAX_CHANNELS * 2) @@ -95,6 +97,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 /** @@ -151,9 +154,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 { + unsigned short d16[20]; + unsigned int d32[10]; + } data __aligned(IIO_DMA_MINALIGN); __be16 d16[2]; }; =20 @@ -192,6 +199,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..b8d630ad156d 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, + .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