Lines Matching +full:lock +full:- +full:detect +full:- +full:function +full:- +full:integer +full:- +full:n +full:- +full:enable

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Low-level ALSA driver for the ENSONIQ SoundScape
71 MODULE_PARM_DESC(joystick, "Enable gameport.");
125 MEDIA_FX, /* Sequoia S-1000 */
126 SSCAPE, /* Sequoia S-2000 */
132 spinlock_t lock; member
144 #define INVALID_IRQ ((unsigned)-1)
149 return (struct soundscape *) (c->private_data); in get_card_soundscape()
163 s->chip->card->dev, in get_dmabuf()
165 dev_err(s->dev, in get_dmabuf()
166 "sscape: Failed to allocate %lu bytes for DMA\n", in get_dmabuf()
176 * Release the DMA-able kernel memory ...
180 if (buf && buf->area) in free_dmabuf()
185 * This function writes to the SoundScape's control registers,
187 * This is why this function is "unsafe" ...
205 spin_lock_irqsave(&s->lock, flags); in sscape_write()
206 sscape_write_unsafe(s->io_base, reg, val); in sscape_write()
207 spin_unlock_irqrestore(&s->lock, flags); in sscape_write()
212 * locking to the caller. This is why the function is "unsafe" ...
238 * Read the SoundScape's host-mode control register, but leave
243 int data = -1; in host_read_unsafe()
251 * Read the SoundScape's host-mode control register, performing
252 * a limited amount of busy-waiting if the register isn't ready.
253 * Also leaves all locking-issues to the caller ...
261 --timeout; in host_read_ctrl_unsafe()
268 * Write to the SoundScape's host-mode control registers, but
282 * Write to the SoundScape's host-mode control registers, performing
283 * a limited amount of busy-waiting if the register isn't ready.
284 * Also leaves all locking-issues to the caller ...
293 --timeout; in host_write_ctrl_unsafe()
312 * This is apparently the standard way to initialise an MPU-401
344 * Wait for a DMA transfer to complete. This is a "limited busy-wait",
352 --timeout; in sscape_wait_dma_unsafe()
359 * Wait for the On-Board Processor to return its start-up
361 * us to perform "busy-waiting", and so we must sleep.
363 * spinlocks when we call this function.
373 spin_lock_irqsave(&s->lock, flags); in obp_startup_ack()
374 x = host_read_unsafe(s->io_base); in obp_startup_ack()
375 spin_unlock_irqrestore(&s->lock, flags); in obp_startup_ack()
386 * Wait for the host to return its start-up acknowledgement
388 * "busy-waiting", and so we must sleep. This in turn means
390 * this function.
400 spin_lock_irqsave(&s->lock, flags); in host_startup_ack()
401 x = host_read_unsafe(s->io_base); in host_startup_ack()
402 spin_unlock_irqrestore(&s->lock, flags); in host_startup_ack()
413 * Upload a byte-stream into the SoundScape using DMA channel A.
424 return -ENOMEM; in upload_dma_data()
426 spin_lock_irqsave(&s->lock, flags); in upload_dma_data()
431 val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG); in upload_dma_data()
432 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val & 0x3f); in upload_dma_data()
435 * Enable the DMA channels and configure them ... in upload_dma_data()
437 val = (s->chip->dma1 << 4) | DMA_8BIT; in upload_dma_data()
438 sscape_write_unsafe(s->io_base, GA_DMAA_REG, val); in upload_dma_data()
439 sscape_write_unsafe(s->io_base, GA_DMAB_REG, 0x20); in upload_dma_data()
444 val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG); in upload_dma_data()
445 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val | 0x80); in upload_dma_data()
457 size -= len; in upload_dma_data()
459 snd_dma_program(s->chip->dma1, dma.addr, len, DMA_MODE_WRITE); in upload_dma_data()
460 sscape_start_dma_unsafe(s->io_base, GA_DMAA_REG); in upload_dma_data()
461 if (!sscape_wait_dma_unsafe(s->io_base, GA_DMAA_REG, 5000)) { in upload_dma_data()
465 spin_unlock_irqrestore(&s->lock, flags); in upload_dma_data()
467 dev_err(s->dev, "sscape: DMA upload has timed out\n"); in upload_dma_data()
468 ret = -EAGAIN; in upload_dma_data()
473 set_host_mode_unsafe(s->io_base); in upload_dma_data()
474 outb(0x0, s->io_base); in upload_dma_data()
479 val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG); in upload_dma_data()
480 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val | 0x40); in upload_dma_data()
481 spin_unlock_irqrestore(&s->lock, flags); in upload_dma_data()
490 dev_err(s->dev, in upload_dma_data()
491 "sscape: No response from on-board processor after upload\n"); in upload_dma_data()
492 ret = -EAGAIN; in upload_dma_data()
494 dev_err(s->dev, "sscape: SoundScape failed to initialise\n"); in upload_dma_data()
495 ret = -EAGAIN; in upload_dma_data()
502 sscape_write(s, GA_DMAA_REG, (s->ic_type == IC_OPUS ? 0x40 : 0x70)); in upload_dma_data()
521 ret = request_firmware(&init_fw, "scope.cod", card->dev); in sscape_upload_bootblock()
523 dev_err(card->dev, "sscape: Error loading scope.cod"); in sscape_upload_bootblock()
526 ret = upload_dma_data(sscape, init_fw->data, init_fw->size); in sscape_upload_bootblock()
530 spin_lock_irqsave(&sscape->lock, flags); in sscape_upload_bootblock()
532 data = host_read_ctrl_unsafe(sscape->io_base, 100); in sscape_upload_bootblock()
535 sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2f); in sscape_upload_bootblock()
537 spin_unlock_irqrestore(&sscape->lock, flags); in sscape_upload_bootblock()
541 dev_err(card->dev, in sscape_upload_bootblock()
542 "sscape: timeout reading firmware version\n"); in sscape_upload_bootblock()
543 ret = -EAGAIN; in sscape_upload_bootblock()
561 err = request_firmware(&init_fw, name, card->dev); in sscape_upload_microcode()
563 dev_err(card->dev, "sscape: Error loading sndscape.co%d", in sscape_upload_microcode()
567 err = upload_dma_data(sscape, init_fw->data, init_fw->size); in sscape_upload_microcode()
569 dev_info(card->dev, "sscape: MIDI firmware loaded %zu KBs\n", in sscape_upload_microcode()
570 init_fw->size >> 10); in sscape_upload_microcode()
583 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in sscape_midi_info()
584 uinfo->count = 1; in sscape_midi_info()
585 uinfo->value.integer.min = 0; in sscape_midi_info()
586 uinfo->value.integer.max = 127; in sscape_midi_info()
594 struct snd_card *card = chip->card; in sscape_midi_get()
598 spin_lock_irqsave(&s->lock, flags); in sscape_midi_get()
599 uctl->value.integer.value[0] = s->midi_vol; in sscape_midi_get()
600 spin_unlock_irqrestore(&s->lock, flags); in sscape_midi_get()
608 struct snd_card *card = chip->card; in sscape_midi_put()
614 spin_lock_irqsave(&s->lock, flags); in sscape_midi_put()
616 new_val = uctl->value.integer.value[0] & 127; in sscape_midi_put()
619 * can send any volume-changing HOST commands ... in sscape_midi_put()
621 set_host_mode_unsafe(s->io_base); in sscape_midi_put()
626 * and then perform another volume-related command. Perhaps the in sscape_midi_put()
629 if (s->midi_vol == new_val) { in sscape_midi_put()
633 change = host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100) in sscape_midi_put()
634 && host_write_ctrl_unsafe(s->io_base, new_val, 100) in sscape_midi_put()
635 && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100) in sscape_midi_put()
636 && host_write_ctrl_unsafe(s->io_base, new_val, 100); in sscape_midi_put()
637 s->midi_vol = new_val; in sscape_midi_put()
643 set_midi_mode_unsafe(s->io_base); in sscape_midi_put()
645 spin_unlock_irqrestore(&s->lock, flags); in sscape_midi_put()
682 * Perform certain arcane port-checks to see whether there
691 spin_lock_irqsave(&s->lock, flags); in detect_sscape()
698 if ((inb(HOST_CTRL_IO(s->io_base)) & 0x78) != 0) in detect_sscape()
701 d = inb(ODIE_ADDR_IO(s->io_base)) & 0xf0; in detect_sscape()
706 s->ic_type = IC_ODIE; in detect_sscape()
708 s->ic_type = IC_OPUS; in detect_sscape()
712 outb(0xfa, ODIE_ADDR_IO(s->io_base)); in detect_sscape()
713 if ((inb(ODIE_ADDR_IO(s->io_base)) & 0x9f) != 0x0a) in detect_sscape()
716 outb(0xfe, ODIE_ADDR_IO(s->io_base)); in detect_sscape()
717 if ((inb(ODIE_ADDR_IO(s->io_base)) & 0x9f) != 0x0e) in detect_sscape()
720 outb(0xfe, ODIE_ADDR_IO(s->io_base)); in detect_sscape()
721 d = inb(ODIE_DATA_IO(s->io_base)); in detect_sscape()
722 if (s->type != SSCAPE_VIVO && (d & 0x9f) != 0x0e) in detect_sscape()
725 if (s->ic_type == IC_OPUS) in detect_sscape()
726 activate_ad1845_unsafe(s->io_base); in detect_sscape()
728 if (s->type == SSCAPE_VIVO) in detect_sscape()
731 d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG); in detect_sscape()
732 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0); in detect_sscape()
738 spin_unlock_irqrestore(&s->lock, flags); in detect_sscape()
740 spin_lock_irqsave(&s->lock, flags); in detect_sscape()
749 d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f; in detect_sscape()
750 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d); in detect_sscape()
753 s->type = MEDIA_FX; in detect_sscape()
755 d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG); in detect_sscape()
756 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0); in detect_sscape()
761 spin_unlock_irqrestore(&s->lock, flags); in detect_sscape()
763 spin_lock_irqsave(&s->lock, flags); in detect_sscape()
772 spin_unlock_irqrestore(&s->lock, flags); in detect_sscape()
777 * ALSA callback function, called when attempting to open the MIDI device.
785 dev_err(mpu->rmidi->card->dev, in mpu401_open()
786 "sscape: MIDI disabled, please load firmware\n"); in mpu401_open()
787 return -ENODEV; in mpu401_open()
794 * Initialise an MPU-401 subdevice for MIDI support on the SoundScape.
806 struct snd_mpu401 *mpu = rawmidi->private_data; in create_mpu401()
807 mpu->open_input = mpu401_open; in create_mpu401()
808 mpu->open_output = mpu401_open; in create_mpu401()
809 mpu->private_data = sscape; in create_mpu401()
832 switch (sscape->type) { in create_ad1845()
841 if (sscape->ic_type != IC_OPUS) in create_ad1845()
852 err = snd_wss_create(card, port, -1, irq, dma1, dma2, in create_ad1845()
857 if (sscape->type != SSCAPE_VIVO) { in create_ad1845()
864 spin_lock_irqsave(&chip->reg_lock, flags); in create_ad1845()
866 spin_unlock_irqrestore(&chip->reg_lock, flags); in create_ad1845()
873 dev_err(card->dev, in create_ad1845()
874 "sscape: No PCM device for AD1845 chip\n"); in create_ad1845()
880 dev_err(card->dev, in create_ad1845()
881 "sscape: No mixer device for AD1845 chip\n"); in create_ad1845()
884 if (chip->hardware != WSS_HW_AD1848) { in create_ad1845()
887 dev_err(card->dev, in create_ad1845()
888 "sscape: No timer device for AD1845 chip\n"); in create_ad1845()
893 if (sscape->type != SSCAPE_VIVO) { in create_ad1845()
897 dev_err(card->dev, in create_ad1845()
898 "sscape: Could not create MIDI mixer control\n"); in create_ad1845()
903 sscape->chip = chip; in create_ad1845()
930 * can detect and control this hardware ... in create_sscape()
932 io_res = devm_request_region(card->dev, port[dev], 8, "SoundScape"); in create_sscape()
934 dev_err(card->dev, in create_sscape()
935 "sscape: can't grab port 0x%lx\n", port[dev]); in create_sscape()
936 return -EBUSY; in create_sscape()
939 if (sscape->type == SSCAPE_VIVO) { in create_sscape()
940 wss_res = devm_request_region(card->dev, wss_port[dev], 4, in create_sscape()
943 dev_err(card->dev, "sscape: can't grab port 0x%lx\n", in create_sscape()
945 return -EBUSY; in create_sscape()
952 err = snd_devm_request_dma(card->dev, dma[dev], "SoundScape"); in create_sscape()
954 dev_err(card->dev, "sscape: can't grab DMA %d\n", dma[dev]); in create_sscape()
958 spin_lock_init(&sscape->lock); in create_sscape()
959 sscape->io_res = io_res; in create_sscape()
960 sscape->wss_res = wss_res; in create_sscape()
961 sscape->io_base = port[dev]; in create_sscape()
964 dev_err(card->dev, "sscape: hardware not detected at 0x%x\n", in create_sscape()
965 sscape->io_base); in create_sscape()
966 return -ENODEV; in create_sscape()
969 switch (sscape->type) { in create_sscape()
987 dev_info(card->dev, "sscape: %s card detected at 0x%x, using IRQ %d, DMA %d\n", in create_sscape()
988 name, sscape->io_base, irq[dev], dma[dev]); in create_sscape()
993 irq_cfg = get_irq_config(sscape->type, irq[dev]); in create_sscape()
995 dev_err(card->dev, "sscape: Invalid IRQ %d\n", irq[dev]); in create_sscape()
996 return -ENXIO; in create_sscape()
999 mpu_irq_cfg = get_irq_config(sscape->type, mpu_irq[dev]); in create_sscape()
1001 dev_err(card->dev, "sscape: Invalid IRQ %d\n", mpu_irq[dev]); in create_sscape()
1002 return -ENXIO; in create_sscape()
1006 * Tell the on-board devices where their resources are (I think - in create_sscape()
1009 spin_lock_irqsave(&sscape->lock, flags); in create_sscape()
1011 sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e); in create_sscape()
1012 sscape_write_unsafe(sscape->io_base, GA_SMCFGB_REG, 0x00); in create_sscape()
1015 * Enable and configure the DMA channels ... in create_sscape()
1017 sscape_write_unsafe(sscape->io_base, GA_DMACFG_REG, 0x50); in create_sscape()
1018 dma_cfg = (sscape->ic_type == IC_OPUS ? 0x40 : 0x70); in create_sscape()
1019 sscape_write_unsafe(sscape->io_base, GA_DMAA_REG, dma_cfg); in create_sscape()
1020 sscape_write_unsafe(sscape->io_base, GA_DMAB_REG, 0x20); in create_sscape()
1023 val = sscape_read_unsafe(sscape->io_base, GA_HMCTL_REG) & 0xF7; in create_sscape()
1026 sscape_write_unsafe(sscape->io_base, GA_HMCTL_REG, val | 0x10); in create_sscape()
1027 sscape_write_unsafe(sscape->io_base, GA_INTCFG_REG, 0xf0 | mpu_irq_cfg); in create_sscape()
1028 sscape_write_unsafe(sscape->io_base, in create_sscape()
1032 * Enable the master IRQ ... in create_sscape()
1034 sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x80); in create_sscape()
1036 spin_unlock_irqrestore(&sscape->lock, flags); in create_sscape()
1040 * detect the AD1845 device ... in create_sscape()
1045 dev_err(card->dev, in create_sscape()
1046 "sscape: No AD1845 device at 0x%lx, IRQ %d\n", in create_sscape()
1050 strcpy(card->driver, "SoundScape"); in create_sscape()
1051 strcpy(card->shortname, name); in create_sscape()
1052 snprintf(card->longname, sizeof(card->longname), in create_sscape()
1053 "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n", in create_sscape()
1054 name, sscape->chip->port, sscape->chip->irq, in create_sscape()
1055 sscape->chip->dma1, sscape->chip->dma2); in create_sscape()
1058 if (sscape->type != SSCAPE_VIVO) { in create_sscape()
1067 dev_err(card->dev, in create_sscape()
1068 "sscape: Failed to create MPU-401 device at 0x%lx\n", in create_sscape()
1076 spin_lock_irqsave(&sscape->lock, flags); in create_sscape()
1077 sscape->midi_vol = 0; in create_sscape()
1078 host_write_ctrl_unsafe(sscape->io_base, in create_sscape()
1080 host_write_ctrl_unsafe(sscape->io_base, in create_sscape()
1081 sscape->midi_vol, 100); in create_sscape()
1082 host_write_ctrl_unsafe(sscape->io_base, in create_sscape()
1084 host_write_ctrl_unsafe(sscape->io_base, in create_sscape()
1085 sscape->midi_vol, 100); in create_sscape()
1086 host_write_ctrl_unsafe(sscape->io_base, in create_sscape()
1088 host_write_ctrl_unsafe(sscape->io_base, in create_sscape()
1090 host_write_ctrl_unsafe(sscape->io_base, CMD_ACK, 100); in create_sscape()
1092 set_midi_mode_unsafe(sscape->io_base); in create_sscape()
1093 spin_unlock_irqrestore(&sscape->lock, flags); in create_sscape()
1113 "sscape: insufficient parameters, need IO, IRQ, MPU-IRQ and DMA\n"); in snd_sscape_match()
1132 sscape->dev = pdev; in snd_sscape_probe()
1133 sscape->type = SSCAPE; in snd_sscape_probe()
1143 dev_err(pdev, "sscape: Failed to register sound card\n"); in snd_sscape_probe()
1180 * Allow this function to fail *quietly* if all the ISA PnP in sscape_pnp_detect()
1185 return -ENOSPC; in sscape_pnp_detect()
1190 dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL); in sscape_pnp_detect()
1192 return -ENODEV; in sscape_pnp_detect()
1196 dev_info(&dev->dev, "sscape: device is inactive\n"); in sscape_pnp_detect()
1197 return -EBUSY; in sscape_pnp_detect()
1205 ret = snd_devm_card_new(&pcard->card->dev, in sscape_pnp_detect()
1212 sscape->dev = card->dev; in sscape_pnp_detect()
1217 if (!strncmp("ENS4081", pid->id, 7)) in sscape_pnp_detect()
1218 sscape->type = SSCAPE_VIVO; in sscape_pnp_detect()
1220 sscape->type = SSCAPE_PNP; in sscape_pnp_detect()
1229 if (sscape->type == SSCAPE_PNP) { in sscape_pnp_detect()
1243 dev_err(card->dev, "sscape: Failed to register sound card\n"); in sscape_pnp_detect()