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