Changeset 305 for GPL/branches/uniaud-2.0/alsa-kernel/pci/fm801.c
- Timestamp:
- Mar 24, 2008, 2:43:42 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/branches/uniaud-2.0/alsa-kernel/pci/fm801.c
r135 r305 1 1 /* 2 2 * The driver for the ForteMedia FM801 based soundcards 3 * Copyright (c) by Jaroslav Kysela <perex@ suse.cz>3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 4 4 * 5 * Support FM only card by Andy Shevchenko <andy@smile.org.ua> 5 6 * 6 7 * This program is free software; you can redistribute it and/or modify … … 20 21 */ 21 22 22 #include <sound/driver.h>23 23 #include <linux/delay.h> 24 24 #include <linux/init.h> … … 26 26 #include <linux/pci.h> 27 27 #include <linux/slab.h> 28 //#include <linux/moduleparam.h>28 #include <linux/moduleparam.h> 29 29 #include <sound/core.h> 30 30 #include <sound/pcm.h> 31 #include <sound/tlv.h> 31 32 #include <sound/ac97_codec.h> 32 33 #include <sound/mpu401.h> … … 36 37 #include <asm/io.h> 37 38 38 #if (defined(CONFIG_SND_FM801_TEA575X) || defined(CONFIG_SND_FM801_TEA575X_MODULE)) && (defined(CONFIG_VIDEO_DEV) || defined(CONFIG_VIDEO_DEV_MODULE))39 #ifdef CONFIG_SND_FM801_TEA575X_BOOL 39 40 #include <sound/tea575x-tuner.h> 40 41 #define TEA575X_RADIO 1 41 42 #endif 42 43 43 MODULE_AUTHOR("Jaroslav Kysela <perex@ suse.cz>");44 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 44 45 MODULE_DESCRIPTION("ForteMedia FM801"); 45 46 MODULE_LICENSE("GPL"); … … 55 56 * 2 = MediaForte 256-PCPR 56 57 * 3 = MediaForte 64-PCR 58 * 16 = setup tuner only (this is additional bit), i.e. SF-64-PCR FM card 57 59 * High 16-bits are video (radio) device number + 1 58 60 */ 59 static int tea575x_tuner[SNDRV_CARDS] = { 0 };60 61 //module_param_array(index, int, NULL, 0444);61 static int tea575x_tuner[SNDRV_CARDS]; 62 63 module_param_array(index, int, NULL, 0444); 62 64 MODULE_PARM_DESC(index, "Index value for the FM801 soundcard."); 63 //module_param_array(id, charp, NULL, 0444);65 module_param_array(id, charp, NULL, 0444); 64 66 MODULE_PARM_DESC(id, "ID string for the FM801 soundcard."); 65 //module_param_array(enable, bool, NULL, 0444);67 module_param_array(enable, bool, NULL, 0444); 66 68 MODULE_PARM_DESC(enable, "Enable FM801 soundcard."); 67 //module_param_array(tea575x_tuner, bool, NULL, 0444);69 module_param_array(tea575x_tuner, int, NULL, 0444); 68 70 MODULE_PARM_DESC(tea575x_tuner, "Enable TEA575x tuner."); 69 71 … … 104 106 #define FM801_POWERDOWN 0x70 /* Blocks Power Down Control */ 105 107 106 #define FM801_AC97_ADDR_SHIFT 10 108 /* codec access */ 109 #define FM801_AC97_READ (1<<7) /* read=1, write=0 */ 110 #define FM801_AC97_VALID (1<<8) /* port valid=1 */ 111 #define FM801_AC97_BUSY (1<<9) /* busy=1 */ 112 #define FM801_AC97_ADDR_SHIFT 10 /* codec id (2bit) */ 107 113 108 114 /* playback and record control register bits */ … … 148 154 */ 149 155 150 typedef struct _snd_fm801 fm801_t; 151 152 struct _snd_fm801 { 156 struct fm801 { 153 157 int irq; 154 158 … … 157 161 secondary: 1; /* secondary codec */ 158 162 unsigned char secondary_addr; /* address of the secondary codec */ 163 unsigned int tea575x_tuner; /* tuner flags */ 159 164 160 165 unsigned short ply_ctrl; /* playback control */ … … 173 178 unsigned int cap_pos; 174 179 175 ac97_bus_t*ac97_bus;176 ac97_t*ac97;177 ac97_t*ac97_sec;180 struct snd_ac97_bus *ac97_bus; 181 struct snd_ac97 *ac97; 182 struct snd_ac97 *ac97_sec; 178 183 179 184 struct pci_dev *pci; 180 s nd_card_t*card;181 s nd_pcm_t*pcm;182 s nd_rawmidi_t*rmidi;183 s nd_pcm_substream_t*playback_substream;184 s nd_pcm_substream_t*capture_substream;185 struct snd_card *card; 186 struct snd_pcm *pcm; 187 struct snd_rawmidi *rmidi; 188 struct snd_pcm_substream *playback_substream; 189 struct snd_pcm_substream *capture_substream; 185 190 unsigned int p_dma_size; 186 191 unsigned int c_dma_size; 187 192 188 193 spinlock_t reg_lock; 189 s nd_info_entry_t*proc_entry;194 struct snd_info_entry *proc_entry; 190 195 191 196 #ifdef TEA575X_RADIO 192 tea575x_t tea; 197 struct snd_tea575x tea; 198 #endif 199 200 #ifdef CONFIG_PM 201 u16 saved_regs[0x20]; 193 202 #endif 194 203 }; … … 196 205 static struct pci_device_id snd_fm801_ids[] = { 197 206 { 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, }, /* FM801 */ 207 { 0x5213, 0x0510, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, }, /* Gallant Odyssey Sound 4 */ 198 208 { 0, } 199 209 }; … … 205 215 */ 206 216 207 static int snd_fm801_update_bits( fm801_t*chip, unsigned short reg,217 static int snd_fm801_update_bits(struct fm801 *chip, unsigned short reg, 208 218 unsigned short mask, unsigned short value) 209 219 { 210 211 212 213 214 220 int change; 221 unsigned long flags; 222 unsigned short old, new; 223 224 spin_lock_irqsave(&chip->reg_lock, flags); 215 225 old = inw(chip->port + reg); 216 226 new = (old & ~mask) | value; 217 227 change = old != new; 218 228 if (change) 219 220 229 outw(new, chip->port + reg); 230 spin_unlock_irqrestore(&chip->reg_lock, flags); 221 231 return change; 222 232 } 223 233 224 static void snd_fm801_codec_write( ac97_t*ac97,234 static void snd_fm801_codec_write(struct snd_ac97 *ac97, 225 235 unsigned short reg, 226 236 unsigned short val) 227 237 { 228 fm801_t*chip = ac97->private_data;238 struct fm801 *chip = ac97->private_data; 229 239 int idx; 230 240 … … 233 243 */ 234 244 for (idx = 0; idx < 100; idx++) { 235 if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))245 if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY)) 236 246 goto ok1; 237 247 udelay(10); 238 248 } 239 snd_printk( "AC'97 interface is busy (1)\n");249 snd_printk(KERN_ERR "AC'97 interface is busy (1)\n"); 240 250 return; 241 251 … … 248 258 */ 249 259 for (idx = 0; idx < 1000; idx++) { 250 if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))260 if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY)) 251 261 return; 252 262 udelay(10); 253 263 } 254 snd_printk( "AC'97 interface #%d is busy (2)\n", ac97->num);255 } 256 257 static unsigned short snd_fm801_codec_read( ac97_t*ac97, unsigned short reg)258 { 259 fm801_t*chip = ac97->private_data;264 snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num); 265 } 266 267 static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short reg) 268 { 269 struct fm801 *chip = ac97->private_data; 260 270 int idx; 261 271 … … 264 274 */ 265 275 for (idx = 0; idx < 100; idx++) { 266 if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))276 if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY)) 267 277 goto ok1; 268 278 udelay(10); 269 279 } 270 snd_printk( "AC'97 interface is busy (1)\n");280 snd_printk(KERN_ERR "AC'97 interface is busy (1)\n"); 271 281 return 0; 272 282 273 283 ok1: 274 284 /* read command */ 275 outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | (1<<7), FM801_REG(chip, AC97_CMD)); 285 outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ, 286 FM801_REG(chip, AC97_CMD)); 276 287 for (idx = 0; idx < 100; idx++) { 277 if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))288 if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY)) 278 289 goto ok2; 279 290 udelay(10); 280 291 } 281 snd_printk( "AC'97 interface #%d is busy (2)\n", ac97->num);292 snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num); 282 293 return 0; 283 294 284 295 ok2: 285 296 for (idx = 0; idx < 1000; idx++) { 286 if (inw(FM801_REG(chip, AC97_CMD)) & (1<<8))297 if (inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_VALID) 287 298 goto ok3; 288 299 udelay(10); 289 300 } 290 snd_printk( "AC'97 interface #%d is not valid (2)\n", ac97->num);301 snd_printk(KERN_ERR "AC'97 interface #%d is not valid (2)\n", ac97->num); 291 302 return 0; 292 303 … … 301 312 }; 302 313 303 static s nd_pcm_hw_constraint_list_t hw_constraints_rates = {304 /* .count = */ARRAY_SIZE(rates),305 /* .list = */rates,306 /* .mask = */0,314 static struct snd_pcm_hw_constraint_list hw_constraints_rates = { 315 .count = ARRAY_SIZE(rates), 316 .list = rates, 317 .mask = 0, 307 318 }; 308 319 … … 311 322 }; 312 323 313 #define CHANNELS sizeof(channels) / sizeof(channels[0]) 314 315 static snd_pcm_hw_constraint_list_t hw_constraints_channels = { 316 /* .count = */CHANNELS, 317 /* .list = */channels, 318 /* .mask = */0, 324 static struct snd_pcm_hw_constraint_list hw_constraints_channels = { 325 .count = ARRAY_SIZE(channels), 326 .list = channels, 327 .mask = 0, 319 328 }; 320 329 … … 338 347 */ 339 348 340 static int snd_fm801_playback_trigger(s nd_pcm_substream_t *substream,349 static int snd_fm801_playback_trigger(struct snd_pcm_substream *substream, 341 350 int cmd) 342 351 { 343 fm801_t*chip = snd_pcm_substream_chip(substream);352 struct fm801 *chip = snd_pcm_substream_chip(substream); 344 353 345 354 spin_lock(&chip->reg_lock); … … 356 365 break; 357 366 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 367 case SNDRV_PCM_TRIGGER_SUSPEND: 358 368 chip->ply_ctrl |= FM801_PAUSE; 359 369 break; 360 370 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 371 case SNDRV_PCM_TRIGGER_RESUME: 361 372 chip->ply_ctrl &= ~FM801_PAUSE; 362 373 break; … … 371 382 } 372 383 373 static int snd_fm801_capture_trigger(s nd_pcm_substream_t *substream,384 static int snd_fm801_capture_trigger(struct snd_pcm_substream *substream, 374 385 int cmd) 375 386 { 376 fm801_t*chip = snd_pcm_substream_chip(substream);387 struct fm801 *chip = snd_pcm_substream_chip(substream); 377 388 378 389 spin_lock(&chip->reg_lock); … … 389 400 break; 390 401 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 402 case SNDRV_PCM_TRIGGER_SUSPEND: 391 403 chip->cap_ctrl |= FM801_PAUSE; 392 404 break; 393 405 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 406 case SNDRV_PCM_TRIGGER_RESUME: 394 407 chip->cap_ctrl &= ~FM801_PAUSE; 395 408 break; … … 404 417 } 405 418 406 static int snd_fm801_hw_params(s nd_pcm_substream_t *substream,407 s nd_pcm_hw_params_t *hw_params)419 static int snd_fm801_hw_params(struct snd_pcm_substream *substream, 420 struct snd_pcm_hw_params *hw_params) 408 421 { 409 422 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); 410 423 } 411 424 412 static int snd_fm801_hw_free(s nd_pcm_substream_t *substream)425 static int snd_fm801_hw_free(struct snd_pcm_substream *substream) 413 426 { 414 427 return snd_pcm_lib_free_pages(substream); 415 428 } 416 429 417 static int snd_fm801_playback_prepare(s nd_pcm_substream_t *substream)418 { 419 fm801_t*chip = snd_pcm_substream_chip(substream);420 s nd_pcm_runtime_t*runtime = substream->runtime;430 static int snd_fm801_playback_prepare(struct snd_pcm_substream *substream) 431 { 432 struct fm801 *chip = snd_pcm_substream_chip(substream); 433 struct snd_pcm_runtime *runtime = substream->runtime; 421 434 422 435 chip->ply_size = snd_pcm_lib_buffer_bytes(substream); 423 424 436 chip->ply_count = snd_pcm_lib_period_bytes(substream); 437 spin_lock_irq(&chip->reg_lock); 425 438 chip->ply_ctrl &= ~(FM801_START | FM801_16BIT | 426 439 FM801_STEREO | FM801_RATE_MASK | … … 442 455 chip->ply_pos = 0; 443 456 outl(chip->ply_buffer, FM801_REG(chip, PLY_BUF1)); 444 445 446 return 0; 447 } 448 449 static int snd_fm801_capture_prepare(s nd_pcm_substream_t *substream)450 { 451 fm801_t*chip = snd_pcm_substream_chip(substream);452 s nd_pcm_runtime_t*runtime = substream->runtime;457 outl(chip->ply_buffer + (chip->ply_count % chip->ply_size), FM801_REG(chip, PLY_BUF2)); 458 spin_unlock_irq(&chip->reg_lock); 459 return 0; 460 } 461 462 static int snd_fm801_capture_prepare(struct snd_pcm_substream *substream) 463 { 464 struct fm801 *chip = snd_pcm_substream_chip(substream); 465 struct snd_pcm_runtime *runtime = substream->runtime; 453 466 454 467 chip->cap_size = snd_pcm_lib_buffer_bytes(substream); 455 456 468 chip->cap_count = snd_pcm_lib_period_bytes(substream); 469 spin_lock_irq(&chip->reg_lock); 457 470 chip->cap_ctrl &= ~(FM801_START | FM801_16BIT | 458 471 FM801_STEREO | FM801_RATE_MASK); … … 468 481 chip->cap_pos = 0; 469 482 outl(chip->cap_buffer, FM801_REG(chip, CAP_BUF1)); 470 471 472 return 0; 473 } 474 475 static snd_pcm_uframes_t snd_fm801_playback_pointer(s nd_pcm_substream_t *substream)476 { 477 fm801_t*chip = snd_pcm_substream_chip(substream);483 outl(chip->cap_buffer + (chip->cap_count % chip->cap_size), FM801_REG(chip, CAP_BUF2)); 484 spin_unlock_irq(&chip->reg_lock); 485 return 0; 486 } 487 488 static snd_pcm_uframes_t snd_fm801_playback_pointer(struct snd_pcm_substream *substream) 489 { 490 struct fm801 *chip = snd_pcm_substream_chip(substream); 478 491 size_t ptr; 479 492 … … 490 503 } 491 504 492 static snd_pcm_uframes_t snd_fm801_capture_pointer(s nd_pcm_substream_t *substream)493 { 494 fm801_t*chip = snd_pcm_substream_chip(substream);505 static snd_pcm_uframes_t snd_fm801_capture_pointer(struct snd_pcm_substream *substream) 506 { 507 struct fm801 *chip = snd_pcm_substream_chip(substream); 495 508 size_t ptr; 496 509 … … 507 520 } 508 521 509 static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id , struct pt_regs *regs)510 { 511 fm801_t*chip = dev_id;522 static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id) 523 { 524 struct fm801 *chip = dev_id; 512 525 unsigned short status; 513 526 unsigned int tmp; … … 516 529 status &= FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU|FM801_IRQ_VOLUME; 517 530 if (! status) 518 return IRQ_NONE; 519 531 return IRQ_NONE; 520 532 /* ack first */ 521 533 outw(status, FM801_REG(chip, IRQ_STATUS)); … … 549 561 } 550 562 if (chip->rmidi && (status & FM801_IRQ_MPU)) 551 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data , regs);563 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data); 552 564 if (status & FM801_IRQ_VOLUME) 553 565 ;/* TODO */ 554 #ifdef TARGET_OS2555 eoi_irq(irq);556 #endif //TARGET_OS2557 566 558 567 return IRQ_HANDLED; 559 568 } 560 569 561 static s nd_pcm_hardware_tsnd_fm801_playback =562 { 563 /*.info = */(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |570 static struct snd_pcm_hardware snd_fm801_playback = 571 { 572 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 564 573 SNDRV_PCM_INFO_BLOCK_TRANSFER | 565 SNDRV_PCM_INFO_PAUSE | 574 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME | 566 575 SNDRV_PCM_INFO_MMAP_VALID), 567 /*.formats = */SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,568 /*.rates = */SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,569 /*.rate_min = */5500,570 /*.rate_max = */48000,571 /*.channels_min = */1,572 /*.channels_max = */2,573 /*.buffer_bytes_max = */(128*1024),574 /*.period_bytes_min = */64,575 /*.period_bytes_max = */(128*1024),576 /*.periods_min = */1,577 /*.periods_max = */1024,578 /*.fifo_size = */0,576 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 577 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000, 578 .rate_min = 5500, 579 .rate_max = 48000, 580 .channels_min = 1, 581 .channels_max = 2, 582 .buffer_bytes_max = (128*1024), 583 .period_bytes_min = 64, 584 .period_bytes_max = (128*1024), 585 .periods_min = 1, 586 .periods_max = 1024, 587 .fifo_size = 0, 579 588 }; 580 589 581 static s nd_pcm_hardware_tsnd_fm801_capture =582 { 583 /*.info = */(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |590 static struct snd_pcm_hardware snd_fm801_capture = 591 { 592 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 584 593 SNDRV_PCM_INFO_BLOCK_TRANSFER | 585 SNDRV_PCM_INFO_PAUSE | 594 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME | 586 595 SNDRV_PCM_INFO_MMAP_VALID), 587 /*.formats = */SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,588 /*.rates = */SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,589 /*.rate_min = */5500,590 /*.rate_max = */48000,591 /*.channels_min = */1,592 /*.channels_max = */2,593 /*.buffer_bytes_max = */(128*1024),594 /*.period_bytes_min = */64,595 /*.period_bytes_max = */(128*1024),596 /*.periods_min = */1,597 /*.periods_max = */1024,598 /*.fifo_size = */0,596 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 597 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000, 598 .rate_min = 5500, 599 .rate_max = 48000, 600 .channels_min = 1, 601 .channels_max = 2, 602 .buffer_bytes_max = (128*1024), 603 .period_bytes_min = 64, 604 .period_bytes_max = (128*1024), 605 .periods_min = 1, 606 .periods_max = 1024, 607 .fifo_size = 0, 599 608 }; 600 609 601 static int snd_fm801_playback_open(s nd_pcm_substream_t *substream)602 { 603 fm801_t*chip = snd_pcm_substream_chip(substream);604 s nd_pcm_runtime_t*runtime = substream->runtime;610 static int snd_fm801_playback_open(struct snd_pcm_substream *substream) 611 { 612 struct fm801 *chip = snd_pcm_substream_chip(substream); 613 struct snd_pcm_runtime *runtime = substream->runtime; 605 614 int err; 606 615 607 616 chip->playback_substream = substream; 608 617 runtime->hw = snd_fm801_playback; 609 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); 618 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 619 &hw_constraints_rates); 610 620 if (chip->multichannel) { 611 621 runtime->hw.channels_max = 6; 612 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels); 622 snd_pcm_hw_constraint_list(runtime, 0, 623 SNDRV_PCM_HW_PARAM_CHANNELS, 624 &hw_constraints_channels); 613 625 } 614 626 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) … … 617 629 } 618 630 619 static int snd_fm801_capture_open(s nd_pcm_substream_t *substream)620 { 621 fm801_t*chip = snd_pcm_substream_chip(substream);622 s nd_pcm_runtime_t*runtime = substream->runtime;631 static int snd_fm801_capture_open(struct snd_pcm_substream *substream) 632 { 633 struct fm801 *chip = snd_pcm_substream_chip(substream); 634 struct snd_pcm_runtime *runtime = substream->runtime; 623 635 int err; 624 636 625 637 chip->capture_substream = substream; 626 638 runtime->hw = snd_fm801_capture; 627 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); 639 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 640 &hw_constraints_rates); 628 641 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 629 642 return err; … … 631 644 } 632 645 633 static int snd_fm801_playback_close(s nd_pcm_substream_t *substream)634 { 635 fm801_t*chip = snd_pcm_substream_chip(substream);646 static int snd_fm801_playback_close(struct snd_pcm_substream *substream) 647 { 648 struct fm801 *chip = snd_pcm_substream_chip(substream); 636 649 637 650 chip->playback_substream = NULL; … … 639 652 } 640 653 641 static int snd_fm801_capture_close(s nd_pcm_substream_t *substream)642 { 643 fm801_t*chip = snd_pcm_substream_chip(substream);654 static int snd_fm801_capture_close(struct snd_pcm_substream *substream) 655 { 656 struct fm801 *chip = snd_pcm_substream_chip(substream); 644 657 645 658 chip->capture_substream = NULL; … … 647 660 } 648 661 649 static snd_pcm_ops_t snd_fm801_playback_ops = { 650 /*.open = */ snd_fm801_playback_open, 651 /*.close = */ snd_fm801_playback_close, 652 /*.ioctl = */ snd_pcm_lib_ioctl, 653 /*.hw_params = */ snd_fm801_hw_params, 654 /*.hw_free = */ snd_fm801_hw_free, 655 /*.prepare = */ snd_fm801_playback_prepare, 656 /*.trigger = */ snd_fm801_playback_trigger, 657 /*.pointer = */ snd_fm801_playback_pointer, 658 0,0,0,0 662 static struct snd_pcm_ops snd_fm801_playback_ops = { 663 .open = snd_fm801_playback_open, 664 .close = snd_fm801_playback_close, 665 .ioctl = snd_pcm_lib_ioctl, 666 .hw_params = snd_fm801_hw_params, 667 .hw_free = snd_fm801_hw_free, 668 .prepare = snd_fm801_playback_prepare, 669 .trigger = snd_fm801_playback_trigger, 670 .pointer = snd_fm801_playback_pointer, 659 671 }; 660 672 661 static snd_pcm_ops_t snd_fm801_capture_ops = { 662 /*.open = */ snd_fm801_capture_open, 663 /*.close = */ snd_fm801_capture_close, 664 /*.ioctl = */ snd_pcm_lib_ioctl, 665 /*.hw_params = */ snd_fm801_hw_params, 666 /*.hw_free = */ snd_fm801_hw_free, 667 /*.prepare = */ snd_fm801_capture_prepare, 668 /*.trigger = */ snd_fm801_capture_trigger, 669 /*.pointer = */ snd_fm801_capture_pointer, 670 0,0,0,0 673 static struct snd_pcm_ops snd_fm801_capture_ops = { 674 .open = snd_fm801_capture_open, 675 .close = snd_fm801_capture_close, 676 .ioctl = snd_pcm_lib_ioctl, 677 .hw_params = snd_fm801_hw_params, 678 .hw_free = snd_fm801_hw_free, 679 .prepare = snd_fm801_capture_prepare, 680 .trigger = snd_fm801_capture_trigger, 681 .pointer = snd_fm801_capture_pointer, 671 682 }; 672 683 673 static void snd_fm801_pcm_free(snd_pcm_t *pcm) 674 { 675 fm801_t *chip = pcm->private_data; 676 chip->pcm = NULL; 677 snd_pcm_lib_preallocate_free_for_all(pcm); 678 } 679 680 static int __devinit snd_fm801_pcm(fm801_t *chip, int device, snd_pcm_t ** rpcm) 681 { 682 snd_pcm_t *pcm; 684 static int __devinit snd_fm801_pcm(struct fm801 *chip, int device, struct snd_pcm ** rpcm) 685 { 686 struct snd_pcm *pcm; 683 687 int err; 684 688 … … 692 696 693 697 pcm->private_data = chip; 694 pcm->private_free = snd_fm801_pcm_free;695 698 pcm->info_flags = 0; 696 699 strcpy(pcm->name, "FM801"); … … 717 720 #define TEA_256PCS_BUS_CLOCK 3 718 721 719 static void snd_fm801_tea575x_256pcs_write( tea575x_t*tea, unsigned int val)720 { 721 fm801_t*chip = tea->private_data;722 static void snd_fm801_tea575x_256pcs_write(struct snd_tea575x *tea, unsigned int val) 723 { 724 struct fm801 *chip = tea->private_data; 722 725 unsigned short reg; 723 726 int i = 25; … … 761 764 } 762 765 763 static unsigned int snd_fm801_tea575x_256pcs_read( tea575x_t*tea)764 { 765 fm801_t*chip = tea->private_data;766 static unsigned int snd_fm801_tea575x_256pcs_read(struct snd_tea575x *tea) 767 { 768 struct fm801 *chip = tea->private_data; 766 769 unsigned short reg; 767 770 unsigned int val = 0; … … 805 808 #define TEA_256PCPR_WRITE_ENABLE 2 /* inverted */ 806 809 807 static void snd_fm801_tea575x_256pcpr_write( tea575x_t*tea, unsigned int val)808 { 809 fm801_t*chip = tea->private_data;810 static void snd_fm801_tea575x_256pcpr_write(struct snd_tea575x *tea, unsigned int val) 811 { 812 struct fm801 *chip = tea->private_data; 810 813 unsigned short reg; 811 814 int i = 25; … … 849 852 } 850 853 851 static unsigned int snd_fm801_tea575x_256pcpr_read( tea575x_t*tea)852 { 853 fm801_t*chip = tea->private_data;854 static unsigned int snd_fm801_tea575x_256pcpr_read(struct snd_tea575x *tea) 855 { 856 struct fm801 *chip = tea->private_data; 854 857 unsigned short reg; 855 858 unsigned int val = 0; … … 893 896 #define TEA_64PCR_DATA 2 894 897 895 static void snd_fm801_tea575x_64pcr_write( tea575x_t*tea, unsigned int val)896 { 897 fm801_t*chip = tea->private_data;898 static void snd_fm801_tea575x_64pcr_write(struct snd_tea575x *tea, unsigned int val) 899 { 900 struct fm801 *chip = tea->private_data; 898 901 unsigned short reg; 899 902 int i = 25; … … 937 940 } 938 941 939 static unsigned int snd_fm801_tea575x_64pcr_read( tea575x_t*tea)940 { 941 fm801_t*chip = tea->private_data;942 static unsigned int snd_fm801_tea575x_64pcr_read(struct snd_tea575x *tea) 943 { 944 struct fm801 *chip = tea->private_data; 942 945 unsigned short reg; 943 946 unsigned int val = 0; … … 976 979 } 977 980 981 static void snd_fm801_tea575x_64pcr_mute(struct snd_tea575x *tea, 982 unsigned int mute) 983 { 984 struct fm801 *chip = tea->private_data; 985 unsigned short reg; 986 987 spin_lock_irq(&chip->reg_lock); 988 989 reg = inw(FM801_REG(chip, GPIO_CTRL)); 990 if (mute) 991 /* 0xf800 (mute) */ 992 reg &= ~FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE); 993 else 994 /* 0xf802 (unmute) */ 995 reg |= FM801_GPIO_GP(TEA_64PCR_WRITE_ENABLE); 996 outw(reg, FM801_REG(chip, GPIO_CTRL)); 997 udelay(1); 998 999 spin_unlock_irq(&chip->reg_lock); 1000 } 1001 978 1002 static struct snd_tea575x_ops snd_fm801_tea_ops[3] = { 979 1003 { … … 991 1015 .write = snd_fm801_tea575x_64pcr_write, 992 1016 .read = snd_fm801_tea575x_64pcr_read, 1017 .mute = snd_fm801_tea575x_64pcr_mute, 993 1018 } 994 1019 }; … … 1000 1025 1001 1026 #define FM801_SINGLE(xname, reg, shift, mask, invert) \ 1002 { SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, xname, 0,0,0, snd_fm801_info_single, \ 1003 snd_fm801_get_single, snd_fm801_put_single, \ 1004 0, reg | (shift << 8) | (mask << 16) | (invert << 24) } 1005 1006 static int snd_fm801_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 1027 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_fm801_info_single, \ 1028 .get = snd_fm801_get_single, .put = snd_fm801_put_single, \ 1029 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } 1030 1031 static int snd_fm801_info_single(struct snd_kcontrol *kcontrol, 1032 struct snd_ctl_elem_info *uinfo) 1007 1033 { 1008 1034 int mask = (kcontrol->private_value >> 16) & 0xff; … … 1015 1041 } 1016 1042 1017 static int snd_fm801_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1018 { 1019 fm801_t *chip = snd_kcontrol_chip(kcontrol); 1043 static int snd_fm801_get_single(struct snd_kcontrol *kcontrol, 1044 struct snd_ctl_elem_value *ucontrol) 1045 { 1046 struct fm801 *chip = snd_kcontrol_chip(kcontrol); 1020 1047 int reg = kcontrol->private_value & 0xff; 1021 1048 int shift = (kcontrol->private_value >> 8) & 0xff; … … 1029 1056 } 1030 1057 1031 static int snd_fm801_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1032 { 1033 fm801_t *chip = snd_kcontrol_chip(kcontrol); 1058 static int snd_fm801_put_single(struct snd_kcontrol *kcontrol, 1059 struct snd_ctl_elem_value *ucontrol) 1060 { 1061 struct fm801 *chip = snd_kcontrol_chip(kcontrol); 1034 1062 int reg = kcontrol->private_value & 0xff; 1035 1063 int shift = (kcontrol->private_value >> 8) & 0xff; … … 1045 1073 1046 1074 #define FM801_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \ 1047 { SNDRV_CTL_ELEM_IFACE_MIXER, 0,0, xname, 0,0,0, snd_fm801_info_double, \ 1048 snd_fm801_get_double, snd_fm801_put_double, \ 1049 0, reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) } 1050 1051 static int snd_fm801_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 1075 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_fm801_info_double, \ 1076 .get = snd_fm801_get_double, .put = snd_fm801_put_double, \ 1077 .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) } 1078 #define FM801_DOUBLE_TLV(xname, reg, shift_left, shift_right, mask, invert, xtlv) \ 1079 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 1080 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ 1081 .name = xname, .info = snd_fm801_info_double, \ 1082 .get = snd_fm801_get_double, .put = snd_fm801_put_double, \ 1083 .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24), \ 1084 .tlv = { .p = (xtlv) } } 1085 1086 static int snd_fm801_info_double(struct snd_kcontrol *kcontrol, 1087 struct snd_ctl_elem_info *uinfo) 1052 1088 { 1053 1089 int mask = (kcontrol->private_value >> 16) & 0xff; … … 1060 1096 } 1061 1097 1062 static int snd_fm801_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1063 { 1064 fm801_t *chip = snd_kcontrol_chip(kcontrol); 1098 static int snd_fm801_get_double(struct snd_kcontrol *kcontrol, 1099 struct snd_ctl_elem_value *ucontrol) 1100 { 1101 struct fm801 *chip = snd_kcontrol_chip(kcontrol); 1065 1102 int reg = kcontrol->private_value & 0xff; 1066 1103 int shift_left = (kcontrol->private_value >> 8) & 0x0f; … … 1080 1117 } 1081 1118 1082 static int snd_fm801_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1083 { 1084 fm801_t *chip = snd_kcontrol_chip(kcontrol); 1119 static int snd_fm801_put_double(struct snd_kcontrol *kcontrol, 1120 struct snd_ctl_elem_value *ucontrol) 1121 { 1122 struct fm801 *chip = snd_kcontrol_chip(kcontrol); 1085 1123 int reg = kcontrol->private_value & 0xff; 1086 1124 int shift_left = (kcontrol->private_value >> 8) & 0x0f; … … 1101 1139 } 1102 1140 1103 static int snd_fm801_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 1141 static int snd_fm801_info_mux(struct snd_kcontrol *kcontrol, 1142 struct snd_ctl_elem_info *uinfo) 1104 1143 { 1105 1144 static char *texts[5] = { … … 1116 1155 } 1117 1156 1118 static int snd_fm801_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1119 { 1120 fm801_t *chip = snd_kcontrol_chip(kcontrol); 1157 static int snd_fm801_get_mux(struct snd_kcontrol *kcontrol, 1158 struct snd_ctl_elem_value *ucontrol) 1159 { 1160 struct fm801 *chip = snd_kcontrol_chip(kcontrol); 1121 1161 unsigned short val; 1122 1162 … … 1128 1168 } 1129 1169 1130 static int snd_fm801_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1131 { 1132 fm801_t *chip = snd_kcontrol_chip(kcontrol); 1170 static int snd_fm801_put_mux(struct snd_kcontrol *kcontrol, 1171 struct snd_ctl_elem_value *ucontrol) 1172 { 1173 struct fm801 *chip = snd_kcontrol_chip(kcontrol); 1133 1174 unsigned short val; 1134 1175 … … 1138 1179 } 1139 1180 1140 #define FM801_CONTROLS (sizeof(snd_fm801_controls)/sizeof(snd_kcontrol_new_t)) 1141 1142 static snd_kcontrol_new_t snd_fm801_controls[] __devinitdata = { 1143 FM801_DOUBLE("Wave Playback Volume", FM801_PCM_VOL, 0, 8, 31, 1), 1181 static const DECLARE_TLV_DB_SCALE(db_scale_dsp, -3450, 150, 0); 1182 1183 #define FM801_CONTROLS ARRAY_SIZE(snd_fm801_controls) 1184 1185 static struct snd_kcontrol_new snd_fm801_controls[] __devinitdata = { 1186 FM801_DOUBLE_TLV("Wave Playback Volume", FM801_PCM_VOL, 0, 8, 31, 1, 1187 db_scale_dsp), 1144 1188 FM801_SINGLE("Wave Playback Switch", FM801_PCM_VOL, 15, 1, 1), 1145 FM801_DOUBLE("I2S Playback Volume", FM801_I2S_VOL, 0, 8, 31, 1), 1189 FM801_DOUBLE_TLV("I2S Playback Volume", FM801_I2S_VOL, 0, 8, 31, 1, 1190 db_scale_dsp), 1146 1191 FM801_SINGLE("I2S Playback Switch", FM801_I2S_VOL, 15, 1, 1), 1147 FM801_DOUBLE("FM Playback Volume", FM801_FM_VOL, 0, 8, 31, 1), 1192 FM801_DOUBLE_TLV("FM Playback Volume", FM801_FM_VOL, 0, 8, 31, 1, 1193 db_scale_dsp), 1148 1194 FM801_SINGLE("FM Playback Switch", FM801_FM_VOL, 15, 1, 1), 1149 1195 { 1150 SNDRV_CTL_ELEM_IFACE_MIXER, 0,0,1151 "Digital Capture Source",0,0,0,1152 snd_fm801_info_mux,1153 snd_fm801_get_mux,1154 snd_fm801_put_mux,01196 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1197 .name = "Digital Capture Source", 1198 .info = snd_fm801_info_mux, 1199 .get = snd_fm801_get_mux, 1200 .put = snd_fm801_put_mux, 1155 1201 } 1156 1202 }; 1157 1203 1158 #define FM801_CONTROLS_MULTI (sizeof(snd_fm801_controls_multi)/sizeof(snd_kcontrol_new_t))1159 1160 static s nd_kcontrol_new_tsnd_fm801_controls_multi[] __devinitdata = {1204 #define FM801_CONTROLS_MULTI ARRAY_SIZE(snd_fm801_controls_multi) 1205 1206 static struct snd_kcontrol_new snd_fm801_controls_multi[] __devinitdata = { 1161 1207 FM801_SINGLE("AC97 2ch->4ch Copy Switch", FM801_CODEC_CTRL, 7, 1, 0), 1162 1208 FM801_SINGLE("AC97 18-bit Switch", FM801_CODEC_CTRL, 10, 1, 0), 1163 FM801_SINGLE( "IEC958 Capture Switch", FM801_I2S_MODE, 8, 1, 0),1164 FM801_SINGLE( "IEC958 Raw Data Playback Switch", FM801_I2S_MODE, 9, 1, 0),1165 FM801_SINGLE( "IEC958 Raw Data Capture Switch", FM801_I2S_MODE, 10, 1, 0),1166 FM801_SINGLE( "IEC958 Playback Switch", FM801_GEN_CTRL, 2, 1, 0),1209 FM801_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), FM801_I2S_MODE, 8, 1, 0), 1210 FM801_SINGLE(SNDRV_CTL_NAME_IEC958("Raw Data ",PLAYBACK,SWITCH), FM801_I2S_MODE, 9, 1, 0), 1211 FM801_SINGLE(SNDRV_CTL_NAME_IEC958("Raw Data ",CAPTURE,SWITCH), FM801_I2S_MODE, 10, 1, 0), 1212 FM801_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), FM801_GEN_CTRL, 2, 1, 0), 1167 1213 }; 1168 1214 1169 static void snd_fm801_mixer_free_ac97_bus( ac97_bus_t*bus)1170 { 1171 fm801_t*chip = bus->private_data;1215 static void snd_fm801_mixer_free_ac97_bus(struct snd_ac97_bus *bus) 1216 { 1217 struct fm801 *chip = bus->private_data; 1172 1218 chip->ac97_bus = NULL; 1173 1219 } 1174 1220 1175 static void snd_fm801_mixer_free_ac97( ac97_t*ac97)1176 { 1177 fm801_t*chip = ac97->private_data;1221 static void snd_fm801_mixer_free_ac97(struct snd_ac97 *ac97) 1222 { 1223 struct fm801 *chip = ac97->private_data; 1178 1224 if (ac97->num == 0) { 1179 1225 chip->ac97 = NULL; … … 1183 1229 } 1184 1230 1185 static int __devinit snd_fm801_mixer( fm801_t*chip)1186 { 1187 ac97_template_tac97;1231 static int __devinit snd_fm801_mixer(struct fm801 *chip) 1232 { 1233 struct snd_ac97_template ac97; 1188 1234 unsigned int i; 1189 1235 int err; 1190 static ac97_bus_ops_tops = {1191 0, 0,snd_fm801_codec_write,1192 snd_fm801_codec_read, 0,0 1236 static struct snd_ac97_bus_ops ops = { 1237 .write = snd_fm801_codec_write, 1238 .read = snd_fm801_codec_read, 1193 1239 }; 1194 1240 … … 1221 1267 */ 1222 1268 1223 static int snd_fm801_free(fm801_t *chip) 1269 static int wait_for_codec(struct fm801 *chip, unsigned int codec_id, 1270 unsigned short reg, unsigned long waits) 1271 { 1272 unsigned long timeout = jiffies + waits; 1273 1274 outw(FM801_AC97_READ | (codec_id << FM801_AC97_ADDR_SHIFT) | reg, 1275 FM801_REG(chip, AC97_CMD)); 1276 udelay(5); 1277 do { 1278 if ((inw(FM801_REG(chip, AC97_CMD)) & (FM801_AC97_VALID|FM801_AC97_BUSY)) 1279 == FM801_AC97_VALID) 1280 return 0; 1281 schedule_timeout_uninterruptible(1); 1282 } while (time_after(timeout, jiffies)); 1283 return -EIO; 1284 } 1285 1286 static int snd_fm801_chip_init(struct fm801 *chip, int resume) 1287 { 1288 int id; 1289 unsigned short cmdw; 1290 1291 if (chip->tea575x_tuner & 0x0010) 1292 goto __ac97_ok; 1293 1294 /* codec cold reset + AC'97 warm reset */ 1295 outw((1<<5) | (1<<6), FM801_REG(chip, CODEC_CTRL)); 1296 inw(FM801_REG(chip, CODEC_CTRL)); /* flush posting data */ 1297 udelay(100); 1298 outw(0, FM801_REG(chip, CODEC_CTRL)); 1299 1300 if (wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)) < 0) { 1301 snd_printk(KERN_ERR "Primary AC'97 codec not found\n"); 1302 if (! resume) 1303 return -EIO; 1304 } 1305 1306 if (chip->multichannel) { 1307 if (chip->secondary_addr) { 1308 wait_for_codec(chip, chip->secondary_addr, 1309 AC97_VENDOR_ID1, msecs_to_jiffies(50)); 1310 } else { 1311 /* my card has the secondary codec */ 1312 /* at address #3, so the loop is inverted */ 1313 for (id = 3; id > 0; id--) { 1314 if (! wait_for_codec(chip, id, AC97_VENDOR_ID1, 1315 msecs_to_jiffies(50))) { 1316 cmdw = inw(FM801_REG(chip, AC97_DATA)); 1317 if (cmdw != 0xffff && cmdw != 0) { 1318 chip->secondary = 1; 1319 chip->secondary_addr = id; 1320 break; 1321 } 1322 } 1323 } 1324 } 1325 1326 /* the recovery phase, it seems that probing for non-existing codec might */ 1327 /* cause timeout problems */ 1328 wait_for_codec(chip, 0, AC97_VENDOR_ID1, msecs_to_jiffies(750)); 1329 } 1330 1331 __ac97_ok: 1332 1333 /* init volume */ 1334 outw(0x0808, FM801_REG(chip, PCM_VOL)); 1335 outw(0x9f1f, FM801_REG(chip, FM_VOL)); 1336 outw(0x8808, FM801_REG(chip, I2S_VOL)); 1337 1338 /* I2S control - I2S mode */ 1339 outw(0x0003, FM801_REG(chip, I2S_MODE)); 1340 1341 /* interrupt setup */ 1342 cmdw = inw(FM801_REG(chip, IRQ_MASK)); 1343 if (chip->irq < 0) 1344 cmdw |= 0x00c3; /* mask everything, no PCM nor MPU */ 1345 else 1346 cmdw &= ~0x0083; /* unmask MPU, PLAYBACK & CAPTURE */ 1347 outw(cmdw, FM801_REG(chip, IRQ_MASK)); 1348 1349 /* interrupt clear */ 1350 outw(FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU, FM801_REG(chip, IRQ_STATUS)); 1351 1352 return 0; 1353 } 1354 1355 1356 static int snd_fm801_free(struct fm801 *chip) 1224 1357 { 1225 1358 unsigned short cmdw; … … 1238 1371 #endif 1239 1372 if (chip->irq >= 0) 1240 free_irq(chip->irq, (void *)chip);1373 free_irq(chip->irq, chip); 1241 1374 pci_release_regions(chip->pci); 1242 1375 pci_disable_device(chip->pci); … … 1246 1379 } 1247 1380 1248 static int snd_fm801_dev_free(s nd_device_t*device)1249 { 1250 fm801_t*chip = device->device_data;1381 static int snd_fm801_dev_free(struct snd_device *device) 1382 { 1383 struct fm801 *chip = device->device_data; 1251 1384 return snd_fm801_free(chip); 1252 1385 } 1253 1386 1254 static int __devinit snd_fm801_create(s nd_card_t *card,1387 static int __devinit snd_fm801_create(struct snd_card *card, 1255 1388 struct pci_dev * pci, 1256 1389 int tea575x_tuner, 1257 fm801_t ** rchip) 1258 { 1259 fm801_t *chip; 1260 unsigned char rev, id; 1261 unsigned short cmdw; 1262 unsigned long timeout; 1390 struct fm801 ** rchip) 1391 { 1392 struct fm801 *chip; 1263 1393 int err; 1264 static s nd_device_ops_tops = {1265 snd_fm801_dev_free, 0,0,01394 static struct snd_device_ops ops = { 1395 .dev_free = snd_fm801_dev_free, 1266 1396 }; 1267 1397 … … 1269 1399 if ((err = pci_enable_device(pci)) < 0) 1270 1400 return err; 1271 chip = k calloc(1,sizeof(*chip), GFP_KERNEL);1401 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1272 1402 if (chip == NULL) { 1273 1403 pci_disable_device(pci); … … 1278 1408 chip->pci = pci; 1279 1409 chip->irq = -1; 1410 chip->tea575x_tuner = tea575x_tuner; 1280 1411 if ((err = pci_request_regions(pci, "FM801")) < 0) { 1281 1412 kfree(chip); … … 1284 1415 } 1285 1416 chip->port = pci_resource_start(pci, 0); 1286 if (request_irq(pci->irq, snd_fm801_interrupt, SA_INTERRUPT|SA_SHIRQ, "FM801", (void *)chip)) { 1287 snd_printk("unable to grab IRQ %d\n", chip->irq); 1288 snd_fm801_free(chip); 1289 return -EBUSY; 1290 } 1291 chip->irq = pci->irq; 1292 pci_set_master(pci); 1293 1294 pci_read_config_byte(pci, PCI_REVISION_ID, &rev); 1295 if (rev >= 0xb1) /* FM801-AU */ 1417 if ((tea575x_tuner & 0x0010) == 0) { 1418 if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED, 1419 "FM801", chip)) { 1420 snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq); 1421 snd_fm801_free(chip); 1422 return -EBUSY; 1423 } 1424 chip->irq = pci->irq; 1425 pci_set_master(pci); 1426 } 1427 1428 #ifndef TARGET_OS2 1429 if (pci->revision >= 0xb1) /* FM801-AU */ 1430 #else 1431 if (snd_pci_revision(pci) >= 0xb1) /* FM801-AU */ 1432 #endif 1296 1433 chip->multichannel = 1; 1297 1434 1298 /* codec cold reset + AC'97 warm reset */ 1299 outw((1<<5)|(1<<6), FM801_REG(chip, CODEC_CTRL)); 1300 inw(FM801_REG(chip, CODEC_CTRL)); /* flush posting data */ 1301 udelay(100); 1302 outw(0, FM801_REG(chip, CODEC_CTRL)); 1303 1304 timeout = (jiffies + (3 * HZ) / 4) + 1; /* min 750ms */ 1305 1306 outw((1<<7) | (0 << FM801_AC97_ADDR_SHIFT), FM801_REG(chip, AC97_CMD)); 1307 udelay(5); 1308 do { 1309 if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8)) 1310 goto __ac97_secondary; 1311 set_current_state(TASK_UNINTERRUPTIBLE); 1312 schedule_timeout(1); 1313 } while (time_after(timeout, jiffies)); 1314 snd_printk("Primary AC'97 codec not found\n"); 1315 snd_fm801_free(chip); 1316 return -EIO; 1317 1318 __ac97_secondary: 1319 if (!chip->multichannel) /* lookup is not required */ 1320 goto __ac97_ok; 1321 for (id = 3; id > 0; id--) { /* my card has the secondary codec */ 1322 /* at address #3, so the loop is inverted */ 1323 1324 timeout = jiffies + HZ / 20; 1325 1326 outw((1<<7) | (id << FM801_AC97_ADDR_SHIFT) | AC97_VENDOR_ID1, FM801_REG(chip, AC97_CMD)); 1327 udelay(5); 1328 do { 1329 if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8)) { 1330 cmdw = inw(FM801_REG(chip, AC97_DATA)); 1331 if (cmdw != 0xffff && cmdw != 0) { 1332 chip->secondary = 1; 1333 chip->secondary_addr = id; 1334 goto __ac97_ok; 1335 } 1336 } 1337 set_current_state(TASK_UNINTERRUPTIBLE); 1338 schedule_timeout(1); 1339 } while (time_after(timeout, jiffies)); 1340 } 1341 1342 /* the recovery phase, it seems that probing for non-existing codec might */ 1343 /* cause timeout problems */ 1344 timeout = (jiffies + (3 * HZ) / 4) + 1; /* min 750ms */ 1345 1346 outw((1<<7) | (0 << FM801_AC97_ADDR_SHIFT), FM801_REG(chip, AC97_CMD)); 1347 udelay(5); 1348 do { 1349 if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8)) 1350 goto __ac97_ok; 1351 set_current_state(TASK_UNINTERRUPTIBLE); 1352 schedule_timeout(1); 1353 } while (time_after(timeout, jiffies)); 1354 snd_printk("Primary AC'97 codec not responding\n"); 1355 snd_fm801_free(chip); 1356 return -EIO; 1357 1358 __ac97_ok: 1359 1360 /* init volume */ 1361 outw(0x0808, FM801_REG(chip, PCM_VOL)); 1362 outw(0x9f1f, FM801_REG(chip, FM_VOL)); 1363 outw(0x8808, FM801_REG(chip, I2S_VOL)); 1364 1365 /* I2S control - I2S mode */ 1366 outw(0x0003, FM801_REG(chip, I2S_MODE)); 1367 1368 /* interrupt setup - unmask MPU, PLAYBACK & CAPTURE */ 1369 cmdw = inw(FM801_REG(chip, IRQ_MASK)); 1370 cmdw &= ~0x0083; 1371 outw(cmdw, FM801_REG(chip, IRQ_MASK)); 1372 1373 /* interrupt clear */ 1374 outw(FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU, FM801_REG(chip, IRQ_STATUS)); 1435 snd_fm801_chip_init(chip, 0); 1375 1436 1376 1437 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { … … 1382 1443 1383 1444 #ifdef TEA575X_RADIO 1384 if (tea575x_tuner > 0 && (tea575x_tuner & 0x ffff) < 4) {1445 if (tea575x_tuner > 0 && (tea575x_tuner & 0x000f) < 4) { 1385 1446 chip->tea.dev_nr = tea575x_tuner >> 16; 1386 1447 chip->tea.card = card; 1387 1448 chip->tea.freq_fixup = 10700; 1388 1449 chip->tea.private_data = chip; 1389 chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & 0x ffff) - 1];1450 chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & 0x000f) - 1]; 1390 1451 snd_tea575x_init(&chip->tea); 1391 1452 } … … 1400 1461 { 1401 1462 static int dev; 1402 s nd_card_t*card;1403 fm801_t*chip;1404 opl3_t*opl3;1463 struct snd_card *card; 1464 struct fm801 *chip; 1465 struct snd_opl3 *opl3; 1405 1466 int err; 1406 1467 … … 1419 1480 return err; 1420 1481 } 1482 card->private_data = chip; 1421 1483 1422 1484 strcpy(card->driver, "FM801"); … … 1426 1488 card->shortname, chip->port, chip->irq); 1427 1489 1490 if (tea575x_tuner[dev] & 0x0010) 1491 goto __fm801_tuner_only; 1492 1428 1493 if ((err = snd_fm801_pcm(chip, 0, NULL)) < 0) { 1429 1494 snd_card_free(card); … … 1434 1499 return err; 1435 1500 } 1436 1437 1501 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801, 1502 FM801_REG(chip, MPU401_DATA), 1438 1503 MPU401_INFO_INTEGRATED, 1439 1504 chip->irq, 0, &chip->rmidi)) < 0) { … … 1452 1517 } 1453 1518 1519 __fm801_tuner_only: 1454 1520 if ((err = snd_card_register(card)) < 0) { 1455 1521 snd_card_free(card); … … 1467 1533 } 1468 1534 1535 #ifdef CONFIG_PM 1536 static unsigned char saved_regs[] = { 1537 FM801_PCM_VOL, FM801_I2S_VOL, FM801_FM_VOL, FM801_REC_SRC, 1538 FM801_PLY_CTRL, FM801_PLY_COUNT, FM801_PLY_BUF1, FM801_PLY_BUF2, 1539 FM801_CAP_CTRL, FM801_CAP_COUNT, FM801_CAP_BUF1, FM801_CAP_BUF2, 1540 FM801_CODEC_CTRL, FM801_I2S_MODE, FM801_VOLUME, FM801_GEN_CTRL, 1541 }; 1542 1543 static int snd_fm801_suspend(struct pci_dev *pci, pm_message_t state) 1544 { 1545 struct snd_card *card = pci_get_drvdata(pci); 1546 struct fm801 *chip = card->private_data; 1547 int i; 1548 1549 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 1550 snd_pcm_suspend_all(chip->pcm); 1551 snd_ac97_suspend(chip->ac97); 1552 snd_ac97_suspend(chip->ac97_sec); 1553 for (i = 0; i < ARRAY_SIZE(saved_regs); i++) 1554 chip->saved_regs[i] = inw(chip->port + saved_regs[i]); 1555 /* FIXME: tea575x suspend */ 1556 1557 pci_disable_device(pci); 1558 pci_save_state(pci); 1559 pci_set_power_state(pci, pci_choose_state(pci, state)); 1560 return 0; 1561 } 1562 1563 static int snd_fm801_resume(struct pci_dev *pci) 1564 { 1565 struct snd_card *card = pci_get_drvdata(pci); 1566 struct fm801 *chip = card->private_data; 1567 int i; 1568 1569 pci_set_power_state(pci, PCI_D0); 1570 pci_restore_state(pci); 1571 if (pci_enable_device(pci) < 0) { 1572 printk(KERN_ERR "fm801: pci_enable_device failed, " 1573 "disabling device\n"); 1574 snd_card_disconnect(card); 1575 return -EIO; 1576 } 1577 pci_set_master(pci); 1578 1579 snd_fm801_chip_init(chip, 1); 1580 snd_ac97_resume(chip->ac97); 1581 snd_ac97_resume(chip->ac97_sec); 1582 for (i = 0; i < ARRAY_SIZE(saved_regs); i++) 1583 outw(chip->saved_regs[i], chip->port + saved_regs[i]); 1584 1585 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 1586 return 0; 1587 } 1588 #endif 1589 1469 1590 static struct pci_driver driver = { 1470 0,0,0, 1471 "FM801", 1472 snd_fm801_ids, 1473 snd_card_fm801_probe, 1474 snd_card_fm801_remove, 1475 0,0 1591 .name = "FM801", 1592 .id_table = snd_fm801_ids, 1593 .probe = snd_card_fm801_probe, 1594 .remove = __devexit_p(snd_card_fm801_remove), 1595 #ifdef CONFIG_PM 1596 .suspend = snd_fm801_suspend, 1597 .resume = snd_fm801_resume, 1598 #endif 1476 1599 }; 1477 1600 1478 1601 static int __init alsa_card_fm801_init(void) 1479 1602 { 1480 return pci_ module_init(&driver);1603 return pci_register_driver(&driver); 1481 1604 } 1482 1605
Note:
See TracChangeset
for help on using the changeset viewer.