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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3E319C77B73 for ; Tue, 2 May 2023 11:18:51 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 11CFA846F6; Tue, 2 May 2023 13:18:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="TubPt784"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D5D12846FB; Tue, 2 May 2023 13:18:47 +0200 (CEST) Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5063882A16 for ; Tue, 2 May 2023 13:18:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=eugen.hristev@collabora.com Received: from [192.168.0.125] (unknown [82.76.24.202]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: ehristev) by madras.collabora.co.uk (Postfix) with ESMTPSA id 99AC26601F25; Tue, 2 May 2023 12:18:44 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1683026324; bh=QrcougOnBohcwwiUbXwyvCJ4tR+7Igd6YS5IlQ75J1w=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=TubPt784or4m1aY/GHuCKDn+qD7lf9q1aOiBXk6sxrHFoX6/3ImZ+C9iXd2s5Zj16 NMmmASSuYeX2fweOW53epOHAiDGqqSRW8WAK0QDKhGtTmFtVxDFtxyxQMDIloXCj2p N2YKS24UXVnX3rPUl6xaJLWlo2pQiqDF4mz2PzZpT7oUS2a91E8NAjbESD1HPFNydz yAC+v2lpRyIWHwmjpk4+4fOWHbPv/QmKa3H+w2tA3AbDuNlJ87InV1JBDULm1yGyHk cg3z0Ocj4hlTKkvz3lysrX+EjcoG3pCH3sczq4QV6w5TxBHnZcaSYoTKw3AuNYWp42 hb/VkhnW/Gl+A== Message-ID: <085be031-b802-a5ce-5bb9-623093336f7d@collabora.com> Date: Tue, 2 May 2023 14:18:42 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] usb: ehci-mx6: replace regulator_set_enable with *_if_allowed Content-Language: en-US To: Marek Vasut , u-boot@lists.denx.de, tharvey@gateworks.com Cc: sjg@chromium.org References: <20230502065104.32242-1-eugen.hristev@collabora.com> <76acce9d-e61c-814a-5dd4-1c54c1417cf1@collabora.com> <477daa1f-a42c-6c88-4e7c-7d67dd8a13f3@denx.de> From: Eugen Hristev In-Reply-To: <477daa1f-a42c-6c88-4e7c-7d67dd8a13f3@denx.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean On 5/2/23 13:53, Marek Vasut wrote: > On 5/2/23 12:41, Eugen Hristev wrote: >> On 5/2/23 12:18, Marek Vasut wrote: >>> On 5/2/23 08:51, Eugen Hristev wrote: >>>> regulator_set_enable_if_allowed already handles cases when the >>>> regulator is already enabled, or already disabled, and does not >>>> treat these as errors. >>>> With this change, the driver can work correctly even if the regulator >>>> is already taken or already disabled by another consumer. >>> >>> Can that ever happen for Vbus supply (the 5V coming out of USB port) ? >>> Can you elaborate how ? >> >> >> Hi Marek, > > Hi, > >> Recently I developed a series of patches to add a reference counter >> for regulators : >> >> https://marc.info/?l=u-boot&m=168191189309879&w=2 > > Ah yes, this is super cool stuff, thanks ! > >> But with this series, having a regulator already enabled or already >> disabled results in an error returned by regulator_set_enable >> >> Hence, one option is to replace calls with >> regulator_set_enable_if_allowed >> >> There is a discussion ongoing here: >> >> https://marc.info/?l=u-boot&m=168295920316621&w=2 > > Pardon my ignorance, but uh ... how does Linux deal with regulators > which are enabled by prior stage, like U-Boot ? Does it set their enable > refcount to =1 or =0 ? Please correct me if I am wrong, I did not dig too much into regulators, but , from my understanding : Normally software(in this case Linux) reads the state of the regulator when it's probed, and sets the refcount accordingly. If the state cannot be read then regulator-boot-on tells Linux that it should have been left enabled by prior stage In Uboot I believe that regulators that have 'regulator-boot-on' are added to a list and set to enable during probe, and the probe is forced even if Uboot normally uses lazy probing (should have the same behavior for regulator-always-on property) So if a regulator is enabled by an initial stage but it's not described with 'regulator-boot-on' , appears to be a bad hardware description in DT.