brcm2708: update linux 4.4 patches to latest version
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0411-Added-support-for-headphones-microphone-and-bclk_rat.patch
1 From 84b2845509748519f239b8212bdc672b84755cd0 Mon Sep 17 00:00:00 2001
2 From: Matt Flax <flatmax@flatmax.org>
3 Date: Fri, 17 Jun 2016 12:03:39 +1000
4 Subject: [PATCH] Added support for headphones, microphone and bclk_ratio
5 settings.
6
7 This patch adds headphone and microphone capability to the Audio Injector sound card. The patch also sets the bit clock ratio for use in the bcm2835-i2s driver. The bcm2835-i2s can't handle an 8 kHz sample rate when the bit clock is at 12 MHz because its register is only 10 bits wide which can't represent the ch2 offset of 1508. For that reason, the rate constraint is added.
8 ---
9 sound/soc/bcm/audioinjector-pi-soundcard.c | 67 ++++++++++++++++++++++++++----
10 1 file changed, 58 insertions(+), 9 deletions(-)
11
12 --- a/sound/soc/bcm/audioinjector-pi-soundcard.c
13 +++ b/sound/soc/bcm/audioinjector-pi-soundcard.c
14 @@ -29,16 +29,56 @@
15
16 #include "../codecs/wm8731.h"
17
18 -static int audioinjector_pi_soundcard_dai_init(struct snd_soc_pcm_runtime *rtd)
19 +static const unsigned int bcm2835_rates_12000000[] = {
20 + 32000, 44100, 48000, 96000, 88200,
21 +};
22 +
23 +static struct snd_pcm_hw_constraint_list bcm2835_constraints_12000000 = {
24 + .list = bcm2835_rates_12000000,
25 + .count = ARRAY_SIZE(bcm2835_rates_12000000),
26 +};
27 +
28 +static int snd_audioinjector_pi_soundcard_startup(struct snd_pcm_substream *substream)
29 {
30 - struct snd_soc_dapm_context *dapm = &rtd->card->dapm;
31 + /* Setup constraints, because there is a 12 MHz XTAL on the board */
32 + snd_pcm_hw_constraint_list(substream->runtime, 0,
33 + SNDRV_PCM_HW_PARAM_RATE,
34 + &bcm2835_constraints_12000000);
35 + return 0;
36 +}
37
38 - // not connected
39 - snd_soc_dapm_nc_pin(dapm, "Mic Bias");
40 - snd_soc_dapm_nc_pin(dapm, "MICIN");
41 - snd_soc_dapm_nc_pin(dapm, "RHPOUT");
42 - snd_soc_dapm_nc_pin(dapm, "LHPOUT");
43 +static int snd_audioinjector_pi_soundcard_hw_params(struct snd_pcm_substream *substream,
44 + struct snd_pcm_hw_params *params)
45 +{
46 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
47 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
48
49 + switch (params_rate(params)){
50 + case 8000:
51 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 1508);
52 + case 32000:
53 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 378);
54 + case 44100:
55 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 274);
56 + case 48000:
57 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 252);
58 + case 88200:
59 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 136);
60 + case 96000:
61 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 126);
62 + default:
63 + return snd_soc_dai_set_bclk_ratio(cpu_dai, 126);
64 + }
65 +}
66 +
67 +/* machine stream operations */
68 +static struct snd_soc_ops snd_audioinjector_pi_soundcard_ops = {
69 + .startup = snd_audioinjector_pi_soundcard_startup,
70 + .hw_params = snd_audioinjector_pi_soundcard_hw_params,
71 +};
72 +
73 +static int audioinjector_pi_soundcard_dai_init(struct snd_soc_pcm_runtime *rtd)
74 +{
75 return snd_soc_dai_set_sysclk(rtd->codec_dai, WM8731_SYSCLK_XTAL, 12000000, SND_SOC_CLOCK_IN);
76 }
77
78 @@ -50,30 +90,39 @@ static struct snd_soc_dai_link audioinje
79 .codec_dai_name = "wm8731-hifi",
80 .platform_name = "bcm2835-i2s.0",
81 .codec_name = "wm8731.1-001a",
82 + .ops = &snd_audioinjector_pi_soundcard_ops,
83 .init = audioinjector_pi_soundcard_dai_init,
84 .dai_fmt = SND_SOC_DAIFMT_CBM_CFM|SND_SOC_DAIFMT_I2S|SND_SOC_DAIFMT_NB_NF,
85 },
86 };
87
88 static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
89 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
90 SND_SOC_DAPM_SPK("Ext Spk", NULL),
91 SND_SOC_DAPM_LINE("Line In Jacks", NULL),
92 + SND_SOC_DAPM_MIC("Microphone", NULL),
93 };
94
95 -/* Corgi machine connections to the codec pins */
96 static const struct snd_soc_dapm_route audioinjector_audio_map[] = {
97 + /* headphone connected to LHPOUT, RHPOUT */
98 + {"Headphone Jack", NULL, "LHPOUT"},
99 + {"Headphone Jack", NULL, "RHPOUT"},
100 +
101 /* speaker connected to LOUT, ROUT */
102 {"Ext Spk", NULL, "ROUT"},
103 {"Ext Spk", NULL, "LOUT"},
104
105 /* line inputs */
106 {"Line In Jacks", NULL, "Line Input"},
107 +
108 + /* mic is connected to Mic Jack, with WM8731 Mic Bias */
109 + {"Microphone", NULL, "Mic Bias"},
110 };
111
112 static struct snd_soc_card snd_soc_audioinjector = {
113 .name = "audioinjector-pi-soundcard",
114 .dai_link = audioinjector_pi_soundcard_dai,
115 - .num_links = 1,
116 + .num_links = ARRAY_SIZE(audioinjector_pi_soundcard_dai),
117
118 .dapm_widgets = wm8731_dapm_widgets,
119 .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets),