2 * PMac Burgundy 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 <linux/init.h>
24 #include <linux/slab.h>
25 #include <linux/delay.h>
26 #include <sound/core.h>
31 /* Waits for busy flag to clear */
33 snd_pmac_burgundy_busy_wait(struct snd_pmac
*chip
)
36 while ((in_le32(&chip
->awacs
->codec_ctrl
) & MASK_NEWECMD
) && timeout
--)
39 printk(KERN_DEBUG
"burgundy_busy_wait: timeout\n");
43 snd_pmac_burgundy_extend_wait(struct snd_pmac
*chip
)
47 while (!(in_le32(&chip
->awacs
->codec_stat
) & MASK_EXTEND
) && timeout
--)
50 printk(KERN_DEBUG
"burgundy_extend_wait: timeout #1\n");
52 while ((in_le32(&chip
->awacs
->codec_stat
) & MASK_EXTEND
) && timeout
--)
55 printk(KERN_DEBUG
"burgundy_extend_wait: timeout #2\n");
59 snd_pmac_burgundy_wcw(struct snd_pmac
*chip
, unsigned addr
, unsigned val
)
61 out_le32(&chip
->awacs
->codec_ctrl
, addr
+ 0x200c00 + (val
& 0xff));
62 snd_pmac_burgundy_busy_wait(chip
);
63 out_le32(&chip
->awacs
->codec_ctrl
, addr
+ 0x200d00 +((val
>>8) & 0xff));
64 snd_pmac_burgundy_busy_wait(chip
);
65 out_le32(&chip
->awacs
->codec_ctrl
, addr
+ 0x200e00 +((val
>>16) & 0xff));
66 snd_pmac_burgundy_busy_wait(chip
);
67 out_le32(&chip
->awacs
->codec_ctrl
, addr
+ 0x200f00 +((val
>>24) & 0xff));
68 snd_pmac_burgundy_busy_wait(chip
);
72 snd_pmac_burgundy_rcw(struct snd_pmac
*chip
, unsigned addr
)
77 spin_lock_irqsave(&chip
->reg_lock
, flags
);
79 out_le32(&chip
->awacs
->codec_ctrl
, addr
+ 0x100000);
80 snd_pmac_burgundy_busy_wait(chip
);
81 snd_pmac_burgundy_extend_wait(chip
);
82 val
+= (in_le32(&chip
->awacs
->codec_stat
) >> 4) & 0xff;
84 out_le32(&chip
->awacs
->codec_ctrl
, addr
+ 0x100100);
85 snd_pmac_burgundy_busy_wait(chip
);
86 snd_pmac_burgundy_extend_wait(chip
);
87 val
+= ((in_le32(&chip
->awacs
->codec_stat
)>>4) & 0xff) <<8;
89 out_le32(&chip
->awacs
->codec_ctrl
, addr
+ 0x100200);
90 snd_pmac_burgundy_busy_wait(chip
);
91 snd_pmac_burgundy_extend_wait(chip
);
92 val
+= ((in_le32(&chip
->awacs
->codec_stat
)>>4) & 0xff) <<16;
94 out_le32(&chip
->awacs
->codec_ctrl
, addr
+ 0x100300);
95 snd_pmac_burgundy_busy_wait(chip
);
96 snd_pmac_burgundy_extend_wait(chip
);
97 val
+= ((in_le32(&chip
->awacs
->codec_stat
)>>4) & 0xff) <<24;
99 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
105 snd_pmac_burgundy_wcb(struct snd_pmac
*chip
, unsigned int addr
, unsigned int val
)
107 out_le32(&chip
->awacs
->codec_ctrl
, addr
+ 0x300000 + (val
& 0xff));
108 snd_pmac_burgundy_busy_wait(chip
);
112 snd_pmac_burgundy_rcb(struct snd_pmac
*chip
, unsigned int addr
)
117 spin_lock_irqsave(&chip
->reg_lock
, flags
);
119 out_le32(&chip
->awacs
->codec_ctrl
, addr
+ 0x100000);
120 snd_pmac_burgundy_busy_wait(chip
);
121 snd_pmac_burgundy_extend_wait(chip
);
122 val
+= (in_le32(&chip
->awacs
->codec_stat
) >> 4) & 0xff;
124 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
130 * Burgundy volume: 0 - 100, stereo
133 snd_pmac_burgundy_write_volume(struct snd_pmac
*chip
, unsigned int address
,
134 long *volume
, int shift
)
136 int hardvolume
, lvolume
, rvolume
;
138 if (volume
[0] < 0 || volume
[0] > 100 ||
139 volume
[1] < 0 || volume
[1] > 100)
140 return; /* -EINVAL */
141 lvolume
= volume
[0] ? volume
[0] + BURGUNDY_VOLUME_OFFSET
: 0;
142 rvolume
= volume
[1] ? volume
[1] + BURGUNDY_VOLUME_OFFSET
: 0;
144 hardvolume
= lvolume
+ (rvolume
<< shift
);
146 hardvolume
|= hardvolume
<< 16;
148 snd_pmac_burgundy_wcw(chip
, address
, hardvolume
);
152 snd_pmac_burgundy_read_volume(struct snd_pmac
*chip
, unsigned int address
,
153 long *volume
, int shift
)
157 wvolume
= snd_pmac_burgundy_rcw(chip
, address
);
159 volume
[0] = wvolume
& 0xff;
160 if (volume
[0] >= BURGUNDY_VOLUME_OFFSET
)
161 volume
[0] -= BURGUNDY_VOLUME_OFFSET
;
164 volume
[1] = (wvolume
>> shift
) & 0xff;
165 if (volume
[1] >= BURGUNDY_VOLUME_OFFSET
)
166 volume
[1] -= BURGUNDY_VOLUME_OFFSET
;
175 #define BASE2ADDR(base) ((base) << 12)
176 #define ADDR2BASE(addr) ((addr) >> 12)
178 static int snd_pmac_burgundy_info_volume(struct snd_kcontrol
*kcontrol
,
179 struct snd_ctl_elem_info
*uinfo
)
181 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
183 uinfo
->value
.integer
.min
= 0;
184 uinfo
->value
.integer
.max
= 100;
188 static int snd_pmac_burgundy_get_volume(struct snd_kcontrol
*kcontrol
,
189 struct snd_ctl_elem_value
*ucontrol
)
191 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
192 unsigned int addr
= BASE2ADDR(kcontrol
->private_value
& 0xff);
193 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
194 snd_pmac_burgundy_read_volume(chip
, addr
, ucontrol
->value
.integer
.value
,
199 static int snd_pmac_burgundy_put_volume(struct snd_kcontrol
*kcontrol
,
200 struct snd_ctl_elem_value
*ucontrol
)
202 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
203 unsigned int addr
= BASE2ADDR(kcontrol
->private_value
& 0xff);
204 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
207 snd_pmac_burgundy_write_volume(chip
, addr
, ucontrol
->value
.integer
.value
,
209 snd_pmac_burgundy_read_volume(chip
, addr
, nvoices
, shift
);
210 return (nvoices
[0] != ucontrol
->value
.integer
.value
[0] ||
211 nvoices
[1] != ucontrol
->value
.integer
.value
[1]);
214 #define BURGUNDY_VOLUME_W(xname, xindex, addr, shift) \
215 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
216 .info = snd_pmac_burgundy_info_volume,\
217 .get = snd_pmac_burgundy_get_volume,\
218 .put = snd_pmac_burgundy_put_volume,\
219 .private_value = ((ADDR2BASE(addr) & 0xff) | ((shift) << 8)) }
222 * Burgundy volume: 0 - 100, stereo, 2-byte reg
225 snd_pmac_burgundy_write_volume_2b(struct snd_pmac
*chip
, unsigned int address
,
226 long *volume
, int off
)
228 int lvolume
, rvolume
;
231 lvolume
= volume
[0] ? volume
[0] + BURGUNDY_VOLUME_OFFSET
: 0;
232 rvolume
= volume
[1] ? volume
[1] + BURGUNDY_VOLUME_OFFSET
: 0;
234 snd_pmac_burgundy_wcb(chip
, address
+ off
, lvolume
);
235 snd_pmac_burgundy_wcb(chip
, address
+ off
+ 0x500, rvolume
);
239 snd_pmac_burgundy_read_volume_2b(struct snd_pmac
*chip
, unsigned int address
,
240 long *volume
, int off
)
242 volume
[0] = snd_pmac_burgundy_rcb(chip
, address
+ off
);
243 if (volume
[0] >= BURGUNDY_VOLUME_OFFSET
)
244 volume
[0] -= BURGUNDY_VOLUME_OFFSET
;
247 volume
[1] = snd_pmac_burgundy_rcb(chip
, address
+ off
+ 0x100);
248 if (volume
[1] >= BURGUNDY_VOLUME_OFFSET
)
249 volume
[1] -= BURGUNDY_VOLUME_OFFSET
;
254 static int snd_pmac_burgundy_info_volume_2b(struct snd_kcontrol
*kcontrol
,
255 struct snd_ctl_elem_info
*uinfo
)
257 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
259 uinfo
->value
.integer
.min
= 0;
260 uinfo
->value
.integer
.max
= 100;
264 static int snd_pmac_burgundy_get_volume_2b(struct snd_kcontrol
*kcontrol
,
265 struct snd_ctl_elem_value
*ucontrol
)
267 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
268 unsigned int addr
= BASE2ADDR(kcontrol
->private_value
& 0xff);
269 int off
= kcontrol
->private_value
& 0x300;
270 snd_pmac_burgundy_read_volume_2b(chip
, addr
,
271 ucontrol
->value
.integer
.value
, off
);
275 static int snd_pmac_burgundy_put_volume_2b(struct snd_kcontrol
*kcontrol
,
276 struct snd_ctl_elem_value
*ucontrol
)
278 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
279 unsigned int addr
= BASE2ADDR(kcontrol
->private_value
& 0xff);
280 int off
= kcontrol
->private_value
& 0x300;
283 snd_pmac_burgundy_write_volume_2b(chip
, addr
,
284 ucontrol
->value
.integer
.value
, off
);
285 snd_pmac_burgundy_read_volume_2b(chip
, addr
, nvoices
, off
);
286 return (nvoices
[0] != ucontrol
->value
.integer
.value
[0] ||
287 nvoices
[1] != ucontrol
->value
.integer
.value
[1]);
290 #define BURGUNDY_VOLUME_2B(xname, xindex, addr, off) \
291 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
292 .info = snd_pmac_burgundy_info_volume_2b,\
293 .get = snd_pmac_burgundy_get_volume_2b,\
294 .put = snd_pmac_burgundy_put_volume_2b,\
295 .private_value = ((ADDR2BASE(addr) & 0xff) | ((off) << 8)) }
298 * Burgundy gain/attenuation: 0 - 15, mono/stereo, byte reg
300 static int snd_pmac_burgundy_info_gain(struct snd_kcontrol
*kcontrol
,
301 struct snd_ctl_elem_info
*uinfo
)
303 int stereo
= (kcontrol
->private_value
>> 24) & 1;
304 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
305 uinfo
->count
= stereo
+ 1;
306 uinfo
->value
.integer
.min
= 0;
307 uinfo
->value
.integer
.max
= 15;
311 static int snd_pmac_burgundy_get_gain(struct snd_kcontrol
*kcontrol
,
312 struct snd_ctl_elem_value
*ucontrol
)
314 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
315 unsigned int addr
= BASE2ADDR(kcontrol
->private_value
& 0xff);
316 int stereo
= (kcontrol
->private_value
>> 24) & 1;
317 int atten
= (kcontrol
->private_value
>> 25) & 1;
320 oval
= snd_pmac_burgundy_rcb(chip
, addr
);
323 ucontrol
->value
.integer
.value
[0] = oval
& 0xf;
325 ucontrol
->value
.integer
.value
[1] = (oval
>> 4) & 0xf;
329 static int snd_pmac_burgundy_put_gain(struct snd_kcontrol
*kcontrol
,
330 struct snd_ctl_elem_value
*ucontrol
)
332 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
333 unsigned int addr
= BASE2ADDR(kcontrol
->private_value
& 0xff);
334 int stereo
= (kcontrol
->private_value
>> 24) & 1;
335 int atten
= (kcontrol
->private_value
>> 25) & 1;
338 oval
= snd_pmac_burgundy_rcb(chip
, addr
);
341 val
= ucontrol
->value
.integer
.value
[0];
343 val
|= ucontrol
->value
.integer
.value
[1] << 4;
345 val
|= ucontrol
->value
.integer
.value
[0] << 4;
348 snd_pmac_burgundy_wcb(chip
, addr
, val
);
352 #define BURGUNDY_VOLUME_B(xname, xindex, addr, stereo, atten) \
353 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
354 .info = snd_pmac_burgundy_info_gain,\
355 .get = snd_pmac_burgundy_get_gain,\
356 .put = snd_pmac_burgundy_put_gain,\
357 .private_value = (ADDR2BASE(addr) | ((stereo) << 24) | ((atten) << 25)) }
360 * Burgundy switch: 0/1, mono/stereo, word reg
362 static int snd_pmac_burgundy_info_switch_w(struct snd_kcontrol
*kcontrol
,
363 struct snd_ctl_elem_info
*uinfo
)
365 int stereo
= (kcontrol
->private_value
>> 24) & 1;
366 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
367 uinfo
->count
= stereo
+ 1;
368 uinfo
->value
.integer
.min
= 0;
369 uinfo
->value
.integer
.max
= 1;
373 static int snd_pmac_burgundy_get_switch_w(struct snd_kcontrol
*kcontrol
,
374 struct snd_ctl_elem_value
*ucontrol
)
376 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
377 unsigned int addr
= BASE2ADDR((kcontrol
->private_value
>> 16) & 0xff);
378 int lmask
= 1 << (kcontrol
->private_value
& 0xff);
379 int rmask
= 1 << ((kcontrol
->private_value
>> 8) & 0xff);
380 int stereo
= (kcontrol
->private_value
>> 24) & 1;
381 int val
= snd_pmac_burgundy_rcw(chip
, addr
);
382 ucontrol
->value
.integer
.value
[0] = (val
& lmask
) ? 1 : 0;
384 ucontrol
->value
.integer
.value
[1] = (val
& rmask
) ? 1 : 0;
388 static int snd_pmac_burgundy_put_switch_w(struct snd_kcontrol
*kcontrol
,
389 struct snd_ctl_elem_value
*ucontrol
)
391 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
392 unsigned int addr
= BASE2ADDR((kcontrol
->private_value
>> 16) & 0xff);
393 int lmask
= 1 << (kcontrol
->private_value
& 0xff);
394 int rmask
= 1 << ((kcontrol
->private_value
>> 8) & 0xff);
395 int stereo
= (kcontrol
->private_value
>> 24) & 1;
397 oval
= snd_pmac_burgundy_rcw(chip
, addr
);
398 val
= oval
& ~(lmask
| (stereo
? rmask
: 0));
399 if (ucontrol
->value
.integer
.value
[0])
401 if (stereo
&& ucontrol
->value
.integer
.value
[1])
403 snd_pmac_burgundy_wcw(chip
, addr
, val
);
407 #define BURGUNDY_SWITCH_W(xname, xindex, addr, lbit, rbit, stereo) \
408 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
409 .info = snd_pmac_burgundy_info_switch_w,\
410 .get = snd_pmac_burgundy_get_switch_w,\
411 .put = snd_pmac_burgundy_put_switch_w,\
412 .private_value = ((lbit) | ((rbit) << 8)\
413 | (ADDR2BASE(addr) << 16) | ((stereo) << 24)) }
416 * Burgundy switch: 0/1, mono/stereo, byte reg, bit mask
418 static int snd_pmac_burgundy_info_switch_b(struct snd_kcontrol
*kcontrol
,
419 struct snd_ctl_elem_info
*uinfo
)
421 int stereo
= (kcontrol
->private_value
>> 24) & 1;
422 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
423 uinfo
->count
= stereo
+ 1;
424 uinfo
->value
.integer
.min
= 0;
425 uinfo
->value
.integer
.max
= 1;
429 static int snd_pmac_burgundy_get_switch_b(struct snd_kcontrol
*kcontrol
,
430 struct snd_ctl_elem_value
*ucontrol
)
432 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
433 unsigned int addr
= BASE2ADDR((kcontrol
->private_value
>> 16) & 0xff);
434 int lmask
= kcontrol
->private_value
& 0xff;
435 int rmask
= (kcontrol
->private_value
>> 8) & 0xff;
436 int stereo
= (kcontrol
->private_value
>> 24) & 1;
437 int val
= snd_pmac_burgundy_rcb(chip
, addr
);
438 ucontrol
->value
.integer
.value
[0] = (val
& lmask
) ? 1 : 0;
440 ucontrol
->value
.integer
.value
[1] = (val
& rmask
) ? 1 : 0;
444 static int snd_pmac_burgundy_put_switch_b(struct snd_kcontrol
*kcontrol
,
445 struct snd_ctl_elem_value
*ucontrol
)
447 struct snd_pmac
*chip
= snd_kcontrol_chip(kcontrol
);
448 unsigned int addr
= BASE2ADDR((kcontrol
->private_value
>> 16) & 0xff);
449 int lmask
= kcontrol
->private_value
& 0xff;
450 int rmask
= (kcontrol
->private_value
>> 8) & 0xff;
451 int stereo
= (kcontrol
->private_value
>> 24) & 1;
453 oval
= snd_pmac_burgundy_rcb(chip
, addr
);
454 val
= oval
& ~(lmask
| rmask
);
455 if (ucontrol
->value
.integer
.value
[0])
457 if (stereo
&& ucontrol
->value
.integer
.value
[1])
459 snd_pmac_burgundy_wcb(chip
, addr
, val
);
463 #define BURGUNDY_SWITCH_B(xname, xindex, addr, lmask, rmask, stereo) \
464 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
465 .info = snd_pmac_burgundy_info_switch_b,\
466 .get = snd_pmac_burgundy_get_switch_b,\
467 .put = snd_pmac_burgundy_put_switch_b,\
468 .private_value = ((lmask) | ((rmask) << 8)\
469 | (ADDR2BASE(addr) << 16) | ((stereo) << 24)) }
474 static struct snd_kcontrol_new snd_pmac_burgundy_mixers
[] __initdata
= {
475 BURGUNDY_VOLUME_W("Master Playback Volume", 0,
476 MASK_ADDR_BURGUNDY_MASTER_VOLUME
, 8),
477 BURGUNDY_VOLUME_W("CD Capture Volume", 0,
478 MASK_ADDR_BURGUNDY_VOLCD
, 16),
479 BURGUNDY_VOLUME_2B("Input Capture Volume", 0,
480 MASK_ADDR_BURGUNDY_VOLMIX01
, 2),
481 BURGUNDY_VOLUME_2B("Mixer Playback Volume", 0,
482 MASK_ADDR_BURGUNDY_VOLMIX23
, 0),
483 BURGUNDY_VOLUME_B("CD Gain Capture Volume", 0,
484 MASK_ADDR_BURGUNDY_GAINCD
, 1, 0),
485 BURGUNDY_SWITCH_W("Master Capture Switch", 0,
486 MASK_ADDR_BURGUNDY_OUTPUTENABLES
, 24, 0, 0),
487 BURGUNDY_SWITCH_W("CD Capture Switch", 0,
488 MASK_ADDR_BURGUNDY_CAPTURESELECTS
, 0, 16, 1),
489 BURGUNDY_SWITCH_W("CD Playback Switch", 0,
490 MASK_ADDR_BURGUNDY_OUTPUTSELECTS
, 0, 16, 1),
491 /* BURGUNDY_SWITCH_W("Loop Capture Switch", 0,
492 * MASK_ADDR_BURGUNDY_CAPTURESELECTS, 8, 24, 1),
493 * BURGUNDY_SWITCH_B("Mixer out Capture Switch", 0,
494 * MASK_ADDR_BURGUNDY_HOSTIFAD, 0x02, 0, 0),
495 * BURGUNDY_SWITCH_B("Mixer Capture Switch", 0,
496 * MASK_ADDR_BURGUNDY_HOSTIFAD, 0x01, 0, 0),
497 * BURGUNDY_SWITCH_B("PCM out Capture Switch", 0,
498 * MASK_ADDR_BURGUNDY_HOSTIFEH, 0x02, 0, 0),
499 */ BURGUNDY_SWITCH_B("PCM Capture Switch", 0,
500 MASK_ADDR_BURGUNDY_HOSTIFEH
, 0x01, 0, 0)
502 static struct snd_kcontrol_new snd_pmac_burgundy_mixers_imac
[] __initdata
= {
503 BURGUNDY_VOLUME_W("Line in Capture Volume", 0,
504 MASK_ADDR_BURGUNDY_VOLLINE
, 16),
505 BURGUNDY_VOLUME_W("Mic Capture Volume", 0,
506 MASK_ADDR_BURGUNDY_VOLMIC
, 16),
507 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
508 MASK_ADDR_BURGUNDY_GAINLINE
, 1, 0),
509 BURGUNDY_VOLUME_B("Mic Gain Capture Volume", 0,
510 MASK_ADDR_BURGUNDY_GAINMIC
, 1, 0),
511 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0,
512 MASK_ADDR_BURGUNDY_ATTENSPEAKER
, 1, 1),
513 BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
514 MASK_ADDR_BURGUNDY_ATTENLINEOUT
, 1, 1),
515 BURGUNDY_VOLUME_B("Headphone Playback Volume", 0,
516 MASK_ADDR_BURGUNDY_ATTENHP
, 1, 1),
517 BURGUNDY_SWITCH_W("Line in Capture Switch", 0,
518 MASK_ADDR_BURGUNDY_CAPTURESELECTS
, 1, 17, 1),
519 BURGUNDY_SWITCH_W("Mic Capture Switch", 0,
520 MASK_ADDR_BURGUNDY_CAPTURESELECTS
, 2, 18, 1),
521 BURGUNDY_SWITCH_W("Line in Playback Switch", 0,
522 MASK_ADDR_BURGUNDY_OUTPUTSELECTS
, 1, 17, 1),
523 BURGUNDY_SWITCH_W("Mic Playback Switch", 0,
524 MASK_ADDR_BURGUNDY_OUTPUTSELECTS
, 2, 18, 1),
525 BURGUNDY_SWITCH_B("Mic Boost Capture Switch", 0,
526 MASK_ADDR_BURGUNDY_INPBOOST
, 0x40, 0x80, 1)
528 static struct snd_kcontrol_new snd_pmac_burgundy_mixers_pmac
[] __initdata
= {
529 BURGUNDY_VOLUME_W("Line in Capture Volume", 0,
530 MASK_ADDR_BURGUNDY_VOLMIC
, 16),
531 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
532 MASK_ADDR_BURGUNDY_GAINMIC
, 1, 0),
533 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0,
534 MASK_ADDR_BURGUNDY_ATTENMONO
, 0, 1),
535 BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
536 MASK_ADDR_BURGUNDY_ATTENSPEAKER
, 1, 1),
537 BURGUNDY_SWITCH_W("Line in Capture Switch", 0,
538 MASK_ADDR_BURGUNDY_CAPTURESELECTS
, 2, 18, 1),
539 BURGUNDY_SWITCH_W("Line in Playback Switch", 0,
540 MASK_ADDR_BURGUNDY_OUTPUTSELECTS
, 2, 18, 1),
541 /* BURGUNDY_SWITCH_B("Line in Boost Capture Switch", 0,
542 * MASK_ADDR_BURGUNDY_INPBOOST, 0x40, 0x80, 1) */
544 static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_imac __initdata
=
545 BURGUNDY_SWITCH_B("Master Playback Switch", 0,
546 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
,
547 BURGUNDY_OUTPUT_LEFT
| BURGUNDY_LINEOUT_LEFT
| BURGUNDY_HP_LEFT
,
548 BURGUNDY_OUTPUT_RIGHT
| BURGUNDY_LINEOUT_RIGHT
| BURGUNDY_HP_RIGHT
, 1);
549 static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_pmac __initdata
=
550 BURGUNDY_SWITCH_B("Master Playback Switch", 0,
551 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
,
552 BURGUNDY_OUTPUT_INTERN
553 | BURGUNDY_OUTPUT_LEFT
, BURGUNDY_OUTPUT_RIGHT
, 1);
554 static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_imac __initdata
=
555 BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0,
556 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
,
557 BURGUNDY_OUTPUT_LEFT
, BURGUNDY_OUTPUT_RIGHT
, 1);
558 static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_pmac __initdata
=
559 BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0,
560 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
,
561 BURGUNDY_OUTPUT_INTERN
, 0, 0);
562 static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_imac __initdata
=
563 BURGUNDY_SWITCH_B("Line out Playback Switch", 0,
564 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
,
565 BURGUNDY_LINEOUT_LEFT
, BURGUNDY_LINEOUT_RIGHT
, 1);
566 static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_pmac __initdata
=
567 BURGUNDY_SWITCH_B("Line out Playback Switch", 0,
568 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
,
569 BURGUNDY_OUTPUT_LEFT
, BURGUNDY_OUTPUT_RIGHT
, 1);
570 static struct snd_kcontrol_new snd_pmac_burgundy_hp_sw_imac __initdata
=
571 BURGUNDY_SWITCH_B("Headphone Playback Switch", 0,
572 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
,
573 BURGUNDY_HP_LEFT
, BURGUNDY_HP_RIGHT
, 1);
576 #ifdef PMAC_SUPPORT_AUTOMUTE
580 static int snd_pmac_burgundy_detect_headphone(struct snd_pmac
*chip
)
582 return (in_le32(&chip
->awacs
->codec_stat
) & chip
->hp_stat_mask
) ? 1 : 0;
585 static void snd_pmac_burgundy_update_automute(struct snd_pmac
*chip
, int do_notify
)
587 if (chip
->auto_mute
) {
588 int imac
= machine_is_compatible("iMac");
590 reg
= oreg
= snd_pmac_burgundy_rcb(chip
,
591 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
);
592 reg
&= imac
? ~(BURGUNDY_OUTPUT_LEFT
| BURGUNDY_OUTPUT_RIGHT
593 | BURGUNDY_HP_LEFT
| BURGUNDY_HP_RIGHT
)
594 : ~(BURGUNDY_OUTPUT_LEFT
| BURGUNDY_OUTPUT_RIGHT
595 | BURGUNDY_OUTPUT_INTERN
);
596 if (snd_pmac_burgundy_detect_headphone(chip
))
597 reg
|= imac
? (BURGUNDY_HP_LEFT
| BURGUNDY_HP_RIGHT
)
598 : (BURGUNDY_OUTPUT_LEFT
599 | BURGUNDY_OUTPUT_RIGHT
);
601 reg
|= imac
? (BURGUNDY_OUTPUT_LEFT
602 | BURGUNDY_OUTPUT_RIGHT
)
603 : (BURGUNDY_OUTPUT_INTERN
);
604 if (do_notify
&& reg
== oreg
)
606 snd_pmac_burgundy_wcb(chip
,
607 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
, reg
);
609 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
610 &chip
->master_sw_ctl
->id
);
611 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
612 &chip
->speaker_sw_ctl
->id
);
613 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
614 &chip
->hp_detect_ctl
->id
);
618 #endif /* PMAC_SUPPORT_AUTOMUTE */
622 * initialize burgundy
624 int __init
snd_pmac_burgundy_init(struct snd_pmac
*chip
)
626 int imac
= machine_is_compatible("iMac");
629 /* Checks to see the chip is alive and kicking */
630 if ((in_le32(&chip
->awacs
->codec_ctrl
) & MASK_ERRCODE
) == 0xf0000) {
631 printk(KERN_WARNING
"pmac burgundy: disabled by MacOS :-(\n");
635 snd_pmac_burgundy_wcw(chip
, MASK_ADDR_BURGUNDY_OUTPUTENABLES
,
636 DEF_BURGUNDY_OUTPUTENABLES
);
637 snd_pmac_burgundy_wcb(chip
, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
,
638 DEF_BURGUNDY_MORE_OUTPUTENABLES
);
639 snd_pmac_burgundy_wcw(chip
, MASK_ADDR_BURGUNDY_OUTPUTSELECTS
,
640 DEF_BURGUNDY_OUTPUTSELECTS
);
642 snd_pmac_burgundy_wcb(chip
, MASK_ADDR_BURGUNDY_INPSEL21
,
643 DEF_BURGUNDY_INPSEL21
);
644 snd_pmac_burgundy_wcb(chip
, MASK_ADDR_BURGUNDY_INPSEL3
,
645 imac
? DEF_BURGUNDY_INPSEL3_IMAC
646 : DEF_BURGUNDY_INPSEL3_PMAC
);
647 snd_pmac_burgundy_wcb(chip
, MASK_ADDR_BURGUNDY_GAINCD
,
648 DEF_BURGUNDY_GAINCD
);
649 snd_pmac_burgundy_wcb(chip
, MASK_ADDR_BURGUNDY_GAINLINE
,
650 DEF_BURGUNDY_GAINLINE
);
651 snd_pmac_burgundy_wcb(chip
, MASK_ADDR_BURGUNDY_GAINMIC
,
652 DEF_BURGUNDY_GAINMIC
);
653 snd_pmac_burgundy_wcb(chip
, MASK_ADDR_BURGUNDY_GAINMODEM
,
654 DEF_BURGUNDY_GAINMODEM
);
656 snd_pmac_burgundy_wcb(chip
, MASK_ADDR_BURGUNDY_ATTENSPEAKER
,
657 DEF_BURGUNDY_ATTENSPEAKER
);
658 snd_pmac_burgundy_wcb(chip
, MASK_ADDR_BURGUNDY_ATTENLINEOUT
,
659 DEF_BURGUNDY_ATTENLINEOUT
);
660 snd_pmac_burgundy_wcb(chip
, MASK_ADDR_BURGUNDY_ATTENHP
,
661 DEF_BURGUNDY_ATTENHP
);
663 snd_pmac_burgundy_wcw(chip
, MASK_ADDR_BURGUNDY_MASTER_VOLUME
,
664 DEF_BURGUNDY_MASTER_VOLUME
);
665 snd_pmac_burgundy_wcw(chip
, MASK_ADDR_BURGUNDY_VOLCD
,
667 snd_pmac_burgundy_wcw(chip
, MASK_ADDR_BURGUNDY_VOLLINE
,
668 DEF_BURGUNDY_VOLLINE
);
669 snd_pmac_burgundy_wcw(chip
, MASK_ADDR_BURGUNDY_VOLMIC
,
670 DEF_BURGUNDY_VOLMIC
);
672 if (chip
->hp_stat_mask
== 0) {
673 /* set headphone-jack detection bit */
675 chip
->hp_stat_mask
= BURGUNDY_HPDETECT_IMAC_UPPER
676 | BURGUNDY_HPDETECT_IMAC_LOWER
677 | BURGUNDY_HPDETECT_IMAC_SIDE
;
679 chip
->hp_stat_mask
= BURGUNDY_HPDETECT_PMAC_BACK
;
682 * build burgundy mixers
684 strcpy(chip
->card
->mixername
, "PowerMac Burgundy");
686 for (i
= 0; i
< ARRAY_SIZE(snd_pmac_burgundy_mixers
); i
++) {
687 err
= snd_ctl_add(chip
->card
,
688 snd_ctl_new1(&snd_pmac_burgundy_mixers
[i
], chip
));
692 for (i
= 0; i
< (imac
? ARRAY_SIZE(snd_pmac_burgundy_mixers_imac
)
693 : ARRAY_SIZE(snd_pmac_burgundy_mixers_pmac
)); i
++) {
694 err
= snd_ctl_add(chip
->card
,
695 snd_ctl_new1(imac
? &snd_pmac_burgundy_mixers_imac
[i
]
696 : &snd_pmac_burgundy_mixers_pmac
[i
], chip
));
700 chip
->master_sw_ctl
= snd_ctl_new1(imac
701 ? &snd_pmac_burgundy_master_sw_imac
702 : &snd_pmac_burgundy_master_sw_pmac
, chip
);
703 if ((err
= snd_ctl_add(chip
->card
, chip
->master_sw_ctl
)) < 0)
705 chip
->master_sw_ctl
= snd_ctl_new1(imac
706 ? &snd_pmac_burgundy_line_sw_imac
707 : &snd_pmac_burgundy_line_sw_pmac
, chip
);
708 err
= snd_ctl_add(chip
->card
, chip
->master_sw_ctl
);
712 chip
->master_sw_ctl
= snd_ctl_new1(
713 &snd_pmac_burgundy_hp_sw_imac
, chip
);
714 err
= snd_ctl_add(chip
->card
, chip
->master_sw_ctl
);
718 chip
->speaker_sw_ctl
= snd_ctl_new1(imac
719 ? &snd_pmac_burgundy_speaker_sw_imac
720 : &snd_pmac_burgundy_speaker_sw_pmac
, chip
);
721 if ((err
= snd_ctl_add(chip
->card
, chip
->speaker_sw_ctl
)) < 0)
723 #ifdef PMAC_SUPPORT_AUTOMUTE
724 if ((err
= snd_pmac_add_automute(chip
)) < 0)
727 chip
->detect_headphone
= snd_pmac_burgundy_detect_headphone
;
728 chip
->update_automute
= snd_pmac_burgundy_update_automute
;
729 snd_pmac_burgundy_update_automute(chip
, 0); /* update the status only */