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

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