| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/* |
| 3 |
* Driver for generic ESS AudioDrive ES18xx soundcards |
| 4 |
* Copyright (c) by Christian Fischbach <[email protected]> |
| 5 |
* Copyright (c) by Abramo Bagnara <[email protected]> |
| 6 |
*/ |
| 7 |
/* GENERAL NOTES: |
| 8 |
* |
| 9 |
* BUGS: |
| 10 |
* - There are pops (we can't delay in trigger function, cause midlevel |
| 11 |
* often need to trigger down and then up very quickly). |
| 12 |
* Any ideas? |
| 13 |
* - Support for 16 bit DMA seems to be broken. I've no hardware to tune it. |
| 14 |
*/ |
| 15 |
|
| 16 |
/* |
| 17 |
* ES1868 NOTES: |
| 18 |
* - The chip has one half duplex pcm (with very limited full duplex support). |
| 19 |
* |
| 20 |
* - Duplex stereophonic sound is impossible. |
| 21 |
* - Record and playback must share the same frequency rate. |
| 22 |
* |
| 23 |
* - The driver use dma2 for playback and dma1 for capture. |
| 24 |
*/ |
| 25 |
|
| 26 |
/* |
| 27 |
* ES1869 NOTES: |
| 28 |
* |
| 29 |
* - there are a first full duplex pcm and a second playback only pcm |
| 30 |
* (incompatible with first pcm capture) |
| 31 |
* |
| 32 |
* - there is support for the capture volume and ESS Spatializer 3D effect. |
| 33 |
* |
| 34 |
* - contrarily to some pages in DS_1869.PDF the rates can be set |
| 35 |
* independently. |
| 36 |
* |
| 37 |
* - Zoom Video is implemented by sharing the FM DAC, thus the user can |
| 38 |
* have either FM playback or Video playback but not both simultaneously. |
| 39 |
* The Video Playback Switch mixer control toggles this choice. |
| 40 |
* |
| 41 |
* BUGS: |
| 42 |
* |
| 43 |
* - There is a major trouble I noted: |
| 44 |
* |
| 45 |
* using both channel for playback stereo 16 bit samples at 44100 Hz |
| 46 |
* the second pcm (Audio1) DMA slows down irregularly and sound is garbled. |
| 47 |
* |
| 48 |
* The same happens using Audio1 for captureing. |
| 49 |
* |
| 50 |
* The Windows driver does not suffer of this (although it use Audio1 |
| 51 |
* only for captureing). I'm unable to discover why. |
| 52 |
* |
| 53 |
*/ |
| 54 |
|
| 55 |
/* |
| 56 |
* ES1879 NOTES: |
| 57 |
* - When Zoom Video is enabled (reg 0x71 bit 6 toggled on) the PCM playback |
| 58 |
* seems to be effected (speaker_test plays a lower frequency). Can't find |
| 59 |
* anything in the datasheet to account for this, so a Video Playback Switch |
| 60 |
* control has been included to allow ZV to be enabled only when necessary. |
| 61 |
* Then again on at least one test system the 0x71 bit 6 enable bit is not |
| 62 |
* needed for ZV, so maybe the datasheet is entirely wrong here. |
| 63 |
*/ |
| 64 |
|
| 65 |
#include <linux/init.h> |
| 66 |
#include <linux/err.h> |
| 67 |
#include <linux/isa.h> |
| 68 |
#include <linux/pnp.h> |
| 69 |
#include <linux/isapnp.h> |
| 70 |
#include <linux/module.h> |
| 71 |
#include <linux/delay.h> |
| 72 |
#include <linux/io.h> |
| 73 |
|
| 74 |
#include <asm/dma.h> |
| 75 |
#include <sound/core.h> |
| 76 |
#include <sound/control.h> |
| 77 |
#include <sound/pcm.h> |
| 78 |
#include <sound/pcm_params.h> |
| 79 |
#include <sound/mpu401.h> |
| 80 |
#include <sound/opl3.h> |
| 81 |
#define SNDRV_LEGACY_FIND_FREE_IRQ |
| 82 |
#define SNDRV_LEGACY_FIND_FREE_DMA |
| 83 |
#include <sound/initval.h> |
| 84 |
|
| 85 |
struct snd_es18xx { |
| 86 |
struct snd_card *card; |
| 87 |
unsigned long port; /* port of ESS chip */ |
| 88 |
unsigned long ctrl_port; /* Control port of ESS chip */ |
| 89 |
int irq; /* IRQ number of ESS chip */ |
| 90 |
int dma1; /* DMA1 */ |
| 91 |
int dma2; /* DMA2 */ |
| 92 |
unsigned short version; /* version of ESS chip */ |
| 93 |
int caps; /* Chip capabilities */ |
| 94 |
unsigned short audio2_vol; /* volume level of audio2 */ |
| 95 |
|
| 96 |
unsigned short active; /* active channel mask */ |
| 97 |
unsigned int dma1_shift; |
| 98 |
unsigned int dma2_shift; |
| 99 |
|
| 100 |
struct snd_pcm *pcm; |
| 101 |
struct snd_pcm_substream *playback_a_substream; |
| 102 |
struct snd_pcm_substream *capture_a_substream; |
| 103 |
struct snd_pcm_substream *playback_b_substream; |
| 104 |
|
| 105 |
struct snd_rawmidi *rmidi; |
| 106 |
|
| 107 |
struct snd_kcontrol *hw_volume; |
| 108 |
struct snd_kcontrol *hw_switch; |
| 109 |
struct snd_kcontrol *master_volume; |
| 110 |
struct snd_kcontrol *master_switch; |
| 111 |
|
| 112 |
spinlock_t reg_lock; |
| 113 |
spinlock_t mixer_lock; |
| 114 |
#ifdef CONFIG_PM |
| 115 |
unsigned char pm_reg; |
| 116 |
#endif |
| 117 |
#ifdef CONFIG_PNP |
| 118 |
struct pnp_dev *dev; |
| 119 |
struct pnp_dev *devc; |
| 120 |
#endif |
| 121 |
}; |
| 122 |
|
| 123 |
#define AUDIO1_IRQ 0x01 |
| 124 |
#define AUDIO2_IRQ 0x02 |
| 125 |
#define HWV_IRQ 0x04 |
| 126 |
#define MPU_IRQ 0x08 |
| 127 |
|
| 128 |
#define ES18XX_PCM2 0x0001 /* Has two useable PCM */ |
| 129 |
#define ES18XX_SPATIALIZER 0x0002 /* Has 3D Spatializer */ |
| 130 |
#define ES18XX_RECMIX 0x0004 /* Has record mixer */ |
| 131 |
#define ES18XX_DUPLEX_MONO 0x0008 /* Has mono duplex only */ |
| 132 |
#define ES18XX_DUPLEX_SAME 0x0010 /* Playback and record must share the same rate */ |
| 133 |
#define ES18XX_NEW_RATE 0x0020 /* More precise rate setting */ |
| 134 |
#define ES18XX_AUXB 0x0040 /* AuxB mixer control */ |
| 135 |
#define ES18XX_HWV 0x0080 /* Has separate hardware volume mixer controls*/ |
| 136 |
#define ES18XX_MONO 0x0100 /* Mono_in mixer control */ |
| 137 |
#define ES18XX_I2S 0x0200 /* I2S mixer control */ |
| 138 |
#define ES18XX_MUTEREC 0x0400 /* Record source can be muted */ |
| 139 |
#define ES18XX_CONTROL 0x0800 /* Has control ports */ |
| 140 |
#define ES18XX_GPO_2BIT 0x1000 /* GPO0,1 controlled by PM port */ |
| 141 |
|
| 142 |
/* Power Management */ |
| 143 |
#define ES18XX_PM 0x07 |
| 144 |
#define ES18XX_PM_GPO0 0x01 |
| 145 |
#define ES18XX_PM_GPO1 0x02 |
| 146 |
#define ES18XX_PM_PDR 0x04 |
| 147 |
#define ES18XX_PM_ANA 0x08 |
| 148 |
#define ES18XX_PM_FM 0x020 |
| 149 |
#define ES18XX_PM_SUS 0x080 |
| 150 |
|
| 151 |
/* Lowlevel */ |
| 152 |
|
| 153 |
#define DAC1 0x01 |
| 154 |
#define ADC1 0x02 |
| 155 |
#define DAC2 0x04 |
| 156 |
#define MILLISECOND 10000 |
| 157 |
|
| 158 |
static int snd_es18xx_dsp_command(struct snd_es18xx *chip, unsigned char val) |
| 159 |
{ |
| 160 |
int i; |
| 161 |
|
| 162 |
for(i = MILLISECOND; i; i--) |
| 163 |
if ((inb(chip->port + 0x0C) & 0x80) == 0) { |
| 164 |
outb(val, chip->port + 0x0C); |
| 165 |
return 0; |
| 166 |
} |
| 167 |
dev_err(chip->card->dev, "dsp_command: timeout (0x%x)\n", val); |
| 168 |
return -EINVAL; |
| 169 |
} |
| 170 |
|
| 171 |
static int snd_es18xx_dsp_get_byte(struct snd_es18xx *chip) |
| 172 |
{ |
| 173 |
int i; |
| 174 |
|
| 175 |
for(i = MILLISECOND/10; i; i--) |
| 176 |
if (inb(chip->port + 0x0C) & 0x40) |
| 177 |
return inb(chip->port + 0x0A); |
| 178 |
dev_err(chip->card->dev, "dsp_get_byte failed: 0x%lx = 0x%x!!!\n", |
| 179 |
chip->port + 0x0A, inb(chip->port + 0x0A)); |
| 180 |
return -ENODEV; |
| 181 |
} |
| 182 |
|
| 183 |
#undef REG_DEBUG |
| 184 |
|
| 185 |
static int snd_es18xx_write(struct snd_es18xx *chip, |
| 186 |
unsigned char reg, unsigned char data) |
| 187 |
{ |
| 188 |
int ret; |
| 189 |
|
| 190 |
guard(spinlock_irqsave)(&chip->reg_lock); |
| 191 |
ret = snd_es18xx_dsp_command(chip, reg); |
| 192 |
if (ret < 0) |
| 193 |
return ret; |
| 194 |
ret = snd_es18xx_dsp_command(chip, data); |
| 195 |
#ifdef REG_DEBUG |
| 196 |
dev_dbg(chip->card->dev, "Reg %02x set to %02x\n", reg, data); |
| 197 |
#endif |
| 198 |
return ret; |
| 199 |
} |
| 200 |
|
| 201 |
static int snd_es18xx_read(struct snd_es18xx *chip, unsigned char reg) |
| 202 |
{ |
| 203 |
int ret, data; |
| 204 |
|
| 205 |
guard(spinlock_irqsave)(&chip->reg_lock); |
| 206 |
ret = snd_es18xx_dsp_command(chip, 0xC0); |
| 207 |
if (ret < 0) |
| 208 |
return ret; |
| 209 |
ret = snd_es18xx_dsp_command(chip, reg); |
| 210 |
if (ret < 0) |
| 211 |
return ret; |
| 212 |
data = snd_es18xx_dsp_get_byte(chip); |
| 213 |
ret = data; |
| 214 |
#ifdef REG_DEBUG |
| 215 |
dev_dbg(chip->card->dev, "Reg %02x now is %02x (%d)\n", reg, data, ret); |
| 216 |
#endif |
| 217 |
return ret; |
| 218 |
} |
| 219 |
|
| 220 |
/* Return old value */ |
| 221 |
static int snd_es18xx_bits(struct snd_es18xx *chip, unsigned char reg, |
| 222 |
unsigned char mask, unsigned char val) |
| 223 |
{ |
| 224 |
int ret; |
| 225 |
unsigned char old, new, oval; |
| 226 |
|
| 227 |
guard(spinlock_irqsave)(&chip->reg_lock); |
| 228 |
ret = snd_es18xx_dsp_command(chip, 0xC0); |
| 229 |
if (ret < 0) |
| 230 |
return ret; |
| 231 |
ret = snd_es18xx_dsp_command(chip, reg); |
| 232 |
if (ret < 0) |
| 233 |
return ret; |
| 234 |
ret = snd_es18xx_dsp_get_byte(chip); |
| 235 |
if (ret < 0) |
| 236 |
return ret; |
| 237 |
old = ret; |
| 238 |
oval = old & mask; |
| 239 |
if (val != oval) { |
| 240 |
ret = snd_es18xx_dsp_command(chip, reg); |
| 241 |
if (ret < 0) |
| 242 |
return ret; |
| 243 |
new = (old & ~mask) | (val & mask); |
| 244 |
ret = snd_es18xx_dsp_command(chip, new); |
| 245 |
if (ret < 0) |
| 246 |
return ret; |
| 247 |
#ifdef REG_DEBUG |
| 248 |
dev_dbg(chip->card->dev, "Reg %02x was %02x, set to %02x (%d)\n", |
| 249 |
reg, old, new, ret); |
| 250 |
#endif |
| 251 |
} |
| 252 |
return oval; |
| 253 |
} |
| 254 |
|
| 255 |
static inline void snd_es18xx_mixer_write(struct snd_es18xx *chip, |
| 256 |
unsigned char reg, unsigned char data) |
| 257 |
{ |
| 258 |
guard(spinlock_irqsave)(&chip->mixer_lock); |
| 259 |
outb(reg, chip->port + 0x04); |
| 260 |
outb(data, chip->port + 0x05); |
| 261 |
#ifdef REG_DEBUG |
| 262 |
dev_dbg(chip->card->dev, "Mixer reg %02x set to %02x\n", reg, data); |
| 263 |
#endif |
| 264 |
} |
| 265 |
|
| 266 |
static inline int snd_es18xx_mixer_read(struct snd_es18xx *chip, unsigned char reg) |
| 267 |
{ |
| 268 |
int data; |
| 269 |
|
| 270 |
guard(spinlock_irqsave)(&chip->mixer_lock); |
| 271 |
outb(reg, chip->port + 0x04); |
| 272 |
data = inb(chip->port + 0x05); |
| 273 |
#ifdef REG_DEBUG |
| 274 |
dev_dbg(chip->card->dev, "Mixer reg %02x now is %02x\n", reg, data); |
| 275 |
#endif |
| 276 |
return data; |
| 277 |
} |
| 278 |
|
| 279 |
/* Return old value */ |
| 280 |
static inline int snd_es18xx_mixer_bits(struct snd_es18xx *chip, unsigned char reg, |
| 281 |
unsigned char mask, unsigned char val) |
| 282 |
{ |
| 283 |
unsigned char old, new, oval; |
| 284 |
|
| 285 |
guard(spinlock_irqsave)(&chip->mixer_lock); |
| 286 |
outb(reg, chip->port + 0x04); |
| 287 |
old = inb(chip->port + 0x05); |
| 288 |
oval = old & mask; |
| 289 |
if (val != oval) { |
| 290 |
new = (old & ~mask) | (val & mask); |
| 291 |
outb(new, chip->port + 0x05); |
| 292 |
#ifdef REG_DEBUG |
| 293 |
dev_dbg(chip->card->dev, "Mixer reg %02x was %02x, set to %02x\n", |
| 294 |
reg, old, new); |
| 295 |
#endif |
| 296 |
} |
| 297 |
return oval; |
| 298 |
} |
| 299 |
|
| 300 |
static inline int snd_es18xx_mixer_writable(struct snd_es18xx *chip, unsigned char reg, |
| 301 |
unsigned char mask) |
| 302 |
{ |
| 303 |
int old, expected, new; |
| 304 |
|
| 305 |
guard(spinlock_irqsave)(&chip->mixer_lock); |
| 306 |
outb(reg, chip->port + 0x04); |
| 307 |
old = inb(chip->port + 0x05); |
| 308 |
expected = old ^ mask; |
| 309 |
outb(expected, chip->port + 0x05); |
| 310 |
new = inb(chip->port + 0x05); |
| 311 |
#ifdef REG_DEBUG |
| 312 |
dev_dbg(chip->card->dev, "Mixer reg %02x was %02x, set to %02x, now is %02x\n", |
| 313 |
reg, old, expected, new); |
| 314 |
#endif |
| 315 |
return expected == new; |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
static int snd_es18xx_reset(struct snd_es18xx *chip) |
| 320 |
{ |
| 321 |
int i; |
| 322 |
outb(0x03, chip->port + 0x06); |
| 323 |
inb(chip->port + 0x06); |
| 324 |
outb(0x00, chip->port + 0x06); |
| 325 |
for(i = 0; i < MILLISECOND && !(inb(chip->port + 0x0E) & 0x80); i++); |
| 326 |
if (inb(chip->port + 0x0A) != 0xAA) |
| 327 |
return -1; |
| 328 |
return 0; |
| 329 |
} |
| 330 |
|
| 331 |
static int snd_es18xx_reset_fifo(struct snd_es18xx *chip) |
| 332 |
{ |
| 333 |
outb(0x02, chip->port + 0x06); |
| 334 |
inb(chip->port + 0x06); |
| 335 |
outb(0x00, chip->port + 0x06); |
| 336 |
return 0; |
| 337 |
} |
| 338 |
|
| 339 |
static const struct snd_ratnum new_clocks[2] = { |
| 340 |
{ |
| 341 |
.num = 793800, |
| 342 |
.den_min = 1, |
| 343 |
.den_max = 128, |
| 344 |
.den_step = 1, |
| 345 |
}, |
| 346 |
{ |
| 347 |
.num = 768000, |
| 348 |
.den_min = 1, |
| 349 |
.den_max = 128, |
| 350 |
.den_step = 1, |
| 351 |
} |
| 352 |
}; |
| 353 |
|
| 354 |
static const struct snd_pcm_hw_constraint_ratnums new_hw_constraints_clocks = { |
| 355 |
.nrats = 2, |
| 356 |
.rats = new_clocks, |
| 357 |
}; |
| 358 |
|
| 359 |
static const struct snd_ratnum old_clocks[2] = { |
| 360 |
{ |
| 361 |
.num = 795444, |
| 362 |
.den_min = 1, |
| 363 |
.den_max = 128, |
| 364 |
.den_step = 1, |
| 365 |
}, |
| 366 |
{ |
| 367 |
.num = 397722, |
| 368 |
.den_min = 1, |
| 369 |
.den_max = 128, |
| 370 |
.den_step = 1, |
| 371 |
} |
| 372 |
}; |
| 373 |
|
| 374 |
static const struct snd_pcm_hw_constraint_ratnums old_hw_constraints_clocks = { |
| 375 |
.nrats = 2, |
| 376 |
.rats = old_clocks, |
| 377 |
}; |
| 378 |
|
| 379 |
|
| 380 |
static void snd_es18xx_rate_set(struct snd_es18xx *chip, |
| 381 |
struct snd_pcm_substream *substream, |
| 382 |
int mode) |
| 383 |
{ |
| 384 |
unsigned int bits, div0; |
| 385 |
struct snd_pcm_runtime *runtime = substream->runtime; |
| 386 |
if (chip->caps & ES18XX_NEW_RATE) { |
| 387 |
if (runtime->rate_num == new_clocks[0].num) |
| 388 |
bits = 128 - runtime->rate_den; |
| 389 |
else |
| 390 |
bits = 256 - runtime->rate_den; |
| 391 |
} else { |
| 392 |
if (runtime->rate_num == old_clocks[0].num) |
| 393 |
bits = 256 - runtime->rate_den; |
| 394 |
else |
| 395 |
bits = 128 - runtime->rate_den; |
| 396 |
} |
| 397 |
|
| 398 |
/* set filter register */ |
| 399 |
div0 = 256 - 7160000*20/(8*82*runtime->rate); |
| 400 |
|
| 401 |
if ((chip->caps & ES18XX_PCM2) && mode == DAC2) { |
| 402 |
snd_es18xx_mixer_write(chip, 0x70, bits); |
| 403 |
/* |
| 404 |
* Comment from kernel oss driver: |
| 405 |
* FKS: fascinating: 0x72 doesn't seem to work. |
| 406 |
*/ |
| 407 |
snd_es18xx_write(chip, 0xA2, div0); |
| 408 |
snd_es18xx_mixer_write(chip, 0x72, div0); |
| 409 |
} else { |
| 410 |
snd_es18xx_write(chip, 0xA1, bits); |
| 411 |
snd_es18xx_write(chip, 0xA2, div0); |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
static int snd_es18xx_playback_hw_params(struct snd_pcm_substream *substream, |
| 416 |
struct snd_pcm_hw_params *hw_params) |
| 417 |
{ |
| 418 |
struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
| 419 |
int shift; |
| 420 |
|
| 421 |
shift = 0; |
| 422 |
if (params_channels(hw_params) == 2) |
| 423 |
shift++; |
| 424 |
if (snd_pcm_format_width(params_format(hw_params)) == 16) |
| 425 |
shift++; |
| 426 |
|
| 427 |
if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) { |
| 428 |
if ((chip->caps & ES18XX_DUPLEX_MONO) && |
| 429 |
(chip->capture_a_substream) && |
| 430 |
params_channels(hw_params) != 1) { |
| 431 |
_snd_pcm_hw_param_setempty(hw_params, SNDRV_PCM_HW_PARAM_CHANNELS); |
| 432 |
return -EBUSY; |
| 433 |
} |
| 434 |
chip->dma2_shift = shift; |
| 435 |
} else { |
| 436 |
chip->dma1_shift = shift; |
| 437 |
} |
| 438 |
return 0; |
| 439 |
} |
| 440 |
|
| 441 |
static int snd_es18xx_playback1_prepare(struct snd_es18xx *chip, |
| 442 |
struct snd_pcm_substream *substream) |
| 443 |
{ |
| 444 |
struct snd_pcm_runtime *runtime = substream->runtime; |
| 445 |
unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 446 |
unsigned int count = snd_pcm_lib_period_bytes(substream); |
| 447 |
|
| 448 |
snd_es18xx_rate_set(chip, substream, DAC2); |
| 449 |
|
| 450 |
/* Transfer Count Reload */ |
| 451 |
count = 0x10000 - count; |
| 452 |
snd_es18xx_mixer_write(chip, 0x74, count & 0xff); |
| 453 |
snd_es18xx_mixer_write(chip, 0x76, count >> 8); |
| 454 |
|
| 455 |
/* Set format */ |
| 456 |
snd_es18xx_mixer_bits(chip, 0x7A, 0x07, |
| 457 |
((runtime->channels == 1) ? 0x00 : 0x02) | |
| 458 |
(snd_pcm_format_width(runtime->format) == 16 ? 0x01 : 0x00) | |
| 459 |
(snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x04)); |
| 460 |
|
| 461 |
/* Set DMA controller */ |
| 462 |
snd_dma_program(chip->dma2, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT); |
| 463 |
|
| 464 |
return 0; |
| 465 |
} |
| 466 |
|
| 467 |
static int snd_es18xx_playback1_trigger(struct snd_es18xx *chip, |
| 468 |
struct snd_pcm_substream *substream, |
| 469 |
int cmd) |
| 470 |
{ |
| 471 |
switch (cmd) { |
| 472 |
case SNDRV_PCM_TRIGGER_START: |
| 473 |
case SNDRV_PCM_TRIGGER_RESUME: |
| 474 |
if (chip->active & DAC2) |
| 475 |
return 0; |
| 476 |
chip->active |= DAC2; |
| 477 |
/* Start DMA */ |
| 478 |
if (chip->dma2 >= 4) |
| 479 |
snd_es18xx_mixer_write(chip, 0x78, 0xb3); |
| 480 |
else |
| 481 |
snd_es18xx_mixer_write(chip, 0x78, 0x93); |
| 482 |
#ifdef AVOID_POPS |
| 483 |
/* Avoid pops */ |
| 484 |
mdelay(100); |
| 485 |
if (chip->caps & ES18XX_PCM2) |
| 486 |
/* Restore Audio 2 volume */ |
| 487 |
snd_es18xx_mixer_write(chip, 0x7C, chip->audio2_vol); |
| 488 |
else |
| 489 |
/* Enable PCM output */ |
| 490 |
snd_es18xx_dsp_command(chip, 0xD1); |
| 491 |
#endif |
| 492 |
break; |
| 493 |
case SNDRV_PCM_TRIGGER_STOP: |
| 494 |
case SNDRV_PCM_TRIGGER_SUSPEND: |
| 495 |
if (!(chip->active & DAC2)) |
| 496 |
return 0; |
| 497 |
chip->active &= ~DAC2; |
| 498 |
/* Stop DMA */ |
| 499 |
snd_es18xx_mixer_write(chip, 0x78, 0x00); |
| 500 |
#ifdef AVOID_POPS |
| 501 |
mdelay(25); |
| 502 |
if (chip->caps & ES18XX_PCM2) |
| 503 |
/* Set Audio 2 volume to 0 */ |
| 504 |
snd_es18xx_mixer_write(chip, 0x7C, 0); |
| 505 |
else |
| 506 |
/* Disable PCM output */ |
| 507 |
snd_es18xx_dsp_command(chip, 0xD3); |
| 508 |
#endif |
| 509 |
break; |
| 510 |
default: |
| 511 |
return -EINVAL; |
| 512 |
} |
| 513 |
|
| 514 |
return 0; |
| 515 |
} |
| 516 |
|
| 517 |
static int snd_es18xx_capture_hw_params(struct snd_pcm_substream *substream, |
| 518 |
struct snd_pcm_hw_params *hw_params) |
| 519 |
{ |
| 520 |
struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
| 521 |
int shift; |
| 522 |
|
| 523 |
shift = 0; |
| 524 |
if ((chip->caps & ES18XX_DUPLEX_MONO) && |
| 525 |
chip->playback_a_substream && |
| 526 |
params_channels(hw_params) != 1) { |
| 527 |
_snd_pcm_hw_param_setempty(hw_params, SNDRV_PCM_HW_PARAM_CHANNELS); |
| 528 |
return -EBUSY; |
| 529 |
} |
| 530 |
if (params_channels(hw_params) == 2) |
| 531 |
shift++; |
| 532 |
if (snd_pcm_format_width(params_format(hw_params)) == 16) |
| 533 |
shift++; |
| 534 |
chip->dma1_shift = shift; |
| 535 |
return 0; |
| 536 |
} |
| 537 |
|
| 538 |
static int snd_es18xx_capture_prepare(struct snd_pcm_substream *substream) |
| 539 |
{ |
| 540 |
struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
| 541 |
struct snd_pcm_runtime *runtime = substream->runtime; |
| 542 |
unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 543 |
unsigned int count = snd_pcm_lib_period_bytes(substream); |
| 544 |
|
| 545 |
snd_es18xx_reset_fifo(chip); |
| 546 |
|
| 547 |
/* Set stereo/mono */ |
| 548 |
snd_es18xx_bits(chip, 0xA8, 0x03, runtime->channels == 1 ? 0x02 : 0x01); |
| 549 |
|
| 550 |
snd_es18xx_rate_set(chip, substream, ADC1); |
| 551 |
|
| 552 |
/* Transfer Count Reload */ |
| 553 |
count = 0x10000 - count; |
| 554 |
snd_es18xx_write(chip, 0xA4, count & 0xff); |
| 555 |
snd_es18xx_write(chip, 0xA5, count >> 8); |
| 556 |
|
| 557 |
#ifdef AVOID_POPS |
| 558 |
mdelay(100); |
| 559 |
#endif |
| 560 |
|
| 561 |
/* Set format */ |
| 562 |
snd_es18xx_write(chip, 0xB7, |
| 563 |
snd_pcm_format_unsigned(runtime->format) ? 0x51 : 0x71); |
| 564 |
snd_es18xx_write(chip, 0xB7, 0x90 | |
| 565 |
((runtime->channels == 1) ? 0x40 : 0x08) | |
| 566 |
(snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) | |
| 567 |
(snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20)); |
| 568 |
|
| 569 |
/* Set DMA controller */ |
| 570 |
snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT); |
| 571 |
|
| 572 |
return 0; |
| 573 |
} |
| 574 |
|
| 575 |
static int snd_es18xx_capture_trigger(struct snd_pcm_substream *substream, |
| 576 |
int cmd) |
| 577 |
{ |
| 578 |
struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
| 579 |
|
| 580 |
switch (cmd) { |
| 581 |
case SNDRV_PCM_TRIGGER_START: |
| 582 |
case SNDRV_PCM_TRIGGER_RESUME: |
| 583 |
if (chip->active & ADC1) |
| 584 |
return 0; |
| 585 |
chip->active |= ADC1; |
| 586 |
/* Start DMA */ |
| 587 |
snd_es18xx_write(chip, 0xB8, 0x0f); |
| 588 |
break; |
| 589 |
case SNDRV_PCM_TRIGGER_STOP: |
| 590 |
case SNDRV_PCM_TRIGGER_SUSPEND: |
| 591 |
if (!(chip->active & ADC1)) |
| 592 |
return 0; |
| 593 |
chip->active &= ~ADC1; |
| 594 |
/* Stop DMA */ |
| 595 |
snd_es18xx_write(chip, 0xB8, 0x00); |
| 596 |
break; |
| 597 |
default: |
| 598 |
return -EINVAL; |
| 599 |
} |
| 600 |
|
| 601 |
return 0; |
| 602 |
} |
| 603 |
|
| 604 |
static int snd_es18xx_playback2_prepare(struct snd_es18xx *chip, |
| 605 |
struct snd_pcm_substream *substream) |
| 606 |
{ |
| 607 |
struct snd_pcm_runtime *runtime = substream->runtime; |
| 608 |
unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 609 |
unsigned int count = snd_pcm_lib_period_bytes(substream); |
| 610 |
|
| 611 |
snd_es18xx_reset_fifo(chip); |
| 612 |
|
| 613 |
/* Set stereo/mono */ |
| 614 |
snd_es18xx_bits(chip, 0xA8, 0x03, runtime->channels == 1 ? 0x02 : 0x01); |
| 615 |
|
| 616 |
snd_es18xx_rate_set(chip, substream, DAC1); |
| 617 |
|
| 618 |
/* Transfer Count Reload */ |
| 619 |
count = 0x10000 - count; |
| 620 |
snd_es18xx_write(chip, 0xA4, count & 0xff); |
| 621 |
snd_es18xx_write(chip, 0xA5, count >> 8); |
| 622 |
|
| 623 |
/* Set format */ |
| 624 |
snd_es18xx_write(chip, 0xB6, |
| 625 |
snd_pcm_format_unsigned(runtime->format) ? 0x80 : 0x00); |
| 626 |
snd_es18xx_write(chip, 0xB7, |
| 627 |
snd_pcm_format_unsigned(runtime->format) ? 0x51 : 0x71); |
| 628 |
snd_es18xx_write(chip, 0xB7, 0x90 | |
| 629 |
(runtime->channels == 1 ? 0x40 : 0x08) | |
| 630 |
(snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) | |
| 631 |
(snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20)); |
| 632 |
|
| 633 |
/* Set DMA controller */ |
| 634 |
snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT); |
| 635 |
|
| 636 |
return 0; |
| 637 |
} |
| 638 |
|
| 639 |
static int snd_es18xx_playback2_trigger(struct snd_es18xx *chip, |
| 640 |
struct snd_pcm_substream *substream, |
| 641 |
int cmd) |
| 642 |
{ |
| 643 |
switch (cmd) { |
| 644 |
case SNDRV_PCM_TRIGGER_START: |
| 645 |
case SNDRV_PCM_TRIGGER_RESUME: |
| 646 |
if (chip->active & DAC1) |
| 647 |
return 0; |
| 648 |
chip->active |= DAC1; |
| 649 |
/* Start DMA */ |
| 650 |
snd_es18xx_write(chip, 0xB8, 0x05); |
| 651 |
#ifdef AVOID_POPS |
| 652 |
/* Avoid pops */ |
| 653 |
mdelay(100); |
| 654 |
/* Enable Audio 1 */ |
| 655 |
snd_es18xx_dsp_command(chip, 0xD1); |
| 656 |
#endif |
| 657 |
break; |
| 658 |
case SNDRV_PCM_TRIGGER_STOP: |
| 659 |
case SNDRV_PCM_TRIGGER_SUSPEND: |
| 660 |
if (!(chip->active & DAC1)) |
| 661 |
return 0; |
| 662 |
chip->active &= ~DAC1; |
| 663 |
/* Stop DMA */ |
| 664 |
snd_es18xx_write(chip, 0xB8, 0x00); |
| 665 |
#ifdef AVOID_POPS |
| 666 |
/* Avoid pops */ |
| 667 |
mdelay(25); |
| 668 |
/* Disable Audio 1 */ |
| 669 |
snd_es18xx_dsp_command(chip, 0xD3); |
| 670 |
#endif |
| 671 |
break; |
| 672 |
default: |
| 673 |
return -EINVAL; |
| 674 |
} |
| 675 |
|
| 676 |
return 0; |
| 677 |
} |
| 678 |
|
| 679 |
static int snd_es18xx_playback_prepare(struct snd_pcm_substream *substream) |
| 680 |
{ |
| 681 |
struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
| 682 |
if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) |
| 683 |
return snd_es18xx_playback1_prepare(chip, substream); |
| 684 |
else |
| 685 |
return snd_es18xx_playback2_prepare(chip, substream); |
| 686 |
} |
| 687 |
|
| 688 |
static int snd_es18xx_playback_trigger(struct snd_pcm_substream *substream, |
| 689 |
int cmd) |
| 690 |
{ |
| 691 |
struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
| 692 |
if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) |
| 693 |
return snd_es18xx_playback1_trigger(chip, substream, cmd); |
| 694 |
else |
| 695 |
return snd_es18xx_playback2_trigger(chip, substream, cmd); |
| 696 |
} |
| 697 |
|
| 698 |
static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id) |
| 699 |
{ |
| 700 |
struct snd_card *card = dev_id; |
| 701 |
struct snd_es18xx *chip = card->private_data; |
| 702 |
unsigned char status; |
| 703 |
|
| 704 |
if (chip->caps & ES18XX_CONTROL) { |
| 705 |
/* Read Interrupt status */ |
| 706 |
status = inb(chip->ctrl_port + 6); |
| 707 |
} else { |
| 708 |
/* Read Interrupt status */ |
| 709 |
status = snd_es18xx_mixer_read(chip, 0x7f) >> 4; |
| 710 |
} |
| 711 |
#if 0 |
| 712 |
else { |
| 713 |
status = 0; |
| 714 |
if (inb(chip->port + 0x0C) & 0x01) |
| 715 |
status |= AUDIO1_IRQ; |
| 716 |
if (snd_es18xx_mixer_read(chip, 0x7A) & 0x80) |
| 717 |
status |= AUDIO2_IRQ; |
| 718 |
if ((chip->caps & ES18XX_HWV) && |
| 719 |
snd_es18xx_mixer_read(chip, 0x64) & 0x10) |
| 720 |
status |= HWV_IRQ; |
| 721 |
} |
| 722 |
#endif |
| 723 |
|
| 724 |
/* Audio 1 & Audio 2 */ |
| 725 |
if (status & AUDIO2_IRQ) { |
| 726 |
if (chip->active & DAC2) |
| 727 |
snd_pcm_period_elapsed(chip->playback_a_substream); |
| 728 |
/* ack interrupt */ |
| 729 |
snd_es18xx_mixer_bits(chip, 0x7A, 0x80, 0x00); |
| 730 |
} |
| 731 |
if (status & AUDIO1_IRQ) { |
| 732 |
/* ok.. capture is active */ |
| 733 |
if (chip->active & ADC1) |
| 734 |
snd_pcm_period_elapsed(chip->capture_a_substream); |
| 735 |
/* ok.. playback2 is active */ |
| 736 |
else if (chip->active & DAC1) |
| 737 |
snd_pcm_period_elapsed(chip->playback_b_substream); |
| 738 |
/* ack interrupt */ |
| 739 |
inb(chip->port + 0x0E); |
| 740 |
} |
| 741 |
|
| 742 |
/* MPU */ |
| 743 |
if ((status & MPU_IRQ) && chip->rmidi) |
| 744 |
snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data); |
| 745 |
|
| 746 |
/* Hardware volume */ |
| 747 |
if (status & HWV_IRQ) { |
| 748 |
int split = 0; |
| 749 |
if (chip->caps & ES18XX_HWV) { |
| 750 |
split = snd_es18xx_mixer_read(chip, 0x64) & 0x80; |
| 751 |
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 752 |
&chip->hw_switch->id); |
| 753 |
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 754 |
&chip->hw_volume->id); |
| 755 |
} |
| 756 |
if (!split) { |
| 757 |
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 758 |
&chip->master_switch->id); |
| 759 |
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 760 |
&chip->master_volume->id); |
| 761 |
} |
| 762 |
/* ack interrupt */ |
| 763 |
snd_es18xx_mixer_write(chip, 0x66, 0x00); |
| 764 |
} |
| 765 |
return IRQ_HANDLED; |
| 766 |
} |
| 767 |
|
| 768 |
static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *substream) |
| 769 |
{ |
| 770 |
struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
| 771 |
unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 772 |
int pos; |
| 773 |
|
| 774 |
if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) { |
| 775 |
if (!(chip->active & DAC2)) |
| 776 |
return 0; |
| 777 |
pos = snd_dma_pointer(chip->dma2, size); |
| 778 |
return pos >> chip->dma2_shift; |
| 779 |
} else { |
| 780 |
if (!(chip->active & DAC1)) |
| 781 |
return 0; |
| 782 |
pos = snd_dma_pointer(chip->dma1, size); |
| 783 |
return pos >> chip->dma1_shift; |
| 784 |
} |
| 785 |
} |
| 786 |
|
| 787 |
static snd_pcm_uframes_t snd_es18xx_capture_pointer(struct snd_pcm_substream *substream) |
| 788 |
{ |
| 789 |
struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
| 790 |
unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 791 |
int pos; |
| 792 |
|
| 793 |
if (!(chip->active & ADC1)) |
| 794 |
return 0; |
| 795 |
pos = snd_dma_pointer(chip->dma1, size); |
| 796 |
return pos >> chip->dma1_shift; |
| 797 |
} |
| 798 |
|
| 799 |
static const struct snd_pcm_hardware snd_es18xx_playback = |
| 800 |
{ |
| 801 |
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 802 |
SNDRV_PCM_INFO_RESUME | |
| 803 |
SNDRV_PCM_INFO_MMAP_VALID), |
| 804 |
.formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 | |
| 805 |
SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE), |
| 806 |
.rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 807 |
.rate_min = 4000, |
| 808 |
.rate_max = 48000, |
| 809 |
.channels_min = 1, |
| 810 |
.channels_max = 2, |
| 811 |
.buffer_bytes_max = 65536, |
| 812 |
.period_bytes_min = 64, |
| 813 |
.period_bytes_max = 65536, |
| 814 |
.periods_min = 1, |
| 815 |
.periods_max = 1024, |
| 816 |
.fifo_size = 0, |
| 817 |
}; |
| 818 |
|
| 819 |
static const struct snd_pcm_hardware snd_es18xx_capture = |
| 820 |
{ |
| 821 |
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 822 |
SNDRV_PCM_INFO_RESUME | |
| 823 |
SNDRV_PCM_INFO_MMAP_VALID), |
| 824 |
.formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 | |
| 825 |
SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE), |
| 826 |
.rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 827 |
.rate_min = 4000, |
| 828 |
.rate_max = 48000, |
| 829 |
.channels_min = 1, |
| 830 |
.channels_max = 2, |
| 831 |
.buffer_bytes_max = 65536, |
| 832 |
.period_bytes_min = 64, |
| 833 |
.period_bytes_max = 65536, |
| 834 |
.periods_min = 1, |
| 835 |
.periods_max = 1024, |
| 836 |
.fifo_size = 0, |
| 837 |
}; |
| 838 |
|
| 839 |
static int snd_es18xx_playback_open(struct snd_pcm_substream *substream) |
| 840 |
{ |
| 841 |
struct snd_pcm_runtime *runtime = substream->runtime; |
| 842 |
struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
| 843 |
|
| 844 |
if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) { |
| 845 |
if ((chip->caps & ES18XX_DUPLEX_MONO) && |
| 846 |
chip->capture_a_substream && |
| 847 |
chip->capture_a_substream->runtime->channels != 1) |
| 848 |
return -EAGAIN; |
| 849 |
chip->playback_a_substream = substream; |
| 850 |
} else if (substream->number <= 1) { |
| 851 |
if (chip->capture_a_substream) |
| 852 |
return -EAGAIN; |
| 853 |
chip->playback_b_substream = substream; |
| 854 |
} else { |
| 855 |
snd_BUG(); |
| 856 |
return -EINVAL; |
| 857 |
} |
| 858 |
substream->runtime->hw = snd_es18xx_playback; |
| 859 |
snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 860 |
(chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks); |
| 861 |
return 0; |
| 862 |
} |
| 863 |
|
| 864 |
static int snd_es18xx_capture_open(struct snd_pcm_substream *substream) |
| 865 |
{ |
| 866 |
struct snd_pcm_runtime *runtime = substream->runtime; |
| 867 |
struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
| 868 |
|
| 869 |
if (chip->playback_b_substream) |
| 870 |
return -EAGAIN; |
| 871 |
if ((chip->caps & ES18XX_DUPLEX_MONO) && |
| 872 |
chip->playback_a_substream && |
| 873 |
chip->playback_a_substream->runtime->channels != 1) |
| 874 |
return -EAGAIN; |
| 875 |
chip->capture_a_substream = substream; |
| 876 |
substream->runtime->hw = snd_es18xx_capture; |
| 877 |
snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 878 |
(chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks); |
| 879 |
return 0; |
| 880 |
} |
| 881 |
|
| 882 |
static int snd_es18xx_playback_close(struct snd_pcm_substream *substream) |
| 883 |
{ |
| 884 |
struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
| 885 |
|
| 886 |
if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) |
| 887 |
chip->playback_a_substream = NULL; |
| 888 |
else |
| 889 |
chip->playback_b_substream = NULL; |
| 890 |
|
| 891 |
return 0; |
| 892 |
} |
| 893 |
|
| 894 |
static int snd_es18xx_capture_close(struct snd_pcm_substream *substream) |
| 895 |
{ |
| 896 |
struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
| 897 |
|
| 898 |
chip->capture_a_substream = NULL; |
| 899 |
return 0; |
| 900 |
} |
| 901 |
|
| 902 |
/* |
| 903 |
* MIXER part |
| 904 |
*/ |
| 905 |
|
| 906 |
/* Record source mux routines: |
| 907 |
* Depending on the chipset this mux switches between 4, 5, or 8 possible inputs. |
| 908 |
* bit table for the 4/5 source mux: |
| 909 |
* reg 1C: |
| 910 |
* b2 b1 b0 muxSource |
| 911 |
* x 0 x microphone |
| 912 |
* 0 1 x CD |
| 913 |
* 1 1 0 line |
| 914 |
* 1 1 1 mixer |
| 915 |
* if it's "mixer" and it's a 5 source mux chipset then reg 7A bit 3 determines |
| 916 |
* either the play mixer or the capture mixer. |
| 917 |
* |
| 918 |
* "map4Source" translates from source number to reg bit pattern |
| 919 |
* "invMap4Source" translates from reg bit pattern to source number |
| 920 |
*/ |
| 921 |
|
| 922 |
static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
| 923 |
{ |
| 924 |
static const char * const texts5Source[5] = { |
| 925 |
"Mic", "CD", "Line", "Master", "Mix" |
| 926 |
}; |
| 927 |
static const char * const texts8Source[8] = { |
| 928 |
"Mic", "Mic Master", "CD", "AOUT", |
| 929 |
"Mic1", "Mix", "Line", "Master" |
| 930 |
}; |
| 931 |
struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
| 932 |
|
| 933 |
switch (chip->version) { |
| 934 |
case 0x1868: |
| 935 |
case 0x1878: |
| 936 |
return snd_ctl_enum_info(uinfo, 1, 4, texts5Source); |
| 937 |
case 0x1887: |
| 938 |
case 0x1888: |
| 939 |
return snd_ctl_enum_info(uinfo, 1, 5, texts5Source); |
| 940 |
case 0x1869: /* DS somewhat contradictory for 1869: could be 5 or 8 */ |
| 941 |
case 0x1879: |
| 942 |
return snd_ctl_enum_info(uinfo, 1, 8, texts8Source); |
| 943 |
default: |
| 944 |
return -EINVAL; |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
static int snd_es18xx_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 949 |
{ |
| 950 |
static const unsigned char invMap4Source[8] = {0, 0, 1, 1, 0, 0, 2, 3}; |
| 951 |
struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
| 952 |
int muxSource = snd_es18xx_mixer_read(chip, 0x1c) & 0x07; |
| 953 |
if (!(chip->version == 0x1869 || chip->version == 0x1879)) { |
| 954 |
muxSource = invMap4Source[muxSource]; |
| 955 |
if (muxSource==3 && |
| 956 |
(chip->version == 0x1887 || chip->version == 0x1888) && |
| 957 |
(snd_es18xx_mixer_read(chip, 0x7a) & 0x08) |
| 958 |
) |
| 959 |
muxSource = 4; |
| 960 |
} |
| 961 |
ucontrol->value.enumerated.item[0] = muxSource; |
| 962 |
return 0; |
| 963 |
} |
| 964 |
|
| 965 |
static int snd_es18xx_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 966 |
{ |
| 967 |
static const unsigned char map4Source[4] = {0, 2, 6, 7}; |
| 968 |
struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
| 969 |
unsigned char val = ucontrol->value.enumerated.item[0]; |
| 970 |
unsigned char retVal = 0; |
| 971 |
|
| 972 |
switch (chip->version) { |
| 973 |
/* 5 source chips */ |
| 974 |
case 0x1887: |
| 975 |
case 0x1888: |
| 976 |
if (val > 4) |
| 977 |
return -EINVAL; |
| 978 |
if (val == 4) { |
| 979 |
retVal = snd_es18xx_mixer_bits(chip, 0x7a, 0x08, 0x08) != 0x08; |
| 980 |
val = 3; |
| 981 |
} else |
| 982 |
retVal = snd_es18xx_mixer_bits(chip, 0x7a, 0x08, 0x00) != 0x00; |
| 983 |
fallthrough; |
| 984 |
/* 4 source chips */ |
| 985 |
case 0x1868: |
| 986 |
case 0x1878: |
| 987 |
if (val > 3) |
| 988 |
return -EINVAL; |
| 989 |
val = map4Source[val]; |
| 990 |
break; |
| 991 |
/* 8 source chips */ |
| 992 |
case 0x1869: |
| 993 |
case 0x1879: |
| 994 |
if (val > 7) |
| 995 |
return -EINVAL; |
| 996 |
break; |
| 997 |
default: |
| 998 |
return -EINVAL; |
| 999 |
} |
| 1000 |
return (snd_es18xx_mixer_bits(chip, 0x1c, 0x07, val) != val) || retVal; |
| 1001 |
} |
| 1002 |
|
| 1003 |
#define snd_es18xx_info_spatializer_enable snd_ctl_boolean_mono_info |
| 1004 |
|
| 1005 |
static int snd_es18xx_get_spatializer_enable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 1006 |
{ |
| 1007 |
struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
| 1008 |
unsigned char val = snd_es18xx_mixer_read(chip, 0x50); |
| 1009 |
ucontrol->value.integer.value[0] = !!(val & 8); |
| 1010 |
return 0; |
| 1011 |
} |
| 1012 |
|
| 1013 |
static int snd_es18xx_put_spatializer_enable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 1014 |
{ |
| 1015 |
struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
| 1016 |
unsigned char oval, nval; |
| 1017 |
int change; |
| 1018 |
nval = ucontrol->value.integer.value[0] ? 0x0c : 0x04; |
| 1019 |
oval = snd_es18xx_mixer_read(chip, 0x50) & 0x0c; |
| 1020 |
change = nval != oval; |
| 1021 |
if (change) { |
| 1022 |
snd_es18xx_mixer_write(chip, 0x50, nval & ~0x04); |
| 1023 |
snd_es18xx_mixer_write(chip, 0x50, nval); |
| 1024 |
} |
| 1025 |
return change; |
| 1026 |
} |
| 1027 |
|
| 1028 |
static int snd_es18xx_info_hw_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
| 1029 |
{ |
| 1030 |
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1031 |
uinfo->count = 2; |
| 1032 |
uinfo->value.integer.min = 0; |
| 1033 |
uinfo->value.integer.max = 63; |
| 1034 |
return 0; |
| 1035 |
} |
| 1036 |
|
| 1037 |
static int snd_es18xx_get_hw_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 1038 |
{ |
| 1039 |
struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
| 1040 |
ucontrol->value.integer.value[0] = snd_es18xx_mixer_read(chip, 0x61) & 0x3f; |
| 1041 |
ucontrol->value.integer.value[1] = snd_es18xx_mixer_read(chip, 0x63) & 0x3f; |
| 1042 |
return 0; |
| 1043 |
} |
| 1044 |
|
| 1045 |
#define snd_es18xx_info_hw_switch snd_ctl_boolean_stereo_info |
| 1046 |
|
| 1047 |
static int snd_es18xx_get_hw_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 1048 |
{ |
| 1049 |
struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
| 1050 |
ucontrol->value.integer.value[0] = !(snd_es18xx_mixer_read(chip, 0x61) & 0x40); |
| 1051 |
ucontrol->value.integer.value[1] = !(snd_es18xx_mixer_read(chip, 0x63) & 0x40); |
| 1052 |
return 0; |
| 1053 |
} |
| 1054 |
|
| 1055 |
static void snd_es18xx_hwv_free(struct snd_kcontrol *kcontrol) |
| 1056 |
{ |
| 1057 |
struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
| 1058 |
chip->master_volume = NULL; |
| 1059 |
chip->master_switch = NULL; |
| 1060 |
chip->hw_volume = NULL; |
| 1061 |
chip->hw_switch = NULL; |
| 1062 |
} |
| 1063 |
|
| 1064 |
static int snd_es18xx_reg_bits(struct snd_es18xx *chip, unsigned char reg, |
| 1065 |
unsigned char mask, unsigned char val) |
| 1066 |
{ |
| 1067 |
if (reg < 0xa0) |
| 1068 |
return snd_es18xx_mixer_bits(chip, reg, mask, val); |
| 1069 |
else |
| 1070 |
return snd_es18xx_bits(chip, reg, mask, val); |
| 1071 |
} |
| 1072 |
|
| 1073 |
static int snd_es18xx_reg_read(struct snd_es18xx *chip, unsigned char reg) |
| 1074 |
{ |
| 1075 |
if (reg < 0xa0) |
| 1076 |
return snd_es18xx_mixer_read(chip, reg); |
| 1077 |
else |
| 1078 |
return snd_es18xx_read(chip, reg); |
| 1079 |
} |
| 1080 |
|
| 1081 |
#define ES18XX_SINGLE(xname, xindex, reg, shift, mask, flags) \ |
| 1082 |
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 1083 |
.info = snd_es18xx_info_single, \ |
| 1084 |
.get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \ |
| 1085 |
.private_value = reg | (shift << 8) | (mask << 16) | (flags << 24) } |
| 1086 |
|
| 1087 |
#define ES18XX_FL_INVERT (1 << 0) |
| 1088 |
#define ES18XX_FL_PMPORT (1 << 1) |
| 1089 |
|
| 1090 |
static int snd_es18xx_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
| 1091 |
{ |
| 1092 |
int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1093 |
|
| 1094 |
uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1095 |
uinfo->count = 1; |
| 1096 |
uinfo->value.integer.min = 0; |
| 1097 |
uinfo->value.integer.max = mask; |
| 1098 |
return 0; |
| 1099 |
} |
| 1100 |
|
| 1101 |
static int snd_es18xx_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 1102 |
{ |
| 1103 |
struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
| 1104 |
int reg = kcontrol->private_value & 0xff; |
| 1105 |
int shift = (kcontrol->private_value >> 8) & 0xff; |
| 1106 |
int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1107 |
int invert = (kcontrol->private_value >> 24) & ES18XX_FL_INVERT; |
| 1108 |
int pm_port = (kcontrol->private_value >> 24) & ES18XX_FL_PMPORT; |
| 1109 |
int val; |
| 1110 |
|
| 1111 |
if (pm_port) |
| 1112 |
val = inb(chip->port + ES18XX_PM); |
| 1113 |
else |
| 1114 |
val = snd_es18xx_reg_read(chip, reg); |
| 1115 |
ucontrol->value.integer.value[0] = (val >> shift) & mask; |
| 1116 |
if (invert) |
| 1117 |
ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 1118 |
return 0; |
| 1119 |
} |
| 1120 |
|
| 1121 |
static int snd_es18xx_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 1122 |
{ |
| 1123 |
struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
| 1124 |
int reg = kcontrol->private_value & 0xff; |
| 1125 |
int shift = (kcontrol->private_value >> 8) & 0xff; |
| 1126 |
int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1127 |
int invert = (kcontrol->private_value >> 24) & ES18XX_FL_INVERT; |
| 1128 |
int pm_port = (kcontrol->private_value >> 24) & ES18XX_FL_PMPORT; |
| 1129 |
unsigned char val; |
| 1130 |
|
| 1131 |
val = (ucontrol->value.integer.value[0] & mask); |
| 1132 |
if (invert) |
| 1133 |
val = mask - val; |
| 1134 |
mask <<= shift; |
| 1135 |
val <<= shift; |
| 1136 |
if (pm_port) { |
| 1137 |
unsigned char cur = inb(chip->port + ES18XX_PM); |
| 1138 |
|
| 1139 |
if ((cur & mask) == val) |
| 1140 |
return 0; |
| 1141 |
outb((cur & ~mask) | val, chip->port + ES18XX_PM); |
| 1142 |
return 1; |
| 1143 |
} |
| 1144 |
|
| 1145 |
return snd_es18xx_reg_bits(chip, reg, mask, val) != val; |
| 1146 |
} |
| 1147 |
|
| 1148 |
#define ES18XX_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ |
| 1149 |
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 1150 |
.info = snd_es18xx_info_double, \ |
| 1151 |
.get = snd_es18xx_get_double, .put = snd_es18xx_put_double, \ |
| 1152 |
.private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } |
| 1153 |
|
| 1154 |
static int snd_es18xx_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
| 1155 |
{ |
| 1156 |
int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1157 |
|
| 1158 |
uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1159 |
uinfo->count = 2; |
| 1160 |
uinfo->value.integer.min = 0; |
| 1161 |
uinfo->value.integer.max = mask; |
| 1162 |
return 0; |
| 1163 |
} |
| 1164 |
|
| 1165 |
static int snd_es18xx_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 1166 |
{ |
| 1167 |
struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
| 1168 |
int left_reg = kcontrol->private_value & 0xff; |
| 1169 |
int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 1170 |
int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 1171 |
int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 1172 |
int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1173 |
int invert = (kcontrol->private_value >> 22) & 1; |
| 1174 |
unsigned char left, right; |
| 1175 |
|
| 1176 |
left = snd_es18xx_reg_read(chip, left_reg); |
| 1177 |
if (left_reg != right_reg) |
| 1178 |
right = snd_es18xx_reg_read(chip, right_reg); |
| 1179 |
else |
| 1180 |
right = left; |
| 1181 |
ucontrol->value.integer.value[0] = (left >> shift_left) & mask; |
| 1182 |
ucontrol->value.integer.value[1] = (right >> shift_right) & mask; |
| 1183 |
if (invert) { |
| 1184 |
ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 1185 |
ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; |
| 1186 |
} |
| 1187 |
return 0; |
| 1188 |
} |
| 1189 |
|
| 1190 |
static int snd_es18xx_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 1191 |
{ |
| 1192 |
struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
| 1193 |
int left_reg = kcontrol->private_value & 0xff; |
| 1194 |
int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 1195 |
int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 1196 |
int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 1197 |
int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1198 |
int invert = (kcontrol->private_value >> 22) & 1; |
| 1199 |
int change; |
| 1200 |
unsigned char val1, val2, mask1, mask2; |
| 1201 |
|
| 1202 |
val1 = ucontrol->value.integer.value[0] & mask; |
| 1203 |
val2 = ucontrol->value.integer.value[1] & mask; |
| 1204 |
if (invert) { |
| 1205 |
val1 = mask - val1; |
| 1206 |
val2 = mask - val2; |
| 1207 |
} |
| 1208 |
val1 <<= shift_left; |
| 1209 |
val2 <<= shift_right; |
| 1210 |
mask1 = mask << shift_left; |
| 1211 |
mask2 = mask << shift_right; |
| 1212 |
if (left_reg != right_reg) { |
| 1213 |
change = 0; |
| 1214 |
if (snd_es18xx_reg_bits(chip, left_reg, mask1, val1) != val1) |
| 1215 |
change = 1; |
| 1216 |
if (snd_es18xx_reg_bits(chip, right_reg, mask2, val2) != val2) |
| 1217 |
change = 1; |
| 1218 |
} else { |
| 1219 |
change = (snd_es18xx_reg_bits(chip, left_reg, mask1 | mask2, |
| 1220 |
val1 | val2) != (val1 | val2)); |
| 1221 |
} |
| 1222 |
return change; |
| 1223 |
} |
| 1224 |
|
| 1225 |
/* Mixer controls |
| 1226 |
* These arrays contain setup data for mixer controls. |
| 1227 |
* |
| 1228 |
* The controls that are universal to all chipsets are fully initialized |
| 1229 |
* here. |
| 1230 |
*/ |
| 1231 |
static const struct snd_kcontrol_new snd_es18xx_base_controls[] = { |
| 1232 |
ES18XX_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0), |
| 1233 |
ES18XX_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1), |
| 1234 |
ES18XX_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0), |
| 1235 |
ES18XX_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0), |
| 1236 |
ES18XX_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0), |
| 1237 |
ES18XX_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0), |
| 1238 |
ES18XX_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0), |
| 1239 |
ES18XX_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0), |
| 1240 |
ES18XX_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0), |
| 1241 |
{ |
| 1242 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1243 |
.name = "Capture Source", |
| 1244 |
.info = snd_es18xx_info_mux, |
| 1245 |
.get = snd_es18xx_get_mux, |
| 1246 |
.put = snd_es18xx_put_mux, |
| 1247 |
} |
| 1248 |
}; |
| 1249 |
|
| 1250 |
static const struct snd_kcontrol_new snd_es18xx_recmix_controls[] = { |
| 1251 |
ES18XX_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0), |
| 1252 |
ES18XX_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0), |
| 1253 |
ES18XX_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0), |
| 1254 |
ES18XX_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0), |
| 1255 |
ES18XX_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0), |
| 1256 |
ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0) |
| 1257 |
}; |
| 1258 |
|
| 1259 |
/* |
| 1260 |
* The chipset specific mixer controls |
| 1261 |
*/ |
| 1262 |
static const struct snd_kcontrol_new snd_es18xx_opt_speaker = |
| 1263 |
ES18XX_SINGLE("Beep Playback Volume", 0, 0x3c, 0, 7, 0); |
| 1264 |
|
| 1265 |
static const struct snd_kcontrol_new snd_es18xx_opt_1869[] = { |
| 1266 |
ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, ES18XX_FL_INVERT), |
| 1267 |
ES18XX_SINGLE("Video Playback Switch", 0, 0x7f, 0, 1, 0), |
| 1268 |
ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0), |
| 1269 |
ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0) |
| 1270 |
}; |
| 1271 |
|
| 1272 |
static const struct snd_kcontrol_new snd_es18xx_opt_1878 = |
| 1273 |
ES18XX_DOUBLE("Video Playback Volume", 0, 0x68, 0x68, 4, 0, 15, 0); |
| 1274 |
|
| 1275 |
static const struct snd_kcontrol_new snd_es18xx_opt_1879[] = { |
| 1276 |
ES18XX_SINGLE("Video Playback Switch", 0, 0x71, 6, 1, 0), |
| 1277 |
ES18XX_DOUBLE("Video Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0), |
| 1278 |
ES18XX_DOUBLE("Video Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0) |
| 1279 |
}; |
| 1280 |
|
| 1281 |
static const struct snd_kcontrol_new snd_es18xx_pcm1_controls[] = { |
| 1282 |
ES18XX_DOUBLE("PCM Playback Volume", 0, 0x14, 0x14, 4, 0, 15, 0), |
| 1283 |
}; |
| 1284 |
|
| 1285 |
static const struct snd_kcontrol_new snd_es18xx_pcm2_controls[] = { |
| 1286 |
ES18XX_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0), |
| 1287 |
ES18XX_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0) |
| 1288 |
}; |
| 1289 |
|
| 1290 |
static const struct snd_kcontrol_new snd_es18xx_spatializer_controls[] = { |
| 1291 |
ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0), |
| 1292 |
{ |
| 1293 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1294 |
.name = "3D Control - Switch", |
| 1295 |
.info = snd_es18xx_info_spatializer_enable, |
| 1296 |
.get = snd_es18xx_get_spatializer_enable, |
| 1297 |
.put = snd_es18xx_put_spatializer_enable, |
| 1298 |
} |
| 1299 |
}; |
| 1300 |
|
| 1301 |
static const struct snd_kcontrol_new snd_es18xx_micpre1_control = |
| 1302 |
ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0xa9, 2, 1, 0); |
| 1303 |
|
| 1304 |
static const struct snd_kcontrol_new snd_es18xx_micpre2_control = |
| 1305 |
ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0); |
| 1306 |
|
| 1307 |
static const struct snd_kcontrol_new snd_es18xx_hw_volume_controls[] = { |
| 1308 |
{ |
| 1309 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1310 |
.name = "Hardware Master Playback Volume", |
| 1311 |
.access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1312 |
.info = snd_es18xx_info_hw_volume, |
| 1313 |
.get = snd_es18xx_get_hw_volume, |
| 1314 |
}, |
| 1315 |
{ |
| 1316 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1317 |
.name = "Hardware Master Playback Switch", |
| 1318 |
.access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1319 |
.info = snd_es18xx_info_hw_switch, |
| 1320 |
.get = snd_es18xx_get_hw_switch, |
| 1321 |
}, |
| 1322 |
ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0), |
| 1323 |
}; |
| 1324 |
|
| 1325 |
static const struct snd_kcontrol_new snd_es18xx_opt_gpo_2bit[] = { |
| 1326 |
ES18XX_SINGLE("GPO0 Switch", 0, ES18XX_PM, 0, 1, ES18XX_FL_PMPORT), |
| 1327 |
ES18XX_SINGLE("GPO1 Switch", 0, ES18XX_PM, 1, 1, ES18XX_FL_PMPORT), |
| 1328 |
}; |
| 1329 |
|
| 1330 |
static int snd_es18xx_config_read(struct snd_es18xx *chip, unsigned char reg) |
| 1331 |
{ |
| 1332 |
outb(reg, chip->ctrl_port); |
| 1333 |
return inb(chip->ctrl_port + 1); |
| 1334 |
} |
| 1335 |
|
| 1336 |
static void snd_es18xx_config_write(struct snd_es18xx *chip, |
| 1337 |
unsigned char reg, unsigned char data) |
| 1338 |
{ |
| 1339 |
/* No need for spinlocks, this function is used only in |
| 1340 |
otherwise protected init code */ |
| 1341 |
outb(reg, chip->ctrl_port); |
| 1342 |
outb(data, chip->ctrl_port + 1); |
| 1343 |
#ifdef REG_DEBUG |
| 1344 |
dev_dbg(chip->card->dev, "Config reg %02x set to %02x\n", reg, data); |
| 1345 |
#endif |
| 1346 |
} |
| 1347 |
|
| 1348 |
static int snd_es18xx_initialize(struct snd_es18xx *chip, |
| 1349 |
unsigned long mpu_port, |
| 1350 |
unsigned long fm_port) |
| 1351 |
{ |
| 1352 |
int mask = 0; |
| 1353 |
|
| 1354 |
/* enable extended mode */ |
| 1355 |
snd_es18xx_dsp_command(chip, 0xC6); |
| 1356 |
/* Reset mixer registers */ |
| 1357 |
snd_es18xx_mixer_write(chip, 0x00, 0x00); |
| 1358 |
|
| 1359 |
/* Audio 1 DMA demand mode (4 bytes/request) */ |
| 1360 |
snd_es18xx_write(chip, 0xB9, 2); |
| 1361 |
if (chip->caps & ES18XX_CONTROL) { |
| 1362 |
/* Hardware volume IRQ */ |
| 1363 |
snd_es18xx_config_write(chip, 0x27, chip->irq); |
| 1364 |
if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) { |
| 1365 |
/* FM I/O */ |
| 1366 |
snd_es18xx_config_write(chip, 0x62, fm_port >> 8); |
| 1367 |
snd_es18xx_config_write(chip, 0x63, fm_port & 0xff); |
| 1368 |
} |
| 1369 |
if (mpu_port > 0 && mpu_port != SNDRV_AUTO_PORT) { |
| 1370 |
/* MPU-401 I/O */ |
| 1371 |
snd_es18xx_config_write(chip, 0x64, mpu_port >> 8); |
| 1372 |
snd_es18xx_config_write(chip, 0x65, mpu_port & 0xff); |
| 1373 |
/* MPU-401 IRQ */ |
| 1374 |
snd_es18xx_config_write(chip, 0x28, chip->irq); |
| 1375 |
} |
| 1376 |
/* Audio1 IRQ */ |
| 1377 |
snd_es18xx_config_write(chip, 0x70, chip->irq); |
| 1378 |
/* Audio2 IRQ */ |
| 1379 |
snd_es18xx_config_write(chip, 0x72, chip->irq); |
| 1380 |
/* Audio1 DMA */ |
| 1381 |
snd_es18xx_config_write(chip, 0x74, chip->dma1); |
| 1382 |
/* Audio2 DMA */ |
| 1383 |
snd_es18xx_config_write(chip, 0x75, chip->dma2); |
| 1384 |
|
| 1385 |
/* Enable Audio 1 IRQ */ |
| 1386 |
snd_es18xx_write(chip, 0xB1, 0x50); |
| 1387 |
/* Enable Audio 2 IRQ */ |
| 1388 |
snd_es18xx_mixer_write(chip, 0x7A, 0x40); |
| 1389 |
/* Enable Audio 1 DMA */ |
| 1390 |
snd_es18xx_write(chip, 0xB2, 0x50); |
| 1391 |
/* Enable MPU and hardware volume interrupt */ |
| 1392 |
snd_es18xx_mixer_write(chip, 0x64, 0x42); |
| 1393 |
/* Enable ESS wavetable input */ |
| 1394 |
snd_es18xx_mixer_bits(chip, 0x48, 0x10, 0x10); |
| 1395 |
} |
| 1396 |
else { |
| 1397 |
int irqmask, dma1mask, dma2mask; |
| 1398 |
switch (chip->irq) { |
| 1399 |
case 2: |
| 1400 |
case 9: |
| 1401 |
irqmask = 0; |
| 1402 |
break; |
| 1403 |
case 5: |
| 1404 |
irqmask = 1; |
| 1405 |
break; |
| 1406 |
case 7: |
| 1407 |
irqmask = 2; |
| 1408 |
break; |
| 1409 |
case 10: |
| 1410 |
irqmask = 3; |
| 1411 |
break; |
| 1412 |
default: |
| 1413 |
dev_err(chip->card->dev, "invalid irq %d\n", chip->irq); |
| 1414 |
return -ENODEV; |
| 1415 |
} |
| 1416 |
switch (chip->dma1) { |
| 1417 |
case 0: |
| 1418 |
dma1mask = 1; |
| 1419 |
break; |
| 1420 |
case 1: |
| 1421 |
dma1mask = 2; |
| 1422 |
break; |
| 1423 |
case 3: |
| 1424 |
dma1mask = 3; |
| 1425 |
break; |
| 1426 |
default: |
| 1427 |
dev_err(chip->card->dev, "invalid dma1 %d\n", chip->dma1); |
| 1428 |
return -ENODEV; |
| 1429 |
} |
| 1430 |
switch (chip->dma2) { |
| 1431 |
case 0: |
| 1432 |
dma2mask = 0; |
| 1433 |
break; |
| 1434 |
case 1: |
| 1435 |
dma2mask = 1; |
| 1436 |
break; |
| 1437 |
case 3: |
| 1438 |
dma2mask = 2; |
| 1439 |
break; |
| 1440 |
case 5: |
| 1441 |
dma2mask = 3; |
| 1442 |
break; |
| 1443 |
default: |
| 1444 |
dev_err(chip->card->dev, "invalid dma2 %d\n", chip->dma2); |
| 1445 |
return -ENODEV; |
| 1446 |
} |
| 1447 |
|
| 1448 |
/* Enable and set Audio 1 IRQ */ |
| 1449 |
snd_es18xx_write(chip, 0xB1, 0x50 | (irqmask << 2)); |
| 1450 |
/* Enable and set Audio 1 DMA */ |
| 1451 |
snd_es18xx_write(chip, 0xB2, 0x50 | (dma1mask << 2)); |
| 1452 |
/* Set Audio 2 DMA */ |
| 1453 |
snd_es18xx_mixer_bits(chip, 0x7d, 0x07, 0x04 | dma2mask); |
| 1454 |
/* Enable Audio 2 IRQ and DMA |
| 1455 |
Set capture mixer input */ |
| 1456 |
snd_es18xx_mixer_write(chip, 0x7A, 0x68); |
| 1457 |
/* Enable and set hardware volume interrupt */ |
| 1458 |
snd_es18xx_mixer_write(chip, 0x64, 0x06); |
| 1459 |
if (mpu_port > 0 && mpu_port != SNDRV_AUTO_PORT) { |
| 1460 |
/* MPU401 share irq with audio |
| 1461 |
Joystick enabled |
| 1462 |
FM enabled */ |
| 1463 |
snd_es18xx_mixer_write(chip, 0x40, |
| 1464 |
0x43 | (mpu_port & 0xf0) >> 1); |
| 1465 |
} |
| 1466 |
snd_es18xx_mixer_write(chip, 0x7f, ((irqmask + 1) << 1) | 0x01); |
| 1467 |
} |
| 1468 |
if (chip->caps & ES18XX_NEW_RATE) { |
| 1469 |
/* Change behaviour of register A1 |
| 1470 |
4x oversampling |
| 1471 |
2nd channel DAC asynchronous */ |
| 1472 |
snd_es18xx_mixer_write(chip, 0x71, 0x32); |
| 1473 |
} |
| 1474 |
if (!(chip->caps & ES18XX_PCM2)) { |
| 1475 |
/* Enable DMA FIFO */ |
| 1476 |
snd_es18xx_write(chip, 0xB7, 0x80); |
| 1477 |
} |
| 1478 |
if (chip->caps & ES18XX_SPATIALIZER) { |
| 1479 |
/* Set spatializer parameters to recommended values */ |
| 1480 |
snd_es18xx_mixer_write(chip, 0x54, 0x8f); |
| 1481 |
snd_es18xx_mixer_write(chip, 0x56, 0x95); |
| 1482 |
snd_es18xx_mixer_write(chip, 0x58, 0x94); |
| 1483 |
snd_es18xx_mixer_write(chip, 0x5a, 0x80); |
| 1484 |
} |
| 1485 |
/* Flip the "enable I2S" bits for those chipsets that need it */ |
| 1486 |
switch (chip->version) { |
| 1487 |
case 0x1879: |
| 1488 |
//Leaving I2S enabled on the 1879 screws up the PCM playback (rate effected somehow) |
| 1489 |
//so a Switch control has been added to toggle this 0x71 bit on/off: |
| 1490 |
//snd_es18xx_mixer_bits(chip, 0x71, 0x40, 0x40); |
| 1491 |
/* Note: we fall through on purpose here. */ |
| 1492 |
case 0x1878: |
| 1493 |
snd_es18xx_config_write(chip, 0x29, snd_es18xx_config_read(chip, 0x29) | 0x40); |
| 1494 |
break; |
| 1495 |
} |
| 1496 |
/* Mute input source */ |
| 1497 |
if (chip->caps & ES18XX_MUTEREC) |
| 1498 |
mask = 0x10; |
| 1499 |
if (chip->caps & ES18XX_RECMIX) |
| 1500 |
snd_es18xx_mixer_write(chip, 0x1c, 0x05 | mask); |
| 1501 |
else { |
| 1502 |
snd_es18xx_mixer_write(chip, 0x1c, 0x00 | mask); |
| 1503 |
snd_es18xx_write(chip, 0xb4, 0x00); |
| 1504 |
} |
| 1505 |
#ifndef AVOID_POPS |
| 1506 |
/* Enable PCM output */ |
| 1507 |
snd_es18xx_dsp_command(chip, 0xD1); |
| 1508 |
#endif |
| 1509 |
|
| 1510 |
return 0; |
| 1511 |
} |
| 1512 |
|
| 1513 |
static int snd_es18xx_identify(struct snd_card *card, struct snd_es18xx *chip) |
| 1514 |
{ |
| 1515 |
int hi,lo; |
| 1516 |
|
| 1517 |
/* reset */ |
| 1518 |
if (snd_es18xx_reset(chip) < 0) { |
| 1519 |
dev_err(card->dev, "reset at 0x%lx failed!!!\n", chip->port); |
| 1520 |
return -ENODEV; |
| 1521 |
} |
| 1522 |
|
| 1523 |
snd_es18xx_dsp_command(chip, 0xe7); |
| 1524 |
hi = snd_es18xx_dsp_get_byte(chip); |
| 1525 |
if (hi < 0) { |
| 1526 |
return hi; |
| 1527 |
} |
| 1528 |
lo = snd_es18xx_dsp_get_byte(chip); |
| 1529 |
if ((lo & 0xf0) != 0x80) { |
| 1530 |
return -ENODEV; |
| 1531 |
} |
| 1532 |
if (hi == 0x48) { |
| 1533 |
chip->version = 0x488; |
| 1534 |
return 0; |
| 1535 |
} |
| 1536 |
if (hi != 0x68) { |
| 1537 |
return -ENODEV; |
| 1538 |
} |
| 1539 |
if ((lo & 0x0f) < 8) { |
| 1540 |
chip->version = 0x688; |
| 1541 |
return 0; |
| 1542 |
} |
| 1543 |
|
| 1544 |
outb(0x40, chip->port + 0x04); |
| 1545 |
udelay(10); |
| 1546 |
hi = inb(chip->port + 0x05); |
| 1547 |
udelay(10); |
| 1548 |
lo = inb(chip->port + 0x05); |
| 1549 |
if (hi != lo) { |
| 1550 |
chip->version = hi << 8 | lo; |
| 1551 |
chip->ctrl_port = inb(chip->port + 0x05) << 8; |
| 1552 |
udelay(10); |
| 1553 |
chip->ctrl_port += inb(chip->port + 0x05); |
| 1554 |
|
| 1555 |
if (!devm_request_region(card->dev, chip->ctrl_port, 8, |
| 1556 |
"ES18xx - CTRL")) { |
| 1557 |
dev_err(card->dev, "unable go grab port 0x%lx\n", chip->ctrl_port); |
| 1558 |
return -EBUSY; |
| 1559 |
} |
| 1560 |
|
| 1561 |
return 0; |
| 1562 |
} |
| 1563 |
|
| 1564 |
/* If has Hardware volume */ |
| 1565 |
if (snd_es18xx_mixer_writable(chip, 0x64, 0x04)) { |
| 1566 |
/* If has Audio2 */ |
| 1567 |
if (snd_es18xx_mixer_writable(chip, 0x70, 0x7f)) { |
| 1568 |
/* If has volume count */ |
| 1569 |
if (snd_es18xx_mixer_writable(chip, 0x64, 0x20)) { |
| 1570 |
chip->version = 0x1887; |
| 1571 |
} else { |
| 1572 |
chip->version = 0x1888; |
| 1573 |
} |
| 1574 |
} else { |
| 1575 |
chip->version = 0x1788; |
| 1576 |
} |
| 1577 |
} |
| 1578 |
else |
| 1579 |
chip->version = 0x1688; |
| 1580 |
return 0; |
| 1581 |
} |
| 1582 |
|
| 1583 |
static int snd_es18xx_probe(struct snd_card *card, |
| 1584 |
struct snd_es18xx *chip, |
| 1585 |
unsigned long mpu_port, |
| 1586 |
unsigned long fm_port) |
| 1587 |
{ |
| 1588 |
if (snd_es18xx_identify(card, chip) < 0) { |
| 1589 |
dev_err(card->dev, "[0x%lx] ESS chip not found\n", chip->port); |
| 1590 |
return -ENODEV; |
| 1591 |
} |
| 1592 |
|
| 1593 |
switch (chip->version) { |
| 1594 |
case 0x1868: |
| 1595 |
chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_CONTROL | ES18XX_GPO_2BIT; |
| 1596 |
break; |
| 1597 |
case 0x1869: |
| 1598 |
chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_MONO | ES18XX_MUTEREC | ES18XX_CONTROL | ES18XX_HWV | ES18XX_GPO_2BIT; |
| 1599 |
break; |
| 1600 |
case 0x1878: |
| 1601 |
chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_I2S | ES18XX_CONTROL; |
| 1602 |
break; |
| 1603 |
case 0x1879: |
| 1604 |
chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV; |
| 1605 |
break; |
| 1606 |
case 0x1887: |
| 1607 |
case 0x1888: |
| 1608 |
chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME | ES18XX_GPO_2BIT; |
| 1609 |
break; |
| 1610 |
default: |
| 1611 |
dev_err(card->dev, "[0x%lx] unsupported chip ES%x\n", |
| 1612 |
chip->port, chip->version); |
| 1613 |
return -ENODEV; |
| 1614 |
} |
| 1615 |
|
| 1616 |
dev_dbg(card->dev, "[0x%lx] ESS%x chip found\n", chip->port, chip->version); |
| 1617 |
|
| 1618 |
if (chip->dma1 == chip->dma2) |
| 1619 |
chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME); |
| 1620 |
|
| 1621 |
return snd_es18xx_initialize(chip, mpu_port, fm_port); |
| 1622 |
} |
| 1623 |
|
| 1624 |
static const struct snd_pcm_ops snd_es18xx_playback_ops = { |
| 1625 |
.open = snd_es18xx_playback_open, |
| 1626 |
.close = snd_es18xx_playback_close, |
| 1627 |
.hw_params = snd_es18xx_playback_hw_params, |
| 1628 |
.prepare = snd_es18xx_playback_prepare, |
| 1629 |
.trigger = snd_es18xx_playback_trigger, |
| 1630 |
.pointer = snd_es18xx_playback_pointer, |
| 1631 |
}; |
| 1632 |
|
| 1633 |
static const struct snd_pcm_ops snd_es18xx_capture_ops = { |
| 1634 |
.open = snd_es18xx_capture_open, |
| 1635 |
.close = snd_es18xx_capture_close, |
| 1636 |
.hw_params = snd_es18xx_capture_hw_params, |
| 1637 |
.prepare = snd_es18xx_capture_prepare, |
| 1638 |
.trigger = snd_es18xx_capture_trigger, |
| 1639 |
.pointer = snd_es18xx_capture_pointer, |
| 1640 |
}; |
| 1641 |
|
| 1642 |
static int snd_es18xx_pcm(struct snd_card *card, int device) |
| 1643 |
{ |
| 1644 |
struct snd_es18xx *chip = card->private_data; |
| 1645 |
struct snd_pcm *pcm; |
| 1646 |
char str[16]; |
| 1647 |
int err; |
| 1648 |
|
| 1649 |
sprintf(str, "ES%x", chip->version); |
| 1650 |
if (chip->caps & ES18XX_PCM2) |
| 1651 |
err = snd_pcm_new(card, str, device, 2, 1, &pcm); |
| 1652 |
else |
| 1653 |
err = snd_pcm_new(card, str, device, 1, 1, &pcm); |
| 1654 |
if (err < 0) |
| 1655 |
return err; |
| 1656 |
|
| 1657 |
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es18xx_playback_ops); |
| 1658 |
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es18xx_capture_ops); |
| 1659 |
|
| 1660 |
/* global setup */ |
| 1661 |
pcm->private_data = chip; |
| 1662 |
pcm->info_flags = 0; |
| 1663 |
if (chip->caps & ES18XX_DUPLEX_SAME) |
| 1664 |
pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 1665 |
if (! (chip->caps & ES18XX_PCM2)) |
| 1666 |
pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX; |
| 1667 |
sprintf(pcm->name, "ESS AudioDrive ES%x", chip->version); |
| 1668 |
chip->pcm = pcm; |
| 1669 |
|
| 1670 |
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, card->dev, |
| 1671 |
64*1024, |
| 1672 |
chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024); |
| 1673 |
return 0; |
| 1674 |
} |
| 1675 |
|
| 1676 |
/* Power Management support functions */ |
| 1677 |
#ifdef CONFIG_PM |
| 1678 |
static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state) |
| 1679 |
{ |
| 1680 |
struct snd_es18xx *chip = card->private_data; |
| 1681 |
|
| 1682 |
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
| 1683 |
|
| 1684 |
/* power down */ |
| 1685 |
chip->pm_reg = (unsigned char)snd_es18xx_read(chip, ES18XX_PM); |
| 1686 |
chip->pm_reg |= (ES18XX_PM_FM | ES18XX_PM_SUS); |
| 1687 |
snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg); |
| 1688 |
snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_SUS); |
| 1689 |
|
| 1690 |
return 0; |
| 1691 |
} |
| 1692 |
|
| 1693 |
static int snd_es18xx_resume(struct snd_card *card) |
| 1694 |
{ |
| 1695 |
struct snd_es18xx *chip = card->private_data; |
| 1696 |
|
| 1697 |
/* restore PM register, we won't wake till (not 0x07) i/o activity though */ |
| 1698 |
snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM); |
| 1699 |
|
| 1700 |
snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
| 1701 |
return 0; |
| 1702 |
} |
| 1703 |
#endif /* CONFIG_PM */ |
| 1704 |
|
| 1705 |
static int snd_es18xx_new_device(struct snd_card *card, |
| 1706 |
unsigned long port, |
| 1707 |
unsigned long mpu_port, |
| 1708 |
unsigned long fm_port, |
| 1709 |
int irq, int dma1, int dma2) |
| 1710 |
{ |
| 1711 |
struct snd_es18xx *chip = card->private_data; |
| 1712 |
|
| 1713 |
chip->card = card; |
| 1714 |
spin_lock_init(&chip->reg_lock); |
| 1715 |
spin_lock_init(&chip->mixer_lock); |
| 1716 |
chip->port = port; |
| 1717 |
chip->irq = -1; |
| 1718 |
chip->dma1 = -1; |
| 1719 |
chip->dma2 = -1; |
| 1720 |
chip->audio2_vol = 0x00; |
| 1721 |
chip->active = 0; |
| 1722 |
|
| 1723 |
if (!devm_request_region(card->dev, port, 16, "ES18xx")) { |
| 1724 |
dev_err(card->dev, "unable to grab ports 0x%lx-0x%lx\n", port, port + 16 - 1); |
| 1725 |
return -EBUSY; |
| 1726 |
} |
| 1727 |
|
| 1728 |
if (devm_request_irq(card->dev, irq, snd_es18xx_interrupt, 0, "ES18xx", |
| 1729 |
(void *) card)) { |
| 1730 |
dev_err(card->dev, "unable to grab IRQ %d\n", irq); |
| 1731 |
return -EBUSY; |
| 1732 |
} |
| 1733 |
chip->irq = irq; |
| 1734 |
card->sync_irq = chip->irq; |
| 1735 |
|
| 1736 |
if (snd_devm_request_dma(card->dev, dma1, "ES18xx DMA 1")) { |
| 1737 |
dev_err(card->dev, "unable to grab DMA1 %d\n", dma1); |
| 1738 |
return -EBUSY; |
| 1739 |
} |
| 1740 |
chip->dma1 = dma1; |
| 1741 |
|
| 1742 |
if (dma2 != dma1 && |
| 1743 |
snd_devm_request_dma(card->dev, dma2, "ES18xx DMA 2")) { |
| 1744 |
dev_err(card->dev, "unable to grab DMA2 %d\n", dma2); |
| 1745 |
return -EBUSY; |
| 1746 |
} |
| 1747 |
chip->dma2 = dma2; |
| 1748 |
|
| 1749 |
if (snd_es18xx_probe(card, chip, mpu_port, fm_port) < 0) |
| 1750 |
return -ENODEV; |
| 1751 |
return 0; |
| 1752 |
} |
| 1753 |
|
| 1754 |
static int snd_es18xx_mixer(struct snd_card *card) |
| 1755 |
{ |
| 1756 |
struct snd_es18xx *chip = card->private_data; |
| 1757 |
int err; |
| 1758 |
unsigned int idx; |
| 1759 |
|
| 1760 |
strscpy(card->mixername, chip->pcm->name); |
| 1761 |
|
| 1762 |
for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) { |
| 1763 |
struct snd_kcontrol *kctl; |
| 1764 |
kctl = snd_ctl_new1(&snd_es18xx_base_controls[idx], chip); |
| 1765 |
if (chip->caps & ES18XX_HWV) { |
| 1766 |
switch (idx) { |
| 1767 |
case 0: |
| 1768 |
chip->master_volume = kctl; |
| 1769 |
kctl->private_free = snd_es18xx_hwv_free; |
| 1770 |
break; |
| 1771 |
case 1: |
| 1772 |
chip->master_switch = kctl; |
| 1773 |
kctl->private_free = snd_es18xx_hwv_free; |
| 1774 |
break; |
| 1775 |
} |
| 1776 |
} |
| 1777 |
err = snd_ctl_add(card, kctl); |
| 1778 |
if (err < 0) |
| 1779 |
return err; |
| 1780 |
} |
| 1781 |
if (chip->caps & ES18XX_PCM2) { |
| 1782 |
for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_pcm2_controls); idx++) { |
| 1783 |
err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_pcm2_controls[idx], chip)); |
| 1784 |
if (err < 0) |
| 1785 |
return err; |
| 1786 |
} |
| 1787 |
} else { |
| 1788 |
for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_pcm1_controls); idx++) { |
| 1789 |
err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_pcm1_controls[idx], chip)); |
| 1790 |
if (err < 0) |
| 1791 |
return err; |
| 1792 |
} |
| 1793 |
} |
| 1794 |
|
| 1795 |
if (chip->caps & ES18XX_RECMIX) { |
| 1796 |
for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_recmix_controls); idx++) { |
| 1797 |
err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_recmix_controls[idx], chip)); |
| 1798 |
if (err < 0) |
| 1799 |
return err; |
| 1800 |
} |
| 1801 |
} |
| 1802 |
switch (chip->version) { |
| 1803 |
default: |
| 1804 |
err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_micpre1_control, chip)); |
| 1805 |
if (err < 0) |
| 1806 |
return err; |
| 1807 |
break; |
| 1808 |
case 0x1869: |
| 1809 |
case 0x1879: |
| 1810 |
err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_micpre2_control, chip)); |
| 1811 |
if (err < 0) |
| 1812 |
return err; |
| 1813 |
break; |
| 1814 |
} |
| 1815 |
if (chip->caps & ES18XX_SPATIALIZER) { |
| 1816 |
for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_spatializer_controls); idx++) { |
| 1817 |
err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_spatializer_controls[idx], chip)); |
| 1818 |
if (err < 0) |
| 1819 |
return err; |
| 1820 |
} |
| 1821 |
} |
| 1822 |
if (chip->caps & ES18XX_HWV) { |
| 1823 |
for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_hw_volume_controls); idx++) { |
| 1824 |
struct snd_kcontrol *kctl; |
| 1825 |
kctl = snd_ctl_new1(&snd_es18xx_hw_volume_controls[idx], chip); |
| 1826 |
if (idx == 0) |
| 1827 |
chip->hw_volume = kctl; |
| 1828 |
else |
| 1829 |
chip->hw_switch = kctl; |
| 1830 |
kctl->private_free = snd_es18xx_hwv_free; |
| 1831 |
err = snd_ctl_add(card, kctl); |
| 1832 |
if (err < 0) |
| 1833 |
return err; |
| 1834 |
|
| 1835 |
} |
| 1836 |
} |
| 1837 |
/* finish initializing other chipset specific controls |
| 1838 |
*/ |
| 1839 |
if (chip->version != 0x1868) { |
| 1840 |
err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_opt_speaker, |
| 1841 |
chip)); |
| 1842 |
if (err < 0) |
| 1843 |
return err; |
| 1844 |
} |
| 1845 |
if (chip->version == 0x1869) { |
| 1846 |
for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_opt_1869); idx++) { |
| 1847 |
err = snd_ctl_add(card, |
| 1848 |
snd_ctl_new1(&snd_es18xx_opt_1869[idx], |
| 1849 |
chip)); |
| 1850 |
if (err < 0) |
| 1851 |
return err; |
| 1852 |
} |
| 1853 |
} else if (chip->version == 0x1878) { |
| 1854 |
err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_opt_1878, |
| 1855 |
chip)); |
| 1856 |
if (err < 0) |
| 1857 |
return err; |
| 1858 |
} else if (chip->version == 0x1879) { |
| 1859 |
for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_opt_1879); idx++) { |
| 1860 |
err = snd_ctl_add(card, |
| 1861 |
snd_ctl_new1(&snd_es18xx_opt_1879[idx], |
| 1862 |
chip)); |
| 1863 |
if (err < 0) |
| 1864 |
return err; |
| 1865 |
} |
| 1866 |
} |
| 1867 |
if (chip->caps & ES18XX_GPO_2BIT) { |
| 1868 |
for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_opt_gpo_2bit); idx++) { |
| 1869 |
err = snd_ctl_add(card, |
| 1870 |
snd_ctl_new1(&snd_es18xx_opt_gpo_2bit[idx], |
| 1871 |
chip)); |
| 1872 |
if (err < 0) |
| 1873 |
return err; |
| 1874 |
} |
| 1875 |
} |
| 1876 |
return 0; |
| 1877 |
} |
| 1878 |
|
| 1879 |
|
| 1880 |
/* Card level */ |
| 1881 |
|
| 1882 |
MODULE_AUTHOR("Christian Fischbach <[email protected]>, Abramo Bagnara <[email protected]>"); |
| 1883 |
MODULE_DESCRIPTION("ESS ES18xx AudioDrive"); |
| 1884 |
MODULE_LICENSE("GPL"); |
| 1885 |
|
| 1886 |
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 1887 |
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 1888 |
static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ |
| 1889 |
#ifdef CONFIG_PNP |
| 1890 |
static bool isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; |
| 1891 |
#endif |
| 1892 |
static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */ |
| 1893 |
#ifndef CONFIG_PNP |
| 1894 |
static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1}; |
| 1895 |
#else |
| 1896 |
static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; |
| 1897 |
#endif |
| 1898 |
static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; |
| 1899 |
static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ |
| 1900 |
static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */ |
| 1901 |
static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */ |
| 1902 |
|
| 1903 |
module_param_array(index, int, NULL, 0444); |
| 1904 |
MODULE_PARM_DESC(index, "Index value for ES18xx soundcard."); |
| 1905 |
module_param_array(id, charp, NULL, 0444); |
| 1906 |
MODULE_PARM_DESC(id, "ID string for ES18xx soundcard."); |
| 1907 |
module_param_array(enable, bool, NULL, 0444); |
| 1908 |
MODULE_PARM_DESC(enable, "Enable ES18xx soundcard."); |
| 1909 |
#ifdef CONFIG_PNP |
| 1910 |
module_param_array(isapnp, bool, NULL, 0444); |
| 1911 |
MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard."); |
| 1912 |
#endif |
| 1913 |
module_param_hw_array(port, long, ioport, NULL, 0444); |
| 1914 |
MODULE_PARM_DESC(port, "Port # for ES18xx driver."); |
| 1915 |
module_param_hw_array(mpu_port, long, ioport, NULL, 0444); |
| 1916 |
MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ES18xx driver."); |
| 1917 |
module_param_hw_array(fm_port, long, ioport, NULL, 0444); |
| 1918 |
MODULE_PARM_DESC(fm_port, "FM port # for ES18xx driver."); |
| 1919 |
module_param_hw_array(irq, int, irq, NULL, 0444); |
| 1920 |
MODULE_PARM_DESC(irq, "IRQ # for ES18xx driver."); |
| 1921 |
module_param_hw_array(dma1, int, dma, NULL, 0444); |
| 1922 |
MODULE_PARM_DESC(dma1, "DMA 1 # for ES18xx driver."); |
| 1923 |
module_param_hw_array(dma2, int, dma, NULL, 0444); |
| 1924 |
MODULE_PARM_DESC(dma2, "DMA 2 # for ES18xx driver."); |
| 1925 |
|
| 1926 |
#ifdef CONFIG_PNP |
| 1927 |
static int isa_registered; |
| 1928 |
static int pnp_registered; |
| 1929 |
static int pnpc_registered; |
| 1930 |
|
| 1931 |
static const struct pnp_device_id snd_audiodrive_pnpbiosids[] = { |
| 1932 |
{ .id = "ESS1869" }, |
| 1933 |
{ .id = "ESS1879" }, |
| 1934 |
{ .id = "" } /* end */ |
| 1935 |
}; |
| 1936 |
|
| 1937 |
MODULE_DEVICE_TABLE(pnp, snd_audiodrive_pnpbiosids); |
| 1938 |
|
| 1939 |
/* PnP main device initialization */ |
| 1940 |
static int snd_audiodrive_pnp_init_main(int dev, struct pnp_dev *pdev) |
| 1941 |
{ |
| 1942 |
if (pnp_activate_dev(pdev) < 0) { |
| 1943 |
dev_err(&pdev->dev, "PnP configure failure (out of resources?)\n"); |
| 1944 |
return -EBUSY; |
| 1945 |
} |
| 1946 |
/* ok. hack using Vendor-Defined Card-Level registers */ |
| 1947 |
/* skip csn and logdev initialization - already done in isapnp_configure */ |
| 1948 |
if (pnp_device_is_isapnp(pdev)) { |
| 1949 |
isapnp_cfg_begin(isapnp_card_number(pdev), isapnp_csn_number(pdev)); |
| 1950 |
isapnp_write_byte(0x27, pnp_irq(pdev, 0)); /* Hardware Volume IRQ Number */ |
| 1951 |
if (mpu_port[dev] != SNDRV_AUTO_PORT) |
| 1952 |
isapnp_write_byte(0x28, pnp_irq(pdev, 0)); /* MPU-401 IRQ Number */ |
| 1953 |
isapnp_write_byte(0x72, pnp_irq(pdev, 0)); /* second IRQ */ |
| 1954 |
isapnp_cfg_end(); |
| 1955 |
} |
| 1956 |
port[dev] = pnp_port_start(pdev, 0); |
| 1957 |
fm_port[dev] = pnp_port_start(pdev, 1); |
| 1958 |
mpu_port[dev] = pnp_port_start(pdev, 2); |
| 1959 |
dma1[dev] = pnp_dma(pdev, 0); |
| 1960 |
dma2[dev] = pnp_dma(pdev, 1); |
| 1961 |
irq[dev] = pnp_irq(pdev, 0); |
| 1962 |
dev_dbg(&pdev->dev, |
| 1963 |
"PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", |
| 1964 |
port[dev], fm_port[dev], mpu_port[dev]); |
| 1965 |
dev_dbg(&pdev->dev, |
| 1966 |
"PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", |
| 1967 |
dma1[dev], dma2[dev], irq[dev]); |
| 1968 |
return 0; |
| 1969 |
} |
| 1970 |
|
| 1971 |
static int snd_audiodrive_pnp(int dev, struct snd_es18xx *chip, |
| 1972 |
struct pnp_dev *pdev) |
| 1973 |
{ |
| 1974 |
chip->dev = pdev; |
| 1975 |
if (snd_audiodrive_pnp_init_main(dev, chip->dev) < 0) |
| 1976 |
return -EBUSY; |
| 1977 |
return 0; |
| 1978 |
} |
| 1979 |
|
| 1980 |
static const struct pnp_card_device_id snd_audiodrive_pnpids[] = { |
| 1981 |
/* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */ |
| 1982 |
{ .id = "ESS1868", .devs = { { "ESS1868" }, { "ESS0000" } } }, |
| 1983 |
/* ESS 1868 (integrated on Maxisound Cards) */ |
| 1984 |
{ .id = "ESS1868", .devs = { { "ESS8601" }, { "ESS8600" } } }, |
| 1985 |
/* ESS 1868 (integrated on Maxisound Cards) */ |
| 1986 |
{ .id = "ESS1868", .devs = { { "ESS8611" }, { "ESS8610" } } }, |
| 1987 |
/* ESS ES1869 Plug and Play AudioDrive */ |
| 1988 |
{ .id = "ESS0003", .devs = { { "ESS1869" }, { "ESS0006" } } }, |
| 1989 |
/* ESS 1869 */ |
| 1990 |
{ .id = "ESS1869", .devs = { { "ESS1869" }, { "ESS0006" } } }, |
| 1991 |
/* ESS 1878 */ |
| 1992 |
{ .id = "ESS1878", .devs = { { "ESS1878" }, { "ESS0004" } } }, |
| 1993 |
/* ESS 1879 */ |
| 1994 |
{ .id = "ESS1879", .devs = { { "ESS1879" }, { "ESS0009" } } }, |
| 1995 |
/* --- */ |
| 1996 |
{ .id = "" } /* end */ |
| 1997 |
}; |
| 1998 |
|
| 1999 |
MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids); |
| 2000 |
|
| 2001 |
static int snd_audiodrive_pnpc(int dev, struct snd_es18xx *chip, |
| 2002 |
struct pnp_card_link *card, |
| 2003 |
const struct pnp_card_device_id *id) |
| 2004 |
{ |
| 2005 |
chip->dev = pnp_request_card_device(card, id->devs[0].id, NULL); |
| 2006 |
if (chip->dev == NULL) |
| 2007 |
return -EBUSY; |
| 2008 |
|
| 2009 |
chip->devc = pnp_request_card_device(card, id->devs[1].id, NULL); |
| 2010 |
if (chip->devc == NULL) |
| 2011 |
return -EBUSY; |
| 2012 |
|
| 2013 |
/* Control port initialization */ |
| 2014 |
if (pnp_activate_dev(chip->devc) < 0) { |
| 2015 |
dev_err(chip->card->dev, |
| 2016 |
"PnP control configure failure (out of resources?)\n"); |
| 2017 |
return -EAGAIN; |
| 2018 |
} |
| 2019 |
dev_dbg(chip->card->dev, "pnp: port=0x%llx\n", |
| 2020 |
(unsigned long long)pnp_port_start(chip->devc, 0)); |
| 2021 |
if (snd_audiodrive_pnp_init_main(dev, chip->dev) < 0) |
| 2022 |
return -EBUSY; |
| 2023 |
|
| 2024 |
return 0; |
| 2025 |
} |
| 2026 |
#endif /* CONFIG_PNP */ |
| 2027 |
|
| 2028 |
#ifdef CONFIG_PNP |
| 2029 |
#define is_isapnp_selected(dev) isapnp[dev] |
| 2030 |
#else |
| 2031 |
#define is_isapnp_selected(dev) 0 |
| 2032 |
#endif |
| 2033 |
|
| 2034 |
static int snd_es18xx_card_new(struct device *pdev, int dev, |
| 2035 |
struct snd_card **cardp) |
| 2036 |
{ |
| 2037 |
return snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE, |
| 2038 |
sizeof(struct snd_es18xx), cardp); |
| 2039 |
} |
| 2040 |
|
| 2041 |
static int snd_audiodrive_probe(struct snd_card *card, int dev) |
| 2042 |
{ |
| 2043 |
struct snd_es18xx *chip = card->private_data; |
| 2044 |
struct snd_opl3 *opl3; |
| 2045 |
int err; |
| 2046 |
|
| 2047 |
err = snd_es18xx_new_device(card, |
| 2048 |
port[dev], mpu_port[dev], fm_port[dev], |
| 2049 |
irq[dev], dma1[dev], dma2[dev]); |
| 2050 |
if (err < 0) |
| 2051 |
return err; |
| 2052 |
|
| 2053 |
sprintf(card->driver, "ES%x", chip->version); |
| 2054 |
|
| 2055 |
sprintf(card->shortname, "ESS AudioDrive ES%x", chip->version); |
| 2056 |
if (dma1[dev] != dma2[dev]) |
| 2057 |
sprintf(card->longname, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d", |
| 2058 |
card->shortname, |
| 2059 |
chip->port, |
| 2060 |
irq[dev], dma1[dev], dma2[dev]); |
| 2061 |
else |
| 2062 |
sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", |
| 2063 |
card->shortname, |
| 2064 |
chip->port, |
| 2065 |
irq[dev], dma1[dev]); |
| 2066 |
|
| 2067 |
err = snd_es18xx_pcm(card, 0); |
| 2068 |
if (err < 0) |
| 2069 |
return err; |
| 2070 |
|
| 2071 |
err = snd_es18xx_mixer(card); |
| 2072 |
if (err < 0) |
| 2073 |
return err; |
| 2074 |
|
| 2075 |
if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) { |
| 2076 |
if (snd_opl3_create(card, fm_port[dev], fm_port[dev] + 2, |
| 2077 |
OPL3_HW_OPL3, 0, &opl3) < 0) { |
| 2078 |
dev_warn(card->dev, |
| 2079 |
"opl3 not detected at 0x%lx\n", |
| 2080 |
fm_port[dev]); |
| 2081 |
} else { |
| 2082 |
err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); |
| 2083 |
if (err < 0) |
| 2084 |
return err; |
| 2085 |
} |
| 2086 |
} |
| 2087 |
|
| 2088 |
if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { |
| 2089 |
err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX, |
| 2090 |
mpu_port[dev], MPU401_INFO_IRQ_HOOK, |
| 2091 |
-1, &chip->rmidi); |
| 2092 |
if (err < 0) |
| 2093 |
return err; |
| 2094 |
} |
| 2095 |
|
| 2096 |
return snd_card_register(card); |
| 2097 |
} |
| 2098 |
|
| 2099 |
static int snd_es18xx_isa_match(struct device *pdev, unsigned int dev) |
| 2100 |
{ |
| 2101 |
return enable[dev] && !is_isapnp_selected(dev); |
| 2102 |
} |
| 2103 |
|
| 2104 |
static int snd_es18xx_isa_probe1(int dev, struct device *devptr) |
| 2105 |
{ |
| 2106 |
struct snd_card *card; |
| 2107 |
int err; |
| 2108 |
|
| 2109 |
err = snd_es18xx_card_new(devptr, dev, &card); |
| 2110 |
if (err < 0) |
| 2111 |
return err; |
| 2112 |
err = snd_audiodrive_probe(card, dev); |
| 2113 |
if (err < 0) |
| 2114 |
return err; |
| 2115 |
dev_set_drvdata(devptr, card); |
| 2116 |
return 0; |
| 2117 |
} |
| 2118 |
|
| 2119 |
static int snd_es18xx_isa_probe(struct device *pdev, unsigned int dev) |
| 2120 |
{ |
| 2121 |
int err; |
| 2122 |
static const int possible_irqs[] = {5, 9, 10, 7, 11, 12, -1}; |
| 2123 |
static const int possible_dmas[] = {1, 0, 3, 5, -1}; |
| 2124 |
|
| 2125 |
if (irq[dev] == SNDRV_AUTO_IRQ) { |
| 2126 |
irq[dev] = snd_legacy_find_free_irq(possible_irqs); |
| 2127 |
if (irq[dev] < 0) { |
| 2128 |
dev_err(pdev, "unable to find a free IRQ\n"); |
| 2129 |
return -EBUSY; |
| 2130 |
} |
| 2131 |
} |
| 2132 |
if (dma1[dev] == SNDRV_AUTO_DMA) { |
| 2133 |
dma1[dev] = snd_legacy_find_free_dma(possible_dmas); |
| 2134 |
if (dma1[dev] < 0) { |
| 2135 |
dev_err(pdev, "unable to find a free DMA1\n"); |
| 2136 |
return -EBUSY; |
| 2137 |
} |
| 2138 |
} |
| 2139 |
if (dma2[dev] == SNDRV_AUTO_DMA) { |
| 2140 |
dma2[dev] = snd_legacy_find_free_dma(possible_dmas); |
| 2141 |
if (dma2[dev] < 0) { |
| 2142 |
dev_err(pdev, "unable to find a free DMA2\n"); |
| 2143 |
return -EBUSY; |
| 2144 |
} |
| 2145 |
} |
| 2146 |
|
| 2147 |
if (port[dev] != SNDRV_AUTO_PORT) { |
| 2148 |
return snd_es18xx_isa_probe1(dev, pdev); |
| 2149 |
} else { |
| 2150 |
static const unsigned long possible_ports[] = {0x220, 0x240, 0x260, 0x280}; |
| 2151 |
int i; |
| 2152 |
for (i = 0; i < ARRAY_SIZE(possible_ports); i++) { |
| 2153 |
port[dev] = possible_ports[i]; |
| 2154 |
err = snd_es18xx_isa_probe1(dev, pdev); |
| 2155 |
if (! err) |
| 2156 |
return 0; |
| 2157 |
} |
| 2158 |
return err; |
| 2159 |
} |
| 2160 |
} |
| 2161 |
|
| 2162 |
#ifdef CONFIG_PM |
| 2163 |
static int snd_es18xx_isa_suspend(struct device *dev, unsigned int n, |
| 2164 |
pm_message_t state) |
| 2165 |
{ |
| 2166 |
return snd_es18xx_suspend(dev_get_drvdata(dev), state); |
| 2167 |
} |
| 2168 |
|
| 2169 |
static int snd_es18xx_isa_resume(struct device *dev, unsigned int n) |
| 2170 |
{ |
| 2171 |
return snd_es18xx_resume(dev_get_drvdata(dev)); |
| 2172 |
} |
| 2173 |
#endif |
| 2174 |
|
| 2175 |
#define DEV_NAME "es18xx" |
| 2176 |
|
| 2177 |
static struct isa_driver snd_es18xx_isa_driver = { |
| 2178 |
.match = snd_es18xx_isa_match, |
| 2179 |
.probe = snd_es18xx_isa_probe, |
| 2180 |
#ifdef CONFIG_PM |
| 2181 |
.suspend = snd_es18xx_isa_suspend, |
| 2182 |
.resume = snd_es18xx_isa_resume, |
| 2183 |
#endif |
| 2184 |
.driver = { |
| 2185 |
.name = DEV_NAME |
| 2186 |
}, |
| 2187 |
}; |
| 2188 |
|
| 2189 |
|
| 2190 |
#ifdef CONFIG_PNP |
| 2191 |
static int snd_audiodrive_pnp_detect(struct pnp_dev *pdev, |
| 2192 |
const struct pnp_device_id *id) |
| 2193 |
{ |
| 2194 |
static int dev; |
| 2195 |
int err; |
| 2196 |
struct snd_card *card; |
| 2197 |
|
| 2198 |
if (pnp_device_is_isapnp(pdev)) |
| 2199 |
return -ENOENT; /* we have another procedure - card */ |
| 2200 |
for (; dev < SNDRV_CARDS; dev++) { |
| 2201 |
if (enable[dev] && isapnp[dev]) |
| 2202 |
break; |
| 2203 |
} |
| 2204 |
if (dev >= SNDRV_CARDS) |
| 2205 |
return -ENODEV; |
| 2206 |
|
| 2207 |
err = snd_es18xx_card_new(&pdev->dev, dev, &card); |
| 2208 |
if (err < 0) |
| 2209 |
return err; |
| 2210 |
err = snd_audiodrive_pnp(dev, card->private_data, pdev); |
| 2211 |
if (err < 0) |
| 2212 |
return err; |
| 2213 |
err = snd_audiodrive_probe(card, dev); |
| 2214 |
if (err < 0) |
| 2215 |
return err; |
| 2216 |
pnp_set_drvdata(pdev, card); |
| 2217 |
dev++; |
| 2218 |
return 0; |
| 2219 |
} |
| 2220 |
|
| 2221 |
#ifdef CONFIG_PM |
| 2222 |
static int snd_audiodrive_pnp_suspend(struct pnp_dev *pdev, pm_message_t state) |
| 2223 |
{ |
| 2224 |
return snd_es18xx_suspend(pnp_get_drvdata(pdev), state); |
| 2225 |
} |
| 2226 |
static int snd_audiodrive_pnp_resume(struct pnp_dev *pdev) |
| 2227 |
{ |
| 2228 |
return snd_es18xx_resume(pnp_get_drvdata(pdev)); |
| 2229 |
} |
| 2230 |
#endif |
| 2231 |
|
| 2232 |
static struct pnp_driver es18xx_pnp_driver = { |
| 2233 |
.name = "es18xx-pnpbios", |
| 2234 |
.id_table = snd_audiodrive_pnpbiosids, |
| 2235 |
.probe = snd_audiodrive_pnp_detect, |
| 2236 |
#ifdef CONFIG_PM |
| 2237 |
.suspend = snd_audiodrive_pnp_suspend, |
| 2238 |
.resume = snd_audiodrive_pnp_resume, |
| 2239 |
#endif |
| 2240 |
}; |
| 2241 |
|
| 2242 |
static int snd_audiodrive_pnpc_detect(struct pnp_card_link *pcard, |
| 2243 |
const struct pnp_card_device_id *pid) |
| 2244 |
{ |
| 2245 |
static int dev; |
| 2246 |
struct snd_card *card; |
| 2247 |
int res; |
| 2248 |
|
| 2249 |
for ( ; dev < SNDRV_CARDS; dev++) { |
| 2250 |
if (enable[dev] && isapnp[dev]) |
| 2251 |
break; |
| 2252 |
} |
| 2253 |
if (dev >= SNDRV_CARDS) |
| 2254 |
return -ENODEV; |
| 2255 |
|
| 2256 |
res = snd_es18xx_card_new(&pcard->card->dev, dev, &card); |
| 2257 |
if (res < 0) |
| 2258 |
return res; |
| 2259 |
|
| 2260 |
res = snd_audiodrive_pnpc(dev, card->private_data, pcard, pid); |
| 2261 |
if (res < 0) |
| 2262 |
return res; |
| 2263 |
res = snd_audiodrive_probe(card, dev); |
| 2264 |
if (res < 0) |
| 2265 |
return res; |
| 2266 |
|
| 2267 |
pnp_set_card_drvdata(pcard, card); |
| 2268 |
dev++; |
| 2269 |
return 0; |
| 2270 |
} |
| 2271 |
|
| 2272 |
#ifdef CONFIG_PM |
| 2273 |
static int snd_audiodrive_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state) |
| 2274 |
{ |
| 2275 |
return snd_es18xx_suspend(pnp_get_card_drvdata(pcard), state); |
| 2276 |
} |
| 2277 |
|
| 2278 |
static int snd_audiodrive_pnpc_resume(struct pnp_card_link *pcard) |
| 2279 |
{ |
| 2280 |
return snd_es18xx_resume(pnp_get_card_drvdata(pcard)); |
| 2281 |
} |
| 2282 |
|
| 2283 |
#endif |
| 2284 |
|
| 2285 |
static struct pnp_card_driver es18xx_pnpc_driver = { |
| 2286 |
.flags = PNP_DRIVER_RES_DISABLE, |
| 2287 |
.name = "es18xx", |
| 2288 |
.id_table = snd_audiodrive_pnpids, |
| 2289 |
.probe = snd_audiodrive_pnpc_detect, |
| 2290 |
#ifdef CONFIG_PM |
| 2291 |
.suspend = snd_audiodrive_pnpc_suspend, |
| 2292 |
.resume = snd_audiodrive_pnpc_resume, |
| 2293 |
#endif |
| 2294 |
}; |
| 2295 |
#endif /* CONFIG_PNP */ |
| 2296 |
|
| 2297 |
static int __init alsa_card_es18xx_init(void) |
| 2298 |
{ |
| 2299 |
int err; |
| 2300 |
|
| 2301 |
err = isa_register_driver(&snd_es18xx_isa_driver, SNDRV_CARDS); |
| 2302 |
#ifdef CONFIG_PNP |
| 2303 |
if (!err) |
| 2304 |
isa_registered = 1; |
| 2305 |
|
| 2306 |
err = pnp_register_driver(&es18xx_pnp_driver); |
| 2307 |
if (!err) |
| 2308 |
pnp_registered = 1; |
| 2309 |
|
| 2310 |
err = pnp_register_card_driver(&es18xx_pnpc_driver); |
| 2311 |
if (!err) |
| 2312 |
pnpc_registered = 1; |
| 2313 |
|
| 2314 |
if (isa_registered || pnp_registered) |
| 2315 |
err = 0; |
| 2316 |
#endif |
| 2317 |
return err; |
| 2318 |
} |
| 2319 |
|
| 2320 |
static void __exit alsa_card_es18xx_exit(void) |
| 2321 |
{ |
| 2322 |
#ifdef CONFIG_PNP |
| 2323 |
if (pnpc_registered) |
| 2324 |
pnp_unregister_card_driver(&es18xx_pnpc_driver); |
| 2325 |
if (pnp_registered) |
| 2326 |
pnp_unregister_driver(&es18xx_pnp_driver); |
| 2327 |
if (isa_registered) |
| 2328 |
#endif |
| 2329 |
isa_unregister_driver(&snd_es18xx_isa_driver); |
| 2330 |
} |
| 2331 |
|
| 2332 |
module_init(alsa_card_es18xx_init) |
| 2333 |
module_exit(alsa_card_es18xx_exit) |