byt-max98090.c 5.0 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",
  64. .report = SND_JACK_HEADPHONE | SND_JACK_LINEOUT,
  65. .debounce_time = 200,
  66. },
  67. {
  68. .name = "mic",
  69. .invert = 1,
  70. .report = SND_JACK_MICROPHONE,
  71. .debounce_time = 200,
  72. },
  73. };
  74. static const struct acpi_gpio_params hp_gpios = { 0, 0, false };
  75. static const struct acpi_gpio_params mic_gpios = { 1, 0, false };
  76. static const struct acpi_gpio_mapping acpi_byt_max98090_gpios[] = {
  77. { "hp-gpios", &hp_gpios, 1 },
  78. { "mic-gpios", &mic_gpios, 1 },
  79. {},
  80. };
  81. static int byt_max98090_init(struct snd_soc_pcm_runtime *runtime)
  82. {
  83. int ret;
  84. struct snd_soc_card *card = runtime->card;
  85. struct byt_max98090_private *drv = snd_soc_card_get_drvdata(card);
  86. struct snd_soc_jack *jack = &drv->jack;
  87. card->dapm.idle_bias_off = true;
  88. ret = snd_soc_dai_set_sysclk(runtime->codec_dai,
  89. M98090_REG_SYSTEM_CLOCK,
  90. 25000000, SND_SOC_CLOCK_IN);
  91. if (ret < 0) {
  92. dev_err(card->dev, "Can't set codec clock %d\n", ret);
  93. return ret;
  94. }
  95. /* Enable jack detection */
  96. ret = snd_soc_card_jack_new(runtime->card, "Headset",
  97. SND_JACK_LINEOUT | SND_JACK_HEADSET, jack,
  98. hs_jack_pins, ARRAY_SIZE(hs_jack_pins));
  99. if (ret)
  100. return ret;
  101. return snd_soc_jack_add_gpiods(card->dev->parent, jack,
  102. ARRAY_SIZE(hs_jack_gpios),
  103. hs_jack_gpios);
  104. }
  105. static struct snd_soc_dai_link byt_max98090_dais[] = {
  106. {
  107. .name = "Baytrail Audio",
  108. .stream_name = "Audio",
  109. .cpu_dai_name = "baytrail-pcm-audio",
  110. .codec_dai_name = "HiFi",
  111. .codec_name = "i2c-193C9890:00",
  112. .platform_name = "baytrail-pcm-audio",
  113. .init = byt_max98090_init,
  114. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  115. SND_SOC_DAIFMT_CBS_CFS,
  116. },
  117. };
  118. static struct snd_soc_card byt_max98090_card = {
  119. .name = "byt-max98090",
  120. .owner = THIS_MODULE,
  121. .dai_link = byt_max98090_dais,
  122. .num_links = ARRAY_SIZE(byt_max98090_dais),
  123. .dapm_widgets = byt_max98090_widgets,
  124. .num_dapm_widgets = ARRAY_SIZE(byt_max98090_widgets),
  125. .dapm_routes = byt_max98090_audio_map,
  126. .num_dapm_routes = ARRAY_SIZE(byt_max98090_audio_map),
  127. .controls = byt_max98090_controls,
  128. .num_controls = ARRAY_SIZE(byt_max98090_controls),
  129. .fully_routed = true,
  130. };
  131. static int byt_max98090_probe(struct platform_device *pdev)
  132. {
  133. struct device *dev = &pdev->dev;
  134. struct byt_max98090_private *priv;
  135. int ret_val;
  136. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  137. if (!priv) {
  138. dev_err(&pdev->dev, "allocation failed\n");
  139. return -ENOMEM;
  140. }
  141. ret_val = devm_acpi_dev_add_driver_gpios(dev->parent, acpi_byt_max98090_gpios);
  142. if (ret_val)
  143. dev_dbg(dev, "Unable to add GPIO mapping table\n");
  144. byt_max98090_card.dev = &pdev->dev;
  145. snd_soc_card_set_drvdata(&byt_max98090_card, priv);
  146. ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_max98090_card);
  147. if (ret_val) {
  148. dev_err(&pdev->dev,
  149. "snd_soc_register_card failed %d\n", ret_val);
  150. return ret_val;
  151. }
  152. return 0;
  153. }
  154. static struct platform_driver byt_max98090_driver = {
  155. .probe = byt_max98090_probe,
  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");