From: Lokesh Vutla Date: Fri, 28 Dec 2018 11:03:03 +0530 Subject: [U-Boot] [PATCH] power: regulator: Return success on attempt to disable an always-on regulator In-Reply-To: References: <20181224110741.27015-1-lokeshvutla@ti.com> Message-ID: <4fd768d4-471f-fd6f-ae6f-cc239bf03072@ti.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Hi Simon, On 28/12/18 3:57 AM, Simon Glass wrote: > Hi Lokesh, >=20 > On Mon, 24 Dec 2018 at 04:08, Lokesh Vutla wrote: >> >> commit 4f86a724e82c0 ("power: regulator: denied disable on always-on >> regulator") throws an error when requested to disable an always-on >> regulator. It is right that an always-on regulator should not be >> attempted to be disabled. But at the same time regulator framework >> should not return an error when such request is received. Instead >> it should just return success without attempting to disable the >> specified regulator. This is because the requesting driver will >> not have the idea if the regulator is always-on or not. The >> requesting driver will always try to enable/disable regulator as >> per the required flow. So it is upto regulator framework to not >> break such scenarios. >=20 > Can the caller not check the error code? It is -EACCES in this case. We considered this an one of the option but I ended up fixing regulator=20 framework due to the following reasons: - If regulator framework returns -EACCES on this scenario then: - -EACCES should be checked in all the existing usage of the api[1] or els= e=20 someone else might encounter the same problem. - Any future usage of the api should take of handling this error. - From a client driver perspective it is not really an error. It is doing = the=20 right thing and receiving an error might be confusing. Hope this is clear. Also just to add one more point, I adapted this error=20 handling from Linux kernel[2]. [1] =E2=9E=9C u-boot git:(master) git grep -in "regulator_set_enable(.*, f= alse)" cmd/regulator.c:410: ret =3D regulator_set_enable(dev, false); drivers/mmc/mmc.c:2552: int ret =3D regulator_set_enable(mmc->vmmc_supp= ly, false); drivers/mmc/omap_hsmmc.c:473: ret =3D regulator_set_enable(priv->pbias_su= pply,=20 false); drivers/mmc/omap_hsmmc.c:478: ret =3D regulator_set_enable(mmc->vqmmc_sup= ply,=20 false); drivers/net/fec_mxc.c:1414: regulator_set_enable(priv->phy_supply, fals= e); drivers/phy/meson-gxl-usb2.c:174: int ret =3D=20 regulator_set_enable(priv->phy_supply, false); drivers/phy/phy-rcar-gen3.c:101: return=20 regulator_set_enable(priv->vbus_supply, false); drivers/phy/phy-stm32-usbphyc.c:251: ret =3D=20 regulator_set_enable(usbphyc_phy->vdda1v1, false); drivers/phy/phy-stm32-usbphyc.c:257: ret =3D=20 regulator_set_enable(usbphyc_phy->vdda1v8, false); drivers/phy/phy-stm32-usbphyc.c:263: ret =3D=20 regulator_set_enable(usbphyc_phy->vdd, false); drivers/usb/host/dwc2.c:199: ret =3D=20 regulator_set_enable(priv->vbus_supply, false); drivers/usb/host/ehci-generic.c:60: return=20 regulator_set_enable(priv->vbus_supply, false); drivers/usb/host/xhci-rockchip.c:161: ret =3D=20 regulator_set_enable(plat->vbus_supply, false); drivers/video/pwm_backlight.c:160: ret =3D=20 regulator_set_enable(priv->reg, false); test/dm/adc.c:74: ut_assertok(regulator_set_enable(supply, false)); [2] [1]=20 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/dri= vers/regulator/core.c#n2333 Thanks and regards, Lokesh