Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * PMac AWACS lowlevel functions | |
3 | * | |
4 | * Copyright (c) by Takashi Iwai <tiwai@suse.de> | |
5 | * code based on dmasound.c. | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | */ | |
21 | ||
22 | ||
1da177e4 LT |
23 | #include <asm/io.h> |
24 | #include <asm/nvram.h> | |
25 | #include <linux/init.h> | |
26 | #include <linux/delay.h> | |
27 | #include <linux/slab.h> | |
28 | #include <sound/core.h> | |
29 | #include "pmac.h" | |
30 | ||
31 | ||
32 | #ifdef CONFIG_ADB_CUDA | |
33 | #define PMAC_AMP_AVAIL | |
34 | #endif | |
35 | ||
36 | #ifdef PMAC_AMP_AVAIL | |
65b29f50 | 37 | struct awacs_amp { |
1da177e4 LT |
38 | unsigned char amp_master; |
39 | unsigned char amp_vol[2][2]; | |
40 | unsigned char amp_tone[2]; | |
65b29f50 | 41 | }; |
1da177e4 LT |
42 | |
43 | #define CHECK_CUDA_AMP() (sys_ctrler == SYS_CTRLER_CUDA) | |
44 | ||
45 | #endif /* PMAC_AMP_AVAIL */ | |
46 | ||
47 | ||
65b29f50 | 48 | static void snd_pmac_screamer_wait(struct snd_pmac *chip) |
1da177e4 LT |
49 | { |
50 | long timeout = 2000; | |
51 | while (!(in_le32(&chip->awacs->codec_stat) & MASK_VALID)) { | |
52 | mdelay(1); | |
53 | if (! --timeout) { | |
54 | snd_printd("snd_pmac_screamer_wait timeout\n"); | |
55 | break; | |
56 | } | |
57 | } | |
58 | } | |
59 | ||
60 | /* | |
61 | * write AWACS register | |
62 | */ | |
63 | static void | |
65b29f50 | 64 | snd_pmac_awacs_write(struct snd_pmac *chip, int val) |
1da177e4 LT |
65 | { |
66 | long timeout = 5000000; | |
67 | ||
68 | if (chip->model == PMAC_SCREAMER) | |
69 | snd_pmac_screamer_wait(chip); | |
70 | out_le32(&chip->awacs->codec_ctrl, val | (chip->subframe << 22)); | |
71 | while (in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) { | |
72 | if (! --timeout) { | |
73 | snd_printd("snd_pmac_awacs_write timeout\n"); | |
74 | break; | |
75 | } | |
76 | } | |
77 | } | |
78 | ||
79 | static void | |
65b29f50 | 80 | snd_pmac_awacs_write_reg(struct snd_pmac *chip, int reg, int val) |
1da177e4 LT |
81 | { |
82 | snd_pmac_awacs_write(chip, val | (reg << 12)); | |
83 | chip->awacs_reg[reg] = val; | |
84 | } | |
85 | ||
86 | static void | |
65b29f50 | 87 | snd_pmac_awacs_write_noreg(struct snd_pmac *chip, int reg, int val) |
1da177e4 LT |
88 | { |
89 | snd_pmac_awacs_write(chip, val | (reg << 12)); | |
90 | } | |
91 | ||
8c870933 | 92 | #ifdef CONFIG_PM |
1da177e4 | 93 | /* Recalibrate chip */ |
65b29f50 | 94 | static void screamer_recalibrate(struct snd_pmac *chip) |
1da177e4 LT |
95 | { |
96 | if (chip->model != PMAC_SCREAMER) | |
97 | return; | |
98 | ||
99 | /* Sorry for the horrible delays... I hope to get that improved | |
100 | * by making the whole PM process asynchronous in a future version | |
101 | */ | |
102 | snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]); | |
103 | if (chip->manufacturer == 0x1) | |
104 | /* delay for broken crystal part */ | |
989a0b24 | 105 | msleep(750); |
1da177e4 | 106 | snd_pmac_awacs_write_noreg(chip, 1, |
65b29f50 TI |
107 | chip->awacs_reg[1] | MASK_RECALIBRATE | |
108 | MASK_CMUTE | MASK_AMUTE); | |
1da177e4 LT |
109 | snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]); |
110 | snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]); | |
111 | } | |
112 | ||
113 | #else | |
114 | #define screamer_recalibrate(chip) /* NOP */ | |
115 | #endif | |
116 | ||
117 | ||
118 | /* | |
119 | * additional callback to set the pcm format | |
120 | */ | |
65b29f50 | 121 | static void snd_pmac_awacs_set_format(struct snd_pmac *chip) |
1da177e4 LT |
122 | { |
123 | chip->awacs_reg[1] &= ~MASK_SAMPLERATE; | |
124 | chip->awacs_reg[1] |= chip->rate_index << 3; | |
125 | snd_pmac_awacs_write_reg(chip, 1, chip->awacs_reg[1]); | |
126 | } | |
127 | ||
128 | ||
129 | /* | |
130 | * AWACS volume callbacks | |
131 | */ | |
132 | /* | |
133 | * volumes: 0-15 stereo | |
134 | */ | |
65b29f50 TI |
135 | static int snd_pmac_awacs_info_volume(struct snd_kcontrol *kcontrol, |
136 | struct snd_ctl_elem_info *uinfo) | |
1da177e4 LT |
137 | { |
138 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
139 | uinfo->count = 2; | |
140 | uinfo->value.integer.min = 0; | |
141 | uinfo->value.integer.max = 15; | |
142 | return 0; | |
143 | } | |
144 | ||
65b29f50 TI |
145 | static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol, |
146 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 147 | { |
65b29f50 | 148 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
149 | int reg = kcontrol->private_value & 0xff; |
150 | int lshift = (kcontrol->private_value >> 8) & 0xff; | |
151 | int inverted = (kcontrol->private_value >> 16) & 1; | |
152 | unsigned long flags; | |
153 | int vol[2]; | |
154 | ||
155 | spin_lock_irqsave(&chip->reg_lock, flags); | |
156 | vol[0] = (chip->awacs_reg[reg] >> lshift) & 0xf; | |
157 | vol[1] = chip->awacs_reg[reg] & 0xf; | |
158 | spin_unlock_irqrestore(&chip->reg_lock, flags); | |
159 | if (inverted) { | |
160 | vol[0] = 0x0f - vol[0]; | |
161 | vol[1] = 0x0f - vol[1]; | |
162 | } | |
163 | ucontrol->value.integer.value[0] = vol[0]; | |
164 | ucontrol->value.integer.value[1] = vol[1]; | |
165 | return 0; | |
166 | } | |
167 | ||
65b29f50 TI |
168 | static int snd_pmac_awacs_put_volume(struct snd_kcontrol *kcontrol, |
169 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 170 | { |
65b29f50 | 171 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
172 | int reg = kcontrol->private_value & 0xff; |
173 | int lshift = (kcontrol->private_value >> 8) & 0xff; | |
174 | int inverted = (kcontrol->private_value >> 16) & 1; | |
175 | int val, oldval; | |
176 | unsigned long flags; | |
d4079ac4 | 177 | unsigned int vol[2]; |
1da177e4 LT |
178 | |
179 | vol[0] = ucontrol->value.integer.value[0]; | |
180 | vol[1] = ucontrol->value.integer.value[1]; | |
d4079ac4 TI |
181 | if (vol[0] > 0x0f || vol[1] > 0x0f) |
182 | return -EINVAL; | |
1da177e4 LT |
183 | if (inverted) { |
184 | vol[0] = 0x0f - vol[0]; | |
185 | vol[1] = 0x0f - vol[1]; | |
186 | } | |
187 | vol[0] &= 0x0f; | |
188 | vol[1] &= 0x0f; | |
189 | spin_lock_irqsave(&chip->reg_lock, flags); | |
190 | oldval = chip->awacs_reg[reg]; | |
191 | val = oldval & ~(0xf | (0xf << lshift)); | |
192 | val |= vol[0] << lshift; | |
193 | val |= vol[1]; | |
194 | if (oldval != val) | |
195 | snd_pmac_awacs_write_reg(chip, reg, val); | |
196 | spin_unlock_irqrestore(&chip->reg_lock, flags); | |
197 | return oldval != reg; | |
198 | } | |
199 | ||
200 | ||
201 | #define AWACS_VOLUME(xname, xreg, xshift, xinverted) \ | |
202 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ | |
203 | .info = snd_pmac_awacs_info_volume, \ | |
204 | .get = snd_pmac_awacs_get_volume, \ | |
205 | .put = snd_pmac_awacs_put_volume, \ | |
206 | .private_value = (xreg) | ((xshift) << 8) | ((xinverted) << 16) } | |
207 | ||
208 | /* | |
209 | * mute master/ogain for AWACS: mono | |
210 | */ | |
65b29f50 TI |
211 | static int snd_pmac_awacs_get_switch(struct snd_kcontrol *kcontrol, |
212 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 213 | { |
65b29f50 | 214 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
215 | int reg = kcontrol->private_value & 0xff; |
216 | int shift = (kcontrol->private_value >> 8) & 0xff; | |
217 | int invert = (kcontrol->private_value >> 16) & 1; | |
218 | int val; | |
219 | unsigned long flags; | |
220 | ||
221 | spin_lock_irqsave(&chip->reg_lock, flags); | |
222 | val = (chip->awacs_reg[reg] >> shift) & 1; | |
223 | spin_unlock_irqrestore(&chip->reg_lock, flags); | |
224 | if (invert) | |
225 | val = 1 - val; | |
226 | ucontrol->value.integer.value[0] = val; | |
227 | return 0; | |
228 | } | |
229 | ||
65b29f50 TI |
230 | static int snd_pmac_awacs_put_switch(struct snd_kcontrol *kcontrol, |
231 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 232 | { |
65b29f50 | 233 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
234 | int reg = kcontrol->private_value & 0xff; |
235 | int shift = (kcontrol->private_value >> 8) & 0xff; | |
236 | int invert = (kcontrol->private_value >> 16) & 1; | |
237 | int mask = 1 << shift; | |
238 | int val, changed; | |
239 | unsigned long flags; | |
240 | ||
241 | spin_lock_irqsave(&chip->reg_lock, flags); | |
242 | val = chip->awacs_reg[reg] & ~mask; | |
243 | if (ucontrol->value.integer.value[0] != invert) | |
244 | val |= mask; | |
245 | changed = chip->awacs_reg[reg] != val; | |
246 | if (changed) | |
247 | snd_pmac_awacs_write_reg(chip, reg, val); | |
248 | spin_unlock_irqrestore(&chip->reg_lock, flags); | |
249 | return changed; | |
250 | } | |
251 | ||
252 | #define AWACS_SWITCH(xname, xreg, xshift, xinvert) \ | |
253 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ | |
254 | .info = snd_pmac_boolean_mono_info, \ | |
255 | .get = snd_pmac_awacs_get_switch, \ | |
256 | .put = snd_pmac_awacs_put_switch, \ | |
257 | .private_value = (xreg) | ((xshift) << 8) | ((xinvert) << 16) } | |
258 | ||
259 | ||
260 | #ifdef PMAC_AMP_AVAIL | |
261 | /* | |
262 | * controls for perch/whisper extension cards, e.g. G3 desktop | |
263 | * | |
264 | * TDA7433 connected via i2c address 0x45 (= 0x8a), | |
265 | * accessed through cuda | |
266 | */ | |
267 | static void awacs_set_cuda(int reg, int val) | |
268 | { | |
269 | struct adb_request req; | |
270 | cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a, reg, val); | |
271 | while (! req.complete) | |
272 | cuda_poll(); | |
273 | } | |
274 | ||
275 | /* | |
276 | * level = 0 - 14, 7 = 0 dB | |
277 | */ | |
65b29f50 | 278 | static void awacs_amp_set_tone(struct awacs_amp *amp, int bass, int treble) |
1da177e4 LT |
279 | { |
280 | amp->amp_tone[0] = bass; | |
281 | amp->amp_tone[1] = treble; | |
282 | if (bass > 7) | |
283 | bass = (14 - bass) + 8; | |
284 | if (treble > 7) | |
285 | treble = (14 - treble) + 8; | |
286 | awacs_set_cuda(2, (bass << 4) | treble); | |
287 | } | |
288 | ||
289 | /* | |
290 | * vol = 0 - 31 (attenuation), 32 = mute bit, stereo | |
291 | */ | |
65b29f50 TI |
292 | static int awacs_amp_set_vol(struct awacs_amp *amp, int index, int lvol, int rvol, |
293 | int do_check) | |
1da177e4 LT |
294 | { |
295 | if (do_check && amp->amp_vol[index][0] == lvol && | |
296 | amp->amp_vol[index][1] == rvol) | |
297 | return 0; | |
298 | awacs_set_cuda(3 + index, lvol); | |
299 | awacs_set_cuda(5 + index, rvol); | |
300 | amp->amp_vol[index][0] = lvol; | |
301 | amp->amp_vol[index][1] = rvol; | |
302 | return 1; | |
303 | } | |
304 | ||
305 | /* | |
306 | * 0 = -79 dB, 79 = 0 dB, 99 = +20 dB | |
307 | */ | |
65b29f50 | 308 | static void awacs_amp_set_master(struct awacs_amp *amp, int vol) |
1da177e4 LT |
309 | { |
310 | amp->amp_master = vol; | |
311 | if (vol <= 79) | |
312 | vol = 32 + (79 - vol); | |
313 | else | |
314 | vol = 32 - (vol - 79); | |
315 | awacs_set_cuda(1, vol); | |
316 | } | |
317 | ||
65b29f50 | 318 | static void awacs_amp_free(struct snd_pmac *chip) |
1da177e4 | 319 | { |
65b29f50 | 320 | struct awacs_amp *amp = chip->mixer_data; |
1da177e4 LT |
321 | snd_assert(amp, return); |
322 | kfree(amp); | |
323 | chip->mixer_data = NULL; | |
324 | chip->mixer_free = NULL; | |
325 | } | |
326 | ||
327 | ||
328 | /* | |
329 | * mixer controls | |
330 | */ | |
65b29f50 TI |
331 | static int snd_pmac_awacs_info_volume_amp(struct snd_kcontrol *kcontrol, |
332 | struct snd_ctl_elem_info *uinfo) | |
1da177e4 LT |
333 | { |
334 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
335 | uinfo->count = 2; | |
336 | uinfo->value.integer.min = 0; | |
337 | uinfo->value.integer.max = 31; | |
338 | return 0; | |
339 | } | |
340 | ||
65b29f50 TI |
341 | static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol, |
342 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 343 | { |
65b29f50 | 344 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
1da177e4 | 345 | int index = kcontrol->private_value; |
65b29f50 | 346 | struct awacs_amp *amp = chip->mixer_data; |
1da177e4 LT |
347 | snd_assert(amp, return -EINVAL); |
348 | snd_assert(index >= 0 && index <= 1, return -EINVAL); | |
349 | ucontrol->value.integer.value[0] = 31 - (amp->amp_vol[index][0] & 31); | |
350 | ucontrol->value.integer.value[1] = 31 - (amp->amp_vol[index][1] & 31); | |
351 | return 0; | |
352 | } | |
353 | ||
65b29f50 TI |
354 | static int snd_pmac_awacs_put_volume_amp(struct snd_kcontrol *kcontrol, |
355 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 356 | { |
65b29f50 | 357 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
358 | int index = kcontrol->private_value; |
359 | int vol[2]; | |
65b29f50 | 360 | struct awacs_amp *amp = chip->mixer_data; |
1da177e4 LT |
361 | snd_assert(amp, return -EINVAL); |
362 | snd_assert(index >= 0 && index <= 1, return -EINVAL); | |
363 | ||
364 | vol[0] = (31 - (ucontrol->value.integer.value[0] & 31)) | (amp->amp_vol[index][0] & 32); | |
365 | vol[1] = (31 - (ucontrol->value.integer.value[1] & 31)) | (amp->amp_vol[index][1] & 32); | |
366 | return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1); | |
367 | } | |
368 | ||
65b29f50 TI |
369 | static int snd_pmac_awacs_get_switch_amp(struct snd_kcontrol *kcontrol, |
370 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 371 | { |
65b29f50 | 372 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
1da177e4 | 373 | int index = kcontrol->private_value; |
65b29f50 | 374 | struct awacs_amp *amp = chip->mixer_data; |
1da177e4 LT |
375 | snd_assert(amp, return -EINVAL); |
376 | snd_assert(index >= 0 && index <= 1, return -EINVAL); | |
377 | ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32) ? 0 : 1; | |
378 | ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32) ? 0 : 1; | |
379 | return 0; | |
380 | } | |
381 | ||
65b29f50 TI |
382 | static int snd_pmac_awacs_put_switch_amp(struct snd_kcontrol *kcontrol, |
383 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 384 | { |
65b29f50 | 385 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
386 | int index = kcontrol->private_value; |
387 | int vol[2]; | |
65b29f50 | 388 | struct awacs_amp *amp = chip->mixer_data; |
1da177e4 LT |
389 | snd_assert(amp, return -EINVAL); |
390 | snd_assert(index >= 0 && index <= 1, return -EINVAL); | |
391 | ||
392 | vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32) | (amp->amp_vol[index][0] & 31); | |
393 | vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32) | (amp->amp_vol[index][1] & 31); | |
394 | return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1); | |
395 | } | |
396 | ||
65b29f50 TI |
397 | static int snd_pmac_awacs_info_tone_amp(struct snd_kcontrol *kcontrol, |
398 | struct snd_ctl_elem_info *uinfo) | |
1da177e4 LT |
399 | { |
400 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
401 | uinfo->count = 1; | |
402 | uinfo->value.integer.min = 0; | |
403 | uinfo->value.integer.max = 14; | |
404 | return 0; | |
405 | } | |
406 | ||
65b29f50 TI |
407 | static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol, |
408 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 409 | { |
65b29f50 | 410 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
1da177e4 | 411 | int index = kcontrol->private_value; |
65b29f50 | 412 | struct awacs_amp *amp = chip->mixer_data; |
1da177e4 LT |
413 | snd_assert(amp, return -EINVAL); |
414 | snd_assert(index >= 0 && index <= 1, return -EINVAL); | |
415 | ucontrol->value.integer.value[0] = amp->amp_tone[index]; | |
416 | return 0; | |
417 | } | |
418 | ||
65b29f50 TI |
419 | static int snd_pmac_awacs_put_tone_amp(struct snd_kcontrol *kcontrol, |
420 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 421 | { |
65b29f50 | 422 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
1da177e4 | 423 | int index = kcontrol->private_value; |
65b29f50 | 424 | struct awacs_amp *amp = chip->mixer_data; |
d4079ac4 | 425 | unsigned int val; |
1da177e4 LT |
426 | snd_assert(amp, return -EINVAL); |
427 | snd_assert(index >= 0 && index <= 1, return -EINVAL); | |
d4079ac4 TI |
428 | val = ucontrol->value.integer.value[0]; |
429 | if (val > 14) | |
430 | return -EINVAL; | |
431 | if (val != amp->amp_tone[index]) { | |
432 | amp->amp_tone[index] = val; | |
1da177e4 LT |
433 | awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]); |
434 | return 1; | |
435 | } | |
436 | return 0; | |
437 | } | |
438 | ||
65b29f50 TI |
439 | static int snd_pmac_awacs_info_master_amp(struct snd_kcontrol *kcontrol, |
440 | struct snd_ctl_elem_info *uinfo) | |
1da177e4 LT |
441 | { |
442 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
443 | uinfo->count = 1; | |
444 | uinfo->value.integer.min = 0; | |
445 | uinfo->value.integer.max = 99; | |
446 | return 0; | |
447 | } | |
448 | ||
65b29f50 TI |
449 | static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol, |
450 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 451 | { |
65b29f50 TI |
452 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
453 | struct awacs_amp *amp = chip->mixer_data; | |
1da177e4 LT |
454 | snd_assert(amp, return -EINVAL); |
455 | ucontrol->value.integer.value[0] = amp->amp_master; | |
456 | return 0; | |
457 | } | |
458 | ||
65b29f50 TI |
459 | static int snd_pmac_awacs_put_master_amp(struct snd_kcontrol *kcontrol, |
460 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 461 | { |
65b29f50 TI |
462 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
463 | struct awacs_amp *amp = chip->mixer_data; | |
d4079ac4 | 464 | unsigned int val; |
1da177e4 | 465 | snd_assert(amp, return -EINVAL); |
d4079ac4 TI |
466 | val = ucontrol->value.integer.value[0]; |
467 | if (val > 99) | |
468 | return -EINVAL; | |
469 | if (val != amp->amp_master) { | |
470 | amp->amp_master = val; | |
1da177e4 LT |
471 | awacs_amp_set_master(amp, amp->amp_master); |
472 | return 1; | |
473 | } | |
474 | return 0; | |
475 | } | |
476 | ||
477 | #define AMP_CH_SPK 0 | |
478 | #define AMP_CH_HD 1 | |
479 | ||
65b29f50 | 480 | static struct snd_kcontrol_new snd_pmac_awacs_amp_vol[] __initdata = { |
1da177e4 LT |
481 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
482 | .name = "PC Speaker Playback Volume", | |
483 | .info = snd_pmac_awacs_info_volume_amp, | |
484 | .get = snd_pmac_awacs_get_volume_amp, | |
485 | .put = snd_pmac_awacs_put_volume_amp, | |
486 | .private_value = AMP_CH_SPK, | |
487 | }, | |
488 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
489 | .name = "Headphone Playback Volume", | |
490 | .info = snd_pmac_awacs_info_volume_amp, | |
491 | .get = snd_pmac_awacs_get_volume_amp, | |
492 | .put = snd_pmac_awacs_put_volume_amp, | |
493 | .private_value = AMP_CH_HD, | |
494 | }, | |
495 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
496 | .name = "Tone Control - Bass", | |
497 | .info = snd_pmac_awacs_info_tone_amp, | |
498 | .get = snd_pmac_awacs_get_tone_amp, | |
499 | .put = snd_pmac_awacs_put_tone_amp, | |
500 | .private_value = 0, | |
501 | }, | |
502 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
503 | .name = "Tone Control - Treble", | |
504 | .info = snd_pmac_awacs_info_tone_amp, | |
505 | .get = snd_pmac_awacs_get_tone_amp, | |
506 | .put = snd_pmac_awacs_put_tone_amp, | |
507 | .private_value = 1, | |
508 | }, | |
509 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
510 | .name = "Amp Master Playback Volume", | |
511 | .info = snd_pmac_awacs_info_master_amp, | |
512 | .get = snd_pmac_awacs_get_master_amp, | |
513 | .put = snd_pmac_awacs_put_master_amp, | |
514 | }, | |
515 | }; | |
516 | ||
65b29f50 | 517 | static struct snd_kcontrol_new snd_pmac_awacs_amp_hp_sw __initdata = { |
1da177e4 LT |
518 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
519 | .name = "Headphone Playback Switch", | |
520 | .info = snd_pmac_boolean_stereo_info, | |
521 | .get = snd_pmac_awacs_get_switch_amp, | |
522 | .put = snd_pmac_awacs_put_switch_amp, | |
523 | .private_value = AMP_CH_HD, | |
524 | }; | |
525 | ||
65b29f50 | 526 | static struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw __initdata = { |
1da177e4 LT |
527 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
528 | .name = "PC Speaker Playback Switch", | |
529 | .info = snd_pmac_boolean_stereo_info, | |
530 | .get = snd_pmac_awacs_get_switch_amp, | |
531 | .put = snd_pmac_awacs_put_switch_amp, | |
532 | .private_value = AMP_CH_SPK, | |
533 | }; | |
534 | ||
535 | #endif /* PMAC_AMP_AVAIL */ | |
536 | ||
537 | ||
538 | /* | |
539 | * mic boost for screamer | |
540 | */ | |
65b29f50 TI |
541 | static int snd_pmac_screamer_mic_boost_info(struct snd_kcontrol *kcontrol, |
542 | struct snd_ctl_elem_info *uinfo) | |
1da177e4 LT |
543 | { |
544 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
545 | uinfo->count = 1; | |
546 | uinfo->value.integer.min = 0; | |
a8c2a6bf | 547 | uinfo->value.integer.max = 3; |
1da177e4 LT |
548 | return 0; |
549 | } | |
550 | ||
65b29f50 TI |
551 | static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol *kcontrol, |
552 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 553 | { |
65b29f50 | 554 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
a8c2a6bf | 555 | int val = 0; |
1da177e4 LT |
556 | unsigned long flags; |
557 | ||
558 | spin_lock_irqsave(&chip->reg_lock, flags); | |
559 | if (chip->awacs_reg[6] & MASK_MIC_BOOST) | |
a8c2a6bf RS |
560 | val |= 2; |
561 | if (chip->awacs_reg[0] & MASK_GAINLINE) | |
562 | val |= 1; | |
1da177e4 LT |
563 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
564 | ucontrol->value.integer.value[0] = val; | |
565 | return 0; | |
566 | } | |
567 | ||
65b29f50 TI |
568 | static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol, |
569 | struct snd_ctl_elem_value *ucontrol) | |
1da177e4 | 570 | { |
65b29f50 | 571 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
1da177e4 LT |
572 | int changed = 0; |
573 | int val0, val6; | |
574 | unsigned long flags; | |
575 | ||
576 | spin_lock_irqsave(&chip->reg_lock, flags); | |
577 | val0 = chip->awacs_reg[0] & ~MASK_GAINLINE; | |
578 | val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST; | |
a8c2a6bf | 579 | if (ucontrol->value.integer.value[0] & 1) |
1da177e4 | 580 | val0 |= MASK_GAINLINE; |
a8c2a6bf RS |
581 | if (ucontrol->value.integer.value[0] & 2) |
582 | val6 |= MASK_MIC_BOOST; | |
1da177e4 LT |
583 | if (val0 != chip->awacs_reg[0]) { |
584 | snd_pmac_awacs_write_reg(chip, 0, val0); | |
585 | changed = 1; | |
586 | } | |
587 | if (val6 != chip->awacs_reg[6]) { | |
588 | snd_pmac_awacs_write_reg(chip, 6, val6); | |
589 | changed = 1; | |
590 | } | |
591 | spin_unlock_irqrestore(&chip->reg_lock, flags); | |
592 | return changed; | |
593 | } | |
594 | ||
595 | /* | |
596 | * lists of mixer elements | |
597 | */ | |
65b29f50 | 598 | static struct snd_kcontrol_new snd_pmac_awacs_mixers[] __initdata = { |
1da177e4 | 599 | AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0), |
a8c2a6bf RS |
600 | AWACS_VOLUME("Master Capture Volume", 0, 4, 0), |
601 | /* AWACS_SWITCH("Unknown Playback Switch", 6, SHIFT_PAROUT0, 0), */ | |
602 | }; | |
603 | ||
604 | static struct snd_kcontrol_new snd_pmac_screamer_mixers_beige[] __initdata = { | |
605 | AWACS_VOLUME("Master Playback Volume", 2, 6, 1), | |
606 | AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1), | |
607 | AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0), | |
608 | AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_LINE, 0), | |
609 | }; | |
610 | ||
611 | static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] __initdata = { | |
612 | AWACS_VOLUME("Line out Playback Volume", 2, 6, 1), | |
613 | AWACS_VOLUME("Master Playback Volume", 5, 6, 1), | |
614 | AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0), | |
615 | }; | |
616 | ||
617 | static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] __initdata = { | |
618 | AWACS_VOLUME("Line out Playback Volume", 2, 6, 1), | |
619 | AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0), | |
620 | AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0), | |
621 | }; | |
622 | ||
623 | static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] __initdata = { | |
624 | AWACS_VOLUME("Master Playback Volume", 2, 6, 1), | |
1da177e4 LT |
625 | AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0), |
626 | }; | |
627 | ||
628 | /* FIXME: is this correct order? | |
629 | * screamer (powerbook G3 pismo) seems to have different bits... | |
630 | */ | |
65b29f50 | 631 | static struct snd_kcontrol_new snd_pmac_awacs_mixers2[] __initdata = { |
1da177e4 LT |
632 | AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_LINE, 0), |
633 | AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_MIC, 0), | |
634 | }; | |
635 | ||
65b29f50 | 636 | static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] __initdata = { |
1da177e4 LT |
637 | AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0), |
638 | AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_LINE, 0), | |
639 | }; | |
640 | ||
65b29f50 | 641 | static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata = |
1da177e4 LT |
642 | AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1); |
643 | ||
a8c2a6bf RS |
644 | static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac __initdata = |
645 | AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1); | |
646 | ||
65b29f50 | 647 | static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = { |
a8c2a6bf | 648 | AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0), |
1da177e4 LT |
649 | }; |
650 | ||
65b29f50 | 651 | static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __initdata = { |
1da177e4 | 652 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
a8c2a6bf | 653 | .name = "Mic Boost Capture Volume", |
1da177e4 LT |
654 | .info = snd_pmac_screamer_mic_boost_info, |
655 | .get = snd_pmac_screamer_mic_boost_get, | |
656 | .put = snd_pmac_screamer_mic_boost_put, | |
657 | }, | |
658 | }; | |
659 | ||
a8c2a6bf RS |
660 | static struct snd_kcontrol_new snd_pmac_awacs_mic_boost_pmac7500[] __initdata = |
661 | { | |
662 | AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0), | |
663 | }; | |
664 | ||
665 | static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_beige[] __initdata = | |
666 | { | |
667 | AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0), | |
668 | AWACS_SWITCH("CD Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0), | |
669 | }; | |
670 | ||
671 | static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] __initdata = | |
672 | { | |
673 | AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0), | |
674 | AWACS_SWITCH("Mic Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0), | |
675 | }; | |
676 | ||
65b29f50 | 677 | static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __initdata = { |
1da177e4 LT |
678 | AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1), |
679 | }; | |
a8c2a6bf | 680 | |
65b29f50 | 681 | static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata = |
1da177e4 LT |
682 | AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1); |
683 | ||
a8c2a6bf RS |
684 | static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac __initdata = |
685 | AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 0); | |
686 | ||
1da177e4 LT |
687 | |
688 | /* | |
689 | * add new mixer elements to the card | |
690 | */ | |
65b29f50 | 691 | static int build_mixers(struct snd_pmac *chip, int nums, struct snd_kcontrol_new *mixers) |
1da177e4 LT |
692 | { |
693 | int i, err; | |
694 | ||
695 | for (i = 0; i < nums; i++) { | |
696 | if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip))) < 0) | |
697 | return err; | |
698 | } | |
699 | return 0; | |
700 | } | |
701 | ||
702 | ||
703 | /* | |
704 | * restore all registers | |
705 | */ | |
65b29f50 | 706 | static void awacs_restore_all_regs(struct snd_pmac *chip) |
1da177e4 LT |
707 | { |
708 | snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]); | |
709 | snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]); | |
710 | snd_pmac_awacs_write_noreg(chip, 2, chip->awacs_reg[2]); | |
711 | snd_pmac_awacs_write_noreg(chip, 4, chip->awacs_reg[4]); | |
712 | if (chip->model == PMAC_SCREAMER) { | |
713 | snd_pmac_awacs_write_noreg(chip, 5, chip->awacs_reg[5]); | |
714 | snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]); | |
715 | snd_pmac_awacs_write_noreg(chip, 7, chip->awacs_reg[7]); | |
716 | } | |
717 | } | |
718 | ||
8c870933 | 719 | #ifdef CONFIG_PM |
65b29f50 | 720 | static void snd_pmac_awacs_suspend(struct snd_pmac *chip) |
1da177e4 LT |
721 | { |
722 | snd_pmac_awacs_write_noreg(chip, 1, (chip->awacs_reg[1] | |
723 | | MASK_AMUTE | MASK_CMUTE)); | |
724 | } | |
725 | ||
65b29f50 | 726 | static void snd_pmac_awacs_resume(struct snd_pmac *chip) |
1da177e4 LT |
727 | { |
728 | if (machine_is_compatible("PowerBook3,1") | |
729 | || machine_is_compatible("PowerBook3,2")) { | |
989a0b24 | 730 | msleep(100); |
1da177e4 LT |
731 | snd_pmac_awacs_write_reg(chip, 1, |
732 | chip->awacs_reg[1] & ~MASK_PAROUT); | |
989a0b24 | 733 | msleep(300); |
1da177e4 LT |
734 | } |
735 | ||
736 | awacs_restore_all_regs(chip); | |
737 | if (chip->model == PMAC_SCREAMER) { | |
738 | /* reset power bits in reg 6 */ | |
739 | mdelay(5); | |
740 | snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]); | |
741 | } | |
742 | screamer_recalibrate(chip); | |
743 | #ifdef PMAC_AMP_AVAIL | |
744 | if (chip->mixer_data) { | |
65b29f50 | 745 | struct awacs_amp *amp = chip->mixer_data; |
1da177e4 LT |
746 | awacs_amp_set_vol(amp, 0, amp->amp_vol[0][0], amp->amp_vol[0][1], 0); |
747 | awacs_amp_set_vol(amp, 1, amp->amp_vol[1][0], amp->amp_vol[1][1], 0); | |
748 | awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]); | |
749 | awacs_amp_set_master(amp, amp->amp_master); | |
750 | } | |
751 | #endif | |
752 | } | |
8c870933 | 753 | #endif /* CONFIG_PM */ |
1da177e4 | 754 | |
a8c2a6bf RS |
755 | #define IS_PM7500 (machine_is_compatible("AAPL,7500")) |
756 | #define IS_BEIGE (machine_is_compatible("AAPL,Gossamer")) | |
757 | #define IS_IMAC (machine_is_compatible("PowerMac2,1") \ | |
758 | || machine_is_compatible("PowerMac2,2") \ | |
759 | || machine_is_compatible("PowerMac4,1")) | |
760 | ||
761 | static int imac; | |
762 | ||
1da177e4 LT |
763 | #ifdef PMAC_SUPPORT_AUTOMUTE |
764 | /* | |
765 | * auto-mute stuffs | |
766 | */ | |
65b29f50 | 767 | static int snd_pmac_awacs_detect_headphone(struct snd_pmac *chip) |
1da177e4 LT |
768 | { |
769 | return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0; | |
770 | } | |
771 | ||
772 | #ifdef PMAC_AMP_AVAIL | |
65b29f50 | 773 | static int toggle_amp_mute(struct awacs_amp *amp, int index, int mute) |
1da177e4 LT |
774 | { |
775 | int vol[2]; | |
776 | vol[0] = amp->amp_vol[index][0] & 31; | |
777 | vol[1] = amp->amp_vol[index][1] & 31; | |
778 | if (mute) { | |
779 | vol[0] |= 32; | |
780 | vol[1] |= 32; | |
781 | } | |
782 | return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1); | |
783 | } | |
784 | #endif | |
785 | ||
65b29f50 | 786 | static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify) |
1da177e4 LT |
787 | { |
788 | if (chip->auto_mute) { | |
789 | #ifdef PMAC_AMP_AVAIL | |
790 | if (chip->mixer_data) { | |
65b29f50 | 791 | struct awacs_amp *amp = chip->mixer_data; |
1da177e4 LT |
792 | int changed; |
793 | if (snd_pmac_awacs_detect_headphone(chip)) { | |
794 | changed = toggle_amp_mute(amp, AMP_CH_HD, 0); | |
795 | changed |= toggle_amp_mute(amp, AMP_CH_SPK, 1); | |
796 | } else { | |
797 | changed = toggle_amp_mute(amp, AMP_CH_HD, 1); | |
798 | changed |= toggle_amp_mute(amp, AMP_CH_SPK, 0); | |
799 | } | |
800 | if (do_notify && ! changed) | |
801 | return; | |
802 | } else | |
803 | #endif | |
804 | { | |
a8c2a6bf RS |
805 | int reg = chip->awacs_reg[1] |
806 | | (MASK_HDMUTE | MASK_SPKMUTE); | |
807 | if (imac) { | |
808 | reg &= ~MASK_SPKMUTE; | |
809 | reg &= ~MASK_PAROUT1; | |
810 | } | |
1da177e4 LT |
811 | if (snd_pmac_awacs_detect_headphone(chip)) |
812 | reg &= ~MASK_HDMUTE; | |
a8c2a6bf RS |
813 | else if (imac) |
814 | reg |= MASK_PAROUT1; | |
1da177e4 LT |
815 | else |
816 | reg &= ~MASK_SPKMUTE; | |
817 | if (do_notify && reg == chip->awacs_reg[1]) | |
818 | return; | |
819 | snd_pmac_awacs_write_reg(chip, 1, reg); | |
820 | } | |
821 | if (do_notify) { | |
822 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, | |
823 | &chip->master_sw_ctl->id); | |
824 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, | |
825 | &chip->speaker_sw_ctl->id); | |
826 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, | |
827 | &chip->hp_detect_ctl->id); | |
828 | } | |
829 | } | |
830 | } | |
831 | #endif /* PMAC_SUPPORT_AUTOMUTE */ | |
832 | ||
833 | ||
834 | /* | |
835 | * initialize chip | |
836 | */ | |
837 | int __init | |
65b29f50 | 838 | snd_pmac_awacs_init(struct snd_pmac *chip) |
1da177e4 | 839 | { |
a8c2a6bf RS |
840 | int pm7500 = IS_PM7500; |
841 | int beige = IS_BEIGE; | |
1da177e4 LT |
842 | int err, vol; |
843 | ||
a8c2a6bf | 844 | imac = IS_IMAC; |
1da177e4 LT |
845 | /* looks like MASK_GAINLINE triggers something, so we set here |
846 | * as start-up | |
847 | */ | |
848 | chip->awacs_reg[0] = MASK_MUX_CD | 0xff | MASK_GAINLINE; | |
849 | chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE; | |
850 | /* FIXME: Only machines with external SRS module need MASK_PAROUT */ | |
851 | if (chip->has_iic || chip->device_id == 0x5 || | |
852 | /*chip->_device_id == 0x8 || */ | |
853 | chip->device_id == 0xb) | |
854 | chip->awacs_reg[1] |= MASK_PAROUT; | |
855 | /* get default volume from nvram */ | |
856 | // vol = (~nvram_read_byte(0x1308) & 7) << 1; | |
857 | // vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 ); | |
858 | vol = 0x0f; /* no, on alsa, muted as default */ | |
859 | vol = vol + (vol << 6); | |
860 | chip->awacs_reg[2] = vol; | |
861 | chip->awacs_reg[4] = vol; | |
862 | if (chip->model == PMAC_SCREAMER) { | |
863 | chip->awacs_reg[5] = vol; /* FIXME: screamer has loopthru vol control */ | |
864 | chip->awacs_reg[6] = MASK_MIC_BOOST; /* FIXME: maybe should be vol << 3 for PCMCIA speaker */ | |
865 | chip->awacs_reg[7] = 0; | |
866 | } | |
867 | ||
868 | awacs_restore_all_regs(chip); | |
869 | chip->manufacturer = (in_le32(&chip->awacs->codec_stat) >> 8) & 0xf; | |
870 | screamer_recalibrate(chip); | |
871 | ||
872 | chip->revision = (in_le32(&chip->awacs->codec_stat) >> 12) & 0xf; | |
873 | #ifdef PMAC_AMP_AVAIL | |
874 | if (chip->revision == 3 && chip->has_iic && CHECK_CUDA_AMP()) { | |
59feddb2 | 875 | struct awacs_amp *amp = kzalloc(sizeof(*amp), GFP_KERNEL); |
1da177e4 LT |
876 | if (! amp) |
877 | return -ENOMEM; | |
878 | chip->mixer_data = amp; | |
1da177e4 LT |
879 | chip->mixer_free = awacs_amp_free; |
880 | awacs_amp_set_vol(amp, 0, 63, 63, 0); /* mute and zero vol */ | |
881 | awacs_amp_set_vol(amp, 1, 63, 63, 0); | |
882 | awacs_amp_set_tone(amp, 7, 7); /* 0 dB */ | |
883 | awacs_amp_set_master(amp, 79); /* 0 dB */ | |
884 | } | |
885 | #endif /* PMAC_AMP_AVAIL */ | |
886 | ||
887 | if (chip->hp_stat_mask == 0) { | |
888 | /* set headphone-jack detection bit */ | |
889 | switch (chip->model) { | |
890 | case PMAC_AWACS: | |
a8c2a6bf RS |
891 | chip->hp_stat_mask = pm7500 ? MASK_HDPCONN |
892 | : MASK_LOCONN; | |
1da177e4 LT |
893 | break; |
894 | case PMAC_SCREAMER: | |
895 | switch (chip->device_id) { | |
896 | case 0x08: | |
a8c2a6bf RS |
897 | case 0x0B: |
898 | chip->hp_stat_mask = imac | |
899 | ? MASK_LOCONN_IMAC | | |
900 | MASK_HDPLCONN_IMAC | | |
901 | MASK_HDPRCONN_IMAC | |
902 | : MASK_HDPCONN; | |
1da177e4 LT |
903 | break; |
904 | case 0x00: | |
905 | case 0x05: | |
a8c2a6bf | 906 | chip->hp_stat_mask = MASK_LOCONN; |
1da177e4 LT |
907 | break; |
908 | default: | |
a8c2a6bf | 909 | chip->hp_stat_mask = MASK_HDPCONN; |
1da177e4 LT |
910 | break; |
911 | } | |
912 | break; | |
913 | default: | |
914 | snd_BUG(); | |
915 | break; | |
916 | } | |
917 | } | |
918 | ||
919 | /* | |
920 | * build mixers | |
921 | */ | |
922 | strcpy(chip->card->mixername, "PowerMac AWACS"); | |
923 | ||
924 | if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers), | |
925 | snd_pmac_awacs_mixers)) < 0) | |
926 | return err; | |
a8c2a6bf RS |
927 | if (beige) |
928 | ; | |
929 | else if (chip->model == PMAC_SCREAMER) | |
1da177e4 LT |
930 | err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2), |
931 | snd_pmac_screamer_mixers2); | |
a8c2a6bf | 932 | else if (!pm7500) |
1da177e4 LT |
933 | err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2), |
934 | snd_pmac_awacs_mixers2); | |
935 | if (err < 0) | |
936 | return err; | |
a8c2a6bf RS |
937 | if (pm7500) |
938 | err = build_mixers(chip, | |
939 | ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500), | |
940 | snd_pmac_awacs_mixers_pmac7500); | |
941 | else if (beige) | |
942 | err = build_mixers(chip, | |
943 | ARRAY_SIZE(snd_pmac_screamer_mixers_beige), | |
944 | snd_pmac_screamer_mixers_beige); | |
945 | else if (imac) | |
946 | err = build_mixers(chip, | |
947 | ARRAY_SIZE(snd_pmac_screamer_mixers_imac), | |
948 | snd_pmac_screamer_mixers_imac); | |
949 | else | |
950 | err = build_mixers(chip, | |
951 | ARRAY_SIZE(snd_pmac_awacs_mixers_pmac), | |
952 | snd_pmac_awacs_mixers_pmac); | |
953 | if (err < 0) | |
954 | return err; | |
955 | chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac) | |
956 | ? &snd_pmac_awacs_master_sw_imac | |
957 | : &snd_pmac_awacs_master_sw, chip); | |
1da177e4 LT |
958 | if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0) |
959 | return err; | |
960 | #ifdef PMAC_AMP_AVAIL | |
961 | if (chip->mixer_data) { | |
962 | /* use amplifier. the signal is connected from route A | |
963 | * to the amp. the amp has its headphone and speaker | |
964 | * volumes and mute switches, so we use them instead of | |
965 | * screamer registers. | |
966 | * in this case, it seems the route C is not used. | |
967 | */ | |
968 | if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol), | |
969 | snd_pmac_awacs_amp_vol)) < 0) | |
970 | return err; | |
971 | /* overwrite */ | |
972 | chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw, chip); | |
973 | if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0) | |
974 | return err; | |
975 | chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw, chip); | |
976 | if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0) | |
977 | return err; | |
978 | } else | |
979 | #endif /* PMAC_AMP_AVAIL */ | |
980 | { | |
981 | /* route A = headphone, route C = speaker */ | |
982 | if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol), | |
983 | snd_pmac_awacs_speaker_vol)) < 0) | |
984 | return err; | |
a8c2a6bf RS |
985 | chip->speaker_sw_ctl = snd_ctl_new1(imac |
986 | ? &snd_pmac_awacs_speaker_sw_imac | |
987 | : &snd_pmac_awacs_speaker_sw, chip); | |
1da177e4 LT |
988 | if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0) |
989 | return err; | |
990 | } | |
991 | ||
a8c2a6bf RS |
992 | if (beige) |
993 | err = build_mixers(chip, | |
994 | ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige), | |
995 | snd_pmac_screamer_mic_boost_beige); | |
996 | else if (imac) | |
997 | err = build_mixers(chip, | |
998 | ARRAY_SIZE(snd_pmac_screamer_mic_boost_imac), | |
999 | snd_pmac_screamer_mic_boost_imac); | |
1000 | else if (chip->model == PMAC_SCREAMER) | |
1001 | err = build_mixers(chip, | |
1002 | ARRAY_SIZE(snd_pmac_screamer_mic_boost), | |
1003 | snd_pmac_screamer_mic_boost); | |
1004 | else if (pm7500) | |
1005 | err = build_mixers(chip, | |
1006 | ARRAY_SIZE(snd_pmac_awacs_mic_boost_pmac7500), | |
1007 | snd_pmac_awacs_mic_boost_pmac7500); | |
1008 | else | |
1009 | err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost), | |
1010 | snd_pmac_awacs_mic_boost); | |
1011 | if (err < 0) | |
1012 | return err; | |
1da177e4 LT |
1013 | |
1014 | /* | |
1015 | * set lowlevel callbacks | |
1016 | */ | |
1017 | chip->set_format = snd_pmac_awacs_set_format; | |
8c870933 | 1018 | #ifdef CONFIG_PM |
1da177e4 LT |
1019 | chip->suspend = snd_pmac_awacs_suspend; |
1020 | chip->resume = snd_pmac_awacs_resume; | |
1021 | #endif | |
1022 | #ifdef PMAC_SUPPORT_AUTOMUTE | |
1023 | if ((err = snd_pmac_add_automute(chip)) < 0) | |
1024 | return err; | |
1025 | chip->detect_headphone = snd_pmac_awacs_detect_headphone; | |
1026 | chip->update_automute = snd_pmac_awacs_update_automute; | |
1027 | snd_pmac_awacs_update_automute(chip, 0); /* update the status only */ | |
1028 | #endif | |
1029 | if (chip->model == PMAC_SCREAMER) { | |
1030 | snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]); | |
1031 | snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]); | |
1032 | } | |
1033 | ||
1034 | return 0; | |
1035 | } |