0064-ASoC-Add-support-for-Rpi-DAC.patch 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. From 29c1cff5d670cc4f22eed035c6e584aec967c1b6 Mon Sep 17 00:00:00 2001
  2. From: Florian Meier <florian.meier@koalo.de>
  3. Date: Fri, 22 Nov 2013 19:21:34 +0100
  4. Subject: [PATCH] ASoC: Add support for Rpi-DAC
  5. ---
  6. sound/soc/bcm/Kconfig | 7 +++
  7. sound/soc/bcm/Makefile | 2 +
  8. sound/soc/bcm/rpi-dac.c | 118 ++++++++++++++++++++++++++++++++++++++++++++
  9. sound/soc/codecs/Kconfig | 9 ++++
  10. sound/soc/codecs/Makefile | 2 +
  11. sound/soc/codecs/pcm1794a.c | 69 ++++++++++++++++++++++++++
  12. 6 files changed, 207 insertions(+)
  13. create mode 100644 sound/soc/bcm/rpi-dac.c
  14. create mode 100644 sound/soc/codecs/pcm1794a.c
  15. --- a/sound/soc/bcm/Kconfig
  16. +++ b/sound/soc/bcm/Kconfig
  17. @@ -14,3 +14,10 @@ config SND_BCM2708_SOC_HIFIBERRY_DAC
  18. select SND_SOC_PCM5102A
  19. help
  20. Say Y or M if you want to add support for HifiBerry DAC.
  21. +
  22. +config SND_BCM2708_SOC_RPI_DAC
  23. + tristate "Support for RPi-DAC"
  24. + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  25. + select SND_SOC_PCM1794A
  26. + help
  27. + Say Y or M if you want to add support for RPi-DAC.
  28. --- a/sound/soc/bcm/Makefile
  29. +++ b/sound/soc/bcm/Makefile
  30. @@ -5,5 +5,7 @@ obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd
  31. # BCM2708 Machine Support
  32. snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  33. +snd-soc-rpi-dac-objs := rpi-dac.o
  34. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  35. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  36. --- /dev/null
  37. +++ b/sound/soc/bcm/rpi-dac.c
  38. @@ -0,0 +1,118 @@
  39. +/*
  40. + * ASoC Driver for RPi-DAC.
  41. + *
  42. + * Author: Florian Meier <florian.meier@koalo.de>
  43. + * Copyright 2013
  44. + *
  45. + * This program is free software; you can redistribute it and/or
  46. + * modify it under the terms of the GNU General Public License
  47. + * version 2 as published by the Free Software Foundation.
  48. + *
  49. + * This program is distributed in the hope that it will be useful, but
  50. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  51. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  52. + * General Public License for more details.
  53. + */
  54. +
  55. +#include <linux/module.h>
  56. +#include <linux/platform_device.h>
  57. +
  58. +#include <sound/core.h>
  59. +#include <sound/pcm.h>
  60. +#include <sound/pcm_params.h>
  61. +#include <sound/soc.h>
  62. +#include <sound/jack.h>
  63. +
  64. +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
  65. +{
  66. + return 0;
  67. +}
  68. +
  69. +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
  70. + struct snd_pcm_hw_params *params)
  71. +{
  72. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  73. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  74. +
  75. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
  76. +}
  77. +
  78. +/* machine stream operations */
  79. +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
  80. + .hw_params = snd_rpi_rpi_dac_hw_params,
  81. +};
  82. +
  83. +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
  84. +{
  85. + .name = "RPi-DAC",
  86. + .stream_name = "RPi-DAC HiFi",
  87. + .cpu_dai_name = "bcm2708-i2s.0",
  88. + .codec_dai_name = "pcm1794a-hifi",
  89. + .platform_name = "bcm2708-i2s.0",
  90. + .codec_name = "pcm1794a-codec",
  91. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  92. + SND_SOC_DAIFMT_CBS_CFS,
  93. + .ops = &snd_rpi_rpi_dac_ops,
  94. + .init = snd_rpi_rpi_dac_init,
  95. +},
  96. +};
  97. +
  98. +/* audio machine driver */
  99. +static struct snd_soc_card snd_rpi_rpi_dac = {
  100. + .name = "snd_rpi_rpi_dac",
  101. + .dai_link = snd_rpi_rpi_dac_dai,
  102. + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
  103. +};
  104. +
  105. +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
  106. +{
  107. + int ret = 0;
  108. +
  109. + snd_rpi_rpi_dac.dev = &pdev->dev;
  110. +
  111. + if (pdev->dev.of_node) {
  112. + struct device_node *i2s_node;
  113. + struct snd_soc_dai_link *dai = &snd_rpi_rpi_dac_dai[0];
  114. + i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
  115. +
  116. + if (i2s_node) {
  117. + dai->cpu_dai_name = NULL;
  118. + dai->cpu_of_node = i2s_node;
  119. + dai->platform_name = NULL;
  120. + dai->platform_of_node = i2s_node;
  121. + }
  122. + }
  123. +
  124. + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
  125. + if (ret)
  126. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  127. +
  128. + return ret;
  129. +}
  130. +
  131. +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
  132. +{
  133. + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
  134. +}
  135. +
  136. +static const struct of_device_id snd_rpi_rpi_dac_of_match[] = {
  137. + { .compatible = "rpi,rpi-dac", },
  138. + {},
  139. +};
  140. +MODULE_DEVICE_TABLE(of, snd_rpi_rpi_dac_of_match);
  141. +
  142. +static struct platform_driver snd_rpi_rpi_dac_driver = {
  143. + .driver = {
  144. + .name = "snd-rpi-dac",
  145. + .owner = THIS_MODULE,
  146. + .of_match_table = snd_rpi_rpi_dac_of_match,
  147. + },
  148. + .probe = snd_rpi_rpi_dac_probe,
  149. + .remove = snd_rpi_rpi_dac_remove,
  150. +};
  151. +
  152. +module_platform_driver(snd_rpi_rpi_dac_driver);
  153. +
  154. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  155. +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
  156. +MODULE_LICENSE("GPL v2");
  157. --- a/sound/soc/codecs/Kconfig
  158. +++ b/sound/soc/codecs/Kconfig
  159. @@ -90,6 +90,7 @@ config SND_SOC_ALL_CODECS
  160. select SND_SOC_RT286 if I2C
  161. select SND_SOC_RT298 if I2C
  162. select SND_SOC_PCM5102A if I2C
  163. + select SND_SOC_PCM1794A if I2C
  164. select SND_SOC_RT5631 if I2C
  165. select SND_SOC_RT5640 if I2C
  166. select SND_SOC_RT5645 if I2C
  167. @@ -550,6 +551,14 @@ config SND_SOC_RT298
  168. tristate
  169. depends on I2C
  170. +config SND_SOC_RT298
  171. + tristate
  172. + depends on I2C
  173. +
  174. +config SND_SOC_PCM1794A
  175. + tristate
  176. + depends on I2C
  177. +
  178. config SND_SOC_PCM5102A
  179. tristate
  180. depends on I2C
  181. --- a/sound/soc/codecs/Makefile
  182. +++ b/sound/soc/codecs/Makefile
  183. @@ -85,6 +85,7 @@ snd-soc-rl6231-objs := rl6231.o
  184. snd-soc-rl6347a-objs := rl6347a.o
  185. snd-soc-rt286-objs := rt286.o
  186. snd-soc-rt298-objs := rt298.o
  187. +snd-soc-pcm1794a-objs := pcm1794a.o
  188. snd-soc-pcm5102a-objs := pcm5102a.o
  189. snd-soc-rt5631-objs := rt5631.o
  190. snd-soc-rt5640-objs := rt5640.o
  191. @@ -281,6 +282,7 @@ obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-
  192. obj-$(CONFIG_SND_SOC_RL6347A) += snd-soc-rl6347a.o
  193. obj-$(CONFIG_SND_SOC_RT286) += snd-soc-rt286.o
  194. obj-$(CONFIG_SND_SOC_RT298) += snd-soc-rt298.o
  195. +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
  196. obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
  197. obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
  198. obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
  199. --- /dev/null
  200. +++ b/sound/soc/codecs/pcm1794a.c
  201. @@ -0,0 +1,69 @@
  202. +/*
  203. + * Driver for the PCM1794A codec
  204. + *
  205. + * Author: Florian Meier <florian.meier@koalo.de>
  206. + * Copyright 2013
  207. + *
  208. + * This program is free software; you can redistribute it and/or
  209. + * modify it under the terms of the GNU General Public License
  210. + * version 2 as published by the Free Software Foundation.
  211. + *
  212. + * This program is distributed in the hope that it will be useful, but
  213. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  214. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  215. + * General Public License for more details.
  216. + */
  217. +
  218. +
  219. +#include <linux/init.h>
  220. +#include <linux/module.h>
  221. +#include <linux/platform_device.h>
  222. +
  223. +#include <sound/soc.h>
  224. +
  225. +static struct snd_soc_dai_driver pcm1794a_dai = {
  226. + .name = "pcm1794a-hifi",
  227. + .playback = {
  228. + .channels_min = 2,
  229. + .channels_max = 2,
  230. + .rates = SNDRV_PCM_RATE_8000_192000,
  231. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  232. + SNDRV_PCM_FMTBIT_S24_LE
  233. + },
  234. +};
  235. +
  236. +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
  237. +
  238. +static int pcm1794a_probe(struct platform_device *pdev)
  239. +{
  240. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
  241. + &pcm1794a_dai, 1);
  242. +}
  243. +
  244. +static int pcm1794a_remove(struct platform_device *pdev)
  245. +{
  246. + snd_soc_unregister_codec(&pdev->dev);
  247. + return 0;
  248. +}
  249. +
  250. +static const struct of_device_id pcm1794a_of_match[] = {
  251. + { .compatible = "ti,pcm1794a", },
  252. + { }
  253. +};
  254. +MODULE_DEVICE_TABLE(of, pcm1794a_of_match);
  255. +
  256. +static struct platform_driver pcm1794a_codec_driver = {
  257. + .probe = pcm1794a_probe,
  258. + .remove = pcm1794a_remove,
  259. + .driver = {
  260. + .name = "pcm1794a-codec",
  261. + .owner = THIS_MODULE,
  262. + .of_match_table = of_match_ptr(pcm1794a_of_match),
  263. + },
  264. +};
  265. +
  266. +module_platform_driver(pcm1794a_codec_driver);
  267. +
  268. +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
  269. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  270. +MODULE_LICENSE("GPL v2");