diff options
Diffstat (limited to 'sound/soc/codecs')
40 files changed, 4567 insertions, 1937 deletions
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index d0e0d691ae51..b6c7f7a01cb0 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig | |||
@@ -10,9 +10,11 @@ config SND_SOC_I2C_AND_SPI | |||
10 | 10 | ||
11 | config SND_SOC_ALL_CODECS | 11 | config SND_SOC_ALL_CODECS |
12 | tristate "Build all ASoC CODEC drivers" | 12 | tristate "Build all ASoC CODEC drivers" |
13 | select SND_SOC_L3 | ||
13 | select SND_SOC_AC97_CODEC if SND_SOC_AC97_BUS | 14 | select SND_SOC_AC97_CODEC if SND_SOC_AC97_BUS |
14 | select SND_SOC_AD1980 if SND_SOC_AC97_BUS | 15 | select SND_SOC_AD1980 if SND_SOC_AC97_BUS |
15 | select SND_SOC_AD73311 if I2C | 16 | select SND_SOC_AD73311 if I2C |
17 | select SND_SOC_AK4104 if SPI_MASTER | ||
16 | select SND_SOC_AK4535 if I2C | 18 | select SND_SOC_AK4535 if I2C |
17 | select SND_SOC_CS4270 if I2C | 19 | select SND_SOC_CS4270 if I2C |
18 | select SND_SOC_PCM3008 | 20 | select SND_SOC_PCM3008 |
@@ -24,6 +26,7 @@ config SND_SOC_ALL_CODECS | |||
24 | select SND_SOC_UDA134X | 26 | select SND_SOC_UDA134X |
25 | select SND_SOC_UDA1380 if I2C | 27 | select SND_SOC_UDA1380 if I2C |
26 | select SND_SOC_WM8350 if MFD_WM8350 | 28 | select SND_SOC_WM8350 if MFD_WM8350 |
29 | select SND_SOC_WM8400 if MFD_WM8400 | ||
27 | select SND_SOC_WM8510 if SND_SOC_I2C_AND_SPI | 30 | select SND_SOC_WM8510 if SND_SOC_I2C_AND_SPI |
28 | select SND_SOC_WM8580 if I2C | 31 | select SND_SOC_WM8580 if I2C |
29 | select SND_SOC_WM8728 if SND_SOC_I2C_AND_SPI | 32 | select SND_SOC_WM8728 if SND_SOC_I2C_AND_SPI |
@@ -34,6 +37,7 @@ config SND_SOC_ALL_CODECS | |||
34 | select SND_SOC_WM8903 if I2C | 37 | select SND_SOC_WM8903 if I2C |
35 | select SND_SOC_WM8971 if I2C | 38 | select SND_SOC_WM8971 if I2C |
36 | select SND_SOC_WM8990 if I2C | 39 | select SND_SOC_WM8990 if I2C |
40 | select SND_SOC_WM9705 if SND_SOC_AC97_BUS | ||
37 | select SND_SOC_WM9712 if SND_SOC_AC97_BUS | 41 | select SND_SOC_WM9712 if SND_SOC_AC97_BUS |
38 | select SND_SOC_WM9713 if SND_SOC_AC97_BUS | 42 | select SND_SOC_WM9713 if SND_SOC_AC97_BUS |
39 | help | 43 | help |
@@ -58,6 +62,9 @@ config SND_SOC_AD1980 | |||
58 | config SND_SOC_AD73311 | 62 | config SND_SOC_AD73311 |
59 | tristate | 63 | tristate |
60 | 64 | ||
65 | config SND_SOC_AK4104 | ||
66 | tristate | ||
67 | |||
61 | config SND_SOC_AK4535 | 68 | config SND_SOC_AK4535 |
62 | tristate | 69 | tristate |
63 | 70 | ||
@@ -65,12 +72,6 @@ config SND_SOC_AK4535 | |||
65 | config SND_SOC_CS4270 | 72 | config SND_SOC_CS4270 |
66 | tristate | 73 | tristate |
67 | 74 | ||
68 | # Cirrus Logic CS4270 Codec Hardware Mute Support | ||
69 | # Select if you have external muting circuitry attached to your CS4270. | ||
70 | config SND_SOC_CS4270_HWMUTE | ||
71 | bool | ||
72 | depends on SND_SOC_CS4270 | ||
73 | |||
74 | # Cirrus Logic CS4270 Codec VD = 3.3V Errata | 75 | # Cirrus Logic CS4270 Codec VD = 3.3V Errata |
75 | # Select if you are affected by the errata where the part will not function | 76 | # Select if you are affected by the errata where the part will not function |
76 | # if MCLK divide-by-1.5 is selected and VD is set to 3.3V. The driver will | 77 | # if MCLK divide-by-1.5 is selected and VD is set to 3.3V. The driver will |
@@ -90,7 +91,6 @@ config SND_SOC_SSM2602 | |||
90 | 91 | ||
91 | config SND_SOC_TLV320AIC23 | 92 | config SND_SOC_TLV320AIC23 |
92 | tristate | 93 | tristate |
93 | depends on I2C | ||
94 | 94 | ||
95 | config SND_SOC_TLV320AIC26 | 95 | config SND_SOC_TLV320AIC26 |
96 | tristate "TI TLV320AIC26 Codec support" if SND_SOC_OF_SIMPLE | 96 | tristate "TI TLV320AIC26 Codec support" if SND_SOC_OF_SIMPLE |
@@ -98,15 +98,12 @@ config SND_SOC_TLV320AIC26 | |||
98 | 98 | ||
99 | config SND_SOC_TLV320AIC3X | 99 | config SND_SOC_TLV320AIC3X |
100 | tristate | 100 | tristate |
101 | depends on I2C | ||
102 | 101 | ||
103 | config SND_SOC_TWL4030 | 102 | config SND_SOC_TWL4030 |
104 | tristate | 103 | tristate |
105 | depends on TWL4030_CORE | ||
106 | 104 | ||
107 | config SND_SOC_UDA134X | 105 | config SND_SOC_UDA134X |
108 | tristate | 106 | tristate |
109 | select SND_SOC_L3 | ||
110 | 107 | ||
111 | config SND_SOC_UDA1380 | 108 | config SND_SOC_UDA1380 |
112 | tristate | 109 | tristate |
@@ -114,6 +111,9 @@ config SND_SOC_UDA1380 | |||
114 | config SND_SOC_WM8350 | 111 | config SND_SOC_WM8350 |
115 | tristate | 112 | tristate |
116 | 113 | ||
114 | config SND_SOC_WM8400 | ||
115 | tristate | ||
116 | |||
117 | config SND_SOC_WM8510 | 117 | config SND_SOC_WM8510 |
118 | tristate | 118 | tristate |
119 | 119 | ||
@@ -144,6 +144,9 @@ config SND_SOC_WM8971 | |||
144 | config SND_SOC_WM8990 | 144 | config SND_SOC_WM8990 |
145 | tristate | 145 | tristate |
146 | 146 | ||
147 | config SND_SOC_WM9705 | ||
148 | tristate | ||
149 | |||
147 | config SND_SOC_WM9712 | 150 | config SND_SOC_WM9712 |
148 | tristate | 151 | tristate |
149 | 152 | ||
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index c4ddc9aa2bbd..030d2454725f 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile | |||
@@ -1,6 +1,7 @@ | |||
1 | snd-soc-ac97-objs := ac97.o | 1 | snd-soc-ac97-objs := ac97.o |
2 | snd-soc-ad1980-objs := ad1980.o | 2 | snd-soc-ad1980-objs := ad1980.o |
3 | snd-soc-ad73311-objs := ad73311.o | 3 | snd-soc-ad73311-objs := ad73311.o |
4 | snd-soc-ak4104-objs := ak4104.o | ||
4 | snd-soc-ak4535-objs := ak4535.o | 5 | snd-soc-ak4535-objs := ak4535.o |
5 | snd-soc-cs4270-objs := cs4270.o | 6 | snd-soc-cs4270-objs := cs4270.o |
6 | snd-soc-l3-objs := l3.o | 7 | snd-soc-l3-objs := l3.o |
@@ -13,6 +14,7 @@ snd-soc-twl4030-objs := twl4030.o | |||
13 | snd-soc-uda134x-objs := uda134x.o | 14 | snd-soc-uda134x-objs := uda134x.o |
14 | snd-soc-uda1380-objs := uda1380.o | 15 | snd-soc-uda1380-objs := uda1380.o |
15 | snd-soc-wm8350-objs := wm8350.o | 16 | snd-soc-wm8350-objs := wm8350.o |
17 | snd-soc-wm8400-objs := wm8400.o | ||
16 | snd-soc-wm8510-objs := wm8510.o | 18 | snd-soc-wm8510-objs := wm8510.o |
17 | snd-soc-wm8580-objs := wm8580.o | 19 | snd-soc-wm8580-objs := wm8580.o |
18 | snd-soc-wm8728-objs := wm8728.o | 20 | snd-soc-wm8728-objs := wm8728.o |
@@ -23,12 +25,14 @@ snd-soc-wm8900-objs := wm8900.o | |||
23 | snd-soc-wm8903-objs := wm8903.o | 25 | snd-soc-wm8903-objs := wm8903.o |
24 | snd-soc-wm8971-objs := wm8971.o | 26 | snd-soc-wm8971-objs := wm8971.o |
25 | snd-soc-wm8990-objs := wm8990.o | 27 | snd-soc-wm8990-objs := wm8990.o |
28 | snd-soc-wm9705-objs := wm9705.o | ||
26 | snd-soc-wm9712-objs := wm9712.o | 29 | snd-soc-wm9712-objs := wm9712.o |
27 | snd-soc-wm9713-objs := wm9713.o | 30 | snd-soc-wm9713-objs := wm9713.o |
28 | 31 | ||
29 | obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o | 32 | obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o |
30 | obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o | 33 | obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o |
31 | obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o | 34 | obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o |
35 | obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o | ||
32 | obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o | 36 | obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o |
33 | obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o | 37 | obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o |
34 | obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o | 38 | obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o |
@@ -41,6 +45,7 @@ obj-$(CONFIG_SND_SOC_TWL4030) += snd-soc-twl4030.o | |||
41 | obj-$(CONFIG_SND_SOC_UDA134X) += snd-soc-uda134x.o | 45 | obj-$(CONFIG_SND_SOC_UDA134X) += snd-soc-uda134x.o |
42 | obj-$(CONFIG_SND_SOC_UDA1380) += snd-soc-uda1380.o | 46 | obj-$(CONFIG_SND_SOC_UDA1380) += snd-soc-uda1380.o |
43 | obj-$(CONFIG_SND_SOC_WM8350) += snd-soc-wm8350.o | 47 | obj-$(CONFIG_SND_SOC_WM8350) += snd-soc-wm8350.o |
48 | obj-$(CONFIG_SND_SOC_WM8400) += snd-soc-wm8400.o | ||
44 | obj-$(CONFIG_SND_SOC_WM8510) += snd-soc-wm8510.o | 49 | obj-$(CONFIG_SND_SOC_WM8510) += snd-soc-wm8510.o |
45 | obj-$(CONFIG_SND_SOC_WM8580) += snd-soc-wm8580.o | 50 | obj-$(CONFIG_SND_SOC_WM8580) += snd-soc-wm8580.o |
46 | obj-$(CONFIG_SND_SOC_WM8728) += snd-soc-wm8728.o | 51 | obj-$(CONFIG_SND_SOC_WM8728) += snd-soc-wm8728.o |
@@ -51,5 +56,7 @@ obj-$(CONFIG_SND_SOC_WM8900) += snd-soc-wm8900.o | |||
51 | obj-$(CONFIG_SND_SOC_WM8903) += snd-soc-wm8903.o | 56 | obj-$(CONFIG_SND_SOC_WM8903) += snd-soc-wm8903.o |
52 | obj-$(CONFIG_SND_SOC_WM8971) += snd-soc-wm8971.o | 57 | obj-$(CONFIG_SND_SOC_WM8971) += snd-soc-wm8971.o |
53 | obj-$(CONFIG_SND_SOC_WM8990) += snd-soc-wm8990.o | 58 | obj-$(CONFIG_SND_SOC_WM8990) += snd-soc-wm8990.o |
59 | obj-$(CONFIG_SND_SOC_WM8991) += snd-soc-wm8991.o | ||
60 | obj-$(CONFIG_SND_SOC_WM9705) += snd-soc-wm9705.o | ||
54 | obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o | 61 | obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o |
55 | obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o | 62 | obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o |
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c index fb53e6511af2..b0d4af145b87 100644 --- a/sound/soc/codecs/ac97.c +++ b/sound/soc/codecs/ac97.c | |||
@@ -30,7 +30,7 @@ static int ac97_prepare(struct snd_pcm_substream *substream, | |||
30 | struct snd_pcm_runtime *runtime = substream->runtime; | 30 | struct snd_pcm_runtime *runtime = substream->runtime; |
31 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 31 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
32 | struct snd_soc_device *socdev = rtd->socdev; | 32 | struct snd_soc_device *socdev = rtd->socdev; |
33 | struct snd_soc_codec *codec = socdev->codec; | 33 | struct snd_soc_codec *codec = socdev->card->codec; |
34 | 34 | ||
35 | int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? | 35 | int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? |
36 | AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE; | 36 | AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE; |
@@ -41,6 +41,10 @@ static int ac97_prepare(struct snd_pcm_substream *substream, | |||
41 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\ | 41 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\ |
42 | SNDRV_PCM_RATE_48000) | 42 | SNDRV_PCM_RATE_48000) |
43 | 43 | ||
44 | static struct snd_soc_dai_ops ac97_dai_ops = { | ||
45 | .prepare = ac97_prepare, | ||
46 | }; | ||
47 | |||
44 | struct snd_soc_dai ac97_dai = { | 48 | struct snd_soc_dai ac97_dai = { |
45 | .name = "AC97 HiFi", | 49 | .name = "AC97 HiFi", |
46 | .ac97_control = 1, | 50 | .ac97_control = 1, |
@@ -56,8 +60,7 @@ struct snd_soc_dai ac97_dai = { | |||
56 | .channels_max = 2, | 60 | .channels_max = 2, |
57 | .rates = STD_AC97_RATES, | 61 | .rates = STD_AC97_RATES, |
58 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 62 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
59 | .ops = { | 63 | .ops = &ac97_dai_ops, |
60 | .prepare = ac97_prepare,}, | ||
61 | }; | 64 | }; |
62 | EXPORT_SYMBOL_GPL(ac97_dai); | 65 | EXPORT_SYMBOL_GPL(ac97_dai); |
63 | 66 | ||
@@ -84,10 +87,10 @@ static int ac97_soc_probe(struct platform_device *pdev) | |||
84 | 87 | ||
85 | printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION); | 88 | printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION); |
86 | 89 | ||
87 | socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | 90 | socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
88 | if (!socdev->codec) | 91 | if (!socdev->card->codec) |
89 | return -ENOMEM; | 92 | return -ENOMEM; |
90 | codec = socdev->codec; | 93 | codec = socdev->card->codec; |
91 | mutex_init(&codec->mutex); | 94 | mutex_init(&codec->mutex); |
92 | 95 | ||
93 | codec->name = "AC97"; | 96 | codec->name = "AC97"; |
@@ -123,23 +126,21 @@ bus_err: | |||
123 | snd_soc_free_pcms(socdev); | 126 | snd_soc_free_pcms(socdev); |
124 | 127 | ||
125 | err: | 128 | err: |
126 | kfree(socdev->codec->reg_cache); | 129 | kfree(socdev->card->codec); |
127 | kfree(socdev->codec); | 130 | socdev->card->codec = NULL; |
128 | socdev->codec = NULL; | ||
129 | return ret; | 131 | return ret; |
130 | } | 132 | } |
131 | 133 | ||
132 | static int ac97_soc_remove(struct platform_device *pdev) | 134 | static int ac97_soc_remove(struct platform_device *pdev) |
133 | { | 135 | { |
134 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 136 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
135 | struct snd_soc_codec *codec = socdev->codec; | 137 | struct snd_soc_codec *codec = socdev->card->codec; |
136 | 138 | ||
137 | if (!codec) | 139 | if (!codec) |
138 | return 0; | 140 | return 0; |
139 | 141 | ||
140 | snd_soc_free_pcms(socdev); | 142 | snd_soc_free_pcms(socdev); |
141 | kfree(socdev->codec->reg_cache); | 143 | kfree(socdev->card->codec); |
142 | kfree(socdev->codec); | ||
143 | 144 | ||
144 | return 0; | 145 | return 0; |
145 | } | 146 | } |
@@ -149,7 +150,7 @@ static int ac97_soc_suspend(struct platform_device *pdev, pm_message_t msg) | |||
149 | { | 150 | { |
150 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 151 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
151 | 152 | ||
152 | snd_ac97_suspend(socdev->codec->ac97); | 153 | snd_ac97_suspend(socdev->card->codec->ac97); |
153 | 154 | ||
154 | return 0; | 155 | return 0; |
155 | } | 156 | } |
@@ -158,7 +159,7 @@ static int ac97_soc_resume(struct platform_device *pdev) | |||
158 | { | 159 | { |
159 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 160 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
160 | 161 | ||
161 | snd_ac97_resume(socdev->codec->ac97); | 162 | snd_ac97_resume(socdev->card->codec->ac97); |
162 | 163 | ||
163 | return 0; | 164 | return 0; |
164 | } | 165 | } |
diff --git a/sound/soc/codecs/ad1980.c b/sound/soc/codecs/ad1980.c index 73fdbb4d4a3d..ddb3b08ac23c 100644 --- a/sound/soc/codecs/ad1980.c +++ b/sound/soc/codecs/ad1980.c | |||
@@ -93,20 +93,6 @@ SOC_ENUM("Capture Source", ad1980_cap_src), | |||
93 | SOC_SINGLE("Mic Boost Switch", AC97_MIC, 6, 1, 0), | 93 | SOC_SINGLE("Mic Boost Switch", AC97_MIC, 6, 1, 0), |
94 | }; | 94 | }; |
95 | 95 | ||
96 | /* add non dapm controls */ | ||
97 | static int ad1980_add_controls(struct snd_soc_codec *codec) | ||
98 | { | ||
99 | int err, i; | ||
100 | |||
101 | for (i = 0; i < ARRAY_SIZE(ad1980_snd_ac97_controls); i++) { | ||
102 | err = snd_ctl_add(codec->card, snd_soc_cnew( | ||
103 | &ad1980_snd_ac97_controls[i], codec, NULL)); | ||
104 | if (err < 0) | ||
105 | return err; | ||
106 | } | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | static unsigned int ac97_read(struct snd_soc_codec *codec, | 96 | static unsigned int ac97_read(struct snd_soc_codec *codec, |
111 | unsigned int reg) | 97 | unsigned int reg) |
112 | { | 98 | { |
@@ -123,7 +109,7 @@ static unsigned int ac97_read(struct snd_soc_codec *codec, | |||
123 | default: | 109 | default: |
124 | reg = reg >> 1; | 110 | reg = reg >> 1; |
125 | 111 | ||
126 | if (reg >= (ARRAY_SIZE(ad1980_reg))) | 112 | if (reg >= ARRAY_SIZE(ad1980_reg)) |
127 | return -EINVAL; | 113 | return -EINVAL; |
128 | 114 | ||
129 | return cache[reg]; | 115 | return cache[reg]; |
@@ -137,7 +123,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, | |||
137 | 123 | ||
138 | soc_ac97_ops.write(codec->ac97, reg, val); | 124 | soc_ac97_ops.write(codec->ac97, reg, val); |
139 | reg = reg >> 1; | 125 | reg = reg >> 1; |
140 | if (reg < (ARRAY_SIZE(ad1980_reg))) | 126 | if (reg < ARRAY_SIZE(ad1980_reg)) |
141 | cache[reg] = val; | 127 | cache[reg] = val; |
142 | 128 | ||
143 | return 0; | 129 | return 0; |
@@ -200,10 +186,10 @@ static int ad1980_soc_probe(struct platform_device *pdev) | |||
200 | 186 | ||
201 | printk(KERN_INFO "AD1980 SoC Audio Codec\n"); | 187 | printk(KERN_INFO "AD1980 SoC Audio Codec\n"); |
202 | 188 | ||
203 | socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | 189 | socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
204 | if (socdev->codec == NULL) | 190 | if (socdev->card->codec == NULL) |
205 | return -ENOMEM; | 191 | return -ENOMEM; |
206 | codec = socdev->codec; | 192 | codec = socdev->card->codec; |
207 | mutex_init(&codec->mutex); | 193 | mutex_init(&codec->mutex); |
208 | 194 | ||
209 | codec->reg_cache = | 195 | codec->reg_cache = |
@@ -269,7 +255,8 @@ static int ad1980_soc_probe(struct platform_device *pdev) | |||
269 | ext_status = ac97_read(codec, AC97_EXTENDED_STATUS); | 255 | ext_status = ac97_read(codec, AC97_EXTENDED_STATUS); |
270 | ac97_write(codec, AC97_EXTENDED_STATUS, ext_status&~0x3800); | 256 | ac97_write(codec, AC97_EXTENDED_STATUS, ext_status&~0x3800); |
271 | 257 | ||
272 | ad1980_add_controls(codec); | 258 | snd_soc_add_controls(codec, ad1980_snd_ac97_controls, |
259 | ARRAY_SIZE(ad1980_snd_ac97_controls)); | ||
273 | ret = snd_soc_init_card(socdev); | 260 | ret = snd_soc_init_card(socdev); |
274 | if (ret < 0) { | 261 | if (ret < 0) { |
275 | printk(KERN_ERR "ad1980: failed to register card\n"); | 262 | printk(KERN_ERR "ad1980: failed to register card\n"); |
@@ -288,15 +275,15 @@ codec_err: | |||
288 | kfree(codec->reg_cache); | 275 | kfree(codec->reg_cache); |
289 | 276 | ||
290 | cache_err: | 277 | cache_err: |
291 | kfree(socdev->codec); | 278 | kfree(socdev->card->codec); |
292 | socdev->codec = NULL; | 279 | socdev->card->codec = NULL; |
293 | return ret; | 280 | return ret; |
294 | } | 281 | } |
295 | 282 | ||
296 | static int ad1980_soc_remove(struct platform_device *pdev) | 283 | static int ad1980_soc_remove(struct platform_device *pdev) |
297 | { | 284 | { |
298 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 285 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
299 | struct snd_soc_codec *codec = socdev->codec; | 286 | struct snd_soc_codec *codec = socdev->card->codec; |
300 | 287 | ||
301 | if (codec == NULL) | 288 | if (codec == NULL) |
302 | return 0; | 289 | return 0; |
diff --git a/sound/soc/codecs/ad73311.c b/sound/soc/codecs/ad73311.c index b09289a1e55a..e61dac5e7b8f 100644 --- a/sound/soc/codecs/ad73311.c +++ b/sound/soc/codecs/ad73311.c | |||
@@ -53,7 +53,7 @@ static int ad73311_soc_probe(struct platform_device *pdev) | |||
53 | codec->owner = THIS_MODULE; | 53 | codec->owner = THIS_MODULE; |
54 | codec->dai = &ad73311_dai; | 54 | codec->dai = &ad73311_dai; |
55 | codec->num_dai = 1; | 55 | codec->num_dai = 1; |
56 | socdev->codec = codec; | 56 | socdev->card->codec = codec; |
57 | INIT_LIST_HEAD(&codec->dapm_widgets); | 57 | INIT_LIST_HEAD(&codec->dapm_widgets); |
58 | INIT_LIST_HEAD(&codec->dapm_paths); | 58 | INIT_LIST_HEAD(&codec->dapm_paths); |
59 | 59 | ||
@@ -75,15 +75,15 @@ static int ad73311_soc_probe(struct platform_device *pdev) | |||
75 | register_err: | 75 | register_err: |
76 | snd_soc_free_pcms(socdev); | 76 | snd_soc_free_pcms(socdev); |
77 | pcm_err: | 77 | pcm_err: |
78 | kfree(socdev->codec); | 78 | kfree(socdev->card->codec); |
79 | socdev->codec = NULL; | 79 | socdev->card->codec = NULL; |
80 | return ret; | 80 | return ret; |
81 | } | 81 | } |
82 | 82 | ||
83 | static int ad73311_soc_remove(struct platform_device *pdev) | 83 | static int ad73311_soc_remove(struct platform_device *pdev) |
84 | { | 84 | { |
85 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 85 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
86 | struct snd_soc_codec *codec = socdev->codec; | 86 | struct snd_soc_codec *codec = socdev->card->codec; |
87 | 87 | ||
88 | if (codec == NULL) | 88 | if (codec == NULL) |
89 | return 0; | 89 | return 0; |
diff --git a/sound/soc/codecs/ad73311.h b/sound/soc/codecs/ad73311.h index 507ce0c30edf..569573d2d4d7 100644 --- a/sound/soc/codecs/ad73311.h +++ b/sound/soc/codecs/ad73311.h | |||
@@ -70,7 +70,7 @@ | |||
70 | #define REGD_IGS(x) (x & 0x7) | 70 | #define REGD_IGS(x) (x & 0x7) |
71 | #define REGD_RMOD (1 << 3) | 71 | #define REGD_RMOD (1 << 3) |
72 | #define REGD_OGS(x) ((x & 0x7) << 4) | 72 | #define REGD_OGS(x) ((x & 0x7) << 4) |
73 | #define REGD_MUTE (x << 7) | 73 | #define REGD_MUTE (1 << 7) |
74 | 74 | ||
75 | /* Control register E */ | 75 | /* Control register E */ |
76 | #define CTRL_REG_E (4 << 8) | 76 | #define CTRL_REG_E (4 << 8) |
diff --git a/sound/soc/codecs/ak4104.c b/sound/soc/codecs/ak4104.c new file mode 100644 index 000000000000..4d47bc4f7428 --- /dev/null +++ b/sound/soc/codecs/ak4104.c | |||
@@ -0,0 +1,365 @@ | |||
1 | /* | ||
2 | * AK4104 ALSA SoC (ASoC) driver | ||
3 | * | ||
4 | * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de> | ||
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 | #include <linux/module.h> | ||
13 | #include <sound/core.h> | ||
14 | #include <sound/soc.h> | ||
15 | #include <sound/initval.h> | ||
16 | #include <linux/spi/spi.h> | ||
17 | #include <sound/asoundef.h> | ||
18 | |||
19 | #include "ak4104.h" | ||
20 | |||
21 | /* AK4104 registers addresses */ | ||
22 | #define AK4104_REG_CONTROL1 0x00 | ||
23 | #define AK4104_REG_RESERVED 0x01 | ||
24 | #define AK4104_REG_CONTROL2 0x02 | ||
25 | #define AK4104_REG_TX 0x03 | ||
26 | #define AK4104_REG_CHN_STATUS(x) ((x) + 0x04) | ||
27 | #define AK4104_NUM_REGS 10 | ||
28 | |||
29 | #define AK4104_REG_MASK 0x1f | ||
30 | #define AK4104_READ 0xc0 | ||
31 | #define AK4104_WRITE 0xe0 | ||
32 | #define AK4104_RESERVED_VAL 0x5b | ||
33 | |||
34 | /* Bit masks for AK4104 registers */ | ||
35 | #define AK4104_CONTROL1_RSTN (1 << 0) | ||
36 | #define AK4104_CONTROL1_PW (1 << 1) | ||
37 | #define AK4104_CONTROL1_DIF0 (1 << 2) | ||
38 | #define AK4104_CONTROL1_DIF1 (1 << 3) | ||
39 | |||
40 | #define AK4104_CONTROL2_SEL0 (1 << 0) | ||
41 | #define AK4104_CONTROL2_SEL1 (1 << 1) | ||
42 | #define AK4104_CONTROL2_MODE (1 << 2) | ||
43 | |||
44 | #define AK4104_TX_TXE (1 << 0) | ||
45 | #define AK4104_TX_V (1 << 1) | ||
46 | |||
47 | #define DRV_NAME "ak4104" | ||
48 | |||
49 | struct ak4104_private { | ||
50 | struct snd_soc_codec codec; | ||
51 | u8 reg_cache[AK4104_NUM_REGS]; | ||
52 | }; | ||
53 | |||
54 | static int ak4104_fill_cache(struct snd_soc_codec *codec) | ||
55 | { | ||
56 | int i; | ||
57 | u8 *reg_cache = codec->reg_cache; | ||
58 | struct spi_device *spi = codec->control_data; | ||
59 | |||
60 | for (i = 0; i < codec->reg_cache_size; i++) { | ||
61 | int ret = spi_w8r8(spi, i | AK4104_READ); | ||
62 | if (ret < 0) { | ||
63 | dev_err(&spi->dev, "SPI write failure\n"); | ||
64 | return ret; | ||
65 | } | ||
66 | |||
67 | reg_cache[i] = ret; | ||
68 | } | ||
69 | |||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | static unsigned int ak4104_read_reg_cache(struct snd_soc_codec *codec, | ||
74 | unsigned int reg) | ||
75 | { | ||
76 | u8 *reg_cache = codec->reg_cache; | ||
77 | |||
78 | if (reg >= codec->reg_cache_size) | ||
79 | return -EINVAL; | ||
80 | |||
81 | return reg_cache[reg]; | ||
82 | } | ||
83 | |||
84 | static int ak4104_spi_write(struct snd_soc_codec *codec, unsigned int reg, | ||
85 | unsigned int value) | ||
86 | { | ||
87 | u8 *cache = codec->reg_cache; | ||
88 | struct spi_device *spi = codec->control_data; | ||
89 | |||
90 | if (reg >= codec->reg_cache_size) | ||
91 | return -EINVAL; | ||
92 | |||
93 | reg &= AK4104_REG_MASK; | ||
94 | reg |= AK4104_WRITE; | ||
95 | |||
96 | /* only write to the hardware if value has changed */ | ||
97 | if (cache[reg] != value) { | ||
98 | u8 tmp[2] = { reg, value }; | ||
99 | if (spi_write(spi, tmp, sizeof(tmp))) { | ||
100 | dev_err(&spi->dev, "SPI write failed\n"); | ||
101 | return -EIO; | ||
102 | } | ||
103 | |||
104 | cache[reg] = value; | ||
105 | } | ||
106 | |||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | static int ak4104_set_dai_fmt(struct snd_soc_dai *codec_dai, | ||
111 | unsigned int format) | ||
112 | { | ||
113 | struct snd_soc_codec *codec = codec_dai->codec; | ||
114 | int val = 0; | ||
115 | |||
116 | val = ak4104_read_reg_cache(codec, AK4104_REG_CONTROL1); | ||
117 | if (val < 0) | ||
118 | return val; | ||
119 | |||
120 | val &= ~(AK4104_CONTROL1_DIF0 | AK4104_CONTROL1_DIF1); | ||
121 | |||
122 | /* set DAI format */ | ||
123 | switch (format & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
124 | case SND_SOC_DAIFMT_RIGHT_J: | ||
125 | break; | ||
126 | case SND_SOC_DAIFMT_LEFT_J: | ||
127 | val |= AK4104_CONTROL1_DIF0; | ||
128 | break; | ||
129 | case SND_SOC_DAIFMT_I2S: | ||
130 | val |= AK4104_CONTROL1_DIF0 | AK4104_CONTROL1_DIF1; | ||
131 | break; | ||
132 | default: | ||
133 | dev_err(codec->dev, "invalid dai format\n"); | ||
134 | return -EINVAL; | ||
135 | } | ||
136 | |||
137 | /* This device can only be slave */ | ||
138 | if ((format & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) | ||
139 | return -EINVAL; | ||
140 | |||
141 | return ak4104_spi_write(codec, AK4104_REG_CONTROL1, val); | ||
142 | } | ||
143 | |||
144 | static int ak4104_hw_params(struct snd_pcm_substream *substream, | ||
145 | struct snd_pcm_hw_params *params, | ||
146 | struct snd_soc_dai *dai) | ||
147 | { | ||
148 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
149 | struct snd_soc_device *socdev = rtd->socdev; | ||
150 | struct snd_soc_codec *codec = socdev->card->codec; | ||
151 | int val = 0; | ||
152 | |||
153 | /* set the IEC958 bits: consumer mode, no copyright bit */ | ||
154 | val |= IEC958_AES0_CON_NOT_COPYRIGHT; | ||
155 | ak4104_spi_write(codec, AK4104_REG_CHN_STATUS(0), val); | ||
156 | |||
157 | val = 0; | ||
158 | |||
159 | switch (params_rate(params)) { | ||
160 | case 44100: | ||
161 | val |= IEC958_AES3_CON_FS_44100; | ||
162 | break; | ||
163 | case 48000: | ||
164 | val |= IEC958_AES3_CON_FS_48000; | ||
165 | break; | ||
166 | case 32000: | ||
167 | val |= IEC958_AES3_CON_FS_32000; | ||
168 | break; | ||
169 | default: | ||
170 | dev_err(codec->dev, "unsupported sampling rate\n"); | ||
171 | return -EINVAL; | ||
172 | } | ||
173 | |||
174 | return ak4104_spi_write(codec, AK4104_REG_CHN_STATUS(3), val); | ||
175 | } | ||
176 | |||
177 | static struct snd_soc_dai_ops ak4101_dai_ops = { | ||
178 | .hw_params = ak4104_hw_params, | ||
179 | .set_fmt = ak4104_set_dai_fmt, | ||
180 | }; | ||
181 | |||
182 | struct snd_soc_dai ak4104_dai = { | ||
183 | .name = DRV_NAME, | ||
184 | .playback = { | ||
185 | .stream_name = "Playback", | ||
186 | .channels_min = 2, | ||
187 | .channels_max = 2, | ||
188 | .rates = SNDRV_PCM_RATE_44100 | | ||
189 | SNDRV_PCM_RATE_48000 | | ||
190 | SNDRV_PCM_RATE_32000, | ||
191 | .formats = SNDRV_PCM_FMTBIT_S16_LE | | ||
192 | SNDRV_PCM_FMTBIT_S24_3LE | | ||
193 | SNDRV_PCM_FMTBIT_S24_LE | ||
194 | }, | ||
195 | .ops = &ak4101_dai_ops, | ||
196 | }; | ||
197 | |||
198 | static struct snd_soc_codec *ak4104_codec; | ||
199 | |||
200 | static int ak4104_spi_probe(struct spi_device *spi) | ||
201 | { | ||
202 | struct snd_soc_codec *codec; | ||
203 | struct ak4104_private *ak4104; | ||
204 | int ret, val; | ||
205 | |||
206 | spi->bits_per_word = 8; | ||
207 | spi->mode = SPI_MODE_0; | ||
208 | ret = spi_setup(spi); | ||
209 | if (ret < 0) | ||
210 | return ret; | ||
211 | |||
212 | ak4104 = kzalloc(sizeof(struct ak4104_private), GFP_KERNEL); | ||
213 | if (!ak4104) { | ||
214 | dev_err(&spi->dev, "could not allocate codec\n"); | ||
215 | return -ENOMEM; | ||
216 | } | ||
217 | |||
218 | codec = &ak4104->codec; | ||
219 | mutex_init(&codec->mutex); | ||
220 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
221 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
222 | |||
223 | codec->dev = &spi->dev; | ||
224 | codec->name = DRV_NAME; | ||
225 | codec->owner = THIS_MODULE; | ||
226 | codec->dai = &ak4104_dai; | ||
227 | codec->num_dai = 1; | ||
228 | codec->private_data = ak4104; | ||
229 | codec->control_data = spi; | ||
230 | codec->reg_cache = ak4104->reg_cache; | ||
231 | codec->reg_cache_size = AK4104_NUM_REGS; | ||
232 | |||
233 | /* read all regs and fill the cache */ | ||
234 | ret = ak4104_fill_cache(codec); | ||
235 | if (ret < 0) { | ||
236 | dev_err(&spi->dev, "failed to fill register cache\n"); | ||
237 | return ret; | ||
238 | } | ||
239 | |||
240 | /* read the 'reserved' register - according to the datasheet, it | ||
241 | * should contain 0x5b. Not a good way to verify the presence of | ||
242 | * the device, but there is no hardware ID register. */ | ||
243 | if (ak4104_read_reg_cache(codec, AK4104_REG_RESERVED) != | ||
244 | AK4104_RESERVED_VAL) { | ||
245 | ret = -ENODEV; | ||
246 | goto error_free_codec; | ||
247 | } | ||
248 | |||
249 | /* set power-up and non-reset bits */ | ||
250 | val = ak4104_read_reg_cache(codec, AK4104_REG_CONTROL1); | ||
251 | val |= AK4104_CONTROL1_PW | AK4104_CONTROL1_RSTN; | ||
252 | ret = ak4104_spi_write(codec, AK4104_REG_CONTROL1, val); | ||
253 | if (ret < 0) | ||
254 | goto error_free_codec; | ||
255 | |||
256 | /* enable transmitter */ | ||
257 | val = ak4104_read_reg_cache(codec, AK4104_REG_TX); | ||
258 | val |= AK4104_TX_TXE; | ||
259 | ret = ak4104_spi_write(codec, AK4104_REG_TX, val); | ||
260 | if (ret < 0) | ||
261 | goto error_free_codec; | ||
262 | |||
263 | ak4104_codec = codec; | ||
264 | ret = snd_soc_register_dai(&ak4104_dai); | ||
265 | if (ret < 0) { | ||
266 | dev_err(&spi->dev, "failed to register DAI\n"); | ||
267 | goto error_free_codec; | ||
268 | } | ||
269 | |||
270 | spi_set_drvdata(spi, ak4104); | ||
271 | dev_info(&spi->dev, "SPI device initialized\n"); | ||
272 | return 0; | ||
273 | |||
274 | error_free_codec: | ||
275 | kfree(ak4104); | ||
276 | ak4104_dai.dev = NULL; | ||
277 | return ret; | ||
278 | } | ||
279 | |||
280 | static int __devexit ak4104_spi_remove(struct spi_device *spi) | ||
281 | { | ||
282 | int ret, val; | ||
283 | struct ak4104_private *ak4104 = spi_get_drvdata(spi); | ||
284 | |||
285 | val = ak4104_read_reg_cache(&ak4104->codec, AK4104_REG_CONTROL1); | ||
286 | if (val < 0) | ||
287 | return val; | ||
288 | |||
289 | /* clear power-up and non-reset bits */ | ||
290 | val &= ~(AK4104_CONTROL1_PW | AK4104_CONTROL1_RSTN); | ||
291 | ret = ak4104_spi_write(&ak4104->codec, AK4104_REG_CONTROL1, val); | ||
292 | if (ret < 0) | ||
293 | return ret; | ||
294 | |||
295 | ak4104_codec = NULL; | ||
296 | kfree(ak4104); | ||
297 | return 0; | ||
298 | } | ||
299 | |||
300 | static int ak4104_probe(struct platform_device *pdev) | ||
301 | { | ||
302 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
303 | struct snd_soc_codec *codec = ak4104_codec; | ||
304 | int ret; | ||
305 | |||
306 | /* Connect the codec to the socdev. snd_soc_new_pcms() needs this. */ | ||
307 | socdev->card->codec = codec; | ||
308 | |||
309 | /* Register PCMs */ | ||
310 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
311 | if (ret < 0) { | ||
312 | dev_err(codec->dev, "failed to create pcms\n"); | ||
313 | return ret; | ||
314 | } | ||
315 | |||
316 | /* Register the socdev */ | ||
317 | ret = snd_soc_init_card(socdev); | ||
318 | if (ret < 0) { | ||
319 | dev_err(codec->dev, "failed to register card\n"); | ||
320 | snd_soc_free_pcms(socdev); | ||
321 | return ret; | ||
322 | } | ||
323 | |||
324 | return 0; | ||
325 | } | ||
326 | |||
327 | static int ak4104_remove(struct platform_device *pdev) | ||
328 | { | ||
329 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
330 | snd_soc_free_pcms(socdev); | ||
331 | return 0; | ||
332 | }; | ||
333 | |||
334 | struct snd_soc_codec_device soc_codec_device_ak4104 = { | ||
335 | .probe = ak4104_probe, | ||
336 | .remove = ak4104_remove | ||
337 | }; | ||
338 | EXPORT_SYMBOL_GPL(soc_codec_device_ak4104); | ||
339 | |||
340 | static struct spi_driver ak4104_spi_driver = { | ||
341 | .driver = { | ||
342 | .name = DRV_NAME, | ||
343 | .owner = THIS_MODULE, | ||
344 | }, | ||
345 | .probe = ak4104_spi_probe, | ||
346 | .remove = __devexit_p(ak4104_spi_remove), | ||
347 | }; | ||
348 | |||
349 | static int __init ak4104_init(void) | ||
350 | { | ||
351 | pr_info("Asahi Kasei AK4104 ALSA SoC Codec Driver\n"); | ||
352 | return spi_register_driver(&ak4104_spi_driver); | ||
353 | } | ||
354 | module_init(ak4104_init); | ||
355 | |||
356 | static void __exit ak4104_exit(void) | ||
357 | { | ||
358 | spi_unregister_driver(&ak4104_spi_driver); | ||
359 | } | ||
360 | module_exit(ak4104_exit); | ||
361 | |||
362 | MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); | ||
363 | MODULE_DESCRIPTION("Asahi Kasei AK4104 ALSA SoC driver"); | ||
364 | MODULE_LICENSE("GPL"); | ||
365 | |||
diff --git a/sound/soc/codecs/ak4104.h b/sound/soc/codecs/ak4104.h new file mode 100644 index 000000000000..eb88fe7e4def --- /dev/null +++ b/sound/soc/codecs/ak4104.h | |||
@@ -0,0 +1,7 @@ | |||
1 | #ifndef _AK4104_H | ||
2 | #define _AK4104_H | ||
3 | |||
4 | extern struct snd_soc_dai ak4104_dai; | ||
5 | extern struct snd_soc_codec_device soc_codec_device_ak4104; | ||
6 | |||
7 | #endif | ||
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c index 81300d8d42ca..1f63d387a2f4 100644 --- a/sound/soc/codecs/ak4535.c +++ b/sound/soc/codecs/ak4535.c | |||
@@ -155,21 +155,6 @@ static const struct snd_kcontrol_new ak4535_snd_controls[] = { | |||
155 | SOC_SINGLE("Mic Sidetone Volume", AK4535_VOL, 4, 7, 0), | 155 | SOC_SINGLE("Mic Sidetone Volume", AK4535_VOL, 4, 7, 0), |
156 | }; | 156 | }; |
157 | 157 | ||
158 | /* add non dapm controls */ | ||
159 | static int ak4535_add_controls(struct snd_soc_codec *codec) | ||
160 | { | ||
161 | int err, i; | ||
162 | |||
163 | for (i = 0; i < ARRAY_SIZE(ak4535_snd_controls); i++) { | ||
164 | err = snd_ctl_add(codec->card, | ||
165 | snd_soc_cnew(&ak4535_snd_controls[i], codec, NULL)); | ||
166 | if (err < 0) | ||
167 | return err; | ||
168 | } | ||
169 | |||
170 | return 0; | ||
171 | } | ||
172 | |||
173 | /* Mono 1 Mixer */ | 158 | /* Mono 1 Mixer */ |
174 | static const struct snd_kcontrol_new ak4535_mono1_mixer_controls[] = { | 159 | static const struct snd_kcontrol_new ak4535_mono1_mixer_controls[] = { |
175 | SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG1, 4, 1, 0), | 160 | SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG1, 4, 1, 0), |
@@ -344,7 +329,7 @@ static int ak4535_hw_params(struct snd_pcm_substream *substream, | |||
344 | { | 329 | { |
345 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 330 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
346 | struct snd_soc_device *socdev = rtd->socdev; | 331 | struct snd_soc_device *socdev = rtd->socdev; |
347 | struct snd_soc_codec *codec = socdev->codec; | 332 | struct snd_soc_codec *codec = socdev->card->codec; |
348 | struct ak4535_priv *ak4535 = codec->private_data; | 333 | struct ak4535_priv *ak4535 = codec->private_data; |
349 | u8 mode2 = ak4535_read_reg_cache(codec, AK4535_MODE2) & ~(0x3 << 5); | 334 | u8 mode2 = ak4535_read_reg_cache(codec, AK4535_MODE2) & ~(0x3 << 5); |
350 | int rate = params_rate(params), fs = 256; | 335 | int rate = params_rate(params), fs = 256; |
@@ -436,6 +421,13 @@ static int ak4535_set_bias_level(struct snd_soc_codec *codec, | |||
436 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ | 421 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ |
437 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) | 422 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) |
438 | 423 | ||
424 | static struct snd_soc_dai_ops ak4535_dai_ops = { | ||
425 | .hw_params = ak4535_hw_params, | ||
426 | .set_fmt = ak4535_set_dai_fmt, | ||
427 | .digital_mute = ak4535_mute, | ||
428 | .set_sysclk = ak4535_set_dai_sysclk, | ||
429 | }; | ||
430 | |||
439 | struct snd_soc_dai ak4535_dai = { | 431 | struct snd_soc_dai ak4535_dai = { |
440 | .name = "AK4535", | 432 | .name = "AK4535", |
441 | .playback = { | 433 | .playback = { |
@@ -450,19 +442,14 @@ struct snd_soc_dai ak4535_dai = { | |||
450 | .channels_max = 2, | 442 | .channels_max = 2, |
451 | .rates = AK4535_RATES, | 443 | .rates = AK4535_RATES, |
452 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 444 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
453 | .ops = { | 445 | .ops = &ak4535_dai_ops, |
454 | .hw_params = ak4535_hw_params, | ||
455 | .set_fmt = ak4535_set_dai_fmt, | ||
456 | .digital_mute = ak4535_mute, | ||
457 | .set_sysclk = ak4535_set_dai_sysclk, | ||
458 | }, | ||
459 | }; | 446 | }; |
460 | EXPORT_SYMBOL_GPL(ak4535_dai); | 447 | EXPORT_SYMBOL_GPL(ak4535_dai); |
461 | 448 | ||
462 | static int ak4535_suspend(struct platform_device *pdev, pm_message_t state) | 449 | static int ak4535_suspend(struct platform_device *pdev, pm_message_t state) |
463 | { | 450 | { |
464 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 451 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
465 | struct snd_soc_codec *codec = socdev->codec; | 452 | struct snd_soc_codec *codec = socdev->card->codec; |
466 | 453 | ||
467 | ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF); | 454 | ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF); |
468 | return 0; | 455 | return 0; |
@@ -471,7 +458,7 @@ static int ak4535_suspend(struct platform_device *pdev, pm_message_t state) | |||
471 | static int ak4535_resume(struct platform_device *pdev) | 458 | static int ak4535_resume(struct platform_device *pdev) |
472 | { | 459 | { |
473 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 460 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
474 | struct snd_soc_codec *codec = socdev->codec; | 461 | struct snd_soc_codec *codec = socdev->card->codec; |
475 | ak4535_sync(codec); | 462 | ak4535_sync(codec); |
476 | ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 463 | ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
477 | ak4535_set_bias_level(codec, codec->suspend_bias_level); | 464 | ak4535_set_bias_level(codec, codec->suspend_bias_level); |
@@ -484,7 +471,7 @@ static int ak4535_resume(struct platform_device *pdev) | |||
484 | */ | 471 | */ |
485 | static int ak4535_init(struct snd_soc_device *socdev) | 472 | static int ak4535_init(struct snd_soc_device *socdev) |
486 | { | 473 | { |
487 | struct snd_soc_codec *codec = socdev->codec; | 474 | struct snd_soc_codec *codec = socdev->card->codec; |
488 | int ret = 0; | 475 | int ret = 0; |
489 | 476 | ||
490 | codec->name = "AK4535"; | 477 | codec->name = "AK4535"; |
@@ -510,7 +497,8 @@ static int ak4535_init(struct snd_soc_device *socdev) | |||
510 | /* power on device */ | 497 | /* power on device */ |
511 | ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 498 | ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
512 | 499 | ||
513 | ak4535_add_controls(codec); | 500 | snd_soc_add_controls(codec, ak4535_snd_controls, |
501 | ARRAY_SIZE(ak4535_snd_controls)); | ||
514 | ak4535_add_widgets(codec); | 502 | ak4535_add_widgets(codec); |
515 | ret = snd_soc_init_card(socdev); | 503 | ret = snd_soc_init_card(socdev); |
516 | if (ret < 0) { | 504 | if (ret < 0) { |
@@ -537,7 +525,7 @@ static int ak4535_i2c_probe(struct i2c_client *i2c, | |||
537 | const struct i2c_device_id *id) | 525 | const struct i2c_device_id *id) |
538 | { | 526 | { |
539 | struct snd_soc_device *socdev = ak4535_socdev; | 527 | struct snd_soc_device *socdev = ak4535_socdev; |
540 | struct snd_soc_codec *codec = socdev->codec; | 528 | struct snd_soc_codec *codec = socdev->card->codec; |
541 | int ret; | 529 | int ret; |
542 | 530 | ||
543 | i2c_set_clientdata(i2c, codec); | 531 | i2c_set_clientdata(i2c, codec); |
@@ -636,7 +624,7 @@ static int ak4535_probe(struct platform_device *pdev) | |||
636 | } | 624 | } |
637 | 625 | ||
638 | codec->private_data = ak4535; | 626 | codec->private_data = ak4535; |
639 | socdev->codec = codec; | 627 | socdev->card->codec = codec; |
640 | mutex_init(&codec->mutex); | 628 | mutex_init(&codec->mutex); |
641 | INIT_LIST_HEAD(&codec->dapm_widgets); | 629 | INIT_LIST_HEAD(&codec->dapm_widgets); |
642 | INIT_LIST_HEAD(&codec->dapm_paths); | 630 | INIT_LIST_HEAD(&codec->dapm_paths); |
@@ -663,7 +651,7 @@ static int ak4535_probe(struct platform_device *pdev) | |||
663 | static int ak4535_remove(struct platform_device *pdev) | 651 | static int ak4535_remove(struct platform_device *pdev) |
664 | { | 652 | { |
665 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 653 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
666 | struct snd_soc_codec *codec = socdev->codec; | 654 | struct snd_soc_codec *codec = socdev->card->codec; |
667 | 655 | ||
668 | if (codec->control_data) | 656 | if (codec->control_data) |
669 | ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF); | 657 | ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF); |
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index f1aa0c34421c..7fa09a387622 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c | |||
@@ -3,27 +3,22 @@ | |||
3 | * | 3 | * |
4 | * Author: Timur Tabi <timur@freescale.com> | 4 | * Author: Timur Tabi <timur@freescale.com> |
5 | * | 5 | * |
6 | * Copyright 2007 Freescale Semiconductor, Inc. This file is licensed under | 6 | * Copyright 2007-2009 Freescale Semiconductor, Inc. This file is licensed |
7 | * the terms of the GNU General Public License version 2. This program | 7 | * under the terms of the GNU General Public License version 2. This |
8 | * is licensed "as is" without any warranty of any kind, whether express | 8 | * program is licensed "as is" without any warranty of any kind, whether |
9 | * or implied. | 9 | * express or implied. |
10 | * | 10 | * |
11 | * This is an ASoC device driver for the Cirrus Logic CS4270 codec. | 11 | * This is an ASoC device driver for the Cirrus Logic CS4270 codec. |
12 | * | 12 | * |
13 | * Current features/limitations: | 13 | * Current features/limitations: |
14 | * | 14 | * |
15 | * 1) Software mode is supported. Stand-alone mode is automatically | 15 | * - Software mode is supported. Stand-alone mode is not supported. |
16 | * selected if I2C is disabled or if a CS4270 is not found on the I2C | 16 | * - Only I2C is supported, not SPI |
17 | * bus. However, stand-alone mode is only partially implemented because | 17 | * - Support for master and slave mode |
18 | * there is no mechanism yet for this driver and the machine driver to | 18 | * - The machine driver's 'startup' function must call |
19 | * communicate the values of the M0, M1, MCLK1, and MCLK2 pins. | 19 | * cs4270_set_dai_sysclk() with the value of MCLK. |
20 | * 2) Only I2C is supported, not SPI | 20 | * - Only I2S and left-justified modes are supported |
21 | * 3) Only Master mode is supported, not Slave. | 21 | * - Power management is not supported |
22 | * 4) The machine driver's 'startup' function must call | ||
23 | * cs4270_set_dai_sysclk() with the value of MCLK. | ||
24 | * 5) Only I2S and left-justified modes are supported | ||
25 | * 6) Power management is not supported | ||
26 | * 7) The only supported control is volume and hardware mute (if enabled) | ||
27 | */ | 22 | */ |
28 | 23 | ||
29 | #include <linux/module.h> | 24 | #include <linux/module.h> |
@@ -35,18 +30,6 @@ | |||
35 | 30 | ||
36 | #include "cs4270.h" | 31 | #include "cs4270.h" |
37 | 32 | ||
38 | /* If I2C is defined, then we support software mode. However, if we're | ||
39 | not compiled as module but I2C is, then we can't use I2C calls. */ | ||
40 | #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) | ||
41 | #define USE_I2C | ||
42 | #endif | ||
43 | |||
44 | /* Private data for the CS4270 */ | ||
45 | struct cs4270_private { | ||
46 | unsigned int mclk; /* Input frequency of the MCLK pin */ | ||
47 | unsigned int mode; /* The mode (I2S or left-justified) */ | ||
48 | }; | ||
49 | |||
50 | /* | 33 | /* |
51 | * The codec isn't really big-endian or little-endian, since the I2S | 34 | * The codec isn't really big-endian or little-endian, since the I2S |
52 | * interface requires data to be sent serially with the MSbit first. | 35 | * interface requires data to be sent serially with the MSbit first. |
@@ -60,8 +43,6 @@ struct cs4270_private { | |||
60 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \ | 43 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \ |
61 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE) | 44 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE) |
62 | 45 | ||
63 | #ifdef USE_I2C | ||
64 | |||
65 | /* CS4270 registers addresses */ | 46 | /* CS4270 registers addresses */ |
66 | #define CS4270_CHIPID 0x01 /* Chip ID */ | 47 | #define CS4270_CHIPID 0x01 /* Chip ID */ |
67 | #define CS4270_PWRCTL 0x02 /* Power Control */ | 48 | #define CS4270_PWRCTL 0x02 /* Power Control */ |
@@ -121,8 +102,22 @@ struct cs4270_private { | |||
121 | #define CS4270_MUTE_DAC_A 0x01 | 102 | #define CS4270_MUTE_DAC_A 0x01 |
122 | #define CS4270_MUTE_DAC_B 0x02 | 103 | #define CS4270_MUTE_DAC_B 0x02 |
123 | 104 | ||
124 | /* | 105 | /* Private data for the CS4270 */ |
125 | * Clock Ratio Selection for Master Mode with I2C enabled | 106 | struct cs4270_private { |
107 | struct snd_soc_codec codec; | ||
108 | u8 reg_cache[CS4270_NUMREGS]; | ||
109 | unsigned int mclk; /* Input frequency of the MCLK pin */ | ||
110 | unsigned int mode; /* The mode (I2S or left-justified) */ | ||
111 | unsigned int slave_mode; | ||
112 | }; | ||
113 | |||
114 | /** | ||
115 | * struct cs4270_mode_ratios - clock ratio tables | ||
116 | * @ratio: the ratio of MCLK to the sample rate | ||
117 | * @speed_mode: the Speed Mode bits to set in the Mode Control register for | ||
118 | * this ratio | ||
119 | * @mclk: the Ratio Select bits to set in the Mode Control register for this | ||
120 | * ratio | ||
126 | * | 121 | * |
127 | * The data for this chart is taken from Table 5 of the CS4270 reference | 122 | * The data for this chart is taken from Table 5 of the CS4270 reference |
128 | * manual. | 123 | * manual. |
@@ -131,31 +126,30 @@ struct cs4270_private { | |||
131 | * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling | 126 | * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling |
132 | * rates the CS4270 currently supports. | 127 | * rates the CS4270 currently supports. |
133 | * | 128 | * |
134 | * Each element in this array corresponds to the ratios in mclk_ratios[]. | 129 | * @speed_mode is the corresponding bit pattern to be written to the |
135 | * These two arrays need to be in sync. | ||
136 | * | ||
137 | * 'speed_mode' is the corresponding bit pattern to be written to the | ||
138 | * MODE bits of the Mode Control Register | 130 | * MODE bits of the Mode Control Register |
139 | * | 131 | * |
140 | * 'mclk' is the corresponding bit pattern to be wirten to the MCLK bits of | 132 | * @mclk is the corresponding bit pattern to be wirten to the MCLK bits of |
141 | * the Mode Control Register. | 133 | * the Mode Control Register. |
142 | * | 134 | * |
143 | * In situations where a single ratio is represented by multiple speed | 135 | * In situations where a single ratio is represented by multiple speed |
144 | * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick | 136 | * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick |
145 | * double-speed instead of quad-speed. However, the CS4270 errata states | 137 | * double-speed instead of quad-speed. However, the CS4270 errata states |
146 | * that Divide-By-1.5 can cause failures, so we avoid that mode where | 138 | * that divide-By-1.5 can cause failures, so we avoid that mode where |
147 | * possible. | 139 | * possible. |
148 | * | 140 | * |
149 | * ERRATA: There is an errata for the CS4270 where divide-by-1.5 does not | 141 | * Errata: There is an errata for the CS4270 where divide-by-1.5 does not |
150 | * work if VD = 3.3V. If this effects you, select the | 142 | * work if Vd is 3.3V. If this effects you, select the |
151 | * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will | 143 | * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will |
152 | * never select any sample rates that require divide-by-1.5. | 144 | * never select any sample rates that require divide-by-1.5. |
153 | */ | 145 | */ |
154 | static struct { | 146 | struct cs4270_mode_ratios { |
155 | unsigned int ratio; | 147 | unsigned int ratio; |
156 | u8 speed_mode; | 148 | u8 speed_mode; |
157 | u8 mclk; | 149 | u8 mclk; |
158 | } cs4270_mode_ratios[] = { | 150 | }; |
151 | |||
152 | static struct cs4270_mode_ratios cs4270_mode_ratios[] = { | ||
159 | {64, CS4270_MODE_4X, CS4270_MODE_DIV1}, | 153 | {64, CS4270_MODE_4X, CS4270_MODE_DIV1}, |
160 | #ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA | 154 | #ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA |
161 | {96, CS4270_MODE_4X, CS4270_MODE_DIV15}, | 155 | {96, CS4270_MODE_4X, CS4270_MODE_DIV15}, |
@@ -172,34 +166,27 @@ static struct { | |||
172 | /* The number of MCLK/LRCK ratios supported by the CS4270 */ | 166 | /* The number of MCLK/LRCK ratios supported by the CS4270 */ |
173 | #define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios) | 167 | #define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios) |
174 | 168 | ||
175 | /* | 169 | /** |
176 | * Determine the CS4270 samples rates. | 170 | * cs4270_set_dai_sysclk - determine the CS4270 samples rates. |
171 | * @codec_dai: the codec DAI | ||
172 | * @clk_id: the clock ID (ignored) | ||
173 | * @freq: the MCLK input frequency | ||
174 | * @dir: the clock direction (ignored) | ||
177 | * | 175 | * |
178 | * 'freq' is the input frequency to MCLK. The other parameters are ignored. | 176 | * This function is used to tell the codec driver what the input MCLK |
177 | * frequency is. | ||
179 | * | 178 | * |
180 | * The value of MCLK is used to determine which sample rates are supported | 179 | * The value of MCLK is used to determine which sample rates are supported |
181 | * by the CS4270. The ratio of MCLK / Fs must be equal to one of nine | 180 | * by the CS4270. The ratio of MCLK / Fs must be equal to one of nine |
182 | * support values: 64, 96, 128, 192, 256, 384, 512, 768, and 1024. | 181 | * supported values - 64, 96, 128, 192, 256, 384, 512, 768, and 1024. |
183 | * | 182 | * |
184 | * This function calculates the nine ratios and determines which ones match | 183 | * This function calculates the nine ratios and determines which ones match |
185 | * a standard sample rate. If there's a match, then it is added to the list | 184 | * a standard sample rate. If there's a match, then it is added to the list |
186 | * of support sample rates. | 185 | * of supported sample rates. |
187 | * | 186 | * |
188 | * This function must be called by the machine driver's 'startup' function, | 187 | * This function must be called by the machine driver's 'startup' function, |
189 | * otherwise the list of supported sample rates will not be available in | 188 | * otherwise the list of supported sample rates will not be available in |
190 | * time for ALSA. | 189 | * time for ALSA. |
191 | * | ||
192 | * Note that in stand-alone mode, the sample rate is determined by input | ||
193 | * pins M0, M1, MDIV1, and MDIV2. Also in stand-alone mode, divide-by-3 | ||
194 | * is not a programmable option. However, divide-by-3 is not an available | ||
195 | * option in stand-alone mode. This cases two problems: a ratio of 768 is | ||
196 | * not available (it requires divide-by-3) and B) ratios 192 and 384 can | ||
197 | * only be selected with divide-by-1.5, but there is an errate that make | ||
198 | * this selection difficult. | ||
199 | * | ||
200 | * In addition, there is no mechanism for communicating with the machine | ||
201 | * driver what the input settings can be. This would need to be implemented | ||
202 | * for stand-alone mode to work. | ||
203 | */ | 190 | */ |
204 | static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai, | 191 | static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
205 | int clk_id, unsigned int freq, int dir) | 192 | int clk_id, unsigned int freq, int dir) |
@@ -225,7 +212,7 @@ static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
225 | rates &= ~SNDRV_PCM_RATE_KNOT; | 212 | rates &= ~SNDRV_PCM_RATE_KNOT; |
226 | 213 | ||
227 | if (!rates) { | 214 | if (!rates) { |
228 | printk(KERN_ERR "cs4270: could not find a valid sample rate\n"); | 215 | dev_err(codec->dev, "could not find a valid sample rate\n"); |
229 | return -EINVAL; | 216 | return -EINVAL; |
230 | } | 217 | } |
231 | 218 | ||
@@ -240,8 +227,10 @@ static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
240 | return 0; | 227 | return 0; |
241 | } | 228 | } |
242 | 229 | ||
243 | /* | 230 | /** |
244 | * Configure the codec for the selected audio format | 231 | * cs4270_set_dai_fmt - configure the codec for the selected audio format |
232 | * @codec_dai: the codec DAI | ||
233 | * @format: a SND_SOC_DAIFMT_x value indicating the data format | ||
245 | * | 234 | * |
246 | * This function takes a bitmask of SND_SOC_DAIFMT_x bits and programs the | 235 | * This function takes a bitmask of SND_SOC_DAIFMT_x bits and programs the |
247 | * codec accordingly. | 236 | * codec accordingly. |
@@ -258,32 +247,43 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
258 | struct cs4270_private *cs4270 = codec->private_data; | 247 | struct cs4270_private *cs4270 = codec->private_data; |
259 | int ret = 0; | 248 | int ret = 0; |
260 | 249 | ||
250 | /* set DAI format */ | ||
261 | switch (format & SND_SOC_DAIFMT_FORMAT_MASK) { | 251 | switch (format & SND_SOC_DAIFMT_FORMAT_MASK) { |
262 | case SND_SOC_DAIFMT_I2S: | 252 | case SND_SOC_DAIFMT_I2S: |
263 | case SND_SOC_DAIFMT_LEFT_J: | 253 | case SND_SOC_DAIFMT_LEFT_J: |
264 | cs4270->mode = format & SND_SOC_DAIFMT_FORMAT_MASK; | 254 | cs4270->mode = format & SND_SOC_DAIFMT_FORMAT_MASK; |
265 | break; | 255 | break; |
266 | default: | 256 | default: |
267 | printk(KERN_ERR "cs4270: invalid DAI format\n"); | 257 | dev_err(codec->dev, "invalid dai format\n"); |
258 | ret = -EINVAL; | ||
259 | } | ||
260 | |||
261 | /* set master/slave audio interface */ | ||
262 | switch (format & SND_SOC_DAIFMT_MASTER_MASK) { | ||
263 | case SND_SOC_DAIFMT_CBS_CFS: | ||
264 | cs4270->slave_mode = 1; | ||
265 | break; | ||
266 | case SND_SOC_DAIFMT_CBM_CFM: | ||
267 | cs4270->slave_mode = 0; | ||
268 | break; | ||
269 | default: | ||
270 | /* all other modes are unsupported by the hardware */ | ||
268 | ret = -EINVAL; | 271 | ret = -EINVAL; |
269 | } | 272 | } |
270 | 273 | ||
271 | return ret; | 274 | return ret; |
272 | } | 275 | } |
273 | 276 | ||
274 | /* | 277 | /** |
275 | * A list of addresses on which this CS4270 could use. I2C addresses are | 278 | * cs4270_fill_cache - pre-fill the CS4270 register cache. |
276 | * 7 bits. For the CS4270, the upper four bits are always 1001, and the | 279 | * @codec: the codec for this CS4270 |
277 | * lower three bits are determined via the AD2, AD1, and AD0 pins | 280 | * |
278 | * (respectively). | 281 | * This function fills in the CS4270 register cache by reading the register |
279 | */ | 282 | * values from the hardware. |
280 | static const unsigned short normal_i2c[] = { | 283 | * |
281 | 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, I2C_CLIENT_END | 284 | * This CS4270 registers are cached to avoid excessive I2C I/O operations. |
282 | }; | 285 | * After the initial read to pre-fill the cache, the CS4270 never updates |
283 | I2C_CLIENT_INSMOD; | 286 | * the register values, so we won't have a cache coherency problem. |
284 | |||
285 | /* | ||
286 | * Pre-fill the CS4270 register cache. | ||
287 | * | 287 | * |
288 | * We use the auto-increment feature of the CS4270 to read all registers in | 288 | * We use the auto-increment feature of the CS4270 to read all registers in |
289 | * one shot. | 289 | * one shot. |
@@ -298,7 +298,7 @@ static int cs4270_fill_cache(struct snd_soc_codec *codec) | |||
298 | CS4270_FIRSTREG | 0x80, CS4270_NUMREGS, cache); | 298 | CS4270_FIRSTREG | 0x80, CS4270_NUMREGS, cache); |
299 | 299 | ||
300 | if (length != CS4270_NUMREGS) { | 300 | if (length != CS4270_NUMREGS) { |
301 | printk(KERN_ERR "cs4270: I2C read failure, addr=0x%x\n", | 301 | dev_err(codec->dev, "i2c read failure, addr=0x%x\n", |
302 | i2c_client->addr); | 302 | i2c_client->addr); |
303 | return -EIO; | 303 | return -EIO; |
304 | } | 304 | } |
@@ -306,12 +306,17 @@ static int cs4270_fill_cache(struct snd_soc_codec *codec) | |||
306 | return 0; | 306 | return 0; |
307 | } | 307 | } |
308 | 308 | ||
309 | /* | 309 | /** |
310 | * Read from the CS4270 register cache. | 310 | * cs4270_read_reg_cache - read from the CS4270 register cache. |
311 | * @codec: the codec for this CS4270 | ||
312 | * @reg: the register to read | ||
313 | * | ||
314 | * This function returns the value for a given register. It reads only from | ||
315 | * the register cache, not the hardware itself. | ||
311 | * | 316 | * |
312 | * This CS4270 registers are cached to avoid excessive I2C I/O operations. | 317 | * This CS4270 registers are cached to avoid excessive I2C I/O operations. |
313 | * After the initial read to pre-fill the cache, the CS4270 never updates | 318 | * After the initial read to pre-fill the cache, the CS4270 never updates |
314 | * the register values, so we won't have a cache coherncy problem. | 319 | * the register values, so we won't have a cache coherency problem. |
315 | */ | 320 | */ |
316 | static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec, | 321 | static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec, |
317 | unsigned int reg) | 322 | unsigned int reg) |
@@ -324,8 +329,11 @@ static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec, | |||
324 | return cache[reg - CS4270_FIRSTREG]; | 329 | return cache[reg - CS4270_FIRSTREG]; |
325 | } | 330 | } |
326 | 331 | ||
327 | /* | 332 | /** |
328 | * Write to a CS4270 register via the I2C bus. | 333 | * cs4270_i2c_write - write to a CS4270 register via the I2C bus. |
334 | * @codec: the codec for this CS4270 | ||
335 | * @reg: the register to write | ||
336 | * @value: the value to write to the register | ||
329 | * | 337 | * |
330 | * This function writes the given value to the given CS4270 register, and | 338 | * This function writes the given value to the given CS4270 register, and |
331 | * also updates the register cache. | 339 | * also updates the register cache. |
@@ -346,7 +354,7 @@ static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg, | |||
346 | if (cache[reg - CS4270_FIRSTREG] != value) { | 354 | if (cache[reg - CS4270_FIRSTREG] != value) { |
347 | struct i2c_client *client = codec->control_data; | 355 | struct i2c_client *client = codec->control_data; |
348 | if (i2c_smbus_write_byte_data(client, reg, value)) { | 356 | if (i2c_smbus_write_byte_data(client, reg, value)) { |
349 | printk(KERN_ERR "cs4270: I2C write failed\n"); | 357 | dev_err(codec->dev, "i2c write failed\n"); |
350 | return -EIO; | 358 | return -EIO; |
351 | } | 359 | } |
352 | 360 | ||
@@ -357,11 +365,17 @@ static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg, | |||
357 | return 0; | 365 | return 0; |
358 | } | 366 | } |
359 | 367 | ||
360 | /* | 368 | /** |
361 | * Program the CS4270 with the given hardware parameters. | 369 | * cs4270_hw_params - program the CS4270 with the given hardware parameters. |
370 | * @substream: the audio stream | ||
371 | * @params: the hardware parameters to set | ||
372 | * @dai: the SOC DAI (ignored) | ||
373 | * | ||
374 | * This function programs the hardware with the values provided. | ||
375 | * Specifically, the sample rate and the data format. | ||
362 | * | 376 | * |
363 | * The .ops functions are used to provide board-specific data, like | 377 | * The .ops functions are used to provide board-specific data, like input |
364 | * input frequencies, to this driver. This function takes that information, | 378 | * frequencies, to this driver. This function takes that information, |
365 | * combines it with the hardware parameters provided, and programs the | 379 | * combines it with the hardware parameters provided, and programs the |
366 | * hardware accordingly. | 380 | * hardware accordingly. |
367 | */ | 381 | */ |
@@ -371,7 +385,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, | |||
371 | { | 385 | { |
372 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 386 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
373 | struct snd_soc_device *socdev = rtd->socdev; | 387 | struct snd_soc_device *socdev = rtd->socdev; |
374 | struct snd_soc_codec *codec = socdev->codec; | 388 | struct snd_soc_codec *codec = socdev->card->codec; |
375 | struct cs4270_private *cs4270 = codec->private_data; | 389 | struct cs4270_private *cs4270 = codec->private_data; |
376 | int ret; | 390 | int ret; |
377 | unsigned int i; | 391 | unsigned int i; |
@@ -391,33 +405,28 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, | |||
391 | 405 | ||
392 | if (i == NUM_MCLK_RATIOS) { | 406 | if (i == NUM_MCLK_RATIOS) { |
393 | /* We did not find a matching ratio */ | 407 | /* We did not find a matching ratio */ |
394 | printk(KERN_ERR "cs4270: could not find matching ratio\n"); | 408 | dev_err(codec->dev, "could not find matching ratio\n"); |
395 | return -EINVAL; | 409 | return -EINVAL; |
396 | } | 410 | } |
397 | 411 | ||
398 | /* Freeze and power-down the codec */ | 412 | /* Set the sample rate */ |
399 | |||
400 | ret = snd_soc_write(codec, CS4270_PWRCTL, CS4270_PWRCTL_FREEZE | | ||
401 | CS4270_PWRCTL_PDN_ADC | CS4270_PWRCTL_PDN_DAC | | ||
402 | CS4270_PWRCTL_PDN); | ||
403 | if (ret < 0) { | ||
404 | printk(KERN_ERR "cs4270: I2C write failed\n"); | ||
405 | return ret; | ||
406 | } | ||
407 | |||
408 | /* Program the mode control register */ | ||
409 | 413 | ||
410 | reg = snd_soc_read(codec, CS4270_MODE); | 414 | reg = snd_soc_read(codec, CS4270_MODE); |
411 | reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK); | 415 | reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK); |
412 | reg |= cs4270_mode_ratios[i].speed_mode | cs4270_mode_ratios[i].mclk; | 416 | reg |= cs4270_mode_ratios[i].mclk; |
417 | |||
418 | if (cs4270->slave_mode) | ||
419 | reg |= CS4270_MODE_SLAVE; | ||
420 | else | ||
421 | reg |= cs4270_mode_ratios[i].speed_mode; | ||
413 | 422 | ||
414 | ret = snd_soc_write(codec, CS4270_MODE, reg); | 423 | ret = snd_soc_write(codec, CS4270_MODE, reg); |
415 | if (ret < 0) { | 424 | if (ret < 0) { |
416 | printk(KERN_ERR "cs4270: I2C write failed\n"); | 425 | dev_err(codec->dev, "i2c write failed\n"); |
417 | return ret; | 426 | return ret; |
418 | } | 427 | } |
419 | 428 | ||
420 | /* Program the format register */ | 429 | /* Set the DAI format */ |
421 | 430 | ||
422 | reg = snd_soc_read(codec, CS4270_FORMAT); | 431 | reg = snd_soc_read(codec, CS4270_FORMAT); |
423 | reg &= ~(CS4270_FORMAT_DAC_MASK | CS4270_FORMAT_ADC_MASK); | 432 | reg &= ~(CS4270_FORMAT_DAC_MASK | CS4270_FORMAT_ADC_MASK); |
@@ -430,55 +439,23 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, | |||
430 | reg |= CS4270_FORMAT_DAC_LJ | CS4270_FORMAT_ADC_LJ; | 439 | reg |= CS4270_FORMAT_DAC_LJ | CS4270_FORMAT_ADC_LJ; |
431 | break; | 440 | break; |
432 | default: | 441 | default: |
433 | printk(KERN_ERR "cs4270: unknown format\n"); | 442 | dev_err(codec->dev, "unknown dai format\n"); |
434 | return -EINVAL; | 443 | return -EINVAL; |
435 | } | 444 | } |
436 | 445 | ||
437 | ret = snd_soc_write(codec, CS4270_FORMAT, reg); | 446 | ret = snd_soc_write(codec, CS4270_FORMAT, reg); |
438 | if (ret < 0) { | 447 | if (ret < 0) { |
439 | printk(KERN_ERR "cs4270: I2C write failed\n"); | 448 | dev_err(codec->dev, "i2c write failed\n"); |
440 | return ret; | ||
441 | } | ||
442 | |||
443 | /* Disable auto-mute. This feature appears to be buggy, because in | ||
444 | some situations, auto-mute will not deactivate when it should. */ | ||
445 | |||
446 | reg = snd_soc_read(codec, CS4270_MUTE); | ||
447 | reg &= ~CS4270_MUTE_AUTO; | ||
448 | ret = snd_soc_write(codec, CS4270_MUTE, reg); | ||
449 | if (ret < 0) { | ||
450 | printk(KERN_ERR "cs4270: I2C write failed\n"); | ||
451 | return ret; | ||
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 | |||
467 | /* Thaw and power-up the codec */ | ||
468 | |||
469 | ret = snd_soc_write(codec, CS4270_PWRCTL, 0); | ||
470 | if (ret < 0) { | ||
471 | printk(KERN_ERR "cs4270: I2C write failed\n"); | ||
472 | return ret; | 449 | return ret; |
473 | } | 450 | } |
474 | 451 | ||
475 | return ret; | 452 | return ret; |
476 | } | 453 | } |
477 | 454 | ||
478 | #ifdef CONFIG_SND_SOC_CS4270_HWMUTE | 455 | /** |
479 | 456 | * cs4270_mute - enable/disable the CS4270 external mute | |
480 | /* | 457 | * @dai: the SOC DAI |
481 | * Set the CS4270 external mute | 458 | * @mute: 0 = disable mute, 1 = enable mute |
482 | * | 459 | * |
483 | * This function toggles the mute bits in the MUTE register. The CS4270's | 460 | * This function toggles the mute bits in the MUTE register. The CS4270's |
484 | * mute capability is intended for external muting circuitry, so if the | 461 | * mute capability is intended for external muting circuitry, so if the |
@@ -493,276 +470,306 @@ static int cs4270_mute(struct snd_soc_dai *dai, int mute) | |||
493 | reg6 = snd_soc_read(codec, CS4270_MUTE); | 470 | reg6 = snd_soc_read(codec, CS4270_MUTE); |
494 | 471 | ||
495 | if (mute) | 472 | if (mute) |
496 | reg6 |= CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B | | 473 | reg6 |= CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B; |
497 | CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B; | ||
498 | else | 474 | else |
499 | reg6 &= ~(CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B | | 475 | reg6 &= ~(CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B); |
500 | CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B); | ||
501 | 476 | ||
502 | return snd_soc_write(codec, CS4270_MUTE, reg6); | 477 | return snd_soc_write(codec, CS4270_MUTE, reg6); |
503 | } | 478 | } |
504 | 479 | ||
505 | #endif | ||
506 | |||
507 | static int cs4270_i2c_probe(struct i2c_client *, const struct i2c_device_id *); | ||
508 | |||
509 | /* A list of non-DAPM controls that the CS4270 supports */ | 480 | /* A list of non-DAPM controls that the CS4270 supports */ |
510 | static const struct snd_kcontrol_new cs4270_snd_controls[] = { | 481 | static const struct snd_kcontrol_new cs4270_snd_controls[] = { |
511 | SOC_DOUBLE_R("Master Playback Volume", | 482 | SOC_DOUBLE_R("Master Playback Volume", |
512 | CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1) | 483 | CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1), |
513 | }; | 484 | SOC_SINGLE("Digital Sidetone Switch", CS4270_FORMAT, 5, 1, 0), |
514 | 485 | SOC_SINGLE("Soft Ramp Switch", CS4270_TRANS, 6, 1, 0), | |
515 | static const struct i2c_device_id cs4270_id[] = { | 486 | SOC_SINGLE("Zero Cross Switch", CS4270_TRANS, 5, 1, 0), |
516 | {"cs4270", 0}, | 487 | SOC_SINGLE("Popguard Switch", CS4270_MODE, 0, 1, 1), |
517 | {} | 488 | SOC_SINGLE("Auto-Mute Switch", CS4270_MUTE, 5, 1, 0), |
518 | }; | 489 | SOC_DOUBLE("Master Capture Switch", CS4270_MUTE, 3, 4, 1, 0) |
519 | MODULE_DEVICE_TABLE(i2c, cs4270_id); | ||
520 | |||
521 | static struct i2c_driver cs4270_i2c_driver = { | ||
522 | .driver = { | ||
523 | .name = "CS4270 I2C", | ||
524 | .owner = THIS_MODULE, | ||
525 | }, | ||
526 | .id_table = cs4270_id, | ||
527 | .probe = cs4270_i2c_probe, | ||
528 | }; | 490 | }; |
529 | 491 | ||
530 | /* | 492 | /* |
531 | * Global variable to store socdev for i2c probe function. | 493 | * cs4270_codec - global variable to store codec for the ASoC probe function |
532 | * | 494 | * |
533 | * If struct i2c_driver had a private_data field, we wouldn't need to use | 495 | * If struct i2c_driver had a private_data field, we wouldn't need to use |
534 | * cs4270_socdec. This is the only way to pass the socdev structure to | 496 | * cs4270_codec. This is the only way to pass the codec structure from |
535 | * cs4270_i2c_probe(). | 497 | * cs4270_i2c_probe() to cs4270_probe(). Unfortunately, there is no good |
536 | * | 498 | * way to synchronize these two functions. cs4270_i2c_probe() can be called |
537 | * The real solution to cs4270_socdev is to create a mechanism | 499 | * multiple times before cs4270_probe() is called even once. So for now, we |
538 | * that maps I2C addresses to snd_soc_device structures. Perhaps the | 500 | * also only allow cs4270_i2c_probe() to be run once. That means that we do |
539 | * creation of the snd_soc_device object should be moved out of | 501 | * not support more than one cs4270 device in the system, at least for now. |
540 | * cs4270_probe() and into cs4270_i2c_probe(), but that would make this | ||
541 | * driver dependent on I2C. The CS4270 supports "stand-alone" mode, whereby | ||
542 | * the chip is *not* connected to the I2C bus, but is instead configured via | ||
543 | * input pins. | ||
544 | */ | 502 | */ |
545 | static struct snd_soc_device *cs4270_socdev; | 503 | static struct snd_soc_codec *cs4270_codec; |
546 | 504 | ||
547 | /* | 505 | static struct snd_soc_dai_ops cs4270_dai_ops = { |
548 | * Initialize the I2C interface of the CS4270 | 506 | .hw_params = cs4270_hw_params, |
549 | * | 507 | .set_sysclk = cs4270_set_dai_sysclk, |
550 | * This function is called for whenever the I2C subsystem finds a device | 508 | .set_fmt = cs4270_set_dai_fmt, |
551 | * at a particular address. | 509 | .digital_mute = cs4270_mute, |
510 | }; | ||
511 | |||
512 | struct snd_soc_dai cs4270_dai = { | ||
513 | .name = "cs4270", | ||
514 | .playback = { | ||
515 | .stream_name = "Playback", | ||
516 | .channels_min = 1, | ||
517 | .channels_max = 2, | ||
518 | .rates = 0, | ||
519 | .formats = CS4270_FORMATS, | ||
520 | }, | ||
521 | .capture = { | ||
522 | .stream_name = "Capture", | ||
523 | .channels_min = 1, | ||
524 | .channels_max = 2, | ||
525 | .rates = 0, | ||
526 | .formats = CS4270_FORMATS, | ||
527 | }, | ||
528 | .ops = &cs4270_dai_ops, | ||
529 | }; | ||
530 | EXPORT_SYMBOL_GPL(cs4270_dai); | ||
531 | |||
532 | /** | ||
533 | * cs4270_probe - ASoC probe function | ||
534 | * @pdev: platform device | ||
552 | * | 535 | * |
553 | * Note: snd_soc_new_pcms() must be called before this function can be called, | 536 | * This function is called when ASoC has all the pieces it needs to |
554 | * because of snd_ctl_add(). | 537 | * instantiate a sound driver. |
555 | */ | 538 | */ |
556 | static int cs4270_i2c_probe(struct i2c_client *i2c_client, | 539 | static int cs4270_probe(struct platform_device *pdev) |
557 | const struct i2c_device_id *id) | ||
558 | { | 540 | { |
559 | struct snd_soc_device *socdev = cs4270_socdev; | 541 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
560 | struct snd_soc_codec *codec = socdev->codec; | 542 | struct snd_soc_codec *codec = cs4270_codec; |
561 | int i; | 543 | int ret; |
562 | int ret = 0; | ||
563 | |||
564 | /* Probing all possible addresses has one drawback: if there are | ||
565 | multiple CS4270s on the bus, then you cannot specify which | ||
566 | socdev is matched with which CS4270. For now, we just reject | ||
567 | this I2C device if the socdev already has one attached. */ | ||
568 | if (codec->control_data) | ||
569 | return -ENODEV; | ||
570 | |||
571 | /* Note: codec_dai->codec is NULL here */ | ||
572 | |||
573 | codec->reg_cache = kzalloc(CS4270_NUMREGS, GFP_KERNEL); | ||
574 | if (!codec->reg_cache) { | ||
575 | printk(KERN_ERR "cs4270: could not allocate register cache\n"); | ||
576 | ret = -ENOMEM; | ||
577 | goto error; | ||
578 | } | ||
579 | 544 | ||
580 | /* Verify that we have a CS4270 */ | 545 | /* Connect the codec to the socdev. snd_soc_new_pcms() needs this. */ |
546 | socdev->card->codec = codec; | ||
581 | 547 | ||
582 | ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID); | 548 | /* Register PCMs */ |
549 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
583 | if (ret < 0) { | 550 | if (ret < 0) { |
584 | printk(KERN_ERR "cs4270: failed to read I2C\n"); | 551 | dev_err(codec->dev, "failed to create pcms\n"); |
585 | goto error; | 552 | return ret; |
586 | } | ||
587 | /* The top four bits of the chip ID should be 1100. */ | ||
588 | if ((ret & 0xF0) != 0xC0) { | ||
589 | /* The device at this address is not a CS4270 codec */ | ||
590 | ret = -ENODEV; | ||
591 | goto error; | ||
592 | } | 553 | } |
593 | 554 | ||
594 | printk(KERN_INFO "cs4270: found device at I2C address %X\n", | 555 | /* Add the non-DAPM controls */ |
595 | i2c_client->addr); | 556 | ret = snd_soc_add_controls(codec, cs4270_snd_controls, |
596 | printk(KERN_INFO "cs4270: hardware revision %X\n", ret & 0xF); | 557 | ARRAY_SIZE(cs4270_snd_controls)); |
597 | |||
598 | codec->control_data = i2c_client; | ||
599 | codec->read = cs4270_read_reg_cache; | ||
600 | codec->write = cs4270_i2c_write; | ||
601 | codec->reg_cache_size = CS4270_NUMREGS; | ||
602 | |||
603 | /* The I2C interface is set up, so pre-fill our register cache */ | ||
604 | |||
605 | ret = cs4270_fill_cache(codec); | ||
606 | if (ret < 0) { | 558 | if (ret < 0) { |
607 | printk(KERN_ERR "cs4270: failed to fill register cache\n"); | 559 | dev_err(codec->dev, "failed to add controls\n"); |
608 | goto error; | 560 | goto error_free_pcms; |
609 | } | 561 | } |
610 | 562 | ||
611 | /* Add the non-DAPM controls */ | 563 | /* And finally, register the socdev */ |
612 | 564 | ret = snd_soc_init_card(socdev); | |
613 | for (i = 0; i < ARRAY_SIZE(cs4270_snd_controls); i++) { | 565 | if (ret < 0) { |
614 | struct snd_kcontrol *kctrl = | 566 | dev_err(codec->dev, "failed to register card\n"); |
615 | snd_soc_cnew(&cs4270_snd_controls[i], codec, NULL); | 567 | goto error_free_pcms; |
616 | |||
617 | ret = snd_ctl_add(codec->card, kctrl); | ||
618 | if (ret < 0) | ||
619 | goto error; | ||
620 | } | 568 | } |
621 | 569 | ||
622 | i2c_set_clientdata(i2c_client, codec); | ||
623 | |||
624 | return 0; | 570 | return 0; |
625 | 571 | ||
626 | error: | 572 | error_free_pcms: |
627 | codec->control_data = NULL; | 573 | snd_soc_free_pcms(socdev); |
628 | |||
629 | kfree(codec->reg_cache); | ||
630 | codec->reg_cache = NULL; | ||
631 | codec->reg_cache_size = 0; | ||
632 | 574 | ||
633 | return ret; | 575 | return ret; |
634 | } | 576 | } |
635 | 577 | ||
636 | #endif /* USE_I2C*/ | 578 | /** |
579 | * cs4270_remove - ASoC remove function | ||
580 | * @pdev: platform device | ||
581 | * | ||
582 | * This function is the counterpart to cs4270_probe(). | ||
583 | */ | ||
584 | static int cs4270_remove(struct platform_device *pdev) | ||
585 | { | ||
586 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
637 | 587 | ||
638 | struct snd_soc_dai cs4270_dai = { | 588 | snd_soc_free_pcms(socdev); |
639 | .name = "CS4270", | 589 | |
640 | .playback = { | 590 | return 0; |
641 | .stream_name = "Playback", | ||
642 | .channels_min = 1, | ||
643 | .channels_max = 2, | ||
644 | .rates = 0, | ||
645 | .formats = CS4270_FORMATS, | ||
646 | }, | ||
647 | .capture = { | ||
648 | .stream_name = "Capture", | ||
649 | .channels_min = 1, | ||
650 | .channels_max = 2, | ||
651 | .rates = 0, | ||
652 | .formats = CS4270_FORMATS, | ||
653 | }, | ||
654 | }; | 591 | }; |
655 | EXPORT_SYMBOL_GPL(cs4270_dai); | ||
656 | 592 | ||
657 | /* | 593 | /** |
658 | * ASoC probe function | 594 | * cs4270_i2c_probe - initialize the I2C interface of the CS4270 |
595 | * @i2c_client: the I2C client object | ||
596 | * @id: the I2C device ID (ignored) | ||
659 | * | 597 | * |
660 | * This function is called when the machine driver calls | 598 | * This function is called whenever the I2C subsystem finds a device that |
661 | * platform_device_add(). | 599 | * matches the device ID given via a prior call to i2c_add_driver(). |
662 | */ | 600 | */ |
663 | static int cs4270_probe(struct platform_device *pdev) | 601 | static int cs4270_i2c_probe(struct i2c_client *i2c_client, |
602 | const struct i2c_device_id *id) | ||
664 | { | 603 | { |
665 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
666 | struct snd_soc_codec *codec; | 604 | struct snd_soc_codec *codec; |
667 | int ret = 0; | 605 | struct cs4270_private *cs4270; |
606 | unsigned int reg; | ||
607 | int ret; | ||
668 | 608 | ||
669 | printk(KERN_INFO "CS4270 ALSA SoC Codec\n"); | 609 | /* For now, we only support one cs4270 device in the system. See the |
610 | * comment for cs4270_codec. | ||
611 | */ | ||
612 | if (cs4270_codec) { | ||
613 | dev_err(&i2c_client->dev, "ignoring CS4270 at addr %X\n", | ||
614 | i2c_client->addr); | ||
615 | dev_err(&i2c_client->dev, "only one per board allowed\n"); | ||
616 | /* Should we return something other than ENODEV here? */ | ||
617 | return -ENODEV; | ||
618 | } | ||
619 | |||
620 | /* Verify that we have a CS4270 */ | ||
621 | |||
622 | ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID); | ||
623 | if (ret < 0) { | ||
624 | dev_err(&i2c_client->dev, "failed to read i2c at addr %X\n", | ||
625 | i2c_client->addr); | ||
626 | return ret; | ||
627 | } | ||
628 | /* The top four bits of the chip ID should be 1100. */ | ||
629 | if ((ret & 0xF0) != 0xC0) { | ||
630 | dev_err(&i2c_client->dev, "device at addr %X is not a CS4270\n", | ||
631 | i2c_client->addr); | ||
632 | return -ENODEV; | ||
633 | } | ||
634 | |||
635 | dev_info(&i2c_client->dev, "found device at i2c address %X\n", | ||
636 | i2c_client->addr); | ||
637 | dev_info(&i2c_client->dev, "hardware revision %X\n", ret & 0xF); | ||
670 | 638 | ||
671 | /* Allocate enough space for the snd_soc_codec structure | 639 | /* Allocate enough space for the snd_soc_codec structure |
672 | and our private data together. */ | 640 | and our private data together. */ |
673 | codec = kzalloc(ALIGN(sizeof(struct snd_soc_codec), 4) + | 641 | cs4270 = kzalloc(sizeof(struct cs4270_private), GFP_KERNEL); |
674 | sizeof(struct cs4270_private), GFP_KERNEL); | 642 | if (!cs4270) { |
675 | if (!codec) { | 643 | dev_err(&i2c_client->dev, "could not allocate codec\n"); |
676 | printk(KERN_ERR "cs4270: Could not allocate codec structure\n"); | ||
677 | return -ENOMEM; | 644 | return -ENOMEM; |
678 | } | 645 | } |
646 | codec = &cs4270->codec; | ||
679 | 647 | ||
680 | mutex_init(&codec->mutex); | 648 | mutex_init(&codec->mutex); |
681 | INIT_LIST_HEAD(&codec->dapm_widgets); | 649 | INIT_LIST_HEAD(&codec->dapm_widgets); |
682 | INIT_LIST_HEAD(&codec->dapm_paths); | 650 | INIT_LIST_HEAD(&codec->dapm_paths); |
683 | 651 | ||
652 | codec->dev = &i2c_client->dev; | ||
684 | codec->name = "CS4270"; | 653 | codec->name = "CS4270"; |
685 | codec->owner = THIS_MODULE; | 654 | codec->owner = THIS_MODULE; |
686 | codec->dai = &cs4270_dai; | 655 | codec->dai = &cs4270_dai; |
687 | codec->num_dai = 1; | 656 | codec->num_dai = 1; |
688 | codec->private_data = (void *) codec + | 657 | codec->private_data = cs4270; |
689 | ALIGN(sizeof(struct snd_soc_codec), 4); | 658 | codec->control_data = i2c_client; |
690 | 659 | codec->read = cs4270_read_reg_cache; | |
691 | socdev->codec = codec; | 660 | codec->write = cs4270_i2c_write; |
661 | codec->reg_cache = cs4270->reg_cache; | ||
662 | codec->reg_cache_size = CS4270_NUMREGS; | ||
692 | 663 | ||
693 | /* Register PCMs */ | 664 | /* The I2C interface is set up, so pre-fill our register cache */ |
694 | 665 | ||
695 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | 666 | ret = cs4270_fill_cache(codec); |
696 | if (ret < 0) { | 667 | if (ret < 0) { |
697 | printk(KERN_ERR "cs4270: failed to create PCMs\n"); | 668 | dev_err(&i2c_client->dev, "failed to fill register cache\n"); |
698 | goto error_free_codec; | 669 | goto error_free_codec; |
699 | } | 670 | } |
700 | 671 | ||
701 | #ifdef USE_I2C | 672 | /* Disable auto-mute. This feature appears to be buggy. In some |
702 | cs4270_socdev = socdev; | 673 | * situations, auto-mute will not deactivate when it should, so we want |
674 | * this feature disabled by default. An application (e.g. alsactl) can | ||
675 | * re-enabled it by using the controls. | ||
676 | */ | ||
703 | 677 | ||
704 | ret = i2c_add_driver(&cs4270_i2c_driver); | 678 | reg = cs4270_read_reg_cache(codec, CS4270_MUTE); |
705 | if (ret) { | 679 | reg &= ~CS4270_MUTE_AUTO; |
706 | printk(KERN_ERR "cs4270: failed to attach driver"); | 680 | ret = cs4270_i2c_write(codec, CS4270_MUTE, reg); |
707 | goto error_free_pcms; | 681 | if (ret < 0) { |
682 | dev_err(&i2c_client->dev, "i2c write failed\n"); | ||
683 | return ret; | ||
708 | } | 684 | } |
709 | 685 | ||
710 | /* Did we find a CS4270 on the I2C bus? */ | 686 | /* Disable automatic volume control. The hardware enables, and it |
711 | if (codec->control_data) { | 687 | * causes volume change commands to be delayed, sometimes until after |
712 | /* Initialize codec ops */ | 688 | * playback has started. An application (e.g. alsactl) can |
713 | cs4270_dai.ops.hw_params = cs4270_hw_params; | 689 | * re-enabled it by using the controls. |
714 | cs4270_dai.ops.set_sysclk = cs4270_set_dai_sysclk; | 690 | */ |
715 | cs4270_dai.ops.set_fmt = cs4270_set_dai_fmt; | ||
716 | #ifdef CONFIG_SND_SOC_CS4270_HWMUTE | ||
717 | cs4270_dai.ops.digital_mute = cs4270_mute; | ||
718 | #endif | ||
719 | } else | ||
720 | printk(KERN_INFO "cs4270: no I2C device found, " | ||
721 | "using stand-alone mode\n"); | ||
722 | #else | ||
723 | printk(KERN_INFO "cs4270: I2C disabled, using stand-alone mode\n"); | ||
724 | #endif | ||
725 | 691 | ||
726 | ret = snd_soc_init_card(socdev); | 692 | reg = cs4270_read_reg_cache(codec, CS4270_TRANS); |
693 | reg &= ~(CS4270_TRANS_SOFT | CS4270_TRANS_ZERO); | ||
694 | ret = cs4270_i2c_write(codec, CS4270_TRANS, reg); | ||
727 | if (ret < 0) { | 695 | if (ret < 0) { |
728 | printk(KERN_ERR "cs4270: failed to register card\n"); | 696 | dev_err(&i2c_client->dev, "i2c write failed\n"); |
729 | goto error_del_driver; | 697 | return ret; |
730 | } | 698 | } |
731 | 699 | ||
732 | return 0; | 700 | /* Initialize the DAI. Normally, we'd prefer to have a kmalloc'd DAI |
701 | * structure for each CS4270 device, but the machine driver needs to | ||
702 | * have a pointer to the DAI structure, so for now it must be a global | ||
703 | * variable. | ||
704 | */ | ||
705 | cs4270_dai.dev = &i2c_client->dev; | ||
733 | 706 | ||
734 | error_del_driver: | 707 | /* Register the DAI. If all the other ASoC driver have already |
735 | #ifdef USE_I2C | 708 | * registered, then this will call our probe function, so |
736 | i2c_del_driver(&cs4270_i2c_driver); | 709 | * cs4270_codec needs to be ready. |
710 | */ | ||
711 | cs4270_codec = codec; | ||
712 | ret = snd_soc_register_dai(&cs4270_dai); | ||
713 | if (ret < 0) { | ||
714 | dev_err(&i2c_client->dev, "failed to register DAIe\n"); | ||
715 | goto error_free_codec; | ||
716 | } | ||
737 | 717 | ||
738 | error_free_pcms: | 718 | i2c_set_clientdata(i2c_client, cs4270); |
739 | #endif | 719 | |
740 | snd_soc_free_pcms(socdev); | 720 | return 0; |
741 | 721 | ||
742 | error_free_codec: | 722 | error_free_codec: |
743 | kfree(socdev->codec); | 723 | kfree(cs4270); |
744 | socdev->codec = NULL; | 724 | cs4270_codec = NULL; |
725 | cs4270_dai.dev = NULL; | ||
745 | 726 | ||
746 | return ret; | 727 | return ret; |
747 | } | 728 | } |
748 | 729 | ||
749 | static int cs4270_remove(struct platform_device *pdev) | 730 | /** |
731 | * cs4270_i2c_remove - remove an I2C device | ||
732 | * @i2c_client: the I2C client object | ||
733 | * | ||
734 | * This function is the counterpart to cs4270_i2c_probe(). | ||
735 | */ | ||
736 | static int cs4270_i2c_remove(struct i2c_client *i2c_client) | ||
750 | { | 737 | { |
751 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 738 | struct cs4270_private *cs4270 = i2c_get_clientdata(i2c_client); |
752 | |||
753 | snd_soc_free_pcms(socdev); | ||
754 | |||
755 | #ifdef USE_I2C | ||
756 | i2c_del_driver(&cs4270_i2c_driver); | ||
757 | #endif | ||
758 | 739 | ||
759 | kfree(socdev->codec); | 740 | kfree(cs4270); |
760 | socdev->codec = NULL; | 741 | cs4270_codec = NULL; |
742 | cs4270_dai.dev = NULL; | ||
761 | 743 | ||
762 | return 0; | 744 | return 0; |
763 | } | 745 | } |
764 | 746 | ||
765 | /* | 747 | /* |
748 | * cs4270_id - I2C device IDs supported by this driver | ||
749 | */ | ||
750 | static struct i2c_device_id cs4270_id[] = { | ||
751 | {"cs4270", 0}, | ||
752 | {} | ||
753 | }; | ||
754 | MODULE_DEVICE_TABLE(i2c, cs4270_id); | ||
755 | |||
756 | /* | ||
757 | * cs4270_i2c_driver - I2C device identification | ||
758 | * | ||
759 | * This structure tells the I2C subsystem how to identify and support a | ||
760 | * given I2C device type. | ||
761 | */ | ||
762 | static struct i2c_driver cs4270_i2c_driver = { | ||
763 | .driver = { | ||
764 | .name = "cs4270", | ||
765 | .owner = THIS_MODULE, | ||
766 | }, | ||
767 | .id_table = cs4270_id, | ||
768 | .probe = cs4270_i2c_probe, | ||
769 | .remove = cs4270_i2c_remove, | ||
770 | }; | ||
771 | |||
772 | /* | ||
766 | * ASoC codec device structure | 773 | * ASoC codec device structure |
767 | * | 774 | * |
768 | * Assign this variable to the codec_dev field of the machine driver's | 775 | * Assign this variable to the codec_dev field of the machine driver's |
@@ -776,13 +783,15 @@ EXPORT_SYMBOL_GPL(soc_codec_device_cs4270); | |||
776 | 783 | ||
777 | static int __init cs4270_init(void) | 784 | static int __init cs4270_init(void) |
778 | { | 785 | { |
779 | return snd_soc_register_dai(&cs4270_dai); | 786 | pr_info("Cirrus Logic CS4270 ALSA SoC Codec Driver\n"); |
787 | |||
788 | return i2c_add_driver(&cs4270_i2c_driver); | ||
780 | } | 789 | } |
781 | module_init(cs4270_init); | 790 | module_init(cs4270_init); |
782 | 791 | ||
783 | static void __exit cs4270_exit(void) | 792 | static void __exit cs4270_exit(void) |
784 | { | 793 | { |
785 | snd_soc_unregister_dai(&cs4270_dai); | 794 | i2c_del_driver(&cs4270_i2c_driver); |
786 | } | 795 | } |
787 | module_exit(cs4270_exit); | 796 | module_exit(cs4270_exit); |
788 | 797 | ||
diff --git a/sound/soc/codecs/pcm3008.c b/sound/soc/codecs/pcm3008.c index 9a3e67e5319c..5cda9e6b5a74 100644 --- a/sound/soc/codecs/pcm3008.c +++ b/sound/soc/codecs/pcm3008.c | |||
@@ -67,11 +67,11 @@ static int pcm3008_soc_probe(struct platform_device *pdev) | |||
67 | 67 | ||
68 | printk(KERN_INFO "PCM3008 SoC Audio Codec %s\n", PCM3008_VERSION); | 68 | printk(KERN_INFO "PCM3008 SoC Audio Codec %s\n", PCM3008_VERSION); |
69 | 69 | ||
70 | socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | 70 | socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
71 | if (!socdev->codec) | 71 | if (!socdev->card->codec) |
72 | return -ENOMEM; | 72 | return -ENOMEM; |
73 | 73 | ||
74 | codec = socdev->codec; | 74 | codec = socdev->card->codec; |
75 | mutex_init(&codec->mutex); | 75 | mutex_init(&codec->mutex); |
76 | 76 | ||
77 | codec->name = "PCM3008"; | 77 | codec->name = "PCM3008"; |
@@ -139,7 +139,7 @@ gpio_err: | |||
139 | card_err: | 139 | card_err: |
140 | snd_soc_free_pcms(socdev); | 140 | snd_soc_free_pcms(socdev); |
141 | pcm_err: | 141 | pcm_err: |
142 | kfree(socdev->codec); | 142 | kfree(socdev->card->codec); |
143 | 143 | ||
144 | return ret; | 144 | return ret; |
145 | } | 145 | } |
@@ -147,7 +147,7 @@ pcm_err: | |||
147 | static int pcm3008_soc_remove(struct platform_device *pdev) | 147 | static int pcm3008_soc_remove(struct platform_device *pdev) |
148 | { | 148 | { |
149 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 149 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
150 | struct snd_soc_codec *codec = socdev->codec; | 150 | struct snd_soc_codec *codec = socdev->card->codec; |
151 | struct pcm3008_setup_data *setup = socdev->codec_data; | 151 | struct pcm3008_setup_data *setup = socdev->codec_data; |
152 | 152 | ||
153 | if (!codec) | 153 | if (!codec) |
@@ -155,7 +155,7 @@ static int pcm3008_soc_remove(struct platform_device *pdev) | |||
155 | 155 | ||
156 | pcm3008_gpio_free(setup); | 156 | pcm3008_gpio_free(setup); |
157 | snd_soc_free_pcms(socdev); | 157 | snd_soc_free_pcms(socdev); |
158 | kfree(socdev->codec); | 158 | kfree(socdev->card->codec); |
159 | 159 | ||
160 | return 0; | 160 | return 0; |
161 | } | 161 | } |
diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c index cac373616768..87f606c76822 100644 --- a/sound/soc/codecs/ssm2602.c +++ b/sound/soc/codecs/ssm2602.c | |||
@@ -151,21 +151,6 @@ SOC_ENUM("Capture Source", ssm2602_enum[0]), | |||
151 | SOC_ENUM("Playback De-emphasis", ssm2602_enum[1]), | 151 | SOC_ENUM("Playback De-emphasis", ssm2602_enum[1]), |
152 | }; | 152 | }; |
153 | 153 | ||
154 | /* add non dapm controls */ | ||
155 | static int ssm2602_add_controls(struct snd_soc_codec *codec) | ||
156 | { | ||
157 | int err, i; | ||
158 | |||
159 | for (i = 0; i < ARRAY_SIZE(ssm2602_snd_controls); i++) { | ||
160 | err = snd_ctl_add(codec->card, | ||
161 | snd_soc_cnew(&ssm2602_snd_controls[i], codec, NULL)); | ||
162 | if (err < 0) | ||
163 | return err; | ||
164 | } | ||
165 | |||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | /* Output Mixer */ | 154 | /* Output Mixer */ |
170 | static const struct snd_kcontrol_new ssm2602_output_mixer_controls[] = { | 155 | static const struct snd_kcontrol_new ssm2602_output_mixer_controls[] = { |
171 | SOC_DAPM_SINGLE("Line Bypass Switch", SSM2602_APANA, 3, 1, 0), | 156 | SOC_DAPM_SINGLE("Line Bypass Switch", SSM2602_APANA, 3, 1, 0), |
@@ -291,7 +276,7 @@ static int ssm2602_hw_params(struct snd_pcm_substream *substream, | |||
291 | u16 srate; | 276 | u16 srate; |
292 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 277 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
293 | struct snd_soc_device *socdev = rtd->socdev; | 278 | struct snd_soc_device *socdev = rtd->socdev; |
294 | struct snd_soc_codec *codec = socdev->codec; | 279 | struct snd_soc_codec *codec = socdev->card->codec; |
295 | struct ssm2602_priv *ssm2602 = codec->private_data; | 280 | struct ssm2602_priv *ssm2602 = codec->private_data; |
296 | struct i2c_client *i2c = codec->control_data; | 281 | struct i2c_client *i2c = codec->control_data; |
297 | u16 iface = ssm2602_read_reg_cache(codec, SSM2602_IFACE) & 0xfff3; | 282 | u16 iface = ssm2602_read_reg_cache(codec, SSM2602_IFACE) & 0xfff3; |
@@ -336,7 +321,7 @@ static int ssm2602_startup(struct snd_pcm_substream *substream, | |||
336 | { | 321 | { |
337 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 322 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
338 | struct snd_soc_device *socdev = rtd->socdev; | 323 | struct snd_soc_device *socdev = rtd->socdev; |
339 | struct snd_soc_codec *codec = socdev->codec; | 324 | struct snd_soc_codec *codec = socdev->card->codec; |
340 | struct ssm2602_priv *ssm2602 = codec->private_data; | 325 | struct ssm2602_priv *ssm2602 = codec->private_data; |
341 | struct i2c_client *i2c = codec->control_data; | 326 | struct i2c_client *i2c = codec->control_data; |
342 | struct snd_pcm_runtime *master_runtime; | 327 | struct snd_pcm_runtime *master_runtime; |
@@ -373,7 +358,7 @@ static int ssm2602_pcm_prepare(struct snd_pcm_substream *substream, | |||
373 | { | 358 | { |
374 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 359 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
375 | struct snd_soc_device *socdev = rtd->socdev; | 360 | struct snd_soc_device *socdev = rtd->socdev; |
376 | struct snd_soc_codec *codec = socdev->codec; | 361 | struct snd_soc_codec *codec = socdev->card->codec; |
377 | /* set active */ | 362 | /* set active */ |
378 | ssm2602_write(codec, SSM2602_ACTIVE, ACTIVE_ACTIVATE_CODEC); | 363 | ssm2602_write(codec, SSM2602_ACTIVE, ACTIVE_ACTIVATE_CODEC); |
379 | 364 | ||
@@ -385,7 +370,7 @@ static void ssm2602_shutdown(struct snd_pcm_substream *substream, | |||
385 | { | 370 | { |
386 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 371 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
387 | struct snd_soc_device *socdev = rtd->socdev; | 372 | struct snd_soc_device *socdev = rtd->socdev; |
388 | struct snd_soc_codec *codec = socdev->codec; | 373 | struct snd_soc_codec *codec = socdev->card->codec; |
389 | struct ssm2602_priv *ssm2602 = codec->private_data; | 374 | struct ssm2602_priv *ssm2602 = codec->private_data; |
390 | /* deactivate */ | 375 | /* deactivate */ |
391 | if (!codec->active) | 376 | if (!codec->active) |
@@ -521,6 +506,16 @@ static int ssm2602_set_bias_level(struct snd_soc_codec *codec, | |||
521 | #define SSM2602_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | 506 | #define SSM2602_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
522 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) | 507 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
523 | 508 | ||
509 | static struct snd_soc_dai_ops ssm2602_dai_ops = { | ||
510 | .startup = ssm2602_startup, | ||
511 | .prepare = ssm2602_pcm_prepare, | ||
512 | .hw_params = ssm2602_hw_params, | ||
513 | .shutdown = ssm2602_shutdown, | ||
514 | .digital_mute = ssm2602_mute, | ||
515 | .set_sysclk = ssm2602_set_dai_sysclk, | ||
516 | .set_fmt = ssm2602_set_dai_fmt, | ||
517 | }; | ||
518 | |||
524 | struct snd_soc_dai ssm2602_dai = { | 519 | struct snd_soc_dai ssm2602_dai = { |
525 | .name = "SSM2602", | 520 | .name = "SSM2602", |
526 | .playback = { | 521 | .playback = { |
@@ -535,22 +530,14 @@ struct snd_soc_dai ssm2602_dai = { | |||
535 | .channels_max = 2, | 530 | .channels_max = 2, |
536 | .rates = SSM2602_RATES, | 531 | .rates = SSM2602_RATES, |
537 | .formats = SSM2602_FORMATS,}, | 532 | .formats = SSM2602_FORMATS,}, |
538 | .ops = { | 533 | .ops = &ssm2602_dai_ops, |
539 | .startup = ssm2602_startup, | ||
540 | .prepare = ssm2602_pcm_prepare, | ||
541 | .hw_params = ssm2602_hw_params, | ||
542 | .shutdown = ssm2602_shutdown, | ||
543 | .digital_mute = ssm2602_mute, | ||
544 | .set_sysclk = ssm2602_set_dai_sysclk, | ||
545 | .set_fmt = ssm2602_set_dai_fmt, | ||
546 | } | ||
547 | }; | 534 | }; |
548 | EXPORT_SYMBOL_GPL(ssm2602_dai); | 535 | EXPORT_SYMBOL_GPL(ssm2602_dai); |
549 | 536 | ||
550 | static int ssm2602_suspend(struct platform_device *pdev, pm_message_t state) | 537 | static int ssm2602_suspend(struct platform_device *pdev, pm_message_t state) |
551 | { | 538 | { |
552 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 539 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
553 | struct snd_soc_codec *codec = socdev->codec; | 540 | struct snd_soc_codec *codec = socdev->card->codec; |
554 | 541 | ||
555 | ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF); | 542 | ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF); |
556 | return 0; | 543 | return 0; |
@@ -559,7 +546,7 @@ static int ssm2602_suspend(struct platform_device *pdev, pm_message_t state) | |||
559 | static int ssm2602_resume(struct platform_device *pdev) | 546 | static int ssm2602_resume(struct platform_device *pdev) |
560 | { | 547 | { |
561 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 548 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
562 | struct snd_soc_codec *codec = socdev->codec; | 549 | struct snd_soc_codec *codec = socdev->card->codec; |
563 | int i; | 550 | int i; |
564 | u8 data[2]; | 551 | u8 data[2]; |
565 | u16 *cache = codec->reg_cache; | 552 | u16 *cache = codec->reg_cache; |
@@ -581,7 +568,7 @@ static int ssm2602_resume(struct platform_device *pdev) | |||
581 | */ | 568 | */ |
582 | static int ssm2602_init(struct snd_soc_device *socdev) | 569 | static int ssm2602_init(struct snd_soc_device *socdev) |
583 | { | 570 | { |
584 | struct snd_soc_codec *codec = socdev->codec; | 571 | struct snd_soc_codec *codec = socdev->card->codec; |
585 | int reg, ret = 0; | 572 | int reg, ret = 0; |
586 | 573 | ||
587 | codec->name = "SSM2602"; | 574 | codec->name = "SSM2602"; |
@@ -622,7 +609,8 @@ static int ssm2602_init(struct snd_soc_device *socdev) | |||
622 | APANA_ENABLE_MIC_BOOST); | 609 | APANA_ENABLE_MIC_BOOST); |
623 | ssm2602_write(codec, SSM2602_PWR, 0); | 610 | ssm2602_write(codec, SSM2602_PWR, 0); |
624 | 611 | ||
625 | ssm2602_add_controls(codec); | 612 | snd_soc_add_controls(codec, ssm2602_snd_controls, |
613 | ARRAY_SIZE(ssm2602_snd_controls)); | ||
626 | ssm2602_add_widgets(codec); | 614 | ssm2602_add_widgets(codec); |
627 | ret = snd_soc_init_card(socdev); | 615 | ret = snd_soc_init_card(socdev); |
628 | if (ret < 0) { | 616 | if (ret < 0) { |
@@ -653,7 +641,7 @@ static int ssm2602_i2c_probe(struct i2c_client *i2c, | |||
653 | const struct i2c_device_id *id) | 641 | const struct i2c_device_id *id) |
654 | { | 642 | { |
655 | struct snd_soc_device *socdev = ssm2602_socdev; | 643 | struct snd_soc_device *socdev = ssm2602_socdev; |
656 | struct snd_soc_codec *codec = socdev->codec; | 644 | struct snd_soc_codec *codec = socdev->card->codec; |
657 | int ret; | 645 | int ret; |
658 | 646 | ||
659 | i2c_set_clientdata(i2c, codec); | 647 | i2c_set_clientdata(i2c, codec); |
@@ -747,7 +735,7 @@ static int ssm2602_probe(struct platform_device *pdev) | |||
747 | } | 735 | } |
748 | 736 | ||
749 | codec->private_data = ssm2602; | 737 | codec->private_data = ssm2602; |
750 | socdev->codec = codec; | 738 | socdev->card->codec = codec; |
751 | mutex_init(&codec->mutex); | 739 | mutex_init(&codec->mutex); |
752 | INIT_LIST_HEAD(&codec->dapm_widgets); | 740 | INIT_LIST_HEAD(&codec->dapm_widgets); |
753 | INIT_LIST_HEAD(&codec->dapm_paths); | 741 | INIT_LIST_HEAD(&codec->dapm_paths); |
@@ -768,7 +756,7 @@ static int ssm2602_probe(struct platform_device *pdev) | |||
768 | static int ssm2602_remove(struct platform_device *pdev) | 756 | static int ssm2602_remove(struct platform_device *pdev) |
769 | { | 757 | { |
770 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 758 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
771 | struct snd_soc_codec *codec = socdev->codec; | 759 | struct snd_soc_codec *codec = socdev->card->codec; |
772 | 760 | ||
773 | if (codec->control_data) | 761 | if (codec->control_data) |
774 | ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF); | 762 | ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF); |
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c index cfdea007c4cb..c3f4afb5d017 100644 --- a/sound/soc/codecs/tlv320aic23.c +++ b/sound/soc/codecs/tlv320aic23.c | |||
@@ -183,24 +183,6 @@ static const struct snd_kcontrol_new tlv320aic23_snd_controls[] = { | |||
183 | SOC_ENUM("Playback De-emphasis", tlv320aic23_deemph), | 183 | SOC_ENUM("Playback De-emphasis", tlv320aic23_deemph), |
184 | }; | 184 | }; |
185 | 185 | ||
186 | /* add non dapm controls */ | ||
187 | static int tlv320aic23_add_controls(struct snd_soc_codec *codec) | ||
188 | { | ||
189 | |||
190 | int err, i; | ||
191 | |||
192 | for (i = 0; i < ARRAY_SIZE(tlv320aic23_snd_controls); i++) { | ||
193 | err = snd_ctl_add(codec->card, | ||
194 | snd_soc_cnew(&tlv320aic23_snd_controls[i], | ||
195 | codec, NULL)); | ||
196 | if (err < 0) | ||
197 | return err; | ||
198 | } | ||
199 | |||
200 | return 0; | ||
201 | |||
202 | } | ||
203 | |||
204 | /* PGA Mixer controls for Line and Mic switch */ | 186 | /* PGA Mixer controls for Line and Mic switch */ |
205 | static const struct snd_kcontrol_new tlv320aic23_output_mixer_controls[] = { | 187 | static const struct snd_kcontrol_new tlv320aic23_output_mixer_controls[] = { |
206 | SOC_DAPM_SINGLE("Line Bypass Switch", TLV320AIC23_ANLG, 3, 1, 0), | 188 | SOC_DAPM_SINGLE("Line Bypass Switch", TLV320AIC23_ANLG, 3, 1, 0), |
@@ -423,7 +405,7 @@ static int tlv320aic23_hw_params(struct snd_pcm_substream *substream, | |||
423 | { | 405 | { |
424 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 406 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
425 | struct snd_soc_device *socdev = rtd->socdev; | 407 | struct snd_soc_device *socdev = rtd->socdev; |
426 | struct snd_soc_codec *codec = socdev->codec; | 408 | struct snd_soc_codec *codec = socdev->card->codec; |
427 | u16 iface_reg; | 409 | u16 iface_reg; |
428 | int ret; | 410 | int ret; |
429 | struct aic23 *aic23 = container_of(codec, struct aic23, codec); | 411 | struct aic23 *aic23 = container_of(codec, struct aic23, codec); |
@@ -471,7 +453,7 @@ static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream, | |||
471 | { | 453 | { |
472 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 454 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
473 | struct snd_soc_device *socdev = rtd->socdev; | 455 | struct snd_soc_device *socdev = rtd->socdev; |
474 | struct snd_soc_codec *codec = socdev->codec; | 456 | struct snd_soc_codec *codec = socdev->card->codec; |
475 | 457 | ||
476 | /* set active */ | 458 | /* set active */ |
477 | tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0001); | 459 | tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0001); |
@@ -484,7 +466,7 @@ static void tlv320aic23_shutdown(struct snd_pcm_substream *substream, | |||
484 | { | 466 | { |
485 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 467 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
486 | struct snd_soc_device *socdev = rtd->socdev; | 468 | struct snd_soc_device *socdev = rtd->socdev; |
487 | struct snd_soc_codec *codec = socdev->codec; | 469 | struct snd_soc_codec *codec = socdev->card->codec; |
488 | struct aic23 *aic23 = container_of(codec, struct aic23, codec); | 470 | struct aic23 *aic23 = container_of(codec, struct aic23, codec); |
489 | 471 | ||
490 | /* deactivate */ | 472 | /* deactivate */ |
@@ -598,6 +580,15 @@ static int tlv320aic23_set_bias_level(struct snd_soc_codec *codec, | |||
598 | #define AIC23_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ | 580 | #define AIC23_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ |
599 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) | 581 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) |
600 | 582 | ||
583 | static struct snd_soc_dai_ops tlv320aic23_dai_ops = { | ||
584 | .prepare = tlv320aic23_pcm_prepare, | ||
585 | .hw_params = tlv320aic23_hw_params, | ||
586 | .shutdown = tlv320aic23_shutdown, | ||
587 | .digital_mute = tlv320aic23_mute, | ||
588 | .set_fmt = tlv320aic23_set_dai_fmt, | ||
589 | .set_sysclk = tlv320aic23_set_dai_sysclk, | ||
590 | }; | ||
591 | |||
601 | struct snd_soc_dai tlv320aic23_dai = { | 592 | struct snd_soc_dai tlv320aic23_dai = { |
602 | .name = "tlv320aic23", | 593 | .name = "tlv320aic23", |
603 | .playback = { | 594 | .playback = { |
@@ -612,14 +603,7 @@ struct snd_soc_dai tlv320aic23_dai = { | |||
612 | .channels_max = 2, | 603 | .channels_max = 2, |
613 | .rates = AIC23_RATES, | 604 | .rates = AIC23_RATES, |
614 | .formats = AIC23_FORMATS,}, | 605 | .formats = AIC23_FORMATS,}, |
615 | .ops = { | 606 | .ops = &tlv320aic23_dai_ops, |
616 | .prepare = tlv320aic23_pcm_prepare, | ||
617 | .hw_params = tlv320aic23_hw_params, | ||
618 | .shutdown = tlv320aic23_shutdown, | ||
619 | .digital_mute = tlv320aic23_mute, | ||
620 | .set_fmt = tlv320aic23_set_dai_fmt, | ||
621 | .set_sysclk = tlv320aic23_set_dai_sysclk, | ||
622 | } | ||
623 | }; | 607 | }; |
624 | EXPORT_SYMBOL_GPL(tlv320aic23_dai); | 608 | EXPORT_SYMBOL_GPL(tlv320aic23_dai); |
625 | 609 | ||
@@ -627,7 +611,7 @@ static int tlv320aic23_suspend(struct platform_device *pdev, | |||
627 | pm_message_t state) | 611 | pm_message_t state) |
628 | { | 612 | { |
629 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 613 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
630 | struct snd_soc_codec *codec = socdev->codec; | 614 | struct snd_soc_codec *codec = socdev->card->codec; |
631 | 615 | ||
632 | tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0); | 616 | tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0); |
633 | tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_OFF); | 617 | tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_OFF); |
@@ -638,7 +622,7 @@ static int tlv320aic23_suspend(struct platform_device *pdev, | |||
638 | static int tlv320aic23_resume(struct platform_device *pdev) | 622 | static int tlv320aic23_resume(struct platform_device *pdev) |
639 | { | 623 | { |
640 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 624 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
641 | struct snd_soc_codec *codec = socdev->codec; | 625 | struct snd_soc_codec *codec = socdev->card->codec; |
642 | int i; | 626 | int i; |
643 | u16 reg; | 627 | u16 reg; |
644 | 628 | ||
@@ -660,7 +644,7 @@ static int tlv320aic23_resume(struct platform_device *pdev) | |||
660 | */ | 644 | */ |
661 | static int tlv320aic23_init(struct snd_soc_device *socdev) | 645 | static int tlv320aic23_init(struct snd_soc_device *socdev) |
662 | { | 646 | { |
663 | struct snd_soc_codec *codec = socdev->codec; | 647 | struct snd_soc_codec *codec = socdev->card->codec; |
664 | int ret = 0; | 648 | int ret = 0; |
665 | u16 reg; | 649 | u16 reg; |
666 | 650 | ||
@@ -718,7 +702,8 @@ static int tlv320aic23_init(struct snd_soc_device *socdev) | |||
718 | 702 | ||
719 | tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x1); | 703 | tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x1); |
720 | 704 | ||
721 | tlv320aic23_add_controls(codec); | 705 | snd_soc_add_controls(codec, tlv320aic23_snd_controls, |
706 | ARRAY_SIZE(tlv320aic23_snd_controls)); | ||
722 | tlv320aic23_add_widgets(codec); | 707 | tlv320aic23_add_widgets(codec); |
723 | ret = snd_soc_init_card(socdev); | 708 | ret = snd_soc_init_card(socdev); |
724 | if (ret < 0) { | 709 | if (ret < 0) { |
@@ -746,7 +731,7 @@ static int tlv320aic23_codec_probe(struct i2c_client *i2c, | |||
746 | const struct i2c_device_id *i2c_id) | 731 | const struct i2c_device_id *i2c_id) |
747 | { | 732 | { |
748 | struct snd_soc_device *socdev = tlv320aic23_socdev; | 733 | struct snd_soc_device *socdev = tlv320aic23_socdev; |
749 | struct snd_soc_codec *codec = socdev->codec; | 734 | struct snd_soc_codec *codec = socdev->card->codec; |
750 | int ret; | 735 | int ret; |
751 | 736 | ||
752 | if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 737 | if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
@@ -804,7 +789,7 @@ static int tlv320aic23_probe(struct platform_device *pdev) | |||
804 | if (aic23 == NULL) | 789 | if (aic23 == NULL) |
805 | return -ENOMEM; | 790 | return -ENOMEM; |
806 | codec = &aic23->codec; | 791 | codec = &aic23->codec; |
807 | socdev->codec = codec; | 792 | socdev->card->codec = codec; |
808 | mutex_init(&codec->mutex); | 793 | mutex_init(&codec->mutex); |
809 | INIT_LIST_HEAD(&codec->dapm_widgets); | 794 | INIT_LIST_HEAD(&codec->dapm_widgets); |
810 | INIT_LIST_HEAD(&codec->dapm_paths); | 795 | INIT_LIST_HEAD(&codec->dapm_paths); |
@@ -823,7 +808,7 @@ static int tlv320aic23_probe(struct platform_device *pdev) | |||
823 | static int tlv320aic23_remove(struct platform_device *pdev) | 808 | static int tlv320aic23_remove(struct platform_device *pdev) |
824 | { | 809 | { |
825 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 810 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
826 | struct snd_soc_codec *codec = socdev->codec; | 811 | struct snd_soc_codec *codec = socdev->card->codec; |
827 | struct aic23 *aic23 = container_of(codec, struct aic23, codec); | 812 | struct aic23 *aic23 = container_of(codec, struct aic23, codec); |
828 | 813 | ||
829 | if (codec->control_data) | 814 | if (codec->control_data) |
diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c index 29f2f1a017fd..3387d9e736ea 100644 --- a/sound/soc/codecs/tlv320aic26.c +++ b/sound/soc/codecs/tlv320aic26.c | |||
@@ -130,7 +130,7 @@ static int aic26_hw_params(struct snd_pcm_substream *substream, | |||
130 | { | 130 | { |
131 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 131 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
132 | struct snd_soc_device *socdev = rtd->socdev; | 132 | struct snd_soc_device *socdev = rtd->socdev; |
133 | struct snd_soc_codec *codec = socdev->codec; | 133 | struct snd_soc_codec *codec = socdev->card->codec; |
134 | struct aic26 *aic26 = codec->private_data; | 134 | struct aic26 *aic26 = codec->private_data; |
135 | int fsref, divisor, wlen, pval, jval, dval, qval; | 135 | int fsref, divisor, wlen, pval, jval, dval, qval; |
136 | u16 reg; | 136 | u16 reg; |
@@ -270,6 +270,13 @@ static int aic26_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) | |||
270 | #define AIC26_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_BE |\ | 270 | #define AIC26_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_BE |\ |
271 | SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S32_BE) | 271 | SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S32_BE) |
272 | 272 | ||
273 | static struct snd_soc_dai_ops aic26_dai_ops = { | ||
274 | .hw_params = aic26_hw_params, | ||
275 | .digital_mute = aic26_mute, | ||
276 | .set_sysclk = aic26_set_sysclk, | ||
277 | .set_fmt = aic26_set_fmt, | ||
278 | }; | ||
279 | |||
273 | struct snd_soc_dai aic26_dai = { | 280 | struct snd_soc_dai aic26_dai = { |
274 | .name = "tlv320aic26", | 281 | .name = "tlv320aic26", |
275 | .playback = { | 282 | .playback = { |
@@ -286,12 +293,7 @@ struct snd_soc_dai aic26_dai = { | |||
286 | .rates = AIC26_RATES, | 293 | .rates = AIC26_RATES, |
287 | .formats = AIC26_FORMATS, | 294 | .formats = AIC26_FORMATS, |
288 | }, | 295 | }, |
289 | .ops = { | 296 | .ops = &aic26_dai_ops, |
290 | .hw_params = aic26_hw_params, | ||
291 | .digital_mute = aic26_mute, | ||
292 | .set_sysclk = aic26_set_sysclk, | ||
293 | .set_fmt = aic26_set_fmt, | ||
294 | }, | ||
295 | }; | 297 | }; |
296 | EXPORT_SYMBOL_GPL(aic26_dai); | 298 | EXPORT_SYMBOL_GPL(aic26_dai); |
297 | 299 | ||
@@ -322,9 +324,8 @@ static int aic26_probe(struct platform_device *pdev) | |||
322 | { | 324 | { |
323 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 325 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
324 | struct snd_soc_codec *codec; | 326 | struct snd_soc_codec *codec; |
325 | struct snd_kcontrol *kcontrol; | ||
326 | struct aic26 *aic26; | 327 | struct aic26 *aic26; |
327 | int i, ret, err; | 328 | int ret, err; |
328 | 329 | ||
329 | dev_info(&pdev->dev, "Probing AIC26 SoC CODEC driver\n"); | 330 | dev_info(&pdev->dev, "Probing AIC26 SoC CODEC driver\n"); |
330 | dev_dbg(&pdev->dev, "socdev=%p\n", socdev); | 331 | dev_dbg(&pdev->dev, "socdev=%p\n", socdev); |
@@ -338,7 +339,7 @@ static int aic26_probe(struct platform_device *pdev) | |||
338 | return -ENODEV; | 339 | return -ENODEV; |
339 | } | 340 | } |
340 | codec = &aic26->codec; | 341 | codec = &aic26->codec; |
341 | socdev->codec = codec; | 342 | socdev->card->codec = codec; |
342 | 343 | ||
343 | dev_dbg(&pdev->dev, "Registering PCMs, dev=%p, socdev->dev=%p\n", | 344 | dev_dbg(&pdev->dev, "Registering PCMs, dev=%p, socdev->dev=%p\n", |
344 | &pdev->dev, socdev->dev); | 345 | &pdev->dev, socdev->dev); |
@@ -351,11 +352,9 @@ static int aic26_probe(struct platform_device *pdev) | |||
351 | 352 | ||
352 | /* register controls */ | 353 | /* register controls */ |
353 | dev_dbg(&pdev->dev, "Registering controls\n"); | 354 | dev_dbg(&pdev->dev, "Registering controls\n"); |
354 | for (i = 0; i < ARRAY_SIZE(aic26_snd_controls); i++) { | 355 | err = snd_soc_add_controls(codec, aic26_snd_controls, |
355 | kcontrol = snd_soc_cnew(&aic26_snd_controls[i], codec, NULL); | 356 | ARRAY_SIZE(aic26_snd_controls)); |
356 | err = snd_ctl_add(codec->card, kcontrol); | 357 | WARN_ON(err < 0); |
357 | WARN_ON(err < 0); | ||
358 | } | ||
359 | 358 | ||
360 | /* CODEC is setup, we can register the card now */ | 359 | /* CODEC is setup, we can register the card now */ |
361 | dev_dbg(&pdev->dev, "Registering card\n"); | 360 | dev_dbg(&pdev->dev, "Registering card\n"); |
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c index aea0cb72d80a..ab099f482487 100644 --- a/sound/soc/codecs/tlv320aic3x.c +++ b/sound/soc/codecs/tlv320aic3x.c | |||
@@ -45,6 +45,7 @@ | |||
45 | #include <sound/soc.h> | 45 | #include <sound/soc.h> |
46 | #include <sound/soc-dapm.h> | 46 | #include <sound/soc-dapm.h> |
47 | #include <sound/initval.h> | 47 | #include <sound/initval.h> |
48 | #include <sound/tlv.h> | ||
48 | 49 | ||
49 | #include "tlv320aic3x.h" | 50 | #include "tlv320aic3x.h" |
50 | 51 | ||
@@ -250,56 +251,86 @@ static const struct soc_enum aic3x_enum[] = { | |||
250 | SOC_ENUM_DOUBLE(AIC3X_CODEC_DFILT_CTRL, 6, 4, 4, aic3x_adc_hpf), | 251 | SOC_ENUM_DOUBLE(AIC3X_CODEC_DFILT_CTRL, 6, 4, 4, aic3x_adc_hpf), |
251 | }; | 252 | }; |
252 | 253 | ||
254 | /* | ||
255 | * DAC digital volumes. From -63.5 to 0 dB in 0.5 dB steps | ||
256 | */ | ||
257 | static DECLARE_TLV_DB_SCALE(dac_tlv, -6350, 50, 0); | ||
258 | /* ADC PGA gain volumes. From 0 to 59.5 dB in 0.5 dB steps */ | ||
259 | static DECLARE_TLV_DB_SCALE(adc_tlv, 0, 50, 0); | ||
260 | /* | ||
261 | * Output stage volumes. From -78.3 to 0 dB. Muted below -78.3 dB. | ||
262 | * Step size is approximately 0.5 dB over most of the scale but increasing | ||
263 | * near the very low levels. | ||
264 | * Define dB scale so that it is mostly correct for range about -55 to 0 dB | ||
265 | * but having increasing dB difference below that (and where it doesn't count | ||
266 | * so much). This setting shows -50 dB (actual is -50.3 dB) for register | ||
267 | * value 100 and -58.5 dB (actual is -78.3 dB) for register value 117. | ||
268 | */ | ||
269 | static DECLARE_TLV_DB_SCALE(output_stage_tlv, -5900, 50, 1); | ||
270 | |||
253 | static const struct snd_kcontrol_new aic3x_snd_controls[] = { | 271 | static const struct snd_kcontrol_new aic3x_snd_controls[] = { |
254 | /* Output */ | 272 | /* Output */ |
255 | SOC_DOUBLE_R("PCM Playback Volume", LDAC_VOL, RDAC_VOL, 0, 0x7f, 1), | 273 | SOC_DOUBLE_R_TLV("PCM Playback Volume", |
274 | LDAC_VOL, RDAC_VOL, 0, 0x7f, 1, dac_tlv), | ||
256 | 275 | ||
257 | SOC_DOUBLE_R("Line DAC Playback Volume", DACL1_2_LLOPM_VOL, | 276 | SOC_DOUBLE_R_TLV("Line DAC Playback Volume", |
258 | DACR1_2_RLOPM_VOL, 0, 0x7f, 1), | 277 | DACL1_2_LLOPM_VOL, DACR1_2_RLOPM_VOL, |
278 | 0, 118, 1, output_stage_tlv), | ||
259 | SOC_SINGLE("LineL Playback Switch", LLOPM_CTRL, 3, 0x01, 0), | 279 | SOC_SINGLE("LineL Playback Switch", LLOPM_CTRL, 3, 0x01, 0), |
260 | SOC_SINGLE("LineR Playback Switch", RLOPM_CTRL, 3, 0x01, 0), | 280 | SOC_SINGLE("LineR Playback Switch", RLOPM_CTRL, 3, 0x01, 0), |
261 | SOC_DOUBLE_R("LineL DAC Playback Volume", DACL1_2_LLOPM_VOL, | 281 | SOC_DOUBLE_R_TLV("LineL DAC Playback Volume", |
262 | DACR1_2_LLOPM_VOL, 0, 0x7f, 1), | 282 | DACL1_2_LLOPM_VOL, DACR1_2_LLOPM_VOL, |
263 | SOC_SINGLE("LineL Left PGA Bypass Playback Volume", PGAL_2_LLOPM_VOL, | 283 | 0, 118, 1, output_stage_tlv), |
264 | 0, 0x7f, 1), | 284 | SOC_SINGLE_TLV("LineL Left PGA Bypass Playback Volume", |
265 | SOC_SINGLE("LineR Right PGA Bypass Playback Volume", PGAR_2_RLOPM_VOL, | 285 | PGAL_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv), |
266 | 0, 0x7f, 1), | 286 | SOC_SINGLE_TLV("LineR Right PGA Bypass Playback Volume", |
267 | SOC_DOUBLE_R("LineL Line2 Bypass Playback Volume", LINE2L_2_LLOPM_VOL, | 287 | PGAR_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv), |
268 | LINE2R_2_LLOPM_VOL, 0, 0x7f, 1), | 288 | SOC_DOUBLE_R_TLV("LineL Line2 Bypass Playback Volume", |
269 | SOC_DOUBLE_R("LineR Line2 Bypass Playback Volume", LINE2L_2_RLOPM_VOL, | 289 | LINE2L_2_LLOPM_VOL, LINE2R_2_LLOPM_VOL, |
270 | LINE2R_2_RLOPM_VOL, 0, 0x7f, 1), | 290 | 0, 118, 1, output_stage_tlv), |
271 | 291 | SOC_DOUBLE_R_TLV("LineR Line2 Bypass Playback Volume", | |
272 | SOC_DOUBLE_R("Mono DAC Playback Volume", DACL1_2_MONOLOPM_VOL, | 292 | LINE2L_2_RLOPM_VOL, LINE2R_2_RLOPM_VOL, |
273 | DACR1_2_MONOLOPM_VOL, 0, 0x7f, 1), | 293 | 0, 118, 1, output_stage_tlv), |
294 | |||
295 | SOC_DOUBLE_R_TLV("Mono DAC Playback Volume", | ||
296 | DACL1_2_MONOLOPM_VOL, DACR1_2_MONOLOPM_VOL, | ||
297 | 0, 118, 1, output_stage_tlv), | ||
274 | SOC_SINGLE("Mono DAC Playback Switch", MONOLOPM_CTRL, 3, 0x01, 0), | 298 | SOC_SINGLE("Mono DAC Playback Switch", MONOLOPM_CTRL, 3, 0x01, 0), |
275 | SOC_DOUBLE_R("Mono PGA Bypass Playback Volume", PGAL_2_MONOLOPM_VOL, | 299 | SOC_DOUBLE_R_TLV("Mono PGA Bypass Playback Volume", |
276 | PGAR_2_MONOLOPM_VOL, 0, 0x7f, 1), | 300 | PGAL_2_MONOLOPM_VOL, PGAR_2_MONOLOPM_VOL, |
277 | SOC_DOUBLE_R("Mono Line2 Bypass Playback Volume", LINE2L_2_MONOLOPM_VOL, | 301 | 0, 118, 1, output_stage_tlv), |
278 | LINE2R_2_MONOLOPM_VOL, 0, 0x7f, 1), | 302 | SOC_DOUBLE_R_TLV("Mono Line2 Bypass Playback Volume", |
279 | 303 | LINE2L_2_MONOLOPM_VOL, LINE2R_2_MONOLOPM_VOL, | |
280 | SOC_DOUBLE_R("HP DAC Playback Volume", DACL1_2_HPLOUT_VOL, | 304 | 0, 118, 1, output_stage_tlv), |
281 | DACR1_2_HPROUT_VOL, 0, 0x7f, 1), | 305 | |
306 | SOC_DOUBLE_R_TLV("HP DAC Playback Volume", | ||
307 | DACL1_2_HPLOUT_VOL, DACR1_2_HPROUT_VOL, | ||
308 | 0, 118, 1, output_stage_tlv), | ||
282 | SOC_DOUBLE_R("HP DAC Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3, | 309 | SOC_DOUBLE_R("HP DAC Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3, |
283 | 0x01, 0), | 310 | 0x01, 0), |
284 | SOC_DOUBLE_R("HP Right PGA Bypass Playback Volume", PGAR_2_HPLOUT_VOL, | 311 | SOC_DOUBLE_R_TLV("HP Right PGA Bypass Playback Volume", |
285 | PGAR_2_HPROUT_VOL, 0, 0x7f, 1), | 312 | PGAR_2_HPLOUT_VOL, PGAR_2_HPROUT_VOL, |
286 | SOC_SINGLE("HPL PGA Bypass Playback Volume", PGAL_2_HPLOUT_VOL, | 313 | 0, 118, 1, output_stage_tlv), |
287 | 0, 0x7f, 1), | 314 | SOC_SINGLE_TLV("HPL PGA Bypass Playback Volume", |
288 | SOC_SINGLE("HPR PGA Bypass Playback Volume", PGAL_2_HPROUT_VOL, | 315 | PGAL_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv), |
289 | 0, 0x7f, 1), | 316 | SOC_SINGLE_TLV("HPR PGA Bypass Playback Volume", |
290 | SOC_DOUBLE_R("HP Line2 Bypass Playback Volume", LINE2L_2_HPLOUT_VOL, | 317 | PGAL_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv), |
291 | LINE2R_2_HPROUT_VOL, 0, 0x7f, 1), | 318 | SOC_DOUBLE_R_TLV("HP Line2 Bypass Playback Volume", |
292 | 319 | LINE2L_2_HPLOUT_VOL, LINE2R_2_HPROUT_VOL, | |
293 | SOC_DOUBLE_R("HPCOM DAC Playback Volume", DACL1_2_HPLCOM_VOL, | 320 | 0, 118, 1, output_stage_tlv), |
294 | DACR1_2_HPRCOM_VOL, 0, 0x7f, 1), | 321 | |
322 | SOC_DOUBLE_R_TLV("HPCOM DAC Playback Volume", | ||
323 | DACL1_2_HPLCOM_VOL, DACR1_2_HPRCOM_VOL, | ||
324 | 0, 118, 1, output_stage_tlv), | ||
295 | SOC_DOUBLE_R("HPCOM DAC Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3, | 325 | SOC_DOUBLE_R("HPCOM DAC Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3, |
296 | 0x01, 0), | 326 | 0x01, 0), |
297 | SOC_SINGLE("HPLCOM PGA Bypass Playback Volume", PGAL_2_HPLCOM_VOL, | 327 | SOC_SINGLE_TLV("HPLCOM PGA Bypass Playback Volume", |
298 | 0, 0x7f, 1), | 328 | PGAL_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv), |
299 | SOC_SINGLE("HPRCOM PGA Bypass Playback Volume", PGAL_2_HPRCOM_VOL, | 329 | SOC_SINGLE_TLV("HPRCOM PGA Bypass Playback Volume", |
300 | 0, 0x7f, 1), | 330 | PGAL_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv), |
301 | SOC_DOUBLE_R("HPCOM Line2 Bypass Playback Volume", LINE2L_2_HPLCOM_VOL, | 331 | SOC_DOUBLE_R_TLV("HPCOM Line2 Bypass Playback Volume", |
302 | LINE2R_2_HPRCOM_VOL, 0, 0x7f, 1), | 332 | LINE2L_2_HPLCOM_VOL, LINE2R_2_HPRCOM_VOL, |
333 | 0, 118, 1, output_stage_tlv), | ||
303 | 334 | ||
304 | /* | 335 | /* |
305 | * Note: enable Automatic input Gain Controller with care. It can | 336 | * Note: enable Automatic input Gain Controller with care. It can |
@@ -308,28 +339,13 @@ static const struct snd_kcontrol_new aic3x_snd_controls[] = { | |||
308 | SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0), | 339 | SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0), |
309 | 340 | ||
310 | /* Input */ | 341 | /* Input */ |
311 | SOC_DOUBLE_R("PGA Capture Volume", LADC_VOL, RADC_VOL, 0, 0x7f, 0), | 342 | SOC_DOUBLE_R_TLV("PGA Capture Volume", LADC_VOL, RADC_VOL, |
343 | 0, 119, 0, adc_tlv), | ||
312 | SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1), | 344 | SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1), |
313 | 345 | ||
314 | SOC_ENUM("ADC HPF Cut-off", aic3x_enum[ADC_HPF_ENUM]), | 346 | SOC_ENUM("ADC HPF Cut-off", aic3x_enum[ADC_HPF_ENUM]), |
315 | }; | 347 | }; |
316 | 348 | ||
317 | /* add non dapm controls */ | ||
318 | static int aic3x_add_controls(struct snd_soc_codec *codec) | ||
319 | { | ||
320 | int err, i; | ||
321 | |||
322 | for (i = 0; i < ARRAY_SIZE(aic3x_snd_controls); i++) { | ||
323 | err = snd_ctl_add(codec->card, | ||
324 | snd_soc_cnew(&aic3x_snd_controls[i], | ||
325 | codec, NULL)); | ||
326 | if (err < 0) | ||
327 | return err; | ||
328 | } | ||
329 | |||
330 | return 0; | ||
331 | } | ||
332 | |||
333 | /* Left DAC Mux */ | 349 | /* Left DAC Mux */ |
334 | static const struct snd_kcontrol_new aic3x_left_dac_mux_controls = | 350 | static const struct snd_kcontrol_new aic3x_left_dac_mux_controls = |
335 | SOC_DAPM_ENUM("Route", aic3x_enum[LDAC_ENUM]); | 351 | SOC_DAPM_ENUM("Route", aic3x_enum[LDAC_ENUM]); |
@@ -746,7 +762,7 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream, | |||
746 | { | 762 | { |
747 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 763 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
748 | struct snd_soc_device *socdev = rtd->socdev; | 764 | struct snd_soc_device *socdev = rtd->socdev; |
749 | struct snd_soc_codec *codec = socdev->codec; | 765 | struct snd_soc_codec *codec = socdev->card->codec; |
750 | struct aic3x_priv *aic3x = codec->private_data; | 766 | struct aic3x_priv *aic3x = codec->private_data; |
751 | int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0; | 767 | int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0; |
752 | u8 data, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1; | 768 | u8 data, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1; |
@@ -1072,6 +1088,13 @@ EXPORT_SYMBOL_GPL(aic3x_button_pressed); | |||
1072 | #define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ | 1088 | #define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ |
1073 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) | 1089 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) |
1074 | 1090 | ||
1091 | static struct snd_soc_dai_ops aic3x_dai_ops = { | ||
1092 | .hw_params = aic3x_hw_params, | ||
1093 | .digital_mute = aic3x_mute, | ||
1094 | .set_sysclk = aic3x_set_dai_sysclk, | ||
1095 | .set_fmt = aic3x_set_dai_fmt, | ||
1096 | }; | ||
1097 | |||
1075 | struct snd_soc_dai aic3x_dai = { | 1098 | struct snd_soc_dai aic3x_dai = { |
1076 | .name = "tlv320aic3x", | 1099 | .name = "tlv320aic3x", |
1077 | .playback = { | 1100 | .playback = { |
@@ -1086,19 +1109,14 @@ struct snd_soc_dai aic3x_dai = { | |||
1086 | .channels_max = 2, | 1109 | .channels_max = 2, |
1087 | .rates = AIC3X_RATES, | 1110 | .rates = AIC3X_RATES, |
1088 | .formats = AIC3X_FORMATS,}, | 1111 | .formats = AIC3X_FORMATS,}, |
1089 | .ops = { | 1112 | .ops = &aic3x_dai_ops, |
1090 | .hw_params = aic3x_hw_params, | ||
1091 | .digital_mute = aic3x_mute, | ||
1092 | .set_sysclk = aic3x_set_dai_sysclk, | ||
1093 | .set_fmt = aic3x_set_dai_fmt, | ||
1094 | } | ||
1095 | }; | 1113 | }; |
1096 | EXPORT_SYMBOL_GPL(aic3x_dai); | 1114 | EXPORT_SYMBOL_GPL(aic3x_dai); |
1097 | 1115 | ||
1098 | static int aic3x_suspend(struct platform_device *pdev, pm_message_t state) | 1116 | static int aic3x_suspend(struct platform_device *pdev, pm_message_t state) |
1099 | { | 1117 | { |
1100 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1118 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1101 | struct snd_soc_codec *codec = socdev->codec; | 1119 | struct snd_soc_codec *codec = socdev->card->codec; |
1102 | 1120 | ||
1103 | aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF); | 1121 | aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF); |
1104 | 1122 | ||
@@ -1108,7 +1126,7 @@ static int aic3x_suspend(struct platform_device *pdev, pm_message_t state) | |||
1108 | static int aic3x_resume(struct platform_device *pdev) | 1126 | static int aic3x_resume(struct platform_device *pdev) |
1109 | { | 1127 | { |
1110 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1128 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1111 | struct snd_soc_codec *codec = socdev->codec; | 1129 | struct snd_soc_codec *codec = socdev->card->codec; |
1112 | int i; | 1130 | int i; |
1113 | u8 data[2]; | 1131 | u8 data[2]; |
1114 | u8 *cache = codec->reg_cache; | 1132 | u8 *cache = codec->reg_cache; |
@@ -1131,7 +1149,7 @@ static int aic3x_resume(struct platform_device *pdev) | |||
1131 | */ | 1149 | */ |
1132 | static int aic3x_init(struct snd_soc_device *socdev) | 1150 | static int aic3x_init(struct snd_soc_device *socdev) |
1133 | { | 1151 | { |
1134 | struct snd_soc_codec *codec = socdev->codec; | 1152 | struct snd_soc_codec *codec = socdev->card->codec; |
1135 | struct aic3x_setup_data *setup = socdev->codec_data; | 1153 | struct aic3x_setup_data *setup = socdev->codec_data; |
1136 | int reg, ret = 0; | 1154 | int reg, ret = 0; |
1137 | 1155 | ||
@@ -1227,7 +1245,8 @@ static int aic3x_init(struct snd_soc_device *socdev) | |||
1227 | aic3x_write(codec, AIC3X_GPIO1_REG, (setup->gpio_func[0] & 0xf) << 4); | 1245 | aic3x_write(codec, AIC3X_GPIO1_REG, (setup->gpio_func[0] & 0xf) << 4); |
1228 | aic3x_write(codec, AIC3X_GPIO2_REG, (setup->gpio_func[1] & 0xf) << 4); | 1246 | aic3x_write(codec, AIC3X_GPIO2_REG, (setup->gpio_func[1] & 0xf) << 4); |
1229 | 1247 | ||
1230 | aic3x_add_controls(codec); | 1248 | snd_soc_add_controls(codec, aic3x_snd_controls, |
1249 | ARRAY_SIZE(aic3x_snd_controls)); | ||
1231 | aic3x_add_widgets(codec); | 1250 | aic3x_add_widgets(codec); |
1232 | ret = snd_soc_init_card(socdev); | 1251 | ret = snd_soc_init_card(socdev); |
1233 | if (ret < 0) { | 1252 | if (ret < 0) { |
@@ -1261,7 +1280,7 @@ static int aic3x_i2c_probe(struct i2c_client *i2c, | |||
1261 | const struct i2c_device_id *id) | 1280 | const struct i2c_device_id *id) |
1262 | { | 1281 | { |
1263 | struct snd_soc_device *socdev = aic3x_socdev; | 1282 | struct snd_soc_device *socdev = aic3x_socdev; |
1264 | struct snd_soc_codec *codec = socdev->codec; | 1283 | struct snd_soc_codec *codec = socdev->card->codec; |
1265 | int ret; | 1284 | int ret; |
1266 | 1285 | ||
1267 | i2c_set_clientdata(i2c, codec); | 1286 | i2c_set_clientdata(i2c, codec); |
@@ -1366,7 +1385,7 @@ static int aic3x_probe(struct platform_device *pdev) | |||
1366 | } | 1385 | } |
1367 | 1386 | ||
1368 | codec->private_data = aic3x; | 1387 | codec->private_data = aic3x; |
1369 | socdev->codec = codec; | 1388 | socdev->card->codec = codec; |
1370 | mutex_init(&codec->mutex); | 1389 | mutex_init(&codec->mutex); |
1371 | INIT_LIST_HEAD(&codec->dapm_widgets); | 1390 | INIT_LIST_HEAD(&codec->dapm_widgets); |
1372 | INIT_LIST_HEAD(&codec->dapm_paths); | 1391 | INIT_LIST_HEAD(&codec->dapm_paths); |
@@ -1392,7 +1411,7 @@ static int aic3x_probe(struct platform_device *pdev) | |||
1392 | static int aic3x_remove(struct platform_device *pdev) | 1411 | static int aic3x_remove(struct platform_device *pdev) |
1393 | { | 1412 | { |
1394 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1413 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1395 | struct snd_soc_codec *codec = socdev->codec; | 1414 | struct snd_soc_codec *codec = socdev->card->codec; |
1396 | 1415 | ||
1397 | /* power down chip */ | 1416 | /* power down chip */ |
1398 | if (codec->control_data) | 1417 | if (codec->control_data) |
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c index ea370a4f86d5..97738e2ece04 100644 --- a/sound/soc/codecs/twl4030.c +++ b/sound/soc/codecs/twl4030.c | |||
@@ -42,7 +42,7 @@ | |||
42 | */ | 42 | */ |
43 | static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = { | 43 | static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = { |
44 | 0x00, /* this register not used */ | 44 | 0x00, /* this register not used */ |
45 | 0x93, /* REG_CODEC_MODE (0x1) */ | 45 | 0x91, /* REG_CODEC_MODE (0x1) */ |
46 | 0xc3, /* REG_OPTION (0x2) */ | 46 | 0xc3, /* REG_OPTION (0x2) */ |
47 | 0x00, /* REG_UNKNOWN (0x3) */ | 47 | 0x00, /* REG_UNKNOWN (0x3) */ |
48 | 0x00, /* REG_MICBIAS_CTL (0x4) */ | 48 | 0x00, /* REG_MICBIAS_CTL (0x4) */ |
@@ -117,6 +117,13 @@ static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = { | |||
117 | 0x00, /* REG_MISC_SET_2 (0x49) */ | 117 | 0x00, /* REG_MISC_SET_2 (0x49) */ |
118 | }; | 118 | }; |
119 | 119 | ||
120 | /* codec private data */ | ||
121 | struct twl4030_priv { | ||
122 | unsigned int bypass_state; | ||
123 | unsigned int codec_powered; | ||
124 | unsigned int codec_muted; | ||
125 | }; | ||
126 | |||
120 | /* | 127 | /* |
121 | * read twl4030 register cache | 128 | * read twl4030 register cache |
122 | */ | 129 | */ |
@@ -125,6 +132,9 @@ static inline unsigned int twl4030_read_reg_cache(struct snd_soc_codec *codec, | |||
125 | { | 132 | { |
126 | u8 *cache = codec->reg_cache; | 133 | u8 *cache = codec->reg_cache; |
127 | 134 | ||
135 | if (reg >= TWL4030_CACHEREGNUM) | ||
136 | return -EIO; | ||
137 | |||
128 | return cache[reg]; | 138 | return cache[reg]; |
129 | } | 139 | } |
130 | 140 | ||
@@ -151,26 +161,22 @@ static int twl4030_write(struct snd_soc_codec *codec, | |||
151 | return twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, value, reg); | 161 | return twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, value, reg); |
152 | } | 162 | } |
153 | 163 | ||
154 | static void twl4030_clear_codecpdz(struct snd_soc_codec *codec) | 164 | static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable) |
155 | { | 165 | { |
166 | struct twl4030_priv *twl4030 = codec->private_data; | ||
156 | u8 mode; | 167 | u8 mode; |
157 | 168 | ||
158 | mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE); | 169 | if (enable == twl4030->codec_powered) |
159 | twl4030_write(codec, TWL4030_REG_CODEC_MODE, | 170 | return; |
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 | ||
171 | mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE); | 172 | mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE); |
172 | twl4030_write(codec, TWL4030_REG_CODEC_MODE, | 173 | if (enable) |
173 | mode | TWL4030_CODECPDZ); | 174 | mode |= TWL4030_CODECPDZ; |
175 | else | ||
176 | mode &= ~TWL4030_CODECPDZ; | ||
177 | |||
178 | twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode); | ||
179 | twl4030->codec_powered = enable; | ||
174 | 180 | ||
175 | /* REVISIT: this delay is present in TI sample drivers */ | 181 | /* REVISIT: this delay is present in TI sample drivers */ |
176 | /* but there seems to be no TRM requirement for it */ | 182 | /* but there seems to be no TRM requirement for it */ |
@@ -182,7 +188,7 @@ static void twl4030_init_chip(struct snd_soc_codec *codec) | |||
182 | int i; | 188 | int i; |
183 | 189 | ||
184 | /* clear CODECPDZ prior to setting register defaults */ | 190 | /* clear CODECPDZ prior to setting register defaults */ |
185 | twl4030_clear_codecpdz(codec); | 191 | twl4030_codec_enable(codec, 0); |
186 | 192 | ||
187 | /* set all audio section registers to reasonable defaults */ | 193 | /* set all audio section registers to reasonable defaults */ |
188 | for (i = TWL4030_REG_OPTION; i <= TWL4030_REG_MISC_SET_2; i++) | 194 | for (i = TWL4030_REG_OPTION; i <= TWL4030_REG_MISC_SET_2; i++) |
@@ -190,6 +196,122 @@ static void twl4030_init_chip(struct snd_soc_codec *codec) | |||
190 | 196 | ||
191 | } | 197 | } |
192 | 198 | ||
199 | static void twl4030_codec_mute(struct snd_soc_codec *codec, int mute) | ||
200 | { | ||
201 | struct twl4030_priv *twl4030 = codec->private_data; | ||
202 | u8 reg_val; | ||
203 | |||
204 | if (mute == twl4030->codec_muted) | ||
205 | return; | ||
206 | |||
207 | if (mute) { | ||
208 | /* Bypass the reg_cache and mute the volumes | ||
209 | * Headset mute is done in it's own event handler | ||
210 | * Things to mute: Earpiece, PreDrivL/R, CarkitL/R | ||
211 | */ | ||
212 | reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_EAR_CTL); | ||
213 | twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, | ||
214 | reg_val & (~TWL4030_EAR_GAIN), | ||
215 | TWL4030_REG_EAR_CTL); | ||
216 | |||
217 | reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_PREDL_CTL); | ||
218 | twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, | ||
219 | reg_val & (~TWL4030_PREDL_GAIN), | ||
220 | TWL4030_REG_PREDL_CTL); | ||
221 | reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_PREDR_CTL); | ||
222 | twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, | ||
223 | reg_val & (~TWL4030_PREDR_GAIN), | ||
224 | TWL4030_REG_PREDL_CTL); | ||
225 | |||
226 | reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_PRECKL_CTL); | ||
227 | twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, | ||
228 | reg_val & (~TWL4030_PRECKL_GAIN), | ||
229 | TWL4030_REG_PRECKL_CTL); | ||
230 | reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_PRECKR_CTL); | ||
231 | twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, | ||
232 | reg_val & (~TWL4030_PRECKL_GAIN), | ||
233 | TWL4030_REG_PRECKR_CTL); | ||
234 | |||
235 | /* Disable PLL */ | ||
236 | reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_APLL_CTL); | ||
237 | reg_val &= ~TWL4030_APLL_EN; | ||
238 | twl4030_write(codec, TWL4030_REG_APLL_CTL, reg_val); | ||
239 | } else { | ||
240 | /* Restore the volumes | ||
241 | * Headset mute is done in it's own event handler | ||
242 | * Things to restore: Earpiece, PreDrivL/R, CarkitL/R | ||
243 | */ | ||
244 | twl4030_write(codec, TWL4030_REG_EAR_CTL, | ||
245 | twl4030_read_reg_cache(codec, TWL4030_REG_EAR_CTL)); | ||
246 | |||
247 | twl4030_write(codec, TWL4030_REG_PREDL_CTL, | ||
248 | twl4030_read_reg_cache(codec, TWL4030_REG_PREDL_CTL)); | ||
249 | twl4030_write(codec, TWL4030_REG_PREDR_CTL, | ||
250 | twl4030_read_reg_cache(codec, TWL4030_REG_PREDR_CTL)); | ||
251 | |||
252 | twl4030_write(codec, TWL4030_REG_PRECKL_CTL, | ||
253 | twl4030_read_reg_cache(codec, TWL4030_REG_PRECKL_CTL)); | ||
254 | twl4030_write(codec, TWL4030_REG_PRECKR_CTL, | ||
255 | twl4030_read_reg_cache(codec, TWL4030_REG_PRECKR_CTL)); | ||
256 | |||
257 | /* Enable PLL */ | ||
258 | reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_APLL_CTL); | ||
259 | reg_val |= TWL4030_APLL_EN; | ||
260 | twl4030_write(codec, TWL4030_REG_APLL_CTL, reg_val); | ||
261 | } | ||
262 | |||
263 | twl4030->codec_muted = mute; | ||
264 | } | ||
265 | |||
266 | static void twl4030_power_up(struct snd_soc_codec *codec) | ||
267 | { | ||
268 | struct twl4030_priv *twl4030 = codec->private_data; | ||
269 | u8 anamicl, regmisc1, byte; | ||
270 | int i = 0; | ||
271 | |||
272 | if (twl4030->codec_powered) | ||
273 | return; | ||
274 | |||
275 | /* set CODECPDZ to turn on codec */ | ||
276 | twl4030_codec_enable(codec, 1); | ||
277 | |||
278 | /* initiate offset cancellation */ | ||
279 | anamicl = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICL); | ||
280 | twl4030_write(codec, TWL4030_REG_ANAMICL, | ||
281 | anamicl | TWL4030_CNCL_OFFSET_START); | ||
282 | |||
283 | /* wait for offset cancellation to complete */ | ||
284 | do { | ||
285 | /* this takes a little while, so don't slam i2c */ | ||
286 | udelay(2000); | ||
287 | twl4030_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte, | ||
288 | TWL4030_REG_ANAMICL); | ||
289 | } while ((i++ < 100) && | ||
290 | ((byte & TWL4030_CNCL_OFFSET_START) == | ||
291 | TWL4030_CNCL_OFFSET_START)); | ||
292 | |||
293 | /* Make sure that the reg_cache has the same value as the HW */ | ||
294 | twl4030_write_reg_cache(codec, TWL4030_REG_ANAMICL, byte); | ||
295 | |||
296 | /* anti-pop when changing analog gain */ | ||
297 | regmisc1 = twl4030_read_reg_cache(codec, TWL4030_REG_MISC_SET_1); | ||
298 | twl4030_write(codec, TWL4030_REG_MISC_SET_1, | ||
299 | regmisc1 | TWL4030_SMOOTH_ANAVOL_EN); | ||
300 | |||
301 | /* toggle CODECPDZ as per TRM */ | ||
302 | twl4030_codec_enable(codec, 0); | ||
303 | twl4030_codec_enable(codec, 1); | ||
304 | } | ||
305 | |||
306 | /* | ||
307 | * Unconditional power down | ||
308 | */ | ||
309 | static void twl4030_power_down(struct snd_soc_codec *codec) | ||
310 | { | ||
311 | /* power down */ | ||
312 | twl4030_codec_enable(codec, 0); | ||
313 | } | ||
314 | |||
193 | /* Earpiece */ | 315 | /* Earpiece */ |
194 | static const char *twl4030_earpiece_texts[] = | 316 | static const char *twl4030_earpiece_texts[] = |
195 | {"Off", "DACL1", "DACL2", "DACR1"}; | 317 | {"Off", "DACL1", "DACL2", "DACR1"}; |
@@ -366,6 +488,41 @@ static const struct soc_enum twl4030_micpathtx2_enum = | |||
366 | static const struct snd_kcontrol_new twl4030_dapm_micpathtx2_control = | 488 | static const struct snd_kcontrol_new twl4030_dapm_micpathtx2_control = |
367 | SOC_DAPM_ENUM("Route", twl4030_micpathtx2_enum); | 489 | SOC_DAPM_ENUM("Route", twl4030_micpathtx2_enum); |
368 | 490 | ||
491 | /* Analog bypass for AudioR1 */ | ||
492 | static const struct snd_kcontrol_new twl4030_dapm_abypassr1_control = | ||
493 | SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXR1_APGA_CTL, 2, 1, 0); | ||
494 | |||
495 | /* Analog bypass for AudioL1 */ | ||
496 | static const struct snd_kcontrol_new twl4030_dapm_abypassl1_control = | ||
497 | SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXL1_APGA_CTL, 2, 1, 0); | ||
498 | |||
499 | /* Analog bypass for AudioR2 */ | ||
500 | static const struct snd_kcontrol_new twl4030_dapm_abypassr2_control = | ||
501 | SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXR2_APGA_CTL, 2, 1, 0); | ||
502 | |||
503 | /* Analog bypass for AudioL2 */ | ||
504 | static const struct snd_kcontrol_new twl4030_dapm_abypassl2_control = | ||
505 | SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXL2_APGA_CTL, 2, 1, 0); | ||
506 | |||
507 | /* Digital bypass gain, 0 mutes the bypass */ | ||
508 | static const unsigned int twl4030_dapm_dbypass_tlv[] = { | ||
509 | TLV_DB_RANGE_HEAD(2), | ||
510 | 0, 3, TLV_DB_SCALE_ITEM(-2400, 0, 1), | ||
511 | 4, 7, TLV_DB_SCALE_ITEM(-1800, 600, 0), | ||
512 | }; | ||
513 | |||
514 | /* Digital bypass left (TX1L -> RX2L) */ | ||
515 | static const struct snd_kcontrol_new twl4030_dapm_dbypassl_control = | ||
516 | SOC_DAPM_SINGLE_TLV("Volume", | ||
517 | TWL4030_REG_ATX2ARXPGA, 3, 7, 0, | ||
518 | twl4030_dapm_dbypass_tlv); | ||
519 | |||
520 | /* Digital bypass right (TX1R -> RX2R) */ | ||
521 | static const struct snd_kcontrol_new twl4030_dapm_dbypassr_control = | ||
522 | SOC_DAPM_SINGLE_TLV("Volume", | ||
523 | TWL4030_REG_ATX2ARXPGA, 0, 7, 0, | ||
524 | twl4030_dapm_dbypass_tlv); | ||
525 | |||
369 | static int micpath_event(struct snd_soc_dapm_widget *w, | 526 | static int micpath_event(struct snd_soc_dapm_widget *w, |
370 | struct snd_kcontrol *kcontrol, int event) | 527 | struct snd_kcontrol *kcontrol, int event) |
371 | { | 528 | { |
@@ -420,6 +577,79 @@ static int handsfree_event(struct snd_soc_dapm_widget *w, | |||
420 | return 0; | 577 | return 0; |
421 | } | 578 | } |
422 | 579 | ||
580 | static int headsetl_event(struct snd_soc_dapm_widget *w, | ||
581 | struct snd_kcontrol *kcontrol, int event) | ||
582 | { | ||
583 | unsigned char hs_gain, hs_pop; | ||
584 | |||
585 | /* Save the current volume */ | ||
586 | hs_gain = twl4030_read_reg_cache(w->codec, TWL4030_REG_HS_GAIN_SET); | ||
587 | hs_pop = twl4030_read_reg_cache(w->codec, TWL4030_REG_HS_POPN_SET); | ||
588 | |||
589 | switch (event) { | ||
590 | case SND_SOC_DAPM_POST_PMU: | ||
591 | /* Do the anti-pop/bias ramp enable according to the TRM */ | ||
592 | hs_pop |= TWL4030_VMID_EN; | ||
593 | twl4030_write(w->codec, TWL4030_REG_HS_POPN_SET, hs_pop); | ||
594 | /* Is this needed? Can we just use whatever gain here? */ | ||
595 | twl4030_write(w->codec, TWL4030_REG_HS_GAIN_SET, | ||
596 | (hs_gain & (~0x0f)) | 0x0a); | ||
597 | hs_pop |= TWL4030_RAMP_EN; | ||
598 | twl4030_write(w->codec, TWL4030_REG_HS_POPN_SET, hs_pop); | ||
599 | |||
600 | /* Restore the original volume */ | ||
601 | twl4030_write(w->codec, TWL4030_REG_HS_GAIN_SET, hs_gain); | ||
602 | break; | ||
603 | case SND_SOC_DAPM_POST_PMD: | ||
604 | /* Do the anti-pop/bias ramp disable according to the TRM */ | ||
605 | hs_pop &= ~TWL4030_RAMP_EN; | ||
606 | twl4030_write(w->codec, TWL4030_REG_HS_POPN_SET, hs_pop); | ||
607 | /* Bypass the reg_cache to mute the headset */ | ||
608 | twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, | ||
609 | hs_gain & (~0x0f), | ||
610 | TWL4030_REG_HS_GAIN_SET); | ||
611 | hs_pop &= ~TWL4030_VMID_EN; | ||
612 | twl4030_write(w->codec, TWL4030_REG_HS_POPN_SET, hs_pop); | ||
613 | break; | ||
614 | } | ||
615 | return 0; | ||
616 | } | ||
617 | |||
618 | static int bypass_event(struct snd_soc_dapm_widget *w, | ||
619 | struct snd_kcontrol *kcontrol, int event) | ||
620 | { | ||
621 | struct soc_mixer_control *m = | ||
622 | (struct soc_mixer_control *)w->kcontrols->private_value; | ||
623 | struct twl4030_priv *twl4030 = w->codec->private_data; | ||
624 | unsigned char reg; | ||
625 | |||
626 | reg = twl4030_read_reg_cache(w->codec, m->reg); | ||
627 | |||
628 | if (m->reg <= TWL4030_REG_ARXR2_APGA_CTL) { | ||
629 | /* Analog bypass */ | ||
630 | if (reg & (1 << m->shift)) | ||
631 | twl4030->bypass_state |= | ||
632 | (1 << (m->reg - TWL4030_REG_ARXL1_APGA_CTL)); | ||
633 | else | ||
634 | twl4030->bypass_state &= | ||
635 | ~(1 << (m->reg - TWL4030_REG_ARXL1_APGA_CTL)); | ||
636 | } else { | ||
637 | /* Digital bypass */ | ||
638 | if (reg & (0x7 << m->shift)) | ||
639 | twl4030->bypass_state |= (1 << (m->shift ? 5 : 4)); | ||
640 | else | ||
641 | twl4030->bypass_state &= ~(1 << (m->shift ? 5 : 4)); | ||
642 | } | ||
643 | |||
644 | if (w->codec->bias_level == SND_SOC_BIAS_STANDBY) { | ||
645 | if (twl4030->bypass_state) | ||
646 | twl4030_codec_mute(w->codec, 0); | ||
647 | else | ||
648 | twl4030_codec_mute(w->codec, 1); | ||
649 | } | ||
650 | return 0; | ||
651 | } | ||
652 | |||
423 | /* | 653 | /* |
424 | * Some of the gain controls in TWL (mostly those which are associated with | 654 | * Some of the gain controls in TWL (mostly those which are associated with |
425 | * the outputs) are implemented in an interesting way: | 655 | * the outputs) are implemented in an interesting way: |
@@ -614,6 +844,17 @@ static DECLARE_TLV_DB_SCALE(digital_capture_tlv, 0, 100, 0); | |||
614 | */ | 844 | */ |
615 | static DECLARE_TLV_DB_SCALE(input_gain_tlv, 0, 600, 0); | 845 | static DECLARE_TLV_DB_SCALE(input_gain_tlv, 0, 600, 0); |
616 | 846 | ||
847 | static const char *twl4030_rampdelay_texts[] = { | ||
848 | "27/20/14 ms", "55/40/27 ms", "109/81/55 ms", "218/161/109 ms", | ||
849 | "437/323/218 ms", "874/645/437 ms", "1748/1291/874 ms", | ||
850 | "3495/2581/1748 ms" | ||
851 | }; | ||
852 | |||
853 | static const struct soc_enum twl4030_rampdelay_enum = | ||
854 | SOC_ENUM_SINGLE(TWL4030_REG_HS_POPN_SET, 2, | ||
855 | ARRAY_SIZE(twl4030_rampdelay_texts), | ||
856 | twl4030_rampdelay_texts); | ||
857 | |||
617 | static const struct snd_kcontrol_new twl4030_snd_controls[] = { | 858 | static const struct snd_kcontrol_new twl4030_snd_controls[] = { |
618 | /* Common playback gain controls */ | 859 | /* Common playback gain controls */ |
619 | SOC_DOUBLE_R_TLV("DAC1 Digital Fine Playback Volume", | 860 | SOC_DOUBLE_R_TLV("DAC1 Digital Fine Playback Volume", |
@@ -668,23 +909,9 @@ static const struct snd_kcontrol_new twl4030_snd_controls[] = { | |||
668 | 909 | ||
669 | SOC_DOUBLE_TLV("Analog Capture Volume", TWL4030_REG_ANAMIC_GAIN, | 910 | SOC_DOUBLE_TLV("Analog Capture Volume", TWL4030_REG_ANAMIC_GAIN, |
670 | 0, 3, 5, 0, input_gain_tlv), | 911 | 0, 3, 5, 0, input_gain_tlv), |
671 | }; | ||
672 | |||
673 | /* add non dapm controls */ | ||
674 | static int twl4030_add_controls(struct snd_soc_codec *codec) | ||
675 | { | ||
676 | int err, i; | ||
677 | |||
678 | for (i = 0; i < ARRAY_SIZE(twl4030_snd_controls); i++) { | ||
679 | err = snd_ctl_add(codec->card, | ||
680 | snd_soc_cnew(&twl4030_snd_controls[i], | ||
681 | codec, NULL)); | ||
682 | if (err < 0) | ||
683 | return err; | ||
684 | } | ||
685 | 912 | ||
686 | return 0; | 913 | SOC_ENUM("HS ramp delay", twl4030_rampdelay_enum), |
687 | } | 914 | }; |
688 | 915 | ||
689 | static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | 916 | static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { |
690 | /* Left channel inputs */ | 917 | /* Left channel inputs */ |
@@ -714,13 +941,13 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | |||
714 | 941 | ||
715 | /* DACs */ | 942 | /* DACs */ |
716 | SND_SOC_DAPM_DAC("DAC Right1", "Right Front Playback", | 943 | SND_SOC_DAPM_DAC("DAC Right1", "Right Front Playback", |
717 | TWL4030_REG_AVDAC_CTL, 0, 0), | 944 | SND_SOC_NOPM, 0, 0), |
718 | SND_SOC_DAPM_DAC("DAC Left1", "Left Front Playback", | 945 | SND_SOC_DAPM_DAC("DAC Left1", "Left Front Playback", |
719 | TWL4030_REG_AVDAC_CTL, 1, 0), | 946 | SND_SOC_NOPM, 0, 0), |
720 | SND_SOC_DAPM_DAC("DAC Right2", "Right Rear Playback", | 947 | SND_SOC_DAPM_DAC("DAC Right2", "Right Rear Playback", |
721 | TWL4030_REG_AVDAC_CTL, 2, 0), | 948 | SND_SOC_NOPM, 0, 0), |
722 | SND_SOC_DAPM_DAC("DAC Left2", "Left Rear Playback", | 949 | SND_SOC_DAPM_DAC("DAC Left2", "Left Rear Playback", |
723 | TWL4030_REG_AVDAC_CTL, 3, 0), | 950 | SND_SOC_NOPM, 0, 0), |
724 | 951 | ||
725 | /* Analog PGAs */ | 952 | /* Analog PGAs */ |
726 | SND_SOC_DAPM_PGA("ARXR1_APGA", TWL4030_REG_ARXR1_APGA_CTL, | 953 | SND_SOC_DAPM_PGA("ARXR1_APGA", TWL4030_REG_ARXR1_APGA_CTL, |
@@ -732,6 +959,37 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | |||
732 | SND_SOC_DAPM_PGA("ARXL2_APGA", TWL4030_REG_ARXL2_APGA_CTL, | 959 | SND_SOC_DAPM_PGA("ARXL2_APGA", TWL4030_REG_ARXL2_APGA_CTL, |
733 | 0, 0, NULL, 0), | 960 | 0, 0, NULL, 0), |
734 | 961 | ||
962 | /* Analog bypasses */ | ||
963 | SND_SOC_DAPM_SWITCH_E("Right1 Analog Loopback", SND_SOC_NOPM, 0, 0, | ||
964 | &twl4030_dapm_abypassr1_control, bypass_event, | ||
965 | SND_SOC_DAPM_POST_REG), | ||
966 | SND_SOC_DAPM_SWITCH_E("Left1 Analog Loopback", SND_SOC_NOPM, 0, 0, | ||
967 | &twl4030_dapm_abypassl1_control, | ||
968 | bypass_event, SND_SOC_DAPM_POST_REG), | ||
969 | SND_SOC_DAPM_SWITCH_E("Right2 Analog Loopback", SND_SOC_NOPM, 0, 0, | ||
970 | &twl4030_dapm_abypassr2_control, | ||
971 | bypass_event, SND_SOC_DAPM_POST_REG), | ||
972 | SND_SOC_DAPM_SWITCH_E("Left2 Analog Loopback", SND_SOC_NOPM, 0, 0, | ||
973 | &twl4030_dapm_abypassl2_control, | ||
974 | bypass_event, SND_SOC_DAPM_POST_REG), | ||
975 | |||
976 | /* Digital bypasses */ | ||
977 | SND_SOC_DAPM_SWITCH_E("Left Digital Loopback", SND_SOC_NOPM, 0, 0, | ||
978 | &twl4030_dapm_dbypassl_control, bypass_event, | ||
979 | SND_SOC_DAPM_POST_REG), | ||
980 | SND_SOC_DAPM_SWITCH_E("Right Digital Loopback", SND_SOC_NOPM, 0, 0, | ||
981 | &twl4030_dapm_dbypassr_control, bypass_event, | ||
982 | SND_SOC_DAPM_POST_REG), | ||
983 | |||
984 | SND_SOC_DAPM_MIXER("Analog R1 Playback Mixer", TWL4030_REG_AVDAC_CTL, | ||
985 | 0, 0, NULL, 0), | ||
986 | SND_SOC_DAPM_MIXER("Analog L1 Playback Mixer", TWL4030_REG_AVDAC_CTL, | ||
987 | 1, 0, NULL, 0), | ||
988 | SND_SOC_DAPM_MIXER("Analog R2 Playback Mixer", TWL4030_REG_AVDAC_CTL, | ||
989 | 2, 0, NULL, 0), | ||
990 | SND_SOC_DAPM_MIXER("Analog L2 Playback Mixer", TWL4030_REG_AVDAC_CTL, | ||
991 | 3, 0, NULL, 0), | ||
992 | |||
735 | /* Output MUX controls */ | 993 | /* Output MUX controls */ |
736 | /* Earpiece */ | 994 | /* Earpiece */ |
737 | SND_SOC_DAPM_VALUE_MUX("Earpiece Mux", SND_SOC_NOPM, 0, 0, | 995 | SND_SOC_DAPM_VALUE_MUX("Earpiece Mux", SND_SOC_NOPM, 0, 0, |
@@ -742,8 +1000,9 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | |||
742 | SND_SOC_DAPM_VALUE_MUX("PredriveR Mux", SND_SOC_NOPM, 0, 0, | 1000 | SND_SOC_DAPM_VALUE_MUX("PredriveR Mux", SND_SOC_NOPM, 0, 0, |
743 | &twl4030_dapm_predriver_control), | 1001 | &twl4030_dapm_predriver_control), |
744 | /* HeadsetL/R */ | 1002 | /* HeadsetL/R */ |
745 | SND_SOC_DAPM_MUX("HeadsetL Mux", SND_SOC_NOPM, 0, 0, | 1003 | SND_SOC_DAPM_MUX_E("HeadsetL Mux", SND_SOC_NOPM, 0, 0, |
746 | &twl4030_dapm_hsol_control), | 1004 | &twl4030_dapm_hsol_control, headsetl_event, |
1005 | SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD), | ||
747 | SND_SOC_DAPM_MUX("HeadsetR Mux", SND_SOC_NOPM, 0, 0, | 1006 | SND_SOC_DAPM_MUX("HeadsetR Mux", SND_SOC_NOPM, 0, 0, |
748 | &twl4030_dapm_hsor_control), | 1007 | &twl4030_dapm_hsor_control), |
749 | /* CarkitL/R */ | 1008 | /* CarkitL/R */ |
@@ -782,16 +1041,16 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | |||
782 | SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD| | 1041 | SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD| |
783 | SND_SOC_DAPM_POST_REG), | 1042 | SND_SOC_DAPM_POST_REG), |
784 | 1043 | ||
785 | /* Analog input muxes with power switch for the physical ADCL/R */ | 1044 | /* Analog input muxes with switch for the capture amplifiers */ |
786 | SND_SOC_DAPM_VALUE_MUX("Analog Left Capture Route", | 1045 | SND_SOC_DAPM_VALUE_MUX("Analog Left Capture Route", |
787 | TWL4030_REG_AVADC_CTL, 3, 0, &twl4030_dapm_analoglmic_control), | 1046 | TWL4030_REG_ANAMICL, 4, 0, &twl4030_dapm_analoglmic_control), |
788 | SND_SOC_DAPM_VALUE_MUX("Analog Right Capture Route", | 1047 | SND_SOC_DAPM_VALUE_MUX("Analog Right Capture Route", |
789 | TWL4030_REG_AVADC_CTL, 1, 0, &twl4030_dapm_analogrmic_control), | 1048 | TWL4030_REG_ANAMICR, 4, 0, &twl4030_dapm_analogrmic_control), |
790 | 1049 | ||
791 | SND_SOC_DAPM_PGA("Analog Left Amplifier", | 1050 | SND_SOC_DAPM_PGA("ADC Physical Left", |
792 | TWL4030_REG_ANAMICL, 4, 0, NULL, 0), | 1051 | TWL4030_REG_AVADC_CTL, 3, 0, NULL, 0), |
793 | SND_SOC_DAPM_PGA("Analog Right Amplifier", | 1052 | SND_SOC_DAPM_PGA("ADC Physical Right", |
794 | TWL4030_REG_ANAMICR, 4, 0, NULL, 0), | 1053 | TWL4030_REG_AVADC_CTL, 1, 0, NULL, 0), |
795 | 1054 | ||
796 | SND_SOC_DAPM_PGA("Digimic0 Enable", | 1055 | SND_SOC_DAPM_PGA("Digimic0 Enable", |
797 | TWL4030_REG_ADCMICSEL, 1, 0, NULL, 0), | 1056 | TWL4030_REG_ADCMICSEL, 1, 0, NULL, 0), |
@@ -801,13 +1060,19 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { | |||
801 | SND_SOC_DAPM_MICBIAS("Mic Bias 1", TWL4030_REG_MICBIAS_CTL, 0, 0), | 1060 | SND_SOC_DAPM_MICBIAS("Mic Bias 1", TWL4030_REG_MICBIAS_CTL, 0, 0), |
802 | SND_SOC_DAPM_MICBIAS("Mic Bias 2", TWL4030_REG_MICBIAS_CTL, 1, 0), | 1061 | SND_SOC_DAPM_MICBIAS("Mic Bias 2", TWL4030_REG_MICBIAS_CTL, 1, 0), |
803 | SND_SOC_DAPM_MICBIAS("Headset Mic Bias", TWL4030_REG_MICBIAS_CTL, 2, 0), | 1062 | SND_SOC_DAPM_MICBIAS("Headset Mic Bias", TWL4030_REG_MICBIAS_CTL, 2, 0), |
1063 | |||
804 | }; | 1064 | }; |
805 | 1065 | ||
806 | static const struct snd_soc_dapm_route intercon[] = { | 1066 | static const struct snd_soc_dapm_route intercon[] = { |
807 | {"ARXL1_APGA", NULL, "DAC Left1"}, | 1067 | {"Analog L1 Playback Mixer", NULL, "DAC Left1"}, |
808 | {"ARXR1_APGA", NULL, "DAC Right1"}, | 1068 | {"Analog R1 Playback Mixer", NULL, "DAC Right1"}, |
809 | {"ARXL2_APGA", NULL, "DAC Left2"}, | 1069 | {"Analog L2 Playback Mixer", NULL, "DAC Left2"}, |
810 | {"ARXR2_APGA", NULL, "DAC Right2"}, | 1070 | {"Analog R2 Playback Mixer", NULL, "DAC Right2"}, |
1071 | |||
1072 | {"ARXL1_APGA", NULL, "Analog L1 Playback Mixer"}, | ||
1073 | {"ARXR1_APGA", NULL, "Analog R1 Playback Mixer"}, | ||
1074 | {"ARXL2_APGA", NULL, "Analog L2 Playback Mixer"}, | ||
1075 | {"ARXR2_APGA", NULL, "Analog R2 Playback Mixer"}, | ||
811 | 1076 | ||
812 | /* Internal playback routings */ | 1077 | /* Internal playback routings */ |
813 | /* Earpiece */ | 1078 | /* Earpiece */ |
@@ -865,23 +1130,23 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
865 | {"Analog Right Capture Route", "Sub mic", "SUBMIC"}, | 1130 | {"Analog Right Capture Route", "Sub mic", "SUBMIC"}, |
866 | {"Analog Right Capture Route", "AUXR", "AUXR"}, | 1131 | {"Analog Right Capture Route", "AUXR", "AUXR"}, |
867 | 1132 | ||
868 | {"Analog Left Amplifier", NULL, "Analog Left Capture Route"}, | 1133 | {"ADC Physical Left", NULL, "Analog Left Capture Route"}, |
869 | {"Analog Right Amplifier", NULL, "Analog Right Capture Route"}, | 1134 | {"ADC Physical Right", NULL, "Analog Right Capture Route"}, |
870 | 1135 | ||
871 | {"Digimic0 Enable", NULL, "DIGIMIC0"}, | 1136 | {"Digimic0 Enable", NULL, "DIGIMIC0"}, |
872 | {"Digimic1 Enable", NULL, "DIGIMIC1"}, | 1137 | {"Digimic1 Enable", NULL, "DIGIMIC1"}, |
873 | 1138 | ||
874 | /* TX1 Left capture path */ | 1139 | /* TX1 Left capture path */ |
875 | {"TX1 Capture Route", "Analog", "Analog Left Amplifier"}, | 1140 | {"TX1 Capture Route", "Analog", "ADC Physical Left"}, |
876 | {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"}, | 1141 | {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"}, |
877 | /* TX1 Right capture path */ | 1142 | /* TX1 Right capture path */ |
878 | {"TX1 Capture Route", "Analog", "Analog Right Amplifier"}, | 1143 | {"TX1 Capture Route", "Analog", "ADC Physical Right"}, |
879 | {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"}, | 1144 | {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"}, |
880 | /* TX2 Left capture path */ | 1145 | /* TX2 Left capture path */ |
881 | {"TX2 Capture Route", "Analog", "Analog Left Amplifier"}, | 1146 | {"TX2 Capture Route", "Analog", "ADC Physical Left"}, |
882 | {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"}, | 1147 | {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"}, |
883 | /* TX2 Right capture path */ | 1148 | /* TX2 Right capture path */ |
884 | {"TX2 Capture Route", "Analog", "Analog Right Amplifier"}, | 1149 | {"TX2 Capture Route", "Analog", "ADC Physical Right"}, |
885 | {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"}, | 1150 | {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"}, |
886 | 1151 | ||
887 | {"ADC Virtual Left1", NULL, "TX1 Capture Route"}, | 1152 | {"ADC Virtual Left1", NULL, "TX1 Capture Route"}, |
@@ -889,6 +1154,24 @@ static const struct snd_soc_dapm_route intercon[] = { | |||
889 | {"ADC Virtual Left2", NULL, "TX2 Capture Route"}, | 1154 | {"ADC Virtual Left2", NULL, "TX2 Capture Route"}, |
890 | {"ADC Virtual Right2", NULL, "TX2 Capture Route"}, | 1155 | {"ADC Virtual Right2", NULL, "TX2 Capture Route"}, |
891 | 1156 | ||
1157 | /* Analog bypass routes */ | ||
1158 | {"Right1 Analog Loopback", "Switch", "Analog Right Capture Route"}, | ||
1159 | {"Left1 Analog Loopback", "Switch", "Analog Left Capture Route"}, | ||
1160 | {"Right2 Analog Loopback", "Switch", "Analog Right Capture Route"}, | ||
1161 | {"Left2 Analog Loopback", "Switch", "Analog Left Capture Route"}, | ||
1162 | |||
1163 | {"Analog R1 Playback Mixer", NULL, "Right1 Analog Loopback"}, | ||
1164 | {"Analog L1 Playback Mixer", NULL, "Left1 Analog Loopback"}, | ||
1165 | {"Analog R2 Playback Mixer", NULL, "Right2 Analog Loopback"}, | ||
1166 | {"Analog L2 Playback Mixer", NULL, "Left2 Analog Loopback"}, | ||
1167 | |||
1168 | /* Digital bypass routes */ | ||
1169 | {"Right Digital Loopback", "Volume", "TX1 Capture Route"}, | ||
1170 | {"Left Digital Loopback", "Volume", "TX1 Capture Route"}, | ||
1171 | |||
1172 | {"Analog R2 Playback Mixer", NULL, "Right Digital Loopback"}, | ||
1173 | {"Analog L2 Playback Mixer", NULL, "Left Digital Loopback"}, | ||
1174 | |||
892 | }; | 1175 | }; |
893 | 1176 | ||
894 | static int twl4030_add_widgets(struct snd_soc_codec *codec) | 1177 | static int twl4030_add_widgets(struct snd_soc_codec *codec) |
@@ -902,82 +1185,28 @@ static int twl4030_add_widgets(struct snd_soc_codec *codec) | |||
902 | return 0; | 1185 | return 0; |
903 | } | 1186 | } |
904 | 1187 | ||
905 | static void twl4030_power_up(struct snd_soc_codec *codec) | ||
906 | { | ||
907 | u8 anamicl, regmisc1, byte, popn; | ||
908 | int i = 0; | ||
909 | |||
910 | /* set CODECPDZ to turn on codec */ | ||
911 | twl4030_set_codecpdz(codec); | ||
912 | |||
913 | /* initiate offset cancellation */ | ||
914 | anamicl = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICL); | ||
915 | twl4030_write(codec, TWL4030_REG_ANAMICL, | ||
916 | anamicl | TWL4030_CNCL_OFFSET_START); | ||
917 | |||
918 | |||
919 | /* wait for offset cancellation to complete */ | ||
920 | do { | ||
921 | /* this takes a little while, so don't slam i2c */ | ||
922 | udelay(2000); | ||
923 | twl4030_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte, | ||
924 | TWL4030_REG_ANAMICL); | ||
925 | } while ((i++ < 100) && | ||
926 | ((byte & TWL4030_CNCL_OFFSET_START) == | ||
927 | TWL4030_CNCL_OFFSET_START)); | ||
928 | |||
929 | /* anti-pop when changing analog gain */ | ||
930 | regmisc1 = twl4030_read_reg_cache(codec, TWL4030_REG_MISC_SET_1); | ||
931 | twl4030_write(codec, TWL4030_REG_MISC_SET_1, | ||
932 | regmisc1 | TWL4030_SMOOTH_ANAVOL_EN); | ||
933 | |||
934 | /* toggle CODECPDZ as per TRM */ | ||
935 | twl4030_clear_codecpdz(codec); | ||
936 | twl4030_set_codecpdz(codec); | ||
937 | |||
938 | /* program anti-pop with bias ramp delay */ | ||
939 | popn = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET); | ||
940 | popn &= TWL4030_RAMP_DELAY; | ||
941 | popn |= TWL4030_RAMP_DELAY_645MS; | ||
942 | twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn); | ||
943 | popn |= TWL4030_VMID_EN; | ||
944 | twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn); | ||
945 | |||
946 | /* enable anti-pop ramp */ | ||
947 | popn |= TWL4030_RAMP_EN; | ||
948 | twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn); | ||
949 | } | ||
950 | |||
951 | static void twl4030_power_down(struct snd_soc_codec *codec) | ||
952 | { | ||
953 | u8 popn; | ||
954 | |||
955 | /* disable anti-pop ramp */ | ||
956 | popn = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET); | ||
957 | popn &= ~TWL4030_RAMP_EN; | ||
958 | twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn); | ||
959 | |||
960 | /* disable bias out */ | ||
961 | popn &= ~TWL4030_VMID_EN; | ||
962 | twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn); | ||
963 | |||
964 | /* power down */ | ||
965 | twl4030_clear_codecpdz(codec); | ||
966 | } | ||
967 | |||
968 | static int twl4030_set_bias_level(struct snd_soc_codec *codec, | 1188 | static int twl4030_set_bias_level(struct snd_soc_codec *codec, |
969 | enum snd_soc_bias_level level) | 1189 | enum snd_soc_bias_level level) |
970 | { | 1190 | { |
1191 | struct twl4030_priv *twl4030 = codec->private_data; | ||
1192 | |||
971 | switch (level) { | 1193 | switch (level) { |
972 | case SND_SOC_BIAS_ON: | 1194 | case SND_SOC_BIAS_ON: |
973 | twl4030_power_up(codec); | 1195 | twl4030_codec_mute(codec, 0); |
974 | break; | 1196 | break; |
975 | case SND_SOC_BIAS_PREPARE: | 1197 | case SND_SOC_BIAS_PREPARE: |
976 | /* TODO: develop a twl4030_prepare function */ | 1198 | twl4030_power_up(codec); |
1199 | if (twl4030->bypass_state) | ||
1200 | twl4030_codec_mute(codec, 0); | ||
1201 | else | ||
1202 | twl4030_codec_mute(codec, 1); | ||
977 | break; | 1203 | break; |
978 | case SND_SOC_BIAS_STANDBY: | 1204 | case SND_SOC_BIAS_STANDBY: |
979 | /* TODO: develop a twl4030_standby function */ | 1205 | twl4030_power_up(codec); |
980 | twl4030_power_down(codec); | 1206 | if (twl4030->bypass_state) |
1207 | twl4030_codec_mute(codec, 0); | ||
1208 | else | ||
1209 | twl4030_codec_mute(codec, 1); | ||
981 | break; | 1210 | break; |
982 | case SND_SOC_BIAS_OFF: | 1211 | case SND_SOC_BIAS_OFF: |
983 | twl4030_power_down(codec); | 1212 | twl4030_power_down(codec); |
@@ -994,10 +1223,9 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream, | |||
994 | { | 1223 | { |
995 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1224 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
996 | struct snd_soc_device *socdev = rtd->socdev; | 1225 | struct snd_soc_device *socdev = rtd->socdev; |
997 | struct snd_soc_codec *codec = socdev->codec; | 1226 | struct snd_soc_codec *codec = socdev->card->codec; |
998 | u8 mode, old_mode, format, old_format; | 1227 | u8 mode, old_mode, format, old_format; |
999 | 1228 | ||
1000 | |||
1001 | /* bit rate */ | 1229 | /* bit rate */ |
1002 | old_mode = twl4030_read_reg_cache(codec, | 1230 | old_mode = twl4030_read_reg_cache(codec, |
1003 | TWL4030_REG_CODEC_MODE) & ~TWL4030_CODECPDZ; | 1231 | TWL4030_REG_CODEC_MODE) & ~TWL4030_CODECPDZ; |
@@ -1039,8 +1267,9 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream, | |||
1039 | 1267 | ||
1040 | if (mode != old_mode) { | 1268 | if (mode != old_mode) { |
1041 | /* change rate and set CODECPDZ */ | 1269 | /* change rate and set CODECPDZ */ |
1270 | twl4030_codec_enable(codec, 0); | ||
1042 | twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode); | 1271 | twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode); |
1043 | twl4030_set_codecpdz(codec); | 1272 | twl4030_codec_enable(codec, 1); |
1044 | } | 1273 | } |
1045 | 1274 | ||
1046 | /* sample size */ | 1275 | /* sample size */ |
@@ -1063,13 +1292,13 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream, | |||
1063 | if (format != old_format) { | 1292 | if (format != old_format) { |
1064 | 1293 | ||
1065 | /* clear CODECPDZ before changing format (codec requirement) */ | 1294 | /* clear CODECPDZ before changing format (codec requirement) */ |
1066 | twl4030_clear_codecpdz(codec); | 1295 | twl4030_codec_enable(codec, 0); |
1067 | 1296 | ||
1068 | /* change format */ | 1297 | /* change format */ |
1069 | twl4030_write(codec, TWL4030_REG_AUDIO_IF, format); | 1298 | twl4030_write(codec, TWL4030_REG_AUDIO_IF, format); |
1070 | 1299 | ||
1071 | /* set CODECPDZ afterwards */ | 1300 | /* set CODECPDZ afterwards */ |
1072 | twl4030_set_codecpdz(codec); | 1301 | twl4030_codec_enable(codec, 1); |
1073 | } | 1302 | } |
1074 | return 0; | 1303 | return 0; |
1075 | } | 1304 | } |
@@ -1139,13 +1368,13 @@ static int twl4030_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
1139 | if (format != old_format) { | 1368 | if (format != old_format) { |
1140 | 1369 | ||
1141 | /* clear CODECPDZ before changing format (codec requirement) */ | 1370 | /* clear CODECPDZ before changing format (codec requirement) */ |
1142 | twl4030_clear_codecpdz(codec); | 1371 | twl4030_codec_enable(codec, 0); |
1143 | 1372 | ||
1144 | /* change format */ | 1373 | /* change format */ |
1145 | twl4030_write(codec, TWL4030_REG_AUDIO_IF, format); | 1374 | twl4030_write(codec, TWL4030_REG_AUDIO_IF, format); |
1146 | 1375 | ||
1147 | /* set CODECPDZ afterwards */ | 1376 | /* set CODECPDZ afterwards */ |
1148 | twl4030_set_codecpdz(codec); | 1377 | twl4030_codec_enable(codec, 1); |
1149 | } | 1378 | } |
1150 | 1379 | ||
1151 | return 0; | 1380 | return 0; |
@@ -1154,6 +1383,12 @@ static int twl4030_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
1154 | #define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000) | 1383 | #define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000) |
1155 | #define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_S24_LE) | 1384 | #define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_S24_LE) |
1156 | 1385 | ||
1386 | static struct snd_soc_dai_ops twl4030_dai_ops = { | ||
1387 | .hw_params = twl4030_hw_params, | ||
1388 | .set_sysclk = twl4030_set_dai_sysclk, | ||
1389 | .set_fmt = twl4030_set_dai_fmt, | ||
1390 | }; | ||
1391 | |||
1157 | struct snd_soc_dai twl4030_dai = { | 1392 | struct snd_soc_dai twl4030_dai = { |
1158 | .name = "twl4030", | 1393 | .name = "twl4030", |
1159 | .playback = { | 1394 | .playback = { |
@@ -1168,18 +1403,14 @@ struct snd_soc_dai twl4030_dai = { | |||
1168 | .channels_max = 2, | 1403 | .channels_max = 2, |
1169 | .rates = TWL4030_RATES, | 1404 | .rates = TWL4030_RATES, |
1170 | .formats = TWL4030_FORMATS,}, | 1405 | .formats = TWL4030_FORMATS,}, |
1171 | .ops = { | 1406 | .ops = &twl4030_dai_ops, |
1172 | .hw_params = twl4030_hw_params, | ||
1173 | .set_sysclk = twl4030_set_dai_sysclk, | ||
1174 | .set_fmt = twl4030_set_dai_fmt, | ||
1175 | } | ||
1176 | }; | 1407 | }; |
1177 | EXPORT_SYMBOL_GPL(twl4030_dai); | 1408 | EXPORT_SYMBOL_GPL(twl4030_dai); |
1178 | 1409 | ||
1179 | static int twl4030_suspend(struct platform_device *pdev, pm_message_t state) | 1410 | static int twl4030_suspend(struct platform_device *pdev, pm_message_t state) |
1180 | { | 1411 | { |
1181 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1412 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1182 | struct snd_soc_codec *codec = socdev->codec; | 1413 | struct snd_soc_codec *codec = socdev->card->codec; |
1183 | 1414 | ||
1184 | twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF); | 1415 | twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF); |
1185 | 1416 | ||
@@ -1189,7 +1420,7 @@ static int twl4030_suspend(struct platform_device *pdev, pm_message_t state) | |||
1189 | static int twl4030_resume(struct platform_device *pdev) | 1420 | static int twl4030_resume(struct platform_device *pdev) |
1190 | { | 1421 | { |
1191 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1422 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1192 | struct snd_soc_codec *codec = socdev->codec; | 1423 | struct snd_soc_codec *codec = socdev->card->codec; |
1193 | 1424 | ||
1194 | twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 1425 | twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
1195 | twl4030_set_bias_level(codec, codec->suspend_bias_level); | 1426 | twl4030_set_bias_level(codec, codec->suspend_bias_level); |
@@ -1203,7 +1434,7 @@ static int twl4030_resume(struct platform_device *pdev) | |||
1203 | 1434 | ||
1204 | static int twl4030_init(struct snd_soc_device *socdev) | 1435 | static int twl4030_init(struct snd_soc_device *socdev) |
1205 | { | 1436 | { |
1206 | struct snd_soc_codec *codec = socdev->codec; | 1437 | struct snd_soc_codec *codec = socdev->card->codec; |
1207 | int ret = 0; | 1438 | int ret = 0; |
1208 | 1439 | ||
1209 | printk(KERN_INFO "TWL4030 Audio Codec init \n"); | 1440 | printk(KERN_INFO "TWL4030 Audio Codec init \n"); |
@@ -1233,7 +1464,8 @@ static int twl4030_init(struct snd_soc_device *socdev) | |||
1233 | /* power on device */ | 1464 | /* power on device */ |
1234 | twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 1465 | twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
1235 | 1466 | ||
1236 | twl4030_add_controls(codec); | 1467 | snd_soc_add_controls(codec, twl4030_snd_controls, |
1468 | ARRAY_SIZE(twl4030_snd_controls)); | ||
1237 | twl4030_add_widgets(codec); | 1469 | twl4030_add_widgets(codec); |
1238 | 1470 | ||
1239 | ret = snd_soc_init_card(socdev); | 1471 | ret = snd_soc_init_card(socdev); |
@@ -1258,12 +1490,20 @@ static int twl4030_probe(struct platform_device *pdev) | |||
1258 | { | 1490 | { |
1259 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1491 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1260 | struct snd_soc_codec *codec; | 1492 | struct snd_soc_codec *codec; |
1493 | struct twl4030_priv *twl4030; | ||
1261 | 1494 | ||
1262 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | 1495 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
1263 | if (codec == NULL) | 1496 | if (codec == NULL) |
1264 | return -ENOMEM; | 1497 | return -ENOMEM; |
1265 | 1498 | ||
1266 | socdev->codec = codec; | 1499 | twl4030 = kzalloc(sizeof(struct twl4030_priv), GFP_KERNEL); |
1500 | if (twl4030 == NULL) { | ||
1501 | kfree(codec); | ||
1502 | return -ENOMEM; | ||
1503 | } | ||
1504 | |||
1505 | codec->private_data = twl4030; | ||
1506 | socdev->card->codec = codec; | ||
1267 | mutex_init(&codec->mutex); | 1507 | mutex_init(&codec->mutex); |
1268 | INIT_LIST_HEAD(&codec->dapm_widgets); | 1508 | INIT_LIST_HEAD(&codec->dapm_widgets); |
1269 | INIT_LIST_HEAD(&codec->dapm_paths); | 1509 | INIT_LIST_HEAD(&codec->dapm_paths); |
@@ -1277,11 +1517,13 @@ static int twl4030_probe(struct platform_device *pdev) | |||
1277 | static int twl4030_remove(struct platform_device *pdev) | 1517 | static int twl4030_remove(struct platform_device *pdev) |
1278 | { | 1518 | { |
1279 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1519 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1280 | struct snd_soc_codec *codec = socdev->codec; | 1520 | struct snd_soc_codec *codec = socdev->card->codec; |
1281 | 1521 | ||
1282 | printk(KERN_INFO "TWL4030 Audio Codec remove\n"); | 1522 | printk(KERN_INFO "TWL4030 Audio Codec remove\n"); |
1523 | twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
1283 | snd_soc_free_pcms(socdev); | 1524 | snd_soc_free_pcms(socdev); |
1284 | snd_soc_dapm_free(socdev); | 1525 | snd_soc_dapm_free(socdev); |
1526 | kfree(codec->private_data); | ||
1285 | kfree(codec); | 1527 | kfree(codec); |
1286 | 1528 | ||
1287 | return 0; | 1529 | return 0; |
diff --git a/sound/soc/codecs/twl4030.h b/sound/soc/codecs/twl4030.h index 442e5a828617..33dbb144dad1 100644 --- a/sound/soc/codecs/twl4030.h +++ b/sound/soc/codecs/twl4030.h | |||
@@ -170,6 +170,9 @@ | |||
170 | #define TWL4030_CLK256FS_EN 0x02 | 170 | #define TWL4030_CLK256FS_EN 0x02 |
171 | #define TWL4030_AIF_EN 0x01 | 171 | #define TWL4030_AIF_EN 0x01 |
172 | 172 | ||
173 | /* EAR_CTL (0x21) */ | ||
174 | #define TWL4030_EAR_GAIN 0x30 | ||
175 | |||
173 | /* HS_GAIN_SET (0x23) Fields */ | 176 | /* HS_GAIN_SET (0x23) Fields */ |
174 | 177 | ||
175 | #define TWL4030_HSR_GAIN 0x0C | 178 | #define TWL4030_HSR_GAIN 0x0C |
@@ -198,6 +201,18 @@ | |||
198 | #define TWL4030_RAMP_DELAY_2581MS 0x1C | 201 | #define TWL4030_RAMP_DELAY_2581MS 0x1C |
199 | #define TWL4030_RAMP_EN 0x02 | 202 | #define TWL4030_RAMP_EN 0x02 |
200 | 203 | ||
204 | /* PREDL_CTL (0x25) */ | ||
205 | #define TWL4030_PREDL_GAIN 0x30 | ||
206 | |||
207 | /* PREDR_CTL (0x26) */ | ||
208 | #define TWL4030_PREDR_GAIN 0x30 | ||
209 | |||
210 | /* PRECKL_CTL (0x27) */ | ||
211 | #define TWL4030_PRECKL_GAIN 0x30 | ||
212 | |||
213 | /* PRECKR_CTL (0x28) */ | ||
214 | #define TWL4030_PRECKR_GAIN 0x30 | ||
215 | |||
201 | /* HFL_CTL (0x29, 0x2A) Fields */ | 216 | /* HFL_CTL (0x29, 0x2A) Fields */ |
202 | #define TWL4030_HF_CTL_HB_EN 0x04 | 217 | #define TWL4030_HF_CTL_HB_EN 0x04 |
203 | #define TWL4030_HF_CTL_LOOP_EN 0x08 | 218 | #define TWL4030_HF_CTL_LOOP_EN 0x08 |
diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c index a2c5064a774b..ddefb8f80145 100644 --- a/sound/soc/codecs/uda134x.c +++ b/sound/soc/codecs/uda134x.c | |||
@@ -173,7 +173,7 @@ static int uda134x_startup(struct snd_pcm_substream *substream, | |||
173 | { | 173 | { |
174 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 174 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
175 | struct snd_soc_device *socdev = rtd->socdev; | 175 | struct snd_soc_device *socdev = rtd->socdev; |
176 | struct snd_soc_codec *codec = socdev->codec; | 176 | struct snd_soc_codec *codec = socdev->card->codec; |
177 | struct uda134x_priv *uda134x = codec->private_data; | 177 | struct uda134x_priv *uda134x = codec->private_data; |
178 | struct snd_pcm_runtime *master_runtime; | 178 | struct snd_pcm_runtime *master_runtime; |
179 | 179 | ||
@@ -206,7 +206,7 @@ static void uda134x_shutdown(struct snd_pcm_substream *substream, | |||
206 | { | 206 | { |
207 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 207 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
208 | struct snd_soc_device *socdev = rtd->socdev; | 208 | struct snd_soc_device *socdev = rtd->socdev; |
209 | struct snd_soc_codec *codec = socdev->codec; | 209 | struct snd_soc_codec *codec = socdev->card->codec; |
210 | struct uda134x_priv *uda134x = codec->private_data; | 210 | struct uda134x_priv *uda134x = codec->private_data; |
211 | 211 | ||
212 | if (uda134x->master_substream == substream) | 212 | if (uda134x->master_substream == substream) |
@@ -221,7 +221,7 @@ static int uda134x_hw_params(struct snd_pcm_substream *substream, | |||
221 | { | 221 | { |
222 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 222 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
223 | struct snd_soc_device *socdev = rtd->socdev; | 223 | struct snd_soc_device *socdev = rtd->socdev; |
224 | struct snd_soc_codec *codec = socdev->codec; | 224 | struct snd_soc_codec *codec = socdev->card->codec; |
225 | struct uda134x_priv *uda134x = codec->private_data; | 225 | struct uda134x_priv *uda134x = codec->private_data; |
226 | u8 hw_params; | 226 | u8 hw_params; |
227 | 227 | ||
@@ -431,38 +431,14 @@ SOC_ENUM("PCM Playback De-emphasis", uda134x_mixer_enum[1]), | |||
431 | SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0), | 431 | SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0), |
432 | }; | 432 | }; |
433 | 433 | ||
434 | static int uda134x_add_controls(struct snd_soc_codec *codec) | 434 | static struct snd_soc_dai_ops uda134x_dai_ops = { |
435 | { | 435 | .startup = uda134x_startup, |
436 | int err, i, n; | 436 | .shutdown = uda134x_shutdown, |
437 | const struct snd_kcontrol_new *ctrls; | 437 | .hw_params = uda134x_hw_params, |
438 | struct uda134x_platform_data *pd = codec->control_data; | 438 | .digital_mute = uda134x_mute, |
439 | 439 | .set_sysclk = uda134x_set_dai_sysclk, | |
440 | switch (pd->model) { | 440 | .set_fmt = uda134x_set_dai_fmt, |
441 | case UDA134X_UDA1340: | 441 | }; |
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 | 442 | ||
467 | struct snd_soc_dai uda134x_dai = { | 443 | struct snd_soc_dai uda134x_dai = { |
468 | .name = "UDA134X", | 444 | .name = "UDA134X", |
@@ -483,14 +459,7 @@ struct snd_soc_dai uda134x_dai = { | |||
483 | .formats = UDA134X_FORMATS, | 459 | .formats = UDA134X_FORMATS, |
484 | }, | 460 | }, |
485 | /* pcm operations */ | 461 | /* pcm operations */ |
486 | .ops = { | 462 | .ops = &uda134x_dai_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 | }; | 463 | }; |
495 | EXPORT_SYMBOL(uda134x_dai); | 464 | EXPORT_SYMBOL(uda134x_dai); |
496 | 465 | ||
@@ -525,11 +494,11 @@ static int uda134x_soc_probe(struct platform_device *pdev) | |||
525 | return -EINVAL; | 494 | return -EINVAL; |
526 | } | 495 | } |
527 | 496 | ||
528 | socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | 497 | socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
529 | if (socdev->codec == NULL) | 498 | if (socdev->card->codec == NULL) |
530 | return ret; | 499 | return ret; |
531 | 500 | ||
532 | codec = socdev->codec; | 501 | codec = socdev->card->codec; |
533 | 502 | ||
534 | uda134x = kzalloc(sizeof(struct uda134x_priv), GFP_KERNEL); | 503 | uda134x = kzalloc(sizeof(struct uda134x_priv), GFP_KERNEL); |
535 | if (uda134x == NULL) | 504 | if (uda134x == NULL) |
@@ -572,7 +541,22 @@ static int uda134x_soc_probe(struct platform_device *pdev) | |||
572 | goto pcm_err; | 541 | goto pcm_err; |
573 | } | 542 | } |
574 | 543 | ||
575 | ret = uda134x_add_controls(codec); | 544 | switch (pd->model) { |
545 | case UDA134X_UDA1340: | ||
546 | case UDA134X_UDA1344: | ||
547 | ret = snd_soc_add_controls(codec, uda1340_snd_controls, | ||
548 | ARRAY_SIZE(uda1340_snd_controls)); | ||
549 | break; | ||
550 | case UDA134X_UDA1341: | ||
551 | ret = snd_soc_add_controls(codec, uda1341_snd_controls, | ||
552 | ARRAY_SIZE(uda1341_snd_controls)); | ||
553 | break; | ||
554 | default: | ||
555 | printk(KERN_ERR "%s unkown codec type: %d", | ||
556 | __func__, pd->model); | ||
557 | return -EINVAL; | ||
558 | } | ||
559 | |||
576 | if (ret < 0) { | 560 | if (ret < 0) { |
577 | printk(KERN_ERR "UDA134X: failed to register controls\n"); | 561 | printk(KERN_ERR "UDA134X: failed to register controls\n"); |
578 | goto pcm_err; | 562 | goto pcm_err; |
@@ -602,7 +586,7 @@ priv_err: | |||
602 | static int uda134x_soc_remove(struct platform_device *pdev) | 586 | static int uda134x_soc_remove(struct platform_device *pdev) |
603 | { | 587 | { |
604 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 588 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
605 | struct snd_soc_codec *codec = socdev->codec; | 589 | struct snd_soc_codec *codec = socdev->card->codec; |
606 | 590 | ||
607 | uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 591 | uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
608 | uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF); | 592 | uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF); |
@@ -622,7 +606,7 @@ static int uda134x_soc_suspend(struct platform_device *pdev, | |||
622 | pm_message_t state) | 606 | pm_message_t state) |
623 | { | 607 | { |
624 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 608 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
625 | struct snd_soc_codec *codec = socdev->codec; | 609 | struct snd_soc_codec *codec = socdev->card->codec; |
626 | 610 | ||
627 | uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 611 | uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
628 | uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF); | 612 | uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF); |
@@ -632,7 +616,7 @@ static int uda134x_soc_suspend(struct platform_device *pdev, | |||
632 | static int uda134x_soc_resume(struct platform_device *pdev) | 616 | static int uda134x_soc_resume(struct platform_device *pdev) |
633 | { | 617 | { |
634 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 618 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
635 | struct snd_soc_codec *codec = socdev->codec; | 619 | struct snd_soc_codec *codec = socdev->card->codec; |
636 | 620 | ||
637 | uda134x_set_bias_level(codec, SND_SOC_BIAS_PREPARE); | 621 | uda134x_set_bias_level(codec, SND_SOC_BIAS_PREPARE); |
638 | uda134x_set_bias_level(codec, SND_SOC_BIAS_ON); | 622 | uda134x_set_bias_level(codec, SND_SOC_BIAS_ON); |
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c index e6bf0844fbf3..5b21594e0e58 100644 --- a/sound/soc/codecs/uda1380.c +++ b/sound/soc/codecs/uda1380.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/ioctl.h> | 25 | #include <linux/ioctl.h> |
26 | #include <linux/delay.h> | 26 | #include <linux/delay.h> |
27 | #include <linux/i2c.h> | 27 | #include <linux/i2c.h> |
28 | #include <linux/workqueue.h> | ||
28 | #include <sound/core.h> | 29 | #include <sound/core.h> |
29 | #include <sound/control.h> | 30 | #include <sound/control.h> |
30 | #include <sound/initval.h> | 31 | #include <sound/initval.h> |
@@ -35,7 +36,8 @@ | |||
35 | 36 | ||
36 | #include "uda1380.h" | 37 | #include "uda1380.h" |
37 | 38 | ||
38 | #define UDA1380_VERSION "0.6" | 39 | static struct work_struct uda1380_work; |
40 | static struct snd_soc_codec *uda1380_codec; | ||
39 | 41 | ||
40 | /* | 42 | /* |
41 | * uda1380 register cache | 43 | * uda1380 register cache |
@@ -52,6 +54,8 @@ static const u16 uda1380_reg[UDA1380_CACHEREGNUM] = { | |||
52 | 0x0000, 0x8000, 0x0002, 0x0000, | 54 | 0x0000, 0x8000, 0x0002, 0x0000, |
53 | }; | 55 | }; |
54 | 56 | ||
57 | static unsigned long uda1380_cache_dirty; | ||
58 | |||
55 | /* | 59 | /* |
56 | * read uda1380 register cache | 60 | * read uda1380 register cache |
57 | */ | 61 | */ |
@@ -73,8 +77,11 @@ static inline void uda1380_write_reg_cache(struct snd_soc_codec *codec, | |||
73 | u16 reg, unsigned int value) | 77 | u16 reg, unsigned int value) |
74 | { | 78 | { |
75 | u16 *cache = codec->reg_cache; | 79 | u16 *cache = codec->reg_cache; |
80 | |||
76 | if (reg >= UDA1380_CACHEREGNUM) | 81 | if (reg >= UDA1380_CACHEREGNUM) |
77 | return; | 82 | return; |
83 | if ((reg >= 0x10) && (cache[reg] != value)) | ||
84 | set_bit(reg - 0x10, &uda1380_cache_dirty); | ||
78 | cache[reg] = value; | 85 | cache[reg] = value; |
79 | } | 86 | } |
80 | 87 | ||
@@ -113,6 +120,8 @@ static int uda1380_write(struct snd_soc_codec *codec, unsigned int reg, | |||
113 | (data[0]<<8) | data[1]); | 120 | (data[0]<<8) | data[1]); |
114 | return -EIO; | 121 | return -EIO; |
115 | } | 122 | } |
123 | if (reg >= 0x10) | ||
124 | clear_bit(reg - 0x10, &uda1380_cache_dirty); | ||
116 | return 0; | 125 | return 0; |
117 | } else | 126 | } else |
118 | return -EIO; | 127 | return -EIO; |
@@ -120,6 +129,20 @@ static int uda1380_write(struct snd_soc_codec *codec, unsigned int reg, | |||
120 | 129 | ||
121 | #define uda1380_reset(c) uda1380_write(c, UDA1380_RESET, 0) | 130 | #define uda1380_reset(c) uda1380_write(c, UDA1380_RESET, 0) |
122 | 131 | ||
132 | static void uda1380_flush_work(struct work_struct *work) | ||
133 | { | ||
134 | int bit, reg; | ||
135 | |||
136 | for_each_bit(bit, &uda1380_cache_dirty, UDA1380_CACHEREGNUM - 0x10) { | ||
137 | reg = 0x10 + bit; | ||
138 | pr_debug("uda1380: flush reg %x val %x:\n", reg, | ||
139 | uda1380_read_reg_cache(uda1380_codec, reg)); | ||
140 | uda1380_write(uda1380_codec, reg, | ||
141 | uda1380_read_reg_cache(uda1380_codec, reg)); | ||
142 | clear_bit(bit, &uda1380_cache_dirty); | ||
143 | } | ||
144 | } | ||
145 | |||
123 | /* declarations of ALSA reg_elem_REAL controls */ | 146 | /* declarations of ALSA reg_elem_REAL controls */ |
124 | static const char *uda1380_deemp[] = { | 147 | static const char *uda1380_deemp[] = { |
125 | "None", | 148 | "None", |
@@ -254,7 +277,6 @@ static const struct snd_kcontrol_new uda1380_snd_controls[] = { | |||
254 | SOC_SINGLE("DAC Polarity inverting Switch", UDA1380_MIXER, 15, 1, 0), /* DA_POL_INV */ | 277 | SOC_SINGLE("DAC Polarity inverting Switch", UDA1380_MIXER, 15, 1, 0), /* DA_POL_INV */ |
255 | SOC_ENUM("Noise Shaper", uda1380_sel_ns_enum), /* SEL_NS */ | 278 | SOC_ENUM("Noise Shaper", uda1380_sel_ns_enum), /* SEL_NS */ |
256 | SOC_ENUM("Digital Mixer Signal Control", uda1380_mix_enum), /* MIX_POS, MIX */ | 279 | SOC_ENUM("Digital Mixer Signal Control", uda1380_mix_enum), /* MIX_POS, MIX */ |
257 | SOC_SINGLE("Silence Switch", UDA1380_MIXER, 7, 1, 0), /* SILENCE, force DAC output to silence */ | ||
258 | SOC_SINGLE("Silence Detector Switch", UDA1380_MIXER, 6, 1, 0), /* SDET_ON */ | 280 | SOC_SINGLE("Silence Detector Switch", UDA1380_MIXER, 6, 1, 0), /* SDET_ON */ |
259 | SOC_ENUM("Silence Detector Setting", uda1380_sdet_enum), /* SD_VALUE */ | 281 | SOC_ENUM("Silence Detector Setting", uda1380_sdet_enum), /* SD_VALUE */ |
260 | SOC_ENUM("Oversampling Input", uda1380_os_enum), /* OS */ | 282 | SOC_ENUM("Oversampling Input", uda1380_os_enum), /* OS */ |
@@ -271,21 +293,6 @@ static const struct snd_kcontrol_new uda1380_snd_controls[] = { | |||
271 | SOC_SINGLE("AGC Switch", UDA1380_AGC, 0, 1, 0), | 293 | SOC_SINGLE("AGC Switch", UDA1380_AGC, 0, 1, 0), |
272 | }; | 294 | }; |
273 | 295 | ||
274 | /* add non dapm controls */ | ||
275 | static int uda1380_add_controls(struct snd_soc_codec *codec) | ||
276 | { | ||
277 | int err, i; | ||
278 | |||
279 | for (i = 0; i < ARRAY_SIZE(uda1380_snd_controls); i++) { | ||
280 | err = snd_ctl_add(codec->card, | ||
281 | snd_soc_cnew(&uda1380_snd_controls[i], codec, NULL)); | ||
282 | if (err < 0) | ||
283 | return err; | ||
284 | } | ||
285 | |||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | /* Input mux */ | 296 | /* Input mux */ |
290 | static const struct snd_kcontrol_new uda1380_input_mux_control = | 297 | static const struct snd_kcontrol_new uda1380_input_mux_control = |
291 | SOC_DAPM_ENUM("Route", uda1380_input_sel_enum); | 298 | SOC_DAPM_ENUM("Route", uda1380_input_sel_enum); |
@@ -371,7 +378,7 @@ static int uda1380_add_widgets(struct snd_soc_codec *codec) | |||
371 | return 0; | 378 | return 0; |
372 | } | 379 | } |
373 | 380 | ||
374 | static int uda1380_set_dai_fmt(struct snd_soc_dai *codec_dai, | 381 | static int uda1380_set_dai_fmt_both(struct snd_soc_dai *codec_dai, |
375 | unsigned int fmt) | 382 | unsigned int fmt) |
376 | { | 383 | { |
377 | struct snd_soc_codec *codec = codec_dai->codec; | 384 | struct snd_soc_codec *codec = codec_dai->codec; |
@@ -381,61 +388,107 @@ static int uda1380_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
381 | iface = uda1380_read_reg_cache(codec, UDA1380_IFACE); | 388 | iface = uda1380_read_reg_cache(codec, UDA1380_IFACE); |
382 | iface &= ~(R01_SFORI_MASK | R01_SIM | R01_SFORO_MASK); | 389 | iface &= ~(R01_SFORI_MASK | R01_SIM | R01_SFORO_MASK); |
383 | 390 | ||
384 | /* FIXME: how to select I2S for DATAO and MSB for DATAI correctly? */ | ||
385 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | 391 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
386 | case SND_SOC_DAIFMT_I2S: | 392 | case SND_SOC_DAIFMT_I2S: |
387 | iface |= R01_SFORI_I2S | R01_SFORO_I2S; | 393 | iface |= R01_SFORI_I2S | R01_SFORO_I2S; |
388 | break; | 394 | break; |
389 | case SND_SOC_DAIFMT_LSB: | 395 | case SND_SOC_DAIFMT_LSB: |
390 | iface |= R01_SFORI_LSB16 | R01_SFORO_I2S; | 396 | iface |= R01_SFORI_LSB16 | R01_SFORO_LSB16; |
391 | break; | 397 | break; |
392 | case SND_SOC_DAIFMT_MSB: | 398 | case SND_SOC_DAIFMT_MSB: |
393 | iface |= R01_SFORI_MSB | R01_SFORO_I2S; | 399 | iface |= R01_SFORI_MSB | R01_SFORO_MSB; |
394 | } | 400 | } |
395 | 401 | ||
396 | if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBM_CFM) | 402 | /* DATAI is slave only, so in single-link mode, this has to be slave */ |
397 | iface |= R01_SIM; | 403 | if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) |
404 | return -EINVAL; | ||
398 | 405 | ||
399 | uda1380_write(codec, UDA1380_IFACE, iface); | 406 | uda1380_write(codec, UDA1380_IFACE, iface); |
400 | 407 | ||
401 | return 0; | 408 | return 0; |
402 | } | 409 | } |
403 | 410 | ||
404 | /* | 411 | static int uda1380_set_dai_fmt_playback(struct snd_soc_dai *codec_dai, |
405 | * Flush reg cache | 412 | unsigned int fmt) |
406 | * We can only write the interpolator and decimator registers | ||
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. | ||
409 | */ | ||
410 | static int uda1380_pcm_prepare(struct snd_pcm_substream *substream, | ||
411 | struct snd_soc_dai *dai) | ||
412 | { | 413 | { |
413 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 414 | struct snd_soc_codec *codec = codec_dai->codec; |
414 | struct snd_soc_device *socdev = rtd->socdev; | 415 | int iface; |
415 | struct snd_soc_codec *codec = socdev->codec; | 416 | |
416 | int reg, reg_start, reg_end, clk; | 417 | /* set up DAI based upon fmt */ |
417 | 418 | iface = uda1380_read_reg_cache(codec, UDA1380_IFACE); | |
418 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | 419 | iface &= ~R01_SFORI_MASK; |
419 | reg_start = UDA1380_MVOL; | 420 | |
420 | reg_end = UDA1380_MIXER; | 421 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
421 | } else { | 422 | case SND_SOC_DAIFMT_I2S: |
422 | reg_start = UDA1380_DEC; | 423 | iface |= R01_SFORI_I2S; |
423 | reg_end = UDA1380_AGC; | 424 | break; |
425 | case SND_SOC_DAIFMT_LSB: | ||
426 | iface |= R01_SFORI_LSB16; | ||
427 | break; | ||
428 | case SND_SOC_DAIFMT_MSB: | ||
429 | iface |= R01_SFORI_MSB; | ||
424 | } | 430 | } |
425 | 431 | ||
426 | /* FIXME disable DAC_CLK */ | 432 | /* DATAI is slave only, so this has to be slave */ |
427 | clk = uda1380_read_reg_cache(codec, UDA1380_CLK); | 433 | if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) |
428 | uda1380_write(codec, UDA1380_CLK, clk & ~R00_DAC_CLK); | 434 | return -EINVAL; |
435 | |||
436 | uda1380_write(codec, UDA1380_IFACE, iface); | ||
437 | |||
438 | return 0; | ||
439 | } | ||
440 | |||
441 | static int uda1380_set_dai_fmt_capture(struct snd_soc_dai *codec_dai, | ||
442 | unsigned int fmt) | ||
443 | { | ||
444 | struct snd_soc_codec *codec = codec_dai->codec; | ||
445 | int iface; | ||
446 | |||
447 | /* set up DAI based upon fmt */ | ||
448 | iface = uda1380_read_reg_cache(codec, UDA1380_IFACE); | ||
449 | iface &= ~(R01_SIM | R01_SFORO_MASK); | ||
429 | 450 | ||
430 | for (reg = reg_start; reg <= reg_end; reg++) { | 451 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
431 | pr_debug("uda1380: flush reg %x val %x:", reg, | 452 | case SND_SOC_DAIFMT_I2S: |
432 | uda1380_read_reg_cache(codec, reg)); | 453 | iface |= R01_SFORO_I2S; |
433 | uda1380_write(codec, reg, uda1380_read_reg_cache(codec, reg)); | 454 | break; |
455 | case SND_SOC_DAIFMT_LSB: | ||
456 | iface |= R01_SFORO_LSB16; | ||
457 | break; | ||
458 | case SND_SOC_DAIFMT_MSB: | ||
459 | iface |= R01_SFORO_MSB; | ||
434 | } | 460 | } |
435 | 461 | ||
436 | /* FIXME enable DAC_CLK */ | 462 | if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBM_CFM) |
437 | uda1380_write(codec, UDA1380_CLK, clk | R00_DAC_CLK); | 463 | iface |= R01_SIM; |
438 | 464 | ||
465 | uda1380_write(codec, UDA1380_IFACE, iface); | ||
466 | |||
467 | return 0; | ||
468 | } | ||
469 | |||
470 | static int uda1380_trigger(struct snd_pcm_substream *substream, int cmd, | ||
471 | struct snd_soc_dai *dai) | ||
472 | { | ||
473 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
474 | struct snd_soc_device *socdev = rtd->socdev; | ||
475 | struct snd_soc_codec *codec = socdev->card->codec; | ||
476 | int mixer = uda1380_read_reg_cache(codec, UDA1380_MIXER); | ||
477 | |||
478 | switch (cmd) { | ||
479 | case SNDRV_PCM_TRIGGER_START: | ||
480 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
481 | uda1380_write_reg_cache(codec, UDA1380_MIXER, | ||
482 | mixer & ~R14_SILENCE); | ||
483 | schedule_work(&uda1380_work); | ||
484 | break; | ||
485 | case SNDRV_PCM_TRIGGER_STOP: | ||
486 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
487 | uda1380_write_reg_cache(codec, UDA1380_MIXER, | ||
488 | mixer | R14_SILENCE); | ||
489 | schedule_work(&uda1380_work); | ||
490 | break; | ||
491 | } | ||
439 | return 0; | 492 | return 0; |
440 | } | 493 | } |
441 | 494 | ||
@@ -445,7 +498,7 @@ static int uda1380_pcm_hw_params(struct snd_pcm_substream *substream, | |||
445 | { | 498 | { |
446 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 499 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
447 | struct snd_soc_device *socdev = rtd->socdev; | 500 | struct snd_soc_device *socdev = rtd->socdev; |
448 | struct snd_soc_codec *codec = socdev->codec; | 501 | struct snd_soc_codec *codec = socdev->card->codec; |
449 | u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK); | 502 | u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK); |
450 | 503 | ||
451 | /* set WSPLL power and divider if running from this clock */ | 504 | /* set WSPLL power and divider if running from this clock */ |
@@ -484,7 +537,7 @@ static void uda1380_pcm_shutdown(struct snd_pcm_substream *substream, | |||
484 | { | 537 | { |
485 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 538 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
486 | struct snd_soc_device *socdev = rtd->socdev; | 539 | struct snd_soc_device *socdev = rtd->socdev; |
487 | struct snd_soc_codec *codec = socdev->codec; | 540 | struct snd_soc_codec *codec = socdev->card->codec; |
488 | u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK); | 541 | u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK); |
489 | 542 | ||
490 | /* shut down WSPLL power if running from this clock */ | 543 | /* shut down WSPLL power if running from this clock */ |
@@ -501,24 +554,6 @@ static void uda1380_pcm_shutdown(struct snd_pcm_substream *substream, | |||
501 | uda1380_write(codec, UDA1380_CLK, clk); | 554 | uda1380_write(codec, UDA1380_CLK, clk); |
502 | } | 555 | } |
503 | 556 | ||
504 | static int uda1380_mute(struct snd_soc_dai *codec_dai, int mute) | ||
505 | { | ||
506 | struct snd_soc_codec *codec = codec_dai->codec; | ||
507 | u16 mute_reg = uda1380_read_reg_cache(codec, UDA1380_DEEMP) & ~R13_MTM; | ||
508 | |||
509 | /* FIXME: mute(codec,0) is called when the magician clock is already | ||
510 | * set to WSPLL, but for some unknown reason writing to interpolator | ||
511 | * registers works only when clocked by SYSCLK */ | ||
512 | u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK); | ||
513 | uda1380_write(codec, UDA1380_CLK, ~R00_DAC_CLK & clk); | ||
514 | if (mute) | ||
515 | uda1380_write(codec, UDA1380_DEEMP, mute_reg | R13_MTM); | ||
516 | else | ||
517 | uda1380_write(codec, UDA1380_DEEMP, mute_reg); | ||
518 | uda1380_write(codec, UDA1380_CLK, clk); | ||
519 | return 0; | ||
520 | } | ||
521 | |||
522 | static int uda1380_set_bias_level(struct snd_soc_codec *codec, | 557 | static int uda1380_set_bias_level(struct snd_soc_codec *codec, |
523 | enum snd_soc_bias_level level) | 558 | enum snd_soc_bias_level level) |
524 | { | 559 | { |
@@ -544,6 +579,27 @@ static int uda1380_set_bias_level(struct snd_soc_codec *codec, | |||
544 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ | 579 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ |
545 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) | 580 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) |
546 | 581 | ||
582 | static struct snd_soc_dai_ops uda1380_dai_ops = { | ||
583 | .hw_params = uda1380_pcm_hw_params, | ||
584 | .shutdown = uda1380_pcm_shutdown, | ||
585 | .trigger = uda1380_trigger, | ||
586 | .set_fmt = uda1380_set_dai_fmt_both, | ||
587 | }; | ||
588 | |||
589 | static struct snd_soc_dai_ops uda1380_dai_ops_playback = { | ||
590 | .hw_params = uda1380_pcm_hw_params, | ||
591 | .shutdown = uda1380_pcm_shutdown, | ||
592 | .trigger = uda1380_trigger, | ||
593 | .set_fmt = uda1380_set_dai_fmt_playback, | ||
594 | }; | ||
595 | |||
596 | static struct snd_soc_dai_ops uda1380_dai_ops_capture = { | ||
597 | .hw_params = uda1380_pcm_hw_params, | ||
598 | .shutdown = uda1380_pcm_shutdown, | ||
599 | .trigger = uda1380_trigger, | ||
600 | .set_fmt = uda1380_set_dai_fmt_capture, | ||
601 | }; | ||
602 | |||
547 | struct snd_soc_dai uda1380_dai[] = { | 603 | struct snd_soc_dai uda1380_dai[] = { |
548 | { | 604 | { |
549 | .name = "UDA1380", | 605 | .name = "UDA1380", |
@@ -559,13 +615,7 @@ struct snd_soc_dai uda1380_dai[] = { | |||
559 | .channels_max = 2, | 615 | .channels_max = 2, |
560 | .rates = UDA1380_RATES, | 616 | .rates = UDA1380_RATES, |
561 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 617 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
562 | .ops = { | 618 | .ops = &uda1380_dai_ops, |
563 | .hw_params = uda1380_pcm_hw_params, | ||
564 | .shutdown = uda1380_pcm_shutdown, | ||
565 | .prepare = uda1380_pcm_prepare, | ||
566 | .digital_mute = uda1380_mute, | ||
567 | .set_fmt = uda1380_set_dai_fmt, | ||
568 | }, | ||
569 | }, | 619 | }, |
570 | { /* playback only - dual interface */ | 620 | { /* playback only - dual interface */ |
571 | .name = "UDA1380", | 621 | .name = "UDA1380", |
@@ -576,13 +626,7 @@ struct snd_soc_dai uda1380_dai[] = { | |||
576 | .rates = UDA1380_RATES, | 626 | .rates = UDA1380_RATES, |
577 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | 627 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
578 | }, | 628 | }, |
579 | .ops = { | 629 | .ops = &uda1380_dai_ops_playback, |
580 | .hw_params = uda1380_pcm_hw_params, | ||
581 | .shutdown = uda1380_pcm_shutdown, | ||
582 | .prepare = uda1380_pcm_prepare, | ||
583 | .digital_mute = uda1380_mute, | ||
584 | .set_fmt = uda1380_set_dai_fmt, | ||
585 | }, | ||
586 | }, | 630 | }, |
587 | { /* capture only - dual interface*/ | 631 | { /* capture only - dual interface*/ |
588 | .name = "UDA1380", | 632 | .name = "UDA1380", |
@@ -593,12 +637,7 @@ struct snd_soc_dai uda1380_dai[] = { | |||
593 | .rates = UDA1380_RATES, | 637 | .rates = UDA1380_RATES, |
594 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | 638 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
595 | }, | 639 | }, |
596 | .ops = { | 640 | .ops = &uda1380_dai_ops_capture, |
597 | .hw_params = uda1380_pcm_hw_params, | ||
598 | .shutdown = uda1380_pcm_shutdown, | ||
599 | .prepare = uda1380_pcm_prepare, | ||
600 | .set_fmt = uda1380_set_dai_fmt, | ||
601 | }, | ||
602 | }, | 641 | }, |
603 | }; | 642 | }; |
604 | EXPORT_SYMBOL_GPL(uda1380_dai); | 643 | EXPORT_SYMBOL_GPL(uda1380_dai); |
@@ -606,7 +645,7 @@ EXPORT_SYMBOL_GPL(uda1380_dai); | |||
606 | static int uda1380_suspend(struct platform_device *pdev, pm_message_t state) | 645 | static int uda1380_suspend(struct platform_device *pdev, pm_message_t state) |
607 | { | 646 | { |
608 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 647 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
609 | struct snd_soc_codec *codec = socdev->codec; | 648 | struct snd_soc_codec *codec = socdev->card->codec; |
610 | 649 | ||
611 | uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF); | 650 | uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF); |
612 | return 0; | 651 | return 0; |
@@ -615,7 +654,7 @@ static int uda1380_suspend(struct platform_device *pdev, pm_message_t state) | |||
615 | static int uda1380_resume(struct platform_device *pdev) | 654 | static int uda1380_resume(struct platform_device *pdev) |
616 | { | 655 | { |
617 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 656 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
618 | struct snd_soc_codec *codec = socdev->codec; | 657 | struct snd_soc_codec *codec = socdev->card->codec; |
619 | int i; | 658 | int i; |
620 | u8 data[2]; | 659 | u8 data[2]; |
621 | u16 *cache = codec->reg_cache; | 660 | u16 *cache = codec->reg_cache; |
@@ -637,7 +676,7 @@ static int uda1380_resume(struct platform_device *pdev) | |||
637 | */ | 676 | */ |
638 | static int uda1380_init(struct snd_soc_device *socdev, int dac_clk) | 677 | static int uda1380_init(struct snd_soc_device *socdev, int dac_clk) |
639 | { | 678 | { |
640 | struct snd_soc_codec *codec = socdev->codec; | 679 | struct snd_soc_codec *codec = socdev->card->codec; |
641 | int ret = 0; | 680 | int ret = 0; |
642 | 681 | ||
643 | codec->name = "UDA1380"; | 682 | codec->name = "UDA1380"; |
@@ -655,6 +694,9 @@ static int uda1380_init(struct snd_soc_device *socdev, int dac_clk) | |||
655 | codec->reg_cache_step = 1; | 694 | codec->reg_cache_step = 1; |
656 | uda1380_reset(codec); | 695 | uda1380_reset(codec); |
657 | 696 | ||
697 | uda1380_codec = codec; | ||
698 | INIT_WORK(&uda1380_work, uda1380_flush_work); | ||
699 | |||
658 | /* register pcms */ | 700 | /* register pcms */ |
659 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | 701 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
660 | if (ret < 0) { | 702 | if (ret < 0) { |
@@ -675,7 +717,8 @@ static int uda1380_init(struct snd_soc_device *socdev, int dac_clk) | |||
675 | } | 717 | } |
676 | 718 | ||
677 | /* uda1380 init */ | 719 | /* uda1380 init */ |
678 | uda1380_add_controls(codec); | 720 | snd_soc_add_controls(codec, uda1380_snd_controls, |
721 | ARRAY_SIZE(uda1380_snd_controls)); | ||
679 | uda1380_add_widgets(codec); | 722 | uda1380_add_widgets(codec); |
680 | ret = snd_soc_init_card(socdev); | 723 | ret = snd_soc_init_card(socdev); |
681 | if (ret < 0) { | 724 | if (ret < 0) { |
@@ -702,7 +745,7 @@ static int uda1380_i2c_probe(struct i2c_client *i2c, | |||
702 | { | 745 | { |
703 | struct snd_soc_device *socdev = uda1380_socdev; | 746 | struct snd_soc_device *socdev = uda1380_socdev; |
704 | struct uda1380_setup_data *setup = socdev->codec_data; | 747 | struct uda1380_setup_data *setup = socdev->codec_data; |
705 | struct snd_soc_codec *codec = socdev->codec; | 748 | struct snd_soc_codec *codec = socdev->card->codec; |
706 | int ret; | 749 | int ret; |
707 | 750 | ||
708 | i2c_set_clientdata(i2c, codec); | 751 | i2c_set_clientdata(i2c, codec); |
@@ -786,14 +829,12 @@ static int uda1380_probe(struct platform_device *pdev) | |||
786 | struct snd_soc_codec *codec; | 829 | struct snd_soc_codec *codec; |
787 | int ret; | 830 | int ret; |
788 | 831 | ||
789 | pr_info("UDA1380 Audio Codec %s", UDA1380_VERSION); | ||
790 | |||
791 | setup = socdev->codec_data; | 832 | setup = socdev->codec_data; |
792 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | 833 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
793 | if (codec == NULL) | 834 | if (codec == NULL) |
794 | return -ENOMEM; | 835 | return -ENOMEM; |
795 | 836 | ||
796 | socdev->codec = codec; | 837 | socdev->card->codec = codec; |
797 | mutex_init(&codec->mutex); | 838 | mutex_init(&codec->mutex); |
798 | INIT_LIST_HEAD(&codec->dapm_widgets); | 839 | INIT_LIST_HEAD(&codec->dapm_widgets); |
799 | INIT_LIST_HEAD(&codec->dapm_paths); | 840 | INIT_LIST_HEAD(&codec->dapm_paths); |
@@ -817,7 +858,7 @@ static int uda1380_probe(struct platform_device *pdev) | |||
817 | static int uda1380_remove(struct platform_device *pdev) | 858 | static int uda1380_remove(struct platform_device *pdev) |
818 | { | 859 | { |
819 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 860 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
820 | struct snd_soc_codec *codec = socdev->codec; | 861 | struct snd_soc_codec *codec = socdev->card->codec; |
821 | 862 | ||
822 | if (codec->control_data) | 863 | if (codec->control_data) |
823 | uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF); | 864 | uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF); |
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c index 35d99750c383..3b1d0993bed9 100644 --- a/sound/soc/codecs/wm8350.c +++ b/sound/soc/codecs/wm8350.c | |||
@@ -51,10 +51,17 @@ struct wm8350_output { | |||
51 | u16 mute; | 51 | u16 mute; |
52 | }; | 52 | }; |
53 | 53 | ||
54 | struct wm8350_jack_data { | ||
55 | struct snd_soc_jack *jack; | ||
56 | int report; | ||
57 | }; | ||
58 | |||
54 | struct wm8350_data { | 59 | struct wm8350_data { |
55 | struct snd_soc_codec codec; | 60 | struct snd_soc_codec codec; |
56 | struct wm8350_output out1; | 61 | struct wm8350_output out1; |
57 | struct wm8350_output out2; | 62 | struct wm8350_output out2; |
63 | struct wm8350_jack_data hpl; | ||
64 | struct wm8350_jack_data hpr; | ||
58 | struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; | 65 | struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; |
59 | }; | 66 | }; |
60 | 67 | ||
@@ -775,21 +782,6 @@ static const struct snd_soc_dapm_route audio_map[] = { | |||
775 | {"Beep", NULL, "IN3R PGA"}, | 782 | {"Beep", NULL, "IN3R PGA"}, |
776 | }; | 783 | }; |
777 | 784 | ||
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) | 785 | static int wm8350_add_widgets(struct snd_soc_codec *codec) |
794 | { | 786 | { |
795 | int ret; | 787 | int ret; |
@@ -1309,7 +1301,7 @@ static int wm8350_set_bias_level(struct snd_soc_codec *codec, | |||
1309 | static int wm8350_suspend(struct platform_device *pdev, pm_message_t state) | 1301 | static int wm8350_suspend(struct platform_device *pdev, pm_message_t state) |
1310 | { | 1302 | { |
1311 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1303 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1312 | struct snd_soc_codec *codec = socdev->codec; | 1304 | struct snd_soc_codec *codec = socdev->card->codec; |
1313 | 1305 | ||
1314 | wm8350_set_bias_level(codec, SND_SOC_BIAS_OFF); | 1306 | wm8350_set_bias_level(codec, SND_SOC_BIAS_OFF); |
1315 | return 0; | 1307 | return 0; |
@@ -1318,7 +1310,7 @@ static int wm8350_suspend(struct platform_device *pdev, pm_message_t state) | |||
1318 | static int wm8350_resume(struct platform_device *pdev) | 1310 | static int wm8350_resume(struct platform_device *pdev) |
1319 | { | 1311 | { |
1320 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1312 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1321 | struct snd_soc_codec *codec = socdev->codec; | 1313 | struct snd_soc_codec *codec = socdev->card->codec; |
1322 | 1314 | ||
1323 | wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 1315 | wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
1324 | 1316 | ||
@@ -1328,6 +1320,95 @@ static int wm8350_resume(struct platform_device *pdev) | |||
1328 | return 0; | 1320 | return 0; |
1329 | } | 1321 | } |
1330 | 1322 | ||
1323 | static void wm8350_hp_jack_handler(struct wm8350 *wm8350, int irq, void *data) | ||
1324 | { | ||
1325 | struct wm8350_data *priv = data; | ||
1326 | u16 reg; | ||
1327 | int report; | ||
1328 | int mask; | ||
1329 | struct wm8350_jack_data *jack = NULL; | ||
1330 | |||
1331 | switch (irq) { | ||
1332 | case WM8350_IRQ_CODEC_JCK_DET_L: | ||
1333 | jack = &priv->hpl; | ||
1334 | mask = WM8350_JACK_L_LVL; | ||
1335 | break; | ||
1336 | |||
1337 | case WM8350_IRQ_CODEC_JCK_DET_R: | ||
1338 | jack = &priv->hpr; | ||
1339 | mask = WM8350_JACK_R_LVL; | ||
1340 | break; | ||
1341 | |||
1342 | default: | ||
1343 | BUG(); | ||
1344 | } | ||
1345 | |||
1346 | if (!jack->jack) { | ||
1347 | dev_warn(wm8350->dev, "Jack interrupt called with no jack\n"); | ||
1348 | return; | ||
1349 | } | ||
1350 | |||
1351 | /* Debounce */ | ||
1352 | msleep(200); | ||
1353 | |||
1354 | reg = wm8350_reg_read(wm8350, WM8350_JACK_PIN_STATUS); | ||
1355 | if (reg & mask) | ||
1356 | report = jack->report; | ||
1357 | else | ||
1358 | report = 0; | ||
1359 | |||
1360 | snd_soc_jack_report(jack->jack, report, jack->report); | ||
1361 | } | ||
1362 | |||
1363 | /** | ||
1364 | * wm8350_hp_jack_detect - Enable headphone jack detection. | ||
1365 | * | ||
1366 | * @codec: WM8350 codec | ||
1367 | * @which: left or right jack detect signal | ||
1368 | * @jack: jack to report detection events on | ||
1369 | * @report: value to report | ||
1370 | * | ||
1371 | * Enables the headphone jack detection of the WM8350. | ||
1372 | */ | ||
1373 | int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which, | ||
1374 | struct snd_soc_jack *jack, int report) | ||
1375 | { | ||
1376 | struct wm8350_data *priv = codec->private_data; | ||
1377 | struct wm8350 *wm8350 = codec->control_data; | ||
1378 | int irq; | ||
1379 | int ena; | ||
1380 | |||
1381 | switch (which) { | ||
1382 | case WM8350_JDL: | ||
1383 | priv->hpl.jack = jack; | ||
1384 | priv->hpl.report = report; | ||
1385 | irq = WM8350_IRQ_CODEC_JCK_DET_L; | ||
1386 | ena = WM8350_JDL_ENA; | ||
1387 | break; | ||
1388 | |||
1389 | case WM8350_JDR: | ||
1390 | priv->hpr.jack = jack; | ||
1391 | priv->hpr.report = report; | ||
1392 | irq = WM8350_IRQ_CODEC_JCK_DET_R; | ||
1393 | ena = WM8350_JDR_ENA; | ||
1394 | break; | ||
1395 | |||
1396 | default: | ||
1397 | return -EINVAL; | ||
1398 | } | ||
1399 | |||
1400 | wm8350_set_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA); | ||
1401 | wm8350_set_bits(wm8350, WM8350_JACK_DETECT, ena); | ||
1402 | |||
1403 | /* Sync status */ | ||
1404 | wm8350_hp_jack_handler(wm8350, irq, priv); | ||
1405 | |||
1406 | wm8350_unmask_irq(wm8350, irq); | ||
1407 | |||
1408 | return 0; | ||
1409 | } | ||
1410 | EXPORT_SYMBOL_GPL(wm8350_hp_jack_detect); | ||
1411 | |||
1331 | static struct snd_soc_codec *wm8350_codec; | 1412 | static struct snd_soc_codec *wm8350_codec; |
1332 | 1413 | ||
1333 | static int wm8350_probe(struct platform_device *pdev) | 1414 | static int wm8350_probe(struct platform_device *pdev) |
@@ -1342,8 +1423,8 @@ static int wm8350_probe(struct platform_device *pdev) | |||
1342 | 1423 | ||
1343 | BUG_ON(!wm8350_codec); | 1424 | BUG_ON(!wm8350_codec); |
1344 | 1425 | ||
1345 | socdev->codec = wm8350_codec; | 1426 | socdev->card->codec = wm8350_codec; |
1346 | codec = socdev->codec; | 1427 | codec = socdev->card->codec; |
1347 | wm8350 = codec->control_data; | 1428 | wm8350 = codec->control_data; |
1348 | priv = codec->private_data; | 1429 | priv = codec->private_data; |
1349 | 1430 | ||
@@ -1381,13 +1462,21 @@ static int wm8350_probe(struct platform_device *pdev) | |||
1381 | wm8350_set_bits(wm8350, WM8350_ROUT2_VOLUME, | 1462 | wm8350_set_bits(wm8350, WM8350_ROUT2_VOLUME, |
1382 | WM8350_OUT2_VU | WM8350_OUT2R_MUTE); | 1463 | WM8350_OUT2_VU | WM8350_OUT2R_MUTE); |
1383 | 1464 | ||
1465 | wm8350_mask_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L); | ||
1466 | wm8350_mask_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R); | ||
1467 | wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L, | ||
1468 | wm8350_hp_jack_handler, priv); | ||
1469 | wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R, | ||
1470 | wm8350_hp_jack_handler, priv); | ||
1471 | |||
1384 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | 1472 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
1385 | if (ret < 0) { | 1473 | if (ret < 0) { |
1386 | dev_err(&pdev->dev, "failed to create pcms\n"); | 1474 | dev_err(&pdev->dev, "failed to create pcms\n"); |
1387 | return ret; | 1475 | return ret; |
1388 | } | 1476 | } |
1389 | 1477 | ||
1390 | wm8350_add_controls(codec); | 1478 | snd_soc_add_controls(codec, wm8350_snd_controls, |
1479 | ARRAY_SIZE(wm8350_snd_controls)); | ||
1391 | wm8350_add_widgets(codec); | 1480 | wm8350_add_widgets(codec); |
1392 | 1481 | ||
1393 | wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 1482 | wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
@@ -1409,10 +1498,23 @@ card_err: | |||
1409 | static int wm8350_remove(struct platform_device *pdev) | 1498 | static int wm8350_remove(struct platform_device *pdev) |
1410 | { | 1499 | { |
1411 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1500 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1412 | struct snd_soc_codec *codec = socdev->codec; | 1501 | struct snd_soc_codec *codec = socdev->card->codec; |
1413 | struct wm8350 *wm8350 = codec->control_data; | 1502 | struct wm8350 *wm8350 = codec->control_data; |
1503 | struct wm8350_data *priv = codec->private_data; | ||
1414 | int ret; | 1504 | int ret; |
1415 | 1505 | ||
1506 | wm8350_clear_bits(wm8350, WM8350_JACK_DETECT, | ||
1507 | WM8350_JDL_ENA | WM8350_JDR_ENA); | ||
1508 | wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA); | ||
1509 | |||
1510 | wm8350_mask_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L); | ||
1511 | wm8350_mask_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R); | ||
1512 | wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L); | ||
1513 | wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R); | ||
1514 | |||
1515 | priv->hpl.jack = NULL; | ||
1516 | priv->hpr.jack = NULL; | ||
1517 | |||
1416 | /* cancel any work waiting to be queued. */ | 1518 | /* cancel any work waiting to be queued. */ |
1417 | ret = cancel_delayed_work(&codec->delayed_work); | 1519 | ret = cancel_delayed_work(&codec->delayed_work); |
1418 | 1520 | ||
@@ -1436,6 +1538,16 @@ static int wm8350_remove(struct platform_device *pdev) | |||
1436 | SNDRV_PCM_FMTBIT_S20_3LE |\ | 1538 | SNDRV_PCM_FMTBIT_S20_3LE |\ |
1437 | SNDRV_PCM_FMTBIT_S24_LE) | 1539 | SNDRV_PCM_FMTBIT_S24_LE) |
1438 | 1540 | ||
1541 | static struct snd_soc_dai_ops wm8350_dai_ops = { | ||
1542 | .hw_params = wm8350_pcm_hw_params, | ||
1543 | .digital_mute = wm8350_mute, | ||
1544 | .trigger = wm8350_pcm_trigger, | ||
1545 | .set_fmt = wm8350_set_dai_fmt, | ||
1546 | .set_sysclk = wm8350_set_dai_sysclk, | ||
1547 | .set_pll = wm8350_set_fll, | ||
1548 | .set_clkdiv = wm8350_set_clkdiv, | ||
1549 | }; | ||
1550 | |||
1439 | struct snd_soc_dai wm8350_dai = { | 1551 | struct snd_soc_dai wm8350_dai = { |
1440 | .name = "WM8350", | 1552 | .name = "WM8350", |
1441 | .playback = { | 1553 | .playback = { |
@@ -1452,15 +1564,7 @@ struct snd_soc_dai wm8350_dai = { | |||
1452 | .rates = WM8350_RATES, | 1564 | .rates = WM8350_RATES, |
1453 | .formats = WM8350_FORMATS, | 1565 | .formats = WM8350_FORMATS, |
1454 | }, | 1566 | }, |
1455 | .ops = { | 1567 | .ops = &wm8350_dai_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 | }; | 1568 | }; |
1465 | EXPORT_SYMBOL_GPL(wm8350_dai); | 1569 | EXPORT_SYMBOL_GPL(wm8350_dai); |
1466 | 1570 | ||
@@ -1472,7 +1576,7 @@ struct snd_soc_codec_device soc_codec_dev_wm8350 = { | |||
1472 | }; | 1576 | }; |
1473 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8350); | 1577 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8350); |
1474 | 1578 | ||
1475 | static int wm8350_codec_probe(struct platform_device *pdev) | 1579 | static __devinit int wm8350_codec_probe(struct platform_device *pdev) |
1476 | { | 1580 | { |
1477 | struct wm8350 *wm8350 = platform_get_drvdata(pdev); | 1581 | struct wm8350 *wm8350 = platform_get_drvdata(pdev); |
1478 | struct wm8350_data *priv; | 1582 | struct wm8350_data *priv; |
diff --git a/sound/soc/codecs/wm8350.h b/sound/soc/codecs/wm8350.h index cc2887aa6c38..d11bd9288cf9 100644 --- a/sound/soc/codecs/wm8350.h +++ b/sound/soc/codecs/wm8350.h | |||
@@ -17,4 +17,12 @@ | |||
17 | extern struct snd_soc_dai wm8350_dai; | 17 | extern struct snd_soc_dai wm8350_dai; |
18 | extern struct snd_soc_codec_device soc_codec_dev_wm8350; | 18 | extern struct snd_soc_codec_device soc_codec_dev_wm8350; |
19 | 19 | ||
20 | enum wm8350_jack { | ||
21 | WM8350_JDL = 1, | ||
22 | WM8350_JDR = 2, | ||
23 | }; | ||
24 | |||
25 | int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which, | ||
26 | struct snd_soc_jack *jack, int report); | ||
27 | |||
20 | #endif | 28 | #endif |
diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c new file mode 100644 index 000000000000..510efa604008 --- /dev/null +++ b/sound/soc/codecs/wm8400.c | |||
@@ -0,0 +1,1582 @@ | |||
1 | /* | ||
2 | * wm8400.c -- WM8400 ALSA Soc Audio driver | ||
3 | * | ||
4 | * Copyright 2008, 2009 Wolfson Microelectronics PLC. | ||
5 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
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 | ||
10 | * option) any later version. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/moduleparam.h> | ||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/delay.h> | ||
19 | #include <linux/pm.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/regulator/consumer.h> | ||
22 | #include <linux/mfd/wm8400-audio.h> | ||
23 | #include <linux/mfd/wm8400-private.h> | ||
24 | #include <sound/core.h> | ||
25 | #include <sound/pcm.h> | ||
26 | #include <sound/pcm_params.h> | ||
27 | #include <sound/soc.h> | ||
28 | #include <sound/soc-dapm.h> | ||
29 | #include <sound/initval.h> | ||
30 | #include <sound/tlv.h> | ||
31 | |||
32 | #include "wm8400.h" | ||
33 | |||
34 | /* Fake register for internal state */ | ||
35 | #define WM8400_INTDRIVBITS (WM8400_REGISTER_COUNT + 1) | ||
36 | #define WM8400_INMIXL_PWR 0 | ||
37 | #define WM8400_AINLMUX_PWR 1 | ||
38 | #define WM8400_INMIXR_PWR 2 | ||
39 | #define WM8400_AINRMUX_PWR 3 | ||
40 | |||
41 | static struct regulator_bulk_data power[] = { | ||
42 | { | ||
43 | .supply = "I2S1VDD", | ||
44 | }, | ||
45 | { | ||
46 | .supply = "I2S2VDD", | ||
47 | }, | ||
48 | { | ||
49 | .supply = "DCVDD", | ||
50 | }, | ||
51 | { | ||
52 | .supply = "AVDD", | ||
53 | }, | ||
54 | { | ||
55 | .supply = "FLLVDD", | ||
56 | }, | ||
57 | { | ||
58 | .supply = "HPVDD", | ||
59 | }, | ||
60 | { | ||
61 | .supply = "SPKVDD", | ||
62 | }, | ||
63 | }; | ||
64 | |||
65 | /* codec private data */ | ||
66 | struct wm8400_priv { | ||
67 | struct snd_soc_codec codec; | ||
68 | struct wm8400 *wm8400; | ||
69 | u16 fake_register; | ||
70 | unsigned int sysclk; | ||
71 | unsigned int pcmclk; | ||
72 | struct work_struct work; | ||
73 | int fll_in, fll_out; | ||
74 | }; | ||
75 | |||
76 | static inline unsigned int wm8400_read(struct snd_soc_codec *codec, | ||
77 | unsigned int reg) | ||
78 | { | ||
79 | struct wm8400_priv *wm8400 = codec->private_data; | ||
80 | |||
81 | if (reg == WM8400_INTDRIVBITS) | ||
82 | return wm8400->fake_register; | ||
83 | else | ||
84 | return wm8400_reg_read(wm8400->wm8400, reg); | ||
85 | } | ||
86 | |||
87 | /* | ||
88 | * write to the wm8400 register space | ||
89 | */ | ||
90 | static int wm8400_write(struct snd_soc_codec *codec, unsigned int reg, | ||
91 | unsigned int value) | ||
92 | { | ||
93 | struct wm8400_priv *wm8400 = codec->private_data; | ||
94 | |||
95 | if (reg == WM8400_INTDRIVBITS) { | ||
96 | wm8400->fake_register = value; | ||
97 | return 0; | ||
98 | } else | ||
99 | return wm8400_set_bits(wm8400->wm8400, reg, 0xffff, value); | ||
100 | } | ||
101 | |||
102 | static void wm8400_codec_reset(struct snd_soc_codec *codec) | ||
103 | { | ||
104 | struct wm8400_priv *wm8400 = codec->private_data; | ||
105 | |||
106 | wm8400_reset_codec_reg_cache(wm8400->wm8400); | ||
107 | } | ||
108 | |||
109 | static const DECLARE_TLV_DB_LINEAR(rec_mix_tlv, -1500, 600); | ||
110 | |||
111 | static const DECLARE_TLV_DB_LINEAR(in_pga_tlv, -1650, 3000); | ||
112 | |||
113 | static const DECLARE_TLV_DB_LINEAR(out_mix_tlv, -2100, 0); | ||
114 | |||
115 | static const DECLARE_TLV_DB_LINEAR(out_pga_tlv, -7300, 600); | ||
116 | |||
117 | static const DECLARE_TLV_DB_LINEAR(out_omix_tlv, -600, 0); | ||
118 | |||
119 | static const DECLARE_TLV_DB_LINEAR(out_dac_tlv, -7163, 0); | ||
120 | |||
121 | static const DECLARE_TLV_DB_LINEAR(in_adc_tlv, -7163, 1763); | ||
122 | |||
123 | static const DECLARE_TLV_DB_LINEAR(out_sidetone_tlv, -3600, 0); | ||
124 | |||
125 | static int wm8400_outpga_put_volsw_vu(struct snd_kcontrol *kcontrol, | ||
126 | struct snd_ctl_elem_value *ucontrol) | ||
127 | { | ||
128 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | ||
129 | struct soc_mixer_control *mc = | ||
130 | (struct soc_mixer_control *)kcontrol->private_value; | ||
131 | int reg = mc->reg; | ||
132 | int ret; | ||
133 | u16 val; | ||
134 | |||
135 | ret = snd_soc_put_volsw(kcontrol, ucontrol); | ||
136 | if (ret < 0) | ||
137 | return ret; | ||
138 | |||
139 | /* now hit the volume update bits (always bit 8) */ | ||
140 | val = wm8400_read(codec, reg); | ||
141 | return wm8400_write(codec, reg, val | 0x0100); | ||
142 | } | ||
143 | |||
144 | #define WM8400_OUTPGA_SINGLE_R_TLV(xname, reg, shift, max, invert, tlv_array) \ | ||
145 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ | ||
146 | .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ | ||
147 | SNDRV_CTL_ELEM_ACCESS_READWRITE,\ | ||
148 | .tlv.p = (tlv_array), \ | ||
149 | .info = snd_soc_info_volsw, \ | ||
150 | .get = snd_soc_get_volsw, .put = wm8400_outpga_put_volsw_vu, \ | ||
151 | .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) } | ||
152 | |||
153 | |||
154 | static const char *wm8400_digital_sidetone[] = | ||
155 | {"None", "Left ADC", "Right ADC", "Reserved"}; | ||
156 | |||
157 | static const struct soc_enum wm8400_left_digital_sidetone_enum = | ||
158 | SOC_ENUM_SINGLE(WM8400_DIGITAL_SIDE_TONE, | ||
159 | WM8400_ADC_TO_DACL_SHIFT, 2, wm8400_digital_sidetone); | ||
160 | |||
161 | static const struct soc_enum wm8400_right_digital_sidetone_enum = | ||
162 | SOC_ENUM_SINGLE(WM8400_DIGITAL_SIDE_TONE, | ||
163 | WM8400_ADC_TO_DACR_SHIFT, 2, wm8400_digital_sidetone); | ||
164 | |||
165 | static const char *wm8400_adcmode[] = | ||
166 | {"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"}; | ||
167 | |||
168 | static const struct soc_enum wm8400_right_adcmode_enum = | ||
169 | SOC_ENUM_SINGLE(WM8400_ADC_CTRL, WM8400_ADC_HPF_CUT_SHIFT, 3, wm8400_adcmode); | ||
170 | |||
171 | static const struct snd_kcontrol_new wm8400_snd_controls[] = { | ||
172 | /* INMIXL */ | ||
173 | SOC_SINGLE("LIN12 PGA Boost", WM8400_INPUT_MIXER3, WM8400_L12MNBST_SHIFT, | ||
174 | 1, 0), | ||
175 | SOC_SINGLE("LIN34 PGA Boost", WM8400_INPUT_MIXER3, WM8400_L34MNBST_SHIFT, | ||
176 | 1, 0), | ||
177 | /* INMIXR */ | ||
178 | SOC_SINGLE("RIN12 PGA Boost", WM8400_INPUT_MIXER3, WM8400_R12MNBST_SHIFT, | ||
179 | 1, 0), | ||
180 | SOC_SINGLE("RIN34 PGA Boost", WM8400_INPUT_MIXER3, WM8400_R34MNBST_SHIFT, | ||
181 | 1, 0), | ||
182 | |||
183 | /* LOMIX */ | ||
184 | SOC_SINGLE_TLV("LOMIX LIN3 Bypass Volume", WM8400_OUTPUT_MIXER3, | ||
185 | WM8400_LLI3LOVOL_SHIFT, 7, 0, out_mix_tlv), | ||
186 | SOC_SINGLE_TLV("LOMIX RIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER3, | ||
187 | WM8400_LR12LOVOL_SHIFT, 7, 0, out_mix_tlv), | ||
188 | SOC_SINGLE_TLV("LOMIX LIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER3, | ||
189 | WM8400_LL12LOVOL_SHIFT, 7, 0, out_mix_tlv), | ||
190 | SOC_SINGLE_TLV("LOMIX RIN3 Bypass Volume", WM8400_OUTPUT_MIXER5, | ||
191 | WM8400_LRI3LOVOL_SHIFT, 7, 0, out_mix_tlv), | ||
192 | SOC_SINGLE_TLV("LOMIX AINRMUX Bypass Volume", WM8400_OUTPUT_MIXER5, | ||
193 | WM8400_LRBLOVOL_SHIFT, 7, 0, out_mix_tlv), | ||
194 | SOC_SINGLE_TLV("LOMIX AINLMUX Bypass Volume", WM8400_OUTPUT_MIXER5, | ||
195 | WM8400_LRBLOVOL_SHIFT, 7, 0, out_mix_tlv), | ||
196 | |||
197 | /* ROMIX */ | ||
198 | SOC_SINGLE_TLV("ROMIX RIN3 Bypass Volume", WM8400_OUTPUT_MIXER4, | ||
199 | WM8400_RRI3ROVOL_SHIFT, 7, 0, out_mix_tlv), | ||
200 | SOC_SINGLE_TLV("ROMIX LIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER4, | ||
201 | WM8400_RL12ROVOL_SHIFT, 7, 0, out_mix_tlv), | ||
202 | SOC_SINGLE_TLV("ROMIX RIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER4, | ||
203 | WM8400_RR12ROVOL_SHIFT, 7, 0, out_mix_tlv), | ||
204 | SOC_SINGLE_TLV("ROMIX LIN3 Bypass Volume", WM8400_OUTPUT_MIXER6, | ||
205 | WM8400_RLI3ROVOL_SHIFT, 7, 0, out_mix_tlv), | ||
206 | SOC_SINGLE_TLV("ROMIX AINLMUX Bypass Volume", WM8400_OUTPUT_MIXER6, | ||
207 | WM8400_RLBROVOL_SHIFT, 7, 0, out_mix_tlv), | ||
208 | SOC_SINGLE_TLV("ROMIX AINRMUX Bypass Volume", WM8400_OUTPUT_MIXER6, | ||
209 | WM8400_RRBROVOL_SHIFT, 7, 0, out_mix_tlv), | ||
210 | |||
211 | /* LOUT */ | ||
212 | WM8400_OUTPGA_SINGLE_R_TLV("LOUT Volume", WM8400_LEFT_OUTPUT_VOLUME, | ||
213 | WM8400_LOUTVOL_SHIFT, WM8400_LOUTVOL_MASK, 0, out_pga_tlv), | ||
214 | SOC_SINGLE("LOUT ZC", WM8400_LEFT_OUTPUT_VOLUME, WM8400_LOZC_SHIFT, 1, 0), | ||
215 | |||
216 | /* ROUT */ | ||
217 | WM8400_OUTPGA_SINGLE_R_TLV("ROUT Volume", WM8400_RIGHT_OUTPUT_VOLUME, | ||
218 | WM8400_ROUTVOL_SHIFT, WM8400_ROUTVOL_MASK, 0, out_pga_tlv), | ||
219 | SOC_SINGLE("ROUT ZC", WM8400_RIGHT_OUTPUT_VOLUME, WM8400_ROZC_SHIFT, 1, 0), | ||
220 | |||
221 | /* LOPGA */ | ||
222 | WM8400_OUTPGA_SINGLE_R_TLV("LOPGA Volume", WM8400_LEFT_OPGA_VOLUME, | ||
223 | WM8400_LOPGAVOL_SHIFT, WM8400_LOPGAVOL_MASK, 0, out_pga_tlv), | ||
224 | SOC_SINGLE("LOPGA ZC Switch", WM8400_LEFT_OPGA_VOLUME, | ||
225 | WM8400_LOPGAZC_SHIFT, 1, 0), | ||
226 | |||
227 | /* ROPGA */ | ||
228 | WM8400_OUTPGA_SINGLE_R_TLV("ROPGA Volume", WM8400_RIGHT_OPGA_VOLUME, | ||
229 | WM8400_ROPGAVOL_SHIFT, WM8400_ROPGAVOL_MASK, 0, out_pga_tlv), | ||
230 | SOC_SINGLE("ROPGA ZC Switch", WM8400_RIGHT_OPGA_VOLUME, | ||
231 | WM8400_ROPGAZC_SHIFT, 1, 0), | ||
232 | |||
233 | SOC_SINGLE("LON Mute Switch", WM8400_LINE_OUTPUTS_VOLUME, | ||
234 | WM8400_LONMUTE_SHIFT, 1, 0), | ||
235 | SOC_SINGLE("LOP Mute Switch", WM8400_LINE_OUTPUTS_VOLUME, | ||
236 | WM8400_LOPMUTE_SHIFT, 1, 0), | ||
237 | SOC_SINGLE("LOP Attenuation Switch", WM8400_LINE_OUTPUTS_VOLUME, | ||
238 | WM8400_LOATTN_SHIFT, 1, 0), | ||
239 | SOC_SINGLE("RON Mute Switch", WM8400_LINE_OUTPUTS_VOLUME, | ||
240 | WM8400_RONMUTE_SHIFT, 1, 0), | ||
241 | SOC_SINGLE("ROP Mute Switch", WM8400_LINE_OUTPUTS_VOLUME, | ||
242 | WM8400_ROPMUTE_SHIFT, 1, 0), | ||
243 | SOC_SINGLE("ROP Attenuation Switch", WM8400_LINE_OUTPUTS_VOLUME, | ||
244 | WM8400_ROATTN_SHIFT, 1, 0), | ||
245 | |||
246 | SOC_SINGLE("OUT3 Mute Switch", WM8400_OUT3_4_VOLUME, | ||
247 | WM8400_OUT3MUTE_SHIFT, 1, 0), | ||
248 | SOC_SINGLE("OUT3 Attenuation Switch", WM8400_OUT3_4_VOLUME, | ||
249 | WM8400_OUT3ATTN_SHIFT, 1, 0), | ||
250 | |||
251 | SOC_SINGLE("OUT4 Mute Switch", WM8400_OUT3_4_VOLUME, | ||
252 | WM8400_OUT4MUTE_SHIFT, 1, 0), | ||
253 | SOC_SINGLE("OUT4 Attenuation Switch", WM8400_OUT3_4_VOLUME, | ||
254 | WM8400_OUT4ATTN_SHIFT, 1, 0), | ||
255 | |||
256 | SOC_SINGLE("Speaker Mode Switch", WM8400_CLASSD1, | ||
257 | WM8400_CDMODE_SHIFT, 1, 0), | ||
258 | |||
259 | SOC_SINGLE("Speaker Output Attenuation Volume", WM8400_SPEAKER_VOLUME, | ||
260 | WM8400_SPKATTN_SHIFT, WM8400_SPKATTN_MASK, 0), | ||
261 | SOC_SINGLE("Speaker DC Boost Volume", WM8400_CLASSD3, | ||
262 | WM8400_DCGAIN_SHIFT, 6, 0), | ||
263 | SOC_SINGLE("Speaker AC Boost Volume", WM8400_CLASSD3, | ||
264 | WM8400_ACGAIN_SHIFT, 6, 0), | ||
265 | |||
266 | WM8400_OUTPGA_SINGLE_R_TLV("Left DAC Digital Volume", | ||
267 | WM8400_LEFT_DAC_DIGITAL_VOLUME, WM8400_DACL_VOL_SHIFT, | ||
268 | 127, 0, out_dac_tlv), | ||
269 | |||
270 | WM8400_OUTPGA_SINGLE_R_TLV("Right DAC Digital Volume", | ||
271 | WM8400_RIGHT_DAC_DIGITAL_VOLUME, WM8400_DACR_VOL_SHIFT, | ||
272 | 127, 0, out_dac_tlv), | ||
273 | |||
274 | SOC_ENUM("Left Digital Sidetone", wm8400_left_digital_sidetone_enum), | ||
275 | SOC_ENUM("Right Digital Sidetone", wm8400_right_digital_sidetone_enum), | ||
276 | |||
277 | SOC_SINGLE_TLV("Left Digital Sidetone Volume", WM8400_DIGITAL_SIDE_TONE, | ||
278 | WM8400_ADCL_DAC_SVOL_SHIFT, 15, 0, out_sidetone_tlv), | ||
279 | SOC_SINGLE_TLV("Right Digital Sidetone Volume", WM8400_DIGITAL_SIDE_TONE, | ||
280 | WM8400_ADCR_DAC_SVOL_SHIFT, 15, 0, out_sidetone_tlv), | ||
281 | |||
282 | SOC_SINGLE("ADC Digital High Pass Filter Switch", WM8400_ADC_CTRL, | ||
283 | WM8400_ADC_HPF_ENA_SHIFT, 1, 0), | ||
284 | |||
285 | SOC_ENUM("ADC HPF Mode", wm8400_right_adcmode_enum), | ||
286 | |||
287 | WM8400_OUTPGA_SINGLE_R_TLV("Left ADC Digital Volume", | ||
288 | WM8400_LEFT_ADC_DIGITAL_VOLUME, | ||
289 | WM8400_ADCL_VOL_SHIFT, | ||
290 | WM8400_ADCL_VOL_MASK, | ||
291 | 0, | ||
292 | in_adc_tlv), | ||
293 | |||
294 | WM8400_OUTPGA_SINGLE_R_TLV("Right ADC Digital Volume", | ||
295 | WM8400_RIGHT_ADC_DIGITAL_VOLUME, | ||
296 | WM8400_ADCR_VOL_SHIFT, | ||
297 | WM8400_ADCR_VOL_MASK, | ||
298 | 0, | ||
299 | in_adc_tlv), | ||
300 | |||
301 | WM8400_OUTPGA_SINGLE_R_TLV("LIN12 Volume", | ||
302 | WM8400_LEFT_LINE_INPUT_1_2_VOLUME, | ||
303 | WM8400_LIN12VOL_SHIFT, | ||
304 | WM8400_LIN12VOL_MASK, | ||
305 | 0, | ||
306 | in_pga_tlv), | ||
307 | |||
308 | SOC_SINGLE("LIN12 ZC Switch", WM8400_LEFT_LINE_INPUT_1_2_VOLUME, | ||
309 | WM8400_LI12ZC_SHIFT, 1, 0), | ||
310 | |||
311 | SOC_SINGLE("LIN12 Mute Switch", WM8400_LEFT_LINE_INPUT_1_2_VOLUME, | ||
312 | WM8400_LI12MUTE_SHIFT, 1, 0), | ||
313 | |||
314 | WM8400_OUTPGA_SINGLE_R_TLV("LIN34 Volume", | ||
315 | WM8400_LEFT_LINE_INPUT_3_4_VOLUME, | ||
316 | WM8400_LIN34VOL_SHIFT, | ||
317 | WM8400_LIN34VOL_MASK, | ||
318 | 0, | ||
319 | in_pga_tlv), | ||
320 | |||
321 | SOC_SINGLE("LIN34 ZC Switch", WM8400_LEFT_LINE_INPUT_3_4_VOLUME, | ||
322 | WM8400_LI34ZC_SHIFT, 1, 0), | ||
323 | |||
324 | SOC_SINGLE("LIN34 Mute Switch", WM8400_LEFT_LINE_INPUT_3_4_VOLUME, | ||
325 | WM8400_LI34MUTE_SHIFT, 1, 0), | ||
326 | |||
327 | WM8400_OUTPGA_SINGLE_R_TLV("RIN12 Volume", | ||
328 | WM8400_RIGHT_LINE_INPUT_1_2_VOLUME, | ||
329 | WM8400_RIN12VOL_SHIFT, | ||
330 | WM8400_RIN12VOL_MASK, | ||
331 | 0, | ||
332 | in_pga_tlv), | ||
333 | |||
334 | SOC_SINGLE("RIN12 ZC Switch", WM8400_RIGHT_LINE_INPUT_1_2_VOLUME, | ||
335 | WM8400_RI12ZC_SHIFT, 1, 0), | ||
336 | |||
337 | SOC_SINGLE("RIN12 Mute Switch", WM8400_RIGHT_LINE_INPUT_1_2_VOLUME, | ||
338 | WM8400_RI12MUTE_SHIFT, 1, 0), | ||
339 | |||
340 | WM8400_OUTPGA_SINGLE_R_TLV("RIN34 Volume", | ||
341 | WM8400_RIGHT_LINE_INPUT_3_4_VOLUME, | ||
342 | WM8400_RIN34VOL_SHIFT, | ||
343 | WM8400_RIN34VOL_MASK, | ||
344 | 0, | ||
345 | in_pga_tlv), | ||
346 | |||
347 | SOC_SINGLE("RIN34 ZC Switch", WM8400_RIGHT_LINE_INPUT_3_4_VOLUME, | ||
348 | WM8400_RI34ZC_SHIFT, 1, 0), | ||
349 | |||
350 | SOC_SINGLE("RIN34 Mute Switch", WM8400_RIGHT_LINE_INPUT_3_4_VOLUME, | ||
351 | WM8400_RI34MUTE_SHIFT, 1, 0), | ||
352 | |||
353 | }; | ||
354 | |||
355 | /* add non dapm controls */ | ||
356 | static int wm8400_add_controls(struct snd_soc_codec *codec) | ||
357 | { | ||
358 | return snd_soc_add_controls(codec, wm8400_snd_controls, | ||
359 | ARRAY_SIZE(wm8400_snd_controls)); | ||
360 | } | ||
361 | |||
362 | /* | ||
363 | * _DAPM_ Controls | ||
364 | */ | ||
365 | |||
366 | static int inmixer_event (struct snd_soc_dapm_widget *w, | ||
367 | struct snd_kcontrol *kcontrol, int event) | ||
368 | { | ||
369 | u16 reg, fakepower; | ||
370 | |||
371 | reg = wm8400_read(w->codec, WM8400_POWER_MANAGEMENT_2); | ||
372 | fakepower = wm8400_read(w->codec, WM8400_INTDRIVBITS); | ||
373 | |||
374 | if (fakepower & ((1 << WM8400_INMIXL_PWR) | | ||
375 | (1 << WM8400_AINLMUX_PWR))) { | ||
376 | reg |= WM8400_AINL_ENA; | ||
377 | } else { | ||
378 | reg &= ~WM8400_AINL_ENA; | ||
379 | } | ||
380 | |||
381 | if (fakepower & ((1 << WM8400_INMIXR_PWR) | | ||
382 | (1 << WM8400_AINRMUX_PWR))) { | ||
383 | reg |= WM8400_AINR_ENA; | ||
384 | } else { | ||
385 | reg &= ~WM8400_AINL_ENA; | ||
386 | } | ||
387 | wm8400_write(w->codec, WM8400_POWER_MANAGEMENT_2, reg); | ||
388 | |||
389 | return 0; | ||
390 | } | ||
391 | |||
392 | static int outmixer_event (struct snd_soc_dapm_widget *w, | ||
393 | struct snd_kcontrol * kcontrol, int event) | ||
394 | { | ||
395 | struct soc_mixer_control *mc = | ||
396 | (struct soc_mixer_control *)kcontrol->private_value; | ||
397 | u32 reg_shift = mc->shift; | ||
398 | int ret = 0; | ||
399 | u16 reg; | ||
400 | |||
401 | switch (reg_shift) { | ||
402 | case WM8400_SPEAKER_MIXER | (WM8400_LDSPK << 8) : | ||
403 | reg = wm8400_read(w->codec, WM8400_OUTPUT_MIXER1); | ||
404 | if (reg & WM8400_LDLO) { | ||
405 | printk(KERN_WARNING | ||
406 | "Cannot set as Output Mixer 1 LDLO Set\n"); | ||
407 | ret = -1; | ||
408 | } | ||
409 | break; | ||
410 | case WM8400_SPEAKER_MIXER | (WM8400_RDSPK << 8): | ||
411 | reg = wm8400_read(w->codec, WM8400_OUTPUT_MIXER2); | ||
412 | if (reg & WM8400_RDRO) { | ||
413 | printk(KERN_WARNING | ||
414 | "Cannot set as Output Mixer 2 RDRO Set\n"); | ||
415 | ret = -1; | ||
416 | } | ||
417 | break; | ||
418 | case WM8400_OUTPUT_MIXER1 | (WM8400_LDLO << 8): | ||
419 | reg = wm8400_read(w->codec, WM8400_SPEAKER_MIXER); | ||
420 | if (reg & WM8400_LDSPK) { | ||
421 | printk(KERN_WARNING | ||
422 | "Cannot set as Speaker Mixer LDSPK Set\n"); | ||
423 | ret = -1; | ||
424 | } | ||
425 | break; | ||
426 | case WM8400_OUTPUT_MIXER2 | (WM8400_RDRO << 8): | ||
427 | reg = wm8400_read(w->codec, WM8400_SPEAKER_MIXER); | ||
428 | if (reg & WM8400_RDSPK) { | ||
429 | printk(KERN_WARNING | ||
430 | "Cannot set as Speaker Mixer RDSPK Set\n"); | ||
431 | ret = -1; | ||
432 | } | ||
433 | break; | ||
434 | } | ||
435 | |||
436 | return ret; | ||
437 | } | ||
438 | |||
439 | /* INMIX dB values */ | ||
440 | static const unsigned int in_mix_tlv[] = { | ||
441 | TLV_DB_RANGE_HEAD(1), | ||
442 | 0,7, TLV_DB_LINEAR_ITEM(-1200, 600), | ||
443 | }; | ||
444 | |||
445 | /* Left In PGA Connections */ | ||
446 | static const struct snd_kcontrol_new wm8400_dapm_lin12_pga_controls[] = { | ||
447 | SOC_DAPM_SINGLE("LIN1 Switch", WM8400_INPUT_MIXER2, WM8400_LMN1_SHIFT, 1, 0), | ||
448 | SOC_DAPM_SINGLE("LIN2 Switch", WM8400_INPUT_MIXER2, WM8400_LMP2_SHIFT, 1, 0), | ||
449 | }; | ||
450 | |||
451 | static const struct snd_kcontrol_new wm8400_dapm_lin34_pga_controls[] = { | ||
452 | SOC_DAPM_SINGLE("LIN3 Switch", WM8400_INPUT_MIXER2, WM8400_LMN3_SHIFT, 1, 0), | ||
453 | SOC_DAPM_SINGLE("LIN4 Switch", WM8400_INPUT_MIXER2, WM8400_LMP4_SHIFT, 1, 0), | ||
454 | }; | ||
455 | |||
456 | /* Right In PGA Connections */ | ||
457 | static const struct snd_kcontrol_new wm8400_dapm_rin12_pga_controls[] = { | ||
458 | SOC_DAPM_SINGLE("RIN1 Switch", WM8400_INPUT_MIXER2, WM8400_RMN1_SHIFT, 1, 0), | ||
459 | SOC_DAPM_SINGLE("RIN2 Switch", WM8400_INPUT_MIXER2, WM8400_RMP2_SHIFT, 1, 0), | ||
460 | }; | ||
461 | |||
462 | static const struct snd_kcontrol_new wm8400_dapm_rin34_pga_controls[] = { | ||
463 | SOC_DAPM_SINGLE("RIN3 Switch", WM8400_INPUT_MIXER2, WM8400_RMN3_SHIFT, 1, 0), | ||
464 | SOC_DAPM_SINGLE("RIN4 Switch", WM8400_INPUT_MIXER2, WM8400_RMP4_SHIFT, 1, 0), | ||
465 | }; | ||
466 | |||
467 | /* INMIXL */ | ||
468 | static const struct snd_kcontrol_new wm8400_dapm_inmixl_controls[] = { | ||
469 | SOC_DAPM_SINGLE_TLV("Record Left Volume", WM8400_INPUT_MIXER3, | ||
470 | WM8400_LDBVOL_SHIFT, WM8400_LDBVOL_MASK, 0, in_mix_tlv), | ||
471 | SOC_DAPM_SINGLE_TLV("LIN2 Volume", WM8400_INPUT_MIXER5, WM8400_LI2BVOL_SHIFT, | ||
472 | 7, 0, in_mix_tlv), | ||
473 | SOC_DAPM_SINGLE("LINPGA12 Switch", WM8400_INPUT_MIXER3, WM8400_L12MNB_SHIFT, | ||
474 | 1, 0), | ||
475 | SOC_DAPM_SINGLE("LINPGA34 Switch", WM8400_INPUT_MIXER3, WM8400_L34MNB_SHIFT, | ||
476 | 1, 0), | ||
477 | }; | ||
478 | |||
479 | /* INMIXR */ | ||
480 | static const struct snd_kcontrol_new wm8400_dapm_inmixr_controls[] = { | ||
481 | SOC_DAPM_SINGLE_TLV("Record Right Volume", WM8400_INPUT_MIXER4, | ||
482 | WM8400_RDBVOL_SHIFT, WM8400_RDBVOL_MASK, 0, in_mix_tlv), | ||
483 | SOC_DAPM_SINGLE_TLV("RIN2 Volume", WM8400_INPUT_MIXER6, WM8400_RI2BVOL_SHIFT, | ||
484 | 7, 0, in_mix_tlv), | ||
485 | SOC_DAPM_SINGLE("RINPGA12 Switch", WM8400_INPUT_MIXER3, WM8400_L12MNB_SHIFT, | ||
486 | 1, 0), | ||
487 | SOC_DAPM_SINGLE("RINPGA34 Switch", WM8400_INPUT_MIXER3, WM8400_L34MNB_SHIFT, | ||
488 | 1, 0), | ||
489 | }; | ||
490 | |||
491 | /* AINLMUX */ | ||
492 | static const char *wm8400_ainlmux[] = | ||
493 | {"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"}; | ||
494 | |||
495 | static const struct soc_enum wm8400_ainlmux_enum = | ||
496 | SOC_ENUM_SINGLE( WM8400_INPUT_MIXER1, WM8400_AINLMODE_SHIFT, | ||
497 | ARRAY_SIZE(wm8400_ainlmux), wm8400_ainlmux); | ||
498 | |||
499 | static const struct snd_kcontrol_new wm8400_dapm_ainlmux_controls = | ||
500 | SOC_DAPM_ENUM("Route", wm8400_ainlmux_enum); | ||
501 | |||
502 | /* DIFFINL */ | ||
503 | |||
504 | /* AINRMUX */ | ||
505 | static const char *wm8400_ainrmux[] = | ||
506 | {"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"}; | ||
507 | |||
508 | static const struct soc_enum wm8400_ainrmux_enum = | ||
509 | SOC_ENUM_SINGLE( WM8400_INPUT_MIXER1, WM8400_AINRMODE_SHIFT, | ||
510 | ARRAY_SIZE(wm8400_ainrmux), wm8400_ainrmux); | ||
511 | |||
512 | static const struct snd_kcontrol_new wm8400_dapm_ainrmux_controls = | ||
513 | SOC_DAPM_ENUM("Route", wm8400_ainrmux_enum); | ||
514 | |||
515 | /* RXVOICE */ | ||
516 | static const struct snd_kcontrol_new wm8400_dapm_rxvoice_controls[] = { | ||
517 | SOC_DAPM_SINGLE_TLV("LIN4/RXN", WM8400_INPUT_MIXER5, WM8400_LR4BVOL_SHIFT, | ||
518 | WM8400_LR4BVOL_MASK, 0, in_mix_tlv), | ||
519 | SOC_DAPM_SINGLE_TLV("RIN4/RXP", WM8400_INPUT_MIXER6, WM8400_RL4BVOL_SHIFT, | ||
520 | WM8400_RL4BVOL_MASK, 0, in_mix_tlv), | ||
521 | }; | ||
522 | |||
523 | /* LOMIX */ | ||
524 | static const struct snd_kcontrol_new wm8400_dapm_lomix_controls[] = { | ||
525 | SOC_DAPM_SINGLE("LOMIX Right ADC Bypass Switch", WM8400_OUTPUT_MIXER1, | ||
526 | WM8400_LRBLO_SHIFT, 1, 0), | ||
527 | SOC_DAPM_SINGLE("LOMIX Left ADC Bypass Switch", WM8400_OUTPUT_MIXER1, | ||
528 | WM8400_LLBLO_SHIFT, 1, 0), | ||
529 | SOC_DAPM_SINGLE("LOMIX RIN3 Bypass Switch", WM8400_OUTPUT_MIXER1, | ||
530 | WM8400_LRI3LO_SHIFT, 1, 0), | ||
531 | SOC_DAPM_SINGLE("LOMIX LIN3 Bypass Switch", WM8400_OUTPUT_MIXER1, | ||
532 | WM8400_LLI3LO_SHIFT, 1, 0), | ||
533 | SOC_DAPM_SINGLE("LOMIX RIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER1, | ||
534 | WM8400_LR12LO_SHIFT, 1, 0), | ||
535 | SOC_DAPM_SINGLE("LOMIX LIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER1, | ||
536 | WM8400_LL12LO_SHIFT, 1, 0), | ||
537 | SOC_DAPM_SINGLE("LOMIX Left DAC Switch", WM8400_OUTPUT_MIXER1, | ||
538 | WM8400_LDLO_SHIFT, 1, 0), | ||
539 | }; | ||
540 | |||
541 | /* ROMIX */ | ||
542 | static const struct snd_kcontrol_new wm8400_dapm_romix_controls[] = { | ||
543 | SOC_DAPM_SINGLE("ROMIX Left ADC Bypass Switch", WM8400_OUTPUT_MIXER2, | ||
544 | WM8400_RLBRO_SHIFT, 1, 0), | ||
545 | SOC_DAPM_SINGLE("ROMIX Right ADC Bypass Switch", WM8400_OUTPUT_MIXER2, | ||
546 | WM8400_RRBRO_SHIFT, 1, 0), | ||
547 | SOC_DAPM_SINGLE("ROMIX LIN3 Bypass Switch", WM8400_OUTPUT_MIXER2, | ||
548 | WM8400_RLI3RO_SHIFT, 1, 0), | ||
549 | SOC_DAPM_SINGLE("ROMIX RIN3 Bypass Switch", WM8400_OUTPUT_MIXER2, | ||
550 | WM8400_RRI3RO_SHIFT, 1, 0), | ||
551 | SOC_DAPM_SINGLE("ROMIX LIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER2, | ||
552 | WM8400_RL12RO_SHIFT, 1, 0), | ||
553 | SOC_DAPM_SINGLE("ROMIX RIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER2, | ||
554 | WM8400_RR12RO_SHIFT, 1, 0), | ||
555 | SOC_DAPM_SINGLE("ROMIX Right DAC Switch", WM8400_OUTPUT_MIXER2, | ||
556 | WM8400_RDRO_SHIFT, 1, 0), | ||
557 | }; | ||
558 | |||
559 | /* LONMIX */ | ||
560 | static const struct snd_kcontrol_new wm8400_dapm_lonmix_controls[] = { | ||
561 | SOC_DAPM_SINGLE("LONMIX Left Mixer PGA Switch", WM8400_LINE_MIXER1, | ||
562 | WM8400_LLOPGALON_SHIFT, 1, 0), | ||
563 | SOC_DAPM_SINGLE("LONMIX Right Mixer PGA Switch", WM8400_LINE_MIXER1, | ||
564 | WM8400_LROPGALON_SHIFT, 1, 0), | ||
565 | SOC_DAPM_SINGLE("LONMIX Inverted LOP Switch", WM8400_LINE_MIXER1, | ||
566 | WM8400_LOPLON_SHIFT, 1, 0), | ||
567 | }; | ||
568 | |||
569 | /* LOPMIX */ | ||
570 | static const struct snd_kcontrol_new wm8400_dapm_lopmix_controls[] = { | ||
571 | SOC_DAPM_SINGLE("LOPMIX Right Mic Bypass Switch", WM8400_LINE_MIXER1, | ||
572 | WM8400_LR12LOP_SHIFT, 1, 0), | ||
573 | SOC_DAPM_SINGLE("LOPMIX Left Mic Bypass Switch", WM8400_LINE_MIXER1, | ||
574 | WM8400_LL12LOP_SHIFT, 1, 0), | ||
575 | SOC_DAPM_SINGLE("LOPMIX Left Mixer PGA Switch", WM8400_LINE_MIXER1, | ||
576 | WM8400_LLOPGALOP_SHIFT, 1, 0), | ||
577 | }; | ||
578 | |||
579 | /* RONMIX */ | ||
580 | static const struct snd_kcontrol_new wm8400_dapm_ronmix_controls[] = { | ||
581 | SOC_DAPM_SINGLE("RONMIX Right Mixer PGA Switch", WM8400_LINE_MIXER2, | ||
582 | WM8400_RROPGARON_SHIFT, 1, 0), | ||
583 | SOC_DAPM_SINGLE("RONMIX Left Mixer PGA Switch", WM8400_LINE_MIXER2, | ||
584 | WM8400_RLOPGARON_SHIFT, 1, 0), | ||
585 | SOC_DAPM_SINGLE("RONMIX Inverted ROP Switch", WM8400_LINE_MIXER2, | ||
586 | WM8400_ROPRON_SHIFT, 1, 0), | ||
587 | }; | ||
588 | |||
589 | /* ROPMIX */ | ||
590 | static const struct snd_kcontrol_new wm8400_dapm_ropmix_controls[] = { | ||
591 | SOC_DAPM_SINGLE("ROPMIX Left Mic Bypass Switch", WM8400_LINE_MIXER2, | ||
592 | WM8400_RL12ROP_SHIFT, 1, 0), | ||
593 | SOC_DAPM_SINGLE("ROPMIX Right Mic Bypass Switch", WM8400_LINE_MIXER2, | ||
594 | WM8400_RR12ROP_SHIFT, 1, 0), | ||
595 | SOC_DAPM_SINGLE("ROPMIX Right Mixer PGA Switch", WM8400_LINE_MIXER2, | ||
596 | WM8400_RROPGAROP_SHIFT, 1, 0), | ||
597 | }; | ||
598 | |||
599 | /* OUT3MIX */ | ||
600 | static const struct snd_kcontrol_new wm8400_dapm_out3mix_controls[] = { | ||
601 | SOC_DAPM_SINGLE("OUT3MIX LIN4/RXP Bypass Switch", WM8400_OUT3_4_MIXER, | ||
602 | WM8400_LI4O3_SHIFT, 1, 0), | ||
603 | SOC_DAPM_SINGLE("OUT3MIX Left Out PGA Switch", WM8400_OUT3_4_MIXER, | ||
604 | WM8400_LPGAO3_SHIFT, 1, 0), | ||
605 | }; | ||
606 | |||
607 | /* OUT4MIX */ | ||
608 | static const struct snd_kcontrol_new wm8400_dapm_out4mix_controls[] = { | ||
609 | SOC_DAPM_SINGLE("OUT4MIX Right Out PGA Switch", WM8400_OUT3_4_MIXER, | ||
610 | WM8400_RPGAO4_SHIFT, 1, 0), | ||
611 | SOC_DAPM_SINGLE("OUT4MIX RIN4/RXP Bypass Switch", WM8400_OUT3_4_MIXER, | ||
612 | WM8400_RI4O4_SHIFT, 1, 0), | ||
613 | }; | ||
614 | |||
615 | /* SPKMIX */ | ||
616 | static const struct snd_kcontrol_new wm8400_dapm_spkmix_controls[] = { | ||
617 | SOC_DAPM_SINGLE("SPKMIX LIN2 Bypass Switch", WM8400_SPEAKER_MIXER, | ||
618 | WM8400_LI2SPK_SHIFT, 1, 0), | ||
619 | SOC_DAPM_SINGLE("SPKMIX LADC Bypass Switch", WM8400_SPEAKER_MIXER, | ||
620 | WM8400_LB2SPK_SHIFT, 1, 0), | ||
621 | SOC_DAPM_SINGLE("SPKMIX Left Mixer PGA Switch", WM8400_SPEAKER_MIXER, | ||
622 | WM8400_LOPGASPK_SHIFT, 1, 0), | ||
623 | SOC_DAPM_SINGLE("SPKMIX Left DAC Switch", WM8400_SPEAKER_MIXER, | ||
624 | WM8400_LDSPK_SHIFT, 1, 0), | ||
625 | SOC_DAPM_SINGLE("SPKMIX Right DAC Switch", WM8400_SPEAKER_MIXER, | ||
626 | WM8400_RDSPK_SHIFT, 1, 0), | ||
627 | SOC_DAPM_SINGLE("SPKMIX Right Mixer PGA Switch", WM8400_SPEAKER_MIXER, | ||
628 | WM8400_ROPGASPK_SHIFT, 1, 0), | ||
629 | SOC_DAPM_SINGLE("SPKMIX RADC Bypass Switch", WM8400_SPEAKER_MIXER, | ||
630 | WM8400_RL12ROP_SHIFT, 1, 0), | ||
631 | SOC_DAPM_SINGLE("SPKMIX RIN2 Bypass Switch", WM8400_SPEAKER_MIXER, | ||
632 | WM8400_RI2SPK_SHIFT, 1, 0), | ||
633 | }; | ||
634 | |||
635 | static const struct snd_soc_dapm_widget wm8400_dapm_widgets[] = { | ||
636 | /* Input Side */ | ||
637 | /* Input Lines */ | ||
638 | SND_SOC_DAPM_INPUT("LIN1"), | ||
639 | SND_SOC_DAPM_INPUT("LIN2"), | ||
640 | SND_SOC_DAPM_INPUT("LIN3"), | ||
641 | SND_SOC_DAPM_INPUT("LIN4/RXN"), | ||
642 | SND_SOC_DAPM_INPUT("RIN3"), | ||
643 | SND_SOC_DAPM_INPUT("RIN4/RXP"), | ||
644 | SND_SOC_DAPM_INPUT("RIN1"), | ||
645 | SND_SOC_DAPM_INPUT("RIN2"), | ||
646 | SND_SOC_DAPM_INPUT("Internal ADC Source"), | ||
647 | |||
648 | /* DACs */ | ||
649 | SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8400_POWER_MANAGEMENT_2, | ||
650 | WM8400_ADCL_ENA_SHIFT, 0), | ||
651 | SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8400_POWER_MANAGEMENT_2, | ||
652 | WM8400_ADCR_ENA_SHIFT, 0), | ||
653 | |||
654 | /* Input PGAs */ | ||
655 | SND_SOC_DAPM_MIXER("LIN12 PGA", WM8400_POWER_MANAGEMENT_2, | ||
656 | WM8400_LIN12_ENA_SHIFT, | ||
657 | 0, &wm8400_dapm_lin12_pga_controls[0], | ||
658 | ARRAY_SIZE(wm8400_dapm_lin12_pga_controls)), | ||
659 | SND_SOC_DAPM_MIXER("LIN34 PGA", WM8400_POWER_MANAGEMENT_2, | ||
660 | WM8400_LIN34_ENA_SHIFT, | ||
661 | 0, &wm8400_dapm_lin34_pga_controls[0], | ||
662 | ARRAY_SIZE(wm8400_dapm_lin34_pga_controls)), | ||
663 | SND_SOC_DAPM_MIXER("RIN12 PGA", WM8400_POWER_MANAGEMENT_2, | ||
664 | WM8400_RIN12_ENA_SHIFT, | ||
665 | 0, &wm8400_dapm_rin12_pga_controls[0], | ||
666 | ARRAY_SIZE(wm8400_dapm_rin12_pga_controls)), | ||
667 | SND_SOC_DAPM_MIXER("RIN34 PGA", WM8400_POWER_MANAGEMENT_2, | ||
668 | WM8400_RIN34_ENA_SHIFT, | ||
669 | 0, &wm8400_dapm_rin34_pga_controls[0], | ||
670 | ARRAY_SIZE(wm8400_dapm_rin34_pga_controls)), | ||
671 | |||
672 | /* INMIXL */ | ||
673 | SND_SOC_DAPM_MIXER_E("INMIXL", WM8400_INTDRIVBITS, WM8400_INMIXL_PWR, 0, | ||
674 | &wm8400_dapm_inmixl_controls[0], | ||
675 | ARRAY_SIZE(wm8400_dapm_inmixl_controls), | ||
676 | inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), | ||
677 | |||
678 | /* AINLMUX */ | ||
679 | SND_SOC_DAPM_MUX_E("AILNMUX", WM8400_INTDRIVBITS, WM8400_AINLMUX_PWR, 0, | ||
680 | &wm8400_dapm_ainlmux_controls, inmixer_event, | ||
681 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), | ||
682 | |||
683 | /* INMIXR */ | ||
684 | SND_SOC_DAPM_MIXER_E("INMIXR", WM8400_INTDRIVBITS, WM8400_INMIXR_PWR, 0, | ||
685 | &wm8400_dapm_inmixr_controls[0], | ||
686 | ARRAY_SIZE(wm8400_dapm_inmixr_controls), | ||
687 | inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), | ||
688 | |||
689 | /* AINRMUX */ | ||
690 | SND_SOC_DAPM_MUX_E("AIRNMUX", WM8400_INTDRIVBITS, WM8400_AINRMUX_PWR, 0, | ||
691 | &wm8400_dapm_ainrmux_controls, inmixer_event, | ||
692 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), | ||
693 | |||
694 | /* Output Side */ | ||
695 | /* DACs */ | ||
696 | SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8400_POWER_MANAGEMENT_3, | ||
697 | WM8400_DACL_ENA_SHIFT, 0), | ||
698 | SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8400_POWER_MANAGEMENT_3, | ||
699 | WM8400_DACR_ENA_SHIFT, 0), | ||
700 | |||
701 | /* LOMIX */ | ||
702 | SND_SOC_DAPM_MIXER_E("LOMIX", WM8400_POWER_MANAGEMENT_3, | ||
703 | WM8400_LOMIX_ENA_SHIFT, | ||
704 | 0, &wm8400_dapm_lomix_controls[0], | ||
705 | ARRAY_SIZE(wm8400_dapm_lomix_controls), | ||
706 | outmixer_event, SND_SOC_DAPM_PRE_REG), | ||
707 | |||
708 | /* LONMIX */ | ||
709 | SND_SOC_DAPM_MIXER("LONMIX", WM8400_POWER_MANAGEMENT_3, WM8400_LON_ENA_SHIFT, | ||
710 | 0, &wm8400_dapm_lonmix_controls[0], | ||
711 | ARRAY_SIZE(wm8400_dapm_lonmix_controls)), | ||
712 | |||
713 | /* LOPMIX */ | ||
714 | SND_SOC_DAPM_MIXER("LOPMIX", WM8400_POWER_MANAGEMENT_3, WM8400_LOP_ENA_SHIFT, | ||
715 | 0, &wm8400_dapm_lopmix_controls[0], | ||
716 | ARRAY_SIZE(wm8400_dapm_lopmix_controls)), | ||
717 | |||
718 | /* OUT3MIX */ | ||
719 | SND_SOC_DAPM_MIXER("OUT3MIX", WM8400_POWER_MANAGEMENT_1, WM8400_OUT3_ENA_SHIFT, | ||
720 | 0, &wm8400_dapm_out3mix_controls[0], | ||
721 | ARRAY_SIZE(wm8400_dapm_out3mix_controls)), | ||
722 | |||
723 | /* SPKMIX */ | ||
724 | SND_SOC_DAPM_MIXER_E("SPKMIX", WM8400_POWER_MANAGEMENT_1, WM8400_SPK_ENA_SHIFT, | ||
725 | 0, &wm8400_dapm_spkmix_controls[0], | ||
726 | ARRAY_SIZE(wm8400_dapm_spkmix_controls), outmixer_event, | ||
727 | SND_SOC_DAPM_PRE_REG), | ||
728 | |||
729 | /* OUT4MIX */ | ||
730 | SND_SOC_DAPM_MIXER("OUT4MIX", WM8400_POWER_MANAGEMENT_1, WM8400_OUT4_ENA_SHIFT, | ||
731 | 0, &wm8400_dapm_out4mix_controls[0], | ||
732 | ARRAY_SIZE(wm8400_dapm_out4mix_controls)), | ||
733 | |||
734 | /* ROPMIX */ | ||
735 | SND_SOC_DAPM_MIXER("ROPMIX", WM8400_POWER_MANAGEMENT_3, WM8400_ROP_ENA_SHIFT, | ||
736 | 0, &wm8400_dapm_ropmix_controls[0], | ||
737 | ARRAY_SIZE(wm8400_dapm_ropmix_controls)), | ||
738 | |||
739 | /* RONMIX */ | ||
740 | SND_SOC_DAPM_MIXER("RONMIX", WM8400_POWER_MANAGEMENT_3, WM8400_RON_ENA_SHIFT, | ||
741 | 0, &wm8400_dapm_ronmix_controls[0], | ||
742 | ARRAY_SIZE(wm8400_dapm_ronmix_controls)), | ||
743 | |||
744 | /* ROMIX */ | ||
745 | SND_SOC_DAPM_MIXER_E("ROMIX", WM8400_POWER_MANAGEMENT_3, | ||
746 | WM8400_ROMIX_ENA_SHIFT, | ||
747 | 0, &wm8400_dapm_romix_controls[0], | ||
748 | ARRAY_SIZE(wm8400_dapm_romix_controls), | ||
749 | outmixer_event, SND_SOC_DAPM_PRE_REG), | ||
750 | |||
751 | /* LOUT PGA */ | ||
752 | SND_SOC_DAPM_PGA("LOUT PGA", WM8400_POWER_MANAGEMENT_1, WM8400_LOUT_ENA_SHIFT, | ||
753 | 0, NULL, 0), | ||
754 | |||
755 | /* ROUT PGA */ | ||
756 | SND_SOC_DAPM_PGA("ROUT PGA", WM8400_POWER_MANAGEMENT_1, WM8400_ROUT_ENA_SHIFT, | ||
757 | 0, NULL, 0), | ||
758 | |||
759 | /* LOPGA */ | ||
760 | SND_SOC_DAPM_PGA("LOPGA", WM8400_POWER_MANAGEMENT_3, WM8400_LOPGA_ENA_SHIFT, 0, | ||
761 | NULL, 0), | ||
762 | |||
763 | /* ROPGA */ | ||
764 | SND_SOC_DAPM_PGA("ROPGA", WM8400_POWER_MANAGEMENT_3, WM8400_ROPGA_ENA_SHIFT, 0, | ||
765 | NULL, 0), | ||
766 | |||
767 | /* MICBIAS */ | ||
768 | SND_SOC_DAPM_MICBIAS("MICBIAS", WM8400_POWER_MANAGEMENT_1, | ||
769 | WM8400_MIC1BIAS_ENA_SHIFT, 0), | ||
770 | |||
771 | SND_SOC_DAPM_OUTPUT("LON"), | ||
772 | SND_SOC_DAPM_OUTPUT("LOP"), | ||
773 | SND_SOC_DAPM_OUTPUT("OUT3"), | ||
774 | SND_SOC_DAPM_OUTPUT("LOUT"), | ||
775 | SND_SOC_DAPM_OUTPUT("SPKN"), | ||
776 | SND_SOC_DAPM_OUTPUT("SPKP"), | ||
777 | SND_SOC_DAPM_OUTPUT("ROUT"), | ||
778 | SND_SOC_DAPM_OUTPUT("OUT4"), | ||
779 | SND_SOC_DAPM_OUTPUT("ROP"), | ||
780 | SND_SOC_DAPM_OUTPUT("RON"), | ||
781 | |||
782 | SND_SOC_DAPM_OUTPUT("Internal DAC Sink"), | ||
783 | }; | ||
784 | |||
785 | static const struct snd_soc_dapm_route audio_map[] = { | ||
786 | /* Make DACs turn on when playing even if not mixed into any outputs */ | ||
787 | {"Internal DAC Sink", NULL, "Left DAC"}, | ||
788 | {"Internal DAC Sink", NULL, "Right DAC"}, | ||
789 | |||
790 | /* Make ADCs turn on when recording | ||
791 | * even if not mixed from any inputs */ | ||
792 | {"Left ADC", NULL, "Internal ADC Source"}, | ||
793 | {"Right ADC", NULL, "Internal ADC Source"}, | ||
794 | |||
795 | /* Input Side */ | ||
796 | /* LIN12 PGA */ | ||
797 | {"LIN12 PGA", "LIN1 Switch", "LIN1"}, | ||
798 | {"LIN12 PGA", "LIN2 Switch", "LIN2"}, | ||
799 | /* LIN34 PGA */ | ||
800 | {"LIN34 PGA", "LIN3 Switch", "LIN3"}, | ||
801 | {"LIN34 PGA", "LIN4 Switch", "LIN4/RXN"}, | ||
802 | /* INMIXL */ | ||
803 | {"INMIXL", "Record Left Volume", "LOMIX"}, | ||
804 | {"INMIXL", "LIN2 Volume", "LIN2"}, | ||
805 | {"INMIXL", "LINPGA12 Switch", "LIN12 PGA"}, | ||
806 | {"INMIXL", "LINPGA34 Switch", "LIN34 PGA"}, | ||
807 | /* AILNMUX */ | ||
808 | {"AILNMUX", "INMIXL Mix", "INMIXL"}, | ||
809 | {"AILNMUX", "DIFFINL Mix", "LIN12 PGA"}, | ||
810 | {"AILNMUX", "DIFFINL Mix", "LIN34 PGA"}, | ||
811 | {"AILNMUX", "RXVOICE Mix", "LIN4/RXN"}, | ||
812 | {"AILNMUX", "RXVOICE Mix", "RIN4/RXP"}, | ||
813 | /* ADC */ | ||
814 | {"Left ADC", NULL, "AILNMUX"}, | ||
815 | |||
816 | /* RIN12 PGA */ | ||
817 | {"RIN12 PGA", "RIN1 Switch", "RIN1"}, | ||
818 | {"RIN12 PGA", "RIN2 Switch", "RIN2"}, | ||
819 | /* RIN34 PGA */ | ||
820 | {"RIN34 PGA", "RIN3 Switch", "RIN3"}, | ||
821 | {"RIN34 PGA", "RIN4 Switch", "RIN4/RXP"}, | ||
822 | /* INMIXL */ | ||
823 | {"INMIXR", "Record Right Volume", "ROMIX"}, | ||
824 | {"INMIXR", "RIN2 Volume", "RIN2"}, | ||
825 | {"INMIXR", "RINPGA12 Switch", "RIN12 PGA"}, | ||
826 | {"INMIXR", "RINPGA34 Switch", "RIN34 PGA"}, | ||
827 | /* AIRNMUX */ | ||
828 | {"AIRNMUX", "INMIXR Mix", "INMIXR"}, | ||
829 | {"AIRNMUX", "DIFFINR Mix", "RIN12 PGA"}, | ||
830 | {"AIRNMUX", "DIFFINR Mix", "RIN34 PGA"}, | ||
831 | {"AIRNMUX", "RXVOICE Mix", "LIN4/RXN"}, | ||
832 | {"AIRNMUX", "RXVOICE Mix", "RIN4/RXP"}, | ||
833 | /* ADC */ | ||
834 | {"Right ADC", NULL, "AIRNMUX"}, | ||
835 | |||
836 | /* LOMIX */ | ||
837 | {"LOMIX", "LOMIX RIN3 Bypass Switch", "RIN3"}, | ||
838 | {"LOMIX", "LOMIX LIN3 Bypass Switch", "LIN3"}, | ||
839 | {"LOMIX", "LOMIX LIN12 PGA Bypass Switch", "LIN12 PGA"}, | ||
840 | {"LOMIX", "LOMIX RIN12 PGA Bypass Switch", "RIN12 PGA"}, | ||
841 | {"LOMIX", "LOMIX Right ADC Bypass Switch", "AIRNMUX"}, | ||
842 | {"LOMIX", "LOMIX Left ADC Bypass Switch", "AILNMUX"}, | ||
843 | {"LOMIX", "LOMIX Left DAC Switch", "Left DAC"}, | ||
844 | |||
845 | /* ROMIX */ | ||
846 | {"ROMIX", "ROMIX RIN3 Bypass Switch", "RIN3"}, | ||
847 | {"ROMIX", "ROMIX LIN3 Bypass Switch", "LIN3"}, | ||
848 | {"ROMIX", "ROMIX LIN12 PGA Bypass Switch", "LIN12 PGA"}, | ||
849 | {"ROMIX", "ROMIX RIN12 PGA Bypass Switch", "RIN12 PGA"}, | ||
850 | {"ROMIX", "ROMIX Right ADC Bypass Switch", "AIRNMUX"}, | ||
851 | {"ROMIX", "ROMIX Left ADC Bypass Switch", "AILNMUX"}, | ||
852 | {"ROMIX", "ROMIX Right DAC Switch", "Right DAC"}, | ||
853 | |||
854 | /* SPKMIX */ | ||
855 | {"SPKMIX", "SPKMIX LIN2 Bypass Switch", "LIN2"}, | ||
856 | {"SPKMIX", "SPKMIX RIN2 Bypass Switch", "RIN2"}, | ||
857 | {"SPKMIX", "SPKMIX LADC Bypass Switch", "AILNMUX"}, | ||
858 | {"SPKMIX", "SPKMIX RADC Bypass Switch", "AIRNMUX"}, | ||
859 | {"SPKMIX", "SPKMIX Left Mixer PGA Switch", "LOPGA"}, | ||
860 | {"SPKMIX", "SPKMIX Right Mixer PGA Switch", "ROPGA"}, | ||
861 | {"SPKMIX", "SPKMIX Right DAC Switch", "Right DAC"}, | ||
862 | {"SPKMIX", "SPKMIX Left DAC Switch", "Right DAC"}, | ||
863 | |||
864 | /* LONMIX */ | ||
865 | {"LONMIX", "LONMIX Left Mixer PGA Switch", "LOPGA"}, | ||
866 | {"LONMIX", "LONMIX Right Mixer PGA Switch", "ROPGA"}, | ||
867 | {"LONMIX", "LONMIX Inverted LOP Switch", "LOPMIX"}, | ||
868 | |||
869 | /* LOPMIX */ | ||
870 | {"LOPMIX", "LOPMIX Right Mic Bypass Switch", "RIN12 PGA"}, | ||
871 | {"LOPMIX", "LOPMIX Left Mic Bypass Switch", "LIN12 PGA"}, | ||
872 | {"LOPMIX", "LOPMIX Left Mixer PGA Switch", "LOPGA"}, | ||
873 | |||
874 | /* OUT3MIX */ | ||
875 | {"OUT3MIX", "OUT3MIX LIN4/RXP Bypass Switch", "LIN4/RXN"}, | ||
876 | {"OUT3MIX", "OUT3MIX Left Out PGA Switch", "LOPGA"}, | ||
877 | |||
878 | /* OUT4MIX */ | ||
879 | {"OUT4MIX", "OUT4MIX Right Out PGA Switch", "ROPGA"}, | ||
880 | {"OUT4MIX", "OUT4MIX RIN4/RXP Bypass Switch", "RIN4/RXP"}, | ||
881 | |||
882 | /* RONMIX */ | ||
883 | {"RONMIX", "RONMIX Right Mixer PGA Switch", "ROPGA"}, | ||
884 | {"RONMIX", "RONMIX Left Mixer PGA Switch", "LOPGA"}, | ||
885 | {"RONMIX", "RONMIX Inverted ROP Switch", "ROPMIX"}, | ||
886 | |||
887 | /* ROPMIX */ | ||
888 | {"ROPMIX", "ROPMIX Left Mic Bypass Switch", "LIN12 PGA"}, | ||
889 | {"ROPMIX", "ROPMIX Right Mic Bypass Switch", "RIN12 PGA"}, | ||
890 | {"ROPMIX", "ROPMIX Right Mixer PGA Switch", "ROPGA"}, | ||
891 | |||
892 | /* Out Mixer PGAs */ | ||
893 | {"LOPGA", NULL, "LOMIX"}, | ||
894 | {"ROPGA", NULL, "ROMIX"}, | ||
895 | |||
896 | {"LOUT PGA", NULL, "LOMIX"}, | ||
897 | {"ROUT PGA", NULL, "ROMIX"}, | ||
898 | |||
899 | /* Output Pins */ | ||
900 | {"LON", NULL, "LONMIX"}, | ||
901 | {"LOP", NULL, "LOPMIX"}, | ||
902 | {"OUT3", NULL, "OUT3MIX"}, | ||
903 | {"LOUT", NULL, "LOUT PGA"}, | ||
904 | {"SPKN", NULL, "SPKMIX"}, | ||
905 | {"ROUT", NULL, "ROUT PGA"}, | ||
906 | {"OUT4", NULL, "OUT4MIX"}, | ||
907 | {"ROP", NULL, "ROPMIX"}, | ||
908 | {"RON", NULL, "RONMIX"}, | ||
909 | }; | ||
910 | |||
911 | static int wm8400_add_widgets(struct snd_soc_codec *codec) | ||
912 | { | ||
913 | snd_soc_dapm_new_controls(codec, wm8400_dapm_widgets, | ||
914 | ARRAY_SIZE(wm8400_dapm_widgets)); | ||
915 | |||
916 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | ||
917 | |||
918 | snd_soc_dapm_new_widgets(codec); | ||
919 | return 0; | ||
920 | } | ||
921 | |||
922 | /* | ||
923 | * Clock after FLL and dividers | ||
924 | */ | ||
925 | static int wm8400_set_dai_sysclk(struct snd_soc_dai *codec_dai, | ||
926 | int clk_id, unsigned int freq, int dir) | ||
927 | { | ||
928 | struct snd_soc_codec *codec = codec_dai->codec; | ||
929 | struct wm8400_priv *wm8400 = codec->private_data; | ||
930 | |||
931 | wm8400->sysclk = freq; | ||
932 | return 0; | ||
933 | } | ||
934 | |||
935 | struct fll_factors { | ||
936 | u16 n; | ||
937 | u16 k; | ||
938 | u16 outdiv; | ||
939 | u16 fratio; | ||
940 | u16 freq_ref; | ||
941 | }; | ||
942 | |||
943 | #define FIXED_FLL_SIZE ((1 << 16) * 10) | ||
944 | |||
945 | static int fll_factors(struct wm8400_priv *wm8400, struct fll_factors *factors, | ||
946 | unsigned int Fref, unsigned int Fout) | ||
947 | { | ||
948 | u64 Kpart; | ||
949 | unsigned int K, Nmod, target; | ||
950 | |||
951 | factors->outdiv = 2; | ||
952 | while (Fout * factors->outdiv < 90000000 || | ||
953 | Fout * factors->outdiv > 100000000) { | ||
954 | factors->outdiv *= 2; | ||
955 | if (factors->outdiv > 32) { | ||
956 | dev_err(wm8400->wm8400->dev, | ||
957 | "Unsupported FLL output frequency %dHz\n", | ||
958 | Fout); | ||
959 | return -EINVAL; | ||
960 | } | ||
961 | } | ||
962 | target = Fout * factors->outdiv; | ||
963 | factors->outdiv = factors->outdiv >> 2; | ||
964 | |||
965 | if (Fref < 48000) | ||
966 | factors->freq_ref = 1; | ||
967 | else | ||
968 | factors->freq_ref = 0; | ||
969 | |||
970 | if (Fref < 1000000) | ||
971 | factors->fratio = 9; | ||
972 | else | ||
973 | factors->fratio = 0; | ||
974 | |||
975 | /* Ensure we have a fractional part */ | ||
976 | do { | ||
977 | if (Fref < 1000000) | ||
978 | factors->fratio--; | ||
979 | else | ||
980 | factors->fratio++; | ||
981 | |||
982 | if (factors->fratio < 1 || factors->fratio > 8) { | ||
983 | dev_err(wm8400->wm8400->dev, | ||
984 | "Unable to calculate FRATIO\n"); | ||
985 | return -EINVAL; | ||
986 | } | ||
987 | |||
988 | factors->n = target / (Fref * factors->fratio); | ||
989 | Nmod = target % (Fref * factors->fratio); | ||
990 | } while (Nmod == 0); | ||
991 | |||
992 | /* Calculate fractional part - scale up so we can round. */ | ||
993 | Kpart = FIXED_FLL_SIZE * (long long)Nmod; | ||
994 | |||
995 | do_div(Kpart, (Fref * factors->fratio)); | ||
996 | |||
997 | K = Kpart & 0xFFFFFFFF; | ||
998 | |||
999 | if ((K % 10) >= 5) | ||
1000 | K += 5; | ||
1001 | |||
1002 | /* Move down to proper range now rounding is done */ | ||
1003 | factors->k = K / 10; | ||
1004 | |||
1005 | dev_dbg(wm8400->wm8400->dev, | ||
1006 | "FLL: Fref=%d Fout=%d N=%x K=%x, FRATIO=%x OUTDIV=%x\n", | ||
1007 | Fref, Fout, | ||
1008 | factors->n, factors->k, factors->fratio, factors->outdiv); | ||
1009 | |||
1010 | return 0; | ||
1011 | } | ||
1012 | |||
1013 | static int wm8400_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, | ||
1014 | unsigned int freq_in, unsigned int freq_out) | ||
1015 | { | ||
1016 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1017 | struct wm8400_priv *wm8400 = codec->private_data; | ||
1018 | struct fll_factors factors; | ||
1019 | int ret; | ||
1020 | u16 reg; | ||
1021 | |||
1022 | if (freq_in == wm8400->fll_in && freq_out == wm8400->fll_out) | ||
1023 | return 0; | ||
1024 | |||
1025 | if (freq_out != 0) { | ||
1026 | ret = fll_factors(wm8400, &factors, freq_in, freq_out); | ||
1027 | if (ret != 0) | ||
1028 | return ret; | ||
1029 | } | ||
1030 | |||
1031 | wm8400->fll_out = freq_out; | ||
1032 | wm8400->fll_in = freq_in; | ||
1033 | |||
1034 | /* We *must* disable the FLL before any changes */ | ||
1035 | reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_2); | ||
1036 | reg &= ~WM8400_FLL_ENA; | ||
1037 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_2, reg); | ||
1038 | |||
1039 | reg = wm8400_read(codec, WM8400_FLL_CONTROL_1); | ||
1040 | reg &= ~WM8400_FLL_OSC_ENA; | ||
1041 | wm8400_write(codec, WM8400_FLL_CONTROL_1, reg); | ||
1042 | |||
1043 | if (freq_out == 0) | ||
1044 | return 0; | ||
1045 | |||
1046 | reg &= ~(WM8400_FLL_REF_FREQ | WM8400_FLL_FRATIO_MASK); | ||
1047 | reg |= WM8400_FLL_FRAC | factors.fratio; | ||
1048 | reg |= factors.freq_ref << WM8400_FLL_REF_FREQ_SHIFT; | ||
1049 | wm8400_write(codec, WM8400_FLL_CONTROL_1, reg); | ||
1050 | |||
1051 | wm8400_write(codec, WM8400_FLL_CONTROL_2, factors.k); | ||
1052 | wm8400_write(codec, WM8400_FLL_CONTROL_3, factors.n); | ||
1053 | |||
1054 | reg = wm8400_read(codec, WM8400_FLL_CONTROL_4); | ||
1055 | reg &= WM8400_FLL_OUTDIV_MASK; | ||
1056 | reg |= factors.outdiv; | ||
1057 | wm8400_write(codec, WM8400_FLL_CONTROL_4, reg); | ||
1058 | |||
1059 | return 0; | ||
1060 | } | ||
1061 | |||
1062 | /* | ||
1063 | * Sets ADC and Voice DAC format. | ||
1064 | */ | ||
1065 | static int wm8400_set_dai_fmt(struct snd_soc_dai *codec_dai, | ||
1066 | unsigned int fmt) | ||
1067 | { | ||
1068 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1069 | u16 audio1, audio3; | ||
1070 | |||
1071 | audio1 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_1); | ||
1072 | audio3 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_3); | ||
1073 | |||
1074 | /* set master/slave audio interface */ | ||
1075 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
1076 | case SND_SOC_DAIFMT_CBS_CFS: | ||
1077 | audio3 &= ~WM8400_AIF_MSTR1; | ||
1078 | break; | ||
1079 | case SND_SOC_DAIFMT_CBM_CFM: | ||
1080 | audio3 |= WM8400_AIF_MSTR1; | ||
1081 | break; | ||
1082 | default: | ||
1083 | return -EINVAL; | ||
1084 | } | ||
1085 | |||
1086 | audio1 &= ~WM8400_AIF_FMT_MASK; | ||
1087 | |||
1088 | /* interface format */ | ||
1089 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
1090 | case SND_SOC_DAIFMT_I2S: | ||
1091 | audio1 |= WM8400_AIF_FMT_I2S; | ||
1092 | audio1 &= ~WM8400_AIF_LRCLK_INV; | ||
1093 | break; | ||
1094 | case SND_SOC_DAIFMT_RIGHT_J: | ||
1095 | audio1 |= WM8400_AIF_FMT_RIGHTJ; | ||
1096 | audio1 &= ~WM8400_AIF_LRCLK_INV; | ||
1097 | break; | ||
1098 | case SND_SOC_DAIFMT_LEFT_J: | ||
1099 | audio1 |= WM8400_AIF_FMT_LEFTJ; | ||
1100 | audio1 &= ~WM8400_AIF_LRCLK_INV; | ||
1101 | break; | ||
1102 | case SND_SOC_DAIFMT_DSP_A: | ||
1103 | audio1 |= WM8400_AIF_FMT_DSP; | ||
1104 | audio1 &= ~WM8400_AIF_LRCLK_INV; | ||
1105 | break; | ||
1106 | case SND_SOC_DAIFMT_DSP_B: | ||
1107 | audio1 |= WM8400_AIF_FMT_DSP | WM8400_AIF_LRCLK_INV; | ||
1108 | break; | ||
1109 | default: | ||
1110 | return -EINVAL; | ||
1111 | } | ||
1112 | |||
1113 | wm8400_write(codec, WM8400_AUDIO_INTERFACE_1, audio1); | ||
1114 | wm8400_write(codec, WM8400_AUDIO_INTERFACE_3, audio3); | ||
1115 | return 0; | ||
1116 | } | ||
1117 | |||
1118 | static int wm8400_set_dai_clkdiv(struct snd_soc_dai *codec_dai, | ||
1119 | int div_id, int div) | ||
1120 | { | ||
1121 | struct snd_soc_codec *codec = codec_dai->codec; | ||
1122 | u16 reg; | ||
1123 | |||
1124 | switch (div_id) { | ||
1125 | case WM8400_MCLK_DIV: | ||
1126 | reg = wm8400_read(codec, WM8400_CLOCKING_2) & | ||
1127 | ~WM8400_MCLK_DIV_MASK; | ||
1128 | wm8400_write(codec, WM8400_CLOCKING_2, reg | div); | ||
1129 | break; | ||
1130 | case WM8400_DACCLK_DIV: | ||
1131 | reg = wm8400_read(codec, WM8400_CLOCKING_2) & | ||
1132 | ~WM8400_DAC_CLKDIV_MASK; | ||
1133 | wm8400_write(codec, WM8400_CLOCKING_2, reg | div); | ||
1134 | break; | ||
1135 | case WM8400_ADCCLK_DIV: | ||
1136 | reg = wm8400_read(codec, WM8400_CLOCKING_2) & | ||
1137 | ~WM8400_ADC_CLKDIV_MASK; | ||
1138 | wm8400_write(codec, WM8400_CLOCKING_2, reg | div); | ||
1139 | break; | ||
1140 | case WM8400_BCLK_DIV: | ||
1141 | reg = wm8400_read(codec, WM8400_CLOCKING_1) & | ||
1142 | ~WM8400_BCLK_DIV_MASK; | ||
1143 | wm8400_write(codec, WM8400_CLOCKING_1, reg | div); | ||
1144 | break; | ||
1145 | default: | ||
1146 | return -EINVAL; | ||
1147 | } | ||
1148 | |||
1149 | return 0; | ||
1150 | } | ||
1151 | |||
1152 | /* | ||
1153 | * Set PCM DAI bit size and sample rate. | ||
1154 | */ | ||
1155 | static int wm8400_hw_params(struct snd_pcm_substream *substream, | ||
1156 | struct snd_pcm_hw_params *params, | ||
1157 | struct snd_soc_dai *dai) | ||
1158 | { | ||
1159 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
1160 | struct snd_soc_device *socdev = rtd->socdev; | ||
1161 | struct snd_soc_codec *codec = socdev->card->codec; | ||
1162 | u16 audio1 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_1); | ||
1163 | |||
1164 | audio1 &= ~WM8400_AIF_WL_MASK; | ||
1165 | /* bit size */ | ||
1166 | switch (params_format(params)) { | ||
1167 | case SNDRV_PCM_FORMAT_S16_LE: | ||
1168 | break; | ||
1169 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
1170 | audio1 |= WM8400_AIF_WL_20BITS; | ||
1171 | break; | ||
1172 | case SNDRV_PCM_FORMAT_S24_LE: | ||
1173 | audio1 |= WM8400_AIF_WL_24BITS; | ||
1174 | break; | ||
1175 | case SNDRV_PCM_FORMAT_S32_LE: | ||
1176 | audio1 |= WM8400_AIF_WL_32BITS; | ||
1177 | break; | ||
1178 | } | ||
1179 | |||
1180 | wm8400_write(codec, WM8400_AUDIO_INTERFACE_1, audio1); | ||
1181 | return 0; | ||
1182 | } | ||
1183 | |||
1184 | static int wm8400_mute(struct snd_soc_dai *dai, int mute) | ||
1185 | { | ||
1186 | struct snd_soc_codec *codec = dai->codec; | ||
1187 | u16 val = wm8400_read(codec, WM8400_DAC_CTRL) & ~WM8400_DAC_MUTE; | ||
1188 | |||
1189 | if (mute) | ||
1190 | wm8400_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE); | ||
1191 | else | ||
1192 | wm8400_write(codec, WM8400_DAC_CTRL, val); | ||
1193 | |||
1194 | return 0; | ||
1195 | } | ||
1196 | |||
1197 | /* TODO: set bias for best performance at standby */ | ||
1198 | static int wm8400_set_bias_level(struct snd_soc_codec *codec, | ||
1199 | enum snd_soc_bias_level level) | ||
1200 | { | ||
1201 | struct wm8400_priv *wm8400 = codec->private_data; | ||
1202 | u16 val; | ||
1203 | int ret; | ||
1204 | |||
1205 | switch (level) { | ||
1206 | case SND_SOC_BIAS_ON: | ||
1207 | break; | ||
1208 | |||
1209 | case SND_SOC_BIAS_PREPARE: | ||
1210 | /* VMID=2*50k */ | ||
1211 | val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1) & | ||
1212 | ~WM8400_VMID_MODE_MASK; | ||
1213 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x2); | ||
1214 | break; | ||
1215 | |||
1216 | case SND_SOC_BIAS_STANDBY: | ||
1217 | if (codec->bias_level == SND_SOC_BIAS_OFF) { | ||
1218 | ret = regulator_bulk_enable(ARRAY_SIZE(power), | ||
1219 | &power[0]); | ||
1220 | if (ret != 0) { | ||
1221 | dev_err(wm8400->wm8400->dev, | ||
1222 | "Failed to enable regulators: %d\n", | ||
1223 | ret); | ||
1224 | return ret; | ||
1225 | } | ||
1226 | |||
1227 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, | ||
1228 | WM8400_CODEC_ENA | WM8400_SYSCLK_ENA); | ||
1229 | |||
1230 | /* Enable POBCTRL, SOFT_ST, VMIDTOG and BUFDCOPEN */ | ||
1231 | wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | | ||
1232 | WM8400_BUFDCOPEN | WM8400_POBCTRL); | ||
1233 | |||
1234 | msleep(50); | ||
1235 | |||
1236 | /* Enable VREF & VMID at 2x50k */ | ||
1237 | val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1); | ||
1238 | val |= 0x2 | WM8400_VREF_ENA; | ||
1239 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val); | ||
1240 | |||
1241 | /* Enable BUFIOEN */ | ||
1242 | wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | | ||
1243 | WM8400_BUFDCOPEN | WM8400_POBCTRL | | ||
1244 | WM8400_BUFIOEN); | ||
1245 | |||
1246 | /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ | ||
1247 | wm8400_write(codec, WM8400_ANTIPOP2, WM8400_BUFIOEN); | ||
1248 | } | ||
1249 | |||
1250 | /* VMID=2*300k */ | ||
1251 | val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1) & | ||
1252 | ~WM8400_VMID_MODE_MASK; | ||
1253 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x4); | ||
1254 | break; | ||
1255 | |||
1256 | case SND_SOC_BIAS_OFF: | ||
1257 | /* Enable POBCTRL and SOFT_ST */ | ||
1258 | wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | | ||
1259 | WM8400_POBCTRL | WM8400_BUFIOEN); | ||
1260 | |||
1261 | /* Enable POBCTRL, SOFT_ST and BUFDCOPEN */ | ||
1262 | wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST | | ||
1263 | WM8400_BUFDCOPEN | WM8400_POBCTRL | | ||
1264 | WM8400_BUFIOEN); | ||
1265 | |||
1266 | /* mute DAC */ | ||
1267 | val = wm8400_read(codec, WM8400_DAC_CTRL); | ||
1268 | wm8400_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE); | ||
1269 | |||
1270 | /* Enable any disabled outputs */ | ||
1271 | val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1); | ||
1272 | val |= WM8400_SPK_ENA | WM8400_OUT3_ENA | | ||
1273 | WM8400_OUT4_ENA | WM8400_LOUT_ENA | | ||
1274 | WM8400_ROUT_ENA; | ||
1275 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val); | ||
1276 | |||
1277 | /* Disable VMID */ | ||
1278 | val &= ~WM8400_VMID_MODE_MASK; | ||
1279 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val); | ||
1280 | |||
1281 | msleep(300); | ||
1282 | |||
1283 | /* Enable all output discharge bits */ | ||
1284 | wm8400_write(codec, WM8400_ANTIPOP1, WM8400_DIS_LLINE | | ||
1285 | WM8400_DIS_RLINE | WM8400_DIS_OUT3 | | ||
1286 | WM8400_DIS_OUT4 | WM8400_DIS_LOUT | | ||
1287 | WM8400_DIS_ROUT); | ||
1288 | |||
1289 | /* Disable VREF */ | ||
1290 | val &= ~WM8400_VREF_ENA; | ||
1291 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val); | ||
1292 | |||
1293 | /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ | ||
1294 | wm8400_write(codec, WM8400_ANTIPOP2, 0x0); | ||
1295 | |||
1296 | ret = regulator_bulk_disable(ARRAY_SIZE(power), | ||
1297 | &power[0]); | ||
1298 | if (ret != 0) | ||
1299 | return ret; | ||
1300 | |||
1301 | break; | ||
1302 | } | ||
1303 | |||
1304 | codec->bias_level = level; | ||
1305 | return 0; | ||
1306 | } | ||
1307 | |||
1308 | #define WM8400_RATES SNDRV_PCM_RATE_8000_96000 | ||
1309 | |||
1310 | #define WM8400_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | ||
1311 | SNDRV_PCM_FMTBIT_S24_LE) | ||
1312 | |||
1313 | static struct snd_soc_dai_ops wm8400_dai_ops = { | ||
1314 | .hw_params = wm8400_hw_params, | ||
1315 | .digital_mute = wm8400_mute, | ||
1316 | .set_fmt = wm8400_set_dai_fmt, | ||
1317 | .set_clkdiv = wm8400_set_dai_clkdiv, | ||
1318 | .set_sysclk = wm8400_set_dai_sysclk, | ||
1319 | .set_pll = wm8400_set_dai_pll, | ||
1320 | }; | ||
1321 | |||
1322 | /* | ||
1323 | * The WM8400 supports 2 different and mutually exclusive DAI | ||
1324 | * configurations. | ||
1325 | * | ||
1326 | * 1. ADC/DAC on Primary Interface | ||
1327 | * 2. ADC on Primary Interface/DAC on secondary | ||
1328 | */ | ||
1329 | struct snd_soc_dai wm8400_dai = { | ||
1330 | /* ADC/DAC on primary */ | ||
1331 | .name = "WM8400 ADC/DAC Primary", | ||
1332 | .id = 1, | ||
1333 | .playback = { | ||
1334 | .stream_name = "Playback", | ||
1335 | .channels_min = 1, | ||
1336 | .channels_max = 2, | ||
1337 | .rates = WM8400_RATES, | ||
1338 | .formats = WM8400_FORMATS, | ||
1339 | }, | ||
1340 | .capture = { | ||
1341 | .stream_name = "Capture", | ||
1342 | .channels_min = 1, | ||
1343 | .channels_max = 2, | ||
1344 | .rates = WM8400_RATES, | ||
1345 | .formats = WM8400_FORMATS, | ||
1346 | }, | ||
1347 | .ops = &wm8400_dai_ops, | ||
1348 | }; | ||
1349 | EXPORT_SYMBOL_GPL(wm8400_dai); | ||
1350 | |||
1351 | static int wm8400_suspend(struct platform_device *pdev, pm_message_t state) | ||
1352 | { | ||
1353 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1354 | struct snd_soc_codec *codec = socdev->card->codec; | ||
1355 | |||
1356 | wm8400_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
1357 | |||
1358 | return 0; | ||
1359 | } | ||
1360 | |||
1361 | static int wm8400_resume(struct platform_device *pdev) | ||
1362 | { | ||
1363 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1364 | struct snd_soc_codec *codec = socdev->card->codec; | ||
1365 | |||
1366 | wm8400_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
1367 | |||
1368 | return 0; | ||
1369 | } | ||
1370 | |||
1371 | static struct snd_soc_codec *wm8400_codec; | ||
1372 | |||
1373 | static int wm8400_probe(struct platform_device *pdev) | ||
1374 | { | ||
1375 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1376 | struct snd_soc_codec *codec; | ||
1377 | int ret; | ||
1378 | |||
1379 | if (!wm8400_codec) { | ||
1380 | dev_err(&pdev->dev, "wm8400 not yet discovered\n"); | ||
1381 | return -ENODEV; | ||
1382 | } | ||
1383 | codec = wm8400_codec; | ||
1384 | |||
1385 | socdev->card->codec = codec; | ||
1386 | |||
1387 | /* register pcms */ | ||
1388 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
1389 | if (ret < 0) { | ||
1390 | dev_err(&pdev->dev, "failed to create pcms\n"); | ||
1391 | goto pcm_err; | ||
1392 | } | ||
1393 | |||
1394 | wm8400_add_controls(codec); | ||
1395 | wm8400_add_widgets(codec); | ||
1396 | |||
1397 | ret = snd_soc_init_card(socdev); | ||
1398 | if (ret < 0) { | ||
1399 | dev_err(&pdev->dev, "failed to register card\n"); | ||
1400 | goto card_err; | ||
1401 | } | ||
1402 | |||
1403 | return ret; | ||
1404 | |||
1405 | card_err: | ||
1406 | snd_soc_free_pcms(socdev); | ||
1407 | snd_soc_dapm_free(socdev); | ||
1408 | pcm_err: | ||
1409 | return ret; | ||
1410 | } | ||
1411 | |||
1412 | /* power down chip */ | ||
1413 | static int wm8400_remove(struct platform_device *pdev) | ||
1414 | { | ||
1415 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1416 | |||
1417 | snd_soc_free_pcms(socdev); | ||
1418 | snd_soc_dapm_free(socdev); | ||
1419 | |||
1420 | return 0; | ||
1421 | } | ||
1422 | |||
1423 | struct snd_soc_codec_device soc_codec_dev_wm8400 = { | ||
1424 | .probe = wm8400_probe, | ||
1425 | .remove = wm8400_remove, | ||
1426 | .suspend = wm8400_suspend, | ||
1427 | .resume = wm8400_resume, | ||
1428 | }; | ||
1429 | |||
1430 | static void wm8400_probe_deferred(struct work_struct *work) | ||
1431 | { | ||
1432 | struct wm8400_priv *priv = container_of(work, struct wm8400_priv, | ||
1433 | work); | ||
1434 | struct snd_soc_codec *codec = &priv->codec; | ||
1435 | int ret; | ||
1436 | |||
1437 | /* charge output caps */ | ||
1438 | wm8400_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
1439 | |||
1440 | /* We're done, tell the subsystem. */ | ||
1441 | ret = snd_soc_register_codec(codec); | ||
1442 | if (ret != 0) { | ||
1443 | dev_err(priv->wm8400->dev, | ||
1444 | "Failed to register codec: %d\n", ret); | ||
1445 | goto err; | ||
1446 | } | ||
1447 | |||
1448 | ret = snd_soc_register_dai(&wm8400_dai); | ||
1449 | if (ret != 0) { | ||
1450 | dev_err(priv->wm8400->dev, | ||
1451 | "Failed to register DAI: %d\n", ret); | ||
1452 | goto err_codec; | ||
1453 | } | ||
1454 | |||
1455 | return; | ||
1456 | |||
1457 | err_codec: | ||
1458 | snd_soc_unregister_codec(codec); | ||
1459 | err: | ||
1460 | wm8400_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
1461 | } | ||
1462 | |||
1463 | static int wm8400_codec_probe(struct platform_device *dev) | ||
1464 | { | ||
1465 | struct wm8400_priv *priv; | ||
1466 | int ret; | ||
1467 | u16 reg; | ||
1468 | struct snd_soc_codec *codec; | ||
1469 | |||
1470 | priv = kzalloc(sizeof(struct wm8400_priv), GFP_KERNEL); | ||
1471 | if (priv == NULL) | ||
1472 | return -ENOMEM; | ||
1473 | |||
1474 | codec = &priv->codec; | ||
1475 | codec->private_data = priv; | ||
1476 | codec->control_data = dev->dev.driver_data; | ||
1477 | priv->wm8400 = dev->dev.driver_data; | ||
1478 | |||
1479 | ret = regulator_bulk_get(priv->wm8400->dev, | ||
1480 | ARRAY_SIZE(power), &power[0]); | ||
1481 | if (ret != 0) { | ||
1482 | dev_err(&dev->dev, "Failed to get regulators: %d\n", ret); | ||
1483 | goto err; | ||
1484 | } | ||
1485 | |||
1486 | codec->dev = &dev->dev; | ||
1487 | wm8400_dai.dev = &dev->dev; | ||
1488 | |||
1489 | codec->name = "WM8400"; | ||
1490 | codec->owner = THIS_MODULE; | ||
1491 | codec->read = wm8400_read; | ||
1492 | codec->write = wm8400_write; | ||
1493 | codec->bias_level = SND_SOC_BIAS_OFF; | ||
1494 | codec->set_bias_level = wm8400_set_bias_level; | ||
1495 | codec->dai = &wm8400_dai; | ||
1496 | codec->num_dai = 1; | ||
1497 | codec->reg_cache_size = WM8400_REGISTER_COUNT; | ||
1498 | mutex_init(&codec->mutex); | ||
1499 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
1500 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
1501 | INIT_WORK(&priv->work, wm8400_probe_deferred); | ||
1502 | |||
1503 | wm8400_codec_reset(codec); | ||
1504 | |||
1505 | reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1); | ||
1506 | wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, reg | WM8400_CODEC_ENA); | ||
1507 | |||
1508 | /* Latch volume update bits */ | ||
1509 | reg = wm8400_read(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME); | ||
1510 | wm8400_write(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME, | ||
1511 | reg & WM8400_IPVU); | ||
1512 | reg = wm8400_read(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME); | ||
1513 | wm8400_write(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME, | ||
1514 | reg & WM8400_IPVU); | ||
1515 | |||
1516 | wm8400_write(codec, WM8400_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8)); | ||
1517 | wm8400_write(codec, WM8400_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8)); | ||
1518 | |||
1519 | wm8400_codec = codec; | ||
1520 | |||
1521 | if (!schedule_work(&priv->work)) { | ||
1522 | ret = -EINVAL; | ||
1523 | goto err_regulator; | ||
1524 | } | ||
1525 | |||
1526 | return 0; | ||
1527 | |||
1528 | err_regulator: | ||
1529 | wm8400_codec = NULL; | ||
1530 | regulator_bulk_free(ARRAY_SIZE(power), power); | ||
1531 | err: | ||
1532 | kfree(priv); | ||
1533 | return ret; | ||
1534 | } | ||
1535 | |||
1536 | static int __exit wm8400_codec_remove(struct platform_device *dev) | ||
1537 | { | ||
1538 | struct wm8400_priv *priv = wm8400_codec->private_data; | ||
1539 | u16 reg; | ||
1540 | |||
1541 | snd_soc_unregister_dai(&wm8400_dai); | ||
1542 | snd_soc_unregister_codec(wm8400_codec); | ||
1543 | |||
1544 | reg = wm8400_read(wm8400_codec, WM8400_POWER_MANAGEMENT_1); | ||
1545 | wm8400_write(wm8400_codec, WM8400_POWER_MANAGEMENT_1, | ||
1546 | reg & (~WM8400_CODEC_ENA)); | ||
1547 | |||
1548 | regulator_bulk_free(ARRAY_SIZE(power), power); | ||
1549 | kfree(priv); | ||
1550 | |||
1551 | wm8400_codec = NULL; | ||
1552 | |||
1553 | return 0; | ||
1554 | } | ||
1555 | |||
1556 | static struct platform_driver wm8400_codec_driver = { | ||
1557 | .driver = { | ||
1558 | .name = "wm8400-codec", | ||
1559 | .owner = THIS_MODULE, | ||
1560 | }, | ||
1561 | .probe = wm8400_codec_probe, | ||
1562 | .remove = __exit_p(wm8400_codec_remove), | ||
1563 | }; | ||
1564 | |||
1565 | static int __init wm8400_codec_init(void) | ||
1566 | { | ||
1567 | return platform_driver_register(&wm8400_codec_driver); | ||
1568 | } | ||
1569 | module_init(wm8400_codec_init); | ||
1570 | |||
1571 | static void __exit wm8400_codec_exit(void) | ||
1572 | { | ||
1573 | platform_driver_unregister(&wm8400_codec_driver); | ||
1574 | } | ||
1575 | module_exit(wm8400_codec_exit); | ||
1576 | |||
1577 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8400); | ||
1578 | |||
1579 | MODULE_DESCRIPTION("ASoC WM8400 driver"); | ||
1580 | MODULE_AUTHOR("Mark Brown"); | ||
1581 | MODULE_LICENSE("GPL"); | ||
1582 | MODULE_ALIAS("platform:wm8400-codec"); | ||
diff --git a/sound/soc/codecs/wm8400.h b/sound/soc/codecs/wm8400.h new file mode 100644 index 000000000000..79c5934d4776 --- /dev/null +++ b/sound/soc/codecs/wm8400.h | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * wm8400.h -- audio driver for WM8400 | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics PLC. | ||
5 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
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 | ||
10 | * option) any later version. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #ifndef _WM8400_CODEC_H | ||
15 | #define _WM8400_CODEC_H | ||
16 | |||
17 | #define WM8400_MCLK_DIV 0 | ||
18 | #define WM8400_DACCLK_DIV 1 | ||
19 | #define WM8400_ADCCLK_DIV 2 | ||
20 | #define WM8400_BCLK_DIV 3 | ||
21 | |||
22 | #define WM8400_MCLK_DIV_1 0x400 | ||
23 | #define WM8400_MCLK_DIV_2 0x800 | ||
24 | |||
25 | #define WM8400_DAC_CLKDIV_1 0x00 | ||
26 | #define WM8400_DAC_CLKDIV_1_5 0x04 | ||
27 | #define WM8400_DAC_CLKDIV_2 0x08 | ||
28 | #define WM8400_DAC_CLKDIV_3 0x0c | ||
29 | #define WM8400_DAC_CLKDIV_4 0x10 | ||
30 | #define WM8400_DAC_CLKDIV_5_5 0x14 | ||
31 | #define WM8400_DAC_CLKDIV_6 0x18 | ||
32 | |||
33 | #define WM8400_ADC_CLKDIV_1 0x00 | ||
34 | #define WM8400_ADC_CLKDIV_1_5 0x20 | ||
35 | #define WM8400_ADC_CLKDIV_2 0x40 | ||
36 | #define WM8400_ADC_CLKDIV_3 0x60 | ||
37 | #define WM8400_ADC_CLKDIV_4 0x80 | ||
38 | #define WM8400_ADC_CLKDIV_5_5 0xa0 | ||
39 | #define WM8400_ADC_CLKDIV_6 0xc0 | ||
40 | |||
41 | |||
42 | #define WM8400_BCLK_DIV_1 (0x0 << 1) | ||
43 | #define WM8400_BCLK_DIV_1_5 (0x1 << 1) | ||
44 | #define WM8400_BCLK_DIV_2 (0x2 << 1) | ||
45 | #define WM8400_BCLK_DIV_3 (0x3 << 1) | ||
46 | #define WM8400_BCLK_DIV_4 (0x4 << 1) | ||
47 | #define WM8400_BCLK_DIV_5_5 (0x5 << 1) | ||
48 | #define WM8400_BCLK_DIV_6 (0x6 << 1) | ||
49 | #define WM8400_BCLK_DIV_8 (0x7 << 1) | ||
50 | #define WM8400_BCLK_DIV_11 (0x8 << 1) | ||
51 | #define WM8400_BCLK_DIV_12 (0x9 << 1) | ||
52 | #define WM8400_BCLK_DIV_16 (0xA << 1) | ||
53 | #define WM8400_BCLK_DIV_22 (0xB << 1) | ||
54 | #define WM8400_BCLK_DIV_24 (0xC << 1) | ||
55 | #define WM8400_BCLK_DIV_32 (0xD << 1) | ||
56 | #define WM8400_BCLK_DIV_44 (0xE << 1) | ||
57 | #define WM8400_BCLK_DIV_48 (0xF << 1) | ||
58 | |||
59 | extern struct snd_soc_dai wm8400_dai; | ||
60 | extern struct snd_soc_codec_device soc_codec_dev_wm8400; | ||
61 | |||
62 | #endif | ||
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c index 40f8238df717..6a4cea09c45d 100644 --- a/sound/soc/codecs/wm8510.c +++ b/sound/soc/codecs/wm8510.c | |||
@@ -171,22 +171,6 @@ SOC_SINGLE("Capture Boost(+20dB)", WM8510_ADCBOOST, 8, 1, 0), | |||
171 | SOC_SINGLE("Mono Playback Switch", WM8510_MONOMIX, 6, 1, 1), | 171 | SOC_SINGLE("Mono Playback Switch", WM8510_MONOMIX, 6, 1, 1), |
172 | }; | 172 | }; |
173 | 173 | ||
174 | /* add non dapm controls */ | ||
175 | static int wm8510_add_controls(struct snd_soc_codec *codec) | ||
176 | { | ||
177 | int err, i; | ||
178 | |||
179 | for (i = 0; i < ARRAY_SIZE(wm8510_snd_controls); i++) { | ||
180 | err = snd_ctl_add(codec->card, | ||
181 | snd_soc_cnew(&wm8510_snd_controls[i], codec, | ||
182 | NULL)); | ||
183 | if (err < 0) | ||
184 | return err; | ||
185 | } | ||
186 | |||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | /* Speaker Output Mixer */ | 174 | /* Speaker Output Mixer */ |
191 | static const struct snd_kcontrol_new wm8510_speaker_mixer_controls[] = { | 175 | static const struct snd_kcontrol_new wm8510_speaker_mixer_controls[] = { |
192 | SOC_DAPM_SINGLE("Line Bypass Switch", WM8510_SPKMIX, 1, 1, 0), | 176 | SOC_DAPM_SINGLE("Line Bypass Switch", WM8510_SPKMIX, 1, 1, 0), |
@@ -352,7 +336,7 @@ static int wm8510_set_dai_pll(struct snd_soc_dai *codec_dai, | |||
352 | return 0; | 336 | return 0; |
353 | } | 337 | } |
354 | 338 | ||
355 | pll_factors(freq_out*8, freq_in); | 339 | pll_factors(freq_out*4, freq_in); |
356 | 340 | ||
357 | wm8510_write(codec, WM8510_PLLN, (pll_div.pre_div << 4) | pll_div.n); | 341 | wm8510_write(codec, WM8510_PLLN, (pll_div.pre_div << 4) | pll_div.n); |
358 | wm8510_write(codec, WM8510_PLLK1, pll_div.k >> 18); | 342 | wm8510_write(codec, WM8510_PLLK1, pll_div.k >> 18); |
@@ -383,7 +367,7 @@ static int wm8510_set_dai_clkdiv(struct snd_soc_dai *codec_dai, | |||
383 | wm8510_write(codec, WM8510_GPIO, reg | div); | 367 | wm8510_write(codec, WM8510_GPIO, reg | div); |
384 | break; | 368 | break; |
385 | case WM8510_MCLKDIV: | 369 | case WM8510_MCLKDIV: |
386 | reg = wm8510_read_reg_cache(codec, WM8510_CLOCK) & 0x1f; | 370 | reg = wm8510_read_reg_cache(codec, WM8510_CLOCK) & 0x11f; |
387 | wm8510_write(codec, WM8510_CLOCK, reg | div); | 371 | wm8510_write(codec, WM8510_CLOCK, reg | div); |
388 | break; | 372 | break; |
389 | case WM8510_ADCCLK: | 373 | case WM8510_ADCCLK: |
@@ -468,7 +452,7 @@ static int wm8510_pcm_hw_params(struct snd_pcm_substream *substream, | |||
468 | { | 452 | { |
469 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 453 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
470 | struct snd_soc_device *socdev = rtd->socdev; | 454 | struct snd_soc_device *socdev = rtd->socdev; |
471 | struct snd_soc_codec *codec = socdev->codec; | 455 | struct snd_soc_codec *codec = socdev->card->codec; |
472 | u16 iface = wm8510_read_reg_cache(codec, WM8510_IFACE) & 0x19f; | 456 | u16 iface = wm8510_read_reg_cache(codec, WM8510_IFACE) & 0x19f; |
473 | u16 adn = wm8510_read_reg_cache(codec, WM8510_ADD) & 0x1f1; | 457 | u16 adn = wm8510_read_reg_cache(codec, WM8510_ADD) & 0x1f1; |
474 | 458 | ||
@@ -570,6 +554,14 @@ static int wm8510_set_bias_level(struct snd_soc_codec *codec, | |||
570 | #define WM8510_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | 554 | #define WM8510_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
571 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) | 555 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
572 | 556 | ||
557 | static struct snd_soc_dai_ops wm8510_dai_ops = { | ||
558 | .hw_params = wm8510_pcm_hw_params, | ||
559 | .digital_mute = wm8510_mute, | ||
560 | .set_fmt = wm8510_set_dai_fmt, | ||
561 | .set_clkdiv = wm8510_set_dai_clkdiv, | ||
562 | .set_pll = wm8510_set_dai_pll, | ||
563 | }; | ||
564 | |||
573 | struct snd_soc_dai wm8510_dai = { | 565 | struct snd_soc_dai wm8510_dai = { |
574 | .name = "WM8510 HiFi", | 566 | .name = "WM8510 HiFi", |
575 | .playback = { | 567 | .playback = { |
@@ -584,20 +576,14 @@ struct snd_soc_dai wm8510_dai = { | |||
584 | .channels_max = 2, | 576 | .channels_max = 2, |
585 | .rates = WM8510_RATES, | 577 | .rates = WM8510_RATES, |
586 | .formats = WM8510_FORMATS,}, | 578 | .formats = WM8510_FORMATS,}, |
587 | .ops = { | 579 | .ops = &wm8510_dai_ops, |
588 | .hw_params = wm8510_pcm_hw_params, | ||
589 | .digital_mute = wm8510_mute, | ||
590 | .set_fmt = wm8510_set_dai_fmt, | ||
591 | .set_clkdiv = wm8510_set_dai_clkdiv, | ||
592 | .set_pll = wm8510_set_dai_pll, | ||
593 | }, | ||
594 | }; | 580 | }; |
595 | EXPORT_SYMBOL_GPL(wm8510_dai); | 581 | EXPORT_SYMBOL_GPL(wm8510_dai); |
596 | 582 | ||
597 | static int wm8510_suspend(struct platform_device *pdev, pm_message_t state) | 583 | static int wm8510_suspend(struct platform_device *pdev, pm_message_t state) |
598 | { | 584 | { |
599 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 585 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
600 | struct snd_soc_codec *codec = socdev->codec; | 586 | struct snd_soc_codec *codec = socdev->card->codec; |
601 | 587 | ||
602 | wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF); | 588 | wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF); |
603 | return 0; | 589 | return 0; |
@@ -606,7 +592,7 @@ static int wm8510_suspend(struct platform_device *pdev, pm_message_t state) | |||
606 | static int wm8510_resume(struct platform_device *pdev) | 592 | static int wm8510_resume(struct platform_device *pdev) |
607 | { | 593 | { |
608 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 594 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
609 | struct snd_soc_codec *codec = socdev->codec; | 595 | struct snd_soc_codec *codec = socdev->card->codec; |
610 | int i; | 596 | int i; |
611 | u8 data[2]; | 597 | u8 data[2]; |
612 | u16 *cache = codec->reg_cache; | 598 | u16 *cache = codec->reg_cache; |
@@ -628,7 +614,7 @@ static int wm8510_resume(struct platform_device *pdev) | |||
628 | */ | 614 | */ |
629 | static int wm8510_init(struct snd_soc_device *socdev) | 615 | static int wm8510_init(struct snd_soc_device *socdev) |
630 | { | 616 | { |
631 | struct snd_soc_codec *codec = socdev->codec; | 617 | struct snd_soc_codec *codec = socdev->card->codec; |
632 | int ret = 0; | 618 | int ret = 0; |
633 | 619 | ||
634 | codec->name = "WM8510"; | 620 | codec->name = "WM8510"; |
@@ -656,7 +642,8 @@ static int wm8510_init(struct snd_soc_device *socdev) | |||
656 | /* power on device */ | 642 | /* power on device */ |
657 | codec->bias_level = SND_SOC_BIAS_OFF; | 643 | codec->bias_level = SND_SOC_BIAS_OFF; |
658 | wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 644 | wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
659 | wm8510_add_controls(codec); | 645 | snd_soc_add_controls(codec, wm8510_snd_controls, |
646 | ARRAY_SIZE(wm8510_snd_controls)); | ||
660 | wm8510_add_widgets(codec); | 647 | wm8510_add_widgets(codec); |
661 | ret = snd_soc_init_card(socdev); | 648 | ret = snd_soc_init_card(socdev); |
662 | if (ret < 0) { | 649 | if (ret < 0) { |
@@ -685,7 +672,7 @@ static int wm8510_i2c_probe(struct i2c_client *i2c, | |||
685 | const struct i2c_device_id *id) | 672 | const struct i2c_device_id *id) |
686 | { | 673 | { |
687 | struct snd_soc_device *socdev = wm8510_socdev; | 674 | struct snd_soc_device *socdev = wm8510_socdev; |
688 | struct snd_soc_codec *codec = socdev->codec; | 675 | struct snd_soc_codec *codec = socdev->card->codec; |
689 | int ret; | 676 | int ret; |
690 | 677 | ||
691 | i2c_set_clientdata(i2c, codec); | 678 | i2c_set_clientdata(i2c, codec); |
@@ -766,7 +753,7 @@ err_driver: | |||
766 | static int __devinit wm8510_spi_probe(struct spi_device *spi) | 753 | static int __devinit wm8510_spi_probe(struct spi_device *spi) |
767 | { | 754 | { |
768 | struct snd_soc_device *socdev = wm8510_socdev; | 755 | struct snd_soc_device *socdev = wm8510_socdev; |
769 | struct snd_soc_codec *codec = socdev->codec; | 756 | struct snd_soc_codec *codec = socdev->card->codec; |
770 | int ret; | 757 | int ret; |
771 | 758 | ||
772 | codec->control_data = spi; | 759 | codec->control_data = spi; |
@@ -832,7 +819,7 @@ static int wm8510_probe(struct platform_device *pdev) | |||
832 | if (codec == NULL) | 819 | if (codec == NULL) |
833 | return -ENOMEM; | 820 | return -ENOMEM; |
834 | 821 | ||
835 | socdev->codec = codec; | 822 | socdev->card->codec = codec; |
836 | mutex_init(&codec->mutex); | 823 | mutex_init(&codec->mutex); |
837 | INIT_LIST_HEAD(&codec->dapm_widgets); | 824 | INIT_LIST_HEAD(&codec->dapm_widgets); |
838 | INIT_LIST_HEAD(&codec->dapm_paths); | 825 | INIT_LIST_HEAD(&codec->dapm_paths); |
@@ -862,7 +849,7 @@ static int wm8510_probe(struct platform_device *pdev) | |||
862 | static int wm8510_remove(struct platform_device *pdev) | 849 | static int wm8510_remove(struct platform_device *pdev) |
863 | { | 850 | { |
864 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 851 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
865 | struct snd_soc_codec *codec = socdev->codec; | 852 | struct snd_soc_codec *codec = socdev->card->codec; |
866 | 853 | ||
867 | if (codec->control_data) | 854 | if (codec->control_data) |
868 | wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF); | 855 | wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF); |
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c index d004e5845298..442ea6f160fc 100644 --- a/sound/soc/codecs/wm8580.c +++ b/sound/soc/codecs/wm8580.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * wm8580.c -- WM8580 ALSA Soc Audio driver | 2 | * wm8580.c -- WM8580 ALSA Soc Audio driver |
3 | * | 3 | * |
4 | * Copyright 2008 Wolfson Microelectronics PLC. | 4 | * Copyright 2008, 2009 Wolfson Microelectronics PLC. |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | 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 | 7 | * under the terms of the GNU General Public License as published by the |
@@ -35,19 +35,6 @@ | |||
35 | 35 | ||
36 | #include "wm8580.h" | 36 | #include "wm8580.h" |
37 | 37 | ||
38 | #define WM8580_VERSION "0.1" | ||
39 | |||
40 | struct pll_state { | ||
41 | unsigned int in; | ||
42 | unsigned int out; | ||
43 | }; | ||
44 | |||
45 | /* codec private data */ | ||
46 | struct wm8580_priv { | ||
47 | struct pll_state a; | ||
48 | struct pll_state b; | ||
49 | }; | ||
50 | |||
51 | /* WM8580 register space */ | 38 | /* WM8580 register space */ |
52 | #define WM8580_PLLA1 0x00 | 39 | #define WM8580_PLLA1 0x00 |
53 | #define WM8580_PLLA2 0x01 | 40 | #define WM8580_PLLA2 0x01 |
@@ -102,6 +89,8 @@ struct wm8580_priv { | |||
102 | #define WM8580_READBACK 0x34 | 89 | #define WM8580_READBACK 0x34 |
103 | #define WM8580_RESET 0x35 | 90 | #define WM8580_RESET 0x35 |
104 | 91 | ||
92 | #define WM8580_MAX_REGISTER 0x35 | ||
93 | |||
105 | /* PLLB4 (register 7h) */ | 94 | /* PLLB4 (register 7h) */ |
106 | #define WM8580_PLLB4_MCLKOUTSRC_MASK 0x60 | 95 | #define WM8580_PLLB4_MCLKOUTSRC_MASK 0x60 |
107 | #define WM8580_PLLB4_MCLKOUTSRC_PLLA 0x20 | 96 | #define WM8580_PLLB4_MCLKOUTSRC_PLLA 0x20 |
@@ -193,6 +182,20 @@ static const u16 wm8580_reg[] = { | |||
193 | 0x0000, 0x0000 /*R53*/ | 182 | 0x0000, 0x0000 /*R53*/ |
194 | }; | 183 | }; |
195 | 184 | ||
185 | struct pll_state { | ||
186 | unsigned int in; | ||
187 | unsigned int out; | ||
188 | }; | ||
189 | |||
190 | /* codec private data */ | ||
191 | struct wm8580_priv { | ||
192 | struct snd_soc_codec codec; | ||
193 | u16 reg_cache[WM8580_MAX_REGISTER + 1]; | ||
194 | struct pll_state a; | ||
195 | struct pll_state b; | ||
196 | }; | ||
197 | |||
198 | |||
196 | /* | 199 | /* |
197 | * read wm8580 register cache | 200 | * read wm8580 register cache |
198 | */ | 201 | */ |
@@ -200,7 +203,7 @@ static inline unsigned int wm8580_read_reg_cache(struct snd_soc_codec *codec, | |||
200 | unsigned int reg) | 203 | unsigned int reg) |
201 | { | 204 | { |
202 | u16 *cache = codec->reg_cache; | 205 | u16 *cache = codec->reg_cache; |
203 | BUG_ON(reg > ARRAY_SIZE(wm8580_reg)); | 206 | BUG_ON(reg >= ARRAY_SIZE(wm8580_reg)); |
204 | return cache[reg]; | 207 | return cache[reg]; |
205 | } | 208 | } |
206 | 209 | ||
@@ -223,7 +226,7 @@ static int wm8580_write(struct snd_soc_codec *codec, unsigned int reg, | |||
223 | { | 226 | { |
224 | u8 data[2]; | 227 | u8 data[2]; |
225 | 228 | ||
226 | BUG_ON(reg > ARRAY_SIZE(wm8580_reg)); | 229 | BUG_ON(reg >= ARRAY_SIZE(wm8580_reg)); |
227 | 230 | ||
228 | /* Registers are 9 bits wide */ | 231 | /* Registers are 9 bits wide */ |
229 | value &= 0x1ff; | 232 | value &= 0x1ff; |
@@ -330,20 +333,6 @@ SOC_DOUBLE("ADC Mute Switch", WM8580_ADC_CONTROL1, 0, 1, 1, 0), | |||
330 | SOC_SINGLE("ADC High-Pass Filter Switch", WM8580_ADC_CONTROL1, 4, 1, 0), | 333 | SOC_SINGLE("ADC High-Pass Filter Switch", WM8580_ADC_CONTROL1, 4, 1, 0), |
331 | }; | 334 | }; |
332 | 335 | ||
333 | /* Add non-DAPM controls */ | ||
334 | static int wm8580_add_controls(struct snd_soc_codec *codec) | ||
335 | { | ||
336 | int err, i; | ||
337 | |||
338 | for (i = 0; i < ARRAY_SIZE(wm8580_snd_controls); i++) { | ||
339 | err = snd_ctl_add(codec->card, | ||
340 | snd_soc_cnew(&wm8580_snd_controls[i], | ||
341 | codec, NULL)); | ||
342 | if (err < 0) | ||
343 | return err; | ||
344 | } | ||
345 | return 0; | ||
346 | } | ||
347 | static const struct snd_soc_dapm_widget wm8580_dapm_widgets[] = { | 336 | static const struct snd_soc_dapm_widget wm8580_dapm_widgets[] = { |
348 | SND_SOC_DAPM_DAC("DAC1", "Playback", WM8580_PWRDN1, 2, 1), | 337 | SND_SOC_DAPM_DAC("DAC1", "Playback", WM8580_PWRDN1, 2, 1), |
349 | SND_SOC_DAPM_DAC("DAC2", "Playback", WM8580_PWRDN1, 3, 1), | 338 | SND_SOC_DAPM_DAC("DAC2", "Playback", WM8580_PWRDN1, 3, 1), |
@@ -553,7 +542,7 @@ static int wm8580_paif_hw_params(struct snd_pcm_substream *substream, | |||
553 | { | 542 | { |
554 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 543 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
555 | struct snd_soc_device *socdev = rtd->socdev; | 544 | struct snd_soc_device *socdev = rtd->socdev; |
556 | struct snd_soc_codec *codec = socdev->codec; | 545 | struct snd_soc_codec *codec = socdev->card->codec; |
557 | u16 paifb = wm8580_read(codec, WM8580_PAIF3 + dai->id); | 546 | u16 paifb = wm8580_read(codec, WM8580_PAIF3 + dai->id); |
558 | 547 | ||
559 | paifb &= ~WM8580_AIF_LENGTH_MASK; | 548 | paifb &= ~WM8580_AIF_LENGTH_MASK; |
@@ -771,8 +760,22 @@ static int wm8580_set_bias_level(struct snd_soc_codec *codec, | |||
771 | switch (level) { | 760 | switch (level) { |
772 | case SND_SOC_BIAS_ON: | 761 | case SND_SOC_BIAS_ON: |
773 | case SND_SOC_BIAS_PREPARE: | 762 | case SND_SOC_BIAS_PREPARE: |
763 | break; | ||
764 | |||
774 | case SND_SOC_BIAS_STANDBY: | 765 | case SND_SOC_BIAS_STANDBY: |
766 | if (codec->bias_level == SND_SOC_BIAS_OFF) { | ||
767 | /* Power up and get individual control of the DACs */ | ||
768 | reg = wm8580_read(codec, WM8580_PWRDN1); | ||
769 | reg &= ~(WM8580_PWRDN1_PWDN | WM8580_PWRDN1_ALLDACPD); | ||
770 | wm8580_write(codec, WM8580_PWRDN1, reg); | ||
771 | |||
772 | /* Make VMID high impedence */ | ||
773 | reg = wm8580_read(codec, WM8580_ADC_CONTROL1); | ||
774 | reg &= ~0x100; | ||
775 | wm8580_write(codec, WM8580_ADC_CONTROL1, reg); | ||
776 | } | ||
775 | break; | 777 | break; |
778 | |||
776 | case SND_SOC_BIAS_OFF: | 779 | case SND_SOC_BIAS_OFF: |
777 | reg = wm8580_read(codec, WM8580_PWRDN1); | 780 | reg = wm8580_read(codec, WM8580_PWRDN1); |
778 | wm8580_write(codec, WM8580_PWRDN1, reg | WM8580_PWRDN1_PWDN); | 781 | wm8580_write(codec, WM8580_PWRDN1, reg | WM8580_PWRDN1_PWDN); |
@@ -785,6 +788,21 @@ static int wm8580_set_bias_level(struct snd_soc_codec *codec, | |||
785 | #define WM8580_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | 788 | #define WM8580_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
786 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) | 789 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
787 | 790 | ||
791 | static struct snd_soc_dai_ops wm8580_dai_ops_playback = { | ||
792 | .hw_params = wm8580_paif_hw_params, | ||
793 | .set_fmt = wm8580_set_paif_dai_fmt, | ||
794 | .set_clkdiv = wm8580_set_dai_clkdiv, | ||
795 | .set_pll = wm8580_set_dai_pll, | ||
796 | .digital_mute = wm8580_digital_mute, | ||
797 | }; | ||
798 | |||
799 | static struct snd_soc_dai_ops wm8580_dai_ops_capture = { | ||
800 | .hw_params = wm8580_paif_hw_params, | ||
801 | .set_fmt = wm8580_set_paif_dai_fmt, | ||
802 | .set_clkdiv = wm8580_set_dai_clkdiv, | ||
803 | .set_pll = wm8580_set_dai_pll, | ||
804 | }; | ||
805 | |||
788 | struct snd_soc_dai wm8580_dai[] = { | 806 | struct snd_soc_dai wm8580_dai[] = { |
789 | { | 807 | { |
790 | .name = "WM8580 PAIFRX", | 808 | .name = "WM8580 PAIFRX", |
@@ -796,13 +814,7 @@ struct snd_soc_dai wm8580_dai[] = { | |||
796 | .rates = SNDRV_PCM_RATE_8000_192000, | 814 | .rates = SNDRV_PCM_RATE_8000_192000, |
797 | .formats = WM8580_FORMATS, | 815 | .formats = WM8580_FORMATS, |
798 | }, | 816 | }, |
799 | .ops = { | 817 | .ops = &wm8580_dai_ops_playback, |
800 | .hw_params = wm8580_paif_hw_params, | ||
801 | .set_fmt = wm8580_set_paif_dai_fmt, | ||
802 | .set_clkdiv = wm8580_set_dai_clkdiv, | ||
803 | .set_pll = wm8580_set_dai_pll, | ||
804 | .digital_mute = wm8580_digital_mute, | ||
805 | }, | ||
806 | }, | 818 | }, |
807 | { | 819 | { |
808 | .name = "WM8580 PAIFTX", | 820 | .name = "WM8580 PAIFTX", |
@@ -814,109 +826,168 @@ struct snd_soc_dai wm8580_dai[] = { | |||
814 | .rates = SNDRV_PCM_RATE_8000_192000, | 826 | .rates = SNDRV_PCM_RATE_8000_192000, |
815 | .formats = WM8580_FORMATS, | 827 | .formats = WM8580_FORMATS, |
816 | }, | 828 | }, |
817 | .ops = { | 829 | .ops = &wm8580_dai_ops_capture, |
818 | .hw_params = wm8580_paif_hw_params, | ||
819 | .set_fmt = wm8580_set_paif_dai_fmt, | ||
820 | .set_clkdiv = wm8580_set_dai_clkdiv, | ||
821 | .set_pll = wm8580_set_dai_pll, | ||
822 | }, | ||
823 | }, | 830 | }, |
824 | }; | 831 | }; |
825 | EXPORT_SYMBOL_GPL(wm8580_dai); | 832 | EXPORT_SYMBOL_GPL(wm8580_dai); |
826 | 833 | ||
827 | /* | 834 | static struct snd_soc_codec *wm8580_codec; |
828 | * initialise the WM8580 driver | 835 | |
829 | * register the mixer and dsp interfaces with the kernel | 836 | static int wm8580_probe(struct platform_device *pdev) |
830 | */ | ||
831 | static int wm8580_init(struct snd_soc_device *socdev) | ||
832 | { | 837 | { |
833 | struct snd_soc_codec *codec = socdev->codec; | 838 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
839 | struct snd_soc_codec *codec; | ||
834 | int ret = 0; | 840 | int ret = 0; |
835 | 841 | ||
836 | codec->name = "WM8580"; | 842 | if (wm8580_codec == NULL) { |
837 | codec->owner = THIS_MODULE; | 843 | dev_err(&pdev->dev, "Codec device not registered\n"); |
838 | codec->read = wm8580_read_reg_cache; | 844 | return -ENODEV; |
839 | codec->write = wm8580_write; | 845 | } |
840 | codec->set_bias_level = wm8580_set_bias_level; | ||
841 | codec->dai = wm8580_dai; | ||
842 | codec->num_dai = ARRAY_SIZE(wm8580_dai); | ||
843 | codec->reg_cache_size = ARRAY_SIZE(wm8580_reg); | ||
844 | codec->reg_cache = kmemdup(wm8580_reg, sizeof(wm8580_reg), | ||
845 | GFP_KERNEL); | ||
846 | |||
847 | if (codec->reg_cache == NULL) | ||
848 | return -ENOMEM; | ||
849 | |||
850 | /* Get the codec into a known state */ | ||
851 | wm8580_write(codec, WM8580_RESET, 0); | ||
852 | |||
853 | /* Power up and get individual control of the DACs */ | ||
854 | wm8580_write(codec, WM8580_PWRDN1, wm8580_read(codec, WM8580_PWRDN1) & | ||
855 | ~(WM8580_PWRDN1_PWDN | WM8580_PWRDN1_ALLDACPD)); | ||
856 | 846 | ||
857 | /* Make VMID high impedence */ | 847 | socdev->card->codec = wm8580_codec; |
858 | wm8580_write(codec, WM8580_ADC_CONTROL1, | 848 | codec = wm8580_codec; |
859 | wm8580_read(codec, WM8580_ADC_CONTROL1) & ~0x100); | ||
860 | 849 | ||
861 | /* register pcms */ | 850 | /* register pcms */ |
862 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, | 851 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
863 | SNDRV_DEFAULT_STR1); | ||
864 | if (ret < 0) { | 852 | if (ret < 0) { |
865 | printk(KERN_ERR "wm8580: failed to create pcms\n"); | 853 | dev_err(codec->dev, "failed to create pcms: %d\n", ret); |
866 | goto pcm_err; | 854 | goto pcm_err; |
867 | } | 855 | } |
868 | 856 | ||
869 | wm8580_add_controls(codec); | 857 | snd_soc_add_controls(codec, wm8580_snd_controls, |
858 | ARRAY_SIZE(wm8580_snd_controls)); | ||
870 | wm8580_add_widgets(codec); | 859 | wm8580_add_widgets(codec); |
871 | |||
872 | ret = snd_soc_init_card(socdev); | 860 | ret = snd_soc_init_card(socdev); |
873 | if (ret < 0) { | 861 | if (ret < 0) { |
874 | printk(KERN_ERR "wm8580: failed to register card\n"); | 862 | dev_err(codec->dev, "failed to register card: %d\n", ret); |
875 | goto card_err; | 863 | goto card_err; |
876 | } | 864 | } |
865 | |||
877 | return ret; | 866 | return ret; |
878 | 867 | ||
879 | card_err: | 868 | card_err: |
880 | snd_soc_free_pcms(socdev); | 869 | snd_soc_free_pcms(socdev); |
881 | snd_soc_dapm_free(socdev); | 870 | snd_soc_dapm_free(socdev); |
882 | pcm_err: | 871 | pcm_err: |
883 | kfree(codec->reg_cache); | ||
884 | return ret; | 872 | return ret; |
885 | } | 873 | } |
886 | 874 | ||
887 | /* If the i2c layer weren't so broken, we could pass this kind of data | 875 | /* power down chip */ |
888 | around */ | 876 | static int wm8580_remove(struct platform_device *pdev) |
889 | static struct snd_soc_device *wm8580_socdev; | 877 | { |
878 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
879 | |||
880 | snd_soc_free_pcms(socdev); | ||
881 | snd_soc_dapm_free(socdev); | ||
890 | 882 | ||
891 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 883 | return 0; |
884 | } | ||
892 | 885 | ||
893 | /* | 886 | struct snd_soc_codec_device soc_codec_dev_wm8580 = { |
894 | * WM8580 2 wire address is determined by GPIO5 | 887 | .probe = wm8580_probe, |
895 | * state during powerup. | 888 | .remove = wm8580_remove, |
896 | * low = 0x1a | 889 | }; |
897 | * high = 0x1b | 890 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8580); |
898 | */ | 891 | |
892 | static int wm8580_register(struct wm8580_priv *wm8580) | ||
893 | { | ||
894 | int ret, i; | ||
895 | struct snd_soc_codec *codec = &wm8580->codec; | ||
896 | |||
897 | if (wm8580_codec) { | ||
898 | dev_err(codec->dev, "Another WM8580 is registered\n"); | ||
899 | ret = -EINVAL; | ||
900 | goto err; | ||
901 | } | ||
902 | |||
903 | mutex_init(&codec->mutex); | ||
904 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
905 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
899 | 906 | ||
907 | codec->private_data = wm8580; | ||
908 | codec->name = "WM8580"; | ||
909 | codec->owner = THIS_MODULE; | ||
910 | codec->read = wm8580_read_reg_cache; | ||
911 | codec->write = wm8580_write; | ||
912 | codec->bias_level = SND_SOC_BIAS_OFF; | ||
913 | codec->set_bias_level = wm8580_set_bias_level; | ||
914 | codec->dai = wm8580_dai; | ||
915 | codec->num_dai = ARRAY_SIZE(wm8580_dai); | ||
916 | codec->reg_cache_size = ARRAY_SIZE(wm8580->reg_cache); | ||
917 | codec->reg_cache = &wm8580->reg_cache; | ||
918 | |||
919 | memcpy(codec->reg_cache, wm8580_reg, sizeof(wm8580_reg)); | ||
920 | |||
921 | /* Get the codec into a known state */ | ||
922 | ret = wm8580_write(codec, WM8580_RESET, 0); | ||
923 | if (ret != 0) { | ||
924 | dev_err(codec->dev, "Failed to reset codec: %d\n", ret); | ||
925 | goto err; | ||
926 | } | ||
927 | |||
928 | for (i = 0; i < ARRAY_SIZE(wm8580_dai); i++) | ||
929 | wm8580_dai[i].dev = codec->dev; | ||
930 | |||
931 | wm8580_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | ||
932 | |||
933 | wm8580_codec = codec; | ||
934 | |||
935 | ret = snd_soc_register_codec(codec); | ||
936 | if (ret != 0) { | ||
937 | dev_err(codec->dev, "Failed to register codec: %d\n", ret); | ||
938 | goto err; | ||
939 | } | ||
940 | |||
941 | ret = snd_soc_register_dais(wm8580_dai, ARRAY_SIZE(wm8580_dai)); | ||
942 | if (ret != 0) { | ||
943 | dev_err(codec->dev, "Failed to register DAI: %d\n", ret); | ||
944 | goto err_codec; | ||
945 | } | ||
946 | |||
947 | return 0; | ||
948 | |||
949 | err_codec: | ||
950 | snd_soc_unregister_codec(codec); | ||
951 | err: | ||
952 | kfree(wm8580); | ||
953 | return ret; | ||
954 | } | ||
955 | |||
956 | static void wm8580_unregister(struct wm8580_priv *wm8580) | ||
957 | { | ||
958 | wm8580_set_bias_level(&wm8580->codec, SND_SOC_BIAS_OFF); | ||
959 | snd_soc_unregister_dais(wm8580_dai, ARRAY_SIZE(wm8580_dai)); | ||
960 | snd_soc_unregister_codec(&wm8580->codec); | ||
961 | kfree(wm8580); | ||
962 | wm8580_codec = NULL; | ||
963 | } | ||
964 | |||
965 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
900 | static int wm8580_i2c_probe(struct i2c_client *i2c, | 966 | static int wm8580_i2c_probe(struct i2c_client *i2c, |
901 | const struct i2c_device_id *id) | 967 | const struct i2c_device_id *id) |
902 | { | 968 | { |
903 | struct snd_soc_device *socdev = wm8580_socdev; | 969 | struct wm8580_priv *wm8580; |
904 | struct snd_soc_codec *codec = socdev->codec; | 970 | struct snd_soc_codec *codec; |
905 | int ret; | ||
906 | 971 | ||
907 | i2c_set_clientdata(i2c, codec); | 972 | wm8580 = kzalloc(sizeof(struct wm8580_priv), GFP_KERNEL); |
973 | if (wm8580 == NULL) | ||
974 | return -ENOMEM; | ||
975 | |||
976 | codec = &wm8580->codec; | ||
977 | codec->hw_write = (hw_write_t)i2c_master_send; | ||
978 | |||
979 | i2c_set_clientdata(i2c, wm8580); | ||
908 | codec->control_data = i2c; | 980 | codec->control_data = i2c; |
909 | 981 | ||
910 | ret = wm8580_init(socdev); | 982 | codec->dev = &i2c->dev; |
911 | if (ret < 0) | 983 | |
912 | dev_err(&i2c->dev, "failed to initialise WM8580\n"); | 984 | return wm8580_register(wm8580); |
913 | return ret; | ||
914 | } | 985 | } |
915 | 986 | ||
916 | static int wm8580_i2c_remove(struct i2c_client *client) | 987 | static int wm8580_i2c_remove(struct i2c_client *client) |
917 | { | 988 | { |
918 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | 989 | struct wm8580_priv *wm8580 = i2c_get_clientdata(client); |
919 | kfree(codec->reg_cache); | 990 | wm8580_unregister(wm8580); |
920 | return 0; | 991 | return 0; |
921 | } | 992 | } |
922 | 993 | ||
@@ -928,129 +999,35 @@ MODULE_DEVICE_TABLE(i2c, wm8580_i2c_id); | |||
928 | 999 | ||
929 | static struct i2c_driver wm8580_i2c_driver = { | 1000 | static struct i2c_driver wm8580_i2c_driver = { |
930 | .driver = { | 1001 | .driver = { |
931 | .name = "WM8580 I2C Codec", | 1002 | .name = "wm8580", |
932 | .owner = THIS_MODULE, | 1003 | .owner = THIS_MODULE, |
933 | }, | 1004 | }, |
934 | .probe = wm8580_i2c_probe, | 1005 | .probe = wm8580_i2c_probe, |
935 | .remove = wm8580_i2c_remove, | 1006 | .remove = wm8580_i2c_remove, |
936 | .id_table = wm8580_i2c_id, | 1007 | .id_table = wm8580_i2c_id, |
937 | }; | 1008 | }; |
1009 | #endif | ||
938 | 1010 | ||
939 | static int wm8580_add_i2c_device(struct platform_device *pdev, | 1011 | static int __init wm8580_modinit(void) |
940 | const struct wm8580_setup_data *setup) | ||
941 | { | 1012 | { |
942 | struct i2c_board_info info; | ||
943 | struct i2c_adapter *adapter; | ||
944 | struct i2c_client *client; | ||
945 | int ret; | 1013 | int ret; |
946 | 1014 | ||
1015 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
947 | ret = i2c_add_driver(&wm8580_i2c_driver); | 1016 | ret = i2c_add_driver(&wm8580_i2c_driver); |
948 | if (ret != 0) { | 1017 | if (ret != 0) { |
949 | dev_err(&pdev->dev, "can't add i2c driver\n"); | 1018 | pr_err("Failed to register WM8580 I2C driver: %d\n", ret); |
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 | } | 1019 | } |
971 | |||
972 | return 0; | ||
973 | |||
974 | err_driver: | ||
975 | i2c_del_driver(&wm8580_i2c_driver); | ||
976 | return -ENODEV; | ||
977 | } | ||
978 | #endif | 1020 | #endif |
979 | 1021 | ||
980 | static int wm8580_probe(struct platform_device *pdev) | ||
981 | { | ||
982 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
983 | struct wm8580_setup_data *setup; | ||
984 | struct snd_soc_codec *codec; | ||
985 | struct wm8580_priv *wm8580; | ||
986 | int ret = 0; | ||
987 | |||
988 | pr_info("WM8580 Audio Codec %s\n", WM8580_VERSION); | ||
989 | |||
990 | setup = socdev->codec_data; | ||
991 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | ||
992 | if (codec == NULL) | ||
993 | return -ENOMEM; | ||
994 | |||
995 | wm8580 = kzalloc(sizeof(struct wm8580_priv), GFP_KERNEL); | ||
996 | if (wm8580 == NULL) { | ||
997 | kfree(codec); | ||
998 | return -ENOMEM; | ||
999 | } | ||
1000 | |||
1001 | codec->private_data = wm8580; | ||
1002 | socdev->codec = codec; | ||
1003 | mutex_init(&codec->mutex); | ||
1004 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
1005 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
1006 | wm8580_socdev = socdev; | ||
1007 | |||
1008 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
1009 | if (setup->i2c_address) { | ||
1010 | codec->hw_write = (hw_write_t)i2c_master_send; | ||
1011 | ret = wm8580_add_i2c_device(pdev, setup); | ||
1012 | } | ||
1013 | #else | ||
1014 | /* Add other interfaces here */ | ||
1015 | #endif | ||
1016 | return ret; | ||
1017 | } | ||
1018 | |||
1019 | /* power down chip */ | ||
1020 | static int wm8580_remove(struct platform_device *pdev) | ||
1021 | { | ||
1022 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1023 | struct snd_soc_codec *codec = socdev->codec; | ||
1024 | |||
1025 | if (codec->control_data) | ||
1026 | wm8580_set_bias_level(codec, SND_SOC_BIAS_OFF); | ||
1027 | snd_soc_free_pcms(socdev); | ||
1028 | snd_soc_dapm_free(socdev); | ||
1029 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
1030 | i2c_unregister_device(codec->control_data); | ||
1031 | i2c_del_driver(&wm8580_i2c_driver); | ||
1032 | #endif | ||
1033 | kfree(codec->private_data); | ||
1034 | kfree(codec); | ||
1035 | |||
1036 | return 0; | 1022 | return 0; |
1037 | } | 1023 | } |
1038 | |||
1039 | struct snd_soc_codec_device soc_codec_dev_wm8580 = { | ||
1040 | .probe = wm8580_probe, | ||
1041 | .remove = wm8580_remove, | ||
1042 | }; | ||
1043 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8580); | ||
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); | 1024 | module_init(wm8580_modinit); |
1050 | 1025 | ||
1051 | static void __exit wm8580_exit(void) | 1026 | static void __exit wm8580_exit(void) |
1052 | { | 1027 | { |
1053 | snd_soc_unregister_dais(wm8580_dai, ARRAY_SIZE(wm8580_dai)); | 1028 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1029 | i2c_del_driver(&wm8580_i2c_driver); | ||
1030 | #endif | ||
1054 | } | 1031 | } |
1055 | module_exit(wm8580_exit); | 1032 | module_exit(wm8580_exit); |
1056 | 1033 | ||
diff --git a/sound/soc/codecs/wm8580.h b/sound/soc/codecs/wm8580.h index 09e4422f6f2f..0dfb5ddde6a2 100644 --- a/sound/soc/codecs/wm8580.h +++ b/sound/soc/codecs/wm8580.h | |||
@@ -28,11 +28,6 @@ | |||
28 | #define WM8580_CLKSRC_OSC 4 | 28 | #define WM8580_CLKSRC_OSC 4 |
29 | #define WM8580_CLKSRC_NONE 5 | 29 | #define WM8580_CLKSRC_NONE 5 |
30 | 30 | ||
31 | struct wm8580_setup_data { | ||
32 | int i2c_bus; | ||
33 | unsigned short i2c_address; | ||
34 | }; | ||
35 | |||
36 | #define WM8580_DAI_PAIFRX 0 | 31 | #define WM8580_DAI_PAIFRX 0 |
37 | #define WM8580_DAI_PAIFTX 1 | 32 | #define WM8580_DAI_PAIFTX 1 |
38 | 33 | ||
diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c index 80b11983e137..e7ff2121ede9 100644 --- a/sound/soc/codecs/wm8728.c +++ b/sound/soc/codecs/wm8728.c | |||
@@ -47,7 +47,7 @@ static inline unsigned int wm8728_read_reg_cache(struct snd_soc_codec *codec, | |||
47 | unsigned int reg) | 47 | unsigned int reg) |
48 | { | 48 | { |
49 | u16 *cache = codec->reg_cache; | 49 | u16 *cache = codec->reg_cache; |
50 | BUG_ON(reg > ARRAY_SIZE(wm8728_reg_defaults)); | 50 | BUG_ON(reg >= ARRAY_SIZE(wm8728_reg_defaults)); |
51 | return cache[reg]; | 51 | return cache[reg]; |
52 | } | 52 | } |
53 | 53 | ||
@@ -55,7 +55,7 @@ static inline void wm8728_write_reg_cache(struct snd_soc_codec *codec, | |||
55 | u16 reg, unsigned int value) | 55 | u16 reg, unsigned int value) |
56 | { | 56 | { |
57 | u16 *cache = codec->reg_cache; | 57 | u16 *cache = codec->reg_cache; |
58 | BUG_ON(reg > ARRAY_SIZE(wm8728_reg_defaults)); | 58 | BUG_ON(reg >= ARRAY_SIZE(wm8728_reg_defaults)); |
59 | cache[reg] = value; | 59 | cache[reg] = value; |
60 | } | 60 | } |
61 | 61 | ||
@@ -92,21 +92,6 @@ SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8728_DACLVOL, WM8728_DACRVOL, | |||
92 | SOC_SINGLE("Deemphasis", WM8728_DACCTL, 1, 1, 0), | 92 | SOC_SINGLE("Deemphasis", WM8728_DACCTL, 1, 1, 0), |
93 | }; | 93 | }; |
94 | 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 | /* | 95 | /* |
111 | * DAPM controls. | 96 | * DAPM controls. |
112 | */ | 97 | */ |
@@ -152,7 +137,7 @@ static int wm8728_hw_params(struct snd_pcm_substream *substream, | |||
152 | { | 137 | { |
153 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 138 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
154 | struct snd_soc_device *socdev = rtd->socdev; | 139 | struct snd_soc_device *socdev = rtd->socdev; |
155 | struct snd_soc_codec *codec = socdev->codec; | 140 | struct snd_soc_codec *codec = socdev->card->codec; |
156 | u16 dac = wm8728_read_reg_cache(codec, WM8728_DACCTL); | 141 | u16 dac = wm8728_read_reg_cache(codec, WM8728_DACCTL); |
157 | 142 | ||
158 | dac &= ~0x18; | 143 | dac &= ~0x18; |
@@ -259,6 +244,12 @@ static int wm8728_set_bias_level(struct snd_soc_codec *codec, | |||
259 | #define WM8728_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | 244 | #define WM8728_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
260 | SNDRV_PCM_FMTBIT_S24_LE) | 245 | SNDRV_PCM_FMTBIT_S24_LE) |
261 | 246 | ||
247 | static struct snd_soc_dai_ops wm8728_dai_ops = { | ||
248 | .hw_params = wm8728_hw_params, | ||
249 | .digital_mute = wm8728_mute, | ||
250 | .set_fmt = wm8728_set_dai_fmt, | ||
251 | }; | ||
252 | |||
262 | struct snd_soc_dai wm8728_dai = { | 253 | struct snd_soc_dai wm8728_dai = { |
263 | .name = "WM8728", | 254 | .name = "WM8728", |
264 | .playback = { | 255 | .playback = { |
@@ -268,18 +259,14 @@ struct snd_soc_dai wm8728_dai = { | |||
268 | .rates = WM8728_RATES, | 259 | .rates = WM8728_RATES, |
269 | .formats = WM8728_FORMATS, | 260 | .formats = WM8728_FORMATS, |
270 | }, | 261 | }, |
271 | .ops = { | 262 | .ops = &wm8728_dai_ops, |
272 | .hw_params = wm8728_hw_params, | ||
273 | .digital_mute = wm8728_mute, | ||
274 | .set_fmt = wm8728_set_dai_fmt, | ||
275 | } | ||
276 | }; | 263 | }; |
277 | EXPORT_SYMBOL_GPL(wm8728_dai); | 264 | EXPORT_SYMBOL_GPL(wm8728_dai); |
278 | 265 | ||
279 | static int wm8728_suspend(struct platform_device *pdev, pm_message_t state) | 266 | static int wm8728_suspend(struct platform_device *pdev, pm_message_t state) |
280 | { | 267 | { |
281 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 268 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
282 | struct snd_soc_codec *codec = socdev->codec; | 269 | struct snd_soc_codec *codec = socdev->card->codec; |
283 | 270 | ||
284 | wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); | 271 | wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); |
285 | 272 | ||
@@ -289,7 +276,7 @@ static int wm8728_suspend(struct platform_device *pdev, pm_message_t state) | |||
289 | static int wm8728_resume(struct platform_device *pdev) | 276 | static int wm8728_resume(struct platform_device *pdev) |
290 | { | 277 | { |
291 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 278 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
292 | struct snd_soc_codec *codec = socdev->codec; | 279 | struct snd_soc_codec *codec = socdev->card->codec; |
293 | 280 | ||
294 | wm8728_set_bias_level(codec, codec->suspend_bias_level); | 281 | wm8728_set_bias_level(codec, codec->suspend_bias_level); |
295 | 282 | ||
@@ -302,7 +289,7 @@ static int wm8728_resume(struct platform_device *pdev) | |||
302 | */ | 289 | */ |
303 | static int wm8728_init(struct snd_soc_device *socdev) | 290 | static int wm8728_init(struct snd_soc_device *socdev) |
304 | { | 291 | { |
305 | struct snd_soc_codec *codec = socdev->codec; | 292 | struct snd_soc_codec *codec = socdev->card->codec; |
306 | int ret = 0; | 293 | int ret = 0; |
307 | 294 | ||
308 | codec->name = "WM8728"; | 295 | codec->name = "WM8728"; |
@@ -330,7 +317,8 @@ static int wm8728_init(struct snd_soc_device *socdev) | |||
330 | /* power on device */ | 317 | /* power on device */ |
331 | wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 318 | wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
332 | 319 | ||
333 | wm8728_add_controls(codec); | 320 | snd_soc_add_controls(codec, wm8728_snd_controls, |
321 | ARRAY_SIZE(wm8728_snd_controls)); | ||
334 | wm8728_add_widgets(codec); | 322 | wm8728_add_widgets(codec); |
335 | ret = snd_soc_init_card(socdev); | 323 | ret = snd_soc_init_card(socdev); |
336 | if (ret < 0) { | 324 | if (ret < 0) { |
@@ -363,7 +351,7 @@ static int wm8728_i2c_probe(struct i2c_client *i2c, | |||
363 | const struct i2c_device_id *id) | 351 | const struct i2c_device_id *id) |
364 | { | 352 | { |
365 | struct snd_soc_device *socdev = wm8728_socdev; | 353 | struct snd_soc_device *socdev = wm8728_socdev; |
366 | struct snd_soc_codec *codec = socdev->codec; | 354 | struct snd_soc_codec *codec = socdev->card->codec; |
367 | int ret; | 355 | int ret; |
368 | 356 | ||
369 | i2c_set_clientdata(i2c, codec); | 357 | i2c_set_clientdata(i2c, codec); |
@@ -444,7 +432,7 @@ err_driver: | |||
444 | static int __devinit wm8728_spi_probe(struct spi_device *spi) | 432 | static int __devinit wm8728_spi_probe(struct spi_device *spi) |
445 | { | 433 | { |
446 | struct snd_soc_device *socdev = wm8728_socdev; | 434 | struct snd_soc_device *socdev = wm8728_socdev; |
447 | struct snd_soc_codec *codec = socdev->codec; | 435 | struct snd_soc_codec *codec = socdev->card->codec; |
448 | int ret; | 436 | int ret; |
449 | 437 | ||
450 | codec->control_data = spi; | 438 | codec->control_data = spi; |
@@ -508,7 +496,7 @@ static int wm8728_probe(struct platform_device *pdev) | |||
508 | if (codec == NULL) | 496 | if (codec == NULL) |
509 | return -ENOMEM; | 497 | return -ENOMEM; |
510 | 498 | ||
511 | socdev->codec = codec; | 499 | socdev->card->codec = codec; |
512 | mutex_init(&codec->mutex); | 500 | mutex_init(&codec->mutex); |
513 | INIT_LIST_HEAD(&codec->dapm_widgets); | 501 | INIT_LIST_HEAD(&codec->dapm_widgets); |
514 | INIT_LIST_HEAD(&codec->dapm_paths); | 502 | INIT_LIST_HEAD(&codec->dapm_paths); |
@@ -541,7 +529,7 @@ static int wm8728_probe(struct platform_device *pdev) | |||
541 | static int wm8728_remove(struct platform_device *pdev) | 529 | static int wm8728_remove(struct platform_device *pdev) |
542 | { | 530 | { |
543 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 531 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
544 | struct snd_soc_codec *codec = socdev->codec; | 532 | struct snd_soc_codec *codec = socdev->card->codec; |
545 | 533 | ||
546 | if (codec->control_data) | 534 | if (codec->control_data) |
547 | wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); | 535 | wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); |
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c index c444b9f2701e..e043e3f60008 100644 --- a/sound/soc/codecs/wm8731.c +++ b/sound/soc/codecs/wm8731.c | |||
@@ -29,15 +29,20 @@ | |||
29 | 29 | ||
30 | #include "wm8731.h" | 30 | #include "wm8731.h" |
31 | 31 | ||
32 | #define WM8731_VERSION "0.13" | 32 | static struct snd_soc_codec *wm8731_codec; |
33 | |||
34 | struct snd_soc_codec_device soc_codec_dev_wm8731; | 33 | struct snd_soc_codec_device soc_codec_dev_wm8731; |
35 | 34 | ||
36 | /* codec private data */ | 35 | /* codec private data */ |
37 | struct wm8731_priv { | 36 | struct wm8731_priv { |
37 | struct snd_soc_codec codec; | ||
38 | u16 reg_cache[WM8731_CACHEREGNUM]; | ||
38 | unsigned int sysclk; | 39 | unsigned int sysclk; |
39 | }; | 40 | }; |
40 | 41 | ||
42 | #ifdef CONFIG_SPI_MASTER | ||
43 | static int wm8731_spi_write(struct spi_device *spi, const char *data, int len); | ||
44 | #endif | ||
45 | |||
41 | /* | 46 | /* |
42 | * wm8731 register cache | 47 | * wm8731 register cache |
43 | * We can't read the WM8731 register space when we are | 48 | * We can't read the WM8731 register space when we are |
@@ -129,22 +134,6 @@ SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI, 4, 1, 0), | |||
129 | SOC_ENUM("Playback De-emphasis", wm8731_enum[1]), | 134 | SOC_ENUM("Playback De-emphasis", wm8731_enum[1]), |
130 | }; | 135 | }; |
131 | 136 | ||
132 | /* add non dapm controls */ | ||
133 | static int wm8731_add_controls(struct snd_soc_codec *codec) | ||
134 | { | ||
135 | int err, i; | ||
136 | |||
137 | for (i = 0; i < ARRAY_SIZE(wm8731_snd_controls); i++) { | ||
138 | err = snd_ctl_add(codec->card, | ||
139 | snd_soc_cnew(&wm8731_snd_controls[i], | ||
140 | codec, NULL)); | ||
141 | if (err < 0) | ||
142 | return err; | ||
143 | } | ||
144 | |||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | /* Output Mixer */ | 137 | /* Output Mixer */ |
149 | static const struct snd_kcontrol_new wm8731_output_mixer_controls[] = { | 138 | static const struct snd_kcontrol_new wm8731_output_mixer_controls[] = { |
150 | SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0), | 139 | SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0), |
@@ -269,7 +258,7 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream, | |||
269 | { | 258 | { |
270 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 259 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
271 | struct snd_soc_device *socdev = rtd->socdev; | 260 | struct snd_soc_device *socdev = rtd->socdev; |
272 | struct snd_soc_codec *codec = socdev->codec; | 261 | struct snd_soc_codec *codec = socdev->card->codec; |
273 | struct wm8731_priv *wm8731 = codec->private_data; | 262 | struct wm8731_priv *wm8731 = codec->private_data; |
274 | u16 iface = wm8731_read_reg_cache(codec, WM8731_IFACE) & 0xfff3; | 263 | u16 iface = wm8731_read_reg_cache(codec, WM8731_IFACE) & 0xfff3; |
275 | int i = get_coeff(wm8731->sysclk, params_rate(params)); | 264 | int i = get_coeff(wm8731->sysclk, params_rate(params)); |
@@ -299,7 +288,7 @@ static int wm8731_pcm_prepare(struct snd_pcm_substream *substream, | |||
299 | { | 288 | { |
300 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 289 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
301 | struct snd_soc_device *socdev = rtd->socdev; | 290 | struct snd_soc_device *socdev = rtd->socdev; |
302 | struct snd_soc_codec *codec = socdev->codec; | 291 | struct snd_soc_codec *codec = socdev->card->codec; |
303 | 292 | ||
304 | /* set active */ | 293 | /* set active */ |
305 | wm8731_write(codec, WM8731_ACTIVE, 0x0001); | 294 | wm8731_write(codec, WM8731_ACTIVE, 0x0001); |
@@ -312,7 +301,7 @@ static void wm8731_shutdown(struct snd_pcm_substream *substream, | |||
312 | { | 301 | { |
313 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 302 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
314 | struct snd_soc_device *socdev = rtd->socdev; | 303 | struct snd_soc_device *socdev = rtd->socdev; |
315 | struct snd_soc_codec *codec = socdev->codec; | 304 | struct snd_soc_codec *codec = socdev->card->codec; |
316 | 305 | ||
317 | /* deactivate */ | 306 | /* deactivate */ |
318 | if (!codec->active) { | 307 | if (!codec->active) { |
@@ -414,21 +403,19 @@ static int wm8731_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
414 | static int wm8731_set_bias_level(struct snd_soc_codec *codec, | 403 | static int wm8731_set_bias_level(struct snd_soc_codec *codec, |
415 | enum snd_soc_bias_level level) | 404 | enum snd_soc_bias_level level) |
416 | { | 405 | { |
417 | u16 reg = wm8731_read_reg_cache(codec, WM8731_PWR) & 0xff7f; | 406 | u16 reg; |
418 | 407 | ||
419 | switch (level) { | 408 | switch (level) { |
420 | case SND_SOC_BIAS_ON: | 409 | case SND_SOC_BIAS_ON: |
421 | /* vref/mid, osc on, dac unmute */ | ||
422 | wm8731_write(codec, WM8731_PWR, reg); | ||
423 | break; | 410 | break; |
424 | case SND_SOC_BIAS_PREPARE: | 411 | case SND_SOC_BIAS_PREPARE: |
425 | break; | 412 | break; |
426 | case SND_SOC_BIAS_STANDBY: | 413 | case SND_SOC_BIAS_STANDBY: |
427 | /* everything off except vref/vmid, */ | 414 | /* Clear PWROFF, gate CLKOUT, everything else as-is */ |
415 | reg = wm8731_read_reg_cache(codec, WM8731_PWR) & 0xff7f; | ||
428 | wm8731_write(codec, WM8731_PWR, reg | 0x0040); | 416 | wm8731_write(codec, WM8731_PWR, reg | 0x0040); |
429 | break; | 417 | break; |
430 | case SND_SOC_BIAS_OFF: | 418 | case SND_SOC_BIAS_OFF: |
431 | /* everything off, dac mute, inactive */ | ||
432 | wm8731_write(codec, WM8731_ACTIVE, 0x0); | 419 | wm8731_write(codec, WM8731_ACTIVE, 0x0); |
433 | wm8731_write(codec, WM8731_PWR, 0xffff); | 420 | wm8731_write(codec, WM8731_PWR, 0xffff); |
434 | break; | 421 | break; |
@@ -446,6 +433,15 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec, | |||
446 | #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | 433 | #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
447 | SNDRV_PCM_FMTBIT_S24_LE) | 434 | SNDRV_PCM_FMTBIT_S24_LE) |
448 | 435 | ||
436 | static struct snd_soc_dai_ops wm8731_dai_ops = { | ||
437 | .prepare = wm8731_pcm_prepare, | ||
438 | .hw_params = wm8731_hw_params, | ||
439 | .shutdown = wm8731_shutdown, | ||
440 | .digital_mute = wm8731_mute, | ||
441 | .set_sysclk = wm8731_set_dai_sysclk, | ||
442 | .set_fmt = wm8731_set_dai_fmt, | ||
443 | }; | ||
444 | |||
449 | struct snd_soc_dai wm8731_dai = { | 445 | struct snd_soc_dai wm8731_dai = { |
450 | .name = "WM8731", | 446 | .name = "WM8731", |
451 | .playback = { | 447 | .playback = { |
@@ -460,21 +456,14 @@ struct snd_soc_dai wm8731_dai = { | |||
460 | .channels_max = 2, | 456 | .channels_max = 2, |
461 | .rates = WM8731_RATES, | 457 | .rates = WM8731_RATES, |
462 | .formats = WM8731_FORMATS,}, | 458 | .formats = WM8731_FORMATS,}, |
463 | .ops = { | 459 | .ops = &wm8731_dai_ops, |
464 | .prepare = wm8731_pcm_prepare, | ||
465 | .hw_params = wm8731_hw_params, | ||
466 | .shutdown = wm8731_shutdown, | ||
467 | .digital_mute = wm8731_mute, | ||
468 | .set_sysclk = wm8731_set_dai_sysclk, | ||
469 | .set_fmt = wm8731_set_dai_fmt, | ||
470 | } | ||
471 | }; | 460 | }; |
472 | EXPORT_SYMBOL_GPL(wm8731_dai); | 461 | EXPORT_SYMBOL_GPL(wm8731_dai); |
473 | 462 | ||
474 | static int wm8731_suspend(struct platform_device *pdev, pm_message_t state) | 463 | static int wm8731_suspend(struct platform_device *pdev, pm_message_t state) |
475 | { | 464 | { |
476 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 465 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
477 | struct snd_soc_codec *codec = socdev->codec; | 466 | struct snd_soc_codec *codec = socdev->card->codec; |
478 | 467 | ||
479 | wm8731_write(codec, WM8731_ACTIVE, 0x0); | 468 | wm8731_write(codec, WM8731_ACTIVE, 0x0); |
480 | wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF); | 469 | wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF); |
@@ -484,7 +473,7 @@ static int wm8731_suspend(struct platform_device *pdev, pm_message_t state) | |||
484 | static int wm8731_resume(struct platform_device *pdev) | 473 | static int wm8731_resume(struct platform_device *pdev) |
485 | { | 474 | { |
486 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 475 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
487 | struct snd_soc_codec *codec = socdev->codec; | 476 | struct snd_soc_codec *codec = socdev->card->codec; |
488 | int i; | 477 | int i; |
489 | u8 data[2]; | 478 | u8 data[2]; |
490 | u16 *cache = codec->reg_cache; | 479 | u16 *cache = codec->reg_cache; |
@@ -500,54 +489,33 @@ static int wm8731_resume(struct platform_device *pdev) | |||
500 | return 0; | 489 | return 0; |
501 | } | 490 | } |
502 | 491 | ||
503 | /* | 492 | static int wm8731_probe(struct platform_device *pdev) |
504 | * initialise the WM8731 driver | ||
505 | * register the mixer and dsp interfaces with the kernel | ||
506 | */ | ||
507 | static int wm8731_init(struct snd_soc_device *socdev) | ||
508 | { | 493 | { |
509 | struct snd_soc_codec *codec = socdev->codec; | 494 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
510 | int reg, ret = 0; | 495 | struct snd_soc_codec *codec; |
496 | int ret = 0; | ||
511 | 497 | ||
512 | codec->name = "WM8731"; | 498 | if (wm8731_codec == NULL) { |
513 | codec->owner = THIS_MODULE; | 499 | dev_err(&pdev->dev, "Codec device not registered\n"); |
514 | codec->read = wm8731_read_reg_cache; | 500 | return -ENODEV; |
515 | codec->write = wm8731_write; | 501 | } |
516 | codec->set_bias_level = wm8731_set_bias_level; | ||
517 | codec->dai = &wm8731_dai; | ||
518 | codec->num_dai = 1; | ||
519 | codec->reg_cache_size = ARRAY_SIZE(wm8731_reg); | ||
520 | codec->reg_cache = kmemdup(wm8731_reg, sizeof(wm8731_reg), GFP_KERNEL); | ||
521 | if (codec->reg_cache == NULL) | ||
522 | return -ENOMEM; | ||
523 | 502 | ||
524 | wm8731_reset(codec); | 503 | socdev->card->codec = wm8731_codec; |
504 | codec = wm8731_codec; | ||
525 | 505 | ||
526 | /* register pcms */ | 506 | /* register pcms */ |
527 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | 507 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
528 | if (ret < 0) { | 508 | if (ret < 0) { |
529 | printk(KERN_ERR "wm8731: failed to create pcms\n"); | 509 | dev_err(codec->dev, "failed to create pcms: %d\n", ret); |
530 | goto pcm_err; | 510 | goto pcm_err; |
531 | } | 511 | } |
532 | 512 | ||
533 | /* power on device */ | 513 | snd_soc_add_controls(codec, wm8731_snd_controls, |
534 | wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 514 | ARRAY_SIZE(wm8731_snd_controls)); |
535 | |||
536 | /* set the update bits */ | ||
537 | reg = wm8731_read_reg_cache(codec, WM8731_LOUT1V); | ||
538 | wm8731_write(codec, WM8731_LOUT1V, reg & ~0x0100); | ||
539 | reg = wm8731_read_reg_cache(codec, WM8731_ROUT1V); | ||
540 | wm8731_write(codec, WM8731_ROUT1V, reg & ~0x0100); | ||
541 | reg = wm8731_read_reg_cache(codec, WM8731_LINVOL); | ||
542 | wm8731_write(codec, WM8731_LINVOL, reg & ~0x0100); | ||
543 | reg = wm8731_read_reg_cache(codec, WM8731_RINVOL); | ||
544 | wm8731_write(codec, WM8731_RINVOL, reg & ~0x0100); | ||
545 | |||
546 | wm8731_add_controls(codec); | ||
547 | wm8731_add_widgets(codec); | 515 | wm8731_add_widgets(codec); |
548 | ret = snd_soc_init_card(socdev); | 516 | ret = snd_soc_init_card(socdev); |
549 | if (ret < 0) { | 517 | if (ret < 0) { |
550 | printk(KERN_ERR "wm8731: failed to register card\n"); | 518 | dev_err(codec->dev, "failed to register card: %d\n", ret); |
551 | goto card_err; | 519 | goto card_err; |
552 | } | 520 | } |
553 | 521 | ||
@@ -557,133 +525,109 @@ card_err: | |||
557 | snd_soc_free_pcms(socdev); | 525 | snd_soc_free_pcms(socdev); |
558 | snd_soc_dapm_free(socdev); | 526 | snd_soc_dapm_free(socdev); |
559 | pcm_err: | 527 | pcm_err: |
560 | kfree(codec->reg_cache); | ||
561 | return ret; | 528 | return ret; |
562 | } | 529 | } |
563 | 530 | ||
564 | static struct snd_soc_device *wm8731_socdev; | 531 | /* power down chip */ |
565 | 532 | static int wm8731_remove(struct platform_device *pdev) | |
566 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
567 | |||
568 | /* | ||
569 | * WM8731 2 wire address is determined by GPIO5 | ||
570 | * state during powerup. | ||
571 | * low = 0x1a | ||
572 | * high = 0x1b | ||
573 | */ | ||
574 | |||
575 | static int wm8731_i2c_probe(struct i2c_client *i2c, | ||
576 | const struct i2c_device_id *id) | ||
577 | { | 533 | { |
578 | struct snd_soc_device *socdev = wm8731_socdev; | 534 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
579 | struct snd_soc_codec *codec = socdev->codec; | ||
580 | int ret; | ||
581 | |||
582 | i2c_set_clientdata(i2c, codec); | ||
583 | codec->control_data = i2c; | ||
584 | |||
585 | ret = wm8731_init(socdev); | ||
586 | if (ret < 0) | ||
587 | pr_err("failed to initialise WM8731\n"); | ||
588 | 535 | ||
589 | return ret; | 536 | snd_soc_free_pcms(socdev); |
590 | } | 537 | snd_soc_dapm_free(socdev); |
591 | 538 | ||
592 | static int wm8731_i2c_remove(struct i2c_client *client) | ||
593 | { | ||
594 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | ||
595 | kfree(codec->reg_cache); | ||
596 | return 0; | 539 | return 0; |
597 | } | 540 | } |
598 | 541 | ||
599 | static const struct i2c_device_id wm8731_i2c_id[] = { | 542 | struct snd_soc_codec_device soc_codec_dev_wm8731 = { |
600 | { "wm8731", 0 }, | 543 | .probe = wm8731_probe, |
601 | { } | 544 | .remove = wm8731_remove, |
602 | }; | 545 | .suspend = wm8731_suspend, |
603 | MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id); | 546 | .resume = wm8731_resume, |
604 | |||
605 | static struct i2c_driver wm8731_i2c_driver = { | ||
606 | .driver = { | ||
607 | .name = "WM8731 I2C Codec", | ||
608 | .owner = THIS_MODULE, | ||
609 | }, | ||
610 | .probe = wm8731_i2c_probe, | ||
611 | .remove = wm8731_i2c_remove, | ||
612 | .id_table = wm8731_i2c_id, | ||
613 | }; | 547 | }; |
548 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); | ||
614 | 549 | ||
615 | static int wm8731_add_i2c_device(struct platform_device *pdev, | 550 | static int wm8731_register(struct wm8731_priv *wm8731) |
616 | const struct wm8731_setup_data *setup) | ||
617 | { | 551 | { |
618 | struct i2c_board_info info; | ||
619 | struct i2c_adapter *adapter; | ||
620 | struct i2c_client *client; | ||
621 | int ret; | 552 | int ret; |
553 | struct snd_soc_codec *codec = &wm8731->codec; | ||
554 | u16 reg; | ||
622 | 555 | ||
623 | ret = i2c_add_driver(&wm8731_i2c_driver); | 556 | if (wm8731_codec) { |
624 | if (ret != 0) { | 557 | dev_err(codec->dev, "Another WM8731 is registered\n"); |
625 | dev_err(&pdev->dev, "can't add i2c driver\n"); | 558 | return -EINVAL; |
626 | return ret; | ||
627 | } | 559 | } |
628 | 560 | ||
629 | memset(&info, 0, sizeof(struct i2c_board_info)); | 561 | mutex_init(&codec->mutex); |
630 | info.addr = setup->i2c_address; | 562 | INIT_LIST_HEAD(&codec->dapm_widgets); |
631 | strlcpy(info.type, "wm8731", I2C_NAME_SIZE); | 563 | INIT_LIST_HEAD(&codec->dapm_paths); |
632 | 564 | ||
633 | adapter = i2c_get_adapter(setup->i2c_bus); | 565 | codec->private_data = wm8731; |
634 | if (!adapter) { | 566 | codec->name = "WM8731"; |
635 | dev_err(&pdev->dev, "can't get i2c adapter %d\n", | 567 | codec->owner = THIS_MODULE; |
636 | setup->i2c_bus); | 568 | codec->read = wm8731_read_reg_cache; |
637 | goto err_driver; | 569 | codec->write = wm8731_write; |
638 | } | 570 | codec->bias_level = SND_SOC_BIAS_OFF; |
571 | codec->set_bias_level = wm8731_set_bias_level; | ||
572 | codec->dai = &wm8731_dai; | ||
573 | codec->num_dai = 1; | ||
574 | codec->reg_cache_size = WM8731_CACHEREGNUM; | ||
575 | codec->reg_cache = &wm8731->reg_cache; | ||
639 | 576 | ||
640 | client = i2c_new_device(adapter, &info); | 577 | memcpy(codec->reg_cache, wm8731_reg, sizeof(wm8731_reg)); |
641 | i2c_put_adapter(adapter); | 578 | |
642 | if (!client) { | 579 | ret = wm8731_reset(codec); |
643 | dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", | 580 | if (ret < 0) { |
644 | (unsigned int)info.addr); | 581 | dev_err(codec->dev, "Failed to issue reset\n"); |
645 | goto err_driver; | 582 | return ret; |
646 | } | 583 | } |
647 | 584 | ||
648 | return 0; | 585 | wm8731_dai.dev = codec->dev; |
649 | 586 | ||
650 | err_driver: | 587 | wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
651 | i2c_del_driver(&wm8731_i2c_driver); | ||
652 | return -ENODEV; | ||
653 | } | ||
654 | #endif | ||
655 | 588 | ||
656 | #if defined(CONFIG_SPI_MASTER) | 589 | /* Latch the update bits */ |
657 | static int __devinit wm8731_spi_probe(struct spi_device *spi) | 590 | reg = wm8731_read_reg_cache(codec, WM8731_LOUT1V); |
658 | { | 591 | wm8731_write(codec, WM8731_LOUT1V, reg & ~0x0100); |
659 | struct snd_soc_device *socdev = wm8731_socdev; | 592 | reg = wm8731_read_reg_cache(codec, WM8731_ROUT1V); |
660 | struct snd_soc_codec *codec = socdev->codec; | 593 | wm8731_write(codec, WM8731_ROUT1V, reg & ~0x0100); |
661 | int ret; | 594 | reg = wm8731_read_reg_cache(codec, WM8731_LINVOL); |
595 | wm8731_write(codec, WM8731_LINVOL, reg & ~0x0100); | ||
596 | reg = wm8731_read_reg_cache(codec, WM8731_RINVOL); | ||
597 | wm8731_write(codec, WM8731_RINVOL, reg & ~0x0100); | ||
662 | 598 | ||
663 | codec->control_data = spi; | 599 | /* Disable bypass path by default */ |
600 | reg = wm8731_read_reg_cache(codec, WM8731_APANA); | ||
601 | wm8731_write(codec, WM8731_APANA, reg & ~0x4); | ||
664 | 602 | ||
665 | ret = wm8731_init(socdev); | 603 | wm8731_codec = codec; |
666 | if (ret < 0) | ||
667 | dev_err(&spi->dev, "failed to initialise WM8731\n"); | ||
668 | 604 | ||
669 | return ret; | 605 | ret = snd_soc_register_codec(codec); |
670 | } | 606 | if (ret != 0) { |
607 | dev_err(codec->dev, "Failed to register codec: %d\n", ret); | ||
608 | return ret; | ||
609 | } | ||
610 | |||
611 | ret = snd_soc_register_dai(&wm8731_dai); | ||
612 | if (ret != 0) { | ||
613 | dev_err(codec->dev, "Failed to register DAI: %d\n", ret); | ||
614 | snd_soc_unregister_codec(codec); | ||
615 | return ret; | ||
616 | } | ||
671 | 617 | ||
672 | static int __devexit wm8731_spi_remove(struct spi_device *spi) | ||
673 | { | ||
674 | return 0; | 618 | return 0; |
675 | } | 619 | } |
676 | 620 | ||
677 | static struct spi_driver wm8731_spi_driver = { | 621 | static void wm8731_unregister(struct wm8731_priv *wm8731) |
678 | .driver = { | 622 | { |
679 | .name = "wm8731", | 623 | wm8731_set_bias_level(&wm8731->codec, SND_SOC_BIAS_OFF); |
680 | .bus = &spi_bus_type, | 624 | snd_soc_unregister_dai(&wm8731_dai); |
681 | .owner = THIS_MODULE, | 625 | snd_soc_unregister_codec(&wm8731->codec); |
682 | }, | 626 | kfree(wm8731); |
683 | .probe = wm8731_spi_probe, | 627 | wm8731_codec = NULL; |
684 | .remove = __devexit_p(wm8731_spi_remove), | 628 | } |
685 | }; | ||
686 | 629 | ||
630 | #if defined(CONFIG_SPI_MASTER) | ||
687 | static int wm8731_spi_write(struct spi_device *spi, const char *data, int len) | 631 | static int wm8731_spi_write(struct spi_device *spi, const char *data, int len) |
688 | { | 632 | { |
689 | struct spi_transfer t; | 633 | struct spi_transfer t; |
@@ -707,101 +651,121 @@ static int wm8731_spi_write(struct spi_device *spi, const char *data, int len) | |||
707 | 651 | ||
708 | return len; | 652 | return len; |
709 | } | 653 | } |
710 | #endif /* CONFIG_SPI_MASTER */ | ||
711 | 654 | ||
712 | static int wm8731_probe(struct platform_device *pdev) | 655 | static int __devinit wm8731_spi_probe(struct spi_device *spi) |
713 | { | 656 | { |
714 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
715 | struct wm8731_setup_data *setup; | ||
716 | struct snd_soc_codec *codec; | 657 | struct snd_soc_codec *codec; |
717 | struct wm8731_priv *wm8731; | 658 | struct wm8731_priv *wm8731; |
718 | int ret = 0; | ||
719 | |||
720 | pr_info("WM8731 Audio Codec %s", WM8731_VERSION); | ||
721 | |||
722 | setup = socdev->codec_data; | ||
723 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | ||
724 | if (codec == NULL) | ||
725 | return -ENOMEM; | ||
726 | 659 | ||
727 | wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); | 660 | wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); |
728 | if (wm8731 == NULL) { | 661 | if (wm8731 == NULL) |
729 | kfree(codec); | ||
730 | return -ENOMEM; | 662 | return -ENOMEM; |
731 | } | ||
732 | 663 | ||
733 | codec->private_data = wm8731; | 664 | codec = &wm8731->codec; |
734 | socdev->codec = codec; | 665 | codec->control_data = spi; |
735 | mutex_init(&codec->mutex); | 666 | codec->hw_write = (hw_write_t)wm8731_spi_write; |
736 | INIT_LIST_HEAD(&codec->dapm_widgets); | 667 | codec->dev = &spi->dev; |
737 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
738 | 668 | ||
739 | wm8731_socdev = socdev; | 669 | spi->dev.driver_data = wm8731; |
740 | ret = -ENODEV; | ||
741 | 670 | ||
742 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 671 | return wm8731_register(wm8731); |
743 | if (setup->i2c_address) { | ||
744 | codec->hw_write = (hw_write_t)i2c_master_send; | ||
745 | ret = wm8731_add_i2c_device(pdev, setup); | ||
746 | } | ||
747 | #endif | ||
748 | #if defined(CONFIG_SPI_MASTER) | ||
749 | if (setup->spi) { | ||
750 | codec->hw_write = (hw_write_t)wm8731_spi_write; | ||
751 | ret = spi_register_driver(&wm8731_spi_driver); | ||
752 | if (ret != 0) | ||
753 | printk(KERN_ERR "can't add spi driver"); | ||
754 | } | ||
755 | #endif | ||
756 | |||
757 | if (ret != 0) { | ||
758 | kfree(codec->private_data); | ||
759 | kfree(codec); | ||
760 | } | ||
761 | return ret; | ||
762 | } | 672 | } |
763 | 673 | ||
764 | /* power down chip */ | 674 | static int __devexit wm8731_spi_remove(struct spi_device *spi) |
765 | static int wm8731_remove(struct platform_device *pdev) | ||
766 | { | 675 | { |
767 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 676 | struct wm8731_priv *wm8731 = spi->dev.driver_data; |
768 | struct snd_soc_codec *codec = socdev->codec; | ||
769 | 677 | ||
770 | if (codec->control_data) | 678 | wm8731_unregister(wm8731); |
771 | wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF); | 679 | |
680 | return 0; | ||
681 | } | ||
682 | |||
683 | static struct spi_driver wm8731_spi_driver = { | ||
684 | .driver = { | ||
685 | .name = "wm8731", | ||
686 | .bus = &spi_bus_type, | ||
687 | .owner = THIS_MODULE, | ||
688 | }, | ||
689 | .probe = wm8731_spi_probe, | ||
690 | .remove = __devexit_p(wm8731_spi_remove), | ||
691 | }; | ||
692 | #endif /* CONFIG_SPI_MASTER */ | ||
772 | 693 | ||
773 | snd_soc_free_pcms(socdev); | ||
774 | snd_soc_dapm_free(socdev); | ||
775 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 694 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
776 | i2c_unregister_device(codec->control_data); | 695 | static __devinit int wm8731_i2c_probe(struct i2c_client *i2c, |
777 | i2c_del_driver(&wm8731_i2c_driver); | 696 | const struct i2c_device_id *id) |
778 | #endif | 697 | { |
779 | #if defined(CONFIG_SPI_MASTER) | 698 | struct wm8731_priv *wm8731; |
780 | spi_unregister_driver(&wm8731_spi_driver); | 699 | struct snd_soc_codec *codec; |
781 | #endif | 700 | |
782 | kfree(codec->private_data); | 701 | wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); |
783 | kfree(codec); | 702 | if (wm8731 == NULL) |
703 | return -ENOMEM; | ||
704 | |||
705 | codec = &wm8731->codec; | ||
706 | codec->hw_write = (hw_write_t)i2c_master_send; | ||
784 | 707 | ||
708 | i2c_set_clientdata(i2c, wm8731); | ||
709 | codec->control_data = i2c; | ||
710 | |||
711 | codec->dev = &i2c->dev; | ||
712 | |||
713 | return wm8731_register(wm8731); | ||
714 | } | ||
715 | |||
716 | static __devexit int wm8731_i2c_remove(struct i2c_client *client) | ||
717 | { | ||
718 | struct wm8731_priv *wm8731 = i2c_get_clientdata(client); | ||
719 | wm8731_unregister(wm8731); | ||
785 | return 0; | 720 | return 0; |
786 | } | 721 | } |
787 | 722 | ||
788 | struct snd_soc_codec_device soc_codec_dev_wm8731 = { | 723 | static const struct i2c_device_id wm8731_i2c_id[] = { |
789 | .probe = wm8731_probe, | 724 | { "wm8731", 0 }, |
790 | .remove = wm8731_remove, | 725 | { } |
791 | .suspend = wm8731_suspend, | ||
792 | .resume = wm8731_resume, | ||
793 | }; | 726 | }; |
794 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); | 727 | MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id); |
728 | |||
729 | static struct i2c_driver wm8731_i2c_driver = { | ||
730 | .driver = { | ||
731 | .name = "WM8731 I2C Codec", | ||
732 | .owner = THIS_MODULE, | ||
733 | }, | ||
734 | .probe = wm8731_i2c_probe, | ||
735 | .remove = __devexit_p(wm8731_i2c_remove), | ||
736 | .id_table = wm8731_i2c_id, | ||
737 | }; | ||
738 | #endif | ||
795 | 739 | ||
796 | static int __init wm8731_modinit(void) | 740 | static int __init wm8731_modinit(void) |
797 | { | 741 | { |
798 | return snd_soc_register_dai(&wm8731_dai); | 742 | int ret; |
743 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
744 | ret = i2c_add_driver(&wm8731_i2c_driver); | ||
745 | if (ret != 0) { | ||
746 | printk(KERN_ERR "Failed to register WM8731 I2C driver: %d\n", | ||
747 | ret); | ||
748 | } | ||
749 | #endif | ||
750 | #if defined(CONFIG_SPI_MASTER) | ||
751 | ret = spi_register_driver(&wm8731_spi_driver); | ||
752 | if (ret != 0) { | ||
753 | printk(KERN_ERR "Failed to register WM8731 SPI driver: %d\n", | ||
754 | ret); | ||
755 | } | ||
756 | #endif | ||
757 | return 0; | ||
799 | } | 758 | } |
800 | module_init(wm8731_modinit); | 759 | module_init(wm8731_modinit); |
801 | 760 | ||
802 | static void __exit wm8731_exit(void) | 761 | static void __exit wm8731_exit(void) |
803 | { | 762 | { |
804 | snd_soc_unregister_dai(&wm8731_dai); | 763 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
764 | i2c_del_driver(&wm8731_i2c_driver); | ||
765 | #endif | ||
766 | #if defined(CONFIG_SPI_MASTER) | ||
767 | spi_unregister_driver(&wm8731_spi_driver); | ||
768 | #endif | ||
805 | } | 769 | } |
806 | module_exit(wm8731_exit); | 770 | module_exit(wm8731_exit); |
807 | 771 | ||
diff --git a/sound/soc/codecs/wm8731.h b/sound/soc/codecs/wm8731.h index 95190e9c0c14..cd7b806e8ad0 100644 --- a/sound/soc/codecs/wm8731.h +++ b/sound/soc/codecs/wm8731.h | |||
@@ -34,12 +34,6 @@ | |||
34 | #define WM8731_SYSCLK 0 | 34 | #define WM8731_SYSCLK 0 |
35 | #define WM8731_DAI 0 | 35 | #define WM8731_DAI 0 |
36 | 36 | ||
37 | struct wm8731_setup_data { | ||
38 | int spi; | ||
39 | int i2c_bus; | ||
40 | unsigned short i2c_address; | ||
41 | }; | ||
42 | |||
43 | extern struct snd_soc_dai wm8731_dai; | 37 | extern struct snd_soc_dai wm8731_dai; |
44 | extern struct snd_soc_codec_device soc_codec_dev_wm8731; | 38 | extern struct snd_soc_codec_device soc_codec_dev_wm8731; |
45 | 39 | ||
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c index 5997fa68e0d5..b64509b01a49 100644 --- a/sound/soc/codecs/wm8750.c +++ b/sound/soc/codecs/wm8750.c | |||
@@ -231,21 +231,6 @@ SOC_SINGLE("Mono Playback Volume", WM8750_MOUTV, 0, 127, 0), | |||
231 | 231 | ||
232 | }; | 232 | }; |
233 | 233 | ||
234 | /* add non dapm controls */ | ||
235 | static int wm8750_add_controls(struct snd_soc_codec *codec) | ||
236 | { | ||
237 | int err, i; | ||
238 | |||
239 | for (i = 0; i < ARRAY_SIZE(wm8750_snd_controls); i++) { | ||
240 | err = snd_ctl_add(codec->card, | ||
241 | snd_soc_cnew(&wm8750_snd_controls[i], | ||
242 | codec, NULL)); | ||
243 | if (err < 0) | ||
244 | return err; | ||
245 | } | ||
246 | return 0; | ||
247 | } | ||
248 | |||
249 | /* | 234 | /* |
250 | * DAPM Controls | 235 | * DAPM Controls |
251 | */ | 236 | */ |
@@ -619,7 +604,7 @@ static int wm8750_pcm_hw_params(struct snd_pcm_substream *substream, | |||
619 | { | 604 | { |
620 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 605 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
621 | struct snd_soc_device *socdev = rtd->socdev; | 606 | struct snd_soc_device *socdev = rtd->socdev; |
622 | struct snd_soc_codec *codec = socdev->codec; | 607 | struct snd_soc_codec *codec = socdev->card->codec; |
623 | struct wm8750_priv *wm8750 = codec->private_data; | 608 | struct wm8750_priv *wm8750 = codec->private_data; |
624 | u16 iface = wm8750_read_reg_cache(codec, WM8750_IFACE) & 0x1f3; | 609 | u16 iface = wm8750_read_reg_cache(codec, WM8750_IFACE) & 0x1f3; |
625 | u16 srate = wm8750_read_reg_cache(codec, WM8750_SRATE) & 0x1c0; | 610 | u16 srate = wm8750_read_reg_cache(codec, WM8750_SRATE) & 0x1c0; |
@@ -694,6 +679,13 @@ static int wm8750_set_bias_level(struct snd_soc_codec *codec, | |||
694 | #define WM8750_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | 679 | #define WM8750_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
695 | SNDRV_PCM_FMTBIT_S24_LE) | 680 | SNDRV_PCM_FMTBIT_S24_LE) |
696 | 681 | ||
682 | static struct snd_soc_dai_ops wm8750_dai_ops = { | ||
683 | .hw_params = wm8750_pcm_hw_params, | ||
684 | .digital_mute = wm8750_mute, | ||
685 | .set_fmt = wm8750_set_dai_fmt, | ||
686 | .set_sysclk = wm8750_set_dai_sysclk, | ||
687 | }; | ||
688 | |||
697 | struct snd_soc_dai wm8750_dai = { | 689 | struct snd_soc_dai wm8750_dai = { |
698 | .name = "WM8750", | 690 | .name = "WM8750", |
699 | .playback = { | 691 | .playback = { |
@@ -708,12 +700,7 @@ struct snd_soc_dai wm8750_dai = { | |||
708 | .channels_max = 2, | 700 | .channels_max = 2, |
709 | .rates = WM8750_RATES, | 701 | .rates = WM8750_RATES, |
710 | .formats = WM8750_FORMATS,}, | 702 | .formats = WM8750_FORMATS,}, |
711 | .ops = { | 703 | .ops = &wm8750_dai_ops, |
712 | .hw_params = wm8750_pcm_hw_params, | ||
713 | .digital_mute = wm8750_mute, | ||
714 | .set_fmt = wm8750_set_dai_fmt, | ||
715 | .set_sysclk = wm8750_set_dai_sysclk, | ||
716 | }, | ||
717 | }; | 704 | }; |
718 | EXPORT_SYMBOL_GPL(wm8750_dai); | 705 | EXPORT_SYMBOL_GPL(wm8750_dai); |
719 | 706 | ||
@@ -727,7 +714,7 @@ static void wm8750_work(struct work_struct *work) | |||
727 | static int wm8750_suspend(struct platform_device *pdev, pm_message_t state) | 714 | static int wm8750_suspend(struct platform_device *pdev, pm_message_t state) |
728 | { | 715 | { |
729 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 716 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
730 | struct snd_soc_codec *codec = socdev->codec; | 717 | struct snd_soc_codec *codec = socdev->card->codec; |
731 | 718 | ||
732 | wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF); | 719 | wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF); |
733 | return 0; | 720 | return 0; |
@@ -736,7 +723,7 @@ static int wm8750_suspend(struct platform_device *pdev, pm_message_t state) | |||
736 | static int wm8750_resume(struct platform_device *pdev) | 723 | static int wm8750_resume(struct platform_device *pdev) |
737 | { | 724 | { |
738 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 725 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
739 | struct snd_soc_codec *codec = socdev->codec; | 726 | struct snd_soc_codec *codec = socdev->card->codec; |
740 | int i; | 727 | int i; |
741 | u8 data[2]; | 728 | u8 data[2]; |
742 | u16 *cache = codec->reg_cache; | 729 | u16 *cache = codec->reg_cache; |
@@ -769,7 +756,7 @@ static int wm8750_resume(struct platform_device *pdev) | |||
769 | */ | 756 | */ |
770 | static int wm8750_init(struct snd_soc_device *socdev) | 757 | static int wm8750_init(struct snd_soc_device *socdev) |
771 | { | 758 | { |
772 | struct snd_soc_codec *codec = socdev->codec; | 759 | struct snd_soc_codec *codec = socdev->card->codec; |
773 | int reg, ret = 0; | 760 | int reg, ret = 0; |
774 | 761 | ||
775 | codec->name = "WM8750"; | 762 | codec->name = "WM8750"; |
@@ -816,7 +803,8 @@ static int wm8750_init(struct snd_soc_device *socdev) | |||
816 | reg = wm8750_read_reg_cache(codec, WM8750_RINVOL); | 803 | reg = wm8750_read_reg_cache(codec, WM8750_RINVOL); |
817 | wm8750_write(codec, WM8750_RINVOL, reg | 0x0100); | 804 | wm8750_write(codec, WM8750_RINVOL, reg | 0x0100); |
818 | 805 | ||
819 | wm8750_add_controls(codec); | 806 | snd_soc_add_controls(codec, wm8750_snd_controls, |
807 | ARRAY_SIZE(wm8750_snd_controls)); | ||
820 | wm8750_add_widgets(codec); | 808 | wm8750_add_widgets(codec); |
821 | ret = snd_soc_init_card(socdev); | 809 | ret = snd_soc_init_card(socdev); |
822 | if (ret < 0) { | 810 | if (ret < 0) { |
@@ -850,7 +838,7 @@ static int wm8750_i2c_probe(struct i2c_client *i2c, | |||
850 | const struct i2c_device_id *id) | 838 | const struct i2c_device_id *id) |
851 | { | 839 | { |
852 | struct snd_soc_device *socdev = wm8750_socdev; | 840 | struct snd_soc_device *socdev = wm8750_socdev; |
853 | struct snd_soc_codec *codec = socdev->codec; | 841 | struct snd_soc_codec *codec = socdev->card->codec; |
854 | int ret; | 842 | int ret; |
855 | 843 | ||
856 | i2c_set_clientdata(i2c, codec); | 844 | i2c_set_clientdata(i2c, codec); |
@@ -931,7 +919,7 @@ err_driver: | |||
931 | static int __devinit wm8750_spi_probe(struct spi_device *spi) | 919 | static int __devinit wm8750_spi_probe(struct spi_device *spi) |
932 | { | 920 | { |
933 | struct snd_soc_device *socdev = wm8750_socdev; | 921 | struct snd_soc_device *socdev = wm8750_socdev; |
934 | struct snd_soc_codec *codec = socdev->codec; | 922 | struct snd_soc_codec *codec = socdev->card->codec; |
935 | int ret; | 923 | int ret; |
936 | 924 | ||
937 | codec->control_data = spi; | 925 | codec->control_data = spi; |
@@ -1003,7 +991,7 @@ static int wm8750_probe(struct platform_device *pdev) | |||
1003 | } | 991 | } |
1004 | 992 | ||
1005 | codec->private_data = wm8750; | 993 | codec->private_data = wm8750; |
1006 | socdev->codec = codec; | 994 | socdev->card->codec = codec; |
1007 | mutex_init(&codec->mutex); | 995 | mutex_init(&codec->mutex); |
1008 | INIT_LIST_HEAD(&codec->dapm_widgets); | 996 | INIT_LIST_HEAD(&codec->dapm_widgets); |
1009 | INIT_LIST_HEAD(&codec->dapm_paths); | 997 | INIT_LIST_HEAD(&codec->dapm_paths); |
@@ -1057,7 +1045,7 @@ static int run_delayed_work(struct delayed_work *dwork) | |||
1057 | static int wm8750_remove(struct platform_device *pdev) | 1045 | static int wm8750_remove(struct platform_device *pdev) |
1058 | { | 1046 | { |
1059 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1047 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1060 | struct snd_soc_codec *codec = socdev->codec; | 1048 | struct snd_soc_codec *codec = socdev->card->codec; |
1061 | 1049 | ||
1062 | if (codec->control_data) | 1050 | if (codec->control_data) |
1063 | wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF); | 1051 | wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF); |
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c index 77620ab98756..a6e8f3f7f052 100644 --- a/sound/soc/codecs/wm8753.c +++ b/sound/soc/codecs/wm8753.c | |||
@@ -51,8 +51,6 @@ | |||
51 | 51 | ||
52 | #include "wm8753.h" | 52 | #include "wm8753.h" |
53 | 53 | ||
54 | #define WM8753_VERSION "0.16" | ||
55 | |||
56 | static int caps_charge = 2000; | 54 | static int caps_charge = 2000; |
57 | module_param(caps_charge, int, 0); | 55 | module_param(caps_charge, int, 0); |
58 | MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)"); | 56 | MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)"); |
@@ -60,12 +58,6 @@ MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)"); | |||
60 | static void wm8753_set_dai_mode(struct snd_soc_codec *codec, | 58 | static void wm8753_set_dai_mode(struct snd_soc_codec *codec, |
61 | unsigned int mode); | 59 | unsigned int mode); |
62 | 60 | ||
63 | /* codec private data */ | ||
64 | struct wm8753_priv { | ||
65 | unsigned int sysclk; | ||
66 | unsigned int pcmclk; | ||
67 | }; | ||
68 | |||
69 | /* | 61 | /* |
70 | * wm8753 register cache | 62 | * wm8753 register cache |
71 | * We can't read the WM8753 register space when we | 63 | * We can't read the WM8753 register space when we |
@@ -90,6 +82,14 @@ static const u16 wm8753_reg[] = { | |||
90 | 0x0000, 0x0000 | 82 | 0x0000, 0x0000 |
91 | }; | 83 | }; |
92 | 84 | ||
85 | /* codec private data */ | ||
86 | struct wm8753_priv { | ||
87 | unsigned int sysclk; | ||
88 | unsigned int pcmclk; | ||
89 | struct snd_soc_codec codec; | ||
90 | u16 reg_cache[ARRAY_SIZE(wm8753_reg)]; | ||
91 | }; | ||
92 | |||
93 | /* | 93 | /* |
94 | * read wm8753 register cache | 94 | * read wm8753 register cache |
95 | */ | 95 | */ |
@@ -97,7 +97,7 @@ static inline unsigned int wm8753_read_reg_cache(struct snd_soc_codec *codec, | |||
97 | unsigned int reg) | 97 | unsigned int reg) |
98 | { | 98 | { |
99 | u16 *cache = codec->reg_cache; | 99 | u16 *cache = codec->reg_cache; |
100 | if (reg < 1 || reg > (ARRAY_SIZE(wm8753_reg) + 1)) | 100 | if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1)) |
101 | return -1; | 101 | return -1; |
102 | return cache[reg - 1]; | 102 | return cache[reg - 1]; |
103 | } | 103 | } |
@@ -109,7 +109,7 @@ static inline void wm8753_write_reg_cache(struct snd_soc_codec *codec, | |||
109 | unsigned int reg, unsigned int value) | 109 | unsigned int reg, unsigned int value) |
110 | { | 110 | { |
111 | u16 *cache = codec->reg_cache; | 111 | u16 *cache = codec->reg_cache; |
112 | if (reg < 1 || reg > 0x3f) | 112 | if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1)) |
113 | return; | 113 | return; |
114 | cache[reg - 1] = value; | 114 | cache[reg - 1] = value; |
115 | } | 115 | } |
@@ -339,21 +339,6 @@ SOC_ENUM("ADC Data Select", wm8753_enum[27]), | |||
339 | SOC_ENUM("ROUT2 Phase", wm8753_enum[28]), | 339 | SOC_ENUM("ROUT2 Phase", wm8753_enum[28]), |
340 | }; | 340 | }; |
341 | 341 | ||
342 | /* add non dapm controls */ | ||
343 | static int wm8753_add_controls(struct snd_soc_codec *codec) | ||
344 | { | ||
345 | int err, i; | ||
346 | |||
347 | for (i = 0; i < ARRAY_SIZE(wm8753_snd_controls); i++) { | ||
348 | err = snd_ctl_add(codec->card, | ||
349 | snd_soc_cnew(&wm8753_snd_controls[i], | ||
350 | codec, NULL)); | ||
351 | if (err < 0) | ||
352 | return err; | ||
353 | } | ||
354 | return 0; | ||
355 | } | ||
356 | |||
357 | /* | 342 | /* |
358 | * _DAPM_ Controls | 343 | * _DAPM_ Controls |
359 | */ | 344 | */ |
@@ -927,7 +912,7 @@ static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream, | |||
927 | { | 912 | { |
928 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 913 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
929 | struct snd_soc_device *socdev = rtd->socdev; | 914 | struct snd_soc_device *socdev = rtd->socdev; |
930 | struct snd_soc_codec *codec = socdev->codec; | 915 | struct snd_soc_codec *codec = socdev->card->codec; |
931 | struct wm8753_priv *wm8753 = codec->private_data; | 916 | struct wm8753_priv *wm8753 = codec->private_data; |
932 | u16 voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x01f3; | 917 | u16 voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x01f3; |
933 | u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x017f; | 918 | u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x017f; |
@@ -1161,7 +1146,7 @@ static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream, | |||
1161 | { | 1146 | { |
1162 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1147 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
1163 | struct snd_soc_device *socdev = rtd->socdev; | 1148 | struct snd_soc_device *socdev = rtd->socdev; |
1164 | struct snd_soc_codec *codec = socdev->codec; | 1149 | struct snd_soc_codec *codec = socdev->card->codec; |
1165 | struct wm8753_priv *wm8753 = codec->private_data; | 1150 | struct wm8753_priv *wm8753 = codec->private_data; |
1166 | u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x01c0; | 1151 | u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x01c0; |
1167 | u16 hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x01f3; | 1152 | u16 hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x01f3; |
@@ -1316,6 +1301,51 @@ static int wm8753_set_bias_level(struct snd_soc_codec *codec, | |||
1316 | * 3. Voice disabled - HIFI over HIFI | 1301 | * 3. Voice disabled - HIFI over HIFI |
1317 | * 4. Voice disabled - HIFI over HIFI, uses voice DAI LRC for capture | 1302 | * 4. Voice disabled - HIFI over HIFI, uses voice DAI LRC for capture |
1318 | */ | 1303 | */ |
1304 | static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode1 = { | ||
1305 | .hw_params = wm8753_i2s_hw_params, | ||
1306 | .digital_mute = wm8753_mute, | ||
1307 | .set_fmt = wm8753_mode1h_set_dai_fmt, | ||
1308 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1309 | .set_pll = wm8753_set_dai_pll, | ||
1310 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1311 | }; | ||
1312 | |||
1313 | static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode1 = { | ||
1314 | .hw_params = wm8753_pcm_hw_params, | ||
1315 | .digital_mute = wm8753_mute, | ||
1316 | .set_fmt = wm8753_mode1v_set_dai_fmt, | ||
1317 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1318 | .set_pll = wm8753_set_dai_pll, | ||
1319 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1320 | }; | ||
1321 | |||
1322 | static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode2 = { | ||
1323 | .hw_params = wm8753_pcm_hw_params, | ||
1324 | .digital_mute = wm8753_mute, | ||
1325 | .set_fmt = wm8753_mode2_set_dai_fmt, | ||
1326 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1327 | .set_pll = wm8753_set_dai_pll, | ||
1328 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1329 | }; | ||
1330 | |||
1331 | static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode3 = { | ||
1332 | .hw_params = wm8753_i2s_hw_params, | ||
1333 | .digital_mute = wm8753_mute, | ||
1334 | .set_fmt = wm8753_mode3_4_set_dai_fmt, | ||
1335 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1336 | .set_pll = wm8753_set_dai_pll, | ||
1337 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1338 | }; | ||
1339 | |||
1340 | static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode4 = { | ||
1341 | .hw_params = wm8753_i2s_hw_params, | ||
1342 | .digital_mute = wm8753_mute, | ||
1343 | .set_fmt = wm8753_mode3_4_set_dai_fmt, | ||
1344 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1345 | .set_pll = wm8753_set_dai_pll, | ||
1346 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1347 | }; | ||
1348 | |||
1319 | static const struct snd_soc_dai wm8753_all_dai[] = { | 1349 | static const struct snd_soc_dai wm8753_all_dai[] = { |
1320 | /* DAI HiFi mode 1 */ | 1350 | /* DAI HiFi mode 1 */ |
1321 | { .name = "WM8753 HiFi", | 1351 | { .name = "WM8753 HiFi", |
@@ -1332,14 +1362,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = { | |||
1332 | .channels_max = 2, | 1362 | .channels_max = 2, |
1333 | .rates = WM8753_RATES, | 1363 | .rates = WM8753_RATES, |
1334 | .formats = WM8753_FORMATS}, | 1364 | .formats = WM8753_FORMATS}, |
1335 | .ops = { | 1365 | .ops = &wm8753_dai_ops_hifi_mode1, |
1336 | .hw_params = wm8753_i2s_hw_params, | ||
1337 | .digital_mute = wm8753_mute, | ||
1338 | .set_fmt = wm8753_mode1h_set_dai_fmt, | ||
1339 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1340 | .set_pll = wm8753_set_dai_pll, | ||
1341 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1342 | }, | ||
1343 | }, | 1366 | }, |
1344 | /* DAI Voice mode 1 */ | 1367 | /* DAI Voice mode 1 */ |
1345 | { .name = "WM8753 Voice", | 1368 | { .name = "WM8753 Voice", |
@@ -1356,14 +1379,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = { | |||
1356 | .channels_max = 2, | 1379 | .channels_max = 2, |
1357 | .rates = WM8753_RATES, | 1380 | .rates = WM8753_RATES, |
1358 | .formats = WM8753_FORMATS,}, | 1381 | .formats = WM8753_FORMATS,}, |
1359 | .ops = { | 1382 | .ops = &wm8753_dai_ops_voice_mode1, |
1360 | .hw_params = wm8753_pcm_hw_params, | ||
1361 | .digital_mute = wm8753_mute, | ||
1362 | .set_fmt = wm8753_mode1v_set_dai_fmt, | ||
1363 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1364 | .set_pll = wm8753_set_dai_pll, | ||
1365 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1366 | }, | ||
1367 | }, | 1383 | }, |
1368 | /* DAI HiFi mode 2 - dummy */ | 1384 | /* DAI HiFi mode 2 - dummy */ |
1369 | { .name = "WM8753 HiFi", | 1385 | { .name = "WM8753 HiFi", |
@@ -1384,14 +1400,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = { | |||
1384 | .channels_max = 2, | 1400 | .channels_max = 2, |
1385 | .rates = WM8753_RATES, | 1401 | .rates = WM8753_RATES, |
1386 | .formats = WM8753_FORMATS,}, | 1402 | .formats = WM8753_FORMATS,}, |
1387 | .ops = { | 1403 | .ops = &wm8753_dai_ops_voice_mode2, |
1388 | .hw_params = wm8753_pcm_hw_params, | ||
1389 | .digital_mute = wm8753_mute, | ||
1390 | .set_fmt = wm8753_mode2_set_dai_fmt, | ||
1391 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1392 | .set_pll = wm8753_set_dai_pll, | ||
1393 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1394 | }, | ||
1395 | }, | 1404 | }, |
1396 | /* DAI HiFi mode 3 */ | 1405 | /* DAI HiFi mode 3 */ |
1397 | { .name = "WM8753 HiFi", | 1406 | { .name = "WM8753 HiFi", |
@@ -1408,14 +1417,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = { | |||
1408 | .channels_max = 2, | 1417 | .channels_max = 2, |
1409 | .rates = WM8753_RATES, | 1418 | .rates = WM8753_RATES, |
1410 | .formats = WM8753_FORMATS,}, | 1419 | .formats = WM8753_FORMATS,}, |
1411 | .ops = { | 1420 | .ops = &wm8753_dai_ops_hifi_mode3, |
1412 | .hw_params = wm8753_i2s_hw_params, | ||
1413 | .digital_mute = wm8753_mute, | ||
1414 | .set_fmt = wm8753_mode3_4_set_dai_fmt, | ||
1415 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1416 | .set_pll = wm8753_set_dai_pll, | ||
1417 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1418 | }, | ||
1419 | }, | 1421 | }, |
1420 | /* DAI Voice mode 3 - dummy */ | 1422 | /* DAI Voice mode 3 - dummy */ |
1421 | { .name = "WM8753 Voice", | 1423 | { .name = "WM8753 Voice", |
@@ -1436,14 +1438,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = { | |||
1436 | .channels_max = 2, | 1438 | .channels_max = 2, |
1437 | .rates = WM8753_RATES, | 1439 | .rates = WM8753_RATES, |
1438 | .formats = WM8753_FORMATS,}, | 1440 | .formats = WM8753_FORMATS,}, |
1439 | .ops = { | 1441 | .ops = &wm8753_dai_ops_hifi_mode4, |
1440 | .hw_params = wm8753_i2s_hw_params, | ||
1441 | .digital_mute = wm8753_mute, | ||
1442 | .set_fmt = wm8753_mode3_4_set_dai_fmt, | ||
1443 | .set_clkdiv = wm8753_set_dai_clkdiv, | ||
1444 | .set_pll = wm8753_set_dai_pll, | ||
1445 | .set_sysclk = wm8753_set_dai_sysclk, | ||
1446 | }, | ||
1447 | }, | 1442 | }, |
1448 | /* DAI Voice mode 4 - dummy */ | 1443 | /* DAI Voice mode 4 - dummy */ |
1449 | { .name = "WM8753 Voice", | 1444 | { .name = "WM8753 Voice", |
@@ -1466,30 +1461,35 @@ static void wm8753_set_dai_mode(struct snd_soc_codec *codec, unsigned int mode) | |||
1466 | if (mode < 4) { | 1461 | if (mode < 4) { |
1467 | int playback_active, capture_active, codec_active, pop_wait; | 1462 | int playback_active, capture_active, codec_active, pop_wait; |
1468 | void *private_data; | 1463 | void *private_data; |
1464 | struct list_head list; | ||
1469 | 1465 | ||
1470 | playback_active = wm8753_dai[0].playback.active; | 1466 | playback_active = wm8753_dai[0].playback.active; |
1471 | capture_active = wm8753_dai[0].capture.active; | 1467 | capture_active = wm8753_dai[0].capture.active; |
1472 | codec_active = wm8753_dai[0].active; | 1468 | codec_active = wm8753_dai[0].active; |
1473 | private_data = wm8753_dai[0].private_data; | 1469 | private_data = wm8753_dai[0].private_data; |
1474 | pop_wait = wm8753_dai[0].pop_wait; | 1470 | pop_wait = wm8753_dai[0].pop_wait; |
1471 | list = wm8753_dai[0].list; | ||
1475 | wm8753_dai[0] = wm8753_all_dai[mode << 1]; | 1472 | wm8753_dai[0] = wm8753_all_dai[mode << 1]; |
1476 | wm8753_dai[0].playback.active = playback_active; | 1473 | wm8753_dai[0].playback.active = playback_active; |
1477 | wm8753_dai[0].capture.active = capture_active; | 1474 | wm8753_dai[0].capture.active = capture_active; |
1478 | wm8753_dai[0].active = codec_active; | 1475 | wm8753_dai[0].active = codec_active; |
1479 | wm8753_dai[0].private_data = private_data; | 1476 | wm8753_dai[0].private_data = private_data; |
1480 | wm8753_dai[0].pop_wait = pop_wait; | 1477 | wm8753_dai[0].pop_wait = pop_wait; |
1478 | wm8753_dai[0].list = list; | ||
1481 | 1479 | ||
1482 | playback_active = wm8753_dai[1].playback.active; | 1480 | playback_active = wm8753_dai[1].playback.active; |
1483 | capture_active = wm8753_dai[1].capture.active; | 1481 | capture_active = wm8753_dai[1].capture.active; |
1484 | codec_active = wm8753_dai[1].active; | 1482 | codec_active = wm8753_dai[1].active; |
1485 | private_data = wm8753_dai[1].private_data; | 1483 | private_data = wm8753_dai[1].private_data; |
1486 | pop_wait = wm8753_dai[1].pop_wait; | 1484 | pop_wait = wm8753_dai[1].pop_wait; |
1485 | list = wm8753_dai[1].list; | ||
1487 | wm8753_dai[1] = wm8753_all_dai[(mode << 1) + 1]; | 1486 | wm8753_dai[1] = wm8753_all_dai[(mode << 1) + 1]; |
1488 | wm8753_dai[1].playback.active = playback_active; | 1487 | wm8753_dai[1].playback.active = playback_active; |
1489 | wm8753_dai[1].capture.active = capture_active; | 1488 | wm8753_dai[1].capture.active = capture_active; |
1490 | wm8753_dai[1].active = codec_active; | 1489 | wm8753_dai[1].active = codec_active; |
1491 | wm8753_dai[1].private_data = private_data; | 1490 | wm8753_dai[1].private_data = private_data; |
1492 | wm8753_dai[1].pop_wait = pop_wait; | 1491 | wm8753_dai[1].pop_wait = pop_wait; |
1492 | wm8753_dai[1].list = list; | ||
1493 | } | 1493 | } |
1494 | wm8753_dai[0].codec = codec; | 1494 | wm8753_dai[0].codec = codec; |
1495 | wm8753_dai[1].codec = codec; | 1495 | wm8753_dai[1].codec = codec; |
@@ -1505,7 +1505,7 @@ static void wm8753_work(struct work_struct *work) | |||
1505 | static int wm8753_suspend(struct platform_device *pdev, pm_message_t state) | 1505 | static int wm8753_suspend(struct platform_device *pdev, pm_message_t state) |
1506 | { | 1506 | { |
1507 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1507 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1508 | struct snd_soc_codec *codec = socdev->codec; | 1508 | struct snd_soc_codec *codec = socdev->card->codec; |
1509 | 1509 | ||
1510 | /* we only need to suspend if we are a valid card */ | 1510 | /* we only need to suspend if we are a valid card */ |
1511 | if (!codec->card) | 1511 | if (!codec->card) |
@@ -1518,7 +1518,7 @@ static int wm8753_suspend(struct platform_device *pdev, pm_message_t state) | |||
1518 | static int wm8753_resume(struct platform_device *pdev) | 1518 | static int wm8753_resume(struct platform_device *pdev) |
1519 | { | 1519 | { |
1520 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1520 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1521 | struct snd_soc_codec *codec = socdev->codec; | 1521 | struct snd_soc_codec *codec = socdev->card->codec; |
1522 | int i; | 1522 | int i; |
1523 | u8 data[2]; | 1523 | u8 data[2]; |
1524 | u16 *cache = codec->reg_cache; | 1524 | u16 *cache = codec->reg_cache; |
@@ -1531,6 +1531,11 @@ static int wm8753_resume(struct platform_device *pdev) | |||
1531 | for (i = 0; i < ARRAY_SIZE(wm8753_reg); i++) { | 1531 | for (i = 0; i < ARRAY_SIZE(wm8753_reg); i++) { |
1532 | if (i + 1 == WM8753_RESET) | 1532 | if (i + 1 == WM8753_RESET) |
1533 | continue; | 1533 | continue; |
1534 | |||
1535 | /* No point in writing hardware default values back */ | ||
1536 | if (cache[i] == wm8753_reg[i]) | ||
1537 | continue; | ||
1538 | |||
1534 | data[0] = ((i + 1) << 1) | ((cache[i] >> 8) & 0x0001); | 1539 | data[0] = ((i + 1) << 1) | ((cache[i] >> 8) & 0x0001); |
1535 | data[1] = cache[i] & 0x00ff; | 1540 | data[1] = cache[i] & 0x00ff; |
1536 | codec->hw_write(codec->control_data, data, 2); | 1541 | codec->hw_write(codec->control_data, data, 2); |
@@ -1549,44 +1554,129 @@ static int wm8753_resume(struct platform_device *pdev) | |||
1549 | return 0; | 1554 | return 0; |
1550 | } | 1555 | } |
1551 | 1556 | ||
1557 | static struct snd_soc_codec *wm8753_codec; | ||
1558 | |||
1559 | static int wm8753_probe(struct platform_device *pdev) | ||
1560 | { | ||
1561 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1562 | struct snd_soc_codec *codec; | ||
1563 | int ret = 0; | ||
1564 | |||
1565 | if (!wm8753_codec) { | ||
1566 | dev_err(&pdev->dev, "WM8753 codec not yet registered\n"); | ||
1567 | return -EINVAL; | ||
1568 | } | ||
1569 | |||
1570 | socdev->card->codec = wm8753_codec; | ||
1571 | codec = wm8753_codec; | ||
1572 | |||
1573 | wm8753_set_dai_mode(codec, 0); | ||
1574 | |||
1575 | /* register pcms */ | ||
1576 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
1577 | if (ret < 0) { | ||
1578 | printk(KERN_ERR "wm8753: failed to create pcms\n"); | ||
1579 | goto pcm_err; | ||
1580 | } | ||
1581 | |||
1582 | snd_soc_add_controls(codec, wm8753_snd_controls, | ||
1583 | ARRAY_SIZE(wm8753_snd_controls)); | ||
1584 | wm8753_add_widgets(codec); | ||
1585 | ret = snd_soc_init_card(socdev); | ||
1586 | if (ret < 0) { | ||
1587 | printk(KERN_ERR "wm8753: failed to register card\n"); | ||
1588 | goto card_err; | ||
1589 | } | ||
1590 | |||
1591 | return 0; | ||
1592 | |||
1593 | card_err: | ||
1594 | snd_soc_free_pcms(socdev); | ||
1595 | snd_soc_dapm_free(socdev); | ||
1596 | |||
1597 | pcm_err: | ||
1598 | return ret; | ||
1599 | } | ||
1600 | |||
1552 | /* | 1601 | /* |
1553 | * initialise the WM8753 driver | 1602 | * This function forces any delayed work to be queued and run. |
1554 | * register the mixer and dsp interfaces with the kernel | ||
1555 | */ | 1603 | */ |
1556 | static int wm8753_init(struct snd_soc_device *socdev) | 1604 | static int run_delayed_work(struct delayed_work *dwork) |
1605 | { | ||
1606 | int ret; | ||
1607 | |||
1608 | /* cancel any work waiting to be queued. */ | ||
1609 | ret = cancel_delayed_work(dwork); | ||
1610 | |||
1611 | /* if there was any work waiting then we run it now and | ||
1612 | * wait for it's completion */ | ||
1613 | if (ret) { | ||
1614 | schedule_delayed_work(dwork, 0); | ||
1615 | flush_scheduled_work(); | ||
1616 | } | ||
1617 | return ret; | ||
1618 | } | ||
1619 | |||
1620 | /* power down chip */ | ||
1621 | static int wm8753_remove(struct platform_device *pdev) | ||
1557 | { | 1622 | { |
1558 | struct snd_soc_codec *codec = socdev->codec; | 1623 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1559 | int reg, ret = 0; | 1624 | |
1625 | snd_soc_free_pcms(socdev); | ||
1626 | snd_soc_dapm_free(socdev); | ||
1627 | |||
1628 | return 0; | ||
1629 | } | ||
1630 | |||
1631 | struct snd_soc_codec_device soc_codec_dev_wm8753 = { | ||
1632 | .probe = wm8753_probe, | ||
1633 | .remove = wm8753_remove, | ||
1634 | .suspend = wm8753_suspend, | ||
1635 | .resume = wm8753_resume, | ||
1636 | }; | ||
1637 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753); | ||
1638 | |||
1639 | static int wm8753_register(struct wm8753_priv *wm8753) | ||
1640 | { | ||
1641 | int ret, i; | ||
1642 | struct snd_soc_codec *codec = &wm8753->codec; | ||
1643 | u16 reg; | ||
1644 | |||
1645 | if (wm8753_codec) { | ||
1646 | dev_err(codec->dev, "Multiple WM8753 devices not supported\n"); | ||
1647 | ret = -EINVAL; | ||
1648 | goto err; | ||
1649 | } | ||
1650 | |||
1651 | mutex_init(&codec->mutex); | ||
1652 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
1653 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
1560 | 1654 | ||
1561 | codec->name = "WM8753"; | 1655 | codec->name = "WM8753"; |
1562 | codec->owner = THIS_MODULE; | 1656 | codec->owner = THIS_MODULE; |
1563 | codec->read = wm8753_read_reg_cache; | 1657 | codec->read = wm8753_read_reg_cache; |
1564 | codec->write = wm8753_write; | 1658 | codec->write = wm8753_write; |
1659 | codec->bias_level = SND_SOC_BIAS_STANDBY; | ||
1565 | codec->set_bias_level = wm8753_set_bias_level; | 1660 | codec->set_bias_level = wm8753_set_bias_level; |
1566 | codec->dai = wm8753_dai; | 1661 | codec->dai = wm8753_dai; |
1567 | codec->num_dai = 2; | 1662 | codec->num_dai = 2; |
1568 | codec->reg_cache_size = ARRAY_SIZE(wm8753_reg); | 1663 | codec->reg_cache_size = ARRAY_SIZE(wm8753->reg_cache); |
1569 | codec->reg_cache = kmemdup(wm8753_reg, sizeof(wm8753_reg), GFP_KERNEL); | 1664 | codec->reg_cache = &wm8753->reg_cache; |
1570 | 1665 | codec->private_data = wm8753; | |
1571 | if (codec->reg_cache == NULL) | ||
1572 | return -ENOMEM; | ||
1573 | |||
1574 | wm8753_set_dai_mode(codec, 0); | ||
1575 | 1666 | ||
1576 | wm8753_reset(codec); | 1667 | memcpy(codec->reg_cache, wm8753_reg, sizeof(codec->reg_cache)); |
1668 | INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work); | ||
1577 | 1669 | ||
1578 | /* register pcms */ | 1670 | ret = wm8753_reset(codec); |
1579 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
1580 | if (ret < 0) { | 1671 | if (ret < 0) { |
1581 | printk(KERN_ERR "wm8753: failed to create pcms\n"); | 1672 | dev_err(codec->dev, "Failed to issue reset\n"); |
1582 | goto pcm_err; | 1673 | goto err; |
1583 | } | 1674 | } |
1584 | 1675 | ||
1585 | /* charge output caps */ | 1676 | /* charge output caps */ |
1586 | wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE); | 1677 | wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE); |
1587 | codec->bias_level = SND_SOC_BIAS_STANDBY; | ||
1588 | schedule_delayed_work(&codec->delayed_work, | 1678 | schedule_delayed_work(&codec->delayed_work, |
1589 | msecs_to_jiffies(caps_charge)); | 1679 | msecs_to_jiffies(caps_charge)); |
1590 | 1680 | ||
1591 | /* set the update bits */ | 1681 | /* set the update bits */ |
1592 | reg = wm8753_read_reg_cache(codec, WM8753_LDAC); | 1682 | reg = wm8753_read_reg_cache(codec, WM8753_LDAC); |
@@ -1610,59 +1700,70 @@ static int wm8753_init(struct snd_soc_device *socdev) | |||
1610 | reg = wm8753_read_reg_cache(codec, WM8753_RINVOL); | 1700 | reg = wm8753_read_reg_cache(codec, WM8753_RINVOL); |
1611 | wm8753_write(codec, WM8753_RINVOL, reg | 0x0100); | 1701 | wm8753_write(codec, WM8753_RINVOL, reg | 0x0100); |
1612 | 1702 | ||
1613 | wm8753_add_controls(codec); | 1703 | wm8753_codec = codec; |
1614 | wm8753_add_widgets(codec); | 1704 | |
1615 | ret = snd_soc_init_card(socdev); | 1705 | for (i = 0; i < ARRAY_SIZE(wm8753_dai); i++) |
1616 | if (ret < 0) { | 1706 | wm8753_dai[i].dev = codec->dev; |
1617 | printk(KERN_ERR "wm8753: failed to register card\n"); | 1707 | |
1618 | goto card_err; | 1708 | ret = snd_soc_register_codec(codec); |
1709 | if (ret != 0) { | ||
1710 | dev_err(codec->dev, "Failed to register codec: %d\n", ret); | ||
1711 | goto err; | ||
1619 | } | 1712 | } |
1620 | 1713 | ||
1621 | return ret; | 1714 | ret = snd_soc_register_dais(&wm8753_dai[0], ARRAY_SIZE(wm8753_dai)); |
1715 | if (ret != 0) { | ||
1716 | dev_err(codec->dev, "Failed to register DAIs: %d\n", ret); | ||
1717 | goto err_codec; | ||
1718 | } | ||
1622 | 1719 | ||
1623 | card_err: | 1720 | return 0; |
1624 | snd_soc_free_pcms(socdev); | 1721 | |
1625 | snd_soc_dapm_free(socdev); | 1722 | err_codec: |
1626 | pcm_err: | 1723 | run_delayed_work(&codec->delayed_work); |
1627 | kfree(codec->reg_cache); | 1724 | snd_soc_unregister_codec(codec); |
1725 | err: | ||
1726 | kfree(wm8753); | ||
1628 | return ret; | 1727 | return ret; |
1629 | } | 1728 | } |
1630 | 1729 | ||
1631 | /* If the i2c layer weren't so broken, we could pass this kind of data | 1730 | static void wm8753_unregister(struct wm8753_priv *wm8753) |
1632 | around */ | 1731 | { |
1633 | static struct snd_soc_device *wm8753_socdev; | 1732 | wm8753_set_bias_level(&wm8753->codec, SND_SOC_BIAS_OFF); |
1733 | run_delayed_work(&wm8753->codec.delayed_work); | ||
1734 | snd_soc_unregister_dais(&wm8753_dai[0], ARRAY_SIZE(wm8753_dai)); | ||
1735 | snd_soc_unregister_codec(&wm8753->codec); | ||
1736 | kfree(wm8753); | ||
1737 | wm8753_codec = NULL; | ||
1738 | } | ||
1634 | 1739 | ||
1635 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1740 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1636 | 1741 | ||
1637 | /* | ||
1638 | * WM8753 2 wire address is determined by GPIO5 | ||
1639 | * state during powerup. | ||
1640 | * low = 0x1a | ||
1641 | * high = 0x1b | ||
1642 | */ | ||
1643 | |||
1644 | static int wm8753_i2c_probe(struct i2c_client *i2c, | 1742 | static int wm8753_i2c_probe(struct i2c_client *i2c, |
1645 | const struct i2c_device_id *id) | 1743 | const struct i2c_device_id *id) |
1646 | { | 1744 | { |
1647 | struct snd_soc_device *socdev = wm8753_socdev; | 1745 | struct snd_soc_codec *codec; |
1648 | struct snd_soc_codec *codec = socdev->codec; | 1746 | struct wm8753_priv *wm8753; |
1649 | int ret; | ||
1650 | 1747 | ||
1651 | i2c_set_clientdata(i2c, codec); | 1748 | wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL); |
1652 | codec->control_data = i2c; | 1749 | if (wm8753 == NULL) |
1750 | return -ENOMEM; | ||
1653 | 1751 | ||
1654 | ret = wm8753_init(socdev); | 1752 | codec = &wm8753->codec; |
1655 | if (ret < 0) | 1753 | codec->hw_write = (hw_write_t)i2c_master_send; |
1656 | pr_err("failed to initialise WM8753\n"); | 1754 | codec->control_data = i2c; |
1755 | i2c_set_clientdata(i2c, wm8753); | ||
1657 | 1756 | ||
1658 | return ret; | 1757 | codec->dev = &i2c->dev; |
1758 | |||
1759 | return wm8753_register(wm8753); | ||
1659 | } | 1760 | } |
1660 | 1761 | ||
1661 | static int wm8753_i2c_remove(struct i2c_client *client) | 1762 | static int wm8753_i2c_remove(struct i2c_client *client) |
1662 | { | 1763 | { |
1663 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | 1764 | struct wm8753_priv *wm8753 = i2c_get_clientdata(client); |
1664 | kfree(codec->reg_cache); | 1765 | wm8753_unregister(wm8753); |
1665 | return 0; | 1766 | return 0; |
1666 | } | 1767 | } |
1667 | 1768 | ||
1668 | static const struct i2c_device_id wm8753_i2c_id[] = { | 1769 | static const struct i2c_device_id wm8753_i2c_id[] = { |
@@ -1673,86 +1774,16 @@ MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id); | |||
1673 | 1774 | ||
1674 | static struct i2c_driver wm8753_i2c_driver = { | 1775 | static struct i2c_driver wm8753_i2c_driver = { |
1675 | .driver = { | 1776 | .driver = { |
1676 | .name = "WM8753 I2C Codec", | 1777 | .name = "wm8753", |
1677 | .owner = THIS_MODULE, | 1778 | .owner = THIS_MODULE, |
1678 | }, | 1779 | }, |
1679 | .probe = wm8753_i2c_probe, | 1780 | .probe = wm8753_i2c_probe, |
1680 | .remove = wm8753_i2c_remove, | 1781 | .remove = wm8753_i2c_remove, |
1681 | .id_table = wm8753_i2c_id, | 1782 | .id_table = wm8753_i2c_id, |
1682 | }; | 1783 | }; |
1683 | |||
1684 | static int wm8753_add_i2c_device(struct platform_device *pdev, | ||
1685 | const struct wm8753_setup_data *setup) | ||
1686 | { | ||
1687 | struct i2c_board_info info; | ||
1688 | struct i2c_adapter *adapter; | ||
1689 | struct i2c_client *client; | ||
1690 | int ret; | ||
1691 | |||
1692 | ret = i2c_add_driver(&wm8753_i2c_driver); | ||
1693 | if (ret != 0) { | ||
1694 | dev_err(&pdev->dev, "can't add i2c driver\n"); | ||
1695 | return ret; | ||
1696 | } | ||
1697 | |||
1698 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
1699 | info.addr = setup->i2c_address; | ||
1700 | strlcpy(info.type, "wm8753", I2C_NAME_SIZE); | ||
1701 | |||
1702 | adapter = i2c_get_adapter(setup->i2c_bus); | ||
1703 | if (!adapter) { | ||
1704 | dev_err(&pdev->dev, "can't get i2c adapter %d\n", | ||
1705 | setup->i2c_bus); | ||
1706 | goto err_driver; | ||
1707 | } | ||
1708 | |||
1709 | client = i2c_new_device(adapter, &info); | ||
1710 | i2c_put_adapter(adapter); | ||
1711 | if (!client) { | ||
1712 | dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", | ||
1713 | (unsigned int)info.addr); | ||
1714 | goto err_driver; | ||
1715 | } | ||
1716 | |||
1717 | return 0; | ||
1718 | |||
1719 | err_driver: | ||
1720 | i2c_del_driver(&wm8753_i2c_driver); | ||
1721 | return -ENODEV; | ||
1722 | } | ||
1723 | #endif | 1784 | #endif |
1724 | 1785 | ||
1725 | #if defined(CONFIG_SPI_MASTER) | 1786 | #if defined(CONFIG_SPI_MASTER) |
1726 | static int __devinit wm8753_spi_probe(struct spi_device *spi) | ||
1727 | { | ||
1728 | struct snd_soc_device *socdev = wm8753_socdev; | ||
1729 | struct snd_soc_codec *codec = socdev->codec; | ||
1730 | int ret; | ||
1731 | |||
1732 | codec->control_data = spi; | ||
1733 | |||
1734 | ret = wm8753_init(socdev); | ||
1735 | if (ret < 0) | ||
1736 | dev_err(&spi->dev, "failed to initialise WM8753\n"); | ||
1737 | |||
1738 | return ret; | ||
1739 | } | ||
1740 | |||
1741 | static int __devexit wm8753_spi_remove(struct spi_device *spi) | ||
1742 | { | ||
1743 | return 0; | ||
1744 | } | ||
1745 | |||
1746 | static struct spi_driver wm8753_spi_driver = { | ||
1747 | .driver = { | ||
1748 | .name = "wm8753", | ||
1749 | .bus = &spi_bus_type, | ||
1750 | .owner = THIS_MODULE, | ||
1751 | }, | ||
1752 | .probe = wm8753_spi_probe, | ||
1753 | .remove = __devexit_p(wm8753_spi_remove), | ||
1754 | }; | ||
1755 | |||
1756 | static int wm8753_spi_write(struct spi_device *spi, const char *data, int len) | 1787 | static int wm8753_spi_write(struct spi_device *spi, const char *data, int len) |
1757 | { | 1788 | { |
1758 | struct spi_transfer t; | 1789 | struct spi_transfer t; |
@@ -1776,120 +1807,69 @@ static int wm8753_spi_write(struct spi_device *spi, const char *data, int len) | |||
1776 | 1807 | ||
1777 | return len; | 1808 | return len; |
1778 | } | 1809 | } |
1779 | #endif | ||
1780 | 1810 | ||
1781 | 1811 | static int __devinit wm8753_spi_probe(struct spi_device *spi) | |
1782 | static int wm8753_probe(struct platform_device *pdev) | ||
1783 | { | 1812 | { |
1784 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
1785 | struct wm8753_setup_data *setup; | ||
1786 | struct snd_soc_codec *codec; | 1813 | struct snd_soc_codec *codec; |
1787 | struct wm8753_priv *wm8753; | 1814 | struct wm8753_priv *wm8753; |
1788 | int ret = 0; | ||
1789 | |||
1790 | pr_info("WM8753 Audio Codec %s", WM8753_VERSION); | ||
1791 | |||
1792 | setup = socdev->codec_data; | ||
1793 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | ||
1794 | if (codec == NULL) | ||
1795 | return -ENOMEM; | ||
1796 | 1815 | ||
1797 | wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL); | 1816 | wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL); |
1798 | if (wm8753 == NULL) { | 1817 | if (wm8753 == NULL) |
1799 | kfree(codec); | ||
1800 | return -ENOMEM; | 1818 | return -ENOMEM; |
1801 | } | ||
1802 | 1819 | ||
1803 | codec->private_data = wm8753; | 1820 | codec = &wm8753->codec; |
1804 | socdev->codec = codec; | 1821 | codec->control_data = spi; |
1805 | mutex_init(&codec->mutex); | 1822 | codec->hw_write = (hw_write_t)wm8753_spi_write; |
1806 | INIT_LIST_HEAD(&codec->dapm_widgets); | 1823 | codec->dev = &spi->dev; |
1807 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
1808 | wm8753_socdev = socdev; | ||
1809 | INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work); | ||
1810 | 1824 | ||
1811 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1825 | spi->dev.driver_data = wm8753; |
1812 | if (setup->i2c_address) { | ||
1813 | codec->hw_write = (hw_write_t)i2c_master_send; | ||
1814 | ret = wm8753_add_i2c_device(pdev, setup); | ||
1815 | } | ||
1816 | #endif | ||
1817 | #if defined(CONFIG_SPI_MASTER) | ||
1818 | if (setup->spi) { | ||
1819 | codec->hw_write = (hw_write_t)wm8753_spi_write; | ||
1820 | ret = spi_register_driver(&wm8753_spi_driver); | ||
1821 | if (ret != 0) | ||
1822 | printk(KERN_ERR "can't add spi driver"); | ||
1823 | } | ||
1824 | #endif | ||
1825 | 1826 | ||
1826 | if (ret != 0) { | 1827 | return wm8753_register(wm8753); |
1827 | kfree(codec->private_data); | ||
1828 | kfree(codec); | ||
1829 | } | ||
1830 | return ret; | ||
1831 | } | 1828 | } |
1832 | 1829 | ||
1833 | /* | 1830 | static int __devexit wm8753_spi_remove(struct spi_device *spi) |
1834 | * This function forces any delayed work to be queued and run. | ||
1835 | */ | ||
1836 | static int run_delayed_work(struct delayed_work *dwork) | ||
1837 | { | 1831 | { |
1838 | int ret; | 1832 | struct wm8753_priv *wm8753 = spi->dev.driver_data; |
1839 | 1833 | wm8753_unregister(wm8753); | |
1840 | /* cancel any work waiting to be queued. */ | 1834 | return 0; |
1841 | ret = cancel_delayed_work(dwork); | ||
1842 | |||
1843 | /* if there was any work waiting then we run it now and | ||
1844 | * wait for it's completion */ | ||
1845 | if (ret) { | ||
1846 | schedule_delayed_work(dwork, 0); | ||
1847 | flush_scheduled_work(); | ||
1848 | } | ||
1849 | return ret; | ||
1850 | } | 1835 | } |
1851 | 1836 | ||
1852 | /* power down chip */ | 1837 | static struct spi_driver wm8753_spi_driver = { |
1853 | static int wm8753_remove(struct platform_device *pdev) | 1838 | .driver = { |
1854 | { | 1839 | .name = "wm8753", |
1855 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1840 | .bus = &spi_bus_type, |
1856 | struct snd_soc_codec *codec = socdev->codec; | 1841 | .owner = THIS_MODULE, |
1842 | }, | ||
1843 | .probe = wm8753_spi_probe, | ||
1844 | .remove = __devexit_p(wm8753_spi_remove), | ||
1845 | }; | ||
1846 | #endif | ||
1857 | 1847 | ||
1858 | if (codec->control_data) | 1848 | static int __init wm8753_modinit(void) |
1859 | wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF); | 1849 | { |
1860 | run_delayed_work(&codec->delayed_work); | 1850 | int ret; |
1861 | snd_soc_free_pcms(socdev); | ||
1862 | snd_soc_dapm_free(socdev); | ||
1863 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 1851 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1864 | i2c_unregister_device(codec->control_data); | 1852 | ret = i2c_add_driver(&wm8753_i2c_driver); |
1865 | i2c_del_driver(&wm8753_i2c_driver); | 1853 | if (ret != 0) |
1854 | pr_err("Failed to register WM8753 I2C driver: %d\n", ret); | ||
1866 | #endif | 1855 | #endif |
1867 | #if defined(CONFIG_SPI_MASTER) | 1856 | #if defined(CONFIG_SPI_MASTER) |
1868 | spi_unregister_driver(&wm8753_spi_driver); | 1857 | ret = spi_register_driver(&wm8753_spi_driver); |
1858 | if (ret != 0) | ||
1859 | pr_err("Failed to register WM8753 SPI driver: %d\n", ret); | ||
1869 | #endif | 1860 | #endif |
1870 | kfree(codec->private_data); | ||
1871 | kfree(codec); | ||
1872 | |||
1873 | return 0; | 1861 | return 0; |
1874 | } | 1862 | } |
1875 | |||
1876 | struct snd_soc_codec_device soc_codec_dev_wm8753 = { | ||
1877 | .probe = wm8753_probe, | ||
1878 | .remove = wm8753_remove, | ||
1879 | .suspend = wm8753_suspend, | ||
1880 | .resume = wm8753_resume, | ||
1881 | }; | ||
1882 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753); | ||
1883 | |||
1884 | static int __init wm8753_modinit(void) | ||
1885 | { | ||
1886 | return snd_soc_register_dais(wm8753_dai, ARRAY_SIZE(wm8753_dai)); | ||
1887 | } | ||
1888 | module_init(wm8753_modinit); | 1863 | module_init(wm8753_modinit); |
1889 | 1864 | ||
1890 | static void __exit wm8753_exit(void) | 1865 | static void __exit wm8753_exit(void) |
1891 | { | 1866 | { |
1892 | snd_soc_unregister_dais(wm8753_dai, ARRAY_SIZE(wm8753_dai)); | 1867 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
1868 | i2c_del_driver(&wm8753_i2c_driver); | ||
1869 | #endif | ||
1870 | #if defined(CONFIG_SPI_MASTER) | ||
1871 | spi_unregister_driver(&wm8753_spi_driver); | ||
1872 | #endif | ||
1893 | } | 1873 | } |
1894 | module_exit(wm8753_exit); | 1874 | module_exit(wm8753_exit); |
1895 | 1875 | ||
diff --git a/sound/soc/codecs/wm8753.h b/sound/soc/codecs/wm8753.h index f55704ce931b..57b2ba244040 100644 --- a/sound/soc/codecs/wm8753.h +++ b/sound/soc/codecs/wm8753.h | |||
@@ -77,12 +77,6 @@ | |||
77 | #define WM8753_BIASCTL 0x3d | 77 | #define WM8753_BIASCTL 0x3d |
78 | #define WM8753_ADCTL2 0x3f | 78 | #define WM8753_ADCTL2 0x3f |
79 | 79 | ||
80 | struct wm8753_setup_data { | ||
81 | int spi; | ||
82 | int i2c_bus; | ||
83 | unsigned short i2c_address; | ||
84 | }; | ||
85 | |||
86 | #define WM8753_PLL1 0 | 80 | #define WM8753_PLL1 0 |
87 | #define WM8753_PLL2 1 | 81 | #define WM8753_PLL2 1 |
88 | 82 | ||
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c index 6767de10ded0..46c5ea1ff921 100644 --- a/sound/soc/codecs/wm8900.c +++ b/sound/soc/codecs/wm8900.c | |||
@@ -517,22 +517,6 @@ SOC_SINGLE("LINEOUT2 LP -12dB", WM8900_REG_LOUTMIXCTL1, | |||
517 | 517 | ||
518 | }; | 518 | }; |
519 | 519 | ||
520 | /* add non dapm controls */ | ||
521 | static int wm8900_add_controls(struct snd_soc_codec *codec) | ||
522 | { | ||
523 | int err, i; | ||
524 | |||
525 | for (i = 0; i < ARRAY_SIZE(wm8900_snd_controls); i++) { | ||
526 | err = snd_ctl_add(codec->card, | ||
527 | snd_soc_cnew(&wm8900_snd_controls[i], | ||
528 | codec, NULL)); | ||
529 | if (err < 0) | ||
530 | return err; | ||
531 | } | ||
532 | |||
533 | return 0; | ||
534 | } | ||
535 | |||
536 | static const struct snd_kcontrol_new wm8900_dapm_loutput2_control = | 520 | static const struct snd_kcontrol_new wm8900_dapm_loutput2_control = |
537 | SOC_DAPM_SINGLE("LINEOUT2L Switch", WM8900_REG_POWER3, 6, 1, 0); | 521 | SOC_DAPM_SINGLE("LINEOUT2L Switch", WM8900_REG_POWER3, 6, 1, 0); |
538 | 522 | ||
@@ -736,7 +720,7 @@ static int wm8900_hw_params(struct snd_pcm_substream *substream, | |||
736 | { | 720 | { |
737 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 721 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
738 | struct snd_soc_device *socdev = rtd->socdev; | 722 | struct snd_soc_device *socdev = rtd->socdev; |
739 | struct snd_soc_codec *codec = socdev->codec; | 723 | struct snd_soc_codec *codec = socdev->card->codec; |
740 | u16 reg; | 724 | u16 reg; |
741 | 725 | ||
742 | reg = wm8900_read(codec, WM8900_REG_AUDIO1) & ~0x60; | 726 | reg = wm8900_read(codec, WM8900_REG_AUDIO1) & ~0x60; |
@@ -1104,6 +1088,14 @@ static int wm8900_digital_mute(struct snd_soc_dai *codec_dai, int mute) | |||
1104 | (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \ | 1088 | (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \ |
1105 | SNDRV_PCM_FORMAT_S24_LE) | 1089 | SNDRV_PCM_FORMAT_S24_LE) |
1106 | 1090 | ||
1091 | static struct snd_soc_dai_ops wm8900_dai_ops = { | ||
1092 | .hw_params = wm8900_hw_params, | ||
1093 | .set_clkdiv = wm8900_set_dai_clkdiv, | ||
1094 | .set_pll = wm8900_set_dai_pll, | ||
1095 | .set_fmt = wm8900_set_dai_fmt, | ||
1096 | .digital_mute = wm8900_digital_mute, | ||
1097 | }; | ||
1098 | |||
1107 | struct snd_soc_dai wm8900_dai = { | 1099 | struct snd_soc_dai wm8900_dai = { |
1108 | .name = "WM8900 HiFi", | 1100 | .name = "WM8900 HiFi", |
1109 | .playback = { | 1101 | .playback = { |
@@ -1120,13 +1112,7 @@ struct snd_soc_dai wm8900_dai = { | |||
1120 | .rates = WM8900_RATES, | 1112 | .rates = WM8900_RATES, |
1121 | .formats = WM8900_PCM_FORMATS, | 1113 | .formats = WM8900_PCM_FORMATS, |
1122 | }, | 1114 | }, |
1123 | .ops = { | 1115 | .ops = &wm8900_dai_ops, |
1124 | .hw_params = wm8900_hw_params, | ||
1125 | .set_clkdiv = wm8900_set_dai_clkdiv, | ||
1126 | .set_pll = wm8900_set_dai_pll, | ||
1127 | .set_fmt = wm8900_set_dai_fmt, | ||
1128 | .digital_mute = wm8900_digital_mute, | ||
1129 | }, | ||
1130 | }; | 1116 | }; |
1131 | EXPORT_SYMBOL_GPL(wm8900_dai); | 1117 | EXPORT_SYMBOL_GPL(wm8900_dai); |
1132 | 1118 | ||
@@ -1226,7 +1212,7 @@ static int wm8900_set_bias_level(struct snd_soc_codec *codec, | |||
1226 | static int wm8900_suspend(struct platform_device *pdev, pm_message_t state) | 1212 | static int wm8900_suspend(struct platform_device *pdev, pm_message_t state) |
1227 | { | 1213 | { |
1228 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1214 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1229 | struct snd_soc_codec *codec = socdev->codec; | 1215 | struct snd_soc_codec *codec = socdev->card->codec; |
1230 | struct wm8900_priv *wm8900 = codec->private_data; | 1216 | struct wm8900_priv *wm8900 = codec->private_data; |
1231 | int fll_out = wm8900->fll_out; | 1217 | int fll_out = wm8900->fll_out; |
1232 | int fll_in = wm8900->fll_in; | 1218 | int fll_in = wm8900->fll_in; |
@@ -1250,7 +1236,7 @@ static int wm8900_suspend(struct platform_device *pdev, pm_message_t state) | |||
1250 | static int wm8900_resume(struct platform_device *pdev) | 1236 | static int wm8900_resume(struct platform_device *pdev) |
1251 | { | 1237 | { |
1252 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1238 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1253 | struct snd_soc_codec *codec = socdev->codec; | 1239 | struct snd_soc_codec *codec = socdev->card->codec; |
1254 | struct wm8900_priv *wm8900 = codec->private_data; | 1240 | struct wm8900_priv *wm8900 = codec->private_data; |
1255 | u16 *cache; | 1241 | u16 *cache; |
1256 | int i, ret; | 1242 | int i, ret; |
@@ -1288,8 +1274,8 @@ static int wm8900_resume(struct platform_device *pdev) | |||
1288 | 1274 | ||
1289 | static struct snd_soc_codec *wm8900_codec; | 1275 | static struct snd_soc_codec *wm8900_codec; |
1290 | 1276 | ||
1291 | static int wm8900_i2c_probe(struct i2c_client *i2c, | 1277 | static __devinit int wm8900_i2c_probe(struct i2c_client *i2c, |
1292 | const struct i2c_device_id *id) | 1278 | const struct i2c_device_id *id) |
1293 | { | 1279 | { |
1294 | struct wm8900_priv *wm8900; | 1280 | struct wm8900_priv *wm8900; |
1295 | struct snd_soc_codec *codec; | 1281 | struct snd_soc_codec *codec; |
@@ -1388,7 +1374,7 @@ err: | |||
1388 | return ret; | 1374 | return ret; |
1389 | } | 1375 | } |
1390 | 1376 | ||
1391 | static int wm8900_i2c_remove(struct i2c_client *client) | 1377 | static __devexit int wm8900_i2c_remove(struct i2c_client *client) |
1392 | { | 1378 | { |
1393 | snd_soc_unregister_dai(&wm8900_dai); | 1379 | snd_soc_unregister_dai(&wm8900_dai); |
1394 | snd_soc_unregister_codec(wm8900_codec); | 1380 | snd_soc_unregister_codec(wm8900_codec); |
@@ -1414,7 +1400,7 @@ static struct i2c_driver wm8900_i2c_driver = { | |||
1414 | .owner = THIS_MODULE, | 1400 | .owner = THIS_MODULE, |
1415 | }, | 1401 | }, |
1416 | .probe = wm8900_i2c_probe, | 1402 | .probe = wm8900_i2c_probe, |
1417 | .remove = wm8900_i2c_remove, | 1403 | .remove = __devexit_p(wm8900_i2c_remove), |
1418 | .id_table = wm8900_i2c_id, | 1404 | .id_table = wm8900_i2c_id, |
1419 | }; | 1405 | }; |
1420 | 1406 | ||
@@ -1430,7 +1416,7 @@ static int wm8900_probe(struct platform_device *pdev) | |||
1430 | } | 1416 | } |
1431 | 1417 | ||
1432 | codec = wm8900_codec; | 1418 | codec = wm8900_codec; |
1433 | socdev->codec = codec; | 1419 | socdev->card->codec = codec; |
1434 | 1420 | ||
1435 | /* Register pcms */ | 1421 | /* Register pcms */ |
1436 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | 1422 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
@@ -1439,7 +1425,8 @@ static int wm8900_probe(struct platform_device *pdev) | |||
1439 | goto pcm_err; | 1425 | goto pcm_err; |
1440 | } | 1426 | } |
1441 | 1427 | ||
1442 | wm8900_add_controls(codec); | 1428 | snd_soc_add_controls(codec, wm8900_snd_controls, |
1429 | ARRAY_SIZE(wm8900_snd_controls)); | ||
1443 | wm8900_add_widgets(codec); | 1430 | wm8900_add_widgets(codec); |
1444 | 1431 | ||
1445 | ret = snd_soc_init_card(socdev); | 1432 | ret = snd_soc_init_card(socdev); |
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c index bde74546db4a..8cf571f1a803 100644 --- a/sound/soc/codecs/wm8903.c +++ b/sound/soc/codecs/wm8903.c | |||
@@ -744,21 +744,6 @@ SOC_DOUBLE_R_TLV("Speaker Volume", | |||
744 | 0, 63, 0, out_tlv), | 744 | 0, 63, 0, out_tlv), |
745 | }; | 745 | }; |
746 | 746 | ||
747 | static int wm8903_add_controls(struct snd_soc_codec *codec) | ||
748 | { | ||
749 | int err, i; | ||
750 | |||
751 | for (i = 0; i < ARRAY_SIZE(wm8903_snd_controls); i++) { | ||
752 | err = snd_ctl_add(codec->card, | ||
753 | snd_soc_cnew(&wm8903_snd_controls[i], | ||
754 | codec, NULL)); | ||
755 | if (err < 0) | ||
756 | return err; | ||
757 | } | ||
758 | |||
759 | return 0; | ||
760 | } | ||
761 | |||
762 | static const struct snd_kcontrol_new linput_mode_mux = | 747 | static const struct snd_kcontrol_new linput_mode_mux = |
763 | SOC_DAPM_ENUM("Left Input Mode Mux", linput_mode_enum); | 748 | SOC_DAPM_ENUM("Left Input Mode Mux", linput_mode_enum); |
764 | 749 | ||
@@ -1276,7 +1261,7 @@ static int wm8903_startup(struct snd_pcm_substream *substream, | |||
1276 | { | 1261 | { |
1277 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1262 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
1278 | struct snd_soc_device *socdev = rtd->socdev; | 1263 | struct snd_soc_device *socdev = rtd->socdev; |
1279 | struct snd_soc_codec *codec = socdev->codec; | 1264 | struct snd_soc_codec *codec = socdev->card->codec; |
1280 | struct wm8903_priv *wm8903 = codec->private_data; | 1265 | struct wm8903_priv *wm8903 = codec->private_data; |
1281 | struct i2c_client *i2c = codec->control_data; | 1266 | struct i2c_client *i2c = codec->control_data; |
1282 | struct snd_pcm_runtime *master_runtime; | 1267 | struct snd_pcm_runtime *master_runtime; |
@@ -1318,7 +1303,7 @@ static void wm8903_shutdown(struct snd_pcm_substream *substream, | |||
1318 | { | 1303 | { |
1319 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1304 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
1320 | struct snd_soc_device *socdev = rtd->socdev; | 1305 | struct snd_soc_device *socdev = rtd->socdev; |
1321 | struct snd_soc_codec *codec = socdev->codec; | 1306 | struct snd_soc_codec *codec = socdev->card->codec; |
1322 | struct wm8903_priv *wm8903 = codec->private_data; | 1307 | struct wm8903_priv *wm8903 = codec->private_data; |
1323 | 1308 | ||
1324 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | 1309 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
@@ -1338,7 +1323,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream, | |||
1338 | { | 1323 | { |
1339 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1324 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
1340 | struct snd_soc_device *socdev = rtd->socdev; | 1325 | struct snd_soc_device *socdev = rtd->socdev; |
1341 | struct snd_soc_codec *codec = socdev->codec; | 1326 | struct snd_soc_codec *codec = socdev->card->codec; |
1342 | struct wm8903_priv *wm8903 = codec->private_data; | 1327 | struct wm8903_priv *wm8903 = codec->private_data; |
1343 | struct i2c_client *i2c = codec->control_data; | 1328 | struct i2c_client *i2c = codec->control_data; |
1344 | int fs = params_rate(params); | 1329 | int fs = params_rate(params); |
@@ -1512,6 +1497,15 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream, | |||
1512 | SNDRV_PCM_FMTBIT_S20_3LE |\ | 1497 | SNDRV_PCM_FMTBIT_S20_3LE |\ |
1513 | SNDRV_PCM_FMTBIT_S24_LE) | 1498 | SNDRV_PCM_FMTBIT_S24_LE) |
1514 | 1499 | ||
1500 | static struct snd_soc_dai_ops wm8903_dai_ops = { | ||
1501 | .startup = wm8903_startup, | ||
1502 | .shutdown = wm8903_shutdown, | ||
1503 | .hw_params = wm8903_hw_params, | ||
1504 | .digital_mute = wm8903_digital_mute, | ||
1505 | .set_fmt = wm8903_set_dai_fmt, | ||
1506 | .set_sysclk = wm8903_set_dai_sysclk, | ||
1507 | }; | ||
1508 | |||
1515 | struct snd_soc_dai wm8903_dai = { | 1509 | struct snd_soc_dai wm8903_dai = { |
1516 | .name = "WM8903", | 1510 | .name = "WM8903", |
1517 | .playback = { | 1511 | .playback = { |
@@ -1528,21 +1522,14 @@ struct snd_soc_dai wm8903_dai = { | |||
1528 | .rates = WM8903_CAPTURE_RATES, | 1522 | .rates = WM8903_CAPTURE_RATES, |
1529 | .formats = WM8903_FORMATS, | 1523 | .formats = WM8903_FORMATS, |
1530 | }, | 1524 | }, |
1531 | .ops = { | 1525 | .ops = &wm8903_dai_ops, |
1532 | .startup = wm8903_startup, | ||
1533 | .shutdown = wm8903_shutdown, | ||
1534 | .hw_params = wm8903_hw_params, | ||
1535 | .digital_mute = wm8903_digital_mute, | ||
1536 | .set_fmt = wm8903_set_dai_fmt, | ||
1537 | .set_sysclk = wm8903_set_dai_sysclk | ||
1538 | } | ||
1539 | }; | 1526 | }; |
1540 | EXPORT_SYMBOL_GPL(wm8903_dai); | 1527 | EXPORT_SYMBOL_GPL(wm8903_dai); |
1541 | 1528 | ||
1542 | static int wm8903_suspend(struct platform_device *pdev, pm_message_t state) | 1529 | static int wm8903_suspend(struct platform_device *pdev, pm_message_t state) |
1543 | { | 1530 | { |
1544 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1531 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1545 | struct snd_soc_codec *codec = socdev->codec; | 1532 | struct snd_soc_codec *codec = socdev->card->codec; |
1546 | 1533 | ||
1547 | wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF); | 1534 | wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF); |
1548 | 1535 | ||
@@ -1552,7 +1539,7 @@ static int wm8903_suspend(struct platform_device *pdev, pm_message_t state) | |||
1552 | static int wm8903_resume(struct platform_device *pdev) | 1539 | static int wm8903_resume(struct platform_device *pdev) |
1553 | { | 1540 | { |
1554 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1541 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1555 | struct snd_soc_codec *codec = socdev->codec; | 1542 | struct snd_soc_codec *codec = socdev->card->codec; |
1556 | struct i2c_client *i2c = codec->control_data; | 1543 | struct i2c_client *i2c = codec->control_data; |
1557 | int i; | 1544 | int i; |
1558 | u16 *reg_cache = codec->reg_cache; | 1545 | u16 *reg_cache = codec->reg_cache; |
@@ -1577,8 +1564,8 @@ static int wm8903_resume(struct platform_device *pdev) | |||
1577 | 1564 | ||
1578 | static struct snd_soc_codec *wm8903_codec; | 1565 | static struct snd_soc_codec *wm8903_codec; |
1579 | 1566 | ||
1580 | static int wm8903_i2c_probe(struct i2c_client *i2c, | 1567 | static __devinit int wm8903_i2c_probe(struct i2c_client *i2c, |
1581 | const struct i2c_device_id *id) | 1568 | const struct i2c_device_id *id) |
1582 | { | 1569 | { |
1583 | struct wm8903_priv *wm8903; | 1570 | struct wm8903_priv *wm8903; |
1584 | struct snd_soc_codec *codec; | 1571 | struct snd_soc_codec *codec; |
@@ -1684,7 +1671,7 @@ err: | |||
1684 | return ret; | 1671 | return ret; |
1685 | } | 1672 | } |
1686 | 1673 | ||
1687 | static int wm8903_i2c_remove(struct i2c_client *client) | 1674 | static __devexit int wm8903_i2c_remove(struct i2c_client *client) |
1688 | { | 1675 | { |
1689 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | 1676 | struct snd_soc_codec *codec = i2c_get_clientdata(client); |
1690 | 1677 | ||
@@ -1714,7 +1701,7 @@ static struct i2c_driver wm8903_i2c_driver = { | |||
1714 | .owner = THIS_MODULE, | 1701 | .owner = THIS_MODULE, |
1715 | }, | 1702 | }, |
1716 | .probe = wm8903_i2c_probe, | 1703 | .probe = wm8903_i2c_probe, |
1717 | .remove = wm8903_i2c_remove, | 1704 | .remove = __devexit_p(wm8903_i2c_remove), |
1718 | .id_table = wm8903_i2c_id, | 1705 | .id_table = wm8903_i2c_id, |
1719 | }; | 1706 | }; |
1720 | 1707 | ||
@@ -1728,7 +1715,7 @@ static int wm8903_probe(struct platform_device *pdev) | |||
1728 | goto err; | 1715 | goto err; |
1729 | } | 1716 | } |
1730 | 1717 | ||
1731 | socdev->codec = wm8903_codec; | 1718 | socdev->card->codec = wm8903_codec; |
1732 | 1719 | ||
1733 | /* register pcms */ | 1720 | /* register pcms */ |
1734 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | 1721 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
@@ -1737,8 +1724,9 @@ static int wm8903_probe(struct platform_device *pdev) | |||
1737 | goto err; | 1724 | goto err; |
1738 | } | 1725 | } |
1739 | 1726 | ||
1740 | wm8903_add_controls(socdev->codec); | 1727 | snd_soc_add_controls(socdev->card->codec, wm8903_snd_controls, |
1741 | wm8903_add_widgets(socdev->codec); | 1728 | ARRAY_SIZE(wm8903_snd_controls)); |
1729 | wm8903_add_widgets(socdev->card->codec); | ||
1742 | 1730 | ||
1743 | ret = snd_soc_init_card(socdev); | 1731 | ret = snd_soc_init_card(socdev); |
1744 | if (ret < 0) { | 1732 | if (ret < 0) { |
@@ -1759,7 +1747,7 @@ err: | |||
1759 | static int wm8903_remove(struct platform_device *pdev) | 1747 | static int wm8903_remove(struct platform_device *pdev) |
1760 | { | 1748 | { |
1761 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1749 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1762 | struct snd_soc_codec *codec = socdev->codec; | 1750 | struct snd_soc_codec *codec = socdev->card->codec; |
1763 | 1751 | ||
1764 | if (codec->control_data) | 1752 | if (codec->control_data) |
1765 | wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF); | 1753 | wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF); |
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c index 88ead7f8dd98..032dca22dbd3 100644 --- a/sound/soc/codecs/wm8971.c +++ b/sound/soc/codecs/wm8971.c | |||
@@ -195,21 +195,6 @@ static const struct snd_kcontrol_new wm8971_snd_controls[] = { | |||
195 | SOC_DOUBLE_R("Mic Boost", WM8971_LADCIN, WM8971_RADCIN, 4, 3, 0), | 195 | SOC_DOUBLE_R("Mic Boost", WM8971_LADCIN, WM8971_RADCIN, 4, 3, 0), |
196 | }; | 196 | }; |
197 | 197 | ||
198 | /* add non-DAPM controls */ | ||
199 | static int wm8971_add_controls(struct snd_soc_codec *codec) | ||
200 | { | ||
201 | int err, i; | ||
202 | |||
203 | for (i = 0; i < ARRAY_SIZE(wm8971_snd_controls); i++) { | ||
204 | err = snd_ctl_add(codec->card, | ||
205 | snd_soc_cnew(&wm8971_snd_controls[i], | ||
206 | codec, NULL)); | ||
207 | if (err < 0) | ||
208 | return err; | ||
209 | } | ||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | /* | 198 | /* |
214 | * DAPM Controls | 199 | * DAPM Controls |
215 | */ | 200 | */ |
@@ -546,7 +531,7 @@ static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream, | |||
546 | { | 531 | { |
547 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 532 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
548 | struct snd_soc_device *socdev = rtd->socdev; | 533 | struct snd_soc_device *socdev = rtd->socdev; |
549 | struct snd_soc_codec *codec = socdev->codec; | 534 | struct snd_soc_codec *codec = socdev->card->codec; |
550 | struct wm8971_priv *wm8971 = codec->private_data; | 535 | struct wm8971_priv *wm8971 = codec->private_data; |
551 | u16 iface = wm8971_read_reg_cache(codec, WM8971_IFACE) & 0x1f3; | 536 | u16 iface = wm8971_read_reg_cache(codec, WM8971_IFACE) & 0x1f3; |
552 | u16 srate = wm8971_read_reg_cache(codec, WM8971_SRATE) & 0x1c0; | 537 | u16 srate = wm8971_read_reg_cache(codec, WM8971_SRATE) & 0x1c0; |
@@ -619,6 +604,13 @@ static int wm8971_set_bias_level(struct snd_soc_codec *codec, | |||
619 | #define WM8971_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ | 604 | #define WM8971_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
620 | SNDRV_PCM_FMTBIT_S24_LE) | 605 | SNDRV_PCM_FMTBIT_S24_LE) |
621 | 606 | ||
607 | static struct snd_soc_dai_ops wm8971_dai_ops = { | ||
608 | .hw_params = wm8971_pcm_hw_params, | ||
609 | .digital_mute = wm8971_mute, | ||
610 | .set_fmt = wm8971_set_dai_fmt, | ||
611 | .set_sysclk = wm8971_set_dai_sysclk, | ||
612 | }; | ||
613 | |||
622 | struct snd_soc_dai wm8971_dai = { | 614 | struct snd_soc_dai wm8971_dai = { |
623 | .name = "WM8971", | 615 | .name = "WM8971", |
624 | .playback = { | 616 | .playback = { |
@@ -633,12 +625,7 @@ struct snd_soc_dai wm8971_dai = { | |||
633 | .channels_max = 2, | 625 | .channels_max = 2, |
634 | .rates = WM8971_RATES, | 626 | .rates = WM8971_RATES, |
635 | .formats = WM8971_FORMATS,}, | 627 | .formats = WM8971_FORMATS,}, |
636 | .ops = { | 628 | .ops = &wm8971_dai_ops, |
637 | .hw_params = wm8971_pcm_hw_params, | ||
638 | .digital_mute = wm8971_mute, | ||
639 | .set_fmt = wm8971_set_dai_fmt, | ||
640 | .set_sysclk = wm8971_set_dai_sysclk, | ||
641 | }, | ||
642 | }; | 629 | }; |
643 | EXPORT_SYMBOL_GPL(wm8971_dai); | 630 | EXPORT_SYMBOL_GPL(wm8971_dai); |
644 | 631 | ||
@@ -652,7 +639,7 @@ static void wm8971_work(struct work_struct *work) | |||
652 | static int wm8971_suspend(struct platform_device *pdev, pm_message_t state) | 639 | static int wm8971_suspend(struct platform_device *pdev, pm_message_t state) |
653 | { | 640 | { |
654 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 641 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
655 | struct snd_soc_codec *codec = socdev->codec; | 642 | struct snd_soc_codec *codec = socdev->card->codec; |
656 | 643 | ||
657 | wm8971_set_bias_level(codec, SND_SOC_BIAS_OFF); | 644 | wm8971_set_bias_level(codec, SND_SOC_BIAS_OFF); |
658 | return 0; | 645 | return 0; |
@@ -661,7 +648,7 @@ static int wm8971_suspend(struct platform_device *pdev, pm_message_t state) | |||
661 | static int wm8971_resume(struct platform_device *pdev) | 648 | static int wm8971_resume(struct platform_device *pdev) |
662 | { | 649 | { |
663 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 650 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
664 | struct snd_soc_codec *codec = socdev->codec; | 651 | struct snd_soc_codec *codec = socdev->card->codec; |
665 | int i; | 652 | int i; |
666 | u8 data[2]; | 653 | u8 data[2]; |
667 | u16 *cache = codec->reg_cache; | 654 | u16 *cache = codec->reg_cache; |
@@ -692,7 +679,7 @@ static int wm8971_resume(struct platform_device *pdev) | |||
692 | 679 | ||
693 | static int wm8971_init(struct snd_soc_device *socdev) | 680 | static int wm8971_init(struct snd_soc_device *socdev) |
694 | { | 681 | { |
695 | struct snd_soc_codec *codec = socdev->codec; | 682 | struct snd_soc_codec *codec = socdev->card->codec; |
696 | int reg, ret = 0; | 683 | int reg, ret = 0; |
697 | 684 | ||
698 | codec->name = "WM8971"; | 685 | codec->name = "WM8971"; |
@@ -745,7 +732,8 @@ static int wm8971_init(struct snd_soc_device *socdev) | |||
745 | reg = wm8971_read_reg_cache(codec, WM8971_RINVOL); | 732 | reg = wm8971_read_reg_cache(codec, WM8971_RINVOL); |
746 | wm8971_write(codec, WM8971_RINVOL, reg | 0x0100); | 733 | wm8971_write(codec, WM8971_RINVOL, reg | 0x0100); |
747 | 734 | ||
748 | wm8971_add_controls(codec); | 735 | snd_soc_add_controls(codec, wm8971_snd_controls, |
736 | ARRAY_SIZE(wm8971_snd_controls)); | ||
749 | wm8971_add_widgets(codec); | 737 | wm8971_add_widgets(codec); |
750 | ret = snd_soc_init_card(socdev); | 738 | ret = snd_soc_init_card(socdev); |
751 | if (ret < 0) { | 739 | if (ret < 0) { |
@@ -772,7 +760,7 @@ static int wm8971_i2c_probe(struct i2c_client *i2c, | |||
772 | const struct i2c_device_id *id) | 760 | const struct i2c_device_id *id) |
773 | { | 761 | { |
774 | struct snd_soc_device *socdev = wm8971_socdev; | 762 | struct snd_soc_device *socdev = wm8971_socdev; |
775 | struct snd_soc_codec *codec = socdev->codec; | 763 | struct snd_soc_codec *codec = socdev->card->codec; |
776 | int ret; | 764 | int ret; |
777 | 765 | ||
778 | i2c_set_clientdata(i2c, codec); | 766 | i2c_set_clientdata(i2c, codec); |
@@ -873,7 +861,7 @@ static int wm8971_probe(struct platform_device *pdev) | |||
873 | } | 861 | } |
874 | 862 | ||
875 | codec->private_data = wm8971; | 863 | codec->private_data = wm8971; |
876 | socdev->codec = codec; | 864 | socdev->card->codec = codec; |
877 | mutex_init(&codec->mutex); | 865 | mutex_init(&codec->mutex); |
878 | INIT_LIST_HEAD(&codec->dapm_widgets); | 866 | INIT_LIST_HEAD(&codec->dapm_widgets); |
879 | INIT_LIST_HEAD(&codec->dapm_paths); | 867 | INIT_LIST_HEAD(&codec->dapm_paths); |
@@ -908,7 +896,7 @@ static int wm8971_probe(struct platform_device *pdev) | |||
908 | static int wm8971_remove(struct platform_device *pdev) | 896 | static int wm8971_remove(struct platform_device *pdev) |
909 | { | 897 | { |
910 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 898 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
911 | struct snd_soc_codec *codec = socdev->codec; | 899 | struct snd_soc_codec *codec = socdev->card->codec; |
912 | 900 | ||
913 | if (codec->control_data) | 901 | if (codec->control_data) |
914 | wm8971_set_bias_level(codec, SND_SOC_BIAS_OFF); | 902 | wm8971_set_bias_level(codec, SND_SOC_BIAS_OFF); |
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c index a5731faa150c..c518c3e5aa3f 100644 --- a/sound/soc/codecs/wm8990.c +++ b/sound/soc/codecs/wm8990.c | |||
@@ -115,7 +115,7 @@ static inline unsigned int wm8990_read_reg_cache(struct snd_soc_codec *codec, | |||
115 | unsigned int reg) | 115 | unsigned int reg) |
116 | { | 116 | { |
117 | u16 *cache = codec->reg_cache; | 117 | u16 *cache = codec->reg_cache; |
118 | BUG_ON(reg > (ARRAY_SIZE(wm8990_reg)) - 1); | 118 | BUG_ON(reg >= ARRAY_SIZE(wm8990_reg)); |
119 | return cache[reg]; | 119 | return cache[reg]; |
120 | } | 120 | } |
121 | 121 | ||
@@ -128,7 +128,7 @@ static inline void wm8990_write_reg_cache(struct snd_soc_codec *codec, | |||
128 | u16 *cache = codec->reg_cache; | 128 | u16 *cache = codec->reg_cache; |
129 | 129 | ||
130 | /* Reset register and reserved registers are uncached */ | 130 | /* Reset register and reserved registers are uncached */ |
131 | if (reg == 0 || reg > ARRAY_SIZE(wm8990_reg) - 1) | 131 | if (reg == 0 || reg >= ARRAY_SIZE(wm8990_reg)) |
132 | return; | 132 | return; |
133 | 133 | ||
134 | cache[reg] = value; | 134 | cache[reg] = value; |
@@ -418,21 +418,6 @@ SOC_SINGLE("RIN34 Mute Switch", WM8990_RIGHT_LINE_INPUT_3_4_VOLUME, | |||
418 | 418 | ||
419 | }; | 419 | }; |
420 | 420 | ||
421 | /* add non dapm controls */ | ||
422 | static int wm8990_add_controls(struct snd_soc_codec *codec) | ||
423 | { | ||
424 | int err, i; | ||
425 | |||
426 | for (i = 0; i < ARRAY_SIZE(wm8990_snd_controls); i++) { | ||
427 | err = snd_ctl_add(codec->card, | ||
428 | snd_soc_cnew(&wm8990_snd_controls[i], codec, | ||
429 | NULL)); | ||
430 | if (err < 0) | ||
431 | return err; | ||
432 | } | ||
433 | return 0; | ||
434 | } | ||
435 | |||
436 | /* | 421 | /* |
437 | * _DAPM_ Controls | 422 | * _DAPM_ Controls |
438 | */ | 423 | */ |
@@ -1178,7 +1163,7 @@ static int wm8990_hw_params(struct snd_pcm_substream *substream, | |||
1178 | { | 1163 | { |
1179 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 1164 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
1180 | struct snd_soc_device *socdev = rtd->socdev; | 1165 | struct snd_soc_device *socdev = rtd->socdev; |
1181 | struct snd_soc_codec *codec = socdev->codec; | 1166 | struct snd_soc_codec *codec = socdev->card->codec; |
1182 | u16 audio1 = wm8990_read_reg_cache(codec, WM8990_AUDIO_INTERFACE_1); | 1167 | u16 audio1 = wm8990_read_reg_cache(codec, WM8990_AUDIO_INTERFACE_1); |
1183 | 1168 | ||
1184 | audio1 &= ~WM8990_AIF_WL_MASK; | 1169 | audio1 &= ~WM8990_AIF_WL_MASK; |
@@ -1347,6 +1332,15 @@ static int wm8990_set_bias_level(struct snd_soc_codec *codec, | |||
1347 | * 1. ADC/DAC on Primary Interface | 1332 | * 1. ADC/DAC on Primary Interface |
1348 | * 2. ADC on Primary Interface/DAC on secondary | 1333 | * 2. ADC on Primary Interface/DAC on secondary |
1349 | */ | 1334 | */ |
1335 | static struct snd_soc_dai_ops wm8990_dai_ops = { | ||
1336 | .hw_params = wm8990_hw_params, | ||
1337 | .digital_mute = wm8990_mute, | ||
1338 | .set_fmt = wm8990_set_dai_fmt, | ||
1339 | .set_clkdiv = wm8990_set_dai_clkdiv, | ||
1340 | .set_pll = wm8990_set_dai_pll, | ||
1341 | .set_sysclk = wm8990_set_dai_sysclk, | ||
1342 | }; | ||
1343 | |||
1350 | struct snd_soc_dai wm8990_dai = { | 1344 | struct snd_soc_dai wm8990_dai = { |
1351 | /* ADC/DAC on primary */ | 1345 | /* ADC/DAC on primary */ |
1352 | .name = "WM8990 ADC/DAC Primary", | 1346 | .name = "WM8990 ADC/DAC Primary", |
@@ -1363,21 +1357,14 @@ struct snd_soc_dai wm8990_dai = { | |||
1363 | .channels_max = 2, | 1357 | .channels_max = 2, |
1364 | .rates = WM8990_RATES, | 1358 | .rates = WM8990_RATES, |
1365 | .formats = WM8990_FORMATS,}, | 1359 | .formats = WM8990_FORMATS,}, |
1366 | .ops = { | 1360 | .ops = &wm8990_dai_ops, |
1367 | .hw_params = wm8990_hw_params, | ||
1368 | .digital_mute = wm8990_mute, | ||
1369 | .set_fmt = wm8990_set_dai_fmt, | ||
1370 | .set_clkdiv = wm8990_set_dai_clkdiv, | ||
1371 | .set_pll = wm8990_set_dai_pll, | ||
1372 | .set_sysclk = wm8990_set_dai_sysclk, | ||
1373 | }, | ||
1374 | }; | 1361 | }; |
1375 | EXPORT_SYMBOL_GPL(wm8990_dai); | 1362 | EXPORT_SYMBOL_GPL(wm8990_dai); |
1376 | 1363 | ||
1377 | static int wm8990_suspend(struct platform_device *pdev, pm_message_t state) | 1364 | static int wm8990_suspend(struct platform_device *pdev, pm_message_t state) |
1378 | { | 1365 | { |
1379 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1366 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1380 | struct snd_soc_codec *codec = socdev->codec; | 1367 | struct snd_soc_codec *codec = socdev->card->codec; |
1381 | 1368 | ||
1382 | /* we only need to suspend if we are a valid card */ | 1369 | /* we only need to suspend if we are a valid card */ |
1383 | if (!codec->card) | 1370 | if (!codec->card) |
@@ -1390,7 +1377,7 @@ static int wm8990_suspend(struct platform_device *pdev, pm_message_t state) | |||
1390 | static int wm8990_resume(struct platform_device *pdev) | 1377 | static int wm8990_resume(struct platform_device *pdev) |
1391 | { | 1378 | { |
1392 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1379 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1393 | struct snd_soc_codec *codec = socdev->codec; | 1380 | struct snd_soc_codec *codec = socdev->card->codec; |
1394 | int i; | 1381 | int i; |
1395 | u8 data[2]; | 1382 | u8 data[2]; |
1396 | u16 *cache = codec->reg_cache; | 1383 | u16 *cache = codec->reg_cache; |
@@ -1418,7 +1405,7 @@ static int wm8990_resume(struct platform_device *pdev) | |||
1418 | */ | 1405 | */ |
1419 | static int wm8990_init(struct snd_soc_device *socdev) | 1406 | static int wm8990_init(struct snd_soc_device *socdev) |
1420 | { | 1407 | { |
1421 | struct snd_soc_codec *codec = socdev->codec; | 1408 | struct snd_soc_codec *codec = socdev->card->codec; |
1422 | u16 reg; | 1409 | u16 reg; |
1423 | int ret = 0; | 1410 | int ret = 0; |
1424 | 1411 | ||
@@ -1461,7 +1448,8 @@ static int wm8990_init(struct snd_soc_device *socdev) | |||
1461 | wm8990_write(codec, WM8990_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8)); | 1448 | wm8990_write(codec, WM8990_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8)); |
1462 | wm8990_write(codec, WM8990_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8)); | 1449 | wm8990_write(codec, WM8990_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8)); |
1463 | 1450 | ||
1464 | wm8990_add_controls(codec); | 1451 | snd_soc_add_controls(codec, wm8990_snd_controls, |
1452 | ARRAY_SIZE(wm8990_snd_controls)); | ||
1465 | wm8990_add_widgets(codec); | 1453 | wm8990_add_widgets(codec); |
1466 | ret = snd_soc_init_card(socdev); | 1454 | ret = snd_soc_init_card(socdev); |
1467 | if (ret < 0) { | 1455 | if (ret < 0) { |
@@ -1495,7 +1483,7 @@ static int wm8990_i2c_probe(struct i2c_client *i2c, | |||
1495 | const struct i2c_device_id *id) | 1483 | const struct i2c_device_id *id) |
1496 | { | 1484 | { |
1497 | struct snd_soc_device *socdev = wm8990_socdev; | 1485 | struct snd_soc_device *socdev = wm8990_socdev; |
1498 | struct snd_soc_codec *codec = socdev->codec; | 1486 | struct snd_soc_codec *codec = socdev->card->codec; |
1499 | int ret; | 1487 | int ret; |
1500 | 1488 | ||
1501 | i2c_set_clientdata(i2c, codec); | 1489 | i2c_set_clientdata(i2c, codec); |
@@ -1594,7 +1582,7 @@ static int wm8990_probe(struct platform_device *pdev) | |||
1594 | } | 1582 | } |
1595 | 1583 | ||
1596 | codec->private_data = wm8990; | 1584 | codec->private_data = wm8990; |
1597 | socdev->codec = codec; | 1585 | socdev->card->codec = codec; |
1598 | mutex_init(&codec->mutex); | 1586 | mutex_init(&codec->mutex); |
1599 | INIT_LIST_HEAD(&codec->dapm_widgets); | 1587 | INIT_LIST_HEAD(&codec->dapm_widgets); |
1600 | INIT_LIST_HEAD(&codec->dapm_paths); | 1588 | INIT_LIST_HEAD(&codec->dapm_paths); |
@@ -1620,7 +1608,7 @@ static int wm8990_probe(struct platform_device *pdev) | |||
1620 | static int wm8990_remove(struct platform_device *pdev) | 1608 | static int wm8990_remove(struct platform_device *pdev) |
1621 | { | 1609 | { |
1622 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1610 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1623 | struct snd_soc_codec *codec = socdev->codec; | 1611 | struct snd_soc_codec *codec = socdev->card->codec; |
1624 | 1612 | ||
1625 | if (codec->control_data) | 1613 | if (codec->control_data) |
1626 | wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF); | 1614 | wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF); |
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c new file mode 100644 index 000000000000..3265817c5c26 --- /dev/null +++ b/sound/soc/codecs/wm9705.c | |||
@@ -0,0 +1,415 @@ | |||
1 | /* | ||
2 | * wm9705.c -- ALSA Soc WM9705 codec support | ||
3 | * | ||
4 | * Copyright 2008 Ian Molton <spyro@f2s.com> | ||
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; Version 2 of the License only. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <linux/init.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/device.h> | ||
16 | #include <sound/core.h> | ||
17 | #include <sound/pcm.h> | ||
18 | #include <sound/ac97_codec.h> | ||
19 | #include <sound/initval.h> | ||
20 | #include <sound/soc.h> | ||
21 | #include <sound/soc-dapm.h> | ||
22 | |||
23 | #include "wm9705.h" | ||
24 | |||
25 | /* | ||
26 | * WM9705 register cache | ||
27 | */ | ||
28 | static const u16 wm9705_reg[] = { | ||
29 | 0x6150, 0x8000, 0x8000, 0x8000, /* 0x0 */ | ||
30 | 0x0000, 0x8000, 0x8008, 0x8008, /* 0x8 */ | ||
31 | 0x8808, 0x8808, 0x8808, 0x8808, /* 0x10 */ | ||
32 | 0x8808, 0x0000, 0x8000, 0x0000, /* 0x18 */ | ||
33 | 0x0000, 0x0000, 0x0000, 0x000f, /* 0x20 */ | ||
34 | 0x0605, 0x0000, 0xbb80, 0x0000, /* 0x28 */ | ||
35 | 0x0000, 0xbb80, 0x0000, 0x0000, /* 0x30 */ | ||
36 | 0x0000, 0x2000, 0x0000, 0x0000, /* 0x38 */ | ||
37 | 0x0000, 0x0000, 0x0000, 0x0000, /* 0x40 */ | ||
38 | 0x0000, 0x0000, 0x0000, 0x0000, /* 0x48 */ | ||
39 | 0x0000, 0x0000, 0x0000, 0x0000, /* 0x50 */ | ||
40 | 0x0000, 0x0000, 0x0000, 0x0000, /* 0x58 */ | ||
41 | 0x0000, 0x0000, 0x0000, 0x0000, /* 0x60 */ | ||
42 | 0x0000, 0x0000, 0x0000, 0x0000, /* 0x68 */ | ||
43 | 0x0000, 0x0808, 0x0000, 0x0006, /* 0x70 */ | ||
44 | 0x0000, 0x0000, 0x574d, 0x4c05, /* 0x78 */ | ||
45 | }; | ||
46 | |||
47 | static const struct snd_kcontrol_new wm9705_snd_ac97_controls[] = { | ||
48 | SOC_DOUBLE("Master Playback Volume", AC97_MASTER, 8, 0, 31, 1), | ||
49 | SOC_SINGLE("Master Playback Switch", AC97_MASTER, 15, 1, 1), | ||
50 | SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1), | ||
51 | SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 1, 1), | ||
52 | SOC_DOUBLE("PCM Playback Volume", AC97_PCM, 8, 0, 31, 1), | ||
53 | SOC_SINGLE("PCM Playback Switch", AC97_PCM, 15, 1, 1), | ||
54 | SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1), | ||
55 | SOC_SINGLE("Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1), | ||
56 | SOC_SINGLE("PCBeep Playback Volume", AC97_PC_BEEP, 1, 15, 1), | ||
57 | SOC_SINGLE("Phone Playback Volume", AC97_PHONE, 0, 31, 1), | ||
58 | SOC_DOUBLE("Line Playback Volume", AC97_LINE, 8, 0, 31, 1), | ||
59 | SOC_DOUBLE("CD Playback Volume", AC97_CD, 8, 0, 31, 1), | ||
60 | SOC_SINGLE("Mic Playback Volume", AC97_MIC, 0, 31, 1), | ||
61 | SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 6, 1, 0), | ||
62 | SOC_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 0), | ||
63 | SOC_SINGLE("Capture Switch", AC97_REC_GAIN, 15, 1, 1), | ||
64 | }; | ||
65 | |||
66 | static const char *wm9705_mic[] = {"Mic 1", "Mic 2"}; | ||
67 | static const char *wm9705_rec_sel[] = {"Mic", "CD", "NC", "NC", | ||
68 | "Line", "Stereo Mix", "Mono Mix", "Phone"}; | ||
69 | |||
70 | static const struct soc_enum wm9705_enum_mic = | ||
71 | SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 8, 2, wm9705_mic); | ||
72 | static const struct soc_enum wm9705_enum_rec_l = | ||
73 | SOC_ENUM_SINGLE(AC97_REC_SEL, 8, 8, wm9705_rec_sel); | ||
74 | static const struct soc_enum wm9705_enum_rec_r = | ||
75 | SOC_ENUM_SINGLE(AC97_REC_SEL, 0, 8, wm9705_rec_sel); | ||
76 | |||
77 | /* Headphone Mixer */ | ||
78 | static const struct snd_kcontrol_new wm9705_hp_mixer_controls[] = { | ||
79 | SOC_DAPM_SINGLE("PCBeep Playback Switch", AC97_PC_BEEP, 15, 1, 1), | ||
80 | SOC_DAPM_SINGLE("CD Playback Switch", AC97_CD, 15, 1, 1), | ||
81 | SOC_DAPM_SINGLE("Mic Playback Switch", AC97_MIC, 15, 1, 1), | ||
82 | SOC_DAPM_SINGLE("Phone Playback Switch", AC97_PHONE, 15, 1, 1), | ||
83 | SOC_DAPM_SINGLE("Line Playback Switch", AC97_LINE, 15, 1, 1), | ||
84 | }; | ||
85 | |||
86 | /* Mic source */ | ||
87 | static const struct snd_kcontrol_new wm9705_mic_src_controls = | ||
88 | SOC_DAPM_ENUM("Route", wm9705_enum_mic); | ||
89 | |||
90 | /* Capture source */ | ||
91 | static const struct snd_kcontrol_new wm9705_capture_selectl_controls = | ||
92 | SOC_DAPM_ENUM("Route", wm9705_enum_rec_l); | ||
93 | static const struct snd_kcontrol_new wm9705_capture_selectr_controls = | ||
94 | SOC_DAPM_ENUM("Route", wm9705_enum_rec_r); | ||
95 | |||
96 | /* DAPM widgets */ | ||
97 | static const struct snd_soc_dapm_widget wm9705_dapm_widgets[] = { | ||
98 | SND_SOC_DAPM_MUX("Mic Source", SND_SOC_NOPM, 0, 0, | ||
99 | &wm9705_mic_src_controls), | ||
100 | SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0, | ||
101 | &wm9705_capture_selectl_controls), | ||
102 | SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0, | ||
103 | &wm9705_capture_selectr_controls), | ||
104 | SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", | ||
105 | SND_SOC_NOPM, 0, 0), | ||
106 | SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", | ||
107 | SND_SOC_NOPM, 0, 0), | ||
108 | SND_SOC_DAPM_MIXER_NAMED_CTL("HP Mixer", SND_SOC_NOPM, 0, 0, | ||
109 | &wm9705_hp_mixer_controls[0], | ||
110 | ARRAY_SIZE(wm9705_hp_mixer_controls)), | ||
111 | SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
112 | SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", SND_SOC_NOPM, 0, 0), | ||
113 | SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", SND_SOC_NOPM, 0, 0), | ||
114 | SND_SOC_DAPM_PGA("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
115 | SND_SOC_DAPM_PGA("Speaker PGA", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
116 | SND_SOC_DAPM_PGA("Line PGA", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
117 | SND_SOC_DAPM_PGA("Line out PGA", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
118 | SND_SOC_DAPM_PGA("Mono PGA", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
119 | SND_SOC_DAPM_PGA("Phone PGA", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
120 | SND_SOC_DAPM_PGA("Mic PGA", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
121 | SND_SOC_DAPM_PGA("PCBEEP PGA", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
122 | SND_SOC_DAPM_PGA("CD PGA", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
123 | SND_SOC_DAPM_PGA("ADC PGA", SND_SOC_NOPM, 0, 0, NULL, 0), | ||
124 | SND_SOC_DAPM_OUTPUT("HPOUTL"), | ||
125 | SND_SOC_DAPM_OUTPUT("HPOUTR"), | ||
126 | SND_SOC_DAPM_OUTPUT("LOUT"), | ||
127 | SND_SOC_DAPM_OUTPUT("ROUT"), | ||
128 | SND_SOC_DAPM_OUTPUT("MONOOUT"), | ||
129 | SND_SOC_DAPM_INPUT("PHONE"), | ||
130 | SND_SOC_DAPM_INPUT("LINEINL"), | ||
131 | SND_SOC_DAPM_INPUT("LINEINR"), | ||
132 | SND_SOC_DAPM_INPUT("CDINL"), | ||
133 | SND_SOC_DAPM_INPUT("CDINR"), | ||
134 | SND_SOC_DAPM_INPUT("PCBEEP"), | ||
135 | SND_SOC_DAPM_INPUT("MIC1"), | ||
136 | SND_SOC_DAPM_INPUT("MIC2"), | ||
137 | }; | ||
138 | |||
139 | /* Audio map | ||
140 | * WM9705 has no switches to disable the route from the inputs to the HP mixer | ||
141 | * so in order to prevent active inputs from forcing the audio outputs to be | ||
142 | * constantly enabled, we use the mutes on those inputs to simulate such | ||
143 | * controls. | ||
144 | */ | ||
145 | static const struct snd_soc_dapm_route audio_map[] = { | ||
146 | /* HP mixer */ | ||
147 | {"HP Mixer", "PCBeep Playback Switch", "PCBEEP PGA"}, | ||
148 | {"HP Mixer", "CD Playback Switch", "CD PGA"}, | ||
149 | {"HP Mixer", "Mic Playback Switch", "Mic PGA"}, | ||
150 | {"HP Mixer", "Phone Playback Switch", "Phone PGA"}, | ||
151 | {"HP Mixer", "Line Playback Switch", "Line PGA"}, | ||
152 | {"HP Mixer", NULL, "Left DAC"}, | ||
153 | {"HP Mixer", NULL, "Right DAC"}, | ||
154 | |||
155 | /* mono mixer */ | ||
156 | {"Mono Mixer", NULL, "HP Mixer"}, | ||
157 | |||
158 | /* outputs */ | ||
159 | {"Headphone PGA", NULL, "HP Mixer"}, | ||
160 | {"HPOUTL", NULL, "Headphone PGA"}, | ||
161 | {"HPOUTR", NULL, "Headphone PGA"}, | ||
162 | {"Line out PGA", NULL, "HP Mixer"}, | ||
163 | {"LOUT", NULL, "Line out PGA"}, | ||
164 | {"ROUT", NULL, "Line out PGA"}, | ||
165 | {"Mono PGA", NULL, "Mono Mixer"}, | ||
166 | {"MONOOUT", NULL, "Mono PGA"}, | ||
167 | |||
168 | /* inputs */ | ||
169 | {"CD PGA", NULL, "CDINL"}, | ||
170 | {"CD PGA", NULL, "CDINR"}, | ||
171 | {"Line PGA", NULL, "LINEINL"}, | ||
172 | {"Line PGA", NULL, "LINEINR"}, | ||
173 | {"Phone PGA", NULL, "PHONE"}, | ||
174 | {"Mic Source", "Mic 1", "MIC1"}, | ||
175 | {"Mic Source", "Mic 2", "MIC2"}, | ||
176 | {"Mic PGA", NULL, "Mic Source"}, | ||
177 | {"PCBEEP PGA", NULL, "PCBEEP"}, | ||
178 | |||
179 | /* Left capture selector */ | ||
180 | {"Left Capture Source", "Mic", "Mic Source"}, | ||
181 | {"Left Capture Source", "CD", "CDINL"}, | ||
182 | {"Left Capture Source", "Line", "LINEINL"}, | ||
183 | {"Left Capture Source", "Stereo Mix", "HP Mixer"}, | ||
184 | {"Left Capture Source", "Mono Mix", "HP Mixer"}, | ||
185 | {"Left Capture Source", "Phone", "PHONE"}, | ||
186 | |||
187 | /* Right capture source */ | ||
188 | {"Right Capture Source", "Mic", "Mic Source"}, | ||
189 | {"Right Capture Source", "CD", "CDINR"}, | ||
190 | {"Right Capture Source", "Line", "LINEINR"}, | ||
191 | {"Right Capture Source", "Stereo Mix", "HP Mixer"}, | ||
192 | {"Right Capture Source", "Mono Mix", "HP Mixer"}, | ||
193 | {"Right Capture Source", "Phone", "PHONE"}, | ||
194 | |||
195 | {"ADC PGA", NULL, "Left Capture Source"}, | ||
196 | {"ADC PGA", NULL, "Right Capture Source"}, | ||
197 | |||
198 | /* ADC's */ | ||
199 | {"Left ADC", NULL, "ADC PGA"}, | ||
200 | {"Right ADC", NULL, "ADC PGA"}, | ||
201 | }; | ||
202 | |||
203 | static int wm9705_add_widgets(struct snd_soc_codec *codec) | ||
204 | { | ||
205 | snd_soc_dapm_new_controls(codec, wm9705_dapm_widgets, | ||
206 | ARRAY_SIZE(wm9705_dapm_widgets)); | ||
207 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | ||
208 | snd_soc_dapm_new_widgets(codec); | ||
209 | |||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | /* We use a register cache to enhance read performance. */ | ||
214 | static unsigned int ac97_read(struct snd_soc_codec *codec, unsigned int reg) | ||
215 | { | ||
216 | u16 *cache = codec->reg_cache; | ||
217 | |||
218 | switch (reg) { | ||
219 | case AC97_RESET: | ||
220 | case AC97_VENDOR_ID1: | ||
221 | case AC97_VENDOR_ID2: | ||
222 | return soc_ac97_ops.read(codec->ac97, reg); | ||
223 | default: | ||
224 | reg = reg >> 1; | ||
225 | |||
226 | if (reg >= (ARRAY_SIZE(wm9705_reg))) | ||
227 | return -EIO; | ||
228 | |||
229 | return cache[reg]; | ||
230 | } | ||
231 | } | ||
232 | |||
233 | static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, | ||
234 | unsigned int val) | ||
235 | { | ||
236 | u16 *cache = codec->reg_cache; | ||
237 | |||
238 | soc_ac97_ops.write(codec->ac97, reg, val); | ||
239 | reg = reg >> 1; | ||
240 | if (reg < (ARRAY_SIZE(wm9705_reg))) | ||
241 | cache[reg] = val; | ||
242 | |||
243 | return 0; | ||
244 | } | ||
245 | |||
246 | static int ac97_prepare(struct snd_pcm_substream *substream, | ||
247 | struct snd_soc_dai *dai) | ||
248 | { | ||
249 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
250 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
251 | struct snd_soc_device *socdev = rtd->socdev; | ||
252 | struct snd_soc_codec *codec = socdev->card->codec; | ||
253 | int reg; | ||
254 | u16 vra; | ||
255 | |||
256 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); | ||
257 | ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); | ||
258 | |||
259 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
260 | reg = AC97_PCM_FRONT_DAC_RATE; | ||
261 | else | ||
262 | reg = AC97_PCM_LR_ADC_RATE; | ||
263 | |||
264 | return ac97_write(codec, reg, runtime->rate); | ||
265 | } | ||
266 | |||
267 | #define WM9705_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | \ | ||
268 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \ | ||
269 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ | ||
270 | SNDRV_PCM_RATE_48000) | ||
271 | |||
272 | static struct snd_soc_dai_ops wm9705_dai_ops = { | ||
273 | .prepare = ac97_prepare, | ||
274 | }; | ||
275 | |||
276 | struct snd_soc_dai wm9705_dai[] = { | ||
277 | { | ||
278 | .name = "AC97 HiFi", | ||
279 | .ac97_control = 1, | ||
280 | .playback = { | ||
281 | .stream_name = "HiFi Playback", | ||
282 | .channels_min = 1, | ||
283 | .channels_max = 2, | ||
284 | .rates = WM9705_AC97_RATES, | ||
285 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
286 | }, | ||
287 | .capture = { | ||
288 | .stream_name = "HiFi Capture", | ||
289 | .channels_min = 1, | ||
290 | .channels_max = 2, | ||
291 | .rates = WM9705_AC97_RATES, | ||
292 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
293 | }, | ||
294 | .ops = &wm9705_dai_ops, | ||
295 | }, | ||
296 | { | ||
297 | .name = "AC97 Aux", | ||
298 | .playback = { | ||
299 | .stream_name = "Aux Playback", | ||
300 | .channels_min = 1, | ||
301 | .channels_max = 1, | ||
302 | .rates = WM9705_AC97_RATES, | ||
303 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
304 | }, | ||
305 | } | ||
306 | }; | ||
307 | EXPORT_SYMBOL_GPL(wm9705_dai); | ||
308 | |||
309 | static int wm9705_reset(struct snd_soc_codec *codec) | ||
310 | { | ||
311 | if (soc_ac97_ops.reset) { | ||
312 | soc_ac97_ops.reset(codec->ac97); | ||
313 | if (ac97_read(codec, 0) == wm9705_reg[0]) | ||
314 | return 0; /* Success */ | ||
315 | } | ||
316 | |||
317 | return -EIO; | ||
318 | } | ||
319 | |||
320 | static int wm9705_soc_probe(struct platform_device *pdev) | ||
321 | { | ||
322 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
323 | struct snd_soc_codec *codec; | ||
324 | int ret = 0; | ||
325 | |||
326 | printk(KERN_INFO "WM9705 SoC Audio Codec\n"); | ||
327 | |||
328 | socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), | ||
329 | GFP_KERNEL); | ||
330 | if (socdev->card->codec == NULL) | ||
331 | return -ENOMEM; | ||
332 | codec = socdev->card->codec; | ||
333 | mutex_init(&codec->mutex); | ||
334 | |||
335 | codec->reg_cache = kmemdup(wm9705_reg, sizeof(wm9705_reg), GFP_KERNEL); | ||
336 | if (codec->reg_cache == NULL) { | ||
337 | ret = -ENOMEM; | ||
338 | goto cache_err; | ||
339 | } | ||
340 | codec->reg_cache_size = sizeof(wm9705_reg); | ||
341 | codec->reg_cache_step = 2; | ||
342 | |||
343 | codec->name = "WM9705"; | ||
344 | codec->owner = THIS_MODULE; | ||
345 | codec->dai = wm9705_dai; | ||
346 | codec->num_dai = ARRAY_SIZE(wm9705_dai); | ||
347 | codec->write = ac97_write; | ||
348 | codec->read = ac97_read; | ||
349 | INIT_LIST_HEAD(&codec->dapm_widgets); | ||
350 | INIT_LIST_HEAD(&codec->dapm_paths); | ||
351 | |||
352 | ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0); | ||
353 | if (ret < 0) { | ||
354 | printk(KERN_ERR "wm9705: failed to register AC97 codec\n"); | ||
355 | goto codec_err; | ||
356 | } | ||
357 | |||
358 | /* register pcms */ | ||
359 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | ||
360 | if (ret < 0) | ||
361 | goto pcm_err; | ||
362 | |||
363 | ret = wm9705_reset(codec); | ||
364 | if (ret) | ||
365 | goto reset_err; | ||
366 | |||
367 | snd_soc_add_controls(codec, wm9705_snd_ac97_controls, | ||
368 | ARRAY_SIZE(wm9705_snd_ac97_controls)); | ||
369 | wm9705_add_widgets(codec); | ||
370 | |||
371 | ret = snd_soc_init_card(socdev); | ||
372 | if (ret < 0) { | ||
373 | printk(KERN_ERR "wm9705: failed to register card\n"); | ||
374 | goto pcm_err; | ||
375 | } | ||
376 | |||
377 | return 0; | ||
378 | |||
379 | reset_err: | ||
380 | snd_soc_free_pcms(socdev); | ||
381 | pcm_err: | ||
382 | snd_soc_free_ac97_codec(codec); | ||
383 | codec_err: | ||
384 | kfree(codec->reg_cache); | ||
385 | cache_err: | ||
386 | kfree(socdev->card->codec); | ||
387 | socdev->card->codec = NULL; | ||
388 | return ret; | ||
389 | } | ||
390 | |||
391 | static int wm9705_soc_remove(struct platform_device *pdev) | ||
392 | { | ||
393 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | ||
394 | struct snd_soc_codec *codec = socdev->card->codec; | ||
395 | |||
396 | if (codec == NULL) | ||
397 | return 0; | ||
398 | |||
399 | snd_soc_dapm_free(socdev); | ||
400 | snd_soc_free_pcms(socdev); | ||
401 | snd_soc_free_ac97_codec(codec); | ||
402 | kfree(codec->reg_cache); | ||
403 | kfree(codec); | ||
404 | return 0; | ||
405 | } | ||
406 | |||
407 | struct snd_soc_codec_device soc_codec_dev_wm9705 = { | ||
408 | .probe = wm9705_soc_probe, | ||
409 | .remove = wm9705_soc_remove, | ||
410 | }; | ||
411 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm9705); | ||
412 | |||
413 | MODULE_DESCRIPTION("ASoC WM9705 driver"); | ||
414 | MODULE_AUTHOR("Ian Molton"); | ||
415 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/sound/soc/codecs/wm9705.h b/sound/soc/codecs/wm9705.h new file mode 100644 index 000000000000..d380f110f9e2 --- /dev/null +++ b/sound/soc/codecs/wm9705.h | |||
@@ -0,0 +1,14 @@ | |||
1 | /* | ||
2 | * wm9705.h -- WM9705 Soc Audio driver | ||
3 | */ | ||
4 | |||
5 | #ifndef _WM9705_H | ||
6 | #define _WM9705_H | ||
7 | |||
8 | #define WM9705_DAI_AC97_HIFI 0 | ||
9 | #define WM9705_DAI_AC97_AUX 1 | ||
10 | |||
11 | extern struct snd_soc_dai wm9705_dai[2]; | ||
12 | extern struct snd_soc_codec_device soc_codec_dev_wm9705; | ||
13 | |||
14 | #endif | ||
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c index af83d629078a..765cf1e7369e 100644 --- a/sound/soc/codecs/wm9712.c +++ b/sound/soc/codecs/wm9712.c | |||
@@ -154,21 +154,6 @@ SOC_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1), | |||
154 | SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0), | 154 | SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0), |
155 | }; | 155 | }; |
156 | 156 | ||
157 | /* add non dapm controls */ | ||
158 | static int wm9712_add_controls(struct snd_soc_codec *codec) | ||
159 | { | ||
160 | int err, i; | ||
161 | |||
162 | for (i = 0; i < ARRAY_SIZE(wm9712_snd_ac97_controls); i++) { | ||
163 | err = snd_ctl_add(codec->card, | ||
164 | snd_soc_cnew(&wm9712_snd_ac97_controls[i], | ||
165 | codec, NULL)); | ||
166 | if (err < 0) | ||
167 | return err; | ||
168 | } | ||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | /* We have to create a fake left and right HP mixers because | 157 | /* We have to create a fake left and right HP mixers because |
173 | * the codec only has a single control that is shared by both channels. | 158 | * the codec only has a single control that is shared by both channels. |
174 | * This makes it impossible to determine the audio path. | 159 | * This makes it impossible to determine the audio path. |
@@ -467,7 +452,7 @@ static unsigned int ac97_read(struct snd_soc_codec *codec, | |||
467 | else { | 452 | else { |
468 | reg = reg >> 1; | 453 | reg = reg >> 1; |
469 | 454 | ||
470 | if (reg > (ARRAY_SIZE(wm9712_reg))) | 455 | if (reg >= (ARRAY_SIZE(wm9712_reg))) |
471 | return -EIO; | 456 | return -EIO; |
472 | 457 | ||
473 | return cache[reg]; | 458 | return cache[reg]; |
@@ -481,7 +466,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, | |||
481 | 466 | ||
482 | soc_ac97_ops.write(codec->ac97, reg, val); | 467 | soc_ac97_ops.write(codec->ac97, reg, val); |
483 | reg = reg >> 1; | 468 | reg = reg >> 1; |
484 | if (reg <= (ARRAY_SIZE(wm9712_reg))) | 469 | if (reg < (ARRAY_SIZE(wm9712_reg))) |
485 | cache[reg] = val; | 470 | cache[reg] = val; |
486 | 471 | ||
487 | return 0; | 472 | return 0; |
@@ -493,7 +478,7 @@ static int ac97_prepare(struct snd_pcm_substream *substream, | |||
493 | struct snd_pcm_runtime *runtime = substream->runtime; | 478 | struct snd_pcm_runtime *runtime = substream->runtime; |
494 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 479 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
495 | struct snd_soc_device *socdev = rtd->socdev; | 480 | struct snd_soc_device *socdev = rtd->socdev; |
496 | struct snd_soc_codec *codec = socdev->codec; | 481 | struct snd_soc_codec *codec = socdev->card->codec; |
497 | int reg; | 482 | int reg; |
498 | u16 vra; | 483 | u16 vra; |
499 | 484 | ||
@@ -514,7 +499,7 @@ static int ac97_aux_prepare(struct snd_pcm_substream *substream, | |||
514 | struct snd_pcm_runtime *runtime = substream->runtime; | 499 | struct snd_pcm_runtime *runtime = substream->runtime; |
515 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 500 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
516 | struct snd_soc_device *socdev = rtd->socdev; | 501 | struct snd_soc_device *socdev = rtd->socdev; |
517 | struct snd_soc_codec *codec = socdev->codec; | 502 | struct snd_soc_codec *codec = socdev->card->codec; |
518 | u16 vra, xsle; | 503 | u16 vra, xsle; |
519 | 504 | ||
520 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); | 505 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); |
@@ -532,6 +517,14 @@ static int ac97_aux_prepare(struct snd_pcm_substream *substream, | |||
532 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\ | 517 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\ |
533 | SNDRV_PCM_RATE_48000) | 518 | SNDRV_PCM_RATE_48000) |
534 | 519 | ||
520 | static struct snd_soc_dai_ops wm9712_dai_ops_hifi = { | ||
521 | .prepare = ac97_prepare, | ||
522 | }; | ||
523 | |||
524 | static struct snd_soc_dai_ops wm9712_dai_ops_aux = { | ||
525 | .prepare = ac97_aux_prepare, | ||
526 | }; | ||
527 | |||
535 | struct snd_soc_dai wm9712_dai[] = { | 528 | struct snd_soc_dai wm9712_dai[] = { |
536 | { | 529 | { |
537 | .name = "AC97 HiFi", | 530 | .name = "AC97 HiFi", |
@@ -548,8 +541,7 @@ struct snd_soc_dai wm9712_dai[] = { | |||
548 | .channels_max = 2, | 541 | .channels_max = 2, |
549 | .rates = WM9712_AC97_RATES, | 542 | .rates = WM9712_AC97_RATES, |
550 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 543 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
551 | .ops = { | 544 | .ops = &wm9712_dai_ops_hifi, |
552 | .prepare = ac97_prepare,}, | ||
553 | }, | 545 | }, |
554 | { | 546 | { |
555 | .name = "AC97 Aux", | 547 | .name = "AC97 Aux", |
@@ -559,8 +551,7 @@ struct snd_soc_dai wm9712_dai[] = { | |||
559 | .channels_max = 1, | 551 | .channels_max = 1, |
560 | .rates = WM9712_AC97_RATES, | 552 | .rates = WM9712_AC97_RATES, |
561 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 553 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
562 | .ops = { | 554 | .ops = &wm9712_dai_ops_aux, |
563 | .prepare = ac97_aux_prepare,}, | ||
564 | } | 555 | } |
565 | }; | 556 | }; |
566 | EXPORT_SYMBOL_GPL(wm9712_dai); | 557 | EXPORT_SYMBOL_GPL(wm9712_dai); |
@@ -607,7 +598,7 @@ static int wm9712_soc_suspend(struct platform_device *pdev, | |||
607 | pm_message_t state) | 598 | pm_message_t state) |
608 | { | 599 | { |
609 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 600 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
610 | struct snd_soc_codec *codec = socdev->codec; | 601 | struct snd_soc_codec *codec = socdev->card->codec; |
611 | 602 | ||
612 | wm9712_set_bias_level(codec, SND_SOC_BIAS_OFF); | 603 | wm9712_set_bias_level(codec, SND_SOC_BIAS_OFF); |
613 | return 0; | 604 | return 0; |
@@ -616,7 +607,7 @@ static int wm9712_soc_suspend(struct platform_device *pdev, | |||
616 | static int wm9712_soc_resume(struct platform_device *pdev) | 607 | static int wm9712_soc_resume(struct platform_device *pdev) |
617 | { | 608 | { |
618 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 609 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
619 | struct snd_soc_codec *codec = socdev->codec; | 610 | struct snd_soc_codec *codec = socdev->card->codec; |
620 | int i, ret; | 611 | int i, ret; |
621 | u16 *cache = codec->reg_cache; | 612 | u16 *cache = codec->reg_cache; |
622 | 613 | ||
@@ -652,10 +643,11 @@ static int wm9712_soc_probe(struct platform_device *pdev) | |||
652 | 643 | ||
653 | printk(KERN_INFO "WM9711/WM9712 SoC Audio Codec %s\n", WM9712_VERSION); | 644 | printk(KERN_INFO "WM9711/WM9712 SoC Audio Codec %s\n", WM9712_VERSION); |
654 | 645 | ||
655 | socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | 646 | socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), |
656 | if (socdev->codec == NULL) | 647 | GFP_KERNEL); |
648 | if (socdev->card->codec == NULL) | ||
657 | return -ENOMEM; | 649 | return -ENOMEM; |
658 | codec = socdev->codec; | 650 | codec = socdev->card->codec; |
659 | mutex_init(&codec->mutex); | 651 | mutex_init(&codec->mutex); |
660 | 652 | ||
661 | codec->reg_cache = kmemdup(wm9712_reg, sizeof(wm9712_reg), GFP_KERNEL); | 653 | codec->reg_cache = kmemdup(wm9712_reg, sizeof(wm9712_reg), GFP_KERNEL); |
@@ -698,7 +690,8 @@ static int wm9712_soc_probe(struct platform_device *pdev) | |||
698 | ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000); | 690 | ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000); |
699 | 691 | ||
700 | wm9712_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 692 | wm9712_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
701 | wm9712_add_controls(codec); | 693 | snd_soc_add_controls(codec, wm9712_snd_ac97_controls, |
694 | ARRAY_SIZE(wm9712_snd_ac97_controls)); | ||
702 | wm9712_add_widgets(codec); | 695 | wm9712_add_widgets(codec); |
703 | ret = snd_soc_init_card(socdev); | 696 | ret = snd_soc_init_card(socdev); |
704 | if (ret < 0) { | 697 | if (ret < 0) { |
@@ -718,15 +711,15 @@ codec_err: | |||
718 | kfree(codec->reg_cache); | 711 | kfree(codec->reg_cache); |
719 | 712 | ||
720 | cache_err: | 713 | cache_err: |
721 | kfree(socdev->codec); | 714 | kfree(socdev->card->codec); |
722 | socdev->codec = NULL; | 715 | socdev->card->codec = NULL; |
723 | return ret; | 716 | return ret; |
724 | } | 717 | } |
725 | 718 | ||
726 | static int wm9712_soc_remove(struct platform_device *pdev) | 719 | static int wm9712_soc_remove(struct platform_device *pdev) |
727 | { | 720 | { |
728 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 721 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
729 | struct snd_soc_codec *codec = socdev->codec; | 722 | struct snd_soc_codec *codec = socdev->card->codec; |
730 | 723 | ||
731 | if (codec == NULL) | 724 | if (codec == NULL) |
732 | return 0; | 725 | return 0; |
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c index f3ca8aaf0139..523bad077fa0 100644 --- a/sound/soc/codecs/wm9713.c +++ b/sound/soc/codecs/wm9713.c | |||
@@ -32,7 +32,6 @@ | |||
32 | 32 | ||
33 | struct wm9713_priv { | 33 | struct wm9713_priv { |
34 | u32 pll_in; /* PLL input frequency */ | 34 | u32 pll_in; /* PLL input frequency */ |
35 | u32 pll_out; /* PLL output frequency */ | ||
36 | }; | 35 | }; |
37 | 36 | ||
38 | static unsigned int ac97_read(struct snd_soc_codec *codec, | 37 | static unsigned int ac97_read(struct snd_soc_codec *codec, |
@@ -190,21 +189,6 @@ SOC_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0), | |||
190 | SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), | 189 | SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), |
191 | }; | 190 | }; |
192 | 191 | ||
193 | /* add non dapm controls */ | ||
194 | static int wm9713_add_controls(struct snd_soc_codec *codec) | ||
195 | { | ||
196 | int err, i; | ||
197 | |||
198 | for (i = 0; i < ARRAY_SIZE(wm9713_snd_ac97_controls); i++) { | ||
199 | err = snd_ctl_add(codec->card, | ||
200 | snd_soc_cnew(&wm9713_snd_ac97_controls[i], | ||
201 | codec, NULL)); | ||
202 | if (err < 0) | ||
203 | return err; | ||
204 | } | ||
205 | return 0; | ||
206 | } | ||
207 | |||
208 | /* We have to create a fake left and right HP mixers because | 192 | /* We have to create a fake left and right HP mixers because |
209 | * the codec only has a single control that is shared by both channels. | 193 | * the codec only has a single control that is shared by both channels. |
210 | * This makes it impossible to determine the audio path using the current | 194 | * This makes it impossible to determine the audio path using the current |
@@ -636,7 +620,7 @@ static unsigned int ac97_read(struct snd_soc_codec *codec, | |||
636 | else { | 620 | else { |
637 | reg = reg >> 1; | 621 | reg = reg >> 1; |
638 | 622 | ||
639 | if (reg > (ARRAY_SIZE(wm9713_reg))) | 623 | if (reg >= (ARRAY_SIZE(wm9713_reg))) |
640 | return -EIO; | 624 | return -EIO; |
641 | 625 | ||
642 | return cache[reg]; | 626 | return cache[reg]; |
@@ -650,7 +634,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, | |||
650 | if (reg < 0x7c) | 634 | if (reg < 0x7c) |
651 | soc_ac97_ops.write(codec->ac97, reg, val); | 635 | soc_ac97_ops.write(codec->ac97, reg, val); |
652 | reg = reg >> 1; | 636 | reg = reg >> 1; |
653 | if (reg <= (ARRAY_SIZE(wm9713_reg))) | 637 | if (reg < (ARRAY_SIZE(wm9713_reg))) |
654 | cache[reg] = val; | 638 | cache[reg] = val; |
655 | 639 | ||
656 | return 0; | 640 | return 0; |
@@ -738,13 +722,13 @@ static int wm9713_set_pll(struct snd_soc_codec *codec, | |||
738 | struct _pll_div pll_div; | 722 | struct _pll_div pll_div; |
739 | 723 | ||
740 | /* turn PLL off ? */ | 724 | /* turn PLL off ? */ |
741 | if (freq_in == 0 || freq_out == 0) { | 725 | if (freq_in == 0) { |
742 | /* disable PLL power and select ext source */ | 726 | /* disable PLL power and select ext source */ |
743 | reg = ac97_read(codec, AC97_HANDSET_RATE); | 727 | reg = ac97_read(codec, AC97_HANDSET_RATE); |
744 | ac97_write(codec, AC97_HANDSET_RATE, reg | 0x0080); | 728 | ac97_write(codec, AC97_HANDSET_RATE, reg | 0x0080); |
745 | reg = ac97_read(codec, AC97_EXTENDED_MID); | 729 | reg = ac97_read(codec, AC97_EXTENDED_MID); |
746 | ac97_write(codec, AC97_EXTENDED_MID, reg | 0x0200); | 730 | ac97_write(codec, AC97_EXTENDED_MID, reg | 0x0200); |
747 | wm9713->pll_out = 0; | 731 | wm9713->pll_in = 0; |
748 | return 0; | 732 | return 0; |
749 | } | 733 | } |
750 | 734 | ||
@@ -788,7 +772,6 @@ static int wm9713_set_pll(struct snd_soc_codec *codec, | |||
788 | ac97_write(codec, AC97_EXTENDED_MID, reg & 0xfdff); | 772 | ac97_write(codec, AC97_EXTENDED_MID, reg & 0xfdff); |
789 | reg = ac97_read(codec, AC97_HANDSET_RATE); | 773 | reg = ac97_read(codec, AC97_HANDSET_RATE); |
790 | ac97_write(codec, AC97_HANDSET_RATE, reg & 0xff7f); | 774 | ac97_write(codec, AC97_HANDSET_RATE, reg & 0xff7f); |
791 | wm9713->pll_out = freq_out; | ||
792 | wm9713->pll_in = freq_in; | 775 | wm9713->pll_in = freq_in; |
793 | 776 | ||
794 | /* wait 10ms AC97 link frames for the link to stabilise */ | 777 | /* wait 10ms AC97 link frames for the link to stabilise */ |
@@ -957,13 +940,14 @@ static void wm9713_voiceshutdown(struct snd_pcm_substream *substream, | |||
957 | struct snd_soc_dai *dai) | 940 | struct snd_soc_dai *dai) |
958 | { | 941 | { |
959 | struct snd_soc_codec *codec = dai->codec; | 942 | struct snd_soc_codec *codec = dai->codec; |
960 | u16 status; | 943 | u16 status, rate; |
961 | 944 | ||
962 | /* Gracefully shut down the voice interface. */ | 945 | /* Gracefully shut down the voice interface. */ |
963 | status = ac97_read(codec, AC97_EXTENDED_STATUS) | 0x1000; | 946 | status = ac97_read(codec, AC97_EXTENDED_STATUS) | 0x1000; |
964 | ac97_write(codec, AC97_HANDSET_RATE, 0x0280); | 947 | rate = ac97_read(codec, AC97_HANDSET_RATE) & 0xF0FF; |
948 | ac97_write(codec, AC97_HANDSET_RATE, rate | 0x0200); | ||
965 | schedule_timeout_interruptible(msecs_to_jiffies(1)); | 949 | schedule_timeout_interruptible(msecs_to_jiffies(1)); |
966 | ac97_write(codec, AC97_HANDSET_RATE, 0x0F80); | 950 | ac97_write(codec, AC97_HANDSET_RATE, rate | 0x0F00); |
967 | ac97_write(codec, AC97_EXTENDED_MID, status); | 951 | ac97_write(codec, AC97_EXTENDED_MID, status); |
968 | } | 952 | } |
969 | 953 | ||
@@ -1021,6 +1005,27 @@ static int ac97_aux_prepare(struct snd_pcm_substream *substream, | |||
1021 | (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \ | 1005 | (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \ |
1022 | SNDRV_PCM_FORMAT_S24_LE) | 1006 | SNDRV_PCM_FORMAT_S24_LE) |
1023 | 1007 | ||
1008 | static struct snd_soc_dai_ops wm9713_dai_ops_hifi = { | ||
1009 | .prepare = ac97_hifi_prepare, | ||
1010 | .set_clkdiv = wm9713_set_dai_clkdiv, | ||
1011 | .set_pll = wm9713_set_dai_pll, | ||
1012 | }; | ||
1013 | |||
1014 | static struct snd_soc_dai_ops wm9713_dai_ops_aux = { | ||
1015 | .prepare = ac97_aux_prepare, | ||
1016 | .set_clkdiv = wm9713_set_dai_clkdiv, | ||
1017 | .set_pll = wm9713_set_dai_pll, | ||
1018 | }; | ||
1019 | |||
1020 | static struct snd_soc_dai_ops wm9713_dai_ops_voice = { | ||
1021 | .hw_params = wm9713_pcm_hw_params, | ||
1022 | .shutdown = wm9713_voiceshutdown, | ||
1023 | .set_clkdiv = wm9713_set_dai_clkdiv, | ||
1024 | .set_pll = wm9713_set_dai_pll, | ||
1025 | .set_fmt = wm9713_set_dai_fmt, | ||
1026 | .set_tristate = wm9713_set_dai_tristate, | ||
1027 | }; | ||
1028 | |||
1024 | struct snd_soc_dai wm9713_dai[] = { | 1029 | struct snd_soc_dai wm9713_dai[] = { |
1025 | { | 1030 | { |
1026 | .name = "AC97 HiFi", | 1031 | .name = "AC97 HiFi", |
@@ -1037,10 +1042,7 @@ struct snd_soc_dai wm9713_dai[] = { | |||
1037 | .channels_max = 2, | 1042 | .channels_max = 2, |
1038 | .rates = WM9713_RATES, | 1043 | .rates = WM9713_RATES, |
1039 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 1044 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
1040 | .ops = { | 1045 | .ops = &wm9713_dai_ops_hifi, |
1041 | .prepare = ac97_hifi_prepare, | ||
1042 | .set_clkdiv = wm9713_set_dai_clkdiv, | ||
1043 | .set_pll = wm9713_set_dai_pll,}, | ||
1044 | }, | 1046 | }, |
1045 | { | 1047 | { |
1046 | .name = "AC97 Aux", | 1048 | .name = "AC97 Aux", |
@@ -1050,10 +1052,7 @@ struct snd_soc_dai wm9713_dai[] = { | |||
1050 | .channels_max = 1, | 1052 | .channels_max = 1, |
1051 | .rates = WM9713_RATES, | 1053 | .rates = WM9713_RATES, |
1052 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, | 1054 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
1053 | .ops = { | 1055 | .ops = &wm9713_dai_ops_aux, |
1054 | .prepare = ac97_aux_prepare, | ||
1055 | .set_clkdiv = wm9713_set_dai_clkdiv, | ||
1056 | .set_pll = wm9713_set_dai_pll,}, | ||
1057 | }, | 1056 | }, |
1058 | { | 1057 | { |
1059 | .name = "WM9713 Voice", | 1058 | .name = "WM9713 Voice", |
@@ -1069,14 +1068,7 @@ struct snd_soc_dai wm9713_dai[] = { | |||
1069 | .channels_max = 2, | 1068 | .channels_max = 2, |
1070 | .rates = WM9713_PCM_RATES, | 1069 | .rates = WM9713_PCM_RATES, |
1071 | .formats = WM9713_PCM_FORMATS,}, | 1070 | .formats = WM9713_PCM_FORMATS,}, |
1072 | .ops = { | 1071 | .ops = &wm9713_dai_ops_voice, |
1073 | .hw_params = wm9713_pcm_hw_params, | ||
1074 | .shutdown = wm9713_voiceshutdown, | ||
1075 | .set_clkdiv = wm9713_set_dai_clkdiv, | ||
1076 | .set_pll = wm9713_set_dai_pll, | ||
1077 | .set_fmt = wm9713_set_dai_fmt, | ||
1078 | .set_tristate = wm9713_set_dai_tristate, | ||
1079 | }, | ||
1080 | }, | 1072 | }, |
1081 | }; | 1073 | }; |
1082 | EXPORT_SYMBOL_GPL(wm9713_dai); | 1074 | EXPORT_SYMBOL_GPL(wm9713_dai); |
@@ -1132,7 +1124,7 @@ static int wm9713_soc_suspend(struct platform_device *pdev, | |||
1132 | pm_message_t state) | 1124 | pm_message_t state) |
1133 | { | 1125 | { |
1134 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1126 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1135 | struct snd_soc_codec *codec = socdev->codec; | 1127 | struct snd_soc_codec *codec = socdev->card->codec; |
1136 | u16 reg; | 1128 | u16 reg; |
1137 | 1129 | ||
1138 | /* Disable everything except touchpanel - that will be handled | 1130 | /* Disable everything except touchpanel - that will be handled |
@@ -1150,7 +1142,7 @@ static int wm9713_soc_suspend(struct platform_device *pdev, | |||
1150 | static int wm9713_soc_resume(struct platform_device *pdev) | 1142 | static int wm9713_soc_resume(struct platform_device *pdev) |
1151 | { | 1143 | { |
1152 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1144 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1153 | struct snd_soc_codec *codec = socdev->codec; | 1145 | struct snd_soc_codec *codec = socdev->card->codec; |
1154 | struct wm9713_priv *wm9713 = codec->private_data; | 1146 | struct wm9713_priv *wm9713 = codec->private_data; |
1155 | int i, ret; | 1147 | int i, ret; |
1156 | u16 *cache = codec->reg_cache; | 1148 | u16 *cache = codec->reg_cache; |
@@ -1164,8 +1156,8 @@ static int wm9713_soc_resume(struct platform_device *pdev) | |||
1164 | wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 1156 | wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
1165 | 1157 | ||
1166 | /* do we need to re-start the PLL ? */ | 1158 | /* do we need to re-start the PLL ? */ |
1167 | if (wm9713->pll_out) | 1159 | if (wm9713->pll_in) |
1168 | wm9713_set_pll(codec, 0, wm9713->pll_in, wm9713->pll_out); | 1160 | wm9713_set_pll(codec, 0, wm9713->pll_in, 0); |
1169 | 1161 | ||
1170 | /* only synchronise the codec if warm reset failed */ | 1162 | /* only synchronise the codec if warm reset failed */ |
1171 | if (ret == 0) { | 1163 | if (ret == 0) { |
@@ -1191,10 +1183,11 @@ static int wm9713_soc_probe(struct platform_device *pdev) | |||
1191 | 1183 | ||
1192 | printk(KERN_INFO "WM9713/WM9714 SoC Audio Codec %s\n", WM9713_VERSION); | 1184 | printk(KERN_INFO "WM9713/WM9714 SoC Audio Codec %s\n", WM9713_VERSION); |
1193 | 1185 | ||
1194 | socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); | 1186 | socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), |
1195 | if (socdev->codec == NULL) | 1187 | GFP_KERNEL); |
1188 | if (socdev->card->codec == NULL) | ||
1196 | return -ENOMEM; | 1189 | return -ENOMEM; |
1197 | codec = socdev->codec; | 1190 | codec = socdev->card->codec; |
1198 | mutex_init(&codec->mutex); | 1191 | mutex_init(&codec->mutex); |
1199 | 1192 | ||
1200 | codec->reg_cache = kmemdup(wm9713_reg, sizeof(wm9713_reg), GFP_KERNEL); | 1193 | codec->reg_cache = kmemdup(wm9713_reg, sizeof(wm9713_reg), GFP_KERNEL); |
@@ -1245,7 +1238,8 @@ static int wm9713_soc_probe(struct platform_device *pdev) | |||
1245 | reg = ac97_read(codec, AC97_CD) & 0x7fff; | 1238 | reg = ac97_read(codec, AC97_CD) & 0x7fff; |
1246 | ac97_write(codec, AC97_CD, reg); | 1239 | ac97_write(codec, AC97_CD, reg); |
1247 | 1240 | ||
1248 | wm9713_add_controls(codec); | 1241 | snd_soc_add_controls(codec, wm9713_snd_ac97_controls, |
1242 | ARRAY_SIZE(wm9713_snd_ac97_controls)); | ||
1249 | wm9713_add_widgets(codec); | 1243 | wm9713_add_widgets(codec); |
1250 | ret = snd_soc_init_card(socdev); | 1244 | ret = snd_soc_init_card(socdev); |
1251 | if (ret < 0) | 1245 | if (ret < 0) |
@@ -1265,15 +1259,15 @@ priv_err: | |||
1265 | kfree(codec->reg_cache); | 1259 | kfree(codec->reg_cache); |
1266 | 1260 | ||
1267 | cache_err: | 1261 | cache_err: |
1268 | kfree(socdev->codec); | 1262 | kfree(socdev->card->codec); |
1269 | socdev->codec = NULL; | 1263 | socdev->card->codec = NULL; |
1270 | return ret; | 1264 | return ret; |
1271 | } | 1265 | } |
1272 | 1266 | ||
1273 | static int wm9713_soc_remove(struct platform_device *pdev) | 1267 | static int wm9713_soc_remove(struct platform_device *pdev) |
1274 | { | 1268 | { |
1275 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 1269 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
1276 | struct snd_soc_codec *codec = socdev->codec; | 1270 | struct snd_soc_codec *codec = socdev->card->codec; |
1277 | 1271 | ||
1278 | if (codec == NULL) | 1272 | if (codec == NULL) |
1279 | return 0; | 1273 | return 0; |