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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. From ddce02de6ff1d13503f66bb08b971ff532b89b43 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 | 39 ++++++++
  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 | 152 ++++++++++++++++++++++++++++++++
  16. 6 files changed, 222 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..2029930
  34. --- /dev/null
  35. +++ b/arch/arm/boot/dts/rpi-proto-overlay.dts
  36. @@ -0,0 +1,39 @@
  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,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 = <&i2c1>;
  62. + __overlay__ {
  63. + #address-cells = <1>;
  64. + #size-cells = <0>;
  65. + status = "okay";
  66. +
  67. + wm8731@1a {
  68. + #sound-dai-cells = <0>;
  69. + compatible = "wlf,wm8731";
  70. + reg = <0x1a>;
  71. + status = "okay";
  72. + };
  73. + };
  74. + };
  75. +};
  76. diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c
  77. index 762e17c..9ce0f78 100644
  78. --- a/arch/arm/mach-bcm2708/bcm2708.c
  79. +++ b/arch/arm/mach-bcm2708/bcm2708.c
  80. @@ -703,6 +703,21 @@ static struct i2c_board_info __initdata snd_tas5713_i2c_devices[] = {
  81. };
  82. #endif
  83. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_PROTO) || defined(CONFIG_SND_BCM2708_SOC_RPI_PROTO_MODULE)
  84. +static struct platform_device snd_rpi_proto_device = {
  85. + .name = "snd-rpi-proto",
  86. + .id = 0,
  87. + .num_resources = 0,
  88. +};
  89. +
  90. +static struct i2c_board_info __initdata snd_wm8731_i2c_devices[] = {
  91. + {
  92. + I2C_BOARD_INFO("wm8731", 0x1a)
  93. + },
  94. +};
  95. +
  96. +#endif
  97. +
  98. #if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  99. static struct platform_device snd_rpi_dac_device = {
  100. .name = "snd-rpi-dac",
  101. @@ -922,6 +937,11 @@ void __init bcm2708_init(void)
  102. i2c_register_board_info_dt(1, snd_tas5713_i2c_devices, ARRAY_SIZE(snd_tas5713_i2c_devices));
  103. #endif
  104. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_PROTO) || defined(CONFIG_SND_BCM2708_SOC_RPI_PROTO_MODULE)
  105. + bcm_register_device_dt(&snd_rpi_proto_device);
  106. + i2c_register_board_info_dt(1, snd_wm8731_i2c_devices, ARRAY_SIZE(snd_wm8731_i2c_devices));
  107. +#endif
  108. +
  109. #if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  110. bcm_register_device_dt(&snd_rpi_dac_device);
  111. bcm_register_device_dt(&snd_pcm1794a_codec_device);
  112. diff --git a/sound/soc/bcm/Kconfig b/sound/soc/bcm/Kconfig
  113. index a562ddf..1ea891d 100644
  114. --- a/sound/soc/bcm/Kconfig
  115. +++ b/sound/soc/bcm/Kconfig
  116. @@ -54,6 +54,14 @@ config SND_BCM2708_SOC_RPI_DAC
  117. help
  118. Say Y or M if you want to add support for RPi-DAC.
  119. +config SND_BCM2708_SOC_RPI_PROTO
  120. + tristate "Support for Rpi-PROTO"
  121. + depends on SND_BCM2708_SOC_I2S
  122. + select SND_SOC_WM8731
  123. + help
  124. + Say Y if you want to add support for Audio Codec Board -
  125. + PROTO (WM8731)
  126. +
  127. config SND_BCM2708_SOC_IQAUDIO_DAC
  128. tristate "Support for IQaudIO-DAC"
  129. depends on SND_BCM2708_SOC_I2S
  130. diff --git a/sound/soc/bcm/Makefile b/sound/soc/bcm/Makefile
  131. index 17ea2b0..883241b 100644
  132. --- a/sound/soc/bcm/Makefile
  133. +++ b/sound/soc/bcm/Makefile
  134. @@ -14,6 +14,7 @@ snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
  135. snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  136. snd-soc-hifiberry-amp-objs := hifiberry_amp.o
  137. snd-soc-rpi-dac-objs := rpi-dac.o
  138. +snd-soc-rpi-proto-objs := rpi-proto.o
  139. snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  140. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  141. @@ -21,4 +22,5 @@ obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
  142. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  143. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
  144. obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  145. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
  146. obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  147. diff --git a/sound/soc/bcm/rpi-proto.c b/sound/soc/bcm/rpi-proto.c
  148. new file mode 100644
  149. index 0000000..cdc8b51
  150. --- /dev/null
  151. +++ b/sound/soc/bcm/rpi-proto.c
  152. @@ -0,0 +1,152 @@
  153. +/*
  154. + * ASoC driver for PROTO AudioCODEC (with a WM8731)
  155. + * connected to a Raspberry Pi
  156. + *
  157. + * Author: Florian Meier, <koalo@koalo.de>
  158. + * Copyright 2013
  159. + *
  160. + * This program is free software; you can redistribute it and/or modify
  161. + * it under the terms of the GNU General Public License version 2 as
  162. + * published by the Free Software Foundation.
  163. + */
  164. +
  165. +#include <linux/module.h>
  166. +#include <linux/platform_device.h>
  167. +
  168. +#include <sound/core.h>
  169. +#include <sound/pcm.h>
  170. +#include <sound/soc.h>
  171. +#include <sound/jack.h>
  172. +
  173. +#include "../codecs/wm8731.h"
  174. +
  175. +static const unsigned int wm8731_rates_12288000[] = {
  176. + 8000, 32000, 48000, 96000,
  177. +};
  178. +
  179. +static struct snd_pcm_hw_constraint_list wm8731_constraints_12288000 = {
  180. + .list = wm8731_rates_12288000,
  181. + .count = ARRAY_SIZE(wm8731_rates_12288000),
  182. +};
  183. +
  184. +static int snd_rpi_proto_startup(struct snd_pcm_substream *substream)
  185. +{
  186. + /* Setup constraints, because there is a 12.288 MHz XTAL on the board */
  187. + snd_pcm_hw_constraint_list(substream->runtime, 0,
  188. + SNDRV_PCM_HW_PARAM_RATE,
  189. + &wm8731_constraints_12288000);
  190. + return 0;
  191. +}
  192. +
  193. +static int snd_rpi_proto_hw_params(struct snd_pcm_substream *substream,
  194. + struct snd_pcm_hw_params *params)
  195. +{
  196. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  197. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  198. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  199. + int sysclk = 12288000; /* This is fixed on this board */
  200. +
  201. + /* Set proto bclk */
  202. + int ret = snd_soc_dai_set_bclk_ratio(cpu_dai,32*2);
  203. + if (ret < 0){
  204. + dev_err(substream->pcm->dev,
  205. + "Failed to set BCLK ratio %d\n", ret);
  206. + return ret;
  207. + }
  208. +
  209. + /* Set proto sysclk */
  210. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
  211. + sysclk, SND_SOC_CLOCK_IN);
  212. + if (ret < 0) {
  213. + dev_err(substream->pcm->dev,
  214. + "Failed to set WM8731 SYSCLK: %d\n", ret);
  215. + return ret;
  216. + }
  217. +
  218. + return 0;
  219. +}
  220. +
  221. +/* machine stream operations */
  222. +static struct snd_soc_ops snd_rpi_proto_ops = {
  223. + .startup = snd_rpi_proto_startup,
  224. + .hw_params = snd_rpi_proto_hw_params,
  225. +};
  226. +
  227. +static struct snd_soc_dai_link snd_rpi_proto_dai[] = {
  228. +{
  229. + .name = "WM8731",
  230. + .stream_name = "WM8731 HiFi",
  231. + .cpu_dai_name = "bcm2708-i2s.0",
  232. + .codec_dai_name = "wm8731-hifi",
  233. + .platform_name = "bcm2708-i2s.0",
  234. + .codec_name = "wm8731.1-001a",
  235. + .dai_fmt = SND_SOC_DAIFMT_I2S
  236. + | SND_SOC_DAIFMT_NB_NF
  237. + | SND_SOC_DAIFMT_CBM_CFM,
  238. + .ops = &snd_rpi_proto_ops,
  239. +},
  240. +};
  241. +
  242. +/* audio machine driver */
  243. +static struct snd_soc_card snd_rpi_proto = {
  244. + .name = "snd_rpi_proto",
  245. + .dai_link = snd_rpi_proto_dai,
  246. + .num_links = ARRAY_SIZE(snd_rpi_proto_dai),
  247. +};
  248. +
  249. +static int snd_rpi_proto_probe(struct platform_device *pdev)
  250. +{
  251. + int ret = 0;
  252. +
  253. + snd_rpi_proto.dev = &pdev->dev;
  254. +
  255. + if (pdev->dev.of_node) {
  256. + struct device_node *i2s_node;
  257. + struct snd_soc_dai_link *dai = &snd_rpi_proto_dai[0];
  258. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  259. + "i2s-controller", 0);
  260. +
  261. + if (i2s_node) {
  262. + dai->cpu_dai_name = NULL;
  263. + dai->cpu_of_node = i2s_node;
  264. + dai->platform_name = NULL;
  265. + dai->platform_of_node = i2s_node;
  266. + }
  267. + }
  268. +
  269. + ret = snd_soc_register_card(&snd_rpi_proto);
  270. + if (ret) {
  271. + dev_err(&pdev->dev,
  272. + "snd_soc_register_card() failed: %d\n", ret);
  273. + }
  274. +
  275. + return ret;
  276. +}
  277. +
  278. +
  279. +static int snd_rpi_proto_remove(struct platform_device *pdev)
  280. +{
  281. + return snd_soc_unregister_card(&snd_rpi_proto);
  282. +}
  283. +
  284. +static const struct of_device_id snd_rpi_proto_of_match[] = {
  285. + { .compatible = "rpi,rpi-proto", },
  286. + {},
  287. +};
  288. +MODULE_DEVICE_TABLE(of, snd_rpi_proto_of_match);
  289. +
  290. +static struct platform_driver snd_rpi_proto_driver = {
  291. + .driver = {
  292. + .name = "snd-rpi-proto",
  293. + .owner = THIS_MODULE,
  294. + .of_match_table = snd_rpi_proto_of_match,
  295. + },
  296. + .probe = snd_rpi_proto_probe,
  297. + .remove = snd_rpi_proto_remove,
  298. +};
  299. +
  300. +module_platform_driver(snd_rpi_proto_driver);
  301. +
  302. +MODULE_AUTHOR("Florian Meier");
  303. +MODULE_DESCRIPTION("ASoC Driver for Raspberry Pi connected to PROTO board (WM8731)");
  304. +MODULE_LICENSE("GPL");
  305. --
  306. 1.9.1