aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/twl4030.c
diff options
context:
space:
mode:
authorPeter Ujfalusi <peter.ujfalusi@nokia.com>2009-01-27 04:29:40 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2009-01-27 05:42:39 -0500
commitdb04e2c58a65364218b89f1372b4b3b78d206423 (patch)
tree0e684dff51ae15530276b77a0a79c08e7372244f /sound/soc/codecs/twl4030.c
parent3fc93030e5a792fdd0da3321487f5cbfd1143c2b (diff)
ASoC: TWL4030: Code clean up for codec power up and down
Merge the codec up and down functions to a simple one. Codec is powered down by default (reg_cache change). Signed-off-by: Peter Ujfalusi <peter.ujfalusi@nokia.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs/twl4030.c')
-rw-r--r--sound/soc/codecs/twl4030.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 24419afd319..af7b433d4f5 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -42,7 +42,7 @@
42 */ 42 */
43static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = { 43static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = {
44 0x00, /* this register not used */ 44 0x00, /* this register not used */
45 0x93, /* REG_CODEC_MODE (0x1) */ 45 0x91, /* REG_CODEC_MODE (0x1) */
46 0xc3, /* REG_OPTION (0x2) */ 46 0xc3, /* REG_OPTION (0x2) */
47 0x00, /* REG_UNKNOWN (0x3) */ 47 0x00, /* REG_UNKNOWN (0x3) */
48 0x00, /* REG_MICBIAS_CTL (0x4) */ 48 0x00, /* REG_MICBIAS_CTL (0x4) */
@@ -154,26 +154,17 @@ static int twl4030_write(struct snd_soc_codec *codec,
154 return twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, value, reg); 154 return twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, value, reg);
155} 155}
156 156
157static void twl4030_clear_codecpdz(struct snd_soc_codec *codec) 157static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable)
158{ 158{
159 u8 mode; 159 u8 mode;
160 160
161 mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE); 161 mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE);
162 twl4030_write(codec, TWL4030_REG_CODEC_MODE, 162 if (enable)
163 mode & ~TWL4030_CODECPDZ); 163 mode |= TWL4030_CODECPDZ;
164 else
165 mode &= ~TWL4030_CODECPDZ;
164 166
165 /* REVISIT: this delay is present in TI sample drivers */ 167 twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
166 /* but there seems to be no TRM requirement for it */
167 udelay(10);
168}
169
170static void twl4030_set_codecpdz(struct snd_soc_codec *codec)
171{
172 u8 mode;
173
174 mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE);
175 twl4030_write(codec, TWL4030_REG_CODEC_MODE,
176 mode | TWL4030_CODECPDZ);
177 168
178 /* REVISIT: this delay is present in TI sample drivers */ 169 /* REVISIT: this delay is present in TI sample drivers */
179 /* but there seems to be no TRM requirement for it */ 170 /* but there seems to be no TRM requirement for it */
@@ -185,7 +176,7 @@ static void twl4030_init_chip(struct snd_soc_codec *codec)
185 int i; 176 int i;
186 177
187 /* clear CODECPDZ prior to setting register defaults */ 178 /* clear CODECPDZ prior to setting register defaults */
188 twl4030_clear_codecpdz(codec); 179 twl4030_codec_enable(codec, 0);
189 180
190 /* set all audio section registers to reasonable defaults */ 181 /* set all audio section registers to reasonable defaults */
191 for (i = TWL4030_REG_OPTION; i <= TWL4030_REG_MISC_SET_2; i++) 182 for (i = TWL4030_REG_OPTION; i <= TWL4030_REG_MISC_SET_2; i++)
@@ -895,7 +886,7 @@ static void twl4030_power_up(struct snd_soc_codec *codec)
895 int i = 0; 886 int i = 0;
896 887
897 /* set CODECPDZ to turn on codec */ 888 /* set CODECPDZ to turn on codec */
898 twl4030_set_codecpdz(codec); 889 twl4030_codec_enable(codec, 1);
899 890
900 /* initiate offset cancellation */ 891 /* initiate offset cancellation */
901 anamicl = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICL); 892 anamicl = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICL);
@@ -922,8 +913,8 @@ static void twl4030_power_up(struct snd_soc_codec *codec)
922 regmisc1 | TWL4030_SMOOTH_ANAVOL_EN); 913 regmisc1 | TWL4030_SMOOTH_ANAVOL_EN);
923 914
924 /* toggle CODECPDZ as per TRM */ 915 /* toggle CODECPDZ as per TRM */
925 twl4030_clear_codecpdz(codec); 916 twl4030_codec_enable(codec, 0);
926 twl4030_set_codecpdz(codec); 917 twl4030_codec_enable(codec, 1);
927 918
928 /* program anti-pop with bias ramp delay */ 919 /* program anti-pop with bias ramp delay */
929 popn = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET); 920 popn = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET);
@@ -952,7 +943,7 @@ static void twl4030_power_down(struct snd_soc_codec *codec)
952 twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn); 943 twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn);
953 944
954 /* power down */ 945 /* power down */
955 twl4030_clear_codecpdz(codec); 946 twl4030_codec_enable(codec, 0);
956} 947}
957 948
958static int twl4030_set_bias_level(struct snd_soc_codec *codec, 949static int twl4030_set_bias_level(struct snd_soc_codec *codec,
@@ -1030,7 +1021,7 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream,
1030 if (mode != old_mode) { 1021 if (mode != old_mode) {
1031 /* change rate and set CODECPDZ */ 1022 /* change rate and set CODECPDZ */
1032 twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode); 1023 twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
1033 twl4030_set_codecpdz(codec); 1024 twl4030_codec_enable(codec, 1);
1034 } 1025 }
1035 1026
1036 /* sample size */ 1027 /* sample size */
@@ -1053,13 +1044,13 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream,
1053 if (format != old_format) { 1044 if (format != old_format) {
1054 1045
1055 /* clear CODECPDZ before changing format (codec requirement) */ 1046 /* clear CODECPDZ before changing format (codec requirement) */
1056 twl4030_clear_codecpdz(codec); 1047 twl4030_codec_enable(codec, 0);
1057 1048
1058 /* change format */ 1049 /* change format */
1059 twl4030_write(codec, TWL4030_REG_AUDIO_IF, format); 1050 twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
1060 1051
1061 /* set CODECPDZ afterwards */ 1052 /* set CODECPDZ afterwards */
1062 twl4030_set_codecpdz(codec); 1053 twl4030_codec_enable(codec, 1);
1063 } 1054 }
1064 return 0; 1055 return 0;
1065} 1056}
@@ -1129,13 +1120,13 @@ static int twl4030_set_dai_fmt(struct snd_soc_dai *codec_dai,
1129 if (format != old_format) { 1120 if (format != old_format) {
1130 1121
1131 /* clear CODECPDZ before changing format (codec requirement) */ 1122 /* clear CODECPDZ before changing format (codec requirement) */
1132 twl4030_clear_codecpdz(codec); 1123 twl4030_codec_enable(codec, 0);
1133 1124
1134 /* change format */ 1125 /* change format */
1135 twl4030_write(codec, TWL4030_REG_AUDIO_IF, format); 1126 twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
1136 1127
1137 /* set CODECPDZ afterwards */ 1128 /* set CODECPDZ afterwards */
1138 twl4030_set_codecpdz(codec); 1129 twl4030_codec_enable(codec, 1);
1139 } 1130 }
1140 1131
1141 return 0; 1132 return 0;