0036-ASoC-BCM2708-Add-support-for-RPi-DAC.patch 8.7 KB

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