uda1380.c (111f6fbeb73fc350fe3a08c4ecd0ccdf3e13bef0) uda1380.c (5b2474425ed2a625b75dcd8d648701e473b7d764)
1/*
2 * uda1380.c - Philips UDA1380 ALSA SoC audio driver
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * Copyright (c) 2007 Philipp Zabel <philipp.zabel@gmail.com>

--- 342 unchanged lines hidden (view full) ---

351 ARRAY_SIZE(uda1380_dapm_widgets));
352
353 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
354
355 snd_soc_dapm_new_widgets(codec);
356 return 0;
357}
358
1/*
2 * uda1380.c - Philips UDA1380 ALSA SoC audio driver
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * Copyright (c) 2007 Philipp Zabel <philipp.zabel@gmail.com>

--- 342 unchanged lines hidden (view full) ---

351 ARRAY_SIZE(uda1380_dapm_widgets));
352
353 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
354
355 snd_soc_dapm_new_widgets(codec);
356 return 0;
357}
358
359static int uda1380_set_dai_fmt(struct snd_soc_dai *codec_dai,
359static int uda1380_set_dai_fmt_both(struct snd_soc_dai *codec_dai,
360 unsigned int fmt)
361{
362 struct snd_soc_codec *codec = codec_dai->codec;
363 int iface;
364
365 /* set up DAI based upon fmt */
366 iface = uda1380_read_reg_cache(codec, UDA1380_IFACE);
367 iface &= ~(R01_SFORI_MASK | R01_SIM | R01_SFORO_MASK);
368
360 unsigned int fmt)
361{
362 struct snd_soc_codec *codec = codec_dai->codec;
363 int iface;
364
365 /* set up DAI based upon fmt */
366 iface = uda1380_read_reg_cache(codec, UDA1380_IFACE);
367 iface &= ~(R01_SFORI_MASK | R01_SIM | R01_SFORO_MASK);
368
369 /* FIXME: how to select I2S for DATAO and MSB for DATAI correctly? */
370 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
371 case SND_SOC_DAIFMT_I2S:
372 iface |= R01_SFORI_I2S | R01_SFORO_I2S;
373 break;
374 case SND_SOC_DAIFMT_LSB:
369 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
370 case SND_SOC_DAIFMT_I2S:
371 iface |= R01_SFORI_I2S | R01_SFORO_I2S;
372 break;
373 case SND_SOC_DAIFMT_LSB:
375 iface |= R01_SFORI_LSB16 | R01_SFORO_I2S;
374 iface |= R01_SFORI_LSB16 | R01_SFORO_LSB16;
376 break;
377 case SND_SOC_DAIFMT_MSB:
375 break;
376 case SND_SOC_DAIFMT_MSB:
378 iface |= R01_SFORI_MSB | R01_SFORO_I2S;
377 iface |= R01_SFORI_MSB | R01_SFORO_MSB;
379 }
380
381 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBM_CFM)
382 iface |= R01_SIM;
383
384 uda1380_write(codec, UDA1380_IFACE, iface);
385
386 return 0;
387}
388
378 }
379
380 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBM_CFM)
381 iface |= R01_SIM;
382
383 uda1380_write(codec, UDA1380_IFACE, iface);
384
385 return 0;
386}
387
388static int uda1380_set_dai_fmt_playback(struct snd_soc_dai *codec_dai,
389 unsigned int fmt)
390{
391 struct snd_soc_codec *codec = codec_dai->codec;
392 int iface;
393
394 /* set up DAI based upon fmt */
395 iface = uda1380_read_reg_cache(codec, UDA1380_IFACE);
396 iface &= ~R01_SFORI_MASK;
397
398 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
399 case SND_SOC_DAIFMT_I2S:
400 iface |= R01_SFORI_I2S;
401 break;
402 case SND_SOC_DAIFMT_LSB:
403 iface |= R01_SFORI_LSB16;
404 break;
405 case SND_SOC_DAIFMT_MSB:
406 iface |= R01_SFORI_MSB;
407 }
408
409 uda1380_write(codec, UDA1380_IFACE, iface);
410
411 return 0;
412}
413
414static int uda1380_set_dai_fmt_capture(struct snd_soc_dai *codec_dai,
415 unsigned int fmt)
416{
417 struct snd_soc_codec *codec = codec_dai->codec;
418 int iface;
419
420 /* set up DAI based upon fmt */
421 iface = uda1380_read_reg_cache(codec, UDA1380_IFACE);
422 iface &= ~(R01_SIM | R01_SFORO_MASK);
423
424 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
425 case SND_SOC_DAIFMT_I2S:
426 iface |= R01_SFORO_I2S;
427 break;
428 case SND_SOC_DAIFMT_LSB:
429 iface |= R01_SFORO_LSB16;
430 break;
431 case SND_SOC_DAIFMT_MSB:
432 iface |= R01_SFORO_MSB;
433 }
434
435 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBM_CFM)
436 iface |= R01_SIM;
437
438 uda1380_write(codec, UDA1380_IFACE, iface);
439
440 return 0;
441}
442
389/*
390 * Flush reg cache
391 * We can only write the interpolator and decimator registers
392 * when the DAI is being clocked by the CPU DAI. It's up to the
393 * machine and cpu DAI driver to do this before we are called.
394 */
395static int uda1380_pcm_prepare(struct snd_pcm_substream *substream,
396 struct snd_soc_dai *dai)

--- 147 unchanged lines hidden (view full) ---

544 .channels_max = 2,
545 .rates = UDA1380_RATES,
546 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
547 .ops = {
548 .hw_params = uda1380_pcm_hw_params,
549 .shutdown = uda1380_pcm_shutdown,
550 .prepare = uda1380_pcm_prepare,
551 .digital_mute = uda1380_mute,
443/*
444 * Flush reg cache
445 * We can only write the interpolator and decimator registers
446 * when the DAI is being clocked by the CPU DAI. It's up to the
447 * machine and cpu DAI driver to do this before we are called.
448 */
449static int uda1380_pcm_prepare(struct snd_pcm_substream *substream,
450 struct snd_soc_dai *dai)

--- 147 unchanged lines hidden (view full) ---

598 .channels_max = 2,
599 .rates = UDA1380_RATES,
600 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
601 .ops = {
602 .hw_params = uda1380_pcm_hw_params,
603 .shutdown = uda1380_pcm_shutdown,
604 .prepare = uda1380_pcm_prepare,
605 .digital_mute = uda1380_mute,
552 .set_fmt = uda1380_set_dai_fmt,
606 .set_fmt = uda1380_set_dai_fmt_both,
553 },
554},
555{ /* playback only - dual interface */
556 .name = "UDA1380",
557 .playback = {
558 .stream_name = "Playback",
559 .channels_min = 1,
560 .channels_max = 2,
561 .rates = UDA1380_RATES,
562 .formats = SNDRV_PCM_FMTBIT_S16_LE,
563 },
564 .ops = {
565 .hw_params = uda1380_pcm_hw_params,
566 .shutdown = uda1380_pcm_shutdown,
567 .prepare = uda1380_pcm_prepare,
568 .digital_mute = uda1380_mute,
607 },
608},
609{ /* playback only - dual interface */
610 .name = "UDA1380",
611 .playback = {
612 .stream_name = "Playback",
613 .channels_min = 1,
614 .channels_max = 2,
615 .rates = UDA1380_RATES,
616 .formats = SNDRV_PCM_FMTBIT_S16_LE,
617 },
618 .ops = {
619 .hw_params = uda1380_pcm_hw_params,
620 .shutdown = uda1380_pcm_shutdown,
621 .prepare = uda1380_pcm_prepare,
622 .digital_mute = uda1380_mute,
569 .set_fmt = uda1380_set_dai_fmt,
623 .set_fmt = uda1380_set_dai_fmt_playback,
570 },
571},
572{ /* capture only - dual interface*/
573 .name = "UDA1380",
574 .capture = {
575 .stream_name = "Capture",
576 .channels_min = 1,
577 .channels_max = 2,
578 .rates = UDA1380_RATES,
579 .formats = SNDRV_PCM_FMTBIT_S16_LE,
580 },
581 .ops = {
582 .hw_params = uda1380_pcm_hw_params,
583 .shutdown = uda1380_pcm_shutdown,
584 .prepare = uda1380_pcm_prepare,
624 },
625},
626{ /* capture only - dual interface*/
627 .name = "UDA1380",
628 .capture = {
629 .stream_name = "Capture",
630 .channels_min = 1,
631 .channels_max = 2,
632 .rates = UDA1380_RATES,
633 .formats = SNDRV_PCM_FMTBIT_S16_LE,
634 },
635 .ops = {
636 .hw_params = uda1380_pcm_hw_params,
637 .shutdown = uda1380_pcm_shutdown,
638 .prepare = uda1380_pcm_prepare,
585 .set_fmt = uda1380_set_dai_fmt,
639 .set_fmt = uda1380_set_dai_fmt_capture,
586 },
587},
588};
589EXPORT_SYMBOL_GPL(uda1380_dai);
590
591static int uda1380_suspend(struct platform_device *pdev, pm_message_t state)
592{
593 struct snd_soc_device *socdev = platform_get_drvdata(pdev);

--- 251 unchanged lines hidden ---
640 },
641},
642};
643EXPORT_SYMBOL_GPL(uda1380_dai);
644
645static int uda1380_suspend(struct platform_device *pdev, pm_message_t state)
646{
647 struct snd_soc_device *socdev = platform_get_drvdata(pdev);

--- 251 unchanged lines hidden ---