aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/ssm2602.c
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2011-05-05 10:59:10 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-05-08 09:44:05 -0400
commit0b4cd2e01c63cf303bba570c9896331e4932a9df (patch)
treeb5843a1c3156e4ab0a7e0ec8011e8c5587f72a60 /sound/soc/codecs/ssm2602.c
parent5e8bc53b7c79c8184ca1a90f73286acff22f4c92 (diff)
ASoC: SSM2602: Cleanup coeff handling
Drop unused field from the coeff struct, precalculate the srate register at compile-time and cleanup up the naming. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs/ssm2602.c')
-rw-r--r--sound/soc/codecs/ssm2602.c75
1 files changed, 35 insertions, 40 deletions
diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c
index 565bc72fb173..73b447eba297 100644
--- a/sound/soc/codecs/ssm2602.c
+++ b/sound/soc/codecs/ssm2602.c
@@ -167,83 +167,78 @@ static int ssm2602_add_widgets(struct snd_soc_codec *codec)
167 return 0; 167 return 0;
168} 168}
169 169
170struct _coeff_div { 170struct ssm2602_coeff {
171 u32 mclk; 171 u32 mclk;
172 u32 rate; 172 u32 rate;
173 u16 fs; 173 u8 srate;
174 u8 sr:4;
175 u8 bosr:1;
176 u8 usb:1;
177}; 174};
178 175
179/* codec mclk clock divider coefficients */ 176#define SSM2602_COEFF_SRATE(sr, bosr, usb) (((sr) << 2) | ((bosr) << 1) | (usb))
180static const struct _coeff_div coeff_div[] = { 177
178/* codec mclk clock coefficients */
179static const struct ssm2602_coeff ssm2602_coeff_table[] = {
181 /* 48k */ 180 /* 48k */
182 {12288000, 48000, 256, 0x0, 0x0, 0x0}, 181 {12288000, 48000, SSM2602_COEFF_SRATE(0x0, 0x0, 0x0)},
183 {18432000, 48000, 384, 0x0, 0x1, 0x0}, 182 {18432000, 48000, SSM2602_COEFF_SRATE(0x0, 0x1, 0x0)},
184 {12000000, 48000, 250, 0x0, 0x0, 0x1}, 183 {12000000, 48000, SSM2602_COEFF_SRATE(0x0, 0x0, 0x1)},
185 184
186 /* 32k */ 185 /* 32k */
187 {12288000, 32000, 384, 0x6, 0x0, 0x0}, 186 {12288000, 32000, SSM2602_COEFF_SRATE(0x6, 0x0, 0x0)},
188 {18432000, 32000, 576, 0x6, 0x1, 0x0}, 187 {18432000, 32000, SSM2602_COEFF_SRATE(0x6, 0x1, 0x0)},
189 {12000000, 32000, 375, 0x6, 0x0, 0x1}, 188 {12000000, 32000, SSM2602_COEFF_SRATE(0x6, 0x0, 0x1)},
190 189
191 /* 8k */ 190 /* 8k */
192 {12288000, 8000, 1536, 0x3, 0x0, 0x0}, 191 {12288000, 8000, SSM2602_COEFF_SRATE(0x3, 0x0, 0x0)},
193 {18432000, 8000, 2304, 0x3, 0x1, 0x0}, 192 {18432000, 8000, SSM2602_COEFF_SRATE(0x3, 0x1, 0x0)},
194 {11289600, 8000, 1408, 0xb, 0x0, 0x0}, 193 {11289600, 8000, SSM2602_COEFF_SRATE(0xb, 0x0, 0x0)},
195 {16934400, 8000, 2112, 0xb, 0x1, 0x0}, 194 {16934400, 8000, SSM2602_COEFF_SRATE(0xb, 0x1, 0x0)},
196 {12000000, 8000, 1500, 0x3, 0x0, 0x1}, 195 {12000000, 8000, SSM2602_COEFF_SRATE(0x3, 0x0, 0x1)},
197 196
198 /* 96k */ 197 /* 96k */
199 {12288000, 96000, 128, 0x7, 0x0, 0x0}, 198 {12288000, 96000, SSM2602_COEFF_SRATE(0x7, 0x0, 0x0)},
200 {18432000, 96000, 192, 0x7, 0x1, 0x0}, 199 {18432000, 96000, SSM2602_COEFF_SRATE(0x7, 0x1, 0x0)},
201 {12000000, 96000, 125, 0x7, 0x0, 0x1}, 200 {12000000, 96000, SSM2602_COEFF_SRATE(0x7, 0x0, 0x1)},
202 201
203 /* 44.1k */ 202 /* 44.1k */
204 {11289600, 44100, 256, 0x8, 0x0, 0x0}, 203 {11289600, 44100, SSM2602_COEFF_SRATE(0x8, 0x0, 0x0)},
205 {16934400, 44100, 384, 0x8, 0x1, 0x0}, 204 {16934400, 44100, SSM2602_COEFF_SRATE(0x8, 0x1, 0x0)},
206 {12000000, 44100, 272, 0x8, 0x1, 0x1}, 205 {12000000, 44100, SSM2602_COEFF_SRATE(0x8, 0x1, 0x1)},
207 206
208 /* 88.2k */ 207 /* 88.2k */
209 {11289600, 88200, 128, 0xf, 0x0, 0x0}, 208 {11289600, 88200, SSM2602_COEFF_SRATE(0xf, 0x0, 0x0)},
210 {16934400, 88200, 192, 0xf, 0x1, 0x0}, 209 {16934400, 88200, SSM2602_COEFF_SRATE(0xf, 0x1, 0x0)},
211 {12000000, 88200, 136, 0xf, 0x1, 0x1}, 210 {12000000, 88200, SSM2602_COEFF_SRATE(0xf, 0x1, 0x1)},
212}; 211};
213 212
214static inline int get_coeff(int mclk, int rate) 213static inline int ssm2602_get_coeff(int mclk, int rate)
215{ 214{
216 int i; 215 int i;
217 216
218 for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { 217 for (i = 0; i < ARRAY_SIZE(ssm2602_coeff_table); i++) {
219 if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk) 218 if (ssm2602_coeff_table[i].rate == rate &&
220 return i; 219 ssm2602_coeff_table[i].mclk == mclk)
220 return ssm2602_coeff_table[i].srate;
221 } 221 }
222 return i; 222 return -EINVAL;
223} 223}
224 224
225static int ssm2602_hw_params(struct snd_pcm_substream *substream, 225static int ssm2602_hw_params(struct snd_pcm_substream *substream,
226 struct snd_pcm_hw_params *params, 226 struct snd_pcm_hw_params *params,
227 struct snd_soc_dai *dai) 227 struct snd_soc_dai *dai)
228{ 228{
229 u16 srate;
230 struct snd_soc_pcm_runtime *rtd = substream->private_data; 229 struct snd_soc_pcm_runtime *rtd = substream->private_data;
231 struct snd_soc_codec *codec = rtd->codec; 230 struct snd_soc_codec *codec = rtd->codec;
232 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); 231 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
233 u16 iface = snd_soc_read(codec, SSM2602_IFACE) & 0xfff3; 232 u16 iface = snd_soc_read(codec, SSM2602_IFACE) & 0xfff3;
234 int i = get_coeff(ssm2602->sysclk, params_rate(params)); 233 int srate = ssm2602_get_coeff(ssm2602->sysclk, params_rate(params));
235 234
236 if (substream == ssm2602->slave_substream) { 235 if (substream == ssm2602->slave_substream) {
237 dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n"); 236 dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n");
238 return 0; 237 return 0;
239 } 238 }
240 239
241 /*no match is found*/ 240 if (srate < 0)
242 if (i == ARRAY_SIZE(coeff_div)) 241 return srate;
243 return -EINVAL;
244
245 srate = (coeff_div[i].sr << 2) |
246 (coeff_div[i].bosr << 1) | coeff_div[i].usb;
247 242
248 snd_soc_write(codec, SSM2602_ACTIVE, 0); 243 snd_soc_write(codec, SSM2602_ACTIVE, 0);
249 snd_soc_write(codec, SSM2602_SRATE, srate); 244 snd_soc_write(codec, SSM2602_SRATE, srate);