24 #include <asm/nvram.h>
27 #include <linux/slab.h>
32 #ifdef CONFIG_ADB_CUDA
33 #define PMAC_AMP_AVAIL
38 unsigned char amp_master;
39 unsigned char amp_vol[2][2];
40 unsigned char amp_tone[2];
43 #define CHECK_CUDA_AMP() (sys_ctrler == SYS_CTRLER_CUDA)
48 static void snd_pmac_screamer_wait(
struct snd_pmac *
chip)
54 snd_printd(
"snd_pmac_screamer_wait timeout\n");
64 snd_pmac_awacs_write(
struct snd_pmac *chip,
int val)
66 long timeout = 5000000;
69 snd_pmac_screamer_wait(chip);
80 snd_pmac_awacs_write_reg(
struct snd_pmac *chip,
int reg,
int val)
82 snd_pmac_awacs_write(chip, val | (reg << 12));
87 snd_pmac_awacs_write_noreg(
struct snd_pmac *chip,
int reg,
int val)
89 snd_pmac_awacs_write(chip, val | (reg << 12));
102 snd_pmac_awacs_write_noreg(chip, 1, chip->
awacs_reg[1]);
106 snd_pmac_awacs_write_noreg(chip, 1,
109 snd_pmac_awacs_write_noreg(chip, 1, chip->
awacs_reg[1]);
110 snd_pmac_awacs_write_noreg(chip, 6, chip->
awacs_reg[6]);
114 #define screamer_recalibrate(chip)
121 static void snd_pmac_awacs_set_format(
struct snd_pmac *chip)
125 snd_pmac_awacs_write_reg(chip, 1, chip->
awacs_reg[1]);
135 static int snd_pmac_awacs_info_volume(
struct snd_kcontrol *kcontrol,
145 static int snd_pmac_awacs_get_volume(
struct snd_kcontrol *kcontrol,
158 spin_unlock_irqrestore(&chip->
reg_lock, flags);
160 vol[0] = 0x0f - vol[0];
161 vol[1] = 0x0f - vol[1];
163 ucontrol->
value.integer.value[0] = vol[0];
164 ucontrol->
value.integer.value[1] = vol[1];
168 static int snd_pmac_awacs_put_volume(
struct snd_kcontrol *kcontrol,
179 vol[0] = ucontrol->
value.integer.value[0];
180 vol[1] = ucontrol->
value.integer.value[1];
181 if (vol[0] > 0x0f || vol[1] > 0x0f)
184 vol[0] = 0x0f - vol[0];
185 vol[1] = 0x0f - vol[1];
191 val = oldval & ~(0xf | (0xf << lshift));
192 val |= vol[0] << lshift;
195 snd_pmac_awacs_write_reg(chip, reg, val);
196 spin_unlock_irqrestore(&chip->
reg_lock, flags);
197 return oldval !=
reg;
201 #define AWACS_VOLUME(xname, xreg, xshift, xinverted) \
202 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
203 .info = snd_pmac_awacs_info_volume, \
204 .get = snd_pmac_awacs_get_volume, \
205 .put = snd_pmac_awacs_put_volume, \
206 .private_value = (xreg) | ((xshift) << 8) | ((xinverted) << 16) }
211 static int snd_pmac_awacs_get_switch(
struct snd_kcontrol *kcontrol,
223 spin_unlock_irqrestore(&chip->
reg_lock, flags);
226 ucontrol->
value.integer.value[0] =
val;
230 static int snd_pmac_awacs_put_switch(
struct snd_kcontrol *kcontrol,
237 int mask = 1 << shift;
243 if (ucontrol->
value.integer.value[0] != invert)
247 snd_pmac_awacs_write_reg(chip, reg, val);
248 spin_unlock_irqrestore(&chip->
reg_lock, flags);
252 #define AWACS_SWITCH(xname, xreg, xshift, xinvert) \
253 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
254 .info = snd_pmac_boolean_mono_info, \
255 .get = snd_pmac_awacs_get_switch, \
256 .put = snd_pmac_awacs_put_switch, \
257 .private_value = (xreg) | ((xshift) << 8) | ((xinvert) << 16) }
260 #ifdef PMAC_AMP_AVAIL
267 static void awacs_set_cuda(
int reg,
int val)
279 static void awacs_amp_set_tone(
struct awacs_amp *amp,
int bass,
int treble)
281 amp->amp_tone[0] = bass;
282 amp->amp_tone[1] = treble;
284 bass = (14 - bass) + 8;
286 treble = (14 - treble) + 8;
287 awacs_set_cuda(2, (bass << 4) | treble);
293 static int awacs_amp_set_vol(
struct awacs_amp *amp,
int index,
294 int lvol,
int rvol,
int do_check)
296 if (do_check && amp->amp_vol[index][0] == lvol &&
297 amp->amp_vol[index][1] == rvol)
299 awacs_set_cuda(3 + index, lvol);
300 awacs_set_cuda(5 + index, rvol);
301 amp->amp_vol[
index][0] = lvol;
302 amp->amp_vol[
index][1] = rvol;
309 static void awacs_amp_set_master(
struct awacs_amp *amp,
int vol)
311 amp->amp_master =
vol;
313 vol = 32 + (79 -
vol);
315 vol = 32 - (vol - 79);
316 awacs_set_cuda(1, vol);
319 static void awacs_amp_free(
struct snd_pmac *chip)
333 static int snd_pmac_awacs_info_volume_amp(
struct snd_kcontrol *kcontrol,
343 static int snd_pmac_awacs_get_volume_amp(
struct snd_kcontrol *kcontrol,
350 ucontrol->
value.integer.value[0] = 31 - (amp->amp_vol[
index][0] & 31);
351 ucontrol->
value.integer.value[1] = 31 - (amp->amp_vol[
index][1] & 31);
355 static int snd_pmac_awacs_put_volume_amp(
struct snd_kcontrol *kcontrol,
363 vol[0] = (31 - (ucontrol->
value.integer.value[0] & 31))
364 | (amp->amp_vol[
index][0] & 32);
365 vol[1] = (31 - (ucontrol->
value.integer.value[1] & 31))
366 | (amp->amp_vol[
index][1] & 32);
367 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
370 static int snd_pmac_awacs_get_switch_amp(
struct snd_kcontrol *kcontrol,
377 ucontrol->
value.integer.value[0] = (amp->amp_vol[
index][0] & 32)
379 ucontrol->
value.integer.value[1] = (amp->amp_vol[
index][1] & 32)
384 static int snd_pmac_awacs_put_switch_amp(
struct snd_kcontrol *kcontrol,
392 vol[0] = (ucontrol->
value.integer.value[0] ? 0 : 32)
393 | (amp->amp_vol[index][0] & 31);
394 vol[1] = (ucontrol->
value.integer.value[1] ? 0 : 32)
395 | (amp->amp_vol[index][1] & 31);
396 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
399 static int snd_pmac_awacs_info_tone_amp(
struct snd_kcontrol *kcontrol,
409 static int snd_pmac_awacs_get_tone_amp(
struct snd_kcontrol *kcontrol,
416 ucontrol->
value.integer.value[0] = amp->amp_tone[
index];
420 static int snd_pmac_awacs_put_tone_amp(
struct snd_kcontrol *kcontrol,
428 val = ucontrol->
value.integer.value[0];
431 if (val != amp->amp_tone[index]) {
433 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
439 static int snd_pmac_awacs_info_master_amp(
struct snd_kcontrol *kcontrol,
449 static int snd_pmac_awacs_get_master_amp(
struct snd_kcontrol *kcontrol,
455 ucontrol->
value.integer.value[0] = amp->amp_master;
459 static int snd_pmac_awacs_put_master_amp(
struct snd_kcontrol *kcontrol,
466 val = ucontrol->
value.integer.value[0];
469 if (val != amp->amp_master) {
470 amp->amp_master =
val;
471 awacs_amp_set_master(amp, amp->amp_master);
482 .name =
"Speaker Playback Volume",
483 .info = snd_pmac_awacs_info_volume_amp,
484 .get = snd_pmac_awacs_get_volume_amp,
485 .put = snd_pmac_awacs_put_volume_amp,
486 .private_value = AMP_CH_SPK,
489 .name =
"Headphone Playback Volume",
490 .info = snd_pmac_awacs_info_volume_amp,
491 .get = snd_pmac_awacs_get_volume_amp,
492 .put = snd_pmac_awacs_put_volume_amp,
493 .private_value = AMP_CH_HD,
496 .name =
"Tone Control - Bass",
497 .info = snd_pmac_awacs_info_tone_amp,
498 .get = snd_pmac_awacs_get_tone_amp,
499 .put = snd_pmac_awacs_put_tone_amp,
503 .name =
"Tone Control - Treble",
504 .info = snd_pmac_awacs_info_tone_amp,
505 .get = snd_pmac_awacs_get_tone_amp,
506 .put = snd_pmac_awacs_put_tone_amp,
510 .name =
"Amp Master Playback Volume",
511 .info = snd_pmac_awacs_info_master_amp,
512 .get = snd_pmac_awacs_get_master_amp,
513 .put = snd_pmac_awacs_put_master_amp,
519 .name =
"Headphone Playback Switch",
521 .get = snd_pmac_awacs_get_switch_amp,
522 .put = snd_pmac_awacs_put_switch_amp,
523 .private_value = AMP_CH_HD,
528 .name =
"Speaker Playback Switch",
530 .get = snd_pmac_awacs_get_switch_amp,
531 .put = snd_pmac_awacs_put_switch_amp,
532 .private_value = AMP_CH_SPK,
541 static int snd_pmac_screamer_mic_boost_info(
struct snd_kcontrol *kcontrol,
551 static int snd_pmac_screamer_mic_boost_get(
struct snd_kcontrol *kcontrol,
563 spin_unlock_irqrestore(&chip->
reg_lock, flags);
564 ucontrol->
value.integer.value[0] =
val;
568 static int snd_pmac_screamer_mic_boost_put(
struct snd_kcontrol *kcontrol,
579 if (ucontrol->
value.integer.value[0] & 1)
581 if (ucontrol->
value.integer.value[0] & 2)
584 snd_pmac_awacs_write_reg(chip, 0, val0);
588 snd_pmac_awacs_write_reg(chip, 6, val6);
591 spin_unlock_irqrestore(&chip->
reg_lock, flags);
604 static struct snd_kcontrol_new snd_pmac_screamer_mixers_beige[] __devinitdata = {
611 static struct snd_kcontrol_new snd_pmac_screamer_mixers_lo[] __devinitdata = {
615 static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] __devinitdata = {
620 static struct snd_kcontrol_new snd_pmac_screamer_mixers_g4agp[] __devinitdata = {
627 static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] __devinitdata = {
633 static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac5500[] __devinitdata = {
637 static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] __devinitdata = {
650 static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] __devinitdata = {
655 static struct snd_kcontrol_new snd_pmac_awacs_mixers2_pmac5500[] __devinitdata = {
662 static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac __devinitdata =
665 static struct snd_kcontrol_new snd_pmac_awacs_master_sw_pmac5500 __devinitdata =
672 static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __devinitdata = {
674 .name =
"Mic Boost Capture Volume",
675 .info = snd_pmac_screamer_mic_boost_info,
676 .get = snd_pmac_screamer_mic_boost_get,
677 .put = snd_pmac_screamer_mic_boost_put,
681 static struct snd_kcontrol_new snd_pmac_awacs_mic_boost_pmac7500[] __devinitdata =
686 static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_beige[] __devinitdata =
692 static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] __devinitdata =
698 static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __devinitdata = {
705 static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac1 __devinitdata =
708 static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac2 __devinitdata =
715 static int build_mixers(
struct snd_pmac *chip,
int nums,
720 for (i = 0; i < nums; i++) {
732 static void awacs_restore_all_regs(
struct snd_pmac *chip)
734 snd_pmac_awacs_write_noreg(chip, 0, chip->
awacs_reg[0]);
735 snd_pmac_awacs_write_noreg(chip, 1, chip->
awacs_reg[1]);
736 snd_pmac_awacs_write_noreg(chip, 2, chip->
awacs_reg[2]);
737 snd_pmac_awacs_write_noreg(chip, 4, chip->
awacs_reg[4]);
739 snd_pmac_awacs_write_noreg(chip, 5, chip->
awacs_reg[5]);
740 snd_pmac_awacs_write_noreg(chip, 6, chip->
awacs_reg[6]);
741 snd_pmac_awacs_write_noreg(chip, 7, chip->
awacs_reg[7]);
746 static void snd_pmac_awacs_suspend(
struct snd_pmac *chip)
748 snd_pmac_awacs_write_noreg(chip, 1, (chip->
awacs_reg[1]
752 static void snd_pmac_awacs_resume(
struct snd_pmac *chip)
757 snd_pmac_awacs_write_reg(chip, 1,
762 awacs_restore_all_regs(chip);
766 snd_pmac_awacs_write_noreg(chip, 6, chip->
awacs_reg[6]);
769 #ifdef PMAC_AMP_AVAIL
772 awacs_amp_set_vol(amp, 0,
773 amp->amp_vol[0][0], amp->amp_vol[0][1], 0);
774 awacs_amp_set_vol(amp, 1,
775 amp->amp_vol[1][0], amp->amp_vol[1][1], 0);
776 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
777 awacs_amp_set_master(amp, amp->amp_master);
783 #define IS_PM7500 (of_machine_is_compatible("AAPL,7500") \
784 || of_machine_is_compatible("AAPL,8500") \
785 || of_machine_is_compatible("AAPL,9500"))
786 #define IS_PM5500 (of_machine_is_compatible("AAPL,e411"))
787 #define IS_BEIGE (of_machine_is_compatible("AAPL,Gossamer"))
788 #define IS_IMAC1 (of_machine_is_compatible("PowerMac2,1"))
789 #define IS_IMAC2 (of_machine_is_compatible("PowerMac2,2") \
790 || of_machine_is_compatible("PowerMac4,1"))
791 #define IS_G4AGP (of_machine_is_compatible("PowerMac3,1"))
792 #define IS_LOMBARD (of_machine_is_compatible("PowerBook1,1"))
794 static int imac1, imac2;
796 #ifdef PMAC_SUPPORT_AUTOMUTE
800 static int snd_pmac_awacs_detect_headphone(
struct snd_pmac *chip)
805 #ifdef PMAC_AMP_AVAIL
806 static int toggle_amp_mute(
struct awacs_amp *amp,
int index,
int mute)
809 vol[0] = amp->amp_vol[
index][0] & 31;
810 vol[1] = amp->amp_vol[
index][1] & 31;
815 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
819 static void snd_pmac_awacs_update_automute(
struct snd_pmac *chip,
int do_notify)
822 #ifdef PMAC_AMP_AVAIL
826 if (snd_pmac_awacs_detect_headphone(chip)) {
827 changed = toggle_amp_mute(amp, AMP_CH_HD, 0);
828 changed |= toggle_amp_mute(amp, AMP_CH_SPK, 1);
830 changed = toggle_amp_mute(amp, AMP_CH_HD, 1);
831 changed |= toggle_amp_mute(amp, AMP_CH_SPK, 0);
833 if (do_notify && ! changed)
847 if (snd_pmac_awacs_detect_headphone(chip))
855 if (do_notify && reg == chip->
awacs_reg[1])
857 snd_pmac_awacs_write_reg(chip, 1, reg);
890 imac = imac1 || imac2;
905 vol = vol + (vol << 6);
916 awacs_restore_all_regs(chip);
921 #ifdef PMAC_AMP_AVAIL
923 struct awacs_amp *amp = kzalloc(
sizeof(*amp),
GFP_KERNEL);
929 awacs_amp_set_vol(amp, 0, 63, 63, 0);
930 awacs_amp_set_vol(amp, 1, 63, 63, 0);
931 awacs_amp_set_tone(amp, 7, 7);
932 awacs_amp_set_master(amp, 79);
938 switch (chip->
model) {
971 strcpy(chip->
card->mixername,
"PowerMac AWACS");
973 err = build_mixers(chip,
ARRAY_SIZE(snd_pmac_awacs_mixers),
974 snd_pmac_awacs_mixers);
980 err = build_mixers(chip,
ARRAY_SIZE(snd_pmac_screamer_mixers2),
981 snd_pmac_screamer_mixers2);
983 err = build_mixers(chip,
ARRAY_SIZE(snd_pmac_awacs_mixers2),
984 snd_pmac_awacs_mixers2);
988 err = build_mixers(chip,
990 snd_pmac_awacs_mixers2_pmac5500);
995 err = build_mixers(chip,
997 snd_pmac_awacs_mixers_pmac7500);
1000 (master_vol =
snd_ctl_new1(snd_pmac_awacs_mixers_pmac5500,
1003 err = build_mixers(chip,
1005 snd_pmac_screamer_mixers_beige);
1006 else if (imac || lombard) {
1008 (master_vol =
snd_ctl_new1(snd_pmac_screamer_mixers_lo,
1012 err = build_mixers(chip,
1014 snd_pmac_screamer_mixers_imac);
1016 err = build_mixers(chip,
1018 snd_pmac_screamer_mixers_g4agp);
1020 err = build_mixers(chip,
1022 snd_pmac_awacs_mixers_pmac);
1026 ? &snd_pmac_awacs_master_sw_imac
1028 ? &snd_pmac_awacs_master_sw_pmac5500
1029 : &snd_pmac_awacs_master_sw, chip);
1033 #ifdef PMAC_AMP_AVAIL
1041 err = build_mixers(chip,
ARRAY_SIZE(snd_pmac_awacs_amp_vol),
1042 snd_pmac_awacs_amp_vol);
1061 (speaker_vol =
snd_ctl_new1(snd_pmac_awacs_speaker_vol,
1066 ? &snd_pmac_awacs_speaker_sw_imac1
1068 ? &snd_pmac_awacs_speaker_sw_imac2
1069 : &snd_pmac_awacs_speaker_sw, chip);
1075 if (pm5500 || imac || lombard) {
1077 "Master Playback Switch", (
unsigned int *)
NULL);
1078 err = snd_ctl_add_slave_uncached(vmaster_sw,
1082 err = snd_ctl_add_slave_uncached(vmaster_sw,
1090 "Master Playback Volume", (
unsigned int *)
NULL);
1091 err = snd_ctl_add_slave(vmaster_vol, master_vol);
1094 err = snd_ctl_add_slave(vmaster_vol, speaker_vol);
1103 err = build_mixers(chip,
1104 ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige),
1105 snd_pmac_screamer_mic_boost_beige);
1107 err = build_mixers(chip,
1108 ARRAY_SIZE(snd_pmac_screamer_mic_boost_imac),
1109 snd_pmac_screamer_mic_boost_imac);
1111 err = build_mixers(chip,
1113 snd_pmac_screamer_mic_boost);
1115 err = build_mixers(chip,
1116 ARRAY_SIZE(snd_pmac_awacs_mic_boost_pmac7500),
1117 snd_pmac_awacs_mic_boost_pmac7500);
1119 err = build_mixers(chip,
ARRAY_SIZE(snd_pmac_awacs_mic_boost),
1120 snd_pmac_awacs_mic_boost);
1127 chip->
set_format = snd_pmac_awacs_set_format;
1129 chip->suspend = snd_pmac_awacs_suspend;
1130 chip->resume = snd_pmac_awacs_resume;
1132 #ifdef PMAC_SUPPORT_AUTOMUTE
1138 snd_pmac_awacs_update_automute(chip, 0);
1141 snd_pmac_awacs_write_noreg(chip, 6, chip->
awacs_reg[6]);
1142 snd_pmac_awacs_write_noreg(chip, 0, chip->
awacs_reg[0]);