sirf-audio.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * SiRF audio card driver
  3. *
  4. * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
  5. *
  6. * Licensed under GPLv2 or later.
  7. */
  8. #include <linux/platform_device.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/gpio.h>
  12. #include <linux/of_gpio.h>
  13. #include <sound/core.h>
  14. #include <sound/pcm.h>
  15. #include <sound/soc.h>
  16. struct sirf_audio_card {
  17. unsigned int gpio_hp_pa;
  18. unsigned int gpio_spk_pa;
  19. };
  20. static int sirf_audio_hp_event(struct snd_soc_dapm_widget *w,
  21. struct snd_kcontrol *ctrl, int event)
  22. {
  23. struct snd_soc_dapm_context *dapm = w->dapm;
  24. struct snd_soc_card *card = dapm->card;
  25. struct sirf_audio_card *sirf_audio_card = snd_soc_card_get_drvdata(card);
  26. int on = !SND_SOC_DAPM_EVENT_OFF(event);
  27. if (gpio_is_valid(sirf_audio_card->gpio_hp_pa))
  28. gpio_set_value(sirf_audio_card->gpio_hp_pa, on);
  29. return 0;
  30. }
  31. static int sirf_audio_spk_event(struct snd_soc_dapm_widget *w,
  32. struct snd_kcontrol *ctrl, int event)
  33. {
  34. struct snd_soc_dapm_context *dapm = w->dapm;
  35. struct snd_soc_card *card = dapm->card;
  36. struct sirf_audio_card *sirf_audio_card = snd_soc_card_get_drvdata(card);
  37. int on = !SND_SOC_DAPM_EVENT_OFF(event);
  38. if (gpio_is_valid(sirf_audio_card->gpio_spk_pa))
  39. gpio_set_value(sirf_audio_card->gpio_spk_pa, on);
  40. return 0;
  41. }
  42. static const struct snd_soc_dapm_widget sirf_audio_dapm_widgets[] = {
  43. SND_SOC_DAPM_HP("Hp", sirf_audio_hp_event),
  44. SND_SOC_DAPM_SPK("Ext Spk", sirf_audio_spk_event),
  45. SND_SOC_DAPM_MIC("Ext Mic", NULL),
  46. };
  47. static const struct snd_soc_dapm_route intercon[] = {
  48. {"Hp", NULL, "HPOUTL"},
  49. {"Hp", NULL, "HPOUTR"},
  50. {"Ext Spk", NULL, "SPKOUT"},
  51. {"MICIN1", NULL, "Mic Bias"},
  52. {"Mic Bias", NULL, "Ext Mic"},
  53. };
  54. /* Digital audio interface glue - connects codec <--> CPU */
  55. static struct snd_soc_dai_link sirf_audio_dai_link[] = {
  56. {
  57. .name = "SiRF audio card",
  58. .stream_name = "SiRF audio HiFi",
  59. .codec_dai_name = "sirf-audio-codec",
  60. },
  61. };
  62. /* Audio machine driver */
  63. static struct snd_soc_card snd_soc_sirf_audio_card = {
  64. .name = "SiRF audio card",
  65. .owner = THIS_MODULE,
  66. .dai_link = sirf_audio_dai_link,
  67. .num_links = ARRAY_SIZE(sirf_audio_dai_link),
  68. .dapm_widgets = sirf_audio_dapm_widgets,
  69. .num_dapm_widgets = ARRAY_SIZE(sirf_audio_dapm_widgets),
  70. .dapm_routes = intercon,
  71. .num_dapm_routes = ARRAY_SIZE(intercon),
  72. };
  73. static int sirf_audio_probe(struct platform_device *pdev)
  74. {
  75. struct snd_soc_card *card = &snd_soc_sirf_audio_card;
  76. struct sirf_audio_card *sirf_audio_card;
  77. int ret;
  78. sirf_audio_card = devm_kzalloc(&pdev->dev, sizeof(struct sirf_audio_card),
  79. GFP_KERNEL);
  80. if (sirf_audio_card == NULL)
  81. return -ENOMEM;
  82. sirf_audio_dai_link[0].cpu_of_node =
  83. of_parse_phandle(pdev->dev.of_node, "sirf,audio-platform", 0);
  84. sirf_audio_dai_link[0].platform_of_node =
  85. of_parse_phandle(pdev->dev.of_node, "sirf,audio-platform", 0);
  86. sirf_audio_dai_link[0].codec_of_node =
  87. of_parse_phandle(pdev->dev.of_node, "sirf,audio-codec", 0);
  88. sirf_audio_card->gpio_spk_pa = of_get_named_gpio(pdev->dev.of_node,
  89. "spk-pa-gpios", 0);
  90. sirf_audio_card->gpio_hp_pa = of_get_named_gpio(pdev->dev.of_node,
  91. "hp-pa-gpios", 0);
  92. if (gpio_is_valid(sirf_audio_card->gpio_spk_pa)) {
  93. ret = devm_gpio_request_one(&pdev->dev,
  94. sirf_audio_card->gpio_spk_pa,
  95. GPIOF_OUT_INIT_LOW, "SPA_PA_SD");
  96. if (ret) {
  97. dev_err(&pdev->dev,
  98. "Failed to request GPIO_%d for reset: %d\n",
  99. sirf_audio_card->gpio_spk_pa, ret);
  100. return ret;
  101. }
  102. }
  103. if (gpio_is_valid(sirf_audio_card->gpio_hp_pa)) {
  104. ret = devm_gpio_request_one(&pdev->dev,
  105. sirf_audio_card->gpio_hp_pa,
  106. GPIOF_OUT_INIT_LOW, "HP_PA_SD");
  107. if (ret) {
  108. dev_err(&pdev->dev,
  109. "Failed to request GPIO_%d for reset: %d\n",
  110. sirf_audio_card->gpio_hp_pa, ret);
  111. return ret;
  112. }
  113. }
  114. card->dev = &pdev->dev;
  115. snd_soc_card_set_drvdata(card, sirf_audio_card);
  116. ret = devm_snd_soc_register_card(&pdev->dev, card);
  117. if (ret)
  118. dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
  119. return ret;
  120. }
  121. static const struct of_device_id sirf_audio_of_match[] = {
  122. {.compatible = "sirf,sirf-audio-card", },
  123. { },
  124. };
  125. MODULE_DEVICE_TABLE(of, sirf_audio_of_match);
  126. static struct platform_driver sirf_audio_driver = {
  127. .driver = {
  128. .name = "sirf-audio-card",
  129. .pm = &snd_soc_pm_ops,
  130. .of_match_table = sirf_audio_of_match,
  131. },
  132. .probe = sirf_audio_probe,
  133. };
  134. module_platform_driver(sirf_audio_driver);
  135. MODULE_AUTHOR("RongJun Ying <RongJun.Ying@csr.com>");
  136. MODULE_DESCRIPTION("ALSA SoC SIRF audio card driver");
  137. MODULE_LICENSE("GPL v2");