Commit a9877b60 authored by Mark Brown's avatar Mark Brown

Merge remote-tracking branch 'regulator/topic/core' into regulator-next

parents 36818b82 39f802d6
...@@ -632,30 +632,6 @@ static ssize_t regulator_bypass_show(struct device *dev, ...@@ -632,30 +632,6 @@ static ssize_t regulator_bypass_show(struct device *dev,
static DEVICE_ATTR(bypass, 0444, static DEVICE_ATTR(bypass, 0444,
regulator_bypass_show, NULL); regulator_bypass_show, NULL);
/*
* These are the only attributes are present for all regulators.
* Other attributes are a function of regulator functionality.
*/
static struct attribute *regulator_dev_attrs[] = {
&dev_attr_name.attr,
&dev_attr_num_users.attr,
&dev_attr_type.attr,
NULL,
};
ATTRIBUTE_GROUPS(regulator_dev);
static void regulator_dev_release(struct device *dev)
{
struct regulator_dev *rdev = dev_get_drvdata(dev);
kfree(rdev);
}
static struct class regulator_class = {
.name = "regulator",
.dev_release = regulator_dev_release,
.dev_groups = regulator_dev_groups,
};
/* Calculate the new optimum regulator operating mode based on the new total /* Calculate the new optimum regulator operating mode based on the new total
* consumer load. All locks held by caller */ * consumer load. All locks held by caller */
static void drms_uA_update(struct regulator_dev *rdev) static void drms_uA_update(struct regulator_dev *rdev)
...@@ -3436,126 +3412,136 @@ int regulator_mode_to_status(unsigned int mode) ...@@ -3436,126 +3412,136 @@ int regulator_mode_to_status(unsigned int mode)
} }
EXPORT_SYMBOL_GPL(regulator_mode_to_status); EXPORT_SYMBOL_GPL(regulator_mode_to_status);
static struct attribute *regulator_dev_attrs[] = {
&dev_attr_name.attr,
&dev_attr_num_users.attr,
&dev_attr_type.attr,
&dev_attr_microvolts.attr,
&dev_attr_microamps.attr,
&dev_attr_opmode.attr,
&dev_attr_state.attr,
&dev_attr_status.attr,
&dev_attr_bypass.attr,
&dev_attr_requested_microamps.attr,
&dev_attr_min_microvolts.attr,
&dev_attr_max_microvolts.attr,
&dev_attr_min_microamps.attr,
&dev_attr_max_microamps.attr,
&dev_attr_suspend_standby_state.attr,
&dev_attr_suspend_mem_state.attr,
&dev_attr_suspend_disk_state.attr,
&dev_attr_suspend_standby_microvolts.attr,
&dev_attr_suspend_mem_microvolts.attr,
&dev_attr_suspend_disk_microvolts.attr,
&dev_attr_suspend_standby_mode.attr,
&dev_attr_suspend_mem_mode.attr,
&dev_attr_suspend_disk_mode.attr,
NULL
};
/* /*
* To avoid cluttering sysfs (and memory) with useless state, only * To avoid cluttering sysfs (and memory) with useless state, only
* create attributes that can be meaningfully displayed. * create attributes that can be meaningfully displayed.
*/ */
static int add_regulator_attributes(struct regulator_dev *rdev) static umode_t regulator_attr_is_visible(struct kobject *kobj,
struct attribute *attr, int idx)
{ {
struct device *dev = &rdev->dev; struct device *dev = kobj_to_dev(kobj);
struct regulator_dev *rdev = container_of(dev, struct regulator_dev, dev);
const struct regulator_ops *ops = rdev->desc->ops; const struct regulator_ops *ops = rdev->desc->ops;
int status = 0; umode_t mode = attr->mode;
/* these three are always present */
if (attr == &dev_attr_name.attr ||
attr == &dev_attr_num_users.attr ||
attr == &dev_attr_type.attr)
return mode;
/* some attributes need specific methods to be displayed */ /* some attributes need specific methods to be displayed */
if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) || if (attr == &dev_attr_microvolts.attr) {
(ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0) || if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) ||
(ops->list_voltage && ops->list_voltage(rdev, 0) >= 0) || (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0) ||
(rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1))) { (ops->list_voltage && ops->list_voltage(rdev, 0) >= 0) ||
status = device_create_file(dev, &dev_attr_microvolts); (rdev->desc->fixed_uV && rdev->desc->n_voltages == 1))
if (status < 0) return mode;
return status; return 0;
}
if (ops->get_current_limit) {
status = device_create_file(dev, &dev_attr_microamps);
if (status < 0)
return status;
}
if (ops->get_mode) {
status = device_create_file(dev, &dev_attr_opmode);
if (status < 0)
return status;
}
if (rdev->ena_pin || ops->is_enabled) {
status = device_create_file(dev, &dev_attr_state);
if (status < 0)
return status;
}
if (ops->get_status) {
status = device_create_file(dev, &dev_attr_status);
if (status < 0)
return status;
}
if (ops->get_bypass) {
status = device_create_file(dev, &dev_attr_bypass);
if (status < 0)
return status;
} }
if (attr == &dev_attr_microamps.attr)
return ops->get_current_limit ? mode : 0;
if (attr == &dev_attr_opmode.attr)
return ops->get_mode ? mode : 0;
if (attr == &dev_attr_state.attr)
return (rdev->ena_pin || ops->is_enabled) ? mode : 0;
if (attr == &dev_attr_status.attr)
return ops->get_status ? mode : 0;
if (attr == &dev_attr_bypass.attr)
return ops->get_bypass ? mode : 0;
/* some attributes are type-specific */ /* some attributes are type-specific */
if (rdev->desc->type == REGULATOR_CURRENT) { if (attr == &dev_attr_requested_microamps.attr)
status = device_create_file(dev, &dev_attr_requested_microamps); return rdev->desc->type == REGULATOR_CURRENT ? mode : 0;
if (status < 0)
return status;
}
/* all the other attributes exist to support constraints; /* all the other attributes exist to support constraints;
* don't show them if there are no constraints, or if the * don't show them if there are no constraints, or if the
* relevant supporting methods are missing. * relevant supporting methods are missing.
*/ */
if (!rdev->constraints) if (!rdev->constraints)
return status; return 0;
/* constraints need specific supporting methods */ /* constraints need specific supporting methods */
if (ops->set_voltage || ops->set_voltage_sel) { if (attr == &dev_attr_min_microvolts.attr ||
status = device_create_file(dev, &dev_attr_min_microvolts); attr == &dev_attr_max_microvolts.attr)
if (status < 0) return (ops->set_voltage || ops->set_voltage_sel) ? mode : 0;
return status;
status = device_create_file(dev, &dev_attr_max_microvolts); if (attr == &dev_attr_min_microamps.attr ||
if (status < 0) attr == &dev_attr_max_microamps.attr)
return status; return ops->set_current_limit ? mode : 0;
}
if (ops->set_current_limit) { if (attr == &dev_attr_suspend_standby_state.attr ||
status = device_create_file(dev, &dev_attr_min_microamps); attr == &dev_attr_suspend_mem_state.attr ||
if (status < 0) attr == &dev_attr_suspend_disk_state.attr)
return status; return mode;
status = device_create_file(dev, &dev_attr_max_microamps);
if (status < 0) if (attr == &dev_attr_suspend_standby_microvolts.attr ||
return status; attr == &dev_attr_suspend_mem_microvolts.attr ||
} attr == &dev_attr_suspend_disk_microvolts.attr)
return ops->set_suspend_voltage ? mode : 0;
status = device_create_file(dev, &dev_attr_suspend_standby_state);
if (status < 0) if (attr == &dev_attr_suspend_standby_mode.attr ||
return status; attr == &dev_attr_suspend_mem_mode.attr ||
status = device_create_file(dev, &dev_attr_suspend_mem_state); attr == &dev_attr_suspend_disk_mode.attr)
if (status < 0) return ops->set_suspend_mode ? mode : 0;
return status;
status = device_create_file(dev, &dev_attr_suspend_disk_state); return mode;
if (status < 0) }
return status;
static const struct attribute_group regulator_dev_group = {
.attrs = regulator_dev_attrs,
.is_visible = regulator_attr_is_visible,
};
static const struct attribute_group *regulator_dev_groups[] = {
&regulator_dev_group,
NULL
};
if (ops->set_suspend_voltage) { static void regulator_dev_release(struct device *dev)
status = device_create_file(dev, {
&dev_attr_suspend_standby_microvolts); struct regulator_dev *rdev = dev_get_drvdata(dev);
if (status < 0) kfree(rdev);
return status;
status = device_create_file(dev,
&dev_attr_suspend_mem_microvolts);
if (status < 0)
return status;
status = device_create_file(dev,
&dev_attr_suspend_disk_microvolts);
if (status < 0)
return status;
}
if (ops->set_suspend_mode) {
status = device_create_file(dev,
&dev_attr_suspend_standby_mode);
if (status < 0)
return status;
status = device_create_file(dev,
&dev_attr_suspend_mem_mode);
if (status < 0)
return status;
status = device_create_file(dev,
&dev_attr_suspend_disk_mode);
if (status < 0)
return status;
}
return status;
} }
static struct class regulator_class = {
.name = "regulator",
.dev_release = regulator_dev_release,
.dev_groups = regulator_dev_groups,
};
static void rdev_init_debugfs(struct regulator_dev *rdev) static void rdev_init_debugfs(struct regulator_dev *rdev)
{ {
rdev->debugfs = debugfs_create_dir(rdev_get_name(rdev), debugfs_root); rdev->debugfs = debugfs_create_dir(rdev_get_name(rdev), debugfs_root);
...@@ -3587,7 +3573,7 @@ regulator_register(const struct regulator_desc *regulator_desc, ...@@ -3587,7 +3573,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
{ {
const struct regulation_constraints *constraints = NULL; const struct regulation_constraints *constraints = NULL;
const struct regulator_init_data *init_data; const struct regulator_init_data *init_data;
static atomic_t regulator_no = ATOMIC_INIT(0); static atomic_t regulator_no = ATOMIC_INIT(-1);
struct regulator_dev *rdev; struct regulator_dev *rdev;
struct device *dev; struct device *dev;
int ret, i; int ret, i;
...@@ -3660,8 +3646,8 @@ regulator_register(const struct regulator_desc *regulator_desc, ...@@ -3660,8 +3646,8 @@ regulator_register(const struct regulator_desc *regulator_desc,
/* register with sysfs */ /* register with sysfs */
rdev->dev.class = &regulator_class; rdev->dev.class = &regulator_class;
rdev->dev.parent = dev; rdev->dev.parent = dev;
dev_set_name(&rdev->dev, "regulator.%d", dev_set_name(&rdev->dev, "regulator.%lu",
atomic_inc_return(&regulator_no) - 1); (unsigned long) atomic_inc_return(&regulator_no));
ret = device_register(&rdev->dev); ret = device_register(&rdev->dev);
if (ret != 0) { if (ret != 0) {
put_device(&rdev->dev); put_device(&rdev->dev);
...@@ -3694,11 +3680,6 @@ regulator_register(const struct regulator_desc *regulator_desc, ...@@ -3694,11 +3680,6 @@ regulator_register(const struct regulator_desc *regulator_desc,
if (ret < 0) if (ret < 0)
goto scrub; goto scrub;
/* add attributes supported by this regulator */
ret = add_regulator_attributes(rdev);
if (ret < 0)
goto scrub;
if (init_data && init_data->supply_regulator) if (init_data && init_data->supply_regulator)
supply = init_data->supply_regulator; supply = init_data->supply_regulator;
else if (regulator_desc->supply_name) else if (regulator_desc->supply_name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment