saarb.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * saarb.c -- SoC audio for saarb
  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 saarb_pm860x_init(struct snd_soc_pcm_runtime *rtd);
  25. static struct platform_device *saarb_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. /* saarb machine dapm widgets */
  34. static const struct snd_soc_dapm_widget saarb_dapm_widgets[] = {
  35. SND_SOC_DAPM_HP("Headphone 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", NULL),
  41. SND_SOC_DAPM_MIC("Ext Mic 3", NULL),
  42. };
  43. /* saarb machine audio map */
  44. static const struct snd_soc_dapm_route saarb_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 saarb_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_tdm_slot(cpu_dai, 3, 3, 2, width);
  77. return ret;
  78. }
  79. static struct snd_soc_ops saarb_i2s_ops = {
  80. .hw_params = saarb_i2s_hw_params,
  81. };
  82. static struct snd_soc_dai_link saarb_dai[] = {
  83. {
  84. .name = "88PM860x I2S",
  85. .stream_name = "I2S Audio",
  86. .cpu_dai_name = "pxa-ssp-dai.1",
  87. .codec_dai_name = "88pm860x-i2s",
  88. .platform_name = "pxa-pcm-audio",
  89. .codec_name = "88pm860x-codec",
  90. .init = saarb_pm860x_init,
  91. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  92. SND_SOC_DAIFMT_CBM_CFM,
  93. .ops = &saarb_i2s_ops,
  94. },
  95. };
  96. static struct snd_soc_card snd_soc_card_saarb = {
  97. .name = "Saarb",
  98. .owner = THIS_MODULE,
  99. .dai_link = saarb_dai,
  100. .num_links = ARRAY_SIZE(saarb_dai),
  101. .dapm_widgets = saarb_dapm_widgets,
  102. .num_dapm_widgets = ARRAY_SIZE(saarb_dapm_widgets),
  103. .dapm_routes = saarb_audio_map,
  104. .num_dapm_routes = ARRAY_SIZE(saarb_audio_map),
  105. };
  106. static int saarb_pm860x_init(struct snd_soc_pcm_runtime *rtd)
  107. {
  108. struct snd_soc_codec *codec = rtd->codec;
  109. struct snd_soc_dapm_context *dapm = &codec->dapm;
  110. /* connected pins */
  111. snd_soc_dapm_enable_pin(dapm, "Ext Speaker");
  112. snd_soc_dapm_enable_pin(dapm, "Ext Mic 1");
  113. snd_soc_dapm_enable_pin(dapm, "Ext Mic 3");
  114. snd_soc_dapm_disable_pin(dapm, "Headset Mic 2");
  115. snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
  116. /* Headset jack detection */
  117. snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE
  118. | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2,
  119. &hs_jack);
  120. snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  121. hs_jack_pins);
  122. snd_soc_jack_new(codec, "Microphone Jack", SND_JACK_MICROPHONE,
  123. &mic_jack);
  124. snd_soc_jack_add_pins(&mic_jack, ARRAY_SIZE(mic_jack_pins),
  125. mic_jack_pins);
  126. /* headphone, microphone detection & headset short detection */
  127. pm860x_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADPHONE,
  128. SND_JACK_BTN_0, SND_JACK_BTN_1, SND_JACK_BTN_2);
  129. pm860x_mic_jack_detect(codec, &hs_jack, SND_JACK_MICROPHONE);
  130. return 0;
  131. }
  132. static int __init saarb_init(void)
  133. {
  134. int ret;
  135. if (!machine_is_saarb())
  136. return -ENODEV;
  137. saarb_snd_device = platform_device_alloc("soc-audio", -1);
  138. if (!saarb_snd_device)
  139. return -ENOMEM;
  140. platform_set_drvdata(saarb_snd_device, &snd_soc_card_saarb);
  141. ret = platform_device_add(saarb_snd_device);
  142. if (ret)
  143. platform_device_put(saarb_snd_device);
  144. return ret;
  145. }
  146. static void __exit saarb_exit(void)
  147. {
  148. platform_device_unregister(saarb_snd_device);
  149. }
  150. module_init(saarb_init);
  151. module_exit(saarb_exit);
  152. MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
  153. MODULE_DESCRIPTION("ALSA SoC 88PM860x Saarb");
  154. MODULE_LICENSE("GPL");