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> |
| 25 | #include <linux/platform_device.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 | |
| 38 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); |
| 39 | MODULE_DESCRIPTION("ESS ESx688 AudioDrive"); |
| 40 | MODULE_LICENSE("GPL"); |
| 41 | MODULE_SUPPORTED_DEVICE("{{ESS,ES688 PnP AudioDrive,pnp:ESS0100}," |
| 42 | "{ESS,ES1688 PnP AudioDrive,pnp:ESS0102}," |
| 43 | "{ESS,ES688 AudioDrive,pnp:ESS6881}," |
| 44 | "{ESS,ES1688 AudioDrive,pnp:ESS1681}}"); |
| 45 | |
| 46 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 47 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 48 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ |
| 49 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */ |
| 50 | static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1}; |
| 51 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ |
| 52 | static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ |
| 53 | static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */ |
| 54 | |
| 55 | module_param_array(index, int, NULL, 0444); |
| 56 | MODULE_PARM_DESC(index, "Index value for ESx688 soundcard."); |
| 57 | module_param_array(id, charp, NULL, 0444); |
| 58 | MODULE_PARM_DESC(id, "ID string for ESx688 soundcard."); |
| 59 | module_param_array(enable, bool, NULL, 0444); |
| 60 | MODULE_PARM_DESC(enable, "Enable ESx688 soundcard."); |
| 61 | module_param_array(port, long, NULL, 0444); |
| 62 | MODULE_PARM_DESC(port, "Port # for ESx688 driver."); |
| 63 | module_param_array(mpu_port, long, NULL, 0444); |
| 64 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ESx688 driver."); |
| 65 | module_param_array(irq, int, NULL, 0444); |
| 66 | MODULE_PARM_DESC(irq, "IRQ # for ESx688 driver."); |
| 67 | module_param_array(mpu_irq, int, NULL, 0444); |
| 68 | MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for ESx688 driver."); |
| 69 | module_param_array(dma8, int, NULL, 0444); |
| 70 | MODULE_PARM_DESC(dma8, "8-bit DMA # for ESx688 driver."); |
| 71 | |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 72 | static struct platform_device *devices[SNDRV_CARDS]; |
| 73 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 74 | #define PFX "es1688: " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 76 | static int __devinit snd_es1688_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 78 | int dev = pdev->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | static int possible_irqs[] = {5, 9, 10, 7, -1}; |
| 80 | static int possible_dmas[] = {1, 3, 0, -1}; |
| 81 | int xirq, xdma, xmpu_irq; |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 82 | struct snd_card *card; |
| 83 | struct snd_es1688 *chip; |
| 84 | struct snd_opl3 *opl3; |
| 85 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | int err; |
| 87 | |
| 88 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); |
| 89 | if (card == NULL) |
| 90 | return -ENOMEM; |
| 91 | |
| 92 | xirq = irq[dev]; |
| 93 | if (xirq == SNDRV_AUTO_IRQ) { |
| 94 | if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 95 | snd_printk(KERN_ERR PFX "unable to find a free IRQ\n"); |
| 96 | err = -EBUSY; |
| 97 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | xmpu_irq = mpu_irq[dev]; |
| 101 | xdma = dma8[dev]; |
| 102 | if (xdma == SNDRV_AUTO_DMA) { |
| 103 | if ((xdma = snd_legacy_find_free_dma(possible_dmas)) < 0) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 104 | snd_printk(KERN_ERR PFX "unable to find a free DMA\n"); |
| 105 | err = -EBUSY; |
| 106 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 110 | if (port[dev] != SNDRV_AUTO_PORT) { |
| 111 | if ((err = snd_es1688_create(card, port[dev], mpu_port[dev], |
| 112 | xirq, xmpu_irq, xdma, |
| 113 | ES1688_HW_AUTO, &chip)) < 0) |
| 114 | goto _err; |
| 115 | } else { |
| 116 | /* auto-probe legacy ports */ |
| 117 | static unsigned long possible_ports[] = { |
| 118 | 0x220, 0x240, 0x260, |
| 119 | }; |
| 120 | int i; |
| 121 | for (i = 0; i < ARRAY_SIZE(possible_ports); i++) { |
| 122 | err = snd_es1688_create(card, possible_ports[i], |
| 123 | mpu_port[dev], |
| 124 | xirq, xmpu_irq, xdma, |
| 125 | ES1688_HW_AUTO, &chip); |
| 126 | if (err >= 0) { |
| 127 | port[dev] = possible_ports[i]; |
| 128 | break; |
| 129 | } |
| 130 | } |
| 131 | if (i >= ARRAY_SIZE(possible_ports)) |
| 132 | goto _err; |
| 133 | } |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 134 | |
| 135 | if ((err = snd_es1688_pcm(chip, 0, &pcm)) < 0) |
| 136 | goto _err; |
| 137 | |
| 138 | if ((err = snd_es1688_mixer(chip)) < 0) |
| 139 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | strcpy(card->driver, "ES1688"); |
| 142 | strcpy(card->shortname, pcm->name); |
| 143 | sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name, chip->port, xirq, xdma); |
| 144 | |
| 145 | if ((snd_opl3_create(card, chip->port, chip->port + 2, OPL3_HW_OPL3, 0, &opl3)) < 0) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 146 | printk(KERN_WARNING PFX "opl3 not detected at 0x%lx\n", chip->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } else { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 148 | if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) |
| 149 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | if (xmpu_irq >= 0 && xmpu_irq != SNDRV_AUTO_IRQ && chip->mpu_port > 0) { |
| 153 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, |
| 154 | chip->mpu_port, 0, |
| 155 | xmpu_irq, |
Thomas Gleixner | 65ca68b | 2006-07-01 19:29:46 -0700 | [diff] [blame] | 156 | IRQF_DISABLED, |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 157 | NULL)) < 0) |
| 158 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 160 | |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 161 | snd_card_set_dev(card, &pdev->dev); |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 162 | |
| 163 | if ((err = snd_card_register(card)) < 0) |
| 164 | goto _err; |
| 165 | |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 166 | platform_set_drvdata(pdev, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | return 0; |
| 168 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 169 | _err: |
| 170 | snd_card_free(card); |
| 171 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 174 | static int __devexit snd_es1688_remove(struct platform_device *devptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 176 | snd_card_free(platform_get_drvdata(devptr)); |
| 177 | platform_set_drvdata(devptr, NULL); |
| 178 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 181 | #define ES1688_DRIVER "snd_es1688" |
| 182 | |
| 183 | static struct platform_driver snd_es1688_driver = { |
| 184 | .probe = snd_es1688_probe, |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 185 | .remove = __devexit_p(snd_es1688_remove), |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 186 | /* FIXME: suspend/resume */ |
| 187 | .driver = { |
| 188 | .name = ES1688_DRIVER |
| 189 | }, |
| 190 | }; |
| 191 | |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 192 | static void __init_or_module snd_es1688_unregister_all(void) |
| 193 | { |
| 194 | int i; |
| 195 | |
| 196 | for (i = 0; i < ARRAY_SIZE(devices); ++i) |
| 197 | platform_device_unregister(devices[i]); |
| 198 | platform_driver_unregister(&snd_es1688_driver); |
| 199 | } |
| 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | static int __init alsa_card_es1688_init(void) |
| 202 | { |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 203 | int i, cards, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 205 | err = platform_driver_register(&snd_es1688_driver); |
| 206 | if (err < 0) |
| 207 | return err; |
| 208 | |
| 209 | cards = 0; |
Takashi Iwai | 8278ca8 | 2006-02-20 11:57:34 +0100 | [diff] [blame] | 210 | for (i = 0; i < SNDRV_CARDS; i++) { |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 211 | struct platform_device *device; |
Takashi Iwai | 8278ca8 | 2006-02-20 11:57:34 +0100 | [diff] [blame] | 212 | if (! enable[i]) |
| 213 | continue; |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 214 | device = platform_device_register_simple(ES1688_DRIVER, |
| 215 | i, NULL, 0); |
Rene Herman | d0ac642 | 2006-04-11 14:08:33 +0200 | [diff] [blame] | 216 | if (IS_ERR(device)) |
| 217 | continue; |
Rene Herman | dcccdd9 | 2006-04-11 14:09:37 +0200 | [diff] [blame] | 218 | if (!platform_get_drvdata(device)) { |
| 219 | platform_device_unregister(device); |
| 220 | continue; |
| 221 | } |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 222 | devices[i] = device; |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 223 | cards++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | if (!cards) { |
| 226 | #ifdef MODULE |
| 227 | printk(KERN_ERR "ESS AudioDrive ES1688 soundcard not found or device busy\n"); |
| 228 | #endif |
Rene Herman | d0ac642 | 2006-04-11 14:08:33 +0200 | [diff] [blame] | 229 | snd_es1688_unregister_all(); |
| 230 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static void __exit alsa_card_es1688_exit(void) |
| 236 | { |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 237 | snd_es1688_unregister_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | module_init(alsa_card_es1688_init) |
| 241 | module_exit(alsa_card_es1688_exit) |