byt-max98090.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Intel Baytrail SST MAX98090 machine driver
  3. * Copyright (c) 2014, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/acpi.h>
  18. #include <linux/device.h>
  19. #include <linux/gpio.h>
  20. #include <linux/gpio/consumer.h>
  21. #include <linux/slab.h>
  22. #include <sound/pcm.h>
  23. #include <sound/pcm_params.h>
  24. #include <sound/soc.h>
  25. #include <sound/jack.h>
  26. #include "../codecs/max98090.h"
  27. struct byt_max98090_private {
  28. struct snd_soc_jack jack;
  29. };
  30. static const struct snd_soc_dapm_widget byt_max98090_widgets[] = {
  31. SND_SOC_DAPM_HP("Headphone", NULL),
  32. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  33. SND_SOC_DAPM_MIC("Int Mic", NULL),
  34. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  35. };
  36. static const struct snd_soc_dapm_route byt_max98090_audio_map[] = {
  37. {"IN34", NULL, "Headset Mic"},
  38. {"Headset Mic", NULL, "MICBIAS"},
  39. {"DMICL", NULL, "Int Mic"},
  40. {"Headphone", NULL, "HPL"},
  41. {"Headphone", NULL, "HPR"},
  42. {"Ext Spk", NULL, "SPKL"},
  43. {"Ext Spk", NULL, "SPKR"},
  44. };
  45. static const struct snd_kcontrol_new byt_max98090_controls[] = {
  46. SOC_DAPM_PIN_SWITCH("Headphone"),
  47. SOC_DAPM_PIN_SWITCH("Headset Mic"),
  48. SOC_DAPM_PIN_SWITCH("Int Mic"),
  49. SOC_DAPM_PIN_SWITCH("Ext Spk"),
  50. };
  51. static struct snd_soc_jack_pin hs_jack_pins[] = {
  52. {
  53. .pin = "Headphone",
  54. .mask = SND_JACK_HEADPHONE,
  55. },
  56. {
  57. .pin = "Headset Mic",
  58. .mask = SND_JACK_MICROPHONE,
  59. },
  60. };
  61. static struct snd_soc_jack_gpio hs_jack_gpios[] = {
  62. {
  63. .name = "hp-gpio",
  64. .idx = 0,
  65. .report = SND_JACK_HEADPHONE | SND_JACK_LINEOUT,
  66. .debounce_time = 200,
  67. },
  68. {
  69. .name = "mic-gpio",
  70. .idx = 1,
  71. .invert = 1,
  72. .report = SND_JACK_MICROPHONE,
  73. .debounce_time = 200,
  74. },
  75. };
  76. static int byt_max98090_init(struct snd_soc_pcm_runtime *runtime)
  77. {
  78. int ret;
  79. struct snd_soc_codec *codec = runtime->codec;
  80. struct snd_soc_card *card = runtime->card;
  81. struct byt_max98090_private *drv = snd_soc_card_get_drvdata(card);
  82. struct snd_soc_jack *jack = &drv->jack;
  83. card->dapm.idle_bias_off = true;
  84. ret = snd_soc_dai_set_sysclk(runtime->codec_dai,
  85. M98090_REG_SYSTEM_CLOCK,
  86. 25000000, SND_SOC_CLOCK_IN);
  87. if (ret < 0) {
  88. dev_err(card->dev, "Can't set codec clock %d\n", ret);
  89. return ret;
  90. }
  91. /* Enable jack detection */
  92. ret = snd_soc_jack_new(codec, "Headset",
  93. SND_JACK_LINEOUT | SND_JACK_HEADSET, jack);
  94. if (ret)
  95. return ret;
  96. ret = snd_soc_jack_add_pins(jack, ARRAY_SIZE(hs_jack_pins),
  97. hs_jack_pins);
  98. if (ret)
  99. return ret;
  100. return snd_soc_jack_add_gpiods(card->dev->parent, jack,
  101. ARRAY_SIZE(hs_jack_gpios),
  102. hs_jack_gpios);
  103. }
  104. static struct snd_soc_dai_link byt_max98090_dais[] = {
  105. {
  106. .name = "Baytrail Audio",
  107. .stream_name = "Audio",
  108. .cpu_dai_name = "baytrail-pcm-audio",
  109. .codec_dai_name = "HiFi",
  110. .codec_name = "i2c-193C9890:00",
  111. .platform_name = "baytrail-pcm-audio",
  112. .init = byt_max98090_init,
  113. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  114. SND_SOC_DAIFMT_CBS_CFS,
  115. },
  116. };
  117. static struct snd_soc_card byt_max98090_card = {
  118. .name = "byt-max98090",
  119. .dai_link = byt_max98090_dais,
  120. .num_links = ARRAY_SIZE(byt_max98090_dais),
  121. .dapm_widgets = byt_max98090_widgets,
  122. .num_dapm_widgets = ARRAY_SIZE(byt_max98090_widgets),
  123. .dapm_routes = byt_max98090_audio_map,
  124. .num_dapm_routes = ARRAY_SIZE(byt_max98090_audio_map),
  125. .controls = byt_max98090_controls,
  126. .num_controls = ARRAY_SIZE(byt_max98090_controls),
  127. .fully_routed = true,
  128. };
  129. static int byt_max98090_probe(struct platform_device *pdev)
  130. {
  131. int ret_val = 0;
  132. struct byt_max98090_private *priv;
  133. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_ATOMIC);
  134. if (!priv) {
  135. dev_err(&pdev->dev, "allocation failed\n");
  136. return -ENOMEM;
  137. }
  138. byt_max98090_card.dev = &pdev->dev;
  139. snd_soc_card_set_drvdata(&byt_max98090_card, priv);
  140. ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_max98090_card);
  141. if (ret_val) {
  142. dev_err(&pdev->dev,
  143. "snd_soc_register_card failed %d\n", ret_val);
  144. return ret_val;
  145. }
  146. return ret_val;
  147. }
  148. static int byt_max98090_remove(struct platform_device *pdev)
  149. {
  150. struct snd_soc_card *card = platform_get_drvdata(pdev);
  151. struct byt_max98090_private *priv = snd_soc_card_get_drvdata(card);
  152. snd_soc_jack_free_gpios(&priv->jack, ARRAY_SIZE(hs_jack_gpios),
  153. hs_jack_gpios);
  154. return 0;
  155. }
  156. static struct platform_driver byt_max98090_driver = {
  157. .probe = byt_max98090_probe,
  158. .remove = byt_max98090_remove,
  159. .driver = {
  160. .name = "byt-max98090",
  161. .owner = THIS_MODULE,
  162. .pm = &snd_soc_pm_ops,
  163. },
  164. };
  165. module_platform_driver(byt_max98090_driver)
  166. MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver");
  167. MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula");
  168. MODULE_LICENSE("GPL v2");
  169. MODULE_ALIAS("platform:byt-max98090");