ttc-dkb.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * linux/sound/soc/pxa/ttc_dkb.c
  3. *
  4. * Copyright (C) 2012 Marvell International Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <linux/module.h>
  22. #include <linux/moduleparam.h>
  23. #include <sound/core.h>
  24. #include <sound/pcm.h>
  25. #include <sound/soc.h>
  26. #include <sound/jack.h>
  27. #include <asm/mach-types.h>
  28. #include <sound/pcm_params.h>
  29. #include "../codecs/88pm860x-codec.h"
  30. static struct snd_soc_jack hs_jack, mic_jack;
  31. static struct snd_soc_jack_pin hs_jack_pins[] = {
  32. { .pin = "Headset Stereophone", .mask = SND_JACK_HEADPHONE, },
  33. };
  34. static struct snd_soc_jack_pin mic_jack_pins[] = {
  35. { .pin = "Headset Mic 2", .mask = SND_JACK_MICROPHONE, },
  36. };
  37. /* ttc machine dapm widgets */
  38. static const struct snd_soc_dapm_widget ttc_dapm_widgets[] = {
  39. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  40. SND_SOC_DAPM_LINE("Lineout Out 1", NULL),
  41. SND_SOC_DAPM_LINE("Lineout Out 2", NULL),
  42. SND_SOC_DAPM_SPK("Ext Speaker", NULL),
  43. SND_SOC_DAPM_MIC("Ext Mic 1", NULL),
  44. SND_SOC_DAPM_MIC("Headset Mic 2", NULL),
  45. SND_SOC_DAPM_MIC("Ext Mic 3", NULL),
  46. };
  47. /* ttc machine audio map */
  48. static const struct snd_soc_dapm_route ttc_audio_map[] = {
  49. {"Headset Stereophone", NULL, "HS1"},
  50. {"Headset Stereophone", NULL, "HS2"},
  51. {"Ext Speaker", NULL, "LSP"},
  52. {"Ext Speaker", NULL, "LSN"},
  53. {"Lineout Out 1", NULL, "LINEOUT1"},
  54. {"Lineout Out 2", NULL, "LINEOUT2"},
  55. {"MIC1P", NULL, "Mic1 Bias"},
  56. {"MIC1N", NULL, "Mic1 Bias"},
  57. {"Mic1 Bias", NULL, "Ext Mic 1"},
  58. {"MIC2P", NULL, "Mic1 Bias"},
  59. {"MIC2N", NULL, "Mic1 Bias"},
  60. {"Mic1 Bias", NULL, "Headset Mic 2"},
  61. {"MIC3P", NULL, "Mic3 Bias"},
  62. {"MIC3N", NULL, "Mic3 Bias"},
  63. {"Mic3 Bias", NULL, "Ext Mic 3"},
  64. };
  65. static int ttc_pm860x_init(struct snd_soc_pcm_runtime *rtd)
  66. {
  67. struct snd_soc_codec *codec = rtd->codec;
  68. /* Headset jack detection */
  69. snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE |
  70. SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2,
  71. &hs_jack, hs_jack_pins, ARRAY_SIZE(hs_jack_pins));
  72. snd_soc_card_jack_new(rtd->card, "Microphone Jack", SND_JACK_MICROPHONE,
  73. &mic_jack, mic_jack_pins,
  74. ARRAY_SIZE(mic_jack_pins));
  75. /* headphone, microphone detection & headset short detection */
  76. pm860x_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADPHONE,
  77. SND_JACK_BTN_0, SND_JACK_BTN_1, SND_JACK_BTN_2);
  78. pm860x_mic_jack_detect(codec, &hs_jack, SND_JACK_MICROPHONE);
  79. return 0;
  80. }
  81. /* ttc/td-dkb digital audio interface glue - connects codec <--> CPU */
  82. static struct snd_soc_dai_link ttc_pm860x_hifi_dai[] = {
  83. {
  84. .name = "88pm860x i2s",
  85. .stream_name = "audio playback",
  86. .codec_name = "88pm860x-codec",
  87. .platform_name = "mmp-pcm-audio",
  88. .cpu_dai_name = "pxa-ssp-dai.1",
  89. .codec_dai_name = "88pm860x-i2s",
  90. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  91. SND_SOC_DAIFMT_CBM_CFM,
  92. .init = ttc_pm860x_init,
  93. },
  94. };
  95. /* ttc/td audio machine driver */
  96. static struct snd_soc_card ttc_dkb_card = {
  97. .name = "ttc-dkb-hifi",
  98. .owner = THIS_MODULE,
  99. .dai_link = ttc_pm860x_hifi_dai,
  100. .num_links = ARRAY_SIZE(ttc_pm860x_hifi_dai),
  101. .dapm_widgets = ttc_dapm_widgets,
  102. .num_dapm_widgets = ARRAY_SIZE(ttc_dapm_widgets),
  103. .dapm_routes = ttc_audio_map,
  104. .num_dapm_routes = ARRAY_SIZE(ttc_audio_map),
  105. };
  106. static int ttc_dkb_probe(struct platform_device *pdev)
  107. {
  108. struct snd_soc_card *card = &ttc_dkb_card;
  109. int ret;
  110. card->dev = &pdev->dev;
  111. ret = devm_snd_soc_register_card(&pdev->dev, card);
  112. if (ret)
  113. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  114. ret);
  115. return ret;
  116. }
  117. static struct platform_driver ttc_dkb_driver = {
  118. .driver = {
  119. .name = "ttc-dkb-audio",
  120. .pm = &snd_soc_pm_ops,
  121. },
  122. .probe = ttc_dkb_probe,
  123. };
  124. module_platform_driver(ttc_dkb_driver);
  125. /* Module information */
  126. MODULE_AUTHOR("Qiao Zhou, <zhouqiao@marvell.com>");
  127. MODULE_DESCRIPTION("ALSA SoC TTC DKB");
  128. MODULE_LICENSE("GPL");
  129. MODULE_ALIAS("platform:ttc-dkb-audio");