0084-RaspiDAC3-support.patch 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. From c7773e6daa5df456d6e0b935321425f3cb7a55b8 Mon Sep 17 00:00:00 2001
  2. From: Jan Grulich <jan@grulich.eu>
  3. Date: Mon, 24 Aug 2015 16:03:47 +0100
  4. Subject: [PATCH 084/381] RaspiDAC3 support
  5. Signed-off-by: Jan Grulich <jan@grulich.eu>
  6. config: fix RaspiDAC Rev.3x dependencies
  7. Change depends to SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  8. like the other I2S soundcard drivers.
  9. Signed-off-by: Matthias Reichl <hias@horus.com>
  10. ---
  11. sound/soc/bcm/Kconfig | 8 ++
  12. sound/soc/bcm/Makefile | 2 +
  13. sound/soc/bcm/raspidac3.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++
  14. 3 files changed, 201 insertions(+)
  15. create mode 100644 sound/soc/bcm/raspidac3.c
  16. --- a/sound/soc/bcm/Kconfig
  17. +++ b/sound/soc/bcm/Kconfig
  18. @@ -56,3 +56,11 @@ config SND_BCM2708_SOC_IQAUDIO_DAC
  19. select SND_SOC_PCM512x_I2C
  20. help
  21. Say Y or M if you want to add support for IQaudIO-DAC.
  22. +
  23. +config SND_BCM2708_SOC_RASPIDAC3
  24. + tristate "Support for RaspiDAC Rev.3x"
  25. + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  26. + select SND_SOC_PCM512x_I2C
  27. + select SND_SOC_TPA6130A2
  28. + help
  29. + Say Y or M if you want to add support for RaspiDAC Rev.3x.
  30. --- a/sound/soc/bcm/Makefile
  31. +++ b/sound/soc/bcm/Makefile
  32. @@ -11,6 +11,7 @@ snd-soc-hifiberry-amp-objs := hifiberry_
  33. snd-soc-rpi-dac-objs := rpi-dac.o
  34. snd-soc-rpi-proto-objs := rpi-proto.o
  35. snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  36. +snd-soc-raspidac3-objs := raspidac3.o
  37. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  38. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
  39. @@ -19,3 +20,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_A
  40. obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  41. obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
  42. obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  43. +obj-$(CONFIG_SND_BCM2708_SOC_RASPIDAC3) += snd-soc-raspidac3.o
  44. --- /dev/null
  45. +++ b/sound/soc/bcm/raspidac3.c
  46. @@ -0,0 +1,191 @@
  47. +/*
  48. + * ASoC Driver for RaspiDAC v3
  49. + *
  50. + * Author: Jan Grulich <jan@grulich.eu>
  51. + * Copyright 2015
  52. + * based on code by Daniel Matuschek <daniel@hifiberry.com>
  53. + * based on code by Florian Meier <florian.meier@koalo.de>
  54. + *
  55. + * This program is free software; you can redistribute it and/or
  56. + * modify it under the terms of the GNU General Public License
  57. + * version 2 as published by the Free Software Foundation.
  58. + *
  59. + * This program is distributed in the hope that it will be useful, but
  60. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  61. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  62. + * General Public License for more details.
  63. + */
  64. +
  65. +#include <linux/module.h>
  66. +#include <linux/platform_device.h>
  67. +
  68. +#include <sound/core.h>
  69. +#include <sound/pcm.h>
  70. +#include <sound/pcm_params.h>
  71. +#include <sound/soc.h>
  72. +#include <sound/jack.h>
  73. +#include <sound/soc-dapm.h>
  74. +
  75. +#include "../codecs/pcm512x.h"
  76. +#include "../codecs/tpa6130a2.h"
  77. +
  78. +/* sound card init */
  79. +static int snd_rpi_raspidac3_init(struct snd_soc_pcm_runtime *rtd)
  80. +{
  81. + int ret;
  82. + struct snd_soc_card *card = rtd->card;
  83. + struct snd_soc_codec *codec = rtd->codec;
  84. + snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
  85. + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
  86. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
  87. +
  88. + ret = snd_soc_limit_volume(card, "Digital Playback Volume", 207);
  89. + if (ret < 0)
  90. + dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
  91. + else {
  92. + struct snd_kcontrol *kctl;
  93. +
  94. + ret = tpa6130a2_add_controls(codec);
  95. + if (ret < 0)
  96. + dev_warn(card->dev, "Failed to add TPA6130A2 controls: %d\n",
  97. + ret);
  98. + ret = snd_soc_limit_volume(card,
  99. + "TPA6130A2 Headphone Playback Volume",
  100. + 54);
  101. + if (ret < 0)
  102. + dev_warn(card->dev, "Failed to set TPA6130A2 volume limit: %d\n",
  103. + ret);
  104. + kctl = snd_soc_card_get_kcontrol(card,
  105. + "TPA6130A2 Headphone Playback Volume");
  106. + if (kctl) {
  107. + strcpy(kctl->id.name, "Headphones Playback Volume");
  108. + /* disable the volume dB scale so alsamixer works */
  109. + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
  110. + }
  111. +
  112. + kctl = snd_soc_card_get_kcontrol(card,
  113. + "TPA6130A2 Headphone Playback Switch");
  114. + if (kctl)
  115. + strcpy(kctl->id.name, "Headphones Playback Switch");
  116. + }
  117. +
  118. + return 0;
  119. +}
  120. +
  121. +/* set hw parameters */
  122. +static int snd_rpi_raspidac3_hw_params(struct snd_pcm_substream *substream,
  123. + struct snd_pcm_hw_params *params)
  124. +{
  125. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  126. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  127. +
  128. + unsigned int sample_bits =
  129. + snd_pcm_format_physical_width(params_format(params));
  130. +
  131. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  132. +}
  133. +
  134. +/* startup */
  135. +static int snd_rpi_raspidac3_startup(struct snd_pcm_substream *substream) {
  136. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  137. + struct snd_soc_codec *codec = rtd->codec;
  138. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
  139. + tpa6130a2_stereo_enable(codec, 1);
  140. + return 0;
  141. +}
  142. +
  143. +/* shutdown */
  144. +static void snd_rpi_raspidac3_shutdown(struct snd_pcm_substream *substream) {
  145. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  146. + struct snd_soc_codec *codec = rtd->codec;
  147. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
  148. + tpa6130a2_stereo_enable(codec, 0);
  149. +}
  150. +
  151. +/* machine stream operations */
  152. +static struct snd_soc_ops snd_rpi_raspidac3_ops = {
  153. + .hw_params = snd_rpi_raspidac3_hw_params,
  154. + .startup = snd_rpi_raspidac3_startup,
  155. + .shutdown = snd_rpi_raspidac3_shutdown,
  156. +};
  157. +
  158. +/* interface setup */
  159. +static struct snd_soc_dai_link snd_rpi_raspidac3_dai[] = {
  160. +{
  161. + .name = "RaspiDAC Rev.3x",
  162. + .stream_name = "RaspiDAC HiFi",
  163. + .cpu_dai_name = "bcm2708-i2s.0",
  164. + .codec_dai_name = "pcm512x-hifi",
  165. + .platform_name = "bcm2708-i2s.0",
  166. + .codec_name = "pcm512x.1-004c",
  167. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  168. + SND_SOC_DAIFMT_CBS_CFS,
  169. + .ops = &snd_rpi_raspidac3_ops,
  170. + .init = snd_rpi_raspidac3_init,
  171. +},
  172. +};
  173. +
  174. +/* audio machine driver */
  175. +static struct snd_soc_card snd_rpi_raspidac3 = {
  176. + .name = "RaspiDAC Rev.3x HiFi Audio Card",
  177. + .dai_link = snd_rpi_raspidac3_dai,
  178. + .num_links = ARRAY_SIZE(snd_rpi_raspidac3_dai),
  179. +};
  180. +
  181. +/* sound card test */
  182. +static int snd_rpi_raspidac3_probe(struct platform_device *pdev)
  183. +{
  184. + int ret = 0;
  185. +
  186. + snd_rpi_raspidac3.dev = &pdev->dev;
  187. +
  188. + if (pdev->dev.of_node) {
  189. + struct device_node *i2s_node;
  190. + struct snd_soc_dai_link *dai = &snd_rpi_raspidac3_dai[0];
  191. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  192. + "i2s-controller", 0);
  193. +
  194. + if (i2s_node) {
  195. + dai->cpu_dai_name = NULL;
  196. + dai->cpu_of_node = i2s_node;
  197. + dai->platform_name = NULL;
  198. + dai->platform_of_node = i2s_node;
  199. + }
  200. + }
  201. +
  202. + ret = snd_soc_register_card(&snd_rpi_raspidac3);
  203. + if (ret)
  204. + dev_err(&pdev->dev,
  205. + "snd_soc_register_card() failed: %d\n", ret);
  206. +
  207. + return ret;
  208. +}
  209. +
  210. +/* sound card disconnect */
  211. +static int snd_rpi_raspidac3_remove(struct platform_device *pdev)
  212. +{
  213. + return snd_soc_unregister_card(&snd_rpi_raspidac3);
  214. +}
  215. +
  216. +static const struct of_device_id raspidac3_of_match[] = {
  217. + { .compatible = "jg,raspidacv3", },
  218. + {},
  219. +};
  220. +MODULE_DEVICE_TABLE(of, raspidac3_of_match);
  221. +
  222. +/* sound card platform driver */
  223. +static struct platform_driver snd_rpi_raspidac3_driver = {
  224. + .driver = {
  225. + .name = "snd-rpi-raspidac3",
  226. + .owner = THIS_MODULE,
  227. + .of_match_table = raspidac3_of_match,
  228. + },
  229. + .probe = snd_rpi_raspidac3_probe,
  230. + .remove = snd_rpi_raspidac3_remove,
  231. +};
  232. +
  233. +module_platform_driver(snd_rpi_raspidac3_driver);
  234. +
  235. +MODULE_AUTHOR("Jan Grulich <jan@grulich.eu>");
  236. +MODULE_DESCRIPTION("ASoC Driver for RaspiDAC Rev.3x");
  237. +MODULE_LICENSE("GPL v2");