0033-ASoC-Add-support-for-HifiBerry-DAC.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. From 77afe84c37210adb241e9b48f1a415f49f183a68 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 033/114] 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 | 5 +++
  12. sound/soc/bcm/hifiberry_dac.c | 100 ++++++++++++++++++++++++++++++++++++++++++
  13. 3 files changed, 112 insertions(+)
  14. create mode 100644 sound/soc/bcm/hifiberry_dac.c
  15. --- a/sound/soc/bcm/Kconfig
  16. +++ b/sound/soc/bcm/Kconfig
  17. @@ -18,3 +18,10 @@ config SND_BCM2708_SOC_I2S
  18. Say Y or M if you want to add support for codecs attached to
  19. the BCM2708 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
  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. @@ -7,3 +7,8 @@ obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd
  31. snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
  32. obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
  33. +
  34. +# BCM2708 Machine Support
  35. +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  36. +
  37. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  38. --- /dev/null
  39. +++ b/sound/soc/bcm/hifiberry_dac.c
  40. @@ -0,0 +1,100 @@
  41. +/*
  42. + * ASoC Driver for HifiBerry DAC
  43. + *
  44. + * Author: Florian Meier <florian.meier@koalo.de>
  45. + * Copyright 2013
  46. + *
  47. + * This program is free software; you can redistribute it and/or
  48. + * modify it under the terms of the GNU General Public License
  49. + * version 2 as published by the Free Software Foundation.
  50. + *
  51. + * This program is distributed in the hope that it will be useful, but
  52. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  53. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  54. + * General Public License for more details.
  55. + */
  56. +
  57. +#include <linux/module.h>
  58. +#include <linux/platform_device.h>
  59. +
  60. +#include <sound/core.h>
  61. +#include <sound/pcm.h>
  62. +#include <sound/pcm_params.h>
  63. +#include <sound/soc.h>
  64. +#include <sound/jack.h>
  65. +
  66. +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  67. +{
  68. + return 0;
  69. +}
  70. +
  71. +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
  72. + struct snd_pcm_hw_params *params)
  73. +{
  74. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  75. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  76. +
  77. + unsigned int sample_bits =
  78. + snd_pcm_format_physical_width(params_format(params));
  79. +
  80. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  81. +}
  82. +
  83. +/* machine stream operations */
  84. +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
  85. + .hw_params = snd_rpi_hifiberry_dac_hw_params,
  86. +};
  87. +
  88. +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
  89. +{
  90. + .name = "HifiBerry DAC",
  91. + .stream_name = "HifiBerry DAC HiFi",
  92. + .cpu_dai_name = "bcm2708-i2s.0",
  93. + .codec_dai_name = "pcm5102a-hifi",
  94. + .platform_name = "bcm2708-i2s.0",
  95. + .codec_name = "pcm5102a-codec",
  96. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  97. + SND_SOC_DAIFMT_CBS_CFS,
  98. + .ops = &snd_rpi_hifiberry_dac_ops,
  99. + .init = snd_rpi_hifiberry_dac_init,
  100. +},
  101. +};
  102. +
  103. +/* audio machine driver */
  104. +static struct snd_soc_card snd_rpi_hifiberry_dac = {
  105. + .name = "snd_rpi_hifiberry_dac",
  106. + .dai_link = snd_rpi_hifiberry_dac_dai,
  107. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
  108. +};
  109. +
  110. +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
  111. +{
  112. + int ret = 0;
  113. +
  114. + snd_rpi_hifiberry_dac.dev = &pdev->dev;
  115. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
  116. + if (ret)
  117. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  118. +
  119. + return ret;
  120. +}
  121. +
  122. +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
  123. +{
  124. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
  125. +}
  126. +
  127. +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
  128. + .driver = {
  129. + .name = "snd-hifiberry-dac",
  130. + .owner = THIS_MODULE,
  131. + },
  132. + .probe = snd_rpi_hifiberry_dac_probe,
  133. + .remove = snd_rpi_hifiberry_dac_remove,
  134. +};
  135. +
  136. +module_platform_driver(snd_rpi_hifiberry_dac_driver);
  137. +
  138. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  139. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
  140. +MODULE_LICENSE("GPL v2");