From 69d588392b057c0cedb1ba58d7973b77a65997ec Mon Sep 17 00:00:00 2001 From: Nishanth Menon Date: Wed, 4 Jun 2014 14:53:25 -0500 Subject: regulator: core: print error value when constraints are not applied With commit 064d5cd110f94ce41ca5681dcda8b77fa63d5b95 (regulator: core: Fix the init of DT defined fixed regulators) We ensure that regulator must be capable of providing it's current voltage when constraints are used, however adding the return value in the print is a little more informative to explain the nature of the failure involved. So, instead of providing message such as: smps9: failed to get the current voltage having error value added to the message such as: smps9: failed to get the current voltage(-22) is a little more informative for debugging the error. Signed-off-by: Nishanth Menon Signed-off-by: Mark Brown --- drivers/regulator/core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 4c1f999041dd..b4902ab64abe 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -846,7 +846,9 @@ static int machine_constraints_voltage(struct regulator_dev *rdev, rdev->constraints->min_uV == rdev->constraints->max_uV) { int current_uV = _regulator_get_voltage(rdev); if (current_uV < 0) { - rdev_err(rdev, "failed to get the current voltage\n"); + rdev_err(rdev, + "failed to get the current voltage(%d)\n", + current_uV); return current_uV; } if (current_uV < rdev->constraints->min_uV || @@ -856,8 +858,8 @@ static int machine_constraints_voltage(struct regulator_dev *rdev, rdev->constraints->max_uV); if (ret < 0) { rdev_err(rdev, - "failed to apply %duV constraint\n", - rdev->constraints->min_uV); + "failed to apply %duV constraint(%d)\n", + rdev->constraints->min_uV, ret); return ret; } } -- cgit v1.2.3 From e303996e94b8705c85f3d78f3c094d05b0620c9d Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Tue, 29 Jul 2014 18:28:55 +0200 Subject: regulator: core: Get voltage from parent if not available Load switches are modeled as regulators but they just provide the voltage of their parent input supply. So the drivers for these switches usually don't provide a .get_voltage function handler but there is code in the kernel that assumes that all regulators should be able to provide its current voltage rail. So, if the output voltage for a regulator is not available and it has a parent supply, then pass the voltage of its parent. Signed-off-by: Javier Martinez Canillas Signed-off-by: Mark Brown --- drivers/regulator/core.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index b4902ab64abe..57fe446fabce 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2620,6 +2620,8 @@ static int _regulator_get_voltage(struct regulator_dev *rdev) ret = rdev->desc->ops->list_voltage(rdev, 0); } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) { ret = rdev->desc->fixed_uV; + } else if (rdev->supply) { + ret = regulator_get_voltage(rdev->supply); } else { return -EINVAL; } -- cgit v1.2.3 From 26988efe11b1dc44853035122927ced25578f302 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Tue, 29 Jul 2014 18:28:56 +0200 Subject: regulator: core: Allow to get voltage count and list from parent Load switches are modeled as regulators but they just provide the voltage of their parent input supply. So, the drivers for these switches usually neither provide a .list_voltage handler not set a .n_voltages count. But there is code in the kernel that assumes that all regulators should be able to provide this information (e.g: cpufreq and mmc subsystems). If the voltage count and list are not available for a regulator and it has a parent input supply, then use the parent values. Signed-off-by: Javier Martinez Canillas Signed-off-by: Mark Brown --- drivers/regulator/core.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 57fe446fabce..5299456d07ee 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2182,7 +2182,13 @@ int regulator_count_voltages(struct regulator *regulator) { struct regulator_dev *rdev = regulator->rdev; - return rdev->desc->n_voltages ? : -EINVAL; + if (rdev->desc->n_voltages) + return rdev->desc->n_voltages; + + if (!rdev->supply) + return -EINVAL; + + return regulator_count_voltages(rdev->supply); } EXPORT_SYMBOL_GPL(regulator_count_voltages); @@ -2205,12 +2211,17 @@ int regulator_list_voltage(struct regulator *regulator, unsigned selector) if (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1 && !selector) return rdev->desc->fixed_uV; - if (!ops->list_voltage || selector >= rdev->desc->n_voltages) + if (ops->list_voltage) { + if (selector >= rdev->desc->n_voltages) + return -EINVAL; + mutex_lock(&rdev->mutex); + ret = ops->list_voltage(rdev, selector); + mutex_unlock(&rdev->mutex); + } else if (rdev->supply) { + ret = regulator_list_voltage(rdev->supply, selector); + } else { return -EINVAL; - - mutex_lock(&rdev->mutex); - ret = ops->list_voltage(rdev, selector); - mutex_unlock(&rdev->mutex); + } if (ret > 0) { if (ret < rdev->constraints->min_uV) -- cgit v1.2.3