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
20 * Rene Rebe <rene.rebe@gmx.net>:
21 * * update from shadow registers on wakeup and headphone plug
22 * * automatically toggle DRC on headphone plug
27 #include <sound/driver.h>
28 #include <linux/init.h>
29 #include <linux/delay.h>
30 #include <linux/i2c.h>
31 #include <linux/i2c-dev.h>
32 #include <linux/kmod.h>
33 #include <linux/slab.h>
34 #include <linux/interrupt.h>
35 #include <sound/core.h>
38 #ifdef CONFIG_PPC_HAS_FEATURE_CALLS
39 #include <asm/pmac_feature.h>
42 #include "tumbler_volume.h"
44 /* i2c address for tumbler */
45 #define TAS_I2C_ADDR 0x34
48 #define TAS_REG_MCS 0x01 /* main control */
49 #define TAS_REG_DRC 0x02
50 #define TAS_REG_VOL 0x04
51 #define TAS_REG_TREBLE 0x05
52 #define TAS_REG_BASS 0x06
53 #define TAS_REG_INPUT1 0x07
54 #define TAS_REG_INPUT2 0x08
57 #define TAS_REG_PCM TAS_REG_INPUT1
60 #define TAS_REG_LMIX TAS_REG_INPUT1
61 #define TAS_REG_RMIX TAS_REG_INPUT2
62 #define TAS_REG_MCS2 0x43 /* main control 2 */
63 #define TAS_REG_ACS 0x40 /* analog control */
65 /* mono volumes for tas3001c/tas3004 */
67 VOL_IDX_PCM_MONO
, /* tas3001c only */
68 VOL_IDX_BASS
, VOL_IDX_TREBLE
,
72 /* stereo volumes for tas3004 */
74 VOL_IDX_PCM
, VOL_IDX_PCM2
, VOL_IDX_ADC
,
78 typedef struct pmac_gpio
{
79 #ifdef CONFIG_PPC_HAS_FEATURE_CALLS
87 typedef struct pmac_tumbler_t
{
89 pmac_gpio_t audio_reset
;
92 pmac_gpio_t hp_detect
;
94 unsigned int master_vol
[2];
95 unsigned int master_switch
[2];
96 unsigned int mono_vol
[VOL_IDX_LAST_MONO
];
97 unsigned int mix_vol
[VOL_IDX_LAST_MIX
][2]; /* stereo volumes for tas3004 */
107 static int send_init_client(pmac_keywest_t
*i2c
, unsigned int *regs
)
112 err
= i2c_smbus_write_byte_data(i2c
->client
,
126 static int tumbler_init_client(pmac_keywest_t
*i2c
)
128 static unsigned int regs
[] = {
129 /* normal operation, SCLK=64fps, i2s output, i2s input, 16bit width */
130 TAS_REG_MCS
, (1<<6)|(2<<4)|(2<<2)|0,
133 return send_init_client(i2c
, regs
);
136 static int snapper_init_client(pmac_keywest_t
*i2c
)
138 static unsigned int regs
[] = {
139 /* normal operation, SCLK=64fps, i2s output, 16bit width */
140 TAS_REG_MCS
, (1<<6)|(2<<4)|0,
141 /* normal operation, all-pass mode */
142 TAS_REG_MCS2
, (1<<1),
143 /* normal output, no deemphasis, A input, power-up, line-in */
147 return send_init_client(i2c
, regs
);
153 #ifdef CONFIG_PPC_HAS_FEATURE_CALLS
154 #define do_gpio_write(gp, val) \
155 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, (gp)->addr, val)
156 #define do_gpio_read(gp) \
157 pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, (gp)->addr, 0)
158 #define tumbler_gpio_free(gp) /* NOP */
160 #define do_gpio_write(gp, val) writeb(val, (gp)->addr)
161 #define do_gpio_read(gp) readb((gp)->addr)
162 static inline void tumbler_gpio_free(pmac_gpio_t
*gp
)
169 #endif /* CONFIG_PPC_HAS_FEATURE_CALLS */
171 static void write_audio_gpio(pmac_gpio_t
*gp
, int active
)
175 active
= active
? gp
->active_state
: !gp
->active_state
;
176 do_gpio_write(gp
, active
? 0x05 : 0x04);
179 static int read_audio_gpio(pmac_gpio_t
*gp
)
184 ret
= ((do_gpio_read(gp
) & 0x02) !=0);
185 return ret
== gp
->active_state
;
189 * update master volume
191 static int tumbler_set_master_volume(pmac_tumbler_t
*mix
)
193 unsigned char block
[6];
194 unsigned int left_vol
, right_vol
;
196 if (! mix
->i2c
.client
)
199 if (! mix
->master_switch
[0])
202 left_vol
= mix
->master_vol
[0];
203 if (left_vol
>= ARRAY_SIZE(master_volume_table
))
204 left_vol
= ARRAY_SIZE(master_volume_table
) - 1;
205 left_vol
= master_volume_table
[left_vol
];
207 if (! mix
->master_switch
[1])
210 right_vol
= mix
->master_vol
[1];
211 if (right_vol
>= ARRAY_SIZE(master_volume_table
))
212 right_vol
= ARRAY_SIZE(master_volume_table
) - 1;
213 right_vol
= master_volume_table
[right_vol
];
216 block
[0] = (left_vol
>> 16) & 0xff;
217 block
[1] = (left_vol
>> 8) & 0xff;
218 block
[2] = (left_vol
>> 0) & 0xff;
220 block
[3] = (right_vol
>> 16) & 0xff;
221 block
[4] = (right_vol
>> 8) & 0xff;
222 block
[5] = (right_vol
>> 0) & 0xff;
224 if (i2c_smbus_write_block_data(mix
->i2c
.client
, TAS_REG_VOL
,
226 snd_printk("failed to set volume \n");
234 static int tumbler_info_master_volume(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
236 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
238 uinfo
->value
.integer
.min
= 0;
239 uinfo
->value
.integer
.max
= ARRAY_SIZE(master_volume_table
) - 1;
243 static int tumbler_get_master_volume(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
245 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
246 pmac_tumbler_t
*mix
= chip
->mixer_data
;
247 snd_assert(mix
, return -ENODEV
);
248 ucontrol
->value
.integer
.value
[0] = mix
->master_vol
[0];
249 ucontrol
->value
.integer
.value
[1] = mix
->master_vol
[1];
253 static int tumbler_put_master_volume(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
255 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
256 pmac_tumbler_t
*mix
= chip
->mixer_data
;
259 snd_assert(mix
, return -ENODEV
);
260 change
= mix
->master_vol
[0] != ucontrol
->value
.integer
.value
[0] ||
261 mix
->master_vol
[1] != ucontrol
->value
.integer
.value
[1];
263 mix
->master_vol
[0] = ucontrol
->value
.integer
.value
[0];
264 mix
->master_vol
[1] = ucontrol
->value
.integer
.value
[1];
265 tumbler_set_master_volume(mix
);
271 static int tumbler_get_master_switch(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
273 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
274 pmac_tumbler_t
*mix
= chip
->mixer_data
;
275 snd_assert(mix
, return -ENODEV
);
276 ucontrol
->value
.integer
.value
[0] = mix
->master_switch
[0];
277 ucontrol
->value
.integer
.value
[1] = mix
->master_switch
[1];
281 static int tumbler_put_master_switch(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
283 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
284 pmac_tumbler_t
*mix
= chip
->mixer_data
;
287 snd_assert(mix
, return -ENODEV
);
288 change
= mix
->master_switch
[0] != ucontrol
->value
.integer
.value
[0] ||
289 mix
->master_switch
[1] != ucontrol
->value
.integer
.value
[1];
291 mix
->master_switch
[0] = !!ucontrol
->value
.integer
.value
[0];
292 mix
->master_switch
[1] = !!ucontrol
->value
.integer
.value
[1];
293 tumbler_set_master_volume(mix
);
300 * TAS3001c dynamic range compression
303 #define TAS3001_DRC_MAX 0x5f
305 static int tumbler_set_drc(pmac_tumbler_t
*mix
)
307 unsigned char val
[2];
309 if (! mix
->i2c
.client
)
312 if (mix
->drc_enable
) {
313 val
[0] = 0xc1; /* enable, 3:1 compression */
314 if (mix
->drc_range
> TAS3001_DRC_MAX
)
316 else if (mix
->drc_range
< 0)
319 val
[1] = mix
->drc_range
+ 0x91;
325 if (i2c_smbus_write_block_data(mix
->i2c
.client
, TAS_REG_DRC
,
327 snd_printk("failed to set DRC\n");
337 #define TAS3004_DRC_MAX 0xef
339 static int snapper_set_drc(pmac_tumbler_t
*mix
)
341 unsigned char val
[6];
343 if (! mix
->i2c
.client
)
347 val
[0] = 0x50; /* 3:1 above threshold */
349 val
[0] = 0x51; /* disabled */
350 val
[1] = 0x02; /* 1:1 below threshold */
351 if (mix
->drc_range
> 0xef)
353 else if (mix
->drc_range
< 0)
356 val
[2] = mix
->drc_range
;
361 if (i2c_smbus_write_block_data(mix
->i2c
.client
, TAS_REG_DRC
,
363 snd_printk("failed to set DRC\n");
369 static int tumbler_info_drc_value(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
371 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
372 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
374 uinfo
->value
.integer
.min
= 0;
375 uinfo
->value
.integer
.max
=
376 chip
->model
== PMAC_TUMBLER
? TAS3001_DRC_MAX
: TAS3004_DRC_MAX
;
380 static int tumbler_get_drc_value(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
382 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
384 if (! (mix
= chip
->mixer_data
))
386 ucontrol
->value
.integer
.value
[0] = mix
->drc_range
;
390 static int tumbler_put_drc_value(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
392 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
396 if (! (mix
= chip
->mixer_data
))
398 change
= mix
->drc_range
!= ucontrol
->value
.integer
.value
[0];
400 mix
->drc_range
= ucontrol
->value
.integer
.value
[0];
401 if (chip
->model
== PMAC_TUMBLER
)
402 tumbler_set_drc(mix
);
404 snapper_set_drc(mix
);
409 static int tumbler_get_drc_switch(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
411 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
413 if (! (mix
= chip
->mixer_data
))
415 ucontrol
->value
.integer
.value
[0] = mix
->drc_enable
;
419 static int tumbler_put_drc_switch(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
421 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
425 if (! (mix
= chip
->mixer_data
))
427 change
= mix
->drc_enable
!= ucontrol
->value
.integer
.value
[0];
429 mix
->drc_enable
= !!ucontrol
->value
.integer
.value
[0];
430 if (chip
->model
== PMAC_TUMBLER
)
431 tumbler_set_drc(mix
);
433 snapper_set_drc(mix
);
443 struct tumbler_mono_vol
{
451 static int tumbler_set_mono_volume(pmac_tumbler_t
*mix
, struct tumbler_mono_vol
*info
)
453 unsigned char block
[4];
457 if (! mix
->i2c
.client
)
460 vol
= mix
->mono_vol
[info
->index
];
461 if (vol
>= info
->max
)
463 vol
= info
->table
[vol
];
464 for (i
= 0; i
< info
->bytes
; i
++)
465 block
[i
] = (vol
>> ((info
->bytes
- i
- 1) * 8)) & 0xff;
466 if (i2c_smbus_write_block_data(mix
->i2c
.client
, info
->reg
,
467 info
->bytes
, block
) < 0) {
468 snd_printk("failed to set mono volume %d\n", info
->index
);
474 static int tumbler_info_mono(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
476 struct tumbler_mono_vol
*info
= (struct tumbler_mono_vol
*)kcontrol
->private_value
;
478 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
480 uinfo
->value
.integer
.min
= 0;
481 uinfo
->value
.integer
.max
= info
->max
- 1;
485 static int tumbler_get_mono(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
487 struct tumbler_mono_vol
*info
= (struct tumbler_mono_vol
*)kcontrol
->private_value
;
488 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
490 if (! (mix
= chip
->mixer_data
))
492 ucontrol
->value
.integer
.value
[0] = mix
->mono_vol
[info
->index
];
496 static int tumbler_put_mono(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
498 struct tumbler_mono_vol
*info
= (struct tumbler_mono_vol
*)kcontrol
->private_value
;
499 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
503 if (! (mix
= chip
->mixer_data
))
505 change
= mix
->mono_vol
[info
->index
] != ucontrol
->value
.integer
.value
[0];
507 mix
->mono_vol
[info
->index
] = ucontrol
->value
.integer
.value
[0];
508 tumbler_set_mono_volume(mix
, info
);
513 /* TAS3001c mono volumes */
514 static struct tumbler_mono_vol tumbler_pcm_vol_info
= {
515 .index
= VOL_IDX_PCM_MONO
,
518 .max
= ARRAY_SIZE(mixer_volume_table
),
519 .table
= mixer_volume_table
,
522 static struct tumbler_mono_vol tumbler_bass_vol_info
= {
523 .index
= VOL_IDX_BASS
,
526 .max
= ARRAY_SIZE(bass_volume_table
),
527 .table
= bass_volume_table
,
530 static struct tumbler_mono_vol tumbler_treble_vol_info
= {
531 .index
= VOL_IDX_TREBLE
,
532 .reg
= TAS_REG_TREBLE
,
534 .max
= ARRAY_SIZE(treble_volume_table
),
535 .table
= treble_volume_table
,
538 /* TAS3004 mono volumes */
539 static struct tumbler_mono_vol snapper_bass_vol_info
= {
540 .index
= VOL_IDX_BASS
,
543 .max
= ARRAY_SIZE(snapper_bass_volume_table
),
544 .table
= snapper_bass_volume_table
,
547 static struct tumbler_mono_vol snapper_treble_vol_info
= {
548 .index
= VOL_IDX_TREBLE
,
549 .reg
= TAS_REG_TREBLE
,
551 .max
= ARRAY_SIZE(snapper_treble_volume_table
),
552 .table
= snapper_treble_volume_table
,
556 #define DEFINE_MONO(xname,type) { \
557 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
559 .info = tumbler_info_mono, \
560 .get = tumbler_get_mono, \
561 .put = tumbler_put_mono, \
562 .private_value = (unsigned long)(&tumbler_##type##_vol_info), \
565 #define DEFINE_SNAPPER_MONO(xname,type) { \
566 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
568 .info = tumbler_info_mono, \
569 .get = tumbler_get_mono, \
570 .put = tumbler_put_mono, \
571 .private_value = (unsigned long)(&snapper_##type##_vol_info), \
576 * snapper mixer volumes
579 static int snapper_set_mix_vol1(pmac_tumbler_t
*mix
, int idx
, int ch
, int reg
)
582 unsigned char block
[9];
584 vol
= mix
->mix_vol
[idx
][ch
];
585 if (vol
>= ARRAY_SIZE(mixer_volume_table
)) {
586 vol
= ARRAY_SIZE(mixer_volume_table
) - 1;
587 mix
->mix_vol
[idx
][ch
] = vol
;
590 for (i
= 0; i
< 3; i
++) {
591 vol
= mix
->mix_vol
[i
][ch
];
592 vol
= mixer_volume_table
[vol
];
593 for (j
= 0; j
< 3; j
++)
594 block
[i
* 3 + j
] = (vol
>> ((2 - j
) * 8)) & 0xff;
596 if (i2c_smbus_write_block_data(mix
->i2c
.client
, reg
, 9, block
) < 0) {
597 snd_printk("failed to set mono volume %d\n", reg
);
603 static int snapper_set_mix_vol(pmac_tumbler_t
*mix
, int idx
)
605 if (! mix
->i2c
.client
)
607 if (snapper_set_mix_vol1(mix
, idx
, 0, TAS_REG_LMIX
) < 0 ||
608 snapper_set_mix_vol1(mix
, idx
, 1, TAS_REG_RMIX
) < 0)
613 static int snapper_info_mix(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
615 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
617 uinfo
->value
.integer
.min
= 0;
618 uinfo
->value
.integer
.max
= ARRAY_SIZE(mixer_volume_table
) - 1;
622 static int snapper_get_mix(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
624 int idx
= (int)kcontrol
->private_value
;
625 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
627 if (! (mix
= chip
->mixer_data
))
629 ucontrol
->value
.integer
.value
[0] = mix
->mix_vol
[idx
][0];
630 ucontrol
->value
.integer
.value
[1] = mix
->mix_vol
[idx
][1];
634 static int snapper_put_mix(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
636 int idx
= (int)kcontrol
->private_value
;
637 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
641 if (! (mix
= chip
->mixer_data
))
643 change
= mix
->mix_vol
[idx
][0] != ucontrol
->value
.integer
.value
[0] ||
644 mix
->mix_vol
[idx
][1] != ucontrol
->value
.integer
.value
[1];
646 mix
->mix_vol
[idx
][0] = ucontrol
->value
.integer
.value
[0];
647 mix
->mix_vol
[idx
][1] = ucontrol
->value
.integer
.value
[1];
648 snapper_set_mix_vol(mix
, idx
);
658 enum { TUMBLER_MUTE_HP
, TUMBLER_MUTE_AMP
};
660 static int tumbler_get_mute_switch(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
662 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
665 if (! (mix
= chip
->mixer_data
))
667 gp
= (kcontrol
->private_value
== TUMBLER_MUTE_HP
) ? &mix
->hp_mute
: &mix
->amp_mute
;
668 ucontrol
->value
.integer
.value
[0] = ! read_audio_gpio(gp
);
672 static int tumbler_put_mute_switch(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
674 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
678 #ifdef PMAC_SUPPORT_AUTOMUTE
679 if (chip
->update_automute
&& chip
->auto_mute
)
680 return 0; /* don't touch in the auto-mute mode */
682 if (! (mix
= chip
->mixer_data
))
684 gp
= (kcontrol
->private_value
== TUMBLER_MUTE_HP
) ? &mix
->hp_mute
: &mix
->amp_mute
;
685 val
= ! read_audio_gpio(gp
);
686 if (val
!= ucontrol
->value
.integer
.value
[0]) {
687 write_audio_gpio(gp
, ! ucontrol
->value
.integer
.value
[0]);
693 static int snapper_set_capture_source(pmac_tumbler_t
*mix
)
695 if (! mix
->i2c
.client
)
697 return i2c_smbus_write_byte_data(mix
->i2c
.client
, TAS_REG_ACS
,
698 mix
->capture_source
? 2 : 0);
701 static int snapper_info_capture_source(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
703 static char *texts
[2] = {
706 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
708 uinfo
->value
.enumerated
.items
= 2;
709 if (uinfo
->value
.enumerated
.item
> 1)
710 uinfo
->value
.enumerated
.item
= 1;
711 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
715 static int snapper_get_capture_source(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
717 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
718 pmac_tumbler_t
*mix
= chip
->mixer_data
;
720 snd_assert(mix
, return -ENODEV
);
721 ucontrol
->value
.integer
.value
[0] = mix
->capture_source
;
725 static int snapper_put_capture_source(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
727 pmac_t
*chip
= snd_kcontrol_chip(kcontrol
);
728 pmac_tumbler_t
*mix
= chip
->mixer_data
;
731 snd_assert(mix
, return -ENODEV
);
732 change
= ucontrol
->value
.integer
.value
[0] != mix
->capture_source
;
734 mix
->capture_source
= !!ucontrol
->value
.integer
.value
[0];
735 snapper_set_capture_source(mix
);
740 #define DEFINE_SNAPPER_MIX(xname,idx,ofs) { \
741 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
743 .info = snapper_info_mix, \
744 .get = snapper_get_mix, \
745 .put = snapper_put_mix, \
747 .private_value = ofs, \
753 static snd_kcontrol_new_t tumbler_mixers
[] __initdata
= {
754 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
755 .name
= "Master Playback Volume",
756 .info
= tumbler_info_master_volume
,
757 .get
= tumbler_get_master_volume
,
758 .put
= tumbler_put_master_volume
760 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
761 .name
= "Master Playback Switch",
762 .info
= snd_pmac_boolean_stereo_info
,
763 .get
= tumbler_get_master_switch
,
764 .put
= tumbler_put_master_switch
766 DEFINE_MONO("Tone Control - Bass", bass
),
767 DEFINE_MONO("Tone Control - Treble", treble
),
768 DEFINE_MONO("PCM Playback Volume", pcm
),
769 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
771 .info
= tumbler_info_drc_value
,
772 .get
= tumbler_get_drc_value
,
773 .put
= tumbler_put_drc_value
777 static snd_kcontrol_new_t snapper_mixers
[] __initdata
= {
778 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
779 .name
= "Master Playback Volume",
780 .info
= tumbler_info_master_volume
,
781 .get
= tumbler_get_master_volume
,
782 .put
= tumbler_put_master_volume
784 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
785 .name
= "Master Playback Switch",
786 .info
= snd_pmac_boolean_stereo_info
,
787 .get
= tumbler_get_master_switch
,
788 .put
= tumbler_put_master_switch
790 DEFINE_SNAPPER_MIX("PCM Playback Volume", 0, VOL_IDX_PCM
),
791 DEFINE_SNAPPER_MIX("PCM Playback Volume", 1, VOL_IDX_PCM2
),
792 DEFINE_SNAPPER_MIX("Monitor Mix Volume", 0, VOL_IDX_ADC
),
793 DEFINE_SNAPPER_MONO("Tone Control - Bass", bass
),
794 DEFINE_SNAPPER_MONO("Tone Control - Treble", treble
),
795 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
797 .info
= tumbler_info_drc_value
,
798 .get
= tumbler_get_drc_value
,
799 .put
= tumbler_put_drc_value
801 { .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
802 .name
= "Input Source", /* FIXME: "Capture Source" doesn't work properly */
803 .info
= snapper_info_capture_source
,
804 .get
= snapper_get_capture_source
,
805 .put
= snapper_put_capture_source
809 static snd_kcontrol_new_t tumbler_hp_sw __initdata
= {
810 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
811 .name
= "Headphone Playback Switch",
812 .info
= snd_pmac_boolean_mono_info
,
813 .get
= tumbler_get_mute_switch
,
814 .put
= tumbler_put_mute_switch
,
815 .private_value
= TUMBLER_MUTE_HP
,
817 static snd_kcontrol_new_t tumbler_speaker_sw __initdata
= {
818 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
819 .name
= "PC Speaker Playback Switch",
820 .info
= snd_pmac_boolean_mono_info
,
821 .get
= tumbler_get_mute_switch
,
822 .put
= tumbler_put_mute_switch
,
823 .private_value
= TUMBLER_MUTE_AMP
,
825 static snd_kcontrol_new_t tumbler_drc_sw __initdata
= {
826 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
827 .name
= "DRC Switch",
828 .info
= snd_pmac_boolean_mono_info
,
829 .get
= tumbler_get_drc_switch
,
830 .put
= tumbler_put_drc_switch
834 #ifdef PMAC_SUPPORT_AUTOMUTE
838 static int tumbler_detect_headphone(pmac_t
*chip
)
840 pmac_tumbler_t
*mix
= chip
->mixer_data
;
841 return read_audio_gpio(&mix
->hp_detect
);
844 static void check_mute(pmac_t
*chip
, pmac_gpio_t
*gp
, int val
, int do_notify
, snd_kcontrol_t
*sw
)
846 //pmac_tumbler_t *mix = chip->mixer_data;
847 if (val
!= read_audio_gpio(gp
)) {
848 write_audio_gpio(gp
, val
);
850 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
, &sw
->id
);
854 static struct work_struct device_change
;
857 device_change_handler(void *self
)
859 pmac_t
*chip
= (pmac_t
*) self
;
865 mix
= chip
->mixer_data
;
867 /* first set the DRC so the speaker do not explode -ReneR */
868 if (chip
->model
== PMAC_TUMBLER
)
869 tumbler_set_drc(mix
);
871 snapper_set_drc(mix
);
873 /* reset the master volume so the correct amplification is applied */
874 tumbler_set_master_volume(mix
);
877 static void tumbler_update_automute(pmac_t
*chip
, int do_notify
)
879 if (chip
->auto_mute
) {
880 pmac_tumbler_t
*mix
= chip
->mixer_data
;
881 snd_assert(mix
, return);
882 if (tumbler_detect_headphone(chip
)) {
884 check_mute(chip
, &mix
->amp_mute
, 1, do_notify
, chip
->speaker_sw_ctl
);
885 check_mute(chip
, &mix
->hp_mute
, 0, do_notify
, chip
->master_sw_ctl
);
890 check_mute(chip
, &mix
->amp_mute
, 0, do_notify
, chip
->speaker_sw_ctl
);
891 check_mute(chip
, &mix
->hp_mute
, 1, do_notify
, chip
->master_sw_ctl
);
895 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
896 &chip
->hp_detect_ctl
->id
);
897 snd_ctl_notify(chip
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
898 &chip
->drc_sw_ctl
->id
);
901 /* finally we need to schedule an update of the mixer values
902 (master and DRC are enough for now) -ReneR */
903 schedule_work(&device_change
);
907 #endif /* PMAC_SUPPORT_AUTOMUTE */
910 /* interrupt - headphone plug changed */
911 static irqreturn_t
headphone_intr(int irq
, void *devid
, struct pt_regs
*regs
)
913 pmac_t
*chip
= devid
;
914 if (chip
->update_automute
&& chip
->initialized
) {
915 chip
->update_automute(chip
, 1);
921 /* look for audio-gpio device */
922 static struct device_node
*find_audio_device(const char *name
)
924 struct device_node
*np
;
926 if (! (np
= find_devices("gpio")))
929 for (np
= np
->child
; np
; np
= np
->sibling
) {
930 char *property
= get_property(np
, "audio-gpio", NULL
);
931 if (property
&& strcmp(property
, name
) == 0)
937 /* look for audio-gpio device */
938 static struct device_node
*find_compatible_audio_device(const char *name
)
940 struct device_node
*np
;
942 if (! (np
= find_devices("gpio")))
945 for (np
= np
->child
; np
; np
= np
->sibling
) {
946 if (device_is_compatible(np
, name
))
952 /* find an audio device and get its address */
953 static unsigned long tumbler_find_device(const char *device
, pmac_gpio_t
*gp
, int is_compatible
)
955 struct device_node
*node
;
959 node
= find_compatible_audio_device(device
);
961 node
= find_audio_device(device
);
963 snd_printdd("cannot find device %s\n", device
);
967 base
= (u32
*)get_property(node
, "AAPL,address", NULL
);
969 snd_printd("cannot find address for device %s\n", device
);
973 #ifdef CONFIG_PPC_HAS_FEATURE_CALLS
974 gp
->addr
= (*base
) & 0x0000ffff;
976 gp
->addr
= ioremap((unsigned long)(*base
), 1);
978 base
= (u32
*)get_property(node
, "audio-gpio-active-state", NULL
);
980 gp
->active_state
= *base
;
982 gp
->active_state
= 1;
985 return (node
->n_intrs
> 0) ? node
->intrs
[0].line
: 0;
989 static void tumbler_reset_audio(pmac_t
*chip
)
991 pmac_tumbler_t
*mix
= chip
->mixer_data
;
993 write_audio_gpio(&mix
->audio_reset
, 0);
995 write_audio_gpio(&mix
->audio_reset
, 1);
997 write_audio_gpio(&mix
->audio_reset
, 0);
1001 #ifdef CONFIG_PMAC_PBOOK
1003 static void tumbler_resume(pmac_t
*chip
)
1005 pmac_tumbler_t
*mix
= chip
->mixer_data
;
1007 snd_assert(mix
, return);
1009 tumbler_reset_audio(chip
);
1010 if (mix
->i2c
.client
&& mix
->i2c
.init_client
) {
1011 if (mix
->i2c
.init_client(&mix
->i2c
) < 0)
1012 printk(KERN_ERR
"tumbler_init_client error\n");
1014 printk(KERN_ERR
"tumbler: i2c is not initialized\n");
1015 if (chip
->model
== PMAC_TUMBLER
) {
1016 tumbler_set_mono_volume(mix
, &tumbler_pcm_vol_info
);
1017 tumbler_set_mono_volume(mix
, &tumbler_bass_vol_info
);
1018 tumbler_set_mono_volume(mix
, &tumbler_treble_vol_info
);
1019 tumbler_set_drc(mix
);
1021 snapper_set_mix_vol(mix
, VOL_IDX_PCM
);
1022 snapper_set_mix_vol(mix
, VOL_IDX_PCM2
);
1023 snapper_set_mix_vol(mix
, VOL_IDX_ADC
);
1024 tumbler_set_mono_volume(mix
, &snapper_bass_vol_info
);
1025 tumbler_set_mono_volume(mix
, &snapper_treble_vol_info
);
1026 snapper_set_drc(mix
);
1027 snapper_set_capture_source(mix
);
1029 tumbler_set_master_volume(mix
);
1030 if (chip
->update_automute
)
1031 chip
->update_automute(chip
, 0);
1035 /* initialize tumbler */
1036 static int __init
tumbler_init(pmac_t
*chip
)
1039 pmac_tumbler_t
*mix
= chip
->mixer_data
;
1040 snd_assert(mix
, return -EINVAL
);
1042 tumbler_find_device("audio-hw-reset", &mix
->audio_reset
, 0);
1043 tumbler_find_device("amp-mute", &mix
->amp_mute
, 0);
1044 tumbler_find_device("headphone-mute", &mix
->hp_mute
, 0);
1045 irq
= tumbler_find_device("headphone-detect", &mix
->hp_detect
, 0);
1047 irq
= tumbler_find_device("keywest-gpio15", &mix
->hp_detect
, 1);
1049 tumbler_reset_audio(chip
);
1051 /* activate headphone status interrupts */
1054 if ((err
= request_irq(irq
, headphone_intr
, 0,
1055 "Tumbler Headphone Detection", chip
)) < 0)
1057 /* activate headphone status interrupts */
1058 val
= do_gpio_read(&mix
->hp_detect
);
1059 do_gpio_write(&mix
->hp_detect
, val
| 0x80);
1061 mix
->headphone_irq
= irq
;
1066 static void tumbler_cleanup(pmac_t
*chip
)
1068 pmac_tumbler_t
*mix
= chip
->mixer_data
;
1072 if (mix
->headphone_irq
>= 0)
1073 free_irq(mix
->headphone_irq
, chip
);
1074 tumbler_gpio_free(&mix
->audio_reset
);
1075 tumbler_gpio_free(&mix
->amp_mute
);
1076 tumbler_gpio_free(&mix
->hp_mute
);
1077 tumbler_gpio_free(&mix
->hp_detect
);
1078 snd_pmac_keywest_cleanup(&mix
->i2c
);
1080 chip
->mixer_data
= NULL
;
1084 int __init
snd_pmac_tumbler_init(pmac_t
*chip
)
1087 pmac_tumbler_t
*mix
;
1089 struct device_node
*tas_node
;
1093 if (current
->fs
->root
)
1094 request_module("i2c-keywest");
1095 #endif /* CONFIG_KMOD */
1097 mix
= kmalloc(sizeof(*mix
), GFP_KERNEL
);
1100 memset(mix
, 0, sizeof(*mix
));
1101 mix
->headphone_irq
= -1;
1103 chip
->mixer_data
= mix
;
1104 chip
->mixer_free
= tumbler_cleanup
;
1106 if ((err
= tumbler_init(chip
)) < 0)
1110 tas_node
= find_devices("deq");
1111 if (tas_node
== NULL
)
1114 paddr
= (u32
*)get_property(tas_node
, "i2c-address", NULL
);
1116 mix
->i2c
.addr
= (*paddr
) >> 1;
1118 mix
->i2c
.addr
= TAS_I2C_ADDR
;
1120 if (chip
->model
== PMAC_TUMBLER
) {
1121 mix
->i2c
.init_client
= tumbler_init_client
;
1122 mix
->i2c
.name
= "TAS3001c";
1123 chipname
= "Tumbler";
1125 mix
->i2c
.init_client
= snapper_init_client
;
1126 mix
->i2c
.name
= "TAS3004";
1127 chipname
= "Snapper";
1130 if ((err
= snd_pmac_keywest_init(&mix
->i2c
)) < 0)
1136 sprintf(chip
->card
->mixername
, "PowerMac %s", chipname
);
1138 if (chip
->model
== PMAC_TUMBLER
) {
1139 for (i
= 0; i
< ARRAY_SIZE(tumbler_mixers
); i
++) {
1140 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&tumbler_mixers
[i
], chip
))) < 0)
1144 for (i
= 0; i
< ARRAY_SIZE(snapper_mixers
); i
++) {
1145 if ((err
= snd_ctl_add(chip
->card
, snd_ctl_new1(&snapper_mixers
[i
], chip
))) < 0)
1149 chip
->master_sw_ctl
= snd_ctl_new1(&tumbler_hp_sw
, chip
);
1150 if ((err
= snd_ctl_add(chip
->card
, chip
->master_sw_ctl
)) < 0)
1152 chip
->speaker_sw_ctl
= snd_ctl_new1(&tumbler_speaker_sw
, chip
);
1153 if ((err
= snd_ctl_add(chip
->card
, chip
->speaker_sw_ctl
)) < 0)
1155 chip
->drc_sw_ctl
= snd_ctl_new1(&tumbler_drc_sw
, chip
);
1156 if ((err
= snd_ctl_add(chip
->card
, chip
->drc_sw_ctl
)) < 0)
1160 #ifdef CONFIG_PMAC_PBOOK
1161 chip
->resume
= tumbler_resume
;
1164 INIT_WORK(&device_change
, device_change_handler
, (void *)chip
);
1166 #ifdef PMAC_SUPPORT_AUTOMUTE
1167 if (mix
->headphone_irq
>=0 && (err
= snd_pmac_add_automute(chip
)) < 0)
1169 chip
->detect_headphone
= tumbler_detect_headphone
;
1170 chip
->update_automute
= tumbler_update_automute
;
1171 tumbler_update_automute(chip
, 0); /* update the status only */