0001-add-support-for-rpi-proto-driver.patch 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. From 70449ef0fb20c168dd341e9bd02dd1929554971c Mon Sep 17 00:00:00 2001
  2. From: Waldemar Brodkorb <wbrodkorb@conet.de>
  3. Date: Wed, 29 Oct 2014 16:30:53 +0100
  4. Subject: [PATCH 1/2] add support for rpi-proto driver
  5. Forward port of 3.10.x driver from https://github.com/koalo
  6. We are using a custom board and would like to use rpi 3.12.x
  7. kernel. Patch works fine for our embedded system.
  8. Signed-off-by: Waldemar Brodkorb <wbrodkorb@conet.de>
  9. Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
  10. ---
  11. arch/arm/mach-bcm2708/bcm2708.c | 17 +++++
  12. sound/soc/bcm/Kconfig | 8 +++
  13. sound/soc/bcm/Makefile | 2 +
  14. sound/soc/bcm/rpi-proto.c | 130 +++++++++++++++++++++++++++++++++++++++
  15. 4 files changed, 157 insertions(+)
  16. create mode 100644 sound/soc/bcm/rpi-proto.c
  17. diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c
  18. index c1a5943..0a0bb05 100644
  19. --- a/arch/arm/mach-bcm2708/bcm2708.c
  20. +++ b/arch/arm/mach-bcm2708/bcm2708.c
  21. @@ -754,6 +754,19 @@ static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
  22. };
  23. #endif
  24. +#ifdef CONFIG_SND_BCM2708_SOC_RPI_CODEC_PROTO_MODULE
  25. +static struct platform_device snd_rpi_proto_device = {
  26. + .name = "snd-rpi-proto",
  27. + .id = 0,
  28. + .num_resources = 0,
  29. +};
  30. +static struct i2c_board_info __initdata snd_rpi_proto_i2c_devices[] = {
  31. + {
  32. + I2C_BOARD_INFO("wm8731", 0x1a)
  33. + },
  34. +};
  35. +#endif
  36. +
  37. int __init bcm_register_device(struct platform_device *pdev)
  38. {
  39. int ret;
  40. @@ -923,6 +936,10 @@ void __init bcm2708_init(void)
  41. bcm_register_device(&snd_rpi_iqaudio_dac_device);
  42. i2c_register_board_info(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
  43. #endif
  44. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_CODEC_PROTO_MODULE)
  45. + bcm_register_device(&snd_rpi_proto_device);
  46. + i2c_register_board_info(1, snd_rpi_proto_i2c_devices, ARRAY_SIZE(snd_rpi_proto_i2c_devices));
  47. +#endif
  48. for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  49. diff --git a/sound/soc/bcm/Kconfig b/sound/soc/bcm/Kconfig
  50. index 301f758..bfe382a 100644
  51. --- a/sound/soc/bcm/Kconfig
  52. +++ b/sound/soc/bcm/Kconfig
  53. @@ -50,3 +50,11 @@ config SND_BCM2708_SOC_IQAUDIO_DAC
  54. select SND_SOC_PCM512x
  55. help
  56. Say Y or M if you want to add support for IQaudIO-DAC.
  57. +
  58. +config SND_BCM2708_SOC_RPI_CODEC_PROTO
  59. + tristate "Support for Audio Codec Board - PROTO (WM8731)"
  60. + depends on SND_BCM2708_SOC_I2S
  61. + select SND_SOC_WM8731
  62. + help
  63. + Say Y if you want to add support for Audio Codec Board -
  64. + PROTO (WM8731)
  65. diff --git a/sound/soc/bcm/Makefile b/sound/soc/bcm/Makefile
  66. index 8b5e8bb..d1bf274 100644
  67. --- a/sound/soc/bcm/Makefile
  68. +++ b/sound/soc/bcm/Makefile
  69. @@ -10,6 +10,7 @@ snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  70. snd-soc-hifiberry-amp-objs := hifiberry_amp.o
  71. snd-soc-rpi-dac-objs := rpi-dac.o
  72. snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  73. +snd-soc-rpi-proto-objs := rpi-proto.o
  74. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  75. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
  76. @@ -17,3 +18,4 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  77. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
  78. obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  79. obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  80. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_CODEC_PROTO) += snd-soc-rpi-proto.o
  81. diff --git a/sound/soc/bcm/rpi-proto.c b/sound/soc/bcm/rpi-proto.c
  82. new file mode 100644
  83. index 0000000..70b0166
  84. --- /dev/null
  85. +++ b/sound/soc/bcm/rpi-proto.c
  86. @@ -0,0 +1,130 @@
  87. +/*
  88. + * ASoC driver for PROTO AudioCODEC (with a WM8731)
  89. + * connected to a Raspberry Pi
  90. + *
  91. + * Author: Florian Meier, <koalo@koalo.de>
  92. + * Copyright 2013
  93. + *
  94. + * This program is free software; you can redistribute it and/or modify
  95. + * it under the terms of the GNU General Public License version 2 as
  96. + * published by the Free Software Foundation.
  97. + */
  98. +
  99. +#include <linux/module.h>
  100. +#include <linux/platform_device.h>
  101. +
  102. +#include <sound/core.h>
  103. +#include <sound/pcm.h>
  104. +#include <sound/soc.h>
  105. +#include <sound/jack.h>
  106. +
  107. +#include "../codecs/wm8731.h"
  108. +
  109. +static const unsigned int wm8731_rates_12288000[] = {
  110. + 8000, 32000, 48000, 96000,
  111. +};
  112. +
  113. +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
  114. + .list = wm8731_rates_12288000,
  115. + .count = ARRAY_SIZE(wm8731_rates_12288000),
  116. +};
  117. +
  118. +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
  119. +{
  120. + /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
  121. + snd_pcm_hw_constraint_list(substream->runtime, 0,
  122. + SNDRV_PCM_HW_PARAM_RATE,
  123. + &wm8731_constraints_12288000);
  124. + return 0;
  125. +}
  126. +
  127. +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
  128. + struct snd_pcm_hw_params *params)
  129. +{
  130. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  131. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  132. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  133. + int sysclk = 12288000; /* This is fixed on this board */
  134. +
  135. + /* Set proto bclk */
  136. + int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
  137. + if (ret < 0){
  138. + dev_err(substream->pcm->dev,
  139. + "Failed to set BCLK ratio %d\n", ret);
  140. + return ret;
  141. + }
  142. +
  143. + /* Set proto sysclk */
  144. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
  145. + sysclk, SND_SOC_CLOCK_IN);
  146. + if (ret < 0) {
  147. + dev_err(substream->pcm->dev,
  148. + "Failed to set WM8731 SYSCLK: %d\n", ret);
  149. + return ret;
  150. + }
  151. +
  152. + return 0;
  153. +}
  154. +
  155. +/* machine stream operations */
  156. +static struct snd_soc_ops snd_rpi_proto_ops = {
  157. + .startup = snd_rpi_proto_startup,
  158. + .hw_params = snd_rpi_proto_hw_params,
  159. +};
  160. +
  161. +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
  162. +{
  163. + .name = "WM8731",
  164. + .stream_name = "WM8731 HiFi",
  165. + .cpu_dai_name = "bcm2708-i2s.0",
  166. + .codec_dai_name = "wm8731-hifi",
  167. + .platform_name = "bcm2708-i2s.0",
  168. + .codec_name = "wm8731.1-001a",
  169. + .dai_fmt = SND_SOC_DAIFMT_I2S
  170. + | SND_SOC_DAIFMT_NB_NF
  171. + | SND_SOC_DAIFMT_CBM_CFM,
  172. + .ops = &snd_rpi_proto_ops,
  173. +},
  174. +};
  175. +
  176. +/* audio machine driver */
  177. +static struct snd_soc_card snd_rpi_proto = {
  178. + .name = "snd_rpi_proto",
  179. + .dai_link = snd_rpi_proto_dai,
  180. + .num_links = ARRAY_SIZE(snd_rpi_proto_dai),
  181. +};
  182. +
  183. +static int snd_rpi_proto_probe(struct platform_device *pdev)
  184. +{
  185. + int ret = 0;
  186. +
  187. + snd_rpi_proto.dev = &pdev->dev;
  188. + ret = snd_soc_register_card(&snd_rpi_proto);
  189. + if (ret) {
  190. + dev_err(&pdev->dev,
  191. + "snd_soc_register_card() failed: %d\n", ret);
  192. + }
  193. +
  194. + return ret;
  195. +}
  196. +
  197. +
  198. +static int snd_rpi_proto_remove(struct platform_device *pdev)
  199. +{
  200. + return snd_soc_unregister_card(&snd_rpi_proto);
  201. +}
  202. +
  203. +static struct platform_driver snd_rpi_proto_driver = {
  204. + .driver = {
  205. + .name = "snd-rpi-proto",
  206. + .owner = THIS_MODULE,
  207. + },
  208. + .probe = snd_rpi_proto_probe,
  209. + .remove = snd_rpi_proto_remove,
  210. +};
  211. +
  212. +module_platform_driver(snd_rpi_proto_driver);
  213. +
  214. +MODULE_AUTHOR("Florian Meier");
  215. +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
  216. +MODULE_LICENSE("GPL");
  217. --
  218. 1.7.10.4