From patchwork Tue Feb 28 22:32:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 657645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FDAFC7EE30 for ; Tue, 28 Feb 2023 22:33:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230072AbjB1Wdm (ORCPT ); Tue, 28 Feb 2023 17:33:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjB1Wde (ORCPT ); Tue, 28 Feb 2023 17:33:34 -0500 Received: from sonic307-7.consmr.mail.ir2.yahoo.com (sonic307-7.consmr.mail.ir2.yahoo.com [87.248.110.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9825223DA0 for ; Tue, 28 Feb 2023 14:33:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1677623606; bh=tgDk+TZQ7fwBqx1EZFVd7dk+gNzKRgzsfoB9HPZliCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=MFgeLyikwgC1V8wNrC30LV5407zKaRwotcMTLmQ9XOUiK95bK5l2fEB1rGacKxL+cbuiInk16TdUGoUVX6YDRJCLTqPs1IBMawFw/3izn+NbVqApwy4ylrjwtwjxTeQMApIs3VRGdcEafHg+u+z12uKfQR3WVsOJRaRAQDVlOEeDK24FB7GPxKVkfMM5us443WWQyVJPQmLMLBATJR+RkszyP6dRjy6p/QpGqiIw529kuWr5/SIiuf+Z5s1j55jkxcyya8y5/CeDKHTcjy+pVuQNyWfk8NFfE2YPWDy2umcOk0o62eXI3vMafC31ZtlCFYbN2oIsQVG3sUJNfEsrgg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1677623606; bh=cuwU/M3pDTaAi42zbzXNOuKnzDT5HnokJR4+BJA3mLc=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=qXaE3LUNH+pHSSsffFA1R1cW4nbnJNf+mjkdQmZPGfLG+h6lLcwn7xMJO5IygmJ38odeR7N7MPL3UQl7E48C2BIOCR4fr4PNUao4/mfpFNr08S7WsR/LsrusUKHqeljoe5CaUcn7TYi87LuROhzpDsoRR498hnB6AuPcjFweZIQiVSMIZ46ALpPmtaZ+ycq2kDAzJaevVQQ1vltcH0T6qCe+QG0/CI97MS4fWiGObtGlXjYq45Tp7F55n0qw7QYsjn8Iv+jxrLYRCnpMZ0KEUNebJ7cjjtxwOflWdYDoj41/XtYxapQjATHZg6DnT9EU0tNfa+miiWU2OfrQZEakZw== X-YMail-OSG: lpR5oDwVM1mkEMrFc1rJ2gJGpYwKBVT9ACE5Evlyd22LPSXUZL_8EGLBZYn1Yu6 c2zM9zRq_5UqP6vYoPfK76mT24dTEeUzaNJNrRxRvO0IKbynGkYn2CpQp0c6QtgmMxhLjbVaS43_ HqzZU3jFBKEFjGt1XlekuTQididgcsTdy0xB7wmsmUjJ3yAEzM8a8QiZ4Ur44exk0prTh07JFy1g qNBQqA5C0o3Qn8OqusBBjBJtcYrZh3nVT_2n.toJzvRdcp073LM5Xnv.iu_gTUZDRUvw0ia5ti8A OILqSa.UQiGDuOKrba5BeLefgxKfhL1a4zITAWVntuDpo2zDuLSOcDA6fz3UxHEaXtICs3RuyICH 00bxiYKExm4ABcy2wvJaZ0be6z9CBtgk5EoyBejUgNeLaQ4RnSDIPJ3cuiY7gaI3MnkJyelX.OWi ibvvUn5vzSLC_QDcdu5Qpnc3FB5tUEQ_zieqLJGLfz3_oidXzX8LhUQfazeH36fNoUBdG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mIGNtIZfqQuHjQjq9EPRKWmGZEyUSikypPEcFfsWWCD15Jail qcvApA_D9xNW5EdrW9TFZM1wjsBiyHNdIUMbLmkiA6TozbgxYNeK2Lwb.I_dKrwmmtlRfR7kA2X0 zN2zJdc7vMdoOMCnEASFsRc0BDszqYA7geHAtzLEAigkXwsOskKYpSLyQVYPORa7TT76ArGSKlmr vSaSQu3_ZMNoMAPXT9Mr_uR7AokDWVyCvsa6pf1rtUXoERGhjpEsGB.YHKRycIFGJQ747VlAs1qz kS88JoskC_Ttib4rx2XEAuWAR.n0od1Wi4rTPVYooz07b3jhdml9AE5dNioYpStktfPxSKPAv7qm 9Xs86Zk8G_mkj7eWRpXufQhyZ7jui87eiCueo64PobzGygddd3YVcFpsvfRpqXHXjkav6QnOuIq3 rGTu8O7xrvd7sdPW1uELJYwZo3vH1_1fE_qhj7yMN98sv1HR8JplEXwLyBlcaeP4_FgtIDi8CbkD nCfq6LkpdW.RNQk1W2GnKm7pRzodsbGu7ZWjbI1P9H1Bx5GRCVkkhMvPMWKzvJOZqZ5kTNX2HYmB vUf63fT6AVXoTmWF1e0I3qGf.cD6HG.etF3Q3Z3qPnmDiDtsHl5YOg_p71yGweMqU.idDn6cQ6qp NF7lB5qZtlCK.WPRwdvTyHj6PEeKwAIfoHn0Irw2PFLQ5JrMgZp1LSOFsG25E47d_GgwzNC3skAC KHa3q.pAvkOfrgI2O_FsfU_r1ECnWmoI4W9pw0xoeqJNEVQ-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic307.consmr.mail.ir2.yahoo.com with HTTP; Tue, 28 Feb 2023 22:33:26 +0000 Received: by hermes--production-ir2-65c64dfd66-lx9xq (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 4362ede20d54ad479836919fc460cee8; Tue, 28 Feb 2023 22:33:21 +0000 (UTC) From: Jakob Hauser To: Sebastian Reichel , Lee Jones , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski Cc: Beomho Seo , Chanwoo Choi , Stephan Gerhold , Raymond Hackley , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH 02/10] mfd: rt5033: Fix chip revision readout Date: Tue, 28 Feb 2023 23:32:19 +0100 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org After reading the data from the DEVICE_ID register, mask 0x0f needs to be applied to extract the revision of the chip [1]. The other part of the DEVICE_ID register, mask 0xf0, is a vendor identification code. That's how it is set up at similar products of Richtek, e.g. RT9455 [2] page 21 top. [1] https://github.com/msm8916-mainline/linux-downstream/blob/GT-I9195I/drivers/mfd/rt5033_core.c#L484 [2] https://www.richtek.com/assets/product_file/RT9455/DS9455-00.pdf Signed-off-by: Jakob Hauser --- drivers/mfd/rt5033.c | 8 +++++--- include/linux/mfd/rt5033-private.h | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/mfd/rt5033.c b/drivers/mfd/rt5033.c index 8029d444b794..d32467174cb5 100644 --- a/drivers/mfd/rt5033.c +++ b/drivers/mfd/rt5033.c @@ -55,7 +55,8 @@ static const struct regmap_config rt5033_regmap_config = { static int rt5033_i2c_probe(struct i2c_client *i2c) { struct rt5033_dev *rt5033; - unsigned int dev_id; + unsigned int data; + unsigned int chip_rev; int ret; rt5033 = devm_kzalloc(&i2c->dev, sizeof(*rt5033), GFP_KERNEL); @@ -73,12 +74,13 @@ static int rt5033_i2c_probe(struct i2c_client *i2c) return PTR_ERR(rt5033->regmap); } - ret = regmap_read(rt5033->regmap, RT5033_REG_DEVICE_ID, &dev_id); + ret = regmap_read(rt5033->regmap, RT5033_REG_DEVICE_ID, &data); if (ret) { dev_err(&i2c->dev, "Device not found\n"); return -ENODEV; } - dev_info(&i2c->dev, "Device found Device ID: %04x\n", dev_id); + chip_rev = data & RT5033_CHIP_REV_MASK; + dev_info(&i2c->dev, "Device found (rev. %d)\n", chip_rev); ret = regmap_add_irq_chip(rt5033->regmap, rt5033->irq, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, diff --git a/include/linux/mfd/rt5033-private.h b/include/linux/mfd/rt5033-private.h index 2d1895c3efbf..d18cd4572208 100644 --- a/include/linux/mfd/rt5033-private.h +++ b/include/linux/mfd/rt5033-private.h @@ -71,6 +71,10 @@ enum rt5033_reg { /* RT5033 CHGCTRL2 register */ #define RT5033_CHGCTRL2_CV_MASK 0xfc +/* RT5033 DEVICE_ID register */ +#define RT5033_VENDOR_ID_MASK 0xf0 +#define RT5033_CHIP_REV_MASK 0x0f + /* RT5033 CHGCTRL3 register */ #define RT5033_CHGCTRL3_CFO_EN_MASK 0x40 #define RT5033_CHGCTRL3_TIMER_MASK 0x38 From patchwork Tue Feb 28 22:32:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 657644 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 108A6C64EC4 for ; Tue, 28 Feb 2023 22:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230036AbjB1Wdn (ORCPT ); Tue, 28 Feb 2023 17:33:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229947AbjB1Wdl (ORCPT ); Tue, 28 Feb 2023 17:33:41 -0500 Received: from sonic304-23.consmr.mail.ir2.yahoo.com (sonic304-23.consmr.mail.ir2.yahoo.com [77.238.179.148]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72A9223126 for ; Tue, 28 Feb 2023 14:33:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1677623608; bh=FbVYddpsZyZOwFt1hKP1uV44/imXC63D+WJnMDA/Y8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=MmsDo9sxW1kt9LCo8hONulayMmxkVqWrNG9JFuWr3LOm1QOktSPS+VpeUcHKn3J0ODRPE+7U/3hP2I/mUJxgksq+pZaufkCCXeysBJGjp6qaZJH+vKYvxR2H97CGukpJuhVRcTY8uJ8lRn+R7BlOJj0226DXIxAw28gJV3MxJyURjzZ9risDdbeWYMWsiN3Dtm8xgvkrj8eAwSzbUtK6g3nZflfOJGFIoJL9XPFVyLLUctorhU7K4raA4FvYxPKRbraXUULoM0+ZN0jUxyFPHSxZzbwqOgg6jCCPBDDy7MJeLns/zscbQuOkNr3sKjQB5SI686CJqUSwZSVVR2c0vQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1677623608; bh=YamGTgELO1bXYBSaWwTaMGBBLHmCM60U3zDykLCNPz2=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=UbCk3ur0Reh7ULQ4No4s9SSF/nPyM1a8EhfH++3HnxuJorQgYY18AVTy011kQKKxLo8e8gWeezFJUTXx3zdO1NarWpcXwV6MUzER+v3XaHmPRil3qYGDt8YaIZoYIGt1f95mUMjC6gDRny2nHxNqTEozB98qijsWKj7fGhCokjRuvpK2ugQYBaw+SxGYa8f1jRarEWCSjpjuJGgpo2g4bfIXEhVdx6Ptba04ivoiZq/Zqc3J6+DvXK7L4WvRN/F4jl0K0fcw+SIlCha83rdwbsqiegetnOY8MpfLsPZb1A1XO8w42+CxaRF4gFEkmrP3FAGXCXsDLlpazYqJy9fp6A== X-YMail-OSG: F1gSIZUVM1kaNk8M2Cu40BJD8C_87G1.9NuQerxZjL1uCrU6omdSMcQtCxZVNU. VZGSUCVxa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PnhjhxH0MG8SYPERE1BpKZhMpNq0y2hVQiH9JGOMEBc mFmJoi1NjR1Na7qw_hs4mu.NWAIK7W2HOFHldhjnNHy9hAdJrCu8s6KV35jmDaBWZZ.VGDIrb4ya Tk_5rvd_W5j0M_OkzPCvb27BBdEc0OFPVeO0U5f2YH5gy0XI- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ir2.yahoo.com with HTTP; Tue, 28 Feb 2023 22:33:28 +0000 Received: by hermes--production-ir2-65c64dfd66-lx9xq (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 4362ede20d54ad479836919fc460cee8; Tue, 28 Feb 2023 22:33:24 +0000 (UTC) From: Jakob Hauser To: Sebastian Reichel , Lee Jones , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski Cc: Beomho Seo , Chanwoo Choi , Stephan Gerhold , Raymond Hackley , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH 05/10] mfd: rt5033: Apply preparatory changes before adding rt5033-charger driver Date: Tue, 28 Feb 2023 23:32:22 +0100 Message-Id: <4edfef7fdf129185355d4dd2d3928d63c04bac73.1677620677.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Order the register blocks to have the masks in descending manner. Add new defines for constant voltage shift (RT5033_CHGCTRL2_CV_SHIFT), MIVR mask (RT5033_CHGCTRL4_MIVR_MASK), pre-charge current shift (RT5033_CHGCTRL4_IPREC_SHIFT), internal timer disable (RT5033_INT_TIMER_DISABLE), termination disable (RT5033_TE_DISABLE), CFO disable (RT5033_CFO_DISABLE), UUG disable (RT5033_CHARGER_UUG_DISABLE). The fast charge timer type needs to be written on mask 0x38 (RT5033_CHGCTRL3_TIMER_MASK). To avoid a bit shift on application, change the values of the timer types to fit the mask. Added the timout duration as a comment. And the timer between TIMER8 and TIMER12 is most likely TIMER10, see e.g. RT5036 [1] page 28 bottom. Add value options for MIVR (Minimum Input Voltage Regulation). Move RT5033_TE_ENABLE_MASK to the block "RT5033 CHGCTRL1 register", in order to have the masks of the register collected there. To fit the naming scheme, rename it to RT5033_CHGCTRL1_TE_EN_MASK. Move RT5033_CHG_MAX_CURRENT to the block "RT5033 charger fast-charge current". Add new defines RT5033_CV_MAX_VOLTAGE and RT5033_CHG_MAX_PRE_CURRENT to the blocks "RT5033 charger constant charge voltage" and "RT5033 charger pre-charge current limits". In include/linux/mfd/rt5033.h, turn power_supply "psy" into a pointer in order to use it in devm_power_supply_register(). [1] https://media.digikey.com/pdf/Data%20Sheets/Richtek%20PDF/RT5036%20%20Preliminary.pdf Signed-off-by: Jakob Hauser --- include/linux/mfd/rt5033-private.h | 53 ++++++++++++++++++++---------- include/linux/mfd/rt5033.h | 2 +- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/include/linux/mfd/rt5033-private.h b/include/linux/mfd/rt5033-private.h index b6773ebf4e6b..0221f806d139 100644 --- a/include/linux/mfd/rt5033-private.h +++ b/include/linux/mfd/rt5033-private.h @@ -55,22 +55,24 @@ enum rt5033_reg { }; /* RT5033 Charger state register */ +#define RT5033_CHG_STAT_TYPE_MASK 0x60 +#define RT5033_CHG_STAT_TYPE_PRE 0x20 +#define RT5033_CHG_STAT_TYPE_FAST 0x60 #define RT5033_CHG_STAT_MASK 0x30 #define RT5033_CHG_STAT_DISCHARGING 0x00 #define RT5033_CHG_STAT_FULL 0x10 #define RT5033_CHG_STAT_CHARGING 0x20 #define RT5033_CHG_STAT_NOT_CHARGING 0x30 -#define RT5033_CHG_STAT_TYPE_MASK 0x60 -#define RT5033_CHG_STAT_TYPE_PRE 0x20 -#define RT5033_CHG_STAT_TYPE_FAST 0x60 /* RT5033 CHGCTRL1 register */ #define RT5033_CHGCTRL1_IAICR_MASK 0xe0 -#define RT5033_CHGCTRL1_MODE_MASK 0x01 +#define RT5033_CHGCTRL1_TE_EN_MASK 0x08 #define RT5033_CHGCTRL1_HZ_MASK 0x02 +#define RT5033_CHGCTRL1_MODE_MASK 0x01 /* RT5033 CHGCTRL2 register */ #define RT5033_CHGCTRL2_CV_MASK 0xfc +#define RT5033_CHGCTRL2_CV_SHIFT 0x02 /* RT5033 DEVICE_ID register */ #define RT5033_VENDOR_ID_MASK 0xf0 @@ -82,14 +84,15 @@ enum rt5033_reg { #define RT5033_CHGCTRL3_TIMER_EN_MASK 0x01 /* RT5033 CHGCTRL4 register */ -#define RT5033_CHGCTRL4_EOC_MASK 0x07 +#define RT5033_CHGCTRL4_MIVR_MASK 0xe0 #define RT5033_CHGCTRL4_IPREC_MASK 0x18 +#define RT5033_CHGCTRL4_IPREC_SHIFT 0x03 +#define RT5033_CHGCTRL4_EOC_MASK 0x07 /* RT5033 CHGCTRL5 register */ -#define RT5033_CHGCTRL5_VPREC_MASK 0x0f #define RT5033_CHGCTRL5_ICHG_MASK 0xf0 #define RT5033_CHGCTRL5_ICHG_SHIFT 0x04 -#define RT5033_CHG_MAX_CURRENT 0x0d +#define RT5033_CHGCTRL5_VPREC_MASK 0x0f /* RT5033 RT CTRL1 register */ #define RT5033_RT_CTRL1_UUG_MASK 0x02 @@ -128,20 +131,28 @@ enum rt5033_reg { #define RT5033_AICR_1500_MODE 0xc0 #define RT5033_AICR_2000_MODE 0xe0 -/* RT5033 use internal timer need to set time */ -#define RT5033_FAST_CHARGE_TIMER4 0x00 -#define RT5033_FAST_CHARGE_TIMER6 0x01 -#define RT5033_FAST_CHARGE_TIMER8 0x02 -#define RT5033_FAST_CHARGE_TIMER9 0x03 -#define RT5033_FAST_CHARGE_TIMER12 0x04 -#define RT5033_FAST_CHARGE_TIMER14 0x05 -#define RT5033_FAST_CHARGE_TIMER16 0x06 +/* RT5033 charger minimum input voltage regulation */ +#define RT5033_CHARGER_MIVR_DISABLE 0x00 +#define RT5033_CHARGER_MIVR_4200MV 0x20 +#define RT5033_CHARGER_MIVR_4300MV 0x40 +#define RT5033_CHARGER_MIVR_4400MV 0x60 +#define RT5033_CHARGER_MIVR_4500MV 0x80 +#define RT5033_CHARGER_MIVR_4600MV 0xa0 +#define RT5033_CHARGER_MIVR_4700MV 0xc0 +#define RT5033_CHARGER_MIVR_4800MV 0xe0 +/* RT5033 use internal timer need to set time */ +#define RT5033_FAST_CHARGE_TIMER4 0x00 /* 4 hrs */ +#define RT5033_FAST_CHARGE_TIMER6 0x08 /* 6 hrs */ +#define RT5033_FAST_CHARGE_TIMER8 0x10 /* 8 hrs */ +#define RT5033_FAST_CHARGE_TIMER10 0x18 /* 10 hrs */ +#define RT5033_FAST_CHARGE_TIMER12 0x20 /* 12 hrs */ +#define RT5033_FAST_CHARGE_TIMER14 0x28 /* 14 hrs */ +#define RT5033_FAST_CHARGE_TIMER16 0x30 /* 16 hrs */ + +#define RT5033_INT_TIMER_DISABLE 0x00 #define RT5033_INT_TIMER_ENABLE 0x01 -/* RT5033 charger termination enable mask */ -#define RT5033_TE_ENABLE_MASK 0x08 - /* * RT5033 charger opa mode. RT5033 has two opa modes for OTG: charger mode * and boost mode. @@ -150,25 +161,30 @@ enum rt5033_reg { #define RT5033_BOOST_MODE 0x01 /* RT5033 charger termination enable */ +#define RT5033_TE_DISABLE 0x00 #define RT5033_TE_ENABLE 0x08 /* RT5033 charger CFO enable */ +#define RT5033_CFO_DISABLE 0x00 #define RT5033_CFO_ENABLE 0x40 /* RT5033 charger constant charge voltage (as in CHGCTRL2 register), uV */ #define RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MIN 3650000U #define RT5033_CHARGER_CONST_VOLTAGE_STEP_NUM 25000U #define RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MAX 4400000U +#define RT5033_CV_MAX_VOLTAGE 0x1e /* RT5033 charger pre-charge current limits (as in CHGCTRL4 register), uA */ #define RT5033_CHARGER_PRE_CURRENT_LIMIT_MIN 350000U #define RT5033_CHARGER_PRE_CURRENT_STEP_NUM 100000U #define RT5033_CHARGER_PRE_CURRENT_LIMIT_MAX 650000U +#define RT5033_CHG_MAX_PRE_CURRENT 0x03 /* RT5033 charger fast-charge current (as in CHGCTRL5 register), uA */ #define RT5033_CHARGER_FAST_CURRENT_MIN 700000U #define RT5033_CHARGER_FAST_CURRENT_STEP_NUM 100000U #define RT5033_CHARGER_FAST_CURRENT_MAX 2000000U +#define RT5033_CHG_MAX_CURRENT 0x0d /* * RT5033 charger const-charge end of charger current ( @@ -192,6 +208,7 @@ enum rt5033_reg { * RT5033 charger UUG. It enables MOS auto control by H/W charger * circuit. */ +#define RT5033_CHARGER_UUG_DISABLE 0x00 #define RT5033_CHARGER_UUG_ENABLE 0x02 /* RT5033 charger high impedance mode */ diff --git a/include/linux/mfd/rt5033.h b/include/linux/mfd/rt5033.h index 8f306ac15a27..e99e2ab0c1c1 100644 --- a/include/linux/mfd/rt5033.h +++ b/include/linux/mfd/rt5033.h @@ -51,7 +51,7 @@ struct rt5033_charger_data { struct rt5033_charger { struct device *dev; struct rt5033_dev *rt5033; - struct power_supply psy; + struct power_supply *psy; struct rt5033_charger_data *chg; }; From patchwork Tue Feb 28 22:32:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 657643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 722F4C7EE31 for ; Tue, 28 Feb 2023 22:38:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229771AbjB1Wi4 (ORCPT ); Tue, 28 Feb 2023 17:38:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbjB1Wiy (ORCPT ); Tue, 28 Feb 2023 17:38:54 -0500 Received: from sonic309-25.consmr.mail.ir2.yahoo.com (sonic309-25.consmr.mail.ir2.yahoo.com [77.238.179.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9341B16ACE for ; Tue, 28 Feb 2023 14:38:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1677623931; bh=AI+0hvjdKYfuB0QkdFl88NWEQ2qielkjcdN5HypZVtY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=K+bYtng/VdIfpwNTdozQJArlLgcN/9aT9bl9/AkvLCmy4lpmGJcczzb6OVjP+9x1nueDQuOeUq1Lhbxsgia0NiQh3gwS05Qix4czhY8jFO8ZCXzOgCDZl/Nhoaqepe9R9x4BGhBG7PhDfyDwCN4EEL1lndMPgg16VGzeW1NH3LSUhRAk6wQbaAE30Hsm9aVEx3v0TznGvGltFLYJOZTGgu40zCiCEtXB1+8IUc9zK/CuKNoHKubTC1iSyuCNAi7ZCexA4jM5Wf5yIbYA7vLwj/9Uxk/gfohN4iiAme94FjiArgcAJvaRdDrLmyW1SxFwKGo4s4EDsmmfaNp7uEJDWQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1677623931; bh=GUg78fiVwK5rF01aTpoXztZE69VaZmSMSXH83LLhrrx=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=nMgS7P3EpkqAFAueYtG50Jio2L2E9lgRKKAbcmlY/Y7HxpyvJH6q72byhQ0DiAk4lfGdUoS/Z8EPDo2frdswAmxu7yX18Pz1Rp35fQLMKQ8/00lIVjGvq8pNRJ4tbwOnj2XqJ4zpoheLFCyejbvwe9yu0oVPLCxv/Zu0ijdnHzIzeD8dqnpVqKHOKshGZ04MQvanGAMRmDubksPXluBmjV4j4TiWk62SuVs8YqGfgupf35+tqjQYIULJFiQ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PT_ulC43 qdCP4xz1hNIVmWDP886lZiaJSM1eQaFzIW5n9XWnqEwDi6IfllTN6CenD3ZGm3a8IhrHiTHHr8rQ laavLr3ZHr9F.pPpj7QP50_pD4bdP7XWzsfTAynPBQwJr.Q9eIOKE2ZOOdLkyzekNtJzMcfj06Dr sJSABvR1U2Db0Fiw0oxmRdRWPQMFE7tFr.5UUAIBrzCkYG0q8o2AnbfGc3wlLDUjvnXs0MSimleo 2N.QSQmdQIqL31qYpzer17t5M4rseTilBWPdcCte7y7_igEtSsGIof2liRnhBGpRbGXoM9zH.eLg CMMuXTlh1Yict1ykzTElm9DgCJCiRHdZ0gEdXY93P6fv9QdGlbe4w X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ir2.yahoo.com with HTTP; Tue, 28 Feb 2023 22:38:51 +0000 Received: by hermes--production-ir2-65c64dfd66-svnc4 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 1052c26ec2388683ab738a7f87fce466; Tue, 28 Feb 2023 22:38:48 +0000 (UTC) From: Jakob Hauser To: Sebastian Reichel , Lee Jones , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski Cc: Beomho Seo , Chanwoo Choi , Stephan Gerhold , Raymond Hackley , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH 07/10] power: supply: rt5033_charger: Add cable detection and USB OTG supply Date: Tue, 28 Feb 2023 23:32:24 +0100 Message-Id: <4ec6fa3f1b2f4a96267771e8f34b12f566bbae06.1677620677.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Implement cable detection by extcon and handle the driver according to the connector type. There are basically three types of action: "set_charging", "set_otg" and "set_disconnect". A forth helper function to "unset_otg" was added because this is used in both "set_charging" and "set_disconnect". In the first case it covers the rather rare event that someone changes from OTG to charging without disconnect. In the second case, when disconnecting, the values are set back to the ones from initialization to return into a defined state. Additionally, there is "set_mivr". When connecting to e.g. a laptop/PC, the minimum input voltage regulation (MIVR) shall prevent a voltage drop if the cable or the supply is weak. The MIVR value is set to 4600MV, same as in the Android driver [1]. When disconnecting, MIVR is set back to DISABLED. In the function rt5033_get_charger_state(): When in OTG mode, the chip reports status "charging". Change this to "discharging" because there is no charging going on in OTG mode [2]. [1] https://github.com/msm8916-mainline/linux-downstream/blob/GT-I9195I/drivers/battery/rt5033_charger.c#L499 [2] https://github.com/msm8916-mainline/linux-downstream/blob/GT-I9195I/drivers/battery/rt5033_charger.c#L686-L687 Tested-by: Raymond Hackley Signed-off-by: Jakob Hauser --- drivers/power/supply/rt5033_charger.c | 265 +++++++++++++++++++++++++- include/linux/mfd/rt5033.h | 8 + 2 files changed, 271 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/rt5033_charger.c b/drivers/power/supply/rt5033_charger.c index 6bb3d45a5e9e..79e7f75fe634 100644 --- a/drivers/power/supply/rt5033_charger.c +++ b/drivers/power/supply/rt5033_charger.c @@ -10,7 +10,10 @@ * published by the Free Software Foundation. */ +#include +#include #include +#include #include #include #include @@ -44,6 +47,10 @@ static int rt5033_get_charger_state(struct rt5033_charger *charger) state = POWER_SUPPLY_STATUS_UNKNOWN; } + /* For OTG mode, RT5033 would still report "charging" */ + if (charger->otg) + state = POWER_SUPPLY_STATUS_DISCHARGING; + return state; } @@ -132,6 +139,9 @@ static inline int rt5033_init_const_charge(struct rt5033_charger *charger) return -EINVAL; } + /* Store that value for later usage */ + charger->cv_regval = reg_data; + /* Set end of charge current */ if (chg->eoc_uamp < RT5033_CHARGER_EOC_MIN || chg->eoc_uamp > RT5033_CHARGER_EOC_MAX) @@ -303,6 +313,152 @@ static int rt5033_charger_reg_init(struct rt5033_charger *charger) return 0; } +static int rt5033_charger_set_otg(struct rt5033_charger *charger) +{ + int ret; + + mutex_lock(&charger->lock); + + /* Set OTG boost v_out to 5 volts */ + ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL2, + RT5033_CHGCTRL2_CV_MASK, + 0x37 << RT5033_CHGCTRL2_CV_SHIFT); + if (ret) { + dev_err(charger->dev, "Failed set OTG boost v_out\n"); + return -EINVAL; + } + + /* Set operation mode to OTG */ + ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL1, + RT5033_CHGCTRL1_MODE_MASK, RT5033_BOOST_MODE); + if (ret) { + dev_err(charger->dev, "Failed to update OTG mode.\n"); + return -EINVAL; + } + + /* In case someone switched from charging to OTG directly */ + if (charger->online) + charger->online = false; + + charger->otg = true; + + mutex_unlock(&charger->lock); + + return 0; +} + +static int rt5033_charger_unset_otg(struct rt5033_charger *charger) +{ + int ret; + u8 data; + + /* Restore constant voltage for charging */ + data = charger->cv_regval; + ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL2, + RT5033_CHGCTRL2_CV_MASK, + data << RT5033_CHGCTRL2_CV_SHIFT); + if (ret) { + dev_err(charger->dev, "Failed to restore constant voltage\n"); + return -EINVAL; + } + + /* Set operation mode to charging */ + ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL1, + RT5033_CHGCTRL1_MODE_MASK, RT5033_CHARGER_MODE); + if (ret) { + dev_err(charger->dev, "Failed to update charger mode.\n"); + return -EINVAL; + } + + charger->otg = false; + + return 0; +} + +static int rt5033_charger_set_charging(struct rt5033_charger *charger) +{ + int ret; + + mutex_lock(&charger->lock); + + /* In case someone switched from OTG to charging directly */ + if (charger->otg) { + ret = rt5033_charger_unset_otg(charger); + if (ret) + return -EINVAL; + } + + charger->online = true; + + mutex_unlock(&charger->lock); + + return 0; +} + +static int rt5033_charger_set_mivr(struct rt5033_charger *charger) +{ + int ret; + + mutex_lock(&charger->lock); + + /* + * When connected via USB connector type SDP (Standard Downstream Port), + * the minimum input voltage regulation (MIVR) should be enabled. It + * prevents an input voltage drop due to insufficient current provided + * by the adapter or USB input. As a downside, it may reduces the + * charging current and thus slows the charging. + */ + ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL4, + RT5033_CHGCTRL4_MIVR_MASK, RT5033_CHARGER_MIVR_4600MV); + if (ret) { + dev_err(charger->dev, "Failed to set MIVR level.\n"); + return -EINVAL; + } + + charger->mivr_enabled = true; + + mutex_unlock(&charger->lock); + + /* Beyond this, do the same steps like setting charging */ + rt5033_charger_set_charging(charger); + + return 0; +} + +static int rt5033_charger_set_disconnect(struct rt5033_charger *charger) +{ + int ret; + + mutex_lock(&charger->lock); + + /* Disable MIVR if enabled */ + if (charger->mivr_enabled) { + ret = regmap_update_bits(charger->rt5033->regmap, + RT5033_REG_CHG_CTRL4, + RT5033_CHGCTRL4_MIVR_MASK, + RT5033_CHARGER_MIVR_DISABLE); + if (ret) { + dev_err(charger->dev, "Failed to disable MIVR.\n"); + return -EINVAL; + } + + charger->mivr_enabled = false; + } + + if (charger->otg) { + ret = rt5033_charger_unset_otg(charger); + if (ret) + return -EINVAL; + } + + if (charger->online) + charger->online = false; + + mutex_unlock(&charger->lock); + + return 0; +} + static enum power_supply_property rt5033_charger_props[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_CHARGE_TYPE, @@ -340,8 +496,7 @@ static int rt5033_charger_get_property(struct power_supply *psy, val->strval = RT5033_MANUFACTURER; break; case POWER_SUPPLY_PROP_ONLINE: - val->intval = (rt5033_get_charger_state(charger) == - POWER_SUPPLY_STATUS_CHARGING); + val->intval = charger->online; break; default: return -EINVAL; @@ -391,6 +546,86 @@ static struct rt5033_charger_data *rt5033_charger_dt_init( return chg; } +static void rt5033_charger_extcon_work(struct work_struct *work) +{ + struct rt5033_charger *charger = + container_of(work, struct rt5033_charger, extcon_work); + struct extcon_dev *edev = charger->edev; + int connector, state; + int ret; + + for (connector = EXTCON_USB_HOST; connector <= EXTCON_CHG_USB_PD; + connector++) { + state = extcon_get_state(edev, connector); + if (state == 1) + break; + } + + /* + * Adding a delay between extcon notification and extcon action. This + * makes extcon action execution more reliable. Without the delay the + * execution sometimes fails, possibly because the chip is busy or not + * ready. + */ + msleep(100); + + switch (connector) { + case EXTCON_CHG_USB_SDP: + ret = rt5033_charger_set_mivr(charger); + if (ret) { + dev_err(charger->dev, "failed to set USB mode\n"); + break; + } + dev_info(charger->dev, "USB mode. connector type: %d\n", + connector); + break; + case EXTCON_CHG_USB_DCP: + case EXTCON_CHG_USB_CDP: + case EXTCON_CHG_USB_ACA: + case EXTCON_CHG_USB_FAST: + case EXTCON_CHG_USB_SLOW: + case EXTCON_CHG_WPT: + case EXTCON_CHG_USB_PD: + ret = rt5033_charger_set_charging(charger); + if (ret) { + dev_err(charger->dev, "failed to set charging\n"); + break; + } + dev_info(charger->dev, "charging. connector type: %d\n", + connector); + break; + case EXTCON_USB_HOST: + ret = rt5033_charger_set_otg(charger); + if (ret) { + dev_err(charger->dev, "failed to set OTG\n"); + break; + } + dev_info(charger->dev, "OTG enabled\n"); + break; + default: + ret = rt5033_charger_set_disconnect(charger); + if (ret) { + dev_err(charger->dev, "failed to set disconnect\n"); + break; + } + dev_info(charger->dev, "disconnected\n"); + break; + } + + power_supply_changed(charger->psy); +} + +static int rt5033_charger_extcon_notifier(struct notifier_block *nb, + unsigned long event, void *param) +{ + struct rt5033_charger *charger = + container_of(nb, struct rt5033_charger, extcon_nb); + + schedule_work(&charger->extcon_work); + + return NOTIFY_OK; +} + static const struct power_supply_desc rt5033_charger_desc = { .name = "rt5033-charger", .type = POWER_SUPPLY_TYPE_USB, @@ -413,6 +648,7 @@ static int rt5033_charger_probe(struct platform_device *pdev) platform_set_drvdata(pdev, charger); charger->dev = &pdev->dev; charger->rt5033 = rt5033; + mutex_init(&charger->lock); charger->chg = rt5033_charger_dt_init(pdev); if (IS_ERR_OR_NULL(charger->chg)) @@ -433,6 +669,31 @@ static int rt5033_charger_probe(struct platform_device *pdev) return PTR_ERR(charger->psy); } + /* + * Extcon support is not vital for the charger to work. If no extcon + * is available, just emit a warning and leave the probe function. + */ + charger->edev = extcon_get_edev_by_phandle(&pdev->dev, 0); + if (IS_ERR(charger->edev)) { + dev_warn(&pdev->dev, "no extcon phandle found in device-tree\n"); + goto out; + } + + ret = devm_work_autocancel(&pdev->dev, &charger->extcon_work, + rt5033_charger_extcon_work); + if (ret) { + dev_err(&pdev->dev, "failed to initialize extcon work\n"); + return ret; + } + + charger->extcon_nb.notifier_call = rt5033_charger_extcon_notifier; + ret = devm_extcon_register_notifier_all(&pdev->dev, charger->edev, + &charger->extcon_nb); + if (ret) { + dev_err(&pdev->dev, "failed to register extcon notifier\n"); + return ret; + } +out: return 0; } diff --git a/include/linux/mfd/rt5033.h b/include/linux/mfd/rt5033.h index e99e2ab0c1c1..d2c613764756 100644 --- a/include/linux/mfd/rt5033.h +++ b/include/linux/mfd/rt5033.h @@ -53,6 +53,14 @@ struct rt5033_charger { struct rt5033_dev *rt5033; struct power_supply *psy; struct rt5033_charger_data *chg; + struct extcon_dev *edev; + struct notifier_block extcon_nb; + struct work_struct extcon_work; + struct mutex lock; + bool online; + bool otg; + bool mivr_enabled; + u8 cv_regval; }; #endif /* __RT5033_H__ */ From patchwork Tue Feb 28 22:32:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 657642 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABEECC7EE30 for ; Tue, 28 Feb 2023 22:39:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229730AbjB1WjB (ORCPT ); Tue, 28 Feb 2023 17:39:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229732AbjB1Wiz (ORCPT ); Tue, 28 Feb 2023 17:38:55 -0500 Received: from sonic302-21.consmr.mail.ir2.yahoo.com (sonic302-21.consmr.mail.ir2.yahoo.com [87.248.110.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3C272069A for ; Tue, 28 Feb 2023 14:38:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1677623932; bh=s32HUPwCKOshIyB3RzDVkjP0uF49xcWO2+tOArORygE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=VigrbbD8aKFhzR97hZhIck1i/JZoKmjNuqqlIYkdawxgM2bALYrg5XHv3kzjLy+MFdth/ams8RdUG62fNEZbh3VND51wJMYty5O9oN2eD1xr40d5cIJ0qbZXFHKxDnNBi4tC3UfvCahYeR84sWbkTyJKzgHQgB0TqF/1ejM1LTqcBD0pHwlhaP4XjG9ENjDAtGSwyD2+llN5RrdJI/Zhcs5usM09h7036wpRrCJ9F1GdxjZJbfJVeJJDchySTTs2fmvqmooncMtH8WTTg51zts2RA0d/t95BTNA1MsX/tPcHVKM5Ig1gBco8u/Mj40BBVBlWc8zJDqut68XCMMQMVg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1677623932; bh=DazgWJ/4JyL16bAVXpPyn+BI5M9Si0HC/6Rq5ZQ296C=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=hTdT9sM6BDIYDYRfEijeoUxODPej0NVXea9647wzjH+E4NK7qR50bjcS5F2Zrg4QqiGs0ExNccc0Rx5d8aLVG+Hodd/OeEg1DJHIpzas659GHI7I4S+vl7YjnhUff6lvSVzFeK0Ef/ErflRzkiijRLKl0IFCLWpl1brfuu1du8wEOSB3BOyppMc76FkO3c3lKiGsH5F7ZlqlpcjeRWzqLd7ru8LSF/Q52pwqmmsfLL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7Z4y0a ZrzdN2PR94kHl4xh57K.iUjvFwISpPYQGgWF07iNF3SecIqx3wsSkM87Fx9AAaEph44uVMCWZa8g SwWlY3Eq3ADySg3Ctc48RTDoNFrJsHkS1iWvipBnUyi43Eli6eDNGdAewM4ytQ8A8q1jDj3EZUuu 17Ix4KHfPohq_PsdZIVfcOPqrIWJFyYKWCxHlkTA7n08cuwq4xGU2UiR6vwNJaNTE_Iv4H29x7Xz 3brrE4wy0mZCnZ_SnDZdk2grj6NxkUla0oAHGvhsT8.K7h1kletjiinZnzDT5PxNRllXIjeo2Dtt pfE2d6CMD.4vswlI4CDvjA.kQxKC3186sgWnCWM0qT1NLjBVvow-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ir2.yahoo.com with HTTP; Tue, 28 Feb 2023 22:38:52 +0000 Received: by hermes--production-ir2-65c64dfd66-svnc4 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 1052c26ec2388683ab738a7f87fce466; Tue, 28 Feb 2023 22:38:50 +0000 (UTC) From: Jakob Hauser To: Sebastian Reichel , Lee Jones , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski Cc: Beomho Seo , Chanwoo Choi , Stephan Gerhold , Raymond Hackley , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH 09/10] power: supply: rt5033_battery: Adopt status property from charger Date: Tue, 28 Feb 2023 23:32:26 +0100 Message-Id: <768faa5609bcf52a97f1f1f71dea6518237b04a0.1677620677.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The rt5033-battery fuelgauge can't get a status by itself. The rt5033-charger can, let's get this value. Tested-by: Raymond Hackley Signed-off-by: Jakob Hauser --- drivers/power/supply/rt5033_battery.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/power/supply/rt5033_battery.c b/drivers/power/supply/rt5033_battery.c index 5c04cf305219..48d4cccce4f6 100644 --- a/drivers/power/supply/rt5033_battery.c +++ b/drivers/power/supply/rt5033_battery.c @@ -12,6 +12,26 @@ #include #include +static int rt5033_battery_get_status(struct i2c_client *client) +{ + struct power_supply *charger; + union power_supply_propval val; + int ret; + + charger = power_supply_get_by_name("rt5033-charger"); + if (!charger) + return -ENODEV; + + ret = power_supply_get_property(charger, POWER_SUPPLY_PROP_STATUS, &val); + if (ret) { + power_supply_put(charger); + return POWER_SUPPLY_STATUS_UNKNOWN; + } + + power_supply_put(charger); + return val.intval; +} + static int rt5033_battery_get_capacity(struct i2c_client *client) { struct rt5033_battery *battery = i2c_get_clientdata(client); @@ -84,6 +104,9 @@ static int rt5033_battery_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_CAPACITY: val->intval = rt5033_battery_get_capacity(battery->client); break; + case POWER_SUPPLY_PROP_STATUS: + val->intval = rt5033_battery_get_status(battery->client); + break; default: return -EINVAL; } @@ -96,6 +119,7 @@ static enum power_supply_property rt5033_battery_props[] = { POWER_SUPPLY_PROP_VOLTAGE_OCV, POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_CAPACITY, + POWER_SUPPLY_PROP_STATUS, }; static const struct regmap_config rt5033_battery_regmap_config = {