Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * PMac AWACS lowlevel functions |
| 3 | * |
| 4 | * Copyright (c) by Takashi Iwai <tiwai@suse.de> |
| 5 | * code based on dmasound.c. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/io.h> |
| 24 | #include <asm/nvram.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <sound/core.h> |
| 29 | #include "pmac.h" |
| 30 | |
| 31 | |
| 32 | #ifdef CONFIG_ADB_CUDA |
| 33 | #define PMAC_AMP_AVAIL |
| 34 | #endif |
| 35 | |
| 36 | #ifdef PMAC_AMP_AVAIL |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 37 | struct awacs_amp { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | unsigned char amp_master; |
| 39 | unsigned char amp_vol[2][2]; |
| 40 | unsigned char amp_tone[2]; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 41 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | #define CHECK_CUDA_AMP() (sys_ctrler == SYS_CTRLER_CUDA) |
| 44 | |
| 45 | #endif /* PMAC_AMP_AVAIL */ |
| 46 | |
| 47 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 48 | static void snd_pmac_screamer_wait(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | long timeout = 2000; |
| 51 | while (!(in_le32(&chip->awacs->codec_stat) & MASK_VALID)) { |
| 52 | mdelay(1); |
| 53 | if (! --timeout) { |
| 54 | snd_printd("snd_pmac_screamer_wait timeout\n"); |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * write AWACS register |
| 62 | */ |
| 63 | static void |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 64 | snd_pmac_awacs_write(struct snd_pmac *chip, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
| 66 | long timeout = 5000000; |
| 67 | |
| 68 | if (chip->model == PMAC_SCREAMER) |
| 69 | snd_pmac_screamer_wait(chip); |
| 70 | out_le32(&chip->awacs->codec_ctrl, val | (chip->subframe << 22)); |
| 71 | while (in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) { |
| 72 | if (! --timeout) { |
| 73 | snd_printd("snd_pmac_awacs_write timeout\n"); |
| 74 | break; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | static void |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 80 | snd_pmac_awacs_write_reg(struct snd_pmac *chip, int reg, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
| 82 | snd_pmac_awacs_write(chip, val | (reg << 12)); |
| 83 | chip->awacs_reg[reg] = val; |
| 84 | } |
| 85 | |
| 86 | static void |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 87 | snd_pmac_awacs_write_noreg(struct snd_pmac *chip, int reg, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
| 89 | snd_pmac_awacs_write(chip, val | (reg << 12)); |
| 90 | } |
| 91 | |
Benjamin Herrenschmidt | 8c87093 | 2005-06-27 14:36:34 -0700 | [diff] [blame] | 92 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* Recalibrate chip */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 94 | static void screamer_recalibrate(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
| 96 | if (chip->model != PMAC_SCREAMER) |
| 97 | return; |
| 98 | |
| 99 | /* Sorry for the horrible delays... I hope to get that improved |
| 100 | * by making the whole PM process asynchronous in a future version |
| 101 | */ |
| 102 | snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]); |
| 103 | if (chip->manufacturer == 0x1) |
| 104 | /* delay for broken crystal part */ |
Nishanth Aravamudan | 989a0b2 | 2005-07-09 10:53:24 +0200 | [diff] [blame] | 105 | msleep(750); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | snd_pmac_awacs_write_noreg(chip, 1, |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 107 | chip->awacs_reg[1] | MASK_RECALIBRATE | |
| 108 | MASK_CMUTE | MASK_AMUTE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]); |
| 110 | snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]); |
| 111 | } |
| 112 | |
| 113 | #else |
| 114 | #define screamer_recalibrate(chip) /* NOP */ |
| 115 | #endif |
| 116 | |
| 117 | |
| 118 | /* |
| 119 | * additional callback to set the pcm format |
| 120 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 121 | static void snd_pmac_awacs_set_format(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
| 123 | chip->awacs_reg[1] &= ~MASK_SAMPLERATE; |
| 124 | chip->awacs_reg[1] |= chip->rate_index << 3; |
| 125 | snd_pmac_awacs_write_reg(chip, 1, chip->awacs_reg[1]); |
| 126 | } |
| 127 | |
| 128 | |
| 129 | /* |
| 130 | * AWACS volume callbacks |
| 131 | */ |
| 132 | /* |
| 133 | * volumes: 0-15 stereo |
| 134 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 135 | static int snd_pmac_awacs_info_volume(struct snd_kcontrol *kcontrol, |
| 136 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | { |
| 138 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 139 | uinfo->count = 2; |
| 140 | uinfo->value.integer.min = 0; |
| 141 | uinfo->value.integer.max = 15; |
| 142 | return 0; |
| 143 | } |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 144 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 145 | static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol, |
| 146 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 148 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | int reg = kcontrol->private_value & 0xff; |
| 150 | int lshift = (kcontrol->private_value >> 8) & 0xff; |
| 151 | int inverted = (kcontrol->private_value >> 16) & 1; |
| 152 | unsigned long flags; |
| 153 | int vol[2]; |
| 154 | |
| 155 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 156 | vol[0] = (chip->awacs_reg[reg] >> lshift) & 0xf; |
| 157 | vol[1] = chip->awacs_reg[reg] & 0xf; |
| 158 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 159 | if (inverted) { |
| 160 | vol[0] = 0x0f - vol[0]; |
| 161 | vol[1] = 0x0f - vol[1]; |
| 162 | } |
| 163 | ucontrol->value.integer.value[0] = vol[0]; |
| 164 | ucontrol->value.integer.value[1] = vol[1]; |
| 165 | return 0; |
| 166 | } |
| 167 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 168 | static int snd_pmac_awacs_put_volume(struct snd_kcontrol *kcontrol, |
| 169 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 171 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | int reg = kcontrol->private_value & 0xff; |
| 173 | int lshift = (kcontrol->private_value >> 8) & 0xff; |
| 174 | int inverted = (kcontrol->private_value >> 16) & 1; |
| 175 | int val, oldval; |
| 176 | unsigned long flags; |
Takashi Iwai | d4079ac | 2007-11-15 16:14:12 +0100 | [diff] [blame] | 177 | unsigned int vol[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | vol[0] = ucontrol->value.integer.value[0]; |
| 180 | vol[1] = ucontrol->value.integer.value[1]; |
Takashi Iwai | d4079ac | 2007-11-15 16:14:12 +0100 | [diff] [blame] | 181 | if (vol[0] > 0x0f || vol[1] > 0x0f) |
| 182 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | if (inverted) { |
| 184 | vol[0] = 0x0f - vol[0]; |
| 185 | vol[1] = 0x0f - vol[1]; |
| 186 | } |
| 187 | vol[0] &= 0x0f; |
| 188 | vol[1] &= 0x0f; |
| 189 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 190 | oldval = chip->awacs_reg[reg]; |
| 191 | val = oldval & ~(0xf | (0xf << lshift)); |
| 192 | val |= vol[0] << lshift; |
| 193 | val |= vol[1]; |
| 194 | if (oldval != val) |
| 195 | snd_pmac_awacs_write_reg(chip, reg, val); |
| 196 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 197 | return oldval != reg; |
| 198 | } |
| 199 | |
| 200 | |
| 201 | #define AWACS_VOLUME(xname, xreg, xshift, xinverted) \ |
| 202 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ |
| 203 | .info = snd_pmac_awacs_info_volume, \ |
| 204 | .get = snd_pmac_awacs_get_volume, \ |
| 205 | .put = snd_pmac_awacs_put_volume, \ |
| 206 | .private_value = (xreg) | ((xshift) << 8) | ((xinverted) << 16) } |
| 207 | |
| 208 | /* |
| 209 | * mute master/ogain for AWACS: mono |
| 210 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 211 | static int snd_pmac_awacs_get_switch(struct snd_kcontrol *kcontrol, |
| 212 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 214 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | int reg = kcontrol->private_value & 0xff; |
| 216 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 217 | int invert = (kcontrol->private_value >> 16) & 1; |
| 218 | int val; |
| 219 | unsigned long flags; |
| 220 | |
| 221 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 222 | val = (chip->awacs_reg[reg] >> shift) & 1; |
| 223 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 224 | if (invert) |
| 225 | val = 1 - val; |
| 226 | ucontrol->value.integer.value[0] = val; |
| 227 | return 0; |
| 228 | } |
| 229 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 230 | static int snd_pmac_awacs_put_switch(struct snd_kcontrol *kcontrol, |
| 231 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 233 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | int reg = kcontrol->private_value & 0xff; |
| 235 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 236 | int invert = (kcontrol->private_value >> 16) & 1; |
| 237 | int mask = 1 << shift; |
| 238 | int val, changed; |
| 239 | unsigned long flags; |
| 240 | |
| 241 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 242 | val = chip->awacs_reg[reg] & ~mask; |
| 243 | if (ucontrol->value.integer.value[0] != invert) |
| 244 | val |= mask; |
| 245 | changed = chip->awacs_reg[reg] != val; |
| 246 | if (changed) |
| 247 | snd_pmac_awacs_write_reg(chip, reg, val); |
| 248 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 249 | return changed; |
| 250 | } |
| 251 | |
| 252 | #define AWACS_SWITCH(xname, xreg, xshift, xinvert) \ |
| 253 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ |
| 254 | .info = snd_pmac_boolean_mono_info, \ |
| 255 | .get = snd_pmac_awacs_get_switch, \ |
| 256 | .put = snd_pmac_awacs_put_switch, \ |
| 257 | .private_value = (xreg) | ((xshift) << 8) | ((xinvert) << 16) } |
| 258 | |
| 259 | |
| 260 | #ifdef PMAC_AMP_AVAIL |
| 261 | /* |
| 262 | * controls for perch/whisper extension cards, e.g. G3 desktop |
| 263 | * |
| 264 | * TDA7433 connected via i2c address 0x45 (= 0x8a), |
| 265 | * accessed through cuda |
| 266 | */ |
| 267 | static void awacs_set_cuda(int reg, int val) |
| 268 | { |
| 269 | struct adb_request req; |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 270 | cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a, |
| 271 | reg, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | while (! req.complete) |
| 273 | cuda_poll(); |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * level = 0 - 14, 7 = 0 dB |
| 278 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 279 | static void awacs_amp_set_tone(struct awacs_amp *amp, int bass, int treble) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | { |
| 281 | amp->amp_tone[0] = bass; |
| 282 | amp->amp_tone[1] = treble; |
| 283 | if (bass > 7) |
| 284 | bass = (14 - bass) + 8; |
| 285 | if (treble > 7) |
| 286 | treble = (14 - treble) + 8; |
| 287 | awacs_set_cuda(2, (bass << 4) | treble); |
| 288 | } |
| 289 | |
| 290 | /* |
| 291 | * vol = 0 - 31 (attenuation), 32 = mute bit, stereo |
| 292 | */ |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 293 | static int awacs_amp_set_vol(struct awacs_amp *amp, int index, |
| 294 | int lvol, int rvol, int do_check) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { |
| 296 | if (do_check && amp->amp_vol[index][0] == lvol && |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 297 | amp->amp_vol[index][1] == rvol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | return 0; |
| 299 | awacs_set_cuda(3 + index, lvol); |
| 300 | awacs_set_cuda(5 + index, rvol); |
| 301 | amp->amp_vol[index][0] = lvol; |
| 302 | amp->amp_vol[index][1] = rvol; |
| 303 | return 1; |
| 304 | } |
| 305 | |
| 306 | /* |
| 307 | * 0 = -79 dB, 79 = 0 dB, 99 = +20 dB |
| 308 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 309 | static void awacs_amp_set_master(struct awacs_amp *amp, int vol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | { |
| 311 | amp->amp_master = vol; |
| 312 | if (vol <= 79) |
| 313 | vol = 32 + (79 - vol); |
| 314 | else |
| 315 | vol = 32 - (vol - 79); |
| 316 | awacs_set_cuda(1, vol); |
| 317 | } |
| 318 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 319 | static void awacs_amp_free(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 321 | struct awacs_amp *amp = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | snd_assert(amp, return); |
| 323 | kfree(amp); |
| 324 | chip->mixer_data = NULL; |
| 325 | chip->mixer_free = NULL; |
| 326 | } |
| 327 | |
| 328 | |
| 329 | /* |
| 330 | * mixer controls |
| 331 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 332 | static int snd_pmac_awacs_info_volume_amp(struct snd_kcontrol *kcontrol, |
| 333 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
| 335 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 336 | uinfo->count = 2; |
| 337 | uinfo->value.integer.min = 0; |
| 338 | uinfo->value.integer.max = 31; |
| 339 | return 0; |
| 340 | } |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 341 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 342 | static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol, |
| 343 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 345 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | int index = kcontrol->private_value; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 347 | struct awacs_amp *amp = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | snd_assert(amp, return -EINVAL); |
| 349 | snd_assert(index >= 0 && index <= 1, return -EINVAL); |
| 350 | ucontrol->value.integer.value[0] = 31 - (amp->amp_vol[index][0] & 31); |
| 351 | ucontrol->value.integer.value[1] = 31 - (amp->amp_vol[index][1] & 31); |
| 352 | return 0; |
| 353 | } |
| 354 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 355 | static int snd_pmac_awacs_put_volume_amp(struct snd_kcontrol *kcontrol, |
| 356 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 358 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | int index = kcontrol->private_value; |
| 360 | int vol[2]; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 361 | struct awacs_amp *amp = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | snd_assert(amp, return -EINVAL); |
| 363 | snd_assert(index >= 0 && index <= 1, return -EINVAL); |
| 364 | |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 365 | vol[0] = (31 - (ucontrol->value.integer.value[0] & 31)) |
| 366 | | (amp->amp_vol[index][0] & 32); |
| 367 | vol[1] = (31 - (ucontrol->value.integer.value[1] & 31)) |
| 368 | | (amp->amp_vol[index][1] & 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1); |
| 370 | } |
| 371 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 372 | static int snd_pmac_awacs_get_switch_amp(struct snd_kcontrol *kcontrol, |
| 373 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 375 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | int index = kcontrol->private_value; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 377 | struct awacs_amp *amp = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | snd_assert(amp, return -EINVAL); |
| 379 | snd_assert(index >= 0 && index <= 1, return -EINVAL); |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 380 | ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32) |
| 381 | ? 0 : 1; |
| 382 | ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32) |
| 383 | ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | return 0; |
| 385 | } |
| 386 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 387 | static int snd_pmac_awacs_put_switch_amp(struct snd_kcontrol *kcontrol, |
| 388 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 390 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | int index = kcontrol->private_value; |
| 392 | int vol[2]; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 393 | struct awacs_amp *amp = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | snd_assert(amp, return -EINVAL); |
| 395 | snd_assert(index >= 0 && index <= 1, return -EINVAL); |
| 396 | |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 397 | vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32) |
| 398 | | (amp->amp_vol[index][0] & 31); |
| 399 | vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32) |
| 400 | | (amp->amp_vol[index][1] & 31); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1); |
| 402 | } |
| 403 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 404 | static int snd_pmac_awacs_info_tone_amp(struct snd_kcontrol *kcontrol, |
| 405 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
| 407 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 408 | uinfo->count = 1; |
| 409 | uinfo->value.integer.min = 0; |
| 410 | uinfo->value.integer.max = 14; |
| 411 | return 0; |
| 412 | } |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 413 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 414 | static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol, |
| 415 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 417 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | int index = kcontrol->private_value; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 419 | struct awacs_amp *amp = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | snd_assert(amp, return -EINVAL); |
| 421 | snd_assert(index >= 0 && index <= 1, return -EINVAL); |
| 422 | ucontrol->value.integer.value[0] = amp->amp_tone[index]; |
| 423 | return 0; |
| 424 | } |
| 425 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 426 | static int snd_pmac_awacs_put_tone_amp(struct snd_kcontrol *kcontrol, |
| 427 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 429 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | int index = kcontrol->private_value; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 431 | struct awacs_amp *amp = chip->mixer_data; |
Takashi Iwai | d4079ac | 2007-11-15 16:14:12 +0100 | [diff] [blame] | 432 | unsigned int val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | snd_assert(amp, return -EINVAL); |
| 434 | snd_assert(index >= 0 && index <= 1, return -EINVAL); |
Takashi Iwai | d4079ac | 2007-11-15 16:14:12 +0100 | [diff] [blame] | 435 | val = ucontrol->value.integer.value[0]; |
| 436 | if (val > 14) |
| 437 | return -EINVAL; |
| 438 | if (val != amp->amp_tone[index]) { |
| 439 | amp->amp_tone[index] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]); |
| 441 | return 1; |
| 442 | } |
| 443 | return 0; |
| 444 | } |
| 445 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 446 | static int snd_pmac_awacs_info_master_amp(struct snd_kcontrol *kcontrol, |
| 447 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
| 449 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 450 | uinfo->count = 1; |
| 451 | uinfo->value.integer.min = 0; |
| 452 | uinfo->value.integer.max = 99; |
| 453 | return 0; |
| 454 | } |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 455 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 456 | static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol, |
| 457 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 459 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 460 | struct awacs_amp *amp = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | snd_assert(amp, return -EINVAL); |
| 462 | ucontrol->value.integer.value[0] = amp->amp_master; |
| 463 | return 0; |
| 464 | } |
| 465 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 466 | static int snd_pmac_awacs_put_master_amp(struct snd_kcontrol *kcontrol, |
| 467 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 469 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
| 470 | struct awacs_amp *amp = chip->mixer_data; |
Takashi Iwai | d4079ac | 2007-11-15 16:14:12 +0100 | [diff] [blame] | 471 | unsigned int val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | snd_assert(amp, return -EINVAL); |
Takashi Iwai | d4079ac | 2007-11-15 16:14:12 +0100 | [diff] [blame] | 473 | val = ucontrol->value.integer.value[0]; |
| 474 | if (val > 99) |
| 475 | return -EINVAL; |
| 476 | if (val != amp->amp_master) { |
| 477 | amp->amp_master = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | awacs_amp_set_master(amp, amp->amp_master); |
| 479 | return 1; |
| 480 | } |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | #define AMP_CH_SPK 0 |
| 485 | #define AMP_CH_HD 1 |
| 486 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 487 | static struct snd_kcontrol_new snd_pmac_awacs_amp_vol[] __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 489 | .name = "PC Speaker Playback Volume", |
| 490 | .info = snd_pmac_awacs_info_volume_amp, |
| 491 | .get = snd_pmac_awacs_get_volume_amp, |
| 492 | .put = snd_pmac_awacs_put_volume_amp, |
| 493 | .private_value = AMP_CH_SPK, |
| 494 | }, |
| 495 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 496 | .name = "Headphone Playback Volume", |
| 497 | .info = snd_pmac_awacs_info_volume_amp, |
| 498 | .get = snd_pmac_awacs_get_volume_amp, |
| 499 | .put = snd_pmac_awacs_put_volume_amp, |
| 500 | .private_value = AMP_CH_HD, |
| 501 | }, |
| 502 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 503 | .name = "Tone Control - Bass", |
| 504 | .info = snd_pmac_awacs_info_tone_amp, |
| 505 | .get = snd_pmac_awacs_get_tone_amp, |
| 506 | .put = snd_pmac_awacs_put_tone_amp, |
| 507 | .private_value = 0, |
| 508 | }, |
| 509 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 510 | .name = "Tone Control - Treble", |
| 511 | .info = snd_pmac_awacs_info_tone_amp, |
| 512 | .get = snd_pmac_awacs_get_tone_amp, |
| 513 | .put = snd_pmac_awacs_put_tone_amp, |
| 514 | .private_value = 1, |
| 515 | }, |
| 516 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 517 | .name = "Amp Master Playback Volume", |
| 518 | .info = snd_pmac_awacs_info_master_amp, |
| 519 | .get = snd_pmac_awacs_get_master_amp, |
| 520 | .put = snd_pmac_awacs_put_master_amp, |
| 521 | }, |
| 522 | }; |
| 523 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 524 | static struct snd_kcontrol_new snd_pmac_awacs_amp_hp_sw __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 526 | .name = "Headphone Playback Switch", |
| 527 | .info = snd_pmac_boolean_stereo_info, |
| 528 | .get = snd_pmac_awacs_get_switch_amp, |
| 529 | .put = snd_pmac_awacs_put_switch_amp, |
| 530 | .private_value = AMP_CH_HD, |
| 531 | }; |
| 532 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 533 | static struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 535 | .name = "PC Speaker Playback Switch", |
| 536 | .info = snd_pmac_boolean_stereo_info, |
| 537 | .get = snd_pmac_awacs_get_switch_amp, |
| 538 | .put = snd_pmac_awacs_put_switch_amp, |
| 539 | .private_value = AMP_CH_SPK, |
| 540 | }; |
| 541 | |
| 542 | #endif /* PMAC_AMP_AVAIL */ |
| 543 | |
| 544 | |
| 545 | /* |
| 546 | * mic boost for screamer |
| 547 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 548 | static int snd_pmac_screamer_mic_boost_info(struct snd_kcontrol *kcontrol, |
| 549 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
| 551 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 552 | uinfo->count = 1; |
| 553 | uinfo->value.integer.min = 0; |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 554 | uinfo->value.integer.max = 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | return 0; |
| 556 | } |
| 557 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 558 | static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol *kcontrol, |
| 559 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 561 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 562 | int val = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | unsigned long flags; |
| 564 | |
| 565 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 566 | if (chip->awacs_reg[6] & MASK_MIC_BOOST) |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 567 | val |= 2; |
| 568 | if (chip->awacs_reg[0] & MASK_GAINLINE) |
| 569 | val |= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 571 | ucontrol->value.integer.value[0] = val; |
| 572 | return 0; |
| 573 | } |
| 574 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 575 | static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol, |
| 576 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 578 | struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | int changed = 0; |
| 580 | int val0, val6; |
| 581 | unsigned long flags; |
| 582 | |
| 583 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 584 | val0 = chip->awacs_reg[0] & ~MASK_GAINLINE; |
| 585 | val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST; |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 586 | if (ucontrol->value.integer.value[0] & 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | val0 |= MASK_GAINLINE; |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 588 | if (ucontrol->value.integer.value[0] & 2) |
| 589 | val6 |= MASK_MIC_BOOST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | if (val0 != chip->awacs_reg[0]) { |
| 591 | snd_pmac_awacs_write_reg(chip, 0, val0); |
| 592 | changed = 1; |
| 593 | } |
| 594 | if (val6 != chip->awacs_reg[6]) { |
| 595 | snd_pmac_awacs_write_reg(chip, 6, val6); |
| 596 | changed = 1; |
| 597 | } |
| 598 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 599 | return changed; |
| 600 | } |
| 601 | |
| 602 | /* |
| 603 | * lists of mixer elements |
| 604 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 605 | static struct snd_kcontrol_new snd_pmac_awacs_mixers[] __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0), |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 607 | AWACS_VOLUME("Master Capture Volume", 0, 4, 0), |
| 608 | /* AWACS_SWITCH("Unknown Playback Switch", 6, SHIFT_PAROUT0, 0), */ |
| 609 | }; |
| 610 | |
| 611 | static struct snd_kcontrol_new snd_pmac_screamer_mixers_beige[] __initdata = { |
| 612 | AWACS_VOLUME("Master Playback Volume", 2, 6, 1), |
| 613 | AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1), |
| 614 | AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0), |
| 615 | AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_LINE, 0), |
| 616 | }; |
| 617 | |
| 618 | static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] __initdata = { |
| 619 | AWACS_VOLUME("Line out Playback Volume", 2, 6, 1), |
| 620 | AWACS_VOLUME("Master Playback Volume", 5, 6, 1), |
| 621 | AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0), |
| 622 | }; |
| 623 | |
| 624 | static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] __initdata = { |
| 625 | AWACS_VOLUME("Line out Playback Volume", 2, 6, 1), |
| 626 | AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0), |
| 627 | AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0), |
| 628 | }; |
| 629 | |
| 630 | static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] __initdata = { |
| 631 | AWACS_VOLUME("Master Playback Volume", 2, 6, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0), |
| 633 | }; |
| 634 | |
| 635 | /* FIXME: is this correct order? |
| 636 | * screamer (powerbook G3 pismo) seems to have different bits... |
| 637 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 638 | static struct snd_kcontrol_new snd_pmac_awacs_mixers2[] __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_LINE, 0), |
| 640 | AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_MIC, 0), |
| 641 | }; |
| 642 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 643 | static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0), |
| 645 | AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_LINE, 0), |
| 646 | }; |
| 647 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 648 | static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1); |
| 650 | |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 651 | static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac __initdata = |
| 652 | AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1); |
| 653 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 654 | static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = { |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 655 | AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | }; |
| 657 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 658 | static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 660 | .name = "Mic Boost Capture Volume", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | .info = snd_pmac_screamer_mic_boost_info, |
| 662 | .get = snd_pmac_screamer_mic_boost_get, |
| 663 | .put = snd_pmac_screamer_mic_boost_put, |
| 664 | }, |
| 665 | }; |
| 666 | |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 667 | static struct snd_kcontrol_new snd_pmac_awacs_mic_boost_pmac7500[] __initdata = |
| 668 | { |
| 669 | AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0), |
| 670 | }; |
| 671 | |
| 672 | static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_beige[] __initdata = |
| 673 | { |
| 674 | AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0), |
| 675 | AWACS_SWITCH("CD Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0), |
| 676 | }; |
| 677 | |
| 678 | static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] __initdata = |
| 679 | { |
| 680 | AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0), |
| 681 | AWACS_SWITCH("Mic Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0), |
| 682 | }; |
| 683 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 684 | static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1), |
| 686 | }; |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 687 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 688 | static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1); |
| 690 | |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 691 | static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac __initdata = |
| 692 | AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 0); |
| 693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
| 695 | /* |
| 696 | * add new mixer elements to the card |
| 697 | */ |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 698 | static int build_mixers(struct snd_pmac *chip, int nums, |
| 699 | struct snd_kcontrol_new *mixers) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | { |
| 701 | int i, err; |
| 702 | |
| 703 | for (i = 0; i < nums; i++) { |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 704 | err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip)); |
| 705 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | return err; |
| 707 | } |
| 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | |
| 712 | /* |
| 713 | * restore all registers |
| 714 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 715 | static void awacs_restore_all_regs(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | { |
| 717 | snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]); |
| 718 | snd_pmac_awacs_write_noreg(chip, 1, chip->awacs_reg[1]); |
| 719 | snd_pmac_awacs_write_noreg(chip, 2, chip->awacs_reg[2]); |
| 720 | snd_pmac_awacs_write_noreg(chip, 4, chip->awacs_reg[4]); |
| 721 | if (chip->model == PMAC_SCREAMER) { |
| 722 | snd_pmac_awacs_write_noreg(chip, 5, chip->awacs_reg[5]); |
| 723 | snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]); |
| 724 | snd_pmac_awacs_write_noreg(chip, 7, chip->awacs_reg[7]); |
| 725 | } |
| 726 | } |
| 727 | |
Benjamin Herrenschmidt | 8c87093 | 2005-06-27 14:36:34 -0700 | [diff] [blame] | 728 | #ifdef CONFIG_PM |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 729 | static void snd_pmac_awacs_suspend(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | { |
| 731 | snd_pmac_awacs_write_noreg(chip, 1, (chip->awacs_reg[1] |
| 732 | | MASK_AMUTE | MASK_CMUTE)); |
| 733 | } |
| 734 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 735 | static void snd_pmac_awacs_resume(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | { |
| 737 | if (machine_is_compatible("PowerBook3,1") |
| 738 | || machine_is_compatible("PowerBook3,2")) { |
Nishanth Aravamudan | 989a0b2 | 2005-07-09 10:53:24 +0200 | [diff] [blame] | 739 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | snd_pmac_awacs_write_reg(chip, 1, |
| 741 | chip->awacs_reg[1] & ~MASK_PAROUT); |
Nishanth Aravamudan | 989a0b2 | 2005-07-09 10:53:24 +0200 | [diff] [blame] | 742 | msleep(300); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | awacs_restore_all_regs(chip); |
| 746 | if (chip->model == PMAC_SCREAMER) { |
| 747 | /* reset power bits in reg 6 */ |
| 748 | mdelay(5); |
| 749 | snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]); |
| 750 | } |
| 751 | screamer_recalibrate(chip); |
| 752 | #ifdef PMAC_AMP_AVAIL |
| 753 | if (chip->mixer_data) { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 754 | struct awacs_amp *amp = chip->mixer_data; |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 755 | awacs_amp_set_vol(amp, 0, |
| 756 | amp->amp_vol[0][0], amp->amp_vol[0][1], 0); |
| 757 | awacs_amp_set_vol(amp, 1, |
| 758 | amp->amp_vol[1][0], amp->amp_vol[1][1], 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]); |
| 760 | awacs_amp_set_master(amp, amp->amp_master); |
| 761 | } |
| 762 | #endif |
| 763 | } |
Benjamin Herrenschmidt | 8c87093 | 2005-06-27 14:36:34 -0700 | [diff] [blame] | 764 | #endif /* CONFIG_PM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 766 | #define IS_PM7500 (machine_is_compatible("AAPL,7500")) |
| 767 | #define IS_BEIGE (machine_is_compatible("AAPL,Gossamer")) |
| 768 | #define IS_IMAC (machine_is_compatible("PowerMac2,1") \ |
| 769 | || machine_is_compatible("PowerMac2,2") \ |
| 770 | || machine_is_compatible("PowerMac4,1")) |
| 771 | |
| 772 | static int imac; |
| 773 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | #ifdef PMAC_SUPPORT_AUTOMUTE |
| 775 | /* |
| 776 | * auto-mute stuffs |
| 777 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 778 | static int snd_pmac_awacs_detect_headphone(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | { |
| 780 | return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0; |
| 781 | } |
| 782 | |
| 783 | #ifdef PMAC_AMP_AVAIL |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 784 | static int toggle_amp_mute(struct awacs_amp *amp, int index, int mute) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | { |
| 786 | int vol[2]; |
| 787 | vol[0] = amp->amp_vol[index][0] & 31; |
| 788 | vol[1] = amp->amp_vol[index][1] & 31; |
| 789 | if (mute) { |
| 790 | vol[0] |= 32; |
| 791 | vol[1] |= 32; |
| 792 | } |
| 793 | return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1); |
| 794 | } |
| 795 | #endif |
| 796 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 797 | static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | { |
| 799 | if (chip->auto_mute) { |
| 800 | #ifdef PMAC_AMP_AVAIL |
| 801 | if (chip->mixer_data) { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 802 | struct awacs_amp *amp = chip->mixer_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | int changed; |
| 804 | if (snd_pmac_awacs_detect_headphone(chip)) { |
| 805 | changed = toggle_amp_mute(amp, AMP_CH_HD, 0); |
| 806 | changed |= toggle_amp_mute(amp, AMP_CH_SPK, 1); |
| 807 | } else { |
| 808 | changed = toggle_amp_mute(amp, AMP_CH_HD, 1); |
| 809 | changed |= toggle_amp_mute(amp, AMP_CH_SPK, 0); |
| 810 | } |
| 811 | if (do_notify && ! changed) |
| 812 | return; |
| 813 | } else |
| 814 | #endif |
| 815 | { |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 816 | int reg = chip->awacs_reg[1] |
| 817 | | (MASK_HDMUTE | MASK_SPKMUTE); |
| 818 | if (imac) { |
| 819 | reg &= ~MASK_SPKMUTE; |
| 820 | reg &= ~MASK_PAROUT1; |
| 821 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | if (snd_pmac_awacs_detect_headphone(chip)) |
| 823 | reg &= ~MASK_HDMUTE; |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 824 | else if (imac) |
| 825 | reg |= MASK_PAROUT1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | else |
| 827 | reg &= ~MASK_SPKMUTE; |
| 828 | if (do_notify && reg == chip->awacs_reg[1]) |
| 829 | return; |
| 830 | snd_pmac_awacs_write_reg(chip, 1, reg); |
| 831 | } |
| 832 | if (do_notify) { |
| 833 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 834 | &chip->master_sw_ctl->id); |
| 835 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 836 | &chip->speaker_sw_ctl->id); |
| 837 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 838 | &chip->hp_detect_ctl->id); |
| 839 | } |
| 840 | } |
| 841 | } |
| 842 | #endif /* PMAC_SUPPORT_AUTOMUTE */ |
| 843 | |
| 844 | |
| 845 | /* |
| 846 | * initialize chip |
| 847 | */ |
| 848 | int __init |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 849 | snd_pmac_awacs_init(struct snd_pmac *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | { |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 851 | int pm7500 = IS_PM7500; |
| 852 | int beige = IS_BEIGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | int err, vol; |
| 854 | |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 855 | imac = IS_IMAC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | /* looks like MASK_GAINLINE triggers something, so we set here |
| 857 | * as start-up |
| 858 | */ |
| 859 | chip->awacs_reg[0] = MASK_MUX_CD | 0xff | MASK_GAINLINE; |
| 860 | chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE; |
| 861 | /* FIXME: Only machines with external SRS module need MASK_PAROUT */ |
| 862 | if (chip->has_iic || chip->device_id == 0x5 || |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 863 | /* chip->_device_id == 0x8 || */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | chip->device_id == 0xb) |
| 865 | chip->awacs_reg[1] |= MASK_PAROUT; |
| 866 | /* get default volume from nvram */ |
| 867 | // vol = (~nvram_read_byte(0x1308) & 7) << 1; |
| 868 | // vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 ); |
| 869 | vol = 0x0f; /* no, on alsa, muted as default */ |
| 870 | vol = vol + (vol << 6); |
| 871 | chip->awacs_reg[2] = vol; |
| 872 | chip->awacs_reg[4] = vol; |
| 873 | if (chip->model == PMAC_SCREAMER) { |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 874 | /* FIXME: screamer has loopthru vol control */ |
| 875 | chip->awacs_reg[5] = vol; |
| 876 | /* FIXME: maybe should be vol << 3 for PCMCIA speaker */ |
| 877 | chip->awacs_reg[6] = MASK_MIC_BOOST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | chip->awacs_reg[7] = 0; |
| 879 | } |
| 880 | |
| 881 | awacs_restore_all_regs(chip); |
| 882 | chip->manufacturer = (in_le32(&chip->awacs->codec_stat) >> 8) & 0xf; |
| 883 | screamer_recalibrate(chip); |
| 884 | |
| 885 | chip->revision = (in_le32(&chip->awacs->codec_stat) >> 12) & 0xf; |
| 886 | #ifdef PMAC_AMP_AVAIL |
| 887 | if (chip->revision == 3 && chip->has_iic && CHECK_CUDA_AMP()) { |
Panagiotis Issaris | 59feddb | 2006-07-25 15:28:03 +0200 | [diff] [blame] | 888 | struct awacs_amp *amp = kzalloc(sizeof(*amp), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | if (! amp) |
| 890 | return -ENOMEM; |
| 891 | chip->mixer_data = amp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | chip->mixer_free = awacs_amp_free; |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 893 | /* mute and zero vol */ |
| 894 | awacs_amp_set_vol(amp, 0, 63, 63, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | awacs_amp_set_vol(amp, 1, 63, 63, 0); |
| 896 | awacs_amp_set_tone(amp, 7, 7); /* 0 dB */ |
| 897 | awacs_amp_set_master(amp, 79); /* 0 dB */ |
| 898 | } |
| 899 | #endif /* PMAC_AMP_AVAIL */ |
| 900 | |
| 901 | if (chip->hp_stat_mask == 0) { |
| 902 | /* set headphone-jack detection bit */ |
| 903 | switch (chip->model) { |
| 904 | case PMAC_AWACS: |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 905 | chip->hp_stat_mask = pm7500 ? MASK_HDPCONN |
| 906 | : MASK_LOCONN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | break; |
| 908 | case PMAC_SCREAMER: |
| 909 | switch (chip->device_id) { |
| 910 | case 0x08: |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 911 | case 0x0B: |
| 912 | chip->hp_stat_mask = imac |
| 913 | ? MASK_LOCONN_IMAC | |
| 914 | MASK_HDPLCONN_IMAC | |
| 915 | MASK_HDPRCONN_IMAC |
| 916 | : MASK_HDPCONN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | break; |
| 918 | case 0x00: |
| 919 | case 0x05: |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 920 | chip->hp_stat_mask = MASK_LOCONN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | break; |
| 922 | default: |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 923 | chip->hp_stat_mask = MASK_HDPCONN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | break; |
| 925 | } |
| 926 | break; |
| 927 | default: |
| 928 | snd_BUG(); |
| 929 | break; |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | /* |
| 934 | * build mixers |
| 935 | */ |
| 936 | strcpy(chip->card->mixername, "PowerMac AWACS"); |
| 937 | |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 938 | err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers), |
| 939 | snd_pmac_awacs_mixers); |
| 940 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | return err; |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 942 | if (beige) |
| 943 | ; |
| 944 | else if (chip->model == PMAC_SCREAMER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2), |
| 946 | snd_pmac_screamer_mixers2); |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 947 | else if (!pm7500) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2), |
| 949 | snd_pmac_awacs_mixers2); |
| 950 | if (err < 0) |
| 951 | return err; |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 952 | if (pm7500) |
| 953 | err = build_mixers(chip, |
| 954 | ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500), |
| 955 | snd_pmac_awacs_mixers_pmac7500); |
| 956 | else if (beige) |
| 957 | err = build_mixers(chip, |
| 958 | ARRAY_SIZE(snd_pmac_screamer_mixers_beige), |
| 959 | snd_pmac_screamer_mixers_beige); |
| 960 | else if (imac) |
| 961 | err = build_mixers(chip, |
| 962 | ARRAY_SIZE(snd_pmac_screamer_mixers_imac), |
| 963 | snd_pmac_screamer_mixers_imac); |
| 964 | else |
| 965 | err = build_mixers(chip, |
| 966 | ARRAY_SIZE(snd_pmac_awacs_mixers_pmac), |
| 967 | snd_pmac_awacs_mixers_pmac); |
| 968 | if (err < 0) |
| 969 | return err; |
| 970 | chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac) |
| 971 | ? &snd_pmac_awacs_master_sw_imac |
| 972 | : &snd_pmac_awacs_master_sw, chip); |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 973 | err = snd_ctl_add(chip->card, chip->master_sw_ctl); |
| 974 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | return err; |
| 976 | #ifdef PMAC_AMP_AVAIL |
| 977 | if (chip->mixer_data) { |
| 978 | /* use amplifier. the signal is connected from route A |
| 979 | * to the amp. the amp has its headphone and speaker |
| 980 | * volumes and mute switches, so we use them instead of |
| 981 | * screamer registers. |
| 982 | * in this case, it seems the route C is not used. |
| 983 | */ |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 984 | err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol), |
| 985 | snd_pmac_awacs_amp_vol); |
| 986 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | return err; |
| 988 | /* overwrite */ |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 989 | chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw, |
| 990 | chip); |
| 991 | err = snd_ctl_add(chip->card, chip->master_sw_ctl); |
| 992 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | return err; |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 994 | chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw, |
| 995 | chip); |
| 996 | err = snd_ctl_add(chip->card, chip->speaker_sw_ctl); |
| 997 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | return err; |
| 999 | } else |
| 1000 | #endif /* PMAC_AMP_AVAIL */ |
| 1001 | { |
| 1002 | /* route A = headphone, route C = speaker */ |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 1003 | err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol), |
| 1004 | snd_pmac_awacs_speaker_vol); |
| 1005 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | return err; |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 1007 | chip->speaker_sw_ctl = snd_ctl_new1(imac |
| 1008 | ? &snd_pmac_awacs_speaker_sw_imac |
| 1009 | : &snd_pmac_awacs_speaker_sw, chip); |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 1010 | err = snd_ctl_add(chip->card, chip->speaker_sw_ctl); |
| 1011 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | return err; |
| 1013 | } |
| 1014 | |
Risto Suominen | a8c2a6b | 2008-04-17 17:55:30 +0200 | [diff] [blame] | 1015 | if (beige) |
| 1016 | err = build_mixers(chip, |
| 1017 | ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige), |
| 1018 | snd_pmac_screamer_mic_boost_beige); |
| 1019 | else if (imac) |
| 1020 | err = build_mixers(chip, |
| 1021 | ARRAY_SIZE(snd_pmac_screamer_mic_boost_imac), |
| 1022 | snd_pmac_screamer_mic_boost_imac); |
| 1023 | else if (chip->model == PMAC_SCREAMER) |
| 1024 | err = build_mixers(chip, |
| 1025 | ARRAY_SIZE(snd_pmac_screamer_mic_boost), |
| 1026 | snd_pmac_screamer_mic_boost); |
| 1027 | else if (pm7500) |
| 1028 | err = build_mixers(chip, |
| 1029 | ARRAY_SIZE(snd_pmac_awacs_mic_boost_pmac7500), |
| 1030 | snd_pmac_awacs_mic_boost_pmac7500); |
| 1031 | else |
| 1032 | err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost), |
| 1033 | snd_pmac_awacs_mic_boost); |
| 1034 | if (err < 0) |
| 1035 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | |
| 1037 | /* |
| 1038 | * set lowlevel callbacks |
| 1039 | */ |
| 1040 | chip->set_format = snd_pmac_awacs_set_format; |
Benjamin Herrenschmidt | 8c87093 | 2005-06-27 14:36:34 -0700 | [diff] [blame] | 1041 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | chip->suspend = snd_pmac_awacs_suspend; |
| 1043 | chip->resume = snd_pmac_awacs_resume; |
| 1044 | #endif |
| 1045 | #ifdef PMAC_SUPPORT_AUTOMUTE |
Risto Suominen | 7ae44cf | 2008-04-16 19:39:27 +0200 | [diff] [blame] | 1046 | err = snd_pmac_add_automute(chip); |
| 1047 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | return err; |
| 1049 | chip->detect_headphone = snd_pmac_awacs_detect_headphone; |
| 1050 | chip->update_automute = snd_pmac_awacs_update_automute; |
| 1051 | snd_pmac_awacs_update_automute(chip, 0); /* update the status only */ |
| 1052 | #endif |
| 1053 | if (chip->model == PMAC_SCREAMER) { |
| 1054 | snd_pmac_awacs_write_noreg(chip, 6, chip->awacs_reg[6]); |
| 1055 | snd_pmac_awacs_write_noreg(chip, 0, chip->awacs_reg[0]); |
| 1056 | } |
| 1057 | |
| 1058 | return 0; |
| 1059 | } |