Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for generic ESS AudioDrive ESx688 soundcards |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 3 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/init.h> |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 23 | #include <linux/err.h> |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 24 | #include <linux/isa.h> |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 25 | #include <linux/isapnp.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); |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 42 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.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 | |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 49 | MODULE_ALIAS("snd_es968"); |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 52 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 53 | #ifdef CONFIG_PNP |
| 54 | static int isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; |
| 55 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ |
| 57 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */ |
Krzysztof Helt | 880abd4 | 2009-01-30 19:20:29 +0100 | [diff] [blame] | 58 | static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* Usually 0x388 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1}; |
| 60 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ |
| 61 | static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ |
| 62 | static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */ |
| 63 | |
| 64 | module_param_array(index, int, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 65 | MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | module_param_array(id, charp, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 67 | MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | module_param_array(enable, bool, NULL, 0444); |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 69 | #ifdef CONFIG_PNP |
| 70 | module_param_array(isapnp, bool, NULL, 0444); |
| 71 | MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard."); |
| 72 | #endif |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 73 | MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | module_param_array(port, long, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 75 | MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | module_param_array(mpu_port, long, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 77 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | module_param_array(irq, int, NULL, 0444); |
Krzysztof Helt | 880abd4 | 2009-01-30 19:20:29 +0100 | [diff] [blame] | 79 | module_param_array(fm_port, long, NULL, 0444); |
| 80 | MODULE_PARM_DESC(fm_port, "FM port # for ES1688 driver."); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 81 | MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | module_param_array(mpu_irq, int, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 83 | MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | module_param_array(dma8, int, NULL, 0444); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 85 | MODULE_PARM_DESC(dma8, "8-bit DMA # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 87 | #ifdef CONFIG_PNP |
| 88 | #define is_isapnp_selected(dev) isapnp[dev] |
| 89 | #else |
| 90 | #define is_isapnp_selected(dev) 0 |
| 91 | #endif |
| 92 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 93 | static int __devinit snd_es1688_match(struct device *dev, unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 95 | return enable[n] && !is_isapnp_selected(n); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 96 | } |
| 97 | |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 98 | static int __devinit snd_es1688_legacy_create(struct snd_card *card, |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 99 | struct device *dev, unsigned int n) |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 100 | { |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 101 | struct snd_es1688 *chip = card->private_data; |
Rene Herman | 019608b | 2007-02-19 13:01:45 +0100 | [diff] [blame] | 102 | static long possible_ports[] = {0x220, 0x240, 0x260}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | static int possible_irqs[] = {5, 9, 10, 7, -1}; |
| 104 | static int possible_dmas[] = {1, 3, 0, -1}; |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 105 | |
Rene Herman | 019608b | 2007-02-19 13:01:45 +0100 | [diff] [blame] | 106 | int i, error; |
| 107 | |
| 108 | if (irq[n] == SNDRV_AUTO_IRQ) { |
| 109 | irq[n] = snd_legacy_find_free_irq(possible_irqs); |
| 110 | if (irq[n] < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 111 | dev_err(dev, "unable to find a free IRQ\n"); |
Rene Herman | 019608b | 2007-02-19 13:01:45 +0100 | [diff] [blame] | 112 | return -EBUSY; |
| 113 | } |
| 114 | } |
| 115 | if (dma8[n] == SNDRV_AUTO_DMA) { |
| 116 | dma8[n] = snd_legacy_find_free_dma(possible_dmas); |
| 117 | if (dma8[n] < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 118 | dev_err(dev, "unable to find a free DMA\n"); |
Rene Herman | 019608b | 2007-02-19 13:01:45 +0100 | [diff] [blame] | 119 | return -EBUSY; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | if (port[n] != SNDRV_AUTO_PORT) |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 124 | return snd_es1688_create(card, chip, port[n], mpu_port[n], |
| 125 | irq[n], mpu_irq[n], dma8[n], ES1688_HW_AUTO); |
Rene Herman | 019608b | 2007-02-19 13:01:45 +0100 | [diff] [blame] | 126 | |
| 127 | i = 0; |
| 128 | do { |
| 129 | port[n] = possible_ports[i]; |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 130 | error = snd_es1688_create(card, chip, port[n], mpu_port[n], |
| 131 | irq[n], mpu_irq[n], dma8[n], ES1688_HW_AUTO); |
Rene Herman | 019608b | 2007-02-19 13:01:45 +0100 | [diff] [blame] | 132 | } while (error < 0 && ++i < ARRAY_SIZE(possible_ports)); |
| 133 | |
| 134 | return error; |
| 135 | } |
| 136 | |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 137 | static int __devinit snd_es1688_probe(struct snd_card *card, unsigned int n) |
Rene Herman | 019608b | 2007-02-19 13:01:45 +0100 | [diff] [blame] | 138 | { |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 139 | struct snd_es1688 *chip = card->private_data; |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 140 | struct snd_opl3 *opl3; |
| 141 | struct snd_pcm *pcm; |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 142 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 144 | error = snd_es1688_pcm(card, chip, 0, &pcm); |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 145 | if (error < 0) |
| 146 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 148 | error = snd_es1688_mixer(card, chip); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 149 | if (error < 0) |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 150 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Dan Carpenter | b0fb75a | 2010-05-14 16:48:28 +0200 | [diff] [blame] | 152 | strlcpy(card->driver, "ES1688", sizeof(card->driver)); |
| 153 | strlcpy(card->shortname, pcm->name, sizeof(card->shortname)); |
| 154 | snprintf(card->longname, sizeof(card->longname), |
| 155 | "%s at 0x%lx, irq %i, dma %i", pcm->name, chip->port, |
| 156 | chip->irq, chip->dma8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Krzysztof Helt | 880abd4 | 2009-01-30 19:20:29 +0100 | [diff] [blame] | 158 | if (fm_port[n] == SNDRV_AUTO_PORT) |
| 159 | fm_port[n] = port[n]; /* share the same port */ |
| 160 | |
| 161 | if (fm_port[n] > 0) { |
| 162 | if (snd_opl3_create(card, fm_port[n], fm_port[n] + 2, |
| 163 | OPL3_HW_OPL3, 0, &opl3) < 0) |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 164 | dev_warn(card->dev, |
Krzysztof Helt | 880abd4 | 2009-01-30 19:20:29 +0100 | [diff] [blame] | 165 | "opl3 not detected at 0x%lx\n", fm_port[n]); |
| 166 | else { |
| 167 | error = snd_opl3_hwdep_new(opl3, 0, 1, NULL); |
| 168 | if (error < 0) |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 169 | return error; |
Krzysztof Helt | 880abd4 | 2009-01-30 19:20:29 +0100 | [diff] [blame] | 170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Rene Herman | 019608b | 2007-02-19 13:01:45 +0100 | [diff] [blame] | 173 | if (mpu_irq[n] >= 0 && mpu_irq[n] != SNDRV_AUTO_IRQ && |
| 174 | chip->mpu_port > 0) { |
| 175 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, |
| 176 | chip->mpu_port, 0, |
| 177 | mpu_irq[n], IRQF_DISABLED, NULL); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 178 | if (error < 0) |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 179 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 181 | |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 182 | return snd_card_register(card); |
| 183 | } |
| 184 | |
| 185 | static int __devinit snd_es1688_isa_probe(struct device *dev, unsigned int n) |
| 186 | { |
| 187 | struct snd_card *card; |
| 188 | int error; |
| 189 | |
| 190 | error = snd_card_create(index[n], id[n], THIS_MODULE, |
| 191 | sizeof(struct snd_es1688), &card); |
| 192 | if (error < 0) |
| 193 | return error; |
| 194 | |
| 195 | error = snd_es1688_legacy_create(card, dev, n); |
| 196 | if (error < 0) |
| 197 | goto out; |
| 198 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 199 | snd_card_set_dev(card, dev); |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 200 | |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 201 | error = snd_es1688_probe(card, n); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 202 | if (error < 0) |
| 203 | goto out; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 204 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 205 | dev_set_drvdata(dev, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 207 | return 0; |
| 208 | out: |
| 209 | snd_card_free(card); |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 210 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 213 | static int __devexit snd_es1688_isa_remove(struct device *dev, unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 215 | snd_card_free(dev_get_drvdata(dev)); |
| 216 | dev_set_drvdata(dev, NULL); |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 217 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 220 | static struct isa_driver snd_es1688_driver = { |
| 221 | .match = snd_es1688_match, |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 222 | .probe = snd_es1688_isa_probe, |
| 223 | .remove = __devexit_p(snd_es1688_isa_remove), |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 224 | #if 0 /* FIXME */ |
| 225 | .suspend = snd_es1688_suspend, |
| 226 | .resume = snd_es1688_resume, |
| 227 | #endif |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 228 | .driver = { |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 229 | .name = DEV_NAME |
| 230 | } |
Takashi Iwai | 2a571ed | 2005-11-17 17:13:30 +0100 | [diff] [blame] | 231 | }; |
| 232 | |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 233 | static int snd_es968_pnp_is_probed; |
| 234 | |
| 235 | #ifdef CONFIG_PNP |
| 236 | static int __devinit snd_card_es968_pnp(struct snd_card *card, unsigned int n, |
| 237 | struct pnp_card_link *pcard, |
| 238 | const struct pnp_card_device_id *pid) |
| 239 | { |
| 240 | struct snd_es1688 *chip = card->private_data; |
| 241 | struct pnp_dev *pdev; |
| 242 | int error; |
| 243 | |
| 244 | pdev = pnp_request_card_device(pcard, pid->devs[0].id, NULL); |
| 245 | if (pdev == NULL) |
| 246 | return -ENODEV; |
| 247 | |
| 248 | error = pnp_activate_dev(pdev); |
| 249 | if (error < 0) { |
| 250 | snd_printk(KERN_ERR "ES968 pnp configure failure\n"); |
| 251 | return error; |
| 252 | } |
| 253 | port[n] = pnp_port_start(pdev, 0); |
| 254 | dma8[n] = pnp_dma(pdev, 0); |
| 255 | irq[n] = pnp_irq(pdev, 0); |
| 256 | |
| 257 | return snd_es1688_create(card, chip, port[n], mpu_port[n], irq[n], |
| 258 | mpu_irq[n], dma8[n], ES1688_HW_AUTO); |
| 259 | } |
| 260 | |
| 261 | static int __devinit snd_es968_pnp_detect(struct pnp_card_link *pcard, |
| 262 | const struct pnp_card_device_id *pid) |
| 263 | { |
| 264 | struct snd_card *card; |
| 265 | static unsigned int dev; |
| 266 | int error; |
| 267 | struct snd_es1688 *chip; |
| 268 | |
| 269 | if (snd_es968_pnp_is_probed) |
| 270 | return -EBUSY; |
| 271 | for ( ; dev < SNDRV_CARDS; dev++) { |
| 272 | if (enable[dev] && isapnp[dev]) |
| 273 | break; |
| 274 | } |
Dan Carpenter | b0fb75a | 2010-05-14 16:48:28 +0200 | [diff] [blame] | 275 | if (dev == SNDRV_CARDS) |
| 276 | return -ENODEV; |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 277 | |
| 278 | error = snd_card_create(index[dev], id[dev], THIS_MODULE, |
| 279 | sizeof(struct snd_es1688), &card); |
| 280 | if (error < 0) |
| 281 | return error; |
| 282 | chip = card->private_data; |
| 283 | |
| 284 | error = snd_card_es968_pnp(card, dev, pcard, pid); |
| 285 | if (error < 0) { |
| 286 | snd_card_free(card); |
| 287 | return error; |
| 288 | } |
| 289 | snd_card_set_dev(card, &pcard->card->dev); |
| 290 | error = snd_es1688_probe(card, dev); |
| 291 | if (error < 0) |
| 292 | return error; |
| 293 | pnp_set_card_drvdata(pcard, card); |
| 294 | snd_es968_pnp_is_probed = 1; |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | static void __devexit snd_es968_pnp_remove(struct pnp_card_link * pcard) |
| 299 | { |
| 300 | snd_card_free(pnp_get_card_drvdata(pcard)); |
| 301 | pnp_set_card_drvdata(pcard, NULL); |
| 302 | snd_es968_pnp_is_probed = 0; |
| 303 | } |
| 304 | |
| 305 | #ifdef CONFIG_PM |
| 306 | static int snd_es968_pnp_suspend(struct pnp_card_link *pcard, |
| 307 | pm_message_t state) |
| 308 | { |
| 309 | struct snd_card *card = pnp_get_card_drvdata(pcard); |
| 310 | struct snd_es1688 *chip = card->private_data; |
| 311 | |
| 312 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
| 313 | snd_pcm_suspend_all(chip->pcm); |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | static int snd_es968_pnp_resume(struct pnp_card_link *pcard) |
| 318 | { |
| 319 | struct snd_card *card = pnp_get_card_drvdata(pcard); |
| 320 | struct snd_es1688 *chip = card->private_data; |
| 321 | |
| 322 | snd_es1688_reset(chip); |
| 323 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
| 324 | return 0; |
| 325 | } |
| 326 | #endif |
| 327 | |
| 328 | static struct pnp_card_device_id snd_es968_pnpids[] = { |
| 329 | { .id = "ESS0968", .devs = { { "@@@0968" }, } }, |
| 330 | { .id = "ESS0968", .devs = { { "ESS0968" }, } }, |
| 331 | { .id = "", } /* end */ |
| 332 | }; |
| 333 | |
| 334 | MODULE_DEVICE_TABLE(pnp_card, snd_es968_pnpids); |
| 335 | |
| 336 | static struct pnp_card_driver es968_pnpc_driver = { |
| 337 | .flags = PNP_DRIVER_RES_DISABLE, |
| 338 | .name = DEV_NAME " PnP", |
| 339 | .id_table = snd_es968_pnpids, |
| 340 | .probe = snd_es968_pnp_detect, |
| 341 | .remove = __devexit_p(snd_es968_pnp_remove), |
| 342 | #ifdef CONFIG_PM |
| 343 | .suspend = snd_es968_pnp_suspend, |
| 344 | .resume = snd_es968_pnp_resume, |
| 345 | #endif |
| 346 | }; |
| 347 | #endif |
| 348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | static int __init alsa_card_es1688_init(void) |
| 350 | { |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 351 | #ifdef CONFIG_PNP |
| 352 | pnp_register_card_driver(&es968_pnpc_driver); |
| 353 | if (snd_es968_pnp_is_probed) |
| 354 | return 0; |
| 355 | pnp_unregister_card_driver(&es968_pnpc_driver); |
| 356 | #endif |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 357 | return isa_register_driver(&snd_es1688_driver, SNDRV_CARDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | static void __exit alsa_card_es1688_exit(void) |
| 361 | { |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 362 | if (!snd_es968_pnp_is_probed) { |
| 363 | isa_unregister_driver(&snd_es1688_driver); |
| 364 | return; |
| 365 | } |
| 366 | #ifdef CONFIG_PNP |
| 367 | pnp_unregister_card_driver(&es968_pnpc_driver); |
| 368 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Rene Herman | ae59618 | 2007-02-14 13:26:17 +0100 | [diff] [blame] | 371 | module_init(alsa_card_es1688_init); |
| 372 | module_exit(alsa_card_es1688_exit); |