ttc-dkb.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * linux/sound/soc/pxa/ttc_dkb.c
  4. *
  5. * Copyright (C) 2012 Marvell International Ltd.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/moduleparam.h>
  9. #include <sound/core.h>
  10. #include <sound/pcm.h>
  11. #include <sound/soc.h>
  12. #include <sound/jack.h>
  13. #include <asm/mach-types.h>
  14. #include <sound/pcm_params.h>
  15. #include "../codecs/88pm860x-codec.h"
  16. static struct snd_soc_jack hs_jack, mic_jack;
  17. static struct snd_soc_jack_pin hs_jack_pins[] = {
  18. { .pin = "Headset Stereophone", .mask = SND_JACK_HEADPHONE, },
  19. };
  20. static struct snd_soc_jack_pin mic_jack_pins[] = {
  21. { .pin = "Headset Mic 2", .mask = SND_JACK_MICROPHONE, },
  22. };
  23. /* ttc machine dapm widgets */
  24. static const struct snd_soc_dapm_widget ttc_dapm_widgets[] = {
  25. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  26. SND_SOC_DAPM_LINE("Lineout Out 1", NULL),
  27. SND_SOC_DAPM_LINE("Lineout Out 2", NULL),
  28. SND_SOC_DAPM_SPK("Ext Speaker", NULL),
  29. SND_SOC_DAPM_MIC("Ext Mic 1", NULL),
  30. SND_SOC_DAPM_MIC("Headset Mic 2", NULL),
  31. SND_SOC_DAPM_MIC("Ext Mic 3", NULL),
  32. };
  33. /* ttc machine audio map */
  34. static const struct snd_soc_dapm_route ttc_audio_map[] = {
  35. {"Headset Stereophone", NULL, "HS1"},
  36. {"Headset Stereophone", NULL, "HS2"},
  37. {"Ext Speaker", NULL, "LSP"},
  38. {"Ext Speaker", NULL, "LSN"},
  39. {"Lineout Out 1", NULL, "LINEOUT1"},
  40. {"Lineout Out 2", NULL, "LINEOUT2"},
  41. {"MIC1P", NULL, "Mic1 Bias"},
  42. {"MIC1N", NULL, "Mic1 Bias"},
  43. {"Mic1 Bias", NULL, "Ext Mic 1"},
  44. {"MIC2P", NULL, "Mic1 Bias"},
  45. {"MIC2N", NULL, "Mic1 Bias"},
  46. {"Mic1 Bias", NULL, "Headset Mic 2"},
  47. {"MIC3P", NULL, "Mic3 Bias"},
  48. {"MIC3N", NULL, "Mic3 Bias"},
  49. {"Mic3 Bias", NULL, "Ext Mic 3"},
  50. };
  51. static int ttc_pm860x_init(struct snd_soc_pcm_runtime *rtd)
  52. {
  53. struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
  54. /* Headset jack detection */
  55. snd_soc_card_jack_new_pins(rtd->card, "Headphone Jack",
  56. SND_JACK_HEADPHONE | SND_JACK_BTN_0 |
  57. SND_JACK_BTN_1 | SND_JACK_BTN_2,
  58. &hs_jack,
  59. hs_jack_pins, ARRAY_SIZE(hs_jack_pins));
  60. snd_soc_card_jack_new_pins(rtd->card, "Microphone Jack",
  61. SND_JACK_MICROPHONE, &mic_jack,
  62. mic_jack_pins, ARRAY_SIZE(mic_jack_pins));
  63. /* headphone, microphone detection & headset short detection */
  64. pm860x_hs_jack_detect(component, &hs_jack, SND_JACK_HEADPHONE,
  65. SND_JACK_BTN_0, SND_JACK_BTN_1, SND_JACK_BTN_2);
  66. pm860x_mic_jack_detect(component, &hs_jack, SND_JACK_MICROPHONE);
  67. return 0;
  68. }
  69. /* ttc/td-dkb digital audio interface glue - connects codec <--> CPU */
  70. SND_SOC_DAILINK_DEFS(i2s,
  71. DAILINK_COMP_ARRAY(COMP_CPU("pxa-ssp-dai.1")),
  72. DAILINK_COMP_ARRAY(COMP_CODEC("88pm860x-codec", "88pm860x-i2s")),
  73. DAILINK_COMP_ARRAY(COMP_PLATFORM("mmp-pcm-audio")));
  74. static struct snd_soc_dai_link ttc_pm860x_hifi_dai[] = {
  75. {
  76. .name = "88pm860x i2s",
  77. .stream_name = "audio playback",
  78. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  79. SND_SOC_DAIFMT_CBM_CFM,
  80. .init = ttc_pm860x_init,
  81. SND_SOC_DAILINK_REG(i2s),
  82. },
  83. };
  84. /* ttc/td audio machine driver */
  85. static struct snd_soc_card ttc_dkb_card = {
  86. .name = "ttc-dkb-hifi",
  87. .owner = THIS_MODULE,
  88. .dai_link = ttc_pm860x_hifi_dai,
  89. .num_links = ARRAY_SIZE(ttc_pm860x_hifi_dai),
  90. .dapm_widgets = ttc_dapm_widgets,
  91. .num_dapm_widgets = ARRAY_SIZE(ttc_dapm_widgets),
  92. .dapm_routes = ttc_audio_map,
  93. .num_dapm_routes = ARRAY_SIZE(ttc_audio_map),
  94. };
  95. static int ttc_dkb_probe(struct platform_device *pdev)
  96. {
  97. struct snd_soc_card *card = &ttc_dkb_card;
  98. int ret;
  99. card->dev = &pdev->dev;
  100. ret = devm_snd_soc_register_card(&pdev->dev, card);
  101. if (ret)
  102. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  103. ret);
  104. return ret;
  105. }
  106. static struct platform_driver ttc_dkb_driver = {
  107. .driver = {
  108. .name = "ttc-dkb-audio",
  109. .pm = &snd_soc_pm_ops,
  110. },
  111. .probe = ttc_dkb_probe,
  112. };
  113. module_platform_driver(ttc_dkb_driver);
  114. /* Module information */
  115. MODULE_AUTHOR("Qiao Zhou, <[email protected]>");
  116. MODULE_DESCRIPTION("ALSA SoC TTC DKB");
  117. MODULE_LICENSE("GPL");
  118. MODULE_ALIAS("platform:ttc-dkb-audio");