Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5714892pxb; Sun, 7 Nov 2021 18:38:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzEQedoc1CbEMIRdYk/HvGgNeqgbJpunsODpwpoDF4OH+KvuMrKG/krzJ3r546lRqDs2MP6 X-Received: by 2002:a92:c56b:: with SMTP id b11mr41265192ilj.243.1636339124259; Sun, 07 Nov 2021 18:38:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636339124; cv=none; d=google.com; s=arc-20160816; b=K9qBpxPjQp5NEJxgJKYxWgr0gMworRez0QcLQtbNxDVZofTb15jbcZUg+bPauHg0/s YnaCwEK0Grwv77WzGZF467Tuyj9n+dbr83knK9YJArXcU+xZQEzHLrtFvfkh9rUN+arw gS4IiLWmKapziLkGYeJqu9HD8JBnKdviRXO6ZOMWJsVJweGHQIBrJ/ODq7hqHZsG6Hdy 0Go/DdHBltI2br9vFGy73FBiDO5KLfyhVALMQ+gelKphlUZv+g2psbKPOhjCPuytvig9 c/KTLXiY0HMaT1ukvAXIE3Q64IEo8b9VR+Ga93w1cJObf6OOp5fnmxUPmzM57nakFHpe 9OYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=fw9CdIc3/VRk9UdBCM9N1QjnoS+qQtswidra737/jxs=; b=SsNmOvGGDEi16ONnOeK2lGzuTOmj3Rc8YPR6osTEuFwcercuSXF3A7uncXC1LTkNiy BezQ9xECVvXnMcLhiLQ+NvNbYdj/WmyWfxWmYXschx8WbFSVAf4BAEnI2muIlPy2uQ8p XKP7W5jBUAXfZnlAw0QaOzjemImBI5vLBxCuaMjj7XLEYBIU6arUZAFh2irKyGyp3uvT oWfRG4nzl+KDCE3M7YU0DVKWgCShYaVPKanzPfI6q5wlAAwVFQ87iuOgPEN75uqfOidH oS1fzlnebNryRtTRXbUjnY09R45OwVorjMNST5QIoQiUCsrWkh+bbPJhSrSMuJa7otjs 0TsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c5CewyPm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k13si29561429ilv.35.2021.11.07.18.38.19; Sun, 07 Nov 2021 18:38:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c5CewyPm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235425AbhKGTu1 (ORCPT + 99 others); Sun, 7 Nov 2021 14:50:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24809 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230364AbhKGTu0 (ORCPT ); Sun, 7 Nov 2021 14:50:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636314463; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fw9CdIc3/VRk9UdBCM9N1QjnoS+qQtswidra737/jxs=; b=c5CewyPmVX0bsOgaIjUGT4GTxgH+YnHkTYOAkz4ghmFEBZtsShGdarZsRm7HpF4czKGXTZ Z3RKXdDkc3ocv7N1E3RnZmvYDF4ejWluovuoDAvxxc8JJedGKIUkNwtPnVJkbLaiF7Qfaq mKk6Zute4EODJoO+GgYBisaDjOU50Xw= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-595-R_i6rn4wOSeZ_0JvI02uBQ-1; Sun, 07 Nov 2021 14:47:42 -0500 X-MC-Unique: R_i6rn4wOSeZ_0JvI02uBQ-1 Received: by mail-ed1-f70.google.com with SMTP id v9-20020a50d849000000b003dcb31eabaaso13119712edj.13 for ; Sun, 07 Nov 2021 11:47:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=fw9CdIc3/VRk9UdBCM9N1QjnoS+qQtswidra737/jxs=; b=W/6JmG0a1dNb9HNkrJP4pY7DmxcvFmCcwdgnmB/dZUXt8eurXIOv26bg+/2+OtSpiw Vr1lvQZu9NddTsCJUSC54X+t8yRYvhbU73RUSQvIvnloDfjx1ImKoRY4VkMEDKhtfNcm ZBn8GQsC4sQ8XqcFAotAqn+8yhknVBkgZEH4yhhpi5OGsw3hOH3agXF+2sb5GK/MLvFQ 1uf+mRK9aLT7n14CSAg4o8MSRgbghh5ATQzRwHwW++KASEQlVcJwQMz2WiKeqq9OUDOt 7peCVEsTyLr2VdVGF7f3egkqolPbiEaAvhuRxXUTNvPhtCWoXoA+qgJHW+4eYKkW0jSo JPsg== X-Gm-Message-State: AOAM531IqI3jNGCLaAy3/zKtTxYvYVDLYfeQQ7UgGjNCicA2KeWAdk8T WXBqjeD8EuS0C4Kjhi21t23am6gh+KvB4fHIJgGFfaUuk/HefPw+bga/ebL1mlblb4jkiWzN1r9 +Q3Di0cOmU649Jrrr1RPAFAQ0 X-Received: by 2002:a17:907:86a6:: with SMTP id qa38mr15296516ejc.286.1636314460993; Sun, 07 Nov 2021 11:47:40 -0800 (PST) X-Received: by 2002:a17:907:86a6:: with SMTP id qa38mr15296473ejc.286.1636314460694; Sun, 07 Nov 2021 11:47:40 -0800 (PST) Received: from ?IPV6:2001:1c00:c1e:bf00:1054:9d19:e0f0:8214? (2001-1c00-0c1e-bf00-1054-9d19-e0f0-8214.cable.dynamic.v6.ziggo.nl. [2001:1c00:c1e:bf00:1054:9d19:e0f0:8214]) by smtp.gmail.com with ESMTPSA id bx27sm8277661edb.7.2021.11.07.11.47.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 07 Nov 2021 11:47:40 -0800 (PST) Message-ID: Date: Sun, 7 Nov 2021 20:47:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH 09/13] power: supply: bq25890: Add bq25890_set_otg_cfg() helper Content-Language: en-US To: Yauhen Kharuzhy Cc: Mark Gross , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org References: <20211030182813.116672-1-hdegoede@redhat.com> <20211030182813.116672-10-hdegoede@redhat.com> From: Hans de Goede In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 11/7/21 19:49, Yauhen Kharuzhy wrote: > On Sat, Oct 30, 2021 at 08:28:09PM +0200, Hans de Goede wrote: >> Add a bq25890_set_otg_cfg() helper function, this is a preparation >> patch for adding regulator support. > > The same notice here: if we enabling the boost mode to supply USB OTG > device, we should disable charging and vice versa. I don't remember if > enabling of OTG with CHG enabled really caused issues but I avoided this > in my Yoga Book work. > > I made quick check — seems that charging can be enabled during of boost > operation, there are no visible side effects in registers and no > limitation in the datasheet, so your approach may be good. Right, the charging bit can simply be always on, if the OTG boost converter is enabled then the charger it will automatically stop charging (AFAIK it is partly re-using the same hw even). I've no idea why the charging bit is being cleared by the BIOS, there really is no need for this, with the exception of either: 1. Using an external Vbus boost converter, because that can e.g. deliver more current, then charging does need to be disabled. 2. Disabling charging for battery health reasons 1. is not the case here; and 2. is something which we could export as something userspace can request but that is optional. So for normal use there really is no reason to set the charging bit to 0 ever (and it is 1 on reset), so just setting it to 1 makes the behavior the same as on many ARM devices where this charger is also used and the same as how similar chargers like the bq2419x and bq2429x are used on other X86 devices. Regards, Hans > >> >> Signed-off-by: Hans de Goede >> --- >> drivers/power/supply/bq25890_charger.c | 28 ++++++++++++++------------ >> 1 file changed, 15 insertions(+), 13 deletions(-) >> >> diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c >> index 163ca5d761aa..7504e30f1e4d 100644 >> --- a/drivers/power/supply/bq25890_charger.c >> +++ b/drivers/power/supply/bq25890_charger.c >> @@ -773,6 +773,17 @@ static int bq25890_power_supply_init(struct bq25890_device *bq) >> return PTR_ERR_OR_ZERO(bq->charger); >> } >> >> +static int bq25890_set_otg_cfg(struct bq25890_device *bq, u8 val) >> +{ >> + int ret; >> + >> + ret = bq25890_field_write(bq, F_OTG_CFG, val); >> + if (ret < 0) >> + dev_err(bq->dev, "Error switching to boost/charger mode: %d\n", ret); >> + >> + return ret; >> +} >> + >> static void bq25890_usb_work(struct work_struct *data) >> { >> int ret; >> @@ -782,25 +793,16 @@ static void bq25890_usb_work(struct work_struct *data) >> switch (bq->usb_event) { >> case USB_EVENT_ID: >> /* Enable boost mode */ >> - ret = bq25890_field_write(bq, F_OTG_CFG, 1); >> - if (ret < 0) >> - goto error; >> + bq25890_set_otg_cfg(bq, 1); >> break; >> >> case USB_EVENT_NONE: >> /* Disable boost mode */ >> - ret = bq25890_field_write(bq, F_OTG_CFG, 0); >> - if (ret < 0) >> - goto error; >> - >> - power_supply_changed(bq->charger); >> + ret = bq25890_set_otg_cfg(bq, 0); >> + if (ret == 0) >> + power_supply_changed(bq->charger); >> break; >> } >> - >> - return; >> - >> -error: >> - dev_err(bq->dev, "Error switching to boost/charger mode.\n"); >> } >> >> static int bq25890_usb_notifier(struct notifier_block *nb, unsigned long val, >> -- >> 2.31.1 >> >