From patchwork Thu Nov 18 14:12:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeny Boger X-Patchwork-Id: 12627153 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61B9BC433FE for ; Thu, 18 Nov 2021 14:13:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 464D161414 for ; Thu, 18 Nov 2021 14:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232818AbhKROP7 (ORCPT ); Thu, 18 Nov 2021 09:15:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232816AbhKROP7 (ORCPT ); Thu, 18 Nov 2021 09:15:59 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34BF6C061764 for ; Thu, 18 Nov 2021 06:12:59 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id bu18so26941682lfb.0 for ; Thu, 18 Nov 2021 06:12:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wirenboard-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WRNQumaXzRFV+KA+JrGKDmpxltYF5cw1xEc+Dklm/zA=; b=OTVPb5B+a0inUBE3P8fEHIkwgevsw7k456WjkzrTEhktEXMgn/ovj7H0BNOo4TcwUl tyo77L/myCc8M1anjl38Od40aawaLFupZi8BJOAfKzBPLdVyEvOqNna1lX3+X+wt8u7Z uQu37FkGnI8iJ1khzk5viMzjIm32IOF2EeOYjiNAhQsLBnclmZwRiAkWzTZ7OKIFczvX LaMG+nPr7td048vuucqfvUj8MLdcj+pHfWSXLSOe7/gNpq3W2yGBKjKP7kuUPYvZLqZf o0sLNgysNDyRpFD17JH6zoY8FPNZSrlJA65bwEtArVDGhvDm6UPgtV8CMCLKXgvVo7tT WEgA== 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=WRNQumaXzRFV+KA+JrGKDmpxltYF5cw1xEc+Dklm/zA=; b=nm8sq/uyVQj20oDiYokqPGaqyELMh0q/CGg8JRQZo6BqeqyQbmllu+2tu5qNvxP67W eYTzKHVPrKGCNa4CvWjs9lSi+XYdrDxI/HUe/hfR6snPYIDcxO5DGaDOtSMZnngSOmli qz9BsiF9Z1FSA2j7GZu4a6dOiq62V0ZIBBi9UvpKXDkbNBl/9GhEcV0yip/j6XWMvj1h GR6zUrIYeLSo+diWzznqugWFvtEPaK2ayPyffp0yRX1jBgNwS6G9/MHz5nt1aQGIFaSg LMCxwxh31yJG+w3+w3MMeW4YmNh2JCNOVjzQ0IfrIky3X+9UdMM5dtZ6uc7p0CGeHrDa 5JWw== X-Gm-Message-State: AOAM533iWzduQSxMRQFgi1ND3awFzP36RlkBDKHa1nGG3dewPYIJszVA yOSMP6hfEDdmqrAbP9B8y4a4ukQg3iQfSQ== X-Google-Smtp-Source: ABdhPJxdq4lafQyf4/Ku/Xy+BIjgRR2P9I0rT5djKWptkGLvvCjUECjWz2TafDe3+3Gh7dmy7vHFUg== X-Received: by 2002:a05:6512:685:: with SMTP id t5mr25204059lfe.84.1637244777234; Thu, 18 Nov 2021 06:12:57 -0800 (PST) Received: from boger-laptop.lan (81.5.99.121.dhcp.mipt-telecom.ru. [81.5.99.121]) by smtp.gmail.com with ESMTPSA id s15sm193634lfp.252.2021.11.18.06.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 06:12:56 -0800 (PST) From: Evgeny Boger To: linux-iio@vger.kernel.org Cc: Evgeny Boger , devicetree@vger.kernel.org, Jonathan Cameron , Lars-Peter Clausen , Chen-Yu Tsai , Jernej Skrabec , Maxime Ripard , Quentin Schulz , linux-sunxi@lists.linux.dev Subject: [PATCH 1/2] iio:adc:axp20x: add support for NTC thermistor Date: Thu, 18 Nov 2021 17:12:32 +0300 Message-Id: <20211118141233.247907-2-boger@wirenboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118141233.247907-1-boger@wirenboard.com> References: <20211118141233.247907-1-boger@wirenboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Most AXPxxx-based reference designs place a 10k NTC thermistor on a TS pin. When appropriately configured, AXP PMICs will inject fixed current (80uA by default) into TS pin and measure the voltage across a thermistor. The PMIC itself will by default compare this voltage with predefined thresholds and disable battery charging whenever the battery is too hot or too cold. Alternatively, the TS pin can be configured as general-purpose ADC input. This mode is not supported by the driver. This patch allows reading the voltage on the TS pin. It can be then either processed by userspace or used by kernel consumer like hwmon ntc thermistor driver. Signed-off-by: Evgeny Boger Acked-by: Maxime Ripard Reviewed-by: Quentin Schulz Reviewed-by: Quentin Schulz --- drivers/iio/adc/axp20x_adc.c | 45 +++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c index 3e0c0233b431..12d469a52cea 100644 --- a/drivers/iio/adc/axp20x_adc.c +++ b/drivers/iio/adc/axp20x_adc.c @@ -186,6 +186,8 @@ static const struct iio_chan_spec axp20x_adc_channels[] = { AXP20X_BATT_CHRG_I_H), AXP20X_ADC_CHANNEL(AXP20X_BATT_DISCHRG_I, "batt_dischrg_i", IIO_CURRENT, AXP20X_BATT_DISCHRG_I_H), + AXP20X_ADC_CHANNEL(AXP20X_TS_IN, "ts_v", IIO_VOLTAGE, + AXP20X_TS_IN_H), }; static const struct iio_chan_spec axp22x_adc_channels[] = { @@ -203,6 +205,8 @@ static const struct iio_chan_spec axp22x_adc_channels[] = { AXP20X_BATT_CHRG_I_H), AXP20X_ADC_CHANNEL(AXP22X_BATT_DISCHRG_I, "batt_dischrg_i", IIO_CURRENT, AXP20X_BATT_DISCHRG_I_H), + AXP20X_ADC_CHANNEL(AXP22X_TS_IN, "ts_v", IIO_VOLTAGE, + AXP22X_TS_ADC_H), }; static const struct iio_chan_spec axp813_adc_channels[] = { @@ -222,6 +226,8 @@ static const struct iio_chan_spec axp813_adc_channels[] = { AXP20X_BATT_CHRG_I_H), AXP20X_ADC_CHANNEL(AXP22X_BATT_DISCHRG_I, "batt_dischrg_i", IIO_CURRENT, AXP20X_BATT_DISCHRG_I_H), + AXP20X_ADC_CHANNEL(AXP813_TS_IN, "ts_v", IIO_VOLTAGE, + AXP288_TS_ADC_H), }; static int axp20x_adc_raw(struct iio_dev *indio_dev, @@ -307,11 +313,36 @@ static int axp20x_adc_scale_voltage(int channel, int *val, int *val2) *val2 = 400000; return IIO_VAL_INT_PLUS_MICRO; + case AXP20X_TS_IN: + /* 0.8 mV per LSB */ + *val = 0; + *val2 = 800000; + return IIO_VAL_INT_PLUS_MICRO; + default: return -EINVAL; } } +static int axp22x_adc_scale_voltage(int channel, int *val, int *val2) +{ + switch (channel) { + case AXP22X_BATT_V: + /* 1.1 mV per LSB */ + *val = 1; + *val2 = 100000; + return IIO_VAL_INT_PLUS_MICRO; + + case AXP22X_TS_IN: + /* 0.8 mV per LSB */ + *val = 0; + *val2 = 800000; + return IIO_VAL_INT_PLUS_MICRO; + + default: + return -EINVAL; + } +} static int axp813_adc_scale_voltage(int channel, int *val, int *val2) { switch (channel) { @@ -325,6 +356,12 @@ static int axp813_adc_scale_voltage(int channel, int *val, int *val2) *val2 = 100000; return IIO_VAL_INT_PLUS_MICRO; + case AXP813_TS_IN: + /* 0.8 mV per LSB */ + *val = 0; + *val2 = 800000; + return IIO_VAL_INT_PLUS_MICRO; + default: return -EINVAL; } @@ -378,12 +415,7 @@ static int axp22x_adc_scale(struct iio_chan_spec const *chan, int *val, { switch (chan->type) { case IIO_VOLTAGE: - if (chan->channel != AXP22X_BATT_V) - return -EINVAL; - - *val = 1; - *val2 = 100000; - return IIO_VAL_INT_PLUS_MICRO; + return axp22x_adc_scale_voltage(chan->channel, val, val2); case IIO_CURRENT: *val = 0; @@ -488,6 +520,7 @@ static int axp22x_read_raw(struct iio_dev *indio_dev, { switch (mask) { case IIO_CHAN_INFO_OFFSET: + /* For PMIC temp only */ *val = -2677; return IIO_VAL_INT; From patchwork Thu Nov 18 14:12:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeny Boger X-Patchwork-Id: 12627155 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EEF7C4332F for ; Thu, 18 Nov 2021 14:13:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0912261107 for ; Thu, 18 Nov 2021 14:13:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232820AbhKROQB (ORCPT ); Thu, 18 Nov 2021 09:16:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232816AbhKROQB (ORCPT ); Thu, 18 Nov 2021 09:16:01 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2926C061764 for ; Thu, 18 Nov 2021 06:13:00 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id y26so26615577lfa.11 for ; Thu, 18 Nov 2021 06:13:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wirenboard-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/ZLSBMSvQ7dJDOk6e1Mx89OYCP5iH5hZWG5YrIJUvVs=; b=Q0jp+Xq/7805elOfY/7qi9pN8dkRYSzSNlvQekc4sAQLG6S32Fai3oQMAbRYi/S+Ze Q4irm3DLIfCxh69p1knnhKOxMl6UHPUACEsXD73Lz9/HsU+/bRLd2s0K98x7q/LYbfH/ hX4gmXI1ObqPwFrQ8Eb7EMubNqMg8ugfEEv2yvFOh6TvKbVzrakFwxDgA4IsEFBx6I79 HhBy4slxLJJNH8RFXThN5cJknqEfbGGQYO2m8/JyJTl7Imz3Ib7LpYV9zZR7ISsTMd5q lRTk9+CE+uLnFflVHwcT3r44epUk+fugM25p/fmySOTLScUYwvhijzR50jL1Q1Fh93Se xYMg== 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=/ZLSBMSvQ7dJDOk6e1Mx89OYCP5iH5hZWG5YrIJUvVs=; b=3wsB9dX7+gfNE2wlEPGRs0PXN8yAEqffHsw8VG2S062GIITOh2EbgaJ9gp6xyHg0VP 3Hih2XeHLBKRlXhUSkK5Gb9VnEK7yuEAVXTaYR9pUZCJrZC447uJcPjEreDYAhXD8YQw 04IbSAbJ87CmDBIGB1UfdZZ03ajrHcdTFsemsyrC7/EGTLjkVqKrVhXrZyLMv6znrOEH aULnZToJcQXILPOJF/lKPiSWST9sm4Bb6+lqesC9eJxLN9KWxZo/gRJuRdYriryeHodY 9hrqsLZ2BOKtVwnntfTzIk4FcDmcwXEtktrHa+S2MsvsuNvjQfbS1Gk6FqRqv7U7v2l6 cngQ== X-Gm-Message-State: AOAM533307rRDekeippUCd69xYQctqIXeWA/quTHS72yj0MjcWtNlI5A q/DlCykBbPFHwBOWOy9IOmYXb0lihK6+CA== X-Google-Smtp-Source: ABdhPJz9vlEmw1/O2Nr3qDyeD0f0a4jF0ReUmezuDcpfWjpAwwTkluE4z+LBsrs2jyZizP5IC6lO+g== X-Received: by 2002:a05:6512:3403:: with SMTP id i3mr25675413lfr.413.1637244778901; Thu, 18 Nov 2021 06:12:58 -0800 (PST) Received: from boger-laptop.lan (81.5.99.121.dhcp.mipt-telecom.ru. [81.5.99.121]) by smtp.gmail.com with ESMTPSA id s15sm193634lfp.252.2021.11.18.06.12.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 06:12:58 -0800 (PST) From: Evgeny Boger To: linux-iio@vger.kernel.org Cc: Evgeny Boger , devicetree@vger.kernel.org, Jonathan Cameron , Lars-Peter Clausen , Chen-Yu Tsai , Jernej Skrabec , Maxime Ripard , Quentin Schulz , linux-sunxi@lists.linux.dev Subject: [PATCH 2/2] dt-bindings: iio: adc: document TS voltage in AXP PMICs Date: Thu, 18 Nov 2021 17:12:33 +0300 Message-Id: <20211118141233.247907-3-boger@wirenboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118141233.247907-1-boger@wirenboard.com> References: <20211118141233.247907-1-boger@wirenboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Most AXPxxx-based reference designs place a 10k NTC thermistor on a TS pin. axp20x IIO driver now report the voltage of this pin via additional IIO channel. Add new "ts_v" channel to the channel description. Signed-off-by: Evgeny Boger Acked-by: Rob Herring Reviewed-by: Quentin Schulz Reviewed-by: Quentin Schulz --- .../devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml b/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml index e759a5da708d..d6d3d8590171 100644 --- a/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml +++ b/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml @@ -27,6 +27,7 @@ description: | 8 | batt_v 9 | batt_chrg_i 10 | batt_dischrg_i + 11 | ts_v AXP22x ------ @@ -34,6 +35,7 @@ description: | 1 | batt_v 2 | batt_chrg_i 3 | batt_dischrg_i + 4 | ts_v AXP813 ------ @@ -42,6 +44,7 @@ description: | 2 | batt_v 3 | batt_chrg_i 4 | batt_dischrg_i + 5 | ts_v properties: