0038-ASoC-BCM-Add-support-for-HiFiBerry-Digi.-Driver-is-b.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. From bccfebf3bc4457faddaa65e3492ec9f07cb5750b Mon Sep 17 00:00:00 2001
  2. From: Daniel Matuschek <info@crazy-audio.com>
  3. Date: Wed, 15 Jan 2014 21:42:08 +0100
  4. Subject: [PATCH 038/114] ASoC: BCM:Add support for HiFiBerry Digi. Driver is
  5. based on the patched WM8804 driver.
  6. Signed-off-by: Daniel Matuschek <daniel@matuschek.net>
  7. ---
  8. sound/soc/bcm/Kconfig | 7 ++
  9. sound/soc/bcm/Makefile | 2 +
  10. sound/soc/bcm/hifiberry_digi.c | 153 +++++++++++++++++++++++++++++++++++++++++
  11. 3 files changed, 162 insertions(+)
  12. create mode 100644 sound/soc/bcm/hifiberry_digi.c
  13. --- a/sound/soc/bcm/Kconfig
  14. +++ b/sound/soc/bcm/Kconfig
  15. @@ -26,6 +26,13 @@ config SND_BCM2708_SOC_HIFIBERRY_DAC
  16. help
  17. Say Y or M if you want to add support for HifiBerry DAC.
  18. +config SND_BCM2708_SOC_HIFIBERRY_DIGI
  19. + tristate "Support for HifiBerry Digi"
  20. + depends on SND_BCM2708_SOC_I2S
  21. + select SND_SOC_WM8804
  22. + help
  23. + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
  24. +
  25. config SND_BCM2708_SOC_RPI_DAC
  26. tristate "Support for RPi-DAC"
  27. depends on SND_BCM2708_SOC_I2S
  28. --- a/sound/soc/bcm/Makefile
  29. +++ b/sound/soc/bcm/Makefile
  30. @@ -10,7 +10,9 @@ obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd
  31. # BCM2708 Machine Support
  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. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  36. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  37. obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  38. --- /dev/null
  39. +++ b/sound/soc/bcm/hifiberry_digi.c
  40. @@ -0,0 +1,153 @@
  41. +/*
  42. + * ASoC Driver for HifiBerry Digi
  43. + *
  44. + * Author: Daniel Matuschek <info@crazy-audio.com>
  45. + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
  46. + * Copyright 2013
  47. + *
  48. + * This program is free software; you can redistribute it and/or
  49. + * modify it under the terms of the GNU General Public License
  50. + * version 2 as published by the Free Software Foundation.
  51. + *
  52. + * This program is distributed in the hope that it will be useful, but
  53. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  54. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  55. + * General Public License for more details.
  56. + */
  57. +
  58. +#include <linux/module.h>
  59. +#include <linux/platform_device.h>
  60. +
  61. +#include <sound/core.h>
  62. +#include <sound/pcm.h>
  63. +#include <sound/pcm_params.h>
  64. +#include <sound/soc.h>
  65. +#include <sound/jack.h>
  66. +
  67. +#include "../codecs/wm8804.h"
  68. +
  69. +static int samplerate=44100;
  70. +
  71. +static int snd_rpi_hifiberry_digi_init(struct snd_soc_pcm_runtime *rtd)
  72. +{
  73. + struct snd_soc_codec *codec = rtd->codec;
  74. +
  75. + /* enable TX output */
  76. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  77. +
  78. + return 0;
  79. +}
  80. +
  81. +static int snd_rpi_hifiberry_digi_hw_params(struct snd_pcm_substream *substream,
  82. + struct snd_pcm_hw_params *params)
  83. +{
  84. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  85. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  86. + struct snd_soc_codec *codec = rtd->codec;
  87. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  88. +
  89. + int sysclk = 27000000; /* This is fixed on this board */
  90. +
  91. + long mclk_freq=0;
  92. + int mclk_div=1;
  93. +
  94. + int ret;
  95. +
  96. + samplerate = params_rate(params);
  97. +
  98. + switch (samplerate) {
  99. + case 44100:
  100. + case 48000:
  101. + case 88200:
  102. + case 96000:
  103. + mclk_freq=samplerate*256;
  104. + mclk_div=WM8804_MCLKDIV_256FS;
  105. + break;
  106. + case 176400:
  107. + case 192000:
  108. + mclk_freq=samplerate*128;
  109. + mclk_div=WM8804_MCLKDIV_128FS;
  110. + break;
  111. + default:
  112. + dev_err(substream->pcm->dev,
  113. + "Failed to set WM8804 SYSCLK, unsupported samplerate\n");
  114. + }
  115. +
  116. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  117. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  118. +
  119. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  120. + sysclk, SND_SOC_CLOCK_OUT);
  121. + if (ret < 0) {
  122. + dev_err(substream->pcm->dev,
  123. + "Failed to set WM8804 SYSCLK: %d\n", ret);
  124. + return ret;
  125. + }
  126. +
  127. + /* Enable TX output */
  128. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  129. +
  130. + /* Power on */
  131. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  132. +
  133. + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
  134. +}
  135. +
  136. +/* machine stream operations */
  137. +static struct snd_soc_ops snd_rpi_hifiberry_digi_ops = {
  138. + .hw_params = snd_rpi_hifiberry_digi_hw_params,
  139. +};
  140. +
  141. +static struct snd_soc_dai_link snd_rpi_hifiberry_digi_dai[] = {
  142. +{
  143. + .name = "HifiBerry Digi",
  144. + .stream_name = "HifiBerry Digi HiFi",
  145. + .cpu_dai_name = "bcm2708-i2s.0",
  146. + .codec_dai_name = "wm8804-spdif",
  147. + .platform_name = "bcm2708-i2s.0",
  148. + .codec_name = "wm8804.1-003b",
  149. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  150. + SND_SOC_DAIFMT_CBM_CFM,
  151. + .ops = &snd_rpi_hifiberry_digi_ops,
  152. + .init = snd_rpi_hifiberry_digi_init,
  153. +},
  154. +};
  155. +
  156. +/* audio machine driver */
  157. +static struct snd_soc_card snd_rpi_hifiberry_digi = {
  158. + .name = "snd_rpi_hifiberry_digi",
  159. + .dai_link = snd_rpi_hifiberry_digi_dai,
  160. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_digi_dai),
  161. +};
  162. +
  163. +static int snd_rpi_hifiberry_digi_probe(struct platform_device *pdev)
  164. +{
  165. + int ret = 0;
  166. +
  167. + snd_rpi_hifiberry_digi.dev = &pdev->dev;
  168. + ret = snd_soc_register_card(&snd_rpi_hifiberry_digi);
  169. + if (ret)
  170. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  171. +
  172. + return ret;
  173. +}
  174. +
  175. +static int snd_rpi_hifiberry_digi_remove(struct platform_device *pdev)
  176. +{
  177. + return snd_soc_unregister_card(&snd_rpi_hifiberry_digi);
  178. +}
  179. +
  180. +static struct platform_driver snd_rpi_hifiberry_digi_driver = {
  181. + .driver = {
  182. + .name = "snd-hifiberry-digi",
  183. + .owner = THIS_MODULE,
  184. + },
  185. + .probe = snd_rpi_hifiberry_digi_probe,
  186. + .remove = snd_rpi_hifiberry_digi_remove,
  187. +};
  188. +
  189. +module_platform_driver(snd_rpi_hifiberry_digi_driver);
  190. +
  191. +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
  192. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry Digi");
  193. +MODULE_LICENSE("GPL v2");