awacs.c 30.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/*
 * PMac AWACS 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
 */


#include <asm/io.h>
#include <asm/nvram.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <sound/core.h>
#include "pmac.h"


#ifdef CONFIG_ADB_CUDA
#define PMAC_AMP_AVAIL
#endif

#ifdef PMAC_AMP_AVAIL
37
struct awacs_amp {
L
Linus Torvalds 已提交
38 39 40
	unsigned char amp_master;
	unsigned char amp_vol[2][2];
	unsigned char amp_tone[2];
41
};
L
Linus Torvalds 已提交
42 43 44 45 46 47

#define CHECK_CUDA_AMP() (sys_ctrler == SYS_CTRLER_CUDA)

#endif /* PMAC_AMP_AVAIL */


48
static void snd_pmac_screamer_wait(struct snd_pmac *chip)
L
Linus Torvalds 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
{
	long timeout = 2000;
	while (!(in_le32(&chip->awacs->codec_stat) & MASK_VALID)) {
		mdelay(1);
		if (! --timeout) {
			snd_printd("snd_pmac_screamer_wait timeout\n");
			break;
		}
	}
}

/*
 * write AWACS register
 */
static void
64
snd_pmac_awacs_write(struct snd_pmac *chip, int val)
L
Linus Torvalds 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
{
	long timeout = 5000000;

	if (chip->model == PMAC_SCREAMER)
		snd_pmac_screamer_wait(chip);
	out_le32(&chip->awacs->codec_ctrl, val | (chip->subframe << 22));
	while (in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) {
		if (! --timeout) {
			snd_printd("snd_pmac_awacs_write timeout\n");
			break;
		}
	}
}

static void
80
snd_pmac_awacs_write_reg(struct snd_pmac *chip, int reg, int val)
L
Linus Torvalds 已提交
81 82 83 84 85 86
{
	snd_pmac_awacs_write(chip, val | (reg << 12));
	chip->awacs_reg[reg] = val;
}

static void
87
snd_pmac_awacs_write_noreg(struct snd_pmac *chip, int reg, int val)
L
Linus Torvalds 已提交
88 89 90 91
{
	snd_pmac_awacs_write(chip, val | (reg << 12));
}

92
#ifdef CONFIG_PM
L
Linus Torvalds 已提交
93
/* Recalibrate chip */
94
static void screamer_recalibrate(struct snd_pmac *chip)
L
Linus Torvalds 已提交
95 96 97 98 99 100 101 102 103 104
{
	if (chip->model != PMAC_SCREAMER)
		return;

	/* Sorry for the horrible delays... I hope to get that improved
	 * by making the whole PM process asynchronous in a future version
	 */
	snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
	if (chip->manufacturer == 0x1)
		/* delay for broken crystal part */
105
		msleep(750);
L
Linus Torvalds 已提交
106
	snd_pmac_awacs_write_noreg(chip, 1,
107 108
				   chip->awacs_reg[1] | MASK_RECALIBRATE |
				   MASK_CMUTE | MASK_AMUTE);
L
Linus Torvalds 已提交
109 110 111 112 113 114 115 116 117 118 119 120
	snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
	snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
}

#else
#define screamer_recalibrate(chip) /* NOP */
#endif


/*
 * additional callback to set the pcm format
 */
121
static void snd_pmac_awacs_set_format(struct snd_pmac *chip)
L
Linus Torvalds 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134
{
	chip->awacs_reg[1] &= ~MASK_SAMPLERATE;
	chip->awacs_reg[1] |= chip->rate_index << 3;
	snd_pmac_awacs_write_reg(chip, 1, chip->awacs_reg[1]);
}


/*
 * AWACS volume callbacks
 */
/*
 * volumes: 0-15 stereo
 */
135 136
static int snd_pmac_awacs_info_volume(struct snd_kcontrol *kcontrol,
				      struct snd_ctl_elem_info *uinfo)
L
Linus Torvalds 已提交
137 138 139 140 141 142 143
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 2;
	uinfo->value.integer.min = 0;
	uinfo->value.integer.max = 15;
	return 0;
}
144

145 146
static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol,
				     struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
147
{
148
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
L
Linus Torvalds 已提交
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
	int reg = kcontrol->private_value & 0xff;
	int lshift = (kcontrol->private_value >> 8) & 0xff;
	int inverted = (kcontrol->private_value >> 16) & 1;
	unsigned long flags;
	int vol[2];

	spin_lock_irqsave(&chip->reg_lock, flags);
	vol[0] = (chip->awacs_reg[reg] >> lshift) & 0xf;
	vol[1] = chip->awacs_reg[reg] & 0xf;
	spin_unlock_irqrestore(&chip->reg_lock, flags);
	if (inverted) {
		vol[0] = 0x0f - vol[0];
		vol[1] = 0x0f - vol[1];
	}
	ucontrol->value.integer.value[0] = vol[0];
	ucontrol->value.integer.value[1] = vol[1];
	return 0;
}

168 169
static int snd_pmac_awacs_put_volume(struct snd_kcontrol *kcontrol,
				     struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
170
{
171
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
L
Linus Torvalds 已提交
172 173 174 175 176
	int reg = kcontrol->private_value & 0xff;
	int lshift = (kcontrol->private_value >> 8) & 0xff;
	int inverted = (kcontrol->private_value >> 16) & 1;
	int val, oldval;
	unsigned long flags;
177
	unsigned int vol[2];
L
Linus Torvalds 已提交
178 179 180

	vol[0] = ucontrol->value.integer.value[0];
	vol[1] = ucontrol->value.integer.value[1];
181 182
	if (vol[0] > 0x0f || vol[1] > 0x0f)
		return -EINVAL;
L
Linus Torvalds 已提交
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
	if (inverted) {
		vol[0] = 0x0f - vol[0];
		vol[1] = 0x0f - vol[1];
	}
	vol[0] &= 0x0f;
	vol[1] &= 0x0f;
	spin_lock_irqsave(&chip->reg_lock, flags);
	oldval = chip->awacs_reg[reg];
	val = oldval & ~(0xf | (0xf << lshift));
	val |= vol[0] << lshift;
	val |= vol[1];
	if (oldval != val)
		snd_pmac_awacs_write_reg(chip, reg, val);
	spin_unlock_irqrestore(&chip->reg_lock, flags);
	return oldval != reg;
}


#define AWACS_VOLUME(xname, xreg, xshift, xinverted) \
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  .info = snd_pmac_awacs_info_volume, \
  .get = snd_pmac_awacs_get_volume, \
  .put = snd_pmac_awacs_put_volume, \
  .private_value = (xreg) | ((xshift) << 8) | ((xinverted) << 16) }

/*
 * mute master/ogain for AWACS: mono
 */
211 212
static int snd_pmac_awacs_get_switch(struct snd_kcontrol *kcontrol,
				     struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
213
{
214
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
L
Linus Torvalds 已提交
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
	int reg = kcontrol->private_value & 0xff;
	int shift = (kcontrol->private_value >> 8) & 0xff;
	int invert = (kcontrol->private_value >> 16) & 1;
	int val;
	unsigned long flags;

	spin_lock_irqsave(&chip->reg_lock, flags);
	val = (chip->awacs_reg[reg] >> shift) & 1;
	spin_unlock_irqrestore(&chip->reg_lock, flags);
	if (invert)
		val = 1 - val;
	ucontrol->value.integer.value[0] = val;
	return 0;
}

230 231
static int snd_pmac_awacs_put_switch(struct snd_kcontrol *kcontrol,
				     struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
232
{
233
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
L
Linus Torvalds 已提交
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
	int reg = kcontrol->private_value & 0xff;
	int shift = (kcontrol->private_value >> 8) & 0xff;
	int invert = (kcontrol->private_value >> 16) & 1;
	int mask = 1 << shift;
	int val, changed;
	unsigned long flags;

	spin_lock_irqsave(&chip->reg_lock, flags);
	val = chip->awacs_reg[reg] & ~mask;
	if (ucontrol->value.integer.value[0] != invert)
		val |= mask;
	changed = chip->awacs_reg[reg] != val;
	if (changed)
		snd_pmac_awacs_write_reg(chip, reg, val);
	spin_unlock_irqrestore(&chip->reg_lock, flags);
	return changed;
}

#define AWACS_SWITCH(xname, xreg, xshift, xinvert) \
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  .info = snd_pmac_boolean_mono_info, \
  .get = snd_pmac_awacs_get_switch, \
  .put = snd_pmac_awacs_put_switch, \
  .private_value = (xreg) | ((xshift) << 8) | ((xinvert) << 16) }


#ifdef PMAC_AMP_AVAIL
/*
 * controls for perch/whisper extension cards, e.g. G3 desktop
 *
 * TDA7433 connected via i2c address 0x45 (= 0x8a),
 * accessed through cuda
 */
static void awacs_set_cuda(int reg, int val)
{
	struct adb_request req;
270 271
	cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a,
			reg, val);
L
Linus Torvalds 已提交
272 273 274 275 276 277 278
	while (! req.complete)
		cuda_poll();
}

/*
 * level = 0 - 14, 7 = 0 dB
 */
279
static void awacs_amp_set_tone(struct awacs_amp *amp, int bass, int treble)
L
Linus Torvalds 已提交
280 281 282 283 284 285 286 287 288 289 290 291 292
{
	amp->amp_tone[0] = bass;
	amp->amp_tone[1] = treble;
	if (bass > 7)
		bass = (14 - bass) + 8;
	if (treble > 7)
		treble = (14 - treble) + 8;
	awacs_set_cuda(2, (bass << 4) | treble);
}

/*
 * vol = 0 - 31 (attenuation), 32 = mute bit, stereo
 */
293 294
static int awacs_amp_set_vol(struct awacs_amp *amp, int index,
			     int lvol, int rvol, int do_check)
L
Linus Torvalds 已提交
295 296
{
	if (do_check && amp->amp_vol[index][0] == lvol &&
297
			amp->amp_vol[index][1] == rvol)
L
Linus Torvalds 已提交
298 299 300 301 302 303 304 305 306 307 308
		return 0;
	awacs_set_cuda(3 + index, lvol);
	awacs_set_cuda(5 + index, rvol);
	amp->amp_vol[index][0] = lvol;
	amp->amp_vol[index][1] = rvol;
	return 1;
}

/*
 * 0 = -79 dB, 79 = 0 dB, 99 = +20 dB
 */
309
static void awacs_amp_set_master(struct awacs_amp *amp, int vol)
L
Linus Torvalds 已提交
310 311 312 313 314 315 316 317 318
{
	amp->amp_master = vol;
	if (vol <= 79)
		vol = 32 + (79 - vol);
	else
		vol = 32 - (vol - 79);
	awacs_set_cuda(1, vol);
}

319
static void awacs_amp_free(struct snd_pmac *chip)
L
Linus Torvalds 已提交
320
{
321
	struct awacs_amp *amp = chip->mixer_data;
L
Linus Torvalds 已提交
322 323 324 325 326 327 328 329 330 331
	snd_assert(amp, return);
	kfree(amp);
	chip->mixer_data = NULL;
	chip->mixer_free = NULL;
}


/*
 * mixer controls
 */
332 333
static int snd_pmac_awacs_info_volume_amp(struct snd_kcontrol *kcontrol,
					  struct snd_ctl_elem_info *uinfo)
L
Linus Torvalds 已提交
334 335 336 337 338 339 340
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 2;
	uinfo->value.integer.min = 0;
	uinfo->value.integer.max = 31;
	return 0;
}
341

342 343
static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol,
					 struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
344
{
345
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
L
Linus Torvalds 已提交
346
	int index = kcontrol->private_value;
347
	struct awacs_amp *amp = chip->mixer_data;
L
Linus Torvalds 已提交
348 349 350 351 352 353 354
	snd_assert(amp, return -EINVAL);
	snd_assert(index >= 0 && index <= 1, return -EINVAL);
	ucontrol->value.integer.value[0] = 31 - (amp->amp_vol[index][0] & 31);
	ucontrol->value.integer.value[1] = 31 - (amp->amp_vol[index][1] & 31);
	return 0;
}

355 356
static int snd_pmac_awacs_put_volume_amp(struct snd_kcontrol *kcontrol,
					 struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
357
{
358
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
L
Linus Torvalds 已提交
359 360
	int index = kcontrol->private_value;
	int vol[2];
361
	struct awacs_amp *amp = chip->mixer_data;
L
Linus Torvalds 已提交
362 363 364
	snd_assert(amp, return -EINVAL);
	snd_assert(index >= 0 && index <= 1, return -EINVAL);

365 366 367 368
	vol[0] = (31 - (ucontrol->value.integer.value[0] & 31))
		| (amp->amp_vol[index][0] & 32);
	vol[1] = (31 - (ucontrol->value.integer.value[1] & 31))
		| (amp->amp_vol[index][1] & 32);
L
Linus Torvalds 已提交
369 370 371
	return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
}

372 373
static int snd_pmac_awacs_get_switch_amp(struct snd_kcontrol *kcontrol,
					 struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
374
{
375
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
L
Linus Torvalds 已提交
376
	int index = kcontrol->private_value;
377
	struct awacs_amp *amp = chip->mixer_data;
L
Linus Torvalds 已提交
378 379
	snd_assert(amp, return -EINVAL);
	snd_assert(index >= 0 && index <= 1, return -EINVAL);
380 381 382 383
	ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32)
					? 0 : 1;
	ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32)
					? 0 : 1;
L
Linus Torvalds 已提交
384 385 386
	return 0;
}

387 388
static int snd_pmac_awacs_put_switch_amp(struct snd_kcontrol *kcontrol,
					 struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
389
{
390
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
L
Linus Torvalds 已提交
391 392
	int index = kcontrol->private_value;
	int vol[2];
393
	struct awacs_amp *amp = chip->mixer_data;
L
Linus Torvalds 已提交
394 395 396
	snd_assert(amp, return -EINVAL);
	snd_assert(index >= 0 && index <= 1, return -EINVAL);

397 398 399 400
	vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32)
		| (amp->amp_vol[index][0] & 31);
	vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32)
		| (amp->amp_vol[index][1] & 31);
L
Linus Torvalds 已提交
401 402 403
	return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
}

404 405
static int snd_pmac_awacs_info_tone_amp(struct snd_kcontrol *kcontrol,
					struct snd_ctl_elem_info *uinfo)
L
Linus Torvalds 已提交
406 407 408 409 410 411 412
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 1;
	uinfo->value.integer.min = 0;
	uinfo->value.integer.max = 14;
	return 0;
}
413

414 415
static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol,
				       struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
416
{
417
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
L
Linus Torvalds 已提交
418
	int index = kcontrol->private_value;
419
	struct awacs_amp *amp = chip->mixer_data;
L
Linus Torvalds 已提交
420 421 422 423 424 425
	snd_assert(amp, return -EINVAL);
	snd_assert(index >= 0 && index <= 1, return -EINVAL);
	ucontrol->value.integer.value[0] = amp->amp_tone[index];
	return 0;
}

426 427
static int snd_pmac_awacs_put_tone_amp(struct snd_kcontrol *kcontrol,
				       struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
428
{
429
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
L
Linus Torvalds 已提交
430
	int index = kcontrol->private_value;
431
	struct awacs_amp *amp = chip->mixer_data;
432
	unsigned int val;
L
Linus Torvalds 已提交
433 434
	snd_assert(amp, return -EINVAL);
	snd_assert(index >= 0 && index <= 1, return -EINVAL);
435 436 437 438 439
	val = ucontrol->value.integer.value[0];
	if (val > 14)
		return -EINVAL;
	if (val != amp->amp_tone[index]) {
		amp->amp_tone[index] = val;
L
Linus Torvalds 已提交
440 441 442 443 444 445
		awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
		return 1;
	}
	return 0;
}

446 447
static int snd_pmac_awacs_info_master_amp(struct snd_kcontrol *kcontrol,
					  struct snd_ctl_elem_info *uinfo)
L
Linus Torvalds 已提交
448 449 450 451 452 453 454
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 1;
	uinfo->value.integer.min = 0;
	uinfo->value.integer.max = 99;
	return 0;
}
455

456 457
static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol,
					 struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
458
{
459 460
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
	struct awacs_amp *amp = chip->mixer_data;
L
Linus Torvalds 已提交
461 462 463 464 465
	snd_assert(amp, return -EINVAL);
	ucontrol->value.integer.value[0] = amp->amp_master;
	return 0;
}

466 467
static int snd_pmac_awacs_put_master_amp(struct snd_kcontrol *kcontrol,
					 struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
468
{
469 470
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
	struct awacs_amp *amp = chip->mixer_data;
471
	unsigned int val;
L
Linus Torvalds 已提交
472
	snd_assert(amp, return -EINVAL);
473 474 475 476 477
	val = ucontrol->value.integer.value[0];
	if (val > 99)
		return -EINVAL;
	if (val != amp->amp_master) {
		amp->amp_master = val;
L
Linus Torvalds 已提交
478 479 480 481 482 483 484 485 486
		awacs_amp_set_master(amp, amp->amp_master);
		return 1;
	}
	return 0;
}

#define AMP_CH_SPK	0
#define AMP_CH_HD	1

487
static struct snd_kcontrol_new snd_pmac_awacs_amp_vol[] __initdata = {
L
Linus Torvalds 已提交
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
	  .name = "PC Speaker Playback Volume",
	  .info = snd_pmac_awacs_info_volume_amp,
	  .get = snd_pmac_awacs_get_volume_amp,
	  .put = snd_pmac_awacs_put_volume_amp,
	  .private_value = AMP_CH_SPK,
	},
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
	  .name = "Headphone Playback Volume",
	  .info = snd_pmac_awacs_info_volume_amp,
	  .get = snd_pmac_awacs_get_volume_amp,
	  .put = snd_pmac_awacs_put_volume_amp,
	  .private_value = AMP_CH_HD,
	},
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
	  .name = "Tone Control - Bass",
	  .info = snd_pmac_awacs_info_tone_amp,
	  .get = snd_pmac_awacs_get_tone_amp,
	  .put = snd_pmac_awacs_put_tone_amp,
	  .private_value = 0,
	},
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
	  .name = "Tone Control - Treble",
	  .info = snd_pmac_awacs_info_tone_amp,
	  .get = snd_pmac_awacs_get_tone_amp,
	  .put = snd_pmac_awacs_put_tone_amp,
	  .private_value = 1,
	},
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
	  .name = "Amp Master Playback Volume",
	  .info = snd_pmac_awacs_info_master_amp,
	  .get = snd_pmac_awacs_get_master_amp,
	  .put = snd_pmac_awacs_put_master_amp,
	},
};

524
static struct snd_kcontrol_new snd_pmac_awacs_amp_hp_sw __initdata = {
L
Linus Torvalds 已提交
525 526 527 528 529 530 531 532
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
	.name = "Headphone Playback Switch",
	.info = snd_pmac_boolean_stereo_info,
	.get = snd_pmac_awacs_get_switch_amp,
	.put = snd_pmac_awacs_put_switch_amp,
	.private_value = AMP_CH_HD,
};

533
static struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw __initdata = {
L
Linus Torvalds 已提交
534 535 536 537 538 539 540 541 542 543 544 545 546 547
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
	.name = "PC Speaker Playback Switch",
	.info = snd_pmac_boolean_stereo_info,
	.get = snd_pmac_awacs_get_switch_amp,
	.put = snd_pmac_awacs_put_switch_amp,
	.private_value = AMP_CH_SPK,
};

#endif /* PMAC_AMP_AVAIL */


/*
 * mic boost for screamer
 */
548 549
static int snd_pmac_screamer_mic_boost_info(struct snd_kcontrol *kcontrol,
					    struct snd_ctl_elem_info *uinfo)
L
Linus Torvalds 已提交
550 551 552 553
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 1;
	uinfo->value.integer.min = 0;
554
	uinfo->value.integer.max = 3;
L
Linus Torvalds 已提交
555 556 557
	return 0;
}

558 559
static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol *kcontrol,
					   struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
560
{
561
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
562
	int val = 0;
L
Linus Torvalds 已提交
563 564 565 566
	unsigned long flags;

	spin_lock_irqsave(&chip->reg_lock, flags);
	if (chip->awacs_reg[6] & MASK_MIC_BOOST)
567 568 569
		val |= 2;
	if (chip->awacs_reg[0] & MASK_GAINLINE)
		val |= 1;
L
Linus Torvalds 已提交
570 571 572 573 574
	spin_unlock_irqrestore(&chip->reg_lock, flags);
	ucontrol->value.integer.value[0] = val;
	return 0;
}

575 576
static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
					   struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
577
{
578
	struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
L
Linus Torvalds 已提交
579 580 581 582 583 584 585
	int changed = 0;
	int val0, val6;
	unsigned long flags;

	spin_lock_irqsave(&chip->reg_lock, flags);
	val0 = chip->awacs_reg[0] & ~MASK_GAINLINE;
	val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST;
586
	if (ucontrol->value.integer.value[0] & 1)
L
Linus Torvalds 已提交
587
		val0 |= MASK_GAINLINE;
588 589
	if (ucontrol->value.integer.value[0] & 2)
		val6 |= MASK_MIC_BOOST;
L
Linus Torvalds 已提交
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
	if (val0 != chip->awacs_reg[0]) {
		snd_pmac_awacs_write_reg(chip, 0, val0);
		changed = 1;
	}
	if (val6 != chip->awacs_reg[6]) {
		snd_pmac_awacs_write_reg(chip, 6, val6);
		changed = 1;
	}
	spin_unlock_irqrestore(&chip->reg_lock, flags);
	return changed;
}

/*
 * lists of mixer elements
 */
605
static struct snd_kcontrol_new snd_pmac_awacs_mixers[] __initdata = {
L
Linus Torvalds 已提交
606
	AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0),
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
	AWACS_VOLUME("Master Capture Volume", 0, 4, 0),
/*	AWACS_SWITCH("Unknown Playback Switch", 6, SHIFT_PAROUT0, 0), */
};

static struct snd_kcontrol_new snd_pmac_screamer_mixers_beige[] __initdata = {
	AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
	AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1),
	AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
	AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_LINE, 0),
};

static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] __initdata = {
	AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
	AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
	AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
};

624 625 626 627 628 629 630
static struct snd_kcontrol_new snd_pmac_screamer_mixers_g4agp[] __initdata = {
	AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
	AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
	AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
	AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
};

631 632 633 634 635 636 637 638
static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] __initdata = {
	AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
	AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
	AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
};

static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] __initdata = {
	AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
L
Linus Torvalds 已提交
639 640 641 642 643 644
	AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
};

/* FIXME: is this correct order?
 * screamer (powerbook G3 pismo) seems to have different bits...
 */
645
static struct snd_kcontrol_new snd_pmac_awacs_mixers2[] __initdata = {
L
Linus Torvalds 已提交
646 647 648 649
	AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_LINE, 0),
	AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_MIC, 0),
};

650
static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] __initdata = {
L
Linus Torvalds 已提交
651 652 653 654
	AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
	AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_LINE, 0),
};

655
static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata =
L
Linus Torvalds 已提交
656 657
AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1);

658 659 660
static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac __initdata =
AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1);

661
static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = {
662
	AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
L
Linus Torvalds 已提交
663 664
};

665
static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __initdata = {
L
Linus Torvalds 已提交
666
	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
667
	  .name = "Mic Boost Capture Volume",
L
Linus Torvalds 已提交
668 669 670 671 672 673
	  .info = snd_pmac_screamer_mic_boost_info,
	  .get = snd_pmac_screamer_mic_boost_get,
	  .put = snd_pmac_screamer_mic_boost_put,
	},
};

674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
static struct snd_kcontrol_new snd_pmac_awacs_mic_boost_pmac7500[] __initdata =
{
	AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
};

static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_beige[] __initdata =
{
	AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
	AWACS_SWITCH("CD Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
};

static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] __initdata =
{
	AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
	AWACS_SWITCH("Mic Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
};

691
static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __initdata = {
L
Linus Torvalds 已提交
692 693
	AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1),
};
694

695
static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata =
L
Linus Torvalds 已提交
696 697
AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);

698 699 700
static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac __initdata =
AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 0);

L
Linus Torvalds 已提交
701 702 703 704

/*
 * add new mixer elements to the card
 */
705 706
static int build_mixers(struct snd_pmac *chip, int nums,
			struct snd_kcontrol_new *mixers)
L
Linus Torvalds 已提交
707 708 709 710
{
	int i, err;

	for (i = 0; i < nums; i++) {
711 712
		err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip));
		if (err < 0)
L
Linus Torvalds 已提交
713 714 715 716 717 718 719 720 721
			return err;
	}
	return 0;
}


/*
 * restore all registers
 */
722
static void awacs_restore_all_regs(struct snd_pmac *chip)
L
Linus Torvalds 已提交
723 724 725 726 727 728 729 730 731 732 733 734
{
	snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
	snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
	snd_pmac_awacs_write_noreg(chip, 2, chip->awacs_reg[2]);
	snd_pmac_awacs_write_noreg(chip, 4, chip->awacs_reg[4]);
	if (chip->model == PMAC_SCREAMER) {
		snd_pmac_awacs_write_noreg(chip, 5, chip->awacs_reg[5]);
		snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
		snd_pmac_awacs_write_noreg(chip, 7, chip->awacs_reg[7]);
	}
}

735
#ifdef CONFIG_PM
736
static void snd_pmac_awacs_suspend(struct snd_pmac *chip)
L
Linus Torvalds 已提交
737 738 739 740 741
{
	snd_pmac_awacs_write_noreg(chip, 1, (chip->awacs_reg[1]
					     | MASK_AMUTE | MASK_CMUTE));
}

742
static void snd_pmac_awacs_resume(struct snd_pmac *chip)
L
Linus Torvalds 已提交
743 744 745
{
	if (machine_is_compatible("PowerBook3,1")
	    || machine_is_compatible("PowerBook3,2")) {
746
		msleep(100);
L
Linus Torvalds 已提交
747 748
		snd_pmac_awacs_write_reg(chip, 1,
			chip->awacs_reg[1] & ~MASK_PAROUT);
749
		msleep(300);
L
Linus Torvalds 已提交
750 751 752 753 754 755 756 757 758 759 760
	}

	awacs_restore_all_regs(chip);
	if (chip->model == PMAC_SCREAMER) {
		/* reset power bits in reg 6 */
		mdelay(5);
		snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
	}
	screamer_recalibrate(chip);
#ifdef PMAC_AMP_AVAIL
	if (chip->mixer_data) {
761
		struct awacs_amp *amp = chip->mixer_data;
762 763 764 765
		awacs_amp_set_vol(amp, 0,
				  amp->amp_vol[0][0], amp->amp_vol[0][1], 0);
		awacs_amp_set_vol(amp, 1,
				  amp->amp_vol[1][0], amp->amp_vol[1][1], 0);
L
Linus Torvalds 已提交
766 767 768 769 770
		awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
		awacs_amp_set_master(amp, amp->amp_master);
	}
#endif
}
771
#endif /* CONFIG_PM */
L
Linus Torvalds 已提交
772

773 774 775 776 777
#define IS_PM7500 (machine_is_compatible("AAPL,7500"))
#define IS_BEIGE (machine_is_compatible("AAPL,Gossamer"))
#define IS_IMAC (machine_is_compatible("PowerMac2,1") \
		|| machine_is_compatible("PowerMac2,2") \
		|| machine_is_compatible("PowerMac4,1"))
778
#define IS_G4AGP (machine_is_compatible("PowerMac3,1"))
779 780 781

static int imac;

L
Linus Torvalds 已提交
782 783 784 785
#ifdef PMAC_SUPPORT_AUTOMUTE
/*
 * auto-mute stuffs
 */
786
static int snd_pmac_awacs_detect_headphone(struct snd_pmac *chip)
L
Linus Torvalds 已提交
787 788 789 790 791
{
	return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0;
}

#ifdef PMAC_AMP_AVAIL
792
static int toggle_amp_mute(struct awacs_amp *amp, int index, int mute)
L
Linus Torvalds 已提交
793 794 795 796 797 798 799 800 801 802 803 804
{
	int vol[2];
	vol[0] = amp->amp_vol[index][0] & 31;
	vol[1] = amp->amp_vol[index][1] & 31;
	if (mute) {
		vol[0] |= 32;
		vol[1] |= 32;
	}
	return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
}
#endif

805
static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
L
Linus Torvalds 已提交
806 807 808 809
{
	if (chip->auto_mute) {
#ifdef PMAC_AMP_AVAIL
		if (chip->mixer_data) {
810
			struct awacs_amp *amp = chip->mixer_data;
L
Linus Torvalds 已提交
811 812 813 814 815 816 817 818 819 820 821 822 823
			int changed;
			if (snd_pmac_awacs_detect_headphone(chip)) {
				changed = toggle_amp_mute(amp, AMP_CH_HD, 0);
				changed |= toggle_amp_mute(amp, AMP_CH_SPK, 1);
			} else {
				changed = toggle_amp_mute(amp, AMP_CH_HD, 1);
				changed |= toggle_amp_mute(amp, AMP_CH_SPK, 0);
			}
			if (do_notify && ! changed)
				return;
		} else
#endif
		{
824 825 826 827 828 829
			int reg = chip->awacs_reg[1]
				| (MASK_HDMUTE | MASK_SPKMUTE);
			if (imac) {
				reg &= ~MASK_SPKMUTE;
				reg &= ~MASK_PAROUT1;
			}
L
Linus Torvalds 已提交
830 831
			if (snd_pmac_awacs_detect_headphone(chip))
				reg &= ~MASK_HDMUTE;
832 833
			else if (imac)
				reg |= MASK_PAROUT1;
L
Linus Torvalds 已提交
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
			else
				reg &= ~MASK_SPKMUTE;
			if (do_notify && reg == chip->awacs_reg[1])
				return;
			snd_pmac_awacs_write_reg(chip, 1, reg);
		}
		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 chip
 */
int __init
857
snd_pmac_awacs_init(struct snd_pmac *chip)
L
Linus Torvalds 已提交
858
{
859 860
	int pm7500 = IS_PM7500;
	int beige = IS_BEIGE;
861
	int g4agp = IS_G4AGP;
L
Linus Torvalds 已提交
862 863
	int err, vol;

864
	imac = IS_IMAC;
L
Linus Torvalds 已提交
865 866 867 868 869 870 871
	/* looks like MASK_GAINLINE triggers something, so we set here
	 * as start-up
	 */
	chip->awacs_reg[0] = MASK_MUX_CD | 0xff | MASK_GAINLINE;
	chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE;
	/* FIXME: Only machines with external SRS module need MASK_PAROUT */
	if (chip->has_iic || chip->device_id == 0x5 ||
872
	    /* chip->_device_id == 0x8 || */
L
Linus Torvalds 已提交
873 874 875 876 877 878 879 880 881 882
	    chip->device_id == 0xb)
		chip->awacs_reg[1] |= MASK_PAROUT;
	/* get default volume from nvram */
	// vol = (~nvram_read_byte(0x1308) & 7) << 1;
	// vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
	vol = 0x0f; /* no, on alsa, muted as default */
	vol = vol + (vol << 6);
	chip->awacs_reg[2] = vol;
	chip->awacs_reg[4] = vol;
	if (chip->model == PMAC_SCREAMER) {
883 884 885 886
		/* FIXME: screamer has loopthru vol control */
		chip->awacs_reg[5] = vol;
		/* FIXME: maybe should be vol << 3 for PCMCIA speaker */
		chip->awacs_reg[6] = MASK_MIC_BOOST;
L
Linus Torvalds 已提交
887 888 889 890 891 892 893 894 895 896
		chip->awacs_reg[7] = 0;
	}

	awacs_restore_all_regs(chip);
	chip->manufacturer = (in_le32(&chip->awacs->codec_stat) >> 8) & 0xf;
	screamer_recalibrate(chip);

	chip->revision = (in_le32(&chip->awacs->codec_stat) >> 12) & 0xf;
#ifdef PMAC_AMP_AVAIL
	if (chip->revision == 3 && chip->has_iic && CHECK_CUDA_AMP()) {
897
		struct awacs_amp *amp = kzalloc(sizeof(*amp), GFP_KERNEL);
L
Linus Torvalds 已提交
898 899 900 901
		if (! amp)
			return -ENOMEM;
		chip->mixer_data = amp;
		chip->mixer_free = awacs_amp_free;
902 903
		/* mute and zero vol */
		awacs_amp_set_vol(amp, 0, 63, 63, 0);
L
Linus Torvalds 已提交
904 905 906 907 908 909 910 911 912 913
		awacs_amp_set_vol(amp, 1, 63, 63, 0);
		awacs_amp_set_tone(amp, 7, 7); /* 0 dB */
		awacs_amp_set_master(amp, 79); /* 0 dB */
	}
#endif /* PMAC_AMP_AVAIL */

	if (chip->hp_stat_mask == 0) {
		/* set headphone-jack detection bit */
		switch (chip->model) {
		case PMAC_AWACS:
914 915
			chip->hp_stat_mask = pm7500 ? MASK_HDPCONN
				: MASK_LOCONN;
L
Linus Torvalds 已提交
916 917 918 919
			break;
		case PMAC_SCREAMER:
			switch (chip->device_id) {
			case 0x08:
920 921 922 923 924 925
			case 0x0B:
				chip->hp_stat_mask = imac
					? MASK_LOCONN_IMAC |
					MASK_HDPLCONN_IMAC |
					MASK_HDPRCONN_IMAC
					: MASK_HDPCONN;
L
Linus Torvalds 已提交
926 927 928
				break;
			case 0x00:
			case 0x05:
929
				chip->hp_stat_mask = MASK_LOCONN;
L
Linus Torvalds 已提交
930 931
				break;
			default:
932
				chip->hp_stat_mask = MASK_HDPCONN;
L
Linus Torvalds 已提交
933 934 935 936 937 938 939 940 941 942 943 944 945 946
				break;
			}
			break;
		default:
			snd_BUG();
			break;
		}
	}

	/*
	 * build mixers
	 */
	strcpy(chip->card->mixername, "PowerMac AWACS");

947 948 949
	err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers),
				snd_pmac_awacs_mixers);
	if (err < 0)
L
Linus Torvalds 已提交
950
		return err;
951
	if (beige || g4agp)
952 953
		;
	else if (chip->model == PMAC_SCREAMER)
L
Linus Torvalds 已提交
954 955
		err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2),
				   snd_pmac_screamer_mixers2);
956
	else if (!pm7500)
L
Linus Torvalds 已提交
957 958 959 960
		err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2),
				   snd_pmac_awacs_mixers2);
	if (err < 0)
		return err;
961 962 963 964 965 966 967 968 969 970 971 972
	if (pm7500)
		err = build_mixers(chip,
				   ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500),
				   snd_pmac_awacs_mixers_pmac7500);
	else if (beige)
		err = build_mixers(chip,
				   ARRAY_SIZE(snd_pmac_screamer_mixers_beige),
				   snd_pmac_screamer_mixers_beige);
	else if (imac)
		err = build_mixers(chip,
				   ARRAY_SIZE(snd_pmac_screamer_mixers_imac),
				   snd_pmac_screamer_mixers_imac);
973 974 975 976
	else if (g4agp)
		err = build_mixers(chip,
				   ARRAY_SIZE(snd_pmac_screamer_mixers_g4agp),
				   snd_pmac_screamer_mixers_g4agp);
977 978 979 980 981 982
	else
		err = build_mixers(chip,
				   ARRAY_SIZE(snd_pmac_awacs_mixers_pmac),
				   snd_pmac_awacs_mixers_pmac);
	if (err < 0)
		return err;
983
	chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac || g4agp)
984 985
			? &snd_pmac_awacs_master_sw_imac
			: &snd_pmac_awacs_master_sw, chip);
986 987
	err = snd_ctl_add(chip->card, chip->master_sw_ctl);
	if (err < 0)
L
Linus Torvalds 已提交
988 989 990 991 992 993 994 995 996
		return err;
#ifdef PMAC_AMP_AVAIL
	if (chip->mixer_data) {
		/* use amplifier.  the signal is connected from route A
		 * to the amp.  the amp has its headphone and speaker
		 * volumes and mute switches, so we use them instead of
		 * screamer registers.
		 * in this case, it seems the route C is not used.
		 */
997 998 999
		err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol),
					snd_pmac_awacs_amp_vol);
		if (err < 0)
L
Linus Torvalds 已提交
1000 1001
			return err;
		/* overwrite */
1002 1003 1004 1005
		chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw,
							chip);
		err = snd_ctl_add(chip->card, chip->master_sw_ctl);
		if (err < 0)
L
Linus Torvalds 已提交
1006
			return err;
1007 1008 1009 1010
		chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw,
							chip);
		err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
		if (err < 0)
L
Linus Torvalds 已提交
1011 1012 1013 1014 1015
			return err;
	} else
#endif /* PMAC_AMP_AVAIL */
	{
		/* route A = headphone, route C = speaker */
1016 1017 1018
		err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol),
					snd_pmac_awacs_speaker_vol);
		if (err < 0)
L
Linus Torvalds 已提交
1019
			return err;
1020 1021 1022
		chip->speaker_sw_ctl = snd_ctl_new1(imac
				? &snd_pmac_awacs_speaker_sw_imac
				: &snd_pmac_awacs_speaker_sw, chip);
1023 1024
		err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
		if (err < 0)
L
Linus Torvalds 已提交
1025 1026 1027
			return err;
	}

1028
	if (beige || g4agp)
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
		err = build_mixers(chip,
				ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige),
				snd_pmac_screamer_mic_boost_beige);
	else if (imac)
		err = build_mixers(chip,
				ARRAY_SIZE(snd_pmac_screamer_mic_boost_imac),
				snd_pmac_screamer_mic_boost_imac);
	else if (chip->model == PMAC_SCREAMER)
		err = build_mixers(chip,
				ARRAY_SIZE(snd_pmac_screamer_mic_boost),
				snd_pmac_screamer_mic_boost);
	else if (pm7500)
		err = build_mixers(chip,
				ARRAY_SIZE(snd_pmac_awacs_mic_boost_pmac7500),
				snd_pmac_awacs_mic_boost_pmac7500);
	else
		err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost),
				snd_pmac_awacs_mic_boost);
	if (err < 0)
		return err;
L
Linus Torvalds 已提交
1049 1050 1051 1052 1053

	/*
	 * set lowlevel callbacks
	 */
	chip->set_format = snd_pmac_awacs_set_format;
1054
#ifdef CONFIG_PM
L
Linus Torvalds 已提交
1055 1056 1057 1058
	chip->suspend = snd_pmac_awacs_suspend;
	chip->resume = snd_pmac_awacs_resume;
#endif
#ifdef PMAC_SUPPORT_AUTOMUTE
1059 1060
	err = snd_pmac_add_automute(chip);
	if (err < 0)
L
Linus Torvalds 已提交
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
		return err;
	chip->detect_headphone = snd_pmac_awacs_detect_headphone;
	chip->update_automute = snd_pmac_awacs_update_automute;
	snd_pmac_awacs_update_automute(chip, 0); /* update the status only */
#endif
	if (chip->model == PMAC_SCREAMER) {
		snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
		snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
	}

	return 0;
}