1 // SPDX-License-Identifier: GPL-2.0-or-later << 2 /* 1 /* 3 * PMac Burgundy lowlevel functions 2 * PMac Burgundy lowlevel functions 4 * 3 * 5 * Copyright (c) by Takashi Iwai <tiwai@suse.d 4 * Copyright (c) by Takashi Iwai <tiwai@suse.de> 6 * code based on dmasound.c. 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 7 */ 20 */ 8 21 9 #include <linux/io.h> !! 22 #include <asm/io.h> 10 #include <linux/init.h> 23 #include <linux/init.h> >> 24 #include <linux/slab.h> 11 #include <linux/delay.h> 25 #include <linux/delay.h> 12 #include <linux/of.h> << 13 #include <sound/core.h> 26 #include <sound/core.h> 14 #include "pmac.h" 27 #include "pmac.h" 15 #include "burgundy.h" 28 #include "burgundy.h" 16 29 17 30 18 /* Waits for busy flag to clear */ 31 /* Waits for busy flag to clear */ 19 static inline void 32 static inline void 20 snd_pmac_burgundy_busy_wait(struct snd_pmac *c 33 snd_pmac_burgundy_busy_wait(struct snd_pmac *chip) 21 { 34 { 22 int timeout = 50; 35 int timeout = 50; 23 while ((in_le32(&chip->awacs->codec_ct 36 while ((in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) && timeout--) 24 udelay(1); 37 udelay(1); 25 if (timeout < 0) 38 if (timeout < 0) 26 printk(KERN_DEBUG "burgundy_bu 39 printk(KERN_DEBUG "burgundy_busy_wait: timeout\n"); 27 } 40 } 28 41 29 static inline void 42 static inline void 30 snd_pmac_burgundy_extend_wait(struct snd_pmac 43 snd_pmac_burgundy_extend_wait(struct snd_pmac *chip) 31 { 44 { 32 int timeout; 45 int timeout; 33 timeout = 50; 46 timeout = 50; 34 while (!(in_le32(&chip->awacs->codec_s 47 while (!(in_le32(&chip->awacs->codec_stat) & MASK_EXTEND) && timeout--) 35 udelay(1); 48 udelay(1); 36 if (timeout < 0) 49 if (timeout < 0) 37 printk(KERN_DEBUG "burgundy_ex 50 printk(KERN_DEBUG "burgundy_extend_wait: timeout #1\n"); 38 timeout = 50; 51 timeout = 50; 39 while ((in_le32(&chip->awacs->codec_st 52 while ((in_le32(&chip->awacs->codec_stat) & MASK_EXTEND) && timeout--) 40 udelay(1); 53 udelay(1); 41 if (timeout < 0) 54 if (timeout < 0) 42 printk(KERN_DEBUG "burgundy_ex 55 printk(KERN_DEBUG "burgundy_extend_wait: timeout #2\n"); 43 } 56 } 44 57 45 static void 58 static void 46 snd_pmac_burgundy_wcw(struct snd_pmac *chip, u 59 snd_pmac_burgundy_wcw(struct snd_pmac *chip, unsigned addr, unsigned val) 47 { 60 { 48 out_le32(&chip->awacs->codec_ctrl, add 61 out_le32(&chip->awacs->codec_ctrl, addr + 0x200c00 + (val & 0xff)); 49 snd_pmac_burgundy_busy_wait(chip); 62 snd_pmac_burgundy_busy_wait(chip); 50 out_le32(&chip->awacs->codec_ctrl, add 63 out_le32(&chip->awacs->codec_ctrl, addr + 0x200d00 +((val>>8) & 0xff)); 51 snd_pmac_burgundy_busy_wait(chip); 64 snd_pmac_burgundy_busy_wait(chip); 52 out_le32(&chip->awacs->codec_ctrl, add 65 out_le32(&chip->awacs->codec_ctrl, addr + 0x200e00 +((val>>16) & 0xff)); 53 snd_pmac_burgundy_busy_wait(chip); 66 snd_pmac_burgundy_busy_wait(chip); 54 out_le32(&chip->awacs->codec_ctrl, add 67 out_le32(&chip->awacs->codec_ctrl, addr + 0x200f00 +((val>>24) & 0xff)); 55 snd_pmac_burgundy_busy_wait(chip); 68 snd_pmac_burgundy_busy_wait(chip); 56 } 69 } 57 70 58 static unsigned 71 static unsigned 59 snd_pmac_burgundy_rcw(struct snd_pmac *chip, u 72 snd_pmac_burgundy_rcw(struct snd_pmac *chip, unsigned addr) 60 { 73 { 61 unsigned val = 0; 74 unsigned val = 0; 62 unsigned long flags; 75 unsigned long flags; 63 76 64 spin_lock_irqsave(&chip->reg_lock, fla 77 spin_lock_irqsave(&chip->reg_lock, flags); 65 78 66 out_le32(&chip->awacs->codec_ctrl, add 79 out_le32(&chip->awacs->codec_ctrl, addr + 0x100000); 67 snd_pmac_burgundy_busy_wait(chip); 80 snd_pmac_burgundy_busy_wait(chip); 68 snd_pmac_burgundy_extend_wait(chip); 81 snd_pmac_burgundy_extend_wait(chip); 69 val += (in_le32(&chip->awacs->codec_st 82 val += (in_le32(&chip->awacs->codec_stat) >> 4) & 0xff; 70 83 71 out_le32(&chip->awacs->codec_ctrl, add 84 out_le32(&chip->awacs->codec_ctrl, addr + 0x100100); 72 snd_pmac_burgundy_busy_wait(chip); 85 snd_pmac_burgundy_busy_wait(chip); 73 snd_pmac_burgundy_extend_wait(chip); 86 snd_pmac_burgundy_extend_wait(chip); 74 val += ((in_le32(&chip->awacs->codec_s 87 val += ((in_le32(&chip->awacs->codec_stat)>>4) & 0xff) <<8; 75 88 76 out_le32(&chip->awacs->codec_ctrl, add 89 out_le32(&chip->awacs->codec_ctrl, addr + 0x100200); 77 snd_pmac_burgundy_busy_wait(chip); 90 snd_pmac_burgundy_busy_wait(chip); 78 snd_pmac_burgundy_extend_wait(chip); 91 snd_pmac_burgundy_extend_wait(chip); 79 val += ((in_le32(&chip->awacs->codec_s 92 val += ((in_le32(&chip->awacs->codec_stat)>>4) & 0xff) <<16; 80 93 81 out_le32(&chip->awacs->codec_ctrl, add 94 out_le32(&chip->awacs->codec_ctrl, addr + 0x100300); 82 snd_pmac_burgundy_busy_wait(chip); 95 snd_pmac_burgundy_busy_wait(chip); 83 snd_pmac_burgundy_extend_wait(chip); 96 snd_pmac_burgundy_extend_wait(chip); 84 val += ((in_le32(&chip->awacs->codec_s 97 val += ((in_le32(&chip->awacs->codec_stat)>>4) & 0xff) <<24; 85 98 86 spin_unlock_irqrestore(&chip->reg_lock 99 spin_unlock_irqrestore(&chip->reg_lock, flags); 87 100 88 return val; 101 return val; 89 } 102 } 90 103 91 static void 104 static void 92 snd_pmac_burgundy_wcb(struct snd_pmac *chip, u 105 snd_pmac_burgundy_wcb(struct snd_pmac *chip, unsigned int addr, 93 unsigned int val) 106 unsigned int val) 94 { 107 { 95 out_le32(&chip->awacs->codec_ctrl, add 108 out_le32(&chip->awacs->codec_ctrl, addr + 0x300000 + (val & 0xff)); 96 snd_pmac_burgundy_busy_wait(chip); 109 snd_pmac_burgundy_busy_wait(chip); 97 } 110 } 98 111 99 static unsigned 112 static unsigned 100 snd_pmac_burgundy_rcb(struct snd_pmac *chip, u 113 snd_pmac_burgundy_rcb(struct snd_pmac *chip, unsigned int addr) 101 { 114 { 102 unsigned val = 0; 115 unsigned val = 0; 103 unsigned long flags; 116 unsigned long flags; 104 117 105 spin_lock_irqsave(&chip->reg_lock, fla 118 spin_lock_irqsave(&chip->reg_lock, flags); 106 119 107 out_le32(&chip->awacs->codec_ctrl, add 120 out_le32(&chip->awacs->codec_ctrl, addr + 0x100000); 108 snd_pmac_burgundy_busy_wait(chip); 121 snd_pmac_burgundy_busy_wait(chip); 109 snd_pmac_burgundy_extend_wait(chip); 122 snd_pmac_burgundy_extend_wait(chip); 110 val += (in_le32(&chip->awacs->codec_st 123 val += (in_le32(&chip->awacs->codec_stat) >> 4) & 0xff; 111 124 112 spin_unlock_irqrestore(&chip->reg_lock 125 spin_unlock_irqrestore(&chip->reg_lock, flags); 113 126 114 return val; 127 return val; 115 } 128 } 116 129 117 #define BASE2ADDR(base) ((base) << 12) 130 #define BASE2ADDR(base) ((base) << 12) 118 #define ADDR2BASE(addr) ((addr) >> 12) 131 #define ADDR2BASE(addr) ((addr) >> 12) 119 132 120 /* 133 /* 121 * Burgundy volume: 0 - 100, stereo, word reg 134 * Burgundy volume: 0 - 100, stereo, word reg 122 */ 135 */ 123 static void 136 static void 124 snd_pmac_burgundy_write_volume(struct snd_pmac 137 snd_pmac_burgundy_write_volume(struct snd_pmac *chip, unsigned int address, 125 long *volume, i 138 long *volume, int shift) 126 { 139 { 127 int hardvolume, lvolume, rvolume; 140 int hardvolume, lvolume, rvolume; 128 141 129 if (volume[0] < 0 || volume[0] > 100 | 142 if (volume[0] < 0 || volume[0] > 100 || 130 volume[1] < 0 || volume[1] > 100) 143 volume[1] < 0 || volume[1] > 100) 131 return; /* -EINVAL */ 144 return; /* -EINVAL */ 132 lvolume = volume[0] ? volume[0] + BURG 145 lvolume = volume[0] ? volume[0] + BURGUNDY_VOLUME_OFFSET : 0; 133 rvolume = volume[1] ? volume[1] + BURG 146 rvolume = volume[1] ? volume[1] + BURGUNDY_VOLUME_OFFSET : 0; 134 147 135 hardvolume = lvolume + (rvolume << shi 148 hardvolume = lvolume + (rvolume << shift); 136 if (shift == 8) 149 if (shift == 8) 137 hardvolume |= hardvolume << 16 150 hardvolume |= hardvolume << 16; 138 151 139 snd_pmac_burgundy_wcw(chip, address, h 152 snd_pmac_burgundy_wcw(chip, address, hardvolume); 140 } 153 } 141 154 142 static void 155 static void 143 snd_pmac_burgundy_read_volume(struct snd_pmac 156 snd_pmac_burgundy_read_volume(struct snd_pmac *chip, unsigned int address, 144 long *volume, in 157 long *volume, int shift) 145 { 158 { 146 int wvolume; 159 int wvolume; 147 160 148 wvolume = snd_pmac_burgundy_rcw(chip, 161 wvolume = snd_pmac_burgundy_rcw(chip, address); 149 162 150 volume[0] = wvolume & 0xff; 163 volume[0] = wvolume & 0xff; 151 if (volume[0] >= BURGUNDY_VOLUME_OFFSE 164 if (volume[0] >= BURGUNDY_VOLUME_OFFSET) 152 volume[0] -= BURGUNDY_VOLUME_O 165 volume[0] -= BURGUNDY_VOLUME_OFFSET; 153 else 166 else 154 volume[0] = 0; 167 volume[0] = 0; 155 volume[1] = (wvolume >> shift) & 0xff; 168 volume[1] = (wvolume >> shift) & 0xff; 156 if (volume[1] >= BURGUNDY_VOLUME_OFFSE 169 if (volume[1] >= BURGUNDY_VOLUME_OFFSET) 157 volume[1] -= BURGUNDY_VOLUME_O 170 volume[1] -= BURGUNDY_VOLUME_OFFSET; 158 else 171 else 159 volume[1] = 0; 172 volume[1] = 0; 160 } 173 } 161 174 162 static int snd_pmac_burgundy_info_volume(struc 175 static int snd_pmac_burgundy_info_volume(struct snd_kcontrol *kcontrol, 163 struc 176 struct snd_ctl_elem_info *uinfo) 164 { 177 { 165 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE 178 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 166 uinfo->count = 2; 179 uinfo->count = 2; 167 uinfo->value.integer.min = 0; 180 uinfo->value.integer.min = 0; 168 uinfo->value.integer.max = 100; 181 uinfo->value.integer.max = 100; 169 return 0; 182 return 0; 170 } 183 } 171 184 172 static int snd_pmac_burgundy_get_volume(struct 185 static int snd_pmac_burgundy_get_volume(struct snd_kcontrol *kcontrol, 173 struct 186 struct snd_ctl_elem_value *ucontrol) 174 { 187 { 175 struct snd_pmac *chip = snd_kcontrol_c 188 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 176 unsigned int addr = BASE2ADDR(kcontrol 189 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 177 int shift = (kcontrol->private_value > 190 int shift = (kcontrol->private_value >> 8) & 0xff; 178 snd_pmac_burgundy_read_volume(chip, ad 191 snd_pmac_burgundy_read_volume(chip, addr, 179 ucontrol 192 ucontrol->value.integer.value, shift); 180 return 0; 193 return 0; 181 } 194 } 182 195 183 static int snd_pmac_burgundy_put_volume(struct 196 static int snd_pmac_burgundy_put_volume(struct snd_kcontrol *kcontrol, 184 struct 197 struct snd_ctl_elem_value *ucontrol) 185 { 198 { 186 struct snd_pmac *chip = snd_kcontrol_c 199 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 187 unsigned int addr = BASE2ADDR(kcontrol 200 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 188 int shift = (kcontrol->private_value > 201 int shift = (kcontrol->private_value >> 8) & 0xff; 189 long nvoices[2]; 202 long nvoices[2]; 190 203 191 snd_pmac_burgundy_write_volume(chip, a 204 snd_pmac_burgundy_write_volume(chip, addr, 192 ucontro 205 ucontrol->value.integer.value, shift); 193 snd_pmac_burgundy_read_volume(chip, ad 206 snd_pmac_burgundy_read_volume(chip, addr, nvoices, shift); 194 return (nvoices[0] != ucontrol->value. 207 return (nvoices[0] != ucontrol->value.integer.value[0] || 195 nvoices[1] != ucontrol->value. 208 nvoices[1] != ucontrol->value.integer.value[1]); 196 } 209 } 197 210 198 #define BURGUNDY_VOLUME_W(xname, xindex, addr, 211 #define BURGUNDY_VOLUME_W(xname, xindex, addr, shift) \ 199 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = 212 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 200 .info = snd_pmac_burgundy_info_volume,\ 213 .info = snd_pmac_burgundy_info_volume,\ 201 .get = snd_pmac_burgundy_get_volume,\ 214 .get = snd_pmac_burgundy_get_volume,\ 202 .put = snd_pmac_burgundy_put_volume,\ 215 .put = snd_pmac_burgundy_put_volume,\ 203 .private_value = ((ADDR2BASE(addr) & 0xff) | 216 .private_value = ((ADDR2BASE(addr) & 0xff) | ((shift) << 8)) } 204 217 205 /* 218 /* 206 * Burgundy volume: 0 - 100, stereo, 2-byte re 219 * Burgundy volume: 0 - 100, stereo, 2-byte reg 207 */ 220 */ 208 static void 221 static void 209 snd_pmac_burgundy_write_volume_2b(struct snd_p 222 snd_pmac_burgundy_write_volume_2b(struct snd_pmac *chip, unsigned int address, 210 long *volume 223 long *volume, int off) 211 { 224 { 212 int lvolume, rvolume; 225 int lvolume, rvolume; 213 226 214 off |= off << 2; 227 off |= off << 2; 215 lvolume = volume[0] ? volume[0] + BURG 228 lvolume = volume[0] ? volume[0] + BURGUNDY_VOLUME_OFFSET : 0; 216 rvolume = volume[1] ? volume[1] + BURG 229 rvolume = volume[1] ? volume[1] + BURGUNDY_VOLUME_OFFSET : 0; 217 230 218 snd_pmac_burgundy_wcb(chip, address + 231 snd_pmac_burgundy_wcb(chip, address + off, lvolume); 219 snd_pmac_burgundy_wcb(chip, address + 232 snd_pmac_burgundy_wcb(chip, address + off + 0x500, rvolume); 220 } 233 } 221 234 222 static void 235 static void 223 snd_pmac_burgundy_read_volume_2b(struct snd_pm 236 snd_pmac_burgundy_read_volume_2b(struct snd_pmac *chip, unsigned int address, 224 long *volume, 237 long *volume, int off) 225 { 238 { 226 volume[0] = snd_pmac_burgundy_rcb(chip 239 volume[0] = snd_pmac_burgundy_rcb(chip, address + off); 227 if (volume[0] >= BURGUNDY_VOLUME_OFFSE 240 if (volume[0] >= BURGUNDY_VOLUME_OFFSET) 228 volume[0] -= BURGUNDY_VOLUME_O 241 volume[0] -= BURGUNDY_VOLUME_OFFSET; 229 else 242 else 230 volume[0] = 0; 243 volume[0] = 0; 231 volume[1] = snd_pmac_burgundy_rcb(chip 244 volume[1] = snd_pmac_burgundy_rcb(chip, address + off + 0x100); 232 if (volume[1] >= BURGUNDY_VOLUME_OFFSE 245 if (volume[1] >= BURGUNDY_VOLUME_OFFSET) 233 volume[1] -= BURGUNDY_VOLUME_O 246 volume[1] -= BURGUNDY_VOLUME_OFFSET; 234 else 247 else 235 volume[1] = 0; 248 volume[1] = 0; 236 } 249 } 237 250 238 static int snd_pmac_burgundy_info_volume_2b(st 251 static int snd_pmac_burgundy_info_volume_2b(struct snd_kcontrol *kcontrol, 239 st 252 struct snd_ctl_elem_info *uinfo) 240 { 253 { 241 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE 254 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 242 uinfo->count = 2; 255 uinfo->count = 2; 243 uinfo->value.integer.min = 0; 256 uinfo->value.integer.min = 0; 244 uinfo->value.integer.max = 100; 257 uinfo->value.integer.max = 100; 245 return 0; 258 return 0; 246 } 259 } 247 260 248 static int snd_pmac_burgundy_get_volume_2b(str 261 static int snd_pmac_burgundy_get_volume_2b(struct snd_kcontrol *kcontrol, 249 str 262 struct snd_ctl_elem_value *ucontrol) 250 { 263 { 251 struct snd_pmac *chip = snd_kcontrol_c 264 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 252 unsigned int addr = BASE2ADDR(kcontrol 265 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 253 int off = kcontrol->private_value & 0x 266 int off = kcontrol->private_value & 0x300; 254 snd_pmac_burgundy_read_volume_2b(chip, 267 snd_pmac_burgundy_read_volume_2b(chip, addr, 255 ucontrol->value.intege 268 ucontrol->value.integer.value, off); 256 return 0; 269 return 0; 257 } 270 } 258 271 259 static int snd_pmac_burgundy_put_volume_2b(str 272 static int snd_pmac_burgundy_put_volume_2b(struct snd_kcontrol *kcontrol, 260 str 273 struct snd_ctl_elem_value *ucontrol) 261 { 274 { 262 struct snd_pmac *chip = snd_kcontrol_c 275 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 263 unsigned int addr = BASE2ADDR(kcontrol 276 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 264 int off = kcontrol->private_value & 0x 277 int off = kcontrol->private_value & 0x300; 265 long nvoices[2]; 278 long nvoices[2]; 266 279 267 snd_pmac_burgundy_write_volume_2b(chip 280 snd_pmac_burgundy_write_volume_2b(chip, addr, 268 ucontrol->value.intege 281 ucontrol->value.integer.value, off); 269 snd_pmac_burgundy_read_volume_2b(chip, 282 snd_pmac_burgundy_read_volume_2b(chip, addr, nvoices, off); 270 return (nvoices[0] != ucontrol->value. 283 return (nvoices[0] != ucontrol->value.integer.value[0] || 271 nvoices[1] != ucontrol->value. 284 nvoices[1] != ucontrol->value.integer.value[1]); 272 } 285 } 273 286 274 #define BURGUNDY_VOLUME_2B(xname, xindex, addr 287 #define BURGUNDY_VOLUME_2B(xname, xindex, addr, off) \ 275 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = 288 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 276 .info = snd_pmac_burgundy_info_volume_2b,\ 289 .info = snd_pmac_burgundy_info_volume_2b,\ 277 .get = snd_pmac_burgundy_get_volume_2b,\ 290 .get = snd_pmac_burgundy_get_volume_2b,\ 278 .put = snd_pmac_burgundy_put_volume_2b,\ 291 .put = snd_pmac_burgundy_put_volume_2b,\ 279 .private_value = ((ADDR2BASE(addr) & 0xff) | 292 .private_value = ((ADDR2BASE(addr) & 0xff) | ((off) << 8)) } 280 293 281 /* 294 /* 282 * Burgundy gain/attenuation: 0 - 15, mono/ste 295 * Burgundy gain/attenuation: 0 - 15, mono/stereo, byte reg 283 */ 296 */ 284 static int snd_pmac_burgundy_info_gain(struct 297 static int snd_pmac_burgundy_info_gain(struct snd_kcontrol *kcontrol, 285 struct 298 struct snd_ctl_elem_info *uinfo) 286 { 299 { 287 int stereo = (kcontrol->private_value 300 int stereo = (kcontrol->private_value >> 24) & 1; 288 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE 301 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 289 uinfo->count = stereo + 1; 302 uinfo->count = stereo + 1; 290 uinfo->value.integer.min = 0; 303 uinfo->value.integer.min = 0; 291 uinfo->value.integer.max = 15; 304 uinfo->value.integer.max = 15; 292 return 0; 305 return 0; 293 } 306 } 294 307 295 static int snd_pmac_burgundy_get_gain(struct s 308 static int snd_pmac_burgundy_get_gain(struct snd_kcontrol *kcontrol, 296 struct s 309 struct snd_ctl_elem_value *ucontrol) 297 { 310 { 298 struct snd_pmac *chip = snd_kcontrol_c 311 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 299 unsigned int addr = BASE2ADDR(kcontrol 312 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 300 int stereo = (kcontrol->private_value 313 int stereo = (kcontrol->private_value >> 24) & 1; 301 int atten = (kcontrol->private_value > 314 int atten = (kcontrol->private_value >> 25) & 1; 302 int oval; 315 int oval; 303 316 304 oval = snd_pmac_burgundy_rcb(chip, add 317 oval = snd_pmac_burgundy_rcb(chip, addr); 305 if (atten) 318 if (atten) 306 oval = ~oval & 0xff; 319 oval = ~oval & 0xff; 307 ucontrol->value.integer.value[0] = ova 320 ucontrol->value.integer.value[0] = oval & 0xf; 308 if (stereo) 321 if (stereo) 309 ucontrol->value.integer.value[ 322 ucontrol->value.integer.value[1] = (oval >> 4) & 0xf; 310 return 0; 323 return 0; 311 } 324 } 312 325 313 static int snd_pmac_burgundy_put_gain(struct s 326 static int snd_pmac_burgundy_put_gain(struct snd_kcontrol *kcontrol, 314 struct s 327 struct snd_ctl_elem_value *ucontrol) 315 { 328 { 316 struct snd_pmac *chip = snd_kcontrol_c 329 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 317 unsigned int addr = BASE2ADDR(kcontrol 330 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 318 int stereo = (kcontrol->private_value 331 int stereo = (kcontrol->private_value >> 24) & 1; 319 int atten = (kcontrol->private_value > 332 int atten = (kcontrol->private_value >> 25) & 1; 320 int oval, val; 333 int oval, val; 321 334 322 oval = snd_pmac_burgundy_rcb(chip, add 335 oval = snd_pmac_burgundy_rcb(chip, addr); 323 if (atten) 336 if (atten) 324 oval = ~oval & 0xff; 337 oval = ~oval & 0xff; 325 val = ucontrol->value.integer.value[0] 338 val = ucontrol->value.integer.value[0]; 326 if (stereo) 339 if (stereo) 327 val |= ucontrol->value.integer 340 val |= ucontrol->value.integer.value[1] << 4; 328 else 341 else 329 val |= ucontrol->value.integer 342 val |= ucontrol->value.integer.value[0] << 4; 330 if (atten) 343 if (atten) 331 val = ~val & 0xff; 344 val = ~val & 0xff; 332 snd_pmac_burgundy_wcb(chip, addr, val) 345 snd_pmac_burgundy_wcb(chip, addr, val); 333 return val != oval; 346 return val != oval; 334 } 347 } 335 348 336 #define BURGUNDY_VOLUME_B(xname, xindex, addr, 349 #define BURGUNDY_VOLUME_B(xname, xindex, addr, stereo, atten) \ 337 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = 350 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 338 .info = snd_pmac_burgundy_info_gain,\ 351 .info = snd_pmac_burgundy_info_gain,\ 339 .get = snd_pmac_burgundy_get_gain,\ 352 .get = snd_pmac_burgundy_get_gain,\ 340 .put = snd_pmac_burgundy_put_gain,\ 353 .put = snd_pmac_burgundy_put_gain,\ 341 .private_value = (ADDR2BASE(addr) | ((stereo 354 .private_value = (ADDR2BASE(addr) | ((stereo) << 24) | ((atten) << 25)) } 342 355 343 /* 356 /* 344 * Burgundy switch: 0/1, mono/stereo, word reg 357 * Burgundy switch: 0/1, mono/stereo, word reg 345 */ 358 */ 346 static int snd_pmac_burgundy_info_switch_w(str 359 static int snd_pmac_burgundy_info_switch_w(struct snd_kcontrol *kcontrol, 347 str 360 struct snd_ctl_elem_info *uinfo) 348 { 361 { 349 int stereo = (kcontrol->private_value 362 int stereo = (kcontrol->private_value >> 24) & 1; 350 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOL 363 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 351 uinfo->count = stereo + 1; 364 uinfo->count = stereo + 1; 352 uinfo->value.integer.min = 0; 365 uinfo->value.integer.min = 0; 353 uinfo->value.integer.max = 1; 366 uinfo->value.integer.max = 1; 354 return 0; 367 return 0; 355 } 368 } 356 369 357 static int snd_pmac_burgundy_get_switch_w(stru 370 static int snd_pmac_burgundy_get_switch_w(struct snd_kcontrol *kcontrol, 358 stru 371 struct snd_ctl_elem_value *ucontrol) 359 { 372 { 360 struct snd_pmac *chip = snd_kcontrol_c 373 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 361 unsigned int addr = BASE2ADDR((kcontro 374 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff); 362 int lmask = 1 << (kcontrol->private_va 375 int lmask = 1 << (kcontrol->private_value & 0xff); 363 int rmask = 1 << ((kcontrol->private_v 376 int rmask = 1 << ((kcontrol->private_value >> 8) & 0xff); 364 int stereo = (kcontrol->private_value 377 int stereo = (kcontrol->private_value >> 24) & 1; 365 int val = snd_pmac_burgundy_rcw(chip, 378 int val = snd_pmac_burgundy_rcw(chip, addr); 366 ucontrol->value.integer.value[0] = (va 379 ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0; 367 if (stereo) 380 if (stereo) 368 ucontrol->value.integer.value[ 381 ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0; 369 return 0; 382 return 0; 370 } 383 } 371 384 372 static int snd_pmac_burgundy_put_switch_w(stru 385 static int snd_pmac_burgundy_put_switch_w(struct snd_kcontrol *kcontrol, 373 stru 386 struct snd_ctl_elem_value *ucontrol) 374 { 387 { 375 struct snd_pmac *chip = snd_kcontrol_c 388 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 376 unsigned int addr = BASE2ADDR((kcontro 389 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff); 377 int lmask = 1 << (kcontrol->private_va 390 int lmask = 1 << (kcontrol->private_value & 0xff); 378 int rmask = 1 << ((kcontrol->private_v 391 int rmask = 1 << ((kcontrol->private_value >> 8) & 0xff); 379 int stereo = (kcontrol->private_value 392 int stereo = (kcontrol->private_value >> 24) & 1; 380 int val, oval; 393 int val, oval; 381 oval = snd_pmac_burgundy_rcw(chip, add 394 oval = snd_pmac_burgundy_rcw(chip, addr); 382 val = oval & ~(lmask | (stereo ? rmask 395 val = oval & ~(lmask | (stereo ? rmask : 0)); 383 if (ucontrol->value.integer.value[0]) 396 if (ucontrol->value.integer.value[0]) 384 val |= lmask; 397 val |= lmask; 385 if (stereo && ucontrol->value.integer. 398 if (stereo && ucontrol->value.integer.value[1]) 386 val |= rmask; 399 val |= rmask; 387 snd_pmac_burgundy_wcw(chip, addr, val) 400 snd_pmac_burgundy_wcw(chip, addr, val); 388 return val != oval; 401 return val != oval; 389 } 402 } 390 403 391 #define BURGUNDY_SWITCH_W(xname, xindex, addr, 404 #define BURGUNDY_SWITCH_W(xname, xindex, addr, lbit, rbit, stereo) \ 392 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = 405 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 393 .info = snd_pmac_burgundy_info_switch_w,\ 406 .info = snd_pmac_burgundy_info_switch_w,\ 394 .get = snd_pmac_burgundy_get_switch_w,\ 407 .get = snd_pmac_burgundy_get_switch_w,\ 395 .put = snd_pmac_burgundy_put_switch_w,\ 408 .put = snd_pmac_burgundy_put_switch_w,\ 396 .private_value = ((lbit) | ((rbit) << 8)\ 409 .private_value = ((lbit) | ((rbit) << 8)\ 397 | (ADDR2BASE(addr) << 16) | (( 410 | (ADDR2BASE(addr) << 16) | ((stereo) << 24)) } 398 411 399 /* 412 /* 400 * Burgundy switch: 0/1, mono/stereo, byte reg 413 * Burgundy switch: 0/1, mono/stereo, byte reg, bit mask 401 */ 414 */ 402 static int snd_pmac_burgundy_info_switch_b(str 415 static int snd_pmac_burgundy_info_switch_b(struct snd_kcontrol *kcontrol, 403 str 416 struct snd_ctl_elem_info *uinfo) 404 { 417 { 405 int stereo = (kcontrol->private_value 418 int stereo = (kcontrol->private_value >> 24) & 1; 406 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOL 419 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 407 uinfo->count = stereo + 1; 420 uinfo->count = stereo + 1; 408 uinfo->value.integer.min = 0; 421 uinfo->value.integer.min = 0; 409 uinfo->value.integer.max = 1; 422 uinfo->value.integer.max = 1; 410 return 0; 423 return 0; 411 } 424 } 412 425 413 static int snd_pmac_burgundy_get_switch_b(stru 426 static int snd_pmac_burgundy_get_switch_b(struct snd_kcontrol *kcontrol, 414 stru 427 struct snd_ctl_elem_value *ucontrol) 415 { 428 { 416 struct snd_pmac *chip = snd_kcontrol_c 429 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 417 unsigned int addr = BASE2ADDR((kcontro 430 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff); 418 int lmask = kcontrol->private_value & 431 int lmask = kcontrol->private_value & 0xff; 419 int rmask = (kcontrol->private_value > 432 int rmask = (kcontrol->private_value >> 8) & 0xff; 420 int stereo = (kcontrol->private_value 433 int stereo = (kcontrol->private_value >> 24) & 1; 421 int val = snd_pmac_burgundy_rcb(chip, 434 int val = snd_pmac_burgundy_rcb(chip, addr); 422 ucontrol->value.integer.value[0] = (va 435 ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0; 423 if (stereo) 436 if (stereo) 424 ucontrol->value.integer.value[ 437 ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0; 425 return 0; 438 return 0; 426 } 439 } 427 440 428 static int snd_pmac_burgundy_put_switch_b(stru 441 static int snd_pmac_burgundy_put_switch_b(struct snd_kcontrol *kcontrol, 429 stru 442 struct snd_ctl_elem_value *ucontrol) 430 { 443 { 431 struct snd_pmac *chip = snd_kcontrol_c 444 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 432 unsigned int addr = BASE2ADDR((kcontro 445 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff); 433 int lmask = kcontrol->private_value & 446 int lmask = kcontrol->private_value & 0xff; 434 int rmask = (kcontrol->private_value > 447 int rmask = (kcontrol->private_value >> 8) & 0xff; 435 int stereo = (kcontrol->private_value 448 int stereo = (kcontrol->private_value >> 24) & 1; 436 int val, oval; 449 int val, oval; 437 oval = snd_pmac_burgundy_rcb(chip, add 450 oval = snd_pmac_burgundy_rcb(chip, addr); 438 val = oval & ~(lmask | rmask); 451 val = oval & ~(lmask | rmask); 439 if (ucontrol->value.integer.value[0]) 452 if (ucontrol->value.integer.value[0]) 440 val |= lmask; 453 val |= lmask; 441 if (stereo && ucontrol->value.integer. 454 if (stereo && ucontrol->value.integer.value[1]) 442 val |= rmask; 455 val |= rmask; 443 snd_pmac_burgundy_wcb(chip, addr, val) 456 snd_pmac_burgundy_wcb(chip, addr, val); 444 return val != oval; 457 return val != oval; 445 } 458 } 446 459 447 #define BURGUNDY_SWITCH_B(xname, xindex, addr, 460 #define BURGUNDY_SWITCH_B(xname, xindex, addr, lmask, rmask, stereo) \ 448 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = 461 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 449 .info = snd_pmac_burgundy_info_switch_b,\ 462 .info = snd_pmac_burgundy_info_switch_b,\ 450 .get = snd_pmac_burgundy_get_switch_b,\ 463 .get = snd_pmac_burgundy_get_switch_b,\ 451 .put = snd_pmac_burgundy_put_switch_b,\ 464 .put = snd_pmac_burgundy_put_switch_b,\ 452 .private_value = ((lmask) | ((rmask) << 8)\ 465 .private_value = ((lmask) | ((rmask) << 8)\ 453 | (ADDR2BASE(addr) << 16) | (( 466 | (ADDR2BASE(addr) << 16) | ((stereo) << 24)) } 454 467 455 /* 468 /* 456 * Burgundy mixers 469 * Burgundy mixers 457 */ 470 */ 458 static const struct snd_kcontrol_new snd_pmac_ !! 471 static struct snd_kcontrol_new snd_pmac_burgundy_mixers[] __devinitdata = { 459 BURGUNDY_VOLUME_W("Master Playback Vol 472 BURGUNDY_VOLUME_W("Master Playback Volume", 0, 460 MASK_ADDR_BURGUNDY_MAS 473 MASK_ADDR_BURGUNDY_MASTER_VOLUME, 8), 461 BURGUNDY_VOLUME_W("CD Capture Volume", 474 BURGUNDY_VOLUME_W("CD Capture Volume", 0, 462 MASK_ADDR_BURGUNDY_VOL 475 MASK_ADDR_BURGUNDY_VOLCD, 16), 463 BURGUNDY_VOLUME_2B("Input Capture Volu 476 BURGUNDY_VOLUME_2B("Input Capture Volume", 0, 464 MASK_ADDR_BURGUNDY_VOL 477 MASK_ADDR_BURGUNDY_VOLMIX01, 2), 465 BURGUNDY_VOLUME_2B("Mixer Playback Vol 478 BURGUNDY_VOLUME_2B("Mixer Playback Volume", 0, 466 MASK_ADDR_BURGUNDY_VOL 479 MASK_ADDR_BURGUNDY_VOLMIX23, 0), 467 BURGUNDY_VOLUME_B("CD Gain Capture Vol 480 BURGUNDY_VOLUME_B("CD Gain Capture Volume", 0, 468 MASK_ADDR_BURGUNDY_GAI 481 MASK_ADDR_BURGUNDY_GAINCD, 1, 0), 469 BURGUNDY_SWITCH_W("Master Capture Swit 482 BURGUNDY_SWITCH_W("Master Capture Switch", 0, 470 MASK_ADDR_BURGUNDY_OUT 483 MASK_ADDR_BURGUNDY_OUTPUTENABLES, 24, 0, 0), 471 BURGUNDY_SWITCH_W("CD Capture Switch", 484 BURGUNDY_SWITCH_W("CD Capture Switch", 0, 472 MASK_ADDR_BURGUNDY_CAP 485 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 0, 16, 1), 473 BURGUNDY_SWITCH_W("CD Playback Switch" 486 BURGUNDY_SWITCH_W("CD Playback Switch", 0, 474 MASK_ADDR_BURGUNDY_OUT 487 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 0, 16, 1), 475 /* BURGUNDY_SWITCH_W("Loop Capture Switch 488 /* BURGUNDY_SWITCH_W("Loop Capture Switch", 0, 476 * MASK_ADDR_BURGUNDY_CAPTURESELE 489 * MASK_ADDR_BURGUNDY_CAPTURESELECTS, 8, 24, 1), 477 * BURGUNDY_SWITCH_B("Mixer out Capture S 490 * BURGUNDY_SWITCH_B("Mixer out Capture Switch", 0, 478 * MASK_ADDR_BURGUNDY_HOSTIFAD, 0 491 * MASK_ADDR_BURGUNDY_HOSTIFAD, 0x02, 0, 0), 479 * BURGUNDY_SWITCH_B("Mixer Capture Switc 492 * BURGUNDY_SWITCH_B("Mixer Capture Switch", 0, 480 * MASK_ADDR_BURGUNDY_HOSTIFAD, 0 493 * MASK_ADDR_BURGUNDY_HOSTIFAD, 0x01, 0, 0), 481 * BURGUNDY_SWITCH_B("PCM out Capture Swi 494 * BURGUNDY_SWITCH_B("PCM out Capture Switch", 0, 482 * MASK_ADDR_BURGUNDY_HOSTIFEH, 0 495 * MASK_ADDR_BURGUNDY_HOSTIFEH, 0x02, 0, 0), 483 */ BURGUNDY_SWITCH_B("PCM Capture Switch" 496 */ BURGUNDY_SWITCH_B("PCM Capture Switch", 0, 484 MASK_ADDR_BURGUNDY_HOS 497 MASK_ADDR_BURGUNDY_HOSTIFEH, 0x01, 0, 0) 485 }; 498 }; 486 static const struct snd_kcontrol_new snd_pmac_ !! 499 static struct snd_kcontrol_new snd_pmac_burgundy_mixers_imac[] __devinitdata = { 487 BURGUNDY_VOLUME_W("Line in Capture Vol 500 BURGUNDY_VOLUME_W("Line in Capture Volume", 0, 488 MASK_ADDR_BURGUNDY_VOL 501 MASK_ADDR_BURGUNDY_VOLLINE, 16), 489 BURGUNDY_VOLUME_W("Mic Capture Volume" 502 BURGUNDY_VOLUME_W("Mic Capture Volume", 0, 490 MASK_ADDR_BURGUNDY_VOL 503 MASK_ADDR_BURGUNDY_VOLMIC, 16), 491 BURGUNDY_VOLUME_B("Line in Gain Captur 504 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0, 492 MASK_ADDR_BURGUNDY_GAI 505 MASK_ADDR_BURGUNDY_GAINLINE, 1, 0), 493 BURGUNDY_VOLUME_B("Mic Gain Capture Vo 506 BURGUNDY_VOLUME_B("Mic Gain Capture Volume", 0, 494 MASK_ADDR_BURGUNDY_GAI 507 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0), 495 BURGUNDY_VOLUME_B("Speaker Playback Vo !! 508 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0, 496 MASK_ADDR_BURGUNDY_ATT 509 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1), 497 BURGUNDY_VOLUME_B("Line out Playback V 510 BURGUNDY_VOLUME_B("Line out Playback Volume", 0, 498 MASK_ADDR_BURGUNDY_ATT 511 MASK_ADDR_BURGUNDY_ATTENLINEOUT, 1, 1), 499 BURGUNDY_VOLUME_B("Headphone Playback 512 BURGUNDY_VOLUME_B("Headphone Playback Volume", 0, 500 MASK_ADDR_BURGUNDY_ATT 513 MASK_ADDR_BURGUNDY_ATTENHP, 1, 1), 501 BURGUNDY_SWITCH_W("Line in Capture Swi 514 BURGUNDY_SWITCH_W("Line in Capture Switch", 0, 502 MASK_ADDR_BURGUNDY_CAP 515 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 1, 17, 1), 503 BURGUNDY_SWITCH_W("Mic Capture Switch" 516 BURGUNDY_SWITCH_W("Mic Capture Switch", 0, 504 MASK_ADDR_BURGUNDY_CAP 517 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 2, 18, 1), 505 BURGUNDY_SWITCH_W("Line in Playback Sw 518 BURGUNDY_SWITCH_W("Line in Playback Switch", 0, 506 MASK_ADDR_BURGUNDY_OUT 519 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 1, 17, 1), 507 BURGUNDY_SWITCH_W("Mic Playback Switch 520 BURGUNDY_SWITCH_W("Mic Playback Switch", 0, 508 MASK_ADDR_BURGUNDY_OUT 521 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 2, 18, 1), 509 BURGUNDY_SWITCH_B("Mic Boost Capture S 522 BURGUNDY_SWITCH_B("Mic Boost Capture Switch", 0, 510 MASK_ADDR_BURGUNDY_INP 523 MASK_ADDR_BURGUNDY_INPBOOST, 0x40, 0x80, 1) 511 }; 524 }; 512 static const struct snd_kcontrol_new snd_pmac_ !! 525 static struct snd_kcontrol_new snd_pmac_burgundy_mixers_pmac[] __devinitdata = { 513 BURGUNDY_VOLUME_W("Line in Capture Vol 526 BURGUNDY_VOLUME_W("Line in Capture Volume", 0, 514 MASK_ADDR_BURGUNDY_VOL 527 MASK_ADDR_BURGUNDY_VOLMIC, 16), 515 BURGUNDY_VOLUME_B("Line in Gain Captur 528 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0, 516 MASK_ADDR_BURGUNDY_GAI 529 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0), 517 BURGUNDY_VOLUME_B("Speaker Playback Vo !! 530 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0, 518 MASK_ADDR_BURGUNDY_ATT 531 MASK_ADDR_BURGUNDY_ATTENMONO, 0, 1), 519 BURGUNDY_VOLUME_B("Line out Playback V 532 BURGUNDY_VOLUME_B("Line out Playback Volume", 0, 520 MASK_ADDR_BURGUNDY_ATT 533 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1), 521 BURGUNDY_SWITCH_W("Line in Capture Swi 534 BURGUNDY_SWITCH_W("Line in Capture Switch", 0, 522 MASK_ADDR_BURGUNDY_CAP 535 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 2, 18, 1), 523 BURGUNDY_SWITCH_W("Line in Playback Sw 536 BURGUNDY_SWITCH_W("Line in Playback Switch", 0, 524 MASK_ADDR_BURGUNDY_OUT 537 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 2, 18, 1), 525 /* BURGUNDY_SWITCH_B("Line in Boost Captu 538 /* BURGUNDY_SWITCH_B("Line in Boost Capture Switch", 0, 526 * MASK_ADDR_BURGUNDY_INPBOOST, 0 539 * MASK_ADDR_BURGUNDY_INPBOOST, 0x40, 0x80, 1) */ 527 }; 540 }; 528 static const struct snd_kcontrol_new snd_pmac_ !! 541 static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_imac __devinitdata = 529 BURGUNDY_SWITCH_B("Master Playback Switch", 0, 542 BURGUNDY_SWITCH_B("Master Playback Switch", 0, 530 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 543 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 531 BURGUNDY_OUTPUT_LEFT | BURGUNDY_LINEOU 544 BURGUNDY_OUTPUT_LEFT | BURGUNDY_LINEOUT_LEFT | BURGUNDY_HP_LEFT, 532 BURGUNDY_OUTPUT_RIGHT | BURGUNDY_LINEO 545 BURGUNDY_OUTPUT_RIGHT | BURGUNDY_LINEOUT_RIGHT | BURGUNDY_HP_RIGHT, 1); 533 static const struct snd_kcontrol_new snd_pmac_ !! 546 static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_pmac __devinitdata = 534 BURGUNDY_SWITCH_B("Master Playback Switch", 0, 547 BURGUNDY_SWITCH_B("Master Playback Switch", 0, 535 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 548 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 536 BURGUNDY_OUTPUT_INTERN 549 BURGUNDY_OUTPUT_INTERN 537 | BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPU 550 | BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1); 538 static const struct snd_kcontrol_new snd_pmac_ !! 551 static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_imac __devinitdata = 539 BURGUNDY_SWITCH_B("Speaker Playback Switch", 0 !! 552 BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0, 540 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 553 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 541 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_ 554 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1); 542 static const struct snd_kcontrol_new snd_pmac_ !! 555 static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_pmac __devinitdata = 543 BURGUNDY_SWITCH_B("Speaker Playback Switch", 0 !! 556 BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0, 544 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 557 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 545 BURGUNDY_OUTPUT_INTERN, 0, 0); 558 BURGUNDY_OUTPUT_INTERN, 0, 0); 546 static const struct snd_kcontrol_new snd_pmac_ !! 559 static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_imac __devinitdata = 547 BURGUNDY_SWITCH_B("Line out Playback Switch", 560 BURGUNDY_SWITCH_B("Line out Playback Switch", 0, 548 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 561 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 549 BURGUNDY_LINEOUT_LEFT, BURGUNDY_LINEOU 562 BURGUNDY_LINEOUT_LEFT, BURGUNDY_LINEOUT_RIGHT, 1); 550 static const struct snd_kcontrol_new snd_pmac_ !! 563 static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_pmac __devinitdata = 551 BURGUNDY_SWITCH_B("Line out Playback Switch", 564 BURGUNDY_SWITCH_B("Line out Playback Switch", 0, 552 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 565 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 553 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_ 566 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1); 554 static const struct snd_kcontrol_new snd_pmac_ !! 567 static struct snd_kcontrol_new snd_pmac_burgundy_hp_sw_imac __devinitdata = 555 BURGUNDY_SWITCH_B("Headphone Playback Switch", 568 BURGUNDY_SWITCH_B("Headphone Playback Switch", 0, 556 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 569 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 557 BURGUNDY_HP_LEFT, BURGUNDY_HP_RIGHT, 1 570 BURGUNDY_HP_LEFT, BURGUNDY_HP_RIGHT, 1); 558 571 559 572 560 #ifdef PMAC_SUPPORT_AUTOMUTE 573 #ifdef PMAC_SUPPORT_AUTOMUTE 561 /* 574 /* 562 * auto-mute stuffs 575 * auto-mute stuffs 563 */ 576 */ 564 static int snd_pmac_burgundy_detect_headphone( 577 static int snd_pmac_burgundy_detect_headphone(struct snd_pmac *chip) 565 { 578 { 566 return (in_le32(&chip->awacs->codec_st 579 return (in_le32(&chip->awacs->codec_stat) & chip->hp_stat_mask) ? 1 : 0; 567 } 580 } 568 581 569 static void snd_pmac_burgundy_update_automute( 582 static void snd_pmac_burgundy_update_automute(struct snd_pmac *chip, int do_notify) 570 { 583 { 571 if (chip->auto_mute) { 584 if (chip->auto_mute) { 572 int imac = of_machine_is_compa !! 585 int imac = machine_is_compatible("iMac"); 573 int reg, oreg; 586 int reg, oreg; 574 reg = oreg = snd_pmac_burgundy 587 reg = oreg = snd_pmac_burgundy_rcb(chip, 575 MASK_ADDR_BURG 588 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES); 576 reg &= imac ? ~(BURGUNDY_OUTPU 589 reg &= imac ? ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT 577 | BURGUNDY_HP_ 590 | BURGUNDY_HP_LEFT | BURGUNDY_HP_RIGHT) 578 : ~(BURGUNDY_OUTPUT_LE 591 : ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT 579 | BURGUNDY_OUT 592 | BURGUNDY_OUTPUT_INTERN); 580 if (snd_pmac_burgundy_detect_h 593 if (snd_pmac_burgundy_detect_headphone(chip)) 581 reg |= imac ? (BURGUND 594 reg |= imac ? (BURGUNDY_HP_LEFT | BURGUNDY_HP_RIGHT) 582 : (BURGUNDY_OU 595 : (BURGUNDY_OUTPUT_LEFT 583 | BURG 596 | BURGUNDY_OUTPUT_RIGHT); 584 else 597 else 585 reg |= imac ? (BURGUND 598 reg |= imac ? (BURGUNDY_OUTPUT_LEFT 586 | BURG 599 | BURGUNDY_OUTPUT_RIGHT) 587 : (BURGUNDY_OU 600 : (BURGUNDY_OUTPUT_INTERN); 588 if (do_notify && reg == oreg) 601 if (do_notify && reg == oreg) 589 return; 602 return; 590 snd_pmac_burgundy_wcb(chip, 603 snd_pmac_burgundy_wcb(chip, 591 MASK_ADDR_BURG 604 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, reg); 592 if (do_notify) { 605 if (do_notify) { 593 snd_ctl_notify(chip->c 606 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, 594 &chip-> 607 &chip->master_sw_ctl->id); 595 snd_ctl_notify(chip->c 608 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, 596 &chip-> 609 &chip->speaker_sw_ctl->id); 597 snd_ctl_notify(chip->c 610 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, 598 &chip-> 611 &chip->hp_detect_ctl->id); 599 } 612 } 600 } 613 } 601 } 614 } 602 #endif /* PMAC_SUPPORT_AUTOMUTE */ 615 #endif /* PMAC_SUPPORT_AUTOMUTE */ 603 616 604 617 605 /* 618 /* 606 * initialize burgundy 619 * initialize burgundy 607 */ 620 */ 608 int snd_pmac_burgundy_init(struct snd_pmac *ch !! 621 int __devinit snd_pmac_burgundy_init(struct snd_pmac *chip) 609 { 622 { 610 int imac = of_machine_is_compatible("i !! 623 int imac = machine_is_compatible("iMac"); 611 int i, err; 624 int i, err; 612 625 613 /* Checks to see the chip is alive and 626 /* Checks to see the chip is alive and kicking */ 614 if ((in_le32(&chip->awacs->codec_ctrl) 627 if ((in_le32(&chip->awacs->codec_ctrl) & MASK_ERRCODE) == 0xf0000) { 615 printk(KERN_WARNING "pmac burg 628 printk(KERN_WARNING "pmac burgundy: disabled by MacOS :-(\n"); 616 return 1; 629 return 1; 617 } 630 } 618 631 619 snd_pmac_burgundy_wcw(chip, MASK_ADDR_ 632 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_OUTPUTENABLES, 620 DEF_BURGUNDY_OUTPUT 633 DEF_BURGUNDY_OUTPUTENABLES); 621 snd_pmac_burgundy_wcb(chip, MASK_ADDR_ 634 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 622 DEF_BURGUNDY_MORE_O 635 DEF_BURGUNDY_MORE_OUTPUTENABLES); 623 snd_pmac_burgundy_wcw(chip, MASK_ADDR_ 636 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 624 DEF_BURGUNDY_OUTPUT 637 DEF_BURGUNDY_OUTPUTSELECTS); 625 638 626 snd_pmac_burgundy_wcb(chip, MASK_ADDR_ 639 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL21, 627 DEF_BURGUNDY_INPSEL 640 DEF_BURGUNDY_INPSEL21); 628 snd_pmac_burgundy_wcb(chip, MASK_ADDR_ 641 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL3, 629 imac ? DEF_BURGUNDY 642 imac ? DEF_BURGUNDY_INPSEL3_IMAC 630 : DEF_BURGUNDY_INPS 643 : DEF_BURGUNDY_INPSEL3_PMAC); 631 snd_pmac_burgundy_wcb(chip, MASK_ADDR_ 644 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINCD, 632 DEF_BURGUNDY_GAINCD 645 DEF_BURGUNDY_GAINCD); 633 snd_pmac_burgundy_wcb(chip, MASK_ADDR_ 646 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINLINE, 634 DEF_BURGUNDY_GAINLI 647 DEF_BURGUNDY_GAINLINE); 635 snd_pmac_burgundy_wcb(chip, MASK_ADDR_ 648 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINMIC, 636 DEF_BURGUNDY_GAINMI 649 DEF_BURGUNDY_GAINMIC); 637 snd_pmac_burgundy_wcb(chip, MASK_ADDR_ 650 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINMODEM, 638 DEF_BURGUNDY_GAINMO 651 DEF_BURGUNDY_GAINMODEM); 639 652 640 snd_pmac_burgundy_wcb(chip, MASK_ADDR_ 653 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_ATTENSPEAKER, 641 DEF_BURGUNDY_ATTENS 654 DEF_BURGUNDY_ATTENSPEAKER); 642 snd_pmac_burgundy_wcb(chip, MASK_ADDR_ 655 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_ATTENLINEOUT, 643 DEF_BURGUNDY_ATTENL 656 DEF_BURGUNDY_ATTENLINEOUT); 644 snd_pmac_burgundy_wcb(chip, MASK_ADDR_ 657 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_ATTENHP, 645 DEF_BURGUNDY_ATTENH 658 DEF_BURGUNDY_ATTENHP); 646 659 647 snd_pmac_burgundy_wcw(chip, MASK_ADDR_ 660 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_MASTER_VOLUME, 648 DEF_BURGUNDY_MASTER 661 DEF_BURGUNDY_MASTER_VOLUME); 649 snd_pmac_burgundy_wcw(chip, MASK_ADDR_ 662 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLCD, 650 DEF_BURGUNDY_VOLCD) 663 DEF_BURGUNDY_VOLCD); 651 snd_pmac_burgundy_wcw(chip, MASK_ADDR_ 664 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLLINE, 652 DEF_BURGUNDY_VOLLIN 665 DEF_BURGUNDY_VOLLINE); 653 snd_pmac_burgundy_wcw(chip, MASK_ADDR_ 666 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLMIC, 654 DEF_BURGUNDY_VOLMIC 667 DEF_BURGUNDY_VOLMIC); 655 668 656 if (chip->hp_stat_mask == 0) { 669 if (chip->hp_stat_mask == 0) { 657 /* set headphone-jack detectio 670 /* set headphone-jack detection bit */ 658 if (imac) 671 if (imac) 659 chip->hp_stat_mask = B 672 chip->hp_stat_mask = BURGUNDY_HPDETECT_IMAC_UPPER 660 | BURGUNDY_HPD 673 | BURGUNDY_HPDETECT_IMAC_LOWER 661 | BURGUNDY_HPD 674 | BURGUNDY_HPDETECT_IMAC_SIDE; 662 else 675 else 663 chip->hp_stat_mask = B 676 chip->hp_stat_mask = BURGUNDY_HPDETECT_PMAC_BACK; 664 } 677 } 665 /* 678 /* 666 * build burgundy mixers 679 * build burgundy mixers 667 */ 680 */ 668 strcpy(chip->card->mixername, "PowerMa 681 strcpy(chip->card->mixername, "PowerMac Burgundy"); 669 682 670 for (i = 0; i < ARRAY_SIZE(snd_pmac_bu 683 for (i = 0; i < ARRAY_SIZE(snd_pmac_burgundy_mixers); i++) { 671 err = snd_ctl_add(chip->card, 684 err = snd_ctl_add(chip->card, 672 snd_ctl_new1(&snd_pmac_bur 685 snd_ctl_new1(&snd_pmac_burgundy_mixers[i], chip)); 673 if (err < 0) 686 if (err < 0) 674 return err; 687 return err; 675 } 688 } 676 for (i = 0; i < (imac ? ARRAY_SIZE(snd 689 for (i = 0; i < (imac ? ARRAY_SIZE(snd_pmac_burgundy_mixers_imac) 677 : ARRAY_SIZE(snd_pmac_ 690 : ARRAY_SIZE(snd_pmac_burgundy_mixers_pmac)); i++) { 678 err = snd_ctl_add(chip->card, 691 err = snd_ctl_add(chip->card, 679 snd_ctl_new1(imac ? &snd_p 692 snd_ctl_new1(imac ? &snd_pmac_burgundy_mixers_imac[i] 680 : &snd_pmac_burgundy_mixer 693 : &snd_pmac_burgundy_mixers_pmac[i], chip)); 681 if (err < 0) 694 if (err < 0) 682 return err; 695 return err; 683 } 696 } 684 chip->master_sw_ctl = snd_ctl_new1(ima 697 chip->master_sw_ctl = snd_ctl_new1(imac 685 ? &snd_pmac_burgundy_m 698 ? &snd_pmac_burgundy_master_sw_imac 686 : &snd_pmac_burgundy_m 699 : &snd_pmac_burgundy_master_sw_pmac, chip); 687 err = snd_ctl_add(chip->card, chip->ma 700 err = snd_ctl_add(chip->card, chip->master_sw_ctl); 688 if (err < 0) 701 if (err < 0) 689 return err; 702 return err; 690 chip->master_sw_ctl = snd_ctl_new1(ima 703 chip->master_sw_ctl = snd_ctl_new1(imac 691 ? &snd_pmac_burgundy_l 704 ? &snd_pmac_burgundy_line_sw_imac 692 : &snd_pmac_burgundy_l 705 : &snd_pmac_burgundy_line_sw_pmac, chip); 693 err = snd_ctl_add(chip->card, chip->ma 706 err = snd_ctl_add(chip->card, chip->master_sw_ctl); 694 if (err < 0) 707 if (err < 0) 695 return err; 708 return err; 696 if (imac) { 709 if (imac) { 697 chip->master_sw_ctl = snd_ctl_ 710 chip->master_sw_ctl = snd_ctl_new1( 698 &snd_pmac_burg 711 &snd_pmac_burgundy_hp_sw_imac, chip); 699 err = snd_ctl_add(chip->card, 712 err = snd_ctl_add(chip->card, chip->master_sw_ctl); 700 if (err < 0) 713 if (err < 0) 701 return err; 714 return err; 702 } 715 } 703 chip->speaker_sw_ctl = snd_ctl_new1(im 716 chip->speaker_sw_ctl = snd_ctl_new1(imac 704 ? &snd_pmac_burgundy_s 717 ? &snd_pmac_burgundy_speaker_sw_imac 705 : &snd_pmac_burgundy_s 718 : &snd_pmac_burgundy_speaker_sw_pmac, chip); 706 err = snd_ctl_add(chip->card, chip->sp 719 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl); 707 if (err < 0) 720 if (err < 0) 708 return err; 721 return err; 709 #ifdef PMAC_SUPPORT_AUTOMUTE 722 #ifdef PMAC_SUPPORT_AUTOMUTE 710 err = snd_pmac_add_automute(chip); 723 err = snd_pmac_add_automute(chip); 711 if (err < 0) 724 if (err < 0) 712 return err; 725 return err; 713 726 714 chip->detect_headphone = snd_pmac_burg 727 chip->detect_headphone = snd_pmac_burgundy_detect_headphone; 715 chip->update_automute = snd_pmac_burgu 728 chip->update_automute = snd_pmac_burgundy_update_automute; 716 snd_pmac_burgundy_update_automute(chip 729 snd_pmac_burgundy_update_automute(chip, 0); /* update the status only */ 717 #endif 730 #endif 718 731 719 return 0; 732 return 0; 720 } 733 } 721 734
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.