From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EC6FC433DB for ; Mon, 21 Dec 2020 15:44:34 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3EB6322B3B for ; Mon, 21 Dec 2020 15:44:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EB6322B3B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Wm81/i76VYr3CB+RGR/pTQa+4eK+XjTDzHC7gawt8H0=; b=ynEcwwsEJ6yYNWdvfwbWhR9eU OP/FwtDD365hf/4EF8YV2bVOzrq0QcBc6HuXFcRu97Z6lPiYlCQne8oRHGEbS7An2nhGZdP+PC0MH 73uPm34A5pp6Hb/ZxSq83TtQ8Fr6JX/J/RDeNdntans37wOpM5pHfY0tlEDlZG1o7jKPA1AJyHiH8 DUu7esVfCBy/Zy/fKVRY2YCz8mnTrp6/kj6jym85suWqU5KXyKaikyRzOpfB5seKV3SwouX/1FmZP mmGNOeYfd+IoAgmu4yIgVUGXq6t+gtYQOjQZRbRNoJdQ/ji9A19CTRb52047sRdnGaDu3Jg4jEGBt 5fpy3l8/w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1krNLC-0006g4-CS; Mon, 21 Dec 2020 15:43:18 +0000 Received: from mail-wm1-f42.google.com ([209.85.128.42]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1krNL9-0006fg-ON for linux-arm-kernel@lists.infradead.org; Mon, 21 Dec 2020 15:43:16 +0000 Received: by mail-wm1-f42.google.com with SMTP id 190so10278460wmz.0 for ; Mon, 21 Dec 2020 07:43:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=eBXm2ENZyMbUD/+MQkl1th7hjWBElaB2QBhgzFuNMgk=; b=RYc6g3OfFbhW00WDx2KYdkAI1uluBbidfmT1fmmeGv0ijwxkdR2IWDVXMW1iZeDivg tL8xsJaz6vev4DhjukhAXRctxGat7HRrqzjEirSKxFUGJ1kpeMztSM/a1pGeGGwGK8Eh 5jkRA90wgmiwGp8RyBxfosq4JhjyFIuwk9c3v6RWPUY3AFd1wHxRZ0nwlNjCKerdveVt EqefpKN0kIM0wSpZD1plrwnc9VOIyor92PEVYnTvDwXklmtUpILYGQLrmEZrqOJabX9+ 5/kZJrIxbMJnLKT352g1/GyM+R+HHzMoxf0Bec2BMGZ+vGJkX+EIDO8Wto9A7zF2WprB rfiA== X-Gm-Message-State: AOAM530MOp4PiiC+SqAwg3Z29lBwnFiaUvUZ1N6dCmlvD1I37chVEXsX ywjqTRJjRbNYgrntqkCNcpw= X-Google-Smtp-Source: ABdhPJzNKXswqKaexwUhV0ogVLvDGB0INsUBzTOsZEnTRDA4tEoNmgFKAq6a4KamldZzTxW0jAU7vg== X-Received: by 2002:a05:600c:313:: with SMTP id q19mr17067442wmd.126.1608565394608; Mon, 21 Dec 2020 07:43:14 -0800 (PST) Received: from kozik-lap (adsl-84-226-167-205.adslplus.ch. [84.226.167.205]) by smtp.googlemail.com with ESMTPSA id v4sm24840766wrw.42.2020.12.21.07.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 07:43:13 -0800 (PST) Date: Mon, 21 Dec 2020 16:43:11 +0100 From: Krzysztof Kozlowski To: Timon Baetz Subject: Re: [PATCH v2 2/6] power: supply: max8997_charger: Set CHARGER current limit Message-ID: <20201221154311.GA43240@kozik-lap> References: <20201202203516.43053-1-timon.baetz@protonmail.com> <20201221095001.595366-1-timon.baetz@protonmail.com> <20201221095001.595366-2-timon.baetz@protonmail.com> <20201221141627.GB33797@kozik-lap> <20201221163455.2c3f095d.timon.baetz@protonmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201221163455.2c3f095d.timon.baetz@protonmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201221_104315_829564_D3139750 X-CRM114-Status: GOOD ( 32.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown , Liam Girdwood , Rob Herring , Sebastian Reichel , Chanwoo Choi , MyungJoo Ham , ~postmarketos/upstreaming@lists.sr.ht, Lee Jones , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Dec 21, 2020 at 03:35:07PM +0000, Timon Baetz wrote: > On Mon, 21 Dec 2020 15:16:27 +0100, Krzysztof Kozlowski wrote: > > On Mon, Dec 21, 2020 at 09:53:15AM +0000, Timon Baetz wrote: > > > Register for extcon notification and set charging current depending on > > > the detected cable type. Current values are taken from vendor kernel, > > > where most charger types end up setting 650mA [0]. > > > > > > Also enable and disable the CHARGER regulator based on extcon events. > > > > > > [0] https://github.com/krzk/linux-vendor-backup/blob/samsung/galaxy-s2-epic-4g-touch-sph-d710-exynos4210-dump/drivers/misc/max8997-muic.c#L1675-L1678 > > > > > > Signed-off-by: Timon Baetz > > > --- > > > drivers/mfd/max8997.c | 4 +- > > > drivers/power/supply/max8997_charger.c | 94 ++++++++++++++++++++++++++ > > > 2 files changed, 96 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c > > > index 68d8f2b95287..55d3a6f97783 100644 > > > --- a/drivers/mfd/max8997.c > > > +++ b/drivers/mfd/max8997.c > > > @@ -29,9 +29,9 @@ > > > static const struct mfd_cell max8997_devs[] = { > > > { .name = "max8997-pmic", }, > > > { .name = "max8997-rtc", }, > > > - { .name = "max8997-battery", }, > > > + { .name = "max8997-battery", .of_compatible = "maxim,max8997-battery", }, > > > { .name = "max8997-haptic", }, > > > - { .name = "max8997-muic", }, > > > + { .name = "max8997-muic", .of_compatible = "maxim,max8997-muic", }, > > > > Undocumented bindings. The checkpatch should complain about it, so I > > assume you did not run it. Please run the checkpatch. > > > > > { .name = "max8997-led", .id = 1 }, > > > { .name = "max8997-led", .id = 2 }, > > > }; > > > diff --git a/drivers/power/supply/max8997_charger.c b/drivers/power/supply/max8997_charger.c > > > index 1947af25879a..6e8750e455ea 100644 > > > --- a/drivers/power/supply/max8997_charger.c > > > +++ b/drivers/power/supply/max8997_charger.c > > > @@ -6,12 +6,14 @@ > > > // MyungJoo Ham > > > > > > #include > > > +#include > > > #include > > > #include > > > #include > > > #include > > > #include > > > #include > > > +#include > > > > > > /* MAX8997_REG_STATUS4 */ > > > #define DCINOK_SHIFT 1 > > > @@ -31,6 +33,10 @@ struct charger_data { > > > struct device *dev; > > > struct max8997_dev *iodev; > > > struct power_supply *battery; > > > + struct regulator *reg; > > > + struct extcon_dev *edev; > > > + struct notifier_block extcon_nb; > > > + struct work_struct extcon_work; > > > }; > > > > > > static enum power_supply_property max8997_battery_props[] = { > > > @@ -88,6 +94,67 @@ static int max8997_battery_get_property(struct power_supply *psy, > > > return 0; > > > } > > > > > > +static void max8997_battery_extcon_evt_stop_work(void *data) > > > +{ > > > + struct charger_data *charger = data; > > > + > > > + cancel_work_sync(&charger->extcon_work); > > > +} > > > + > > > +static void max8997_battery_extcon_evt_worker(struct work_struct *work) > > > +{ > > > + struct charger_data *charger = > > > + container_of(work, struct charger_data, extcon_work); > > > + struct extcon_dev *edev = charger->edev; > > > + int current_limit, ret; > > > + > > > + if (extcon_get_state(edev, EXTCON_CHG_USB_SDP) > 0) { > > > + dev_dbg(charger->dev, "USB SDP charger is connected\n"); > > > + current_limit = 450000; > > > + } else if (extcon_get_state(edev, EXTCON_CHG_USB_DCP) > 0) { > > > + dev_dbg(charger->dev, "USB DCP charger is connected\n"); > > > + current_limit = 650000; > > > + } else if (extcon_get_state(edev, EXTCON_CHG_USB_FAST) > 0) { > > > + dev_dbg(charger->dev, "USB FAST charger is connected\n"); > > > + current_limit = 650000; > > > + } else if (extcon_get_state(edev, EXTCON_CHG_USB_SLOW) > 0) { > > > + dev_dbg(charger->dev, "USB SLOW charger is connected\n"); > > > + current_limit = 650000; > > > + } else if (extcon_get_state(edev, EXTCON_CHG_USB_CDP) > 0) { > > > + dev_dbg(charger->dev, "USB CDP charger is connected\n"); > > > + current_limit = 650000; > > > + } else { > > > + dev_dbg(charger->dev, "USB charger is diconnected\n"); > > > + current_limit = -1; > > > + } > > > + > > > + if (current_limit > 0) { > > > + ret = regulator_set_current_limit(charger->reg, current_limit, current_limit); > > > + if (ret) { > > > + dev_err(charger->dev, "failed to set current limit: %d\n", ret); > > > + goto regulator_disable; > > > > Unusual error path... if regulator was not enabled before and > > regulator_set_current_limit() failed, you disable the regulator? Why? > > Wasn't it already disabled? > > Because I thought you asked me to in v1 of this patch: > > Failure of setting the current should rather disable the charging. > > I probably misunderstood you comment then. So I guess it should just > return? Yes, I was not specific enough. In v1 you enabled the charging even in case of regulator_set_current_limit() error. Instead, the charging should not be enabled, so just return here with error. Best regards, Krzysztof _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel