0068-Add-IQaudIO-Sound-Card-support-for-Raspberry-Pi.patch 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. From f0fc1c656af73bbfc2984e0bb6b90b27bac1a532 Mon Sep 17 00:00:00 2001
  2. From: Gordon Garrity <gordon@iqaudio.com>
  3. Date: Sat, 8 Mar 2014 16:56:57 +0000
  4. Subject: [PATCH 068/381] Add IQaudIO Sound Card support for Raspberry Pi
  5. Set a limit of 0dB on Digital Volume Control
  6. The main volume control in the PCM512x DAC has a range up to
  7. +24dB. This is dangerously loud and can potentially cause massive
  8. clipping in the output stages. Therefore this sets a sensible
  9. limit of 0dB for this control.
  10. ---
  11. sound/soc/bcm/Kconfig | 7 +++
  12. sound/soc/bcm/Makefile | 2 +
  13. sound/soc/bcm/iqaudio-dac.c | 132 ++++++++++++++++++++++++++++++++++++++++++++
  14. 3 files changed, 141 insertions(+)
  15. create mode 100644 sound/soc/bcm/iqaudio-dac.c
  16. --- a/sound/soc/bcm/Kconfig
  17. +++ b/sound/soc/bcm/Kconfig
  18. @@ -28,3 +28,10 @@ config SND_BCM2708_SOC_RPI_DAC
  19. select SND_SOC_PCM1794A
  20. help
  21. Say Y or M if you want to add support for RPi-DAC.
  22. +
  23. +config SND_BCM2708_SOC_IQAUDIO_DAC
  24. + tristate "Support for IQaudIO-DAC"
  25. + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  26. + select SND_SOC_PCM512x_I2C
  27. + help
  28. + Say Y or M if you want to add support for IQaudIO-DAC.
  29. --- a/sound/soc/bcm/Makefile
  30. +++ b/sound/soc/bcm/Makefile
  31. @@ -7,7 +7,9 @@ obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd
  32. snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  33. snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  34. snd-soc-rpi-dac-objs := rpi-dac.o
  35. +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  36. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  37. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  38. obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  39. +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  40. --- /dev/null
  41. +++ b/sound/soc/bcm/iqaudio-dac.c
  42. @@ -0,0 +1,132 @@
  43. +/*
  44. + * ASoC Driver for IQaudIO DAC
  45. + *
  46. + * Author: Florian Meier <florian.meier@koalo.de>
  47. + * Copyright 2013
  48. + *
  49. + * This program is free software; you can redistribute it and/or
  50. + * modify it under the terms of the GNU General Public License
  51. + * version 2 as published by the Free Software Foundation.
  52. + *
  53. + * This program is distributed in the hope that it will be useful, but
  54. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  55. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  56. + * General Public License for more details.
  57. + */
  58. +
  59. +#include <linux/module.h>
  60. +#include <linux/platform_device.h>
  61. +
  62. +#include <sound/core.h>
  63. +#include <sound/pcm.h>
  64. +#include <sound/pcm_params.h>
  65. +#include <sound/soc.h>
  66. +#include <sound/jack.h>
  67. +
  68. +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
  69. +{
  70. + int ret;
  71. + struct snd_soc_card *card = rtd->card;
  72. +
  73. + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
  74. + if (ret < 0)
  75. + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
  76. +
  77. + return 0;
  78. +}
  79. +
  80. +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream,
  81. + struct snd_pcm_hw_params *params)
  82. +{
  83. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  84. +// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai;
  85. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  86. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  87. +
  88. + unsigned int sample_bits =
  89. + snd_pcm_format_physical_width(params_format(params));
  90. +
  91. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  92. +}
  93. +
  94. +/* machine stream operations */
  95. +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = {
  96. + .hw_params = snd_rpi_iqaudio_dac_hw_params,
  97. +};
  98. +
  99. +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
  100. +{
  101. + .name = "IQaudIO DAC",
  102. + .stream_name = "IQaudIO DAC HiFi",
  103. + .cpu_dai_name = "bcm2708-i2s.0",
  104. + .codec_dai_name = "pcm512x-hifi",
  105. + .platform_name = "bcm2708-i2s.0",
  106. + .codec_name = "pcm512x.1-004c",
  107. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  108. + SND_SOC_DAIFMT_CBS_CFS,
  109. + .ops = &snd_rpi_iqaudio_dac_ops,
  110. + .init = snd_rpi_iqaudio_dac_init,
  111. +},
  112. +};
  113. +
  114. +/* audio machine driver */
  115. +static struct snd_soc_card snd_rpi_iqaudio_dac = {
  116. + .name = "IQaudIODAC",
  117. + .dai_link = snd_rpi_iqaudio_dac_dai,
  118. + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
  119. +};
  120. +
  121. +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
  122. +{
  123. + int ret = 0;
  124. +
  125. + snd_rpi_iqaudio_dac.dev = &pdev->dev;
  126. +
  127. + if (pdev->dev.of_node) {
  128. + struct device_node *i2s_node;
  129. + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_dac_dai[0];
  130. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  131. + "i2s-controller", 0);
  132. +
  133. + if (i2s_node) {
  134. + dai->cpu_dai_name = NULL;
  135. + dai->cpu_of_node = i2s_node;
  136. + dai->platform_name = NULL;
  137. + dai->platform_of_node = i2s_node;
  138. + }
  139. + }
  140. +
  141. + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
  142. + if (ret)
  143. + dev_err(&pdev->dev,
  144. + "snd_soc_register_card() failed: %d\n", ret);
  145. +
  146. + return ret;
  147. +}
  148. +
  149. +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
  150. +{
  151. + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
  152. +}
  153. +
  154. +static const struct of_device_id iqaudio_of_match[] = {
  155. + { .compatible = "iqaudio,iqaudio-dac", },
  156. + {},
  157. +};
  158. +MODULE_DEVICE_TABLE(of, iqaudio_of_match);
  159. +
  160. +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
  161. + .driver = {
  162. + .name = "snd-rpi-iqaudio-dac",
  163. + .owner = THIS_MODULE,
  164. + .of_match_table = iqaudio_of_match,
  165. + },
  166. + .probe = snd_rpi_iqaudio_dac_probe,
  167. + .remove = snd_rpi_iqaudio_dac_remove,
  168. +};
  169. +
  170. +module_platform_driver(snd_rpi_iqaudio_dac_driver);
  171. +
  172. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  173. +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
  174. +MODULE_LICENSE("GPL v2");