From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vk1-f170.google.com (mail-vk1-f170.google.com [209.85.221.170]) (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 790243AAF56 for ; Sun, 9 Aug 2026 08:28:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786264086; cv=none; b=FlBYN+t7sidXJHR1fp1SkOggQHpurHqWx9N7OJl9iuiUkuLPKQiFSvIl3hiUrVVsZSk4V05Xg2BTbAvE1R1tDt3I1ATlw6BzsAThcBmLHzyZg13eQlFd8/ZJ2rl7OQIPyT0DfutLONhxpM3nXW+wc/VSVs4udWQmOXDcWZVBsHk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786264086; c=relaxed/simple; bh=ztQMnOAhsVLsTHPjrj99yVY1PEfiigj3zy0kNYd75Z4=; h=Content-Type:Date:Message-Id:Subject:From:To:Cc:Mime-Version: References:In-Reply-To; b=Y4SlBwnt+zM3j5V+3pf2ivwynWgV5onYU1cdSXu+8wxT/E6WReqE2P6O73OgCZtWG6zMttJwz8B5xDknROKwOL4atAir6ThSo7aFZeOrFFE0Plw45Bh4bfstSZeTJJrLKNrRzBtoz4cngbdPUDmdYH3nYZrKC71t3yK5n1ZaU6E= 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.170 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-f170.google.com with SMTP id 71dfb90a1353d-59b074ec7ceso434330e0c.1 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=WKcH2NIT6FWdpnHTfQrJvbZb68Zsw6pHV9V9FCaSYZGdgz9c9vqYp6g7FW0MOW8uEn UkfnUMfkKx7Cp4noSjfGhyhc7DSMVNb0g+wU4U60cCFrrt8WQHJQYBPcWs+KiqzU/GOg rIf7Q1+GtHGMB+3Pn3YQL/fl5QdKG3m7nEaivlXpobMzVV65AuV8h501T6TYeHrceFmd 55PJoXbdy+3I6uUOQGcdjMDtfy6imgCPo2vTdVj6ZaIvgpXyehxOn7Z6WI2ew4y5tHQ1 vb2j49LiRktzxVSbJJu7S2O7ItFwkcmQjrplInhrmYaXwRhEPsRxdZC3aKcr4TO5Cnhi Ds/g== X-Forwarded-Encrypted: i=1; AHgh+RrvWFY52Y2/GVkilSBmoGS07wseACjWwvFXuZqFsqkTGLVcUb3D141MuwVRLadk7ItDSmnxsyK72piQ@vger.kernel.org X-Gm-Message-State: AOJu0YwCLyU8ZW/sCZnLPSJKuf2UeTSuhgkjL70oaVCsNenYW3qWAp9g qEFVDXA/Q3HNp1/vtZr7ngHJYVqRiTmAWA4nWGzjN6H3bshIlJXrHRpK X-Gm-Gg: AR+sD12rcdGNdGoKfxk+QuRFm7DzZmoYUIJjHpE6uaAZ5NEAZDIUeVTbIdn6EY0rCxe lXGsx2E1XPfk1m2MFWON/uIKiq1M85sH5x2rgGwjtiY5XeWvErn6GeIo7Y3aB+vXOlOHE+I6kZT OzlYs3Kv356aQv7y4BuSnf8T8qob4us1lH9zPHW5Zy5zu1dZT3lS1j2+WonJsuaY3Uu9vRnh4dQ HMVNzqjqA32WpUb4uE/+U1nsWeZAineUclrz4/9vkLajgAUsT6Nv9OxY8jbeOeAyIN5i74PJWZv kQ+6dYol/Lo+IX1vl44nQ29xmlA/+dtRCS102YP+DfHJih/tHlHvA5vBQl4N/aCELbdlU92BxBG f+LH+LJUflNcDlPF9/N1Dq1Af5FzhN8x4wEFTIMNgM0ePDudlYcqu8i37Xn3leEA2y6yM4PjbT7 rqwnLCq0h/h8glYF5tt6sQbCoV9bvc88CjF5yez6rfO06kloNSoPBcJcGnREtlaQ== 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: devicetree@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