diff mbox

[7/8] ASoC: tlv320aic3x: add initial usage of regulator framework to control avdd_dac

Message ID 1255003137-1034-8-git-send-email-eduardo.valentin@nokia.com (mailing list archive)
State Awaiting Upstream, archived
Headers show

Commit Message

Eduardo Valentin Oct. 8, 2009, 11:58 a.m. UTC
None
diff mbox

Patch

diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 3395cf9..82e0a64 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -38,6 +38,7 @@ 
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/i2c.h>
+#include <linux/regulator/consumer.h>
 #include <linux/platform_device.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -56,6 +57,7 @@  struct aic3x_priv {
 	struct snd_soc_codec codec;
 	unsigned int sysclk;
 	int master;
+	struct regulator *regulator;
 };
 
 /*
@@ -1286,6 +1288,11 @@  static int aic3x_unregister(struct aic3x_priv *aic3x)
 	snd_soc_unregister_dai(&aic3x_dai);
 	snd_soc_unregister_codec(&aic3x->codec);
 
+	if (aic3x->regulator) {
+		regulator_disable(aic3x->regulator);
+		regulator_put(aic3x->regulator);
+	}
+
 	kfree(aic3x);
 	aic3x_codec = NULL;
 
@@ -1320,6 +1327,25 @@  static int aic3x_i2c_probe(struct i2c_client *i2c,
 	codec->control_data = i2c;
 	codec->hw_write = (hw_write_t) i2c_master_send;
 
+	aic3x->regulator = regulator_get(&i2c->dev, "avdd_dac");
+	if (IS_ERR(aic3x->regulator)) {
+		dev_warn(&i2c->dev, "No regulator to supply avdd_dac."
+					" Assuming always on.\n");
+		aic3x->regulator = NULL;
+	}
+
+	/*
+	 * REVISIT: Need to add proper code to put into sleep mode
+	 * avdd_dac regulator. For now, just leave it on.
+	 */
+	if (aic3x->regulator) {
+		int err;
+
+		err = regulator_enable(aic3x->regulator);
+		if (err < 0)
+			return err;
+	}
+
 	i2c_set_clientdata(i2c, aic3x);
 
 	return aic3x_register(codec);