0421-Add-support-for-Dion-Audio-LOCO-DAC-AMP-HAT.patch 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. From be377792090556422c0735f3486b502b991da36d Mon Sep 17 00:00:00 2001
  2. From: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
  3. Date: Sat, 2 Jul 2016 16:26:19 +0100
  4. Subject: [PATCH] Add support for Dion Audio LOCO DAC-AMP HAT
  5. Using dedicated machine driver and pcm5102a codec driver.
  6. Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
  7. ---
  8. arch/arm/boot/dts/overlays/Makefile | 1 +
  9. arch/arm/boot/dts/overlays/README | 6 +
  10. .../boot/dts/overlays/dionaudio-loco-overlay.dts | 39 +++++++
  11. arch/arm/configs/bcm2709_defconfig | 1 +
  12. arch/arm/configs/bcmrpi_defconfig | 1 +
  13. sound/soc/bcm/Kconfig | 7 ++
  14. sound/soc/bcm/Makefile | 3 +-
  15. sound/soc/bcm/dionaudio_loco.c | 121 +++++++++++++++++++++
  16. 8 files changed, 178 insertions(+), 1 deletion(-)
  17. create mode 100644 arch/arm/boot/dts/overlays/dionaudio-loco-overlay.dts
  18. create mode 100644 sound/soc/bcm/dionaudio_loco.c
  19. --- a/arch/arm/boot/dts/overlays/Makefile
  20. +++ b/arch/arm/boot/dts/overlays/Makefile
  21. @@ -20,6 +20,7 @@ dtbo-$(RPI_DT_OVERLAYS) += at86rf233.dtb
  22. dtbo-$(RPI_DT_OVERLAYS) += audioinjector-wm8731-audio.dtbo
  23. dtbo-$(RPI_DT_OVERLAYS) += bmp085_i2c-sensor.dtbo
  24. dtbo-$(RPI_DT_OVERLAYS) += dht11.dtbo
  25. +dtbo-$(RPI_DT_OVERLAYS) += dionaudio-loco.dtbo
  26. dtbo-$(RPI_DT_OVERLAYS) += dpi24.dtbo
  27. dtbo-$(RPI_DT_OVERLAYS) += dwc-otg.dtbo
  28. dtbo-$(RPI_DT_OVERLAYS) += dwc2.dtbo
  29. --- a/arch/arm/boot/dts/overlays/README
  30. +++ b/arch/arm/boot/dts/overlays/README
  31. @@ -268,6 +268,12 @@ Params: gpiopin GPIO con
  32. (default 4)
  33. +Name: dionaudio-loco
  34. +Info: Configures the Dion Audio LOCO DAC-AMP
  35. +Load: dtoverlay=dionaudio-loco
  36. +Params: <None>
  37. +
  38. +
  39. Name: dpi24
  40. Info: Overlay for a generic 24-bit DPI display
  41. This uses GPIOs 0-27 (so no I2C, uart etc.), and activates the output
  42. --- /dev/null
  43. +++ b/arch/arm/boot/dts/overlays/dionaudio-loco-overlay.dts
  44. @@ -0,0 +1,39 @@
  45. +// Definitions for Dion Audio LOCO DAC-AMP
  46. +
  47. +/*
  48. + * PCM5242 DAC (in hardware mode) and TPA3118 AMP.
  49. + */
  50. +
  51. +/dts-v1/;
  52. +/plugin/;
  53. +
  54. +/ {
  55. + compatible = "brcm,bcm2708";
  56. +
  57. + fragment@0 {
  58. + target = <&i2s>;
  59. + __overlay__ {
  60. + status = "okay";
  61. + };
  62. + };
  63. +
  64. + fragment@1 {
  65. + target-path = "/";
  66. + __overlay__ {
  67. + pcm5102a-codec {
  68. + #sound-dai-cells = <0>;
  69. + compatible = "ti,pcm5102a";
  70. + status = "okay";
  71. + };
  72. + };
  73. + };
  74. +
  75. + fragment@2 {
  76. + target = <&sound>;
  77. + __overlay__ {
  78. + compatible = "dionaudio,loco-pcm5242-tpa3118";
  79. + i2s-controller = <&i2s>;
  80. + status = "okay";
  81. + };
  82. + };
  83. +};
  84. --- a/arch/arm/configs/bcm2709_defconfig
  85. +++ b/arch/arm/configs/bcm2709_defconfig
  86. @@ -870,6 +870,7 @@ CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
  87. CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
  88. CONFIG_SND_DIGIDAC1_SOUNDCARD=m
  89. CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
  90. +CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
  91. CONFIG_SND_SOC_ADAU1701=m
  92. CONFIG_SND_SOC_WM8804_I2C=m
  93. CONFIG_SND_SIMPLE_CARD=m
  94. --- a/arch/arm/configs/bcmrpi_defconfig
  95. +++ b/arch/arm/configs/bcmrpi_defconfig
  96. @@ -862,6 +862,7 @@ CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
  97. CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
  98. CONFIG_SND_DIGIDAC1_SOUNDCARD=m
  99. CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
  100. +CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
  101. CONFIG_SND_SOC_ADAU1701=m
  102. CONFIG_SND_SOC_WM8804_I2C=m
  103. CONFIG_SND_SIMPLE_CARD=m
  104. --- a/sound/soc/bcm/Kconfig
  105. +++ b/sound/soc/bcm/Kconfig
  106. @@ -107,3 +107,10 @@ config SND_DIGIDAC1_SOUNDCARD
  107. select SND_SOC_WM8741
  108. help
  109. Say Y or M if you want to add support for Red Rocks Audio DigiDAC1 board.
  110. +
  111. +config SND_BCM2708_SOC_DIONAUDIO_LOCO
  112. + tristate "Support for Dion Audio LOCO DAC-AMP"
  113. + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  114. + select SND_SOC_PCM5102a
  115. + help
  116. + Say Y or M if you want to add support for Dion Audio LOCO.
  117. --- a/sound/soc/bcm/Makefile
  118. +++ b/sound/soc/bcm/Makefile
  119. @@ -18,6 +18,7 @@ snd-soc-iqaudio-digi-objs := iqaudio_dig
  120. snd-soc-raspidac3-objs := raspidac3.o
  121. snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
  122. snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
  123. +snd-soc-dionaudio-loco-objs := dionaudio_loco.o
  124. obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
  125. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  126. @@ -33,4 +34,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DIG
  127. obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
  128. obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
  129. obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
  130. -
  131. +obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
  132. --- /dev/null
  133. +++ b/sound/soc/bcm/dionaudio_loco.c
  134. @@ -0,0 +1,121 @@
  135. +/*
  136. + * ASoC Driver for Dion Audio LOCO DAC-AMP
  137. + *
  138. + * Author: Miquel Blauw <info@dionaudio.nl>
  139. + * Copyright 2016
  140. + *
  141. + * Based on the software of the RPi-DAC writen by Florian Meier
  142. + *
  143. + * This program is free software; you can redistribute it and/or
  144. + * modify it under the terms of the GNU General Public License
  145. + * version 2 as published by the Free Software Foundation.
  146. + *
  147. + * This program is distributed in the hope that it will be useful, but
  148. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  149. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  150. + * General Public License for more details.
  151. + */
  152. +
  153. +#include <linux/module.h>
  154. +#include <linux/platform_device.h>
  155. +
  156. +#include <sound/core.h>
  157. +#include <sound/pcm.h>
  158. +#include <sound/pcm_params.h>
  159. +#include <sound/soc.h>
  160. +#include <sound/jack.h>
  161. +
  162. +static int snd_rpi_dionaudio_loco_hw_params(
  163. + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
  164. +{
  165. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  166. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  167. +
  168. + unsigned int sample_bits =
  169. + snd_pcm_format_physical_width(params_format(params));
  170. +
  171. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  172. +}
  173. +
  174. +/* machine stream operations */
  175. +static struct snd_soc_ops snd_rpi_dionaudio_loco_ops = {
  176. + .hw_params = snd_rpi_dionaudio_loco_hw_params,
  177. +};
  178. +
  179. +static struct snd_soc_dai_link snd_rpi_dionaudio_loco_dai[] = {
  180. +{
  181. + .name = "DionAudio LOCO",
  182. + .stream_name = "DionAudio LOCO DAC-AMP",
  183. + .cpu_dai_name = "bcm2708-i2s.0",
  184. + .codec_dai_name = "pcm5102a-hifi",
  185. + .platform_name = "bcm2708-i2s.0",
  186. + .codec_name = "pcm5102a-codec",
  187. + .dai_fmt = SND_SOC_DAIFMT_I2S |
  188. + SND_SOC_DAIFMT_NB_NF |
  189. + SND_SOC_DAIFMT_CBS_CFS,
  190. + .ops = &snd_rpi_dionaudio_loco_ops,
  191. +},
  192. +};
  193. +
  194. +/* audio machine driver */
  195. +static struct snd_soc_card snd_rpi_dionaudio_loco = {
  196. + .name = "snd_rpi_dionaudio_loco",
  197. + .dai_link = snd_rpi_dionaudio_loco_dai,
  198. + .num_links = ARRAY_SIZE(snd_rpi_dionaudio_loco_dai),
  199. +};
  200. +
  201. +static int snd_rpi_dionaudio_loco_probe(struct platform_device *pdev)
  202. +{
  203. + struct device_node *np;
  204. + int ret = 0;
  205. +
  206. + snd_rpi_dionaudio_loco.dev = &pdev->dev;
  207. +
  208. + np = pdev->dev.of_node;
  209. + if (np) {
  210. + struct snd_soc_dai_link *dai = &snd_rpi_dionaudio_loco_dai[0];
  211. + struct device_node *i2s_np;
  212. +
  213. + i2s_np = of_parse_phandle(np, "i2s-controller", 0);
  214. + if (i2s_np) {
  215. + dai->cpu_dai_name = NULL;
  216. + dai->cpu_of_node = i2s_np;
  217. + dai->platform_name = NULL;
  218. + dai->platform_of_node = i2s_np;
  219. + }
  220. + }
  221. +
  222. + ret = snd_soc_register_card(&snd_rpi_dionaudio_loco);
  223. + if (ret)
  224. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  225. + ret);
  226. +
  227. + return ret;
  228. +}
  229. +
  230. +static int snd_rpi_dionaudio_loco_remove(struct platform_device *pdev)
  231. +{
  232. + return snd_soc_unregister_card(&snd_rpi_dionaudio_loco);
  233. +}
  234. +
  235. +static const struct of_device_id snd_rpi_dionaudio_loco_of_match[] = {
  236. + { .compatible = "dionaudio,loco-pcm5242-tpa3118", },
  237. + { /* sentinel */ },
  238. +};
  239. +MODULE_DEVICE_TABLE(of, snd_rpi_dionaudio_loco_of_match);
  240. +
  241. +static struct platform_driver snd_rpi_dionaudio_loco_driver = {
  242. + .driver = {
  243. + .name = "snd-dionaudio-loco",
  244. + .owner = THIS_MODULE,
  245. + .of_match_table = snd_rpi_dionaudio_loco_of_match,
  246. + },
  247. + .probe = snd_rpi_dionaudio_loco_probe,
  248. + .remove = snd_rpi_dionaudio_loco_remove,
  249. +};
  250. +
  251. +module_platform_driver(snd_rpi_dionaudio_loco_driver);
  252. +
  253. +MODULE_AUTHOR("Miquel Blauw <info@dionaudio.nl>");
  254. +MODULE_DESCRIPTION("ASoC Driver for DionAudio LOCO");
  255. +MODULE_LICENSE("GPL v2");