0042-Add-IQaudIO-Sound-Card-support-for-Raspberry-Pi.patch 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. From 19b5aa63015268ce3c736b720e1e7f8211f7cf98 Mon Sep 17 00:00:00 2001
  2. From: Gordon Garrity <gordon@iqaudio.com>
  3. Date: Sat, 8 Mar 2014 16:56:57 +0000
  4. Subject: [PATCH 042/114] Add IQaudIO Sound Card support for Raspberry Pi
  5. ---
  6. arch/arm/configs/bcmrpi_defconfig | 1 +
  7. arch/arm/mach-bcm2708/bcm2708.c | 22 ++++++++
  8. sound/soc/bcm/Kconfig | 7 +++
  9. sound/soc/bcm/Makefile | 2 +
  10. sound/soc/bcm/iqaudio-dac.c | 111 ++++++++++++++++++++++++++++++++++++++
  11. 5 files changed, 143 insertions(+)
  12. create mode 100644 sound/soc/bcm/iqaudio-dac.c
  13. --- a/arch/arm/configs/bcmrpi_defconfig
  14. +++ b/arch/arm/configs/bcmrpi_defconfig
  15. @@ -758,6 +758,7 @@ CONFIG_SND_BCM2708_SOC_I2S=m
  16. CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  17. CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  18. CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  19. +CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  20. CONFIG_SND_SIMPLE_CARD=m
  21. CONFIG_SOUND_PRIME=m
  22. CONFIG_HIDRAW=y
  23. --- a/arch/arm/mach-bcm2708/bcm2708.c
  24. +++ b/arch/arm/mach-bcm2708/bcm2708.c
  25. @@ -652,6 +652,22 @@ static struct platform_device snd_pcm179
  26. };
  27. #endif
  28. +
  29. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  30. +static struct platform_device snd_rpi_iqaudio_dac_device = {
  31. + .name = "snd-rpi-iqaudio-dac",
  32. + .id = 0,
  33. + .num_resources = 0,
  34. +};
  35. +
  36. +// Use the actual device name rather than generic driver name
  37. +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
  38. + {
  39. + I2C_BOARD_INFO("pcm5122", 0x4c)
  40. + },
  41. +};
  42. +#endif
  43. +
  44. int __init bcm_register_device(struct platform_device *pdev)
  45. {
  46. int ret;
  47. @@ -791,6 +807,12 @@ void __init bcm2708_init(void)
  48. bcm_register_device(&snd_pcm1794a_codec_device);
  49. #endif
  50. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  51. + bcm_register_device(&snd_rpi_iqaudio_dac_device);
  52. + i2c_register_board_info(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
  53. +#endif
  54. +
  55. +
  56. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  57. struct amba_device *d = amba_devs[i];
  58. amba_device_register(d, &iomem_resource);
  59. --- a/sound/soc/bcm/Kconfig
  60. +++ b/sound/soc/bcm/Kconfig
  61. @@ -39,3 +39,10 @@ config SND_BCM2708_SOC_RPI_DAC
  62. select SND_SOC_PCM1794A
  63. help
  64. Say Y or M if you want to add support for RPi-DAC.
  65. +
  66. +config SND_BCM2708_SOC_IQAUDIO_DAC
  67. + tristate "Support for IQaudIO-DAC"
  68. + depends on SND_BCM2708_SOC_I2S
  69. + select SND_SOC_PCM512x_I2C
  70. + help
  71. + Say Y or M if you want to add support for IQaudIO-DAC.
  72. --- a/sound/soc/bcm/Makefile
  73. +++ b/sound/soc/bcm/Makefile
  74. @@ -12,7 +12,9 @@ obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd
  75. snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  76. snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  77. snd-soc-rpi-dac-objs := rpi-dac.o
  78. +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  79. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  80. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  81. obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  82. +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  83. --- /dev/null
  84. +++ b/sound/soc/bcm/iqaudio-dac.c
  85. @@ -0,0 +1,111 @@
  86. +/*
  87. + * ASoC Driver for IQaudIO 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_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
  112. +{
  113. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  114. +
  115. + return 0;
  116. +}
  117. +
  118. +static int snd_rpi_iqaudio_dac_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. +// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai;
  123. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  124. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  125. +
  126. + unsigned int sample_bits =
  127. + snd_pcm_format_physical_width(params_format(params));
  128. +
  129. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  130. +}
  131. +
  132. +/* machine stream operations */
  133. +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = {
  134. + .hw_params = snd_rpi_iqaudio_dac_hw_params,
  135. +};
  136. +
  137. +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
  138. +{
  139. + .name = "IQaudIO DAC",
  140. + .stream_name = "IQaudIO DAC HiFi",
  141. + .cpu_dai_name = "bcm2708-i2s.0",
  142. + .codec_dai_name = "pcm512x-hifi",
  143. + .platform_name = "bcm2708-i2s.0",
  144. + .codec_name = "pcm512x.1-004c",
  145. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  146. + SND_SOC_DAIFMT_CBS_CFS,
  147. + .ops = &snd_rpi_iqaudio_dac_ops,
  148. + .init = snd_rpi_iqaudio_dac_init,
  149. +},
  150. +};
  151. +
  152. +/* audio machine driver */
  153. +static struct snd_soc_card snd_rpi_iqaudio_dac = {
  154. + .name = "IQaudIODAC",
  155. + .dai_link = snd_rpi_iqaudio_dac_dai,
  156. + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
  157. +};
  158. +
  159. +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
  160. +{
  161. + int ret = 0;
  162. +
  163. + snd_rpi_iqaudio_dac.dev = &pdev->dev;
  164. + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
  165. + if (ret)
  166. + dev_err(&pdev->dev,
  167. + "snd_soc_register_card() failed: %d\n", ret);
  168. +
  169. + return ret;
  170. +}
  171. +
  172. +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
  173. +{
  174. + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
  175. +}
  176. +
  177. +static const struct of_device_id iqaudio_of_match[] = {
  178. + { .compatible = "iqaudio,iqaudio-dac", },
  179. + {},
  180. +};
  181. +
  182. +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
  183. + .driver = {
  184. + .name = "snd-rpi-iqaudio-dac",
  185. + .owner = THIS_MODULE,
  186. + .of_match_table = iqaudio_of_match,
  187. + },
  188. + .probe = snd_rpi_iqaudio_dac_probe,
  189. + .remove = snd_rpi_iqaudio_dac_remove,
  190. +};
  191. +
  192. +module_platform_driver(snd_rpi_iqaudio_dac_driver);
  193. +
  194. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  195. +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
  196. +MODULE_LICENSE("GPL v2");