0063-ASoC-Add-support-for-HifiBerry-DAC.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. From 9cf0b8eed930ac26384249e193c1c91044a460e1 Mon Sep 17 00:00:00 2001
  2. From: Florian Meier <florian.meier@koalo.de>
  3. Date: Fri, 22 Nov 2013 19:19:08 +0100
  4. Subject: [PATCH] ASoC: Add support for HifiBerry DAC
  5. This adds a machine driver for the HifiBerry DAC.
  6. It is a sound card that can
  7. be stacked onto the Raspberry Pi.
  8. Signed-off-by: Florian Meier <florian.meier@koalo.de>
  9. ---
  10. sound/soc/bcm/Kconfig | 7 +++
  11. sound/soc/bcm/Makefile | 4 ++
  12. sound/soc/bcm/hifiberry_dac.c | 122 ++++++++++++++++++++++++++++++++++++++++++
  13. 3 files changed, 133 insertions(+)
  14. create mode 100644 sound/soc/bcm/hifiberry_dac.c
  15. --- a/sound/soc/bcm/Kconfig
  16. +++ b/sound/soc/bcm/Kconfig
  17. @@ -7,3 +7,10 @@ config SND_BCM2835_SOC_I2S
  18. Say Y or M if you want to add support for codecs attached to
  19. the BCM2835 I2S interface. You will also need
  20. to select the audio interfaces to support below.
  21. +
  22. +config SND_BCM2708_SOC_HIFIBERRY_DAC
  23. + tristate "Support for HifiBerry DAC"
  24. + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  25. + select SND_SOC_PCM5102A
  26. + help
  27. + Say Y or M if you want to add support for HifiBerry DAC.
  28. --- a/sound/soc/bcm/Makefile
  29. +++ b/sound/soc/bcm/Makefile
  30. @@ -3,3 +3,7 @@ snd-soc-bcm2835-i2s-objs := bcm2835-i2s.
  31. obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd-soc-bcm2835-i2s.o
  32. +# BCM2708 Machine Support
  33. +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  34. +
  35. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  36. --- /dev/null
  37. +++ b/sound/soc/bcm/hifiberry_dac.c
  38. @@ -0,0 +1,122 @@
  39. +/*
  40. + * ASoC Driver for HifiBerry DAC
  41. + *
  42. + * Author: Florian Meier <florian.meier@koalo.de>
  43. + * Copyright 2013
  44. + *
  45. + * This program is free software; you can redistribute it and/or
  46. + * modify it under the terms of the GNU General Public License
  47. + * version 2 as published by the Free Software Foundation.
  48. + *
  49. + * This program is distributed in the hope that it will be useful, but
  50. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  51. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  52. + * General Public License for more details.
  53. + */
  54. +
  55. +#include <linux/module.h>
  56. +#include <linux/platform_device.h>
  57. +
  58. +#include <sound/core.h>
  59. +#include <sound/pcm.h>
  60. +#include <sound/pcm_params.h>
  61. +#include <sound/soc.h>
  62. +#include <sound/jack.h>
  63. +
  64. +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  65. +{
  66. + return 0;
  67. +}
  68. +
  69. +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
  70. + struct snd_pcm_hw_params *params)
  71. +{
  72. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  73. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  74. +
  75. + unsigned int sample_bits =
  76. + snd_pcm_format_physical_width(params_format(params));
  77. +
  78. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  79. +}
  80. +
  81. +/* machine stream operations */
  82. +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
  83. + .hw_params = snd_rpi_hifiberry_dac_hw_params,
  84. +};
  85. +
  86. +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
  87. +{
  88. + .name = "HifiBerry DAC",
  89. + .stream_name = "HifiBerry DAC HiFi",
  90. + .cpu_dai_name = "bcm2708-i2s.0",
  91. + .codec_dai_name = "pcm5102a-hifi",
  92. + .platform_name = "bcm2708-i2s.0",
  93. + .codec_name = "pcm5102a-codec",
  94. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  95. + SND_SOC_DAIFMT_CBS_CFS,
  96. + .ops = &snd_rpi_hifiberry_dac_ops,
  97. + .init = snd_rpi_hifiberry_dac_init,
  98. +},
  99. +};
  100. +
  101. +/* audio machine driver */
  102. +static struct snd_soc_card snd_rpi_hifiberry_dac = {
  103. + .name = "snd_rpi_hifiberry_dac",
  104. + .dai_link = snd_rpi_hifiberry_dac_dai,
  105. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
  106. +};
  107. +
  108. +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
  109. +{
  110. + int ret = 0;
  111. +
  112. + snd_rpi_hifiberry_dac.dev = &pdev->dev;
  113. +
  114. + if (pdev->dev.of_node) {
  115. + struct device_node *i2s_node;
  116. + struct snd_soc_dai_link *dai = &snd_rpi_hifiberry_dac_dai[0];
  117. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  118. + "i2s-controller", 0);
  119. +
  120. + if (i2s_node) {
  121. + dai->cpu_dai_name = NULL;
  122. + dai->cpu_of_node = i2s_node;
  123. + dai->platform_name = NULL;
  124. + dai->platform_of_node = i2s_node;
  125. + }
  126. + }
  127. +
  128. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
  129. + if (ret)
  130. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  131. +
  132. + return ret;
  133. +}
  134. +
  135. +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
  136. +{
  137. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
  138. +}
  139. +
  140. +static const struct of_device_id snd_rpi_hifiberry_dac_of_match[] = {
  141. + { .compatible = "hifiberry,hifiberry-dac", },
  142. + {},
  143. +};
  144. +MODULE_DEVICE_TABLE(of, snd_rpi_hifiberry_dac_of_match);
  145. +
  146. +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
  147. + .driver = {
  148. + .name = "snd-hifiberry-dac",
  149. + .owner = THIS_MODULE,
  150. + .of_match_table = snd_rpi_hifiberry_dac_of_match,
  151. + },
  152. + .probe = snd_rpi_hifiberry_dac_probe,
  153. + .remove = snd_rpi_hifiberry_dac_remove,
  154. +};
  155. +
  156. +module_platform_driver(snd_rpi_hifiberry_dac_driver);
  157. +
  158. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  159. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
  160. +MODULE_LICENSE("GPL v2");