diff options
author | Prashant Gaikwad <pgaikwad@nvidia.com> | 2011-01-27 18:23:33 +0530 |
---|---|---|
committer | Varun Colbert <vcolbert@nvidia.com> | 2011-01-27 17:19:10 -0800 |
commit | 8bece06b922468da92d48b51482be5a965451857 (patch) | |
tree | fa096184a73088a65fb802190a1af636f5a9f8ea /drivers | |
parent | 170d80909110ad7d437bccc9bffe9bbed32599fc (diff) |
iio: light: als: Enable and disable regulator
Regulator has to be enabled for ISL29018.
Bug 782958
Change-Id: Ic8d86107d905c9b8e1d4a858c9028b0a13d3d188
Reviewed-on: http://git-master/r/17201
Tested-by: Prashant Gaikwad <pgaikwad@nvidia.com>
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/iio/light/isl29018.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/staging/iio/light/isl29018.c b/drivers/staging/iio/light/isl29018.c index defaf28a02d5..179835e7a84f 100644 --- a/drivers/staging/iio/light/isl29018.c +++ b/drivers/staging/iio/light/isl29018.c @@ -21,6 +21,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include <linux/regulator/consumer.h> #include <linux/module.h> #include <linux/i2c.h> #include <linux/err.h> @@ -61,6 +62,7 @@ struct isl29018_chip { unsigned int adc_bit; int prox_scheme; u8 reg_cache[ISL29018_MAX_REGS]; + struct regulator *regulator; }; static bool isl29018_write_data(struct i2c_client *client, u8 reg, @@ -425,6 +427,38 @@ static const struct attribute_group isl29108_group = { .attrs = isl29018_attributes, }; +static void isl29018_regulator_enable(struct i2c_client *client) +{ + struct isl29018_chip *chip = i2c_get_clientdata(client); + + chip->regulator = regulator_get(NULL, "vdd_vcore_phtn"); + if (IS_ERR_OR_NULL(chip->regulator)) { + dev_err(&client->dev, "Couldn't get regulator vdd_vcore_phtn\n"); + chip->regulator = NULL; + } + else { + regulator_enable(chip->regulator); + /* Optimal time to get the regulator turned on + * before initializing isl29018 chip*/ + mdelay(5); + } +} + +static void isl29018_regulator_disable(struct i2c_client *client) +{ + struct isl29018_chip *chip = i2c_get_clientdata(client); + struct regulator *isl29018_reg = chip->regulator; + int ret; + + if (isl29018_reg) { + ret = regulator_is_enabled(isl29018_reg); + if (ret > 0) + regulator_disable(isl29018_reg); + regulator_put(isl29018_reg); + } + chip->regulator = NULL; +} + static int isl29018_chip_init(struct i2c_client *client) { struct isl29018_chip *chip = i2c_get_clientdata(client); @@ -433,6 +467,8 @@ static int isl29018_chip_init(struct i2c_client *client) int new_adc_bit; unsigned int new_range; + isl29018_regulator_enable(client); + for (i = 0; i < ARRAY_SIZE(chip->reg_cache); i++) { chip->reg_cache[i] = 0; } @@ -506,6 +542,7 @@ static int __devexit isl29018_remove(struct i2c_client *client) struct isl29018_chip *chip = i2c_get_clientdata(client); dev_dbg(&client->dev, "%s()\n", __func__); + isl29018_regulator_disable(client); iio_device_unregister(chip->indio_dev); kfree(chip); return 0; |