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 static void do_mdelay(int msec
, int can_schedule
)
98 set_current_state(TASK_UNINTERRUPTIBLE
);
99 schedule_timeout((msec
* HZ
+ 999) / 1000);
104 #ifdef CONFIG_PMAC_PBOOK
105 /* Recalibrate chip */
106 static void screamer_recalibrate(pmac_t
*chip
, int can_schedule
)
108 if (chip
->model
!= PMAC_SCREAMER
)
111 /* Sorry for the horrible delays... I hope to get that improved
112 * by making the whole PM process asynchronous in a future version
114 snd_pmac_awacs_write_noreg(chip
, 1, chip
->awacs_reg
[1]);
115 if (chip
->manufacturer
== 0x1)
116 /* delay for broken crystal part */
117 do_mdelay(750, can_schedule
);
118 snd_pmac_awacs_write_noreg(chip
, 1,
119 chip
->awacs_reg
[1] | MASK_RECALIBRATE
| MASK_CMUTE
| MASK_AMUTE
);
120 snd_pmac_awacs_write_noreg(chip
, 1, chip
->awacs_reg
[1]);
121 snd_pmac_awacs_write_noreg(chip
, 6, chip
->awacs_reg
[6]);
125 #define screamer_recalibrate(chip, can_schedule) /* NOP */
130 * additional callback to set the pcm format
132 static void snd_pmac_awacs_set_format(pmac_t
*chip
)
134 chip
->awacs_reg
[1] &= ~MASK_SAMPLERATE
;
135 chip
->awacs_reg
[1] |= chip
->rate_index
<< 3;
136 snd_pmac_awacs_write_reg(chip
, 1, chip
->awacs_reg
[1]);
141 * AWACS volume callbacks
144 * volumes: 0-15 stereo
146 static int snd_pmac_awacs_info_volume(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
148 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
150 uinfo
->value
.integer
.min
= 0;
151 uinfo
->value
.integer
.max
= 15;
155 static int snd_pmac_awacs_get_volume(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
157 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
158 int reg
= kcontrol
->private_value
& 0xff;
159 int lshift
= (kcontrol
->private_value
>> 8) & 0xff;
160 int inverted
= (kcontrol
->private_value
>> 16) & 1;
164 spin_lock_irqsave(&chip
->reg_lock
, flags
);
165 vol
[0] = (chip
->awacs_reg
[reg
] >> lshift
) & 0xf;
166 vol
[1] = chip
->awacs_reg
[reg
] & 0xf;
167 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
169 vol
[0] = 0x0f - vol
[0];
170 vol
[1] = 0x0f - vol
[1];
172 ucontrol
->value
.integer
.value
[0] = vol
[0];
173 ucontrol
->value
.integer
.value
[1] = vol
[1];
177 static int snd_pmac_awacs_put_volume(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
179 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
180 int reg
= kcontrol
->private_value
& 0xff;
181 int lshift
= (kcontrol
->private_value
>> 8) & 0xff;
182 int inverted
= (kcontrol
->private_value
>> 16) & 1;
187 vol
[0] = ucontrol
->value
.integer
.value
[0];
188 vol
[1] = ucontrol
->value
.integer
.value
[1];
190 vol
[0] = 0x0f - vol
[0];
191 vol
[1] = 0x0f - vol
[1];
195 spin_lock_irqsave(&chip
->reg_lock
, flags
);
196 oldval
= chip
->awacs_reg
[reg
];
197 val
= oldval
& ~(0xf | (0xf << lshift
));
198 val
|= vol
[0] << lshift
;
201 snd_pmac_awacs_write_reg(chip
, reg
, val
);
202 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
203 return oldval
!= reg
;
207 #define AWACS_VOLUME(xname, xreg, xshift, xinverted) \
208 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
209 .info = snd_pmac_awacs_info_volume, \
210 .get = snd_pmac_awacs_get_volume, \
211 .put = snd_pmac_awacs_put_volume, \
212 .private_value = (xreg) | ((xshift) << 8) | ((xinverted) << 16) }
215 * mute master/ogain for AWACS: mono
217 static int snd_pmac_awacs_get_switch(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
219 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
220 int reg
= kcontrol
->private_value
& 0xff;
221 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
222 int invert
= (kcontrol
->private_value
>> 16) & 1;
226 spin_lock_irqsave(&chip
->reg_lock
, flags
);
227 val
= (chip
->awacs_reg
[reg
] >> shift
) & 1;
228 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
231 ucontrol
->value
.integer
.value
[0] = val
;
235 static int snd_pmac_awacs_put_switch(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
237 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
238 int reg
= kcontrol
->private_value
& 0xff;
239 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
240 int invert
= (kcontrol
->private_value
>> 16) & 1;
241 int mask
= 1 << shift
;
245 spin_lock_irqsave(&chip
->reg_lock
, flags
);
246 val
= chip
->awacs_reg
[reg
] & ~mask
;
247 if (ucontrol
->value
.integer
.value
[0] != invert
)
249 changed
= chip
->awacs_reg
[reg
] != val
;
251 snd_pmac_awacs_write_reg(chip
, reg
, val
);
252 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
256 #define AWACS_SWITCH(xname, xreg, xshift, xinvert) \
257 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
258 .info = snd_pmac_boolean_mono_info, \
259 .get = snd_pmac_awacs_get_switch, \
260 .put = snd_pmac_awacs_put_switch, \
261 .private_value = (xreg) | ((xshift) << 8) | ((xinvert) << 16) }
264 #ifdef PMAC_AMP_AVAIL
266 * controls for perch/whisper extension cards, e.g. G3 desktop
268 * TDA7433 connected via i2c address 0x45 (= 0x8a),
269 * accessed through cuda
271 static void awacs_set_cuda(int reg
, int val
)
273 struct adb_request req
;
274 cuda_request(&req
, NULL
, 5, CUDA_PACKET
, CUDA_GET_SET_IIC
, 0x8a, reg
, val
);
275 while (! req
.complete
)
280 * level = 0 - 14, 7 = 0 dB
282 static void awacs_amp_set_tone(awacs_amp_t
*amp
, int bass
, int treble
)
284 amp
->amp_tone
[0] = bass
;
285 amp
->amp_tone
[1] = treble
;
287 bass
= (14 - bass
) + 8;
289 treble
= (14 - treble
) + 8;
290 awacs_set_cuda(2, (bass
<< 4) | treble
);
294 * vol = 0 - 31 (attenuation), 32 = mute bit, stereo
296 static int awacs_amp_set_vol(awacs_amp_t
*amp
, int index
, int lvol
, int rvol
, int do_check
)
298 if (do_check
&& amp
->amp_vol
[index
][0] == lvol
&&
299 amp
->amp_vol
[index
][1] == rvol
)
301 awacs_set_cuda(3 + index
, lvol
);
302 awacs_set_cuda(5 + index
, rvol
);
303 amp
->amp_vol
[index
][0] = lvol
;
304 amp
->amp_vol
[index
][1] = rvol
;
309 * 0 = -79 dB, 79 = 0 dB, 99 = +20 dB
311 static void awacs_amp_set_master(awacs_amp_t
*amp
, int vol
)
313 amp
->amp_master
= vol
;
315 vol
= 32 + (79 - vol
);
317 vol
= 32 - (vol
- 79);
318 awacs_set_cuda(1, vol
);
321 static void awacs_amp_free(pmac_t
*chip
)
323 awacs_amp_t
*amp
= chip
->mixer_data
;
324 snd_assert(amp
, return);
326 chip
->mixer_data
= NULL
;
327 chip
->mixer_free
= NULL
;
334 static int snd_pmac_awacs_info_volume_amp(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
336 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
338 uinfo
->value
.integer
.min
= 0;
339 uinfo
->value
.integer
.max
= 31;
343 static int snd_pmac_awacs_get_volume_amp(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
345 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
346 int index
= kcontrol
->private_value
;
347 awacs_amp_t
*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(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
357 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
358 int index
= kcontrol
->private_value
;
360 awacs_amp_t
*amp
= chip
->mixer_data
;
361 snd_assert(amp
, return -EINVAL
);
362 snd_assert(index
>= 0 && index
<= 1, return -EINVAL
);
364 vol
[0] = (31 - (ucontrol
->value
.integer
.value
[0] & 31)) | (amp
->amp_vol
[index
][0] & 32);
365 vol
[1] = (31 - (ucontrol
->value
.integer
.value
[1] & 31)) | (amp
->amp_vol
[index
][1] & 32);
366 return awacs_amp_set_vol(amp
, index
, vol
[0], vol
[1], 1);
369 static int snd_pmac_awacs_get_switch_amp(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
371 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
372 int index
= kcontrol
->private_value
;
373 awacs_amp_t
*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(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
383 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
384 int index
= kcontrol
->private_value
;
386 awacs_amp_t
*amp
= chip
->mixer_data
;
387 snd_assert(amp
, return -EINVAL
);
388 snd_assert(index
>= 0 && index
<= 1, return -EINVAL
);
390 vol
[0] = (ucontrol
->value
.integer
.value
[0] ? 0 : 32) | (amp
->amp_vol
[index
][0] & 31);
391 vol
[1] = (ucontrol
->value
.integer
.value
[1] ? 0 : 32) | (amp
->amp_vol
[index
][1] & 31);
392 return awacs_amp_set_vol(amp
, index
, vol
[0], vol
[1], 1);
395 static int snd_pmac_awacs_info_tone_amp(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
397 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
399 uinfo
->value
.integer
.min
= 0;
400 uinfo
->value
.integer
.max
= 14;
404 static int snd_pmac_awacs_get_tone_amp(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
406 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
407 int index
= kcontrol
->private_value
;
408 awacs_amp_t
*amp
= chip
->mixer_data
;
409 snd_assert(amp
, return -EINVAL
);
410 snd_assert(index
>= 0 && index
<= 1, return -EINVAL
);
411 ucontrol
->value
.integer
.value
[0] = amp
->amp_tone
[index
];
415 static int snd_pmac_awacs_put_tone_amp(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
417 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
418 int index
= kcontrol
->private_value
;
419 awacs_amp_t
*amp
= chip
->mixer_data
;
420 snd_assert(amp
, return -EINVAL
);
421 snd_assert(index
>= 0 && index
<= 1, return -EINVAL
);
422 if (ucontrol
->value
.integer
.value
[0] != amp
->amp_tone
[index
]) {
423 amp
->amp_tone
[index
] = ucontrol
->value
.integer
.value
[0];
424 awacs_amp_set_tone(amp
, amp
->amp_tone
[0], amp
->amp_tone
[1]);
430 static int snd_pmac_awacs_info_master_amp(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
432 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
434 uinfo
->value
.integer
.min
= 0;
435 uinfo
->value
.integer
.max
= 99;
439 static int snd_pmac_awacs_get_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 ucontrol
->value
.integer
.value
[0] = amp
->amp_master
;
448 static int snd_pmac_awacs_put_master_amp(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
450 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
451 awacs_amp_t
*amp
= chip
->mixer_data
;
452 snd_assert(amp
, return -EINVAL
);
453 if (ucontrol
->value
.integer
.value
[0] != amp
->amp_master
) {
454 amp
->amp_master
= ucontrol
->value
.integer
.value
[0];
455 awacs_amp_set_master(amp
, amp
->amp_master
);
464 static snd_kcontrol_new_t snd_pmac_awacs_amp_vol
[] __initdata
= {
465 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
466 .name
= "PC Speaker Playback Volume",
467 .info
= snd_pmac_awacs_info_volume_amp
,
468 .get
= snd_pmac_awacs_get_volume_amp
,
469 .put
= snd_pmac_awacs_put_volume_amp
,
470 .private_value
= AMP_CH_SPK
,
472 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
473 .name
= "Headphone 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_HD
,
479 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
480 .name
= "Tone Control - Bass",
481 .info
= snd_pmac_awacs_info_tone_amp
,
482 .get
= snd_pmac_awacs_get_tone_amp
,
483 .put
= snd_pmac_awacs_put_tone_amp
,
486 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
487 .name
= "Tone Control - Treble",
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
= "Amp Master Playback Volume",
495 .info
= snd_pmac_awacs_info_master_amp
,
496 .get
= snd_pmac_awacs_get_master_amp
,
497 .put
= snd_pmac_awacs_put_master_amp
,
501 static snd_kcontrol_new_t snd_pmac_awacs_amp_hp_sw __initdata
= {
502 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
503 .name
= "Headphone 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_HD
,
510 static snd_kcontrol_new_t snd_pmac_awacs_amp_spk_sw __initdata
= {
511 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
512 .name
= "PC Speaker Playback Switch",
513 .info
= snd_pmac_boolean_stereo_info
,
514 .get
= snd_pmac_awacs_get_switch_amp
,
515 .put
= snd_pmac_awacs_put_switch_amp
,
516 .private_value
= AMP_CH_SPK
,
519 #endif /* PMAC_AMP_AVAIL */
523 * mic boost for screamer
525 static int snd_pmac_screamer_mic_boost_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
527 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
529 uinfo
->value
.integer
.min
= 0;
530 uinfo
->value
.integer
.max
= 2;
534 static int snd_pmac_screamer_mic_boost_get(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
536 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
540 spin_lock_irqsave(&chip
->reg_lock
, flags
);
541 if (chip
->awacs_reg
[6] & MASK_MIC_BOOST
)
543 else if (chip
->awacs_reg
[0] & MASK_GAINLINE
)
547 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
548 ucontrol
->value
.integer
.value
[0] = val
;
552 static int snd_pmac_screamer_mic_boost_put(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
554 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
559 spin_lock_irqsave(&chip
->reg_lock
, flags
);
560 val0
= chip
->awacs_reg
[0] & ~MASK_GAINLINE
;
561 val6
= chip
->awacs_reg
[6] & ~MASK_MIC_BOOST
;
562 if (ucontrol
->value
.integer
.value
[0] > 0) {
563 val0
|= MASK_GAINLINE
;
564 if (ucontrol
->value
.integer
.value
[0] > 1)
565 val6
|= MASK_MIC_BOOST
;
567 if (val0
!= chip
->awacs_reg
[0]) {
568 snd_pmac_awacs_write_reg(chip
, 0, val0
);
571 if (val6
!= chip
->awacs_reg
[6]) {
572 snd_pmac_awacs_write_reg(chip
, 6, val6
);
575 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
580 * lists of mixer elements
582 static snd_kcontrol_new_t snd_pmac_awacs_mixers
[] __initdata
= {
583 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
584 AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU
, 0),
585 AWACS_VOLUME("Capture Volume", 0, 4, 0),
586 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_LINE
, 0),
587 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD
, 0),
588 AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_MIC
, 0),
591 static snd_kcontrol_new_t snd_pmac_awacs_master_sw __initdata
=
592 AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE
, 1);
594 static snd_kcontrol_new_t snd_pmac_awacs_mic_boost
[] __initdata
= {
595 AWACS_SWITCH("Mic Boost", 0, SHIFT_GAINLINE
, 0),
598 static snd_kcontrol_new_t snd_pmac_screamer_mic_boost
[] __initdata
= {
599 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
601 .info
= snd_pmac_screamer_mic_boost_info
,
602 .get
= snd_pmac_screamer_mic_boost_get
,
603 .put
= snd_pmac_screamer_mic_boost_put
,
607 static snd_kcontrol_new_t snd_pmac_awacs_speaker_vol
[] __initdata
= {
608 AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1),
610 static snd_kcontrol_new_t snd_pmac_awacs_speaker_sw __initdata
=
611 AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE
, 1);
614 #define num_controls(ary) (sizeof(ary) / sizeof(snd_kcontrol_new_t))
617 * add new mixer elements to the card
619 static int build_mixers(pmac_t
*chip
, int nums
, snd_kcontrol_new_t
*mixers
)
623 for (i
= 0; i
< nums
; i
++) {
624 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&mixers
[i
], chip
))) < 0)
632 * restore all registers
634 static void awacs_restore_all_regs(pmac_t
*chip
, int can_schedule
)
636 snd_pmac_awacs_write_noreg(chip
, 0, chip
->awacs_reg
[0]);
637 snd_pmac_awacs_write_noreg(chip
, 1, chip
->awacs_reg
[1]);
638 snd_pmac_awacs_write_noreg(chip
, 2, chip
->awacs_reg
[2]);
639 snd_pmac_awacs_write_noreg(chip
, 4, chip
->awacs_reg
[4]);
640 if (chip
->model
== PMAC_SCREAMER
) {
641 snd_pmac_awacs_write_noreg(chip
, 5, chip
->awacs_reg
[5]);
642 snd_pmac_awacs_write_noreg(chip
, 6, chip
->awacs_reg
[6]);
643 snd_pmac_awacs_write_noreg(chip
, 7, chip
->awacs_reg
[7]);
647 #ifdef CONFIG_PMAC_PBOOK
648 static void snd_pmac_awacs_suspend(pmac_t
*chip
)
650 snd_pmac_awacs_write_noreg(chip
, 1, (chip
->awacs_reg
[1]
651 | MASK_AMUTE
| MASK_CMUTE
));
654 static void snd_pmac_awacs_resume(pmac_t
*chip
)
656 if (machine_is_compatible("PowerBook3,1")
657 || machine_is_compatible("PowerBook3,2")) {
659 snd_pmac_awacs_write_reg(chip
, 1,
660 chip
->awacs_reg
[1] & ~MASK_PAROUT
);
664 awacs_restore_all_regs(chip
, 0);
665 if (chip
->model
== PMAC_SCREAMER
) {
666 /* reset power bits in reg 6 */
668 snd_pmac_awacs_write_noreg(chip
, 6, chip
->awacs_reg
[6]);
670 screamer_recalibrate(chip
, 0);
671 #ifdef PMAC_AMP_AVAIL
672 if (chip
->mixer_data
) {
673 awacs_amp_t
*amp
= chip
->mixer_data
;
674 awacs_amp_set_vol(amp
, 0, amp
->amp_vol
[0][0], amp
->amp_vol
[0][1], 0);
675 awacs_amp_set_vol(amp
, 1, amp
->amp_vol
[1][0], amp
->amp_vol
[1][1], 0);
676 awacs_amp_set_tone(amp
, amp
->amp_tone
[0], amp
->amp_tone
[1]);
677 awacs_amp_set_master(amp
, amp
->amp_master
);
681 #endif /* CONFIG_PMAC_PBOOK */
683 #ifdef PMAC_SUPPORT_AUTOMUTE
687 static int snd_pmac_awacs_detect_headphone(pmac_t
*chip
)
689 return (in_le32(&chip
->awacs
->codec_stat
) & chip
->hp_stat_mask
) ? 1 : 0;
692 #ifdef PMAC_AMP_AVAIL
693 static int toggle_amp_mute(awacs_amp_t
*amp
, int index
, int mute
)
696 vol
[0] = amp
->amp_vol
[index
][0] & 31;
697 vol
[1] = amp
->amp_vol
[index
][1] & 31;
702 return awacs_amp_set_vol(amp
, index
, vol
[0], vol
[1], 1);
706 static void snd_pmac_awacs_update_automute(pmac_t
*chip
, int do_notify
)
708 if (chip
->auto_mute
) {
709 #ifdef PMAC_AMP_AVAIL
710 if (chip
->mixer_data
) {
711 awacs_amp_t
*amp
= chip
->mixer_data
;
713 if (snd_pmac_awacs_detect_headphone(chip
)) {
714 changed
= toggle_amp_mute(amp
, AMP_CH_HD
, 0);
715 changed
|= toggle_amp_mute(amp
, AMP_CH_SPK
, 1);
717 changed
= toggle_amp_mute(amp
, AMP_CH_HD
, 1);
718 changed
|= toggle_amp_mute(amp
, AMP_CH_SPK
, 0);
720 if (do_notify
&& ! changed
)
725 int reg
= chip
->awacs_reg
[1] | (MASK_HDMUTE
|MASK_SPKMUTE
);
726 if (snd_pmac_awacs_detect_headphone(chip
))
729 reg
&= ~MASK_SPKMUTE
;
730 if (do_notify
&& reg
== chip
->awacs_reg
[1])
732 snd_pmac_awacs_write_reg(chip
, 1, reg
);
735 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
736 &chip
->master_sw_ctl
->id
);
737 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
738 &chip
->speaker_sw_ctl
->id
);
739 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
740 &chip
->hp_detect_ctl
->id
);
744 #endif /* PMAC_SUPPORT_AUTOMUTE */
751 snd_pmac_awacs_init(pmac_t
*chip
)
755 /* looks like MASK_GAINLINE triggers something, so we set here
758 chip
->awacs_reg
[0] = MASK_MUX_CD
| 0xff | MASK_GAINLINE
;
759 chip
->awacs_reg
[1] = MASK_CMUTE
| MASK_AMUTE
;
760 /* FIXME: Only machines with external SRS module need MASK_PAROUT */
761 if (chip
->has_iic
|| chip
->device_id
== 0x5 ||
762 /*chip->_device_id == 0x8 || */
763 chip
->device_id
== 0xb)
764 chip
->awacs_reg
[1] |= MASK_PAROUT
;
765 /* get default volume from nvram */
766 // vol = (~nvram_read_byte(0x1308) & 7) << 1;
767 // vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
768 vol
= 0x0f; /* no, on alsa, muted as default */
769 vol
= vol
+ (vol
<< 6);
770 chip
->awacs_reg
[2] = vol
;
771 chip
->awacs_reg
[4] = vol
;
772 if (chip
->model
== PMAC_SCREAMER
) {
773 chip
->awacs_reg
[5] = vol
; /* FIXME: screamer has loopthru vol control */
774 chip
->awacs_reg
[6] = MASK_MIC_BOOST
; /* FIXME: maybe should be vol << 3 for PCMCIA speaker */
775 chip
->awacs_reg
[7] = 0;
778 awacs_restore_all_regs(chip
, 1);
779 chip
->manufacturer
= (in_le32(&chip
->awacs
->codec_stat
) >> 8) & 0xf;
780 screamer_recalibrate(chip
, 1);
782 chip
->revision
= (in_le32(&chip
->awacs
->codec_stat
) >> 12) & 0xf;
783 #ifdef PMAC_AMP_AVAIL
784 if (chip
->revision
== 3 && chip
->has_iic
&& CHECK_CUDA_AMP()) {
785 awacs_amp_t
*amp
= kmalloc(sizeof(*amp
), GFP_KERNEL
);
788 chip
->mixer_data
= amp
;
789 memset(amp
, 0, sizeof(*amp
));
790 chip
->mixer_free
= awacs_amp_free
;
791 awacs_amp_set_vol(amp
, 0, 63, 63, 0); /* mute and zero vol */
792 awacs_amp_set_vol(amp
, 1, 63, 63, 0);
793 awacs_amp_set_tone(amp
, 7, 7); /* 0 dB */
794 awacs_amp_set_master(amp
, 79); /* 0 dB */
796 #endif /* PMAC_AMP_AVAIL */
798 if (chip
->hp_stat_mask
== 0) {
799 /* set headphone-jack detection bit */
800 switch (chip
->model
) {
802 chip
->hp_stat_mask
= 0x04;
805 switch (chip
->device_id
) {
807 /* 1 = side jack, 2 = front jack */
808 chip
->hp_stat_mask
= 0x03;
812 chip
->hp_stat_mask
= 0x04;
815 chip
->hp_stat_mask
= 0x08;
828 strcpy(chip
->card
->mixername
, "PowerMac AWACS");
830 if ((err
= build_mixers(chip
, num_controls(snd_pmac_awacs_mixers
),
831 snd_pmac_awacs_mixers
)) < 0)
833 chip
->master_sw_ctl
= snd_ctl_new1(&snd_pmac_awacs_master_sw
, chip
);
834 if ((err
= snd_ctl_add(chip
->card
, chip
->master_sw_ctl
)) < 0)
836 #ifdef PMAC_AMP_AVAIL
837 if (chip
->mixer_data
) {
838 /* use amplifier. the signal is connected from route A
839 * to the amp. the amp has its headphone and speaker
840 * volumes and mute switches, so we use them instead of
841 * screamer registers.
842 * in this case, it seems the route C is not used.
844 if ((err
= build_mixers(chip
, num_controls(snd_pmac_awacs_amp_vol
),
845 snd_pmac_awacs_amp_vol
)) < 0)
848 chip
->master_sw_ctl
= snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw
, chip
);
849 if ((err
= snd_ctl_add(chip
->card
, chip
->master_sw_ctl
)) < 0)
851 chip
->speaker_sw_ctl
= snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw
, chip
);
852 if ((err
= snd_ctl_add(chip
->card
, chip
->speaker_sw_ctl
)) < 0)
855 #endif /* PMAC_AMP_AVAIL */
857 /* route A = headphone, route C = speaker */
858 if ((err
= build_mixers(chip
, num_controls(snd_pmac_awacs_speaker_vol
),
859 snd_pmac_awacs_speaker_vol
)) < 0)
861 chip
->speaker_sw_ctl
= snd_ctl_new1(&snd_pmac_awacs_speaker_sw
, chip
);
862 if ((err
= snd_ctl_add(chip
->card
, chip
->speaker_sw_ctl
)) < 0)
866 if (chip
->model
== PMAC_SCREAMER
) {
867 if ((err
= build_mixers(chip
, num_controls(snd_pmac_screamer_mic_boost
),
868 snd_pmac_screamer_mic_boost
)) < 0)
871 if ((err
= build_mixers(chip
, num_controls(snd_pmac_awacs_mic_boost
),
872 snd_pmac_awacs_mic_boost
)) < 0)
877 * set lowlevel callbacks
879 chip
->set_format
= snd_pmac_awacs_set_format
;
880 #ifdef CONFIG_PMAC_PBOOK
881 chip
->suspend
= snd_pmac_awacs_suspend
;
882 chip
->resume
= snd_pmac_awacs_resume
;
884 #ifdef PMAC_SUPPORT_AUTOMUTE
885 if ((err
= snd_pmac_add_automute(chip
)) < 0)
887 chip
->detect_headphone
= snd_pmac_awacs_detect_headphone
;
888 chip
->update_automute
= snd_pmac_awacs_update_automute
;
889 snd_pmac_awacs_update_automute(chip
, 0); /* update the status only */
891 if (chip
->model
== PMAC_SCREAMER
) {
892 snd_pmac_awacs_write_noreg(chip
, 6, chip
->awacs_reg
[6]);
893 snd_pmac_awacs_write_noreg(chip
, 0, chip
->awacs_reg
[0]);