950-0076-RaspiDAC3-support.patch 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. From b545537294ffc7e21fcc5e0c78ea8ac20c9ecd3f Mon Sep 17 00:00:00 2001
  2. From: Jan Grulich <[email protected]>
  3. Date: Mon, 24 Aug 2015 16:03:47 +0100
  4. Subject: [PATCH] RaspiDAC3 support
  5. Signed-off-by: Jan Grulich <[email protected]>
  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 <[email protected]>
  10. ---
  11. sound/soc/bcm/Kconfig | 8 ++
  12. sound/soc/bcm/Makefile | 2 +
  13. sound/soc/bcm/raspidac3.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++
  14. 3 files changed, 196 insertions(+)
  15. create mode 100644 sound/soc/bcm/raspidac3.c
  16. --- a/sound/soc/bcm/Kconfig
  17. +++ b/sound/soc/bcm/Kconfig
  18. @@ -65,3 +65,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. @@ -16,6 +16,7 @@ snd-soc-hifiberry-digi-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_AMP) += snd-soc-hifiberry-amp.o
  38. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  39. @@ -24,3 +25,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_D
  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,186 @@
  47. +/*
  48. + * ASoC Driver for RaspiDAC v3
  49. + *
  50. + * Author: Jan Grulich <[email protected]>
  51. + * Copyright 2015
  52. + * based on code by Daniel Matuschek <[email protected]>
  53. + * based on code by Florian Meier <[email protected]>
  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 = snd_soc_limit_volume(card,
  95. + "TPA6130A2 Headphone Playback Volume",
  96. + 54);
  97. + if (ret < 0)
  98. + dev_warn(card->dev, "Failed to set TPA6130A2 volume limit: %d\n",
  99. + ret);
  100. + kctl = snd_soc_card_get_kcontrol(card,
  101. + "TPA6130A2 Headphone Playback Volume");
  102. + if (kctl) {
  103. + strcpy(kctl->id.name, "Headphones Playback Volume");
  104. + /* disable the volume dB scale so alsamixer works */
  105. + kctl->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
  106. + }
  107. +
  108. + kctl = snd_soc_card_get_kcontrol(card,
  109. + "TPA6130A2 Headphone Playback Switch");
  110. + if (kctl)
  111. + strcpy(kctl->id.name, "Headphones Playback Switch");
  112. + }
  113. +
  114. + return 0;
  115. +}
  116. +
  117. +/* set hw parameters */
  118. +static int snd_rpi_raspidac3_hw_params(struct snd_pcm_substream *substream,
  119. + struct snd_pcm_hw_params *params)
  120. +{
  121. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  122. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  123. +
  124. + unsigned int sample_bits =
  125. + snd_pcm_format_physical_width(params_format(params));
  126. +
  127. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  128. +}
  129. +
  130. +/* startup */
  131. +static int snd_rpi_raspidac3_startup(struct snd_pcm_substream *substream) {
  132. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  133. + struct snd_soc_codec *codec = rtd->codec;
  134. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
  135. + return 0;
  136. +}
  137. +
  138. +/* shutdown */
  139. +static void snd_rpi_raspidac3_shutdown(struct snd_pcm_substream *substream) {
  140. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  141. + struct snd_soc_codec *codec = rtd->codec;
  142. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
  143. +}
  144. +
  145. +/* machine stream operations */
  146. +static struct snd_soc_ops snd_rpi_raspidac3_ops = {
  147. + .hw_params = snd_rpi_raspidac3_hw_params,
  148. + .startup = snd_rpi_raspidac3_startup,
  149. + .shutdown = snd_rpi_raspidac3_shutdown,
  150. +};
  151. +
  152. +/* interface setup */
  153. +static struct snd_soc_dai_link snd_rpi_raspidac3_dai[] = {
  154. +{
  155. + .name = "RaspiDAC Rev.3x",
  156. + .stream_name = "RaspiDAC HiFi",
  157. + .cpu_dai_name = "bcm2708-i2s.0",
  158. + .codec_dai_name = "pcm512x-hifi",
  159. + .platform_name = "bcm2708-i2s.0",
  160. + .codec_name = "pcm512x.1-004c",
  161. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  162. + SND_SOC_DAIFMT_CBS_CFS,
  163. + .ops = &snd_rpi_raspidac3_ops,
  164. + .init = snd_rpi_raspidac3_init,
  165. +},
  166. +};
  167. +
  168. +/* audio machine driver */
  169. +static struct snd_soc_card snd_rpi_raspidac3 = {
  170. + .name = "RaspiDAC Rev.3x HiFi Audio Card",
  171. + .owner = THIS_MODULE,
  172. + .dai_link = snd_rpi_raspidac3_dai,
  173. + .num_links = ARRAY_SIZE(snd_rpi_raspidac3_dai),
  174. +};
  175. +
  176. +/* sound card test */
  177. +static int snd_rpi_raspidac3_probe(struct platform_device *pdev)
  178. +{
  179. + int ret = 0;
  180. +
  181. + snd_rpi_raspidac3.dev = &pdev->dev;
  182. +
  183. + if (pdev->dev.of_node) {
  184. + struct device_node *i2s_node;
  185. + struct snd_soc_dai_link *dai = &snd_rpi_raspidac3_dai[0];
  186. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  187. + "i2s-controller", 0);
  188. +
  189. + if (i2s_node) {
  190. + dai->cpu_dai_name = NULL;
  191. + dai->cpu_of_node = i2s_node;
  192. + dai->platform_name = NULL;
  193. + dai->platform_of_node = i2s_node;
  194. + }
  195. + }
  196. +
  197. + ret = snd_soc_register_card(&snd_rpi_raspidac3);
  198. + if (ret)
  199. + dev_err(&pdev->dev,
  200. + "snd_soc_register_card() failed: %d\n", ret);
  201. +
  202. + return ret;
  203. +}
  204. +
  205. +/* sound card disconnect */
  206. +static int snd_rpi_raspidac3_remove(struct platform_device *pdev)
  207. +{
  208. + return snd_soc_unregister_card(&snd_rpi_raspidac3);
  209. +}
  210. +
  211. +static const struct of_device_id raspidac3_of_match[] = {
  212. + { .compatible = "jg,raspidacv3", },
  213. + {},
  214. +};
  215. +MODULE_DEVICE_TABLE(of, raspidac3_of_match);
  216. +
  217. +/* sound card platform driver */
  218. +static struct platform_driver snd_rpi_raspidac3_driver = {
  219. + .driver = {
  220. + .name = "snd-rpi-raspidac3",
  221. + .owner = THIS_MODULE,
  222. + .of_match_table = raspidac3_of_match,
  223. + },
  224. + .probe = snd_rpi_raspidac3_probe,
  225. + .remove = snd_rpi_raspidac3_remove,
  226. +};
  227. +
  228. +module_platform_driver(snd_rpi_raspidac3_driver);
  229. +
  230. +MODULE_AUTHOR("Jan Grulich <[email protected]>");
  231. +MODULE_DESCRIPTION("ASoC Driver for RaspiDAC Rev.3x");
  232. +MODULE_LICENSE("GPL v2");