tavorevb3.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * tavorevb3.c -- SoC audio for Tavor EVB3
  3. *
  4. * Copyright (C) 2010 Marvell International Ltd.
  5. * Haojian Zhuang <haojian.zhuang@marvell.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/device.h>
  14. #include <linux/clk.h>
  15. #include <linux/i2c.h>
  16. #include <sound/core.h>
  17. #include <sound/pcm.h>
  18. #include <sound/pcm_params.h>
  19. #include <sound/soc.h>
  20. #include <sound/jack.h>
  21. #include <asm/mach-types.h>
  22. #include "../codecs/88pm860x-codec.h"
  23. #include "pxa-ssp.h"
  24. static int evb3_pm860x_init(struct snd_soc_pcm_runtime *rtd);
  25. static struct platform_device *evb3_snd_device;
  26. static struct snd_soc_jack hs_jack, mic_jack;
  27. static struct snd_soc_jack_pin hs_jack_pins[] = {
  28. { .pin = "Headset Stereophone", .mask = SND_JACK_HEADPHONE, },
  29. };
  30. static struct snd_soc_jack_pin mic_jack_pins[] = {
  31. { .pin = "Headset Mic 2", .mask = SND_JACK_MICROPHONE, },
  32. };
  33. /* tavorevb3 machine dapm widgets */
  34. static const struct snd_soc_dapm_widget evb3_dapm_widgets[] = {
  35. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  36. SND_SOC_DAPM_LINE("Lineout Out 1", NULL),
  37. SND_SOC_DAPM_LINE("Lineout Out 2", NULL),
  38. SND_SOC_DAPM_SPK("Ext Speaker", NULL),
  39. SND_SOC_DAPM_MIC("Ext Mic 1", NULL),
  40. SND_SOC_DAPM_MIC("Headset Mic 2", NULL),
  41. SND_SOC_DAPM_MIC("Ext Mic 3", NULL),
  42. };
  43. /* tavorevb3 machine audio map */
  44. static const struct snd_soc_dapm_route audio_map[] = {
  45. {"Headset Stereophone", NULL, "HS1"},
  46. {"Headset Stereophone", NULL, "HS2"},
  47. {"Ext Speaker", NULL, "LSP"},
  48. {"Ext Speaker", NULL, "LSN"},
  49. {"Lineout Out 1", NULL, "LINEOUT1"},
  50. {"Lineout Out 2", NULL, "LINEOUT2"},
  51. {"MIC1P", NULL, "Mic1 Bias"},
  52. {"MIC1N", NULL, "Mic1 Bias"},
  53. {"Mic1 Bias", NULL, "Ext Mic 1"},
  54. {"MIC2P", NULL, "Mic1 Bias"},
  55. {"MIC2N", NULL, "Mic1 Bias"},
  56. {"Mic1 Bias", NULL, "Headset Mic 2"},
  57. {"MIC3P", NULL, "Mic3 Bias"},
  58. {"MIC3N", NULL, "Mic3 Bias"},
  59. {"Mic3 Bias", NULL, "Ext Mic 3"},
  60. };
  61. static int evb3_i2s_hw_params(struct snd_pcm_substream *substream,
  62. struct snd_pcm_hw_params *params)
  63. {
  64. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  65. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  66. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  67. int width = snd_pcm_format_physical_width(params_format(params));
  68. int ret;
  69. ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_NET_PLL, 0,
  70. PM860X_CLK_DIR_OUT);
  71. if (ret < 0)
  72. return ret;
  73. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 0, PM860X_CLK_DIR_OUT);
  74. if (ret < 0)
  75. return ret;
  76. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  77. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
  78. if (ret < 0)
  79. return ret;
  80. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  81. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
  82. if (ret < 0)
  83. return ret;
  84. ret = snd_soc_dai_set_tdm_slot(cpu_dai, 3, 3, 2, width);
  85. return ret;
  86. }
  87. static struct snd_soc_ops evb3_i2s_ops = {
  88. .hw_params = evb3_i2s_hw_params,
  89. };
  90. static struct snd_soc_dai_link evb3_dai[] = {
  91. {
  92. .name = "88PM860x I2S",
  93. .stream_name = "I2S Audio",
  94. .cpu_dai_name = "pxa-ssp-dai.1",
  95. .codec_dai_name = "88pm860x-i2s",
  96. .platform_name = "pxa-pcm-audio",
  97. .codec_name = "88pm860x-codec",
  98. .init = evb3_pm860x_init,
  99. .ops = &evb3_i2s_ops,
  100. },
  101. };
  102. static struct snd_soc_card snd_soc_card_evb3 = {
  103. .name = "Tavor EVB3",
  104. .dai_link = evb3_dai,
  105. .num_links = ARRAY_SIZE(evb3_dai),
  106. };
  107. static int evb3_pm860x_init(struct snd_soc_pcm_runtime *rtd)
  108. {
  109. struct snd_soc_codec *codec = rtd->codec;
  110. struct snd_soc_dapm_context *dapm = &codec->dapm;
  111. int ret;
  112. snd_soc_dapm_new_controls(dapm, evb3_dapm_widgets,
  113. ARRAY_SIZE(evb3_dapm_widgets));
  114. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  115. /* connected pins */
  116. snd_soc_dapm_enable_pin(dapm, "Ext Speaker");
  117. snd_soc_dapm_enable_pin(dapm, "Ext Mic 1");
  118. snd_soc_dapm_enable_pin(dapm, "Ext Mic 3");
  119. snd_soc_dapm_disable_pin(dapm, "Headset Mic 2");
  120. snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
  121. ret = snd_soc_dapm_sync(dapm);
  122. if (ret)
  123. return ret;
  124. /* Headset jack detection */
  125. snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE
  126. | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2,
  127. &hs_jack);
  128. snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  129. hs_jack_pins);
  130. snd_soc_jack_new(codec, "Microphone Jack", SND_JACK_MICROPHONE,
  131. &mic_jack);
  132. snd_soc_jack_add_pins(&mic_jack, ARRAY_SIZE(mic_jack_pins),
  133. mic_jack_pins);
  134. /* headphone, microphone detection & headset short detection */
  135. pm860x_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADPHONE,
  136. SND_JACK_BTN_0, SND_JACK_BTN_1, SND_JACK_BTN_2);
  137. pm860x_mic_jack_detect(codec, &hs_jack, SND_JACK_MICROPHONE);
  138. return 0;
  139. }
  140. static int __init tavorevb3_init(void)
  141. {
  142. int ret;
  143. if (!machine_is_tavorevb3())
  144. return -ENODEV;
  145. evb3_snd_device = platform_device_alloc("soc-audio", -1);
  146. if (!evb3_snd_device)
  147. return -ENOMEM;
  148. platform_set_drvdata(evb3_snd_device, &snd_soc_card_evb3);
  149. ret = platform_device_add(evb3_snd_device);
  150. if (ret)
  151. platform_device_put(evb3_snd_device);
  152. return ret;
  153. }
  154. static void __exit tavorevb3_exit(void)
  155. {
  156. platform_device_unregister(evb3_snd_device);
  157. }
  158. module_init(tavorevb3_init);
  159. module_exit(tavorevb3_exit);
  160. MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
  161. MODULE_DESCRIPTION("ALSA SoC 88PM860x Tavor EVB3");
  162. MODULE_LICENSE("GPL");