diff options
author | Peter Ujfalusi <peter.ujfalusi@ti.com> | 2014-01-03 08:27:49 -0500 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-01-08 07:48:53 -0500 |
commit | a8fc415c29a62e4f0a7a932110ee9d8423e2cc52 (patch) | |
tree | 85f9155f72cf260556e67e4685607415d32ed760 /sound | |
parent | 258549c06803da30acf0971807c985bf83db8491 (diff) |
ASoC: twl4030: Separate write condition checking from I/O function
Simplifies the code a bit and prepares it to the removal of local caching.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/soc/codecs/twl4030.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c index dfc51bb425da..419108ae31de 100644 --- a/sound/soc/codecs/twl4030.c +++ b/sound/soc/codecs/twl4030.c | |||
@@ -181,50 +181,56 @@ static inline void twl4030_write_reg_cache(struct snd_soc_codec *codec, | |||
181 | cache[reg] = value; | 181 | cache[reg] = value; |
182 | } | 182 | } |
183 | 183 | ||
184 | /* | 184 | static bool twl4030_can_write_to_chip(struct snd_soc_codec *codec, |
185 | * write to the twl4030 register space | 185 | unsigned int reg) |
186 | */ | ||
187 | static int twl4030_write(struct snd_soc_codec *codec, | ||
188 | unsigned int reg, unsigned int value) | ||
189 | { | 186 | { |
190 | struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); | 187 | struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); |
191 | int write_to_reg = 0; | 188 | bool write_to_reg = false; |
192 | 189 | ||
193 | twl4030_write_reg_cache(codec, reg, value); | ||
194 | /* Decide if the given register can be written */ | 190 | /* Decide if the given register can be written */ |
195 | switch (reg) { | 191 | switch (reg) { |
196 | case TWL4030_REG_EAR_CTL: | 192 | case TWL4030_REG_EAR_CTL: |
197 | if (twl4030->earpiece_enabled) | 193 | if (twl4030->earpiece_enabled) |
198 | write_to_reg = 1; | 194 | write_to_reg = true; |
199 | break; | 195 | break; |
200 | case TWL4030_REG_PREDL_CTL: | 196 | case TWL4030_REG_PREDL_CTL: |
201 | if (twl4030->predrivel_enabled) | 197 | if (twl4030->predrivel_enabled) |
202 | write_to_reg = 1; | 198 | write_to_reg = true; |
203 | break; | 199 | break; |
204 | case TWL4030_REG_PREDR_CTL: | 200 | case TWL4030_REG_PREDR_CTL: |
205 | if (twl4030->predriver_enabled) | 201 | if (twl4030->predriver_enabled) |
206 | write_to_reg = 1; | 202 | write_to_reg = true; |
207 | break; | 203 | break; |
208 | case TWL4030_REG_PRECKL_CTL: | 204 | case TWL4030_REG_PRECKL_CTL: |
209 | if (twl4030->carkitl_enabled) | 205 | if (twl4030->carkitl_enabled) |
210 | write_to_reg = 1; | 206 | write_to_reg = true; |
211 | break; | 207 | break; |
212 | case TWL4030_REG_PRECKR_CTL: | 208 | case TWL4030_REG_PRECKR_CTL: |
213 | if (twl4030->carkitr_enabled) | 209 | if (twl4030->carkitr_enabled) |
214 | write_to_reg = 1; | 210 | write_to_reg = true; |
215 | break; | 211 | break; |
216 | case TWL4030_REG_HS_GAIN_SET: | 212 | case TWL4030_REG_HS_GAIN_SET: |
217 | if (twl4030->hsl_enabled || twl4030->hsr_enabled) | 213 | if (twl4030->hsl_enabled || twl4030->hsr_enabled) |
218 | write_to_reg = 1; | 214 | write_to_reg = true; |
219 | break; | 215 | break; |
220 | default: | 216 | default: |
221 | /* All other register can be written */ | 217 | /* All other register can be written */ |
222 | write_to_reg = 1; | 218 | write_to_reg = true; |
223 | break; | 219 | break; |
224 | } | 220 | } |
225 | if (write_to_reg) | 221 | |
226 | return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, | 222 | return write_to_reg; |
227 | value, reg); | 223 | } |
224 | |||
225 | /* | ||
226 | * write to the twl4030 register space | ||
227 | */ | ||
228 | static int twl4030_write(struct snd_soc_codec *codec, | ||
229 | unsigned int reg, unsigned int value) | ||
230 | { | ||
231 | twl4030_write_reg_cache(codec, reg, value); | ||
232 | if (twl4030_can_write_to_chip(codec, reg)) | ||
233 | return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, value, reg); | ||
228 | 234 | ||
229 | return 0; | 235 | return 0; |
230 | } | 236 | } |