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];
183 vol
[0] = 0x0f - vol
[0];
184 vol
[1] = 0x0f - vol
[1];
188 spin_lock_irqsave(&chip
->reg_lock
, flags
);
189 oldval
= chip
->awacs_reg
[reg
];
190 val
= oldval
& ~(0xf | (0xf << lshift
));
191 val
|= vol
[0] << lshift
;
194 snd_pmac_awacs_write_reg(chip
, reg
, val
);
195 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
196 return oldval
!= reg
;
200 #define AWACS_VOLUME(xname, xreg, xshift, xinverted) \
201 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
202 .info = snd_pmac_awacs_info_volume, \
203 .get = snd_pmac_awacs_get_volume, \
204 .put = snd_pmac_awacs_put_volume, \
205 .private_value = (xreg) | ((xshift) << 8) | ((xinverted) << 16) }
208 * mute master/ogain for AWACS: mono
210 static int snd_pmac_awacs_get_switch(struct snd_kcontrol
*kcontrol
,
211 struct snd_ctl_elem_value
*ucontrol
)
213 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
214 int reg
= kcontrol
->private_value
& 0xff;
215 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
216 int invert
= (kcontrol
->private_value
>> 16) & 1;
220 spin_lock_irqsave(&chip
->reg_lock
, flags
);
221 val
= (chip
->awacs_reg
[reg
] >> shift
) & 1;
222 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
225 ucontrol
->value
.integer
.value
[0] = val
;
229 static int snd_pmac_awacs_put_switch(struct snd_kcontrol
*kcontrol
,
230 struct snd_ctl_elem_value
*ucontrol
)
232 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
233 int reg
= kcontrol
->private_value
& 0xff;
234 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
235 int invert
= (kcontrol
->private_value
>> 16) & 1;
236 int mask
= 1 << shift
;
240 spin_lock_irqsave(&chip
->reg_lock
, flags
);
241 val
= chip
->awacs_reg
[reg
] & ~mask
;
242 if (ucontrol
->value
.integer
.value
[0] != invert
)
244 changed
= chip
->awacs_reg
[reg
] != val
;
246 snd_pmac_awacs_write_reg(chip
, reg
, val
);
247 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
251 #define AWACS_SWITCH(xname, xreg, xshift, xinvert) \
252 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
253 .info = snd_pmac_boolean_mono_info, \
254 .get = snd_pmac_awacs_get_switch, \
255 .put = snd_pmac_awacs_put_switch, \
256 .private_value = (xreg) | ((xshift) << 8) | ((xinvert) << 16) }
259 #ifdef PMAC_AMP_AVAIL
261 * controls for perch/whisper extension cards, e.g. G3 desktop
263 * TDA7433 connected via i2c address 0x45 (= 0x8a),
264 * accessed through cuda
266 static void awacs_set_cuda(int reg
, int val
)
268 struct adb_request req
;
269 cuda_request(&req
, NULL
, 5, CUDA_PACKET
, CUDA_GET_SET_IIC
, 0x8a, reg
, val
);
270 while (! req
.complete
)
275 * level = 0 - 14, 7 = 0 dB
277 static void awacs_amp_set_tone(struct awacs_amp
*amp
, int bass
, int treble
)
279 amp
->amp_tone
[0] = bass
;
280 amp
->amp_tone
[1] = treble
;
282 bass
= (14 - bass
) + 8;
284 treble
= (14 - treble
) + 8;
285 awacs_set_cuda(2, (bass
<< 4) | treble
);
289 * vol = 0 - 31 (attenuation), 32 = mute bit, stereo
291 static int awacs_amp_set_vol(struct awacs_amp
*amp
, int index
, int lvol
, int rvol
,
294 if (do_check
&& amp
->amp_vol
[index
][0] == lvol
&&
295 amp
->amp_vol
[index
][1] == rvol
)
297 awacs_set_cuda(3 + index
, lvol
);
298 awacs_set_cuda(5 + index
, rvol
);
299 amp
->amp_vol
[index
][0] = lvol
;
300 amp
->amp_vol
[index
][1] = rvol
;
305 * 0 = -79 dB, 79 = 0 dB, 99 = +20 dB
307 static void awacs_amp_set_master(struct awacs_amp
*amp
, int vol
)
309 amp
->amp_master
= vol
;
311 vol
= 32 + (79 - vol
);
313 vol
= 32 - (vol
- 79);
314 awacs_set_cuda(1, vol
);
317 static void awacs_amp_free(struct snd_pmac
*chip
)
319 struct awacs_amp
*amp
= chip
->mixer_data
;
320 snd_assert(amp
, return);
322 chip
->mixer_data
= NULL
;
323 chip
->mixer_free
= NULL
;
330 static int snd_pmac_awacs_info_volume_amp(struct snd_kcontrol
*kcontrol
,
331 struct snd_ctl_elem_info
*uinfo
)
333 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
335 uinfo
->value
.integer
.min
= 0;
336 uinfo
->value
.integer
.max
= 31;
340 static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol
*kcontrol
,
341 struct snd_ctl_elem_value
*ucontrol
)
343 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
344 int index
= kcontrol
->private_value
;
345 struct awacs_amp
*amp
= chip
->mixer_data
;
346 snd_assert(amp
, return -EINVAL
);
347 snd_assert(index
>= 0 && index
<= 1, return -EINVAL
);
348 ucontrol
->value
.integer
.value
[0] = 31 - (amp
->amp_vol
[index
][0] & 31);
349 ucontrol
->value
.integer
.value
[1] = 31 - (amp
->amp_vol
[index
][1] & 31);
353 static int snd_pmac_awacs_put_volume_amp(struct snd_kcontrol
*kcontrol
,
354 struct snd_ctl_elem_value
*ucontrol
)
356 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
357 int index
= kcontrol
->private_value
;
359 struct awacs_amp
*amp
= chip
->mixer_data
;
360 snd_assert(amp
, return -EINVAL
);
361 snd_assert(index
>= 0 && index
<= 1, return -EINVAL
);
363 vol
[0] = (31 - (ucontrol
->value
.integer
.value
[0] & 31)) | (amp
->amp_vol
[index
][0] & 32);
364 vol
[1] = (31 - (ucontrol
->value
.integer
.value
[1] & 31)) | (amp
->amp_vol
[index
][1] & 32);
365 return awacs_amp_set_vol(amp
, index
, vol
[0], vol
[1], 1);
368 static int snd_pmac_awacs_get_switch_amp(struct snd_kcontrol
*kcontrol
,
369 struct snd_ctl_elem_value
*ucontrol
)
371 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
372 int index
= kcontrol
->private_value
;
373 struct awacs_amp
*amp
= chip
->mixer_data
;
374 snd_assert(amp
, return -EINVAL
);
375 snd_assert(index
>= 0 && index
<= 1, return -EINVAL
);
376 ucontrol
->value
.integer
.value
[0] = (amp
->amp_vol
[index
][0] & 32) ? 0 : 1;
377 ucontrol
->value
.integer
.value
[1] = (amp
->amp_vol
[index
][1] & 32) ? 0 : 1;
381 static int snd_pmac_awacs_put_switch_amp(struct snd_kcontrol
*kcontrol
,
382 struct snd_ctl_elem_value
*ucontrol
)
384 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
385 int index
= kcontrol
->private_value
;
387 struct awacs_amp
*amp
= chip
->mixer_data
;
388 snd_assert(amp
, return -EINVAL
);
389 snd_assert(index
>= 0 && index
<= 1, return -EINVAL
);
391 vol
[0] = (ucontrol
->value
.integer
.value
[0] ? 0 : 32) | (amp
->amp_vol
[index
][0] & 31);
392 vol
[1] = (ucontrol
->value
.integer
.value
[1] ? 0 : 32) | (amp
->amp_vol
[index
][1] & 31);
393 return awacs_amp_set_vol(amp
, index
, vol
[0], vol
[1], 1);
396 static int snd_pmac_awacs_info_tone_amp(struct snd_kcontrol
*kcontrol
,
397 struct snd_ctl_elem_info
*uinfo
)
399 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
401 uinfo
->value
.integer
.min
= 0;
402 uinfo
->value
.integer
.max
= 14;
406 static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol
*kcontrol
,
407 struct snd_ctl_elem_value
*ucontrol
)
409 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
410 int index
= kcontrol
->private_value
;
411 struct awacs_amp
*amp
= chip
->mixer_data
;
412 snd_assert(amp
, return -EINVAL
);
413 snd_assert(index
>= 0 && index
<= 1, return -EINVAL
);
414 ucontrol
->value
.integer
.value
[0] = amp
->amp_tone
[index
];
418 static int snd_pmac_awacs_put_tone_amp(struct snd_kcontrol
*kcontrol
,
419 struct snd_ctl_elem_value
*ucontrol
)
421 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
422 int index
= kcontrol
->private_value
;
423 struct awacs_amp
*amp
= chip
->mixer_data
;
424 snd_assert(amp
, return -EINVAL
);
425 snd_assert(index
>= 0 && index
<= 1, return -EINVAL
);
426 if (ucontrol
->value
.integer
.value
[0] != amp
->amp_tone
[index
]) {
427 amp
->amp_tone
[index
] = ucontrol
->value
.integer
.value
[0];
428 awacs_amp_set_tone(amp
, amp
->amp_tone
[0], amp
->amp_tone
[1]);
434 static int snd_pmac_awacs_info_master_amp(struct snd_kcontrol
*kcontrol
,
435 struct snd_ctl_elem_info
*uinfo
)
437 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
439 uinfo
->value
.integer
.min
= 0;
440 uinfo
->value
.integer
.max
= 99;
444 static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol
*kcontrol
,
445 struct snd_ctl_elem_value
*ucontrol
)
447 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
448 struct awacs_amp
*amp
= chip
->mixer_data
;
449 snd_assert(amp
, return -EINVAL
);
450 ucontrol
->value
.integer
.value
[0] = amp
->amp_master
;
454 static int snd_pmac_awacs_put_master_amp(struct snd_kcontrol
*kcontrol
,
455 struct snd_ctl_elem_value
*ucontrol
)
457 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
458 struct awacs_amp
*amp
= chip
->mixer_data
;
459 snd_assert(amp
, return -EINVAL
);
460 if (ucontrol
->value
.integer
.value
[0] != amp
->amp_master
) {
461 amp
->amp_master
= ucontrol
->value
.integer
.value
[0];
462 awacs_amp_set_master(amp
, amp
->amp_master
);
471 static struct snd_kcontrol_new snd_pmac_awacs_amp_vol
[] __initdata
= {
472 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
473 .name
= "PC Speaker Playback Volume",
474 .info
= snd_pmac_awacs_info_volume_amp
,
475 .get
= snd_pmac_awacs_get_volume_amp
,
476 .put
= snd_pmac_awacs_put_volume_amp
,
477 .private_value
= AMP_CH_SPK
,
479 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
480 .name
= "Headphone Playback Volume",
481 .info
= snd_pmac_awacs_info_volume_amp
,
482 .get
= snd_pmac_awacs_get_volume_amp
,
483 .put
= snd_pmac_awacs_put_volume_amp
,
484 .private_value
= AMP_CH_HD
,
486 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
487 .name
= "Tone Control - Bass",
488 .info
= snd_pmac_awacs_info_tone_amp
,
489 .get
= snd_pmac_awacs_get_tone_amp
,
490 .put
= snd_pmac_awacs_put_tone_amp
,
493 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
494 .name
= "Tone Control - Treble",
495 .info
= snd_pmac_awacs_info_tone_amp
,
496 .get
= snd_pmac_awacs_get_tone_amp
,
497 .put
= snd_pmac_awacs_put_tone_amp
,
500 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
501 .name
= "Amp Master Playback Volume",
502 .info
= snd_pmac_awacs_info_master_amp
,
503 .get
= snd_pmac_awacs_get_master_amp
,
504 .put
= snd_pmac_awacs_put_master_amp
,
508 static struct snd_kcontrol_new snd_pmac_awacs_amp_hp_sw __initdata
= {
509 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
510 .name
= "Headphone Playback Switch",
511 .info
= snd_pmac_boolean_stereo_info
,
512 .get
= snd_pmac_awacs_get_switch_amp
,
513 .put
= snd_pmac_awacs_put_switch_amp
,
514 .private_value
= AMP_CH_HD
,
517 static struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw __initdata
= {
518 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
519 .name
= "PC Speaker 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_SPK
,
526 #endif /* PMAC_AMP_AVAIL */
530 * mic boost for screamer
532 static int snd_pmac_screamer_mic_boost_info(struct snd_kcontrol
*kcontrol
,
533 struct snd_ctl_elem_info
*uinfo
)
535 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
537 uinfo
->value
.integer
.min
= 0;
538 uinfo
->value
.integer
.max
= 2;
542 static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol
*kcontrol
,
543 struct snd_ctl_elem_value
*ucontrol
)
545 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
549 spin_lock_irqsave(&chip
->reg_lock
, flags
);
550 if (chip
->awacs_reg
[6] & MASK_MIC_BOOST
)
552 else if (chip
->awacs_reg
[0] & MASK_GAINLINE
)
556 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
557 ucontrol
->value
.integer
.value
[0] = val
;
561 static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol
*kcontrol
,
562 struct snd_ctl_elem_value
*ucontrol
)
564 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
569 spin_lock_irqsave(&chip
->reg_lock
, flags
);
570 val0
= chip
->awacs_reg
[0] & ~MASK_GAINLINE
;
571 val6
= chip
->awacs_reg
[6] & ~MASK_MIC_BOOST
;
572 if (ucontrol
->value
.integer
.value
[0] > 0) {
573 val0
|= MASK_GAINLINE
;
574 if (ucontrol
->value
.integer
.value
[0] > 1)
575 val6
|= MASK_MIC_BOOST
;
577 if (val0
!= chip
->awacs_reg
[0]) {
578 snd_pmac_awacs_write_reg(chip
, 0, val0
);
581 if (val6
!= chip
->awacs_reg
[6]) {
582 snd_pmac_awacs_write_reg(chip
, 6, val6
);
585 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
590 * lists of mixer elements
592 static struct snd_kcontrol_new snd_pmac_awacs_mixers
[] __initdata
= {
593 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
594 AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU
, 0),
595 AWACS_VOLUME("Capture Volume", 0, 4, 0),
596 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD
, 0),
599 /* FIXME: is this correct order?
600 * screamer (powerbook G3 pismo) seems to have different bits...
602 static struct snd_kcontrol_new snd_pmac_awacs_mixers2
[] __initdata
= {
603 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_LINE
, 0),
604 AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_MIC
, 0),
607 static struct snd_kcontrol_new snd_pmac_screamer_mixers2
[] __initdata
= {
608 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC
, 0),
609 AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_LINE
, 0),
612 static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata
=
613 AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE
, 1);
615 static struct snd_kcontrol_new snd_pmac_awacs_mic_boost
[] __initdata
= {
616 AWACS_SWITCH("Mic Boost", 0, SHIFT_GAINLINE
, 0),
619 static struct snd_kcontrol_new snd_pmac_screamer_mic_boost
[] __initdata
= {
620 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
622 .info
= snd_pmac_screamer_mic_boost_info
,
623 .get
= snd_pmac_screamer_mic_boost_get
,
624 .put
= snd_pmac_screamer_mic_boost_put
,
628 static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol
[] __initdata
= {
629 AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1),
631 static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata
=
632 AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE
, 1);
636 * add new mixer elements to the card
638 static int build_mixers(struct snd_pmac
*chip
, int nums
, struct snd_kcontrol_new
*mixers
)
642 for (i
= 0; i
< nums
; i
++) {
643 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&mixers
[i
], chip
))) < 0)
651 * restore all registers
653 static void awacs_restore_all_regs(struct snd_pmac
*chip
)
655 snd_pmac_awacs_write_noreg(chip
, 0, chip
->awacs_reg
[0]);
656 snd_pmac_awacs_write_noreg(chip
, 1, chip
->awacs_reg
[1]);
657 snd_pmac_awacs_write_noreg(chip
, 2, chip
->awacs_reg
[2]);
658 snd_pmac_awacs_write_noreg(chip
, 4, chip
->awacs_reg
[4]);
659 if (chip
->model
== PMAC_SCREAMER
) {
660 snd_pmac_awacs_write_noreg(chip
, 5, chip
->awacs_reg
[5]);
661 snd_pmac_awacs_write_noreg(chip
, 6, chip
->awacs_reg
[6]);
662 snd_pmac_awacs_write_noreg(chip
, 7, chip
->awacs_reg
[7]);
667 static void snd_pmac_awacs_suspend(struct snd_pmac
*chip
)
669 snd_pmac_awacs_write_noreg(chip
, 1, (chip
->awacs_reg
[1]
670 | MASK_AMUTE
| MASK_CMUTE
));
673 static void snd_pmac_awacs_resume(struct snd_pmac
*chip
)
675 if (machine_is_compatible("PowerBook3,1")
676 || machine_is_compatible("PowerBook3,2")) {
678 snd_pmac_awacs_write_reg(chip
, 1,
679 chip
->awacs_reg
[1] & ~MASK_PAROUT
);
683 awacs_restore_all_regs(chip
);
684 if (chip
->model
== PMAC_SCREAMER
) {
685 /* reset power bits in reg 6 */
687 snd_pmac_awacs_write_noreg(chip
, 6, chip
->awacs_reg
[6]);
689 screamer_recalibrate(chip
);
690 #ifdef PMAC_AMP_AVAIL
691 if (chip
->mixer_data
) {
692 struct awacs_amp
*amp
= chip
->mixer_data
;
693 awacs_amp_set_vol(amp
, 0, amp
->amp_vol
[0][0], amp
->amp_vol
[0][1], 0);
694 awacs_amp_set_vol(amp
, 1, amp
->amp_vol
[1][0], amp
->amp_vol
[1][1], 0);
695 awacs_amp_set_tone(amp
, amp
->amp_tone
[0], amp
->amp_tone
[1]);
696 awacs_amp_set_master(amp
, amp
->amp_master
);
700 #endif /* CONFIG_PM */
702 #ifdef PMAC_SUPPORT_AUTOMUTE
706 static int snd_pmac_awacs_detect_headphone(struct snd_pmac
*chip
)
708 return (in_le32(&chip
->awacs
->codec_stat
) & chip
->hp_stat_mask
) ? 1 : 0;
711 #ifdef PMAC_AMP_AVAIL
712 static int toggle_amp_mute(struct awacs_amp
*amp
, int index
, int mute
)
715 vol
[0] = amp
->amp_vol
[index
][0] & 31;
716 vol
[1] = amp
->amp_vol
[index
][1] & 31;
721 return awacs_amp_set_vol(amp
, index
, vol
[0], vol
[1], 1);
725 static void snd_pmac_awacs_update_automute(struct snd_pmac
*chip
, int do_notify
)
727 if (chip
->auto_mute
) {
728 #ifdef PMAC_AMP_AVAIL
729 if (chip
->mixer_data
) {
730 struct awacs_amp
*amp
= chip
->mixer_data
;
732 if (snd_pmac_awacs_detect_headphone(chip
)) {
733 changed
= toggle_amp_mute(amp
, AMP_CH_HD
, 0);
734 changed
|= toggle_amp_mute(amp
, AMP_CH_SPK
, 1);
736 changed
= toggle_amp_mute(amp
, AMP_CH_HD
, 1);
737 changed
|= toggle_amp_mute(amp
, AMP_CH_SPK
, 0);
739 if (do_notify
&& ! changed
)
744 int reg
= chip
->awacs_reg
[1] | (MASK_HDMUTE
|MASK_SPKMUTE
);
745 if (snd_pmac_awacs_detect_headphone(chip
))
748 reg
&= ~MASK_SPKMUTE
;
749 if (do_notify
&& reg
== chip
->awacs_reg
[1])
751 snd_pmac_awacs_write_reg(chip
, 1, reg
);
754 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
755 &chip
->master_sw_ctl
->id
);
756 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
757 &chip
->speaker_sw_ctl
->id
);
758 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
759 &chip
->hp_detect_ctl
->id
);
763 #endif /* PMAC_SUPPORT_AUTOMUTE */
770 snd_pmac_awacs_init(struct snd_pmac
*chip
)
774 /* looks like MASK_GAINLINE triggers something, so we set here
777 chip
->awacs_reg
[0] = MASK_MUX_CD
| 0xff | MASK_GAINLINE
;
778 chip
->awacs_reg
[1] = MASK_CMUTE
| MASK_AMUTE
;
779 /* FIXME: Only machines with external SRS module need MASK_PAROUT */
780 if (chip
->has_iic
|| chip
->device_id
== 0x5 ||
781 /*chip->_device_id == 0x8 || */
782 chip
->device_id
== 0xb)
783 chip
->awacs_reg
[1] |= MASK_PAROUT
;
784 /* get default volume from nvram */
785 // vol = (~nvram_read_byte(0x1308) & 7) << 1;
786 // vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
787 vol
= 0x0f; /* no, on alsa, muted as default */
788 vol
= vol
+ (vol
<< 6);
789 chip
->awacs_reg
[2] = vol
;
790 chip
->awacs_reg
[4] = vol
;
791 if (chip
->model
== PMAC_SCREAMER
) {
792 chip
->awacs_reg
[5] = vol
; /* FIXME: screamer has loopthru vol control */
793 chip
->awacs_reg
[6] = MASK_MIC_BOOST
; /* FIXME: maybe should be vol << 3 for PCMCIA speaker */
794 chip
->awacs_reg
[7] = 0;
797 awacs_restore_all_regs(chip
);
798 chip
->manufacturer
= (in_le32(&chip
->awacs
->codec_stat
) >> 8) & 0xf;
799 screamer_recalibrate(chip
);
801 chip
->revision
= (in_le32(&chip
->awacs
->codec_stat
) >> 12) & 0xf;
802 #ifdef PMAC_AMP_AVAIL
803 if (chip
->revision
== 3 && chip
->has_iic
&& CHECK_CUDA_AMP()) {
804 struct awacs_amp
*amp
= kzalloc(sizeof(*amp
), GFP_KERNEL
);
807 chip
->mixer_data
= amp
;
808 chip
->mixer_free
= awacs_amp_free
;
809 awacs_amp_set_vol(amp
, 0, 63, 63, 0); /* mute and zero vol */
810 awacs_amp_set_vol(amp
, 1, 63, 63, 0);
811 awacs_amp_set_tone(amp
, 7, 7); /* 0 dB */
812 awacs_amp_set_master(amp
, 79); /* 0 dB */
814 #endif /* PMAC_AMP_AVAIL */
816 if (chip
->hp_stat_mask
== 0) {
817 /* set headphone-jack detection bit */
818 switch (chip
->model
) {
820 chip
->hp_stat_mask
= 0x04;
823 switch (chip
->device_id
) {
825 /* 1 = side jack, 2 = front jack */
826 chip
->hp_stat_mask
= 0x03;
830 chip
->hp_stat_mask
= 0x04;
833 chip
->hp_stat_mask
= 0x08;
846 strcpy(chip
->card
->mixername
, "PowerMac AWACS");
848 if ((err
= build_mixers(chip
, ARRAY_SIZE(snd_pmac_awacs_mixers
),
849 snd_pmac_awacs_mixers
)) < 0)
851 if (chip
->model
== PMAC_SCREAMER
)
852 err
= build_mixers(chip
, ARRAY_SIZE(snd_pmac_screamer_mixers2
),
853 snd_pmac_screamer_mixers2
);
855 err
= build_mixers(chip
, ARRAY_SIZE(snd_pmac_awacs_mixers2
),
856 snd_pmac_awacs_mixers2
);
859 chip
->master_sw_ctl
= snd_ctl_new1(&snd_pmac_awacs_master_sw
, chip
);
860 if ((err
= snd_ctl_add(chip
->card
, chip
->master_sw_ctl
)) < 0)
862 #ifdef PMAC_AMP_AVAIL
863 if (chip
->mixer_data
) {
864 /* use amplifier. the signal is connected from route A
865 * to the amp. the amp has its headphone and speaker
866 * volumes and mute switches, so we use them instead of
867 * screamer registers.
868 * in this case, it seems the route C is not used.
870 if ((err
= build_mixers(chip
, ARRAY_SIZE(snd_pmac_awacs_amp_vol
),
871 snd_pmac_awacs_amp_vol
)) < 0)
874 chip
->master_sw_ctl
= snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw
, chip
);
875 if ((err
= snd_ctl_add(chip
->card
, chip
->master_sw_ctl
)) < 0)
877 chip
->speaker_sw_ctl
= snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw
, chip
);
878 if ((err
= snd_ctl_add(chip
->card
, chip
->speaker_sw_ctl
)) < 0)
881 #endif /* PMAC_AMP_AVAIL */
883 /* route A = headphone, route C = speaker */
884 if ((err
= build_mixers(chip
, ARRAY_SIZE(snd_pmac_awacs_speaker_vol
),
885 snd_pmac_awacs_speaker_vol
)) < 0)
887 chip
->speaker_sw_ctl
= snd_ctl_new1(&snd_pmac_awacs_speaker_sw
, chip
);
888 if ((err
= snd_ctl_add(chip
->card
, chip
->speaker_sw_ctl
)) < 0)
892 if (chip
->model
== PMAC_SCREAMER
) {
893 if ((err
= build_mixers(chip
, ARRAY_SIZE(snd_pmac_screamer_mic_boost
),
894 snd_pmac_screamer_mic_boost
)) < 0)
897 if ((err
= build_mixers(chip
, ARRAY_SIZE(snd_pmac_awacs_mic_boost
),
898 snd_pmac_awacs_mic_boost
)) < 0)
903 * set lowlevel callbacks
905 chip
->set_format
= snd_pmac_awacs_set_format
;
907 chip
->suspend
= snd_pmac_awacs_suspend
;
908 chip
->resume
= snd_pmac_awacs_resume
;
910 #ifdef PMAC_SUPPORT_AUTOMUTE
911 if ((err
= snd_pmac_add_automute(chip
)) < 0)
913 chip
->detect_headphone
= snd_pmac_awacs_detect_headphone
;
914 chip
->update_automute
= snd_pmac_awacs_update_automute
;
915 snd_pmac_awacs_update_automute(chip
, 0); /* update the status only */
917 if (chip
->model
== PMAC_SCREAMER
) {
918 snd_pmac_awacs_write_noreg(chip
, 6, chip
->awacs_reg
[6]);
919 snd_pmac_awacs_write_noreg(chip
, 0, chip
->awacs_reg
[0]);