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>
33 #ifdef CONFIG_ADB_CUDA
34 #define PMAC_AMP_AVAIL
39 unsigned char amp_master;
40 unsigned char amp_vol[2][2];
41 unsigned char amp_tone[2];
44 #define CHECK_CUDA_AMP() (sys_ctrler == SYS_CTRLER_CUDA)
46 #endif /* PMAC_AMP_AVAIL */
49 static void snd_pmac_screamer_wait(struct snd_pmac *chip)
52 while (!(in_le32(&chip->awacs->codec_stat) & MASK_VALID)) {
55 snd_printd("snd_pmac_screamer_wait timeout\n");
62 * write AWACS register
65 snd_pmac_awacs_write(struct snd_pmac *chip, int val)
67 long timeout = 5000000;
69 if (chip->model == PMAC_SCREAMER)
70 snd_pmac_screamer_wait(chip);
71 out_le32(&chip->awacs->codec_ctrl, val | (chip->subframe << 22));
72 while (in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) {
74 snd_printd("snd_pmac_awacs_write timeout\n");
81 snd_pmac_awacs_write_reg(struct snd_pmac *chip, int reg, int val)
83 snd_pmac_awacs_write(chip, val | (reg << 12));
84 chip->awacs_reg[reg] = val;
88 snd_pmac_awacs_write_noreg(struct snd_pmac *chip, int reg, int val)
90 snd_pmac_awacs_write(chip, val | (reg << 12));
94 /* Recalibrate chip */
95 static void screamer_recalibrate(struct snd_pmac *chip)
97 if (chip->model != PMAC_SCREAMER)
100 /* Sorry for the horrible delays... I hope to get that improved
101 * by making the whole PM process asynchronous in a future version
103 snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
104 if (chip->manufacturer == 0x1)
105 /* delay for broken crystal part */
107 snd_pmac_awacs_write_noreg(chip, 1,
108 chip->awacs_reg[1] | MASK_RECALIBRATE |
109 MASK_CMUTE | MASK_AMUTE);
110 snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
111 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
115 #define screamer_recalibrate(chip) /* NOP */
120 * additional callback to set the pcm format
122 static void snd_pmac_awacs_set_format(struct snd_pmac *chip)
124 chip->awacs_reg[1] &= ~MASK_SAMPLERATE;
125 chip->awacs_reg[1] |= chip->rate_index << 3;
126 snd_pmac_awacs_write_reg(chip, 1, chip->awacs_reg[1]);
131 * AWACS volume callbacks
134 * volumes: 0-15 stereo
136 static int snd_pmac_awacs_info_volume(struct snd_kcontrol *kcontrol,
137 struct snd_ctl_elem_info *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(struct snd_kcontrol *kcontrol,
147 struct snd_ctl_elem_value *ucontrol)
149 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
150 int reg = kcontrol->private_value & 0xff;
151 int lshift = (kcontrol->private_value >> 8) & 0xff;
152 int inverted = (kcontrol->private_value >> 16) & 1;
156 spin_lock_irqsave(&chip->reg_lock, flags);
157 vol[0] = (chip->awacs_reg[reg] >> lshift) & 0xf;
158 vol[1] = chip->awacs_reg[reg] & 0xf;
159 spin_unlock_irqrestore(&chip->reg_lock, flags);
161 vol[0] = 0x0f - vol[0];
162 vol[1] = 0x0f - vol[1];
164 ucontrol->value.integer.value[0] = vol[0];
165 ucontrol->value.integer.value[1] = vol[1];
169 static int snd_pmac_awacs_put_volume(struct snd_kcontrol *kcontrol,
170 struct snd_ctl_elem_value *ucontrol)
172 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
173 int reg = kcontrol->private_value & 0xff;
174 int lshift = (kcontrol->private_value >> 8) & 0xff;
175 int inverted = (kcontrol->private_value >> 16) & 1;
180 vol[0] = ucontrol->value.integer.value[0];
181 vol[1] = ucontrol->value.integer.value[1];
182 if (vol[0] > 0x0f || vol[1] > 0x0f)
185 vol[0] = 0x0f - vol[0];
186 vol[1] = 0x0f - vol[1];
190 spin_lock_irqsave(&chip->reg_lock, flags);
191 oldval = chip->awacs_reg[reg];
192 val = oldval & ~(0xf | (0xf << lshift));
193 val |= vol[0] << lshift;
196 snd_pmac_awacs_write_reg(chip, reg, val);
197 spin_unlock_irqrestore(&chip->reg_lock, flags);
198 return oldval != reg;
202 #define AWACS_VOLUME(xname, xreg, xshift, xinverted) \
203 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
204 .info = snd_pmac_awacs_info_volume, \
205 .get = snd_pmac_awacs_get_volume, \
206 .put = snd_pmac_awacs_put_volume, \
207 .private_value = (xreg) | ((xshift) << 8) | ((xinverted) << 16) }
210 * mute master/ogain for AWACS: mono
212 static int snd_pmac_awacs_get_switch(struct snd_kcontrol *kcontrol,
213 struct snd_ctl_elem_value *ucontrol)
215 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
216 int reg = kcontrol->private_value & 0xff;
217 int shift = (kcontrol->private_value >> 8) & 0xff;
218 int invert = (kcontrol->private_value >> 16) & 1;
222 spin_lock_irqsave(&chip->reg_lock, flags);
223 val = (chip->awacs_reg[reg] >> shift) & 1;
224 spin_unlock_irqrestore(&chip->reg_lock, flags);
227 ucontrol->value.integer.value[0] = val;
231 static int snd_pmac_awacs_put_switch(struct snd_kcontrol *kcontrol,
232 struct snd_ctl_elem_value *ucontrol)
234 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
235 int reg = kcontrol->private_value & 0xff;
236 int shift = (kcontrol->private_value >> 8) & 0xff;
237 int invert = (kcontrol->private_value >> 16) & 1;
238 int mask = 1 << shift;
242 spin_lock_irqsave(&chip->reg_lock, flags);
243 val = chip->awacs_reg[reg] & ~mask;
244 if (ucontrol->value.integer.value[0] != invert)
246 changed = chip->awacs_reg[reg] != val;
248 snd_pmac_awacs_write_reg(chip, reg, val);
249 spin_unlock_irqrestore(&chip->reg_lock, flags);
253 #define AWACS_SWITCH(xname, xreg, xshift, xinvert) \
254 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
255 .info = snd_pmac_boolean_mono_info, \
256 .get = snd_pmac_awacs_get_switch, \
257 .put = snd_pmac_awacs_put_switch, \
258 .private_value = (xreg) | ((xshift) << 8) | ((xinvert) << 16) }
261 #ifdef PMAC_AMP_AVAIL
263 * controls for perch/whisper extension cards, e.g. G3 desktop
265 * TDA7433 connected via i2c address 0x45 (= 0x8a),
266 * accessed through cuda
268 static void awacs_set_cuda(int reg, int val)
270 struct adb_request req;
271 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a, reg, val);
272 while (! req.complete)
277 * level = 0 - 14, 7 = 0 dB
279 static void awacs_amp_set_tone(struct awacs_amp *amp, int bass, int treble)
281 amp->amp_tone[0] = bass;
282 amp->amp_tone[1] = treble;
284 bass = (14 - bass) + 8;
286 treble = (14 - treble) + 8;
287 awacs_set_cuda(2, (bass << 4) | treble);
291 * vol = 0 - 31 (attenuation), 32 = mute bit, stereo
293 static int awacs_amp_set_vol(struct awacs_amp *amp, int index, int lvol, int rvol,
296 if (do_check && amp->amp_vol[index][0] == lvol &&
297 amp->amp_vol[index][1] == rvol)
299 awacs_set_cuda(3 + index, lvol);
300 awacs_set_cuda(5 + index, rvol);
301 amp->amp_vol[index][0] = lvol;
302 amp->amp_vol[index][1] = rvol;
307 * 0 = -79 dB, 79 = 0 dB, 99 = +20 dB
309 static void awacs_amp_set_master(struct awacs_amp *amp, int vol)
311 amp->amp_master = vol;
313 vol = 32 + (79 - vol);
315 vol = 32 - (vol - 79);
316 awacs_set_cuda(1, vol);
319 static void awacs_amp_free(struct snd_pmac *chip)
321 struct awacs_amp *amp = chip->mixer_data;
322 snd_assert(amp, return);
324 chip->mixer_data = NULL;
325 chip->mixer_free = NULL;
332 static int snd_pmac_awacs_info_volume_amp(struct snd_kcontrol *kcontrol,
333 struct snd_ctl_elem_info *uinfo)
335 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
337 uinfo->value.integer.min = 0;
338 uinfo->value.integer.max = 31;
342 static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol,
343 struct snd_ctl_elem_value *ucontrol)
345 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
346 int index = kcontrol->private_value;
347 struct awacs_amp *amp = chip->mixer_data;
348 snd_assert(amp, return -EINVAL);
349 snd_assert(index >= 0 && index <= 1, return -EINVAL);
350 ucontrol->value.integer.value[0] = 31 - (amp->amp_vol[index][0] & 31);
351 ucontrol->value.integer.value[1] = 31 - (amp->amp_vol[index][1] & 31);
355 static int snd_pmac_awacs_put_volume_amp(struct snd_kcontrol *kcontrol,
356 struct snd_ctl_elem_value *ucontrol)
358 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
359 int index = kcontrol->private_value;
361 struct awacs_amp *amp = chip->mixer_data;
362 snd_assert(amp, return -EINVAL);
363 snd_assert(index >= 0 && index <= 1, return -EINVAL);
365 vol[0] = (31 - (ucontrol->value.integer.value[0] & 31)) | (amp->amp_vol[index][0] & 32);
366 vol[1] = (31 - (ucontrol->value.integer.value[1] & 31)) | (amp->amp_vol[index][1] & 32);
367 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
370 static int snd_pmac_awacs_get_switch_amp(struct snd_kcontrol *kcontrol,
371 struct snd_ctl_elem_value *ucontrol)
373 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
374 int index = kcontrol->private_value;
375 struct awacs_amp *amp = chip->mixer_data;
376 snd_assert(amp, return -EINVAL);
377 snd_assert(index >= 0 && index <= 1, return -EINVAL);
378 ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32) ? 0 : 1;
379 ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32) ? 0 : 1;
383 static int snd_pmac_awacs_put_switch_amp(struct snd_kcontrol *kcontrol,
384 struct snd_ctl_elem_value *ucontrol)
386 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
387 int index = kcontrol->private_value;
389 struct awacs_amp *amp = chip->mixer_data;
390 snd_assert(amp, return -EINVAL);
391 snd_assert(index >= 0 && index <= 1, return -EINVAL);
393 vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32) | (amp->amp_vol[index][0] & 31);
394 vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32) | (amp->amp_vol[index][1] & 31);
395 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
398 static int snd_pmac_awacs_info_tone_amp(struct snd_kcontrol *kcontrol,
399 struct snd_ctl_elem_info *uinfo)
401 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
403 uinfo->value.integer.min = 0;
404 uinfo->value.integer.max = 14;
408 static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol,
409 struct snd_ctl_elem_value *ucontrol)
411 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
412 int index = kcontrol->private_value;
413 struct awacs_amp *amp = chip->mixer_data;
414 snd_assert(amp, return -EINVAL);
415 snd_assert(index >= 0 && index <= 1, return -EINVAL);
416 ucontrol->value.integer.value[0] = amp->amp_tone[index];
420 static int snd_pmac_awacs_put_tone_amp(struct snd_kcontrol *kcontrol,
421 struct snd_ctl_elem_value *ucontrol)
423 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
424 int index = kcontrol->private_value;
425 struct awacs_amp *amp = chip->mixer_data;
427 snd_assert(amp, return -EINVAL);
428 snd_assert(index >= 0 && index <= 1, return -EINVAL);
429 val = ucontrol->value.integer.value[0];
432 if (val != amp->amp_tone[index]) {
433 amp->amp_tone[index] = val;
434 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
440 static int snd_pmac_awacs_info_master_amp(struct snd_kcontrol *kcontrol,
441 struct snd_ctl_elem_info *uinfo)
443 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
445 uinfo->value.integer.min = 0;
446 uinfo->value.integer.max = 99;
450 static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol,
451 struct snd_ctl_elem_value *ucontrol)
453 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
454 struct awacs_amp *amp = chip->mixer_data;
455 snd_assert(amp, return -EINVAL);
456 ucontrol->value.integer.value[0] = amp->amp_master;
460 static int snd_pmac_awacs_put_master_amp(struct snd_kcontrol *kcontrol,
461 struct snd_ctl_elem_value *ucontrol)
463 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
464 struct awacs_amp *amp = chip->mixer_data;
466 snd_assert(amp, return -EINVAL);
467 val = ucontrol->value.integer.value[0];
470 if (val != amp->amp_master) {
471 amp->amp_master = val;
472 awacs_amp_set_master(amp, amp->amp_master);
481 static struct snd_kcontrol_new snd_pmac_awacs_amp_vol[] __initdata = {
482 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
483 .name = "PC Speaker Playback Volume",
484 .info = snd_pmac_awacs_info_volume_amp,
485 .get = snd_pmac_awacs_get_volume_amp,
486 .put = snd_pmac_awacs_put_volume_amp,
487 .private_value = AMP_CH_SPK,
489 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
490 .name = "Headphone Playback Volume",
491 .info = snd_pmac_awacs_info_volume_amp,
492 .get = snd_pmac_awacs_get_volume_amp,
493 .put = snd_pmac_awacs_put_volume_amp,
494 .private_value = AMP_CH_HD,
496 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
497 .name = "Tone Control - Bass",
498 .info = snd_pmac_awacs_info_tone_amp,
499 .get = snd_pmac_awacs_get_tone_amp,
500 .put = snd_pmac_awacs_put_tone_amp,
503 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
504 .name = "Tone Control - Treble",
505 .info = snd_pmac_awacs_info_tone_amp,
506 .get = snd_pmac_awacs_get_tone_amp,
507 .put = snd_pmac_awacs_put_tone_amp,
510 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
511 .name = "Amp Master Playback Volume",
512 .info = snd_pmac_awacs_info_master_amp,
513 .get = snd_pmac_awacs_get_master_amp,
514 .put = snd_pmac_awacs_put_master_amp,
518 static struct snd_kcontrol_new snd_pmac_awacs_amp_hp_sw __initdata = {
519 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
520 .name = "Headphone Playback Switch",
521 .info = snd_pmac_boolean_stereo_info,
522 .get = snd_pmac_awacs_get_switch_amp,
523 .put = snd_pmac_awacs_put_switch_amp,
524 .private_value = AMP_CH_HD,
527 static struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw __initdata = {
528 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
529 .name = "PC Speaker Playback Switch",
530 .info = snd_pmac_boolean_stereo_info,
531 .get = snd_pmac_awacs_get_switch_amp,
532 .put = snd_pmac_awacs_put_switch_amp,
533 .private_value = AMP_CH_SPK,
536 #endif /* PMAC_AMP_AVAIL */
540 * mic boost for screamer
542 static int snd_pmac_screamer_mic_boost_info(struct snd_kcontrol *kcontrol,
543 struct snd_ctl_elem_info *uinfo)
545 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
547 uinfo->value.integer.min = 0;
548 uinfo->value.integer.max = 2;
552 static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol *kcontrol,
553 struct snd_ctl_elem_value *ucontrol)
555 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
559 spin_lock_irqsave(&chip->reg_lock, flags);
560 if (chip->awacs_reg[6] & MASK_MIC_BOOST)
562 else if (chip->awacs_reg[0] & MASK_GAINLINE)
566 spin_unlock_irqrestore(&chip->reg_lock, flags);
567 ucontrol->value.integer.value[0] = val;
571 static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
572 struct snd_ctl_elem_value *ucontrol)
574 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
579 spin_lock_irqsave(&chip->reg_lock, flags);
580 val0 = chip->awacs_reg[0] & ~MASK_GAINLINE;
581 val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST;
582 if (ucontrol->value.integer.value[0] > 0) {
583 val0 |= MASK_GAINLINE;
584 if (ucontrol->value.integer.value[0] > 1)
585 val6 |= MASK_MIC_BOOST;
587 if (val0 != chip->awacs_reg[0]) {
588 snd_pmac_awacs_write_reg(chip, 0, val0);
591 if (val6 != chip->awacs_reg[6]) {
592 snd_pmac_awacs_write_reg(chip, 6, val6);
595 spin_unlock_irqrestore(&chip->reg_lock, flags);
600 * lists of mixer elements
602 static struct snd_kcontrol_new snd_pmac_awacs_mixers[] __initdata = {
603 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
604 AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0),
605 AWACS_VOLUME("Capture Volume", 0, 4, 0),
606 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
609 /* FIXME: is this correct order?
610 * screamer (powerbook G3 pismo) seems to have different bits...
612 static struct snd_kcontrol_new snd_pmac_awacs_mixers2[] __initdata = {
613 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_LINE, 0),
614 AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_MIC, 0),
617 static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] __initdata = {
618 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
619 AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_LINE, 0),
622 static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata =
623 AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1);
625 static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = {
626 AWACS_SWITCH("Mic Boost", 0, SHIFT_GAINLINE, 0),
629 static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __initdata = {
630 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
632 .info = snd_pmac_screamer_mic_boost_info,
633 .get = snd_pmac_screamer_mic_boost_get,
634 .put = snd_pmac_screamer_mic_boost_put,
638 static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __initdata = {
639 AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1),
641 static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata =
642 AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);
646 * add new mixer elements to the card
648 static int build_mixers(struct snd_pmac *chip, int nums, struct snd_kcontrol_new *mixers)
652 for (i = 0; i < nums; i++) {
653 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip))) < 0)
661 * restore all registers
663 static void awacs_restore_all_regs(struct snd_pmac *chip)
665 snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
666 snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
667 snd_pmac_awacs_write_noreg(chip, 2, chip->awacs_reg[2]);
668 snd_pmac_awacs_write_noreg(chip, 4, chip->awacs_reg[4]);
669 if (chip->model == PMAC_SCREAMER) {
670 snd_pmac_awacs_write_noreg(chip, 5, chip->awacs_reg[5]);
671 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
672 snd_pmac_awacs_write_noreg(chip, 7, chip->awacs_reg[7]);
677 static void snd_pmac_awacs_suspend(struct snd_pmac *chip)
679 snd_pmac_awacs_write_noreg(chip, 1, (chip->awacs_reg[1]
680 | MASK_AMUTE | MASK_CMUTE));
683 static void snd_pmac_awacs_resume(struct snd_pmac *chip)
685 if (machine_is_compatible("PowerBook3,1")
686 || machine_is_compatible("PowerBook3,2")) {
688 snd_pmac_awacs_write_reg(chip, 1,
689 chip->awacs_reg[1] & ~MASK_PAROUT);
693 awacs_restore_all_regs(chip);
694 if (chip->model == PMAC_SCREAMER) {
695 /* reset power bits in reg 6 */
697 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
699 screamer_recalibrate(chip);
700 #ifdef PMAC_AMP_AVAIL
701 if (chip->mixer_data) {
702 struct awacs_amp *amp = chip->mixer_data;
703 awacs_amp_set_vol(amp, 0, amp->amp_vol[0][0], amp->amp_vol[0][1], 0);
704 awacs_amp_set_vol(amp, 1, amp->amp_vol[1][0], amp->amp_vol[1][1], 0);
705 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
706 awacs_amp_set_master(amp, amp->amp_master);
710 #endif /* CONFIG_PM */
712 #ifdef PMAC_SUPPORT_AUTOMUTE
716 static int snd_pmac_awacs_detect_headphone(struct snd_pmac *chip)
718 return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0;
721 #ifdef PMAC_AMP_AVAIL
722 static int toggle_amp_mute(struct awacs_amp *amp, int index, int mute)
725 vol[0] = amp->amp_vol[index][0] & 31;
726 vol[1] = amp->amp_vol[index][1] & 31;
731 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
735 static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
737 if (chip->auto_mute) {
738 #ifdef PMAC_AMP_AVAIL
739 if (chip->mixer_data) {
740 struct awacs_amp *amp = chip->mixer_data;
742 if (snd_pmac_awacs_detect_headphone(chip)) {
743 changed = toggle_amp_mute(amp, AMP_CH_HD, 0);
744 changed |= toggle_amp_mute(amp, AMP_CH_SPK, 1);
746 changed = toggle_amp_mute(amp, AMP_CH_HD, 1);
747 changed |= toggle_amp_mute(amp, AMP_CH_SPK, 0);
749 if (do_notify && ! changed)
754 int reg = chip->awacs_reg[1] | (MASK_HDMUTE|MASK_SPKMUTE);
755 if (snd_pmac_awacs_detect_headphone(chip))
758 reg &= ~MASK_SPKMUTE;
759 if (do_notify && reg == chip->awacs_reg[1])
761 snd_pmac_awacs_write_reg(chip, 1, reg);
764 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
765 &chip->master_sw_ctl->id);
766 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
767 &chip->speaker_sw_ctl->id);
768 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
769 &chip->hp_detect_ctl->id);
773 #endif /* PMAC_SUPPORT_AUTOMUTE */
780 snd_pmac_awacs_init(struct snd_pmac *chip)
784 /* looks like MASK_GAINLINE triggers something, so we set here
787 chip->awacs_reg[0] = MASK_MUX_CD | 0xff | MASK_GAINLINE;
788 chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE;
789 /* FIXME: Only machines with external SRS module need MASK_PAROUT */
790 if (chip->has_iic || chip->device_id == 0x5 ||
791 /*chip->_device_id == 0x8 || */
792 chip->device_id == 0xb)
793 chip->awacs_reg[1] |= MASK_PAROUT;
794 /* get default volume from nvram */
795 // vol = (~nvram_read_byte(0x1308) & 7) << 1;
796 // vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
797 vol = 0x0f; /* no, on alsa, muted as default */
798 vol = vol + (vol << 6);
799 chip->awacs_reg[2] = vol;
800 chip->awacs_reg[4] = vol;
801 if (chip->model == PMAC_SCREAMER) {
802 chip->awacs_reg[5] = vol; /* FIXME: screamer has loopthru vol control */
803 chip->awacs_reg[6] = MASK_MIC_BOOST; /* FIXME: maybe should be vol << 3 for PCMCIA speaker */
804 chip->awacs_reg[7] = 0;
807 awacs_restore_all_regs(chip);
808 chip->manufacturer = (in_le32(&chip->awacs->codec_stat) >> 8) & 0xf;
809 screamer_recalibrate(chip);
811 chip->revision = (in_le32(&chip->awacs->codec_stat) >> 12) & 0xf;
812 #ifdef PMAC_AMP_AVAIL
813 if (chip->revision == 3 && chip->has_iic && CHECK_CUDA_AMP()) {
814 struct awacs_amp *amp = kzalloc(sizeof(*amp), GFP_KERNEL);
817 chip->mixer_data = amp;
818 chip->mixer_free = awacs_amp_free;
819 awacs_amp_set_vol(amp, 0, 63, 63, 0); /* mute and zero vol */
820 awacs_amp_set_vol(amp, 1, 63, 63, 0);
821 awacs_amp_set_tone(amp, 7, 7); /* 0 dB */
822 awacs_amp_set_master(amp, 79); /* 0 dB */
824 #endif /* PMAC_AMP_AVAIL */
826 if (chip->hp_stat_mask == 0) {
827 /* set headphone-jack detection bit */
828 switch (chip->model) {
830 chip->hp_stat_mask = 0x04;
833 switch (chip->device_id) {
835 /* 1 = side jack, 2 = front jack */
836 chip->hp_stat_mask = 0x03;
840 chip->hp_stat_mask = 0x04;
843 chip->hp_stat_mask = 0x08;
856 strcpy(chip->card->mixername, "PowerMac AWACS");
858 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers),
859 snd_pmac_awacs_mixers)) < 0)
861 if (chip->model == PMAC_SCREAMER)
862 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2),
863 snd_pmac_screamer_mixers2);
865 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2),
866 snd_pmac_awacs_mixers2);
869 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_master_sw, chip);
870 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0)
872 #ifdef PMAC_AMP_AVAIL
873 if (chip->mixer_data) {
874 /* use amplifier. the signal is connected from route A
875 * to the amp. the amp has its headphone and speaker
876 * volumes and mute switches, so we use them instead of
877 * screamer registers.
878 * in this case, it seems the route C is not used.
880 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol),
881 snd_pmac_awacs_amp_vol)) < 0)
884 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw, chip);
885 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0)
887 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw, chip);
888 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0)
891 #endif /* PMAC_AMP_AVAIL */
893 /* route A = headphone, route C = speaker */
894 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol),
895 snd_pmac_awacs_speaker_vol)) < 0)
897 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_speaker_sw, chip);
898 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0)
902 if (chip->model == PMAC_SCREAMER) {
903 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mic_boost),
904 snd_pmac_screamer_mic_boost)) < 0)
907 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost),
908 snd_pmac_awacs_mic_boost)) < 0)
913 * set lowlevel callbacks
915 chip->set_format = snd_pmac_awacs_set_format;
917 chip->suspend = snd_pmac_awacs_suspend;
918 chip->resume = snd_pmac_awacs_resume;
920 #ifdef PMAC_SUPPORT_AUTOMUTE
921 if ((err = snd_pmac_add_automute(chip)) < 0)
923 chip->detect_headphone = snd_pmac_awacs_detect_headphone;
924 chip->update_automute = snd_pmac_awacs_update_automute;
925 snd_pmac_awacs_update_automute(chip, 0); /* update the status only */
927 if (chip->model == PMAC_SCREAMER) {
928 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
929 snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);