Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1908788lqp; Sat, 23 Mar 2024 14:36:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUmhdB4pOTsz7acOyJnpNcX2XZmOc/xd/cpTlrI6C/inweu9OTy++lc8ByC5RhXqpZR9WaxxPXbyVcv9FlNjs+N9M4XTmp60o2m1VDx2A== X-Google-Smtp-Source: AGHT+IHvhi+IJzek9dN7xKSQ4opsa+wc00ASSJEYDpYNsGKyBKxN0ce5SXKilKAn/4xDBdyHfLU0 X-Received: by 2002:a05:6a21:6d97:b0:1a3:8a93:aa76 with SMTP id wl23-20020a056a216d9700b001a38a93aa76mr3913765pzb.44.1711229790117; Sat, 23 Mar 2024 14:36:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711229790; cv=pass; d=google.com; s=arc-20160816; b=AS0Q7UdSoX7tMPTwU4JO/1tCRFR/Dvc6bHQCSrDSL9IWm6lKMD3+wJ4tA4STXle/eP A0b5BKjvMBtr8Rcg66JrhF8ulBd5nN0r6KCzjJVYbIdjreQvu9U2OmFH1JLTFe8pOBhT SHqB0Ddv38uJXxmZENPscw4XWOMHYE9Rpq2etabKWrOV2wDX8nhA46Z5QsYr8KQHbY5I YSd/nLQypVuWXhupZWRk6yTOF2n54f42wCtiw/N14NRZEYKyeVSHDUufYPpT1H0KXZbs SaV4+C4k+jj0EqoC0Qz7UojK3bn+Ab1xy8LS81bnVhHtcERIwX9vigeqVm0u0yTcj2kG xj4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:in-reply-to:content-transfer-encoding :content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:references:message-id:subject:cc:to:from:date; bh=DH6u5hueJXghx+HTd5Xf1afUfgYNMoexe68mmON4jws=; fh=/fCEo7N67AFgrQCYixB5LKlahh3ibuzDcxpkPiQjk1s=; b=nP1e/5vHMaGTi1navpiv53KfvlnnxKgHm3WoX4vj1pYoZDYb8fqV3j7BBeKVjVtaf1 KJdZ8x0wkMQm0j0EOXofs8vLdUEEdwokNVdllZCjsz++ASCTkQRfTrct1Ks9HmbA5kqM N/TT1eI6onFcEO9A2MxwbOTQksL4EO2jtkvGdJJpin82RWmjzfwk3AQDPzhc8jh1poN5 l6NwDbzZcW9fQQUz5p7mtXNpJ0cdU+o9P1xilFPkUV1fNv/zlUE0QBJCbfIFn9Biz1yz l/cRalf721uzG8knV/aczonDmpe2BEcDgX5X0/6VHGMauQVAz4FfO5I9WWUYZrtd0dvC mdKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=GVghcTCk; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-112491-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112491-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v7-20020a655c47000000b005dc8372021bsi4858476pgr.464.2024.03.23.14.36.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 14:36:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112491-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=GVghcTCk; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-112491-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112491-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C3D1F282027 for ; Sat, 23 Mar 2024 21:36:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB14F5A119; Sat, 23 Mar 2024 21:36:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="GVghcTCk" Received: from a.peacevolution.org (a.peacevolution.org [206.189.193.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20DC563D; Sat, 23 Mar 2024 21:36:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=206.189.193.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711229782; cv=none; b=s70cIqWi87a2ZqGWErJnAFpMkCsX7keH4GogpuMxLPkmosPV0n0WObGw9AqqWASnLKNT9YQ6/CclBef7/1Ao2YJ/SSkS9W/pkLkY29LLhTcZTaslFblSHqhwnThaL53i8naApIxej7sOrWx/H9tTc4YsZQfAUDyfu5+4feYABtM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711229782; c=relaxed/simple; bh=SOjwEita4xleHBrq6ZggCrx3xzRmKXFreSfxXqMtNdM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QxgkwTTCFrg5/GOiewm6T0wcJfZwhEWAFIXhp2rqMGU0osU/CYpdbqb1Nmr5+s9TqNxQ17muXAdPGFrId/2XQAD4+VrSFXFkk1/GMZ/5j99tGGeqJj2OlOZf6R5N/8gFWSmaqhhsOdxORcoWN8xOoVtFm84knPvIP/VX3BcC818= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org; spf=pass smtp.mailfrom=peacevolution.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b=GVghcTCk; arc=none smtp.client-ip=206.189.193.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=peacevolution.org Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 84F384624A; Sat, 23 Mar 2024 21:36:12 +0000 (UTC) Date: Sat, 23 Mar 2024 17:36:10 -0400 From: Aren To: =?utf-8?Q?Ond=C5=99ej?= Jirman Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Hans de Goede , Aidan MacDonald , Chen-Yu Tsai , Quentin Schulz , Sebastian Reichel Subject: Re: [PATCH v2 5/5] power: supply: axp20x_usb_power: set input current limit in probe Message-ID: <5ulz6dcy5rqumj44hmka5ljdvx3tfvsqdpdsz3npcttb7ckf7j@53lxdl5koolz> References: <20240130203714.3020464-1-aren@peacevolution.org> <20240130203714.3020464-6-aren@peacevolution.org> <6nf7h3nc4q7fwrnm4spmgv2sdkczowkfpietcv2tyv4mixkq3b@svxgzkdqnzlq> <73j4grggnygltxrw6l44w53bjdc2e52c5m2ld5s6dg2q4plmrf@oicpllrnw53c> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <73j4grggnygltxrw6l44w53bjdc2e52c5m2ld5s6dg2q4plmrf@oicpllrnw53c> X-Spamd-Bar: / Authentication-Results: auth=pass smtp.auth=aren@peacevolution.org smtp.mailfrom=aren@peacevolution.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=peacevolution.org; s=dkim; t=1711229773; h=from:subject:date:message-id:to:cc:mime-version:content-type:content-transfer-encoding:in-reply-to:references; bh=DH6u5hueJXghx+HTd5Xf1afUfgYNMoexe68mmON4jws=; b=GVghcTCk0wtMbNT5AyGT91Flb0R6u0J3HHtcsA0B8hPDDQB65eicZE7x3o/kK/6tfKSiI8 FT/bD6Q7dlWQNaRg+TQ+sDiW2PH7IblaN0n/Cf1LumAYbefTZkFDN3Cn4/aVvUXEsiwGF2 ChAZXPAGDbnmJCuBLjkKko3bMGy98Nk= Hi Ondřej, On Wed, Mar 20, 2024 at 01:12:31AM +0100, Ondřej Jirman wrote: > Hi Aren, > > On Thu, Mar 14, 2024 at 06:39:52PM -0400, Aren wrote: > > > Also in Pinephone case, you'll not really have a case where the battery has > > > < 2V not loaded. That's not going to happen. PMIC will shut off at 3V battery > > > voltage when loaded. It will not discharge further, and after shutoff battery > > > voltage will jump to 3.4V or so, and it will not drop below 2V after that, ever. > > > So the battery will pretty much always be detected as long as it's present. > > > > The most likely case I can think of is if someone intentionally tries to > > boot the device without the battery. I suspect it's also possible for a > > battery to degrade to the point where it won't hold a charge. > > Yes, that's my usecase that I'd like to preserve. Pinephone has removable > battery and using it without battery is quite reasonable. It works fine > currently for me and this patch will break this if there's no opt out. And > there's no opt out other than patching and re-building the kernel. > > > > What actual problem have you seen that this patch is trying to solve? > > > > The problem, in theory, is that the pmic ignores the USB BC > > specification and sets the current limit to 3A instead of 500mA. In > > practice (as long as the power supply is implemented properly) if this > > is too much power, it should just cause the power supply to shut off. > > I'm not sure how likely / what the risks of a power supply cutting > > corners are. > > Pinephone with no battery takes between 0.5-1A from VBUS. Even under full > load, it's not enough to damage even a USB 3.0 SDP port. It's only a > slight problem for unprotected USB 2.0 SDP ports. On protected 2.0 ports > or ports with overdesigned output power, it will either shut down due > to brownout, or just work. > > It's not enough to overload any actual USB charger. > > In any case, people wanting to run Pinephone without a battery probably > will not do so from a USB 2.0 computer port. Maybe for FEL USB mode, for > development or flashing, but at that stage the power consumption is still > very low, well below 2.5W. > > > I find it surprising that the hardware/driver takes a lot of care to > > figure out what the proper current is and stick to that, except when > > there isn't a battery. > > It seems to have apparent purpose documented in the datasheet: > > https://megous.com/dl/tmp/78d4c0771fc6d2c8.png > > "If Battery not present, and this bit is 0,the VBUS current limit set to 3A, > for the F/W update in factory" > > You can also get rid of the issue by writing 1 to: > > "REG 2DH: BC Module VBUS Control and Status Register" bit 6 > > in the bootloader very early on before enabling BC. That should fix the issue, > too in a more proper way than forcing 500mA limit halfway during boot, when > BC1.2 detection might have detected something higher earlier on and the boot > success depends on the higher value. I agree this is a better way of handling this, I made an attempt previously to get USB BC working without a battery connected, but I was has having problems with USB BC hanging. Based on what you describe below, I now suspect that had to do with leaving dead battery detection enabled (0x2E bit 6). I'll take a look through the code again to see if I can get it working. Thanks - Aren > > battery. The datasheet says that register 0x2D bit 6 is used to indicate > > first power on status. According to it, if that bit is 0 and the battery > > is not detected, it will set the input current limit to 3A, however > > setting that bit to 1 doesn't to prevent the pmic from setting the > > current limit to 3A. > > Actually it does (I made a quick test with Pinephone with no battery being > plugged to the PC's USB port and executing a test program over FEL that talks to > the PMIC): > > PMIC registers: (initial values post-powerup with no battery) > > 2c: 0 - BC disabled by default, something has to enable it > 2d: b0 - bit 6 not set (*not* first boot bit) > 2e: 40 > 2f: 0 > 30: 1 > 31: 3 > 32: 43 > 33: c5 > 34: 45 > 35: 68 - initially 3A limit > 36: 59 > 37: 0 > 38: a5 > 39: 1f > 3a: 80 > > changed values > > 2c: 5 - test program enables BC > 2e: 0 - disable DB detection (otherwise with no battery DB detection will > prolong BC detection result by 45minutes or whatever is the timeout) > see DBP_Timeout_CTL(DBP Hardware Timeout Control) > 2f: 10 > 30: 2a > 35: 38 - test program sets 1.5A limit > 36: 8 > > ... about 400 ms later > > 2c: 1 - BC complete > 2f: 30 - BC result = SDP (matches reality) > 35: 68 - 3A VBUS limit set by PMIC itself > > > Another run with 2d.6 bit set: > > (initial values omitted, same as above) > > > changed values > > 2c: 5 - enable BC > 2d: f0 - bit 6 set (*not* first boot) > 2e: 0 > 2f: 10 > 30: 2a > 35: 38 - test program sets 1.5A limit > 36: 8 > > ... after about 400 ms > > 2c: 1 - BC complete > 2f: 30 - BC result = SDP > 35: 18 - 500mA VBUS limit set by PMIC itself > > > So the detection works with no battery inserted. PMIC's BC correcly detects > regular USB 2.0 data port and configures a correct limit in about 400ms > after cable plug in. So I don't see a problem with the HW, that you're > describing in the commit message. > > The proper way to handle this issue is to fix whichever component is configuring > the BC detection initially (it's disabled by default, apparently), to properly > set the first boot bit before enabling BC. IMO, that place should be the > platform firmware. Then the detection will work from the get go and proper limit > will be always set correctly and will match the USB charger, and there will be > no need for any kernel hacks. > > Pretty much what platform FW should do is to: > > - set "not first boot bit" in 0x2d register > - check if battery is present > - if not clear 0x2e register > - otherwise configure DBD in 0x2e > - configure DCP/CDP current limit to 1.5A or 2A (1.5A maybe safer) > - configure VBUS Vhold to 4.5V (Pinephone needs this for powered USB dock to > work with in general with arbitrary chargers, and it will overload weaker > USB PSU's less) > - configure BC detection and start it > > My usecase of using Pinephone without battery will still work, too, and will > not be broken by this patch. > > > The point of this patch (after a revision) should be to make it explicit > > when and why this driver ignores the USB BC specification. And to reduce > > the cases where it does, if possible. > > The kernel has no business forcing the limit to some fixed low value that > has no relationship to the last BC detection result and breaks boot in > the exact scenario this patch is targetting (no battery -> too high current > limit). > > This doesn't make any sense to me. > > kind regards, > o. > > > With the goal of making it explicit what cases ignore the spec, I would > > prefer to have an opt-out mechanism. I compiled what I believe to be a > > full list of devices that use this driver with usb bc enabled (detailed > > notes below), and there's only a handful of them. It shouldn't be too > > difficult to out-out the boards that need it. > > > > > > > > Thank you and kind regards, > > > o. > > > > Sorry it took me a while to respond, I haven't had much time to work on > > this in the past few weeks. > > > > Regards > > - Aren > > > > p.s. the notes on what devices use this functionality: > > > > These devices include the axp803 or axp81x dtsi: > > $ rg -l 'include "axp(803|81x).dtsi"' > > - sun50i-a100-allwinner-perf1.dts > > - sun50i-a64-amarula-relic.dts > > - sun50i-a64-bananapi-m64.dts > > - sun50i-a64-nanopi-a64.dts > > - sun50i-a64-olinuxino.dts > > - sun50i-a64-orangepi-win.dts > > - sun50i-a64-pine64.dts > > - sun50i-a64-pinebook.dts > > - sun50i-a64-pinephone.dtsi > > - sun50i-a64-pinetab.dts > > - sun50i-a64-sopine.dtsi > > - sun50i-a64-teres-i.dts > > - sun8i-a83t-allwinner-h8homlet-v2.dts > > - sun8i-a83t-bananapi-m3.dts > > - sun8i-a83t-cubietruck-plus.dts > > - sun8i-a83t-tbs-a711.dts > > > > Out of those only these enable usb_power_supply: > > $ rg -l 'include "axp(803|81x).dtsi"' | xargs rg -l 'usb_power_supply' > > - sun50i-a64-bananapi-m64.dts > > - sun50i-a64-pinetab.dts > > - sun50i-a64-pinephone.dtsi > > - sun8i-a83t-tbs-a711.dts > > - sun8i-a83t-cubietruck-plus.dts > > - sun8i-a83t-bananapi-m3.dts > > > > sun50i-a64-bananapi-m64.dts: The barrel jack is connected to acin, so > > will be unaffected. Banannapi docs say it's not possible to power over > > usb, but schematic suggests it should work. Probably needs to opt-out of > > the lower current limit. > > > > sun50i-a64-pinetab.dts: unclear if charging is supported via usb, vbus > > is connected through a component listed as "NC/0R". Regardless device > > has barrel jack and battery for power, shouldn't need to run exclusively > > from usb. > > > > sun50i-a64-pinephone.dtsi: is typically booted with a battery connected, > > shouldn't need to run exclusively from usb. > > > > sun8i-a83t-tbs-a711.dts: has an internal battery, shouldn't need to run > > exclusively from usb. > > > > sun8i-a83t-cubietruck-plus.dts and sun8i-a83t-bananapi-m3.dts: Both > > appear to support being powered over usb and a barrel jack. These will > > need to opt-out to be able to run from usb.