Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Driver for Yamaha OPL3-SA[2,3] soundcards |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 4 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/init.h> |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 8 | #include <linux/err.h> |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 9 | #include <linux/isa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/interrupt.h> |
| 11 | #include <linux/pm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/pnp.h> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 13 | #include <linux/module.h> |
Takashi Iwai | 6cbbfe1 | 2015-01-28 16:49:33 +0100 | [diff] [blame] | 14 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <sound/core.h> |
Krzysztof Helt | 61ef19d | 2008-07-31 21:02:42 +0200 | [diff] [blame] | 16 | #include <sound/wss.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <sound/mpu401.h> |
| 18 | #include <sound/opl3.h> |
| 19 | #include <sound/initval.h> |
Takashi Iwai | a1c7a7d | 2006-08-22 13:16:39 +0200 | [diff] [blame] | 20 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 22 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | MODULE_DESCRIPTION("Yamaha OPL3SA2+"); |
| 24 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 27 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 28 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #ifdef CONFIG_PNP |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 30 | static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #endif |
| 32 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0xf86,0x370,0x100 */ |
| 33 | static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */ |
| 34 | static long wss_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* 0x530,0xe80,0xf40,0x604 */ |
| 35 | static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x388 */ |
| 36 | static long midi_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* 0x330,0x300 */ |
| 37 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 0,1,3,5,9,11,12,15 */ |
| 38 | static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */ |
| 39 | static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */ |
Takashi Iwai | 6581f4e | 2006-05-17 17:14:51 +0200 | [diff] [blame] | 40 | static int opl3sa3_ymode[SNDRV_CARDS]; /* 0,1,2,3 */ /*SL Added*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | module_param_array(index, int, NULL, 0444); |
| 43 | MODULE_PARM_DESC(index, "Index value for OPL3-SA soundcard."); |
| 44 | module_param_array(id, charp, NULL, 0444); |
| 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."); |
| 48 | #ifdef CONFIG_PNP |
| 49 | module_param_array(isapnp, bool, NULL, 0444); |
| 50 | MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard."); |
| 51 | #endif |
David Howells | e992ef5 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 52 | module_param_hw_array(port, long, ioport, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | MODULE_PARM_DESC(port, "Port # for OPL3-SA driver."); |
David Howells | e992ef5 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 54 | module_param_hw_array(sb_port, long, ioport, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | MODULE_PARM_DESC(sb_port, "SB port # for OPL3-SA driver."); |
David Howells | e992ef5 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 56 | module_param_hw_array(wss_port, long, ioport, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | MODULE_PARM_DESC(wss_port, "WSS port # for OPL3-SA driver."); |
David Howells | e992ef5 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 58 | module_param_hw_array(fm_port, long, ioport, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | MODULE_PARM_DESC(fm_port, "FM port # for OPL3-SA driver."); |
David Howells | e992ef5 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 60 | module_param_hw_array(midi_port, long, ioport, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | MODULE_PARM_DESC(midi_port, "MIDI port # for OPL3-SA driver."); |
David Howells | e992ef5 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 62 | module_param_hw_array(irq, int, irq, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | MODULE_PARM_DESC(irq, "IRQ # for OPL3-SA driver."); |
David Howells | e992ef5 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 64 | module_param_hw_array(dma1, int, dma, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | MODULE_PARM_DESC(dma1, "DMA1 # for OPL3-SA driver."); |
David Howells | e992ef5 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 66 | module_param_hw_array(dma2, int, dma, NULL, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | MODULE_PARM_DESC(dma2, "DMA2 # for OPL3-SA driver."); |
| 68 | module_param_array(opl3sa3_ymode, int, NULL, 0444); |
| 69 | MODULE_PARM_DESC(opl3sa3_ymode, "Speaker size selection for 3D Enhancement mode: Desktop/Large Notebook/Small Notebook/HiFi."); |
| 70 | |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 71 | #ifdef CONFIG_PNP |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 72 | static int isa_registered; |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 73 | static int pnp_registered; |
| 74 | static int pnpc_registered; |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 75 | #endif |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | /* control ports */ |
| 78 | #define OPL3SA2_PM_CTRL 0x01 |
| 79 | #define OPL3SA2_SYS_CTRL 0x02 |
| 80 | #define OPL3SA2_IRQ_CONFIG 0x03 |
| 81 | #define OPL3SA2_IRQ_STATUS 0x04 |
| 82 | #define OPL3SA2_DMA_CONFIG 0x06 |
| 83 | #define OPL3SA2_MASTER_LEFT 0x07 |
| 84 | #define OPL3SA2_MASTER_RIGHT 0x08 |
| 85 | #define OPL3SA2_MIC 0x09 |
| 86 | #define OPL3SA2_MISC 0x0A |
| 87 | |
| 88 | /* opl3sa3 only */ |
| 89 | #define OPL3SA3_DGTL_DOWN 0x12 |
| 90 | #define OPL3SA3_ANLG_DOWN 0x13 |
| 91 | #define OPL3SA3_WIDE 0x14 |
| 92 | #define OPL3SA3_BASS 0x15 |
| 93 | #define OPL3SA3_TREBLE 0x16 |
| 94 | |
| 95 | /* power management bits */ |
| 96 | #define OPL3SA2_PM_ADOWN 0x20 |
| 97 | #define OPL3SA2_PM_PSV 0x04 |
| 98 | #define OPL3SA2_PM_PDN 0x02 |
| 99 | #define OPL3SA2_PM_PDX 0x01 |
| 100 | |
| 101 | #define OPL3SA2_PM_D0 0x00 |
| 102 | #define OPL3SA2_PM_D3 (OPL3SA2_PM_ADOWN|OPL3SA2_PM_PSV|OPL3SA2_PM_PDN|OPL3SA2_PM_PDX) |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | struct snd_opl3sa2 { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | int version; /* 2 or 3 */ |
| 106 | unsigned long port; /* control port */ |
| 107 | struct resource *res_port; /* control port resource */ |
| 108 | int irq; |
| 109 | int single_dma; |
| 110 | spinlock_t reg_lock; |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 111 | struct snd_hwdep *synth; |
| 112 | struct snd_rawmidi *rmidi; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 113 | struct snd_wss *wss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | unsigned char ctlregs[0x20]; |
| 115 | int ymode; /* SL added */ |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 116 | struct snd_kcontrol *master_switch; |
| 117 | struct snd_kcontrol *master_volume; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 120 | #define PFX "opl3sa2: " |
| 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | #ifdef CONFIG_PNP |
| 123 | |
Arvind Yadav | 607b5d7 | 2017-08-17 15:36:18 +0530 | [diff] [blame] | 124 | static const struct pnp_device_id snd_opl3sa2_pnpbiosids[] = { |
Jaroslav Kysela | 53b2666 | 2005-08-12 17:35:09 +0200 | [diff] [blame] | 125 | { .id = "YMH0021" }, |
Jaroslav Kysela | 1265509c | 2005-08-12 17:24:24 +0200 | [diff] [blame] | 126 | { .id = "NMX2210" }, /* Gateway Solo 2500 */ |
| 127 | { .id = "" } /* end */ |
| 128 | }; |
| 129 | |
| 130 | MODULE_DEVICE_TABLE(pnp, snd_opl3sa2_pnpbiosids); |
| 131 | |
Arvind Yadav | 607b5d7 | 2017-08-17 15:36:18 +0530 | [diff] [blame] | 132 | static const struct pnp_card_device_id snd_opl3sa2_pnpids[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | /* Yamaha YMF719E-S (Genius Sound Maker 3DX) */ |
| 134 | { .id = "YMH0020", .devs = { { "YMH0021" } } }, |
| 135 | /* Yamaha OPL3-SA3 (integrated on Intel's Pentium II AL440LX motherboard) */ |
| 136 | { .id = "YMH0030", .devs = { { "YMH0021" } } }, |
| 137 | /* Yamaha OPL3-SA2 */ |
| 138 | { .id = "YMH0800", .devs = { { "YMH0021" } } }, |
| 139 | /* Yamaha OPL3-SA2 */ |
| 140 | { .id = "YMH0801", .devs = { { "YMH0021" } } }, |
| 141 | /* NeoMagic MagicWave 3DX */ |
| 142 | { .id = "NMX2200", .devs = { { "YMH2210" } } }, |
Paul Vojta | 4700418 | 2007-07-04 10:34:22 +0200 | [diff] [blame] | 143 | /* NeoMagic MagicWave 3D */ |
| 144 | { .id = "NMX2200", .devs = { { "NMX2210" } } }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | /* --- */ |
| 146 | { .id = "" } /* end */ |
| 147 | }; |
| 148 | |
| 149 | MODULE_DEVICE_TABLE(pnp_card, snd_opl3sa2_pnpids); |
| 150 | |
| 151 | #endif /* CONFIG_PNP */ |
| 152 | |
| 153 | |
| 154 | /* read control port (w/o spinlock) */ |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 155 | static unsigned char __snd_opl3sa2_read(struct snd_opl3sa2 *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
| 157 | unsigned char result; |
| 158 | #if 0 |
| 159 | outb(0x1d, port); /* password */ |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 160 | printk(KERN_DEBUG "read [0x%lx] = 0x%x\n", port, inb(port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | #endif |
| 162 | outb(reg, chip->port); /* register */ |
| 163 | result = inb(chip->port + 1); |
| 164 | #if 0 |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 165 | printk(KERN_DEBUG "read [0x%lx] = 0x%x [0x%x]\n", |
| 166 | port, result, inb(port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | #endif |
| 168 | return result; |
| 169 | } |
| 170 | |
| 171 | /* read control port (with spinlock) */ |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 172 | static unsigned char snd_opl3sa2_read(struct snd_opl3sa2 *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
| 174 | unsigned long flags; |
| 175 | unsigned char result; |
| 176 | |
| 177 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 178 | result = __snd_opl3sa2_read(chip, reg); |
| 179 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 180 | return result; |
| 181 | } |
| 182 | |
| 183 | /* write control port (w/o spinlock) */ |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 184 | static void __snd_opl3sa2_write(struct snd_opl3sa2 *chip, unsigned char reg, unsigned char value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
| 186 | #if 0 |
| 187 | outb(0x1d, port); /* password */ |
| 188 | #endif |
| 189 | outb(reg, chip->port); /* register */ |
| 190 | outb(value, chip->port + 1); |
| 191 | chip->ctlregs[reg] = value; |
| 192 | } |
| 193 | |
| 194 | /* write control port (with spinlock) */ |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 195 | static void snd_opl3sa2_write(struct snd_opl3sa2 *chip, unsigned char reg, unsigned char value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | unsigned long flags; |
| 198 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 199 | __snd_opl3sa2_write(chip, reg, value); |
| 200 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 201 | } |
| 202 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 203 | static int snd_opl3sa2_detect(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | { |
Krzysztof Helt | 503c10d | 2008-08-17 20:01:14 +0200 | [diff] [blame] | 205 | struct snd_opl3sa2 *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | unsigned long port; |
| 207 | unsigned char tmp, tmp1; |
| 208 | char str[2]; |
| 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | port = chip->port; |
Takashi Iwai | 6bf39b5 | 2021-07-15 09:59:30 +0200 | [diff] [blame] | 211 | chip->res_port = devm_request_region(card->dev, port, 2, |
| 212 | "OPL3-SA control"); |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 213 | if (!chip->res_port) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 214 | snd_printk(KERN_ERR PFX "can't grab port 0x%lx\n", port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | return -EBUSY; |
| 216 | } |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 217 | /* |
| 218 | snd_printk(KERN_DEBUG "REG 0A = 0x%x\n", |
| 219 | snd_opl3sa2_read(chip, 0x0a)); |
| 220 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | chip->version = 0; |
| 222 | tmp = snd_opl3sa2_read(chip, OPL3SA2_MISC); |
| 223 | if (tmp == 0xff) { |
| 224 | snd_printd("OPL3-SA [0x%lx] detect = 0x%x\n", port, tmp); |
| 225 | return -ENODEV; |
| 226 | } |
| 227 | switch (tmp & 0x07) { |
| 228 | case 0x01: |
| 229 | chip->version = 2; /* YMF711 */ |
| 230 | break; |
| 231 | default: |
| 232 | chip->version = 3; |
| 233 | /* 0x02 - standard */ |
| 234 | /* 0x03 - YM715B */ |
| 235 | /* 0x04 - YM719 - OPL-SA4? */ |
| 236 | /* 0x05 - OPL3-SA3 - Libretto 100 */ |
Paul Vojta | e234046 | 2007-07-27 12:20:38 +0200 | [diff] [blame] | 237 | /* 0x07 - unknown - Neomagic MagicWave 3D */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | break; |
| 239 | } |
| 240 | str[0] = chip->version + '0'; |
| 241 | str[1] = 0; |
| 242 | strcat(card->shortname, str); |
| 243 | snd_opl3sa2_write(chip, OPL3SA2_MISC, tmp ^ 7); |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 244 | tmp1 = snd_opl3sa2_read(chip, OPL3SA2_MISC); |
| 245 | if (tmp1 != tmp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | snd_printd("OPL3-SA [0x%lx] detect (1) = 0x%x (0x%x)\n", port, tmp, tmp1); |
| 247 | return -ENODEV; |
| 248 | } |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 249 | /* try if the MIC register is accessible */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | tmp = snd_opl3sa2_read(chip, OPL3SA2_MIC); |
| 251 | snd_opl3sa2_write(chip, OPL3SA2_MIC, 0x8a); |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 252 | tmp1 = snd_opl3sa2_read(chip, OPL3SA2_MIC); |
| 253 | if ((tmp1 & 0x9f) != 0x8a) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | snd_printd("OPL3-SA [0x%lx] detect (2) = 0x%x (0x%x)\n", port, tmp, tmp1); |
| 255 | return -ENODEV; |
| 256 | } |
| 257 | snd_opl3sa2_write(chip, OPL3SA2_MIC, 0x9f); |
| 258 | /* initialization */ |
| 259 | /* Power Management - full on */ |
| 260 | snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D0); |
| 261 | if (chip->version > 2) { |
| 262 | /* ymode is bits 4&5 (of 0 to 7) on all but opl3sa2 versions */ |
| 263 | snd_opl3sa2_write(chip, OPL3SA2_SYS_CTRL, (chip->ymode << 4)); |
| 264 | } else { |
| 265 | /* default for opl3sa2 versions */ |
| 266 | snd_opl3sa2_write(chip, OPL3SA2_SYS_CTRL, 0x00); |
| 267 | } |
| 268 | snd_opl3sa2_write(chip, OPL3SA2_IRQ_CONFIG, 0x0d); /* Interrupt Channel Configuration - IRQ A = OPL3 + MPU + WSS */ |
| 269 | if (chip->single_dma) { |
| 270 | snd_opl3sa2_write(chip, OPL3SA2_DMA_CONFIG, 0x03); /* DMA Configuration - DMA A = WSS-R + WSS-P */ |
| 271 | } else { |
| 272 | snd_opl3sa2_write(chip, OPL3SA2_DMA_CONFIG, 0x21); /* DMA Configuration - DMA B = WSS-R, DMA A = WSS-P */ |
| 273 | } |
| 274 | snd_opl3sa2_write(chip, OPL3SA2_MISC, 0x80 | (tmp & 7)); /* Miscellaneous - default */ |
| 275 | if (chip->version > 2) { |
| 276 | snd_opl3sa2_write(chip, OPL3SA3_DGTL_DOWN, 0x00); /* Digital Block Partial Power Down - default */ |
| 277 | snd_opl3sa2_write(chip, OPL3SA3_ANLG_DOWN, 0x00); /* Analog Block Partial Power Down - default */ |
| 278 | } |
| 279 | return 0; |
| 280 | } |
| 281 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 282 | static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
| 284 | unsigned short status; |
Krzysztof Helt | 503c10d | 2008-08-17 20:01:14 +0200 | [diff] [blame] | 285 | struct snd_card *card = dev_id; |
| 286 | struct snd_opl3sa2 *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | int handled = 0; |
| 288 | |
Krzysztof Helt | f87426e | 2008-08-19 21:51:49 +0200 | [diff] [blame] | 289 | if (card == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | return IRQ_NONE; |
| 291 | |
Krzysztof Helt | 503c10d | 2008-08-17 20:01:14 +0200 | [diff] [blame] | 292 | chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | status = snd_opl3sa2_read(chip, OPL3SA2_IRQ_STATUS); |
| 294 | |
| 295 | if (status & 0x20) { |
| 296 | handled = 1; |
| 297 | snd_opl3_interrupt(chip->synth); |
| 298 | } |
| 299 | |
| 300 | if ((status & 0x10) && chip->rmidi != NULL) { |
| 301 | handled = 1; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 302 | snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | if (status & 0x07) { /* TI,CI,PI */ |
| 306 | handled = 1; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 307 | snd_wss_interrupt(irq, chip->wss); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | if (status & 0x40) { /* hardware volume change */ |
| 311 | handled = 1; |
| 312 | /* reading from Master Lch register at 0x07 clears this bit */ |
| 313 | snd_opl3sa2_read(chip, OPL3SA2_MASTER_RIGHT); |
| 314 | snd_opl3sa2_read(chip, OPL3SA2_MASTER_LEFT); |
| 315 | if (chip->master_switch && chip->master_volume) { |
Krzysztof Helt | 503c10d | 2008-08-17 20:01:14 +0200 | [diff] [blame] | 316 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 317 | &chip->master_switch->id); |
| 318 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 319 | &chip->master_volume->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | return IRQ_RETVAL(handled); |
| 323 | } |
| 324 | |
| 325 | #define OPL3SA2_SINGLE(xname, xindex, reg, shift, mask, invert) \ |
| 326 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
Krzysztof Helt | f87426e | 2008-08-19 21:51:49 +0200 | [diff] [blame] | 327 | .info = snd_wss_info_single, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | .get = snd_opl3sa2_get_single, .put = snd_opl3sa2_put_single, \ |
| 329 | .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } |
Takashi Iwai | a1c7a7d | 2006-08-22 13:16:39 +0200 | [diff] [blame] | 330 | #define OPL3SA2_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv) \ |
| 331 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 332 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ |
| 333 | .name = xname, .index = xindex, \ |
Krzysztof Helt | f87426e | 2008-08-19 21:51:49 +0200 | [diff] [blame] | 334 | .info = snd_wss_info_single, \ |
Takashi Iwai | a1c7a7d | 2006-08-22 13:16:39 +0200 | [diff] [blame] | 335 | .get = snd_opl3sa2_get_single, .put = snd_opl3sa2_put_single, \ |
| 336 | .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24), \ |
| 337 | .tlv = { .p = (xtlv) } } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 339 | static int snd_opl3sa2_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 341 | struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | unsigned long flags; |
| 343 | int reg = kcontrol->private_value & 0xff; |
| 344 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 345 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 346 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 347 | |
| 348 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 349 | ucontrol->value.integer.value[0] = (chip->ctlregs[reg] >> shift) & mask; |
| 350 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 351 | if (invert) |
| 352 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 353 | return 0; |
| 354 | } |
| 355 | |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 356 | static int snd_opl3sa2_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 358 | struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | unsigned long flags; |
| 360 | int reg = kcontrol->private_value & 0xff; |
| 361 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 362 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 363 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 364 | int change; |
| 365 | unsigned short val, oval; |
| 366 | |
| 367 | val = (ucontrol->value.integer.value[0] & mask); |
| 368 | if (invert) |
| 369 | val = mask - val; |
| 370 | val <<= shift; |
| 371 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 372 | oval = chip->ctlregs[reg]; |
| 373 | val = (oval & ~(mask << shift)) | val; |
| 374 | change = val != oval; |
| 375 | __snd_opl3sa2_write(chip, reg, val); |
| 376 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 377 | return change; |
| 378 | } |
| 379 | |
| 380 | #define OPL3SA2_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ |
| 381 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
Krzysztof Helt | f87426e | 2008-08-19 21:51:49 +0200 | [diff] [blame] | 382 | .info = snd_wss_info_double, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | .get = snd_opl3sa2_get_double, .put = snd_opl3sa2_put_double, \ |
| 384 | .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } |
Takashi Iwai | a1c7a7d | 2006-08-22 13:16:39 +0200 | [diff] [blame] | 385 | #define OPL3SA2_DOUBLE_TLV(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert, xtlv) \ |
| 386 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 387 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ |
| 388 | .name = xname, .index = xindex, \ |
Krzysztof Helt | f87426e | 2008-08-19 21:51:49 +0200 | [diff] [blame] | 389 | .info = snd_wss_info_double, \ |
Takashi Iwai | a1c7a7d | 2006-08-22 13:16:39 +0200 | [diff] [blame] | 390 | .get = snd_opl3sa2_get_double, .put = snd_opl3sa2_put_double, \ |
| 391 | .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22), \ |
| 392 | .tlv = { .p = (xtlv) } } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 394 | static int snd_opl3sa2_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 396 | struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | unsigned long flags; |
| 398 | int left_reg = kcontrol->private_value & 0xff; |
| 399 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 400 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 401 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 402 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 403 | int invert = (kcontrol->private_value >> 22) & 1; |
| 404 | |
| 405 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 406 | ucontrol->value.integer.value[0] = (chip->ctlregs[left_reg] >> shift_left) & mask; |
| 407 | ucontrol->value.integer.value[1] = (chip->ctlregs[right_reg] >> shift_right) & mask; |
| 408 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 409 | if (invert) { |
| 410 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 411 | ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; |
| 412 | } |
| 413 | return 0; |
| 414 | } |
| 415 | |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 416 | static int snd_opl3sa2_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | { |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 418 | struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | unsigned long flags; |
| 420 | int left_reg = kcontrol->private_value & 0xff; |
| 421 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 422 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 423 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 424 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 425 | int invert = (kcontrol->private_value >> 22) & 1; |
| 426 | int change; |
| 427 | unsigned short val1, val2, oval1, oval2; |
| 428 | |
| 429 | val1 = ucontrol->value.integer.value[0] & mask; |
| 430 | val2 = ucontrol->value.integer.value[1] & mask; |
| 431 | if (invert) { |
| 432 | val1 = mask - val1; |
| 433 | val2 = mask - val2; |
| 434 | } |
| 435 | val1 <<= shift_left; |
| 436 | val2 <<= shift_right; |
| 437 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 438 | if (left_reg != right_reg) { |
| 439 | oval1 = chip->ctlregs[left_reg]; |
| 440 | oval2 = chip->ctlregs[right_reg]; |
| 441 | val1 = (oval1 & ~(mask << shift_left)) | val1; |
| 442 | val2 = (oval2 & ~(mask << shift_right)) | val2; |
| 443 | change = val1 != oval1 || val2 != oval2; |
| 444 | __snd_opl3sa2_write(chip, left_reg, val1); |
| 445 | __snd_opl3sa2_write(chip, right_reg, val2); |
| 446 | } else { |
| 447 | oval1 = chip->ctlregs[left_reg]; |
| 448 | val1 = (oval1 & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2; |
| 449 | change = val1 != oval1; |
| 450 | __snd_opl3sa2_write(chip, left_reg, val1); |
| 451 | } |
| 452 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 453 | return change; |
| 454 | } |
| 455 | |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 456 | static const DECLARE_TLV_DB_SCALE(db_scale_master, -3000, 200, 0); |
| 457 | static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0); |
Takashi Iwai | a1c7a7d | 2006-08-22 13:16:39 +0200 | [diff] [blame] | 458 | |
Takashi Iwai | fdd1f6f | 2020-01-03 09:16:51 +0100 | [diff] [blame] | 459 | static const struct snd_kcontrol_new snd_opl3sa2_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | OPL3SA2_DOUBLE("Master Playback Switch", 0, 0x07, 0x08, 7, 7, 1, 1), |
Takashi Iwai | a1c7a7d | 2006-08-22 13:16:39 +0200 | [diff] [blame] | 461 | OPL3SA2_DOUBLE_TLV("Master Playback Volume", 0, 0x07, 0x08, 0, 0, 15, 1, |
| 462 | db_scale_master), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | OPL3SA2_SINGLE("Mic Playback Switch", 0, 0x09, 7, 1, 1), |
Takashi Iwai | a1c7a7d | 2006-08-22 13:16:39 +0200 | [diff] [blame] | 464 | OPL3SA2_SINGLE_TLV("Mic Playback Volume", 0, 0x09, 0, 31, 1, |
| 465 | db_scale_5bit_12db_max), |
Krzysztof Helt | 1661c61 | 2009-03-24 22:37:14 +0100 | [diff] [blame] | 466 | OPL3SA2_SINGLE("ZV Port Switch", 0, 0x02, 0, 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | }; |
| 468 | |
Takashi Iwai | fdd1f6f | 2020-01-03 09:16:51 +0100 | [diff] [blame] | 469 | static const struct snd_kcontrol_new snd_opl3sa2_tone_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | OPL3SA2_DOUBLE("3D Control - Wide", 0, 0x14, 0x14, 4, 0, 7, 0), |
| 471 | OPL3SA2_DOUBLE("Tone Control - Bass", 0, 0x15, 0x15, 4, 0, 7, 0), |
| 472 | OPL3SA2_DOUBLE("Tone Control - Treble", 0, 0x16, 0x16, 4, 0, 7, 0) |
| 473 | }; |
| 474 | |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 475 | static void snd_opl3sa2_master_free(struct snd_kcontrol *kcontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 477 | struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | chip->master_switch = NULL; |
| 479 | chip->master_volume = NULL; |
| 480 | } |
| 481 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 482 | static int snd_opl3sa2_mixer(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
Krzysztof Helt | 503c10d | 2008-08-17 20:01:14 +0200 | [diff] [blame] | 484 | struct snd_opl3sa2 *chip = card->private_data; |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 485 | struct snd_ctl_elem_id id1, id2; |
| 486 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | unsigned int idx; |
| 488 | int err; |
| 489 | |
| 490 | memset(&id1, 0, sizeof(id1)); |
| 491 | memset(&id2, 0, sizeof(id2)); |
| 492 | id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 493 | /* reassign AUX0 to CD */ |
| 494 | strcpy(id1.name, "Aux Playback Switch"); |
| 495 | strcpy(id2.name, "CD Playback Switch"); |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 496 | err = snd_ctl_rename_id(card, &id1, &id2); |
| 497 | if (err < 0) { |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 498 | snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | return err; |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 500 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | strcpy(id1.name, "Aux Playback Volume"); |
| 502 | strcpy(id2.name, "CD Playback Volume"); |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 503 | err = snd_ctl_rename_id(card, &id1, &id2); |
| 504 | if (err < 0) { |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 505 | snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | return err; |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 507 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | /* reassign AUX1 to FM */ |
| 509 | strcpy(id1.name, "Aux Playback Switch"); id1.index = 1; |
| 510 | strcpy(id2.name, "FM Playback Switch"); |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 511 | err = snd_ctl_rename_id(card, &id1, &id2); |
| 512 | if (err < 0) { |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 513 | snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | return err; |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 515 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | strcpy(id1.name, "Aux Playback Volume"); |
| 517 | strcpy(id2.name, "FM Playback Volume"); |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 518 | err = snd_ctl_rename_id(card, &id1, &id2); |
| 519 | if (err < 0) { |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 520 | snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | return err; |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 522 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | /* add OPL3SA2 controls */ |
| 524 | for (idx = 0; idx < ARRAY_SIZE(snd_opl3sa2_controls); idx++) { |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 525 | kctl = snd_ctl_new1(&snd_opl3sa2_controls[idx], chip); |
| 526 | err = snd_ctl_add(card, kctl); |
| 527 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | return err; |
| 529 | switch (idx) { |
| 530 | case 0: chip->master_switch = kctl; kctl->private_free = snd_opl3sa2_master_free; break; |
| 531 | case 1: chip->master_volume = kctl; kctl->private_free = snd_opl3sa2_master_free; break; |
| 532 | } |
| 533 | } |
| 534 | if (chip->version > 2) { |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 535 | for (idx = 0; idx < ARRAY_SIZE(snd_opl3sa2_tone_controls); idx++) { |
| 536 | err = snd_ctl_add(card, snd_ctl_new1(&snd_opl3sa2_tone_controls[idx], chip)); |
| 537 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | return err; |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 539 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | /* Power Management support functions */ |
| 545 | #ifdef CONFIG_PM |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 546 | static int snd_opl3sa2_suspend(struct snd_card *card, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | { |
Krzysztof Helt | dde332b | 2009-03-16 21:32:25 +0100 | [diff] [blame] | 548 | if (card) { |
| 549 | struct snd_opl3sa2 *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Krzysztof Helt | dde332b | 2009-03-16 21:32:25 +0100 | [diff] [blame] | 551 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
| 552 | chip->wss->suspend(chip->wss); |
| 553 | /* power down */ |
| 554 | snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D3); |
| 555 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
| 557 | return 0; |
| 558 | } |
| 559 | |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 560 | static int snd_opl3sa2_resume(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
Krzysztof Helt | dde332b | 2009-03-16 21:32:25 +0100 | [diff] [blame] | 562 | struct snd_opl3sa2 *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | int i; |
| 564 | |
Krzysztof Helt | dde332b | 2009-03-16 21:32:25 +0100 | [diff] [blame] | 565 | if (!card) |
| 566 | return 0; |
| 567 | |
| 568 | chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | /* power up */ |
| 570 | snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D0); |
| 571 | |
| 572 | /* restore registers */ |
| 573 | for (i = 2; i <= 0x0a; i++) { |
| 574 | if (i != OPL3SA2_IRQ_STATUS) |
| 575 | snd_opl3sa2_write(chip, i, chip->ctlregs[i]); |
| 576 | } |
| 577 | if (chip->version > 2) { |
| 578 | for (i = 0x12; i <= 0x16; i++) |
| 579 | snd_opl3sa2_write(chip, i, chip->ctlregs[i]); |
| 580 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 581 | /* restore wss */ |
| 582 | chip->wss->resume(chip->wss); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 584 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | return 0; |
| 586 | } |
| 587 | #endif /* CONFIG_PM */ |
| 588 | |
| 589 | #ifdef CONFIG_PNP |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 590 | static int snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip, |
| 591 | struct pnp_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | { |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 593 | if (pnp_activate_dev(pdev) < 0) { |
| 594 | snd_printk(KERN_ERR "PnP configure failure (out of resources?)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | return -EBUSY; |
| 596 | } |
| 597 | sb_port[dev] = pnp_port_start(pdev, 0); |
| 598 | wss_port[dev] = pnp_port_start(pdev, 1); |
| 599 | fm_port[dev] = pnp_port_start(pdev, 2); |
| 600 | midi_port[dev] = pnp_port_start(pdev, 3); |
| 601 | port[dev] = pnp_port_start(pdev, 4); |
| 602 | dma1[dev] = pnp_dma(pdev, 0); |
| 603 | dma2[dev] = pnp_dma(pdev, 1); |
| 604 | irq[dev] = pnp_irq(pdev, 0); |
Jaroslav Kysela | 1265509c | 2005-08-12 17:24:24 +0200 | [diff] [blame] | 605 | snd_printdd("%sPnP OPL3-SA: sb port=0x%lx, wss port=0x%lx, fm port=0x%lx, midi port=0x%lx\n", |
| 606 | pnp_device_is_pnpbios(pdev) ? "BIOS" : "ISA", sb_port[dev], wss_port[dev], fm_port[dev], midi_port[dev]); |
| 607 | snd_printdd("%sPnP OPL3-SA: control port=0x%lx, dma1=%i, dma2=%i, irq=%i\n", |
| 608 | pnp_device_is_pnpbios(pdev) ? "BIOS" : "ISA", port[dev], dma1[dev], dma2[dev], irq[dev]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | return 0; |
| 610 | } |
| 611 | #endif /* CONFIG_PNP */ |
| 612 | |
Takashi Iwai | 4323cc4 | 2014-01-29 13:03:56 +0100 | [diff] [blame] | 613 | static int snd_opl3sa2_card_new(struct device *pdev, int dev, |
| 614 | struct snd_card **cardp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | { |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 616 | struct snd_card *card; |
| 617 | struct snd_opl3sa2 *chip; |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 618 | int err; |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 619 | |
Takashi Iwai | 6bf39b5 | 2021-07-15 09:59:30 +0200 | [diff] [blame] | 620 | err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE, |
| 621 | sizeof(struct snd_opl3sa2), &card); |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 622 | if (err < 0) |
| 623 | return err; |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 624 | strcpy(card->driver, "OPL3SA2"); |
Krzysztof Helt | 1713c0d | 2009-02-27 21:41:40 +0100 | [diff] [blame] | 625 | strcpy(card->shortname, "Yamaha OPL3-SA"); |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 626 | chip = card->private_data; |
| 627 | spin_lock_init(&chip->reg_lock); |
| 628 | chip->irq = -1; |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 629 | *cardp = card; |
| 630 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 633 | static int snd_opl3sa2_probe(struct snd_card *card, int dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
| 635 | int xirq, xdma1, xdma2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | struct snd_opl3sa2 *chip; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 637 | struct snd_wss *wss; |
Takashi Iwai | ec6c5ae | 2005-11-17 14:41:45 +0100 | [diff] [blame] | 638 | struct snd_opl3 *opl3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | int err; |
| 640 | |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 641 | /* initialise this card from supplied (or default) parameter*/ |
| 642 | chip = card->private_data; |
| 643 | chip->ymode = opl3sa3_ymode[dev] & 0x03 ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | chip->port = port[dev]; |
| 645 | xirq = irq[dev]; |
| 646 | xdma1 = dma1[dev]; |
| 647 | xdma2 = dma2[dev]; |
| 648 | if (xdma2 < 0) |
| 649 | chip->single_dma = 1; |
Krzysztof Helt | 503c10d | 2008-08-17 20:01:14 +0200 | [diff] [blame] | 650 | err = snd_opl3sa2_detect(card); |
| 651 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 652 | return err; |
Takashi Iwai | 6bf39b5 | 2021-07-15 09:59:30 +0200 | [diff] [blame] | 653 | err = devm_request_irq(card->dev, xirq, snd_opl3sa2_interrupt, 0, |
| 654 | "OPL3-SA2", card); |
Krzysztof Helt | 503c10d | 2008-08-17 20:01:14 +0200 | [diff] [blame] | 655 | if (err) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 656 | snd_printk(KERN_ERR PFX "can't grab IRQ %d\n", xirq); |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 657 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
| 659 | chip->irq = xirq; |
Takashi Iwai | d3e163b | 2019-12-10 07:34:43 +0100 | [diff] [blame] | 660 | card->sync_irq = chip->irq; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 661 | err = snd_wss_create(card, |
| 662 | wss_port[dev] + 4, -1, |
| 663 | xirq, xdma1, xdma2, |
| 664 | WSS_HW_OPL3SA2, WSS_HWSHARE_IRQ, &wss); |
| 665 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | snd_printd("Oops, WSS not detected at 0x%lx\n", wss_port[dev] + 4); |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 667 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 669 | chip->wss = wss; |
Lars-Peter Clausen | fa60c06 | 2015-01-02 12:24:43 +0100 | [diff] [blame] | 670 | err = snd_wss_pcm(wss, 0); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 671 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 672 | return err; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 673 | err = snd_wss_mixer(wss); |
| 674 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 675 | return err; |
Krzysztof Helt | 503c10d | 2008-08-17 20:01:14 +0200 | [diff] [blame] | 676 | err = snd_opl3sa2_mixer(card); |
| 677 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 678 | return err; |
Lars-Peter Clausen | fa60c06 | 2015-01-02 12:24:43 +0100 | [diff] [blame] | 679 | err = snd_wss_timer(wss, 0); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 680 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 681 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | if (fm_port[dev] >= 0x340 && fm_port[dev] < 0x400) { |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 683 | err = snd_opl3_create(card, fm_port[dev], |
| 684 | fm_port[dev] + 2, |
| 685 | OPL3_HW_OPL3, 0, &opl3); |
| 686 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 687 | return err; |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 688 | err = snd_opl3_timer_new(opl3, 1, 2); |
| 689 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 690 | return err; |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 691 | err = snd_opl3_hwdep_new(opl3, 0, 1, &chip->synth); |
| 692 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 693 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | } |
| 695 | if (midi_port[dev] >= 0x300 && midi_port[dev] < 0x340) { |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 696 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_OPL3SA2, |
| 697 | midi_port[dev], |
| 698 | MPU401_INFO_IRQ_HOOK, -1, |
| 699 | &chip->rmidi); |
| 700 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 701 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", |
| 704 | card->shortname, chip->port, xirq, xdma1); |
Alexey Dobriyan | 1d79716 | 2006-01-25 14:30:44 +0100 | [diff] [blame] | 705 | if (xdma2 >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | sprintf(card->longname + strlen(card->longname), "&%d", xdma2); |
| 707 | |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 708 | return snd_card_register(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | #ifdef CONFIG_PNP |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 712 | static int snd_opl3sa2_pnp_detect(struct pnp_dev *pdev, |
| 713 | const struct pnp_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | { |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 715 | static int dev; |
| 716 | int err; |
| 717 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 719 | if (pnp_device_is_isapnp(pdev)) |
| 720 | return -ENOENT; /* we have another procedure - card */ |
| 721 | for (; dev < SNDRV_CARDS; dev++) { |
| 722 | if (enable[dev] && isapnp[dev]) |
| 723 | break; |
| 724 | } |
| 725 | if (dev >= SNDRV_CARDS) |
| 726 | return -ENODEV; |
| 727 | |
Takashi Iwai | 4323cc4 | 2014-01-29 13:03:56 +0100 | [diff] [blame] | 728 | err = snd_opl3sa2_card_new(&pdev->dev, dev, &card); |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 729 | if (err < 0) |
| 730 | return err; |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 731 | err = snd_opl3sa2_pnp(dev, card->private_data, pdev); |
Takashi Iwai | 6bf39b5 | 2021-07-15 09:59:30 +0200 | [diff] [blame] | 732 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 733 | return err; |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 734 | err = snd_opl3sa2_probe(card, dev); |
Takashi Iwai | 6bf39b5 | 2021-07-15 09:59:30 +0200 | [diff] [blame] | 735 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 736 | return err; |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 737 | pnp_set_drvdata(pdev, card); |
| 738 | dev++; |
| 739 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 742 | #ifdef CONFIG_PM |
| 743 | static int snd_opl3sa2_pnp_suspend(struct pnp_dev *pdev, pm_message_t state) |
| 744 | { |
| 745 | return snd_opl3sa2_suspend(pnp_get_drvdata(pdev), state); |
| 746 | } |
| 747 | static int snd_opl3sa2_pnp_resume(struct pnp_dev *pdev) |
| 748 | { |
| 749 | return snd_opl3sa2_resume(pnp_get_drvdata(pdev)); |
| 750 | } |
| 751 | #endif |
| 752 | |
Jaroslav Kysela | 1265509c | 2005-08-12 17:24:24 +0200 | [diff] [blame] | 753 | static struct pnp_driver opl3sa2_pnp_driver = { |
Takashi Iwai | 62af990 | 2006-01-20 14:03:06 +0100 | [diff] [blame] | 754 | .name = "snd-opl3sa2-pnpbios", |
Jaroslav Kysela | 1265509c | 2005-08-12 17:24:24 +0200 | [diff] [blame] | 755 | .id_table = snd_opl3sa2_pnpbiosids, |
| 756 | .probe = snd_opl3sa2_pnp_detect, |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 757 | #ifdef CONFIG_PM |
| 758 | .suspend = snd_opl3sa2_pnp_suspend, |
| 759 | .resume = snd_opl3sa2_pnp_resume, |
| 760 | #endif |
Jaroslav Kysela | 1265509c | 2005-08-12 17:24:24 +0200 | [diff] [blame] | 761 | }; |
| 762 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 763 | static int snd_opl3sa2_pnp_cdetect(struct pnp_card_link *pcard, |
| 764 | const struct pnp_card_device_id *id) |
Jaroslav Kysela | 1265509c | 2005-08-12 17:24:24 +0200 | [diff] [blame] | 765 | { |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 766 | static int dev; |
| 767 | struct pnp_dev *pdev; |
| 768 | int err; |
| 769 | struct snd_card *card; |
Jaroslav Kysela | 1265509c | 2005-08-12 17:24:24 +0200 | [diff] [blame] | 770 | |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 771 | pdev = pnp_request_card_device(pcard, id->devs[0].id, NULL); |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 772 | if (pdev == NULL) { |
| 773 | snd_printk(KERN_ERR PFX "can't get pnp device from id '%s'\n", |
| 774 | id->devs[0].id); |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 775 | return -EBUSY; |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 776 | } |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 777 | for (; dev < SNDRV_CARDS; dev++) { |
| 778 | if (enable[dev] && isapnp[dev]) |
| 779 | break; |
| 780 | } |
| 781 | if (dev >= SNDRV_CARDS) |
| 782 | return -ENODEV; |
| 783 | |
Takashi Iwai | 4323cc4 | 2014-01-29 13:03:56 +0100 | [diff] [blame] | 784 | err = snd_opl3sa2_card_new(&pdev->dev, dev, &card); |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 785 | if (err < 0) |
| 786 | return err; |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 787 | err = snd_opl3sa2_pnp(dev, card->private_data, pdev); |
Takashi Iwai | 6bf39b5 | 2021-07-15 09:59:30 +0200 | [diff] [blame] | 788 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 789 | return err; |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 790 | err = snd_opl3sa2_probe(card, dev); |
Takashi Iwai | 6bf39b5 | 2021-07-15 09:59:30 +0200 | [diff] [blame] | 791 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 792 | return err; |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 793 | pnp_set_card_drvdata(pcard, card); |
| 794 | dev++; |
| 795 | return 0; |
Jaroslav Kysela | 1265509c | 2005-08-12 17:24:24 +0200 | [diff] [blame] | 796 | } |
| 797 | |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 798 | #ifdef CONFIG_PM |
| 799 | static int snd_opl3sa2_pnp_csuspend(struct pnp_card_link *pcard, pm_message_t state) |
| 800 | { |
| 801 | return snd_opl3sa2_suspend(pnp_get_card_drvdata(pcard), state); |
| 802 | } |
| 803 | static int snd_opl3sa2_pnp_cresume(struct pnp_card_link *pcard) |
| 804 | { |
| 805 | return snd_opl3sa2_resume(pnp_get_card_drvdata(pcard)); |
| 806 | } |
| 807 | #endif |
| 808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | static struct pnp_card_driver opl3sa2_pnpc_driver = { |
| 810 | .flags = PNP_DRIVER_RES_DISABLE, |
Takashi Iwai | 62af990 | 2006-01-20 14:03:06 +0100 | [diff] [blame] | 811 | .name = "snd-opl3sa2-cpnp", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | .id_table = snd_opl3sa2_pnpids, |
Jaroslav Kysela | 1265509c | 2005-08-12 17:24:24 +0200 | [diff] [blame] | 813 | .probe = snd_opl3sa2_pnp_cdetect, |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 814 | #ifdef CONFIG_PM |
| 815 | .suspend = snd_opl3sa2_pnp_csuspend, |
| 816 | .resume = snd_opl3sa2_pnp_cresume, |
| 817 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | }; |
| 819 | #endif /* CONFIG_PNP */ |
| 820 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 821 | static int snd_opl3sa2_isa_match(struct device *pdev, |
| 822 | unsigned int dev) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 823 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 824 | if (!enable[dev]) |
| 825 | return 0; |
| 826 | #ifdef CONFIG_PNP |
| 827 | if (isapnp[dev]) |
| 828 | return 0; |
| 829 | #endif |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 830 | if (port[dev] == SNDRV_AUTO_PORT) { |
| 831 | snd_printk(KERN_ERR PFX "specify port\n"); |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 832 | return 0; |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 833 | } |
| 834 | if (wss_port[dev] == SNDRV_AUTO_PORT) { |
| 835 | snd_printk(KERN_ERR PFX "specify wss_port\n"); |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 836 | return 0; |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 837 | } |
| 838 | if (fm_port[dev] == SNDRV_AUTO_PORT) { |
| 839 | snd_printk(KERN_ERR PFX "specify fm_port\n"); |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 840 | return 0; |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 841 | } |
| 842 | if (midi_port[dev] == SNDRV_AUTO_PORT) { |
| 843 | snd_printk(KERN_ERR PFX "specify midi_port\n"); |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 844 | return 0; |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 845 | } |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 846 | return 1; |
| 847 | } |
| 848 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 849 | static int snd_opl3sa2_isa_probe(struct device *pdev, |
| 850 | unsigned int dev) |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 851 | { |
| 852 | struct snd_card *card; |
| 853 | int err; |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 854 | |
Takashi Iwai | 4323cc4 | 2014-01-29 13:03:56 +0100 | [diff] [blame] | 855 | err = snd_opl3sa2_card_new(pdev, dev, &card); |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 856 | if (err < 0) |
| 857 | return err; |
Takashi Iwai | 4b3bd10 | 2021-06-08 16:04:43 +0200 | [diff] [blame] | 858 | err = snd_opl3sa2_probe(card, dev); |
Takashi Iwai | 6bf39b5 | 2021-07-15 09:59:30 +0200 | [diff] [blame] | 859 | if (err < 0) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 860 | return err; |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 861 | dev_set_drvdata(pdev, card); |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 862 | return 0; |
| 863 | } |
| 864 | |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 865 | #ifdef CONFIG_PM |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 866 | static int snd_opl3sa2_isa_suspend(struct device *dev, unsigned int n, |
| 867 | pm_message_t state) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 868 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 869 | return snd_opl3sa2_suspend(dev_get_drvdata(dev), state); |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 870 | } |
| 871 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 872 | static int snd_opl3sa2_isa_resume(struct device *dev, unsigned int n) |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 873 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 874 | return snd_opl3sa2_resume(dev_get_drvdata(dev)); |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 875 | } |
| 876 | #endif |
| 877 | |
Rene Herman | 83c51c0 | 2007-03-20 11:33:46 +0100 | [diff] [blame] | 878 | #define DEV_NAME "opl3sa2" |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 879 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 880 | static struct isa_driver snd_opl3sa2_isa_driver = { |
| 881 | .match = snd_opl3sa2_isa_match, |
| 882 | .probe = snd_opl3sa2_isa_probe, |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 883 | #ifdef CONFIG_PM |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 884 | .suspend = snd_opl3sa2_isa_suspend, |
| 885 | .resume = snd_opl3sa2_isa_resume, |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 886 | #endif |
| 887 | .driver = { |
Rene Herman | 83c51c0 | 2007-03-20 11:33:46 +0100 | [diff] [blame] | 888 | .name = DEV_NAME |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 889 | }, |
| 890 | }; |
| 891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | static int __init alsa_card_opl3sa2_init(void) |
| 893 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 894 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 896 | err = isa_register_driver(&snd_opl3sa2_isa_driver, SNDRV_CARDS); |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 897 | #ifdef CONFIG_PNP |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 898 | if (!err) |
| 899 | isa_registered = 1; |
| 900 | |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 901 | err = pnp_register_driver(&opl3sa2_pnp_driver); |
Bjorn Helgaas | 8c59c4a | 2006-03-27 01:17:05 -0800 | [diff] [blame] | 902 | if (!err) |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 903 | pnp_registered = 1; |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 904 | |
Takashi Iwai | 704e052 | 2005-11-17 17:11:53 +0100 | [diff] [blame] | 905 | err = pnp_register_card_driver(&opl3sa2_pnpc_driver); |
Bjorn Helgaas | 8c59c4a | 2006-03-27 01:17:05 -0800 | [diff] [blame] | 906 | if (!err) |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 907 | pnpc_registered = 1; |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 908 | |
| 909 | if (isa_registered || pnp_registered) |
| 910 | err = 0; |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 911 | #endif |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 912 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | static void __exit alsa_card_opl3sa2_exit(void) |
| 916 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 917 | #ifdef CONFIG_PNP |
| 918 | if (pnpc_registered) |
| 919 | pnp_unregister_card_driver(&opl3sa2_pnpc_driver); |
| 920 | if (pnp_registered) |
| 921 | pnp_unregister_driver(&opl3sa2_pnp_driver); |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 922 | if (isa_registered) |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 923 | #endif |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 924 | isa_unregister_driver(&snd_opl3sa2_isa_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | module_init(alsa_card_opl3sa2_init) |
| 928 | module_exit(alsa_card_opl3sa2_exit) |