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

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