From nobody Sun Feb 8 10:43:29 2026 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.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 0D07420F09B; Mon, 3 Mar 2025 12:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741004530; cv=none; b=HCAqzaKbdw78kp9MH0qbHS78gLwUz6yrUbJTKwoTrlKsGs5pUbxYShkCOxjAOJodMsPn8BXHE8Lvg4cuYGMVnTQm2Qg58QfSr9L2ZpPi2xEkGHAYRoMv13cR9i+QDx2N7alaBvPfEu1FAGzWQtX5qMcXaMGT34EO/p52BuN9q54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741004530; c=relaxed/simple; bh=3P7plyntZFcl2TvumIvg1gg+MV5fPPzYZIQsPwlnySs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nZ4CduYRugd+9PaFya7CinQ3j8t8o1Br4mwOi4PCc5hw2Bc6n3SrVzb0cXNPniHGsH3WUgOG4YlltP0O/rXWxfTr4YM9bXIvFthdxNULeflOC7t5eQ8zu42doTNKF5DDqRCSfGbTNgg/ikiyDQr274Xmptxb2ANCbCJt//cA/c0= 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=HgZnVEnF; arc=none smtp.client-ip=209.85.167.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="HgZnVEnF" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-54838cd334cso5151689e87.1; Mon, 03 Mar 2025 04:22:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741004527; x=1741609327; 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=bKcPvNO+XMSYUnpyn2o7+FoGqwTbIxZBoY9y1RYbRGE=; b=HgZnVEnFIgUeyUwyMGQ+Xs9OrXpry5CgmVPrk9khjDcj1JRDrse6AYf71LrXigtrUj i7F9aR7J7KzzWUd1MY1z25G2bofEDNyO5SlG+re0rtXGwOEvBota08mNc1D3agsOnisT PpDmuLHxCgCpLsClDoKXdsLwluiP1JmK5PKuAoxq4SdDNDi60kb9I8WtbJ/ebOLrtfXW dzwDwju3Z+9wv1pPEXhNiA53Sb3xtQbaBBcrVUazEQ4JFs/FeRxo99gNQwp1nfWnqS48 AV9ScgpEXDWJeEP0QcEc7iA0C7l+XeWlUkx0ayc23bYKPtzDAoGEWOycVpYrJA+4cMP6 Sz6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741004527; x=1741609327; 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=bKcPvNO+XMSYUnpyn2o7+FoGqwTbIxZBoY9y1RYbRGE=; b=XhKbMtli9XNb61c51I2JzHemUQ0S4lni8v+N9+aVPGItthaFO3tdy9Sq+Yab62ltvw l91S9CZhs4Q4tttBQeMlcBXQHsvHT9IH4dlrjJS9nok0RHCSZnnsJCcXNBlO+Es7mRmg 8fll5TaFDRxvOf1wNH1UbcQsGE8ZoN2zYcGlLSr1fq2xb9HqrGM8p+j9JWtAamRwZ7oq lSCUqSBcqeiTwKVUA7KZUnVAIAmvkixNfX0YulaJIiTO1zAYWLRjHva/lCHhZ5DrKSgM rayWfPnvbZuxcZ025lDPzRLw+ueC1TzJC0ZL8OoOwR5/wzqcliyxtQkvGpH6cUz5zLtr gEVg== X-Forwarded-Encrypted: i=1; AJvYcCWKhWDFtK63wYFTHCeiLkUtdJQPDOmG+DpZxAfAIhz6jJ3oitT3RMlZc/UMMzqVneRaJM+/vDfDEW1b@vger.kernel.org, AJvYcCWsmXH0OLY2VHoARfFWzqa7to/oedGc3faN6UrtRNHODyYU8bFuX0AORxMcy0TuXZwO2E5UTv7SDAOilXBJ@vger.kernel.org X-Gm-Message-State: AOJu0YyhGFJwLAcrhB4T885jjU5VNOUAh1EjQRBoFifyL/E91Xuug+J6 TA0iS7M1AiV6XmdCipTOQkP+z0GExI0+y3Io4LfccghxRvQqRJ8Z X-Gm-Gg: ASbGncsHelJiHrPIzfWTWZ/OAyiZJ/ghGOxb4yKoMHxjfTcmLr04kFoIvtaNpBNB00l S4am3X3/2aR1mOUH2T+wU2GTWVUlFG4rgxGyIV18+RmI5zdUsHyKgKR9EgJlE6EAvzvnJ6B3tY1 B8idGrl9lgzgk4Qu7fW3yJuY8JMsOZjBZi5P9jYJHlqSMBWtLJbpVs/V9Xh09ajiMqewZdGCzzi 4xb6NegzA0x/8Ltk+PP1ZNhywmzb3rfqpwACDn9IfhVE4NjfkIauTdRg5TU9wgsJWRiXL21UvY/ 6/eAYqmaMp9SWNCR06VuEk9WpYbJwlk3iZs= X-Google-Smtp-Source: AGHT+IHWtPDKpHupjft94sSLR1zlyXRW+3TSgQROpvRsH2VJWhrlZkDu//jnxvTGOSOEBQ90KqHuLQ== X-Received: by 2002:a05:6512:3d19:b0:545:ea9:1a19 with SMTP id 2adb3069b0e04-5494c10c72bmr5744120e87.5.1741004526999; Mon, 03 Mar 2025 04:22:06 -0800 (PST) Received: from xeon.. ([188.163.112.51]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-30b868766desm13486611fa.100.2025.03.03.04.22.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 04:22:06 -0800 (PST) From: Svyatoslav Ryhel To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Laxman Dewangan Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/2] dt-bindings: thermal: generic-adc: Add optional io-channel-cells property Date: Mon, 3 Mar 2025 14:21:50 +0200 Message-ID: <20250303122151.91557-2-clamor95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250303122151.91557-1-clamor95@gmail.com> References: <20250303122151.91557-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 A= DC IIO channel, effectively creating a temperature IIO channel. This approach avoi= ds 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 10:43:29 2026 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 61C59211261; Mon, 3 Mar 2025 12:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741004532; cv=none; b=Gpm8trc6eiEvy0axRoVfGXvPQb+6bwDNyvT1pZ7I9jMo9KmdjXZHG7BgE77inKoaHwaVSQe6wJy/YGsOzjW4+G/P4NHxA1SJLpzhzxufmCzxvcf5B2AA3fUsUzui8XZkB5yckzLEyVqD/Je7f6JtzC8rzi2PYKFG+Njjt3BBkl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741004532; c=relaxed/simple; bh=/RoB+O5ZCm4Jt93NVDs+1xICxKfZ4DLQGNO3TjWMPtU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WFU4PeDdnuTyOEoDy2C3ToJGpKOQlLQonjKOa8irfM/DuJKaADpQhJY/QFY4Slrb88+hNc7ZZT6orpR/hhQTynmVG6zQkKeJhaxOAxrXZSDMNLniAskV2El316oswmfMmaKjhLT9j7r/zPhZ1cSqyGV34zGV8RJsMUi4QYn3YYo= 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=W7TV8fFC; arc=none smtp.client-ip=209.85.208.174 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="W7TV8fFC" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-30b9f7c4165so20927941fa.3; Mon, 03 Mar 2025 04:22:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741004528; x=1741609328; 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=kOGpGJnVdsS2eqbkL2yrs0irjDblflxlQ891CwEclog=; b=W7TV8fFC+6O9TCz9jLCPIZSfz4gejQRNrN+h2rtLMqI6dWClZR6Jxaqi1n+GGtJEnZ u6wgA9jgLQMMuGn1EBOu4Yx6gQ2vtNT7v5BAjklfKSQEnZpB4gm1wekA+1zjiDJh3uOc 9ByiCqyyxOf7vEFtlzqEYXCzNQ4QM0wNnX9Yv/Evu+6hVYBTll5mLsnw9YaySNrEqiB7 IKXlO2NUouBOIv+j3xekTBYS4BeS+mF+PTL+A61P5OWhVkI5MtZyZ4rwaZmUL+vRuwM6 3+rwnu32QLxoYFLXNgE1hN83YI5Zk4d6zOFpwsGysf9Asec/3DDf3S6Ey2b2eKRqubDr 0lEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741004528; x=1741609328; 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=kOGpGJnVdsS2eqbkL2yrs0irjDblflxlQ891CwEclog=; b=T+zeo7NLX1PXsFiSod9JToJJhWk+IOThnzQ7Rj1T+rZJNnjFYPIDXFW5NbceJb3s2/ BhxWmc8qF5rKb9MRpLdix2G1UU4TVSUhafqe/DBpbja4m94oj8jWQqc5bzpoXTt1/YQ8 7ddEPGmQl9o7GP1J2zF/MOtqlRwZbaB4PNu6Vfjo7m++sj868/+EtteQomkneaE37zr7 tmS5rTxZI3jlUgjUfoGqOFTl9qRveyupE795OIvCxaKaN5HEQPtLdHl5NBxE0l6C3Ov2 P1KhDOVr8rOHwtztNMjDjhheY/6WzIB9ecFL/jv5DChe5oP3TltZM5oOYroNMNeStX06 i0Fg== X-Forwarded-Encrypted: i=1; AJvYcCXnUiT3DcpVS07PK7jFSenuJ+u8XB1Pq04SVipRNRZXXq5R2a4dBENYL9Nbd3P9ZOAAi1EaxUTOd6OU@vger.kernel.org, AJvYcCXyKvoAfhqmT78e1PCX4TelrF9CE/0IqJoXV8AuyiGfkIE2WBdofSKKalrO3PkjDDQ1bj27W8VUz4HA5zam@vger.kernel.org X-Gm-Message-State: AOJu0YzcBdjp3L/jJEbtocF37SwtiAGk84cak2XJH5SoE9T4y0hyrGy4 w2zetoc3Gyy8Y1k5G2jf4HRuQogGR0Vrymi2Prg+9urI/pJFTaCxQcrK5A== X-Gm-Gg: ASbGncvQlT6fQax3jgR5kkuw/x6WNU+kFVRvGN8gLForEzNPtuhlCH3O+ypyvTQaHIp Y/Sgc8tXfefZFpEGgYzH2WMeGXpeEqXz4NjEescoxJ5ZakmR4bMBDc2TJ4vD2vjgk2owZlKiFQD 8XGd5LGrHTMv9e9tF8gvRr1me7SQGMyZ/RKrpFmsJ5pEKrOGsJ5ulsUJllVTuMYaAO1hj/EFtsU Qi6NHZEsfktmEJv9fxJfS2+dHH5/cmtdzkBj3dI9W3Tv32C8UDOpFAk2uwJ3ow/uE6lLEsW08ks Qm0A+/y4TUbUCn8+Kup8lxHag5qOjmu31hs= X-Google-Smtp-Source: AGHT+IGI1Gd+yOAoF2e2IdT9/R4jZ9Lr6thS4xPZWq9Os6HxY5dMlAcS7PgHy1ECByIHbtsiXkFQgQ== X-Received: by 2002:a2e:bc14:0:b0:308:ee65:7f4d with SMTP id 38308e7fff4ca-30b93454590mr44700661fa.32.1741004528273; Mon, 03 Mar 2025 04:22:08 -0800 (PST) Received: from xeon.. ([188.163.112.51]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-30b868766desm13486611fa.100.2025.03.03.04.22.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 04:22:07 -0800 (PST) From: Svyatoslav Ryhel To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Laxman Dewangan Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] thermal: thermal-generic-adc: add temperature sensor channel Date: Mon, 3 Mar 2025 14:21:51 +0200 Message-ID: <20250303122151.91557-3-clamor95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250303122151.91557-1-clamor95@gmail.com> References: <20250303122151.91557-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 I= IO 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. Signed-off-by: Svyatoslav Ryhel --- drivers/thermal/thermal-generic-adc.c | 54 ++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/therma= l-generic-adc.c index ee3d0aa31406..a8f3b965b39b 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,57 @@ 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_PROCESSED), + } +}; + +static int gadc_thermal_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *temp, int *val2, long mask) +{ + struct gadc_thermal_info *gtinfo =3D iio_priv(indio_dev); + int ret; + + if (mask !=3D IIO_CHAN_INFO_PROCESSED) + return -EINVAL; + + ret =3D gadc_thermal_get_temp(gtinfo->tz_dev, temp); + if (ret < 0) + return ret; + + *temp /=3D 1000; + + return IIO_VAL_INT; +} + +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 +205,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