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
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>
32 #ifdef CONFIG_ADB_CUDA
33 #define PMAC_AMP_AVAIL
38 unsigned char amp_master;
39 unsigned char amp_vol[2][2];
40 unsigned char amp_tone[2];
43 #define CHECK_CUDA_AMP() (sys_ctrler == SYS_CTRLER_CUDA)
45 #endif /* PMAC_AMP_AVAIL */
48 static void snd_pmac_screamer_wait(struct snd_pmac *chip)
51 while (!(in_le32(&chip->awacs->codec_stat) & MASK_VALID)) {
54 snd_printd("snd_pmac_screamer_wait timeout\n");
61 * write AWACS register
64 snd_pmac_awacs_write(struct snd_pmac *chip, int val)
66 long timeout = 5000000;
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) {
73 snd_printd("snd_pmac_awacs_write timeout\n");
80 snd_pmac_awacs_write_reg(struct snd_pmac *chip, int reg, int val)
82 snd_pmac_awacs_write(chip, val | (reg << 12));
83 chip->awacs_reg[reg] = val;
87 snd_pmac_awacs_write_noreg(struct snd_pmac *chip, int reg, int val)
89 snd_pmac_awacs_write(chip, val | (reg << 12));
93 /* Recalibrate chip */
94 static void screamer_recalibrate(struct snd_pmac *chip)
96 if (chip->model != PMAC_SCREAMER)
99 /* Sorry for the horrible delays... I hope to get that improved
100 * by making the whole PM process asynchronous in a future version
102 snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
103 if (chip->manufacturer == 0x1)
104 /* delay for broken crystal part */
106 snd_pmac_awacs_write_noreg(chip, 1,
107 chip->awacs_reg[1] | MASK_RECALIBRATE |
108 MASK_CMUTE | MASK_AMUTE);
109 snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
110 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
114 #define screamer_recalibrate(chip) /* NOP */
119 * additional callback to set the pcm format
121 static void snd_pmac_awacs_set_format(struct snd_pmac *chip)
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]);
130 * AWACS volume callbacks
133 * volumes: 0-15 stereo
135 static int snd_pmac_awacs_info_volume(struct snd_kcontrol *kcontrol,
136 struct snd_ctl_elem_info *uinfo)
138 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
140 uinfo->value.integer.min = 0;
141 uinfo->value.integer.max = 15;
145 static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol,
146 struct snd_ctl_elem_value *ucontrol)
148 struct snd_pmac *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(struct snd_kcontrol *kcontrol,
169 struct snd_ctl_elem_value *ucontrol)
171 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
172 int reg = kcontrol->private_value & 0xff;
173 int lshift = (kcontrol->private_value >> 8) & 0xff;
174 int inverted = (kcontrol->private_value >> 16) & 1;
179 vol[0] = ucontrol->value.integer.value[0];
180 vol[1] = ucontrol->value.integer.value[1];
181 if (vol[0] > 0x0f || vol[1] > 0x0f)
184 vol[0] = 0x0f - vol[0];
185 vol[1] = 0x0f - vol[1];
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;
195 snd_pmac_awacs_write_reg(chip, reg, val);
196 spin_unlock_irqrestore(&chip->reg_lock, flags);
197 return oldval != reg;
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) }
209 * mute master/ogain for AWACS: mono
211 static int snd_pmac_awacs_get_switch(struct snd_kcontrol *kcontrol,
212 struct snd_ctl_elem_value *ucontrol)
214 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
215 int reg = kcontrol->private_value & 0xff;
216 int shift = (kcontrol->private_value >> 8) & 0xff;
217 int invert = (kcontrol->private_value >> 16) & 1;
221 spin_lock_irqsave(&chip->reg_lock, flags);
222 val = (chip->awacs_reg[reg] >> shift) & 1;
223 spin_unlock_irqrestore(&chip->reg_lock, flags);
226 ucontrol->value.integer.value[0] = val;
230 static int snd_pmac_awacs_put_switch(struct snd_kcontrol *kcontrol,
231 struct snd_ctl_elem_value *ucontrol)
233 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
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;
241 spin_lock_irqsave(&chip->reg_lock, flags);
242 val = chip->awacs_reg[reg] & ~mask;
243 if (ucontrol->value.integer.value[0] != invert)
245 changed = chip->awacs_reg[reg] != val;
247 snd_pmac_awacs_write_reg(chip, reg, val);
248 spin_unlock_irqrestore(&chip->reg_lock, flags);
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) }
260 #ifdef PMAC_AMP_AVAIL
262 * controls for perch/whisper extension cards, e.g. G3 desktop
264 * TDA7433 connected via i2c address 0x45 (= 0x8a),
265 * accessed through cuda
267 static void awacs_set_cuda(int reg, int val)
269 struct adb_request req;
270 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a,
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,
294 int lvol, int rvol, int do_check)
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))
366 | (amp->amp_vol[index][0] & 32);
367 vol[1] = (31 - (ucontrol->value.integer.value[1] & 31))
368 | (amp->amp_vol[index][1] & 32);
369 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
372 static int snd_pmac_awacs_get_switch_amp(struct snd_kcontrol *kcontrol,
373 struct snd_ctl_elem_value *ucontrol)
375 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
376 int index = kcontrol->private_value;
377 struct awacs_amp *amp = chip->mixer_data;
378 snd_assert(amp, return -EINVAL);
379 snd_assert(index >= 0 && index <= 1, return -EINVAL);
380 ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32)
382 ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32)
387 static int snd_pmac_awacs_put_switch_amp(struct snd_kcontrol *kcontrol,
388 struct snd_ctl_elem_value *ucontrol)
390 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
391 int index = kcontrol->private_value;
393 struct awacs_amp *amp = chip->mixer_data;
394 snd_assert(amp, return -EINVAL);
395 snd_assert(index >= 0 && index <= 1, return -EINVAL);
397 vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32)
398 | (amp->amp_vol[index][0] & 31);
399 vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32)
400 | (amp->amp_vol[index][1] & 31);
401 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
404 static int snd_pmac_awacs_info_tone_amp(struct snd_kcontrol *kcontrol,
405 struct snd_ctl_elem_info *uinfo)
407 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
409 uinfo->value.integer.min = 0;
410 uinfo->value.integer.max = 14;
414 static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol,
415 struct snd_ctl_elem_value *ucontrol)
417 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
418 int index = kcontrol->private_value;
419 struct awacs_amp *amp = chip->mixer_data;
420 snd_assert(amp, return -EINVAL);
421 snd_assert(index >= 0 && index <= 1, return -EINVAL);
422 ucontrol->value.integer.value[0] = amp->amp_tone[index];
426 static int snd_pmac_awacs_put_tone_amp(struct snd_kcontrol *kcontrol,
427 struct snd_ctl_elem_value *ucontrol)
429 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
430 int index = kcontrol->private_value;
431 struct awacs_amp *amp = chip->mixer_data;
433 snd_assert(amp, return -EINVAL);
434 snd_assert(index >= 0 && index <= 1, return -EINVAL);
435 val = ucontrol->value.integer.value[0];
438 if (val != amp->amp_tone[index]) {
439 amp->amp_tone[index] = val;
440 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
446 static int snd_pmac_awacs_info_master_amp(struct snd_kcontrol *kcontrol,
447 struct snd_ctl_elem_info *uinfo)
449 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
451 uinfo->value.integer.min = 0;
452 uinfo->value.integer.max = 99;
456 static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol,
457 struct snd_ctl_elem_value *ucontrol)
459 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
460 struct awacs_amp *amp = chip->mixer_data;
461 snd_assert(amp, return -EINVAL);
462 ucontrol->value.integer.value[0] = amp->amp_master;
466 static int snd_pmac_awacs_put_master_amp(struct snd_kcontrol *kcontrol,
467 struct snd_ctl_elem_value *ucontrol)
469 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
470 struct awacs_amp *amp = chip->mixer_data;
472 snd_assert(amp, return -EINVAL);
473 val = ucontrol->value.integer.value[0];
476 if (val != amp->amp_master) {
477 amp->amp_master = val;
478 awacs_amp_set_master(amp, amp->amp_master);
487 static struct snd_kcontrol_new snd_pmac_awacs_amp_vol[] __initdata = {
488 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
489 .name = "PC Speaker 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_SPK,
495 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
496 .name = "Headphone Playback Volume",
497 .info = snd_pmac_awacs_info_volume_amp,
498 .get = snd_pmac_awacs_get_volume_amp,
499 .put = snd_pmac_awacs_put_volume_amp,
500 .private_value = AMP_CH_HD,
502 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
503 .name = "Tone Control - Bass",
504 .info = snd_pmac_awacs_info_tone_amp,
505 .get = snd_pmac_awacs_get_tone_amp,
506 .put = snd_pmac_awacs_put_tone_amp,
509 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
510 .name = "Tone Control - Treble",
511 .info = snd_pmac_awacs_info_tone_amp,
512 .get = snd_pmac_awacs_get_tone_amp,
513 .put = snd_pmac_awacs_put_tone_amp,
516 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
517 .name = "Amp Master Playback Volume",
518 .info = snd_pmac_awacs_info_master_amp,
519 .get = snd_pmac_awacs_get_master_amp,
520 .put = snd_pmac_awacs_put_master_amp,
524 static struct snd_kcontrol_new snd_pmac_awacs_amp_hp_sw __initdata = {
525 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
526 .name = "Headphone Playback Switch",
527 .info = snd_pmac_boolean_stereo_info,
528 .get = snd_pmac_awacs_get_switch_amp,
529 .put = snd_pmac_awacs_put_switch_amp,
530 .private_value = AMP_CH_HD,
533 static struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw __initdata = {
534 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
535 .name = "PC Speaker Playback Switch",
536 .info = snd_pmac_boolean_stereo_info,
537 .get = snd_pmac_awacs_get_switch_amp,
538 .put = snd_pmac_awacs_put_switch_amp,
539 .private_value = AMP_CH_SPK,
542 #endif /* PMAC_AMP_AVAIL */
546 * mic boost for screamer
548 static int snd_pmac_screamer_mic_boost_info(struct snd_kcontrol *kcontrol,
549 struct snd_ctl_elem_info *uinfo)
551 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
553 uinfo->value.integer.min = 0;
554 uinfo->value.integer.max = 3;
558 static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol *kcontrol,
559 struct snd_ctl_elem_value *ucontrol)
561 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
565 spin_lock_irqsave(&chip->reg_lock, flags);
566 if (chip->awacs_reg[6] & MASK_MIC_BOOST)
568 if (chip->awacs_reg[0] & MASK_GAINLINE)
570 spin_unlock_irqrestore(&chip->reg_lock, flags);
571 ucontrol->value.integer.value[0] = val;
575 static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
576 struct snd_ctl_elem_value *ucontrol)
578 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
583 spin_lock_irqsave(&chip->reg_lock, flags);
584 val0 = chip->awacs_reg[0] & ~MASK_GAINLINE;
585 val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST;
586 if (ucontrol->value.integer.value[0] & 1)
587 val0 |= MASK_GAINLINE;
588 if (ucontrol->value.integer.value[0] & 2)
589 val6 |= MASK_MIC_BOOST;
590 if (val0 != chip->awacs_reg[0]) {
591 snd_pmac_awacs_write_reg(chip, 0, val0);
594 if (val6 != chip->awacs_reg[6]) {
595 snd_pmac_awacs_write_reg(chip, 6, val6);
598 spin_unlock_irqrestore(&chip->reg_lock, flags);
603 * lists of mixer elements
605 static struct snd_kcontrol_new snd_pmac_awacs_mixers[] __initdata = {
606 AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0),
607 AWACS_VOLUME("Master Capture Volume", 0, 4, 0),
608 /* AWACS_SWITCH("Unknown Playback Switch", 6, SHIFT_PAROUT0, 0), */
611 static struct snd_kcontrol_new snd_pmac_screamer_mixers_beige[] __initdata = {
612 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
613 AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1),
614 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
615 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_LINE, 0),
618 static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] __initdata = {
619 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
620 AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
621 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
624 static struct snd_kcontrol_new snd_pmac_screamer_mixers_g4agp[] __initdata = {
625 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
626 AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
627 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
628 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
631 static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] __initdata = {
632 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
633 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
634 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
637 static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] __initdata = {
638 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
639 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
642 /* FIXME: is this correct order?
643 * screamer (powerbook G3 pismo) seems to have different bits...
645 static struct snd_kcontrol_new snd_pmac_awacs_mixers2[] __initdata = {
646 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_LINE, 0),
647 AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_MIC, 0),
650 static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] __initdata = {
651 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
652 AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_LINE, 0),
655 static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata =
656 AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1);
658 static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac __initdata =
659 AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1);
661 static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = {
662 AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
665 static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __initdata = {
666 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
667 .name = "Mic Boost Capture Volume",
668 .info = snd_pmac_screamer_mic_boost_info,
669 .get = snd_pmac_screamer_mic_boost_get,
670 .put = snd_pmac_screamer_mic_boost_put,
674 static struct snd_kcontrol_new snd_pmac_awacs_mic_boost_pmac7500[] __initdata =
676 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
679 static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_beige[] __initdata =
681 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
682 AWACS_SWITCH("CD Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
685 static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] __initdata =
687 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
688 AWACS_SWITCH("Mic Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
691 static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __initdata = {
692 AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1),
695 static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata =
696 AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);
698 static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac1 __initdata =
699 AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 1);
701 static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac2 __initdata =
702 AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 0);
706 * add new mixer elements to the card
708 static int build_mixers(struct snd_pmac *chip, int nums,
709 struct snd_kcontrol_new *mixers)
713 for (i = 0; i < nums; i++) {
714 err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip));
723 * restore all registers
725 static void awacs_restore_all_regs(struct snd_pmac *chip)
727 snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
728 snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
729 snd_pmac_awacs_write_noreg(chip, 2, chip->awacs_reg[2]);
730 snd_pmac_awacs_write_noreg(chip, 4, chip->awacs_reg[4]);
731 if (chip->model == PMAC_SCREAMER) {
732 snd_pmac_awacs_write_noreg(chip, 5, chip->awacs_reg[5]);
733 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
734 snd_pmac_awacs_write_noreg(chip, 7, chip->awacs_reg[7]);
739 static void snd_pmac_awacs_suspend(struct snd_pmac *chip)
741 snd_pmac_awacs_write_noreg(chip, 1, (chip->awacs_reg[1]
742 | MASK_AMUTE | MASK_CMUTE));
745 static void snd_pmac_awacs_resume(struct snd_pmac *chip)
747 if (machine_is_compatible("PowerBook3,1")
748 || machine_is_compatible("PowerBook3,2")) {
750 snd_pmac_awacs_write_reg(chip, 1,
751 chip->awacs_reg[1] & ~MASK_PAROUT);
755 awacs_restore_all_regs(chip);
756 if (chip->model == PMAC_SCREAMER) {
757 /* reset power bits in reg 6 */
759 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
761 screamer_recalibrate(chip);
762 #ifdef PMAC_AMP_AVAIL
763 if (chip->mixer_data) {
764 struct awacs_amp *amp = chip->mixer_data;
765 awacs_amp_set_vol(amp, 0,
766 amp->amp_vol[0][0], amp->amp_vol[0][1], 0);
767 awacs_amp_set_vol(amp, 1,
768 amp->amp_vol[1][0], amp->amp_vol[1][1], 0);
769 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
770 awacs_amp_set_master(amp, amp->amp_master);
774 #endif /* CONFIG_PM */
776 #define IS_PM7500 (machine_is_compatible("AAPL,7500"))
777 #define IS_BEIGE (machine_is_compatible("AAPL,Gossamer"))
778 #define IS_IMAC1 (machine_is_compatible("PowerMac2,1"))
779 #define IS_IMAC2 (machine_is_compatible("PowerMac2,2") \
780 || machine_is_compatible("PowerMac4,1"))
781 #define IS_G4AGP (machine_is_compatible("PowerMac3,1"))
783 static int imac1, imac2;
785 #ifdef PMAC_SUPPORT_AUTOMUTE
789 static int snd_pmac_awacs_detect_headphone(struct snd_pmac *chip)
791 return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0;
794 #ifdef PMAC_AMP_AVAIL
795 static int toggle_amp_mute(struct awacs_amp *amp, int index, int mute)
798 vol[0] = amp->amp_vol[index][0] & 31;
799 vol[1] = amp->amp_vol[index][1] & 31;
804 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
808 static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
810 if (chip->auto_mute) {
811 #ifdef PMAC_AMP_AVAIL
812 if (chip->mixer_data) {
813 struct awacs_amp *amp = chip->mixer_data;
815 if (snd_pmac_awacs_detect_headphone(chip)) {
816 changed = toggle_amp_mute(amp, AMP_CH_HD, 0);
817 changed |= toggle_amp_mute(amp, AMP_CH_SPK, 1);
819 changed = toggle_amp_mute(amp, AMP_CH_HD, 1);
820 changed |= toggle_amp_mute(amp, AMP_CH_SPK, 0);
822 if (do_notify && ! changed)
827 int reg = chip->awacs_reg[1]
828 | (MASK_HDMUTE | MASK_SPKMUTE);
830 reg &= ~MASK_SPKMUTE;
833 reg &= ~MASK_SPKMUTE;
834 reg &= ~MASK_PAROUT1;
836 if (snd_pmac_awacs_detect_headphone(chip))
839 reg &= ~MASK_PAROUT1;
843 reg &= ~MASK_SPKMUTE;
844 if (do_notify && reg == chip->awacs_reg[1])
846 snd_pmac_awacs_write_reg(chip, 1, reg);
849 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
850 &chip->master_sw_ctl->id);
851 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
852 &chip->speaker_sw_ctl->id);
853 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
854 &chip->hp_detect_ctl->id);
858 #endif /* PMAC_SUPPORT_AUTOMUTE */
865 snd_pmac_awacs_init(struct snd_pmac *chip)
867 int pm7500 = IS_PM7500;
868 int beige = IS_BEIGE;
869 int g4agp = IS_G4AGP;
875 imac = imac1 || imac2;
876 /* looks like MASK_GAINLINE triggers something, so we set here
879 chip->awacs_reg[0] = MASK_MUX_CD | 0xff | MASK_GAINLINE;
880 chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE;
881 /* FIXME: Only machines with external SRS module need MASK_PAROUT */
882 if (chip->has_iic || chip->device_id == 0x5 ||
883 /* chip->_device_id == 0x8 || */
884 chip->device_id == 0xb)
885 chip->awacs_reg[1] |= MASK_PAROUT;
886 /* get default volume from nvram */
887 // vol = (~nvram_read_byte(0x1308) & 7) << 1;
888 // vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
889 vol = 0x0f; /* no, on alsa, muted as default */
890 vol = vol + (vol << 6);
891 chip->awacs_reg[2] = vol;
892 chip->awacs_reg[4] = vol;
893 if (chip->model == PMAC_SCREAMER) {
894 /* FIXME: screamer has loopthru vol control */
895 chip->awacs_reg[5] = vol;
896 /* FIXME: maybe should be vol << 3 for PCMCIA speaker */
897 chip->awacs_reg[6] = MASK_MIC_BOOST;
898 chip->awacs_reg[7] = 0;
901 awacs_restore_all_regs(chip);
902 chip->manufacturer = (in_le32(&chip->awacs->codec_stat) >> 8) & 0xf;
903 screamer_recalibrate(chip);
905 chip->revision = (in_le32(&chip->awacs->codec_stat) >> 12) & 0xf;
906 #ifdef PMAC_AMP_AVAIL
907 if (chip->revision == 3 && chip->has_iic && CHECK_CUDA_AMP()) {
908 struct awacs_amp *amp = kzalloc(sizeof(*amp), GFP_KERNEL);
911 chip->mixer_data = amp;
912 chip->mixer_free = awacs_amp_free;
913 /* mute and zero vol */
914 awacs_amp_set_vol(amp, 0, 63, 63, 0);
915 awacs_amp_set_vol(amp, 1, 63, 63, 0);
916 awacs_amp_set_tone(amp, 7, 7); /* 0 dB */
917 awacs_amp_set_master(amp, 79); /* 0 dB */
919 #endif /* PMAC_AMP_AVAIL */
921 if (chip->hp_stat_mask == 0) {
922 /* set headphone-jack detection bit */
923 switch (chip->model) {
925 chip->hp_stat_mask = pm7500 ? MASK_HDPCONN
929 switch (chip->device_id) {
932 chip->hp_stat_mask = imac
940 chip->hp_stat_mask = MASK_LOCONN;
943 chip->hp_stat_mask = MASK_HDPCONN;
956 strcpy(chip->card->mixername, "PowerMac AWACS");
958 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers),
959 snd_pmac_awacs_mixers);
964 else if (chip->model == PMAC_SCREAMER)
965 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2),
966 snd_pmac_screamer_mixers2);
968 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2),
969 snd_pmac_awacs_mixers2);
973 err = build_mixers(chip,
974 ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500),
975 snd_pmac_awacs_mixers_pmac7500);
977 err = build_mixers(chip,
978 ARRAY_SIZE(snd_pmac_screamer_mixers_beige),
979 snd_pmac_screamer_mixers_beige);
981 err = build_mixers(chip,
982 ARRAY_SIZE(snd_pmac_screamer_mixers_imac),
983 snd_pmac_screamer_mixers_imac);
985 err = build_mixers(chip,
986 ARRAY_SIZE(snd_pmac_screamer_mixers_g4agp),
987 snd_pmac_screamer_mixers_g4agp);
989 err = build_mixers(chip,
990 ARRAY_SIZE(snd_pmac_awacs_mixers_pmac),
991 snd_pmac_awacs_mixers_pmac);
994 chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac || g4agp)
995 ? &snd_pmac_awacs_master_sw_imac
996 : &snd_pmac_awacs_master_sw, chip);
997 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
1000 #ifdef PMAC_AMP_AVAIL
1001 if (chip->mixer_data) {
1002 /* use amplifier. the signal is connected from route A
1003 * to the amp. the amp has its headphone and speaker
1004 * volumes and mute switches, so we use them instead of
1005 * screamer registers.
1006 * in this case, it seems the route C is not used.
1008 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol),
1009 snd_pmac_awacs_amp_vol);
1013 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw,
1015 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
1018 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw,
1020 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
1024 #endif /* PMAC_AMP_AVAIL */
1026 /* route A = headphone, route C = speaker */
1027 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol),
1028 snd_pmac_awacs_speaker_vol);
1031 chip->speaker_sw_ctl = snd_ctl_new1(imac1
1032 ? &snd_pmac_awacs_speaker_sw_imac1
1034 ? &snd_pmac_awacs_speaker_sw_imac2
1035 : &snd_pmac_awacs_speaker_sw, chip);
1036 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
1042 err = build_mixers(chip,
1043 ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige),
1044 snd_pmac_screamer_mic_boost_beige);
1046 err = build_mixers(chip,
1047 ARRAY_SIZE(snd_pmac_screamer_mic_boost_imac),
1048 snd_pmac_screamer_mic_boost_imac);
1049 else if (chip->model == PMAC_SCREAMER)
1050 err = build_mixers(chip,
1051 ARRAY_SIZE(snd_pmac_screamer_mic_boost),
1052 snd_pmac_screamer_mic_boost);
1054 err = build_mixers(chip,
1055 ARRAY_SIZE(snd_pmac_awacs_mic_boost_pmac7500),
1056 snd_pmac_awacs_mic_boost_pmac7500);
1058 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost),
1059 snd_pmac_awacs_mic_boost);
1064 * set lowlevel callbacks
1066 chip->set_format = snd_pmac_awacs_set_format;
1068 chip->suspend = snd_pmac_awacs_suspend;
1069 chip->resume = snd_pmac_awacs_resume;
1071 #ifdef PMAC_SUPPORT_AUTOMUTE
1072 err = snd_pmac_add_automute(chip);
1075 chip->detect_headphone = snd_pmac_awacs_detect_headphone;
1076 chip->update_automute = snd_pmac_awacs_update_automute;
1077 snd_pmac_awacs_update_automute(chip, 0); /* update the status only */
1079 if (chip->model == PMAC_SCREAMER) {
1080 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
1081 snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);