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