From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vk1-f172.google.com (mail-vk1-f172.google.com [209.85.221.172]) (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 5F2B63A7F60 for ; Sun, 9 Aug 2026 08:28:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786264088; cv=none; b=P3hMiX4csLsldOvBFTYitGN/Hq+jyM1ScB2fpZ/amuT121ymee9iFySnAGBCkXqYeSRyqo/Iy9PW4AS8F6PW/cXq5LUzhtAKz2a+OKXkaY9ExODOF11Ih6QL/P8w1pMhhJTIrI8hOmXIUQu2/YveJKtQz3jwINKz0zX1lHhNEQY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786264088; c=relaxed/simple; bh=ztQMnOAhsVLsTHPjrj99yVY1PEfiigj3zy0kNYd75Z4=; h=Content-Type:Date:Message-Id:Subject:From:To:Cc:Mime-Version: References:In-Reply-To; b=vCyCdl9sMHi0U9SsanxYStwmx4RP8US4o2JGUNBS3RKZndUpexJN2gv0e2eW7k7s70FDzSn+mtbET7KK35mP6pq17nEJ5PiyvOyHwaR7vmsZ7KpmI7OhrBb+tAENo1q20A1eVTXBCHoC3XYaIPzvdtbW2A/ZuxT7eyuMnUkUirA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=noI+9hVV; arc=none smtp.client-ip=209.85.221.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="noI+9hVV" Received: by mail-vk1-f172.google.com with SMTP id 71dfb90a1353d-5bf5370d38fso293893e0c.2 for ; Sun, 09 Aug 2026 01:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786264084; x=1786868884; darn=vger.kernel.org; h=in-reply-to:references:content-transfer-encoding:mime-version:cc:to :from:subject:message-id:date:content-type:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Wwu0sNSPRL9t1VlX8pUN/G4E4jICdzc6GI/iobwP1p4=; b=noI+9hVViPEmkwBNJM0ZpftidmnOSf7YPziIC6B6+hdc+d6sYGJwj6wCAvsEYGAddJ ss/TuohXTuhHNqPwAAXySloqwHoXiJgEURQDxHEZJp3wl5w/5YnvJA03rFGWJb9fGFFr F0vmA1KnvUqB4Vn8ZshGql9IFnz6tAHzTMwbwmlhAlDuRYkW01rk0JGSVb2r+1PnFYKu Ol+omts26uQZ8KJBmYbJk3ZeHLHBO8n5igFpMTI+v7fkxoN4nUUBdMKuIFyBFbg7vr7G a8peu94z861RLzmMTQo4mDp1HbtsCg4bVtJjVaXYhNLxSx/FL8duW6KrrsM1PO9v9t6r x8TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786264084; x=1786868884; h=in-reply-to:references:content-transfer-encoding:mime-version:cc:to :from:subject:message-id:date:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Wwu0sNSPRL9t1VlX8pUN/G4E4jICdzc6GI/iobwP1p4=; b=syN1TQD6HAxmuAL0zYVmGfQmXJfk4xsXeV0JTWI95E/znKV7/PcitCIL2LEpOJy5lq hQ/M7GrHEiMkOSEn5S0y9A4j0mDIwA9Yqj9vJag3weMQBcIysIa0QjT7EHK6osBdYzTm jRqUR+cMLZiiaEXCPv162ozG6uKTC9zsJn71QGpZY+gA9C2o5H0SSUmOLjcgDDjG0j8M 8hDSZaD2wOk6gKz60lAds+PlUDv1s1V0X7KUvjed/CIXO2EmV6v7B46z+EJ3gSaqXJmi SeM8jfx615aIUo4amLR4D+GhyzqwG4wAIEGCrz3QWaVpN5Kd6xiTlHHGz6Zn9eHOiLd0 Nckw== X-Forwarded-Encrypted: i=1; AHgh+Rp0s8qJ5GfzDJp1E3spV5LA86tAMlBsoAsb5mceIigVuntaRzHlxJSQQGAoY3Lp7QkYxrPZ5rQ6LP6ABLw=@vger.kernel.org X-Gm-Message-State: AOJu0Ywlb/g8uYLNvx28XqDl5e9+cMjH8DJqdnKaQPG5X5P8t+TS8YQK aUQ9qMeRDcsMuTP+nw7QqoHXQiSYmi9cu+1/P9Yxk8WUICxk4/VhhvLb X-Gm-Gg: AR+sD12s1gaq5E8ThKFpr/5hxQGnfzwaHPWKyRxgVzCCnTqv6t10idphcIif74uFbXb eiy7BiXfKzWmkpZ25eu7HeySafzw2j8Aw4Mzzzi6mnpHfJGvSIhCRepRMvHkuJf/rnWt9oiTdBB mYe5EjWnDJSzZR8Po2r6V3ZvLxIP242Q6AINZ5Ff3LIyW8flWx5oP6nOGvWGOHfy2Ue619HrjUD 1f/Md/krSiGatfH8xox2ANRfRcXoJbhMPUiZbafWb+A6k1XKtSOKBqiIO0Jh0OQ7sXUIYK/dXZX +N/ANlHOd2+lNDjdo+cm6u8pDN3g7zthPOe7MWPHGc3RLO1dyRWEBkU1n9WUaK0HisEoPfN45Cv TeBzQVwQArrBoZavc5CEJqVjga9f5NnYrCpSrucP9VAEaqp/a+XAPk8gcEj0XRTBXP1rkJKkK7E L+oJcNIpAtk+MYmW6YLGhLBZYSq8gUF8bg/ufmI5AvO/QxbLJjJOAOE2a7t/W69A== X-Received: by 2002:a05:6122:e250:b0:5c3:61c2:9ec6 with SMTP id 71dfb90a1353d-5c3d9161b60mr3772625e0c.7.1786264084241; Sun, 09 Aug 2026 01:28:04 -0700 (PDT) Received: from localhost ([2800:bf0:82:11a2:7ac4:1f2:947b:2b6]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5c40b212fa6sm2751296e0c.16.2026.08.09.01.28.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 09 Aug 2026 01:28:03 -0700 (PDT) Content-Type: text/plain; charset=UTF-8 Date: Sun, 09 Aug 2026 03:28:01 -0500 Message-Id: Subject: Re: [PATCH v3 4/9] iio: adc: ti-ads1262: support per-channel reference and gain From: "Kurt Borja" To: "David Lechner" , "Kurt Borja" , "Jonathan Cameron" , "Rob Herring" , "Krzysztof Kozlowski" , "Conor Dooley" , "Linus Walleij" , "Bartosz Golaszewski" Cc: =?utf-8?q?Nuno_S=C3=A1?= , "Andy Shevchenko" , , , , 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 X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20260807-ads126x-v3-0-f89925d72792@gmail.com> <20260807-ads126x-v3-4-f89925d72792@gmail.com> In-Reply-To: On Sat Aug 8, 2026 at 1:39 PM -05, David Lechner wrote: > On 8/7/26 10:58 PM, Kurt Borja wrote: >> Allow each channel to select its voltage reference through the >> "reference-sources" firmware property. Then, use the reference voltage >> to calculate available scales. > > It looks like this is also implementing PGA gain at the same time, but > isn't mentioned in ght commit messsage. I would also expect something > here about how we should handle PGA bypass (even if it just says default > works always and we can consdier controlling it later). I forgot about the PGA bypass stuff. I do believe it should belong in devicetree because it changes the voltage range of the analog inputs. See datasheet section 10.3 and 7.3. > >>=20 >> The ADS1262 allows single-ended supply configurations or bipolar supply >> configurations. In single ended configurations both the analog and >> digital rails share the same ground, i.e. AVSS =3D DGND =3D 0 V. In bipo= lar >> supply configurations, AVSS can go below ground, e.g. AVSS =3D -2.5 V. >>=20 >> If AVSS is below ground, the ADC can achieve true bipolar measurements >> and the external references can also have voltage levels below ground. >> This is currently an issue because the regulator subsystem doesn't >> support negative voltages. >>=20 >> The ad4170-4 driver faces this problem too and the same workaround is >> used in this case: assume every regulator reports magnitudes (absolute >> values). If the chip has a bipolar supply configuration, then assume >> positive references are above ground (>=3D 0 V) and negative references >> are below ground (<=3D 0 V). This is not a hardware constraint, but it i= s >> the most common wiring. >>=20 >> Signed-off-by: Kurt Borja >> --- >> drivers/iio/adc/ti-ads1262.c | 417 ++++++++++++++++++++++++++++++++++++= +++++-- >> 1 file changed, 406 insertions(+), 11 deletions(-) >>=20 >> diff --git a/drivers/iio/adc/ti-ads1262.c b/drivers/iio/adc/ti-ads1262.c >> index b3b7b1249102..360ce01a5871 100644 >> --- a/drivers/iio/adc/ti-ads1262.c >> +++ b/drivers/iio/adc/ti-ads1262.c [...] >> @@ -688,6 +818,91 @@ static const struct regmap_bus ads1262_regmap_bus = =3D { >> .max_raw_write =3D ADS1262_MAX_REGMAP_WRITE, >> }; >> =20 >> +static void ads1262_calculate_scales(int (*scales)[2], size_t num_scale= s, >> + u32 full_scale, u64 mult, >> + u32 resolution) >> +{ >> + unsigned int i; >> + s64 val; >> + >> + for (i =3D 0; i < num_scales; i++) { > > This could use a comment explaining the relasionship of the index in the > array to the PGA multipier. > >> + val =3D mul_u64_u64_shr(full_scale, mult, resolution - 1 + i); >> + iio_val_s64_decompose(val, &scales[i][0], &scales[i][1]); >> + } >> +} >> + >> +static int ads1262_populate_scales_resistance(struct ads1262 *st, >> + const struct iio_chan_spec *spec) >> +{ >> + struct ads1262_channel *chan =3D &st->channels[spec->scan_index]; >> + u32 full_scale; >> + >> + if (WARN_ON(!ads1262_ref_is_external(chan->ref_p, chan->ref_n))) >> + return -EINVAL; > > WARN_ON() is a bit strong for something that is coming from the devicetre= e. > I would just fail the parse() function with an appropriate error message > so that we don't have to check here. Actually, an IIO_RESISTANCE channel without external reference is just a bug and would read past the end of buffer below, which is the only reason I verify it one last time. We should never actually hit this warning. I'll add a comment explaining that. > >> + >> + full_scale =3D st->rref_ohms[chan->ref_p - 1][chan->ref_n - 1]; >> + >> + chan->num_scales =3D ARRAY_SIZE(chan->scales); >> + >> + ads1262_calculate_scales(chan->scales, chan->num_scales, full_scale, >> + PICO, ADS1262_ADC1_RESOLUTION); >> + >> + return 0; >> +} --=20 Thanks, ~ Kurt