Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for generic ESS AudioDrive ESx688 soundcards |
| 3 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> |
| 4 | * |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <sound/driver.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/init.h> |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 24 | #include <linux/err.h> |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 25 | #include <linux/isa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/time.h> |
| 27 | #include <linux/wait.h> |
| 28 | #include <linux/moduleparam.h> |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 29 | #include <asm/dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <sound/core.h> |
| 31 | #include <sound/es1688.h> |
| 32 | #include <sound/mpu401.h> |
| 33 | #include <sound/opl3.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #define SNDRV_LEGACY_FIND_FREE_IRQ |
| 35 | #define SNDRV_LEGACY_FIND_FREE_DMA |
| 36 | #include <sound/initval.h> |
| 37 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 38 | #define CRD_NAME "Generic ESS ES1688/ES688 AudioDrive" |
| 39 | #define DEV_NAME "es1688" |
| 40 | |
| 41 | MODULE_DESCRIPTION(CRD_NAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | MODULE_LICENSE("GPL"); |
| 44 | MODULE_SUPPORTED_DEVICE("{{ESS,ES688 PnP AudioDrive,pnp:ESS0100}," |
| 45 | "{ESS,ES1688 PnP AudioDrive,pnp:ESS0102}," |
| 46 | "{ESS,ES688 AudioDrive,pnp:ESS6881}," |
| 47 | "{ESS,ES1688 AudioDrive,pnp:ESS1681}}"); |
| 48 | |
| 49 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 50 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 51 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ |
| 52 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */ |
| 53 | static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1}; |
| 54 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ |
| 55 | static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ |
| 56 | static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */ |
| 57 | |
| 58 | module_param_array(index, int, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 59 | MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | module_param_array(id, charp, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 61 | MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | module_param_array(enable, bool, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 63 | MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | module_param_array(port, long, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 65 | MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | module_param_array(mpu_port, long, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 67 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | module_param_array(irq, int, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 69 | MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | module_param_array(mpu_irq, int, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 71 | MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | module_param_array(dma8, int, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 73 | MODULE_PARM_DESC(dma8, "8-bit DMA # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 75 | static int __devinit snd_es1688_match(struct device *dev, unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 77 | return enable[n]; |
| 78 | } |
| 79 | |
| 80 | static int __devinit snd_es1688_probe(struct device *dev, unsigned int n) |
| 81 | { |
| 82 | static unsigned long possible_ports[] = {0x220, 0x240, 0x260}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | static int possible_irqs[] = {5, 9, 10, 7, -1}; |
| 84 | static int possible_dmas[] = {1, 3, 0, -1}; |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 85 | int i, xirq, xdma; |
| 86 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 87 | struct snd_card *card; |
| 88 | struct snd_es1688 *chip; |
| 89 | struct snd_opl3 *opl3; |
| 90 | struct snd_pcm *pcm; |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 91 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 93 | card = snd_card_new(index[n], id[n], THIS_MODULE, 0); |
| 94 | if (!card) |
| 95 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 97 | error = -EBUSY; |
| 98 | |
| 99 | xirq = irq[n]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | if (xirq == SNDRV_AUTO_IRQ) { |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 101 | xirq = snd_legacy_find_free_irq(possible_irqs); |
| 102 | if (xirq < 0) { |
| 103 | snd_printk(KERN_ERR "%s: unable to find a free IRQ\n", dev->bus_id); |
| 104 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | } |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 107 | |
| 108 | xdma = dma8[n]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | if (xdma == SNDRV_AUTO_DMA) { |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 110 | xdma = snd_legacy_find_free_dma(possible_dmas); |
| 111 | if (xdma < 0) { |
| 112 | snd_printk(KERN_ERR "%s: unable to find a free DMA\n", dev->bus_id); |
| 113 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 117 | if (port[n] == SNDRV_AUTO_PORT) |
| 118 | for (i = 0; i < ARRAY_SIZE(possible_ports) && error < 0; i++) |
| 119 | error = snd_es1688_create(card, possible_ports[i], mpu_port[n], |
| 120 | xirq, mpu_irq[n], xdma, ES1688_HW_AUTO, &chip); |
| 121 | else |
| 122 | error = snd_es1688_create(card, port[n], mpu_port[n], |
| 123 | xirq, mpu_irq[n], xdma, ES1688_HW_AUTO, &chip); |
| 124 | if (error < 0) |
| 125 | goto out; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 126 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 127 | error = snd_es1688_pcm(chip, 0, &pcm); |
| 128 | if (error < 0) |
| 129 | goto out; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 130 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 131 | error = snd_es1688_mixer(chip); |
| 132 | if (error < 0) |
| 133 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | strcpy(card->driver, "ES1688"); |
| 136 | strcpy(card->shortname, pcm->name); |
| 137 | sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name, chip->port, xirq, xdma); |
| 138 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 139 | if (snd_opl3_create(card, chip->port, chip->port + 2, OPL3_HW_OPL3, 0, &opl3) < 0) |
| 140 | printk(KERN_WARNING "%s: opl3 not detected at 0x%lx\n", dev->bus_id, chip->port); |
| 141 | else { |
| 142 | error = snd_opl3_hwdep_new(opl3, 0, 1, NULL); |
| 143 | if (error < 0) |
| 144 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 147 | if (mpu_irq[n] >= 0 && mpu_irq[n] != SNDRV_AUTO_IRQ && chip->mpu_port > 0) { |
| 148 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, chip->mpu_port, |
| 149 | 0, mpu_irq[n], IRQF_DISABLED, NULL); |
| 150 | if (error < 0) |
| 151 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 153 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 154 | snd_card_set_dev(card, dev); |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 155 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 156 | error = snd_card_register(card); |
| 157 | if (error < 0) |
| 158 | goto out; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 159 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 160 | dev_set_drvdata(dev, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | return 0; |
| 162 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 163 | out: snd_card_free(card); |
| 164 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 167 | static int __devexit snd_es1688_remove(struct device *dev, unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 169 | snd_card_free(dev_get_drvdata(dev)); |
| 170 | dev_set_drvdata(dev, NULL); |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 171 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 174 | static struct isa_driver snd_es1688_driver = { |
| 175 | .match = snd_es1688_match, |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 176 | .probe = snd_es1688_probe, |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 177 | .remove = snd_es1688_remove, |
| 178 | #if 0 /* FIXME */ |
| 179 | .suspend = snd_es1688_suspend, |
| 180 | .resume = snd_es1688_resume, |
| 181 | #endif |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 182 | .driver = { |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 183 | .name = DEV_NAME |
| 184 | } |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 185 | }; |
| 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | static int __init alsa_card_es1688_init(void) |
| 188 | { |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 189 | return isa_register_driver(&snd_es1688_driver, SNDRV_CARDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | static void __exit alsa_card_es1688_exit(void) |
| 193 | { |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 194 | isa_unregister_driver(&snd_es1688_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame^] | 197 | module_init(alsa_card_es1688_init); |
| 198 | module_exit(alsa_card_es1688_exit); |