0060-Added-support-for-HiFiBerry-DAC.patch 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. From fb7a1cc51aee2d66232d3a170e1343dfbb7b3485 Mon Sep 17 00:00:00 2001
  2. From: Daniel Matuschek <info@crazy-audio.com>
  3. Date: Mon, 4 Aug 2014 10:06:56 +0200
  4. Subject: [PATCH 060/114] Added support for HiFiBerry DAC+
  5. The driver is based on the HiFiBerry DAC driver. However HiFiBerry DAC+ uses
  6. a different codec chip (PCM5122), therefore a new driver is necessary.
  7. ---
  8. arch/arm/configs/bcmrpi_defconfig | 1 +
  9. arch/arm/mach-bcm2708/bcm2708.c | 19 ++++++
  10. sound/soc/bcm/Kconfig | 7 +++
  11. sound/soc/bcm/Makefile | 2 +
  12. sound/soc/bcm/hifiberry_dacplus.c | 119 ++++++++++++++++++++++++++++++++++++++
  13. 5 files changed, 148 insertions(+)
  14. create mode 100644 sound/soc/bcm/hifiberry_dacplus.c
  15. --- a/arch/arm/configs/bcmrpi_defconfig
  16. +++ b/arch/arm/configs/bcmrpi_defconfig
  17. @@ -756,6 +756,7 @@ CONFIG_SND_USB_6FIRE=m
  18. CONFIG_SND_SOC=m
  19. CONFIG_SND_BCM2708_SOC_I2S=m
  20. CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  21. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
  22. CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  23. CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  24. CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  25. --- a/arch/arm/mach-bcm2708/bcm2708.c
  26. +++ b/arch/arm/mach-bcm2708/bcm2708.c
  27. @@ -645,6 +645,20 @@ static struct platform_device snd_pcm510
  28. };
  29. #endif
  30. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
  31. +static struct platform_device snd_rpi_hifiberry_dacplus_device = {
  32. + .name = "snd-rpi-hifiberry-dacplus",
  33. + .id = 0,
  34. + .num_resources = 0,
  35. +};
  36. +
  37. +static struct i2c_board_info __initdata snd_pcm512x_hbdacplus_i2c_devices[] = {
  38. + {
  39. + I2C_BOARD_INFO("pcm5122", 0x4d)
  40. + },
  41. +};
  42. +#endif
  43. +
  44. #if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  45. static struct platform_device snd_hifiberry_digi_device = {
  46. .name = "snd-hifiberry-digi",
  47. @@ -845,6 +859,11 @@ void __init bcm2708_init(void)
  48. bcm_register_device(&snd_pcm5102a_codec_device);
  49. #endif
  50. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
  51. + bcm_register_device(&snd_rpi_hifiberry_dacplus_device);
  52. + i2c_register_board_info(1, snd_pcm512x_hbdacplus_i2c_devices, ARRAY_SIZE(snd_pcm512x_hbdacplus_i2c_devices));
  53. +#endif
  54. +
  55. #if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  56. bcm_register_device(&snd_hifiberry_digi_device);
  57. i2c_register_board_info(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
  58. --- a/sound/soc/bcm/Kconfig
  59. +++ b/sound/soc/bcm/Kconfig
  60. @@ -26,6 +26,13 @@ config SND_BCM2708_SOC_HIFIBERRY_DAC
  61. help
  62. Say Y or M if you want to add support for HifiBerry DAC.
  63. +config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
  64. + tristate "Support for HifiBerry DAC+"
  65. + depends on SND_BCM2708_SOC_I2S
  66. + select SND_SOC_PCM512x
  67. + help
  68. + Say Y or M if you want to add support for HifiBerry DAC+.
  69. +
  70. config SND_BCM2708_SOC_HIFIBERRY_DIGI
  71. tristate "Support for HifiBerry Digi"
  72. depends on SND_BCM2708_SOC_I2S
  73. --- a/sound/soc/bcm/Makefile
  74. +++ b/sound/soc/bcm/Makefile
  75. @@ -10,11 +10,13 @@ obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd
  76. # BCM2708 Machine Support
  77. snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  78. +snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
  79. snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  80. snd-soc-rpi-dac-objs := rpi-dac.o
  81. snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  82. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  83. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
  84. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  85. obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  86. obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  87. --- /dev/null
  88. +++ b/sound/soc/bcm/hifiberry_dacplus.c
  89. @@ -0,0 +1,119 @@
  90. +/*
  91. + * ASoC Driver for HiFiBerry DAC+
  92. + *
  93. + * Author: Daniel Matuschek
  94. + * Copyright 2014
  95. + * based on code by Florian Meier <florian.meier@koalo.de>
  96. + *
  97. + * This program is free software; you can redistribute it and/or
  98. + * modify it under the terms of the GNU General Public License
  99. + * version 2 as published by the Free Software Foundation.
  100. + *
  101. + * This program is distributed in the hope that it will be useful, but
  102. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  103. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  104. + * General Public License for more details.
  105. + */
  106. +
  107. +#include <linux/module.h>
  108. +#include <linux/platform_device.h>
  109. +
  110. +#include <sound/core.h>
  111. +#include <sound/pcm.h>
  112. +#include <sound/pcm_params.h>
  113. +#include <sound/soc.h>
  114. +#include <sound/jack.h>
  115. +
  116. +#include "../codecs/pcm512x.h"
  117. +
  118. +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
  119. +{
  120. + struct snd_soc_codec *codec = rtd->codec;
  121. + snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
  122. + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
  123. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
  124. + return 0;
  125. +}
  126. +
  127. +static int snd_rpi_hifiberry_dacplus_hw_params(struct snd_pcm_substream *substream,
  128. + struct snd_pcm_hw_params *params)
  129. +{
  130. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  131. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  132. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
  133. +}
  134. +
  135. +static int snd_rpi_hifiberry_dacplus_startup(struct snd_pcm_substream *substream) {
  136. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  137. + struct snd_soc_codec *codec = rtd->codec;
  138. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
  139. + return 0;
  140. +}
  141. +
  142. +static void snd_rpi_hifiberry_dacplus_shutdown(struct snd_pcm_substream *substream) {
  143. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  144. + struct snd_soc_codec *codec = rtd->codec;
  145. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
  146. +}
  147. +
  148. +/* machine stream operations */
  149. +static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = {
  150. + .hw_params = snd_rpi_hifiberry_dacplus_hw_params,
  151. + .startup = snd_rpi_hifiberry_dacplus_startup,
  152. + .shutdown = snd_rpi_hifiberry_dacplus_shutdown,
  153. +};
  154. +
  155. +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
  156. +{
  157. + .name = "HiFiBerry DAC+",
  158. + .stream_name = "HiFiBerry DAC+ HiFi",
  159. + .cpu_dai_name = "bcm2708-i2s.0",
  160. + .codec_dai_name = "pcm512x-hifi",
  161. + .platform_name = "bcm2708-i2s.0",
  162. + .codec_name = "pcm512x.1-004d",
  163. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  164. + SND_SOC_DAIFMT_CBS_CFS,
  165. + .ops = &snd_rpi_hifiberry_dacplus_ops,
  166. + .init = snd_rpi_hifiberry_dacplus_init,
  167. +},
  168. +};
  169. +
  170. +/* audio machine driver */
  171. +static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
  172. + .name = "snd_rpi_hifiberry_dacplus",
  173. + .dai_link = snd_rpi_hifiberry_dacplus_dai,
  174. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
  175. +};
  176. +
  177. +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
  178. +{
  179. + int ret = 0;
  180. +
  181. + snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
  182. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplus);
  183. + if (ret)
  184. + dev_err(&pdev->dev,
  185. + "snd_soc_register_card() failed: %d\n", ret);
  186. +
  187. + return ret;
  188. +}
  189. +
  190. +static int snd_rpi_hifiberry_dacplus_remove(struct platform_device *pdev)
  191. +{
  192. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dacplus);
  193. +}
  194. +
  195. +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
  196. + .driver = {
  197. + .name = "snd-rpi-hifiberry-dacplus",
  198. + .owner = THIS_MODULE,
  199. + },
  200. + .probe = snd_rpi_hifiberry_dacplus_probe,
  201. + .remove = snd_rpi_hifiberry_dacplus_remove,
  202. +};
  203. +
  204. +module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
  205. +
  206. +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
  207. +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
  208. +MODULE_LICENSE("GPL v2");