aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs
diff options
context:
space:
mode:
authorBarry Song <21cnbao@gmail.com>2010-03-28 23:16:00 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2010-03-29 16:02:24 -0400
commit9dd7b79a86c53a097463ee1582c0bc6c4b83b770 (patch)
tree595e287ac87329f561c7a192ffc97d0aea36a7dd /sound/soc/codecs
parente6ab07ce0f0cb1636fd14aa4f3e6e9631bd5d0c6 (diff)
ASoC: ad193x: move codec register/unregister to bus probe/remove
The way i've factored out the bus probe and removal functions so that there's no code in the individual I2C and SPI functions means that the register() and unregister() functions could just be squashed into the bus_probe() and bus_remove() functions. Signed-off-by: Barry Song <21cnbao@gmail.com> Acked-by: Liam Girdwood <lrg@slimlogic.co.uk> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r--sound/soc/codecs/ad193x.c102
1 files changed, 44 insertions, 58 deletions
diff --git a/sound/soc/codecs/ad193x.c b/sound/soc/codecs/ad193x.c
index e10820670752..4bfd66bc2624 100644
--- a/sound/soc/codecs/ad193x.c
+++ b/sound/soc/codecs/ad193x.c
@@ -35,8 +35,6 @@ static const u8 ad193x_reg[AD193X_NUM_REGS] = {
35 35
36static struct snd_soc_codec *ad193x_codec; 36static struct snd_soc_codec *ad193x_codec;
37struct snd_soc_codec_device soc_codec_dev_ad193x; 37struct snd_soc_codec_device soc_codec_dev_ad193x;
38static int ad193x_register(struct ad193x_priv *ad193x, int bus_type);
39static void ad193x_unregister(struct ad193x_priv *ad193x);
40 38
41/* 39/*
42 * AD193X volume/mute/de-emphasis etc. controls 40 * AD193X volume/mute/de-emphasis etc. controls
@@ -290,69 +288,23 @@ static int ad193x_bus_probe(struct device *dev, void *ctrl_data, int bus_type)
290{ 288{
291 struct snd_soc_codec *codec; 289 struct snd_soc_codec *codec;
292 struct ad193x_priv *ad193x; 290 struct ad193x_priv *ad193x;
291 int ret;
292
293 if (ad193x_codec) {
294 dev_err(dev, "Another ad193x is registered\n");
295 return -EINVAL;
296 }
293 297
294 ad193x = kzalloc(sizeof(struct ad193x_priv), GFP_KERNEL); 298 ad193x = kzalloc(sizeof(struct ad193x_priv), GFP_KERNEL);
295 if (ad193x == NULL) 299 if (ad193x == NULL)
296 return -ENOMEM; 300 return -ENOMEM;
297 301
298 codec = &ad193x->codec;
299 codec->control_data = ctrl_data;
300 codec->dev = dev;
301
302 dev_set_drvdata(dev, ad193x); 302 dev_set_drvdata(dev, ad193x);
303 303
304 return ad193x_register(ad193x, bus_type); 304 codec = &ad193x->codec;
305}
306
307static int ad193x_bus_remove(struct device *dev)
308{
309 struct ad193x_priv *ad193x = dev_get_drvdata(dev);
310
311 ad193x_unregister(ad193x);
312 return 0;
313}
314
315static struct snd_soc_dai_ops ad193x_dai_ops = {
316 .hw_params = ad193x_hw_params,
317 .digital_mute = ad193x_mute,
318 .set_tdm_slot = ad193x_set_tdm_slot,
319 .set_fmt = ad193x_set_dai_fmt,
320};
321
322/* codec DAI instance */
323struct snd_soc_dai ad193x_dai = {
324 .name = "AD193X",
325 .playback = {
326 .stream_name = "Playback",
327 .channels_min = 2,
328 .channels_max = 8,
329 .rates = SNDRV_PCM_RATE_48000,
330 .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE |
331 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE,
332 },
333 .capture = {
334 .stream_name = "Capture",
335 .channels_min = 2,
336 .channels_max = 4,
337 .rates = SNDRV_PCM_RATE_48000,
338 .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE |
339 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE,
340 },
341 .ops = &ad193x_dai_ops,
342};
343EXPORT_SYMBOL_GPL(ad193x_dai);
344
345static int ad193x_register(struct ad193x_priv *ad193x, int bus_type)
346{
347 int ret;
348 struct snd_soc_codec *codec = &ad193x->codec;
349
350 if (ad193x_codec) {
351 dev_err(codec->dev, "Another ad193x is registered\n");
352 return -EINVAL;
353 }
354
355 mutex_init(&codec->mutex); 305 mutex_init(&codec->mutex);
306 codec->control_data = ctrl_data;
307 codec->dev = dev;
356 codec->private_data = ad193x; 308 codec->private_data = ad193x;
357 codec->reg_cache = ad193x->reg_cache; 309 codec->reg_cache = ad193x->reg_cache;
358 codec->reg_cache_size = AD193X_NUM_REGS; 310 codec->reg_cache_size = AD193X_NUM_REGS;
@@ -413,14 +365,48 @@ static int ad193x_register(struct ad193x_priv *ad193x, int bus_type)
413 return 0; 365 return 0;
414} 366}
415 367
416static void ad193x_unregister(struct ad193x_priv *ad193x) 368static int ad193x_bus_remove(struct device *dev)
417{ 369{
370 struct ad193x_priv *ad193x = dev_get_drvdata(dev);
371
418 snd_soc_unregister_dai(&ad193x_dai); 372 snd_soc_unregister_dai(&ad193x_dai);
419 snd_soc_unregister_codec(&ad193x->codec); 373 snd_soc_unregister_codec(&ad193x->codec);
420 kfree(ad193x); 374 kfree(ad193x);
421 ad193x_codec = NULL; 375 ad193x_codec = NULL;
376
377 return 0;
422} 378}
423 379
380static struct snd_soc_dai_ops ad193x_dai_ops = {
381 .hw_params = ad193x_hw_params,
382 .digital_mute = ad193x_mute,
383 .set_tdm_slot = ad193x_set_tdm_slot,
384 .set_fmt = ad193x_set_dai_fmt,
385};
386
387/* codec DAI instance */
388struct snd_soc_dai ad193x_dai = {
389 .name = "AD193X",
390 .playback = {
391 .stream_name = "Playback",
392 .channels_min = 2,
393 .channels_max = 8,
394 .rates = SNDRV_PCM_RATE_48000,
395 .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE |
396 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE,
397 },
398 .capture = {
399 .stream_name = "Capture",
400 .channels_min = 2,
401 .channels_max = 4,
402 .rates = SNDRV_PCM_RATE_48000,
403 .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE |
404 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE,
405 },
406 .ops = &ad193x_dai_ops,
407};
408EXPORT_SYMBOL_GPL(ad193x_dai);
409
424static int ad193x_probe(struct platform_device *pdev) 410static int ad193x_probe(struct platform_device *pdev)
425{ 411{
426 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 412 struct snd_soc_device *socdev = platform_get_drvdata(pdev);