sscape.c (f0968e3f7a8ea30728d2580d3043a30ea9994ec6) | sscape.c (acd47100914b2896d0699febefd077f85c4dd272) |
---|---|
1/* | 1/* |
2 * Low-level ALSA driver for the ENSONIQ SoundScape PnP | 2 * Low-level ALSA driver for the ENSONIQ SoundScape |
3 * Copyright (c) by Chris Rankin 4 * 5 * This driver was written in part using information obtained from 6 * the OSS/Free SoundScape driver, written by Hannu Savolainen. 7 * 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by --- 9 unchanged lines hidden (view full) --- 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 */ 23 24#include <linux/init.h> 25#include <linux/err.h> 26#include <linux/isa.h> 27#include <linux/delay.h> | 3 * Copyright (c) by Chris Rankin 4 * 5 * This driver was written in part using information obtained from 6 * the OSS/Free SoundScape driver, written by Hannu Savolainen. 7 * 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by --- 9 unchanged lines hidden (view full) --- 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 */ 23 24#include <linux/init.h> 25#include <linux/err.h> 26#include <linux/isa.h> 27#include <linux/delay.h> |
28#include <linux/firmware.h> |
|
28#include <linux/pnp.h> 29#include <linux/spinlock.h> 30#include <linux/moduleparam.h> 31#include <asm/dma.h> 32#include <sound/core.h> | 29#include <linux/pnp.h> 30#include <linux/spinlock.h> 31#include <linux/moduleparam.h> 32#include <asm/dma.h> 33#include <sound/core.h> |
33#include <sound/hwdep.h> | |
34#include <sound/wss.h> 35#include <sound/mpu401.h> 36#include <sound/initval.h> 37 | 34#include <sound/wss.h> 35#include <sound/mpu401.h> 36#include <sound/initval.h> 37 |
38#include <sound/sscape_ioctl.h> | |
39 | 38 |
40 | |
41MODULE_AUTHOR("Chris Rankin"); | 39MODULE_AUTHOR("Chris Rankin"); |
42MODULE_DESCRIPTION("ENSONIQ SoundScape PnP driver"); | 40MODULE_DESCRIPTION("ENSONIQ SoundScape driver"); |
43MODULE_LICENSE("GPL"); | 41MODULE_LICENSE("GPL"); |
42MODULE_FIRMWARE("sndscape.co0"); 43MODULE_FIRMWARE("sndscape.co1"); 44MODULE_FIRMWARE("sndscape.co2"); 45MODULE_FIRMWARE("sndscape.co3"); 46MODULE_FIRMWARE("sndscape.co4"); 47MODULE_FIRMWARE("scope.cod"); |
|
44 45static int index[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IDX; 46static char* id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_STR; 47static long port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT; 48static long wss_port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT; 49static int irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ; 50static int mpu_irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ; 51static int dma[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_DMA; --- 85 unchanged lines hidden (view full) --- 137 spinlock_t lock; 138 unsigned io_base; 139 int ic_type; 140 enum card_type type; 141 struct resource *io_res; 142 struct resource *wss_res; 143 struct snd_wss *chip; 144 struct snd_mpu401 *mpu; | 48 49static int index[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IDX; 50static char* id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_STR; 51static long port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT; 52static long wss_port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT; 53static int irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ; 54static int mpu_irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ; 55static int dma[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_DMA; --- 85 unchanged lines hidden (view full) --- 141 spinlock_t lock; 142 unsigned io_base; 143 int ic_type; 144 enum card_type type; 145 struct resource *io_res; 146 struct resource *wss_res; 147 struct snd_wss *chip; 148 struct snd_mpu401 *mpu; |
145 struct snd_hwdep *hw; | |
146 147 /* 148 * The MIDI device won't work until we've loaded 149 * its firmware via a hardware-dependent device IOCTL 150 */ 151 spinlock_t fwlock; | 149 150 /* 151 * The MIDI device won't work until we've loaded 152 * its firmware via a hardware-dependent device IOCTL 153 */ 154 spinlock_t fwlock; |
152 int hw_in_use; | |
153 unsigned long midi_usage; 154 unsigned char midi_vol; 155}; 156 157#define INVALID_IRQ ((unsigned)-1) 158 159 160static inline struct soundscape *get_card_soundscape(struct snd_card *c) 161{ 162 return (struct soundscape *) (c->private_data); 163} 164 165static inline struct soundscape *get_mpu401_soundscape(struct snd_mpu401 * mpu) 166{ 167 return (struct soundscape *) (mpu->private_data); 168} 169 | 155 unsigned long midi_usage; 156 unsigned char midi_vol; 157}; 158 159#define INVALID_IRQ ((unsigned)-1) 160 161 162static inline struct soundscape *get_card_soundscape(struct snd_card *c) 163{ 164 return (struct soundscape *) (c->private_data); 165} 166 167static inline struct soundscape *get_mpu401_soundscape(struct snd_mpu401 * mpu) 168{ 169 return (struct soundscape *) (mpu->private_data); 170} 171 |
170static inline struct soundscape *get_hwdep_soundscape(struct snd_hwdep * hw) 171{ 172 return (struct soundscape *) (hw->private_data); 173} 174 175 | |
176/* 177 * Allocates some kernel memory that we can use for DMA. 178 * I think this means that the memory has to map to 179 * contiguous pages of physical memory. 180 */ 181static struct snd_dma_buffer *get_dmabuf(struct snd_dma_buffer *buf, unsigned long size) 182{ 183 if (buf) { --- 204 unchanged lines hidden (view full) --- 388 * spinlocks when we call this function. 389 */ 390static int obp_startup_ack(struct soundscape *s, unsigned timeout) 391{ 392 unsigned long end_time = jiffies + msecs_to_jiffies(timeout); 393 394 do { 395 unsigned long flags; | 172/* 173 * Allocates some kernel memory that we can use for DMA. 174 * I think this means that the memory has to map to 175 * contiguous pages of physical memory. 176 */ 177static struct snd_dma_buffer *get_dmabuf(struct snd_dma_buffer *buf, unsigned long size) 178{ 179 if (buf) { --- 204 unchanged lines hidden (view full) --- 384 * spinlocks when we call this function. 385 */ 386static int obp_startup_ack(struct soundscape *s, unsigned timeout) 387{ 388 unsigned long end_time = jiffies + msecs_to_jiffies(timeout); 389 390 do { 391 unsigned long flags; |
396 unsigned char x; | 392 int x; |
397 398 spin_lock_irqsave(&s->lock, flags); | 393 394 spin_lock_irqsave(&s->lock, flags); |
399 x = inb(HOST_DATA_IO(s->io_base)); | 395 x = host_read_unsafe(s->io_base); |
400 spin_unlock_irqrestore(&s->lock, flags); | 396 spin_unlock_irqrestore(&s->lock, flags); |
401 if ((x & 0xfe) == 0xfe) | 397 if (x == 0xfe || x == 0xff) |
402 return 1; 403 404 msleep(10); 405 } while (time_before(jiffies, end_time)); 406 407 return 0; 408} 409 --- 5 unchanged lines hidden (view full) --- 415 * this function. 416 */ 417static int host_startup_ack(struct soundscape *s, unsigned timeout) 418{ 419 unsigned long end_time = jiffies + msecs_to_jiffies(timeout); 420 421 do { 422 unsigned long flags; | 398 return 1; 399 400 msleep(10); 401 } while (time_before(jiffies, end_time)); 402 403 return 0; 404} 405 --- 5 unchanged lines hidden (view full) --- 411 * this function. 412 */ 413static int host_startup_ack(struct soundscape *s, unsigned timeout) 414{ 415 unsigned long end_time = jiffies + msecs_to_jiffies(timeout); 416 417 do { 418 unsigned long flags; |
423 unsigned char x; | 419 int x; |
424 425 spin_lock_irqsave(&s->lock, flags); | 420 421 spin_lock_irqsave(&s->lock, flags); |
426 x = inb(HOST_DATA_IO(s->io_base)); | 422 x = host_read_unsafe(s->io_base); |
427 spin_unlock_irqrestore(&s->lock, flags); 428 if (x == 0xfe) 429 return 1; 430 431 msleep(10); 432 } while (time_before(jiffies, end_time)); 433 434 return 0; 435} 436 437/* 438 * Upload a byte-stream into the SoundScape using DMA channel A. 439 */ 440static int upload_dma_data(struct soundscape *s, | 423 spin_unlock_irqrestore(&s->lock, flags); 424 if (x == 0xfe) 425 return 1; 426 427 msleep(10); 428 } while (time_before(jiffies, end_time)); 429 430 return 0; 431} 432 433/* 434 * Upload a byte-stream into the SoundScape using DMA channel A. 435 */ 436static int upload_dma_data(struct soundscape *s, |
441 const unsigned char __user *data, | 437 const unsigned char *data, |
442 size_t size) 443{ 444 unsigned long flags; 445 struct snd_dma_buffer dma; 446 int ret; 447 | 438 size_t size) 439{ 440 unsigned long flags; 441 struct snd_dma_buffer dma; 442 int ret; 443 |
448 if (!get_dmabuf(&dma, PAGE_ALIGN(size))) | 444 if (!get_dmabuf(&dma, PAGE_ALIGN(32 * 1024))) |
449 return -ENOMEM; 450 451 spin_lock_irqsave(&s->lock, flags); 452 453 /* 454 * Reset the board ... 455 */ 456 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f); 457 458 /* 459 * Enable the DMA channels and configure them ... 460 */ | 445 return -ENOMEM; 446 447 spin_lock_irqsave(&s->lock, flags); 448 449 /* 450 * Reset the board ... 451 */ 452 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f); 453 454 /* 455 * Enable the DMA channels and configure them ... 456 */ |
461 sscape_write_unsafe(s->io_base, GA_DMACFG_REG, 0x50); | |
462 sscape_write_unsafe(s->io_base, GA_DMAA_REG, (s->chip->dma1 << 4) | DMA_8BIT); 463 sscape_write_unsafe(s->io_base, GA_DMAB_REG, 0x20); 464 465 /* 466 * Take the board out of reset ... 467 */ 468 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x80); 469 470 /* | 457 sscape_write_unsafe(s->io_base, GA_DMAA_REG, (s->chip->dma1 << 4) | DMA_8BIT); 458 sscape_write_unsafe(s->io_base, GA_DMAB_REG, 0x20); 459 460 /* 461 * Take the board out of reset ... 462 */ 463 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x80); 464 465 /* |
471 * Upload the user's data (firmware?) to the SoundScape | 466 * Upload the firmware to the SoundScape |
472 * board through the DMA channel ... 473 */ 474 while (size != 0) { 475 unsigned long len; 476 | 467 * board through the DMA channel ... 468 */ 469 while (size != 0) { 470 unsigned long len; 471 |
477 /* 478 * Apparently, copying to/from userspace can sleep. 479 * We are therefore forbidden from holding any 480 * spinlocks while we copy ... 481 */ 482 spin_unlock_irqrestore(&s->lock, flags); 483 484 /* 485 * Remember that the data that we want to DMA 486 * comes from USERSPACE. We have already verified 487 * the userspace pointer ... 488 */ | |
489 len = min(size, dma.bytes); | 472 len = min(size, dma.bytes); |
490 len -= __copy_from_user(dma.area, data, len); | 473 memcpy(dma.area, data, len); |
491 data += len; 492 size -= len; 493 | 474 data += len; 475 size -= len; 476 |
494 /* 495 * Grab that spinlock again, now that we've 496 * finished copying! 497 */ 498 spin_lock_irqsave(&s->lock, flags); 499 | |
500 snd_dma_program(s->chip->dma1, dma.addr, len, DMA_MODE_WRITE); 501 sscape_start_dma_unsafe(s->io_base, GA_DMAA_REG); 502 if (!sscape_wait_dma_unsafe(s->io_base, GA_DMAA_REG, 5000)) { 503 /* 504 * Don't forget to release this spinlock we're holding ... 505 */ 506 spin_unlock_irqrestore(&s->lock, flags); 507 508 snd_printk(KERN_ERR "sscape: DMA upload has timed out\n"); 509 ret = -EAGAIN; 510 goto _release_dma; 511 } 512 } /* while */ 513 514 set_host_mode_unsafe(s->io_base); | 477 snd_dma_program(s->chip->dma1, dma.addr, len, DMA_MODE_WRITE); 478 sscape_start_dma_unsafe(s->io_base, GA_DMAA_REG); 479 if (!sscape_wait_dma_unsafe(s->io_base, GA_DMAA_REG, 5000)) { 480 /* 481 * Don't forget to release this spinlock we're holding ... 482 */ 483 spin_unlock_irqrestore(&s->lock, flags); 484 485 snd_printk(KERN_ERR "sscape: DMA upload has timed out\n"); 486 ret = -EAGAIN; 487 goto _release_dma; 488 } 489 } /* while */ 490 491 set_host_mode_unsafe(s->io_base); |
492 outb(0x0, s->io_base); |
|
515 516 /* 517 * Boot the board ... (I think) 518 */ 519 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x40); 520 spin_unlock_irqrestore(&s->lock, flags); 521 522 /* --- 9 unchanged lines hidden (view full) --- 532 snd_printk(KERN_ERR "sscape: SoundScape failed to initialise\n"); 533 ret = -EAGAIN; 534 } 535 536_release_dma: 537 /* 538 * NOTE!!! We are NOT holding any spinlocks at this point !!! 539 */ | 493 494 /* 495 * Boot the board ... (I think) 496 */ 497 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x40); 498 spin_unlock_irqrestore(&s->lock, flags); 499 500 /* --- 9 unchanged lines hidden (view full) --- 510 snd_printk(KERN_ERR "sscape: SoundScape failed to initialise\n"); 511 ret = -EAGAIN; 512 } 513 514_release_dma: 515 /* 516 * NOTE!!! We are NOT holding any spinlocks at this point !!! 517 */ |
540 sscape_write(s, GA_DMAA_REG, (s->ic_type == IC_ODIE ? 0x70 : 0x40)); | 518 sscape_write(s, GA_DMAA_REG, (s->ic_type == IC_OPUS ? 0x40 : 0x70)); |
541 free_dmabuf(&dma); 542 543 return ret; 544} 545 546/* 547 * Upload the bootblock(?) into the SoundScape. The only 548 * purpose of this block of code seems to be to tell 549 * us which version of the microcode we should be using. | 519 free_dmabuf(&dma); 520 521 return ret; 522} 523 524/* 525 * Upload the bootblock(?) into the SoundScape. The only 526 * purpose of this block of code seems to be to tell 527 * us which version of the microcode we should be using. |
550 * 551 * NOTE: The boot-block data resides in USER-SPACE!!! 552 * However, we have already verified its memory 553 * addresses by the time we get here. | |
554 */ | 528 */ |
555static int sscape_upload_bootblock(struct soundscape *sscape, struct sscape_bootblock __user *bb) | 529static int sscape_upload_bootblock(struct snd_card *card) |
556{ | 530{ |
531 struct soundscape *sscape = get_card_soundscape(card); |
|
557 unsigned long flags; | 532 unsigned long flags; |
533 const struct firmware *init_fw = NULL; |
|
558 int data = 0; 559 int ret; 560 | 534 int data = 0; 535 int ret; 536 |
561 ret = upload_dma_data(sscape, bb->code, sizeof(bb->code)); | 537 ret = request_firmware(&init_fw, "scope.cod", card->dev); 538 if (ret < 0) { 539 snd_printk(KERN_ERR "Error loading scope.cod"); 540 return ret; 541 } 542 ret = upload_dma_data(sscape, init_fw->data, init_fw->size); |
562 | 543 |
544 release_firmware(init_fw); 545 |
|
563 spin_lock_irqsave(&sscape->lock, flags); | 546 spin_lock_irqsave(&sscape->lock, flags); |
564 if (ret == 0) { | 547 if (ret == 0) |
565 data = host_read_ctrl_unsafe(sscape->io_base, 100); | 548 data = host_read_ctrl_unsafe(sscape->io_base, 100); |
566 } 567 set_midi_mode_unsafe(sscape->io_base); 568 spin_unlock_irqrestore(&sscape->lock, flags); | |
569 | 549 |
570 if (ret == 0) { 571 if (data < 0) { 572 snd_printk(KERN_ERR "sscape: timeout reading firmware version\n"); 573 ret = -EAGAIN; 574 } 575 else if (__copy_to_user(&bb->version, &data, sizeof(bb->version))) { 576 ret = -EFAULT; 577 } 578 } | 550 if (data & 0x10) 551 sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2f); |
579 | 552 |
580 return ret; 581} | 553 spin_unlock_irqrestore(&sscape->lock, flags); |
582 | 554 |
583/* 584 * Upload the microcode into the SoundScape. The 585 * microcode is 64K of data, and if we try to copy 586 * it into a local variable then we will SMASH THE 587 * KERNEL'S STACK! We therefore leave it in USER 588 * SPACE, and save ourselves from copying it at all. 589 */ 590static int sscape_upload_microcode(struct soundscape *sscape, 591 const struct sscape_microcode __user *mc) 592{ 593 unsigned long flags; 594 char __user *code; 595 int err; 596 597 /* 598 * We are going to have to copy this data into a special 599 * DMA-able buffer before we can upload it. We shall therefore 600 * just check that the data pointer is valid for now. 601 * 602 * NOTE: This buffer is 64K long! That's WAY too big to 603 * copy into a stack-temporary anyway. 604 */ 605 if ( get_user(code, &mc->code) || 606 !access_ok(VERIFY_READ, code, SSCAPE_MICROCODE_SIZE) ) 607 return -EFAULT; 608 609 if ((err = upload_dma_data(sscape, code, SSCAPE_MICROCODE_SIZE)) == 0) { 610 snd_printk(KERN_INFO "sscape: MIDI firmware loaded\n"); | 555 data &= 0xf; 556 if (ret == 0 && data > 7) { 557 snd_printk(KERN_ERR "timeout reading firmware version\n"); 558 ret = -EAGAIN; |
611 } 612 | 559 } 560 |
613 spin_lock_irqsave(&sscape->lock, flags); 614 set_midi_mode_unsafe(sscape->io_base); 615 spin_unlock_irqrestore(&sscape->lock, flags); 616 617 initialise_mpu401(sscape->mpu); 618 619 return err; | 561 return (ret == 0) ? data : ret; |
620} 621 622/* | 562} 563 564/* |
623 * Hardware-specific device functions, to implement special 624 * IOCTLs for the SoundScape card. This is how we upload 625 * the microcode into the card, for example, and so we 626 * must ensure that no two processes can open this device 627 * simultaneously, and that we can't open it at all if 628 * someone is using the MIDI device. | 565 * Upload the microcode into the SoundScape. |
629 */ | 566 */ |
630static int sscape_hw_open(struct snd_hwdep * hw, struct file *file) | 567static int sscape_upload_microcode(struct snd_card *card, int version) |
631{ | 568{ |
632 register struct soundscape *sscape = get_hwdep_soundscape(hw); 633 unsigned long flags; | 569 struct soundscape *sscape = get_card_soundscape(card); 570 const struct firmware *init_fw = NULL; 571 char name[14]; |
634 int err; 635 | 572 int err; 573 |
636 spin_lock_irqsave(&sscape->fwlock, flags); | 574 snprintf(name, sizeof(name), "sndscape.co%d", version); |
637 | 575 |
638 if ((sscape->midi_usage != 0) || sscape->hw_in_use) { 639 err = -EBUSY; 640 } else { 641 sscape->hw_in_use = 1; 642 err = 0; | 576 err = request_firmware(&init_fw, name, card->dev); 577 if (err < 0) { 578 snd_printk(KERN_ERR "Error loading sndscape.co%d", version); 579 return err; |
643 } | 580 } |
581 err = upload_dma_data(sscape, init_fw->data, init_fw->size); 582 if (err == 0) 583 snd_printk(KERN_INFO "MIDI firmware loaded %d KBs\n", 584 init_fw->size >> 10); |
|
644 | 585 |
645 spin_unlock_irqrestore(&sscape->fwlock, flags); 646 return err; 647} | 586 release_firmware(init_fw); |
648 | 587 |
649static int sscape_hw_release(struct snd_hwdep * hw, struct file *file) 650{ 651 register struct soundscape *sscape = get_hwdep_soundscape(hw); 652 unsigned long flags; 653 654 spin_lock_irqsave(&sscape->fwlock, flags); 655 sscape->hw_in_use = 0; 656 spin_unlock_irqrestore(&sscape->fwlock, flags); 657 return 0; 658} 659 660static int sscape_hw_ioctl(struct snd_hwdep * hw, struct file *file, 661 unsigned int cmd, unsigned long arg) 662{ 663 struct soundscape *sscape = get_hwdep_soundscape(hw); 664 int err = -EBUSY; 665 666 switch (cmd) { 667 case SND_SSCAPE_LOAD_BOOTB: 668 { 669 register struct sscape_bootblock __user *bb = (struct sscape_bootblock __user *) arg; 670 671 /* 672 * We are going to have to copy this data into a special 673 * DMA-able buffer before we can upload it. We shall therefore 674 * just check that the data pointer is valid for now ... 675 */ 676 if ( !access_ok(VERIFY_READ, bb->code, sizeof(bb->code)) ) 677 return -EFAULT; 678 679 /* 680 * Now check that we can write the firmware version number too... 681 */ 682 if ( !access_ok(VERIFY_WRITE, &bb->version, sizeof(bb->version)) ) 683 return -EFAULT; 684 685 err = sscape_upload_bootblock(sscape, bb); 686 } 687 break; 688 689 case SND_SSCAPE_LOAD_MCODE: 690 { 691 register const struct sscape_microcode __user *mc = (const struct sscape_microcode __user *) arg; 692 693 err = sscape_upload_microcode(sscape, mc); 694 } 695 break; 696 697 default: 698 err = -EINVAL; 699 break; 700 } /* switch */ 701 | |
702 return err; 703} 704 | 588 return err; 589} 590 |
705 | |
706/* 707 * Mixer control for the SoundScape's MIDI device. 708 */ 709static int sscape_midi_info(struct snd_kcontrol *ctl, 710 struct snd_ctl_elem_info *uinfo) 711{ 712 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 713 uinfo->count = 1; --- 201 unchanged lines hidden (view full) --- 915 snd_printk(KERN_ERR "sscape: MIDI disabled, please load firmware\n"); 916 err = -ENODEV; 917 } else { 918 register struct soundscape *sscape = get_mpu401_soundscape(mpu); 919 unsigned long flags; 920 921 spin_lock_irqsave(&sscape->fwlock, flags); 922 | 591/* 592 * Mixer control for the SoundScape's MIDI device. 593 */ 594static int sscape_midi_info(struct snd_kcontrol *ctl, 595 struct snd_ctl_elem_info *uinfo) 596{ 597 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 598 uinfo->count = 1; --- 201 unchanged lines hidden (view full) --- 800 snd_printk(KERN_ERR "sscape: MIDI disabled, please load firmware\n"); 801 err = -ENODEV; 802 } else { 803 register struct soundscape *sscape = get_mpu401_soundscape(mpu); 804 unsigned long flags; 805 806 spin_lock_irqsave(&sscape->fwlock, flags); 807 |
923 if (sscape->hw_in_use || (sscape->midi_usage == ULONG_MAX)) { | 808 if (sscape->midi_usage == ULONG_MAX) { |
924 err = -EBUSY; 925 } else { 926 ++(sscape->midi_usage); 927 err = 0; 928 } 929 930 spin_unlock_irqrestore(&sscape->fwlock, flags); 931 } --- 116 unchanged lines hidden (view full) --- 1048 snd_ctl_new1(&midi_mixer_ctl, chip)); 1049 if (err < 0) { 1050 snd_printk(KERN_ERR "sscape: Could not create " 1051 "MIDI mixer control\n"); 1052 goto _error; 1053 } 1054 } 1055 | 809 err = -EBUSY; 810 } else { 811 ++(sscape->midi_usage); 812 err = 0; 813 } 814 815 spin_unlock_irqrestore(&sscape->fwlock, flags); 816 } --- 116 unchanged lines hidden (view full) --- 933 snd_ctl_new1(&midi_mixer_ctl, chip)); 934 if (err < 0) { 935 snd_printk(KERN_ERR "sscape: Could not create " 936 "MIDI mixer control\n"); 937 goto _error; 938 } 939 } 940 |
1056 strcpy(card->driver, "SoundScape"); 1057 strcpy(card->shortname, pcm->name); 1058 snprintf(card->longname, sizeof(card->longname), 1059 "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n", 1060 pcm->name, chip->port, chip->irq, 1061 chip->dma1, chip->dma2); 1062 | |
1063 sscape->chip = chip; 1064 } 1065 1066 _error: 1067 return err; 1068} 1069 1070 --- 86 unchanged lines hidden (view full) --- 1157 } 1158 1159 mpu_irq_cfg = get_irq_config(sscape->type, mpu_irq[dev]); 1160 if (mpu_irq_cfg == INVALID_IRQ) { 1161 printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]); 1162 return -ENXIO; 1163 } 1164 | 941 sscape->chip = chip; 942 } 943 944 _error: 945 return err; 946} 947 948 --- 86 unchanged lines hidden (view full) --- 1035 } 1036 1037 mpu_irq_cfg = get_irq_config(sscape->type, mpu_irq[dev]); 1038 if (mpu_irq_cfg == INVALID_IRQ) { 1039 printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]); 1040 return -ENXIO; 1041 } 1042 |
1165 if (sscape->type != SSCAPE_VIVO) { 1166 /* 1167 * Now create the hardware-specific device so that we can 1168 * load the microcode into the on-board processor. 1169 * We cannot use the MPU-401 MIDI system until this firmware 1170 * has been loaded into the card. 1171 */ 1172 err = snd_hwdep_new(card, "MC68EC000", 0, &(sscape->hw)); 1173 if (err < 0) { 1174 printk(KERN_ERR "sscape: Failed to create " 1175 "firmware device\n"); 1176 goto _release_dma; 1177 } 1178 strlcpy(sscape->hw->name, "SoundScape M68K", 1179 sizeof(sscape->hw->name)); 1180 sscape->hw->name[sizeof(sscape->hw->name) - 1] = '\0'; 1181 sscape->hw->iface = SNDRV_HWDEP_IFACE_SSCAPE; 1182 sscape->hw->ops.open = sscape_hw_open; 1183 sscape->hw->ops.release = sscape_hw_release; 1184 sscape->hw->ops.ioctl = sscape_hw_ioctl; 1185 sscape->hw->private_data = sscape; 1186 } 1187 | |
1188 /* 1189 * Tell the on-board devices where their resources are (I think - 1190 * I can't be sure without a datasheet ... So many magic values!) 1191 */ 1192 spin_lock_irqsave(&sscape->lock, flags); 1193 1194 sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x00); /* disable */ 1195 sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e); --- 21 unchanged lines hidden (view full) --- 1217 */ 1218 err = create_ad1845(card, wss_port[dev], irq[dev], 1219 dma[dev], dma2[dev]); 1220 if (err < 0) { 1221 printk(KERN_ERR "sscape: No AD1845 device at 0x%lx, IRQ %d\n", 1222 wss_port[dev], irq[dev]); 1223 goto _release_dma; 1224 } | 1043 /* 1044 * Tell the on-board devices where their resources are (I think - 1045 * I can't be sure without a datasheet ... So many magic values!) 1046 */ 1047 spin_lock_irqsave(&sscape->lock, flags); 1048 1049 sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x00); /* disable */ 1050 sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e); --- 21 unchanged lines hidden (view full) --- 1072 */ 1073 err = create_ad1845(card, wss_port[dev], irq[dev], 1074 dma[dev], dma2[dev]); 1075 if (err < 0) { 1076 printk(KERN_ERR "sscape: No AD1845 device at 0x%lx, IRQ %d\n", 1077 wss_port[dev], irq[dev]); 1078 goto _release_dma; 1079 } |
1080 strcpy(card->driver, "SoundScape"); 1081 strcpy(card->shortname, name); 1082 snprintf(card->longname, sizeof(card->longname), 1083 "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n", 1084 name, sscape->chip->port, sscape->chip->irq, 1085 sscape->chip->dma1, sscape->chip->dma2); 1086 |
|
1225#define MIDI_DEVNUM 0 1226 if (sscape->type != SSCAPE_VIVO) { | 1087#define MIDI_DEVNUM 0 1088 if (sscape->type != SSCAPE_VIVO) { |
1227 err = create_mpu401(card, MIDI_DEVNUM, port[dev], mpu_irq[dev]); 1228 if (err < 0) { 1229 printk(KERN_ERR "sscape: Failed to create " 1230 "MPU-401 device at 0x%lx\n", 1231 port[dev]); 1232 goto _release_dma; 1233 } | 1089 err = sscape_upload_bootblock(card); 1090 if (err >= 0) 1091 err = sscape_upload_microcode(card, err); |
1234 | 1092 |
1235 /* 1236 * Enable the master IRQ ... 1237 */ 1238 sscape_write(sscape, GA_INTENA_REG, 0x80); | 1093 if (err == 0) { 1094 err = create_mpu401(card, MIDI_DEVNUM, port[dev], 1095 mpu_irq[dev]); 1096 if (err < 0) { 1097 printk(KERN_ERR "sscape: Failed to create " 1098 "MPU-401 device at 0x%lx\n", 1099 port[dev]); 1100 goto _release_dma; 1101 } |
1239 | 1102 |
1240 /* 1241 * Initialize mixer 1242 */ 1243 sscape->midi_vol = 0; 1244 host_write_ctrl_unsafe(sscape->io_base, CMD_SET_MIDI_VOL, 100); 1245 host_write_ctrl_unsafe(sscape->io_base, 0, 100); 1246 host_write_ctrl_unsafe(sscape->io_base, CMD_XXX_MIDI_VOL, 100); | 1103 /* 1104 * Enable the master IRQ ... 1105 */ 1106 sscape_write(sscape, GA_INTENA_REG, 0x80); 1107 1108 /* 1109 * Initialize mixer 1110 */ 1111 spin_lock_irqsave(&sscape->lock, flags); 1112 sscape->midi_vol = 0; 1113 host_write_ctrl_unsafe(sscape->io_base, 1114 CMD_SET_MIDI_VOL, 100); 1115 host_write_ctrl_unsafe(sscape->io_base, 1116 sscape->midi_vol, 100); 1117 host_write_ctrl_unsafe(sscape->io_base, 1118 CMD_XXX_MIDI_VOL, 100); 1119 host_write_ctrl_unsafe(sscape->io_base, 1120 sscape->midi_vol, 100); 1121 host_write_ctrl_unsafe(sscape->io_base, 1122 CMD_SET_EXTMIDI, 100); 1123 host_write_ctrl_unsafe(sscape->io_base, 1124 0, 100); 1125 host_write_ctrl_unsafe(sscape->io_base, CMD_ACK, 100); 1126 1127 set_midi_mode_unsafe(sscape->io_base); 1128 spin_unlock_irqrestore(&sscape->lock, flags); 1129 } |
1247 } 1248 1249 /* 1250 * Now that we have successfully created this sound card, 1251 * it is safe to store the pointer. 1252 * NOTE: we only register the sound card's "destructor" 1253 * function now that our "constructor" has completed. 1254 */ --- 41 unchanged lines hidden (view full) --- 1296 sizeof(struct soundscape), &card); 1297 if (ret < 0) 1298 return ret; 1299 1300 sscape = get_card_soundscape(card); 1301 sscape->type = SSCAPE; 1302 1303 dma[dev] &= 0x03; | 1130 } 1131 1132 /* 1133 * Now that we have successfully created this sound card, 1134 * it is safe to store the pointer. 1135 * NOTE: we only register the sound card's "destructor" 1136 * function now that our "constructor" has completed. 1137 */ --- 41 unchanged lines hidden (view full) --- 1179 sizeof(struct soundscape), &card); 1180 if (ret < 0) 1181 return ret; 1182 1183 sscape = get_card_soundscape(card); 1184 sscape->type = SSCAPE; 1185 1186 dma[dev] &= 0x03; |
1187 snd_card_set_dev(card, pdev); 1188 |
|
1304 ret = create_sscape(dev, card); 1305 if (ret < 0) 1306 goto _release_card; 1307 | 1189 ret = create_sscape(dev, card); 1190 if (ret < 0) 1191 goto _release_card; 1192 |
1308 snd_card_set_dev(card, pdev); | |
1309 if ((ret = snd_card_register(card)) < 0) { 1310 printk(KERN_ERR "sscape: Failed to register sound card\n"); 1311 goto _release_card; 1312 } 1313 dev_set_drvdata(pdev, card); 1314 return 0; 1315 1316_release_card: --- 104 unchanged lines hidden (view full) --- 1421 dma[idx] = pnp_dma(dev, 0) & 0x03; 1422 if (sscape->type == SSCAPE_PNP) { 1423 dma2[idx] = dma[idx]; 1424 wss_port[idx] = CODEC_IO(port[idx]); 1425 } else { 1426 wss_port[idx] = pnp_port_start(dev, 1); 1427 dma2[idx] = pnp_dma(dev, 1); 1428 } | 1193 if ((ret = snd_card_register(card)) < 0) { 1194 printk(KERN_ERR "sscape: Failed to register sound card\n"); 1195 goto _release_card; 1196 } 1197 dev_set_drvdata(pdev, card); 1198 return 0; 1199 1200_release_card: --- 104 unchanged lines hidden (view full) --- 1305 dma[idx] = pnp_dma(dev, 0) & 0x03; 1306 if (sscape->type == SSCAPE_PNP) { 1307 dma2[idx] = dma[idx]; 1308 wss_port[idx] = CODEC_IO(port[idx]); 1309 } else { 1310 wss_port[idx] = pnp_port_start(dev, 1); 1311 dma2[idx] = pnp_dma(dev, 1); 1312 } |
1313 snd_card_set_dev(card, &pcard->card->dev); |
|
1429 1430 ret = create_sscape(idx, card); 1431 if (ret < 0) 1432 goto _release_card; 1433 | 1314 1315 ret = create_sscape(idx, card); 1316 if (ret < 0) 1317 goto _release_card; 1318 |
1434 snd_card_set_dev(card, &pcard->card->dev); | |
1435 if ((ret = snd_card_register(card)) < 0) { 1436 printk(KERN_ERR "sscape: Failed to register sound card\n"); 1437 goto _release_card; 1438 } 1439 1440 pnp_set_card_drvdata(pcard, card); 1441 ++idx; 1442 return 0; --- 53 unchanged lines hidden --- | 1319 if ((ret = snd_card_register(card)) < 0) { 1320 printk(KERN_ERR "sscape: Failed to register sound card\n"); 1321 goto _release_card; 1322 } 1323 1324 pnp_set_card_drvdata(pcard, card); 1325 ++idx; 1326 return 0; --- 53 unchanged lines hidden --- |