Blame view

sound/ppc/burgundy.c 24.4 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  /*
   * PMac Burgundy lowlevel functions
   *
   * Copyright (c) by Takashi Iwai <tiwai@suse.de>
   * code based on dmasound.c.
   *
   *   This program is free software; you can redistribute it and/or modify
   *   it under the terms of the GNU General Public License as published by
   *   the Free Software Foundation; either version 2 of the License, or
   *   (at your option) any later version.
   *
   *   This program is distributed in the hope that it will be useful,
   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *   GNU General Public License for more details.
   *
   *   You should have received a copy of the GNU General Public License
   *   along with this program; if not, write to the Free Software
   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
22
  #include <asm/io.h>
  #include <linux/init.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
24
25
26
27
28
29
  #include <linux/delay.h>
  #include <sound/core.h>
  #include "pmac.h"
  #include "burgundy.h"
  
  
  /* Waits for busy flag to clear */
77933d727   Jesper Juhl   [PATCH] clean up ...
30
  static inline void
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
31
  snd_pmac_burgundy_busy_wait(struct snd_pmac *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
34
35
  {
  	int timeout = 50;
  	while ((in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) && timeout--)
  		udelay(1);
396617586   Roel Kluin   ALSA: snd-powerma...
36
  	if (timeout < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
39
  		printk(KERN_DEBUG "burgundy_busy_wait: timeout
  ");
  }
77933d727   Jesper Juhl   [PATCH] clean up ...
40
  static inline void
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
41
  snd_pmac_burgundy_extend_wait(struct snd_pmac *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
44
45
46
  {
  	int timeout;
  	timeout = 50;
  	while (!(in_le32(&chip->awacs->codec_stat) & MASK_EXTEND) && timeout--)
  		udelay(1);
13be1bf14   Roel Kluin   ALSA: burgundy: t...
47
  	if (timeout < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48
49
50
51
52
  		printk(KERN_DEBUG "burgundy_extend_wait: timeout #1
  ");
  	timeout = 50;
  	while ((in_le32(&chip->awacs->codec_stat) & MASK_EXTEND) && timeout--)
  		udelay(1);
13be1bf14   Roel Kluin   ALSA: burgundy: t...
53
  	if (timeout < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
54
55
56
57
58
  		printk(KERN_DEBUG "burgundy_extend_wait: timeout #2
  ");
  }
  
  static void
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
59
  snd_pmac_burgundy_wcw(struct snd_pmac *chip, unsigned addr, unsigned val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
61
62
63
64
65
66
67
68
69
70
71
  {
  	out_le32(&chip->awacs->codec_ctrl, addr + 0x200c00 + (val & 0xff));
  	snd_pmac_burgundy_busy_wait(chip);
  	out_le32(&chip->awacs->codec_ctrl, addr + 0x200d00 +((val>>8) & 0xff));
  	snd_pmac_burgundy_busy_wait(chip);
  	out_le32(&chip->awacs->codec_ctrl, addr + 0x200e00 +((val>>16) & 0xff));
  	snd_pmac_burgundy_busy_wait(chip);
  	out_le32(&chip->awacs->codec_ctrl, addr + 0x200f00 +((val>>24) & 0xff));
  	snd_pmac_burgundy_busy_wait(chip);
  }
  
  static unsigned
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
72
  snd_pmac_burgundy_rcw(struct snd_pmac *chip, unsigned addr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  {
  	unsigned val = 0;
  	unsigned long flags;
  
  	spin_lock_irqsave(&chip->reg_lock, flags);
  
  	out_le32(&chip->awacs->codec_ctrl, addr + 0x100000);
  	snd_pmac_burgundy_busy_wait(chip);
  	snd_pmac_burgundy_extend_wait(chip);
  	val += (in_le32(&chip->awacs->codec_stat) >> 4) & 0xff;
  
  	out_le32(&chip->awacs->codec_ctrl, addr + 0x100100);
  	snd_pmac_burgundy_busy_wait(chip);
  	snd_pmac_burgundy_extend_wait(chip);
  	val += ((in_le32(&chip->awacs->codec_stat)>>4) & 0xff) <<8;
  
  	out_le32(&chip->awacs->codec_ctrl, addr + 0x100200);
  	snd_pmac_burgundy_busy_wait(chip);
  	snd_pmac_burgundy_extend_wait(chip);
  	val += ((in_le32(&chip->awacs->codec_stat)>>4) & 0xff) <<16;
  
  	out_le32(&chip->awacs->codec_ctrl, addr + 0x100300);
  	snd_pmac_burgundy_busy_wait(chip);
  	snd_pmac_burgundy_extend_wait(chip);
  	val += ((in_le32(&chip->awacs->codec_stat)>>4) & 0xff) <<24;
  
  	spin_unlock_irqrestore(&chip->reg_lock, flags);
  
  	return val;
  }
  
  static void
20861fa7b   Risto Suominen   [ALSA] snd-powerm...
105
106
  snd_pmac_burgundy_wcb(struct snd_pmac *chip, unsigned int addr,
  		      unsigned int val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107
108
109
110
111
112
  {
  	out_le32(&chip->awacs->codec_ctrl, addr + 0x300000 + (val & 0xff));
  	snd_pmac_burgundy_busy_wait(chip);
  }
  
  static unsigned
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
113
  snd_pmac_burgundy_rcb(struct snd_pmac *chip, unsigned int addr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  {
  	unsigned val = 0;
  	unsigned long flags;
  
  	spin_lock_irqsave(&chip->reg_lock, flags);
  
  	out_le32(&chip->awacs->codec_ctrl, addr + 0x100000);
  	snd_pmac_burgundy_busy_wait(chip);
  	snd_pmac_burgundy_extend_wait(chip);
  	val += (in_le32(&chip->awacs->codec_stat) >> 4) & 0xff;
  
  	spin_unlock_irqrestore(&chip->reg_lock, flags);
  
  	return val;
  }
20861fa7b   Risto Suominen   [ALSA] snd-powerm...
129
130
  #define BASE2ADDR(base)	((base) << 12)
  #define ADDR2BASE(addr)	((addr) >> 12)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131
  /*
20861fa7b   Risto Suominen   [ALSA] snd-powerm...
132
   * Burgundy volume: 0 - 100, stereo, word reg
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
133
134
   */
  static void
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
135
136
  snd_pmac_burgundy_write_volume(struct snd_pmac *chip, unsigned int address,
  			       long *volume, int shift)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
137
138
  {
  	int hardvolume, lvolume, rvolume;
d4079ac49   Takashi Iwai   [ALSA] powermac -...
139
140
141
  	if (volume[0] < 0 || volume[0] > 100 ||
  	    volume[1] < 0 || volume[1] > 100)
  		return; /* -EINVAL */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142
143
144
145
146
147
148
149
150
151
152
  	lvolume = volume[0] ? volume[0] + BURGUNDY_VOLUME_OFFSET : 0;
  	rvolume = volume[1] ? volume[1] + BURGUNDY_VOLUME_OFFSET : 0;
  
  	hardvolume = lvolume + (rvolume << shift);
  	if (shift == 8)
  		hardvolume |= hardvolume << 16;
  
  	snd_pmac_burgundy_wcw(chip, address, hardvolume);
  }
  
  static void
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
153
154
  snd_pmac_burgundy_read_volume(struct snd_pmac *chip, unsigned int address,
  			      long *volume, int shift)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
  {
  	int wvolume;
  
  	wvolume = snd_pmac_burgundy_rcw(chip, address);
  
  	volume[0] = wvolume & 0xff;
  	if (volume[0] >= BURGUNDY_VOLUME_OFFSET)
  		volume[0] -= BURGUNDY_VOLUME_OFFSET;
  	else
  		volume[0] = 0;
  	volume[1] = (wvolume >> shift) & 0xff;
  	if (volume[1] >= BURGUNDY_VOLUME_OFFSET)
  		volume[1] -= BURGUNDY_VOLUME_OFFSET;
  	else
  		volume[1] = 0;
  }
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
171
172
  static int snd_pmac_burgundy_info_volume(struct snd_kcontrol *kcontrol,
  					 struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
173
174
175
176
177
178
179
  {
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  	uinfo->count = 2;
  	uinfo->value.integer.min = 0;
  	uinfo->value.integer.max = 100;
  	return 0;
  }
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
180
181
  static int snd_pmac_burgundy_get_volume(struct snd_kcontrol *kcontrol,
  					struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
182
  {
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
183
  	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
184
185
  	unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
  	int shift = (kcontrol->private_value >> 8) & 0xff;
20861fa7b   Risto Suominen   [ALSA] snd-powerm...
186
187
  	snd_pmac_burgundy_read_volume(chip, addr,
  				      ucontrol->value.integer.value, shift);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
188
189
  	return 0;
  }
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
190
191
  static int snd_pmac_burgundy_put_volume(struct snd_kcontrol *kcontrol,
  					struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
192
  {
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
193
  	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
194
195
196
  	unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
  	int shift = (kcontrol->private_value >> 8) & 0xff;
  	long nvoices[2];
20861fa7b   Risto Suominen   [ALSA] snd-powerm...
197
198
  	snd_pmac_burgundy_write_volume(chip, addr,
  				       ucontrol->value.integer.value, shift);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
199
200
201
202
  	snd_pmac_burgundy_read_volume(chip, addr, nvoices, shift);
  	return (nvoices[0] != ucontrol->value.integer.value[0] ||
  		nvoices[1] != ucontrol->value.integer.value[1]);
  }
44deee129   Risto Suominen   [ALSA] snd-powerm...
203
  #define BURGUNDY_VOLUME_W(xname, xindex, addr, shift) \
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
204
205
206
207
208
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
    .info = snd_pmac_burgundy_info_volume,\
    .get = snd_pmac_burgundy_get_volume,\
    .put = snd_pmac_burgundy_put_volume,\
    .private_value = ((ADDR2BASE(addr) & 0xff) | ((shift) << 8)) }
44deee129   Risto Suominen   [ALSA] snd-powerm...
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
  /*
   * Burgundy volume: 0 - 100, stereo, 2-byte reg
   */
  static void
  snd_pmac_burgundy_write_volume_2b(struct snd_pmac *chip, unsigned int address,
  				  long *volume, int off)
  {
  	int lvolume, rvolume;
  
  	off |= off << 2;
  	lvolume = volume[0] ? volume[0] + BURGUNDY_VOLUME_OFFSET : 0;
  	rvolume = volume[1] ? volume[1] + BURGUNDY_VOLUME_OFFSET : 0;
  
  	snd_pmac_burgundy_wcb(chip, address + off, lvolume);
  	snd_pmac_burgundy_wcb(chip, address + off + 0x500, rvolume);
  }
  
  static void
  snd_pmac_burgundy_read_volume_2b(struct snd_pmac *chip, unsigned int address,
  				 long *volume, int off)
  {
  	volume[0] = snd_pmac_burgundy_rcb(chip, address + off);
  	if (volume[0] >= BURGUNDY_VOLUME_OFFSET)
  		volume[0] -= BURGUNDY_VOLUME_OFFSET;
  	else
  		volume[0] = 0;
  	volume[1] = snd_pmac_burgundy_rcb(chip, address + off + 0x100);
  	if (volume[1] >= BURGUNDY_VOLUME_OFFSET)
  		volume[1] -= BURGUNDY_VOLUME_OFFSET;
  	else
  		volume[1] = 0;
  }
  
  static int snd_pmac_burgundy_info_volume_2b(struct snd_kcontrol *kcontrol,
  					    struct snd_ctl_elem_info *uinfo)
  {
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  	uinfo->count = 2;
  	uinfo->value.integer.min = 0;
  	uinfo->value.integer.max = 100;
  	return 0;
  }
  
  static int snd_pmac_burgundy_get_volume_2b(struct snd_kcontrol *kcontrol,
  					   struct snd_ctl_elem_value *ucontrol)
  {
  	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  	unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
  	int off = kcontrol->private_value & 0x300;
  	snd_pmac_burgundy_read_volume_2b(chip, addr,
  			ucontrol->value.integer.value, off);
  	return 0;
  }
  
  static int snd_pmac_burgundy_put_volume_2b(struct snd_kcontrol *kcontrol,
  					   struct snd_ctl_elem_value *ucontrol)
  {
  	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  	unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
  	int off = kcontrol->private_value & 0x300;
  	long nvoices[2];
  
  	snd_pmac_burgundy_write_volume_2b(chip, addr,
  			ucontrol->value.integer.value, off);
  	snd_pmac_burgundy_read_volume_2b(chip, addr, nvoices, off);
  	return (nvoices[0] != ucontrol->value.integer.value[0] ||
  		nvoices[1] != ucontrol->value.integer.value[1]);
  }
  
  #define BURGUNDY_VOLUME_2B(xname, xindex, addr, off) \
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
    .info = snd_pmac_burgundy_info_volume_2b,\
    .get = snd_pmac_burgundy_get_volume_2b,\
    .put = snd_pmac_burgundy_put_volume_2b,\
    .private_value = ((ADDR2BASE(addr) & 0xff) | ((off) << 8)) }
  
  /*
   * Burgundy gain/attenuation: 0 - 15, mono/stereo, byte reg
   */
  static int snd_pmac_burgundy_info_gain(struct snd_kcontrol *kcontrol,
  				       struct snd_ctl_elem_info *uinfo)
  {
  	int stereo = (kcontrol->private_value >> 24) & 1;
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  	uinfo->count = stereo + 1;
  	uinfo->value.integer.min = 0;
  	uinfo->value.integer.max = 15;
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298

44deee129   Risto Suominen   [ALSA] snd-powerm...
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
  static int snd_pmac_burgundy_get_gain(struct snd_kcontrol *kcontrol,
  				      struct snd_ctl_elem_value *ucontrol)
  {
  	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  	unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
  	int stereo = (kcontrol->private_value >> 24) & 1;
  	int atten = (kcontrol->private_value >> 25) & 1;
  	int oval;
  
  	oval = snd_pmac_burgundy_rcb(chip, addr);
  	if (atten)
  		oval = ~oval & 0xff;
  	ucontrol->value.integer.value[0] = oval & 0xf;
  	if (stereo)
  		ucontrol->value.integer.value[1] = (oval >> 4) & 0xf;
  	return 0;
  }
  
  static int snd_pmac_burgundy_put_gain(struct snd_kcontrol *kcontrol,
  				      struct snd_ctl_elem_value *ucontrol)
  {
  	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
  	unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
  	int stereo = (kcontrol->private_value >> 24) & 1;
  	int atten = (kcontrol->private_value >> 25) & 1;
  	int oval, val;
  
  	oval = snd_pmac_burgundy_rcb(chip, addr);
  	if (atten)
  		oval = ~oval & 0xff;
  	val = ucontrol->value.integer.value[0];
  	if (stereo)
  		val |= ucontrol->value.integer.value[1] << 4;
  	else
  		val |= ucontrol->value.integer.value[0] << 4;
  	if (atten)
  		val = ~val & 0xff;
  	snd_pmac_burgundy_wcb(chip, addr, val);
  	return val != oval;
  }
  
  #define BURGUNDY_VOLUME_B(xname, xindex, addr, stereo, atten) \
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
    .info = snd_pmac_burgundy_info_gain,\
    .get = snd_pmac_burgundy_get_gain,\
    .put = snd_pmac_burgundy_put_gain,\
    .private_value = (ADDR2BASE(addr) | ((stereo) << 24) | ((atten) << 25)) }
  
  /*
   * Burgundy switch: 0/1, mono/stereo, word reg
   */
  static int snd_pmac_burgundy_info_switch_w(struct snd_kcontrol *kcontrol,
  					   struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
352
353
354
355
356
357
358
359
  {
  	int stereo = (kcontrol->private_value >> 24) & 1;
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  	uinfo->count = stereo + 1;
  	uinfo->value.integer.min = 0;
  	uinfo->value.integer.max = 1;
  	return 0;
  }
44deee129   Risto Suominen   [ALSA] snd-powerm...
360
361
  static int snd_pmac_burgundy_get_switch_w(struct snd_kcontrol *kcontrol,
  					  struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
362
  {
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
363
  	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
44deee129   Risto Suominen   [ALSA] snd-powerm...
364
365
366
  	unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
  	int lmask = 1 << (kcontrol->private_value & 0xff);
  	int rmask = 1 << ((kcontrol->private_value >> 8) & 0xff);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
367
  	int stereo = (kcontrol->private_value >> 24) & 1;
44deee129   Risto Suominen   [ALSA] snd-powerm...
368
  	int val = snd_pmac_burgundy_rcw(chip, addr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
369
370
371
372
373
  	ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0;
  	if (stereo)
  		ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0;
  	return 0;
  }
44deee129   Risto Suominen   [ALSA] snd-powerm...
374
375
  static int snd_pmac_burgundy_put_switch_w(struct snd_kcontrol *kcontrol,
  					  struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
376
  {
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
377
  	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
44deee129   Risto Suominen   [ALSA] snd-powerm...
378
379
380
  	unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
  	int lmask = 1 << (kcontrol->private_value & 0xff);
  	int rmask = 1 << ((kcontrol->private_value >> 8) & 0xff);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
381
382
  	int stereo = (kcontrol->private_value >> 24) & 1;
  	int val, oval;
44deee129   Risto Suominen   [ALSA] snd-powerm...
383
384
  	oval = snd_pmac_burgundy_rcw(chip, addr);
  	val = oval & ~(lmask | (stereo ? rmask : 0));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
385
386
387
388
  	if (ucontrol->value.integer.value[0])
  		val |= lmask;
  	if (stereo && ucontrol->value.integer.value[1])
  		val |= rmask;
44deee129   Risto Suominen   [ALSA] snd-powerm...
389
  	snd_pmac_burgundy_wcw(chip, addr, val);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
390
391
  	return val != oval;
  }
44deee129   Risto Suominen   [ALSA] snd-powerm...
392
  #define BURGUNDY_SWITCH_W(xname, xindex, addr, lbit, rbit, stereo) \
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
393
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
44deee129   Risto Suominen   [ALSA] snd-powerm...
394
395
396
397
398
399
400
401
402
403
404
    .info = snd_pmac_burgundy_info_switch_w,\
    .get = snd_pmac_burgundy_get_switch_w,\
    .put = snd_pmac_burgundy_put_switch_w,\
    .private_value = ((lbit) | ((rbit) << 8)\
  		| (ADDR2BASE(addr) << 16) | ((stereo) << 24)) }
  
  /*
   * Burgundy switch: 0/1, mono/stereo, byte reg, bit mask
   */
  static int snd_pmac_burgundy_info_switch_b(struct snd_kcontrol *kcontrol,
  					   struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
405
406
  {
  	int stereo = (kcontrol->private_value >> 24) & 1;
44deee129   Risto Suominen   [ALSA] snd-powerm...
407
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
408
409
  	uinfo->count = stereo + 1;
  	uinfo->value.integer.min = 0;
44deee129   Risto Suominen   [ALSA] snd-powerm...
410
  	uinfo->value.integer.max = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
411
412
  	return 0;
  }
44deee129   Risto Suominen   [ALSA] snd-powerm...
413
414
  static int snd_pmac_burgundy_get_switch_b(struct snd_kcontrol *kcontrol,
  					  struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
415
  {
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
416
  	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
44deee129   Risto Suominen   [ALSA] snd-powerm...
417
418
419
  	unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
  	int lmask = kcontrol->private_value & 0xff;
  	int rmask = (kcontrol->private_value >> 8) & 0xff;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
420
  	int stereo = (kcontrol->private_value >> 24) & 1;
44deee129   Risto Suominen   [ALSA] snd-powerm...
421
422
  	int val = snd_pmac_burgundy_rcb(chip, addr);
  	ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
423
  	if (stereo)
44deee129   Risto Suominen   [ALSA] snd-powerm...
424
  		ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
425
426
  	return 0;
  }
44deee129   Risto Suominen   [ALSA] snd-powerm...
427
428
  static int snd_pmac_burgundy_put_switch_b(struct snd_kcontrol *kcontrol,
  					  struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
429
  {
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
430
  	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
44deee129   Risto Suominen   [ALSA] snd-powerm...
431
432
433
  	unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
  	int lmask = kcontrol->private_value & 0xff;
  	int rmask = (kcontrol->private_value >> 8) & 0xff;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
434
  	int stereo = (kcontrol->private_value >> 24) & 1;
44deee129   Risto Suominen   [ALSA] snd-powerm...
435
436
437
438
439
440
441
  	int val, oval;
  	oval = snd_pmac_burgundy_rcb(chip, addr);
  	val = oval & ~(lmask | rmask);
  	if (ucontrol->value.integer.value[0])
  		val |= lmask;
  	if (stereo && ucontrol->value.integer.value[1])
  		val |= rmask;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
442
443
444
  	snd_pmac_burgundy_wcb(chip, addr, val);
  	return val != oval;
  }
44deee129   Risto Suominen   [ALSA] snd-powerm...
445
  #define BURGUNDY_SWITCH_B(xname, xindex, addr, lmask, rmask, stereo) \
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
446
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
44deee129   Risto Suominen   [ALSA] snd-powerm...
447
448
449
450
451
    .info = snd_pmac_burgundy_info_switch_b,\
    .get = snd_pmac_burgundy_get_switch_b,\
    .put = snd_pmac_burgundy_put_switch_b,\
    .private_value = ((lmask) | ((rmask) << 8)\
  		| (ADDR2BASE(addr) << 16) | ((stereo) << 24)) }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
452

44deee129   Risto Suominen   [ALSA] snd-powerm...
453
454
455
  /*
   * Burgundy mixers
   */
3e1e0a5dd   Takashi Iwai   ALSA: powermac - ...
456
  static struct snd_kcontrol_new snd_pmac_burgundy_mixers[] __devinitdata = {
44deee129   Risto Suominen   [ALSA] snd-powerm...
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
  	BURGUNDY_VOLUME_W("Master Playback Volume", 0,
  			MASK_ADDR_BURGUNDY_MASTER_VOLUME, 8),
  	BURGUNDY_VOLUME_W("CD Capture Volume", 0,
  			MASK_ADDR_BURGUNDY_VOLCD, 16),
  	BURGUNDY_VOLUME_2B("Input Capture Volume", 0,
  			MASK_ADDR_BURGUNDY_VOLMIX01, 2),
  	BURGUNDY_VOLUME_2B("Mixer Playback Volume", 0,
  			MASK_ADDR_BURGUNDY_VOLMIX23, 0),
  	BURGUNDY_VOLUME_B("CD Gain Capture Volume", 0,
  			MASK_ADDR_BURGUNDY_GAINCD, 1, 0),
  	BURGUNDY_SWITCH_W("Master Capture Switch", 0,
  			MASK_ADDR_BURGUNDY_OUTPUTENABLES, 24, 0, 0),
  	BURGUNDY_SWITCH_W("CD Capture Switch", 0,
  			MASK_ADDR_BURGUNDY_CAPTURESELECTS, 0, 16, 1),
  	BURGUNDY_SWITCH_W("CD Playback Switch", 0,
  			MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 0, 16, 1),
  /*	BURGUNDY_SWITCH_W("Loop Capture Switch", 0,
   *		MASK_ADDR_BURGUNDY_CAPTURESELECTS, 8, 24, 1),
   *	BURGUNDY_SWITCH_B("Mixer out Capture Switch", 0,
   *		MASK_ADDR_BURGUNDY_HOSTIFAD, 0x02, 0, 0),
   *	BURGUNDY_SWITCH_B("Mixer Capture Switch", 0,
   *		MASK_ADDR_BURGUNDY_HOSTIFAD, 0x01, 0, 0),
   *	BURGUNDY_SWITCH_B("PCM out Capture Switch", 0,
   *		MASK_ADDR_BURGUNDY_HOSTIFEH, 0x02, 0, 0),
   */	BURGUNDY_SWITCH_B("PCM Capture Switch", 0,
  			MASK_ADDR_BURGUNDY_HOSTIFEH, 0x01, 0, 0)
  };
3e1e0a5dd   Takashi Iwai   ALSA: powermac - ...
484
  static struct snd_kcontrol_new snd_pmac_burgundy_mixers_imac[] __devinitdata = {
44deee129   Risto Suominen   [ALSA] snd-powerm...
485
486
487
488
489
490
491
492
  	BURGUNDY_VOLUME_W("Line in Capture Volume", 0,
  			MASK_ADDR_BURGUNDY_VOLLINE, 16),
  	BURGUNDY_VOLUME_W("Mic Capture Volume", 0,
  			MASK_ADDR_BURGUNDY_VOLMIC, 16),
  	BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
  			MASK_ADDR_BURGUNDY_GAINLINE, 1, 0),
  	BURGUNDY_VOLUME_B("Mic Gain Capture Volume", 0,
  			MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
ad1cd7450   Jaroslav Kysela   ALSA: rename "PC ...
493
  	BURGUNDY_VOLUME_B("Speaker Playback Volume", 0,
44deee129   Risto Suominen   [ALSA] snd-powerm...
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
  			MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
  	BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
  			MASK_ADDR_BURGUNDY_ATTENLINEOUT, 1, 1),
  	BURGUNDY_VOLUME_B("Headphone Playback Volume", 0,
  			MASK_ADDR_BURGUNDY_ATTENHP, 1, 1),
  	BURGUNDY_SWITCH_W("Line in Capture Switch", 0,
  			MASK_ADDR_BURGUNDY_CAPTURESELECTS, 1, 17, 1),
  	BURGUNDY_SWITCH_W("Mic Capture Switch", 0,
  			MASK_ADDR_BURGUNDY_CAPTURESELECTS, 2, 18, 1),
  	BURGUNDY_SWITCH_W("Line in Playback Switch", 0,
  			MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 1, 17, 1),
  	BURGUNDY_SWITCH_W("Mic Playback Switch", 0,
  			MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 2, 18, 1),
  	BURGUNDY_SWITCH_B("Mic Boost Capture Switch", 0,
  			MASK_ADDR_BURGUNDY_INPBOOST, 0x40, 0x80, 1)
  };
3e1e0a5dd   Takashi Iwai   ALSA: powermac - ...
510
  static struct snd_kcontrol_new snd_pmac_burgundy_mixers_pmac[] __devinitdata = {
44deee129   Risto Suominen   [ALSA] snd-powerm...
511
512
513
514
  	BURGUNDY_VOLUME_W("Line in Capture Volume", 0,
  			MASK_ADDR_BURGUNDY_VOLMIC, 16),
  	BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
  			MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
ad1cd7450   Jaroslav Kysela   ALSA: rename "PC ...
515
  	BURGUNDY_VOLUME_B("Speaker Playback Volume", 0,
44deee129   Risto Suominen   [ALSA] snd-powerm...
516
517
518
519
520
521
522
523
524
525
  			MASK_ADDR_BURGUNDY_ATTENMONO, 0, 1),
  	BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
  			MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
  	BURGUNDY_SWITCH_W("Line in Capture Switch", 0,
  			MASK_ADDR_BURGUNDY_CAPTURESELECTS, 2, 18, 1),
  	BURGUNDY_SWITCH_W("Line in Playback Switch", 0,
  			MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 2, 18, 1),
  /*	BURGUNDY_SWITCH_B("Line in Boost Capture Switch", 0,
   *		MASK_ADDR_BURGUNDY_INPBOOST, 0x40, 0x80, 1) */
  };
3e1e0a5dd   Takashi Iwai   ALSA: powermac - ...
526
  static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_imac __devinitdata =
44deee129   Risto Suominen   [ALSA] snd-powerm...
527
528
529
530
  BURGUNDY_SWITCH_B("Master Playback Switch", 0,
  	MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  	BURGUNDY_OUTPUT_LEFT | BURGUNDY_LINEOUT_LEFT | BURGUNDY_HP_LEFT,
  	BURGUNDY_OUTPUT_RIGHT | BURGUNDY_LINEOUT_RIGHT | BURGUNDY_HP_RIGHT, 1);
3e1e0a5dd   Takashi Iwai   ALSA: powermac - ...
531
  static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_pmac __devinitdata =
44deee129   Risto Suominen   [ALSA] snd-powerm...
532
533
534
535
  BURGUNDY_SWITCH_B("Master Playback Switch", 0,
  	MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  	BURGUNDY_OUTPUT_INTERN
  	| BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
3e1e0a5dd   Takashi Iwai   ALSA: powermac - ...
536
  static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_imac __devinitdata =
ad1cd7450   Jaroslav Kysela   ALSA: rename "PC ...
537
  BURGUNDY_SWITCH_B("Speaker Playback Switch", 0,
44deee129   Risto Suominen   [ALSA] snd-powerm...
538
539
  	MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  	BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
3e1e0a5dd   Takashi Iwai   ALSA: powermac - ...
540
  static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_pmac __devinitdata =
ad1cd7450   Jaroslav Kysela   ALSA: rename "PC ...
541
  BURGUNDY_SWITCH_B("Speaker Playback Switch", 0,
44deee129   Risto Suominen   [ALSA] snd-powerm...
542
543
  	MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  	BURGUNDY_OUTPUT_INTERN, 0, 0);
3e1e0a5dd   Takashi Iwai   ALSA: powermac - ...
544
  static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_imac __devinitdata =
44deee129   Risto Suominen   [ALSA] snd-powerm...
545
546
547
  BURGUNDY_SWITCH_B("Line out Playback Switch", 0,
  	MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  	BURGUNDY_LINEOUT_LEFT, BURGUNDY_LINEOUT_RIGHT, 1);
3e1e0a5dd   Takashi Iwai   ALSA: powermac - ...
548
  static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_pmac __devinitdata =
44deee129   Risto Suominen   [ALSA] snd-powerm...
549
550
551
  BURGUNDY_SWITCH_B("Line out Playback Switch", 0,
  	MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  	BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
3e1e0a5dd   Takashi Iwai   ALSA: powermac - ...
552
  static struct snd_kcontrol_new snd_pmac_burgundy_hp_sw_imac __devinitdata =
44deee129   Risto Suominen   [ALSA] snd-powerm...
553
554
555
  BURGUNDY_SWITCH_B("Headphone Playback Switch", 0,
  	MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  	BURGUNDY_HP_LEFT, BURGUNDY_HP_RIGHT, 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
556
557
558
559
560
561
  
  
  #ifdef PMAC_SUPPORT_AUTOMUTE
  /*
   * auto-mute stuffs
   */
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
562
  static int snd_pmac_burgundy_detect_headphone(struct snd_pmac *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
563
564
565
  {
  	return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0;
  }
65b29f503   Takashi Iwai   [ALSA] Remove xxx...
566
  static void snd_pmac_burgundy_update_automute(struct snd_pmac *chip, int do_notify)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
567
568
  {
  	if (chip->auto_mute) {
71a157e8e   Grant Likely   of: add 'of_' pre...
569
  		int imac = of_machine_is_compatible("iMac");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
570
  		int reg, oreg;
44deee129   Risto Suominen   [ALSA] snd-powerm...
571
572
573
574
575
576
  		reg = oreg = snd_pmac_burgundy_rcb(chip,
  				MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES);
  		reg &= imac ? ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT
  				| BURGUNDY_HP_LEFT | BURGUNDY_HP_RIGHT)
  			: ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT
  				| BURGUNDY_OUTPUT_INTERN);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
577
  		if (snd_pmac_burgundy_detect_headphone(chip))
44deee129   Risto Suominen   [ALSA] snd-powerm...
578
579
580
  			reg |= imac ? (BURGUNDY_HP_LEFT | BURGUNDY_HP_RIGHT)
  				: (BURGUNDY_OUTPUT_LEFT
  					| BURGUNDY_OUTPUT_RIGHT);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
581
  		else
44deee129   Risto Suominen   [ALSA] snd-powerm...
582
583
584
  			reg |= imac ? (BURGUNDY_OUTPUT_LEFT
  					| BURGUNDY_OUTPUT_RIGHT)
  				: (BURGUNDY_OUTPUT_INTERN);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
585
586
  		if (do_notify && reg == oreg)
  			return;
44deee129   Risto Suominen   [ALSA] snd-powerm...
587
588
  		snd_pmac_burgundy_wcb(chip,
  				MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, reg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
  		if (do_notify) {
  			snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  				       &chip->master_sw_ctl->id);
  			snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  				       &chip->speaker_sw_ctl->id);
  			snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
  				       &chip->hp_detect_ctl->id);
  		}
  	}
  }
  #endif /* PMAC_SUPPORT_AUTOMUTE */
  
  
  /*
   * initialize burgundy
   */
5c9b6e9e6   Stephen Rothwell   ALSA: sound/ppc: ...
605
  int __devinit snd_pmac_burgundy_init(struct snd_pmac *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
606
  {
71a157e8e   Grant Likely   of: add 'of_' pre...
607
  	int imac = of_machine_is_compatible("iMac");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
608
609
610
611
612
613
614
615
  	int i, err;
  
  	/* Checks to see the chip is alive and kicking */
  	if ((in_le32(&chip->awacs->codec_ctrl) & MASK_ERRCODE) == 0xf0000) {
  		printk(KERN_WARNING "pmac burgundy: disabled by MacOS :-(
  ");
  		return 1;
  	}
44deee129   Risto Suominen   [ALSA] snd-powerm...
616
  	snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_OUTPUTENABLES,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
617
618
619
620
621
622
623
624
625
  			   DEF_BURGUNDY_OUTPUTENABLES);
  	snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
  			   DEF_BURGUNDY_MORE_OUTPUTENABLES);
  	snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_OUTPUTSELECTS,
  			   DEF_BURGUNDY_OUTPUTSELECTS);
  
  	snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL21,
  			   DEF_BURGUNDY_INPSEL21);
  	snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL3,
44deee129   Risto Suominen   [ALSA] snd-powerm...
626
627
  			   imac ? DEF_BURGUNDY_INPSEL3_IMAC
  			   : DEF_BURGUNDY_INPSEL3_PMAC);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
  	snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINCD,
  			   DEF_BURGUNDY_GAINCD);
  	snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINLINE,
  			   DEF_BURGUNDY_GAINLINE);
  	snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINMIC,
  			   DEF_BURGUNDY_GAINMIC);
  	snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINMODEM,
  			   DEF_BURGUNDY_GAINMODEM);
  
  	snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_ATTENSPEAKER,
  			   DEF_BURGUNDY_ATTENSPEAKER);
  	snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_ATTENLINEOUT,
  			   DEF_BURGUNDY_ATTENLINEOUT);
  	snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_ATTENHP,
  			   DEF_BURGUNDY_ATTENHP);
  
  	snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_MASTER_VOLUME,
  			   DEF_BURGUNDY_MASTER_VOLUME);
  	snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLCD,
  			   DEF_BURGUNDY_VOLCD);
  	snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLLINE,
  			   DEF_BURGUNDY_VOLLINE);
  	snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLMIC,
  			   DEF_BURGUNDY_VOLMIC);
44deee129   Risto Suominen   [ALSA] snd-powerm...
652
  	if (chip->hp_stat_mask == 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
653
  		/* set headphone-jack detection bit */
44deee129   Risto Suominen   [ALSA] snd-powerm...
654
655
656
657
658
659
660
  		if (imac)
  			chip->hp_stat_mask = BURGUNDY_HPDETECT_IMAC_UPPER
  				| BURGUNDY_HPDETECT_IMAC_LOWER
  				| BURGUNDY_HPDETECT_IMAC_SIDE;
  		else
  			chip->hp_stat_mask = BURGUNDY_HPDETECT_PMAC_BACK;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
661
662
663
664
665
666
  	/*
  	 * build burgundy mixers
  	 */
  	strcpy(chip->card->mixername, "PowerMac Burgundy");
  
  	for (i = 0; i < ARRAY_SIZE(snd_pmac_burgundy_mixers); i++) {
44deee129   Risto Suominen   [ALSA] snd-powerm...
667
668
669
670
671
672
673
674
675
676
677
  		err = snd_ctl_add(chip->card,
  		    snd_ctl_new1(&snd_pmac_burgundy_mixers[i], chip));
  		if (err < 0)
  			return err;
  	}
  	for (i = 0; i < (imac ? ARRAY_SIZE(snd_pmac_burgundy_mixers_imac)
  			: ARRAY_SIZE(snd_pmac_burgundy_mixers_pmac)); i++) {
  		err = snd_ctl_add(chip->card,
  		    snd_ctl_new1(imac ? &snd_pmac_burgundy_mixers_imac[i]
  		    : &snd_pmac_burgundy_mixers_pmac[i], chip));
  		if (err < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
678
679
  			return err;
  	}
44deee129   Risto Suominen   [ALSA] snd-powerm...
680
681
682
  	chip->master_sw_ctl = snd_ctl_new1(imac
  			? &snd_pmac_burgundy_master_sw_imac
  			: &snd_pmac_burgundy_master_sw_pmac, chip);
20861fa7b   Risto Suominen   [ALSA] snd-powerm...
683
684
  	err = snd_ctl_add(chip->card, chip->master_sw_ctl);
  	if (err < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
685
  		return err;
44deee129   Risto Suominen   [ALSA] snd-powerm...
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
  	chip->master_sw_ctl = snd_ctl_new1(imac
  			? &snd_pmac_burgundy_line_sw_imac
  			: &snd_pmac_burgundy_line_sw_pmac, chip);
  	err = snd_ctl_add(chip->card, chip->master_sw_ctl);
  	if (err < 0)
  		return err;
  	if (imac) {
  		chip->master_sw_ctl = snd_ctl_new1(
  				&snd_pmac_burgundy_hp_sw_imac, chip);
  		err = snd_ctl_add(chip->card, chip->master_sw_ctl);
  		if (err < 0)
  			return err;
  	}
  	chip->speaker_sw_ctl = snd_ctl_new1(imac
  			? &snd_pmac_burgundy_speaker_sw_imac
  			: &snd_pmac_burgundy_speaker_sw_pmac, chip);
20861fa7b   Risto Suominen   [ALSA] snd-powerm...
702
703
  	err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
  	if (err < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
704
705
  		return err;
  #ifdef PMAC_SUPPORT_AUTOMUTE
20861fa7b   Risto Suominen   [ALSA] snd-powerm...
706
707
  	err = snd_pmac_add_automute(chip);
  	if (err < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
708
709
710
711
712
713
714
715
716
  		return err;
  
  	chip->detect_headphone = snd_pmac_burgundy_detect_headphone;
  	chip->update_automute = snd_pmac_burgundy_update_automute;
  	snd_pmac_burgundy_update_automute(chip, 0); /* update the status only */
  #endif
  
  	return 0;
  }