28 #include <linux/module.h>
42 "{Genius,Sound Maker 3DX},"
44 "{Intel,AL440LX sound},"
45 "{NeoMagic,MagicWave 3DX}}");
90 MODULE_PARM_DESC(opl3sa3_ymode,
"Speaker size selection for 3D Enhancement mode: Desktop/Large Notebook/Small Notebook/HiFi.");
93 static int isa_registered;
94 static int pnp_registered;
95 static int pnpc_registered;
99 #define OPL3SA2_PM_CTRL 0x01
100 #define OPL3SA2_SYS_CTRL 0x02
101 #define OPL3SA2_IRQ_CONFIG 0x03
102 #define OPL3SA2_IRQ_STATUS 0x04
103 #define OPL3SA2_DMA_CONFIG 0x06
104 #define OPL3SA2_MASTER_LEFT 0x07
105 #define OPL3SA2_MASTER_RIGHT 0x08
106 #define OPL3SA2_MIC 0x09
107 #define OPL3SA2_MISC 0x0A
110 #define OPL3SA3_DGTL_DOWN 0x12
111 #define OPL3SA3_ANLG_DOWN 0x13
112 #define OPL3SA3_WIDE 0x14
113 #define OPL3SA3_BASS 0x15
114 #define OPL3SA3_TREBLE 0x16
117 #define OPL3SA2_PM_ADOWN 0x20
118 #define OPL3SA2_PM_PSV 0x04
119 #define OPL3SA2_PM_PDN 0x02
120 #define OPL3SA2_PM_PDX 0x01
122 #define OPL3SA2_PM_D0 0x00
123 #define OPL3SA2_PM_D3 (OPL3SA2_PM_ADOWN|OPL3SA2_PM_PSV|OPL3SA2_PM_PDN|OPL3SA2_PM_PDX)
141 #define PFX "opl3sa2: "
155 { .
id =
"YMH0020", .devs = { {
"YMH0021" } } },
157 { .id =
"YMH0030", .devs = { {
"YMH0021" } } },
159 { .id =
"YMH0800", .devs = { {
"YMH0021" } } },
161 { .id =
"YMH0801", .devs = { {
"YMH0021" } } },
163 { .id =
"NMX2200", .devs = { {
"YMH2210" } } },
165 { .id =
"NMX2200", .devs = { {
"NMX2210" } } },
187 port, result,
inb(port));
193 static unsigned char snd_opl3sa2_read(
struct snd_opl3sa2 *chip,
unsigned char reg)
199 result = __snd_opl3sa2_read(chip, reg);
200 spin_unlock_irqrestore(&chip->
reg_lock, flags);
205 static void __snd_opl3sa2_write(
struct snd_opl3sa2 *chip,
unsigned char reg,
unsigned char value)
216 static void snd_opl3sa2_write(
struct snd_opl3sa2 *chip,
unsigned char reg,
unsigned char value)
220 __snd_opl3sa2_write(chip, reg, value);
221 spin_unlock_irqrestore(&chip->
reg_lock, flags);
243 snd_printd(
"OPL3-SA [0x%lx] detect = 0x%x\n", port, tmp);
246 switch (tmp & 0x07) {
263 if ((tmp1 = snd_opl3sa2_read(chip,
OPL3SA2_MISC)) != tmp) {
264 snd_printd(
"OPL3-SA [0x%lx] detect (1) = 0x%x (0x%x)\n", port, tmp, tmp1);
270 if (((tmp1 = snd_opl3sa2_read(chip,
OPL3SA2_MIC)) & 0x9f) != 0x8a) {
271 snd_printd(
"OPL3-SA [0x%lx] detect (2) = 0x%x (0x%x)\n", port, tmp, tmp1);
291 snd_opl3sa2_write(chip,
OPL3SA2_MISC, 0x80 | (tmp & 7));
317 if ((status & 0x10) && chip->
rmidi !=
NULL) {
342 #define OPL3SA2_SINGLE(xname, xindex, reg, shift, mask, invert) \
343 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
344 .info = snd_wss_info_single, \
345 .get = snd_opl3sa2_get_single, .put = snd_opl3sa2_put_single, \
346 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
347 #define OPL3SA2_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv) \
348 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
349 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
350 .name = xname, .index = xindex, \
351 .info = snd_wss_info_single, \
352 .get = snd_opl3sa2_get_single, .put = snd_opl3sa2_put_single, \
353 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24), \
354 .tlv = { .p = (xtlv) } }
366 ucontrol->
value.integer.value[0] = (chip->
ctlregs[
reg] >> shift) & mask;
367 spin_unlock_irqrestore(&chip->
reg_lock, flags);
369 ucontrol->
value.integer.value[0] = mask - ucontrol->
value.integer.value[0];
382 unsigned short val, oval;
384 val = (ucontrol->
value.integer.value[0] &
mask);
390 val = (oval & ~(mask << shift)) |
val;
391 change = val != oval;
392 __snd_opl3sa2_write(chip, reg, val);
393 spin_unlock_irqrestore(&chip->
reg_lock, flags);
397 #define OPL3SA2_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
398 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
399 .info = snd_wss_info_double, \
400 .get = snd_opl3sa2_get_double, .put = snd_opl3sa2_put_double, \
401 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
402 #define OPL3SA2_DOUBLE_TLV(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert, xtlv) \
403 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
404 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
405 .name = xname, .index = xindex, \
406 .info = snd_wss_info_double, \
407 .get = snd_opl3sa2_get_double, .put = snd_opl3sa2_put_double, \
408 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22), \
409 .tlv = { .p = (xtlv) } }
423 ucontrol->
value.integer.value[0] = (chip->
ctlregs[left_reg] >> shift_left) & mask;
425 spin_unlock_irqrestore(&chip->
reg_lock, flags);
427 ucontrol->
value.integer.value[0] = mask - ucontrol->
value.integer.value[0];
428 ucontrol->
value.integer.value[1] = mask - ucontrol->
value.integer.value[1];
444 unsigned short val1, val2, oval1, oval2;
446 val1 = ucontrol->
value.integer.value[0] &
mask;
447 val2 = ucontrol->
value.integer.value[1] &
mask;
455 if (left_reg != right_reg) {
456 oval1 = chip->
ctlregs[left_reg];
457 oval2 = chip->
ctlregs[right_reg];
458 val1 = (oval1 & ~(mask << shift_left)) | val1;
460 change = val1 != oval1 || val2 != oval2;
461 __snd_opl3sa2_write(chip, left_reg, val1);
462 __snd_opl3sa2_write(chip, right_reg, val2);
464 oval1 = chip->
ctlregs[left_reg];
465 val1 = (oval1 & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
466 change = val1 != oval1;
467 __snd_opl3sa2_write(chip, left_reg, val1);
469 spin_unlock_irqrestore(&chip->
reg_lock, flags);
477 OPL3SA2_DOUBLE(
"Master Playback Switch", 0, 0x07, 0x08, 7, 7, 1, 1),
482 db_scale_5bit_12db_max),
489 OPL3SA2_DOUBLE(
"Tone Control - Treble", 0, 0x16, 0x16, 4, 0, 7, 0)
492 static void snd_opl3sa2_master_free(
struct snd_kcontrol *kcontrol)
537 for (idx = 0; idx <
ARRAY_SIZE(snd_opl3sa2_controls); idx++) {
546 for (idx = 0; idx <
ARRAY_SIZE(snd_opl3sa2_tone_controls); idx++)
561 chip->
wss->suspend(chip->
wss);
569 static int snd_opl3sa2_resume(
struct snd_card *card)
582 for (i = 2; i <= 0x0a; i++) {
584 snd_opl3sa2_write(chip, i, chip->
ctlregs[i]);
587 for (i = 0x12; i <= 0x16; i++)
588 snd_opl3sa2_write(chip, i, chip->
ctlregs[i]);
591 chip->
wss->resume(chip->
wss);
606 sb_port[
dev] = pnp_port_start(pdev, 0);
607 wss_port[
dev] = pnp_port_start(pdev, 1);
608 fm_port[
dev] = pnp_port_start(pdev, 2);
609 midi_port[
dev] = pnp_port_start(pdev, 3);
610 port[
dev] = pnp_port_start(pdev, 4);
614 snd_printdd(
"%sPnP OPL3-SA: sb port=0x%lx, wss port=0x%lx, fm port=0x%lx, midi port=0x%lx\n",
615 pnp_device_is_pnpbios(pdev) ?
"BIOS" :
"ISA", sb_port[dev], wss_port[dev], fm_port[dev], midi_port[dev]);
616 snd_printdd(
"%sPnP OPL3-SA: control port=0x%lx, dma1=%i, dma2=%i, irq=%i\n",
622 static void snd_opl3sa2_free(
struct snd_card *card)
630 static int snd_opl3sa2_card_new(
int dev,
struct snd_card **cardp)
652 int xirq, xdma1, xdma2;
660 chip->
ymode = opl3sa3_ymode[
dev] & 0x03 ;
667 err = snd_opl3sa2_detect(card);
678 wss_port[dev] + 4, -1,
682 snd_printd(
"Oops, WSS not detected at 0x%lx\n", wss_port[dev] + 4);
692 err = snd_opl3sa2_mixer(card);
698 if (fm_port[dev] >= 0x340 && fm_port[dev] < 0x400) {
708 if (midi_port[dev] >= 0x300 && midi_port[dev] < 0x340) {
734 if (
enable[dev] && isapnp[dev])
737 if (dev >= SNDRV_CARDS)
740 err = snd_opl3sa2_card_new(dev, &card);
743 if ((err = snd_opl3sa2_pnp(dev, card->
private_data, pdev)) < 0) {
748 if ((err = snd_opl3sa2_probe(card, dev)) < 0) {
752 pnp_set_drvdata(pdev, card);
760 pnp_set_drvdata(pdev,
NULL);
766 return snd_opl3sa2_suspend(pnp_get_drvdata(pdev), state);
768 static int snd_opl3sa2_pnp_resume(
struct pnp_dev *pdev)
770 return snd_opl3sa2_resume(pnp_get_drvdata(pdev));
774 static struct pnp_driver opl3sa2_pnp_driver = {
775 .
name =
"snd-opl3sa2-pnpbios",
776 .id_table = snd_opl3sa2_pnpbiosids,
777 .probe = snd_opl3sa2_pnp_detect,
780 .suspend = snd_opl3sa2_pnp_suspend,
781 .resume = snd_opl3sa2_pnp_resume,
800 if (
enable[dev] && isapnp[dev])
803 if (dev >= SNDRV_CARDS)
806 err = snd_opl3sa2_card_new(dev, &card);
809 if ((err = snd_opl3sa2_pnp(dev, card->
private_data, pdev)) < 0) {
814 if ((err = snd_opl3sa2_probe(card, dev)) < 0) {
818 pnp_set_card_drvdata(pcard, card);
826 pnp_set_card_drvdata(pcard,
NULL);
832 return snd_opl3sa2_suspend(pnp_get_card_drvdata(pcard), state);
834 static int snd_opl3sa2_pnp_cresume(
struct pnp_card_link *pcard)
836 return snd_opl3sa2_resume(pnp_get_card_drvdata(pcard));
842 .name =
"snd-opl3sa2-cpnp",
843 .id_table = snd_opl3sa2_pnpids,
844 .probe = snd_opl3sa2_pnp_cdetect,
847 .suspend = snd_opl3sa2_pnp_csuspend,
848 .resume = snd_opl3sa2_pnp_cresume,
887 err = snd_opl3sa2_card_new(dev, &card);
891 if ((err = snd_opl3sa2_probe(card, dev)) < 0) {
908 static int snd_opl3sa2_isa_suspend(
struct device *dev,
unsigned int n,
914 static int snd_opl3sa2_isa_resume(
struct device *dev,
unsigned int n)
920 #define DEV_NAME "opl3sa2"
922 static struct isa_driver snd_opl3sa2_isa_driver = {
923 .match = snd_opl3sa2_isa_match,
924 .probe = snd_opl3sa2_isa_probe,
927 .suspend = snd_opl3sa2_isa_suspend,
928 .resume = snd_opl3sa2_isa_resume,
935 static int __init alsa_card_opl3sa2_init(
void)
952 if (isa_registered || pnp_registered)
958 static void __exit alsa_card_opl3sa2_exit(
void)