byt-max98090.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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_card *card = runtime->card;
  80. struct byt_max98090_private *drv = snd_soc_card_get_drvdata(card);
  81. struct snd_soc_jack *jack = &drv->jack;
  82. card->dapm.idle_bias_off = true;
  83. ret = snd_soc_dai_set_sysclk(runtime->codec_dai,
  84. M98090_REG_SYSTEM_CLOCK,
  85. 25000000, SND_SOC_CLOCK_IN);
  86. if (ret < 0) {
  87. dev_err(card->dev, "Can't set codec clock %d\n", ret);
  88. return ret;
  89. }
  90. /* Enable jack detection */
  91. ret = snd_soc_card_jack_new(runtime->card, "Headset",
  92. SND_JACK_LINEOUT | SND_JACK_HEADSET, jack,
  93. hs_jack_pins, ARRAY_SIZE(hs_jack_pins));
  94. if (ret)
  95. return ret;
  96. return snd_soc_jack_add_gpiods(card->dev->parent, jack,
  97. ARRAY_SIZE(hs_jack_gpios),
  98. hs_jack_gpios);
  99. }
  100. static struct snd_soc_dai_link byt_max98090_dais[] = {
  101. {
  102. .name = "Baytrail Audio",
  103. .stream_name = "Audio",
  104. .cpu_dai_name = "baytrail-pcm-audio",
  105. .codec_dai_name = "HiFi",
  106. .codec_name = "i2c-193C9890:00",
  107. .platform_name = "baytrail-pcm-audio",
  108. .init = byt_max98090_init,
  109. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  110. SND_SOC_DAIFMT_CBS_CFS,
  111. },
  112. };
  113. static struct snd_soc_card byt_max98090_card = {
  114. .name = "byt-max98090",
  115. .owner = THIS_MODULE,
  116. .dai_link = byt_max98090_dais,
  117. .num_links = ARRAY_SIZE(byt_max98090_dais),
  118. .dapm_widgets = byt_max98090_widgets,
  119. .num_dapm_widgets = ARRAY_SIZE(byt_max98090_widgets),
  120. .dapm_routes = byt_max98090_audio_map,
  121. .num_dapm_routes = ARRAY_SIZE(byt_max98090_audio_map),
  122. .controls = byt_max98090_controls,
  123. .num_controls = ARRAY_SIZE(byt_max98090_controls),
  124. .fully_routed = true,
  125. };
  126. static int byt_max98090_probe(struct platform_device *pdev)
  127. {
  128. int ret_val = 0;
  129. struct byt_max98090_private *priv;
  130. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_ATOMIC);
  131. if (!priv) {
  132. dev_err(&pdev->dev, "allocation failed\n");
  133. return -ENOMEM;
  134. }
  135. byt_max98090_card.dev = &pdev->dev;
  136. snd_soc_card_set_drvdata(&byt_max98090_card, priv);
  137. ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_max98090_card);
  138. if (ret_val) {
  139. dev_err(&pdev->dev,
  140. "snd_soc_register_card failed %d\n", ret_val);
  141. return ret_val;
  142. }
  143. return ret_val;
  144. }
  145. static int byt_max98090_remove(struct platform_device *pdev)
  146. {
  147. struct snd_soc_card *card = platform_get_drvdata(pdev);
  148. struct byt_max98090_private *priv = snd_soc_card_get_drvdata(card);
  149. snd_soc_jack_free_gpios(&priv->jack, ARRAY_SIZE(hs_jack_gpios),
  150. hs_jack_gpios);
  151. return 0;
  152. }
  153. static struct platform_driver byt_max98090_driver = {
  154. .probe = byt_max98090_probe,
  155. .remove = byt_max98090_remove,
  156. .driver = {
  157. .name = "byt-max98090",
  158. .pm = &snd_soc_pm_ops,
  159. },
  160. };
  161. module_platform_driver(byt_max98090_driver)
  162. MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver");
  163. MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula");
  164. MODULE_LICENSE("GPL v2");
  165. MODULE_ALIAS("platform:byt-max98090");