2 * PMac AWACS lowlevel functions
4 * Copyright (c) by Takashi Iwai <tiwai@suse.de>
5 * code based on dmasound.c.
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.
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.
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
23 #include <sound/driver.h>
25 #include <asm/nvram.h>
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <sound/core.h>
35 #ifdef CONFIG_ADB_CUDA
36 #define PMAC_AMP_AVAIL
40 typedef struct awacs_amp {
41 unsigned char amp_master;
42 unsigned char amp_vol[2][2];
43 unsigned char amp_tone[2];
46 #define CHECK_CUDA_AMP() (sys_ctrler == SYS_CTRLER_CUDA)
48 #endif /* PMAC_AMP_AVAIL */
51 static void snd_pmac_screamer_wait(pmac_t *chip)
54 while (!(in_le32(&chip->awacs->codec_stat) & MASK_VALID)) {
57 snd_printd("snd_pmac_screamer_wait timeout\n");
64 * write AWACS register
67 snd_pmac_awacs_write(pmac_t *chip, int val)
69 long timeout = 5000000;
71 if (chip->model == PMAC_SCREAMER)
72 snd_pmac_screamer_wait(chip);
73 out_le32(&chip->awacs->codec_ctrl, val | (chip->subframe << 22));
74 while (in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) {
76 snd_printd("snd_pmac_awacs_write timeout\n");
83 snd_pmac_awacs_write_reg(pmac_t *chip, int reg, int val)
85 snd_pmac_awacs_write(chip, val | (reg << 12));
86 chip->awacs_reg[reg] = val;
90 snd_pmac_awacs_write_noreg(pmac_t *chip, int reg, int val)
92 snd_pmac_awacs_write(chip, val | (reg << 12));
95 #ifdef CONFIG_PMAC_PBOOK
96 /* Recalibrate chip */
97 static void screamer_recalibrate(pmac_t *chip)
99 if (chip->model != PMAC_SCREAMER)
102 /* Sorry for the horrible delays... I hope to get that improved
103 * by making the whole PM process asynchronous in a future version
105 snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
106 if (chip->manufacturer == 0x1)
107 /* delay for broken crystal part */
109 snd_pmac_awacs_write_noreg(chip, 1,
110 chip->awacs_reg[1] | MASK_RECALIBRATE | MASK_CMUTE | MASK_AMUTE);
111 snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
112 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
116 #define screamer_recalibrate(chip) /* NOP */
121 * additional callback to set the pcm format
123 static void snd_pmac_awacs_set_format(pmac_t *chip)
125 chip->awacs_reg[1] &= ~MASK_SAMPLERATE;
126 chip->awacs_reg[1] |= chip->rate_index << 3;
127 snd_pmac_awacs_write_reg(chip, 1, chip->awacs_reg[1]);
132 * AWACS volume callbacks
135 * volumes: 0-15 stereo
137 static int snd_pmac_awacs_info_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
139 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
141 uinfo->value.integer.min = 0;
142 uinfo->value.integer.max = 15;
146 static int snd_pmac_awacs_get_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
148 pmac_t *chip = snd_kcontrol_chip(kcontrol);
149 int reg = kcontrol->private_value & 0xff;
150 int lshift = (kcontrol->private_value >> 8) & 0xff;
151 int inverted = (kcontrol->private_value >> 16) & 1;
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);
160 vol[0] = 0x0f - vol[0];
161 vol[1] = 0x0f - vol[1];
163 ucontrol->value.integer.value[0] = vol[0];
164 ucontrol->value.integer.value[1] = vol[1];
168 static int snd_pmac_awacs_put_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
170 pmac_t *chip = snd_kcontrol_chip(kcontrol);
171 int reg = kcontrol->private_value & 0xff;
172 int lshift = (kcontrol->private_value >> 8) & 0xff;
173 int inverted = (kcontrol->private_value >> 16) & 1;
178 vol[0] = ucontrol->value.integer.value[0];
179 vol[1] = ucontrol->value.integer.value[1];
181 vol[0] = 0x0f - vol[0];
182 vol[1] = 0x0f - vol[1];
186 spin_lock_irqsave(&chip->reg_lock, flags);
187 oldval = chip->awacs_reg[reg];
188 val = oldval & ~(0xf | (0xf << lshift));
189 val |= vol[0] << lshift;
192 snd_pmac_awacs_write_reg(chip, reg, val);
193 spin_unlock_irqrestore(&chip->reg_lock, flags);
194 return oldval != reg;
198 #define AWACS_VOLUME(xname, xreg, xshift, xinverted) \
199 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
200 .info = snd_pmac_awacs_info_volume, \
201 .get = snd_pmac_awacs_get_volume, \
202 .put = snd_pmac_awacs_put_volume, \
203 .private_value = (xreg) | ((xshift) << 8) | ((xinverted) << 16) }
206 * mute master/ogain for AWACS: mono
208 static int snd_pmac_awacs_get_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
210 pmac_t *chip = snd_kcontrol_chip(kcontrol);
211 int reg = kcontrol->private_value & 0xff;
212 int shift = (kcontrol->private_value >> 8) & 0xff;
213 int invert = (kcontrol->private_value >> 16) & 1;
217 spin_lock_irqsave(&chip->reg_lock, flags);
218 val = (chip->awacs_reg[reg] >> shift) & 1;
219 spin_unlock_irqrestore(&chip->reg_lock, flags);
222 ucontrol->value.integer.value[0] = val;
226 static int snd_pmac_awacs_put_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
228 pmac_t *chip = snd_kcontrol_chip(kcontrol);
229 int reg = kcontrol->private_value & 0xff;
230 int shift = (kcontrol->private_value >> 8) & 0xff;
231 int invert = (kcontrol->private_value >> 16) & 1;
232 int mask = 1 << shift;
236 spin_lock_irqsave(&chip->reg_lock, flags);
237 val = chip->awacs_reg[reg] & ~mask;
238 if (ucontrol->value.integer.value[0] != invert)
240 changed = chip->awacs_reg[reg] != val;
242 snd_pmac_awacs_write_reg(chip, reg, val);
243 spin_unlock_irqrestore(&chip->reg_lock, flags);
247 #define AWACS_SWITCH(xname, xreg, xshift, xinvert) \
248 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
249 .info = snd_pmac_boolean_mono_info, \
250 .get = snd_pmac_awacs_get_switch, \
251 .put = snd_pmac_awacs_put_switch, \
252 .private_value = (xreg) | ((xshift) << 8) | ((xinvert) << 16) }
255 #ifdef PMAC_AMP_AVAIL
257 * controls for perch/whisper extension cards, e.g. G3 desktop
259 * TDA7433 connected via i2c address 0x45 (= 0x8a),
260 * accessed through cuda
262 static void awacs_set_cuda(int reg, int val)
264 struct adb_request req;
265 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a, reg, val);
266 while (! req.complete)
271 * level = 0 - 14, 7 = 0 dB
273 static void awacs_amp_set_tone(awacs_amp_t *amp, int bass, int treble)
275 amp->amp_tone[0] = bass;
276 amp->amp_tone[1] = treble;
278 bass = (14 - bass) + 8;
280 treble = (14 - treble) + 8;
281 awacs_set_cuda(2, (bass << 4) | treble);
285 * vol = 0 - 31 (attenuation), 32 = mute bit, stereo
287 static int awacs_amp_set_vol(awacs_amp_t *amp, int index, int lvol, int rvol, int do_check)
289 if (do_check && amp->amp_vol[index][0] == lvol &&
290 amp->amp_vol[index][1] == rvol)
292 awacs_set_cuda(3 + index, lvol);
293 awacs_set_cuda(5 + index, rvol);
294 amp->amp_vol[index][0] = lvol;
295 amp->amp_vol[index][1] = rvol;
300 * 0 = -79 dB, 79 = 0 dB, 99 = +20 dB
302 static void awacs_amp_set_master(awacs_amp_t *amp, int vol)
304 amp->amp_master = vol;
306 vol = 32 + (79 - vol);
308 vol = 32 - (vol - 79);
309 awacs_set_cuda(1, vol);
312 static void awacs_amp_free(pmac_t *chip)
314 awacs_amp_t *amp = chip->mixer_data;
315 snd_assert(amp, return);
317 chip->mixer_data = NULL;
318 chip->mixer_free = NULL;
325 static int snd_pmac_awacs_info_volume_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
327 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
329 uinfo->value.integer.min = 0;
330 uinfo->value.integer.max = 31;
334 static int snd_pmac_awacs_get_volume_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
336 pmac_t *chip = snd_kcontrol_chip(kcontrol);
337 int index = kcontrol->private_value;
338 awacs_amp_t *amp = chip->mixer_data;
339 snd_assert(amp, return -EINVAL);
340 snd_assert(index >= 0 && index <= 1, return -EINVAL);
341 ucontrol->value.integer.value[0] = 31 - (amp->amp_vol[index][0] & 31);
342 ucontrol->value.integer.value[1] = 31 - (amp->amp_vol[index][1] & 31);
346 static int snd_pmac_awacs_put_volume_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
348 pmac_t *chip = snd_kcontrol_chip(kcontrol);
349 int index = kcontrol->private_value;
351 awacs_amp_t *amp = chip->mixer_data;
352 snd_assert(amp, return -EINVAL);
353 snd_assert(index >= 0 && index <= 1, return -EINVAL);
355 vol[0] = (31 - (ucontrol->value.integer.value[0] & 31)) | (amp->amp_vol[index][0] & 32);
356 vol[1] = (31 - (ucontrol->value.integer.value[1] & 31)) | (amp->amp_vol[index][1] & 32);
357 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
360 static int snd_pmac_awacs_get_switch_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
362 pmac_t *chip = snd_kcontrol_chip(kcontrol);
363 int index = kcontrol->private_value;
364 awacs_amp_t *amp = chip->mixer_data;
365 snd_assert(amp, return -EINVAL);
366 snd_assert(index >= 0 && index <= 1, return -EINVAL);
367 ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32) ? 0 : 1;
368 ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32) ? 0 : 1;
372 static int snd_pmac_awacs_put_switch_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
374 pmac_t *chip = snd_kcontrol_chip(kcontrol);
375 int index = kcontrol->private_value;
377 awacs_amp_t *amp = chip->mixer_data;
378 snd_assert(amp, return -EINVAL);
379 snd_assert(index >= 0 && index <= 1, return -EINVAL);
381 vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32) | (amp->amp_vol[index][0] & 31);
382 vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32) | (amp->amp_vol[index][1] & 31);
383 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
386 static int snd_pmac_awacs_info_tone_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
388 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
390 uinfo->value.integer.min = 0;
391 uinfo->value.integer.max = 14;
395 static int snd_pmac_awacs_get_tone_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
397 pmac_t *chip = snd_kcontrol_chip(kcontrol);
398 int index = kcontrol->private_value;
399 awacs_amp_t *amp = chip->mixer_data;
400 snd_assert(amp, return -EINVAL);
401 snd_assert(index >= 0 && index <= 1, return -EINVAL);
402 ucontrol->value.integer.value[0] = amp->amp_tone[index];
406 static int snd_pmac_awacs_put_tone_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
408 pmac_t *chip = snd_kcontrol_chip(kcontrol);
409 int index = kcontrol->private_value;
410 awacs_amp_t *amp = chip->mixer_data;
411 snd_assert(amp, return -EINVAL);
412 snd_assert(index >= 0 && index <= 1, return -EINVAL);
413 if (ucontrol->value.integer.value[0] != amp->amp_tone[index]) {
414 amp->amp_tone[index] = ucontrol->value.integer.value[0];
415 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
421 static int snd_pmac_awacs_info_master_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
423 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
425 uinfo->value.integer.min = 0;
426 uinfo->value.integer.max = 99;
430 static int snd_pmac_awacs_get_master_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
432 pmac_t *chip = snd_kcontrol_chip(kcontrol);
433 awacs_amp_t *amp = chip->mixer_data;
434 snd_assert(amp, return -EINVAL);
435 ucontrol->value.integer.value[0] = amp->amp_master;
439 static int snd_pmac_awacs_put_master_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
441 pmac_t *chip = snd_kcontrol_chip(kcontrol);
442 awacs_amp_t *amp = chip->mixer_data;
443 snd_assert(amp, return -EINVAL);
444 if (ucontrol->value.integer.value[0] != amp->amp_master) {
445 amp->amp_master = ucontrol->value.integer.value[0];
446 awacs_amp_set_master(amp, amp->amp_master);
455 static snd_kcontrol_new_t snd_pmac_awacs_amp_vol[] __initdata = {
456 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
457 .name = "PC Speaker Playback Volume",
458 .info = snd_pmac_awacs_info_volume_amp,
459 .get = snd_pmac_awacs_get_volume_amp,
460 .put = snd_pmac_awacs_put_volume_amp,
461 .private_value = AMP_CH_SPK,
463 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
464 .name = "Headphone Playback Volume",
465 .info = snd_pmac_awacs_info_volume_amp,
466 .get = snd_pmac_awacs_get_volume_amp,
467 .put = snd_pmac_awacs_put_volume_amp,
468 .private_value = AMP_CH_HD,
470 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
471 .name = "Tone Control - Bass",
472 .info = snd_pmac_awacs_info_tone_amp,
473 .get = snd_pmac_awacs_get_tone_amp,
474 .put = snd_pmac_awacs_put_tone_amp,
477 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
478 .name = "Tone Control - Treble",
479 .info = snd_pmac_awacs_info_tone_amp,
480 .get = snd_pmac_awacs_get_tone_amp,
481 .put = snd_pmac_awacs_put_tone_amp,
484 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
485 .name = "Amp Master Playback Volume",
486 .info = snd_pmac_awacs_info_master_amp,
487 .get = snd_pmac_awacs_get_master_amp,
488 .put = snd_pmac_awacs_put_master_amp,
492 static snd_kcontrol_new_t snd_pmac_awacs_amp_hp_sw __initdata = {
493 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
494 .name = "Headphone Playback Switch",
495 .info = snd_pmac_boolean_stereo_info,
496 .get = snd_pmac_awacs_get_switch_amp,
497 .put = snd_pmac_awacs_put_switch_amp,
498 .private_value = AMP_CH_HD,
501 static snd_kcontrol_new_t snd_pmac_awacs_amp_spk_sw __initdata = {
502 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
503 .name = "PC Speaker Playback Switch",
504 .info = snd_pmac_boolean_stereo_info,
505 .get = snd_pmac_awacs_get_switch_amp,
506 .put = snd_pmac_awacs_put_switch_amp,
507 .private_value = AMP_CH_SPK,
510 #endif /* PMAC_AMP_AVAIL */
514 * mic boost for screamer
516 static int snd_pmac_screamer_mic_boost_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
518 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
520 uinfo->value.integer.min = 0;
521 uinfo->value.integer.max = 2;
525 static int snd_pmac_screamer_mic_boost_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
527 pmac_t *chip = snd_kcontrol_chip(kcontrol);
531 spin_lock_irqsave(&chip->reg_lock, flags);
532 if (chip->awacs_reg[6] & MASK_MIC_BOOST)
534 else if (chip->awacs_reg[0] & MASK_GAINLINE)
538 spin_unlock_irqrestore(&chip->reg_lock, flags);
539 ucontrol->value.integer.value[0] = val;
543 static int snd_pmac_screamer_mic_boost_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
545 pmac_t *chip = snd_kcontrol_chip(kcontrol);
550 spin_lock_irqsave(&chip->reg_lock, flags);
551 val0 = chip->awacs_reg[0] & ~MASK_GAINLINE;
552 val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST;
553 if (ucontrol->value.integer.value[0] > 0) {
554 val0 |= MASK_GAINLINE;
555 if (ucontrol->value.integer.value[0] > 1)
556 val6 |= MASK_MIC_BOOST;
558 if (val0 != chip->awacs_reg[0]) {
559 snd_pmac_awacs_write_reg(chip, 0, val0);
562 if (val6 != chip->awacs_reg[6]) {
563 snd_pmac_awacs_write_reg(chip, 6, val6);
566 spin_unlock_irqrestore(&chip->reg_lock, flags);
571 * lists of mixer elements
573 static snd_kcontrol_new_t snd_pmac_awacs_mixers[] __initdata = {
574 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
575 AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0),
576 AWACS_VOLUME("Capture Volume", 0, 4, 0),
577 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_LINE, 0),
578 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
579 AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_MIC, 0),
582 static snd_kcontrol_new_t snd_pmac_awacs_master_sw __initdata =
583 AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1);
585 static snd_kcontrol_new_t snd_pmac_awacs_mic_boost[] __initdata = {
586 AWACS_SWITCH("Mic Boost", 0, SHIFT_GAINLINE, 0),
589 static snd_kcontrol_new_t snd_pmac_screamer_mic_boost[] __initdata = {
590 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
592 .info = snd_pmac_screamer_mic_boost_info,
593 .get = snd_pmac_screamer_mic_boost_get,
594 .put = snd_pmac_screamer_mic_boost_put,
598 static snd_kcontrol_new_t snd_pmac_awacs_speaker_vol[] __initdata = {
599 AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1),
601 static snd_kcontrol_new_t snd_pmac_awacs_speaker_sw __initdata =
602 AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);
605 #define num_controls(ary) (sizeof(ary) / sizeof(snd_kcontrol_new_t))
608 * add new mixer elements to the card
610 static int build_mixers(pmac_t *chip, int nums, snd_kcontrol_new_t *mixers)
614 for (i = 0; i < nums; i++) {
615 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip))) < 0)
623 * restore all registers
625 static void awacs_restore_all_regs(pmac_t *chip)
627 snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
628 snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
629 snd_pmac_awacs_write_noreg(chip, 2, chip->awacs_reg[2]);
630 snd_pmac_awacs_write_noreg(chip, 4, chip->awacs_reg[4]);
631 if (chip->model == PMAC_SCREAMER) {
632 snd_pmac_awacs_write_noreg(chip, 5, chip->awacs_reg[5]);
633 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
634 snd_pmac_awacs_write_noreg(chip, 7, chip->awacs_reg[7]);
638 #ifdef CONFIG_PMAC_PBOOK
639 static void snd_pmac_awacs_suspend(pmac_t *chip)
641 snd_pmac_awacs_write_noreg(chip, 1, (chip->awacs_reg[1]
642 | MASK_AMUTE | MASK_CMUTE));
645 static void snd_pmac_awacs_resume(pmac_t *chip)
647 if (machine_is_compatible("PowerBook3,1")
648 || machine_is_compatible("PowerBook3,2")) {
650 snd_pmac_awacs_write_reg(chip, 1,
651 chip->awacs_reg[1] & ~MASK_PAROUT);
655 awacs_restore_all_regs(chip);
656 if (chip->model == PMAC_SCREAMER) {
657 /* reset power bits in reg 6 */
659 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
661 screamer_recalibrate(chip);
662 #ifdef PMAC_AMP_AVAIL
663 if (chip->mixer_data) {
664 awacs_amp_t *amp = chip->mixer_data;
665 awacs_amp_set_vol(amp, 0, amp->amp_vol[0][0], amp->amp_vol[0][1], 0);
666 awacs_amp_set_vol(amp, 1, amp->amp_vol[1][0], amp->amp_vol[1][1], 0);
667 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
668 awacs_amp_set_master(amp, amp->amp_master);
672 #endif /* CONFIG_PMAC_PBOOK */
674 #ifdef PMAC_SUPPORT_AUTOMUTE
678 static int snd_pmac_awacs_detect_headphone(pmac_t *chip)
680 return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0;
683 #ifdef PMAC_AMP_AVAIL
684 static int toggle_amp_mute(awacs_amp_t *amp, int index, int mute)
687 vol[0] = amp->amp_vol[index][0] & 31;
688 vol[1] = amp->amp_vol[index][1] & 31;
693 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
697 static void snd_pmac_awacs_update_automute(pmac_t *chip, int do_notify)
699 if (chip->auto_mute) {
700 #ifdef PMAC_AMP_AVAIL
701 if (chip->mixer_data) {
702 awacs_amp_t *amp = chip->mixer_data;
704 if (snd_pmac_awacs_detect_headphone(chip)) {
705 changed = toggle_amp_mute(amp, AMP_CH_HD, 0);
706 changed |= toggle_amp_mute(amp, AMP_CH_SPK, 1);
708 changed = toggle_amp_mute(amp, AMP_CH_HD, 1);
709 changed |= toggle_amp_mute(amp, AMP_CH_SPK, 0);
711 if (do_notify && ! changed)
716 int reg = chip->awacs_reg[1] | (MASK_HDMUTE|MASK_SPKMUTE);
717 if (snd_pmac_awacs_detect_headphone(chip))
720 reg &= ~MASK_SPKMUTE;
721 if (do_notify && reg == chip->awacs_reg[1])
723 snd_pmac_awacs_write_reg(chip, 1, reg);
726 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
727 &chip->master_sw_ctl->id);
728 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
729 &chip->speaker_sw_ctl->id);
730 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
731 &chip->hp_detect_ctl->id);
735 #endif /* PMAC_SUPPORT_AUTOMUTE */
742 snd_pmac_awacs_init(pmac_t *chip)
746 /* looks like MASK_GAINLINE triggers something, so we set here
749 chip->awacs_reg[0] = MASK_MUX_CD | 0xff | MASK_GAINLINE;
750 chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE;
751 /* FIXME: Only machines with external SRS module need MASK_PAROUT */
752 if (chip->has_iic || chip->device_id == 0x5 ||
753 /*chip->_device_id == 0x8 || */
754 chip->device_id == 0xb)
755 chip->awacs_reg[1] |= MASK_PAROUT;
756 /* get default volume from nvram */
757 // vol = (~nvram_read_byte(0x1308) & 7) << 1;
758 // vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
759 vol = 0x0f; /* no, on alsa, muted as default */
760 vol = vol + (vol << 6);
761 chip->awacs_reg[2] = vol;
762 chip->awacs_reg[4] = vol;
763 if (chip->model == PMAC_SCREAMER) {
764 chip->awacs_reg[5] = vol; /* FIXME: screamer has loopthru vol control */
765 chip->awacs_reg[6] = MASK_MIC_BOOST; /* FIXME: maybe should be vol << 3 for PCMCIA speaker */
766 chip->awacs_reg[7] = 0;
769 awacs_restore_all_regs(chip);
770 chip->manufacturer = (in_le32(&chip->awacs->codec_stat) >> 8) & 0xf;
771 screamer_recalibrate(chip);
773 chip->revision = (in_le32(&chip->awacs->codec_stat) >> 12) & 0xf;
774 #ifdef PMAC_AMP_AVAIL
775 if (chip->revision == 3 && chip->has_iic && CHECK_CUDA_AMP()) {
776 awacs_amp_t *amp = kmalloc(sizeof(*amp), GFP_KERNEL);
779 chip->mixer_data = amp;
780 memset(amp, 0, sizeof(*amp));
781 chip->mixer_free = awacs_amp_free;
782 awacs_amp_set_vol(amp, 0, 63, 63, 0); /* mute and zero vol */
783 awacs_amp_set_vol(amp, 1, 63, 63, 0);
784 awacs_amp_set_tone(amp, 7, 7); /* 0 dB */
785 awacs_amp_set_master(amp, 79); /* 0 dB */
787 #endif /* PMAC_AMP_AVAIL */
789 if (chip->hp_stat_mask == 0) {
790 /* set headphone-jack detection bit */
791 switch (chip->model) {
793 chip->hp_stat_mask = 0x04;
796 switch (chip->device_id) {
798 /* 1 = side jack, 2 = front jack */
799 chip->hp_stat_mask = 0x03;
803 chip->hp_stat_mask = 0x04;
806 chip->hp_stat_mask = 0x08;
819 strcpy(chip->card->mixername, "PowerMac AWACS");
821 if ((err = build_mixers(chip, num_controls(snd_pmac_awacs_mixers),
822 snd_pmac_awacs_mixers)) < 0)
824 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_master_sw, chip);
825 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0)
827 #ifdef PMAC_AMP_AVAIL
828 if (chip->mixer_data) {
829 /* use amplifier. the signal is connected from route A
830 * to the amp. the amp has its headphone and speaker
831 * volumes and mute switches, so we use them instead of
832 * screamer registers.
833 * in this case, it seems the route C is not used.
835 if ((err = build_mixers(chip, num_controls(snd_pmac_awacs_amp_vol),
836 snd_pmac_awacs_amp_vol)) < 0)
839 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw, chip);
840 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0)
842 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw, chip);
843 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0)
846 #endif /* PMAC_AMP_AVAIL */
848 /* route A = headphone, route C = speaker */
849 if ((err = build_mixers(chip, num_controls(snd_pmac_awacs_speaker_vol),
850 snd_pmac_awacs_speaker_vol)) < 0)
852 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_speaker_sw, chip);
853 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0)
857 if (chip->model == PMAC_SCREAMER) {
858 if ((err = build_mixers(chip, num_controls(snd_pmac_screamer_mic_boost),
859 snd_pmac_screamer_mic_boost)) < 0)
862 if ((err = build_mixers(chip, num_controls(snd_pmac_awacs_mic_boost),
863 snd_pmac_awacs_mic_boost)) < 0)
868 * set lowlevel callbacks
870 chip->set_format = snd_pmac_awacs_set_format;
871 #ifdef CONFIG_PMAC_PBOOK
872 chip->suspend = snd_pmac_awacs_suspend;
873 chip->resume = snd_pmac_awacs_resume;
875 #ifdef PMAC_SUPPORT_AUTOMUTE
876 if ((err = snd_pmac_add_automute(chip)) < 0)
878 chip->detect_headphone = snd_pmac_awacs_detect_headphone;
879 chip->update_automute = snd_pmac_awacs_update_automute;
880 snd_pmac_awacs_update_automute(chip, 0); /* update the status only */
882 if (chip->model == PMAC_SCREAMER) {
883 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
884 snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);