From patchwork Sun Apr 16 12:44:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 674061 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 B03F3C77B61 for ; Sun, 16 Apr 2023 12:45:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230269AbjDPMpI (ORCPT ); Sun, 16 Apr 2023 08:45:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230259AbjDPMpG (ORCPT ); Sun, 16 Apr 2023 08:45:06 -0400 Received: from sonic314-19.consmr.mail.ir2.yahoo.com (sonic314-19.consmr.mail.ir2.yahoo.com [77.238.177.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABEAF183 for ; Sun, 16 Apr 2023 05:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1681649102; bh=vcMGH2mB7eHRV3jsyfJ2abjxznWmNhKkivWuWeFmIyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=kaBAC3tyz2euOa7nEJtwnq74GCMk8VlifCkyRAyilRMdgcjqOlECd9pYdp5VVpc1tZ7++pCZHLvjG3I2KfG1eunvoqbHemEmDreJwS6YpOzDMCwpfEdll0/6P+FbUScecDOJkwYed7Fj+rjH8Pq4xElGZFXtWeca0rLs516QrPc9m7VK8xTdRgLm7yKq4Pha6etLAaBMwzTL/ycwlTHkNzCPOR9iihUD41w6VGuGhTQ5IJGSgtUD27ZYvTU3TWLPjEr0UoFHMI9y/7bVFMcBMpUD85wnrEzBB8+0YLZRYOKcn1L2J5Z0L5OAxBt3WbTl+xf2zX5SIiK31rGZrQzfSQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681649102; bh=8ZNE0MQuLwrNNYS0CbBCfLqbwkm0cePeENa4S1PfKW9=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=hRsQx2d8AyRGgmcs/kOmv+M59k8Q9/u8jPqqD03RO+86FVdd0fLOBx/e93EQmesORgV89OolRfVaNAh2o7EfcpBn3xeySTXQoPWd+ec03uoC3I3mOa9VBwHqb+jFHoemuzuQFI3ecVcOzehCB2AdiqC8qOpet7jUR+YNqLOAFkhwwQNKYMD1DQMax8ejBKztx1JnGV+akMR79oZ0XFrvs+pRWRIoOkLElOobbUSngV1xojqoFyRC5ipUntrAn64+5nXgSfRGaaBP9pvo54WUcULWMexKHjiKPHJ5TQ6VcUHOjqE8bvaalOvV6hPIR0qvyGPpoonTtiDzQ7yvDMQXZA== X-YMail-OSG: om7kt2oVM1lj35PrV2MoYBW57IVgfU8uOtqOzmGulUyABjbF4TOc.nzcKzrl8Ab 6wonre8A0VqBenbAvvW89jrNcydIMxk0Sl3g.XX6sSC2nh7C4XY3y0c3oTgAvT4IrvIq4ijTPb0V YpjSOAf1zhazDgfmRgeZuP96I49orFdYpVHe2oBMEUQAhpxNUwF0uGaZeot99nY87iYCwAR5ZLcX sR48RRB2VcCTL7pSncfl7L7NH7Eu2JTeTxbs8UPWZEJqe8N.C3PHeUnLw60yxN941eu_D3osT8XB u.i1knaXrygPTjiJ_CUWBVi.hdAqduhH5yBZNHyMc4K7YiZ_jb_rdxzxKO1r.j6d11z7M7neRutQ OPQ534.mNd1QW8bnca1QVo38TQJJQZ_BLwAbRPirb9gJBK4GA1O7KEd_VdGduALMnYy0J9sqPaoj BwOuofm5286Qm0.q0V5Uk3Uq1R50IwZ4jZ_Ky0GDBKfnuEc5tUGikbdCYlYrN5Z6geteCYFzshpB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P drygj4L3cfTc1Yr4IFkww3kNe0rOL3n.qjfpcrGWO.YH4Lk_u_DDRYxH.EwwxStOUr7f273rPw9U OVbgt4YxjAvnI766P0Pn2whtxdAVXEoR_lS5Ru8R17yTDUX1VdURJgxo9LXmaI0OHEQxssVTDM_5 rqMlqAHxX1bRxNtFKVh5qxhzCtsb8j0RU63ZIBAPFHjJVhVW_sP.sBMZW7Y5x_16VT4FMFU1gfE2 MbtquMdYmfPE3.Chrp0Iu7ydc3DQyp1AgA_1A7Fyu1POfMhC9mDyb1lT0B.4DcTgB1I8.irEVhEI nMwPJPJoiSYi8Id0qEvyOld5oWw.tfUllNh1gJhR3CQIBnZxV0X3NmI.Pea3JjIjeOZ7aPO_ImvK zgyaQua3n.BARPv4zno8JTKTN83jSldWgtWLsKA6daoU7a4dcxPYIcbZ.ZgdDbgvA_tC3rYJWfnX pkTgde7bmb4TZOXS9z.cbNh9NP4rs8jcMZTDryf91KRZEoK8gK81WbKjPHGBkvogYBITknw5hjhZ A1mHXmpdKwnsTm_6dJ5d3H86Swx7greF6VIyKIh.zH5lCYu6pWClXArvPdOo65cLU9o7ZNzNiC1t LFV32NR4GnbiSXI1CbHJfO4obvCMrXLmFKn.6tsmfLonjOuTFPZHznqUUdV0ZBep1ij0BBYQxL2d gz3vRIlT1FUt8SxEOApEUKslUl4BupFHzJTvojDrUwY8a6utskkZgAKWTK9i2GV_3mMbuvAPIcR4 EFsenSqEGC1UfWL9Rx63rkbd5 X-Sonic-MF: X-Sonic-ID: 16ab8e62-c231-4b1a-8c5f-a2517dae839a Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ir2.yahoo.com with HTTP; Sun, 16 Apr 2023 12:45:02 +0000 Received: by hermes--production-ir2-74cd8fc864-4bl68 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8a53f7a8722383f9609d619e4fab1862; Sun, 16 Apr 2023 12:45:01 +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 , Pavel Machek , Axel Lin , ChiYuan Huang , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Lee Jones , Jakob Hauser Subject: [PATCH v2 1/9] mfd: rt5033: Drop rt5033-battery sub-device Date: Sun, 16 Apr 2023 14:44:28 +0200 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Stephan Gerhold The fuel gauge in the RT5033 PMIC (rt5033-battery) has its own I2C bus and interrupt lines. Therefore, it is not part of the MFD device and needs to be specified separately in the device tree. Cc: Beomho Seo Cc: Chanwoo Choi Fixes: 0b271258544b ("mfd: rt5033: Add Richtek RT5033 driver core.") Signed-off-by: Stephan Gerhold Acked-by: Lee Jones Signed-off-by: Jakob Hauser --- drivers/mfd/rt5033.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/mfd/rt5033.c b/drivers/mfd/rt5033.c index a5e520fe50a1..8029d444b794 100644 --- a/drivers/mfd/rt5033.c +++ b/drivers/mfd/rt5033.c @@ -40,9 +40,6 @@ static const struct mfd_cell rt5033_devs[] = { { .name = "rt5033-charger", .of_compatible = "richtek,rt5033-charger", - }, { - .name = "rt5033-battery", - .of_compatible = "richtek,rt5033-battery", }, { .name = "rt5033-led", .of_compatible = "richtek,rt5033-led", From patchwork Sun Apr 16 12:44:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 673681 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 A0E84C77B77 for ; Sun, 16 Apr 2023 12:45:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230431AbjDPMpR (ORCPT ); Sun, 16 Apr 2023 08:45:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230312AbjDPMpM (ORCPT ); Sun, 16 Apr 2023 08:45:12 -0400 Received: from sonic301-21.consmr.mail.ir2.yahoo.com (sonic301-21.consmr.mail.ir2.yahoo.com [77.238.176.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9D0D4685 for ; Sun, 16 Apr 2023 05:45:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1681649106; bh=Fg8O9S7CQWLvLBXMCmKEFeFmz8DxFrOra+7NQGOwBwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=KszPe5nUvNjng6faEv3yoQCb0HsZzD2YGWMLl/YxpjKxzXDXSgY8/SMEOHg81nvlSOQwKPrR0btBR5Uo42mog+ShPLwnLkLJTXjxE3aHterfs7/oVofN9quuRpfbK4dUfw/y1NHLbhqSsdT3/b1Ud3x3JV43YuXknZ9Uc9J2QAhgIkBSaWByxvWcdlyvM5KsbGnt9xhfPe5ztPMWTa65JO2xCliYgPmHkX39gSVBsK/8/8uuX5hi8IBFcwQFnFmfztSCQL2a8t0tJ39DPdYGb25/89dDzHNxC/xs5gKXSIitjG+OsX3/UfmB8j887drF3VlySUSRQ76a8xwJA3GFrA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681649106; bh=PmzEobjZYlreqbgwJRMQ3U9bSsfqaPE/JSDDCP6IjM5=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=FPTF2ZiXdrGn2NabX1D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1i1TQcK2c7rVTV.zKM1ciR.3_oHE0MymP w6Td1y3XZzDI6CEyG_8zsb.QNQrJ1Xt9rIZaZLBgwz14e.i.bKOjXotYLnTIRLrfPsxwyYa8ovQX Ze6d9wHSJuAzMpIv8KvcqJZybbJ_IGC67wGBNICrBFrZCBqeoPeP5X4oN7ukpkBOpmIJBWjqrZoW rOdMii_4MIxzA2M6jB7lY1MAw7BsSdekdIIkeflwSLttVusNlzETwsmknOhXkfmNQrNFFsskwAYW Dj9y6iL0nG6Q9LzoAwOVYmMjjsz4CiHtb5151u78mM2TXT33SWoh99ijkLcFImqWgbKTE1.1oCxd xU4ssssvH9CSbmNmXYgNaifk0fTPPUfEYcp_u8eQcnChYAhb5_xPIIuVHd8PehXiuUh5cSXTjAJ0 NvmmufAezPNg2RZWXLNYeeYGC60KJr2o5wGVQtl36vlR24.5Lcy81Bnqw6xkdjvsrlED1ZNcUIjF CCMTPWgjmnSexjzuXHzj26oqcfMATY.3sfuN1rZ.smrizQnnj6eHatURYV64YTmGYvfCe7FG6jy8 nhCu5JlTaT6xrsXeJ7SfjmMbGOFp77RInhYlCaW01Y_U79EY- X-Sonic-MF: X-Sonic-ID: e071def9-0b1c-4e98-8221-260d1abc3263 Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ir2.yahoo.com with HTTP; Sun, 16 Apr 2023 12:45:06 +0000 Received: by hermes--production-ir2-74cd8fc864-4bl68 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8a53f7a8722383f9609d619e4fab1862; Sun, 16 Apr 2023 12:45:03 +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 , Pavel Machek , Axel Lin , ChiYuan Huang , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v2 2/9] mfd: rt5033: Fix chip revision readout Date: Sun, 16 Apr 2023 14:44:29 +0200 Message-Id: <7eab1fd42adf0428cd80cc2b4c2fb3d928014125.1681646904.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@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 | 5 +++-- include/linux/mfd/rt5033-private.h | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/mfd/rt5033.c b/drivers/mfd/rt5033.c index 8029d444b794..3eee4242ee02 100644 --- a/drivers/mfd/rt5033.c +++ b/drivers/mfd/rt5033.c @@ -55,7 +55,7 @@ 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 dev_id, chip_rev; int ret; rt5033 = devm_kzalloc(&i2c->dev, sizeof(*rt5033), GFP_KERNEL); @@ -78,7 +78,8 @@ static int rt5033_i2c_probe(struct i2c_client *i2c) dev_err(&i2c->dev, "Device not found\n"); return -ENODEV; } - dev_info(&i2c->dev, "Device found Device ID: %04x\n", dev_id); + chip_rev = dev_id & 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 6bb432f6a96c..b035a67cec73 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 Sun Apr 16 12:44:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 674060 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 45BC6C77B79 for ; Sun, 16 Apr 2023 12:45:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230452AbjDPMpT (ORCPT ); Sun, 16 Apr 2023 08:45:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230400AbjDPMpP (ORCPT ); Sun, 16 Apr 2023 08:45:15 -0400 Received: from sonic314-19.consmr.mail.ir2.yahoo.com (sonic314-19.consmr.mail.ir2.yahoo.com [77.238.177.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D2564EED for ; Sun, 16 Apr 2023 05:45:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1681649107; bh=BgnxKccDW0hD4wBKD/wGrzdwGz4y7GQfSjWtC1jgF84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=WrGLvDI03t9ixKW8BXIrR4+Q+gua8L8MuaHIr2+gMD89i+nyI1OEfFhrZl3i5YxMJgnTV/IUgOH7pO1Ifz9piZ0BfdbF0A9KGyFMzfF58FOYCX17f5iUvx4uUYTdNN0XLjw5bF4pxG934CqBLExiiFMIV+W/wDhLdziZJDrzpw+F09wvScBeZriuhLB06wx21dbBnOfwafDFbYTqF+aU10/sQ4mXlXn20MBtDNFPD3iVtBTOotmFZB/J45ujSTcmGGJ+UObRf94vhurMK179l4Kljul8rDPUgjrC5LupBYYLluOToOWf54z27ik/UYeXmOlQ5PuSgor9DxOO9F1hWA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681649107; bh=NW+YohgAJIbbu+CgcHo6KoDs37jn6lf4CpBsx9o0SLx=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=dJUlraXL6u+S2u75PB06KZo/r+CbL253gXEzSZC5EisMN4m0wm7nU8Ygj5wyRGEPo4yhCp81iBEIlvmCdJ1KOrpRhc5nuiCy067OltLrfIeDAozDwFmM6GsOnjTBshwokQmw05Yup91ycGP7Ykfb16UBN7QSnVTuuGIgV96HsggZptUu8LhU6PJoOhEX3WagkU3tkpHpyIbnng8GuDqT4XqsxdbRTvLYUP00RFiz3TwE4ihPSPGM6DdYXfMgEQR8Xvqlb631j8vXpvDNrUzCU28scjG0L05QcUyF7YimfsJRpEN1xpj6apK/53dK9khyyoP6YA+a7RIQozoUaWFT2A== X-YMail-OSG: 0xG1sX0VM1nFpK4qSSijT7Eo3.3W6j2mCRJwPArQWwvzLUQ17rf61lj8gHzNZnO o1LFuZ4.PegTxUrjbrXTI56K2eqOAiRfloL8w8EbkCt5LCEN0iNtxmJGvDwLhn0Dhfkqu5ZiG3UI cMWFYTfU53lJUYqWkW9_XPZ3tSjTCDu4ZG.Mk6ieRll_owWbnvvc8ezO33noV.aEmvH3zLI1rboY 0vHIsE924_cJ5.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KxrzvDuflKu0elz3cMzSmcYYbsko- X-Sonic-MF: X-Sonic-ID: 8127dbfb-da10-4c3d-b8b5-d9c2217b666d Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ir2.yahoo.com with HTTP; Sun, 16 Apr 2023 12:45:07 +0000 Received: by hermes--production-ir2-74cd8fc864-4bl68 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8a53f7a8722383f9609d619e4fab1862; Sun, 16 Apr 2023 12:45:04 +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 , Pavel Machek , Axel Lin , ChiYuan Huang , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v2 3/9] mfd: rt5033: Fix STAT_MASK, HZ_MASK and AICR defines Date: Sun, 16 Apr 2023 14:44:30 +0200 Message-Id: <7eda1f8751b4f5a5bd88063b7fbf3cfdb911019c.1681646904.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The charger state mask RT5033_CHG_STAT_MASK should be 0x30 [1][2]. The high impedance mask RT5033_RT_HZ_MASK is actually value 0x02 [3] and is assosiated to the RT5033 CHGCTRL1 register [4]. Accordingly also change RT5033_CHARGER_HZ_ENABLE to 0x02 to avoid the need of a bit shift upon application. For input current limiting AICR mode, the define for the 1000 mA step was missing [5]. Additionally add the define for DISABLE option. Concerning the mask, remove RT5033_AICR_MODE_MASK because there is already RT5033_CHGCTRL1_IAICR_MASK further up. They are redundant and the upper one makes more sense to have the masks of a register colleted there as an overview. [1] https://github.com/msm8916-mainline/linux-downstream/blob/GT-I9195I/drivers/battery/rt5033_charger.c#L669-L682 [2] https://github.com/torvalds/linux/blob/v6.0/include/linux/mfd/rt5033-private.h#L59-L62 [3] https://github.com/msm8916-mainline/linux-downstream/blob/GT-I9195I/include/linux/battery/charger/rt5033_charger.h#L44 [4] https://github.com/msm8916-mainline/linux-downstream/blob/GT-I9195I/drivers/battery/rt5033_charger.c#L223 [5] https://github.com/msm8916-mainline/linux-downstream/blob/GT-I9195I/drivers/battery/rt5033_charger.c#L278 Signed-off-by: Jakob Hauser Acked-for-MFD-by: Lee Jones --- include/linux/mfd/rt5033-private.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/linux/mfd/rt5033-private.h b/include/linux/mfd/rt5033-private.h index b035a67cec73..b6773ebf4e6b 100644 --- a/include/linux/mfd/rt5033-private.h +++ b/include/linux/mfd/rt5033-private.h @@ -55,7 +55,7 @@ enum rt5033_reg { }; /* RT5033 Charger state register */ -#define RT5033_CHG_STAT_MASK 0x20 +#define RT5033_CHG_STAT_MASK 0x30 #define RT5033_CHG_STAT_DISCHARGING 0x00 #define RT5033_CHG_STAT_FULL 0x10 #define RT5033_CHG_STAT_CHARGING 0x20 @@ -67,6 +67,7 @@ enum rt5033_reg { /* RT5033 CHGCTRL1 register */ #define RT5033_CHGCTRL1_IAICR_MASK 0xe0 #define RT5033_CHGCTRL1_MODE_MASK 0x01 +#define RT5033_CHGCTRL1_HZ_MASK 0x02 /* RT5033 CHGCTRL2 register */ #define RT5033_CHGCTRL2_CV_MASK 0xfc @@ -92,7 +93,6 @@ enum rt5033_reg { /* RT5033 RT CTRL1 register */ #define RT5033_RT_CTRL1_UUG_MASK 0x02 -#define RT5033_RT_HZ_MASK 0x01 /* RT5033 control register */ #define RT5033_CTRL_FCCM_BUCK_MASK BIT(0) @@ -119,13 +119,14 @@ enum rt5033_reg { * register), AICR mode limits the input current. For example, the AIRC 100 * mode limits the input current to 100 mA. */ +#define RT5033_AICR_DISABLE 0x00 #define RT5033_AICR_100_MODE 0x20 #define RT5033_AICR_500_MODE 0x40 #define RT5033_AICR_700_MODE 0x60 #define RT5033_AICR_900_MODE 0x80 +#define RT5033_AICR_1000_MODE 0xa0 #define RT5033_AICR_1500_MODE 0xc0 #define RT5033_AICR_2000_MODE 0xe0 -#define RT5033_AICR_MODE_MASK 0xe0 /* RT5033 use internal timer need to set time */ #define RT5033_FAST_CHARGE_TIMER4 0x00 @@ -195,7 +196,7 @@ enum rt5033_reg { /* RT5033 charger high impedance mode */ #define RT5033_CHARGER_HZ_DISABLE 0x00 -#define RT5033_CHARGER_HZ_ENABLE 0x01 +#define RT5033_CHARGER_HZ_ENABLE 0x02 /* RT5033 regulator BUCK output voltage uV */ #define RT5033_REGULATOR_BUCK_VOLTAGE_MIN 1000000U From patchwork Sun Apr 16 12:44:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 674059 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 D81BFC77B61 for ; Sun, 16 Apr 2023 12:45:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230499AbjDPMpd (ORCPT ); Sun, 16 Apr 2023 08:45:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230400AbjDPMpT (ORCPT ); Sun, 16 Apr 2023 08:45:19 -0400 Received: from sonic310-57.consmr.mail.ir2.yahoo.com (sonic310-57.consmr.mail.ir2.yahoo.com [77.238.177.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DBAF4C39 for ; Sun, 16 Apr 2023 05:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1681649111; bh=5w6Shyycf9TKW8fxiIBkdZ0V7BL6iy8PZMl/Ylzmv2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=LrMztTlliwRbTv5z/JWofG7LAQ7iak9yAdRU8G3DTgkEraIz/bTFMD8B9rUohK2vf+2kRmKB05fPtFyY4edRnNDM9J1a9jaYbd9DCPJOYISH22VRlSFQ3PNP2TWROT4LM+E/27kiKPOSZAK1d/6b73D0f5kOW/KJ5mZFb3PPGMnYr8dVeUI61okTmXlIqstvS73YUis1SMVfw8kivFShN/FSjHdvD/p0cZw+aYamdan8aMuwSpVttIPX6R58qgsalh/xia7TYOu+EsYYdGMKTZOHVjUQnhvZGmnjxtzllpgjDO6nXjLu6H/P5tRl4RhX6YckB/1I/s2cbeCNBsLnjw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681649111; bh=6jNhRSkwjwcNdOysluK5MECwQrmE27tZ2YUS6DdYuC6=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=HxkliYZQ+UEAaqTKVmWF1wo9NSc+mY2B7E9Nm/RcQpcGEl+2ClqQuGakk8s2K4Q6kxZU6Wtm/FFG/zVDm4WB/+dOrygEAz0L27SuVVYBZSISWvr4RaF/M3Zl5daHlJ3Z3bsHHLjnI7za6uFDSNrdzOzhhDf7xncv0huA9S347bTRwcKxO5AiIPSLAOD+5Ks4fIA1u6ZLe7/wudPF5nxzVQhYouZI5oQExqrd4nP2omIlpAtb/poDmWHImtvSMob8Bd1fkpQwOZbqLg4nDwPrZ7O2msyyv4oDBE2FjsMpY8Oh/M7TJ99ab6dvprDYaavrh5yRQHKjl3zJY66a/Y2sBA== X-YMail-OSG: 80cIE4wVM1l6d8QFJAP7GwTQ9cVWNQxyEye6eYPKht4pV5848pUWVCvSZ.iT_g0 uhms_iuX5H4LwdCZockrDzAPf6GHiInciAVOaTdQjVcXt62TOQjyMM7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qyn4zsiN59W1HMHPJDHljm W15kiHmkkLOniMOAgMFaOwNe1F3AtWduU.Pbnlm2ftK_3HKkDi.9VvZtHeGQBo3_Yi0Ff701xubK C.3T9nU_NprSLmCGisVoKLgIY3ePq4.VDzwIigV6y0RAWyD94 X-Sonic-MF: X-Sonic-ID: 7428be8d-47e8-428a-9d4e-c25f9104e0c3 Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ir2.yahoo.com with HTTP; Sun, 16 Apr 2023 12:45:11 +0000 Received: by hermes--production-ir2-74cd8fc864-4bl68 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8a53f7a8722383f9609d619e4fab1862; Sun, 16 Apr 2023 12:45:06 +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 , Pavel Machek , Axel Lin , ChiYuan Huang , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v2 4/9] mfd: rt5033: Apply preparatory changes before adding rt5033-charger driver Date: Sun, 16 Apr 2023 14:44:31 +0200 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@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 Sun Apr 16 12:44:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 673680 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 5019EC77B61 for ; Sun, 16 Apr 2023 12:45:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230421AbjDPMpW (ORCPT ); Sun, 16 Apr 2023 08:45:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230401AbjDPMpS (ORCPT ); Sun, 16 Apr 2023 08:45:18 -0400 Received: from sonic312-25.consmr.mail.ir2.yahoo.com (sonic312-25.consmr.mail.ir2.yahoo.com [77.238.178.96]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5B655FC0 for ; Sun, 16 Apr 2023 05:45:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1681649111; bh=po22Pka6e1k6bWH2o5z/cMQ182cbRZtmE52Iz+lWe/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=IzIxiWohCKA7+KYLrVB89fpkhRJjfiUKNN3mZjSEkndxYhz9NzqCWdVUlOPMH8r8FHVh11Mfiw7PXxHv7/C6mpfdXPZLdcH/YXHs/kWE0YJ4izXTY7f/omtX6+zsfEzefMtgBzSV24fMz0chYuNrLTXWagDtSSzxnZ1fSLpZma0itoPLTvSvRvBSo4zeLpjHLRv6lFTHzV/Tz2W4F+Kt7Ky7WHN6yGNEtsllMAcbST4hydTstrOyLPdOo6a3Zhl5v9Nw9nY8ooBOcPpNokE1RyvMRXqIj/ViwJ2HtAbguFH15n514XYQBrRffQiJfrl8FmV0Bt1eErzqH2CjFs9HEw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681649111; bh=pF2rsLDQVLHDo6glnY5gsdjGqpZpEY01AJ1+FhIohsN=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=PsrBbSMDz4WN5+GAQxBDHs8MnjBMUYm7ZyUKBq75ZBz3/7h3YuZa+phgOXLwiGV/AcHeUizrSm5BdkF7m22mjKhHG0UKsL3k98VfmIlNzGNiCEvSdHDaqGwlcpZlqSJxEjaX3N/TMCIrDLzeZIHKEolMvzDtlw0zG0U+/DvAvVZahyR+qOgZhn5siqJRQMl6G702ywNzNwDfSCmRAmzIMQsLhR8U1W42vvdDThUVtb/VaSr477vb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Dyyr3R52aWYUOmhXJm p48nNsl1vsgdfBFx8m4lwlQh00aGQ.jexlcV9KQU19cA8NkHBvtNajkqioyk7ZvHW68.JyIEOF8h 6SXPdTHmJWZEQ1Of.7oblespE7a4HrRwVLpRLw8qUVAHJnMzRDob1uDa2eIvkOfNT9whxt2BRG0I EkUBmt0p2XGDdR6e2hw9zdLrtgJFxeZ_eT.qK4nwKcJlbGl_Pe5y_6BhvPrkNze0ZiEnDygeaAqN LbTnBhZo1TQbP7oV1YCsD5xdmJngqZYr2jJVWwSjOcRUVqn_v26o7svFtHTiz32t3Zm3aTVHMsA8 pGJC0hU8LuztGTVqMpho_Px84i1SmtMK0NR3RlmhAVozAjxVnmUVI0A-- X-Sonic-MF: X-Sonic-ID: a0f80762-b46e-493a-b2ed-7d0ef27e2824 Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ir2.yahoo.com with HTTP; Sun, 16 Apr 2023 12:45:11 +0000 Received: by hermes--production-ir2-74cd8fc864-4bl68 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 8a53f7a8722383f9609d619e4fab1862; Sun, 16 Apr 2023 12:45:07 +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 , Pavel Machek , Axel Lin , ChiYuan Huang , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v2 5/9] regulator: rt5033: Change regulator names to lowercase Date: Sun, 16 Apr 2023 14:44:32 +0200 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Lowercase is preferred for node names. Cc: Beomho Seo Cc: Chanwoo Choi Cc: Axel Lin Cc: ChiYuan Huang Signed-off-by: Jakob Hauser --- drivers/regulator/rt5033-regulator.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/regulator/rt5033-regulator.c b/drivers/regulator/rt5033-regulator.c index 2ba74f205543..dee272dc81df 100644 --- a/drivers/regulator/rt5033-regulator.c +++ b/drivers/regulator/rt5033-regulator.c @@ -41,8 +41,8 @@ static const struct regulator_ops rt5033_buck_ops = { static const struct regulator_desc rt5033_supported_regulators[] = { [RT5033_BUCK] = { - .name = "BUCK", - .of_match = of_match_ptr("BUCK"), + .name = "buck", + .of_match = of_match_ptr("buck"), .regulators_node = of_match_ptr("regulators"), .id = RT5033_BUCK, .ops = &rt5033_buck_ops, @@ -57,8 +57,8 @@ static const struct regulator_desc rt5033_supported_regulators[] = { .vsel_mask = RT5033_BUCK_CTRL_MASK, }, [RT5033_LDO] = { - .name = "LDO", - .of_match = of_match_ptr("LDO"), + .name = "ldo", + .of_match = of_match_ptr("ldo"), .regulators_node = of_match_ptr("regulators"), .id = RT5033_LDO, .ops = &rt5033_buck_ops, @@ -73,8 +73,8 @@ static const struct regulator_desc rt5033_supported_regulators[] = { .vsel_mask = RT5033_LDO_CTRL_MASK, }, [RT5033_SAFE_LDO] = { - .name = "SAFE_LDO", - .of_match = of_match_ptr("SAFE_LDO"), + .name = "safe_ldo", + .of_match = of_match_ptr("safe_ldo"), .regulators_node = of_match_ptr("regulators"), .id = RT5033_SAFE_LDO, .ops = &rt5033_safe_ldo_ops, From patchwork Sun Apr 16 12:44:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 673679 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 69BEBC77B77 for ; Sun, 16 Apr 2023 12:50:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230271AbjDPMuf (ORCPT ); Sun, 16 Apr 2023 08:50:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbjDPMue (ORCPT ); Sun, 16 Apr 2023 08:50:34 -0400 Received: from sonic308-17.consmr.mail.ir2.yahoo.com (sonic308-17.consmr.mail.ir2.yahoo.com [77.238.178.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C6D291 for ; Sun, 16 Apr 2023 05:50:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1681649430; bh=w02hY1HIp+qDBUno1VcYVxa72PQBwajHWCo6K51iWc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=IrGMbRhG26hGnSoQyHybWgFZB9tFyw3xUVvHznk/SpPaD/hJOEjvTVFrQT+qqtCYHn9QlcpilqWnC4lNfPzHqc3JRPJKCVLfaJgHugPMRn0+IUIDGbDvRYpp3QbO2q2yI4Cai8k+WH1e88izfNZZWosNfkugPp0EepjSrMrih5nzLgAVxo1E0TvJdKLIXbBPLbng2lb73ruK5PcbBQafNF/yz6nr4SE/HWeM1QJJVKJYcDIysM5980aB3tlqeo5uOTcY2jB7WFZgIBjP1OnasffOBMC2VW+jIjZhYrj5/r2go5dgXKN7QGq6djHaXyMQrCtcW6PRWizOLS62uaKFPA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681649430; bh=KxG8LYB2qHuTiuGTL2/VUUQVh7xUPU+CUvksV498Hqb=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=VwO1frkc+wN0Hi2H3uxQMwLxQCl2JXxGgpeH/EV2lXVJxJ3rtMnnQApVz6F+/QKv1rKThonk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h3qPxaHmYe3R6Vi9_gh1RfzIDd5FokH27n pEOyJnyoYwpdunvix01cgYhrohy6sNOIvWNrREcKXgSBbJwSDDRmjxKwoRunG3yeXc6z4tf21Q_H rhIr20pt8n2z7l0UAlfQj_9qqxL6tR7_i7.21w0UAtqU14rt_wleuvu2BsZBQOyTjPlBfyATVDTc no00m5ej1KqFoft_SVMX5DbgeVTq0S4npD9aZPPZHKtwM_k1T02YQkEY0UkF5jN.xFrzqROuqEA0 Pfr447.GO7qleFJ1ZMmZ0I4GGamJcK2y8H755u9aeBhUPt0dTz.Fid7tCTa07m2mJbo2qpFrJbVT iG.xhGPAtxZWtpHIpYaGqo8wPfqV1WXVRGoGUkFil5lVDP3uhubGaQFaVaB.FPlN7cV55tf.empM uYzA2HdoufgmUjoYqpwEc15C1xg2izmpqxRUiuam.5n04o01rUzAn9rIbMDoQ5f73r6kmt7Pk2ya JcbXv15prbpGk0NyxmL4swgdoEg111yHxtgl86VVBd0N2ClQkGEjFKg-- X-Sonic-MF: X-Sonic-ID: 5e0ee88b-bf01-45e8-b449-045deadfede7 Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ir2.yahoo.com with HTTP; Sun, 16 Apr 2023 12:50:30 +0000 Received: by hermes--production-ir2-74cd8fc864-9w846 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID e1e6b4a18b1a30b9efb33afa6a04eb6c; Sun, 16 Apr 2023 12:50:30 +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 , Pavel Machek , Axel Lin , ChiYuan Huang , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v2 6/9] power: supply: rt5033_charger: Add RT5033 charger device driver Date: Sun, 16 Apr 2023 14:44:33 +0200 Message-Id: <665d8906ea7b84e0a248315e8395a80007b8bafb.1681646904.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This patch adds device driver of Richtek RT5033 PMIC. The driver supports switching charger. rt5033 charger provides three charging modes. The charging modes are pre-charge mode, fast charge mode and constant voltage mode. They vary in charge rate, the charge parameters can be controlled by i2c interface. Cc: Beomho Seo Cc: Chanwoo Choi Tested-by: Raymond Hackley Signed-off-by: Jakob Hauser --- drivers/power/supply/Kconfig | 8 + drivers/power/supply/Makefile | 1 + drivers/power/supply/rt5033_charger.c | 463 ++++++++++++++++++++++++++ 3 files changed, 472 insertions(+) create mode 100644 drivers/power/supply/rt5033_charger.c diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index c78be9f322e6..ea11797670ca 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -766,6 +766,14 @@ config BATTERY_RT5033 The fuelgauge calculates and determines the battery state of charge according to battery open circuit voltage. +config CHARGER_RT5033 + tristate "RT5033 battery charger support" + depends on MFD_RT5033 + help + This adds support for battery charger in Richtek RT5033 PMIC. + The device supports pre-charge mode, fast charge mode and + constant voltage mode. + config CHARGER_RT9455 tristate "Richtek RT9455 battery charger driver" depends on I2C diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile index 4adbfba02d05..dfc624bbcf1d 100644 --- a/drivers/power/supply/Makefile +++ b/drivers/power/supply/Makefile @@ -54,6 +54,7 @@ obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o obj-$(CONFIG_BATTERY_MAX1721X) += max1721x_battery.o obj-$(CONFIG_BATTERY_RT5033) += rt5033_battery.o +obj-$(CONFIG_CHARGER_RT5033) += rt5033_charger.o obj-$(CONFIG_CHARGER_RT9455) += rt9455_charger.o obj-$(CONFIG_CHARGER_RT9467) += rt9467-charger.o obj-$(CONFIG_CHARGER_RT9471) += rt9471.o diff --git a/drivers/power/supply/rt5033_charger.c b/drivers/power/supply/rt5033_charger.c new file mode 100644 index 000000000000..b5be43e6ebf5 --- /dev/null +++ b/drivers/power/supply/rt5033_charger.c @@ -0,0 +1,463 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Battery charger driver for RT5033 + * + * Copyright (C) 2014 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include + +static int rt5033_get_charger_state(struct rt5033_charger *charger) +{ + struct regmap *regmap = charger->rt5033->regmap; + unsigned int reg_data; + int state; + + if (!regmap) + return state; + + regmap_read(regmap, RT5033_REG_CHG_STAT, ®_data); + + switch (reg_data & RT5033_CHG_STAT_MASK) { + case RT5033_CHG_STAT_DISCHARGING: + state = POWER_SUPPLY_STATUS_DISCHARGING; + break; + case RT5033_CHG_STAT_CHARGING: + state = POWER_SUPPLY_STATUS_CHARGING; + break; + case RT5033_CHG_STAT_FULL: + state = POWER_SUPPLY_STATUS_FULL; + break; + case RT5033_CHG_STAT_NOT_CHARGING: + state = POWER_SUPPLY_STATUS_NOT_CHARGING; + break; + default: + state = POWER_SUPPLY_STATUS_UNKNOWN; + } + + return state; +} + +static int rt5033_get_charger_type(struct rt5033_charger *charger) +{ + struct regmap *regmap = charger->rt5033->regmap; + unsigned int reg_data; + int state; + + regmap_read(regmap, RT5033_REG_CHG_STAT, ®_data); + + switch (reg_data & RT5033_CHG_STAT_TYPE_MASK) { + case RT5033_CHG_STAT_TYPE_FAST: + state = POWER_SUPPLY_CHARGE_TYPE_FAST; + break; + case RT5033_CHG_STAT_TYPE_PRE: + state = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; + break; + default: + state = POWER_SUPPLY_CHARGE_TYPE_NONE; + } + + return state; +} + +static int rt5033_get_charger_current_limit(struct rt5033_charger *charger) +{ + struct regmap *regmap = charger->rt5033->regmap; + unsigned int state, reg_data, data; + + regmap_read(regmap, RT5033_REG_CHG_CTRL5, ®_data); + + state = (reg_data & RT5033_CHGCTRL5_ICHG_MASK) + >> RT5033_CHGCTRL5_ICHG_SHIFT; + + data = RT5033_CHARGER_FAST_CURRENT_MIN + + RT5033_CHARGER_FAST_CURRENT_STEP_NUM * state; + + return data; +} + +static int rt5033_get_charger_const_voltage(struct rt5033_charger *charger) +{ + struct regmap *regmap = charger->rt5033->regmap; + unsigned int state, reg_data, data; + + regmap_read(regmap, RT5033_REG_CHG_CTRL2, ®_data); + + state = (reg_data & RT5033_CHGCTRL2_CV_MASK) + >> RT5033_CHGCTRL2_CV_SHIFT; + + data = RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MIN + + RT5033_CHARGER_CONST_VOLTAGE_STEP_NUM * state; + + return data; +} + +static inline int rt5033_init_const_charge(struct rt5033_charger *charger) +{ + struct rt5033_charger_data *chg = charger->chg; + int ret; + unsigned int val; + u8 reg_data; + + /* Set constant voltage mode */ + if (chg->const_uvolt < RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MIN || + chg->const_uvolt > RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MAX) + return -EINVAL; + + if (chg->const_uvolt == RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MIN) + reg_data = 0x00; + else if (chg->const_uvolt == RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MAX) + reg_data = RT5033_CV_MAX_VOLTAGE; + else { + val = chg->const_uvolt; + val -= RT5033_CHARGER_CONST_VOLTAGE_LIMIT_MIN; + val /= RT5033_CHARGER_CONST_VOLTAGE_STEP_NUM; + reg_data = val; + } + + ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL2, + RT5033_CHGCTRL2_CV_MASK, + reg_data << RT5033_CHGCTRL2_CV_SHIFT); + if (ret) { + dev_err(charger->dev, "Failed regmap update\n"); + return -EINVAL; + } + + /* Set end of charge current */ + if (chg->eoc_uamp < RT5033_CHARGER_EOC_MIN || + chg->eoc_uamp > RT5033_CHARGER_EOC_MAX) + return -EINVAL; + + if (chg->eoc_uamp == RT5033_CHARGER_EOC_MIN) + reg_data = 0x01; + else if (chg->eoc_uamp == RT5033_CHARGER_EOC_MAX) + reg_data = 0x07; + else { + val = chg->eoc_uamp; + if (val < RT5033_CHARGER_EOC_REF) { + val -= RT5033_CHARGER_EOC_MIN; + val /= RT5033_CHARGER_EOC_STEP_NUM1; + reg_data = 0x01 + val; + } else if (val > RT5033_CHARGER_EOC_REF) { + val -= RT5033_CHARGER_EOC_REF; + val /= RT5033_CHARGER_EOC_STEP_NUM2; + reg_data = 0x04 + val; + } else { + reg_data = 0x04; + } + } + + ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL4, + RT5033_CHGCTRL4_EOC_MASK, reg_data); + if (ret) { + dev_err(charger->dev, "Failed regmap update\n"); + return -EINVAL; + } + + return 0; +} + +static inline int rt5033_init_fast_charge(struct rt5033_charger *charger) +{ + struct rt5033_charger_data *chg = charger->chg; + int ret; + unsigned int val; + u8 reg_data; + + /* Set limit input current */ + ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL1, + RT5033_CHGCTRL1_IAICR_MASK, RT5033_AICR_2000_MODE); + if (ret) { + dev_err(charger->dev, "Failed regmap update\n"); + return -EINVAL; + } + + /* Set fast-charge mode charging current */ + if (chg->fast_uamp < RT5033_CHARGER_FAST_CURRENT_MIN || + chg->fast_uamp > RT5033_CHARGER_FAST_CURRENT_MAX) + return -EINVAL; + + if (chg->fast_uamp == RT5033_CHARGER_FAST_CURRENT_MIN) + reg_data = 0x00; + else if (chg->fast_uamp == RT5033_CHARGER_FAST_CURRENT_MAX) + reg_data = RT5033_CHG_MAX_CURRENT; + else { + val = chg->fast_uamp; + val -= RT5033_CHARGER_FAST_CURRENT_MIN; + val /= RT5033_CHARGER_FAST_CURRENT_STEP_NUM; + reg_data = val; + } + + ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL5, + RT5033_CHGCTRL5_ICHG_MASK, + reg_data << RT5033_CHGCTRL5_ICHG_SHIFT); + if (ret) { + dev_err(charger->dev, "Failed regmap update\n"); + return -EINVAL; + } + + return 0; +} + +static inline int rt5033_init_pre_charge(struct rt5033_charger *charger) +{ + struct rt5033_charger_data *chg = charger->chg; + int ret; + unsigned int val; + u8 reg_data; + + /* Set pre-charge threshold voltage */ + if (chg->pre_uvolt < RT5033_CHARGER_PRE_THRESHOLD_LIMIT_MIN || + chg->pre_uvolt > RT5033_CHARGER_PRE_THRESHOLD_LIMIT_MAX) + return -EINVAL; + + if (chg->pre_uvolt == RT5033_CHARGER_PRE_THRESHOLD_LIMIT_MIN) + reg_data = 0x00; + else if (chg->pre_uvolt == RT5033_CHARGER_PRE_THRESHOLD_LIMIT_MAX) + reg_data = 0x0f; + else { + val = chg->pre_uvolt; + val -= RT5033_CHARGER_PRE_THRESHOLD_LIMIT_MIN; + val /= RT5033_CHARGER_PRE_THRESHOLD_STEP_NUM; + reg_data = val; + } + + ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL5, + RT5033_CHGCTRL5_VPREC_MASK, reg_data); + if (ret) { + dev_err(charger->dev, "Failed regmap update\n"); + return -EINVAL; + } + + /* Set pre-charge mode charging current */ + if (chg->pre_uamp < RT5033_CHARGER_PRE_CURRENT_LIMIT_MIN || + chg->pre_uamp > RT5033_CHARGER_PRE_CURRENT_LIMIT_MAX) + return -EINVAL; + + if (chg->pre_uamp == RT5033_CHARGER_PRE_CURRENT_LIMIT_MIN) + reg_data = 0x00; + else if (chg->pre_uamp == RT5033_CHARGER_PRE_CURRENT_LIMIT_MAX) + reg_data = RT5033_CHG_MAX_PRE_CURRENT; + else { + val = chg->pre_uamp; + val -= RT5033_CHARGER_PRE_CURRENT_LIMIT_MIN; + val /= RT5033_CHARGER_PRE_CURRENT_STEP_NUM; + reg_data = val; + } + + ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL4, + RT5033_CHGCTRL4_IPREC_MASK, + reg_data << RT5033_CHGCTRL4_IPREC_SHIFT); + if (ret) { + dev_err(charger->dev, "Failed regmap update\n"); + return -EINVAL; + } + + return 0; +} + +static int rt5033_charger_reg_init(struct rt5033_charger *charger) +{ + int ret = 0; + + /* Enable charging termination */ + ret = regmap_update_bits(charger->rt5033->regmap, RT5033_REG_CHG_CTRL1, + RT5033_CHGCTRL1_TE_EN_MASK, RT5033_TE_ENABLE); + if (ret) { + dev_err(charger->dev, "Failed to enable charging termination.\n"); + return -EINVAL; + } + + /* + * Disable minimum input voltage regulation (MIVR), this improves + * the charging performance. + */ + 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; + } + + ret = rt5033_init_pre_charge(charger); + if (ret) + return ret; + + ret = rt5033_init_fast_charge(charger); + if (ret) + return ret; + + ret = rt5033_init_const_charge(charger); + if (ret) + return ret; + + return 0; +} + +static enum power_supply_property rt5033_charger_props[] = { + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_CHARGE_TYPE, + POWER_SUPPLY_PROP_CURRENT_MAX, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, + POWER_SUPPLY_PROP_MODEL_NAME, + POWER_SUPPLY_PROP_MANUFACTURER, + POWER_SUPPLY_PROP_ONLINE, +}; + +static int rt5033_charger_get_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct rt5033_charger *charger = power_supply_get_drvdata(psy); + int ret = 0; + + switch (psp) { + case POWER_SUPPLY_PROP_STATUS: + val->intval = rt5033_get_charger_state(charger); + break; + case POWER_SUPPLY_PROP_CHARGE_TYPE: + val->intval = rt5033_get_charger_type(charger); + break; + case POWER_SUPPLY_PROP_CURRENT_MAX: + val->intval = rt5033_get_charger_current_limit(charger); + break; + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: + val->intval = rt5033_get_charger_const_voltage(charger); + break; + case POWER_SUPPLY_PROP_MODEL_NAME: + val->strval = RT5033_CHARGER_MODEL; + break; + case POWER_SUPPLY_PROP_MANUFACTURER: + val->strval = RT5033_MANUFACTURER; + break; + case POWER_SUPPLY_PROP_ONLINE: + val->intval = (rt5033_get_charger_state(charger) == + POWER_SUPPLY_STATUS_CHARGING); + break; + default: + return -EINVAL; + } + + return ret; +} + +static struct rt5033_charger_data *rt5033_charger_dt_init( + struct platform_device *pdev) +{ + struct rt5033_charger_data *chg; + struct device_node *np = pdev->dev.of_node; + int ret; + + if (!np) { + dev_err(&pdev->dev, "No charger of_node\n"); + return ERR_PTR(-EINVAL); + } + + chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL); + if (!chg) + return ERR_PTR(-ENOMEM); + + ret = of_property_read_u32(np, "richtek,pre-microamp", &chg->pre_uamp); + if (ret) + return ERR_PTR(ret); + + ret = of_property_read_u32(np, "richtek,pre-threshold-microvolt", + &chg->pre_uvolt); + if (ret) + return ERR_PTR(ret); + + ret = of_property_read_u32(np, "richtek,fast-microamp", &chg->fast_uamp); + if (ret) + return ERR_PTR(ret); + + ret = of_property_read_u32(np, "richtek,const-microvolt", + &chg->const_uvolt); + if (ret) + return ERR_PTR(ret); + + ret = of_property_read_u32(np, "richtek,eoc-microamp", &chg->eoc_uamp); + if (ret) + return ERR_PTR(ret); + + return chg; +} + +static const struct power_supply_desc rt5033_charger_desc = { + .name = "rt5033-charger", + .type = POWER_SUPPLY_TYPE_USB, + .properties = rt5033_charger_props, + .num_properties = ARRAY_SIZE(rt5033_charger_props), + .get_property = rt5033_charger_get_property, +}; + +static int rt5033_charger_probe(struct platform_device *pdev) +{ + struct rt5033_charger *charger; + struct rt5033_dev *rt5033 = dev_get_drvdata(pdev->dev.parent); + struct power_supply_config psy_cfg = {}; + int ret; + + charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); + if (!charger) + return -ENOMEM; + + platform_set_drvdata(pdev, charger); + charger->dev = &pdev->dev; + charger->rt5033 = rt5033; + + charger->chg = rt5033_charger_dt_init(pdev); + if (IS_ERR_OR_NULL(charger->chg)) + return -ENODEV; + + ret = rt5033_charger_reg_init(charger); + if (ret) + return ret; + + psy_cfg.of_node = pdev->dev.of_node; + psy_cfg.drv_data = charger; + + charger->psy = devm_power_supply_register(&pdev->dev, + &rt5033_charger_desc, + &psy_cfg); + if (IS_ERR(charger->psy)) { + dev_err(&pdev->dev, "failed: power supply register\n"); + return PTR_ERR(charger->psy); + } + + return 0; +} + +static const struct platform_device_id rt5033_charger_id[] = { + { "rt5033-charger", }, + { } +}; +MODULE_DEVICE_TABLE(platform, rt5033_charger_id); + +static const struct of_device_id rt5033_charger_of_match[] = { + { .compatible = "richtek,rt5033-charger", }, + { } +}; +MODULE_DEVICE_TABLE(of, rt5033_charger_of_match); + +static struct platform_driver rt5033_charger_driver = { + .driver = { + .name = "rt5033-charger", + .of_match_table = rt5033_charger_of_match, + }, + .probe = rt5033_charger_probe, + .id_table = rt5033_charger_id, +}; +module_platform_driver(rt5033_charger_driver); + +MODULE_DESCRIPTION("Richtek RT5033 charger driver"); +MODULE_AUTHOR("Beomho Seo "); +MODULE_LICENSE("GPL v2"); From patchwork Sun Apr 16 12:44:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 673678 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 62E1AC77B73 for ; Sun, 16 Apr 2023 12:50:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230494AbjDPMum (ORCPT ); Sun, 16 Apr 2023 08:50:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230456AbjDPMuk (ORCPT ); Sun, 16 Apr 2023 08:50:40 -0400 Received: from sonic308-17.consmr.mail.ir2.yahoo.com (sonic308-17.consmr.mail.ir2.yahoo.com [77.238.178.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73BAC1982 for ; Sun, 16 Apr 2023 05:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1681649435; bh=U4eMVUfWJ8XaHrvH+5J4MdBct8eeD1kSSIOQlDDshYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=i0weJPFkHHKUGahoFSHKGbQhpm6ZsXyIVt8WSLqdSe//cbPl/RDwz/bBMOfS7uRTijgRTAVINYbuLk885l4nxrP3y2nYlutl63pfRu/2wxG40w9BUDGpW/SmxHyCM+f3ipDvoiotuubY6QQgy7jdDTIz5d0NpYUWOAuFRK7s+xNY9K8ClKUONj/7O9fBmfy2Pai30O5wqnzgt3UEJ+BqDL9PKQH4hLhea9iHtMi+OlFirPn9ofJgfUM0ZC7Hx/hFqbTp8Lean8kJjiWhwDjZrPke+RyUelTI72E/bpeGQXdfJNxHc4u3FC2pjEfRpEKuYl61qNHh0L+yB44aXarKnw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681649435; bh=buPDOhnwlqoYBBjwCWGvecJ5PpIl0GLue1+djqkbzyZ=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=grBNsuXfaTAgR8k+cBKLEJq6n+WqKhOk3H1YCLfnTrdwobq/ie2cpsKXpXRspL7UNUxXy3DRo2tofJ2J1ypKobLSuEheLfibEIOqYTWlZotgD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CoKd buaFJkK8HmcCYtxJuRTlfI9IZ6amiKhhGN_Ohm7.VztRM4HMX8tDBq0DnymRLv1xl8OGCdoQNErl 68kgNeSFu3Ew1rAf9HwAFzTwEa4FqEoZV.9LOsf1bNfX2SSiL7xcebRyQcZhffNWdncKA_1cCj07 IR_4zXpyHFw5FZtp_rxJkVo.qGG5JFEJJEOZ6d9UoNAGa7xkl3UWjWV6H_yupQ9ya8DTMaA4MNHX zlA.dtBUTnx9G6FBHPleTHj675gDuMw5zKbBzvNb.CNXzXc9BqEACSCTztY.CrIMakB9WB70ZXXD 81th5qtwNMt5FAqQBBAxIlMghJAIJ2gI2decojEQfy1NzQIt.CPBCxjbRRbmn4w2JojijeORuHkS WrPzS4uKHLNRhHLysRg6fqrOBzc.MIFtm6cJcUX85GDLVTLIm34_NeBAkCCrfrq9FCPEvuyurIz8 DHsdoEsSMluer0Ec3_tC6TqrCV9vB8eZMZRow52RbxWLs4y4.W6BYcg-- X-Sonic-MF: X-Sonic-ID: 52d95fc6-ec98-4b7e-9a40-c5246ee92025 Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ir2.yahoo.com with HTTP; Sun, 16 Apr 2023 12:50:35 +0000 Received: by hermes--production-ir2-74cd8fc864-9w846 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID e1e6b4a18b1a30b9efb33afa6a04eb6c; Sun, 16 Apr 2023 12:50:31 +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 , Pavel Machek , Axel Lin , ChiYuan Huang , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v2 7/9] power: supply: rt5033_charger: Add cable detection and USB OTG supply Date: Sun, 16 Apr 2023 14:44:34 +0200 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@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 b5be43e6ebf5..dd71233d554b 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 Sun Apr 16 12:44:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 674057 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 9FF97C77B79 for ; Sun, 16 Apr 2023 12:50:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230400AbjDPMun (ORCPT ); Sun, 16 Apr 2023 08:50:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230479AbjDPMul (ORCPT ); Sun, 16 Apr 2023 08:50:41 -0400 Received: from sonic301-21.consmr.mail.ir2.yahoo.com (sonic301-21.consmr.mail.ir2.yahoo.com [77.238.176.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA63430ED for ; Sun, 16 Apr 2023 05:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1681649436; bh=t2fvyYZS7Chh40ho3TEbOh4/xUHgvfaETlyY4tmywTw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=OOQ1PErd5vd8UQBpNxVM/+o1su7VLFHpeVTHjoFaEI/k6269DK9UvDTPxwQ4+zAvhbb+vNihoXqLpfsEpi68JifWkP1Y86UsXGFZLCfwHsLeWLNVHMJFwOTX5d0/qu/xsN7vN2+QDTOG1kQkLX7uO16k22jvKd6FKxIyC6az485KViJQKH4+1bjgRgmEE7ko77Y3DKiknLD0gX9PVA6olpqmBRmK8hGIhWh8iEMc0xnhOqbHACLuR0MCnnsrwhsWDqQX/3I8hE5DchN8JZtRAsTHNTJZ5M/n9QyBSDbPVtiUwjej7729BsQ0NfmtNp3QF5IIXWV8B0uUP+M950D+7w== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1681649436; bh=6pZIRE45gcFJ00KwaPV3W2dWc2VJdFKuQHIvliouYvS=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=MCljO7+jXWpB6VL4OH5CUK8VUdP8gOhTo+FTOeC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mV8ONxQkhg6ypB .pQ7zfXLyS2VmFxgDRyUW1PYH.ZTGj5cH35xzoLvSSV_YldkMi6LdtilEMEVHFl_aV7ihtAGqkue LQtMbMXggSqoFdfOZZgpswwgqxbnkJ5pibvgO.UBUhjK3iCQyAPW1clHZhD1RkJwvLEKZzFOoCXY ELxSViGxreHLTj.d_mXhQZEIUI3vB8GfOx5uurdySxcmUTeDxYSPZmpD5aPOXnT7dLFKrWQcmt_l FeVGShetNNRo2q5ZgMyA2jSq9HonuUcbEGnr4jwbttbcMY0UoGvr_j4rxkb6vEHhZGPKbvP_GsB7 bcUMxrDPcDeBeEU92ZmZKC67884F0c3JyUYK9xpPIq59wFts4RHjqXO4_Y_anyAcjvwPNCljvJdS _klnB8Y6l2F3Jh0mJ1SN63_OeI9vPnNN.6KeP9.VElIFb4XFYQwlnZQ47n6gaha45Fz5tirNFN_o 6ibVKE2uVv2iOzbxvcXFvbGRrHcccHO9AWbRXW73.zre_YzufJg9.ELSihlXpVdVxu_jTQmGWCIR KUIYGBsZrN9tzKp4vqPy8TXGdCn7.oyDAfodXPCNkGjraeOVNFdkc3g-- X-Sonic-MF: X-Sonic-ID: 37b66e74-6baf-4456-be0a-5c9429113131 Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ir2.yahoo.com with HTTP; Sun, 16 Apr 2023 12:50:36 +0000 Received: by hermes--production-ir2-74cd8fc864-9w846 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID e1e6b4a18b1a30b9efb33afa6a04eb6c; Sun, 16 Apr 2023 12:50:33 +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 , Pavel Machek , Axel Lin , ChiYuan Huang , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v2 8/9] power: supply: rt5033_battery: Adopt status property from charger Date: Sun, 16 Apr 2023 14:44:35 +0200 Message-Id: <23260904aab2566faf86d2ac01a31e7f1e024e66.1681646904.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@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 = { From patchwork Sun Apr 16 12:44:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 674058 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 830A5C77B7A for ; Sun, 16 Apr 2023 12:50:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230474AbjDPMul (ORCPT ); Sun, 16 Apr 2023 08:50:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230269AbjDPMuk (ORCPT ); Sun, 16 Apr 2023 08:50:40 -0400 Received: from sonic311-30.consmr.mail.ir2.yahoo.com (sonic311-30.consmr.mail.ir2.yahoo.com [77.238.176.162]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C828A26A0 for ; Sun, 16 Apr 2023 05:50:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1681649435; bh=ry1wdbINkSV09xVX5t7wSbuuNoW3ImeInKe2pM61If4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=Booa5Zq1c31RmSx4IxxAajr8qh23zdTe5Ey891xiJtQh6vvKujBID6m/nwGVBp3oTx2ZvncDPt7EytughQAevY/NPfuG04SwkPJ1xjT0lPX0jz8tsx7yxyxKVEdaoy2oactEO/3AxEShWMVdaIz3X0PrFS10spLuhYrb1BdKp8y8gl6YeWKxFP2oiApEPuQqMjcukVEjLn0YD6hgSywRqI8c35hG15Pu2At1Jpt5Ft3hiNp7X1+0hoDd/vlbEszAj0nOoGwT40eb+I+ftIsGhj8229hY+vT3jhHpobJxzLxQF/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1kZw6cgHcbTPRD.y.G3Ws1Vus.h96xtNo5KwRIZCeLTmrQsSBqZwzPIQUhruI7ig7R1C z_A4K8bQjhvP5dKhPIHFoOjmNRk7lSCp76sCxuztqPeiuY4WUB5fYOhxGVDfyUxSqlqubBgqUPo5 MaJ1T1CkbcAbk8EDdiAZRriaP_mxNfObNrBfGBLDDlh3EPWzJ01aRl_2uicDsY8S12q1O.lZwlFz 71otxDUs0sdfathHEBHvDqnnm7Z7sAFnqr73sNuQaIum3bZuuEWm4Z7wEPQKUL.b6ZUVBNykpdfz w.kPKMUIMZMOOGgEl2MQ.YnutK2skxh9REancbLR8yumMrub0qClQmR3Mr7AD4El7C4F49KxAvce 7NGOPb653JbcHyO6IpCZVb79VFMU1RvHZFPCDe2p0ll1ge236Jxyh.kOvDlH03AVdwjG0QXRtYkl C8JbcwhHADeFlD.2MqiBeTVaetrHo_tRbbRrwcmWpYhabWpPsKser6EcFF8oLeFbBzpVI.616tDN y5.e2281.JTq2a5MpA3frgpdyb9ky9WF_nV6ec3.X7LDJbahmGjwrxlV9FOOA3DBQhX42ZbBMcv4 b8bOURSOU2oen8Hvsy7Hycmeikl2kv98LH3laSAUAJNqYGqdX8q17ns_jUxCeWsmb0qiNatWctM6 LVZK2DMECP8.mDmsI7pUFCqjpXeosAhFsjoXPUMOWuvDiz..sCPnUziN9vD2QVSO5J18GwlKAFJC ct93pLndcPmJ4Fnv5rlTQa0knerfSuFDKVKM2uA5WKLVZ6EsVSV3oBw-- X-Sonic-MF: X-Sonic-ID: c8ccb835-27b9-4f7b-a2f5-b718b209afcc Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ir2.yahoo.com with HTTP; Sun, 16 Apr 2023 12:50:35 +0000 Received: by hermes--production-ir2-74cd8fc864-9w846 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID e1e6b4a18b1a30b9efb33afa6a04eb6c; Sun, 16 Apr 2023 12:50:34 +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 , Pavel Machek , Axel Lin , ChiYuan Huang , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v2 9/9] dt-bindings: Add documentation for rt5033 mfd, regulator and charger Date: Sun, 16 Apr 2023 14:44:36 +0200 Message-Id: <9275af790e6e21b5cf661a2444effe4caf2be02e.1681646904.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add device tree binding documentation for rt5033 multifunction device, voltage regulator and battery charger. Cc: Beomho Seo Cc: Chanwoo Choi Signed-off-by: Jakob Hauser --- The patch is based on linux-next (tag "next-20230413"). .../bindings/mfd/richtek,rt5033.yaml | 90 +++++++++++++++++++ .../power/supply/richtek,rt5033-charger.yaml | 76 ++++++++++++++++ .../regulator/richtek,rt5033-regulator.yaml | 24 +++++ 3 files changed, 190 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/richtek,rt5033.yaml create mode 100644 Documentation/devicetree/bindings/power/supply/richtek,rt5033-charger.yaml create mode 100644 Documentation/devicetree/bindings/regulator/richtek,rt5033-regulator.yaml diff --git a/Documentation/devicetree/bindings/mfd/richtek,rt5033.yaml b/Documentation/devicetree/bindings/mfd/richtek,rt5033.yaml new file mode 100644 index 000000000000..158036a57291 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/richtek,rt5033.yaml @@ -0,0 +1,90 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/richtek,rt5033.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Richtek RT5033 Power Management Integrated Circuit + +maintainers: + - Jakob Hauser + +description: + RT5033 is a multifunction device which includes battery charger, fuel gauge, + flash LED current source, LDO and synchronous Buck converter for portable + applications. It is interfaced to host controller using I2C interface. The + battery fuel gauge uses a separate I2C bus. + +properties: + compatible: + const: richtek,rt5033 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + regulators: + type: object + $ref: /schemas/regulator/richtek,rt5033-regulator.yaml# + + charger: + type: object + $ref: /schemas/power/supply/richtek,rt5033-charger.yaml# + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + pmic@34 { + compatible = "richtek,rt5033"; + reg = <0x34>; + + interrupt-parent = <&msmgpio>; + interrupts = <62 IRQ_TYPE_EDGE_FALLING>; + + pinctrl-names = "default"; + pinctrl-0 = <&pmic_int_default>; + + regulators { + safe_ldo_reg: safe_ldo { + regulator-name = "safe_ldo"; + regulator-min-microvolt = <4900000>; + regulator-max-microvolt = <4900000>; + regulator-always-on; + }; + ldo_reg: ldo { + regulator-name = "ldo"; + regulator-min-microvolt = <2800000>; + regulator-max-microvolt = <2800000>; + }; + buck_reg: buck { + regulator-name = "buck"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1200000>; + }; + }; + + charger { + compatible = "richtek,rt5033-charger"; + richtek,pre-microamp = <450000>; + richtek,fast-microamp = <1000000>; + richtek,eoc-microamp = <150000>; + richtek,pre-threshold-microvolt = <3500000>; + richtek,const-microvolt = <4350000>; + extcon = <&muic>; + }; + }; + }; diff --git a/Documentation/devicetree/bindings/power/supply/richtek,rt5033-charger.yaml b/Documentation/devicetree/bindings/power/supply/richtek,rt5033-charger.yaml new file mode 100644 index 000000000000..439e0b7962f3 --- /dev/null +++ b/Documentation/devicetree/bindings/power/supply/richtek,rt5033-charger.yaml @@ -0,0 +1,76 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/supply/richtek,rt5033-charger.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Richtek RT5033 PIMC Battery Charger + +maintainers: + - Jakob Hauser + +description: + The battery charger of the multifunction device RT5033 has to be instantiated + under sub-node named "charger" using the following format. + +properties: + compatible: + const: richtek,rt5033-charger + + richtek,pre-microamp: + description: + Current of pre-charge mode. The pre-charge current levels are 350 mA to + 650 mA programmed by I2C per 100 mA. + maxItems: 1 + + richtek,fast-microamp: + description: + Current of fast-charge mode. The fast-charge current levels are 700 mA + to 2000 mA programmed by I2C per 100 mA. + maxItems: 1 + + richtek,eoc-microamp: + description: + This property is end of charge current. Its level ranges from 150 mA to + 600 mA. Between 150 mA and 300 mA in 50 mA steps, between 300 mA and 600 mA + in 100 mA steps. + maxItems: 1 + + richtek,pre-threshold-microvolt: + description: + Voltage of pre-charge mode. If the battery voltage is below the pre-charge + threshold voltage, the charger is in pre-charge mode with pre-charge current. + Its levels are 2.3 V to 3.8 V programmed by I2C per 0.1 V. + maxItems: 1 + + richtek,const-microvolt: + description: + Battery regulation voltage of constant voltage mode. This voltage levels from + 3.65 V to 4.4 V by I2C per 0.025 V. + maxItems: 1 + + extcon: + description: + Phandle to the extcon device. + maxItems: 1 + +required: + - richtek,pre-microamp + - richtek,fast-microamp + - richtek,eoc-microamp + - richtek,pre-threshold-microvolt + - richtek,const-microvolt + +additionalProperties: false + +examples: + - | + charger { + compatible = "richtek,rt5033-charger"; + richtek,pre-microamp = <450000>; + richtek,fast-microamp = <1000000>; + richtek,eoc-microamp = <150000>; + richtek,pre-threshold-microvolt = <3500000>; + richtek,const-microvolt = <4350000>; + extcon = <&muic>; + }; diff --git a/Documentation/devicetree/bindings/regulator/richtek,rt5033-regulator.yaml b/Documentation/devicetree/bindings/regulator/richtek,rt5033-regulator.yaml new file mode 100644 index 000000000000..66c8a0692e10 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/richtek,rt5033-regulator.yaml @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/regulator/richtek,rt5033-regulator.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Richtek RT5033 PIMC Voltage Regulator + +maintainers: + - Jakob Hauser + +description: + The regulators of RT5033 have to be instantiated under a sub-node named + "regulators". For "safe_ldo" voltage there is only one value of 4.9 V. "ldo" + voltage ranges from 1.2 V to 3.0 V in 0.1 V steps. "buck" voltage ranges from + 1.0 V to 3.0 V in 0.1 V steps. + +patternProperties: + "^(safe_ldo|ldo|buck)$": + type: object + $ref: /schemas/regulator/regulator.yaml# + unevaluatedProperties: false + +additionalProperties: false