Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * PMac Tumbler/Snapper lowlevel functions |
| 3 | * |
| 4 | * Copyright (c) by Takashi Iwai <tiwai@suse.de> |
| 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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 |
| 19 | * |
| 20 | * Rene Rebe <rene.rebe@gmx.net>: |
| 21 | * * update from shadow registers on wakeup and headphone plug |
| 22 | * * automatically toggle DRC on headphone plug |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | #include <sound/driver.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/i2c.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/kmod.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/interrupt.h> |
| 34 | #include <sound/core.h> |
| 35 | #include <asm/io.h> |
| 36 | #include <asm/irq.h> |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 37 | #include <asm/machdep.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <asm/pmac_feature.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "pmac.h" |
| 40 | #include "tumbler_volume.h" |
| 41 | |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 42 | #undef DEBUG |
| 43 | |
| 44 | #ifdef DEBUG |
| 45 | #define DBG(fmt...) printk(fmt) |
| 46 | #else |
| 47 | #define DBG(fmt...) |
| 48 | #endif |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | /* i2c address for tumbler */ |
| 51 | #define TAS_I2C_ADDR 0x34 |
| 52 | |
| 53 | /* registers */ |
| 54 | #define TAS_REG_MCS 0x01 /* main control */ |
| 55 | #define TAS_REG_DRC 0x02 |
| 56 | #define TAS_REG_VOL 0x04 |
| 57 | #define TAS_REG_TREBLE 0x05 |
| 58 | #define TAS_REG_BASS 0x06 |
| 59 | #define TAS_REG_INPUT1 0x07 |
| 60 | #define TAS_REG_INPUT2 0x08 |
| 61 | |
| 62 | /* tas3001c */ |
| 63 | #define TAS_REG_PCM TAS_REG_INPUT1 |
| 64 | |
| 65 | /* tas3004 */ |
| 66 | #define TAS_REG_LMIX TAS_REG_INPUT1 |
| 67 | #define TAS_REG_RMIX TAS_REG_INPUT2 |
| 68 | #define TAS_REG_MCS2 0x43 /* main control 2 */ |
| 69 | #define TAS_REG_ACS 0x40 /* analog control */ |
| 70 | |
| 71 | /* mono volumes for tas3001c/tas3004 */ |
| 72 | enum { |
| 73 | VOL_IDX_PCM_MONO, /* tas3001c only */ |
| 74 | VOL_IDX_BASS, VOL_IDX_TREBLE, |
| 75 | VOL_IDX_LAST_MONO |
| 76 | }; |
| 77 | |
| 78 | /* stereo volumes for tas3004 */ |
| 79 | enum { |
| 80 | VOL_IDX_PCM, VOL_IDX_PCM2, VOL_IDX_ADC, |
| 81 | VOL_IDX_LAST_MIX |
| 82 | }; |
| 83 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 84 | struct pmac_gpio { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | unsigned int addr; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 86 | u8 active_val; |
| 87 | u8 inactive_val; |
| 88 | u8 active_state; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 89 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 91 | struct pmac_tumbler { |
| 92 | struct pmac_keywest i2c; |
| 93 | struct pmac_gpio audio_reset; |
| 94 | struct pmac_gpio amp_mute; |
| 95 | struct pmac_gpio line_mute; |
| 96 | struct pmac_gpio line_detect; |
| 97 | struct pmac_gpio hp_mute; |
| 98 | struct pmac_gpio hp_detect; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | int headphone_irq; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 100 | int lineout_irq; |
Colin Leroy | 085e6fc | 2005-05-01 08:58:43 -0700 | [diff] [blame] | 101 | unsigned int save_master_vol[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | unsigned int master_vol[2]; |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 103 | unsigned int save_master_switch[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | unsigned int master_switch[2]; |
| 105 | unsigned int mono_vol[VOL_IDX_LAST_MONO]; |
| 106 | unsigned int mix_vol[VOL_IDX_LAST_MIX][2]; /* stereo volumes for tas3004 */ |
| 107 | int drc_range; |
| 108 | int drc_enable; |
| 109 | int capture_source; |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 110 | int anded_reset; |
| 111 | int auto_mute_notify; |
| 112 | int reset_on_sleep; |
| 113 | u8 acs; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 114 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
| 116 | |
| 117 | /* |
| 118 | */ |
| 119 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 120 | static int send_init_client(struct pmac_keywest *i2c, unsigned int *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | { |
| 122 | while (*regs > 0) { |
| 123 | int err, count = 10; |
| 124 | do { |
| 125 | err = i2c_smbus_write_byte_data(i2c->client, |
| 126 | regs[0], regs[1]); |
| 127 | if (err >= 0) |
| 128 | break; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 129 | DBG("(W) i2c error %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | mdelay(10); |
| 131 | } while (count--); |
| 132 | if (err < 0) |
| 133 | return -ENXIO; |
| 134 | regs += 2; |
| 135 | } |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 140 | static int tumbler_init_client(struct pmac_keywest *i2c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { |
| 142 | static unsigned int regs[] = { |
| 143 | /* normal operation, SCLK=64fps, i2s output, i2s input, 16bit width */ |
| 144 | TAS_REG_MCS, (1<<6)|(2<<4)|(2<<2)|0, |
| 145 | 0, /* terminator */ |
| 146 | }; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 147 | DBG("(I) tumbler init client\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | return send_init_client(i2c, regs); |
| 149 | } |
| 150 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 151 | static int snapper_init_client(struct pmac_keywest *i2c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
| 153 | static unsigned int regs[] = { |
| 154 | /* normal operation, SCLK=64fps, i2s output, 16bit width */ |
| 155 | TAS_REG_MCS, (1<<6)|(2<<4)|0, |
| 156 | /* normal operation, all-pass mode */ |
| 157 | TAS_REG_MCS2, (1<<1), |
| 158 | /* normal output, no deemphasis, A input, power-up, line-in */ |
| 159 | TAS_REG_ACS, 0, |
| 160 | 0, /* terminator */ |
| 161 | }; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 162 | DBG("(I) snapper init client\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | return send_init_client(i2c, regs); |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * gpio access |
| 168 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | #define do_gpio_write(gp, val) \ |
| 170 | pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, (gp)->addr, val) |
| 171 | #define do_gpio_read(gp) \ |
| 172 | pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, (gp)->addr, 0) |
| 173 | #define tumbler_gpio_free(gp) /* NOP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 175 | static void write_audio_gpio(struct pmac_gpio *gp, int active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
| 177 | if (! gp->addr) |
| 178 | return; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 179 | active = active ? gp->active_val : gp->inactive_val; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 180 | do_gpio_write(gp, active); |
| 181 | DBG("(I) gpio %x write %d\n", gp->addr, active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 184 | static int check_audio_gpio(struct pmac_gpio *gp) |
Benjamin Herrenschmidt | 4be8dc7 | 2005-05-01 08:58:43 -0700 | [diff] [blame] | 185 | { |
| 186 | int ret; |
| 187 | |
| 188 | if (! gp->addr) |
| 189 | return 0; |
| 190 | |
| 191 | ret = do_gpio_read(gp); |
| 192 | |
Andreas Schwab | 2fd53a7 | 2006-09-01 17:15:36 +0200 | [diff] [blame] | 193 | return (ret & 0x1) == (gp->active_val & 0x1); |
Benjamin Herrenschmidt | 4be8dc7 | 2005-05-01 08:58:43 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 196 | static int read_audio_gpio(struct pmac_gpio *gp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
| 198 | int ret; |
| 199 | if (! gp->addr) |
| 200 | return 0; |
Andreas Schwab | 2fd53a7 | 2006-09-01 17:15:36 +0200 | [diff] [blame] | 201 | ret = do_gpio_read(gp); |
| 202 | ret = (ret & 0x02) !=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | return ret == gp->active_state; |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * update master volume |
| 208 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 209 | static int tumbler_set_master_volume(struct pmac_tumbler *mix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | { |
| 211 | unsigned char block[6]; |
| 212 | unsigned int left_vol, right_vol; |
| 213 | |
| 214 | if (! mix->i2c.client) |
| 215 | return -ENODEV; |
| 216 | |
| 217 | if (! mix->master_switch[0]) |
| 218 | left_vol = 0; |
| 219 | else { |
| 220 | left_vol = mix->master_vol[0]; |
| 221 | if (left_vol >= ARRAY_SIZE(master_volume_table)) |
| 222 | left_vol = ARRAY_SIZE(master_volume_table) - 1; |
| 223 | left_vol = master_volume_table[left_vol]; |
| 224 | } |
| 225 | if (! mix->master_switch[1]) |
| 226 | right_vol = 0; |
| 227 | else { |
| 228 | right_vol = mix->master_vol[1]; |
| 229 | if (right_vol >= ARRAY_SIZE(master_volume_table)) |
| 230 | right_vol = ARRAY_SIZE(master_volume_table) - 1; |
| 231 | right_vol = master_volume_table[right_vol]; |
| 232 | } |
| 233 | |
| 234 | block[0] = (left_vol >> 16) & 0xff; |
| 235 | block[1] = (left_vol >> 8) & 0xff; |
| 236 | block[2] = (left_vol >> 0) & 0xff; |
| 237 | |
| 238 | block[3] = (right_vol >> 16) & 0xff; |
| 239 | block[4] = (right_vol >> 8) & 0xff; |
| 240 | block[5] = (right_vol >> 0) & 0xff; |
| 241 | |
Benjamin Herrenschmidt | 367636e | 2006-02-08 15:04:18 +1100 | [diff] [blame] | 242 | if (i2c_smbus_write_i2c_block_data(mix->i2c.client, TAS_REG_VOL, 6, |
| 243 | block) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | snd_printk("failed to set volume \n"); |
| 245 | return -EINVAL; |
| 246 | } |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | |
| 251 | /* output volume */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 252 | static int tumbler_info_master_volume(struct snd_kcontrol *kcontrol, |
| 253 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
| 255 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 256 | uinfo->count = 2; |
| 257 | uinfo->value.integer.min = 0; |
| 258 | uinfo->value.integer.max = ARRAY_SIZE(master_volume_table) - 1; |
| 259 | return 0; |
| 260 | } |
| 261 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 262 | static int tumbler_get_master_volume(struct snd_kcontrol *kcontrol, |
| 263 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 265 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 266 | struct pmac_tumbler *mix = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | snd_assert(mix, return -ENODEV); |
| 268 | ucontrol->value.integer.value[0] = mix->master_vol[0]; |
| 269 | ucontrol->value.integer.value[1] = mix->master_vol[1]; |
| 270 | return 0; |
| 271 | } |
| 272 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 273 | static int tumbler_put_master_volume(struct snd_kcontrol *kcontrol, |
| 274 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 276 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 277 | struct pmac_tumbler *mix = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | int change; |
| 279 | |
| 280 | snd_assert(mix, return -ENODEV); |
| 281 | change = mix->master_vol[0] != ucontrol->value.integer.value[0] || |
| 282 | mix->master_vol[1] != ucontrol->value.integer.value[1]; |
| 283 | if (change) { |
| 284 | mix->master_vol[0] = ucontrol->value.integer.value[0]; |
| 285 | mix->master_vol[1] = ucontrol->value.integer.value[1]; |
| 286 | tumbler_set_master_volume(mix); |
| 287 | } |
| 288 | return change; |
| 289 | } |
| 290 | |
| 291 | /* output switch */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 292 | static int tumbler_get_master_switch(struct snd_kcontrol *kcontrol, |
| 293 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 295 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 296 | struct pmac_tumbler *mix = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | snd_assert(mix, return -ENODEV); |
| 298 | ucontrol->value.integer.value[0] = mix->master_switch[0]; |
| 299 | ucontrol->value.integer.value[1] = mix->master_switch[1]; |
| 300 | return 0; |
| 301 | } |
| 302 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 303 | static int tumbler_put_master_switch(struct snd_kcontrol *kcontrol, |
| 304 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 306 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 307 | struct pmac_tumbler *mix = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | int change; |
| 309 | |
| 310 | snd_assert(mix, return -ENODEV); |
| 311 | change = mix->master_switch[0] != ucontrol->value.integer.value[0] || |
| 312 | mix->master_switch[1] != ucontrol->value.integer.value[1]; |
| 313 | if (change) { |
| 314 | mix->master_switch[0] = !!ucontrol->value.integer.value[0]; |
| 315 | mix->master_switch[1] = !!ucontrol->value.integer.value[1]; |
| 316 | tumbler_set_master_volume(mix); |
| 317 | } |
| 318 | return change; |
| 319 | } |
| 320 | |
| 321 | |
| 322 | /* |
| 323 | * TAS3001c dynamic range compression |
| 324 | */ |
| 325 | |
| 326 | #define TAS3001_DRC_MAX 0x5f |
| 327 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 328 | static int tumbler_set_drc(struct pmac_tumbler *mix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
| 330 | unsigned char val[2]; |
| 331 | |
| 332 | if (! mix->i2c.client) |
| 333 | return -ENODEV; |
| 334 | |
| 335 | if (mix->drc_enable) { |
| 336 | val[0] = 0xc1; /* enable, 3:1 compression */ |
| 337 | if (mix->drc_range > TAS3001_DRC_MAX) |
| 338 | val[1] = 0xf0; |
| 339 | else if (mix->drc_range < 0) |
| 340 | val[1] = 0x91; |
| 341 | else |
| 342 | val[1] = mix->drc_range + 0x91; |
| 343 | } else { |
| 344 | val[0] = 0; |
| 345 | val[1] = 0; |
| 346 | } |
| 347 | |
Benjamin Herrenschmidt | 367636e | 2006-02-08 15:04:18 +1100 | [diff] [blame] | 348 | if (i2c_smbus_write_i2c_block_data(mix->i2c.client, TAS_REG_DRC, |
| 349 | 2, val) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | snd_printk("failed to set DRC\n"); |
| 351 | return -EINVAL; |
| 352 | } |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | /* |
| 357 | * TAS3004 |
| 358 | */ |
| 359 | |
| 360 | #define TAS3004_DRC_MAX 0xef |
| 361 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 362 | static int snapper_set_drc(struct pmac_tumbler *mix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { |
| 364 | unsigned char val[6]; |
| 365 | |
| 366 | if (! mix->i2c.client) |
| 367 | return -ENODEV; |
| 368 | |
| 369 | if (mix->drc_enable) |
| 370 | val[0] = 0x50; /* 3:1 above threshold */ |
| 371 | else |
| 372 | val[0] = 0x51; /* disabled */ |
| 373 | val[1] = 0x02; /* 1:1 below threshold */ |
| 374 | if (mix->drc_range > 0xef) |
| 375 | val[2] = 0xef; |
| 376 | else if (mix->drc_range < 0) |
| 377 | val[2] = 0x00; |
| 378 | else |
| 379 | val[2] = mix->drc_range; |
| 380 | val[3] = 0xb0; |
| 381 | val[4] = 0x60; |
| 382 | val[5] = 0xa0; |
| 383 | |
Benjamin Herrenschmidt | 367636e | 2006-02-08 15:04:18 +1100 | [diff] [blame] | 384 | if (i2c_smbus_write_i2c_block_data(mix->i2c.client, TAS_REG_DRC, |
| 385 | 6, val) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | snd_printk("failed to set DRC\n"); |
| 387 | return -EINVAL; |
| 388 | } |
| 389 | return 0; |
| 390 | } |
| 391 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 392 | static int tumbler_info_drc_value(struct snd_kcontrol *kcontrol, |
| 393 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 395 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 397 | uinfo->count = 1; |
| 398 | uinfo->value.integer.min = 0; |
| 399 | uinfo->value.integer.max = |
| 400 | chip->model == PMAC_TUMBLER ? TAS3001_DRC_MAX : TAS3004_DRC_MAX; |
| 401 | return 0; |
| 402 | } |
| 403 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 404 | static int tumbler_get_drc_value(struct snd_kcontrol *kcontrol, |
| 405 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 407 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 408 | struct pmac_tumbler *mix; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | if (! (mix = chip->mixer_data)) |
| 410 | return -ENODEV; |
| 411 | ucontrol->value.integer.value[0] = mix->drc_range; |
| 412 | return 0; |
| 413 | } |
| 414 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 415 | static int tumbler_put_drc_value(struct snd_kcontrol *kcontrol, |
| 416 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 418 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 419 | struct pmac_tumbler *mix; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | int change; |
| 421 | |
| 422 | if (! (mix = chip->mixer_data)) |
| 423 | return -ENODEV; |
| 424 | change = mix->drc_range != ucontrol->value.integer.value[0]; |
| 425 | if (change) { |
| 426 | mix->drc_range = ucontrol->value.integer.value[0]; |
| 427 | if (chip->model == PMAC_TUMBLER) |
| 428 | tumbler_set_drc(mix); |
| 429 | else |
| 430 | snapper_set_drc(mix); |
| 431 | } |
| 432 | return change; |
| 433 | } |
| 434 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 435 | static int tumbler_get_drc_switch(struct snd_kcontrol *kcontrol, |
| 436 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 438 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 439 | struct pmac_tumbler *mix; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | if (! (mix = chip->mixer_data)) |
| 441 | return -ENODEV; |
| 442 | ucontrol->value.integer.value[0] = mix->drc_enable; |
| 443 | return 0; |
| 444 | } |
| 445 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 446 | static int tumbler_put_drc_switch(struct snd_kcontrol *kcontrol, |
| 447 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 449 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 450 | struct pmac_tumbler *mix; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | int change; |
| 452 | |
| 453 | if (! (mix = chip->mixer_data)) |
| 454 | return -ENODEV; |
| 455 | change = mix->drc_enable != ucontrol->value.integer.value[0]; |
| 456 | if (change) { |
| 457 | mix->drc_enable = !!ucontrol->value.integer.value[0]; |
| 458 | if (chip->model == PMAC_TUMBLER) |
| 459 | tumbler_set_drc(mix); |
| 460 | else |
| 461 | snapper_set_drc(mix); |
| 462 | } |
| 463 | return change; |
| 464 | } |
| 465 | |
| 466 | |
| 467 | /* |
| 468 | * mono volumes |
| 469 | */ |
| 470 | |
| 471 | struct tumbler_mono_vol { |
| 472 | int index; |
| 473 | int reg; |
| 474 | int bytes; |
| 475 | unsigned int max; |
| 476 | unsigned int *table; |
| 477 | }; |
| 478 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 479 | static int tumbler_set_mono_volume(struct pmac_tumbler *mix, |
| 480 | struct tumbler_mono_vol *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | { |
| 482 | unsigned char block[4]; |
| 483 | unsigned int vol; |
| 484 | int i; |
| 485 | |
| 486 | if (! mix->i2c.client) |
| 487 | return -ENODEV; |
| 488 | |
| 489 | vol = mix->mono_vol[info->index]; |
| 490 | if (vol >= info->max) |
| 491 | vol = info->max - 1; |
| 492 | vol = info->table[vol]; |
| 493 | for (i = 0; i < info->bytes; i++) |
| 494 | block[i] = (vol >> ((info->bytes - i - 1) * 8)) & 0xff; |
Benjamin Herrenschmidt | 367636e | 2006-02-08 15:04:18 +1100 | [diff] [blame] | 495 | if (i2c_smbus_write_i2c_block_data(mix->i2c.client, info->reg, |
| 496 | info->bytes, block) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | snd_printk("failed to set mono volume %d\n", info->index); |
| 498 | return -EINVAL; |
| 499 | } |
| 500 | return 0; |
| 501 | } |
| 502 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 503 | static int tumbler_info_mono(struct snd_kcontrol *kcontrol, |
| 504 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | { |
| 506 | struct tumbler_mono_vol *info = (struct tumbler_mono_vol *)kcontrol->private_value; |
| 507 | |
| 508 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 509 | uinfo->count = 1; |
| 510 | uinfo->value.integer.min = 0; |
| 511 | uinfo->value.integer.max = info->max - 1; |
| 512 | return 0; |
| 513 | } |
| 514 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 515 | static int tumbler_get_mono(struct snd_kcontrol *kcontrol, |
| 516 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | { |
| 518 | struct tumbler_mono_vol *info = (struct tumbler_mono_vol *)kcontrol->private_value; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 519 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 520 | struct pmac_tumbler *mix; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | if (! (mix = chip->mixer_data)) |
| 522 | return -ENODEV; |
| 523 | ucontrol->value.integer.value[0] = mix->mono_vol[info->index]; |
| 524 | return 0; |
| 525 | } |
| 526 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 527 | static int tumbler_put_mono(struct snd_kcontrol *kcontrol, |
| 528 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | { |
| 530 | struct tumbler_mono_vol *info = (struct tumbler_mono_vol *)kcontrol->private_value; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 531 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 532 | struct pmac_tumbler *mix; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | int change; |
| 534 | |
| 535 | if (! (mix = chip->mixer_data)) |
| 536 | return -ENODEV; |
| 537 | change = mix->mono_vol[info->index] != ucontrol->value.integer.value[0]; |
| 538 | if (change) { |
| 539 | mix->mono_vol[info->index] = ucontrol->value.integer.value[0]; |
| 540 | tumbler_set_mono_volume(mix, info); |
| 541 | } |
| 542 | return change; |
| 543 | } |
| 544 | |
| 545 | /* TAS3001c mono volumes */ |
| 546 | static struct tumbler_mono_vol tumbler_pcm_vol_info = { |
| 547 | .index = VOL_IDX_PCM_MONO, |
| 548 | .reg = TAS_REG_PCM, |
| 549 | .bytes = 3, |
| 550 | .max = ARRAY_SIZE(mixer_volume_table), |
| 551 | .table = mixer_volume_table, |
| 552 | }; |
| 553 | |
| 554 | static struct tumbler_mono_vol tumbler_bass_vol_info = { |
| 555 | .index = VOL_IDX_BASS, |
| 556 | .reg = TAS_REG_BASS, |
| 557 | .bytes = 1, |
| 558 | .max = ARRAY_SIZE(bass_volume_table), |
| 559 | .table = bass_volume_table, |
| 560 | }; |
| 561 | |
| 562 | static struct tumbler_mono_vol tumbler_treble_vol_info = { |
| 563 | .index = VOL_IDX_TREBLE, |
| 564 | .reg = TAS_REG_TREBLE, |
| 565 | .bytes = 1, |
| 566 | .max = ARRAY_SIZE(treble_volume_table), |
| 567 | .table = treble_volume_table, |
| 568 | }; |
| 569 | |
| 570 | /* TAS3004 mono volumes */ |
| 571 | static struct tumbler_mono_vol snapper_bass_vol_info = { |
| 572 | .index = VOL_IDX_BASS, |
| 573 | .reg = TAS_REG_BASS, |
| 574 | .bytes = 1, |
| 575 | .max = ARRAY_SIZE(snapper_bass_volume_table), |
| 576 | .table = snapper_bass_volume_table, |
| 577 | }; |
| 578 | |
| 579 | static struct tumbler_mono_vol snapper_treble_vol_info = { |
| 580 | .index = VOL_IDX_TREBLE, |
| 581 | .reg = TAS_REG_TREBLE, |
| 582 | .bytes = 1, |
| 583 | .max = ARRAY_SIZE(snapper_treble_volume_table), |
| 584 | .table = snapper_treble_volume_table, |
| 585 | }; |
| 586 | |
| 587 | |
| 588 | #define DEFINE_MONO(xname,type) { \ |
| 589 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\ |
| 590 | .name = xname, \ |
| 591 | .info = tumbler_info_mono, \ |
| 592 | .get = tumbler_get_mono, \ |
| 593 | .put = tumbler_put_mono, \ |
| 594 | .private_value = (unsigned long)(&tumbler_##type##_vol_info), \ |
| 595 | } |
| 596 | |
| 597 | #define DEFINE_SNAPPER_MONO(xname,type) { \ |
| 598 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\ |
| 599 | .name = xname, \ |
| 600 | .info = tumbler_info_mono, \ |
| 601 | .get = tumbler_get_mono, \ |
| 602 | .put = tumbler_put_mono, \ |
| 603 | .private_value = (unsigned long)(&snapper_##type##_vol_info), \ |
| 604 | } |
| 605 | |
| 606 | |
| 607 | /* |
| 608 | * snapper mixer volumes |
| 609 | */ |
| 610 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 611 | static int snapper_set_mix_vol1(struct pmac_tumbler *mix, int idx, int ch, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | { |
| 613 | int i, j, vol; |
| 614 | unsigned char block[9]; |
| 615 | |
| 616 | vol = mix->mix_vol[idx][ch]; |
| 617 | if (vol >= ARRAY_SIZE(mixer_volume_table)) { |
| 618 | vol = ARRAY_SIZE(mixer_volume_table) - 1; |
| 619 | mix->mix_vol[idx][ch] = vol; |
| 620 | } |
| 621 | |
| 622 | for (i = 0; i < 3; i++) { |
| 623 | vol = mix->mix_vol[i][ch]; |
| 624 | vol = mixer_volume_table[vol]; |
| 625 | for (j = 0; j < 3; j++) |
| 626 | block[i * 3 + j] = (vol >> ((2 - j) * 8)) & 0xff; |
| 627 | } |
Benjamin Herrenschmidt | 367636e | 2006-02-08 15:04:18 +1100 | [diff] [blame] | 628 | if (i2c_smbus_write_i2c_block_data(mix->i2c.client, reg, |
| 629 | 9, block) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | snd_printk("failed to set mono volume %d\n", reg); |
| 631 | return -EINVAL; |
| 632 | } |
| 633 | return 0; |
| 634 | } |
| 635 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 636 | static int snapper_set_mix_vol(struct pmac_tumbler *mix, int idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | { |
| 638 | if (! mix->i2c.client) |
| 639 | return -ENODEV; |
| 640 | if (snapper_set_mix_vol1(mix, idx, 0, TAS_REG_LMIX) < 0 || |
| 641 | snapper_set_mix_vol1(mix, idx, 1, TAS_REG_RMIX) < 0) |
| 642 | return -EINVAL; |
| 643 | return 0; |
| 644 | } |
| 645 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 646 | static int snapper_info_mix(struct snd_kcontrol *kcontrol, |
| 647 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | { |
| 649 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 650 | uinfo->count = 2; |
| 651 | uinfo->value.integer.min = 0; |
| 652 | uinfo->value.integer.max = ARRAY_SIZE(mixer_volume_table) - 1; |
| 653 | return 0; |
| 654 | } |
| 655 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 656 | static int snapper_get_mix(struct snd_kcontrol *kcontrol, |
| 657 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | { |
| 659 | int idx = (int)kcontrol->private_value; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 660 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 661 | struct pmac_tumbler *mix; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | if (! (mix = chip->mixer_data)) |
| 663 | return -ENODEV; |
| 664 | ucontrol->value.integer.value[0] = mix->mix_vol[idx][0]; |
| 665 | ucontrol->value.integer.value[1] = mix->mix_vol[idx][1]; |
| 666 | return 0; |
| 667 | } |
| 668 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 669 | static int snapper_put_mix(struct snd_kcontrol *kcontrol, |
| 670 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | { |
| 672 | int idx = (int)kcontrol->private_value; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 673 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 674 | struct pmac_tumbler *mix; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | int change; |
| 676 | |
| 677 | if (! (mix = chip->mixer_data)) |
| 678 | return -ENODEV; |
| 679 | change = mix->mix_vol[idx][0] != ucontrol->value.integer.value[0] || |
| 680 | mix->mix_vol[idx][1] != ucontrol->value.integer.value[1]; |
| 681 | if (change) { |
| 682 | mix->mix_vol[idx][0] = ucontrol->value.integer.value[0]; |
| 683 | mix->mix_vol[idx][1] = ucontrol->value.integer.value[1]; |
| 684 | snapper_set_mix_vol(mix, idx); |
| 685 | } |
| 686 | return change; |
| 687 | } |
| 688 | |
| 689 | |
| 690 | /* |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 691 | * mute switches. FIXME: Turn that into software mute when both outputs are muted |
| 692 | * to avoid codec reset on ibook M7 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | */ |
| 694 | |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 695 | enum { TUMBLER_MUTE_HP, TUMBLER_MUTE_AMP, TUMBLER_MUTE_LINE }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 697 | static int tumbler_get_mute_switch(struct snd_kcontrol *kcontrol, |
| 698 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 700 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 701 | struct pmac_tumbler *mix; |
| 702 | struct pmac_gpio *gp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | if (! (mix = chip->mixer_data)) |
| 704 | return -ENODEV; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 705 | switch(kcontrol->private_value) { |
| 706 | case TUMBLER_MUTE_HP: |
| 707 | gp = &mix->hp_mute; break; |
| 708 | case TUMBLER_MUTE_AMP: |
| 709 | gp = &mix->amp_mute; break; |
| 710 | case TUMBLER_MUTE_LINE: |
| 711 | gp = &mix->line_mute; break; |
| 712 | default: |
| 713 | gp = NULL; |
| 714 | } |
| 715 | if (gp == NULL) |
| 716 | return -EINVAL; |
Benjamin Herrenschmidt | 4be8dc7 | 2005-05-01 08:58:43 -0700 | [diff] [blame] | 717 | ucontrol->value.integer.value[0] = !check_audio_gpio(gp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | return 0; |
| 719 | } |
| 720 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 721 | static int tumbler_put_mute_switch(struct snd_kcontrol *kcontrol, |
| 722 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 724 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 725 | struct pmac_tumbler *mix; |
| 726 | struct pmac_gpio *gp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | int val; |
| 728 | #ifdef PMAC_SUPPORT_AUTOMUTE |
| 729 | if (chip->update_automute && chip->auto_mute) |
| 730 | return 0; /* don't touch in the auto-mute mode */ |
| 731 | #endif |
| 732 | if (! (mix = chip->mixer_data)) |
| 733 | return -ENODEV; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 734 | switch(kcontrol->private_value) { |
| 735 | case TUMBLER_MUTE_HP: |
| 736 | gp = &mix->hp_mute; break; |
| 737 | case TUMBLER_MUTE_AMP: |
| 738 | gp = &mix->amp_mute; break; |
| 739 | case TUMBLER_MUTE_LINE: |
| 740 | gp = &mix->line_mute; break; |
| 741 | default: |
| 742 | gp = NULL; |
| 743 | } |
| 744 | if (gp == NULL) |
| 745 | return -EINVAL; |
Benjamin Herrenschmidt | 4be8dc7 | 2005-05-01 08:58:43 -0700 | [diff] [blame] | 746 | val = ! check_audio_gpio(gp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | if (val != ucontrol->value.integer.value[0]) { |
| 748 | write_audio_gpio(gp, ! ucontrol->value.integer.value[0]); |
| 749 | return 1; |
| 750 | } |
| 751 | return 0; |
| 752 | } |
| 753 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 754 | static int snapper_set_capture_source(struct pmac_tumbler *mix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | { |
| 756 | if (! mix->i2c.client) |
| 757 | return -ENODEV; |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 758 | if (mix->capture_source) |
| 759 | mix->acs = mix->acs |= 2; |
| 760 | else |
| 761 | mix->acs &= ~2; |
| 762 | return i2c_smbus_write_byte_data(mix->i2c.client, TAS_REG_ACS, mix->acs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 765 | static int snapper_info_capture_source(struct snd_kcontrol *kcontrol, |
| 766 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | { |
| 768 | static char *texts[2] = { |
| 769 | "Line", "Mic" |
| 770 | }; |
| 771 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 772 | uinfo->count = 1; |
| 773 | uinfo->value.enumerated.items = 2; |
| 774 | if (uinfo->value.enumerated.item > 1) |
| 775 | uinfo->value.enumerated.item = 1; |
| 776 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 777 | return 0; |
| 778 | } |
| 779 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 780 | static int snapper_get_capture_source(struct snd_kcontrol *kcontrol, |
| 781 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 783 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 784 | struct pmac_tumbler *mix = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
| 786 | snd_assert(mix, return -ENODEV); |
| 787 | ucontrol->value.integer.value[0] = mix->capture_source; |
| 788 | return 0; |
| 789 | } |
| 790 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 791 | static int snapper_put_capture_source(struct snd_kcontrol *kcontrol, |
| 792 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 794 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 795 | struct pmac_tumbler *mix = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | int change; |
| 797 | |
| 798 | snd_assert(mix, return -ENODEV); |
| 799 | change = ucontrol->value.integer.value[0] != mix->capture_source; |
| 800 | if (change) { |
| 801 | mix->capture_source = !!ucontrol->value.integer.value[0]; |
| 802 | snapper_set_capture_source(mix); |
| 803 | } |
| 804 | return change; |
| 805 | } |
| 806 | |
| 807 | #define DEFINE_SNAPPER_MIX(xname,idx,ofs) { \ |
| 808 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\ |
| 809 | .name = xname, \ |
| 810 | .info = snapper_info_mix, \ |
| 811 | .get = snapper_get_mix, \ |
| 812 | .put = snapper_put_mix, \ |
| 813 | .index = idx,\ |
| 814 | .private_value = ofs, \ |
| 815 | } |
| 816 | |
| 817 | |
| 818 | /* |
| 819 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 820 | static struct snd_kcontrol_new tumbler_mixers[] __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 822 | .name = "Master Playback Volume", |
| 823 | .info = tumbler_info_master_volume, |
| 824 | .get = tumbler_get_master_volume, |
| 825 | .put = tumbler_put_master_volume |
| 826 | }, |
| 827 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 828 | .name = "Master Playback Switch", |
| 829 | .info = snd_pmac_boolean_stereo_info, |
| 830 | .get = tumbler_get_master_switch, |
| 831 | .put = tumbler_put_master_switch |
| 832 | }, |
| 833 | DEFINE_MONO("Tone Control - Bass", bass), |
| 834 | DEFINE_MONO("Tone Control - Treble", treble), |
| 835 | DEFINE_MONO("PCM Playback Volume", pcm), |
| 836 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 837 | .name = "DRC Range", |
| 838 | .info = tumbler_info_drc_value, |
| 839 | .get = tumbler_get_drc_value, |
| 840 | .put = tumbler_put_drc_value |
| 841 | }, |
| 842 | }; |
| 843 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 844 | static struct snd_kcontrol_new snapper_mixers[] __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 846 | .name = "Master Playback Volume", |
| 847 | .info = tumbler_info_master_volume, |
| 848 | .get = tumbler_get_master_volume, |
| 849 | .put = tumbler_put_master_volume |
| 850 | }, |
| 851 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 852 | .name = "Master Playback Switch", |
| 853 | .info = snd_pmac_boolean_stereo_info, |
| 854 | .get = tumbler_get_master_switch, |
| 855 | .put = tumbler_put_master_switch |
| 856 | }, |
| 857 | DEFINE_SNAPPER_MIX("PCM Playback Volume", 0, VOL_IDX_PCM), |
| 858 | DEFINE_SNAPPER_MIX("PCM Playback Volume", 1, VOL_IDX_PCM2), |
| 859 | DEFINE_SNAPPER_MIX("Monitor Mix Volume", 0, VOL_IDX_ADC), |
| 860 | DEFINE_SNAPPER_MONO("Tone Control - Bass", bass), |
| 861 | DEFINE_SNAPPER_MONO("Tone Control - Treble", treble), |
| 862 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 863 | .name = "DRC Range", |
| 864 | .info = tumbler_info_drc_value, |
| 865 | .get = tumbler_get_drc_value, |
| 866 | .put = tumbler_put_drc_value |
| 867 | }, |
| 868 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 869 | .name = "Input Source", /* FIXME: "Capture Source" doesn't work properly */ |
| 870 | .info = snapper_info_capture_source, |
| 871 | .get = snapper_get_capture_source, |
| 872 | .put = snapper_put_capture_source |
| 873 | }, |
| 874 | }; |
| 875 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 876 | static struct snd_kcontrol_new tumbler_hp_sw __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 878 | .name = "Headphone Playback Switch", |
| 879 | .info = snd_pmac_boolean_mono_info, |
| 880 | .get = tumbler_get_mute_switch, |
| 881 | .put = tumbler_put_mute_switch, |
| 882 | .private_value = TUMBLER_MUTE_HP, |
| 883 | }; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 884 | static struct snd_kcontrol_new tumbler_speaker_sw __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 886 | .name = "PC Speaker Playback Switch", |
| 887 | .info = snd_pmac_boolean_mono_info, |
| 888 | .get = tumbler_get_mute_switch, |
| 889 | .put = tumbler_put_mute_switch, |
| 890 | .private_value = TUMBLER_MUTE_AMP, |
| 891 | }; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 892 | static struct snd_kcontrol_new tumbler_lineout_sw __initdata = { |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 893 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 894 | .name = "Line Out Playback Switch", |
| 895 | .info = snd_pmac_boolean_mono_info, |
| 896 | .get = tumbler_get_mute_switch, |
| 897 | .put = tumbler_put_mute_switch, |
| 898 | .private_value = TUMBLER_MUTE_LINE, |
| 899 | }; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 900 | static struct snd_kcontrol_new tumbler_drc_sw __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 902 | .name = "DRC Switch", |
| 903 | .info = snd_pmac_boolean_mono_info, |
| 904 | .get = tumbler_get_drc_switch, |
| 905 | .put = tumbler_put_drc_switch |
| 906 | }; |
| 907 | |
| 908 | |
| 909 | #ifdef PMAC_SUPPORT_AUTOMUTE |
| 910 | /* |
| 911 | * auto-mute stuffs |
| 912 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 913 | static int tumbler_detect_headphone(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 915 | struct pmac_tumbler *mix = chip->mixer_data; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 916 | int detect = 0; |
| 917 | |
| 918 | if (mix->hp_detect.addr) |
| 919 | detect |= read_audio_gpio(&mix->hp_detect); |
| 920 | return detect; |
| 921 | } |
| 922 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 923 | static int tumbler_detect_lineout(struct snd_pmac *chip) |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 924 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 925 | struct pmac_tumbler *mix = chip->mixer_data; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 926 | int detect = 0; |
| 927 | |
| 928 | if (mix->line_detect.addr) |
| 929 | detect |= read_audio_gpio(&mix->line_detect); |
| 930 | return detect; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | } |
| 932 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 933 | static void check_mute(struct snd_pmac *chip, struct pmac_gpio *gp, int val, int do_notify, |
| 934 | struct snd_kcontrol *sw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | { |
Benjamin Herrenschmidt | 4be8dc7 | 2005-05-01 08:58:43 -0700 | [diff] [blame] | 936 | if (check_audio_gpio(gp) != val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | write_audio_gpio(gp, val); |
| 938 | if (do_notify) |
Benjamin Herrenschmidt | 4be8dc7 | 2005-05-01 08:58:43 -0700 | [diff] [blame] | 939 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 940 | &sw->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | } |
| 942 | } |
| 943 | |
| 944 | static struct work_struct device_change; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 945 | static struct snd_pmac *device_change_chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 947 | static void device_change_handler(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 949 | struct snd_pmac *chip = device_change_chip; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 950 | struct pmac_tumbler *mix; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 951 | int headphone, lineout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
| 953 | if (!chip) |
| 954 | return; |
| 955 | |
| 956 | mix = chip->mixer_data; |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 957 | snd_assert(mix, return); |
| 958 | |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 959 | headphone = tumbler_detect_headphone(chip); |
| 960 | lineout = tumbler_detect_lineout(chip); |
| 961 | |
| 962 | DBG("headphone: %d, lineout: %d\n", headphone, lineout); |
| 963 | |
| 964 | if (headphone || lineout) { |
| 965 | /* unmute headphone/lineout & mute speaker */ |
| 966 | if (headphone) |
| 967 | check_mute(chip, &mix->hp_mute, 0, mix->auto_mute_notify, |
| 968 | chip->master_sw_ctl); |
| 969 | if (lineout && mix->line_mute.addr != 0) |
| 970 | check_mute(chip, &mix->line_mute, 0, mix->auto_mute_notify, |
| 971 | chip->lineout_sw_ctl); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 972 | if (mix->anded_reset) |
Nishanth Aravamudan | 989a0b2 | 2005-07-09 10:53:24 +0200 | [diff] [blame] | 973 | msleep(10); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 974 | check_mute(chip, &mix->amp_mute, 1, mix->auto_mute_notify, |
| 975 | chip->speaker_sw_ctl); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 976 | } else { |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 977 | /* unmute speaker, mute others */ |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 978 | check_mute(chip, &mix->amp_mute, 0, mix->auto_mute_notify, |
| 979 | chip->speaker_sw_ctl); |
| 980 | if (mix->anded_reset) |
Nishanth Aravamudan | 989a0b2 | 2005-07-09 10:53:24 +0200 | [diff] [blame] | 981 | msleep(10); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 982 | check_mute(chip, &mix->hp_mute, 1, mix->auto_mute_notify, |
| 983 | chip->master_sw_ctl); |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 984 | if (mix->line_mute.addr != 0) |
| 985 | check_mute(chip, &mix->line_mute, 1, mix->auto_mute_notify, |
| 986 | chip->lineout_sw_ctl); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 987 | } |
Takashi Iwai | f328385 | 2005-09-07 17:08:40 +0200 | [diff] [blame] | 988 | if (mix->auto_mute_notify) |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 989 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 990 | &chip->hp_detect_ctl->id); |
Takashi Iwai | f328385 | 2005-09-07 17:08:40 +0200 | [diff] [blame] | 991 | |
| 992 | #ifdef CONFIG_SND_POWERMAC_AUTO_DRC |
| 993 | mix->drc_enable = ! (headphone || lineout); |
| 994 | if (mix->auto_mute_notify) |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 995 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 996 | &chip->drc_sw_ctl->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | if (chip->model == PMAC_TUMBLER) |
| 998 | tumbler_set_drc(mix); |
| 999 | else |
| 1000 | snapper_set_drc(mix); |
Takashi Iwai | f328385 | 2005-09-07 17:08:40 +0200 | [diff] [blame] | 1001 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
| 1003 | /* reset the master volume so the correct amplification is applied */ |
| 1004 | tumbler_set_master_volume(mix); |
| 1005 | } |
| 1006 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1007 | static void tumbler_update_automute(struct snd_pmac *chip, int do_notify) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | { |
| 1009 | if (chip->auto_mute) { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1010 | struct pmac_tumbler *mix; |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1011 | mix = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | snd_assert(mix, return); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1013 | mix->auto_mute_notify = do_notify; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | schedule_work(&device_change); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | #endif /* PMAC_SUPPORT_AUTOMUTE */ |
| 1018 | |
| 1019 | |
| 1020 | /* interrupt - headphone plug changed */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1021 | static irqreturn_t headphone_intr(int irq, void *devid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1023 | struct snd_pmac *chip = devid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | if (chip->update_automute && chip->initialized) { |
| 1025 | chip->update_automute(chip, 1); |
| 1026 | return IRQ_HANDLED; |
| 1027 | } |
| 1028 | return IRQ_NONE; |
| 1029 | } |
| 1030 | |
| 1031 | /* look for audio-gpio device */ |
| 1032 | static struct device_node *find_audio_device(const char *name) |
| 1033 | { |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1034 | struct device_node *gpiop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | struct device_node *np; |
| 1036 | |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1037 | gpiop = of_find_node_by_name(NULL, "gpio"); |
| 1038 | if (! gpiop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | return NULL; |
| 1040 | |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1041 | for (np = of_get_next_child(gpiop, NULL); np; |
| 1042 | np = of_get_next_child(gpiop, np)) { |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 1043 | const char *property = of_get_property(np, "audio-gpio", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | if (property && strcmp(property, name) == 0) |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1045 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | } |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1047 | of_node_put(gpiop); |
| 1048 | return np; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | /* look for audio-gpio device */ |
| 1052 | static struct device_node *find_compatible_audio_device(const char *name) |
| 1053 | { |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1054 | struct device_node *gpiop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | struct device_node *np; |
| 1056 | |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1057 | gpiop = of_find_node_by_name(NULL, "gpio"); |
| 1058 | if (!gpiop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | return NULL; |
| 1060 | |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1061 | for (np = of_get_next_child(gpiop, NULL); np; |
| 1062 | np = of_get_next_child(gpiop, np)) { |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 1063 | if (of_device_is_compatible(np, name)) |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1064 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | } |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1066 | of_node_put(gpiop); |
| 1067 | return np; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | /* find an audio device and get its address */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1071 | static long tumbler_find_device(const char *device, const char *platform, |
| 1072 | struct pmac_gpio *gp, int is_compatible) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | { |
| 1074 | struct device_node *node; |
Jeremy Kerr | abddd18 | 2006-07-12 15:41:18 +1000 | [diff] [blame] | 1075 | const u32 *base; |
| 1076 | u32 addr; |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1077 | long ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
| 1079 | if (is_compatible) |
| 1080 | node = find_compatible_audio_device(device); |
| 1081 | else |
| 1082 | node = find_audio_device(device); |
| 1083 | if (! node) { |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1084 | DBG("(W) cannot find audio device %s !\n", device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | snd_printdd("cannot find device %s\n", device); |
| 1086 | return -ENODEV; |
| 1087 | } |
| 1088 | |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 1089 | base = of_get_property(node, "AAPL,address", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | if (! base) { |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 1091 | base = of_get_property(node, "reg", NULL); |
Benjamin Herrenschmidt | b75550e | 2005-04-16 15:24:31 -0700 | [diff] [blame] | 1092 | if (!base) { |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1093 | DBG("(E) cannot find address for device %s !\n", device); |
Benjamin Herrenschmidt | b75550e | 2005-04-16 15:24:31 -0700 | [diff] [blame] | 1094 | snd_printd("cannot find address for device %s\n", device); |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1095 | of_node_put(node); |
Benjamin Herrenschmidt | b75550e | 2005-04-16 15:24:31 -0700 | [diff] [blame] | 1096 | return -ENODEV; |
| 1097 | } |
Benjamin Herrenschmidt | b75550e | 2005-04-16 15:24:31 -0700 | [diff] [blame] | 1098 | addr = *base; |
| 1099 | if (addr < 0x50) |
| 1100 | addr += 0x50; |
| 1101 | } else |
| 1102 | addr = *base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | |
Benjamin Herrenschmidt | b75550e | 2005-04-16 15:24:31 -0700 | [diff] [blame] | 1104 | gp->addr = addr & 0x0000ffff; |
Benjamin Herrenschmidt | b75550e | 2005-04-16 15:24:31 -0700 | [diff] [blame] | 1105 | /* Try to find the active state, default to 0 ! */ |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 1106 | base = of_get_property(node, "audio-gpio-active-state", NULL); |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1107 | if (base) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | gp->active_state = *base; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1109 | gp->active_val = (*base) ? 0x5 : 0x4; |
| 1110 | gp->inactive_val = (*base) ? 0x4 : 0x5; |
| 1111 | } else { |
Jeremy Kerr | abddd18 | 2006-07-12 15:41:18 +1000 | [diff] [blame] | 1112 | const u32 *prop = NULL; |
Benjamin Herrenschmidt | b75550e | 2005-04-16 15:24:31 -0700 | [diff] [blame] | 1113 | gp->active_state = 0; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1114 | gp->active_val = 0x4; |
| 1115 | gp->inactive_val = 0x5; |
| 1116 | /* Here are some crude hacks to extract the GPIO polarity and |
| 1117 | * open collector informations out of the do-platform script |
| 1118 | * as we don't yet have an interpreter for these things |
| 1119 | */ |
| 1120 | if (platform) |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 1121 | prop = of_get_property(node, platform, NULL); |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1122 | if (prop) { |
| 1123 | if (prop[3] == 0x9 && prop[4] == 0x9) { |
| 1124 | gp->active_val = 0xd; |
| 1125 | gp->inactive_val = 0xc; |
| 1126 | } |
| 1127 | if (prop[3] == 0x1 && prop[4] == 0x1) { |
| 1128 | gp->active_val = 0x5; |
| 1129 | gp->inactive_val = 0x4; |
| 1130 | } |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | DBG("(I) GPIO device %s found, offset: %x, active state: %d !\n", |
| 1135 | device, gp->addr, gp->active_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1137 | ret = irq_of_parse_and_map(node, 0); |
| 1138 | of_node_put(node); |
| 1139 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | /* reset audio */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1143 | static void tumbler_reset_audio(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1145 | struct pmac_tumbler *mix = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1147 | if (mix->anded_reset) { |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1148 | DBG("(I) codec anded reset !\n"); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1149 | write_audio_gpio(&mix->hp_mute, 0); |
| 1150 | write_audio_gpio(&mix->amp_mute, 0); |
Nishanth Aravamudan | 989a0b2 | 2005-07-09 10:53:24 +0200 | [diff] [blame] | 1151 | msleep(200); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1152 | write_audio_gpio(&mix->hp_mute, 1); |
| 1153 | write_audio_gpio(&mix->amp_mute, 1); |
Nishanth Aravamudan | 989a0b2 | 2005-07-09 10:53:24 +0200 | [diff] [blame] | 1154 | msleep(100); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1155 | write_audio_gpio(&mix->hp_mute, 0); |
| 1156 | write_audio_gpio(&mix->amp_mute, 0); |
Nishanth Aravamudan | 989a0b2 | 2005-07-09 10:53:24 +0200 | [diff] [blame] | 1157 | msleep(100); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1158 | } else { |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1159 | DBG("(I) codec normal reset !\n"); |
| 1160 | |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1161 | write_audio_gpio(&mix->audio_reset, 0); |
Nishanth Aravamudan | 989a0b2 | 2005-07-09 10:53:24 +0200 | [diff] [blame] | 1162 | msleep(200); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1163 | write_audio_gpio(&mix->audio_reset, 1); |
Nishanth Aravamudan | 989a0b2 | 2005-07-09 10:53:24 +0200 | [diff] [blame] | 1164 | msleep(100); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1165 | write_audio_gpio(&mix->audio_reset, 0); |
Nishanth Aravamudan | 989a0b2 | 2005-07-09 10:53:24 +0200 | [diff] [blame] | 1166 | msleep(100); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
Benjamin Herrenschmidt | 8c87093 | 2005-06-27 14:36:34 -0700 | [diff] [blame] | 1170 | #ifdef CONFIG_PM |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1171 | /* suspend mixer */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1172 | static void tumbler_suspend(struct snd_pmac *chip) |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1173 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1174 | struct pmac_tumbler *mix = chip->mixer_data; |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1175 | |
| 1176 | if (mix->headphone_irq >= 0) |
| 1177 | disable_irq(mix->headphone_irq); |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1178 | if (mix->lineout_irq >= 0) |
| 1179 | disable_irq(mix->lineout_irq); |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1180 | mix->save_master_switch[0] = mix->master_switch[0]; |
| 1181 | mix->save_master_switch[1] = mix->master_switch[1]; |
Colin Leroy | 085e6fc | 2005-05-01 08:58:43 -0700 | [diff] [blame] | 1182 | mix->save_master_vol[0] = mix->master_vol[0]; |
| 1183 | mix->save_master_vol[1] = mix->master_vol[1]; |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1184 | mix->master_switch[0] = mix->master_switch[1] = 0; |
| 1185 | tumbler_set_master_volume(mix); |
| 1186 | if (!mix->anded_reset) { |
| 1187 | write_audio_gpio(&mix->amp_mute, 1); |
| 1188 | write_audio_gpio(&mix->hp_mute, 1); |
| 1189 | } |
| 1190 | if (chip->model == PMAC_SNAPPER) { |
| 1191 | mix->acs |= 1; |
| 1192 | i2c_smbus_write_byte_data(mix->i2c.client, TAS_REG_ACS, mix->acs); |
| 1193 | } |
| 1194 | if (mix->anded_reset) { |
| 1195 | write_audio_gpio(&mix->amp_mute, 1); |
| 1196 | write_audio_gpio(&mix->hp_mute, 1); |
| 1197 | } else |
| 1198 | write_audio_gpio(&mix->audio_reset, 1); |
| 1199 | } |
| 1200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | /* resume mixer */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1202 | static void tumbler_resume(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1204 | struct pmac_tumbler *mix = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | |
| 1206 | snd_assert(mix, return); |
| 1207 | |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1208 | mix->acs &= ~1; |
| 1209 | mix->master_switch[0] = mix->save_master_switch[0]; |
| 1210 | mix->master_switch[1] = mix->save_master_switch[1]; |
Colin Leroy | 085e6fc | 2005-05-01 08:58:43 -0700 | [diff] [blame] | 1211 | mix->master_vol[0] = mix->save_master_vol[0]; |
| 1212 | mix->master_vol[1] = mix->save_master_vol[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | tumbler_reset_audio(chip); |
| 1214 | if (mix->i2c.client && mix->i2c.init_client) { |
| 1215 | if (mix->i2c.init_client(&mix->i2c) < 0) |
| 1216 | printk(KERN_ERR "tumbler_init_client error\n"); |
| 1217 | } else |
| 1218 | printk(KERN_ERR "tumbler: i2c is not initialized\n"); |
| 1219 | if (chip->model == PMAC_TUMBLER) { |
| 1220 | tumbler_set_mono_volume(mix, &tumbler_pcm_vol_info); |
| 1221 | tumbler_set_mono_volume(mix, &tumbler_bass_vol_info); |
| 1222 | tumbler_set_mono_volume(mix, &tumbler_treble_vol_info); |
| 1223 | tumbler_set_drc(mix); |
| 1224 | } else { |
| 1225 | snapper_set_mix_vol(mix, VOL_IDX_PCM); |
| 1226 | snapper_set_mix_vol(mix, VOL_IDX_PCM2); |
| 1227 | snapper_set_mix_vol(mix, VOL_IDX_ADC); |
| 1228 | tumbler_set_mono_volume(mix, &snapper_bass_vol_info); |
| 1229 | tumbler_set_mono_volume(mix, &snapper_treble_vol_info); |
| 1230 | snapper_set_drc(mix); |
| 1231 | snapper_set_capture_source(mix); |
| 1232 | } |
| 1233 | tumbler_set_master_volume(mix); |
| 1234 | if (chip->update_automute) |
| 1235 | chip->update_automute(chip, 0); |
Guido Guenther | c0ce5c5 | 2005-11-15 17:28:05 +1100 | [diff] [blame] | 1236 | if (mix->headphone_irq >= 0) { |
| 1237 | unsigned char val; |
| 1238 | |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1239 | enable_irq(mix->headphone_irq); |
Guido Guenther | c0ce5c5 | 2005-11-15 17:28:05 +1100 | [diff] [blame] | 1240 | /* activate headphone status interrupts */ |
| 1241 | val = do_gpio_read(&mix->hp_detect); |
| 1242 | do_gpio_write(&mix->hp_detect, val | 0x80); |
| 1243 | } |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1244 | if (mix->lineout_irq >= 0) |
| 1245 | enable_irq(mix->lineout_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | } |
| 1247 | #endif |
| 1248 | |
| 1249 | /* initialize tumbler */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1250 | static int __init tumbler_init(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | { |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1252 | int irq; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1253 | struct pmac_tumbler *mix = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | snd_assert(mix, return -EINVAL); |
| 1255 | |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1256 | if (tumbler_find_device("audio-hw-reset", |
| 1257 | "platform-do-hw-reset", |
| 1258 | &mix->audio_reset, 0) < 0) |
| 1259 | tumbler_find_device("hw-reset", |
| 1260 | "platform-do-hw-reset", |
| 1261 | &mix->audio_reset, 1); |
| 1262 | if (tumbler_find_device("amp-mute", |
| 1263 | "platform-do-amp-mute", |
| 1264 | &mix->amp_mute, 0) < 0) |
| 1265 | tumbler_find_device("amp-mute", |
| 1266 | "platform-do-amp-mute", |
| 1267 | &mix->amp_mute, 1); |
| 1268 | if (tumbler_find_device("headphone-mute", |
| 1269 | "platform-do-headphone-mute", |
| 1270 | &mix->hp_mute, 0) < 0) |
| 1271 | tumbler_find_device("headphone-mute", |
| 1272 | "platform-do-headphone-mute", |
| 1273 | &mix->hp_mute, 1); |
| 1274 | if (tumbler_find_device("line-output-mute", |
| 1275 | "platform-do-lineout-mute", |
| 1276 | &mix->line_mute, 0) < 0) |
| 1277 | tumbler_find_device("line-output-mute", |
| 1278 | "platform-do-lineout-mute", |
| 1279 | &mix->line_mute, 1); |
| 1280 | irq = tumbler_find_device("headphone-detect", |
| 1281 | NULL, &mix->hp_detect, 0); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1282 | if (irq <= NO_IRQ) |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1283 | irq = tumbler_find_device("headphone-detect", |
| 1284 | NULL, &mix->hp_detect, 1); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1285 | if (irq <= NO_IRQ) |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1286 | irq = tumbler_find_device("keywest-gpio15", |
| 1287 | NULL, &mix->hp_detect, 1); |
| 1288 | mix->headphone_irq = irq; |
| 1289 | irq = tumbler_find_device("line-output-detect", |
| 1290 | NULL, &mix->line_detect, 0); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1291 | if (irq <= NO_IRQ) |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1292 | irq = tumbler_find_device("line-output-detect", |
| 1293 | NULL, &mix->line_detect, 1); |
| 1294 | mix->lineout_irq = irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
| 1296 | tumbler_reset_audio(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | |
| 1298 | return 0; |
| 1299 | } |
| 1300 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1301 | static void tumbler_cleanup(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1303 | struct pmac_tumbler *mix = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | if (! mix) |
| 1305 | return; |
| 1306 | |
| 1307 | if (mix->headphone_irq >= 0) |
| 1308 | free_irq(mix->headphone_irq, chip); |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1309 | if (mix->lineout_irq >= 0) |
| 1310 | free_irq(mix->lineout_irq, chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | tumbler_gpio_free(&mix->audio_reset); |
| 1312 | tumbler_gpio_free(&mix->amp_mute); |
| 1313 | tumbler_gpio_free(&mix->hp_mute); |
| 1314 | tumbler_gpio_free(&mix->hp_detect); |
| 1315 | snd_pmac_keywest_cleanup(&mix->i2c); |
| 1316 | kfree(mix); |
| 1317 | chip->mixer_data = NULL; |
| 1318 | } |
| 1319 | |
| 1320 | /* exported */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1321 | int __init snd_pmac_tumbler_init(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | { |
| 1323 | int i, err; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 1324 | struct pmac_tumbler *mix; |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 1325 | const u32 *paddr; |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1326 | struct device_node *tas_node, *np; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | char *chipname; |
| 1328 | |
| 1329 | #ifdef CONFIG_KMOD |
| 1330 | if (current->fs->root) |
Benjamin Herrenschmidt | 4d6c588 | 2006-04-21 15:04:22 +1000 | [diff] [blame] | 1331 | request_module("i2c-powermac"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | #endif /* CONFIG_KMOD */ |
| 1333 | |
Panagiotis Issaris | 59feddb | 2006-07-25 15:28:03 +0200 | [diff] [blame] | 1334 | mix = kzalloc(sizeof(*mix), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | if (! mix) |
| 1336 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | mix->headphone_irq = -1; |
| 1338 | |
| 1339 | chip->mixer_data = mix; |
| 1340 | chip->mixer_free = tumbler_cleanup; |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1341 | mix->anded_reset = 0; |
| 1342 | mix->reset_on_sleep = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1344 | for (np = chip->node->child; np; np = np->sibling) { |
| 1345 | if (!strcmp(np->name, "sound")) { |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 1346 | if (of_get_property(np, "has-anded-reset", NULL)) |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1347 | mix->anded_reset = 1; |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 1348 | if (of_get_property(np, "layout-id", NULL)) |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1349 | mix->reset_on_sleep = 0; |
| 1350 | break; |
| 1351 | } |
| 1352 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | if ((err = tumbler_init(chip)) < 0) |
| 1354 | return err; |
| 1355 | |
| 1356 | /* set up TAS */ |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1357 | tas_node = of_find_node_by_name(NULL, "deq"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | if (tas_node == NULL) |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1359 | tas_node = of_find_node_by_name(NULL, "codec"); |
Benjamin Herrenschmidt | b75550e | 2005-04-16 15:24:31 -0700 | [diff] [blame] | 1360 | if (tas_node == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | return -ENODEV; |
| 1362 | |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 1363 | paddr = of_get_property(tas_node, "i2c-address", NULL); |
Benjamin Herrenschmidt | b75550e | 2005-04-16 15:24:31 -0700 | [diff] [blame] | 1364 | if (paddr == NULL) |
Stephen Rothwell | c4f55b3 | 2007-04-03 22:39:14 +1000 | [diff] [blame] | 1365 | paddr = of_get_property(tas_node, "reg", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | if (paddr) |
| 1367 | mix->i2c.addr = (*paddr) >> 1; |
| 1368 | else |
| 1369 | mix->i2c.addr = TAS_I2C_ADDR; |
Stephen Rothwell | 30686ba | 2007-04-24 13:53:04 +1000 | [diff] [blame] | 1370 | of_node_put(tas_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1372 | DBG("(I) TAS i2c address is: %x\n", mix->i2c.addr); |
| 1373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | if (chip->model == PMAC_TUMBLER) { |
| 1375 | mix->i2c.init_client = tumbler_init_client; |
| 1376 | mix->i2c.name = "TAS3001c"; |
| 1377 | chipname = "Tumbler"; |
| 1378 | } else { |
| 1379 | mix->i2c.init_client = snapper_init_client; |
| 1380 | mix->i2c.name = "TAS3004"; |
| 1381 | chipname = "Snapper"; |
| 1382 | } |
| 1383 | |
| 1384 | if ((err = snd_pmac_keywest_init(&mix->i2c)) < 0) |
| 1385 | return err; |
| 1386 | |
| 1387 | /* |
| 1388 | * build mixers |
| 1389 | */ |
| 1390 | sprintf(chip->card->mixername, "PowerMac %s", chipname); |
| 1391 | |
| 1392 | if (chip->model == PMAC_TUMBLER) { |
| 1393 | for (i = 0; i < ARRAY_SIZE(tumbler_mixers); i++) { |
| 1394 | if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&tumbler_mixers[i], chip))) < 0) |
| 1395 | return err; |
| 1396 | } |
| 1397 | } else { |
| 1398 | for (i = 0; i < ARRAY_SIZE(snapper_mixers); i++) { |
| 1399 | if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snapper_mixers[i], chip))) < 0) |
| 1400 | return err; |
| 1401 | } |
| 1402 | } |
| 1403 | chip->master_sw_ctl = snd_ctl_new1(&tumbler_hp_sw, chip); |
| 1404 | if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0) |
| 1405 | return err; |
| 1406 | chip->speaker_sw_ctl = snd_ctl_new1(&tumbler_speaker_sw, chip); |
| 1407 | if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0) |
| 1408 | return err; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1409 | if (mix->line_mute.addr != 0) { |
| 1410 | chip->lineout_sw_ctl = snd_ctl_new1(&tumbler_lineout_sw, chip); |
| 1411 | if ((err = snd_ctl_add(chip->card, chip->lineout_sw_ctl)) < 0) |
| 1412 | return err; |
| 1413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | chip->drc_sw_ctl = snd_ctl_new1(&tumbler_drc_sw, chip); |
| 1415 | if ((err = snd_ctl_add(chip->card, chip->drc_sw_ctl)) < 0) |
| 1416 | return err; |
| 1417 | |
Takashi Iwai | f328385 | 2005-09-07 17:08:40 +0200 | [diff] [blame] | 1418 | /* set initial DRC range to 60% */ |
| 1419 | if (chip->model == PMAC_TUMBLER) |
| 1420 | mix->drc_range = (TAS3001_DRC_MAX * 6) / 10; |
| 1421 | else |
| 1422 | mix->drc_range = (TAS3004_DRC_MAX * 6) / 10; |
| 1423 | mix->drc_enable = 1; /* will be changed later if AUTO_DRC is set */ |
| 1424 | if (chip->model == PMAC_TUMBLER) |
| 1425 | tumbler_set_drc(mix); |
| 1426 | else |
| 1427 | snapper_set_drc(mix); |
| 1428 | |
Benjamin Herrenschmidt | 8c87093 | 2005-06-27 14:36:34 -0700 | [diff] [blame] | 1429 | #ifdef CONFIG_PM |
Benjamin Herrenschmidt | b20af5f | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1430 | chip->suspend = tumbler_suspend; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | chip->resume = tumbler_resume; |
| 1432 | #endif |
| 1433 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1434 | INIT_WORK(&device_change, device_change_handler); |
| 1435 | device_change_chip = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | |
| 1437 | #ifdef PMAC_SUPPORT_AUTOMUTE |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1438 | if ((mix->headphone_irq >=0 || mix->lineout_irq >= 0) |
| 1439 | && (err = snd_pmac_add_automute(chip)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | return err; |
| 1441 | chip->detect_headphone = tumbler_detect_headphone; |
| 1442 | chip->update_automute = tumbler_update_automute; |
| 1443 | tumbler_update_automute(chip, 0); /* update the status only */ |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 1444 | |
| 1445 | /* activate headphone status interrupts */ |
| 1446 | if (mix->headphone_irq >= 0) { |
| 1447 | unsigned char val; |
| 1448 | if ((err = request_irq(mix->headphone_irq, headphone_intr, 0, |
| 1449 | "Sound Headphone Detection", chip)) < 0) |
| 1450 | return 0; |
| 1451 | /* activate headphone status interrupts */ |
| 1452 | val = do_gpio_read(&mix->hp_detect); |
| 1453 | do_gpio_write(&mix->hp_detect, val | 0x80); |
| 1454 | } |
| 1455 | if (mix->lineout_irq >= 0) { |
| 1456 | unsigned char val; |
| 1457 | if ((err = request_irq(mix->lineout_irq, headphone_intr, 0, |
| 1458 | "Sound Lineout Detection", chip)) < 0) |
| 1459 | return 0; |
| 1460 | /* activate headphone status interrupts */ |
| 1461 | val = do_gpio_read(&mix->line_detect); |
| 1462 | do_gpio_write(&mix->line_detect, val | 0x80); |
| 1463 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | #endif |
| 1465 | |
| 1466 | return 0; |
| 1467 | } |