0349-New-AudioInjector.net-Pi-soundcard-with-low-jitter-a.patch 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. From 4f02da8ef066e8f62f41bae95348aede12bd4bd1 Mon Sep 17 00:00:00 2001
  2. From: Matt Flax <flatmax@flatmax.org>
  3. Date: Mon, 16 May 2016 21:36:31 +1000
  4. Subject: [PATCH] New AudioInjector.net Pi soundcard with low jitter audio in
  5. and out.
  6. Contains the sound/soc/bcm ALSA machine driver and necessary alterations to the Kconfig and Makefile.
  7. Adds the dts overlay and updates the Makefile and README.
  8. Updates the relevant defconfig files to enable building for the Raspberry Pi.
  9. Thanks to Phil Elwell (pelwell) for the review, simple-card concepts and discussion. Thanks to Clive Messer for overlay naming suggestions.
  10. ---
  11. arch/arm/boot/dts/overlays/Makefile | 1 +
  12. arch/arm/boot/dts/overlays/README | 6 +
  13. .../audioinjector-wm8731-audio-overlay.dts | 39 ++++++
  14. arch/arm/configs/bcm2709_defconfig | 1 +
  15. arch/arm/configs/bcmrpi_defconfig | 1 +
  16. sound/soc/bcm/Kconfig | 7 +
  17. sound/soc/bcm/Makefile | 3 +
  18. sound/soc/bcm/audioinjector-pi-soundcard.c | 142 +++++++++++++++++++++
  19. 8 files changed, 200 insertions(+)
  20. create mode 100644 arch/arm/boot/dts/overlays/audioinjector-wm8731-audio-overlay.dts
  21. create mode 100644 sound/soc/bcm/audioinjector-pi-soundcard.c
  22. --- a/arch/arm/boot/dts/overlays/Makefile
  23. +++ b/arch/arm/boot/dts/overlays/Makefile
  24. @@ -16,6 +16,7 @@ dtbo-$(RPI_DT_OVERLAYS) += adau1977-adc.
  25. dtbo-$(RPI_DT_OVERLAYS) += ads7846.dtbo
  26. dtbo-$(RPI_DT_OVERLAYS) += akkordion-iqdacplus.dtbo
  27. dtbo-$(RPI_DT_OVERLAYS) += at86rf233.dtbo
  28. +dtbo-$(RPI_DT_OVERLAYS) += audioinjector-wm8731-audio.dtbo
  29. dtbo-$(RPI_DT_OVERLAYS) += bmp085_i2c-sensor.dtbo
  30. dtbo-$(RPI_DT_OVERLAYS) += boomberry-dac.dtbo
  31. dtbo-$(RPI_DT_OVERLAYS) += boomberry-digi.dtbo
  32. --- a/arch/arm/boot/dts/overlays/README
  33. +++ b/arch/arm/boot/dts/overlays/README
  34. @@ -225,6 +225,12 @@ Params: interrupt GPIO use
  35. arrays (0=+0pF, 15=+4.5pF, default 15)
  36. +Name: audioinjector-wm8731-audio
  37. +Info: Configures the audioinjector.net audio add on soundcard
  38. +Load: dtoverlay=audioinjector-wm8731-audio
  39. +Params: <None>
  40. +
  41. +
  42. Name: bmp085_i2c-sensor
  43. Info: Configures the BMP085/BMP180 digital barometric pressure and temperature
  44. sensors from Bosch Sensortec
  45. --- /dev/null
  46. +++ b/arch/arm/boot/dts/overlays/audioinjector-wm8731-audio-overlay.dts
  47. @@ -0,0 +1,39 @@
  48. +// Definitions for audioinjector.net audio add on soundcard
  49. +/dts-v1/;
  50. +/plugin/;
  51. +
  52. +/ {
  53. + compatible = "brcm,bcm2708";
  54. +
  55. + fragment@0 {
  56. + target = <&i2s>;
  57. + __overlay__ {
  58. + status = "okay";
  59. + };
  60. + };
  61. +
  62. + fragment@1 {
  63. + target = <&i2c1>;
  64. + __overlay__ {
  65. + #address-cells = <1>;
  66. + #size-cells = <0>;
  67. + status = "okay";
  68. +
  69. + wm8731@1a {
  70. + #sound-dai-cells = <0>;
  71. + compatible = "wlf,wm8731";
  72. + reg = <0x1a>;
  73. + status = "okay";
  74. + };
  75. + };
  76. + };
  77. +
  78. + fragment@2 {
  79. + target = <&sound>;
  80. + __overlay__ {
  81. + compatible = "ai,audioinjector-pi-soundcard";
  82. + i2s-controller = <&i2s>;
  83. + status = "okay";
  84. + };
  85. + };
  86. +};
  87. --- a/arch/arm/configs/bcm2709_defconfig
  88. +++ b/arch/arm/configs/bcm2709_defconfig
  89. @@ -863,6 +863,7 @@ CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
  90. CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI=m
  91. CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  92. CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
  93. +CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
  94. CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
  95. CONFIG_SND_SOC_ADAU1701=m
  96. CONFIG_SND_SOC_WM8804_I2C=m
  97. --- a/arch/arm/configs/bcmrpi_defconfig
  98. +++ b/arch/arm/configs/bcmrpi_defconfig
  99. @@ -855,6 +855,7 @@ CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
  100. CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI=m
  101. CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  102. CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
  103. +CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
  104. CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
  105. CONFIG_SND_SOC_ADAU1701=m
  106. CONFIG_SND_SOC_WM8804_I2C=m
  107. --- a/sound/soc/bcm/Kconfig
  108. +++ b/sound/soc/bcm/Kconfig
  109. @@ -85,3 +85,10 @@ config SND_BCM2708_SOC_ADAU1977_ADC
  110. select SND_SOC_ADAU1977_I2C
  111. help
  112. Say Y or M if you want to add support for ADAU1977 ADC.
  113. +
  114. +config SND_AUDIOINJECTOR_PI_SOUNDCARD
  115. + tristate "Support for audioinjector.net Pi add on soundcard"
  116. + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  117. + select SND_SOC_WM8731
  118. + help
  119. + Say Y or M if you want to add support for audioinjector.net Pi Hat
  120. --- a/sound/soc/bcm/Makefile
  121. +++ b/sound/soc/bcm/Makefile
  122. @@ -15,6 +15,7 @@ snd-soc-rpi-dac-objs := rpi-dac.o
  123. snd-soc-rpi-proto-objs := rpi-proto.o
  124. snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  125. snd-soc-raspidac3-objs := raspidac3.o
  126. +snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
  127. obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
  128. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  129. @@ -27,3 +28,5 @@ obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) +=
  130. obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
  131. obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  132. obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
  133. +obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
  134. +
  135. --- /dev/null
  136. +++ b/sound/soc/bcm/audioinjector-pi-soundcard.c
  137. @@ -0,0 +1,142 @@
  138. +/*
  139. + * ASoC Driver for AudioInjector Pi add on soundcard
  140. + *
  141. + * Created on: 13-May-2016
  142. + * Author: flatmax@flatmax.org
  143. + * based on code by Cliff Cai <Cliff.Cai@analog.com> for the ssm2602 machine blackfin.
  144. + * with help from Lars-Peter Clausen for simplifying the original code to use the dai_fmt field.
  145. + * i2s_node code taken from the other sound/soc/bcm machine drivers.
  146. + *
  147. + * Copyright (C) 2016 Flatmax Pty. Ltd.
  148. + *
  149. + * This program is free software; you can redistribute it and/or
  150. + * modify it under the terms of the GNU General Public License
  151. + * version 2 as published by the Free Software Foundation.
  152. + *
  153. + * This program is distributed in the hope that it will be useful, but
  154. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  155. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  156. + * General Public License for more details.
  157. + */
  158. +
  159. +#include <linux/module.h>
  160. +#include <linux/types.h>
  161. +
  162. +#include <sound/core.h>
  163. +#include <sound/soc.h>
  164. +#include <sound/pcm_params.h>
  165. +#include <sound/control.h>
  166. +
  167. +#include "../codecs/wm8731.h"
  168. +
  169. +static int audioinjector_pi_soundcard_dai_init(struct snd_soc_pcm_runtime *rtd)
  170. +{
  171. + struct snd_soc_dapm_context *dapm = &rtd->card->dapm;
  172. +
  173. + // not connected
  174. + snd_soc_dapm_nc_pin(dapm, "Mic Bias");
  175. + snd_soc_dapm_nc_pin(dapm, "MICIN");
  176. + snd_soc_dapm_nc_pin(dapm, "RHPOUT");
  177. + snd_soc_dapm_nc_pin(dapm, "LHPOUT");
  178. +
  179. + return snd_soc_dai_set_sysclk(rtd->codec_dai, WM8731_SYSCLK_XTAL, 12000000, SND_SOC_CLOCK_IN);
  180. +}
  181. +
  182. +static struct snd_soc_dai_link audioinjector_pi_soundcard_dai[] = {
  183. + {
  184. + .name = "AudioInjector audio",
  185. + .stream_name = "AudioInjector audio",
  186. + .cpu_dai_name = "bcm2708-i2s.0",
  187. + .codec_dai_name = "wm8731-hifi",
  188. + .platform_name = "bcm2835-i2s.0",
  189. + .codec_name = "wm8731.1-001a",
  190. + .init = audioinjector_pi_soundcard_dai_init,
  191. + .dai_fmt = SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF,
  192. + },
  193. +};
  194. +
  195. +static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
  196. + SND_SOC_DAPM_SPK("Ext Spk", NULL),
  197. + SND_SOC_DAPM_LINE("Line In Jacks", NULL),
  198. +};
  199. +
  200. +/* Corgi machine connections to the codec pins */
  201. +static const struct snd_soc_dapm_route audioinjector_audio_map[] = {
  202. + /* speaker connected to LOUT, ROUT */
  203. + {"Ext Spk", NULL, "ROUT"},
  204. + {"Ext Spk", NULL, "LOUT"},
  205. +
  206. + /* line inputs */
  207. + {"Line In Jacks", NULL, "Line Input"},
  208. +};
  209. +
  210. +static struct snd_soc_card snd_soc_audioinjector = {
  211. + .name = "audioinjector-pi-soundcard",
  212. + .dai_link = audioinjector_pi_soundcard_dai,
  213. + .num_links = 1,
  214. +
  215. + .dapm_widgets = wm8731_dapm_widgets,
  216. + .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets),
  217. + .dapm_routes = audioinjector_audio_map,
  218. + .num_dapm_routes = ARRAY_SIZE(audioinjector_audio_map),
  219. +};
  220. +
  221. +static int audioinjector_pi_soundcard_probe(struct platform_device *pdev)
  222. +{
  223. + struct snd_soc_card *card = &snd_soc_audioinjector;
  224. + int ret;
  225. +
  226. + card->dev = &pdev->dev;
  227. +
  228. + if (pdev->dev.of_node) {
  229. + struct snd_soc_dai_link *dai = &audioinjector_pi_soundcard_dai[0];
  230. + struct device_node *i2s_node = of_parse_phandle(pdev->dev.of_node,
  231. + "i2s-controller", 0);
  232. +
  233. + if (i2s_node) {
  234. + dai->cpu_dai_name = NULL;
  235. + dai->cpu_of_node = i2s_node;
  236. + dai->platform_name = NULL;
  237. + dai->platform_of_node = i2s_node;
  238. + } else
  239. + if (!dai->cpu_of_node) {
  240. + dev_err(&pdev->dev, "Property 'i2s-controller' missing or invalid\n");
  241. + return -EINVAL;
  242. + }
  243. + }
  244. +
  245. + if ((ret = snd_soc_register_card(card))) {
  246. + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
  247. + }
  248. + return ret;
  249. +}
  250. +
  251. +static int audioinjector_pi_soundcard_remove(struct platform_device *pdev)
  252. +{
  253. + struct snd_soc_card *card = platform_get_drvdata(pdev);
  254. + return snd_soc_unregister_card(card);
  255. +
  256. +}
  257. +
  258. +static const struct of_device_id audioinjector_pi_soundcard_of_match[] = {
  259. + { .compatible = "ai,audioinjector-pi-soundcard", },
  260. + {},
  261. +};
  262. +MODULE_DEVICE_TABLE(of, audioinjector_pi_soundcard_of_match);
  263. +
  264. +static struct platform_driver audioinjector_pi_soundcard_driver = {
  265. + .driver = {
  266. + .name = "audioinjector-audio",
  267. + .owner = THIS_MODULE,
  268. + .of_match_table = audioinjector_pi_soundcard_of_match,
  269. + },
  270. + .probe = audioinjector_pi_soundcard_probe,
  271. + .remove = audioinjector_pi_soundcard_remove,
  272. +};
  273. +
  274. +module_platform_driver(audioinjector_pi_soundcard_driver);
  275. +MODULE_AUTHOR("Matt Flax <flatmax@flatmax.org>");
  276. +MODULE_DESCRIPTION("AudioInjector.net Pi Soundcard");
  277. +MODULE_LICENSE("GPL v2");
  278. +MODULE_ALIAS("platform:audioinjector-pi-soundcard");
  279. +