0507-Allo-Piano-DAC-boards-Initial-2-channel-stereo-suppo.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. From 655114c25214675520d742f5e86cdd8dd534e6c7 Mon Sep 17 00:00:00 2001
  2. From: Clive Messer <clive.m.messer@gmail.com>
  3. Date: Mon, 19 Sep 2016 14:01:04 +0100
  4. Subject: [PATCH] Allo Piano DAC boards: Initial 2 channel (stereo) support
  5. (#1645)
  6. Add initial 2 channel (stereo) support for Allo Piano DAC (2.0/2.1) boards,
  7. using allo-piano-dac-pcm512x-audio overlay and allo-piano-dac ALSA ASoC
  8. machine driver.
  9. NB. The initial support is 2 channel (stereo) ONLY!
  10. (The Piano DAC 2.1 will only support 2 channel (stereo) left/right output,
  11. pending an update to the upstream pcm512x codec driver, which will have
  12. to be submitted via upstream. With the initial downstream support,
  13. provided by this patch, the Piano DAC 2.1 subwoofer outputs will
  14. not function.)
  15. Signed-off-by: Baswaraj K <jaikumar@cem-solutions.net>
  16. Signed-off-by: Clive Messer <clive.messer@digitaldreamtime.co.uk>
  17. Tested-by: Clive Messer <clive.messer@digitaldreamtime.co.uk>
  18. ---
  19. arch/arm/boot/dts/overlays/Makefile | 1 +
  20. arch/arm/boot/dts/overlays/README | 20 +++
  21. .../allo-piano-dac-pcm512x-audio-overlay.dts | 54 ++++++++
  22. arch/arm/configs/bcm2709_defconfig | 1 +
  23. arch/arm/configs/bcmrpi_defconfig | 1 +
  24. sound/soc/bcm/Kconfig | 7 +
  25. sound/soc/bcm/Makefile | 2 +
  26. sound/soc/bcm/allo-piano-dac.c | 144 +++++++++++++++++++++
  27. 8 files changed, 230 insertions(+)
  28. create mode 100644 arch/arm/boot/dts/overlays/allo-piano-dac-pcm512x-audio-overlay.dts
  29. create mode 100644 sound/soc/bcm/allo-piano-dac.c
  30. --- a/arch/arm/boot/dts/overlays/Makefile
  31. +++ b/arch/arm/boot/dts/overlays/Makefile
  32. @@ -16,6 +16,7 @@ dtbo-$(RPI_DT_OVERLAYS) += adau1977-adc.
  33. dtbo-$(RPI_DT_OVERLAYS) += ads1015.dtbo
  34. dtbo-$(RPI_DT_OVERLAYS) += ads7846.dtbo
  35. dtbo-$(RPI_DT_OVERLAYS) += akkordion-iqdacplus.dtbo
  36. +dtbo-$(RPI_DT_OVERLAYS) += allo-piano-dac-pcm512x-audio.dtbo
  37. dtbo-$(RPI_DT_OVERLAYS) += at86rf233.dtbo
  38. dtbo-$(RPI_DT_OVERLAYS) += audioinjector-wm8731-audio.dtbo
  39. dtbo-$(RPI_DT_OVERLAYS) += audremap.dtbo
  40. --- a/arch/arm/boot/dts/overlays/README
  41. +++ b/arch/arm/boot/dts/overlays/README
  42. @@ -235,6 +235,26 @@ Params: 24db_digital_gain Allow ga
  43. that does not result in clipping/distortion!)
  44. +Name: allo-piano-dac-pcm512x-audio
  45. +Info: Configures the Allo Piano DAC (2.0/2.1) audio cards.
  46. + (NB. This initial support is for 2.0 channel audio ONLY! ie. stereo.
  47. + The subwoofer outputs on the Piano 2.1 are not currently supported!)
  48. +Load: dtoverlay=allo-piano-dac-pcm512x-audio,<param>
  49. +Params: 24db_digital_gain Allow gain to be applied via the PCM512x codec
  50. + Digital volume control.
  51. + (The default behaviour is that the Digital
  52. + volume control is limited to a maximum of
  53. + 0dB. ie. it can attenuate but not provide
  54. + gain. For most users, this will be desired
  55. + as it will prevent clipping. By appending
  56. + the 24db_digital_gain parameter, the Digital
  57. + volume control will allow up to 24dB of
  58. + gain. If this parameter is enabled, it is the
  59. + responsibility of the user to ensure that
  60. + the Digital volume control is set to a value
  61. + that does not result in clipping/distortion!)
  62. +
  63. +
  64. Name: at86rf233
  65. Info: Configures the Atmel AT86RF233 802.15.4 low-power WPAN transceiver,
  66. connected to spi0.0
  67. --- /dev/null
  68. +++ b/arch/arm/boot/dts/overlays/allo-piano-dac-pcm512x-audio-overlay.dts
  69. @@ -0,0 +1,54 @@
  70. +/*
  71. + * Definitions for Allo Piano DAC (2.0/2.1) boards
  72. + *
  73. + * NB. The Piano DAC 2.1 board contains 2x TI PCM5142 DAC's. One DAC is stereo
  74. + * (left/right) and the other provides a subwoofer output, using DSP on the
  75. + * chip for digital high/low pass crossover.
  76. + * The initial support for this hardware, that doesn't require any codec driver
  77. + * modifications, uses only one DAC chip for stereo (left/right) output, the
  78. + * chip with 0x4c slave address. The other chip at 0x4d is currently ignored!
  79. + */
  80. +
  81. +/dts-v1/;
  82. +/plugin/;
  83. +
  84. +/ {
  85. + compatible = "brcm,bcm2708";
  86. +
  87. + fragment@0 {
  88. + target = <&i2s>;
  89. + __overlay__ {
  90. + status = "okay";
  91. + };
  92. + };
  93. +
  94. + fragment@1 {
  95. + target = <&i2c1>;
  96. + __overlay__ {
  97. + #address-cells = <1>;
  98. + #size-cells = <0>;
  99. + status = "okay";
  100. +
  101. + pcm5142@4c {
  102. + #sound-dai-cells = <0>;
  103. + compatible = "ti,pcm5142";
  104. + reg = <0x4c>;
  105. + status = "okay";
  106. + };
  107. + };
  108. + };
  109. +
  110. + fragment@2 {
  111. + target = <&sound>;
  112. + piano_dac: __overlay__ {
  113. + compatible = "allo,piano-dac";
  114. + i2s-controller = <&i2s>;
  115. + status = "okay";
  116. + };
  117. + };
  118. +
  119. + __overrides__ {
  120. + 24db_digital_gain =
  121. + <&piano_dac>,"allo,24db_digital_gain?";
  122. + };
  123. +};
  124. --- a/arch/arm/configs/bcm2709_defconfig
  125. +++ b/arch/arm/configs/bcm2709_defconfig
  126. @@ -879,6 +879,7 @@ CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
  127. CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
  128. CONFIG_SND_DIGIDAC1_SOUNDCARD=m
  129. CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
  130. +CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC=m
  131. CONFIG_SND_SOC_ADAU1701=m
  132. CONFIG_SND_SOC_WM8804_I2C=m
  133. CONFIG_SND_SIMPLE_CARD=m
  134. --- a/arch/arm/configs/bcmrpi_defconfig
  135. +++ b/arch/arm/configs/bcmrpi_defconfig
  136. @@ -871,6 +871,7 @@ CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
  137. CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
  138. CONFIG_SND_DIGIDAC1_SOUNDCARD=m
  139. CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO=m
  140. +CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC=m
  141. CONFIG_SND_SOC_ADAU1701=m
  142. CONFIG_SND_SOC_WM8804_I2C=m
  143. CONFIG_SND_SIMPLE_CARD=m
  144. --- a/sound/soc/bcm/Kconfig
  145. +++ b/sound/soc/bcm/Kconfig
  146. @@ -114,3 +114,10 @@ config SND_BCM2708_SOC_DIONAUDIO_LOCO
  147. select SND_SOC_PCM5102a
  148. help
  149. Say Y or M if you want to add support for Dion Audio LOCO.
  150. +
  151. +config SND_BCM2708_SOC_ALLO_PIANO_DAC
  152. + tristate "Support for Allo Piano DAC"
  153. + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  154. + select SND_SOC_PCM512x_I2C
  155. + help
  156. + Say Y or M if you want to add support for Allo Piano DAC.
  157. --- a/sound/soc/bcm/Makefile
  158. +++ b/sound/soc/bcm/Makefile
  159. @@ -19,6 +19,7 @@ snd-soc-raspidac3-objs := raspidac3.o
  160. snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
  161. snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
  162. snd-soc-dionaudio-loco-objs := dionaudio_loco.o
  163. +snd-soc-allo-piano-dac-objs := allo-piano-dac.o
  164. obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
  165. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  166. @@ -35,3 +36,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3)
  167. obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
  168. obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
  169. obj-$(CONFIG_SND_BCM2708_SOC_DIONAUDIO_LOCO) += snd-soc-dionaudio-loco.o
  170. +obj-$(CONFIG_SND_BCM2708_SOC_ALLO_PIANO_DAC) += snd-soc-allo-piano-dac.o
  171. --- /dev/null
  172. +++ b/sound/soc/bcm/allo-piano-dac.c
  173. @@ -0,0 +1,144 @@
  174. +/*
  175. + * ALSA ASoC Machine Driver for Allo Piano DAC
  176. + *
  177. + * Author: Baswaraj K <jaikumar@cem-solutions.net>
  178. + * Copyright 2016
  179. + * based on code by Daniel Matuschek <info@crazy-audio.com>
  180. + * based on code by Florian Meier <florian.meier@koalo.de>
  181. + *
  182. + * This program is free software; you can redistribute it and/or
  183. + * modify it under the terms of the GNU General Public License
  184. + * version 2 as published by the Free Software Foundation.
  185. + *
  186. + * This program is distributed in the hope that it will be useful, but
  187. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  188. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  189. + * General Public License for more details.
  190. + */
  191. +
  192. +#include <linux/module.h>
  193. +#include <linux/platform_device.h>
  194. +
  195. +#include <sound/core.h>
  196. +#include <sound/pcm.h>
  197. +#include <sound/pcm_params.h>
  198. +#include <sound/soc.h>
  199. +
  200. +static bool digital_gain_0db_limit = true;
  201. +
  202. +static int snd_allo_piano_dac_init(struct snd_soc_pcm_runtime *rtd)
  203. +{
  204. + if (digital_gain_0db_limit) {
  205. + int ret;
  206. + struct snd_soc_card *card = rtd->card;
  207. +
  208. + ret = snd_soc_limit_volume(card, "Digital Playback Volume",
  209. + 207);
  210. + if (ret < 0)
  211. + dev_warn(card->dev, "Failed to set volume limit: %d\n",
  212. + ret);
  213. + }
  214. +
  215. + return 0;
  216. +}
  217. +
  218. +static int snd_allo_piano_dac_hw_params(
  219. + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
  220. +{
  221. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  222. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  223. +
  224. + unsigned int sample_bits =
  225. + snd_pcm_format_physical_width(params_format(params));
  226. +
  227. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  228. +}
  229. +
  230. +/* machine stream operations */
  231. +static struct snd_soc_ops snd_allo_piano_dac_ops = {
  232. + .hw_params = snd_allo_piano_dac_hw_params,
  233. +};
  234. +
  235. +static struct snd_soc_dai_link snd_allo_piano_dac_dai[] = {
  236. +{
  237. + .name = "Piano DAC",
  238. + .stream_name = "Piano DAC HiFi",
  239. + .cpu_dai_name = "bcm2708-i2s.0",
  240. + .codec_dai_name = "pcm512x-hifi",
  241. + .platform_name = "bcm2708-i2s.0",
  242. + .codec_name = "pcm512x.1-004c",
  243. + .dai_fmt = SND_SOC_DAIFMT_I2S |
  244. + SND_SOC_DAIFMT_NB_NF |
  245. + SND_SOC_DAIFMT_CBS_CFS,
  246. + .ops = &snd_allo_piano_dac_ops,
  247. + .init = snd_allo_piano_dac_init,
  248. +},
  249. +};
  250. +
  251. +/* audio machine driver */
  252. +static struct snd_soc_card snd_allo_piano_dac = {
  253. + .name = "PianoDAC",
  254. + .owner = THIS_MODULE,
  255. + .dai_link = snd_allo_piano_dac_dai,
  256. + .num_links = ARRAY_SIZE(snd_allo_piano_dac_dai),
  257. +};
  258. +
  259. +static int snd_allo_piano_dac_probe(struct platform_device *pdev)
  260. +{
  261. + int ret = 0;
  262. +
  263. + snd_allo_piano_dac.dev = &pdev->dev;
  264. +
  265. + if (pdev->dev.of_node) {
  266. + struct device_node *i2s_node;
  267. + struct snd_soc_dai_link *dai;
  268. +
  269. + dai = &snd_allo_piano_dac_dai[0];
  270. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  271. + "i2s-controller", 0);
  272. +
  273. + if (i2s_node) {
  274. + dai->cpu_dai_name = NULL;
  275. + dai->cpu_of_node = i2s_node;
  276. + dai->platform_name = NULL;
  277. + dai->platform_of_node = i2s_node;
  278. + }
  279. +
  280. + digital_gain_0db_limit = !of_property_read_bool(
  281. + pdev->dev.of_node, "allo,24db_digital_gain");
  282. + }
  283. +
  284. + ret = snd_soc_register_card(&snd_allo_piano_dac);
  285. + if (ret)
  286. + dev_err(&pdev->dev,
  287. + "snd_soc_register_card() failed: %d\n", ret);
  288. +
  289. + return ret;
  290. +}
  291. +
  292. +static int snd_allo_piano_dac_remove(struct platform_device *pdev)
  293. +{
  294. + return snd_soc_unregister_card(&snd_allo_piano_dac);
  295. +}
  296. +
  297. +static const struct of_device_id snd_allo_piano_dac_of_match[] = {
  298. + { .compatible = "allo,piano-dac", },
  299. + { /* sentinel */ },
  300. +};
  301. +MODULE_DEVICE_TABLE(of, snd_allo_piano_dac_of_match);
  302. +
  303. +static struct platform_driver snd_allo_piano_dac_driver = {
  304. + .driver = {
  305. + .name = "snd-allo-piano-dac",
  306. + .owner = THIS_MODULE,
  307. + .of_match_table = snd_allo_piano_dac_of_match,
  308. + },
  309. + .probe = snd_allo_piano_dac_probe,
  310. + .remove = snd_allo_piano_dac_remove,
  311. +};
  312. +
  313. +module_platform_driver(snd_allo_piano_dac_driver);
  314. +
  315. +MODULE_AUTHOR("Baswaraj K <jaikumar@cem-solutions.net>");
  316. +MODULE_DESCRIPTION("ALSA ASoC Machine Driver for Allo Piano DAC");
  317. +MODULE_LICENSE("GPL v2");