[ALSA] snd-powermac: Burgundy mixers for B&W and iMac
[deliverable/linux.git] / sound / ppc / burgundy.c
1 /*
2 * PMac Burgundy lowlevel functions
3 *
4 * Copyright (c) by Takashi Iwai <tiwai@suse.de>
5 * code based on dmasound.c.
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include <asm/io.h>
23 #include <linux/init.h>
24 #include <linux/slab.h>
25 #include <linux/delay.h>
26 #include <sound/core.h>
27 #include "pmac.h"
28 #include "burgundy.h"
29
30
31 /* Waits for busy flag to clear */
32 static inline void
33 snd_pmac_burgundy_busy_wait(struct snd_pmac *chip)
34 {
35 int timeout = 50;
36 while ((in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) && timeout--)
37 udelay(1);
38 if (! timeout)
39 printk(KERN_DEBUG "burgundy_busy_wait: timeout\n");
40 }
41
42 static inline void
43 snd_pmac_burgundy_extend_wait(struct snd_pmac *chip)
44 {
45 int timeout;
46 timeout = 50;
47 while (!(in_le32(&chip->awacs->codec_stat) & MASK_EXTEND) && timeout--)
48 udelay(1);
49 if (! timeout)
50 printk(KERN_DEBUG "burgundy_extend_wait: timeout #1\n");
51 timeout = 50;
52 while ((in_le32(&chip->awacs->codec_stat) & MASK_EXTEND) && timeout--)
53 udelay(1);
54 if (! timeout)
55 printk(KERN_DEBUG "burgundy_extend_wait: timeout #2\n");
56 }
57
58 static void
59 snd_pmac_burgundy_wcw(struct snd_pmac *chip, unsigned addr, unsigned val)
60 {
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);
69 }
70
71 static unsigned
72 snd_pmac_burgundy_rcw(struct snd_pmac *chip, unsigned addr)
73 {
74 unsigned val = 0;
75 unsigned long flags;
76
77 spin_lock_irqsave(&chip->reg_lock, flags);
78
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;
83
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;
88
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;
93
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;
98
99 spin_unlock_irqrestore(&chip->reg_lock, flags);
100
101 return val;
102 }
103
104 static void
105 snd_pmac_burgundy_wcb(struct snd_pmac *chip, unsigned int addr, unsigned int val)
106 {
107 out_le32(&chip->awacs->codec_ctrl, addr + 0x300000 + (val & 0xff));
108 snd_pmac_burgundy_busy_wait(chip);
109 }
110
111 static unsigned
112 snd_pmac_burgundy_rcb(struct snd_pmac *chip, unsigned int addr)
113 {
114 unsigned val = 0;
115 unsigned long flags;
116
117 spin_lock_irqsave(&chip->reg_lock, flags);
118
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;
123
124 spin_unlock_irqrestore(&chip->reg_lock, flags);
125
126 return val;
127 }
128
129 /*
130 * Burgundy volume: 0 - 100, stereo
131 */
132 static void
133 snd_pmac_burgundy_write_volume(struct snd_pmac *chip, unsigned int address,
134 long *volume, int shift)
135 {
136 int hardvolume, lvolume, rvolume;
137
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;
143
144 hardvolume = lvolume + (rvolume << shift);
145 if (shift == 8)
146 hardvolume |= hardvolume << 16;
147
148 snd_pmac_burgundy_wcw(chip, address, hardvolume);
149 }
150
151 static void
152 snd_pmac_burgundy_read_volume(struct snd_pmac *chip, unsigned int address,
153 long *volume, int shift)
154 {
155 int wvolume;
156
157 wvolume = snd_pmac_burgundy_rcw(chip, address);
158
159 volume[0] = wvolume & 0xff;
160 if (volume[0] >= BURGUNDY_VOLUME_OFFSET)
161 volume[0] -= BURGUNDY_VOLUME_OFFSET;
162 else
163 volume[0] = 0;
164 volume[1] = (wvolume >> shift) & 0xff;
165 if (volume[1] >= BURGUNDY_VOLUME_OFFSET)
166 volume[1] -= BURGUNDY_VOLUME_OFFSET;
167 else
168 volume[1] = 0;
169 }
170
171
172 /*
173 */
174
175 #define BASE2ADDR(base) ((base) << 12)
176 #define ADDR2BASE(addr) ((addr) >> 12)
177
178 static int snd_pmac_burgundy_info_volume(struct snd_kcontrol *kcontrol,
179 struct snd_ctl_elem_info *uinfo)
180 {
181 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
182 uinfo->count = 2;
183 uinfo->value.integer.min = 0;
184 uinfo->value.integer.max = 100;
185 return 0;
186 }
187
188 static int snd_pmac_burgundy_get_volume(struct snd_kcontrol *kcontrol,
189 struct snd_ctl_elem_value *ucontrol)
190 {
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,
195 shift);
196 return 0;
197 }
198
199 static int snd_pmac_burgundy_put_volume(struct snd_kcontrol *kcontrol,
200 struct snd_ctl_elem_value *ucontrol)
201 {
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;
205 long nvoices[2];
206
207 snd_pmac_burgundy_write_volume(chip, addr, ucontrol->value.integer.value,
208 shift);
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]);
212 }
213
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)) }
220
221 /*
222 * Burgundy volume: 0 - 100, stereo, 2-byte reg
223 */
224 static void
225 snd_pmac_burgundy_write_volume_2b(struct snd_pmac *chip, unsigned int address,
226 long *volume, int off)
227 {
228 int lvolume, rvolume;
229
230 off |= off << 2;
231 lvolume = volume[0] ? volume[0] + BURGUNDY_VOLUME_OFFSET : 0;
232 rvolume = volume[1] ? volume[1] + BURGUNDY_VOLUME_OFFSET : 0;
233
234 snd_pmac_burgundy_wcb(chip, address + off, lvolume);
235 snd_pmac_burgundy_wcb(chip, address + off + 0x500, rvolume);
236 }
237
238 static void
239 snd_pmac_burgundy_read_volume_2b(struct snd_pmac *chip, unsigned int address,
240 long *volume, int off)
241 {
242 volume[0] = snd_pmac_burgundy_rcb(chip, address + off);
243 if (volume[0] >= BURGUNDY_VOLUME_OFFSET)
244 volume[0] -= BURGUNDY_VOLUME_OFFSET;
245 else
246 volume[0] = 0;
247 volume[1] = snd_pmac_burgundy_rcb(chip, address + off + 0x100);
248 if (volume[1] >= BURGUNDY_VOLUME_OFFSET)
249 volume[1] -= BURGUNDY_VOLUME_OFFSET;
250 else
251 volume[1] = 0;
252 }
253
254 static int snd_pmac_burgundy_info_volume_2b(struct snd_kcontrol *kcontrol,
255 struct snd_ctl_elem_info *uinfo)
256 {
257 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
258 uinfo->count = 2;
259 uinfo->value.integer.min = 0;
260 uinfo->value.integer.max = 100;
261 return 0;
262 }
263
264 static int snd_pmac_burgundy_get_volume_2b(struct snd_kcontrol *kcontrol,
265 struct snd_ctl_elem_value *ucontrol)
266 {
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);
272 return 0;
273 }
274
275 static int snd_pmac_burgundy_put_volume_2b(struct snd_kcontrol *kcontrol,
276 struct snd_ctl_elem_value *ucontrol)
277 {
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;
281 long nvoices[2];
282
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]);
288 }
289
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)) }
296
297 /*
298 * Burgundy gain/attenuation: 0 - 15, mono/stereo, byte reg
299 */
300 static int snd_pmac_burgundy_info_gain(struct snd_kcontrol *kcontrol,
301 struct snd_ctl_elem_info *uinfo)
302 {
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;
308 return 0;
309 }
310
311 static int snd_pmac_burgundy_get_gain(struct snd_kcontrol *kcontrol,
312 struct snd_ctl_elem_value *ucontrol)
313 {
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;
318 int oval;
319
320 oval = snd_pmac_burgundy_rcb(chip, addr);
321 if (atten)
322 oval = ~oval & 0xff;
323 ucontrol->value.integer.value[0] = oval & 0xf;
324 if (stereo)
325 ucontrol->value.integer.value[1] = (oval >> 4) & 0xf;
326 return 0;
327 }
328
329 static int snd_pmac_burgundy_put_gain(struct snd_kcontrol *kcontrol,
330 struct snd_ctl_elem_value *ucontrol)
331 {
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;
336 int oval, val;
337
338 oval = snd_pmac_burgundy_rcb(chip, addr);
339 if (atten)
340 oval = ~oval & 0xff;
341 val = ucontrol->value.integer.value[0];
342 if (stereo)
343 val |= ucontrol->value.integer.value[1] << 4;
344 else
345 val |= ucontrol->value.integer.value[0] << 4;
346 if (atten)
347 val = ~val & 0xff;
348 snd_pmac_burgundy_wcb(chip, addr, val);
349 return val != oval;
350 }
351
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)) }
358
359 /*
360 * Burgundy switch: 0/1, mono/stereo, word reg
361 */
362 static int snd_pmac_burgundy_info_switch_w(struct snd_kcontrol *kcontrol,
363 struct snd_ctl_elem_info *uinfo)
364 {
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;
370 return 0;
371 }
372
373 static int snd_pmac_burgundy_get_switch_w(struct snd_kcontrol *kcontrol,
374 struct snd_ctl_elem_value *ucontrol)
375 {
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;
383 if (stereo)
384 ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0;
385 return 0;
386 }
387
388 static int snd_pmac_burgundy_put_switch_w(struct snd_kcontrol *kcontrol,
389 struct snd_ctl_elem_value *ucontrol)
390 {
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;
396 int val, oval;
397 oval = snd_pmac_burgundy_rcw(chip, addr);
398 val = oval & ~(lmask | (stereo ? rmask : 0));
399 if (ucontrol->value.integer.value[0])
400 val |= lmask;
401 if (stereo && ucontrol->value.integer.value[1])
402 val |= rmask;
403 snd_pmac_burgundy_wcw(chip, addr, val);
404 return val != oval;
405 }
406
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)) }
414
415 /*
416 * Burgundy switch: 0/1, mono/stereo, byte reg, bit mask
417 */
418 static int snd_pmac_burgundy_info_switch_b(struct snd_kcontrol *kcontrol,
419 struct snd_ctl_elem_info *uinfo)
420 {
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;
426 return 0;
427 }
428
429 static int snd_pmac_burgundy_get_switch_b(struct snd_kcontrol *kcontrol,
430 struct snd_ctl_elem_value *ucontrol)
431 {
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;
439 if (stereo)
440 ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0;
441 return 0;
442 }
443
444 static int snd_pmac_burgundy_put_switch_b(struct snd_kcontrol *kcontrol,
445 struct snd_ctl_elem_value *ucontrol)
446 {
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;
452 int val, oval;
453 oval = snd_pmac_burgundy_rcb(chip, addr);
454 val = oval & ~(lmask | rmask);
455 if (ucontrol->value.integer.value[0])
456 val |= lmask;
457 if (stereo && ucontrol->value.integer.value[1])
458 val |= rmask;
459 snd_pmac_burgundy_wcb(chip, addr, val);
460 return val != oval;
461 }
462
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)) }
470
471 /*
472 * Burgundy mixers
473 */
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)
501 };
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)
527 };
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) */
543 };
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);
574
575
576 #ifdef PMAC_SUPPORT_AUTOMUTE
577 /*
578 * auto-mute stuffs
579 */
580 static int snd_pmac_burgundy_detect_headphone(struct snd_pmac *chip)
581 {
582 return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0;
583 }
584
585 static void snd_pmac_burgundy_update_automute(struct snd_pmac *chip, int do_notify)
586 {
587 if (chip->auto_mute) {
588 int imac = machine_is_compatible("iMac");
589 int reg, oreg;
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);
600 else
601 reg |= imac ? (BURGUNDY_OUTPUT_LEFT
602 | BURGUNDY_OUTPUT_RIGHT)
603 : (BURGUNDY_OUTPUT_INTERN);
604 if (do_notify && reg == oreg)
605 return;
606 snd_pmac_burgundy_wcb(chip,
607 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, reg);
608 if (do_notify) {
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);
615 }
616 }
617 }
618 #endif /* PMAC_SUPPORT_AUTOMUTE */
619
620
621 /*
622 * initialize burgundy
623 */
624 int __init snd_pmac_burgundy_init(struct snd_pmac *chip)
625 {
626 int imac = machine_is_compatible("iMac");
627 int i, err;
628
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");
632 return 1;
633 }
634
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);
641
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);
655
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);
662
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,
666 DEF_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);
671
672 if (chip->hp_stat_mask == 0) {
673 /* set headphone-jack detection bit */
674 if (imac)
675 chip->hp_stat_mask = BURGUNDY_HPDETECT_IMAC_UPPER
676 | BURGUNDY_HPDETECT_IMAC_LOWER
677 | BURGUNDY_HPDETECT_IMAC_SIDE;
678 else
679 chip->hp_stat_mask = BURGUNDY_HPDETECT_PMAC_BACK;
680 }
681 /*
682 * build burgundy mixers
683 */
684 strcpy(chip->card->mixername, "PowerMac Burgundy");
685
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));
689 if (err < 0)
690 return err;
691 }
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));
697 if (err < 0)
698 return err;
699 }
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)
704 return err;
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);
709 if (err < 0)
710 return err;
711 if (imac) {
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);
715 if (err < 0)
716 return err;
717 }
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)
722 return err;
723 #ifdef PMAC_SUPPORT_AUTOMUTE
724 if ((err = snd_pmac_add_automute(chip)) < 0)
725 return err;
726
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 */
730 #endif
731
732 return 0;
733 }
This page took 0.059688 seconds and 6 git commands to generate.