@@ -26,6 +26,7 @@
#include <linux/device.h>
#include <linux/i2c.h>
#include <linux/sysfs.h>
+#include <linux/regulator/consumer.h>
#include <sound/tpa6130a2-plat.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
@@ -42,6 +43,7 @@ struct tpa6130a2_data {
unsigned char regs[TPA6130A2_CACHEREGNUM];
unsigned char power_state;
int (*set_power)(int state);
+ struct regulator *regulator;
};
static int tpa6130a2_i2c_read(int reg)
@@ -121,6 +123,8 @@ void tpa6130a2_power(int power)
mutex_lock(&data->mutex);
if (power) {
+ if (data->regulator)
+ regulator_enable(data->regulator);
/* Power on */
if (data->set_power) {
data->set_power(1);
@@ -141,6 +145,8 @@ void tpa6130a2_power(int power)
data->set_power(0);
data->power_state = 0;
}
+ if (data->regulator)
+ regulator_disable(data->regulator);
}
mutex_unlock(&data->mutex);
}
@@ -292,6 +298,12 @@ static int tpa6130a2_probe(struct i2c_client *client,
}
pdata = (struct tpa6130a2_platform_data *)client->dev.platform_data;
+ data->regulator = regulator_get(dev, "vdd");
+ if (IS_ERR(data->regulator)) {
+ dev_info(dev, "Could not get regulator for vdd. "
+ "Executing without regulator.\n");
+ data->regulator = NULL;
+ }
/* Set default register values */
data->regs[TPA6130A2_REG_CONTROL] = TPA6130A2_SWS |
TPA6130A2_HP_EN_R |
@@ -326,6 +338,8 @@ static int tpa6130a2_probe(struct i2c_client *client,
return 0;
fail3:
tpa6130a2_power(0);
+ if (data->regulator)
+ regulator_put(data->regulator);
fail2:
kfree(data);
i2c_set_clientdata(tpa6130a2_client, NULL);
@@ -340,6 +354,8 @@ static int tpa6130a2_remove(struct i2c_client *client)
struct tpa6130a2_data *data = i2c_get_clientdata(client);
tpa6130a2_power(0);
+ if (data->regulator)
+ regulator_put(data->regulator);
kfree(data);
tpa6130a2_client = 0;