0241-Add-Support-for-BoomBerry-Audio-boards.patch 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. From d26cb19ea8e7c42a8b53e5a3a377e198c9cce73e Mon Sep 17 00:00:00 2001
  2. From: Aaron Shaw <shawaj@gmail.com>
  3. Date: Thu, 7 Apr 2016 21:26:21 +0100
  4. Subject: [PATCH 241/381] Add Support for BoomBerry Audio boards
  5. ---
  6. arch/arm/boot/dts/overlays/Makefile | 2 +
  7. arch/arm/boot/dts/overlays/README | 26 +++
  8. .../boot/dts/overlays/boomberry-dac-overlay.dts | 43 +++++
  9. .../boot/dts/overlays/boomberry-digi-overlay.dts | 39 ++++
  10. arch/arm/configs/bcm2709_defconfig | 2 +
  11. arch/arm/configs/bcmrpi_defconfig | 2 +
  12. sound/soc/bcm/Kconfig | 14 ++
  13. sound/soc/bcm/Makefile | 4 +
  14. sound/soc/bcm/boomberry-dac.c | 163 ++++++++++++++++
  15. sound/soc/bcm/boomberry-digi.c | 215 +++++++++++++++++++++
  16. 10 files changed, 510 insertions(+)
  17. create mode 100644 arch/arm/boot/dts/overlays/boomberry-dac-overlay.dts
  18. create mode 100644 arch/arm/boot/dts/overlays/boomberry-digi-overlay.dts
  19. create mode 100644 sound/soc/bcm/boomberry-dac.c
  20. create mode 100644 sound/soc/bcm/boomberry-digi.c
  21. --- a/arch/arm/boot/dts/overlays/Makefile
  22. +++ b/arch/arm/boot/dts/overlays/Makefile
  23. @@ -16,6 +16,8 @@ dtbo-$(RPI_DT_OVERLAYS) += ads7846.dtbo
  24. dtbo-$(RPI_DT_OVERLAYS) += akkordion-iqdacplus.dtbo
  25. dtbo-$(RPI_DT_OVERLAYS) += at86rf233.dtbo
  26. dtbo-$(RPI_DT_OVERLAYS) += bmp085_i2c-sensor.dtbo
  27. +dtbo-$(RPI_DT_OVERLAYS) += boomberry-dac.dtbo
  28. +dtbo-$(RPI_DT_OVERLAYS) += boomberry-digi.dtbo
  29. dtbo-$(RPI_DT_OVERLAYS) += dpi24.dtbo
  30. dtbo-$(RPI_DT_OVERLAYS) += dwc2.dtbo
  31. dtbo-$(RPI_DT_OVERLAYS) += dwc-otg.dtbo
  32. --- a/arch/arm/boot/dts/overlays/README
  33. +++ b/arch/arm/boot/dts/overlays/README
  34. @@ -225,6 +225,32 @@ Load: dtoverlay=bmp085_i2c-sensor
  35. Params: <None>
  36. +Name: boomberry-dac
  37. +Info: Configures the BoomBerry DAC HAT, Amp HAT, DAC Zero and Amp Zero audio
  38. + cards
  39. +Load: dtoverlay=boomberry-dac,<param>=<val>
  40. +Params: 24db_digital_gain Allow gain to be applied via the PCM512x codec
  41. + Digital volume control. Enable with
  42. + "dtoverlay=boomberry-dac,24db_digital_gain"
  43. + (The default behaviour is that the Digital
  44. + volume control is limited to a maximum of
  45. + 0dB. ie. it can attenuate but not provide
  46. + gain. For most users, this will be desired
  47. + as it will prevent clipping. By appending
  48. + the 24dB_digital_gain parameter, the Digital
  49. + volume control will allow up to 24dB of
  50. + gain. If this parameter is enabled, it is the
  51. + responsibility of the user to ensure that
  52. + the Digital volume control is set to a value
  53. + that does not result in clipping/distortion!)
  54. +
  55. +
  56. +Name: boomberry-digi
  57. +Info: Configures the BoomBerry Digi HAT and Digi Zero audio cards
  58. +Load: dtoverlay=boomberry-digi
  59. +Params: <None>
  60. +
  61. +
  62. Name: dht11
  63. Info: Overlay for the DHT11/DHT21/DHT22 humidity/temperature sensors
  64. Also sometimes found with the part number(s) AM230x.
  65. --- /dev/null
  66. +++ b/arch/arm/boot/dts/overlays/boomberry-dac-overlay.dts
  67. @@ -0,0 +1,43 @@
  68. +// Definitions for BoomBerry DAC
  69. +/dts-v1/;
  70. +/plugin/;
  71. +
  72. +/ {
  73. + compatible = "brcm,bcm2708";
  74. +
  75. + fragment@0 {
  76. + target = <&sound>;
  77. + frag0: __overlay__ {
  78. + compatible = "boomberry,boomberry-dac";
  79. + i2s-controller = <&i2s>;
  80. + status = "okay";
  81. + };
  82. + };
  83. +
  84. + fragment@1 {
  85. + target = <&i2s>;
  86. + __overlay__ {
  87. + status = "okay";
  88. + };
  89. + };
  90. +
  91. + fragment@2 {
  92. + target = <&i2c1>;
  93. + __overlay__ {
  94. + #address-cells = <1>;
  95. + #size-cells = <0>;
  96. + status = "okay";
  97. +
  98. + pcm5122@4d {
  99. + #sound-dai-cells = <0>;
  100. + compatible = "ti,pcm5122";
  101. + reg = <0x4d>;
  102. + status = "okay";
  103. + };
  104. + };
  105. + };
  106. +
  107. + __overrides__ {
  108. + 24db_digital_gain = <&frag0>,"boomberry,24db_digital_gain?";
  109. + };
  110. +};
  111. --- /dev/null
  112. +++ b/arch/arm/boot/dts/overlays/boomberry-digi-overlay.dts
  113. @@ -0,0 +1,39 @@
  114. +// Definitions for BoomBerry Digi
  115. +/dts-v1/;
  116. +/plugin/;
  117. +
  118. +/ {
  119. + compatible = "brcm,bcm2708";
  120. +
  121. + fragment@0 {
  122. + target = <&sound>;
  123. + __overlay__ {
  124. + compatible = "boomberry,boomberry-digi";
  125. + i2s-controller = <&i2s>;
  126. + status = "okay";
  127. + };
  128. + };
  129. +
  130. + fragment@1 {
  131. + target = <&i2s>;
  132. + __overlay__ {
  133. + status = "okay";
  134. + };
  135. + };
  136. +
  137. + fragment@2 {
  138. + target = <&i2c1>;
  139. + __overlay__ {
  140. + #address-cells = <1>;
  141. + #size-cells = <0>;
  142. + status = "okay";
  143. +
  144. + wm8804@3b {
  145. + #sound-dai-cells = <0>;
  146. + compatible = "wlf,wm8804";
  147. + reg = <0x3b>;
  148. + status = "okay";
  149. + };
  150. + };
  151. + };
  152. +};
  153. --- a/arch/arm/configs/bcm2709_defconfig
  154. +++ b/arch/arm/configs/bcm2709_defconfig
  155. @@ -853,6 +853,8 @@ CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  156. CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
  157. CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  158. CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
  159. +CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
  160. +CONFIG_SNG_BCM2708_SOC_BOOMBERRY_DIGI=m
  161. CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  162. CONFIG_SND_BCM2708_SOC_RPI_PROTO=m
  163. CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  164. --- a/arch/arm/configs/bcmrpi_defconfig
  165. +++ b/arch/arm/configs/bcmrpi_defconfig
  166. @@ -845,6 +845,8 @@ CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  167. CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
  168. CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  169. CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
  170. +CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
  171. +CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI=m
  172. CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  173. CONFIG_SND_BCM2708_SOC_RPI_PROTO=m
  174. CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  175. --- a/sound/soc/bcm/Kconfig
  176. +++ b/sound/soc/bcm/Kconfig
  177. @@ -50,6 +50,20 @@ config SND_BCM2708_SOC_RPI_PROTO
  178. help
  179. Say Y or M if you want to add support for Audio Codec Board PROTO (WM8731).
  180. +config SND_BCM2708_SOC_BOOMBERRY_DAC
  181. + tristate "Support for BoomBerry DAC"
  182. + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  183. + select SND_SOC_PCM512x
  184. + help
  185. + Say Y or M if you want to add support for BoomBerry DAC.
  186. +
  187. +config SND_BCM2708_SOC_BOOMBERRY_DIGI
  188. + tristate "Support for BoomBerry Digi"
  189. + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  190. + select SND_SOC_WM8804
  191. + help
  192. + Say Y or M if you want to add support for BoomBerry Digi.
  193. +
  194. config SND_BCM2708_SOC_IQAUDIO_DAC
  195. tristate "Support for IQaudIO-DAC"
  196. depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  197. --- a/sound/soc/bcm/Makefile
  198. +++ b/sound/soc/bcm/Makefile
  199. @@ -8,6 +8,8 @@ snd-soc-hifiberry-dac-objs := hifiberry_
  200. snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
  201. snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  202. snd-soc-hifiberry-amp-objs := hifiberry_amp.o
  203. +snd-soc-boomberry-dac-objs := boomberry-dac.o
  204. +snd-soc-boomberry-digi-objs := boomberry-digi.o
  205. snd-soc-rpi-dac-objs := rpi-dac.o
  206. snd-soc-rpi-proto-objs := rpi-proto.o
  207. snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  208. @@ -17,6 +19,8 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_D
  209. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
  210. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  211. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
  212. +obj-$(CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC) += snd-soc-boomberry-dac.o
  213. +obj-$(CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI) += snd-soc-boomberry-digi.o
  214. obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  215. obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
  216. obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  217. --- /dev/null
  218. +++ b/sound/soc/bcm/boomberry-dac.c
  219. @@ -0,0 +1,163 @@
  220. +/*
  221. + * ASoC Driver for BoomBerry DAC Raspberry Pi HAT Sound Card
  222. + *
  223. + * Author: Milan Neskovic
  224. + * Copyright 2016
  225. + * based on code by Daniel Matuschek <info@crazy-audio.com>
  226. + * based on code by Florian Meier <florian.meier@koalo.de>
  227. + *
  228. + * This program is free software; you can redistribute it and/or
  229. + * modify it under the terms of the GNU General Public License
  230. + * version 2 as published by the Free Software Foundation.
  231. + *
  232. + * This program is distributed in the hope that it will be useful, but
  233. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  234. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  235. + * General Public License for more details.
  236. + */
  237. +
  238. +#include <linux/module.h>
  239. +#include <linux/platform_device.h>
  240. +
  241. +#include <sound/core.h>
  242. +#include <sound/pcm.h>
  243. +#include <sound/pcm_params.h>
  244. +#include <sound/soc.h>
  245. +#include <sound/jack.h>
  246. +
  247. +#include "../codecs/pcm512x.h"
  248. +
  249. +static bool digital_gain_0db_limit = true;
  250. +
  251. +static int snd_rpi_boomberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  252. +{
  253. + struct snd_soc_codec *codec = rtd->codec;
  254. + snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
  255. + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
  256. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
  257. +
  258. + if (digital_gain_0db_limit)
  259. + {
  260. + int ret;
  261. + struct snd_soc_card *card = rtd->card;
  262. + struct snd_soc_codec *codec = rtd->codec;
  263. +
  264. + ret = snd_soc_limit_volume(codec, "Digital Playback Volume", 207);
  265. + if (ret < 0)
  266. + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
  267. + }
  268. +
  269. + return 0;
  270. +}
  271. +
  272. +static int snd_rpi_boomberry_dac_hw_params(struct snd_pcm_substream *substream,
  273. + struct snd_pcm_hw_params *params)
  274. +{
  275. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  276. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  277. + /*return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);*/
  278. + unsigned int sample_bits =
  279. + snd_pcm_format_physical_width(params_format(params));
  280. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  281. +}
  282. +
  283. +static int snd_rpi_boomberry_dac_startup(struct snd_pcm_substream *substream) {
  284. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  285. + struct snd_soc_codec *codec = rtd->codec;
  286. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
  287. + return 0;
  288. +}
  289. +
  290. +static void snd_rpi_boomberry_dac_shutdown(struct snd_pcm_substream *substream) {
  291. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  292. + struct snd_soc_codec *codec = rtd->codec;
  293. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
  294. +}
  295. +
  296. +/* machine stream operations */
  297. +static struct snd_soc_ops snd_rpi_boomberry_dac_ops = {
  298. + .hw_params = snd_rpi_boomberry_dac_hw_params,
  299. + .startup = snd_rpi_boomberry_dac_startup,
  300. + .shutdown = snd_rpi_boomberry_dac_shutdown,
  301. +};
  302. +
  303. +static struct snd_soc_dai_link snd_rpi_boomberry_dac_dai[] = {
  304. +{
  305. + .name = "BoomBerry DAC",
  306. + .stream_name = "BoomBerry DAC HiFi",
  307. + .cpu_dai_name = "bcm2708-i2s.0",
  308. + .codec_dai_name = "pcm512x-hifi",
  309. + .platform_name = "bcm2708-i2s.0",
  310. + .codec_name = "pcm512x.1-004d",
  311. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  312. + SND_SOC_DAIFMT_CBS_CFS,
  313. + .ops = &snd_rpi_boomberry_dac_ops,
  314. + .init = snd_rpi_boomberry_dac_init,
  315. +},
  316. +};
  317. +
  318. +/* audio machine driver */
  319. +static struct snd_soc_card snd_rpi_boomberry_dac = {
  320. + .name = "snd_rpi_boomberry_dac",
  321. + .owner = THIS_MODULE,
  322. + .dai_link = snd_rpi_boomberry_dac_dai,
  323. + .num_links = ARRAY_SIZE(snd_rpi_boomberry_dac_dai),
  324. +};
  325. +
  326. +static int snd_rpi_boomberry_dac_probe(struct platform_device *pdev)
  327. +{
  328. + int ret = 0;
  329. +
  330. + snd_rpi_boomberry_dac.dev = &pdev->dev;
  331. +
  332. + if (pdev->dev.of_node) {
  333. + struct device_node *i2s_node;
  334. + struct snd_soc_dai_link *dai = &snd_rpi_boomberry_dac_dai[0];
  335. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  336. + "i2s-controller", 0);
  337. +
  338. + if (i2s_node) {
  339. + dai->cpu_dai_name = NULL;
  340. + dai->cpu_of_node = i2s_node;
  341. + dai->platform_name = NULL;
  342. + dai->platform_of_node = i2s_node;
  343. + }
  344. +
  345. + digital_gain_0db_limit = !of_property_read_bool(
  346. + pdev->dev.of_node, "boomberry,24db_digital_gain");
  347. + }
  348. +
  349. + ret = snd_soc_register_card(&snd_rpi_boomberry_dac);
  350. + if (ret)
  351. + dev_err(&pdev->dev,
  352. + "snd_soc_register_card() failed: %d\n", ret);
  353. +
  354. + return ret;
  355. +}
  356. +
  357. +static int snd_rpi_boomberry_dac_remove(struct platform_device *pdev)
  358. +{
  359. + return snd_soc_unregister_card(&snd_rpi_boomberry_dac);
  360. +}
  361. +
  362. +static const struct of_device_id snd_rpi_boomberry_dac_of_match[] = {
  363. + { .compatible = "boomberry,boomberry-dac", },
  364. + {},
  365. +};
  366. +MODULE_DEVICE_TABLE(of, snd_rpi_boomberry_dac_of_match);
  367. +
  368. +static struct platform_driver snd_rpi_boomberry_dac_driver = {
  369. + .driver = {
  370. + .name = "snd-rpi-boomberry-dac",
  371. + .owner = THIS_MODULE,
  372. + .of_match_table = snd_rpi_boomberry_dac_of_match,
  373. + },
  374. + .probe = snd_rpi_boomberry_dac_probe,
  375. + .remove = snd_rpi_boomberry_dac_remove,
  376. +};
  377. +
  378. +module_platform_driver(snd_rpi_boomberry_dac_driver);
  379. +
  380. +MODULE_AUTHOR("Milan Neskovic <info@boomberry.co>");
  381. +MODULE_DESCRIPTION("ASoC Driver for BoomBerry PI DAC HAT Sound Card");
  382. +MODULE_LICENSE("GPL v2");
  383. --- /dev/null
  384. +++ b/sound/soc/bcm/boomberry-digi.c
  385. @@ -0,0 +1,215 @@
  386. +/*
  387. + * ASoC Driver for BoomBerry Raspberry Pi Digi HAT Sound Card
  388. + *
  389. + * Author: Milan Neskovic
  390. + * Copyright 2016
  391. + * based on code by Daniel Matuschek <info@crazy-audio.com>
  392. + * based on code by Florian Meier <florian.meier@koalo.de>
  393. + *
  394. + * This program is free software; you can redistribute it and/or
  395. + * modify it under the terms of the GNU General Public License
  396. + * version 2 as published by the Free Software Foundation.
  397. + *
  398. + * This program is distributed in the hope that it will be useful, but
  399. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  400. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  401. + * General Public License for more details.
  402. + */
  403. +
  404. +#include <linux/module.h>
  405. +#include <linux/platform_device.h>
  406. +
  407. +#include <sound/core.h>
  408. +#include <sound/pcm.h>
  409. +#include <sound/pcm_params.h>
  410. +#include <sound/soc.h>
  411. +#include <sound/jack.h>
  412. +
  413. +#include "../codecs/wm8804.h"
  414. +
  415. +static int snd_rpi_boomberry_digi_init(struct snd_soc_pcm_runtime *rtd)
  416. +{
  417. + struct snd_soc_codec *codec = rtd->codec;
  418. +
  419. + /* enable TX output */
  420. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  421. +
  422. + return 0;
  423. +}
  424. +
  425. +static int snd_rpi_boomberry_digi_startup(struct snd_pcm_substream *substream) {
  426. + /* turn on digital output */
  427. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  428. + struct snd_soc_codec *codec = rtd->codec;
  429. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x00);
  430. + return 0;
  431. +}
  432. +
  433. +static void snd_rpi_boomberry_digi_shutdown(struct snd_pcm_substream *substream) {
  434. + /* turn off output */
  435. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  436. + struct snd_soc_codec *codec = rtd->codec;
  437. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x3c);
  438. +}
  439. +
  440. +static int snd_rpi_boomberry_digi_hw_params(struct snd_pcm_substream *substream,
  441. + struct snd_pcm_hw_params *params)
  442. +{
  443. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  444. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  445. + struct snd_soc_codec *codec = rtd->codec;
  446. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  447. +
  448. + int sysclk = 27000000; /* This is fixed on this board */
  449. +
  450. + long mclk_freq=0;
  451. + int mclk_div=1;
  452. + int sampling_freq=1;
  453. +
  454. + int ret;
  455. +
  456. + int samplerate = params_rate(params);
  457. +
  458. + if (samplerate<=96000) {
  459. + mclk_freq=samplerate*256;
  460. + mclk_div=WM8804_MCLKDIV_256FS;
  461. + } else {
  462. + mclk_freq=samplerate*128;
  463. + mclk_div=WM8804_MCLKDIV_128FS;
  464. + }
  465. +
  466. + switch (samplerate) {
  467. + case 32000:
  468. + sampling_freq=0x03;
  469. + break;
  470. + case 44100:
  471. + sampling_freq=0x00;
  472. + break;
  473. + case 48000:
  474. + sampling_freq=0x02;
  475. + break;
  476. + case 88200:
  477. + sampling_freq=0x08;
  478. + break;
  479. + case 96000:
  480. + sampling_freq=0x0a;
  481. + break;
  482. + case 176400:
  483. + sampling_freq=0x0c;
  484. + break;
  485. + case 192000:
  486. + sampling_freq=0x0e;
  487. + break;
  488. + default:
  489. + dev_err(codec->dev,
  490. + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
  491. + samplerate);
  492. + }
  493. +
  494. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  495. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  496. +
  497. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  498. + sysclk, SND_SOC_CLOCK_OUT);
  499. + if (ret < 0) {
  500. + dev_err(codec->dev,
  501. + "Failed to set WM8804 SYSCLK: %d\n", ret);
  502. + return ret;
  503. + }
  504. +
  505. + /* Enable TX output */
  506. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  507. +
  508. + /* Power on */
  509. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  510. +
  511. + /* set sampling frequency status bits */
  512. + snd_soc_update_bits(codec, WM8804_SPDTX4, 0x0f, sampling_freq);
  513. +
  514. + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
  515. +}
  516. +
  517. +/* machine stream operations */
  518. +static struct snd_soc_ops snd_rpi_boomberry_digi_ops = {
  519. + .hw_params = snd_rpi_boomberry_digi_hw_params,
  520. + .startup = snd_rpi_boomberry_digi_startup,
  521. + .shutdown = snd_rpi_boomberry_digi_shutdown,
  522. +};
  523. +
  524. +static struct snd_soc_dai_link snd_rpi_boomberry_digi_dai[] = {
  525. +{
  526. + .name = "BoomBerry Digi",
  527. + .stream_name = "BoomBerry Digi HiFi",
  528. + .cpu_dai_name = "bcm2708-i2s.0",
  529. + .codec_dai_name = "wm8804-spdif",
  530. + .platform_name = "bcm2708-i2s.0",
  531. + .codec_name = "wm8804.1-003b",
  532. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  533. + SND_SOC_DAIFMT_CBM_CFM,
  534. + .ops = &snd_rpi_boomberry_digi_ops,
  535. + .init = snd_rpi_boomberry_digi_init,
  536. +},
  537. +};
  538. +
  539. +/* audio machine driver */
  540. +static struct snd_soc_card snd_rpi_boomberry_digi = {
  541. + .name = "snd_rpi_boomberry_digi",
  542. + .owner = THIS_MODULE,
  543. + .dai_link = snd_rpi_boomberry_digi_dai,
  544. + .num_links = ARRAY_SIZE(snd_rpi_boomberry_digi_dai),
  545. +};
  546. +
  547. +static int snd_rpi_boomberry_digi_probe(struct platform_device *pdev)
  548. +{
  549. + int ret = 0;
  550. +
  551. + snd_rpi_boomberry_digi.dev = &pdev->dev;
  552. +
  553. + if (pdev->dev.of_node) {
  554. + struct device_node *i2s_node;
  555. + struct snd_soc_dai_link *dai = &snd_rpi_boomberry_digi_dai[0];
  556. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  557. + "i2s-controller", 0);
  558. +
  559. + if (i2s_node) {
  560. + dai->cpu_dai_name = NULL;
  561. + dai->cpu_of_node = i2s_node;
  562. + dai->platform_name = NULL;
  563. + dai->platform_of_node = i2s_node;
  564. + }
  565. + }
  566. +
  567. + ret = snd_soc_register_card(&snd_rpi_boomberry_digi);
  568. + if (ret)
  569. + dev_err(&pdev->dev,
  570. + "snd_soc_register_card() failed: %d\n", ret);
  571. +
  572. + return ret;
  573. +}
  574. +
  575. +static int snd_rpi_boomberry_digi_remove(struct platform_device *pdev)
  576. +{
  577. + return snd_soc_unregister_card(&snd_rpi_boomberry_digi);
  578. +}
  579. +
  580. +static const struct of_device_id snd_rpi_boomberry_digi_of_match[] = {
  581. + { .compatible = "boomberry,boomberry-digi", },
  582. + {},
  583. +};
  584. +MODULE_DEVICE_TABLE(of, snd_rpi_boomberry_digi_of_match);
  585. +
  586. +static struct platform_driver snd_rpi_boomberry_digi_driver = {
  587. + .driver = {
  588. + .name = "snd-rpi-boomberry-digi",
  589. + .owner = THIS_MODULE,
  590. + .of_match_table = snd_rpi_boomberry_digi_of_match,
  591. + },
  592. + .probe = snd_rpi_boomberry_digi_probe,
  593. + .remove = snd_rpi_boomberry_digi_remove,
  594. +};
  595. +
  596. +module_platform_driver(snd_rpi_boomberry_digi_driver);
  597. +
  598. +MODULE_AUTHOR("Milan Neskovic <info@boomberry.co>");
  599. +MODULE_DESCRIPTION("ASoC Driver for BoomBerry PI Digi HAT Sound Card");
  600. +MODULE_LICENSE("GPL v2");