regulator enable and disable sysfs control
This commit is contained in:
parent
b4d28f2e73
commit
5d37c72c64
1 changed files with 55 additions and 1 deletions
56
lichee/linux-4.9/drivers/regulator/core.c
Normal file → Executable file
56
lichee/linux-4.9/drivers/regulator/core.c
Normal file → Executable file
|
@ -99,6 +99,7 @@ struct regulator_supply_alias {
|
|||
};
|
||||
|
||||
static int _regulator_is_enabled(struct regulator_dev *rdev);
|
||||
static int _regulator_enable(struct regulator_dev *rdev);
|
||||
static int _regulator_disable(struct regulator_dev *rdev);
|
||||
static int _regulator_get_voltage(struct regulator_dev *rdev);
|
||||
static int _regulator_get_current_limit(struct regulator_dev *rdev);
|
||||
|
@ -915,6 +916,59 @@ static ssize_t regulator_print_state(char *buf, int state)
|
|||
return sprintf(buf, "unknown\n");
|
||||
}
|
||||
|
||||
static ssize_t regulator_state_store(struct device *dev,
|
||||
struct device_attribute *attr, const char *buf, size_t count)
|
||||
{
|
||||
struct regulator_dev *rdev = dev_get_drvdata(dev);
|
||||
int ret = 0;
|
||||
|
||||
#if 1
|
||||
if (sysfs_streq(buf, "enable")) {
|
||||
|
||||
pr_info("enable regulator %s\n", rdev_get_name(rdev));
|
||||
|
||||
mutex_lock(&rdev->mutex);
|
||||
ret = _regulator_enable(rdev);
|
||||
mutex_unlock(&rdev->mutex);
|
||||
|
||||
if (ret != 0) {
|
||||
pr_err("enable failed\n");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
else if(sysfs_streq(buf, "disable")) {
|
||||
if (_regulator_is_enabled(rdev) > 0) {
|
||||
pr_info("disable regulator %s\n", rdev_get_name(rdev));
|
||||
|
||||
mutex_lock(&rdev->mutex);
|
||||
ret = _regulator_disable(rdev);
|
||||
mutex_unlock(&rdev->mutex);
|
||||
|
||||
if (ret != 0) {
|
||||
pr_err("disable failed\n");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
else {
|
||||
pr_info("regulator already disabled");
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (sysfs_streq(buf, "enable")) {
|
||||
ret = regulator_enable(rdev->supply);
|
||||
if(ret)
|
||||
pr_info("enable regulator %s failed\n", rdev_get_name(rdev));
|
||||
}
|
||||
else if(sysfs_streq(buf, "disable")) {
|
||||
ret = regulator_disable(rdev->supply);
|
||||
if(ret)
|
||||
pr_info("diable regulator %s failed\n", rdev_get_name(rdev));
|
||||
}
|
||||
#endif
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t regulator_state_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
|
@ -927,7 +981,7 @@ static ssize_t regulator_state_show(struct device *dev,
|
|||
|
||||
return ret;
|
||||
}
|
||||
static DEVICE_ATTR(state, 0444, regulator_state_show, NULL);
|
||||
static DEVICE_ATTR(state, 0664, regulator_state_show, regulator_state_store);
|
||||
|
||||
static ssize_t regulator_status_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue