Merge branch '2023-08-14-keep-fixed-gpio-regulator-count-in-balance' into next

To quote the author:

The commit 4fcba5d556 ("regulator: implement basic reference counter")
have made it more important to keep fixed/gpio regulators enable/disable
state in balance.

This series fixes an inbalance in the mmc_dw driver and changes to use
the more relaxed regulator_set_enable_if_allowed function for a few
other drivers.

The regulator_set_enable_if_allowed function is more relaxed and will
return ENOSYS if the provided regulator is NULL or when DM_REGULATOR
was disabled. Using the following call convention should be safe:

  ret = regulator_set_enable_if_allowed(<supply>, <true|false>);
  if (ret && ret != -ENOSYS)
          return ret;
This commit is contained in:
Tom Rini 2023-08-14 09:14:51 -04:00
commit 831a80c2af
5 changed files with 37 additions and 36 deletions

View file

@ -51,23 +51,21 @@ static int check_channel(struct udevice *dev, int value, bool number_or_mask,
static int adc_supply_enable(struct udevice *dev)
{
struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev);
const char *supply_type;
int ret = 0;
int ret;
if (uc_pdata->vdd_supply) {
supply_type = "vdd";
ret = regulator_set_enable(uc_pdata->vdd_supply, true);
ret = regulator_set_enable_if_allowed(uc_pdata->vdd_supply, true);
if (ret && ret != -ENOSYS) {
pr_err("%s: can't enable vdd-supply!", dev->name);
return ret;
}
if (!ret && uc_pdata->vss_supply) {
supply_type = "vss";
ret = regulator_set_enable(uc_pdata->vss_supply, true);
ret = regulator_set_enable_if_allowed(uc_pdata->vss_supply, true);
if (ret && ret != -ENOSYS) {
pr_err("%s: can't enable vss-supply!", dev->name);
return ret;
}
if (ret)
pr_err("%s: can't enable %s-supply!", dev->name, supply_type);
return ret;
return 0;
}
int adc_data_mask(struct udevice *dev, unsigned int *data_mask)

View file

@ -509,6 +509,10 @@ static int dwmci_set_ios(struct mmc *mmc)
if (mmc->vqmmc_supply) {
int ret;
ret = regulator_set_enable_if_allowed(mmc->vqmmc_supply, false);
if (ret)
return ret;
if (mmc->signal_voltage == MMC_SIGNAL_VOLTAGE_180)
regulator_set_value(mmc->vqmmc_supply, 1800000);
else

View file

@ -2775,9 +2775,10 @@ static int mmc_power_on(struct mmc *mmc)
{
#if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(DM_REGULATOR)
if (mmc->vmmc_supply) {
int ret = regulator_set_enable(mmc->vmmc_supply, true);
int ret = regulator_set_enable_if_allowed(mmc->vmmc_supply,
true);
if (ret && ret != -EACCES) {
if (ret && ret != -ENOSYS) {
printf("Error enabling VMMC supply : %d\n", ret);
return ret;
}
@ -2791,9 +2792,10 @@ static int mmc_power_off(struct mmc *mmc)
mmc_set_clock(mmc, 0, MMC_CLK_DISABLE);
#if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(DM_REGULATOR)
if (mmc->vmmc_supply) {
int ret = regulator_set_enable(mmc->vmmc_supply, false);
int ret = regulator_set_enable_if_allowed(mmc->vmmc_supply,
false);
if (ret && ret != -EACCES) {
if (ret && ret != -ENOSYS) {
pr_debug("Error disabling VMMC supply : %d\n", ret);
return ret;
}

View file

@ -194,8 +194,8 @@ static int dwc_vbus_supply_init(struct udevice *dev)
return 0;
}
ret = regulator_set_enable(priv->vbus_supply, true);
if (ret) {
ret = regulator_set_enable_if_allowed(priv->vbus_supply, true);
if (ret && ret != -ENOSYS) {
dev_err(dev, "Error enabling vbus supply\n");
return ret;
}
@ -208,12 +208,10 @@ static int dwc_vbus_supply_exit(struct udevice *dev)
struct dwc2_priv *priv = dev_get_priv(dev);
int ret;
if (priv->vbus_supply) {
ret = regulator_set_enable(priv->vbus_supply, false);
if (ret) {
dev_err(dev, "Error disabling vbus supply\n");
return ret;
}
ret = regulator_set_enable_if_allowed(priv->vbus_supply, false);
if (ret && ret != -ENOSYS) {
dev_err(dev, "Error disabling vbus supply\n");
return ret;
}
return 0;

View file

@ -39,14 +39,10 @@ static int ehci_enable_vbus_supply(struct udevice *dev)
if (ret && ret != -ENOENT)
return ret;
if (priv->vbus_supply) {
ret = regulator_set_enable(priv->vbus_supply, true);
if (ret) {
dev_err(dev, "Error enabling VBUS supply (ret=%d)\n", ret);
return ret;
}
} else {
dev_dbg(dev, "No vbus supply\n");
ret = regulator_set_enable_if_allowed(priv->vbus_supply, true);
if (ret && ret != -ENOSYS) {
dev_err(dev, "Error enabling VBUS supply (ret=%d)\n", ret);
return ret;
}
return 0;
@ -54,10 +50,13 @@ static int ehci_enable_vbus_supply(struct udevice *dev)
static int ehci_disable_vbus_supply(struct generic_ehci *priv)
{
if (priv->vbus_supply)
return regulator_set_enable(priv->vbus_supply, false);
else
return 0;
int ret;
ret = regulator_set_enable_if_allowed(priv->vbus_supply, false);
if (ret && ret != -ENOSYS)
return ret;
return 0;
}
static int ehci_usb_probe(struct udevice *dev)