0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/io.h>
0011 #include <asm/nvram.h>
0012 #include <linux/init.h>
0013 #include <linux/delay.h>
0014 #include <linux/slab.h>
0015 #include <sound/core.h>
0016 #include "pmac.h"
0017
0018
0019 #ifdef CONFIG_ADB_CUDA
0020 #define PMAC_AMP_AVAIL
0021 #endif
0022
0023 #ifdef PMAC_AMP_AVAIL
0024 struct awacs_amp {
0025 unsigned char amp_master;
0026 unsigned char amp_vol[2][2];
0027 unsigned char amp_tone[2];
0028 };
0029
0030 #define CHECK_CUDA_AMP() (sys_ctrler == SYS_CTRLER_CUDA)
0031
0032 #endif
0033
0034
0035 static void snd_pmac_screamer_wait(struct snd_pmac *chip)
0036 {
0037 long timeout = 2000;
0038 while (!(in_le32(&chip->awacs->codec_stat) & MASK_VALID)) {
0039 mdelay(1);
0040 if (! --timeout) {
0041 snd_printd("snd_pmac_screamer_wait timeout\n");
0042 break;
0043 }
0044 }
0045 }
0046
0047
0048
0049
0050 static void
0051 snd_pmac_awacs_write(struct snd_pmac *chip, int val)
0052 {
0053 long timeout = 5000000;
0054
0055 if (chip->model == PMAC_SCREAMER)
0056 snd_pmac_screamer_wait(chip);
0057 out_le32(&chip->awacs->codec_ctrl, val | (chip->subframe << 22));
0058 while (in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) {
0059 if (! --timeout) {
0060 snd_printd("snd_pmac_awacs_write timeout\n");
0061 break;
0062 }
0063 }
0064 }
0065
0066 static void
0067 snd_pmac_awacs_write_reg(struct snd_pmac *chip, int reg, int val)
0068 {
0069 snd_pmac_awacs_write(chip, val | (reg << 12));
0070 chip->awacs_reg[reg] = val;
0071 }
0072
0073 static void
0074 snd_pmac_awacs_write_noreg(struct snd_pmac *chip, int reg, int val)
0075 {
0076 snd_pmac_awacs_write(chip, val | (reg << 12));
0077 }
0078
0079 #ifdef CONFIG_PM
0080
0081 static void screamer_recalibrate(struct snd_pmac *chip)
0082 {
0083 if (chip->model != PMAC_SCREAMER)
0084 return;
0085
0086
0087
0088
0089 snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
0090 if (chip->manufacturer == 0x1)
0091
0092 msleep(750);
0093 snd_pmac_awacs_write_noreg(chip, 1,
0094 chip->awacs_reg[1] | MASK_RECALIBRATE |
0095 MASK_CMUTE | MASK_AMUTE);
0096 snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
0097 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
0098 }
0099
0100 #else
0101 #define screamer_recalibrate(chip)
0102 #endif
0103
0104
0105
0106
0107
0108 static void snd_pmac_awacs_set_format(struct snd_pmac *chip)
0109 {
0110 chip->awacs_reg[1] &= ~MASK_SAMPLERATE;
0111 chip->awacs_reg[1] |= chip->rate_index << 3;
0112 snd_pmac_awacs_write_reg(chip, 1, chip->awacs_reg[1]);
0113 }
0114
0115
0116
0117
0118
0119
0120
0121
0122 static int snd_pmac_awacs_info_volume(struct snd_kcontrol *kcontrol,
0123 struct snd_ctl_elem_info *uinfo)
0124 {
0125 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
0126 uinfo->count = 2;
0127 uinfo->value.integer.min = 0;
0128 uinfo->value.integer.max = 15;
0129 return 0;
0130 }
0131
0132 static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol,
0133 struct snd_ctl_elem_value *ucontrol)
0134 {
0135 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0136 int reg = kcontrol->private_value & 0xff;
0137 int lshift = (kcontrol->private_value >> 8) & 0xff;
0138 int inverted = (kcontrol->private_value >> 16) & 1;
0139 unsigned long flags;
0140 int vol[2];
0141
0142 spin_lock_irqsave(&chip->reg_lock, flags);
0143 vol[0] = (chip->awacs_reg[reg] >> lshift) & 0xf;
0144 vol[1] = chip->awacs_reg[reg] & 0xf;
0145 spin_unlock_irqrestore(&chip->reg_lock, flags);
0146 if (inverted) {
0147 vol[0] = 0x0f - vol[0];
0148 vol[1] = 0x0f - vol[1];
0149 }
0150 ucontrol->value.integer.value[0] = vol[0];
0151 ucontrol->value.integer.value[1] = vol[1];
0152 return 0;
0153 }
0154
0155 static int snd_pmac_awacs_put_volume(struct snd_kcontrol *kcontrol,
0156 struct snd_ctl_elem_value *ucontrol)
0157 {
0158 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0159 int reg = kcontrol->private_value & 0xff;
0160 int lshift = (kcontrol->private_value >> 8) & 0xff;
0161 int inverted = (kcontrol->private_value >> 16) & 1;
0162 int val, oldval;
0163 unsigned long flags;
0164 unsigned int vol[2];
0165
0166 vol[0] = ucontrol->value.integer.value[0];
0167 vol[1] = ucontrol->value.integer.value[1];
0168 if (vol[0] > 0x0f || vol[1] > 0x0f)
0169 return -EINVAL;
0170 if (inverted) {
0171 vol[0] = 0x0f - vol[0];
0172 vol[1] = 0x0f - vol[1];
0173 }
0174 vol[0] &= 0x0f;
0175 vol[1] &= 0x0f;
0176 spin_lock_irqsave(&chip->reg_lock, flags);
0177 oldval = chip->awacs_reg[reg];
0178 val = oldval & ~(0xf | (0xf << lshift));
0179 val |= vol[0] << lshift;
0180 val |= vol[1];
0181 if (oldval != val)
0182 snd_pmac_awacs_write_reg(chip, reg, val);
0183 spin_unlock_irqrestore(&chip->reg_lock, flags);
0184 return oldval != reg;
0185 }
0186
0187
0188 #define AWACS_VOLUME(xname, xreg, xshift, xinverted) \
0189 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
0190 .info = snd_pmac_awacs_info_volume, \
0191 .get = snd_pmac_awacs_get_volume, \
0192 .put = snd_pmac_awacs_put_volume, \
0193 .private_value = (xreg) | ((xshift) << 8) | ((xinverted) << 16) }
0194
0195
0196
0197
0198 static int snd_pmac_awacs_get_switch(struct snd_kcontrol *kcontrol,
0199 struct snd_ctl_elem_value *ucontrol)
0200 {
0201 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0202 int reg = kcontrol->private_value & 0xff;
0203 int shift = (kcontrol->private_value >> 8) & 0xff;
0204 int invert = (kcontrol->private_value >> 16) & 1;
0205 int val;
0206 unsigned long flags;
0207
0208 spin_lock_irqsave(&chip->reg_lock, flags);
0209 val = (chip->awacs_reg[reg] >> shift) & 1;
0210 spin_unlock_irqrestore(&chip->reg_lock, flags);
0211 if (invert)
0212 val = 1 - val;
0213 ucontrol->value.integer.value[0] = val;
0214 return 0;
0215 }
0216
0217 static int snd_pmac_awacs_put_switch(struct snd_kcontrol *kcontrol,
0218 struct snd_ctl_elem_value *ucontrol)
0219 {
0220 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0221 int reg = kcontrol->private_value & 0xff;
0222 int shift = (kcontrol->private_value >> 8) & 0xff;
0223 int invert = (kcontrol->private_value >> 16) & 1;
0224 int mask = 1 << shift;
0225 int val, changed;
0226 unsigned long flags;
0227
0228 spin_lock_irqsave(&chip->reg_lock, flags);
0229 val = chip->awacs_reg[reg] & ~mask;
0230 if (ucontrol->value.integer.value[0] != invert)
0231 val |= mask;
0232 changed = chip->awacs_reg[reg] != val;
0233 if (changed)
0234 snd_pmac_awacs_write_reg(chip, reg, val);
0235 spin_unlock_irqrestore(&chip->reg_lock, flags);
0236 return changed;
0237 }
0238
0239 #define AWACS_SWITCH(xname, xreg, xshift, xinvert) \
0240 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
0241 .info = snd_pmac_boolean_mono_info, \
0242 .get = snd_pmac_awacs_get_switch, \
0243 .put = snd_pmac_awacs_put_switch, \
0244 .private_value = (xreg) | ((xshift) << 8) | ((xinvert) << 16) }
0245
0246
0247 #ifdef PMAC_AMP_AVAIL
0248
0249
0250
0251
0252
0253
0254 static void awacs_set_cuda(int reg, int val)
0255 {
0256 struct adb_request req;
0257 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a,
0258 reg, val);
0259 while (! req.complete)
0260 cuda_poll();
0261 }
0262
0263
0264
0265
0266 static void awacs_amp_set_tone(struct awacs_amp *amp, int bass, int treble)
0267 {
0268 amp->amp_tone[0] = bass;
0269 amp->amp_tone[1] = treble;
0270 if (bass > 7)
0271 bass = (14 - bass) + 8;
0272 if (treble > 7)
0273 treble = (14 - treble) + 8;
0274 awacs_set_cuda(2, (bass << 4) | treble);
0275 }
0276
0277
0278
0279
0280 static int awacs_amp_set_vol(struct awacs_amp *amp, int index,
0281 int lvol, int rvol, int do_check)
0282 {
0283 if (do_check && amp->amp_vol[index][0] == lvol &&
0284 amp->amp_vol[index][1] == rvol)
0285 return 0;
0286 awacs_set_cuda(3 + index, lvol);
0287 awacs_set_cuda(5 + index, rvol);
0288 amp->amp_vol[index][0] = lvol;
0289 amp->amp_vol[index][1] = rvol;
0290 return 1;
0291 }
0292
0293
0294
0295
0296 static void awacs_amp_set_master(struct awacs_amp *amp, int vol)
0297 {
0298 amp->amp_master = vol;
0299 if (vol <= 79)
0300 vol = 32 + (79 - vol);
0301 else
0302 vol = 32 - (vol - 79);
0303 awacs_set_cuda(1, vol);
0304 }
0305
0306 static void awacs_amp_free(struct snd_pmac *chip)
0307 {
0308 struct awacs_amp *amp = chip->mixer_data;
0309 if (!amp)
0310 return;
0311 kfree(amp);
0312 chip->mixer_data = NULL;
0313 chip->mixer_free = NULL;
0314 }
0315
0316
0317
0318
0319
0320 static int snd_pmac_awacs_info_volume_amp(struct snd_kcontrol *kcontrol,
0321 struct snd_ctl_elem_info *uinfo)
0322 {
0323 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
0324 uinfo->count = 2;
0325 uinfo->value.integer.min = 0;
0326 uinfo->value.integer.max = 31;
0327 return 0;
0328 }
0329
0330 static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol,
0331 struct snd_ctl_elem_value *ucontrol)
0332 {
0333 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0334 int index = kcontrol->private_value;
0335 struct awacs_amp *amp = chip->mixer_data;
0336
0337 ucontrol->value.integer.value[0] = 31 - (amp->amp_vol[index][0] & 31);
0338 ucontrol->value.integer.value[1] = 31 - (amp->amp_vol[index][1] & 31);
0339 return 0;
0340 }
0341
0342 static int snd_pmac_awacs_put_volume_amp(struct snd_kcontrol *kcontrol,
0343 struct snd_ctl_elem_value *ucontrol)
0344 {
0345 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0346 int index = kcontrol->private_value;
0347 int vol[2];
0348 struct awacs_amp *amp = chip->mixer_data;
0349
0350 vol[0] = (31 - (ucontrol->value.integer.value[0] & 31))
0351 | (amp->amp_vol[index][0] & 32);
0352 vol[1] = (31 - (ucontrol->value.integer.value[1] & 31))
0353 | (amp->amp_vol[index][1] & 32);
0354 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
0355 }
0356
0357 static int snd_pmac_awacs_get_switch_amp(struct snd_kcontrol *kcontrol,
0358 struct snd_ctl_elem_value *ucontrol)
0359 {
0360 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0361 int index = kcontrol->private_value;
0362 struct awacs_amp *amp = chip->mixer_data;
0363
0364 ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32)
0365 ? 0 : 1;
0366 ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32)
0367 ? 0 : 1;
0368 return 0;
0369 }
0370
0371 static int snd_pmac_awacs_put_switch_amp(struct snd_kcontrol *kcontrol,
0372 struct snd_ctl_elem_value *ucontrol)
0373 {
0374 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0375 int index = kcontrol->private_value;
0376 int vol[2];
0377 struct awacs_amp *amp = chip->mixer_data;
0378
0379 vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32)
0380 | (amp->amp_vol[index][0] & 31);
0381 vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32)
0382 | (amp->amp_vol[index][1] & 31);
0383 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
0384 }
0385
0386 static int snd_pmac_awacs_info_tone_amp(struct snd_kcontrol *kcontrol,
0387 struct snd_ctl_elem_info *uinfo)
0388 {
0389 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
0390 uinfo->count = 1;
0391 uinfo->value.integer.min = 0;
0392 uinfo->value.integer.max = 14;
0393 return 0;
0394 }
0395
0396 static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol,
0397 struct snd_ctl_elem_value *ucontrol)
0398 {
0399 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0400 int index = kcontrol->private_value;
0401 struct awacs_amp *amp = chip->mixer_data;
0402
0403 ucontrol->value.integer.value[0] = amp->amp_tone[index];
0404 return 0;
0405 }
0406
0407 static int snd_pmac_awacs_put_tone_amp(struct snd_kcontrol *kcontrol,
0408 struct snd_ctl_elem_value *ucontrol)
0409 {
0410 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0411 int index = kcontrol->private_value;
0412 struct awacs_amp *amp = chip->mixer_data;
0413 unsigned int val;
0414
0415 val = ucontrol->value.integer.value[0];
0416 if (val > 14)
0417 return -EINVAL;
0418 if (val != amp->amp_tone[index]) {
0419 amp->amp_tone[index] = val;
0420 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
0421 return 1;
0422 }
0423 return 0;
0424 }
0425
0426 static int snd_pmac_awacs_info_master_amp(struct snd_kcontrol *kcontrol,
0427 struct snd_ctl_elem_info *uinfo)
0428 {
0429 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
0430 uinfo->count = 1;
0431 uinfo->value.integer.min = 0;
0432 uinfo->value.integer.max = 99;
0433 return 0;
0434 }
0435
0436 static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol,
0437 struct snd_ctl_elem_value *ucontrol)
0438 {
0439 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0440 struct awacs_amp *amp = chip->mixer_data;
0441
0442 ucontrol->value.integer.value[0] = amp->amp_master;
0443 return 0;
0444 }
0445
0446 static int snd_pmac_awacs_put_master_amp(struct snd_kcontrol *kcontrol,
0447 struct snd_ctl_elem_value *ucontrol)
0448 {
0449 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0450 struct awacs_amp *amp = chip->mixer_data;
0451 unsigned int val;
0452
0453 val = ucontrol->value.integer.value[0];
0454 if (val > 99)
0455 return -EINVAL;
0456 if (val != amp->amp_master) {
0457 amp->amp_master = val;
0458 awacs_amp_set_master(amp, amp->amp_master);
0459 return 1;
0460 }
0461 return 0;
0462 }
0463
0464 #define AMP_CH_SPK 0
0465 #define AMP_CH_HD 1
0466
0467 static const struct snd_kcontrol_new snd_pmac_awacs_amp_vol[] = {
0468 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0469 .name = "Speaker Playback Volume",
0470 .info = snd_pmac_awacs_info_volume_amp,
0471 .get = snd_pmac_awacs_get_volume_amp,
0472 .put = snd_pmac_awacs_put_volume_amp,
0473 .private_value = AMP_CH_SPK,
0474 },
0475 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0476 .name = "Headphone Playback Volume",
0477 .info = snd_pmac_awacs_info_volume_amp,
0478 .get = snd_pmac_awacs_get_volume_amp,
0479 .put = snd_pmac_awacs_put_volume_amp,
0480 .private_value = AMP_CH_HD,
0481 },
0482 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0483 .name = "Tone Control - Bass",
0484 .info = snd_pmac_awacs_info_tone_amp,
0485 .get = snd_pmac_awacs_get_tone_amp,
0486 .put = snd_pmac_awacs_put_tone_amp,
0487 .private_value = 0,
0488 },
0489 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0490 .name = "Tone Control - Treble",
0491 .info = snd_pmac_awacs_info_tone_amp,
0492 .get = snd_pmac_awacs_get_tone_amp,
0493 .put = snd_pmac_awacs_put_tone_amp,
0494 .private_value = 1,
0495 },
0496 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0497 .name = "Amp Master Playback Volume",
0498 .info = snd_pmac_awacs_info_master_amp,
0499 .get = snd_pmac_awacs_get_master_amp,
0500 .put = snd_pmac_awacs_put_master_amp,
0501 },
0502 };
0503
0504 static const struct snd_kcontrol_new snd_pmac_awacs_amp_hp_sw = {
0505 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0506 .name = "Headphone Playback Switch",
0507 .info = snd_pmac_boolean_stereo_info,
0508 .get = snd_pmac_awacs_get_switch_amp,
0509 .put = snd_pmac_awacs_put_switch_amp,
0510 .private_value = AMP_CH_HD,
0511 };
0512
0513 static const struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw = {
0514 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0515 .name = "Speaker Playback Switch",
0516 .info = snd_pmac_boolean_stereo_info,
0517 .get = snd_pmac_awacs_get_switch_amp,
0518 .put = snd_pmac_awacs_put_switch_amp,
0519 .private_value = AMP_CH_SPK,
0520 };
0521
0522 #endif
0523
0524
0525
0526
0527
0528 static int snd_pmac_screamer_mic_boost_info(struct snd_kcontrol *kcontrol,
0529 struct snd_ctl_elem_info *uinfo)
0530 {
0531 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
0532 uinfo->count = 1;
0533 uinfo->value.integer.min = 0;
0534 uinfo->value.integer.max = 3;
0535 return 0;
0536 }
0537
0538 static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol *kcontrol,
0539 struct snd_ctl_elem_value *ucontrol)
0540 {
0541 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0542 int val = 0;
0543 unsigned long flags;
0544
0545 spin_lock_irqsave(&chip->reg_lock, flags);
0546 if (chip->awacs_reg[6] & MASK_MIC_BOOST)
0547 val |= 2;
0548 if (chip->awacs_reg[0] & MASK_GAINLINE)
0549 val |= 1;
0550 spin_unlock_irqrestore(&chip->reg_lock, flags);
0551 ucontrol->value.integer.value[0] = val;
0552 return 0;
0553 }
0554
0555 static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
0556 struct snd_ctl_elem_value *ucontrol)
0557 {
0558 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
0559 int changed = 0;
0560 int val0, val6;
0561 unsigned long flags;
0562
0563 spin_lock_irqsave(&chip->reg_lock, flags);
0564 val0 = chip->awacs_reg[0] & ~MASK_GAINLINE;
0565 val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST;
0566 if (ucontrol->value.integer.value[0] & 1)
0567 val0 |= MASK_GAINLINE;
0568 if (ucontrol->value.integer.value[0] & 2)
0569 val6 |= MASK_MIC_BOOST;
0570 if (val0 != chip->awacs_reg[0]) {
0571 snd_pmac_awacs_write_reg(chip, 0, val0);
0572 changed = 1;
0573 }
0574 if (val6 != chip->awacs_reg[6]) {
0575 snd_pmac_awacs_write_reg(chip, 6, val6);
0576 changed = 1;
0577 }
0578 spin_unlock_irqrestore(&chip->reg_lock, flags);
0579 return changed;
0580 }
0581
0582
0583
0584
0585 static const struct snd_kcontrol_new snd_pmac_awacs_mixers[] = {
0586 AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0),
0587 AWACS_VOLUME("Master Capture Volume", 0, 4, 0),
0588
0589 };
0590
0591 static const struct snd_kcontrol_new snd_pmac_screamer_mixers_beige[] = {
0592 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
0593 AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1),
0594 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
0595 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_LINE, 0),
0596 };
0597
0598 static const struct snd_kcontrol_new snd_pmac_screamer_mixers_lo[] = {
0599 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
0600 };
0601
0602 static const struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] = {
0603 AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1),
0604 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
0605 };
0606
0607 static const struct snd_kcontrol_new snd_pmac_screamer_mixers_g4agp[] = {
0608 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
0609 AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
0610 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
0611 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
0612 };
0613
0614 static const struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] = {
0615 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
0616 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
0617 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
0618 };
0619
0620 static const struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac5500[] = {
0621 AWACS_VOLUME("Headphone Playback Volume", 2, 6, 1),
0622 };
0623
0624 static const struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] = {
0625 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
0626 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
0627 };
0628
0629
0630
0631
0632 static const struct snd_kcontrol_new snd_pmac_awacs_mixers2[] = {
0633 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_LINE, 0),
0634 AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_MIC, 0),
0635 };
0636
0637 static const struct snd_kcontrol_new snd_pmac_screamer_mixers2[] = {
0638 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
0639 AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_LINE, 0),
0640 };
0641
0642 static const struct snd_kcontrol_new snd_pmac_awacs_mixers2_pmac5500[] = {
0643 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
0644 };
0645
0646 static const struct snd_kcontrol_new snd_pmac_awacs_master_sw =
0647 AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1);
0648
0649 static const struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac =
0650 AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1);
0651
0652 static const struct snd_kcontrol_new snd_pmac_awacs_master_sw_pmac5500 =
0653 AWACS_SWITCH("Headphone Playback Switch", 1, SHIFT_HDMUTE, 1);
0654
0655 static const struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] = {
0656 AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
0657 };
0658
0659 static const struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] = {
0660 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0661 .name = "Mic Boost Capture Volume",
0662 .info = snd_pmac_screamer_mic_boost_info,
0663 .get = snd_pmac_screamer_mic_boost_get,
0664 .put = snd_pmac_screamer_mic_boost_put,
0665 },
0666 };
0667
0668 static const struct snd_kcontrol_new snd_pmac_awacs_mic_boost_pmac7500[] =
0669 {
0670 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
0671 };
0672
0673 static const struct snd_kcontrol_new snd_pmac_screamer_mic_boost_beige[] =
0674 {
0675 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
0676 AWACS_SWITCH("CD Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
0677 };
0678
0679 static const struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] =
0680 {
0681 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
0682 AWACS_SWITCH("Mic Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
0683 };
0684
0685 static const struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] = {
0686 AWACS_VOLUME("Speaker Playback Volume", 4, 6, 1),
0687 };
0688
0689 static const struct snd_kcontrol_new snd_pmac_awacs_speaker_sw =
0690 AWACS_SWITCH("Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);
0691
0692 static const struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac1 =
0693 AWACS_SWITCH("Speaker Playback Switch", 1, SHIFT_PAROUT1, 1);
0694
0695 static const struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac2 =
0696 AWACS_SWITCH("Speaker Playback Switch", 1, SHIFT_PAROUT1, 0);
0697
0698
0699
0700
0701
0702 static int build_mixers(struct snd_pmac *chip, int nums,
0703 const struct snd_kcontrol_new *mixers)
0704 {
0705 int i, err;
0706
0707 for (i = 0; i < nums; i++) {
0708 err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip));
0709 if (err < 0)
0710 return err;
0711 }
0712 return 0;
0713 }
0714
0715
0716
0717
0718
0719 static void awacs_restore_all_regs(struct snd_pmac *chip)
0720 {
0721 snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
0722 snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]);
0723 snd_pmac_awacs_write_noreg(chip, 2, chip->awacs_reg[2]);
0724 snd_pmac_awacs_write_noreg(chip, 4, chip->awacs_reg[4]);
0725 if (chip->model == PMAC_SCREAMER) {
0726 snd_pmac_awacs_write_noreg(chip, 5, chip->awacs_reg[5]);
0727 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
0728 snd_pmac_awacs_write_noreg(chip, 7, chip->awacs_reg[7]);
0729 }
0730 }
0731
0732 #ifdef CONFIG_PM
0733 static void snd_pmac_awacs_suspend(struct snd_pmac *chip)
0734 {
0735 snd_pmac_awacs_write_noreg(chip, 1, (chip->awacs_reg[1]
0736 | MASK_AMUTE | MASK_CMUTE));
0737 }
0738
0739 static void snd_pmac_awacs_resume(struct snd_pmac *chip)
0740 {
0741 if (of_machine_is_compatible("PowerBook3,1")
0742 || of_machine_is_compatible("PowerBook3,2")) {
0743 msleep(100);
0744 snd_pmac_awacs_write_reg(chip, 1,
0745 chip->awacs_reg[1] & ~MASK_PAROUT);
0746 msleep(300);
0747 }
0748
0749 awacs_restore_all_regs(chip);
0750 if (chip->model == PMAC_SCREAMER) {
0751
0752 mdelay(5);
0753 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
0754 }
0755 screamer_recalibrate(chip);
0756 #ifdef PMAC_AMP_AVAIL
0757 if (chip->mixer_data) {
0758 struct awacs_amp *amp = chip->mixer_data;
0759 awacs_amp_set_vol(amp, 0,
0760 amp->amp_vol[0][0], amp->amp_vol[0][1], 0);
0761 awacs_amp_set_vol(amp, 1,
0762 amp->amp_vol[1][0], amp->amp_vol[1][1], 0);
0763 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
0764 awacs_amp_set_master(amp, amp->amp_master);
0765 }
0766 #endif
0767 }
0768 #endif
0769
0770 #define IS_PM7500 (of_machine_is_compatible("AAPL,7500") \
0771 || of_machine_is_compatible("AAPL,8500") \
0772 || of_machine_is_compatible("AAPL,9500"))
0773 #define IS_PM5500 (of_machine_is_compatible("AAPL,e411"))
0774 #define IS_BEIGE (of_machine_is_compatible("AAPL,Gossamer"))
0775 #define IS_IMAC1 (of_machine_is_compatible("PowerMac2,1"))
0776 #define IS_IMAC2 (of_machine_is_compatible("PowerMac2,2") \
0777 || of_machine_is_compatible("PowerMac4,1"))
0778 #define IS_G4AGP (of_machine_is_compatible("PowerMac3,1"))
0779 #define IS_LOMBARD (of_machine_is_compatible("PowerBook1,1"))
0780
0781 static int imac1, imac2;
0782
0783 #ifdef PMAC_SUPPORT_AUTOMUTE
0784
0785
0786
0787 static int snd_pmac_awacs_detect_headphone(struct snd_pmac *chip)
0788 {
0789 return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0;
0790 }
0791
0792 #ifdef PMAC_AMP_AVAIL
0793 static int toggle_amp_mute(struct awacs_amp *amp, int index, int mute)
0794 {
0795 int vol[2];
0796 vol[0] = amp->amp_vol[index][0] & 31;
0797 vol[1] = amp->amp_vol[index][1] & 31;
0798 if (mute) {
0799 vol[0] |= 32;
0800 vol[1] |= 32;
0801 }
0802 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
0803 }
0804 #endif
0805
0806 static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
0807 {
0808 if (chip->auto_mute) {
0809 #ifdef PMAC_AMP_AVAIL
0810 if (chip->mixer_data) {
0811 struct awacs_amp *amp = chip->mixer_data;
0812 int changed;
0813 if (snd_pmac_awacs_detect_headphone(chip)) {
0814 changed = toggle_amp_mute(amp, AMP_CH_HD, 0);
0815 changed |= toggle_amp_mute(amp, AMP_CH_SPK, 1);
0816 } else {
0817 changed = toggle_amp_mute(amp, AMP_CH_HD, 1);
0818 changed |= toggle_amp_mute(amp, AMP_CH_SPK, 0);
0819 }
0820 if (do_notify && ! changed)
0821 return;
0822 } else
0823 #endif
0824 {
0825 int reg = chip->awacs_reg[1]
0826 | (MASK_HDMUTE | MASK_SPKMUTE);
0827 if (imac1) {
0828 reg &= ~MASK_SPKMUTE;
0829 reg |= MASK_PAROUT1;
0830 } else if (imac2) {
0831 reg &= ~MASK_SPKMUTE;
0832 reg &= ~MASK_PAROUT1;
0833 }
0834 if (snd_pmac_awacs_detect_headphone(chip))
0835 reg &= ~MASK_HDMUTE;
0836 else if (imac1)
0837 reg &= ~MASK_PAROUT1;
0838 else if (imac2)
0839 reg |= MASK_PAROUT1;
0840 else
0841 reg &= ~MASK_SPKMUTE;
0842 if (do_notify && reg == chip->awacs_reg[1])
0843 return;
0844 snd_pmac_awacs_write_reg(chip, 1, reg);
0845 }
0846 if (do_notify) {
0847 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
0848 &chip->master_sw_ctl->id);
0849 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
0850 &chip->speaker_sw_ctl->id);
0851 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
0852 &chip->hp_detect_ctl->id);
0853 }
0854 }
0855 }
0856 #endif
0857
0858
0859
0860
0861
0862 int
0863 snd_pmac_awacs_init(struct snd_pmac *chip)
0864 {
0865 int pm7500 = IS_PM7500;
0866 int pm5500 = IS_PM5500;
0867 int beige = IS_BEIGE;
0868 int g4agp = IS_G4AGP;
0869 int lombard = IS_LOMBARD;
0870 int imac;
0871 int err, vol;
0872 struct snd_kcontrol *vmaster_sw, *vmaster_vol;
0873 struct snd_kcontrol *master_vol, *speaker_vol;
0874
0875 imac1 = IS_IMAC1;
0876 imac2 = IS_IMAC2;
0877 imac = imac1 || imac2;
0878
0879
0880
0881 chip->awacs_reg[0] = MASK_MUX_CD | 0xff | MASK_GAINLINE;
0882 chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE;
0883
0884 if (chip->has_iic || chip->device_id == 0x5 ||
0885
0886 chip->device_id == 0xb)
0887 chip->awacs_reg[1] |= MASK_PAROUT;
0888
0889
0890
0891 vol = 0x0f;
0892 vol = vol + (vol << 6);
0893 chip->awacs_reg[2] = vol;
0894 chip->awacs_reg[4] = vol;
0895 if (chip->model == PMAC_SCREAMER) {
0896
0897 chip->awacs_reg[5] = vol;
0898
0899 chip->awacs_reg[6] = MASK_MIC_BOOST;
0900 chip->awacs_reg[7] = 0;
0901 }
0902
0903 awacs_restore_all_regs(chip);
0904 chip->manufacturer = (in_le32(&chip->awacs->codec_stat) >> 8) & 0xf;
0905 screamer_recalibrate(chip);
0906
0907 chip->revision = (in_le32(&chip->awacs->codec_stat) >> 12) & 0xf;
0908 #ifdef PMAC_AMP_AVAIL
0909 if (chip->revision == 3 && chip->has_iic && CHECK_CUDA_AMP()) {
0910 struct awacs_amp *amp = kzalloc(sizeof(*amp), GFP_KERNEL);
0911 if (! amp)
0912 return -ENOMEM;
0913 chip->mixer_data = amp;
0914 chip->mixer_free = awacs_amp_free;
0915
0916 awacs_amp_set_vol(amp, 0, 63, 63, 0);
0917 awacs_amp_set_vol(amp, 1, 63, 63, 0);
0918 awacs_amp_set_tone(amp, 7, 7);
0919 awacs_amp_set_master(amp, 79);
0920 }
0921 #endif
0922
0923 if (chip->hp_stat_mask == 0) {
0924
0925 switch (chip->model) {
0926 case PMAC_AWACS:
0927 chip->hp_stat_mask = pm7500 || pm5500 ? MASK_HDPCONN
0928 : MASK_LOCONN;
0929 break;
0930 case PMAC_SCREAMER:
0931 switch (chip->device_id) {
0932 case 0x08:
0933 case 0x0B:
0934 chip->hp_stat_mask = imac
0935 ? MASK_LOCONN_IMAC |
0936 MASK_HDPLCONN_IMAC |
0937 MASK_HDPRCONN_IMAC
0938 : MASK_HDPCONN;
0939 break;
0940 case 0x00:
0941 case 0x05:
0942 chip->hp_stat_mask = MASK_LOCONN;
0943 break;
0944 default:
0945 chip->hp_stat_mask = MASK_HDPCONN;
0946 break;
0947 }
0948 break;
0949 default:
0950 snd_BUG();
0951 break;
0952 }
0953 }
0954
0955
0956
0957
0958 strcpy(chip->card->mixername, "PowerMac AWACS");
0959
0960 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers),
0961 snd_pmac_awacs_mixers);
0962 if (err < 0)
0963 return err;
0964 if (beige || g4agp)
0965 ;
0966 else if (chip->model == PMAC_SCREAMER || pm5500)
0967 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2),
0968 snd_pmac_screamer_mixers2);
0969 else if (!pm7500)
0970 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2),
0971 snd_pmac_awacs_mixers2);
0972 if (err < 0)
0973 return err;
0974 if (pm5500) {
0975 err = build_mixers(chip,
0976 ARRAY_SIZE(snd_pmac_awacs_mixers2_pmac5500),
0977 snd_pmac_awacs_mixers2_pmac5500);
0978 if (err < 0)
0979 return err;
0980 }
0981 master_vol = NULL;
0982 if (pm7500)
0983 err = build_mixers(chip,
0984 ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500),
0985 snd_pmac_awacs_mixers_pmac7500);
0986 else if (pm5500)
0987 err = snd_ctl_add(chip->card,
0988 (master_vol = snd_ctl_new1(snd_pmac_awacs_mixers_pmac5500,
0989 chip)));
0990 else if (beige)
0991 err = build_mixers(chip,
0992 ARRAY_SIZE(snd_pmac_screamer_mixers_beige),
0993 snd_pmac_screamer_mixers_beige);
0994 else if (imac || lombard) {
0995 err = snd_ctl_add(chip->card,
0996 (master_vol = snd_ctl_new1(snd_pmac_screamer_mixers_lo,
0997 chip)));
0998 if (err < 0)
0999 return err;
1000 err = build_mixers(chip,
1001 ARRAY_SIZE(snd_pmac_screamer_mixers_imac),
1002 snd_pmac_screamer_mixers_imac);
1003 } else if (g4agp)
1004 err = build_mixers(chip,
1005 ARRAY_SIZE(snd_pmac_screamer_mixers_g4agp),
1006 snd_pmac_screamer_mixers_g4agp);
1007 else
1008 err = build_mixers(chip,
1009 ARRAY_SIZE(snd_pmac_awacs_mixers_pmac),
1010 snd_pmac_awacs_mixers_pmac);
1011 if (err < 0)
1012 return err;
1013 chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac || g4agp || lombard)
1014 ? &snd_pmac_awacs_master_sw_imac
1015 : pm5500
1016 ? &snd_pmac_awacs_master_sw_pmac5500
1017 : &snd_pmac_awacs_master_sw, chip);
1018 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
1019 if (err < 0)
1020 return err;
1021 #ifdef PMAC_AMP_AVAIL
1022 if (chip->mixer_data) {
1023
1024
1025
1026
1027
1028
1029 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol),
1030 snd_pmac_awacs_amp_vol);
1031 if (err < 0)
1032 return err;
1033
1034 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw,
1035 chip);
1036 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
1037 if (err < 0)
1038 return err;
1039 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw,
1040 chip);
1041 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
1042 if (err < 0)
1043 return err;
1044 } else
1045 #endif
1046 {
1047
1048 err = snd_ctl_add(chip->card,
1049 (speaker_vol = snd_ctl_new1(snd_pmac_awacs_speaker_vol,
1050 chip)));
1051 if (err < 0)
1052 return err;
1053 chip->speaker_sw_ctl = snd_ctl_new1(imac1
1054 ? &snd_pmac_awacs_speaker_sw_imac1
1055 : imac2
1056 ? &snd_pmac_awacs_speaker_sw_imac2
1057 : &snd_pmac_awacs_speaker_sw, chip);
1058 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
1059 if (err < 0)
1060 return err;
1061 }
1062
1063 if (pm5500 || imac || lombard) {
1064 vmaster_sw = snd_ctl_make_virtual_master(
1065 "Master Playback Switch", (unsigned int *) NULL);
1066 err = snd_ctl_add_follower_uncached(vmaster_sw,
1067 chip->master_sw_ctl);
1068 if (err < 0)
1069 return err;
1070 err = snd_ctl_add_follower_uncached(vmaster_sw,
1071 chip->speaker_sw_ctl);
1072 if (err < 0)
1073 return err;
1074 err = snd_ctl_add(chip->card, vmaster_sw);
1075 if (err < 0)
1076 return err;
1077 vmaster_vol = snd_ctl_make_virtual_master(
1078 "Master Playback Volume", (unsigned int *) NULL);
1079 err = snd_ctl_add_follower(vmaster_vol, master_vol);
1080 if (err < 0)
1081 return err;
1082 err = snd_ctl_add_follower(vmaster_vol, speaker_vol);
1083 if (err < 0)
1084 return err;
1085 err = snd_ctl_add(chip->card, vmaster_vol);
1086 if (err < 0)
1087 return err;
1088 }
1089
1090 if (beige || g4agp)
1091 err = build_mixers(chip,
1092 ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige),
1093 snd_pmac_screamer_mic_boost_beige);
1094 else if (imac)
1095 err = build_mixers(chip,
1096 ARRAY_SIZE(snd_pmac_screamer_mic_boost_imac),
1097 snd_pmac_screamer_mic_boost_imac);
1098 else if (chip->model == PMAC_SCREAMER)
1099 err = build_mixers(chip,
1100 ARRAY_SIZE(snd_pmac_screamer_mic_boost),
1101 snd_pmac_screamer_mic_boost);
1102 else if (pm7500)
1103 err = build_mixers(chip,
1104 ARRAY_SIZE(snd_pmac_awacs_mic_boost_pmac7500),
1105 snd_pmac_awacs_mic_boost_pmac7500);
1106 else
1107 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost),
1108 snd_pmac_awacs_mic_boost);
1109 if (err < 0)
1110 return err;
1111
1112
1113
1114
1115 chip->set_format = snd_pmac_awacs_set_format;
1116 #ifdef CONFIG_PM
1117 chip->suspend = snd_pmac_awacs_suspend;
1118 chip->resume = snd_pmac_awacs_resume;
1119 #endif
1120 #ifdef PMAC_SUPPORT_AUTOMUTE
1121 err = snd_pmac_add_automute(chip);
1122 if (err < 0)
1123 return err;
1124 chip->detect_headphone = snd_pmac_awacs_detect_headphone;
1125 chip->update_automute = snd_pmac_awacs_update_automute;
1126 snd_pmac_awacs_update_automute(chip, 0);
1127 #endif
1128 if (chip->model == PMAC_SCREAMER) {
1129 snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]);
1130 snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]);
1131 }
1132
1133 return 0;
1134 }