1 // SPDX-License-Identifier: GPL-2.0-or-later 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 2 /* 3 * ALSA driver for ICEnsemble VT1724 (Envy24 3 * ALSA driver for ICEnsemble VT1724 (Envy24HT) 4 * 4 * 5 * Lowlevel functions for Pontis MS300 5 * Lowlevel functions for Pontis MS300 6 * 6 * 7 * Copyright (c) 2004 Takashi Iwai <tiwai 7 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de> 8 */ 8 */ 9 9 10 #include <linux/delay.h> 10 #include <linux/delay.h> 11 #include <linux/interrupt.h> 11 #include <linux/interrupt.h> 12 #include <linux/init.h> 12 #include <linux/init.h> 13 #include <linux/slab.h> 13 #include <linux/slab.h> 14 #include <linux/mutex.h> 14 #include <linux/mutex.h> 15 15 16 #include <sound/core.h> 16 #include <sound/core.h> 17 #include <sound/info.h> 17 #include <sound/info.h> 18 #include <sound/tlv.h> 18 #include <sound/tlv.h> 19 19 20 #include "ice1712.h" 20 #include "ice1712.h" 21 #include "envy24ht.h" 21 #include "envy24ht.h" 22 #include "pontis.h" 22 #include "pontis.h" 23 23 24 /* I2C addresses */ 24 /* I2C addresses */ 25 #define WM_DEV 0x34 25 #define WM_DEV 0x34 26 #define CS_DEV 0x20 26 #define CS_DEV 0x20 27 27 28 /* WM8776 registers */ 28 /* WM8776 registers */ 29 #define WM_HP_ATTEN_L 0x00 /* hea 29 #define WM_HP_ATTEN_L 0x00 /* headphone left attenuation */ 30 #define WM_HP_ATTEN_R 0x01 /* hea 30 #define WM_HP_ATTEN_R 0x01 /* headphone left attenuation */ 31 #define WM_HP_MASTER 0x02 /* hea 31 #define WM_HP_MASTER 0x02 /* headphone master (both channels) */ 32 /* ove 32 /* override LLR */ 33 #define WM_DAC_ATTEN_L 0x03 /* dig 33 #define WM_DAC_ATTEN_L 0x03 /* digital left attenuation */ 34 #define WM_DAC_ATTEN_R 0x04 34 #define WM_DAC_ATTEN_R 0x04 35 #define WM_DAC_MASTER 0x05 35 #define WM_DAC_MASTER 0x05 36 #define WM_PHASE_SWAP 0x06 /* DAC 36 #define WM_PHASE_SWAP 0x06 /* DAC phase swap */ 37 #define WM_DAC_CTRL1 0x07 37 #define WM_DAC_CTRL1 0x07 38 #define WM_DAC_MUTE 0x08 38 #define WM_DAC_MUTE 0x08 39 #define WM_DAC_CTRL2 0x09 39 #define WM_DAC_CTRL2 0x09 40 #define WM_DAC_INT 0x0a 40 #define WM_DAC_INT 0x0a 41 #define WM_ADC_INT 0x0b 41 #define WM_ADC_INT 0x0b 42 #define WM_MASTER_CTRL 0x0c 42 #define WM_MASTER_CTRL 0x0c 43 #define WM_POWERDOWN 0x0d 43 #define WM_POWERDOWN 0x0d 44 #define WM_ADC_ATTEN_L 0x0e 44 #define WM_ADC_ATTEN_L 0x0e 45 #define WM_ADC_ATTEN_R 0x0f 45 #define WM_ADC_ATTEN_R 0x0f 46 #define WM_ALC_CTRL1 0x10 46 #define WM_ALC_CTRL1 0x10 47 #define WM_ALC_CTRL2 0x11 47 #define WM_ALC_CTRL2 0x11 48 #define WM_ALC_CTRL3 0x12 48 #define WM_ALC_CTRL3 0x12 49 #define WM_NOISE_GATE 0x13 49 #define WM_NOISE_GATE 0x13 50 #define WM_LIMITER 0x14 50 #define WM_LIMITER 0x14 51 #define WM_ADC_MUX 0x15 51 #define WM_ADC_MUX 0x15 52 #define WM_OUT_MUX 0x16 52 #define WM_OUT_MUX 0x16 53 #define WM_RESET 0x17 53 #define WM_RESET 0x17 54 54 55 /* 55 /* 56 * GPIO 56 * GPIO 57 */ 57 */ 58 #define PONTIS_CS_CS (1<<4) /* CS 58 #define PONTIS_CS_CS (1<<4) /* CS */ 59 #define PONTIS_CS_CLK (1<<5) /* CLK 59 #define PONTIS_CS_CLK (1<<5) /* CLK */ 60 #define PONTIS_CS_RDATA (1<<6) /* CS8 60 #define PONTIS_CS_RDATA (1<<6) /* CS8416 -> VT1720 */ 61 #define PONTIS_CS_WDATA (1<<7) /* VT1 61 #define PONTIS_CS_WDATA (1<<7) /* VT1720 -> CS8416 */ 62 62 63 63 64 /* 64 /* 65 * get the current register value of WM codec 65 * get the current register value of WM codec 66 */ 66 */ 67 static unsigned short wm_get(struct snd_ice171 67 static unsigned short wm_get(struct snd_ice1712 *ice, int reg) 68 { 68 { 69 reg <<= 1; 69 reg <<= 1; 70 return ((unsigned short)ice->akm[0].im 70 return ((unsigned short)ice->akm[0].images[reg] << 8) | 71 ice->akm[0].images[reg + 1]; 71 ice->akm[0].images[reg + 1]; 72 } 72 } 73 73 74 /* 74 /* 75 * set the register value of WM codec and reme 75 * set the register value of WM codec and remember it 76 */ 76 */ 77 static void wm_put_nocache(struct snd_ice1712 77 static void wm_put_nocache(struct snd_ice1712 *ice, int reg, unsigned short val) 78 { 78 { 79 unsigned short cval; 79 unsigned short cval; 80 cval = (reg << 9) | val; 80 cval = (reg << 9) | val; 81 snd_vt1724_write_i2c(ice, WM_DEV, cval 81 snd_vt1724_write_i2c(ice, WM_DEV, cval >> 8, cval & 0xff); 82 } 82 } 83 83 84 static void wm_put(struct snd_ice1712 *ice, in 84 static void wm_put(struct snd_ice1712 *ice, int reg, unsigned short val) 85 { 85 { 86 wm_put_nocache(ice, reg, val); 86 wm_put_nocache(ice, reg, val); 87 reg <<= 1; 87 reg <<= 1; 88 ice->akm[0].images[reg] = val >> 8; 88 ice->akm[0].images[reg] = val >> 8; 89 ice->akm[0].images[reg + 1] = val; 89 ice->akm[0].images[reg + 1] = val; 90 } 90 } 91 91 92 /* 92 /* 93 * DAC volume attenuation mixer control (-64dB 93 * DAC volume attenuation mixer control (-64dB to 0dB) 94 */ 94 */ 95 95 96 #define DAC_0dB 0xff 96 #define DAC_0dB 0xff 97 #define DAC_RES 128 97 #define DAC_RES 128 98 #define DAC_MIN (DAC_0dB - DAC_RES) 98 #define DAC_MIN (DAC_0dB - DAC_RES) 99 99 100 static int wm_dac_vol_info(struct snd_kcontrol 100 static int wm_dac_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 101 { 101 { 102 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE 102 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 103 uinfo->count = 2; 103 uinfo->count = 2; 104 uinfo->value.integer.min = 0; /* mut 104 uinfo->value.integer.min = 0; /* mute */ 105 uinfo->value.integer.max = DAC_RES; 105 uinfo->value.integer.max = DAC_RES; /* 0dB, 0.5dB step */ 106 return 0; 106 return 0; 107 } 107 } 108 108 109 static int wm_dac_vol_get(struct snd_kcontrol 109 static int wm_dac_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 110 { 110 { 111 struct snd_ice1712 *ice = snd_kcontrol 111 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 112 unsigned short val; 112 unsigned short val; 113 int i; 113 int i; 114 114 115 mutex_lock(&ice->gpio_mutex); 115 mutex_lock(&ice->gpio_mutex); 116 for (i = 0; i < 2; i++) { 116 for (i = 0; i < 2; i++) { 117 val = wm_get(ice, WM_DAC_ATTEN 117 val = wm_get(ice, WM_DAC_ATTEN_L + i) & 0xff; 118 val = val > DAC_MIN ? (val - D 118 val = val > DAC_MIN ? (val - DAC_MIN) : 0; 119 ucontrol->value.integer.value[ 119 ucontrol->value.integer.value[i] = val; 120 } 120 } 121 mutex_unlock(&ice->gpio_mutex); 121 mutex_unlock(&ice->gpio_mutex); 122 return 0; 122 return 0; 123 } 123 } 124 124 125 static int wm_dac_vol_put(struct snd_kcontrol 125 static int wm_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 126 { 126 { 127 struct snd_ice1712 *ice = snd_kcontrol 127 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 128 unsigned short oval, nval; 128 unsigned short oval, nval; 129 int i, idx, change = 0; 129 int i, idx, change = 0; 130 130 131 mutex_lock(&ice->gpio_mutex); 131 mutex_lock(&ice->gpio_mutex); 132 for (i = 0; i < 2; i++) { 132 for (i = 0; i < 2; i++) { 133 nval = ucontrol->value.integer 133 nval = ucontrol->value.integer.value[i]; 134 nval = (nval ? (nval + DAC_MIN 134 nval = (nval ? (nval + DAC_MIN) : 0) & 0xff; 135 idx = WM_DAC_ATTEN_L + i; 135 idx = WM_DAC_ATTEN_L + i; 136 oval = wm_get(ice, idx) & 0xff 136 oval = wm_get(ice, idx) & 0xff; 137 if (oval != nval) { 137 if (oval != nval) { 138 wm_put(ice, idx, nval) 138 wm_put(ice, idx, nval); 139 wm_put_nocache(ice, id 139 wm_put_nocache(ice, idx, nval | 0x100); 140 change = 1; 140 change = 1; 141 } 141 } 142 } 142 } 143 mutex_unlock(&ice->gpio_mutex); 143 mutex_unlock(&ice->gpio_mutex); 144 return change; 144 return change; 145 } 145 } 146 146 147 /* 147 /* 148 * ADC gain mixer control (-64dB to 0dB) 148 * ADC gain mixer control (-64dB to 0dB) 149 */ 149 */ 150 150 151 #define ADC_0dB 0xcf 151 #define ADC_0dB 0xcf 152 #define ADC_RES 128 152 #define ADC_RES 128 153 #define ADC_MIN (ADC_0dB - ADC_RES) 153 #define ADC_MIN (ADC_0dB - ADC_RES) 154 154 155 static int wm_adc_vol_info(struct snd_kcontrol 155 static int wm_adc_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 156 { 156 { 157 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE 157 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 158 uinfo->count = 2; 158 uinfo->count = 2; 159 uinfo->value.integer.min = 0; /* mut 159 uinfo->value.integer.min = 0; /* mute (-64dB) */ 160 uinfo->value.integer.max = ADC_RES; 160 uinfo->value.integer.max = ADC_RES; /* 0dB, 0.5dB step */ 161 return 0; 161 return 0; 162 } 162 } 163 163 164 static int wm_adc_vol_get(struct snd_kcontrol 164 static int wm_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 165 { 165 { 166 struct snd_ice1712 *ice = snd_kcontrol 166 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 167 unsigned short val; 167 unsigned short val; 168 int i; 168 int i; 169 169 170 mutex_lock(&ice->gpio_mutex); 170 mutex_lock(&ice->gpio_mutex); 171 for (i = 0; i < 2; i++) { 171 for (i = 0; i < 2; i++) { 172 val = wm_get(ice, WM_ADC_ATTEN 172 val = wm_get(ice, WM_ADC_ATTEN_L + i) & 0xff; 173 val = val > ADC_MIN ? (val - A 173 val = val > ADC_MIN ? (val - ADC_MIN) : 0; 174 ucontrol->value.integer.value[ 174 ucontrol->value.integer.value[i] = val; 175 } 175 } 176 mutex_unlock(&ice->gpio_mutex); 176 mutex_unlock(&ice->gpio_mutex); 177 return 0; 177 return 0; 178 } 178 } 179 179 180 static int wm_adc_vol_put(struct snd_kcontrol 180 static int wm_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 181 { 181 { 182 struct snd_ice1712 *ice = snd_kcontrol 182 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 183 unsigned short ovol, nvol; 183 unsigned short ovol, nvol; 184 int i, idx, change = 0; 184 int i, idx, change = 0; 185 185 186 mutex_lock(&ice->gpio_mutex); 186 mutex_lock(&ice->gpio_mutex); 187 for (i = 0; i < 2; i++) { 187 for (i = 0; i < 2; i++) { 188 nvol = ucontrol->value.integer 188 nvol = ucontrol->value.integer.value[i]; 189 nvol = nvol ? (nvol + ADC_MIN) 189 nvol = nvol ? (nvol + ADC_MIN) : 0; 190 idx = WM_ADC_ATTEN_L + i; 190 idx = WM_ADC_ATTEN_L + i; 191 ovol = wm_get(ice, idx) & 0xff 191 ovol = wm_get(ice, idx) & 0xff; 192 if (ovol != nvol) { 192 if (ovol != nvol) { 193 wm_put(ice, idx, nvol) 193 wm_put(ice, idx, nvol); 194 change = 1; 194 change = 1; 195 } 195 } 196 } 196 } 197 mutex_unlock(&ice->gpio_mutex); 197 mutex_unlock(&ice->gpio_mutex); 198 return change; 198 return change; 199 } 199 } 200 200 201 /* 201 /* 202 * ADC input mux mixer control 202 * ADC input mux mixer control 203 */ 203 */ 204 #define wm_adc_mux_info snd_ctl_boolea 204 #define wm_adc_mux_info snd_ctl_boolean_mono_info 205 205 206 static int wm_adc_mux_get(struct snd_kcontrol 206 static int wm_adc_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 207 { 207 { 208 struct snd_ice1712 *ice = snd_kcontrol 208 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 209 int bit = kcontrol->private_value; 209 int bit = kcontrol->private_value; 210 210 211 mutex_lock(&ice->gpio_mutex); 211 mutex_lock(&ice->gpio_mutex); 212 ucontrol->value.integer.value[0] = (wm 212 ucontrol->value.integer.value[0] = (wm_get(ice, WM_ADC_MUX) & (1 << bit)) ? 1 : 0; 213 mutex_unlock(&ice->gpio_mutex); 213 mutex_unlock(&ice->gpio_mutex); 214 return 0; 214 return 0; 215 } 215 } 216 216 217 static int wm_adc_mux_put(struct snd_kcontrol 217 static int wm_adc_mux_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 218 { 218 { 219 struct snd_ice1712 *ice = snd_kcontrol 219 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 220 int bit = kcontrol->private_value; 220 int bit = kcontrol->private_value; 221 unsigned short oval, nval; 221 unsigned short oval, nval; 222 int change; 222 int change; 223 223 224 mutex_lock(&ice->gpio_mutex); 224 mutex_lock(&ice->gpio_mutex); 225 nval = oval = wm_get(ice, WM_ADC_MUX); 225 nval = oval = wm_get(ice, WM_ADC_MUX); 226 if (ucontrol->value.integer.value[0]) 226 if (ucontrol->value.integer.value[0]) 227 nval |= (1 << bit); 227 nval |= (1 << bit); 228 else 228 else 229 nval &= ~(1 << bit); 229 nval &= ~(1 << bit); 230 change = nval != oval; 230 change = nval != oval; 231 if (change) { 231 if (change) { 232 wm_put(ice, WM_ADC_MUX, nval); 232 wm_put(ice, WM_ADC_MUX, nval); 233 } 233 } 234 mutex_unlock(&ice->gpio_mutex); 234 mutex_unlock(&ice->gpio_mutex); 235 return change; 235 return change; 236 } 236 } 237 237 238 /* 238 /* 239 * Analog bypass (In -> Out) 239 * Analog bypass (In -> Out) 240 */ 240 */ 241 #define wm_bypass_info snd_ctl_boolea 241 #define wm_bypass_info snd_ctl_boolean_mono_info 242 242 243 static int wm_bypass_get(struct snd_kcontrol * 243 static int wm_bypass_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 244 { 244 { 245 struct snd_ice1712 *ice = snd_kcontrol 245 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 246 246 247 mutex_lock(&ice->gpio_mutex); 247 mutex_lock(&ice->gpio_mutex); 248 ucontrol->value.integer.value[0] = (wm 248 ucontrol->value.integer.value[0] = (wm_get(ice, WM_OUT_MUX) & 0x04) ? 1 : 0; 249 mutex_unlock(&ice->gpio_mutex); 249 mutex_unlock(&ice->gpio_mutex); 250 return 0; 250 return 0; 251 } 251 } 252 252 253 static int wm_bypass_put(struct snd_kcontrol * 253 static int wm_bypass_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 254 { 254 { 255 struct snd_ice1712 *ice = snd_kcontrol 255 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 256 unsigned short val, oval; 256 unsigned short val, oval; 257 int change = 0; 257 int change = 0; 258 258 259 mutex_lock(&ice->gpio_mutex); 259 mutex_lock(&ice->gpio_mutex); 260 val = oval = wm_get(ice, WM_OUT_MUX); 260 val = oval = wm_get(ice, WM_OUT_MUX); 261 if (ucontrol->value.integer.value[0]) 261 if (ucontrol->value.integer.value[0]) 262 val |= 0x04; 262 val |= 0x04; 263 else 263 else 264 val &= ~0x04; 264 val &= ~0x04; 265 if (val != oval) { 265 if (val != oval) { 266 wm_put(ice, WM_OUT_MUX, val); 266 wm_put(ice, WM_OUT_MUX, val); 267 change = 1; 267 change = 1; 268 } 268 } 269 mutex_unlock(&ice->gpio_mutex); 269 mutex_unlock(&ice->gpio_mutex); 270 return change; 270 return change; 271 } 271 } 272 272 273 /* 273 /* 274 * Left/Right swap 274 * Left/Right swap 275 */ 275 */ 276 #define wm_chswap_info snd_ctl_boolea 276 #define wm_chswap_info snd_ctl_boolean_mono_info 277 277 278 static int wm_chswap_get(struct snd_kcontrol * 278 static int wm_chswap_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 279 { 279 { 280 struct snd_ice1712 *ice = snd_kcontrol 280 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 281 281 282 mutex_lock(&ice->gpio_mutex); 282 mutex_lock(&ice->gpio_mutex); 283 ucontrol->value.integer.value[0] = (wm 283 ucontrol->value.integer.value[0] = (wm_get(ice, WM_DAC_CTRL1) & 0xf0) != 0x90; 284 mutex_unlock(&ice->gpio_mutex); 284 mutex_unlock(&ice->gpio_mutex); 285 return 0; 285 return 0; 286 } 286 } 287 287 288 static int wm_chswap_put(struct snd_kcontrol * 288 static int wm_chswap_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 289 { 289 { 290 struct snd_ice1712 *ice = snd_kcontrol 290 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 291 unsigned short val, oval; 291 unsigned short val, oval; 292 int change = 0; 292 int change = 0; 293 293 294 mutex_lock(&ice->gpio_mutex); 294 mutex_lock(&ice->gpio_mutex); 295 oval = wm_get(ice, WM_DAC_CTRL1); 295 oval = wm_get(ice, WM_DAC_CTRL1); 296 val = oval & 0x0f; 296 val = oval & 0x0f; 297 if (ucontrol->value.integer.value[0]) 297 if (ucontrol->value.integer.value[0]) 298 val |= 0x60; 298 val |= 0x60; 299 else 299 else 300 val |= 0x90; 300 val |= 0x90; 301 if (val != oval) { 301 if (val != oval) { 302 wm_put(ice, WM_DAC_CTRL1, val) 302 wm_put(ice, WM_DAC_CTRL1, val); 303 wm_put_nocache(ice, WM_DAC_CTR 303 wm_put_nocache(ice, WM_DAC_CTRL1, val); 304 change = 1; 304 change = 1; 305 } 305 } 306 mutex_unlock(&ice->gpio_mutex); 306 mutex_unlock(&ice->gpio_mutex); 307 return change; 307 return change; 308 } 308 } 309 309 310 /* 310 /* 311 * write data in the SPI mode 311 * write data in the SPI mode 312 */ 312 */ 313 static void set_gpio_bit(struct snd_ice1712 *i 313 static void set_gpio_bit(struct snd_ice1712 *ice, unsigned int bit, int val) 314 { 314 { 315 unsigned int tmp = snd_ice1712_gpio_re 315 unsigned int tmp = snd_ice1712_gpio_read(ice); 316 if (val) 316 if (val) 317 tmp |= bit; 317 tmp |= bit; 318 else 318 else 319 tmp &= ~bit; 319 tmp &= ~bit; 320 snd_ice1712_gpio_write(ice, tmp); 320 snd_ice1712_gpio_write(ice, tmp); 321 } 321 } 322 322 323 static void spi_send_byte(struct snd_ice1712 * 323 static void spi_send_byte(struct snd_ice1712 *ice, unsigned char data) 324 { 324 { 325 int i; 325 int i; 326 for (i = 0; i < 8; i++) { 326 for (i = 0; i < 8; i++) { 327 set_gpio_bit(ice, PONTIS_CS_CL 327 set_gpio_bit(ice, PONTIS_CS_CLK, 0); 328 udelay(1); 328 udelay(1); 329 set_gpio_bit(ice, PONTIS_CS_WD 329 set_gpio_bit(ice, PONTIS_CS_WDATA, data & 0x80); 330 udelay(1); 330 udelay(1); 331 set_gpio_bit(ice, PONTIS_CS_CL 331 set_gpio_bit(ice, PONTIS_CS_CLK, 1); 332 udelay(1); 332 udelay(1); 333 data <<= 1; 333 data <<= 1; 334 } 334 } 335 } 335 } 336 336 337 static unsigned int spi_read_byte(struct snd_i 337 static unsigned int spi_read_byte(struct snd_ice1712 *ice) 338 { 338 { 339 int i; 339 int i; 340 unsigned int val = 0; 340 unsigned int val = 0; 341 341 342 for (i = 0; i < 8; i++) { 342 for (i = 0; i < 8; i++) { 343 val <<= 1; 343 val <<= 1; 344 set_gpio_bit(ice, PONTIS_CS_CL 344 set_gpio_bit(ice, PONTIS_CS_CLK, 0); 345 udelay(1); 345 udelay(1); 346 if (snd_ice1712_gpio_read(ice) 346 if (snd_ice1712_gpio_read(ice) & PONTIS_CS_RDATA) 347 val |= 1; 347 val |= 1; 348 udelay(1); 348 udelay(1); 349 set_gpio_bit(ice, PONTIS_CS_CL 349 set_gpio_bit(ice, PONTIS_CS_CLK, 1); 350 udelay(1); 350 udelay(1); 351 } 351 } 352 return val; 352 return val; 353 } 353 } 354 354 355 355 356 static void spi_write(struct snd_ice1712 *ice, 356 static void spi_write(struct snd_ice1712 *ice, unsigned int dev, unsigned int reg, unsigned int data) 357 { 357 { 358 snd_ice1712_gpio_set_dir(ice, PONTIS_C 358 snd_ice1712_gpio_set_dir(ice, PONTIS_CS_CS|PONTIS_CS_WDATA|PONTIS_CS_CLK); 359 snd_ice1712_gpio_set_mask(ice, ~(PONTI 359 snd_ice1712_gpio_set_mask(ice, ~(PONTIS_CS_CS|PONTIS_CS_WDATA|PONTIS_CS_CLK)); 360 set_gpio_bit(ice, PONTIS_CS_CS, 0); 360 set_gpio_bit(ice, PONTIS_CS_CS, 0); 361 spi_send_byte(ice, dev & ~1); /* WRITE 361 spi_send_byte(ice, dev & ~1); /* WRITE */ 362 spi_send_byte(ice, reg); /* MAP */ 362 spi_send_byte(ice, reg); /* MAP */ 363 spi_send_byte(ice, data); /* DATA */ 363 spi_send_byte(ice, data); /* DATA */ 364 /* trigger */ 364 /* trigger */ 365 set_gpio_bit(ice, PONTIS_CS_CS, 1); 365 set_gpio_bit(ice, PONTIS_CS_CS, 1); 366 udelay(1); 366 udelay(1); 367 /* restore */ 367 /* restore */ 368 snd_ice1712_gpio_set_mask(ice, ice->gp 368 snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask); 369 snd_ice1712_gpio_set_dir(ice, ice->gpi 369 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction); 370 } 370 } 371 371 372 static unsigned int spi_read(struct snd_ice171 372 static unsigned int spi_read(struct snd_ice1712 *ice, unsigned int dev, unsigned int reg) 373 { 373 { 374 unsigned int val; 374 unsigned int val; 375 snd_ice1712_gpio_set_dir(ice, PONTIS_C 375 snd_ice1712_gpio_set_dir(ice, PONTIS_CS_CS|PONTIS_CS_WDATA|PONTIS_CS_CLK); 376 snd_ice1712_gpio_set_mask(ice, ~(PONTI 376 snd_ice1712_gpio_set_mask(ice, ~(PONTIS_CS_CS|PONTIS_CS_WDATA|PONTIS_CS_CLK)); 377 set_gpio_bit(ice, PONTIS_CS_CS, 0); 377 set_gpio_bit(ice, PONTIS_CS_CS, 0); 378 spi_send_byte(ice, dev & ~1); /* WRITE 378 spi_send_byte(ice, dev & ~1); /* WRITE */ 379 spi_send_byte(ice, reg); /* MAP */ 379 spi_send_byte(ice, reg); /* MAP */ 380 /* trigger */ 380 /* trigger */ 381 set_gpio_bit(ice, PONTIS_CS_CS, 1); 381 set_gpio_bit(ice, PONTIS_CS_CS, 1); 382 udelay(1); 382 udelay(1); 383 set_gpio_bit(ice, PONTIS_CS_CS, 0); 383 set_gpio_bit(ice, PONTIS_CS_CS, 0); 384 spi_send_byte(ice, dev | 1); /* READ * 384 spi_send_byte(ice, dev | 1); /* READ */ 385 val = spi_read_byte(ice); 385 val = spi_read_byte(ice); 386 /* trigger */ 386 /* trigger */ 387 set_gpio_bit(ice, PONTIS_CS_CS, 1); 387 set_gpio_bit(ice, PONTIS_CS_CS, 1); 388 udelay(1); 388 udelay(1); 389 /* restore */ 389 /* restore */ 390 snd_ice1712_gpio_set_mask(ice, ice->gp 390 snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask); 391 snd_ice1712_gpio_set_dir(ice, ice->gpi 391 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction); 392 return val; 392 return val; 393 } 393 } 394 394 395 395 396 /* 396 /* 397 * SPDIF input source 397 * SPDIF input source 398 */ 398 */ 399 static int cs_source_info(struct snd_kcontrol 399 static int cs_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 400 { 400 { 401 static const char * const texts[] = { 401 static const char * const texts[] = { 402 "Coax", /* RXP0 */ 402 "Coax", /* RXP0 */ 403 "Optical", /* RXP1 */ 403 "Optical", /* RXP1 */ 404 "CD", /* RXP2 */ 404 "CD", /* RXP2 */ 405 }; 405 }; 406 return snd_ctl_enum_info(uinfo, 1, 3, 406 return snd_ctl_enum_info(uinfo, 1, 3, texts); 407 } 407 } 408 408 409 static int cs_source_get(struct snd_kcontrol * 409 static int cs_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 410 { 410 { 411 struct snd_ice1712 *ice = snd_kcontrol 411 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 412 412 413 mutex_lock(&ice->gpio_mutex); 413 mutex_lock(&ice->gpio_mutex); 414 ucontrol->value.enumerated.item[0] = i 414 ucontrol->value.enumerated.item[0] = ice->gpio.saved[0]; 415 mutex_unlock(&ice->gpio_mutex); 415 mutex_unlock(&ice->gpio_mutex); 416 return 0; 416 return 0; 417 } 417 } 418 418 419 static int cs_source_put(struct snd_kcontrol * 419 static int cs_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 420 { 420 { 421 struct snd_ice1712 *ice = snd_kcontrol 421 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 422 unsigned char val; 422 unsigned char val; 423 int change = 0; 423 int change = 0; 424 424 425 mutex_lock(&ice->gpio_mutex); 425 mutex_lock(&ice->gpio_mutex); 426 if (ucontrol->value.enumerated.item[0] 426 if (ucontrol->value.enumerated.item[0] != ice->gpio.saved[0]) { 427 ice->gpio.saved[0] = ucontrol- 427 ice->gpio.saved[0] = ucontrol->value.enumerated.item[0] & 3; 428 val = 0x80 | (ice->gpio.saved[ 428 val = 0x80 | (ice->gpio.saved[0] << 3); 429 spi_write(ice, CS_DEV, 0x04, v 429 spi_write(ice, CS_DEV, 0x04, val); 430 change = 1; 430 change = 1; 431 } 431 } 432 mutex_unlock(&ice->gpio_mutex); 432 mutex_unlock(&ice->gpio_mutex); 433 return change; 433 return change; 434 } 434 } 435 435 436 436 437 /* 437 /* 438 * GPIO controls 438 * GPIO controls 439 */ 439 */ 440 static int pontis_gpio_mask_info(struct snd_kc 440 static int pontis_gpio_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 441 { 441 { 442 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTE 442 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 443 uinfo->count = 1; 443 uinfo->count = 1; 444 uinfo->value.integer.min = 0; 444 uinfo->value.integer.min = 0; 445 uinfo->value.integer.max = 0xffff; /* 445 uinfo->value.integer.max = 0xffff; /* 16bit */ 446 return 0; 446 return 0; 447 } 447 } 448 448 449 static int pontis_gpio_mask_get(struct snd_kco 449 static int pontis_gpio_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 450 { 450 { 451 struct snd_ice1712 *ice = snd_kcontrol 451 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 452 mutex_lock(&ice->gpio_mutex); 452 mutex_lock(&ice->gpio_mutex); 453 /* 4-7 reserved */ 453 /* 4-7 reserved */ 454 ucontrol->value.integer.value[0] = (~i 454 ucontrol->value.integer.value[0] = (~ice->gpio.write_mask & 0xffff) | 0x00f0; 455 mutex_unlock(&ice->gpio_mutex); 455 mutex_unlock(&ice->gpio_mutex); 456 return 0; 456 return 0; 457 } 457 } 458 458 459 static int pontis_gpio_mask_put(struct snd_kco 459 static int pontis_gpio_mask_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 460 { 460 { 461 struct snd_ice1712 *ice = snd_kcontrol 461 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 462 unsigned int val; 462 unsigned int val; 463 int changed; 463 int changed; 464 mutex_lock(&ice->gpio_mutex); 464 mutex_lock(&ice->gpio_mutex); 465 /* 4-7 reserved */ 465 /* 4-7 reserved */ 466 val = (~ucontrol->value.integer.value[ 466 val = (~ucontrol->value.integer.value[0] & 0xffff) | 0x00f0; 467 changed = val != ice->gpio.write_mask; 467 changed = val != ice->gpio.write_mask; 468 ice->gpio.write_mask = val; 468 ice->gpio.write_mask = val; 469 mutex_unlock(&ice->gpio_mutex); 469 mutex_unlock(&ice->gpio_mutex); 470 return changed; 470 return changed; 471 } 471 } 472 472 473 static int pontis_gpio_dir_get(struct snd_kcon 473 static int pontis_gpio_dir_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 474 { 474 { 475 struct snd_ice1712 *ice = snd_kcontrol 475 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 476 mutex_lock(&ice->gpio_mutex); 476 mutex_lock(&ice->gpio_mutex); 477 /* 4-7 reserved */ 477 /* 4-7 reserved */ 478 ucontrol->value.integer.value[0] = ice 478 ucontrol->value.integer.value[0] = ice->gpio.direction & 0xff0f; 479 mutex_unlock(&ice->gpio_mutex); 479 mutex_unlock(&ice->gpio_mutex); 480 return 0; 480 return 0; 481 } 481 } 482 482 483 static int pontis_gpio_dir_put(struct snd_kcon 483 static int pontis_gpio_dir_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 484 { 484 { 485 struct snd_ice1712 *ice = snd_kcontrol 485 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 486 unsigned int val; 486 unsigned int val; 487 int changed; 487 int changed; 488 mutex_lock(&ice->gpio_mutex); 488 mutex_lock(&ice->gpio_mutex); 489 /* 4-7 reserved */ 489 /* 4-7 reserved */ 490 val = ucontrol->value.integer.value[0] 490 val = ucontrol->value.integer.value[0] & 0xff0f; 491 changed = (val != ice->gpio.direction) 491 changed = (val != ice->gpio.direction); 492 ice->gpio.direction = val; 492 ice->gpio.direction = val; 493 mutex_unlock(&ice->gpio_mutex); 493 mutex_unlock(&ice->gpio_mutex); 494 return changed; 494 return changed; 495 } 495 } 496 496 497 static int pontis_gpio_data_get(struct snd_kco 497 static int pontis_gpio_data_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 498 { 498 { 499 struct snd_ice1712 *ice = snd_kcontrol 499 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 500 mutex_lock(&ice->gpio_mutex); 500 mutex_lock(&ice->gpio_mutex); 501 snd_ice1712_gpio_set_dir(ice, ice->gpi 501 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction); 502 snd_ice1712_gpio_set_mask(ice, ice->gp 502 snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask); 503 ucontrol->value.integer.value[0] = snd 503 ucontrol->value.integer.value[0] = snd_ice1712_gpio_read(ice) & 0xffff; 504 mutex_unlock(&ice->gpio_mutex); 504 mutex_unlock(&ice->gpio_mutex); 505 return 0; 505 return 0; 506 } 506 } 507 507 508 static int pontis_gpio_data_put(struct snd_kco 508 static int pontis_gpio_data_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 509 { 509 { 510 struct snd_ice1712 *ice = snd_kcontrol 510 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 511 unsigned int val, nval; 511 unsigned int val, nval; 512 int changed = 0; 512 int changed = 0; 513 mutex_lock(&ice->gpio_mutex); 513 mutex_lock(&ice->gpio_mutex); 514 snd_ice1712_gpio_set_dir(ice, ice->gpi 514 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction); 515 snd_ice1712_gpio_set_mask(ice, ice->gp 515 snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask); 516 val = snd_ice1712_gpio_read(ice) & 0xf 516 val = snd_ice1712_gpio_read(ice) & 0xffff; 517 nval = ucontrol->value.integer.value[0 517 nval = ucontrol->value.integer.value[0] & 0xffff; 518 if (val != nval) { 518 if (val != nval) { 519 snd_ice1712_gpio_write(ice, nv 519 snd_ice1712_gpio_write(ice, nval); 520 changed = 1; 520 changed = 1; 521 } 521 } 522 mutex_unlock(&ice->gpio_mutex); 522 mutex_unlock(&ice->gpio_mutex); 523 return changed; 523 return changed; 524 } 524 } 525 525 526 static const DECLARE_TLV_DB_SCALE(db_scale_vol 526 static const DECLARE_TLV_DB_SCALE(db_scale_volume, -6400, 50, 1); 527 527 528 /* 528 /* 529 * mixers 529 * mixers 530 */ 530 */ 531 531 532 static const struct snd_kcontrol_new pontis_co 532 static const struct snd_kcontrol_new pontis_controls[] = { 533 { 533 { 534 .iface = SNDRV_CTL_ELEM_IFACE_ 534 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 535 .access = (SNDRV_CTL_ELEM_ACCE 535 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 536 SNDRV_CTL_ELEM_ACCE 536 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 537 .name = "PCM Playback Volume", 537 .name = "PCM Playback Volume", 538 .info = wm_dac_vol_info, 538 .info = wm_dac_vol_info, 539 .get = wm_dac_vol_get, 539 .get = wm_dac_vol_get, 540 .put = wm_dac_vol_put, 540 .put = wm_dac_vol_put, 541 .tlv = { .p = db_scale_volume 541 .tlv = { .p = db_scale_volume }, 542 }, 542 }, 543 { 543 { 544 .iface = SNDRV_CTL_ELEM_IFACE_ 544 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 545 .access = (SNDRV_CTL_ELEM_ACCE 545 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 546 SNDRV_CTL_ELEM_ACCE 546 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 547 .name = "Capture Volume", 547 .name = "Capture Volume", 548 .info = wm_adc_vol_info, 548 .info = wm_adc_vol_info, 549 .get = wm_adc_vol_get, 549 .get = wm_adc_vol_get, 550 .put = wm_adc_vol_put, 550 .put = wm_adc_vol_put, 551 .tlv = { .p = db_scale_volume 551 .tlv = { .p = db_scale_volume }, 552 }, 552 }, 553 { 553 { 554 .iface = SNDRV_CTL_ELEM_IFACE_ 554 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 555 .name = "CD Capture Switch", 555 .name = "CD Capture Switch", 556 .info = wm_adc_mux_info, 556 .info = wm_adc_mux_info, 557 .get = wm_adc_mux_get, 557 .get = wm_adc_mux_get, 558 .put = wm_adc_mux_put, 558 .put = wm_adc_mux_put, 559 .private_value = 0, 559 .private_value = 0, 560 }, 560 }, 561 { 561 { 562 .iface = SNDRV_CTL_ELEM_IFACE_ 562 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 563 .name = "Line Capture Switch", 563 .name = "Line Capture Switch", 564 .info = wm_adc_mux_info, 564 .info = wm_adc_mux_info, 565 .get = wm_adc_mux_get, 565 .get = wm_adc_mux_get, 566 .put = wm_adc_mux_put, 566 .put = wm_adc_mux_put, 567 .private_value = 1, 567 .private_value = 1, 568 }, 568 }, 569 { 569 { 570 .iface = SNDRV_CTL_ELEM_IFACE_ 570 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 571 .name = "Analog Bypass Switch" 571 .name = "Analog Bypass Switch", 572 .info = wm_bypass_info, 572 .info = wm_bypass_info, 573 .get = wm_bypass_get, 573 .get = wm_bypass_get, 574 .put = wm_bypass_put, 574 .put = wm_bypass_put, 575 }, 575 }, 576 { 576 { 577 .iface = SNDRV_CTL_ELEM_IFACE_ 577 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 578 .name = "Swap Output Channels" 578 .name = "Swap Output Channels", 579 .info = wm_chswap_info, 579 .info = wm_chswap_info, 580 .get = wm_chswap_get, 580 .get = wm_chswap_get, 581 .put = wm_chswap_put, 581 .put = wm_chswap_put, 582 }, 582 }, 583 { 583 { 584 .iface = SNDRV_CTL_ELEM_IFACE_ 584 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 585 .name = "IEC958 Input Source", 585 .name = "IEC958 Input Source", 586 .info = cs_source_info, 586 .info = cs_source_info, 587 .get = cs_source_get, 587 .get = cs_source_get, 588 .put = cs_source_put, 588 .put = cs_source_put, 589 }, 589 }, 590 /* FIXME: which interface? */ 590 /* FIXME: which interface? */ 591 { 591 { 592 .iface = SNDRV_CTL_ELEM_IFACE_ 592 .iface = SNDRV_CTL_ELEM_IFACE_CARD, 593 .name = "GPIO Mask", 593 .name = "GPIO Mask", 594 .info = pontis_gpio_mask_info, 594 .info = pontis_gpio_mask_info, 595 .get = pontis_gpio_mask_get, 595 .get = pontis_gpio_mask_get, 596 .put = pontis_gpio_mask_put, 596 .put = pontis_gpio_mask_put, 597 }, 597 }, 598 { 598 { 599 .iface = SNDRV_CTL_ELEM_IFACE_ 599 .iface = SNDRV_CTL_ELEM_IFACE_CARD, 600 .name = "GPIO Direction", 600 .name = "GPIO Direction", 601 .info = pontis_gpio_mask_info, 601 .info = pontis_gpio_mask_info, 602 .get = pontis_gpio_dir_get, 602 .get = pontis_gpio_dir_get, 603 .put = pontis_gpio_dir_put, 603 .put = pontis_gpio_dir_put, 604 }, 604 }, 605 { 605 { 606 .iface = SNDRV_CTL_ELEM_IFACE_ 606 .iface = SNDRV_CTL_ELEM_IFACE_CARD, 607 .name = "GPIO Data", 607 .name = "GPIO Data", 608 .info = pontis_gpio_mask_info, 608 .info = pontis_gpio_mask_info, 609 .get = pontis_gpio_data_get, 609 .get = pontis_gpio_data_get, 610 .put = pontis_gpio_data_put, 610 .put = pontis_gpio_data_put, 611 }, 611 }, 612 }; 612 }; 613 613 614 614 615 /* 615 /* 616 * WM codec registers 616 * WM codec registers 617 */ 617 */ 618 static void wm_proc_regs_write(struct snd_info 618 static void wm_proc_regs_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 619 { 619 { 620 struct snd_ice1712 *ice = entry->priva 620 struct snd_ice1712 *ice = entry->private_data; 621 char line[64]; 621 char line[64]; 622 unsigned int reg, val; 622 unsigned int reg, val; 623 mutex_lock(&ice->gpio_mutex); 623 mutex_lock(&ice->gpio_mutex); 624 while (!snd_info_get_line(buffer, line 624 while (!snd_info_get_line(buffer, line, sizeof(line))) { 625 if (sscanf(line, "%x %x", ® 625 if (sscanf(line, "%x %x", ®, &val) != 2) 626 continue; 626 continue; 627 if (reg <= 0x17 && val <= 0xff 627 if (reg <= 0x17 && val <= 0xffff) 628 wm_put(ice, reg, val); 628 wm_put(ice, reg, val); 629 } 629 } 630 mutex_unlock(&ice->gpio_mutex); 630 mutex_unlock(&ice->gpio_mutex); 631 } 631 } 632 632 633 static void wm_proc_regs_read(struct snd_info_ 633 static void wm_proc_regs_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 634 { 634 { 635 struct snd_ice1712 *ice = entry->priva 635 struct snd_ice1712 *ice = entry->private_data; 636 int reg, val; 636 int reg, val; 637 637 638 mutex_lock(&ice->gpio_mutex); 638 mutex_lock(&ice->gpio_mutex); 639 for (reg = 0; reg <= 0x17; reg++) { 639 for (reg = 0; reg <= 0x17; reg++) { 640 val = wm_get(ice, reg); 640 val = wm_get(ice, reg); 641 snd_iprintf(buffer, "%02x = %0 641 snd_iprintf(buffer, "%02x = %04x\n", reg, val); 642 } 642 } 643 mutex_unlock(&ice->gpio_mutex); 643 mutex_unlock(&ice->gpio_mutex); 644 } 644 } 645 645 646 static void wm_proc_init(struct snd_ice1712 *i 646 static void wm_proc_init(struct snd_ice1712 *ice) 647 { 647 { 648 snd_card_rw_proc_new(ice->card, "wm_co 648 snd_card_rw_proc_new(ice->card, "wm_codec", ice, wm_proc_regs_read, 649 wm_proc_regs_writ 649 wm_proc_regs_write); 650 } 650 } 651 651 652 static void cs_proc_regs_read(struct snd_info_ 652 static void cs_proc_regs_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 653 { 653 { 654 struct snd_ice1712 *ice = entry->priva 654 struct snd_ice1712 *ice = entry->private_data; 655 int reg, val; 655 int reg, val; 656 656 657 mutex_lock(&ice->gpio_mutex); 657 mutex_lock(&ice->gpio_mutex); 658 for (reg = 0; reg <= 0x26; reg++) { 658 for (reg = 0; reg <= 0x26; reg++) { 659 val = spi_read(ice, CS_DEV, re 659 val = spi_read(ice, CS_DEV, reg); 660 snd_iprintf(buffer, "%02x = %0 660 snd_iprintf(buffer, "%02x = %02x\n", reg, val); 661 } 661 } 662 val = spi_read(ice, CS_DEV, 0x7f); 662 val = spi_read(ice, CS_DEV, 0x7f); 663 snd_iprintf(buffer, "%02x = %02x\n", 0 663 snd_iprintf(buffer, "%02x = %02x\n", 0x7f, val); 664 mutex_unlock(&ice->gpio_mutex); 664 mutex_unlock(&ice->gpio_mutex); 665 } 665 } 666 666 667 static void cs_proc_init(struct snd_ice1712 *i 667 static void cs_proc_init(struct snd_ice1712 *ice) 668 { 668 { 669 snd_card_ro_proc_new(ice->card, "cs_co 669 snd_card_ro_proc_new(ice->card, "cs_codec", ice, cs_proc_regs_read); 670 } 670 } 671 671 672 672 673 static int pontis_add_controls(struct snd_ice1 673 static int pontis_add_controls(struct snd_ice1712 *ice) 674 { 674 { 675 unsigned int i; 675 unsigned int i; 676 int err; 676 int err; 677 677 678 for (i = 0; i < ARRAY_SIZE(pontis_cont 678 for (i = 0; i < ARRAY_SIZE(pontis_controls); i++) { 679 err = snd_ctl_add(ice->card, s 679 err = snd_ctl_add(ice->card, snd_ctl_new1(&pontis_controls[i], ice)); 680 if (err < 0) 680 if (err < 0) 681 return err; 681 return err; 682 } 682 } 683 683 684 wm_proc_init(ice); 684 wm_proc_init(ice); 685 cs_proc_init(ice); 685 cs_proc_init(ice); 686 686 687 return 0; 687 return 0; 688 } 688 } 689 689 690 690 691 /* 691 /* 692 * initialize the chip 692 * initialize the chip 693 */ 693 */ 694 static int pontis_init(struct snd_ice1712 *ice 694 static int pontis_init(struct snd_ice1712 *ice) 695 { 695 { 696 static const unsigned short wm_inits[] 696 static const unsigned short wm_inits[] = { 697 /* These come first to reduce 697 /* These come first to reduce init pop noise */ 698 WM_ADC_MUX, 0x00c0, /* ADC 698 WM_ADC_MUX, 0x00c0, /* ADC mute */ 699 WM_DAC_MUTE, 0x0001, /* DAC 699 WM_DAC_MUTE, 0x0001, /* DAC softmute */ 700 WM_DAC_CTRL1, 0x0000, /* DAC 700 WM_DAC_CTRL1, 0x0000, /* DAC mute */ 701 701 702 WM_POWERDOWN, 0x0008, /* All 702 WM_POWERDOWN, 0x0008, /* All power-up except HP */ 703 WM_RESET, 0x0000, /* res 703 WM_RESET, 0x0000, /* reset */ 704 }; 704 }; 705 static const unsigned short wm_inits2[ 705 static const unsigned short wm_inits2[] = { 706 WM_MASTER_CTRL, 0x0022, /* 256 706 WM_MASTER_CTRL, 0x0022, /* 256fs, slave mode */ 707 WM_DAC_INT, 0x0022, /* I2S 707 WM_DAC_INT, 0x0022, /* I2S, normal polarity, 24bit */ 708 WM_ADC_INT, 0x0022, /* I2S 708 WM_ADC_INT, 0x0022, /* I2S, normal polarity, 24bit */ 709 WM_DAC_CTRL1, 0x0090, /* DAC 709 WM_DAC_CTRL1, 0x0090, /* DAC L/R */ 710 WM_OUT_MUX, 0x0001, /* OUT 710 WM_OUT_MUX, 0x0001, /* OUT DAC */ 711 WM_HP_ATTEN_L, 0x0179, /* HP 711 WM_HP_ATTEN_L, 0x0179, /* HP 0dB */ 712 WM_HP_ATTEN_R, 0x0179, /* HP 712 WM_HP_ATTEN_R, 0x0179, /* HP 0dB */ 713 WM_DAC_ATTEN_L, 0x0000, /* DAC 713 WM_DAC_ATTEN_L, 0x0000, /* DAC 0dB */ 714 WM_DAC_ATTEN_L, 0x0100, /* DAC 714 WM_DAC_ATTEN_L, 0x0100, /* DAC 0dB */ 715 WM_DAC_ATTEN_R, 0x0000, /* DAC 715 WM_DAC_ATTEN_R, 0x0000, /* DAC 0dB */ 716 WM_DAC_ATTEN_R, 0x0100, /* DAC 716 WM_DAC_ATTEN_R, 0x0100, /* DAC 0dB */ 717 /* WM_DAC_MASTER, 0x0100 717 /* WM_DAC_MASTER, 0x0100, */ /* DAC master muted */ 718 WM_PHASE_SWAP, 0x0000, /* pha 718 WM_PHASE_SWAP, 0x0000, /* phase normal */ 719 WM_DAC_CTRL2, 0x0000, /* no 719 WM_DAC_CTRL2, 0x0000, /* no deemphasis, no ZFLG */ 720 WM_ADC_ATTEN_L, 0x0000, /* ADC 720 WM_ADC_ATTEN_L, 0x0000, /* ADC muted */ 721 WM_ADC_ATTEN_R, 0x0000, /* ADC 721 WM_ADC_ATTEN_R, 0x0000, /* ADC muted */ 722 #if 0 722 #if 0 723 WM_ALC_CTRL1, 0x007b, /* */ 723 WM_ALC_CTRL1, 0x007b, /* */ 724 WM_ALC_CTRL2, 0x0000, /* */ 724 WM_ALC_CTRL2, 0x0000, /* */ 725 WM_ALC_CTRL3, 0x0000, /* */ 725 WM_ALC_CTRL3, 0x0000, /* */ 726 WM_NOISE_GATE, 0x0000, /* */ 726 WM_NOISE_GATE, 0x0000, /* */ 727 #endif 727 #endif 728 WM_DAC_MUTE, 0x0000, /* DAC 728 WM_DAC_MUTE, 0x0000, /* DAC unmute */ 729 WM_ADC_MUX, 0x0003, /* ADC 729 WM_ADC_MUX, 0x0003, /* ADC unmute, both CD/Line On */ 730 }; 730 }; 731 static const unsigned char cs_inits[] 731 static const unsigned char cs_inits[] = { 732 0x04, 0x80, /* RUN, RXP0 * 732 0x04, 0x80, /* RUN, RXP0 */ 733 0x05, 0x05, /* slave, 24bi 733 0x05, 0x05, /* slave, 24bit */ 734 0x01, 0x00, 734 0x01, 0x00, 735 0x02, 0x00, 735 0x02, 0x00, 736 0x03, 0x00, 736 0x03, 0x00, 737 }; 737 }; 738 unsigned int i; 738 unsigned int i; 739 739 740 ice->vt1720 = 1; 740 ice->vt1720 = 1; 741 ice->num_total_dacs = 2; 741 ice->num_total_dacs = 2; 742 ice->num_total_adcs = 2; 742 ice->num_total_adcs = 2; 743 743 744 /* to remember the register values */ 744 /* to remember the register values */ 745 ice->akm = kzalloc(sizeof(struct snd_a 745 ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL); 746 if (! ice->akm) 746 if (! ice->akm) 747 return -ENOMEM; 747 return -ENOMEM; 748 ice->akm_codecs = 1; 748 ice->akm_codecs = 1; 749 749 750 /* HACK - use this as the SPDIF source 750 /* HACK - use this as the SPDIF source. 751 * don't call snd_ice1712_gpio_get/put 751 * don't call snd_ice1712_gpio_get/put(), otherwise it's overwritten 752 */ 752 */ 753 ice->gpio.saved[0] = 0; 753 ice->gpio.saved[0] = 0; 754 754 755 /* initialize WM8776 codec */ 755 /* initialize WM8776 codec */ 756 for (i = 0; i < ARRAY_SIZE(wm_inits); 756 for (i = 0; i < ARRAY_SIZE(wm_inits); i += 2) 757 wm_put(ice, wm_inits[i], wm_in 757 wm_put(ice, wm_inits[i], wm_inits[i+1]); 758 schedule_timeout_uninterruptible(1); 758 schedule_timeout_uninterruptible(1); 759 for (i = 0; i < ARRAY_SIZE(wm_inits2); 759 for (i = 0; i < ARRAY_SIZE(wm_inits2); i += 2) 760 wm_put(ice, wm_inits2[i], wm_i 760 wm_put(ice, wm_inits2[i], wm_inits2[i+1]); 761 761 762 /* initialize CS8416 codec */ 762 /* initialize CS8416 codec */ 763 /* assert PRST#; MT05 bit 7 */ 763 /* assert PRST#; MT05 bit 7 */ 764 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0 764 outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD)); 765 mdelay(5); 765 mdelay(5); 766 /* deassert PRST# */ 766 /* deassert PRST# */ 767 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~ 767 outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD)); 768 768 769 for (i = 0; i < ARRAY_SIZE(cs_inits); 769 for (i = 0; i < ARRAY_SIZE(cs_inits); i += 2) 770 spi_write(ice, CS_DEV, cs_init 770 spi_write(ice, CS_DEV, cs_inits[i], cs_inits[i+1]); 771 771 772 return 0; 772 return 0; 773 } 773 } 774 774 775 775 776 /* 776 /* 777 * Pontis boards don't provide the EEPROM data 777 * Pontis boards don't provide the EEPROM data at all. 778 * hence the driver needs to sets up it proper 778 * hence the driver needs to sets up it properly. 779 */ 779 */ 780 780 781 static const unsigned char pontis_eeprom[] = { 781 static const unsigned char pontis_eeprom[] = { 782 [ICE_EEP2_SYSCONF] = 0x08, /* clo 782 [ICE_EEP2_SYSCONF] = 0x08, /* clock 256, mpu401, spdif-in/ADC, 1DAC */ 783 [ICE_EEP2_ACLINK] = 0x80, /* I2S 783 [ICE_EEP2_ACLINK] = 0x80, /* I2S */ 784 [ICE_EEP2_I2S] = 0xf8, /* vol 784 [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */ 785 [ICE_EEP2_SPDIF] = 0xc3, /* out 785 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */ 786 [ICE_EEP2_GPIO_DIR] = 0x07, 786 [ICE_EEP2_GPIO_DIR] = 0x07, 787 [ICE_EEP2_GPIO_DIR1] = 0x00, 787 [ICE_EEP2_GPIO_DIR1] = 0x00, 788 [ICE_EEP2_GPIO_DIR2] = 0x00, /* ign 788 [ICE_EEP2_GPIO_DIR2] = 0x00, /* ignored */ 789 [ICE_EEP2_GPIO_MASK] = 0x0f, /* 4-7 789 [ICE_EEP2_GPIO_MASK] = 0x0f, /* 4-7 reserved for CS8416 */ 790 [ICE_EEP2_GPIO_MASK1] = 0xff, 790 [ICE_EEP2_GPIO_MASK1] = 0xff, 791 [ICE_EEP2_GPIO_MASK2] = 0x00, /* ign 791 [ICE_EEP2_GPIO_MASK2] = 0x00, /* ignored */ 792 [ICE_EEP2_GPIO_STATE] = 0x06, /* 0-l 792 [ICE_EEP2_GPIO_STATE] = 0x06, /* 0-low, 1-high, 2-high */ 793 [ICE_EEP2_GPIO_STATE1] = 0x00, 793 [ICE_EEP2_GPIO_STATE1] = 0x00, 794 [ICE_EEP2_GPIO_STATE2] = 0x00, /* ign 794 [ICE_EEP2_GPIO_STATE2] = 0x00, /* ignored */ 795 }; 795 }; 796 796 797 /* entry point */ 797 /* entry point */ 798 struct snd_ice1712_card_info snd_vt1720_pontis 798 struct snd_ice1712_card_info snd_vt1720_pontis_cards[] = { 799 { 799 { 800 .subvendor = VT1720_SUBDEVICE_ 800 .subvendor = VT1720_SUBDEVICE_PONTIS_MS300, 801 .name = "Pontis MS300", 801 .name = "Pontis MS300", 802 .model = "ms300", 802 .model = "ms300", 803 .chip_init = pontis_init, 803 .chip_init = pontis_init, 804 .build_controls = pontis_add_c 804 .build_controls = pontis_add_controls, 805 .eeprom_size = sizeof(pontis_e 805 .eeprom_size = sizeof(pontis_eeprom), 806 .eeprom_data = pontis_eeprom, 806 .eeprom_data = pontis_eeprom, 807 }, 807 }, 808 { } /* terminator */ 808 { } /* terminator */ 809 }; 809 }; 810 810
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.