From nobody Sun Feb 8 19:55:46 2026 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F383F222595; Mon, 10 Mar 2025 07:57:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741593440; cv=none; b=TEnDzl3BqcQ/s2hZuJnw5xRtvIhWW8ZvphIQEDzLOqxTnAf/YQr58Ye27VOHb8GSDEY3Mb3UqpKuBntz89AB+UVqhIdnQzVdtOiYJQKIKm7P5BohA0BHWR/+ghwsjpZvq4Xs0mc1/sx4u9+qsHwJVCq3AyeuHlgru9AIAnXj9/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741593440; c=relaxed/simple; bh=yU+C+ctdw5d7G7jsiaddrDPo0Urr2NVMzLggVGFVTc0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cFKgAuNXz5zm9lUBRbejXlIvKKfSMJ51kzw3YhDwc6juTqdd8t+/V6uGVo/dkyPXz4MLva6AnmrkDQsdLG1LCkgeuu9GGhlkIEj9hi4NK1gLJ4SHdPrMYEJ49CRNVQjgS7HoV72mm3sP4Fr0oBob9rXoQ8at122tRaDPXYog66E= 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=FHlLB94g; arc=none smtp.client-ip=209.85.218.49 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="FHlLB94g" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-abfe7b5fbe8so575054766b.0; Mon, 10 Mar 2025 00:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741593434; x=1742198234; 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=tBlTT1AB0KMrBYwTn3M+sIKO/uDVK4wSMDsGEkLbHK4=; b=FHlLB94g6VR6pLe1qjAZVDHnLOet/gFiTca1RcgmIP5nc3f5lTBvnOnV8KySa4rW6t G2z87I8yLLuyHzFScymM4Cc8VqkN1FKHjkwjJ8Dj1KUv4YLhjezq7DiU4jqEf5kh5+uL mYNa6/F+8Czroo1yiqgS5i4myeM7H92gK+9quuI6Hq/xmHyNForztOEl2cwrzDTRsNm3 KfWS/OUoTcUxMaQ+csRNH+GMUbMO0FZXamj5bFJQr+Y7Sd0JUElc7M18MztIEDVoE5ys BreLjJ0NoA3Yz73Ymi8ym6o7dTpcggXIVM5oDrYwE4Gydy9P/Zfvf7qhKJfIESQqpvCT s6DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741593434; x=1742198234; 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=tBlTT1AB0KMrBYwTn3M+sIKO/uDVK4wSMDsGEkLbHK4=; b=TkMLbRRpOeDWcvp3Lw1tUQ9yjd3yJahYKd4gQAS1Is7cPMc/yHY3XCjcNTIisQnPNm nSs4y2t24oJfniItt3EEoY3UIpnsLzvqQrl7TfVQCSHB85T5tlmmzHbl1rRZ+Kz/d4Uy 4t8/kCn/6aH2JlthVsLCToncbnIOHg9V4VJpsAL/YFToLk0dAPejmnjztt2PqLkTrEPy zsA6qBsoQEgmo4Aq/5a+jTOz7LY4nBGGwuA/Hbv/w3iaeJ6WdqeQu9mw7kN21CCuPmbi VtpyFP0g4KrtRI0wsTtyBfZTp+gwfRa+pSDGOJvaP3SDBDg6AgoYKw6baWm31YNYDgkR jP0A== X-Forwarded-Encrypted: i=1; AJvYcCWhceQkT5aL6E3AtYLthw3j2ZQVf4nW7gITd7tueYUP9DvA9uh4sUer8hEGsoq8yk6T+8qTUt7OqxDsCZxs@vger.kernel.org, AJvYcCWjezel8OKr3BlVZumGFYWoklVxdGI7qS3xce2Dsy5RHuG/269QXDsIkyXe1y8PpBqFuDQzjv92+UiC@vger.kernel.org X-Gm-Message-State: AOJu0Yyd+QDFEkVumKv1587NABc/KlpjzPdYVDxmar1Db1sc0WJucT4C xBTiVn2hHBM+86Dm70ktf0U14koduPZHZcG6+Aiiy//9LSCXEikJ X-Gm-Gg: ASbGncsOzB/4hIouwN/HRcFFMR1fCMX6GgW/xwPOgSKDmZR1Az2gIwc/Czi+LD9VR94 DY8QB2/gAOW690LkF93ENqlrRWVE64xlNm614RI1PLfE+5Jrm+dAtW+SDuZ46Ie3+y4zb4hdlRU +Kv2fp+vpr/dzCduZITSPAIUNOJAo+H+Wbq6A+0Wal9/ozye+FHny9bOG3NDaNO8kPuiHTxxdqr 0bGzxgxKQw1WU7Ki/hWklGozyn47ibjJlDHrwNypaCAiMpJjImis+2x4oswJsXvkOv+UWW6f5Jq hQwPy6cwIniQlMMPBybbZGYlIgCPs/ToTGwr X-Google-Smtp-Source: AGHT+IFtYKN/7c+ChwWeAaa28tcqn/iMpy24US0C339Y0FaBl5ubiDBfLwDGvCnIZoUzibDrZoI2Gg== X-Received: by 2002:a05:6402:34c7:b0:5e5:ba77:6f24 with SMTP id 4fb4d7f45d1cf-5e5e22d4c66mr34927806a12.16.1741593433762; Mon, 10 Mar 2025 00:57:13 -0700 (PDT) Received: from xeon.. ([188.163.112.51]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac2895e7e6asm274697566b.54.2025.03.10.00.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 00:57:13 -0700 (PDT) From: Svyatoslav Ryhel To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Laxman Dewangan , Svyatoslav Ryhel Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/2] dt-bindings: thermal: generic-adc: Add optional io-channel-cells property Date: Mon, 10 Mar 2025 09:56:37 +0200 Message-ID: <20250310075638.6979-2-clamor95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250310075638.6979-1-clamor95@gmail.com> References: <20250310075638.6979-1-clamor95@gmail.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" This implements a mechanism to derive temperature values from an existing ADC IIO channel, effectively creating a temperature IIO channel. This approach avoids adding a new sensor and its associated conversion table, while providing IIO-based temperature data for devices that may not utilize hwmon. Signed-off-by: Svyatoslav Ryhel --- .../devicetree/bindings/thermal/generic-adc-thermal.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/thermal/generic-adc-thermal.= yaml b/Documentation/devicetree/bindings/thermal/generic-adc-thermal.yaml index 12e6418dc24d..4bc2cff0593c 100644 --- a/Documentation/devicetree/bindings/thermal/generic-adc-thermal.yaml +++ b/Documentation/devicetree/bindings/thermal/generic-adc-thermal.yaml @@ -30,6 +30,9 @@ properties: io-channel-names: const: sensor-channel =20 + '#io-channel-cells': + const: 1 + temperature-lookup-table: description: | Lookup table to map the relation between ADC value and temperature. @@ -60,6 +63,7 @@ examples: #thermal-sensor-cells =3D <0>; io-channels =3D <&ads1015 1>; io-channel-names =3D "sensor-channel"; + #io-channel-cells =3D <1>; temperature-lookup-table =3D < (-40000) 2578 (-39000) 2577 --=20 2.43.0 From nobody Sun Feb 8 19:55:46 2026 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.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 6BAE22222BC; Mon, 10 Mar 2025 07:57:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741593442; cv=none; b=B0Ru+yYHx0/Txyp+8PuhT/tmVaPenMBFjY4FaT6KFSGhSNEAG6E/F5I3s7v5McEP+ww/9eTZLNtwsWkSxkTDsLdeAc4WLuAYdwL68BCGEXDceE5POSkEq/KfE/y0TRbfn0bBC4PCc5T0aDEctzutkThuycSXwnQLxGxOBaMUL4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741593442; c=relaxed/simple; bh=IRW2DIUZjUg11Wxpe6r9qiFzm+6oup2NeqXVoEzJym4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rwl+egwQXh48mE2faGMI+pVzzyu9+PmVj8cNIXv4pwBYfa1hADzkB4XWsDcScBQjRSeXPrG15E2I2S9eiVICdBBOYJFNQINx0tbfLYkdc659CUhm5Fgpa2bcWhm9Q6wMNFxv70LlOVMhRGI/arGeUVURlXsd2tPtjxb4MN3IjdQ= 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=L5nQZ++0; arc=none smtp.client-ip=209.85.218.53 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="L5nQZ++0" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-ac286d4ed05so177349266b.3; Mon, 10 Mar 2025 00:57:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741593437; x=1742198237; 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=Um6v6XdMIQ/YPUNEUAxNwsTqTXuDEykk4Jq5COm9hZ0=; b=L5nQZ++0DJposk6lKH7IR5UUCspl6BOG7gwNjXSLuJxn9ALXeyiqmXWc6wJAuleqpT mAV/VEaAdwgaH4b2DLauZcOjV6XQtS8sfM1RrsZ2pnKZ/Zz6Y9TySPEQBTv8VqxvjnBj yU7PoxXl0wtIzQ7RYstrqRDV0tUi5i5/nm9LhfFpcK/kl54KFxwtca/ymqoMVnHxDdL7 fosQ4T7Qd2UdMQoMFPxy/WIYWKH4niW9GHgD5ArooUmubXn9ScWHhfQhjUTk7Bm6839c emZSD82JOUhkGoeTW6aoswpgZHDG+sy+6TbvncfYF7V7DC/t3C+RlUbw6OBNIp2908US TFww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741593437; x=1742198237; 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=Um6v6XdMIQ/YPUNEUAxNwsTqTXuDEykk4Jq5COm9hZ0=; b=NU3TUZnwJ/Z0kOMGDQIXYy9ZD2zc/nkNlRNZlUbQ7TON+uDiKDlIS5Qy3Fk2suQosc uDvUHP4tf+FManvKU7z691kzb3uauGAOslwrFsc1Zhvst1zj7PeLUtO8d4gFoYDkoWND mLuijwKk1Jrvzu71XDGDSLKS1EmNSknjLz0tMNWzeO2nltGYB7vk6/lyRlepE6qw7tsJ tocWD+swz289FuMDClepog6aKKJfE1WCZfTBt2SvzTaVQEXF9WG0CEbCMp1LmrF2F8ne BoFvxUUzovW9XvB57G6Ybpy6icYB5YN3dV/Rnn1IqeYB7zpSDetGJ8LBv1kJglOIKxxU ircg== X-Forwarded-Encrypted: i=1; AJvYcCULGQjrqHKi55oFZqZrOwV4KQO+UMS/GxStVcwREiEvB9rDd5+diJgiumsF/jxG0pzCoedDlpBOv1Z2BJ/X@vger.kernel.org, AJvYcCW1uDsU4ShZoLbuSlf5QpWNTKwRrH2zJoDx6XaQSxjv4+KfNIXJvp1WVXxwJ4nCQvCk88yyAoLMGBL9@vger.kernel.org X-Gm-Message-State: AOJu0YzWevfc5QOqVeX10AOpns775JcmGtTDeVkx577q7aW2Cl2S5JTQ oCKW2Y3jQEPlSUoH9XrSPheiOmljedDwsS7JKoI+IshX955mtU82 X-Gm-Gg: ASbGncvt8GHfAMKZfm0Cg7C6eGQJjdm+/7RHjvgfC0hkCjauuElIarBKtnDi2UwofAU fHx/FYLJbvL96pghG80IA8yU8g7p9eYz3NwXwJ9MsvCuYUALczfv8CQ1KftkNP6aKppPV4HbjO1 ZUIW7ON6FvaAtscei8zufo4zg9yEL8bMvn8MGqNsMdkWxwd+PIsC9Rc1P02Oh3vL57qrV/bUHyC XHGEnVKM7AwSjdo4LFscg6ZhefFm2g9bLUzGNNfWl5pXmbASMzP097rXdYU86gj6Q++PN8B05Hc oaCePxOTfISbInSPVVrHnW6beX/T82VUkosGJEeFp3clYCU= X-Google-Smtp-Source: AGHT+IFLKGUKxsl6twHWzzRJajNzVYfmXdVnBYN9298SUG7/OC3ET3EOjHh1Ib8lt3dCyN+uJOv1UQ== X-Received: by 2002:a17:907:1998:b0:ac2:a473:4186 with SMTP id a640c23a62f3a-ac2a4734ebdmr264406366b.34.1741593434836; Mon, 10 Mar 2025 00:57:14 -0700 (PDT) Received: from xeon.. ([188.163.112.51]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac2895e7e6asm274697566b.54.2025.03.10.00.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 00:57:14 -0700 (PDT) From: Svyatoslav Ryhel To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Laxman Dewangan , Svyatoslav Ryhel Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/2] thermal: thermal-generic-adc: add temperature sensor channel Date: Mon, 10 Mar 2025 09:56:38 +0200 Message-ID: <20250310075638.6979-3-clamor95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250310075638.6979-1-clamor95@gmail.com> References: <20250310075638.6979-1-clamor95@gmail.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" To avoid duplicating sensor functionality and conversion tables, this design allows converting an ADC IIO channel's output directly into a temperature IIO channel. This is particularly useful for devices where hwmon isn't suitable or where temperature data must be accessible through IIO. One such device is, for example, the MAX17040 fuel gauge. The temperature data, while technically a product of conversion and thus categorized as IIO_CHAN_INFO_PROCESSED, maintains its unscaled state (milli-degree). To account for this, IIO_CHAN_INFO_RAW is used along with IIO_CHAN_INFO_SCALE to provide different degrees of accuracy. Signed-off-by: Svyatoslav Ryhel --- drivers/thermal/thermal-generic-adc.c | 62 ++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/therma= l-generic-adc.c index ee3d0aa31406..7dcc2e1168a4 100644 --- a/drivers/thermal/thermal-generic-adc.c +++ b/drivers/thermal/thermal-generic-adc.c @@ -7,6 +7,7 @@ * Author: Laxman Dewangan */ #include +#include #include #include #include @@ -73,6 +74,65 @@ static const struct thermal_zone_device_ops gadc_thermal= _ops =3D { .get_temp =3D gadc_thermal_get_temp, }; =20 +static const struct iio_chan_spec gadc_thermal_iio_channel[] =3D { + { + .type =3D IIO_TEMP, + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + } +}; + +static int gadc_thermal_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct gadc_thermal_info *gtinfo =3D iio_priv(indio_dev); + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret =3D gadc_thermal_get_temp(gtinfo->tz_dev, val); + if (ret) + return ret; + + return IIO_VAL_INT; + + case IIO_CHAN_INFO_SCALE: + /* scale to a degree centigrade */ + *val =3D 1; + *val2 =3D 1000; + return IIO_VAL_FRACTIONAL; + + default: + return -EINVAL; + } +} + +static const struct iio_info gadc_thermal_iio_info =3D { + .read_raw =3D gadc_thermal_read_raw, +}; + +static int gadc_iio_register(struct device *dev, struct gadc_thermal_info = *gti) +{ + struct gadc_thermal_info *gtinfo; + struct iio_dev *indio_dev; + + indio_dev =3D devm_iio_device_alloc(dev, sizeof(struct gadc_thermal_info)= ); + if (!indio_dev) + return -ENOMEM; + + gtinfo =3D iio_priv(indio_dev); + memcpy(gtinfo, gti, sizeof(struct gadc_thermal_info)); + + indio_dev->name =3D dev_name(dev); + indio_dev->info =3D &gadc_thermal_iio_info; + indio_dev->modes =3D INDIO_DIRECT_MODE; + indio_dev->channels =3D gadc_thermal_iio_channel; + indio_dev->num_channels =3D ARRAY_SIZE(gadc_thermal_iio_channel); + + return devm_iio_device_register(dev, indio_dev); +} + static int gadc_thermal_read_linear_lookup_table(struct device *dev, struct gadc_thermal_info *gti) { @@ -153,7 +213,7 @@ static int gadc_thermal_probe(struct platform_device *p= dev) =20 devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev); =20 - return 0; + return gadc_iio_register(&pdev->dev, gti); } =20 static const struct of_device_id of_adc_thermal_match[] =3D { --=20 2.43.0