0001-add-support-for-rpi-proto-hardware.patch 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. From 7174c08bd5f4e4976259c7a0894d302acc67321e Mon Sep 17 00:00:00 2001
  2. From: Waldemar Brodkorb <wbrodkorb@conet.de>
  3. Date: Mon, 2 Feb 2015 11:08:33 +0100
  4. Subject: [PATCH] add support for rpi-proto hardware
  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.18.x
  7. kernel. Patch works fine for our embedded system.
  8. Signed-off-by: Waldemar Brodkorb <wbrodkorb@conet.de>
  9. ---
  10. arch/arm/boot/dts/Makefile | 1 +
  11. arch/arm/boot/dts/rpi-proto-overlay.dts | 34 +++++++++
  12. arch/arm/mach-bcm2708/bcm2708.c | 20 +++++
  13. sound/soc/bcm/Kconfig | 8 ++
  14. sound/soc/bcm/Makefile | 2 +
  15. sound/soc/bcm/rpi-proto.c | 130 ++++++++++++++++++++++++++++++++
  16. 6 files changed, 195 insertions(+)
  17. create mode 100644 arch/arm/boot/dts/rpi-proto-overlay.dts
  18. create mode 100644 sound/soc/bcm/rpi-proto.c
  19. diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
  20. index 1b66478..7171eb6 100644
  21. --- a/arch/arm/boot/dts/Makefile
  22. +++ b/arch/arm/boot/dts/Makefile
  23. @@ -61,6 +61,7 @@ dtb-$(CONFIG_BCM2708_DT) += hifiberry-digi-overlay.dtb
  24. dtb-$(CONFIG_BCM2708_DT) += hifiberry-amp-overlay.dtb
  25. dtb-$(CONFIG_BCM2708_DT) += iqaudio-dac-overlay.dtb
  26. dtb-$(CONFIG_BCM2708_DT) += iqaudio-dacplus-overlay.dtb
  27. +dtb-$(CONFIG_BCM2708_DT) += rpi-proto-overlay.dtb
  28. dtb-$(CONFIG_BCM2708_DT) += lirc-rpi-overlay.dtb
  29. dtb-$(CONFIG_BCM2708_DT) += pcf8523-rtc-overlay.dtb
  30. dtb-$(CONFIG_BCM2708_DT) += pps-gpio-overlay.dtb
  31. diff --git a/arch/arm/boot/dts/rpi-proto-overlay.dts b/arch/arm/boot/dts/rpi-proto-overlay.dts
  32. new file mode 100644
  33. index 0000000..984545b
  34. --- /dev/null
  35. +++ b/arch/arm/boot/dts/rpi-proto-overlay.dts
  36. @@ -0,0 +1,34 @@
  37. +// Definitions for Rpi-Proto
  38. +/dts-v1/;
  39. +/plugin/;
  40. +
  41. +/ {
  42. + compatible = "brcm,bcm2708";
  43. +
  44. + fragment@0 {
  45. + target = <&sound>;
  46. + __overlay__ {
  47. + compatible = "rpi-proto";
  48. + i2s-controller = <&i2s>;
  49. + status = "okay";
  50. + };
  51. + };
  52. +
  53. + fragment@1 {
  54. + target = <&i2s>;
  55. + __overlay__ {
  56. + status = "okay";
  57. + };
  58. + };
  59. +
  60. + fragment@2 {
  61. + target-path = "/";
  62. + __overlay__ {
  63. + wm8731-codec {
  64. + #sound-dai-cells = <0>;
  65. + compatible = "wlf,wm8731";
  66. + status = "okay";
  67. + };
  68. + };
  69. + };
  70. +};
  71. diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c
  72. index 762e17c..9ce0f78 100644
  73. --- a/arch/arm/mach-bcm2708/bcm2708.c
  74. +++ b/arch/arm/mach-bcm2708/bcm2708.c
  75. @@ -703,6 +703,21 @@ static struct i2c_board_info __initdata snd_tas5713_i2c_devices[] = {
  76. };
  77. #endif
  78. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_PROTO) || defined(CONFIG_SND_BCM2708_SOC_RPI_PROTO_MODULE)
  79. +static struct platform_device snd_rpi_proto_device = {
  80. + .name = "snd-rpi-proto",
  81. + .id = 0,
  82. + .num_resources = 0,
  83. +};
  84. +
  85. +static struct i2c_board_info __initdata snd_wm8731_i2c_devices[] = {
  86. + {
  87. + I2C_BOARD_INFO("wm8731", 0x1a)
  88. + },
  89. +};
  90. +
  91. +#endif
  92. +
  93. #if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  94. static struct platform_device snd_rpi_dac_device = {
  95. .name = "snd-rpi-dac",
  96. @@ -922,6 +937,11 @@ void __init bcm2708_init(void)
  97. i2c_register_board_info_dt(1, snd_tas5713_i2c_devices, ARRAY_SIZE(snd_tas5713_i2c_devices));
  98. #endif
  99. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_PROTO) || defined(CONFIG_SND_BCM2708_SOC_RPI_PROTO_MODULE)
  100. + bcm_register_device_dt(&snd_rpi_proto_device);
  101. + i2c_register_board_info_dt(1, snd_wm8731_i2c_devices, ARRAY_SIZE(snd_wm8731_i2c_devices));
  102. +#endif
  103. +
  104. #if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  105. bcm_register_device_dt(&snd_rpi_dac_device);
  106. bcm_register_device_dt(&snd_pcm1794a_codec_device);
  107. diff --git a/sound/soc/bcm/Kconfig b/sound/soc/bcm/Kconfig
  108. index a562ddf..1ea891d 100644
  109. --- a/sound/soc/bcm/Kconfig
  110. +++ b/sound/soc/bcm/Kconfig
  111. @@ -54,6 +54,14 @@ config SND_BCM2708_SOC_RPI_DAC
  112. help
  113. Say Y or M if you want to add support for RPi-DAC.
  114. +config SND_BCM2708_SOC_RPI_PROTO
  115. + tristate "Support for Rpi-PROTO"
  116. + depends on SND_BCM2708_SOC_I2S
  117. + select SND_SOC_WM8731
  118. + help
  119. + Say Y if you want to add support for Audio Codec Board -
  120. + PROTO (WM8731)
  121. +
  122. config SND_BCM2708_SOC_IQAUDIO_DAC
  123. tristate "Support for IQaudIO-DAC"
  124. depends on SND_BCM2708_SOC_I2S
  125. diff --git a/sound/soc/bcm/Makefile b/sound/soc/bcm/Makefile
  126. index 17ea2b0..883241b 100644
  127. --- a/sound/soc/bcm/Makefile
  128. +++ b/sound/soc/bcm/Makefile
  129. @@ -14,6 +14,7 @@ snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
  130. snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  131. snd-soc-hifiberry-amp-objs := hifiberry_amp.o
  132. snd-soc-rpi-dac-objs := rpi-dac.o
  133. +snd-soc-rpi-proto-objs := rpi-proto.o
  134. snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  135. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  136. @@ -21,4 +22,5 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
  137. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  138. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
  139. obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  140. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
  141. obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  142. diff --git a/sound/soc/bcm/rpi-proto.c b/sound/soc/bcm/rpi-proto.c
  143. new file mode 100644
  144. index 0000000..70b0166
  145. --- /dev/null
  146. +++ b/sound/soc/bcm/rpi-proto.c
  147. @@ -0,0 +1,130 @@
  148. +/*
  149. + * ASoC driver for PROTO AudioCODEC (with a WM8731)
  150. + * connected to a Raspberry Pi
  151. + *
  152. + * Author: Florian Meier, <koalo@koalo.de>
  153. + * Copyright 2013
  154. + *
  155. + * This program is free software; you can redistribute it and/or modify
  156. + * it under the terms of the GNU General Public License version 2 as
  157. + * published by the Free Software Foundation.
  158. + */
  159. +
  160. +#include <linux/module.h>
  161. +#include <linux/platform_device.h>
  162. +
  163. +#include <sound/core.h>
  164. +#include <sound/pcm.h>
  165. +#include <sound/soc.h>
  166. +#include <sound/jack.h>
  167. +
  168. +#include "../codecs/wm8731.h"
  169. +
  170. +static const unsigned int wm8731_rates_12288000[] = {
  171. + 8000, 32000, 48000, 96000,
  172. +};
  173. +
  174. +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
  175. + .list = wm8731_rates_12288000,
  176. + .count = ARRAY_SIZE(wm8731_rates_12288000),
  177. +};
  178. +
  179. +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
  180. +{
  181. + /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
  182. + snd_pcm_hw_constraint_list(substream->runtime, 0,
  183. + SNDRV_PCM_HW_PARAM_RATE,
  184. + &wm8731_constraints_12288000);
  185. + return 0;
  186. +}
  187. +
  188. +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
  189. + struct snd_pcm_hw_params *params)
  190. +{
  191. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  192. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  193. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  194. + int sysclk = 12288000; /* This is fixed on this board */
  195. +
  196. + /* Set proto bclk */
  197. + int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
  198. + if (ret < 0){
  199. + dev_err(substream->pcm->dev,
  200. + "Failed to set BCLK ratio %d\n", ret);
  201. + return ret;
  202. + }
  203. +
  204. + /* Set proto sysclk */
  205. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
  206. + sysclk, SND_SOC_CLOCK_IN);
  207. + if (ret < 0) {
  208. + dev_err(substream->pcm->dev,
  209. + "Failed to set WM8731 SYSCLK: %d\n", ret);
  210. + return ret;
  211. + }
  212. +
  213. + return 0;
  214. +}
  215. +
  216. +/* machine stream operations */
  217. +static struct snd_soc_ops snd_rpi_proto_ops = {
  218. + .startup = snd_rpi_proto_startup,
  219. + .hw_params = snd_rpi_proto_hw_params,
  220. +};
  221. +
  222. +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
  223. +{
  224. + .name = "WM8731",
  225. + .stream_name = "WM8731 HiFi",
  226. + .cpu_dai_name = "bcm2708-i2s.0",
  227. + .codec_dai_name = "wm8731-hifi",
  228. + .platform_name = "bcm2708-i2s.0",
  229. + .codec_name = "wm8731.1-001a",
  230. + .dai_fmt = SND_SOC_DAIFMT_I2S
  231. + | SND_SOC_DAIFMT_NB_NF
  232. + | SND_SOC_DAIFMT_CBM_CFM,
  233. + .ops = &snd_rpi_proto_ops,
  234. +},
  235. +};
  236. +
  237. +/* audio machine driver */
  238. +static struct snd_soc_card snd_rpi_proto = {
  239. + .name = "snd_rpi_proto",
  240. + .dai_link = snd_rpi_proto_dai,
  241. + .num_links = ARRAY_SIZE(snd_rpi_proto_dai),
  242. +};
  243. +
  244. +static int snd_rpi_proto_probe(struct platform_device *pdev)
  245. +{
  246. + int ret = 0;
  247. +
  248. + snd_rpi_proto.dev = &pdev->dev;
  249. + ret = snd_soc_register_card(&snd_rpi_proto);
  250. + if (ret) {
  251. + dev_err(&pdev->dev,
  252. + "snd_soc_register_card() failed: %d\n", ret);
  253. + }
  254. +
  255. + return ret;
  256. +}
  257. +
  258. +
  259. +static int snd_rpi_proto_remove(struct platform_device *pdev)
  260. +{
  261. + return snd_soc_unregister_card(&snd_rpi_proto);
  262. +}
  263. +
  264. +static struct platform_driver snd_rpi_proto_driver = {
  265. + .driver = {
  266. + .name = "snd-rpi-proto",
  267. + .owner = THIS_MODULE,
  268. + },
  269. + .probe = snd_rpi_proto_probe,
  270. + .remove = snd_rpi_proto_remove,
  271. +};
  272. +
  273. +module_platform_driver(snd_rpi_proto_driver);
  274. +
  275. +MODULE_AUTHOR("Florian Meier");
  276. +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
  277. +MODULE_LICENSE("GPL");
  278. --
  279. 1.9.1