diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2015-07-15 07:49:56 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-07-15 07:50:02 +0200 |
commit | e47bfe803be150e705ea66939351346119ce107e (patch) | |
tree | 73426918c1813e0fb72443483327515c767786d6 /drivers/regulator/core.c | |
parent | 7dd0345b1ab8d9cd9f9672dd017b5bd3f1c24d17 (diff) | |
download | barebox-e47bfe803be150e705ea66939351346119ce107e.tar.gz barebox-e47bfe803be150e705ea66939351346119ce107e.tar.xz |
regulator: Factor out functions to work with regulator_internal
Internally we only have a struct regulator_internal, so factor
out regulator_enable_internal and regulator_disable_internal
functions which can be called from regulator internal code.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r-- | drivers/regulator/core.c | 86 |
1 files changed, 45 insertions, 41 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index a3c9e41abb..96bf846d9f 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -43,6 +43,49 @@ struct regulator { struct device_d *dev; }; +static int regulator_enable_internal(struct regulator_internal *ri) +{ + int ret; + + if (ri->enable_count) { + ri->enable_count++; + return 0; + } + + if (!ri->rdev->ops->enable) + return -ENOSYS; + + ret = ri->rdev->ops->enable(ri->rdev); + if (ret) + return ret; + + if (ri->enable_time_us) + udelay(ri->enable_time_us); + + ri->enable_count++; + + return 0; +} + +static int regulator_disable_internal(struct regulator_internal *ri) +{ + int ret; + + if (!ri->enable_count) + return -EINVAL; + + if (!ri->rdev->ops->disable) + return -ENOSYS; + + ret = ri->rdev->ops->disable(ri->rdev); + if (ret) + return ret; + + ri->enable_count--; + + return 0; +} + static struct regulator_internal * __regulator_register(struct regulator_dev *rd, const char *name) { struct regulator_internal *ri; @@ -239,32 +282,10 @@ struct regulator *regulator_get(struct device_d *dev, const char *supply) */ int regulator_enable(struct regulator *r) { - struct regulator_internal *ri; - int ret; - if (!r) return 0; - ri = r->ri; - - if (ri->enable_count) { - ri->enable_count++; - return 0; - } - - if (!ri->rdev->ops->enable) - return -ENOSYS; - - ret = ri->rdev->ops->enable(ri->rdev); - if (ret) - return ret; - - if (ri->enable_time_us) - udelay(ri->enable_time_us); - - ri->enable_count++; - - return 0; + return regulator_enable_internal(r->ri); } /* @@ -278,27 +299,10 @@ int regulator_enable(struct regulator *r) */ int regulator_disable(struct regulator *r) { - struct regulator_internal *ri; - int ret; - if (!r) return 0; - ri = r->ri; - - if (!ri->enable_count) - return -EINVAL; - - if (!ri->rdev->ops->disable) - return -ENOSYS; - - ret = ri->rdev->ops->disable(ri->rdev); - if (ret) - return ret; - - ri->enable_count--; - - return 0; + return regulator_disable_internal(r->ri); } static void regulator_print_one(struct regulator_internal *ri) |