0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <linux/delay.h>
0015 #include <linux/interrupt.h>
0016 #include <linux/init.h>
0017 #include <sound/core.h>
0018 #include <sound/tlv.h>
0019 #include <linux/slab.h>
0020
0021 #include "ice1712.h"
0022 #include "envy24ht.h"
0023 #include "wtm.h"
0024 #include "stac946x.h"
0025
0026 struct wtm_spec {
0027
0028 struct mutex mute_mutex;
0029 };
0030
0031
0032
0033
0034
0035 static inline void stac9460_put(struct snd_ice1712 *ice, int reg,
0036 unsigned char val)
0037 {
0038 snd_vt1724_write_i2c(ice, STAC9460_I2C_ADDR, reg, val);
0039 }
0040
0041 static inline unsigned char stac9460_get(struct snd_ice1712 *ice, int reg)
0042 {
0043 return snd_vt1724_read_i2c(ice, STAC9460_I2C_ADDR, reg);
0044 }
0045
0046
0047
0048
0049 static inline void stac9460_2_put(struct snd_ice1712 *ice, int reg,
0050 unsigned char val)
0051 {
0052 snd_vt1724_write_i2c(ice, STAC9460_2_I2C_ADDR, reg, val);
0053 }
0054
0055 static inline unsigned char stac9460_2_get(struct snd_ice1712 *ice, int reg)
0056 {
0057 return snd_vt1724_read_i2c(ice, STAC9460_2_I2C_ADDR, reg);
0058 }
0059
0060
0061
0062
0063
0064 static void stac9460_dac_mute_all(struct snd_ice1712 *ice, unsigned char mute,
0065 unsigned short int *change_mask)
0066 {
0067 unsigned char new, old;
0068 int id, idx, change;
0069
0070
0071 for (id = 0; id < 7; id++) {
0072 if (*change_mask & (0x01 << id)) {
0073 if (id == 0)
0074 idx = STAC946X_MASTER_VOLUME;
0075 else
0076 idx = STAC946X_LF_VOLUME - 1 + id;
0077 old = stac9460_get(ice, idx);
0078 new = (~mute << 7 & 0x80) | (old & ~0x80);
0079 change = (new != old);
0080 if (change) {
0081 stac9460_put(ice, idx, new);
0082 *change_mask = *change_mask | (0x01 << id);
0083 } else {
0084 *change_mask = *change_mask & ~(0x01 << id);
0085 }
0086 }
0087 }
0088
0089
0090 for (id = 0; id < 3; id++) {
0091 if (*change_mask & (0x01 << (id + 7))) {
0092 if (id == 0)
0093 idx = STAC946X_MASTER_VOLUME;
0094 else
0095 idx = STAC946X_LF_VOLUME - 1 + id;
0096 old = stac9460_2_get(ice, idx);
0097 new = (~mute << 7 & 0x80) | (old & ~0x80);
0098 change = (new != old);
0099 if (change) {
0100 stac9460_2_put(ice, idx, new);
0101 *change_mask = *change_mask | (0x01 << id);
0102 } else {
0103 *change_mask = *change_mask & ~(0x01 << id);
0104 }
0105 }
0106 }
0107 }
0108
0109
0110
0111 #define stac9460_dac_mute_info snd_ctl_boolean_mono_info
0112
0113 static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol,
0114 struct snd_ctl_elem_value *ucontrol)
0115 {
0116 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0117 struct wtm_spec *spec = ice->spec;
0118 unsigned char val;
0119 int idx, id;
0120
0121 mutex_lock(&spec->mute_mutex);
0122
0123 if (kcontrol->private_value) {
0124 idx = STAC946X_MASTER_VOLUME;
0125 id = 0;
0126 } else {
0127 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
0128 idx = id + STAC946X_LF_VOLUME;
0129 }
0130 if (id < 6)
0131 val = stac9460_get(ice, idx);
0132 else
0133 val = stac9460_2_get(ice, idx - 6);
0134 ucontrol->value.integer.value[0] = (~val >> 7) & 0x1;
0135
0136 mutex_unlock(&spec->mute_mutex);
0137 return 0;
0138 }
0139
0140 static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol,
0141 struct snd_ctl_elem_value *ucontrol)
0142 {
0143 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0144 unsigned char new, old;
0145 int id, idx;
0146 int change;
0147
0148 if (kcontrol->private_value) {
0149 idx = STAC946X_MASTER_VOLUME;
0150 old = stac9460_get(ice, idx);
0151 new = (~ucontrol->value.integer.value[0] << 7 & 0x80) |
0152 (old & ~0x80);
0153 change = (new != old);
0154 if (change) {
0155 stac9460_put(ice, idx, new);
0156 stac9460_2_put(ice, idx, new);
0157 }
0158 } else {
0159 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
0160 idx = id + STAC946X_LF_VOLUME;
0161 if (id < 6)
0162 old = stac9460_get(ice, idx);
0163 else
0164 old = stac9460_2_get(ice, idx - 6);
0165 new = (~ucontrol->value.integer.value[0] << 7 & 0x80) |
0166 (old & ~0x80);
0167 change = (new != old);
0168 if (change) {
0169 if (id < 6)
0170 stac9460_put(ice, idx, new);
0171 else
0172 stac9460_2_put(ice, idx - 6, new);
0173 }
0174 }
0175 return change;
0176 }
0177
0178
0179
0180
0181 static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol,
0182 struct snd_ctl_elem_info *uinfo)
0183 {
0184 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
0185 uinfo->count = 1;
0186 uinfo->value.integer.min = 0;
0187 uinfo->value.integer.max = 0x7f;
0188 return 0;
0189 }
0190
0191 static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol,
0192 struct snd_ctl_elem_value *ucontrol)
0193 {
0194 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0195 int idx, id;
0196 unsigned char vol;
0197
0198 if (kcontrol->private_value) {
0199 idx = STAC946X_MASTER_VOLUME;
0200 id = 0;
0201 } else {
0202 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
0203 idx = id + STAC946X_LF_VOLUME;
0204 }
0205 if (id < 6)
0206 vol = stac9460_get(ice, idx) & 0x7f;
0207 else
0208 vol = stac9460_2_get(ice, idx - 6) & 0x7f;
0209 ucontrol->value.integer.value[0] = 0x7f - vol;
0210 return 0;
0211 }
0212
0213 static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol,
0214 struct snd_ctl_elem_value *ucontrol)
0215 {
0216 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0217 int idx, id;
0218 unsigned char tmp, ovol, nvol;
0219 int change;
0220
0221 if (kcontrol->private_value) {
0222 idx = STAC946X_MASTER_VOLUME;
0223 nvol = ucontrol->value.integer.value[0] & 0x7f;
0224 tmp = stac9460_get(ice, idx);
0225 ovol = 0x7f - (tmp & 0x7f);
0226 change = (ovol != nvol);
0227 if (change) {
0228 stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
0229 stac9460_2_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
0230 }
0231 } else {
0232 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
0233 idx = id + STAC946X_LF_VOLUME;
0234 nvol = ucontrol->value.integer.value[0] & 0x7f;
0235 if (id < 6)
0236 tmp = stac9460_get(ice, idx);
0237 else
0238 tmp = stac9460_2_get(ice, idx - 6);
0239 ovol = 0x7f - (tmp & 0x7f);
0240 change = (ovol != nvol);
0241 if (change) {
0242 if (id < 6)
0243 stac9460_put(ice, idx, (0x7f - nvol) |
0244 (tmp & 0x80));
0245 else
0246 stac9460_2_put(ice, idx-6, (0x7f - nvol) |
0247 (tmp & 0x80));
0248 }
0249 }
0250 return change;
0251 }
0252
0253
0254
0255
0256 #define stac9460_adc_mute_info snd_ctl_boolean_stereo_info
0257
0258 static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol,
0259 struct snd_ctl_elem_value *ucontrol)
0260 {
0261 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0262 unsigned char val;
0263 int i, id;
0264
0265 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
0266 if (id == 0) {
0267 for (i = 0; i < 2; ++i) {
0268 val = stac9460_get(ice, STAC946X_MIC_L_VOLUME + i);
0269 ucontrol->value.integer.value[i] = ~val>>7 & 0x1;
0270 }
0271 } else {
0272 for (i = 0; i < 2; ++i) {
0273 val = stac9460_2_get(ice, STAC946X_MIC_L_VOLUME + i);
0274 ucontrol->value.integer.value[i] = ~val>>7 & 0x1;
0275 }
0276 }
0277 return 0;
0278 }
0279
0280 static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol,
0281 struct snd_ctl_elem_value *ucontrol)
0282 {
0283 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0284 unsigned char new, old;
0285 int i, reg, id;
0286 int change;
0287
0288 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
0289 if (id == 0) {
0290 for (i = 0; i < 2; ++i) {
0291 reg = STAC946X_MIC_L_VOLUME + i;
0292 old = stac9460_get(ice, reg);
0293 new = (~ucontrol->value.integer.value[i]<<7&0x80) |
0294 (old&~0x80);
0295 change = (new != old);
0296 if (change)
0297 stac9460_put(ice, reg, new);
0298 }
0299 } else {
0300 for (i = 0; i < 2; ++i) {
0301 reg = STAC946X_MIC_L_VOLUME + i;
0302 old = stac9460_2_get(ice, reg);
0303 new = (~ucontrol->value.integer.value[i]<<7&0x80) |
0304 (old&~0x80);
0305 change = (new != old);
0306 if (change)
0307 stac9460_2_put(ice, reg, new);
0308 }
0309 }
0310 return change;
0311 }
0312
0313
0314
0315
0316 static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol,
0317 struct snd_ctl_elem_info *uinfo)
0318 {
0319 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
0320 uinfo->count = 2;
0321 uinfo->value.integer.min = 0;
0322 uinfo->value.integer.max = 0x0f;
0323 return 0;
0324 }
0325
0326 static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol,
0327 struct snd_ctl_elem_value *ucontrol)
0328 {
0329 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0330 int i, reg, id;
0331 unsigned char vol;
0332
0333 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
0334 if (id == 0) {
0335 for (i = 0; i < 2; ++i) {
0336 reg = STAC946X_MIC_L_VOLUME + i;
0337 vol = stac9460_get(ice, reg) & 0x0f;
0338 ucontrol->value.integer.value[i] = 0x0f - vol;
0339 }
0340 } else {
0341 for (i = 0; i < 2; ++i) {
0342 reg = STAC946X_MIC_L_VOLUME + i;
0343 vol = stac9460_2_get(ice, reg) & 0x0f;
0344 ucontrol->value.integer.value[i] = 0x0f - vol;
0345 }
0346 }
0347 return 0;
0348 }
0349
0350 static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol,
0351 struct snd_ctl_elem_value *ucontrol)
0352 {
0353 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0354 int i, reg, id;
0355 unsigned char ovol, nvol;
0356 int change;
0357
0358 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
0359 if (id == 0) {
0360 for (i = 0; i < 2; ++i) {
0361 reg = STAC946X_MIC_L_VOLUME + i;
0362 nvol = ucontrol->value.integer.value[i] & 0x0f;
0363 ovol = 0x0f - stac9460_get(ice, reg);
0364 change = ((ovol & 0x0f) != nvol);
0365 if (change)
0366 stac9460_put(ice, reg, (0x0f - nvol) |
0367 (ovol & ~0x0f));
0368 }
0369 } else {
0370 for (i = 0; i < 2; ++i) {
0371 reg = STAC946X_MIC_L_VOLUME + i;
0372 nvol = ucontrol->value.integer.value[i] & 0x0f;
0373 ovol = 0x0f - stac9460_2_get(ice, reg);
0374 change = ((ovol & 0x0f) != nvol);
0375 if (change)
0376 stac9460_2_put(ice, reg, (0x0f - nvol) |
0377 (ovol & ~0x0f));
0378 }
0379 }
0380 return change;
0381 }
0382
0383
0384
0385
0386 static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol,
0387 struct snd_ctl_elem_info *uinfo)
0388 {
0389 static const char * const texts[2] = { "Line In", "Mic" };
0390
0391 return snd_ctl_enum_info(uinfo, 1, 2, texts);
0392 }
0393
0394
0395 static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
0396 struct snd_ctl_elem_value *ucontrol)
0397 {
0398 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0399 unsigned char val;
0400 int id;
0401
0402 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
0403 if (id == 0)
0404 val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
0405 else
0406 val = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
0407 ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1;
0408 return 0;
0409 }
0410
0411 static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
0412 struct snd_ctl_elem_value *ucontrol)
0413 {
0414 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
0415 unsigned char new, old;
0416 int change, id;
0417
0418 id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
0419 if (id == 0)
0420 old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
0421 else
0422 old = stac9460_2_get(ice, STAC946X_GENERAL_PURPOSE);
0423 new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80);
0424 change = (new != old);
0425 if (change) {
0426 if (id == 0)
0427 stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new);
0428 else
0429 stac9460_2_put(ice, STAC946X_GENERAL_PURPOSE, new);
0430 }
0431 return change;
0432 }
0433
0434
0435
0436
0437
0438 static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)
0439 {
0440 unsigned char old, new;
0441 unsigned short int changed;
0442 struct wtm_spec *spec = ice->spec;
0443
0444 if (rate == 0)
0445 return;
0446 else if (rate <= 48000)
0447 new = 0x08;
0448 else if (rate <= 96000)
0449 new = 0x11;
0450 else
0451 new = 0x12;
0452
0453 old = stac9460_get(ice, STAC946X_MASTER_CLOCKING);
0454 if (old == new)
0455 return;
0456
0457
0458 mutex_lock(&spec->mute_mutex);
0459
0460 changed = 0xFFFF;
0461 stac9460_dac_mute_all(ice, 0, &changed);
0462
0463 stac9460_put(ice, STAC946X_MASTER_CLOCKING, new);
0464 stac9460_2_put(ice, STAC946X_MASTER_CLOCKING, new);
0465 udelay(10);
0466
0467
0468 stac9460_dac_mute_all(ice, 1, &changed);
0469 mutex_unlock(&spec->mute_mutex);
0470 }
0471
0472
0473
0474 static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0);
0475 static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);
0476
0477
0478
0479
0480 static const struct snd_kcontrol_new stac9640_controls[] = {
0481 {
0482 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0483 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
0484 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
0485 .name = "Master Playback Switch",
0486 .info = stac9460_dac_mute_info,
0487 .get = stac9460_dac_mute_get,
0488 .put = stac9460_dac_mute_put,
0489 .private_value = 1,
0490 .tlv = { .p = db_scale_dac }
0491 },
0492 {
0493 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0494 .name = "Master Playback Volume",
0495 .info = stac9460_dac_vol_info,
0496 .get = stac9460_dac_vol_get,
0497 .put = stac9460_dac_vol_put,
0498 .private_value = 1,
0499 },
0500 {
0501 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0502 .name = "MIC/Line Input Enum",
0503 .count = 2,
0504 .info = stac9460_mic_sw_info,
0505 .get = stac9460_mic_sw_get,
0506 .put = stac9460_mic_sw_put,
0507
0508 },
0509 {
0510 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0511 .name = "DAC Switch",
0512 .count = 8,
0513 .info = stac9460_dac_mute_info,
0514 .get = stac9460_dac_mute_get,
0515 .put = stac9460_dac_mute_put,
0516 },
0517 {
0518 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0519 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
0520 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
0521
0522 .name = "DAC Volume",
0523 .count = 8,
0524 .info = stac9460_dac_vol_info,
0525 .get = stac9460_dac_vol_get,
0526 .put = stac9460_dac_vol_put,
0527 .tlv = { .p = db_scale_dac }
0528 },
0529 {
0530 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0531 .name = "ADC Switch",
0532 .count = 2,
0533 .info = stac9460_adc_mute_info,
0534 .get = stac9460_adc_mute_get,
0535 .put = stac9460_adc_mute_put,
0536 },
0537 {
0538 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
0539 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
0540 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
0541
0542 .name = "ADC Volume",
0543 .count = 2,
0544 .info = stac9460_adc_vol_info,
0545 .get = stac9460_adc_vol_get,
0546 .put = stac9460_adc_vol_put,
0547 .tlv = { .p = db_scale_adc }
0548 }
0549 };
0550
0551
0552
0553
0554 static int wtm_add_controls(struct snd_ice1712 *ice)
0555 {
0556 unsigned int i;
0557 int err;
0558
0559 for (i = 0; i < ARRAY_SIZE(stac9640_controls); i++) {
0560 err = snd_ctl_add(ice->card,
0561 snd_ctl_new1(&stac9640_controls[i], ice));
0562 if (err < 0)
0563 return err;
0564 }
0565 return 0;
0566 }
0567
0568 static int wtm_init(struct snd_ice1712 *ice)
0569 {
0570 static const unsigned short stac_inits_wtm[] = {
0571 STAC946X_RESET, 0,
0572 STAC946X_MASTER_CLOCKING, 0x11,
0573 (unsigned short)-1
0574 };
0575 const unsigned short *p;
0576 struct wtm_spec *spec;
0577
0578
0579 ice->num_total_dacs = 8;
0580 ice->num_total_adcs = 4;
0581 ice->force_rdma1 = 1;
0582
0583
0584 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
0585 if (!spec)
0586 return -ENOMEM;
0587 ice->spec = spec;
0588 mutex_init(&spec->mute_mutex);
0589
0590
0591
0592 p = stac_inits_wtm;
0593 for (; *p != (unsigned short)-1; p += 2) {
0594 stac9460_put(ice, p[0], p[1]);
0595 stac9460_2_put(ice, p[0], p[1]);
0596 }
0597 ice->gpio.set_pro_rate = stac9460_set_rate_val;
0598 return 0;
0599 }
0600
0601
0602 static const unsigned char wtm_eeprom[] = {
0603 [ICE_EEP2_SYSCONF] = 0x67,
0604
0605 [ICE_EEP2_ACLINK] = 0x80,
0606 [ICE_EEP2_I2S] = 0xf8,
0607 [ICE_EEP2_SPDIF] = 0xc1,
0608 [ICE_EEP2_GPIO_DIR] = 0x9f,
0609 [ICE_EEP2_GPIO_DIR1] = 0xff,
0610 [ICE_EEP2_GPIO_DIR2] = 0x7f,
0611 [ICE_EEP2_GPIO_MASK] = 0x9f,
0612 [ICE_EEP2_GPIO_MASK1] = 0xff,
0613 [ICE_EEP2_GPIO_MASK2] = 0x7f,
0614 [ICE_EEP2_GPIO_STATE] = 0x16,
0615 [ICE_EEP2_GPIO_STATE1] = 0x80,
0616 [ICE_EEP2_GPIO_STATE2] = 0x00,
0617 };
0618
0619
0620
0621 struct snd_ice1712_card_info snd_vt1724_wtm_cards[] = {
0622 {
0623 .subvendor = VT1724_SUBDEVICE_WTM,
0624 .name = "ESI Waveterminal 192M",
0625 .model = "WT192M",
0626 .chip_init = wtm_init,
0627 .build_controls = wtm_add_controls,
0628 .eeprom_size = sizeof(wtm_eeprom),
0629 .eeprom_data = wtm_eeprom,
0630 },
0631 {}
0632 };