From patchwork Wed Nov 23 17:54:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: saravanan sekar X-Patchwork-Id: 13054053 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 DC6D8C433FE for ; Wed, 23 Nov 2022 17:54:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237705AbiKWRyp (ORCPT ); Wed, 23 Nov 2022 12:54:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237461AbiKWRyo (ORCPT ); Wed, 23 Nov 2022 12:54:44 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A465861743; Wed, 23 Nov 2022 09:54:43 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id b29so17984714pfp.13; Wed, 23 Nov 2022 09:54:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q7SDO8Hfv8UNbCG9VUfErLc2iywPx7lgKEb1KGhgxPQ=; b=B8qFyvJ0ncXIpKh8Uz+tA+NVGOEhLdB35VewuYn15B+1aUQAzc1ojGCWU7dKUqfdG6 ixZeESZi4myMt3y5S4vc3gFlD78dPjPC3kmDr5HkElp4gqt5YeXrlDnBSIB3y/jnJDbu fp4TK2S1nH+lMs3RSAQPfcIaunm+jYc22HhOypMsBcdNF45ONzcV9X5OOjpmP7z/aMmn FppIwyOrCHDj4ht5hx6Mlv/grnF9OLNiAzlzin6t8/ioW2v3OaBxehYYUXHNxcjzmQ9K EvQjUulZFrdacDouK+Xv6HJnNKb1Hlqwnri5vH1p3hCJTima3kgmox4QWYkKOxZyJlZd HVDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q7SDO8Hfv8UNbCG9VUfErLc2iywPx7lgKEb1KGhgxPQ=; b=stuUsFP05VqjIM6oaZVxmqqCEg8dRnZH8JhFVHETH36uoXnFGlRefbhkDIDd2YOeoI rQrIgelpwLUfDOuzwtcPXHy6JdmIjcy0zdEafQqVulp/EJb2UFCno9Mnip39rfA6kb6w WcIXmPqbs4R7aJHiPB3Xz8SKPkkW3A7U3GyEf9yRnRmW5QFrJ8TLjIYjugAGnYCtgeEV 3lT2ZOyIzNuHAusq2OgOf76uLIRaIaNL7TZ7Y18Ap1izC2mZ/IE8bPm4jkkVWuOXIV7L M+CP+GSOsZ/r0Fxk0kXCBf4Ht9HHthtca0EpvKkyd3KnYNr1HJZ7Cuvrre3eGj5DP9q0 E6CA== X-Gm-Message-State: ANoB5pk5V5YaiVxUFRgwWJ0dJsUKsCbMWB0taypND5kNUOoEM1yGTLSp 7US4k/pvEimZt5sHGcz9gFBeenS75fE= X-Google-Smtp-Source: AA0mqf5+cnVz3hSy30L2DJBG/IkNjGN+e/YIar8DRBKJ7BNLNd/Ti0vZ7RCnhS12aQ8Op9gtkz/APA== X-Received: by 2002:a63:389:0:b0:477:7f68:bbbc with SMTP id 131-20020a630389000000b004777f68bbbcmr4199498pgd.279.1669226083192; Wed, 23 Nov 2022 09:54:43 -0800 (PST) Received: from discovery.. ([2401:4900:483b:e422:60e:77bf:baa2:9d8b]) by smtp.gmail.com with ESMTPSA id y76-20020a62644f000000b0057470a06694sm837503pfb.40.2022.11.23.09.54.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 09:54:42 -0800 (PST) From: Saravanan Sekar To: sre@kernel.org, lee@kernel.org, jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com Cc: linux-pm@vger.kernel.org, linux-iio@vger.kernel.org, Saravanan Sekar Subject: [PATCH v6 1/7] mfd: mp2629: fix failed to get iio channel by device name Date: Wed, 23 Nov 2022 18:54:19 +0100 Message-Id: <20221123175425.564042-2-sravanhome@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221123175425.564042-1-sravanhome@gmail.com> References: <20221123175425.564042-1-sravanhome@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The mfd cell devices name populated on sysfs entry is dynamically derived from an auto instance which introduced a regression. As a result mpc2629_charger driver failed to get adc channel because of iio consumer name mismatch with the sysfs. /sys/class/i2c-adapter/i2c-1/mp2629_adc.0.auto/ /sys/class/i2c-adapter/i2c-1/mp2629_charger.1.auto/ Fixes: 466a62d7642f ("mfd: core: Make a best effort attempt to match devices with the correct of_nodes") Signed-off-by: Saravanan Sekar --- drivers/mfd/mp2629.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mfd/mp2629.c b/drivers/mfd/mp2629.c index 16840ec5fd1c..f4c5aa06f38c 100644 --- a/drivers/mfd/mp2629.c +++ b/drivers/mfd/mp2629.c @@ -51,7 +51,7 @@ static int mp2629_probe(struct i2c_client *client) return PTR_ERR(ddata->regmap); } - ret = devm_mfd_add_devices(ddata->dev, PLATFORM_DEVID_AUTO, mp2629_cell, + ret = devm_mfd_add_devices(ddata->dev, PLATFORM_DEVID_NONE, mp2629_cell, ARRAY_SIZE(mp2629_cell), NULL, 0, NULL); if (ret) dev_err(ddata->dev, "Failed to register sub-devices %d\n", ret); From patchwork Wed Nov 23 17:54:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: saravanan sekar X-Patchwork-Id: 13054054 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 53A98C433FE for ; Wed, 23 Nov 2022 17:54:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238572AbiKWRyt (ORCPT ); Wed, 23 Nov 2022 12:54:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237461AbiKWRys (ORCPT ); Wed, 23 Nov 2022 12:54:48 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F3E36AEDA; Wed, 23 Nov 2022 09:54:48 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id 136so17420820pga.1; Wed, 23 Nov 2022 09:54:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZH0Qc9jkq5rdx+9MsswFw6fY0Pcj+rHLWBfTQ1gC3xE=; b=bSzfkZ91RRT95GKDEsYr040rfLq3/tNhJGmUkALs3tqr6/PUBUelP8T2iI3eRBXXRS W5CmmUzi02a6tBqR0Vl0LEq15kFsBNajis8R4U07kmaXyziOnEA0N0Eh1VGYYWgLju2Y NSer/a9rNnK4zC3NWAWIfDifeMoTBKR7ahbJVmnLll7AL7j/Umr+4OBeiDPNBiDHKp7B fkbMdcytezSkSYI7HHptXLYquVd5GcIDpCg3W7NKOoxRcTfZ8M8AClji2dFAUP4THzEN vEbYSdgBgDWd2hTxBPclb2xuci6fhclly4gsmz3ROVDcfitJ9dZVevo3whkhp3r8uKTu KBfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZH0Qc9jkq5rdx+9MsswFw6fY0Pcj+rHLWBfTQ1gC3xE=; b=POdA2cR1jSq1SNgaZGfTWtylgWYSH7DfJyNzZ05DE7DCK3UOrxb+PBcaX/Kk7CTemL L7LZxmfZ9oiS3I/ZZuDjut3O0pe6/TRDbEDD/09DqKbQUoVZ1/QinsV4r4+QEYU0gksY zq5M+wSR8oCI1hOKgO9D6NQrrkUxgzSt0aCl8EK62gYRccgmAMrWnoUhVKETS0mHKvU2 RfpZ86A+dPP0RWnP5VgPSRVnUxoeAoDWZ+UBiAHmGrbZGIEQIVhfUaKom9kWXnR2tZMU RMXtzavHsHPbtZNFqLZfvx6pZOZVlBuEy5v7XWo4D8H81r36xTOLPFfDcPW4Jb0aNZMq 5ekA== X-Gm-Message-State: ANoB5pm+c9AF6QwZZ6P7NRF5UjnbGq5tDGHe21B6NTm42J3cYHuItZWA 46n5fRhTc3IJWPRDCmrB6ew= X-Google-Smtp-Source: AA0mqf7YdadYIfWlr1MiOMG6p2VQbPoO7jqU51ydgFvs+e5KuEdOFD1kyrlLDjl2/YzZ+KUO+baytQ== X-Received: by 2002:a63:c65:0:b0:476:db6f:d436 with SMTP id 37-20020a630c65000000b00476db6fd436mr27393231pgm.394.1669226087686; Wed, 23 Nov 2022 09:54:47 -0800 (PST) Received: from discovery.. ([2401:4900:483b:e422:60e:77bf:baa2:9d8b]) by smtp.gmail.com with ESMTPSA id y76-20020a62644f000000b0057470a06694sm837503pfb.40.2022.11.23.09.54.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 09:54:47 -0800 (PST) From: Saravanan Sekar To: sre@kernel.org, lee@kernel.org, jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com Cc: linux-pm@vger.kernel.org, linux-iio@vger.kernel.org, Saravanan Sekar Subject: [PATCH v6 2/7] power: supply: fix wrong interpretation of register value Date: Wed, 23 Nov 2022 18:54:20 +0100 Message-Id: <20221123175425.564042-3-sravanhome@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221123175425.564042-1-sravanhome@gmail.com> References: <20221123175425.564042-1-sravanhome@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Fix the switch cases to match the register value. Signed-off-by: Saravanan Sekar Acked-by: Sebastian Reichel --- drivers/power/supply/mp2629_charger.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/mp2629_charger.c b/drivers/power/supply/mp2629_charger.c index bf9c27b463a8..46d620bd23b9 100644 --- a/drivers/power/supply/mp2629_charger.c +++ b/drivers/power/supply/mp2629_charger.c @@ -284,10 +284,10 @@ static int mp2629_charger_battery_get_prop(struct power_supply *psy, val->intval = POWER_SUPPLY_STATUS_DISCHARGING; break; case 0x01: - case 0x10: + case 0x02: val->intval = POWER_SUPPLY_STATUS_CHARGING; break; - case 0x11: + case 0x03: val->intval = POWER_SUPPLY_STATUS_FULL; } break; @@ -305,7 +305,7 @@ static int mp2629_charger_battery_get_prop(struct power_supply *psy, case 0x01: val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; break; - case 0x10: + case 0x02: val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD; break; default: From patchwork Wed Nov 23 17:54:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: saravanan sekar X-Patchwork-Id: 13054055 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 2578EC4332F for ; Wed, 23 Nov 2022 17:54:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238764AbiKWRyy (ORCPT ); Wed, 23 Nov 2022 12:54:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238639AbiKWRyx (ORCPT ); Wed, 23 Nov 2022 12:54:53 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D047064A2C; Wed, 23 Nov 2022 09:54:52 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id a1-20020a17090abe0100b00218a7df7789so2764013pjs.5; Wed, 23 Nov 2022 09:54:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=POR67NNOWOg5L0ub1cqdpDYlQnLokUngs3/LSYj03K0=; b=K88ASrwDTFK4OGChFmDH1LZtBUdGBGKG9j41LYJLOWnAbYk8fe1ZQSE5LLRDKmTLK4 2s4glEMHtObtvX13izlex/80fofnqLokFZ4+9A4IiuIsLUGCcEPTyRB8d2nrSUVaR+A0 7zcs8IA96gwwwlifelFXbovvYhS0CaBJwxp73+d9hthMUrCNX1cLieMxkn9rnJ4X0j1K ddrQP5jK+LNMNP3IRBVkgG/ISabCdlRckD+suCjBPPDz6xO6UatSyTHzoTGryHFj0VpG 0h26/Yt0oAY7+wqL8SM6Djt9VXd3bwQnmT0KXwih/PpQsYv4xSiSLndCIM1IMr6oPdey Sh9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=POR67NNOWOg5L0ub1cqdpDYlQnLokUngs3/LSYj03K0=; b=D6+zGyl97LtohsGknjS+sy4o04AKA1L9GBq/XxlhU5+phDy2zzK0JyfCD+4d4lv/wr nVssvL31GCpj6bKg+QdFT2GVvGjPVabqH24dNwBOGWZ1wDxhHajSz5q3clxFr2X1f8ps Q/9WakooWGvTitaGa8KV1LDrJ2cRgIHVzuAsK+eFXHhnmkpkAdinsSDaA1QQMe8o2Gnj zm990M2pjBaNqOtoB7DzYgdPDkGItsDJ6LXUEyOwGHe3uaWMeZNSIUNAb+Eidqro3+8t KVvTYD4kDDMq9ycjnD+oGMdqXf65f0SsKKJmBhxsTRYJfUt2JhT6N6eSKfukFPfd27PO MWJg== X-Gm-Message-State: ANoB5pm1wL6V7AIcaHJAbRUKmh7CzVKR6HPdXEgkNXd0wQzgUeoBakv3 +02if2TPPo+r1xD5d6eyPb6AfTUHml4= X-Google-Smtp-Source: AA0mqf6frPtH2L1iIleqUdyaFNUp/p4wFW/uiXFyonXhv6aMaL1JrFfFIAl1CqOYz8N0iuIwp5PAGQ== X-Received: by 2002:a17:902:ce82:b0:186:ed91:5086 with SMTP id f2-20020a170902ce8200b00186ed915086mr9795463plg.59.1669226092356; Wed, 23 Nov 2022 09:54:52 -0800 (PST) Received: from discovery.. ([2401:4900:483b:e422:60e:77bf:baa2:9d8b]) by smtp.gmail.com with ESMTPSA id y76-20020a62644f000000b0057470a06694sm837503pfb.40.2022.11.23.09.54.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 09:54:51 -0800 (PST) From: Saravanan Sekar To: sre@kernel.org, lee@kernel.org, jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com Cc: linux-pm@vger.kernel.org, linux-iio@vger.kernel.org, Saravanan Sekar Subject: [PATCH v6 3/7] mfd: mp2629: introduce chip id machanism to distinguish chip Date: Wed, 23 Nov 2022 18:54:21 +0100 Message-Id: <20221123175425.564042-4-sravanhome@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221123175425.564042-1-sravanhome@gmail.com> References: <20221123175425.564042-1-sravanhome@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Introduce chip id machanism to distinguish chip Signed-off-by: Saravanan Sekar Reviewed-by: Andy Shevchenko --- drivers/mfd/mp2629.c | 4 +++- include/linux/mfd/mp2629.h | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/mfd/mp2629.c b/drivers/mfd/mp2629.c index f4c5aa06f38c..a3fc02ad5ec1 100644 --- a/drivers/mfd/mp2629.c +++ b/drivers/mfd/mp2629.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -43,6 +44,7 @@ static int mp2629_probe(struct i2c_client *client) return -ENOMEM; ddata->dev = &client->dev; + ddata->chip_id = (uintptr_t)device_get_match_data(&client->dev); i2c_set_clientdata(client, ddata); ddata->regmap = devm_regmap_init_i2c(client, &mp2629_regmap_config); @@ -60,7 +62,7 @@ static int mp2629_probe(struct i2c_client *client) } static const struct of_device_id mp2629_of_match[] = { - { .compatible = "mps,mp2629"}, + { .compatible = "mps,mp2629", .data = (void *)CHIP_ID_MP2629 }, { } }; MODULE_DEVICE_TABLE(of, mp2629_of_match); diff --git a/include/linux/mfd/mp2629.h b/include/linux/mfd/mp2629.h index 89b706900b57..072c8181b48b 100644 --- a/include/linux/mfd/mp2629.h +++ b/include/linux/mfd/mp2629.h @@ -9,9 +9,14 @@ #include #include +enum mp2xx_chip_id { + CHIP_ID_MP2629, +}; + struct mp2629_data { struct device *dev; struct regmap *regmap; + enum mp2xx_chip_id chip_id; }; enum mp2629_adc_chan { From patchwork Wed Nov 23 17:54:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: saravanan sekar X-Patchwork-Id: 13054057 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 B9677C3A59F for ; Wed, 23 Nov 2022 17:55:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239286AbiKWRzI (ORCPT ); Wed, 23 Nov 2022 12:55:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238557AbiKWRy7 (ORCPT ); Wed, 23 Nov 2022 12:54:59 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAD0E6F349; Wed, 23 Nov 2022 09:54:57 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id z26so18025416pff.1; Wed, 23 Nov 2022 09:54:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LqRBdYQ0hW2GoJp2mDn0xBVx5Bwku/wXXuv0oUxCzNw=; b=E6ewgTv8yHrViH1SfPXTgR9/FuFvPVwgYlCxFp+KCu6kQ/U+QM5N905rlsMIya3DYy CGzCZThzxWxL0LA/si+Ee4w5AdQ6hc+gJuSx67Fd6fdNYlWVgEba0ZSv946EwYnW+79/ 1Kmm2A1JDMyqXC7WQ57YqNM/4nUDFEXe/y3Za3eOxeDErB/7AlTlVE/KaCaXh3fLzOCV R3dEDnRFSkmfKYWcXPlVI4DDD++WGHmfXQk2zT8s3+Nas1XaS0KfyuX2tLuuER/F4vPh CWn1PCDd6uWnvShEnIGIWqmHvTK5Ms4Bq0PJxymnd9QA65LcK5IU17/YOmBEj447Aw5T I91w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LqRBdYQ0hW2GoJp2mDn0xBVx5Bwku/wXXuv0oUxCzNw=; b=2UyIf7P3f430CcrxlCdDOAx3JZ7J279JmK6VtVxGlbfOljXmY/s5322eTgd6dpusGF UDHLM5ks9MZHlHBsBx+15xBAlSgNY4IPCcTh90rwTNhCbyF//oF0VRaIBVzqR5sS5fJd X8SCeHYF7hMufIiA6KQ8iqmeKXvp0nYQIgvtM9Q7sAat+YsMuyFCrHnukLGD5ep0EyjL m32bu6wiuPdPQB3wEK1VZnMkODuXTWs80v0rJ22/mBGhfRM/SbsqIbkTe8adCKrYSU8R LON2YOAuxHP11plwoYzyNW8CCzHKmBXO2TQgMX24Vr/xexob43CiCEuDZ64k+NF3EqvT iPWw== X-Gm-Message-State: ANoB5pny3WbpoXnkX3bD8AYbHAJovedYmchb3Xp2MSc2vgB67cjISb2V f4k3tvbVNLm4HpMvtQ6KE5BgzT8cMUY= X-Google-Smtp-Source: AA0mqf6tmbdKAoeAmkyVRcXlL6n6RnrqEIQ9SfY5AZ3pfcKyUbjLdmw3yjZaqH7VTAf0vUWcRPQXMQ== X-Received: by 2002:a63:4d0d:0:b0:477:14ea:cee6 with SMTP id a13-20020a634d0d000000b0047714eacee6mr8264902pgb.303.1669226097387; Wed, 23 Nov 2022 09:54:57 -0800 (PST) Received: from discovery.. ([2401:4900:483b:e422:60e:77bf:baa2:9d8b]) by smtp.gmail.com with ESMTPSA id y76-20020a62644f000000b0057470a06694sm837503pfb.40.2022.11.23.09.54.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 09:54:56 -0800 (PST) From: Saravanan Sekar To: sre@kernel.org, lee@kernel.org, jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com Cc: linux-pm@vger.kernel.org, linux-iio@vger.kernel.org, Saravanan Sekar Subject: [PATCH v6 4/7] mfd: mp2629: Add support for mps mp2733 battery charger Date: Wed, 23 Nov 2022 18:54:22 +0100 Message-Id: <20221123175425.564042-5-sravanhome@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221123175425.564042-1-sravanhome@gmail.com> References: <20221123175425.564042-1-sravanhome@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org mp2733 is updated version of mp2629 battery charge management device for single-cell Li-ion or Li-polymer battery. Additionally supports USB fast-charge and higher range of input voltage. Signed-off-by: Saravanan Sekar Reviewed-by: Andy Shevchenko --- drivers/mfd/mp2629.c | 1 + include/linux/mfd/mp2629.h | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/mfd/mp2629.c b/drivers/mfd/mp2629.c index a3fc02ad5ec1..57db0f5009b9 100644 --- a/drivers/mfd/mp2629.c +++ b/drivers/mfd/mp2629.c @@ -63,6 +63,7 @@ static int mp2629_probe(struct i2c_client *client) static const struct of_device_id mp2629_of_match[] = { { .compatible = "mps,mp2629", .data = (void *)CHIP_ID_MP2629 }, + { .compatible = "mps,mp2733", .data = (void *)CHIP_ID_MP2733 }, { } }; MODULE_DEVICE_TABLE(of, mp2629_of_match); diff --git a/include/linux/mfd/mp2629.h b/include/linux/mfd/mp2629.h index 072c8181b48b..ee0e65720c75 100644 --- a/include/linux/mfd/mp2629.h +++ b/include/linux/mfd/mp2629.h @@ -11,6 +11,7 @@ enum mp2xx_chip_id { CHIP_ID_MP2629, + CHIP_ID_MP2733, }; struct mp2629_data { From patchwork Wed Nov 23 17:54:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: saravanan sekar X-Patchwork-Id: 13054056 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 828E6C47088 for ; Wed, 23 Nov 2022 17:55:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239307AbiKWRzJ (ORCPT ); Wed, 23 Nov 2022 12:55:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239207AbiKWRzH (ORCPT ); Wed, 23 Nov 2022 12:55:07 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28340B97CF; Wed, 23 Nov 2022 09:55:02 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id l22-20020a17090a3f1600b00212fbbcfb78so2774524pjc.3; Wed, 23 Nov 2022 09:55:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Sa9+zB2hHRJShe6/SZl8Kai19estoaLiBOw5LdWRhFM=; b=i1mnF3o9X2VVwhcc/7mMkcUzGBgFLXlUVrVryPxRvZVsboC0Rm6ZtiAC47G13l29v3 QlAI45XfTHCQeT/uWgld7yZY0122erVTLAgKPzLOFtPIpDRi7fTCuSU6iU0nSvpMBbxU /5JGmSUYmEWuvYa4/55dWhFarMPXtnfJYKECPD0CkybsHQ+GBVFnPHxRe/b/20qWS9TM UuhGzgezb8h3iVXmpMM0raRV38ya4qirlq64bspEZQCl5MmagksPUJY/ApqAS5W2x+uZ 1vZcgd0KsrjJo4E1dgVWDF4oa6LIAJ1EVFhTlGJYA78XD3dJ78kjjZj2mVbSrO34mdrd PPRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Sa9+zB2hHRJShe6/SZl8Kai19estoaLiBOw5LdWRhFM=; b=vHZ7krtrk7HpzcJGnOGx4mF64BpsTLhgChr2fZ5tyQXjjxdZusKZqhUWRAdEyGosqs eWILvFOZRZrIfj4d/Uq/Ps+ltCO6Rh2Lcm9Pfxp6+7RYW9VzKM/W4gu2Z/TmzVHVSHfR Nh+vEzlC5ttB/7p30hpnGALZgMURNaobcLuf4habeKL9h06pXqN0YhclMTIatoqTdDmw Nfq+qwO5wvhUYJEUr0td+8dz2/KM336lNT2dsXEaItpKogh09TFJy5ufH/aSLYoavvk6 DgI+Nk23XlxDLkOQ4L1E3pAIDQ688zcTtZr3wbBkgd16IdCj89K0mwFCBpODdJdH9h/u gg+A== X-Gm-Message-State: ANoB5plL83w7SEZo/s6u/Y8/ITRP4YAbr5OzyrugM9mL7qCRlHz5njHY spoeollx3ubMzzys3jVMy53RV6RW+hs= X-Google-Smtp-Source: AA0mqf6G/6YAi7FR4gkYG/ewDYRZ832a02qcb3kGoos+y+LKdcuH19EwQgU6xU5ZkvW9mk3IfneIlA== X-Received: by 2002:a17:902:ce90:b0:186:6d34:b7b5 with SMTP id f16-20020a170902ce9000b001866d34b7b5mr13021371plg.37.1669226101693; Wed, 23 Nov 2022 09:55:01 -0800 (PST) Received: from discovery.. ([2401:4900:483b:e422:60e:77bf:baa2:9d8b]) by smtp.gmail.com with ESMTPSA id y76-20020a62644f000000b0057470a06694sm837503pfb.40.2022.11.23.09.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 09:55:01 -0800 (PST) From: Saravanan Sekar To: sre@kernel.org, lee@kernel.org, jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com Cc: linux-pm@vger.kernel.org, linux-iio@vger.kernel.org, Saravanan Sekar , Jonathan Cameron Subject: [PATCH v6 5/7] iio: adc: mp2629: restrict input voltage mask for mp2629 Date: Wed, 23 Nov 2022 18:54:23 +0100 Message-Id: <20221123175425.564042-6-sravanhome@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221123175425.564042-1-sravanhome@gmail.com> References: <20221123175425.564042-1-sravanhome@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add support for mp2733 which is updated version of mp2629 with a higher range of input voltage. Signed-off-by: Saravanan Sekar Reviewed-by: Andy Shevchenko Acked-by: Jonathan Cameron --- drivers/iio/adc/mp2629_adc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/mp2629_adc.c b/drivers/iio/adc/mp2629_adc.c index 88e947f300cf..18290e176e1e 100644 --- a/drivers/iio/adc/mp2629_adc.c +++ b/drivers/iio/adc/mp2629_adc.c @@ -66,6 +66,7 @@ static int mp2629_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct mp2629_adc *info = iio_priv(indio_dev); + struct mp2629_data *ddata = dev_get_drvdata(info->dev); unsigned int rval; int ret; @@ -75,8 +76,10 @@ static int mp2629_read_raw(struct iio_dev *indio_dev, if (ret) return ret; - if (chan->channel == MP2629_INPUT_VOLT) + if (chan->channel == MP2629_INPUT_VOLT && + ddata->chip_id == CHIP_ID_MP2629) rval &= GENMASK(6, 0); + *val = rval; return IIO_VAL_INT; From patchwork Wed Nov 23 17:54:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: saravanan sekar X-Patchwork-Id: 13054058 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 999E7C433FE for ; Wed, 23 Nov 2022 17:55:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239279AbiKWRzP (ORCPT ); Wed, 23 Nov 2022 12:55:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239298AbiKWRzJ (ORCPT ); Wed, 23 Nov 2022 12:55:09 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAFB76A6AE; Wed, 23 Nov 2022 09:55:07 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id f9so13180040pgf.7; Wed, 23 Nov 2022 09:55:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=orj5zmzIKR7QW+91Ap7/jvHRciPjHKTw/L4LGYwZM1o=; b=PC7675NGGmpHBZx19VsvHHuOIFN6FjIKPh3S5/f3G7cWSfOlFtVp3m8Od/6kGfd9EC ZRxH+9JmyDa5YV6+UOzb+NITucMv0s94JNf/cPA14JFeXDZDM9a21bE/19HQXsxmGXIb pDu+ngVGr+FIwnMxmaUuwVoj/wNR4d3xmk/5CUyGLWe5l62uLtWLBTvBto+54DjoAHzR jE32eunuJKYjQcPG0+w8Xm4h7P5/+fy03cj9s2EXAyZ2OXZSO5gV1ibcIpnTZDXnBLCW xwvyG20XHH0ljuWCjeMycO38wIc+TbReGlo3Far37Ih2g024oq/IgHuB4p6FZKizNsKA QRBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=orj5zmzIKR7QW+91Ap7/jvHRciPjHKTw/L4LGYwZM1o=; b=IpDt65ztnSbwtE8ZofAUR+d0WQYH68DzA+8SuVara1Csm9/JhMsHbmsdD2qIYwo500 rYYRXu92ifr5DpG47ywYfTgaKz/o60e0y48CFUaZgfmhYLMz5wkEixlpZh4qeYLyU+W3 e5K5GKxh4oounO7Jaq5efyeDOZMruGBKHuqpkK7mTl+RhVsnPhnCWdkxGjT/VDw9KGVN Y/wyOcnrcKfkAt1Sb9nsh8WiLFYrZoTdzD2SwNnmuQXu6PKQfjLCw7wha+1hyVPepTho /84xaBLLOcPdiIQZyv8u49u3U5bzD4E0RmeHJYOeEGAFmuHhTKPZoTAapTgMM5GLw++F vTjg== X-Gm-Message-State: ANoB5pkZ2k+j9EYI5nzj4MLU5RVhpDItR8yQM9E9ZE3THDN1862Hyxvw haGjEPeDZvVaEOI2B1GOc0pSpBBJYkE= X-Google-Smtp-Source: AA0mqf7+utv1EwXC+8WhgpzCtOzmO5tUdQsZLuqGnmT9WaC6cjxZ7J1yEnd0bETZufkOzi2BNEXxog== X-Received: by 2002:aa7:9245:0:b0:571:3fb3:9b5f with SMTP id 5-20020aa79245000000b005713fb39b5fmr31072791pfp.86.1669226107396; Wed, 23 Nov 2022 09:55:07 -0800 (PST) Received: from discovery.. ([2401:4900:483b:e422:60e:77bf:baa2:9d8b]) by smtp.gmail.com with ESMTPSA id y76-20020a62644f000000b0057470a06694sm837503pfb.40.2022.11.23.09.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 09:55:06 -0800 (PST) From: Saravanan Sekar To: sre@kernel.org, lee@kernel.org, jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com Cc: linux-pm@vger.kernel.org, linux-iio@vger.kernel.org, Saravanan Sekar , Sebastian Reichel Subject: [PATCH v6 6/7] power: supply: Add support for mp2733 battery charger Date: Wed, 23 Nov 2022 18:54:24 +0100 Message-Id: <20221123175425.564042-7-sravanhome@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221123175425.564042-1-sravanhome@gmail.com> References: <20221123175425.564042-1-sravanhome@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org mp2733 is updated version of mp2629 battery charge management which supports USB fast-charge and higher range of input voltage. Signed-off-by: Saravanan Sekar Reviewed-by: Andy Shevchenko Acked-by: Sebastian Reichel --- drivers/power/supply/mp2629_charger.c | 223 ++++++++++++++++++++++---- 1 file changed, 192 insertions(+), 31 deletions(-) diff --git a/drivers/power/supply/mp2629_charger.c b/drivers/power/supply/mp2629_charger.c index 46d620bd23b9..2ff3729afc48 100644 --- a/drivers/power/supply/mp2629_charger.c +++ b/drivers/power/supply/mp2629_charger.c @@ -30,12 +30,15 @@ #define MP2629_REG_INTERRUPT 0x0b #define MP2629_REG_STATUS 0x0c #define MP2629_REG_FAULT 0x0d +#define MP2629_REG_FAST_CHARGE 0x17 #define MP2629_MASK_INPUT_TYPE GENMASK(7, 5) #define MP2629_MASK_CHARGE_TYPE GENMASK(4, 3) #define MP2629_MASK_CHARGE_CTRL GENMASK(5, 4) #define MP2629_MASK_WDOG_CTRL GENMASK(5, 4) #define MP2629_MASK_IMPEDANCE GENMASK(7, 4) +#define MP2733_MASK_FAST_CHARGE GENMASK(2, 1) +#define MP2733_MASK_FAST_CHARGE_RESET BIT(0) #define MP2629_INPUTSOURCE_CHANGE GENMASK(7, 5) #define MP2629_CHARGING_CHANGE GENMASK(4, 3) @@ -62,6 +65,17 @@ enum mp2629_source_type { MP2629_SOURCE_TYPE_OTG = 7, }; +enum mp2733_source_type { + MP2733_SOURCE_TYPE_NO_INPUT, + MP2733_SOURCE_TYPE_NON_STD, + MP2733_SOURCE_TYPE_APPLE_1p0, + MP2733_SOURCE_TYPE_APPLE_2p1, + MP2733_SOURCE_TYPE_APPLE_2p4, + MP2733_SOURCE_TYPE_SDP, + MP2733_SOURCE_TYPE_CDP, + MP2733_SOURCE_TYPE_DCP, +}; + enum mp2629_field { INPUT_ILIM, INPUT_VLIM, @@ -72,11 +86,30 @@ enum mp2629_field { MP2629_MAX_FIELD }; +struct mp2629_prop { + int reg; + int mask; + int min; + int max; + int step; + int shift; +}; + +struct mp2xx_chip_info { + const struct reg_field *rfields; + struct mp2629_prop *chip_props; + bool has_impedance; + bool has_fast_charge; + + int (*mp2xx_get_usb_type)(unsigned int rval); +}; + struct mp2629_charger { struct device *dev; int status; int fault; + const struct mp2xx_chip_info *chip_info; struct regmap *regmap; struct regmap_field *regmap_fields[MP2629_MAX_FIELD]; struct mutex lock; @@ -85,15 +118,6 @@ struct mp2629_charger { struct iio_channel *iiochan[MP2629_ADC_CHAN_END]; }; -struct mp2629_prop { - int reg; - int mask; - int min; - int max; - int step; - int shift; -}; - static enum power_supply_usb_type mp2629_usb_types[] = { POWER_SUPPLY_USB_TYPE_SDP, POWER_SUPPLY_USB_TYPE_DCP, @@ -126,7 +150,25 @@ static enum power_supply_property mp2629_charger_bat_props[] = { POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, }; -static struct mp2629_prop props[] = { +static struct mp2629_prop mp2733_chip_props[] = { + MP2629_PROPS(INPUT_ILIM, 100000, 3250000, 50000), + MP2629_PROPS(INPUT_VLIM, 3800000, 15200000, 100000), + MP2629_PROPS(CHARGE_ILIM, 320000, 4520000, 40000), + MP2629_PROPS(CHARGE_VLIM, 3400000, 4670000, 10000), + MP2629_PROPS(PRECHARGE, 120000, 720000, 40000), + MP2629_PROPS(TERM_CURRENT, 80000, 680000, 40000), +}; + +static const struct reg_field mp2733_reg_fields[] = { + [INPUT_ILIM] = REG_FIELD(MP2629_REG_INPUT_ILIM, 0, 5), + [INPUT_VLIM] = REG_FIELD(MP2629_REG_INPUT_VLIM, 0, 6), + [CHARGE_ILIM] = REG_FIELD(MP2629_REG_CHARGE_ILIM, 0, 6), + [CHARGE_VLIM] = REG_FIELD(MP2629_REG_CHARGE_VLIM, 1, 7), + [PRECHARGE] = REG_FIELD(MP2629_REG_PRECHARGE, 4, 7), + [TERM_CURRENT] = REG_FIELD(MP2629_REG_TERM_CURRENT, 0, 3), +}; + +static struct mp2629_prop mp2629_chip_props[] = { MP2629_PROPS(INPUT_ILIM, 100000, 3250000, 50000), MP2629_PROPS(INPUT_VLIM, 3800000, 5300000, 100000), MP2629_PROPS(CHARGE_ILIM, 320000, 4520000, 40000), @@ -174,6 +216,7 @@ static int mp2629_get_prop(struct mp2629_charger *charger, { int ret; unsigned int rval; + struct mp2629_prop *props = charger->chip_info->chip_props; ret = regmap_field_read(charger->regmap_fields[fld], &rval); if (ret) @@ -189,6 +232,7 @@ static int mp2629_set_prop(struct mp2629_charger *charger, const union power_supply_propval *val) { unsigned int rval; + struct mp2629_prop *props = charger->chip_info->chip_props; if (val->intval < props[fld].min || val->intval > props[fld].max) return -EINVAL; @@ -311,6 +355,16 @@ static int mp2629_charger_battery_get_prop(struct power_supply *psy, default: val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; } + + if (charger->chip_info->has_fast_charge) { + ret = regmap_read(charger->regmap, + MP2629_REG_FAST_CHARGE, &rval); + if (ret) + break; + + if (rval & BIT(6)) + val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST; + } break; default: @@ -344,6 +398,40 @@ static int mp2629_charger_battery_set_prop(struct power_supply *psy, } } +static int mp2733_get_usb_type(unsigned int rval) +{ + switch (rval) { + case MP2733_SOURCE_TYPE_APPLE_1p0: + case MP2733_SOURCE_TYPE_APPLE_2p1: + case MP2733_SOURCE_TYPE_APPLE_2p4: + return POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID; + case MP2733_SOURCE_TYPE_SDP: + return POWER_SUPPLY_USB_TYPE_SDP; + case MP2733_SOURCE_TYPE_CDP: + return POWER_SUPPLY_USB_TYPE_CDP; + case MP2733_SOURCE_TYPE_DCP: + return POWER_SUPPLY_USB_TYPE_DCP; + default: + return POWER_SUPPLY_USB_TYPE_UNKNOWN; + } +} + +static int mp2629_get_usb_type(unsigned int rval) +{ + switch (rval) { + case MP2629_SOURCE_TYPE_SDP: + return POWER_SUPPLY_USB_TYPE_SDP; + case MP2629_SOURCE_TYPE_CDP: + return POWER_SUPPLY_USB_TYPE_CDP; + case MP2629_SOURCE_TYPE_DCP: + return POWER_SUPPLY_USB_TYPE_DCP; + case MP2629_SOURCE_TYPE_OTG: + return POWER_SUPPLY_USB_TYPE_PD_DRP; + default: + return POWER_SUPPLY_USB_TYPE_UNKNOWN; + } +} + static int mp2629_charger_usb_get_prop(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -367,23 +455,7 @@ static int mp2629_charger_usb_get_prop(struct power_supply *psy, break; rval = (rval & MP2629_MASK_INPUT_TYPE) >> 5; - switch (rval) { - case MP2629_SOURCE_TYPE_SDP: - val->intval = POWER_SUPPLY_USB_TYPE_SDP; - break; - case MP2629_SOURCE_TYPE_CDP: - val->intval = POWER_SUPPLY_USB_TYPE_CDP; - break; - case MP2629_SOURCE_TYPE_DCP: - val->intval = POWER_SUPPLY_USB_TYPE_DCP; - break; - case MP2629_SOURCE_TYPE_OTG: - val->intval = POWER_SUPPLY_USB_TYPE_PD_DRP; - break; - default: - val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN; - break; - } + val->intval = charger->chip_info->mp2xx_get_usb_type(rval); break; case POWER_SUPPLY_PROP_VOLTAGE_NOW: @@ -550,11 +622,72 @@ static ssize_t batt_impedance_compensation_store(struct device *dev, static DEVICE_ATTR_RW(batt_impedance_compensation); -static struct attribute *mp2629_charger_sysfs_attrs[] = { +static struct attribute *mp2xx_batt_imp_sysfs_attrs[] = { + &dev_attr_batt_impedance_compensation.attr, + NULL +}; +ATTRIBUTE_GROUPS(mp2xx_batt_imp_sysfs); + +static ssize_t usb_fast_charge_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct mp2629_charger *charger = dev_get_drvdata(dev->parent); + unsigned int rval; + int ret; + + ret = regmap_read(charger->regmap, MP2629_REG_INTERRUPT, &rval); + if (ret) + return ret; + + return sysfs_emit(buf, "USB DP %u:DM %u\n", !!(rval & BIT(2)), + !!(rval & BIT(1))); +} + +static ssize_t usb_fast_charge_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t count) +{ + struct mp2629_charger *charger = dev_get_drvdata(dev->parent); + unsigned int val; + int ret; + + ret = kstrtouint(buf, 10, &val); + if (ret) + return ret; + + if (val > 3) + return -ERANGE; + + ret = regmap_update_bits(charger->regmap, MP2629_REG_INTERRUPT, + MP2733_MASK_FAST_CHARGE, val << 1); + if (ret) + return ret; + + ret = regmap_update_bits(charger->regmap, MP2629_REG_INTERRUPT, + MP2733_MASK_FAST_CHARGE_RESET, + MP2733_MASK_FAST_CHARGE_RESET); + if (ret) + return ret; + + return count; +} + +static DEVICE_ATTR_RW(usb_fast_charge); + +static struct attribute *mp2xx_fast_charge_sysfs_attrs[] = { + &dev_attr_usb_fast_charge.attr, + NULL +}; +ATTRIBUTE_GROUPS(mp2xx_fast_charge_sysfs); + +static struct attribute *mp2xx_all_sysfs_attrs[] = { + &dev_attr_usb_fast_charge.attr, &dev_attr_batt_impedance_compensation.attr, NULL }; -ATTRIBUTE_GROUPS(mp2629_charger_sysfs); +ATTRIBUTE_GROUPS(mp2xx_all_sysfs); static void mp2629_charger_disable(void *data) { @@ -564,6 +697,23 @@ static void mp2629_charger_disable(void *data) MP2629_MASK_CHARGE_CTRL, 0); } +static const struct mp2xx_chip_info mp2xx_chip_info_tbl[] = { + [CHIP_ID_MP2629] = { + .rfields = mp2629_reg_fields, + .chip_props = mp2629_chip_props, + .has_impedance = 1, + + .mp2xx_get_usb_type = mp2629_get_usb_type, + }, + [CHIP_ID_MP2733] = { + .rfields = mp2733_reg_fields, + .chip_props = mp2733_chip_props, + .has_fast_charge = 1, + + .mp2xx_get_usb_type = mp2733_get_usb_type, + }, +}; + static int mp2629_charger_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -578,6 +728,7 @@ static int mp2629_charger_probe(struct platform_device *pdev) charger->regmap = ddata->regmap; charger->dev = dev; + charger->chip_info = &mp2xx_chip_info_tbl[ddata->chip_id]; platform_set_drvdata(pdev, charger); irq = platform_get_irq(to_platform_device(dev->parent), 0); @@ -586,7 +737,8 @@ static int mp2629_charger_probe(struct platform_device *pdev) for (i = 0; i < MP2629_MAX_FIELD; i++) { charger->regmap_fields[i] = devm_regmap_field_alloc(dev, - charger->regmap, mp2629_reg_fields[i]); + charger->regmap, + charger->chip_info->rfields[i]); if (IS_ERR(charger->regmap_fields[i])) { dev_err(dev, "regmap field alloc fail %d\n", i); return PTR_ERR(charger->regmap_fields[i]); @@ -613,7 +765,16 @@ static int mp2629_charger_probe(struct platform_device *pdev) } psy_cfg.drv_data = charger; - psy_cfg.attr_grp = mp2629_charger_sysfs_groups; + + if (charger->chip_info->has_impedance && + charger->chip_info->has_fast_charge) { + psy_cfg.attr_grp = mp2xx_all_sysfs_groups; + } else if (charger->chip_info->has_impedance) { + psy_cfg.attr_grp = mp2xx_batt_imp_sysfs_groups; + } else if (charger->chip_info->has_fast_charge) { + psy_cfg.attr_grp = mp2xx_fast_charge_sysfs_groups; + } + charger->battery = devm_power_supply_register(dev, &mp2629_battery_desc, &psy_cfg); if (IS_ERR(charger->battery)) { From patchwork Wed Nov 23 17:54:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: saravanan sekar X-Patchwork-Id: 13054059 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 8EEDFC4332F for ; Wed, 23 Nov 2022 17:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238557AbiKWRzS (ORCPT ); Wed, 23 Nov 2022 12:55:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239176AbiKWRzO (ORCPT ); Wed, 23 Nov 2022 12:55:14 -0500 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3767DC6548; Wed, 23 Nov 2022 09:55:13 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id w79so228175pfc.2; Wed, 23 Nov 2022 09:55:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m+M3x55LJlAjHZJKxmYKxIY2+MF/c7xVWLTdidtcZn4=; b=b3UVpwmGo3F4HCcrN0/3YXUiCz7Qzq3EIzUyux4zu/Usmg51yIMJPmFtWtDggK5S8f lI7LCMtHp6E4jtx8gmyI6gf+W+JkDqmnj1lzEpw6aljSLBTxQSWf4bwohTD8XuCTc72+ ZMI+8nXMEQWnigyxM8sbRT5SDl9drWpXk+7WnD1g+PWIQ+j0AAq5yAnn1nAcTTq2aD0y J4beUJeALB/LOaDYXzGQkwBVW5nx1PNGE8xi39oyvqEdVzhNUn7VXdklTspp9F/j+LEZ Lw75eYUc6vhLzC1COtFM8sWQamshZHMbMq2wm+/vn7wOPmPuEL0Bc1HrpNiFNWN9C7gR DDhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m+M3x55LJlAjHZJKxmYKxIY2+MF/c7xVWLTdidtcZn4=; b=4El3w7xoCSZM53StdczRDO8fF0OT6zzIXqaUXuHXG3sbbswjKlauejM+rbKHZATqhF TDyEm+qXHqe9DTozOfNY98Vk4CvRGVQ9HlW2ECYqAcmBWJJPodWbRdbVKzWCDvcgiQo1 q0is8f5LeF3u6UIiVsPYwjzPQQnxNSXSpF3CkTQqWX/PovMSfAtj3600WSzBlxVHC9p2 UX+Bn2UwxOYGylFF8dQZNNyIyOdxiN0tPvsi8pgPZRsYXLPTQupe7FW5ooiCHNGuwhB6 ZXjfKxOu+6MODYAQvGwF8w8khYsEzr2sGcNNfvlNscgePKgSYu58A7NYsBa76hx4Wwgu 31CQ== X-Gm-Message-State: ANoB5pnGXIeFxnKFcA6AbIt7KhPCpnm9EcUX2Ix8La9fg078L935EC3J ZGGoBBP1ssp5MYABY3/iPao= X-Google-Smtp-Source: AA0mqf58zOVYwaWP7qDZBa6fJLF9D8FVab+2rjJ66s8oQ+tlRPc9N//pjAKRFg6ppcYOMchpCNVlIQ== X-Received: by 2002:a62:2544:0:b0:565:b27d:1f61 with SMTP id l65-20020a622544000000b00565b27d1f61mr19760787pfl.85.1669226112706; Wed, 23 Nov 2022 09:55:12 -0800 (PST) Received: from discovery.. ([2401:4900:483b:e422:60e:77bf:baa2:9d8b]) by smtp.gmail.com with ESMTPSA id y76-20020a62644f000000b0057470a06694sm837503pfb.40.2022.11.23.09.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 09:55:12 -0800 (PST) From: Saravanan Sekar To: sre@kernel.org, lee@kernel.org, jic23@kernel.org, lars@metafoo.de, andy.shevchenko@gmail.com Cc: linux-pm@vger.kernel.org, linux-iio@vger.kernel.org, Saravanan Sekar , Sebastian Reichel Subject: [PATCH v6 7/7] power: supply: mp2629: Add USB fast charge settings Date: Wed, 23 Nov 2022 18:54:25 +0100 Message-Id: <20221123175425.564042-8-sravanhome@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221123175425.564042-1-sravanhome@gmail.com> References: <20221123175425.564042-1-sravanhome@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Allows the user to change the USB device fast charge setting to advertise host on enumeration helps to accelerate the charging cycle. Altering this value resets USB existing connection. Signed-off-by: Saravanan Sekar Reviewed-by: Andy Shevchenko Acked-by: Sebastian Reichel --- .../ABI/testing/sysfs-class-power-mp2629 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-power-mp2629 b/Documentation/ABI/testing/sysfs-class-power-mp2629 index 914d67caac0d..40abb9a11d97 100644 --- a/Documentation/ABI/testing/sysfs-class-power-mp2629 +++ b/Documentation/ABI/testing/sysfs-class-power-mp2629 @@ -1,3 +1,19 @@ +What: /sys/class/power_supply/mp2629_battery/usb_fast_charge +Date: November 2022 +KernelVersion: 6.1 +Description: + Represents a USB device fast charge settings.Altering this + value resets USB existing connection + USB DP:DM[0:0] 0.6V : Hi-Z + USB DP:DM[0:1] 3.3V : 0.6V + USB DP:DM[1:0] 0.6V : 0.6V + USB DP:DM[1:1] 0.6V : 3.3V + + Access: Read, Write + + Valid values: Represented in bit DP & DM setting. Valid + range is [0, 3]. + What: /sys/class/power_supply/mp2629_battery/batt_impedance_compen Date: April 2020 KernelVersion: 5.7