0371-New-driver-for-RRA-DigiDAC1-soundcard-using-WM8741-W.patch 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. From 46c94fc6017e8a4e768aeb7c4b3d3a40928f1fa6 Mon Sep 17 00:00:00 2001
  2. From: escalator2015 <jmtasende@gmail.com>
  3. Date: Tue, 24 May 2016 16:20:09 +0100
  4. Subject: [PATCH] New driver for RRA DigiDAC1 soundcard using WM8741 + WM8804
  5. ---
  6. arch/arm/boot/dts/overlays/Makefile | 1 +
  7. arch/arm/boot/dts/overlays/README | 6 +
  8. .../overlays/rra-digidac1-wm8741-audio-overlay.dts | 81 ++++
  9. arch/arm/configs/bcm2709_defconfig | 1 +
  10. arch/arm/configs/bcmrpi_defconfig | 1 +
  11. sound/soc/bcm/Kconfig | 8 +
  12. sound/soc/bcm/Makefile | 2 +
  13. sound/soc/bcm/digidac1-soundcard.c | 422 +++++++++++++++++++++
  14. 8 files changed, 522 insertions(+)
  15. create mode 100644 arch/arm/boot/dts/overlays/rra-digidac1-wm8741-audio-overlay.dts
  16. create mode 100644 sound/soc/bcm/digidac1-soundcard.c
  17. --- a/arch/arm/boot/dts/overlays/Makefile
  18. +++ b/arch/arm/boot/dts/overlays/Makefile
  19. @@ -67,6 +67,7 @@ dtbo-$(RPI_DT_OVERLAYS) += rpi-display.d
  20. dtbo-$(RPI_DT_OVERLAYS) += rpi-ft5406.dtbo
  21. dtbo-$(RPI_DT_OVERLAYS) += rpi-proto.dtbo
  22. dtbo-$(RPI_DT_OVERLAYS) += rpi-sense.dtbo
  23. +dtbo-$(RPI_DT_OVERLAYS) += rra-digidac1-wm8741-audio.dtbo
  24. dtbo-$(RPI_DT_OVERLAYS) += sdhost.dtbo
  25. dtbo-$(RPI_DT_OVERLAYS) += sdio.dtbo
  26. dtbo-$(RPI_DT_OVERLAYS) += sdio-1bit.dtbo
  27. --- a/arch/arm/boot/dts/overlays/README
  28. +++ b/arch/arm/boot/dts/overlays/README
  29. @@ -842,6 +842,12 @@ Load: dtoverlay=rpi-sense
  30. Params: <None>
  31. +Name: rra-digidac1-wm8741-audio
  32. +Info: Configures the Red Rocks Audio DigiDAC1 soundcard
  33. +Load: dtoverlay=rra-digidac1-wm8741-audio
  34. +Params: <None>
  35. +
  36. +
  37. Name: sdhost
  38. Info: Selects the bcm2835-sdhost SD/MMC driver, optionally with overclock.
  39. N.B. This overlay is designed for situations where the mmc driver is
  40. --- /dev/null
  41. +++ b/arch/arm/boot/dts/overlays/rra-digidac1-wm8741-audio-overlay.dts
  42. @@ -0,0 +1,81 @@
  43. +// Definitions for RRA DigiDAC1 Audio card
  44. +/dts-v1/;
  45. +/plugin/;
  46. +
  47. +/ {
  48. + compatible = "brcm,bcm2708";
  49. +
  50. + fragment@0 {
  51. + target-path = "/";
  52. + __overlay__ {
  53. + aliases {
  54. + ldo0 = &ldo0;
  55. + ldo1 = &ldo1;
  56. + };
  57. + };
  58. + };
  59. +
  60. + fragment@1 {
  61. + target-path = "/soc";
  62. + __overlay__ {
  63. +
  64. + ldo1: ldo1 {
  65. + compatible = "regulator-fixed";
  66. + regulator-name = "DC_5V";
  67. + regulator-min-microvolt = <5000000>;
  68. + regulator-max-microvolt = <5000000>;
  69. + regulator-always-on;
  70. + };
  71. +
  72. + ldo0: ldo0 {
  73. + compatible = "regulator-fixed";
  74. + regulator-name = "DC_3V3";
  75. + regulator-min-microvolt = <3300000>;
  76. + regulator-max-microvolt = <3300000>;
  77. + regulator-always-on;
  78. + };
  79. + };
  80. + };
  81. +
  82. + fragment@2 {
  83. + target = <&i2s>;
  84. + __overlay__ {
  85. + status = "okay";
  86. + };
  87. + };
  88. +
  89. + fragment@3 {
  90. + target = <&i2c1>;
  91. + __overlay__ {
  92. + #address-cells = <1>;
  93. + #size-cells = <0>;
  94. + status = "okay";
  95. +
  96. + wm8804@3b {
  97. + #sound-dai-cells = <0>;
  98. + compatible = "wlf,wm8804";
  99. + reg = <0x3b>;
  100. + status = "okay";
  101. + PVDD-supply = <&ldo0>;
  102. + DVDD-supply = <&ldo0>;
  103. + };
  104. +
  105. + wm8742: wm8741@1a {
  106. + compatible = "wlf,wm8741";
  107. + reg = <0x1a>;
  108. + status = "okay";
  109. + AVDD-supply = <&ldo1>;
  110. + DVDD-supply = <&ldo0>;
  111. + };
  112. + };
  113. + };
  114. +
  115. + fragment@4 {
  116. + target = <&sound>;
  117. + __overlay__ {
  118. + compatible = "rra,digidac1-soundcard";
  119. + i2s-controller = <&i2s>;
  120. + status = "okay";
  121. + };
  122. + };
  123. +};
  124. --- a/arch/arm/configs/bcm2709_defconfig
  125. +++ b/arch/arm/configs/bcm2709_defconfig
  126. @@ -866,6 +866,7 @@ CONFIG_SND_BCM2708_SOC_JUSTBOOM_DIGI=m
  127. CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  128. CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
  129. CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
  130. +CONFIG_SND_DIGIDAC1_SOUNDCARD=m
  131. CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
  132. CONFIG_SND_SOC_ADAU1701=m
  133. CONFIG_SND_SOC_WM8804_I2C=m
  134. --- a/arch/arm/configs/bcmrpi_defconfig
  135. +++ b/arch/arm/configs/bcmrpi_defconfig
  136. @@ -858,6 +858,7 @@ CONFIG_SND_BCM2708_SOC_JUSTBOOM_DIGI=m
  137. CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  138. CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
  139. CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD=m
  140. +CONFIG_SND_DIGIDAC1_SOUNDCARD=m
  141. CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
  142. CONFIG_SND_SOC_ADAU1701=m
  143. CONFIG_SND_SOC_WM8804_I2C=m
  144. --- a/sound/soc/bcm/Kconfig
  145. +++ b/sound/soc/bcm/Kconfig
  146. @@ -92,3 +92,11 @@ config SND_AUDIOINJECTOR_PI_SOUNDCARD
  147. select SND_SOC_WM8731
  148. help
  149. Say Y or M if you want to add support for audioinjector.net Pi Hat
  150. +
  151. +config SND_DIGIDAC1_SOUNDCARD
  152. + tristate "Support for Red Rocks Audio DigiDAC1"
  153. + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  154. + select SND_SOC_WM8804
  155. + select SND_SOC_WM8741
  156. + help
  157. + Say Y or M if you want to add support for Red Rocks Audio DigiDAC1 board.
  158. --- a/sound/soc/bcm/Makefile
  159. +++ b/sound/soc/bcm/Makefile
  160. @@ -16,6 +16,7 @@ snd-soc-rpi-proto-objs := rpi-proto.o
  161. snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  162. snd-soc-raspidac3-objs := raspidac3.o
  163. snd-soc-audioinjector-pi-soundcard-objs := audioinjector-pi-soundcard.o
  164. +snd-soc-digidac1-soundcard-objs := digidac1-soundcard.o
  165. obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
  166. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  167. @@ -29,4 +30,5 @@ obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO)
  168. obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  169. obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
  170. obj-$(CONFIG_SND_AUDIOINJECTOR_PI_SOUNDCARD) += snd-soc-audioinjector-pi-soundcard.o
  171. +obj-$(CONFIG_SND_DIGIDAC1_SOUNDCARD) += snd-soc-digidac1-soundcard.o
  172. --- /dev/null
  173. +++ b/sound/soc/bcm/digidac1-soundcard.c
  174. @@ -0,0 +1,422 @@
  175. +/*
  176. + * ASoC Driver for RRA DigiDAC1
  177. + * Copyright 2016
  178. + * Author: José M. Tasende <vintage@redrocksaudio.es>
  179. + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
  180. + * and the Wolfson card driver by Nikesh Oswal, <Nikesh.Oswal@wolfsonmicro.com>
  181. + * This program is free software; you can redistribute it and/or
  182. + * modify it under the terms of the GNU General Public License
  183. + * version 2 as published by the Free Software Foundation.
  184. + *
  185. + * This program is distributed in the hope that it will be useful, but
  186. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  187. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  188. + * General Public License for more details.
  189. + */
  190. +
  191. +#include <linux/module.h>
  192. +#include <linux/platform_device.h>
  193. +#include <linux/i2c.h>
  194. +#include <sound/core.h>
  195. +#include <sound/pcm.h>
  196. +#include <sound/pcm_params.h>
  197. +#include <sound/soc.h>
  198. +#include <sound/jack.h>
  199. +#include <sound/soc-dapm.h>
  200. +#include <sound/tlv.h>
  201. +#include <linux/regulator/consumer.h>
  202. +
  203. +#include "../codecs/wm8804.h"
  204. +#include "../codecs/wm8741.h"
  205. +
  206. +#define WM8741_NUM_SUPPLIES 2
  207. +
  208. +/* codec private data */
  209. +struct wm8741_priv {
  210. + struct wm8741_platform_data pdata;
  211. + struct regmap *regmap;
  212. + struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES];
  213. + unsigned int sysclk;
  214. + const struct snd_pcm_hw_constraint_list *sysclk_constraints;
  215. +};
  216. +
  217. +static int samplerate = 44100;
  218. +
  219. +/* New Alsa Controls not exposed by original wm8741 codec driver */
  220. +/* in actual driver the att. adjustment is wrong because */
  221. +/* this DAC has a coarse attenuation register with 4dB steps */
  222. +/* and a fine level register with 0.125dB steps */
  223. +/* each register has 32 steps so combining both we have 1024 steps */
  224. +/* of 0.125 dB. */
  225. +/* The original level controls from driver are removed at startup */
  226. +/* and replaced by the corrected ones. */
  227. +/* The same wm8741 driver can be used for wm8741 and wm8742 devices */
  228. +
  229. +static const DECLARE_TLV_DB_SCALE(dac_tlv_fine, 0, 13, 0);
  230. +static const DECLARE_TLV_DB_SCALE(dac_tlv_coarse, -12700, 400, 1);
  231. +static const char *w8741_dither[4] = {"Off", "RPDF", "TPDF", "HPDF"};
  232. +static const char *w8741_filter[5] = {
  233. + "Type 1", "Type 2", "Type 3", "Type 4", "Type 5"};
  234. +static const char *w8741_switch[2] = {"Off", "On"};
  235. +static const struct soc_enum w8741_enum[] = {
  236. +SOC_ENUM_SINGLE(WM8741_MODE_CONTROL_2, 0, 4, w8741_dither),/* dithering type */
  237. +SOC_ENUM_SINGLE(WM8741_FILTER_CONTROL, 0, 5, w8741_filter),/* filter type */
  238. +SOC_ENUM_SINGLE(WM8741_FORMAT_CONTROL, 6, 2, w8741_switch),/* phase invert */
  239. +SOC_ENUM_SINGLE(WM8741_VOLUME_CONTROL, 0, 2, w8741_switch),/* volume ramp */
  240. +SOC_ENUM_SINGLE(WM8741_VOLUME_CONTROL, 3, 2, w8741_switch),/* soft mute */
  241. +};
  242. +
  243. +static const struct snd_kcontrol_new w8741_snd_controls_stereo[] = {
  244. +SOC_DOUBLE_R_TLV("DAC Fine Playback Volume", WM8741_DACLLSB_ATTENUATION,
  245. + WM8741_DACRLSB_ATTENUATION, 0, 31, 1, dac_tlv_fine),
  246. +SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8741_DACLMSB_ATTENUATION,
  247. + WM8741_DACRMSB_ATTENUATION, 0, 31, 1, dac_tlv_coarse),
  248. +SOC_ENUM("DAC Dither", w8741_enum[0]),
  249. +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
  250. +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
  251. +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
  252. +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
  253. +};
  254. +
  255. +static const struct snd_kcontrol_new w8741_snd_controls_mono_left[] = {
  256. +SOC_SINGLE_TLV("DAC Fine Playback Volume", WM8741_DACLLSB_ATTENUATION,
  257. + 0, 31, 0, dac_tlv_fine),
  258. +SOC_SINGLE_TLV("Digital Playback Volume", WM8741_DACLMSB_ATTENUATION,
  259. + 0, 31, 1, dac_tlv_coarse),
  260. +SOC_ENUM("DAC Dither", w8741_enum[0]),
  261. +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
  262. +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
  263. +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
  264. +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
  265. +};
  266. +
  267. +static const struct snd_kcontrol_new w8741_snd_controls_mono_right[] = {
  268. +SOC_SINGLE_TLV("DAC Fine Playback Volume", WM8741_DACRLSB_ATTENUATION,
  269. + 0, 31, 0, dac_tlv_fine),
  270. +SOC_SINGLE_TLV("Digital Playback Volume", WM8741_DACRMSB_ATTENUATION,
  271. + 0, 31, 1, dac_tlv_coarse),
  272. +SOC_ENUM("DAC Dither", w8741_enum[0]),
  273. +SOC_ENUM("DAC Digital Filter", w8741_enum[1]),
  274. +SOC_ENUM("DAC Phase Invert", w8741_enum[2]),
  275. +SOC_ENUM("DAC Volume Ramp", w8741_enum[3]),
  276. +SOC_ENUM("DAC Soft Mute", w8741_enum[4]),
  277. +};
  278. +
  279. +static int w8741_add_controls(struct snd_soc_codec *codec)
  280. +{
  281. + struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
  282. +
  283. + switch (wm8741->pdata.diff_mode) {
  284. + case WM8741_DIFF_MODE_STEREO:
  285. + case WM8741_DIFF_MODE_STEREO_REVERSED:
  286. + snd_soc_add_codec_controls(codec,
  287. + w8741_snd_controls_stereo,
  288. + ARRAY_SIZE(w8741_snd_controls_stereo));
  289. + break;
  290. + case WM8741_DIFF_MODE_MONO_LEFT:
  291. + snd_soc_add_codec_controls(codec,
  292. + w8741_snd_controls_mono_left,
  293. + ARRAY_SIZE(w8741_snd_controls_mono_left));
  294. + break;
  295. + case WM8741_DIFF_MODE_MONO_RIGHT:
  296. + snd_soc_add_codec_controls(codec,
  297. + w8741_snd_controls_mono_right,
  298. + ARRAY_SIZE(w8741_snd_controls_mono_right));
  299. + break;
  300. + default:
  301. + return -EINVAL;
  302. + }
  303. +
  304. + return 0;
  305. +}
  306. +
  307. +static int digidac1_soundcard_init(struct snd_soc_pcm_runtime *rtd)
  308. +{
  309. + struct snd_soc_codec *codec = rtd->codec;
  310. + struct snd_soc_card *card = rtd->card;
  311. + struct snd_soc_pcm_runtime *wm8741_rtd;
  312. + struct snd_soc_codec *wm8741_codec;
  313. + struct snd_card *sound_card = card->snd_card;
  314. + struct snd_kcontrol *kctl;
  315. + int ret;
  316. +
  317. + wm8741_rtd = snd_soc_get_pcm_runtime(card, card->dai_link[1].name);
  318. + if (!wm8741_rtd) {
  319. + dev_warn(card->dev, "digidac1_soundcard_init: couldn't get wm8741 rtd\n");
  320. + return -EFAULT;
  321. + }
  322. + wm8741_codec = wm8741_rtd->codec;
  323. + ret = w8741_add_controls(wm8741_codec);
  324. + if (ret < 0)
  325. + dev_warn(card->dev, "Failed to add new wm8741 controls: %d\n",
  326. + ret);
  327. +
  328. + /* enable TX output */
  329. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  330. +
  331. + kctl = snd_soc_card_get_kcontrol(card,
  332. + "Playback Volume");
  333. + if (kctl) {
  334. + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
  335. + snd_ctl_remove(sound_card, kctl);
  336. + }
  337. + kctl = snd_soc_card_get_kcontrol(card,
  338. + "Fine Playback Volume");
  339. + if (kctl) {
  340. + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
  341. + snd_ctl_remove(sound_card, kctl);
  342. + }
  343. + return 0;
  344. +}
  345. +
  346. +static int digidac1_soundcard_startup(struct snd_pcm_substream *substream)
  347. +{
  348. + /* turn on wm8804 digital output */
  349. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  350. + struct snd_soc_codec *codec = rtd->codec;
  351. + struct snd_soc_card *card = rtd->card;
  352. + struct snd_soc_pcm_runtime *wm8741_rtd;
  353. + struct snd_soc_codec *wm8741_codec;
  354. +
  355. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x00);
  356. + wm8741_rtd = snd_soc_get_pcm_runtime(card, card->dai_link[1].name);
  357. + if (!wm8741_rtd) {
  358. + dev_warn(card->dev, "digidac1_soundcard_startup: couldn't get WM8741 rtd\n");
  359. + return -EFAULT;
  360. + }
  361. + wm8741_codec = wm8741_rtd->codec;
  362. +
  363. + /* latch wm8741 level */
  364. + snd_soc_update_bits(wm8741_codec, WM8741_DACLLSB_ATTENUATION,
  365. + WM8741_UPDATELL, WM8741_UPDATELL);
  366. + snd_soc_update_bits(wm8741_codec, WM8741_DACLMSB_ATTENUATION,
  367. + WM8741_UPDATELM, WM8741_UPDATELM);
  368. + snd_soc_update_bits(wm8741_codec, WM8741_DACRLSB_ATTENUATION,
  369. + WM8741_UPDATERL, WM8741_UPDATERL);
  370. + snd_soc_update_bits(wm8741_codec, WM8741_DACRMSB_ATTENUATION,
  371. + WM8741_UPDATERM, WM8741_UPDATERM);
  372. +
  373. + return 0;
  374. +}
  375. +
  376. +static void digidac1_soundcard_shutdown(struct snd_pcm_substream *substream)
  377. +{
  378. + /* turn off wm8804 digital output */
  379. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  380. + struct snd_soc_codec *codec = rtd->codec;
  381. +
  382. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x3c, 0x3c);
  383. +}
  384. +
  385. +static int digidac1_soundcard_hw_params(struct snd_pcm_substream *substream,
  386. + struct snd_pcm_hw_params *params)
  387. +{
  388. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  389. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  390. + struct snd_soc_codec *codec = rtd->codec;
  391. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  392. + struct snd_soc_card *card = rtd->card;
  393. + struct snd_soc_pcm_runtime *wm8741_rtd;
  394. + struct snd_soc_codec *wm8741_codec;
  395. +
  396. + int sysclk = 27000000;
  397. + long mclk_freq = 0;
  398. + int mclk_div = 1;
  399. + int sampling_freq = 1;
  400. + int ret;
  401. +
  402. + wm8741_rtd = snd_soc_get_pcm_runtime(card, card->dai_link[1].name);
  403. + if (!wm8741_rtd) {
  404. + dev_warn(card->dev, "digidac1_soundcard_hw_params: couldn't get WM8741 rtd\n");
  405. + return -EFAULT;
  406. + }
  407. + wm8741_codec = wm8741_rtd->codec;
  408. + samplerate = params_rate(params);
  409. +
  410. + if (samplerate <= 96000) {
  411. + mclk_freq = samplerate*256;
  412. + mclk_div = WM8804_MCLKDIV_256FS;
  413. + } else {
  414. + mclk_freq = samplerate*128;
  415. + mclk_div = WM8804_MCLKDIV_128FS;
  416. + }
  417. +
  418. + switch (samplerate) {
  419. + case 32000:
  420. + sampling_freq = 0x03;
  421. + break;
  422. + case 44100:
  423. + sampling_freq = 0x00;
  424. + break;
  425. + case 48000:
  426. + sampling_freq = 0x02;
  427. + break;
  428. + case 88200:
  429. + sampling_freq = 0x08;
  430. + break;
  431. + case 96000:
  432. + sampling_freq = 0x0a;
  433. + break;
  434. + case 176400:
  435. + sampling_freq = 0x0c;
  436. + break;
  437. + case 192000:
  438. + sampling_freq = 0x0e;
  439. + break;
  440. + default:
  441. + dev_err(codec->dev,
  442. + "Failed to set WM8804 SYSCLK, unsupported samplerate %d\n",
  443. + samplerate);
  444. + }
  445. +
  446. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  447. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  448. +
  449. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  450. + sysclk, SND_SOC_CLOCK_OUT);
  451. + if (ret < 0) {
  452. + dev_err(codec->dev,
  453. + "Failed to set WM8804 SYSCLK: %d\n", ret);
  454. + return ret;
  455. + }
  456. + /* Enable wm8804 TX output */
  457. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  458. +
  459. + /* wm8804 Power on */
  460. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  461. +
  462. + /* wm8804 set sampling frequency status bits */
  463. + snd_soc_update_bits(codec, WM8804_SPDTX4, 0x0f, sampling_freq);
  464. +
  465. + /* Now update wm8741 registers for the correct oversampling */
  466. + if (samplerate <= 48000)
  467. + snd_soc_update_bits(wm8741_codec, WM8741_MODE_CONTROL_1,
  468. + WM8741_OSR_MASK, 0x00);
  469. + else if (samplerate <= 96000)
  470. + snd_soc_update_bits(wm8741_codec, WM8741_MODE_CONTROL_1,
  471. + WM8741_OSR_MASK, 0x20);
  472. + else
  473. + snd_soc_update_bits(wm8741_codec, WM8741_MODE_CONTROL_1,
  474. + WM8741_OSR_MASK, 0x40);
  475. +
  476. + /* wm8741 bit size */
  477. + switch (params_width(params)) {
  478. + case 16:
  479. + snd_soc_update_bits(wm8741_codec, WM8741_FORMAT_CONTROL,
  480. + WM8741_IWL_MASK, 0x00);
  481. + break;
  482. + case 20:
  483. + snd_soc_update_bits(wm8741_codec, WM8741_FORMAT_CONTROL,
  484. + WM8741_IWL_MASK, 0x01);
  485. + break;
  486. + case 24:
  487. + snd_soc_update_bits(wm8741_codec, WM8741_FORMAT_CONTROL,
  488. + WM8741_IWL_MASK, 0x02);
  489. + break;
  490. + case 32:
  491. + snd_soc_update_bits(wm8741_codec, WM8741_FORMAT_CONTROL,
  492. + WM8741_IWL_MASK, 0x03);
  493. + break;
  494. + default:
  495. + dev_dbg(codec->dev, "wm8741_hw_params: Unsupported bit size param = %d",
  496. + params_width(params));
  497. + return -EINVAL;
  498. + }
  499. +
  500. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
  501. +}
  502. +/* machine stream operations */
  503. +static struct snd_soc_ops digidac1_soundcard_ops = {
  504. + .hw_params = digidac1_soundcard_hw_params,
  505. + .startup = digidac1_soundcard_startup,
  506. + .shutdown = digidac1_soundcard_shutdown,
  507. +};
  508. +
  509. +static struct snd_soc_dai_link digidac1_soundcard_dai[] = {
  510. + {
  511. + .name = "RRA DigiDAC1",
  512. + .stream_name = "RRA DigiDAC1 HiFi",
  513. + .cpu_dai_name = "bcm2708-i2s.0",
  514. + .codec_dai_name = "wm8804-spdif",
  515. + .platform_name = "bcm2708-i2s.0",
  516. + .codec_name = "wm8804.1-003b",
  517. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  518. + SND_SOC_DAIFMT_CBM_CFM,
  519. + .ops = &digidac1_soundcard_ops,
  520. + .init = digidac1_soundcard_init,
  521. + },
  522. + {
  523. + .name = "RRA DigiDAC11",
  524. + .stream_name = "RRA DigiDAC11 HiFi",
  525. + .cpu_dai_name = "wm8804-spdif",
  526. + .codec_dai_name = "wm8741",
  527. + .codec_name = "wm8741.1-001a",
  528. + .dai_fmt = SND_SOC_DAIFMT_I2S
  529. + | SND_SOC_DAIFMT_NB_NF
  530. + | SND_SOC_DAIFMT_CBS_CFS,
  531. + },
  532. +};
  533. +
  534. +/* audio machine driver */
  535. +static struct snd_soc_card digidac1_soundcard = {
  536. + .name = "digidac1-soundcard",
  537. + .owner = THIS_MODULE,
  538. + .dai_link = digidac1_soundcard_dai,
  539. + .num_links = ARRAY_SIZE(digidac1_soundcard_dai),
  540. +};
  541. +
  542. +static int digidac1_soundcard_probe(struct platform_device *pdev)
  543. +{
  544. + int ret = 0;
  545. +
  546. + digidac1_soundcard.dev = &pdev->dev;
  547. +
  548. + if (pdev->dev.of_node) {
  549. + struct device_node *i2s_node;
  550. + struct snd_soc_dai_link *dai = &digidac1_soundcard_dai[0];
  551. +
  552. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  553. + "i2s-controller", 0);
  554. +
  555. + if (i2s_node) {
  556. + dai->cpu_dai_name = NULL;
  557. + dai->cpu_of_node = i2s_node;
  558. + dai->platform_name = NULL;
  559. + dai->platform_of_node = i2s_node;
  560. + }
  561. + }
  562. +
  563. + ret = snd_soc_register_card(&digidac1_soundcard);
  564. + if (ret)
  565. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  566. + ret);
  567. +
  568. + return ret;
  569. +}
  570. +
  571. +static int digidac1_soundcard_remove(struct platform_device *pdev)
  572. +{
  573. + return snd_soc_unregister_card(&digidac1_soundcard);
  574. +}
  575. +
  576. +static const struct of_device_id digidac1_soundcard_of_match[] = {
  577. + { .compatible = "rra,digidac1-soundcard", },
  578. + {},
  579. +};
  580. +MODULE_DEVICE_TABLE(of, digidac1_soundcard_of_match);
  581. +
  582. +static struct platform_driver digidac1_soundcard_driver = {
  583. + .driver = {
  584. + .name = "digidac1-audio",
  585. + .owner = THIS_MODULE,
  586. + .of_match_table = digidac1_soundcard_of_match,
  587. + },
  588. + .probe = digidac1_soundcard_probe,
  589. + .remove = digidac1_soundcard_remove,
  590. +};
  591. +
  592. +module_platform_driver(digidac1_soundcard_driver);
  593. +
  594. +MODULE_AUTHOR("José M. Tasende <vintage@redrocksaudio.es>");
  595. +MODULE_DESCRIPTION("ASoC Driver for RRA DigiDAC1");
  596. +MODULE_LICENSE("GPL v2");