Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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