Skip to content

Commit

Permalink
Merge remote-tracking branch 'regulator/topic/core' into regulator-next
Browse files Browse the repository at this point in the history
  • Loading branch information
broonie committed Apr 30, 2017
2 parents 6a8007c + c93609a commit bde1e61
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
33 changes: 15 additions & 18 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1326,8 +1326,8 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
regulator->dev = dev;

/* Add a link to the device sysfs entry */
size = scnprintf(buf, REG_STR_SIZE, "%s-%s",
dev->kobj.name, supply_name);
size = snprintf(buf, REG_STR_SIZE, "%s-%s",
dev->kobj.name, supply_name);
if (size >= REG_STR_SIZE)
goto overflow_err;

Expand All @@ -1343,7 +1343,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
/* non-fatal */
}
} else {
regulator->supply_name = kstrdup(supply_name, GFP_KERNEL);
regulator->supply_name = kstrdup_const(supply_name, GFP_KERNEL);
if (regulator->supply_name == NULL)
goto overflow_err;
}
Expand Down Expand Up @@ -1451,8 +1451,6 @@ static struct regulator_dev *regulator_lookup_by_name(const char *name)
* regulator_dev_lookup - lookup a regulator device.
* @dev: device for regulator "consumer".
* @supply: Supply name or regulator ID.
* @ret: 0 on success, -ENODEV if lookup fails permanently, -EPROBE_DEFER if
* lookup could succeed in the future.
*
* If successful, returns a struct regulator_dev that corresponds to the name
* @supply and with the embedded struct device refcount incremented by one.
Expand Down Expand Up @@ -1534,14 +1532,6 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
if (IS_ERR(r)) {
ret = PTR_ERR(r);

if (ret == -ENODEV) {
/*
* No supply was specified for this regulator and
* there will never be one.
*/
return 0;
}

/* Did the lookup explicitly defer for us? */
if (ret == -EPROBE_DEFER)
return ret;
Expand Down Expand Up @@ -1799,7 +1789,7 @@ static void _regulator_put(struct regulator *regulator)
put_device(&rdev->dev);
mutex_unlock(&rdev->mutex);

kfree(regulator->supply_name);
kfree_const(regulator->supply_name);
kfree(regulator);

module_put(rdev->owner);
Expand Down Expand Up @@ -2486,7 +2476,7 @@ static int _regulator_list_voltage(struct regulator *regulator,
ret = ops->list_voltage(rdev, selector);
if (lock)
mutex_unlock(&rdev->mutex);
} else if (rdev->supply) {
} else if (rdev->is_switch && rdev->supply) {
ret = _regulator_list_voltage(rdev->supply, selector, lock);
} else {
return -EINVAL;
Expand Down Expand Up @@ -2544,7 +2534,7 @@ int regulator_count_voltages(struct regulator *regulator)
if (rdev->desc->n_voltages)
return rdev->desc->n_voltages;

if (!rdev->supply)
if (!rdev->is_switch || !rdev->supply)
return -EINVAL;

return regulator_count_voltages(rdev->supply);
Expand Down Expand Up @@ -2941,8 +2931,10 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator,
if (ret < 0)
goto out2;

if (rdev->supply && (rdev->desc->min_dropout_uV ||
!rdev->desc->ops->get_voltage)) {
if (rdev->supply &&
regulator_ops_is_valid(rdev->supply->rdev,
REGULATOR_CHANGE_VOLTAGE) &&
(rdev->desc->min_dropout_uV || !rdev->desc->ops->get_voltage)) {
int current_supply_uV;
int selector;

Expand Down Expand Up @@ -4099,6 +4091,11 @@ regulator_register(const struct regulator_desc *regulator_desc,
mutex_unlock(&regulator_list_mutex);
}

if (!rdev->desc->ops->get_voltage &&
!rdev->desc->ops->list_voltage &&
!rdev->desc->fixed_uV)
rdev->is_switch = true;

ret = device_register(&rdev->dev);
if (ret != 0) {
put_device(&rdev->dev);
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct regulator {
int uA_load;
int min_uV;
int max_uV;
char *supply_name;
const char *supply_name;
struct device_attribute dev_attr;
struct regulator_dev *rdev;
struct dentry *debugfs;
Expand Down
2 changes: 2 additions & 0 deletions include/linux/regulator/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ struct regulator_dev {
struct regulator_enable_gpio *ena_pin;
unsigned int ena_gpio_state:1;

unsigned int is_switch:1;

/* time when this regulator was disabled last time */
unsigned long last_off_jiffy;
};
Expand Down

0 comments on commit bde1e61

Please sign in to comment.