2 * PMac Tumbler/Snapper lowlevel functions
4 * Copyright (c) by Takashi Iwai <tiwai@suse.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sound/driver.h>
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/i2c.h>
26 #include <linux/i2c-dev.h>
27 #include <linux/kmod.h>
28 #include <linux/slab.h>
29 #include <linux/interrupt.h>
30 #include <sound/core.h>
33 #ifdef CONFIG_PPC_HAS_FEATURE_CALLS
34 #include <asm/pmac_feature.h>
37 #include "tumbler_volume.h"
41 /* i2c address for tumbler */
42 #define TAS_I2C_ADDR 0x34
45 #define TAS_REG_MCS 0x01 /* main control */
46 #define TAS_REG_DRC 0x02
47 #define TAS_REG_VOL 0x04
48 #define TAS_REG_TREBLE 0x05
49 #define TAS_REG_BASS 0x06
50 #define TAS_REG_INPUT1 0x07
51 #define TAS_REG_INPUT2 0x08
54 #define TAS_REG_PCM TAS_REG_INPUT1
57 #define TAS_REG_LMIX TAS_REG_INPUT1
58 #define TAS_REG_RMIX TAS_REG_INPUT2
59 #define TAS_REG_MCS2 0x43 /* main control 2 */
60 #define TAS_REG_ACS 0x40 /* analog control */
62 /* mono volumes for tas3001c/tas3004 */
64 VOL_IDX_PCM_MONO, /* tas3001c only */
65 VOL_IDX_BASS, VOL_IDX_TREBLE,
69 /* stereo volumes for tas3004 */
71 VOL_IDX_PCM, VOL_IDX_PCM2, VOL_IDX_ADC,
75 typedef struct pmac_gpio {
76 #ifdef CONFIG_PPC_HAS_FEATURE_CALLS
84 typedef struct pmac_tumbler_t {
86 pmac_gpio_t audio_reset;
89 pmac_gpio_t hp_detect;
91 unsigned int master_vol[2];
92 unsigned int master_switch[2];
93 unsigned int mono_vol[VOL_IDX_LAST_MONO];
94 unsigned int mix_vol[VOL_IDX_LAST_MIX][2]; /* stereo volumes for tas3004 */
104 static int send_init_client(pmac_keywest_t *i2c, unsigned int *regs)
109 err = snd_pmac_keywest_write_byte(i2c, regs[0], regs[1]);
122 static int tumbler_init_client(pmac_keywest_t *i2c)
124 static unsigned int regs[] = {
125 /* normal operation, SCLK=64fps, i2s output, i2s input, 16bit width */
126 TAS_REG_MCS, (1<<6)|(2<<4)|(2<<2)|0,
129 return send_init_client(i2c, regs);
132 static int snapper_init_client(pmac_keywest_t *i2c)
134 static unsigned int regs[] = {
135 /* normal operation, SCLK=64fps, i2s output, 16bit width */
136 TAS_REG_MCS, (1<<6)|(2<<4)|0,
137 /* normal operation, all-pass mode */
138 TAS_REG_MCS2, (1<<1),
139 /* normal output, no deemphasis, A input, power-up, line-in */
143 return send_init_client(i2c, regs);
149 #ifdef CONFIG_PPC_HAS_FEATURE_CALLS
150 #define do_gpio_write(gp, val) \
151 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, (gp)->addr, val)
152 #define do_gpio_read(gp) \
153 pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, (gp)->addr, 0)
154 #define tumbler_gpio_free(gp) /* NOP */
156 #define do_gpio_write(gp, val) writeb(val, (gp)->addr)
157 #define do_gpio_read(gp) readb((gp)->addr)
158 static inline void tumbler_gpio_free(pmac_gpio_t *gp)
165 #endif /* CONFIG_PPC_HAS_FEATURE_CALLS */
167 static void write_audio_gpio(pmac_gpio_t *gp, int active)
171 active = active ? gp->active_state : !gp->active_state;
172 do_gpio_write(gp, active ? 0x05 : 0x04);
175 static int read_audio_gpio(pmac_gpio_t *gp)
180 ret = ((do_gpio_read(gp) & 0x02) !=0);
181 return ret == gp->active_state;
185 * update master volume
187 static int tumbler_set_master_volume(pmac_tumbler_t *mix)
189 unsigned char block[6];
190 unsigned int left_vol, right_vol;
192 if (! mix->i2c.client)
195 if (! mix->master_switch[0])
198 left_vol = mix->master_vol[0];
199 if (left_vol >= ARRAY_SIZE(master_volume_table))
200 left_vol = ARRAY_SIZE(master_volume_table) - 1;
201 left_vol = master_volume_table[left_vol];
203 if (! mix->master_switch[1])
206 right_vol = mix->master_vol[1];
207 if (right_vol >= ARRAY_SIZE(master_volume_table))
208 right_vol = ARRAY_SIZE(master_volume_table) - 1;
209 right_vol = master_volume_table[right_vol];
212 block[0] = (left_vol >> 16) & 0xff;
213 block[1] = (left_vol >> 8) & 0xff;
214 block[2] = (left_vol >> 0) & 0xff;
216 block[3] = (right_vol >> 16) & 0xff;
217 block[4] = (right_vol >> 8) & 0xff;
218 block[5] = (right_vol >> 0) & 0xff;
220 if (snd_pmac_keywest_write(&mix->i2c, TAS_REG_VOL, 6, block) < 0) {
221 snd_printk("failed to set volume \n");
229 static int tumbler_info_master_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
231 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
233 uinfo->value.integer.min = 0;
234 uinfo->value.integer.max = ARRAY_SIZE(master_volume_table) - 1;
238 static int tumbler_get_master_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
240 pmac_t *chip = snd_kcontrol_chip(kcontrol);
241 pmac_tumbler_t *mix = chip->mixer_data;
242 snd_assert(mix, return -ENODEV);
243 ucontrol->value.integer.value[0] = mix->master_vol[0];
244 ucontrol->value.integer.value[1] = mix->master_vol[1];
248 static int tumbler_put_master_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
250 pmac_t *chip = snd_kcontrol_chip(kcontrol);
251 pmac_tumbler_t *mix = chip->mixer_data;
254 snd_assert(mix, return -ENODEV);
255 change = mix->master_vol[0] != ucontrol->value.integer.value[0] ||
256 mix->master_vol[1] != ucontrol->value.integer.value[1];
258 mix->master_vol[0] = ucontrol->value.integer.value[0];
259 mix->master_vol[1] = ucontrol->value.integer.value[1];
260 tumbler_set_master_volume(mix);
266 static int tumbler_get_master_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
268 pmac_t *chip = snd_kcontrol_chip(kcontrol);
269 pmac_tumbler_t *mix = chip->mixer_data;
270 snd_assert(mix, return -ENODEV);
271 ucontrol->value.integer.value[0] = mix->master_switch[0];
272 ucontrol->value.integer.value[1] = mix->master_switch[1];
276 static int tumbler_put_master_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
278 pmac_t *chip = snd_kcontrol_chip(kcontrol);
279 pmac_tumbler_t *mix = chip->mixer_data;
282 snd_assert(mix, return -ENODEV);
283 change = mix->master_switch[0] != ucontrol->value.integer.value[0] ||
284 mix->master_switch[1] != ucontrol->value.integer.value[1];
286 mix->master_switch[0] = !!ucontrol->value.integer.value[0];
287 mix->master_switch[1] = !!ucontrol->value.integer.value[1];
288 tumbler_set_master_volume(mix);
295 * TAS3001c dynamic range compression
298 #define TAS3001_DRC_MAX 0x5f
300 static int tumbler_set_drc(pmac_tumbler_t *mix)
302 unsigned char val[2];
304 if (! mix->i2c.client)
307 if (mix->drc_enable) {
308 val[0] = 0xc1; /* enable, 3:1 compression */
309 if (mix->drc_range > TAS3001_DRC_MAX)
311 else if (mix->drc_range < 0)
314 val[1] = mix->drc_range + 0x91;
320 if (snd_pmac_keywest_write(&mix->i2c, TAS_REG_DRC, 2, val) < 0) {
321 snd_printk("failed to set DRC\n");
331 #define TAS3004_DRC_MAX 0xef
333 static int snapper_set_drc(pmac_tumbler_t *mix)
335 unsigned char val[6];
337 if (! mix->i2c.client)
341 val[0] = 0x50; /* 3:1 above threshold */
343 val[0] = 0x51; /* disabled */
344 val[1] = 0x02; /* 1:1 below threshold */
345 if (mix->drc_range > 0xef)
347 else if (mix->drc_range < 0)
350 val[2] = mix->drc_range;
355 if (snd_pmac_keywest_write(&mix->i2c, TAS_REG_DRC, 6, val) < 0) {
356 snd_printk("failed to set DRC\n");
362 static int tumbler_info_drc_value(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
364 pmac_t *chip = snd_kcontrol_chip(kcontrol);
365 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
367 uinfo->value.integer.min = 0;
368 uinfo->value.integer.max =
369 chip->model == PMAC_TUMBLER ? TAS3001_DRC_MAX : TAS3004_DRC_MAX;
373 static int tumbler_get_drc_value(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
375 pmac_t *chip = snd_kcontrol_chip(kcontrol);
377 if (! (mix = chip->mixer_data))
379 ucontrol->value.integer.value[0] = mix->drc_range;
383 static int tumbler_put_drc_value(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
385 pmac_t *chip = snd_kcontrol_chip(kcontrol);
389 if (! (mix = chip->mixer_data))
391 change = mix->drc_range != ucontrol->value.integer.value[0];
393 mix->drc_range = ucontrol->value.integer.value[0];
394 if (chip->model == PMAC_TUMBLER)
395 tumbler_set_drc(mix);
397 snapper_set_drc(mix);
402 static int tumbler_get_drc_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
404 pmac_t *chip = snd_kcontrol_chip(kcontrol);
406 if (! (mix = chip->mixer_data))
408 ucontrol->value.integer.value[0] = mix->drc_enable;
412 static int tumbler_put_drc_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
414 pmac_t *chip = snd_kcontrol_chip(kcontrol);
418 if (! (mix = chip->mixer_data))
420 change = mix->drc_enable != ucontrol->value.integer.value[0];
422 mix->drc_enable = !!ucontrol->value.integer.value[0];
423 if (chip->model == PMAC_TUMBLER)
424 tumbler_set_drc(mix);
426 snapper_set_drc(mix);
436 struct tumbler_mono_vol {
444 static int tumbler_set_mono_volume(pmac_tumbler_t *mix, struct tumbler_mono_vol *info)
446 unsigned char block[4];
450 if (! mix->i2c.client)
453 vol = mix->mono_vol[info->index];
454 if (vol >= info->max)
456 vol = info->table[vol];
457 for (i = 0; i < info->bytes; i++)
458 block[i] = (vol >> ((info->bytes - i - 1) * 8)) & 0xff;
459 if (snd_pmac_keywest_write(&mix->i2c, info->reg, info->bytes, block) < 0) {
460 snd_printk("failed to set mono volume %d\n", info->index);
466 static int tumbler_info_mono(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
468 struct tumbler_mono_vol *info = (struct tumbler_mono_vol *)kcontrol->private_value;
470 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
472 uinfo->value.integer.min = 0;
473 uinfo->value.integer.max = info->max - 1;
477 static int tumbler_get_mono(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
479 struct tumbler_mono_vol *info = (struct tumbler_mono_vol *)kcontrol->private_value;
480 pmac_t *chip = snd_kcontrol_chip(kcontrol);
482 if (! (mix = chip->mixer_data))
484 ucontrol->value.integer.value[0] = mix->mono_vol[info->index];
488 static int tumbler_put_mono(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
490 struct tumbler_mono_vol *info = (struct tumbler_mono_vol *)kcontrol->private_value;
491 pmac_t *chip = snd_kcontrol_chip(kcontrol);
495 if (! (mix = chip->mixer_data))
497 change = mix->mono_vol[info->index] != ucontrol->value.integer.value[0];
499 mix->mono_vol[info->index] = ucontrol->value.integer.value[0];
500 tumbler_set_mono_volume(mix, info);
505 /* TAS3001c mono volumes */
506 static struct tumbler_mono_vol tumbler_pcm_vol_info = {
507 .index = VOL_IDX_PCM_MONO,
510 .max = ARRAY_SIZE(mixer_volume_table),
511 .table = mixer_volume_table,
514 static struct tumbler_mono_vol tumbler_bass_vol_info = {
515 .index = VOL_IDX_BASS,
518 .max = ARRAY_SIZE(bass_volume_table),
519 .table = bass_volume_table,
522 static struct tumbler_mono_vol tumbler_treble_vol_info = {
523 .index = VOL_IDX_TREBLE,
524 .reg = TAS_REG_TREBLE,
526 .max = ARRAY_SIZE(treble_volume_table),
527 .table = treble_volume_table,
530 /* TAS3004 mono volumes */
531 static struct tumbler_mono_vol snapper_bass_vol_info = {
532 .index = VOL_IDX_BASS,
535 .max = ARRAY_SIZE(snapper_bass_volume_table),
536 .table = snapper_bass_volume_table,
539 static struct tumbler_mono_vol snapper_treble_vol_info = {
540 .index = VOL_IDX_TREBLE,
541 .reg = TAS_REG_TREBLE,
543 .max = ARRAY_SIZE(snapper_treble_volume_table),
544 .table = snapper_treble_volume_table,
548 #define DEFINE_MONO(xname,type) { \
549 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
551 .info = tumbler_info_mono, \
552 .get = tumbler_get_mono, \
553 .put = tumbler_put_mono, \
554 .private_value = (unsigned long)(&tumbler_##type##_vol_info), \
557 #define DEFINE_SNAPPER_MONO(xname,type) { \
558 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
560 .info = tumbler_info_mono, \
561 .get = tumbler_get_mono, \
562 .put = tumbler_put_mono, \
563 .private_value = (unsigned long)(&snapper_##type##_vol_info), \
568 * snapper mixer volumes
571 static int snapper_set_mix_vol1(pmac_tumbler_t *mix, int idx, int ch, int reg)
574 unsigned char block[9];
576 vol = mix->mix_vol[idx][ch];
577 if (vol >= ARRAY_SIZE(mixer_volume_table)) {
578 vol = ARRAY_SIZE(mixer_volume_table) - 1;
579 mix->mix_vol[idx][ch] = vol;
582 for (i = 0; i < 3; i++) {
583 vol = mix->mix_vol[i][ch];
584 vol = mixer_volume_table[vol];
585 for (j = 0; j < 3; j++)
586 block[i * 3 + j] = (vol >> ((2 - j) * 8)) & 0xff;
588 if (snd_pmac_keywest_write(&mix->i2c, reg, 9, block) < 0) {
589 snd_printk("failed to set mono volume %d\n", reg);
595 static int snapper_set_mix_vol(pmac_tumbler_t *mix, int idx)
597 if (! mix->i2c.client)
599 if (snapper_set_mix_vol1(mix, idx, 0, TAS_REG_LMIX) < 0 ||
600 snapper_set_mix_vol1(mix, idx, 1, TAS_REG_RMIX) < 0)
605 static int snapper_info_mix(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
607 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
609 uinfo->value.integer.min = 0;
610 uinfo->value.integer.max = ARRAY_SIZE(mixer_volume_table) - 1;
614 static int snapper_get_mix(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
616 int idx = (int)kcontrol->private_value;
617 pmac_t *chip = snd_kcontrol_chip(kcontrol);
619 if (! (mix = chip->mixer_data))
621 ucontrol->value.integer.value[0] = mix->mix_vol[idx][0];
622 ucontrol->value.integer.value[1] = mix->mix_vol[idx][1];
626 static int snapper_put_mix(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
628 int idx = (int)kcontrol->private_value;
629 pmac_t *chip = snd_kcontrol_chip(kcontrol);
633 if (! (mix = chip->mixer_data))
635 change = mix->mix_vol[idx][0] != ucontrol->value.integer.value[0] ||
636 mix->mix_vol[idx][1] != ucontrol->value.integer.value[1];
638 mix->mix_vol[idx][0] = ucontrol->value.integer.value[0];
639 mix->mix_vol[idx][1] = ucontrol->value.integer.value[1];
640 snapper_set_mix_vol(mix, idx);
650 enum { TUMBLER_MUTE_HP, TUMBLER_MUTE_AMP };
652 static int tumbler_get_mute_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
654 pmac_t *chip = snd_kcontrol_chip(kcontrol);
657 if (! (mix = chip->mixer_data))
659 gp = (kcontrol->private_value == TUMBLER_MUTE_HP) ? &mix->hp_mute : &mix->amp_mute;
660 ucontrol->value.integer.value[0] = ! read_audio_gpio(gp);
664 static int tumbler_put_mute_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
666 pmac_t *chip = snd_kcontrol_chip(kcontrol);
670 #ifdef PMAC_SUPPORT_AUTOMUTE
671 if (chip->update_automute && chip->auto_mute)
672 return 0; /* don't touch in the auto-mute mode */
674 if (! (mix = chip->mixer_data))
676 gp = (kcontrol->private_value == TUMBLER_MUTE_HP) ? &mix->hp_mute : &mix->amp_mute;
677 val = ! read_audio_gpio(gp);
678 if (val != ucontrol->value.integer.value[0]) {
679 write_audio_gpio(gp, ! ucontrol->value.integer.value[0]);
685 static int snapper_set_capture_source(pmac_tumbler_t *mix)
687 if (! mix->i2c.client)
689 return snd_pmac_keywest_write_byte(&mix->i2c, TAS_REG_ACS,
690 mix->capture_source ? 2 : 0);
693 static int snapper_info_capture_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
695 static char *texts[2] = {
698 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
700 uinfo->value.enumerated.items = 2;
701 if (uinfo->value.enumerated.item > 1)
702 uinfo->value.enumerated.item = 1;
703 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
707 static int snapper_get_capture_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
709 pmac_t *chip = snd_kcontrol_chip(kcontrol);
710 pmac_tumbler_t *mix = chip->mixer_data;
712 snd_assert(mix, return -ENODEV);
713 ucontrol->value.integer.value[0] = mix->capture_source;
717 static int snapper_put_capture_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
719 pmac_t *chip = snd_kcontrol_chip(kcontrol);
720 pmac_tumbler_t *mix = chip->mixer_data;
723 snd_assert(mix, return -ENODEV);
724 change = ucontrol->value.integer.value[0] != mix->capture_source;
726 mix->capture_source = !!ucontrol->value.integer.value[0];
727 snapper_set_capture_source(mix);
732 #define DEFINE_SNAPPER_MIX(xname,idx,ofs) { \
733 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
735 .info = snapper_info_mix, \
736 .get = snapper_get_mix, \
737 .put = snapper_put_mix, \
739 .private_value = ofs, \
745 static snd_kcontrol_new_t tumbler_mixers[] __initdata = {
746 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
747 .name = "Master Playback Volume",
748 .info = tumbler_info_master_volume,
749 .get = tumbler_get_master_volume,
750 .put = tumbler_put_master_volume
752 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
753 .name = "Master Playback Switch",
754 .info = snd_pmac_boolean_stereo_info,
755 .get = tumbler_get_master_switch,
756 .put = tumbler_put_master_switch
758 DEFINE_MONO("Tone Control - Bass", bass),
759 DEFINE_MONO("Tone Control - Treble", treble),
760 DEFINE_MONO("PCM Playback Volume", pcm),
761 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
762 .name = "DRC Switch",
763 .info = snd_pmac_boolean_mono_info,
764 .get = tumbler_get_drc_switch,
765 .put = tumbler_put_drc_switch
767 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
769 .info = tumbler_info_drc_value,
770 .get = tumbler_get_drc_value,
771 .put = tumbler_put_drc_value
775 static snd_kcontrol_new_t snapper_mixers[] __initdata = {
776 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
777 .name = "Master Playback Volume",
778 .info = tumbler_info_master_volume,
779 .get = tumbler_get_master_volume,
780 .put = tumbler_put_master_volume
782 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
783 .name = "Master Playback Switch",
784 .info = snd_pmac_boolean_stereo_info,
785 .get = tumbler_get_master_switch,
786 .put = tumbler_put_master_switch
788 DEFINE_SNAPPER_MIX("PCM Playback Volume", 0, VOL_IDX_PCM),
789 DEFINE_SNAPPER_MIX("PCM Playback Volume", 1, VOL_IDX_PCM2),
790 DEFINE_SNAPPER_MIX("Monitor Mix Volume", 0, VOL_IDX_ADC),
791 DEFINE_SNAPPER_MONO("Tone Control - Bass", bass),
792 DEFINE_SNAPPER_MONO("Tone Control - Treble", treble),
793 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
794 .name = "DRC Switch",
795 .info = snd_pmac_boolean_mono_info,
796 .get = tumbler_get_drc_switch,
797 .put = tumbler_put_drc_switch
799 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
801 .info = tumbler_info_drc_value,
802 .get = tumbler_get_drc_value,
803 .put = tumbler_put_drc_value
805 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
806 .name = "Input Source", /* FIXME: "Capture Source" doesn't work properly */
807 .info = snapper_info_capture_source,
808 .get = snapper_get_capture_source,
809 .put = snapper_put_capture_source
813 static snd_kcontrol_new_t tumbler_hp_sw __initdata = {
814 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
815 .name = "Headphone Playback Switch",
816 .info = snd_pmac_boolean_mono_info,
817 .get = tumbler_get_mute_switch,
818 .put = tumbler_put_mute_switch,
819 .private_value = TUMBLER_MUTE_HP,
821 static snd_kcontrol_new_t tumbler_speaker_sw __initdata = {
822 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
823 .name = "PC Speaker Playback Switch",
824 .info = snd_pmac_boolean_mono_info,
825 .get = tumbler_get_mute_switch,
826 .put = tumbler_put_mute_switch,
827 .private_value = TUMBLER_MUTE_AMP,
830 #ifdef PMAC_SUPPORT_AUTOMUTE
834 static int tumbler_detect_headphone(pmac_t *chip)
836 pmac_tumbler_t *mix = chip->mixer_data;
837 return read_audio_gpio(&mix->hp_detect);
840 static void check_mute(pmac_t *chip, pmac_gpio_t *gp, int val, int do_notify, snd_kcontrol_t *sw)
842 //pmac_tumbler_t *mix = chip->mixer_data;
843 if (val != read_audio_gpio(gp)) {
844 write_audio_gpio(gp, val);
846 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &sw->id);
850 static void tumbler_update_automute(pmac_t *chip, int do_notify)
852 if (chip->auto_mute) {
853 pmac_tumbler_t *mix = chip->mixer_data;
854 snd_assert(mix, return);
855 if (tumbler_detect_headphone(chip)) {
857 check_mute(chip, &mix->amp_mute, 1, do_notify, chip->speaker_sw_ctl);
858 check_mute(chip, &mix->hp_mute, 0, do_notify, chip->master_sw_ctl);
861 check_mute(chip, &mix->amp_mute, 0, do_notify, chip->speaker_sw_ctl);
862 check_mute(chip, &mix->hp_mute, 1, do_notify, chip->master_sw_ctl);
865 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
866 &chip->hp_detect_ctl->id);
869 #endif /* PMAC_SUPPORT_AUTOMUTE */
872 /* interrupt - headphone plug changed */
873 static irqreturn_t headphone_intr(int irq, void *devid, struct pt_regs *regs)
875 pmac_t *chip = snd_magic_cast(pmac_t, devid, return IRQ_NONE);
876 if (chip->update_automute && chip->initialized) {
877 chip->update_automute(chip, 1);
883 /* look for audio-gpio device */
884 static struct device_node *find_audio_device(const char *name)
886 struct device_node *np;
888 if (! (np = find_devices("gpio")))
891 for (np = np->child; np; np = np->sibling) {
892 char *property = get_property(np, "audio-gpio", NULL);
893 if (property && strcmp(property, name) == 0)
899 /* look for audio-gpio device */
900 static struct device_node *find_compatible_audio_device(const char *name)
902 struct device_node *np;
904 if (! (np = find_devices("gpio")))
907 for (np = np->child; np; np = np->sibling) {
908 if (device_is_compatible(np, name))
914 /* find an audio device and get its address */
915 static unsigned long tumbler_find_device(const char *device, pmac_gpio_t *gp, int is_compatible)
917 struct device_node *node;
921 node = find_compatible_audio_device(device);
923 node = find_audio_device(device);
925 snd_printdd("cannot find device %s\n", device);
929 base = (u32 *)get_property(node, "AAPL,address", NULL);
931 snd_printd("cannot find address for device %s\n", device);
935 #ifdef CONFIG_PPC_HAS_FEATURE_CALLS
936 gp->addr = (*base) & 0x0000ffff;
938 gp->addr = (void*)ioremap((unsigned long)(*base), 1);
940 base = (u32 *)get_property(node, "audio-gpio-active-state", NULL);
942 gp->active_state = *base;
944 gp->active_state = 1;
947 return (node->n_intrs > 0) ? node->intrs[0].line : 0;
951 static void tumbler_reset_audio(pmac_t *chip)
953 pmac_tumbler_t *mix = chip->mixer_data;
955 write_audio_gpio(&mix->audio_reset, 0);
957 write_audio_gpio(&mix->audio_reset, 1);
959 write_audio_gpio(&mix->audio_reset, 0);
963 #ifdef CONFIG_PMAC_PBOOK
965 static void tumbler_resume(pmac_t *chip)
967 pmac_tumbler_t *mix = chip->mixer_data;
969 snd_assert(mix, return);
971 tumbler_reset_audio(chip);
972 if (mix->i2c.client && mix->i2c.init_client) {
973 if (mix->i2c.init_client(&mix->i2c) < 0)
974 printk(KERN_ERR "tumbler_init_client error\n");
976 printk(KERN_ERR "tumbler: i2c is not initialized\n");
977 if (chip->model == PMAC_TUMBLER) {
978 tumbler_set_mono_volume(mix, &tumbler_pcm_vol_info);
979 tumbler_set_mono_volume(mix, &tumbler_bass_vol_info);
980 tumbler_set_mono_volume(mix, &tumbler_treble_vol_info);
981 tumbler_set_drc(mix);
983 snapper_set_mix_vol(mix, VOL_IDX_PCM);
984 snapper_set_mix_vol(mix, VOL_IDX_PCM2);
985 snapper_set_mix_vol(mix, VOL_IDX_ADC);
986 tumbler_set_mono_volume(mix, &snapper_bass_vol_info);
987 tumbler_set_mono_volume(mix, &snapper_treble_vol_info);
988 snapper_set_drc(mix);
989 snapper_set_capture_source(mix);
991 tumbler_set_master_volume(mix);
992 if (chip->update_automute)
993 chip->update_automute(chip, 0);
997 /* initialize tumbler */
998 static int __init tumbler_init(pmac_t *chip)
1001 pmac_tumbler_t *mix = chip->mixer_data;
1002 snd_assert(mix, return -EINVAL);
1004 tumbler_find_device("audio-hw-reset", &mix->audio_reset, 0);
1005 tumbler_find_device("amp-mute", &mix->amp_mute, 0);
1006 tumbler_find_device("headphone-mute", &mix->hp_mute, 0);
1007 irq = tumbler_find_device("headphone-detect", &mix->hp_detect, 0);
1009 irq = tumbler_find_device("keywest-gpio15", &mix->hp_detect, 1);
1011 tumbler_reset_audio(chip);
1013 /* activate headphone status interrupts */
1016 if ((err = request_irq(irq, headphone_intr, 0,
1017 "Tumbler Headphone Detection", chip)) < 0)
1019 /* activate headphone status interrupts */
1020 val = do_gpio_read(&mix->hp_detect);
1021 do_gpio_write(&mix->hp_detect, val | 0x80);
1023 mix->headphone_irq = irq;
1028 static void tumbler_cleanup(pmac_t *chip)
1030 pmac_tumbler_t *mix = chip->mixer_data;
1034 if (mix->headphone_irq >= 0)
1035 free_irq(mix->headphone_irq, chip);
1036 tumbler_gpio_free(&mix->audio_reset);
1037 tumbler_gpio_free(&mix->amp_mute);
1038 tumbler_gpio_free(&mix->hp_mute);
1039 tumbler_gpio_free(&mix->hp_detect);
1040 snd_pmac_keywest_cleanup(&mix->i2c);
1042 chip->mixer_data = NULL;
1046 int __init snd_pmac_tumbler_init(pmac_t *chip)
1049 pmac_tumbler_t *mix;
1051 struct device_node *tas_node;
1055 if (current->fs->root)
1056 request_module("i2c-keywest");
1057 #endif /* CONFIG_KMOD */
1059 mix = kmalloc(sizeof(*mix), GFP_KERNEL);
1062 memset(mix, 0, sizeof(*mix));
1063 mix->headphone_irq = -1;
1065 chip->mixer_data = mix;
1066 chip->mixer_free = tumbler_cleanup;
1068 if ((err = tumbler_init(chip)) < 0)
1072 tas_node = find_devices("deq");
1073 if (tas_node == NULL)
1076 paddr = (u32 *)get_property(tas_node, "i2c-address", NULL);
1078 mix->i2c.addr = (*paddr) >> 1;
1080 mix->i2c.addr = TAS_I2C_ADDR;
1082 if (chip->model == PMAC_TUMBLER) {
1083 mix->i2c.init_client = tumbler_init_client;
1084 mix->i2c.name = "TAS3001c";
1085 chipname = "Tumbler";
1087 mix->i2c.init_client = snapper_init_client;
1088 mix->i2c.name = "TAS3004";
1089 chipname = "Snapper";
1092 if ((err = snd_pmac_keywest_init(&mix->i2c)) < 0)
1098 sprintf(chip->card->mixername, "PowerMac %s", chipname);
1100 if (chip->model == PMAC_TUMBLER) {
1101 for (i = 0; i < ARRAY_SIZE(tumbler_mixers); i++) {
1102 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&tumbler_mixers[i], chip))) < 0)
1106 for (i = 0; i < ARRAY_SIZE(snapper_mixers); i++) {
1107 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snapper_mixers[i], chip))) < 0)
1111 chip->master_sw_ctl = snd_ctl_new1(&tumbler_hp_sw, chip);
1112 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0)
1114 chip->speaker_sw_ctl = snd_ctl_new1(&tumbler_speaker_sw, chip);
1115 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0)
1118 #ifdef CONFIG_PMAC_PBOOK
1119 chip->resume = tumbler_resume;
1122 #ifdef PMAC_SUPPORT_AUTOMUTE
1123 if (mix->headphone_irq >=0 && (err = snd_pmac_add_automute(chip)) < 0)
1125 chip->detect_headphone = tumbler_detect_headphone;
1126 chip->update_automute = tumbler_update_automute;
1127 tumbler_update_automute(chip, 0); /* update the status only */