From patchwork Sun May 14 12:31:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 682274 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 633ADC7EE2E for ; Sun, 14 May 2023 12:32:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235354AbjENMb6 (ORCPT ); Sun, 14 May 2023 08:31:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234152AbjENMb4 (ORCPT ); Sun, 14 May 2023 08:31:56 -0400 Received: from sonic313-20.consmr.mail.ir2.yahoo.com (sonic313-20.consmr.mail.ir2.yahoo.com [77.238.179.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D2E4171D for ; Sun, 14 May 2023 05:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1684067513; bh=tWxmac8mwRjMj71krRu9An5Rypa20FdRhR7NzHl2dAk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=lJxf1+0atQl4LVIuxw9nXF3FrCjXZ0MtejnjuOnEXidz1JEmBVTZwuWMiv09WPJn/VlPnzGrAlDVmNvw7z3xj6DxRlzoI3oYu3MGj/Zencw/09ichl/DHc776Aw8JbYenS+MhVW+/ThNHKmBBvL+BqhlHJacKUjkEEeKGOG0DZxKAR3InWFD3KEpubg8SMZUi8lHypnm4ZSV8FlsvzM+cpsRWBnbGipHf7S+mHYJ3imjHMIwTFFFFIufFNYKHwzInr2iSUH/w18EkqZGYjRKKi6RcWFrSFGLwsaaD6Pbz6pIwIOBcApsHzYwL3cgT7Hrr/28xj8M8OQd88YdtkUFUQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1684067513; bh=0w5YwCWwvMTy0fAoDNbwYRkRoLZyR/ErTg6FIbrv0Vd=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=ZR8VK7BELOHd/DY555mbdg7NjnrlJaArqGyAF2sxqvdpoBqRVjfdClPNuVYe7CnDlemilkceq81rCuGanTCBr8z09E9d6R87a4pxmoWSTkFHIhlVpu/vCCl5OHLlojDJHt+5Ts/qJuT1CYVECBNpIgIGzmQ+EiWCSbj0hG7tPbk7X3KQNH2BraUEbycVDojhwa9RQGrWMK61cub8R+EtThMkRvym/cDETvHmO+1Fkh2fx5DK2siPenUgol8rV4v7AvCpGPGbBU2BBR8FN7szBBMSXmLwQg2pHMO3q4P+671diE4MVfXsyji61U+L2YELVM510sdjeq/D9X8nO8+BBg== X-YMail-OSG: BPORoeIVM1lVP1GRrleAMcn.pZ7jDQg_r6w.nOOTz9.iii1xRp7OD1GmulUvb70 VFPrIAqqCHNzUnFFKB0dJxCxMCjzndrQcOeNr1BG_MKeul8wNwPxEfbPv6ffhev0EcT_nkrt5yVd YW72O2stX.S.Bv65ugxuRmvU74pHLt.1vRuEs9viy5TGdiAkuFonXqtfebZyUeC9BsUVetevcMLf 5b6AvxJ0J45L2qY4dMyZkvc9JxBjhSXBUXtDHs7YxBnmxC562RTeAhlRa_VswyCI6Aggm_QEj4SZ EFMJjuL3u9cUWfjkzIQ9V_eP31iiS8J4xul6hRZRt.3pgNhibEmle.pah6RxbmcSPtSh_8lwGc90 mPmZ8ZkBdeoUfATcre1.xpIwxraXdEFHk3SGZb1EEb7BUFv_5OXp8hB9sVvLNofkOeb_KJ68Rr3O 2B4mi9p8LZJU.WVYDmtTed2l6OJReuWk_._PgakIh4fXNZenEBbvxUYkBI0T55HHj738V58VJzV0 yFBEcAirYObO..zZok9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ogBauoHIiMwQH2Fg5V3jzroObm.OpEFlAqTpGfU2fGv4ly70yRmrc 8e29bnxnKtg7OLZej2TvT8m9dAAaKkZb9nQV6qTPSRK8Ef4HDGRuX4nZ2RvsMjdWB4Fho5c4YAie kGPpy4bshWiPchyH5l.EiSkXB_lqYAQkthnsS1Z_73UwnDk79vb1iHm2m4czTjus7xvxoDBHD7ov Yfb4ZdQqTh1fyNDQaUaemYn5N8amiJ3wrWslUKQyaDfJQYHCFQPX9NgjpMfmbPWdpp1GtLWY6oJZ gIq3A_kwpt22L7Cozi0YI6fUp6dnyrMv8H91H9.QWuPnysJkBcIOzniEmdysl5BxVop8lqJj0pEY scpVf6AKvq9M0IXRsOAyG2hxQ_gibbunOIV6SlVtRkaSHUPwWbUP2hylNgpsIOUt3IcjWwaD.P2W RhYPRqZ3aVbI25T4ARyHwsU5sL877qZS5B7V7zYQxXGQh3ekCaII3ka3X2f4ABjtcitgjCbxKl3s VslCaCJjbu8owPIPLtmaDtcMU7HrI6eIUWmmJXxPDjDJq5Gp9qoH4Sb5evyYbD7zqttks0_UaLZs ppiDpqtRwvL9laptE6EPpkC8Bqa5fw8BBEtp8_RDROLw_wBV1E_kJDYz9BtIkEAlsM56ugxaHF1V bz98E_0Znbqn9fTmnIsZ5pZ5pOjq5DLWpbZHUIIvoS.KlKgWFpfniX8VgGbPfN8YvlFbTguKBg_4 S.OUm1pSTacumlNNVIuKuXk.p X-Sonic-MF: X-Sonic-ID: e60d1f4a-a32a-4d5e-b71d-9e99e9ba4dff Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.ir2.yahoo.com with HTTP; Sun, 14 May 2023 12:31:53 +0000 Received: by hermes--production-ir2-7867f454fc-kqstn (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 32d47a946aad3f7d203db987b930ba8f; Sun, 14 May 2023 12:31: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 , Pavel Machek , Axel Lin , ChiYuan Huang , Linus Walleij , Henrik Grimler , 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 v5 01/10] mfd: rt5033: Drop rt5033-battery sub-device Date: Sun, 14 May 2023 14:31:21 +0200 Message-Id: <20230514123130.41172-2-jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230514123130.41172-1-jahau@rocketmail.com> References: <20230514123130.41172-1-jahau@rocketmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 Reviewed-by: Linus Walleij --- 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 May 14 12:31: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: 681911 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 805D1C7EE22 for ; Sun, 14 May 2023 12:32:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229987AbjENMcA (ORCPT ); Sun, 14 May 2023 08:32:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235134AbjENMb6 (ORCPT ); Sun, 14 May 2023 08:31:58 -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 A96E826BB for ; Sun, 14 May 2023 05:31:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1684067515; bh=Fg8O9S7CQWLvLBXMCmKEFeFmz8DxFrOra+7NQGOwBwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=XlIWbq8PlxqdwrN301ADyRkhQXCiF993mORFVh/QN53NhnDCUYNFCGpTaqyu5mc3fODy68uA9E5GhrV+chzRZrC/IvaVor0PE+2YbwXGO/s3PcC/l+PD+cNk8U7Bu05vh0nd43McoGvJjhBfnPNb62Fg4gdpn0H89SuAYcjhZv+ocfHT8MGMyAoCgJBkGlyGIuUtoU1TUVGw/UCNZwDYetMpuNFkvIoPBnH9x8Uw28T+GbTso/jEgVBbZ2hKBvbCaMqwHxMd3aSykq7p7VOW8PYw17SSb3PPRd79vJA9NeaJzFSTPTmvIHy3ooAvs6i9uVp4w4tlkCVoswYZDOjEww== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1684067515; bh=SBPJmK8rSWush7S0V6c3t1jgi55cFE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BuGD8XJQAWrmsdMRQXAPYOjfozVo5Gc8FkhmczocgYPC_jjM_ltC wzHV6V1hcpPDiP3AehXTigrWMMAQkwhWtW7IYr4dOtuqmtfZfZwJr8WSGbyMvtVknepxScfkcZrM hix3qQin8mkVhMGosK_.7bMIbQUiHjdNN5f4428bo0QHcXz_00UOQL7laP0E._I_6.RSrjwP4qOl _2nxIf5owOcqdeb_JzKK9Qpfr6n5D4Cae9fa2QnbPjyBpZXbrdAfV1yjpczQBqoMIlunucgkCOMJ F4rDjpXp.JiXnS9PwE1TgtsVrucr6NaT_ZpVLLYvCYp3zj2A4Nk9HUm_FFeSvihCpbiaxh56S295 uBOy5VfsvUc1Dx.0Tq6lsSEInRjI6hC2aMOt3hCfdUpWwOEJgwMUL1rKfWi1qLU2BBLjaQaypY2u _WQlNWuksqtVIV0y2vMxi.dScVOFaIKErgK8GStv0z8gzVXiMm_VNFzSc1FoI.h6ShPvVZpD_SOy c3NNfwwtsphQqVhnCkR2krLmtJavzipgmT9g6IJBO3CMsiEPAAC6U1K53uYm5qfY55m00tcARf2K N.WAxjXX7hud8P4Uj7zYkC1v9 X-Sonic-MF: X-Sonic-ID: f11cbd54-bba3-4800-a368-3581eb786e2a Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ir2.yahoo.com with HTTP; Sun, 14 May 2023 12:31:55 +0000 Received: by hermes--production-ir2-7867f454fc-kqstn (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 32d47a946aad3f7d203db987b930ba8f; Sun, 14 May 2023 12:31:52 +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 , Linus Walleij , Henrik Grimler , 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 v5 02/10] mfd: rt5033: Fix chip revision readout Date: Sun, 14 May 2023 14:31:22 +0200 Message-Id: <20230514123130.41172-3-jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230514123130.41172-1-jahau@rocketmail.com> References: <20230514123130.41172-1-jahau@rocketmail.com> 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 | 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 May 14 12:31:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 681910 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 0D68CC77B7D for ; Sun, 14 May 2023 12:32:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231630AbjENMcK (ORCPT ); Sun, 14 May 2023 08:32:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237327AbjENMcF (ORCPT ); Sun, 14 May 2023 08:32:05 -0400 Received: from sonic309-24.consmr.mail.ir2.yahoo.com (sonic309-24.consmr.mail.ir2.yahoo.com [77.238.179.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B77422D48 for ; Sun, 14 May 2023 05:32:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1684067519; bh=BgnxKccDW0hD4wBKD/wGrzdwGz4y7GQfSjWtC1jgF84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=tOFNhfjc7cMjPVUPZWShSvLt9MmaYuhvzwBdSJyDSnRBNLUM9ghwCZPz2RWxOtTzKGaXq0X4GTIxsWUwG3GJwG7D8JjO13euTQfG003dIZ+MkRHIFrVsbJUaX69kbl/sG1uEz+F6+/Ie44pjt1bQ6Z3ia8Pwm1zrp+3H7M3LYctOB+WM6uxRVKFixs3PzqRqKgO/koOke5Lj0oDgFrNxq7eo2AlvtMC75jWpyTGjwYGqrq4lWFRmSv4hC2pQfk09ygnTrZyIA1JZaApzrz7sPBNvq3abZtnnOPkBuglOsqBgtli/WUXBHOBstPmoB0GG5uKcghld7APdavvOPIFbGQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1684067519; bh=F1e/yH2/7uoIQfeSzKAgSA5/bP4Dh1YK42oYCg+sfM/=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=AGNMK6IHn41SjYp9fpgk/qlIaqCgADeyt4mD8PbH/A8ulSWvVpWJIFemIB61p1J3iLbeC1LLGw69EEbVeBEHIG2JUEOK0yQe5DFqO7erl1hN3nZjuRohA/j4sxCsaUsrHNQfCGYMDt06K2F/wZZNb92iHLxGr/Nvejp1cl6y1HQ9o+e6ogPeVu8eiPSKV93TYQNhR9/TSEe94cliUo/xSuXVVRZxgOmcjTxYYv7lLCCbB0GbhN2ZDTaz+aa/6s3ezZxGvlWze6+xyREJMin/j3zdhy9pbpT5pshZQColj5IThIAzATlqD8UUN1pIOic1RngZKwTLFEhw3f77mlB9hQ== X-YMail-OSG: mXxq_KIVM1kqLI5v7AqJx03NRoX2RkS4eD3cxfPawAdacQksZaC_k7NPkg7srpt I.Lh0nB9r0qpgdSqA09RiRBybXjAve9o9D_65.WSXElnu6uNQ0fKLygQ7j4FQeBp3EICUzgDWzXq sgFvG9W_eJlYeYj2BeDLW_snaEIHP.A1iFKu.bJKukI8JXokxjfuaAwMHxzVUcaO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hFZd_A-- X-Sonic-MF: X-Sonic-ID: b3d60582-78fb-4e9a-84be-0df6b00ff0c8 Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ir2.yahoo.com with HTTP; Sun, 14 May 2023 12:31:59 +0000 Received: by hermes--production-ir2-7867f454fc-kqstn (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 32d47a946aad3f7d203db987b930ba8f; Sun, 14 May 2023 12:31:53 +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 , Linus Walleij , Henrik Grimler , 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 v5 03/10] mfd: rt5033: Fix STAT_MASK, HZ_MASK and AICR defines Date: Sun, 14 May 2023 14:31:23 +0200 Message-Id: <20230514123130.41172-4-jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230514123130.41172-1-jahau@rocketmail.com> References: <20230514123130.41172-1-jahau@rocketmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 May 14 12:31: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: 682273 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 C4691C7EE22 for ; Sun, 14 May 2023 12:32:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237370AbjENMcG (ORCPT ); Sun, 14 May 2023 08:32:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237240AbjENMcB (ORCPT ); Sun, 14 May 2023 08:32:01 -0400 Received: from sonic303-20.consmr.mail.ir2.yahoo.com (sonic303-20.consmr.mail.ir2.yahoo.com [77.238.178.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC97026BB for ; Sun, 14 May 2023 05:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1684067518; bh=5w6Shyycf9TKW8fxiIBkdZ0V7BL6iy8PZMl/Ylzmv2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=DyDRhBQEYRktzcQdNPQ9ON26jgHHUNBPM80JuNTydyZ79XWt4Pih3v7S91pB+uDxd1Y77NSLrK0wxHr6AhFaFot3ML2cCqMZ5pQr2OZEAGCjtmThU+LosS1OFp657Rkr3q8vnazE8Ah2rsr1CYcmzsTmog6ZlcrZ+ITalYvlvTU8aL0DI2v0DU39MC6D7kjqTyXd2mrFm6vB/XKd8ds3YxNFXjypnIlNK4k86oqCE5dYQtBvD/xHRXdCoJDc79ouwJ0B2yhYpwHFjZP1T6yu+OOP4WJSwucof21CrWwnfmjeC6Gt7JJRSlyWLtVz3BapkSZgdV0F7hbPhoTdpdsmbA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1684067518; bh=HJebqURTY5FrewwRn8MaPno1pIcc4hgve2QLthmWurb=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=gIq/9i6lh+RILmhp3DE5VuXIXSOE8awybChQNBMqjL9SqRxSeGvMQwsvvXETSdmFNsmQk/iaSzA/zGONv3lnilJcAfnlEgsbsVJOI+O0pbCBefaPkSZUizNNE4a3rwsJ1WPm+UNw4v4J4a2Ikn5N4zqTSiJJiu3LKMOCaO02Zcv+Ms8+vQLt6o55pybyO3EKY3Az1Fu9PvOB3GEz++bsun27Er/HwCZBgl8ZLj4C+yWqN1E9gmxXCapAPxRjUftx0Vzf0Frm/f09tBhTuUwM+oRKVb9p09YmyH4HZZXMJ4pI/Hv/sLnzxM6CvrF5HTzPhr8KBQt6NR79nYExqZMZlw== X-YMail-OSG: fGv2R5kVM1kg_xJK_.dwb6p.im7jSADU7DsvYp0O6tNZvAEcCRsu0O_p8178qIs _9jkbLeeIymvRghM1y8i3clr5Yt79KCwgdf79VkTR1mvhnfZxOiWIIB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AFwNmBTA4Y56rFi9w6jcbawYMzEviYcmlHXkOOR878euVpmIQyZrhbZyC6TXfRGwP4SWii HdWiDWT7KzAiuiCuZSaSHmDY4 X-Sonic-MF: X-Sonic-ID: 444e4b96-56f7-4f5b-a7bb-2b756b76af81 Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ir2.yahoo.com with HTTP; Sun, 14 May 2023 12:31:58 +0000 Received: by hermes--production-ir2-7867f454fc-kqstn (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 32d47a946aad3f7d203db987b930ba8f; Sun, 14 May 2023 12:31:55 +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 , Linus Walleij , Henrik Grimler , 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 v5 04/10] mfd: rt5033: Apply preparatory changes before adding rt5033-charger driver Date: Sun, 14 May 2023 14:31:24 +0200 Message-Id: <20230514123130.41172-5-jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230514123130.41172-1-jahau@rocketmail.com> References: <20230514123130.41172-1-jahau@rocketmail.com> 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 Sun May 14 12:31:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 681909 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 F384EC7EE26 for ; Sun, 14 May 2023 12:32:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237326AbjENMcO (ORCPT ); Sun, 14 May 2023 08:32:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237517AbjENMcH (ORCPT ); Sun, 14 May 2023 08:32:07 -0400 Received: from sonic306-19.consmr.mail.ir2.yahoo.com (sonic306-19.consmr.mail.ir2.yahoo.com [77.238.176.205]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B5B3273D for ; Sun, 14 May 2023 05:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1684067520; bh=xfHykX4lNV0IJkAiNJxxbDhqSPAzmVIyexGvhYt+828=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=pmT0AhKPqCJGY2LRJYSr0thvKqdI/DFCZirY7L8CLCWe18rrJvixoUX95DSik1lUPnxloDu6SBol3jFIrbnfp8pUDpqJR2jFFev86iBjZdVkk6CbM0VCCeLhkFCp1jvsoQ3bap4lpkhwTiiz2WtkgzZclQXKm4XjCf1agg3tUhRFUtAKteN0rwr257SojBBRjwASViyzLXZOWOIMfA78iUPxOIJO/RTvVQAWYDReIw2sHBlrIPRFtDTh+nbtgxuU7jbceA0zES4SUdasCd3RfH034GUmkM0mrWNJR5D0gQ3ekINLn2Rj6jZcqohePQjGuwAT16MH0lOeRQEK6WxsaQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1684067520; bh=l6+PRkGShezgHq+bJCwTCvlB4lyX9L9yCZdvoBysmd6=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=JI3Pl6sIl3T6IQ6YcBoZgihpR/baA/pmsjYXe2aDan3g6yUA5Q5v1952BdVy/SFC2X9/LYHUxlprXTGpI/Jleyior3nyTysvaChzpb9p95odR2IY3modpXNIMLgBDe+RRmU1Kizes9Ab3SrkCTscbd9I+vdsnfrLRMa+0A0angF6mh+RbqBGqSO6MMhXkcq8u3ixi6oNlLSDMXC+0uoQcnN/jT6sEtd1l2rVInMsrB2Zaj3km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D52UvjgcVFBcDZRjZjaSsfsGSaNoyVrW.o3YvZ9GMwc3XUABhTyu74anvc8kCJycXkFC0rlURuj o_DUrzelpqrPn5LtsMndHOYkooaN8C9pnK5gQP_UDrwzIuY20Uvq0R58f_E5_bFTdIy79BPRmIfP GGqJgGT39mM6J22iG4rKfrPtGhxmcf_4oBDz.Zpj3WDTjC4lAnaVNVeFuQuu9lCBP8GcOhjY7MqG r5W.C8hhicLfMxJ64iLpBIAo79xLnV_egKaToj0A2FVCVQzV2oZDsXMLORfNnZ64A2.pjYmxFRkR hjOE2ZiQ7XNFh5iYpsu0MOqXukZSAWOs- X-Sonic-MF: X-Sonic-ID: d38c1b50-3e18-4029-8bc5-ff22906835a3 Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ir2.yahoo.com with HTTP; Sun, 14 May 2023 12:32:00 +0000 Received: by hermes--production-ir2-7867f454fc-kqstn (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 32d47a946aad3f7d203db987b930ba8f; Sun, 14 May 2023 12:31:56 +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 , Linus Walleij , Henrik Grimler , 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 v5 05/10] power: supply: rt5033_charger: Add RT5033 charger device driver Date: Sun, 14 May 2023 14:31:25 +0200 Message-Id: <20230514123130.41172-6-jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230514123130.41172-1-jahau@rocketmail.com> References: <20230514123130.41172-1-jahau@rocketmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 Reviewed-by: Linus Walleij Acked-by: Sebastian Reichel --- drivers/power/supply/Kconfig | 8 + drivers/power/supply/Makefile | 1 + drivers/power/supply/rt5033_charger.c | 472 ++++++++++++++++++++++++++ include/linux/mfd/rt5033.h | 16 - 4 files changed, 481 insertions(+), 16 deletions(-) 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..1aa346dd0679 --- /dev/null +++ b/drivers/power/supply/rt5033_charger.c @@ -0,0 +1,472 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Battery charger driver for RT5033 + * + * Copyright (C) 2014 Samsung Electronics, Co., Ltd. + * Author: Beomho Seo + */ + +#include +#include +#include +#include +#include +#include + +struct rt5033_charger_data { + unsigned int pre_uamp; + unsigned int pre_uvolt; + unsigned int const_uvolt; + unsigned int eoc_uamp; + unsigned int fast_uamp; +}; + +struct rt5033_charger { + struct device *dev; + struct regmap *regmap; + struct power_supply *psy; + struct rt5033_charger_data *chg; +}; + +static int rt5033_get_charger_state(struct rt5033_charger *charger) +{ + struct regmap *regmap = charger->regmap; + unsigned int reg_data; + int state; + + if (!regmap) + return POWER_SUPPLY_STATUS_UNKNOWN; + + 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->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->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->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) { + dev_err(charger->dev, + "Value 'constant-charge-voltage-max-microvolt' out of range\n"); + 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->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) { + dev_err(charger->dev, + "Value 'charge-term-current-microamp' out of range\n"); + 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->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->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) { + dev_err(charger->dev, + "Value 'constant-charge-current-max-microamp' out of range\n"); + 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->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) { + dev_err(charger->dev, + "Value 'precharge-upper-limit-microvolt' out of range\n"); + 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->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) { + dev_err(charger->dev, + "Value 'precharge-current-microamp' out of range\n"); + 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->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->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->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); + + 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 0; +} + +static struct rt5033_charger_data *rt5033_charger_dt_init( + struct rt5033_charger *charger) +{ + struct rt5033_charger_data *chg; + struct power_supply_battery_info *info; + int ret; + + chg = devm_kzalloc(charger->dev, sizeof(*chg), GFP_KERNEL); + if (!chg) + return ERR_PTR(-ENOMEM); + + ret = power_supply_get_battery_info(charger->psy, &info); + if (ret) + return ERR_PTR(dev_err_probe(charger->dev, -EINVAL, + "missing battery info\n")); + + /* Assign data. Validity will be checked in the init functions. */ + chg->pre_uamp = info->precharge_current_ua; + chg->fast_uamp = info->constant_charge_current_max_ua; + chg->eoc_uamp = info->charge_term_current_ua; + chg->pre_uvolt = info->precharge_voltage_max_uv; + chg->const_uvolt = info->constant_charge_voltage_max_uv; + + 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 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->regmap = dev_get_regmap(pdev->dev.parent, NULL); + + 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)) + return dev_err_probe(&pdev->dev, PTR_ERR(charger->psy), + "Failed to register power supply\n"); + + charger->chg = rt5033_charger_dt_init(charger); + if (IS_ERR_OR_NULL(charger->chg)) + return -ENODEV; + + ret = rt5033_charger_reg_init(charger); + if (ret) + return ret; + + 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"); diff --git a/include/linux/mfd/rt5033.h b/include/linux/mfd/rt5033.h index e99e2ab0c1c1..3992fb2ef0a8 100644 --- a/include/linux/mfd/rt5033.h +++ b/include/linux/mfd/rt5033.h @@ -39,20 +39,4 @@ struct rt5033_battery { struct power_supply *psy; }; -/* RT5033 charger platform data */ -struct rt5033_charger_data { - unsigned int pre_uamp; - unsigned int pre_uvolt; - unsigned int const_uvolt; - unsigned int eoc_uamp; - unsigned int fast_uamp; -}; - -struct rt5033_charger { - struct device *dev; - struct rt5033_dev *rt5033; - struct power_supply *psy; - struct rt5033_charger_data *chg; -}; - #endif /* __RT5033_H__ */ From patchwork Sun May 14 12:31: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: 682272 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 B7E54C7EE24 for ; Sun, 14 May 2023 12:32:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229611AbjENMcN (ORCPT ); Sun, 14 May 2023 08:32:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237348AbjENMcF (ORCPT ); Sun, 14 May 2023 08:32:05 -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 9732930D1 for ; Sun, 14 May 2023 05:32:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1684067520; bh=OldnDodhv2UMYI2uWUh8c6nG0E6HngPbQQkkB+bleEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=Yh1V05HTSyaFt1uqWbRmOA8TIPVm3mJ5J7Jl2taW2qiwmVBG1hs1yohUaFXjsim06XK4d4Gi7RcU/r+U5G7x58RlDpo2s4E7gIAAftG/UMloKZweMnEEACd206NQ04Y8tR00oJ1+3x3EK8rN3n06Odf9S5HzdvclC8c1/3RIpI7RA6sGOOI2eggZDyjgnJggMU8U4wFQ/WRIB01HgwLhHiyl0gX2V7m7diY8bQ9SL2D0lN+mHvInECVzhX2cJC8PvhwV1rFk6V4j9TYWWTsdIoVxm11vTzPHg5nseqGGOCi0THm5aTQqzdlI6ZkzKyeOBeTaG4dWLvfsu3BnBrJxZg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1684067520; bh=jnfGf+F6s62v7cprSAky7Cd8CejK/75WgmNOqwWM7TL=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=rYHwi+kgNWt7l5JTpKz7JsL0xOGgK4ut4MRkeHTJXxuYljVJy1iU7AMEGh7v/oJaKn/qbi1Ku9Lov0oiACPFU0q20u8rY4gaVho21jPi4+C5jo23THrMVgtOBg9iWIxDZSubSGNGg1BVVvYfPHRLyVdwLKlDfCAExKa/DTGHrf2Z7DzTeHtS5uN3vh9y3bPizKtC4VZkPGHiP27LGUuAQ1Gka9/R1Dy9UbsqZ56gI5JhozV0n7jl5PuHxjPtfOM+OvkxMORdNx+yYRz0HArY7p113BLn7A8BU2rQVBdrg60OT1OAjzHIgRQLJYkY8bDMZpoT/NpHZfXDa8sKL8vXoA== X-YMail-OSG: e_yc170VM1kcBWD9Qa5K.yDxfOq1guwncs59YlOXMfwyTHcIGh2oafUaXuz8A0h 43OHbccAhqtScF_3k5GqDqPBe_hShjTaUCK1c7lt2o_CDK5uLQN3tA.GFQMYaqyHgEjzUNtYtRjZ kNnzMC4D6tYDT3Rt9Hy5xeENGyoHsFETEclSpa5DUsdKv7MCbApmNiQQmEr7WrZfq6gWh6f22l6S X5J2DIy.rVvMRETVbB7YiqjHWD78bCiHngp7R99WTFhV5BjChNynzgXD0lEOCN6sAlbyAZfds0Eu VyOYpm86.bz2_KUjNB4E0D9cRNMUMrtaMSXpqGhG8amTLbxDoRZcgwHqN70bNajwDkY6QcuCUXKc i.HwCpk8x3q0vxabBHkEUbvDP0kyiJn0GutPvI0Ly_LwEBc_wdyoRiWcy5hpLr0LUJGz05VQFFZb wJ3I7iZyz3Wwemls3_xoGMZEHspjMggVltyNm4LuEL3_vDcHKrHVJEjP5tVny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EDzZxBwLA4fAERjuGqrnd_MaJLYDxRPN6vWh1MfgQWw1UzhErEWJYySlBAOv2Ts9WiWhPUYs2z3 ydc7AYeZVk.IXYNpSDcemBVpjutj3DHF1kQEv0PVJd6zYEN1HzrY80sqF.YRRBrYhoERdhdM2z8r bcyeZntAhOndmXlu4u_Je8cgJymqBHDnloQNvFD13LfQliXrnBgR2fikTeKm1.Ai3kZpbimWaw6j 3phldlrCTF1Hcfjc4FTuDJfQIxMRsVQ53IbjoEFcDw2knQcigYcRDtGBgbc5zOlDPpbsb1_0Rp6G h_s8Dwh7pq1fHlZ66AEjX9dXhLiIcMvjUg_CCuqiGpLiLz7DXMiRfCeYzIn0li3sZULh1bBHBXRG OHzRRFCsHmgYjCgLEOR6_pQ9TlyzJ9SGYD8lg5v18sNO1jgkXdIY6a8HdnhJ1YNATVkVBNCM48Q8 niTobHBg8US4_Zsbg8XukFmbcuopxxSBfyMtgpnPR3Dd4urHW0AHfk4jIVO_HOS.7UNU11h.o3ps FH1XAk7qfhOcHofzItGhKqWVSspKYp_bkSdY0nMpxh2RdFTGgfpFPYXg3a_ERcYqisEeZwQ1Wmli H1RVYvvt5RWIIztlprzGkjFPC853BAA4vok2JugyGM0atwT8Gs0s2BQAp4oSjIlRhfCG61D5ZFmq 0BHQaQJiuSYjZSIZw35QtjOJ8Vxl.8O4vGHizGxdVmxCD912IMc2VphNhHDGkScuOS3L1Dubm65S D41QdHLhUrEIblBWFy_8bPxAiVU5MJT4- X-Sonic-MF: X-Sonic-ID: 222650e1-c93d-44bd-95c8-65ff071e9161 Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ir2.yahoo.com with HTTP; Sun, 14 May 2023 12:32:00 +0000 Received: by hermes--production-ir2-7867f454fc-kqstn (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 32d47a946aad3f7d203db987b930ba8f; Sun, 14 May 2023 12:31:58 +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 , Linus Walleij , Henrik Grimler , 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 v5 06/10] power: supply: rt5033_charger: Add cable detection and USB OTG supply Date: Sun, 14 May 2023 14:31:26 +0200 Message-Id: <20230514123130.41172-7-jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230514123130.41172-1-jahau@rocketmail.com> References: <20230514123130.41172-1-jahau@rocketmail.com> 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 | 276 +++++++++++++++++++++++++- 1 file changed, 274 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/rt5033_charger.c b/drivers/power/supply/rt5033_charger.c index 1aa346dd0679..7c7fd4cf0623 100644 --- a/drivers/power/supply/rt5033_charger.c +++ b/drivers/power/supply/rt5033_charger.c @@ -6,7 +6,10 @@ * Author: Beomho Seo */ +#include +#include #include +#include #include #include #include @@ -26,6 +29,14 @@ struct rt5033_charger { struct regmap *regmap; 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; }; static int rt5033_get_charger_state(struct rt5033_charger *charger) @@ -56,6 +67,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; } @@ -147,6 +162,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) { @@ -330,6 +348,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->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->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->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->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->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->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, @@ -366,8 +530,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; @@ -402,6 +565,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, @@ -414,6 +657,7 @@ static int rt5033_charger_probe(struct platform_device *pdev) { struct rt5033_charger *charger; struct power_supply_config psy_cfg = {}; + struct device_node *np_conn, *np_edev; int ret; charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); @@ -423,6 +667,7 @@ static int rt5033_charger_probe(struct platform_device *pdev) platform_set_drvdata(pdev, charger); charger->dev = &pdev->dev; charger->regmap = dev_get_regmap(pdev->dev.parent, NULL); + mutex_init(&charger->lock); psy_cfg.of_node = pdev->dev.of_node; psy_cfg.drv_data = charger; @@ -442,6 +687,33 @@ static int rt5033_charger_probe(struct platform_device *pdev) if (ret) return ret; + /* + * Extcon support is not vital for the charger to work. If no extcon + * is available, just emit a warning and leave the probe function. + */ + np_conn = of_parse_phandle(pdev->dev.of_node, "richtek,usb-connector", 0); + np_edev = of_get_parent(np_conn); + charger->edev = extcon_find_edev_by_node(np_edev); + if (IS_ERR(charger->edev)) { + dev_warn(&pdev->dev, "no extcon device 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; } From patchwork Sun May 14 12:31:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 681908 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 7773DC7EE2D for ; Sun, 14 May 2023 12:37:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231640AbjENMhb (ORCPT ); Sun, 14 May 2023 08:37:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234676AbjENMh3 (ORCPT ); Sun, 14 May 2023 08:37:29 -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 90D8726A1 for ; Sun, 14 May 2023 05:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1684067845; bh=VqIx9LSfStGIwADHV2nx489yoOzekt9YBpjG8dE8w6w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=qvDNkQPO9K0t6noCETiE2k3jPvB2018MeCDFv5vhHr1B/30OMrcsZHHgzi26lkjifU55eitVjXhZfl0vSwjwytq7+15IZFB7UrzterCBNpmTmihAqil2bO2EnwgB28aml9tVDu5wBfdGYeWURqBR0RzYZHPXuibwqt20QcSYvjT0FEr3l3s/qSTmnnwYdPj/in/DodkLGzl7b6ATuAUR81VCmwKkyl7Kacb1QKe6R/0CthUC4a+uQPkEVTqt9UZ7z34SPreexH7zjJkYY6Ia+1iZn55jOxCegrqknhfav6AWilYgTwk8qqTcG3fQLJHJOjQr0iJm8r/0rZdhqdB/Qw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1684067845; bh=Awwi1q9aHXuKCeEYu1dy1W4ZCJJwkzQEbd2LjgXvC8r=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=Q7WjNySFufjsKv9sB0B+4rA5l+BWUL5ebe7IUDU+YF1RxqBswIjeKGs4/P3KVtmV28zYP91fxVEq8cMJg4O1I8fgkIQAIq9XKgvD2kh1oOyEN7ZhhGS76W8tSpXvOyRaS7KWbhciwhv6ccIyAoDRR0YmRMfhQRrBNsKWCjQAY9RVZtg8xMSreya0oiI6pmHYq3KJ5BeOgkL12dEH2JeOUpShvaVAZRPzInYW+XGmiKd/vPxuEvL87++GYiiSaqKnzYkB+YELOZ0q8kZfPI6E9TPT++9PfUi3z5r0aL9HKy/XmZwGN43rYvCSLGvShOsb5AHGv4zMCap9JybsUpcD4w== X-YMail-OSG: cuHQmTwVM1k4SQHQNYFgZMrSScidaSR_5IEb2Eow3z_uX3iC2o31iS_fLM3feES 43vClyWqqziJCkL6rSGX1T0_LjMqaZKQ2GICmjSfijvB2.kyF.F3Iv8C9c5iwET_swr5dwvho94. pVc.N3xNdq_6zLllgVDsqtj8.7kJJBrsKrGRfMC_OoN1y.J2xdDTJkvkCjgT09bo_zD0a2_egiS. FIc.q6TvvgDDC7T9e1koLbKdJt54ANGSUncbw8_a6JDjoCAKQfM.Efge_CeTLDLQzvfPnYSnaIIW xHTx1fClbgCaJqWfwl6UmKCeJEV1I4hwau7yw7Wwbk.RoZg4bosG0fTPDpOzSr67pvFYmi7A0_xI wy0yvEd9ZBFsmQ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XyP0a_QE0YhKB_YMEk4GH7zRRg1gFSpJacUwOHt4TG2NuqV2VUpfvfRWvtE U2a7k92vEQdFScySYEtBw2TztZslUKFBA9zop0pBsn8XCrwxmMjp0IvBfrmvRhAIBgtp9vYU4QBX s3ZA7qDqb9LhiUDbhOY6YaSbPlfHvEKjpHhZEZDApSusY4g_vnVcxAl5LJV0trkLuihqD3wZhLDl D0TcipUYvoqSBogBDYXPhMaZ8SZx7qMOIrkCR8PRGOLBkhldSi5H3NBL.aKbZMa8gi0UU7xlYUX9 xkoLADQY75aHdWFYzzwGyisWp4BJER_YJY9LguNSgiMU79MHioyHpzc8oR7jl1bcB9zYuh3jLjqd OFFQIgjPjqDD_A8vseq5ixqCRIqh8.wBzrzGMbpuKF5iw3u5ZOJnnYnQ1UGdgnVpdg77tFUAKC52 .7E0Z1jZXWWIcj2AGJOsHsR47khFsHJATD26749hgiIFb3Ys08NzwjOtaZx_fY7RDqOPvC5ZUFxS DVRQc.VurLQjzRT.mWyzZReZv3sG9NYsqzsBJk2McQFHvYEaDPdYKN8qPqnZD6wlYgH6S393dAl0 iJObruMFUdtH3J63JVoyPtJvejo6F4dDijWgNWqAESZssabT5AaZdaFd3mKZRPh.jJdNR39DExbn faNMFCy_qmCNYGr_Pfkkq4R6hhU5GtGF2waq2qrI_7D8RqLqr6L1.Z4SSpI4AOno0cxk4Mb2Z_Pt 2800_of4NpIMQ.gufzEPokN2VLBvardPsEteY24xFT1RDGcMi1EikVGUWnRY8piUIK_StMPJcttw 3LHINN0krFtHDdjYRTMxwO6CWoiKshekO8VQ_Nqz68LAcS9rtqo9WcV8O9g06VoZE.DNHzzujpkj hSFjuNmt8_3qWCRzJFbaIzwSEmE17HQ-- X-Sonic-MF: X-Sonic-ID: 3aacc60e-eb6d-4247-8021-2b47a8d10bff Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ir2.yahoo.com with HTTP; Sun, 14 May 2023 12:37:25 +0000 Received: by hermes--production-ir2-7867f454fc-tvsct (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID ec262f708c8ca7d1990bed607fb68ca2; Sun, 14 May 2023 12:37:20 +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 , Linus Walleij , Henrik Grimler , 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 v5 07/10] power: supply: rt5033_battery: Move struct rt5033_battery to battery driver Date: Sun, 14 May 2023 14:31:27 +0200 Message-Id: <20230514123130.41172-8-jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230514123130.41172-1-jahau@rocketmail.com> References: <20230514123130.41172-1-jahau@rocketmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Move struct rt5033_battery from the mfd header into the battery driver because it's not used by others. Within struct rt5033_battery, remove the line "struct rt5033_dev *rt5033;" because it doesn't get used. In rt5033.h, remove #include , it's not necessary anymore. In rt5033_battery.c, remove #include , it's not necessary anymore either. Instead add #include and Signed-off-by: Jakob Hauser Acked-by: Sebastian Reichel --- drivers/power/supply/rt5033_battery.c | 9 ++++++++- include/linux/mfd/rt5033.h | 8 -------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/power/supply/rt5033_battery.c b/drivers/power/supply/rt5033_battery.c index 5c04cf305219..91e1efd81f69 100644 --- a/drivers/power/supply/rt5033_battery.c +++ b/drivers/power/supply/rt5033_battery.c @@ -6,11 +6,18 @@ * Author: Beomho Seo */ +#include #include #include #include +#include #include -#include + +struct rt5033_battery { + struct i2c_client *client; + struct regmap *regmap; + struct power_supply *psy; +}; static int rt5033_battery_get_capacity(struct i2c_client *client) { diff --git a/include/linux/mfd/rt5033.h b/include/linux/mfd/rt5033.h index 3992fb2ef0a8..bb3d18945d21 100644 --- a/include/linux/mfd/rt5033.h +++ b/include/linux/mfd/rt5033.h @@ -12,7 +12,6 @@ #include #include #include -#include /* RT5033 regulator IDs */ enum rt5033_regulators { @@ -32,11 +31,4 @@ struct rt5033_dev { bool wakeup; }; -struct rt5033_battery { - struct i2c_client *client; - struct rt5033_dev *rt5033; - struct regmap *regmap; - struct power_supply *psy; -}; - #endif /* __RT5033_H__ */ From patchwork Sun May 14 12:31: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: 682271 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 6F2FDC7EE24 for ; Sun, 14 May 2023 12:37:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235831AbjENMha (ORCPT ); Sun, 14 May 2023 08:37:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233993AbjENMh3 (ORCPT ); Sun, 14 May 2023 08:37:29 -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 9060D19A3 for ; Sun, 14 May 2023 05:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1684067845; bh=iR6f3XRVOHcEpdjcnFCif4nNa1shR7J/nAlLWRT5R4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=aNDwZkDhIJzo4X4l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Sonic-ID: 877ba4c0-0451-46bb-a1c2-970c7ffcb540 Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ir2.yahoo.com with HTTP; Sun, 14 May 2023 12:37:25 +0000 Received: by hermes--production-ir2-7867f454fc-tvsct (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID ec262f708c8ca7d1990bed607fb68ca2; Sun, 14 May 2023 12:37:22 +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 , Linus Walleij , Henrik Grimler , 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 v5 08/10] power: supply: rt5033_battery: Adopt status property from charger Date: Sun, 14 May 2023 14:31:28 +0200 Message-Id: <20230514123130.41172-9-jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230514123130.41172-1-jahau@rocketmail.com> References: <20230514123130.41172-1-jahau@rocketmail.com> 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. To get the charger as a "supplier" from the devicetree, the "of_node" needs to be initiated. Additionally, in the probe function replace dev_err() with dev_err_probe(), this will avoid printing an error for -EPROBE_DEFER when the battery driver probes before the charger driver. Signed-off-by: Jakob Hauser --- drivers/power/supply/rt5033_battery.c | 29 +++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/power/supply/rt5033_battery.c b/drivers/power/supply/rt5033_battery.c index 91e1efd81f69..94d2dea7ef5e 100644 --- a/drivers/power/supply/rt5033_battery.c +++ b/drivers/power/supply/rt5033_battery.c @@ -19,6 +19,21 @@ struct rt5033_battery { struct power_supply *psy; }; +static int rt5033_battery_get_status(struct i2c_client *client) +{ + struct rt5033_battery *battery = i2c_get_clientdata(client); + union power_supply_propval val; + int ret; + + ret = power_supply_get_property_from_supplier(battery->psy, + POWER_SUPPLY_PROP_STATUS, + &val); + if (ret) + val.intval = POWER_SUPPLY_STATUS_UNKNOWN; + + return val.intval; +} + static int rt5033_battery_get_capacity(struct i2c_client *client) { struct rt5033_battery *battery = i2c_get_clientdata(client); @@ -91,6 +106,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; } @@ -103,6 +121,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 = { @@ -124,7 +143,6 @@ static int rt5033_battery_probe(struct i2c_client *client) struct i2c_adapter *adapter = client->adapter; struct power_supply_config psy_cfg = {}; struct rt5033_battery *battery; - u32 ret; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) return -EIO; @@ -142,15 +160,14 @@ static int rt5033_battery_probe(struct i2c_client *client) } i2c_set_clientdata(client, battery); + psy_cfg.of_node = client->dev.of_node; psy_cfg.drv_data = battery; battery->psy = power_supply_register(&client->dev, &rt5033_battery_desc, &psy_cfg); - if (IS_ERR(battery->psy)) { - dev_err(&client->dev, "Failed to register power supply\n"); - ret = PTR_ERR(battery->psy); - return ret; - } + if (IS_ERR(battery->psy)) + return dev_err_probe(&client->dev, PTR_ERR(battery->psy), + "Failed to register power supply\n"); return 0; } From patchwork Sun May 14 12:31: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: 682270 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 D54A4C7EE22 for ; Sun, 14 May 2023 12:37:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237293AbjENMhi (ORCPT ); Sun, 14 May 2023 08:37:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234082AbjENMhd (ORCPT ); Sun, 14 May 2023 08:37:33 -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 C63C4199A for ; Sun, 14 May 2023 05:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1684067849; bh=ABeDo2NB0iraRjL4IKIY6NTLT84fW2XDtRNA6OdZxuM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=OG9u4u10QhHTqLZL3Z/c590W+5uvwb/7PNYCmdUC3Q5wFNk35lu2uGXkceV23V/lhMhOl6lhaZFhjfUbmqI/gF/tHUa8YbGyZGFS6KhOtWyo0vA8Xbq89TnF2CQUpd6PcG+wUqdEPUBQw9jTdHFCy4T4GKD5dmEir6mMlhRoBM/llSFn1d8h2aXbhWDAbe8s5iSUxV2WAs5uKVoF8LyqMu92GycFYHcHjjo8hQh07Xa6O0gwggOZTbnB63Ra1cItHyr5sP6H/6pH3ldymVYTB+PPyQoqvl1odiVgYcnqElIJqFqXeUElLBCxAk2SO+KxyIMUPxuDuGPhhm6Lr++sgA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256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0 lrUp8BYLp8y_TjAU9Jrg5qvMv6YNckkSPIrdvDZJ35VD7npBr4D7AP47G_7mKJfU_BB9jLElyqYg 6zfmLQCGhl7ztz2KYCSnqUNvKDkhSb_nvb2JxRUQz6jDT3oqdnZ9cp3q2ptt_CXelDvZ_6.2OWND HjhSdsTlvdLxGhjA3OwEokqNBjEI0twwK_inxl3aofqLhkeSv7QKJ_dyCGZBLVBF7UXdSShojt40 2U9lomEzYuBADy29_XM5FwzbGk5FkN5Yu9X6to5XabJSiTLFGn3Dl1vifa4m5rIIfnz8s6ABUeyj bN6_Vku9_TL9rV7FryUtwqbvCn66HOnI36mwNFoiNpQtSH4o8IozduCoR1nw8xeZUpMBSe8LxwwS 9mBcM01Ep4nkUtAdYMsxeuXMHYcdR0SPpsfE8rgGwjihU_vnGeE5wmzAE8osUJbYkDcWfr6OotV5 nPUuaso._N9UhtHgOxOHo0lkCrcQMu89rnmSyU0WLsT_VdL97zd5EukELiGS6cC_yuDRp8WKJ3Rh Rxk2gdnCJzp9RnKey.dC6oF7mFEFz.fo5w7Zb4j6H47Tp_9rimHPfrTssA97kpuh3Jv4gBlpM9Au ghwyMKe.9.Jm.dQDEp.EAHQ7LOU8pkrMKIj3CKe1K1Rt.VZLb8G73tBcQ_0AaDm8.Iirwys6VI5p vvgcIzvbje5KAMgAdYtzzYP9nwuRj X-Sonic-MF: X-Sonic-ID: 613d2af4-0dd7-4765-892d-9e43d36e4134 Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ir2.yahoo.com with HTTP; Sun, 14 May 2023 12:37:29 +0000 Received: by hermes--production-ir2-7867f454fc-tvsct (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID ec262f708c8ca7d1990bed607fb68ca2; Sun, 14 May 2023 12:37: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 , Pavel Machek , Axel Lin , ChiYuan Huang , Linus Walleij , Henrik Grimler , 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 v5 09/10] dt-bindings: power: supply: rt5033-battery: Add power-supplies as a property Date: Sun, 14 May 2023 14:31:29 +0200 Message-Id: <20230514123130.41172-10-jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230514123130.41172-1-jahau@rocketmail.com> References: <20230514123130.41172-1-jahau@rocketmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Additionally to the already available ref "power-supply.yaml", add "power-supplies" as a property. Otherwise, when referencing rt5033-battery in an example, message "'power-supplies' does not match any of the regexes: 'pinctrl-[0-9]+'" will be returned. Signed-off-by: Jakob Hauser --- .../bindings/power/supply/richtek,rt5033-battery.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/power/supply/richtek,rt5033-battery.yaml b/Documentation/devicetree/bindings/power/supply/richtek,rt5033-battery.yaml index 756c16d1727d..07e03418a909 100644 --- a/Documentation/devicetree/bindings/power/supply/richtek,rt5033-battery.yaml +++ b/Documentation/devicetree/bindings/power/supply/richtek,rt5033-battery.yaml @@ -22,6 +22,8 @@ properties: interrupts: maxItems: 1 + power-supplies: true + required: - compatible - reg From patchwork Sun May 14 12:31: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: 681907 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 82F75C7EE24 for ; Sun, 14 May 2023 12:37:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237436AbjENMhj (ORCPT ); Sun, 14 May 2023 08:37:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231472AbjENMhe (ORCPT ); Sun, 14 May 2023 08:37:34 -0400 Received: from sonic306-19.consmr.mail.ir2.yahoo.com (sonic306-19.consmr.mail.ir2.yahoo.com [77.238.176.205]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 470C32D68 for ; Sun, 14 May 2023 05:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1684067850; bh=qFvY2JFOmSq4Z+lRw0WQgKuCvuPeqtQx/L9EsUd7oWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=Ap94I2PWKPqMd9rRCgQ8jVmOa+eE2265+ka0nXYHgJM73TYfm5DR5dkh6AE+bsYv3sTcLfZ1ZtKMtSwztvm8sQYUX8FNJm6FEwo16h3bB2LpIrkhjPCw9cg7p6PUD2UQ0GBnKvIdxlSeTJyOKN+Orum1yJrOF8wpKryUEJ8kjvDI40JYAIvnRESXQLrMIYQYPhJaafO4ynlkV4Hj6Mp8PSXp74hYpEvk9Ubvil6W6oZGLxExWR14aMaCnqWGhnawL33P3XeW/EsigKEQj/O0UHsyLtfU9CTxyEKoBYk0hEy+8vd0DfTMFr9P3t+Cr8dXbd8Z+0o2Gma/+liar7dENg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1684067850; bh=LogvbTdi4dn1Hdfv+qy/CLbOlrMg659kLM33wQPo/Ky=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=RGqKNsM/xGfSTo3znIbKNJLpHqvzylIX0mJUwcXGWbCO7sl3qhscCkQSNItKx2m/Ou6ZeC8qftu/fFBQmt/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l.FRRm pPEgl9s5Jc5m5mNYM00IVp5BeRMYRKuQI9fUc6YKWOZtsfyO7QiAwsa.TA.ARahdeSVIXHixJlZI W4teFDZr5wNv4EO8GyF_XjBdMZTTQO3KqidKAXmFlXrHyeND3dzCrIrhr5kXGqpcjzXW9FCC26VS eBA6LepTNHGW8qk819LS5Zk1nQ2ONeNh.ZVhLJx7KnKK1mlSXSsqaqqKUbgB_ajBP8ro7ROxwa_U RYDV0iYGbcaA_JYJaPbE3pjocJ2xWSI4Q7LNYgFdBQIoTiEfPLJeThTp8t8Ay6kc8hbl8SOzhhn2 CbadxJs8kpVgOxf4wT10A0CuOS_853le7ZDariIN2._QILCCHLJju1ZEbyQ9wbhcltHyd4zbxjcU tUeHoXaTuvAizmP0.wvb0XWyWNFOx1c4UU1tv0Cp2IcFcWn0NT2o5moektmbnKpNIsV0SVWujp_y Z1RSnIxMiiAEUU36dUJ6ibWYxXu_n5V4- X-Sonic-MF: X-Sonic-ID: 810f99fe-6e5b-402e-9bbc-38b58df947d5 Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ir2.yahoo.com with HTTP; Sun, 14 May 2023 12:37:30 +0000 Received: by hermes--production-ir2-7867f454fc-tvsct (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID ec262f708c8ca7d1990bed607fb68ca2; Sun, 14 May 2023 12:37:26 +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 , Linus Walleij , Henrik Grimler , 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 v5 10/10] dt-bindings: Add rt5033 mfd, regulator and charger Date: Sun, 14 May 2023 14:31:30 +0200 Message-Id: <20230514123130.41172-11-jahau@rocketmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230514123130.41172-1-jahau@rocketmail.com> References: <20230514123130.41172-1-jahau@rocketmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 Reviewed-by: Linus Walleij Reviewed-by: Krzysztof Kozlowski --- The patch is based on torvalds/linux v6.4-rc1. The drivers for rt5033 (mfd) and rt5033-regulator are existing. Whereas the the driver rt5033-charger is new in this patchset. Changes in v5: - In file "richtek,rt5033-charger.yaml" fixed typo on "PMIC" in the title. - In the charger file changed the general "connector" property into vendor-specific "richtek,usb-connector". - In the charger file added $ref to phandle for "monitored-battery" and "richtek,usb-connector". - In charger file removed line "maxItems: 1" from property "richtek,usb-connector" because dt_binding_check complained about it. - In the mfd example added the "power-supplies" connection between fuel-gauge and charger. As the example fuel-gauge contains compatible "richtek,rt5033-battery", dt_binding_check was rather picky to implement that node completely. .../bindings/mfd/richtek,rt5033.yaml | 138 ++++++++++++++++++ .../power/supply/richtek,rt5033-charger.yaml | 65 +++++++++ 2 files changed, 203 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/richtek,rt5033.yaml create mode 100644 Documentation/devicetree/bindings/power/supply/richtek,rt5033-charger.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..386b1a50158a --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/richtek,rt5033.yaml @@ -0,0 +1,138 @@ +# 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: + 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. + type: object + patternProperties: + "^(SAFE_LDO|LDO|BUCK)$": + type: object + $ref: /schemas/regulator/regulator.yaml# + unevaluatedProperties: false + additionalProperties: false + + charger: + type: object + $ref: /schemas/power/supply/richtek,rt5033-charger.yaml# + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + #include + + battery: battery { + compatible = "simple-battery"; + precharge-current-microamp = <450000>; + constant-charge-current-max-microamp = <1000000>; + charge-term-current-microamp = <150000>; + precharge-upper-limit-microvolt = <3500000>; + constant-charge-voltage-max-microvolt = <4350000>; + }; + + extcon { + usb_con: connector { + compatible = "usb-b-connector"; + label = "micro-USB"; + type = "micro"; + }; + }; + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + i2c@0 { + #address-cells = <1>; + #size-cells = <0>; + reg = <0>; + + fuel-gauge@35 { + compatible = "richtek,rt5033-battery"; + reg = <0x35>; + + interrupt-parent = <&msmgpio>; + interrupts = <121 IRQ_TYPE_EDGE_FALLING>; + + pinctrl-names = "default"; + pinctrl-0 = <&fg_alert_default>; + + power-supplies = <&rt5033_charger>; + }; + }; + + i2c@1 { + #address-cells = <1>; + #size-cells = <0>; + reg = <1>; + + 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>; + }; + }; + + rt5033_charger: charger { + compatible = "richtek,rt5033-charger"; + monitored-battery = <&battery>; + richtek,usb-connector = <&usb_con>; + }; + }; + }; + }; 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..5b3edd79a523 --- /dev/null +++ b/Documentation/devicetree/bindings/power/supply/richtek,rt5033-charger.yaml @@ -0,0 +1,65 @@ +# 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 PMIC 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 + + monitored-battery: + $ref: /schemas/types.yaml#/definitions/phandle + description: | + Phandle to the monitored battery according to battery.yaml. The battery + node needs to contain five parameters. + + precharge-current-microamp: + Current of pre-charge mode. The pre-charge current levels are 350 mA + to 650 mA programmed by I2C per 100 mA. + + constant-charge-current-max-microamp: + Current of fast-charge mode. The fast-charge current levels are 700 mA + to 2000 mA programmed by I2C per 100 mA. + + charge-term-current-microamp: + 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. + + precharge-upper-limit-microvolt: + 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. + + constant-charge-voltage-max-microvolt: + Battery regulation voltage of constant voltage mode. This voltage levels + from 3.65 V to 4.4 V by I2C per 0.025 V. + + richtek,usb-connector: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Phandle to a USB connector according to usb-connector.yaml. The connector + should be a child of the extcon device. + +required: + - monitored-battery + +additionalProperties: false + +examples: + - | + charger { + compatible = "richtek,rt5033-charger"; + monitored-battery = <&battery>; + richtek,usb-connector = <&usb_con>; + };