aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/oxygen/oxygen_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/oxygen/oxygen_lib.c')
-rw-r--r--sound/pci/oxygen/oxygen_lib.c100
1 files changed, 87 insertions, 13 deletions
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index 9c81e0b05113..312251d39696 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -34,6 +34,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
34MODULE_DESCRIPTION("C-Media CMI8788 helper library"); 34MODULE_DESCRIPTION("C-Media CMI8788 helper library");
35MODULE_LICENSE("GPL v2"); 35MODULE_LICENSE("GPL v2");
36 36
37#define DRIVER "oxygen"
37 38
38static inline int oxygen_uart_input_ready(struct oxygen *chip) 39static inline int oxygen_uart_input_ready(struct oxygen *chip)
39{ 40{
@@ -243,6 +244,62 @@ static void oxygen_proc_init(struct oxygen *chip)
243#define oxygen_proc_init(chip) 244#define oxygen_proc_init(chip)
244#endif 245#endif
245 246
247static const struct pci_device_id *
248oxygen_search_pci_id(struct oxygen *chip, const struct pci_device_id ids[])
249{
250 u16 subdevice;
251
252 /*
253 * Make sure the EEPROM pins are available, i.e., not used for SPI.
254 * (This function is called before we initialize or use SPI.)
255 */
256 oxygen_clear_bits8(chip, OXYGEN_FUNCTION,
257 OXYGEN_FUNCTION_ENABLE_SPI_4_5);
258 /*
259 * Read the subsystem device ID directly from the EEPROM, because the
260 * chip didn't if the first EEPROM word was overwritten.
261 */
262 subdevice = oxygen_read_eeprom(chip, 2);
263 /*
264 * We use only the subsystem device ID for searching because it is
265 * unique even without the subsystem vendor ID, which may have been
266 * overwritten in the EEPROM.
267 */
268 for (; ids->vendor; ++ids)
269 if (ids->subdevice == subdevice &&
270 ids->driver_data != BROKEN_EEPROM_DRIVER_DATA)
271 return ids;
272 return NULL;
273}
274
275static void oxygen_restore_eeprom(struct oxygen *chip,
276 const struct pci_device_id *id)
277{
278 if (oxygen_read_eeprom(chip, 0) != OXYGEN_EEPROM_ID) {
279 /*
280 * This function gets called only when a known card model has
281 * been detected, i.e., we know there is a valid subsystem
282 * product ID at index 2 in the EEPROM. Therefore, we have
283 * been able to deduce the correct subsystem vendor ID, and
284 * this is enough information to restore the original EEPROM
285 * contents.
286 */
287 oxygen_write_eeprom(chip, 1, id->subvendor);
288 oxygen_write_eeprom(chip, 0, OXYGEN_EEPROM_ID);
289
290 oxygen_set_bits8(chip, OXYGEN_MISC,
291 OXYGEN_MISC_WRITE_PCI_SUBID);
292 pci_write_config_word(chip->pci, PCI_SUBSYSTEM_VENDOR_ID,
293 id->subvendor);
294 pci_write_config_word(chip->pci, PCI_SUBSYSTEM_ID,
295 id->subdevice);
296 oxygen_clear_bits8(chip, OXYGEN_MISC,
297 OXYGEN_MISC_WRITE_PCI_SUBID);
298
299 snd_printk(KERN_INFO "EEPROM ID restored\n");
300 }
301}
302
246static void oxygen_init(struct oxygen *chip) 303static void oxygen_init(struct oxygen *chip)
247{ 304{
248 unsigned int i; 305 unsigned int i;
@@ -446,21 +503,26 @@ static void oxygen_card_free(struct snd_card *card)
446 free_irq(chip->irq, chip); 503 free_irq(chip->irq, chip);
447 flush_scheduled_work(); 504 flush_scheduled_work();
448 chip->model.cleanup(chip); 505 chip->model.cleanup(chip);
506 kfree(chip->model_data);
449 mutex_destroy(&chip->mutex); 507 mutex_destroy(&chip->mutex);
450 pci_release_regions(chip->pci); 508 pci_release_regions(chip->pci);
451 pci_disable_device(chip->pci); 509 pci_disable_device(chip->pci);
452} 510}
453 511
454int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, 512int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
455 const struct oxygen_model *model, 513 struct module *owner,
456 unsigned long driver_data) 514 const struct pci_device_id *ids,
515 int (*get_model)(struct oxygen *chip,
516 const struct pci_device_id *id
517 )
518 )
457{ 519{
458 struct snd_card *card; 520 struct snd_card *card;
459 struct oxygen *chip; 521 struct oxygen *chip;
522 const struct pci_device_id *pci_id;
460 int err; 523 int err;
461 524
462 err = snd_card_create(index, id, model->owner, 525 err = snd_card_create(index, id, owner, sizeof(*chip), &card);
463 sizeof(*chip) + model->model_data_size, &card);
464 if (err < 0) 526 if (err < 0)
465 return err; 527 return err;
466 528
@@ -468,8 +530,6 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
468 chip->card = card; 530 chip->card = card;
469 chip->pci = pci; 531 chip->pci = pci;
470 chip->irq = -1; 532 chip->irq = -1;
471 chip->model = *model;
472 chip->model_data = chip + 1;
473 spin_lock_init(&chip->reg_lock); 533 spin_lock_init(&chip->reg_lock);
474 mutex_init(&chip->mutex); 534 mutex_init(&chip->mutex);
475 INIT_WORK(&chip->spdif_input_bits_work, 535 INIT_WORK(&chip->spdif_input_bits_work,
@@ -481,7 +541,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
481 if (err < 0) 541 if (err < 0)
482 goto err_card; 542 goto err_card;
483 543
484 err = pci_request_regions(pci, model->chip); 544 err = pci_request_regions(pci, DRIVER);
485 if (err < 0) { 545 if (err < 0) {
486 snd_printk(KERN_ERR "cannot reserve PCI resources\n"); 546 snd_printk(KERN_ERR "cannot reserve PCI resources\n");
487 goto err_pci_enable; 547 goto err_pci_enable;
@@ -495,20 +555,34 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
495 } 555 }
496 chip->addr = pci_resource_start(pci, 0); 556 chip->addr = pci_resource_start(pci, 0);
497 557
558 pci_id = oxygen_search_pci_id(chip, ids);
559 if (!pci_id) {
560 err = -ENODEV;
561 goto err_pci_regions;
562 }
563 oxygen_restore_eeprom(chip, pci_id);
564 err = get_model(chip, pci_id);
565 if (err < 0)
566 goto err_pci_regions;
567
568 if (chip->model.model_data_size) {
569 chip->model_data = kzalloc(chip->model.model_data_size,
570 GFP_KERNEL);
571 if (!chip->model_data) {
572 err = -ENOMEM;
573 goto err_pci_regions;
574 }
575 }
576
498 pci_set_master(pci); 577 pci_set_master(pci);
499 snd_card_set_dev(card, &pci->dev); 578 snd_card_set_dev(card, &pci->dev);
500 card->private_free = oxygen_card_free; 579 card->private_free = oxygen_card_free;
501 580
502 if (chip->model.probe) {
503 err = chip->model.probe(chip, driver_data);
504 if (err < 0)
505 goto err_card;
506 }
507 oxygen_init(chip); 581 oxygen_init(chip);
508 chip->model.init(chip); 582 chip->model.init(chip);
509 583
510 err = request_irq(pci->irq, oxygen_interrupt, IRQF_SHARED, 584 err = request_irq(pci->irq, oxygen_interrupt, IRQF_SHARED,
511 chip->model.chip, chip); 585 DRIVER, chip);
512 if (err < 0) { 586 if (err < 0) {
513 snd_printk(KERN_ERR "cannot grab interrupt %d\n", pci->irq); 587 snd_printk(KERN_ERR "cannot grab interrupt %d\n", pci->irq);
514 goto err_card; 588 goto err_card;