From patchwork Thu Aug 13 21:34:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11713047 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D67B174A for ; Thu, 13 Aug 2020 21:35:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FB1920885 for ; Thu, 13 Aug 2020 21:35:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cEJlGGye" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726667AbgHMVed (ORCPT ); Thu, 13 Aug 2020 17:34:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726467AbgHMVec (ORCPT ); Thu, 13 Aug 2020 17:34:32 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 823FBC061757; Thu, 13 Aug 2020 14:34:32 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id v12so7788039ljc.10; Thu, 13 Aug 2020 14:34:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fZLsHIDpnTF+VfT0D85OABvcYZ+3mXctvnf5hSJQWzI=; b=cEJlGGyeVOnUqLHStkUx6OeQErNRTVSS220RFZE6V8zt+iutywGEiDiWgxjOwmvT0W QzHpMjc5mPTLcGxJ2ANM0rQHnB/BWFzwv1dv5PTx2/OnLnAxHKQKpUq7vf6gU+UePgRo R82mDt9eh/+PIbdPd8SNW8gE30QIDV0U9eMs+0vTiVZe/GDv2bhzqv0Mbc2zRz8MTFex MdhehJ/5k/Y7HLiQDC3mWACmwSEpjXc0c7bGjpHZutU43yvHm67c59185gu1yjgiz9xw kJY5hODB9QVq4gjuzkNUx3c42T/R4KiR6M8NGQ6mWlZAE6m2Y3wG0ikeH3uG/MvqVVY/ yBvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fZLsHIDpnTF+VfT0D85OABvcYZ+3mXctvnf5hSJQWzI=; b=VbJQPDGoOS37oBuzW9j00IOVhgcpTIeqVrTP8T4iUBnLSPF2d3rv7arX8b1bcrbHBn 3HbMf3s7Hgn2wf7z4sOod1SfJm7rIpuqPJLNhTZZqjycMDS9BtAUpBkF3Mf1fjiICY8l YcXbYYskvmW7W7rjBoxLvaqBCiBgXYoXlPreErhy/wrjIez15u+iGLcyNadmzwinZRFP 0s/nHBzXdq1fAhSCmxcWp4cY4mAiMqbpvKbT0zEhdPfKEVC6hMzoMx9f1fDvOPD/eRta rjZLLe2CFH12/hOMlT3zetOtHAFQ53Vu53nuE+1LW7gjtGtreIo0c3c246+9msDa6j25 jHhg== X-Gm-Message-State: AOAM530tsAF3FkZLlRa+uuUxlFRO2IpAlghpEo6HwirHzGtelArV2I1X KNsWXdl94atb93Nv/LNCQLc= X-Google-Smtp-Source: ABdhPJxvfXQdfIk92pJtg8kgylRAvmzl0C/vMZ0PbV7h+vJYE5TyhNAGmBca3vdh/RJ0c0/LYmIYyg== X-Received: by 2002:a2e:b8cf:: with SMTP id s15mr3072321ljp.166.1597354470954; Thu, 13 Aug 2020 14:34:30 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j2sm1345309ljb.98.2020.08.13.14.34.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 14:34:30 -0700 (PDT) From: Dmitry Osipenko To: Sebastian Reichel , Rob Herring , Andy Gross , Bjorn Andersson , David Heidelberg , Thierry Reding , Jonathan Hunter , Mika Westerberg , "Bruce E . Robertson" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Jonghwa Lee , John Stultz , Vinay Simha BN , linux-tegra@vger.kernel.org Subject: [PATCH v3 01/10] dt-bindings: battery: Add temperature properties Date: Fri, 14 Aug 2020 00:34:00 +0300 Message-Id: <20200813213409.24222-2-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200813213409.24222-1-digetx@gmail.com> References: <20200813213409.24222-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Document generic battery temperature properties. Signed-off-by: Dmitry Osipenko Reviewed-by: Rob Herring --- .../bindings/power/supply/battery.yaml | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Documentation/devicetree/bindings/power/supply/battery.yaml b/Documentation/devicetree/bindings/power/supply/battery.yaml index 932b736ce5c0..0c7e2e44793b 100644 --- a/Documentation/devicetree/bindings/power/supply/battery.yaml +++ b/Documentation/devicetree/bindings/power/supply/battery.yaml @@ -82,6 +82,27 @@ properties: An array containing the temperature in degree Celsius, for each of the battery capacity lookup table. + operating-range-celsius: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: operating temperature range of a battery + items: + - description: minimum temperature at which battery can operate + - description: maximum temperature at which battery can operate + + ambient-celsius: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: safe range of ambient temperature + items: + - description: alert when ambient temperature is lower than this value + - description: alert when ambient temperature is higher than this value + + alert-celsius: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: safe range of battery temperature + items: + - description: alert when battery temperature is lower than this value + - description: alert when battery temperature is higher than this value + required: - compatible @@ -130,6 +151,9 @@ examples: /* table for 10 degree Celsius */ ocv-capacity-table-2 = <4250000 100>, <4200000 95>, <4185000 90>; resistance-temp-table = <20 100>, <10 90>, <0 80>, <(-10) 60>; + operating-range-celsius = <(-30) 50>; + ambient-celsius = <(-5) 50>; + alert-celsius = <0 40>; }; charger@11 { From patchwork Thu Aug 13 21:34:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11713043 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AEBCA16B1 for ; Thu, 13 Aug 2020 21:35:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D23022BED for ; Thu, 13 Aug 2020 21:35:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dJkbke/B" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726694AbgHMVef (ORCPT ); Thu, 13 Aug 2020 17:34:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726686AbgHMVee (ORCPT ); Thu, 13 Aug 2020 17:34:34 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C18BBC061757; Thu, 13 Aug 2020 14:34:33 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id t23so7823763ljc.3; Thu, 13 Aug 2020 14:34:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yO29YDGuBtqi3W2Ytkv38r6JCCBE5Jw2QeGc0NUGWBo=; b=dJkbke/BSwBTQzlUTUwCrheZnN7Xv3dnQiWBS51aIOCl3Soj/2AHLspVne01kGXzJE 9VbMB/cLvBzzLGHCl0tnsDKXZQynO40Opwt/FvyiCG9zljermb/uicaz0zomjETYj6ux zmksCqwu76qufPxBsONr+TJEQTidITKPdFSmxsSYFKl+yCDyr0v90k4vhsrEWChiuWD7 Hpk9c0DJCgFiYif0nFRBEFafVz/yyyzpWlOMEoDVwsnLX69h71STvmoY71K98Leu88f6 WUN0intA0K7PRZ+WwR3cu7SqpkS385XgBavm38/VPVme0AkDa99HZLIGMgpEBnTqUARI tGUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yO29YDGuBtqi3W2Ytkv38r6JCCBE5Jw2QeGc0NUGWBo=; b=bVhNDCp7L2P/MBrzXTO5eK96qQX2RVQzxTe7mBhpjBokJpHMmDUSjjB/wMLx3eNfj/ 3PfO/sgNIoo+gS16FQKofL3jIj9bvEHWQWN/THBMhEC2YNbF+pforK+h4qVE69W+iTmX F+UUkURu/3CfHlfaK+gtuZXxHe/ebznuoMrdeXQQNfcaLMYbo8DkIZErPs5ZDPISHnrs xXMLa3ub6lSvGq/I5sxashQ4myqaorcJvPyIBIrn6oXtsjUO+BEQpYsDLPxb/a6rpod1 McbPFn5eRZN997dNlMAWwEJwgVi2lxgojvMUXzeJ7BI5ufQZboKV9MmsZJKTN+iJ34R4 ay3w== X-Gm-Message-State: AOAM53298Wxlf5+Tgc+/6QuqeiVwS1WKfAxkuPIJFfL9xA5ZvbaaLiey htJtl8zIhg8Ah1huUcnq108= X-Google-Smtp-Source: ABdhPJz1UIQ1B2CMDWWp9Ca5EXYgvhI3lrx+GPEzaTSWoAQ1DIijg1h10CYehPTKYGDxU6lO5YSslQ== X-Received: by 2002:a2e:503:: with SMTP id 3mr3110264ljf.225.1597354472112; Thu, 13 Aug 2020 14:34:32 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j2sm1345309ljb.98.2020.08.13.14.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 14:34:31 -0700 (PDT) From: Dmitry Osipenko To: Sebastian Reichel , Rob Herring , Andy Gross , Bjorn Andersson , David Heidelberg , Thierry Reding , Jonathan Hunter , Mika Westerberg , "Bruce E . Robertson" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Jonghwa Lee , John Stultz , Vinay Simha BN , linux-tegra@vger.kernel.org Subject: [PATCH v3 02/10] dt-bindings: power: supply: Add device-tree binding for Summit SMB3xx Date: Fri, 14 Aug 2020 00:34:01 +0300 Message-Id: <20200813213409.24222-3-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200813213409.24222-1-digetx@gmail.com> References: <20200813213409.24222-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: David Heidelberg Summit SMB3xx series is a Programmable Switching Li+ Battery Charger. This patch adds device-tree binding for Summit SMB345, SMB347 and SMB358 chargers. Signed-off-by: David Heidelberg Signed-off-by: Dmitry Osipenko Reviewed-by: Rob Herring --- .../power/supply/summit,smb347-charger.yaml | 152 ++++++++++++++++++ .../dt-bindings/power/summit,smb347-charger.h | 19 +++ 2 files changed, 171 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/summit,smb347-charger.yaml create mode 100644 include/dt-bindings/power/summit,smb347-charger.h diff --git a/Documentation/devicetree/bindings/power/supply/summit,smb347-charger.yaml b/Documentation/devicetree/bindings/power/supply/summit,smb347-charger.yaml new file mode 100644 index 000000000000..193a23af2007 --- /dev/null +++ b/Documentation/devicetree/bindings/power/supply/summit,smb347-charger.yaml @@ -0,0 +1,152 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/power/supply/summit,smb347-charger.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Battery charger driver for SMB345, SMB347 and SMB358 + +maintainers: + - David Heidelberg + - Dmitry Osipenko + +properties: + compatible: + enum: + - summit,smb345 + - summit,smb347 + - summit,smb358 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + monitored-battery: + description: phandle to the battery node + $ref: /schemas/types.yaml#/definitions/phandle + + summit,enable-usb-charging: + type: boolean + description: Enable charging through USB. + + summit,enable-otg-charging: + type: boolean + description: Provide power for USB OTG + + summit,enable-mains-charging: + type: boolean + description: Enable charging through mains + + summit,enable-charge-control: + description: Enable charging control + $ref: /schemas/types.yaml#/definitions/uint32 + enum: + - 0 # SMB3XX_CHG_ENABLE_SW SW (I2C interface) + - 1 # SMB3XX_CHG_ENABLE_PIN_ACTIVE_LOW Pin control (Active Low) + - 2 # SMB3XX_CHG_ENABLE_PIN_ACTIVE_HIGH Pin control (Active High) + + summit,fast-voltage-threshold-microvolt: + description: Voltage threshold to transit to fast charge mode (in uV) + minimum: 2400000 + maximum: 3000000 + + summit,mains-current-limit-microamp: + description: Maximum input current from AC/DC input (in uA) + + summit,usb-current-limit-microamp: + description: Maximum input current from USB input (in uA) + + summit,charge-current-compensation-microamp: + description: Charge current compensation (in uA) + + summit,chip-temperature-threshold-celsius: + description: Chip temperature for thermal regulation in °C. + enum: [100, 110, 120, 130] + + summit,soft-compensation-method: + description: Soft temperature limit compensation method + $ref: /schemas/types.yaml#/definitions/uint32 + enum: + - 0 # SMB3XX_SOFT_TEMP_COMPENSATE_NONE Compensation none + - 1 # SMB3XX_SOFT_TEMP_COMPENSATE_CURRENT Current compensation + - 2 # SMB3XX_SOFT_TEMP_COMPENSATE_VOLTAGE Voltage compensation + +allOf: + - if: + properties: + compatible: + enum: + - summit,smb345 + - summit,smb358 + + then: + properties: + summit,mains-current-limit-microamp: + enum: [ 300000, 500000, 700000, 1000000, + 1500000, 1800000, 2000000] + + summit,usb-current-limit-microamp: + enum: [ 300000, 500000, 700000, 1000000, + 1500000, 1800000, 2000000] + + summit,charge-current-compensation-microamp: + enum: [200000, 450000, 600000, 900000] + + else: + properties: + summit,mains-current-limit-microamp: + enum: [ 300000, 500000, 700000, 900000, 1200000, + 1500000, 1800000, 2000000, 2200000, 2500000] + + summit,usb-current-limit-microamp: + enum: [ 300000, 500000, 700000, 900000, 1200000, + 1500000, 1800000, 2000000, 2200000, 2500000] + + summit,charge-current-compensation-microamp: + enum: [250000, 700000, 900000, 1200000] + +required: + - compatible + - reg + +anyOf: + - required: + - summit,enable-usb-charging + - required: + - summit,enable-otg-charging + - required: + - summit,enable-mains-charging + +additionalProperties: false + +examples: + - | + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + charger@7f { + compatible = "summit,smb347"; + reg = <0x7f>; + + summit,enable-charge-control = ; + summit,chip-temperature-threshold-celsius = <110>; + summit,mains-current-limit-microamp = <2000000>; + summit,usb-current-limit-microamp = <500000>; + summit,enable-usb-charging; + summit,enable-mains-charging; + + monitored-battery = <&battery>; + }; + }; + + battery: battery-cell { + compatible = "simple-battery"; + constant-charge-current-max-microamp = <1800000>; + operating-range-celsius = <0 45>; + alert-celsius = <3 42>; + }; diff --git a/include/dt-bindings/power/summit,smb347-charger.h b/include/dt-bindings/power/summit,smb347-charger.h new file mode 100644 index 000000000000..d918bf321a71 --- /dev/null +++ b/include/dt-bindings/power/summit,smb347-charger.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: (GPL-2.0-or-later or MIT) */ +/* + * Author: David Heidelberg + */ + +#ifndef _DT_BINDINGS_SMB347_CHARGER_H +#define _DT_BINDINGS_SMB347_CHARGER_H + +/* Charging compensation method */ +#define SMB3XX_SOFT_TEMP_COMPENSATE_NONE 0 +#define SMB3XX_SOFT_TEMP_COMPENSATE_CURRENT 1 +#define SMB3XX_SOFT_TEMP_COMPENSATE_VOLTAGE 2 + +/* Charging enable control */ +#define SMB3XX_CHG_ENABLE_SW 0 +#define SMB3XX_CHG_ENABLE_PIN_ACTIVE_LOW 1 +#define SMB3XX_CHG_ENABLE_PIN_ACTIVE_HIGH 2 + +#endif From patchwork Thu Aug 13 21:34:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11713041 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83655174A for ; Thu, 13 Aug 2020 21:35:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AACE206A4 for ; Thu, 13 Aug 2020 21:35:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ddXLjfWd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726773AbgHMVfP (ORCPT ); Thu, 13 Aug 2020 17:35:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726698AbgHMVef (ORCPT ); Thu, 13 Aug 2020 17:34:35 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58F22C061757; Thu, 13 Aug 2020 14:34:35 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id w25so7768217ljo.12; Thu, 13 Aug 2020 14:34:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O0yugzvKqUofOFg3gQRSvSu6LWWdYaLpdIpz8+ZfmFw=; b=ddXLjfWdJqtVi9h0B0q10kZwaUeFC21Cmph08cYVhcYpcRipvwLkeLriefbwYCcpfX rTbmC4KnsQCFYU1rdDlTWecPjwDSsDLO0G9zds2gZZnxBSQJhpBB8eZyzGKKcrfUsMP5 Wgjm8jGtpOif/83zPKkw4ljD/qMIMU83AwkYSQHDVKGr3Bq4R65FeRZtz6yKlyBPyrlM UqtZt738ZsXQNjSx4hnPkugPw2chvbDcI55NsFClym66wv7t5DhKasIYMvBFadijib66 0/TKzIYHWVHIZ0T6/IJWuQIIFqb/5/pdyLklEFcHBXmO4h1/5+WakWOaLYVwEnp62K2/ ctrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O0yugzvKqUofOFg3gQRSvSu6LWWdYaLpdIpz8+ZfmFw=; b=AaFxAwx3nuyXBGW7x+TZQ6dRu87S/cERD+71sfmvaJ+vkysbU65q1B6eMXPXAD/DRf HANBl7yKd0Lzzd2npDcr3rDHG/69zCWrACU1puwG0ewKUajyzp1z4okPhh9x9ZGaTKZA 5eLsIKEw8PNOwhg6Lw4p6J0I9T6gPbKE4nHEIMZ1X+aUs1SfFwvjqwtx3BEyA1REfZIk TogQPEeQXxYuIHmGWY6fBM4Vyn1PjQuJGEdMbOwritLLrIMhqmAW+LQn1x6T4ZcJ/SwS Z7dc43Exw2Sx92bb6zV30GrQSEZSfDssR1GXC49baCZrl2h/C7/53E6wXMRxqmhQ9cyh mPng== X-Gm-Message-State: AOAM532m+TRPHsz4q51w3Wx4zukBgqae9llOy2ZqlGrictq6FSyxliyZ Hc7rwyMCybe0uj/uFctADXU= X-Google-Smtp-Source: ABdhPJznWI2df852Z9LPq9Z2Nw9rDffTl31+GknxyxBxb5ZTU/I2CWkvoOOdoGCj8Zd191VQqU6etw== X-Received: by 2002:a2e:9449:: with SMTP id o9mr3142556ljh.403.1597354473868; Thu, 13 Aug 2020 14:34:33 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j2sm1345309ljb.98.2020.08.13.14.34.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 14:34:33 -0700 (PDT) From: Dmitry Osipenko To: Sebastian Reichel , Rob Herring , Andy Gross , Bjorn Andersson , David Heidelberg , Thierry Reding , Jonathan Hunter , Mika Westerberg , "Bruce E . Robertson" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Jonghwa Lee , John Stultz , Vinay Simha BN , linux-tegra@vger.kernel.org Subject: [PATCH v3 03/10] power: supply: Support battery temperature device-tree properties Date: Fri, 14 Aug 2020 00:34:02 +0300 Message-Id: <20200813213409.24222-4-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200813213409.24222-1-digetx@gmail.com> References: <20200813213409.24222-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The generic battery temperature properties are already supported by the power-supply core. Let's support parsing of the common battery temperature properties from a device-tree. Signed-off-by: Dmitry Osipenko --- drivers/power/supply/power_supply_core.c | 19 +++++++++++++++++++ include/linux/power_supply.h | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index ccbad435ed12..38e3aa642131 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -579,6 +579,12 @@ int power_supply_get_battery_info(struct power_supply *psy, info->charge_term_current_ua = -EINVAL; info->constant_charge_current_max_ua = -EINVAL; info->constant_charge_voltage_max_uv = -EINVAL; + info->temp_ambient_alert_min = INT_MIN; + info->temp_ambient_alert_max = INT_MAX; + info->temp_alert_min = INT_MIN; + info->temp_alert_max = INT_MAX; + info->temp_min = INT_MIN; + info->temp_max = INT_MAX; info->factory_internal_resistance_uohm = -EINVAL; info->resist_table = NULL; @@ -639,6 +645,19 @@ int power_supply_get_battery_info(struct power_supply *psy, of_property_read_u32(battery_np, "factory-internal-resistance-micro-ohms", &info->factory_internal_resistance_uohm); + of_property_read_u32_index(battery_np, "ambient-celsius", + 0, &info->temp_ambient_alert_min); + of_property_read_u32_index(battery_np, "ambient-celsius", + 1, &info->temp_ambient_alert_max); + of_property_read_u32_index(battery_np, "alert-celsius", + 0, &info->temp_alert_min); + of_property_read_u32_index(battery_np, "alert-celsius", + 1, &info->temp_alert_max); + of_property_read_u32_index(battery_np, "operating-range-celsius", + 0, &info->temp_min); + of_property_read_u32_index(battery_np, "operating-range-celsius", + 1, &info->temp_max); + len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius"); if (len < 0 && len != -EINVAL) { err = len; diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 97cc4b85bf61..d0684362a392 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -365,6 +365,12 @@ struct power_supply_battery_info { int constant_charge_voltage_max_uv; /* microVolts */ int factory_internal_resistance_uohm; /* microOhms */ int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX];/* celsius */ + int temp_ambient_alert_min; /* celsius */ + int temp_ambient_alert_max; /* celsius */ + int temp_alert_min; /* celsius */ + int temp_alert_max; /* celsius */ + int temp_min; /* celsius */ + int temp_max; /* celsius */ struct power_supply_battery_ocv_table *ocv_table[POWER_SUPPLY_OCV_TEMP_MAX]; int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX]; struct power_supply_resistance_temp_table *resist_table; From patchwork Thu Aug 13 21:34:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11713011 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B30CA16B1 for ; Thu, 13 Aug 2020 21:34:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9848A20855 for ; Thu, 13 Aug 2020 21:34:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nCI/rqUm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726724AbgHMVej (ORCPT ); Thu, 13 Aug 2020 17:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726718AbgHMVeh (ORCPT ); Thu, 13 Aug 2020 17:34:37 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCC0BC061757; Thu, 13 Aug 2020 14:34:36 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id w25so7768281ljo.12; Thu, 13 Aug 2020 14:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B7Fi9L3i7XzTcr6thO/0SWvSgth3FROAtfqsWSnrJqc=; b=nCI/rqUmNTDu+Fl5/y2BjihRHRHuAoXjTGy+pnXb6sz62NXrVptvuywTJDpUgbqXFt LvdgGGyVFRm9Rr2WnhhTRs6RTDEURphbUXMtsfRQNvDmyYQ9Ev3ju0zBiqUUTK5xmHKS 24Td3vj5fjq+f0e8Op/0duH6usiBkBIkeaq9dMn6qeDPiloryVxUWWSz6JcX9dtyakKQ DP2GLHxrqBPeG5cYRRKGdLkGy+PlKzu0R/uSVZjO2wWxS+6pzCi7BpdDLZjJbyPRufaD GDjtaPytY2T9/fs7C7eLGLCFgEd1W11xEdHY9HbN9Y8LD+4OxkPmb0XnjbPWlU5dulZZ RWBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B7Fi9L3i7XzTcr6thO/0SWvSgth3FROAtfqsWSnrJqc=; b=X/NQ1MvllR807XBpLNOypJr72ck+9fyPfKnGR0O9+tl0r9u1bf18+6uwmfzSeBrVya 0YGzakA6yli1aSkn9uzQzVVsFUsHU8id4t58R26wHcX1vn57SnFRMdh6w0GWYNIvA+pg Wot4uXhjgHGKZd3ytbcqx/V7tzbn5MfrSZDb+vQkjFTzQ9ZHvuSTdZJTvn8h0gflEXbp ycgi5tLF60oL6EG67jJlO2BwOgpMI/RQJvH0c2HQLtHWxAW3gZMx0hBEQQieOwrS16i0 t3+SOUnV5aKDk6YVpvH//h2ZEz5MKpjY39Z6qvhAdahibIMhPD0Ojs6Zhim4SWiqrznr mnxQ== X-Gm-Message-State: AOAM532PLi9p6S7YcnnERXYnJBhNeXcWjAgq2iHpAmUvPuTAK2ssdZWx Enpof9/oPiUJ8d8Sk89vX8E= X-Google-Smtp-Source: ABdhPJwxbqgXVaBZrFY3PpKIRWKclZtqP6XwEoUawr6zgszysfLBYmbVMjc+91HdVTfS+xzKVXd4lg== X-Received: by 2002:a05:651c:505:: with SMTP id o5mr2949310ljp.306.1597354475176; Thu, 13 Aug 2020 14:34:35 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j2sm1345309ljb.98.2020.08.13.14.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 14:34:34 -0700 (PDT) From: Dmitry Osipenko To: Sebastian Reichel , Rob Herring , Andy Gross , Bjorn Andersson , David Heidelberg , Thierry Reding , Jonathan Hunter , Mika Westerberg , "Bruce E . Robertson" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Jonghwa Lee , John Stultz , Vinay Simha BN , linux-tegra@vger.kernel.org Subject: [PATCH v3 04/10] power: supply: smb347-charger: Use resource-managed API Date: Fri, 14 Aug 2020 00:34:03 +0300 Message-Id: <20200813213409.24222-5-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200813213409.24222-1-digetx@gmail.com> References: <20200813213409.24222-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: David Heidelberg Simplify code, more convenient to use with Device Tree. Reviewed-by: Dmitry Osipenko Signed-off-by: David Heidelberg --- drivers/power/supply/smb347-charger.c | 75 +++++++++++---------------- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/drivers/power/supply/smb347-charger.c b/drivers/power/supply/smb347-charger.c index f99026d81f2a..60894105fcbd 100644 --- a/drivers/power/supply/smb347-charger.c +++ b/drivers/power/supply/smb347-charger.c @@ -836,21 +836,31 @@ static int smb347_irq_init(struct smb347_charger *smb, struct i2c_client *client) { const struct smb347_charger_platform_data *pdata = smb->pdata; - int ret, irq = gpio_to_irq(pdata->irq_gpio); + unsigned long irqflags = IRQF_ONESHOT; + int ret; - ret = gpio_request_one(pdata->irq_gpio, GPIOF_IN, client->name); - if (ret < 0) - goto fail; + /* Requesting GPIO for IRQ is only needed in non-DT way */ + if (!client->irq) { + int irq = gpio_to_irq(pdata->irq_gpio); + + ret = devm_gpio_request_one(smb->dev, pdata->irq_gpio, + GPIOF_IN, client->name); + if (ret < 0) + return ret; + + irqflags |= IRQF_TRIGGER_FALLING; + client->irq = irq; + } - ret = request_threaded_irq(irq, NULL, smb347_interrupt, - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, - client->name, smb); + ret = devm_request_threaded_irq(smb->dev, client->irq, NULL, + smb347_interrupt, irqflags, + client->name, smb); if (ret < 0) - goto fail_gpio; + return ret; ret = smb347_set_writable(smb, true); if (ret < 0) - goto fail_irq; + return ret; /* * Configure the STAT output to be suitable for interrupts: disable @@ -860,20 +870,10 @@ static int smb347_irq_init(struct smb347_charger *smb, CFG_STAT_ACTIVE_HIGH | CFG_STAT_DISABLED, CFG_STAT_DISABLED); if (ret < 0) - goto fail_readonly; + client->irq = 0; smb347_set_writable(smb, false); - client->irq = irq; - return 0; -fail_readonly: - smb347_set_writable(smb, false); -fail_irq: - free_irq(irq, smb); -fail_gpio: - gpio_free(pdata->irq_gpio); -fail: - client->irq = 0; return ret; } @@ -1251,32 +1251,24 @@ static int smb347_probe(struct i2c_client *client, mains_usb_cfg.num_supplicants = ARRAY_SIZE(battery); mains_usb_cfg.drv_data = smb; if (smb->pdata->use_mains) { - smb->mains = power_supply_register(dev, &smb347_mains_desc, - &mains_usb_cfg); + smb->mains = devm_power_supply_register(dev, &smb347_mains_desc, + &mains_usb_cfg); if (IS_ERR(smb->mains)) return PTR_ERR(smb->mains); } if (smb->pdata->use_usb) { - smb->usb = power_supply_register(dev, &smb347_usb_desc, - &mains_usb_cfg); - if (IS_ERR(smb->usb)) { - if (smb->pdata->use_mains) - power_supply_unregister(smb->mains); + smb->usb = devm_power_supply_register(dev, &smb347_usb_desc, + &mains_usb_cfg); + if (IS_ERR(smb->usb)) return PTR_ERR(smb->usb); - } } battery_cfg.drv_data = smb; - smb->battery = power_supply_register(dev, &smb347_battery_desc, - &battery_cfg); - if (IS_ERR(smb->battery)) { - if (smb->pdata->use_usb) - power_supply_unregister(smb->usb); - if (smb->pdata->use_mains) - power_supply_unregister(smb->mains); + smb->battery = devm_power_supply_register(dev, &smb347_battery_desc, + &battery_cfg); + if (IS_ERR(smb->battery)) return PTR_ERR(smb->battery); - } /* * Interrupt pin is optional. If it is connected, we setup the @@ -1299,17 +1291,8 @@ static int smb347_remove(struct i2c_client *client) { struct smb347_charger *smb = i2c_get_clientdata(client); - if (client->irq) { + if (client->irq) smb347_irq_disable(smb); - free_irq(client->irq, smb); - gpio_free(smb->pdata->irq_gpio); - } - - power_supply_unregister(smb->battery); - if (smb->pdata->use_usb) - power_supply_unregister(smb->usb); - if (smb->pdata->use_mains) - power_supply_unregister(smb->mains); return 0; } From patchwork Thu Aug 13 21:34:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11713019 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 072B3722 for ; Thu, 13 Aug 2020 21:35:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D947B22B45 for ; Thu, 13 Aug 2020 21:35:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MAkX+Ug+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726835AbgHMVer (ORCPT ); Thu, 13 Aug 2020 17:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726686AbgHMVei (ORCPT ); Thu, 13 Aug 2020 17:34:38 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0125FC061757; Thu, 13 Aug 2020 14:34:38 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id m22so7789232ljj.5; Thu, 13 Aug 2020 14:34:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Vvax3w5zuK8UPtDnqtBVJ1VxyZp9PqB+NM2Rb701YK0=; b=MAkX+Ug+p6CdPoSe37XJnbgQmX3yCBW0vfji9BV1ZddlQDEkqnFtQaX5TqYk/lLza7 7vx/NXmOcKxs4Vv5XcPlcS2O6TOoF/AtrOmZxY2JJtPROV3BCZblv8V9axRTYef7ZIPa q9M472RZHBn56UIHEBEjDDG2RbmhfKyAO/BRbAVyJP89adlVwo4FPXPzSRk6aOW+HVZk FwZPcMpsPG2/wfjDc1pwJWKFSGSNXFow9kf6AZf2nHLMmKoRhxkhcCUI2/NCMpgdR2F2 ID8JgVyYUR8bDN5XM3uIu7edtxahpeAxuyS2U4aaKfuNp0tfRS10wqqQLS1oRkwM1Dsp j+Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vvax3w5zuK8UPtDnqtBVJ1VxyZp9PqB+NM2Rb701YK0=; b=Jfox2gQD62z9H3plcHZZcqeHngfmqpudKx82tnu5g23Iyv63XRabyc9HpYcxqpeqSz VeoaXh6YWYo+QIcZYU3rhznRGNoZ77B9Sm3sutMw80tsTjSRZ6m1B45ZWTRLRGQ1qtkc 4th+0B727GCXReSnu6RFlW+titxghKDr+lz1pShsklso0CF/lpNGPVmTGWyYmd7BtbE5 o08PzEgg18v+XtgUapHwocwYvHsXlSjens7a27ZGac0op1gimnvc619nPXw3S0fkgZUd ZveELUpxpjpoj+64VVT7xSHeNWaeOXMQwGUl1aYYxv17dsRxfVpLCP81Nbz4S6HktHj2 t9UA== X-Gm-Message-State: AOAM530THPhK/77qCGznFyyr4DQY35f6M7BHztW5ds7o6zcPN2odxf41 3GNQWIgqGj0NKTCBg/AAGoA= X-Google-Smtp-Source: ABdhPJzGLtS2jY3MI09apEoWdHFhx8OTfB1O7Fyu1ptGmy1FdOFZAYc7hVKGoGLnrpo+ae0daHUNpQ== X-Received: by 2002:a05:651c:1293:: with SMTP id 19mr334463ljc.427.1597354476417; Thu, 13 Aug 2020 14:34:36 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j2sm1345309ljb.98.2020.08.13.14.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 14:34:35 -0700 (PDT) From: Dmitry Osipenko To: Sebastian Reichel , Rob Herring , Andy Gross , Bjorn Andersson , David Heidelberg , Thierry Reding , Jonathan Hunter , Mika Westerberg , "Bruce E . Robertson" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Jonghwa Lee , John Stultz , Vinay Simha BN , linux-tegra@vger.kernel.org Subject: [PATCH v3 05/10] power: supply: smb347-charger: Implement device-tree support Date: Fri, 14 Aug 2020 00:34:04 +0300 Message-Id: <20200813213409.24222-6-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200813213409.24222-1-digetx@gmail.com> References: <20200813213409.24222-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: David Heidelberg This patch adds device-tree support to the SMB347 charger driver. All legacy platform data now can be parsed from DT. Because of that and since SMB347 is an I2C client driver, the IRQ number can be passed automatically through client's IRQ variable if it's defined in DT. There is no need to map GPIO to IRQ manually in the case of DT. This patch is based on the original work made by: Jonghwa Lee Link: https://patchwork.kernel.org/patch/4284731/ Signed-off-by: Dmitry Osipenko Signed-off-by: David Heidelberg --- drivers/power/supply/smb347-charger.c | 151 +++++++++++++++++++++++--- 1 file changed, 137 insertions(+), 14 deletions(-) diff --git a/drivers/power/supply/smb347-charger.c b/drivers/power/supply/smb347-charger.c index 60894105fcbd..da2c337107bf 100644 --- a/drivers/power/supply/smb347-charger.c +++ b/drivers/power/supply/smb347-charger.c @@ -1180,6 +1180,119 @@ static bool smb347_readable_reg(struct device *dev, unsigned int reg) return smb347_volatile_reg(dev, reg); } +static void smb347_dt_parse_pdata(struct device_node *np, + struct smb347_charger_platform_data *pdata) +{ + pdata->soft_temp_limit_compensation = + SMB347_SOFT_TEMP_COMPENSATE_DEFAULT; + /* + * These properties come from the battery info, still we need to + * pre-initialize the values. See smb347_get_battery_info() below. + */ + pdata->soft_cold_temp_limit = SMB347_TEMP_USE_DEFAULT; + pdata->hard_cold_temp_limit = SMB347_TEMP_USE_DEFAULT; + pdata->soft_hot_temp_limit = SMB347_TEMP_USE_DEFAULT; + pdata->hard_hot_temp_limit = SMB347_TEMP_USE_DEFAULT; + + /* Charging constraints */ + of_property_read_u32(np, "summit,fast-voltage-threshold-microvolt", + &pdata->pre_to_fast_voltage); + of_property_read_u32(np, "summit,mains-current-limit-microamp", + &pdata->mains_current_limit); + of_property_read_u32(np, "summit,usb-current-limit-microamp", + &pdata->usb_hc_current_limit); + + /* For thermometer monitoring */ + of_property_read_u32(np, "summit,chip-temperature-threshold-celsius", + &pdata->chip_temp_threshold); + of_property_read_u32(np, "summit,soft-compensation-method", + &pdata->soft_temp_limit_compensation); + of_property_read_u32(np, "summit,charge-current-compensation-microamp", + &pdata->charge_current_compensation); + + /* Supported charging mode */ + pdata->use_mains = + of_property_read_bool(np, "summit,enable-mains-charging"); + pdata->use_usb = + of_property_read_bool(np, "summit,enable-usb-charging"); + pdata->use_usb_otg = + of_property_read_bool(np, "summit,enable-otg-charging"); + + /* Select charging control */ + of_property_read_u32(np, "summit,enable-charge-control", + &pdata->enable_control); + + /* Interrupt support is optional */ + if (!of_find_property(np, "interrupts", NULL)) + pdata->irq_gpio = -1; +} + +static int smb347_get_battery_info(struct smb347_charger *smb) +{ + struct smb347_charger_platform_data *pdata = (void *)smb->pdata; + struct power_supply_battery_info info = {}; + struct power_supply *supply; + int err; + + if (smb->mains) + supply = smb->mains; + else + supply = smb->usb; + + err = power_supply_get_battery_info(supply, &info); + if (err == -ENXIO || err == -ENODEV) + return 0; + if (err) + return err; + + if (info.constant_charge_current_max_ua != -EINVAL) + pdata->max_charge_current = info.constant_charge_current_max_ua; + + if (info.constant_charge_voltage_max_uv != -EINVAL) + pdata->max_charge_voltage = info.constant_charge_voltage_max_uv; + + if (info.precharge_current_ua != -EINVAL) + pdata->pre_charge_current = info.precharge_current_ua; + + if (info.charge_term_current_ua != -EINVAL) + pdata->termination_current = info.charge_term_current_ua; + + if (info.temp_alert_min != INT_MIN) + pdata->soft_cold_temp_limit = info.temp_alert_min; + + if (info.temp_alert_max != INT_MAX) + pdata->soft_hot_temp_limit = info.temp_alert_max; + + if (info.temp_min != INT_MIN) + pdata->hard_cold_temp_limit = info.temp_min; + + if (info.temp_max != INT_MAX) + pdata->hard_hot_temp_limit = info.temp_max; + + /* Suspend when battery temperature is outside hard limits */ + if (pdata->hard_cold_temp_limit != SMB347_TEMP_USE_DEFAULT || + pdata->hard_hot_temp_limit != SMB347_TEMP_USE_DEFAULT) + pdata->suspend_on_hard_temp_limit = true; + + return 0; +} + +static struct smb347_charger_platform_data + *smb347_get_platdata(struct device *dev) +{ + struct smb347_charger_platform_data *pdata; + + if (dev->of_node) { + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (pdata) + smb347_dt_parse_pdata(dev->of_node, pdata); + } else { + pdata = dev_get_platdata(dev); + } + + return pdata; +} + static const struct regmap_config smb347_regmap = { .reg_bits = 8, .val_bits = 8, @@ -1216,40 +1329,35 @@ static int smb347_probe(struct i2c_client *client, const struct i2c_device_id *id) { static char *battery[] = { "smb347-battery" }; - const struct smb347_charger_platform_data *pdata; struct power_supply_config mains_usb_cfg = {}, battery_cfg = {}; struct device *dev = &client->dev; struct smb347_charger *smb; int ret; - pdata = dev->platform_data; - if (!pdata) - return -EINVAL; - - if (!pdata->use_mains && !pdata->use_usb) - return -EINVAL; - smb = devm_kzalloc(dev, sizeof(*smb), GFP_KERNEL); if (!smb) return -ENOMEM; + smb->pdata = smb347_get_platdata(dev); + if (!smb->pdata) + return -ENODEV; + + if (!smb->pdata->use_mains && !smb->pdata->use_usb) + return -EINVAL; + i2c_set_clientdata(client, smb); mutex_init(&smb->lock); smb->dev = &client->dev; - smb->pdata = pdata; smb->regmap = devm_regmap_init_i2c(client, &smb347_regmap); if (IS_ERR(smb->regmap)) return PTR_ERR(smb->regmap); - ret = smb347_hw_init(smb); - if (ret < 0) - return ret; - mains_usb_cfg.supplied_to = battery; mains_usb_cfg.num_supplicants = ARRAY_SIZE(battery); mains_usb_cfg.drv_data = smb; + mains_usb_cfg.of_node = dev->of_node; if (smb->pdata->use_mains) { smb->mains = devm_power_supply_register(dev, &smb347_mains_desc, &mains_usb_cfg); @@ -1270,11 +1378,19 @@ static int smb347_probe(struct i2c_client *client, if (IS_ERR(smb->battery)) return PTR_ERR(smb->battery); + ret = smb347_get_battery_info(smb); + if (ret) + return ret; + + ret = smb347_hw_init(smb); + if (ret < 0) + return ret; + /* * Interrupt pin is optional. If it is connected, we setup the * interrupt support here. */ - if (pdata->irq_gpio >= 0) { + if (smb->pdata->irq_gpio >= 0) { ret = smb347_irq_init(smb, client); if (ret < 0) { dev_warn(dev, "failed to initialize IRQ: %d\n", ret); @@ -1302,9 +1418,16 @@ static const struct i2c_device_id smb347_id[] = { }; MODULE_DEVICE_TABLE(i2c, smb347_id); +static const struct of_device_id smb3xx_of_match[] = { + { .compatible = "summit,smb347" }, + { }, +}; +MODULE_DEVICE_TABLE(of, smb3xx_of_match); + static struct i2c_driver smb347_driver = { .driver = { .name = "smb347", + .of_match_table = smb3xx_of_match, }, .probe = smb347_probe, .remove = smb347_remove, From patchwork Thu Aug 13 21:34:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11713023 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D2F6A722 for ; Thu, 13 Aug 2020 21:35:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B509520838 for ; Thu, 13 Aug 2020 21:35:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i3GzF4xq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726815AbgHMVer (ORCPT ); Thu, 13 Aug 2020 17:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726596AbgHMVek (ORCPT ); Thu, 13 Aug 2020 17:34:40 -0400 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B83BC061383; Thu, 13 Aug 2020 14:34:39 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id s9so3803353lfs.4; Thu, 13 Aug 2020 14:34:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rDN7toTIVhzK3vl2BFEECQNcRaypv+RPJaVRD3dX5gI=; b=i3GzF4xqY6Qw00PCzWfmYvuKwpxfBQmFokEKZaQYeHPR3fviAqENSgA1865VOgnT7r IRFG2VDTbfeaxJ7Kw0nJHRpTy2n8NQWOo1xZdvHFqPWAvb+WsxQ8aCvvR8duUN4hSEIr b9pOPrYaKIOA03SNe9k/durn4dm6K9paSrIkDXQFgcp9GMoHbhHzaid9Oa3S0wsgvadL p3pWidPdhzb8c4/VjcuXLtc8j5s2zjajYJnIOGoGfO3QyOvs2n5e5lMPn9jzF+LbTKFO FjrGKcDohZ2VT0QL9APKLc1bDPiIpUG+UP/gvVsM31eaAYyoF/GpiTFOO3bT/DQAVlVt LBbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rDN7toTIVhzK3vl2BFEECQNcRaypv+RPJaVRD3dX5gI=; b=qdGFvjUheB4SoGm3sUTT6iaQDAvak7aiLR9o3PnB9cjubz/zYXoD0E/MPiOdO9WfKL ycejb1b6iRJTzmoLN2UZ3YZVj6RRioG9Yyq+2CuqWuJXsUF9qxzzE/d2rPdo12ppc6nU VOLKQKlcP++Vqexox3fMAEiF+8IIixGf4eMkt9ZqeMxDqfWrroeaiwpjVNvSrPKCKa1o q/Jbb9Eybup2X02gCxw8r9ur51LfKGeaKtfIX5Mlcuc7Qosp7RzaFYOsFrsyytdUYQ71 KuCjo6RFEneFdWj94OX+o7zi2vrRA2RdgGQHUgwukwGk+hVpUqLg+Q9XgjnDQbAjJu2H E4Rg== X-Gm-Message-State: AOAM533V/mgaNZ/lXDk2g4LQ4PDFD9vo0UDS8zUdSUIWW/M9+cXalfv1 O+BoJ81+6sVbupjEX46nblWYZmJa X-Google-Smtp-Source: ABdhPJzNzH6A0dKJ/Ys8lpiFtSK9o7ZgUVZCtmM4omKFcNMzmqk5X8MkrU6+nD0G2KDp8je0vR7Psw== X-Received: by 2002:a19:4857:: with SMTP id v84mr3000466lfa.195.1597354477549; Thu, 13 Aug 2020 14:34:37 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j2sm1345309ljb.98.2020.08.13.14.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 14:34:37 -0700 (PDT) From: Dmitry Osipenko To: Sebastian Reichel , Rob Herring , Andy Gross , Bjorn Andersson , David Heidelberg , Thierry Reding , Jonathan Hunter , Mika Westerberg , "Bruce E . Robertson" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Jonghwa Lee , John Stultz , Vinay Simha BN , linux-tegra@vger.kernel.org Subject: [PATCH v3 06/10] power: supply: smb347-charger: Support SMB345 and SMB358 Date: Fri, 14 Aug 2020 00:34:05 +0300 Message-Id: <20200813213409.24222-7-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200813213409.24222-1-digetx@gmail.com> References: <20200813213409.24222-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: David Heidelberg SMB345 tested on Nexus 7 2013. Based on: - https://patchwork.kernel.org/patch/4922431/ - https://patchwork.ozlabs.org/patch/666877/ Signed-off-by: David Heidelberg --- drivers/power/supply/Kconfig | 6 +- drivers/power/supply/smb347-charger.c | 109 ++++++++++++++------------ 2 files changed, 62 insertions(+), 53 deletions(-) diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index e87b2434d835..7b1eda3257dd 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -639,12 +639,12 @@ config CHARGER_BQ25890 Say Y to enable support for the TI BQ25890 battery charger. config CHARGER_SMB347 - tristate "Summit Microelectronics SMB347 Battery Charger" + tristate "Summit Microelectronics SMB3XX Battery Charger" depends on I2C select REGMAP_I2C help - Say Y to include support for Summit Microelectronics SMB347 - Battery Charger. + Say Y to include support for Summit Microelectronics SMB345, + SMB347 or SMB358 Battery Charger. config CHARGER_TPS65090 tristate "TPS65090 battery charger driver" diff --git a/drivers/power/supply/smb347-charger.c b/drivers/power/supply/smb347-charger.c index da2c337107bf..90a87e0624a6 100644 --- a/drivers/power/supply/smb347-charger.c +++ b/drivers/power/supply/smb347-charger.c @@ -128,6 +128,7 @@ * @mains: power_supply instance for AC/DC power * @usb: power_supply instance for USB power * @battery: power_supply instance for battery + * @id: SMB charger ID * @mains_online: is AC/DC input connected * @usb_online: is USB input connected * @charging_enabled: is charging enabled @@ -140,64 +141,61 @@ struct smb347_charger { struct power_supply *mains; struct power_supply *usb; struct power_supply *battery; + unsigned int id; bool mains_online; bool usb_online; bool charging_enabled; const struct smb347_charger_platform_data *pdata; }; -/* Fast charge current in uA */ -static const unsigned int fcc_tbl[] = { - 700000, - 900000, - 1200000, - 1500000, - 1800000, - 2000000, - 2200000, - 2500000, +enum smb_charger_chipid { + SMB345, + SMB347, + SMB358, + NUM_CHIP_TYPES, }; +/* Fast charge current in uA */ +static const unsigned int fcc_tbl[NUM_CHIP_TYPES][8] = { + [SMB345] = { 200000, 450000, 600000, 900000, + 1300000, 1500000, 1800000, 2000000 }, + [SMB347] = { 700000, 900000, 1200000, 1500000, + 1800000, 2000000, 2200000, 2500000 }, + [SMB358] = { 200000, 450000, 600000, 900000, + 1300000, 1500000, 1800000, 2000000 }, +}; /* Pre-charge current in uA */ -static const unsigned int pcc_tbl[] = { - 100000, - 150000, - 200000, - 250000, +static const unsigned int pcc_tbl[NUM_CHIP_TYPES][4] = { + [SMB345] = { 150000, 250000, 350000, 450000 }, + [SMB347] = { 100000, 150000, 200000, 250000 }, + [SMB358] = { 150000, 250000, 350000, 450000 }, }; /* Termination current in uA */ -static const unsigned int tc_tbl[] = { - 37500, - 50000, - 100000, - 150000, - 200000, - 250000, - 500000, - 600000, +static const unsigned int tc_tbl[NUM_CHIP_TYPES][8] = { + [SMB345] = { 30000, 40000, 60000, 80000, + 100000, 125000, 150000, 200000 }, + [SMB347] = { 37500, 50000, 100000, 150000, + 200000, 250000, 500000, 600000 }, + [SMB358] = { 30000, 40000, 60000, 80000, + 100000, 125000, 150000, 200000 }, }; /* Input current limit in uA */ -static const unsigned int icl_tbl[] = { - 300000, - 500000, - 700000, - 900000, - 1200000, - 1500000, - 1800000, - 2000000, - 2200000, - 2500000, +static const unsigned int icl_tbl[NUM_CHIP_TYPES][10] = { + [SMB345] = { 300000, 500000, 700000, 1000000, 1500000, + 1800000, 2000000, 2000000, 2000000, 2000000 }, + [SMB347] = { 300000, 500000, 700000, 900000, 1200000, + 1500000, 1800000, 2000000, 2200000, 2500000 }, + [SMB358] = { 300000, 500000, 700000, 1000000, 1500000, + 1800000, 2000000, 2000000, 2000000, 2000000 }, }; /* Charge current compensation in uA */ -static const unsigned int ccc_tbl[] = { - 250000, - 700000, - 900000, - 1200000, +static const unsigned int ccc_tbl[NUM_CHIP_TYPES][4] = { + [SMB345] = { 200000, 450000, 600000, 900000 }, + [SMB347] = { 250000, 700000, 900000, 1200000 }, + [SMB358] = { 200000, 450000, 600000, 900000 }, }; /* Convert register value to current using lookup table */ @@ -352,10 +350,11 @@ static int smb347_start_stop_charging(struct smb347_charger *smb) static int smb347_set_charge_current(struct smb347_charger *smb) { + unsigned int id = smb->id; int ret; if (smb->pdata->max_charge_current) { - ret = current_to_hw(fcc_tbl, ARRAY_SIZE(fcc_tbl), + ret = current_to_hw(fcc_tbl[id], ARRAY_SIZE(fcc_tbl[id]), smb->pdata->max_charge_current); if (ret < 0) return ret; @@ -368,7 +367,7 @@ static int smb347_set_charge_current(struct smb347_charger *smb) } if (smb->pdata->pre_charge_current) { - ret = current_to_hw(pcc_tbl, ARRAY_SIZE(pcc_tbl), + ret = current_to_hw(pcc_tbl[id], ARRAY_SIZE(pcc_tbl[id]), smb->pdata->pre_charge_current); if (ret < 0) return ret; @@ -381,7 +380,7 @@ static int smb347_set_charge_current(struct smb347_charger *smb) } if (smb->pdata->termination_current) { - ret = current_to_hw(tc_tbl, ARRAY_SIZE(tc_tbl), + ret = current_to_hw(tc_tbl[id], ARRAY_SIZE(tc_tbl[id]), smb->pdata->termination_current); if (ret < 0) return ret; @@ -397,10 +396,11 @@ static int smb347_set_charge_current(struct smb347_charger *smb) static int smb347_set_current_limits(struct smb347_charger *smb) { + unsigned int id = smb->id; int ret; if (smb->pdata->mains_current_limit) { - ret = current_to_hw(icl_tbl, ARRAY_SIZE(icl_tbl), + ret = current_to_hw(icl_tbl[id], ARRAY_SIZE(icl_tbl[id]), smb->pdata->mains_current_limit); if (ret < 0) return ret; @@ -413,7 +413,7 @@ static int smb347_set_current_limits(struct smb347_charger *smb) } if (smb->pdata->usb_hc_current_limit) { - ret = current_to_hw(icl_tbl, ARRAY_SIZE(icl_tbl), + ret = current_to_hw(icl_tbl[id], ARRAY_SIZE(icl_tbl[id]), smb->pdata->usb_hc_current_limit); if (ret < 0) return ret; @@ -463,6 +463,7 @@ static int smb347_set_voltage_limits(struct smb347_charger *smb) static int smb347_set_temp_limits(struct smb347_charger *smb) { + unsigned int id = smb->id; bool enable_therm_monitor = false; int ret = 0; int val; @@ -587,7 +588,7 @@ static int smb347_set_temp_limits(struct smb347_charger *smb) } if (smb->pdata->charge_current_compensation) { - val = current_to_hw(ccc_tbl, ARRAY_SIZE(ccc_tbl), + val = current_to_hw(ccc_tbl[id], ARRAY_SIZE(ccc_tbl[id]), smb->pdata->charge_current_compensation); if (val < 0) return val; @@ -883,6 +884,7 @@ static int smb347_irq_init(struct smb347_charger *smb, */ static int get_const_charge_current(struct smb347_charger *smb) { + unsigned int id = smb->id; int ret, intval; unsigned int v; @@ -898,10 +900,12 @@ static int get_const_charge_current(struct smb347_charger *smb) * and we can detect which table to use from bit 5. */ if (v & 0x20) { - intval = hw_to_current(fcc_tbl, ARRAY_SIZE(fcc_tbl), v & 7); + intval = hw_to_current(fcc_tbl[id], + ARRAY_SIZE(fcc_tbl[id]), v & 7); } else { v >>= 3; - intval = hw_to_current(pcc_tbl, ARRAY_SIZE(pcc_tbl), v & 7); + intval = hw_to_current(pcc_tbl[id], + ARRAY_SIZE(pcc_tbl[id]), v & 7); } return intval; @@ -1349,6 +1353,7 @@ static int smb347_probe(struct i2c_client *client, mutex_init(&smb->lock); smb->dev = &client->dev; + smb->id = id->driver_data; smb->regmap = devm_regmap_init_i2c(client, &smb347_regmap); if (IS_ERR(smb->regmap)) @@ -1413,13 +1418,17 @@ static int smb347_remove(struct i2c_client *client) } static const struct i2c_device_id smb347_id[] = { - { "smb347", 0 }, - { } + { "smb345", SMB345 }, + { "smb347", SMB347 }, + { "smb358", SMB358 }, + { }, }; MODULE_DEVICE_TABLE(i2c, smb347_id); static const struct of_device_id smb3xx_of_match[] = { + { .compatible = "summit,smb345" }, { .compatible = "summit,smb347" }, + { .compatible = "summit,smb358" }, { }, }; MODULE_DEVICE_TABLE(of, smb3xx_of_match); From patchwork Thu Aug 13 21:34:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11713029 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B048713B6 for ; Thu, 13 Aug 2020 21:35:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 938652177B for ; Thu, 13 Aug 2020 21:35:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eq+F5iEl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726792AbgHMVep (ORCPT ); Thu, 13 Aug 2020 17:34:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726752AbgHMVel (ORCPT ); Thu, 13 Aug 2020 17:34:41 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C430C061757; Thu, 13 Aug 2020 14:34:40 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id h19so7777607ljg.13; Thu, 13 Aug 2020 14:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EqGqa6HvoFlh+c/YAEirRq/tW0ZfROO35qCFwppetS0=; b=eq+F5iEl/Etuio9GjQtESMcB/k/q0HAp3tsVxLraGrMOLWJXZebvUElShxzyWhqNMO lC9AwhsRuRI0LwEPeUpYmfMbYTievYFqyzMbe4ctL1iIMsHRngKaL5fzL8WLKGhgKqTJ M2YnxYsoxgB0k5M4wi54UfXzfjy9hK2Ae4w8q1uKz6e1bts5KxBuqa8cL+jwxY8NYsiN MBL/sHSeLZmzl9Au+SG3B1E5f1mXSSFi3xSNsY0OnzVc2pzcyHfWDBoA+Pk4sHPs3SnS dF+oTGgmxfGKXFlXyKDGhe5/7qSwWW8J6CFtt149scYXjM/TLdb/lHC6DZMB4qcBPDML wyUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EqGqa6HvoFlh+c/YAEirRq/tW0ZfROO35qCFwppetS0=; b=IEnyFqAMW6cYk4xH2SMLXaQFxpDbfcUGKtC7p41sbPSYsKJ6v48B7hm6ngFGG/8ON0 7iHoHoyE5+AmYwr6hnIEfBZKk5hfeKiXFw9XdlZcsTdd954F+Mjj4vFInziIT+xyDPzB hJ3WP8VkKAXbxHkweGUeV3baFB/fYfZ5ugg2O838hzXY3xKUtsCJY8yGQjHHQX+zF4ro IDsNEIAqUvrn8uacnsn0nBi5l5PLLNEP+ESpawAqK0dNo5Q3L6clqE2MgUhjZ7xUqQIW aXSJNm3+AD3QackBhZiZbJWk0lKB+LwF62bLnBJdLFHMRDOA3CB/BASqpkuljLcEU877 GYiA== X-Gm-Message-State: AOAM531eNXqXw/39Zv74Aobiugtv1bipmosHlgQFnKaKi9FRKnWHAo1c sfBxH68MxFiuxvxj+Jf5b94= X-Google-Smtp-Source: ABdhPJzVF95c0zu0LJ9gugw5NGOqEtyLN8XOwKwwJ5vwtxSrIaw6FOM2w9bHyhMTCdJwbdxR7OvkxQ== X-Received: by 2002:a05:651c:1349:: with SMTP id j9mr2789261ljb.392.1597354478863; Thu, 13 Aug 2020 14:34:38 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j2sm1345309ljb.98.2020.08.13.14.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 14:34:38 -0700 (PDT) From: Dmitry Osipenko To: Sebastian Reichel , Rob Herring , Andy Gross , Bjorn Andersson , David Heidelberg , Thierry Reding , Jonathan Hunter , Mika Westerberg , "Bruce E . Robertson" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Jonghwa Lee , John Stultz , Vinay Simha BN , linux-tegra@vger.kernel.org Subject: [PATCH v3 07/10] power: supply: smb347-charger: Remove virtual smb347-battery Date: Fri, 14 Aug 2020 00:34:06 +0300 Message-Id: <20200813213409.24222-8-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200813213409.24222-1-digetx@gmail.com> References: <20200813213409.24222-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: David Heidelberg SMB347 is a charger and not a battery driver. Secondly, power-supply core now supports monitored-battery. So the 'fake' battery doesn't do anything useful for us, and thus, it should be removed. Transfer smb347-battery functionality into smb347-mains and smb347-usb. Reviewed-by: Dmitry Osipenko Signed-off-by: David Heidelberg --- drivers/power/supply/smb347-charger.c | 206 ++++++++------------------ 1 file changed, 60 insertions(+), 146 deletions(-) diff --git a/drivers/power/supply/smb347-charger.c b/drivers/power/supply/smb347-charger.c index 90a87e0624a6..335b6ee494e4 100644 --- a/drivers/power/supply/smb347-charger.c +++ b/drivers/power/supply/smb347-charger.c @@ -127,7 +127,6 @@ * @regmap: pointer to driver regmap * @mains: power_supply instance for AC/DC power * @usb: power_supply instance for USB power - * @battery: power_supply instance for battery * @id: SMB charger ID * @mains_online: is AC/DC input connected * @usb_online: is USB input connected @@ -140,7 +139,6 @@ struct smb347_charger { struct regmap *regmap; struct power_supply *mains; struct power_supply *usb; - struct power_supply *battery; unsigned int id; bool mains_online; bool usb_online; @@ -743,7 +741,10 @@ static irqreturn_t smb347_interrupt(int irq, void *data) */ if (stat_c & STAT_C_CHARGER_ERROR) { dev_err(smb->dev, "charging stopped due to charger error\n"); - power_supply_changed(smb->battery); + if (smb->pdata->use_mains) + power_supply_changed(smb->mains); + if (smb->pdata->use_usb) + power_supply_changed(smb->usb); handled = true; } @@ -753,8 +754,12 @@ static irqreturn_t smb347_interrupt(int irq, void *data) * disabled by the hardware. */ if (irqstat_c & (IRQSTAT_C_TERMINATION_IRQ | IRQSTAT_C_TAPER_IRQ)) { - if (irqstat_c & IRQSTAT_C_TERMINATION_STAT) - power_supply_changed(smb->battery); + if (irqstat_c & IRQSTAT_C_TERMINATION_STAT) { + if (smb->pdata->use_mains) + power_supply_changed(smb->mains); + if (smb->pdata->use_usb) + power_supply_changed(smb->usb); + } dev_dbg(smb->dev, "going to HW maintenance mode\n"); handled = true; } @@ -768,7 +773,10 @@ static irqreturn_t smb347_interrupt(int irq, void *data) if (irqstat_d & IRQSTAT_D_CHARGE_TIMEOUT_STAT) dev_warn(smb->dev, "charging stopped due to timeout\n"); - power_supply_changed(smb->battery); + if (smb->pdata->use_mains) + power_supply_changed(smb->mains); + if (smb->pdata->use_usb) + power_supply_changed(smb->usb); handled = true; } @@ -936,95 +944,19 @@ static int get_const_charge_voltage(struct smb347_charger *smb) return intval; } -static int smb347_mains_get_property(struct power_supply *psy, - enum power_supply_property prop, - union power_supply_propval *val) -{ - struct smb347_charger *smb = power_supply_get_drvdata(psy); - int ret; - - switch (prop) { - case POWER_SUPPLY_PROP_ONLINE: - val->intval = smb->mains_online; - break; - - case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: - ret = get_const_charge_voltage(smb); - if (ret < 0) - return ret; - else - val->intval = ret; - break; - - case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: - ret = get_const_charge_current(smb); - if (ret < 0) - return ret; - else - val->intval = ret; - break; - - default: - return -EINVAL; - } - - return 0; -} - -static enum power_supply_property smb347_mains_properties[] = { - POWER_SUPPLY_PROP_ONLINE, - POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, - POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, -}; - -static int smb347_usb_get_property(struct power_supply *psy, - enum power_supply_property prop, - union power_supply_propval *val) -{ - struct smb347_charger *smb = power_supply_get_drvdata(psy); - int ret; - - switch (prop) { - case POWER_SUPPLY_PROP_ONLINE: - val->intval = smb->usb_online; - break; - - case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: - ret = get_const_charge_voltage(smb); - if (ret < 0) - return ret; - else - val->intval = ret; - break; - - case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: - ret = get_const_charge_current(smb); - if (ret < 0) - return ret; - else - val->intval = ret; - break; - - default: - return -EINVAL; - } - - return 0; -} - -static enum power_supply_property smb347_usb_properties[] = { - POWER_SUPPLY_PROP_ONLINE, - POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, - POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, -}; - -static int smb347_get_charging_status(struct smb347_charger *smb) +static int smb347_get_charging_status(struct smb347_charger *smb, + struct power_supply *psy) { int ret, status; unsigned int val; - if (!smb347_is_ps_online(smb)) - return POWER_SUPPLY_STATUS_DISCHARGING; + if (psy->desc->type == POWER_SUPPLY_TYPE_USB) { + if (!smb->usb_online) + return POWER_SUPPLY_STATUS_DISCHARGING; + } else { + if (!smb->mains_online) + return POWER_SUPPLY_STATUS_DISCHARGING; + } ret = regmap_read(smb->regmap, STAT_C, &val); if (ret < 0) @@ -1063,29 +995,29 @@ static int smb347_get_charging_status(struct smb347_charger *smb) return status; } -static int smb347_battery_get_property(struct power_supply *psy, - enum power_supply_property prop, - union power_supply_propval *val) +static int smb347_get_property(struct power_supply *psy, + enum power_supply_property prop, + union power_supply_propval *val) { struct smb347_charger *smb = power_supply_get_drvdata(psy); - const struct smb347_charger_platform_data *pdata = smb->pdata; int ret; - ret = smb347_update_ps_status(smb); - if (ret < 0) - return ret; - switch (prop) { case POWER_SUPPLY_PROP_STATUS: - ret = smb347_get_charging_status(smb); + ret = smb347_get_charging_status(smb, psy); if (ret < 0) return ret; val->intval = ret; break; case POWER_SUPPLY_PROP_CHARGE_TYPE: - if (!smb347_is_ps_online(smb)) - return -ENODATA; + if (psy->desc->type == POWER_SUPPLY_TYPE_USB) { + if (!smb->usb_online) + return -ENODATA; + } else { + if (!smb->mains_online) + return -ENODATA; + } /* * We handle trickle and pre-charging the same, and taper @@ -1104,24 +1036,25 @@ static int smb347_battery_get_property(struct power_supply *psy, } break; - case POWER_SUPPLY_PROP_TECHNOLOGY: - val->intval = pdata->battery_info.technology; - break; - - case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: - val->intval = pdata->battery_info.voltage_min_design; - break; - - case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: - val->intval = pdata->battery_info.voltage_max_design; + case POWER_SUPPLY_PROP_ONLINE: + if (psy->desc->type == POWER_SUPPLY_TYPE_USB) + val->intval = smb->usb_online; + else + val->intval = smb->mains_online; break; - case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: - val->intval = pdata->battery_info.charge_full_design; + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: + ret = get_const_charge_voltage(smb); + if (ret < 0) + return ret; + val->intval = ret; break; - case POWER_SUPPLY_PROP_MODEL_NAME: - val->strval = pdata->battery_info.name; + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: + ret = get_const_charge_current(smb); + if (ret < 0) + return ret; + val->intval = ret; break; default: @@ -1131,14 +1064,12 @@ static int smb347_battery_get_property(struct power_supply *psy, return 0; } -static enum power_supply_property smb347_battery_properties[] = { +static enum power_supply_property smb347_properties[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_CHARGE_TYPE, - POWER_SUPPLY_PROP_TECHNOLOGY, - POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, - POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, - POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, - POWER_SUPPLY_PROP_MODEL_NAME, + POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, }; static bool smb347_volatile_reg(struct device *dev, unsigned int reg) @@ -1308,32 +1239,23 @@ static const struct regmap_config smb347_regmap = { static const struct power_supply_desc smb347_mains_desc = { .name = "smb347-mains", .type = POWER_SUPPLY_TYPE_MAINS, - .get_property = smb347_mains_get_property, - .properties = smb347_mains_properties, - .num_properties = ARRAY_SIZE(smb347_mains_properties), + .get_property = smb347_get_property, + .properties = smb347_properties, + .num_properties = ARRAY_SIZE(smb347_properties), }; static const struct power_supply_desc smb347_usb_desc = { .name = "smb347-usb", .type = POWER_SUPPLY_TYPE_USB, - .get_property = smb347_usb_get_property, - .properties = smb347_usb_properties, - .num_properties = ARRAY_SIZE(smb347_usb_properties), -}; - -static const struct power_supply_desc smb347_battery_desc = { - .name = "smb347-battery", - .type = POWER_SUPPLY_TYPE_BATTERY, - .get_property = smb347_battery_get_property, - .properties = smb347_battery_properties, - .num_properties = ARRAY_SIZE(smb347_battery_properties), + .get_property = smb347_get_property, + .properties = smb347_properties, + .num_properties = ARRAY_SIZE(smb347_properties), }; static int smb347_probe(struct i2c_client *client, const struct i2c_device_id *id) { - static char *battery[] = { "smb347-battery" }; - struct power_supply_config mains_usb_cfg = {}, battery_cfg = {}; + struct power_supply_config mains_usb_cfg = {}; struct device *dev = &client->dev; struct smb347_charger *smb; int ret; @@ -1359,8 +1281,6 @@ static int smb347_probe(struct i2c_client *client, if (IS_ERR(smb->regmap)) return PTR_ERR(smb->regmap); - mains_usb_cfg.supplied_to = battery; - mains_usb_cfg.num_supplicants = ARRAY_SIZE(battery); mains_usb_cfg.drv_data = smb; mains_usb_cfg.of_node = dev->of_node; if (smb->pdata->use_mains) { @@ -1377,12 +1297,6 @@ static int smb347_probe(struct i2c_client *client, return PTR_ERR(smb->usb); } - battery_cfg.drv_data = smb; - smb->battery = devm_power_supply_register(dev, &smb347_battery_desc, - &battery_cfg); - if (IS_ERR(smb->battery)) - return PTR_ERR(smb->battery); - ret = smb347_get_battery_info(smb); if (ret) return ret; From patchwork Thu Aug 13 21:34:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11713013 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E632D14E3 for ; Thu, 13 Aug 2020 21:34:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C9C222087C for ; Thu, 13 Aug 2020 21:34:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Mdz7ome6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726778AbgHMVeo (ORCPT ); Thu, 13 Aug 2020 17:34:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726769AbgHMVen (ORCPT ); Thu, 13 Aug 2020 17:34:43 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A90E9C061757; Thu, 13 Aug 2020 14:34:42 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id b11so3788310lfe.10; Thu, 13 Aug 2020 14:34:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1VKJz7as6Cnf5+ugS7B5We4tFvmDh5J1LQ5Ei+QN204=; b=Mdz7ome6uGBEDSOOYK1DK2qGkJ2LyKmz4CprA4KNemfPR/vk6ZmCuWZkqa595YZzfe jAT/sVUAp9PADvR4NTiGN/uTzi4qDigHCn0/13Km49+msRgSlVVeG7ngq563LxXT/x8G wOCdx+vBhsF1l2OTpSh4HBUbc6RmpcXspSoXTgPMo56wVA2KGEgqLtxDNkxE4mNB0wkX Q6ouuCT+pW8M+ZX9cNkVakyjE9HYnpfLQnfyA9rsEnE22sVxL5Ow5b+3rk3L9WuvwR3i WiWuS4c4TktAPdapjBdDosIq1VNKRqk02/Xzpbr8E8y6fHFvgMXkWeMaY40eqwmKR5e5 QJqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1VKJz7as6Cnf5+ugS7B5We4tFvmDh5J1LQ5Ei+QN204=; b=euIsVOHvsSNbFIonFC+ovGHwD7QUAH9aVHykVbDmrlWcj4guKi/GeuXRvWGcJmqGDn vU6vNmXwuv6ZX5U83JPm3JcZSX+xMQyH4pn0ZqIfUgFUBZC1/rhRuAOA+Xx3i8nETOBi AtnXE82/Yb+idobRMdNfyJGK09R1RoRojkgxs2ZjkFSUwJ3iHZEaP6z7t16KoV+2xESI 5NX4bg6lao+8A01Ou9Mmi6fw8MrG0FPDScTmRms9qU7T+hTbm9o78bdERBsnn1r6dMS9 48B76UAqknrxqSg7tG2BAvfdvXR5Y2iiOhi42o1f+evS5GK/Ghf/Qu7fGdFJHhfhF/p5 KS0A== X-Gm-Message-State: AOAM531HaRXijLz+eAVx37PnGRKccE602PmeFZl8dF8i+U+FAPErtlXz BVJr2Dx5m+ebUeJ7K8gKkAU= X-Google-Smtp-Source: ABdhPJw39bedeZ+5oHMO7WQ2X8ddte3dC4UDJEKwhsoj6tIuzTJAAHfXFj8f5zPPVwpuQi3ZMdrYbg== X-Received: by 2002:ac2:546f:: with SMTP id e15mr3217327lfn.133.1597354480140; Thu, 13 Aug 2020 14:34:40 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j2sm1345309ljb.98.2020.08.13.14.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 14:34:39 -0700 (PDT) From: Dmitry Osipenko To: Sebastian Reichel , Rob Herring , Andy Gross , Bjorn Andersson , David Heidelberg , Thierry Reding , Jonathan Hunter , Mika Westerberg , "Bruce E . Robertson" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Jonghwa Lee , John Stultz , Vinay Simha BN , linux-tegra@vger.kernel.org Subject: [PATCH v3 08/10] power: supply: smb347-charger: Replace mutex with IRQ disable/enable Date: Fri, 14 Aug 2020 00:34:07 +0300 Message-Id: <20200813213409.24222-9-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200813213409.24222-1-digetx@gmail.com> References: <20200813213409.24222-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Let's simply disable/enable IRQ rather than use a mutex that protects from racing with the interrupt handler. The result of this patch is that it's a bit easier now to follow the driver's code. Tested-by: David Heidelberg Signed-off-by: Dmitry Osipenko --- drivers/power/supply/smb347-charger.c | 38 ++++++++++++++------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/drivers/power/supply/smb347-charger.c b/drivers/power/supply/smb347-charger.c index 335b6ee494e4..ec68ab2bce27 100644 --- a/drivers/power/supply/smb347-charger.c +++ b/drivers/power/supply/smb347-charger.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -122,7 +121,6 @@ /** * struct smb347_charger - smb347 charger instance - * @lock: protects concurrent access to online variables * @dev: pointer to device * @regmap: pointer to driver regmap * @mains: power_supply instance for AC/DC power @@ -134,7 +132,6 @@ * @pdata: pointer to platform data */ struct smb347_charger { - struct mutex lock; struct device *dev; struct regmap *regmap; struct power_supply *mains; @@ -243,11 +240,9 @@ static int smb347_update_ps_status(struct smb347_charger *smb) if (smb->pdata->use_usb) usb = !(val & IRQSTAT_E_USBIN_UV_STAT); - mutex_lock(&smb->lock); ret = smb->mains_online != dc || smb->usb_online != usb; smb->mains_online = dc; smb->usb_online = usb; - mutex_unlock(&smb->lock); return ret; } @@ -263,13 +258,7 @@ static int smb347_update_ps_status(struct smb347_charger *smb) */ static bool smb347_is_ps_online(struct smb347_charger *smb) { - bool ret; - - mutex_lock(&smb->lock); - ret = smb->usb_online || smb->mains_online; - mutex_unlock(&smb->lock); - - return ret; + return smb->usb_online || smb->mains_online; } /** @@ -303,14 +292,13 @@ static int smb347_charging_set(struct smb347_charger *smb, bool enable) return 0; } - mutex_lock(&smb->lock); if (smb->charging_enabled != enable) { ret = regmap_update_bits(smb->regmap, CMD_A, CMD_A_CHG_ENABLED, enable ? CMD_A_CHG_ENABLED : 0); if (!ret) smb->charging_enabled = enable; } - mutex_unlock(&smb->lock); + return ret; } @@ -995,9 +983,9 @@ static int smb347_get_charging_status(struct smb347_charger *smb, return status; } -static int smb347_get_property(struct power_supply *psy, - enum power_supply_property prop, - union power_supply_propval *val) +static int smb347_get_property_locked(struct power_supply *psy, + enum power_supply_property prop, + union power_supply_propval *val) { struct smb347_charger *smb = power_supply_get_drvdata(psy); int ret; @@ -1064,6 +1052,21 @@ static int smb347_get_property(struct power_supply *psy, return 0; } +static int smb347_get_property(struct power_supply *psy, + enum power_supply_property prop, + union power_supply_propval *val) +{ + struct smb347_charger *smb = power_supply_get_drvdata(psy); + struct i2c_client *client = to_i2c_client(smb->dev); + int ret; + + disable_irq(client->irq); + ret = smb347_get_property_locked(psy, prop, val); + enable_irq(client->irq); + + return ret; +} + static enum power_supply_property smb347_properties[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_CHARGE_TYPE, @@ -1273,7 +1276,6 @@ static int smb347_probe(struct i2c_client *client, i2c_set_clientdata(client, smb); - mutex_init(&smb->lock); smb->dev = &client->dev; smb->id = id->driver_data; From patchwork Thu Aug 13 21:34:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11713015 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9EA6914E3 for ; Thu, 13 Aug 2020 21:34:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83AC120855 for ; Thu, 13 Aug 2020 21:34:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ga1eSlCg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726795AbgHMVeq (ORCPT ); Thu, 13 Aug 2020 17:34:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726718AbgHMVen (ORCPT ); Thu, 13 Aug 2020 17:34:43 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9CD3C061383; Thu, 13 Aug 2020 14:34:42 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id f26so7779026ljc.8; Thu, 13 Aug 2020 14:34:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NW2Q8QyAC78Di/n3r7tUYO+X21vGGqNAbxETdGTQ/s4=; b=ga1eSlCgNIQqjyKkNoHyFOMNd7eZ0bntSeuLg6psM+R2q/UKb/44fN51fnAbSwcJ7d B2pNAp6Bf3BKUNnROkJiwaJABK0vuZPsZ9BquV64IUq1sMlt4Cz/iViZvOEquEG/L51F T9RFJ+1n5UZly2+EOAVvUVVb2w0xz5r1IoTNg156/WrVJt/6DOpBmqurx7xcY+qCQ8XX SS5T1niE+cfqQVZEJ49ZP2PP8wnX4OpNnKHNxU2QndSMXrsM85a+E4SvxtU/pgzmhlMA gqQOJonOkjCrhkQ6/X5UTzOcUK4xqqSvK4UK3WqFu5BZUz0Y5ub8UJIW3jXtbjK7Yvde ZmzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NW2Q8QyAC78Di/n3r7tUYO+X21vGGqNAbxETdGTQ/s4=; b=SghftJVaVW8VOd0g/E9fF9cn9hYZ4JSOV+Lvm1iW3SlauJheQPVRQqaRXhWRqis5J2 2QXsYKQeC02Sfw8VMe1z/pgJPKziNQbbWJomdzEgta/KSbLPf2nyfPSweihLP48ACEMo bt3h1daghibT6a3/rF2RsGrgOe3rTUKS+mY8pGzrtolUyfpkZOeG6va4hj1cdkpDLt5T It/Q2+qq3e0GtdeBVdDifGaVLn0iYtGUpmeGSP7xQNEZaLfFGUV0SjF20nmgzvsRxW0V EYNlAsYIHTSRjBBayTX9UfG/lefDoMDnFMgjHcOAKwKTkvvTkQgKCv2jnlWbStJkw3IT t98Q== X-Gm-Message-State: AOAM531iY1h4xAyMtT5n5NR39bYzPnJkthAVnieiq33XRPO/uFjzwP2k cvFk0tYtn1RqsQT5/7Y9oPg= X-Google-Smtp-Source: ABdhPJxffWEq5zLwVT/WMICj481TkdoYo3I3X7+ZiyjNO7oBDSABTz3CnwcUNuBjRHK8KqBarUZtXQ== X-Received: by 2002:a2e:9899:: with SMTP id b25mr2652637ljj.178.1597354481284; Thu, 13 Aug 2020 14:34:41 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j2sm1345309ljb.98.2020.08.13.14.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 14:34:40 -0700 (PDT) From: Dmitry Osipenko To: Sebastian Reichel , Rob Herring , Andy Gross , Bjorn Andersson , David Heidelberg , Thierry Reding , Jonathan Hunter , Mika Westerberg , "Bruce E . Robertson" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Jonghwa Lee , John Stultz , Vinay Simha BN , linux-tegra@vger.kernel.org Subject: [PATCH v3 09/10] ARM: dts: qcom: apq8064-nexus7: Add SMB345 battery charger Date: Fri, 14 Aug 2020 00:34:08 +0300 Message-Id: <20200813213409.24222-10-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200813213409.24222-1-digetx@gmail.com> References: <20200813213409.24222-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: David Heidelberg Add SMB345 charger node to Nexus 7 2013 DTS. Proper charger configuration prevents battery from overcharging. Original author: Vinay Simha BN Signed-off-by: David Heidelberg --- .../boot/dts/qcom-apq8064-asus-nexus7-flo.dts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/arm/boot/dts/qcom-apq8064-asus-nexus7-flo.dts b/arch/arm/boot/dts/qcom-apq8064-asus-nexus7-flo.dts index a701d4bac320..0c126df20417 100644 --- a/arch/arm/boot/dts/qcom-apq8064-asus-nexus7-flo.dts +++ b/arch/arm/boot/dts/qcom-apq8064-asus-nexus7-flo.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { model = "Asus Nexus7(flo)"; compatible = "asus,nexus7-flo", "qcom,apq8064"; @@ -56,6 +57,12 @@ volume_down { }; }; + battery_cell: battery-cell { + compatible = "simple-battery"; + constant-charge-current-max-microamp = <1800000>; + operating-range-celsius = <0 45>; + }; + soc { rpm@108000 { regulators { @@ -296,8 +303,25 @@ eeprom@52 { bq27541@55 { compatible = "ti,bq27541"; reg = <0x55>; + power-supplies = <&power_supply>; + monitored-battery = <&battery_cell>; }; + power_supply: charger@6a { + compatible = "summit,smb345"; + reg = <0x6a>; + + interrupt-parent = <&tlmm_pinmux>; + interrupts = <23 IRQ_TYPE_EDGE_BOTH>; + + summit,chip-temperature-threshold-celsius = <110>; + summit,usb-current-limit-microamp = <500000>; + summit,enable-charge-control = ; + summit,enable-usb-charging; + summit,enable-otg-charging; + + monitored-battery = <&battery_cell>; + }; }; }; From patchwork Thu Aug 13 21:34:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11713035 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0054D13B6 for ; Thu, 13 Aug 2020 21:35:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8F9E206A4 for ; Thu, 13 Aug 2020 21:35:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VoBDyM+t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726768AbgHMVfI (ORCPT ); Thu, 13 Aug 2020 17:35:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726773AbgHMVeo (ORCPT ); Thu, 13 Aug 2020 17:34:44 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31599C061757; Thu, 13 Aug 2020 14:34:44 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id m15so3794365lfp.7; Thu, 13 Aug 2020 14:34:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YV+mrC5kiC7QQYV/FBFX4qMy1dVded4Mn/XHB6H0W0I=; b=VoBDyM+tte4MJ8a9yQorB2SaOnVDp2m49O31ggdeuUOxgsZx/NdLhq0Lqoaza/aDu2 wG8TmQIstDiqk4lLJajdCpj/ybwYDk3jrTLNqAHricGuQR0o/oByfcj9Yd41TH/oSmap +oxIDH2XqJptS6rFqsY+gUp8ePI5Q2uZg6sjDTbgGYxN9fkBU1XaFHdjLGeShR6F3pn+ fTDl2QL2bkosXZrtZMUpaByw39DtX7+wv4AwWdxVfssNHPUiq9+hvFd++KOFL8xFkS1a 1zv7MOcU4SBPk7RdhyN1k0e+7k2OwVXzKppK9kH6YOYUSjk9fXfNLuUzQ08QIP4G0DbH BLeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YV+mrC5kiC7QQYV/FBFX4qMy1dVded4Mn/XHB6H0W0I=; b=mex+ij+MbQJA7twT+a/OYgVEkKOWiNiAYMNysEiMFc62PMrPtDYqXAl+7I1j8ql7LM OeLjOaBF1CuuAzIdl9uvlEYTiKMY7ZCakMZbh+9s/xTXu/GouM5+9jyX34C69ZQ2I06Y lkq/4axaYdQKYb7wFhiezgdKGw/bgk0+0GxgpJssDiFfczy+PDwgzhnA3zvKek0zGn5P FNcNziSl1c16wJ1vMWMDsw+6HUhu/komppWVB7zhOC2AXTFJsBmuLwYvwxBk3a2bWtOv vtWLkNX2zwzu54yrw/jmuGBUFa3jg3anmeG8m66jX8VAn7O3Z+af349YoXUFGgdlix7M /kHA== X-Gm-Message-State: AOAM532NmcbQgbxhiQbpObTgAT8oaFb2nxoJSxTRCs2g39OkloOm49sy lDeYuNzGzjOjqXD2M0LLWJQ7jacm X-Google-Smtp-Source: ABdhPJwXiz7uILUNUhDvRcL8o6/prwxG95Ifu0ZfXuChgZ6XNpf2ZV/Dw7EJODy4vNJYOdKNnPjysg== X-Received: by 2002:a19:8452:: with SMTP id g79mr3227883lfd.29.1597354482652; Thu, 13 Aug 2020 14:34:42 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id j2sm1345309ljb.98.2020.08.13.14.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 14:34:41 -0700 (PDT) From: Dmitry Osipenko To: Sebastian Reichel , Rob Herring , Andy Gross , Bjorn Andersson , David Heidelberg , Thierry Reding , Jonathan Hunter , Mika Westerberg , "Bruce E . Robertson" Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Jonghwa Lee , John Stultz , Vinay Simha BN , linux-tegra@vger.kernel.org Subject: [PATCH v3 10/10] ARM: tegra: nexus7: Add SMB347 battery charger Date: Fri, 14 Aug 2020 00:34:09 +0300 Message-Id: <20200813213409.24222-11-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200813213409.24222-1-digetx@gmail.com> References: <20200813213409.24222-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: David Heidelberg SMB347 is a battery charger controller which is found on the Nexus 7 device. Signed-off-by: David Heidelberg Signed-off-by: Dmitry Osipenko --- .../tegra30-asus-nexus7-grouper-common.dtsi | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/arch/arm/boot/dts/tegra30-asus-nexus7-grouper-common.dtsi b/arch/arm/boot/dts/tegra30-asus-nexus7-grouper-common.dtsi index e2d5fbacf9b4..903457292c04 100644 --- a/arch/arm/boot/dts/tegra30-asus-nexus7-grouper-common.dtsi +++ b/arch/arm/boot/dts/tegra30-asus-nexus7-grouper-common.dtsi @@ -2,6 +2,7 @@ #include #include +#include #include #include "tegra30.dtsi" @@ -919,9 +920,24 @@ nct72: temperature-sensor@4c { #thermal-sensor-cells = <1>; }; - battery@55 { + fuel-gauge@55 { compatible = "ti,bq27541"; reg = <0x55>; + power-supplies = <&power_supply>; + monitored-battery = <&battery_cell>; + }; + + power_supply: charger@6a { + compatible = "summit,smb347"; + reg = <0x6a>; + + interrupt-parent = <&gpio>; + interrupts = ; + + summit,enable-charge-control = ; + summit,enable-usb-charging; + + monitored-battery = <&battery_cell>; }; }; @@ -1011,6 +1027,12 @@ backlight: backlight { default-brightness-level = <15>; }; + battery_cell: battery-cell { + compatible = "simple-battery"; + constant-charge-current-max-microamp = <1800000>; + operating-range-celsius = <0 45>; + }; + /* PMIC has a built-in 32KHz oscillator which is used by PMC */ clk32k_in: clock@0 { compatible = "fixed-clock";