0326-ARM-adau1977-adc-Add-basic-machine-driver-for-adau19.patch 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. From 347d4cf757e6f093860048fe69737c29f5adcd0f Mon Sep 17 00:00:00 2001
  2. From: Andrey Grodzovsky <andrey2805@gmail.com>
  3. Date: Tue, 3 May 2016 22:10:59 -0400
  4. Subject: [PATCH 326/381] ARM: adau1977-adc: Add basic machine driver for
  5. adau1977 codec driver.
  6. This commit adds basic support for the codec usage including: Device tree overlay,
  7. binding I2S bus and setting I2S mode, clock source and frequency setting according
  8. to spec.
  9. Signed-off-by: Andrey Grodzovsky <andrey2805@gmail.com>
  10. ---
  11. arch/arm/boot/dts/overlays/Makefile | 1 +
  12. arch/arm/boot/dts/overlays/README | 7 ++
  13. .../arm/boot/dts/overlays/adau1977-adc-overlay.dts | 53 +++++++++
  14. arch/arm/configs/bcm2709_defconfig | 1 +
  15. arch/arm/configs/bcmrpi_defconfig | 1 +
  16. sound/soc/bcm/Kconfig | 7 ++
  17. sound/soc/bcm/Makefile | 2 +
  18. sound/soc/bcm/adau1977-adc.c | 125 +++++++++++++++++++++
  19. 8 files changed, 197 insertions(+)
  20. create mode 100644 arch/arm/boot/dts/overlays/adau1977-adc-overlay.dts
  21. create mode 100644 sound/soc/bcm/adau1977-adc.c
  22. --- a/arch/arm/boot/dts/overlays/Makefile
  23. +++ b/arch/arm/boot/dts/overlays/Makefile
  24. @@ -12,6 +12,7 @@ ifeq ($(CONFIG_ARCH_BCM2835),y)
  25. RPI_DT_OVERLAYS=y
  26. endif
  27. +dtbo-$(RPI_DT_OVERLAYS) += adau1977-adc.dtbo
  28. dtbo-$(RPI_DT_OVERLAYS) += ads7846.dtbo
  29. dtbo-$(RPI_DT_OVERLAYS) += akkordion-iqdacplus.dtbo
  30. dtbo-$(RPI_DT_OVERLAYS) += at86rf233.dtbo
  31. --- a/arch/arm/boot/dts/overlays/README
  32. +++ b/arch/arm/boot/dts/overlays/README
  33. @@ -161,6 +161,13 @@ Params:
  34. and the other i2c baudrate parameters.
  35. +Name: adau1977-adc
  36. +Info: Overlay for activation of ADAU1977 ADC codec over I2C for control
  37. + and I2S for data.
  38. +Load: dtoverlay=adau1977-adc
  39. +Params: <None>
  40. +
  41. +
  42. Name: ads7846
  43. Info: ADS7846 Touch controller
  44. Load: dtoverlay=ads7846,<param>=<val>
  45. --- /dev/null
  46. +++ b/arch/arm/boot/dts/overlays/adau1977-adc-overlay.dts
  47. @@ -0,0 +1,53 @@
  48. +// Definitions for ADAU1977 ADC
  49. +/dts-v1/;
  50. +/plugin/;
  51. +
  52. +/ {
  53. + compatible = "brcm,bcm2708";
  54. +
  55. + fragment@0 {
  56. + target = <&soc>;
  57. +
  58. + __overlay__ {
  59. + codec_supply: fixedregulator@0 {
  60. + compatible = "regulator-fixed";
  61. + regulator-name = "AVDD";
  62. + regulator-min-microvolt = <3300000>;
  63. + regulator-max-microvolt = <3300000>;
  64. + };
  65. + };
  66. + };
  67. +
  68. + fragment@1 {
  69. + target = <&i2c>;
  70. +
  71. + __overlay__ {
  72. + #address-cells = <1>;
  73. + #size-cells = <0>;
  74. + status = "okay";
  75. +
  76. + adau1977: codec@11 {
  77. + compatible = "adi,adau1977";
  78. + reg = <0x11>;
  79. + reset-gpios = <&gpio 5 0>;
  80. + AVDD-supply = <&codec_supply>;
  81. + };
  82. + };
  83. + };
  84. +
  85. + fragment@2 {
  86. + target = <&i2s>;
  87. + __overlay__ {
  88. + status = "okay";
  89. + };
  90. + };
  91. +
  92. + fragment@3 {
  93. + target = <&sound>;
  94. + __overlay__ {
  95. + compatible = "adi,adau1977-adc";
  96. + i2s-controller = <&i2s>;
  97. + status = "okay";
  98. + };
  99. + };
  100. +};
  101. --- a/arch/arm/configs/bcm2709_defconfig
  102. +++ b/arch/arm/configs/bcm2709_defconfig
  103. @@ -861,6 +861,7 @@ CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
  104. CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI=m
  105. CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  106. CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
  107. +CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
  108. CONFIG_SND_SOC_ADAU1701=m
  109. CONFIG_SND_SOC_WM8804_I2C=m
  110. CONFIG_SND_SIMPLE_CARD=m
  111. --- a/arch/arm/configs/bcmrpi_defconfig
  112. +++ b/arch/arm/configs/bcmrpi_defconfig
  113. @@ -853,6 +853,7 @@ CONFIG_SND_BCM2708_SOC_BOOMBERRY_DAC=m
  114. CONFIG_SND_BCM2708_SOC_BOOMBERRY_DIGI=m
  115. CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  116. CONFIG_SND_BCM2708_SOC_RASPIDAC3=m
  117. +CONFIG_SND_BCM2708_SOC_ADAU1977_ADC=m
  118. CONFIG_SND_SOC_ADAU1701=m
  119. CONFIG_SND_SOC_WM8804_I2C=m
  120. CONFIG_SND_SIMPLE_CARD=m
  121. --- a/sound/soc/bcm/Kconfig
  122. +++ b/sound/soc/bcm/Kconfig
  123. @@ -78,3 +78,10 @@ config SND_BCM2708_SOC_RASPIDAC3
  124. select SND_SOC_TPA6130A2
  125. help
  126. Say Y or M if you want to add support for RaspiDAC Rev.3x.
  127. +
  128. +config SND_BCM2708_SOC_ADAU1977_ADC
  129. + tristate "Support for ADAU1977 ADC"
  130. + depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
  131. + select SND_SOC_ADAU1977_I2C
  132. + help
  133. + Say Y or M if you want to add support for ADAU1977 ADC.
  134. --- a/sound/soc/bcm/Makefile
  135. +++ b/sound/soc/bcm/Makefile
  136. @@ -4,6 +4,7 @@ snd-soc-bcm2835-i2s-objs := bcm2835-i2s.
  137. obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd-soc-bcm2835-i2s.o
  138. # BCM2708 Machine Support
  139. +snd-soc-adau1977-adc-objs := adau1977-adc.o
  140. snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  141. snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
  142. snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  143. @@ -15,6 +16,7 @@ snd-soc-rpi-proto-objs := rpi-proto.o
  144. snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  145. snd-soc-raspidac3-objs := raspidac3.o
  146. +obj-$(CONFIG_SND_BCM2708_SOC_ADAU1977_ADC) += snd-soc-adau1977-adc.o
  147. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  148. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
  149. obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  150. --- /dev/null
  151. +++ b/sound/soc/bcm/adau1977-adc.c
  152. @@ -0,0 +1,125 @@
  153. +/*
  154. + * ASoC Driver for ADAU1977 ADC
  155. + *
  156. + * Author: Andrey Grodzovsky <andrey2805@gmail.com>
  157. + * Copyright 2016
  158. + *
  159. + * This file is based on hifibery_dac driver by Florian Meier.
  160. + *
  161. + * This program is free software; you can redistribute it and/or
  162. + * modify it under the terms of the GNU General Public License
  163. + * version 2 as published by the Free Software Foundation.
  164. + *
  165. + * This program is distributed in the hope that it will be useful, but
  166. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  167. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  168. + * General Public License for more details.
  169. + */
  170. +
  171. +#include <linux/module.h>
  172. +#include <linux/platform_device.h>
  173. +
  174. +#include <sound/core.h>
  175. +#include <sound/pcm.h>
  176. +#include <sound/pcm_params.h>
  177. +#include <sound/soc.h>
  178. +#include <sound/jack.h>
  179. +
  180. +enum adau1977_clk_id {
  181. + ADAU1977_SYSCLK,
  182. +};
  183. +
  184. +enum adau1977_sysclk_src {
  185. + ADAU1977_SYSCLK_SRC_MCLK,
  186. + ADAU1977_SYSCLK_SRC_LRCLK,
  187. +};
  188. +
  189. +static int eval_adau1977_init(struct snd_soc_pcm_runtime *rtd)
  190. +{
  191. + int ret;
  192. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  193. +
  194. + ret = snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 0, 0);
  195. + if (ret < 0)
  196. + return ret;
  197. +
  198. + return snd_soc_codec_set_sysclk(rtd->codec, ADAU1977_SYSCLK,
  199. + ADAU1977_SYSCLK_SRC_MCLK, 11289600, SND_SOC_CLOCK_IN);
  200. +}
  201. +
  202. +static struct snd_soc_dai_link snd_rpi_adau1977_dai[] = {
  203. + {
  204. + .name = "adau1977",
  205. + .stream_name = "ADAU1977",
  206. + .cpu_dai_name = "bcm2708-i2s.0",
  207. + .codec_dai_name = "adau1977-hifi",
  208. + .platform_name = "bcm2708-i2s.0",
  209. + .codec_name = "adau1977.1-0011",
  210. + .init = eval_adau1977_init,
  211. + .dai_fmt = SND_SOC_DAIFMT_I2S |
  212. + SND_SOC_DAIFMT_NB_NF |
  213. + SND_SOC_DAIFMT_CBM_CFM,
  214. + },
  215. +};
  216. +
  217. +/* audio machine driver */
  218. +static struct snd_soc_card snd_adau1977_adc = {
  219. + .name = "snd_rpi_adau1977_adc",
  220. + .owner = THIS_MODULE,
  221. + .dai_link = snd_rpi_adau1977_dai,
  222. + .num_links = ARRAY_SIZE(snd_rpi_adau1977_dai),
  223. +};
  224. +
  225. +static int snd_adau1977_adc_probe(struct platform_device *pdev)
  226. +{
  227. + int ret = 0;
  228. +
  229. + snd_adau1977_adc.dev = &pdev->dev;
  230. + if (pdev->dev.of_node) {
  231. + struct device_node *i2s_node;
  232. + struct snd_soc_dai_link *dai = &snd_rpi_adau1977_dai[0];
  233. + i2s_node = of_parse_phandle(pdev->dev.of_node,
  234. + "i2s-controller", 0);
  235. +
  236. + if (i2s_node) {
  237. + dai->cpu_dai_name = NULL;
  238. + dai->cpu_of_node = i2s_node;
  239. + dai->platform_name = NULL;
  240. + dai->platform_of_node = i2s_node;
  241. + }
  242. + }
  243. +
  244. + ret = snd_soc_register_card(&snd_adau1977_adc);
  245. + if (ret)
  246. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  247. +
  248. + return ret;
  249. +}
  250. +
  251. +static int snd_adau1977_adc_remove(struct platform_device *pdev)
  252. +{
  253. + return snd_soc_unregister_card(&snd_adau1977_adc);
  254. +}
  255. +
  256. +static const struct of_device_id snd_adau1977_adc_of_match[] = {
  257. + { .compatible = "adi,adau1977-adc", },
  258. + {},
  259. +};
  260. +
  261. +MODULE_DEVICE_TABLE(of, snd_adau1977_adc_of_match);
  262. +
  263. +static struct platform_driver snd_adau1977_adc_driver = {
  264. + .driver = {
  265. + .name = "snd-adau1977-adc",
  266. + .owner = THIS_MODULE,
  267. + .of_match_table = snd_adau1977_adc_of_match,
  268. + },
  269. + .probe = snd_adau1977_adc_probe,
  270. + .remove = snd_adau1977_adc_remove,
  271. +};
  272. +
  273. +module_platform_driver(snd_adau1977_adc_driver);
  274. +
  275. +MODULE_AUTHOR("Andrey Grodzovsky <andrey2805@gmail.com>");
  276. +MODULE_DESCRIPTION("ASoC Driver for ADAU1977 ADC");
  277. +MODULE_LICENSE("GPL v2");