From patchwork Thu Nov 25 02:08:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12638399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02F50C433F5 for ; Thu, 25 Nov 2021 02:52:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234986AbhKYCzj (ORCPT ); Wed, 24 Nov 2021 21:55:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235436AbhKYCxi (ORCPT ); Wed, 24 Nov 2021 21:53:38 -0500 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7000C0698D4 for ; Wed, 24 Nov 2021 18:10:54 -0800 (PST) Received: by mail-lf1-x135.google.com with SMTP id l22so12205712lfg.7 for ; Wed, 24 Nov 2021 18:10:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=12C3fQGGzI1eMdxkB4i98B03WTNPWwmJzoAMnHB2J+A=; b=wFn+jyCBkB6unHasWMTRD419h+1W4HcFbsJNjGlJ2n0PiuQUkz7CwAWzEV/0Y7pZ39 cfsZHGj9tU+85t4s0LkzU0rHU8s6aIVRkijf6+xy+WGNu+Rum0XZh8iMfzXxa0dHWrVC b1HuaAYBe8OWNgIx2P+foBGVgC8pmhvICEvL9FwGer80Q8gmDGtCLZ6IV2ERO72fjSX6 e4UNKTo2+Na35A5BmZGA6Z32yTpXfUM4mQ/bT3yERrX07h6rTaT+78o+1D4Xq1yX3H/k JUm1p6sbsMHKm8YWyKhR9J9VP5U/eXA0rxFGTa+Yk4paUFg2GCVuHQ0ANVmZCQl/Beyu pHPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=12C3fQGGzI1eMdxkB4i98B03WTNPWwmJzoAMnHB2J+A=; b=OCv0mQSIsDjLU9ezJjHK4gMPNi1jpbZeCoe21qk2IvX1kQQPMSB2FlBYE+O/pgM/oE hlMqDuRIXhpmr0Kp28hE7G2KhgAPHb1Q0RMZ4OqGV9EE8UhY1On5P9GpqId2SO//PEoT C368XTA7Vnqk6CjA4VgHsBh0ttMDUcvZpUVAT9lon9Vby2Q1nKEh7rjXKyZBGSkbmmvx E2QYL5zSwk1p6yXw0BxqcO0GKblDo/MsBqrTS+ezPAqsUcwYoiSYdIFMtTTUhmC5Efvj Q76JzITo6/44m9ANMwIZZFXv05NEb1DIwgdp3SfjoPTCK4jgRYxtNAHOetW70uNUPq2i KTaw== X-Gm-Message-State: AOAM5332oDbrRx2e85Km1CQ1ti1KFAFWBgGbS2YKJMwgYztb65Tn5bdd ExSnf8KBHDonaiwBdV/xcluQmmjH/AZ8sA== X-Google-Smtp-Source: ABdhPJz+JEx+lDtB/2EQ7pKZ5xIk6V1jNFTIS9QhZVU7oewlUOIbbcltLI8aE+iHBsveWEQo0hVt6w== X-Received: by 2002:a05:6512:33c9:: with SMTP id d9mr19641633lfg.615.1637806253193; Wed, 24 Nov 2021 18:10:53 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id m3sm132507lji.112.2021.11.24.18.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 18:10:52 -0800 (PST) From: Linus Walleij To: Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, Linus Walleij , Peter Rosin , Chris Lesiak Subject: [PATCH 1/4] hwmon: (ntc_thermistor) Merge platform data into driver Date: Thu, 25 Nov 2021 03:08:38 +0100 Message-Id: <20211125020841.3616359-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211125020841.3616359-1-linus.walleij@linaro.org> References: <20211125020841.3616359-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Platform data is supposed to be used with "board files", device descriptions in C. Since the introduction of the NTC driver in 2011, no such platforms have been submitted to the Linux kernel, and their use is strongly discouraged in favor of Device Tree, ACPI or as last resort software firmware nodes. Drop the external header and copy the platform data into the driver file. Cc: Peter Rosin Cc: Chris Lesiak Signed-off-by: Linus Walleij --- drivers/hwmon/ntc_thermistor.c | 41 ++++++++++++++-- include/linux/platform_data/ntc_thermistor.h | 50 -------------------- 2 files changed, 36 insertions(+), 55 deletions(-) delete mode 100644 include/linux/platform_data/ntc_thermistor.h diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c index cf26c44f2b88..034ef55d0706 100644 --- a/drivers/hwmon/ntc_thermistor.c +++ b/drivers/hwmon/ntc_thermistor.c @@ -14,12 +14,45 @@ #include #include #include +#include +#include -#include +enum ntc_thermistor_type { + TYPE_B57330V2103, + TYPE_B57891S0103, + TYPE_NCPXXWB473, + TYPE_NCPXXWF104, + TYPE_NCPXXWL333, + TYPE_NCPXXXH103, +}; -#include +struct ntc_thermistor_platform_data { + /* + * One (not both) of read_uV and read_ohm should be provided and only + * one of the two should be provided. + * Both functions should return negative value for an error case. + * + * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required to use + * read_uV() + * + * How to setup pullup_ohm, pulldown_ohm, and connect is + * described at Documentation/hwmon/ntc_thermistor.rst + * + * pullup/down_ohm: 0 for infinite / not-connected + * + * chan: iio_channel pointer to communicate with the ADC which the + * thermistor is using for conversion of the analog values. + */ + int (*read_uv)(struct ntc_thermistor_platform_data *); + unsigned int pullup_uv; -#include + unsigned int pullup_ohm; + unsigned int pulldown_ohm; + enum { NTC_CONNECTED_POSITIVE, NTC_CONNECTED_GROUND } connect; + struct iio_channel *chan; + + int (*read_ohm)(void); +}; struct ntc_compensation { int temp_c; @@ -651,8 +684,6 @@ static int ntc_thermistor_probe(struct platform_device *pdev) pdata = ntc_thermistor_parse_dt(dev); if (IS_ERR(pdata)) return PTR_ERR(pdata); - else if (pdata == NULL) - pdata = dev_get_platdata(dev); if (!pdata) { dev_err(dev, "No platform init data supplied.\n"); diff --git a/include/linux/platform_data/ntc_thermistor.h b/include/linux/platform_data/ntc_thermistor.h deleted file mode 100644 index b324d03e580c..000000000000 --- a/include/linux/platform_data/ntc_thermistor.h +++ /dev/null @@ -1,50 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * ntc_thermistor.h - NTC Thermistors - * - * Copyright (C) 2010 Samsung Electronics - * MyungJoo Ham - */ -#ifndef _LINUX_NTC_H -#define _LINUX_NTC_H - -struct iio_channel; - -enum ntc_thermistor_type { - TYPE_B57330V2103, - TYPE_B57891S0103, - TYPE_NCPXXWB473, - TYPE_NCPXXWF104, - TYPE_NCPXXWL333, - TYPE_NCPXXXH103, -}; - -struct ntc_thermistor_platform_data { - /* - * One (not both) of read_uV and read_ohm should be provided and only - * one of the two should be provided. - * Both functions should return negative value for an error case. - * - * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required to use - * read_uV() - * - * How to setup pullup_ohm, pulldown_ohm, and connect is - * described at Documentation/hwmon/ntc_thermistor.rst - * - * pullup/down_ohm: 0 for infinite / not-connected - * - * chan: iio_channel pointer to communicate with the ADC which the - * thermistor is using for conversion of the analog values. - */ - int (*read_uv)(struct ntc_thermistor_platform_data *); - unsigned int pullup_uv; - - unsigned int pullup_ohm; - unsigned int pulldown_ohm; - enum { NTC_CONNECTED_POSITIVE, NTC_CONNECTED_GROUND } connect; - struct iio_channel *chan; - - int (*read_ohm)(void); -}; - -#endif /* _LINUX_NTC_H */ From patchwork Thu Nov 25 02:08:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12638401 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39F03C433EF for ; Thu, 25 Nov 2021 02:52:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235436AbhKYCzk (ORCPT ); Wed, 24 Nov 2021 21:55:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235479AbhKYCxi (ORCPT ); Wed, 24 Nov 2021 21:53:38 -0500 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E3FBC0698D5 for ; Wed, 24 Nov 2021 18:10:57 -0800 (PST) Received: by mail-lj1-x22a.google.com with SMTP id l9so9395914ljq.5 for ; Wed, 24 Nov 2021 18:10:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ISanM5Ms5QyPXFSs3B16gTrLvoGEzuF9zx/zlV2+gAA=; b=WLKjSj6HPpOqTWAbcRFrg0zIOcCQ+OlTNtiUCvLzSaTbunzU/tcNPqnJq2cRpzkn1z aEFjkRoFfoBVghp7tijrGib6SQDt01oT/i3MwRUkmR2+Xc7PsvCucpBi42TICxHPBRuv Q+S7wm5M9r0WButUxGGVM5GxzOGV9HNG/ftbS78p6FNaSKYShVZ6sU3/S3m0pOGocy7W nSJM/U+i6RI/ojewpLeYb31N/oG9SCL3S3zFNNKsotgWW4GV9nGtquGaNjLssw4C979L 8E6oA7B7xLX62l2oTIi5C7dM+S9mT95YkGKZlVai52nP9jsjv433KVfHGZt4v3oV/F+1 rb9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ISanM5Ms5QyPXFSs3B16gTrLvoGEzuF9zx/zlV2+gAA=; b=N0DAC++pgxJBoKfMFF3B6squTw7EITZsWsPZS62ctrsUw0UlBeC3qJJxIyKAeknWXd r6Je+YaXbBESpJrRIUB7wxDTIVlRCJOwybseV/U45xfTMdid9UEhRbUu78mUjtXLJfHw DjP9FzrI9MGhhJXPJJe/BkJt7EEjOxOGc66+FjUq+c42+EB5+EivvKTPlesRnYnqZBaJ UkCvldN8tJVtrdqjq6UL4bprVlzI0i0AGERCJk2BKRgU1yUZ/X2Q8vxaP8okqoodiQj8 TsuUhFL23Y5NKRBWUA7kt90GYCdRXRYDlZlNwskQDK8CVBjQMxGppcGXoaTpdSGD/T3l cjiQ== X-Gm-Message-State: AOAM532kX88nEr7kq81Ir3wQ5AqWZxFNuUAZcNoDj8bhfru7p0faxQky KeLulp4g0dcLooxFtPQ7E7Qv5Q== X-Google-Smtp-Source: ABdhPJx9La+8uLY0HFFj2ZJR9WJG3qEC4VmBHhsEEst4ujp2wA6onL/rBvrMfg8P0R/dqJUjrV5sZg== X-Received: by 2002:a05:651c:612:: with SMTP id k18mr21231089lje.383.1637806255405; Wed, 24 Nov 2021 18:10:55 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id m3sm132507lji.112.2021.11.24.18.10.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 18:10:54 -0800 (PST) From: Linus Walleij To: Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, Linus Walleij , Peter Rosin , Chris Lesiak Subject: [PATCH 2/4] hwmon: (ntc_thermistor) Drop get_ohm() Date: Thu, 25 Nov 2021 03:08:39 +0100 Message-Id: <20211125020841.3616359-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211125020841.3616359-1-linus.walleij@linaro.org> References: <20211125020841.3616359-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Nothing in the kernel (this driver) is using the callback to read ohms directly. We always read a voltage and convert it to a resistance. Drop this callback. Cc: Peter Rosin Cc: Chris Lesiak Signed-off-by: Linus Walleij --- drivers/hwmon/ntc_thermistor.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c index 034ef55d0706..8a78e899fa12 100644 --- a/drivers/hwmon/ntc_thermistor.c +++ b/drivers/hwmon/ntc_thermistor.c @@ -28,10 +28,6 @@ enum ntc_thermistor_type { struct ntc_thermistor_platform_data { /* - * One (not both) of read_uV and read_ohm should be provided and only - * one of the two should be provided. - * Both functions should return negative value for an error case. - * * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required to use * read_uV() * @@ -50,8 +46,6 @@ struct ntc_thermistor_platform_data { unsigned int pulldown_ohm; enum { NTC_CONNECTED_POSITIVE, NTC_CONNECTED_GROUND } connect; struct iio_channel *chan; - - int (*read_ohm)(void); }; struct ntc_compensation { @@ -600,9 +594,6 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data) { int read_uv; - if (data->pdata->read_ohm) - return data->pdata->read_ohm(); - if (data->pdata->read_uv) { read_uv = data->pdata->read_uv(data->pdata); if (read_uv < 0) @@ -690,19 +681,11 @@ static int ntc_thermistor_probe(struct platform_device *pdev) return -ENODEV; } - /* Either one of the two is required. */ - if (!pdata->read_uv && !pdata->read_ohm) { - dev_err(dev, - "Both read_uv and read_ohm missing. Need either one of the two.\n"); + if (!pdata->read_uv) { + dev_err(dev, "read_uv missing\n"); return -EINVAL; } - if (pdata->read_uv && pdata->read_ohm) { - dev_warn(dev, - "Only one of read_uv and read_ohm is needed; ignoring read_uv.\n"); - pdata->read_uv = NULL; - } - if (pdata->read_uv && (pdata->pullup_uv == 0 || (pdata->pullup_ohm == 0 && pdata->connect == NTC_CONNECTED_GROUND) || From patchwork Thu Nov 25 02:08:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12638403 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2467C433EF for ; Thu, 25 Nov 2021 02:54:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238177AbhKYC53 (ORCPT ); Wed, 24 Nov 2021 21:57:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238798AbhKYCz3 (ORCPT ); Wed, 24 Nov 2021 21:55:29 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C24FC0698D6 for ; Wed, 24 Nov 2021 18:10:59 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id l22so12206078lfg.7 for ; Wed, 24 Nov 2021 18:10:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sysNk/MtA9eShgMwPDGkyoQIaKsUFfBEZqV8IACsDcg=; b=rA87TsnEL99v7Mc5Fi9qh3MfkYt0ep7aCOtWvS33Er9pvxLo+51OVpaQefI8z/3GQE vBzag5HhoqMMUolyGBRhv+PQyUSWPBaQmjJrCENlbdfSVYwGQnWkB6THYpizA7VaNQ4v GeVBehy/4yIdtU/Lu6jnaYHjvJ8pOFNOqIa+cu62cjxsFYOx0FXXnFxIP3VVbWqInRQs aj5hOfZ7PX5TWJLGYGboTNxIwBuI5Y1u0XwrirQGVwN38sjrZ6ZD0IQMXrV8dfjfPbjt j4D4heJWOV5v3Bbe88I1J2pLZrpqoAvjZaGnmzyBdO679m+u4JEFVJRuSCePIKfJgBDB TP1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sysNk/MtA9eShgMwPDGkyoQIaKsUFfBEZqV8IACsDcg=; b=biZylMq8d0kihvrFW0dTT3qZ51CtngPYW3E8JOhrDEEQVG1b+wPLV0CY10s9b4IT/k ahjiZHwXVRPUvicPPl35swiUm73u+bfH8yLtbcTbSjws4YyFNJKki6VHMTB3YDBJej/f QtUZdtS8njsnBws4ENjbDQMErzIZ2j1tZNSZuRnOlF/wJxCYziuNXiz5DhNz00Y91WJ4 I+8i1VndRNd9Jbi+svoDFjZj6UhfN1zTd/AHAd4NTUicGyQGRTWNnjtBWjWbpZgylXXV F4rAQ7qmwBFyxRpeCjHuXcbk+1Rct46Fp0iTv471P/Tbv+5SLlZ17IM/tL4yRQJjxfEy Ha2w== X-Gm-Message-State: AOAM532ypoGBOAL3mjqFOhcwyfEF6gRVubsj/1VSA3OFDI4+DoaUYbZ+ ZM33yZtdMQqL8NLLr9mjkPQSiQ== X-Google-Smtp-Source: ABdhPJxgd2sqD1K0rZRdu5zYc2W/sGuXl8EKUsDOg/9k4NVbQnEaJf2Vcp/nLCS/afkBFPPxKgJznA== X-Received: by 2002:a05:6512:398b:: with SMTP id j11mr19361070lfu.170.1637806257708; Wed, 24 Nov 2021 18:10:57 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id m3sm132507lji.112.2021.11.24.18.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 18:10:56 -0800 (PST) From: Linus Walleij To: Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, Linus Walleij , Peter Rosin , Chris Lesiak Subject: [PATCH 3/4] hwmon: (ntc_thermistor) Drop read_uv() depend on OF and IIO Date: Thu, 25 Nov 2021 03:08:40 +0100 Message-Id: <20211125020841.3616359-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211125020841.3616359-1-linus.walleij@linaro.org> References: <20211125020841.3616359-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The only possible assignment of a function to get a voltage to convert to a resistance is to use the internal function ntc_adc_iio_read() which is only available when using IIO and OF. Bite the bullet and mandate OF and IIO, drop the read_uv() callback abstraction and some ifdefs. As no board is using the platform data, all users are using OF and IIO anyway. Cc: Peter Rosin Cc: Chris Lesiak Signed-off-by: Linus Walleij --- drivers/hwmon/Kconfig | 5 ++-- drivers/hwmon/ntc_thermistor.c | 49 +++++++++------------------------- 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 64bd3dfba2c4..e491e8f354bb 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1414,8 +1414,9 @@ config SENSORS_PC87427 will be called pc87427. config SENSORS_NTC_THERMISTOR - tristate "NTC thermistor support from Murata" - depends on !OF || IIO=n || IIO + tristate "NTC thermistor support" + depends on OF + depends on IIO depends on THERMAL || !THERMAL_OF help This driver supports NTC thermistors sensor reading and its diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c index 8a78e899fa12..cedb3ee0f762 100644 --- a/drivers/hwmon/ntc_thermistor.c +++ b/drivers/hwmon/ntc_thermistor.c @@ -28,8 +28,7 @@ enum ntc_thermistor_type { struct ntc_thermistor_platform_data { /* - * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required to use - * read_uV() + * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required. * * How to setup pullup_ohm, pulldown_ohm, and connect is * described at Documentation/hwmon/ntc_thermistor.rst @@ -39,9 +38,7 @@ struct ntc_thermistor_platform_data { * chan: iio_channel pointer to communicate with the ADC which the * thermistor is using for conversion of the analog values. */ - int (*read_uv)(struct ntc_thermistor_platform_data *); unsigned int pullup_uv; - unsigned int pullup_ohm; unsigned int pulldown_ohm; enum { NTC_CONNECTED_POSITIVE, NTC_CONNECTED_GROUND } connect; @@ -346,7 +343,6 @@ struct ntc_data { int n_comp; }; -#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_IIO) static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata) { struct iio_channel *channel = pdata->chan; @@ -451,20 +447,9 @@ ntc_thermistor_parse_dt(struct device *dev) pdata->connect = NTC_CONNECTED_GROUND; pdata->chan = chan; - pdata->read_uv = ntc_adc_iio_read; return pdata; } -#else -static struct ntc_thermistor_platform_data * -ntc_thermistor_parse_dt(struct device *dev) -{ - return NULL; -} - -#define ntc_match NULL - -#endif static inline u64 div64_u64_safe(u64 dividend, u64 divisor) { @@ -594,13 +579,10 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data) { int read_uv; - if (data->pdata->read_uv) { - read_uv = data->pdata->read_uv(data->pdata); - if (read_uv < 0) - return read_uv; - return get_ohm_of_thermistor(data, read_uv); - } - return -EINVAL; + read_uv = ntc_adc_iio_read(data->pdata); + if (read_uv < 0) + return read_uv; + return get_ohm_of_thermistor(data, read_uv); } static int ntc_read(struct device *dev, enum hwmon_sensor_types type, @@ -681,19 +663,14 @@ static int ntc_thermistor_probe(struct platform_device *pdev) return -ENODEV; } - if (!pdata->read_uv) { - dev_err(dev, "read_uv missing\n"); - return -EINVAL; - } - - if (pdata->read_uv && (pdata->pullup_uv == 0 || - (pdata->pullup_ohm == 0 && pdata->connect == - NTC_CONNECTED_GROUND) || - (pdata->pulldown_ohm == 0 && pdata->connect == - NTC_CONNECTED_POSITIVE) || - (pdata->connect != NTC_CONNECTED_POSITIVE && - pdata->connect != NTC_CONNECTED_GROUND))) { - dev_err(dev, "Required data to use read_uv not supplied.\n"); + if (pdata->pullup_uv == 0 || + (pdata->pullup_ohm == 0 && pdata->connect == + NTC_CONNECTED_GROUND) || + (pdata->pulldown_ohm == 0 && pdata->connect == + NTC_CONNECTED_POSITIVE) || + (pdata->connect != NTC_CONNECTED_POSITIVE && + pdata->connect != NTC_CONNECTED_GROUND)) { + dev_err(dev, "Required data to use NTC driver not supplied.\n"); return -EINVAL; } From patchwork Thu Nov 25 02:08:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 12638405 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18B21C433F5 for ; Thu, 25 Nov 2021 02:54:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229845AbhKYC5a (ORCPT ); Wed, 24 Nov 2021 21:57:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238810AbhKYCz3 (ORCPT ); Wed, 24 Nov 2021 21:55:29 -0500 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19325C0698D7 for ; Wed, 24 Nov 2021 18:11:02 -0800 (PST) Received: by mail-lf1-x135.google.com with SMTP id u3so12229727lfl.2 for ; Wed, 24 Nov 2021 18:11:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LiKHdfqSNHA/KZi7sX9wOmmsE2ep6Bx+XNqfYZCkFRc=; b=mYz1c6kvCk5YcpQrTyrmuZqHygeEchjKcpSMbkq5ACofoq7Jl7dVIGtwsQAwvHNCeC +1r81C6KFjV/KLVeyCWTNrHxKGqOO4HPKn9z+ITt52zzdKpq0Vx/krVfBnn5WdRDBYoU +5a44zdESGXhLpJ9uMEBBB2TeOJhVzXEgMdo7xXlT/L4+wdxUl/Gh+3RTZkvQb+MHiVY pCIHFV7BcUosXr/XZoK6WewT1Dt0ezyLBoMGnmYnWRQ9Jdj/2SaVanpdF5mRfW25OPR+ MwDNjJNIX5kQ4dy0X85ibRlRv7vyGw+61WZ0ugf1GpcuC+Hfc+W4lChPYZLlk40K8SfU DqeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LiKHdfqSNHA/KZi7sX9wOmmsE2ep6Bx+XNqfYZCkFRc=; b=UdWuP5DXy5bxFQWvJ67Gz/mv5NWDVgkcmuU+shuAI+vRRXefMEig3BMmEIN4Mn3RTf 1RhZ+jdGUAiL0ydjMpRlGx7dxv+vZSITTjO0NPcyP/1joxXoOzrWOTtO3pxVv7ixTuAG sKebj/rpMheuTf1F/oDUxIEaQ8TYR3vTna5ULAuqPL+xFHm58Dfpqxm8Uplt85l3lz0q se0GGqoD5IqUwRBtUTIz3GP8IC+N9FvXofQNJWxLWHjl1648uRMb1Sh2bmwDaoTSSeS6 unjGVUaY1COa4rOgu9dy9JXZ4vAn+ZCcTCr3x/kpFiG/pB1ffVPC1z1oZfB5duKA35f7 0hnw== X-Gm-Message-State: AOAM532RtDwb3WFLFs3uBjkz4XnytKWlR5IbOrj/cC0SYIxCKoJEI3zc CxrMxsFnYnLe4AI6p6bUUzft0Q== X-Google-Smtp-Source: ABdhPJzpmdtGHMHWvZSoxAeBd7m6F8/bajv++6UXNC2NrHGhtVAUsaZCzQFrWqJvgmEOCU86cP9/yg== X-Received: by 2002:ac2:4c4e:: with SMTP id o14mr20619200lfk.148.1637806260366; Wed, 24 Nov 2021 18:11:00 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id m3sm132507lji.112.2021.11.24.18.10.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 18:10:59 -0800 (PST) From: Linus Walleij To: Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, Linus Walleij , Peter Rosin , Chris Lesiak Subject: [PATCH 4/4] hwmon: (ntc_thermistor) Merge platform data Date: Thu, 25 Nov 2021 03:08:41 +0100 Message-Id: <20211125020841.3616359-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211125020841.3616359-1-linus.walleij@linaro.org> References: <20211125020841.3616359-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Allocate one state container for the device: struct ntc_data. Move all items from struct ntc_thermistor_platform_data into this struct and simplify. Cc: Peter Rosin Cc: Chris Lesiak Signed-off-by: Linus Walleij --- drivers/hwmon/ntc_thermistor.c | 109 +++++++++++++++------------------ 1 file changed, 48 insertions(+), 61 deletions(-) diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c index cedb3ee0f762..ed638ebd0923 100644 --- a/drivers/hwmon/ntc_thermistor.c +++ b/drivers/hwmon/ntc_thermistor.c @@ -26,25 +26,6 @@ enum ntc_thermistor_type { TYPE_NCPXXXH103, }; -struct ntc_thermistor_platform_data { - /* - * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required. - * - * How to setup pullup_ohm, pulldown_ohm, and connect is - * described at Documentation/hwmon/ntc_thermistor.rst - * - * pullup/down_ohm: 0 for infinite / not-connected - * - * chan: iio_channel pointer to communicate with the ADC which the - * thermistor is using for conversion of the analog values. - */ - unsigned int pullup_uv; - unsigned int pullup_ohm; - unsigned int pulldown_ohm; - enum { NTC_CONNECTED_POSITIVE, NTC_CONNECTED_GROUND } connect; - struct iio_channel *chan; -}; - struct ntc_compensation { int temp_c; unsigned int ohm; @@ -337,15 +318,30 @@ static const struct ntc_type ntc_type[] = { NTC_TYPE(TYPE_NCPXXXH103, ncpXXxh103), }; +/* + * pullup_uV, pullup_ohm, pulldown_ohm, and connect are required. + * + * How to setup pullup_ohm, pulldown_ohm, and connect is + * described at Documentation/hwmon/ntc_thermistor.rst + * + * pullup/down_ohm: 0 for infinite / not-connected + * + * chan: iio_channel pointer to communicate with the ADC which the + * thermistor is using for conversion of the analog values. + */ struct ntc_data { - struct ntc_thermistor_platform_data *pdata; const struct ntc_compensation *comp; int n_comp; + unsigned int pullup_uv; + unsigned int pullup_ohm; + unsigned int pulldown_ohm; + enum { NTC_CONNECTED_POSITIVE, NTC_CONNECTED_GROUND } connect; + struct iio_channel *chan; }; -static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata) +static int ntc_adc_iio_read(struct ntc_data *data) { - struct iio_channel *channel = pdata->chan; + struct iio_channel *channel = data->chan; int uv, ret; ret = iio_read_channel_processed_scale(channel, &uv, 1000); @@ -365,7 +361,7 @@ static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata) ret = iio_convert_raw_to_processed(channel, raw, &uv, 1000); if (ret < 0) { /* Assume 12 bit ADC with vref at pullup_uv */ - uv = (pdata->pullup_uv * (s64)raw) >> 12; + uv = (data->pullup_uv * (s64)raw) >> 12; } } @@ -407,20 +403,19 @@ static const struct of_device_id ntc_match[] = { }; MODULE_DEVICE_TABLE(of, ntc_match); -static struct ntc_thermistor_platform_data * -ntc_thermistor_parse_dt(struct device *dev) +static struct ntc_data *ntc_thermistor_parse_dt(struct device *dev) { + struct ntc_data *data; struct iio_channel *chan; enum iio_chan_type type; struct device_node *np = dev->of_node; - struct ntc_thermistor_platform_data *pdata; int ret; if (!np) return NULL; - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); - if (!pdata) + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) return ERR_PTR(-ENOMEM); chan = devm_iio_channel_get(dev, NULL); @@ -434,21 +429,21 @@ ntc_thermistor_parse_dt(struct device *dev) if (type != IIO_VOLTAGE) return ERR_PTR(-EINVAL); - if (of_property_read_u32(np, "pullup-uv", &pdata->pullup_uv)) + if (of_property_read_u32(np, "pullup-uv", &data->pullup_uv)) return ERR_PTR(-ENODEV); - if (of_property_read_u32(np, "pullup-ohm", &pdata->pullup_ohm)) + if (of_property_read_u32(np, "pullup-ohm", &data->pullup_ohm)) return ERR_PTR(-ENODEV); - if (of_property_read_u32(np, "pulldown-ohm", &pdata->pulldown_ohm)) + if (of_property_read_u32(np, "pulldown-ohm", &data->pulldown_ohm)) return ERR_PTR(-ENODEV); if (of_find_property(np, "connected-positive", NULL)) - pdata->connect = NTC_CONNECTED_POSITIVE; + data->connect = NTC_CONNECTED_POSITIVE; else /* status change should be possible if not always on. */ - pdata->connect = NTC_CONNECTED_GROUND; + data->connect = NTC_CONNECTED_GROUND; - pdata->chan = chan; + data->chan = chan; - return pdata; + return data; } static inline u64 div64_u64_safe(u64 dividend, u64 divisor) @@ -462,24 +457,23 @@ static inline u64 div64_u64_safe(u64 dividend, u64 divisor) static int get_ohm_of_thermistor(struct ntc_data *data, unsigned int uv) { - struct ntc_thermistor_platform_data *pdata = data->pdata; - u32 puv = pdata->pullup_uv; + u32 puv = data->pullup_uv; u64 n, puo, pdo; - puo = pdata->pullup_ohm; - pdo = pdata->pulldown_ohm; + puo = data->pullup_ohm; + pdo = data->pulldown_ohm; if (uv == 0) - return (pdata->connect == NTC_CONNECTED_POSITIVE) ? + return (data->connect == NTC_CONNECTED_POSITIVE) ? INT_MAX : 0; if (uv >= puv) - return (pdata->connect == NTC_CONNECTED_POSITIVE) ? + return (data->connect == NTC_CONNECTED_POSITIVE) ? 0 : INT_MAX; - if (pdata->connect == NTC_CONNECTED_POSITIVE && puo == 0) + if (data->connect == NTC_CONNECTED_POSITIVE && puo == 0) n = div_u64(pdo * (puv - uv), uv); - else if (pdata->connect == NTC_CONNECTED_GROUND && pdo == 0) + else if (data->connect == NTC_CONNECTED_GROUND && pdo == 0) n = div_u64(puo * uv, puv - uv); - else if (pdata->connect == NTC_CONNECTED_POSITIVE) + else if (data->connect == NTC_CONNECTED_POSITIVE) n = div64_u64_safe(pdo * puo * (puv - uv), puo * uv - pdo * (puv - uv)); else @@ -579,7 +573,7 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data) { int read_uv; - read_uv = ntc_adc_iio_read(data->pdata); + read_uv = ntc_adc_iio_read(data); if (read_uv < 0) return read_uv; return get_ohm_of_thermistor(data, read_uv); @@ -650,38 +644,31 @@ static int ntc_thermistor_probe(struct platform_device *pdev) const struct of_device_id *of_id = of_match_device(of_match_ptr(ntc_match), dev); const struct platform_device_id *pdev_id; - struct ntc_thermistor_platform_data *pdata; struct device *hwmon_dev; struct ntc_data *data; - pdata = ntc_thermistor_parse_dt(dev); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); + data = ntc_thermistor_parse_dt(dev); + if (IS_ERR(data)) + return PTR_ERR(data); - if (!pdata) { + if (!data) { dev_err(dev, "No platform init data supplied.\n"); return -ENODEV; } - if (pdata->pullup_uv == 0 || - (pdata->pullup_ohm == 0 && pdata->connect == + if (data->pullup_uv == 0 || + (data->pullup_ohm == 0 && data->connect == NTC_CONNECTED_GROUND) || - (pdata->pulldown_ohm == 0 && pdata->connect == + (data->pulldown_ohm == 0 && data->connect == NTC_CONNECTED_POSITIVE) || - (pdata->connect != NTC_CONNECTED_POSITIVE && - pdata->connect != NTC_CONNECTED_GROUND)) { + (data->connect != NTC_CONNECTED_POSITIVE && + data->connect != NTC_CONNECTED_GROUND)) { dev_err(dev, "Required data to use NTC driver not supplied.\n"); return -EINVAL; } - data = devm_kzalloc(dev, sizeof(struct ntc_data), GFP_KERNEL); - if (!data) - return -ENOMEM; - pdev_id = of_id ? of_id->data : platform_get_device_id(pdev); - data->pdata = pdata; - if (pdev_id->driver_data >= ARRAY_SIZE(ntc_type)) { dev_err(dev, "Unknown device type: %lu(%s)\n", pdev_id->driver_data, pdev_id->name);