Lines Matching +full:invert +full:- +full:enable

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for Yamaha OPL3-SA[2,3] soundcards
26 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
28 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ variable
30 static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
43 MODULE_PARM_DESC(index, "Index value for OPL3-SA soundcard.");
45 MODULE_PARM_DESC(id, "ID string for OPL3-SA soundcard.");
46 module_param_array(enable, bool, NULL, 0444);
47 MODULE_PARM_DESC(enable, "Enable OPL3-SA soundcard.");
53 MODULE_PARM_DESC(port, "Port # for OPL3-SA driver.");
55 MODULE_PARM_DESC(sb_port, "SB port # for OPL3-SA driver.");
57 MODULE_PARM_DESC(wss_port, "WSS port # for OPL3-SA driver.");
59 MODULE_PARM_DESC(fm_port, "FM port # for OPL3-SA driver.");
61 MODULE_PARM_DESC(midi_port, "MIDI port # for OPL3-SA driver.");
63 MODULE_PARM_DESC(irq, "IRQ # for OPL3-SA driver.");
65 MODULE_PARM_DESC(dma1, "DMA1 # for OPL3-SA driver.");
67 MODULE_PARM_DESC(dma2, "DMA2 # for OPL3-SA driver.");
134 /* Yamaha YMF719E-S (Genius Sound Maker 3DX) */
136 /* Yamaha OPL3-SA3 (integrated on Intel's Pentium II AL440LX motherboard) */
138 /* Yamaha OPL3-SA2 */
140 /* Yamaha OPL3-SA2 */
146 /* --- */
161 dev_dbg(chip->card->dev, "read [0x%lx] = 0x%x\n", port, inb(port)); in __snd_opl3sa2_read()
163 outb(reg, chip->port); /* register */ in __snd_opl3sa2_read()
164 result = inb(chip->port + 1); in __snd_opl3sa2_read()
166 dev_dbg(chip->card->dev, "read [0x%lx] = 0x%x [0x%x]\n", in __snd_opl3sa2_read()
178 spin_lock_irqsave(&chip->reg_lock, flags); in snd_opl3sa2_read()
180 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_opl3sa2_read()
190 outb(reg, chip->port); /* register */ in __snd_opl3sa2_write()
191 outb(value, chip->port + 1); in __snd_opl3sa2_write()
192 chip->ctlregs[reg] = value; in __snd_opl3sa2_write()
199 spin_lock_irqsave(&chip->reg_lock, flags); in snd_opl3sa2_write()
201 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_opl3sa2_write()
206 struct snd_opl3sa2 *chip = card->private_data; in snd_opl3sa2_detect()
211 port = chip->port; in snd_opl3sa2_detect()
212 chip->res_port = devm_request_region(card->dev, port, 2, in snd_opl3sa2_detect()
213 "OPL3-SA control"); in snd_opl3sa2_detect()
214 if (!chip->res_port) { in snd_opl3sa2_detect()
215 dev_err(card->dev, "can't grab port 0x%lx\n", port); in snd_opl3sa2_detect()
216 return -EBUSY; in snd_opl3sa2_detect()
218 chip->version = 0; in snd_opl3sa2_detect()
221 dev_dbg(card->dev, "OPL3-SA [0x%lx] detect = 0x%x\n", port, tmp); in snd_opl3sa2_detect()
222 return -ENODEV; in snd_opl3sa2_detect()
226 chip->version = 2; /* YMF711 */ in snd_opl3sa2_detect()
229 chip->version = 3; in snd_opl3sa2_detect()
230 /* 0x02 - standard */ in snd_opl3sa2_detect()
231 /* 0x03 - YM715B */ in snd_opl3sa2_detect()
232 /* 0x04 - YM719 - OPL-SA4? */ in snd_opl3sa2_detect()
233 /* 0x05 - OPL3-SA3 - Libretto 100 */ in snd_opl3sa2_detect()
234 /* 0x07 - unknown - Neomagic MagicWave 3D */ in snd_opl3sa2_detect()
237 str[0] = chip->version + '0'; in snd_opl3sa2_detect()
239 strcat(card->shortname, str); in snd_opl3sa2_detect()
243 dev_dbg(card->dev, "OPL3-SA [0x%lx] detect (1) = 0x%x (0x%x)\n", port, tmp, tmp1); in snd_opl3sa2_detect()
244 return -ENODEV; in snd_opl3sa2_detect()
251 dev_dbg(card->dev, "OPL3-SA [0x%lx] detect (2) = 0x%x (0x%x)\n", port, tmp, tmp1); in snd_opl3sa2_detect()
252 return -ENODEV; in snd_opl3sa2_detect()
256 /* Power Management - full on */ in snd_opl3sa2_detect()
258 if (chip->version > 2) { in snd_opl3sa2_detect()
260 snd_opl3sa2_write(chip, OPL3SA2_SYS_CTRL, (chip->ymode << 4)); in snd_opl3sa2_detect()
265 …snd_opl3sa2_write(chip, OPL3SA2_IRQ_CONFIG, 0x0d); /* Interrupt Channel Configuration - IRQ A = OP… in snd_opl3sa2_detect()
266 if (chip->single_dma) { in snd_opl3sa2_detect()
267 snd_opl3sa2_write(chip, OPL3SA2_DMA_CONFIG, 0x03); /* DMA Configuration - DMA A = WSS-R + WSS-P */ in snd_opl3sa2_detect()
269 …l3sa2_write(chip, OPL3SA2_DMA_CONFIG, 0x21); /* DMA Configuration - DMA B = WSS-R, DMA A = WSS-P */ in snd_opl3sa2_detect()
271 snd_opl3sa2_write(chip, OPL3SA2_MISC, 0x80 | (tmp & 7)); /* Miscellaneous - default */ in snd_opl3sa2_detect()
272 if (chip->version > 2) { in snd_opl3sa2_detect()
273 snd_opl3sa2_write(chip, OPL3SA3_DGTL_DOWN, 0x00); /* Digital Block Partial Power Down - default */ in snd_opl3sa2_detect()
274 snd_opl3sa2_write(chip, OPL3SA3_ANLG_DOWN, 0x00); /* Analog Block Partial Power Down - default */ in snd_opl3sa2_detect()
289 chip = card->private_data; in snd_opl3sa2_interrupt()
294 snd_opl3_interrupt(chip->synth); in snd_opl3sa2_interrupt()
297 if ((status & 0x10) && chip->rmidi != NULL) { in snd_opl3sa2_interrupt()
299 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data); in snd_opl3sa2_interrupt()
304 snd_wss_interrupt(irq, chip->wss); in snd_opl3sa2_interrupt()
312 if (chip->master_switch && chip->master_volume) { in snd_opl3sa2_interrupt()
314 &chip->master_switch->id); in snd_opl3sa2_interrupt()
316 &chip->master_volume->id); in snd_opl3sa2_interrupt()
322 #define OPL3SA2_SINGLE(xname, xindex, reg, shift, mask, invert) \ argument
326 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
327 #define OPL3SA2_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv) \ argument
333 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24), \
340 int reg = kcontrol->private_value & 0xff; in snd_opl3sa2_get_single()
341 int shift = (kcontrol->private_value >> 8) & 0xff; in snd_opl3sa2_get_single()
342 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_opl3sa2_get_single()
343 int invert = (kcontrol->private_value >> 24) & 0xff; in snd_opl3sa2_get_single() local
345 spin_lock_irqsave(&chip->reg_lock, flags); in snd_opl3sa2_get_single()
346 ucontrol->value.integer.value[0] = (chip->ctlregs[reg] >> shift) & mask; in snd_opl3sa2_get_single()
347 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_opl3sa2_get_single()
348 if (invert) in snd_opl3sa2_get_single()
349 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; in snd_opl3sa2_get_single()
357 int reg = kcontrol->private_value & 0xff; in snd_opl3sa2_put_single()
358 int shift = (kcontrol->private_value >> 8) & 0xff; in snd_opl3sa2_put_single()
359 int mask = (kcontrol->private_value >> 16) & 0xff; in snd_opl3sa2_put_single()
360 int invert = (kcontrol->private_value >> 24) & 0xff; in snd_opl3sa2_put_single() local
364 val = (ucontrol->value.integer.value[0] & mask); in snd_opl3sa2_put_single()
365 if (invert) in snd_opl3sa2_put_single()
366 val = mask - val; in snd_opl3sa2_put_single()
368 spin_lock_irqsave(&chip->reg_lock, flags); in snd_opl3sa2_put_single()
369 oval = chip->ctlregs[reg]; in snd_opl3sa2_put_single()
373 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_opl3sa2_put_single()
377 #define OPL3SA2_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ argument
381 …reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
382 …L3SA2_DOUBLE_TLV(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert, xtlv) \ argument
388 …eg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22), \
395 int left_reg = kcontrol->private_value & 0xff; in snd_opl3sa2_get_double()
396 int right_reg = (kcontrol->private_value >> 8) & 0xff; in snd_opl3sa2_get_double()
397 int shift_left = (kcontrol->private_value >> 16) & 0x07; in snd_opl3sa2_get_double()
398 int shift_right = (kcontrol->private_value >> 19) & 0x07; in snd_opl3sa2_get_double()
399 int mask = (kcontrol->private_value >> 24) & 0xff; in snd_opl3sa2_get_double()
400 int invert = (kcontrol->private_value >> 22) & 1; in snd_opl3sa2_get_double() local
402 spin_lock_irqsave(&chip->reg_lock, flags); in snd_opl3sa2_get_double()
403 ucontrol->value.integer.value[0] = (chip->ctlregs[left_reg] >> shift_left) & mask; in snd_opl3sa2_get_double()
404 ucontrol->value.integer.value[1] = (chip->ctlregs[right_reg] >> shift_right) & mask; in snd_opl3sa2_get_double()
405 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_opl3sa2_get_double()
406 if (invert) { in snd_opl3sa2_get_double()
407 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; in snd_opl3sa2_get_double()
408 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; in snd_opl3sa2_get_double()
417 int left_reg = kcontrol->private_value & 0xff; in snd_opl3sa2_put_double()
418 int right_reg = (kcontrol->private_value >> 8) & 0xff; in snd_opl3sa2_put_double()
419 int shift_left = (kcontrol->private_value >> 16) & 0x07; in snd_opl3sa2_put_double()
420 int shift_right = (kcontrol->private_value >> 19) & 0x07; in snd_opl3sa2_put_double()
421 int mask = (kcontrol->private_value >> 24) & 0xff; in snd_opl3sa2_put_double()
422 int invert = (kcontrol->private_value >> 22) & 1; in snd_opl3sa2_put_double() local
426 val1 = ucontrol->value.integer.value[0] & mask; in snd_opl3sa2_put_double()
427 val2 = ucontrol->value.integer.value[1] & mask; in snd_opl3sa2_put_double()
428 if (invert) { in snd_opl3sa2_put_double()
429 val1 = mask - val1; in snd_opl3sa2_put_double()
430 val2 = mask - val2; in snd_opl3sa2_put_double()
434 spin_lock_irqsave(&chip->reg_lock, flags); in snd_opl3sa2_put_double()
436 oval1 = chip->ctlregs[left_reg]; in snd_opl3sa2_put_double()
437 oval2 = chip->ctlregs[right_reg]; in snd_opl3sa2_put_double()
444 oval1 = chip->ctlregs[left_reg]; in snd_opl3sa2_put_double()
449 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_opl3sa2_put_double()
453 static const DECLARE_TLV_DB_SCALE(db_scale_master, -3000, 200, 0);
454 static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
467 OPL3SA2_DOUBLE("3D Control - Wide", 0, 0x14, 0x14, 4, 0, 7, 0),
468 OPL3SA2_DOUBLE("Tone Control - Bass", 0, 0x15, 0x15, 4, 0, 7, 0),
469 OPL3SA2_DOUBLE("Tone Control - Treble", 0, 0x16, 0x16, 4, 0, 7, 0)
475 chip->master_switch = NULL; in snd_opl3sa2_master_free()
476 chip->master_volume = NULL; in snd_opl3sa2_master_free()
481 struct snd_opl3sa2 *chip = card->private_data; in snd_opl3sa2_mixer()
495 dev_err(card->dev, "Cannot rename opl3sa2 control\n"); in snd_opl3sa2_mixer()
502 dev_err(card->dev, "Cannot rename opl3sa2 control\n"); in snd_opl3sa2_mixer()
510 dev_err(card->dev, "Cannot rename opl3sa2 control\n"); in snd_opl3sa2_mixer()
517 dev_err(card->dev, "Cannot rename opl3sa2 control\n"); in snd_opl3sa2_mixer()
527 case 0: chip->master_switch = kctl; kctl->private_free = snd_opl3sa2_master_free; break; in snd_opl3sa2_mixer()
528 case 1: chip->master_volume = kctl; kctl->private_free = snd_opl3sa2_master_free; break; in snd_opl3sa2_mixer()
531 if (chip->version > 2) { in snd_opl3sa2_mixer()
546 struct snd_opl3sa2 *chip = card->private_data; in snd_opl3sa2_suspend()
549 chip->wss->suspend(chip->wss); in snd_opl3sa2_suspend()
565 chip = card->private_data; in snd_opl3sa2_resume()
572 snd_opl3sa2_write(chip, i, chip->ctlregs[i]); in snd_opl3sa2_resume()
574 if (chip->version > 2) { in snd_opl3sa2_resume()
576 snd_opl3sa2_write(chip, i, chip->ctlregs[i]); in snd_opl3sa2_resume()
579 chip->wss->resume(chip->wss); in snd_opl3sa2_resume()
591 dev_err(chip->card->dev, "PnP configure failure (out of resources?)\n"); in snd_opl3sa2_pnp()
592 return -EBUSY; in snd_opl3sa2_pnp()
602 …dev_dbg(chip->card->dev, "%sPnP OPL3-SA: sb port=0x%lx, wss port=0x%lx, fm port=0x%lx, midi port=0… in snd_opl3sa2_pnp()
604 dev_dbg(chip->card->dev, "%sPnP OPL3-SA: control port=0x%lx, dma1=%i, dma2=%i, irq=%i\n", in snd_opl3sa2_pnp()
621 strcpy(card->driver, "OPL3SA2"); in snd_opl3sa2_card_new()
622 strcpy(card->shortname, "Yamaha OPL3-SA"); in snd_opl3sa2_card_new()
623 chip = card->private_data; in snd_opl3sa2_card_new()
624 spin_lock_init(&chip->reg_lock); in snd_opl3sa2_card_new()
625 chip->irq = -1; in snd_opl3sa2_card_new()
639 chip = card->private_data; in snd_opl3sa2_probe()
640 chip->card = card; in snd_opl3sa2_probe()
641 chip->ymode = opl3sa3_ymode[dev] & 0x03 ; in snd_opl3sa2_probe()
642 chip->port = port[dev]; in snd_opl3sa2_probe()
647 chip->single_dma = 1; in snd_opl3sa2_probe()
651 err = devm_request_irq(card->dev, xirq, snd_opl3sa2_interrupt, 0, in snd_opl3sa2_probe()
652 "OPL3-SA2", card); in snd_opl3sa2_probe()
654 dev_err(card->dev, "can't grab IRQ %d\n", xirq); in snd_opl3sa2_probe()
655 return -ENODEV; in snd_opl3sa2_probe()
657 chip->irq = xirq; in snd_opl3sa2_probe()
658 card->sync_irq = chip->irq; in snd_opl3sa2_probe()
660 wss_port[dev] + 4, -1, in snd_opl3sa2_probe()
664 dev_dbg(card->dev, "Oops, WSS not detected at 0x%lx\n", wss_port[dev] + 4); in snd_opl3sa2_probe()
667 chip->wss = wss; in snd_opl3sa2_probe()
689 err = snd_opl3_hwdep_new(opl3, 0, 1, &chip->synth); in snd_opl3sa2_probe()
696 MPU401_INFO_IRQ_HOOK, -1, in snd_opl3sa2_probe()
697 &chip->rmidi); in snd_opl3sa2_probe()
701 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", in snd_opl3sa2_probe()
702 card->shortname, chip->port, xirq, xdma1); in snd_opl3sa2_probe()
704 sprintf(card->longname + strlen(card->longname), "&%d", xdma2); in snd_opl3sa2_probe()
718 return -ENOENT; /* we have another procedure - card */ in snd_opl3sa2_pnp_detect()
720 if (enable[dev] && isapnp[dev]) in snd_opl3sa2_pnp_detect()
724 return -ENODEV; in snd_opl3sa2_pnp_detect()
726 err = snd_opl3sa2_card_new(&pdev->dev, dev, &card); in snd_opl3sa2_pnp_detect()
729 err = snd_opl3sa2_pnp(dev, card->private_data, pdev); in snd_opl3sa2_pnp_detect()
752 .name = "snd-opl3sa2-pnpbios",
769 pdev = pnp_request_card_device(pcard, id->devs[0].id, NULL); in snd_opl3sa2_pnp_cdetect()
771 dev_err(&pcard->card->dev, "can't get pnp device from id '%s'\n", in snd_opl3sa2_pnp_cdetect()
772 id->devs[0].id); in snd_opl3sa2_pnp_cdetect()
773 return -EBUSY; in snd_opl3sa2_pnp_cdetect()
776 if (enable[dev] && isapnp[dev]) in snd_opl3sa2_pnp_cdetect()
780 return -ENODEV; in snd_opl3sa2_pnp_cdetect()
782 err = snd_opl3sa2_card_new(&pdev->dev, dev, &card); in snd_opl3sa2_pnp_cdetect()
785 err = snd_opl3sa2_pnp(dev, card->private_data, pdev); in snd_opl3sa2_pnp_cdetect()
809 .name = "snd-opl3sa2-cpnp",
822 if (!enable[dev]) in snd_opl3sa2_isa_match()