0417-Add-IQAudIO-Digi-WM8804-board-support.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. From 6fac57fc7d9e04a6f5083897b2f424cb3505dbf7 Mon Sep 17 00:00:00 2001
  2. From: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
  3. Date: Thu, 30 Jun 2016 18:38:42 +0100
  4. Subject: [PATCH] Add IQAudIO Digi WM8804 board support
  5. Support IQAudIO Digi board with iqaudio_digi machine driver and
  6. iqaudio-digi-wm8804-audio overlay.
  7. NB. Machine driver is a cut and paste of hifiberry_digi code, with format
  8. and general cleanup to comply with kernel coding standards.
  9. Signed-off-by: DigitalDreamtime <clive.messer@digitaldreamtime.co.uk>
  10. ---
  11. arch/arm/boot/dts/overlays/Makefile | 1 +
  12. arch/arm/boot/dts/overlays/README | 9 +
  13. .../overlays/iqaudio-digi-wm8804-audio-overlay.dts | 47 ++++
  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 | 2 +
  18. sound/soc/bcm/iqaudio_digi.c | 239 +++++++++++++++++++++
  19. 8 files changed, 307 insertions(+)
  20. create mode 100644 arch/arm/boot/dts/overlays/iqaudio-digi-wm8804-audio-overlay.dts
  21. create mode 100644 sound/soc/bcm/iqaudio_digi.c
  22. --- a/arch/arm/boot/dts/overlays/Makefile
  23. +++ b/arch/arm/boot/dts/overlays/Makefile
  24. @@ -42,6 +42,7 @@ dtbo-$(RPI_DT_OVERLAYS) += i2s-gpio28-31
  25. dtbo-$(RPI_DT_OVERLAYS) += i2s-mmap.dtbo
  26. dtbo-$(RPI_DT_OVERLAYS) += iqaudio-dac.dtbo
  27. dtbo-$(RPI_DT_OVERLAYS) += iqaudio-dacplus.dtbo
  28. +dtbo-$(RPI_DT_OVERLAYS) += iqaudio-digi-wm8804-audio.dtbo
  29. dtbo-$(RPI_DT_OVERLAYS) += justboom-dac.dtbo
  30. dtbo-$(RPI_DT_OVERLAYS) += justboom-digi.dtbo
  31. dtbo-$(RPI_DT_OVERLAYS) += lirc-rpi.dtbo
  32. --- a/arch/arm/boot/dts/overlays/README
  33. +++ b/arch/arm/boot/dts/overlays/README
  34. @@ -546,6 +546,15 @@ Params: 24db_digital_gain Allow ga
  35. the DAC driver module loads.
  36. +Name: iqaudio-digi-wm8804-audio
  37. +Info: Configures the IQAudIO Digi WM8804 audio card
  38. +Load: dtoverlay=iqaudio-digi-wm8804-audio,<param>=<val>
  39. +Params: card_name Override the default, "IQAudIODigi", card name.
  40. + dai_name Override the default, "IQAudIO Digi", dai name.
  41. + dai_stream_name Override the default, "IQAudIO Digi HiFi",
  42. + dai stream name.
  43. +
  44. +
  45. Name: justboom-dac
  46. Info: Configures the JustBoom DAC HAT, Amp HAT, DAC Zero and Amp Zero audio
  47. cards
  48. --- /dev/null
  49. +++ b/arch/arm/boot/dts/overlays/iqaudio-digi-wm8804-audio-overlay.dts
  50. @@ -0,0 +1,47 @@
  51. +// Definitions for IQAudIO Digi WM8804 audio board
  52. +/dts-v1/;
  53. +/plugin/;
  54. +
  55. +/ {
  56. + compatible = "brcm,bcm2708";
  57. +
  58. + fragment@0 {
  59. + target = <&i2s>;
  60. + __overlay__ {
  61. + status = "okay";
  62. + };
  63. + };
  64. +
  65. + fragment@1 {
  66. + target = <&i2c1>;
  67. + __overlay__ {
  68. + #address-cells = <1>;
  69. + #size-cells = <0>;
  70. + status = "okay";
  71. +
  72. + wm8804@3b {
  73. + #sound-dai-cells = <0>;
  74. + compatible = "wlf,wm8804";
  75. + reg = <0x3b>;
  76. + status = "okay";
  77. + // DVDD-supply = <&reg_3v3>;
  78. + // PVDD-supply = <&reg_3v3>;
  79. + };
  80. + };
  81. + };
  82. +
  83. + fragment@2 {
  84. + target = <&sound>;
  85. + wm8804_digi: __overlay__ {
  86. + compatible = "iqaudio,wm8804-digi";
  87. + i2s-controller = <&i2s>;
  88. + status = "okay";
  89. + };
  90. + };
  91. +
  92. + __overrides__ {
  93. + card_name = <&wm8804_digi>,"wm8804-digi,card-name";
  94. + dai_name = <&wm8804_digi>,"wm8804-digi,dai-name";
  95. + dai_stream_name = <&wm8804_digi>,"wm8804-digi,dai-stream-name";
  96. + };
  97. +};
  98. --- a/arch/arm/configs/bcm2709_defconfig
  99. +++ b/arch/arm/configs/bcm2709_defconfig
  100. @@ -865,6 +865,7 @@ CONFIG_SND_BCM2708_SOC_RPI_PROTO=m
  101. CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC=m
  102. CONFIG_SND_BCM2708_SOC_JUSTBOOM_DIGI=m
  103. CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  104. +CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI=m
  105. CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
  106. CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
  107. CONFIG_SND_DIGIDAC1_SOUNDCARD=m
  108. --- a/arch/arm/configs/bcmrpi_defconfig
  109. +++ b/arch/arm/configs/bcmrpi_defconfig
  110. @@ -857,6 +857,7 @@ CONFIG_SND_BCM2708_SOC_RPI_PROTO=m
  111. CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC=m
  112. CONFIG_SND_BCM2708_SOC_JUSTBOOM_DIGI=m
  113. CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  114. +CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI=m
  115. CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
  116. CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
  117. CONFIG_SND_DIGIDAC1_SOUNDCARD=m
  118. --- a/sound/soc/bcm/Kconfig
  119. +++ b/sound/soc/bcm/Kconfig
  120. @@ -71,6 +71,13 @@ config SND_BCM2708_SOC_IQAUDIO_DAC
  121. help
  122. Say Y or M if you want to add support for IQaudIO-DAC.
  123. +config SND_BCM2708_SOC_IQAUDIO_DIGI
  124. + tristate "Support for IQAudIO Digi"
  125. + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  126. + select SND_SOC_WM8804
  127. + help
  128. + Say Y or M if you want to add support for IQAudIO Digital IO board.
  129. +
  130. config SND_BCM2708_SOC_RASPIDAC3
  131. tristate "Support for RaspiDAC Rev.3x"
  132. depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  133. --- a/sound/soc/bcm/Makefile
  134. +++ b/sound/soc/bcm/Makefile
  135. @@ -14,6 +14,7 @@ snd-soc-justboom-digi-objs := justboom-d
  136. snd-soc-rpi-dac-objs := rpi-dac.o
  137. snd-soc-rpi-proto-objs := rpi-proto.o
  138. snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  139. +snd-soc-iqaudio-digi-objs := iqaudio_digi.o
  140. snd-soc-raspidac3-objs := raspidac3.o
  141. snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
  142. snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
  143. @@ -28,6 +29,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DI
  144. obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  145. obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
  146. obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  147. +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DIGI) += snd-soc-iqaudio-digi.o
  148. obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
  149. obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
  150. obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
  151. --- /dev/null
  152. +++ b/sound/soc/bcm/iqaudio_digi.c
  153. @@ -0,0 +1,239 @@
  154. +/*
  155. + * ASoC Driver for IQAudIO WM8804 Digi
  156. + *
  157. + * Author: Daniel Matuschek <info@crazy-audio.com>
  158. + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
  159. + * Copyright 2013
  160. + *
  161. + * This program is free software; you can redistribute it and/or
  162. + * modify it under the terms of the GNU General Public License
  163. + * version 2 as published by the Free Software Foundation.
  164. + *
  165. + * This program is distributed in the hope that it will be useful, but
  166. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  167. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  168. + * General Public License for more details.
  169. + */
  170. +
  171. +#include <linux/module.h>
  172. +#include <linux/platform_device.h>
  173. +
  174. +#include <sound/core.h>
  175. +#include <sound/pcm.h>
  176. +#include <sound/pcm_params.h>
  177. +#include <sound/soc.h>
  178. +#include <sound/jack.h>
  179. +
  180. +#include "../codecs/wm8804.h"
  181. +
  182. +static short int auto_shutdown_output;
  183. +module_param(auto_shutdown_output, short,
  184. + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  185. +MODULE_PARM_DESC(auto_shutdown_output, "Shutdown SP/DIF output if playback is stopped");
  186. +
  187. +static int snd_rpi_iqaudio_digi_init(struct snd_soc_pcm_runtime *rtd)
  188. +{
  189. + struct snd_soc_codec *codec = rtd->codec;
  190. +
  191. + /* enable TX output */
  192. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  193. +
  194. + return 0;
  195. +}
  196. +
  197. +static int snd_rpi_iqaudio_digi_startup(struct snd_pcm_substream *substream)
  198. +{
  199. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  200. + struct snd_soc_codec *codec = rtd->codec;
  201. +
  202. + /* turn on digital output */
  203. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x00);
  204. +
  205. + return 0;
  206. +}
  207. +
  208. +static void snd_rpi_iqaudio_digi_shutdown(struct snd_pcm_substream *substream)
  209. +{
  210. + if (auto_shutdown_output) {
  211. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  212. + struct snd_soc_codec *codec = rtd->codec;
  213. +
  214. + /* turn off digital output */
  215. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x3c);
  216. + }
  217. +}
  218. +
  219. +
  220. +static int snd_rpi_iqaudio_digi_hw_params(struct snd_pcm_substream *substream,
  221. + struct snd_pcm_hw_params *params)
  222. +{
  223. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  224. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  225. + struct snd_soc_codec *codec = rtd->codec;
  226. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  227. +
  228. + int sysclk = 27000000; /* This is fixed on this board */
  229. +
  230. + long mclk_freq = 0;
  231. + int mclk_div = 1;
  232. + int sampling_freq = 1;
  233. +
  234. + int ret;
  235. +
  236. + int samplerate = params_rate(params);
  237. +
  238. + if (samplerate <= 96000) {
  239. + mclk_freq = samplerate * 256;
  240. + mclk_div = WM8804_MCLKDIV_256FS;
  241. + } else {
  242. + mclk_freq = samplerate * 128;
  243. + mclk_div = WM8804_MCLKDIV_128FS;
  244. + }
  245. +
  246. + switch (samplerate) {
  247. + case 32000:
  248. + sampling_freq = 0x03;
  249. + break;
  250. + case 44100:
  251. + sampling_freq = 0x00;
  252. + break;
  253. + case 48000:
  254. + sampling_freq = 0x02;
  255. + break;
  256. + case 88200:
  257. + sampling_freq = 0x08;
  258. + break;
  259. + case 96000:
  260. + sampling_freq = 0x0a;
  261. + break;
  262. + case 176400:
  263. + sampling_freq = 0x0c;
  264. + break;
  265. + case 192000:
  266. + sampling_freq = 0x0e;
  267. + break;
  268. + default:
  269. + dev_err(codec->dev, "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
  270. + samplerate);
  271. + }
  272. +
  273. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  274. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  275. +
  276. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  277. + sysclk, SND_SOC_CLOCK_OUT);
  278. + if (ret < 0) {
  279. + dev_err(codec->dev, "Failed to set WM8804 SYSCLK: %d\n", ret);
  280. + return ret;
  281. + }
  282. +
  283. + /* Enable TX output */
  284. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  285. +
  286. + /* Power on */
  287. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  288. +
  289. + /* set sampling frequency status bits */
  290. + snd_soc_update_bits(codec, WM8804_SPDTX4, 0x0f, sampling_freq);
  291. +
  292. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
  293. +}
  294. +
  295. +/* machine stream operations */
  296. +static struct snd_soc_ops snd_rpi_iqaudio_digi_ops = {
  297. + .hw_params = snd_rpi_iqaudio_digi_hw_params,
  298. + .startup = snd_rpi_iqaudio_digi_startup,
  299. + .shutdown = snd_rpi_iqaudio_digi_shutdown,
  300. +};
  301. +
  302. +static struct snd_soc_dai_link snd_rpi_iqaudio_digi_dai[] = {
  303. +{
  304. + .name = "IQAudIO Digi",
  305. + .stream_name = "IQAudIO Digi HiFi",
  306. + .cpu_dai_name = "bcm2708-i2s.0",
  307. + .codec_dai_name = "wm8804-spdif",
  308. + .platform_name = "bcm2708-i2s.0",
  309. + .codec_name = "wm8804.1-003b",
  310. + .dai_fmt = SND_SOC_DAIFMT_I2S |
  311. + SND_SOC_DAIFMT_NB_NF |
  312. + SND_SOC_DAIFMT_CBM_CFM,
  313. + .ops = &snd_rpi_iqaudio_digi_ops,
  314. + .init = snd_rpi_iqaudio_digi_init,
  315. +},
  316. +};
  317. +
  318. +/* audio machine driver */
  319. +static struct snd_soc_card snd_rpi_iqaudio_digi = {
  320. + .name = "IQAudIODigi",
  321. + .owner = THIS_MODULE,
  322. + .dai_link = snd_rpi_iqaudio_digi_dai,
  323. + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_digi_dai),
  324. +};
  325. +
  326. +static int snd_rpi_iqaudio_digi_probe(struct platform_device *pdev)
  327. +{
  328. + struct snd_soc_card *card = &snd_rpi_iqaudio_digi;
  329. + char *prefix = "wm8804-digi,";
  330. + char prop[128];
  331. + struct device_node *np;
  332. + int ret = 0;
  333. +
  334. + snd_rpi_iqaudio_digi.dev = &pdev->dev;
  335. +
  336. + np = pdev->dev.of_node;
  337. + if (np) {
  338. + struct snd_soc_dai_link *dai = &snd_rpi_iqaudio_digi_dai[0];
  339. + struct device_node *i2s_node;
  340. +
  341. + i2s_node = of_parse_phandle(np, "i2s-controller", 0);
  342. + if (i2s_node) {
  343. + dai->cpu_dai_name = NULL;
  344. + dai->cpu_of_node = i2s_node;
  345. + dai->platform_name = NULL;
  346. + dai->platform_of_node = i2s_node;
  347. + }
  348. +
  349. + snprintf(prop, sizeof(prop), "%scard-name", prefix);
  350. + of_property_read_string(np, prop, &card->name);
  351. +
  352. + snprintf(prop, sizeof(prop), "%sdai-name", prefix);
  353. + of_property_read_string(np, prop, &dai->name);
  354. +
  355. + snprintf(prop, sizeof(prop), "%sdai-stream-name", prefix);
  356. + of_property_read_string(np, prop, &dai->stream_name);
  357. + }
  358. +
  359. + ret = snd_soc_register_card(card);
  360. + if (ret)
  361. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  362. + ret);
  363. +
  364. + return ret;
  365. +}
  366. +
  367. +static int snd_rpi_iqaudio_digi_remove(struct platform_device *pdev)
  368. +{
  369. + return snd_soc_unregister_card(&snd_rpi_iqaudio_digi);
  370. +}
  371. +
  372. +static const struct of_device_id snd_rpi_iqaudio_digi_of_match[] = {
  373. + { .compatible = "iqaudio,wm8804-digi", },
  374. + {},
  375. +};
  376. +MODULE_DEVICE_TABLE(of, snd_rpi_iqaudio_digi_of_match);
  377. +
  378. +static struct platform_driver snd_rpi_iqaudio_digi_driver = {
  379. + .driver = {
  380. + .name = "IQAudIODigi",
  381. + .owner = THIS_MODULE,
  382. + .of_match_table = snd_rpi_iqaudio_digi_of_match,
  383. + },
  384. + .probe = snd_rpi_iqaudio_digi_probe,
  385. + .remove = snd_rpi_iqaudio_digi_remove,
  386. +};
  387. +
  388. +module_platform_driver(snd_rpi_iqaudio_digi_driver);
  389. +
  390. +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
  391. +MODULE_DESCRIPTION("ASoC Driver for IQAudIO WM8804 Digi");
  392. +MODULE_LICENSE("GPL v2");