diff options
-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; |