950-0067-ASoC-Add-support-for-Rpi-DAC.patch 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. From 3a890b43d08fbfe10895f733578f095a6449ba0b Mon Sep 17 00:00:00 2001
  2. From: Florian Meier <[email protected]>
  3. Date: Mon, 25 Jan 2016 15:48:59 +0000
  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 | 119 ++++++++++++++++++++++++++++++++++++++++++++
  9. sound/soc/codecs/Kconfig | 5 ++
  10. sound/soc/codecs/Makefile | 2 +
  11. sound/soc/codecs/pcm1794a.c | 69 +++++++++++++++++++++++++
  12. 6 files changed, 204 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. @@ -23,3 +23,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. @@ -10,5 +10,7 @@ obj-$(CONFIG_SND_SOC_CYGNUS) += snd-soc-
  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,119 @@
  39. +/*
  40. + * ASoC Driver for RPi-DAC.
  41. + *
  42. + * Author: Florian Meier <[email protected]>
  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. + .owner = THIS_MODULE,
  102. + .dai_link = snd_rpi_rpi_dac_dai,
  103. + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
  104. +};
  105. +
  106. +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
  107. +{
  108. + int ret = 0;
  109. +
  110. + snd_rpi_rpi_dac.dev = &pdev->dev;
  111. +
  112. + if (pdev->dev.of_node) {
  113. + struct device_node *i2s_node;
  114. + struct snd_soc_dai_link *dai = &snd_rpi_rpi_dac_dai[0];
  115. + i2s_node = of_parse_phandle(pdev->dev.of_node, "i2s-controller", 0);
  116. +
  117. + if (i2s_node) {
  118. + dai->cpu_dai_name = NULL;
  119. + dai->cpu_of_node = i2s_node;
  120. + dai->platform_name = NULL;
  121. + dai->platform_of_node = i2s_node;
  122. + }
  123. + }
  124. +
  125. + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
  126. + if (ret)
  127. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  128. +
  129. + return ret;
  130. +}
  131. +
  132. +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
  133. +{
  134. + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
  135. +}
  136. +
  137. +static const struct of_device_id snd_rpi_rpi_dac_of_match[] = {
  138. + { .compatible = "rpi,rpi-dac", },
  139. + {},
  140. +};
  141. +MODULE_DEVICE_TABLE(of, snd_rpi_rpi_dac_of_match);
  142. +
  143. +static struct platform_driver snd_rpi_rpi_dac_driver = {
  144. + .driver = {
  145. + .name = "snd-rpi-dac",
  146. + .owner = THIS_MODULE,
  147. + .of_match_table = snd_rpi_rpi_dac_of_match,
  148. + },
  149. + .probe = snd_rpi_rpi_dac_probe,
  150. + .remove = snd_rpi_rpi_dac_remove,
  151. +};
  152. +
  153. +module_platform_driver(snd_rpi_rpi_dac_driver);
  154. +
  155. +MODULE_AUTHOR("Florian Meier <[email protected]>");
  156. +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
  157. +MODULE_LICENSE("GPL v2");
  158. --- a/sound/soc/codecs/Kconfig
  159. +++ b/sound/soc/codecs/Kconfig
  160. @@ -98,6 +98,7 @@ config SND_SOC_ALL_CODECS
  161. select SND_SOC_PCM1681 if I2C
  162. select SND_SOC_PCM179X_I2C if I2C
  163. select SND_SOC_PCM179X_SPI if SPI_MASTER
  164. + select SND_SOC_PCM1794A if I2C
  165. select SND_SOC_PCM3008
  166. select SND_SOC_PCM3168A_I2C if I2C
  167. select SND_SOC_PCM3168A_SPI if SPI_MASTER
  168. @@ -689,6 +690,10 @@ config SND_SOC_RT5616
  169. tristate "Realtek RT5616 CODEC"
  170. depends on I2C
  171. +config SND_SOC_PCM1794A
  172. + tristate
  173. + depends on I2C
  174. +
  175. config SND_SOC_RT5631
  176. tristate "Realtek ALC5631/RT5631 CODEC"
  177. depends on I2C
  178. --- a/sound/soc/codecs/Makefile
  179. +++ b/sound/soc/codecs/Makefile
  180. @@ -93,6 +93,7 @@ snd-soc-pcm1681-objs := pcm1681.o
  181. snd-soc-pcm179x-codec-objs := pcm179x.o
  182. snd-soc-pcm179x-i2c-objs := pcm179x-i2c.o
  183. snd-soc-pcm179x-spi-objs := pcm179x-spi.o
  184. +snd-soc-pcm1794a-objs := pcm1794a.o
  185. snd-soc-pcm3008-objs := pcm3008.o
  186. snd-soc-pcm3168a-objs := pcm3168a.o
  187. snd-soc-pcm3168a-i2c-objs := pcm3168a-i2c.o
  188. @@ -325,6 +326,7 @@ obj-$(CONFIG_SND_SOC_PCM5102A) += snd-so
  189. obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
  190. obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o
  191. obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o
  192. +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
  193. obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o
  194. obj-$(CONFIG_SND_SOC_RL6347A) += snd-soc-rl6347a.o
  195. obj-$(CONFIG_SND_SOC_RT286) += snd-soc-rt286.o
  196. --- /dev/null
  197. +++ b/sound/soc/codecs/pcm1794a.c
  198. @@ -0,0 +1,69 @@
  199. +/*
  200. + * Driver for the PCM1794A codec
  201. + *
  202. + * Author: Florian Meier <[email protected]>
  203. + * Copyright 2013
  204. + *
  205. + * This program is free software; you can redistribute it and/or
  206. + * modify it under the terms of the GNU General Public License
  207. + * version 2 as published by the Free Software Foundation.
  208. + *
  209. + * This program is distributed in the hope that it will be useful, but
  210. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  211. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  212. + * General Public License for more details.
  213. + */
  214. +
  215. +
  216. +#include <linux/init.h>
  217. +#include <linux/module.h>
  218. +#include <linux/platform_device.h>
  219. +
  220. +#include <sound/soc.h>
  221. +
  222. +static struct snd_soc_dai_driver pcm1794a_dai = {
  223. + .name = "pcm1794a-hifi",
  224. + .playback = {
  225. + .channels_min = 2,
  226. + .channels_max = 2,
  227. + .rates = SNDRV_PCM_RATE_8000_192000,
  228. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  229. + SNDRV_PCM_FMTBIT_S24_LE
  230. + },
  231. +};
  232. +
  233. +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
  234. +
  235. +static int pcm1794a_probe(struct platform_device *pdev)
  236. +{
  237. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
  238. + &pcm1794a_dai, 1);
  239. +}
  240. +
  241. +static int pcm1794a_remove(struct platform_device *pdev)
  242. +{
  243. + snd_soc_unregister_codec(&pdev->dev);
  244. + return 0;
  245. +}
  246. +
  247. +static const struct of_device_id pcm1794a_of_match[] = {
  248. + { .compatible = "ti,pcm1794a", },
  249. + { }
  250. +};
  251. +MODULE_DEVICE_TABLE(of, pcm1794a_of_match);
  252. +
  253. +static struct platform_driver pcm1794a_codec_driver = {
  254. + .probe = pcm1794a_probe,
  255. + .remove = pcm1794a_remove,
  256. + .driver = {
  257. + .name = "pcm1794a-codec",
  258. + .owner = THIS_MODULE,
  259. + .of_match_table = of_match_ptr(pcm1794a_of_match),
  260. + },
  261. +};
  262. +
  263. +module_platform_driver(pcm1794a_codec_driver);
  264. +
  265. +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
  266. +MODULE_AUTHOR("Florian Meier <[email protected]>");
  267. +MODULE_LICENSE("GPL v2");