Blame view
sound/pci/ad1889.c
26.4 KB
12bb5b78e [ALSA] ad1889: ad... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
/* Analog Devices 1889 audio driver * * This is a driver for the AD1889 PCI audio chipset found * on the HP PA-RISC [BCJ]-xxx0 workstations. * * Copyright (C) 2004-2005, Kyle McMartin <kyle@parisc-linux.org> * Copyright (C) 2005, Thibaut Varene <varenet@parisc-linux.org> * Based on the OSS AD1889 driver by Randolph Chung <tausq@debian.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * TODO: * Do we need to take care of CCS register? * Maybe we could use finer grained locking (separate locks for pb/cap)? * Wishlist: * Control Interface (mixer) support * Better AC97 support (VSR...)? * PM support * MIDI support * Game Port support |
25985edce Fix common misspe... |
32 |
* SG DMA support (this will need *a lot* of work) |
12bb5b78e [ALSA] ad1889: ad... |
33 34 35 36 |
*/ #include <linux/init.h> #include <linux/pci.h> |
9d2f928dd [PATCH] Intruduce... |
37 |
#include <linux/dma-mapping.h> |
12bb5b78e [ALSA] ad1889: ad... |
38 39 40 41 |
#include <linux/slab.h> #include <linux/interrupt.h> #include <linux/compiler.h> #include <linux/delay.h> |
da155d5b4 sound: Add module... |
42 |
#include <linux/module.h> |
12bb5b78e [ALSA] ad1889: ad... |
43 |
|
12bb5b78e [ALSA] ad1889: ad... |
44 45 46 47 48 49 50 51 52 |
#include <sound/core.h> #include <sound/pcm.h> #include <sound/initval.h> #include <sound/ac97_codec.h> #include <asm/io.h> #include "ad1889.h" #include "ac97/ac97_id.h" |
c6f43290a [ALSA] ad1889 - r... |
53 |
#define AD1889_DRVVER "Version: 1.7" |
12bb5b78e [ALSA] ad1889: ad... |
54 55 56 57 58 59 60 61 62 63 64 65 66 |
MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>, Thibaut Varene <t-bone@parisc-linux.org>"); MODULE_DESCRIPTION("Analog Devices AD1889 ALSA sound driver"); MODULE_LICENSE("GPL"); MODULE_SUPPORTED_DEVICE("{{Analog Devices,AD1889}}"); static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for the AD1889 soundcard."); static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for the AD1889 soundcard."); |
a67ff6a54 ALSA: module_para... |
67 |
static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; |
12bb5b78e [ALSA] ad1889: ad... |
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable AD1889 soundcard."); static char *ac97_quirk[SNDRV_CARDS]; module_param_array(ac97_quirk, charp, NULL, 0444); MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); #define DEVNAME "ad1889" #define PFX DEVNAME ": " /* let's use the global sound debug interfaces */ #define ad1889_debug(fmt, arg...) snd_printd(KERN_DEBUG fmt, ## arg) /* keep track of some hw registers */ struct ad1889_register_state { u16 reg; /* reg setup */ u32 addr; /* dma base address */ unsigned long size; /* DMA buffer size */ }; struct snd_ad1889 { |
02c2de69d [ALSA] Remove xxx... |
89 |
struct snd_card *card; |
12bb5b78e [ALSA] ad1889: ad... |
90 91 92 93 94 |
struct pci_dev *pci; int irq; unsigned long bar; void __iomem *iobase; |
02c2de69d [ALSA] Remove xxx... |
95 96 97 98 |
struct snd_ac97 *ac97; struct snd_ac97_bus *ac97_bus; struct snd_pcm *pcm; struct snd_info_entry *proc; |
12bb5b78e [ALSA] ad1889: ad... |
99 |
|
02c2de69d [ALSA] Remove xxx... |
100 101 |
struct snd_pcm_substream *psubs; struct snd_pcm_substream *csubs; |
12bb5b78e [ALSA] ad1889: ad... |
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
/* playback register state */ struct ad1889_register_state wave; struct ad1889_register_state ramc; spinlock_t lock; }; static inline u16 ad1889_readw(struct snd_ad1889 *chip, unsigned reg) { return readw(chip->iobase + reg); } static inline void ad1889_writew(struct snd_ad1889 *chip, unsigned reg, u16 val) { writew(val, chip->iobase + reg); } static inline u32 ad1889_readl(struct snd_ad1889 *chip, unsigned reg) { return readl(chip->iobase + reg); } static inline void ad1889_writel(struct snd_ad1889 *chip, unsigned reg, u32 val) { writel(val, chip->iobase + reg); } static inline void ad1889_unmute(struct snd_ad1889 *chip) { u16 st; st = ad1889_readw(chip, AD_DS_WADA) & ~(AD_DS_WADA_RWAM | AD_DS_WADA_LWAM); ad1889_writew(chip, AD_DS_WADA, st); ad1889_readw(chip, AD_DS_WADA); } static inline void ad1889_mute(struct snd_ad1889 *chip) { u16 st; st = ad1889_readw(chip, AD_DS_WADA) | AD_DS_WADA_RWAM | AD_DS_WADA_LWAM; ad1889_writew(chip, AD_DS_WADA, st); ad1889_readw(chip, AD_DS_WADA); } static inline void ad1889_load_adc_buffer_address(struct snd_ad1889 *chip, u32 address) { ad1889_writel(chip, AD_DMA_ADCBA, address); ad1889_writel(chip, AD_DMA_ADCCA, address); } static inline void ad1889_load_adc_buffer_count(struct snd_ad1889 *chip, u32 count) { ad1889_writel(chip, AD_DMA_ADCBC, count); ad1889_writel(chip, AD_DMA_ADCCC, count); } static inline void ad1889_load_adc_interrupt_count(struct snd_ad1889 *chip, u32 count) { ad1889_writel(chip, AD_DMA_ADCIB, count); ad1889_writel(chip, AD_DMA_ADCIC, count); } static inline void ad1889_load_wave_buffer_address(struct snd_ad1889 *chip, u32 address) { ad1889_writel(chip, AD_DMA_WAVBA, address); ad1889_writel(chip, AD_DMA_WAVCA, address); } static inline void ad1889_load_wave_buffer_count(struct snd_ad1889 *chip, u32 count) { ad1889_writel(chip, AD_DMA_WAVBC, count); ad1889_writel(chip, AD_DMA_WAVCC, count); } static inline void ad1889_load_wave_interrupt_count(struct snd_ad1889 *chip, u32 count) { ad1889_writel(chip, AD_DMA_WAVIB, count); ad1889_writel(chip, AD_DMA_WAVIC, count); } static void ad1889_channel_reset(struct snd_ad1889 *chip, unsigned int channel) { u16 reg; if (channel & AD_CHAN_WAV) { /* Disable wave channel */ reg = ad1889_readw(chip, AD_DS_WSMC) & ~AD_DS_WSMC_WAEN; ad1889_writew(chip, AD_DS_WSMC, reg); chip->wave.reg = reg; /* disable IRQs */ reg = ad1889_readw(chip, AD_DMA_WAV); reg &= AD_DMA_IM_DIS; reg &= ~AD_DMA_LOOP; ad1889_writew(chip, AD_DMA_WAV, reg); /* clear IRQ and address counters and pointers */ ad1889_load_wave_buffer_address(chip, 0x0); ad1889_load_wave_buffer_count(chip, 0x0); ad1889_load_wave_interrupt_count(chip, 0x0); /* flush */ ad1889_readw(chip, AD_DMA_WAV); } if (channel & AD_CHAN_ADC) { /* Disable ADC channel */ reg = ad1889_readw(chip, AD_DS_RAMC) & ~AD_DS_RAMC_ADEN; ad1889_writew(chip, AD_DS_RAMC, reg); chip->ramc.reg = reg; reg = ad1889_readw(chip, AD_DMA_ADC); reg &= AD_DMA_IM_DIS; reg &= ~AD_DMA_LOOP; ad1889_writew(chip, AD_DMA_ADC, reg); ad1889_load_adc_buffer_address(chip, 0x0); ad1889_load_adc_buffer_count(chip, 0x0); ad1889_load_adc_interrupt_count(chip, 0x0); /* flush */ ad1889_readw(chip, AD_DMA_ADC); } } |
f40b68903 [ALSA] Fix sectio... |
240 |
static u16 |
02c2de69d [ALSA] Remove xxx... |
241 |
snd_ad1889_ac97_read(struct snd_ac97 *ac97, unsigned short reg) |
12bb5b78e [ALSA] ad1889: ad... |
242 243 244 245 |
{ struct snd_ad1889 *chip = ac97->private_data; return ad1889_readw(chip, AD_AC97_BASE + reg); } |
f40b68903 [ALSA] Fix sectio... |
246 |
static void |
02c2de69d [ALSA] Remove xxx... |
247 |
snd_ad1889_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val) |
12bb5b78e [ALSA] ad1889: ad... |
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
{ struct snd_ad1889 *chip = ac97->private_data; ad1889_writew(chip, AD_AC97_BASE + reg, val); } static int snd_ad1889_ac97_ready(struct snd_ad1889 *chip) { int retry = 400; /* average needs 352 msec */ while (!(ad1889_readw(chip, AD_AC97_ACIC) & AD_AC97_ACIC_ACRDY) && --retry) mdelay(1); if (!retry) { snd_printk(KERN_ERR PFX "[%s] Link is not ready. ", |
9bf8e7dde [ALSA] sound: rep... |
264 |
__func__); |
12bb5b78e [ALSA] ad1889: ad... |
265 266 |
return -EIO; } |
9bf8e7dde [ALSA] sound: rep... |
267 268 |
ad1889_debug("[%s] ready after %d ms ", __func__, 400 - retry); |
12bb5b78e [ALSA] ad1889: ad... |
269 270 271 272 273 |
return 0; } static int |
02c2de69d [ALSA] Remove xxx... |
274 275 |
snd_ad1889_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) |
12bb5b78e [ALSA] ad1889: ad... |
276 277 278 279 280 281 |
{ return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); } static int |
02c2de69d [ALSA] Remove xxx... |
282 |
snd_ad1889_hw_free(struct snd_pcm_substream *substream) |
12bb5b78e [ALSA] ad1889: ad... |
283 284 285 |
{ return snd_pcm_lib_free_pages(substream); } |
02c2de69d [ALSA] Remove xxx... |
286 |
static struct snd_pcm_hardware snd_ad1889_playback_hw = { |
12bb5b78e [ALSA] ad1889: ad... |
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
.info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BLOCK_TRANSFER, .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, .rate_min = 8000, /* docs say 7000, but we're lazy */ .rate_max = 48000, .channels_min = 1, .channels_max = 2, .buffer_bytes_max = BUFFER_BYTES_MAX, .period_bytes_min = PERIOD_BYTES_MIN, .period_bytes_max = PERIOD_BYTES_MAX, .periods_min = PERIODS_MIN, .periods_max = PERIODS_MAX, /*.fifo_size = 0,*/ }; |
02c2de69d [ALSA] Remove xxx... |
302 |
static struct snd_pcm_hardware snd_ad1889_capture_hw = { |
12bb5b78e [ALSA] ad1889: ad... |
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
.info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BLOCK_TRANSFER, .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_48000, .rate_min = 48000, /* docs say we could to VSR, but we're lazy */ .rate_max = 48000, .channels_min = 1, .channels_max = 2, .buffer_bytes_max = BUFFER_BYTES_MAX, .period_bytes_min = PERIOD_BYTES_MIN, .period_bytes_max = PERIOD_BYTES_MAX, .periods_min = PERIODS_MIN, .periods_max = PERIODS_MAX, /*.fifo_size = 0,*/ }; static int |
02c2de69d [ALSA] Remove xxx... |
320 |
snd_ad1889_playback_open(struct snd_pcm_substream *ss) |
12bb5b78e [ALSA] ad1889: ad... |
321 322 |
{ struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); |
02c2de69d [ALSA] Remove xxx... |
323 |
struct snd_pcm_runtime *rt = ss->runtime; |
12bb5b78e [ALSA] ad1889: ad... |
324 325 326 327 328 329 330 331 |
chip->psubs = ss; rt->hw = snd_ad1889_playback_hw; return 0; } static int |
02c2de69d [ALSA] Remove xxx... |
332 |
snd_ad1889_capture_open(struct snd_pcm_substream *ss) |
12bb5b78e [ALSA] ad1889: ad... |
333 334 |
{ struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); |
02c2de69d [ALSA] Remove xxx... |
335 |
struct snd_pcm_runtime *rt = ss->runtime; |
12bb5b78e [ALSA] ad1889: ad... |
336 337 338 339 340 341 342 343 |
chip->csubs = ss; rt->hw = snd_ad1889_capture_hw; return 0; } static int |
02c2de69d [ALSA] Remove xxx... |
344 |
snd_ad1889_playback_close(struct snd_pcm_substream *ss) |
12bb5b78e [ALSA] ad1889: ad... |
345 346 347 348 349 350 351 |
{ struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); chip->psubs = NULL; return 0; } static int |
02c2de69d [ALSA] Remove xxx... |
352 |
snd_ad1889_capture_close(struct snd_pcm_substream *ss) |
12bb5b78e [ALSA] ad1889: ad... |
353 354 355 356 357 358 359 |
{ struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); chip->csubs = NULL; return 0; } static int |
02c2de69d [ALSA] Remove xxx... |
360 |
snd_ad1889_playback_prepare(struct snd_pcm_substream *ss) |
12bb5b78e [ALSA] ad1889: ad... |
361 362 |
{ struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); |
02c2de69d [ALSA] Remove xxx... |
363 |
struct snd_pcm_runtime *rt = ss->runtime; |
12bb5b78e [ALSA] ad1889: ad... |
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
unsigned int size = snd_pcm_lib_buffer_bytes(ss); unsigned int count = snd_pcm_lib_period_bytes(ss); u16 reg; ad1889_channel_reset(chip, AD_CHAN_WAV); reg = ad1889_readw(chip, AD_DS_WSMC); /* Mask out 16-bit / Stereo */ reg &= ~(AD_DS_WSMC_WA16 | AD_DS_WSMC_WAST); if (snd_pcm_format_width(rt->format) == 16) reg |= AD_DS_WSMC_WA16; if (rt->channels > 1) reg |= AD_DS_WSMC_WAST; /* let's make sure we don't clobber ourselves */ spin_lock_irq(&chip->lock); chip->wave.size = size; chip->wave.reg = reg; chip->wave.addr = rt->dma_addr; ad1889_writew(chip, AD_DS_WSMC, chip->wave.reg); /* Set sample rates on the codec */ ad1889_writew(chip, AD_DS_WAS, rt->rate); /* Set up DMA */ ad1889_load_wave_buffer_address(chip, chip->wave.addr); ad1889_load_wave_buffer_count(chip, size); ad1889_load_wave_interrupt_count(chip, count); /* writes flush */ ad1889_readw(chip, AD_DS_WSMC); spin_unlock_irq(&chip->lock); ad1889_debug("prepare playback: addr = 0x%x, count = %u, " "size = %u, reg = 0x%x, rate = %u ", chip->wave.addr, count, size, reg, rt->rate); return 0; } static int |
02c2de69d [ALSA] Remove xxx... |
411 |
snd_ad1889_capture_prepare(struct snd_pcm_substream *ss) |
12bb5b78e [ALSA] ad1889: ad... |
412 413 |
{ struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); |
02c2de69d [ALSA] Remove xxx... |
414 |
struct snd_pcm_runtime *rt = ss->runtime; |
12bb5b78e [ALSA] ad1889: ad... |
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
unsigned int size = snd_pcm_lib_buffer_bytes(ss); unsigned int count = snd_pcm_lib_period_bytes(ss); u16 reg; ad1889_channel_reset(chip, AD_CHAN_ADC); reg = ad1889_readw(chip, AD_DS_RAMC); /* Mask out 16-bit / Stereo */ reg &= ~(AD_DS_RAMC_AD16 | AD_DS_RAMC_ADST); if (snd_pcm_format_width(rt->format) == 16) reg |= AD_DS_RAMC_AD16; if (rt->channels > 1) reg |= AD_DS_RAMC_ADST; /* let's make sure we don't clobber ourselves */ spin_lock_irq(&chip->lock); chip->ramc.size = size; chip->ramc.reg = reg; chip->ramc.addr = rt->dma_addr; ad1889_writew(chip, AD_DS_RAMC, chip->ramc.reg); /* Set up DMA */ ad1889_load_adc_buffer_address(chip, chip->ramc.addr); ad1889_load_adc_buffer_count(chip, size); ad1889_load_adc_interrupt_count(chip, count); /* writes flush */ ad1889_readw(chip, AD_DS_RAMC); spin_unlock_irq(&chip->lock); ad1889_debug("prepare capture: addr = 0x%x, count = %u, " "size = %u, reg = 0x%x, rate = %u ", chip->ramc.addr, count, size, reg, rt->rate); return 0; } /* this is called in atomic context with IRQ disabled. Must be as fast as possible and not sleep. DMA should be *triggered* by this call. The WSMC "WAEN" bit triggers DMA Wave On/Off */ static int |
02c2de69d [ALSA] Remove xxx... |
463 |
snd_ad1889_playback_trigger(struct snd_pcm_substream *ss, int cmd) |
12bb5b78e [ALSA] ad1889: ad... |
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
{ u16 wsmc; struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); wsmc = ad1889_readw(chip, AD_DS_WSMC); switch (cmd) { case SNDRV_PCM_TRIGGER_START: /* enable DMA loop & interrupts */ ad1889_writew(chip, AD_DMA_WAV, AD_DMA_LOOP | AD_DMA_IM_CNT); wsmc |= AD_DS_WSMC_WAEN; /* 1 to clear CHSS bit */ ad1889_writel(chip, AD_DMA_CHSS, AD_DMA_CHSS_WAVS); ad1889_unmute(chip); break; case SNDRV_PCM_TRIGGER_STOP: ad1889_mute(chip); wsmc &= ~AD_DS_WSMC_WAEN; break; default: snd_BUG(); return -EINVAL; } chip->wave.reg = wsmc; ad1889_writew(chip, AD_DS_WSMC, wsmc); ad1889_readw(chip, AD_DS_WSMC); /* flush */ /* reset the chip when STOP - will disable IRQs */ if (cmd == SNDRV_PCM_TRIGGER_STOP) ad1889_channel_reset(chip, AD_CHAN_WAV); return 0; } /* this is called in atomic context with IRQ disabled. Must be as fast as possible and not sleep. DMA should be *triggered* by this call. The RAMC "ADEN" bit triggers DMA ADC On/Off */ static int |
02c2de69d [ALSA] Remove xxx... |
504 |
snd_ad1889_capture_trigger(struct snd_pcm_substream *ss, int cmd) |
12bb5b78e [ALSA] ad1889: ad... |
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
{ u16 ramc; struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); ramc = ad1889_readw(chip, AD_DS_RAMC); switch (cmd) { case SNDRV_PCM_TRIGGER_START: /* enable DMA loop & interrupts */ ad1889_writew(chip, AD_DMA_ADC, AD_DMA_LOOP | AD_DMA_IM_CNT); ramc |= AD_DS_RAMC_ADEN; /* 1 to clear CHSS bit */ ad1889_writel(chip, AD_DMA_CHSS, AD_DMA_CHSS_ADCS); break; case SNDRV_PCM_TRIGGER_STOP: ramc &= ~AD_DS_RAMC_ADEN; break; default: return -EINVAL; } chip->ramc.reg = ramc; ad1889_writew(chip, AD_DS_RAMC, ramc); ad1889_readw(chip, AD_DS_RAMC); /* flush */ /* reset the chip when STOP - will disable IRQs */ if (cmd == SNDRV_PCM_TRIGGER_STOP) ad1889_channel_reset(chip, AD_CHAN_ADC); return 0; } /* Called in atomic context with IRQ disabled */ static snd_pcm_uframes_t |
02c2de69d [ALSA] Remove xxx... |
539 |
snd_ad1889_playback_pointer(struct snd_pcm_substream *ss) |
12bb5b78e [ALSA] ad1889: ad... |
540 541 542 543 544 545 546 547 548 549 |
{ size_t ptr = 0; struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); if (unlikely(!(chip->wave.reg & AD_DS_WSMC_WAEN))) return 0; ptr = ad1889_readl(chip, AD_DMA_WAVCA); ptr -= chip->wave.addr; |
da3cec35d ALSA: Kill snd_as... |
550 551 |
if (snd_BUG_ON(ptr >= chip->wave.size)) return 0; |
12bb5b78e [ALSA] ad1889: ad... |
552 553 554 555 556 557 |
return bytes_to_frames(ss->runtime, ptr); } /* Called in atomic context with IRQ disabled */ static snd_pcm_uframes_t |
02c2de69d [ALSA] Remove xxx... |
558 |
snd_ad1889_capture_pointer(struct snd_pcm_substream *ss) |
12bb5b78e [ALSA] ad1889: ad... |
559 560 561 562 563 564 565 566 567 |
{ size_t ptr = 0; struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); if (unlikely(!(chip->ramc.reg & AD_DS_RAMC_ADEN))) return 0; ptr = ad1889_readl(chip, AD_DMA_ADCCA); ptr -= chip->ramc.addr; |
da3cec35d ALSA: Kill snd_as... |
568 569 |
if (snd_BUG_ON(ptr >= chip->ramc.size)) return 0; |
12bb5b78e [ALSA] ad1889: ad... |
570 571 572 |
return bytes_to_frames(ss->runtime, ptr); } |
02c2de69d [ALSA] Remove xxx... |
573 |
static struct snd_pcm_ops snd_ad1889_playback_ops = { |
12bb5b78e [ALSA] ad1889: ad... |
574 575 576 577 578 579 580 581 582 |
.open = snd_ad1889_playback_open, .close = snd_ad1889_playback_close, .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_ad1889_hw_params, .hw_free = snd_ad1889_hw_free, .prepare = snd_ad1889_playback_prepare, .trigger = snd_ad1889_playback_trigger, .pointer = snd_ad1889_playback_pointer, }; |
02c2de69d [ALSA] Remove xxx... |
583 |
static struct snd_pcm_ops snd_ad1889_capture_ops = { |
12bb5b78e [ALSA] ad1889: ad... |
584 585 586 587 588 589 590 591 592 593 594 |
.open = snd_ad1889_capture_open, .close = snd_ad1889_capture_close, .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_ad1889_hw_params, .hw_free = snd_ad1889_hw_free, .prepare = snd_ad1889_capture_prepare, .trigger = snd_ad1889_capture_trigger, .pointer = snd_ad1889_capture_pointer, }; static irqreturn_t |
7d12e780e IRQ: Maintain reg... |
595 |
snd_ad1889_interrupt(int irq, void *dev_id) |
12bb5b78e [ALSA] ad1889: ad... |
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 |
{ unsigned long st; struct snd_ad1889 *chip = dev_id; st = ad1889_readl(chip, AD_DMA_DISR); /* clear ISR */ ad1889_writel(chip, AD_DMA_DISR, st); st &= AD_INTR_MASK; if (unlikely(!st)) return IRQ_NONE; if (st & (AD_DMA_DISR_PMAI|AD_DMA_DISR_PTAI)) ad1889_debug("Unexpected master or target abort interrupt! "); if ((st & AD_DMA_DISR_WAVI) && chip->psubs) snd_pcm_period_elapsed(chip->psubs); if ((st & AD_DMA_DISR_ADCI) && chip->csubs) snd_pcm_period_elapsed(chip->csubs); return IRQ_HANDLED; } |
12bb5b78e [ALSA] ad1889: ad... |
621 |
static int __devinit |
02c2de69d [ALSA] Remove xxx... |
622 |
snd_ad1889_pcm_init(struct snd_ad1889 *chip, int device, struct snd_pcm **rpcm) |
12bb5b78e [ALSA] ad1889: ad... |
623 624 |
{ int err; |
02c2de69d [ALSA] Remove xxx... |
625 |
struct snd_pcm *pcm; |
12bb5b78e [ALSA] ad1889: ad... |
626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
if (rpcm) *rpcm = NULL; err = snd_pcm_new(chip->card, chip->card->driver, device, 1, 1, &pcm); if (err < 0) return err; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ad1889_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ad1889_capture_ops); pcm->private_data = chip; |
12bb5b78e [ALSA] ad1889: ad... |
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
pcm->info_flags = 0; strcpy(pcm->name, chip->card->shortname); chip->pcm = pcm; chip->psubs = NULL; chip->csubs = NULL; err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), BUFFER_BYTES_MAX / 2, BUFFER_BYTES_MAX); if (err < 0) { snd_printk(KERN_ERR PFX "buffer allocation error: %d ", err); return err; } if (rpcm) *rpcm = pcm; return 0; } static void |
02c2de69d [ALSA] Remove xxx... |
665 |
snd_ad1889_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) |
12bb5b78e [ALSA] ad1889: ad... |
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 |
{ struct snd_ad1889 *chip = entry->private_data; u16 reg; int tmp; reg = ad1889_readw(chip, AD_DS_WSMC); snd_iprintf(buffer, "Wave output: %s ", (reg & AD_DS_WSMC_WAEN) ? "enabled" : "disabled"); snd_iprintf(buffer, "Wave Channels: %s ", (reg & AD_DS_WSMC_WAST) ? "stereo" : "mono"); snd_iprintf(buffer, "Wave Quality: %d-bit linear ", (reg & AD_DS_WSMC_WA16) ? 16 : 8); /* WARQ is at offset 12 */ tmp = (reg & AD_DS_WSMC_WARQ) ? (((reg & AD_DS_WSMC_WARQ >> 12) & 0x01) ? 12 : 18) : 4; tmp /= (reg & AD_DS_WSMC_WAST) ? 2 : 1; snd_iprintf(buffer, "Wave FIFO: %d %s words ", tmp, (reg & AD_DS_WSMC_WAST) ? "stereo" : "mono"); snd_iprintf(buffer, "Synthesis output: %s ", reg & AD_DS_WSMC_SYEN ? "enabled" : "disabled"); /* SYRQ is at offset 4 */ tmp = (reg & AD_DS_WSMC_SYRQ) ? (((reg & AD_DS_WSMC_SYRQ >> 4) & 0x01) ? 12 : 18) : 4; tmp /= (reg & AD_DS_WSMC_WAST) ? 2 : 1; snd_iprintf(buffer, "Synthesis FIFO: %d %s words ", tmp, (reg & AD_DS_WSMC_WAST) ? "stereo" : "mono"); reg = ad1889_readw(chip, AD_DS_RAMC); snd_iprintf(buffer, "ADC input: %s ", (reg & AD_DS_RAMC_ADEN) ? "enabled" : "disabled"); snd_iprintf(buffer, "ADC Channels: %s ", (reg & AD_DS_RAMC_ADST) ? "stereo" : "mono"); snd_iprintf(buffer, "ADC Quality: %d-bit linear ", (reg & AD_DS_RAMC_AD16) ? 16 : 8); /* ACRQ is at offset 4 */ tmp = (reg & AD_DS_RAMC_ACRQ) ? (((reg & AD_DS_RAMC_ACRQ >> 4) & 0x01) ? 12 : 18) : 4; tmp /= (reg & AD_DS_RAMC_ADST) ? 2 : 1; snd_iprintf(buffer, "ADC FIFO: %d %s words ", tmp, (reg & AD_DS_RAMC_ADST) ? "stereo" : "mono"); snd_iprintf(buffer, "Resampler input: %s ", reg & AD_DS_RAMC_REEN ? "enabled" : "disabled"); /* RERQ is at offset 12 */ tmp = (reg & AD_DS_RAMC_RERQ) ? (((reg & AD_DS_RAMC_RERQ >> 12) & 0x01) ? 12 : 18) : 4; tmp /= (reg & AD_DS_RAMC_ADST) ? 2 : 1; snd_iprintf(buffer, "Resampler FIFO: %d %s words ", tmp, (reg & AD_DS_WSMC_WAST) ? "stereo" : "mono"); /* doc says LSB represents -1.5dB, but the max value (-94.5dB) suggests that LSB is -3dB, which is more coherent with the logarithmic nature of the dB scale */ reg = ad1889_readw(chip, AD_DS_WADA); snd_iprintf(buffer, "Left: %s, -%d dB ", (reg & AD_DS_WADA_LWAM) ? "mute" : "unmute", ((reg & AD_DS_WADA_LWAA) >> 8) * 3); reg = ad1889_readw(chip, AD_DS_WADA); snd_iprintf(buffer, "Right: %s, -%d dB ", (reg & AD_DS_WADA_RWAM) ? "mute" : "unmute", ((reg & AD_DS_WADA_RWAA) >> 8) * 3); reg = ad1889_readw(chip, AD_DS_WAS); snd_iprintf(buffer, "Wave samplerate: %u Hz ", reg); reg = ad1889_readw(chip, AD_DS_RES); snd_iprintf(buffer, "Resampler samplerate: %u Hz ", reg); } static void __devinit snd_ad1889_proc_init(struct snd_ad1889 *chip) { |
02c2de69d [ALSA] Remove xxx... |
768 |
struct snd_info_entry *entry; |
12bb5b78e [ALSA] ad1889: ad... |
769 770 |
if (!snd_card_proc_new(chip->card, chip->card->driver, &entry)) |
bf850204a [ALSA] Remove unn... |
771 |
snd_info_set_text_ops(entry, chip, snd_ad1889_proc_read); |
12bb5b78e [ALSA] ad1889: ad... |
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 |
} static struct ac97_quirk ac97_quirks[] = { { .subvendor = 0x11d4, /* AD */ .subdevice = 0x1889, /* AD1889 */ .codec_id = AC97_ID_AD1819, .name = "AD1889", .type = AC97_TUNE_HP_ONLY }, { } /* terminator */ }; static void __devinit snd_ad1889_ac97_xinit(struct snd_ad1889 *chip) { u16 reg; reg = ad1889_readw(chip, AD_AC97_ACIC); reg |= AD_AC97_ACIC_ACRD; /* Reset Disable */ ad1889_writew(chip, AD_AC97_ACIC, reg); ad1889_readw(chip, AD_AC97_ACIC); /* flush posted write */ udelay(10); /* Interface Enable */ reg |= AD_AC97_ACIC_ACIE; ad1889_writew(chip, AD_AC97_ACIC, reg); snd_ad1889_ac97_ready(chip); /* Audio Stream Output | Variable Sample Rate Mode */ reg = ad1889_readw(chip, AD_AC97_ACIC); reg |= AD_AC97_ACIC_ASOE | AD_AC97_ACIC_VSRM; ad1889_writew(chip, AD_AC97_ACIC, reg); ad1889_readw(chip, AD_AC97_ACIC); /* flush posted write */ } static void |
02c2de69d [ALSA] Remove xxx... |
810 |
snd_ad1889_ac97_bus_free(struct snd_ac97_bus *bus) |
12bb5b78e [ALSA] ad1889: ad... |
811 812 813 814 815 816 |
{ struct snd_ad1889 *chip = bus->private_data; chip->ac97_bus = NULL; } static void |
02c2de69d [ALSA] Remove xxx... |
817 |
snd_ad1889_ac97_free(struct snd_ac97 *ac97) |
12bb5b78e [ALSA] ad1889: ad... |
818 819 820 821 822 823 824 825 826 |
{ struct snd_ad1889 *chip = ac97->private_data; chip->ac97 = NULL; } static int __devinit snd_ad1889_ac97_init(struct snd_ad1889 *chip, const char *quirk_override) { int err; |
02c2de69d [ALSA] Remove xxx... |
827 828 |
struct snd_ac97_template ac97; static struct snd_ac97_bus_ops ops = { |
12bb5b78e [ALSA] ad1889: ad... |
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 |
.write = snd_ad1889_ac97_write, .read = snd_ad1889_ac97_read, }; /* doing that here, it works. */ snd_ad1889_ac97_xinit(chip); err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus); if (err < 0) return err; chip->ac97_bus->private_free = snd_ad1889_ac97_bus_free; memset(&ac97, 0, sizeof(ac97)); ac97.private_data = chip; ac97.private_free = snd_ad1889_ac97_free; ac97.pci = chip->pci; err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97); if (err < 0) return err; snd_ac97_tune_hardware(chip->ac97, ac97_quirks, quirk_override); return 0; } static int snd_ad1889_free(struct snd_ad1889 *chip) { if (chip->irq < 0) goto skip_hw; spin_lock_irq(&chip->lock); ad1889_mute(chip); /* Turn off interrupt on count and zero DMA registers */ ad1889_channel_reset(chip, AD_CHAN_WAV | AD_CHAN_ADC); /* clear DISR. If we don't, we'd better jump off the Eiffel Tower */ ad1889_writel(chip, AD_DMA_DISR, AD_DMA_DISR_PTAI | AD_DMA_DISR_PMAI); ad1889_readl(chip, AD_DMA_DISR); /* flush, dammit! */ spin_unlock_irq(&chip->lock); |
12bb5b78e [ALSA] ad1889: ad... |
874 |
if (chip->irq >= 0) |
437a5a460 [ALSA] Remove IRQ... |
875 |
free_irq(chip->irq, chip); |
12bb5b78e [ALSA] ad1889: ad... |
876 877 878 879 880 881 882 883 884 885 886 |
skip_hw: if (chip->iobase) iounmap(chip->iobase); pci_release_regions(chip->pci); pci_disable_device(chip->pci); kfree(chip); return 0; } |
f40b68903 [ALSA] Fix sectio... |
887 |
static int |
02c2de69d [ALSA] Remove xxx... |
888 |
snd_ad1889_dev_free(struct snd_device *device) |
12bb5b78e [ALSA] ad1889: ad... |
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 |
{ struct snd_ad1889 *chip = device->device_data; return snd_ad1889_free(chip); } static int __devinit snd_ad1889_init(struct snd_ad1889 *chip) { ad1889_writew(chip, AD_DS_CCS, AD_DS_CCS_CLKEN); /* turn on clock */ ad1889_readw(chip, AD_DS_CCS); /* flush posted write */ mdelay(10); /* enable Master and Target abort interrupts */ ad1889_writel(chip, AD_DMA_DISR, AD_DMA_DISR_PMAE | AD_DMA_DISR_PTAE); return 0; } static int __devinit |
02c2de69d [ALSA] Remove xxx... |
909 |
snd_ad1889_create(struct snd_card *card, |
12bb5b78e [ALSA] ad1889: ad... |
910 911 912 913 914 915 |
struct pci_dev *pci, struct snd_ad1889 **rchip) { int err; struct snd_ad1889 *chip; |
02c2de69d [ALSA] Remove xxx... |
916 |
static struct snd_device_ops ops = { |
12bb5b78e [ALSA] ad1889: ad... |
917 918 919 920 921 922 923 |
.dev_free = snd_ad1889_dev_free, }; *rchip = NULL; if ((err = pci_enable_device(pci)) < 0) return err; |
9d2f928dd [PATCH] Intruduce... |
924 |
|
12bb5b78e [ALSA] ad1889: ad... |
925 |
/* check PCI availability (32bit DMA) */ |
284901a90 dma-mapping: repl... |
926 927 |
if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 || pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { |
12bb5b78e [ALSA] ad1889: ad... |
928 929 930 931 932 933 934 |
printk(KERN_ERR PFX "error setting 32-bit DMA mask. "); pci_disable_device(pci); return -ENXIO; } /* allocate chip specific data with zero-filled memory */ |
e560d8d83 [ALSA] Replace wi... |
935 |
if ((chip = kzalloc(sizeof(*chip), GFP_KERNEL)) == NULL) { |
12bb5b78e [ALSA] ad1889: ad... |
936 937 938 939 940 941 942 943 944 945 946 947 948 949 |
pci_disable_device(pci); return -ENOMEM; } chip->card = card; card->private_data = chip; chip->pci = pci; chip->irq = -1; /* (1) PCI resource allocation */ if ((err = pci_request_regions(pci, card->driver)) < 0) goto free_and_ret; chip->bar = pci_resource_start(pci, 0); |
2f5ad54ea pci: use pci_iore... |
950 |
chip->iobase = pci_ioremap_bar(pci, 0); |
12bb5b78e [ALSA] ad1889: ad... |
951 952 953 954 955 956 957 958 959 960 961 962 |
if (chip->iobase == NULL) { printk(KERN_ERR PFX "unable to reserve region. "); err = -EBUSY; goto free_and_ret; } pci_set_master(pci); spin_lock_init(&chip->lock); /* only now can we call ad1889_free */ if (request_irq(pci->irq, snd_ad1889_interrupt, |
934c2b6d0 ALSA: use KBUILD_... |
963 |
IRQF_SHARED, KBUILD_MODNAME, chip)) { |
12bb5b78e [ALSA] ad1889: ad... |
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 |
printk(KERN_ERR PFX "cannot obtain IRQ %d ", pci->irq); snd_ad1889_free(chip); return -EBUSY; } chip->irq = pci->irq; synchronize_irq(chip->irq); /* (2) initialization of the chip hardware */ if ((err = snd_ad1889_init(chip)) < 0) { snd_ad1889_free(chip); return err; } if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { snd_ad1889_free(chip); return err; } snd_card_set_dev(card, &pci->dev); *rchip = chip; return 0; free_and_ret: |
fc58422ad [ALSA] Big kfree ... |
991 |
kfree(chip); |
12bb5b78e [ALSA] ad1889: ad... |
992 993 994 995 996 997 998 999 1000 1001 1002 |
pci_disable_device(pci); return err; } static int __devinit snd_ad1889_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { int err; static int devno; |
02c2de69d [ALSA] Remove xxx... |
1003 |
struct snd_card *card; |
12bb5b78e [ALSA] ad1889: ad... |
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 |
struct snd_ad1889 *chip; /* (1) */ if (devno >= SNDRV_CARDS) return -ENODEV; if (!enable[devno]) { devno++; return -ENOENT; } /* (2) */ |
e58de7baf ALSA: Convert to ... |
1015 |
err = snd_card_create(index[devno], id[devno], THIS_MODULE, 0, &card); |
12bb5b78e [ALSA] ad1889: ad... |
1016 |
/* XXX REVISIT: we can probably allocate chip in this call */ |
e58de7baf ALSA: Convert to ... |
1017 1018 |
if (err < 0) return err; |
12bb5b78e [ALSA] ad1889: ad... |
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 |
strcpy(card->driver, "AD1889"); strcpy(card->shortname, "Analog Devices AD1889"); /* (3) */ err = snd_ad1889_create(card, pci, &chip); if (err < 0) goto free_and_ret; /* (4) */ sprintf(card->longname, "%s at 0x%lx irq %i", card->shortname, chip->bar, chip->irq); /* (5) */ /* register AC97 mixer */ err = snd_ad1889_ac97_init(chip, ac97_quirk[devno]); if (err < 0) goto free_and_ret; err = snd_ad1889_pcm_init(chip, 0, NULL); if (err < 0) goto free_and_ret; /* register proc interface */ snd_ad1889_proc_init(chip); /* (6) */ err = snd_card_register(card); if (err < 0) goto free_and_ret; /* (7) */ pci_set_drvdata(pci, card); devno++; return 0; free_and_ret: snd_card_free(card); return err; } static void __devexit snd_ad1889_remove(struct pci_dev *pci) { snd_card_free(pci_get_drvdata(pci)); pci_set_drvdata(pci, NULL); } |
cebe41d4b sound: use DEFINE... |
1067 |
static DEFINE_PCI_DEVICE_TABLE(snd_ad1889_ids) = { |
12bb5b78e [ALSA] ad1889: ad... |
1068 1069 1070 1071 |
{ PCI_DEVICE(PCI_VENDOR_ID_ANALOG_DEVICES, PCI_DEVICE_ID_AD1889JS) }, { 0, }, }; MODULE_DEVICE_TABLE(pci, snd_ad1889_ids); |
e4d76815c [ALSA] sound: fix... |
1072 |
static struct pci_driver ad1889_pci_driver = { |
3733e424c ALSA: Use KBUILD_... |
1073 |
.name = KBUILD_MODNAME, |
12bb5b78e [ALSA] ad1889: ad... |
1074 1075 1076 1077 1078 1079 1080 1081 |
.id_table = snd_ad1889_ids, .probe = snd_ad1889_probe, .remove = __devexit_p(snd_ad1889_remove), }; static int __init alsa_ad1889_init(void) { |
e4d76815c [ALSA] sound: fix... |
1082 |
return pci_register_driver(&ad1889_pci_driver); |
12bb5b78e [ALSA] ad1889: ad... |
1083 1084 1085 1086 1087 |
} static void __exit alsa_ad1889_fini(void) { |
e4d76815c [ALSA] sound: fix... |
1088 |
pci_unregister_driver(&ad1889_pci_driver); |
12bb5b78e [ALSA] ad1889: ad... |
1089 1090 1091 1092 |
} module_init(alsa_ad1889_init); module_exit(alsa_ad1889_fini); |