0001-rpi-proto-driver.patch 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. diff -Nur linux-3.12.37.orig/arch/arm/mach-bcm2708/bcm2708.c linux-3.12.37/arch/arm/mach-bcm2708/bcm2708.c
  2. --- linux-3.12.37.orig/arch/arm/mach-bcm2708/bcm2708.c 2015-02-18 14:32:14.988546928 +0100
  3. +++ linux-3.12.37/arch/arm/mach-bcm2708/bcm2708.c 2015-02-18 15:20:32.564560932 +0100
  4. @@ -769,6 +769,19 @@
  5. };
  6. #endif
  7. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_PROTO_MODULE
  8. +static struct platform_device snd_rpi_proto_device = {
  9. + .name = "snd-rpi-proto",
  10. + .id = 0,
  11. + .num_resources = 0,
  12. +};
  13. +static struct i2c_board_info __initdata snd_rpi_proto_i2c_devices[] = {
  14. + {
  15. + I2C_BOARD_INFO("wm8731", 0x1a)
  16. + },
  17. +};
  18. +#endif
  19. +
  20. int __init bcm_register_device(struct platform_device *pdev)
  21. {
  22. int ret;
  23. @@ -944,6 +957,10 @@
  24. bcm_register_device(&snd_rpi_iqaudio_dac_device);
  25. i2c_register_board_info(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
  26. #endif
  27. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_PROTO) || defined(CONFIG_SND_BCM2708_SOC_RPI_PROTO_MODULE)
  28. + bcm_register_device(&snd_rpi_proto_device);
  29. + i2c_register_board_info(1, snd_rpi_proto_i2c_devices, ARRAY_SIZE(snd_rpi_proto_i2c_devices));
  30. +#endif
  31. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  32. diff -Nur linux-3.12.37.orig/sound/soc/bcm/bcm2708-i2s.c linux-3.12.37/sound/soc/bcm/bcm2708-i2s.c
  33. --- linux-3.12.37.orig/sound/soc/bcm/bcm2708-i2s.c 2015-02-18 14:32:15.128546928 +0100
  34. +++ linux-3.12.37/sound/soc/bcm/bcm2708-i2s.c 2015-02-18 15:10:07.452557911 +0100
  35. @@ -171,6 +171,11 @@
  36. /* I2S pin configuration */
  37. static int bcm2708_i2s_gpio=BCM2708_I2S_GPIO_AUTO;
  38. +static bool use_mmap = 1;
  39. +module_param(use_mmap, bool, S_IRUGO);
  40. +MODULE_PARM_DESC(use_mmap, "Use MMAP");
  41. +
  42. +
  43. /* General device struct */
  44. struct bcm2708_i2s_dev {
  45. struct device *dev;
  46. @@ -870,7 +875,7 @@
  47. .name = "bcm2708-i2s-comp",
  48. };
  49. -static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
  50. +static struct snd_pcm_hardware bcm2708_pcm_hardware = {
  51. .info = SNDRV_PCM_INFO_INTERLEAVED |
  52. SNDRV_PCM_INFO_JOINT_DUPLEX,
  53. .formats = SNDRV_PCM_FMTBIT_S16_LE |
  54. @@ -962,6 +967,11 @@
  55. return ret;
  56. }
  57. + if (use_mmap) {
  58. + bcm2708_pcm_hardware.info |= SNDRV_PCM_INFO_MMAP;
  59. + bcm2708_pcm_hardware.info |= SNDRV_PCM_INFO_MMAP_VALID;
  60. + }
  61. +
  62. ret = snd_dmaengine_pcm_register(&pdev->dev,
  63. &bcm2708_dmaengine_pcm_config,
  64. SND_DMAENGINE_PCM_FLAG_COMPAT);
  65. diff -Nur linux-3.12.37.orig/sound/soc/bcm/Kconfig linux-3.12.37/sound/soc/bcm/Kconfig
  66. --- linux-3.12.37.orig/sound/soc/bcm/Kconfig 2015-02-18 14:32:15.128546928 +0100
  67. +++ linux-3.12.37/sound/soc/bcm/Kconfig 2015-02-18 15:18:22.948560306 +0100
  68. @@ -50,3 +50,11 @@
  69. select SND_SOC_PCM512x
  70. help
  71. Say Y or M if you want to add support for IQaudIO-DAC.
  72. +
  73. +config SND_BCM2708_SOC_RPI_PROTO
  74. + tristate "Support for Rpi-PROTO"
  75. + depends on SND_BCM2708_SOC_I2S
  76. + select SND_SOC_WM8731
  77. + help
  78. + Say Y if you want to add support for Audio Codec Board -
  79. + PROTO (WM8731)
  80. diff -Nur linux-3.12.37.orig/sound/soc/bcm/Makefile linux-3.12.37/sound/soc/bcm/Makefile
  81. --- linux-3.12.37.orig/sound/soc/bcm/Makefile 2015-02-18 14:32:15.128546928 +0100
  82. +++ linux-3.12.37/sound/soc/bcm/Makefile 2015-02-18 15:18:39.484560386 +0100
  83. @@ -10,6 +10,7 @@
  84. snd-soc-hifiberry-amp-objs := hifiberry_amp.o
  85. snd-soc-rpi-dac-objs := rpi-dac.o
  86. snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  87. +snd-soc-rpi-proto-objs := rpi-proto.o
  88. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  89. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
  90. @@ -17,3 +18,4 @@
  91. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
  92. obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  93. obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  94. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
  95. diff -Nur linux-3.12.37.orig/sound/soc/bcm/rpi-proto.c linux-3.12.37/sound/soc/bcm/rpi-proto.c
  96. --- linux-3.12.37.orig/sound/soc/bcm/rpi-proto.c 1970-01-01 01:00:00.000000000 +0100
  97. +++ linux-3.12.37/sound/soc/bcm/rpi-proto.c 2015-02-18 15:10:01.164557881 +0100
  98. @@ -0,0 +1,130 @@
  99. +/*
  100. + * ASoC driver for PROTO AudioCODEC (with a WM8731)
  101. + * connected to a Raspberry Pi
  102. + *
  103. + * Author: Florian Meier, <koalo@koalo.de>
  104. + * Copyright 2013
  105. + *
  106. + * This program is free software; you can redistribute it and/or modify
  107. + * it under the terms of the GNU General Public License version 2 as
  108. + * published by the Free Software Foundation.
  109. + */
  110. +
  111. +#include <linux/module.h>
  112. +#include <linux/platform_device.h>
  113. +
  114. +#include <sound/core.h>
  115. +#include <sound/pcm.h>
  116. +#include <sound/soc.h>
  117. +#include <sound/jack.h>
  118. +
  119. +#include "../codecs/wm8731.h"
  120. +
  121. +static const unsigned int wm8731_rates_12288000[] = {
  122. + 8000, 32000, 48000, 96000,
  123. +};
  124. +
  125. +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
  126. + .list = wm8731_rates_12288000,
  127. + .count = ARRAY_SIZE(wm8731_rates_12288000),
  128. +};
  129. +
  130. +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
  131. +{
  132. + /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
  133. + snd_pcm_hw_constraint_list(substream->runtime, 0,
  134. + SNDRV_PCM_HW_PARAM_RATE,
  135. + &wm8731_constraints_12288000);
  136. + return 0;
  137. +}
  138. +
  139. +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
  140. + struct snd_pcm_hw_params *params)
  141. +{
  142. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  143. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  144. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  145. + int sysclk = 12288000; /* This is fixed on this board */
  146. +
  147. + /* Set proto bclk */
  148. + int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
  149. + if (ret < 0){
  150. + dev_err(substream->pcm->dev,
  151. + "Failed to set BCLK ratio %d\n", ret);
  152. + return ret;
  153. + }
  154. +
  155. + /* Set proto sysclk */
  156. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
  157. + sysclk, SND_SOC_CLOCK_IN);
  158. + if (ret < 0) {
  159. + dev_err(substream->pcm->dev,
  160. + "Failed to set WM8731 SYSCLK: %d\n", ret);
  161. + return ret;
  162. + }
  163. +
  164. + return 0;
  165. +}
  166. +
  167. +/* machine stream operations */
  168. +static struct snd_soc_ops snd_rpi_proto_ops = {
  169. + .startup = snd_rpi_proto_startup,
  170. + .hw_params = snd_rpi_proto_hw_params,
  171. +};
  172. +
  173. +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
  174. +{
  175. + .name = "WM8731",
  176. + .stream_name = "WM8731 HiFi",
  177. + .cpu_dai_name = "bcm2708-i2s.0",
  178. + .codec_dai_name = "wm8731-hifi",
  179. + .platform_name = "bcm2708-i2s.0",
  180. + .codec_name = "wm8731.1-001a",
  181. + .dai_fmt = SND_SOC_DAIFMT_I2S
  182. + | SND_SOC_DAIFMT_NB_NF
  183. + | SND_SOC_DAIFMT_CBM_CFM,
  184. + .ops = &snd_rpi_proto_ops,
  185. +},
  186. +};
  187. +
  188. +/* audio machine driver */
  189. +static struct snd_soc_card snd_rpi_proto = {
  190. + .name = "snd_rpi_proto",
  191. + .dai_link = snd_rpi_proto_dai,
  192. + .num_links = ARRAY_SIZE(snd_rpi_proto_dai),
  193. +};
  194. +
  195. +static int snd_rpi_proto_probe(struct platform_device *pdev)
  196. +{
  197. + int ret = 0;
  198. +
  199. + snd_rpi_proto.dev = &pdev->dev;
  200. + ret = snd_soc_register_card(&snd_rpi_proto);
  201. + if (ret) {
  202. + dev_err(&pdev->dev,
  203. + "snd_soc_register_card() failed: %d\n", ret);
  204. + }
  205. +
  206. + return ret;
  207. +}
  208. +
  209. +
  210. +static int snd_rpi_proto_remove(struct platform_device *pdev)
  211. +{
  212. + return snd_soc_unregister_card(&snd_rpi_proto);
  213. +}
  214. +
  215. +static struct platform_driver snd_rpi_proto_driver = {
  216. + .driver = {
  217. + .name = "snd-rpi-proto",
  218. + .owner = THIS_MODULE,
  219. + },
  220. + .probe = snd_rpi_proto_probe,
  221. + .remove = snd_rpi_proto_remove,
  222. +};
  223. +
  224. +module_platform_driver(snd_rpi_proto_driver);
  225. +
  226. +MODULE_AUTHOR("Florian Meier");
  227. +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
  228. +MODULE_LICENSE("GPL");