diff options
Diffstat (limited to 'sound/soc/codecs')
39 files changed, 5854 insertions, 617 deletions
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 38a0e3b620a7..c41289b5f586 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig | |||
@@ -1,31 +1,40 @@ | |||
1 | config SND_SOC_ALL_CODECS | 1 | config SND_SOC_ALL_CODECS |
2 | tristate "Build all ASoC CODEC drivers" | 2 | tristate "Build all ASoC CODEC drivers" |
3 | depends on I2C | 3 | select SND_SOC_AC97_CODEC if SND_SOC_AC97_BUS |
4 | select SPI | 4 | select SND_SOC_AD1980 if SND_SOC_AC97_BUS |
5 | select SPI_MASTER | 5 | select SND_SOC_AD73311 if I2C |
6 | select SND_SOC_AD73311 | 6 | select SND_SOC_AK4535 if I2C |
7 | select SND_SOC_AK4535 | 7 | select SND_SOC_CS4270 if I2C |
8 | select SND_SOC_CS4270 | 8 | select SND_SOC_PCM3008 |
9 | select SND_SOC_SSM2602 | 9 | select SND_SOC_SSM2602 if I2C |
10 | select SND_SOC_TLV320AIC23 | 10 | select SND_SOC_TLV320AIC23 if I2C |
11 | select SND_SOC_TLV320AIC26 | 11 | select SND_SOC_TLV320AIC26 if SPI_MASTER |
12 | select SND_SOC_TLV320AIC3X | 12 | select SND_SOC_TLV320AIC3X if I2C |
13 | select SND_SOC_UDA1380 | 13 | select SND_SOC_TWL4030 if TWL4030_CORE |
14 | select SND_SOC_WM8510 | 14 | select SND_SOC_UDA134X |
15 | select SND_SOC_WM8580 | 15 | select SND_SOC_UDA1380 if I2C |
16 | select SND_SOC_WM8731 | 16 | select SND_SOC_WM8350 if MFD_WM8350 |
17 | select SND_SOC_WM8750 | 17 | select SND_SOC_WM8510 if (I2C || SPI_MASTER) |
18 | select SND_SOC_WM8753 | 18 | select SND_SOC_WM8580 if I2C |
19 | select SND_SOC_WM8900 | 19 | select SND_SOC_WM8728 if (I2C || SPI_MASTER) |
20 | select SND_SOC_WM8903 | 20 | select SND_SOC_WM8731 if (I2C || SPI_MASTER) |
21 | select SND_SOC_WM8971 | 21 | select SND_SOC_WM8750 if (I2C || SPI_MASTER) |
22 | select SND_SOC_WM8990 | 22 | select SND_SOC_WM8753 if (I2C || SPI_MASTER) |
23 | select SND_SOC_WM8900 if I2C | ||
24 | select SND_SOC_WM8903 if I2C | ||
25 | select SND_SOC_WM8971 if I2C | ||
26 | select SND_SOC_WM8990 if I2C | ||
27 | select SND_SOC_WM9712 if SND_SOC_AC97_BUS | ||
28 | select SND_SOC_WM9713 if SND_SOC_AC97_BUS | ||
23 | help | 29 | help |
24 | Normally ASoC codec drivers are only built if a machine driver which | 30 | Normally ASoC codec drivers are only built if a machine driver which |
25 | uses them is also built since they are only usable with a machine | 31 | uses them is also built since they are only usable with a machine |
26 | driver. Selecting this option will allow these drivers to be built | 32 | driver. Selecting this option will allow these drivers to be built |
27 | without an explicit machine driver for test and development purposes. | 33 | without an explicit machine driver for test and development purposes. |
28 | 34 | ||
35 | Support for the bus types used to access the codecs to be built must | ||
36 | be selected separately. | ||
37 | |||
29 | If unsure select "N". | 38 | If unsure select "N". |
30 | 39 | ||
31 | 40 | ||
@@ -60,6 +69,12 @@ config SND_SOC_CS4270_VD33_ERRATA | |||
60 | bool | 69 | bool |
61 | depends on SND_SOC_CS4270 | 70 | depends on SND_SOC_CS4270 |
62 | 71 | ||
72 | config SND_SOC_L3 | ||
73 | tristate | ||
74 | |||
75 | config SND_SOC_PCM3008 | ||
76 | tristate | ||
77 | |||
63 | config SND_SOC_SSM2602 | 78 | config SND_SOC_SSM2602 |
64 | tristate | 79 | tristate |
65 | 80 | ||
@@ -75,15 +90,29 @@ config SND_SOC_TLV320AIC3X | |||
75 | tristate | 90 | tristate |
76 | depends on I2C | 91 | depends on I2C |
77 | 92 | ||
93 | config SND_SOC_TWL4030 | ||
94 | tristate | ||
95 | depends on TWL4030_CORE | ||
96 | |||
97 | config SND_SOC_UDA134X | ||
98 | tristate | ||
99 | select SND_SOC_L3 | ||
100 | |||
78 | config SND_SOC_UDA1380 | 101 | config SND_SOC_UDA1380 |
79 | tristate | 102 | tristate |
80 | 103 | ||
104 | config SND_SOC_WM8350 | ||
105 | tristate | ||
106 | |||
81 | config SND_SOC_WM8510 | 107 | config SND_SOC_WM8510 |
82 | tristate | 108 | tristate |
83 | 109 | ||
84 | config SND_SOC_WM8580 | 110 | config SND_SOC_WM8580 |
85 | tristate | 111 | tristate |
86 | 112 | ||
113 | config SND_SOC_WM8728 | ||
114 | tristate | ||
115 | |||
87 | config SND_SOC_WM8731 | 116 | config SND_SOC_WM8731 |
88 | tristate | 117 | tristate |
89 | 118 | ||
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 90f0a585fc70..c4ddc9aa2bbd 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile | |||
@@ -3,13 +3,19 @@ snd-soc-ad1980-objs := ad1980.o | |||
3 | snd-soc-ad73311-objs := ad73311.o | 3 | snd-soc-ad73311-objs := ad73311.o |
4 | snd-soc-ak4535-objs := ak4535.o | 4 | snd-soc-ak4535-objs := ak4535.o |
5 | snd-soc-cs4270-objs := cs4270.o | 5 | snd-soc-cs4270-objs := cs4270.o |
6 | snd-soc-l3-objs := l3.o | ||
7 | snd-soc-pcm3008-objs := pcm3008.o | ||
6 | snd-soc-ssm2602-objs := ssm2602.o | 8 | snd-soc-ssm2602-objs := ssm2602.o |
7 | snd-soc-tlv320aic23-objs := tlv320aic23.o | 9 | snd-soc-tlv320aic23-objs := tlv320aic23.o |
8 | snd-soc-tlv320aic26-objs := tlv320aic26.o | 10 | snd-soc-tlv320aic26-objs := tlv320aic26.o |
9 | snd-soc-tlv320aic3x-objs := tlv320aic3x.o | 11 | snd-soc-tlv320aic3x-objs := tlv320aic3x.o |
12 | snd-soc-twl4030-objs := twl4030.o | ||
13 | snd-soc-uda134x-objs := uda134x.o | ||
10 | snd-soc-uda1380-objs := uda1380.o | 14 | snd-soc-uda1380-objs := uda1380.o |
15 | snd-soc-wm8350-objs := wm8350.o | ||
11 | snd-soc-wm8510-objs := wm8510.o | 16 | snd-soc-wm8510-objs := wm8510.o |
12 | snd-soc-wm8580-objs := wm8580.o | 17 | snd-soc-wm8580-objs := wm8580.o |
18 | snd-soc-wm8728-objs := wm8728.o | ||
13 | snd-soc-wm8731-objs := wm8731.o | 19 | snd-soc-wm8731-objs := wm8731.o |
14 | snd-soc-wm8750-objs := wm8750.o | 20 | snd-soc-wm8750-objs := wm8750.o |
15 | snd-soc-wm8753-objs := wm8753.o | 21 | snd-soc-wm8753-objs := wm8753.o |
@@ -25,13 +31,19 @@ obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o | |||
25 | obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o | 31 | obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o |
26 | obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o | 32 | obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o |
27 | obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o | 33 | obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o |
34 | obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o | ||
35 | obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o | ||
28 | obj-$(CONFIG_SND_SOC_SSM2602) += snd-soc-ssm2602.o | 36 | obj-$(CONFIG_SND_SOC_SSM2602) += snd-soc-ssm2602.o |
29 | obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o | 37 | obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o |
30 | obj-$(CONFIG_SND_SOC_TLV320AIC26) += snd-soc-tlv320aic26.o | 38 | obj-$(CONFIG_SND_SOC_TLV320AIC26) += snd-soc-tlv320aic26.o |
31 | obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o | 39 | obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o |
40 | obj-$(CONFIG_SND_SOC_TWL4030) += snd-soc-twl4030.o | ||
41 | obj-$(CONFIG_SND_SOC_UDA134X) += snd-soc-uda134x.o | ||
32 | obj-$(CONFIG_SND_SOC_UDA1380) += snd-soc-uda1380.o | 42 | obj-$(CONFIG_SND_SOC_UDA1380) += snd-soc-uda1380.o |
43 | obj-$(CONFIG_SND_SOC_WM8350) += snd-soc-wm8350.o | ||
33 | obj-$(CONFIG_SND_SOC_WM8510) += snd-soc-wm8510.o | 44 | obj-$(CONFIG_SND_SOC_WM8510) += snd-soc-wm8510.o |
34 | obj-$(CONFIG_SND_SOC_WM8580) += snd-soc-wm8580.o | 45 | obj-$(CONFIG_SND_SOC_WM8580) += snd-soc-wm8580.o |
46 | obj-$(CONFIG_SND_SOC_WM8728) += snd-soc-wm8728.o | ||
35 | obj-$(CONFIG_SND_SOC_WM8731) += snd-soc-wm8731.o | 47 | obj-$(CONFIG_SND_SOC_WM8731) += snd-soc-wm8731.o |
36 | obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o | 48 | obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o |
37 | obj-$(CONFIG_SND_SOC_WM8753) += snd-soc-wm8753.o | 49 | obj-$(CONFIG_SND_SOC_WM8753) += snd-soc-wm8753.o |
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c index bd1ebdc6c86c..fb53e6511af2 100644 --- a/sound/soc/codecs/ac97.c +++ b/sound/soc/codecs/ac97.c | |||
@@ -24,7 +24,8 @@ | |||
24 | 24 | ||
25 | #define AC97_VERSION "0.6" | 25 | #define AC97_VERSION "0.6" |
26 | 26 | ||
27 | static int ac97_prepare(struct snd_pcm_substream *substream) | 27 | static int ac97_prepare(struct snd_pcm_substream *substream, |
28 | struct snd_soc_dai *dai) | ||
28 | { | 29 | { |
29 | struct snd_pcm_runtime *runtime = substream->runtime; | 30 | struct snd_pcm_runtime *runtime = substream->runtime; |
30 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 31 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
@@ -42,7 +43,7 @@ static int ac97_prepare(struct snd_pcm_substream *substream) | |||
42 | 43 | ||
43 | struct snd_soc_dai ac97_dai = { | 44 | struct snd_soc_dai ac97_dai = { |
44 | .name = "AC97 HiFi", | 45 | .name = "AC97 HiFi", |
45 | .type = SND_SOC_DAI_AC97, | 46 | .ac97_control = 1, |
46 | .playback = { | 47 | .playback = { |
47 | .stream_name = "AC97 Playback", | 48 | .stream_name = "AC97 Playback", |
48 | .channels_min = 1, | 49 | .channels_min = 1, |
@@ -113,7 +114,7 @@ static int ac97_soc_probe(struct platform_device *pdev) | |||
113 | if (ret < 0) | 114 | if (ret < 0) |
114 | goto bus_err; | 115 | goto bus_err; |
115 | 116 | ||
116 | ret = snd_soc_register_card(socdev); | 117 | ret = snd_soc_init_card(socdev); |
117 | if (ret < 0) | 118 | if (ret < 0) |
118 | goto bus_err; | 119 | goto bus_err; |
119 | return 0; | 120 | return 0; |
diff --git a/sound/soc/codecs/ad1980.c b/sound/soc/codecs/ad1980.c index 1397b8e06c0b..73fdbb4d4a3d 100644 --- a/sound/soc/codecs/ad1980.c +++ b/sound/soc/codecs/ad1980.c | |||
@@ -85,6 +85,9 @@ SOC_DOUBLE("Line HP Swap Switch", AC97_AD_MISC, 10, 5, 1, 0), | |||
85 | SOC_DOUBLE("Surround Playback Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1), | 85 | SOC_DOUBLE("Surround Playback Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1), |
86 | SOC_DOUBLE("Surround Playback Switch", AC97_SURROUND_MASTER, 15, 7, 1, 1), | 86 | SOC_DOUBLE("Surround Playback Switch", AC97_SURROUND_MASTER, 15, 7, 1, 1), |
87 | 87 | ||
88 | SOC_DOUBLE("Center/LFE Playback Volume", AC97_CENTER_LFE_MASTER, 8, 0, 31, 1), | ||
89 | SOC_DOUBLE("Center/LFE Playback Switch", AC97_CENTER_LFE_MASTER, 15, 7, 1, 1), | ||
90 | |||
88 | SOC_ENUM("Capture Source", ad1980_cap_src), | 91 | SOC_ENUM("Capture Source", ad1980_cap_src), |
89 | 92 | ||
90 | SOC_SINGLE("Mic Boost Switch", AC97_MIC, 6, 1, 0), | 93 | SOC_SINGLE("Mic Boost Switch", AC97_MIC, 6, 1, 0), |
@@ -142,10 +145,11 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, | |||
142 | 145 | ||
143 | struct snd_soc_dai ad1980_dai = { | 146 | struct snd_soc_dai ad1980_dai = { |
144 | .name = "AC97", | 147 | .name = "AC97", |
148 | .ac97_control = 1, | ||
145 | .playback = { | 149 | .playback = { |
146 | .stream_name = "Playback", | 150 | .stream_name = "Playback", |
147 | .channels_min = 2, | 151 | .channels_min = 2, |
148 | .channels_max = 2, | 152 | .channels_max = 6, |
149 | .rates = SNDRV_PCM_RATE_48000, | 153 | .rates = SNDRV_PCM_RATE_48000, |
150 | .formats = SNDRV_PCM_FMTBIT_S16_LE, }, | 154 | .formats = SNDRV_PCM_FMTBIT_S16_LE, }, |
151 | .capture = { | 155 | .capture = { |
@@ -192,6 +196,7 @@ static int ad1980_soc_probe(struct platform_device *pdev) | |||
192 | struct snd_soc_codec *codec; | 196 | struct snd_soc_codec *codec; |
193 | int ret = 0; | 197 | int ret = 0; |
194 | u16 vendor_id2; | 198 | u16 vendor_id2; |
199 | u16 ext_status; | ||
195 | 200 | ||
196 | printk(KERN_INFO "AD1980 SoC Audio Codec\n"); | 201 | printk(KERN_INFO "AD1980 SoC Audio Codec\n"); |
197 | 202 | ||
@@ -234,7 +239,7 @@ static int ad1980_soc_probe(struct platform_device *pdev) | |||
234 | 239 | ||
235 | ret = ad1980_reset(codec, 0); | 240 | ret = ad1980_reset(codec, 0); |
236 | if (ret < 0) { | 241 | if (ret < 0) { |
237 | printk(KERN_ERR "AC97 link error\n"); | 242 | printk(KERN_ERR "Failed to reset AD1980: AC97 link error\n"); |
238 | goto reset_err; | 243 | goto reset_err; |
239 | } | 244 | } |
240 | 245 | ||
@@ -253,12 +258,19 @@ static int ad1980_soc_probe(struct platform_device *pdev) | |||
253 | "supported\n"); | 258 | "supported\n"); |
254 | } | 259 | } |
255 | 260 | ||
256 | ac97_write(codec, AC97_MASTER, 0x0000); /* unmute line out volume */ | 261 | /* unmute captures and playbacks volume */ |
257 | ac97_write(codec, AC97_PCM, 0x0000); /* unmute PCM out volume */ | 262 | ac97_write(codec, AC97_MASTER, 0x0000); |
258 | ac97_write(codec, AC97_REC_GAIN, 0x0000);/* unmute record volume */ | 263 | ac97_write(codec, AC97_PCM, 0x0000); |
264 | ac97_write(codec, AC97_REC_GAIN, 0x0000); | ||
265 | ac97_write(codec, AC97_CENTER_LFE_MASTER, 0x0000); | ||
266 | ac97_write(codec, AC97_SURROUND_MASTER, 0x0000); | ||
267 | |||
268 | /*power on LFE/CENTER/Surround DACs*/ | ||
269 | ext_status = ac97_read(codec, AC97_EXTENDED_STATUS); | ||
270 | ac97_write(codec, AC97_EXTENDED_STATUS, ext_status&~0x3800); | ||
259 | 271 | ||
260 | ad1980_add_controls(codec); | 272 | ad1980_add_controls(codec); |
261 | ret = snd_soc_register_card(socdev); | 273 | ret = snd_soc_init_card(socdev); |
262 | if (ret < 0) { | 274 | if (ret < 0) { |
263 | printk(KERN_ERR "ad1980: failed to register card\n"); | 275 | printk(KERN_ERR "ad1980: failed to register card\n"); |
264 | goto reset_err; | 276 | goto reset_err; |
diff --git a/sound/soc/codecs/ad73311.c b/sound/soc/codecs/ad73311.c index 37af8607b00a..b09289a1e55a 100644 --- a/sound/soc/codecs/ad73311.c +++ b/sound/soc/codecs/ad73311.c | |||
@@ -8,14 +8,10 @@ | |||
8 | * under the terms of the GNU General Public License as published by the | 8 | * under the terms of the GNU General Public License as published by the |
9 | * Free Software Foundation; either version 2 of the License, or (at your | 9 | * Free Software Foundation; either version 2 of the License, or (at your |
10 | * option) any later version. | 10 | * option) any later version. |
11 | * | ||
12 | * Revision history | ||
13 | * 25th Sep 2008 Initial version. | ||
14 | */ | 11 | */ |
15 | 12 | ||
16 | #include <linux/init.h> | 13 | #include <linux/init.h> |
17 | #include <linux/module.h> | 14 | #include <linux/module.h> |
18 | #include <linux/version.h> | ||
19 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
20 | #include <linux/device.h> | 16 | #include <linux/device.h> |
21 | #include <sound/core.h> | 17 | #include <sound/core.h> |
@@ -68,7 +64,7 @@ static int ad73311_soc_probe(struct platform_device *pdev) | |||
68 | goto pcm_err; | 64 | goto pcm_err; |
69 | } | 65 | } |
70 | 66 | ||
71 | ret = snd_soc_register_card(socdev); | 67 | ret = snd_soc_init_card(socdev); |
72 | if (ret < 0) { | 68 | if (ret < 0) { |
73 | printk(KERN_ERR "ad73311: failed to register card\n"); | 69 | printk(KERN_ERR "ad73311: failed to register card\n"); |
74 | goto register_err; | 70 | goto register_err; |
@@ -102,6 +98,18 @@ struct snd_soc_codec_device soc_codec_dev_ad73311 = { | |||
102 | }; | 98 | }; |
103 | EXPORT_SYMBOL_GPL(soc_codec_dev_ad73311); | 99 | EXPORT_SYMBOL_GPL(soc_codec_dev_ad73311); |
104 | 100 | ||
101 | static int __init ad73311_init(void) | ||
102 | { | ||
103 | return snd_soc_register_dai(&ad73311_dai); | ||
104 | } | ||
105 | module_init(ad73311_init); | ||
106 | |||
107 | static void __exit ad73311_exit(void) | ||
108 | { | ||
109 | snd_soc_unregister_dai(&ad73311_dai); | ||
110 | } | ||
111 | module_exit(ad73311_exit); | ||
112 | |||
105 | MODULE_DESCRIPTION("ASoC ad73311 driver"); | 113 | MODULE_DESCRIPTION("ASoC ad73311 driver"); |
106 | MODULE_AUTHOR("Cliff Cai "); | 114 | MODULE_AUTHOR("Cliff Cai "); |
107 | MODULE_LICENSE("GPL"); | 115 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c index 2a89b5888e11..81300d8d42ca 100644 --- a/sound/soc/codecs/ak4535.c +++ b/sound/soc/codecs/ak4535.c | |||
@@ -339,7 +339,8 @@ static int ak4535_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
339 | } | 339 | } |
340 | 340 | ||
341 | static int ak4535_hw_params(struct snd_pcm_substream *substream, | 341 | static int ak4535_hw_params(struct snd_pcm_substream *substream, |
342 | struct snd_pcm_hw_params *params) | 342 | struct snd_pcm_hw_params *params, |
343 | struct snd_soc_dai *dai) | ||
343 | { | 344 | { |
344 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 345 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
345 | struct snd_soc_device *socdev = rtd->socdev; | 346 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -451,8 +452,6 @@ struct snd_soc_dai ak4535_dai = { | |||
451 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 452 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
452 | .ops = { | 453 | .ops = { |
453 | .hw_params = ak4535_hw_params, | 454 | .hw_params = ak4535_hw_params, |
454 | }, | ||
455 | .dai_ops = { | ||
456 | .set_fmt = ak4535_set_dai_fmt, | 455 | .set_fmt = ak4535_set_dai_fmt, |
457 | .digital_mute = ak4535_mute, | 456 | .digital_mute = ak4535_mute, |
458 | .set_sysclk = ak4535_set_dai_sysclk, | 457 | .set_sysclk = ak4535_set_dai_sysclk, |
@@ -513,7 +512,7 @@ static int ak4535_init(struct snd_soc_device *socdev) | |||
513 | 512 | ||
514 | ak4535_add_controls(codec); | 513 | ak4535_add_controls(codec); |
515 | ak4535_add_widgets(codec); | 514 | ak4535_add_widgets(codec); |
516 | ret = snd_soc_register_card(socdev); | 515 | ret = snd_soc_init_card(socdev); |
517 | if (ret < 0) { | 516 | if (ret < 0) { |
518 | printk(KERN_ERR "ak4535: failed to register card\n"); | 517 | printk(KERN_ERR "ak4535: failed to register card\n"); |
519 | goto card_err; | 518 | goto card_err; |
@@ -689,6 +688,18 @@ struct snd_soc_codec_device soc_codec_dev_ak4535 = { | |||
689 | }; | 688 | }; |
690 | EXPORT_SYMBOL_GPL(soc_codec_dev_ak4535); | 689 | EXPORT_SYMBOL_GPL(soc_codec_dev_ak4535); |
691 | 690 | ||
691 | static int __init ak4535_modinit(void) | ||
692 | { | ||
693 | return snd_soc_register_dai(&ak4535_dai); | ||
694 | } | ||
695 | module_init(ak4535_modinit); | ||
696 | |||
697 | static void __exit ak4535_exit(void) | ||
698 | { | ||
699 | snd_soc_unregister_dai(&ak4535_dai); | ||
700 | } | ||
701 | module_exit(ak4535_exit); | ||
702 | |||
692 | MODULE_DESCRIPTION("Soc AK4535 driver"); | 703 | MODULE_DESCRIPTION("Soc AK4535 driver"); |
693 | MODULE_AUTHOR("Richard Purdie"); | 704 | MODULE_AUTHOR("Richard Purdie"); |
694 | MODULE_LICENSE("GPL"); | 705 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 0bbd94501d7e..f1aa0c34421c 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c | |||
@@ -360,13 +360,14 @@ static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg, | |||
360 | /* | 360 | /* |
361 | * Program the CS4270 with the given hardware parameters. | 361 | * Program the CS4270 with the given hardware parameters. |
362 | * | 362 | * |
363 | * The .dai_ops functions are used to provide board-specific data, like | 363 | * The .ops functions are used to provide board-specific data, like |
364 | * input frequencies, to this driver. This function takes that information, | 364 | * input frequencies, to this driver. This function takes that information, |
365 | * combines it with the hardware parameters provided, and programs the | 365 | * combines it with the hardware parameters provided, and programs the |
366 | * hardware accordingly. | 366 | * hardware accordingly. |
367 | */ | 367 | */ |
368 | static int cs4270_hw_params(struct snd_pcm_substream *substream, | 368 | static int cs4270_hw_params(struct snd_pcm_substream *substream, |
369 | struct snd_pcm_hw_params *params) | 369 | struct snd_pcm_hw_params *params, |
370 | struct snd_soc_dai *dai) | ||
370 | { | 371 | { |
371 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 372 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
372 | struct snd_soc_device *socdev = rtd->socdev; | 373 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -450,6 +451,19 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, | |||
450 | return ret; | 451 | return ret; |
451 | } | 452 | } |
452 | 453 | ||
454 | /* Disable automatic volume control. It's enabled by default, and | ||
455 | * it causes volume change commands to be delayed, sometimes until | ||
456 | * after playback has started. | ||
457 | */ | ||
458 | |||
459 | reg = cs4270_read_reg_cache(codec, CS4270_TRANS); | ||
460 | reg &= ~(CS4270_TRANS_SOFT | CS4270_TRANS_ZERO); | ||
461 | ret = cs4270_i2c_write(codec, CS4270_TRANS, reg); | ||
462 | if (ret < 0) { | ||
463 | printk(KERN_ERR "I2C write failed\n"); | ||
464 | return ret; | ||
465 | } | ||
466 | |||
453 | /* Thaw and power-up the codec */ | 467 | /* Thaw and power-up the codec */ |
454 | 468 | ||
455 | ret = snd_soc_write(codec, CS4270_PWRCTL, 0); | 469 | ret = snd_soc_write(codec, CS4270_PWRCTL, 0); |
@@ -697,10 +711,10 @@ static int cs4270_probe(struct platform_device *pdev) | |||
697 | if (codec->control_data) { | 711 | if (codec->control_data) { |
698 | /* Initialize codec ops */ | 712 | /* Initialize codec ops */ |
699 | cs4270_dai.ops.hw_params = cs4270_hw_params; | 713 | cs4270_dai.ops.hw_params = cs4270_hw_params; |
700 | cs4270_dai.dai_ops.set_sysclk = cs4270_set_dai_sysclk; | 714 | cs4270_dai.ops.set_sysclk = cs4270_set_dai_sysclk; |
701 | cs4270_dai.dai_ops.set_fmt = cs4270_set_dai_fmt; | 715 | cs4270_dai.ops.set_fmt = cs4270_set_dai_fmt; |
702 | #ifdef CONFIG_SND_SOC_CS4270_HWMUTE | 716 | #ifdef CONFIG_SND_SOC_CS4270_HWMUTE |
703 | cs4270_dai.dai_ops.digital_mute = cs4270_mute; | 717 | cs4270_dai.ops.digital_mute = cs4270_mute; |
704 | #endif | 718 | #endif |
705 | } else | 719 | } else |
706 | printk(KERN_INFO "cs4270: no I2C device found, " | 720 | printk(KERN_INFO "cs4270: no I2C device found, " |
@@ -709,7 +723,7 @@ static int cs4270_probe(struct platform_device *pdev) | |||
709 | printk(KERN_INFO "cs4270: I2C disabled, using stand-alone mode\n"); | 723 | printk(KERN_INFO "cs4270: I2C disabled, using stand-alone mode\n"); |
710 | #endif | 724 | #endif |
711 | 725 | ||
712 | ret = snd_soc_register_card(socdev); | 726 | ret = snd_soc_init_card(socdev); |
713 | if (ret < 0) { | 727 | if (ret < 0) { |
714 | printk(KERN_ERR "cs4270: failed to register card\n"); | 728 | printk(KERN_ERR "cs4270: failed to register card\n"); |
715 | goto error_del_driver; | 729 | goto error_del_driver; |
@@ -760,6 +774,18 @@ struct snd_soc_codec_device soc_codec_device_cs4270 = { | |||
760 | }; | 774 | }; |
761 | EXPORT_SYMBOL_GPL(soc_codec_device_cs4270); | 775 | EXPORT_SYMBOL_GPL(soc_codec_device_cs4270); |
762 | 776 | ||
777 | static int __init cs4270_init(void) | ||
778 | { | ||
779 | return snd_soc_register_dai(&cs4270_dai); | ||
780 | } | ||
781 | module_init(cs4270_init); | ||
782 | |||
783 | static void __exit cs4270_exit(void) | ||
784 | { | ||
785 | snd_soc_unregister_dai(&cs4270_dai); | ||
786 | } | ||
787 | module_exit(cs4270_exit); | ||
788 | |||
763 | MODULE_AUTHOR("Timur Tabi <timur@freescale.com>"); | 789 | MODULE_AUTHOR("Timur Tabi <timur@freescale.com>"); |
764 | MODULE_DESCRIPTION("Cirrus Logic CS4270 ALSA SoC Codec Driver"); | 790 | MODULE_DESCRIPTION("Cirrus Logic CS4270 ALSA SoC Codec Driver"); |
765 | MODULE_LICENSE("GPL"); | 791 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/l3.c b/sound/soc/codecs/l3.c new file mode 100644 index 000000000000..5353af58862c --- /dev/null +++ b/sound/soc/codecs/l3.c | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | * L3 code | ||
3 | * | ||
4 | * Copyright (C) 2008, Christian Pellegrin <chripell@evolware.org> | ||
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 | * based on: | ||
12 | * | ||
13 | * L3 bus algorithm module. | ||
14 | * | ||
15 | * Copyright (C) 2001 Russell King, All Rights Reserved. | ||
16 | * | ||
17 | * | ||
18 | */ | ||
19 | |||
20 | #include <linux/module.h> | ||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/delay.h> | ||
23 | |||
24 | #include <sound/l3.h> | ||
25 | |||
26 | /* | ||
27 | * Send one byte of data to the chip. Data is latched into the chip on | ||
28 | * the rising edge of the clock. | ||
29 | */ | ||
30 | static void sendbyte(struct l3_pins *adap, unsigned int byte) | ||
31 | { | ||
32 | int i; | ||
33 | |||
34 | for (i = 0; i < 8; i++) { | ||
35 | adap->setclk(0); | ||
36 | udelay(adap->data_hold); | ||
37 | adap->setdat(byte & 1); | ||
38 | udelay(adap->data_setup); | ||
39 | adap->setclk(1); | ||
40 | udelay(adap->clock_high); | ||
41 | byte >>= 1; | ||
42 | } | ||
43 | } | ||
44 | |||
45 | /* | ||
46 | * Send a set of bytes to the chip. We need to pulse the MODE line | ||
47 | * between each byte, but never at the start nor at the end of the | ||
48 | * transfer. | ||
49 | */ | ||
50 | static void sendbytes(struct l3_pins *adap, const u8 *buf, | ||
51 | int len) | ||
52 | { | ||
53 | int i; | ||
54 | |||
55 | for (i = 0; i < len; i++) { | ||
56 | if (i) { | ||
57 | udelay(adap->mode_hold); | ||
58 | adap->setmode(0); | ||
59 | udelay(adap->mode); | ||
60 | } | ||
61 | adap->setmode(1); | ||
62 | udelay(adap->mode_setup); | ||
63 | sendbyte(adap, buf[i]); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | int l3_write(struct l3_pins *adap, u8 addr, u8 *data, int len) | ||
68 | { | ||
69 | adap->setclk(1); | ||
70 | adap->setdat(1); | ||
71 | adap->setmode(1); | ||
72 | udelay(adap->mode); | ||
73 | |||
74 | adap->setmode(0); | ||
75 | udelay(adap->mode_setup); | ||
76 | sendbyte(adap, addr); | ||
77 | udelay(adap->mode_hold); | ||
78 | |||
79 | sendbytes(adap, data, len); | ||
80 | |||
81 | adap->setclk(1); | ||
82 | adap->setdat(1); | ||
83 | adap->setmode(0); | ||
84 | |||
85 | return len; | ||
86 | } | ||
87 | EXPORT_SYMBOL_GPL(l3_write); | ||
88 | |||
89 | MODULE_DESCRIPTION("L3 bit-banging driver"); | ||
90 | MODULE_AUTHOR("Christian Pellegrin <chripell@evolware.org>"); | ||
91 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/pcm3008.c b/sound/soc/codecs/pcm3008.c new file mode 100644 index 000000000000..9a3e67e5319c --- /dev/null +++ b/sound/soc/codecs/pcm3008.c | |||
@@ -0,0 +1,212 @@ | |||
1 | /* | ||
2 | * ALSA Soc PCM3008 codec support | ||
3 | * | ||
4 | * Author: Hugo Villeneuve | ||
5 | * Copyright (C) 2008 Lyrtech inc | ||
6 | * | ||
7 | * Based on AC97 Soc codec, original copyright follow: | ||
8 | * Copyright 2005 Wolfson Microelectronics PLC. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | * | ||
15 | * Generic PCM3008 support. | ||
16 | */ | ||
17 | |||
18 | #include <linux/init.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/device.h> | ||
21 | #include <linux/gpio.h> | ||
22 | #include <sound/core.h> | ||
23 | #include <sound/pcm.h> | ||
24 | #include <sound/initval.h> | ||
25 | #include <sound/soc.h> | ||
26 | |||
27 | #include "pcm3008.h" | ||
28 | |||
29 | #define PCM3008_VERSION "0.2" | ||
30 | |||
31 | #define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ | ||
32 | SNDRV_PCM_RATE_48000) | ||
33 | |||
34 | struct snd_soc_dai pcm3008_dai = { | ||
35 | .name = "PCM3008 HiFi", | ||
36 | .playback = { | ||
37 | .stream_name = "PCM3008 Playback", | ||
38 | .channels_min = 1, | ||
39 | .channels_max = 2, | ||
40 | .rates = PCM3008_RATES, | ||
41 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
42 | }, | ||
43 | .capture = { | ||
44 | .stream_name = "PCM3008 Capture", | ||
45 | .channels_min = 1, | ||
46 | .channels_max = 2, | ||
47 | .rates = PCM3008_RATES, | ||
48 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
49 | }, | ||
50 | }; | ||
51 | EXPORT_SYMBOL_GPL(pcm3008_dai); | ||
52 | |||
53 | static void pcm3008_gpio_free(struct pcm3008_setup_data *setup) | ||
54 | { | ||
55 | gpio_free(setup->dem0_pin); | ||
56 | gpio_free(setup->dem1_pin); | ||
57 | gpio_free(setup->pdad_pin); | ||
58 | gpio_free(setup->pdda_pin); | ||
59 | } | ||
60 | |||
61 | static int pcm3008_soc_probe(struct platform_device *pdev) | ||
62 | { | ||
63 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
64 | struct snd_soc_codec *codec; | ||
65 | struct pcm3008_setup_data *setup = socdev->codec_data; | ||
66 | int ret = 0; | ||
67 | |||
68 | printk(KERN_INFO "PCM3008 SoC Audio Codec %s\n", PCM3008_VERSION); | ||
69 | |||
70 | socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | ||
71 | if (!socdev->codec) | ||
72 | return -ENOMEM; | ||
73 | |||
74 | codec = socdev->codec; | ||
75 | mutex_init(&codec->mutex); | ||
76 | |||
77 | codec->name = "PCM3008"; | ||
78 | codec->owner = THIS_MODULE; | ||
79 | codec->dai = &pcm3008_dai; | ||
80 | codec->num_dai = 1; | ||
81 | codec->write = NULL; | ||
82 | codec->read = NULL; | ||
83 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
84 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
85 | |||
86 | /* Register PCMs. */ | ||
87 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
88 | if (ret < 0) { | ||
89 | printk(KERN_ERR "pcm3008: failed to create pcms\n"); | ||
90 | goto pcm_err; | ||
91 | } | ||
92 | |||
93 | /* Register Card. */ | ||
94 | ret = snd_soc_init_card(socdev); | ||
95 | if (ret < 0) { | ||
96 | printk(KERN_ERR "pcm3008: failed to register card\n"); | ||
97 | goto card_err; | ||
98 | } | ||
99 | |||
100 | /* DEM1 DEM0 DE-EMPHASIS_MODE | ||
101 | * Low Low De-emphasis 44.1 kHz ON | ||
102 | * Low High De-emphasis OFF | ||
103 | * High Low De-emphasis 48 kHz ON | ||
104 | * High High De-emphasis 32 kHz ON | ||
105 | */ | ||
106 | |||
107 | /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */ | ||
108 | ret = gpio_request(setup->dem0_pin, "codec_dem0"); | ||
109 | if (ret == 0) | ||
110 | ret = gpio_direction_output(setup->dem0_pin, 1); | ||
111 | if (ret != 0) | ||
112 | goto gpio_err; | ||
113 | |||
114 | /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */ | ||
115 | ret = gpio_request(setup->dem1_pin, "codec_dem1"); | ||
116 | if (ret == 0) | ||
117 | ret = gpio_direction_output(setup->dem1_pin, 0); | ||
118 | if (ret != 0) | ||
119 | goto gpio_err; | ||
120 | |||
121 | /* Configure PDAD GPIO. */ | ||
122 | ret = gpio_request(setup->pdad_pin, "codec_pdad"); | ||
123 | if (ret == 0) | ||
124 | ret = gpio_direction_output(setup->pdad_pin, 1); | ||
125 | if (ret != 0) | ||
126 | goto gpio_err; | ||
127 | |||
128 | /* Configure PDDA GPIO. */ | ||
129 | ret = gpio_request(setup->pdda_pin, "codec_pdda"); | ||
130 | if (ret == 0) | ||
131 | ret = gpio_direction_output(setup->pdda_pin, 1); | ||
132 | if (ret != 0) | ||
133 | goto gpio_err; | ||
134 | |||
135 | return ret; | ||
136 | |||
137 | gpio_err: | ||
138 | pcm3008_gpio_free(setup); | ||
139 | card_err: | ||
140 | snd_soc_free_pcms(socdev); | ||
141 | pcm_err: | ||
142 | kfree(socdev->codec); | ||
143 | |||
144 | return ret; | ||
145 | } | ||
146 | |||
147 | static int pcm3008_soc_remove(struct platform_device *pdev) | ||
148 | { | ||
149 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
150 | struct snd_soc_codec *codec = socdev->codec; | ||
151 | struct pcm3008_setup_data *setup = socdev->codec_data; | ||
152 | |||
153 | if (!codec) | ||
154 | return 0; | ||
155 | |||
156 | pcm3008_gpio_free(setup); | ||
157 | snd_soc_free_pcms(socdev); | ||
158 | kfree(socdev->codec); | ||
159 | |||
160 | return 0; | ||
161 | } | ||
162 | |||
163 | #ifdef CONFIG_PM | ||
164 | static int pcm3008_soc_suspend(struct platform_device *pdev, pm_message_t msg) | ||
165 | { | ||
166 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
167 | struct pcm3008_setup_data *setup = socdev->codec_data; | ||
168 | |||
169 | gpio_set_value(setup->pdad_pin, 0); | ||
170 | gpio_set_value(setup->pdda_pin, 0); | ||
171 | |||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | static int pcm3008_soc_resume(struct platform_device *pdev) | ||
176 | { | ||
177 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
178 | struct pcm3008_setup_data *setup = socdev->codec_data; | ||
179 | |||
180 | gpio_set_value(setup->pdad_pin, 1); | ||
181 | gpio_set_value(setup->pdda_pin, 1); | ||
182 | |||
183 | return 0; | ||
184 | } | ||
185 | #else | ||
186 | #define pcm3008_soc_suspend NULL | ||
187 | #define pcm3008_soc_resume NULL | ||
188 | #endif | ||
189 | |||
190 | struct snd_soc_codec_device soc_codec_dev_pcm3008 = { | ||
191 | .probe = pcm3008_soc_probe, | ||
192 | .remove = pcm3008_soc_remove, | ||
193 | .suspend = pcm3008_soc_suspend, | ||
194 | .resume = pcm3008_soc_resume, | ||
195 | }; | ||
196 | EXPORT_SYMBOL_GPL(soc_codec_dev_pcm3008); | ||
197 | |||
198 | static int __init pcm3008_init(void) | ||
199 | { | ||
200 | return snd_soc_register_dai(&pcm3008_dai); | ||
201 | } | ||
202 | module_init(pcm3008_init); | ||
203 | |||
204 | static void __exit pcm3008_exit(void) | ||
205 | { | ||
206 | snd_soc_unregister_dai(&pcm3008_dai); | ||
207 | } | ||
208 | module_exit(pcm3008_exit); | ||
209 | |||
210 | MODULE_DESCRIPTION("Soc PCM3008 driver"); | ||
211 | MODULE_AUTHOR("Hugo Villeneuve"); | ||
212 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/pcm3008.h b/sound/soc/codecs/pcm3008.h new file mode 100644 index 000000000000..d04e87d3c060 --- /dev/null +++ b/sound/soc/codecs/pcm3008.h | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * PCM3008 ALSA SoC Layer | ||
3 | * | ||
4 | * Author: Hugo Villeneuve | ||
5 | * Copyright (C) 2008 Lyrtech inc | ||
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 __LINUX_SND_SOC_PCM3008_H | ||
13 | #define __LINUX_SND_SOC_PCM3008_H | ||
14 | |||
15 | struct pcm3008_setup_data { | ||
16 | unsigned dem0_pin; | ||
17 | unsigned dem1_pin; | ||
18 | unsigned pdad_pin; | ||
19 | unsigned pdda_pin; | ||
20 | }; | ||
21 | |||
22 | extern struct snd_soc_codec_device soc_codec_dev_pcm3008; | ||
23 | extern struct snd_soc_dai pcm3008_dai; | ||
24 | |||
25 | #endif | ||
diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c index 44ef0dacd564..cac373616768 100644 --- a/sound/soc/codecs/ssm2602.c +++ b/sound/soc/codecs/ssm2602.c | |||
@@ -285,16 +285,23 @@ static inline int get_coeff(int mclk, int rate) | |||
285 | } | 285 | } |
286 | 286 | ||
287 | static int ssm2602_hw_params(struct snd_pcm_substream *substream, | 287 | static int ssm2602_hw_params(struct snd_pcm_substream *substream, |
288 | struct snd_pcm_hw_params *params) | 288 | struct snd_pcm_hw_params *params, |
289 | struct snd_soc_dai *dai) | ||
289 | { | 290 | { |
290 | u16 srate; | 291 | u16 srate; |
291 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 292 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
292 | struct snd_soc_device *socdev = rtd->socdev; | 293 | struct snd_soc_device *socdev = rtd->socdev; |
293 | struct snd_soc_codec *codec = socdev->codec; | 294 | struct snd_soc_codec *codec = socdev->codec; |
294 | struct ssm2602_priv *ssm2602 = codec->private_data; | 295 | struct ssm2602_priv *ssm2602 = codec->private_data; |
296 | struct i2c_client *i2c = codec->control_data; | ||
295 | u16 iface = ssm2602_read_reg_cache(codec, SSM2602_IFACE) & 0xfff3; | 297 | u16 iface = ssm2602_read_reg_cache(codec, SSM2602_IFACE) & 0xfff3; |
296 | int i = get_coeff(ssm2602->sysclk, params_rate(params)); | 298 | int i = get_coeff(ssm2602->sysclk, params_rate(params)); |
297 | 299 | ||
300 | if (substream == ssm2602->slave_substream) { | ||
301 | dev_dbg(&i2c->dev, "Ignoring hw_params for slave substream\n"); | ||
302 | return 0; | ||
303 | } | ||
304 | |||
298 | /*no match is found*/ | 305 | /*no match is found*/ |
299 | if (i == ARRAY_SIZE(coeff_div)) | 306 | if (i == ARRAY_SIZE(coeff_div)) |
300 | return -EINVAL; | 307 | return -EINVAL; |
@@ -324,19 +331,26 @@ static int ssm2602_hw_params(struct snd_pcm_substream *substream, | |||
324 | return 0; | 331 | return 0; |
325 | } | 332 | } |
326 | 333 | ||
327 | static int ssm2602_startup(struct snd_pcm_substream *substream) | 334 | static int ssm2602_startup(struct snd_pcm_substream *substream, |
335 | struct snd_soc_dai *dai) | ||
328 | { | 336 | { |
329 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 337 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
330 | struct snd_soc_device *socdev = rtd->socdev; | 338 | struct snd_soc_device *socdev = rtd->socdev; |
331 | struct snd_soc_codec *codec = socdev->codec; | 339 | struct snd_soc_codec *codec = socdev->codec; |
332 | struct ssm2602_priv *ssm2602 = codec->private_data; | 340 | struct ssm2602_priv *ssm2602 = codec->private_data; |
341 | struct i2c_client *i2c = codec->control_data; | ||
333 | struct snd_pcm_runtime *master_runtime; | 342 | struct snd_pcm_runtime *master_runtime; |
334 | 343 | ||
335 | /* The DAI has shared clocks so if we already have a playback or | 344 | /* The DAI has shared clocks so if we already have a playback or |
336 | * capture going then constrain this substream to match it. | 345 | * capture going then constrain this substream to match it. |
346 | * TODO: the ssm2602 allows pairs of non-matching PB/REC rates | ||
337 | */ | 347 | */ |
338 | if (ssm2602->master_substream) { | 348 | if (ssm2602->master_substream) { |
339 | master_runtime = ssm2602->master_substream->runtime; | 349 | master_runtime = ssm2602->master_substream->runtime; |
350 | dev_dbg(&i2c->dev, "Constraining to %d bits at %dHz\n", | ||
351 | master_runtime->sample_bits, | ||
352 | master_runtime->rate); | ||
353 | |||
340 | snd_pcm_hw_constraint_minmax(substream->runtime, | 354 | snd_pcm_hw_constraint_minmax(substream->runtime, |
341 | SNDRV_PCM_HW_PARAM_RATE, | 355 | SNDRV_PCM_HW_PARAM_RATE, |
342 | master_runtime->rate, | 356 | master_runtime->rate, |
@@ -354,7 +368,8 @@ static int ssm2602_startup(struct snd_pcm_substream *substream) | |||
354 | return 0; | 368 | return 0; |
355 | } | 369 | } |
356 | 370 | ||
357 | static int ssm2602_pcm_prepare(struct snd_pcm_substream *substream) | 371 | static int ssm2602_pcm_prepare(struct snd_pcm_substream *substream, |
372 | struct snd_soc_dai *dai) | ||
358 | { | 373 | { |
359 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 374 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
360 | struct snd_soc_device *socdev = rtd->socdev; | 375 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -365,14 +380,21 @@ static int ssm2602_pcm_prepare(struct snd_pcm_substream *substream) | |||
365 | return 0; | 380 | return 0; |
366 | } | 381 | } |
367 | 382 | ||
368 | static void ssm2602_shutdown(struct snd_pcm_substream *substream) | 383 | static void ssm2602_shutdown(struct snd_pcm_substream *substream, |
384 | struct snd_soc_dai *dai) | ||
369 | { | 385 | { |
370 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 386 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
371 | struct snd_soc_device *socdev = rtd->socdev; | 387 | struct snd_soc_device *socdev = rtd->socdev; |
372 | struct snd_soc_codec *codec = socdev->codec; | 388 | struct snd_soc_codec *codec = socdev->codec; |
389 | struct ssm2602_priv *ssm2602 = codec->private_data; | ||
373 | /* deactivate */ | 390 | /* deactivate */ |
374 | if (!codec->active) | 391 | if (!codec->active) |
375 | ssm2602_write(codec, SSM2602_ACTIVE, 0); | 392 | ssm2602_write(codec, SSM2602_ACTIVE, 0); |
393 | |||
394 | if (ssm2602->master_substream == substream) | ||
395 | ssm2602->master_substream = ssm2602->slave_substream; | ||
396 | |||
397 | ssm2602->slave_substream = NULL; | ||
376 | } | 398 | } |
377 | 399 | ||
378 | static int ssm2602_mute(struct snd_soc_dai *dai, int mute) | 400 | static int ssm2602_mute(struct snd_soc_dai *dai, int mute) |
@@ -432,10 +454,10 @@ static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
432 | iface |= 0x0001; | 454 | iface |= 0x0001; |
433 | break; | 455 | break; |
434 | case SND_SOC_DAIFMT_DSP_A: | 456 | case SND_SOC_DAIFMT_DSP_A: |
435 | iface |= 0x0003; | 457 | iface |= 0x0013; |
436 | break; | 458 | break; |
437 | case SND_SOC_DAIFMT_DSP_B: | 459 | case SND_SOC_DAIFMT_DSP_B: |
438 | iface |= 0x0013; | 460 | iface |= 0x0003; |
439 | break; | 461 | break; |
440 | default: | 462 | default: |
441 | return -EINVAL; | 463 | return -EINVAL; |
@@ -496,6 +518,9 @@ static int ssm2602_set_bias_level(struct snd_soc_codec *codec, | |||
496 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\ | 518 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\ |
497 | SNDRV_PCM_RATE_96000) | 519 | SNDRV_PCM_RATE_96000) |
498 | 520 | ||
521 | #define SSM2602_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | ||
522 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) | ||
523 | |||
499 | struct snd_soc_dai ssm2602_dai = { | 524 | struct snd_soc_dai ssm2602_dai = { |
500 | .name = "SSM2602", | 525 | .name = "SSM2602", |
501 | .playback = { | 526 | .playback = { |
@@ -503,20 +528,18 @@ struct snd_soc_dai ssm2602_dai = { | |||
503 | .channels_min = 2, | 528 | .channels_min = 2, |
504 | .channels_max = 2, | 529 | .channels_max = 2, |
505 | .rates = SSM2602_RATES, | 530 | .rates = SSM2602_RATES, |
506 | .formats = SNDRV_PCM_FMTBIT_S32_LE,}, | 531 | .formats = SSM2602_FORMATS,}, |
507 | .capture = { | 532 | .capture = { |
508 | .stream_name = "Capture", | 533 | .stream_name = "Capture", |
509 | .channels_min = 2, | 534 | .channels_min = 2, |
510 | .channels_max = 2, | 535 | .channels_max = 2, |
511 | .rates = SSM2602_RATES, | 536 | .rates = SSM2602_RATES, |
512 | .formats = SNDRV_PCM_FMTBIT_S32_LE,}, | 537 | .formats = SSM2602_FORMATS,}, |
513 | .ops = { | 538 | .ops = { |
514 | .startup = ssm2602_startup, | 539 | .startup = ssm2602_startup, |
515 | .prepare = ssm2602_pcm_prepare, | 540 | .prepare = ssm2602_pcm_prepare, |
516 | .hw_params = ssm2602_hw_params, | 541 | .hw_params = ssm2602_hw_params, |
517 | .shutdown = ssm2602_shutdown, | 542 | .shutdown = ssm2602_shutdown, |
518 | }, | ||
519 | .dai_ops = { | ||
520 | .digital_mute = ssm2602_mute, | 543 | .digital_mute = ssm2602_mute, |
521 | .set_sysclk = ssm2602_set_dai_sysclk, | 544 | .set_sysclk = ssm2602_set_dai_sysclk, |
522 | .set_fmt = ssm2602_set_dai_fmt, | 545 | .set_fmt = ssm2602_set_dai_fmt, |
@@ -601,7 +624,7 @@ static int ssm2602_init(struct snd_soc_device *socdev) | |||
601 | 624 | ||
602 | ssm2602_add_controls(codec); | 625 | ssm2602_add_controls(codec); |
603 | ssm2602_add_widgets(codec); | 626 | ssm2602_add_widgets(codec); |
604 | ret = snd_soc_register_card(socdev); | 627 | ret = snd_soc_init_card(socdev); |
605 | if (ret < 0) { | 628 | if (ret < 0) { |
606 | pr_err("ssm2602: failed to register card\n"); | 629 | pr_err("ssm2602: failed to register card\n"); |
607 | goto card_err; | 630 | goto card_err; |
@@ -770,6 +793,18 @@ struct snd_soc_codec_device soc_codec_dev_ssm2602 = { | |||
770 | }; | 793 | }; |
771 | EXPORT_SYMBOL_GPL(soc_codec_dev_ssm2602); | 794 | EXPORT_SYMBOL_GPL(soc_codec_dev_ssm2602); |
772 | 795 | ||
796 | static int __init ssm2602_modinit(void) | ||
797 | { | ||
798 | return snd_soc_register_dai(&ssm2602_dai); | ||
799 | } | ||
800 | module_init(ssm2602_modinit); | ||
801 | |||
802 | static void __exit ssm2602_exit(void) | ||
803 | { | ||
804 | snd_soc_unregister_dai(&ssm2602_dai); | ||
805 | } | ||
806 | module_exit(ssm2602_exit); | ||
807 | |||
773 | MODULE_DESCRIPTION("ASoC ssm2602 driver"); | 808 | MODULE_DESCRIPTION("ASoC ssm2602 driver"); |
774 | MODULE_AUTHOR("Cliff Cai"); | 809 | MODULE_AUTHOR("Cliff Cai"); |
775 | MODULE_LICENSE("GPL"); | 810 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c index 44308dac9e18..cfdea007c4cb 100644 --- a/sound/soc/codecs/tlv320aic23.c +++ b/sound/soc/codecs/tlv320aic23.c | |||
@@ -37,12 +37,6 @@ | |||
37 | 37 | ||
38 | #define AIC23_VERSION "0.1" | 38 | #define AIC23_VERSION "0.1" |
39 | 39 | ||
40 | struct tlv320aic23_srate_reg_info { | ||
41 | u32 sample_rate; | ||
42 | u8 control; /* SR3, SR2, SR1, SR0 and BOSR */ | ||
43 | u8 divider; /* if 0 CLKIN = MCLK, if 1 CLKIN = MCLK/2 */ | ||
44 | }; | ||
45 | |||
46 | /* | 40 | /* |
47 | * AIC23 register cache | 41 | * AIC23 register cache |
48 | */ | 42 | */ |
@@ -261,20 +255,156 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
261 | 255 | ||
262 | }; | 256 | }; |
263 | 257 | ||
264 | /* tlv320aic23 related */ | 258 | /* AIC23 driver data */ |
265 | static const struct tlv320aic23_srate_reg_info srate_reg_info[] = { | 259 | struct aic23 { |
266 | {4000, 0x06, 1}, /* 4000 */ | 260 | struct snd_soc_codec codec; |
267 | {8000, 0x06, 0}, /* 8000 */ | 261 | int mclk; |
268 | {16000, 0x0C, 1}, /* 16000 */ | 262 | int requested_adc; |
269 | {22050, 0x11, 1}, /* 22050 */ | 263 | int requested_dac; |
270 | {24000, 0x00, 1}, /* 24000 */ | 264 | }; |
271 | {32000, 0x0C, 0}, /* 32000 */ | 265 | |
272 | {44100, 0x11, 0}, /* 44100 */ | 266 | /* |
273 | {48000, 0x00, 0}, /* 48000 */ | 267 | * Common Crystals used |
274 | {88200, 0x1F, 0}, /* 88200 */ | 268 | * 11.2896 Mhz /128 = *88.2k /192 = 58.8k |
275 | {96000, 0x0E, 0}, /* 96000 */ | 269 | * 12.0000 Mhz /125 = *96k /136 = 88.235K |
270 | * 12.2880 Mhz /128 = *96k /192 = 64k | ||
271 | * 16.9344 Mhz /128 = 132.3k /192 = *88.2k | ||
272 | * 18.4320 Mhz /128 = 144k /192 = *96k | ||
273 | */ | ||
274 | |||
275 | /* | ||
276 | * Normal BOSR 0-256/2 = 128, 1-384/2 = 192 | ||
277 | * USB BOSR 0-250/2 = 125, 1-272/2 = 136 | ||
278 | */ | ||
279 | static const int bosr_usb_divisor_table[] = { | ||
280 | 128, 125, 192, 136 | ||
281 | }; | ||
282 | #define LOWER_GROUP ((1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<6) | (1<<7)) | ||
283 | #define UPPER_GROUP ((1<<8) | (1<<9) | (1<<10) | (1<<11) | (1<<15)) | ||
284 | static const unsigned short sr_valid_mask[] = { | ||
285 | LOWER_GROUP|UPPER_GROUP, /* Normal, bosr - 0*/ | ||
286 | LOWER_GROUP|UPPER_GROUP, /* Normal, bosr - 1*/ | ||
287 | LOWER_GROUP, /* Usb, bosr - 0*/ | ||
288 | UPPER_GROUP, /* Usb, bosr - 1*/ | ||
289 | }; | ||
290 | /* | ||
291 | * Every divisor is a factor of 11*12 | ||
292 | */ | ||
293 | #define SR_MULT (11*12) | ||
294 | #define A(x) (x) ? (SR_MULT/x) : 0 | ||
295 | static const unsigned char sr_adc_mult_table[] = { | ||
296 | A(2), A(2), A(12), A(12), A(0), A(0), A(3), A(1), | ||
297 | A(2), A(2), A(11), A(11), A(0), A(0), A(0), A(1) | ||
298 | }; | ||
299 | static const unsigned char sr_dac_mult_table[] = { | ||
300 | A(2), A(12), A(2), A(12), A(0), A(0), A(3), A(1), | ||
301 | A(2), A(11), A(2), A(11), A(0), A(0), A(0), A(1) | ||
276 | }; | 302 | }; |
277 | 303 | ||
304 | static unsigned get_score(int adc, int adc_l, int adc_h, int need_adc, | ||
305 | int dac, int dac_l, int dac_h, int need_dac) | ||
306 | { | ||
307 | if ((adc >= adc_l) && (adc <= adc_h) && | ||
308 | (dac >= dac_l) && (dac <= dac_h)) { | ||
309 | int diff_adc = need_adc - adc; | ||
310 | int diff_dac = need_dac - dac; | ||
311 | return abs(diff_adc) + abs(diff_dac); | ||
312 | } | ||
313 | return UINT_MAX; | ||
314 | } | ||
315 | |||
316 | static int find_rate(int mclk, u32 need_adc, u32 need_dac) | ||
317 | { | ||
318 | int i, j; | ||
319 | int best_i = -1; | ||
320 | int best_j = -1; | ||
321 | int best_div = 0; | ||
322 | unsigned best_score = UINT_MAX; | ||
323 | int adc_l, adc_h, dac_l, dac_h; | ||
324 | |||
325 | need_adc *= SR_MULT; | ||
326 | need_dac *= SR_MULT; | ||
327 | /* | ||
328 | * rates given are +/- 1/32 | ||
329 | */ | ||
330 | adc_l = need_adc - (need_adc >> 5); | ||
331 | adc_h = need_adc + (need_adc >> 5); | ||
332 | dac_l = need_dac - (need_dac >> 5); | ||
333 | dac_h = need_dac + (need_dac >> 5); | ||
334 | for (i = 0; i < ARRAY_SIZE(bosr_usb_divisor_table); i++) { | ||
335 | int base = mclk / bosr_usb_divisor_table[i]; | ||
336 | int mask = sr_valid_mask[i]; | ||
337 | for (j = 0; j < ARRAY_SIZE(sr_adc_mult_table); | ||
338 | j++, mask >>= 1) { | ||
339 | int adc; | ||
340 | int dac; | ||
341 | int score; | ||
342 | if ((mask & 1) == 0) | ||
343 | continue; | ||
344 | adc = base * sr_adc_mult_table[j]; | ||
345 | dac = base * sr_dac_mult_table[j]; | ||
346 | score = get_score(adc, adc_l, adc_h, need_adc, | ||
347 | dac, dac_l, dac_h, need_dac); | ||
348 | if (best_score > score) { | ||
349 | best_score = score; | ||
350 | best_i = i; | ||
351 | best_j = j; | ||
352 | best_div = 0; | ||
353 | } | ||
354 | score = get_score((adc >> 1), adc_l, adc_h, need_adc, | ||
355 | (dac >> 1), dac_l, dac_h, need_dac); | ||
356 | /* prefer to have a /2 */ | ||
357 | if ((score != UINT_MAX) && (best_score >= score)) { | ||
358 | best_score = score; | ||
359 | best_i = i; | ||
360 | best_j = j; | ||
361 | best_div = 1; | ||
362 | } | ||
363 | } | ||
364 | } | ||
365 | return (best_j << 2) | best_i | (best_div << TLV320AIC23_CLKIN_SHIFT); | ||
366 | } | ||
367 | |||
368 | #ifdef DEBUG | ||
369 | static void get_current_sample_rates(struct snd_soc_codec *codec, int mclk, | ||
370 | u32 *sample_rate_adc, u32 *sample_rate_dac) | ||
371 | { | ||
372 | int src = tlv320aic23_read_reg_cache(codec, TLV320AIC23_SRATE); | ||
373 | int sr = (src >> 2) & 0x0f; | ||
374 | int val = (mclk / bosr_usb_divisor_table[src & 3]); | ||
375 | int adc = (val * sr_adc_mult_table[sr]) / SR_MULT; | ||
376 | int dac = (val * sr_dac_mult_table[sr]) / SR_MULT; | ||
377 | if (src & TLV320AIC23_CLKIN_HALF) { | ||
378 | adc >>= 1; | ||
379 | dac >>= 1; | ||
380 | } | ||
381 | *sample_rate_adc = adc; | ||
382 | *sample_rate_dac = dac; | ||
383 | } | ||
384 | #endif | ||
385 | |||
386 | static int set_sample_rate_control(struct snd_soc_codec *codec, int mclk, | ||
387 | u32 sample_rate_adc, u32 sample_rate_dac) | ||
388 | { | ||
389 | /* Search for the right sample rate */ | ||
390 | int data = find_rate(mclk, sample_rate_adc, sample_rate_dac); | ||
391 | if (data < 0) { | ||
392 | printk(KERN_ERR "%s:Invalid rate %u,%u requested\n", | ||
393 | __func__, sample_rate_adc, sample_rate_dac); | ||
394 | return -EINVAL; | ||
395 | } | ||
396 | tlv320aic23_write(codec, TLV320AIC23_SRATE, data); | ||
397 | #ifdef DEBUG | ||
398 | { | ||
399 | u32 adc, dac; | ||
400 | get_current_sample_rates(codec, mclk, &adc, &dac); | ||
401 | printk(KERN_DEBUG "actual samplerate = %u,%u reg=%x\n", | ||
402 | adc, dac, data); | ||
403 | } | ||
404 | #endif | ||
405 | return 0; | ||
406 | } | ||
407 | |||
278 | static int tlv320aic23_add_widgets(struct snd_soc_codec *codec) | 408 | static int tlv320aic23_add_widgets(struct snd_soc_codec *codec) |
279 | { | 409 | { |
280 | snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets, | 410 | snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets, |
@@ -288,32 +418,36 @@ static int tlv320aic23_add_widgets(struct snd_soc_codec *codec) | |||
288 | } | 418 | } |
289 | 419 | ||
290 | static int tlv320aic23_hw_params(struct snd_pcm_substream *substream, | 420 | static int tlv320aic23_hw_params(struct snd_pcm_substream *substream, |
291 | struct snd_pcm_hw_params *params) | 421 | struct snd_pcm_hw_params *params, |
422 | struct snd_soc_dai *dai) | ||
292 | { | 423 | { |
293 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 424 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
294 | struct snd_soc_device *socdev = rtd->socdev; | 425 | struct snd_soc_device *socdev = rtd->socdev; |
295 | struct snd_soc_codec *codec = socdev->codec; | 426 | struct snd_soc_codec *codec = socdev->codec; |
296 | u16 iface_reg, data; | 427 | u16 iface_reg; |
297 | u8 count = 0; | 428 | int ret; |
429 | struct aic23 *aic23 = container_of(codec, struct aic23, codec); | ||
430 | u32 sample_rate_adc = aic23->requested_adc; | ||
431 | u32 sample_rate_dac = aic23->requested_dac; | ||
432 | u32 sample_rate = params_rate(params); | ||
433 | |||
434 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
435 | aic23->requested_dac = sample_rate_dac = sample_rate; | ||
436 | if (!sample_rate_adc) | ||
437 | sample_rate_adc = sample_rate; | ||
438 | } else { | ||
439 | aic23->requested_adc = sample_rate_adc = sample_rate; | ||
440 | if (!sample_rate_dac) | ||
441 | sample_rate_dac = sample_rate; | ||
442 | } | ||
443 | ret = set_sample_rate_control(codec, aic23->mclk, sample_rate_adc, | ||
444 | sample_rate_dac); | ||
445 | if (ret < 0) | ||
446 | return ret; | ||
298 | 447 | ||
299 | iface_reg = | 448 | iface_reg = |
300 | tlv320aic23_read_reg_cache(codec, | 449 | tlv320aic23_read_reg_cache(codec, |
301 | TLV320AIC23_DIGT_FMT) & ~(0x03 << 2); | 450 | TLV320AIC23_DIGT_FMT) & ~(0x03 << 2); |
302 | |||
303 | /* Search for the right sample rate */ | ||
304 | /* Verify what happens if the rate is not supported | ||
305 | * now it goes to 96Khz */ | ||
306 | while ((srate_reg_info[count].sample_rate != params_rate(params)) && | ||
307 | (count < ARRAY_SIZE(srate_reg_info))) { | ||
308 | count++; | ||
309 | } | ||
310 | |||
311 | data = (srate_reg_info[count].divider << TLV320AIC23_CLKIN_SHIFT) | | ||
312 | (srate_reg_info[count]. control << TLV320AIC23_BOSR_SHIFT) | | ||
313 | TLV320AIC23_USB_CLK_ON; | ||
314 | |||
315 | tlv320aic23_write(codec, TLV320AIC23_SRATE, data); | ||
316 | |||
317 | switch (params_format(params)) { | 451 | switch (params_format(params)) { |
318 | case SNDRV_PCM_FORMAT_S16_LE: | 452 | case SNDRV_PCM_FORMAT_S16_LE: |
319 | break; | 453 | break; |
@@ -332,7 +466,8 @@ static int tlv320aic23_hw_params(struct snd_pcm_substream *substream, | |||
332 | return 0; | 466 | return 0; |
333 | } | 467 | } |
334 | 468 | ||
335 | static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream) | 469 | static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream, |
470 | struct snd_soc_dai *dai) | ||
336 | { | 471 | { |
337 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 472 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
338 | struct snd_soc_device *socdev = rtd->socdev; | 473 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -344,17 +479,23 @@ static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream) | |||
344 | return 0; | 479 | return 0; |
345 | } | 480 | } |
346 | 481 | ||
347 | static void tlv320aic23_shutdown(struct snd_pcm_substream *substream) | 482 | static void tlv320aic23_shutdown(struct snd_pcm_substream *substream, |
483 | struct snd_soc_dai *dai) | ||
348 | { | 484 | { |
349 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 485 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
350 | struct snd_soc_device *socdev = rtd->socdev; | 486 | struct snd_soc_device *socdev = rtd->socdev; |
351 | struct snd_soc_codec *codec = socdev->codec; | 487 | struct snd_soc_codec *codec = socdev->codec; |
488 | struct aic23 *aic23 = container_of(codec, struct aic23, codec); | ||
352 | 489 | ||
353 | /* deactivate */ | 490 | /* deactivate */ |
354 | if (!codec->active) { | 491 | if (!codec->active) { |
355 | udelay(50); | 492 | udelay(50); |
356 | tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0); | 493 | tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0); |
357 | } | 494 | } |
495 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
496 | aic23->requested_dac = 0; | ||
497 | else | ||
498 | aic23->requested_adc = 0; | ||
358 | } | 499 | } |
359 | 500 | ||
360 | static int tlv320aic23_mute(struct snd_soc_dai *dai, int mute) | 501 | static int tlv320aic23_mute(struct snd_soc_dai *dai, int mute) |
@@ -400,7 +541,7 @@ static int tlv320aic23_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
400 | case SND_SOC_DAIFMT_I2S: | 541 | case SND_SOC_DAIFMT_I2S: |
401 | iface_reg |= TLV320AIC23_FOR_I2S; | 542 | iface_reg |= TLV320AIC23_FOR_I2S; |
402 | break; | 543 | break; |
403 | case SND_SOC_DAIFMT_DSP_A: | 544 | case SND_SOC_DAIFMT_DSP_B: |
404 | iface_reg |= TLV320AIC23_FOR_DSP; | 545 | iface_reg |= TLV320AIC23_FOR_DSP; |
405 | break; | 546 | break; |
406 | case SND_SOC_DAIFMT_RIGHT_J: | 547 | case SND_SOC_DAIFMT_RIGHT_J: |
@@ -422,12 +563,9 @@ static int tlv320aic23_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
422 | int clk_id, unsigned int freq, int dir) | 563 | int clk_id, unsigned int freq, int dir) |
423 | { | 564 | { |
424 | struct snd_soc_codec *codec = codec_dai->codec; | 565 | struct snd_soc_codec *codec = codec_dai->codec; |
425 | 566 | struct aic23 *aic23 = container_of(codec, struct aic23, codec); | |
426 | switch (freq) { | 567 | aic23->mclk = freq; |
427 | case 12000000: | 568 | return 0; |
428 | return 0; | ||
429 | } | ||
430 | return -EINVAL; | ||
431 | } | 569 | } |
432 | 570 | ||
433 | static int tlv320aic23_set_bias_level(struct snd_soc_codec *codec, | 571 | static int tlv320aic23_set_bias_level(struct snd_soc_codec *codec, |
@@ -478,12 +616,10 @@ struct snd_soc_dai tlv320aic23_dai = { | |||
478 | .prepare = tlv320aic23_pcm_prepare, | 616 | .prepare = tlv320aic23_pcm_prepare, |
479 | .hw_params = tlv320aic23_hw_params, | 617 | .hw_params = tlv320aic23_hw_params, |
480 | .shutdown = tlv320aic23_shutdown, | 618 | .shutdown = tlv320aic23_shutdown, |
481 | }, | 619 | .digital_mute = tlv320aic23_mute, |
482 | .dai_ops = { | 620 | .set_fmt = tlv320aic23_set_dai_fmt, |
483 | .digital_mute = tlv320aic23_mute, | 621 | .set_sysclk = tlv320aic23_set_dai_sysclk, |
484 | .set_fmt = tlv320aic23_set_dai_fmt, | 622 | } |
485 | .set_sysclk = tlv320aic23_set_dai_sysclk, | ||
486 | } | ||
487 | }; | 623 | }; |
488 | EXPORT_SYMBOL_GPL(tlv320aic23_dai); | 624 | EXPORT_SYMBOL_GPL(tlv320aic23_dai); |
489 | 625 | ||
@@ -584,7 +720,7 @@ static int tlv320aic23_init(struct snd_soc_device *socdev) | |||
584 | 720 | ||
585 | tlv320aic23_add_controls(codec); | 721 | tlv320aic23_add_controls(codec); |
586 | tlv320aic23_add_widgets(codec); | 722 | tlv320aic23_add_widgets(codec); |
587 | ret = snd_soc_register_card(socdev); | 723 | ret = snd_soc_init_card(socdev); |
588 | if (ret < 0) { | 724 | if (ret < 0) { |
589 | printk(KERN_ERR "tlv320aic23: failed to register card\n"); | 725 | printk(KERN_ERR "tlv320aic23: failed to register card\n"); |
590 | goto card_err; | 726 | goto card_err; |
@@ -659,14 +795,15 @@ static int tlv320aic23_probe(struct platform_device *pdev) | |||
659 | { | 795 | { |
660 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 796 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
661 | struct snd_soc_codec *codec; | 797 | struct snd_soc_codec *codec; |
798 | struct aic23 *aic23; | ||
662 | int ret = 0; | 799 | int ret = 0; |
663 | 800 | ||
664 | printk(KERN_INFO "AIC23 Audio Codec %s\n", AIC23_VERSION); | 801 | printk(KERN_INFO "AIC23 Audio Codec %s\n", AIC23_VERSION); |
665 | 802 | ||
666 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | 803 | aic23 = kzalloc(sizeof(struct aic23), GFP_KERNEL); |
667 | if (codec == NULL) | 804 | if (aic23 == NULL) |
668 | return -ENOMEM; | 805 | return -ENOMEM; |
669 | 806 | codec = &aic23->codec; | |
670 | socdev->codec = codec; | 807 | socdev->codec = codec; |
671 | mutex_init(&codec->mutex); | 808 | mutex_init(&codec->mutex); |
672 | INIT_LIST_HEAD(&codec->dapm_widgets); | 809 | INIT_LIST_HEAD(&codec->dapm_widgets); |
@@ -687,6 +824,7 @@ static int tlv320aic23_remove(struct platform_device *pdev) | |||
687 | { | 824 | { |
688 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 825 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
689 | struct snd_soc_codec *codec = socdev->codec; | 826 | struct snd_soc_codec *codec = socdev->codec; |
827 | struct aic23 *aic23 = container_of(codec, struct aic23, codec); | ||
690 | 828 | ||
691 | if (codec->control_data) | 829 | if (codec->control_data) |
692 | tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_OFF); | 830 | tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_OFF); |
@@ -697,7 +835,7 @@ static int tlv320aic23_remove(struct platform_device *pdev) | |||
697 | i2c_del_driver(&tlv320aic23_i2c_driver); | 835 | i2c_del_driver(&tlv320aic23_i2c_driver); |
698 | #endif | 836 | #endif |
699 | kfree(codec->reg_cache); | 837 | kfree(codec->reg_cache); |
700 | kfree(codec); | 838 | kfree(aic23); |
701 | 839 | ||
702 | return 0; | 840 | return 0; |
703 | } | 841 | } |
@@ -709,6 +847,18 @@ struct snd_soc_codec_device soc_codec_dev_tlv320aic23 = { | |||
709 | }; | 847 | }; |
710 | EXPORT_SYMBOL_GPL(soc_codec_dev_tlv320aic23); | 848 | EXPORT_SYMBOL_GPL(soc_codec_dev_tlv320aic23); |
711 | 849 | ||
850 | static int __init tlv320aic23_modinit(void) | ||
851 | { | ||
852 | return snd_soc_register_dai(&tlv320aic23_dai); | ||
853 | } | ||
854 | module_init(tlv320aic23_modinit); | ||
855 | |||
856 | static void __exit tlv320aic23_exit(void) | ||
857 | { | ||
858 | snd_soc_unregister_dai(&tlv320aic23_dai); | ||
859 | } | ||
860 | module_exit(tlv320aic23_exit); | ||
861 | |||
712 | MODULE_DESCRIPTION("ASoC TLV320AIC23 codec driver"); | 862 | MODULE_DESCRIPTION("ASoC TLV320AIC23 codec driver"); |
713 | MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>"); | 863 | MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>"); |
714 | MODULE_LICENSE("GPL"); | 864 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c index bed8a9e63ddc..29f2f1a017fd 100644 --- a/sound/soc/codecs/tlv320aic26.c +++ b/sound/soc/codecs/tlv320aic26.c | |||
@@ -125,7 +125,8 @@ static int aic26_reg_write(struct snd_soc_codec *codec, unsigned int reg, | |||
125 | * Digital Audio Interface Operations | 125 | * Digital Audio Interface Operations |
126 | */ | 126 | */ |
127 | static int aic26_hw_params(struct snd_pcm_substream *substream, | 127 | static int aic26_hw_params(struct snd_pcm_substream *substream, |
128 | struct snd_pcm_hw_params *params) | 128 | struct snd_pcm_hw_params *params, |
129 | struct snd_soc_dai *dai) | ||
129 | { | 130 | { |
130 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 131 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
131 | struct snd_soc_device *socdev = rtd->socdev; | 132 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -287,8 +288,6 @@ struct snd_soc_dai aic26_dai = { | |||
287 | }, | 288 | }, |
288 | .ops = { | 289 | .ops = { |
289 | .hw_params = aic26_hw_params, | 290 | .hw_params = aic26_hw_params, |
290 | }, | ||
291 | .dai_ops = { | ||
292 | .digital_mute = aic26_mute, | 291 | .digital_mute = aic26_mute, |
293 | .set_sysclk = aic26_set_sysclk, | 292 | .set_sysclk = aic26_set_sysclk, |
294 | .set_fmt = aic26_set_fmt, | 293 | .set_fmt = aic26_set_fmt, |
@@ -360,7 +359,7 @@ static int aic26_probe(struct platform_device *pdev) | |||
360 | 359 | ||
361 | /* CODEC is setup, we can register the card now */ | 360 | /* CODEC is setup, we can register the card now */ |
362 | dev_dbg(&pdev->dev, "Registering card\n"); | 361 | dev_dbg(&pdev->dev, "Registering card\n"); |
363 | ret = snd_soc_register_card(socdev); | 362 | ret = snd_soc_init_card(socdev); |
364 | if (ret < 0) { | 363 | if (ret < 0) { |
365 | dev_err(&pdev->dev, "aic26: failed to register card\n"); | 364 | dev_err(&pdev->dev, "aic26: failed to register card\n"); |
366 | goto card_err; | 365 | goto card_err; |
@@ -427,7 +426,7 @@ static DEVICE_ATTR(keyclick, 0644, aic26_keyclick_show, aic26_keyclick_set); | |||
427 | static int aic26_spi_probe(struct spi_device *spi) | 426 | static int aic26_spi_probe(struct spi_device *spi) |
428 | { | 427 | { |
429 | struct aic26 *aic26; | 428 | struct aic26 *aic26; |
430 | int rc, i, reg; | 429 | int ret, i, reg; |
431 | 430 | ||
432 | dev_dbg(&spi->dev, "probing tlv320aic26 spi device\n"); | 431 | dev_dbg(&spi->dev, "probing tlv320aic26 spi device\n"); |
433 | 432 | ||
@@ -457,6 +456,14 @@ static int aic26_spi_probe(struct spi_device *spi) | |||
457 | aic26->codec.reg_cache_size = AIC26_NUM_REGS; | 456 | aic26->codec.reg_cache_size = AIC26_NUM_REGS; |
458 | aic26->codec.reg_cache = aic26->reg_cache; | 457 | aic26->codec.reg_cache = aic26->reg_cache; |
459 | 458 | ||
459 | aic26_dai.dev = &spi->dev; | ||
460 | ret = snd_soc_register_dai(&aic26_dai); | ||
461 | if (ret != 0) { | ||
462 | dev_err(&spi->dev, "Failed to register DAI: %d\n", ret); | ||
463 | kfree(aic26); | ||
464 | return ret; | ||
465 | } | ||
466 | |||
460 | /* Reset the codec to power on defaults */ | 467 | /* Reset the codec to power on defaults */ |
461 | aic26_reg_write(&aic26->codec, AIC26_REG_RESET, 0xBB00); | 468 | aic26_reg_write(&aic26->codec, AIC26_REG_RESET, 0xBB00); |
462 | 469 | ||
@@ -475,8 +482,8 @@ static int aic26_spi_probe(struct spi_device *spi) | |||
475 | 482 | ||
476 | /* Register the sysfs files for debugging */ | 483 | /* Register the sysfs files for debugging */ |
477 | /* Create SysFS files */ | 484 | /* Create SysFS files */ |
478 | rc = device_create_file(&spi->dev, &dev_attr_keyclick); | 485 | ret = device_create_file(&spi->dev, &dev_attr_keyclick); |
479 | if (rc) | 486 | if (ret) |
480 | dev_info(&spi->dev, "error creating sysfs files\n"); | 487 | dev_info(&spi->dev, "error creating sysfs files\n"); |
481 | 488 | ||
482 | #if defined(CONFIG_SND_SOC_OF_SIMPLE) | 489 | #if defined(CONFIG_SND_SOC_OF_SIMPLE) |
@@ -493,6 +500,7 @@ static int aic26_spi_remove(struct spi_device *spi) | |||
493 | { | 500 | { |
494 | struct aic26 *aic26 = dev_get_drvdata(&spi->dev); | 501 | struct aic26 *aic26 = dev_get_drvdata(&spi->dev); |
495 | 502 | ||
503 | snd_soc_unregister_dai(&aic26_dai); | ||
496 | kfree(aic26); | 504 | kfree(aic26); |
497 | 505 | ||
498 | return 0; | 506 | return 0; |
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c index cff276ee261e..b47a749c5ea2 100644 --- a/sound/soc/codecs/tlv320aic3x.c +++ b/sound/soc/codecs/tlv320aic3x.c | |||
@@ -253,11 +253,17 @@ static const struct snd_kcontrol_new aic3x_snd_controls[] = { | |||
253 | 253 | ||
254 | SOC_DOUBLE_R("Line DAC Playback Volume", DACL1_2_LLOPM_VOL, | 254 | SOC_DOUBLE_R("Line DAC Playback Volume", DACL1_2_LLOPM_VOL, |
255 | DACR1_2_RLOPM_VOL, 0, 0x7f, 1), | 255 | DACR1_2_RLOPM_VOL, 0, 0x7f, 1), |
256 | SOC_DOUBLE_R("Line DAC Playback Switch", LLOPM_CTRL, RLOPM_CTRL, 3, | 256 | SOC_SINGLE("LineL Playback Switch", LLOPM_CTRL, 3, 0x01, 0), |
257 | 0x01, 0), | 257 | SOC_SINGLE("LineR Playback Switch", RLOPM_CTRL, 3, 0x01, 0), |
258 | SOC_DOUBLE_R("Line PGA Bypass Playback Volume", PGAL_2_LLOPM_VOL, | 258 | SOC_DOUBLE_R("LineL DAC Playback Volume", DACL1_2_LLOPM_VOL, |
259 | PGAR_2_RLOPM_VOL, 0, 0x7f, 1), | 259 | DACR1_2_LLOPM_VOL, 0, 0x7f, 1), |
260 | SOC_DOUBLE_R("Line Line2 Bypass Playback Volume", LINE2L_2_LLOPM_VOL, | 260 | SOC_SINGLE("LineL Left PGA Bypass Playback Volume", PGAL_2_LLOPM_VOL, |
261 | 0, 0x7f, 1), | ||
262 | SOC_SINGLE("LineR Right PGA Bypass Playback Volume", PGAR_2_RLOPM_VOL, | ||
263 | 0, 0x7f, 1), | ||
264 | SOC_DOUBLE_R("LineL Line2 Bypass Playback Volume", LINE2L_2_LLOPM_VOL, | ||
265 | LINE2R_2_LLOPM_VOL, 0, 0x7f, 1), | ||
266 | SOC_DOUBLE_R("LineR Line2 Bypass Playback Volume", LINE2L_2_RLOPM_VOL, | ||
261 | LINE2R_2_RLOPM_VOL, 0, 0x7f, 1), | 267 | LINE2R_2_RLOPM_VOL, 0, 0x7f, 1), |
262 | 268 | ||
263 | SOC_DOUBLE_R("Mono DAC Playback Volume", DACL1_2_MONOLOPM_VOL, | 269 | SOC_DOUBLE_R("Mono DAC Playback Volume", DACL1_2_MONOLOPM_VOL, |
@@ -272,8 +278,12 @@ static const struct snd_kcontrol_new aic3x_snd_controls[] = { | |||
272 | DACR1_2_HPROUT_VOL, 0, 0x7f, 1), | 278 | DACR1_2_HPROUT_VOL, 0, 0x7f, 1), |
273 | SOC_DOUBLE_R("HP DAC Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3, | 279 | SOC_DOUBLE_R("HP DAC Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3, |
274 | 0x01, 0), | 280 | 0x01, 0), |
275 | SOC_DOUBLE_R("HP PGA Bypass Playback Volume", PGAL_2_HPLOUT_VOL, | 281 | SOC_DOUBLE_R("HP Right PGA Bypass Playback Volume", PGAR_2_HPLOUT_VOL, |
276 | PGAR_2_HPROUT_VOL, 0, 0x7f, 1), | 282 | PGAR_2_HPROUT_VOL, 0, 0x7f, 1), |
283 | SOC_SINGLE("HPL PGA Bypass Playback Volume", PGAL_2_HPLOUT_VOL, | ||
284 | 0, 0x7f, 1), | ||
285 | SOC_SINGLE("HPR PGA Bypass Playback Volume", PGAL_2_HPROUT_VOL, | ||
286 | 0, 0x7f, 1), | ||
277 | SOC_DOUBLE_R("HP Line2 Bypass Playback Volume", LINE2L_2_HPLOUT_VOL, | 287 | SOC_DOUBLE_R("HP Line2 Bypass Playback Volume", LINE2L_2_HPLOUT_VOL, |
278 | LINE2R_2_HPROUT_VOL, 0, 0x7f, 1), | 288 | LINE2R_2_HPROUT_VOL, 0, 0x7f, 1), |
279 | 289 | ||
@@ -281,8 +291,10 @@ static const struct snd_kcontrol_new aic3x_snd_controls[] = { | |||
281 | DACR1_2_HPRCOM_VOL, 0, 0x7f, 1), | 291 | DACR1_2_HPRCOM_VOL, 0, 0x7f, 1), |
282 | SOC_DOUBLE_R("HPCOM DAC Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3, | 292 | SOC_DOUBLE_R("HPCOM DAC Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3, |
283 | 0x01, 0), | 293 | 0x01, 0), |
284 | SOC_DOUBLE_R("HPCOM PGA Bypass Playback Volume", PGAL_2_HPLCOM_VOL, | 294 | SOC_SINGLE("HPLCOM PGA Bypass Playback Volume", PGAL_2_HPLCOM_VOL, |
285 | PGAR_2_HPRCOM_VOL, 0, 0x7f, 1), | 295 | 0, 0x7f, 1), |
296 | SOC_SINGLE("HPRCOM PGA Bypass Playback Volume", PGAL_2_HPRCOM_VOL, | ||
297 | 0, 0x7f, 1), | ||
286 | SOC_DOUBLE_R("HPCOM Line2 Bypass Playback Volume", LINE2L_2_HPLCOM_VOL, | 298 | SOC_DOUBLE_R("HPCOM Line2 Bypass Playback Volume", LINE2L_2_HPLCOM_VOL, |
287 | LINE2R_2_HPRCOM_VOL, 0, 0x7f, 1), | 299 | LINE2R_2_HPRCOM_VOL, 0, 0x7f, 1), |
288 | 300 | ||
@@ -333,7 +345,8 @@ SOC_DAPM_ENUM("Route", aic3x_enum[RHPCOM_ENUM]); | |||
333 | 345 | ||
334 | /* Left DAC_L1 Mixer */ | 346 | /* Left DAC_L1 Mixer */ |
335 | static const struct snd_kcontrol_new aic3x_left_dac_mixer_controls[] = { | 347 | static const struct snd_kcontrol_new aic3x_left_dac_mixer_controls[] = { |
336 | SOC_DAPM_SINGLE("Line Switch", DACL1_2_LLOPM_VOL, 7, 1, 0), | 348 | SOC_DAPM_SINGLE("LineL Switch", DACL1_2_LLOPM_VOL, 7, 1, 0), |
349 | SOC_DAPM_SINGLE("LineR Switch", DACL1_2_RLOPM_VOL, 7, 1, 0), | ||
337 | SOC_DAPM_SINGLE("Mono Switch", DACL1_2_MONOLOPM_VOL, 7, 1, 0), | 350 | SOC_DAPM_SINGLE("Mono Switch", DACL1_2_MONOLOPM_VOL, 7, 1, 0), |
338 | SOC_DAPM_SINGLE("HP Switch", DACL1_2_HPLOUT_VOL, 7, 1, 0), | 351 | SOC_DAPM_SINGLE("HP Switch", DACL1_2_HPLOUT_VOL, 7, 1, 0), |
339 | SOC_DAPM_SINGLE("HPCOM Switch", DACL1_2_HPLCOM_VOL, 7, 1, 0), | 352 | SOC_DAPM_SINGLE("HPCOM Switch", DACL1_2_HPLCOM_VOL, 7, 1, 0), |
@@ -341,7 +354,8 @@ static const struct snd_kcontrol_new aic3x_left_dac_mixer_controls[] = { | |||
341 | 354 | ||
342 | /* Right DAC_R1 Mixer */ | 355 | /* Right DAC_R1 Mixer */ |
343 | static const struct snd_kcontrol_new aic3x_right_dac_mixer_controls[] = { | 356 | static const struct snd_kcontrol_new aic3x_right_dac_mixer_controls[] = { |
344 | SOC_DAPM_SINGLE("Line Switch", DACR1_2_RLOPM_VOL, 7, 1, 0), | 357 | SOC_DAPM_SINGLE("LineL Switch", DACR1_2_LLOPM_VOL, 7, 1, 0), |
358 | SOC_DAPM_SINGLE("LineR Switch", DACR1_2_RLOPM_VOL, 7, 1, 0), | ||
345 | SOC_DAPM_SINGLE("Mono Switch", DACR1_2_MONOLOPM_VOL, 7, 1, 0), | 359 | SOC_DAPM_SINGLE("Mono Switch", DACR1_2_MONOLOPM_VOL, 7, 1, 0), |
346 | SOC_DAPM_SINGLE("HP Switch", DACR1_2_HPROUT_VOL, 7, 1, 0), | 360 | SOC_DAPM_SINGLE("HP Switch", DACR1_2_HPROUT_VOL, 7, 1, 0), |
347 | SOC_DAPM_SINGLE("HPCOM Switch", DACR1_2_HPRCOM_VOL, 7, 1, 0), | 361 | SOC_DAPM_SINGLE("HPCOM Switch", DACR1_2_HPRCOM_VOL, 7, 1, 0), |
@@ -350,14 +364,18 @@ static const struct snd_kcontrol_new aic3x_right_dac_mixer_controls[] = { | |||
350 | /* Left PGA Mixer */ | 364 | /* Left PGA Mixer */ |
351 | static const struct snd_kcontrol_new aic3x_left_pga_mixer_controls[] = { | 365 | static const struct snd_kcontrol_new aic3x_left_pga_mixer_controls[] = { |
352 | SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1), | 366 | SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1), |
367 | SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_LADC_CTRL, 3, 1, 1), | ||
353 | SOC_DAPM_SINGLE_AIC3X("Line2L Switch", LINE2L_2_LADC_CTRL, 3, 1, 1), | 368 | SOC_DAPM_SINGLE_AIC3X("Line2L Switch", LINE2L_2_LADC_CTRL, 3, 1, 1), |
354 | SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1), | 369 | SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1), |
370 | SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_LADC_CTRL, 0, 1, 1), | ||
355 | }; | 371 | }; |
356 | 372 | ||
357 | /* Right PGA Mixer */ | 373 | /* Right PGA Mixer */ |
358 | static const struct snd_kcontrol_new aic3x_right_pga_mixer_controls[] = { | 374 | static const struct snd_kcontrol_new aic3x_right_pga_mixer_controls[] = { |
359 | SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1), | 375 | SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1), |
376 | SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_RADC_CTRL, 3, 1, 1), | ||
360 | SOC_DAPM_SINGLE_AIC3X("Line2R Switch", LINE2R_2_RADC_CTRL, 3, 1, 1), | 377 | SOC_DAPM_SINGLE_AIC3X("Line2R Switch", LINE2R_2_RADC_CTRL, 3, 1, 1), |
378 | SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_RADC_CTRL, 4, 1, 1), | ||
361 | SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1), | 379 | SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1), |
362 | }; | 380 | }; |
363 | 381 | ||
@@ -379,34 +397,42 @@ SOC_DAPM_ENUM("Route", aic3x_enum[LINE2R_ENUM]); | |||
379 | 397 | ||
380 | /* Left PGA Bypass Mixer */ | 398 | /* Left PGA Bypass Mixer */ |
381 | static const struct snd_kcontrol_new aic3x_left_pga_bp_mixer_controls[] = { | 399 | static const struct snd_kcontrol_new aic3x_left_pga_bp_mixer_controls[] = { |
382 | SOC_DAPM_SINGLE("Line Switch", PGAL_2_LLOPM_VOL, 7, 1, 0), | 400 | SOC_DAPM_SINGLE("LineL Switch", PGAL_2_LLOPM_VOL, 7, 1, 0), |
401 | SOC_DAPM_SINGLE("LineR Switch", PGAL_2_RLOPM_VOL, 7, 1, 0), | ||
383 | SOC_DAPM_SINGLE("Mono Switch", PGAL_2_MONOLOPM_VOL, 7, 1, 0), | 402 | SOC_DAPM_SINGLE("Mono Switch", PGAL_2_MONOLOPM_VOL, 7, 1, 0), |
384 | SOC_DAPM_SINGLE("HP Switch", PGAL_2_HPLOUT_VOL, 7, 1, 0), | 403 | SOC_DAPM_SINGLE("HPL Switch", PGAL_2_HPLOUT_VOL, 7, 1, 0), |
385 | SOC_DAPM_SINGLE("HPCOM Switch", PGAL_2_HPLCOM_VOL, 7, 1, 0), | 404 | SOC_DAPM_SINGLE("HPR Switch", PGAL_2_HPROUT_VOL, 7, 1, 0), |
405 | SOC_DAPM_SINGLE("HPLCOM Switch", PGAL_2_HPLCOM_VOL, 7, 1, 0), | ||
406 | SOC_DAPM_SINGLE("HPRCOM Switch", PGAL_2_HPRCOM_VOL, 7, 1, 0), | ||
386 | }; | 407 | }; |
387 | 408 | ||
388 | /* Right PGA Bypass Mixer */ | 409 | /* Right PGA Bypass Mixer */ |
389 | static const struct snd_kcontrol_new aic3x_right_pga_bp_mixer_controls[] = { | 410 | static const struct snd_kcontrol_new aic3x_right_pga_bp_mixer_controls[] = { |
390 | SOC_DAPM_SINGLE("Line Switch", PGAR_2_RLOPM_VOL, 7, 1, 0), | 411 | SOC_DAPM_SINGLE("LineL Switch", PGAR_2_LLOPM_VOL, 7, 1, 0), |
412 | SOC_DAPM_SINGLE("LineR Switch", PGAR_2_RLOPM_VOL, 7, 1, 0), | ||
391 | SOC_DAPM_SINGLE("Mono Switch", PGAR_2_MONOLOPM_VOL, 7, 1, 0), | 413 | SOC_DAPM_SINGLE("Mono Switch", PGAR_2_MONOLOPM_VOL, 7, 1, 0), |
392 | SOC_DAPM_SINGLE("HP Switch", PGAR_2_HPROUT_VOL, 7, 1, 0), | 414 | SOC_DAPM_SINGLE("HPL Switch", PGAR_2_HPLOUT_VOL, 7, 1, 0), |
393 | SOC_DAPM_SINGLE("HPCOM Switch", PGAR_2_HPRCOM_VOL, 7, 1, 0), | 415 | SOC_DAPM_SINGLE("HPR Switch", PGAR_2_HPROUT_VOL, 7, 1, 0), |
416 | SOC_DAPM_SINGLE("HPLCOM Switch", PGAR_2_HPLCOM_VOL, 7, 1, 0), | ||
417 | SOC_DAPM_SINGLE("HPRCOM Switch", PGAR_2_HPRCOM_VOL, 7, 1, 0), | ||
394 | }; | 418 | }; |
395 | 419 | ||
396 | /* Left Line2 Bypass Mixer */ | 420 | /* Left Line2 Bypass Mixer */ |
397 | static const struct snd_kcontrol_new aic3x_left_line2_bp_mixer_controls[] = { | 421 | static const struct snd_kcontrol_new aic3x_left_line2_bp_mixer_controls[] = { |
398 | SOC_DAPM_SINGLE("Line Switch", LINE2L_2_LLOPM_VOL, 7, 1, 0), | 422 | SOC_DAPM_SINGLE("LineL Switch", LINE2L_2_LLOPM_VOL, 7, 1, 0), |
423 | SOC_DAPM_SINGLE("LineR Switch", LINE2L_2_RLOPM_VOL, 7, 1, 0), | ||
399 | SOC_DAPM_SINGLE("Mono Switch", LINE2L_2_MONOLOPM_VOL, 7, 1, 0), | 424 | SOC_DAPM_SINGLE("Mono Switch", LINE2L_2_MONOLOPM_VOL, 7, 1, 0), |
400 | SOC_DAPM_SINGLE("HP Switch", LINE2L_2_HPLOUT_VOL, 7, 1, 0), | 425 | SOC_DAPM_SINGLE("HP Switch", LINE2L_2_HPLOUT_VOL, 7, 1, 0), |
401 | SOC_DAPM_SINGLE("HPCOM Switch", LINE2L_2_HPLCOM_VOL, 7, 1, 0), | 426 | SOC_DAPM_SINGLE("HPLCOM Switch", LINE2L_2_HPLCOM_VOL, 7, 1, 0), |
402 | }; | 427 | }; |
403 | 428 | ||
404 | /* Right Line2 Bypass Mixer */ | 429 | /* Right Line2 Bypass Mixer */ |
405 | static const struct snd_kcontrol_new aic3x_right_line2_bp_mixer_controls[] = { | 430 | static const struct snd_kcontrol_new aic3x_right_line2_bp_mixer_controls[] = { |
406 | SOC_DAPM_SINGLE("Line Switch", LINE2R_2_RLOPM_VOL, 7, 1, 0), | 431 | SOC_DAPM_SINGLE("LineL Switch", LINE2R_2_LLOPM_VOL, 7, 1, 0), |
432 | SOC_DAPM_SINGLE("LineR Switch", LINE2R_2_RLOPM_VOL, 7, 1, 0), | ||
407 | SOC_DAPM_SINGLE("Mono Switch", LINE2R_2_MONOLOPM_VOL, 7, 1, 0), | 433 | SOC_DAPM_SINGLE("Mono Switch", LINE2R_2_MONOLOPM_VOL, 7, 1, 0), |
408 | SOC_DAPM_SINGLE("HP Switch", LINE2R_2_HPROUT_VOL, 7, 1, 0), | 434 | SOC_DAPM_SINGLE("HP Switch", LINE2R_2_HPROUT_VOL, 7, 1, 0), |
409 | SOC_DAPM_SINGLE("HPCOM Switch", LINE2R_2_HPRCOM_VOL, 7, 1, 0), | 435 | SOC_DAPM_SINGLE("HPRCOM Switch", LINE2R_2_HPRCOM_VOL, 7, 1, 0), |
410 | }; | 436 | }; |
411 | 437 | ||
412 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { | 438 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { |
@@ -439,22 +465,26 @@ static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { | |||
439 | /* Mono Output */ | 465 | /* Mono Output */ |
440 | SND_SOC_DAPM_PGA("Mono Out", MONOLOPM_CTRL, 0, 0, NULL, 0), | 466 | SND_SOC_DAPM_PGA("Mono Out", MONOLOPM_CTRL, 0, 0, NULL, 0), |
441 | 467 | ||
442 | /* Left Inputs to Left ADC */ | 468 | /* Inputs to Left ADC */ |
443 | SND_SOC_DAPM_ADC("Left ADC", "Left Capture", LINE1L_2_LADC_CTRL, 2, 0), | 469 | SND_SOC_DAPM_ADC("Left ADC", "Left Capture", LINE1L_2_LADC_CTRL, 2, 0), |
444 | SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0, | 470 | SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0, |
445 | &aic3x_left_pga_mixer_controls[0], | 471 | &aic3x_left_pga_mixer_controls[0], |
446 | ARRAY_SIZE(aic3x_left_pga_mixer_controls)), | 472 | ARRAY_SIZE(aic3x_left_pga_mixer_controls)), |
447 | SND_SOC_DAPM_MUX("Left Line1L Mux", SND_SOC_NOPM, 0, 0, | 473 | SND_SOC_DAPM_MUX("Left Line1L Mux", SND_SOC_NOPM, 0, 0, |
448 | &aic3x_left_line1_mux_controls), | 474 | &aic3x_left_line1_mux_controls), |
475 | SND_SOC_DAPM_MUX("Left Line1R Mux", SND_SOC_NOPM, 0, 0, | ||
476 | &aic3x_left_line1_mux_controls), | ||
449 | SND_SOC_DAPM_MUX("Left Line2L Mux", SND_SOC_NOPM, 0, 0, | 477 | SND_SOC_DAPM_MUX("Left Line2L Mux", SND_SOC_NOPM, 0, 0, |
450 | &aic3x_left_line2_mux_controls), | 478 | &aic3x_left_line2_mux_controls), |
451 | 479 | ||
452 | /* Right Inputs to Right ADC */ | 480 | /* Inputs to Right ADC */ |
453 | SND_SOC_DAPM_ADC("Right ADC", "Right Capture", | 481 | SND_SOC_DAPM_ADC("Right ADC", "Right Capture", |
454 | LINE1R_2_RADC_CTRL, 2, 0), | 482 | LINE1R_2_RADC_CTRL, 2, 0), |
455 | SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0, | 483 | SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0, |
456 | &aic3x_right_pga_mixer_controls[0], | 484 | &aic3x_right_pga_mixer_controls[0], |
457 | ARRAY_SIZE(aic3x_right_pga_mixer_controls)), | 485 | ARRAY_SIZE(aic3x_right_pga_mixer_controls)), |
486 | SND_SOC_DAPM_MUX("Right Line1L Mux", SND_SOC_NOPM, 0, 0, | ||
487 | &aic3x_right_line1_mux_controls), | ||
458 | SND_SOC_DAPM_MUX("Right Line1R Mux", SND_SOC_NOPM, 0, 0, | 488 | SND_SOC_DAPM_MUX("Right Line1R Mux", SND_SOC_NOPM, 0, 0, |
459 | &aic3x_right_line1_mux_controls), | 489 | &aic3x_right_line1_mux_controls), |
460 | SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0, | 490 | SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0, |
@@ -531,7 +561,8 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
531 | {"Left DAC Mux", "DAC_L2", "Left DAC"}, | 561 | {"Left DAC Mux", "DAC_L2", "Left DAC"}, |
532 | {"Left DAC Mux", "DAC_L3", "Left DAC"}, | 562 | {"Left DAC Mux", "DAC_L3", "Left DAC"}, |
533 | 563 | ||
534 | {"Left DAC_L1 Mixer", "Line Switch", "Left DAC Mux"}, | 564 | {"Left DAC_L1 Mixer", "LineL Switch", "Left DAC Mux"}, |
565 | {"Left DAC_L1 Mixer", "LineR Switch", "Left DAC Mux"}, | ||
535 | {"Left DAC_L1 Mixer", "Mono Switch", "Left DAC Mux"}, | 566 | {"Left DAC_L1 Mixer", "Mono Switch", "Left DAC Mux"}, |
536 | {"Left DAC_L1 Mixer", "HP Switch", "Left DAC Mux"}, | 567 | {"Left DAC_L1 Mixer", "HP Switch", "Left DAC Mux"}, |
537 | {"Left DAC_L1 Mixer", "HPCOM Switch", "Left DAC Mux"}, | 568 | {"Left DAC_L1 Mixer", "HPCOM Switch", "Left DAC Mux"}, |
@@ -557,7 +588,8 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
557 | {"Right DAC Mux", "DAC_R2", "Right DAC"}, | 588 | {"Right DAC Mux", "DAC_R2", "Right DAC"}, |
558 | {"Right DAC Mux", "DAC_R3", "Right DAC"}, | 589 | {"Right DAC Mux", "DAC_R3", "Right DAC"}, |
559 | 590 | ||
560 | {"Right DAC_R1 Mixer", "Line Switch", "Right DAC Mux"}, | 591 | {"Right DAC_R1 Mixer", "LineL Switch", "Right DAC Mux"}, |
592 | {"Right DAC_R1 Mixer", "LineR Switch", "Right DAC Mux"}, | ||
561 | {"Right DAC_R1 Mixer", "Mono Switch", "Right DAC Mux"}, | 593 | {"Right DAC_R1 Mixer", "Mono Switch", "Right DAC Mux"}, |
562 | {"Right DAC_R1 Mixer", "HP Switch", "Right DAC Mux"}, | 594 | {"Right DAC_R1 Mixer", "HP Switch", "Right DAC Mux"}, |
563 | {"Right DAC_R1 Mixer", "HPCOM Switch", "Right DAC Mux"}, | 595 | {"Right DAC_R1 Mixer", "HPCOM Switch", "Right DAC Mux"}, |
@@ -592,8 +624,10 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
592 | {"Left Line2L Mux", "differential", "LINE2L"}, | 624 | {"Left Line2L Mux", "differential", "LINE2L"}, |
593 | 625 | ||
594 | {"Left PGA Mixer", "Line1L Switch", "Left Line1L Mux"}, | 626 | {"Left PGA Mixer", "Line1L Switch", "Left Line1L Mux"}, |
627 | {"Left PGA Mixer", "Line1R Switch", "Left Line1R Mux"}, | ||
595 | {"Left PGA Mixer", "Line2L Switch", "Left Line2L Mux"}, | 628 | {"Left PGA Mixer", "Line2L Switch", "Left Line2L Mux"}, |
596 | {"Left PGA Mixer", "Mic3L Switch", "MIC3L"}, | 629 | {"Left PGA Mixer", "Mic3L Switch", "MIC3L"}, |
630 | {"Left PGA Mixer", "Mic3R Switch", "MIC3R"}, | ||
597 | 631 | ||
598 | {"Left ADC", NULL, "Left PGA Mixer"}, | 632 | {"Left ADC", NULL, "Left PGA Mixer"}, |
599 | {"Left ADC", NULL, "GPIO1 dmic modclk"}, | 633 | {"Left ADC", NULL, "GPIO1 dmic modclk"}, |
@@ -605,18 +639,23 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
605 | {"Right Line2R Mux", "single-ended", "LINE2R"}, | 639 | {"Right Line2R Mux", "single-ended", "LINE2R"}, |
606 | {"Right Line2R Mux", "differential", "LINE2R"}, | 640 | {"Right Line2R Mux", "differential", "LINE2R"}, |
607 | 641 | ||
642 | {"Right PGA Mixer", "Line1L Switch", "Right Line1L Mux"}, | ||
608 | {"Right PGA Mixer", "Line1R Switch", "Right Line1R Mux"}, | 643 | {"Right PGA Mixer", "Line1R Switch", "Right Line1R Mux"}, |
609 | {"Right PGA Mixer", "Line2R Switch", "Right Line2R Mux"}, | 644 | {"Right PGA Mixer", "Line2R Switch", "Right Line2R Mux"}, |
645 | {"Right PGA Mixer", "Mic3L Switch", "MIC3L"}, | ||
610 | {"Right PGA Mixer", "Mic3R Switch", "MIC3R"}, | 646 | {"Right PGA Mixer", "Mic3R Switch", "MIC3R"}, |
611 | 647 | ||
612 | {"Right ADC", NULL, "Right PGA Mixer"}, | 648 | {"Right ADC", NULL, "Right PGA Mixer"}, |
613 | {"Right ADC", NULL, "GPIO1 dmic modclk"}, | 649 | {"Right ADC", NULL, "GPIO1 dmic modclk"}, |
614 | 650 | ||
615 | /* Left PGA Bypass */ | 651 | /* Left PGA Bypass */ |
616 | {"Left PGA Bypass Mixer", "Line Switch", "Left PGA Mixer"}, | 652 | {"Left PGA Bypass Mixer", "LineL Switch", "Left PGA Mixer"}, |
653 | {"Left PGA Bypass Mixer", "LineR Switch", "Left PGA Mixer"}, | ||
617 | {"Left PGA Bypass Mixer", "Mono Switch", "Left PGA Mixer"}, | 654 | {"Left PGA Bypass Mixer", "Mono Switch", "Left PGA Mixer"}, |
618 | {"Left PGA Bypass Mixer", "HP Switch", "Left PGA Mixer"}, | 655 | {"Left PGA Bypass Mixer", "HPL Switch", "Left PGA Mixer"}, |
619 | {"Left PGA Bypass Mixer", "HPCOM Switch", "Left PGA Mixer"}, | 656 | {"Left PGA Bypass Mixer", "HPR Switch", "Left PGA Mixer"}, |
657 | {"Left PGA Bypass Mixer", "HPLCOM Switch", "Left PGA Mixer"}, | ||
658 | {"Left PGA Bypass Mixer", "HPRCOM Switch", "Left PGA Mixer"}, | ||
620 | 659 | ||
621 | {"Left HPCOM Mux", "differential of HPLOUT", "Left PGA Bypass Mixer"}, | 660 | {"Left HPCOM Mux", "differential of HPLOUT", "Left PGA Bypass Mixer"}, |
622 | {"Left HPCOM Mux", "constant VCM", "Left PGA Bypass Mixer"}, | 661 | {"Left HPCOM Mux", "constant VCM", "Left PGA Bypass Mixer"}, |
@@ -627,10 +666,13 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
627 | {"Left HP Out", NULL, "Left PGA Bypass Mixer"}, | 666 | {"Left HP Out", NULL, "Left PGA Bypass Mixer"}, |
628 | 667 | ||
629 | /* Right PGA Bypass */ | 668 | /* Right PGA Bypass */ |
630 | {"Right PGA Bypass Mixer", "Line Switch", "Right PGA Mixer"}, | 669 | {"Right PGA Bypass Mixer", "LineL Switch", "Right PGA Mixer"}, |
670 | {"Right PGA Bypass Mixer", "LineR Switch", "Right PGA Mixer"}, | ||
631 | {"Right PGA Bypass Mixer", "Mono Switch", "Right PGA Mixer"}, | 671 | {"Right PGA Bypass Mixer", "Mono Switch", "Right PGA Mixer"}, |
632 | {"Right PGA Bypass Mixer", "HP Switch", "Right PGA Mixer"}, | 672 | {"Right PGA Bypass Mixer", "HPL Switch", "Right PGA Mixer"}, |
633 | {"Right PGA Bypass Mixer", "HPCOM Switch", "Right PGA Mixer"}, | 673 | {"Right PGA Bypass Mixer", "HPR Switch", "Right PGA Mixer"}, |
674 | {"Right PGA Bypass Mixer", "HPLCOM Switch", "Right PGA Mixer"}, | ||
675 | {"Right PGA Bypass Mixer", "HPRCOM Switch", "Right PGA Mixer"}, | ||
634 | 676 | ||
635 | {"Right HPCOM Mux", "differential of HPROUT", "Right PGA Bypass Mixer"}, | 677 | {"Right HPCOM Mux", "differential of HPROUT", "Right PGA Bypass Mixer"}, |
636 | {"Right HPCOM Mux", "constant VCM", "Right PGA Bypass Mixer"}, | 678 | {"Right HPCOM Mux", "constant VCM", "Right PGA Bypass Mixer"}, |
@@ -643,10 +685,11 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
643 | {"Right HP Out", NULL, "Right PGA Bypass Mixer"}, | 685 | {"Right HP Out", NULL, "Right PGA Bypass Mixer"}, |
644 | 686 | ||
645 | /* Left Line2 Bypass */ | 687 | /* Left Line2 Bypass */ |
646 | {"Left Line2 Bypass Mixer", "Line Switch", "Left Line2L Mux"}, | 688 | {"Left Line2 Bypass Mixer", "LineL Switch", "Left Line2L Mux"}, |
689 | {"Left Line2 Bypass Mixer", "LineR Switch", "Left Line2L Mux"}, | ||
647 | {"Left Line2 Bypass Mixer", "Mono Switch", "Left Line2L Mux"}, | 690 | {"Left Line2 Bypass Mixer", "Mono Switch", "Left Line2L Mux"}, |
648 | {"Left Line2 Bypass Mixer", "HP Switch", "Left Line2L Mux"}, | 691 | {"Left Line2 Bypass Mixer", "HP Switch", "Left Line2L Mux"}, |
649 | {"Left Line2 Bypass Mixer", "HPCOM Switch", "Left Line2L Mux"}, | 692 | {"Left Line2 Bypass Mixer", "HPLCOM Switch", "Left Line2L Mux"}, |
650 | 693 | ||
651 | {"Left HPCOM Mux", "differential of HPLOUT", "Left Line2 Bypass Mixer"}, | 694 | {"Left HPCOM Mux", "differential of HPLOUT", "Left Line2 Bypass Mixer"}, |
652 | {"Left HPCOM Mux", "constant VCM", "Left Line2 Bypass Mixer"}, | 695 | {"Left HPCOM Mux", "constant VCM", "Left Line2 Bypass Mixer"}, |
@@ -657,10 +700,11 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
657 | {"Left HP Out", NULL, "Left Line2 Bypass Mixer"}, | 700 | {"Left HP Out", NULL, "Left Line2 Bypass Mixer"}, |
658 | 701 | ||
659 | /* Right Line2 Bypass */ | 702 | /* Right Line2 Bypass */ |
660 | {"Right Line2 Bypass Mixer", "Line Switch", "Right Line2R Mux"}, | 703 | {"Right Line2 Bypass Mixer", "LineL Switch", "Right Line2R Mux"}, |
704 | {"Right Line2 Bypass Mixer", "LineR Switch", "Right Line2R Mux"}, | ||
661 | {"Right Line2 Bypass Mixer", "Mono Switch", "Right Line2R Mux"}, | 705 | {"Right Line2 Bypass Mixer", "Mono Switch", "Right Line2R Mux"}, |
662 | {"Right Line2 Bypass Mixer", "HP Switch", "Right Line2R Mux"}, | 706 | {"Right Line2 Bypass Mixer", "HP Switch", "Right Line2R Mux"}, |
663 | {"Right Line2 Bypass Mixer", "HPCOM Switch", "Right Line2R Mux"}, | 707 | {"Right Line2 Bypass Mixer", "HPRCOM Switch", "Right Line2R Mux"}, |
664 | 708 | ||
665 | {"Right HPCOM Mux", "differential of HPROUT", "Right Line2 Bypass Mixer"}, | 709 | {"Right HPCOM Mux", "differential of HPROUT", "Right Line2 Bypass Mixer"}, |
666 | {"Right HPCOM Mux", "constant VCM", "Right Line2 Bypass Mixer"}, | 710 | {"Right HPCOM Mux", "constant VCM", "Right Line2 Bypass Mixer"}, |
@@ -694,7 +738,8 @@ static int aic3x_add_widgets(struct snd_soc_codec *codec) | |||
694 | } | 738 | } |
695 | 739 | ||
696 | static int aic3x_hw_params(struct snd_pcm_substream *substream, | 740 | static int aic3x_hw_params(struct snd_pcm_substream *substream, |
697 | struct snd_pcm_hw_params *params) | 741 | struct snd_pcm_hw_params *params, |
742 | struct snd_soc_dai *dai) | ||
698 | { | 743 | { |
699 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 744 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
700 | struct snd_soc_device *socdev = rtd->socdev; | 745 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -846,6 +891,7 @@ static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
846 | struct snd_soc_codec *codec = codec_dai->codec; | 891 | struct snd_soc_codec *codec = codec_dai->codec; |
847 | struct aic3x_priv *aic3x = codec->private_data; | 892 | struct aic3x_priv *aic3x = codec->private_data; |
848 | u8 iface_areg, iface_breg; | 893 | u8 iface_areg, iface_breg; |
894 | int delay = 0; | ||
849 | 895 | ||
850 | iface_areg = aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLA) & 0x3f; | 896 | iface_areg = aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLA) & 0x3f; |
851 | iface_breg = aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLB) & 0x3f; | 897 | iface_breg = aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLB) & 0x3f; |
@@ -871,6 +917,8 @@ static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
871 | SND_SOC_DAIFMT_INV_MASK)) { | 917 | SND_SOC_DAIFMT_INV_MASK)) { |
872 | case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF): | 918 | case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF): |
873 | break; | 919 | break; |
920 | case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF): | ||
921 | delay = 1; | ||
874 | case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF): | 922 | case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF): |
875 | iface_breg |= (0x01 << 6); | 923 | iface_breg |= (0x01 << 6); |
876 | break; | 924 | break; |
@@ -887,6 +935,7 @@ static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
887 | /* set iface */ | 935 | /* set iface */ |
888 | aic3x_write(codec, AIC3X_ASD_INTF_CTRLA, iface_areg); | 936 | aic3x_write(codec, AIC3X_ASD_INTF_CTRLA, iface_areg); |
889 | aic3x_write(codec, AIC3X_ASD_INTF_CTRLB, iface_breg); | 937 | aic3x_write(codec, AIC3X_ASD_INTF_CTRLB, iface_breg); |
938 | aic3x_write(codec, AIC3X_ASD_INTF_CTRLC, delay); | ||
890 | 939 | ||
891 | return 0; | 940 | return 0; |
892 | } | 941 | } |
@@ -981,14 +1030,41 @@ int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio) | |||
981 | } | 1030 | } |
982 | EXPORT_SYMBOL_GPL(aic3x_get_gpio); | 1031 | EXPORT_SYMBOL_GPL(aic3x_get_gpio); |
983 | 1032 | ||
1033 | void aic3x_set_headset_detection(struct snd_soc_codec *codec, int detect, | ||
1034 | int headset_debounce, int button_debounce) | ||
1035 | { | ||
1036 | u8 val; | ||
1037 | |||
1038 | val = ((detect & AIC3X_HEADSET_DETECT_MASK) | ||
1039 | << AIC3X_HEADSET_DETECT_SHIFT) | | ||
1040 | ((headset_debounce & AIC3X_HEADSET_DEBOUNCE_MASK) | ||
1041 | << AIC3X_HEADSET_DEBOUNCE_SHIFT) | | ||
1042 | ((button_debounce & AIC3X_BUTTON_DEBOUNCE_MASK) | ||
1043 | << AIC3X_BUTTON_DEBOUNCE_SHIFT); | ||
1044 | |||
1045 | if (detect & AIC3X_HEADSET_DETECT_MASK) | ||
1046 | val |= AIC3X_HEADSET_DETECT_ENABLED; | ||
1047 | |||
1048 | aic3x_write(codec, AIC3X_HEADSET_DETECT_CTRL_A, val); | ||
1049 | } | ||
1050 | EXPORT_SYMBOL_GPL(aic3x_set_headset_detection); | ||
1051 | |||
984 | int aic3x_headset_detected(struct snd_soc_codec *codec) | 1052 | int aic3x_headset_detected(struct snd_soc_codec *codec) |
985 | { | 1053 | { |
986 | u8 val; | 1054 | u8 val; |
987 | aic3x_read(codec, AIC3X_RT_IRQ_FLAGS_REG, &val); | 1055 | aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val); |
988 | return (val >> 2) & 1; | 1056 | return (val >> 4) & 1; |
989 | } | 1057 | } |
990 | EXPORT_SYMBOL_GPL(aic3x_headset_detected); | 1058 | EXPORT_SYMBOL_GPL(aic3x_headset_detected); |
991 | 1059 | ||
1060 | int aic3x_button_pressed(struct snd_soc_codec *codec) | ||
1061 | { | ||
1062 | u8 val; | ||
1063 | aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val); | ||
1064 | return (val >> 5) & 1; | ||
1065 | } | ||
1066 | EXPORT_SYMBOL_GPL(aic3x_button_pressed); | ||
1067 | |||
992 | #define AIC3X_RATES SNDRV_PCM_RATE_8000_96000 | 1068 | #define AIC3X_RATES SNDRV_PCM_RATE_8000_96000 |
993 | #define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ | 1069 | #define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ |
994 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) | 1070 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) |
@@ -1009,8 +1085,6 @@ struct snd_soc_dai aic3x_dai = { | |||
1009 | .formats = AIC3X_FORMATS,}, | 1085 | .formats = AIC3X_FORMATS,}, |
1010 | .ops = { | 1086 | .ops = { |
1011 | .hw_params = aic3x_hw_params, | 1087 | .hw_params = aic3x_hw_params, |
1012 | }, | ||
1013 | .dai_ops = { | ||
1014 | .digital_mute = aic3x_mute, | 1088 | .digital_mute = aic3x_mute, |
1015 | .set_sysclk = aic3x_set_dai_sysclk, | 1089 | .set_sysclk = aic3x_set_dai_sysclk, |
1016 | .set_fmt = aic3x_set_dai_fmt, | 1090 | .set_fmt = aic3x_set_dai_fmt, |
@@ -1152,7 +1226,7 @@ static int aic3x_init(struct snd_soc_device *socdev) | |||
1152 | 1226 | ||
1153 | aic3x_add_controls(codec); | 1227 | aic3x_add_controls(codec); |
1154 | aic3x_add_widgets(codec); | 1228 | aic3x_add_widgets(codec); |
1155 | ret = snd_soc_register_card(socdev); | 1229 | ret = snd_soc_init_card(socdev); |
1156 | if (ret < 0) { | 1230 | if (ret < 0) { |
1157 | printk(KERN_ERR "aic3x: failed to register card\n"); | 1231 | printk(KERN_ERR "aic3x: failed to register card\n"); |
1158 | goto card_err; | 1232 | goto card_err; |
@@ -1341,6 +1415,18 @@ struct snd_soc_codec_device soc_codec_dev_aic3x = { | |||
1341 | }; | 1415 | }; |
1342 | EXPORT_SYMBOL_GPL(soc_codec_dev_aic3x); | 1416 | EXPORT_SYMBOL_GPL(soc_codec_dev_aic3x); |
1343 | 1417 | ||
1418 | static int __init aic3x_modinit(void) | ||
1419 | { | ||
1420 | return snd_soc_register_dai(&aic3x_dai); | ||
1421 | } | ||
1422 | module_init(aic3x_modinit); | ||
1423 | |||
1424 | static void __exit aic3x_exit(void) | ||
1425 | { | ||
1426 | snd_soc_unregister_dai(&aic3x_dai); | ||
1427 | } | ||
1428 | module_exit(aic3x_exit); | ||
1429 | |||
1344 | MODULE_DESCRIPTION("ASoC TLV320AIC3X codec driver"); | 1430 | MODULE_DESCRIPTION("ASoC TLV320AIC3X codec driver"); |
1345 | MODULE_AUTHOR("Vladimir Barinov"); | 1431 | MODULE_AUTHOR("Vladimir Barinov"); |
1346 | MODULE_LICENSE("GPL"); | 1432 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/tlv320aic3x.h b/sound/soc/codecs/tlv320aic3x.h index 00a195aa02e4..ac827e578c4d 100644 --- a/sound/soc/codecs/tlv320aic3x.h +++ b/sound/soc/codecs/tlv320aic3x.h | |||
@@ -35,11 +35,15 @@ | |||
35 | #define AIC3X_ASD_INTF_CTRLA 8 | 35 | #define AIC3X_ASD_INTF_CTRLA 8 |
36 | /* Audio serial data interface control register B */ | 36 | /* Audio serial data interface control register B */ |
37 | #define AIC3X_ASD_INTF_CTRLB 9 | 37 | #define AIC3X_ASD_INTF_CTRLB 9 |
38 | /* Audio serial data interface control register C */ | ||
39 | #define AIC3X_ASD_INTF_CTRLC 10 | ||
38 | /* Audio overflow status and PLL R value programming register */ | 40 | /* Audio overflow status and PLL R value programming register */ |
39 | #define AIC3X_OVRF_STATUS_AND_PLLR_REG 11 | 41 | #define AIC3X_OVRF_STATUS_AND_PLLR_REG 11 |
40 | /* Audio codec digital filter control register */ | 42 | /* Audio codec digital filter control register */ |
41 | #define AIC3X_CODEC_DFILT_CTRL 12 | 43 | #define AIC3X_CODEC_DFILT_CTRL 12 |
42 | 44 | /* Headset/button press detection register */ | |
45 | #define AIC3X_HEADSET_DETECT_CTRL_A 13 | ||
46 | #define AIC3X_HEADSET_DETECT_CTRL_B 14 | ||
43 | /* ADC PGA Gain control registers */ | 47 | /* ADC PGA Gain control registers */ |
44 | #define LADC_VOL 15 | 48 | #define LADC_VOL 15 |
45 | #define RADC_VOL 16 | 49 | #define RADC_VOL 16 |
@@ -48,7 +52,9 @@ | |||
48 | #define MIC3LR_2_RADC_CTRL 18 | 52 | #define MIC3LR_2_RADC_CTRL 18 |
49 | /* Line1 Input control registers */ | 53 | /* Line1 Input control registers */ |
50 | #define LINE1L_2_LADC_CTRL 19 | 54 | #define LINE1L_2_LADC_CTRL 19 |
55 | #define LINE1R_2_LADC_CTRL 21 | ||
51 | #define LINE1R_2_RADC_CTRL 22 | 56 | #define LINE1R_2_RADC_CTRL 22 |
57 | #define LINE1L_2_RADC_CTRL 24 | ||
52 | /* Line2 Input control registers */ | 58 | /* Line2 Input control registers */ |
53 | #define LINE2L_2_LADC_CTRL 20 | 59 | #define LINE2L_2_LADC_CTRL 20 |
54 | #define LINE2R_2_RADC_CTRL 23 | 60 | #define LINE2R_2_RADC_CTRL 23 |
@@ -79,6 +85,8 @@ | |||
79 | #define LINE2L_2_HPLOUT_VOL 45 | 85 | #define LINE2L_2_HPLOUT_VOL 45 |
80 | #define LINE2R_2_HPROUT_VOL 62 | 86 | #define LINE2R_2_HPROUT_VOL 62 |
81 | #define PGAL_2_HPLOUT_VOL 46 | 87 | #define PGAL_2_HPLOUT_VOL 46 |
88 | #define PGAL_2_HPROUT_VOL 60 | ||
89 | #define PGAR_2_HPLOUT_VOL 49 | ||
82 | #define PGAR_2_HPROUT_VOL 63 | 90 | #define PGAR_2_HPROUT_VOL 63 |
83 | #define DACL1_2_HPLOUT_VOL 47 | 91 | #define DACL1_2_HPLOUT_VOL 47 |
84 | #define DACR1_2_HPROUT_VOL 64 | 92 | #define DACR1_2_HPROUT_VOL 64 |
@@ -88,6 +96,8 @@ | |||
88 | #define LINE2L_2_HPLCOM_VOL 52 | 96 | #define LINE2L_2_HPLCOM_VOL 52 |
89 | #define LINE2R_2_HPRCOM_VOL 69 | 97 | #define LINE2R_2_HPRCOM_VOL 69 |
90 | #define PGAL_2_HPLCOM_VOL 53 | 98 | #define PGAL_2_HPLCOM_VOL 53 |
99 | #define PGAR_2_HPLCOM_VOL 56 | ||
100 | #define PGAL_2_HPRCOM_VOL 67 | ||
91 | #define PGAR_2_HPRCOM_VOL 70 | 101 | #define PGAR_2_HPRCOM_VOL 70 |
92 | #define DACL1_2_HPLCOM_VOL 54 | 102 | #define DACL1_2_HPLCOM_VOL 54 |
93 | #define DACR1_2_HPRCOM_VOL 71 | 103 | #define DACR1_2_HPRCOM_VOL 71 |
@@ -103,11 +113,17 @@ | |||
103 | #define MONOLOPM_CTRL 79 | 113 | #define MONOLOPM_CTRL 79 |
104 | /* Line Output Plus/Minus control registers */ | 114 | /* Line Output Plus/Minus control registers */ |
105 | #define LINE2L_2_LLOPM_VOL 80 | 115 | #define LINE2L_2_LLOPM_VOL 80 |
116 | #define LINE2L_2_RLOPM_VOL 87 | ||
117 | #define LINE2R_2_LLOPM_VOL 83 | ||
106 | #define LINE2R_2_RLOPM_VOL 90 | 118 | #define LINE2R_2_RLOPM_VOL 90 |
107 | #define PGAL_2_LLOPM_VOL 81 | 119 | #define PGAL_2_LLOPM_VOL 81 |
120 | #define PGAL_2_RLOPM_VOL 88 | ||
121 | #define PGAR_2_LLOPM_VOL 84 | ||
108 | #define PGAR_2_RLOPM_VOL 91 | 122 | #define PGAR_2_RLOPM_VOL 91 |
109 | #define DACL1_2_LLOPM_VOL 82 | 123 | #define DACL1_2_LLOPM_VOL 82 |
124 | #define DACL1_2_RLOPM_VOL 89 | ||
110 | #define DACR1_2_RLOPM_VOL 92 | 125 | #define DACR1_2_RLOPM_VOL 92 |
126 | #define DACR1_2_LLOPM_VOL 85 | ||
111 | #define LLOPM_CTRL 86 | 127 | #define LLOPM_CTRL 86 |
112 | #define RLOPM_CTRL 93 | 128 | #define RLOPM_CTRL 93 |
113 | /* GPIO/IRQ registers */ | 129 | /* GPIO/IRQ registers */ |
@@ -221,7 +237,49 @@ enum { | |||
221 | 237 | ||
222 | void aic3x_set_gpio(struct snd_soc_codec *codec, int gpio, int state); | 238 | void aic3x_set_gpio(struct snd_soc_codec *codec, int gpio, int state); |
223 | int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio); | 239 | int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio); |
240 | |||
241 | /* headset detection / button API */ | ||
242 | |||
243 | /* The AIC3x supports detection of stereo headsets (GND + left + right signal) | ||
244 | * and cellular headsets (GND + speaker output + microphone input). | ||
245 | * It is recommended to enable MIC bias for this function to work properly. | ||
246 | * For more information, please refer to the datasheet. */ | ||
247 | enum { | ||
248 | AIC3X_HEADSET_DETECT_OFF = 0, | ||
249 | AIC3X_HEADSET_DETECT_STEREO = 1, | ||
250 | AIC3X_HEADSET_DETECT_CELLULAR = 2, | ||
251 | AIC3X_HEADSET_DETECT_BOTH = 3 | ||
252 | }; | ||
253 | |||
254 | enum { | ||
255 | AIC3X_HEADSET_DEBOUNCE_16MS = 0, | ||
256 | AIC3X_HEADSET_DEBOUNCE_32MS = 1, | ||
257 | AIC3X_HEADSET_DEBOUNCE_64MS = 2, | ||
258 | AIC3X_HEADSET_DEBOUNCE_128MS = 3, | ||
259 | AIC3X_HEADSET_DEBOUNCE_256MS = 4, | ||
260 | AIC3X_HEADSET_DEBOUNCE_512MS = 5 | ||
261 | }; | ||
262 | |||
263 | enum { | ||
264 | AIC3X_BUTTON_DEBOUNCE_0MS = 0, | ||
265 | AIC3X_BUTTON_DEBOUNCE_8MS = 1, | ||
266 | AIC3X_BUTTON_DEBOUNCE_16MS = 2, | ||
267 | AIC3X_BUTTON_DEBOUNCE_32MS = 3 | ||
268 | }; | ||
269 | |||
270 | #define AIC3X_HEADSET_DETECT_ENABLED 0x80 | ||
271 | #define AIC3X_HEADSET_DETECT_SHIFT 5 | ||
272 | #define AIC3X_HEADSET_DETECT_MASK 3 | ||
273 | #define AIC3X_HEADSET_DEBOUNCE_SHIFT 2 | ||
274 | #define AIC3X_HEADSET_DEBOUNCE_MASK 7 | ||
275 | #define AIC3X_BUTTON_DEBOUNCE_SHIFT 0 | ||
276 | #define AIC3X_BUTTON_DEBOUNCE_MASK 3 | ||
277 | |||
278 | /* see the enums above for valid parameters to this function */ | ||
279 | void aic3x_set_headset_detection(struct snd_soc_codec *codec, int detect, | ||
280 | int headset_debounce, int button_debounce); | ||
224 | int aic3x_headset_detected(struct snd_soc_codec *codec); | 281 | int aic3x_headset_detected(struct snd_soc_codec *codec); |
282 | int aic3x_button_pressed(struct snd_soc_codec *codec); | ||
225 | 283 | ||
226 | struct aic3x_setup_data { | 284 | struct aic3x_setup_data { |
227 | int i2c_bus; | 285 | int i2c_bus; |
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c new file mode 100644 index 000000000000..51848880504a --- /dev/null +++ b/sound/soc/codecs/twl4030.c | |||
@@ -0,0 +1,1317 @@ | |||
1 | /* | ||
2 | * ALSA SoC TWL4030 codec driver | ||
3 | * | ||
4 | * Author: Steve Sakoman, <steve@sakoman.com> | ||
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/init.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/pm.h> | ||
27 | #include <linux/i2c.h> | ||
28 | #include <linux/platform_device.h> | ||
29 | #include <linux/i2c/twl4030.h> | ||
30 | #include <sound/core.h> | ||
31 | #include <sound/pcm.h> | ||
32 | #include <sound/pcm_params.h> | ||
33 | #include <sound/soc.h> | ||
34 | #include <sound/soc-dapm.h> | ||
35 | #include <sound/initval.h> | ||
36 | #include <sound/tlv.h> | ||
37 | |||
38 | #include "twl4030.h" | ||
39 | |||
40 | /* | ||
41 | * twl4030 register cache & default register settings | ||
42 | */ | ||
43 | static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = { | ||
44 | 0x00, /* this register not used */ | ||
45 | 0x93, /* REG_CODEC_MODE (0x1) */ | ||
46 | 0xc3, /* REG_OPTION (0x2) */ | ||
47 | 0x00, /* REG_UNKNOWN (0x3) */ | ||
48 | 0x00, /* REG_MICBIAS_CTL (0x4) */ | ||
49 | 0x20, /* REG_ANAMICL (0x5) */ | ||
50 | 0x00, /* REG_ANAMICR (0x6) */ | ||
51 | 0x00, /* REG_AVADC_CTL (0x7) */ | ||
52 | 0x00, /* REG_ADCMICSEL (0x8) */ | ||
53 | 0x00, /* REG_DIGMIXING (0x9) */ | ||
54 | 0x0c, /* REG_ATXL1PGA (0xA) */ | ||
55 | 0x0c, /* REG_ATXR1PGA (0xB) */ | ||
56 | 0x00, /* REG_AVTXL2PGA (0xC) */ | ||
57 | 0x00, /* REG_AVTXR2PGA (0xD) */ | ||
58 | 0x01, /* REG_AUDIO_IF (0xE) */ | ||
59 | 0x00, /* REG_VOICE_IF (0xF) */ | ||
60 | 0x00, /* REG_ARXR1PGA (0x10) */ | ||
61 | 0x00, /* REG_ARXL1PGA (0x11) */ | ||
62 | 0x6c, /* REG_ARXR2PGA (0x12) */ | ||
63 | 0x6c, /* REG_ARXL2PGA (0x13) */ | ||
64 | 0x00, /* REG_VRXPGA (0x14) */ | ||
65 | 0x00, /* REG_VSTPGA (0x15) */ | ||
66 | 0x00, /* REG_VRX2ARXPGA (0x16) */ | ||
67 | 0x0c, /* REG_AVDAC_CTL (0x17) */ | ||
68 | 0x00, /* REG_ARX2VTXPGA (0x18) */ | ||
69 | 0x00, /* REG_ARXL1_APGA_CTL (0x19) */ | ||
70 | 0x00, /* REG_ARXR1_APGA_CTL (0x1A) */ | ||
71 | 0x4b, /* REG_ARXL2_APGA_CTL (0x1B) */ | ||
72 | 0x4b, /* REG_ARXR2_APGA_CTL (0x1C) */ | ||
73 | 0x00, /* REG_ATX2ARXPGA (0x1D) */ | ||
74 | 0x00, /* REG_BT_IF (0x1E) */ | ||
75 | 0x00, /* REG_BTPGA (0x1F) */ | ||
76 | 0x00, /* REG_BTSTPGA (0x20) */ | ||
77 | 0x00, /* REG_EAR_CTL (0x21) */ | ||
78 | 0x24, /* REG_HS_SEL (0x22) */ | ||
79 | 0x0a, /* REG_HS_GAIN_SET (0x23) */ | ||
80 | 0x00, /* REG_HS_POPN_SET (0x24) */ | ||
81 | 0x00, /* REG_PREDL_CTL (0x25) */ | ||
82 | 0x00, /* REG_PREDR_CTL (0x26) */ | ||
83 | 0x00, /* REG_PRECKL_CTL (0x27) */ | ||
84 | 0x00, /* REG_PRECKR_CTL (0x28) */ | ||
85 | 0x00, /* REG_HFL_CTL (0x29) */ | ||
86 | 0x00, /* REG_HFR_CTL (0x2A) */ | ||
87 | 0x00, /* REG_ALC_CTL (0x2B) */ | ||
88 | 0x00, /* REG_ALC_SET1 (0x2C) */ | ||
89 | 0x00, /* REG_ALC_SET2 (0x2D) */ | ||
90 | 0x00, /* REG_BOOST_CTL (0x2E) */ | ||
91 | 0x00, /* REG_SOFTVOL_CTL (0x2F) */ | ||
92 | 0x00, /* REG_DTMF_FREQSEL (0x30) */ | ||
93 | 0x00, /* REG_DTMF_TONEXT1H (0x31) */ | ||
94 | 0x00, /* REG_DTMF_TONEXT1L (0x32) */ | ||
95 | 0x00, /* REG_DTMF_TONEXT2H (0x33) */ | ||
96 | 0x00, /* REG_DTMF_TONEXT2L (0x34) */ | ||
97 | 0x00, /* REG_DTMF_TONOFF (0x35) */ | ||
98 | 0x00, /* REG_DTMF_WANONOFF (0x36) */ | ||
99 | 0x00, /* REG_I2S_RX_SCRAMBLE_H (0x37) */ | ||
100 | 0x00, /* REG_I2S_RX_SCRAMBLE_M (0x38) */ | ||
101 | 0x00, /* REG_I2S_RX_SCRAMBLE_L (0x39) */ | ||
102 | 0x16, /* REG_APLL_CTL (0x3A) */ | ||
103 | 0x00, /* REG_DTMF_CTL (0x3B) */ | ||
104 | 0x00, /* REG_DTMF_PGA_CTL2 (0x3C) */ | ||
105 | 0x00, /* REG_DTMF_PGA_CTL1 (0x3D) */ | ||
106 | 0x00, /* REG_MISC_SET_1 (0x3E) */ | ||
107 | 0x00, /* REG_PCMBTMUX (0x3F) */ | ||
108 | 0x00, /* not used (0x40) */ | ||
109 | 0x00, /* not used (0x41) */ | ||
110 | 0x00, /* not used (0x42) */ | ||
111 | 0x00, /* REG_RX_PATH_SEL (0x43) */ | ||
112 | 0x00, /* REG_VDL_APGA_CTL (0x44) */ | ||
113 | 0x00, /* REG_VIBRA_CTL (0x45) */ | ||
114 | 0x00, /* REG_VIBRA_SET (0x46) */ | ||
115 | 0x00, /* REG_VIBRA_PWM_SET (0x47) */ | ||
116 | 0x00, /* REG_ANAMIC_GAIN (0x48) */ | ||
117 | 0x00, /* REG_MISC_SET_2 (0x49) */ | ||
118 | }; | ||
119 | |||
120 | /* | ||
121 | * read twl4030 register cache | ||
122 | */ | ||
123 | static inline unsigned int twl4030_read_reg_cache(struct snd_soc_codec *codec, | ||
124 | unsigned int reg) | ||
125 | { | ||
126 | u8 *cache = codec->reg_cache; | ||
127 | |||
128 | return cache[reg]; | ||
129 | } | ||
130 | |||
131 | /* | ||
132 | * write twl4030 register cache | ||
133 | */ | ||
134 | static inline void twl4030_write_reg_cache(struct snd_soc_codec *codec, | ||
135 | u8 reg, u8 value) | ||
136 | { | ||
137 | u8 *cache = codec->reg_cache; | ||
138 | |||
139 | if (reg >= TWL4030_CACHEREGNUM) | ||
140 | return; | ||
141 | cache[reg] = value; | ||
142 | } | ||
143 | |||
144 | /* | ||
145 | * write to the twl4030 register space | ||
146 | */ | ||
147 | static int twl4030_write(struct snd_soc_codec *codec, | ||
148 | unsigned int reg, unsigned int value) | ||
149 | { | ||
150 | twl4030_write_reg_cache(codec, reg, value); | ||
151 | return twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, value, reg); | ||
152 | } | ||
153 | |||
154 | static void twl4030_clear_codecpdz(struct snd_soc_codec *codec) | ||
155 | { | ||
156 | u8 mode; | ||
157 | |||
158 | mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE); | ||
159 | twl4030_write(codec, TWL4030_REG_CODEC_MODE, | ||
160 | mode & ~TWL4030_CODECPDZ); | ||
161 | |||
162 | /* REVISIT: this delay is present in TI sample drivers */ | ||
163 | /* but there seems to be no TRM requirement for it */ | ||
164 | udelay(10); | ||
165 | } | ||
166 | |||
167 | static void twl4030_set_codecpdz(struct snd_soc_codec *codec) | ||
168 | { | ||
169 | u8 mode; | ||
170 | |||
171 | mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE); | ||
172 | twl4030_write(codec, TWL4030_REG_CODEC_MODE, | ||
173 | mode | TWL4030_CODECPDZ); | ||
174 | |||
175 | /* REVISIT: this delay is present in TI sample drivers */ | ||
176 | /* but there seems to be no TRM requirement for it */ | ||
177 | udelay(10); | ||
178 | } | ||
179 | |||
180 | static void twl4030_init_chip(struct snd_soc_codec *codec) | ||
181 | { | ||
182 | int i; | ||
183 | |||
184 | /* clear CODECPDZ prior to setting register defaults */ | ||
185 | twl4030_clear_codecpdz(codec); | ||
186 | |||
187 | /* set all audio section registers to reasonable defaults */ | ||
188 | for (i = TWL4030_REG_OPTION; i <= TWL4030_REG_MISC_SET_2; i++) | ||
189 | twl4030_write(codec, i, twl4030_reg[i]); | ||
190 | |||
191 | } | ||
192 | |||
193 | /* Earpiece */ | ||
194 | static const char *twl4030_earpiece_texts[] = | ||
195 | {"Off", "DACL1", "DACL2", "Invalid", "DACR1"}; | ||
196 | |||
197 | static const struct soc_enum twl4030_earpiece_enum = | ||
198 | SOC_ENUM_SINGLE(TWL4030_REG_EAR_CTL, 1, | ||
199 | ARRAY_SIZE(twl4030_earpiece_texts), | ||
200 | twl4030_earpiece_texts); | ||
201 | |||
202 | static const struct snd_kcontrol_new twl4030_dapm_earpiece_control = | ||
203 | SOC_DAPM_ENUM("Route", twl4030_earpiece_enum); | ||
204 | |||
205 | /* PreDrive Left */ | ||
206 | static const char *twl4030_predrivel_texts[] = | ||
207 | {"Off", "DACL1", "DACL2", "Invalid", "DACR2"}; | ||
208 | |||
209 | static const struct soc_enum twl4030_predrivel_enum = | ||
210 | SOC_ENUM_SINGLE(TWL4030_REG_PREDL_CTL, 1, | ||
211 | ARRAY_SIZE(twl4030_predrivel_texts), | ||
212 | twl4030_predrivel_texts); | ||
213 | |||
214 | static const struct snd_kcontrol_new twl4030_dapm_predrivel_control = | ||
215 | SOC_DAPM_ENUM("Route", twl4030_predrivel_enum); | ||
216 | |||
217 | /* PreDrive Right */ | ||
218 | static const char *twl4030_predriver_texts[] = | ||
219 | {"Off", "DACR1", "DACR2", "Invalid", "DACL2"}; | ||
220 | |||
221 | static const struct soc_enum twl4030_predriver_enum = | ||
222 | SOC_ENUM_SINGLE(TWL4030_REG_PREDR_CTL, 1, | ||
223 | ARRAY_SIZE(twl4030_predriver_texts), | ||
224 | twl4030_predriver_texts); | ||
225 | |||
226 | static const struct snd_kcontrol_new twl4030_dapm_predriver_control = | ||
227 | SOC_DAPM_ENUM("Route", twl4030_predriver_enum); | ||
228 | |||
229 | /* Headset Left */ | ||
230 | static const char *twl4030_hsol_texts[] = | ||
231 | {"Off", "DACL1", "DACL2"}; | ||
232 | |||
233 | static const struct soc_enum twl4030_hsol_enum = | ||
234 | SOC_ENUM_SINGLE(TWL4030_REG_HS_SEL, 1, | ||
235 | ARRAY_SIZE(twl4030_hsol_texts), | ||
236 | twl4030_hsol_texts); | ||
237 | |||
238 | static const struct snd_kcontrol_new twl4030_dapm_hsol_control = | ||
239 | SOC_DAPM_ENUM("Route", twl4030_hsol_enum); | ||
240 | |||
241 | /* Headset Right */ | ||
242 | static const char *twl4030_hsor_texts[] = | ||
243 | {"Off", "DACR1", "DACR2"}; | ||
244 | |||
245 | static const struct soc_enum twl4030_hsor_enum = | ||
246 | SOC_ENUM_SINGLE(TWL4030_REG_HS_SEL, 4, | ||
247 | ARRAY_SIZE(twl4030_hsor_texts), | ||
248 | twl4030_hsor_texts); | ||
249 | |||
250 | static const struct snd_kcontrol_new twl4030_dapm_hsor_control = | ||
251 | SOC_DAPM_ENUM("Route", twl4030_hsor_enum); | ||
252 | |||
253 | /* Carkit Left */ | ||
254 | static const char *twl4030_carkitl_texts[] = | ||
255 | {"Off", "DACL1", "DACL2"}; | ||
256 | |||
257 | static const struct soc_enum twl4030_carkitl_enum = | ||
258 | SOC_ENUM_SINGLE(TWL4030_REG_PRECKL_CTL, 1, | ||
259 | ARRAY_SIZE(twl4030_carkitl_texts), | ||
260 | twl4030_carkitl_texts); | ||
261 | |||
262 | static const struct snd_kcontrol_new twl4030_dapm_carkitl_control = | ||
263 | SOC_DAPM_ENUM("Route", twl4030_carkitl_enum); | ||
264 | |||
265 | /* Carkit Right */ | ||
266 | static const char *twl4030_carkitr_texts[] = | ||
267 | {"Off", "DACR1", "DACR2"}; | ||
268 | |||
269 | static const struct soc_enum twl4030_carkitr_enum = | ||
270 | SOC_ENUM_SINGLE(TWL4030_REG_PRECKR_CTL, 1, | ||
271 | ARRAY_SIZE(twl4030_carkitr_texts), | ||
272 | twl4030_carkitr_texts); | ||
273 | |||
274 | static const struct snd_kcontrol_new twl4030_dapm_carkitr_control = | ||
275 | SOC_DAPM_ENUM("Route", twl4030_carkitr_enum); | ||
276 | |||
277 | /* Handsfree Left */ | ||
278 | static const char *twl4030_handsfreel_texts[] = | ||
279 | {"Voice", "DACL1", "DACL2", "DACR2"}; | ||
280 | |||
281 | static const struct soc_enum twl4030_handsfreel_enum = | ||
282 | SOC_ENUM_SINGLE(TWL4030_REG_HFL_CTL, 0, | ||
283 | ARRAY_SIZE(twl4030_handsfreel_texts), | ||
284 | twl4030_handsfreel_texts); | ||
285 | |||
286 | static const struct snd_kcontrol_new twl4030_dapm_handsfreel_control = | ||
287 | SOC_DAPM_ENUM("Route", twl4030_handsfreel_enum); | ||
288 | |||
289 | /* Handsfree Right */ | ||
290 | static const char *twl4030_handsfreer_texts[] = | ||
291 | {"Voice", "DACR1", "DACR2", "DACL2"}; | ||
292 | |||
293 | static const struct soc_enum twl4030_handsfreer_enum = | ||
294 | SOC_ENUM_SINGLE(TWL4030_REG_HFR_CTL, 0, | ||
295 | ARRAY_SIZE(twl4030_handsfreer_texts), | ||
296 | twl4030_handsfreer_texts); | ||
297 | |||
298 | static const struct snd_kcontrol_new twl4030_dapm_handsfreer_control = | ||
299 | SOC_DAPM_ENUM("Route", twl4030_handsfreer_enum); | ||
300 | |||
301 | static int outmixer_event(struct snd_soc_dapm_widget *w, | ||
302 | struct snd_kcontrol *kcontrol, int event) | ||
303 | { | ||
304 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; | ||
305 | int ret = 0; | ||
306 | int val; | ||
307 | |||
308 | switch (e->reg) { | ||
309 | case TWL4030_REG_PREDL_CTL: | ||
310 | case TWL4030_REG_PREDR_CTL: | ||
311 | case TWL4030_REG_EAR_CTL: | ||
312 | val = w->value >> e->shift_l; | ||
313 | if (val == 3) { | ||
314 | printk(KERN_WARNING | ||
315 | "Invalid MUX setting for register 0x%02x (%d)\n", | ||
316 | e->reg, val); | ||
317 | ret = -1; | ||
318 | } | ||
319 | break; | ||
320 | } | ||
321 | |||
322 | return ret; | ||
323 | } | ||
324 | |||
325 | static int handsfree_event(struct snd_soc_dapm_widget *w, | ||
326 | struct snd_kcontrol *kcontrol, int event) | ||
327 | { | ||
328 | struct soc_enum *e = (struct soc_enum *)w->kcontrols->private_value; | ||
329 | unsigned char hs_ctl; | ||
330 | |||
331 | hs_ctl = twl4030_read_reg_cache(w->codec, e->reg); | ||
332 | |||
333 | if (hs_ctl & TWL4030_HF_CTL_REF_EN) { | ||
334 | hs_ctl |= TWL4030_HF_CTL_RAMP_EN; | ||
335 | twl4030_write(w->codec, e->reg, hs_ctl); | ||
336 | hs_ctl |= TWL4030_HF_CTL_LOOP_EN; | ||
337 | twl4030_write(w->codec, e->reg, hs_ctl); | ||
338 | hs_ctl |= TWL4030_HF_CTL_HB_EN; | ||
339 | twl4030_write(w->codec, e->reg, hs_ctl); | ||
340 | } else { | ||
341 | hs_ctl &= ~(TWL4030_HF_CTL_RAMP_EN | TWL4030_HF_CTL_LOOP_EN | ||
342 | | TWL4030_HF_CTL_HB_EN); | ||
343 | twl4030_write(w->codec, e->reg, hs_ctl); | ||
344 | } | ||
345 | |||
346 | return 0; | ||
347 | } | ||
348 | |||
349 | /* | ||
350 | * Some of the gain controls in TWL (mostly those which are associated with | ||
351 | * the outputs) are implemented in an interesting way: | ||
352 | * 0x0 : Power down (mute) | ||
353 | * 0x1 : 6dB | ||
354 | * 0x2 : 0 dB | ||
355 | * 0x3 : -6 dB | ||
356 | * Inverting not going to help with these. | ||
357 | * Custom volsw and volsw_2r get/put functions to handle these gain bits. | ||
358 | */ | ||
359 | #define SOC_DOUBLE_TLV_TWL4030(xname, xreg, shift_left, shift_right, xmax,\ | ||
360 | xinvert, tlv_array) \ | ||
361 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ | ||
362 | .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ | ||
363 | SNDRV_CTL_ELEM_ACCESS_READWRITE,\ | ||
364 | .tlv.p = (tlv_array), \ | ||
365 | .info = snd_soc_info_volsw, \ | ||
366 | .get = snd_soc_get_volsw_twl4030, \ | ||
367 | .put = snd_soc_put_volsw_twl4030, \ | ||
368 | .private_value = (unsigned long)&(struct soc_mixer_control) \ | ||
369 | {.reg = xreg, .shift = shift_left, .rshift = shift_right,\ | ||
370 | .max = xmax, .invert = xinvert} } | ||
371 | #define SOC_DOUBLE_R_TLV_TWL4030(xname, reg_left, reg_right, xshift, xmax,\ | ||
372 | xinvert, tlv_array) \ | ||
373 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ | ||
374 | .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ | ||
375 | SNDRV_CTL_ELEM_ACCESS_READWRITE,\ | ||
376 | .tlv.p = (tlv_array), \ | ||
377 | .info = snd_soc_info_volsw_2r, \ | ||
378 | .get = snd_soc_get_volsw_r2_twl4030,\ | ||
379 | .put = snd_soc_put_volsw_r2_twl4030, \ | ||
380 | .private_value = (unsigned long)&(struct soc_mixer_control) \ | ||
381 | {.reg = reg_left, .rreg = reg_right, .shift = xshift, \ | ||
382 | .rshift = xshift, .max = xmax, .invert = xinvert} } | ||
383 | #define SOC_SINGLE_TLV_TWL4030(xname, xreg, xshift, xmax, xinvert, tlv_array) \ | ||
384 | SOC_DOUBLE_TLV_TWL4030(xname, xreg, xshift, xshift, xmax, \ | ||
385 | xinvert, tlv_array) | ||
386 | |||
387 | static int snd_soc_get_volsw_twl4030(struct snd_kcontrol *kcontrol, | ||
388 | struct snd_ctl_elem_value *ucontrol) | ||
389 | { | ||
390 | struct soc_mixer_control *mc = | ||
391 | (struct soc_mixer_control *)kcontrol->private_value; | ||
392 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
393 | unsigned int reg = mc->reg; | ||
394 | unsigned int shift = mc->shift; | ||
395 | unsigned int rshift = mc->rshift; | ||
396 | int max = mc->max; | ||
397 | int mask = (1 << fls(max)) - 1; | ||
398 | |||
399 | ucontrol->value.integer.value[0] = | ||
400 | (snd_soc_read(codec, reg) >> shift) & mask; | ||
401 | if (ucontrol->value.integer.value[0]) | ||
402 | ucontrol->value.integer.value[0] = | ||
403 | max + 1 - ucontrol->value.integer.value[0]; | ||
404 | |||
405 | if (shift != rshift) { | ||
406 | ucontrol->value.integer.value[1] = | ||
407 | (snd_soc_read(codec, reg) >> rshift) & mask; | ||
408 | if (ucontrol->value.integer.value[1]) | ||
409 | ucontrol->value.integer.value[1] = | ||
410 | max + 1 - ucontrol->value.integer.value[1]; | ||
411 | } | ||
412 | |||
413 | return 0; | ||
414 | } | ||
415 | |||
416 | static int snd_soc_put_volsw_twl4030(struct snd_kcontrol *kcontrol, | ||
417 | struct snd_ctl_elem_value *ucontrol) | ||
418 | { | ||
419 | struct soc_mixer_control *mc = | ||
420 | (struct soc_mixer_control *)kcontrol->private_value; | ||
421 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
422 | unsigned int reg = mc->reg; | ||
423 | unsigned int shift = mc->shift; | ||
424 | unsigned int rshift = mc->rshift; | ||
425 | int max = mc->max; | ||
426 | int mask = (1 << fls(max)) - 1; | ||
427 | unsigned short val, val2, val_mask; | ||
428 | |||
429 | val = (ucontrol->value.integer.value[0] & mask); | ||
430 | |||
431 | val_mask = mask << shift; | ||
432 | if (val) | ||
433 | val = max + 1 - val; | ||
434 | val = val << shift; | ||
435 | if (shift != rshift) { | ||
436 | val2 = (ucontrol->value.integer.value[1] & mask); | ||
437 | val_mask |= mask << rshift; | ||
438 | if (val2) | ||
439 | val2 = max + 1 - val2; | ||
440 | val |= val2 << rshift; | ||
441 | } | ||
442 | return snd_soc_update_bits(codec, reg, val_mask, val); | ||
443 | } | ||
444 | |||
445 | static int snd_soc_get_volsw_r2_twl4030(struct snd_kcontrol *kcontrol, | ||
446 | struct snd_ctl_elem_value *ucontrol) | ||
447 | { | ||
448 | struct soc_mixer_control *mc = | ||
449 | (struct soc_mixer_control *)kcontrol->private_value; | ||
450 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
451 | unsigned int reg = mc->reg; | ||
452 | unsigned int reg2 = mc->rreg; | ||
453 | unsigned int shift = mc->shift; | ||
454 | int max = mc->max; | ||
455 | int mask = (1<<fls(max))-1; | ||
456 | |||
457 | ucontrol->value.integer.value[0] = | ||
458 | (snd_soc_read(codec, reg) >> shift) & mask; | ||
459 | ucontrol->value.integer.value[1] = | ||
460 | (snd_soc_read(codec, reg2) >> shift) & mask; | ||
461 | |||
462 | if (ucontrol->value.integer.value[0]) | ||
463 | ucontrol->value.integer.value[0] = | ||
464 | max + 1 - ucontrol->value.integer.value[0]; | ||
465 | if (ucontrol->value.integer.value[1]) | ||
466 | ucontrol->value.integer.value[1] = | ||
467 | max + 1 - ucontrol->value.integer.value[1]; | ||
468 | |||
469 | return 0; | ||
470 | } | ||
471 | |||
472 | static int snd_soc_put_volsw_r2_twl4030(struct snd_kcontrol *kcontrol, | ||
473 | struct snd_ctl_elem_value *ucontrol) | ||
474 | { | ||
475 | struct soc_mixer_control *mc = | ||
476 | (struct soc_mixer_control *)kcontrol->private_value; | ||
477 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
478 | unsigned int reg = mc->reg; | ||
479 | unsigned int reg2 = mc->rreg; | ||
480 | unsigned int shift = mc->shift; | ||
481 | int max = mc->max; | ||
482 | int mask = (1 << fls(max)) - 1; | ||
483 | int err; | ||
484 | unsigned short val, val2, val_mask; | ||
485 | |||
486 | val_mask = mask << shift; | ||
487 | val = (ucontrol->value.integer.value[0] & mask); | ||
488 | val2 = (ucontrol->value.integer.value[1] & mask); | ||
489 | |||
490 | if (val) | ||
491 | val = max + 1 - val; | ||
492 | if (val2) | ||
493 | val2 = max + 1 - val2; | ||
494 | |||
495 | val = val << shift; | ||
496 | val2 = val2 << shift; | ||
497 | |||
498 | err = snd_soc_update_bits(codec, reg, val_mask, val); | ||
499 | if (err < 0) | ||
500 | return err; | ||
501 | |||
502 | err = snd_soc_update_bits(codec, reg2, val_mask, val2); | ||
503 | return err; | ||
504 | } | ||
505 | |||
506 | static int twl4030_get_left_input(struct snd_kcontrol *kcontrol, | ||
507 | struct snd_ctl_elem_value *ucontrol) | ||
508 | { | ||
509 | struct snd_soc_codec *codec = kcontrol->private_data; | ||
510 | u8 reg = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICL); | ||
511 | int result = 0; | ||
512 | |||
513 | /* one bit must be set a time */ | ||
514 | reg &= TWL4030_CKMIC_EN | TWL4030_AUXL_EN | TWL4030_HSMIC_EN | ||
515 | | TWL4030_MAINMIC_EN; | ||
516 | if (reg != 0) { | ||
517 | result++; | ||
518 | while ((reg & 1) == 0) { | ||
519 | result++; | ||
520 | reg >>= 1; | ||
521 | } | ||
522 | } | ||
523 | |||
524 | ucontrol->value.integer.value[0] = result; | ||
525 | return 0; | ||
526 | } | ||
527 | |||
528 | static int twl4030_put_left_input(struct snd_kcontrol *kcontrol, | ||
529 | struct snd_ctl_elem_value *ucontrol) | ||
530 | { | ||
531 | struct snd_soc_codec *codec = kcontrol->private_data; | ||
532 | int value = ucontrol->value.integer.value[0]; | ||
533 | u8 anamicl, micbias, avadc_ctl; | ||
534 | |||
535 | anamicl = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICL); | ||
536 | anamicl &= ~(TWL4030_CKMIC_EN | TWL4030_AUXL_EN | TWL4030_HSMIC_EN | ||
537 | | TWL4030_MAINMIC_EN); | ||
538 | micbias = twl4030_read_reg_cache(codec, TWL4030_REG_MICBIAS_CTL); | ||
539 | micbias &= ~(TWL4030_HSMICBIAS_EN | TWL4030_MICBIAS1_EN); | ||
540 | avadc_ctl = twl4030_read_reg_cache(codec, TWL4030_REG_AVADC_CTL); | ||
541 | |||
542 | switch (value) { | ||
543 | case 1: | ||
544 | anamicl |= TWL4030_MAINMIC_EN; | ||
545 | micbias |= TWL4030_MICBIAS1_EN; | ||
546 | break; | ||
547 | case 2: | ||
548 | anamicl |= TWL4030_HSMIC_EN; | ||
549 | micbias |= TWL4030_HSMICBIAS_EN; | ||
550 | break; | ||
551 | case 3: | ||
552 | anamicl |= TWL4030_AUXL_EN; | ||
553 | break; | ||
554 | case 4: | ||
555 | anamicl |= TWL4030_CKMIC_EN; | ||
556 | break; | ||
557 | default: | ||
558 | break; | ||
559 | } | ||
560 | |||
561 | /* If some input is selected, enable amp and ADC */ | ||
562 | if (value != 0) { | ||
563 | anamicl |= TWL4030_MICAMPL_EN; | ||
564 | avadc_ctl |= TWL4030_ADCL_EN; | ||
565 | } else { | ||
566 | anamicl &= ~TWL4030_MICAMPL_EN; | ||
567 | avadc_ctl &= ~TWL4030_ADCL_EN; | ||
568 | } | ||
569 | |||
570 | twl4030_write(codec, TWL4030_REG_ANAMICL, anamicl); | ||
571 | twl4030_write(codec, TWL4030_REG_MICBIAS_CTL, micbias); | ||
572 | twl4030_write(codec, TWL4030_REG_AVADC_CTL, avadc_ctl); | ||
573 | |||
574 | return 1; | ||
575 | } | ||
576 | |||
577 | static int twl4030_get_right_input(struct snd_kcontrol *kcontrol, | ||
578 | struct snd_ctl_elem_value *ucontrol) | ||
579 | { | ||
580 | struct snd_soc_codec *codec = kcontrol->private_data; | ||
581 | u8 reg = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICR); | ||
582 | int value = 0; | ||
583 | |||
584 | reg &= TWL4030_SUBMIC_EN|TWL4030_AUXR_EN; | ||
585 | switch (reg) { | ||
586 | case TWL4030_SUBMIC_EN: | ||
587 | value = 1; | ||
588 | break; | ||
589 | case TWL4030_AUXR_EN: | ||
590 | value = 2; | ||
591 | break; | ||
592 | default: | ||
593 | break; | ||
594 | } | ||
595 | |||
596 | ucontrol->value.integer.value[0] = value; | ||
597 | return 0; | ||
598 | } | ||
599 | |||
600 | static int twl4030_put_right_input(struct snd_kcontrol *kcontrol, | ||
601 | struct snd_ctl_elem_value *ucontrol) | ||
602 | { | ||
603 | struct snd_soc_codec *codec = kcontrol->private_data; | ||
604 | int value = ucontrol->value.integer.value[0]; | ||
605 | u8 anamicr, micbias, avadc_ctl; | ||
606 | |||
607 | anamicr = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICR); | ||
608 | anamicr &= ~(TWL4030_SUBMIC_EN|TWL4030_AUXR_EN); | ||
609 | micbias = twl4030_read_reg_cache(codec, TWL4030_REG_MICBIAS_CTL); | ||
610 | micbias &= ~TWL4030_MICBIAS2_EN; | ||
611 | avadc_ctl = twl4030_read_reg_cache(codec, TWL4030_REG_AVADC_CTL); | ||
612 | |||
613 | switch (value) { | ||
614 | case 1: | ||
615 | anamicr |= TWL4030_SUBMIC_EN; | ||
616 | micbias |= TWL4030_MICBIAS2_EN; | ||
617 | break; | ||
618 | case 2: | ||
619 | anamicr |= TWL4030_AUXR_EN; | ||
620 | break; | ||
621 | default: | ||
622 | break; | ||
623 | } | ||
624 | |||
625 | if (value != 0) { | ||
626 | anamicr |= TWL4030_MICAMPR_EN; | ||
627 | avadc_ctl |= TWL4030_ADCR_EN; | ||
628 | } else { | ||
629 | anamicr &= ~TWL4030_MICAMPR_EN; | ||
630 | avadc_ctl &= ~TWL4030_ADCR_EN; | ||
631 | } | ||
632 | |||
633 | twl4030_write(codec, TWL4030_REG_ANAMICR, anamicr); | ||
634 | twl4030_write(codec, TWL4030_REG_MICBIAS_CTL, micbias); | ||
635 | twl4030_write(codec, TWL4030_REG_AVADC_CTL, avadc_ctl); | ||
636 | |||
637 | return 1; | ||
638 | } | ||
639 | |||
640 | static const char *twl4030_left_in_sel[] = { | ||
641 | "None", | ||
642 | "Main Mic", | ||
643 | "Headset Mic", | ||
644 | "Line In", | ||
645 | "Carkit Mic", | ||
646 | }; | ||
647 | |||
648 | static const char *twl4030_right_in_sel[] = { | ||
649 | "None", | ||
650 | "Sub Mic", | ||
651 | "Line In", | ||
652 | }; | ||
653 | |||
654 | static const struct soc_enum twl4030_left_input_mux = | ||
655 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(twl4030_left_in_sel), | ||
656 | twl4030_left_in_sel); | ||
657 | |||
658 | static const struct soc_enum twl4030_right_input_mux = | ||
659 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(twl4030_right_in_sel), | ||
660 | twl4030_right_in_sel); | ||
661 | |||
662 | /* | ||
663 | * FGAIN volume control: | ||
664 | * from -62 to 0 dB in 1 dB steps (mute instead of -63 dB) | ||
665 | */ | ||
666 | static DECLARE_TLV_DB_SCALE(digital_fine_tlv, -6300, 100, 1); | ||
667 | |||
668 | /* | ||
669 | * CGAIN volume control: | ||
670 | * 0 dB to 12 dB in 6 dB steps | ||
671 | * value 2 and 3 means 12 dB | ||
672 | */ | ||
673 | static DECLARE_TLV_DB_SCALE(digital_coarse_tlv, 0, 600, 0); | ||
674 | |||
675 | /* | ||
676 | * Analog playback gain | ||
677 | * -24 dB to 12 dB in 2 dB steps | ||
678 | */ | ||
679 | static DECLARE_TLV_DB_SCALE(analog_tlv, -2400, 200, 0); | ||
680 | |||
681 | /* | ||
682 | * Gain controls tied to outputs | ||
683 | * -6 dB to 6 dB in 6 dB steps (mute instead of -12) | ||
684 | */ | ||
685 | static DECLARE_TLV_DB_SCALE(output_tvl, -1200, 600, 1); | ||
686 | |||
687 | /* | ||
688 | * Capture gain after the ADCs | ||
689 | * from 0 dB to 31 dB in 1 dB steps | ||
690 | */ | ||
691 | static DECLARE_TLV_DB_SCALE(digital_capture_tlv, 0, 100, 0); | ||
692 | |||
693 | /* | ||
694 | * Gain control for input amplifiers | ||
695 | * 0 dB to 30 dB in 6 dB steps | ||
696 | */ | ||
697 | static DECLARE_TLV_DB_SCALE(input_gain_tlv, 0, 600, 0); | ||
698 | |||
699 | static const struct snd_kcontrol_new twl4030_snd_controls[] = { | ||
700 | /* Common playback gain controls */ | ||
701 | SOC_DOUBLE_R_TLV("DAC1 Digital Fine Playback Volume", | ||
702 | TWL4030_REG_ARXL1PGA, TWL4030_REG_ARXR1PGA, | ||
703 | 0, 0x3f, 0, digital_fine_tlv), | ||
704 | SOC_DOUBLE_R_TLV("DAC2 Digital Fine Playback Volume", | ||
705 | TWL4030_REG_ARXL2PGA, TWL4030_REG_ARXR2PGA, | ||
706 | 0, 0x3f, 0, digital_fine_tlv), | ||
707 | |||
708 | SOC_DOUBLE_R_TLV("DAC1 Digital Coarse Playback Volume", | ||
709 | TWL4030_REG_ARXL1PGA, TWL4030_REG_ARXR1PGA, | ||
710 | 6, 0x2, 0, digital_coarse_tlv), | ||
711 | SOC_DOUBLE_R_TLV("DAC2 Digital Coarse Playback Volume", | ||
712 | TWL4030_REG_ARXL2PGA, TWL4030_REG_ARXR2PGA, | ||
713 | 6, 0x2, 0, digital_coarse_tlv), | ||
714 | |||
715 | SOC_DOUBLE_R_TLV("DAC1 Analog Playback Volume", | ||
716 | TWL4030_REG_ARXL1_APGA_CTL, TWL4030_REG_ARXR1_APGA_CTL, | ||
717 | 3, 0x12, 1, analog_tlv), | ||
718 | SOC_DOUBLE_R_TLV("DAC2 Analog Playback Volume", | ||
719 | TWL4030_REG_ARXL2_APGA_CTL, TWL4030_REG_ARXR2_APGA_CTL, | ||
720 | 3, 0x12, 1, analog_tlv), | ||
721 | SOC_DOUBLE_R("DAC1 Analog Playback Switch", | ||
722 | TWL4030_REG_ARXL1_APGA_CTL, TWL4030_REG_ARXR1_APGA_CTL, | ||
723 | 1, 1, 0), | ||
724 | SOC_DOUBLE_R("DAC2 Analog Playback Switch", | ||
725 | TWL4030_REG_ARXL2_APGA_CTL, TWL4030_REG_ARXR2_APGA_CTL, | ||
726 | 1, 1, 0), | ||
727 | |||
728 | /* Separate output gain controls */ | ||
729 | SOC_DOUBLE_R_TLV_TWL4030("PreDriv Playback Volume", | ||
730 | TWL4030_REG_PREDL_CTL, TWL4030_REG_PREDR_CTL, | ||
731 | 4, 3, 0, output_tvl), | ||
732 | |||
733 | SOC_DOUBLE_TLV_TWL4030("Headset Playback Volume", | ||
734 | TWL4030_REG_HS_GAIN_SET, 0, 2, 3, 0, output_tvl), | ||
735 | |||
736 | SOC_DOUBLE_R_TLV_TWL4030("Carkit Playback Volume", | ||
737 | TWL4030_REG_PRECKL_CTL, TWL4030_REG_PRECKR_CTL, | ||
738 | 4, 3, 0, output_tvl), | ||
739 | |||
740 | SOC_SINGLE_TLV_TWL4030("Earpiece Playback Volume", | ||
741 | TWL4030_REG_EAR_CTL, 4, 3, 0, output_tvl), | ||
742 | |||
743 | /* Common capture gain controls */ | ||
744 | SOC_DOUBLE_R_TLV("Capture Volume", | ||
745 | TWL4030_REG_ATXL1PGA, TWL4030_REG_ATXR1PGA, | ||
746 | 0, 0x1f, 0, digital_capture_tlv), | ||
747 | |||
748 | SOC_DOUBLE_TLV("Input Boost Volume", TWL4030_REG_ANAMIC_GAIN, | ||
749 | 0, 3, 5, 0, input_gain_tlv), | ||
750 | |||
751 | /* Input source controls */ | ||
752 | SOC_ENUM_EXT("Left Input Source", twl4030_left_input_mux, | ||
753 | twl4030_get_left_input, twl4030_put_left_input), | ||
754 | SOC_ENUM_EXT("Right Input Source", twl4030_right_input_mux, | ||
755 | twl4030_get_right_input, twl4030_put_right_input), | ||
756 | }; | ||
757 | |||
758 | /* add non dapm controls */ | ||
759 | static int twl4030_add_controls(struct snd_soc_codec *codec) | ||
760 | { | ||
761 | int err, i; | ||
762 | |||
763 | for (i = 0; i < ARRAY_SIZE(twl4030_snd_controls); i++) { | ||
764 | err = snd_ctl_add(codec->card, | ||
765 | snd_soc_cnew(&twl4030_snd_controls[i], | ||
766 | codec, NULL)); | ||
767 | if (err < 0) | ||
768 | return err; | ||
769 | } | ||
770 | |||
771 | return 0; | ||
772 | } | ||
773 | |||
774 | static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | ||
775 | SND_SOC_DAPM_INPUT("INL"), | ||
776 | SND_SOC_DAPM_INPUT("INR"), | ||
777 | |||
778 | SND_SOC_DAPM_OUTPUT("OUTL"), | ||
779 | SND_SOC_DAPM_OUTPUT("OUTR"), | ||
780 | SND_SOC_DAPM_OUTPUT("EARPIECE"), | ||
781 | SND_SOC_DAPM_OUTPUT("PREDRIVEL"), | ||
782 | SND_SOC_DAPM_OUTPUT("PREDRIVER"), | ||
783 | SND_SOC_DAPM_OUTPUT("HSOL"), | ||
784 | SND_SOC_DAPM_OUTPUT("HSOR"), | ||
785 | SND_SOC_DAPM_OUTPUT("CARKITL"), | ||
786 | SND_SOC_DAPM_OUTPUT("CARKITR"), | ||
787 | SND_SOC_DAPM_OUTPUT("HFL"), | ||
788 | SND_SOC_DAPM_OUTPUT("HFR"), | ||
789 | |||
790 | /* DACs */ | ||
791 | SND_SOC_DAPM_DAC("DAC Right1", "Right Front Playback", | ||
792 | TWL4030_REG_AVDAC_CTL, 0, 0), | ||
793 | SND_SOC_DAPM_DAC("DAC Left1", "Left Front Playback", | ||
794 | TWL4030_REG_AVDAC_CTL, 1, 0), | ||
795 | SND_SOC_DAPM_DAC("DAC Right2", "Right Rear Playback", | ||
796 | TWL4030_REG_AVDAC_CTL, 2, 0), | ||
797 | SND_SOC_DAPM_DAC("DAC Left2", "Left Rear Playback", | ||
798 | TWL4030_REG_AVDAC_CTL, 3, 0), | ||
799 | |||
800 | /* Analog PGAs */ | ||
801 | SND_SOC_DAPM_PGA("ARXR1_APGA", TWL4030_REG_ARXR1_APGA_CTL, | ||
802 | 0, 0, NULL, 0), | ||
803 | SND_SOC_DAPM_PGA("ARXL1_APGA", TWL4030_REG_ARXL1_APGA_CTL, | ||
804 | 0, 0, NULL, 0), | ||
805 | SND_SOC_DAPM_PGA("ARXR2_APGA", TWL4030_REG_ARXR2_APGA_CTL, | ||
806 | 0, 0, NULL, 0), | ||
807 | SND_SOC_DAPM_PGA("ARXL2_APGA", TWL4030_REG_ARXL2_APGA_CTL, | ||
808 | 0, 0, NULL, 0), | ||
809 | |||
810 | /* Output MUX controls */ | ||
811 | /* Earpiece */ | ||
812 | SND_SOC_DAPM_MUX_E("Earpiece Mux", SND_SOC_NOPM, 0, 0, | ||
813 | &twl4030_dapm_earpiece_control, outmixer_event, | ||
814 | SND_SOC_DAPM_PRE_REG), | ||
815 | /* PreDrivL/R */ | ||
816 | SND_SOC_DAPM_MUX_E("PredriveL Mux", SND_SOC_NOPM, 0, 0, | ||
817 | &twl4030_dapm_predrivel_control, outmixer_event, | ||
818 | SND_SOC_DAPM_PRE_REG), | ||
819 | SND_SOC_DAPM_MUX_E("PredriveR Mux", SND_SOC_NOPM, 0, 0, | ||
820 | &twl4030_dapm_predriver_control, outmixer_event, | ||
821 | SND_SOC_DAPM_PRE_REG), | ||
822 | /* HeadsetL/R */ | ||
823 | SND_SOC_DAPM_MUX("HeadsetL Mux", SND_SOC_NOPM, 0, 0, | ||
824 | &twl4030_dapm_hsol_control), | ||
825 | SND_SOC_DAPM_MUX("HeadsetR Mux", SND_SOC_NOPM, 0, 0, | ||
826 | &twl4030_dapm_hsor_control), | ||
827 | /* CarkitL/R */ | ||
828 | SND_SOC_DAPM_MUX("CarkitL Mux", SND_SOC_NOPM, 0, 0, | ||
829 | &twl4030_dapm_carkitl_control), | ||
830 | SND_SOC_DAPM_MUX("CarkitR Mux", SND_SOC_NOPM, 0, 0, | ||
831 | &twl4030_dapm_carkitr_control), | ||
832 | /* HandsfreeL/R */ | ||
833 | SND_SOC_DAPM_MUX_E("HandsfreeL Mux", TWL4030_REG_HFL_CTL, 5, 0, | ||
834 | &twl4030_dapm_handsfreel_control, handsfree_event, | ||
835 | SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD), | ||
836 | SND_SOC_DAPM_MUX_E("HandsfreeR Mux", TWL4030_REG_HFR_CTL, 5, 0, | ||
837 | &twl4030_dapm_handsfreer_control, handsfree_event, | ||
838 | SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD), | ||
839 | |||
840 | SND_SOC_DAPM_ADC("ADCL", "Left Capture", SND_SOC_NOPM, 0, 0), | ||
841 | SND_SOC_DAPM_ADC("ADCR", "Right Capture", SND_SOC_NOPM, 0, 0), | ||
842 | }; | ||
843 | |||
844 | static const struct snd_soc_dapm_route intercon[] = { | ||
845 | {"ARXL1_APGA", NULL, "DAC Left1"}, | ||
846 | {"ARXR1_APGA", NULL, "DAC Right1"}, | ||
847 | {"ARXL2_APGA", NULL, "DAC Left2"}, | ||
848 | {"ARXR2_APGA", NULL, "DAC Right2"}, | ||
849 | |||
850 | /* Internal playback routings */ | ||
851 | /* Earpiece */ | ||
852 | {"Earpiece Mux", "DACL1", "ARXL1_APGA"}, | ||
853 | {"Earpiece Mux", "DACL2", "ARXL2_APGA"}, | ||
854 | {"Earpiece Mux", "DACR1", "ARXR1_APGA"}, | ||
855 | /* PreDrivL */ | ||
856 | {"PredriveL Mux", "DACL1", "ARXL1_APGA"}, | ||
857 | {"PredriveL Mux", "DACL2", "ARXL2_APGA"}, | ||
858 | {"PredriveL Mux", "DACR2", "ARXR2_APGA"}, | ||
859 | /* PreDrivR */ | ||
860 | {"PredriveR Mux", "DACR1", "ARXR1_APGA"}, | ||
861 | {"PredriveR Mux", "DACR2", "ARXR2_APGA"}, | ||
862 | {"PredriveR Mux", "DACL2", "ARXL2_APGA"}, | ||
863 | /* HeadsetL */ | ||
864 | {"HeadsetL Mux", "DACL1", "ARXL1_APGA"}, | ||
865 | {"HeadsetL Mux", "DACL2", "ARXL2_APGA"}, | ||
866 | /* HeadsetR */ | ||
867 | {"HeadsetR Mux", "DACR1", "ARXR1_APGA"}, | ||
868 | {"HeadsetR Mux", "DACR2", "ARXR2_APGA"}, | ||
869 | /* CarkitL */ | ||
870 | {"CarkitL Mux", "DACL1", "ARXL1_APGA"}, | ||
871 | {"CarkitL Mux", "DACL2", "ARXL2_APGA"}, | ||
872 | /* CarkitR */ | ||
873 | {"CarkitR Mux", "DACR1", "ARXR1_APGA"}, | ||
874 | {"CarkitR Mux", "DACR2", "ARXR2_APGA"}, | ||
875 | /* HandsfreeL */ | ||
876 | {"HandsfreeL Mux", "DACL1", "ARXL1_APGA"}, | ||
877 | {"HandsfreeL Mux", "DACL2", "ARXL2_APGA"}, | ||
878 | {"HandsfreeL Mux", "DACR2", "ARXR2_APGA"}, | ||
879 | /* HandsfreeR */ | ||
880 | {"HandsfreeR Mux", "DACR1", "ARXR1_APGA"}, | ||
881 | {"HandsfreeR Mux", "DACR2", "ARXR2_APGA"}, | ||
882 | {"HandsfreeR Mux", "DACL2", "ARXL2_APGA"}, | ||
883 | |||
884 | /* outputs */ | ||
885 | {"OUTL", NULL, "ARXL2_APGA"}, | ||
886 | {"OUTR", NULL, "ARXR2_APGA"}, | ||
887 | {"EARPIECE", NULL, "Earpiece Mux"}, | ||
888 | {"PREDRIVEL", NULL, "PredriveL Mux"}, | ||
889 | {"PREDRIVER", NULL, "PredriveR Mux"}, | ||
890 | {"HSOL", NULL, "HeadsetL Mux"}, | ||
891 | {"HSOR", NULL, "HeadsetR Mux"}, | ||
892 | {"CARKITL", NULL, "CarkitL Mux"}, | ||
893 | {"CARKITR", NULL, "CarkitR Mux"}, | ||
894 | {"HFL", NULL, "HandsfreeL Mux"}, | ||
895 | {"HFR", NULL, "HandsfreeR Mux"}, | ||
896 | |||
897 | /* inputs */ | ||
898 | {"ADCL", NULL, "INL"}, | ||
899 | {"ADCR", NULL, "INR"}, | ||
900 | }; | ||
901 | |||
902 | static int twl4030_add_widgets(struct snd_soc_codec *codec) | ||
903 | { | ||
904 | snd_soc_dapm_new_controls(codec, twl4030_dapm_widgets, | ||
905 | ARRAY_SIZE(twl4030_dapm_widgets)); | ||
906 | |||
907 | snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); | ||
908 | |||
909 | snd_soc_dapm_new_widgets(codec); | ||
910 | return 0; | ||
911 | } | ||
912 | |||
913 | static void twl4030_power_up(struct snd_soc_codec *codec) | ||
914 | { | ||
915 | u8 anamicl, regmisc1, byte, popn; | ||
916 | int i = 0; | ||
917 | |||
918 | /* set CODECPDZ to turn on codec */ | ||
919 | twl4030_set_codecpdz(codec); | ||
920 | |||
921 | /* initiate offset cancellation */ | ||
922 | anamicl = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICL); | ||
923 | twl4030_write(codec, TWL4030_REG_ANAMICL, | ||
924 | anamicl | TWL4030_CNCL_OFFSET_START); | ||
925 | |||
926 | /* wait for offset cancellation to complete */ | ||
927 | do { | ||
928 | /* this takes a little while, so don't slam i2c */ | ||
929 | udelay(2000); | ||
930 | twl4030_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte, | ||
931 | TWL4030_REG_ANAMICL); | ||
932 | } while ((i++ < 100) && | ||
933 | ((byte & TWL4030_CNCL_OFFSET_START) == | ||
934 | TWL4030_CNCL_OFFSET_START)); | ||
935 | |||
936 | /* anti-pop when changing analog gain */ | ||
937 | regmisc1 = twl4030_read_reg_cache(codec, TWL4030_REG_MISC_SET_1); | ||
938 | twl4030_write(codec, TWL4030_REG_MISC_SET_1, | ||
939 | regmisc1 | TWL4030_SMOOTH_ANAVOL_EN); | ||
940 | |||
941 | /* toggle CODECPDZ as per TRM */ | ||
942 | twl4030_clear_codecpdz(codec); | ||
943 | twl4030_set_codecpdz(codec); | ||
944 | |||
945 | /* program anti-pop with bias ramp delay */ | ||
946 | popn = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET); | ||
947 | popn &= TWL4030_RAMP_DELAY; | ||
948 | popn |= TWL4030_RAMP_DELAY_645MS; | ||
949 | twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn); | ||
950 | popn |= TWL4030_VMID_EN; | ||
951 | twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn); | ||
952 | |||
953 | /* enable anti-pop ramp */ | ||
954 | popn |= TWL4030_RAMP_EN; | ||
955 | twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn); | ||
956 | } | ||
957 | |||
958 | static void twl4030_power_down(struct snd_soc_codec *codec) | ||
959 | { | ||
960 | u8 popn; | ||
961 | |||
962 | /* disable anti-pop ramp */ | ||
963 | popn = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET); | ||
964 | popn &= ~TWL4030_RAMP_EN; | ||
965 | twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn); | ||
966 | |||
967 | /* disable bias out */ | ||
968 | popn &= ~TWL4030_VMID_EN; | ||
969 | twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn); | ||
970 | |||
971 | /* power down */ | ||
972 | twl4030_clear_codecpdz(codec); | ||
973 | } | ||
974 | |||
975 | static int twl4030_set_bias_level(struct snd_soc_codec *codec, | ||
976 | enum snd_soc_bias_level level) | ||
977 | { | ||
978 | switch (level) { | ||
979 | case SND_SOC_BIAS_ON: | ||
980 | twl4030_power_up(codec); | ||
981 | break; | ||
982 | case SND_SOC_BIAS_PREPARE: | ||
983 | /* TODO: develop a twl4030_prepare function */ | ||
984 | break; | ||
985 | case SND_SOC_BIAS_STANDBY: | ||
986 | /* TODO: develop a twl4030_standby function */ | ||
987 | twl4030_power_down(codec); | ||
988 | break; | ||
989 | case SND_SOC_BIAS_OFF: | ||
990 | twl4030_power_down(codec); | ||
991 | break; | ||
992 | } | ||
993 | codec->bias_level = level; | ||
994 | |||
995 | return 0; | ||
996 | } | ||
997 | |||
998 | static int twl4030_hw_params(struct snd_pcm_substream *substream, | ||
999 | struct snd_pcm_hw_params *params, | ||
1000 | struct snd_soc_dai *dai) | ||
1001 | { | ||
1002 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
1003 | struct snd_soc_device *socdev = rtd->socdev; | ||
1004 | struct snd_soc_codec *codec = socdev->codec; | ||
1005 | u8 mode, old_mode, format, old_format; | ||
1006 | |||
1007 | |||
1008 | /* bit rate */ | ||
1009 | old_mode = twl4030_read_reg_cache(codec, | ||
1010 | TWL4030_REG_CODEC_MODE) & ~TWL4030_CODECPDZ; | ||
1011 | mode = old_mode & ~TWL4030_APLL_RATE; | ||
1012 | |||
1013 | switch (params_rate(params)) { | ||
1014 | case 8000: | ||
1015 | mode |= TWL4030_APLL_RATE_8000; | ||
1016 | break; | ||
1017 | case 11025: | ||
1018 | mode |= TWL4030_APLL_RATE_11025; | ||
1019 | break; | ||
1020 | case 12000: | ||
1021 | mode |= TWL4030_APLL_RATE_12000; | ||
1022 | break; | ||
1023 | case 16000: | ||
1024 | mode |= TWL4030_APLL_RATE_16000; | ||
1025 | break; | ||
1026 | case 22050: | ||
1027 | mode |= TWL4030_APLL_RATE_22050; | ||
1028 | break; | ||
1029 | case 24000: | ||
1030 | mode |= TWL4030_APLL_RATE_24000; | ||
1031 | break; | ||
1032 | case 32000: | ||
1033 | mode |= TWL4030_APLL_RATE_32000; | ||
1034 | break; | ||
1035 | case 44100: | ||
1036 | mode |= TWL4030_APLL_RATE_44100; | ||
1037 | break; | ||
1038 | case 48000: | ||
1039 | mode |= TWL4030_APLL_RATE_48000; | ||
1040 | break; | ||
1041 | default: | ||
1042 | printk(KERN_ERR "TWL4030 hw params: unknown rate %d\n", | ||
1043 | params_rate(params)); | ||
1044 | return -EINVAL; | ||
1045 | } | ||
1046 | |||
1047 | if (mode != old_mode) { | ||
1048 | /* change rate and set CODECPDZ */ | ||
1049 | twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode); | ||
1050 | twl4030_set_codecpdz(codec); | ||
1051 | } | ||
1052 | |||
1053 | /* sample size */ | ||
1054 | old_format = twl4030_read_reg_cache(codec, TWL4030_REG_AUDIO_IF); | ||
1055 | format = old_format; | ||
1056 | format &= ~TWL4030_DATA_WIDTH; | ||
1057 | switch (params_format(params)) { | ||
1058 | case SNDRV_PCM_FORMAT_S16_LE: | ||
1059 | format |= TWL4030_DATA_WIDTH_16S_16W; | ||
1060 | break; | ||
1061 | case SNDRV_PCM_FORMAT_S24_LE: | ||
1062 | format |= TWL4030_DATA_WIDTH_32S_24W; | ||
1063 | break; | ||
1064 | default: | ||
1065 | printk(KERN_ERR "TWL4030 hw params: unknown format %d\n", | ||
1066 | params_format(params)); | ||
1067 | return -EINVAL; | ||
1068 | } | ||
1069 | |||
1070 | if (format != old_format) { | ||
1071 | |||
1072 | /* clear CODECPDZ before changing format (codec requirement) */ | ||
1073 | twl4030_clear_codecpdz(codec); | ||
1074 | |||
1075 | /* change format */ | ||
1076 | twl4030_write(codec, TWL4030_REG_AUDIO_IF, format); | ||
1077 | |||
1078 | /* set CODECPDZ afterwards */ | ||
1079 | twl4030_set_codecpdz(codec); | ||
1080 | } | ||
1081 | return 0; | ||
1082 | } | ||
1083 | |||
1084 | static int twl4030_set_dai_sysclk(struct snd_soc_dai *codec_dai, | ||
1085 | int clk_id, unsigned int freq, int dir) | ||
1086 | { | ||
1087 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1088 | u8 infreq; | ||
1089 | |||
1090 | switch (freq) { | ||
1091 | case 19200000: | ||
1092 | infreq = TWL4030_APLL_INFREQ_19200KHZ; | ||
1093 | break; | ||
1094 | case 26000000: | ||
1095 | infreq = TWL4030_APLL_INFREQ_26000KHZ; | ||
1096 | break; | ||
1097 | case 38400000: | ||
1098 | infreq = TWL4030_APLL_INFREQ_38400KHZ; | ||
1099 | break; | ||
1100 | default: | ||
1101 | printk(KERN_ERR "TWL4030 set sysclk: unknown rate %d\n", | ||
1102 | freq); | ||
1103 | return -EINVAL; | ||
1104 | } | ||
1105 | |||
1106 | infreq |= TWL4030_APLL_EN; | ||
1107 | twl4030_write(codec, TWL4030_REG_APLL_CTL, infreq); | ||
1108 | |||
1109 | return 0; | ||
1110 | } | ||
1111 | |||
1112 | static int twl4030_set_dai_fmt(struct snd_soc_dai *codec_dai, | ||
1113 | unsigned int fmt) | ||
1114 | { | ||
1115 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1116 | u8 old_format, format; | ||
1117 | |||
1118 | /* get format */ | ||
1119 | old_format = twl4030_read_reg_cache(codec, TWL4030_REG_AUDIO_IF); | ||
1120 | format = old_format; | ||
1121 | |||
1122 | /* set master/slave audio interface */ | ||
1123 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
1124 | case SND_SOC_DAIFMT_CBM_CFM: | ||
1125 | format &= ~(TWL4030_AIF_SLAVE_EN); | ||
1126 | format &= ~(TWL4030_CLK256FS_EN); | ||
1127 | break; | ||
1128 | case SND_SOC_DAIFMT_CBS_CFS: | ||
1129 | format |= TWL4030_AIF_SLAVE_EN; | ||
1130 | format |= TWL4030_CLK256FS_EN; | ||
1131 | break; | ||
1132 | default: | ||
1133 | return -EINVAL; | ||
1134 | } | ||
1135 | |||
1136 | /* interface format */ | ||
1137 | format &= ~TWL4030_AIF_FORMAT; | ||
1138 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
1139 | case SND_SOC_DAIFMT_I2S: | ||
1140 | format |= TWL4030_AIF_FORMAT_CODEC; | ||
1141 | break; | ||
1142 | default: | ||
1143 | return -EINVAL; | ||
1144 | } | ||
1145 | |||
1146 | if (format != old_format) { | ||
1147 | |||
1148 | /* clear CODECPDZ before changing format (codec requirement) */ | ||
1149 | twl4030_clear_codecpdz(codec); | ||
1150 | |||
1151 | /* change format */ | ||
1152 | twl4030_write(codec, TWL4030_REG_AUDIO_IF, format); | ||
1153 | |||
1154 | /* set CODECPDZ afterwards */ | ||
1155 | twl4030_set_codecpdz(codec); | ||
1156 | } | ||
1157 | |||
1158 | return 0; | ||
1159 | } | ||
1160 | |||
1161 | #define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000) | ||
1162 | #define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_S24_LE) | ||
1163 | |||
1164 | struct snd_soc_dai twl4030_dai = { | ||
1165 | .name = "twl4030", | ||
1166 | .playback = { | ||
1167 | .stream_name = "Playback", | ||
1168 | .channels_min = 2, | ||
1169 | .channels_max = 2, | ||
1170 | .rates = TWL4030_RATES, | ||
1171 | .formats = TWL4030_FORMATS,}, | ||
1172 | .capture = { | ||
1173 | .stream_name = "Capture", | ||
1174 | .channels_min = 2, | ||
1175 | .channels_max = 2, | ||
1176 | .rates = TWL4030_RATES, | ||
1177 | .formats = TWL4030_FORMATS,}, | ||
1178 | .ops = { | ||
1179 | .hw_params = twl4030_hw_params, | ||
1180 | .set_sysclk = twl4030_set_dai_sysclk, | ||
1181 | .set_fmt = twl4030_set_dai_fmt, | ||
1182 | } | ||
1183 | }; | ||
1184 | EXPORT_SYMBOL_GPL(twl4030_dai); | ||
1185 | |||
1186 | static int twl4030_suspend(struct platform_device *pdev, pm_message_t state) | ||
1187 | { | ||
1188 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1189 | struct snd_soc_codec *codec = socdev->codec; | ||
1190 | |||
1191 | twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
1192 | |||
1193 | return 0; | ||
1194 | } | ||
1195 | |||
1196 | static int twl4030_resume(struct platform_device *pdev) | ||
1197 | { | ||
1198 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1199 | struct snd_soc_codec *codec = socdev->codec; | ||
1200 | |||
1201 | twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
1202 | twl4030_set_bias_level(codec, codec->suspend_bias_level); | ||
1203 | return 0; | ||
1204 | } | ||
1205 | |||
1206 | /* | ||
1207 | * initialize the driver | ||
1208 | * register the mixer and dsp interfaces with the kernel | ||
1209 | */ | ||
1210 | |||
1211 | static int twl4030_init(struct snd_soc_device *socdev) | ||
1212 | { | ||
1213 | struct snd_soc_codec *codec = socdev->codec; | ||
1214 | int ret = 0; | ||
1215 | |||
1216 | printk(KERN_INFO "TWL4030 Audio Codec init \n"); | ||
1217 | |||
1218 | codec->name = "twl4030"; | ||
1219 | codec->owner = THIS_MODULE; | ||
1220 | codec->read = twl4030_read_reg_cache; | ||
1221 | codec->write = twl4030_write; | ||
1222 | codec->set_bias_level = twl4030_set_bias_level; | ||
1223 | codec->dai = &twl4030_dai; | ||
1224 | codec->num_dai = 1; | ||
1225 | codec->reg_cache_size = sizeof(twl4030_reg); | ||
1226 | codec->reg_cache = kmemdup(twl4030_reg, sizeof(twl4030_reg), | ||
1227 | GFP_KERNEL); | ||
1228 | if (codec->reg_cache == NULL) | ||
1229 | return -ENOMEM; | ||
1230 | |||
1231 | /* register pcms */ | ||
1232 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
1233 | if (ret < 0) { | ||
1234 | printk(KERN_ERR "twl4030: failed to create pcms\n"); | ||
1235 | goto pcm_err; | ||
1236 | } | ||
1237 | |||
1238 | twl4030_init_chip(codec); | ||
1239 | |||
1240 | /* power on device */ | ||
1241 | twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
1242 | |||
1243 | twl4030_add_controls(codec); | ||
1244 | twl4030_add_widgets(codec); | ||
1245 | |||
1246 | ret = snd_soc_init_card(socdev); | ||
1247 | if (ret < 0) { | ||
1248 | printk(KERN_ERR "twl4030: failed to register card\n"); | ||
1249 | goto card_err; | ||
1250 | } | ||
1251 | |||
1252 | return ret; | ||
1253 | |||
1254 | card_err: | ||
1255 | snd_soc_free_pcms(socdev); | ||
1256 | snd_soc_dapm_free(socdev); | ||
1257 | pcm_err: | ||
1258 | kfree(codec->reg_cache); | ||
1259 | return ret; | ||
1260 | } | ||
1261 | |||
1262 | static struct snd_soc_device *twl4030_socdev; | ||
1263 | |||
1264 | static int twl4030_probe(struct platform_device *pdev) | ||
1265 | { | ||
1266 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1267 | struct snd_soc_codec *codec; | ||
1268 | |||
1269 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | ||
1270 | if (codec == NULL) | ||
1271 | return -ENOMEM; | ||
1272 | |||
1273 | socdev->codec = codec; | ||
1274 | mutex_init(&codec->mutex); | ||
1275 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
1276 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
1277 | |||
1278 | twl4030_socdev = socdev; | ||
1279 | twl4030_init(socdev); | ||
1280 | |||
1281 | return 0; | ||
1282 | } | ||
1283 | |||
1284 | static int twl4030_remove(struct platform_device *pdev) | ||
1285 | { | ||
1286 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1287 | struct snd_soc_codec *codec = socdev->codec; | ||
1288 | |||
1289 | printk(KERN_INFO "TWL4030 Audio Codec remove\n"); | ||
1290 | kfree(codec); | ||
1291 | |||
1292 | return 0; | ||
1293 | } | ||
1294 | |||
1295 | struct snd_soc_codec_device soc_codec_dev_twl4030 = { | ||
1296 | .probe = twl4030_probe, | ||
1297 | .remove = twl4030_remove, | ||
1298 | .suspend = twl4030_suspend, | ||
1299 | .resume = twl4030_resume, | ||
1300 | }; | ||
1301 | EXPORT_SYMBOL_GPL(soc_codec_dev_twl4030); | ||
1302 | |||
1303 | static int __init twl4030_modinit(void) | ||
1304 | { | ||
1305 | return snd_soc_register_dai(&twl4030_dai); | ||
1306 | } | ||
1307 | module_init(twl4030_modinit); | ||
1308 | |||
1309 | static void __exit twl4030_exit(void) | ||
1310 | { | ||
1311 | snd_soc_unregister_dai(&twl4030_dai); | ||
1312 | } | ||
1313 | module_exit(twl4030_exit); | ||
1314 | |||
1315 | MODULE_DESCRIPTION("ASoC TWL4030 codec driver"); | ||
1316 | MODULE_AUTHOR("Steve Sakoman"); | ||
1317 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/twl4030.h b/sound/soc/codecs/twl4030.h new file mode 100644 index 000000000000..54615c76802b --- /dev/null +++ b/sound/soc/codecs/twl4030.h | |||
@@ -0,0 +1,219 @@ | |||
1 | /* | ||
2 | * ALSA SoC TWL4030 codec driver | ||
3 | * | ||
4 | * Author: Steve Sakoman <steve@sakoman.com> | ||
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 | #ifndef __TWL4030_AUDIO_H__ | ||
23 | #define __TWL4030_AUDIO_H__ | ||
24 | |||
25 | #define TWL4030_REG_CODEC_MODE 0x1 | ||
26 | #define TWL4030_REG_OPTION 0x2 | ||
27 | #define TWL4030_REG_UNKNOWN 0x3 | ||
28 | #define TWL4030_REG_MICBIAS_CTL 0x4 | ||
29 | #define TWL4030_REG_ANAMICL 0x5 | ||
30 | #define TWL4030_REG_ANAMICR 0x6 | ||
31 | #define TWL4030_REG_AVADC_CTL 0x7 | ||
32 | #define TWL4030_REG_ADCMICSEL 0x8 | ||
33 | #define TWL4030_REG_DIGMIXING 0x9 | ||
34 | #define TWL4030_REG_ATXL1PGA 0xA | ||
35 | #define TWL4030_REG_ATXR1PGA 0xB | ||
36 | #define TWL4030_REG_AVTXL2PGA 0xC | ||
37 | #define TWL4030_REG_AVTXR2PGA 0xD | ||
38 | #define TWL4030_REG_AUDIO_IF 0xE | ||
39 | #define TWL4030_REG_VOICE_IF 0xF | ||
40 | #define TWL4030_REG_ARXR1PGA 0x10 | ||
41 | #define TWL4030_REG_ARXL1PGA 0x11 | ||
42 | #define TWL4030_REG_ARXR2PGA 0x12 | ||
43 | #define TWL4030_REG_ARXL2PGA 0x13 | ||
44 | #define TWL4030_REG_VRXPGA 0x14 | ||
45 | #define TWL4030_REG_VSTPGA 0x15 | ||
46 | #define TWL4030_REG_VRX2ARXPGA 0x16 | ||
47 | #define TWL4030_REG_AVDAC_CTL 0x17 | ||
48 | #define TWL4030_REG_ARX2VTXPGA 0x18 | ||
49 | #define TWL4030_REG_ARXL1_APGA_CTL 0x19 | ||
50 | #define TWL4030_REG_ARXR1_APGA_CTL 0x1A | ||
51 | #define TWL4030_REG_ARXL2_APGA_CTL 0x1B | ||
52 | #define TWL4030_REG_ARXR2_APGA_CTL 0x1C | ||
53 | #define TWL4030_REG_ATX2ARXPGA 0x1D | ||
54 | #define TWL4030_REG_BT_IF 0x1E | ||
55 | #define TWL4030_REG_BTPGA 0x1F | ||
56 | #define TWL4030_REG_BTSTPGA 0x20 | ||
57 | #define TWL4030_REG_EAR_CTL 0x21 | ||
58 | #define TWL4030_REG_HS_SEL 0x22 | ||
59 | #define TWL4030_REG_HS_GAIN_SET 0x23 | ||
60 | #define TWL4030_REG_HS_POPN_SET 0x24 | ||
61 | #define TWL4030_REG_PREDL_CTL 0x25 | ||
62 | #define TWL4030_REG_PREDR_CTL 0x26 | ||
63 | #define TWL4030_REG_PRECKL_CTL 0x27 | ||
64 | #define TWL4030_REG_PRECKR_CTL 0x28 | ||
65 | #define TWL4030_REG_HFL_CTL 0x29 | ||
66 | #define TWL4030_REG_HFR_CTL 0x2A | ||
67 | #define TWL4030_REG_ALC_CTL 0x2B | ||
68 | #define TWL4030_REG_ALC_SET1 0x2C | ||
69 | #define TWL4030_REG_ALC_SET2 0x2D | ||
70 | #define TWL4030_REG_BOOST_CTL 0x2E | ||
71 | #define TWL4030_REG_SOFTVOL_CTL 0x2F | ||
72 | #define TWL4030_REG_DTMF_FREQSEL 0x30 | ||
73 | #define TWL4030_REG_DTMF_TONEXT1H 0x31 | ||
74 | #define TWL4030_REG_DTMF_TONEXT1L 0x32 | ||
75 | #define TWL4030_REG_DTMF_TONEXT2H 0x33 | ||
76 | #define TWL4030_REG_DTMF_TONEXT2L 0x34 | ||
77 | #define TWL4030_REG_DTMF_TONOFF 0x35 | ||
78 | #define TWL4030_REG_DTMF_WANONOFF 0x36 | ||
79 | #define TWL4030_REG_I2S_RX_SCRAMBLE_H 0x37 | ||
80 | #define TWL4030_REG_I2S_RX_SCRAMBLE_M 0x38 | ||
81 | #define TWL4030_REG_I2S_RX_SCRAMBLE_L 0x39 | ||
82 | #define TWL4030_REG_APLL_CTL 0x3A | ||
83 | #define TWL4030_REG_DTMF_CTL 0x3B | ||
84 | #define TWL4030_REG_DTMF_PGA_CTL2 0x3C | ||
85 | #define TWL4030_REG_DTMF_PGA_CTL1 0x3D | ||
86 | #define TWL4030_REG_MISC_SET_1 0x3E | ||
87 | #define TWL4030_REG_PCMBTMUX 0x3F | ||
88 | #define TWL4030_REG_RX_PATH_SEL 0x43 | ||
89 | #define TWL4030_REG_VDL_APGA_CTL 0x44 | ||
90 | #define TWL4030_REG_VIBRA_CTL 0x45 | ||
91 | #define TWL4030_REG_VIBRA_SET 0x46 | ||
92 | #define TWL4030_REG_VIBRA_PWM_SET 0x47 | ||
93 | #define TWL4030_REG_ANAMIC_GAIN 0x48 | ||
94 | #define TWL4030_REG_MISC_SET_2 0x49 | ||
95 | |||
96 | #define TWL4030_CACHEREGNUM (TWL4030_REG_MISC_SET_2 + 1) | ||
97 | |||
98 | /* Bitfield Definitions */ | ||
99 | |||
100 | /* TWL4030_CODEC_MODE (0x01) Fields */ | ||
101 | |||
102 | #define TWL4030_APLL_RATE 0xF0 | ||
103 | #define TWL4030_APLL_RATE_8000 0x00 | ||
104 | #define TWL4030_APLL_RATE_11025 0x10 | ||
105 | #define TWL4030_APLL_RATE_12000 0x20 | ||
106 | #define TWL4030_APLL_RATE_16000 0x40 | ||
107 | #define TWL4030_APLL_RATE_22050 0x50 | ||
108 | #define TWL4030_APLL_RATE_24000 0x60 | ||
109 | #define TWL4030_APLL_RATE_32000 0x80 | ||
110 | #define TWL4030_APLL_RATE_44100 0x90 | ||
111 | #define TWL4030_APLL_RATE_48000 0xA0 | ||
112 | #define TWL4030_SEL_16K 0x04 | ||
113 | #define TWL4030_CODECPDZ 0x02 | ||
114 | #define TWL4030_OPT_MODE 0x01 | ||
115 | |||
116 | /* TWL4030_REG_MICBIAS_CTL (0x04) Fields */ | ||
117 | |||
118 | #define TWL4030_MICBIAS2_CTL 0x40 | ||
119 | #define TWL4030_MICBIAS1_CTL 0x20 | ||
120 | #define TWL4030_HSMICBIAS_EN 0x04 | ||
121 | #define TWL4030_MICBIAS2_EN 0x02 | ||
122 | #define TWL4030_MICBIAS1_EN 0x01 | ||
123 | |||
124 | /* ANAMICL (0x05) Fields */ | ||
125 | |||
126 | #define TWL4030_CNCL_OFFSET_START 0x80 | ||
127 | #define TWL4030_OFFSET_CNCL_SEL 0x60 | ||
128 | #define TWL4030_OFFSET_CNCL_SEL_ARX1 0x00 | ||
129 | #define TWL4030_OFFSET_CNCL_SEL_ARX2 0x20 | ||
130 | #define TWL4030_OFFSET_CNCL_SEL_VRX 0x40 | ||
131 | #define TWL4030_OFFSET_CNCL_SEL_ALL 0x60 | ||
132 | #define TWL4030_MICAMPL_EN 0x10 | ||
133 | #define TWL4030_CKMIC_EN 0x08 | ||
134 | #define TWL4030_AUXL_EN 0x04 | ||
135 | #define TWL4030_HSMIC_EN 0x02 | ||
136 | #define TWL4030_MAINMIC_EN 0x01 | ||
137 | |||
138 | /* ANAMICR (0x06) Fields */ | ||
139 | |||
140 | #define TWL4030_MICAMPR_EN 0x10 | ||
141 | #define TWL4030_AUXR_EN 0x04 | ||
142 | #define TWL4030_SUBMIC_EN 0x01 | ||
143 | |||
144 | /* AVADC_CTL (0x07) Fields */ | ||
145 | |||
146 | #define TWL4030_ADCL_EN 0x08 | ||
147 | #define TWL4030_AVADC_CLK_PRIORITY 0x04 | ||
148 | #define TWL4030_ADCR_EN 0x02 | ||
149 | |||
150 | /* AUDIO_IF (0x0E) Fields */ | ||
151 | |||
152 | #define TWL4030_AIF_SLAVE_EN 0x80 | ||
153 | #define TWL4030_DATA_WIDTH 0x60 | ||
154 | #define TWL4030_DATA_WIDTH_16S_16W 0x00 | ||
155 | #define TWL4030_DATA_WIDTH_32S_16W 0x40 | ||
156 | #define TWL4030_DATA_WIDTH_32S_24W 0x60 | ||
157 | #define TWL4030_AIF_FORMAT 0x18 | ||
158 | #define TWL4030_AIF_FORMAT_CODEC 0x00 | ||
159 | #define TWL4030_AIF_FORMAT_LEFT 0x08 | ||
160 | #define TWL4030_AIF_FORMAT_RIGHT 0x10 | ||
161 | #define TWL4030_AIF_FORMAT_TDM 0x18 | ||
162 | #define TWL4030_AIF_TRI_EN 0x04 | ||
163 | #define TWL4030_CLK256FS_EN 0x02 | ||
164 | #define TWL4030_AIF_EN 0x01 | ||
165 | |||
166 | /* HS_GAIN_SET (0x23) Fields */ | ||
167 | |||
168 | #define TWL4030_HSR_GAIN 0x0C | ||
169 | #define TWL4030_HSR_GAIN_PWR_DOWN 0x00 | ||
170 | #define TWL4030_HSR_GAIN_PLUS_6DB 0x04 | ||
171 | #define TWL4030_HSR_GAIN_0DB 0x08 | ||
172 | #define TWL4030_HSR_GAIN_MINUS_6DB 0x0C | ||
173 | #define TWL4030_HSL_GAIN 0x03 | ||
174 | #define TWL4030_HSL_GAIN_PWR_DOWN 0x00 | ||
175 | #define TWL4030_HSL_GAIN_PLUS_6DB 0x01 | ||
176 | #define TWL4030_HSL_GAIN_0DB 0x02 | ||
177 | #define TWL4030_HSL_GAIN_MINUS_6DB 0x03 | ||
178 | |||
179 | /* HS_POPN_SET (0x24) Fields */ | ||
180 | |||
181 | #define TWL4030_VMID_EN 0x40 | ||
182 | #define TWL4030_EXTMUTE 0x20 | ||
183 | #define TWL4030_RAMP_DELAY 0x1C | ||
184 | #define TWL4030_RAMP_DELAY_20MS 0x00 | ||
185 | #define TWL4030_RAMP_DELAY_40MS 0x04 | ||
186 | #define TWL4030_RAMP_DELAY_81MS 0x08 | ||
187 | #define TWL4030_RAMP_DELAY_161MS 0x0C | ||
188 | #define TWL4030_RAMP_DELAY_323MS 0x10 | ||
189 | #define TWL4030_RAMP_DELAY_645MS 0x14 | ||
190 | #define TWL4030_RAMP_DELAY_1291MS 0x18 | ||
191 | #define TWL4030_RAMP_DELAY_2581MS 0x1C | ||
192 | #define TWL4030_RAMP_EN 0x02 | ||
193 | |||
194 | /* HFL_CTL (0x29, 0x2A) Fields */ | ||
195 | #define TWL4030_HF_CTL_HB_EN 0x04 | ||
196 | #define TWL4030_HF_CTL_LOOP_EN 0x08 | ||
197 | #define TWL4030_HF_CTL_RAMP_EN 0x10 | ||
198 | #define TWL4030_HF_CTL_REF_EN 0x20 | ||
199 | |||
200 | /* APLL_CTL (0x3A) Fields */ | ||
201 | |||
202 | #define TWL4030_APLL_EN 0x10 | ||
203 | #define TWL4030_APLL_INFREQ 0x0F | ||
204 | #define TWL4030_APLL_INFREQ_19200KHZ 0x05 | ||
205 | #define TWL4030_APLL_INFREQ_26000KHZ 0x06 | ||
206 | #define TWL4030_APLL_INFREQ_38400KHZ 0x0F | ||
207 | |||
208 | /* REG_MISC_SET_1 (0x3E) Fields */ | ||
209 | |||
210 | #define TWL4030_CLK64_EN 0x80 | ||
211 | #define TWL4030_SCRAMBLE_EN 0x40 | ||
212 | #define TWL4030_FMLOOP_EN 0x20 | ||
213 | #define TWL4030_SMOOTH_ANAVOL_EN 0x02 | ||
214 | #define TWL4030_DIGMIC_LR_SWAP_EN 0x01 | ||
215 | |||
216 | extern struct snd_soc_dai twl4030_dai; | ||
217 | extern struct snd_soc_codec_device soc_codec_dev_twl4030; | ||
218 | |||
219 | #endif /* End of __TWL4030_AUDIO_H__ */ | ||
diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c new file mode 100644 index 000000000000..a2c5064a774b --- /dev/null +++ b/sound/soc/codecs/uda134x.c | |||
@@ -0,0 +1,668 @@ | |||
1 | /* | ||
2 | * uda134x.c -- UDA134X ALSA SoC Codec driver | ||
3 | * | ||
4 | * Modifications by Christian Pellegrin <chripell@evolware.org> | ||
5 | * | ||
6 | * Copyright 2007 Dension Audio Systems Ltd. | ||
7 | * Author: Zoltan Devai | ||
8 | * | ||
9 | * Based on the WM87xx drivers by Liam Girdwood and Richard Purdie | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #include <linux/module.h> | ||
17 | #include <linux/delay.h> | ||
18 | #include <sound/pcm.h> | ||
19 | #include <sound/pcm_params.h> | ||
20 | #include <sound/soc.h> | ||
21 | #include <sound/soc-dapm.h> | ||
22 | #include <sound/initval.h> | ||
23 | |||
24 | #include <sound/uda134x.h> | ||
25 | #include <sound/l3.h> | ||
26 | |||
27 | #include "uda134x.h" | ||
28 | |||
29 | |||
30 | #define POWER_OFF_ON_STANDBY 1 | ||
31 | /* | ||
32 | ALSA SOC usually puts the device in standby mode when it's not used | ||
33 | for sometime. If you define POWER_OFF_ON_STANDBY the driver will | ||
34 | turn off the ADC/DAC when this callback is invoked and turn it back | ||
35 | on when needed. Unfortunately this will result in a very light bump | ||
36 | (it can be audible only with good earphones). If this bothers you | ||
37 | just comment this line, you will have slightly higher power | ||
38 | consumption . Please note that sending the L3 command for ADC is | ||
39 | enough to make the bump, so it doesn't make difference if you | ||
40 | completely take off power from the codec. | ||
41 | */ | ||
42 | |||
43 | #define UDA134X_RATES SNDRV_PCM_RATE_8000_48000 | ||
44 | #define UDA134X_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE | \ | ||
45 | SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S20_3LE) | ||
46 | |||
47 | struct uda134x_priv { | ||
48 | int sysclk; | ||
49 | int dai_fmt; | ||
50 | |||
51 | struct snd_pcm_substream *master_substream; | ||
52 | struct snd_pcm_substream *slave_substream; | ||
53 | }; | ||
54 | |||
55 | /* In-data addresses are hard-coded into the reg-cache values */ | ||
56 | static const char uda134x_reg[UDA134X_REGS_NUM] = { | ||
57 | /* Extended address registers */ | ||
58 | 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
59 | /* Status, data regs */ | ||
60 | 0x00, 0x83, 0x00, 0x40, 0x80, 0x00, | ||
61 | }; | ||
62 | |||
63 | /* | ||
64 | * The codec has no support for reading its registers except for peak level... | ||
65 | */ | ||
66 | static inline unsigned int uda134x_read_reg_cache(struct snd_soc_codec *codec, | ||
67 | unsigned int reg) | ||
68 | { | ||
69 | u8 *cache = codec->reg_cache; | ||
70 | |||
71 | if (reg >= UDA134X_REGS_NUM) | ||
72 | return -1; | ||
73 | return cache[reg]; | ||
74 | } | ||
75 | |||
76 | /* | ||
77 | * Write the register cache | ||
78 | */ | ||
79 | static inline void uda134x_write_reg_cache(struct snd_soc_codec *codec, | ||
80 | u8 reg, unsigned int value) | ||
81 | { | ||
82 | u8 *cache = codec->reg_cache; | ||
83 | |||
84 | if (reg >= UDA134X_REGS_NUM) | ||
85 | return; | ||
86 | cache[reg] = value; | ||
87 | } | ||
88 | |||
89 | /* | ||
90 | * Write to the uda134x registers | ||
91 | * | ||
92 | */ | ||
93 | static int uda134x_write(struct snd_soc_codec *codec, unsigned int reg, | ||
94 | unsigned int value) | ||
95 | { | ||
96 | int ret; | ||
97 | u8 addr; | ||
98 | u8 data = value; | ||
99 | struct uda134x_platform_data *pd = codec->control_data; | ||
100 | |||
101 | pr_debug("%s reg: %02X, value:%02X\n", __func__, reg, value); | ||
102 | |||
103 | if (reg >= UDA134X_REGS_NUM) { | ||
104 | printk(KERN_ERR "%s unkown register: reg: %d", | ||
105 | __func__, reg); | ||
106 | return -EINVAL; | ||
107 | } | ||
108 | |||
109 | uda134x_write_reg_cache(codec, reg, value); | ||
110 | |||
111 | switch (reg) { | ||
112 | case UDA134X_STATUS0: | ||
113 | case UDA134X_STATUS1: | ||
114 | addr = UDA134X_STATUS_ADDR; | ||
115 | break; | ||
116 | case UDA134X_DATA000: | ||
117 | case UDA134X_DATA001: | ||
118 | case UDA134X_DATA010: | ||
119 | addr = UDA134X_DATA0_ADDR; | ||
120 | break; | ||
121 | case UDA134X_DATA1: | ||
122 | addr = UDA134X_DATA1_ADDR; | ||
123 | break; | ||
124 | default: | ||
125 | /* It's an extended address register */ | ||
126 | addr = (reg | UDA134X_EXTADDR_PREFIX); | ||
127 | |||
128 | ret = l3_write(&pd->l3, | ||
129 | UDA134X_DATA0_ADDR, &addr, 1); | ||
130 | if (ret != 1) | ||
131 | return -EIO; | ||
132 | |||
133 | addr = UDA134X_DATA0_ADDR; | ||
134 | data = (value | UDA134X_EXTDATA_PREFIX); | ||
135 | break; | ||
136 | } | ||
137 | |||
138 | ret = l3_write(&pd->l3, | ||
139 | addr, &data, 1); | ||
140 | if (ret != 1) | ||
141 | return -EIO; | ||
142 | |||
143 | return 0; | ||
144 | } | ||
145 | |||
146 | static inline void uda134x_reset(struct snd_soc_codec *codec) | ||
147 | { | ||
148 | u8 reset_reg = uda134x_read_reg_cache(codec, UDA134X_STATUS0); | ||
149 | uda134x_write(codec, UDA134X_STATUS0, reset_reg | (1<<6)); | ||
150 | msleep(1); | ||
151 | uda134x_write(codec, UDA134X_STATUS0, reset_reg & ~(1<<6)); | ||
152 | } | ||
153 | |||
154 | static int uda134x_mute(struct snd_soc_dai *dai, int mute) | ||
155 | { | ||
156 | struct snd_soc_codec *codec = dai->codec; | ||
157 | u8 mute_reg = uda134x_read_reg_cache(codec, UDA134X_DATA010); | ||
158 | |||
159 | pr_debug("%s mute: %d\n", __func__, mute); | ||
160 | |||
161 | if (mute) | ||
162 | mute_reg |= (1<<2); | ||
163 | else | ||
164 | mute_reg &= ~(1<<2); | ||
165 | |||
166 | uda134x_write(codec, UDA134X_DATA010, mute_reg & ~(1<<2)); | ||
167 | |||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | static int uda134x_startup(struct snd_pcm_substream *substream, | ||
172 | struct snd_soc_dai *dai) | ||
173 | { | ||
174 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
175 | struct snd_soc_device *socdev = rtd->socdev; | ||
176 | struct snd_soc_codec *codec = socdev->codec; | ||
177 | struct uda134x_priv *uda134x = codec->private_data; | ||
178 | struct snd_pcm_runtime *master_runtime; | ||
179 | |||
180 | if (uda134x->master_substream) { | ||
181 | master_runtime = uda134x->master_substream->runtime; | ||
182 | |||
183 | pr_debug("%s constraining to %d bits at %d\n", __func__, | ||
184 | master_runtime->sample_bits, | ||
185 | master_runtime->rate); | ||
186 | |||
187 | snd_pcm_hw_constraint_minmax(substream->runtime, | ||
188 | SNDRV_PCM_HW_PARAM_RATE, | ||
189 | master_runtime->rate, | ||
190 | master_runtime->rate); | ||
191 | |||
192 | snd_pcm_hw_constraint_minmax(substream->runtime, | ||
193 | SNDRV_PCM_HW_PARAM_SAMPLE_BITS, | ||
194 | master_runtime->sample_bits, | ||
195 | master_runtime->sample_bits); | ||
196 | |||
197 | uda134x->slave_substream = substream; | ||
198 | } else | ||
199 | uda134x->master_substream = substream; | ||
200 | |||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | static void uda134x_shutdown(struct snd_pcm_substream *substream, | ||
205 | struct snd_soc_dai *dai) | ||
206 | { | ||
207 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
208 | struct snd_soc_device *socdev = rtd->socdev; | ||
209 | struct snd_soc_codec *codec = socdev->codec; | ||
210 | struct uda134x_priv *uda134x = codec->private_data; | ||
211 | |||
212 | if (uda134x->master_substream == substream) | ||
213 | uda134x->master_substream = uda134x->slave_substream; | ||
214 | |||
215 | uda134x->slave_substream = NULL; | ||
216 | } | ||
217 | |||
218 | static int uda134x_hw_params(struct snd_pcm_substream *substream, | ||
219 | struct snd_pcm_hw_params *params, | ||
220 | struct snd_soc_dai *dai) | ||
221 | { | ||
222 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
223 | struct snd_soc_device *socdev = rtd->socdev; | ||
224 | struct snd_soc_codec *codec = socdev->codec; | ||
225 | struct uda134x_priv *uda134x = codec->private_data; | ||
226 | u8 hw_params; | ||
227 | |||
228 | if (substream == uda134x->slave_substream) { | ||
229 | pr_debug("%s ignoring hw_params for slave substream\n", | ||
230 | __func__); | ||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | hw_params = uda134x_read_reg_cache(codec, UDA134X_STATUS0); | ||
235 | hw_params &= STATUS0_SYSCLK_MASK; | ||
236 | hw_params &= STATUS0_DAIFMT_MASK; | ||
237 | |||
238 | pr_debug("%s sysclk: %d, rate:%d\n", __func__, | ||
239 | uda134x->sysclk, params_rate(params)); | ||
240 | |||
241 | /* set SYSCLK / fs ratio */ | ||
242 | switch (uda134x->sysclk / params_rate(params)) { | ||
243 | case 512: | ||
244 | break; | ||
245 | case 384: | ||
246 | hw_params |= (1<<4); | ||
247 | break; | ||
248 | case 256: | ||
249 | hw_params |= (1<<5); | ||
250 | break; | ||
251 | default: | ||
252 | printk(KERN_ERR "%s unsupported fs\n", __func__); | ||
253 | return -EINVAL; | ||
254 | } | ||
255 | |||
256 | pr_debug("%s dai_fmt: %d, params_format:%d\n", __func__, | ||
257 | uda134x->dai_fmt, params_format(params)); | ||
258 | |||
259 | /* set DAI format and word length */ | ||
260 | switch (uda134x->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
261 | case SND_SOC_DAIFMT_I2S: | ||
262 | break; | ||
263 | case SND_SOC_DAIFMT_RIGHT_J: | ||
264 | switch (params_format(params)) { | ||
265 | case SNDRV_PCM_FORMAT_S16_LE: | ||
266 | hw_params |= (1<<1); | ||
267 | break; | ||
268 | case SNDRV_PCM_FORMAT_S18_3LE: | ||
269 | hw_params |= (1<<2); | ||
270 | break; | ||
271 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
272 | hw_params |= ((1<<2) | (1<<1)); | ||
273 | break; | ||
274 | default: | ||
275 | printk(KERN_ERR "%s unsupported format (right)\n", | ||
276 | __func__); | ||
277 | return -EINVAL; | ||
278 | } | ||
279 | break; | ||
280 | case SND_SOC_DAIFMT_LEFT_J: | ||
281 | hw_params |= (1<<3); | ||
282 | break; | ||
283 | default: | ||
284 | printk(KERN_ERR "%s unsupported format\n", __func__); | ||
285 | return -EINVAL; | ||
286 | } | ||
287 | |||
288 | uda134x_write(codec, UDA134X_STATUS0, hw_params); | ||
289 | |||
290 | return 0; | ||
291 | } | ||
292 | |||
293 | static int uda134x_set_dai_sysclk(struct snd_soc_dai *codec_dai, | ||
294 | int clk_id, unsigned int freq, int dir) | ||
295 | { | ||
296 | struct snd_soc_codec *codec = codec_dai->codec; | ||
297 | struct uda134x_priv *uda134x = codec->private_data; | ||
298 | |||
299 | pr_debug("%s clk_id: %d, freq: %d, dir: %d\n", __func__, | ||
300 | clk_id, freq, dir); | ||
301 | |||
302 | /* Anything between 256fs*8Khz and 512fs*48Khz should be acceptable | ||
303 | because the codec is slave. Of course limitations of the clock | ||
304 | master (the IIS controller) apply. | ||
305 | We'll error out on set_hw_params if it's not OK */ | ||
306 | if ((freq >= (256 * 8000)) && (freq <= (512 * 48000))) { | ||
307 | uda134x->sysclk = freq; | ||
308 | return 0; | ||
309 | } | ||
310 | |||
311 | printk(KERN_ERR "%s unsupported sysclk\n", __func__); | ||
312 | return -EINVAL; | ||
313 | } | ||
314 | |||
315 | static int uda134x_set_dai_fmt(struct snd_soc_dai *codec_dai, | ||
316 | unsigned int fmt) | ||
317 | { | ||
318 | struct snd_soc_codec *codec = codec_dai->codec; | ||
319 | struct uda134x_priv *uda134x = codec->private_data; | ||
320 | |||
321 | pr_debug("%s fmt: %08X\n", __func__, fmt); | ||
322 | |||
323 | /* codec supports only full slave mode */ | ||
324 | if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) { | ||
325 | printk(KERN_ERR "%s unsupported slave mode\n", __func__); | ||
326 | return -EINVAL; | ||
327 | } | ||
328 | |||
329 | /* no support for clock inversion */ | ||
330 | if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF) { | ||
331 | printk(KERN_ERR "%s unsupported clock inversion\n", __func__); | ||
332 | return -EINVAL; | ||
333 | } | ||
334 | |||
335 | /* We can't setup DAI format here as it depends on the word bit num */ | ||
336 | /* so let's just store the value for later */ | ||
337 | uda134x->dai_fmt = fmt; | ||
338 | |||
339 | return 0; | ||
340 | } | ||
341 | |||
342 | static int uda134x_set_bias_level(struct snd_soc_codec *codec, | ||
343 | enum snd_soc_bias_level level) | ||
344 | { | ||
345 | u8 reg; | ||
346 | struct uda134x_platform_data *pd = codec->control_data; | ||
347 | int i; | ||
348 | u8 *cache = codec->reg_cache; | ||
349 | |||
350 | pr_debug("%s bias level %d\n", __func__, level); | ||
351 | |||
352 | switch (level) { | ||
353 | case SND_SOC_BIAS_ON: | ||
354 | /* ADC, DAC on */ | ||
355 | reg = uda134x_read_reg_cache(codec, UDA134X_STATUS1); | ||
356 | uda134x_write(codec, UDA134X_STATUS1, reg | 0x03); | ||
357 | break; | ||
358 | case SND_SOC_BIAS_PREPARE: | ||
359 | /* power on */ | ||
360 | if (pd->power) { | ||
361 | pd->power(1); | ||
362 | /* Sync reg_cache with the hardware */ | ||
363 | for (i = 0; i < ARRAY_SIZE(uda134x_reg); i++) | ||
364 | codec->write(codec, i, *cache++); | ||
365 | } | ||
366 | break; | ||
367 | case SND_SOC_BIAS_STANDBY: | ||
368 | /* ADC, DAC power off */ | ||
369 | reg = uda134x_read_reg_cache(codec, UDA134X_STATUS1); | ||
370 | uda134x_write(codec, UDA134X_STATUS1, reg & ~(0x03)); | ||
371 | break; | ||
372 | case SND_SOC_BIAS_OFF: | ||
373 | /* power off */ | ||
374 | if (pd->power) | ||
375 | pd->power(0); | ||
376 | break; | ||
377 | } | ||
378 | codec->bias_level = level; | ||
379 | return 0; | ||
380 | } | ||
381 | |||
382 | static const char *uda134x_dsp_setting[] = {"Flat", "Minimum1", | ||
383 | "Minimum2", "Maximum"}; | ||
384 | static const char *uda134x_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"}; | ||
385 | static const char *uda134x_mixmode[] = {"Differential", "Analog1", | ||
386 | "Analog2", "Both"}; | ||
387 | |||
388 | static const struct soc_enum uda134x_mixer_enum[] = { | ||
389 | SOC_ENUM_SINGLE(UDA134X_DATA010, 0, 0x04, uda134x_dsp_setting), | ||
390 | SOC_ENUM_SINGLE(UDA134X_DATA010, 3, 0x04, uda134x_deemph), | ||
391 | SOC_ENUM_SINGLE(UDA134X_EA010, 0, 0x04, uda134x_mixmode), | ||
392 | }; | ||
393 | |||
394 | static const struct snd_kcontrol_new uda1341_snd_controls[] = { | ||
395 | SOC_SINGLE("Master Playback Volume", UDA134X_DATA000, 0, 0x3F, 1), | ||
396 | SOC_SINGLE("Capture Volume", UDA134X_EA010, 2, 0x07, 0), | ||
397 | SOC_SINGLE("Analog1 Volume", UDA134X_EA000, 0, 0x1F, 1), | ||
398 | SOC_SINGLE("Analog2 Volume", UDA134X_EA001, 0, 0x1F, 1), | ||
399 | |||
400 | SOC_SINGLE("Mic Sensitivity", UDA134X_EA010, 2, 7, 0), | ||
401 | SOC_SINGLE("Mic Volume", UDA134X_EA101, 0, 0x1F, 0), | ||
402 | |||
403 | SOC_SINGLE("Tone Control - Bass", UDA134X_DATA001, 2, 0xF, 0), | ||
404 | SOC_SINGLE("Tone Control - Treble", UDA134X_DATA001, 0, 3, 0), | ||
405 | |||
406 | SOC_ENUM("Sound Processing Filter", uda134x_mixer_enum[0]), | ||
407 | SOC_ENUM("PCM Playback De-emphasis", uda134x_mixer_enum[1]), | ||
408 | SOC_ENUM("Input Mux", uda134x_mixer_enum[2]), | ||
409 | |||
410 | SOC_SINGLE("AGC Switch", UDA134X_EA100, 4, 1, 0), | ||
411 | SOC_SINGLE("AGC Target Volume", UDA134X_EA110, 0, 0x03, 1), | ||
412 | SOC_SINGLE("AGC Timing", UDA134X_EA110, 2, 0x07, 0), | ||
413 | |||
414 | SOC_SINGLE("DAC +6dB Switch", UDA134X_STATUS1, 6, 1, 0), | ||
415 | SOC_SINGLE("ADC +6dB Switch", UDA134X_STATUS1, 5, 1, 0), | ||
416 | SOC_SINGLE("ADC Polarity Switch", UDA134X_STATUS1, 4, 1, 0), | ||
417 | SOC_SINGLE("DAC Polarity Switch", UDA134X_STATUS1, 3, 1, 0), | ||
418 | SOC_SINGLE("Double Speed Playback Switch", UDA134X_STATUS1, 2, 1, 0), | ||
419 | SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0), | ||
420 | }; | ||
421 | |||
422 | static const struct snd_kcontrol_new uda1340_snd_controls[] = { | ||
423 | SOC_SINGLE("Master Playback Volume", UDA134X_DATA000, 0, 0x3F, 1), | ||
424 | |||
425 | SOC_SINGLE("Tone Control - Bass", UDA134X_DATA001, 2, 0xF, 0), | ||
426 | SOC_SINGLE("Tone Control - Treble", UDA134X_DATA001, 0, 3, 0), | ||
427 | |||
428 | SOC_ENUM("Sound Processing Filter", uda134x_mixer_enum[0]), | ||
429 | SOC_ENUM("PCM Playback De-emphasis", uda134x_mixer_enum[1]), | ||
430 | |||
431 | SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0), | ||
432 | }; | ||
433 | |||
434 | static int uda134x_add_controls(struct snd_soc_codec *codec) | ||
435 | { | ||
436 | int err, i, n; | ||
437 | const struct snd_kcontrol_new *ctrls; | ||
438 | struct uda134x_platform_data *pd = codec->control_data; | ||
439 | |||
440 | switch (pd->model) { | ||
441 | case UDA134X_UDA1340: | ||
442 | case UDA134X_UDA1344: | ||
443 | n = ARRAY_SIZE(uda1340_snd_controls); | ||
444 | ctrls = uda1340_snd_controls; | ||
445 | break; | ||
446 | case UDA134X_UDA1341: | ||
447 | n = ARRAY_SIZE(uda1341_snd_controls); | ||
448 | ctrls = uda1341_snd_controls; | ||
449 | break; | ||
450 | default: | ||
451 | printk(KERN_ERR "%s unkown codec type: %d", | ||
452 | __func__, pd->model); | ||
453 | return -EINVAL; | ||
454 | } | ||
455 | |||
456 | for (i = 0; i < n; i++) { | ||
457 | err = snd_ctl_add(codec->card, | ||
458 | snd_soc_cnew(&ctrls[i], | ||
459 | codec, NULL)); | ||
460 | if (err < 0) | ||
461 | return err; | ||
462 | } | ||
463 | |||
464 | return 0; | ||
465 | } | ||
466 | |||
467 | struct snd_soc_dai uda134x_dai = { | ||
468 | .name = "UDA134X", | ||
469 | /* playback capabilities */ | ||
470 | .playback = { | ||
471 | .stream_name = "Playback", | ||
472 | .channels_min = 1, | ||
473 | .channels_max = 2, | ||
474 | .rates = UDA134X_RATES, | ||
475 | .formats = UDA134X_FORMATS, | ||
476 | }, | ||
477 | /* capture capabilities */ | ||
478 | .capture = { | ||
479 | .stream_name = "Capture", | ||
480 | .channels_min = 1, | ||
481 | .channels_max = 2, | ||
482 | .rates = UDA134X_RATES, | ||
483 | .formats = UDA134X_FORMATS, | ||
484 | }, | ||
485 | /* pcm operations */ | ||
486 | .ops = { | ||
487 | .startup = uda134x_startup, | ||
488 | .shutdown = uda134x_shutdown, | ||
489 | .hw_params = uda134x_hw_params, | ||
490 | .digital_mute = uda134x_mute, | ||
491 | .set_sysclk = uda134x_set_dai_sysclk, | ||
492 | .set_fmt = uda134x_set_dai_fmt, | ||
493 | } | ||
494 | }; | ||
495 | EXPORT_SYMBOL(uda134x_dai); | ||
496 | |||
497 | |||
498 | static int uda134x_soc_probe(struct platform_device *pdev) | ||
499 | { | ||
500 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
501 | struct snd_soc_codec *codec; | ||
502 | struct uda134x_priv *uda134x; | ||
503 | void *codec_setup_data = socdev->codec_data; | ||
504 | int ret = -ENOMEM; | ||
505 | struct uda134x_platform_data *pd; | ||
506 | |||
507 | printk(KERN_INFO "UDA134X SoC Audio Codec\n"); | ||
508 | |||
509 | if (!codec_setup_data) { | ||
510 | printk(KERN_ERR "UDA134X SoC codec: " | ||
511 | "missing L3 bitbang function\n"); | ||
512 | return -ENODEV; | ||
513 | } | ||
514 | |||
515 | pd = codec_setup_data; | ||
516 | switch (pd->model) { | ||
517 | case UDA134X_UDA1340: | ||
518 | case UDA134X_UDA1341: | ||
519 | case UDA134X_UDA1344: | ||
520 | break; | ||
521 | default: | ||
522 | printk(KERN_ERR "UDA134X SoC codec: " | ||
523 | "unsupported model %d\n", | ||
524 | pd->model); | ||
525 | return -EINVAL; | ||
526 | } | ||
527 | |||
528 | socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | ||
529 | if (socdev->codec == NULL) | ||
530 | return ret; | ||
531 | |||
532 | codec = socdev->codec; | ||
533 | |||
534 | uda134x = kzalloc(sizeof(struct uda134x_priv), GFP_KERNEL); | ||
535 | if (uda134x == NULL) | ||
536 | goto priv_err; | ||
537 | codec->private_data = uda134x; | ||
538 | |||
539 | codec->reg_cache = kmemdup(uda134x_reg, sizeof(uda134x_reg), | ||
540 | GFP_KERNEL); | ||
541 | if (codec->reg_cache == NULL) | ||
542 | goto reg_err; | ||
543 | |||
544 | mutex_init(&codec->mutex); | ||
545 | |||
546 | codec->reg_cache_size = sizeof(uda134x_reg); | ||
547 | codec->reg_cache_step = 1; | ||
548 | |||
549 | codec->name = "UDA134X"; | ||
550 | codec->owner = THIS_MODULE; | ||
551 | codec->dai = &uda134x_dai; | ||
552 | codec->num_dai = 1; | ||
553 | codec->read = uda134x_read_reg_cache; | ||
554 | codec->write = uda134x_write; | ||
555 | #ifdef POWER_OFF_ON_STANDBY | ||
556 | codec->set_bias_level = uda134x_set_bias_level; | ||
557 | #endif | ||
558 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
559 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
560 | |||
561 | codec->control_data = codec_setup_data; | ||
562 | |||
563 | if (pd->power) | ||
564 | pd->power(1); | ||
565 | |||
566 | uda134x_reset(codec); | ||
567 | |||
568 | /* register pcms */ | ||
569 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
570 | if (ret < 0) { | ||
571 | printk(KERN_ERR "UDA134X: failed to register pcms\n"); | ||
572 | goto pcm_err; | ||
573 | } | ||
574 | |||
575 | ret = uda134x_add_controls(codec); | ||
576 | if (ret < 0) { | ||
577 | printk(KERN_ERR "UDA134X: failed to register controls\n"); | ||
578 | goto pcm_err; | ||
579 | } | ||
580 | |||
581 | ret = snd_soc_init_card(socdev); | ||
582 | if (ret < 0) { | ||
583 | printk(KERN_ERR "UDA134X: failed to register card\n"); | ||
584 | goto card_err; | ||
585 | } | ||
586 | |||
587 | return 0; | ||
588 | |||
589 | card_err: | ||
590 | snd_soc_free_pcms(socdev); | ||
591 | snd_soc_dapm_free(socdev); | ||
592 | pcm_err: | ||
593 | kfree(codec->reg_cache); | ||
594 | reg_err: | ||
595 | kfree(codec->private_data); | ||
596 | priv_err: | ||
597 | kfree(codec); | ||
598 | return ret; | ||
599 | } | ||
600 | |||
601 | /* power down chip */ | ||
602 | static int uda134x_soc_remove(struct platform_device *pdev) | ||
603 | { | ||
604 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
605 | struct snd_soc_codec *codec = socdev->codec; | ||
606 | |||
607 | uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
608 | uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
609 | |||
610 | snd_soc_free_pcms(socdev); | ||
611 | snd_soc_dapm_free(socdev); | ||
612 | |||
613 | kfree(codec->private_data); | ||
614 | kfree(codec->reg_cache); | ||
615 | kfree(codec); | ||
616 | |||
617 | return 0; | ||
618 | } | ||
619 | |||
620 | #if defined(CONFIG_PM) | ||
621 | static int uda134x_soc_suspend(struct platform_device *pdev, | ||
622 | pm_message_t state) | ||
623 | { | ||
624 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
625 | struct snd_soc_codec *codec = socdev->codec; | ||
626 | |||
627 | uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
628 | uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
629 | return 0; | ||
630 | } | ||
631 | |||
632 | static int uda134x_soc_resume(struct platform_device *pdev) | ||
633 | { | ||
634 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
635 | struct snd_soc_codec *codec = socdev->codec; | ||
636 | |||
637 | uda134x_set_bias_level(codec, SND_SOC_BIAS_PREPARE); | ||
638 | uda134x_set_bias_level(codec, SND_SOC_BIAS_ON); | ||
639 | return 0; | ||
640 | } | ||
641 | #else | ||
642 | #define uda134x_soc_suspend NULL | ||
643 | #define uda134x_soc_resume NULL | ||
644 | #endif /* CONFIG_PM */ | ||
645 | |||
646 | struct snd_soc_codec_device soc_codec_dev_uda134x = { | ||
647 | .probe = uda134x_soc_probe, | ||
648 | .remove = uda134x_soc_remove, | ||
649 | .suspend = uda134x_soc_suspend, | ||
650 | .resume = uda134x_soc_resume, | ||
651 | }; | ||
652 | EXPORT_SYMBOL_GPL(soc_codec_dev_uda134x); | ||
653 | |||
654 | static int __init uda134x_init(void) | ||
655 | { | ||
656 | return snd_soc_register_dai(&uda134x_dai); | ||
657 | } | ||
658 | module_init(uda134x_init); | ||
659 | |||
660 | static void __exit uda134x_exit(void) | ||
661 | { | ||
662 | snd_soc_unregister_dai(&uda134x_dai); | ||
663 | } | ||
664 | module_exit(uda134x_exit); | ||
665 | |||
666 | MODULE_DESCRIPTION("UDA134X ALSA soc codec driver"); | ||
667 | MODULE_AUTHOR("Zoltan Devai, Christian Pellegrin <chripell@evolware.org>"); | ||
668 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/uda134x.h b/sound/soc/codecs/uda134x.h new file mode 100644 index 000000000000..94f440490b31 --- /dev/null +++ b/sound/soc/codecs/uda134x.h | |||
@@ -0,0 +1,36 @@ | |||
1 | #ifndef _UDA134X_CODEC_H | ||
2 | #define _UDA134X_CODEC_H | ||
3 | |||
4 | #define UDA134X_L3ADDR 5 | ||
5 | #define UDA134X_DATA0_ADDR ((UDA134X_L3ADDR << 2) | 0) | ||
6 | #define UDA134X_DATA1_ADDR ((UDA134X_L3ADDR << 2) | 1) | ||
7 | #define UDA134X_STATUS_ADDR ((UDA134X_L3ADDR << 2) | 2) | ||
8 | |||
9 | #define UDA134X_EXTADDR_PREFIX 0xC0 | ||
10 | #define UDA134X_EXTDATA_PREFIX 0xE0 | ||
11 | |||
12 | /* UDA134X registers */ | ||
13 | #define UDA134X_EA000 0 | ||
14 | #define UDA134X_EA001 1 | ||
15 | #define UDA134X_EA010 2 | ||
16 | #define UDA134X_EA011 3 | ||
17 | #define UDA134X_EA100 4 | ||
18 | #define UDA134X_EA101 5 | ||
19 | #define UDA134X_EA110 6 | ||
20 | #define UDA134X_EA111 7 | ||
21 | #define UDA134X_STATUS0 8 | ||
22 | #define UDA134X_STATUS1 9 | ||
23 | #define UDA134X_DATA000 10 | ||
24 | #define UDA134X_DATA001 11 | ||
25 | #define UDA134X_DATA010 12 | ||
26 | #define UDA134X_DATA1 13 | ||
27 | |||
28 | #define UDA134X_REGS_NUM 14 | ||
29 | |||
30 | #define STATUS0_DAIFMT_MASK (~(7<<1)) | ||
31 | #define STATUS0_SYSCLK_MASK (~(3<<4)) | ||
32 | |||
33 | extern struct snd_soc_dai uda134x_dai; | ||
34 | extern struct snd_soc_codec_device soc_codec_dev_uda134x; | ||
35 | |||
36 | #endif | ||
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c index a69ee72a7af5..e6bf0844fbf3 100644 --- a/sound/soc/codecs/uda1380.c +++ b/sound/soc/codecs/uda1380.c | |||
@@ -407,7 +407,8 @@ static int uda1380_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
407 | * when the DAI is being clocked by the CPU DAI. It's up to the | 407 | * when the DAI is being clocked by the CPU DAI. It's up to the |
408 | * machine and cpu DAI driver to do this before we are called. | 408 | * machine and cpu DAI driver to do this before we are called. |
409 | */ | 409 | */ |
410 | static int uda1380_pcm_prepare(struct snd_pcm_substream *substream) | 410 | static int uda1380_pcm_prepare(struct snd_pcm_substream *substream, |
411 | struct snd_soc_dai *dai) | ||
411 | { | 412 | { |
412 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 413 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
413 | struct snd_soc_device *socdev = rtd->socdev; | 414 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -439,7 +440,8 @@ static int uda1380_pcm_prepare(struct snd_pcm_substream *substream) | |||
439 | } | 440 | } |
440 | 441 | ||
441 | static int uda1380_pcm_hw_params(struct snd_pcm_substream *substream, | 442 | static int uda1380_pcm_hw_params(struct snd_pcm_substream *substream, |
442 | struct snd_pcm_hw_params *params) | 443 | struct snd_pcm_hw_params *params, |
444 | struct snd_soc_dai *dai) | ||
443 | { | 445 | { |
444 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 446 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
445 | struct snd_soc_device *socdev = rtd->socdev; | 447 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -477,7 +479,8 @@ static int uda1380_pcm_hw_params(struct snd_pcm_substream *substream, | |||
477 | return 0; | 479 | return 0; |
478 | } | 480 | } |
479 | 481 | ||
480 | static void uda1380_pcm_shutdown(struct snd_pcm_substream *substream) | 482 | static void uda1380_pcm_shutdown(struct snd_pcm_substream *substream, |
483 | struct snd_soc_dai *dai) | ||
481 | { | 484 | { |
482 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 485 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
483 | struct snd_soc_device *socdev = rtd->socdev; | 486 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -560,8 +563,6 @@ struct snd_soc_dai uda1380_dai[] = { | |||
560 | .hw_params = uda1380_pcm_hw_params, | 563 | .hw_params = uda1380_pcm_hw_params, |
561 | .shutdown = uda1380_pcm_shutdown, | 564 | .shutdown = uda1380_pcm_shutdown, |
562 | .prepare = uda1380_pcm_prepare, | 565 | .prepare = uda1380_pcm_prepare, |
563 | }, | ||
564 | .dai_ops = { | ||
565 | .digital_mute = uda1380_mute, | 566 | .digital_mute = uda1380_mute, |
566 | .set_fmt = uda1380_set_dai_fmt, | 567 | .set_fmt = uda1380_set_dai_fmt, |
567 | }, | 568 | }, |
@@ -579,8 +580,6 @@ struct snd_soc_dai uda1380_dai[] = { | |||
579 | .hw_params = uda1380_pcm_hw_params, | 580 | .hw_params = uda1380_pcm_hw_params, |
580 | .shutdown = uda1380_pcm_shutdown, | 581 | .shutdown = uda1380_pcm_shutdown, |
581 | .prepare = uda1380_pcm_prepare, | 582 | .prepare = uda1380_pcm_prepare, |
582 | }, | ||
583 | .dai_ops = { | ||
584 | .digital_mute = uda1380_mute, | 583 | .digital_mute = uda1380_mute, |
585 | .set_fmt = uda1380_set_dai_fmt, | 584 | .set_fmt = uda1380_set_dai_fmt, |
586 | }, | 585 | }, |
@@ -598,8 +597,6 @@ struct snd_soc_dai uda1380_dai[] = { | |||
598 | .hw_params = uda1380_pcm_hw_params, | 597 | .hw_params = uda1380_pcm_hw_params, |
599 | .shutdown = uda1380_pcm_shutdown, | 598 | .shutdown = uda1380_pcm_shutdown, |
600 | .prepare = uda1380_pcm_prepare, | 599 | .prepare = uda1380_pcm_prepare, |
601 | }, | ||
602 | .dai_ops = { | ||
603 | .set_fmt = uda1380_set_dai_fmt, | 600 | .set_fmt = uda1380_set_dai_fmt, |
604 | }, | 601 | }, |
605 | }, | 602 | }, |
@@ -680,7 +677,7 @@ static int uda1380_init(struct snd_soc_device *socdev, int dac_clk) | |||
680 | /* uda1380 init */ | 677 | /* uda1380 init */ |
681 | uda1380_add_controls(codec); | 678 | uda1380_add_controls(codec); |
682 | uda1380_add_widgets(codec); | 679 | uda1380_add_widgets(codec); |
683 | ret = snd_soc_register_card(socdev); | 680 | ret = snd_soc_init_card(socdev); |
684 | if (ret < 0) { | 681 | if (ret < 0) { |
685 | pr_err("uda1380: failed to register card\n"); | 682 | pr_err("uda1380: failed to register card\n"); |
686 | goto card_err; | 683 | goto card_err; |
@@ -844,6 +841,18 @@ struct snd_soc_codec_device soc_codec_dev_uda1380 = { | |||
844 | }; | 841 | }; |
845 | EXPORT_SYMBOL_GPL(soc_codec_dev_uda1380); | 842 | EXPORT_SYMBOL_GPL(soc_codec_dev_uda1380); |
846 | 843 | ||
844 | static int __init uda1380_modinit(void) | ||
845 | { | ||
846 | return snd_soc_register_dais(uda1380_dai, ARRAY_SIZE(uda1380_dai)); | ||
847 | } | ||
848 | module_init(uda1380_modinit); | ||
849 | |||
850 | static void __exit uda1380_exit(void) | ||
851 | { | ||
852 | snd_soc_unregister_dais(uda1380_dai, ARRAY_SIZE(uda1380_dai)); | ||
853 | } | ||
854 | module_exit(uda1380_exit); | ||
855 | |||
847 | MODULE_AUTHOR("Giorgio Padrin"); | 856 | MODULE_AUTHOR("Giorgio Padrin"); |
848 | MODULE_DESCRIPTION("Audio support for codec Philips UDA1380"); | 857 | MODULE_DESCRIPTION("Audio support for codec Philips UDA1380"); |
849 | MODULE_LICENSE("GPL"); | 858 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c new file mode 100644 index 000000000000..e3989d406f54 --- /dev/null +++ b/sound/soc/codecs/wm8350.c | |||
@@ -0,0 +1,1583 @@ | |||
1 | /* | ||
2 | * wm8350.c -- WM8350 ALSA SoC audio driver | ||
3 | * | ||
4 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
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 | #include <linux/module.h> | ||
14 | #include <linux/moduleparam.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/delay.h> | ||
17 | #include <linux/pm.h> | ||
18 | #include <linux/platform_device.h> | ||
19 | #include <linux/mfd/wm8350/audio.h> | ||
20 | #include <linux/mfd/wm8350/core.h> | ||
21 | #include <linux/regulator/consumer.h> | ||
22 | #include <sound/core.h> | ||
23 | #include <sound/pcm.h> | ||
24 | #include <sound/pcm_params.h> | ||
25 | #include <sound/soc.h> | ||
26 | #include <sound/soc-dapm.h> | ||
27 | #include <sound/initval.h> | ||
28 | #include <sound/tlv.h> | ||
29 | |||
30 | #include "wm8350.h" | ||
31 | |||
32 | #define WM8350_OUTn_0dB 0x39 | ||
33 | |||
34 | #define WM8350_RAMP_NONE 0 | ||
35 | #define WM8350_RAMP_UP 1 | ||
36 | #define WM8350_RAMP_DOWN 2 | ||
37 | |||
38 | /* We only include the analogue supplies here; the digital supplies | ||
39 | * need to be available well before this driver can be probed. | ||
40 | */ | ||
41 | static const char *supply_names[] = { | ||
42 | "AVDD", | ||
43 | "HPVDD", | ||
44 | }; | ||
45 | |||
46 | struct wm8350_output { | ||
47 | u16 active; | ||
48 | u16 left_vol; | ||
49 | u16 right_vol; | ||
50 | u16 ramp; | ||
51 | u16 mute; | ||
52 | }; | ||
53 | |||
54 | struct wm8350_data { | ||
55 | struct snd_soc_codec codec; | ||
56 | struct wm8350_output out1; | ||
57 | struct wm8350_output out2; | ||
58 | struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; | ||
59 | }; | ||
60 | |||
61 | static unsigned int wm8350_codec_cache_read(struct snd_soc_codec *codec, | ||
62 | unsigned int reg) | ||
63 | { | ||
64 | struct wm8350 *wm8350 = codec->control_data; | ||
65 | return wm8350->reg_cache[reg]; | ||
66 | } | ||
67 | |||
68 | static unsigned int wm8350_codec_read(struct snd_soc_codec *codec, | ||
69 | unsigned int reg) | ||
70 | { | ||
71 | struct wm8350 *wm8350 = codec->control_data; | ||
72 | return wm8350_reg_read(wm8350, reg); | ||
73 | } | ||
74 | |||
75 | static int wm8350_codec_write(struct snd_soc_codec *codec, unsigned int reg, | ||
76 | unsigned int value) | ||
77 | { | ||
78 | struct wm8350 *wm8350 = codec->control_data; | ||
79 | return wm8350_reg_write(wm8350, reg, value); | ||
80 | } | ||
81 | |||
82 | /* | ||
83 | * Ramp OUT1 PGA volume to minimise pops at stream startup and shutdown. | ||
84 | */ | ||
85 | static inline int wm8350_out1_ramp_step(struct snd_soc_codec *codec) | ||
86 | { | ||
87 | struct wm8350_data *wm8350_data = codec->private_data; | ||
88 | struct wm8350_output *out1 = &wm8350_data->out1; | ||
89 | struct wm8350 *wm8350 = codec->control_data; | ||
90 | int left_complete = 0, right_complete = 0; | ||
91 | u16 reg, val; | ||
92 | |||
93 | /* left channel */ | ||
94 | reg = wm8350_reg_read(wm8350, WM8350_LOUT1_VOLUME); | ||
95 | val = (reg & WM8350_OUT1L_VOL_MASK) >> WM8350_OUT1L_VOL_SHIFT; | ||
96 | |||
97 | if (out1->ramp == WM8350_RAMP_UP) { | ||
98 | /* ramp step up */ | ||
99 | if (val < out1->left_vol) { | ||
100 | val++; | ||
101 | reg &= ~WM8350_OUT1L_VOL_MASK; | ||
102 | wm8350_reg_write(wm8350, WM8350_LOUT1_VOLUME, | ||
103 | reg | (val << WM8350_OUT1L_VOL_SHIFT)); | ||
104 | } else | ||
105 | left_complete = 1; | ||
106 | } else if (out1->ramp == WM8350_RAMP_DOWN) { | ||
107 | /* ramp step down */ | ||
108 | if (val > 0) { | ||
109 | val--; | ||
110 | reg &= ~WM8350_OUT1L_VOL_MASK; | ||
111 | wm8350_reg_write(wm8350, WM8350_LOUT1_VOLUME, | ||
112 | reg | (val << WM8350_OUT1L_VOL_SHIFT)); | ||
113 | } else | ||
114 | left_complete = 1; | ||
115 | } else | ||
116 | return 1; | ||
117 | |||
118 | /* right channel */ | ||
119 | reg = wm8350_reg_read(wm8350, WM8350_ROUT1_VOLUME); | ||
120 | val = (reg & WM8350_OUT1R_VOL_MASK) >> WM8350_OUT1R_VOL_SHIFT; | ||
121 | if (out1->ramp == WM8350_RAMP_UP) { | ||
122 | /* ramp step up */ | ||
123 | if (val < out1->right_vol) { | ||
124 | val++; | ||
125 | reg &= ~WM8350_OUT1R_VOL_MASK; | ||
126 | wm8350_reg_write(wm8350, WM8350_ROUT1_VOLUME, | ||
127 | reg | (val << WM8350_OUT1R_VOL_SHIFT)); | ||
128 | } else | ||
129 | right_complete = 1; | ||
130 | } else if (out1->ramp == WM8350_RAMP_DOWN) { | ||
131 | /* ramp step down */ | ||
132 | if (val > 0) { | ||
133 | val--; | ||
134 | reg &= ~WM8350_OUT1R_VOL_MASK; | ||
135 | wm8350_reg_write(wm8350, WM8350_ROUT1_VOLUME, | ||
136 | reg | (val << WM8350_OUT1R_VOL_SHIFT)); | ||
137 | } else | ||
138 | right_complete = 1; | ||
139 | } | ||
140 | |||
141 | /* only hit the update bit if either volume has changed this step */ | ||
142 | if (!left_complete || !right_complete) | ||
143 | wm8350_set_bits(wm8350, WM8350_LOUT1_VOLUME, WM8350_OUT1_VU); | ||
144 | |||
145 | return left_complete & right_complete; | ||
146 | } | ||
147 | |||
148 | /* | ||
149 | * Ramp OUT2 PGA volume to minimise pops at stream startup and shutdown. | ||
150 | */ | ||
151 | static inline int wm8350_out2_ramp_step(struct snd_soc_codec *codec) | ||
152 | { | ||
153 | struct wm8350_data *wm8350_data = codec->private_data; | ||
154 | struct wm8350_output *out2 = &wm8350_data->out2; | ||
155 | struct wm8350 *wm8350 = codec->control_data; | ||
156 | int left_complete = 0, right_complete = 0; | ||
157 | u16 reg, val; | ||
158 | |||
159 | /* left channel */ | ||
160 | reg = wm8350_reg_read(wm8350, WM8350_LOUT2_VOLUME); | ||
161 | val = (reg & WM8350_OUT2L_VOL_MASK) >> WM8350_OUT1L_VOL_SHIFT; | ||
162 | if (out2->ramp == WM8350_RAMP_UP) { | ||
163 | /* ramp step up */ | ||
164 | if (val < out2->left_vol) { | ||
165 | val++; | ||
166 | reg &= ~WM8350_OUT2L_VOL_MASK; | ||
167 | wm8350_reg_write(wm8350, WM8350_LOUT2_VOLUME, | ||
168 | reg | (val << WM8350_OUT1L_VOL_SHIFT)); | ||
169 | } else | ||
170 | left_complete = 1; | ||
171 | } else if (out2->ramp == WM8350_RAMP_DOWN) { | ||
172 | /* ramp step down */ | ||
173 | if (val > 0) { | ||
174 | val--; | ||
175 | reg &= ~WM8350_OUT2L_VOL_MASK; | ||
176 | wm8350_reg_write(wm8350, WM8350_LOUT2_VOLUME, | ||
177 | reg | (val << WM8350_OUT1L_VOL_SHIFT)); | ||
178 | } else | ||
179 | left_complete = 1; | ||
180 | } else | ||
181 | return 1; | ||
182 | |||
183 | /* right channel */ | ||
184 | reg = wm8350_reg_read(wm8350, WM8350_ROUT2_VOLUME); | ||
185 | val = (reg & WM8350_OUT2R_VOL_MASK) >> WM8350_OUT1R_VOL_SHIFT; | ||
186 | if (out2->ramp == WM8350_RAMP_UP) { | ||
187 | /* ramp step up */ | ||
188 | if (val < out2->right_vol) { | ||
189 | val++; | ||
190 | reg &= ~WM8350_OUT2R_VOL_MASK; | ||
191 | wm8350_reg_write(wm8350, WM8350_ROUT2_VOLUME, | ||
192 | reg | (val << WM8350_OUT1R_VOL_SHIFT)); | ||
193 | } else | ||
194 | right_complete = 1; | ||
195 | } else if (out2->ramp == WM8350_RAMP_DOWN) { | ||
196 | /* ramp step down */ | ||
197 | if (val > 0) { | ||
198 | val--; | ||
199 | reg &= ~WM8350_OUT2R_VOL_MASK; | ||
200 | wm8350_reg_write(wm8350, WM8350_ROUT2_VOLUME, | ||
201 | reg | (val << WM8350_OUT1R_VOL_SHIFT)); | ||
202 | } else | ||
203 | right_complete = 1; | ||
204 | } | ||
205 | |||
206 | /* only hit the update bit if either volume has changed this step */ | ||
207 | if (!left_complete || !right_complete) | ||
208 | wm8350_set_bits(wm8350, WM8350_LOUT2_VOLUME, WM8350_OUT2_VU); | ||
209 | |||
210 | return left_complete & right_complete; | ||
211 | } | ||
212 | |||
213 | /* | ||
214 | * This work ramps both output PGAs at stream start/stop time to | ||
215 | * minimise pop associated with DAPM power switching. | ||
216 | * It's best to enable Zero Cross when ramping occurs to minimise any | ||
217 | * zipper noises. | ||
218 | */ | ||
219 | static void wm8350_pga_work(struct work_struct *work) | ||
220 | { | ||
221 | struct snd_soc_codec *codec = | ||
222 | container_of(work, struct snd_soc_codec, delayed_work.work); | ||
223 | struct wm8350_data *wm8350_data = codec->private_data; | ||
224 | struct wm8350_output *out1 = &wm8350_data->out1, | ||
225 | *out2 = &wm8350_data->out2; | ||
226 | int i, out1_complete, out2_complete; | ||
227 | |||
228 | /* do we need to ramp at all ? */ | ||
229 | if (out1->ramp == WM8350_RAMP_NONE && out2->ramp == WM8350_RAMP_NONE) | ||
230 | return; | ||
231 | |||
232 | /* PGA volumes have 6 bits of resolution to ramp */ | ||
233 | for (i = 0; i <= 63; i++) { | ||
234 | out1_complete = 1, out2_complete = 1; | ||
235 | if (out1->ramp != WM8350_RAMP_NONE) | ||
236 | out1_complete = wm8350_out1_ramp_step(codec); | ||
237 | if (out2->ramp != WM8350_RAMP_NONE) | ||
238 | out2_complete = wm8350_out2_ramp_step(codec); | ||
239 | |||
240 | /* ramp finished ? */ | ||
241 | if (out1_complete && out2_complete) | ||
242 | break; | ||
243 | |||
244 | /* we need to delay longer on the up ramp */ | ||
245 | if (out1->ramp == WM8350_RAMP_UP || | ||
246 | out2->ramp == WM8350_RAMP_UP) { | ||
247 | /* delay is longer over 0dB as increases are larger */ | ||
248 | if (i >= WM8350_OUTn_0dB) | ||
249 | schedule_timeout_interruptible(msecs_to_jiffies | ||
250 | (2)); | ||
251 | else | ||
252 | schedule_timeout_interruptible(msecs_to_jiffies | ||
253 | (1)); | ||
254 | } else | ||
255 | udelay(50); /* doesn't matter if we delay longer */ | ||
256 | } | ||
257 | |||
258 | out1->ramp = WM8350_RAMP_NONE; | ||
259 | out2->ramp = WM8350_RAMP_NONE; | ||
260 | } | ||
261 | |||
262 | /* | ||
263 | * WM8350 Controls | ||
264 | */ | ||
265 | |||
266 | static int pga_event(struct snd_soc_dapm_widget *w, | ||
267 | struct snd_kcontrol *kcontrol, int event) | ||
268 | { | ||
269 | struct snd_soc_codec *codec = w->codec; | ||
270 | struct wm8350_data *wm8350_data = codec->private_data; | ||
271 | struct wm8350_output *out; | ||
272 | |||
273 | switch (w->shift) { | ||
274 | case 0: | ||
275 | case 1: | ||
276 | out = &wm8350_data->out1; | ||
277 | break; | ||
278 | case 2: | ||
279 | case 3: | ||
280 | out = &wm8350_data->out2; | ||
281 | break; | ||
282 | |||
283 | default: | ||
284 | BUG(); | ||
285 | return -1; | ||
286 | } | ||
287 | |||
288 | switch (event) { | ||
289 | case SND_SOC_DAPM_POST_PMU: | ||
290 | out->ramp = WM8350_RAMP_UP; | ||
291 | out->active = 1; | ||
292 | |||
293 | if (!delayed_work_pending(&codec->delayed_work)) | ||
294 | schedule_delayed_work(&codec->delayed_work, | ||
295 | msecs_to_jiffies(1)); | ||
296 | break; | ||
297 | |||
298 | case SND_SOC_DAPM_PRE_PMD: | ||
299 | out->ramp = WM8350_RAMP_DOWN; | ||
300 | out->active = 0; | ||
301 | |||
302 | if (!delayed_work_pending(&codec->delayed_work)) | ||
303 | schedule_delayed_work(&codec->delayed_work, | ||
304 | msecs_to_jiffies(1)); | ||
305 | break; | ||
306 | } | ||
307 | |||
308 | return 0; | ||
309 | } | ||
310 | |||
311 | static int wm8350_put_volsw_2r_vu(struct snd_kcontrol *kcontrol, | ||
312 | struct snd_ctl_elem_value *ucontrol) | ||
313 | { | ||
314 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
315 | struct wm8350_data *wm8350_priv = codec->private_data; | ||
316 | struct wm8350_output *out = NULL; | ||
317 | struct soc_mixer_control *mc = | ||
318 | (struct soc_mixer_control *)kcontrol->private_value; | ||
319 | int ret; | ||
320 | unsigned int reg = mc->reg; | ||
321 | u16 val; | ||
322 | |||
323 | /* For OUT1 and OUT2 we shadow the values and only actually write | ||
324 | * them out when active in order to ensure the amplifier comes on | ||
325 | * as quietly as possible. */ | ||
326 | switch (reg) { | ||
327 | case WM8350_LOUT1_VOLUME: | ||
328 | out = &wm8350_priv->out1; | ||
329 | break; | ||
330 | case WM8350_LOUT2_VOLUME: | ||
331 | out = &wm8350_priv->out2; | ||
332 | break; | ||
333 | default: | ||
334 | break; | ||
335 | } | ||
336 | |||
337 | if (out) { | ||
338 | out->left_vol = ucontrol->value.integer.value[0]; | ||
339 | out->right_vol = ucontrol->value.integer.value[1]; | ||
340 | if (!out->active) | ||
341 | return 1; | ||
342 | } | ||
343 | |||
344 | ret = snd_soc_put_volsw_2r(kcontrol, ucontrol); | ||
345 | if (ret < 0) | ||
346 | return ret; | ||
347 | |||
348 | /* now hit the volume update bits (always bit 8) */ | ||
349 | val = wm8350_codec_read(codec, reg); | ||
350 | wm8350_codec_write(codec, reg, val | WM8350_OUT1_VU); | ||
351 | return 1; | ||
352 | } | ||
353 | |||
354 | static int wm8350_get_volsw_2r(struct snd_kcontrol *kcontrol, | ||
355 | struct snd_ctl_elem_value *ucontrol) | ||
356 | { | ||
357 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
358 | struct wm8350_data *wm8350_priv = codec->private_data; | ||
359 | struct wm8350_output *out1 = &wm8350_priv->out1; | ||
360 | struct wm8350_output *out2 = &wm8350_priv->out2; | ||
361 | struct soc_mixer_control *mc = | ||
362 | (struct soc_mixer_control *)kcontrol->private_value; | ||
363 | unsigned int reg = mc->reg; | ||
364 | |||
365 | /* If these are cached registers use the cache */ | ||
366 | switch (reg) { | ||
367 | case WM8350_LOUT1_VOLUME: | ||
368 | ucontrol->value.integer.value[0] = out1->left_vol; | ||
369 | ucontrol->value.integer.value[1] = out1->right_vol; | ||
370 | return 0; | ||
371 | |||
372 | case WM8350_LOUT2_VOLUME: | ||
373 | ucontrol->value.integer.value[0] = out2->left_vol; | ||
374 | ucontrol->value.integer.value[1] = out2->right_vol; | ||
375 | return 0; | ||
376 | |||
377 | default: | ||
378 | break; | ||
379 | } | ||
380 | |||
381 | return snd_soc_get_volsw_2r(kcontrol, ucontrol); | ||
382 | } | ||
383 | |||
384 | /* double control with volume update */ | ||
385 | #define SOC_WM8350_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, \ | ||
386 | xinvert, tlv_array) \ | ||
387 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ | ||
388 | .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ | ||
389 | SNDRV_CTL_ELEM_ACCESS_READWRITE | \ | ||
390 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | ||
391 | .tlv.p = (tlv_array), \ | ||
392 | .info = snd_soc_info_volsw_2r, \ | ||
393 | .get = wm8350_get_volsw_2r, .put = wm8350_put_volsw_2r_vu, \ | ||
394 | .private_value = (unsigned long)&(struct soc_mixer_control) \ | ||
395 | {.reg = reg_left, .rreg = reg_right, .shift = xshift, \ | ||
396 | .rshift = xshift, .max = xmax, .invert = xinvert}, } | ||
397 | |||
398 | static const char *wm8350_deemp[] = { "None", "32kHz", "44.1kHz", "48kHz" }; | ||
399 | static const char *wm8350_pol[] = { "Normal", "Inv R", "Inv L", "Inv L & R" }; | ||
400 | static const char *wm8350_dacmutem[] = { "Normal", "Soft" }; | ||
401 | static const char *wm8350_dacmutes[] = { "Fast", "Slow" }; | ||
402 | static const char *wm8350_dacfilter[] = { "Normal", "Sloping" }; | ||
403 | static const char *wm8350_adcfilter[] = { "None", "High Pass" }; | ||
404 | static const char *wm8350_adchp[] = { "44.1kHz", "8kHz", "16kHz", "32kHz" }; | ||
405 | static const char *wm8350_lr[] = { "Left", "Right" }; | ||
406 | |||
407 | static const struct soc_enum wm8350_enum[] = { | ||
408 | SOC_ENUM_SINGLE(WM8350_DAC_CONTROL, 4, 4, wm8350_deemp), | ||
409 | SOC_ENUM_SINGLE(WM8350_DAC_CONTROL, 0, 4, wm8350_pol), | ||
410 | SOC_ENUM_SINGLE(WM8350_DAC_MUTE_VOLUME, 14, 2, wm8350_dacmutem), | ||
411 | SOC_ENUM_SINGLE(WM8350_DAC_MUTE_VOLUME, 13, 2, wm8350_dacmutes), | ||
412 | SOC_ENUM_SINGLE(WM8350_DAC_MUTE_VOLUME, 12, 2, wm8350_dacfilter), | ||
413 | SOC_ENUM_SINGLE(WM8350_ADC_CONTROL, 15, 2, wm8350_adcfilter), | ||
414 | SOC_ENUM_SINGLE(WM8350_ADC_CONTROL, 8, 4, wm8350_adchp), | ||
415 | SOC_ENUM_SINGLE(WM8350_ADC_CONTROL, 0, 4, wm8350_pol), | ||
416 | SOC_ENUM_SINGLE(WM8350_INPUT_MIXER_VOLUME, 15, 2, wm8350_lr), | ||
417 | }; | ||
418 | |||
419 | static DECLARE_TLV_DB_LINEAR(pre_amp_tlv, -1200, 3525); | ||
420 | static DECLARE_TLV_DB_LINEAR(out_pga_tlv, -5700, 600); | ||
421 | static DECLARE_TLV_DB_SCALE(dac_pcm_tlv, -7163, 36, 1); | ||
422 | static DECLARE_TLV_DB_SCALE(adc_pcm_tlv, -12700, 50, 1); | ||
423 | static DECLARE_TLV_DB_SCALE(out_mix_tlv, -1500, 300, 1); | ||
424 | |||
425 | static const unsigned int capture_sd_tlv[] = { | ||
426 | TLV_DB_RANGE_HEAD(2), | ||
427 | 0, 12, TLV_DB_SCALE_ITEM(-3600, 300, 1), | ||
428 | 13, 15, TLV_DB_SCALE_ITEM(0, 0, 0), | ||
429 | }; | ||
430 | |||
431 | static const struct snd_kcontrol_new wm8350_snd_controls[] = { | ||
432 | SOC_ENUM("Playback Deemphasis", wm8350_enum[0]), | ||
433 | SOC_ENUM("Playback DAC Inversion", wm8350_enum[1]), | ||
434 | SOC_WM8350_DOUBLE_R_TLV("Playback PCM Volume", | ||
435 | WM8350_DAC_DIGITAL_VOLUME_L, | ||
436 | WM8350_DAC_DIGITAL_VOLUME_R, | ||
437 | 0, 255, 0, dac_pcm_tlv), | ||
438 | SOC_ENUM("Playback PCM Mute Function", wm8350_enum[2]), | ||
439 | SOC_ENUM("Playback PCM Mute Speed", wm8350_enum[3]), | ||
440 | SOC_ENUM("Playback PCM Filter", wm8350_enum[4]), | ||
441 | SOC_ENUM("Capture PCM Filter", wm8350_enum[5]), | ||
442 | SOC_ENUM("Capture PCM HP Filter", wm8350_enum[6]), | ||
443 | SOC_ENUM("Capture ADC Inversion", wm8350_enum[7]), | ||
444 | SOC_WM8350_DOUBLE_R_TLV("Capture PCM Volume", | ||
445 | WM8350_ADC_DIGITAL_VOLUME_L, | ||
446 | WM8350_ADC_DIGITAL_VOLUME_R, | ||
447 | 0, 255, 0, adc_pcm_tlv), | ||
448 | SOC_DOUBLE_TLV("Capture Sidetone Volume", | ||
449 | WM8350_ADC_DIVIDER, | ||
450 | 8, 4, 15, 1, capture_sd_tlv), | ||
451 | SOC_WM8350_DOUBLE_R_TLV("Capture Volume", | ||
452 | WM8350_LEFT_INPUT_VOLUME, | ||
453 | WM8350_RIGHT_INPUT_VOLUME, | ||
454 | 2, 63, 0, pre_amp_tlv), | ||
455 | SOC_DOUBLE_R("Capture ZC Switch", | ||
456 | WM8350_LEFT_INPUT_VOLUME, | ||
457 | WM8350_RIGHT_INPUT_VOLUME, 13, 1, 0), | ||
458 | SOC_SINGLE_TLV("Left Input Left Sidetone Volume", | ||
459 | WM8350_OUTPUT_LEFT_MIXER_VOLUME, 1, 7, 0, out_mix_tlv), | ||
460 | SOC_SINGLE_TLV("Left Input Right Sidetone Volume", | ||
461 | WM8350_OUTPUT_LEFT_MIXER_VOLUME, | ||
462 | 5, 7, 0, out_mix_tlv), | ||
463 | SOC_SINGLE_TLV("Left Input Bypass Volume", | ||
464 | WM8350_OUTPUT_LEFT_MIXER_VOLUME, | ||
465 | 9, 7, 0, out_mix_tlv), | ||
466 | SOC_SINGLE_TLV("Right Input Left Sidetone Volume", | ||
467 | WM8350_OUTPUT_RIGHT_MIXER_VOLUME, | ||
468 | 1, 7, 0, out_mix_tlv), | ||
469 | SOC_SINGLE_TLV("Right Input Right Sidetone Volume", | ||
470 | WM8350_OUTPUT_RIGHT_MIXER_VOLUME, | ||
471 | 5, 7, 0, out_mix_tlv), | ||
472 | SOC_SINGLE_TLV("Right Input Bypass Volume", | ||
473 | WM8350_OUTPUT_RIGHT_MIXER_VOLUME, | ||
474 | 13, 7, 0, out_mix_tlv), | ||
475 | SOC_SINGLE("Left Input Mixer +20dB Switch", | ||
476 | WM8350_INPUT_MIXER_VOLUME_L, 0, 1, 0), | ||
477 | SOC_SINGLE("Right Input Mixer +20dB Switch", | ||
478 | WM8350_INPUT_MIXER_VOLUME_R, 0, 1, 0), | ||
479 | SOC_SINGLE_TLV("Out4 Capture Volume", | ||
480 | WM8350_INPUT_MIXER_VOLUME, | ||
481 | 1, 7, 0, out_mix_tlv), | ||
482 | SOC_WM8350_DOUBLE_R_TLV("Out1 Playback Volume", | ||
483 | WM8350_LOUT1_VOLUME, | ||
484 | WM8350_ROUT1_VOLUME, | ||
485 | 2, 63, 0, out_pga_tlv), | ||
486 | SOC_DOUBLE_R("Out1 Playback ZC Switch", | ||
487 | WM8350_LOUT1_VOLUME, | ||
488 | WM8350_ROUT1_VOLUME, 13, 1, 0), | ||
489 | SOC_WM8350_DOUBLE_R_TLV("Out2 Playback Volume", | ||
490 | WM8350_LOUT2_VOLUME, | ||
491 | WM8350_ROUT2_VOLUME, | ||
492 | 2, 63, 0, out_pga_tlv), | ||
493 | SOC_DOUBLE_R("Out2 Playback ZC Switch", WM8350_LOUT2_VOLUME, | ||
494 | WM8350_ROUT2_VOLUME, 13, 1, 0), | ||
495 | SOC_SINGLE("Out2 Right Invert Switch", WM8350_ROUT2_VOLUME, 10, 1, 0), | ||
496 | SOC_SINGLE_TLV("Out2 Beep Volume", WM8350_BEEP_VOLUME, | ||
497 | 5, 7, 0, out_mix_tlv), | ||
498 | |||
499 | SOC_DOUBLE_R("Out1 Playback Switch", | ||
500 | WM8350_LOUT1_VOLUME, | ||
501 | WM8350_ROUT1_VOLUME, | ||
502 | 14, 1, 1), | ||
503 | SOC_DOUBLE_R("Out2 Playback Switch", | ||
504 | WM8350_LOUT2_VOLUME, | ||
505 | WM8350_ROUT2_VOLUME, | ||
506 | 14, 1, 1), | ||
507 | }; | ||
508 | |||
509 | /* | ||
510 | * DAPM Controls | ||
511 | */ | ||
512 | |||
513 | /* Left Playback Mixer */ | ||
514 | static const struct snd_kcontrol_new wm8350_left_play_mixer_controls[] = { | ||
515 | SOC_DAPM_SINGLE("Playback Switch", | ||
516 | WM8350_LEFT_MIXER_CONTROL, 11, 1, 0), | ||
517 | SOC_DAPM_SINGLE("Left Bypass Switch", | ||
518 | WM8350_LEFT_MIXER_CONTROL, 2, 1, 0), | ||
519 | SOC_DAPM_SINGLE("Right Playback Switch", | ||
520 | WM8350_LEFT_MIXER_CONTROL, 12, 1, 0), | ||
521 | SOC_DAPM_SINGLE("Left Sidetone Switch", | ||
522 | WM8350_LEFT_MIXER_CONTROL, 0, 1, 0), | ||
523 | SOC_DAPM_SINGLE("Right Sidetone Switch", | ||
524 | WM8350_LEFT_MIXER_CONTROL, 1, 1, 0), | ||
525 | }; | ||
526 | |||
527 | /* Right Playback Mixer */ | ||
528 | static const struct snd_kcontrol_new wm8350_right_play_mixer_controls[] = { | ||
529 | SOC_DAPM_SINGLE("Playback Switch", | ||
530 | WM8350_RIGHT_MIXER_CONTROL, 12, 1, 0), | ||
531 | SOC_DAPM_SINGLE("Right Bypass Switch", | ||
532 | WM8350_RIGHT_MIXER_CONTROL, 3, 1, 0), | ||
533 | SOC_DAPM_SINGLE("Left Playback Switch", | ||
534 | WM8350_RIGHT_MIXER_CONTROL, 11, 1, 0), | ||
535 | SOC_DAPM_SINGLE("Left Sidetone Switch", | ||
536 | WM8350_RIGHT_MIXER_CONTROL, 0, 1, 0), | ||
537 | SOC_DAPM_SINGLE("Right Sidetone Switch", | ||
538 | WM8350_RIGHT_MIXER_CONTROL, 1, 1, 0), | ||
539 | }; | ||
540 | |||
541 | /* Out4 Mixer */ | ||
542 | static const struct snd_kcontrol_new wm8350_out4_mixer_controls[] = { | ||
543 | SOC_DAPM_SINGLE("Right Playback Switch", | ||
544 | WM8350_OUT4_MIXER_CONTROL, 12, 1, 0), | ||
545 | SOC_DAPM_SINGLE("Left Playback Switch", | ||
546 | WM8350_OUT4_MIXER_CONTROL, 11, 1, 0), | ||
547 | SOC_DAPM_SINGLE("Right Capture Switch", | ||
548 | WM8350_OUT4_MIXER_CONTROL, 9, 1, 0), | ||
549 | SOC_DAPM_SINGLE("Out3 Playback Switch", | ||
550 | WM8350_OUT4_MIXER_CONTROL, 2, 1, 0), | ||
551 | SOC_DAPM_SINGLE("Right Mixer Switch", | ||
552 | WM8350_OUT4_MIXER_CONTROL, 1, 1, 0), | ||
553 | SOC_DAPM_SINGLE("Left Mixer Switch", | ||
554 | WM8350_OUT4_MIXER_CONTROL, 0, 1, 0), | ||
555 | }; | ||
556 | |||
557 | /* Out3 Mixer */ | ||
558 | static const struct snd_kcontrol_new wm8350_out3_mixer_controls[] = { | ||
559 | SOC_DAPM_SINGLE("Left Playback Switch", | ||
560 | WM8350_OUT3_MIXER_CONTROL, 11, 1, 0), | ||
561 | SOC_DAPM_SINGLE("Left Capture Switch", | ||
562 | WM8350_OUT3_MIXER_CONTROL, 8, 1, 0), | ||
563 | SOC_DAPM_SINGLE("Out4 Playback Switch", | ||
564 | WM8350_OUT3_MIXER_CONTROL, 3, 1, 0), | ||
565 | SOC_DAPM_SINGLE("Left Mixer Switch", | ||
566 | WM8350_OUT3_MIXER_CONTROL, 0, 1, 0), | ||
567 | }; | ||
568 | |||
569 | /* Left Input Mixer */ | ||
570 | static const struct snd_kcontrol_new wm8350_left_capt_mixer_controls[] = { | ||
571 | SOC_DAPM_SINGLE_TLV("L2 Capture Volume", | ||
572 | WM8350_INPUT_MIXER_VOLUME_L, 1, 7, 0, out_mix_tlv), | ||
573 | SOC_DAPM_SINGLE_TLV("L3 Capture Volume", | ||
574 | WM8350_INPUT_MIXER_VOLUME_L, 9, 7, 0, out_mix_tlv), | ||
575 | SOC_DAPM_SINGLE("PGA Capture Switch", | ||
576 | WM8350_LEFT_INPUT_VOLUME, 14, 1, 0), | ||
577 | }; | ||
578 | |||
579 | /* Right Input Mixer */ | ||
580 | static const struct snd_kcontrol_new wm8350_right_capt_mixer_controls[] = { | ||
581 | SOC_DAPM_SINGLE_TLV("L2 Capture Volume", | ||
582 | WM8350_INPUT_MIXER_VOLUME_R, 5, 7, 0, out_mix_tlv), | ||
583 | SOC_DAPM_SINGLE_TLV("L3 Capture Volume", | ||
584 | WM8350_INPUT_MIXER_VOLUME_R, 13, 7, 0, out_mix_tlv), | ||
585 | SOC_DAPM_SINGLE("PGA Capture Switch", | ||
586 | WM8350_RIGHT_INPUT_VOLUME, 14, 1, 0), | ||
587 | }; | ||
588 | |||
589 | /* Left Mic Mixer */ | ||
590 | static const struct snd_kcontrol_new wm8350_left_mic_mixer_controls[] = { | ||
591 | SOC_DAPM_SINGLE("INN Capture Switch", WM8350_INPUT_CONTROL, 1, 1, 0), | ||
592 | SOC_DAPM_SINGLE("INP Capture Switch", WM8350_INPUT_CONTROL, 0, 1, 0), | ||
593 | SOC_DAPM_SINGLE("IN2 Capture Switch", WM8350_INPUT_CONTROL, 2, 1, 0), | ||
594 | }; | ||
595 | |||
596 | /* Right Mic Mixer */ | ||
597 | static const struct snd_kcontrol_new wm8350_right_mic_mixer_controls[] = { | ||
598 | SOC_DAPM_SINGLE("INN Capture Switch", WM8350_INPUT_CONTROL, 9, 1, 0), | ||
599 | SOC_DAPM_SINGLE("INP Capture Switch", WM8350_INPUT_CONTROL, 8, 1, 0), | ||
600 | SOC_DAPM_SINGLE("IN2 Capture Switch", WM8350_INPUT_CONTROL, 10, 1, 0), | ||
601 | }; | ||
602 | |||
603 | /* Beep Switch */ | ||
604 | static const struct snd_kcontrol_new wm8350_beep_switch_controls = | ||
605 | SOC_DAPM_SINGLE("Switch", WM8350_BEEP_VOLUME, 15, 1, 1); | ||
606 | |||
607 | /* Out4 Capture Mux */ | ||
608 | static const struct snd_kcontrol_new wm8350_out4_capture_controls = | ||
609 | SOC_DAPM_ENUM("Route", wm8350_enum[8]); | ||
610 | |||
611 | static const struct snd_soc_dapm_widget wm8350_dapm_widgets[] = { | ||
612 | |||
613 | SND_SOC_DAPM_PGA("IN3R PGA", WM8350_POWER_MGMT_2, 11, 0, NULL, 0), | ||
614 | SND_SOC_DAPM_PGA("IN3L PGA", WM8350_POWER_MGMT_2, 10, 0, NULL, 0), | ||
615 | SND_SOC_DAPM_PGA_E("Right Out2 PGA", WM8350_POWER_MGMT_3, 3, 0, NULL, | ||
616 | 0, pga_event, | ||
617 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), | ||
618 | SND_SOC_DAPM_PGA_E("Left Out2 PGA", WM8350_POWER_MGMT_3, 2, 0, NULL, 0, | ||
619 | pga_event, | ||
620 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), | ||
621 | SND_SOC_DAPM_PGA_E("Right Out1 PGA", WM8350_POWER_MGMT_3, 1, 0, NULL, | ||
622 | 0, pga_event, | ||
623 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), | ||
624 | SND_SOC_DAPM_PGA_E("Left Out1 PGA", WM8350_POWER_MGMT_3, 0, 0, NULL, 0, | ||
625 | pga_event, | ||
626 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), | ||
627 | |||
628 | SND_SOC_DAPM_MIXER("Right Capture Mixer", WM8350_POWER_MGMT_2, | ||
629 | 7, 0, &wm8350_right_capt_mixer_controls[0], | ||
630 | ARRAY_SIZE(wm8350_right_capt_mixer_controls)), | ||
631 | |||
632 | SND_SOC_DAPM_MIXER("Left Capture Mixer", WM8350_POWER_MGMT_2, | ||
633 | 6, 0, &wm8350_left_capt_mixer_controls[0], | ||
634 | ARRAY_SIZE(wm8350_left_capt_mixer_controls)), | ||
635 | |||
636 | SND_SOC_DAPM_MIXER("Out4 Mixer", WM8350_POWER_MGMT_2, 5, 0, | ||
637 | &wm8350_out4_mixer_controls[0], | ||
638 | ARRAY_SIZE(wm8350_out4_mixer_controls)), | ||
639 | |||
640 | SND_SOC_DAPM_MIXER("Out3 Mixer", WM8350_POWER_MGMT_2, 4, 0, | ||
641 | &wm8350_out3_mixer_controls[0], | ||
642 | ARRAY_SIZE(wm8350_out3_mixer_controls)), | ||
643 | |||
644 | SND_SOC_DAPM_MIXER("Right Playback Mixer", WM8350_POWER_MGMT_2, 1, 0, | ||
645 | &wm8350_right_play_mixer_controls[0], | ||
646 | ARRAY_SIZE(wm8350_right_play_mixer_controls)), | ||
647 | |||
648 | SND_SOC_DAPM_MIXER("Left Playback Mixer", WM8350_POWER_MGMT_2, 0, 0, | ||
649 | &wm8350_left_play_mixer_controls[0], | ||
650 | ARRAY_SIZE(wm8350_left_play_mixer_controls)), | ||
651 | |||
652 | SND_SOC_DAPM_MIXER("Left Mic Mixer", WM8350_POWER_MGMT_2, 8, 0, | ||
653 | &wm8350_left_mic_mixer_controls[0], | ||
654 | ARRAY_SIZE(wm8350_left_mic_mixer_controls)), | ||
655 | |||
656 | SND_SOC_DAPM_MIXER("Right Mic Mixer", WM8350_POWER_MGMT_2, 9, 0, | ||
657 | &wm8350_right_mic_mixer_controls[0], | ||
658 | ARRAY_SIZE(wm8350_right_mic_mixer_controls)), | ||
659 | |||
660 | /* virtual mixer for Beep and Out2R */ | ||
661 | SND_SOC_DAPM_MIXER("Out2 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
662 | |||
663 | SND_SOC_DAPM_SWITCH("Beep", WM8350_POWER_MGMT_3, 7, 0, | ||
664 | &wm8350_beep_switch_controls), | ||
665 | |||
666 | SND_SOC_DAPM_ADC("Right ADC", "Right Capture", | ||
667 | WM8350_POWER_MGMT_4, 3, 0), | ||
668 | SND_SOC_DAPM_ADC("Left ADC", "Left Capture", | ||
669 | WM8350_POWER_MGMT_4, 2, 0), | ||
670 | SND_SOC_DAPM_DAC("Right DAC", "Right Playback", | ||
671 | WM8350_POWER_MGMT_4, 5, 0), | ||
672 | SND_SOC_DAPM_DAC("Left DAC", "Left Playback", | ||
673 | WM8350_POWER_MGMT_4, 4, 0), | ||
674 | |||
675 | SND_SOC_DAPM_MICBIAS("Mic Bias", WM8350_POWER_MGMT_1, 4, 0), | ||
676 | |||
677 | SND_SOC_DAPM_MUX("Out4 Capture Channel", SND_SOC_NOPM, 0, 0, | ||
678 | &wm8350_out4_capture_controls), | ||
679 | |||
680 | SND_SOC_DAPM_OUTPUT("OUT1R"), | ||
681 | SND_SOC_DAPM_OUTPUT("OUT1L"), | ||
682 | SND_SOC_DAPM_OUTPUT("OUT2R"), | ||
683 | SND_SOC_DAPM_OUTPUT("OUT2L"), | ||
684 | SND_SOC_DAPM_OUTPUT("OUT3"), | ||
685 | SND_SOC_DAPM_OUTPUT("OUT4"), | ||
686 | |||
687 | SND_SOC_DAPM_INPUT("IN1RN"), | ||
688 | SND_SOC_DAPM_INPUT("IN1RP"), | ||
689 | SND_SOC_DAPM_INPUT("IN2R"), | ||
690 | SND_SOC_DAPM_INPUT("IN1LP"), | ||
691 | SND_SOC_DAPM_INPUT("IN1LN"), | ||
692 | SND_SOC_DAPM_INPUT("IN2L"), | ||
693 | SND_SOC_DAPM_INPUT("IN3R"), | ||
694 | SND_SOC_DAPM_INPUT("IN3L"), | ||
695 | }; | ||
696 | |||
697 | static const struct snd_soc_dapm_route audio_map[] = { | ||
698 | |||
699 | /* left playback mixer */ | ||
700 | {"Left Playback Mixer", "Playback Switch", "Left DAC"}, | ||
701 | {"Left Playback Mixer", "Left Bypass Switch", "IN3L PGA"}, | ||
702 | {"Left Playback Mixer", "Right Playback Switch", "Right DAC"}, | ||
703 | {"Left Playback Mixer", "Left Sidetone Switch", "Left Mic Mixer"}, | ||
704 | {"Left Playback Mixer", "Right Sidetone Switch", "Right Mic Mixer"}, | ||
705 | |||
706 | /* right playback mixer */ | ||
707 | {"Right Playback Mixer", "Playback Switch", "Right DAC"}, | ||
708 | {"Right Playback Mixer", "Right Bypass Switch", "IN3R PGA"}, | ||
709 | {"Right Playback Mixer", "Left Playback Switch", "Left DAC"}, | ||
710 | {"Right Playback Mixer", "Left Sidetone Switch", "Left Mic Mixer"}, | ||
711 | {"Right Playback Mixer", "Right Sidetone Switch", "Right Mic Mixer"}, | ||
712 | |||
713 | /* out4 playback mixer */ | ||
714 | {"Out4 Mixer", "Right Playback Switch", "Right DAC"}, | ||
715 | {"Out4 Mixer", "Left Playback Switch", "Left DAC"}, | ||
716 | {"Out4 Mixer", "Right Capture Switch", "Right Capture Mixer"}, | ||
717 | {"Out4 Mixer", "Out3 Playback Switch", "Out3 Mixer"}, | ||
718 | {"Out4 Mixer", "Right Mixer Switch", "Right Playback Mixer"}, | ||
719 | {"Out4 Mixer", "Left Mixer Switch", "Left Playback Mixer"}, | ||
720 | {"OUT4", NULL, "Out4 Mixer"}, | ||
721 | |||
722 | /* out3 playback mixer */ | ||
723 | {"Out3 Mixer", "Left Playback Switch", "Left DAC"}, | ||
724 | {"Out3 Mixer", "Left Capture Switch", "Left Capture Mixer"}, | ||
725 | {"Out3 Mixer", "Left Mixer Switch", "Left Playback Mixer"}, | ||
726 | {"Out3 Mixer", "Out4 Playback Switch", "Out4 Mixer"}, | ||
727 | {"OUT3", NULL, "Out3 Mixer"}, | ||
728 | |||
729 | /* out2 */ | ||
730 | {"Right Out2 PGA", NULL, "Right Playback Mixer"}, | ||
731 | {"Left Out2 PGA", NULL, "Left Playback Mixer"}, | ||
732 | {"OUT2L", NULL, "Left Out2 PGA"}, | ||
733 | {"OUT2R", NULL, "Right Out2 PGA"}, | ||
734 | |||
735 | /* out1 */ | ||
736 | {"Right Out1 PGA", NULL, "Right Playback Mixer"}, | ||
737 | {"Left Out1 PGA", NULL, "Left Playback Mixer"}, | ||
738 | {"OUT1L", NULL, "Left Out1 PGA"}, | ||
739 | {"OUT1R", NULL, "Right Out1 PGA"}, | ||
740 | |||
741 | /* ADCs */ | ||
742 | {"Left ADC", NULL, "Left Capture Mixer"}, | ||
743 | {"Right ADC", NULL, "Right Capture Mixer"}, | ||
744 | |||
745 | /* Left capture mixer */ | ||
746 | {"Left Capture Mixer", "L2 Capture Volume", "IN2L"}, | ||
747 | {"Left Capture Mixer", "L3 Capture Volume", "IN3L PGA"}, | ||
748 | {"Left Capture Mixer", "PGA Capture Switch", "Left Mic Mixer"}, | ||
749 | {"Left Capture Mixer", NULL, "Out4 Capture Channel"}, | ||
750 | |||
751 | /* Right capture mixer */ | ||
752 | {"Right Capture Mixer", "L2 Capture Volume", "IN2R"}, | ||
753 | {"Right Capture Mixer", "L3 Capture Volume", "IN3R PGA"}, | ||
754 | {"Right Capture Mixer", "PGA Capture Switch", "Right Mic Mixer"}, | ||
755 | {"Right Capture Mixer", NULL, "Out4 Capture Channel"}, | ||
756 | |||
757 | /* L3 Inputs */ | ||
758 | {"IN3L PGA", NULL, "IN3L"}, | ||
759 | {"IN3R PGA", NULL, "IN3R"}, | ||
760 | |||
761 | /* Left Mic mixer */ | ||
762 | {"Left Mic Mixer", "INN Capture Switch", "IN1LN"}, | ||
763 | {"Left Mic Mixer", "INP Capture Switch", "IN1LP"}, | ||
764 | {"Left Mic Mixer", "IN2 Capture Switch", "IN2L"}, | ||
765 | |||
766 | /* Right Mic mixer */ | ||
767 | {"Right Mic Mixer", "INN Capture Switch", "IN1RN"}, | ||
768 | {"Right Mic Mixer", "INP Capture Switch", "IN1RP"}, | ||
769 | {"Right Mic Mixer", "IN2 Capture Switch", "IN2R"}, | ||
770 | |||
771 | /* out 4 capture */ | ||
772 | {"Out4 Capture Channel", NULL, "Out4 Mixer"}, | ||
773 | |||
774 | /* Beep */ | ||
775 | {"Beep", NULL, "IN3R PGA"}, | ||
776 | }; | ||
777 | |||
778 | static int wm8350_add_controls(struct snd_soc_codec *codec) | ||
779 | { | ||
780 | int err, i; | ||
781 | |||
782 | for (i = 0; i < ARRAY_SIZE(wm8350_snd_controls); i++) { | ||
783 | err = snd_ctl_add(codec->card, | ||
784 | snd_soc_cnew(&wm8350_snd_controls[i], | ||
785 | codec, NULL)); | ||
786 | if (err < 0) | ||
787 | return err; | ||
788 | } | ||
789 | |||
790 | return 0; | ||
791 | } | ||
792 | |||
793 | static int wm8350_add_widgets(struct snd_soc_codec *codec) | ||
794 | { | ||
795 | int ret; | ||
796 | |||
797 | ret = snd_soc_dapm_new_controls(codec, | ||
798 | wm8350_dapm_widgets, | ||
799 | ARRAY_SIZE(wm8350_dapm_widgets)); | ||
800 | if (ret != 0) { | ||
801 | dev_err(codec->dev, "dapm control register failed\n"); | ||
802 | return ret; | ||
803 | } | ||
804 | |||
805 | /* set up audio paths */ | ||
806 | ret = snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | ||
807 | if (ret != 0) { | ||
808 | dev_err(codec->dev, "DAPM route register failed\n"); | ||
809 | return ret; | ||
810 | } | ||
811 | |||
812 | return snd_soc_dapm_new_widgets(codec); | ||
813 | } | ||
814 | |||
815 | static int wm8350_set_dai_sysclk(struct snd_soc_dai *codec_dai, | ||
816 | int clk_id, unsigned int freq, int dir) | ||
817 | { | ||
818 | struct snd_soc_codec *codec = codec_dai->codec; | ||
819 | struct wm8350 *wm8350 = codec->control_data; | ||
820 | u16 fll_4; | ||
821 | |||
822 | switch (clk_id) { | ||
823 | case WM8350_MCLK_SEL_MCLK: | ||
824 | wm8350_clear_bits(wm8350, WM8350_CLOCK_CONTROL_1, | ||
825 | WM8350_MCLK_SEL); | ||
826 | break; | ||
827 | case WM8350_MCLK_SEL_PLL_MCLK: | ||
828 | case WM8350_MCLK_SEL_PLL_DAC: | ||
829 | case WM8350_MCLK_SEL_PLL_ADC: | ||
830 | case WM8350_MCLK_SEL_PLL_32K: | ||
831 | wm8350_set_bits(wm8350, WM8350_CLOCK_CONTROL_1, | ||
832 | WM8350_MCLK_SEL); | ||
833 | fll_4 = wm8350_codec_read(codec, WM8350_FLL_CONTROL_4) & | ||
834 | ~WM8350_FLL_CLK_SRC_MASK; | ||
835 | wm8350_codec_write(codec, WM8350_FLL_CONTROL_4, fll_4 | clk_id); | ||
836 | break; | ||
837 | } | ||
838 | |||
839 | /* MCLK direction */ | ||
840 | if (dir == WM8350_MCLK_DIR_OUT) | ||
841 | wm8350_set_bits(wm8350, WM8350_CLOCK_CONTROL_2, | ||
842 | WM8350_MCLK_DIR); | ||
843 | else | ||
844 | wm8350_clear_bits(wm8350, WM8350_CLOCK_CONTROL_2, | ||
845 | WM8350_MCLK_DIR); | ||
846 | |||
847 | return 0; | ||
848 | } | ||
849 | |||
850 | static int wm8350_set_clkdiv(struct snd_soc_dai *codec_dai, int div_id, int div) | ||
851 | { | ||
852 | struct snd_soc_codec *codec = codec_dai->codec; | ||
853 | u16 val; | ||
854 | |||
855 | switch (div_id) { | ||
856 | case WM8350_ADC_CLKDIV: | ||
857 | val = wm8350_codec_read(codec, WM8350_ADC_DIVIDER) & | ||
858 | ~WM8350_ADC_CLKDIV_MASK; | ||
859 | wm8350_codec_write(codec, WM8350_ADC_DIVIDER, val | div); | ||
860 | break; | ||
861 | case WM8350_DAC_CLKDIV: | ||
862 | val = wm8350_codec_read(codec, WM8350_DAC_CLOCK_CONTROL) & | ||
863 | ~WM8350_DAC_CLKDIV_MASK; | ||
864 | wm8350_codec_write(codec, WM8350_DAC_CLOCK_CONTROL, val | div); | ||
865 | break; | ||
866 | case WM8350_BCLK_CLKDIV: | ||
867 | val = wm8350_codec_read(codec, WM8350_CLOCK_CONTROL_1) & | ||
868 | ~WM8350_BCLK_DIV_MASK; | ||
869 | wm8350_codec_write(codec, WM8350_CLOCK_CONTROL_1, val | div); | ||
870 | break; | ||
871 | case WM8350_OPCLK_CLKDIV: | ||
872 | val = wm8350_codec_read(codec, WM8350_CLOCK_CONTROL_1) & | ||
873 | ~WM8350_OPCLK_DIV_MASK; | ||
874 | wm8350_codec_write(codec, WM8350_CLOCK_CONTROL_1, val | div); | ||
875 | break; | ||
876 | case WM8350_SYS_CLKDIV: | ||
877 | val = wm8350_codec_read(codec, WM8350_CLOCK_CONTROL_1) & | ||
878 | ~WM8350_MCLK_DIV_MASK; | ||
879 | wm8350_codec_write(codec, WM8350_CLOCK_CONTROL_1, val | div); | ||
880 | break; | ||
881 | case WM8350_DACLR_CLKDIV: | ||
882 | val = wm8350_codec_read(codec, WM8350_DAC_LR_RATE) & | ||
883 | ~WM8350_DACLRC_RATE_MASK; | ||
884 | wm8350_codec_write(codec, WM8350_DAC_LR_RATE, val | div); | ||
885 | break; | ||
886 | case WM8350_ADCLR_CLKDIV: | ||
887 | val = wm8350_codec_read(codec, WM8350_ADC_LR_RATE) & | ||
888 | ~WM8350_ADCLRC_RATE_MASK; | ||
889 | wm8350_codec_write(codec, WM8350_ADC_LR_RATE, val | div); | ||
890 | break; | ||
891 | default: | ||
892 | return -EINVAL; | ||
893 | } | ||
894 | |||
895 | return 0; | ||
896 | } | ||
897 | |||
898 | static int wm8350_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) | ||
899 | { | ||
900 | struct snd_soc_codec *codec = codec_dai->codec; | ||
901 | u16 iface = wm8350_codec_read(codec, WM8350_AI_FORMATING) & | ||
902 | ~(WM8350_AIF_BCLK_INV | WM8350_AIF_LRCLK_INV | WM8350_AIF_FMT_MASK); | ||
903 | u16 master = wm8350_codec_read(codec, WM8350_AI_DAC_CONTROL) & | ||
904 | ~WM8350_BCLK_MSTR; | ||
905 | u16 dac_lrc = wm8350_codec_read(codec, WM8350_DAC_LR_RATE) & | ||
906 | ~WM8350_DACLRC_ENA; | ||
907 | u16 adc_lrc = wm8350_codec_read(codec, WM8350_ADC_LR_RATE) & | ||
908 | ~WM8350_ADCLRC_ENA; | ||
909 | |||
910 | /* set master/slave audio interface */ | ||
911 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
912 | case SND_SOC_DAIFMT_CBM_CFM: | ||
913 | master |= WM8350_BCLK_MSTR; | ||
914 | dac_lrc |= WM8350_DACLRC_ENA; | ||
915 | adc_lrc |= WM8350_ADCLRC_ENA; | ||
916 | break; | ||
917 | case SND_SOC_DAIFMT_CBS_CFS: | ||
918 | break; | ||
919 | default: | ||
920 | return -EINVAL; | ||
921 | } | ||
922 | |||
923 | /* interface format */ | ||
924 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
925 | case SND_SOC_DAIFMT_I2S: | ||
926 | iface |= 0x2 << 8; | ||
927 | break; | ||
928 | case SND_SOC_DAIFMT_RIGHT_J: | ||
929 | break; | ||
930 | case SND_SOC_DAIFMT_LEFT_J: | ||
931 | iface |= 0x1 << 8; | ||
932 | break; | ||
933 | case SND_SOC_DAIFMT_DSP_A: | ||
934 | iface |= 0x3 << 8; | ||
935 | break; | ||
936 | case SND_SOC_DAIFMT_DSP_B: | ||
937 | iface |= 0x3 << 8; /* lg not sure which mode */ | ||
938 | break; | ||
939 | default: | ||
940 | return -EINVAL; | ||
941 | } | ||
942 | |||
943 | /* clock inversion */ | ||
944 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
945 | case SND_SOC_DAIFMT_NB_NF: | ||
946 | break; | ||
947 | case SND_SOC_DAIFMT_IB_IF: | ||
948 | iface |= WM8350_AIF_LRCLK_INV | WM8350_AIF_BCLK_INV; | ||
949 | break; | ||
950 | case SND_SOC_DAIFMT_IB_NF: | ||
951 | iface |= WM8350_AIF_BCLK_INV; | ||
952 | break; | ||
953 | case SND_SOC_DAIFMT_NB_IF: | ||
954 | iface |= WM8350_AIF_LRCLK_INV; | ||
955 | break; | ||
956 | default: | ||
957 | return -EINVAL; | ||
958 | } | ||
959 | |||
960 | wm8350_codec_write(codec, WM8350_AI_FORMATING, iface); | ||
961 | wm8350_codec_write(codec, WM8350_AI_DAC_CONTROL, master); | ||
962 | wm8350_codec_write(codec, WM8350_DAC_LR_RATE, dac_lrc); | ||
963 | wm8350_codec_write(codec, WM8350_ADC_LR_RATE, adc_lrc); | ||
964 | return 0; | ||
965 | } | ||
966 | |||
967 | static int wm8350_pcm_trigger(struct snd_pcm_substream *substream, | ||
968 | int cmd, struct snd_soc_dai *codec_dai) | ||
969 | { | ||
970 | struct snd_soc_codec *codec = codec_dai->codec; | ||
971 | int master = wm8350_codec_cache_read(codec, WM8350_AI_DAC_CONTROL) & | ||
972 | WM8350_BCLK_MSTR; | ||
973 | int enabled = 0; | ||
974 | |||
975 | /* Check that the DACs or ADCs are enabled since they are | ||
976 | * required for LRC in master mode. The DACs or ADCs need a | ||
977 | * valid audio path i.e. pin -> ADC or DAC -> pin before | ||
978 | * the LRC will be enabled in master mode. */ | ||
979 | if (!master && cmd != SNDRV_PCM_TRIGGER_START) | ||
980 | return 0; | ||
981 | |||
982 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { | ||
983 | enabled = wm8350_codec_cache_read(codec, WM8350_POWER_MGMT_4) & | ||
984 | (WM8350_ADCR_ENA | WM8350_ADCL_ENA); | ||
985 | } else { | ||
986 | enabled = wm8350_codec_cache_read(codec, WM8350_POWER_MGMT_4) & | ||
987 | (WM8350_DACR_ENA | WM8350_DACL_ENA); | ||
988 | } | ||
989 | |||
990 | if (!enabled) { | ||
991 | dev_err(codec->dev, | ||
992 | "%s: invalid audio path - no clocks available\n", | ||
993 | __func__); | ||
994 | return -EINVAL; | ||
995 | } | ||
996 | return 0; | ||
997 | } | ||
998 | |||
999 | static int wm8350_pcm_hw_params(struct snd_pcm_substream *substream, | ||
1000 | struct snd_pcm_hw_params *params, | ||
1001 | struct snd_soc_dai *codec_dai) | ||
1002 | { | ||
1003 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1004 | u16 iface = wm8350_codec_read(codec, WM8350_AI_FORMATING) & | ||
1005 | ~WM8350_AIF_WL_MASK; | ||
1006 | |||
1007 | /* bit size */ | ||
1008 | switch (params_format(params)) { | ||
1009 | case SNDRV_PCM_FORMAT_S16_LE: | ||
1010 | break; | ||
1011 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
1012 | iface |= 0x1 << 10; | ||
1013 | break; | ||
1014 | case SNDRV_PCM_FORMAT_S24_LE: | ||
1015 | iface |= 0x2 << 10; | ||
1016 | break; | ||
1017 | case SNDRV_PCM_FORMAT_S32_LE: | ||
1018 | iface |= 0x3 << 10; | ||
1019 | break; | ||
1020 | } | ||
1021 | |||
1022 | wm8350_codec_write(codec, WM8350_AI_FORMATING, iface); | ||
1023 | return 0; | ||
1024 | } | ||
1025 | |||
1026 | static int wm8350_mute(struct snd_soc_dai *dai, int mute) | ||
1027 | { | ||
1028 | struct snd_soc_codec *codec = dai->codec; | ||
1029 | struct wm8350 *wm8350 = codec->control_data; | ||
1030 | |||
1031 | if (mute) | ||
1032 | wm8350_set_bits(wm8350, WM8350_DAC_MUTE, WM8350_DAC_MUTE_ENA); | ||
1033 | else | ||
1034 | wm8350_clear_bits(wm8350, WM8350_DAC_MUTE, WM8350_DAC_MUTE_ENA); | ||
1035 | return 0; | ||
1036 | } | ||
1037 | |||
1038 | /* FLL divisors */ | ||
1039 | struct _fll_div { | ||
1040 | int div; /* FLL_OUTDIV */ | ||
1041 | int n; | ||
1042 | int k; | ||
1043 | int ratio; /* FLL_FRATIO */ | ||
1044 | }; | ||
1045 | |||
1046 | /* The size in bits of the fll divide multiplied by 10 | ||
1047 | * to allow rounding later */ | ||
1048 | #define FIXED_FLL_SIZE ((1 << 16) * 10) | ||
1049 | |||
1050 | static inline int fll_factors(struct _fll_div *fll_div, unsigned int input, | ||
1051 | unsigned int output) | ||
1052 | { | ||
1053 | u64 Kpart; | ||
1054 | unsigned int t1, t2, K, Nmod; | ||
1055 | |||
1056 | if (output >= 2815250 && output <= 3125000) | ||
1057 | fll_div->div = 0x4; | ||
1058 | else if (output >= 5625000 && output <= 6250000) | ||
1059 | fll_div->div = 0x3; | ||
1060 | else if (output >= 11250000 && output <= 12500000) | ||
1061 | fll_div->div = 0x2; | ||
1062 | else if (output >= 22500000 && output <= 25000000) | ||
1063 | fll_div->div = 0x1; | ||
1064 | else { | ||
1065 | printk(KERN_ERR "wm8350: fll freq %d out of range\n", output); | ||
1066 | return -EINVAL; | ||
1067 | } | ||
1068 | |||
1069 | if (input > 48000) | ||
1070 | fll_div->ratio = 1; | ||
1071 | else | ||
1072 | fll_div->ratio = 8; | ||
1073 | |||
1074 | t1 = output * (1 << (fll_div->div + 1)); | ||
1075 | t2 = input * fll_div->ratio; | ||
1076 | |||
1077 | fll_div->n = t1 / t2; | ||
1078 | Nmod = t1 % t2; | ||
1079 | |||
1080 | if (Nmod) { | ||
1081 | Kpart = FIXED_FLL_SIZE * (long long)Nmod; | ||
1082 | do_div(Kpart, t2); | ||
1083 | K = Kpart & 0xFFFFFFFF; | ||
1084 | |||
1085 | /* Check if we need to round */ | ||
1086 | if ((K % 10) >= 5) | ||
1087 | K += 5; | ||
1088 | |||
1089 | /* Move down to proper range now rounding is done */ | ||
1090 | K /= 10; | ||
1091 | fll_div->k = K; | ||
1092 | } else | ||
1093 | fll_div->k = 0; | ||
1094 | |||
1095 | return 0; | ||
1096 | } | ||
1097 | |||
1098 | static int wm8350_set_fll(struct snd_soc_dai *codec_dai, | ||
1099 | int pll_id, unsigned int freq_in, | ||
1100 | unsigned int freq_out) | ||
1101 | { | ||
1102 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1103 | struct wm8350 *wm8350 = codec->control_data; | ||
1104 | struct _fll_div fll_div; | ||
1105 | int ret = 0; | ||
1106 | u16 fll_1, fll_4; | ||
1107 | |||
1108 | /* power down FLL - we need to do this for reconfiguration */ | ||
1109 | wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_4, | ||
1110 | WM8350_FLL_ENA | WM8350_FLL_OSC_ENA); | ||
1111 | |||
1112 | if (freq_out == 0 || freq_in == 0) | ||
1113 | return ret; | ||
1114 | |||
1115 | ret = fll_factors(&fll_div, freq_in, freq_out); | ||
1116 | if (ret < 0) | ||
1117 | return ret; | ||
1118 | dev_dbg(wm8350->dev, | ||
1119 | "FLL in %d FLL out %d N 0x%x K 0x%x div %d ratio %d", | ||
1120 | freq_in, freq_out, fll_div.n, fll_div.k, fll_div.div, | ||
1121 | fll_div.ratio); | ||
1122 | |||
1123 | /* set up N.K & dividers */ | ||
1124 | fll_1 = wm8350_codec_read(codec, WM8350_FLL_CONTROL_1) & | ||
1125 | ~(WM8350_FLL_OUTDIV_MASK | WM8350_FLL_RSP_RATE_MASK | 0xc000); | ||
1126 | wm8350_codec_write(codec, WM8350_FLL_CONTROL_1, | ||
1127 | fll_1 | (fll_div.div << 8) | 0x50); | ||
1128 | wm8350_codec_write(codec, WM8350_FLL_CONTROL_2, | ||
1129 | (fll_div.ratio << 11) | (fll_div. | ||
1130 | n & WM8350_FLL_N_MASK)); | ||
1131 | wm8350_codec_write(codec, WM8350_FLL_CONTROL_3, fll_div.k); | ||
1132 | fll_4 = wm8350_codec_read(codec, WM8350_FLL_CONTROL_4) & | ||
1133 | ~(WM8350_FLL_FRAC | WM8350_FLL_SLOW_LOCK_REF); | ||
1134 | wm8350_codec_write(codec, WM8350_FLL_CONTROL_4, | ||
1135 | fll_4 | (fll_div.k ? WM8350_FLL_FRAC : 0) | | ||
1136 | (fll_div.ratio == 8 ? WM8350_FLL_SLOW_LOCK_REF : 0)); | ||
1137 | |||
1138 | /* power FLL on */ | ||
1139 | wm8350_set_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_FLL_OSC_ENA); | ||
1140 | wm8350_set_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_FLL_ENA); | ||
1141 | |||
1142 | return 0; | ||
1143 | } | ||
1144 | |||
1145 | static int wm8350_set_bias_level(struct snd_soc_codec *codec, | ||
1146 | enum snd_soc_bias_level level) | ||
1147 | { | ||
1148 | struct wm8350 *wm8350 = codec->control_data; | ||
1149 | struct wm8350_data *priv = codec->private_data; | ||
1150 | struct wm8350_audio_platform_data *platform = | ||
1151 | wm8350->codec.platform_data; | ||
1152 | u16 pm1; | ||
1153 | int ret; | ||
1154 | |||
1155 | switch (level) { | ||
1156 | case SND_SOC_BIAS_ON: | ||
1157 | pm1 = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_1) & | ||
1158 | ~(WM8350_VMID_MASK | WM8350_CODEC_ISEL_MASK); | ||
1159 | wm8350_reg_write(wm8350, WM8350_POWER_MGMT_1, | ||
1160 | pm1 | WM8350_VMID_50K | | ||
1161 | platform->codec_current_on << 14); | ||
1162 | break; | ||
1163 | |||
1164 | case SND_SOC_BIAS_PREPARE: | ||
1165 | pm1 = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_1); | ||
1166 | pm1 &= ~WM8350_VMID_MASK; | ||
1167 | wm8350_reg_write(wm8350, WM8350_POWER_MGMT_1, | ||
1168 | pm1 | WM8350_VMID_50K); | ||
1169 | break; | ||
1170 | |||
1171 | case SND_SOC_BIAS_STANDBY: | ||
1172 | if (codec->bias_level == SND_SOC_BIAS_OFF) { | ||
1173 | ret = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), | ||
1174 | priv->supplies); | ||
1175 | if (ret != 0) | ||
1176 | return ret; | ||
1177 | |||
1178 | /* Enable the system clock */ | ||
1179 | wm8350_set_bits(wm8350, WM8350_POWER_MGMT_4, | ||
1180 | WM8350_SYSCLK_ENA); | ||
1181 | |||
1182 | /* mute DAC & outputs */ | ||
1183 | wm8350_set_bits(wm8350, WM8350_DAC_MUTE, | ||
1184 | WM8350_DAC_MUTE_ENA); | ||
1185 | |||
1186 | /* discharge cap memory */ | ||
1187 | wm8350_reg_write(wm8350, WM8350_ANTI_POP_CONTROL, | ||
1188 | platform->dis_out1 | | ||
1189 | (platform->dis_out2 << 2) | | ||
1190 | (platform->dis_out3 << 4) | | ||
1191 | (platform->dis_out4 << 6)); | ||
1192 | |||
1193 | /* wait for discharge */ | ||
1194 | schedule_timeout_interruptible(msecs_to_jiffies | ||
1195 | (platform-> | ||
1196 | cap_discharge_msecs)); | ||
1197 | |||
1198 | /* enable antipop */ | ||
1199 | wm8350_reg_write(wm8350, WM8350_ANTI_POP_CONTROL, | ||
1200 | (platform->vmid_s_curve << 8)); | ||
1201 | |||
1202 | /* ramp up vmid */ | ||
1203 | wm8350_reg_write(wm8350, WM8350_POWER_MGMT_1, | ||
1204 | (platform-> | ||
1205 | codec_current_charge << 14) | | ||
1206 | WM8350_VMID_5K | WM8350_VMIDEN | | ||
1207 | WM8350_VBUFEN); | ||
1208 | |||
1209 | /* wait for vmid */ | ||
1210 | schedule_timeout_interruptible(msecs_to_jiffies | ||
1211 | (platform-> | ||
1212 | vmid_charge_msecs)); | ||
1213 | |||
1214 | /* turn on vmid 300k */ | ||
1215 | pm1 = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_1) & | ||
1216 | ~(WM8350_VMID_MASK | WM8350_CODEC_ISEL_MASK); | ||
1217 | pm1 |= WM8350_VMID_300K | | ||
1218 | (platform->codec_current_standby << 14); | ||
1219 | wm8350_reg_write(wm8350, WM8350_POWER_MGMT_1, | ||
1220 | pm1); | ||
1221 | |||
1222 | |||
1223 | /* enable analogue bias */ | ||
1224 | pm1 |= WM8350_BIASEN; | ||
1225 | wm8350_reg_write(wm8350, WM8350_POWER_MGMT_1, pm1); | ||
1226 | |||
1227 | /* disable antipop */ | ||
1228 | wm8350_reg_write(wm8350, WM8350_ANTI_POP_CONTROL, 0); | ||
1229 | |||
1230 | } else { | ||
1231 | /* turn on vmid 300k and reduce current */ | ||
1232 | pm1 = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_1) & | ||
1233 | ~(WM8350_VMID_MASK | WM8350_CODEC_ISEL_MASK); | ||
1234 | wm8350_reg_write(wm8350, WM8350_POWER_MGMT_1, | ||
1235 | pm1 | WM8350_VMID_300K | | ||
1236 | (platform-> | ||
1237 | codec_current_standby << 14)); | ||
1238 | |||
1239 | } | ||
1240 | break; | ||
1241 | |||
1242 | case SND_SOC_BIAS_OFF: | ||
1243 | |||
1244 | /* mute DAC & enable outputs */ | ||
1245 | wm8350_set_bits(wm8350, WM8350_DAC_MUTE, WM8350_DAC_MUTE_ENA); | ||
1246 | |||
1247 | wm8350_set_bits(wm8350, WM8350_POWER_MGMT_3, | ||
1248 | WM8350_OUT1L_ENA | WM8350_OUT1R_ENA | | ||
1249 | WM8350_OUT2L_ENA | WM8350_OUT2R_ENA); | ||
1250 | |||
1251 | /* enable anti pop S curve */ | ||
1252 | wm8350_reg_write(wm8350, WM8350_ANTI_POP_CONTROL, | ||
1253 | (platform->vmid_s_curve << 8)); | ||
1254 | |||
1255 | /* turn off vmid */ | ||
1256 | pm1 = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_1) & | ||
1257 | ~WM8350_VMIDEN; | ||
1258 | wm8350_reg_write(wm8350, WM8350_POWER_MGMT_1, pm1); | ||
1259 | |||
1260 | /* wait */ | ||
1261 | schedule_timeout_interruptible(msecs_to_jiffies | ||
1262 | (platform-> | ||
1263 | vmid_discharge_msecs)); | ||
1264 | |||
1265 | wm8350_reg_write(wm8350, WM8350_ANTI_POP_CONTROL, | ||
1266 | (platform->vmid_s_curve << 8) | | ||
1267 | platform->dis_out1 | | ||
1268 | (platform->dis_out2 << 2) | | ||
1269 | (platform->dis_out3 << 4) | | ||
1270 | (platform->dis_out4 << 6)); | ||
1271 | |||
1272 | /* turn off VBuf and drain */ | ||
1273 | pm1 = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_1) & | ||
1274 | ~(WM8350_VBUFEN | WM8350_VMID_MASK); | ||
1275 | wm8350_reg_write(wm8350, WM8350_POWER_MGMT_1, | ||
1276 | pm1 | WM8350_OUTPUT_DRAIN_EN); | ||
1277 | |||
1278 | /* wait */ | ||
1279 | schedule_timeout_interruptible(msecs_to_jiffies | ||
1280 | (platform->drain_msecs)); | ||
1281 | |||
1282 | pm1 &= ~WM8350_BIASEN; | ||
1283 | wm8350_reg_write(wm8350, WM8350_POWER_MGMT_1, pm1); | ||
1284 | |||
1285 | /* disable anti-pop */ | ||
1286 | wm8350_reg_write(wm8350, WM8350_ANTI_POP_CONTROL, 0); | ||
1287 | |||
1288 | wm8350_clear_bits(wm8350, WM8350_LOUT1_VOLUME, | ||
1289 | WM8350_OUT1L_ENA); | ||
1290 | wm8350_clear_bits(wm8350, WM8350_ROUT1_VOLUME, | ||
1291 | WM8350_OUT1R_ENA); | ||
1292 | wm8350_clear_bits(wm8350, WM8350_LOUT2_VOLUME, | ||
1293 | WM8350_OUT2L_ENA); | ||
1294 | wm8350_clear_bits(wm8350, WM8350_ROUT2_VOLUME, | ||
1295 | WM8350_OUT2R_ENA); | ||
1296 | |||
1297 | /* disable clock gen */ | ||
1298 | wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_4, | ||
1299 | WM8350_SYSCLK_ENA); | ||
1300 | |||
1301 | regulator_bulk_disable(ARRAY_SIZE(priv->supplies), | ||
1302 | priv->supplies); | ||
1303 | break; | ||
1304 | } | ||
1305 | codec->bias_level = level; | ||
1306 | return 0; | ||
1307 | } | ||
1308 | |||
1309 | static int wm8350_suspend(struct platform_device *pdev, pm_message_t state) | ||
1310 | { | ||
1311 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1312 | struct snd_soc_codec *codec = socdev->codec; | ||
1313 | |||
1314 | wm8350_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
1315 | return 0; | ||
1316 | } | ||
1317 | |||
1318 | static int wm8350_resume(struct platform_device *pdev) | ||
1319 | { | ||
1320 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1321 | struct snd_soc_codec *codec = socdev->codec; | ||
1322 | |||
1323 | wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
1324 | |||
1325 | if (codec->suspend_bias_level == SND_SOC_BIAS_ON) | ||
1326 | wm8350_set_bias_level(codec, SND_SOC_BIAS_ON); | ||
1327 | |||
1328 | return 0; | ||
1329 | } | ||
1330 | |||
1331 | static struct snd_soc_codec *wm8350_codec; | ||
1332 | |||
1333 | static int wm8350_probe(struct platform_device *pdev) | ||
1334 | { | ||
1335 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1336 | struct snd_soc_codec *codec; | ||
1337 | struct wm8350 *wm8350; | ||
1338 | struct wm8350_data *priv; | ||
1339 | int ret; | ||
1340 | struct wm8350_output *out1; | ||
1341 | struct wm8350_output *out2; | ||
1342 | |||
1343 | BUG_ON(!wm8350_codec); | ||
1344 | |||
1345 | socdev->codec = wm8350_codec; | ||
1346 | codec = socdev->codec; | ||
1347 | wm8350 = codec->control_data; | ||
1348 | priv = codec->private_data; | ||
1349 | |||
1350 | /* Enable the codec */ | ||
1351 | wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); | ||
1352 | |||
1353 | /* Enable robust clocking mode in ADC */ | ||
1354 | wm8350_codec_write(codec, WM8350_SECURITY, 0xa7); | ||
1355 | wm8350_codec_write(codec, 0xde, 0x13); | ||
1356 | wm8350_codec_write(codec, WM8350_SECURITY, 0); | ||
1357 | |||
1358 | /* read OUT1 & OUT2 volumes */ | ||
1359 | out1 = &priv->out1; | ||
1360 | out2 = &priv->out2; | ||
1361 | out1->left_vol = (wm8350_reg_read(wm8350, WM8350_LOUT1_VOLUME) & | ||
1362 | WM8350_OUT1L_VOL_MASK) >> WM8350_OUT1L_VOL_SHIFT; | ||
1363 | out1->right_vol = (wm8350_reg_read(wm8350, WM8350_ROUT1_VOLUME) & | ||
1364 | WM8350_OUT1R_VOL_MASK) >> WM8350_OUT1R_VOL_SHIFT; | ||
1365 | out2->left_vol = (wm8350_reg_read(wm8350, WM8350_LOUT2_VOLUME) & | ||
1366 | WM8350_OUT2L_VOL_MASK) >> WM8350_OUT1L_VOL_SHIFT; | ||
1367 | out2->right_vol = (wm8350_reg_read(wm8350, WM8350_ROUT2_VOLUME) & | ||
1368 | WM8350_OUT2R_VOL_MASK) >> WM8350_OUT1R_VOL_SHIFT; | ||
1369 | wm8350_reg_write(wm8350, WM8350_LOUT1_VOLUME, 0); | ||
1370 | wm8350_reg_write(wm8350, WM8350_ROUT1_VOLUME, 0); | ||
1371 | wm8350_reg_write(wm8350, WM8350_LOUT2_VOLUME, 0); | ||
1372 | wm8350_reg_write(wm8350, WM8350_ROUT2_VOLUME, 0); | ||
1373 | |||
1374 | /* Latch VU bits & mute */ | ||
1375 | wm8350_set_bits(wm8350, WM8350_LOUT1_VOLUME, | ||
1376 | WM8350_OUT1_VU | WM8350_OUT1L_MUTE); | ||
1377 | wm8350_set_bits(wm8350, WM8350_LOUT2_VOLUME, | ||
1378 | WM8350_OUT2_VU | WM8350_OUT2L_MUTE); | ||
1379 | wm8350_set_bits(wm8350, WM8350_ROUT1_VOLUME, | ||
1380 | WM8350_OUT1_VU | WM8350_OUT1R_MUTE); | ||
1381 | wm8350_set_bits(wm8350, WM8350_ROUT2_VOLUME, | ||
1382 | WM8350_OUT2_VU | WM8350_OUT2R_MUTE); | ||
1383 | |||
1384 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
1385 | if (ret < 0) { | ||
1386 | dev_err(&pdev->dev, "failed to create pcms\n"); | ||
1387 | return ret; | ||
1388 | } | ||
1389 | |||
1390 | wm8350_add_controls(codec); | ||
1391 | wm8350_add_widgets(codec); | ||
1392 | |||
1393 | wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
1394 | |||
1395 | ret = snd_soc_init_card(socdev); | ||
1396 | if (ret < 0) { | ||
1397 | dev_err(&pdev->dev, "failed to register card\n"); | ||
1398 | goto card_err; | ||
1399 | } | ||
1400 | |||
1401 | return 0; | ||
1402 | |||
1403 | card_err: | ||
1404 | snd_soc_free_pcms(socdev); | ||
1405 | snd_soc_dapm_free(socdev); | ||
1406 | return ret; | ||
1407 | } | ||
1408 | |||
1409 | static int wm8350_remove(struct platform_device *pdev) | ||
1410 | { | ||
1411 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1412 | struct snd_soc_codec *codec = socdev->codec; | ||
1413 | struct wm8350 *wm8350 = codec->control_data; | ||
1414 | int ret; | ||
1415 | |||
1416 | /* cancel any work waiting to be queued. */ | ||
1417 | ret = cancel_delayed_work(&codec->delayed_work); | ||
1418 | |||
1419 | /* if there was any work waiting then we run it now and | ||
1420 | * wait for its completion */ | ||
1421 | if (ret) { | ||
1422 | schedule_delayed_work(&codec->delayed_work, 0); | ||
1423 | flush_scheduled_work(); | ||
1424 | } | ||
1425 | |||
1426 | wm8350_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
1427 | |||
1428 | wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); | ||
1429 | |||
1430 | return 0; | ||
1431 | } | ||
1432 | |||
1433 | #define WM8350_RATES (SNDRV_PCM_RATE_8000_96000) | ||
1434 | |||
1435 | #define WM8350_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\ | ||
1436 | SNDRV_PCM_FMTBIT_S20_3LE |\ | ||
1437 | SNDRV_PCM_FMTBIT_S24_LE) | ||
1438 | |||
1439 | struct snd_soc_dai wm8350_dai = { | ||
1440 | .name = "WM8350", | ||
1441 | .playback = { | ||
1442 | .stream_name = "Playback", | ||
1443 | .channels_min = 1, | ||
1444 | .channels_max = 2, | ||
1445 | .rates = WM8350_RATES, | ||
1446 | .formats = WM8350_FORMATS, | ||
1447 | }, | ||
1448 | .capture = { | ||
1449 | .stream_name = "Capture", | ||
1450 | .channels_min = 1, | ||
1451 | .channels_max = 2, | ||
1452 | .rates = WM8350_RATES, | ||
1453 | .formats = WM8350_FORMATS, | ||
1454 | }, | ||
1455 | .ops = { | ||
1456 | .hw_params = wm8350_pcm_hw_params, | ||
1457 | .digital_mute = wm8350_mute, | ||
1458 | .trigger = wm8350_pcm_trigger, | ||
1459 | .set_fmt = wm8350_set_dai_fmt, | ||
1460 | .set_sysclk = wm8350_set_dai_sysclk, | ||
1461 | .set_pll = wm8350_set_fll, | ||
1462 | .set_clkdiv = wm8350_set_clkdiv, | ||
1463 | }, | ||
1464 | }; | ||
1465 | EXPORT_SYMBOL_GPL(wm8350_dai); | ||
1466 | |||
1467 | struct snd_soc_codec_device soc_codec_dev_wm8350 = { | ||
1468 | .probe = wm8350_probe, | ||
1469 | .remove = wm8350_remove, | ||
1470 | .suspend = wm8350_suspend, | ||
1471 | .resume = wm8350_resume, | ||
1472 | }; | ||
1473 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8350); | ||
1474 | |||
1475 | static int wm8350_codec_probe(struct platform_device *pdev) | ||
1476 | { | ||
1477 | struct wm8350 *wm8350 = platform_get_drvdata(pdev); | ||
1478 | struct wm8350_data *priv; | ||
1479 | struct snd_soc_codec *codec; | ||
1480 | int ret, i; | ||
1481 | |||
1482 | if (wm8350->codec.platform_data == NULL) { | ||
1483 | dev_err(&pdev->dev, "No audio platform data supplied\n"); | ||
1484 | return -EINVAL; | ||
1485 | } | ||
1486 | |||
1487 | priv = kzalloc(sizeof(struct wm8350_data), GFP_KERNEL); | ||
1488 | if (priv == NULL) | ||
1489 | return -ENOMEM; | ||
1490 | |||
1491 | for (i = 0; i < ARRAY_SIZE(supply_names); i++) | ||
1492 | priv->supplies[i].supply = supply_names[i]; | ||
1493 | |||
1494 | ret = regulator_bulk_get(wm8350->dev, ARRAY_SIZE(priv->supplies), | ||
1495 | priv->supplies); | ||
1496 | if (ret != 0) | ||
1497 | goto err_priv; | ||
1498 | |||
1499 | codec = &priv->codec; | ||
1500 | wm8350->codec.codec = codec; | ||
1501 | |||
1502 | wm8350_dai.dev = &pdev->dev; | ||
1503 | |||
1504 | mutex_init(&codec->mutex); | ||
1505 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
1506 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
1507 | codec->dev = &pdev->dev; | ||
1508 | codec->name = "WM8350"; | ||
1509 | codec->owner = THIS_MODULE; | ||
1510 | codec->read = wm8350_codec_read; | ||
1511 | codec->write = wm8350_codec_write; | ||
1512 | codec->bias_level = SND_SOC_BIAS_OFF; | ||
1513 | codec->set_bias_level = wm8350_set_bias_level; | ||
1514 | codec->dai = &wm8350_dai; | ||
1515 | codec->num_dai = 1; | ||
1516 | codec->reg_cache_size = WM8350_MAX_REGISTER; | ||
1517 | codec->private_data = priv; | ||
1518 | codec->control_data = wm8350; | ||
1519 | |||
1520 | /* Put the codec into reset if it wasn't already */ | ||
1521 | wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); | ||
1522 | |||
1523 | INIT_DELAYED_WORK(&codec->delayed_work, wm8350_pga_work); | ||
1524 | ret = snd_soc_register_codec(codec); | ||
1525 | if (ret != 0) | ||
1526 | goto err_supply; | ||
1527 | |||
1528 | wm8350_codec = codec; | ||
1529 | |||
1530 | ret = snd_soc_register_dai(&wm8350_dai); | ||
1531 | if (ret != 0) | ||
1532 | goto err_codec; | ||
1533 | return 0; | ||
1534 | |||
1535 | err_codec: | ||
1536 | snd_soc_unregister_codec(codec); | ||
1537 | err_supply: | ||
1538 | regulator_bulk_free(ARRAY_SIZE(priv->supplies), priv->supplies); | ||
1539 | err_priv: | ||
1540 | kfree(priv); | ||
1541 | wm8350_codec = NULL; | ||
1542 | return ret; | ||
1543 | } | ||
1544 | |||
1545 | static int __devexit wm8350_codec_remove(struct platform_device *pdev) | ||
1546 | { | ||
1547 | struct wm8350 *wm8350 = platform_get_drvdata(pdev); | ||
1548 | struct snd_soc_codec *codec = wm8350->codec.codec; | ||
1549 | struct wm8350_data *priv = codec->private_data; | ||
1550 | |||
1551 | snd_soc_unregister_dai(&wm8350_dai); | ||
1552 | snd_soc_unregister_codec(codec); | ||
1553 | regulator_bulk_free(ARRAY_SIZE(priv->supplies), priv->supplies); | ||
1554 | kfree(priv); | ||
1555 | wm8350_codec = NULL; | ||
1556 | return 0; | ||
1557 | } | ||
1558 | |||
1559 | static struct platform_driver wm8350_codec_driver = { | ||
1560 | .driver = { | ||
1561 | .name = "wm8350-codec", | ||
1562 | .owner = THIS_MODULE, | ||
1563 | }, | ||
1564 | .probe = wm8350_codec_probe, | ||
1565 | .remove = __devexit_p(wm8350_codec_remove), | ||
1566 | }; | ||
1567 | |||
1568 | static __init int wm8350_init(void) | ||
1569 | { | ||
1570 | return platform_driver_register(&wm8350_codec_driver); | ||
1571 | } | ||
1572 | module_init(wm8350_init); | ||
1573 | |||
1574 | static __exit void wm8350_exit(void) | ||
1575 | { | ||
1576 | platform_driver_unregister(&wm8350_codec_driver); | ||
1577 | } | ||
1578 | module_exit(wm8350_exit); | ||
1579 | |||
1580 | MODULE_DESCRIPTION("ASoC WM8350 driver"); | ||
1581 | MODULE_AUTHOR("Liam Girdwood"); | ||
1582 | MODULE_LICENSE("GPL"); | ||
1583 | MODULE_ALIAS("platform:wm8350-codec"); | ||
diff --git a/sound/soc/codecs/wm8350.h b/sound/soc/codecs/wm8350.h new file mode 100644 index 000000000000..cc2887aa6c38 --- /dev/null +++ b/sound/soc/codecs/wm8350.h | |||
@@ -0,0 +1,20 @@ | |||
1 | /* | ||
2 | * wm8350.h - WM8903 audio codec interface | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | */ | ||
11 | |||
12 | #ifndef _WM8350_H | ||
13 | #define _WM8350_H | ||
14 | |||
15 | #include <sound/soc.h> | ||
16 | |||
17 | extern struct snd_soc_dai wm8350_dai; | ||
18 | extern struct snd_soc_codec_device soc_codec_dev_wm8350; | ||
19 | |||
20 | #endif | ||
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c index d8ca2da8d634..40f8238df717 100644 --- a/sound/soc/codecs/wm8510.c +++ b/sound/soc/codecs/wm8510.c | |||
@@ -463,7 +463,8 @@ static int wm8510_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
463 | } | 463 | } |
464 | 464 | ||
465 | static int wm8510_pcm_hw_params(struct snd_pcm_substream *substream, | 465 | static int wm8510_pcm_hw_params(struct snd_pcm_substream *substream, |
466 | struct snd_pcm_hw_params *params) | 466 | struct snd_pcm_hw_params *params, |
467 | struct snd_soc_dai *dai) | ||
467 | { | 468 | { |
468 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 469 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
469 | struct snd_soc_device *socdev = rtd->socdev; | 470 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -585,8 +586,6 @@ struct snd_soc_dai wm8510_dai = { | |||
585 | .formats = WM8510_FORMATS,}, | 586 | .formats = WM8510_FORMATS,}, |
586 | .ops = { | 587 | .ops = { |
587 | .hw_params = wm8510_pcm_hw_params, | 588 | .hw_params = wm8510_pcm_hw_params, |
588 | }, | ||
589 | .dai_ops = { | ||
590 | .digital_mute = wm8510_mute, | 589 | .digital_mute = wm8510_mute, |
591 | .set_fmt = wm8510_set_dai_fmt, | 590 | .set_fmt = wm8510_set_dai_fmt, |
592 | .set_clkdiv = wm8510_set_dai_clkdiv, | 591 | .set_clkdiv = wm8510_set_dai_clkdiv, |
@@ -659,7 +658,7 @@ static int wm8510_init(struct snd_soc_device *socdev) | |||
659 | wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 658 | wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
660 | wm8510_add_controls(codec); | 659 | wm8510_add_controls(codec); |
661 | wm8510_add_widgets(codec); | 660 | wm8510_add_widgets(codec); |
662 | ret = snd_soc_register_card(socdev); | 661 | ret = snd_soc_init_card(socdev); |
663 | if (ret < 0) { | 662 | if (ret < 0) { |
664 | printk(KERN_ERR "wm8510: failed to register card\n"); | 663 | printk(KERN_ERR "wm8510: failed to register card\n"); |
665 | goto card_err; | 664 | goto card_err; |
@@ -890,6 +889,18 @@ struct snd_soc_codec_device soc_codec_dev_wm8510 = { | |||
890 | }; | 889 | }; |
891 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8510); | 890 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8510); |
892 | 891 | ||
892 | static int __init wm8510_modinit(void) | ||
893 | { | ||
894 | return snd_soc_register_dai(&wm8510_dai); | ||
895 | } | ||
896 | module_init(wm8510_modinit); | ||
897 | |||
898 | static void __exit wm8510_exit(void) | ||
899 | { | ||
900 | snd_soc_unregister_dai(&wm8510_dai); | ||
901 | } | ||
902 | module_exit(wm8510_exit); | ||
903 | |||
893 | MODULE_DESCRIPTION("ASoC WM8510 driver"); | 904 | MODULE_DESCRIPTION("ASoC WM8510 driver"); |
894 | MODULE_AUTHOR("Liam Girdwood"); | 905 | MODULE_AUTHOR("Liam Girdwood"); |
895 | MODULE_LICENSE("GPL"); | 906 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c index 627ebfb4209b..d004e5845298 100644 --- a/sound/soc/codecs/wm8580.c +++ b/sound/soc/codecs/wm8580.c | |||
@@ -548,13 +548,13 @@ static int wm8580_set_dai_pll(struct snd_soc_dai *codec_dai, | |||
548 | * Set PCM DAI bit size and sample rate. | 548 | * Set PCM DAI bit size and sample rate. |
549 | */ | 549 | */ |
550 | static int wm8580_paif_hw_params(struct snd_pcm_substream *substream, | 550 | static int wm8580_paif_hw_params(struct snd_pcm_substream *substream, |
551 | struct snd_pcm_hw_params *params) | 551 | struct snd_pcm_hw_params *params, |
552 | struct snd_soc_dai *dai) | ||
552 | { | 553 | { |
553 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 554 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
554 | struct snd_soc_dai_link *dai = rtd->dai; | ||
555 | struct snd_soc_device *socdev = rtd->socdev; | 555 | struct snd_soc_device *socdev = rtd->socdev; |
556 | struct snd_soc_codec *codec = socdev->codec; | 556 | struct snd_soc_codec *codec = socdev->codec; |
557 | u16 paifb = wm8580_read(codec, WM8580_PAIF3 + dai->codec_dai->id); | 557 | u16 paifb = wm8580_read(codec, WM8580_PAIF3 + dai->id); |
558 | 558 | ||
559 | paifb &= ~WM8580_AIF_LENGTH_MASK; | 559 | paifb &= ~WM8580_AIF_LENGTH_MASK; |
560 | /* bit size */ | 560 | /* bit size */ |
@@ -574,7 +574,7 @@ static int wm8580_paif_hw_params(struct snd_pcm_substream *substream, | |||
574 | return -EINVAL; | 574 | return -EINVAL; |
575 | } | 575 | } |
576 | 576 | ||
577 | wm8580_write(codec, WM8580_PAIF3 + dai->codec_dai->id, paifb); | 577 | wm8580_write(codec, WM8580_PAIF3 + dai->id, paifb); |
578 | return 0; | 578 | return 0; |
579 | } | 579 | } |
580 | 580 | ||
@@ -798,8 +798,6 @@ struct snd_soc_dai wm8580_dai[] = { | |||
798 | }, | 798 | }, |
799 | .ops = { | 799 | .ops = { |
800 | .hw_params = wm8580_paif_hw_params, | 800 | .hw_params = wm8580_paif_hw_params, |
801 | }, | ||
802 | .dai_ops = { | ||
803 | .set_fmt = wm8580_set_paif_dai_fmt, | 801 | .set_fmt = wm8580_set_paif_dai_fmt, |
804 | .set_clkdiv = wm8580_set_dai_clkdiv, | 802 | .set_clkdiv = wm8580_set_dai_clkdiv, |
805 | .set_pll = wm8580_set_dai_pll, | 803 | .set_pll = wm8580_set_dai_pll, |
@@ -818,8 +816,6 @@ struct snd_soc_dai wm8580_dai[] = { | |||
818 | }, | 816 | }, |
819 | .ops = { | 817 | .ops = { |
820 | .hw_params = wm8580_paif_hw_params, | 818 | .hw_params = wm8580_paif_hw_params, |
821 | }, | ||
822 | .dai_ops = { | ||
823 | .set_fmt = wm8580_set_paif_dai_fmt, | 819 | .set_fmt = wm8580_set_paif_dai_fmt, |
824 | .set_clkdiv = wm8580_set_dai_clkdiv, | 820 | .set_clkdiv = wm8580_set_dai_clkdiv, |
825 | .set_pll = wm8580_set_dai_pll, | 821 | .set_pll = wm8580_set_dai_pll, |
@@ -873,7 +869,7 @@ static int wm8580_init(struct snd_soc_device *socdev) | |||
873 | wm8580_add_controls(codec); | 869 | wm8580_add_controls(codec); |
874 | wm8580_add_widgets(codec); | 870 | wm8580_add_widgets(codec); |
875 | 871 | ||
876 | ret = snd_soc_register_card(socdev); | 872 | ret = snd_soc_init_card(socdev); |
877 | if (ret < 0) { | 873 | if (ret < 0) { |
878 | printk(KERN_ERR "wm8580: failed to register card\n"); | 874 | printk(KERN_ERR "wm8580: failed to register card\n"); |
879 | goto card_err; | 875 | goto card_err; |
@@ -900,85 +896,85 @@ static struct snd_soc_device *wm8580_socdev; | |||
900 | * low = 0x1a | 896 | * low = 0x1a |
901 | * high = 0x1b | 897 | * high = 0x1b |
902 | */ | 898 | */ |
903 | static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END }; | ||
904 | |||
905 | /* Magic definition of all other variables and things */ | ||
906 | I2C_CLIENT_INSMOD; | ||
907 | 899 | ||
908 | static struct i2c_driver wm8580_i2c_driver; | 900 | static int wm8580_i2c_probe(struct i2c_client *i2c, |
909 | static struct i2c_client client_template; | 901 | const struct i2c_device_id *id) |
910 | |||
911 | static int wm8580_codec_probe(struct i2c_adapter *adap, int addr, int kind) | ||
912 | { | 902 | { |
913 | struct snd_soc_device *socdev = wm8580_socdev; | 903 | struct snd_soc_device *socdev = wm8580_socdev; |
914 | struct wm8580_setup_data *setup = socdev->codec_data; | ||
915 | struct snd_soc_codec *codec = socdev->codec; | 904 | struct snd_soc_codec *codec = socdev->codec; |
916 | struct i2c_client *i2c; | ||
917 | int ret; | 905 | int ret; |
918 | 906 | ||
919 | if (addr != setup->i2c_address) | ||
920 | return -ENODEV; | ||
921 | |||
922 | client_template.adapter = adap; | ||
923 | client_template.addr = addr; | ||
924 | |||
925 | i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); | ||
926 | if (i2c == NULL) { | ||
927 | kfree(codec); | ||
928 | return -ENOMEM; | ||
929 | } | ||
930 | i2c_set_clientdata(i2c, codec); | 907 | i2c_set_clientdata(i2c, codec); |
931 | codec->control_data = i2c; | 908 | codec->control_data = i2c; |
932 | 909 | ||
933 | ret = i2c_attach_client(i2c); | ||
934 | if (ret < 0) { | ||
935 | dev_err(&i2c->dev, "failed to attach codec at addr %x\n", addr); | ||
936 | goto err; | ||
937 | } | ||
938 | |||
939 | ret = wm8580_init(socdev); | 910 | ret = wm8580_init(socdev); |
940 | if (ret < 0) { | 911 | if (ret < 0) |
941 | dev_err(&i2c->dev, "failed to initialise WM8580\n"); | 912 | dev_err(&i2c->dev, "failed to initialise WM8580\n"); |
942 | goto err; | ||
943 | } | ||
944 | |||
945 | return ret; | ||
946 | |||
947 | err: | ||
948 | kfree(codec); | ||
949 | kfree(i2c); | ||
950 | return ret; | 913 | return ret; |
951 | } | 914 | } |
952 | 915 | ||
953 | static int wm8580_i2c_detach(struct i2c_client *client) | 916 | static int wm8580_i2c_remove(struct i2c_client *client) |
954 | { | 917 | { |
955 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | 918 | struct snd_soc_codec *codec = i2c_get_clientdata(client); |
956 | i2c_detach_client(client); | ||
957 | kfree(codec->reg_cache); | 919 | kfree(codec->reg_cache); |
958 | kfree(client); | ||
959 | return 0; | 920 | return 0; |
960 | } | 921 | } |
961 | 922 | ||
962 | static int wm8580_i2c_attach(struct i2c_adapter *adap) | 923 | static const struct i2c_device_id wm8580_i2c_id[] = { |
963 | { | 924 | { "wm8580", 0 }, |
964 | return i2c_probe(adap, &addr_data, wm8580_codec_probe); | 925 | { } |
965 | } | 926 | }; |
927 | MODULE_DEVICE_TABLE(i2c, wm8580_i2c_id); | ||
966 | 928 | ||
967 | /* corgi i2c codec control layer */ | ||
968 | static struct i2c_driver wm8580_i2c_driver = { | 929 | static struct i2c_driver wm8580_i2c_driver = { |
969 | .driver = { | 930 | .driver = { |
970 | .name = "WM8580 I2C Codec", | 931 | .name = "WM8580 I2C Codec", |
971 | .owner = THIS_MODULE, | 932 | .owner = THIS_MODULE, |
972 | }, | 933 | }, |
973 | .attach_adapter = wm8580_i2c_attach, | 934 | .probe = wm8580_i2c_probe, |
974 | .detach_client = wm8580_i2c_detach, | 935 | .remove = wm8580_i2c_remove, |
975 | .command = NULL, | 936 | .id_table = wm8580_i2c_id, |
976 | }; | 937 | }; |
977 | 938 | ||
978 | static struct i2c_client client_template = { | 939 | static int wm8580_add_i2c_device(struct platform_device *pdev, |
979 | .name = "WM8580", | 940 | const struct wm8580_setup_data *setup) |
980 | .driver = &wm8580_i2c_driver, | 941 | { |
981 | }; | 942 | struct i2c_board_info info; |
943 | struct i2c_adapter *adapter; | ||
944 | struct i2c_client *client; | ||
945 | int ret; | ||
946 | |||
947 | ret = i2c_add_driver(&wm8580_i2c_driver); | ||
948 | if (ret != 0) { | ||
949 | dev_err(&pdev->dev, "can't add i2c driver\n"); | ||
950 | return ret; | ||
951 | } | ||
952 | |||
953 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
954 | info.addr = setup->i2c_address; | ||
955 | strlcpy(info.type, "wm8580", I2C_NAME_SIZE); | ||
956 | |||
957 | adapter = i2c_get_adapter(setup->i2c_bus); | ||
958 | if (!adapter) { | ||
959 | dev_err(&pdev->dev, "can't get i2c adapter %d\n", | ||
960 | setup->i2c_bus); | ||
961 | goto err_driver; | ||
962 | } | ||
963 | |||
964 | client = i2c_new_device(adapter, &info); | ||
965 | i2c_put_adapter(adapter); | ||
966 | if (!client) { | ||
967 | dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", | ||
968 | (unsigned int)info.addr); | ||
969 | goto err_driver; | ||
970 | } | ||
971 | |||
972 | return 0; | ||
973 | |||
974 | err_driver: | ||
975 | i2c_del_driver(&wm8580_i2c_driver); | ||
976 | return -ENODEV; | ||
977 | } | ||
982 | #endif | 978 | #endif |
983 | 979 | ||
984 | static int wm8580_probe(struct platform_device *pdev) | 980 | static int wm8580_probe(struct platform_device *pdev) |
@@ -1011,11 +1007,8 @@ static int wm8580_probe(struct platform_device *pdev) | |||
1011 | 1007 | ||
1012 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1008 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1013 | if (setup->i2c_address) { | 1009 | if (setup->i2c_address) { |
1014 | normal_i2c[0] = setup->i2c_address; | ||
1015 | codec->hw_write = (hw_write_t)i2c_master_send; | 1010 | codec->hw_write = (hw_write_t)i2c_master_send; |
1016 | ret = i2c_add_driver(&wm8580_i2c_driver); | 1011 | ret = wm8580_add_i2c_device(pdev, setup); |
1017 | if (ret != 0) | ||
1018 | printk(KERN_ERR "can't add i2c driver"); | ||
1019 | } | 1012 | } |
1020 | #else | 1013 | #else |
1021 | /* Add other interfaces here */ | 1014 | /* Add other interfaces here */ |
@@ -1034,6 +1027,7 @@ static int wm8580_remove(struct platform_device *pdev) | |||
1034 | snd_soc_free_pcms(socdev); | 1027 | snd_soc_free_pcms(socdev); |
1035 | snd_soc_dapm_free(socdev); | 1028 | snd_soc_dapm_free(socdev); |
1036 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1029 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1030 | i2c_unregister_device(codec->control_data); | ||
1037 | i2c_del_driver(&wm8580_i2c_driver); | 1031 | i2c_del_driver(&wm8580_i2c_driver); |
1038 | #endif | 1032 | #endif |
1039 | kfree(codec->private_data); | 1033 | kfree(codec->private_data); |
@@ -1048,6 +1042,18 @@ struct snd_soc_codec_device soc_codec_dev_wm8580 = { | |||
1048 | }; | 1042 | }; |
1049 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8580); | 1043 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8580); |
1050 | 1044 | ||
1045 | static int __init wm8580_modinit(void) | ||
1046 | { | ||
1047 | return snd_soc_register_dais(wm8580_dai, ARRAY_SIZE(wm8580_dai)); | ||
1048 | } | ||
1049 | module_init(wm8580_modinit); | ||
1050 | |||
1051 | static void __exit wm8580_exit(void) | ||
1052 | { | ||
1053 | snd_soc_unregister_dais(wm8580_dai, ARRAY_SIZE(wm8580_dai)); | ||
1054 | } | ||
1055 | module_exit(wm8580_exit); | ||
1056 | |||
1051 | MODULE_DESCRIPTION("ASoC WM8580 driver"); | 1057 | MODULE_DESCRIPTION("ASoC WM8580 driver"); |
1052 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | 1058 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
1053 | MODULE_LICENSE("GPL"); | 1059 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/wm8580.h b/sound/soc/codecs/wm8580.h index 589ddaba21d7..09e4422f6f2f 100644 --- a/sound/soc/codecs/wm8580.h +++ b/sound/soc/codecs/wm8580.h | |||
@@ -29,6 +29,7 @@ | |||
29 | #define WM8580_CLKSRC_NONE 5 | 29 | #define WM8580_CLKSRC_NONE 5 |
30 | 30 | ||
31 | struct wm8580_setup_data { | 31 | struct wm8580_setup_data { |
32 | int i2c_bus; | ||
32 | unsigned short i2c_address; | 33 | unsigned short i2c_address; |
33 | }; | 34 | }; |
34 | 35 | ||
diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c new file mode 100644 index 000000000000..80b11983e137 --- /dev/null +++ b/sound/soc/codecs/wm8728.c | |||
@@ -0,0 +1,585 @@ | |||
1 | /* | ||
2 | * wm8728.c -- WM8728 ALSA SoC Audio driver | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics plc | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
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 | #include <linux/module.h> | ||
14 | #include <linux/moduleparam.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/delay.h> | ||
17 | #include <linux/pm.h> | ||
18 | #include <linux/i2c.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | #include <linux/spi/spi.h> | ||
21 | #include <sound/core.h> | ||
22 | #include <sound/pcm.h> | ||
23 | #include <sound/pcm_params.h> | ||
24 | #include <sound/soc.h> | ||
25 | #include <sound/soc-dapm.h> | ||
26 | #include <sound/initval.h> | ||
27 | #include <sound/tlv.h> | ||
28 | |||
29 | #include "wm8728.h" | ||
30 | |||
31 | struct snd_soc_codec_device soc_codec_dev_wm8728; | ||
32 | |||
33 | /* | ||
34 | * We can't read the WM8728 register space so we cache them instead. | ||
35 | * Note that the defaults here aren't the physical defaults, we latch | ||
36 | * the volume update bits, mute the output and enable infinite zero | ||
37 | * detect. | ||
38 | */ | ||
39 | static const u16 wm8728_reg_defaults[] = { | ||
40 | 0x1ff, | ||
41 | 0x1ff, | ||
42 | 0x001, | ||
43 | 0x100, | ||
44 | }; | ||
45 | |||
46 | static inline unsigned int wm8728_read_reg_cache(struct snd_soc_codec *codec, | ||
47 | unsigned int reg) | ||
48 | { | ||
49 | u16 *cache = codec->reg_cache; | ||
50 | BUG_ON(reg > ARRAY_SIZE(wm8728_reg_defaults)); | ||
51 | return cache[reg]; | ||
52 | } | ||
53 | |||
54 | static inline void wm8728_write_reg_cache(struct snd_soc_codec *codec, | ||
55 | u16 reg, unsigned int value) | ||
56 | { | ||
57 | u16 *cache = codec->reg_cache; | ||
58 | BUG_ON(reg > ARRAY_SIZE(wm8728_reg_defaults)); | ||
59 | cache[reg] = value; | ||
60 | } | ||
61 | |||
62 | /* | ||
63 | * write to the WM8728 register space | ||
64 | */ | ||
65 | static int wm8728_write(struct snd_soc_codec *codec, unsigned int reg, | ||
66 | unsigned int value) | ||
67 | { | ||
68 | u8 data[2]; | ||
69 | |||
70 | /* data is | ||
71 | * D15..D9 WM8728 register offset | ||
72 | * D8...D0 register data | ||
73 | */ | ||
74 | data[0] = (reg << 1) | ((value >> 8) & 0x0001); | ||
75 | data[1] = value & 0x00ff; | ||
76 | |||
77 | wm8728_write_reg_cache(codec, reg, value); | ||
78 | |||
79 | if (codec->hw_write(codec->control_data, data, 2) == 2) | ||
80 | return 0; | ||
81 | else | ||
82 | return -EIO; | ||
83 | } | ||
84 | |||
85 | static const DECLARE_TLV_DB_SCALE(wm8728_tlv, -12750, 50, 1); | ||
86 | |||
87 | static const struct snd_kcontrol_new wm8728_snd_controls[] = { | ||
88 | |||
89 | SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8728_DACLVOL, WM8728_DACRVOL, | ||
90 | 0, 255, 0, wm8728_tlv), | ||
91 | |||
92 | SOC_SINGLE("Deemphasis", WM8728_DACCTL, 1, 1, 0), | ||
93 | }; | ||
94 | |||
95 | static int wm8728_add_controls(struct snd_soc_codec *codec) | ||
96 | { | ||
97 | int err, i; | ||
98 | |||
99 | for (i = 0; i < ARRAY_SIZE(wm8728_snd_controls); i++) { | ||
100 | err = snd_ctl_add(codec->card, | ||
101 | snd_soc_cnew(&wm8728_snd_controls[i], | ||
102 | codec, NULL)); | ||
103 | if (err < 0) | ||
104 | return err; | ||
105 | } | ||
106 | |||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | /* | ||
111 | * DAPM controls. | ||
112 | */ | ||
113 | static const struct snd_soc_dapm_widget wm8728_dapm_widgets[] = { | ||
114 | SND_SOC_DAPM_DAC("DAC", "HiFi Playback", SND_SOC_NOPM, 0, 0), | ||
115 | SND_SOC_DAPM_OUTPUT("VOUTL"), | ||
116 | SND_SOC_DAPM_OUTPUT("VOUTR"), | ||
117 | }; | ||
118 | |||
119 | static const struct snd_soc_dapm_route intercon[] = { | ||
120 | {"VOUTL", NULL, "DAC"}, | ||
121 | {"VOUTR", NULL, "DAC"}, | ||
122 | }; | ||
123 | |||
124 | static int wm8728_add_widgets(struct snd_soc_codec *codec) | ||
125 | { | ||
126 | snd_soc_dapm_new_controls(codec, wm8728_dapm_widgets, | ||
127 | ARRAY_SIZE(wm8728_dapm_widgets)); | ||
128 | |||
129 | snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); | ||
130 | |||
131 | snd_soc_dapm_new_widgets(codec); | ||
132 | |||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | static int wm8728_mute(struct snd_soc_dai *dai, int mute) | ||
137 | { | ||
138 | struct snd_soc_codec *codec = dai->codec; | ||
139 | u16 mute_reg = wm8728_read_reg_cache(codec, WM8728_DACCTL); | ||
140 | |||
141 | if (mute) | ||
142 | wm8728_write(codec, WM8728_DACCTL, mute_reg | 1); | ||
143 | else | ||
144 | wm8728_write(codec, WM8728_DACCTL, mute_reg & ~1); | ||
145 | |||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | static int wm8728_hw_params(struct snd_pcm_substream *substream, | ||
150 | struct snd_pcm_hw_params *params, | ||
151 | struct snd_soc_dai *dai) | ||
152 | { | ||
153 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
154 | struct snd_soc_device *socdev = rtd->socdev; | ||
155 | struct snd_soc_codec *codec = socdev->codec; | ||
156 | u16 dac = wm8728_read_reg_cache(codec, WM8728_DACCTL); | ||
157 | |||
158 | dac &= ~0x18; | ||
159 | |||
160 | switch (params_format(params)) { | ||
161 | case SNDRV_PCM_FORMAT_S16_LE: | ||
162 | break; | ||
163 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
164 | dac |= 0x10; | ||
165 | break; | ||
166 | case SNDRV_PCM_FORMAT_S24_LE: | ||
167 | dac |= 0x08; | ||
168 | break; | ||
169 | default: | ||
170 | return -EINVAL; | ||
171 | } | ||
172 | |||
173 | wm8728_write(codec, WM8728_DACCTL, dac); | ||
174 | |||
175 | return 0; | ||
176 | } | ||
177 | |||
178 | static int wm8728_set_dai_fmt(struct snd_soc_dai *codec_dai, | ||
179 | unsigned int fmt) | ||
180 | { | ||
181 | struct snd_soc_codec *codec = codec_dai->codec; | ||
182 | u16 iface = wm8728_read_reg_cache(codec, WM8728_IFCTL); | ||
183 | |||
184 | /* Currently only I2S is supported by the driver, though the | ||
185 | * hardware is more flexible. | ||
186 | */ | ||
187 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
188 | case SND_SOC_DAIFMT_I2S: | ||
189 | iface |= 1; | ||
190 | break; | ||
191 | default: | ||
192 | return -EINVAL; | ||
193 | } | ||
194 | |||
195 | /* The hardware only support full slave mode */ | ||
196 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
197 | case SND_SOC_DAIFMT_CBS_CFS: | ||
198 | break; | ||
199 | default: | ||
200 | return -EINVAL; | ||
201 | } | ||
202 | |||
203 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
204 | case SND_SOC_DAIFMT_NB_NF: | ||
205 | iface &= ~0x22; | ||
206 | break; | ||
207 | case SND_SOC_DAIFMT_IB_NF: | ||
208 | iface |= 0x20; | ||
209 | iface &= ~0x02; | ||
210 | break; | ||
211 | case SND_SOC_DAIFMT_NB_IF: | ||
212 | iface |= 0x02; | ||
213 | iface &= ~0x20; | ||
214 | break; | ||
215 | case SND_SOC_DAIFMT_IB_IF: | ||
216 | iface |= 0x22; | ||
217 | break; | ||
218 | default: | ||
219 | return -EINVAL; | ||
220 | } | ||
221 | |||
222 | wm8728_write(codec, WM8728_IFCTL, iface); | ||
223 | return 0; | ||
224 | } | ||
225 | |||
226 | static int wm8728_set_bias_level(struct snd_soc_codec *codec, | ||
227 | enum snd_soc_bias_level level) | ||
228 | { | ||
229 | u16 reg; | ||
230 | int i; | ||
231 | |||
232 | switch (level) { | ||
233 | case SND_SOC_BIAS_ON: | ||
234 | case SND_SOC_BIAS_PREPARE: | ||
235 | case SND_SOC_BIAS_STANDBY: | ||
236 | if (codec->bias_level == SND_SOC_BIAS_OFF) { | ||
237 | /* Power everything up... */ | ||
238 | reg = wm8728_read_reg_cache(codec, WM8728_DACCTL); | ||
239 | wm8728_write(codec, WM8728_DACCTL, reg & ~0x4); | ||
240 | |||
241 | /* ..then sync in the register cache. */ | ||
242 | for (i = 0; i < ARRAY_SIZE(wm8728_reg_defaults); i++) | ||
243 | wm8728_write(codec, i, | ||
244 | wm8728_read_reg_cache(codec, i)); | ||
245 | } | ||
246 | break; | ||
247 | |||
248 | case SND_SOC_BIAS_OFF: | ||
249 | reg = wm8728_read_reg_cache(codec, WM8728_DACCTL); | ||
250 | wm8728_write(codec, WM8728_DACCTL, reg | 0x4); | ||
251 | break; | ||
252 | } | ||
253 | codec->bias_level = level; | ||
254 | return 0; | ||
255 | } | ||
256 | |||
257 | #define WM8728_RATES (SNDRV_PCM_RATE_8000_192000) | ||
258 | |||
259 | #define WM8728_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | ||
260 | SNDRV_PCM_FMTBIT_S24_LE) | ||
261 | |||
262 | struct snd_soc_dai wm8728_dai = { | ||
263 | .name = "WM8728", | ||
264 | .playback = { | ||
265 | .stream_name = "Playback", | ||
266 | .channels_min = 2, | ||
267 | .channels_max = 2, | ||
268 | .rates = WM8728_RATES, | ||
269 | .formats = WM8728_FORMATS, | ||
270 | }, | ||
271 | .ops = { | ||
272 | .hw_params = wm8728_hw_params, | ||
273 | .digital_mute = wm8728_mute, | ||
274 | .set_fmt = wm8728_set_dai_fmt, | ||
275 | } | ||
276 | }; | ||
277 | EXPORT_SYMBOL_GPL(wm8728_dai); | ||
278 | |||
279 | static int wm8728_suspend(struct platform_device *pdev, pm_message_t state) | ||
280 | { | ||
281 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
282 | struct snd_soc_codec *codec = socdev->codec; | ||
283 | |||
284 | wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
285 | |||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static int wm8728_resume(struct platform_device *pdev) | ||
290 | { | ||
291 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
292 | struct snd_soc_codec *codec = socdev->codec; | ||
293 | |||
294 | wm8728_set_bias_level(codec, codec->suspend_bias_level); | ||
295 | |||
296 | return 0; | ||
297 | } | ||
298 | |||
299 | /* | ||
300 | * initialise the WM8728 driver | ||
301 | * register the mixer and dsp interfaces with the kernel | ||
302 | */ | ||
303 | static int wm8728_init(struct snd_soc_device *socdev) | ||
304 | { | ||
305 | struct snd_soc_codec *codec = socdev->codec; | ||
306 | int ret = 0; | ||
307 | |||
308 | codec->name = "WM8728"; | ||
309 | codec->owner = THIS_MODULE; | ||
310 | codec->read = wm8728_read_reg_cache; | ||
311 | codec->write = wm8728_write; | ||
312 | codec->set_bias_level = wm8728_set_bias_level; | ||
313 | codec->dai = &wm8728_dai; | ||
314 | codec->num_dai = 1; | ||
315 | codec->bias_level = SND_SOC_BIAS_OFF; | ||
316 | codec->reg_cache_size = ARRAY_SIZE(wm8728_reg_defaults); | ||
317 | codec->reg_cache = kmemdup(wm8728_reg_defaults, | ||
318 | sizeof(wm8728_reg_defaults), | ||
319 | GFP_KERNEL); | ||
320 | if (codec->reg_cache == NULL) | ||
321 | return -ENOMEM; | ||
322 | |||
323 | /* register pcms */ | ||
324 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
325 | if (ret < 0) { | ||
326 | printk(KERN_ERR "wm8728: failed to create pcms\n"); | ||
327 | goto pcm_err; | ||
328 | } | ||
329 | |||
330 | /* power on device */ | ||
331 | wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
332 | |||
333 | wm8728_add_controls(codec); | ||
334 | wm8728_add_widgets(codec); | ||
335 | ret = snd_soc_init_card(socdev); | ||
336 | if (ret < 0) { | ||
337 | printk(KERN_ERR "wm8728: failed to register card\n"); | ||
338 | goto card_err; | ||
339 | } | ||
340 | |||
341 | return ret; | ||
342 | |||
343 | card_err: | ||
344 | snd_soc_free_pcms(socdev); | ||
345 | snd_soc_dapm_free(socdev); | ||
346 | pcm_err: | ||
347 | kfree(codec->reg_cache); | ||
348 | return ret; | ||
349 | } | ||
350 | |||
351 | static struct snd_soc_device *wm8728_socdev; | ||
352 | |||
353 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
354 | |||
355 | /* | ||
356 | * WM8728 2 wire address is determined by GPIO5 | ||
357 | * state during powerup. | ||
358 | * low = 0x1a | ||
359 | * high = 0x1b | ||
360 | */ | ||
361 | |||
362 | static int wm8728_i2c_probe(struct i2c_client *i2c, | ||
363 | const struct i2c_device_id *id) | ||
364 | { | ||
365 | struct snd_soc_device *socdev = wm8728_socdev; | ||
366 | struct snd_soc_codec *codec = socdev->codec; | ||
367 | int ret; | ||
368 | |||
369 | i2c_set_clientdata(i2c, codec); | ||
370 | codec->control_data = i2c; | ||
371 | |||
372 | ret = wm8728_init(socdev); | ||
373 | if (ret < 0) | ||
374 | pr_err("failed to initialise WM8728\n"); | ||
375 | |||
376 | return ret; | ||
377 | } | ||
378 | |||
379 | static int wm8728_i2c_remove(struct i2c_client *client) | ||
380 | { | ||
381 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | ||
382 | kfree(codec->reg_cache); | ||
383 | return 0; | ||
384 | } | ||
385 | |||
386 | static const struct i2c_device_id wm8728_i2c_id[] = { | ||
387 | { "wm8728", 0 }, | ||
388 | { } | ||
389 | }; | ||
390 | MODULE_DEVICE_TABLE(i2c, wm8728_i2c_id); | ||
391 | |||
392 | static struct i2c_driver wm8728_i2c_driver = { | ||
393 | .driver = { | ||
394 | .name = "WM8728 I2C Codec", | ||
395 | .owner = THIS_MODULE, | ||
396 | }, | ||
397 | .probe = wm8728_i2c_probe, | ||
398 | .remove = wm8728_i2c_remove, | ||
399 | .id_table = wm8728_i2c_id, | ||
400 | }; | ||
401 | |||
402 | static int wm8728_add_i2c_device(struct platform_device *pdev, | ||
403 | const struct wm8728_setup_data *setup) | ||
404 | { | ||
405 | struct i2c_board_info info; | ||
406 | struct i2c_adapter *adapter; | ||
407 | struct i2c_client *client; | ||
408 | int ret; | ||
409 | |||
410 | ret = i2c_add_driver(&wm8728_i2c_driver); | ||
411 | if (ret != 0) { | ||
412 | dev_err(&pdev->dev, "can't add i2c driver\n"); | ||
413 | return ret; | ||
414 | } | ||
415 | |||
416 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
417 | info.addr = setup->i2c_address; | ||
418 | strlcpy(info.type, "wm8728", I2C_NAME_SIZE); | ||
419 | |||
420 | adapter = i2c_get_adapter(setup->i2c_bus); | ||
421 | if (!adapter) { | ||
422 | dev_err(&pdev->dev, "can't get i2c adapter %d\n", | ||
423 | setup->i2c_bus); | ||
424 | goto err_driver; | ||
425 | } | ||
426 | |||
427 | client = i2c_new_device(adapter, &info); | ||
428 | i2c_put_adapter(adapter); | ||
429 | if (!client) { | ||
430 | dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", | ||
431 | (unsigned int)info.addr); | ||
432 | goto err_driver; | ||
433 | } | ||
434 | |||
435 | return 0; | ||
436 | |||
437 | err_driver: | ||
438 | i2c_del_driver(&wm8728_i2c_driver); | ||
439 | return -ENODEV; | ||
440 | } | ||
441 | #endif | ||
442 | |||
443 | #if defined(CONFIG_SPI_MASTER) | ||
444 | static int __devinit wm8728_spi_probe(struct spi_device *spi) | ||
445 | { | ||
446 | struct snd_soc_device *socdev = wm8728_socdev; | ||
447 | struct snd_soc_codec *codec = socdev->codec; | ||
448 | int ret; | ||
449 | |||
450 | codec->control_data = spi; | ||
451 | |||
452 | ret = wm8728_init(socdev); | ||
453 | if (ret < 0) | ||
454 | dev_err(&spi->dev, "failed to initialise WM8728\n"); | ||
455 | |||
456 | return ret; | ||
457 | } | ||
458 | |||
459 | static int __devexit wm8728_spi_remove(struct spi_device *spi) | ||
460 | { | ||
461 | return 0; | ||
462 | } | ||
463 | |||
464 | static struct spi_driver wm8728_spi_driver = { | ||
465 | .driver = { | ||
466 | .name = "wm8728", | ||
467 | .bus = &spi_bus_type, | ||
468 | .owner = THIS_MODULE, | ||
469 | }, | ||
470 | .probe = wm8728_spi_probe, | ||
471 | .remove = __devexit_p(wm8728_spi_remove), | ||
472 | }; | ||
473 | |||
474 | static int wm8728_spi_write(struct spi_device *spi, const char *data, int len) | ||
475 | { | ||
476 | struct spi_transfer t; | ||
477 | struct spi_message m; | ||
478 | u8 msg[2]; | ||
479 | |||
480 | if (len <= 0) | ||
481 | return 0; | ||
482 | |||
483 | msg[0] = data[0]; | ||
484 | msg[1] = data[1]; | ||
485 | |||
486 | spi_message_init(&m); | ||
487 | memset(&t, 0, (sizeof t)); | ||
488 | |||
489 | t.tx_buf = &msg[0]; | ||
490 | t.len = len; | ||
491 | |||
492 | spi_message_add_tail(&t, &m); | ||
493 | spi_sync(spi, &m); | ||
494 | |||
495 | return len; | ||
496 | } | ||
497 | #endif /* CONFIG_SPI_MASTER */ | ||
498 | |||
499 | static int wm8728_probe(struct platform_device *pdev) | ||
500 | { | ||
501 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
502 | struct wm8728_setup_data *setup; | ||
503 | struct snd_soc_codec *codec; | ||
504 | int ret = 0; | ||
505 | |||
506 | setup = socdev->codec_data; | ||
507 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | ||
508 | if (codec == NULL) | ||
509 | return -ENOMEM; | ||
510 | |||
511 | socdev->codec = codec; | ||
512 | mutex_init(&codec->mutex); | ||
513 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
514 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
515 | |||
516 | wm8728_socdev = socdev; | ||
517 | ret = -ENODEV; | ||
518 | |||
519 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
520 | if (setup->i2c_address) { | ||
521 | codec->hw_write = (hw_write_t)i2c_master_send; | ||
522 | ret = wm8728_add_i2c_device(pdev, setup); | ||
523 | } | ||
524 | #endif | ||
525 | #if defined(CONFIG_SPI_MASTER) | ||
526 | if (setup->spi) { | ||
527 | codec->hw_write = (hw_write_t)wm8728_spi_write; | ||
528 | ret = spi_register_driver(&wm8728_spi_driver); | ||
529 | if (ret != 0) | ||
530 | printk(KERN_ERR "can't add spi driver"); | ||
531 | } | ||
532 | #endif | ||
533 | |||
534 | if (ret != 0) | ||
535 | kfree(codec); | ||
536 | |||
537 | return ret; | ||
538 | } | ||
539 | |||
540 | /* power down chip */ | ||
541 | static int wm8728_remove(struct platform_device *pdev) | ||
542 | { | ||
543 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
544 | struct snd_soc_codec *codec = socdev->codec; | ||
545 | |||
546 | if (codec->control_data) | ||
547 | wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
548 | |||
549 | snd_soc_free_pcms(socdev); | ||
550 | snd_soc_dapm_free(socdev); | ||
551 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
552 | i2c_unregister_device(codec->control_data); | ||
553 | i2c_del_driver(&wm8728_i2c_driver); | ||
554 | #endif | ||
555 | #if defined(CONFIG_SPI_MASTER) | ||
556 | spi_unregister_driver(&wm8728_spi_driver); | ||
557 | #endif | ||
558 | kfree(codec); | ||
559 | |||
560 | return 0; | ||
561 | } | ||
562 | |||
563 | struct snd_soc_codec_device soc_codec_dev_wm8728 = { | ||
564 | .probe = wm8728_probe, | ||
565 | .remove = wm8728_remove, | ||
566 | .suspend = wm8728_suspend, | ||
567 | .resume = wm8728_resume, | ||
568 | }; | ||
569 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8728); | ||
570 | |||
571 | static int __init wm8728_modinit(void) | ||
572 | { | ||
573 | return snd_soc_register_dai(&wm8728_dai); | ||
574 | } | ||
575 | module_init(wm8728_modinit); | ||
576 | |||
577 | static void __exit wm8728_exit(void) | ||
578 | { | ||
579 | snd_soc_unregister_dai(&wm8728_dai); | ||
580 | } | ||
581 | module_exit(wm8728_exit); | ||
582 | |||
583 | MODULE_DESCRIPTION("ASoC WM8728 driver"); | ||
584 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
585 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/codecs/wm8728.h b/sound/soc/codecs/wm8728.h new file mode 100644 index 000000000000..d269c132474b --- /dev/null +++ b/sound/soc/codecs/wm8728.h | |||
@@ -0,0 +1,30 @@ | |||
1 | /* | ||
2 | * wm8728.h -- WM8728 ASoC codec driver | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics plc | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
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 | #ifndef _WM8728_H | ||
14 | #define _WM8728_H | ||
15 | |||
16 | #define WM8728_DACLVOL 0x00 | ||
17 | #define WM8728_DACRVOL 0x01 | ||
18 | #define WM8728_DACCTL 0x02 | ||
19 | #define WM8728_IFCTL 0x03 | ||
20 | |||
21 | struct wm8728_setup_data { | ||
22 | int spi; | ||
23 | int i2c_bus; | ||
24 | unsigned short i2c_address; | ||
25 | }; | ||
26 | |||
27 | extern struct snd_soc_dai wm8728_dai; | ||
28 | extern struct snd_soc_codec_device soc_codec_dev_wm8728; | ||
29 | |||
30 | #endif | ||
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c index 7f8a7e36b33e..c444b9f2701e 100644 --- a/sound/soc/codecs/wm8731.c +++ b/sound/soc/codecs/wm8731.c | |||
@@ -264,7 +264,8 @@ static inline int get_coeff(int mclk, int rate) | |||
264 | } | 264 | } |
265 | 265 | ||
266 | static int wm8731_hw_params(struct snd_pcm_substream *substream, | 266 | static int wm8731_hw_params(struct snd_pcm_substream *substream, |
267 | struct snd_pcm_hw_params *params) | 267 | struct snd_pcm_hw_params *params, |
268 | struct snd_soc_dai *dai) | ||
268 | { | 269 | { |
269 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 270 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
270 | struct snd_soc_device *socdev = rtd->socdev; | 271 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -293,7 +294,8 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream, | |||
293 | return 0; | 294 | return 0; |
294 | } | 295 | } |
295 | 296 | ||
296 | static int wm8731_pcm_prepare(struct snd_pcm_substream *substream) | 297 | static int wm8731_pcm_prepare(struct snd_pcm_substream *substream, |
298 | struct snd_soc_dai *dai) | ||
297 | { | 299 | { |
298 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 300 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
299 | struct snd_soc_device *socdev = rtd->socdev; | 301 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -305,7 +307,8 @@ static int wm8731_pcm_prepare(struct snd_pcm_substream *substream) | |||
305 | return 0; | 307 | return 0; |
306 | } | 308 | } |
307 | 309 | ||
308 | static void wm8731_shutdown(struct snd_pcm_substream *substream) | 310 | static void wm8731_shutdown(struct snd_pcm_substream *substream, |
311 | struct snd_soc_dai *dai) | ||
309 | { | 312 | { |
310 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 313 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
311 | struct snd_soc_device *socdev = rtd->socdev; | 314 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -461,8 +464,6 @@ struct snd_soc_dai wm8731_dai = { | |||
461 | .prepare = wm8731_pcm_prepare, | 464 | .prepare = wm8731_pcm_prepare, |
462 | .hw_params = wm8731_hw_params, | 465 | .hw_params = wm8731_hw_params, |
463 | .shutdown = wm8731_shutdown, | 466 | .shutdown = wm8731_shutdown, |
464 | }, | ||
465 | .dai_ops = { | ||
466 | .digital_mute = wm8731_mute, | 467 | .digital_mute = wm8731_mute, |
467 | .set_sysclk = wm8731_set_dai_sysclk, | 468 | .set_sysclk = wm8731_set_dai_sysclk, |
468 | .set_fmt = wm8731_set_dai_fmt, | 469 | .set_fmt = wm8731_set_dai_fmt, |
@@ -544,7 +545,7 @@ static int wm8731_init(struct snd_soc_device *socdev) | |||
544 | 545 | ||
545 | wm8731_add_controls(codec); | 546 | wm8731_add_controls(codec); |
546 | wm8731_add_widgets(codec); | 547 | wm8731_add_widgets(codec); |
547 | ret = snd_soc_register_card(socdev); | 548 | ret = snd_soc_init_card(socdev); |
548 | if (ret < 0) { | 549 | if (ret < 0) { |
549 | printk(KERN_ERR "wm8731: failed to register card\n"); | 550 | printk(KERN_ERR "wm8731: failed to register card\n"); |
550 | goto card_err; | 551 | goto card_err; |
@@ -792,6 +793,18 @@ struct snd_soc_codec_device soc_codec_dev_wm8731 = { | |||
792 | }; | 793 | }; |
793 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); | 794 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); |
794 | 795 | ||
796 | static int __init wm8731_modinit(void) | ||
797 | { | ||
798 | return snd_soc_register_dai(&wm8731_dai); | ||
799 | } | ||
800 | module_init(wm8731_modinit); | ||
801 | |||
802 | static void __exit wm8731_exit(void) | ||
803 | { | ||
804 | snd_soc_unregister_dai(&wm8731_dai); | ||
805 | } | ||
806 | module_exit(wm8731_exit); | ||
807 | |||
795 | MODULE_DESCRIPTION("ASoC WM8731 driver"); | 808 | MODULE_DESCRIPTION("ASoC WM8731 driver"); |
796 | MODULE_AUTHOR("Richard Purdie"); | 809 | MODULE_AUTHOR("Richard Purdie"); |
797 | MODULE_LICENSE("GPL"); | 810 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c index 9b7296ee5b08..5997fa68e0d5 100644 --- a/sound/soc/codecs/wm8750.c +++ b/sound/soc/codecs/wm8750.c | |||
@@ -614,7 +614,8 @@ static int wm8750_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
614 | } | 614 | } |
615 | 615 | ||
616 | static int wm8750_pcm_hw_params(struct snd_pcm_substream *substream, | 616 | static int wm8750_pcm_hw_params(struct snd_pcm_substream *substream, |
617 | struct snd_pcm_hw_params *params) | 617 | struct snd_pcm_hw_params *params, |
618 | struct snd_soc_dai *dai) | ||
618 | { | 619 | { |
619 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 620 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
620 | struct snd_soc_device *socdev = rtd->socdev; | 621 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -709,8 +710,6 @@ struct snd_soc_dai wm8750_dai = { | |||
709 | .formats = WM8750_FORMATS,}, | 710 | .formats = WM8750_FORMATS,}, |
710 | .ops = { | 711 | .ops = { |
711 | .hw_params = wm8750_pcm_hw_params, | 712 | .hw_params = wm8750_pcm_hw_params, |
712 | }, | ||
713 | .dai_ops = { | ||
714 | .digital_mute = wm8750_mute, | 713 | .digital_mute = wm8750_mute, |
715 | .set_fmt = wm8750_set_dai_fmt, | 714 | .set_fmt = wm8750_set_dai_fmt, |
716 | .set_sysclk = wm8750_set_dai_sysclk, | 715 | .set_sysclk = wm8750_set_dai_sysclk, |
@@ -819,7 +818,7 @@ static int wm8750_init(struct snd_soc_device *socdev) | |||
819 | 818 | ||
820 | wm8750_add_controls(codec); | 819 | wm8750_add_controls(codec); |
821 | wm8750_add_widgets(codec); | 820 | wm8750_add_widgets(codec); |
822 | ret = snd_soc_register_card(socdev); | 821 | ret = snd_soc_init_card(socdev); |
823 | if (ret < 0) { | 822 | if (ret < 0) { |
824 | printk(KERN_ERR "wm8750: failed to register card\n"); | 823 | printk(KERN_ERR "wm8750: failed to register card\n"); |
825 | goto card_err; | 824 | goto card_err; |
@@ -1086,6 +1085,18 @@ struct snd_soc_codec_device soc_codec_dev_wm8750 = { | |||
1086 | }; | 1085 | }; |
1087 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8750); | 1086 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8750); |
1088 | 1087 | ||
1088 | static int __init wm8750_modinit(void) | ||
1089 | { | ||
1090 | return snd_soc_register_dai(&wm8750_dai); | ||
1091 | } | ||
1092 | module_init(wm8750_modinit); | ||
1093 | |||
1094 | static void __exit wm8750_exit(void) | ||
1095 | { | ||
1096 | snd_soc_unregister_dai(&wm8750_dai); | ||
1097 | } | ||
1098 | module_exit(wm8750_exit); | ||
1099 | |||
1089 | MODULE_DESCRIPTION("ASoC WM8750 driver"); | 1100 | MODULE_DESCRIPTION("ASoC WM8750 driver"); |
1090 | MODULE_AUTHOR("Liam Girdwood"); | 1101 | MODULE_AUTHOR("Liam Girdwood"); |
1091 | MODULE_LICENSE("GPL"); | 1102 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c index d426eaa22185..6c21b50c9375 100644 --- a/sound/soc/codecs/wm8753.c +++ b/sound/soc/codecs/wm8753.c | |||
@@ -922,7 +922,8 @@ static int wm8753_vdac_adc_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
922 | * Set PCM DAI bit size and sample rate. | 922 | * Set PCM DAI bit size and sample rate. |
923 | */ | 923 | */ |
924 | static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream, | 924 | static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream, |
925 | struct snd_pcm_hw_params *params) | 925 | struct snd_pcm_hw_params *params, |
926 | struct snd_soc_dai *dai) | ||
926 | { | 927 | { |
927 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 928 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
928 | struct snd_soc_device *socdev = rtd->socdev; | 929 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -1155,7 +1156,8 @@ static int wm8753_i2s_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
1155 | * Set PCM DAI bit size and sample rate. | 1156 | * Set PCM DAI bit size and sample rate. |
1156 | */ | 1157 | */ |
1157 | static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream, | 1158 | static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream, |
1158 | struct snd_pcm_hw_params *params) | 1159 | struct snd_pcm_hw_params *params, |
1160 | struct snd_soc_dai *dai) | ||
1159 | { | 1161 | { |
1160 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1162 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
1161 | struct snd_soc_device *socdev = rtd->socdev; | 1163 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -1323,16 +1325,15 @@ static const struct snd_soc_dai wm8753_all_dai[] = { | |||
1323 | .channels_min = 1, | 1325 | .channels_min = 1, |
1324 | .channels_max = 2, | 1326 | .channels_max = 2, |
1325 | .rates = WM8753_RATES, | 1327 | .rates = WM8753_RATES, |
1326 | .formats = WM8753_FORMATS,}, | 1328 | .formats = WM8753_FORMATS}, |
1327 | .capture = { /* dummy for fast DAI switching */ | 1329 | .capture = { /* dummy for fast DAI switching */ |
1328 | .stream_name = "Capture", | 1330 | .stream_name = "Capture", |
1329 | .channels_min = 1, | 1331 | .channels_min = 1, |
1330 | .channels_max = 2, | 1332 | .channels_max = 2, |
1331 | .rates = WM8753_RATES, | 1333 | .rates = WM8753_RATES, |
1332 | .formats = WM8753_FORMATS,}, | 1334 | .formats = WM8753_FORMATS}, |
1333 | .ops = { | 1335 | .ops = { |
1334 | .hw_params = wm8753_i2s_hw_params,}, | 1336 | .hw_params = wm8753_i2s_hw_params, |
1335 | .dai_ops = { | ||
1336 | .digital_mute = wm8753_mute, | 1337 | .digital_mute = wm8753_mute, |
1337 | .set_fmt = wm8753_mode1h_set_dai_fmt, | 1338 | .set_fmt = wm8753_mode1h_set_dai_fmt, |
1338 | .set_clkdiv = wm8753_set_dai_clkdiv, | 1339 | .set_clkdiv = wm8753_set_dai_clkdiv, |
@@ -1356,8 +1357,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = { | |||
1356 | .rates = WM8753_RATES, | 1357 | .rates = WM8753_RATES, |
1357 | .formats = WM8753_FORMATS,}, | 1358 | .formats = WM8753_FORMATS,}, |
1358 | .ops = { | 1359 | .ops = { |
1359 | .hw_params = wm8753_pcm_hw_params,}, | 1360 | .hw_params = wm8753_pcm_hw_params, |
1360 | .dai_ops = { | ||
1361 | .digital_mute = wm8753_mute, | 1361 | .digital_mute = wm8753_mute, |
1362 | .set_fmt = wm8753_mode1v_set_dai_fmt, | 1362 | .set_fmt = wm8753_mode1v_set_dai_fmt, |
1363 | .set_clkdiv = wm8753_set_dai_clkdiv, | 1363 | .set_clkdiv = wm8753_set_dai_clkdiv, |
@@ -1385,8 +1385,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = { | |||
1385 | .rates = WM8753_RATES, | 1385 | .rates = WM8753_RATES, |
1386 | .formats = WM8753_FORMATS,}, | 1386 | .formats = WM8753_FORMATS,}, |
1387 | .ops = { | 1387 | .ops = { |
1388 | .hw_params = wm8753_pcm_hw_params,}, | 1388 | .hw_params = wm8753_pcm_hw_params, |
1389 | .dai_ops = { | ||
1390 | .digital_mute = wm8753_mute, | 1389 | .digital_mute = wm8753_mute, |
1391 | .set_fmt = wm8753_mode2_set_dai_fmt, | 1390 | .set_fmt = wm8753_mode2_set_dai_fmt, |
1392 | .set_clkdiv = wm8753_set_dai_clkdiv, | 1391 | .set_clkdiv = wm8753_set_dai_clkdiv, |
@@ -1410,8 +1409,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = { | |||
1410 | .rates = WM8753_RATES, | 1409 | .rates = WM8753_RATES, |
1411 | .formats = WM8753_FORMATS,}, | 1410 | .formats = WM8753_FORMATS,}, |
1412 | .ops = { | 1411 | .ops = { |
1413 | .hw_params = wm8753_i2s_hw_params,}, | 1412 | .hw_params = wm8753_i2s_hw_params, |
1414 | .dai_ops = { | ||
1415 | .digital_mute = wm8753_mute, | 1413 | .digital_mute = wm8753_mute, |
1416 | .set_fmt = wm8753_mode3_4_set_dai_fmt, | 1414 | .set_fmt = wm8753_mode3_4_set_dai_fmt, |
1417 | .set_clkdiv = wm8753_set_dai_clkdiv, | 1415 | .set_clkdiv = wm8753_set_dai_clkdiv, |
@@ -1439,8 +1437,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = { | |||
1439 | .rates = WM8753_RATES, | 1437 | .rates = WM8753_RATES, |
1440 | .formats = WM8753_FORMATS,}, | 1438 | .formats = WM8753_FORMATS,}, |
1441 | .ops = { | 1439 | .ops = { |
1442 | .hw_params = wm8753_i2s_hw_params,}, | 1440 | .hw_params = wm8753_i2s_hw_params, |
1443 | .dai_ops = { | ||
1444 | .digital_mute = wm8753_mute, | 1441 | .digital_mute = wm8753_mute, |
1445 | .set_fmt = wm8753_mode3_4_set_dai_fmt, | 1442 | .set_fmt = wm8753_mode3_4_set_dai_fmt, |
1446 | .set_clkdiv = wm8753_set_dai_clkdiv, | 1443 | .set_clkdiv = wm8753_set_dai_clkdiv, |
@@ -1608,7 +1605,7 @@ static int wm8753_init(struct snd_soc_device *socdev) | |||
1608 | 1605 | ||
1609 | wm8753_add_controls(codec); | 1606 | wm8753_add_controls(codec); |
1610 | wm8753_add_widgets(codec); | 1607 | wm8753_add_widgets(codec); |
1611 | ret = snd_soc_register_card(socdev); | 1608 | ret = snd_soc_init_card(socdev); |
1612 | if (ret < 0) { | 1609 | if (ret < 0) { |
1613 | printk(KERN_ERR "wm8753: failed to register card\n"); | 1610 | printk(KERN_ERR "wm8753: failed to register card\n"); |
1614 | goto card_err; | 1611 | goto card_err; |
@@ -1877,6 +1874,18 @@ struct snd_soc_codec_device soc_codec_dev_wm8753 = { | |||
1877 | }; | 1874 | }; |
1878 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753); | 1875 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753); |
1879 | 1876 | ||
1877 | static int __init wm8753_modinit(void) | ||
1878 | { | ||
1879 | return snd_soc_register_dais(wm8753_dai, ARRAY_SIZE(wm8753_dai)); | ||
1880 | } | ||
1881 | module_init(wm8753_modinit); | ||
1882 | |||
1883 | static void __exit wm8753_exit(void) | ||
1884 | { | ||
1885 | snd_soc_unregister_dais(wm8753_dai, ARRAY_SIZE(wm8753_dai)); | ||
1886 | } | ||
1887 | module_exit(wm8753_exit); | ||
1888 | |||
1880 | MODULE_DESCRIPTION("ASoC WM8753 driver"); | 1889 | MODULE_DESCRIPTION("ASoC WM8753 driver"); |
1881 | MODULE_AUTHOR("Liam Girdwood"); | 1890 | MODULE_AUTHOR("Liam Girdwood"); |
1882 | MODULE_LICENSE("GPL"); | 1891 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c index 3b326c9b5586..6767de10ded0 100644 --- a/sound/soc/codecs/wm8900.c +++ b/sound/soc/codecs/wm8900.c | |||
@@ -138,6 +138,10 @@ | |||
138 | struct snd_soc_codec_device soc_codec_dev_wm8900; | 138 | struct snd_soc_codec_device soc_codec_dev_wm8900; |
139 | 139 | ||
140 | struct wm8900_priv { | 140 | struct wm8900_priv { |
141 | struct snd_soc_codec codec; | ||
142 | |||
143 | u16 reg_cache[WM8900_MAXREG]; | ||
144 | |||
141 | u32 fll_in; /* FLL input frequency */ | 145 | u32 fll_in; /* FLL input frequency */ |
142 | u32 fll_out; /* FLL output frequency */ | 146 | u32 fll_out; /* FLL output frequency */ |
143 | }; | 147 | }; |
@@ -727,7 +731,8 @@ static int wm8900_add_widgets(struct snd_soc_codec *codec) | |||
727 | } | 731 | } |
728 | 732 | ||
729 | static int wm8900_hw_params(struct snd_pcm_substream *substream, | 733 | static int wm8900_hw_params(struct snd_pcm_substream *substream, |
730 | struct snd_pcm_hw_params *params) | 734 | struct snd_pcm_hw_params *params, |
735 | struct snd_soc_dai *dai) | ||
731 | { | 736 | { |
732 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 737 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
733 | struct snd_soc_device *socdev = rtd->socdev; | 738 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -1117,8 +1122,6 @@ struct snd_soc_dai wm8900_dai = { | |||
1117 | }, | 1122 | }, |
1118 | .ops = { | 1123 | .ops = { |
1119 | .hw_params = wm8900_hw_params, | 1124 | .hw_params = wm8900_hw_params, |
1120 | }, | ||
1121 | .dai_ops = { | ||
1122 | .set_clkdiv = wm8900_set_dai_clkdiv, | 1125 | .set_clkdiv = wm8900_set_dai_clkdiv, |
1123 | .set_pll = wm8900_set_dai_pll, | 1126 | .set_pll = wm8900_set_dai_pll, |
1124 | .set_fmt = wm8900_set_dai_fmt, | 1127 | .set_fmt = wm8900_set_dai_fmt, |
@@ -1283,16 +1286,28 @@ static int wm8900_resume(struct platform_device *pdev) | |||
1283 | return 0; | 1286 | return 0; |
1284 | } | 1287 | } |
1285 | 1288 | ||
1286 | /* | 1289 | static struct snd_soc_codec *wm8900_codec; |
1287 | * initialise the WM8900 driver | 1290 | |
1288 | * register the mixer and dsp interfaces with the kernel | 1291 | static int wm8900_i2c_probe(struct i2c_client *i2c, |
1289 | */ | 1292 | const struct i2c_device_id *id) |
1290 | static int wm8900_init(struct snd_soc_device *socdev) | ||
1291 | { | 1293 | { |
1292 | struct snd_soc_codec *codec = socdev->codec; | 1294 | struct wm8900_priv *wm8900; |
1293 | int ret = 0; | 1295 | struct snd_soc_codec *codec; |
1294 | unsigned int reg; | 1296 | unsigned int reg; |
1295 | struct i2c_client *i2c_client = socdev->codec->control_data; | 1297 | int ret; |
1298 | |||
1299 | wm8900 = kzalloc(sizeof(struct wm8900_priv), GFP_KERNEL); | ||
1300 | if (wm8900 == NULL) | ||
1301 | return -ENOMEM; | ||
1302 | |||
1303 | codec = &wm8900->codec; | ||
1304 | codec->private_data = wm8900; | ||
1305 | codec->reg_cache = &wm8900->reg_cache[0]; | ||
1306 | codec->reg_cache_size = WM8900_MAXREG; | ||
1307 | |||
1308 | mutex_init(&codec->mutex); | ||
1309 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
1310 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
1296 | 1311 | ||
1297 | codec->name = "WM8900"; | 1312 | codec->name = "WM8900"; |
1298 | codec->owner = THIS_MODULE; | 1313 | codec->owner = THIS_MODULE; |
@@ -1300,33 +1315,28 @@ static int wm8900_init(struct snd_soc_device *socdev) | |||
1300 | codec->write = wm8900_write; | 1315 | codec->write = wm8900_write; |
1301 | codec->dai = &wm8900_dai; | 1316 | codec->dai = &wm8900_dai; |
1302 | codec->num_dai = 1; | 1317 | codec->num_dai = 1; |
1303 | codec->reg_cache_size = WM8900_MAXREG; | 1318 | codec->hw_write = (hw_write_t)i2c_master_send; |
1304 | codec->reg_cache = kmemdup(wm8900_reg_defaults, | 1319 | codec->control_data = i2c; |
1305 | sizeof(wm8900_reg_defaults), GFP_KERNEL); | 1320 | codec->set_bias_level = wm8900_set_bias_level; |
1306 | 1321 | codec->dev = &i2c->dev; | |
1307 | if (codec->reg_cache == NULL) | ||
1308 | return -ENOMEM; | ||
1309 | 1322 | ||
1310 | reg = wm8900_read(codec, WM8900_REG_ID); | 1323 | reg = wm8900_read(codec, WM8900_REG_ID); |
1311 | if (reg != 0x8900) { | 1324 | if (reg != 0x8900) { |
1312 | dev_err(&i2c_client->dev, "Device is not a WM8900 - ID %x\n", | 1325 | dev_err(&i2c->dev, "Device is not a WM8900 - ID %x\n", reg); |
1313 | reg); | 1326 | ret = -ENODEV; |
1314 | return -ENODEV; | 1327 | goto err; |
1315 | } | ||
1316 | |||
1317 | codec->private_data = kzalloc(sizeof(struct wm8900_priv), GFP_KERNEL); | ||
1318 | if (codec->private_data == NULL) { | ||
1319 | ret = -ENOMEM; | ||
1320 | goto priv_err; | ||
1321 | } | 1328 | } |
1322 | 1329 | ||
1323 | /* Read back from the chip */ | 1330 | /* Read back from the chip */ |
1324 | reg = wm8900_chip_read(codec, WM8900_REG_POWER1); | 1331 | reg = wm8900_chip_read(codec, WM8900_REG_POWER1); |
1325 | reg = (reg >> 12) & 0xf; | 1332 | reg = (reg >> 12) & 0xf; |
1326 | dev_info(&i2c_client->dev, "WM8900 revision %d\n", reg); | 1333 | dev_info(&i2c->dev, "WM8900 revision %d\n", reg); |
1327 | 1334 | ||
1328 | wm8900_reset(codec); | 1335 | wm8900_reset(codec); |
1329 | 1336 | ||
1337 | /* Turn the chip on */ | ||
1338 | wm8900_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
1339 | |||
1330 | /* Latch the volume update bits */ | 1340 | /* Latch the volume update bits */ |
1331 | wm8900_write(codec, WM8900_REG_LINVOL, | 1341 | wm8900_write(codec, WM8900_REG_LINVOL, |
1332 | wm8900_read(codec, WM8900_REG_LINVOL) | 0x100); | 1342 | wm8900_read(codec, WM8900_REG_LINVOL) | 0x100); |
@@ -1352,160 +1362,98 @@ static int wm8900_init(struct snd_soc_device *socdev) | |||
1352 | /* Set the DAC and mixer output bias */ | 1362 | /* Set the DAC and mixer output bias */ |
1353 | wm8900_write(codec, WM8900_REG_OUTBIASCTL, 0x81); | 1363 | wm8900_write(codec, WM8900_REG_OUTBIASCTL, 0x81); |
1354 | 1364 | ||
1355 | /* Register pcms */ | 1365 | wm8900_dai.dev = &i2c->dev; |
1356 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
1357 | if (ret < 0) { | ||
1358 | dev_err(&i2c_client->dev, "Failed to register new PCMs\n"); | ||
1359 | goto pcm_err; | ||
1360 | } | ||
1361 | |||
1362 | /* Turn the chip on */ | ||
1363 | codec->bias_level = SND_SOC_BIAS_OFF; | ||
1364 | wm8900_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
1365 | |||
1366 | wm8900_add_controls(codec); | ||
1367 | wm8900_add_widgets(codec); | ||
1368 | |||
1369 | ret = snd_soc_register_card(socdev); | ||
1370 | if (ret < 0) { | ||
1371 | dev_err(&i2c_client->dev, "Failed to register card\n"); | ||
1372 | goto card_err; | ||
1373 | } | ||
1374 | return ret; | ||
1375 | |||
1376 | card_err: | ||
1377 | snd_soc_free_pcms(socdev); | ||
1378 | snd_soc_dapm_free(socdev); | ||
1379 | pcm_err: | ||
1380 | kfree(codec->reg_cache); | ||
1381 | priv_err: | ||
1382 | kfree(codec->private_data); | ||
1383 | return ret; | ||
1384 | } | ||
1385 | 1366 | ||
1386 | static struct snd_soc_device *wm8900_socdev; | 1367 | wm8900_codec = codec; |
1387 | 1368 | ||
1388 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1369 | ret = snd_soc_register_codec(codec); |
1389 | 1370 | if (ret != 0) { | |
1390 | static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END }; | 1371 | dev_err(&i2c->dev, "Failed to register codec: %d\n", ret); |
1391 | |||
1392 | /* Magic definition of all other variables and things */ | ||
1393 | I2C_CLIENT_INSMOD; | ||
1394 | |||
1395 | static struct i2c_driver wm8900_i2c_driver; | ||
1396 | static struct i2c_client client_template; | ||
1397 | |||
1398 | /* If the i2c layer weren't so broken, we could pass this kind of data | ||
1399 | around */ | ||
1400 | static int wm8900_codec_probe(struct i2c_adapter *adap, int addr, int kind) | ||
1401 | { | ||
1402 | struct snd_soc_device *socdev = wm8900_socdev; | ||
1403 | struct wm8900_setup_data *setup = socdev->codec_data; | ||
1404 | struct snd_soc_codec *codec = socdev->codec; | ||
1405 | struct i2c_client *i2c; | ||
1406 | int ret; | ||
1407 | |||
1408 | if (addr != setup->i2c_address) | ||
1409 | return -ENODEV; | ||
1410 | |||
1411 | dev_err(&adap->dev, "Probe on %x\n", addr); | ||
1412 | |||
1413 | client_template.adapter = adap; | ||
1414 | client_template.addr = addr; | ||
1415 | |||
1416 | i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); | ||
1417 | if (i2c == NULL) { | ||
1418 | kfree(codec); | ||
1419 | return -ENOMEM; | ||
1420 | } | ||
1421 | i2c_set_clientdata(i2c, codec); | ||
1422 | codec->control_data = i2c; | ||
1423 | |||
1424 | ret = i2c_attach_client(i2c); | ||
1425 | if (ret < 0) { | ||
1426 | dev_err(&adap->dev, | ||
1427 | "failed to attach codec at addr %x\n", addr); | ||
1428 | goto err; | 1372 | goto err; |
1429 | } | 1373 | } |
1430 | 1374 | ||
1431 | ret = wm8900_init(socdev); | 1375 | ret = snd_soc_register_dai(&wm8900_dai); |
1432 | if (ret < 0) { | 1376 | if (ret != 0) { |
1433 | dev_err(&adap->dev, "failed to initialise WM8900\n"); | 1377 | dev_err(&i2c->dev, "Failed to register DAI: %d\n", ret); |
1434 | goto err; | 1378 | goto err_codec; |
1435 | } | 1379 | } |
1380 | |||
1436 | return ret; | 1381 | return ret; |
1437 | 1382 | ||
1383 | err_codec: | ||
1384 | snd_soc_unregister_codec(codec); | ||
1438 | err: | 1385 | err: |
1439 | kfree(codec); | 1386 | kfree(wm8900); |
1440 | kfree(i2c); | 1387 | wm8900_codec = NULL; |
1441 | return ret; | 1388 | return ret; |
1442 | } | 1389 | } |
1443 | 1390 | ||
1444 | static int wm8900_i2c_detach(struct i2c_client *client) | 1391 | static int wm8900_i2c_remove(struct i2c_client *client) |
1445 | { | 1392 | { |
1446 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | 1393 | snd_soc_unregister_dai(&wm8900_dai); |
1447 | i2c_detach_client(client); | 1394 | snd_soc_unregister_codec(wm8900_codec); |
1448 | kfree(codec->reg_cache); | 1395 | |
1449 | kfree(client); | 1396 | wm8900_set_bias_level(wm8900_codec, SND_SOC_BIAS_OFF); |
1397 | |||
1398 | wm8900_dai.dev = NULL; | ||
1399 | kfree(wm8900_codec->private_data); | ||
1400 | wm8900_codec = NULL; | ||
1401 | |||
1450 | return 0; | 1402 | return 0; |
1451 | } | 1403 | } |
1452 | 1404 | ||
1453 | static int wm8900_i2c_attach(struct i2c_adapter *adap) | 1405 | static const struct i2c_device_id wm8900_i2c_id[] = { |
1454 | { | 1406 | { "wm8900", 0 }, |
1455 | return i2c_probe(adap, &addr_data, wm8900_codec_probe); | 1407 | { } |
1456 | } | 1408 | }; |
1409 | MODULE_DEVICE_TABLE(i2c, wm8900_i2c_id); | ||
1457 | 1410 | ||
1458 | /* corgi i2c codec control layer */ | ||
1459 | static struct i2c_driver wm8900_i2c_driver = { | 1411 | static struct i2c_driver wm8900_i2c_driver = { |
1460 | .driver = { | 1412 | .driver = { |
1461 | .name = "WM8900 I2C codec", | 1413 | .name = "WM8900", |
1462 | .owner = THIS_MODULE, | 1414 | .owner = THIS_MODULE, |
1463 | }, | 1415 | }, |
1464 | .attach_adapter = wm8900_i2c_attach, | 1416 | .probe = wm8900_i2c_probe, |
1465 | .detach_client = wm8900_i2c_detach, | 1417 | .remove = wm8900_i2c_remove, |
1466 | .command = NULL, | 1418 | .id_table = wm8900_i2c_id, |
1467 | }; | ||
1468 | |||
1469 | static struct i2c_client client_template = { | ||
1470 | .name = "WM8900", | ||
1471 | .driver = &wm8900_i2c_driver, | ||
1472 | }; | 1419 | }; |
1473 | #endif | ||
1474 | 1420 | ||
1475 | static int wm8900_probe(struct platform_device *pdev) | 1421 | static int wm8900_probe(struct platform_device *pdev) |
1476 | { | 1422 | { |
1477 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1423 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1478 | struct wm8900_setup_data *setup; | ||
1479 | struct snd_soc_codec *codec; | 1424 | struct snd_soc_codec *codec; |
1480 | int ret = 0; | 1425 | int ret = 0; |
1481 | 1426 | ||
1482 | dev_info(&pdev->dev, "WM8900 Audio Codec\n"); | 1427 | if (!wm8900_codec) { |
1483 | 1428 | dev_err(&pdev->dev, "I2C client not yet instantiated\n"); | |
1484 | setup = socdev->codec_data; | 1429 | return -ENODEV; |
1485 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | 1430 | } |
1486 | if (codec == NULL) | ||
1487 | return -ENOMEM; | ||
1488 | |||
1489 | mutex_init(&codec->mutex); | ||
1490 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
1491 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
1492 | 1431 | ||
1432 | codec = wm8900_codec; | ||
1493 | socdev->codec = codec; | 1433 | socdev->codec = codec; |
1494 | 1434 | ||
1495 | codec->set_bias_level = wm8900_set_bias_level; | 1435 | /* Register pcms */ |
1436 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
1437 | if (ret < 0) { | ||
1438 | dev_err(&pdev->dev, "Failed to register new PCMs\n"); | ||
1439 | goto pcm_err; | ||
1440 | } | ||
1496 | 1441 | ||
1497 | wm8900_socdev = socdev; | 1442 | wm8900_add_controls(codec); |
1498 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1443 | wm8900_add_widgets(codec); |
1499 | if (setup->i2c_address) { | 1444 | |
1500 | normal_i2c[0] = setup->i2c_address; | 1445 | ret = snd_soc_init_card(socdev); |
1501 | codec->hw_write = (hw_write_t)i2c_master_send; | 1446 | if (ret < 0) { |
1502 | ret = i2c_add_driver(&wm8900_i2c_driver); | 1447 | dev_err(&pdev->dev, "Failed to register card\n"); |
1503 | if (ret != 0) | 1448 | goto card_err; |
1504 | printk(KERN_ERR "can't add i2c driver"); | ||
1505 | } | 1449 | } |
1506 | #else | 1450 | |
1507 | #error Non-I2C interfaces not yet supported | 1451 | return ret; |
1508 | #endif | 1452 | |
1453 | card_err: | ||
1454 | snd_soc_free_pcms(socdev); | ||
1455 | snd_soc_dapm_free(socdev); | ||
1456 | pcm_err: | ||
1509 | return ret; | 1457 | return ret; |
1510 | } | 1458 | } |
1511 | 1459 | ||
@@ -1513,17 +1461,9 @@ static int wm8900_probe(struct platform_device *pdev) | |||
1513 | static int wm8900_remove(struct platform_device *pdev) | 1461 | static int wm8900_remove(struct platform_device *pdev) |
1514 | { | 1462 | { |
1515 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1463 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1516 | struct snd_soc_codec *codec = socdev->codec; | ||
1517 | |||
1518 | if (codec->control_data) | ||
1519 | wm8900_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
1520 | 1464 | ||
1521 | snd_soc_free_pcms(socdev); | 1465 | snd_soc_free_pcms(socdev); |
1522 | snd_soc_dapm_free(socdev); | 1466 | snd_soc_dapm_free(socdev); |
1523 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
1524 | i2c_del_driver(&wm8900_i2c_driver); | ||
1525 | #endif | ||
1526 | kfree(codec); | ||
1527 | 1467 | ||
1528 | return 0; | 1468 | return 0; |
1529 | } | 1469 | } |
@@ -1536,6 +1476,18 @@ struct snd_soc_codec_device soc_codec_dev_wm8900 = { | |||
1536 | }; | 1476 | }; |
1537 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8900); | 1477 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8900); |
1538 | 1478 | ||
1479 | static int __init wm8900_modinit(void) | ||
1480 | { | ||
1481 | return i2c_add_driver(&wm8900_i2c_driver); | ||
1482 | } | ||
1483 | module_init(wm8900_modinit); | ||
1484 | |||
1485 | static void __exit wm8900_exit(void) | ||
1486 | { | ||
1487 | i2c_del_driver(&wm8900_i2c_driver); | ||
1488 | } | ||
1489 | module_exit(wm8900_exit); | ||
1490 | |||
1539 | MODULE_DESCRIPTION("ASoC WM8900 driver"); | 1491 | MODULE_DESCRIPTION("ASoC WM8900 driver"); |
1540 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfonmicro.com>"); | 1492 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfonmicro.com>"); |
1541 | MODULE_LICENSE("GPL"); | 1493 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/wm8900.h b/sound/soc/codecs/wm8900.h index ba450d99e902..fd15007d10c7 100644 --- a/sound/soc/codecs/wm8900.h +++ b/sound/soc/codecs/wm8900.h | |||
@@ -52,12 +52,6 @@ | |||
52 | #define WM8900_DAC_CLKDIV_5_5 0x14 | 52 | #define WM8900_DAC_CLKDIV_5_5 0x14 |
53 | #define WM8900_DAC_CLKDIV_6 0x18 | 53 | #define WM8900_DAC_CLKDIV_6 0x18 |
54 | 54 | ||
55 | #define WM8900_ | ||
56 | |||
57 | struct wm8900_setup_data { | ||
58 | unsigned short i2c_address; | ||
59 | }; | ||
60 | |||
61 | extern struct snd_soc_dai wm8900_dai; | 55 | extern struct snd_soc_dai wm8900_dai; |
62 | extern struct snd_soc_codec_device soc_codec_dev_wm8900; | 56 | extern struct snd_soc_codec_device soc_codec_dev_wm8900; |
63 | 57 | ||
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c index ce40d7877605..bde74546db4a 100644 --- a/sound/soc/codecs/wm8903.c +++ b/sound/soc/codecs/wm8903.c | |||
@@ -33,19 +33,6 @@ | |||
33 | 33 | ||
34 | #include "wm8903.h" | 34 | #include "wm8903.h" |
35 | 35 | ||
36 | struct wm8903_priv { | ||
37 | int sysclk; | ||
38 | |||
39 | /* Reference counts */ | ||
40 | int charge_pump_users; | ||
41 | int class_w_users; | ||
42 | int playback_active; | ||
43 | int capture_active; | ||
44 | |||
45 | struct snd_pcm_substream *master_substream; | ||
46 | struct snd_pcm_substream *slave_substream; | ||
47 | }; | ||
48 | |||
49 | /* Register defaults at reset */ | 36 | /* Register defaults at reset */ |
50 | static u16 wm8903_reg_defaults[] = { | 37 | static u16 wm8903_reg_defaults[] = { |
51 | 0x8903, /* R0 - SW Reset and ID */ | 38 | 0x8903, /* R0 - SW Reset and ID */ |
@@ -223,6 +210,23 @@ static u16 wm8903_reg_defaults[] = { | |||
223 | 0x0000, /* R172 - Analogue Output Bias 0 */ | 210 | 0x0000, /* R172 - Analogue Output Bias 0 */ |
224 | }; | 211 | }; |
225 | 212 | ||
213 | struct wm8903_priv { | ||
214 | struct snd_soc_codec codec; | ||
215 | u16 reg_cache[ARRAY_SIZE(wm8903_reg_defaults)]; | ||
216 | |||
217 | int sysclk; | ||
218 | |||
219 | /* Reference counts */ | ||
220 | int charge_pump_users; | ||
221 | int class_w_users; | ||
222 | int playback_active; | ||
223 | int capture_active; | ||
224 | |||
225 | struct snd_pcm_substream *master_substream; | ||
226 | struct snd_pcm_substream *slave_substream; | ||
227 | }; | ||
228 | |||
229 | |||
226 | static unsigned int wm8903_read_reg_cache(struct snd_soc_codec *codec, | 230 | static unsigned int wm8903_read_reg_cache(struct snd_soc_codec *codec, |
227 | unsigned int reg) | 231 | unsigned int reg) |
228 | { | 232 | { |
@@ -360,6 +364,8 @@ static void wm8903_sync_reg_cache(struct snd_soc_codec *codec, u16 *cache) | |||
360 | static void wm8903_reset(struct snd_soc_codec *codec) | 364 | static void wm8903_reset(struct snd_soc_codec *codec) |
361 | { | 365 | { |
362 | wm8903_write(codec, WM8903_SW_RESET_AND_ID, 0); | 366 | wm8903_write(codec, WM8903_SW_RESET_AND_ID, 0); |
367 | memcpy(codec->reg_cache, wm8903_reg_defaults, | ||
368 | sizeof(wm8903_reg_defaults)); | ||
363 | } | 369 | } |
364 | 370 | ||
365 | #define WM8903_OUTPUT_SHORT 0x8 | 371 | #define WM8903_OUTPUT_SHORT 0x8 |
@@ -392,6 +398,7 @@ static int wm8903_output_event(struct snd_soc_dapm_widget *w, | |||
392 | break; | 398 | break; |
393 | default: | 399 | default: |
394 | BUG(); | 400 | BUG(); |
401 | return -EINVAL; /* Spurious warning from some compilers */ | ||
395 | } | 402 | } |
396 | 403 | ||
397 | switch (w->shift) { | 404 | switch (w->shift) { |
@@ -403,6 +410,7 @@ static int wm8903_output_event(struct snd_soc_dapm_widget *w, | |||
403 | break; | 410 | break; |
404 | default: | 411 | default: |
405 | BUG(); | 412 | BUG(); |
413 | return -EINVAL; /* Spurious warning from some compilers */ | ||
406 | } | 414 | } |
407 | 415 | ||
408 | if (event & SND_SOC_DAPM_PRE_PMU) { | 416 | if (event & SND_SOC_DAPM_PRE_PMU) { |
@@ -773,14 +781,14 @@ static const struct snd_kcontrol_new left_output_mixer[] = { | |||
773 | SOC_DAPM_SINGLE("DACL Switch", WM8903_ANALOGUE_LEFT_MIX_0, 3, 1, 0), | 781 | SOC_DAPM_SINGLE("DACL Switch", WM8903_ANALOGUE_LEFT_MIX_0, 3, 1, 0), |
774 | SOC_DAPM_SINGLE("DACR Switch", WM8903_ANALOGUE_LEFT_MIX_0, 2, 1, 0), | 782 | SOC_DAPM_SINGLE("DACR Switch", WM8903_ANALOGUE_LEFT_MIX_0, 2, 1, 0), |
775 | SOC_DAPM_SINGLE_W("Left Bypass Switch", WM8903_ANALOGUE_LEFT_MIX_0, 1, 1, 0), | 783 | SOC_DAPM_SINGLE_W("Left Bypass Switch", WM8903_ANALOGUE_LEFT_MIX_0, 1, 1, 0), |
776 | SOC_DAPM_SINGLE_W("Right Bypass Switch", WM8903_ANALOGUE_LEFT_MIX_0, 1, 1, 0), | 784 | SOC_DAPM_SINGLE_W("Right Bypass Switch", WM8903_ANALOGUE_LEFT_MIX_0, 0, 1, 0), |
777 | }; | 785 | }; |
778 | 786 | ||
779 | static const struct snd_kcontrol_new right_output_mixer[] = { | 787 | static const struct snd_kcontrol_new right_output_mixer[] = { |
780 | SOC_DAPM_SINGLE("DACL Switch", WM8903_ANALOGUE_RIGHT_MIX_0, 3, 1, 0), | 788 | SOC_DAPM_SINGLE("DACL Switch", WM8903_ANALOGUE_RIGHT_MIX_0, 3, 1, 0), |
781 | SOC_DAPM_SINGLE("DACR Switch", WM8903_ANALOGUE_RIGHT_MIX_0, 2, 1, 0), | 789 | SOC_DAPM_SINGLE("DACR Switch", WM8903_ANALOGUE_RIGHT_MIX_0, 2, 1, 0), |
782 | SOC_DAPM_SINGLE_W("Left Bypass Switch", WM8903_ANALOGUE_RIGHT_MIX_0, 1, 1, 0), | 790 | SOC_DAPM_SINGLE_W("Left Bypass Switch", WM8903_ANALOGUE_RIGHT_MIX_0, 1, 1, 0), |
783 | SOC_DAPM_SINGLE_W("Right Bypass Switch", WM8903_ANALOGUE_RIGHT_MIX_0, 1, 1, 0), | 791 | SOC_DAPM_SINGLE_W("Right Bypass Switch", WM8903_ANALOGUE_RIGHT_MIX_0, 0, 1, 0), |
784 | }; | 792 | }; |
785 | 793 | ||
786 | static const struct snd_kcontrol_new left_speaker_mixer[] = { | 794 | static const struct snd_kcontrol_new left_speaker_mixer[] = { |
@@ -788,7 +796,7 @@ SOC_DAPM_SINGLE("DACL Switch", WM8903_ANALOGUE_SPK_MIX_LEFT_0, 3, 1, 0), | |||
788 | SOC_DAPM_SINGLE("DACR Switch", WM8903_ANALOGUE_SPK_MIX_LEFT_0, 2, 1, 0), | 796 | SOC_DAPM_SINGLE("DACR Switch", WM8903_ANALOGUE_SPK_MIX_LEFT_0, 2, 1, 0), |
789 | SOC_DAPM_SINGLE("Left Bypass Switch", WM8903_ANALOGUE_SPK_MIX_LEFT_0, 1, 1, 0), | 797 | SOC_DAPM_SINGLE("Left Bypass Switch", WM8903_ANALOGUE_SPK_MIX_LEFT_0, 1, 1, 0), |
790 | SOC_DAPM_SINGLE("Right Bypass Switch", WM8903_ANALOGUE_SPK_MIX_LEFT_0, | 798 | SOC_DAPM_SINGLE("Right Bypass Switch", WM8903_ANALOGUE_SPK_MIX_LEFT_0, |
791 | 1, 1, 0), | 799 | 0, 1, 0), |
792 | }; | 800 | }; |
793 | 801 | ||
794 | static const struct snd_kcontrol_new right_speaker_mixer[] = { | 802 | static const struct snd_kcontrol_new right_speaker_mixer[] = { |
@@ -797,7 +805,7 @@ SOC_DAPM_SINGLE("DACR Switch", WM8903_ANALOGUE_SPK_MIX_RIGHT_0, 2, 1, 0), | |||
797 | SOC_DAPM_SINGLE("Left Bypass Switch", WM8903_ANALOGUE_SPK_MIX_RIGHT_0, | 805 | SOC_DAPM_SINGLE("Left Bypass Switch", WM8903_ANALOGUE_SPK_MIX_RIGHT_0, |
798 | 1, 1, 0), | 806 | 1, 1, 0), |
799 | SOC_DAPM_SINGLE("Right Bypass Switch", WM8903_ANALOGUE_SPK_MIX_RIGHT_0, | 807 | SOC_DAPM_SINGLE("Right Bypass Switch", WM8903_ANALOGUE_SPK_MIX_RIGHT_0, |
800 | 1, 1, 0), | 808 | 0, 1, 0), |
801 | }; | 809 | }; |
802 | 810 | ||
803 | static const struct snd_soc_dapm_widget wm8903_dapm_widgets[] = { | 811 | static const struct snd_soc_dapm_widget wm8903_dapm_widgets[] = { |
@@ -989,6 +997,9 @@ static int wm8903_set_bias_level(struct snd_soc_codec *codec, | |||
989 | 997 | ||
990 | case SND_SOC_BIAS_STANDBY: | 998 | case SND_SOC_BIAS_STANDBY: |
991 | if (codec->bias_level == SND_SOC_BIAS_OFF) { | 999 | if (codec->bias_level == SND_SOC_BIAS_OFF) { |
1000 | wm8903_write(codec, WM8903_CLOCK_RATES_2, | ||
1001 | WM8903_CLK_SYS_ENA); | ||
1002 | |||
992 | wm8903_run_sequence(codec, 0); | 1003 | wm8903_run_sequence(codec, 0); |
993 | wm8903_sync_reg_cache(codec, codec->reg_cache); | 1004 | wm8903_sync_reg_cache(codec, codec->reg_cache); |
994 | 1005 | ||
@@ -1019,6 +1030,9 @@ static int wm8903_set_bias_level(struct snd_soc_codec *codec, | |||
1019 | 1030 | ||
1020 | case SND_SOC_BIAS_OFF: | 1031 | case SND_SOC_BIAS_OFF: |
1021 | wm8903_run_sequence(codec, 32); | 1032 | wm8903_run_sequence(codec, 32); |
1033 | reg = wm8903_read(codec, WM8903_CLOCK_RATES_2); | ||
1034 | reg &= ~WM8903_CLK_SYS_ENA; | ||
1035 | wm8903_write(codec, WM8903_CLOCK_RATES_2, reg); | ||
1022 | break; | 1036 | break; |
1023 | } | 1037 | } |
1024 | 1038 | ||
@@ -1257,7 +1271,8 @@ static struct { | |||
1257 | { 0, 0 }, | 1271 | { 0, 0 }, |
1258 | }; | 1272 | }; |
1259 | 1273 | ||
1260 | static int wm8903_startup(struct snd_pcm_substream *substream) | 1274 | static int wm8903_startup(struct snd_pcm_substream *substream, |
1275 | struct snd_soc_dai *dai) | ||
1261 | { | 1276 | { |
1262 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1277 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
1263 | struct snd_soc_device *socdev = rtd->socdev; | 1278 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -1298,7 +1313,8 @@ static int wm8903_startup(struct snd_pcm_substream *substream) | |||
1298 | return 0; | 1313 | return 0; |
1299 | } | 1314 | } |
1300 | 1315 | ||
1301 | static void wm8903_shutdown(struct snd_pcm_substream *substream) | 1316 | static void wm8903_shutdown(struct snd_pcm_substream *substream, |
1317 | struct snd_soc_dai *dai) | ||
1302 | { | 1318 | { |
1303 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1319 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
1304 | struct snd_soc_device *socdev = rtd->socdev; | 1320 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -1317,7 +1333,8 @@ static void wm8903_shutdown(struct snd_pcm_substream *substream) | |||
1317 | } | 1333 | } |
1318 | 1334 | ||
1319 | static int wm8903_hw_params(struct snd_pcm_substream *substream, | 1335 | static int wm8903_hw_params(struct snd_pcm_substream *substream, |
1320 | struct snd_pcm_hw_params *params) | 1336 | struct snd_pcm_hw_params *params, |
1337 | struct snd_soc_dai *dai) | ||
1321 | { | 1338 | { |
1322 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1339 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
1323 | struct snd_soc_device *socdev = rtd->socdev; | 1340 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -1515,8 +1532,6 @@ struct snd_soc_dai wm8903_dai = { | |||
1515 | .startup = wm8903_startup, | 1532 | .startup = wm8903_startup, |
1516 | .shutdown = wm8903_shutdown, | 1533 | .shutdown = wm8903_shutdown, |
1517 | .hw_params = wm8903_hw_params, | 1534 | .hw_params = wm8903_hw_params, |
1518 | }, | ||
1519 | .dai_ops = { | ||
1520 | .digital_mute = wm8903_digital_mute, | 1535 | .digital_mute = wm8903_digital_mute, |
1521 | .set_fmt = wm8903_set_dai_fmt, | 1536 | .set_fmt = wm8903_set_dai_fmt, |
1522 | .set_sysclk = wm8903_set_dai_sysclk | 1537 | .set_sysclk = wm8903_set_dai_sysclk |
@@ -1560,39 +1575,48 @@ static int wm8903_resume(struct platform_device *pdev) | |||
1560 | return 0; | 1575 | return 0; |
1561 | } | 1576 | } |
1562 | 1577 | ||
1563 | /* | 1578 | static struct snd_soc_codec *wm8903_codec; |
1564 | * initialise the WM8903 driver | 1579 | |
1565 | * register the mixer and dsp interfaces with the kernel | 1580 | static int wm8903_i2c_probe(struct i2c_client *i2c, |
1566 | */ | 1581 | const struct i2c_device_id *id) |
1567 | static int wm8903_init(struct snd_soc_device *socdev) | ||
1568 | { | 1582 | { |
1569 | struct snd_soc_codec *codec = socdev->codec; | 1583 | struct wm8903_priv *wm8903; |
1570 | struct i2c_client *i2c = codec->control_data; | 1584 | struct snd_soc_codec *codec; |
1571 | int ret = 0; | 1585 | int ret; |
1572 | u16 val; | 1586 | u16 val; |
1573 | 1587 | ||
1574 | val = wm8903_hw_read(codec, WM8903_SW_RESET_AND_ID); | 1588 | wm8903 = kzalloc(sizeof(struct wm8903_priv), GFP_KERNEL); |
1575 | if (val != wm8903_reg_defaults[WM8903_SW_RESET_AND_ID]) { | 1589 | if (wm8903 == NULL) |
1576 | dev_err(&i2c->dev, | 1590 | return -ENOMEM; |
1577 | "Device with ID register %x is not a WM8903\n", val); | 1591 | |
1578 | return -ENODEV; | 1592 | codec = &wm8903->codec; |
1579 | } | ||
1580 | 1593 | ||
1594 | mutex_init(&codec->mutex); | ||
1595 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
1596 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
1597 | |||
1598 | codec->dev = &i2c->dev; | ||
1581 | codec->name = "WM8903"; | 1599 | codec->name = "WM8903"; |
1582 | codec->owner = THIS_MODULE; | 1600 | codec->owner = THIS_MODULE; |
1583 | codec->read = wm8903_read; | 1601 | codec->read = wm8903_read; |
1584 | codec->write = wm8903_write; | 1602 | codec->write = wm8903_write; |
1603 | codec->hw_write = (hw_write_t)i2c_master_send; | ||
1585 | codec->bias_level = SND_SOC_BIAS_OFF; | 1604 | codec->bias_level = SND_SOC_BIAS_OFF; |
1586 | codec->set_bias_level = wm8903_set_bias_level; | 1605 | codec->set_bias_level = wm8903_set_bias_level; |
1587 | codec->dai = &wm8903_dai; | 1606 | codec->dai = &wm8903_dai; |
1588 | codec->num_dai = 1; | 1607 | codec->num_dai = 1; |
1589 | codec->reg_cache_size = ARRAY_SIZE(wm8903_reg_defaults); | 1608 | codec->reg_cache_size = ARRAY_SIZE(wm8903->reg_cache); |
1590 | codec->reg_cache = kmemdup(wm8903_reg_defaults, | 1609 | codec->reg_cache = &wm8903->reg_cache[0]; |
1591 | sizeof(wm8903_reg_defaults), | 1610 | codec->private_data = wm8903; |
1592 | GFP_KERNEL); | 1611 | |
1593 | if (codec->reg_cache == NULL) { | 1612 | i2c_set_clientdata(i2c, codec); |
1594 | dev_err(&i2c->dev, "Failed to allocate register cache\n"); | 1613 | codec->control_data = i2c; |
1595 | return -ENOMEM; | 1614 | |
1615 | val = wm8903_hw_read(codec, WM8903_SW_RESET_AND_ID); | ||
1616 | if (val != wm8903_reg_defaults[WM8903_SW_RESET_AND_ID]) { | ||
1617 | dev_err(&i2c->dev, | ||
1618 | "Device with ID register %x is not a WM8903\n", val); | ||
1619 | return -ENODEV; | ||
1596 | } | 1620 | } |
1597 | 1621 | ||
1598 | val = wm8903_read(codec, WM8903_REVISION_NUMBER); | 1622 | val = wm8903_read(codec, WM8903_REVISION_NUMBER); |
@@ -1601,16 +1625,6 @@ static int wm8903_init(struct snd_soc_device *socdev) | |||
1601 | 1625 | ||
1602 | wm8903_reset(codec); | 1626 | wm8903_reset(codec); |
1603 | 1627 | ||
1604 | /* register pcms */ | ||
1605 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
1606 | if (ret < 0) { | ||
1607 | dev_err(&i2c->dev, "failed to create pcms\n"); | ||
1608 | goto pcm_err; | ||
1609 | } | ||
1610 | |||
1611 | /* SYSCLK is required for pretty much anything */ | ||
1612 | wm8903_write(codec, WM8903_CLOCK_RATES_2, WM8903_CLK_SYS_ENA); | ||
1613 | |||
1614 | /* power on device */ | 1628 | /* power on device */ |
1615 | wm8903_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 1629 | wm8903_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
1616 | 1630 | ||
@@ -1645,47 +1659,45 @@ static int wm8903_init(struct snd_soc_device *socdev) | |||
1645 | val |= WM8903_DAC_MUTEMODE; | 1659 | val |= WM8903_DAC_MUTEMODE; |
1646 | wm8903_write(codec, WM8903_DAC_DIGITAL_1, val); | 1660 | wm8903_write(codec, WM8903_DAC_DIGITAL_1, val); |
1647 | 1661 | ||
1648 | wm8903_add_controls(codec); | 1662 | wm8903_dai.dev = &i2c->dev; |
1649 | wm8903_add_widgets(codec); | 1663 | wm8903_codec = codec; |
1650 | ret = snd_soc_register_card(socdev); | 1664 | |
1651 | if (ret < 0) { | 1665 | ret = snd_soc_register_codec(codec); |
1652 | dev_err(&i2c->dev, "wm8903: failed to register card\n"); | 1666 | if (ret != 0) { |
1653 | goto card_err; | 1667 | dev_err(&i2c->dev, "Failed to register codec: %d\n", ret); |
1668 | goto err; | ||
1669 | } | ||
1670 | |||
1671 | ret = snd_soc_register_dai(&wm8903_dai); | ||
1672 | if (ret != 0) { | ||
1673 | dev_err(&i2c->dev, "Failed to register DAI: %d\n", ret); | ||
1674 | goto err_codec; | ||
1654 | } | 1675 | } |
1655 | 1676 | ||
1656 | return ret; | 1677 | return ret; |
1657 | 1678 | ||
1658 | card_err: | 1679 | err_codec: |
1659 | snd_soc_free_pcms(socdev); | 1680 | snd_soc_unregister_codec(codec); |
1660 | snd_soc_dapm_free(socdev); | 1681 | err: |
1661 | pcm_err: | 1682 | wm8903_codec = NULL; |
1662 | kfree(codec->reg_cache); | 1683 | kfree(wm8903); |
1663 | return ret; | 1684 | return ret; |
1664 | } | 1685 | } |
1665 | 1686 | ||
1666 | static struct snd_soc_device *wm8903_socdev; | 1687 | static int wm8903_i2c_remove(struct i2c_client *client) |
1667 | |||
1668 | static int wm8903_i2c_probe(struct i2c_client *i2c, | ||
1669 | const struct i2c_device_id *id) | ||
1670 | { | 1688 | { |
1671 | struct snd_soc_device *socdev = wm8903_socdev; | 1689 | struct snd_soc_codec *codec = i2c_get_clientdata(client); |
1672 | struct snd_soc_codec *codec = socdev->codec; | ||
1673 | int ret; | ||
1674 | 1690 | ||
1675 | i2c_set_clientdata(i2c, codec); | 1691 | snd_soc_unregister_dai(&wm8903_dai); |
1676 | codec->control_data = i2c; | 1692 | snd_soc_unregister_codec(codec); |
1677 | 1693 | ||
1678 | ret = wm8903_init(socdev); | 1694 | wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF); |
1679 | if (ret < 0) | ||
1680 | dev_err(&i2c->dev, "Device initialisation failed\n"); | ||
1681 | 1695 | ||
1682 | return ret; | 1696 | kfree(codec->private_data); |
1683 | } | 1697 | |
1698 | wm8903_codec = NULL; | ||
1699 | wm8903_dai.dev = NULL; | ||
1684 | 1700 | ||
1685 | static int wm8903_i2c_remove(struct i2c_client *client) | ||
1686 | { | ||
1687 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | ||
1688 | kfree(codec->reg_cache); | ||
1689 | return 0; | 1701 | return 0; |
1690 | } | 1702 | } |
1691 | 1703 | ||
@@ -1709,75 +1721,37 @@ static struct i2c_driver wm8903_i2c_driver = { | |||
1709 | static int wm8903_probe(struct platform_device *pdev) | 1721 | static int wm8903_probe(struct platform_device *pdev) |
1710 | { | 1722 | { |
1711 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1723 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1712 | struct wm8903_setup_data *setup; | ||
1713 | struct snd_soc_codec *codec; | ||
1714 | struct wm8903_priv *wm8903; | ||
1715 | struct i2c_board_info board_info; | ||
1716 | struct i2c_adapter *adapter; | ||
1717 | struct i2c_client *i2c_client; | ||
1718 | int ret = 0; | 1724 | int ret = 0; |
1719 | 1725 | ||
1720 | setup = socdev->codec_data; | 1726 | if (!wm8903_codec) { |
1721 | 1727 | dev_err(&pdev->dev, "I2C device not yet probed\n"); | |
1722 | if (!setup->i2c_address) { | 1728 | goto err; |
1723 | dev_err(&pdev->dev, "No codec address provided\n"); | ||
1724 | return -ENODEV; | ||
1725 | } | 1729 | } |
1726 | 1730 | ||
1727 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | 1731 | socdev->codec = wm8903_codec; |
1728 | if (codec == NULL) | ||
1729 | return -ENOMEM; | ||
1730 | 1732 | ||
1731 | wm8903 = kzalloc(sizeof(struct wm8903_priv), GFP_KERNEL); | 1733 | /* register pcms */ |
1732 | if (wm8903 == NULL) { | 1734 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
1733 | ret = -ENOMEM; | 1735 | if (ret < 0) { |
1734 | goto err_codec; | 1736 | dev_err(&pdev->dev, "failed to create pcms\n"); |
1737 | goto err; | ||
1735 | } | 1738 | } |
1736 | 1739 | ||
1737 | codec->private_data = wm8903; | 1740 | wm8903_add_controls(socdev->codec); |
1738 | socdev->codec = codec; | 1741 | wm8903_add_widgets(socdev->codec); |
1739 | mutex_init(&codec->mutex); | ||
1740 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
1741 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
1742 | |||
1743 | wm8903_socdev = socdev; | ||
1744 | 1742 | ||
1745 | codec->hw_write = (hw_write_t)i2c_master_send; | 1743 | ret = snd_soc_init_card(socdev); |
1746 | ret = i2c_add_driver(&wm8903_i2c_driver); | 1744 | if (ret < 0) { |
1747 | if (ret != 0) { | 1745 | dev_err(&pdev->dev, "wm8903: failed to register card\n"); |
1748 | dev_err(&pdev->dev, "can't add i2c driver\n"); | 1746 | goto card_err; |
1749 | goto err_priv; | ||
1750 | } else { | ||
1751 | memset(&board_info, 0, sizeof(board_info)); | ||
1752 | strlcpy(board_info.type, "wm8903", I2C_NAME_SIZE); | ||
1753 | board_info.addr = setup->i2c_address; | ||
1754 | |||
1755 | adapter = i2c_get_adapter(setup->i2c_bus); | ||
1756 | if (!adapter) { | ||
1757 | dev_err(&pdev->dev, "Can't get I2C bus %d\n", | ||
1758 | setup->i2c_bus); | ||
1759 | ret = -ENODEV; | ||
1760 | goto err_adapter; | ||
1761 | } | ||
1762 | |||
1763 | i2c_client = i2c_new_device(adapter, &board_info); | ||
1764 | i2c_put_adapter(adapter); | ||
1765 | if (i2c_client == NULL) { | ||
1766 | dev_err(&pdev->dev, | ||
1767 | "I2C driver registration failed\n"); | ||
1768 | ret = -ENODEV; | ||
1769 | goto err_adapter; | ||
1770 | } | ||
1771 | } | 1747 | } |
1772 | 1748 | ||
1773 | return ret; | 1749 | return ret; |
1774 | 1750 | ||
1775 | err_adapter: | 1751 | card_err: |
1776 | i2c_del_driver(&wm8903_i2c_driver); | 1752 | snd_soc_free_pcms(socdev); |
1777 | err_priv: | 1753 | snd_soc_dapm_free(socdev); |
1778 | kfree(codec->private_data); | 1754 | err: |
1779 | err_codec: | ||
1780 | kfree(codec); | ||
1781 | return ret; | 1755 | return ret; |
1782 | } | 1756 | } |
1783 | 1757 | ||
@@ -1792,10 +1766,6 @@ static int wm8903_remove(struct platform_device *pdev) | |||
1792 | 1766 | ||
1793 | snd_soc_free_pcms(socdev); | 1767 | snd_soc_free_pcms(socdev); |
1794 | snd_soc_dapm_free(socdev); | 1768 | snd_soc_dapm_free(socdev); |
1795 | i2c_unregister_device(socdev->codec->control_data); | ||
1796 | i2c_del_driver(&wm8903_i2c_driver); | ||
1797 | kfree(codec->private_data); | ||
1798 | kfree(codec); | ||
1799 | 1769 | ||
1800 | return 0; | 1770 | return 0; |
1801 | } | 1771 | } |
@@ -1808,6 +1778,18 @@ struct snd_soc_codec_device soc_codec_dev_wm8903 = { | |||
1808 | }; | 1778 | }; |
1809 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8903); | 1779 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8903); |
1810 | 1780 | ||
1781 | static int __init wm8903_modinit(void) | ||
1782 | { | ||
1783 | return i2c_add_driver(&wm8903_i2c_driver); | ||
1784 | } | ||
1785 | module_init(wm8903_modinit); | ||
1786 | |||
1787 | static void __exit wm8903_exit(void) | ||
1788 | { | ||
1789 | i2c_del_driver(&wm8903_i2c_driver); | ||
1790 | } | ||
1791 | module_exit(wm8903_exit); | ||
1792 | |||
1811 | MODULE_DESCRIPTION("ASoC WM8903 driver"); | 1793 | MODULE_DESCRIPTION("ASoC WM8903 driver"); |
1812 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.cm>"); | 1794 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.cm>"); |
1813 | MODULE_LICENSE("GPL"); | 1795 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/wm8903.h b/sound/soc/codecs/wm8903.h index cec622f2f660..0ea27e2b9963 100644 --- a/sound/soc/codecs/wm8903.h +++ b/sound/soc/codecs/wm8903.h | |||
@@ -18,11 +18,6 @@ | |||
18 | extern struct snd_soc_dai wm8903_dai; | 18 | extern struct snd_soc_dai wm8903_dai; |
19 | extern struct snd_soc_codec_device soc_codec_dev_wm8903; | 19 | extern struct snd_soc_codec_device soc_codec_dev_wm8903; |
20 | 20 | ||
21 | struct wm8903_setup_data { | ||
22 | int i2c_bus; | ||
23 | int i2c_address; | ||
24 | }; | ||
25 | |||
26 | #define WM8903_MCLK_DIV_2 1 | 21 | #define WM8903_MCLK_DIV_2 1 |
27 | #define WM8903_CLK_SYS 2 | 22 | #define WM8903_CLK_SYS 2 |
28 | #define WM8903_BCLK 3 | 23 | #define WM8903_BCLK 3 |
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c index f41a578ddd4f..88ead7f8dd98 100644 --- a/sound/soc/codecs/wm8971.c +++ b/sound/soc/codecs/wm8971.c | |||
@@ -541,7 +541,8 @@ static int wm8971_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
541 | } | 541 | } |
542 | 542 | ||
543 | static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream, | 543 | static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream, |
544 | struct snd_pcm_hw_params *params) | 544 | struct snd_pcm_hw_params *params, |
545 | struct snd_soc_dai *dai) | ||
545 | { | 546 | { |
546 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 547 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
547 | struct snd_soc_device *socdev = rtd->socdev; | 548 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -634,8 +635,6 @@ struct snd_soc_dai wm8971_dai = { | |||
634 | .formats = WM8971_FORMATS,}, | 635 | .formats = WM8971_FORMATS,}, |
635 | .ops = { | 636 | .ops = { |
636 | .hw_params = wm8971_pcm_hw_params, | 637 | .hw_params = wm8971_pcm_hw_params, |
637 | }, | ||
638 | .dai_ops = { | ||
639 | .digital_mute = wm8971_mute, | 638 | .digital_mute = wm8971_mute, |
640 | .set_fmt = wm8971_set_dai_fmt, | 639 | .set_fmt = wm8971_set_dai_fmt, |
641 | .set_sysclk = wm8971_set_dai_sysclk, | 640 | .set_sysclk = wm8971_set_dai_sysclk, |
@@ -748,7 +747,7 @@ static int wm8971_init(struct snd_soc_device *socdev) | |||
748 | 747 | ||
749 | wm8971_add_controls(codec); | 748 | wm8971_add_controls(codec); |
750 | wm8971_add_widgets(codec); | 749 | wm8971_add_widgets(codec); |
751 | ret = snd_soc_register_card(socdev); | 750 | ret = snd_soc_init_card(socdev); |
752 | if (ret < 0) { | 751 | if (ret < 0) { |
753 | printk(KERN_ERR "wm8971: failed to register card\n"); | 752 | printk(KERN_ERR "wm8971: failed to register card\n"); |
754 | goto card_err; | 753 | goto card_err; |
@@ -936,6 +935,18 @@ struct snd_soc_codec_device soc_codec_dev_wm8971 = { | |||
936 | 935 | ||
937 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8971); | 936 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8971); |
938 | 937 | ||
938 | static int __init wm8971_modinit(void) | ||
939 | { | ||
940 | return snd_soc_register_dai(&wm8971_dai); | ||
941 | } | ||
942 | module_init(wm8971_modinit); | ||
943 | |||
944 | static void __exit wm8971_exit(void) | ||
945 | { | ||
946 | snd_soc_unregister_dai(&wm8971_dai); | ||
947 | } | ||
948 | module_exit(wm8971_exit); | ||
949 | |||
939 | MODULE_DESCRIPTION("ASoC WM8971 driver"); | 950 | MODULE_DESCRIPTION("ASoC WM8971 driver"); |
940 | MODULE_AUTHOR("Lab126"); | 951 | MODULE_AUTHOR("Lab126"); |
941 | MODULE_LICENSE("GPL"); | 952 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c index 572d22b0880b..5b5afc144478 100644 --- a/sound/soc/codecs/wm8990.c +++ b/sound/soc/codecs/wm8990.c | |||
@@ -106,6 +106,7 @@ static const u16 wm8990_reg[] = { | |||
106 | 0x0008, /* R60 - PLL1 */ | 106 | 0x0008, /* R60 - PLL1 */ |
107 | 0x0031, /* R61 - PLL2 */ | 107 | 0x0031, /* R61 - PLL2 */ |
108 | 0x0026, /* R62 - PLL3 */ | 108 | 0x0026, /* R62 - PLL3 */ |
109 | 0x0000, /* R63 - Driver internal */ | ||
109 | }; | 110 | }; |
110 | 111 | ||
111 | /* | 112 | /* |
@@ -126,10 +127,9 @@ static inline void wm8990_write_reg_cache(struct snd_soc_codec *codec, | |||
126 | unsigned int reg, unsigned int value) | 127 | unsigned int reg, unsigned int value) |
127 | { | 128 | { |
128 | u16 *cache = codec->reg_cache; | 129 | u16 *cache = codec->reg_cache; |
129 | BUG_ON(reg > (ARRAY_SIZE(wm8990_reg)) - 1); | ||
130 | 130 | ||
131 | /* Reset register is uncached */ | 131 | /* Reset register and reserved registers are uncached */ |
132 | if (reg == 0) | 132 | if (reg == 0 || reg > ARRAY_SIZE(wm8990_reg) - 1) |
133 | return; | 133 | return; |
134 | 134 | ||
135 | cache[reg] = value; | 135 | cache[reg] = value; |
@@ -1172,7 +1172,8 @@ static int wm8990_set_dai_clkdiv(struct snd_soc_dai *codec_dai, | |||
1172 | * Set PCM DAI bit size and sample rate. | 1172 | * Set PCM DAI bit size and sample rate. |
1173 | */ | 1173 | */ |
1174 | static int wm8990_hw_params(struct snd_pcm_substream *substream, | 1174 | static int wm8990_hw_params(struct snd_pcm_substream *substream, |
1175 | struct snd_pcm_hw_params *params) | 1175 | struct snd_pcm_hw_params *params, |
1176 | struct snd_soc_dai *dai) | ||
1176 | { | 1177 | { |
1177 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1178 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
1178 | struct snd_soc_device *socdev = rtd->socdev; | 1179 | struct snd_soc_device *socdev = rtd->socdev; |
@@ -1222,8 +1223,14 @@ static int wm8990_set_bias_level(struct snd_soc_codec *codec, | |||
1222 | switch (level) { | 1223 | switch (level) { |
1223 | case SND_SOC_BIAS_ON: | 1224 | case SND_SOC_BIAS_ON: |
1224 | break; | 1225 | break; |
1226 | |||
1225 | case SND_SOC_BIAS_PREPARE: | 1227 | case SND_SOC_BIAS_PREPARE: |
1228 | /* VMID=2*50k */ | ||
1229 | val = wm8990_read_reg_cache(codec, WM8990_POWER_MANAGEMENT_1) & | ||
1230 | ~WM8990_VMID_MODE_MASK; | ||
1231 | wm8990_write(codec, WM8990_POWER_MANAGEMENT_1, val | 0x2); | ||
1226 | break; | 1232 | break; |
1233 | |||
1227 | case SND_SOC_BIAS_STANDBY: | 1234 | case SND_SOC_BIAS_STANDBY: |
1228 | if (codec->bias_level == SND_SOC_BIAS_OFF) { | 1235 | if (codec->bias_level == SND_SOC_BIAS_OFF) { |
1229 | /* Enable all output discharge bits */ | 1236 | /* Enable all output discharge bits */ |
@@ -1272,10 +1279,17 @@ static int wm8990_set_bias_level(struct snd_soc_codec *codec, | |||
1272 | 1279 | ||
1273 | /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ | 1280 | /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ |
1274 | wm8990_write(codec, WM8990_ANTIPOP2, WM8990_BUFIOEN); | 1281 | wm8990_write(codec, WM8990_ANTIPOP2, WM8990_BUFIOEN); |
1275 | } else { | ||
1276 | /* ON -> standby */ | ||
1277 | 1282 | ||
1283 | /* Enable workaround for ADC clocking issue. */ | ||
1284 | wm8990_write(codec, WM8990_EXT_ACCESS_ENA, 0x2); | ||
1285 | wm8990_write(codec, WM8990_EXT_CTL1, 0xa003); | ||
1286 | wm8990_write(codec, WM8990_EXT_ACCESS_ENA, 0); | ||
1278 | } | 1287 | } |
1288 | |||
1289 | /* VMID=2*250k */ | ||
1290 | val = wm8990_read_reg_cache(codec, WM8990_POWER_MANAGEMENT_1) & | ||
1291 | ~WM8990_VMID_MODE_MASK; | ||
1292 | wm8990_write(codec, WM8990_POWER_MANAGEMENT_1, val | 0x4); | ||
1279 | break; | 1293 | break; |
1280 | 1294 | ||
1281 | case SND_SOC_BIAS_OFF: | 1295 | case SND_SOC_BIAS_OFF: |
@@ -1349,8 +1363,7 @@ struct snd_soc_dai wm8990_dai = { | |||
1349 | .rates = WM8990_RATES, | 1363 | .rates = WM8990_RATES, |
1350 | .formats = WM8990_FORMATS,}, | 1364 | .formats = WM8990_FORMATS,}, |
1351 | .ops = { | 1365 | .ops = { |
1352 | .hw_params = wm8990_hw_params,}, | 1366 | .hw_params = wm8990_hw_params, |
1353 | .dai_ops = { | ||
1354 | .digital_mute = wm8990_mute, | 1367 | .digital_mute = wm8990_mute, |
1355 | .set_fmt = wm8990_set_dai_fmt, | 1368 | .set_fmt = wm8990_set_dai_fmt, |
1356 | .set_clkdiv = wm8990_set_dai_clkdiv, | 1369 | .set_clkdiv = wm8990_set_dai_clkdiv, |
@@ -1449,7 +1462,7 @@ static int wm8990_init(struct snd_soc_device *socdev) | |||
1449 | 1462 | ||
1450 | wm8990_add_controls(codec); | 1463 | wm8990_add_controls(codec); |
1451 | wm8990_add_widgets(codec); | 1464 | wm8990_add_widgets(codec); |
1452 | ret = snd_soc_register_card(socdev); | 1465 | ret = snd_soc_init_card(socdev); |
1453 | if (ret < 0) { | 1466 | if (ret < 0) { |
1454 | printk(KERN_ERR "wm8990: failed to register card\n"); | 1467 | printk(KERN_ERR "wm8990: failed to register card\n"); |
1455 | goto card_err; | 1468 | goto card_err; |
@@ -1630,6 +1643,18 @@ struct snd_soc_codec_device soc_codec_dev_wm8990 = { | |||
1630 | }; | 1643 | }; |
1631 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8990); | 1644 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8990); |
1632 | 1645 | ||
1646 | static int __init wm8990_modinit(void) | ||
1647 | { | ||
1648 | return snd_soc_register_dai(&wm8990_dai); | ||
1649 | } | ||
1650 | module_init(wm8990_modinit); | ||
1651 | |||
1652 | static void __exit wm8990_exit(void) | ||
1653 | { | ||
1654 | snd_soc_unregister_dai(&wm8990_dai); | ||
1655 | } | ||
1656 | module_exit(wm8990_exit); | ||
1657 | |||
1633 | MODULE_DESCRIPTION("ASoC WM8990 driver"); | 1658 | MODULE_DESCRIPTION("ASoC WM8990 driver"); |
1634 | MODULE_AUTHOR("Liam Girdwood"); | 1659 | MODULE_AUTHOR("Liam Girdwood"); |
1635 | MODULE_LICENSE("GPL"); | 1660 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/codecs/wm8990.h b/sound/soc/codecs/wm8990.h index 0e192f3b0788..7114ddc88b4b 100644 --- a/sound/soc/codecs/wm8990.h +++ b/sound/soc/codecs/wm8990.h | |||
@@ -80,8 +80,8 @@ | |||
80 | #define WM8990_PLL3 0x3E | 80 | #define WM8990_PLL3 0x3E |
81 | #define WM8990_INTDRIVBITS 0x3F | 81 | #define WM8990_INTDRIVBITS 0x3F |
82 | 82 | ||
83 | #define WM8990_REGISTER_COUNT 60 | 83 | #define WM8990_EXT_ACCESS_ENA 0x75 |
84 | #define WM8990_MAX_REGISTER 0x3F | 84 | #define WM8990_EXT_CTL1 0x7a |
85 | 85 | ||
86 | /* | 86 | /* |
87 | * Field Definitions. | 87 | * Field Definitions. |
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c index ffb471e420e2..af83d629078a 100644 --- a/sound/soc/codecs/wm9712.c +++ b/sound/soc/codecs/wm9712.c | |||
@@ -487,7 +487,8 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, | |||
487 | return 0; | 487 | return 0; |
488 | } | 488 | } |
489 | 489 | ||
490 | static int ac97_prepare(struct snd_pcm_substream *substream) | 490 | static int ac97_prepare(struct snd_pcm_substream *substream, |
491 | struct snd_soc_dai *dai) | ||
491 | { | 492 | { |
492 | struct snd_pcm_runtime *runtime = substream->runtime; | 493 | struct snd_pcm_runtime *runtime = substream->runtime; |
493 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 494 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
@@ -507,7 +508,8 @@ static int ac97_prepare(struct snd_pcm_substream *substream) | |||
507 | return ac97_write(codec, reg, runtime->rate); | 508 | return ac97_write(codec, reg, runtime->rate); |
508 | } | 509 | } |
509 | 510 | ||
510 | static int ac97_aux_prepare(struct snd_pcm_substream *substream) | 511 | static int ac97_aux_prepare(struct snd_pcm_substream *substream, |
512 | struct snd_soc_dai *dai) | ||
511 | { | 513 | { |
512 | struct snd_pcm_runtime *runtime = substream->runtime; | 514 | struct snd_pcm_runtime *runtime = substream->runtime; |
513 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 515 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
@@ -533,7 +535,7 @@ static int ac97_aux_prepare(struct snd_pcm_substream *substream) | |||
533 | struct snd_soc_dai wm9712_dai[] = { | 535 | struct snd_soc_dai wm9712_dai[] = { |
534 | { | 536 | { |
535 | .name = "AC97 HiFi", | 537 | .name = "AC97 HiFi", |
536 | .type = SND_SOC_DAI_AC97_BUS, | 538 | .ac97_control = 1, |
537 | .playback = { | 539 | .playback = { |
538 | .stream_name = "HiFi Playback", | 540 | .stream_name = "HiFi Playback", |
539 | .channels_min = 1, | 541 | .channels_min = 1, |
@@ -688,7 +690,7 @@ static int wm9712_soc_probe(struct platform_device *pdev) | |||
688 | 690 | ||
689 | ret = wm9712_reset(codec, 0); | 691 | ret = wm9712_reset(codec, 0); |
690 | if (ret < 0) { | 692 | if (ret < 0) { |
691 | printk(KERN_ERR "AC97 link error\n"); | 693 | printk(KERN_ERR "Failed to reset WM9712: AC97 link error\n"); |
692 | goto reset_err; | 694 | goto reset_err; |
693 | } | 695 | } |
694 | 696 | ||
@@ -698,7 +700,7 @@ static int wm9712_soc_probe(struct platform_device *pdev) | |||
698 | wm9712_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 700 | wm9712_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
699 | wm9712_add_controls(codec); | 701 | wm9712_add_controls(codec); |
700 | wm9712_add_widgets(codec); | 702 | wm9712_add_widgets(codec); |
701 | ret = snd_soc_register_card(socdev); | 703 | ret = snd_soc_init_card(socdev); |
702 | if (ret < 0) { | 704 | if (ret < 0) { |
703 | printk(KERN_ERR "wm9712: failed to register card\n"); | 705 | printk(KERN_ERR "wm9712: failed to register card\n"); |
704 | goto reset_err; | 706 | goto reset_err; |
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c index 945b32ed9884..f3ca8aaf0139 100644 --- a/sound/soc/codecs/wm9713.c +++ b/sound/soc/codecs/wm9713.c | |||
@@ -928,11 +928,10 @@ static int wm9713_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
928 | } | 928 | } |
929 | 929 | ||
930 | static int wm9713_pcm_hw_params(struct snd_pcm_substream *substream, | 930 | static int wm9713_pcm_hw_params(struct snd_pcm_substream *substream, |
931 | struct snd_pcm_hw_params *params) | 931 | struct snd_pcm_hw_params *params, |
932 | struct snd_soc_dai *dai) | ||
932 | { | 933 | { |
933 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 934 | struct snd_soc_codec *codec = dai->codec; |
934 | struct snd_soc_device *socdev = rtd->socdev; | ||
935 | struct snd_soc_codec *codec = socdev->codec; | ||
936 | u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xfff3; | 935 | u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xfff3; |
937 | 936 | ||
938 | switch (params_format(params)) { | 937 | switch (params_format(params)) { |
@@ -954,11 +953,10 @@ static int wm9713_pcm_hw_params(struct snd_pcm_substream *substream, | |||
954 | return 0; | 953 | return 0; |
955 | } | 954 | } |
956 | 955 | ||
957 | static void wm9713_voiceshutdown(struct snd_pcm_substream *substream) | 956 | static void wm9713_voiceshutdown(struct snd_pcm_substream *substream, |
957 | struct snd_soc_dai *dai) | ||
958 | { | 958 | { |
959 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 959 | struct snd_soc_codec *codec = dai->codec; |
960 | struct snd_soc_device *socdev = rtd->socdev; | ||
961 | struct snd_soc_codec *codec = socdev->codec; | ||
962 | u16 status; | 960 | u16 status; |
963 | 961 | ||
964 | /* Gracefully shut down the voice interface. */ | 962 | /* Gracefully shut down the voice interface. */ |
@@ -969,12 +967,11 @@ static void wm9713_voiceshutdown(struct snd_pcm_substream *substream) | |||
969 | ac97_write(codec, AC97_EXTENDED_MID, status); | 967 | ac97_write(codec, AC97_EXTENDED_MID, status); |
970 | } | 968 | } |
971 | 969 | ||
972 | static int ac97_hifi_prepare(struct snd_pcm_substream *substream) | 970 | static int ac97_hifi_prepare(struct snd_pcm_substream *substream, |
971 | struct snd_soc_dai *dai) | ||
973 | { | 972 | { |
973 | struct snd_soc_codec *codec = dai->codec; | ||
974 | struct snd_pcm_runtime *runtime = substream->runtime; | 974 | struct snd_pcm_runtime *runtime = substream->runtime; |
975 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
976 | struct snd_soc_device *socdev = rtd->socdev; | ||
977 | struct snd_soc_codec *codec = socdev->codec; | ||
978 | int reg; | 975 | int reg; |
979 | u16 vra; | 976 | u16 vra; |
980 | 977 | ||
@@ -989,12 +986,11 @@ static int ac97_hifi_prepare(struct snd_pcm_substream *substream) | |||
989 | return ac97_write(codec, reg, runtime->rate); | 986 | return ac97_write(codec, reg, runtime->rate); |
990 | } | 987 | } |
991 | 988 | ||
992 | static int ac97_aux_prepare(struct snd_pcm_substream *substream) | 989 | static int ac97_aux_prepare(struct snd_pcm_substream *substream, |
990 | struct snd_soc_dai *dai) | ||
993 | { | 991 | { |
992 | struct snd_soc_codec *codec = dai->codec; | ||
994 | struct snd_pcm_runtime *runtime = substream->runtime; | 993 | struct snd_pcm_runtime *runtime = substream->runtime; |
995 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
996 | struct snd_soc_device *socdev = rtd->socdev; | ||
997 | struct snd_soc_codec *codec = socdev->codec; | ||
998 | u16 vra, xsle; | 994 | u16 vra, xsle; |
999 | 995 | ||
1000 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); | 996 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); |
@@ -1028,7 +1024,7 @@ static int ac97_aux_prepare(struct snd_pcm_substream *substream) | |||
1028 | struct snd_soc_dai wm9713_dai[] = { | 1024 | struct snd_soc_dai wm9713_dai[] = { |
1029 | { | 1025 | { |
1030 | .name = "AC97 HiFi", | 1026 | .name = "AC97 HiFi", |
1031 | .type = SND_SOC_DAI_AC97_BUS, | 1027 | .ac97_control = 1, |
1032 | .playback = { | 1028 | .playback = { |
1033 | .stream_name = "HiFi Playback", | 1029 | .stream_name = "HiFi Playback", |
1034 | .channels_min = 1, | 1030 | .channels_min = 1, |
@@ -1042,8 +1038,7 @@ struct snd_soc_dai wm9713_dai[] = { | |||
1042 | .rates = WM9713_RATES, | 1038 | .rates = WM9713_RATES, |
1043 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 1039 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
1044 | .ops = { | 1040 | .ops = { |
1045 | .prepare = ac97_hifi_prepare,}, | 1041 | .prepare = ac97_hifi_prepare, |
1046 | .dai_ops = { | ||
1047 | .set_clkdiv = wm9713_set_dai_clkdiv, | 1042 | .set_clkdiv = wm9713_set_dai_clkdiv, |
1048 | .set_pll = wm9713_set_dai_pll,}, | 1043 | .set_pll = wm9713_set_dai_pll,}, |
1049 | }, | 1044 | }, |
@@ -1056,8 +1051,7 @@ struct snd_soc_dai wm9713_dai[] = { | |||
1056 | .rates = WM9713_RATES, | 1051 | .rates = WM9713_RATES, |
1057 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 1052 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
1058 | .ops = { | 1053 | .ops = { |
1059 | .prepare = ac97_aux_prepare,}, | 1054 | .prepare = ac97_aux_prepare, |
1060 | .dai_ops = { | ||
1061 | .set_clkdiv = wm9713_set_dai_clkdiv, | 1055 | .set_clkdiv = wm9713_set_dai_clkdiv, |
1062 | .set_pll = wm9713_set_dai_pll,}, | 1056 | .set_pll = wm9713_set_dai_pll,}, |
1063 | }, | 1057 | }, |
@@ -1077,8 +1071,7 @@ struct snd_soc_dai wm9713_dai[] = { | |||
1077 | .formats = WM9713_PCM_FORMATS,}, | 1071 | .formats = WM9713_PCM_FORMATS,}, |
1078 | .ops = { | 1072 | .ops = { |
1079 | .hw_params = wm9713_pcm_hw_params, | 1073 | .hw_params = wm9713_pcm_hw_params, |
1080 | .shutdown = wm9713_voiceshutdown,}, | 1074 | .shutdown = wm9713_voiceshutdown, |
1081 | .dai_ops = { | ||
1082 | .set_clkdiv = wm9713_set_dai_clkdiv, | 1075 | .set_clkdiv = wm9713_set_dai_clkdiv, |
1083 | .set_pll = wm9713_set_dai_pll, | 1076 | .set_pll = wm9713_set_dai_pll, |
1084 | .set_fmt = wm9713_set_dai_fmt, | 1077 | .set_fmt = wm9713_set_dai_fmt, |
@@ -1097,6 +1090,8 @@ int wm9713_reset(struct snd_soc_codec *codec, int try_warm) | |||
1097 | } | 1090 | } |
1098 | 1091 | ||
1099 | soc_ac97_ops.reset(codec->ac97); | 1092 | soc_ac97_ops.reset(codec->ac97); |
1093 | if (soc_ac97_ops.warm_reset) | ||
1094 | soc_ac97_ops.warm_reset(codec->ac97); | ||
1100 | if (ac97_read(codec, 0) != wm9713_reg[0]) | 1095 | if (ac97_read(codec, 0) != wm9713_reg[0]) |
1101 | return -EIO; | 1096 | return -EIO; |
1102 | return 0; | 1097 | return 0; |
@@ -1240,7 +1235,7 @@ static int wm9713_soc_probe(struct platform_device *pdev) | |||
1240 | wm9713_reset(codec, 0); | 1235 | wm9713_reset(codec, 0); |
1241 | ret = wm9713_reset(codec, 1); | 1236 | ret = wm9713_reset(codec, 1); |
1242 | if (ret < 0) { | 1237 | if (ret < 0) { |
1243 | printk(KERN_ERR "AC97 link error\n"); | 1238 | printk(KERN_ERR "Failed to reset WM9713: AC97 link error\n"); |
1244 | goto reset_err; | 1239 | goto reset_err; |
1245 | } | 1240 | } |
1246 | 1241 | ||
@@ -1252,7 +1247,7 @@ static int wm9713_soc_probe(struct platform_device *pdev) | |||
1252 | 1247 | ||
1253 | wm9713_add_controls(codec); | 1248 | wm9713_add_controls(codec); |
1254 | wm9713_add_widgets(codec); | 1249 | wm9713_add_widgets(codec); |
1255 | ret = snd_soc_register_card(socdev); | 1250 | ret = snd_soc_init_card(socdev); |
1256 | if (ret < 0) | 1251 | if (ret < 0) |
1257 | goto reset_err; | 1252 | goto reset_err; |
1258 | return 0; | 1253 | return 0; |
@@ -1288,7 +1283,6 @@ static int wm9713_soc_remove(struct platform_device *pdev) | |||
1288 | snd_soc_free_ac97_codec(codec); | 1283 | snd_soc_free_ac97_codec(codec); |
1289 | kfree(codec->private_data); | 1284 | kfree(codec->private_data); |
1290 | kfree(codec->reg_cache); | 1285 | kfree(codec->reg_cache); |
1291 | kfree(codec->dai); | ||
1292 | kfree(codec); | 1286 | kfree(codec); |
1293 | return 0; | 1287 | return 0; |
1294 | } | 1288 | } |