diff options
59 files changed, 6514 insertions, 666 deletions
diff --git a/Documentation/sound/alsa/soc/dapm.txt b/Documentation/sound/alsa/soc/dapm.txt index 9e6763264a2e..9ac842be9b4f 100644 --- a/Documentation/sound/alsa/soc/dapm.txt +++ b/Documentation/sound/alsa/soc/dapm.txt | |||
@@ -62,6 +62,7 @@ Audio DAPM widgets fall into a number of types:- | |||
62 | o Mic - Mic (and optional Jack) | 62 | o Mic - Mic (and optional Jack) |
63 | o Line - Line Input/Output (and optional Jack) | 63 | o Line - Line Input/Output (and optional Jack) |
64 | o Speaker - Speaker | 64 | o Speaker - Speaker |
65 | o Supply - Power or clock supply widget used by other widgets. | ||
65 | o Pre - Special PRE widget (exec before all others) | 66 | o Pre - Special PRE widget (exec before all others) |
66 | o Post - Special POST widget (exec after all others) | 67 | o Post - Special POST widget (exec after all others) |
67 | 68 | ||
diff --git a/MAINTAINERS b/MAINTAINERS index ef03abed595a..17c8ec119d4f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -4544,7 +4544,8 @@ F: drivers/pcmcia/pxa2xx* | |||
4544 | F: drivers/spi/pxa2xx* | 4544 | F: drivers/spi/pxa2xx* |
4545 | F: drivers/usb/gadget/pxa2* | 4545 | F: drivers/usb/gadget/pxa2* |
4546 | F: include/sound/pxa2xx-lib.h | 4546 | F: include/sound/pxa2xx-lib.h |
4547 | F: sound/soc/pxa/pxa2xx* | 4547 | F: sound/arm/pxa* |
4548 | F: sound/soc/pxa | ||
4548 | 4549 | ||
4549 | PXA168 SUPPORT | 4550 | PXA168 SUPPORT |
4550 | P: Eric Miao | 4551 | P: Eric Miao |
@@ -5277,6 +5278,7 @@ L: alsa-devel@alsa-project.org (subscribers-only) | |||
5277 | W: http://alsa-project.org/main/index.php/ASoC | 5278 | W: http://alsa-project.org/main/index.php/ASoC |
5278 | S: Supported | 5279 | S: Supported |
5279 | F: sound/soc/ | 5280 | F: sound/soc/ |
5281 | F: include/sound/soc* | ||
5280 | 5282 | ||
5281 | SPARC + UltraSPARC (sparc/sparc64) | 5283 | SPARC + UltraSPARC (sparc/sparc64) |
5282 | P: David S. Miller | 5284 | P: David S. Miller |
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h index 13676472ddfc..496dc30457b7 100644 --- a/include/sound/soc-dai.h +++ b/include/sound/soc-dai.h | |||
@@ -45,24 +45,6 @@ struct snd_pcm_substream; | |||
45 | #define SND_SOC_DAIFMT_GATED (1 << 4) /* clock is gated */ | 45 | #define SND_SOC_DAIFMT_GATED (1 << 4) /* clock is gated */ |
46 | 46 | ||
47 | /* | 47 | /* |
48 | * DAI Left/Right Clocks. | ||
49 | * | ||
50 | * Specifies whether the DAI can support different samples for similtanious | ||
51 | * playback and capture. This usually requires a seperate physical frame | ||
52 | * clock for playback and capture. | ||
53 | */ | ||
54 | #define SND_SOC_DAIFMT_SYNC (0 << 5) /* Tx FRM = Rx FRM */ | ||
55 | #define SND_SOC_DAIFMT_ASYNC (1 << 5) /* Tx FRM ~ Rx FRM */ | ||
56 | |||
57 | /* | ||
58 | * TDM | ||
59 | * | ||
60 | * Time Division Multiplexing. Allows PCM data to be multplexed with other | ||
61 | * data on the DAI. | ||
62 | */ | ||
63 | #define SND_SOC_DAIFMT_TDM (1 << 6) | ||
64 | |||
65 | /* | ||
66 | * DAI hardware signal inversions. | 48 | * DAI hardware signal inversions. |
67 | * | 49 | * |
68 | * Specifies whether the DAI can also support inverted clocks for the specified | 50 | * Specifies whether the DAI can also support inverted clocks for the specified |
@@ -96,6 +78,9 @@ struct snd_pcm_substream; | |||
96 | #define SND_SOC_CLOCK_IN 0 | 78 | #define SND_SOC_CLOCK_IN 0 |
97 | #define SND_SOC_CLOCK_OUT 1 | 79 | #define SND_SOC_CLOCK_OUT 1 |
98 | 80 | ||
81 | #define SND_SOC_STD_AC97_FMTS (SNDRV_PCM_FMTBIT_S16_LE |\ | ||
82 | SNDRV_PCM_FMTBIT_S32_LE) | ||
83 | |||
99 | struct snd_soc_dai_ops; | 84 | struct snd_soc_dai_ops; |
100 | struct snd_soc_dai; | 85 | struct snd_soc_dai; |
101 | struct snd_ac97_bus_ops; | 86 | struct snd_ac97_bus_ops; |
@@ -208,6 +193,7 @@ struct snd_soc_dai { | |||
208 | /* DAI capabilities */ | 193 | /* DAI capabilities */ |
209 | struct snd_soc_pcm_stream capture; | 194 | struct snd_soc_pcm_stream capture; |
210 | struct snd_soc_pcm_stream playback; | 195 | struct snd_soc_pcm_stream playback; |
196 | unsigned int symmetric_rates:1; | ||
211 | 197 | ||
212 | /* DAI runtime info */ | 198 | /* DAI runtime info */ |
213 | struct snd_pcm_runtime *runtime; | 199 | struct snd_pcm_runtime *runtime; |
@@ -219,11 +205,8 @@ struct snd_soc_dai { | |||
219 | /* DAI private data */ | 205 | /* DAI private data */ |
220 | void *private_data; | 206 | void *private_data; |
221 | 207 | ||
222 | /* parent codec/platform */ | 208 | /* parent platform */ |
223 | union { | 209 | struct snd_soc_platform *platform; |
224 | struct snd_soc_codec *codec; | ||
225 | struct snd_soc_platform *platform; | ||
226 | }; | ||
227 | 210 | ||
228 | struct list_head list; | 211 | struct list_head list; |
229 | }; | 212 | }; |
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index a7def6a9a030..533f9f256496 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h | |||
@@ -140,16 +140,30 @@ | |||
140 | #define SND_SOC_DAPM_DAC(wname, stname, wreg, wshift, winvert) \ | 140 | #define SND_SOC_DAPM_DAC(wname, stname, wreg, wshift, winvert) \ |
141 | { .id = snd_soc_dapm_dac, .name = wname, .sname = stname, .reg = wreg, \ | 141 | { .id = snd_soc_dapm_dac, .name = wname, .sname = stname, .reg = wreg, \ |
142 | .shift = wshift, .invert = winvert} | 142 | .shift = wshift, .invert = winvert} |
143 | #define SND_SOC_DAPM_DAC_E(wname, stname, wreg, wshift, winvert, \ | ||
144 | wevent, wflags) \ | ||
145 | { .id = snd_soc_dapm_dac, .name = wname, .sname = stname, .reg = wreg, \ | ||
146 | .shift = wshift, .invert = winvert, \ | ||
147 | .event = wevent, .event_flags = wflags} | ||
143 | #define SND_SOC_DAPM_ADC(wname, stname, wreg, wshift, winvert) \ | 148 | #define SND_SOC_DAPM_ADC(wname, stname, wreg, wshift, winvert) \ |
144 | { .id = snd_soc_dapm_adc, .name = wname, .sname = stname, .reg = wreg, \ | 149 | { .id = snd_soc_dapm_adc, .name = wname, .sname = stname, .reg = wreg, \ |
145 | .shift = wshift, .invert = winvert} | 150 | .shift = wshift, .invert = winvert} |
151 | #define SND_SOC_DAPM_ADC_E(wname, stname, wreg, wshift, winvert, \ | ||
152 | wevent, wflags) \ | ||
153 | { .id = snd_soc_dapm_adc, .name = wname, .sname = stname, .reg = wreg, \ | ||
154 | .shift = wshift, .invert = winvert, \ | ||
155 | .event = wevent, .event_flags = wflags} | ||
146 | 156 | ||
147 | /* generic register modifier widget */ | 157 | /* generic widgets */ |
148 | #define SND_SOC_DAPM_REG(wid, wname, wreg, wshift, wmask, won_val, woff_val) \ | 158 | #define SND_SOC_DAPM_REG(wid, wname, wreg, wshift, wmask, won_val, woff_val) \ |
149 | { .id = wid, .name = wname, .kcontrols = NULL, .num_kcontrols = 0, \ | 159 | { .id = wid, .name = wname, .kcontrols = NULL, .num_kcontrols = 0, \ |
150 | .reg = -((wreg) + 1), .shift = wshift, .mask = wmask, \ | 160 | .reg = -((wreg) + 1), .shift = wshift, .mask = wmask, \ |
151 | .on_val = won_val, .off_val = woff_val, .event = dapm_reg_event, \ | 161 | .on_val = won_val, .off_val = woff_val, .event = dapm_reg_event, \ |
152 | .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD} | 162 | .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD} |
163 | #define SND_SOC_DAPM_SUPPLY(wname, wreg, wshift, winvert, wevent, wflags) \ | ||
164 | { .id = snd_soc_dapm_supply, .name = wname, .reg = wreg, \ | ||
165 | .shift = wshift, .invert = winvert, .event = wevent, \ | ||
166 | .event_flags = wflags} | ||
153 | 167 | ||
154 | /* dapm kcontrol types */ | 168 | /* dapm kcontrol types */ |
155 | #define SOC_DAPM_SINGLE(xname, reg, shift, max, invert) \ | 169 | #define SOC_DAPM_SINGLE(xname, reg, shift, max, invert) \ |
@@ -298,6 +312,7 @@ enum snd_soc_dapm_type { | |||
298 | snd_soc_dapm_vmid, /* codec bias/vmid - to minimise pops */ | 312 | snd_soc_dapm_vmid, /* codec bias/vmid - to minimise pops */ |
299 | snd_soc_dapm_pre, /* machine specific pre widget - exec first */ | 313 | snd_soc_dapm_pre, /* machine specific pre widget - exec first */ |
300 | snd_soc_dapm_post, /* machine specific post widget - exec last */ | 314 | snd_soc_dapm_post, /* machine specific post widget - exec last */ |
315 | snd_soc_dapm_supply, /* power/clock supply */ | ||
301 | }; | 316 | }; |
302 | 317 | ||
303 | /* | 318 | /* |
@@ -357,6 +372,8 @@ struct snd_soc_dapm_widget { | |||
357 | unsigned char suspend:1; /* was active before suspend */ | 372 | unsigned char suspend:1; /* was active before suspend */ |
358 | unsigned char pmdown:1; /* waiting for timeout */ | 373 | unsigned char pmdown:1; /* waiting for timeout */ |
359 | 374 | ||
375 | int (*power_check)(struct snd_soc_dapm_widget *w); | ||
376 | |||
360 | /* external events */ | 377 | /* external events */ |
361 | unsigned short event_flags; /* flags to specify event types */ | 378 | unsigned short event_flags; /* flags to specify event types */ |
362 | int (*event)(struct snd_soc_dapm_widget*, struct snd_kcontrol *, int); | 379 | int (*event)(struct snd_soc_dapm_widget*, struct snd_kcontrol *, int); |
diff --git a/include/sound/soc.h b/include/sound/soc.h index a40bc6f316fc..6ab80bf7abd2 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h | |||
@@ -118,6 +118,14 @@ | |||
118 | .info = snd_soc_info_volsw, \ | 118 | .info = snd_soc_info_volsw, \ |
119 | .get = xhandler_get, .put = xhandler_put, \ | 119 | .get = xhandler_get, .put = xhandler_put, \ |
120 | .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) } | 120 | .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) } |
121 | #define SOC_DOUBLE_EXT(xname, xreg, shift_left, shift_right, xmax, xinvert,\ | ||
122 | xhandler_get, xhandler_put) \ | ||
123 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ | ||
124 | .info = snd_soc_info_volsw, \ | ||
125 | .get = xhandler_get, .put = xhandler_put, \ | ||
126 | .private_value = (unsigned long)&(struct soc_mixer_control) \ | ||
127 | {.reg = xreg, .shift = shift_left, .rshift = shift_right, \ | ||
128 | .max = xmax, .invert = xinvert} } | ||
121 | #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\ | 129 | #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\ |
122 | xhandler_get, xhandler_put, tlv_array) \ | 130 | xhandler_get, xhandler_put, tlv_array) \ |
123 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ | 131 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
@@ -417,6 +425,12 @@ struct snd_soc_dai_link { | |||
417 | /* codec/machine specific init - e.g. add machine controls */ | 425 | /* codec/machine specific init - e.g. add machine controls */ |
418 | int (*init)(struct snd_soc_codec *codec); | 426 | int (*init)(struct snd_soc_codec *codec); |
419 | 427 | ||
428 | /* Symmetry requirements */ | ||
429 | unsigned int symmetric_rates:1; | ||
430 | |||
431 | /* Symmetry data - only valid if symmetry is being enforced */ | ||
432 | unsigned int rate; | ||
433 | |||
420 | /* DAI pcm */ | 434 | /* DAI pcm */ |
421 | struct snd_pcm *pcm; | 435 | struct snd_pcm *pcm; |
422 | }; | 436 | }; |
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig index 3d2bb6fc6dcc..3304f9dd92fa 100644 --- a/sound/soc/Kconfig +++ b/sound/soc/Kconfig | |||
@@ -32,6 +32,7 @@ source "sound/soc/fsl/Kconfig" | |||
32 | source "sound/soc/omap/Kconfig" | 32 | source "sound/soc/omap/Kconfig" |
33 | source "sound/soc/pxa/Kconfig" | 33 | source "sound/soc/pxa/Kconfig" |
34 | source "sound/soc/s3c24xx/Kconfig" | 34 | source "sound/soc/s3c24xx/Kconfig" |
35 | source "sound/soc/s6000/Kconfig" | ||
35 | source "sound/soc/sh/Kconfig" | 36 | source "sound/soc/sh/Kconfig" |
36 | 37 | ||
37 | # Supported codecs | 38 | # Supported codecs |
diff --git a/sound/soc/Makefile b/sound/soc/Makefile index 0237879fd412..8943a140c818 100644 --- a/sound/soc/Makefile +++ b/sound/soc/Makefile | |||
@@ -10,4 +10,5 @@ obj-$(CONFIG_SND_SOC) += fsl/ | |||
10 | obj-$(CONFIG_SND_SOC) += omap/ | 10 | obj-$(CONFIG_SND_SOC) += omap/ |
11 | obj-$(CONFIG_SND_SOC) += pxa/ | 11 | obj-$(CONFIG_SND_SOC) += pxa/ |
12 | obj-$(CONFIG_SND_SOC) += s3c24xx/ | 12 | obj-$(CONFIG_SND_SOC) += s3c24xx/ |
13 | obj-$(CONFIG_SND_SOC) += s6000/ | ||
13 | obj-$(CONFIG_SND_SOC) += sh/ | 14 | obj-$(CONFIG_SND_SOC) += sh/ |
diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig index a608d7009dbd..e720d5e6f04c 100644 --- a/sound/soc/atmel/Kconfig +++ b/sound/soc/atmel/Kconfig | |||
@@ -41,3 +41,11 @@ config SND_AT32_SOC_PLAYPAQ_SLAVE | |||
41 | and FRAME signals on the PlayPaq. Unless you want to play | 41 | and FRAME signals on the PlayPaq. Unless you want to play |
42 | with the AT32 as the SSC master, you probably want to say N here, | 42 | with the AT32 as the SSC master, you probably want to say N here, |
43 | as this will give you better sound quality. | 43 | as this will give you better sound quality. |
44 | |||
45 | config SND_AT91_SOC_AFEB9260 | ||
46 | tristate "SoC Audio support for AFEB9260 board" | ||
47 | depends on ARCH_AT91 && MACH_AFEB9260 && SND_ATMEL_SOC | ||
48 | select SND_ATMEL_SOC_SSC | ||
49 | select SND_SOC_TLV320AIC23 | ||
50 | help | ||
51 | Say Y here to support sound on AFEB9260 board. | ||
diff --git a/sound/soc/atmel/Makefile b/sound/soc/atmel/Makefile index f54a7cc68e66..e7ea56bd5f82 100644 --- a/sound/soc/atmel/Makefile +++ b/sound/soc/atmel/Makefile | |||
@@ -13,3 +13,4 @@ snd-soc-playpaq-objs := playpaq_wm8510.o | |||
13 | 13 | ||
14 | obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o | 14 | obj-$(CONFIG_SND_AT91_SOC_SAM9G20_WM8731) += snd-soc-sam9g20-wm8731.o |
15 | obj-$(CONFIG_SND_AT32_SOC_PLAYPAQ) += snd-soc-playpaq.o | 15 | obj-$(CONFIG_SND_AT32_SOC_PLAYPAQ) += snd-soc-playpaq.o |
16 | obj-$(CONFIG_SND_AT91_SOC_AFEB9260) += snd-soc-afeb9260.o | ||
diff --git a/sound/soc/atmel/snd-soc-afeb9260.c b/sound/soc/atmel/snd-soc-afeb9260.c new file mode 100644 index 000000000000..23349de27313 --- /dev/null +++ b/sound/soc/atmel/snd-soc-afeb9260.c | |||
@@ -0,0 +1,203 @@ | |||
1 | /* | ||
2 | * afeb9260.c -- SoC audio for AFEB9260 | ||
3 | * | ||
4 | * Copyright (C) 2009 Sergey Lapin <slapin@ossfans.org> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * version 2 as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, but | ||
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
18 | * 02110-1301 USA | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/moduleparam.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/clk.h> | ||
26 | #include <linux/platform_device.h> | ||
27 | |||
28 | #include <linux/atmel-ssc.h> | ||
29 | #include <sound/core.h> | ||
30 | #include <sound/pcm.h> | ||
31 | #include <sound/pcm_params.h> | ||
32 | #include <sound/soc.h> | ||
33 | #include <sound/soc-dapm.h> | ||
34 | |||
35 | #include <asm/mach-types.h> | ||
36 | #include <mach/hardware.h> | ||
37 | #include <linux/gpio.h> | ||
38 | |||
39 | #include "../codecs/tlv320aic23.h" | ||
40 | #include "atmel-pcm.h" | ||
41 | #include "atmel_ssc_dai.h" | ||
42 | |||
43 | #define CODEC_CLOCK 12000000 | ||
44 | |||
45 | static int afeb9260_hw_params(struct snd_pcm_substream *substream, | ||
46 | struct snd_pcm_hw_params *params) | ||
47 | { | ||
48 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
49 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; | ||
50 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | ||
51 | int err; | ||
52 | |||
53 | /* Set codec DAI configuration */ | ||
54 | err = snd_soc_dai_set_fmt(codec_dai, | ||
55 | SND_SOC_DAIFMT_I2S| | ||
56 | SND_SOC_DAIFMT_NB_IF | | ||
57 | SND_SOC_DAIFMT_CBM_CFM); | ||
58 | if (err < 0) { | ||
59 | printk(KERN_ERR "can't set codec DAI configuration\n"); | ||
60 | return err; | ||
61 | } | ||
62 | |||
63 | /* Set cpu DAI configuration */ | ||
64 | err = snd_soc_dai_set_fmt(cpu_dai, | ||
65 | SND_SOC_DAIFMT_I2S | | ||
66 | SND_SOC_DAIFMT_NB_IF | | ||
67 | SND_SOC_DAIFMT_CBM_CFM); | ||
68 | if (err < 0) { | ||
69 | printk(KERN_ERR "can't set cpu DAI configuration\n"); | ||
70 | return err; | ||
71 | } | ||
72 | |||
73 | /* Set the codec system clock for DAC and ADC */ | ||
74 | err = | ||
75 | snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN); | ||
76 | |||
77 | if (err < 0) { | ||
78 | printk(KERN_ERR "can't set codec system clock\n"); | ||
79 | return err; | ||
80 | } | ||
81 | |||
82 | return err; | ||
83 | } | ||
84 | |||
85 | static struct snd_soc_ops afeb9260_ops = { | ||
86 | .hw_params = afeb9260_hw_params, | ||
87 | }; | ||
88 | |||
89 | static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = { | ||
90 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | ||
91 | SND_SOC_DAPM_LINE("Line In", NULL), | ||
92 | SND_SOC_DAPM_MIC("Mic Jack", NULL), | ||
93 | }; | ||
94 | |||
95 | static const struct snd_soc_dapm_route audio_map[] = { | ||
96 | {"Headphone Jack", NULL, "LHPOUT"}, | ||
97 | {"Headphone Jack", NULL, "RHPOUT"}, | ||
98 | |||
99 | {"LLINEIN", NULL, "Line In"}, | ||
100 | {"RLINEIN", NULL, "Line In"}, | ||
101 | |||
102 | {"MICIN", NULL, "Mic Jack"}, | ||
103 | }; | ||
104 | |||
105 | static int afeb9260_tlv320aic23_init(struct snd_soc_codec *codec) | ||
106 | { | ||
107 | |||
108 | /* Add afeb9260 specific widgets */ | ||
109 | snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets, | ||
110 | ARRAY_SIZE(tlv320aic23_dapm_widgets)); | ||
111 | |||
112 | /* Set up afeb9260 specific audio path audio_map */ | ||
113 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | ||
114 | |||
115 | snd_soc_dapm_enable_pin(codec, "Headphone Jack"); | ||
116 | snd_soc_dapm_enable_pin(codec, "Line In"); | ||
117 | snd_soc_dapm_enable_pin(codec, "Mic Jack"); | ||
118 | |||
119 | snd_soc_dapm_sync(codec); | ||
120 | |||
121 | return 0; | ||
122 | } | ||
123 | |||
124 | /* Digital audio interface glue - connects codec <--> CPU */ | ||
125 | static struct snd_soc_dai_link afeb9260_dai = { | ||
126 | .name = "TLV320AIC23", | ||
127 | .stream_name = "AIC23", | ||
128 | .cpu_dai = &atmel_ssc_dai[0], | ||
129 | .codec_dai = &tlv320aic23_dai, | ||
130 | .init = afeb9260_tlv320aic23_init, | ||
131 | .ops = &afeb9260_ops, | ||
132 | }; | ||
133 | |||
134 | /* Audio machine driver */ | ||
135 | static struct snd_soc_card snd_soc_machine_afeb9260 = { | ||
136 | .name = "AFEB9260", | ||
137 | .platform = &atmel_soc_platform, | ||
138 | .dai_link = &afeb9260_dai, | ||
139 | .num_links = 1, | ||
140 | }; | ||
141 | |||
142 | /* Audio subsystem */ | ||
143 | static struct snd_soc_device afeb9260_snd_devdata = { | ||
144 | .card = &snd_soc_machine_afeb9260, | ||
145 | .codec_dev = &soc_codec_dev_tlv320aic23, | ||
146 | }; | ||
147 | |||
148 | static struct platform_device *afeb9260_snd_device; | ||
149 | |||
150 | static int __init afeb9260_soc_init(void) | ||
151 | { | ||
152 | int err; | ||
153 | struct device *dev; | ||
154 | struct atmel_ssc_info *ssc_p = afeb9260_dai.cpu_dai->private_data; | ||
155 | struct ssc_device *ssc = NULL; | ||
156 | |||
157 | if (!(machine_is_afeb9260())) | ||
158 | return -ENODEV; | ||
159 | |||
160 | ssc = ssc_request(0); | ||
161 | if (IS_ERR(ssc)) { | ||
162 | printk(KERN_ERR "ASoC: Failed to request SSC 0\n"); | ||
163 | err = PTR_ERR(ssc); | ||
164 | ssc = NULL; | ||
165 | goto err_ssc; | ||
166 | } | ||
167 | ssc_p->ssc = ssc; | ||
168 | |||
169 | afeb9260_snd_device = platform_device_alloc("soc-audio", -1); | ||
170 | if (!afeb9260_snd_device) { | ||
171 | printk(KERN_ERR "ASoC: Platform device allocation failed\n"); | ||
172 | return -ENOMEM; | ||
173 | } | ||
174 | |||
175 | platform_set_drvdata(afeb9260_snd_device, &afeb9260_snd_devdata); | ||
176 | afeb9260_snd_devdata.dev = &afeb9260_snd_device->dev; | ||
177 | err = platform_device_add(afeb9260_snd_device); | ||
178 | if (err) | ||
179 | goto err1; | ||
180 | |||
181 | dev = &afeb9260_snd_device->dev; | ||
182 | |||
183 | return 0; | ||
184 | err1: | ||
185 | platform_device_del(afeb9260_snd_device); | ||
186 | platform_device_put(afeb9260_snd_device); | ||
187 | err_ssc: | ||
188 | return err; | ||
189 | |||
190 | } | ||
191 | |||
192 | static void __exit afeb9260_soc_exit(void) | ||
193 | { | ||
194 | platform_device_unregister(afeb9260_snd_device); | ||
195 | } | ||
196 | |||
197 | module_init(afeb9260_soc_init); | ||
198 | module_exit(afeb9260_soc_exit); | ||
199 | |||
200 | MODULE_AUTHOR("Sergey Lapin <slapin@ossfans.org>"); | ||
201 | MODULE_DESCRIPTION("ALSA SoC for AFEB9260"); | ||
202 | MODULE_LICENSE("GPL"); | ||
203 | |||
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index b6c7f7a01cb0..1c19ad54a9f9 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig | |||
@@ -35,7 +35,10 @@ config SND_SOC_ALL_CODECS | |||
35 | select SND_SOC_WM8753 if SND_SOC_I2C_AND_SPI | 35 | select SND_SOC_WM8753 if SND_SOC_I2C_AND_SPI |
36 | select SND_SOC_WM8900 if I2C | 36 | select SND_SOC_WM8900 if I2C |
37 | select SND_SOC_WM8903 if I2C | 37 | select SND_SOC_WM8903 if I2C |
38 | select SND_SOC_WM8940 if I2C | ||
39 | select SND_SOC_WM8960 if I2C | ||
38 | select SND_SOC_WM8971 if I2C | 40 | select SND_SOC_WM8971 if I2C |
41 | select SND_SOC_WM8988 if SND_SOC_I2C_AND_SPI | ||
39 | select SND_SOC_WM8990 if I2C | 42 | select SND_SOC_WM8990 if I2C |
40 | select SND_SOC_WM9705 if SND_SOC_AC97_BUS | 43 | select SND_SOC_WM9705 if SND_SOC_AC97_BUS |
41 | select SND_SOC_WM9712 if SND_SOC_AC97_BUS | 44 | select SND_SOC_WM9712 if SND_SOC_AC97_BUS |
@@ -138,9 +141,18 @@ config SND_SOC_WM8900 | |||
138 | config SND_SOC_WM8903 | 141 | config SND_SOC_WM8903 |
139 | tristate | 142 | tristate |
140 | 143 | ||
144 | config SND_SOC_WM8940 | ||
145 | tristate | ||
146 | |||
147 | config SND_SOC_WM8960 | ||
148 | tristate | ||
149 | |||
141 | config SND_SOC_WM8971 | 150 | config SND_SOC_WM8971 |
142 | tristate | 151 | tristate |
143 | 152 | ||
153 | config SND_SOC_WM8988 | ||
154 | tristate | ||
155 | |||
144 | config SND_SOC_WM8990 | 156 | config SND_SOC_WM8990 |
145 | tristate | 157 | tristate |
146 | 158 | ||
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index f2653803ede8..3d31b6bea834 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile | |||
@@ -23,7 +23,10 @@ snd-soc-wm8750-objs := wm8750.o | |||
23 | snd-soc-wm8753-objs := wm8753.o | 23 | snd-soc-wm8753-objs := wm8753.o |
24 | snd-soc-wm8900-objs := wm8900.o | 24 | snd-soc-wm8900-objs := wm8900.o |
25 | snd-soc-wm8903-objs := wm8903.o | 25 | snd-soc-wm8903-objs := wm8903.o |
26 | snd-soc-wm8940-objs := wm8940.o | ||
27 | snd-soc-wm8960-objs := wm8960.o | ||
26 | snd-soc-wm8971-objs := wm8971.o | 28 | snd-soc-wm8971-objs := wm8971.o |
29 | snd-soc-wm8988-objs := wm8988.o | ||
27 | snd-soc-wm8990-objs := wm8990.o | 30 | snd-soc-wm8990-objs := wm8990.o |
28 | snd-soc-wm9705-objs := wm9705.o | 31 | snd-soc-wm9705-objs := wm9705.o |
29 | snd-soc-wm9712-objs := wm9712.o | 32 | snd-soc-wm9712-objs := wm9712.o |
@@ -55,6 +58,9 @@ obj-$(CONFIG_SND_SOC_WM8753) += snd-soc-wm8753.o | |||
55 | obj-$(CONFIG_SND_SOC_WM8900) += snd-soc-wm8900.o | 58 | obj-$(CONFIG_SND_SOC_WM8900) += snd-soc-wm8900.o |
56 | obj-$(CONFIG_SND_SOC_WM8903) += snd-soc-wm8903.o | 59 | obj-$(CONFIG_SND_SOC_WM8903) += snd-soc-wm8903.o |
57 | obj-$(CONFIG_SND_SOC_WM8971) += snd-soc-wm8971.o | 60 | obj-$(CONFIG_SND_SOC_WM8971) += snd-soc-wm8971.o |
61 | obj-$(CONFIG_SND_SOC_WM8940) += snd-soc-wm8940.o | ||
62 | obj-$(CONFIG_SND_SOC_WM8960) += snd-soc-wm8960.o | ||
63 | obj-$(CONFIG_SND_SOC_WM8988) += snd-soc-wm8988.o | ||
58 | obj-$(CONFIG_SND_SOC_WM8990) += snd-soc-wm8990.o | 64 | obj-$(CONFIG_SND_SOC_WM8990) += snd-soc-wm8990.o |
59 | obj-$(CONFIG_SND_SOC_WM9705) += snd-soc-wm9705.o | 65 | obj-$(CONFIG_SND_SOC_WM9705) += snd-soc-wm9705.o |
60 | obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o | 66 | obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o |
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c index b0d4af145b87..932299bb5d1e 100644 --- a/sound/soc/codecs/ac97.c +++ b/sound/soc/codecs/ac97.c | |||
@@ -53,13 +53,13 @@ struct snd_soc_dai ac97_dai = { | |||
53 | .channels_min = 1, | 53 | .channels_min = 1, |
54 | .channels_max = 2, | 54 | .channels_max = 2, |
55 | .rates = STD_AC97_RATES, | 55 | .rates = STD_AC97_RATES, |
56 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 56 | .formats = SND_SOC_STD_AC97_FMTS,}, |
57 | .capture = { | 57 | .capture = { |
58 | .stream_name = "AC97 Capture", | 58 | .stream_name = "AC97 Capture", |
59 | .channels_min = 1, | 59 | .channels_min = 1, |
60 | .channels_max = 2, | 60 | .channels_max = 2, |
61 | .rates = STD_AC97_RATES, | 61 | .rates = STD_AC97_RATES, |
62 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 62 | .formats = SND_SOC_STD_AC97_FMTS,}, |
63 | .ops = &ac97_dai_ops, | 63 | .ops = &ac97_dai_ops, |
64 | }; | 64 | }; |
65 | EXPORT_SYMBOL_GPL(ac97_dai); | 65 | EXPORT_SYMBOL_GPL(ac97_dai); |
diff --git a/sound/soc/codecs/ad1980.c b/sound/soc/codecs/ad1980.c index ddb3b08ac23c..d7440a982d22 100644 --- a/sound/soc/codecs/ad1980.c +++ b/sound/soc/codecs/ad1980.c | |||
@@ -137,13 +137,13 @@ struct snd_soc_dai ad1980_dai = { | |||
137 | .channels_min = 2, | 137 | .channels_min = 2, |
138 | .channels_max = 6, | 138 | .channels_max = 6, |
139 | .rates = SNDRV_PCM_RATE_48000, | 139 | .rates = SNDRV_PCM_RATE_48000, |
140 | .formats = SNDRV_PCM_FMTBIT_S16_LE, }, | 140 | .formats = SND_SOC_STD_AC97_FMTS, }, |
141 | .capture = { | 141 | .capture = { |
142 | .stream_name = "Capture", | 142 | .stream_name = "Capture", |
143 | .channels_min = 2, | 143 | .channels_min = 2, |
144 | .channels_max = 2, | 144 | .channels_max = 2, |
145 | .rates = SNDRV_PCM_RATE_48000, | 145 | .rates = SNDRV_PCM_RATE_48000, |
146 | .formats = SNDRV_PCM_FMTBIT_S16_LE, }, | 146 | .formats = SND_SOC_STD_AC97_FMTS, }, |
147 | }; | 147 | }; |
148 | EXPORT_SYMBOL_GPL(ad1980_dai); | 148 | EXPORT_SYMBOL_GPL(ad1980_dai); |
149 | 149 | ||
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 7fa09a387622..a32b8226c8a4 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c | |||
@@ -18,7 +18,7 @@ | |||
18 | * - The machine driver's 'startup' function must call | 18 | * - The machine driver's 'startup' function must call |
19 | * cs4270_set_dai_sysclk() with the value of MCLK. | 19 | * cs4270_set_dai_sysclk() with the value of MCLK. |
20 | * - Only I2S and left-justified modes are supported | 20 | * - Only I2S and left-justified modes are supported |
21 | * - Power management is not supported | 21 | * - Power management is supported |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
@@ -27,6 +27,7 @@ | |||
27 | #include <sound/soc.h> | 27 | #include <sound/soc.h> |
28 | #include <sound/initval.h> | 28 | #include <sound/initval.h> |
29 | #include <linux/i2c.h> | 29 | #include <linux/i2c.h> |
30 | #include <linux/delay.h> | ||
30 | 31 | ||
31 | #include "cs4270.h" | 32 | #include "cs4270.h" |
32 | 33 | ||
@@ -56,6 +57,7 @@ | |||
56 | #define CS4270_FIRSTREG 0x01 | 57 | #define CS4270_FIRSTREG 0x01 |
57 | #define CS4270_LASTREG 0x08 | 58 | #define CS4270_LASTREG 0x08 |
58 | #define CS4270_NUMREGS (CS4270_LASTREG - CS4270_FIRSTREG + 1) | 59 | #define CS4270_NUMREGS (CS4270_LASTREG - CS4270_FIRSTREG + 1) |
60 | #define CS4270_I2C_INCR 0x80 | ||
59 | 61 | ||
60 | /* Bit masks for the CS4270 registers */ | 62 | /* Bit masks for the CS4270 registers */ |
61 | #define CS4270_CHIPID_ID 0xF0 | 63 | #define CS4270_CHIPID_ID 0xF0 |
@@ -64,6 +66,8 @@ | |||
64 | #define CS4270_PWRCTL_PDN_ADC 0x20 | 66 | #define CS4270_PWRCTL_PDN_ADC 0x20 |
65 | #define CS4270_PWRCTL_PDN_DAC 0x02 | 67 | #define CS4270_PWRCTL_PDN_DAC 0x02 |
66 | #define CS4270_PWRCTL_PDN 0x01 | 68 | #define CS4270_PWRCTL_PDN 0x01 |
69 | #define CS4270_PWRCTL_PDN_ALL \ | ||
70 | (CS4270_PWRCTL_PDN_ADC | CS4270_PWRCTL_PDN_DAC | CS4270_PWRCTL_PDN) | ||
67 | #define CS4270_MODE_SPEED_MASK 0x30 | 71 | #define CS4270_MODE_SPEED_MASK 0x30 |
68 | #define CS4270_MODE_1X 0x00 | 72 | #define CS4270_MODE_1X 0x00 |
69 | #define CS4270_MODE_2X 0x10 | 73 | #define CS4270_MODE_2X 0x10 |
@@ -109,6 +113,7 @@ struct cs4270_private { | |||
109 | unsigned int mclk; /* Input frequency of the MCLK pin */ | 113 | unsigned int mclk; /* Input frequency of the MCLK pin */ |
110 | unsigned int mode; /* The mode (I2S or left-justified) */ | 114 | unsigned int mode; /* The mode (I2S or left-justified) */ |
111 | unsigned int slave_mode; | 115 | unsigned int slave_mode; |
116 | unsigned int manual_mute; | ||
112 | }; | 117 | }; |
113 | 118 | ||
114 | /** | 119 | /** |
@@ -295,7 +300,7 @@ static int cs4270_fill_cache(struct snd_soc_codec *codec) | |||
295 | s32 length; | 300 | s32 length; |
296 | 301 | ||
297 | length = i2c_smbus_read_i2c_block_data(i2c_client, | 302 | length = i2c_smbus_read_i2c_block_data(i2c_client, |
298 | CS4270_FIRSTREG | 0x80, CS4270_NUMREGS, cache); | 303 | CS4270_FIRSTREG | CS4270_I2C_INCR, CS4270_NUMREGS, cache); |
299 | 304 | ||
300 | if (length != CS4270_NUMREGS) { | 305 | if (length != CS4270_NUMREGS) { |
301 | dev_err(codec->dev, "i2c read failure, addr=0x%x\n", | 306 | dev_err(codec->dev, "i2c read failure, addr=0x%x\n", |
@@ -453,7 +458,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, | |||
453 | } | 458 | } |
454 | 459 | ||
455 | /** | 460 | /** |
456 | * cs4270_mute - enable/disable the CS4270 external mute | 461 | * cs4270_dai_mute - enable/disable the CS4270 external mute |
457 | * @dai: the SOC DAI | 462 | * @dai: the SOC DAI |
458 | * @mute: 0 = disable mute, 1 = enable mute | 463 | * @mute: 0 = disable mute, 1 = enable mute |
459 | * | 464 | * |
@@ -462,21 +467,52 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, | |||
462 | * board does not have the MUTEA or MUTEB pins connected to such circuitry, | 467 | * board does not have the MUTEA or MUTEB pins connected to such circuitry, |
463 | * then this function will do nothing. | 468 | * then this function will do nothing. |
464 | */ | 469 | */ |
465 | static int cs4270_mute(struct snd_soc_dai *dai, int mute) | 470 | static int cs4270_dai_mute(struct snd_soc_dai *dai, int mute) |
466 | { | 471 | { |
467 | struct snd_soc_codec *codec = dai->codec; | 472 | struct snd_soc_codec *codec = dai->codec; |
473 | struct cs4270_private *cs4270 = codec->private_data; | ||
468 | int reg6; | 474 | int reg6; |
469 | 475 | ||
470 | reg6 = snd_soc_read(codec, CS4270_MUTE); | 476 | reg6 = snd_soc_read(codec, CS4270_MUTE); |
471 | 477 | ||
472 | if (mute) | 478 | if (mute) |
473 | reg6 |= CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B; | 479 | reg6 |= CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B; |
474 | else | 480 | else { |
475 | reg6 &= ~(CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B); | 481 | reg6 &= ~(CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B); |
482 | reg6 |= cs4270->manual_mute; | ||
483 | } | ||
476 | 484 | ||
477 | return snd_soc_write(codec, CS4270_MUTE, reg6); | 485 | return snd_soc_write(codec, CS4270_MUTE, reg6); |
478 | } | 486 | } |
479 | 487 | ||
488 | /** | ||
489 | * cs4270_soc_put_mute - put callback for the 'Master Playback switch' | ||
490 | * alsa control. | ||
491 | * @kcontrol: mixer control | ||
492 | * @ucontrol: control element information | ||
493 | * | ||
494 | * This function basically passes the arguments on to the generic | ||
495 | * snd_soc_put_volsw() function and saves the mute information in | ||
496 | * our private data structure. This is because we want to prevent | ||
497 | * cs4270_dai_mute() neglecting the user's decision to manually | ||
498 | * mute the codec's output. | ||
499 | * | ||
500 | * Returns 0 for success. | ||
501 | */ | ||
502 | static int cs4270_soc_put_mute(struct snd_kcontrol *kcontrol, | ||
503 | struct snd_ctl_elem_value *ucontrol) | ||
504 | { | ||
505 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
506 | struct cs4270_private *cs4270 = codec->private_data; | ||
507 | int left = !ucontrol->value.integer.value[0]; | ||
508 | int right = !ucontrol->value.integer.value[1]; | ||
509 | |||
510 | cs4270->manual_mute = (left ? CS4270_MUTE_DAC_A : 0) | | ||
511 | (right ? CS4270_MUTE_DAC_B : 0); | ||
512 | |||
513 | return snd_soc_put_volsw(kcontrol, ucontrol); | ||
514 | } | ||
515 | |||
480 | /* A list of non-DAPM controls that the CS4270 supports */ | 516 | /* A list of non-DAPM controls that the CS4270 supports */ |
481 | static const struct snd_kcontrol_new cs4270_snd_controls[] = { | 517 | static const struct snd_kcontrol_new cs4270_snd_controls[] = { |
482 | SOC_DOUBLE_R("Master Playback Volume", | 518 | SOC_DOUBLE_R("Master Playback Volume", |
@@ -486,7 +522,9 @@ static const struct snd_kcontrol_new cs4270_snd_controls[] = { | |||
486 | SOC_SINGLE("Zero Cross Switch", CS4270_TRANS, 5, 1, 0), | 522 | SOC_SINGLE("Zero Cross Switch", CS4270_TRANS, 5, 1, 0), |
487 | SOC_SINGLE("Popguard Switch", CS4270_MODE, 0, 1, 1), | 523 | SOC_SINGLE("Popguard Switch", CS4270_MODE, 0, 1, 1), |
488 | SOC_SINGLE("Auto-Mute Switch", CS4270_MUTE, 5, 1, 0), | 524 | SOC_SINGLE("Auto-Mute Switch", CS4270_MUTE, 5, 1, 0), |
489 | SOC_DOUBLE("Master Capture Switch", CS4270_MUTE, 3, 4, 1, 0) | 525 | SOC_DOUBLE("Master Capture Switch", CS4270_MUTE, 3, 4, 1, 1), |
526 | SOC_DOUBLE_EXT("Master Playback Switch", CS4270_MUTE, 0, 1, 1, 1, | ||
527 | snd_soc_get_volsw, cs4270_soc_put_mute), | ||
490 | }; | 528 | }; |
491 | 529 | ||
492 | /* | 530 | /* |
@@ -506,7 +544,7 @@ static struct snd_soc_dai_ops cs4270_dai_ops = { | |||
506 | .hw_params = cs4270_hw_params, | 544 | .hw_params = cs4270_hw_params, |
507 | .set_sysclk = cs4270_set_dai_sysclk, | 545 | .set_sysclk = cs4270_set_dai_sysclk, |
508 | .set_fmt = cs4270_set_dai_fmt, | 546 | .set_fmt = cs4270_set_dai_fmt, |
509 | .digital_mute = cs4270_mute, | 547 | .digital_mute = cs4270_dai_mute, |
510 | }; | 548 | }; |
511 | 549 | ||
512 | struct snd_soc_dai cs4270_dai = { | 550 | struct snd_soc_dai cs4270_dai = { |
@@ -753,6 +791,57 @@ static struct i2c_device_id cs4270_id[] = { | |||
753 | }; | 791 | }; |
754 | MODULE_DEVICE_TABLE(i2c, cs4270_id); | 792 | MODULE_DEVICE_TABLE(i2c, cs4270_id); |
755 | 793 | ||
794 | #ifdef CONFIG_PM | ||
795 | |||
796 | /* This suspend/resume implementation can handle both - a simple standby | ||
797 | * where the codec remains powered, and a full suspend, where the voltage | ||
798 | * domain the codec is connected to is teared down and/or any other hardware | ||
799 | * reset condition is asserted. | ||
800 | * | ||
801 | * The codec's own power saving features are enabled in the suspend callback, | ||
802 | * and all registers are written back to the hardware when resuming. | ||
803 | */ | ||
804 | |||
805 | static int cs4270_i2c_suspend(struct i2c_client *client, pm_message_t mesg) | ||
806 | { | ||
807 | struct cs4270_private *cs4270 = i2c_get_clientdata(client); | ||
808 | struct snd_soc_codec *codec = &cs4270->codec; | ||
809 | int reg = snd_soc_read(codec, CS4270_PWRCTL) | CS4270_PWRCTL_PDN_ALL; | ||
810 | |||
811 | return snd_soc_write(codec, CS4270_PWRCTL, reg); | ||
812 | } | ||
813 | |||
814 | static int cs4270_i2c_resume(struct i2c_client *client) | ||
815 | { | ||
816 | struct cs4270_private *cs4270 = i2c_get_clientdata(client); | ||
817 | struct snd_soc_codec *codec = &cs4270->codec; | ||
818 | int reg; | ||
819 | |||
820 | /* In case the device was put to hard reset during sleep, we need to | ||
821 | * wait 500ns here before any I2C communication. */ | ||
822 | ndelay(500); | ||
823 | |||
824 | /* first restore the entire register cache ... */ | ||
825 | for (reg = CS4270_FIRSTREG; reg <= CS4270_LASTREG; reg++) { | ||
826 | u8 val = snd_soc_read(codec, reg); | ||
827 | |||
828 | if (i2c_smbus_write_byte_data(client, reg, val)) { | ||
829 | dev_err(codec->dev, "i2c write failed\n"); | ||
830 | return -EIO; | ||
831 | } | ||
832 | } | ||
833 | |||
834 | /* ... then disable the power-down bits */ | ||
835 | reg = snd_soc_read(codec, CS4270_PWRCTL); | ||
836 | reg &= ~CS4270_PWRCTL_PDN_ALL; | ||
837 | |||
838 | return snd_soc_write(codec, CS4270_PWRCTL, reg); | ||
839 | } | ||
840 | #else | ||
841 | #define cs4270_i2c_suspend NULL | ||
842 | #define cs4270_i2c_resume NULL | ||
843 | #endif /* CONFIG_PM */ | ||
844 | |||
756 | /* | 845 | /* |
757 | * cs4270_i2c_driver - I2C device identification | 846 | * cs4270_i2c_driver - I2C device identification |
758 | * | 847 | * |
@@ -767,6 +856,8 @@ static struct i2c_driver cs4270_i2c_driver = { | |||
767 | .id_table = cs4270_id, | 856 | .id_table = cs4270_id, |
768 | .probe = cs4270_i2c_probe, | 857 | .probe = cs4270_i2c_probe, |
769 | .remove = cs4270_i2c_remove, | 858 | .remove = cs4270_i2c_remove, |
859 | .suspend = cs4270_i2c_suspend, | ||
860 | .resume = cs4270_i2c_resume, | ||
770 | }; | 861 | }; |
771 | 862 | ||
772 | /* | 863 | /* |
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c index c3f4afb5d017..21f69df9994c 100644 --- a/sound/soc/codecs/tlv320aic23.c +++ b/sound/soc/codecs/tlv320aic23.c | |||
@@ -523,6 +523,8 @@ static int tlv320aic23_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
523 | case SND_SOC_DAIFMT_I2S: | 523 | case SND_SOC_DAIFMT_I2S: |
524 | iface_reg |= TLV320AIC23_FOR_I2S; | 524 | iface_reg |= TLV320AIC23_FOR_I2S; |
525 | break; | 525 | break; |
526 | case SND_SOC_DAIFMT_DSP_A: | ||
527 | iface_reg |= TLV320AIC23_LRP_ON; | ||
526 | case SND_SOC_DAIFMT_DSP_B: | 528 | case SND_SOC_DAIFMT_DSP_B: |
527 | iface_reg |= TLV320AIC23_FOR_DSP; | 529 | iface_reg |= TLV320AIC23_FOR_DSP; |
528 | break; | 530 | break; |
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c index df7c8c281d2f..eaf91ab465b4 100644 --- a/sound/soc/codecs/twl4030.c +++ b/sound/soc/codecs/twl4030.c | |||
@@ -125,6 +125,11 @@ struct twl4030_priv { | |||
125 | 125 | ||
126 | struct snd_pcm_substream *master_substream; | 126 | struct snd_pcm_substream *master_substream; |
127 | struct snd_pcm_substream *slave_substream; | 127 | struct snd_pcm_substream *slave_substream; |
128 | |||
129 | unsigned int configured; | ||
130 | unsigned int rate; | ||
131 | unsigned int sample_bits; | ||
132 | unsigned int channels; | ||
128 | }; | 133 | }; |
129 | 134 | ||
130 | /* | 135 | /* |
@@ -232,7 +237,7 @@ static void twl4030_codec_mute(struct snd_soc_codec *codec, int mute) | |||
232 | TWL4030_REG_PRECKL_CTL); | 237 | TWL4030_REG_PRECKL_CTL); |
233 | reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_PRECKR_CTL); | 238 | reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_PRECKR_CTL); |
234 | twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, | 239 | twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, |
235 | reg_val & (~TWL4030_PRECKL_GAIN), | 240 | reg_val & (~TWL4030_PRECKR_GAIN), |
236 | TWL4030_REG_PRECKR_CTL); | 241 | TWL4030_REG_PRECKR_CTL); |
237 | 242 | ||
238 | /* Disable PLL */ | 243 | /* Disable PLL */ |
@@ -316,104 +321,60 @@ static void twl4030_power_down(struct snd_soc_codec *codec) | |||
316 | } | 321 | } |
317 | 322 | ||
318 | /* Earpiece */ | 323 | /* Earpiece */ |
319 | static const char *twl4030_earpiece_texts[] = | 324 | static const struct snd_kcontrol_new twl4030_dapm_earpiece_controls[] = { |
320 | {"Off", "DACL1", "DACL2", "DACR1"}; | 325 | SOC_DAPM_SINGLE("Voice", TWL4030_REG_EAR_CTL, 0, 1, 0), |
321 | 326 | SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_EAR_CTL, 1, 1, 0), | |
322 | static const unsigned int twl4030_earpiece_values[] = | 327 | SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_EAR_CTL, 2, 1, 0), |
323 | {0x0, 0x1, 0x2, 0x4}; | 328 | SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_EAR_CTL, 3, 1, 0), |
324 | 329 | }; | |
325 | static const struct soc_enum twl4030_earpiece_enum = | ||
326 | SOC_VALUE_ENUM_SINGLE(TWL4030_REG_EAR_CTL, 1, 0x7, | ||
327 | ARRAY_SIZE(twl4030_earpiece_texts), | ||
328 | twl4030_earpiece_texts, | ||
329 | twl4030_earpiece_values); | ||
330 | |||
331 | static const struct snd_kcontrol_new twl4030_dapm_earpiece_control = | ||
332 | SOC_DAPM_VALUE_ENUM("Route", twl4030_earpiece_enum); | ||
333 | 330 | ||
334 | /* PreDrive Left */ | 331 | /* PreDrive Left */ |
335 | static const char *twl4030_predrivel_texts[] = | 332 | static const struct snd_kcontrol_new twl4030_dapm_predrivel_controls[] = { |
336 | {"Off", "DACL1", "DACL2", "DACR2"}; | 333 | SOC_DAPM_SINGLE("Voice", TWL4030_REG_PREDL_CTL, 0, 1, 0), |
337 | 334 | SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_PREDL_CTL, 1, 1, 0), | |
338 | static const unsigned int twl4030_predrivel_values[] = | 335 | SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_PREDL_CTL, 2, 1, 0), |
339 | {0x0, 0x1, 0x2, 0x4}; | 336 | SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_PREDL_CTL, 3, 1, 0), |
340 | 337 | }; | |
341 | static const struct soc_enum twl4030_predrivel_enum = | ||
342 | SOC_VALUE_ENUM_SINGLE(TWL4030_REG_PREDL_CTL, 1, 0x7, | ||
343 | ARRAY_SIZE(twl4030_predrivel_texts), | ||
344 | twl4030_predrivel_texts, | ||
345 | twl4030_predrivel_values); | ||
346 | |||
347 | static const struct snd_kcontrol_new twl4030_dapm_predrivel_control = | ||
348 | SOC_DAPM_VALUE_ENUM("Route", twl4030_predrivel_enum); | ||
349 | 338 | ||
350 | /* PreDrive Right */ | 339 | /* PreDrive Right */ |
351 | static const char *twl4030_predriver_texts[] = | 340 | static const struct snd_kcontrol_new twl4030_dapm_predriver_controls[] = { |
352 | {"Off", "DACR1", "DACR2", "DACL2"}; | 341 | SOC_DAPM_SINGLE("Voice", TWL4030_REG_PREDR_CTL, 0, 1, 0), |
353 | 342 | SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_PREDR_CTL, 1, 1, 0), | |
354 | static const unsigned int twl4030_predriver_values[] = | 343 | SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_PREDR_CTL, 2, 1, 0), |
355 | {0x0, 0x1, 0x2, 0x4}; | 344 | SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_PREDR_CTL, 3, 1, 0), |
356 | 345 | }; | |
357 | static const struct soc_enum twl4030_predriver_enum = | ||
358 | SOC_VALUE_ENUM_SINGLE(TWL4030_REG_PREDR_CTL, 1, 0x7, | ||
359 | ARRAY_SIZE(twl4030_predriver_texts), | ||
360 | twl4030_predriver_texts, | ||
361 | twl4030_predriver_values); | ||
362 | |||
363 | static const struct snd_kcontrol_new twl4030_dapm_predriver_control = | ||
364 | SOC_DAPM_VALUE_ENUM("Route", twl4030_predriver_enum); | ||
365 | 346 | ||
366 | /* Headset Left */ | 347 | /* Headset Left */ |
367 | static const char *twl4030_hsol_texts[] = | 348 | static const struct snd_kcontrol_new twl4030_dapm_hsol_controls[] = { |
368 | {"Off", "DACL1", "DACL2"}; | 349 | SOC_DAPM_SINGLE("Voice", TWL4030_REG_HS_SEL, 0, 1, 0), |
369 | 350 | SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_HS_SEL, 1, 1, 0), | |
370 | static const struct soc_enum twl4030_hsol_enum = | 351 | SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_HS_SEL, 2, 1, 0), |
371 | SOC_ENUM_SINGLE(TWL4030_REG_HS_SEL, 1, | 352 | }; |
372 | ARRAY_SIZE(twl4030_hsol_texts), | ||
373 | twl4030_hsol_texts); | ||
374 | |||
375 | static const struct snd_kcontrol_new twl4030_dapm_hsol_control = | ||
376 | SOC_DAPM_ENUM("Route", twl4030_hsol_enum); | ||
377 | 353 | ||
378 | /* Headset Right */ | 354 | /* Headset Right */ |
379 | static const char *twl4030_hsor_texts[] = | 355 | static const struct snd_kcontrol_new twl4030_dapm_hsor_controls[] = { |
380 | {"Off", "DACR1", "DACR2"}; | 356 | SOC_DAPM_SINGLE("Voice", TWL4030_REG_HS_SEL, 3, 1, 0), |
381 | 357 | SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_HS_SEL, 4, 1, 0), | |
382 | static const struct soc_enum twl4030_hsor_enum = | 358 | SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_HS_SEL, 5, 1, 0), |
383 | SOC_ENUM_SINGLE(TWL4030_REG_HS_SEL, 4, | 359 | }; |
384 | ARRAY_SIZE(twl4030_hsor_texts), | ||
385 | twl4030_hsor_texts); | ||
386 | |||
387 | static const struct snd_kcontrol_new twl4030_dapm_hsor_control = | ||
388 | SOC_DAPM_ENUM("Route", twl4030_hsor_enum); | ||
389 | 360 | ||
390 | /* Carkit Left */ | 361 | /* Carkit Left */ |
391 | static const char *twl4030_carkitl_texts[] = | 362 | static const struct snd_kcontrol_new twl4030_dapm_carkitl_controls[] = { |
392 | {"Off", "DACL1", "DACL2"}; | 363 | SOC_DAPM_SINGLE("Voice", TWL4030_REG_PRECKL_CTL, 0, 1, 0), |
393 | 364 | SOC_DAPM_SINGLE("AudioL1", TWL4030_REG_PRECKL_CTL, 1, 1, 0), | |
394 | static const struct soc_enum twl4030_carkitl_enum = | 365 | SOC_DAPM_SINGLE("AudioL2", TWL4030_REG_PRECKL_CTL, 2, 1, 0), |
395 | SOC_ENUM_SINGLE(TWL4030_REG_PRECKL_CTL, 1, | 366 | }; |
396 | ARRAY_SIZE(twl4030_carkitl_texts), | ||
397 | twl4030_carkitl_texts); | ||
398 | |||
399 | static const struct snd_kcontrol_new twl4030_dapm_carkitl_control = | ||
400 | SOC_DAPM_ENUM("Route", twl4030_carkitl_enum); | ||
401 | 367 | ||
402 | /* Carkit Right */ | 368 | /* Carkit Right */ |
403 | static const char *twl4030_carkitr_texts[] = | 369 | static const struct snd_kcontrol_new twl4030_dapm_carkitr_controls[] = { |
404 | {"Off", "DACR1", "DACR2"}; | 370 | SOC_DAPM_SINGLE("Voice", TWL4030_REG_PRECKR_CTL, 0, 1, 0), |
405 | 371 | SOC_DAPM_SINGLE("AudioR1", TWL4030_REG_PRECKR_CTL, 1, 1, 0), | |
406 | static const struct soc_enum twl4030_carkitr_enum = | 372 | SOC_DAPM_SINGLE("AudioR2", TWL4030_REG_PRECKR_CTL, 2, 1, 0), |
407 | SOC_ENUM_SINGLE(TWL4030_REG_PRECKR_CTL, 1, | 373 | }; |
408 | ARRAY_SIZE(twl4030_carkitr_texts), | ||
409 | twl4030_carkitr_texts); | ||
410 | |||
411 | static const struct snd_kcontrol_new twl4030_dapm_carkitr_control = | ||
412 | SOC_DAPM_ENUM("Route", twl4030_carkitr_enum); | ||
413 | 374 | ||
414 | /* Handsfree Left */ | 375 | /* Handsfree Left */ |
415 | static const char *twl4030_handsfreel_texts[] = | 376 | static const char *twl4030_handsfreel_texts[] = |
416 | {"Voice", "DACL1", "DACL2", "DACR2"}; | 377 | {"Voice", "AudioL1", "AudioL2", "AudioR2"}; |
417 | 378 | ||
418 | static const struct soc_enum twl4030_handsfreel_enum = | 379 | static const struct soc_enum twl4030_handsfreel_enum = |
419 | SOC_ENUM_SINGLE(TWL4030_REG_HFL_CTL, 0, | 380 | SOC_ENUM_SINGLE(TWL4030_REG_HFL_CTL, 0, |
@@ -425,7 +386,7 @@ SOC_DAPM_ENUM("Route", twl4030_handsfreel_enum); | |||
425 | 386 | ||
426 | /* Handsfree Right */ | 387 | /* Handsfree Right */ |
427 | static const char *twl4030_handsfreer_texts[] = | 388 | static const char *twl4030_handsfreer_texts[] = |
428 | {"Voice", "DACR1", "DACR2", "DACL2"}; | 389 | {"Voice", "AudioR1", "AudioR2", "AudioL2"}; |
429 | 390 | ||
430 | static const struct soc_enum twl4030_handsfreer_enum = | 391 | static const struct soc_enum twl4030_handsfreer_enum = |
431 | SOC_ENUM_SINGLE(TWL4030_REG_HFR_CTL, 0, | 392 | SOC_ENUM_SINGLE(TWL4030_REG_HFR_CTL, 0, |
@@ -435,37 +396,44 @@ static const struct soc_enum twl4030_handsfreer_enum = | |||
435 | static const struct snd_kcontrol_new twl4030_dapm_handsfreer_control = | 396 | static const struct snd_kcontrol_new twl4030_dapm_handsfreer_control = |
436 | SOC_DAPM_ENUM("Route", twl4030_handsfreer_enum); | 397 | SOC_DAPM_ENUM("Route", twl4030_handsfreer_enum); |
437 | 398 | ||
438 | /* Left analog microphone selection */ | 399 | /* Vibra */ |
439 | static const char *twl4030_analoglmic_texts[] = | 400 | /* Vibra audio path selection */ |
440 | {"Off", "Main mic", "Headset mic", "AUXL", "Carkit mic"}; | 401 | static const char *twl4030_vibra_texts[] = |
402 | {"AudioL1", "AudioR1", "AudioL2", "AudioR2"}; | ||
441 | 403 | ||
442 | static const unsigned int twl4030_analoglmic_values[] = | 404 | static const struct soc_enum twl4030_vibra_enum = |
443 | {0x0, 0x1, 0x2, 0x4, 0x8}; | 405 | SOC_ENUM_SINGLE(TWL4030_REG_VIBRA_CTL, 2, |
406 | ARRAY_SIZE(twl4030_vibra_texts), | ||
407 | twl4030_vibra_texts); | ||
444 | 408 | ||
445 | static const struct soc_enum twl4030_analoglmic_enum = | 409 | static const struct snd_kcontrol_new twl4030_dapm_vibra_control = |
446 | SOC_VALUE_ENUM_SINGLE(TWL4030_REG_ANAMICL, 0, 0xf, | 410 | SOC_DAPM_ENUM("Route", twl4030_vibra_enum); |
447 | ARRAY_SIZE(twl4030_analoglmic_texts), | ||
448 | twl4030_analoglmic_texts, | ||
449 | twl4030_analoglmic_values); | ||
450 | 411 | ||
451 | static const struct snd_kcontrol_new twl4030_dapm_analoglmic_control = | 412 | /* Vibra path selection: local vibrator (PWM) or audio driven */ |
452 | SOC_DAPM_VALUE_ENUM("Route", twl4030_analoglmic_enum); | 413 | static const char *twl4030_vibrapath_texts[] = |
414 | {"Local vibrator", "Audio"}; | ||
453 | 415 | ||
454 | /* Right analog microphone selection */ | 416 | static const struct soc_enum twl4030_vibrapath_enum = |
455 | static const char *twl4030_analogrmic_texts[] = | 417 | SOC_ENUM_SINGLE(TWL4030_REG_VIBRA_CTL, 4, |
456 | {"Off", "Sub mic", "AUXR"}; | 418 | ARRAY_SIZE(twl4030_vibrapath_texts), |
419 | twl4030_vibrapath_texts); | ||
457 | 420 | ||
458 | static const unsigned int twl4030_analogrmic_values[] = | 421 | static const struct snd_kcontrol_new twl4030_dapm_vibrapath_control = |
459 | {0x0, 0x1, 0x4}; | 422 | SOC_DAPM_ENUM("Route", twl4030_vibrapath_enum); |
460 | 423 | ||
461 | static const struct soc_enum twl4030_analogrmic_enum = | 424 | /* Left analog microphone selection */ |
462 | SOC_VALUE_ENUM_SINGLE(TWL4030_REG_ANAMICR, 0, 0x5, | 425 | static const struct snd_kcontrol_new twl4030_dapm_analoglmic_controls[] = { |
463 | ARRAY_SIZE(twl4030_analogrmic_texts), | 426 | SOC_DAPM_SINGLE("Main mic", TWL4030_REG_ANAMICL, 0, 1, 0), |
464 | twl4030_analogrmic_texts, | 427 | SOC_DAPM_SINGLE("Headset mic", TWL4030_REG_ANAMICL, 1, 1, 0), |
465 | twl4030_analogrmic_values); | 428 | SOC_DAPM_SINGLE("AUXL", TWL4030_REG_ANAMICL, 2, 1, 0), |
429 | SOC_DAPM_SINGLE("Carkit mic", TWL4030_REG_ANAMICL, 3, 1, 0), | ||
430 | }; | ||
466 | 431 | ||
467 | static const struct snd_kcontrol_new twl4030_dapm_analogrmic_control = | 432 | /* Right analog microphone selection */ |
468 | SOC_DAPM_VALUE_ENUM("Route", twl4030_analogrmic_enum); | 433 | static const struct snd_kcontrol_new twl4030_dapm_analogrmic_controls[] = { |
434 | SOC_DAPM_SINGLE("Sub mic", TWL4030_REG_ANAMICR, 0, 1, 0), | ||
435 | SOC_DAPM_SINGLE("AUXR", TWL4030_REG_ANAMICR, 1, 1, 0), | ||
436 | }; | ||
469 | 437 | ||
470 | /* TX1 L/R Analog/Digital microphone selection */ | 438 | /* TX1 L/R Analog/Digital microphone selection */ |
471 | static const char *twl4030_micpathtx1_texts[] = | 439 | static const char *twl4030_micpathtx1_texts[] = |
@@ -507,6 +475,10 @@ static const struct snd_kcontrol_new twl4030_dapm_abypassr2_control = | |||
507 | static const struct snd_kcontrol_new twl4030_dapm_abypassl2_control = | 475 | static const struct snd_kcontrol_new twl4030_dapm_abypassl2_control = |
508 | SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXL2_APGA_CTL, 2, 1, 0); | 476 | SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXL2_APGA_CTL, 2, 1, 0); |
509 | 477 | ||
478 | /* Analog bypass for Voice */ | ||
479 | static const struct snd_kcontrol_new twl4030_dapm_abypassv_control = | ||
480 | SOC_DAPM_SINGLE("Switch", TWL4030_REG_VDL_APGA_CTL, 2, 1, 0); | ||
481 | |||
510 | /* Digital bypass gain, 0 mutes the bypass */ | 482 | /* Digital bypass gain, 0 mutes the bypass */ |
511 | static const unsigned int twl4030_dapm_dbypass_tlv[] = { | 483 | static const unsigned int twl4030_dapm_dbypass_tlv[] = { |
512 | TLV_DB_RANGE_HEAD(2), | 484 | TLV_DB_RANGE_HEAD(2), |
@@ -526,6 +498,18 @@ static const struct snd_kcontrol_new twl4030_dapm_dbypassr_control = | |||
526 | TWL4030_REG_ATX2ARXPGA, 0, 7, 0, | 498 | TWL4030_REG_ATX2ARXPGA, 0, 7, 0, |
527 | twl4030_dapm_dbypass_tlv); | 499 | twl4030_dapm_dbypass_tlv); |
528 | 500 | ||
501 | /* | ||
502 | * Voice Sidetone GAIN volume control: | ||
503 | * from -51 to -10 dB in 1 dB steps (mute instead of -51 dB) | ||
504 | */ | ||
505 | static DECLARE_TLV_DB_SCALE(twl4030_dapm_dbypassv_tlv, -5100, 100, 1); | ||
506 | |||
507 | /* Digital bypass voice: sidetone (VUL -> VDL)*/ | ||
508 | static const struct snd_kcontrol_new twl4030_dapm_dbypassv_control = | ||
509 | SOC_DAPM_SINGLE_TLV("Volume", | ||
510 | TWL4030_REG_VSTPGA, 0, 0x29, 0, | ||
511 | twl4030_dapm_dbypassv_tlv); | ||
512 | |||
529 | static int micpath_event(struct snd_soc_dapm_widget *w, | 513 | static int micpath_event(struct snd_soc_dapm_widget *w, |
530 | struct snd_kcontrol *kcontrol, int event) | 514 | struct snd_kcontrol *kcontrol, int event) |
531 | { | 515 | { |
@@ -624,7 +608,7 @@ static int bypass_event(struct snd_soc_dapm_widget *w, | |||
624 | struct soc_mixer_control *m = | 608 | struct soc_mixer_control *m = |
625 | (struct soc_mixer_control *)w->kcontrols->private_value; | 609 | (struct soc_mixer_control *)w->kcontrols->private_value; |
626 | struct twl4030_priv *twl4030 = w->codec->private_data; | 610 | struct twl4030_priv *twl4030 = w->codec->private_data; |
627 | unsigned char reg; | 611 | unsigned char reg, misc; |
628 | 612 | ||
629 | reg = twl4030_read_reg_cache(w->codec, m->reg); | 613 | reg = twl4030_read_reg_cache(w->codec, m->reg); |
630 | 614 | ||
@@ -636,14 +620,34 @@ static int bypass_event(struct snd_soc_dapm_widget *w, | |||
636 | else | 620 | else |
637 | twl4030->bypass_state &= | 621 | twl4030->bypass_state &= |
638 | ~(1 << (m->reg - TWL4030_REG_ARXL1_APGA_CTL)); | 622 | ~(1 << (m->reg - TWL4030_REG_ARXL1_APGA_CTL)); |
623 | } else if (m->reg == TWL4030_REG_VDL_APGA_CTL) { | ||
624 | /* Analog voice bypass */ | ||
625 | if (reg & (1 << m->shift)) | ||
626 | twl4030->bypass_state |= (1 << 4); | ||
627 | else | ||
628 | twl4030->bypass_state &= ~(1 << 4); | ||
629 | } else if (m->reg == TWL4030_REG_VSTPGA) { | ||
630 | /* Voice digital bypass */ | ||
631 | if (reg) | ||
632 | twl4030->bypass_state |= (1 << 5); | ||
633 | else | ||
634 | twl4030->bypass_state &= ~(1 << 5); | ||
639 | } else { | 635 | } else { |
640 | /* Digital bypass */ | 636 | /* Digital bypass */ |
641 | if (reg & (0x7 << m->shift)) | 637 | if (reg & (0x7 << m->shift)) |
642 | twl4030->bypass_state |= (1 << (m->shift ? 5 : 4)); | 638 | twl4030->bypass_state |= (1 << (m->shift ? 7 : 6)); |
643 | else | 639 | else |
644 | twl4030->bypass_state &= ~(1 << (m->shift ? 5 : 4)); | 640 | twl4030->bypass_state &= ~(1 << (m->shift ? 7 : 6)); |
645 | } | 641 | } |
646 | 642 | ||
643 | /* Enable master analog loopback mode if any analog switch is enabled*/ | ||
644 | misc = twl4030_read_reg_cache(w->codec, TWL4030_REG_MISC_SET_1); | ||
645 | if (twl4030->bypass_state & 0x1F) | ||
646 | misc |= TWL4030_FMLOOP_EN; | ||
647 | else | ||
648 | misc &= ~TWL4030_FMLOOP_EN; | ||
649 | twl4030_write(w->codec, TWL4030_REG_MISC_SET_1, misc); | ||
650 | |||
647 | if (w->codec->bias_level == SND_SOC_BIAS_STANDBY) { | 651 | if (w->codec->bias_level == SND_SOC_BIAS_STANDBY) { |
648 | if (twl4030->bypass_state) | 652 | if (twl4030->bypass_state) |
649 | twl4030_codec_mute(w->codec, 0); | 653 | twl4030_codec_mute(w->codec, 0); |
@@ -824,6 +828,12 @@ static DECLARE_TLV_DB_SCALE(digital_fine_tlv, -6300, 100, 1); | |||
824 | static DECLARE_TLV_DB_SCALE(digital_coarse_tlv, 0, 600, 0); | 828 | static DECLARE_TLV_DB_SCALE(digital_coarse_tlv, 0, 600, 0); |
825 | 829 | ||
826 | /* | 830 | /* |
831 | * Voice Downlink GAIN volume control: | ||
832 | * from -37 to 12 dB in 1 dB steps (mute instead of -37 dB) | ||
833 | */ | ||
834 | static DECLARE_TLV_DB_SCALE(digital_voice_downlink_tlv, -3700, 100, 1); | ||
835 | |||
836 | /* | ||
827 | * Analog playback gain | 837 | * Analog playback gain |
828 | * -24 dB to 12 dB in 2 dB steps | 838 | * -24 dB to 12 dB in 2 dB steps |
829 | */ | 839 | */ |
@@ -864,6 +874,26 @@ static const struct soc_enum twl4030_rampdelay_enum = | |||
864 | ARRAY_SIZE(twl4030_rampdelay_texts), | 874 | ARRAY_SIZE(twl4030_rampdelay_texts), |
865 | twl4030_rampdelay_texts); | 875 | twl4030_rampdelay_texts); |
866 | 876 | ||
877 | /* Vibra H-bridge direction mode */ | ||
878 | static const char *twl4030_vibradirmode_texts[] = { | ||
879 | "Vibra H-bridge direction", "Audio data MSB", | ||
880 | }; | ||
881 | |||
882 | static const struct soc_enum twl4030_vibradirmode_enum = | ||
883 | SOC_ENUM_SINGLE(TWL4030_REG_VIBRA_CTL, 5, | ||
884 | ARRAY_SIZE(twl4030_vibradirmode_texts), | ||
885 | twl4030_vibradirmode_texts); | ||
886 | |||
887 | /* Vibra H-bridge direction */ | ||
888 | static const char *twl4030_vibradir_texts[] = { | ||
889 | "Positive polarity", "Negative polarity", | ||
890 | }; | ||
891 | |||
892 | static const struct soc_enum twl4030_vibradir_enum = | ||
893 | SOC_ENUM_SINGLE(TWL4030_REG_VIBRA_CTL, 1, | ||
894 | ARRAY_SIZE(twl4030_vibradir_texts), | ||
895 | twl4030_vibradir_texts); | ||
896 | |||
867 | static const struct snd_kcontrol_new twl4030_snd_controls[] = { | 897 | static const struct snd_kcontrol_new twl4030_snd_controls[] = { |
868 | /* Common playback gain controls */ | 898 | /* Common playback gain controls */ |
869 | SOC_DOUBLE_R_TLV("DAC1 Digital Fine Playback Volume", | 899 | SOC_DOUBLE_R_TLV("DAC1 Digital Fine Playback Volume", |
@@ -893,6 +923,16 @@ static const struct snd_kcontrol_new twl4030_snd_controls[] = { | |||
893 | TWL4030_REG_ARXL2_APGA_CTL, TWL4030_REG_ARXR2_APGA_CTL, | 923 | TWL4030_REG_ARXL2_APGA_CTL, TWL4030_REG_ARXR2_APGA_CTL, |
894 | 1, 1, 0), | 924 | 1, 1, 0), |
895 | 925 | ||
926 | /* Common voice downlink gain controls */ | ||
927 | SOC_SINGLE_TLV("DAC Voice Digital Downlink Volume", | ||
928 | TWL4030_REG_VRXPGA, 0, 0x31, 0, digital_voice_downlink_tlv), | ||
929 | |||
930 | SOC_SINGLE_TLV("DAC Voice Analog Downlink Volume", | ||
931 | TWL4030_REG_VDL_APGA_CTL, 3, 0x12, 1, analog_tlv), | ||
932 | |||
933 | SOC_SINGLE("DAC Voice Analog Downlink Switch", | ||
934 | TWL4030_REG_VDL_APGA_CTL, 1, 1, 0), | ||
935 | |||
896 | /* Separate output gain controls */ | 936 | /* Separate output gain controls */ |
897 | SOC_DOUBLE_R_TLV_TWL4030("PreDriv Playback Volume", | 937 | SOC_DOUBLE_R_TLV_TWL4030("PreDriv Playback Volume", |
898 | TWL4030_REG_PREDL_CTL, TWL4030_REG_PREDR_CTL, | 938 | TWL4030_REG_PREDL_CTL, TWL4030_REG_PREDR_CTL, |
@@ -920,6 +960,9 @@ static const struct snd_kcontrol_new twl4030_snd_controls[] = { | |||
920 | 0, 3, 5, 0, input_gain_tlv), | 960 | 0, 3, 5, 0, input_gain_tlv), |
921 | 961 | ||
922 | SOC_ENUM("HS ramp delay", twl4030_rampdelay_enum), | 962 | SOC_ENUM("HS ramp delay", twl4030_rampdelay_enum), |
963 | |||
964 | SOC_ENUM("Vibra H-bridge mode", twl4030_vibradirmode_enum), | ||
965 | SOC_ENUM("Vibra H-bridge direction", twl4030_vibradir_enum), | ||
923 | }; | 966 | }; |
924 | 967 | ||
925 | static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | 968 | static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { |
@@ -947,6 +990,7 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | |||
947 | SND_SOC_DAPM_OUTPUT("CARKITR"), | 990 | SND_SOC_DAPM_OUTPUT("CARKITR"), |
948 | SND_SOC_DAPM_OUTPUT("HFL"), | 991 | SND_SOC_DAPM_OUTPUT("HFL"), |
949 | SND_SOC_DAPM_OUTPUT("HFR"), | 992 | SND_SOC_DAPM_OUTPUT("HFR"), |
993 | SND_SOC_DAPM_OUTPUT("VIBRA"), | ||
950 | 994 | ||
951 | /* DACs */ | 995 | /* DACs */ |
952 | SND_SOC_DAPM_DAC("DAC Right1", "Right Front Playback", | 996 | SND_SOC_DAPM_DAC("DAC Right1", "Right Front Playback", |
@@ -957,6 +1001,8 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | |||
957 | SND_SOC_NOPM, 0, 0), | 1001 | SND_SOC_NOPM, 0, 0), |
958 | SND_SOC_DAPM_DAC("DAC Left2", "Left Rear Playback", | 1002 | SND_SOC_DAPM_DAC("DAC Left2", "Left Rear Playback", |
959 | SND_SOC_NOPM, 0, 0), | 1003 | SND_SOC_NOPM, 0, 0), |
1004 | SND_SOC_DAPM_DAC("DAC Voice", "Voice Playback", | ||
1005 | SND_SOC_NOPM, 0, 0), | ||
960 | 1006 | ||
961 | /* Analog PGAs */ | 1007 | /* Analog PGAs */ |
962 | SND_SOC_DAPM_PGA("ARXR1_APGA", TWL4030_REG_ARXR1_APGA_CTL, | 1008 | SND_SOC_DAPM_PGA("ARXR1_APGA", TWL4030_REG_ARXR1_APGA_CTL, |
@@ -967,6 +1013,8 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | |||
967 | 0, 0, NULL, 0), | 1013 | 0, 0, NULL, 0), |
968 | SND_SOC_DAPM_PGA("ARXL2_APGA", TWL4030_REG_ARXL2_APGA_CTL, | 1014 | SND_SOC_DAPM_PGA("ARXL2_APGA", TWL4030_REG_ARXL2_APGA_CTL, |
969 | 0, 0, NULL, 0), | 1015 | 0, 0, NULL, 0), |
1016 | SND_SOC_DAPM_PGA("VDL_APGA", TWL4030_REG_VDL_APGA_CTL, | ||
1017 | 0, 0, NULL, 0), | ||
970 | 1018 | ||
971 | /* Analog bypasses */ | 1019 | /* Analog bypasses */ |
972 | SND_SOC_DAPM_SWITCH_E("Right1 Analog Loopback", SND_SOC_NOPM, 0, 0, | 1020 | SND_SOC_DAPM_SWITCH_E("Right1 Analog Loopback", SND_SOC_NOPM, 0, 0, |
@@ -981,6 +1029,9 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | |||
981 | SND_SOC_DAPM_SWITCH_E("Left2 Analog Loopback", SND_SOC_NOPM, 0, 0, | 1029 | SND_SOC_DAPM_SWITCH_E("Left2 Analog Loopback", SND_SOC_NOPM, 0, 0, |
982 | &twl4030_dapm_abypassl2_control, | 1030 | &twl4030_dapm_abypassl2_control, |
983 | bypass_event, SND_SOC_DAPM_POST_REG), | 1031 | bypass_event, SND_SOC_DAPM_POST_REG), |
1032 | SND_SOC_DAPM_SWITCH_E("Voice Analog Loopback", SND_SOC_NOPM, 0, 0, | ||
1033 | &twl4030_dapm_abypassv_control, | ||
1034 | bypass_event, SND_SOC_DAPM_POST_REG), | ||
984 | 1035 | ||
985 | /* Digital bypasses */ | 1036 | /* Digital bypasses */ |
986 | SND_SOC_DAPM_SWITCH_E("Left Digital Loopback", SND_SOC_NOPM, 0, 0, | 1037 | SND_SOC_DAPM_SWITCH_E("Left Digital Loopback", SND_SOC_NOPM, 0, 0, |
@@ -989,6 +1040,9 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | |||
989 | SND_SOC_DAPM_SWITCH_E("Right Digital Loopback", SND_SOC_NOPM, 0, 0, | 1040 | SND_SOC_DAPM_SWITCH_E("Right Digital Loopback", SND_SOC_NOPM, 0, 0, |
990 | &twl4030_dapm_dbypassr_control, bypass_event, | 1041 | &twl4030_dapm_dbypassr_control, bypass_event, |
991 | SND_SOC_DAPM_POST_REG), | 1042 | SND_SOC_DAPM_POST_REG), |
1043 | SND_SOC_DAPM_SWITCH_E("Voice Digital Loopback", SND_SOC_NOPM, 0, 0, | ||
1044 | &twl4030_dapm_dbypassv_control, bypass_event, | ||
1045 | SND_SOC_DAPM_POST_REG), | ||
992 | 1046 | ||
993 | SND_SOC_DAPM_MIXER("Analog R1 Playback Mixer", TWL4030_REG_AVDAC_CTL, | 1047 | SND_SOC_DAPM_MIXER("Analog R1 Playback Mixer", TWL4030_REG_AVDAC_CTL, |
994 | 0, 0, NULL, 0), | 1048 | 0, 0, NULL, 0), |
@@ -998,27 +1052,38 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | |||
998 | 2, 0, NULL, 0), | 1052 | 2, 0, NULL, 0), |
999 | SND_SOC_DAPM_MIXER("Analog L2 Playback Mixer", TWL4030_REG_AVDAC_CTL, | 1053 | SND_SOC_DAPM_MIXER("Analog L2 Playback Mixer", TWL4030_REG_AVDAC_CTL, |
1000 | 3, 0, NULL, 0), | 1054 | 3, 0, NULL, 0), |
1055 | SND_SOC_DAPM_MIXER("Analog Voice Playback Mixer", TWL4030_REG_AVDAC_CTL, | ||
1056 | 4, 0, NULL, 0), | ||
1001 | 1057 | ||
1002 | /* Output MUX controls */ | 1058 | /* Output MIXER controls */ |
1003 | /* Earpiece */ | 1059 | /* Earpiece */ |
1004 | SND_SOC_DAPM_VALUE_MUX("Earpiece Mux", SND_SOC_NOPM, 0, 0, | 1060 | SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0, |
1005 | &twl4030_dapm_earpiece_control), | 1061 | &twl4030_dapm_earpiece_controls[0], |
1062 | ARRAY_SIZE(twl4030_dapm_earpiece_controls)), | ||
1006 | /* PreDrivL/R */ | 1063 | /* PreDrivL/R */ |
1007 | SND_SOC_DAPM_VALUE_MUX("PredriveL Mux", SND_SOC_NOPM, 0, 0, | 1064 | SND_SOC_DAPM_MIXER("PredriveL Mixer", SND_SOC_NOPM, 0, 0, |
1008 | &twl4030_dapm_predrivel_control), | 1065 | &twl4030_dapm_predrivel_controls[0], |
1009 | SND_SOC_DAPM_VALUE_MUX("PredriveR Mux", SND_SOC_NOPM, 0, 0, | 1066 | ARRAY_SIZE(twl4030_dapm_predrivel_controls)), |
1010 | &twl4030_dapm_predriver_control), | 1067 | SND_SOC_DAPM_MIXER("PredriveR Mixer", SND_SOC_NOPM, 0, 0, |
1068 | &twl4030_dapm_predriver_controls[0], | ||
1069 | ARRAY_SIZE(twl4030_dapm_predriver_controls)), | ||
1011 | /* HeadsetL/R */ | 1070 | /* HeadsetL/R */ |
1012 | SND_SOC_DAPM_MUX_E("HeadsetL Mux", SND_SOC_NOPM, 0, 0, | 1071 | SND_SOC_DAPM_MIXER_E("HeadsetL Mixer", SND_SOC_NOPM, 0, 0, |
1013 | &twl4030_dapm_hsol_control, headsetl_event, | 1072 | &twl4030_dapm_hsol_controls[0], |
1014 | SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD), | 1073 | ARRAY_SIZE(twl4030_dapm_hsol_controls), headsetl_event, |
1015 | SND_SOC_DAPM_MUX("HeadsetR Mux", SND_SOC_NOPM, 0, 0, | 1074 | SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD), |
1016 | &twl4030_dapm_hsor_control), | 1075 | SND_SOC_DAPM_MIXER("HeadsetR Mixer", SND_SOC_NOPM, 0, 0, |
1076 | &twl4030_dapm_hsor_controls[0], | ||
1077 | ARRAY_SIZE(twl4030_dapm_hsor_controls)), | ||
1017 | /* CarkitL/R */ | 1078 | /* CarkitL/R */ |
1018 | SND_SOC_DAPM_MUX("CarkitL Mux", SND_SOC_NOPM, 0, 0, | 1079 | SND_SOC_DAPM_MIXER("CarkitL Mixer", SND_SOC_NOPM, 0, 0, |
1019 | &twl4030_dapm_carkitl_control), | 1080 | &twl4030_dapm_carkitl_controls[0], |
1020 | SND_SOC_DAPM_MUX("CarkitR Mux", SND_SOC_NOPM, 0, 0, | 1081 | ARRAY_SIZE(twl4030_dapm_carkitl_controls)), |
1021 | &twl4030_dapm_carkitr_control), | 1082 | SND_SOC_DAPM_MIXER("CarkitR Mixer", SND_SOC_NOPM, 0, 0, |
1083 | &twl4030_dapm_carkitr_controls[0], | ||
1084 | ARRAY_SIZE(twl4030_dapm_carkitr_controls)), | ||
1085 | |||
1086 | /* Output MUX controls */ | ||
1022 | /* HandsfreeL/R */ | 1087 | /* HandsfreeL/R */ |
1023 | SND_SOC_DAPM_MUX_E("HandsfreeL Mux", TWL4030_REG_HFL_CTL, 5, 0, | 1088 | SND_SOC_DAPM_MUX_E("HandsfreeL Mux", TWL4030_REG_HFL_CTL, 5, 0, |
1024 | &twl4030_dapm_handsfreel_control, handsfree_event, | 1089 | &twl4030_dapm_handsfreel_control, handsfree_event, |
@@ -1026,6 +1091,11 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | |||
1026 | SND_SOC_DAPM_MUX_E("HandsfreeR Mux", TWL4030_REG_HFR_CTL, 5, 0, | 1091 | SND_SOC_DAPM_MUX_E("HandsfreeR Mux", TWL4030_REG_HFR_CTL, 5, 0, |
1027 | &twl4030_dapm_handsfreer_control, handsfree_event, | 1092 | &twl4030_dapm_handsfreer_control, handsfree_event, |
1028 | SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD), | 1093 | SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD), |
1094 | /* Vibra */ | ||
1095 | SND_SOC_DAPM_MUX("Vibra Mux", TWL4030_REG_VIBRA_CTL, 0, 0, | ||
1096 | &twl4030_dapm_vibra_control), | ||
1097 | SND_SOC_DAPM_MUX("Vibra Route", SND_SOC_NOPM, 0, 0, | ||
1098 | &twl4030_dapm_vibrapath_control), | ||
1029 | 1099 | ||
1030 | /* Introducing four virtual ADC, since TWL4030 have four channel for | 1100 | /* Introducing four virtual ADC, since TWL4030 have four channel for |
1031 | capture */ | 1101 | capture */ |
@@ -1050,11 +1120,15 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | |||
1050 | SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD| | 1120 | SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD| |
1051 | SND_SOC_DAPM_POST_REG), | 1121 | SND_SOC_DAPM_POST_REG), |
1052 | 1122 | ||
1053 | /* Analog input muxes with switch for the capture amplifiers */ | 1123 | /* Analog input mixers for the capture amplifiers */ |
1054 | SND_SOC_DAPM_VALUE_MUX("Analog Left Capture Route", | 1124 | SND_SOC_DAPM_MIXER("Analog Left Capture Route", |
1055 | TWL4030_REG_ANAMICL, 4, 0, &twl4030_dapm_analoglmic_control), | 1125 | TWL4030_REG_ANAMICL, 4, 0, |
1056 | SND_SOC_DAPM_VALUE_MUX("Analog Right Capture Route", | 1126 | &twl4030_dapm_analoglmic_controls[0], |
1057 | TWL4030_REG_ANAMICR, 4, 0, &twl4030_dapm_analogrmic_control), | 1127 | ARRAY_SIZE(twl4030_dapm_analoglmic_controls)), |
1128 | SND_SOC_DAPM_MIXER("Analog Right Capture Route", | ||
1129 | TWL4030_REG_ANAMICR, 4, 0, | ||
1130 | &twl4030_dapm_analogrmic_controls[0], | ||
1131 | ARRAY_SIZE(twl4030_dapm_analogrmic_controls)), | ||
1058 | 1132 | ||
1059 | SND_SOC_DAPM_PGA("ADC Physical Left", | 1133 | SND_SOC_DAPM_PGA("ADC Physical Left", |
1060 | TWL4030_REG_AVADC_CTL, 3, 0, NULL, 0), | 1134 | TWL4030_REG_AVADC_CTL, 3, 0, NULL, 0), |
@@ -1077,58 +1151,76 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
1077 | {"Analog R1 Playback Mixer", NULL, "DAC Right1"}, | 1151 | {"Analog R1 Playback Mixer", NULL, "DAC Right1"}, |
1078 | {"Analog L2 Playback Mixer", NULL, "DAC Left2"}, | 1152 | {"Analog L2 Playback Mixer", NULL, "DAC Left2"}, |
1079 | {"Analog R2 Playback Mixer", NULL, "DAC Right2"}, | 1153 | {"Analog R2 Playback Mixer", NULL, "DAC Right2"}, |
1154 | {"Analog Voice Playback Mixer", NULL, "DAC Voice"}, | ||
1080 | 1155 | ||
1081 | {"ARXL1_APGA", NULL, "Analog L1 Playback Mixer"}, | 1156 | {"ARXL1_APGA", NULL, "Analog L1 Playback Mixer"}, |
1082 | {"ARXR1_APGA", NULL, "Analog R1 Playback Mixer"}, | 1157 | {"ARXR1_APGA", NULL, "Analog R1 Playback Mixer"}, |
1083 | {"ARXL2_APGA", NULL, "Analog L2 Playback Mixer"}, | 1158 | {"ARXL2_APGA", NULL, "Analog L2 Playback Mixer"}, |
1084 | {"ARXR2_APGA", NULL, "Analog R2 Playback Mixer"}, | 1159 | {"ARXR2_APGA", NULL, "Analog R2 Playback Mixer"}, |
1160 | {"VDL_APGA", NULL, "Analog Voice Playback Mixer"}, | ||
1085 | 1161 | ||
1086 | /* Internal playback routings */ | 1162 | /* Internal playback routings */ |
1087 | /* Earpiece */ | 1163 | /* Earpiece */ |
1088 | {"Earpiece Mux", "DACL1", "ARXL1_APGA"}, | 1164 | {"Earpiece Mixer", "Voice", "VDL_APGA"}, |
1089 | {"Earpiece Mux", "DACL2", "ARXL2_APGA"}, | 1165 | {"Earpiece Mixer", "AudioL1", "ARXL1_APGA"}, |
1090 | {"Earpiece Mux", "DACR1", "ARXR1_APGA"}, | 1166 | {"Earpiece Mixer", "AudioL2", "ARXL2_APGA"}, |
1167 | {"Earpiece Mixer", "AudioR1", "ARXR1_APGA"}, | ||
1091 | /* PreDrivL */ | 1168 | /* PreDrivL */ |
1092 | {"PredriveL Mux", "DACL1", "ARXL1_APGA"}, | 1169 | {"PredriveL Mixer", "Voice", "VDL_APGA"}, |
1093 | {"PredriveL Mux", "DACL2", "ARXL2_APGA"}, | 1170 | {"PredriveL Mixer", "AudioL1", "ARXL1_APGA"}, |
1094 | {"PredriveL Mux", "DACR2", "ARXR2_APGA"}, | 1171 | {"PredriveL Mixer", "AudioL2", "ARXL2_APGA"}, |
1172 | {"PredriveL Mixer", "AudioR2", "ARXR2_APGA"}, | ||
1095 | /* PreDrivR */ | 1173 | /* PreDrivR */ |
1096 | {"PredriveR Mux", "DACR1", "ARXR1_APGA"}, | 1174 | {"PredriveR Mixer", "Voice", "VDL_APGA"}, |
1097 | {"PredriveR Mux", "DACR2", "ARXR2_APGA"}, | 1175 | {"PredriveR Mixer", "AudioR1", "ARXR1_APGA"}, |
1098 | {"PredriveR Mux", "DACL2", "ARXL2_APGA"}, | 1176 | {"PredriveR Mixer", "AudioR2", "ARXR2_APGA"}, |
1177 | {"PredriveR Mixer", "AudioL2", "ARXL2_APGA"}, | ||
1099 | /* HeadsetL */ | 1178 | /* HeadsetL */ |
1100 | {"HeadsetL Mux", "DACL1", "ARXL1_APGA"}, | 1179 | {"HeadsetL Mixer", "Voice", "VDL_APGA"}, |
1101 | {"HeadsetL Mux", "DACL2", "ARXL2_APGA"}, | 1180 | {"HeadsetL Mixer", "AudioL1", "ARXL1_APGA"}, |
1181 | {"HeadsetL Mixer", "AudioL2", "ARXL2_APGA"}, | ||
1102 | /* HeadsetR */ | 1182 | /* HeadsetR */ |
1103 | {"HeadsetR Mux", "DACR1", "ARXR1_APGA"}, | 1183 | {"HeadsetR Mixer", "Voice", "VDL_APGA"}, |
1104 | {"HeadsetR Mux", "DACR2", "ARXR2_APGA"}, | 1184 | {"HeadsetR Mixer", "AudioR1", "ARXR1_APGA"}, |
1185 | {"HeadsetR Mixer", "AudioR2", "ARXR2_APGA"}, | ||
1105 | /* CarkitL */ | 1186 | /* CarkitL */ |
1106 | {"CarkitL Mux", "DACL1", "ARXL1_APGA"}, | 1187 | {"CarkitL Mixer", "Voice", "VDL_APGA"}, |
1107 | {"CarkitL Mux", "DACL2", "ARXL2_APGA"}, | 1188 | {"CarkitL Mixer", "AudioL1", "ARXL1_APGA"}, |
1189 | {"CarkitL Mixer", "AudioL2", "ARXL2_APGA"}, | ||
1108 | /* CarkitR */ | 1190 | /* CarkitR */ |
1109 | {"CarkitR Mux", "DACR1", "ARXR1_APGA"}, | 1191 | {"CarkitR Mixer", "Voice", "VDL_APGA"}, |
1110 | {"CarkitR Mux", "DACR2", "ARXR2_APGA"}, | 1192 | {"CarkitR Mixer", "AudioR1", "ARXR1_APGA"}, |
1193 | {"CarkitR Mixer", "AudioR2", "ARXR2_APGA"}, | ||
1111 | /* HandsfreeL */ | 1194 | /* HandsfreeL */ |
1112 | {"HandsfreeL Mux", "DACL1", "ARXL1_APGA"}, | 1195 | {"HandsfreeL Mux", "Voice", "VDL_APGA"}, |
1113 | {"HandsfreeL Mux", "DACL2", "ARXL2_APGA"}, | 1196 | {"HandsfreeL Mux", "AudioL1", "ARXL1_APGA"}, |
1114 | {"HandsfreeL Mux", "DACR2", "ARXR2_APGA"}, | 1197 | {"HandsfreeL Mux", "AudioL2", "ARXL2_APGA"}, |
1198 | {"HandsfreeL Mux", "AudioR2", "ARXR2_APGA"}, | ||
1115 | /* HandsfreeR */ | 1199 | /* HandsfreeR */ |
1116 | {"HandsfreeR Mux", "DACR1", "ARXR1_APGA"}, | 1200 | {"HandsfreeR Mux", "Voice", "VDL_APGA"}, |
1117 | {"HandsfreeR Mux", "DACR2", "ARXR2_APGA"}, | 1201 | {"HandsfreeR Mux", "AudioR1", "ARXR1_APGA"}, |
1118 | {"HandsfreeR Mux", "DACL2", "ARXL2_APGA"}, | 1202 | {"HandsfreeR Mux", "AudioR2", "ARXR2_APGA"}, |
1203 | {"HandsfreeR Mux", "AudioL2", "ARXL2_APGA"}, | ||
1204 | /* Vibra */ | ||
1205 | {"Vibra Mux", "AudioL1", "DAC Left1"}, | ||
1206 | {"Vibra Mux", "AudioR1", "DAC Right1"}, | ||
1207 | {"Vibra Mux", "AudioL2", "DAC Left2"}, | ||
1208 | {"Vibra Mux", "AudioR2", "DAC Right2"}, | ||
1119 | 1209 | ||
1120 | /* outputs */ | 1210 | /* outputs */ |
1121 | {"OUTL", NULL, "ARXL2_APGA"}, | 1211 | {"OUTL", NULL, "ARXL2_APGA"}, |
1122 | {"OUTR", NULL, "ARXR2_APGA"}, | 1212 | {"OUTR", NULL, "ARXR2_APGA"}, |
1123 | {"EARPIECE", NULL, "Earpiece Mux"}, | 1213 | {"EARPIECE", NULL, "Earpiece Mixer"}, |
1124 | {"PREDRIVEL", NULL, "PredriveL Mux"}, | 1214 | {"PREDRIVEL", NULL, "PredriveL Mixer"}, |
1125 | {"PREDRIVER", NULL, "PredriveR Mux"}, | 1215 | {"PREDRIVER", NULL, "PredriveR Mixer"}, |
1126 | {"HSOL", NULL, "HeadsetL Mux"}, | 1216 | {"HSOL", NULL, "HeadsetL Mixer"}, |
1127 | {"HSOR", NULL, "HeadsetR Mux"}, | 1217 | {"HSOR", NULL, "HeadsetR Mixer"}, |
1128 | {"CARKITL", NULL, "CarkitL Mux"}, | 1218 | {"CARKITL", NULL, "CarkitL Mixer"}, |
1129 | {"CARKITR", NULL, "CarkitR Mux"}, | 1219 | {"CARKITR", NULL, "CarkitR Mixer"}, |
1130 | {"HFL", NULL, "HandsfreeL Mux"}, | 1220 | {"HFL", NULL, "HandsfreeL Mux"}, |
1131 | {"HFR", NULL, "HandsfreeR Mux"}, | 1221 | {"HFR", NULL, "HandsfreeR Mux"}, |
1222 | {"Vibra Route", "Audio", "Vibra Mux"}, | ||
1223 | {"VIBRA", NULL, "Vibra Route"}, | ||
1132 | 1224 | ||
1133 | /* Capture path */ | 1225 | /* Capture path */ |
1134 | {"Analog Left Capture Route", "Main mic", "MAINMIC"}, | 1226 | {"Analog Left Capture Route", "Main mic", "MAINMIC"}, |
@@ -1168,18 +1260,22 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
1168 | {"Left1 Analog Loopback", "Switch", "Analog Left Capture Route"}, | 1260 | {"Left1 Analog Loopback", "Switch", "Analog Left Capture Route"}, |
1169 | {"Right2 Analog Loopback", "Switch", "Analog Right Capture Route"}, | 1261 | {"Right2 Analog Loopback", "Switch", "Analog Right Capture Route"}, |
1170 | {"Left2 Analog Loopback", "Switch", "Analog Left Capture Route"}, | 1262 | {"Left2 Analog Loopback", "Switch", "Analog Left Capture Route"}, |
1263 | {"Voice Analog Loopback", "Switch", "Analog Left Capture Route"}, | ||
1171 | 1264 | ||
1172 | {"Analog R1 Playback Mixer", NULL, "Right1 Analog Loopback"}, | 1265 | {"Analog R1 Playback Mixer", NULL, "Right1 Analog Loopback"}, |
1173 | {"Analog L1 Playback Mixer", NULL, "Left1 Analog Loopback"}, | 1266 | {"Analog L1 Playback Mixer", NULL, "Left1 Analog Loopback"}, |
1174 | {"Analog R2 Playback Mixer", NULL, "Right2 Analog Loopback"}, | 1267 | {"Analog R2 Playback Mixer", NULL, "Right2 Analog Loopback"}, |
1175 | {"Analog L2 Playback Mixer", NULL, "Left2 Analog Loopback"}, | 1268 | {"Analog L2 Playback Mixer", NULL, "Left2 Analog Loopback"}, |
1269 | {"Analog Voice Playback Mixer", NULL, "Voice Analog Loopback"}, | ||
1176 | 1270 | ||
1177 | /* Digital bypass routes */ | 1271 | /* Digital bypass routes */ |
1178 | {"Right Digital Loopback", "Volume", "TX1 Capture Route"}, | 1272 | {"Right Digital Loopback", "Volume", "TX1 Capture Route"}, |
1179 | {"Left Digital Loopback", "Volume", "TX1 Capture Route"}, | 1273 | {"Left Digital Loopback", "Volume", "TX1 Capture Route"}, |
1274 | {"Voice Digital Loopback", "Volume", "TX2 Capture Route"}, | ||
1180 | 1275 | ||
1181 | {"Analog R2 Playback Mixer", NULL, "Right Digital Loopback"}, | 1276 | {"Analog R2 Playback Mixer", NULL, "Right Digital Loopback"}, |
1182 | {"Analog L2 Playback Mixer", NULL, "Left Digital Loopback"}, | 1277 | {"Analog L2 Playback Mixer", NULL, "Left Digital Loopback"}, |
1278 | {"Analog Voice Playback Mixer", NULL, "Voice Digital Loopback"}, | ||
1183 | 1279 | ||
1184 | }; | 1280 | }; |
1185 | 1281 | ||
@@ -1226,6 +1322,58 @@ static int twl4030_set_bias_level(struct snd_soc_codec *codec, | |||
1226 | return 0; | 1322 | return 0; |
1227 | } | 1323 | } |
1228 | 1324 | ||
1325 | static void twl4030_constraints(struct twl4030_priv *twl4030, | ||
1326 | struct snd_pcm_substream *mst_substream) | ||
1327 | { | ||
1328 | struct snd_pcm_substream *slv_substream; | ||
1329 | |||
1330 | /* Pick the stream, which need to be constrained */ | ||
1331 | if (mst_substream == twl4030->master_substream) | ||
1332 | slv_substream = twl4030->slave_substream; | ||
1333 | else if (mst_substream == twl4030->slave_substream) | ||
1334 | slv_substream = twl4030->master_substream; | ||
1335 | else /* This should not happen.. */ | ||
1336 | return; | ||
1337 | |||
1338 | /* Set the constraints according to the already configured stream */ | ||
1339 | snd_pcm_hw_constraint_minmax(slv_substream->runtime, | ||
1340 | SNDRV_PCM_HW_PARAM_RATE, | ||
1341 | twl4030->rate, | ||
1342 | twl4030->rate); | ||
1343 | |||
1344 | snd_pcm_hw_constraint_minmax(slv_substream->runtime, | ||
1345 | SNDRV_PCM_HW_PARAM_SAMPLE_BITS, | ||
1346 | twl4030->sample_bits, | ||
1347 | twl4030->sample_bits); | ||
1348 | |||
1349 | snd_pcm_hw_constraint_minmax(slv_substream->runtime, | ||
1350 | SNDRV_PCM_HW_PARAM_CHANNELS, | ||
1351 | twl4030->channels, | ||
1352 | twl4030->channels); | ||
1353 | } | ||
1354 | |||
1355 | /* In case of 4 channel mode, the RX1 L/R for playback and the TX2 L/R for | ||
1356 | * capture has to be enabled/disabled. */ | ||
1357 | static void twl4030_tdm_enable(struct snd_soc_codec *codec, int direction, | ||
1358 | int enable) | ||
1359 | { | ||
1360 | u8 reg, mask; | ||
1361 | |||
1362 | reg = twl4030_read_reg_cache(codec, TWL4030_REG_OPTION); | ||
1363 | |||
1364 | if (direction == SNDRV_PCM_STREAM_PLAYBACK) | ||
1365 | mask = TWL4030_ARXL1_VRX_EN | TWL4030_ARXR1_EN; | ||
1366 | else | ||
1367 | mask = TWL4030_ATXL2_VTXL_EN | TWL4030_ATXR2_VTXR_EN; | ||
1368 | |||
1369 | if (enable) | ||
1370 | reg |= mask; | ||
1371 | else | ||
1372 | reg &= ~mask; | ||
1373 | |||
1374 | twl4030_write(codec, TWL4030_REG_OPTION, reg); | ||
1375 | } | ||
1376 | |||
1229 | static int twl4030_startup(struct snd_pcm_substream *substream, | 1377 | static int twl4030_startup(struct snd_pcm_substream *substream, |
1230 | struct snd_soc_dai *dai) | 1378 | struct snd_soc_dai *dai) |
1231 | { | 1379 | { |
@@ -1234,26 +1382,25 @@ static int twl4030_startup(struct snd_pcm_substream *substream, | |||
1234 | struct snd_soc_codec *codec = socdev->card->codec; | 1382 | struct snd_soc_codec *codec = socdev->card->codec; |
1235 | struct twl4030_priv *twl4030 = codec->private_data; | 1383 | struct twl4030_priv *twl4030 = codec->private_data; |
1236 | 1384 | ||
1237 | /* If we already have a playback or capture going then constrain | ||
1238 | * this substream to match it. | ||
1239 | */ | ||
1240 | if (twl4030->master_substream) { | 1385 | if (twl4030->master_substream) { |
1241 | struct snd_pcm_runtime *master_runtime; | ||
1242 | master_runtime = twl4030->master_substream->runtime; | ||
1243 | |||
1244 | snd_pcm_hw_constraint_minmax(substream->runtime, | ||
1245 | SNDRV_PCM_HW_PARAM_RATE, | ||
1246 | master_runtime->rate, | ||
1247 | master_runtime->rate); | ||
1248 | |||
1249 | snd_pcm_hw_constraint_minmax(substream->runtime, | ||
1250 | SNDRV_PCM_HW_PARAM_SAMPLE_BITS, | ||
1251 | master_runtime->sample_bits, | ||
1252 | master_runtime->sample_bits); | ||
1253 | |||
1254 | twl4030->slave_substream = substream; | 1386 | twl4030->slave_substream = substream; |
1255 | } else | 1387 | /* The DAI has one configuration for playback and capture, so |
1388 | * if the DAI has been already configured then constrain this | ||
1389 | * substream to match it. */ | ||
1390 | if (twl4030->configured) | ||
1391 | twl4030_constraints(twl4030, twl4030->master_substream); | ||
1392 | } else { | ||
1393 | if (!(twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE) & | ||
1394 | TWL4030_OPTION_1)) { | ||
1395 | /* In option2 4 channel is not supported, set the | ||
1396 | * constraint for the first stream for channels, the | ||
1397 | * second stream will 'inherit' this cosntraint */ | ||
1398 | snd_pcm_hw_constraint_minmax(substream->runtime, | ||
1399 | SNDRV_PCM_HW_PARAM_CHANNELS, | ||
1400 | 2, 2); | ||
1401 | } | ||
1256 | twl4030->master_substream = substream; | 1402 | twl4030->master_substream = substream; |
1403 | } | ||
1257 | 1404 | ||
1258 | return 0; | 1405 | return 0; |
1259 | } | 1406 | } |
@@ -1270,6 +1417,17 @@ static void twl4030_shutdown(struct snd_pcm_substream *substream, | |||
1270 | twl4030->master_substream = twl4030->slave_substream; | 1417 | twl4030->master_substream = twl4030->slave_substream; |
1271 | 1418 | ||
1272 | twl4030->slave_substream = NULL; | 1419 | twl4030->slave_substream = NULL; |
1420 | |||
1421 | /* If all streams are closed, or the remaining stream has not yet | ||
1422 | * been configured than set the DAI as not configured. */ | ||
1423 | if (!twl4030->master_substream) | ||
1424 | twl4030->configured = 0; | ||
1425 | else if (!twl4030->master_substream->runtime->channels) | ||
1426 | twl4030->configured = 0; | ||
1427 | |||
1428 | /* If the closing substream had 4 channel, do the necessary cleanup */ | ||
1429 | if (substream->runtime->channels == 4) | ||
1430 | twl4030_tdm_enable(codec, substream->stream, 0); | ||
1273 | } | 1431 | } |
1274 | 1432 | ||
1275 | static int twl4030_hw_params(struct snd_pcm_substream *substream, | 1433 | static int twl4030_hw_params(struct snd_pcm_substream *substream, |
@@ -1282,8 +1440,18 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream, | |||
1282 | struct twl4030_priv *twl4030 = codec->private_data; | 1440 | struct twl4030_priv *twl4030 = codec->private_data; |
1283 | u8 mode, old_mode, format, old_format; | 1441 | u8 mode, old_mode, format, old_format; |
1284 | 1442 | ||
1285 | if (substream == twl4030->slave_substream) | 1443 | /* If the substream has 4 channel, do the necessary setup */ |
1286 | /* Ignoring hw_params for slave substream */ | 1444 | if (params_channels(params) == 4) { |
1445 | /* Safety check: are we in the correct operating mode? */ | ||
1446 | if ((twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE) & | ||
1447 | TWL4030_OPTION_1)) | ||
1448 | twl4030_tdm_enable(codec, substream->stream, 1); | ||
1449 | else | ||
1450 | return -EINVAL; | ||
1451 | } | ||
1452 | |||
1453 | if (twl4030->configured) | ||
1454 | /* Ignoring hw_params for already configured DAI */ | ||
1287 | return 0; | 1455 | return 0; |
1288 | 1456 | ||
1289 | /* bit rate */ | 1457 | /* bit rate */ |
@@ -1363,6 +1531,21 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream, | |||
1363 | /* set CODECPDZ afterwards */ | 1531 | /* set CODECPDZ afterwards */ |
1364 | twl4030_codec_enable(codec, 1); | 1532 | twl4030_codec_enable(codec, 1); |
1365 | } | 1533 | } |
1534 | |||
1535 | /* Store the important parameters for the DAI configuration and set | ||
1536 | * the DAI as configured */ | ||
1537 | twl4030->configured = 1; | ||
1538 | twl4030->rate = params_rate(params); | ||
1539 | twl4030->sample_bits = hw_param_interval(params, | ||
1540 | SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min; | ||
1541 | twl4030->channels = params_channels(params); | ||
1542 | |||
1543 | /* If both playback and capture streams are open, and one of them | ||
1544 | * is setting the hw parameters right now (since we are here), set | ||
1545 | * constraints to the other stream to match the current one. */ | ||
1546 | if (twl4030->slave_substream) | ||
1547 | twl4030_constraints(twl4030, substream); | ||
1548 | |||
1366 | return 0; | 1549 | return 0; |
1367 | } | 1550 | } |
1368 | 1551 | ||
@@ -1424,6 +1607,9 @@ static int twl4030_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
1424 | case SND_SOC_DAIFMT_I2S: | 1607 | case SND_SOC_DAIFMT_I2S: |
1425 | format |= TWL4030_AIF_FORMAT_CODEC; | 1608 | format |= TWL4030_AIF_FORMAT_CODEC; |
1426 | break; | 1609 | break; |
1610 | case SND_SOC_DAIFMT_DSP_A: | ||
1611 | format |= TWL4030_AIF_FORMAT_TDM; | ||
1612 | break; | ||
1427 | default: | 1613 | default: |
1428 | return -EINVAL; | 1614 | return -EINVAL; |
1429 | } | 1615 | } |
@@ -1443,6 +1629,144 @@ static int twl4030_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
1443 | return 0; | 1629 | return 0; |
1444 | } | 1630 | } |
1445 | 1631 | ||
1632 | static int twl4030_voice_startup(struct snd_pcm_substream *substream, | ||
1633 | struct snd_soc_dai *dai) | ||
1634 | { | ||
1635 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
1636 | struct snd_soc_device *socdev = rtd->socdev; | ||
1637 | struct snd_soc_codec *codec = socdev->card->codec; | ||
1638 | u8 infreq; | ||
1639 | u8 mode; | ||
1640 | |||
1641 | /* If the system master clock is not 26MHz, the voice PCM interface is | ||
1642 | * not avilable. | ||
1643 | */ | ||
1644 | infreq = twl4030_read_reg_cache(codec, TWL4030_REG_APLL_CTL) | ||
1645 | & TWL4030_APLL_INFREQ; | ||
1646 | |||
1647 | if (infreq != TWL4030_APLL_INFREQ_26000KHZ) { | ||
1648 | printk(KERN_ERR "TWL4030 voice startup: " | ||
1649 | "MCLK is not 26MHz, call set_sysclk() on init\n"); | ||
1650 | return -EINVAL; | ||
1651 | } | ||
1652 | |||
1653 | /* If the codec mode is not option2, the voice PCM interface is not | ||
1654 | * avilable. | ||
1655 | */ | ||
1656 | mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE) | ||
1657 | & TWL4030_OPT_MODE; | ||
1658 | |||
1659 | if (mode != TWL4030_OPTION_2) { | ||
1660 | printk(KERN_ERR "TWL4030 voice startup: " | ||
1661 | "the codec mode is not option2\n"); | ||
1662 | return -EINVAL; | ||
1663 | } | ||
1664 | |||
1665 | return 0; | ||
1666 | } | ||
1667 | |||
1668 | static int twl4030_voice_hw_params(struct snd_pcm_substream *substream, | ||
1669 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) | ||
1670 | { | ||
1671 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
1672 | struct snd_soc_device *socdev = rtd->socdev; | ||
1673 | struct snd_soc_codec *codec = socdev->card->codec; | ||
1674 | u8 old_mode, mode; | ||
1675 | |||
1676 | /* bit rate */ | ||
1677 | old_mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE) | ||
1678 | & ~(TWL4030_CODECPDZ); | ||
1679 | mode = old_mode; | ||
1680 | |||
1681 | switch (params_rate(params)) { | ||
1682 | case 8000: | ||
1683 | mode &= ~(TWL4030_SEL_16K); | ||
1684 | break; | ||
1685 | case 16000: | ||
1686 | mode |= TWL4030_SEL_16K; | ||
1687 | break; | ||
1688 | default: | ||
1689 | printk(KERN_ERR "TWL4030 voice hw params: unknown rate %d\n", | ||
1690 | params_rate(params)); | ||
1691 | return -EINVAL; | ||
1692 | } | ||
1693 | |||
1694 | if (mode != old_mode) { | ||
1695 | /* change rate and set CODECPDZ */ | ||
1696 | twl4030_codec_enable(codec, 0); | ||
1697 | twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode); | ||
1698 | twl4030_codec_enable(codec, 1); | ||
1699 | } | ||
1700 | |||
1701 | return 0; | ||
1702 | } | ||
1703 | |||
1704 | static int twl4030_voice_set_dai_sysclk(struct snd_soc_dai *codec_dai, | ||
1705 | int clk_id, unsigned int freq, int dir) | ||
1706 | { | ||
1707 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1708 | u8 infreq; | ||
1709 | |||
1710 | switch (freq) { | ||
1711 | case 26000000: | ||
1712 | infreq = TWL4030_APLL_INFREQ_26000KHZ; | ||
1713 | break; | ||
1714 | default: | ||
1715 | printk(KERN_ERR "TWL4030 voice set sysclk: unknown rate %d\n", | ||
1716 | freq); | ||
1717 | return -EINVAL; | ||
1718 | } | ||
1719 | |||
1720 | infreq |= TWL4030_APLL_EN; | ||
1721 | twl4030_write(codec, TWL4030_REG_APLL_CTL, infreq); | ||
1722 | |||
1723 | return 0; | ||
1724 | } | ||
1725 | |||
1726 | static int twl4030_voice_set_dai_fmt(struct snd_soc_dai *codec_dai, | ||
1727 | unsigned int fmt) | ||
1728 | { | ||
1729 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1730 | u8 old_format, format; | ||
1731 | |||
1732 | /* get format */ | ||
1733 | old_format = twl4030_read_reg_cache(codec, TWL4030_REG_VOICE_IF); | ||
1734 | format = old_format; | ||
1735 | |||
1736 | /* set master/slave audio interface */ | ||
1737 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
1738 | case SND_SOC_DAIFMT_CBS_CFM: | ||
1739 | format &= ~(TWL4030_VIF_SLAVE_EN); | ||
1740 | break; | ||
1741 | case SND_SOC_DAIFMT_CBS_CFS: | ||
1742 | format |= TWL4030_VIF_SLAVE_EN; | ||
1743 | break; | ||
1744 | default: | ||
1745 | return -EINVAL; | ||
1746 | } | ||
1747 | |||
1748 | /* clock inversion */ | ||
1749 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
1750 | case SND_SOC_DAIFMT_IB_NF: | ||
1751 | format &= ~(TWL4030_VIF_FORMAT); | ||
1752 | break; | ||
1753 | case SND_SOC_DAIFMT_NB_IF: | ||
1754 | format |= TWL4030_VIF_FORMAT; | ||
1755 | break; | ||
1756 | default: | ||
1757 | return -EINVAL; | ||
1758 | } | ||
1759 | |||
1760 | if (format != old_format) { | ||
1761 | /* change format and set CODECPDZ */ | ||
1762 | twl4030_codec_enable(codec, 0); | ||
1763 | twl4030_write(codec, TWL4030_REG_VOICE_IF, format); | ||
1764 | twl4030_codec_enable(codec, 1); | ||
1765 | } | ||
1766 | |||
1767 | return 0; | ||
1768 | } | ||
1769 | |||
1446 | #define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000) | 1770 | #define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000) |
1447 | #define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_S24_LE) | 1771 | #define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_S24_LE) |
1448 | 1772 | ||
@@ -1454,21 +1778,46 @@ static struct snd_soc_dai_ops twl4030_dai_ops = { | |||
1454 | .set_fmt = twl4030_set_dai_fmt, | 1778 | .set_fmt = twl4030_set_dai_fmt, |
1455 | }; | 1779 | }; |
1456 | 1780 | ||
1457 | struct snd_soc_dai twl4030_dai = { | 1781 | static struct snd_soc_dai_ops twl4030_dai_voice_ops = { |
1782 | .startup = twl4030_voice_startup, | ||
1783 | .hw_params = twl4030_voice_hw_params, | ||
1784 | .set_sysclk = twl4030_voice_set_dai_sysclk, | ||
1785 | .set_fmt = twl4030_voice_set_dai_fmt, | ||
1786 | }; | ||
1787 | |||
1788 | struct snd_soc_dai twl4030_dai[] = { | ||
1789 | { | ||
1458 | .name = "twl4030", | 1790 | .name = "twl4030", |
1459 | .playback = { | 1791 | .playback = { |
1460 | .stream_name = "Playback", | 1792 | .stream_name = "Playback", |
1461 | .channels_min = 2, | 1793 | .channels_min = 2, |
1462 | .channels_max = 2, | 1794 | .channels_max = 4, |
1463 | .rates = TWL4030_RATES | SNDRV_PCM_RATE_96000, | 1795 | .rates = TWL4030_RATES | SNDRV_PCM_RATE_96000, |
1464 | .formats = TWL4030_FORMATS,}, | 1796 | .formats = TWL4030_FORMATS,}, |
1465 | .capture = { | 1797 | .capture = { |
1466 | .stream_name = "Capture", | 1798 | .stream_name = "Capture", |
1467 | .channels_min = 2, | 1799 | .channels_min = 2, |
1468 | .channels_max = 2, | 1800 | .channels_max = 4, |
1469 | .rates = TWL4030_RATES, | 1801 | .rates = TWL4030_RATES, |
1470 | .formats = TWL4030_FORMATS,}, | 1802 | .formats = TWL4030_FORMATS,}, |
1471 | .ops = &twl4030_dai_ops, | 1803 | .ops = &twl4030_dai_ops, |
1804 | }, | ||
1805 | { | ||
1806 | .name = "twl4030 Voice", | ||
1807 | .playback = { | ||
1808 | .stream_name = "Playback", | ||
1809 | .channels_min = 1, | ||
1810 | .channels_max = 1, | ||
1811 | .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000, | ||
1812 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | ||
1813 | .capture = { | ||
1814 | .stream_name = "Capture", | ||
1815 | .channels_min = 1, | ||
1816 | .channels_max = 2, | ||
1817 | .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000, | ||
1818 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | ||
1819 | .ops = &twl4030_dai_voice_ops, | ||
1820 | }, | ||
1472 | }; | 1821 | }; |
1473 | EXPORT_SYMBOL_GPL(twl4030_dai); | 1822 | EXPORT_SYMBOL_GPL(twl4030_dai); |
1474 | 1823 | ||
@@ -1509,8 +1858,8 @@ static int twl4030_init(struct snd_soc_device *socdev) | |||
1509 | codec->read = twl4030_read_reg_cache; | 1858 | codec->read = twl4030_read_reg_cache; |
1510 | codec->write = twl4030_write; | 1859 | codec->write = twl4030_write; |
1511 | codec->set_bias_level = twl4030_set_bias_level; | 1860 | codec->set_bias_level = twl4030_set_bias_level; |
1512 | codec->dai = &twl4030_dai; | 1861 | codec->dai = twl4030_dai; |
1513 | codec->num_dai = 1; | 1862 | codec->num_dai = ARRAY_SIZE(twl4030_dai), |
1514 | codec->reg_cache_size = sizeof(twl4030_reg); | 1863 | codec->reg_cache_size = sizeof(twl4030_reg); |
1515 | codec->reg_cache = kmemdup(twl4030_reg, sizeof(twl4030_reg), | 1864 | codec->reg_cache = kmemdup(twl4030_reg, sizeof(twl4030_reg), |
1516 | GFP_KERNEL); | 1865 | GFP_KERNEL); |
@@ -1604,13 +1953,13 @@ EXPORT_SYMBOL_GPL(soc_codec_dev_twl4030); | |||
1604 | 1953 | ||
1605 | static int __init twl4030_modinit(void) | 1954 | static int __init twl4030_modinit(void) |
1606 | { | 1955 | { |
1607 | return snd_soc_register_dai(&twl4030_dai); | 1956 | return snd_soc_register_dais(&twl4030_dai[0], ARRAY_SIZE(twl4030_dai)); |
1608 | } | 1957 | } |
1609 | module_init(twl4030_modinit); | 1958 | module_init(twl4030_modinit); |
1610 | 1959 | ||
1611 | static void __exit twl4030_exit(void) | 1960 | static void __exit twl4030_exit(void) |
1612 | { | 1961 | { |
1613 | snd_soc_unregister_dai(&twl4030_dai); | 1962 | snd_soc_unregister_dais(&twl4030_dai[0], ARRAY_SIZE(twl4030_dai)); |
1614 | } | 1963 | } |
1615 | module_exit(twl4030_exit); | 1964 | module_exit(twl4030_exit); |
1616 | 1965 | ||
diff --git a/sound/soc/codecs/twl4030.h b/sound/soc/codecs/twl4030.h index cb63765db1df..3441115136f6 100644 --- a/sound/soc/codecs/twl4030.h +++ b/sound/soc/codecs/twl4030.h | |||
@@ -113,6 +113,19 @@ | |||
113 | #define TWL4030_SEL_16K 0x04 | 113 | #define TWL4030_SEL_16K 0x04 |
114 | #define TWL4030_CODECPDZ 0x02 | 114 | #define TWL4030_CODECPDZ 0x02 |
115 | #define TWL4030_OPT_MODE 0x01 | 115 | #define TWL4030_OPT_MODE 0x01 |
116 | #define TWL4030_OPTION_1 (1 << 0) | ||
117 | #define TWL4030_OPTION_2 (0 << 0) | ||
118 | |||
119 | /* TWL4030_OPTION (0x02) Fields */ | ||
120 | |||
121 | #define TWL4030_ATXL1_EN (1 << 0) | ||
122 | #define TWL4030_ATXR1_EN (1 << 1) | ||
123 | #define TWL4030_ATXL2_VTXL_EN (1 << 2) | ||
124 | #define TWL4030_ATXR2_VTXR_EN (1 << 3) | ||
125 | #define TWL4030_ARXL1_VRX_EN (1 << 4) | ||
126 | #define TWL4030_ARXR1_EN (1 << 5) | ||
127 | #define TWL4030_ARXL2_EN (1 << 6) | ||
128 | #define TWL4030_ARXR2_EN (1 << 7) | ||
116 | 129 | ||
117 | /* TWL4030_REG_MICBIAS_CTL (0x04) Fields */ | 130 | /* TWL4030_REG_MICBIAS_CTL (0x04) Fields */ |
118 | 131 | ||
@@ -171,6 +184,17 @@ | |||
171 | #define TWL4030_CLK256FS_EN 0x02 | 184 | #define TWL4030_CLK256FS_EN 0x02 |
172 | #define TWL4030_AIF_EN 0x01 | 185 | #define TWL4030_AIF_EN 0x01 |
173 | 186 | ||
187 | /* VOICE_IF (0x0F) Fields */ | ||
188 | |||
189 | #define TWL4030_VIF_SLAVE_EN 0x80 | ||
190 | #define TWL4030_VIF_DIN_EN 0x40 | ||
191 | #define TWL4030_VIF_DOUT_EN 0x20 | ||
192 | #define TWL4030_VIF_SWAP 0x10 | ||
193 | #define TWL4030_VIF_FORMAT 0x08 | ||
194 | #define TWL4030_VIF_TRI_EN 0x04 | ||
195 | #define TWL4030_VIF_SUB_EN 0x02 | ||
196 | #define TWL4030_VIF_EN 0x01 | ||
197 | |||
174 | /* EAR_CTL (0x21) */ | 198 | /* EAR_CTL (0x21) */ |
175 | #define TWL4030_EAR_GAIN 0x30 | 199 | #define TWL4030_EAR_GAIN 0x30 |
176 | 200 | ||
@@ -236,7 +260,10 @@ | |||
236 | #define TWL4030_SMOOTH_ANAVOL_EN 0x02 | 260 | #define TWL4030_SMOOTH_ANAVOL_EN 0x02 |
237 | #define TWL4030_DIGMIC_LR_SWAP_EN 0x01 | 261 | #define TWL4030_DIGMIC_LR_SWAP_EN 0x01 |
238 | 262 | ||
239 | extern struct snd_soc_dai twl4030_dai; | 263 | #define TWL4030_DAI_HIFI 0 |
264 | #define TWL4030_DAI_VOICE 1 | ||
265 | |||
266 | extern struct snd_soc_dai twl4030_dai[2]; | ||
240 | extern struct snd_soc_codec_device soc_codec_dev_twl4030; | 267 | extern struct snd_soc_codec_device soc_codec_dev_twl4030; |
241 | 268 | ||
242 | #endif /* End of __TWL4030_AUDIO_H__ */ | 269 | #endif /* End of __TWL4030_AUDIO_H__ */ |
diff --git a/sound/soc/codecs/wm8350.h b/sound/soc/codecs/wm8350.h index d11bd9288cf9..d088eb4b88bb 100644 --- a/sound/soc/codecs/wm8350.h +++ b/sound/soc/codecs/wm8350.h | |||
@@ -13,6 +13,7 @@ | |||
13 | #define _WM8350_H | 13 | #define _WM8350_H |
14 | 14 | ||
15 | #include <sound/soc.h> | 15 | #include <sound/soc.h> |
16 | #include <linux/mfd/wm8350/audio.h> | ||
16 | 17 | ||
17 | extern struct snd_soc_dai wm8350_dai; | 18 | extern struct snd_soc_dai wm8350_dai; |
18 | extern struct snd_soc_codec_device soc_codec_dev_wm8350; | 19 | extern struct snd_soc_codec_device soc_codec_dev_wm8350; |
diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c index 510efa604008..e4547de8eec2 100644 --- a/sound/soc/codecs/wm8400.c +++ b/sound/soc/codecs/wm8400.c | |||
@@ -1473,8 +1473,8 @@ static int wm8400_codec_probe(struct platform_device *dev) | |||
1473 | 1473 | ||
1474 | codec = &priv->codec; | 1474 | codec = &priv->codec; |
1475 | codec->private_data = priv; | 1475 | codec->private_data = priv; |
1476 | codec->control_data = dev->dev.driver_data; | 1476 | codec->control_data = dev_get_drvdata(&dev->dev); |
1477 | priv->wm8400 = dev->dev.driver_data; | 1477 | priv->wm8400 = dev_get_drvdata(&dev->dev); |
1478 | 1478 | ||
1479 | ret = regulator_bulk_get(priv->wm8400->dev, | 1479 | ret = regulator_bulk_get(priv->wm8400->dev, |
1480 | ARRAY_SIZE(power), &power[0]); | 1480 | ARRAY_SIZE(power), &power[0]); |
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c index e043e3f60008..7a205876ef4f 100644 --- a/sound/soc/codecs/wm8731.c +++ b/sound/soc/codecs/wm8731.c | |||
@@ -666,14 +666,14 @@ static int __devinit wm8731_spi_probe(struct spi_device *spi) | |||
666 | codec->hw_write = (hw_write_t)wm8731_spi_write; | 666 | codec->hw_write = (hw_write_t)wm8731_spi_write; |
667 | codec->dev = &spi->dev; | 667 | codec->dev = &spi->dev; |
668 | 668 | ||
669 | spi->dev.driver_data = wm8731; | 669 | dev_set_drvdata(&spi->dev, wm8731); |
670 | 670 | ||
671 | return wm8731_register(wm8731); | 671 | return wm8731_register(wm8731); |
672 | } | 672 | } |
673 | 673 | ||
674 | static int __devexit wm8731_spi_remove(struct spi_device *spi) | 674 | static int __devexit wm8731_spi_remove(struct spi_device *spi) |
675 | { | 675 | { |
676 | struct wm8731_priv *wm8731 = spi->dev.driver_data; | 676 | struct wm8731_priv *wm8731 = dev_get_drvdata(&spi->dev); |
677 | 677 | ||
678 | wm8731_unregister(wm8731); | 678 | wm8731_unregister(wm8731); |
679 | 679 | ||
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c index a6e8f3f7f052..d121e58cae2b 100644 --- a/sound/soc/codecs/wm8753.c +++ b/sound/soc/codecs/wm8753.c | |||
@@ -1822,14 +1822,14 @@ static int __devinit wm8753_spi_probe(struct spi_device *spi) | |||
1822 | codec->hw_write = (hw_write_t)wm8753_spi_write; | 1822 | codec->hw_write = (hw_write_t)wm8753_spi_write; |
1823 | codec->dev = &spi->dev; | 1823 | codec->dev = &spi->dev; |
1824 | 1824 | ||
1825 | spi->dev.driver_data = wm8753; | 1825 | dev_set_drvdata(&spi->dev, wm8753); |
1826 | 1826 | ||
1827 | return wm8753_register(wm8753); | 1827 | return wm8753_register(wm8753); |
1828 | } | 1828 | } |
1829 | 1829 | ||
1830 | static int __devexit wm8753_spi_remove(struct spi_device *spi) | 1830 | static int __devexit wm8753_spi_remove(struct spi_device *spi) |
1831 | { | 1831 | { |
1832 | struct wm8753_priv *wm8753 = spi->dev.driver_data; | 1832 | struct wm8753_priv *wm8753 = dev_get_drvdata(&spi->dev); |
1833 | wm8753_unregister(wm8753); | 1833 | wm8753_unregister(wm8753); |
1834 | return 0; | 1834 | return 0; |
1835 | } | 1835 | } |
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c index 8cf571f1a803..d8a9222fbf74 100644 --- a/sound/soc/codecs/wm8903.c +++ b/sound/soc/codecs/wm8903.c | |||
@@ -217,7 +217,6 @@ struct wm8903_priv { | |||
217 | int sysclk; | 217 | int sysclk; |
218 | 218 | ||
219 | /* Reference counts */ | 219 | /* Reference counts */ |
220 | int charge_pump_users; | ||
221 | int class_w_users; | 220 | int class_w_users; |
222 | int playback_active; | 221 | int playback_active; |
223 | int capture_active; | 222 | int capture_active; |
@@ -373,6 +372,15 @@ static void wm8903_reset(struct snd_soc_codec *codec) | |||
373 | #define WM8903_OUTPUT_INT 0x2 | 372 | #define WM8903_OUTPUT_INT 0x2 |
374 | #define WM8903_OUTPUT_IN 0x1 | 373 | #define WM8903_OUTPUT_IN 0x1 |
375 | 374 | ||
375 | static int wm8903_cp_event(struct snd_soc_dapm_widget *w, | ||
376 | struct snd_kcontrol *kcontrol, int event) | ||
377 | { | ||
378 | WARN_ON(event != SND_SOC_DAPM_POST_PMU); | ||
379 | mdelay(4); | ||
380 | |||
381 | return 0; | ||
382 | } | ||
383 | |||
376 | /* | 384 | /* |
377 | * Event for headphone and line out amplifier power changes. Special | 385 | * Event for headphone and line out amplifier power changes. Special |
378 | * power up/down sequences are required in order to maximise pop/click | 386 | * power up/down sequences are required in order to maximise pop/click |
@@ -382,19 +390,20 @@ static int wm8903_output_event(struct snd_soc_dapm_widget *w, | |||
382 | struct snd_kcontrol *kcontrol, int event) | 390 | struct snd_kcontrol *kcontrol, int event) |
383 | { | 391 | { |
384 | struct snd_soc_codec *codec = w->codec; | 392 | struct snd_soc_codec *codec = w->codec; |
385 | struct wm8903_priv *wm8903 = codec->private_data; | ||
386 | struct i2c_client *i2c = codec->control_data; | ||
387 | u16 val; | 393 | u16 val; |
388 | u16 reg; | 394 | u16 reg; |
395 | u16 dcs_reg; | ||
396 | u16 dcs_bit; | ||
389 | int shift; | 397 | int shift; |
390 | u16 cp_reg = wm8903_read(codec, WM8903_CHARGE_PUMP_0); | ||
391 | 398 | ||
392 | switch (w->reg) { | 399 | switch (w->reg) { |
393 | case WM8903_POWER_MANAGEMENT_2: | 400 | case WM8903_POWER_MANAGEMENT_2: |
394 | reg = WM8903_ANALOGUE_HP_0; | 401 | reg = WM8903_ANALOGUE_HP_0; |
402 | dcs_bit = 0 + w->shift; | ||
395 | break; | 403 | break; |
396 | case WM8903_POWER_MANAGEMENT_3: | 404 | case WM8903_POWER_MANAGEMENT_3: |
397 | reg = WM8903_ANALOGUE_LINEOUT_0; | 405 | reg = WM8903_ANALOGUE_LINEOUT_0; |
406 | dcs_bit = 2 + w->shift; | ||
398 | break; | 407 | break; |
399 | default: | 408 | default: |
400 | BUG(); | 409 | BUG(); |
@@ -419,18 +428,6 @@ static int wm8903_output_event(struct snd_soc_dapm_widget *w, | |||
419 | /* Short the output */ | 428 | /* Short the output */ |
420 | val &= ~(WM8903_OUTPUT_SHORT << shift); | 429 | val &= ~(WM8903_OUTPUT_SHORT << shift); |
421 | wm8903_write(codec, reg, val); | 430 | wm8903_write(codec, reg, val); |
422 | |||
423 | wm8903->charge_pump_users++; | ||
424 | |||
425 | dev_dbg(&i2c->dev, "Charge pump use count now %d\n", | ||
426 | wm8903->charge_pump_users); | ||
427 | |||
428 | if (wm8903->charge_pump_users == 1) { | ||
429 | dev_dbg(&i2c->dev, "Enabling charge pump\n"); | ||
430 | wm8903_write(codec, WM8903_CHARGE_PUMP_0, | ||
431 | cp_reg | WM8903_CP_ENA); | ||
432 | mdelay(4); | ||
433 | } | ||
434 | } | 431 | } |
435 | 432 | ||
436 | if (event & SND_SOC_DAPM_POST_PMU) { | 433 | if (event & SND_SOC_DAPM_POST_PMU) { |
@@ -446,6 +443,11 @@ static int wm8903_output_event(struct snd_soc_dapm_widget *w, | |||
446 | val |= (WM8903_OUTPUT_OUT << shift); | 443 | val |= (WM8903_OUTPUT_OUT << shift); |
447 | wm8903_write(codec, reg, val); | 444 | wm8903_write(codec, reg, val); |
448 | 445 | ||
446 | /* Enable the DC servo */ | ||
447 | dcs_reg = wm8903_read(codec, WM8903_DC_SERVO_0); | ||
448 | dcs_reg |= dcs_bit; | ||
449 | wm8903_write(codec, WM8903_DC_SERVO_0, dcs_reg); | ||
450 | |||
449 | /* Remove the short */ | 451 | /* Remove the short */ |
450 | val |= (WM8903_OUTPUT_SHORT << shift); | 452 | val |= (WM8903_OUTPUT_SHORT << shift); |
451 | wm8903_write(codec, reg, val); | 453 | wm8903_write(codec, reg, val); |
@@ -458,25 +460,17 @@ static int wm8903_output_event(struct snd_soc_dapm_widget *w, | |||
458 | val &= ~(WM8903_OUTPUT_SHORT << shift); | 460 | val &= ~(WM8903_OUTPUT_SHORT << shift); |
459 | wm8903_write(codec, reg, val); | 461 | wm8903_write(codec, reg, val); |
460 | 462 | ||
463 | /* Disable the DC servo */ | ||
464 | dcs_reg = wm8903_read(codec, WM8903_DC_SERVO_0); | ||
465 | dcs_reg &= ~dcs_bit; | ||
466 | wm8903_write(codec, WM8903_DC_SERVO_0, dcs_reg); | ||
467 | |||
461 | /* Then disable the intermediate and output stages */ | 468 | /* Then disable the intermediate and output stages */ |
462 | val &= ~((WM8903_OUTPUT_OUT | WM8903_OUTPUT_INT | | 469 | val &= ~((WM8903_OUTPUT_OUT | WM8903_OUTPUT_INT | |
463 | WM8903_OUTPUT_IN) << shift); | 470 | WM8903_OUTPUT_IN) << shift); |
464 | wm8903_write(codec, reg, val); | 471 | wm8903_write(codec, reg, val); |
465 | } | 472 | } |
466 | 473 | ||
467 | if (event & SND_SOC_DAPM_POST_PMD) { | ||
468 | wm8903->charge_pump_users--; | ||
469 | |||
470 | dev_dbg(&i2c->dev, "Charge pump use count now %d\n", | ||
471 | wm8903->charge_pump_users); | ||
472 | |||
473 | if (wm8903->charge_pump_users == 0) { | ||
474 | dev_dbg(&i2c->dev, "Disabling charge pump\n"); | ||
475 | wm8903_write(codec, WM8903_CHARGE_PUMP_0, | ||
476 | cp_reg & ~WM8903_CP_ENA); | ||
477 | } | ||
478 | } | ||
479 | |||
480 | return 0; | 474 | return 0; |
481 | } | 475 | } |
482 | 476 | ||
@@ -539,6 +533,7 @@ static int wm8903_class_w_put(struct snd_kcontrol *kcontrol, | |||
539 | /* ALSA can only do steps of .01dB */ | 533 | /* ALSA can only do steps of .01dB */ |
540 | static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1); | 534 | static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1); |
541 | 535 | ||
536 | static const DECLARE_TLV_DB_SCALE(digital_sidetone_tlv, -3600, 300, 0); | ||
542 | static const DECLARE_TLV_DB_SCALE(out_tlv, -5700, 100, 0); | 537 | static const DECLARE_TLV_DB_SCALE(out_tlv, -5700, 100, 0); |
543 | 538 | ||
544 | static const DECLARE_TLV_DB_SCALE(drc_tlv_thresh, 0, 75, 0); | 539 | static const DECLARE_TLV_DB_SCALE(drc_tlv_thresh, 0, 75, 0); |
@@ -657,6 +652,16 @@ static const struct soc_enum rinput_inv_enum = | |||
657 | SOC_ENUM_SINGLE(WM8903_ANALOGUE_RIGHT_INPUT_1, 4, 3, rinput_mux_text); | 652 | SOC_ENUM_SINGLE(WM8903_ANALOGUE_RIGHT_INPUT_1, 4, 3, rinput_mux_text); |
658 | 653 | ||
659 | 654 | ||
655 | static const char *sidetone_text[] = { | ||
656 | "None", "Left", "Right" | ||
657 | }; | ||
658 | |||
659 | static const struct soc_enum lsidetone_enum = | ||
660 | SOC_ENUM_SINGLE(WM8903_DAC_DIGITAL_0, 2, 3, sidetone_text); | ||
661 | |||
662 | static const struct soc_enum rsidetone_enum = | ||
663 | SOC_ENUM_SINGLE(WM8903_DAC_DIGITAL_0, 0, 3, sidetone_text); | ||
664 | |||
660 | static const struct snd_kcontrol_new wm8903_snd_controls[] = { | 665 | static const struct snd_kcontrol_new wm8903_snd_controls[] = { |
661 | 666 | ||
662 | /* Input PGAs - No TLV since the scale depends on PGA mode */ | 667 | /* Input PGAs - No TLV since the scale depends on PGA mode */ |
@@ -700,6 +705,9 @@ SOC_DOUBLE_R_TLV("Digital Capture Volume", WM8903_ADC_DIGITAL_VOLUME_LEFT, | |||
700 | SOC_ENUM("ADC Companding Mode", adc_companding), | 705 | SOC_ENUM("ADC Companding Mode", adc_companding), |
701 | SOC_SINGLE("ADC Companding Switch", WM8903_AUDIO_INTERFACE_0, 3, 1, 0), | 706 | SOC_SINGLE("ADC Companding Switch", WM8903_AUDIO_INTERFACE_0, 3, 1, 0), |
702 | 707 | ||
708 | SOC_DOUBLE_TLV("Digital Sidetone Volume", WM8903_DAC_DIGITAL_0, 4, 8, | ||
709 | 12, 0, digital_sidetone_tlv), | ||
710 | |||
703 | /* DAC */ | 711 | /* DAC */ |
704 | SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8903_DAC_DIGITAL_VOLUME_LEFT, | 712 | SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8903_DAC_DIGITAL_VOLUME_LEFT, |
705 | WM8903_DAC_DIGITAL_VOLUME_RIGHT, 1, 120, 0, digital_tlv), | 713 | WM8903_DAC_DIGITAL_VOLUME_RIGHT, 1, 120, 0, digital_tlv), |
@@ -762,6 +770,12 @@ static const struct snd_kcontrol_new rinput_mux = | |||
762 | static const struct snd_kcontrol_new rinput_inv_mux = | 770 | static const struct snd_kcontrol_new rinput_inv_mux = |
763 | SOC_DAPM_ENUM("Right Inverting Input Mux", rinput_inv_enum); | 771 | SOC_DAPM_ENUM("Right Inverting Input Mux", rinput_inv_enum); |
764 | 772 | ||
773 | static const struct snd_kcontrol_new lsidetone_mux = | ||
774 | SOC_DAPM_ENUM("DACL Sidetone Mux", lsidetone_enum); | ||
775 | |||
776 | static const struct snd_kcontrol_new rsidetone_mux = | ||
777 | SOC_DAPM_ENUM("DACR Sidetone Mux", rsidetone_enum); | ||
778 | |||
765 | static const struct snd_kcontrol_new left_output_mixer[] = { | 779 | static const struct snd_kcontrol_new left_output_mixer[] = { |
766 | SOC_DAPM_SINGLE("DACL Switch", WM8903_ANALOGUE_LEFT_MIX_0, 3, 1, 0), | 780 | SOC_DAPM_SINGLE("DACL Switch", WM8903_ANALOGUE_LEFT_MIX_0, 3, 1, 0), |
767 | SOC_DAPM_SINGLE("DACR Switch", WM8903_ANALOGUE_LEFT_MIX_0, 2, 1, 0), | 781 | SOC_DAPM_SINGLE("DACR Switch", WM8903_ANALOGUE_LEFT_MIX_0, 2, 1, 0), |
@@ -828,6 +842,9 @@ SND_SOC_DAPM_PGA("Right Input PGA", WM8903_POWER_MANAGEMENT_0, 0, 0, NULL, 0), | |||
828 | SND_SOC_DAPM_ADC("ADCL", "Left HiFi Capture", WM8903_POWER_MANAGEMENT_6, 1, 0), | 842 | SND_SOC_DAPM_ADC("ADCL", "Left HiFi Capture", WM8903_POWER_MANAGEMENT_6, 1, 0), |
829 | SND_SOC_DAPM_ADC("ADCR", "Right HiFi Capture", WM8903_POWER_MANAGEMENT_6, 0, 0), | 843 | SND_SOC_DAPM_ADC("ADCR", "Right HiFi Capture", WM8903_POWER_MANAGEMENT_6, 0, 0), |
830 | 844 | ||
845 | SND_SOC_DAPM_MUX("DACL Sidetone", SND_SOC_NOPM, 0, 0, &lsidetone_mux), | ||
846 | SND_SOC_DAPM_MUX("DACR Sidetone", SND_SOC_NOPM, 0, 0, &rsidetone_mux), | ||
847 | |||
831 | SND_SOC_DAPM_DAC("DACL", "Left Playback", WM8903_POWER_MANAGEMENT_6, 3, 0), | 848 | SND_SOC_DAPM_DAC("DACL", "Left Playback", WM8903_POWER_MANAGEMENT_6, 3, 0), |
832 | SND_SOC_DAPM_DAC("DACR", "Right Playback", WM8903_POWER_MANAGEMENT_6, 2, 0), | 849 | SND_SOC_DAPM_DAC("DACR", "Right Playback", WM8903_POWER_MANAGEMENT_6, 2, 0), |
833 | 850 | ||
@@ -844,26 +861,29 @@ SND_SOC_DAPM_MIXER("Right Speaker Mixer", WM8903_POWER_MANAGEMENT_4, 0, 0, | |||
844 | SND_SOC_DAPM_PGA_E("Left Headphone Output PGA", WM8903_POWER_MANAGEMENT_2, | 861 | SND_SOC_DAPM_PGA_E("Left Headphone Output PGA", WM8903_POWER_MANAGEMENT_2, |
845 | 1, 0, NULL, 0, wm8903_output_event, | 862 | 1, 0, NULL, 0, wm8903_output_event, |
846 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | | 863 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
847 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), | 864 | SND_SOC_DAPM_PRE_PMD), |
848 | SND_SOC_DAPM_PGA_E("Right Headphone Output PGA", WM8903_POWER_MANAGEMENT_2, | 865 | SND_SOC_DAPM_PGA_E("Right Headphone Output PGA", WM8903_POWER_MANAGEMENT_2, |
849 | 0, 0, NULL, 0, wm8903_output_event, | 866 | 0, 0, NULL, 0, wm8903_output_event, |
850 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | | 867 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
851 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), | 868 | SND_SOC_DAPM_PRE_PMD), |
852 | 869 | ||
853 | SND_SOC_DAPM_PGA_E("Left Line Output PGA", WM8903_POWER_MANAGEMENT_3, 1, 0, | 870 | SND_SOC_DAPM_PGA_E("Left Line Output PGA", WM8903_POWER_MANAGEMENT_3, 1, 0, |
854 | NULL, 0, wm8903_output_event, | 871 | NULL, 0, wm8903_output_event, |
855 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | | 872 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
856 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), | 873 | SND_SOC_DAPM_PRE_PMD), |
857 | SND_SOC_DAPM_PGA_E("Right Line Output PGA", WM8903_POWER_MANAGEMENT_3, 0, 0, | 874 | SND_SOC_DAPM_PGA_E("Right Line Output PGA", WM8903_POWER_MANAGEMENT_3, 0, 0, |
858 | NULL, 0, wm8903_output_event, | 875 | NULL, 0, wm8903_output_event, |
859 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | | 876 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
860 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), | 877 | SND_SOC_DAPM_PRE_PMD), |
861 | 878 | ||
862 | SND_SOC_DAPM_PGA("Left Speaker PGA", WM8903_POWER_MANAGEMENT_5, 1, 0, | 879 | SND_SOC_DAPM_PGA("Left Speaker PGA", WM8903_POWER_MANAGEMENT_5, 1, 0, |
863 | NULL, 0), | 880 | NULL, 0), |
864 | SND_SOC_DAPM_PGA("Right Speaker PGA", WM8903_POWER_MANAGEMENT_5, 0, 0, | 881 | SND_SOC_DAPM_PGA("Right Speaker PGA", WM8903_POWER_MANAGEMENT_5, 0, 0, |
865 | NULL, 0), | 882 | NULL, 0), |
866 | 883 | ||
884 | SND_SOC_DAPM_SUPPLY("Charge Pump", WM8903_CHARGE_PUMP_0, 0, 0, | ||
885 | wm8903_cp_event, SND_SOC_DAPM_POST_PMU), | ||
886 | SND_SOC_DAPM_SUPPLY("CLK_DSP", WM8903_CLOCK_RATES_2, 1, 0, NULL, 0), | ||
867 | }; | 887 | }; |
868 | 888 | ||
869 | static const struct snd_soc_dapm_route intercon[] = { | 889 | static const struct snd_soc_dapm_route intercon[] = { |
@@ -909,7 +929,19 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
909 | { "Right Input PGA", NULL, "Right Input Mode Mux" }, | 929 | { "Right Input PGA", NULL, "Right Input Mode Mux" }, |
910 | 930 | ||
911 | { "ADCL", NULL, "Left Input PGA" }, | 931 | { "ADCL", NULL, "Left Input PGA" }, |
932 | { "ADCL", NULL, "CLK_DSP" }, | ||
912 | { "ADCR", NULL, "Right Input PGA" }, | 933 | { "ADCR", NULL, "Right Input PGA" }, |
934 | { "ADCR", NULL, "CLK_DSP" }, | ||
935 | |||
936 | { "DACL Sidetone", "Left", "ADCL" }, | ||
937 | { "DACL Sidetone", "Right", "ADCR" }, | ||
938 | { "DACR Sidetone", "Left", "ADCL" }, | ||
939 | { "DACR Sidetone", "Right", "ADCR" }, | ||
940 | |||
941 | { "DACL", NULL, "DACL Sidetone" }, | ||
942 | { "DACL", NULL, "CLK_DSP" }, | ||
943 | { "DACR", NULL, "DACR Sidetone" }, | ||
944 | { "DACR", NULL, "CLK_DSP" }, | ||
913 | 945 | ||
914 | { "Left Output Mixer", "Left Bypass Switch", "Left Input PGA" }, | 946 | { "Left Output Mixer", "Left Bypass Switch", "Left Input PGA" }, |
915 | { "Left Output Mixer", "Right Bypass Switch", "Right Input PGA" }, | 947 | { "Left Output Mixer", "Right Bypass Switch", "Right Input PGA" }, |
@@ -951,6 +983,11 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
951 | 983 | ||
952 | { "ROP", NULL, "Right Speaker PGA" }, | 984 | { "ROP", NULL, "Right Speaker PGA" }, |
953 | { "RON", NULL, "Right Speaker PGA" }, | 985 | { "RON", NULL, "Right Speaker PGA" }, |
986 | |||
987 | { "Left Headphone Output PGA", NULL, "Charge Pump" }, | ||
988 | { "Right Headphone Output PGA", NULL, "Charge Pump" }, | ||
989 | { "Left Line Output PGA", NULL, "Charge Pump" }, | ||
990 | { "Right Line Output PGA", NULL, "Charge Pump" }, | ||
954 | }; | 991 | }; |
955 | 992 | ||
956 | static int wm8903_add_widgets(struct snd_soc_codec *codec) | 993 | static int wm8903_add_widgets(struct snd_soc_codec *codec) |
@@ -985,6 +1022,11 @@ static int wm8903_set_bias_level(struct snd_soc_codec *codec, | |||
985 | wm8903_write(codec, WM8903_CLOCK_RATES_2, | 1022 | wm8903_write(codec, WM8903_CLOCK_RATES_2, |
986 | WM8903_CLK_SYS_ENA); | 1023 | WM8903_CLK_SYS_ENA); |
987 | 1024 | ||
1025 | /* Change DC servo dither level in startup sequence */ | ||
1026 | wm8903_write(codec, WM8903_WRITE_SEQUENCER_0, 0x11); | ||
1027 | wm8903_write(codec, WM8903_WRITE_SEQUENCER_1, 0x1257); | ||
1028 | wm8903_write(codec, WM8903_WRITE_SEQUENCER_2, 0x2); | ||
1029 | |||
988 | wm8903_run_sequence(codec, 0); | 1030 | wm8903_run_sequence(codec, 0); |
989 | wm8903_sync_reg_cache(codec, codec->reg_cache); | 1031 | wm8903_sync_reg_cache(codec, codec->reg_cache); |
990 | 1032 | ||
@@ -1277,14 +1319,8 @@ static int wm8903_startup(struct snd_pcm_substream *substream, | |||
1277 | if (wm8903->master_substream) { | 1319 | if (wm8903->master_substream) { |
1278 | master_runtime = wm8903->master_substream->runtime; | 1320 | master_runtime = wm8903->master_substream->runtime; |
1279 | 1321 | ||
1280 | dev_dbg(&i2c->dev, "Constraining to %d bits at %dHz\n", | 1322 | dev_dbg(&i2c->dev, "Constraining to %d bits\n", |
1281 | master_runtime->sample_bits, | 1323 | master_runtime->sample_bits); |
1282 | master_runtime->rate); | ||
1283 | |||
1284 | snd_pcm_hw_constraint_minmax(substream->runtime, | ||
1285 | SNDRV_PCM_HW_PARAM_RATE, | ||
1286 | master_runtime->rate, | ||
1287 | master_runtime->rate); | ||
1288 | 1324 | ||
1289 | snd_pcm_hw_constraint_minmax(substream->runtime, | 1325 | snd_pcm_hw_constraint_minmax(substream->runtime, |
1290 | SNDRV_PCM_HW_PARAM_SAMPLE_BITS, | 1326 | SNDRV_PCM_HW_PARAM_SAMPLE_BITS, |
@@ -1523,6 +1559,7 @@ struct snd_soc_dai wm8903_dai = { | |||
1523 | .formats = WM8903_FORMATS, | 1559 | .formats = WM8903_FORMATS, |
1524 | }, | 1560 | }, |
1525 | .ops = &wm8903_dai_ops, | 1561 | .ops = &wm8903_dai_ops, |
1562 | .symmetric_rates = 1, | ||
1526 | }; | 1563 | }; |
1527 | EXPORT_SYMBOL_GPL(wm8903_dai); | 1564 | EXPORT_SYMBOL_GPL(wm8903_dai); |
1528 | 1565 | ||
diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c new file mode 100644 index 000000000000..a66dacc7cc83 --- /dev/null +++ b/sound/soc/codecs/wm8940.c | |||
@@ -0,0 +1,955 @@ | |||
1 | /* | ||
2 | * wm8940.c -- WM8940 ALSA Soc Audio driver | ||
3 | * | ||
4 | * Author: Jonathan Cameron <jic23@cam.ac.uk> | ||
5 | * | ||
6 | * Based on wm8510.c | ||
7 | * Copyright 2006 Wolfson Microelectronics PLC. | ||
8 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as | ||
12 | * published by the Free Software Foundation. | ||
13 | * | ||
14 | * Not currently handled: | ||
15 | * Notch filter control | ||
16 | * AUXMode (inverting vs mixer) | ||
17 | * No means to obtain current gain if alc enabled. | ||
18 | * No use made of gpio | ||
19 | * Fast VMID discharge for power down | ||
20 | * Soft Start | ||
21 | * DLR and ALR Swaps not enabled | ||
22 | * Digital Sidetone not supported | ||
23 | */ | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/moduleparam.h> | ||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/delay.h> | ||
29 | #include <linux/pm.h> | ||
30 | #include <linux/i2c.h> | ||
31 | #include <linux/platform_device.h> | ||
32 | #include <linux/spi/spi.h> | ||
33 | #include <sound/core.h> | ||
34 | #include <sound/pcm.h> | ||
35 | #include <sound/pcm_params.h> | ||
36 | #include <sound/soc.h> | ||
37 | #include <sound/soc-dapm.h> | ||
38 | #include <sound/initval.h> | ||
39 | #include <sound/tlv.h> | ||
40 | |||
41 | #include "wm8940.h" | ||
42 | |||
43 | struct wm8940_priv { | ||
44 | unsigned int sysclk; | ||
45 | u16 reg_cache[WM8940_CACHEREGNUM]; | ||
46 | struct snd_soc_codec codec; | ||
47 | }; | ||
48 | |||
49 | static u16 wm8940_reg_defaults[] = { | ||
50 | 0x8940, /* Soft Reset */ | ||
51 | 0x0000, /* Power 1 */ | ||
52 | 0x0000, /* Power 2 */ | ||
53 | 0x0000, /* Power 3 */ | ||
54 | 0x0010, /* Interface Control */ | ||
55 | 0x0000, /* Companding Control */ | ||
56 | 0x0140, /* Clock Control */ | ||
57 | 0x0000, /* Additional Controls */ | ||
58 | 0x0000, /* GPIO Control */ | ||
59 | 0x0002, /* Auto Increment Control */ | ||
60 | 0x0000, /* DAC Control */ | ||
61 | 0x00FF, /* DAC Volume */ | ||
62 | 0, | ||
63 | 0, | ||
64 | 0x0100, /* ADC Control */ | ||
65 | 0x00FF, /* ADC Volume */ | ||
66 | 0x0000, /* Notch Filter 1 Control 1 */ | ||
67 | 0x0000, /* Notch Filter 1 Control 2 */ | ||
68 | 0x0000, /* Notch Filter 2 Control 1 */ | ||
69 | 0x0000, /* Notch Filter 2 Control 2 */ | ||
70 | 0x0000, /* Notch Filter 3 Control 1 */ | ||
71 | 0x0000, /* Notch Filter 3 Control 2 */ | ||
72 | 0x0000, /* Notch Filter 4 Control 1 */ | ||
73 | 0x0000, /* Notch Filter 4 Control 2 */ | ||
74 | 0x0032, /* DAC Limit Control 1 */ | ||
75 | 0x0000, /* DAC Limit Control 2 */ | ||
76 | 0, | ||
77 | 0, | ||
78 | 0, | ||
79 | 0, | ||
80 | 0, | ||
81 | 0, | ||
82 | 0x0038, /* ALC Control 1 */ | ||
83 | 0x000B, /* ALC Control 2 */ | ||
84 | 0x0032, /* ALC Control 3 */ | ||
85 | 0x0000, /* Noise Gate */ | ||
86 | 0x0041, /* PLLN */ | ||
87 | 0x000C, /* PLLK1 */ | ||
88 | 0x0093, /* PLLK2 */ | ||
89 | 0x00E9, /* PLLK3 */ | ||
90 | 0, | ||
91 | 0, | ||
92 | 0x0030, /* ALC Control 4 */ | ||
93 | 0, | ||
94 | 0x0002, /* Input Control */ | ||
95 | 0x0050, /* PGA Gain */ | ||
96 | 0, | ||
97 | 0x0002, /* ADC Boost Control */ | ||
98 | 0, | ||
99 | 0x0002, /* Output Control */ | ||
100 | 0x0000, /* Speaker Mixer Control */ | ||
101 | 0, | ||
102 | 0, | ||
103 | 0, | ||
104 | 0x0079, /* Speaker Volume */ | ||
105 | 0, | ||
106 | 0x0000, /* Mono Mixer Control */ | ||
107 | }; | ||
108 | |||
109 | static inline unsigned int wm8940_read_reg_cache(struct snd_soc_codec *codec, | ||
110 | unsigned int reg) | ||
111 | { | ||
112 | u16 *cache = codec->reg_cache; | ||
113 | |||
114 | if (reg >= ARRAY_SIZE(wm8940_reg_defaults)) | ||
115 | return -1; | ||
116 | |||
117 | return cache[reg]; | ||
118 | } | ||
119 | |||
120 | static inline int wm8940_write_reg_cache(struct snd_soc_codec *codec, | ||
121 | u16 reg, unsigned int value) | ||
122 | { | ||
123 | u16 *cache = codec->reg_cache; | ||
124 | |||
125 | if (reg >= ARRAY_SIZE(wm8940_reg_defaults)) | ||
126 | return -1; | ||
127 | |||
128 | cache[reg] = value; | ||
129 | |||
130 | return 0; | ||
131 | } | ||
132 | |||
133 | static int wm8940_write(struct snd_soc_codec *codec, unsigned int reg, | ||
134 | unsigned int value) | ||
135 | { | ||
136 | int ret; | ||
137 | u8 data[3] = { reg, | ||
138 | (value & 0xff00) >> 8, | ||
139 | (value & 0x00ff) | ||
140 | }; | ||
141 | |||
142 | wm8940_write_reg_cache(codec, reg, value); | ||
143 | |||
144 | ret = codec->hw_write(codec->control_data, data, 3); | ||
145 | |||
146 | if (ret < 0) | ||
147 | return ret; | ||
148 | else if (ret != 3) | ||
149 | return -EIO; | ||
150 | return 0; | ||
151 | } | ||
152 | |||
153 | static const char *wm8940_companding[] = { "Off", "NC", "u-law", "A-law" }; | ||
154 | static const struct soc_enum wm8940_adc_companding_enum | ||
155 | = SOC_ENUM_SINGLE(WM8940_COMPANDINGCTL, 1, 4, wm8940_companding); | ||
156 | static const struct soc_enum wm8940_dac_companding_enum | ||
157 | = SOC_ENUM_SINGLE(WM8940_COMPANDINGCTL, 3, 4, wm8940_companding); | ||
158 | |||
159 | static const char *wm8940_alc_mode_text[] = {"ALC", "Limiter"}; | ||
160 | static const struct soc_enum wm8940_alc_mode_enum | ||
161 | = SOC_ENUM_SINGLE(WM8940_ALC3, 8, 2, wm8940_alc_mode_text); | ||
162 | |||
163 | static const char *wm8940_mic_bias_level_text[] = {"0.9", "0.65"}; | ||
164 | static const struct soc_enum wm8940_mic_bias_level_enum | ||
165 | = SOC_ENUM_SINGLE(WM8940_INPUTCTL, 8, 2, wm8940_mic_bias_level_text); | ||
166 | |||
167 | static const char *wm8940_filter_mode_text[] = {"Audio", "Application"}; | ||
168 | static const struct soc_enum wm8940_filter_mode_enum | ||
169 | = SOC_ENUM_SINGLE(WM8940_ADC, 7, 2, wm8940_filter_mode_text); | ||
170 | |||
171 | static DECLARE_TLV_DB_SCALE(wm8940_spk_vol_tlv, -5700, 100, 1); | ||
172 | static DECLARE_TLV_DB_SCALE(wm8940_att_tlv, -1000, 1000, 0); | ||
173 | static DECLARE_TLV_DB_SCALE(wm8940_pga_vol_tlv, -1200, 75, 0); | ||
174 | static DECLARE_TLV_DB_SCALE(wm8940_alc_min_tlv, -1200, 600, 0); | ||
175 | static DECLARE_TLV_DB_SCALE(wm8940_alc_max_tlv, 675, 600, 0); | ||
176 | static DECLARE_TLV_DB_SCALE(wm8940_alc_tar_tlv, -2250, 50, 0); | ||
177 | static DECLARE_TLV_DB_SCALE(wm8940_lim_boost_tlv, 0, 100, 0); | ||
178 | static DECLARE_TLV_DB_SCALE(wm8940_lim_thresh_tlv, -600, 100, 0); | ||
179 | static DECLARE_TLV_DB_SCALE(wm8940_adc_tlv, -12750, 50, 1); | ||
180 | static DECLARE_TLV_DB_SCALE(wm8940_capture_boost_vol_tlv, 0, 2000, 0); | ||
181 | |||
182 | static const struct snd_kcontrol_new wm8940_snd_controls[] = { | ||
183 | SOC_SINGLE("Digital Loopback Switch", WM8940_COMPANDINGCTL, | ||
184 | 6, 1, 0), | ||
185 | SOC_ENUM("DAC Companding", wm8940_dac_companding_enum), | ||
186 | SOC_ENUM("ADC Companding", wm8940_adc_companding_enum), | ||
187 | |||
188 | SOC_ENUM("ALC Mode", wm8940_alc_mode_enum), | ||
189 | SOC_SINGLE("ALC Switch", WM8940_ALC1, 8, 1, 0), | ||
190 | SOC_SINGLE_TLV("ALC Capture Max Gain", WM8940_ALC1, | ||
191 | 3, 7, 1, wm8940_alc_max_tlv), | ||
192 | SOC_SINGLE_TLV("ALC Capture Min Gain", WM8940_ALC1, | ||
193 | 0, 7, 0, wm8940_alc_min_tlv), | ||
194 | SOC_SINGLE_TLV("ALC Capture Target", WM8940_ALC2, | ||
195 | 0, 14, 0, wm8940_alc_tar_tlv), | ||
196 | SOC_SINGLE("ALC Capture Hold", WM8940_ALC2, 4, 10, 0), | ||
197 | SOC_SINGLE("ALC Capture Decay", WM8940_ALC3, 4, 10, 0), | ||
198 | SOC_SINGLE("ALC Capture Attach", WM8940_ALC3, 0, 10, 0), | ||
199 | SOC_SINGLE("ALC ZC Switch", WM8940_ALC4, 1, 1, 0), | ||
200 | SOC_SINGLE("ALC Capture Noise Gate Switch", WM8940_NOISEGATE, | ||
201 | 3, 1, 0), | ||
202 | SOC_SINGLE("ALC Capture Noise Gate Threshold", WM8940_NOISEGATE, | ||
203 | 0, 7, 0), | ||
204 | |||
205 | SOC_SINGLE("DAC Playback Limiter Switch", WM8940_DACLIM1, 8, 1, 0), | ||
206 | SOC_SINGLE("DAC Playback Limiter Attack", WM8940_DACLIM1, 0, 9, 0), | ||
207 | SOC_SINGLE("DAC Playback Limiter Decay", WM8940_DACLIM1, 4, 11, 0), | ||
208 | SOC_SINGLE_TLV("DAC Playback Limiter Threshold", WM8940_DACLIM2, | ||
209 | 4, 9, 1, wm8940_lim_thresh_tlv), | ||
210 | SOC_SINGLE_TLV("DAC Playback Limiter Boost", WM8940_DACLIM2, | ||
211 | 0, 12, 0, wm8940_lim_boost_tlv), | ||
212 | |||
213 | SOC_SINGLE("Capture PGA ZC Switch", WM8940_PGAGAIN, 7, 1, 0), | ||
214 | SOC_SINGLE_TLV("Capture PGA Volume", WM8940_PGAGAIN, | ||
215 | 0, 63, 0, wm8940_pga_vol_tlv), | ||
216 | SOC_SINGLE_TLV("Digital Playback Volume", WM8940_DACVOL, | ||
217 | 0, 255, 0, wm8940_adc_tlv), | ||
218 | SOC_SINGLE_TLV("Digital Capture Volume", WM8940_ADCVOL, | ||
219 | 0, 255, 0, wm8940_adc_tlv), | ||
220 | SOC_ENUM("Mic Bias Level", wm8940_mic_bias_level_enum), | ||
221 | SOC_SINGLE_TLV("Capture Boost Volue", WM8940_ADCBOOST, | ||
222 | 8, 1, 0, wm8940_capture_boost_vol_tlv), | ||
223 | SOC_SINGLE_TLV("Speaker Playback Volume", WM8940_SPKVOL, | ||
224 | 0, 63, 0, wm8940_spk_vol_tlv), | ||
225 | SOC_SINGLE("Speaker Playback Switch", WM8940_SPKVOL, 6, 1, 1), | ||
226 | |||
227 | SOC_SINGLE_TLV("Speaker Mixer Line Bypass Volume", WM8940_SPKVOL, | ||
228 | 8, 1, 1, wm8940_att_tlv), | ||
229 | SOC_SINGLE("Speaker Playback ZC Switch", WM8940_SPKVOL, 7, 1, 0), | ||
230 | |||
231 | SOC_SINGLE("Mono Out Switch", WM8940_MONOMIX, 6, 1, 1), | ||
232 | SOC_SINGLE_TLV("Mono Mixer Line Bypass Volume", WM8940_MONOMIX, | ||
233 | 7, 1, 1, wm8940_att_tlv), | ||
234 | |||
235 | SOC_SINGLE("High Pass Filter Switch", WM8940_ADC, 8, 1, 0), | ||
236 | SOC_ENUM("High Pass Filter Mode", wm8940_filter_mode_enum), | ||
237 | SOC_SINGLE("High Pass Filter Cut Off", WM8940_ADC, 4, 7, 0), | ||
238 | SOC_SINGLE("ADC Inversion Switch", WM8940_ADC, 0, 1, 0), | ||
239 | SOC_SINGLE("DAC Inversion Switch", WM8940_DAC, 0, 1, 0), | ||
240 | SOC_SINGLE("DAC Auto Mute Switch", WM8940_DAC, 2, 1, 0), | ||
241 | SOC_SINGLE("ZC Timeout Clock Switch", WM8940_ADDCNTRL, 0, 1, 0), | ||
242 | }; | ||
243 | |||
244 | static const struct snd_kcontrol_new wm8940_speaker_mixer_controls[] = { | ||
245 | SOC_DAPM_SINGLE("Line Bypass Switch", WM8940_SPKMIX, 1, 1, 0), | ||
246 | SOC_DAPM_SINGLE("Aux Playback Switch", WM8940_SPKMIX, 5, 1, 0), | ||
247 | SOC_DAPM_SINGLE("PCM Playback Switch", WM8940_SPKMIX, 0, 1, 0), | ||
248 | }; | ||
249 | |||
250 | static const struct snd_kcontrol_new wm8940_mono_mixer_controls[] = { | ||
251 | SOC_DAPM_SINGLE("Line Bypass Switch", WM8940_MONOMIX, 1, 1, 0), | ||
252 | SOC_DAPM_SINGLE("Aux Playback Switch", WM8940_MONOMIX, 2, 1, 0), | ||
253 | SOC_DAPM_SINGLE("PCM Playback Switch", WM8940_MONOMIX, 0, 1, 0), | ||
254 | }; | ||
255 | |||
256 | static DECLARE_TLV_DB_SCALE(wm8940_boost_vol_tlv, -1500, 300, 1); | ||
257 | static const struct snd_kcontrol_new wm8940_input_boost_controls[] = { | ||
258 | SOC_DAPM_SINGLE("Mic PGA Switch", WM8940_PGAGAIN, 6, 1, 1), | ||
259 | SOC_DAPM_SINGLE_TLV("Aux Volume", WM8940_ADCBOOST, | ||
260 | 0, 7, 0, wm8940_boost_vol_tlv), | ||
261 | SOC_DAPM_SINGLE_TLV("Mic Volume", WM8940_ADCBOOST, | ||
262 | 4, 7, 0, wm8940_boost_vol_tlv), | ||
263 | }; | ||
264 | |||
265 | static const struct snd_kcontrol_new wm8940_micpga_controls[] = { | ||
266 | SOC_DAPM_SINGLE("AUX Switch", WM8940_INPUTCTL, 2, 1, 0), | ||
267 | SOC_DAPM_SINGLE("MICP Switch", WM8940_INPUTCTL, 0, 1, 0), | ||
268 | SOC_DAPM_SINGLE("MICN Switch", WM8940_INPUTCTL, 1, 1, 0), | ||
269 | }; | ||
270 | |||
271 | static const struct snd_soc_dapm_widget wm8940_dapm_widgets[] = { | ||
272 | SND_SOC_DAPM_MIXER("Speaker Mixer", WM8940_POWER3, 2, 0, | ||
273 | &wm8940_speaker_mixer_controls[0], | ||
274 | ARRAY_SIZE(wm8940_speaker_mixer_controls)), | ||
275 | SND_SOC_DAPM_MIXER("Mono Mixer", WM8940_POWER3, 3, 0, | ||
276 | &wm8940_mono_mixer_controls[0], | ||
277 | ARRAY_SIZE(wm8940_mono_mixer_controls)), | ||
278 | SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8940_POWER3, 0, 0), | ||
279 | |||
280 | SND_SOC_DAPM_PGA("SpkN Out", WM8940_POWER3, 5, 0, NULL, 0), | ||
281 | SND_SOC_DAPM_PGA("SpkP Out", WM8940_POWER3, 6, 0, NULL, 0), | ||
282 | SND_SOC_DAPM_PGA("Mono Out", WM8940_POWER3, 7, 0, NULL, 0), | ||
283 | SND_SOC_DAPM_OUTPUT("MONOOUT"), | ||
284 | SND_SOC_DAPM_OUTPUT("SPKOUTP"), | ||
285 | SND_SOC_DAPM_OUTPUT("SPKOUTN"), | ||
286 | |||
287 | SND_SOC_DAPM_PGA("Aux Input", WM8940_POWER1, 6, 0, NULL, 0), | ||
288 | SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8940_POWER2, 0, 0), | ||
289 | SND_SOC_DAPM_MIXER("Mic PGA", WM8940_POWER2, 2, 0, | ||
290 | &wm8940_micpga_controls[0], | ||
291 | ARRAY_SIZE(wm8940_micpga_controls)), | ||
292 | SND_SOC_DAPM_MIXER("Boost Mixer", WM8940_POWER2, 4, 0, | ||
293 | &wm8940_input_boost_controls[0], | ||
294 | ARRAY_SIZE(wm8940_input_boost_controls)), | ||
295 | SND_SOC_DAPM_MICBIAS("Mic Bias", WM8940_POWER1, 4, 0), | ||
296 | |||
297 | SND_SOC_DAPM_INPUT("MICN"), | ||
298 | SND_SOC_DAPM_INPUT("MICP"), | ||
299 | SND_SOC_DAPM_INPUT("AUX"), | ||
300 | }; | ||
301 | |||
302 | static const struct snd_soc_dapm_route audio_map[] = { | ||
303 | /* Mono output mixer */ | ||
304 | {"Mono Mixer", "PCM Playback Switch", "DAC"}, | ||
305 | {"Mono Mixer", "Aux Playback Switch", "Aux Input"}, | ||
306 | {"Mono Mixer", "Line Bypass Switch", "Boost Mixer"}, | ||
307 | |||
308 | /* Speaker output mixer */ | ||
309 | {"Speaker Mixer", "PCM Playback Switch", "DAC"}, | ||
310 | {"Speaker Mixer", "Aux Playback Switch", "Aux Input"}, | ||
311 | {"Speaker Mixer", "Line Bypass Switch", "Boost Mixer"}, | ||
312 | |||
313 | /* Outputs */ | ||
314 | {"Mono Out", NULL, "Mono Mixer"}, | ||
315 | {"MONOOUT", NULL, "Mono Out"}, | ||
316 | {"SpkN Out", NULL, "Speaker Mixer"}, | ||
317 | {"SpkP Out", NULL, "Speaker Mixer"}, | ||
318 | {"SPKOUTN", NULL, "SpkN Out"}, | ||
319 | {"SPKOUTP", NULL, "SpkP Out"}, | ||
320 | |||
321 | /* Microphone PGA */ | ||
322 | {"Mic PGA", "MICN Switch", "MICN"}, | ||
323 | {"Mic PGA", "MICP Switch", "MICP"}, | ||
324 | {"Mic PGA", "AUX Switch", "AUX"}, | ||
325 | |||
326 | /* Boost Mixer */ | ||
327 | {"Boost Mixer", "Mic PGA Switch", "Mic PGA"}, | ||
328 | {"Boost Mixer", "Mic Volume", "MICP"}, | ||
329 | {"Boost Mixer", "Aux Volume", "Aux Input"}, | ||
330 | |||
331 | {"ADC", NULL, "Boost Mixer"}, | ||
332 | }; | ||
333 | |||
334 | static int wm8940_add_widgets(struct snd_soc_codec *codec) | ||
335 | { | ||
336 | int ret; | ||
337 | |||
338 | ret = snd_soc_dapm_new_controls(codec, wm8940_dapm_widgets, | ||
339 | ARRAY_SIZE(wm8940_dapm_widgets)); | ||
340 | if (ret) | ||
341 | goto error_ret; | ||
342 | ret = snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | ||
343 | if (ret) | ||
344 | goto error_ret; | ||
345 | ret = snd_soc_dapm_new_widgets(codec); | ||
346 | |||
347 | error_ret: | ||
348 | return ret; | ||
349 | } | ||
350 | |||
351 | #define wm8940_reset(c) wm8940_write(c, WM8940_SOFTRESET, 0); | ||
352 | |||
353 | static int wm8940_set_dai_fmt(struct snd_soc_dai *codec_dai, | ||
354 | unsigned int fmt) | ||
355 | { | ||
356 | struct snd_soc_codec *codec = codec_dai->codec; | ||
357 | u16 iface = wm8940_read_reg_cache(codec, WM8940_IFACE) & 0xFE67; | ||
358 | u16 clk = wm8940_read_reg_cache(codec, WM8940_CLOCK) & 0x1fe; | ||
359 | |||
360 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
361 | case SND_SOC_DAIFMT_CBM_CFM: | ||
362 | clk |= 1; | ||
363 | break; | ||
364 | case SND_SOC_DAIFMT_CBS_CFS: | ||
365 | break; | ||
366 | default: | ||
367 | return -EINVAL; | ||
368 | } | ||
369 | wm8940_write(codec, WM8940_CLOCK, clk); | ||
370 | |||
371 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
372 | case SND_SOC_DAIFMT_I2S: | ||
373 | iface |= (2 << 3); | ||
374 | break; | ||
375 | case SND_SOC_DAIFMT_LEFT_J: | ||
376 | iface |= (1 << 3); | ||
377 | break; | ||
378 | case SND_SOC_DAIFMT_RIGHT_J: | ||
379 | break; | ||
380 | case SND_SOC_DAIFMT_DSP_A: | ||
381 | iface |= (3 << 3); | ||
382 | break; | ||
383 | case SND_SOC_DAIFMT_DSP_B: | ||
384 | iface |= (3 << 3) | (1 << 7); | ||
385 | break; | ||
386 | } | ||
387 | |||
388 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
389 | case SND_SOC_DAIFMT_NB_NF: | ||
390 | break; | ||
391 | case SND_SOC_DAIFMT_NB_IF: | ||
392 | iface |= (1 << 7); | ||
393 | break; | ||
394 | case SND_SOC_DAIFMT_IB_NF: | ||
395 | iface |= (1 << 8); | ||
396 | break; | ||
397 | case SND_SOC_DAIFMT_IB_IF: | ||
398 | iface |= (1 << 8) | (1 << 7); | ||
399 | break; | ||
400 | } | ||
401 | |||
402 | wm8940_write(codec, WM8940_IFACE, iface); | ||
403 | |||
404 | return 0; | ||
405 | } | ||
406 | |||
407 | static int wm8940_i2s_hw_params(struct snd_pcm_substream *substream, | ||
408 | struct snd_pcm_hw_params *params, | ||
409 | struct snd_soc_dai *dai) | ||
410 | { | ||
411 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
412 | struct snd_soc_device *socdev = rtd->socdev; | ||
413 | struct snd_soc_codec *codec = socdev->card->codec; | ||
414 | u16 iface = wm8940_read_reg_cache(codec, WM8940_IFACE) & 0xFD9F; | ||
415 | u16 addcntrl = wm8940_read_reg_cache(codec, WM8940_ADDCNTRL) & 0xFFF1; | ||
416 | u16 companding = wm8940_read_reg_cache(codec, | ||
417 | WM8940_COMPANDINGCTL) & 0xFFDF; | ||
418 | int ret; | ||
419 | |||
420 | /* LoutR control */ | ||
421 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE | ||
422 | && params_channels(params) == 2) | ||
423 | iface |= (1 << 9); | ||
424 | |||
425 | switch (params_rate(params)) { | ||
426 | case SNDRV_PCM_RATE_8000: | ||
427 | addcntrl |= (0x5 << 1); | ||
428 | break; | ||
429 | case SNDRV_PCM_RATE_11025: | ||
430 | addcntrl |= (0x4 << 1); | ||
431 | break; | ||
432 | case SNDRV_PCM_RATE_16000: | ||
433 | addcntrl |= (0x3 << 1); | ||
434 | break; | ||
435 | case SNDRV_PCM_RATE_22050: | ||
436 | addcntrl |= (0x2 << 1); | ||
437 | break; | ||
438 | case SNDRV_PCM_RATE_32000: | ||
439 | addcntrl |= (0x1 << 1); | ||
440 | break; | ||
441 | case SNDRV_PCM_RATE_44100: | ||
442 | case SNDRV_PCM_RATE_48000: | ||
443 | break; | ||
444 | } | ||
445 | ret = wm8940_write(codec, WM8940_ADDCNTRL, addcntrl); | ||
446 | if (ret) | ||
447 | goto error_ret; | ||
448 | |||
449 | switch (params_format(params)) { | ||
450 | case SNDRV_PCM_FORMAT_S8: | ||
451 | companding = companding | (1 << 5); | ||
452 | break; | ||
453 | case SNDRV_PCM_FORMAT_S16_LE: | ||
454 | break; | ||
455 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
456 | iface |= (1 << 5); | ||
457 | break; | ||
458 | case SNDRV_PCM_FORMAT_S24_LE: | ||
459 | iface |= (2 << 5); | ||
460 | break; | ||
461 | case SNDRV_PCM_FORMAT_S32_LE: | ||
462 | iface |= (3 << 5); | ||
463 | break; | ||
464 | } | ||
465 | ret = wm8940_write(codec, WM8940_COMPANDINGCTL, companding); | ||
466 | if (ret) | ||
467 | goto error_ret; | ||
468 | ret = wm8940_write(codec, WM8940_IFACE, iface); | ||
469 | |||
470 | error_ret: | ||
471 | return ret; | ||
472 | } | ||
473 | |||
474 | static int wm8940_mute(struct snd_soc_dai *dai, int mute) | ||
475 | { | ||
476 | struct snd_soc_codec *codec = dai->codec; | ||
477 | u16 mute_reg = wm8940_read_reg_cache(codec, WM8940_DAC) & 0xffbf; | ||
478 | |||
479 | if (mute) | ||
480 | mute_reg |= 0x40; | ||
481 | |||
482 | return wm8940_write(codec, WM8940_DAC, mute_reg); | ||
483 | } | ||
484 | |||
485 | static int wm8940_set_bias_level(struct snd_soc_codec *codec, | ||
486 | enum snd_soc_bias_level level) | ||
487 | { | ||
488 | u16 val; | ||
489 | u16 pwr_reg = wm8940_read_reg_cache(codec, WM8940_POWER1) & 0x1F0; | ||
490 | int ret = 0; | ||
491 | |||
492 | switch (level) { | ||
493 | case SND_SOC_BIAS_ON: | ||
494 | /* ensure bufioen and biasen */ | ||
495 | pwr_reg |= (1 << 2) | (1 << 3); | ||
496 | /* Enable thermal shutdown */ | ||
497 | val = wm8940_read_reg_cache(codec, WM8940_OUTPUTCTL); | ||
498 | ret = wm8940_write(codec, WM8940_OUTPUTCTL, val | 0x2); | ||
499 | if (ret) | ||
500 | break; | ||
501 | /* set vmid to 75k */ | ||
502 | ret = wm8940_write(codec, WM8940_POWER1, pwr_reg | 0x1); | ||
503 | break; | ||
504 | case SND_SOC_BIAS_PREPARE: | ||
505 | /* ensure bufioen and biasen */ | ||
506 | pwr_reg |= (1 << 2) | (1 << 3); | ||
507 | ret = wm8940_write(codec, WM8940_POWER1, pwr_reg | 0x1); | ||
508 | break; | ||
509 | case SND_SOC_BIAS_STANDBY: | ||
510 | /* ensure bufioen and biasen */ | ||
511 | pwr_reg |= (1 << 2) | (1 << 3); | ||
512 | /* set vmid to 300k for standby */ | ||
513 | ret = wm8940_write(codec, WM8940_POWER1, pwr_reg | 0x2); | ||
514 | break; | ||
515 | case SND_SOC_BIAS_OFF: | ||
516 | ret = wm8940_write(codec, WM8940_POWER1, pwr_reg); | ||
517 | break; | ||
518 | } | ||
519 | |||
520 | return ret; | ||
521 | } | ||
522 | |||
523 | struct pll_ { | ||
524 | unsigned int pre_scale:2; | ||
525 | unsigned int n:4; | ||
526 | unsigned int k; | ||
527 | }; | ||
528 | |||
529 | static struct pll_ pll_div; | ||
530 | |||
531 | /* The size in bits of the pll divide multiplied by 10 | ||
532 | * to allow rounding later */ | ||
533 | #define FIXED_PLL_SIZE ((1 << 24) * 10) | ||
534 | static void pll_factors(unsigned int target, unsigned int source) | ||
535 | { | ||
536 | unsigned long long Kpart; | ||
537 | unsigned int K, Ndiv, Nmod; | ||
538 | /* The left shift ist to avoid accuracy loss when right shifting */ | ||
539 | Ndiv = target / source; | ||
540 | |||
541 | if (Ndiv > 12) { | ||
542 | source <<= 1; | ||
543 | /* Multiply by 2 */ | ||
544 | pll_div.pre_scale = 0; | ||
545 | Ndiv = target / source; | ||
546 | } else if (Ndiv < 3) { | ||
547 | source >>= 2; | ||
548 | /* Divide by 4 */ | ||
549 | pll_div.pre_scale = 3; | ||
550 | Ndiv = target / source; | ||
551 | } else if (Ndiv < 6) { | ||
552 | source >>= 1; | ||
553 | /* divide by 2 */ | ||
554 | pll_div.pre_scale = 2; | ||
555 | Ndiv = target / source; | ||
556 | } else | ||
557 | pll_div.pre_scale = 1; | ||
558 | |||
559 | if ((Ndiv < 6) || (Ndiv > 12)) | ||
560 | printk(KERN_WARNING | ||
561 | "WM8940 N value %d outwith recommended range!d\n", | ||
562 | Ndiv); | ||
563 | |||
564 | pll_div.n = Ndiv; | ||
565 | Nmod = target % source; | ||
566 | Kpart = FIXED_PLL_SIZE * (long long)Nmod; | ||
567 | |||
568 | do_div(Kpart, source); | ||
569 | |||
570 | K = Kpart & 0xFFFFFFFF; | ||
571 | |||
572 | /* Check if we need to round */ | ||
573 | if ((K % 10) >= 5) | ||
574 | K += 5; | ||
575 | |||
576 | /* Move down to proper range now rounding is done */ | ||
577 | K /= 10; | ||
578 | |||
579 | pll_div.k = K; | ||
580 | } | ||
581 | |||
582 | /* Untested at the moment */ | ||
583 | static int wm8940_set_dai_pll(struct snd_soc_dai *codec_dai, | ||
584 | int pll_id, unsigned int freq_in, unsigned int freq_out) | ||
585 | { | ||
586 | struct snd_soc_codec *codec = codec_dai->codec; | ||
587 | u16 reg; | ||
588 | |||
589 | /* Turn off PLL */ | ||
590 | reg = wm8940_read_reg_cache(codec, WM8940_POWER1); | ||
591 | wm8940_write(codec, WM8940_POWER1, reg & 0x1df); | ||
592 | |||
593 | if (freq_in == 0 || freq_out == 0) { | ||
594 | /* Clock CODEC directly from MCLK */ | ||
595 | reg = wm8940_read_reg_cache(codec, WM8940_CLOCK); | ||
596 | wm8940_write(codec, WM8940_CLOCK, reg & 0x0ff); | ||
597 | /* Pll power down */ | ||
598 | wm8940_write(codec, WM8940_PLLN, (1 << 7)); | ||
599 | return 0; | ||
600 | } | ||
601 | |||
602 | /* Pll is followed by a frequency divide by 4 */ | ||
603 | pll_factors(freq_out*4, freq_in); | ||
604 | if (pll_div.k) | ||
605 | wm8940_write(codec, WM8940_PLLN, | ||
606 | (pll_div.pre_scale << 4) | pll_div.n | (1 << 6)); | ||
607 | else /* No factional component */ | ||
608 | wm8940_write(codec, WM8940_PLLN, | ||
609 | (pll_div.pre_scale << 4) | pll_div.n); | ||
610 | wm8940_write(codec, WM8940_PLLK1, pll_div.k >> 18); | ||
611 | wm8940_write(codec, WM8940_PLLK2, (pll_div.k >> 9) & 0x1ff); | ||
612 | wm8940_write(codec, WM8940_PLLK3, pll_div.k & 0x1ff); | ||
613 | /* Enable the PLL */ | ||
614 | reg = wm8940_read_reg_cache(codec, WM8940_POWER1); | ||
615 | wm8940_write(codec, WM8940_POWER1, reg | 0x020); | ||
616 | |||
617 | /* Run CODEC from PLL instead of MCLK */ | ||
618 | reg = wm8940_read_reg_cache(codec, WM8940_CLOCK); | ||
619 | wm8940_write(codec, WM8940_CLOCK, reg | 0x100); | ||
620 | |||
621 | return 0; | ||
622 | } | ||
623 | |||
624 | static int wm8940_set_dai_sysclk(struct snd_soc_dai *codec_dai, | ||
625 | int clk_id, unsigned int freq, int dir) | ||
626 | { | ||
627 | struct snd_soc_codec *codec = codec_dai->codec; | ||
628 | struct wm8940_priv *wm8940 = codec->private_data; | ||
629 | |||
630 | switch (freq) { | ||
631 | case 11289600: | ||
632 | case 12000000: | ||
633 | case 12288000: | ||
634 | case 16934400: | ||
635 | case 18432000: | ||
636 | wm8940->sysclk = freq; | ||
637 | return 0; | ||
638 | } | ||
639 | return -EINVAL; | ||
640 | } | ||
641 | |||
642 | static int wm8940_set_dai_clkdiv(struct snd_soc_dai *codec_dai, | ||
643 | int div_id, int div) | ||
644 | { | ||
645 | struct snd_soc_codec *codec = codec_dai->codec; | ||
646 | u16 reg; | ||
647 | int ret = 0; | ||
648 | |||
649 | switch (div_id) { | ||
650 | case WM8940_BCLKDIV: | ||
651 | reg = wm8940_read_reg_cache(codec, WM8940_CLOCK) & 0xFFEF3; | ||
652 | ret = wm8940_write(codec, WM8940_CLOCK, reg | (div << 2)); | ||
653 | break; | ||
654 | case WM8940_MCLKDIV: | ||
655 | reg = wm8940_read_reg_cache(codec, WM8940_CLOCK) & 0xFF1F; | ||
656 | ret = wm8940_write(codec, WM8940_CLOCK, reg | (div << 5)); | ||
657 | break; | ||
658 | case WM8940_OPCLKDIV: | ||
659 | reg = wm8940_read_reg_cache(codec, WM8940_ADDCNTRL) & 0xFFCF; | ||
660 | ret = wm8940_write(codec, WM8940_ADDCNTRL, reg | (div << 4)); | ||
661 | break; | ||
662 | } | ||
663 | return ret; | ||
664 | } | ||
665 | |||
666 | #define WM8940_RATES SNDRV_PCM_RATE_8000_48000 | ||
667 | |||
668 | #define WM8940_FORMATS (SNDRV_PCM_FMTBIT_S8 | \ | ||
669 | SNDRV_PCM_FMTBIT_S16_LE | \ | ||
670 | SNDRV_PCM_FMTBIT_S20_3LE | \ | ||
671 | SNDRV_PCM_FMTBIT_S24_LE | \ | ||
672 | SNDRV_PCM_FMTBIT_S32_LE) | ||
673 | |||
674 | static struct snd_soc_dai_ops wm8940_dai_ops = { | ||
675 | .hw_params = wm8940_i2s_hw_params, | ||
676 | .set_sysclk = wm8940_set_dai_sysclk, | ||
677 | .digital_mute = wm8940_mute, | ||
678 | .set_fmt = wm8940_set_dai_fmt, | ||
679 | .set_clkdiv = wm8940_set_dai_clkdiv, | ||
680 | .set_pll = wm8940_set_dai_pll, | ||
681 | }; | ||
682 | |||
683 | struct snd_soc_dai wm8940_dai = { | ||
684 | .name = "WM8940", | ||
685 | .playback = { | ||
686 | .stream_name = "Playback", | ||
687 | .channels_min = 1, | ||
688 | .channels_max = 2, | ||
689 | .rates = WM8940_RATES, | ||
690 | .formats = WM8940_FORMATS, | ||
691 | }, | ||
692 | .capture = { | ||
693 | .stream_name = "Capture", | ||
694 | .channels_min = 1, | ||
695 | .channels_max = 2, | ||
696 | .rates = WM8940_RATES, | ||
697 | .formats = WM8940_FORMATS, | ||
698 | }, | ||
699 | .ops = &wm8940_dai_ops, | ||
700 | .symmetric_rates = 1, | ||
701 | }; | ||
702 | EXPORT_SYMBOL_GPL(wm8940_dai); | ||
703 | |||
704 | static int wm8940_suspend(struct platform_device *pdev, pm_message_t state) | ||
705 | { | ||
706 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
707 | struct snd_soc_codec *codec = socdev->card->codec; | ||
708 | |||
709 | return wm8940_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
710 | } | ||
711 | |||
712 | static int wm8940_resume(struct platform_device *pdev) | ||
713 | { | ||
714 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
715 | struct snd_soc_codec *codec = socdev->card->codec; | ||
716 | int i; | ||
717 | int ret; | ||
718 | u8 data[3]; | ||
719 | u16 *cache = codec->reg_cache; | ||
720 | |||
721 | /* Sync reg_cache with the hardware | ||
722 | * Could use auto incremented writes to speed this up | ||
723 | */ | ||
724 | for (i = 0; i < ARRAY_SIZE(wm8940_reg_defaults); i++) { | ||
725 | data[0] = i; | ||
726 | data[1] = (cache[i] & 0xFF00) >> 8; | ||
727 | data[2] = cache[i] & 0x00FF; | ||
728 | ret = codec->hw_write(codec->control_data, data, 3); | ||
729 | if (ret < 0) | ||
730 | goto error_ret; | ||
731 | else if (ret != 3) { | ||
732 | ret = -EIO; | ||
733 | goto error_ret; | ||
734 | } | ||
735 | } | ||
736 | ret = wm8940_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
737 | if (ret) | ||
738 | goto error_ret; | ||
739 | ret = wm8940_set_bias_level(codec, codec->suspend_bias_level); | ||
740 | |||
741 | error_ret: | ||
742 | return ret; | ||
743 | } | ||
744 | |||
745 | static struct snd_soc_codec *wm8940_codec; | ||
746 | |||
747 | static int wm8940_probe(struct platform_device *pdev) | ||
748 | { | ||
749 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
750 | struct snd_soc_codec *codec; | ||
751 | |||
752 | int ret = 0; | ||
753 | |||
754 | if (wm8940_codec == NULL) { | ||
755 | dev_err(&pdev->dev, "Codec device not registered\n"); | ||
756 | return -ENODEV; | ||
757 | } | ||
758 | |||
759 | socdev->card->codec = wm8940_codec; | ||
760 | codec = wm8940_codec; | ||
761 | |||
762 | mutex_init(&codec->mutex); | ||
763 | /* register pcms */ | ||
764 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
765 | if (ret < 0) { | ||
766 | dev_err(codec->dev, "failed to create pcms: %d\n", ret); | ||
767 | goto pcm_err; | ||
768 | } | ||
769 | |||
770 | ret = snd_soc_add_controls(codec, wm8940_snd_controls, | ||
771 | ARRAY_SIZE(wm8940_snd_controls)); | ||
772 | if (ret) | ||
773 | goto error_free_pcms; | ||
774 | ret = wm8940_add_widgets(codec); | ||
775 | if (ret) | ||
776 | goto error_free_pcms; | ||
777 | |||
778 | ret = snd_soc_init_card(socdev); | ||
779 | if (ret < 0) { | ||
780 | dev_err(codec->dev, "failed to register card: %d\n", ret); | ||
781 | goto error_free_pcms; | ||
782 | } | ||
783 | |||
784 | return ret; | ||
785 | |||
786 | error_free_pcms: | ||
787 | snd_soc_free_pcms(socdev); | ||
788 | snd_soc_dapm_free(socdev); | ||
789 | pcm_err: | ||
790 | return ret; | ||
791 | } | ||
792 | |||
793 | static int wm8940_remove(struct platform_device *pdev) | ||
794 | { | ||
795 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
796 | |||
797 | snd_soc_free_pcms(socdev); | ||
798 | snd_soc_dapm_free(socdev); | ||
799 | |||
800 | return 0; | ||
801 | } | ||
802 | |||
803 | struct snd_soc_codec_device soc_codec_dev_wm8940 = { | ||
804 | .probe = wm8940_probe, | ||
805 | .remove = wm8940_remove, | ||
806 | .suspend = wm8940_suspend, | ||
807 | .resume = wm8940_resume, | ||
808 | }; | ||
809 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8940); | ||
810 | |||
811 | static int wm8940_register(struct wm8940_priv *wm8940) | ||
812 | { | ||
813 | struct wm8940_setup_data *pdata = wm8940->codec.dev->platform_data; | ||
814 | struct snd_soc_codec *codec = &wm8940->codec; | ||
815 | int ret; | ||
816 | u16 reg; | ||
817 | if (wm8940_codec) { | ||
818 | dev_err(codec->dev, "Another WM8940 is registered\n"); | ||
819 | return -EINVAL; | ||
820 | } | ||
821 | |||
822 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
823 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
824 | |||
825 | codec->private_data = wm8940; | ||
826 | codec->name = "WM8940"; | ||
827 | codec->owner = THIS_MODULE; | ||
828 | codec->read = wm8940_read_reg_cache; | ||
829 | codec->write = wm8940_write; | ||
830 | codec->bias_level = SND_SOC_BIAS_OFF; | ||
831 | codec->set_bias_level = wm8940_set_bias_level; | ||
832 | codec->dai = &wm8940_dai; | ||
833 | codec->num_dai = 1; | ||
834 | codec->reg_cache_size = ARRAY_SIZE(wm8940_reg_defaults); | ||
835 | codec->reg_cache = &wm8940->reg_cache; | ||
836 | |||
837 | memcpy(codec->reg_cache, wm8940_reg_defaults, | ||
838 | sizeof(wm8940_reg_defaults)); | ||
839 | |||
840 | ret = wm8940_reset(codec); | ||
841 | if (ret < 0) { | ||
842 | dev_err(codec->dev, "Failed to issue reset\n"); | ||
843 | return ret; | ||
844 | } | ||
845 | |||
846 | wm8940_dai.dev = codec->dev; | ||
847 | |||
848 | wm8940_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
849 | |||
850 | ret = wm8940_write(codec, WM8940_POWER1, 0x180); | ||
851 | if (ret < 0) | ||
852 | return ret; | ||
853 | |||
854 | if (!pdata) | ||
855 | dev_warn(codec->dev, "No platform data supplied\n"); | ||
856 | else { | ||
857 | reg = wm8940_read_reg_cache(codec, WM8940_OUTPUTCTL); | ||
858 | ret = wm8940_write(codec, WM8940_OUTPUTCTL, reg | pdata->vroi); | ||
859 | if (ret < 0) | ||
860 | return ret; | ||
861 | } | ||
862 | |||
863 | |||
864 | wm8940_codec = codec; | ||
865 | |||
866 | ret = snd_soc_register_codec(codec); | ||
867 | if (ret) { | ||
868 | dev_err(codec->dev, "Failed to register codec: %d\n", ret); | ||
869 | return ret; | ||
870 | } | ||
871 | |||
872 | ret = snd_soc_register_dai(&wm8940_dai); | ||
873 | if (ret) { | ||
874 | dev_err(codec->dev, "Failed to register DAI: %d\n", ret); | ||
875 | snd_soc_unregister_codec(codec); | ||
876 | return ret; | ||
877 | } | ||
878 | |||
879 | return 0; | ||
880 | } | ||
881 | |||
882 | static void wm8940_unregister(struct wm8940_priv *wm8940) | ||
883 | { | ||
884 | wm8940_set_bias_level(&wm8940->codec, SND_SOC_BIAS_OFF); | ||
885 | snd_soc_unregister_dai(&wm8940_dai); | ||
886 | snd_soc_unregister_codec(&wm8940->codec); | ||
887 | kfree(wm8940); | ||
888 | wm8940_codec = NULL; | ||
889 | } | ||
890 | |||
891 | static int wm8940_i2c_probe(struct i2c_client *i2c, | ||
892 | const struct i2c_device_id *id) | ||
893 | { | ||
894 | struct wm8940_priv *wm8940; | ||
895 | struct snd_soc_codec *codec; | ||
896 | |||
897 | wm8940 = kzalloc(sizeof *wm8940, GFP_KERNEL); | ||
898 | if (wm8940 == NULL) | ||
899 | return -ENOMEM; | ||
900 | |||
901 | codec = &wm8940->codec; | ||
902 | codec->hw_write = (hw_write_t)i2c_master_send; | ||
903 | i2c_set_clientdata(i2c, wm8940); | ||
904 | codec->control_data = i2c; | ||
905 | codec->dev = &i2c->dev; | ||
906 | |||
907 | return wm8940_register(wm8940); | ||
908 | } | ||
909 | |||
910 | static int wm8940_i2c_remove(struct i2c_client *client) | ||
911 | { | ||
912 | struct wm8940_priv *wm8940 = i2c_get_clientdata(client); | ||
913 | |||
914 | wm8940_unregister(wm8940); | ||
915 | |||
916 | return 0; | ||
917 | } | ||
918 | |||
919 | static const struct i2c_device_id wm8940_i2c_id[] = { | ||
920 | { "wm8940", 0 }, | ||
921 | { } | ||
922 | }; | ||
923 | MODULE_DEVICE_TABLE(i2c, wm8940_i2c_id); | ||
924 | |||
925 | static struct i2c_driver wm8940_i2c_driver = { | ||
926 | .driver = { | ||
927 | .name = "WM8940 I2C Codec", | ||
928 | .owner = THIS_MODULE, | ||
929 | }, | ||
930 | .probe = wm8940_i2c_probe, | ||
931 | .remove = __devexit_p(wm8940_i2c_remove), | ||
932 | .id_table = wm8940_i2c_id, | ||
933 | }; | ||
934 | |||
935 | static int __init wm8940_modinit(void) | ||
936 | { | ||
937 | int ret; | ||
938 | |||
939 | ret = i2c_add_driver(&wm8940_i2c_driver); | ||
940 | if (ret) | ||
941 | printk(KERN_ERR "Failed to register WM8940 I2C driver: %d\n", | ||
942 | ret); | ||
943 | return ret; | ||
944 | } | ||
945 | module_init(wm8940_modinit); | ||
946 | |||
947 | static void __exit wm8940_exit(void) | ||
948 | { | ||
949 | i2c_del_driver(&wm8940_i2c_driver); | ||
950 | } | ||
951 | module_exit(wm8940_exit); | ||
952 | |||
953 | MODULE_DESCRIPTION("ASoC WM8940 driver"); | ||
954 | MODULE_AUTHOR("Jonathan Cameron"); | ||
955 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/wm8940.h b/sound/soc/codecs/wm8940.h new file mode 100644 index 000000000000..8410eed3ef84 --- /dev/null +++ b/sound/soc/codecs/wm8940.h | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | * wm8940.h -- WM8940 Soc Audio driver | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | |||
9 | #ifndef _WM8940_H | ||
10 | #define _WM8940_H | ||
11 | |||
12 | struct wm8940_setup_data { | ||
13 | /* Vref to analogue output resistance */ | ||
14 | #define WM8940_VROI_1K 0 | ||
15 | #define WM8940_VROI_30K 1 | ||
16 | unsigned int vroi:1; | ||
17 | }; | ||
18 | extern struct snd_soc_dai wm8940_dai; | ||
19 | extern struct snd_soc_codec_device soc_codec_dev_wm8940; | ||
20 | |||
21 | /* WM8940 register space */ | ||
22 | #define WM8940_SOFTRESET 0x00 | ||
23 | #define WM8940_POWER1 0x01 | ||
24 | #define WM8940_POWER2 0x02 | ||
25 | #define WM8940_POWER3 0x03 | ||
26 | #define WM8940_IFACE 0x04 | ||
27 | #define WM8940_COMPANDINGCTL 0x05 | ||
28 | #define WM8940_CLOCK 0x06 | ||
29 | #define WM8940_ADDCNTRL 0x07 | ||
30 | #define WM8940_GPIO 0x08 | ||
31 | #define WM8940_CTLINT 0x09 | ||
32 | #define WM8940_DAC 0x0A | ||
33 | #define WM8940_DACVOL 0x0B | ||
34 | |||
35 | #define WM8940_ADC 0x0E | ||
36 | #define WM8940_ADCVOL 0x0F | ||
37 | #define WM8940_NOTCH1 0x10 | ||
38 | #define WM8940_NOTCH2 0x11 | ||
39 | #define WM8940_NOTCH3 0x12 | ||
40 | #define WM8940_NOTCH4 0x13 | ||
41 | #define WM8940_NOTCH5 0x14 | ||
42 | #define WM8940_NOTCH6 0x15 | ||
43 | #define WM8940_NOTCH7 0x16 | ||
44 | #define WM8940_NOTCH8 0x17 | ||
45 | #define WM8940_DACLIM1 0x18 | ||
46 | #define WM8940_DACLIM2 0x19 | ||
47 | |||
48 | #define WM8940_ALC1 0x20 | ||
49 | #define WM8940_ALC2 0x21 | ||
50 | #define WM8940_ALC3 0x22 | ||
51 | #define WM8940_NOISEGATE 0x23 | ||
52 | #define WM8940_PLLN 0x24 | ||
53 | #define WM8940_PLLK1 0x25 | ||
54 | #define WM8940_PLLK2 0x26 | ||
55 | #define WM8940_PLLK3 0x27 | ||
56 | |||
57 | #define WM8940_ALC4 0x2A | ||
58 | |||
59 | #define WM8940_INPUTCTL 0x2C | ||
60 | #define WM8940_PGAGAIN 0x2D | ||
61 | |||
62 | #define WM8940_ADCBOOST 0x2F | ||
63 | |||
64 | #define WM8940_OUTPUTCTL 0x31 | ||
65 | #define WM8940_SPKMIX 0x32 | ||
66 | |||
67 | #define WM8940_SPKVOL 0x36 | ||
68 | |||
69 | #define WM8940_MONOMIX 0x38 | ||
70 | |||
71 | #define WM8940_CACHEREGNUM 0x57 | ||
72 | |||
73 | |||
74 | /* Clock divider Id's */ | ||
75 | #define WM8940_BCLKDIV 0 | ||
76 | #define WM8940_MCLKDIV 1 | ||
77 | #define WM8940_OPCLKDIV 2 | ||
78 | |||
79 | /* MCLK clock dividers */ | ||
80 | #define WM8940_MCLKDIV_1 0 | ||
81 | #define WM8940_MCLKDIV_1_5 1 | ||
82 | #define WM8940_MCLKDIV_2 2 | ||
83 | #define WM8940_MCLKDIV_3 3 | ||
84 | #define WM8940_MCLKDIV_4 4 | ||
85 | #define WM8940_MCLKDIV_6 5 | ||
86 | #define WM8940_MCLKDIV_8 6 | ||
87 | #define WM8940_MCLKDIV_12 7 | ||
88 | |||
89 | /* BCLK clock dividers */ | ||
90 | #define WM8940_BCLKDIV_1 0 | ||
91 | #define WM8940_BCLKDIV_2 1 | ||
92 | #define WM8940_BCLKDIV_4 2 | ||
93 | #define WM8940_BCLKDIV_8 3 | ||
94 | #define WM8940_BCLKDIV_16 4 | ||
95 | #define WM8940_BCLKDIV_32 5 | ||
96 | |||
97 | /* PLL Out Dividers */ | ||
98 | #define WM8940_OPCLKDIV_1 0 | ||
99 | #define WM8940_OPCLKDIV_2 1 | ||
100 | #define WM8940_OPCLKDIV_3 2 | ||
101 | #define WM8940_OPCLKDIV_4 3 | ||
102 | |||
103 | #endif /* _WM8940_H */ | ||
104 | |||
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c new file mode 100644 index 000000000000..e224d8add170 --- /dev/null +++ b/sound/soc/codecs/wm8960.c | |||
@@ -0,0 +1,969 @@ | |||
1 | /* | ||
2 | * wm8960.c -- WM8960 ALSA SoC Audio driver | ||
3 | * | ||
4 | * Author: Liam Girdwood | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | #include <linux/module.h> | ||
12 | #include <linux/moduleparam.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/delay.h> | ||
15 | #include <linux/pm.h> | ||
16 | #include <linux/i2c.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <sound/core.h> | ||
19 | #include <sound/pcm.h> | ||
20 | #include <sound/pcm_params.h> | ||
21 | #include <sound/soc.h> | ||
22 | #include <sound/soc-dapm.h> | ||
23 | #include <sound/initval.h> | ||
24 | #include <sound/tlv.h> | ||
25 | |||
26 | #include "wm8960.h" | ||
27 | |||
28 | #define AUDIO_NAME "wm8960" | ||
29 | |||
30 | struct snd_soc_codec_device soc_codec_dev_wm8960; | ||
31 | |||
32 | /* R25 - Power 1 */ | ||
33 | #define WM8960_VREF 0x40 | ||
34 | |||
35 | /* R28 - Anti-pop 1 */ | ||
36 | #define WM8960_POBCTRL 0x80 | ||
37 | #define WM8960_BUFDCOPEN 0x10 | ||
38 | #define WM8960_BUFIOEN 0x08 | ||
39 | #define WM8960_SOFT_ST 0x04 | ||
40 | #define WM8960_HPSTBY 0x01 | ||
41 | |||
42 | /* R29 - Anti-pop 2 */ | ||
43 | #define WM8960_DISOP 0x40 | ||
44 | |||
45 | /* | ||
46 | * wm8960 register cache | ||
47 | * We can't read the WM8960 register space when we are | ||
48 | * using 2 wire for device control, so we cache them instead. | ||
49 | */ | ||
50 | static const u16 wm8960_reg[WM8960_CACHEREGNUM] = { | ||
51 | 0x0097, 0x0097, 0x0000, 0x0000, | ||
52 | 0x0000, 0x0008, 0x0000, 0x000a, | ||
53 | 0x01c0, 0x0000, 0x00ff, 0x00ff, | ||
54 | 0x0000, 0x0000, 0x0000, 0x0000, | ||
55 | 0x0000, 0x007b, 0x0100, 0x0032, | ||
56 | 0x0000, 0x00c3, 0x00c3, 0x01c0, | ||
57 | 0x0000, 0x0000, 0x0000, 0x0000, | ||
58 | 0x0000, 0x0000, 0x0000, 0x0000, | ||
59 | 0x0100, 0x0100, 0x0050, 0x0050, | ||
60 | 0x0050, 0x0050, 0x0000, 0x0000, | ||
61 | 0x0000, 0x0000, 0x0040, 0x0000, | ||
62 | 0x0000, 0x0050, 0x0050, 0x0000, | ||
63 | 0x0002, 0x0037, 0x004d, 0x0080, | ||
64 | 0x0008, 0x0031, 0x0026, 0x00e9, | ||
65 | }; | ||
66 | |||
67 | struct wm8960_priv { | ||
68 | u16 reg_cache[WM8960_CACHEREGNUM]; | ||
69 | struct snd_soc_codec codec; | ||
70 | }; | ||
71 | |||
72 | /* | ||
73 | * read wm8960 register cache | ||
74 | */ | ||
75 | static inline unsigned int wm8960_read_reg_cache(struct snd_soc_codec *codec, | ||
76 | unsigned int reg) | ||
77 | { | ||
78 | u16 *cache = codec->reg_cache; | ||
79 | if (reg == WM8960_RESET) | ||
80 | return 0; | ||
81 | if (reg >= WM8960_CACHEREGNUM) | ||
82 | return -1; | ||
83 | return cache[reg]; | ||
84 | } | ||
85 | |||
86 | /* | ||
87 | * write wm8960 register cache | ||
88 | */ | ||
89 | static inline void wm8960_write_reg_cache(struct snd_soc_codec *codec, | ||
90 | u16 reg, unsigned int value) | ||
91 | { | ||
92 | u16 *cache = codec->reg_cache; | ||
93 | if (reg >= WM8960_CACHEREGNUM) | ||
94 | return; | ||
95 | cache[reg] = value; | ||
96 | } | ||
97 | |||
98 | static inline unsigned int wm8960_read(struct snd_soc_codec *codec, | ||
99 | unsigned int reg) | ||
100 | { | ||
101 | return wm8960_read_reg_cache(codec, reg); | ||
102 | } | ||
103 | |||
104 | /* | ||
105 | * write to the WM8960 register space | ||
106 | */ | ||
107 | static int wm8960_write(struct snd_soc_codec *codec, unsigned int reg, | ||
108 | unsigned int value) | ||
109 | { | ||
110 | u8 data[2]; | ||
111 | |||
112 | /* data is | ||
113 | * D15..D9 WM8960 register offset | ||
114 | * D8...D0 register data | ||
115 | */ | ||
116 | data[0] = (reg << 1) | ((value >> 8) & 0x0001); | ||
117 | data[1] = value & 0x00ff; | ||
118 | |||
119 | wm8960_write_reg_cache(codec, reg, value); | ||
120 | if (codec->hw_write(codec->control_data, data, 2) == 2) | ||
121 | return 0; | ||
122 | else | ||
123 | return -EIO; | ||
124 | } | ||
125 | |||
126 | #define wm8960_reset(c) wm8960_write(c, WM8960_RESET, 0) | ||
127 | |||
128 | /* enumerated controls */ | ||
129 | static const char *wm8960_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"}; | ||
130 | static const char *wm8960_polarity[] = {"No Inversion", "Left Inverted", | ||
131 | "Right Inverted", "Stereo Inversion"}; | ||
132 | static const char *wm8960_3d_upper_cutoff[] = {"High", "Low"}; | ||
133 | static const char *wm8960_3d_lower_cutoff[] = {"Low", "High"}; | ||
134 | static const char *wm8960_alcfunc[] = {"Off", "Right", "Left", "Stereo"}; | ||
135 | static const char *wm8960_alcmode[] = {"ALC", "Limiter"}; | ||
136 | |||
137 | static const struct soc_enum wm8960_enum[] = { | ||
138 | SOC_ENUM_SINGLE(WM8960_DACCTL1, 1, 4, wm8960_deemph), | ||
139 | SOC_ENUM_SINGLE(WM8960_DACCTL1, 5, 4, wm8960_polarity), | ||
140 | SOC_ENUM_SINGLE(WM8960_DACCTL2, 5, 4, wm8960_polarity), | ||
141 | SOC_ENUM_SINGLE(WM8960_3D, 6, 2, wm8960_3d_upper_cutoff), | ||
142 | SOC_ENUM_SINGLE(WM8960_3D, 5, 2, wm8960_3d_lower_cutoff), | ||
143 | SOC_ENUM_SINGLE(WM8960_ALC1, 7, 4, wm8960_alcfunc), | ||
144 | SOC_ENUM_SINGLE(WM8960_ALC3, 8, 2, wm8960_alcmode), | ||
145 | }; | ||
146 | |||
147 | static const DECLARE_TLV_DB_SCALE(adc_tlv, -9700, 50, 0); | ||
148 | static const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 50, 1); | ||
149 | static const DECLARE_TLV_DB_SCALE(bypass_tlv, -2100, 300, 0); | ||
150 | static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1); | ||
151 | |||
152 | static const struct snd_kcontrol_new wm8960_snd_controls[] = { | ||
153 | SOC_DOUBLE_R_TLV("Capture Volume", WM8960_LINVOL, WM8960_RINVOL, | ||
154 | 0, 63, 0, adc_tlv), | ||
155 | SOC_DOUBLE_R("Capture Volume ZC Switch", WM8960_LINVOL, WM8960_RINVOL, | ||
156 | 6, 1, 0), | ||
157 | SOC_DOUBLE_R("Capture Switch", WM8960_LINVOL, WM8960_RINVOL, | ||
158 | 7, 1, 0), | ||
159 | |||
160 | SOC_DOUBLE_R_TLV("Playback Volume", WM8960_LDAC, WM8960_RDAC, | ||
161 | 0, 255, 0, dac_tlv), | ||
162 | |||
163 | SOC_DOUBLE_R_TLV("Headphone Playback Volume", WM8960_LOUT1, WM8960_ROUT1, | ||
164 | 0, 127, 0, out_tlv), | ||
165 | SOC_DOUBLE_R("Headphone Playback ZC Switch", WM8960_LOUT1, WM8960_ROUT1, | ||
166 | 7, 1, 0), | ||
167 | |||
168 | SOC_DOUBLE_R_TLV("Speaker Playback Volume", WM8960_LOUT2, WM8960_ROUT2, | ||
169 | 0, 127, 0, out_tlv), | ||
170 | SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8960_LOUT2, WM8960_ROUT2, | ||
171 | 7, 1, 0), | ||
172 | SOC_SINGLE("Speaker DC Volume", WM8960_CLASSD3, 3, 5, 0), | ||
173 | SOC_SINGLE("Speaker AC Volume", WM8960_CLASSD3, 0, 5, 0), | ||
174 | |||
175 | SOC_SINGLE("PCM Playback -6dB Switch", WM8960_DACCTL1, 7, 1, 0), | ||
176 | SOC_ENUM("ADC Polarity", wm8960_enum[1]), | ||
177 | SOC_ENUM("Playback De-emphasis", wm8960_enum[0]), | ||
178 | SOC_SINGLE("ADC High Pass Filter Switch", WM8960_DACCTL1, 0, 1, 0), | ||
179 | |||
180 | SOC_ENUM("DAC Polarity", wm8960_enum[2]), | ||
181 | |||
182 | SOC_ENUM("3D Filter Upper Cut-Off", wm8960_enum[3]), | ||
183 | SOC_ENUM("3D Filter Lower Cut-Off", wm8960_enum[4]), | ||
184 | SOC_SINGLE("3D Volume", WM8960_3D, 1, 15, 0), | ||
185 | SOC_SINGLE("3D Switch", WM8960_3D, 0, 1, 0), | ||
186 | |||
187 | SOC_ENUM("ALC Function", wm8960_enum[5]), | ||
188 | SOC_SINGLE("ALC Max Gain", WM8960_ALC1, 4, 7, 0), | ||
189 | SOC_SINGLE("ALC Target", WM8960_ALC1, 0, 15, 1), | ||
190 | SOC_SINGLE("ALC Min Gain", WM8960_ALC2, 4, 7, 0), | ||
191 | SOC_SINGLE("ALC Hold Time", WM8960_ALC2, 0, 15, 0), | ||
192 | SOC_ENUM("ALC Mode", wm8960_enum[6]), | ||
193 | SOC_SINGLE("ALC Decay", WM8960_ALC3, 4, 15, 0), | ||
194 | SOC_SINGLE("ALC Attack", WM8960_ALC3, 0, 15, 0), | ||
195 | |||
196 | SOC_SINGLE("Noise Gate Threshold", WM8960_NOISEG, 3, 31, 0), | ||
197 | SOC_SINGLE("Noise Gate Switch", WM8960_NOISEG, 0, 1, 0), | ||
198 | |||
199 | SOC_DOUBLE_R("ADC PCM Capture Volume", WM8960_LINPATH, WM8960_RINPATH, | ||
200 | 0, 127, 0), | ||
201 | |||
202 | SOC_SINGLE_TLV("Left Output Mixer Boost Bypass Volume", | ||
203 | WM8960_BYPASS1, 4, 7, 1, bypass_tlv), | ||
204 | SOC_SINGLE_TLV("Left Output Mixer LINPUT3 Volume", | ||
205 | WM8960_LOUTMIX, 4, 7, 1, bypass_tlv), | ||
206 | SOC_SINGLE_TLV("Right Output Mixer Boost Bypass Volume", | ||
207 | WM8960_BYPASS2, 4, 7, 1, bypass_tlv), | ||
208 | SOC_SINGLE_TLV("Right Output Mixer RINPUT3 Volume", | ||
209 | WM8960_ROUTMIX, 4, 7, 1, bypass_tlv), | ||
210 | }; | ||
211 | |||
212 | static const struct snd_kcontrol_new wm8960_lin_boost[] = { | ||
213 | SOC_DAPM_SINGLE("LINPUT2 Switch", WM8960_LINPATH, 6, 1, 0), | ||
214 | SOC_DAPM_SINGLE("LINPUT3 Switch", WM8960_LINPATH, 7, 1, 0), | ||
215 | SOC_DAPM_SINGLE("LINPUT1 Switch", WM8960_LINPATH, 8, 1, 0), | ||
216 | }; | ||
217 | |||
218 | static const struct snd_kcontrol_new wm8960_lin[] = { | ||
219 | SOC_DAPM_SINGLE("Boost Switch", WM8960_LINPATH, 3, 1, 0), | ||
220 | }; | ||
221 | |||
222 | static const struct snd_kcontrol_new wm8960_rin_boost[] = { | ||
223 | SOC_DAPM_SINGLE("RINPUT2 Switch", WM8960_RINPATH, 6, 1, 0), | ||
224 | SOC_DAPM_SINGLE("RINPUT3 Switch", WM8960_RINPATH, 7, 1, 0), | ||
225 | SOC_DAPM_SINGLE("RINPUT1 Switch", WM8960_RINPATH, 8, 1, 0), | ||
226 | }; | ||
227 | |||
228 | static const struct snd_kcontrol_new wm8960_rin[] = { | ||
229 | SOC_DAPM_SINGLE("Boost Switch", WM8960_RINPATH, 3, 1, 0), | ||
230 | }; | ||
231 | |||
232 | static const struct snd_kcontrol_new wm8960_loutput_mixer[] = { | ||
233 | SOC_DAPM_SINGLE("PCM Playback Switch", WM8960_LOUTMIX, 8, 1, 0), | ||
234 | SOC_DAPM_SINGLE("LINPUT3 Switch", WM8960_LOUTMIX, 7, 1, 0), | ||
235 | SOC_DAPM_SINGLE("Boost Bypass Switch", WM8960_BYPASS1, 7, 1, 0), | ||
236 | }; | ||
237 | |||
238 | static const struct snd_kcontrol_new wm8960_routput_mixer[] = { | ||
239 | SOC_DAPM_SINGLE("PCM Playback Switch", WM8960_ROUTMIX, 8, 1, 0), | ||
240 | SOC_DAPM_SINGLE("RINPUT3 Switch", WM8960_ROUTMIX, 7, 1, 0), | ||
241 | SOC_DAPM_SINGLE("Boost Bypass Switch", WM8960_BYPASS2, 7, 1, 0), | ||
242 | }; | ||
243 | |||
244 | static const struct snd_kcontrol_new wm8960_mono_out[] = { | ||
245 | SOC_DAPM_SINGLE("Left Switch", WM8960_MONOMIX1, 7, 1, 0), | ||
246 | SOC_DAPM_SINGLE("Right Switch", WM8960_MONOMIX2, 7, 1, 0), | ||
247 | }; | ||
248 | |||
249 | static const struct snd_soc_dapm_widget wm8960_dapm_widgets[] = { | ||
250 | SND_SOC_DAPM_INPUT("LINPUT1"), | ||
251 | SND_SOC_DAPM_INPUT("RINPUT1"), | ||
252 | SND_SOC_DAPM_INPUT("LINPUT2"), | ||
253 | SND_SOC_DAPM_INPUT("RINPUT2"), | ||
254 | SND_SOC_DAPM_INPUT("LINPUT3"), | ||
255 | SND_SOC_DAPM_INPUT("RINPUT3"), | ||
256 | |||
257 | SND_SOC_DAPM_MICBIAS("MICB", WM8960_POWER1, 1, 0), | ||
258 | |||
259 | SND_SOC_DAPM_MIXER("Left Boost Mixer", WM8960_POWER1, 5, 0, | ||
260 | wm8960_lin_boost, ARRAY_SIZE(wm8960_lin_boost)), | ||
261 | SND_SOC_DAPM_MIXER("Right Boost Mixer", WM8960_POWER1, 4, 0, | ||
262 | wm8960_rin_boost, ARRAY_SIZE(wm8960_rin_boost)), | ||
263 | |||
264 | SND_SOC_DAPM_MIXER("Left Input Mixer", WM8960_POWER3, 5, 0, | ||
265 | wm8960_lin, ARRAY_SIZE(wm8960_lin)), | ||
266 | SND_SOC_DAPM_MIXER("Right Input Mixer", WM8960_POWER3, 4, 0, | ||
267 | wm8960_rin, ARRAY_SIZE(wm8960_rin)), | ||
268 | |||
269 | SND_SOC_DAPM_ADC("Left ADC", "Capture", WM8960_POWER2, 3, 0), | ||
270 | SND_SOC_DAPM_ADC("Right ADC", "Capture", WM8960_POWER2, 2, 0), | ||
271 | |||
272 | SND_SOC_DAPM_DAC("Left DAC", "Playback", WM8960_POWER2, 8, 0), | ||
273 | SND_SOC_DAPM_DAC("Right DAC", "Playback", WM8960_POWER2, 7, 0), | ||
274 | |||
275 | SND_SOC_DAPM_MIXER("Left Output Mixer", WM8960_POWER3, 3, 0, | ||
276 | &wm8960_loutput_mixer[0], | ||
277 | ARRAY_SIZE(wm8960_loutput_mixer)), | ||
278 | SND_SOC_DAPM_MIXER("Right Output Mixer", WM8960_POWER3, 2, 0, | ||
279 | &wm8960_routput_mixer[0], | ||
280 | ARRAY_SIZE(wm8960_routput_mixer)), | ||
281 | |||
282 | SND_SOC_DAPM_MIXER("Mono Output Mixer", WM8960_POWER2, 1, 0, | ||
283 | &wm8960_mono_out[0], | ||
284 | ARRAY_SIZE(wm8960_mono_out)), | ||
285 | |||
286 | SND_SOC_DAPM_PGA("LOUT1 PGA", WM8960_POWER2, 6, 0, NULL, 0), | ||
287 | SND_SOC_DAPM_PGA("ROUT1 PGA", WM8960_POWER2, 5, 0, NULL, 0), | ||
288 | |||
289 | SND_SOC_DAPM_PGA("Left Speaker PGA", WM8960_POWER2, 4, 0, NULL, 0), | ||
290 | SND_SOC_DAPM_PGA("Right Speaker PGA", WM8960_POWER2, 3, 0, NULL, 0), | ||
291 | |||
292 | SND_SOC_DAPM_PGA("Right Speaker Output", WM8960_CLASSD1, 7, 0, NULL, 0), | ||
293 | SND_SOC_DAPM_PGA("Left Speaker Output", WM8960_CLASSD1, 6, 0, NULL, 0), | ||
294 | |||
295 | SND_SOC_DAPM_OUTPUT("SPK_LP"), | ||
296 | SND_SOC_DAPM_OUTPUT("SPK_LN"), | ||
297 | SND_SOC_DAPM_OUTPUT("HP_L"), | ||
298 | SND_SOC_DAPM_OUTPUT("HP_R"), | ||
299 | SND_SOC_DAPM_OUTPUT("SPK_RP"), | ||
300 | SND_SOC_DAPM_OUTPUT("SPK_RN"), | ||
301 | SND_SOC_DAPM_OUTPUT("OUT3"), | ||
302 | }; | ||
303 | |||
304 | static const struct snd_soc_dapm_route audio_paths[] = { | ||
305 | { "Left Boost Mixer", "LINPUT1 Switch", "LINPUT1" }, | ||
306 | { "Left Boost Mixer", "LINPUT2 Switch", "LINPUT2" }, | ||
307 | { "Left Boost Mixer", "LINPUT3 Switch", "LINPUT3" }, | ||
308 | |||
309 | { "Left Input Mixer", "Boost Switch", "Left Boost Mixer", }, | ||
310 | { "Left Input Mixer", NULL, "LINPUT1", }, /* Really Boost Switch */ | ||
311 | { "Left Input Mixer", NULL, "LINPUT2" }, | ||
312 | { "Left Input Mixer", NULL, "LINPUT3" }, | ||
313 | |||
314 | { "Right Boost Mixer", "RINPUT1 Switch", "RINPUT1" }, | ||
315 | { "Right Boost Mixer", "RINPUT2 Switch", "RINPUT2" }, | ||
316 | { "Right Boost Mixer", "RINPUT3 Switch", "RINPUT3" }, | ||
317 | |||
318 | { "Right Input Mixer", "Boost Switch", "Right Boost Mixer", }, | ||
319 | { "Right Input Mixer", NULL, "RINPUT1", }, /* Really Boost Switch */ | ||
320 | { "Right Input Mixer", NULL, "RINPUT2" }, | ||
321 | { "Right Input Mixer", NULL, "LINPUT3" }, | ||
322 | |||
323 | { "Left ADC", NULL, "Left Input Mixer" }, | ||
324 | { "Right ADC", NULL, "Right Input Mixer" }, | ||
325 | |||
326 | { "Left Output Mixer", "LINPUT3 Switch", "LINPUT3" }, | ||
327 | { "Left Output Mixer", "Boost Bypass Switch", "Left Boost Mixer"} , | ||
328 | { "Left Output Mixer", "PCM Playback Switch", "Left DAC" }, | ||
329 | |||
330 | { "Right Output Mixer", "RINPUT3 Switch", "RINPUT3" }, | ||
331 | { "Right Output Mixer", "Boost Bypass Switch", "Right Boost Mixer" } , | ||
332 | { "Right Output Mixer", "PCM Playback Switch", "Right DAC" }, | ||
333 | |||
334 | { "Mono Output Mixer", "Left Switch", "Left Output Mixer" }, | ||
335 | { "Mono Output Mixer", "Right Switch", "Right Output Mixer" }, | ||
336 | |||
337 | { "LOUT1 PGA", NULL, "Left Output Mixer" }, | ||
338 | { "ROUT1 PGA", NULL, "Right Output Mixer" }, | ||
339 | |||
340 | { "HP_L", NULL, "LOUT1 PGA" }, | ||
341 | { "HP_R", NULL, "ROUT1 PGA" }, | ||
342 | |||
343 | { "Left Speaker PGA", NULL, "Left Output Mixer" }, | ||
344 | { "Right Speaker PGA", NULL, "Right Output Mixer" }, | ||
345 | |||
346 | { "Left Speaker Output", NULL, "Left Speaker PGA" }, | ||
347 | { "Right Speaker Output", NULL, "Right Speaker PGA" }, | ||
348 | |||
349 | { "SPK_LN", NULL, "Left Speaker Output" }, | ||
350 | { "SPK_LP", NULL, "Left Speaker Output" }, | ||
351 | { "SPK_RN", NULL, "Right Speaker Output" }, | ||
352 | { "SPK_RP", NULL, "Right Speaker Output" }, | ||
353 | |||
354 | { "OUT3", NULL, "Mono Output Mixer", } | ||
355 | }; | ||
356 | |||
357 | static int wm8960_add_widgets(struct snd_soc_codec *codec) | ||
358 | { | ||
359 | snd_soc_dapm_new_controls(codec, wm8960_dapm_widgets, | ||
360 | ARRAY_SIZE(wm8960_dapm_widgets)); | ||
361 | |||
362 | snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths)); | ||
363 | |||
364 | snd_soc_dapm_new_widgets(codec); | ||
365 | return 0; | ||
366 | } | ||
367 | |||
368 | static int wm8960_set_dai_fmt(struct snd_soc_dai *codec_dai, | ||
369 | unsigned int fmt) | ||
370 | { | ||
371 | struct snd_soc_codec *codec = codec_dai->codec; | ||
372 | u16 iface = 0; | ||
373 | |||
374 | /* set master/slave audio interface */ | ||
375 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
376 | case SND_SOC_DAIFMT_CBM_CFM: | ||
377 | iface |= 0x0040; | ||
378 | break; | ||
379 | case SND_SOC_DAIFMT_CBS_CFS: | ||
380 | break; | ||
381 | default: | ||
382 | return -EINVAL; | ||
383 | } | ||
384 | |||
385 | /* interface format */ | ||
386 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
387 | case SND_SOC_DAIFMT_I2S: | ||
388 | iface |= 0x0002; | ||
389 | break; | ||
390 | case SND_SOC_DAIFMT_RIGHT_J: | ||
391 | break; | ||
392 | case SND_SOC_DAIFMT_LEFT_J: | ||
393 | iface |= 0x0001; | ||
394 | break; | ||
395 | case SND_SOC_DAIFMT_DSP_A: | ||
396 | iface |= 0x0003; | ||
397 | break; | ||
398 | case SND_SOC_DAIFMT_DSP_B: | ||
399 | iface |= 0x0013; | ||
400 | break; | ||
401 | default: | ||
402 | return -EINVAL; | ||
403 | } | ||
404 | |||
405 | /* clock inversion */ | ||
406 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
407 | case SND_SOC_DAIFMT_NB_NF: | ||
408 | break; | ||
409 | case SND_SOC_DAIFMT_IB_IF: | ||
410 | iface |= 0x0090; | ||
411 | break; | ||
412 | case SND_SOC_DAIFMT_IB_NF: | ||
413 | iface |= 0x0080; | ||
414 | break; | ||
415 | case SND_SOC_DAIFMT_NB_IF: | ||
416 | iface |= 0x0010; | ||
417 | break; | ||
418 | default: | ||
419 | return -EINVAL; | ||
420 | } | ||
421 | |||
422 | /* set iface */ | ||
423 | wm8960_write(codec, WM8960_IFACE1, iface); | ||
424 | return 0; | ||
425 | } | ||
426 | |||
427 | static int wm8960_hw_params(struct snd_pcm_substream *substream, | ||
428 | struct snd_pcm_hw_params *params, | ||
429 | struct snd_soc_dai *dai) | ||
430 | { | ||
431 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
432 | struct snd_soc_device *socdev = rtd->socdev; | ||
433 | struct snd_soc_codec *codec = socdev->card->codec; | ||
434 | u16 iface = wm8960_read(codec, WM8960_IFACE1) & 0xfff3; | ||
435 | |||
436 | /* bit size */ | ||
437 | switch (params_format(params)) { | ||
438 | case SNDRV_PCM_FORMAT_S16_LE: | ||
439 | break; | ||
440 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
441 | iface |= 0x0004; | ||
442 | break; | ||
443 | case SNDRV_PCM_FORMAT_S24_LE: | ||
444 | iface |= 0x0008; | ||
445 | break; | ||
446 | } | ||
447 | |||
448 | /* set iface */ | ||
449 | wm8960_write(codec, WM8960_IFACE1, iface); | ||
450 | return 0; | ||
451 | } | ||
452 | |||
453 | static int wm8960_mute(struct snd_soc_dai *dai, int mute) | ||
454 | { | ||
455 | struct snd_soc_codec *codec = dai->codec; | ||
456 | u16 mute_reg = wm8960_read(codec, WM8960_DACCTL1) & 0xfff7; | ||
457 | |||
458 | if (mute) | ||
459 | wm8960_write(codec, WM8960_DACCTL1, mute_reg | 0x8); | ||
460 | else | ||
461 | wm8960_write(codec, WM8960_DACCTL1, mute_reg); | ||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | static int wm8960_set_bias_level(struct snd_soc_codec *codec, | ||
466 | enum snd_soc_bias_level level) | ||
467 | { | ||
468 | struct wm8960_data *pdata = codec->dev->platform_data; | ||
469 | u16 reg; | ||
470 | |||
471 | switch (level) { | ||
472 | case SND_SOC_BIAS_ON: | ||
473 | break; | ||
474 | |||
475 | case SND_SOC_BIAS_PREPARE: | ||
476 | /* Set VMID to 2x50k */ | ||
477 | reg = wm8960_read(codec, WM8960_POWER1); | ||
478 | reg &= ~0x180; | ||
479 | reg |= 0x80; | ||
480 | wm8960_write(codec, WM8960_POWER1, reg); | ||
481 | break; | ||
482 | |||
483 | case SND_SOC_BIAS_STANDBY: | ||
484 | if (codec->bias_level == SND_SOC_BIAS_OFF) { | ||
485 | /* Enable anti-pop features */ | ||
486 | wm8960_write(codec, WM8960_APOP1, | ||
487 | WM8960_POBCTRL | WM8960_SOFT_ST | | ||
488 | WM8960_BUFDCOPEN | WM8960_BUFIOEN); | ||
489 | |||
490 | /* Discharge HP output */ | ||
491 | reg = WM8960_DISOP; | ||
492 | if (pdata) | ||
493 | reg |= pdata->dres << 4; | ||
494 | wm8960_write(codec, WM8960_APOP2, reg); | ||
495 | |||
496 | msleep(400); | ||
497 | |||
498 | wm8960_write(codec, WM8960_APOP2, 0); | ||
499 | |||
500 | /* Enable & ramp VMID at 2x50k */ | ||
501 | reg = wm8960_read(codec, WM8960_POWER1); | ||
502 | reg |= 0x80; | ||
503 | wm8960_write(codec, WM8960_POWER1, reg); | ||
504 | msleep(100); | ||
505 | |||
506 | /* Enable VREF */ | ||
507 | wm8960_write(codec, WM8960_POWER1, reg | WM8960_VREF); | ||
508 | |||
509 | /* Disable anti-pop features */ | ||
510 | wm8960_write(codec, WM8960_APOP1, WM8960_BUFIOEN); | ||
511 | } | ||
512 | |||
513 | /* Set VMID to 2x250k */ | ||
514 | reg = wm8960_read(codec, WM8960_POWER1); | ||
515 | reg &= ~0x180; | ||
516 | reg |= 0x100; | ||
517 | wm8960_write(codec, WM8960_POWER1, reg); | ||
518 | break; | ||
519 | |||
520 | case SND_SOC_BIAS_OFF: | ||
521 | /* Enable anti-pop features */ | ||
522 | wm8960_write(codec, WM8960_APOP1, | ||
523 | WM8960_POBCTRL | WM8960_SOFT_ST | | ||
524 | WM8960_BUFDCOPEN | WM8960_BUFIOEN); | ||
525 | |||
526 | /* Disable VMID and VREF, let them discharge */ | ||
527 | wm8960_write(codec, WM8960_POWER1, 0); | ||
528 | msleep(600); | ||
529 | |||
530 | wm8960_write(codec, WM8960_APOP1, 0); | ||
531 | break; | ||
532 | } | ||
533 | |||
534 | codec->bias_level = level; | ||
535 | |||
536 | return 0; | ||
537 | } | ||
538 | |||
539 | /* PLL divisors */ | ||
540 | struct _pll_div { | ||
541 | u32 pre_div:1; | ||
542 | u32 n:4; | ||
543 | u32 k:24; | ||
544 | }; | ||
545 | |||
546 | /* The size in bits of the pll divide multiplied by 10 | ||
547 | * to allow rounding later */ | ||
548 | #define FIXED_PLL_SIZE ((1 << 24) * 10) | ||
549 | |||
550 | static int pll_factors(unsigned int source, unsigned int target, | ||
551 | struct _pll_div *pll_div) | ||
552 | { | ||
553 | unsigned long long Kpart; | ||
554 | unsigned int K, Ndiv, Nmod; | ||
555 | |||
556 | pr_debug("WM8960 PLL: setting %dHz->%dHz\n", source, target); | ||
557 | |||
558 | /* Scale up target to PLL operating frequency */ | ||
559 | target *= 4; | ||
560 | |||
561 | Ndiv = target / source; | ||
562 | if (Ndiv < 6) { | ||
563 | source >>= 1; | ||
564 | pll_div->pre_div = 1; | ||
565 | Ndiv = target / source; | ||
566 | } else | ||
567 | pll_div->pre_div = 0; | ||
568 | |||
569 | if ((Ndiv < 6) || (Ndiv > 12)) { | ||
570 | pr_err("WM8960 PLL: Unsupported N=%d\n", Ndiv); | ||
571 | return -EINVAL; | ||
572 | } | ||
573 | |||
574 | pll_div->n = Ndiv; | ||
575 | Nmod = target % source; | ||
576 | Kpart = FIXED_PLL_SIZE * (long long)Nmod; | ||
577 | |||
578 | do_div(Kpart, source); | ||
579 | |||
580 | K = Kpart & 0xFFFFFFFF; | ||
581 | |||
582 | /* Check if we need to round */ | ||
583 | if ((K % 10) >= 5) | ||
584 | K += 5; | ||
585 | |||
586 | /* Move down to proper range now rounding is done */ | ||
587 | K /= 10; | ||
588 | |||
589 | pll_div->k = K; | ||
590 | |||
591 | pr_debug("WM8960 PLL: N=%x K=%x pre_div=%d\n", | ||
592 | pll_div->n, pll_div->k, pll_div->pre_div); | ||
593 | |||
594 | return 0; | ||
595 | } | ||
596 | |||
597 | static int wm8960_set_dai_pll(struct snd_soc_dai *codec_dai, | ||
598 | int pll_id, unsigned int freq_in, unsigned int freq_out) | ||
599 | { | ||
600 | struct snd_soc_codec *codec = codec_dai->codec; | ||
601 | u16 reg; | ||
602 | static struct _pll_div pll_div; | ||
603 | int ret; | ||
604 | |||
605 | if (freq_in && freq_out) { | ||
606 | ret = pll_factors(freq_in, freq_out, &pll_div); | ||
607 | if (ret != 0) | ||
608 | return ret; | ||
609 | } | ||
610 | |||
611 | /* Disable the PLL: even if we are changing the frequency the | ||
612 | * PLL needs to be disabled while we do so. */ | ||
613 | wm8960_write(codec, WM8960_CLOCK1, | ||
614 | wm8960_read(codec, WM8960_CLOCK1) & ~1); | ||
615 | wm8960_write(codec, WM8960_POWER2, | ||
616 | wm8960_read(codec, WM8960_POWER2) & ~1); | ||
617 | |||
618 | if (!freq_in || !freq_out) | ||
619 | return 0; | ||
620 | |||
621 | reg = wm8960_read(codec, WM8960_PLL1) & ~0x3f; | ||
622 | reg |= pll_div.pre_div << 4; | ||
623 | reg |= pll_div.n; | ||
624 | |||
625 | if (pll_div.k) { | ||
626 | reg |= 0x20; | ||
627 | |||
628 | wm8960_write(codec, WM8960_PLL2, (pll_div.k >> 18) & 0x3f); | ||
629 | wm8960_write(codec, WM8960_PLL3, (pll_div.k >> 9) & 0x1ff); | ||
630 | wm8960_write(codec, WM8960_PLL4, pll_div.k & 0x1ff); | ||
631 | } | ||
632 | wm8960_write(codec, WM8960_PLL1, reg); | ||
633 | |||
634 | /* Turn it on */ | ||
635 | wm8960_write(codec, WM8960_POWER2, | ||
636 | wm8960_read(codec, WM8960_POWER2) | 1); | ||
637 | msleep(250); | ||
638 | wm8960_write(codec, WM8960_CLOCK1, | ||
639 | wm8960_read(codec, WM8960_CLOCK1) | 1); | ||
640 | |||
641 | return 0; | ||
642 | } | ||
643 | |||
644 | static int wm8960_set_dai_clkdiv(struct snd_soc_dai *codec_dai, | ||
645 | int div_id, int div) | ||
646 | { | ||
647 | struct snd_soc_codec *codec = codec_dai->codec; | ||
648 | u16 reg; | ||
649 | |||
650 | switch (div_id) { | ||
651 | case WM8960_SYSCLKSEL: | ||
652 | reg = wm8960_read(codec, WM8960_CLOCK1) & 0x1fe; | ||
653 | wm8960_write(codec, WM8960_CLOCK1, reg | div); | ||
654 | break; | ||
655 | case WM8960_SYSCLKDIV: | ||
656 | reg = wm8960_read(codec, WM8960_CLOCK1) & 0x1f9; | ||
657 | wm8960_write(codec, WM8960_CLOCK1, reg | div); | ||
658 | break; | ||
659 | case WM8960_DACDIV: | ||
660 | reg = wm8960_read(codec, WM8960_CLOCK1) & 0x1c7; | ||
661 | wm8960_write(codec, WM8960_CLOCK1, reg | div); | ||
662 | break; | ||
663 | case WM8960_OPCLKDIV: | ||
664 | reg = wm8960_read(codec, WM8960_PLL1) & 0x03f; | ||
665 | wm8960_write(codec, WM8960_PLL1, reg | div); | ||
666 | break; | ||
667 | case WM8960_DCLKDIV: | ||
668 | reg = wm8960_read(codec, WM8960_CLOCK2) & 0x03f; | ||
669 | wm8960_write(codec, WM8960_CLOCK2, reg | div); | ||
670 | break; | ||
671 | case WM8960_TOCLKSEL: | ||
672 | reg = wm8960_read(codec, WM8960_ADDCTL1) & 0x1fd; | ||
673 | wm8960_write(codec, WM8960_ADDCTL1, reg | div); | ||
674 | break; | ||
675 | default: | ||
676 | return -EINVAL; | ||
677 | } | ||
678 | |||
679 | return 0; | ||
680 | } | ||
681 | |||
682 | #define WM8960_RATES SNDRV_PCM_RATE_8000_48000 | ||
683 | |||
684 | #define WM8960_FORMATS \ | ||
685 | (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ | ||
686 | SNDRV_PCM_FMTBIT_S24_LE) | ||
687 | |||
688 | static struct snd_soc_dai_ops wm8960_dai_ops = { | ||
689 | .hw_params = wm8960_hw_params, | ||
690 | .digital_mute = wm8960_mute, | ||
691 | .set_fmt = wm8960_set_dai_fmt, | ||
692 | .set_clkdiv = wm8960_set_dai_clkdiv, | ||
693 | .set_pll = wm8960_set_dai_pll, | ||
694 | }; | ||
695 | |||
696 | struct snd_soc_dai wm8960_dai = { | ||
697 | .name = "WM8960", | ||
698 | .playback = { | ||
699 | .stream_name = "Playback", | ||
700 | .channels_min = 1, | ||
701 | .channels_max = 2, | ||
702 | .rates = WM8960_RATES, | ||
703 | .formats = WM8960_FORMATS,}, | ||
704 | .capture = { | ||
705 | .stream_name = "Capture", | ||
706 | .channels_min = 1, | ||
707 | .channels_max = 2, | ||
708 | .rates = WM8960_RATES, | ||
709 | .formats = WM8960_FORMATS,}, | ||
710 | .ops = &wm8960_dai_ops, | ||
711 | .symmetric_rates = 1, | ||
712 | }; | ||
713 | EXPORT_SYMBOL_GPL(wm8960_dai); | ||
714 | |||
715 | static int wm8960_suspend(struct platform_device *pdev, pm_message_t state) | ||
716 | { | ||
717 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
718 | struct snd_soc_codec *codec = socdev->card->codec; | ||
719 | |||
720 | wm8960_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
721 | return 0; | ||
722 | } | ||
723 | |||
724 | static int wm8960_resume(struct platform_device *pdev) | ||
725 | { | ||
726 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
727 | struct snd_soc_codec *codec = socdev->card->codec; | ||
728 | int i; | ||
729 | u8 data[2]; | ||
730 | u16 *cache = codec->reg_cache; | ||
731 | |||
732 | /* Sync reg_cache with the hardware */ | ||
733 | for (i = 0; i < ARRAY_SIZE(wm8960_reg); i++) { | ||
734 | data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001); | ||
735 | data[1] = cache[i] & 0x00ff; | ||
736 | codec->hw_write(codec->control_data, data, 2); | ||
737 | } | ||
738 | |||
739 | wm8960_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
740 | wm8960_set_bias_level(codec, codec->suspend_bias_level); | ||
741 | return 0; | ||
742 | } | ||
743 | |||
744 | static struct snd_soc_codec *wm8960_codec; | ||
745 | |||
746 | static int wm8960_probe(struct platform_device *pdev) | ||
747 | { | ||
748 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
749 | struct snd_soc_codec *codec; | ||
750 | int ret = 0; | ||
751 | |||
752 | if (wm8960_codec == NULL) { | ||
753 | dev_err(&pdev->dev, "Codec device not registered\n"); | ||
754 | return -ENODEV; | ||
755 | } | ||
756 | |||
757 | socdev->card->codec = wm8960_codec; | ||
758 | codec = wm8960_codec; | ||
759 | |||
760 | /* register pcms */ | ||
761 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
762 | if (ret < 0) { | ||
763 | dev_err(codec->dev, "failed to create pcms: %d\n", ret); | ||
764 | goto pcm_err; | ||
765 | } | ||
766 | |||
767 | snd_soc_add_controls(codec, wm8960_snd_controls, | ||
768 | ARRAY_SIZE(wm8960_snd_controls)); | ||
769 | wm8960_add_widgets(codec); | ||
770 | ret = snd_soc_init_card(socdev); | ||
771 | if (ret < 0) { | ||
772 | dev_err(codec->dev, "failed to register card: %d\n", ret); | ||
773 | goto card_err; | ||
774 | } | ||
775 | |||
776 | return ret; | ||
777 | |||
778 | card_err: | ||
779 | snd_soc_free_pcms(socdev); | ||
780 | snd_soc_dapm_free(socdev); | ||
781 | pcm_err: | ||
782 | return ret; | ||
783 | } | ||
784 | |||
785 | /* power down chip */ | ||
786 | static int wm8960_remove(struct platform_device *pdev) | ||
787 | { | ||
788 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
789 | |||
790 | snd_soc_free_pcms(socdev); | ||
791 | snd_soc_dapm_free(socdev); | ||
792 | |||
793 | return 0; | ||
794 | } | ||
795 | |||
796 | struct snd_soc_codec_device soc_codec_dev_wm8960 = { | ||
797 | .probe = wm8960_probe, | ||
798 | .remove = wm8960_remove, | ||
799 | .suspend = wm8960_suspend, | ||
800 | .resume = wm8960_resume, | ||
801 | }; | ||
802 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8960); | ||
803 | |||
804 | static int wm8960_register(struct wm8960_priv *wm8960) | ||
805 | { | ||
806 | struct wm8960_data *pdata = wm8960->codec.dev->platform_data; | ||
807 | struct snd_soc_codec *codec = &wm8960->codec; | ||
808 | int ret; | ||
809 | u16 reg; | ||
810 | |||
811 | if (wm8960_codec) { | ||
812 | dev_err(codec->dev, "Another WM8960 is registered\n"); | ||
813 | return -EINVAL; | ||
814 | } | ||
815 | |||
816 | if (!pdata) { | ||
817 | dev_warn(codec->dev, "No platform data supplied\n"); | ||
818 | } else { | ||
819 | if (pdata->dres > WM8960_DRES_MAX) { | ||
820 | dev_err(codec->dev, "Invalid DRES: %d\n", pdata->dres); | ||
821 | pdata->dres = 0; | ||
822 | } | ||
823 | } | ||
824 | |||
825 | mutex_init(&codec->mutex); | ||
826 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
827 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
828 | |||
829 | codec->private_data = wm8960; | ||
830 | codec->name = "WM8960"; | ||
831 | codec->owner = THIS_MODULE; | ||
832 | codec->read = wm8960_read_reg_cache; | ||
833 | codec->write = wm8960_write; | ||
834 | codec->bias_level = SND_SOC_BIAS_OFF; | ||
835 | codec->set_bias_level = wm8960_set_bias_level; | ||
836 | codec->dai = &wm8960_dai; | ||
837 | codec->num_dai = 1; | ||
838 | codec->reg_cache_size = WM8960_CACHEREGNUM; | ||
839 | codec->reg_cache = &wm8960->reg_cache; | ||
840 | |||
841 | memcpy(codec->reg_cache, wm8960_reg, sizeof(wm8960_reg)); | ||
842 | |||
843 | ret = wm8960_reset(codec); | ||
844 | if (ret < 0) { | ||
845 | dev_err(codec->dev, "Failed to issue reset\n"); | ||
846 | return ret; | ||
847 | } | ||
848 | |||
849 | wm8960_dai.dev = codec->dev; | ||
850 | |||
851 | wm8960_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
852 | |||
853 | /* Latch the update bits */ | ||
854 | reg = wm8960_read(codec, WM8960_LINVOL); | ||
855 | wm8960_write(codec, WM8960_LINVOL, reg | 0x100); | ||
856 | reg = wm8960_read(codec, WM8960_RINVOL); | ||
857 | wm8960_write(codec, WM8960_RINVOL, reg | 0x100); | ||
858 | reg = wm8960_read(codec, WM8960_LADC); | ||
859 | wm8960_write(codec, WM8960_LADC, reg | 0x100); | ||
860 | reg = wm8960_read(codec, WM8960_RADC); | ||
861 | wm8960_write(codec, WM8960_RADC, reg | 0x100); | ||
862 | reg = wm8960_read(codec, WM8960_LDAC); | ||
863 | wm8960_write(codec, WM8960_LDAC, reg | 0x100); | ||
864 | reg = wm8960_read(codec, WM8960_RDAC); | ||
865 | wm8960_write(codec, WM8960_RDAC, reg | 0x100); | ||
866 | reg = wm8960_read(codec, WM8960_LOUT1); | ||
867 | wm8960_write(codec, WM8960_LOUT1, reg | 0x100); | ||
868 | reg = wm8960_read(codec, WM8960_ROUT1); | ||
869 | wm8960_write(codec, WM8960_ROUT1, reg | 0x100); | ||
870 | reg = wm8960_read(codec, WM8960_LOUT2); | ||
871 | wm8960_write(codec, WM8960_LOUT2, reg | 0x100); | ||
872 | reg = wm8960_read(codec, WM8960_ROUT2); | ||
873 | wm8960_write(codec, WM8960_ROUT2, reg | 0x100); | ||
874 | |||
875 | wm8960_codec = codec; | ||
876 | |||
877 | ret = snd_soc_register_codec(codec); | ||
878 | if (ret != 0) { | ||
879 | dev_err(codec->dev, "Failed to register codec: %d\n", ret); | ||
880 | return ret; | ||
881 | } | ||
882 | |||
883 | ret = snd_soc_register_dai(&wm8960_dai); | ||
884 | if (ret != 0) { | ||
885 | dev_err(codec->dev, "Failed to register DAI: %d\n", ret); | ||
886 | snd_soc_unregister_codec(codec); | ||
887 | return ret; | ||
888 | } | ||
889 | |||
890 | return 0; | ||
891 | } | ||
892 | |||
893 | static void wm8960_unregister(struct wm8960_priv *wm8960) | ||
894 | { | ||
895 | wm8960_set_bias_level(&wm8960->codec, SND_SOC_BIAS_OFF); | ||
896 | snd_soc_unregister_dai(&wm8960_dai); | ||
897 | snd_soc_unregister_codec(&wm8960->codec); | ||
898 | kfree(wm8960); | ||
899 | wm8960_codec = NULL; | ||
900 | } | ||
901 | |||
902 | static __devinit int wm8960_i2c_probe(struct i2c_client *i2c, | ||
903 | const struct i2c_device_id *id) | ||
904 | { | ||
905 | struct wm8960_priv *wm8960; | ||
906 | struct snd_soc_codec *codec; | ||
907 | |||
908 | wm8960 = kzalloc(sizeof(struct wm8960_priv), GFP_KERNEL); | ||
909 | if (wm8960 == NULL) | ||
910 | return -ENOMEM; | ||
911 | |||
912 | codec = &wm8960->codec; | ||
913 | codec->hw_write = (hw_write_t)i2c_master_send; | ||
914 | |||
915 | i2c_set_clientdata(i2c, wm8960); | ||
916 | codec->control_data = i2c; | ||
917 | |||
918 | codec->dev = &i2c->dev; | ||
919 | |||
920 | return wm8960_register(wm8960); | ||
921 | } | ||
922 | |||
923 | static __devexit int wm8960_i2c_remove(struct i2c_client *client) | ||
924 | { | ||
925 | struct wm8960_priv *wm8960 = i2c_get_clientdata(client); | ||
926 | wm8960_unregister(wm8960); | ||
927 | return 0; | ||
928 | } | ||
929 | |||
930 | static const struct i2c_device_id wm8960_i2c_id[] = { | ||
931 | { "wm8960", 0 }, | ||
932 | { } | ||
933 | }; | ||
934 | MODULE_DEVICE_TABLE(i2c, wm8960_i2c_id); | ||
935 | |||
936 | static struct i2c_driver wm8960_i2c_driver = { | ||
937 | .driver = { | ||
938 | .name = "WM8960 I2C Codec", | ||
939 | .owner = THIS_MODULE, | ||
940 | }, | ||
941 | .probe = wm8960_i2c_probe, | ||
942 | .remove = __devexit_p(wm8960_i2c_remove), | ||
943 | .id_table = wm8960_i2c_id, | ||
944 | }; | ||
945 | |||
946 | static int __init wm8960_modinit(void) | ||
947 | { | ||
948 | int ret; | ||
949 | |||
950 | ret = i2c_add_driver(&wm8960_i2c_driver); | ||
951 | if (ret != 0) { | ||
952 | printk(KERN_ERR "Failed to register WM8960 I2C driver: %d\n", | ||
953 | ret); | ||
954 | } | ||
955 | |||
956 | return ret; | ||
957 | } | ||
958 | module_init(wm8960_modinit); | ||
959 | |||
960 | static void __exit wm8960_exit(void) | ||
961 | { | ||
962 | i2c_del_driver(&wm8960_i2c_driver); | ||
963 | } | ||
964 | module_exit(wm8960_exit); | ||
965 | |||
966 | |||
967 | MODULE_DESCRIPTION("ASoC WM8960 driver"); | ||
968 | MODULE_AUTHOR("Liam Girdwood"); | ||
969 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/wm8960.h b/sound/soc/codecs/wm8960.h new file mode 100644 index 000000000000..c9af56c9d9d4 --- /dev/null +++ b/sound/soc/codecs/wm8960.h | |||
@@ -0,0 +1,127 @@ | |||
1 | /* | ||
2 | * wm8960.h -- WM8960 Soc Audio driver | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | |||
9 | #ifndef _WM8960_H | ||
10 | #define _WM8960_H | ||
11 | |||
12 | /* WM8960 register space */ | ||
13 | |||
14 | |||
15 | #define WM8960_CACHEREGNUM 56 | ||
16 | |||
17 | #define WM8960_LINVOL 0x0 | ||
18 | #define WM8960_RINVOL 0x1 | ||
19 | #define WM8960_LOUT1 0x2 | ||
20 | #define WM8960_ROUT1 0x3 | ||
21 | #define WM8960_CLOCK1 0x4 | ||
22 | #define WM8960_DACCTL1 0x5 | ||
23 | #define WM8960_DACCTL2 0x6 | ||
24 | #define WM8960_IFACE1 0x7 | ||
25 | #define WM8960_CLOCK2 0x8 | ||
26 | #define WM8960_IFACE2 0x9 | ||
27 | #define WM8960_LDAC 0xa | ||
28 | #define WM8960_RDAC 0xb | ||
29 | |||
30 | #define WM8960_RESET 0xf | ||
31 | #define WM8960_3D 0x10 | ||
32 | #define WM8960_ALC1 0x11 | ||
33 | #define WM8960_ALC2 0x12 | ||
34 | #define WM8960_ALC3 0x13 | ||
35 | #define WM8960_NOISEG 0x14 | ||
36 | #define WM8960_LADC 0x15 | ||
37 | #define WM8960_RADC 0x16 | ||
38 | #define WM8960_ADDCTL1 0x17 | ||
39 | #define WM8960_ADDCTL2 0x18 | ||
40 | #define WM8960_POWER1 0x19 | ||
41 | #define WM8960_POWER2 0x1a | ||
42 | #define WM8960_ADDCTL3 0x1b | ||
43 | #define WM8960_APOP1 0x1c | ||
44 | #define WM8960_APOP2 0x1d | ||
45 | |||
46 | #define WM8960_LINPATH 0x20 | ||
47 | #define WM8960_RINPATH 0x21 | ||
48 | #define WM8960_LOUTMIX 0x22 | ||
49 | |||
50 | #define WM8960_ROUTMIX 0x25 | ||
51 | #define WM8960_MONOMIX1 0x26 | ||
52 | #define WM8960_MONOMIX2 0x27 | ||
53 | #define WM8960_LOUT2 0x28 | ||
54 | #define WM8960_ROUT2 0x29 | ||
55 | #define WM8960_MONO 0x2a | ||
56 | #define WM8960_INBMIX1 0x2b | ||
57 | #define WM8960_INBMIX2 0x2c | ||
58 | #define WM8960_BYPASS1 0x2d | ||
59 | #define WM8960_BYPASS2 0x2e | ||
60 | #define WM8960_POWER3 0x2f | ||
61 | #define WM8960_ADDCTL4 0x30 | ||
62 | #define WM8960_CLASSD1 0x31 | ||
63 | |||
64 | #define WM8960_CLASSD3 0x33 | ||
65 | #define WM8960_PLL1 0x34 | ||
66 | #define WM8960_PLL2 0x35 | ||
67 | #define WM8960_PLL3 0x36 | ||
68 | #define WM8960_PLL4 0x37 | ||
69 | |||
70 | |||
71 | /* | ||
72 | * WM8960 Clock dividers | ||
73 | */ | ||
74 | #define WM8960_SYSCLKDIV 0 | ||
75 | #define WM8960_DACDIV 1 | ||
76 | #define WM8960_OPCLKDIV 2 | ||
77 | #define WM8960_DCLKDIV 3 | ||
78 | #define WM8960_TOCLKSEL 4 | ||
79 | #define WM8960_SYSCLKSEL 5 | ||
80 | |||
81 | #define WM8960_SYSCLK_DIV_1 (0 << 1) | ||
82 | #define WM8960_SYSCLK_DIV_2 (2 << 1) | ||
83 | |||
84 | #define WM8960_SYSCLK_MCLK (0 << 0) | ||
85 | #define WM8960_SYSCLK_PLL (1 << 0) | ||
86 | |||
87 | #define WM8960_DAC_DIV_1 (0 << 3) | ||
88 | #define WM8960_DAC_DIV_1_5 (1 << 3) | ||
89 | #define WM8960_DAC_DIV_2 (2 << 3) | ||
90 | #define WM8960_DAC_DIV_3 (3 << 3) | ||
91 | #define WM8960_DAC_DIV_4 (4 << 3) | ||
92 | #define WM8960_DAC_DIV_5_5 (5 << 3) | ||
93 | #define WM8960_DAC_DIV_6 (6 << 3) | ||
94 | |||
95 | #define WM8960_DCLK_DIV_1_5 (0 << 6) | ||
96 | #define WM8960_DCLK_DIV_2 (1 << 6) | ||
97 | #define WM8960_DCLK_DIV_3 (2 << 6) | ||
98 | #define WM8960_DCLK_DIV_4 (3 << 6) | ||
99 | #define WM8960_DCLK_DIV_6 (4 << 6) | ||
100 | #define WM8960_DCLK_DIV_8 (5 << 6) | ||
101 | #define WM8960_DCLK_DIV_12 (6 << 6) | ||
102 | #define WM8960_DCLK_DIV_16 (7 << 6) | ||
103 | |||
104 | #define WM8960_TOCLK_F19 (0 << 1) | ||
105 | #define WM8960_TOCLK_F21 (1 << 1) | ||
106 | |||
107 | #define WM8960_OPCLK_DIV_1 (0 << 0) | ||
108 | #define WM8960_OPCLK_DIV_2 (1 << 0) | ||
109 | #define WM8960_OPCLK_DIV_3 (2 << 0) | ||
110 | #define WM8960_OPCLK_DIV_4 (3 << 0) | ||
111 | #define WM8960_OPCLK_DIV_5_5 (4 << 0) | ||
112 | #define WM8960_OPCLK_DIV_6 (5 << 0) | ||
113 | |||
114 | extern struct snd_soc_dai wm8960_dai; | ||
115 | extern struct snd_soc_codec_device soc_codec_dev_wm8960; | ||
116 | |||
117 | #define WM8960_DRES_400R 0 | ||
118 | #define WM8960_DRES_200R 1 | ||
119 | #define WM8960_DRES_600R 2 | ||
120 | #define WM8960_DRES_150R 3 | ||
121 | #define WM8960_DRES_MAX 3 | ||
122 | |||
123 | struct wm8960_data { | ||
124 | int dres; | ||
125 | }; | ||
126 | |||
127 | #endif | ||
diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c new file mode 100644 index 000000000000..c05f71803aa8 --- /dev/null +++ b/sound/soc/codecs/wm8988.c | |||
@@ -0,0 +1,1097 @@ | |||
1 | /* | ||
2 | * wm8988.c -- WM8988 ALSA SoC audio driver | ||
3 | * | ||
4 | * Copyright 2009 Wolfson Microelectronics plc | ||
5 | * Copyright 2005 Openedhand Ltd. | ||
6 | * | ||
7 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/moduleparam.h> | ||
16 | #include <linux/init.h> | ||
17 | #include <linux/delay.h> | ||
18 | #include <linux/pm.h> | ||
19 | #include <linux/i2c.h> | ||
20 | #include <linux/spi/spi.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <sound/core.h> | ||
23 | #include <sound/pcm.h> | ||
24 | #include <sound/pcm_params.h> | ||
25 | #include <sound/tlv.h> | ||
26 | #include <sound/soc.h> | ||
27 | #include <sound/soc-dapm.h> | ||
28 | #include <sound/initval.h> | ||
29 | |||
30 | #include "wm8988.h" | ||
31 | |||
32 | /* | ||
33 | * wm8988 register cache | ||
34 | * We can't read the WM8988 register space when we | ||
35 | * are using 2 wire for device control, so we cache them instead. | ||
36 | */ | ||
37 | static const u16 wm8988_reg[] = { | ||
38 | 0x0097, 0x0097, 0x0079, 0x0079, /* 0 */ | ||
39 | 0x0000, 0x0008, 0x0000, 0x000a, /* 4 */ | ||
40 | 0x0000, 0x0000, 0x00ff, 0x00ff, /* 8 */ | ||
41 | 0x000f, 0x000f, 0x0000, 0x0000, /* 12 */ | ||
42 | 0x0000, 0x007b, 0x0000, 0x0032, /* 16 */ | ||
43 | 0x0000, 0x00c3, 0x00c3, 0x00c0, /* 20 */ | ||
44 | 0x0000, 0x0000, 0x0000, 0x0000, /* 24 */ | ||
45 | 0x0000, 0x0000, 0x0000, 0x0000, /* 28 */ | ||
46 | 0x0000, 0x0000, 0x0050, 0x0050, /* 32 */ | ||
47 | 0x0050, 0x0050, 0x0050, 0x0050, /* 36 */ | ||
48 | 0x0079, 0x0079, 0x0079, /* 40 */ | ||
49 | }; | ||
50 | |||
51 | /* codec private data */ | ||
52 | struct wm8988_priv { | ||
53 | unsigned int sysclk; | ||
54 | struct snd_soc_codec codec; | ||
55 | struct snd_pcm_hw_constraint_list *sysclk_constraints; | ||
56 | u16 reg_cache[WM8988_NUM_REG]; | ||
57 | }; | ||
58 | |||
59 | |||
60 | /* | ||
61 | * read wm8988 register cache | ||
62 | */ | ||
63 | static inline unsigned int wm8988_read_reg_cache(struct snd_soc_codec *codec, | ||
64 | unsigned int reg) | ||
65 | { | ||
66 | u16 *cache = codec->reg_cache; | ||
67 | if (reg > WM8988_NUM_REG) | ||
68 | return -1; | ||
69 | return cache[reg]; | ||
70 | } | ||
71 | |||
72 | /* | ||
73 | * write wm8988 register cache | ||
74 | */ | ||
75 | static inline void wm8988_write_reg_cache(struct snd_soc_codec *codec, | ||
76 | unsigned int reg, unsigned int value) | ||
77 | { | ||
78 | u16 *cache = codec->reg_cache; | ||
79 | if (reg > WM8988_NUM_REG) | ||
80 | return; | ||
81 | cache[reg] = value; | ||
82 | } | ||
83 | |||
84 | static int wm8988_write(struct snd_soc_codec *codec, unsigned int reg, | ||
85 | unsigned int value) | ||
86 | { | ||
87 | u8 data[2]; | ||
88 | |||
89 | /* data is | ||
90 | * D15..D9 WM8753 register offset | ||
91 | * D8...D0 register data | ||
92 | */ | ||
93 | data[0] = (reg << 1) | ((value >> 8) & 0x0001); | ||
94 | data[1] = value & 0x00ff; | ||
95 | |||
96 | wm8988_write_reg_cache(codec, reg, value); | ||
97 | if (codec->hw_write(codec->control_data, data, 2) == 2) | ||
98 | return 0; | ||
99 | else | ||
100 | return -EIO; | ||
101 | } | ||
102 | |||
103 | #define wm8988_reset(c) wm8988_write(c, WM8988_RESET, 0) | ||
104 | |||
105 | /* | ||
106 | * WM8988 Controls | ||
107 | */ | ||
108 | |||
109 | static const char *bass_boost_txt[] = {"Linear Control", "Adaptive Boost"}; | ||
110 | static const struct soc_enum bass_boost = | ||
111 | SOC_ENUM_SINGLE(WM8988_BASS, 7, 2, bass_boost_txt); | ||
112 | |||
113 | static const char *bass_filter_txt[] = { "130Hz @ 48kHz", "200Hz @ 48kHz" }; | ||
114 | static const struct soc_enum bass_filter = | ||
115 | SOC_ENUM_SINGLE(WM8988_BASS, 6, 2, bass_filter_txt); | ||
116 | |||
117 | static const char *treble_txt[] = {"8kHz", "4kHz"}; | ||
118 | static const struct soc_enum treble = | ||
119 | SOC_ENUM_SINGLE(WM8988_TREBLE, 6, 2, treble_txt); | ||
120 | |||
121 | static const char *stereo_3d_lc_txt[] = {"200Hz", "500Hz"}; | ||
122 | static const struct soc_enum stereo_3d_lc = | ||
123 | SOC_ENUM_SINGLE(WM8988_3D, 5, 2, stereo_3d_lc_txt); | ||
124 | |||
125 | static const char *stereo_3d_uc_txt[] = {"2.2kHz", "1.5kHz"}; | ||
126 | static const struct soc_enum stereo_3d_uc = | ||
127 | SOC_ENUM_SINGLE(WM8988_3D, 6, 2, stereo_3d_uc_txt); | ||
128 | |||
129 | static const char *stereo_3d_func_txt[] = {"Capture", "Playback"}; | ||
130 | static const struct soc_enum stereo_3d_func = | ||
131 | SOC_ENUM_SINGLE(WM8988_3D, 7, 2, stereo_3d_func_txt); | ||
132 | |||
133 | static const char *alc_func_txt[] = {"Off", "Right", "Left", "Stereo"}; | ||
134 | static const struct soc_enum alc_func = | ||
135 | SOC_ENUM_SINGLE(WM8988_ALC1, 7, 4, alc_func_txt); | ||
136 | |||
137 | static const char *ng_type_txt[] = {"Constant PGA Gain", | ||
138 | "Mute ADC Output"}; | ||
139 | static const struct soc_enum ng_type = | ||
140 | SOC_ENUM_SINGLE(WM8988_NGATE, 1, 2, ng_type_txt); | ||
141 | |||
142 | static const char *deemph_txt[] = {"None", "32Khz", "44.1Khz", "48Khz"}; | ||
143 | static const struct soc_enum deemph = | ||
144 | SOC_ENUM_SINGLE(WM8988_ADCDAC, 1, 4, deemph_txt); | ||
145 | |||
146 | static const char *adcpol_txt[] = {"Normal", "L Invert", "R Invert", | ||
147 | "L + R Invert"}; | ||
148 | static const struct soc_enum adcpol = | ||
149 | SOC_ENUM_SINGLE(WM8988_ADCDAC, 5, 4, adcpol_txt); | ||
150 | |||
151 | static const DECLARE_TLV_DB_SCALE(pga_tlv, -1725, 75, 0); | ||
152 | static const DECLARE_TLV_DB_SCALE(adc_tlv, -9750, 50, 1); | ||
153 | static const DECLARE_TLV_DB_SCALE(dac_tlv, -12750, 50, 1); | ||
154 | static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1); | ||
155 | static const DECLARE_TLV_DB_SCALE(bypass_tlv, -1500, 300, 0); | ||
156 | |||
157 | static const struct snd_kcontrol_new wm8988_snd_controls[] = { | ||
158 | |||
159 | SOC_ENUM("Bass Boost", bass_boost), | ||
160 | SOC_ENUM("Bass Filter", bass_filter), | ||
161 | SOC_SINGLE("Bass Volume", WM8988_BASS, 0, 15, 1), | ||
162 | |||
163 | SOC_SINGLE("Treble Volume", WM8988_TREBLE, 0, 15, 0), | ||
164 | SOC_ENUM("Treble Cut-off", treble), | ||
165 | |||
166 | SOC_SINGLE("3D Switch", WM8988_3D, 0, 1, 0), | ||
167 | SOC_SINGLE("3D Volume", WM8988_3D, 1, 15, 0), | ||
168 | SOC_ENUM("3D Lower Cut-off", stereo_3d_lc), | ||
169 | SOC_ENUM("3D Upper Cut-off", stereo_3d_uc), | ||
170 | SOC_ENUM("3D Mode", stereo_3d_func), | ||
171 | |||
172 | SOC_SINGLE("ALC Capture Target Volume", WM8988_ALC1, 0, 7, 0), | ||
173 | SOC_SINGLE("ALC Capture Max Volume", WM8988_ALC1, 4, 7, 0), | ||
174 | SOC_ENUM("ALC Capture Function", alc_func), | ||
175 | SOC_SINGLE("ALC Capture ZC Switch", WM8988_ALC2, 7, 1, 0), | ||
176 | SOC_SINGLE("ALC Capture Hold Time", WM8988_ALC2, 0, 15, 0), | ||
177 | SOC_SINGLE("ALC Capture Decay Time", WM8988_ALC3, 4, 15, 0), | ||
178 | SOC_SINGLE("ALC Capture Attack Time", WM8988_ALC3, 0, 15, 0), | ||
179 | SOC_SINGLE("ALC Capture NG Threshold", WM8988_NGATE, 3, 31, 0), | ||
180 | SOC_ENUM("ALC Capture NG Type", ng_type), | ||
181 | SOC_SINGLE("ALC Capture NG Switch", WM8988_NGATE, 0, 1, 0), | ||
182 | |||
183 | SOC_SINGLE("ZC Timeout Switch", WM8988_ADCTL1, 0, 1, 0), | ||
184 | |||
185 | SOC_DOUBLE_R_TLV("Capture Digital Volume", WM8988_LADC, WM8988_RADC, | ||
186 | 0, 255, 0, adc_tlv), | ||
187 | SOC_DOUBLE_R_TLV("Capture Volume", WM8988_LINVOL, WM8988_RINVOL, | ||
188 | 0, 63, 0, pga_tlv), | ||
189 | SOC_DOUBLE_R("Capture ZC Switch", WM8988_LINVOL, WM8988_RINVOL, 6, 1, 0), | ||
190 | SOC_DOUBLE_R("Capture Switch", WM8988_LINVOL, WM8988_RINVOL, 7, 1, 1), | ||
191 | |||
192 | SOC_ENUM("Playback De-emphasis", deemph), | ||
193 | |||
194 | SOC_ENUM("Capture Polarity", adcpol), | ||
195 | SOC_SINGLE("Playback 6dB Attenuate", WM8988_ADCDAC, 7, 1, 0), | ||
196 | SOC_SINGLE("Capture 6dB Attenuate", WM8988_ADCDAC, 8, 1, 0), | ||
197 | |||
198 | SOC_DOUBLE_R_TLV("PCM Volume", WM8988_LDAC, WM8988_RDAC, 0, 255, 0, dac_tlv), | ||
199 | |||
200 | SOC_SINGLE_TLV("Left Mixer Left Bypass Volume", WM8988_LOUTM1, 4, 7, 1, | ||
201 | bypass_tlv), | ||
202 | SOC_SINGLE_TLV("Left Mixer Right Bypass Volume", WM8988_LOUTM2, 4, 7, 1, | ||
203 | bypass_tlv), | ||
204 | SOC_SINGLE_TLV("Right Mixer Left Bypass Volume", WM8988_ROUTM1, 4, 7, 1, | ||
205 | bypass_tlv), | ||
206 | SOC_SINGLE_TLV("Right Mixer Right Bypass Volume", WM8988_ROUTM2, 4, 7, 1, | ||
207 | bypass_tlv), | ||
208 | |||
209 | SOC_DOUBLE_R("Output 1 Playback ZC Switch", WM8988_LOUT1V, | ||
210 | WM8988_ROUT1V, 7, 1, 0), | ||
211 | SOC_DOUBLE_R_TLV("Output 1 Playback Volume", WM8988_LOUT1V, WM8988_ROUT1V, | ||
212 | 0, 127, 0, out_tlv), | ||
213 | |||
214 | SOC_DOUBLE_R("Output 2 Playback ZC Switch", WM8988_LOUT2V, | ||
215 | WM8988_ROUT2V, 7, 1, 0), | ||
216 | SOC_DOUBLE_R_TLV("Output 2 Playback Volume", WM8988_LOUT2V, WM8988_ROUT2V, | ||
217 | 0, 127, 0, out_tlv), | ||
218 | |||
219 | }; | ||
220 | |||
221 | /* | ||
222 | * DAPM Controls | ||
223 | */ | ||
224 | |||
225 | static int wm8988_lrc_control(struct snd_soc_dapm_widget *w, | ||
226 | struct snd_kcontrol *kcontrol, int event) | ||
227 | { | ||
228 | struct snd_soc_codec *codec = w->codec; | ||
229 | u16 adctl2 = wm8988_read_reg_cache(codec, WM8988_ADCTL2); | ||
230 | |||
231 | /* Use the DAC to gate LRC if active, otherwise use ADC */ | ||
232 | if (wm8988_read_reg_cache(codec, WM8988_PWR2) & 0x180) | ||
233 | adctl2 &= ~0x4; | ||
234 | else | ||
235 | adctl2 |= 0x4; | ||
236 | |||
237 | return wm8988_write(codec, WM8988_ADCTL2, adctl2); | ||
238 | } | ||
239 | |||
240 | static const char *wm8988_line_texts[] = { | ||
241 | "Line 1", "Line 2", "PGA", "Differential"}; | ||
242 | |||
243 | static const unsigned int wm8988_line_values[] = { | ||
244 | 0, 1, 3, 4}; | ||
245 | |||
246 | static const struct soc_enum wm8988_lline_enum = | ||
247 | SOC_VALUE_ENUM_SINGLE(WM8988_LOUTM1, 0, 7, | ||
248 | ARRAY_SIZE(wm8988_line_texts), | ||
249 | wm8988_line_texts, | ||
250 | wm8988_line_values); | ||
251 | static const struct snd_kcontrol_new wm8988_left_line_controls = | ||
252 | SOC_DAPM_VALUE_ENUM("Route", wm8988_lline_enum); | ||
253 | |||
254 | static const struct soc_enum wm8988_rline_enum = | ||
255 | SOC_VALUE_ENUM_SINGLE(WM8988_ROUTM1, 0, 7, | ||
256 | ARRAY_SIZE(wm8988_line_texts), | ||
257 | wm8988_line_texts, | ||
258 | wm8988_line_values); | ||
259 | static const struct snd_kcontrol_new wm8988_right_line_controls = | ||
260 | SOC_DAPM_VALUE_ENUM("Route", wm8988_lline_enum); | ||
261 | |||
262 | /* Left Mixer */ | ||
263 | static const struct snd_kcontrol_new wm8988_left_mixer_controls[] = { | ||
264 | SOC_DAPM_SINGLE("Playback Switch", WM8988_LOUTM1, 8, 1, 0), | ||
265 | SOC_DAPM_SINGLE("Left Bypass Switch", WM8988_LOUTM1, 7, 1, 0), | ||
266 | SOC_DAPM_SINGLE("Right Playback Switch", WM8988_LOUTM2, 8, 1, 0), | ||
267 | SOC_DAPM_SINGLE("Right Bypass Switch", WM8988_LOUTM2, 7, 1, 0), | ||
268 | }; | ||
269 | |||
270 | /* Right Mixer */ | ||
271 | static const struct snd_kcontrol_new wm8988_right_mixer_controls[] = { | ||
272 | SOC_DAPM_SINGLE("Left Playback Switch", WM8988_ROUTM1, 8, 1, 0), | ||
273 | SOC_DAPM_SINGLE("Left Bypass Switch", WM8988_ROUTM1, 7, 1, 0), | ||
274 | SOC_DAPM_SINGLE("Playback Switch", WM8988_ROUTM2, 8, 1, 0), | ||
275 | SOC_DAPM_SINGLE("Right Bypass Switch", WM8988_ROUTM2, 7, 1, 0), | ||
276 | }; | ||
277 | |||
278 | static const char *wm8988_pga_sel[] = {"Line 1", "Line 2", "Differential"}; | ||
279 | static const unsigned int wm8988_pga_val[] = { 0, 1, 3 }; | ||
280 | |||
281 | /* Left PGA Mux */ | ||
282 | static const struct soc_enum wm8988_lpga_enum = | ||
283 | SOC_VALUE_ENUM_SINGLE(WM8988_LADCIN, 6, 3, | ||
284 | ARRAY_SIZE(wm8988_pga_sel), | ||
285 | wm8988_pga_sel, | ||
286 | wm8988_pga_val); | ||
287 | static const struct snd_kcontrol_new wm8988_left_pga_controls = | ||
288 | SOC_DAPM_VALUE_ENUM("Route", wm8988_lpga_enum); | ||
289 | |||
290 | /* Right PGA Mux */ | ||
291 | static const struct soc_enum wm8988_rpga_enum = | ||
292 | SOC_VALUE_ENUM_SINGLE(WM8988_RADCIN, 6, 3, | ||
293 | ARRAY_SIZE(wm8988_pga_sel), | ||
294 | wm8988_pga_sel, | ||
295 | wm8988_pga_val); | ||
296 | static const struct snd_kcontrol_new wm8988_right_pga_controls = | ||
297 | SOC_DAPM_VALUE_ENUM("Route", wm8988_rpga_enum); | ||
298 | |||
299 | /* Differential Mux */ | ||
300 | static const char *wm8988_diff_sel[] = {"Line 1", "Line 2"}; | ||
301 | static const struct soc_enum diffmux = | ||
302 | SOC_ENUM_SINGLE(WM8988_ADCIN, 8, 2, wm8988_diff_sel); | ||
303 | static const struct snd_kcontrol_new wm8988_diffmux_controls = | ||
304 | SOC_DAPM_ENUM("Route", diffmux); | ||
305 | |||
306 | /* Mono ADC Mux */ | ||
307 | static const char *wm8988_mono_mux[] = {"Stereo", "Mono (Left)", | ||
308 | "Mono (Right)", "Digital Mono"}; | ||
309 | static const struct soc_enum monomux = | ||
310 | SOC_ENUM_SINGLE(WM8988_ADCIN, 6, 4, wm8988_mono_mux); | ||
311 | static const struct snd_kcontrol_new wm8988_monomux_controls = | ||
312 | SOC_DAPM_ENUM("Route", monomux); | ||
313 | |||
314 | static const struct snd_soc_dapm_widget wm8988_dapm_widgets[] = { | ||
315 | SND_SOC_DAPM_MICBIAS("Mic Bias", WM8988_PWR1, 1, 0), | ||
316 | |||
317 | SND_SOC_DAPM_MUX("Differential Mux", SND_SOC_NOPM, 0, 0, | ||
318 | &wm8988_diffmux_controls), | ||
319 | SND_SOC_DAPM_MUX("Left ADC Mux", SND_SOC_NOPM, 0, 0, | ||
320 | &wm8988_monomux_controls), | ||
321 | SND_SOC_DAPM_MUX("Right ADC Mux", SND_SOC_NOPM, 0, 0, | ||
322 | &wm8988_monomux_controls), | ||
323 | |||
324 | SND_SOC_DAPM_MUX("Left PGA Mux", WM8988_PWR1, 5, 0, | ||
325 | &wm8988_left_pga_controls), | ||
326 | SND_SOC_DAPM_MUX("Right PGA Mux", WM8988_PWR1, 4, 0, | ||
327 | &wm8988_right_pga_controls), | ||
328 | |||
329 | SND_SOC_DAPM_MUX("Left Line Mux", SND_SOC_NOPM, 0, 0, | ||
330 | &wm8988_left_line_controls), | ||
331 | SND_SOC_DAPM_MUX("Right Line Mux", SND_SOC_NOPM, 0, 0, | ||
332 | &wm8988_right_line_controls), | ||
333 | |||
334 | SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8988_PWR1, 2, 0), | ||
335 | SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8988_PWR1, 3, 0), | ||
336 | |||
337 | SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8988_PWR2, 7, 0), | ||
338 | SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8988_PWR2, 8, 0), | ||
339 | |||
340 | SND_SOC_DAPM_MIXER("Left Mixer", SND_SOC_NOPM, 0, 0, | ||
341 | &wm8988_left_mixer_controls[0], | ||
342 | ARRAY_SIZE(wm8988_left_mixer_controls)), | ||
343 | SND_SOC_DAPM_MIXER("Right Mixer", SND_SOC_NOPM, 0, 0, | ||
344 | &wm8988_right_mixer_controls[0], | ||
345 | ARRAY_SIZE(wm8988_right_mixer_controls)), | ||
346 | |||
347 | SND_SOC_DAPM_PGA("Right Out 2", WM8988_PWR2, 3, 0, NULL, 0), | ||
348 | SND_SOC_DAPM_PGA("Left Out 2", WM8988_PWR2, 4, 0, NULL, 0), | ||
349 | SND_SOC_DAPM_PGA("Right Out 1", WM8988_PWR2, 5, 0, NULL, 0), | ||
350 | SND_SOC_DAPM_PGA("Left Out 1", WM8988_PWR2, 6, 0, NULL, 0), | ||
351 | |||
352 | SND_SOC_DAPM_POST("LRC control", wm8988_lrc_control), | ||
353 | |||
354 | SND_SOC_DAPM_OUTPUT("LOUT1"), | ||
355 | SND_SOC_DAPM_OUTPUT("ROUT1"), | ||
356 | SND_SOC_DAPM_OUTPUT("LOUT2"), | ||
357 | SND_SOC_DAPM_OUTPUT("ROUT2"), | ||
358 | SND_SOC_DAPM_OUTPUT("VREF"), | ||
359 | |||
360 | SND_SOC_DAPM_INPUT("LINPUT1"), | ||
361 | SND_SOC_DAPM_INPUT("LINPUT2"), | ||
362 | SND_SOC_DAPM_INPUT("RINPUT1"), | ||
363 | SND_SOC_DAPM_INPUT("RINPUT2"), | ||
364 | }; | ||
365 | |||
366 | static const struct snd_soc_dapm_route audio_map[] = { | ||
367 | |||
368 | { "Left Line Mux", "Line 1", "LINPUT1" }, | ||
369 | { "Left Line Mux", "Line 2", "LINPUT2" }, | ||
370 | { "Left Line Mux", "PGA", "Left PGA Mux" }, | ||
371 | { "Left Line Mux", "Differential", "Differential Mux" }, | ||
372 | |||
373 | { "Right Line Mux", "Line 1", "RINPUT1" }, | ||
374 | { "Right Line Mux", "Line 2", "RINPUT2" }, | ||
375 | { "Right Line Mux", "PGA", "Right PGA Mux" }, | ||
376 | { "Right Line Mux", "Differential", "Differential Mux" }, | ||
377 | |||
378 | { "Left PGA Mux", "Line 1", "LINPUT1" }, | ||
379 | { "Left PGA Mux", "Line 2", "LINPUT2" }, | ||
380 | { "Left PGA Mux", "Differential", "Differential Mux" }, | ||
381 | |||
382 | { "Right PGA Mux", "Line 1", "RINPUT1" }, | ||
383 | { "Right PGA Mux", "Line 2", "RINPUT2" }, | ||
384 | { "Right PGA Mux", "Differential", "Differential Mux" }, | ||
385 | |||
386 | { "Differential Mux", "Line 1", "LINPUT1" }, | ||
387 | { "Differential Mux", "Line 1", "RINPUT1" }, | ||
388 | { "Differential Mux", "Line 2", "LINPUT2" }, | ||
389 | { "Differential Mux", "Line 2", "RINPUT2" }, | ||
390 | |||
391 | { "Left ADC Mux", "Stereo", "Left PGA Mux" }, | ||
392 | { "Left ADC Mux", "Mono (Left)", "Left PGA Mux" }, | ||
393 | { "Left ADC Mux", "Digital Mono", "Left PGA Mux" }, | ||
394 | |||
395 | { "Right ADC Mux", "Stereo", "Right PGA Mux" }, | ||
396 | { "Right ADC Mux", "Mono (Right)", "Right PGA Mux" }, | ||
397 | { "Right ADC Mux", "Digital Mono", "Right PGA Mux" }, | ||
398 | |||
399 | { "Left ADC", NULL, "Left ADC Mux" }, | ||
400 | { "Right ADC", NULL, "Right ADC Mux" }, | ||
401 | |||
402 | { "Left Line Mux", "Line 1", "LINPUT1" }, | ||
403 | { "Left Line Mux", "Line 2", "LINPUT2" }, | ||
404 | { "Left Line Mux", "PGA", "Left PGA Mux" }, | ||
405 | { "Left Line Mux", "Differential", "Differential Mux" }, | ||
406 | |||
407 | { "Right Line Mux", "Line 1", "RINPUT1" }, | ||
408 | { "Right Line Mux", "Line 2", "RINPUT2" }, | ||
409 | { "Right Line Mux", "PGA", "Right PGA Mux" }, | ||
410 | { "Right Line Mux", "Differential", "Differential Mux" }, | ||
411 | |||
412 | { "Left Mixer", "Playback Switch", "Left DAC" }, | ||
413 | { "Left Mixer", "Left Bypass Switch", "Left Line Mux" }, | ||
414 | { "Left Mixer", "Right Playback Switch", "Right DAC" }, | ||
415 | { "Left Mixer", "Right Bypass Switch", "Right Line Mux" }, | ||
416 | |||
417 | { "Right Mixer", "Left Playback Switch", "Left DAC" }, | ||
418 | { "Right Mixer", "Left Bypass Switch", "Left Line Mux" }, | ||
419 | { "Right Mixer", "Playback Switch", "Right DAC" }, | ||
420 | { "Right Mixer", "Right Bypass Switch", "Right Line Mux" }, | ||
421 | |||
422 | { "Left Out 1", NULL, "Left Mixer" }, | ||
423 | { "LOUT1", NULL, "Left Out 1" }, | ||
424 | { "Right Out 1", NULL, "Right Mixer" }, | ||
425 | { "ROUT1", NULL, "Right Out 1" }, | ||
426 | |||
427 | { "Left Out 2", NULL, "Left Mixer" }, | ||
428 | { "LOUT2", NULL, "Left Out 2" }, | ||
429 | { "Right Out 2", NULL, "Right Mixer" }, | ||
430 | { "ROUT2", NULL, "Right Out 2" }, | ||
431 | }; | ||
432 | |||
433 | struct _coeff_div { | ||
434 | u32 mclk; | ||
435 | u32 rate; | ||
436 | u16 fs; | ||
437 | u8 sr:5; | ||
438 | u8 usb:1; | ||
439 | }; | ||
440 | |||
441 | /* codec hifi mclk clock divider coefficients */ | ||
442 | static const struct _coeff_div coeff_div[] = { | ||
443 | /* 8k */ | ||
444 | {12288000, 8000, 1536, 0x6, 0x0}, | ||
445 | {11289600, 8000, 1408, 0x16, 0x0}, | ||
446 | {18432000, 8000, 2304, 0x7, 0x0}, | ||
447 | {16934400, 8000, 2112, 0x17, 0x0}, | ||
448 | {12000000, 8000, 1500, 0x6, 0x1}, | ||
449 | |||
450 | /* 11.025k */ | ||
451 | {11289600, 11025, 1024, 0x18, 0x0}, | ||
452 | {16934400, 11025, 1536, 0x19, 0x0}, | ||
453 | {12000000, 11025, 1088, 0x19, 0x1}, | ||
454 | |||
455 | /* 16k */ | ||
456 | {12288000, 16000, 768, 0xa, 0x0}, | ||
457 | {18432000, 16000, 1152, 0xb, 0x0}, | ||
458 | {12000000, 16000, 750, 0xa, 0x1}, | ||
459 | |||
460 | /* 22.05k */ | ||
461 | {11289600, 22050, 512, 0x1a, 0x0}, | ||
462 | {16934400, 22050, 768, 0x1b, 0x0}, | ||
463 | {12000000, 22050, 544, 0x1b, 0x1}, | ||
464 | |||
465 | /* 32k */ | ||
466 | {12288000, 32000, 384, 0xc, 0x0}, | ||
467 | {18432000, 32000, 576, 0xd, 0x0}, | ||
468 | {12000000, 32000, 375, 0xa, 0x1}, | ||
469 | |||
470 | /* 44.1k */ | ||
471 | {11289600, 44100, 256, 0x10, 0x0}, | ||
472 | {16934400, 44100, 384, 0x11, 0x0}, | ||
473 | {12000000, 44100, 272, 0x11, 0x1}, | ||
474 | |||
475 | /* 48k */ | ||
476 | {12288000, 48000, 256, 0x0, 0x0}, | ||
477 | {18432000, 48000, 384, 0x1, 0x0}, | ||
478 | {12000000, 48000, 250, 0x0, 0x1}, | ||
479 | |||
480 | /* 88.2k */ | ||
481 | {11289600, 88200, 128, 0x1e, 0x0}, | ||
482 | {16934400, 88200, 192, 0x1f, 0x0}, | ||
483 | {12000000, 88200, 136, 0x1f, 0x1}, | ||
484 | |||
485 | /* 96k */ | ||
486 | {12288000, 96000, 128, 0xe, 0x0}, | ||
487 | {18432000, 96000, 192, 0xf, 0x0}, | ||
488 | {12000000, 96000, 125, 0xe, 0x1}, | ||
489 | }; | ||
490 | |||
491 | static inline int get_coeff(int mclk, int rate) | ||
492 | { | ||
493 | int i; | ||
494 | |||
495 | for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { | ||
496 | if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk) | ||
497 | return i; | ||
498 | } | ||
499 | |||
500 | return -EINVAL; | ||
501 | } | ||
502 | |||
503 | /* The set of rates we can generate from the above for each SYSCLK */ | ||
504 | |||
505 | static unsigned int rates_12288[] = { | ||
506 | 8000, 12000, 16000, 24000, 24000, 32000, 48000, 96000, | ||
507 | }; | ||
508 | |||
509 | static struct snd_pcm_hw_constraint_list constraints_12288 = { | ||
510 | .count = ARRAY_SIZE(rates_12288), | ||
511 | .list = rates_12288, | ||
512 | }; | ||
513 | |||
514 | static unsigned int rates_112896[] = { | ||
515 | 8000, 11025, 22050, 44100, | ||
516 | }; | ||
517 | |||
518 | static struct snd_pcm_hw_constraint_list constraints_112896 = { | ||
519 | .count = ARRAY_SIZE(rates_112896), | ||
520 | .list = rates_112896, | ||
521 | }; | ||
522 | |||
523 | static unsigned int rates_12[] = { | ||
524 | 8000, 11025, 12000, 16000, 22050, 2400, 32000, 41100, 48000, | ||
525 | 48000, 88235, 96000, | ||
526 | }; | ||
527 | |||
528 | static struct snd_pcm_hw_constraint_list constraints_12 = { | ||
529 | .count = ARRAY_SIZE(rates_12), | ||
530 | .list = rates_12, | ||
531 | }; | ||
532 | |||
533 | /* | ||
534 | * Note that this should be called from init rather than from hw_params. | ||
535 | */ | ||
536 | static int wm8988_set_dai_sysclk(struct snd_soc_dai *codec_dai, | ||
537 | int clk_id, unsigned int freq, int dir) | ||
538 | { | ||
539 | struct snd_soc_codec *codec = codec_dai->codec; | ||
540 | struct wm8988_priv *wm8988 = codec->private_data; | ||
541 | |||
542 | switch (freq) { | ||
543 | case 11289600: | ||
544 | case 18432000: | ||
545 | case 22579200: | ||
546 | case 36864000: | ||
547 | wm8988->sysclk_constraints = &constraints_112896; | ||
548 | wm8988->sysclk = freq; | ||
549 | return 0; | ||
550 | |||
551 | case 12288000: | ||
552 | case 16934400: | ||
553 | case 24576000: | ||
554 | case 33868800: | ||
555 | wm8988->sysclk_constraints = &constraints_12288; | ||
556 | wm8988->sysclk = freq; | ||
557 | return 0; | ||
558 | |||
559 | case 12000000: | ||
560 | case 24000000: | ||
561 | wm8988->sysclk_constraints = &constraints_12; | ||
562 | wm8988->sysclk = freq; | ||
563 | return 0; | ||
564 | } | ||
565 | return -EINVAL; | ||
566 | } | ||
567 | |||
568 | static int wm8988_set_dai_fmt(struct snd_soc_dai *codec_dai, | ||
569 | unsigned int fmt) | ||
570 | { | ||
571 | struct snd_soc_codec *codec = codec_dai->codec; | ||
572 | u16 iface = 0; | ||
573 | |||
574 | /* set master/slave audio interface */ | ||
575 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
576 | case SND_SOC_DAIFMT_CBM_CFM: | ||
577 | iface = 0x0040; | ||
578 | break; | ||
579 | case SND_SOC_DAIFMT_CBS_CFS: | ||
580 | break; | ||
581 | default: | ||
582 | return -EINVAL; | ||
583 | } | ||
584 | |||
585 | /* interface format */ | ||
586 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
587 | case SND_SOC_DAIFMT_I2S: | ||
588 | iface |= 0x0002; | ||
589 | break; | ||
590 | case SND_SOC_DAIFMT_RIGHT_J: | ||
591 | break; | ||
592 | case SND_SOC_DAIFMT_LEFT_J: | ||
593 | iface |= 0x0001; | ||
594 | break; | ||
595 | case SND_SOC_DAIFMT_DSP_A: | ||
596 | iface |= 0x0003; | ||
597 | break; | ||
598 | case SND_SOC_DAIFMT_DSP_B: | ||
599 | iface |= 0x0013; | ||
600 | break; | ||
601 | default: | ||
602 | return -EINVAL; | ||
603 | } | ||
604 | |||
605 | /* clock inversion */ | ||
606 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
607 | case SND_SOC_DAIFMT_NB_NF: | ||
608 | break; | ||
609 | case SND_SOC_DAIFMT_IB_IF: | ||
610 | iface |= 0x0090; | ||
611 | break; | ||
612 | case SND_SOC_DAIFMT_IB_NF: | ||
613 | iface |= 0x0080; | ||
614 | break; | ||
615 | case SND_SOC_DAIFMT_NB_IF: | ||
616 | iface |= 0x0010; | ||
617 | break; | ||
618 | default: | ||
619 | return -EINVAL; | ||
620 | } | ||
621 | |||
622 | wm8988_write(codec, WM8988_IFACE, iface); | ||
623 | return 0; | ||
624 | } | ||
625 | |||
626 | static int wm8988_pcm_startup(struct snd_pcm_substream *substream, | ||
627 | struct snd_soc_dai *dai) | ||
628 | { | ||
629 | struct snd_soc_codec *codec = dai->codec; | ||
630 | struct wm8988_priv *wm8988 = codec->private_data; | ||
631 | |||
632 | /* The set of sample rates that can be supported depends on the | ||
633 | * MCLK supplied to the CODEC - enforce this. | ||
634 | */ | ||
635 | if (!wm8988->sysclk) { | ||
636 | dev_err(codec->dev, | ||
637 | "No MCLK configured, call set_sysclk() on init\n"); | ||
638 | return -EINVAL; | ||
639 | } | ||
640 | |||
641 | snd_pcm_hw_constraint_list(substream->runtime, 0, | ||
642 | SNDRV_PCM_HW_PARAM_RATE, | ||
643 | wm8988->sysclk_constraints); | ||
644 | |||
645 | return 0; | ||
646 | } | ||
647 | |||
648 | static int wm8988_pcm_hw_params(struct snd_pcm_substream *substream, | ||
649 | struct snd_pcm_hw_params *params, | ||
650 | struct snd_soc_dai *dai) | ||
651 | { | ||
652 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
653 | struct snd_soc_device *socdev = rtd->socdev; | ||
654 | struct snd_soc_codec *codec = socdev->card->codec; | ||
655 | struct wm8988_priv *wm8988 = codec->private_data; | ||
656 | u16 iface = wm8988_read_reg_cache(codec, WM8988_IFACE) & 0x1f3; | ||
657 | u16 srate = wm8988_read_reg_cache(codec, WM8988_SRATE) & 0x180; | ||
658 | int coeff; | ||
659 | |||
660 | coeff = get_coeff(wm8988->sysclk, params_rate(params)); | ||
661 | if (coeff < 0) { | ||
662 | coeff = get_coeff(wm8988->sysclk / 2, params_rate(params)); | ||
663 | srate |= 0x40; | ||
664 | } | ||
665 | if (coeff < 0) { | ||
666 | dev_err(codec->dev, | ||
667 | "Unable to configure sample rate %dHz with %dHz MCLK\n", | ||
668 | params_rate(params), wm8988->sysclk); | ||
669 | return coeff; | ||
670 | } | ||
671 | |||
672 | /* bit size */ | ||
673 | switch (params_format(params)) { | ||
674 | case SNDRV_PCM_FORMAT_S16_LE: | ||
675 | break; | ||
676 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
677 | iface |= 0x0004; | ||
678 | break; | ||
679 | case SNDRV_PCM_FORMAT_S24_LE: | ||
680 | iface |= 0x0008; | ||
681 | break; | ||
682 | case SNDRV_PCM_FORMAT_S32_LE: | ||
683 | iface |= 0x000c; | ||
684 | break; | ||
685 | } | ||
686 | |||
687 | /* set iface & srate */ | ||
688 | wm8988_write(codec, WM8988_IFACE, iface); | ||
689 | if (coeff >= 0) | ||
690 | wm8988_write(codec, WM8988_SRATE, srate | | ||
691 | (coeff_div[coeff].sr << 1) | coeff_div[coeff].usb); | ||
692 | |||
693 | return 0; | ||
694 | } | ||
695 | |||
696 | static int wm8988_mute(struct snd_soc_dai *dai, int mute) | ||
697 | { | ||
698 | struct snd_soc_codec *codec = dai->codec; | ||
699 | u16 mute_reg = wm8988_read_reg_cache(codec, WM8988_ADCDAC) & 0xfff7; | ||
700 | |||
701 | if (mute) | ||
702 | wm8988_write(codec, WM8988_ADCDAC, mute_reg | 0x8); | ||
703 | else | ||
704 | wm8988_write(codec, WM8988_ADCDAC, mute_reg); | ||
705 | return 0; | ||
706 | } | ||
707 | |||
708 | static int wm8988_set_bias_level(struct snd_soc_codec *codec, | ||
709 | enum snd_soc_bias_level level) | ||
710 | { | ||
711 | u16 pwr_reg = wm8988_read_reg_cache(codec, WM8988_PWR1) & ~0x1c1; | ||
712 | |||
713 | switch (level) { | ||
714 | case SND_SOC_BIAS_ON: | ||
715 | break; | ||
716 | |||
717 | case SND_SOC_BIAS_PREPARE: | ||
718 | /* VREF, VMID=2x50k, digital enabled */ | ||
719 | wm8988_write(codec, WM8988_PWR1, pwr_reg | 0x00c0); | ||
720 | break; | ||
721 | |||
722 | case SND_SOC_BIAS_STANDBY: | ||
723 | if (codec->bias_level == SND_SOC_BIAS_OFF) { | ||
724 | /* VREF, VMID=2x5k */ | ||
725 | wm8988_write(codec, WM8988_PWR1, pwr_reg | 0x1c1); | ||
726 | |||
727 | /* Charge caps */ | ||
728 | msleep(100); | ||
729 | } | ||
730 | |||
731 | /* VREF, VMID=2*500k, digital stopped */ | ||
732 | wm8988_write(codec, WM8988_PWR1, pwr_reg | 0x0141); | ||
733 | break; | ||
734 | |||
735 | case SND_SOC_BIAS_OFF: | ||
736 | wm8988_write(codec, WM8988_PWR1, 0x0000); | ||
737 | break; | ||
738 | } | ||
739 | codec->bias_level = level; | ||
740 | return 0; | ||
741 | } | ||
742 | |||
743 | #define WM8988_RATES SNDRV_PCM_RATE_8000_96000 | ||
744 | |||
745 | #define WM8988_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | ||
746 | SNDRV_PCM_FMTBIT_S24_LE) | ||
747 | |||
748 | static struct snd_soc_dai_ops wm8988_ops = { | ||
749 | .startup = wm8988_pcm_startup, | ||
750 | .hw_params = wm8988_pcm_hw_params, | ||
751 | .set_fmt = wm8988_set_dai_fmt, | ||
752 | .set_sysclk = wm8988_set_dai_sysclk, | ||
753 | .digital_mute = wm8988_mute, | ||
754 | }; | ||
755 | |||
756 | struct snd_soc_dai wm8988_dai = { | ||
757 | .name = "WM8988", | ||
758 | .playback = { | ||
759 | .stream_name = "Playback", | ||
760 | .channels_min = 1, | ||
761 | .channels_max = 2, | ||
762 | .rates = WM8988_RATES, | ||
763 | .formats = WM8988_FORMATS, | ||
764 | }, | ||
765 | .capture = { | ||
766 | .stream_name = "Capture", | ||
767 | .channels_min = 1, | ||
768 | .channels_max = 2, | ||
769 | .rates = WM8988_RATES, | ||
770 | .formats = WM8988_FORMATS, | ||
771 | }, | ||
772 | .ops = &wm8988_ops, | ||
773 | .symmetric_rates = 1, | ||
774 | }; | ||
775 | EXPORT_SYMBOL_GPL(wm8988_dai); | ||
776 | |||
777 | static int wm8988_suspend(struct platform_device *pdev, pm_message_t state) | ||
778 | { | ||
779 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
780 | struct snd_soc_codec *codec = socdev->card->codec; | ||
781 | |||
782 | wm8988_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
783 | return 0; | ||
784 | } | ||
785 | |||
786 | static int wm8988_resume(struct platform_device *pdev) | ||
787 | { | ||
788 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
789 | struct snd_soc_codec *codec = socdev->card->codec; | ||
790 | int i; | ||
791 | u8 data[2]; | ||
792 | u16 *cache = codec->reg_cache; | ||
793 | |||
794 | /* Sync reg_cache with the hardware */ | ||
795 | for (i = 0; i < WM8988_NUM_REG; i++) { | ||
796 | if (i == WM8988_RESET) | ||
797 | continue; | ||
798 | data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001); | ||
799 | data[1] = cache[i] & 0x00ff; | ||
800 | codec->hw_write(codec->control_data, data, 2); | ||
801 | } | ||
802 | |||
803 | wm8988_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
804 | |||
805 | return 0; | ||
806 | } | ||
807 | |||
808 | static struct snd_soc_codec *wm8988_codec; | ||
809 | |||
810 | static int wm8988_probe(struct platform_device *pdev) | ||
811 | { | ||
812 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
813 | struct snd_soc_codec *codec; | ||
814 | int ret = 0; | ||
815 | |||
816 | if (wm8988_codec == NULL) { | ||
817 | dev_err(&pdev->dev, "Codec device not registered\n"); | ||
818 | return -ENODEV; | ||
819 | } | ||
820 | |||
821 | socdev->card->codec = wm8988_codec; | ||
822 | codec = wm8988_codec; | ||
823 | |||
824 | /* register pcms */ | ||
825 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
826 | if (ret < 0) { | ||
827 | dev_err(codec->dev, "failed to create pcms: %d\n", ret); | ||
828 | goto pcm_err; | ||
829 | } | ||
830 | |||
831 | snd_soc_add_controls(codec, wm8988_snd_controls, | ||
832 | ARRAY_SIZE(wm8988_snd_controls)); | ||
833 | snd_soc_dapm_new_controls(codec, wm8988_dapm_widgets, | ||
834 | ARRAY_SIZE(wm8988_dapm_widgets)); | ||
835 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | ||
836 | snd_soc_dapm_new_widgets(codec); | ||
837 | |||
838 | ret = snd_soc_init_card(socdev); | ||
839 | if (ret < 0) { | ||
840 | dev_err(codec->dev, "failed to register card: %d\n", ret); | ||
841 | goto card_err; | ||
842 | } | ||
843 | |||
844 | return ret; | ||
845 | |||
846 | card_err: | ||
847 | snd_soc_free_pcms(socdev); | ||
848 | snd_soc_dapm_free(socdev); | ||
849 | pcm_err: | ||
850 | return ret; | ||
851 | } | ||
852 | |||
853 | static int wm8988_remove(struct platform_device *pdev) | ||
854 | { | ||
855 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
856 | |||
857 | snd_soc_free_pcms(socdev); | ||
858 | snd_soc_dapm_free(socdev); | ||
859 | |||
860 | return 0; | ||
861 | } | ||
862 | |||
863 | struct snd_soc_codec_device soc_codec_dev_wm8988 = { | ||
864 | .probe = wm8988_probe, | ||
865 | .remove = wm8988_remove, | ||
866 | .suspend = wm8988_suspend, | ||
867 | .resume = wm8988_resume, | ||
868 | }; | ||
869 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8988); | ||
870 | |||
871 | static int wm8988_register(struct wm8988_priv *wm8988) | ||
872 | { | ||
873 | struct snd_soc_codec *codec = &wm8988->codec; | ||
874 | int ret; | ||
875 | u16 reg; | ||
876 | |||
877 | if (wm8988_codec) { | ||
878 | dev_err(codec->dev, "Another WM8988 is registered\n"); | ||
879 | ret = -EINVAL; | ||
880 | goto err; | ||
881 | } | ||
882 | |||
883 | mutex_init(&codec->mutex); | ||
884 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
885 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
886 | |||
887 | codec->private_data = wm8988; | ||
888 | codec->name = "WM8988"; | ||
889 | codec->owner = THIS_MODULE; | ||
890 | codec->read = wm8988_read_reg_cache; | ||
891 | codec->write = wm8988_write; | ||
892 | codec->dai = &wm8988_dai; | ||
893 | codec->num_dai = 1; | ||
894 | codec->reg_cache_size = ARRAY_SIZE(wm8988->reg_cache); | ||
895 | codec->reg_cache = &wm8988->reg_cache; | ||
896 | codec->bias_level = SND_SOC_BIAS_OFF; | ||
897 | codec->set_bias_level = wm8988_set_bias_level; | ||
898 | |||
899 | memcpy(codec->reg_cache, wm8988_reg, | ||
900 | sizeof(wm8988_reg)); | ||
901 | |||
902 | ret = wm8988_reset(codec); | ||
903 | if (ret < 0) { | ||
904 | dev_err(codec->dev, "Failed to issue reset\n"); | ||
905 | return ret; | ||
906 | } | ||
907 | |||
908 | /* set the update bits (we always update left then right) */ | ||
909 | reg = wm8988_read_reg_cache(codec, WM8988_RADC); | ||
910 | wm8988_write(codec, WM8988_RADC, reg | 0x100); | ||
911 | reg = wm8988_read_reg_cache(codec, WM8988_RDAC); | ||
912 | wm8988_write(codec, WM8988_RDAC, reg | 0x0100); | ||
913 | reg = wm8988_read_reg_cache(codec, WM8988_ROUT1V); | ||
914 | wm8988_write(codec, WM8988_ROUT1V, reg | 0x0100); | ||
915 | reg = wm8988_read_reg_cache(codec, WM8988_ROUT2V); | ||
916 | wm8988_write(codec, WM8988_ROUT2V, reg | 0x0100); | ||
917 | reg = wm8988_read_reg_cache(codec, WM8988_RINVOL); | ||
918 | wm8988_write(codec, WM8988_RINVOL, reg | 0x0100); | ||
919 | |||
920 | wm8988_set_bias_level(&wm8988->codec, SND_SOC_BIAS_STANDBY); | ||
921 | |||
922 | wm8988_dai.dev = codec->dev; | ||
923 | |||
924 | wm8988_codec = codec; | ||
925 | |||
926 | ret = snd_soc_register_codec(codec); | ||
927 | if (ret != 0) { | ||
928 | dev_err(codec->dev, "Failed to register codec: %d\n", ret); | ||
929 | return ret; | ||
930 | } | ||
931 | |||
932 | ret = snd_soc_register_dai(&wm8988_dai); | ||
933 | if (ret != 0) { | ||
934 | dev_err(codec->dev, "Failed to register DAI: %d\n", ret); | ||
935 | snd_soc_unregister_codec(codec); | ||
936 | return ret; | ||
937 | } | ||
938 | |||
939 | return 0; | ||
940 | |||
941 | err: | ||
942 | kfree(wm8988); | ||
943 | return ret; | ||
944 | } | ||
945 | |||
946 | static void wm8988_unregister(struct wm8988_priv *wm8988) | ||
947 | { | ||
948 | wm8988_set_bias_level(&wm8988->codec, SND_SOC_BIAS_OFF); | ||
949 | snd_soc_unregister_dai(&wm8988_dai); | ||
950 | snd_soc_unregister_codec(&wm8988->codec); | ||
951 | kfree(wm8988); | ||
952 | wm8988_codec = NULL; | ||
953 | } | ||
954 | |||
955 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
956 | static int wm8988_i2c_probe(struct i2c_client *i2c, | ||
957 | const struct i2c_device_id *id) | ||
958 | { | ||
959 | struct wm8988_priv *wm8988; | ||
960 | struct snd_soc_codec *codec; | ||
961 | |||
962 | wm8988 = kzalloc(sizeof(struct wm8988_priv), GFP_KERNEL); | ||
963 | if (wm8988 == NULL) | ||
964 | return -ENOMEM; | ||
965 | |||
966 | codec = &wm8988->codec; | ||
967 | codec->hw_write = (hw_write_t)i2c_master_send; | ||
968 | |||
969 | i2c_set_clientdata(i2c, wm8988); | ||
970 | codec->control_data = i2c; | ||
971 | |||
972 | codec->dev = &i2c->dev; | ||
973 | |||
974 | return wm8988_register(wm8988); | ||
975 | } | ||
976 | |||
977 | static int wm8988_i2c_remove(struct i2c_client *client) | ||
978 | { | ||
979 | struct wm8988_priv *wm8988 = i2c_get_clientdata(client); | ||
980 | wm8988_unregister(wm8988); | ||
981 | return 0; | ||
982 | } | ||
983 | |||
984 | static const struct i2c_device_id wm8988_i2c_id[] = { | ||
985 | { "wm8988", 0 }, | ||
986 | { } | ||
987 | }; | ||
988 | MODULE_DEVICE_TABLE(i2c, wm8988_i2c_id); | ||
989 | |||
990 | static struct i2c_driver wm8988_i2c_driver = { | ||
991 | .driver = { | ||
992 | .name = "WM8988", | ||
993 | .owner = THIS_MODULE, | ||
994 | }, | ||
995 | .probe = wm8988_i2c_probe, | ||
996 | .remove = wm8988_i2c_remove, | ||
997 | .id_table = wm8988_i2c_id, | ||
998 | }; | ||
999 | #endif | ||
1000 | |||
1001 | #if defined(CONFIG_SPI_MASTER) | ||
1002 | static int wm8988_spi_write(struct spi_device *spi, const char *data, int len) | ||
1003 | { | ||
1004 | struct spi_transfer t; | ||
1005 | struct spi_message m; | ||
1006 | u8 msg[2]; | ||
1007 | |||
1008 | if (len <= 0) | ||
1009 | return 0; | ||
1010 | |||
1011 | msg[0] = data[0]; | ||
1012 | msg[1] = data[1]; | ||
1013 | |||
1014 | spi_message_init(&m); | ||
1015 | memset(&t, 0, (sizeof t)); | ||
1016 | |||
1017 | t.tx_buf = &msg[0]; | ||
1018 | t.len = len; | ||
1019 | |||
1020 | spi_message_add_tail(&t, &m); | ||
1021 | spi_sync(spi, &m); | ||
1022 | |||
1023 | return len; | ||
1024 | } | ||
1025 | |||
1026 | static int __devinit wm8988_spi_probe(struct spi_device *spi) | ||
1027 | { | ||
1028 | struct wm8988_priv *wm8988; | ||
1029 | struct snd_soc_codec *codec; | ||
1030 | |||
1031 | wm8988 = kzalloc(sizeof(struct wm8988_priv), GFP_KERNEL); | ||
1032 | if (wm8988 == NULL) | ||
1033 | return -ENOMEM; | ||
1034 | |||
1035 | codec = &wm8988->codec; | ||
1036 | codec->hw_write = (hw_write_t)wm8988_spi_write; | ||
1037 | codec->control_data = spi; | ||
1038 | codec->dev = &spi->dev; | ||
1039 | |||
1040 | spi->dev.driver_data = wm8988; | ||
1041 | |||
1042 | return wm8988_register(wm8988); | ||
1043 | } | ||
1044 | |||
1045 | static int __devexit wm8988_spi_remove(struct spi_device *spi) | ||
1046 | { | ||
1047 | struct wm8988_priv *wm8988 = spi->dev.driver_data; | ||
1048 | |||
1049 | wm8988_unregister(wm8988); | ||
1050 | |||
1051 | return 0; | ||
1052 | } | ||
1053 | |||
1054 | static struct spi_driver wm8988_spi_driver = { | ||
1055 | .driver = { | ||
1056 | .name = "wm8988", | ||
1057 | .bus = &spi_bus_type, | ||
1058 | .owner = THIS_MODULE, | ||
1059 | }, | ||
1060 | .probe = wm8988_spi_probe, | ||
1061 | .remove = __devexit_p(wm8988_spi_remove), | ||
1062 | }; | ||
1063 | #endif | ||
1064 | |||
1065 | static int __init wm8988_modinit(void) | ||
1066 | { | ||
1067 | int ret; | ||
1068 | |||
1069 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
1070 | ret = i2c_add_driver(&wm8988_i2c_driver); | ||
1071 | if (ret != 0) | ||
1072 | pr_err("WM8988: Unable to register I2C driver: %d\n", ret); | ||
1073 | #endif | ||
1074 | #if defined(CONFIG_SPI_MASTER) | ||
1075 | ret = spi_register_driver(&wm8988_spi_driver); | ||
1076 | if (ret != 0) | ||
1077 | pr_err("WM8988: Unable to register SPI driver: %d\n", ret); | ||
1078 | #endif | ||
1079 | return ret; | ||
1080 | } | ||
1081 | module_init(wm8988_modinit); | ||
1082 | |||
1083 | static void __exit wm8988_exit(void) | ||
1084 | { | ||
1085 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
1086 | i2c_del_driver(&wm8988_i2c_driver); | ||
1087 | #endif | ||
1088 | #if defined(CONFIG_SPI_MASTER) | ||
1089 | spi_unregister_driver(&wm8988_spi_driver); | ||
1090 | #endif | ||
1091 | } | ||
1092 | module_exit(wm8988_exit); | ||
1093 | |||
1094 | |||
1095 | MODULE_DESCRIPTION("ASoC WM8988 driver"); | ||
1096 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
1097 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/wm8988.h b/sound/soc/codecs/wm8988.h new file mode 100644 index 000000000000..4552d37fdd41 --- /dev/null +++ b/sound/soc/codecs/wm8988.h | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | * Copyright 2005 Openedhand Ltd. | ||
3 | * | ||
4 | * Author: Richard Purdie <richard@openedhand.com> | ||
5 | * | ||
6 | * Based on WM8753.h | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #ifndef _WM8988_H | ||
15 | #define _WM8988_H | ||
16 | |||
17 | /* WM8988 register space */ | ||
18 | |||
19 | #define WM8988_LINVOL 0x00 | ||
20 | #define WM8988_RINVOL 0x01 | ||
21 | #define WM8988_LOUT1V 0x02 | ||
22 | #define WM8988_ROUT1V 0x03 | ||
23 | #define WM8988_ADCDAC 0x05 | ||
24 | #define WM8988_IFACE 0x07 | ||
25 | #define WM8988_SRATE 0x08 | ||
26 | #define WM8988_LDAC 0x0a | ||
27 | #define WM8988_RDAC 0x0b | ||
28 | #define WM8988_BASS 0x0c | ||
29 | #define WM8988_TREBLE 0x0d | ||
30 | #define WM8988_RESET 0x0f | ||
31 | #define WM8988_3D 0x10 | ||
32 | #define WM8988_ALC1 0x11 | ||
33 | #define WM8988_ALC2 0x12 | ||
34 | #define WM8988_ALC3 0x13 | ||
35 | #define WM8988_NGATE 0x14 | ||
36 | #define WM8988_LADC 0x15 | ||
37 | #define WM8988_RADC 0x16 | ||
38 | #define WM8988_ADCTL1 0x17 | ||
39 | #define WM8988_ADCTL2 0x18 | ||
40 | #define WM8988_PWR1 0x19 | ||
41 | #define WM8988_PWR2 0x1a | ||
42 | #define WM8988_ADCTL3 0x1b | ||
43 | #define WM8988_ADCIN 0x1f | ||
44 | #define WM8988_LADCIN 0x20 | ||
45 | #define WM8988_RADCIN 0x21 | ||
46 | #define WM8988_LOUTM1 0x22 | ||
47 | #define WM8988_LOUTM2 0x23 | ||
48 | #define WM8988_ROUTM1 0x24 | ||
49 | #define WM8988_ROUTM2 0x25 | ||
50 | #define WM8988_LOUT2V 0x28 | ||
51 | #define WM8988_ROUT2V 0x29 | ||
52 | #define WM8988_LPPB 0x43 | ||
53 | #define WM8988_NUM_REG 0x44 | ||
54 | |||
55 | #define WM8988_SYSCLK 0 | ||
56 | |||
57 | extern struct snd_soc_dai wm8988_dai; | ||
58 | extern struct snd_soc_codec_device soc_codec_dev_wm8988; | ||
59 | |||
60 | #endif | ||
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c index c2d1a7a18fa3..fa88b463e71f 100644 --- a/sound/soc/codecs/wm9705.c +++ b/sound/soc/codecs/wm9705.c | |||
@@ -282,14 +282,14 @@ struct snd_soc_dai wm9705_dai[] = { | |||
282 | .channels_min = 1, | 282 | .channels_min = 1, |
283 | .channels_max = 2, | 283 | .channels_max = 2, |
284 | .rates = WM9705_AC97_RATES, | 284 | .rates = WM9705_AC97_RATES, |
285 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | 285 | .formats = SND_SOC_STD_AC97_FMTS, |
286 | }, | 286 | }, |
287 | .capture = { | 287 | .capture = { |
288 | .stream_name = "HiFi Capture", | 288 | .stream_name = "HiFi Capture", |
289 | .channels_min = 1, | 289 | .channels_min = 1, |
290 | .channels_max = 2, | 290 | .channels_max = 2, |
291 | .rates = WM9705_AC97_RATES, | 291 | .rates = WM9705_AC97_RATES, |
292 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | 292 | .formats = SND_SOC_STD_AC97_FMTS, |
293 | }, | 293 | }, |
294 | .ops = &wm9705_dai_ops, | 294 | .ops = &wm9705_dai_ops, |
295 | }, | 295 | }, |
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c index 765cf1e7369e..550c903f23bf 100644 --- a/sound/soc/codecs/wm9712.c +++ b/sound/soc/codecs/wm9712.c | |||
@@ -534,13 +534,13 @@ struct snd_soc_dai wm9712_dai[] = { | |||
534 | .channels_min = 1, | 534 | .channels_min = 1, |
535 | .channels_max = 2, | 535 | .channels_max = 2, |
536 | .rates = WM9712_AC97_RATES, | 536 | .rates = WM9712_AC97_RATES, |
537 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 537 | .formats = SND_SOC_STD_AC97_FMTS,}, |
538 | .capture = { | 538 | .capture = { |
539 | .stream_name = "HiFi Capture", | 539 | .stream_name = "HiFi Capture", |
540 | .channels_min = 1, | 540 | .channels_min = 1, |
541 | .channels_max = 2, | 541 | .channels_max = 2, |
542 | .rates = WM9712_AC97_RATES, | 542 | .rates = WM9712_AC97_RATES, |
543 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 543 | .formats = SND_SOC_STD_AC97_FMTS,}, |
544 | .ops = &wm9712_dai_ops_hifi, | 544 | .ops = &wm9712_dai_ops_hifi, |
545 | }, | 545 | }, |
546 | { | 546 | { |
@@ -550,7 +550,7 @@ struct snd_soc_dai wm9712_dai[] = { | |||
550 | .channels_min = 1, | 550 | .channels_min = 1, |
551 | .channels_max = 1, | 551 | .channels_max = 1, |
552 | .rates = WM9712_AC97_RATES, | 552 | .rates = WM9712_AC97_RATES, |
553 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 553 | .formats = SND_SOC_STD_AC97_FMTS,}, |
554 | .ops = &wm9712_dai_ops_aux, | 554 | .ops = &wm9712_dai_ops_aux, |
555 | } | 555 | } |
556 | }; | 556 | }; |
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c index 523bad077fa0..d1744e96f303 100644 --- a/sound/soc/codecs/wm9713.c +++ b/sound/soc/codecs/wm9713.c | |||
@@ -189,6 +189,26 @@ SOC_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0), | |||
189 | SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), | 189 | SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), |
190 | }; | 190 | }; |
191 | 191 | ||
192 | static int wm9713_voice_shutdown(struct snd_soc_dapm_widget *w, | ||
193 | struct snd_kcontrol *kcontrol, int event) | ||
194 | { | ||
195 | struct snd_soc_codec *codec = w->codec; | ||
196 | u16 status, rate; | ||
197 | |||
198 | BUG_ON(event != SND_SOC_DAPM_PRE_PMD); | ||
199 | |||
200 | /* Gracefully shut down the voice interface. */ | ||
201 | status = ac97_read(codec, AC97_EXTENDED_MID) | 0x1000; | ||
202 | rate = ac97_read(codec, AC97_HANDSET_RATE) & 0xF0FF; | ||
203 | ac97_write(codec, AC97_HANDSET_RATE, rate | 0x0200); | ||
204 | schedule_timeout_interruptible(msecs_to_jiffies(1)); | ||
205 | ac97_write(codec, AC97_HANDSET_RATE, rate | 0x0F00); | ||
206 | ac97_write(codec, AC97_EXTENDED_MID, status); | ||
207 | |||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | |||
192 | /* We have to create a fake left and right HP mixers because | 212 | /* We have to create a fake left and right HP mixers because |
193 | * the codec only has a single control that is shared by both channels. | 213 | * the codec only has a single control that is shared by both channels. |
194 | * This makes it impossible to determine the audio path using the current | 214 | * This makes it impossible to determine the audio path using the current |
@@ -400,7 +420,8 @@ SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), | |||
400 | SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), | 420 | SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
401 | SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), | 421 | SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
402 | SND_SOC_DAPM_MIXER("Capture Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), | 422 | SND_SOC_DAPM_MIXER("Capture Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
403 | SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", AC97_EXTENDED_MID, 12, 1), | 423 | SND_SOC_DAPM_DAC_E("Voice DAC", "Voice Playback", AC97_EXTENDED_MID, 12, 1, |
424 | wm9713_voice_shutdown, SND_SOC_DAPM_PRE_PMD), | ||
404 | SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID, 11, 1), | 425 | SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID, 11, 1), |
405 | SND_SOC_DAPM_PGA("Left ADC", AC97_EXTENDED_MID, 5, 1, NULL, 0), | 426 | SND_SOC_DAPM_PGA("Left ADC", AC97_EXTENDED_MID, 5, 1, NULL, 0), |
406 | SND_SOC_DAPM_PGA("Right ADC", AC97_EXTENDED_MID, 4, 1, NULL, 0), | 427 | SND_SOC_DAPM_PGA("Right ADC", AC97_EXTENDED_MID, 4, 1, NULL, 0), |
@@ -936,21 +957,6 @@ static int wm9713_pcm_hw_params(struct snd_pcm_substream *substream, | |||
936 | return 0; | 957 | return 0; |
937 | } | 958 | } |
938 | 959 | ||
939 | static void wm9713_voiceshutdown(struct snd_pcm_substream *substream, | ||
940 | struct snd_soc_dai *dai) | ||
941 | { | ||
942 | struct snd_soc_codec *codec = dai->codec; | ||
943 | u16 status, rate; | ||
944 | |||
945 | /* Gracefully shut down the voice interface. */ | ||
946 | status = ac97_read(codec, AC97_EXTENDED_STATUS) | 0x1000; | ||
947 | rate = ac97_read(codec, AC97_HANDSET_RATE) & 0xF0FF; | ||
948 | ac97_write(codec, AC97_HANDSET_RATE, rate | 0x0200); | ||
949 | schedule_timeout_interruptible(msecs_to_jiffies(1)); | ||
950 | ac97_write(codec, AC97_HANDSET_RATE, rate | 0x0F00); | ||
951 | ac97_write(codec, AC97_EXTENDED_MID, status); | ||
952 | } | ||
953 | |||
954 | static int ac97_hifi_prepare(struct snd_pcm_substream *substream, | 960 | static int ac97_hifi_prepare(struct snd_pcm_substream *substream, |
955 | struct snd_soc_dai *dai) | 961 | struct snd_soc_dai *dai) |
956 | { | 962 | { |
@@ -1019,7 +1025,6 @@ static struct snd_soc_dai_ops wm9713_dai_ops_aux = { | |||
1019 | 1025 | ||
1020 | static struct snd_soc_dai_ops wm9713_dai_ops_voice = { | 1026 | static struct snd_soc_dai_ops wm9713_dai_ops_voice = { |
1021 | .hw_params = wm9713_pcm_hw_params, | 1027 | .hw_params = wm9713_pcm_hw_params, |
1022 | .shutdown = wm9713_voiceshutdown, | ||
1023 | .set_clkdiv = wm9713_set_dai_clkdiv, | 1028 | .set_clkdiv = wm9713_set_dai_clkdiv, |
1024 | .set_pll = wm9713_set_dai_pll, | 1029 | .set_pll = wm9713_set_dai_pll, |
1025 | .set_fmt = wm9713_set_dai_fmt, | 1030 | .set_fmt = wm9713_set_dai_fmt, |
@@ -1035,13 +1040,13 @@ struct snd_soc_dai wm9713_dai[] = { | |||
1035 | .channels_min = 1, | 1040 | .channels_min = 1, |
1036 | .channels_max = 2, | 1041 | .channels_max = 2, |
1037 | .rates = WM9713_RATES, | 1042 | .rates = WM9713_RATES, |
1038 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 1043 | .formats = SND_SOC_STD_AC97_FMTS,}, |
1039 | .capture = { | 1044 | .capture = { |
1040 | .stream_name = "HiFi Capture", | 1045 | .stream_name = "HiFi Capture", |
1041 | .channels_min = 1, | 1046 | .channels_min = 1, |
1042 | .channels_max = 2, | 1047 | .channels_max = 2, |
1043 | .rates = WM9713_RATES, | 1048 | .rates = WM9713_RATES, |
1044 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 1049 | .formats = SND_SOC_STD_AC97_FMTS,}, |
1045 | .ops = &wm9713_dai_ops_hifi, | 1050 | .ops = &wm9713_dai_ops_hifi, |
1046 | }, | 1051 | }, |
1047 | { | 1052 | { |
@@ -1051,7 +1056,7 @@ struct snd_soc_dai wm9713_dai[] = { | |||
1051 | .channels_min = 1, | 1056 | .channels_min = 1, |
1052 | .channels_max = 1, | 1057 | .channels_max = 1, |
1053 | .rates = WM9713_RATES, | 1058 | .rates = WM9713_RATES, |
1054 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 1059 | .formats = SND_SOC_STD_AC97_FMTS,}, |
1055 | .ops = &wm9713_dai_ops_aux, | 1060 | .ops = &wm9713_dai_ops_aux, |
1056 | }, | 1061 | }, |
1057 | { | 1062 | { |
@@ -1069,6 +1074,7 @@ struct snd_soc_dai wm9713_dai[] = { | |||
1069 | .rates = WM9713_PCM_RATES, | 1074 | .rates = WM9713_PCM_RATES, |
1070 | .formats = WM9713_PCM_FORMATS,}, | 1075 | .formats = WM9713_PCM_FORMATS,}, |
1071 | .ops = &wm9713_dai_ops_voice, | 1076 | .ops = &wm9713_dai_ops_voice, |
1077 | .symmetric_rates = 1, | ||
1072 | }, | 1078 | }, |
1073 | }; | 1079 | }; |
1074 | EXPORT_SYMBOL_GPL(wm9713_dai); | 1080 | EXPORT_SYMBOL_GPL(wm9713_dai); |
diff --git a/sound/soc/omap/n810.c b/sound/soc/omap/n810.c index 91ef17992de5..b60b1dfbc435 100644 --- a/sound/soc/omap/n810.c +++ b/sound/soc/omap/n810.c | |||
@@ -383,10 +383,9 @@ static int __init n810_soc_init(void) | |||
383 | clk_set_parent(sys_clkout2_src, func96m_clk); | 383 | clk_set_parent(sys_clkout2_src, func96m_clk); |
384 | clk_set_rate(sys_clkout2, 12000000); | 384 | clk_set_rate(sys_clkout2, 12000000); |
385 | 385 | ||
386 | if (gpio_request(N810_HEADSET_AMP_GPIO, "hs_amp") < 0) | 386 | BUG_ON((gpio_request(N810_HEADSET_AMP_GPIO, "hs_amp") < 0) || |
387 | BUG(); | 387 | (gpio_request(N810_SPEAKER_AMP_GPIO, "spk_amp") < 0)); |
388 | if (gpio_request(N810_SPEAKER_AMP_GPIO, "spk_amp") < 0) | 388 | |
389 | BUG(); | ||
390 | gpio_direction_output(N810_HEADSET_AMP_GPIO, 0); | 389 | gpio_direction_output(N810_HEADSET_AMP_GPIO, 0); |
391 | gpio_direction_output(N810_SPEAKER_AMP_GPIO, 0); | 390 | gpio_direction_output(N810_SPEAKER_AMP_GPIO, 0); |
392 | 391 | ||
diff --git a/sound/soc/omap/omap-mcbsp.c b/sound/soc/omap/omap-mcbsp.c index 912614283848..a5d46a7b196a 100644 --- a/sound/soc/omap/omap-mcbsp.c +++ b/sound/soc/omap/omap-mcbsp.c | |||
@@ -215,8 +215,9 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream, | |||
215 | struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data); | 215 | struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data); |
216 | struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs; | 216 | struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs; |
217 | int dma, bus_id = mcbsp_data->bus_id, id = cpu_dai->id; | 217 | int dma, bus_id = mcbsp_data->bus_id, id = cpu_dai->id; |
218 | int wlen, channels; | 218 | int wlen, channels, wpf; |
219 | unsigned long port; | 219 | unsigned long port; |
220 | unsigned int format; | ||
220 | 221 | ||
221 | if (cpu_class_is_omap1()) { | 222 | if (cpu_class_is_omap1()) { |
222 | dma = omap1_dma_reqs[bus_id][substream->stream]; | 223 | dma = omap1_dma_reqs[bus_id][substream->stream]; |
@@ -244,18 +245,24 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream, | |||
244 | return 0; | 245 | return 0; |
245 | } | 246 | } |
246 | 247 | ||
247 | channels = params_channels(params); | 248 | format = mcbsp_data->fmt & SND_SOC_DAIFMT_FORMAT_MASK; |
249 | wpf = channels = params_channels(params); | ||
248 | switch (channels) { | 250 | switch (channels) { |
249 | case 2: | 251 | case 2: |
250 | /* Use dual-phase frames */ | 252 | if (format == SND_SOC_DAIFMT_I2S) { |
251 | regs->rcr2 |= RPHASE; | 253 | /* Use dual-phase frames */ |
252 | regs->xcr2 |= XPHASE; | 254 | regs->rcr2 |= RPHASE; |
255 | regs->xcr2 |= XPHASE; | ||
256 | /* Set 1 word per (McBSP) frame for phase1 and phase2 */ | ||
257 | wpf--; | ||
258 | regs->rcr2 |= RFRLEN2(wpf - 1); | ||
259 | regs->xcr2 |= XFRLEN2(wpf - 1); | ||
260 | } | ||
253 | case 1: | 261 | case 1: |
254 | /* Set 1 word per (McBSP) frame */ | 262 | case 4: |
255 | regs->rcr2 |= RFRLEN2(1 - 1); | 263 | /* Set word per (McBSP) frame for phase1 */ |
256 | regs->rcr1 |= RFRLEN1(1 - 1); | 264 | regs->rcr1 |= RFRLEN1(wpf - 1); |
257 | regs->xcr2 |= XFRLEN2(1 - 1); | 265 | regs->xcr1 |= XFRLEN1(wpf - 1); |
258 | regs->xcr1 |= XFRLEN1(1 - 1); | ||
259 | break; | 266 | break; |
260 | default: | 267 | default: |
261 | /* Unsupported number of channels */ | 268 | /* Unsupported number of channels */ |
@@ -277,11 +284,12 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream, | |||
277 | } | 284 | } |
278 | 285 | ||
279 | /* Set FS period and length in terms of bit clock periods */ | 286 | /* Set FS period and length in terms of bit clock periods */ |
280 | switch (mcbsp_data->fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | 287 | switch (format) { |
281 | case SND_SOC_DAIFMT_I2S: | 288 | case SND_SOC_DAIFMT_I2S: |
282 | regs->srgr2 |= FPER(wlen * 2 - 1); | 289 | regs->srgr2 |= FPER(wlen * channels - 1); |
283 | regs->srgr1 |= FWID(wlen - 1); | 290 | regs->srgr1 |= FWID(wlen - 1); |
284 | break; | 291 | break; |
292 | case SND_SOC_DAIFMT_DSP_A: | ||
285 | case SND_SOC_DAIFMT_DSP_B: | 293 | case SND_SOC_DAIFMT_DSP_B: |
286 | regs->srgr2 |= FPER(wlen * channels - 1); | 294 | regs->srgr2 |= FPER(wlen * channels - 1); |
287 | regs->srgr1 |= FWID(0); | 295 | regs->srgr1 |= FWID(0); |
@@ -326,6 +334,13 @@ static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai, | |||
326 | regs->rcr2 |= RDATDLY(1); | 334 | regs->rcr2 |= RDATDLY(1); |
327 | regs->xcr2 |= XDATDLY(1); | 335 | regs->xcr2 |= XDATDLY(1); |
328 | break; | 336 | break; |
337 | case SND_SOC_DAIFMT_DSP_A: | ||
338 | /* 1-bit data delay */ | ||
339 | regs->rcr2 |= RDATDLY(1); | ||
340 | regs->xcr2 |= XDATDLY(1); | ||
341 | /* Invert FS polarity configuration */ | ||
342 | temp_fmt ^= SND_SOC_DAIFMT_NB_IF; | ||
343 | break; | ||
329 | case SND_SOC_DAIFMT_DSP_B: | 344 | case SND_SOC_DAIFMT_DSP_B: |
330 | /* 0-bit data delay */ | 345 | /* 0-bit data delay */ |
331 | regs->rcr2 |= RDATDLY(0); | 346 | regs->rcr2 |= RDATDLY(0); |
@@ -492,13 +507,13 @@ static struct snd_soc_dai_ops omap_mcbsp_dai_ops = { | |||
492 | .id = (link_id), \ | 507 | .id = (link_id), \ |
493 | .playback = { \ | 508 | .playback = { \ |
494 | .channels_min = 1, \ | 509 | .channels_min = 1, \ |
495 | .channels_max = 2, \ | 510 | .channels_max = 4, \ |
496 | .rates = OMAP_MCBSP_RATES, \ | 511 | .rates = OMAP_MCBSP_RATES, \ |
497 | .formats = SNDRV_PCM_FMTBIT_S16_LE, \ | 512 | .formats = SNDRV_PCM_FMTBIT_S16_LE, \ |
498 | }, \ | 513 | }, \ |
499 | .capture = { \ | 514 | .capture = { \ |
500 | .channels_min = 1, \ | 515 | .channels_min = 1, \ |
501 | .channels_max = 2, \ | 516 | .channels_max = 4, \ |
502 | .rates = OMAP_MCBSP_RATES, \ | 517 | .rates = OMAP_MCBSP_RATES, \ |
503 | .formats = SNDRV_PCM_FMTBIT_S16_LE, \ | 518 | .formats = SNDRV_PCM_FMTBIT_S16_LE, \ |
504 | }, \ | 519 | }, \ |
diff --git a/sound/soc/omap/omap-pcm.c b/sound/soc/omap/omap-pcm.c index 07cf7f46b584..6454e15f7d28 100644 --- a/sound/soc/omap/omap-pcm.c +++ b/sound/soc/omap/omap-pcm.c | |||
@@ -87,8 +87,10 @@ static int omap_pcm_hw_params(struct snd_pcm_substream *substream, | |||
87 | struct omap_pcm_dma_data *dma_data = rtd->dai->cpu_dai->dma_data; | 87 | struct omap_pcm_dma_data *dma_data = rtd->dai->cpu_dai->dma_data; |
88 | int err = 0; | 88 | int err = 0; |
89 | 89 | ||
90 | /* return if this is a bufferless transfer e.g. | ||
91 | * codec <--> BT codec or GSM modem -- lg FIXME */ | ||
90 | if (!dma_data) | 92 | if (!dma_data) |
91 | return -ENODEV; | 93 | return 0; |
92 | 94 | ||
93 | snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); | 95 | snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); |
94 | runtime->dma_bytes = params_buffer_bytes(params); | 96 | runtime->dma_bytes = params_buffer_bytes(params); |
@@ -134,6 +136,11 @@ static int omap_pcm_prepare(struct snd_pcm_substream *substream) | |||
134 | struct omap_pcm_dma_data *dma_data = prtd->dma_data; | 136 | struct omap_pcm_dma_data *dma_data = prtd->dma_data; |
135 | struct omap_dma_channel_params dma_params; | 137 | struct omap_dma_channel_params dma_params; |
136 | 138 | ||
139 | /* return if this is a bufferless transfer e.g. | ||
140 | * codec <--> BT codec or GSM modem -- lg FIXME */ | ||
141 | if (!prtd->dma_data) | ||
142 | return 0; | ||
143 | |||
137 | memset(&dma_params, 0, sizeof(dma_params)); | 144 | memset(&dma_params, 0, sizeof(dma_params)); |
138 | /* | 145 | /* |
139 | * Note: Regardless of interface data formats supported by OMAP McBSP | 146 | * Note: Regardless of interface data formats supported by OMAP McBSP |
diff --git a/sound/soc/omap/omap2evm.c b/sound/soc/omap/omap2evm.c index 0c2322dcf02a..027e1a40f8a1 100644 --- a/sound/soc/omap/omap2evm.c +++ b/sound/soc/omap/omap2evm.c | |||
@@ -86,7 +86,7 @@ static struct snd_soc_dai_link omap2evm_dai = { | |||
86 | .name = "TWL4030", | 86 | .name = "TWL4030", |
87 | .stream_name = "TWL4030", | 87 | .stream_name = "TWL4030", |
88 | .cpu_dai = &omap_mcbsp_dai[0], | 88 | .cpu_dai = &omap_mcbsp_dai[0], |
89 | .codec_dai = &twl4030_dai, | 89 | .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI], |
90 | .ops = &omap2evm_ops, | 90 | .ops = &omap2evm_ops, |
91 | }; | 91 | }; |
92 | 92 | ||
diff --git a/sound/soc/omap/omap3beagle.c b/sound/soc/omap/omap3beagle.c index fd24a4acd2f5..b0cff9f33b7e 100644 --- a/sound/soc/omap/omap3beagle.c +++ b/sound/soc/omap/omap3beagle.c | |||
@@ -41,23 +41,33 @@ static int omap3beagle_hw_params(struct snd_pcm_substream *substream, | |||
41 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 41 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
42 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; | 42 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; |
43 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | 43 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; |
44 | unsigned int fmt; | ||
44 | int ret; | 45 | int ret; |
45 | 46 | ||
47 | switch (params_channels(params)) { | ||
48 | case 2: /* Stereo I2S mode */ | ||
49 | fmt = SND_SOC_DAIFMT_I2S | | ||
50 | SND_SOC_DAIFMT_NB_NF | | ||
51 | SND_SOC_DAIFMT_CBM_CFM; | ||
52 | break; | ||
53 | case 4: /* Four channel TDM mode */ | ||
54 | fmt = SND_SOC_DAIFMT_DSP_A | | ||
55 | SND_SOC_DAIFMT_IB_NF | | ||
56 | SND_SOC_DAIFMT_CBM_CFM; | ||
57 | break; | ||
58 | default: | ||
59 | return -EINVAL; | ||
60 | } | ||
61 | |||
46 | /* Set codec DAI configuration */ | 62 | /* Set codec DAI configuration */ |
47 | ret = snd_soc_dai_set_fmt(codec_dai, | 63 | ret = snd_soc_dai_set_fmt(codec_dai, fmt); |
48 | SND_SOC_DAIFMT_I2S | | ||
49 | SND_SOC_DAIFMT_NB_NF | | ||
50 | SND_SOC_DAIFMT_CBM_CFM); | ||
51 | if (ret < 0) { | 64 | if (ret < 0) { |
52 | printk(KERN_ERR "can't set codec DAI configuration\n"); | 65 | printk(KERN_ERR "can't set codec DAI configuration\n"); |
53 | return ret; | 66 | return ret; |
54 | } | 67 | } |
55 | 68 | ||
56 | /* Set cpu DAI configuration */ | 69 | /* Set cpu DAI configuration */ |
57 | ret = snd_soc_dai_set_fmt(cpu_dai, | 70 | ret = snd_soc_dai_set_fmt(cpu_dai, fmt); |
58 | SND_SOC_DAIFMT_I2S | | ||
59 | SND_SOC_DAIFMT_NB_NF | | ||
60 | SND_SOC_DAIFMT_CBM_CFM); | ||
61 | if (ret < 0) { | 71 | if (ret < 0) { |
62 | printk(KERN_ERR "can't set cpu DAI configuration\n"); | 72 | printk(KERN_ERR "can't set cpu DAI configuration\n"); |
63 | return ret; | 73 | return ret; |
@@ -83,7 +93,7 @@ static struct snd_soc_dai_link omap3beagle_dai = { | |||
83 | .name = "TWL4030", | 93 | .name = "TWL4030", |
84 | .stream_name = "TWL4030", | 94 | .stream_name = "TWL4030", |
85 | .cpu_dai = &omap_mcbsp_dai[0], | 95 | .cpu_dai = &omap_mcbsp_dai[0], |
86 | .codec_dai = &twl4030_dai, | 96 | .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI], |
87 | .ops = &omap3beagle_ops, | 97 | .ops = &omap3beagle_ops, |
88 | }; | 98 | }; |
89 | 99 | ||
diff --git a/sound/soc/omap/omap3pandora.c b/sound/soc/omap/omap3pandora.c index fe282d4ef422..ad219aaf7cb8 100644 --- a/sound/soc/omap/omap3pandora.c +++ b/sound/soc/omap/omap3pandora.c | |||
@@ -228,14 +228,14 @@ static struct snd_soc_dai_link omap3pandora_dai[] = { | |||
228 | .name = "PCM1773", | 228 | .name = "PCM1773", |
229 | .stream_name = "HiFi Out", | 229 | .stream_name = "HiFi Out", |
230 | .cpu_dai = &omap_mcbsp_dai[0], | 230 | .cpu_dai = &omap_mcbsp_dai[0], |
231 | .codec_dai = &twl4030_dai, | 231 | .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI], |
232 | .ops = &omap3pandora_out_ops, | 232 | .ops = &omap3pandora_out_ops, |
233 | .init = omap3pandora_out_init, | 233 | .init = omap3pandora_out_init, |
234 | }, { | 234 | }, { |
235 | .name = "TWL4030", | 235 | .name = "TWL4030", |
236 | .stream_name = "Line/Mic In", | 236 | .stream_name = "Line/Mic In", |
237 | .cpu_dai = &omap_mcbsp_dai[1], | 237 | .cpu_dai = &omap_mcbsp_dai[1], |
238 | .codec_dai = &twl4030_dai, | 238 | .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI], |
239 | .ops = &omap3pandora_in_ops, | 239 | .ops = &omap3pandora_in_ops, |
240 | .init = omap3pandora_in_init, | 240 | .init = omap3pandora_in_init, |
241 | } | 241 | } |
diff --git a/sound/soc/omap/overo.c b/sound/soc/omap/overo.c index a72dc4e159e5..ec4f8fd8b3a2 100644 --- a/sound/soc/omap/overo.c +++ b/sound/soc/omap/overo.c | |||
@@ -83,7 +83,7 @@ static struct snd_soc_dai_link overo_dai = { | |||
83 | .name = "TWL4030", | 83 | .name = "TWL4030", |
84 | .stream_name = "TWL4030", | 84 | .stream_name = "TWL4030", |
85 | .cpu_dai = &omap_mcbsp_dai[0], | 85 | .cpu_dai = &omap_mcbsp_dai[0], |
86 | .codec_dai = &twl4030_dai, | 86 | .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI], |
87 | .ops = &overo_ops, | 87 | .ops = &overo_ops, |
88 | }; | 88 | }; |
89 | 89 | ||
diff --git a/sound/soc/omap/sdp3430.c b/sound/soc/omap/sdp3430.c index 10f1c867f11d..1c7974101a0b 100644 --- a/sound/soc/omap/sdp3430.c +++ b/sound/soc/omap/sdp3430.c | |||
@@ -197,7 +197,7 @@ static struct snd_soc_dai_link sdp3430_dai = { | |||
197 | .name = "TWL4030", | 197 | .name = "TWL4030", |
198 | .stream_name = "TWL4030", | 198 | .stream_name = "TWL4030", |
199 | .cpu_dai = &omap_mcbsp_dai[0], | 199 | .cpu_dai = &omap_mcbsp_dai[0], |
200 | .codec_dai = &twl4030_dai, | 200 | .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI], |
201 | .init = sdp3430_twl4030_init, | 201 | .init = sdp3430_twl4030_init, |
202 | .ops = &sdp3430_ops, | 202 | .ops = &sdp3430_ops, |
203 | }; | 203 | }; |
diff --git a/sound/soc/pxa/Kconfig b/sound/soc/pxa/Kconfig index ad8a10fe6298..dcd163a4ee9a 100644 --- a/sound/soc/pxa/Kconfig +++ b/sound/soc/pxa/Kconfig | |||
@@ -89,13 +89,13 @@ config SND_PXA2XX_SOC_E800 | |||
89 | Toshiba e800 PDA | 89 | Toshiba e800 PDA |
90 | 90 | ||
91 | config SND_PXA2XX_SOC_EM_X270 | 91 | config SND_PXA2XX_SOC_EM_X270 |
92 | tristate "SoC Audio support for CompuLab EM-x270" | 92 | tristate "SoC Audio support for CompuLab EM-x270, eXeda and CM-X300" |
93 | depends on SND_PXA2XX_SOC && MACH_EM_X270 | 93 | depends on SND_PXA2XX_SOC && MACH_EM_X270 |
94 | select SND_PXA2XX_SOC_AC97 | 94 | select SND_PXA2XX_SOC_AC97 |
95 | select SND_SOC_WM9712 | 95 | select SND_SOC_WM9712 |
96 | help | 96 | help |
97 | Say Y if you want to add support for SoC audio on | 97 | Say Y if you want to add support for SoC audio on |
98 | CompuLab EM-x270. | 98 | CompuLab EM-x270, eXeda and CM-X300 machines. |
99 | 99 | ||
100 | config SND_PXA2XX_SOC_PALM27X | 100 | config SND_PXA2XX_SOC_PALM27X |
101 | bool "SoC Audio support for Palm T|X, T5 and LifeDrive" | 101 | bool "SoC Audio support for Palm T|X, T5 and LifeDrive" |
@@ -134,3 +134,12 @@ config SND_PXA2XX_SOC_MIOA701 | |||
134 | help | 134 | help |
135 | Say Y if you want to add support for SoC audio on the | 135 | Say Y if you want to add support for SoC audio on the |
136 | MIO A701. | 136 | MIO A701. |
137 | |||
138 | config SND_PXA2XX_SOC_IMOTE2 | ||
139 | tristate "SoC Audio support for IMote 2" | ||
140 | depends on SND_PXA2XX_SOC && MACH_INTELMOTE2 | ||
141 | select SND_PXA2XX_SOC_I2S | ||
142 | select SND_SOC_WM8940 | ||
143 | help | ||
144 | Say Y if you want to add support for SoC audio on the | ||
145 | IMote 2. | ||
diff --git a/sound/soc/pxa/Makefile b/sound/soc/pxa/Makefile index 4b90c3ccae45..6e096b480335 100644 --- a/sound/soc/pxa/Makefile +++ b/sound/soc/pxa/Makefile | |||
@@ -22,6 +22,7 @@ snd-soc-palm27x-objs := palm27x.o | |||
22 | snd-soc-zylonite-objs := zylonite.o | 22 | snd-soc-zylonite-objs := zylonite.o |
23 | snd-soc-magician-objs := magician.o | 23 | snd-soc-magician-objs := magician.o |
24 | snd-soc-mioa701-objs := mioa701_wm9713.o | 24 | snd-soc-mioa701-objs := mioa701_wm9713.o |
25 | snd-soc-imote2-objs := imote2.o | ||
25 | 26 | ||
26 | obj-$(CONFIG_SND_PXA2XX_SOC_CORGI) += snd-soc-corgi.o | 27 | obj-$(CONFIG_SND_PXA2XX_SOC_CORGI) += snd-soc-corgi.o |
27 | obj-$(CONFIG_SND_PXA2XX_SOC_POODLE) += snd-soc-poodle.o | 28 | obj-$(CONFIG_SND_PXA2XX_SOC_POODLE) += snd-soc-poodle.o |
@@ -35,3 +36,4 @@ obj-$(CONFIG_SND_PXA2XX_SOC_PALM27X) += snd-soc-palm27x.o | |||
35 | obj-$(CONFIG_SND_PXA2XX_SOC_MAGICIAN) += snd-soc-magician.o | 36 | obj-$(CONFIG_SND_PXA2XX_SOC_MAGICIAN) += snd-soc-magician.o |
36 | obj-$(CONFIG_SND_PXA2XX_SOC_MIOA701) += snd-soc-mioa701.o | 37 | obj-$(CONFIG_SND_PXA2XX_SOC_MIOA701) += snd-soc-mioa701.o |
37 | obj-$(CONFIG_SND_SOC_ZYLONITE) += snd-soc-zylonite.o | 38 | obj-$(CONFIG_SND_SOC_ZYLONITE) += snd-soc-zylonite.o |
39 | obj-$(CONFIG_SND_PXA2XX_SOC_IMOTE2) += snd-soc-imote2.o | ||
diff --git a/sound/soc/pxa/em-x270.c b/sound/soc/pxa/em-x270.c index 949be9c2a01b..f4756e4025fd 100644 --- a/sound/soc/pxa/em-x270.c +++ b/sound/soc/pxa/em-x270.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * em-x270.c -- SoC audio for EM-X270 | 2 | * SoC audio driver for EM-X270, eXeda and CM-X300 |
3 | * | 3 | * |
4 | * Copyright 2007 CompuLab, Ltd. | 4 | * Copyright 2007, 2009 CompuLab, Ltd. |
5 | * | 5 | * |
6 | * Author: Mike Rapoport <mike@compulab.co.il> | 6 | * Author: Mike Rapoport <mike@compulab.co.il> |
7 | * | 7 | * |
@@ -68,7 +68,8 @@ static int __init em_x270_init(void) | |||
68 | { | 68 | { |
69 | int ret; | 69 | int ret; |
70 | 70 | ||
71 | if (!machine_is_em_x270()) | 71 | if (!(machine_is_em_x270() || machine_is_exeda() |
72 | || machine_is_cm_x300())) | ||
72 | return -ENODEV; | 73 | return -ENODEV; |
73 | 74 | ||
74 | em_x270_snd_device = platform_device_alloc("soc-audio", -1); | 75 | em_x270_snd_device = platform_device_alloc("soc-audio", -1); |
@@ -95,5 +96,5 @@ module_exit(em_x270_exit); | |||
95 | 96 | ||
96 | /* Module information */ | 97 | /* Module information */ |
97 | MODULE_AUTHOR("Mike Rapoport"); | 98 | MODULE_AUTHOR("Mike Rapoport"); |
98 | MODULE_DESCRIPTION("ALSA SoC EM-X270"); | 99 | MODULE_DESCRIPTION("ALSA SoC EM-X270, eXeda and CM-X300"); |
99 | MODULE_LICENSE("GPL"); | 100 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/pxa/imote2.c b/sound/soc/pxa/imote2.c new file mode 100644 index 000000000000..405587a01160 --- /dev/null +++ b/sound/soc/pxa/imote2.c | |||
@@ -0,0 +1,114 @@ | |||
1 | |||
2 | #include <linux/module.h> | ||
3 | #include <sound/soc.h> | ||
4 | |||
5 | #include <asm/mach-types.h> | ||
6 | |||
7 | #include "../codecs/wm8940.h" | ||
8 | #include "pxa2xx-i2s.h" | ||
9 | #include "pxa2xx-pcm.h" | ||
10 | |||
11 | static int imote2_asoc_hw_params(struct snd_pcm_substream *substream, | ||
12 | struct snd_pcm_hw_params *params) | ||
13 | { | ||
14 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
15 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; | ||
16 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | ||
17 | unsigned int clk = 0; | ||
18 | int ret; | ||
19 | |||
20 | switch (params_rate(params)) { | ||
21 | case 8000: | ||
22 | case 16000: | ||
23 | case 48000: | ||
24 | case 96000: | ||
25 | clk = 12288000; | ||
26 | break; | ||
27 | case 11025: | ||
28 | case 22050: | ||
29 | case 44100: | ||
30 | clk = 11289600; | ||
31 | break; | ||
32 | } | ||
33 | |||
34 | /* set codec DAI configuration */ | ||
35 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | ||
36 | | SND_SOC_DAIFMT_NB_NF | ||
37 | | SND_SOC_DAIFMT_CBS_CFS); | ||
38 | if (ret < 0) | ||
39 | return ret; | ||
40 | |||
41 | /* CPU should be clock master */ | ||
42 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | ||
43 | | SND_SOC_DAIFMT_NB_NF | ||
44 | | SND_SOC_DAIFMT_CBS_CFS); | ||
45 | if (ret < 0) | ||
46 | return ret; | ||
47 | |||
48 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, clk, | ||
49 | SND_SOC_CLOCK_IN); | ||
50 | if (ret < 0) | ||
51 | return ret; | ||
52 | |||
53 | /* set the I2S system clock as input (unused) */ | ||
54 | ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, clk, | ||
55 | SND_SOC_CLOCK_OUT); | ||
56 | |||
57 | return ret; | ||
58 | } | ||
59 | |||
60 | static struct snd_soc_ops imote2_asoc_ops = { | ||
61 | .hw_params = imote2_asoc_hw_params, | ||
62 | }; | ||
63 | |||
64 | static struct snd_soc_dai_link imote2_dai = { | ||
65 | .name = "WM8940", | ||
66 | .stream_name = "WM8940", | ||
67 | .cpu_dai = &pxa_i2s_dai, | ||
68 | .codec_dai = &wm8940_dai, | ||
69 | .ops = &imote2_asoc_ops, | ||
70 | }; | ||
71 | |||
72 | static struct snd_soc_card snd_soc_imote2 = { | ||
73 | .name = "Imote2", | ||
74 | .platform = &pxa2xx_soc_platform, | ||
75 | .dai_link = &imote2_dai, | ||
76 | .num_links = 1, | ||
77 | }; | ||
78 | |||
79 | static struct snd_soc_device imote2_snd_devdata = { | ||
80 | .card = &snd_soc_imote2, | ||
81 | .codec_dev = &soc_codec_dev_wm8940, | ||
82 | }; | ||
83 | |||
84 | static struct platform_device *imote2_snd_device; | ||
85 | |||
86 | static int __init imote2_asoc_init(void) | ||
87 | { | ||
88 | int ret; | ||
89 | |||
90 | if (!machine_is_intelmote2()) | ||
91 | return -ENODEV; | ||
92 | imote2_snd_device = platform_device_alloc("soc-audio", -1); | ||
93 | if (!imote2_snd_device) | ||
94 | return -ENOMEM; | ||
95 | |||
96 | platform_set_drvdata(imote2_snd_device, &imote2_snd_devdata); | ||
97 | imote2_snd_devdata.dev = &imote2_snd_device->dev; | ||
98 | ret = platform_device_add(imote2_snd_device); | ||
99 | if (ret) | ||
100 | platform_device_put(imote2_snd_device); | ||
101 | |||
102 | return ret; | ||
103 | } | ||
104 | module_init(imote2_asoc_init); | ||
105 | |||
106 | static void __exit imote2_asoc_exit(void) | ||
107 | { | ||
108 | platform_device_unregister(imote2_snd_device); | ||
109 | } | ||
110 | module_exit(imote2_asoc_exit); | ||
111 | |||
112 | MODULE_AUTHOR("Jonathan Cameron"); | ||
113 | MODULE_DESCRIPTION("ALSA SoC Imote 2"); | ||
114 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/pxa/pxa-ssp.c b/sound/soc/pxa/pxa-ssp.c index 286be31545df..6fc787610ad7 100644 --- a/sound/soc/pxa/pxa-ssp.c +++ b/sound/soc/pxa/pxa-ssp.c | |||
@@ -50,139 +50,6 @@ struct ssp_priv { | |||
50 | #endif | 50 | #endif |
51 | }; | 51 | }; |
52 | 52 | ||
53 | #define PXA2xx_SSP1_BASE 0x41000000 | ||
54 | #define PXA27x_SSP2_BASE 0x41700000 | ||
55 | #define PXA27x_SSP3_BASE 0x41900000 | ||
56 | #define PXA3xx_SSP4_BASE 0x41a00000 | ||
57 | |||
58 | static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_mono_out = { | ||
59 | .name = "SSP1 PCM Mono out", | ||
60 | .dev_addr = PXA2xx_SSP1_BASE + SSDR, | ||
61 | .drcmr = &DRCMR(14), | ||
62 | .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG | | ||
63 | DCMD_BURST16 | DCMD_WIDTH2, | ||
64 | }; | ||
65 | |||
66 | static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_mono_in = { | ||
67 | .name = "SSP1 PCM Mono in", | ||
68 | .dev_addr = PXA2xx_SSP1_BASE + SSDR, | ||
69 | .drcmr = &DRCMR(13), | ||
70 | .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC | | ||
71 | DCMD_BURST16 | DCMD_WIDTH2, | ||
72 | }; | ||
73 | |||
74 | static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_stereo_out = { | ||
75 | .name = "SSP1 PCM Stereo out", | ||
76 | .dev_addr = PXA2xx_SSP1_BASE + SSDR, | ||
77 | .drcmr = &DRCMR(14), | ||
78 | .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG | | ||
79 | DCMD_BURST16 | DCMD_WIDTH4, | ||
80 | }; | ||
81 | |||
82 | static struct pxa2xx_pcm_dma_params pxa_ssp1_pcm_stereo_in = { | ||
83 | .name = "SSP1 PCM Stereo in", | ||
84 | .dev_addr = PXA2xx_SSP1_BASE + SSDR, | ||
85 | .drcmr = &DRCMR(13), | ||
86 | .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC | | ||
87 | DCMD_BURST16 | DCMD_WIDTH4, | ||
88 | }; | ||
89 | |||
90 | static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_mono_out = { | ||
91 | .name = "SSP2 PCM Mono out", | ||
92 | .dev_addr = PXA27x_SSP2_BASE + SSDR, | ||
93 | .drcmr = &DRCMR(16), | ||
94 | .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG | | ||
95 | DCMD_BURST16 | DCMD_WIDTH2, | ||
96 | }; | ||
97 | |||
98 | static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_mono_in = { | ||
99 | .name = "SSP2 PCM Mono in", | ||
100 | .dev_addr = PXA27x_SSP2_BASE + SSDR, | ||
101 | .drcmr = &DRCMR(15), | ||
102 | .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC | | ||
103 | DCMD_BURST16 | DCMD_WIDTH2, | ||
104 | }; | ||
105 | |||
106 | static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_stereo_out = { | ||
107 | .name = "SSP2 PCM Stereo out", | ||
108 | .dev_addr = PXA27x_SSP2_BASE + SSDR, | ||
109 | .drcmr = &DRCMR(16), | ||
110 | .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG | | ||
111 | DCMD_BURST16 | DCMD_WIDTH4, | ||
112 | }; | ||
113 | |||
114 | static struct pxa2xx_pcm_dma_params pxa_ssp2_pcm_stereo_in = { | ||
115 | .name = "SSP2 PCM Stereo in", | ||
116 | .dev_addr = PXA27x_SSP2_BASE + SSDR, | ||
117 | .drcmr = &DRCMR(15), | ||
118 | .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC | | ||
119 | DCMD_BURST16 | DCMD_WIDTH4, | ||
120 | }; | ||
121 | |||
122 | static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_mono_out = { | ||
123 | .name = "SSP3 PCM Mono out", | ||
124 | .dev_addr = PXA27x_SSP3_BASE + SSDR, | ||
125 | .drcmr = &DRCMR(67), | ||
126 | .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG | | ||
127 | DCMD_BURST16 | DCMD_WIDTH2, | ||
128 | }; | ||
129 | |||
130 | static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_mono_in = { | ||
131 | .name = "SSP3 PCM Mono in", | ||
132 | .dev_addr = PXA27x_SSP3_BASE + SSDR, | ||
133 | .drcmr = &DRCMR(66), | ||
134 | .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC | | ||
135 | DCMD_BURST16 | DCMD_WIDTH2, | ||
136 | }; | ||
137 | |||
138 | static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_stereo_out = { | ||
139 | .name = "SSP3 PCM Stereo out", | ||
140 | .dev_addr = PXA27x_SSP3_BASE + SSDR, | ||
141 | .drcmr = &DRCMR(67), | ||
142 | .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG | | ||
143 | DCMD_BURST16 | DCMD_WIDTH4, | ||
144 | }; | ||
145 | |||
146 | static struct pxa2xx_pcm_dma_params pxa_ssp3_pcm_stereo_in = { | ||
147 | .name = "SSP3 PCM Stereo in", | ||
148 | .dev_addr = PXA27x_SSP3_BASE + SSDR, | ||
149 | .drcmr = &DRCMR(66), | ||
150 | .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC | | ||
151 | DCMD_BURST16 | DCMD_WIDTH4, | ||
152 | }; | ||
153 | |||
154 | static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_mono_out = { | ||
155 | .name = "SSP4 PCM Mono out", | ||
156 | .dev_addr = PXA3xx_SSP4_BASE + SSDR, | ||
157 | .drcmr = &DRCMR(67), | ||
158 | .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG | | ||
159 | DCMD_BURST16 | DCMD_WIDTH2, | ||
160 | }; | ||
161 | |||
162 | static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_mono_in = { | ||
163 | .name = "SSP4 PCM Mono in", | ||
164 | .dev_addr = PXA3xx_SSP4_BASE + SSDR, | ||
165 | .drcmr = &DRCMR(66), | ||
166 | .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC | | ||
167 | DCMD_BURST16 | DCMD_WIDTH2, | ||
168 | }; | ||
169 | |||
170 | static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_stereo_out = { | ||
171 | .name = "SSP4 PCM Stereo out", | ||
172 | .dev_addr = PXA3xx_SSP4_BASE + SSDR, | ||
173 | .drcmr = &DRCMR(67), | ||
174 | .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG | | ||
175 | DCMD_BURST16 | DCMD_WIDTH4, | ||
176 | }; | ||
177 | |||
178 | static struct pxa2xx_pcm_dma_params pxa_ssp4_pcm_stereo_in = { | ||
179 | .name = "SSP4 PCM Stereo in", | ||
180 | .dev_addr = PXA3xx_SSP4_BASE + SSDR, | ||
181 | .drcmr = &DRCMR(66), | ||
182 | .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC | | ||
183 | DCMD_BURST16 | DCMD_WIDTH4, | ||
184 | }; | ||
185 | |||
186 | static void dump_registers(struct ssp_device *ssp) | 53 | static void dump_registers(struct ssp_device *ssp) |
187 | { | 54 | { |
188 | dev_dbg(&ssp->pdev->dev, "SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n", | 55 | dev_dbg(&ssp->pdev->dev, "SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n", |
@@ -194,25 +61,33 @@ static void dump_registers(struct ssp_device *ssp) | |||
194 | ssp_read_reg(ssp, SSACD)); | 61 | ssp_read_reg(ssp, SSACD)); |
195 | } | 62 | } |
196 | 63 | ||
197 | static struct pxa2xx_pcm_dma_params *ssp_dma_params[4][4] = { | 64 | struct pxa2xx_pcm_dma_data { |
198 | { | 65 | struct pxa2xx_pcm_dma_params params; |
199 | &pxa_ssp1_pcm_mono_out, &pxa_ssp1_pcm_mono_in, | 66 | char name[20]; |
200 | &pxa_ssp1_pcm_stereo_out, &pxa_ssp1_pcm_stereo_in, | ||
201 | }, | ||
202 | { | ||
203 | &pxa_ssp2_pcm_mono_out, &pxa_ssp2_pcm_mono_in, | ||
204 | &pxa_ssp2_pcm_stereo_out, &pxa_ssp2_pcm_stereo_in, | ||
205 | }, | ||
206 | { | ||
207 | &pxa_ssp3_pcm_mono_out, &pxa_ssp3_pcm_mono_in, | ||
208 | &pxa_ssp3_pcm_stereo_out, &pxa_ssp3_pcm_stereo_in, | ||
209 | }, | ||
210 | { | ||
211 | &pxa_ssp4_pcm_mono_out, &pxa_ssp4_pcm_mono_in, | ||
212 | &pxa_ssp4_pcm_stereo_out, &pxa_ssp4_pcm_stereo_in, | ||
213 | }, | ||
214 | }; | 67 | }; |
215 | 68 | ||
69 | static struct pxa2xx_pcm_dma_params * | ||
70 | ssp_get_dma_params(struct ssp_device *ssp, int width4, int out) | ||
71 | { | ||
72 | struct pxa2xx_pcm_dma_data *dma; | ||
73 | |||
74 | dma = kzalloc(sizeof(struct pxa2xx_pcm_dma_data), GFP_KERNEL); | ||
75 | if (dma == NULL) | ||
76 | return NULL; | ||
77 | |||
78 | snprintf(dma->name, 20, "SSP%d PCM %s %s", ssp->port_id, | ||
79 | width4 ? "32-bit" : "16-bit", out ? "out" : "in"); | ||
80 | |||
81 | dma->params.name = dma->name; | ||
82 | dma->params.drcmr = &DRCMR(out ? ssp->drcmr_tx : ssp->drcmr_rx); | ||
83 | dma->params.dcmd = (out ? (DCMD_INCSRCADDR | DCMD_FLOWTRG) : | ||
84 | (DCMD_INCTRGADDR | DCMD_FLOWSRC)) | | ||
85 | (width4 ? DCMD_WIDTH4 : DCMD_WIDTH2) | DCMD_BURST16; | ||
86 | dma->params.dev_addr = ssp->phys_base + SSDR; | ||
87 | |||
88 | return &dma->params; | ||
89 | } | ||
90 | |||
216 | static int pxa_ssp_startup(struct snd_pcm_substream *substream, | 91 | static int pxa_ssp_startup(struct snd_pcm_substream *substream, |
217 | struct snd_soc_dai *dai) | 92 | struct snd_soc_dai *dai) |
218 | { | 93 | { |
@@ -227,6 +102,11 @@ static int pxa_ssp_startup(struct snd_pcm_substream *substream, | |||
227 | clk_enable(priv->dev.ssp->clk); | 102 | clk_enable(priv->dev.ssp->clk); |
228 | ssp_disable(&priv->dev); | 103 | ssp_disable(&priv->dev); |
229 | } | 104 | } |
105 | |||
106 | if (cpu_dai->dma_data) { | ||
107 | kfree(cpu_dai->dma_data); | ||
108 | cpu_dai->dma_data = NULL; | ||
109 | } | ||
230 | return ret; | 110 | return ret; |
231 | } | 111 | } |
232 | 112 | ||
@@ -241,6 +121,11 @@ static void pxa_ssp_shutdown(struct snd_pcm_substream *substream, | |||
241 | ssp_disable(&priv->dev); | 121 | ssp_disable(&priv->dev); |
242 | clk_disable(priv->dev.ssp->clk); | 122 | clk_disable(priv->dev.ssp->clk); |
243 | } | 123 | } |
124 | |||
125 | if (cpu_dai->dma_data) { | ||
126 | kfree(cpu_dai->dma_data); | ||
127 | cpu_dai->dma_data = NULL; | ||
128 | } | ||
244 | } | 129 | } |
245 | 130 | ||
246 | #ifdef CONFIG_PM | 131 | #ifdef CONFIG_PM |
@@ -589,7 +474,10 @@ static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai, | |||
589 | case SND_SOC_DAIFMT_NB_IF: | 474 | case SND_SOC_DAIFMT_NB_IF: |
590 | break; | 475 | break; |
591 | case SND_SOC_DAIFMT_IB_IF: | 476 | case SND_SOC_DAIFMT_IB_IF: |
592 | sspsp |= SSPSP_SCMODE(3); | 477 | sspsp |= SSPSP_SCMODE(2); |
478 | break; | ||
479 | case SND_SOC_DAIFMT_IB_NF: | ||
480 | sspsp |= SSPSP_SCMODE(2) | SSPSP_SFRMP; | ||
593 | break; | 481 | break; |
594 | default: | 482 | default: |
595 | return -EINVAL; | 483 | return -EINVAL; |
@@ -606,7 +494,13 @@ static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai, | |||
606 | case SND_SOC_DAIFMT_NB_NF: | 494 | case SND_SOC_DAIFMT_NB_NF: |
607 | sspsp |= SSPSP_SFRMP; | 495 | sspsp |= SSPSP_SFRMP; |
608 | break; | 496 | break; |
497 | case SND_SOC_DAIFMT_NB_IF: | ||
498 | break; | ||
609 | case SND_SOC_DAIFMT_IB_IF: | 499 | case SND_SOC_DAIFMT_IB_IF: |
500 | sspsp |= SSPSP_SCMODE(2); | ||
501 | break; | ||
502 | case SND_SOC_DAIFMT_IB_NF: | ||
503 | sspsp |= SSPSP_SCMODE(2) | SSPSP_SFRMP; | ||
610 | break; | 504 | break; |
611 | default: | 505 | default: |
612 | return -EINVAL; | 506 | return -EINVAL; |
@@ -644,25 +538,23 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream, | |||
644 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | 538 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; |
645 | struct ssp_priv *priv = cpu_dai->private_data; | 539 | struct ssp_priv *priv = cpu_dai->private_data; |
646 | struct ssp_device *ssp = priv->dev.ssp; | 540 | struct ssp_device *ssp = priv->dev.ssp; |
647 | int dma = 0, chn = params_channels(params); | 541 | int chn = params_channels(params); |
648 | u32 sscr0; | 542 | u32 sscr0; |
649 | u32 sspsp; | 543 | u32 sspsp; |
650 | int width = snd_pcm_format_physical_width(params_format(params)); | 544 | int width = snd_pcm_format_physical_width(params_format(params)); |
651 | int ttsa = ssp_read_reg(ssp, SSTSA) & 0xf; | 545 | int ttsa = ssp_read_reg(ssp, SSTSA) & 0xf; |
652 | 546 | ||
653 | /* select correct DMA params */ | 547 | /* generate correct DMA params */ |
654 | if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) | 548 | if (cpu_dai->dma_data) |
655 | dma = 1; /* capture DMA offset is 1,3 */ | 549 | kfree(cpu_dai->dma_data); |
550 | |||
656 | /* Network mode with one active slot (ttsa == 1) can be used | 551 | /* Network mode with one active slot (ttsa == 1) can be used |
657 | * to force 16-bit frame width on the wire (for S16_LE), even | 552 | * to force 16-bit frame width on the wire (for S16_LE), even |
658 | * with two channels. Use 16-bit DMA transfers for this case. | 553 | * with two channels. Use 16-bit DMA transfers for this case. |
659 | */ | 554 | */ |
660 | if (((chn == 2) && (ttsa != 1)) || (width == 32)) | 555 | cpu_dai->dma_data = ssp_get_dma_params(ssp, |
661 | dma += 2; /* 32-bit DMA offset is 2, 16-bit is 0 */ | 556 | ((chn == 2) && (ttsa != 1)) || (width == 32), |
662 | 557 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK); | |
663 | cpu_dai->dma_data = ssp_dma_params[cpu_dai->id][dma]; | ||
664 | |||
665 | dev_dbg(&ssp->pdev->dev, "pxa_ssp_hw_params: dma %d\n", dma); | ||
666 | 558 | ||
667 | /* we can only change the settings if the port is not in use */ | 559 | /* we can only change the settings if the port is not in use */ |
668 | if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) | 560 | if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) |
diff --git a/sound/soc/pxa/pxa2xx-i2s.c b/sound/soc/pxa/pxa2xx-i2s.c index 2f4b6e489b78..60145770aeba 100644 --- a/sound/soc/pxa/pxa2xx-i2s.c +++ b/sound/soc/pxa/pxa2xx-i2s.c | |||
@@ -329,6 +329,7 @@ struct snd_soc_dai pxa_i2s_dai = { | |||
329 | .rates = PXA2XX_I2S_RATES, | 329 | .rates = PXA2XX_I2S_RATES, |
330 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 330 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
331 | .ops = &pxa_i2s_dai_ops, | 331 | .ops = &pxa_i2s_dai_ops, |
332 | .symmetric_rates = 1, | ||
332 | }; | 333 | }; |
333 | 334 | ||
334 | EXPORT_SYMBOL_GPL(pxa_i2s_dai); | 335 | EXPORT_SYMBOL_GPL(pxa_i2s_dai); |
diff --git a/sound/soc/s3c24xx/s3c-i2s-v2.c b/sound/soc/s3c24xx/s3c-i2s-v2.c index ab680aac3fcb..972c27684198 100644 --- a/sound/soc/s3c24xx/s3c-i2s-v2.c +++ b/sound/soc/s3c24xx/s3c-i2s-v2.c | |||
@@ -37,6 +37,20 @@ | |||
37 | 37 | ||
38 | #include "s3c-i2s-v2.h" | 38 | #include "s3c-i2s-v2.h" |
39 | 39 | ||
40 | #undef S3C_IIS_V2_SUPPORTED | ||
41 | |||
42 | #if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413) | ||
43 | #define S3C_IIS_V2_SUPPORTED | ||
44 | #endif | ||
45 | |||
46 | #ifdef CONFIG_PLAT_S3C64XX | ||
47 | #define S3C_IIS_V2_SUPPORTED | ||
48 | #endif | ||
49 | |||
50 | #ifndef S3C_IIS_V2_SUPPORTED | ||
51 | #error Unsupported CPU model | ||
52 | #endif | ||
53 | |||
40 | #define S3C2412_I2S_DEBUG_CON 0 | 54 | #define S3C2412_I2S_DEBUG_CON 0 |
41 | 55 | ||
42 | static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai) | 56 | static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai) |
@@ -75,7 +89,7 @@ static inline void dbg_showcon(const char *fn, u32 con) | |||
75 | 89 | ||
76 | 90 | ||
77 | /* Turn on or off the transmission path. */ | 91 | /* Turn on or off the transmission path. */ |
78 | void s3c2412_snd_txctrl(struct s3c_i2sv2_info *i2s, int on) | 92 | static void s3c2412_snd_txctrl(struct s3c_i2sv2_info *i2s, int on) |
79 | { | 93 | { |
80 | void __iomem *regs = i2s->regs; | 94 | void __iomem *regs = i2s->regs; |
81 | u32 fic, con, mod; | 95 | u32 fic, con, mod; |
@@ -105,7 +119,9 @@ void s3c2412_snd_txctrl(struct s3c_i2sv2_info *i2s, int on) | |||
105 | break; | 119 | break; |
106 | 120 | ||
107 | default: | 121 | default: |
108 | dev_err(i2s->dev, "TXEN: Invalid MODE in IISMOD\n"); | 122 | dev_err(i2s->dev, "TXEN: Invalid MODE %x in IISMOD\n", |
123 | mod & S3C2412_IISMOD_MODE_MASK); | ||
124 | break; | ||
109 | } | 125 | } |
110 | 126 | ||
111 | writel(con, regs + S3C2412_IISCON); | 127 | writel(con, regs + S3C2412_IISCON); |
@@ -132,7 +148,9 @@ void s3c2412_snd_txctrl(struct s3c_i2sv2_info *i2s, int on) | |||
132 | break; | 148 | break; |
133 | 149 | ||
134 | default: | 150 | default: |
135 | dev_err(i2s->dev, "TXDIS: Invalid MODE in IISMOD\n"); | 151 | dev_err(i2s->dev, "TXDIS: Invalid MODE %x in IISMOD\n", |
152 | mod & S3C2412_IISMOD_MODE_MASK); | ||
153 | break; | ||
136 | } | 154 | } |
137 | 155 | ||
138 | writel(mod, regs + S3C2412_IISMOD); | 156 | writel(mod, regs + S3C2412_IISMOD); |
@@ -143,9 +161,8 @@ void s3c2412_snd_txctrl(struct s3c_i2sv2_info *i2s, int on) | |||
143 | dbg_showcon(__func__, con); | 161 | dbg_showcon(__func__, con); |
144 | pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic); | 162 | pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic); |
145 | } | 163 | } |
146 | EXPORT_SYMBOL_GPL(s3c2412_snd_txctrl); | ||
147 | 164 | ||
148 | void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on) | 165 | static void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on) |
149 | { | 166 | { |
150 | void __iomem *regs = i2s->regs; | 167 | void __iomem *regs = i2s->regs; |
151 | u32 fic, con, mod; | 168 | u32 fic, con, mod; |
@@ -175,7 +192,8 @@ void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on) | |||
175 | break; | 192 | break; |
176 | 193 | ||
177 | default: | 194 | default: |
178 | dev_err(i2s->dev, "RXEN: Invalid MODE in IISMOD\n"); | 195 | dev_err(i2s->dev, "RXEN: Invalid MODE %x in IISMOD\n", |
196 | mod & S3C2412_IISMOD_MODE_MASK); | ||
179 | } | 197 | } |
180 | 198 | ||
181 | writel(mod, regs + S3C2412_IISMOD); | 199 | writel(mod, regs + S3C2412_IISMOD); |
@@ -199,7 +217,8 @@ void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on) | |||
199 | break; | 217 | break; |
200 | 218 | ||
201 | default: | 219 | default: |
202 | dev_err(i2s->dev, "RXEN: Invalid MODE in IISMOD\n"); | 220 | dev_err(i2s->dev, "RXDIS: Invalid MODE %x in IISMOD\n", |
221 | mod & S3C2412_IISMOD_MODE_MASK); | ||
203 | } | 222 | } |
204 | 223 | ||
205 | writel(con, regs + S3C2412_IISCON); | 224 | writel(con, regs + S3C2412_IISCON); |
@@ -209,7 +228,6 @@ void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on) | |||
209 | fic = readl(regs + S3C2412_IISFIC); | 228 | fic = readl(regs + S3C2412_IISFIC); |
210 | pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic); | 229 | pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic); |
211 | } | 230 | } |
212 | EXPORT_SYMBOL_GPL(s3c2412_snd_rxctrl); | ||
213 | 231 | ||
214 | /* | 232 | /* |
215 | * Wait for the LR signal to allow synchronisation to the L/R clock | 233 | * Wait for the LR signal to allow synchronisation to the L/R clock |
@@ -266,7 +284,7 @@ static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai, | |||
266 | */ | 284 | */ |
267 | #define IISMOD_MASTER_MASK (1 << 11) | 285 | #define IISMOD_MASTER_MASK (1 << 11) |
268 | #define IISMOD_SLAVE (1 << 11) | 286 | #define IISMOD_SLAVE (1 << 11) |
269 | #define IISMOD_MASTER (0x0) | 287 | #define IISMOD_MASTER (0 << 11) |
270 | #endif | 288 | #endif |
271 | 289 | ||
272 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | 290 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
@@ -281,7 +299,7 @@ static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai, | |||
281 | iismod |= IISMOD_MASTER; | 299 | iismod |= IISMOD_MASTER; |
282 | break; | 300 | break; |
283 | default: | 301 | default: |
284 | pr_debug("unknwon master/slave format\n"); | 302 | pr_err("unknwon master/slave format\n"); |
285 | return -EINVAL; | 303 | return -EINVAL; |
286 | } | 304 | } |
287 | 305 | ||
@@ -298,7 +316,7 @@ static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai, | |||
298 | iismod |= S3C2412_IISMOD_SDF_IIS; | 316 | iismod |= S3C2412_IISMOD_SDF_IIS; |
299 | break; | 317 | break; |
300 | default: | 318 | default: |
301 | pr_debug("Unknown data format\n"); | 319 | pr_err("Unknown data format\n"); |
302 | return -EINVAL; | 320 | return -EINVAL; |
303 | } | 321 | } |
304 | 322 | ||
@@ -327,6 +345,7 @@ static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream, | |||
327 | iismod = readl(i2s->regs + S3C2412_IISMOD); | 345 | iismod = readl(i2s->regs + S3C2412_IISMOD); |
328 | pr_debug("%s: r: IISMOD: %x\n", __func__, iismod); | 346 | pr_debug("%s: r: IISMOD: %x\n", __func__, iismod); |
329 | 347 | ||
348 | #if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413) | ||
330 | switch (params_format(params)) { | 349 | switch (params_format(params)) { |
331 | case SNDRV_PCM_FORMAT_S8: | 350 | case SNDRV_PCM_FORMAT_S8: |
332 | iismod |= S3C2412_IISMOD_8BIT; | 351 | iismod |= S3C2412_IISMOD_8BIT; |
@@ -335,6 +354,25 @@ static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream, | |||
335 | iismod &= ~S3C2412_IISMOD_8BIT; | 354 | iismod &= ~S3C2412_IISMOD_8BIT; |
336 | break; | 355 | break; |
337 | } | 356 | } |
357 | #endif | ||
358 | |||
359 | #ifdef CONFIG_PLAT_S3C64XX | ||
360 | iismod &= ~0x606; | ||
361 | /* Sample size */ | ||
362 | switch (params_format(params)) { | ||
363 | case SNDRV_PCM_FORMAT_S8: | ||
364 | /* 8 bit sample, 16fs BCLK */ | ||
365 | iismod |= 0x2004; | ||
366 | break; | ||
367 | case SNDRV_PCM_FORMAT_S16_LE: | ||
368 | /* 16 bit sample, 32fs BCLK */ | ||
369 | break; | ||
370 | case SNDRV_PCM_FORMAT_S24_LE: | ||
371 | /* 24 bit sample, 48fs BCLK */ | ||
372 | iismod |= 0x4002; | ||
373 | break; | ||
374 | } | ||
375 | #endif | ||
338 | 376 | ||
339 | writel(iismod, i2s->regs + S3C2412_IISMOD); | 377 | writel(iismod, i2s->regs + S3C2412_IISMOD); |
340 | pr_debug("%s: w: IISMOD: %x\n", __func__, iismod); | 378 | pr_debug("%s: w: IISMOD: %x\n", __func__, iismod); |
@@ -489,6 +527,8 @@ int s3c_i2sv2_iis_calc_rate(struct s3c_i2sv2_rate_calc *info, | |||
489 | unsigned int best_rate = 0; | 527 | unsigned int best_rate = 0; |
490 | unsigned int best_deviation = INT_MAX; | 528 | unsigned int best_deviation = INT_MAX; |
491 | 529 | ||
530 | pr_debug("Input clock rate %ldHz\n", clkrate); | ||
531 | |||
492 | if (fstab == NULL) | 532 | if (fstab == NULL) |
493 | fstab = iis_fs_tab; | 533 | fstab = iis_fs_tab; |
494 | 534 | ||
@@ -539,12 +579,31 @@ int s3c_i2sv2_probe(struct platform_device *pdev, | |||
539 | unsigned long base) | 579 | unsigned long base) |
540 | { | 580 | { |
541 | struct device *dev = &pdev->dev; | 581 | struct device *dev = &pdev->dev; |
582 | unsigned int iismod; | ||
542 | 583 | ||
543 | i2s->dev = dev; | 584 | i2s->dev = dev; |
544 | 585 | ||
545 | /* record our i2s structure for later use in the callbacks */ | 586 | /* record our i2s structure for later use in the callbacks */ |
546 | dai->private_data = i2s; | 587 | dai->private_data = i2s; |
547 | 588 | ||
589 | if (!base) { | ||
590 | struct resource *res = platform_get_resource(pdev, | ||
591 | IORESOURCE_MEM, | ||
592 | 0); | ||
593 | if (!res) { | ||
594 | dev_err(dev, "Unable to get register resource\n"); | ||
595 | return -ENXIO; | ||
596 | } | ||
597 | |||
598 | if (!request_mem_region(res->start, resource_size(res), | ||
599 | "s3c64xx-i2s-v4")) { | ||
600 | dev_err(dev, "Unable to request register region\n"); | ||
601 | return -EBUSY; | ||
602 | } | ||
603 | |||
604 | base = res->start; | ||
605 | } | ||
606 | |||
548 | i2s->regs = ioremap(base, 0x100); | 607 | i2s->regs = ioremap(base, 0x100); |
549 | if (i2s->regs == NULL) { | 608 | if (i2s->regs == NULL) { |
550 | dev_err(dev, "cannot ioremap registers\n"); | 609 | dev_err(dev, "cannot ioremap registers\n"); |
@@ -560,12 +619,16 @@ int s3c_i2sv2_probe(struct platform_device *pdev, | |||
560 | 619 | ||
561 | clk_enable(i2s->iis_pclk); | 620 | clk_enable(i2s->iis_pclk); |
562 | 621 | ||
622 | /* Mark ourselves as in TXRX mode so we can run through our cleanup | ||
623 | * process without warnings. */ | ||
624 | iismod = readl(i2s->regs + S3C2412_IISMOD); | ||
625 | iismod |= S3C2412_IISMOD_MODE_TXRX; | ||
626 | writel(iismod, i2s->regs + S3C2412_IISMOD); | ||
563 | s3c2412_snd_txctrl(i2s, 0); | 627 | s3c2412_snd_txctrl(i2s, 0); |
564 | s3c2412_snd_rxctrl(i2s, 0); | 628 | s3c2412_snd_rxctrl(i2s, 0); |
565 | 629 | ||
566 | return 0; | 630 | return 0; |
567 | } | 631 | } |
568 | |||
569 | EXPORT_SYMBOL_GPL(s3c_i2sv2_probe); | 632 | EXPORT_SYMBOL_GPL(s3c_i2sv2_probe); |
570 | 633 | ||
571 | #ifdef CONFIG_PM | 634 | #ifdef CONFIG_PM |
diff --git a/sound/soc/s3c24xx/s3c2412-i2s.c b/sound/soc/s3c24xx/s3c2412-i2s.c index b7e0b3f0bfc8..168a088ba761 100644 --- a/sound/soc/s3c24xx/s3c2412-i2s.c +++ b/sound/soc/s3c24xx/s3c2412-i2s.c | |||
@@ -120,7 +120,7 @@ static int s3c2412_i2s_probe(struct platform_device *pdev, | |||
120 | 120 | ||
121 | s3c2412_i2s.iis_cclk = clk_get(&pdev->dev, "i2sclk"); | 121 | s3c2412_i2s.iis_cclk = clk_get(&pdev->dev, "i2sclk"); |
122 | if (s3c2412_i2s.iis_cclk == NULL) { | 122 | if (s3c2412_i2s.iis_cclk == NULL) { |
123 | pr_debug("failed to get i2sclk clock\n"); | 123 | pr_err("failed to get i2sclk clock\n"); |
124 | iounmap(s3c2412_i2s.regs); | 124 | iounmap(s3c2412_i2s.regs); |
125 | return -ENODEV; | 125 | return -ENODEV; |
126 | } | 126 | } |
diff --git a/sound/soc/s3c24xx/s3c64xx-i2s.c b/sound/soc/s3c24xx/s3c64xx-i2s.c index 33c5de7e255f..3c06c401d0fb 100644 --- a/sound/soc/s3c24xx/s3c64xx-i2s.c +++ b/sound/soc/s3c24xx/s3c64xx-i2s.c | |||
@@ -108,48 +108,19 @@ static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai, | |||
108 | return 0; | 108 | return 0; |
109 | } | 109 | } |
110 | 110 | ||
111 | 111 | struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai) | |
112 | unsigned long s3c64xx_i2s_get_clockrate(struct snd_soc_dai *dai) | ||
113 | { | 112 | { |
114 | struct s3c_i2sv2_info *i2s = to_info(dai); | 113 | struct s3c_i2sv2_info *i2s = to_info(dai); |
115 | 114 | ||
116 | return clk_get_rate(i2s->iis_cclk); | 115 | return i2s->iis_cclk; |
117 | } | 116 | } |
118 | EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clockrate); | 117 | EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock); |
119 | 118 | ||
120 | static int s3c64xx_i2s_probe(struct platform_device *pdev, | 119 | static int s3c64xx_i2s_probe(struct platform_device *pdev, |
121 | struct snd_soc_dai *dai) | 120 | struct snd_soc_dai *dai) |
122 | { | 121 | { |
123 | struct device *dev = &pdev->dev; | ||
124 | struct s3c_i2sv2_info *i2s; | ||
125 | int ret; | ||
126 | |||
127 | dev_dbg(dev, "%s: probing dai %d\n", __func__, pdev->id); | ||
128 | |||
129 | if (pdev->id < 0 || pdev->id > ARRAY_SIZE(s3c64xx_i2s)) { | ||
130 | dev_err(dev, "id %d out of range\n", pdev->id); | ||
131 | return -EINVAL; | ||
132 | } | ||
133 | |||
134 | i2s = &s3c64xx_i2s[pdev->id]; | ||
135 | |||
136 | ret = s3c_i2sv2_probe(pdev, dai, i2s, | ||
137 | pdev->id ? S3C64XX_PA_IIS1 : S3C64XX_PA_IIS0); | ||
138 | if (ret) | ||
139 | return ret; | ||
140 | |||
141 | i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id]; | ||
142 | i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id]; | ||
143 | |||
144 | i2s->iis_cclk = clk_get(dev, "audio-bus"); | ||
145 | if (IS_ERR(i2s->iis_cclk)) { | ||
146 | dev_err(dev, "failed to get audio-bus"); | ||
147 | iounmap(i2s->regs); | ||
148 | return -ENODEV; | ||
149 | } | ||
150 | |||
151 | /* configure GPIO for i2s port */ | 122 | /* configure GPIO for i2s port */ |
152 | switch (pdev->id) { | 123 | switch (dai->id) { |
153 | case 0: | 124 | case 0: |
154 | s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK); | 125 | s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK); |
155 | s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK); | 126 | s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK); |
@@ -175,41 +146,122 @@ static int s3c64xx_i2s_probe(struct platform_device *pdev, | |||
175 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) | 146 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) |
176 | 147 | ||
177 | #define S3C64XX_I2S_FMTS \ | 148 | #define S3C64XX_I2S_FMTS \ |
178 | (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE) | 149 | (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\ |
150 | SNDRV_PCM_FMTBIT_S24_LE) | ||
179 | 151 | ||
180 | static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = { | 152 | static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = { |
181 | .set_sysclk = s3c64xx_i2s_set_sysclk, | 153 | .set_sysclk = s3c64xx_i2s_set_sysclk, |
182 | }; | 154 | }; |
183 | 155 | ||
184 | struct snd_soc_dai s3c64xx_i2s_dai = { | 156 | struct snd_soc_dai s3c64xx_i2s_dai[] = { |
185 | .name = "s3c64xx-i2s", | 157 | { |
186 | .id = 0, | 158 | .name = "s3c64xx-i2s", |
187 | .probe = s3c64xx_i2s_probe, | 159 | .id = 0, |
188 | .playback = { | 160 | .probe = s3c64xx_i2s_probe, |
189 | .channels_min = 2, | 161 | .playback = { |
190 | .channels_max = 2, | 162 | .channels_min = 2, |
191 | .rates = S3C64XX_I2S_RATES, | 163 | .channels_max = 2, |
192 | .formats = S3C64XX_I2S_FMTS, | 164 | .rates = S3C64XX_I2S_RATES, |
165 | .formats = S3C64XX_I2S_FMTS, | ||
166 | }, | ||
167 | .capture = { | ||
168 | .channels_min = 2, | ||
169 | .channels_max = 2, | ||
170 | .rates = S3C64XX_I2S_RATES, | ||
171 | .formats = S3C64XX_I2S_FMTS, | ||
172 | }, | ||
173 | .ops = &s3c64xx_i2s_dai_ops, | ||
174 | .symmetric_rates = 1, | ||
193 | }, | 175 | }, |
194 | .capture = { | 176 | { |
195 | .channels_min = 2, | 177 | .name = "s3c64xx-i2s", |
196 | .channels_max = 2, | 178 | .id = 1, |
197 | .rates = S3C64XX_I2S_RATES, | 179 | .probe = s3c64xx_i2s_probe, |
198 | .formats = S3C64XX_I2S_FMTS, | 180 | .playback = { |
181 | .channels_min = 2, | ||
182 | .channels_max = 2, | ||
183 | .rates = S3C64XX_I2S_RATES, | ||
184 | .formats = S3C64XX_I2S_FMTS, | ||
185 | }, | ||
186 | .capture = { | ||
187 | .channels_min = 2, | ||
188 | .channels_max = 2, | ||
189 | .rates = S3C64XX_I2S_RATES, | ||
190 | .formats = S3C64XX_I2S_FMTS, | ||
191 | }, | ||
192 | .ops = &s3c64xx_i2s_dai_ops, | ||
193 | .symmetric_rates = 1, | ||
199 | }, | 194 | }, |
200 | .ops = &s3c64xx_i2s_dai_ops, | ||
201 | }; | 195 | }; |
202 | EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai); | 196 | EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai); |
203 | 197 | ||
198 | static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev) | ||
199 | { | ||
200 | struct s3c_i2sv2_info *i2s; | ||
201 | struct snd_soc_dai *dai; | ||
202 | int ret; | ||
203 | |||
204 | if (pdev->id >= ARRAY_SIZE(s3c64xx_i2s)) { | ||
205 | dev_err(&pdev->dev, "id %d out of range\n", pdev->id); | ||
206 | return -EINVAL; | ||
207 | } | ||
208 | |||
209 | i2s = &s3c64xx_i2s[pdev->id]; | ||
210 | dai = &s3c64xx_i2s_dai[pdev->id]; | ||
211 | dai->dev = &pdev->dev; | ||
212 | |||
213 | i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id]; | ||
214 | i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id]; | ||
215 | |||
216 | i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus"); | ||
217 | if (IS_ERR(i2s->iis_cclk)) { | ||
218 | dev_err(&pdev->dev, "failed to get audio-bus\n"); | ||
219 | ret = PTR_ERR(i2s->iis_cclk); | ||
220 | goto err; | ||
221 | } | ||
222 | |||
223 | ret = s3c_i2sv2_probe(pdev, dai, i2s, 0); | ||
224 | if (ret) | ||
225 | goto err_clk; | ||
226 | |||
227 | ret = s3c_i2sv2_register_dai(dai); | ||
228 | if (ret != 0) | ||
229 | goto err_i2sv2; | ||
230 | |||
231 | return 0; | ||
232 | |||
233 | err_i2sv2: | ||
234 | /* Not implemented for I2Sv2 core yet */ | ||
235 | err_clk: | ||
236 | clk_put(i2s->iis_cclk); | ||
237 | err: | ||
238 | return ret; | ||
239 | } | ||
240 | |||
241 | static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev) | ||
242 | { | ||
243 | dev_err(&pdev->dev, "Device removal not yet supported\n"); | ||
244 | return 0; | ||
245 | } | ||
246 | |||
247 | static struct platform_driver s3c64xx_iis_driver = { | ||
248 | .probe = s3c64xx_iis_dev_probe, | ||
249 | .remove = s3c64xx_iis_dev_remove, | ||
250 | .driver = { | ||
251 | .name = "s3c64xx-iis", | ||
252 | .owner = THIS_MODULE, | ||
253 | }, | ||
254 | }; | ||
255 | |||
204 | static int __init s3c64xx_i2s_init(void) | 256 | static int __init s3c64xx_i2s_init(void) |
205 | { | 257 | { |
206 | return s3c_i2sv2_register_dai(&s3c64xx_i2s_dai); | 258 | return platform_driver_register(&s3c64xx_iis_driver); |
207 | } | 259 | } |
208 | module_init(s3c64xx_i2s_init); | 260 | module_init(s3c64xx_i2s_init); |
209 | 261 | ||
210 | static void __exit s3c64xx_i2s_exit(void) | 262 | static void __exit s3c64xx_i2s_exit(void) |
211 | { | 263 | { |
212 | snd_soc_unregister_dai(&s3c64xx_i2s_dai); | 264 | platform_driver_unregister(&s3c64xx_iis_driver); |
213 | } | 265 | } |
214 | module_exit(s3c64xx_i2s_exit); | 266 | module_exit(s3c64xx_i2s_exit); |
215 | 267 | ||
@@ -217,6 +269,3 @@ module_exit(s3c64xx_i2s_exit); | |||
217 | MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); | 269 | MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); |
218 | MODULE_DESCRIPTION("S3C64XX I2S SoC Interface"); | 270 | MODULE_DESCRIPTION("S3C64XX I2S SoC Interface"); |
219 | MODULE_LICENSE("GPL"); | 271 | MODULE_LICENSE("GPL"); |
220 | |||
221 | |||
222 | |||
diff --git a/sound/soc/s3c24xx/s3c64xx-i2s.h b/sound/soc/s3c24xx/s3c64xx-i2s.h index b7ffe3c38b66..02148cee2613 100644 --- a/sound/soc/s3c24xx/s3c64xx-i2s.h +++ b/sound/soc/s3c24xx/s3c64xx-i2s.h | |||
@@ -15,6 +15,8 @@ | |||
15 | #ifndef __SND_SOC_S3C24XX_S3C64XX_I2S_H | 15 | #ifndef __SND_SOC_S3C24XX_S3C64XX_I2S_H |
16 | #define __SND_SOC_S3C24XX_S3C64XX_I2S_H __FILE__ | 16 | #define __SND_SOC_S3C24XX_S3C64XX_I2S_H __FILE__ |
17 | 17 | ||
18 | struct clk; | ||
19 | |||
18 | #include "s3c-i2s-v2.h" | 20 | #include "s3c-i2s-v2.h" |
19 | 21 | ||
20 | #define S3C64XX_DIV_BCLK S3C_I2SV2_DIV_BCLK | 22 | #define S3C64XX_DIV_BCLK S3C_I2SV2_DIV_BCLK |
@@ -24,8 +26,8 @@ | |||
24 | #define S3C64XX_CLKSRC_PCLK (0) | 26 | #define S3C64XX_CLKSRC_PCLK (0) |
25 | #define S3C64XX_CLKSRC_MUX (1) | 27 | #define S3C64XX_CLKSRC_MUX (1) |
26 | 28 | ||
27 | extern struct snd_soc_dai s3c64xx_i2s_dai; | 29 | extern struct snd_soc_dai s3c64xx_i2s_dai[]; |
28 | 30 | ||
29 | extern unsigned long s3c64xx_i2s_get_clockrate(struct snd_soc_dai *cpu_dai); | 31 | extern struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai); |
30 | 32 | ||
31 | #endif /* __SND_SOC_S3C24XX_S3C64XX_I2S_H */ | 33 | #endif /* __SND_SOC_S3C24XX_S3C64XX_I2S_H */ |
diff --git a/sound/soc/s6000/Kconfig b/sound/soc/s6000/Kconfig new file mode 100644 index 000000000000..c74eb3d4a47c --- /dev/null +++ b/sound/soc/s6000/Kconfig | |||
@@ -0,0 +1,19 @@ | |||
1 | config SND_S6000_SOC | ||
2 | tristate "SoC Audio for the Stretch s6000 family" | ||
3 | depends on XTENSA_VARIANT_S6000 | ||
4 | help | ||
5 | Say Y or M if you want to add support for codecs attached to | ||
6 | s6000 family chips. You will also need to select the platform | ||
7 | to support below. | ||
8 | |||
9 | config SND_S6000_SOC_I2S | ||
10 | tristate | ||
11 | |||
12 | config SND_S6000_SOC_S6IPCAM | ||
13 | tristate "SoC Audio support for Stretch 6105 IP Camera" | ||
14 | depends on SND_S6000_SOC && XTENSA_PLATFORM_S6105 | ||
15 | select SND_S6000_SOC_I2S | ||
16 | select SND_SOC_TLV320AIC3X | ||
17 | help | ||
18 | Say Y if you want to add support for SoC audio on the | ||
19 | Stretch s6105 IP Camera Reference Design. | ||
diff --git a/sound/soc/s6000/Makefile b/sound/soc/s6000/Makefile new file mode 100644 index 000000000000..7a613612e010 --- /dev/null +++ b/sound/soc/s6000/Makefile | |||
@@ -0,0 +1,11 @@ | |||
1 | # s6000 Platform Support | ||
2 | snd-soc-s6000-objs := s6000-pcm.o | ||
3 | snd-soc-s6000-i2s-objs := s6000-i2s.o | ||
4 | |||
5 | obj-$(CONFIG_SND_S6000_SOC) += snd-soc-s6000.o | ||
6 | obj-$(CONFIG_SND_S6000_SOC_I2S) += snd-soc-s6000-i2s.o | ||
7 | |||
8 | # s6105 Machine Support | ||
9 | snd-soc-s6ipcam-objs := s6105-ipcam.o | ||
10 | |||
11 | obj-$(CONFIG_SND_S6000_SOC_S6IPCAM) += snd-soc-s6ipcam.o | ||
diff --git a/sound/soc/s6000/s6000-i2s.c b/sound/soc/s6000/s6000-i2s.c new file mode 100644 index 000000000000..c5cda187ecab --- /dev/null +++ b/sound/soc/s6000/s6000-i2s.c | |||
@@ -0,0 +1,629 @@ | |||
1 | /* | ||
2 | * ALSA SoC I2S Audio Layer for the Stretch S6000 family | ||
3 | * | ||
4 | * Author: Daniel Gloeckner, <dg@emlix.com> | ||
5 | * Copyright: (C) 2009 emlix GmbH <info@emlix.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/init.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/device.h> | ||
15 | #include <linux/delay.h> | ||
16 | #include <linux/clk.h> | ||
17 | #include <linux/interrupt.h> | ||
18 | #include <linux/io.h> | ||
19 | |||
20 | #include <sound/core.h> | ||
21 | #include <sound/pcm.h> | ||
22 | #include <sound/pcm_params.h> | ||
23 | #include <sound/initval.h> | ||
24 | #include <sound/soc.h> | ||
25 | |||
26 | #include "s6000-i2s.h" | ||
27 | #include "s6000-pcm.h" | ||
28 | |||
29 | struct s6000_i2s_dev { | ||
30 | dma_addr_t sifbase; | ||
31 | u8 __iomem *scbbase; | ||
32 | unsigned int wide; | ||
33 | unsigned int channel_in; | ||
34 | unsigned int channel_out; | ||
35 | unsigned int lines_in; | ||
36 | unsigned int lines_out; | ||
37 | struct s6000_pcm_dma_params dma_params; | ||
38 | }; | ||
39 | |||
40 | #define S6_I2S_INTERRUPT_STATUS 0x00 | ||
41 | #define S6_I2S_INT_OVERRUN 1 | ||
42 | #define S6_I2S_INT_UNDERRUN 2 | ||
43 | #define S6_I2S_INT_ALIGNMENT 4 | ||
44 | #define S6_I2S_INTERRUPT_ENABLE 0x04 | ||
45 | #define S6_I2S_INTERRUPT_RAW 0x08 | ||
46 | #define S6_I2S_INTERRUPT_CLEAR 0x0C | ||
47 | #define S6_I2S_INTERRUPT_SET 0x10 | ||
48 | #define S6_I2S_MODE 0x20 | ||
49 | #define S6_I2S_DUAL 0 | ||
50 | #define S6_I2S_WIDE 1 | ||
51 | #define S6_I2S_TX_DEFAULT 0x24 | ||
52 | #define S6_I2S_DATA_CFG(c) (0x40 + 0x10 * (c)) | ||
53 | #define S6_I2S_IN 0 | ||
54 | #define S6_I2S_OUT 1 | ||
55 | #define S6_I2S_UNUSED 2 | ||
56 | #define S6_I2S_INTERFACE_CFG(c) (0x44 + 0x10 * (c)) | ||
57 | #define S6_I2S_DIV_MASK 0x001fff | ||
58 | #define S6_I2S_16BIT 0x000000 | ||
59 | #define S6_I2S_20BIT 0x002000 | ||
60 | #define S6_I2S_24BIT 0x004000 | ||
61 | #define S6_I2S_32BIT 0x006000 | ||
62 | #define S6_I2S_BITS_MASK 0x006000 | ||
63 | #define S6_I2S_MEM_16BIT 0x000000 | ||
64 | #define S6_I2S_MEM_32BIT 0x008000 | ||
65 | #define S6_I2S_MEM_MASK 0x008000 | ||
66 | #define S6_I2S_CHANNELS_SHIFT 16 | ||
67 | #define S6_I2S_CHANNELS_MASK 0x030000 | ||
68 | #define S6_I2S_SCK_IN 0x000000 | ||
69 | #define S6_I2S_SCK_OUT 0x040000 | ||
70 | #define S6_I2S_SCK_DIR 0x040000 | ||
71 | #define S6_I2S_WS_IN 0x000000 | ||
72 | #define S6_I2S_WS_OUT 0x080000 | ||
73 | #define S6_I2S_WS_DIR 0x080000 | ||
74 | #define S6_I2S_LEFT_FIRST 0x000000 | ||
75 | #define S6_I2S_RIGHT_FIRST 0x100000 | ||
76 | #define S6_I2S_FIRST 0x100000 | ||
77 | #define S6_I2S_CUR_SCK 0x200000 | ||
78 | #define S6_I2S_CUR_WS 0x400000 | ||
79 | #define S6_I2S_ENABLE(c) (0x48 + 0x10 * (c)) | ||
80 | #define S6_I2S_DISABLE_IF 0x02 | ||
81 | #define S6_I2S_ENABLE_IF 0x03 | ||
82 | #define S6_I2S_IS_BUSY 0x04 | ||
83 | #define S6_I2S_DMA_ACTIVE 0x08 | ||
84 | #define S6_I2S_IS_ENABLED 0x10 | ||
85 | |||
86 | #define S6_I2S_NUM_LINES 4 | ||
87 | |||
88 | #define S6_I2S_SIF_PORT0 0x0000000 | ||
89 | #define S6_I2S_SIF_PORT1 0x0000080 /* docs say 0x0000010 */ | ||
90 | |||
91 | static inline void s6_i2s_write_reg(struct s6000_i2s_dev *dev, int reg, u32 val) | ||
92 | { | ||
93 | writel(val, dev->scbbase + reg); | ||
94 | } | ||
95 | |||
96 | static inline u32 s6_i2s_read_reg(struct s6000_i2s_dev *dev, int reg) | ||
97 | { | ||
98 | return readl(dev->scbbase + reg); | ||
99 | } | ||
100 | |||
101 | static inline void s6_i2s_mod_reg(struct s6000_i2s_dev *dev, int reg, | ||
102 | u32 mask, u32 val) | ||
103 | { | ||
104 | val ^= s6_i2s_read_reg(dev, reg) & ~mask; | ||
105 | s6_i2s_write_reg(dev, reg, val); | ||
106 | } | ||
107 | |||
108 | static void s6000_i2s_start_channel(struct s6000_i2s_dev *dev, int channel) | ||
109 | { | ||
110 | int i, j, cur, prev; | ||
111 | |||
112 | /* | ||
113 | * Wait for WCLK to toggle 5 times before enabling the channel | ||
114 | * s6000 Family Datasheet 3.6.4: | ||
115 | * "At least two cycles of WS must occur between commands | ||
116 | * to disable or enable the interface" | ||
117 | */ | ||
118 | j = 0; | ||
119 | prev = ~S6_I2S_CUR_WS; | ||
120 | for (i = 1000000; --i && j < 6; ) { | ||
121 | cur = s6_i2s_read_reg(dev, S6_I2S_INTERFACE_CFG(channel)) | ||
122 | & S6_I2S_CUR_WS; | ||
123 | if (prev != cur) { | ||
124 | prev = cur; | ||
125 | j++; | ||
126 | } | ||
127 | } | ||
128 | if (j < 6) | ||
129 | printk(KERN_WARNING "s6000-i2s: timeout waiting for WCLK\n"); | ||
130 | |||
131 | s6_i2s_write_reg(dev, S6_I2S_ENABLE(channel), S6_I2S_ENABLE_IF); | ||
132 | } | ||
133 | |||
134 | static void s6000_i2s_stop_channel(struct s6000_i2s_dev *dev, int channel) | ||
135 | { | ||
136 | s6_i2s_write_reg(dev, S6_I2S_ENABLE(channel), S6_I2S_DISABLE_IF); | ||
137 | } | ||
138 | |||
139 | static void s6000_i2s_start(struct snd_pcm_substream *substream) | ||
140 | { | ||
141 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
142 | struct s6000_i2s_dev *dev = rtd->dai->cpu_dai->private_data; | ||
143 | int channel; | ||
144 | |||
145 | channel = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? | ||
146 | dev->channel_out : dev->channel_in; | ||
147 | |||
148 | s6000_i2s_start_channel(dev, channel); | ||
149 | } | ||
150 | |||
151 | static void s6000_i2s_stop(struct snd_pcm_substream *substream) | ||
152 | { | ||
153 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
154 | struct s6000_i2s_dev *dev = rtd->dai->cpu_dai->private_data; | ||
155 | int channel; | ||
156 | |||
157 | channel = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? | ||
158 | dev->channel_out : dev->channel_in; | ||
159 | |||
160 | s6000_i2s_stop_channel(dev, channel); | ||
161 | } | ||
162 | |||
163 | static int s6000_i2s_trigger(struct snd_pcm_substream *substream, int cmd, | ||
164 | int after) | ||
165 | { | ||
166 | switch (cmd) { | ||
167 | case SNDRV_PCM_TRIGGER_START: | ||
168 | case SNDRV_PCM_TRIGGER_RESUME: | ||
169 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
170 | if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) ^ !after) | ||
171 | s6000_i2s_start(substream); | ||
172 | break; | ||
173 | case SNDRV_PCM_TRIGGER_STOP: | ||
174 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
175 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
176 | if (!after) | ||
177 | s6000_i2s_stop(substream); | ||
178 | } | ||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | static unsigned int s6000_i2s_int_sources(struct s6000_i2s_dev *dev) | ||
183 | { | ||
184 | unsigned int pending; | ||
185 | pending = s6_i2s_read_reg(dev, S6_I2S_INTERRUPT_RAW); | ||
186 | pending &= S6_I2S_INT_ALIGNMENT | | ||
187 | S6_I2S_INT_UNDERRUN | | ||
188 | S6_I2S_INT_OVERRUN; | ||
189 | s6_i2s_write_reg(dev, S6_I2S_INTERRUPT_CLEAR, pending); | ||
190 | |||
191 | return pending; | ||
192 | } | ||
193 | |||
194 | static unsigned int s6000_i2s_check_xrun(struct snd_soc_dai *cpu_dai) | ||
195 | { | ||
196 | struct s6000_i2s_dev *dev = cpu_dai->private_data; | ||
197 | unsigned int errors; | ||
198 | unsigned int ret; | ||
199 | |||
200 | errors = s6000_i2s_int_sources(dev); | ||
201 | if (likely(!errors)) | ||
202 | return 0; | ||
203 | |||
204 | ret = 0; | ||
205 | if (errors & S6_I2S_INT_ALIGNMENT) | ||
206 | printk(KERN_ERR "s6000-i2s: WCLK misaligned\n"); | ||
207 | if (errors & S6_I2S_INT_UNDERRUN) | ||
208 | ret |= 1 << SNDRV_PCM_STREAM_PLAYBACK; | ||
209 | if (errors & S6_I2S_INT_OVERRUN) | ||
210 | ret |= 1 << SNDRV_PCM_STREAM_CAPTURE; | ||
211 | return ret; | ||
212 | } | ||
213 | |||
214 | static void s6000_i2s_wait_disabled(struct s6000_i2s_dev *dev) | ||
215 | { | ||
216 | int channel; | ||
217 | int n = 50; | ||
218 | for (channel = 0; channel < 2; channel++) { | ||
219 | while (--n >= 0) { | ||
220 | int v = s6_i2s_read_reg(dev, S6_I2S_ENABLE(channel)); | ||
221 | if ((v & S6_I2S_IS_ENABLED) | ||
222 | || !(v & (S6_I2S_DMA_ACTIVE | S6_I2S_IS_BUSY))) | ||
223 | break; | ||
224 | udelay(20); | ||
225 | } | ||
226 | } | ||
227 | if (n < 0) | ||
228 | printk(KERN_WARNING "s6000-i2s: timeout disabling interfaces"); | ||
229 | } | ||
230 | |||
231 | static int s6000_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai, | ||
232 | unsigned int fmt) | ||
233 | { | ||
234 | struct s6000_i2s_dev *dev = cpu_dai->private_data; | ||
235 | u32 w; | ||
236 | |||
237 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
238 | case SND_SOC_DAIFMT_CBM_CFM: | ||
239 | w = S6_I2S_SCK_IN | S6_I2S_WS_IN; | ||
240 | break; | ||
241 | case SND_SOC_DAIFMT_CBS_CFM: | ||
242 | w = S6_I2S_SCK_OUT | S6_I2S_WS_IN; | ||
243 | break; | ||
244 | case SND_SOC_DAIFMT_CBM_CFS: | ||
245 | w = S6_I2S_SCK_IN | S6_I2S_WS_OUT; | ||
246 | break; | ||
247 | case SND_SOC_DAIFMT_CBS_CFS: | ||
248 | w = S6_I2S_SCK_OUT | S6_I2S_WS_OUT; | ||
249 | break; | ||
250 | default: | ||
251 | return -EINVAL; | ||
252 | } | ||
253 | |||
254 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
255 | case SND_SOC_DAIFMT_NB_NF: | ||
256 | w |= S6_I2S_LEFT_FIRST; | ||
257 | break; | ||
258 | case SND_SOC_DAIFMT_NB_IF: | ||
259 | w |= S6_I2S_RIGHT_FIRST; | ||
260 | break; | ||
261 | default: | ||
262 | return -EINVAL; | ||
263 | } | ||
264 | |||
265 | s6_i2s_mod_reg(dev, S6_I2S_INTERFACE_CFG(0), | ||
266 | S6_I2S_FIRST | S6_I2S_WS_DIR | S6_I2S_SCK_DIR, w); | ||
267 | s6_i2s_mod_reg(dev, S6_I2S_INTERFACE_CFG(1), | ||
268 | S6_I2S_FIRST | S6_I2S_WS_DIR | S6_I2S_SCK_DIR, w); | ||
269 | |||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | static int s6000_i2s_set_clkdiv(struct snd_soc_dai *dai, int div_id, int div) | ||
274 | { | ||
275 | struct s6000_i2s_dev *dev = dai->private_data; | ||
276 | |||
277 | if (!div || (div & 1) || div > (S6_I2S_DIV_MASK + 1) * 2) | ||
278 | return -EINVAL; | ||
279 | |||
280 | s6_i2s_mod_reg(dev, S6_I2S_INTERFACE_CFG(div_id), | ||
281 | S6_I2S_DIV_MASK, div / 2 - 1); | ||
282 | return 0; | ||
283 | } | ||
284 | |||
285 | static int s6000_i2s_hw_params(struct snd_pcm_substream *substream, | ||
286 | struct snd_pcm_hw_params *params, | ||
287 | struct snd_soc_dai *dai) | ||
288 | { | ||
289 | struct s6000_i2s_dev *dev = dai->private_data; | ||
290 | int interf; | ||
291 | u32 w = 0; | ||
292 | |||
293 | if (dev->wide) | ||
294 | interf = 0; | ||
295 | else { | ||
296 | w |= (((params_channels(params) - 2) / 2) | ||
297 | << S6_I2S_CHANNELS_SHIFT) & S6_I2S_CHANNELS_MASK; | ||
298 | interf = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
299 | ? dev->channel_out : dev->channel_in; | ||
300 | } | ||
301 | |||
302 | switch (params_format(params)) { | ||
303 | case SNDRV_PCM_FORMAT_S16_LE: | ||
304 | w |= S6_I2S_16BIT | S6_I2S_MEM_16BIT; | ||
305 | break; | ||
306 | case SNDRV_PCM_FORMAT_S32_LE: | ||
307 | w |= S6_I2S_32BIT | S6_I2S_MEM_32BIT; | ||
308 | break; | ||
309 | default: | ||
310 | printk(KERN_WARNING "s6000-i2s: unsupported PCM format %x\n", | ||
311 | params_format(params)); | ||
312 | return -EINVAL; | ||
313 | } | ||
314 | |||
315 | if (s6_i2s_read_reg(dev, S6_I2S_INTERFACE_CFG(interf)) | ||
316 | & S6_I2S_IS_ENABLED) { | ||
317 | printk(KERN_ERR "s6000-i2s: interface already enabled\n"); | ||
318 | return -EBUSY; | ||
319 | } | ||
320 | |||
321 | s6_i2s_mod_reg(dev, S6_I2S_INTERFACE_CFG(interf), | ||
322 | S6_I2S_CHANNELS_MASK|S6_I2S_MEM_MASK|S6_I2S_BITS_MASK, | ||
323 | w); | ||
324 | |||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | static int s6000_i2s_dai_probe(struct platform_device *pdev, | ||
329 | struct snd_soc_dai *dai) | ||
330 | { | ||
331 | struct s6000_i2s_dev *dev = dai->private_data; | ||
332 | struct s6000_snd_platform_data *pdata = pdev->dev.platform_data; | ||
333 | |||
334 | if (!pdata) | ||
335 | return -EINVAL; | ||
336 | |||
337 | dev->wide = pdata->wide; | ||
338 | dev->channel_in = pdata->channel_in; | ||
339 | dev->channel_out = pdata->channel_out; | ||
340 | dev->lines_in = pdata->lines_in; | ||
341 | dev->lines_out = pdata->lines_out; | ||
342 | |||
343 | s6_i2s_write_reg(dev, S6_I2S_MODE, | ||
344 | dev->wide ? S6_I2S_WIDE : S6_I2S_DUAL); | ||
345 | |||
346 | if (dev->wide) { | ||
347 | int i; | ||
348 | |||
349 | if (dev->lines_in + dev->lines_out > S6_I2S_NUM_LINES) | ||
350 | return -EINVAL; | ||
351 | |||
352 | dev->channel_in = 0; | ||
353 | dev->channel_out = 1; | ||
354 | dai->capture.channels_min = 2 * dev->lines_in; | ||
355 | dai->capture.channels_max = dai->capture.channels_min; | ||
356 | dai->playback.channels_min = 2 * dev->lines_out; | ||
357 | dai->playback.channels_max = dai->playback.channels_min; | ||
358 | |||
359 | for (i = 0; i < dev->lines_out; i++) | ||
360 | s6_i2s_write_reg(dev, S6_I2S_DATA_CFG(i), S6_I2S_OUT); | ||
361 | |||
362 | for (; i < S6_I2S_NUM_LINES - dev->lines_in; i++) | ||
363 | s6_i2s_write_reg(dev, S6_I2S_DATA_CFG(i), | ||
364 | S6_I2S_UNUSED); | ||
365 | |||
366 | for (; i < S6_I2S_NUM_LINES; i++) | ||
367 | s6_i2s_write_reg(dev, S6_I2S_DATA_CFG(i), S6_I2S_IN); | ||
368 | } else { | ||
369 | unsigned int cfg[2] = {S6_I2S_UNUSED, S6_I2S_UNUSED}; | ||
370 | |||
371 | if (dev->lines_in > 1 || dev->lines_out > 1) | ||
372 | return -EINVAL; | ||
373 | |||
374 | dai->capture.channels_min = 2 * dev->lines_in; | ||
375 | dai->capture.channels_max = 8 * dev->lines_in; | ||
376 | dai->playback.channels_min = 2 * dev->lines_out; | ||
377 | dai->playback.channels_max = 8 * dev->lines_out; | ||
378 | |||
379 | if (dev->lines_in) | ||
380 | cfg[dev->channel_in] = S6_I2S_IN; | ||
381 | if (dev->lines_out) | ||
382 | cfg[dev->channel_out] = S6_I2S_OUT; | ||
383 | |||
384 | s6_i2s_write_reg(dev, S6_I2S_DATA_CFG(0), cfg[0]); | ||
385 | s6_i2s_write_reg(dev, S6_I2S_DATA_CFG(1), cfg[1]); | ||
386 | } | ||
387 | |||
388 | if (dev->lines_out) { | ||
389 | if (dev->lines_in) { | ||
390 | if (!dev->dma_params.dma_out) | ||
391 | return -ENODEV; | ||
392 | } else { | ||
393 | dev->dma_params.dma_out = dev->dma_params.dma_in; | ||
394 | dev->dma_params.dma_in = 0; | ||
395 | } | ||
396 | } | ||
397 | dev->dma_params.sif_in = dev->sifbase + (dev->channel_in ? | ||
398 | S6_I2S_SIF_PORT1 : S6_I2S_SIF_PORT0); | ||
399 | dev->dma_params.sif_out = dev->sifbase + (dev->channel_out ? | ||
400 | S6_I2S_SIF_PORT1 : S6_I2S_SIF_PORT0); | ||
401 | dev->dma_params.same_rate = pdata->same_rate | pdata->wide; | ||
402 | return 0; | ||
403 | } | ||
404 | |||
405 | #define S6000_I2S_RATES (SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_5512 | \ | ||
406 | SNDRV_PCM_RATE_8000_192000) | ||
407 | #define S6000_I2S_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE) | ||
408 | |||
409 | static struct snd_soc_dai_ops s6000_i2s_dai_ops = { | ||
410 | .set_fmt = s6000_i2s_set_dai_fmt, | ||
411 | .set_clkdiv = s6000_i2s_set_clkdiv, | ||
412 | .hw_params = s6000_i2s_hw_params, | ||
413 | }; | ||
414 | |||
415 | struct snd_soc_dai s6000_i2s_dai = { | ||
416 | .name = "s6000-i2s", | ||
417 | .id = 0, | ||
418 | .probe = s6000_i2s_dai_probe, | ||
419 | .playback = { | ||
420 | .channels_min = 2, | ||
421 | .channels_max = 8, | ||
422 | .formats = S6000_I2S_FORMATS, | ||
423 | .rates = S6000_I2S_RATES, | ||
424 | .rate_min = 0, | ||
425 | .rate_max = 1562500, | ||
426 | }, | ||
427 | .capture = { | ||
428 | .channels_min = 2, | ||
429 | .channels_max = 8, | ||
430 | .formats = S6000_I2S_FORMATS, | ||
431 | .rates = S6000_I2S_RATES, | ||
432 | .rate_min = 0, | ||
433 | .rate_max = 1562500, | ||
434 | }, | ||
435 | .ops = &s6000_i2s_dai_ops, | ||
436 | } | ||
437 | EXPORT_SYMBOL_GPL(s6000_i2s_dai); | ||
438 | |||
439 | static int __devinit s6000_i2s_probe(struct platform_device *pdev) | ||
440 | { | ||
441 | struct s6000_i2s_dev *dev; | ||
442 | struct resource *scbmem, *sifmem, *region, *dma1, *dma2; | ||
443 | u8 __iomem *mmio; | ||
444 | int ret; | ||
445 | |||
446 | scbmem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
447 | if (!scbmem) { | ||
448 | dev_err(&pdev->dev, "no mem resource?\n"); | ||
449 | ret = -ENODEV; | ||
450 | goto err_release_none; | ||
451 | } | ||
452 | |||
453 | region = request_mem_region(scbmem->start, | ||
454 | scbmem->end - scbmem->start + 1, | ||
455 | pdev->name); | ||
456 | if (!region) { | ||
457 | dev_err(&pdev->dev, "I2S SCB region already claimed\n"); | ||
458 | ret = -EBUSY; | ||
459 | goto err_release_none; | ||
460 | } | ||
461 | |||
462 | mmio = ioremap(scbmem->start, scbmem->end - scbmem->start + 1); | ||
463 | if (!mmio) { | ||
464 | dev_err(&pdev->dev, "can't ioremap SCB region\n"); | ||
465 | ret = -ENOMEM; | ||
466 | goto err_release_scb; | ||
467 | } | ||
468 | |||
469 | sifmem = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
470 | if (!sifmem) { | ||
471 | dev_err(&pdev->dev, "no second mem resource?\n"); | ||
472 | ret = -ENODEV; | ||
473 | goto err_release_map; | ||
474 | } | ||
475 | |||
476 | region = request_mem_region(sifmem->start, | ||
477 | sifmem->end - sifmem->start + 1, | ||
478 | pdev->name); | ||
479 | if (!region) { | ||
480 | dev_err(&pdev->dev, "I2S SIF region already claimed\n"); | ||
481 | ret = -EBUSY; | ||
482 | goto err_release_map; | ||
483 | } | ||
484 | |||
485 | dma1 = platform_get_resource(pdev, IORESOURCE_DMA, 0); | ||
486 | if (!dma1) { | ||
487 | dev_err(&pdev->dev, "no dma resource?\n"); | ||
488 | ret = -ENODEV; | ||
489 | goto err_release_sif; | ||
490 | } | ||
491 | |||
492 | region = request_mem_region(dma1->start, dma1->end - dma1->start + 1, | ||
493 | pdev->name); | ||
494 | if (!region) { | ||
495 | dev_err(&pdev->dev, "I2S DMA region already claimed\n"); | ||
496 | ret = -EBUSY; | ||
497 | goto err_release_sif; | ||
498 | } | ||
499 | |||
500 | dma2 = platform_get_resource(pdev, IORESOURCE_DMA, 1); | ||
501 | if (dma2) { | ||
502 | region = request_mem_region(dma2->start, | ||
503 | dma2->end - dma2->start + 1, | ||
504 | pdev->name); | ||
505 | if (!region) { | ||
506 | dev_err(&pdev->dev, | ||
507 | "I2S DMA region already claimed\n"); | ||
508 | ret = -EBUSY; | ||
509 | goto err_release_dma1; | ||
510 | } | ||
511 | } | ||
512 | |||
513 | dev = kzalloc(sizeof(struct s6000_i2s_dev), GFP_KERNEL); | ||
514 | if (!dev) { | ||
515 | ret = -ENOMEM; | ||
516 | goto err_release_dma2; | ||
517 | } | ||
518 | |||
519 | s6000_i2s_dai.dev = &pdev->dev; | ||
520 | s6000_i2s_dai.private_data = dev; | ||
521 | s6000_i2s_dai.dma_data = &dev->dma_params; | ||
522 | |||
523 | dev->sifbase = sifmem->start; | ||
524 | dev->scbbase = mmio; | ||
525 | |||
526 | s6_i2s_write_reg(dev, S6_I2S_INTERRUPT_ENABLE, 0); | ||
527 | s6_i2s_write_reg(dev, S6_I2S_INTERRUPT_CLEAR, | ||
528 | S6_I2S_INT_ALIGNMENT | | ||
529 | S6_I2S_INT_UNDERRUN | | ||
530 | S6_I2S_INT_OVERRUN); | ||
531 | |||
532 | s6000_i2s_stop_channel(dev, 0); | ||
533 | s6000_i2s_stop_channel(dev, 1); | ||
534 | s6000_i2s_wait_disabled(dev); | ||
535 | |||
536 | dev->dma_params.check_xrun = s6000_i2s_check_xrun; | ||
537 | dev->dma_params.trigger = s6000_i2s_trigger; | ||
538 | dev->dma_params.dma_in = dma1->start; | ||
539 | dev->dma_params.dma_out = dma2 ? dma2->start : 0; | ||
540 | dev->dma_params.irq = platform_get_irq(pdev, 0); | ||
541 | if (dev->dma_params.irq < 0) { | ||
542 | dev_err(&pdev->dev, "no irq resource?\n"); | ||
543 | ret = -ENODEV; | ||
544 | goto err_release_dev; | ||
545 | } | ||
546 | |||
547 | s6_i2s_write_reg(dev, S6_I2S_INTERRUPT_ENABLE, | ||
548 | S6_I2S_INT_ALIGNMENT | | ||
549 | S6_I2S_INT_UNDERRUN | | ||
550 | S6_I2S_INT_OVERRUN); | ||
551 | |||
552 | ret = snd_soc_register_dai(&s6000_i2s_dai); | ||
553 | if (ret) | ||
554 | goto err_release_dev; | ||
555 | |||
556 | return 0; | ||
557 | |||
558 | err_release_dev: | ||
559 | kfree(dev); | ||
560 | err_release_dma2: | ||
561 | if (dma2) | ||
562 | release_mem_region(dma2->start, dma2->end - dma2->start + 1); | ||
563 | err_release_dma1: | ||
564 | release_mem_region(dma1->start, dma1->end - dma1->start + 1); | ||
565 | err_release_sif: | ||
566 | release_mem_region(sifmem->start, (sifmem->end - sifmem->start) + 1); | ||
567 | err_release_map: | ||
568 | iounmap(mmio); | ||
569 | err_release_scb: | ||
570 | release_mem_region(scbmem->start, (scbmem->end - scbmem->start) + 1); | ||
571 | err_release_none: | ||
572 | return ret; | ||
573 | } | ||
574 | |||
575 | static void __devexit s6000_i2s_remove(struct platform_device *pdev) | ||
576 | { | ||
577 | struct s6000_i2s_dev *dev = s6000_i2s_dai.private_data; | ||
578 | struct resource *region; | ||
579 | void __iomem *mmio = dev->scbbase; | ||
580 | |||
581 | snd_soc_unregister_dai(&s6000_i2s_dai); | ||
582 | |||
583 | s6000_i2s_stop_channel(dev, 0); | ||
584 | s6000_i2s_stop_channel(dev, 1); | ||
585 | |||
586 | s6_i2s_write_reg(dev, S6_I2S_INTERRUPT_ENABLE, 0); | ||
587 | s6000_i2s_dai.private_data = 0; | ||
588 | kfree(dev); | ||
589 | |||
590 | region = platform_get_resource(pdev, IORESOURCE_DMA, 0); | ||
591 | release_mem_region(region->start, region->end - region->start + 1); | ||
592 | |||
593 | region = platform_get_resource(pdev, IORESOURCE_DMA, 1); | ||
594 | if (region) | ||
595 | release_mem_region(region->start, | ||
596 | region->end - region->start + 1); | ||
597 | |||
598 | region = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
599 | release_mem_region(region->start, (region->end - region->start) + 1); | ||
600 | |||
601 | iounmap(mmio); | ||
602 | region = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
603 | release_mem_region(region->start, (region->end - region->start) + 1); | ||
604 | } | ||
605 | |||
606 | static struct platform_driver s6000_i2s_driver = { | ||
607 | .probe = s6000_i2s_probe, | ||
608 | .remove = __devexit_p(s6000_i2s_remove), | ||
609 | .driver = { | ||
610 | .name = "s6000-i2s", | ||
611 | .owner = THIS_MODULE, | ||
612 | }, | ||
613 | }; | ||
614 | |||
615 | static int __init s6000_i2s_init(void) | ||
616 | { | ||
617 | return platform_driver_register(&s6000_i2s_driver); | ||
618 | } | ||
619 | module_init(s6000_i2s_init); | ||
620 | |||
621 | static void __exit s6000_i2s_exit(void) | ||
622 | { | ||
623 | platform_driver_unregister(&s6000_i2s_driver); | ||
624 | } | ||
625 | module_exit(s6000_i2s_exit); | ||
626 | |||
627 | MODULE_AUTHOR("Daniel Gloeckner"); | ||
628 | MODULE_DESCRIPTION("Stretch s6000 family I2S SoC Interface"); | ||
629 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/s6000/s6000-i2s.h b/sound/soc/s6000/s6000-i2s.h new file mode 100644 index 000000000000..2375fdfe6dba --- /dev/null +++ b/sound/soc/s6000/s6000-i2s.h | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * ALSA SoC I2S Audio Layer for the Stretch s6000 family | ||
3 | * | ||
4 | * Author: Daniel Gloeckner, <dg@emlix.com> | ||
5 | * Copyright: (C) 2009 emlix GmbH <info@emlix.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #ifndef _S6000_I2S_H | ||
13 | #define _S6000_I2S_H | ||
14 | |||
15 | extern struct snd_soc_dai s6000_i2s_dai; | ||
16 | |||
17 | struct s6000_snd_platform_data { | ||
18 | int lines_in; | ||
19 | int lines_out; | ||
20 | int channel_in; | ||
21 | int channel_out; | ||
22 | int wide; | ||
23 | int same_rate; | ||
24 | }; | ||
25 | #endif | ||
diff --git a/sound/soc/s6000/s6000-pcm.c b/sound/soc/s6000/s6000-pcm.c new file mode 100644 index 000000000000..83b8028e209d --- /dev/null +++ b/sound/soc/s6000/s6000-pcm.c | |||
@@ -0,0 +1,497 @@ | |||
1 | /* | ||
2 | * ALSA PCM interface for the Stetch s6000 family | ||
3 | * | ||
4 | * Author: Daniel Gloeckner, <dg@emlix.com> | ||
5 | * Copyright: (C) 2009 emlix GmbH <info@emlix.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/platform_device.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <linux/dma-mapping.h> | ||
17 | #include <linux/interrupt.h> | ||
18 | |||
19 | #include <sound/core.h> | ||
20 | #include <sound/pcm.h> | ||
21 | #include <sound/pcm_params.h> | ||
22 | #include <sound/soc.h> | ||
23 | |||
24 | #include <asm/dma.h> | ||
25 | #include <variant/dmac.h> | ||
26 | |||
27 | #include "s6000-pcm.h" | ||
28 | |||
29 | #define S6_PCM_PREALLOCATE_SIZE (96 * 1024) | ||
30 | #define S6_PCM_PREALLOCATE_MAX (2048 * 1024) | ||
31 | |||
32 | static struct snd_pcm_hardware s6000_pcm_hardware = { | ||
33 | .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | | ||
34 | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | | ||
35 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_JOINT_DUPLEX), | ||
36 | .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE), | ||
37 | .rates = (SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_5512 | \ | ||
38 | SNDRV_PCM_RATE_8000_192000), | ||
39 | .rate_min = 0, | ||
40 | .rate_max = 1562500, | ||
41 | .channels_min = 2, | ||
42 | .channels_max = 8, | ||
43 | .buffer_bytes_max = 0x7ffffff0, | ||
44 | .period_bytes_min = 16, | ||
45 | .period_bytes_max = 0xfffff0, | ||
46 | .periods_min = 2, | ||
47 | .periods_max = 1024, /* no limit */ | ||
48 | .fifo_size = 0, | ||
49 | }; | ||
50 | |||
51 | struct s6000_runtime_data { | ||
52 | spinlock_t lock; | ||
53 | int period; /* current DMA period */ | ||
54 | }; | ||
55 | |||
56 | static void s6000_pcm_enqueue_dma(struct snd_pcm_substream *substream) | ||
57 | { | ||
58 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
59 | struct s6000_runtime_data *prtd = runtime->private_data; | ||
60 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
61 | struct s6000_pcm_dma_params *par = soc_runtime->dai->cpu_dai->dma_data; | ||
62 | int channel; | ||
63 | unsigned int period_size; | ||
64 | unsigned int dma_offset; | ||
65 | dma_addr_t dma_pos; | ||
66 | dma_addr_t src, dst; | ||
67 | |||
68 | period_size = snd_pcm_lib_period_bytes(substream); | ||
69 | dma_offset = prtd->period * period_size; | ||
70 | dma_pos = runtime->dma_addr + dma_offset; | ||
71 | |||
72 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
73 | src = dma_pos; | ||
74 | dst = par->sif_out; | ||
75 | channel = par->dma_out; | ||
76 | } else { | ||
77 | src = par->sif_in; | ||
78 | dst = dma_pos; | ||
79 | channel = par->dma_in; | ||
80 | } | ||
81 | |||
82 | if (!s6dmac_channel_enabled(DMA_MASK_DMAC(channel), | ||
83 | DMA_INDEX_CHNL(channel))) | ||
84 | return; | ||
85 | |||
86 | if (s6dmac_fifo_full(DMA_MASK_DMAC(channel), DMA_INDEX_CHNL(channel))) { | ||
87 | printk(KERN_ERR "s6000-pcm: fifo full\n"); | ||
88 | return; | ||
89 | } | ||
90 | |||
91 | BUG_ON(period_size & 15); | ||
92 | s6dmac_put_fifo(DMA_MASK_DMAC(channel), DMA_INDEX_CHNL(channel), | ||
93 | src, dst, period_size); | ||
94 | |||
95 | prtd->period++; | ||
96 | if (unlikely(prtd->period >= runtime->periods)) | ||
97 | prtd->period = 0; | ||
98 | } | ||
99 | |||
100 | static irqreturn_t s6000_pcm_irq(int irq, void *data) | ||
101 | { | ||
102 | struct snd_pcm *pcm = data; | ||
103 | struct snd_soc_pcm_runtime *runtime = pcm->private_data; | ||
104 | struct s6000_pcm_dma_params *params = runtime->dai->cpu_dai->dma_data; | ||
105 | struct s6000_runtime_data *prtd; | ||
106 | unsigned int has_xrun; | ||
107 | int i, ret = IRQ_NONE; | ||
108 | u32 channel[2] = { | ||
109 | [SNDRV_PCM_STREAM_PLAYBACK] = params->dma_out, | ||
110 | [SNDRV_PCM_STREAM_CAPTURE] = params->dma_in | ||
111 | }; | ||
112 | |||
113 | has_xrun = params->check_xrun(runtime->dai->cpu_dai); | ||
114 | |||
115 | for (i = 0; i < ARRAY_SIZE(channel); ++i) { | ||
116 | struct snd_pcm_substream *substream = pcm->streams[i].substream; | ||
117 | unsigned int pending; | ||
118 | |||
119 | if (!channel[i]) | ||
120 | continue; | ||
121 | |||
122 | if (unlikely(has_xrun & (1 << i)) && | ||
123 | substream->runtime && | ||
124 | snd_pcm_running(substream)) { | ||
125 | dev_dbg(pcm->dev, "xrun\n"); | ||
126 | snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); | ||
127 | ret = IRQ_HANDLED; | ||
128 | } | ||
129 | |||
130 | pending = s6dmac_int_sources(DMA_MASK_DMAC(channel[i]), | ||
131 | DMA_INDEX_CHNL(channel[i])); | ||
132 | |||
133 | if (pending & 1) { | ||
134 | ret = IRQ_HANDLED; | ||
135 | if (likely(substream->runtime && | ||
136 | snd_pcm_running(substream))) { | ||
137 | snd_pcm_period_elapsed(substream); | ||
138 | dev_dbg(pcm->dev, "period elapsed %x %x\n", | ||
139 | s6dmac_cur_src(DMA_MASK_DMAC(channel[i]), | ||
140 | DMA_INDEX_CHNL(channel[i])), | ||
141 | s6dmac_cur_dst(DMA_MASK_DMAC(channel[i]), | ||
142 | DMA_INDEX_CHNL(channel[i]))); | ||
143 | prtd = substream->runtime->private_data; | ||
144 | spin_lock(&prtd->lock); | ||
145 | s6000_pcm_enqueue_dma(substream); | ||
146 | spin_unlock(&prtd->lock); | ||
147 | } | ||
148 | } | ||
149 | |||
150 | if (unlikely(pending & ~7)) { | ||
151 | if (pending & (1 << 3)) | ||
152 | printk(KERN_WARNING | ||
153 | "s6000-pcm: DMA %x Underflow\n", | ||
154 | channel[i]); | ||
155 | if (pending & (1 << 4)) | ||
156 | printk(KERN_WARNING | ||
157 | "s6000-pcm: DMA %x Overflow\n", | ||
158 | channel[i]); | ||
159 | if (pending & 0x1e0) | ||
160 | printk(KERN_WARNING | ||
161 | "s6000-pcm: DMA %x Master Error " | ||
162 | "(mask %x)\n", | ||
163 | channel[i], pending >> 5); | ||
164 | |||
165 | } | ||
166 | } | ||
167 | |||
168 | return ret; | ||
169 | } | ||
170 | |||
171 | static int s6000_pcm_start(struct snd_pcm_substream *substream) | ||
172 | { | ||
173 | struct s6000_runtime_data *prtd = substream->runtime->private_data; | ||
174 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
175 | struct s6000_pcm_dma_params *par = soc_runtime->dai->cpu_dai->dma_data; | ||
176 | unsigned long flags; | ||
177 | int srcinc; | ||
178 | u32 dma; | ||
179 | |||
180 | spin_lock_irqsave(&prtd->lock, flags); | ||
181 | |||
182 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
183 | srcinc = 1; | ||
184 | dma = par->dma_out; | ||
185 | } else { | ||
186 | srcinc = 0; | ||
187 | dma = par->dma_in; | ||
188 | } | ||
189 | s6dmac_enable_chan(DMA_MASK_DMAC(dma), DMA_INDEX_CHNL(dma), | ||
190 | 1 /* priority 1 (0 is max) */, | ||
191 | 0 /* peripheral requests w/o xfer length mode */, | ||
192 | srcinc /* source address increment */, | ||
193 | srcinc^1 /* destination address increment */, | ||
194 | 0 /* chunksize 0 (skip impossible on this dma) */, | ||
195 | 0 /* source skip after chunk (impossible) */, | ||
196 | 0 /* destination skip after chunk (impossible) */, | ||
197 | 4 /* 16 byte burst size */, | ||
198 | -1 /* don't conserve bandwidth */, | ||
199 | 0 /* low watermark irq descriptor theshold */, | ||
200 | 0 /* disable hardware timestamps */, | ||
201 | 1 /* enable channel */); | ||
202 | |||
203 | s6000_pcm_enqueue_dma(substream); | ||
204 | s6000_pcm_enqueue_dma(substream); | ||
205 | |||
206 | spin_unlock_irqrestore(&prtd->lock, flags); | ||
207 | |||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | static int s6000_pcm_stop(struct snd_pcm_substream *substream) | ||
212 | { | ||
213 | struct s6000_runtime_data *prtd = substream->runtime->private_data; | ||
214 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
215 | struct s6000_pcm_dma_params *par = soc_runtime->dai->cpu_dai->dma_data; | ||
216 | unsigned long flags; | ||
217 | u32 channel; | ||
218 | |||
219 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
220 | channel = par->dma_out; | ||
221 | else | ||
222 | channel = par->dma_in; | ||
223 | |||
224 | s6dmac_set_terminal_count(DMA_MASK_DMAC(channel), | ||
225 | DMA_INDEX_CHNL(channel), 0); | ||
226 | |||
227 | spin_lock_irqsave(&prtd->lock, flags); | ||
228 | |||
229 | s6dmac_disable_chan(DMA_MASK_DMAC(channel), DMA_INDEX_CHNL(channel)); | ||
230 | |||
231 | spin_unlock_irqrestore(&prtd->lock, flags); | ||
232 | |||
233 | return 0; | ||
234 | } | ||
235 | |||
236 | static int s6000_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | ||
237 | { | ||
238 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
239 | struct s6000_pcm_dma_params *par = soc_runtime->dai->cpu_dai->dma_data; | ||
240 | int ret; | ||
241 | |||
242 | ret = par->trigger(substream, cmd, 0); | ||
243 | if (ret < 0) | ||
244 | return ret; | ||
245 | |||
246 | switch (cmd) { | ||
247 | case SNDRV_PCM_TRIGGER_START: | ||
248 | case SNDRV_PCM_TRIGGER_RESUME: | ||
249 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
250 | ret = s6000_pcm_start(substream); | ||
251 | break; | ||
252 | case SNDRV_PCM_TRIGGER_STOP: | ||
253 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
254 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
255 | ret = s6000_pcm_stop(substream); | ||
256 | break; | ||
257 | default: | ||
258 | ret = -EINVAL; | ||
259 | } | ||
260 | if (ret < 0) | ||
261 | return ret; | ||
262 | |||
263 | return par->trigger(substream, cmd, 1); | ||
264 | } | ||
265 | |||
266 | static int s6000_pcm_prepare(struct snd_pcm_substream *substream) | ||
267 | { | ||
268 | struct s6000_runtime_data *prtd = substream->runtime->private_data; | ||
269 | |||
270 | prtd->period = 0; | ||
271 | |||
272 | return 0; | ||
273 | } | ||
274 | |||
275 | static snd_pcm_uframes_t s6000_pcm_pointer(struct snd_pcm_substream *substream) | ||
276 | { | ||
277 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
278 | struct s6000_pcm_dma_params *par = soc_runtime->dai->cpu_dai->dma_data; | ||
279 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
280 | struct s6000_runtime_data *prtd = runtime->private_data; | ||
281 | unsigned long flags; | ||
282 | unsigned int offset; | ||
283 | dma_addr_t count; | ||
284 | |||
285 | spin_lock_irqsave(&prtd->lock, flags); | ||
286 | |||
287 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
288 | count = s6dmac_cur_src(DMA_MASK_DMAC(par->dma_out), | ||
289 | DMA_INDEX_CHNL(par->dma_out)); | ||
290 | else | ||
291 | count = s6dmac_cur_dst(DMA_MASK_DMAC(par->dma_in), | ||
292 | DMA_INDEX_CHNL(par->dma_in)); | ||
293 | |||
294 | count -= runtime->dma_addr; | ||
295 | |||
296 | spin_unlock_irqrestore(&prtd->lock, flags); | ||
297 | |||
298 | offset = bytes_to_frames(runtime, count); | ||
299 | if (unlikely(offset >= runtime->buffer_size)) | ||
300 | offset = 0; | ||
301 | |||
302 | return offset; | ||
303 | } | ||
304 | |||
305 | static int s6000_pcm_open(struct snd_pcm_substream *substream) | ||
306 | { | ||
307 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
308 | struct s6000_pcm_dma_params *par = soc_runtime->dai->cpu_dai->dma_data; | ||
309 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
310 | struct s6000_runtime_data *prtd; | ||
311 | int ret; | ||
312 | |||
313 | snd_soc_set_runtime_hwparams(substream, &s6000_pcm_hardware); | ||
314 | |||
315 | ret = snd_pcm_hw_constraint_step(runtime, 0, | ||
316 | SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 16); | ||
317 | if (ret < 0) | ||
318 | return ret; | ||
319 | ret = snd_pcm_hw_constraint_step(runtime, 0, | ||
320 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 16); | ||
321 | if (ret < 0) | ||
322 | return ret; | ||
323 | ret = snd_pcm_hw_constraint_integer(runtime, | ||
324 | SNDRV_PCM_HW_PARAM_PERIODS); | ||
325 | if (ret < 0) | ||
326 | return ret; | ||
327 | |||
328 | if (par->same_rate) { | ||
329 | int rate; | ||
330 | spin_lock(&par->lock); /* needed? */ | ||
331 | rate = par->rate; | ||
332 | spin_unlock(&par->lock); | ||
333 | if (rate != -1) { | ||
334 | ret = snd_pcm_hw_constraint_minmax(runtime, | ||
335 | SNDRV_PCM_HW_PARAM_RATE, | ||
336 | rate, rate); | ||
337 | if (ret < 0) | ||
338 | return ret; | ||
339 | } | ||
340 | } | ||
341 | |||
342 | prtd = kzalloc(sizeof(struct s6000_runtime_data), GFP_KERNEL); | ||
343 | if (prtd == NULL) | ||
344 | return -ENOMEM; | ||
345 | |||
346 | spin_lock_init(&prtd->lock); | ||
347 | |||
348 | runtime->private_data = prtd; | ||
349 | |||
350 | return 0; | ||
351 | } | ||
352 | |||
353 | static int s6000_pcm_close(struct snd_pcm_substream *substream) | ||
354 | { | ||
355 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
356 | struct s6000_runtime_data *prtd = runtime->private_data; | ||
357 | |||
358 | kfree(prtd); | ||
359 | |||
360 | return 0; | ||
361 | } | ||
362 | |||
363 | static int s6000_pcm_hw_params(struct snd_pcm_substream *substream, | ||
364 | struct snd_pcm_hw_params *hw_params) | ||
365 | { | ||
366 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
367 | struct s6000_pcm_dma_params *par = soc_runtime->dai->cpu_dai->dma_data; | ||
368 | int ret; | ||
369 | ret = snd_pcm_lib_malloc_pages(substream, | ||
370 | params_buffer_bytes(hw_params)); | ||
371 | if (ret < 0) { | ||
372 | printk(KERN_WARNING "s6000-pcm: allocation of memory failed\n"); | ||
373 | return ret; | ||
374 | } | ||
375 | |||
376 | if (par->same_rate) { | ||
377 | spin_lock(&par->lock); | ||
378 | if (par->rate == -1 || | ||
379 | !(par->in_use & ~(1 << substream->stream))) { | ||
380 | par->rate = params_rate(hw_params); | ||
381 | par->in_use |= 1 << substream->stream; | ||
382 | } else if (params_rate(hw_params) != par->rate) { | ||
383 | snd_pcm_lib_free_pages(substream); | ||
384 | par->in_use &= ~(1 << substream->stream); | ||
385 | ret = -EBUSY; | ||
386 | } | ||
387 | spin_unlock(&par->lock); | ||
388 | } | ||
389 | return ret; | ||
390 | } | ||
391 | |||
392 | static int s6000_pcm_hw_free(struct snd_pcm_substream *substream) | ||
393 | { | ||
394 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
395 | struct s6000_pcm_dma_params *par = soc_runtime->dai->cpu_dai->dma_data; | ||
396 | |||
397 | spin_lock(&par->lock); | ||
398 | par->in_use &= ~(1 << substream->stream); | ||
399 | if (!par->in_use) | ||
400 | par->rate = -1; | ||
401 | spin_unlock(&par->lock); | ||
402 | |||
403 | return snd_pcm_lib_free_pages(substream); | ||
404 | } | ||
405 | |||
406 | static struct snd_pcm_ops s6000_pcm_ops = { | ||
407 | .open = s6000_pcm_open, | ||
408 | .close = s6000_pcm_close, | ||
409 | .ioctl = snd_pcm_lib_ioctl, | ||
410 | .hw_params = s6000_pcm_hw_params, | ||
411 | .hw_free = s6000_pcm_hw_free, | ||
412 | .trigger = s6000_pcm_trigger, | ||
413 | .prepare = s6000_pcm_prepare, | ||
414 | .pointer = s6000_pcm_pointer, | ||
415 | }; | ||
416 | |||
417 | static void s6000_pcm_free(struct snd_pcm *pcm) | ||
418 | { | ||
419 | struct snd_soc_pcm_runtime *runtime = pcm->private_data; | ||
420 | struct s6000_pcm_dma_params *params = runtime->dai->cpu_dai->dma_data; | ||
421 | |||
422 | free_irq(params->irq, pcm); | ||
423 | snd_pcm_lib_preallocate_free_for_all(pcm); | ||
424 | } | ||
425 | |||
426 | static u64 s6000_pcm_dmamask = DMA_32BIT_MASK; | ||
427 | |||
428 | static int s6000_pcm_new(struct snd_card *card, | ||
429 | struct snd_soc_dai *dai, struct snd_pcm *pcm) | ||
430 | { | ||
431 | struct snd_soc_pcm_runtime *runtime = pcm->private_data; | ||
432 | struct s6000_pcm_dma_params *params = runtime->dai->cpu_dai->dma_data; | ||
433 | int res; | ||
434 | |||
435 | if (!card->dev->dma_mask) | ||
436 | card->dev->dma_mask = &s6000_pcm_dmamask; | ||
437 | if (!card->dev->coherent_dma_mask) | ||
438 | card->dev->coherent_dma_mask = DMA_32BIT_MASK; | ||
439 | |||
440 | if (params->dma_in) { | ||
441 | s6dmac_disable_chan(DMA_MASK_DMAC(params->dma_in), | ||
442 | DMA_INDEX_CHNL(params->dma_in)); | ||
443 | s6dmac_int_sources(DMA_MASK_DMAC(params->dma_in), | ||
444 | DMA_INDEX_CHNL(params->dma_in)); | ||
445 | } | ||
446 | |||
447 | if (params->dma_out) { | ||
448 | s6dmac_disable_chan(DMA_MASK_DMAC(params->dma_out), | ||
449 | DMA_INDEX_CHNL(params->dma_out)); | ||
450 | s6dmac_int_sources(DMA_MASK_DMAC(params->dma_out), | ||
451 | DMA_INDEX_CHNL(params->dma_out)); | ||
452 | } | ||
453 | |||
454 | res = request_irq(params->irq, s6000_pcm_irq, IRQF_SHARED, | ||
455 | s6000_soc_platform.name, pcm); | ||
456 | if (res) { | ||
457 | printk(KERN_ERR "s6000-pcm couldn't get IRQ\n"); | ||
458 | return res; | ||
459 | } | ||
460 | |||
461 | res = snd_pcm_lib_preallocate_pages_for_all(pcm, | ||
462 | SNDRV_DMA_TYPE_DEV, | ||
463 | card->dev, | ||
464 | S6_PCM_PREALLOCATE_SIZE, | ||
465 | S6_PCM_PREALLOCATE_MAX); | ||
466 | if (res) | ||
467 | printk(KERN_WARNING "s6000-pcm: preallocation failed\n"); | ||
468 | |||
469 | spin_lock_init(¶ms->lock); | ||
470 | params->in_use = 0; | ||
471 | params->rate = -1; | ||
472 | return 0; | ||
473 | } | ||
474 | |||
475 | struct snd_soc_platform s6000_soc_platform = { | ||
476 | .name = "s6000-audio", | ||
477 | .pcm_ops = &s6000_pcm_ops, | ||
478 | .pcm_new = s6000_pcm_new, | ||
479 | .pcm_free = s6000_pcm_free, | ||
480 | }; | ||
481 | EXPORT_SYMBOL_GPL(s6000_soc_platform); | ||
482 | |||
483 | static int __init s6000_pcm_init(void) | ||
484 | { | ||
485 | return snd_soc_register_platform(&s6000_soc_platform); | ||
486 | } | ||
487 | module_init(s6000_pcm_init); | ||
488 | |||
489 | static void __exit s6000_pcm_exit(void) | ||
490 | { | ||
491 | snd_soc_unregister_platform(&s6000_soc_platform); | ||
492 | } | ||
493 | module_exit(s6000_pcm_exit); | ||
494 | |||
495 | MODULE_AUTHOR("Daniel Gloeckner"); | ||
496 | MODULE_DESCRIPTION("Stretch s6000 family PCM DMA module"); | ||
497 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/s6000/s6000-pcm.h b/sound/soc/s6000/s6000-pcm.h new file mode 100644 index 000000000000..96f23f6f52bf --- /dev/null +++ b/sound/soc/s6000/s6000-pcm.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | * ALSA PCM interface for the Stretch s6000 family | ||
3 | * | ||
4 | * Author: Daniel Gloeckner, <dg@emlix.com> | ||
5 | * Copyright: (C) 2009 emlix GmbH <info@emlix.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #ifndef _S6000_PCM_H | ||
13 | #define _S6000_PCM_H | ||
14 | |||
15 | struct snd_soc_dai; | ||
16 | struct snd_pcm_substream; | ||
17 | |||
18 | struct s6000_pcm_dma_params { | ||
19 | unsigned int (*check_xrun)(struct snd_soc_dai *cpu_dai); | ||
20 | int (*trigger)(struct snd_pcm_substream *substream, int cmd, int after); | ||
21 | dma_addr_t sif_in; | ||
22 | dma_addr_t sif_out; | ||
23 | u32 dma_in; | ||
24 | u32 dma_out; | ||
25 | int irq; | ||
26 | int same_rate; | ||
27 | |||
28 | spinlock_t lock; | ||
29 | int in_use; | ||
30 | int rate; | ||
31 | }; | ||
32 | |||
33 | extern struct snd_soc_platform s6000_soc_platform; | ||
34 | |||
35 | #endif | ||
diff --git a/sound/soc/s6000/s6105-ipcam.c b/sound/soc/s6000/s6105-ipcam.c new file mode 100644 index 000000000000..b5f95f9781c1 --- /dev/null +++ b/sound/soc/s6000/s6105-ipcam.c | |||
@@ -0,0 +1,244 @@ | |||
1 | /* | ||
2 | * ASoC driver for Stretch s6105 IP camera platform | ||
3 | * | ||
4 | * Author: Daniel Gloeckner, <dg@emlix.com> | ||
5 | * Copyright: (C) 2009 emlix GmbH <info@emlix.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/moduleparam.h> | ||
14 | #include <linux/timer.h> | ||
15 | #include <linux/interrupt.h> | ||
16 | #include <linux/platform_device.h> | ||
17 | #include <sound/core.h> | ||
18 | #include <sound/pcm.h> | ||
19 | #include <sound/soc.h> | ||
20 | #include <sound/soc-dapm.h> | ||
21 | |||
22 | #include <variant/dmac.h> | ||
23 | |||
24 | #include "../codecs/tlv320aic3x.h" | ||
25 | #include "s6000-pcm.h" | ||
26 | #include "s6000-i2s.h" | ||
27 | |||
28 | #define S6105_CAM_CODEC_CLOCK 12288000 | ||
29 | |||
30 | static int s6105_hw_params(struct snd_pcm_substream *substream, | ||
31 | struct snd_pcm_hw_params *params) | ||
32 | { | ||
33 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
34 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; | ||
35 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | ||
36 | int ret = 0; | ||
37 | |||
38 | /* set codec DAI configuration */ | ||
39 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | | ||
40 | SND_SOC_DAIFMT_CBM_CFM); | ||
41 | if (ret < 0) | ||
42 | return ret; | ||
43 | |||
44 | /* set cpu DAI configuration */ | ||
45 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM | | ||
46 | SND_SOC_DAIFMT_NB_NF); | ||
47 | if (ret < 0) | ||
48 | return ret; | ||
49 | |||
50 | /* set the codec system clock */ | ||
51 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, S6105_CAM_CODEC_CLOCK, | ||
52 | SND_SOC_CLOCK_OUT); | ||
53 | if (ret < 0) | ||
54 | return ret; | ||
55 | |||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | static struct snd_soc_ops s6105_ops = { | ||
60 | .hw_params = s6105_hw_params, | ||
61 | }; | ||
62 | |||
63 | /* s6105 machine dapm widgets */ | ||
64 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { | ||
65 | SND_SOC_DAPM_LINE("Audio Out Differential", NULL), | ||
66 | SND_SOC_DAPM_LINE("Audio Out Stereo", NULL), | ||
67 | SND_SOC_DAPM_LINE("Audio In", NULL), | ||
68 | }; | ||
69 | |||
70 | /* s6105 machine audio_mapnections to the codec pins */ | ||
71 | static const struct snd_soc_dapm_route audio_map[] = { | ||
72 | /* Audio Out connected to HPLOUT, HPLCOM, HPROUT */ | ||
73 | {"Audio Out Differential", NULL, "HPLOUT"}, | ||
74 | {"Audio Out Differential", NULL, "HPLCOM"}, | ||
75 | {"Audio Out Stereo", NULL, "HPLOUT"}, | ||
76 | {"Audio Out Stereo", NULL, "HPROUT"}, | ||
77 | |||
78 | /* Audio In connected to LINE1L, LINE1R */ | ||
79 | {"LINE1L", NULL, "Audio In"}, | ||
80 | {"LINE1R", NULL, "Audio In"}, | ||
81 | }; | ||
82 | |||
83 | static int output_type_info(struct snd_kcontrol *kcontrol, | ||
84 | struct snd_ctl_elem_info *uinfo) | ||
85 | { | ||
86 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
87 | uinfo->count = 1; | ||
88 | uinfo->value.enumerated.items = 2; | ||
89 | if (uinfo->value.enumerated.item) { | ||
90 | uinfo->value.enumerated.item = 1; | ||
91 | strcpy(uinfo->value.enumerated.name, "HPLOUT/HPROUT"); | ||
92 | } else { | ||
93 | strcpy(uinfo->value.enumerated.name, "HPLOUT/HPLCOM"); | ||
94 | } | ||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | static int output_type_get(struct snd_kcontrol *kcontrol, | ||
99 | struct snd_ctl_elem_value *ucontrol) | ||
100 | { | ||
101 | ucontrol->value.enumerated.item[0] = kcontrol->private_value; | ||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | static int output_type_put(struct snd_kcontrol *kcontrol, | ||
106 | struct snd_ctl_elem_value *ucontrol) | ||
107 | { | ||
108 | struct snd_soc_codec *codec = kcontrol->private_data; | ||
109 | unsigned int val = (ucontrol->value.enumerated.item[0] != 0); | ||
110 | char *differential = "Audio Out Differential"; | ||
111 | char *stereo = "Audio Out Stereo"; | ||
112 | |||
113 | if (kcontrol->private_value == val) | ||
114 | return 0; | ||
115 | kcontrol->private_value = val; | ||
116 | snd_soc_dapm_disable_pin(codec, val ? differential : stereo); | ||
117 | snd_soc_dapm_sync(codec); | ||
118 | snd_soc_dapm_enable_pin(codec, val ? stereo : differential); | ||
119 | snd_soc_dapm_sync(codec); | ||
120 | |||
121 | return 1; | ||
122 | } | ||
123 | |||
124 | static const struct snd_kcontrol_new audio_out_mux = { | ||
125 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
126 | .name = "Master Output Mux", | ||
127 | .index = 0, | ||
128 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, | ||
129 | .info = output_type_info, | ||
130 | .get = output_type_get, | ||
131 | .put = output_type_put, | ||
132 | .private_value = 1 /* default to stereo */ | ||
133 | }; | ||
134 | |||
135 | /* Logic for a aic3x as connected on the s6105 ip camera ref design */ | ||
136 | static int s6105_aic3x_init(struct snd_soc_codec *codec) | ||
137 | { | ||
138 | /* Add s6105 specific widgets */ | ||
139 | snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets, | ||
140 | ARRAY_SIZE(aic3x_dapm_widgets)); | ||
141 | |||
142 | /* Set up s6105 specific audio path audio_map */ | ||
143 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | ||
144 | |||
145 | /* not present */ | ||
146 | snd_soc_dapm_nc_pin(codec, "MONO_LOUT"); | ||
147 | snd_soc_dapm_nc_pin(codec, "LINE2L"); | ||
148 | snd_soc_dapm_nc_pin(codec, "LINE2R"); | ||
149 | |||
150 | /* not connected */ | ||
151 | snd_soc_dapm_nc_pin(codec, "MIC3L"); /* LINE2L on this chip */ | ||
152 | snd_soc_dapm_nc_pin(codec, "MIC3R"); /* LINE2R on this chip */ | ||
153 | snd_soc_dapm_nc_pin(codec, "LLOUT"); | ||
154 | snd_soc_dapm_nc_pin(codec, "RLOUT"); | ||
155 | snd_soc_dapm_nc_pin(codec, "HPRCOM"); | ||
156 | |||
157 | /* always connected */ | ||
158 | snd_soc_dapm_enable_pin(codec, "Audio In"); | ||
159 | |||
160 | /* must correspond to audio_out_mux.private_value initializer */ | ||
161 | snd_soc_dapm_disable_pin(codec, "Audio Out Differential"); | ||
162 | snd_soc_dapm_sync(codec); | ||
163 | snd_soc_dapm_enable_pin(codec, "Audio Out Stereo"); | ||
164 | |||
165 | snd_soc_dapm_sync(codec); | ||
166 | |||
167 | snd_ctl_add(codec->card, snd_ctl_new1(&audio_out_mux, codec)); | ||
168 | |||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | /* s6105 digital audio interface glue - connects codec <--> CPU */ | ||
173 | static struct snd_soc_dai_link s6105_dai = { | ||
174 | .name = "TLV320AIC31", | ||
175 | .stream_name = "AIC31", | ||
176 | .cpu_dai = &s6000_i2s_dai, | ||
177 | .codec_dai = &aic3x_dai, | ||
178 | .init = s6105_aic3x_init, | ||
179 | .ops = &s6105_ops, | ||
180 | }; | ||
181 | |||
182 | /* s6105 audio machine driver */ | ||
183 | static struct snd_soc_card snd_soc_card_s6105 = { | ||
184 | .name = "Stretch IP Camera", | ||
185 | .platform = &s6000_soc_platform, | ||
186 | .dai_link = &s6105_dai, | ||
187 | .num_links = 1, | ||
188 | }; | ||
189 | |||
190 | /* s6105 audio private data */ | ||
191 | static struct aic3x_setup_data s6105_aic3x_setup = { | ||
192 | .i2c_bus = 0, | ||
193 | .i2c_address = 0x18, | ||
194 | }; | ||
195 | |||
196 | /* s6105 audio subsystem */ | ||
197 | static struct snd_soc_device s6105_snd_devdata = { | ||
198 | .card = &snd_soc_card_s6105, | ||
199 | .codec_dev = &soc_codec_dev_aic3x, | ||
200 | .codec_data = &s6105_aic3x_setup, | ||
201 | }; | ||
202 | |||
203 | static struct s6000_snd_platform_data __initdata s6105_snd_data = { | ||
204 | .wide = 0, | ||
205 | .channel_in = 0, | ||
206 | .channel_out = 1, | ||
207 | .lines_in = 1, | ||
208 | .lines_out = 1, | ||
209 | .same_rate = 1, | ||
210 | }; | ||
211 | |||
212 | static struct platform_device *s6105_snd_device; | ||
213 | |||
214 | static int __init s6105_init(void) | ||
215 | { | ||
216 | int ret; | ||
217 | |||
218 | s6105_snd_device = platform_device_alloc("soc-audio", -1); | ||
219 | if (!s6105_snd_device) | ||
220 | return -ENOMEM; | ||
221 | |||
222 | platform_set_drvdata(s6105_snd_device, &s6105_snd_devdata); | ||
223 | s6105_snd_devdata.dev = &s6105_snd_device->dev; | ||
224 | platform_device_add_data(s6105_snd_device, &s6105_snd_data, | ||
225 | sizeof(s6105_snd_data)); | ||
226 | |||
227 | ret = platform_device_add(s6105_snd_device); | ||
228 | if (ret) | ||
229 | platform_device_put(s6105_snd_device); | ||
230 | |||
231 | return ret; | ||
232 | } | ||
233 | |||
234 | static void __exit s6105_exit(void) | ||
235 | { | ||
236 | platform_device_unregister(s6105_snd_device); | ||
237 | } | ||
238 | |||
239 | module_init(s6105_init); | ||
240 | module_exit(s6105_exit); | ||
241 | |||
242 | MODULE_AUTHOR("Daniel Gloeckner"); | ||
243 | MODULE_DESCRIPTION("Stretch s6105 IP camera ASoC driver"); | ||
244 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 1cd149b9ce69..c0e706645ec4 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c | |||
@@ -113,6 +113,35 @@ static int soc_ac97_dev_register(struct snd_soc_codec *codec) | |||
113 | } | 113 | } |
114 | #endif | 114 | #endif |
115 | 115 | ||
116 | static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream) | ||
117 | { | ||
118 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
119 | struct snd_soc_device *socdev = rtd->socdev; | ||
120 | struct snd_soc_card *card = socdev->card; | ||
121 | struct snd_soc_dai_link *machine = rtd->dai; | ||
122 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; | ||
123 | struct snd_soc_dai *codec_dai = machine->codec_dai; | ||
124 | int ret; | ||
125 | |||
126 | if (codec_dai->symmetric_rates || cpu_dai->symmetric_rates || | ||
127 | machine->symmetric_rates) { | ||
128 | dev_dbg(card->dev, "Symmetry forces %dHz rate\n", | ||
129 | machine->rate); | ||
130 | |||
131 | ret = snd_pcm_hw_constraint_minmax(substream->runtime, | ||
132 | SNDRV_PCM_HW_PARAM_RATE, | ||
133 | machine->rate, | ||
134 | machine->rate); | ||
135 | if (ret < 0) { | ||
136 | dev_err(card->dev, | ||
137 | "Unable to apply rate symmetry constraint: %d\n", ret); | ||
138 | return ret; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | return 0; | ||
143 | } | ||
144 | |||
116 | /* | 145 | /* |
117 | * Called by ALSA when a PCM substream is opened, the runtime->hw record is | 146 | * Called by ALSA when a PCM substream is opened, the runtime->hw record is |
118 | * then initialized and any private data can be allocated. This also calls | 147 | * then initialized and any private data can be allocated. This also calls |
@@ -221,6 +250,13 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) | |||
221 | goto machine_err; | 250 | goto machine_err; |
222 | } | 251 | } |
223 | 252 | ||
253 | /* Symmetry only applies if we've already got an active stream. */ | ||
254 | if (cpu_dai->active || codec_dai->active) { | ||
255 | ret = soc_pcm_apply_symmetry(substream); | ||
256 | if (ret != 0) | ||
257 | goto machine_err; | ||
258 | } | ||
259 | |||
224 | pr_debug("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name); | 260 | pr_debug("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name); |
225 | pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates); | 261 | pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates); |
226 | pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min, | 262 | pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min, |
@@ -521,6 +557,8 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, | |||
521 | } | 557 | } |
522 | } | 558 | } |
523 | 559 | ||
560 | machine->rate = params_rate(params); | ||
561 | |||
524 | out: | 562 | out: |
525 | mutex_unlock(&pcm_mutex); | 563 | mutex_unlock(&pcm_mutex); |
526 | return ret; | 564 | return ret; |
@@ -1744,7 +1782,7 @@ int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol, | |||
1744 | { | 1782 | { |
1745 | int max = kcontrol->private_value; | 1783 | int max = kcontrol->private_value; |
1746 | 1784 | ||
1747 | if (max == 1) | 1785 | if (max == 1 && !strstr(kcontrol->id.name, " Volume")) |
1748 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | 1786 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
1749 | else | 1787 | else |
1750 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | 1788 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
@@ -1774,7 +1812,7 @@ int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, | |||
1774 | unsigned int shift = mc->shift; | 1812 | unsigned int shift = mc->shift; |
1775 | unsigned int rshift = mc->rshift; | 1813 | unsigned int rshift = mc->rshift; |
1776 | 1814 | ||
1777 | if (max == 1) | 1815 | if (max == 1 && !strstr(kcontrol->id.name, " Volume")) |
1778 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | 1816 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
1779 | else | 1817 | else |
1780 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | 1818 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
@@ -1881,7 +1919,7 @@ int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol, | |||
1881 | (struct soc_mixer_control *)kcontrol->private_value; | 1919 | (struct soc_mixer_control *)kcontrol->private_value; |
1882 | int max = mc->max; | 1920 | int max = mc->max; |
1883 | 1921 | ||
1884 | if (max == 1) | 1922 | if (max == 1 && !strstr(kcontrol->id.name, " Volume")) |
1885 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | 1923 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
1886 | else | 1924 | else |
1887 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | 1925 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
@@ -2065,7 +2103,7 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); | |||
2065 | int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, | 2103 | int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
2066 | unsigned int freq, int dir) | 2104 | unsigned int freq, int dir) |
2067 | { | 2105 | { |
2068 | if (dai->ops->set_sysclk) | 2106 | if (dai->ops && dai->ops->set_sysclk) |
2069 | return dai->ops->set_sysclk(dai, clk_id, freq, dir); | 2107 | return dai->ops->set_sysclk(dai, clk_id, freq, dir); |
2070 | else | 2108 | else |
2071 | return -EINVAL; | 2109 | return -EINVAL; |
@@ -2085,7 +2123,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); | |||
2085 | int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, | 2123 | int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, |
2086 | int div_id, int div) | 2124 | int div_id, int div) |
2087 | { | 2125 | { |
2088 | if (dai->ops->set_clkdiv) | 2126 | if (dai->ops && dai->ops->set_clkdiv) |
2089 | return dai->ops->set_clkdiv(dai, div_id, div); | 2127 | return dai->ops->set_clkdiv(dai, div_id, div); |
2090 | else | 2128 | else |
2091 | return -EINVAL; | 2129 | return -EINVAL; |
@@ -2104,7 +2142,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); | |||
2104 | int snd_soc_dai_set_pll(struct snd_soc_dai *dai, | 2142 | int snd_soc_dai_set_pll(struct snd_soc_dai *dai, |
2105 | int pll_id, unsigned int freq_in, unsigned int freq_out) | 2143 | int pll_id, unsigned int freq_in, unsigned int freq_out) |
2106 | { | 2144 | { |
2107 | if (dai->ops->set_pll) | 2145 | if (dai->ops && dai->ops->set_pll) |
2108 | return dai->ops->set_pll(dai, pll_id, freq_in, freq_out); | 2146 | return dai->ops->set_pll(dai, pll_id, freq_in, freq_out); |
2109 | else | 2147 | else |
2110 | return -EINVAL; | 2148 | return -EINVAL; |
@@ -2120,7 +2158,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); | |||
2120 | */ | 2158 | */ |
2121 | int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) | 2159 | int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
2122 | { | 2160 | { |
2123 | if (dai->ops->set_fmt) | 2161 | if (dai->ops && dai->ops->set_fmt) |
2124 | return dai->ops->set_fmt(dai, fmt); | 2162 | return dai->ops->set_fmt(dai, fmt); |
2125 | else | 2163 | else |
2126 | return -EINVAL; | 2164 | return -EINVAL; |
@@ -2139,7 +2177,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); | |||
2139 | int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, | 2177 | int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, |
2140 | unsigned int mask, int slots) | 2178 | unsigned int mask, int slots) |
2141 | { | 2179 | { |
2142 | if (dai->ops->set_sysclk) | 2180 | if (dai->ops && dai->ops->set_tdm_slot) |
2143 | return dai->ops->set_tdm_slot(dai, mask, slots); | 2181 | return dai->ops->set_tdm_slot(dai, mask, slots); |
2144 | else | 2182 | else |
2145 | return -EINVAL; | 2183 | return -EINVAL; |
@@ -2155,7 +2193,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); | |||
2155 | */ | 2193 | */ |
2156 | int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) | 2194 | int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) |
2157 | { | 2195 | { |
2158 | if (dai->ops->set_sysclk) | 2196 | if (dai->ops && dai->ops->set_tristate) |
2159 | return dai->ops->set_tristate(dai, tristate); | 2197 | return dai->ops->set_tristate(dai, tristate); |
2160 | else | 2198 | else |
2161 | return -EINVAL; | 2199 | return -EINVAL; |
@@ -2171,7 +2209,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); | |||
2171 | */ | 2209 | */ |
2172 | int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) | 2210 | int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) |
2173 | { | 2211 | { |
2174 | if (dai->ops->digital_mute) | 2212 | if (dai->ops && dai->ops->digital_mute) |
2175 | return dai->ops->digital_mute(dai, mute); | 2213 | return dai->ops->digital_mute(dai, mute); |
2176 | else | 2214 | else |
2177 | return -EINVAL; | 2215 | return -EINVAL; |
@@ -2352,6 +2390,39 @@ void snd_soc_unregister_platform(struct snd_soc_platform *platform) | |||
2352 | } | 2390 | } |
2353 | EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); | 2391 | EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); |
2354 | 2392 | ||
2393 | static u64 codec_format_map[] = { | ||
2394 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE, | ||
2395 | SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE, | ||
2396 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE, | ||
2397 | SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, | ||
2398 | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, | ||
2399 | SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE, | ||
2400 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, | ||
2401 | SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, | ||
2402 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE, | ||
2403 | SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE, | ||
2404 | SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE, | ||
2405 | SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE, | ||
2406 | SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE, | ||
2407 | SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE, | ||
2408 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE | ||
2409 | | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE, | ||
2410 | }; | ||
2411 | |||
2412 | /* Fix up the DAI formats for endianness: codecs don't actually see | ||
2413 | * the endianness of the data but we're using the CPU format | ||
2414 | * definitions which do need to include endianness so we ensure that | ||
2415 | * codec DAIs always have both big and little endian variants set. | ||
2416 | */ | ||
2417 | static void fixup_codec_formats(struct snd_soc_pcm_stream *stream) | ||
2418 | { | ||
2419 | int i; | ||
2420 | |||
2421 | for (i = 0; i < ARRAY_SIZE(codec_format_map); i++) | ||
2422 | if (stream->formats & codec_format_map[i]) | ||
2423 | stream->formats |= codec_format_map[i]; | ||
2424 | } | ||
2425 | |||
2355 | /** | 2426 | /** |
2356 | * snd_soc_register_codec - Register a codec with the ASoC core | 2427 | * snd_soc_register_codec - Register a codec with the ASoC core |
2357 | * | 2428 | * |
@@ -2359,6 +2430,8 @@ EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); | |||
2359 | */ | 2430 | */ |
2360 | int snd_soc_register_codec(struct snd_soc_codec *codec) | 2431 | int snd_soc_register_codec(struct snd_soc_codec *codec) |
2361 | { | 2432 | { |
2433 | int i; | ||
2434 | |||
2362 | if (!codec->name) | 2435 | if (!codec->name) |
2363 | return -EINVAL; | 2436 | return -EINVAL; |
2364 | 2437 | ||
@@ -2368,6 +2441,11 @@ int snd_soc_register_codec(struct snd_soc_codec *codec) | |||
2368 | 2441 | ||
2369 | INIT_LIST_HEAD(&codec->list); | 2442 | INIT_LIST_HEAD(&codec->list); |
2370 | 2443 | ||
2444 | for (i = 0; i < codec->num_dai; i++) { | ||
2445 | fixup_codec_formats(&codec->dai[i].playback); | ||
2446 | fixup_codec_formats(&codec->dai[i].capture); | ||
2447 | } | ||
2448 | |||
2371 | mutex_lock(&client_mutex); | 2449 | mutex_lock(&client_mutex); |
2372 | list_add(&codec->list, &codec_list); | 2450 | list_add(&codec->list, &codec_list); |
2373 | snd_soc_instantiate_cards(); | 2451 | snd_soc_instantiate_cards(); |
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 735903a74675..7847f80e96d1 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c | |||
@@ -52,17 +52,19 @@ | |||
52 | 52 | ||
53 | /* dapm power sequences - make this per codec in the future */ | 53 | /* dapm power sequences - make this per codec in the future */ |
54 | static int dapm_up_seq[] = { | 54 | static int dapm_up_seq[] = { |
55 | snd_soc_dapm_pre, snd_soc_dapm_micbias, snd_soc_dapm_mic, | 55 | snd_soc_dapm_pre, snd_soc_dapm_supply, snd_soc_dapm_micbias, |
56 | snd_soc_dapm_mux, snd_soc_dapm_value_mux, snd_soc_dapm_dac, | 56 | snd_soc_dapm_mic, snd_soc_dapm_mux, snd_soc_dapm_value_mux, |
57 | snd_soc_dapm_mixer, snd_soc_dapm_mixer_named_ctl, snd_soc_dapm_pga, | 57 | snd_soc_dapm_dac, snd_soc_dapm_mixer, snd_soc_dapm_mixer_named_ctl, |
58 | snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk, snd_soc_dapm_post | 58 | snd_soc_dapm_pga, snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk, |
59 | snd_soc_dapm_post | ||
59 | }; | 60 | }; |
60 | 61 | ||
61 | static int dapm_down_seq[] = { | 62 | static int dapm_down_seq[] = { |
62 | snd_soc_dapm_pre, snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk, | 63 | snd_soc_dapm_pre, snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk, |
63 | snd_soc_dapm_pga, snd_soc_dapm_mixer_named_ctl, snd_soc_dapm_mixer, | 64 | snd_soc_dapm_pga, snd_soc_dapm_mixer_named_ctl, snd_soc_dapm_mixer, |
64 | snd_soc_dapm_dac, snd_soc_dapm_mic, snd_soc_dapm_micbias, | 65 | snd_soc_dapm_dac, snd_soc_dapm_mic, snd_soc_dapm_micbias, |
65 | snd_soc_dapm_mux, snd_soc_dapm_value_mux, snd_soc_dapm_post | 66 | snd_soc_dapm_mux, snd_soc_dapm_value_mux, snd_soc_dapm_supply, |
67 | snd_soc_dapm_post | ||
66 | }; | 68 | }; |
67 | 69 | ||
68 | static int dapm_status = 1; | 70 | static int dapm_status = 1; |
@@ -165,6 +167,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w, | |||
165 | case snd_soc_dapm_dac: | 167 | case snd_soc_dapm_dac: |
166 | case snd_soc_dapm_micbias: | 168 | case snd_soc_dapm_micbias: |
167 | case snd_soc_dapm_vmid: | 169 | case snd_soc_dapm_vmid: |
170 | case snd_soc_dapm_supply: | ||
168 | p->connect = 1; | 171 | p->connect = 1; |
169 | break; | 172 | break; |
170 | /* does effect routing - dynamically connected */ | 173 | /* does effect routing - dynamically connected */ |
@@ -357,8 +360,9 @@ static int dapm_new_mixer(struct snd_soc_codec *codec, | |||
357 | path->long_name); | 360 | path->long_name); |
358 | ret = snd_ctl_add(codec->card, path->kcontrol); | 361 | ret = snd_ctl_add(codec->card, path->kcontrol); |
359 | if (ret < 0) { | 362 | if (ret < 0) { |
360 | printk(KERN_ERR "asoc: failed to add dapm kcontrol %s\n", | 363 | printk(KERN_ERR "asoc: failed to add dapm kcontrol %s: %d\n", |
361 | path->long_name); | 364 | path->long_name, |
365 | ret); | ||
362 | kfree(path->long_name); | 366 | kfree(path->long_name); |
363 | path->long_name = NULL; | 367 | path->long_name = NULL; |
364 | return ret; | 368 | return ret; |
@@ -434,6 +438,9 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget) | |||
434 | struct snd_soc_dapm_path *path; | 438 | struct snd_soc_dapm_path *path; |
435 | int con = 0; | 439 | int con = 0; |
436 | 440 | ||
441 | if (widget->id == snd_soc_dapm_supply) | ||
442 | return 0; | ||
443 | |||
437 | if (widget->id == snd_soc_dapm_adc && widget->active) | 444 | if (widget->id == snd_soc_dapm_adc && widget->active) |
438 | return 1; | 445 | return 1; |
439 | 446 | ||
@@ -470,6 +477,9 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget) | |||
470 | struct snd_soc_dapm_path *path; | 477 | struct snd_soc_dapm_path *path; |
471 | int con = 0; | 478 | int con = 0; |
472 | 479 | ||
480 | if (widget->id == snd_soc_dapm_supply) | ||
481 | return 0; | ||
482 | |||
473 | /* active stream ? */ | 483 | /* active stream ? */ |
474 | if (widget->id == snd_soc_dapm_dac && widget->active) | 484 | if (widget->id == snd_soc_dapm_dac && widget->active) |
475 | return 1; | 485 | return 1; |
@@ -521,39 +531,137 @@ int dapm_reg_event(struct snd_soc_dapm_widget *w, | |||
521 | } | 531 | } |
522 | EXPORT_SYMBOL_GPL(dapm_reg_event); | 532 | EXPORT_SYMBOL_GPL(dapm_reg_event); |
523 | 533 | ||
524 | /* | 534 | /* Standard power change method, used to apply power changes to most |
525 | * Scan a single DAPM widget for a complete audio path and update the | 535 | * widgets. |
526 | * power status appropriately. | ||
527 | */ | 536 | */ |
528 | static int dapm_power_widget(struct snd_soc_codec *codec, int event, | 537 | static int dapm_generic_apply_power(struct snd_soc_dapm_widget *w) |
529 | struct snd_soc_dapm_widget *w) | ||
530 | { | 538 | { |
531 | int in, out, power_change, power, ret; | 539 | int ret; |
532 | 540 | ||
533 | /* vmid - no action */ | 541 | /* call any power change event handlers */ |
534 | if (w->id == snd_soc_dapm_vmid) | 542 | if (w->event) |
535 | return 0; | 543 | pr_debug("power %s event for %s flags %x\n", |
544 | w->power ? "on" : "off", | ||
545 | w->name, w->event_flags); | ||
546 | |||
547 | /* power up pre event */ | ||
548 | if (w->power && w->event && | ||
549 | (w->event_flags & SND_SOC_DAPM_PRE_PMU)) { | ||
550 | ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU); | ||
551 | if (ret < 0) | ||
552 | return ret; | ||
553 | } | ||
536 | 554 | ||
537 | /* active ADC */ | 555 | /* power down pre event */ |
538 | if (w->id == snd_soc_dapm_adc && w->active) { | 556 | if (!w->power && w->event && |
557 | (w->event_flags & SND_SOC_DAPM_PRE_PMD)) { | ||
558 | ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD); | ||
559 | if (ret < 0) | ||
560 | return ret; | ||
561 | } | ||
562 | |||
563 | /* Lower PGA volume to reduce pops */ | ||
564 | if (w->id == snd_soc_dapm_pga && !w->power) | ||
565 | dapm_set_pga(w, w->power); | ||
566 | |||
567 | dapm_update_bits(w); | ||
568 | |||
569 | /* Raise PGA volume to reduce pops */ | ||
570 | if (w->id == snd_soc_dapm_pga && w->power) | ||
571 | dapm_set_pga(w, w->power); | ||
572 | |||
573 | /* power up post event */ | ||
574 | if (w->power && w->event && | ||
575 | (w->event_flags & SND_SOC_DAPM_POST_PMU)) { | ||
576 | ret = w->event(w, | ||
577 | NULL, SND_SOC_DAPM_POST_PMU); | ||
578 | if (ret < 0) | ||
579 | return ret; | ||
580 | } | ||
581 | |||
582 | /* power down post event */ | ||
583 | if (!w->power && w->event && | ||
584 | (w->event_flags & SND_SOC_DAPM_POST_PMD)) { | ||
585 | ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD); | ||
586 | if (ret < 0) | ||
587 | return ret; | ||
588 | } | ||
589 | |||
590 | return 0; | ||
591 | } | ||
592 | |||
593 | /* Generic check to see if a widget should be powered. | ||
594 | */ | ||
595 | static int dapm_generic_check_power(struct snd_soc_dapm_widget *w) | ||
596 | { | ||
597 | int in, out; | ||
598 | |||
599 | in = is_connected_input_ep(w); | ||
600 | dapm_clear_walk(w->codec); | ||
601 | out = is_connected_output_ep(w); | ||
602 | dapm_clear_walk(w->codec); | ||
603 | return out != 0 && in != 0; | ||
604 | } | ||
605 | |||
606 | /* Check to see if an ADC has power */ | ||
607 | static int dapm_adc_check_power(struct snd_soc_dapm_widget *w) | ||
608 | { | ||
609 | int in; | ||
610 | |||
611 | if (w->active) { | ||
539 | in = is_connected_input_ep(w); | 612 | in = is_connected_input_ep(w); |
540 | dapm_clear_walk(w->codec); | 613 | dapm_clear_walk(w->codec); |
541 | w->power = (in != 0) ? 1 : 0; | 614 | return in != 0; |
542 | dapm_update_bits(w); | 615 | } else { |
543 | return 0; | 616 | return dapm_generic_check_power(w); |
544 | } | 617 | } |
618 | } | ||
545 | 619 | ||
546 | /* active DAC */ | 620 | /* Check to see if a DAC has power */ |
547 | if (w->id == snd_soc_dapm_dac && w->active) { | 621 | static int dapm_dac_check_power(struct snd_soc_dapm_widget *w) |
622 | { | ||
623 | int out; | ||
624 | |||
625 | if (w->active) { | ||
548 | out = is_connected_output_ep(w); | 626 | out = is_connected_output_ep(w); |
549 | dapm_clear_walk(w->codec); | 627 | dapm_clear_walk(w->codec); |
550 | w->power = (out != 0) ? 1 : 0; | 628 | return out != 0; |
551 | dapm_update_bits(w); | 629 | } else { |
552 | return 0; | 630 | return dapm_generic_check_power(w); |
631 | } | ||
632 | } | ||
633 | |||
634 | /* Check to see if a power supply is needed */ | ||
635 | static int dapm_supply_check_power(struct snd_soc_dapm_widget *w) | ||
636 | { | ||
637 | struct snd_soc_dapm_path *path; | ||
638 | int power = 0; | ||
639 | |||
640 | /* Check if one of our outputs is connected */ | ||
641 | list_for_each_entry(path, &w->sinks, list_source) { | ||
642 | if (path->sink && path->sink->power_check && | ||
643 | path->sink->power_check(path->sink)) { | ||
644 | power = 1; | ||
645 | break; | ||
646 | } | ||
553 | } | 647 | } |
554 | 648 | ||
555 | /* pre and post event widgets */ | 649 | dapm_clear_walk(w->codec); |
556 | if (w->id == snd_soc_dapm_pre) { | 650 | |
651 | return power; | ||
652 | } | ||
653 | |||
654 | /* | ||
655 | * Scan a single DAPM widget for a complete audio path and update the | ||
656 | * power status appropriately. | ||
657 | */ | ||
658 | static int dapm_power_widget(struct snd_soc_codec *codec, int event, | ||
659 | struct snd_soc_dapm_widget *w) | ||
660 | { | ||
661 | int power, ret; | ||
662 | |||
663 | switch (w->id) { | ||
664 | case snd_soc_dapm_pre: | ||
557 | if (!w->event) | 665 | if (!w->event) |
558 | return 0; | 666 | return 0; |
559 | 667 | ||
@@ -569,8 +677,8 @@ static int dapm_power_widget(struct snd_soc_codec *codec, int event, | |||
569 | return ret; | 677 | return ret; |
570 | } | 678 | } |
571 | return 0; | 679 | return 0; |
572 | } | 680 | |
573 | if (w->id == snd_soc_dapm_post) { | 681 | case snd_soc_dapm_post: |
574 | if (!w->event) | 682 | if (!w->event) |
575 | return 0; | 683 | return 0; |
576 | 684 | ||
@@ -586,70 +694,20 @@ static int dapm_power_widget(struct snd_soc_codec *codec, int event, | |||
586 | return ret; | 694 | return ret; |
587 | } | 695 | } |
588 | return 0; | 696 | return 0; |
589 | } | ||
590 | |||
591 | /* all other widgets */ | ||
592 | in = is_connected_input_ep(w); | ||
593 | dapm_clear_walk(w->codec); | ||
594 | out = is_connected_output_ep(w); | ||
595 | dapm_clear_walk(w->codec); | ||
596 | power = (out != 0 && in != 0) ? 1 : 0; | ||
597 | power_change = (w->power == power) ? 0 : 1; | ||
598 | w->power = power; | ||
599 | 697 | ||
600 | if (!power_change) | 698 | default: |
601 | return 0; | 699 | break; |
602 | |||
603 | /* call any power change event handlers */ | ||
604 | if (w->event) | ||
605 | pr_debug("power %s event for %s flags %x\n", | ||
606 | w->power ? "on" : "off", | ||
607 | w->name, w->event_flags); | ||
608 | |||
609 | /* power up pre event */ | ||
610 | if (power && w->event && | ||
611 | (w->event_flags & SND_SOC_DAPM_PRE_PMU)) { | ||
612 | ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU); | ||
613 | if (ret < 0) | ||
614 | return ret; | ||
615 | } | ||
616 | |||
617 | /* power down pre event */ | ||
618 | if (!power && w->event && | ||
619 | (w->event_flags & SND_SOC_DAPM_PRE_PMD)) { | ||
620 | ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD); | ||
621 | if (ret < 0) | ||
622 | return ret; | ||
623 | } | 700 | } |
624 | 701 | ||
625 | /* Lower PGA volume to reduce pops */ | 702 | if (!w->power_check) |
626 | if (w->id == snd_soc_dapm_pga && !power) | 703 | return 0; |
627 | dapm_set_pga(w, power); | ||
628 | |||
629 | dapm_update_bits(w); | ||
630 | |||
631 | /* Raise PGA volume to reduce pops */ | ||
632 | if (w->id == snd_soc_dapm_pga && power) | ||
633 | dapm_set_pga(w, power); | ||
634 | |||
635 | /* power up post event */ | ||
636 | if (power && w->event && | ||
637 | (w->event_flags & SND_SOC_DAPM_POST_PMU)) { | ||
638 | ret = w->event(w, | ||
639 | NULL, SND_SOC_DAPM_POST_PMU); | ||
640 | if (ret < 0) | ||
641 | return ret; | ||
642 | } | ||
643 | 704 | ||
644 | /* power down post event */ | 705 | power = w->power_check(w); |
645 | if (!power && w->event && | 706 | if (w->power == power) |
646 | (w->event_flags & SND_SOC_DAPM_POST_PMD)) { | 707 | return 0; |
647 | ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD); | 708 | w->power = power; |
648 | if (ret < 0) | ||
649 | return ret; | ||
650 | } | ||
651 | 709 | ||
652 | return 0; | 710 | return dapm_generic_apply_power(w); |
653 | } | 711 | } |
654 | 712 | ||
655 | /* | 713 | /* |
@@ -723,6 +781,7 @@ static void dbg_dump_dapm(struct snd_soc_codec* codec, const char *action) | |||
723 | case snd_soc_dapm_pga: | 781 | case snd_soc_dapm_pga: |
724 | case snd_soc_dapm_mixer: | 782 | case snd_soc_dapm_mixer: |
725 | case snd_soc_dapm_mixer_named_ctl: | 783 | case snd_soc_dapm_mixer_named_ctl: |
784 | case snd_soc_dapm_supply: | ||
726 | if (w->name) { | 785 | if (w->name) { |
727 | in = is_connected_input_ep(w); | 786 | in = is_connected_input_ep(w); |
728 | dapm_clear_walk(w->codec); | 787 | dapm_clear_walk(w->codec); |
@@ -851,6 +910,7 @@ static ssize_t dapm_widget_show(struct device *dev, | |||
851 | case snd_soc_dapm_pga: | 910 | case snd_soc_dapm_pga: |
852 | case snd_soc_dapm_mixer: | 911 | case snd_soc_dapm_mixer: |
853 | case snd_soc_dapm_mixer_named_ctl: | 912 | case snd_soc_dapm_mixer_named_ctl: |
913 | case snd_soc_dapm_supply: | ||
854 | if (w->name) | 914 | if (w->name) |
855 | count += sprintf(buf + count, "%s: %s\n", | 915 | count += sprintf(buf + count, "%s: %s\n", |
856 | w->name, w->power ? "On":"Off"); | 916 | w->name, w->power ? "On":"Off"); |
@@ -1015,6 +1075,7 @@ static int snd_soc_dapm_add_route(struct snd_soc_codec *codec, | |||
1015 | case snd_soc_dapm_vmid: | 1075 | case snd_soc_dapm_vmid: |
1016 | case snd_soc_dapm_pre: | 1076 | case snd_soc_dapm_pre: |
1017 | case snd_soc_dapm_post: | 1077 | case snd_soc_dapm_post: |
1078 | case snd_soc_dapm_supply: | ||
1018 | list_add(&path->list, &codec->dapm_paths); | 1079 | list_add(&path->list, &codec->dapm_paths); |
1019 | list_add(&path->list_sink, &wsink->sources); | 1080 | list_add(&path->list_sink, &wsink->sources); |
1020 | list_add(&path->list_source, &wsource->sinks); | 1081 | list_add(&path->list_source, &wsource->sinks); |
@@ -1108,15 +1169,22 @@ int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec) | |||
1108 | case snd_soc_dapm_switch: | 1169 | case snd_soc_dapm_switch: |
1109 | case snd_soc_dapm_mixer: | 1170 | case snd_soc_dapm_mixer: |
1110 | case snd_soc_dapm_mixer_named_ctl: | 1171 | case snd_soc_dapm_mixer_named_ctl: |
1172 | w->power_check = dapm_generic_check_power; | ||
1111 | dapm_new_mixer(codec, w); | 1173 | dapm_new_mixer(codec, w); |
1112 | break; | 1174 | break; |
1113 | case snd_soc_dapm_mux: | 1175 | case snd_soc_dapm_mux: |
1114 | case snd_soc_dapm_value_mux: | 1176 | case snd_soc_dapm_value_mux: |
1177 | w->power_check = dapm_generic_check_power; | ||
1115 | dapm_new_mux(codec, w); | 1178 | dapm_new_mux(codec, w); |
1116 | break; | 1179 | break; |
1117 | case snd_soc_dapm_adc: | 1180 | case snd_soc_dapm_adc: |
1181 | w->power_check = dapm_adc_check_power; | ||
1182 | break; | ||
1118 | case snd_soc_dapm_dac: | 1183 | case snd_soc_dapm_dac: |
1184 | w->power_check = dapm_dac_check_power; | ||
1185 | break; | ||
1119 | case snd_soc_dapm_pga: | 1186 | case snd_soc_dapm_pga: |
1187 | w->power_check = dapm_generic_check_power; | ||
1120 | dapm_new_pga(codec, w); | 1188 | dapm_new_pga(codec, w); |
1121 | break; | 1189 | break; |
1122 | case snd_soc_dapm_input: | 1190 | case snd_soc_dapm_input: |
@@ -1126,6 +1194,10 @@ int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec) | |||
1126 | case snd_soc_dapm_hp: | 1194 | case snd_soc_dapm_hp: |
1127 | case snd_soc_dapm_mic: | 1195 | case snd_soc_dapm_mic: |
1128 | case snd_soc_dapm_line: | 1196 | case snd_soc_dapm_line: |
1197 | w->power_check = dapm_generic_check_power; | ||
1198 | break; | ||
1199 | case snd_soc_dapm_supply: | ||
1200 | w->power_check = dapm_supply_check_power; | ||
1129 | case snd_soc_dapm_vmid: | 1201 | case snd_soc_dapm_vmid: |
1130 | case snd_soc_dapm_pre: | 1202 | case snd_soc_dapm_pre: |
1131 | case snd_soc_dapm_post: | 1203 | case snd_soc_dapm_post: |