| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 1 | /* | 
| Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 2 |  * Driver for audio on multifunction CS5535/6 companion device | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 3 |  * Copyright (C) Jaya Kumar | 
 | 4 |  * | 
 | 5 |  * Based on Jaroslav Kysela and Takashi Iwai's examples. | 
 | 6 |  * This work was sponsored by CIS(M) Sdn Bhd. | 
 | 7 |  * | 
 | 8 |  * This program is free software; you can redistribute it and/or modify | 
 | 9 |  * it under the terms of the GNU General Public License as published by | 
 | 10 |  * the Free Software Foundation; either version 2 of the License, or | 
 | 11 |  * (at your option) any later version. | 
 | 12 |  * | 
 | 13 |  * This program is distributed in the hope that it will be useful, | 
 | 14 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 15 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 16 |  * GNU General Public License for more details. | 
 | 17 |  * | 
 | 18 |  * You should have received a copy of the GNU General Public License | 
 | 19 |  * along with this program; if not, write to the Free Software | 
 | 20 |  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA | 
 | 21 |  * | 
 | 22 |  */ | 
 | 23 |  | 
 | 24 | #include <linux/delay.h> | 
 | 25 | #include <linux/interrupt.h> | 
 | 26 | #include <linux/init.h> | 
 | 27 | #include <linux/pci.h> | 
 | 28 | #include <linux/slab.h> | 
 | 29 | #include <linux/moduleparam.h> | 
 | 30 | #include <asm/io.h> | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 31 | #include <sound/core.h> | 
 | 32 | #include <sound/control.h> | 
 | 33 | #include <sound/pcm.h> | 
 | 34 | #include <sound/rawmidi.h> | 
 | 35 | #include <sound/ac97_codec.h> | 
 | 36 | #include <sound/initval.h> | 
 | 37 | #include <sound/asoundef.h> | 
 | 38 | #include "cs5535audio.h" | 
 | 39 |  | 
 | 40 | #define DRIVER_NAME "cs5535audio" | 
 | 41 |  | 
| Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 42 | static char *ac97_quirk; | 
 | 43 | module_param(ac97_quirk, charp, 0444); | 
 | 44 | MODULE_PARM_DESC(ac97_quirk, "AC'97 board specific workarounds."); | 
 | 45 |  | 
 | 46 | static struct ac97_quirk ac97_quirks[] __devinitdata = { | 
 | 47 | #if 0 /* Not yet confirmed if all 5536 boards are HP only */ | 
 | 48 | 	{ | 
 | 49 | 		.subvendor = PCI_VENDOR_ID_AMD,  | 
 | 50 | 		.subdevice = PCI_DEVICE_ID_AMD_CS5536_AUDIO,  | 
 | 51 | 		.name = "AMD RDK",      | 
 | 52 | 		.type = AC97_TUNE_HP_ONLY | 
 | 53 | 	}, | 
 | 54 | #endif | 
 | 55 | 	{} | 
 | 56 | }; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 57 |  | 
| Takashi Iwai | 302e4c2 | 2006-05-23 13:24:30 +0200 | [diff] [blame] | 58 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; | 
 | 59 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; | 
 | 60 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 61 |  | 
| Takashi Iwai | 302e4c2 | 2006-05-23 13:24:30 +0200 | [diff] [blame] | 62 | module_param_array(index, int, NULL, 0444); | 
| Takashi Iwai | 1dbfd8c | 2006-05-02 18:31:31 +0200 | [diff] [blame] | 63 | MODULE_PARM_DESC(index, "Index value for " DRIVER_NAME); | 
| Takashi Iwai | 302e4c2 | 2006-05-23 13:24:30 +0200 | [diff] [blame] | 64 | module_param_array(id, charp, NULL, 0444); | 
| Takashi Iwai | 1dbfd8c | 2006-05-02 18:31:31 +0200 | [diff] [blame] | 65 | MODULE_PARM_DESC(id, "ID string for " DRIVER_NAME); | 
| Takashi Iwai | 302e4c2 | 2006-05-23 13:24:30 +0200 | [diff] [blame] | 66 | module_param_array(enable, bool, NULL, 0444); | 
 | 67 | MODULE_PARM_DESC(enable, "Enable " DRIVER_NAME); | 
| Takashi Iwai | 1dbfd8c | 2006-05-02 18:31:31 +0200 | [diff] [blame] | 68 |  | 
| Takashi Iwai | f40b689 | 2006-07-05 16:51:05 +0200 | [diff] [blame] | 69 | static struct pci_device_id snd_cs5535audio_ids[] = { | 
| Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 70 | 	{ PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_AUDIO) }, | 
 | 71 | 	{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_AUDIO) }, | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 72 | 	{} | 
 | 73 | }; | 
 | 74 |  | 
 | 75 | MODULE_DEVICE_TABLE(pci, snd_cs5535audio_ids); | 
 | 76 |  | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 77 | static void wait_till_cmd_acked(struct cs5535audio *cs5535au, unsigned long timeout) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 78 | { | 
| Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 79 | 	unsigned int tmp; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 80 | 	do { | 
 | 81 | 		tmp = cs_readl(cs5535au, ACC_CODEC_CNTL); | 
 | 82 | 		if (!(tmp & CMD_NEW)) | 
 | 83 | 			break; | 
| David Vrabel | 1037593 | 2006-03-03 18:01:57 +0100 | [diff] [blame] | 84 | 		udelay(1); | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 85 | 	} while (--timeout); | 
 | 86 | 	if (!timeout) | 
 | 87 | 		snd_printk(KERN_ERR "Failure writing to cs5535 codec\n"); | 
 | 88 | } | 
 | 89 |  | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 90 | static unsigned short snd_cs5535audio_codec_read(struct cs5535audio *cs5535au, | 
 | 91 | 						 unsigned short reg) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 92 | { | 
| Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 93 | 	unsigned int regdata; | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 94 | 	unsigned int timeout; | 
| Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 95 | 	unsigned int val; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 96 |  | 
| Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 97 | 	regdata = ((unsigned int) reg) << 24; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 98 | 	regdata |= ACC_CODEC_CNTL_RD_CMD; | 
 | 99 | 	regdata |= CMD_NEW; | 
 | 100 |  | 
 | 101 | 	cs_writel(cs5535au, ACC_CODEC_CNTL, regdata); | 
| David Vrabel | 1037593 | 2006-03-03 18:01:57 +0100 | [diff] [blame] | 102 | 	wait_till_cmd_acked(cs5535au, 50); | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 103 |  | 
 | 104 | 	timeout = 50; | 
 | 105 | 	do { | 
 | 106 | 		val = cs_readl(cs5535au, ACC_CODEC_STATUS); | 
| Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 107 | 		if ((val & STS_NEW) && reg == (val >> 24)) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 108 | 			break; | 
| David Vrabel | 1037593 | 2006-03-03 18:01:57 +0100 | [diff] [blame] | 109 | 		udelay(1); | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 110 | 	} while (--timeout); | 
 | 111 | 	if (!timeout) | 
| Jaya Kumar | 40a4f7a | 2006-06-13 12:01:14 +0200 | [diff] [blame] | 112 | 		snd_printk(KERN_ERR "Failure reading codec reg 0x%x," | 
 | 113 | 					"Last value=0x%x\n", reg, val); | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 114 |  | 
| Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 115 | 	return (unsigned short) val; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 116 | } | 
 | 117 |  | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 118 | static void snd_cs5535audio_codec_write(struct cs5535audio *cs5535au, | 
 | 119 | 					unsigned short reg, unsigned short val) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 120 | { | 
| Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 121 | 	unsigned int regdata; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 122 |  | 
| Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 123 | 	regdata = ((unsigned int) reg) << 24; | 
 | 124 | 	regdata |= val; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 125 | 	regdata &= CMD_MASK; | 
 | 126 | 	regdata |= CMD_NEW; | 
 | 127 | 	regdata &= ACC_CODEC_CNTL_WR_CMD; | 
 | 128 |  | 
 | 129 | 	cs_writel(cs5535au, ACC_CODEC_CNTL, regdata); | 
 | 130 | 	wait_till_cmd_acked(cs5535au, 50); | 
 | 131 | } | 
 | 132 |  | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 133 | static void snd_cs5535audio_ac97_codec_write(struct snd_ac97 *ac97, | 
 | 134 | 					     unsigned short reg, unsigned short val) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 135 | { | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 136 | 	struct cs5535audio *cs5535au = ac97->private_data; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 137 | 	snd_cs5535audio_codec_write(cs5535au, reg, val); | 
 | 138 | } | 
 | 139 |  | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 140 | static unsigned short snd_cs5535audio_ac97_codec_read(struct snd_ac97 *ac97, | 
 | 141 | 						      unsigned short reg) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 142 | { | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 143 | 	struct cs5535audio *cs5535au = ac97->private_data; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 144 | 	return snd_cs5535audio_codec_read(cs5535au, reg); | 
 | 145 | } | 
 | 146 |  | 
| Randy Dunlap | 5be55be | 2008-01-23 11:52:06 +0100 | [diff] [blame] | 147 | static int __devinit snd_cs5535audio_mixer(struct cs5535audio *cs5535au) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 148 | { | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 149 | 	struct snd_card *card = cs5535au->card; | 
 | 150 | 	struct snd_ac97_bus *pbus; | 
 | 151 | 	struct snd_ac97_template ac97; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 152 | 	int err; | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 153 | 	static struct snd_ac97_bus_ops ops = { | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 154 | 		.write = snd_cs5535audio_ac97_codec_write, | 
 | 155 | 		.read = snd_cs5535audio_ac97_codec_read, | 
 | 156 | 	}; | 
 | 157 |  | 
 | 158 | 	if ((err = snd_ac97_bus(card, 0, &ops, NULL, &pbus)) < 0) | 
 | 159 | 		return err; | 
 | 160 |  | 
 | 161 | 	memset(&ac97, 0, sizeof(ac97)); | 
 | 162 | 	ac97.scaps = AC97_SCAP_AUDIO|AC97_SCAP_SKIP_MODEM; | 
 | 163 | 	ac97.private_data = cs5535au; | 
 | 164 | 	ac97.pci = cs5535au->pci; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 165 |  | 
 | 166 | 	if ((err = snd_ac97_mixer(pbus, &ac97, &cs5535au->ac97)) < 0) { | 
| Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 167 | 		snd_printk(KERN_ERR "mixer failed\n"); | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 168 | 		return err; | 
 | 169 | 	} | 
 | 170 |  | 
| Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 171 | 	snd_ac97_tune_hardware(cs5535au->ac97, ac97_quirks, ac97_quirk); | 
 | 172 |  | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 173 | 	return 0; | 
 | 174 | } | 
 | 175 |  | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 176 | static void process_bm0_irq(struct cs5535audio *cs5535au) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 177 | { | 
 | 178 | 	u8 bm_stat; | 
 | 179 | 	spin_lock(&cs5535au->reg_lock); | 
 | 180 | 	bm_stat = cs_readb(cs5535au, ACC_BM0_STATUS); | 
 | 181 | 	spin_unlock(&cs5535au->reg_lock); | 
 | 182 | 	if (bm_stat & EOP) { | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 183 | 		struct cs5535audio_dma *dma; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 184 | 		dma = cs5535au->playback_substream->runtime->private_data; | 
 | 185 | 		snd_pcm_period_elapsed(cs5535au->playback_substream); | 
 | 186 | 	} else { | 
 | 187 | 		snd_printk(KERN_ERR "unexpected bm0 irq src, bm_stat=%x\n", | 
 | 188 | 					bm_stat); | 
 | 189 | 	} | 
 | 190 | } | 
 | 191 |  | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 192 | static void process_bm1_irq(struct cs5535audio *cs5535au) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 193 | { | 
 | 194 | 	u8 bm_stat; | 
 | 195 | 	spin_lock(&cs5535au->reg_lock); | 
 | 196 | 	bm_stat = cs_readb(cs5535au, ACC_BM1_STATUS); | 
 | 197 | 	spin_unlock(&cs5535au->reg_lock); | 
 | 198 | 	if (bm_stat & EOP) { | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 199 | 		struct cs5535audio_dma *dma; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 200 | 		dma = cs5535au->capture_substream->runtime->private_data; | 
 | 201 | 		snd_pcm_period_elapsed(cs5535au->capture_substream); | 
 | 202 | 	} | 
 | 203 | } | 
 | 204 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 205 | static irqreturn_t snd_cs5535audio_interrupt(int irq, void *dev_id) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 206 | { | 
 | 207 | 	u16 acc_irq_stat; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 208 | 	unsigned char count; | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 209 | 	struct cs5535audio *cs5535au = dev_id; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 210 |  | 
 | 211 | 	if (cs5535au == NULL) | 
 | 212 | 		return IRQ_NONE; | 
 | 213 |  | 
 | 214 | 	acc_irq_stat = cs_readw(cs5535au, ACC_IRQ_STATUS); | 
 | 215 |  | 
 | 216 | 	if (!acc_irq_stat) | 
 | 217 | 		return IRQ_NONE; | 
| Andres Salomon | 4ea2416 | 2007-09-03 15:43:43 +0200 | [diff] [blame] | 218 | 	for (count = 0; count < 4; count++) { | 
| Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 219 | 		if (acc_irq_stat & (1 << count)) { | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 220 | 			switch (count) { | 
 | 221 | 			case IRQ_STS: | 
 | 222 | 				cs_readl(cs5535au, ACC_GPIO_STATUS); | 
 | 223 | 				break; | 
 | 224 | 			case WU_IRQ_STS: | 
 | 225 | 				cs_readl(cs5535au, ACC_GPIO_STATUS); | 
 | 226 | 				break; | 
 | 227 | 			case BM0_IRQ_STS: | 
 | 228 | 				process_bm0_irq(cs5535au); | 
 | 229 | 				break; | 
 | 230 | 			case BM1_IRQ_STS: | 
 | 231 | 				process_bm1_irq(cs5535au); | 
 | 232 | 				break; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 233 | 			default: | 
| Andres Salomon | 4ea2416 | 2007-09-03 15:43:43 +0200 | [diff] [blame] | 234 | 				snd_printk(KERN_ERR "Unexpected irq src: " | 
 | 235 | 						"0x%x\n", acc_irq_stat); | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 236 | 				break; | 
 | 237 | 			} | 
 | 238 | 		} | 
 | 239 | 	} | 
 | 240 | 	return IRQ_HANDLED; | 
 | 241 | } | 
 | 242 |  | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 243 | static int snd_cs5535audio_free(struct cs5535audio *cs5535au) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 244 | { | 
 | 245 | 	synchronize_irq(cs5535au->irq); | 
 | 246 | 	pci_set_power_state(cs5535au->pci, 3); | 
 | 247 |  | 
 | 248 | 	if (cs5535au->irq >= 0) | 
 | 249 | 		free_irq(cs5535au->irq, cs5535au); | 
 | 250 |  | 
 | 251 | 	pci_release_regions(cs5535au->pci); | 
 | 252 | 	pci_disable_device(cs5535au->pci); | 
 | 253 | 	kfree(cs5535au); | 
 | 254 | 	return 0; | 
 | 255 | } | 
 | 256 |  | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 257 | static int snd_cs5535audio_dev_free(struct snd_device *device) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 258 | { | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 259 | 	struct cs5535audio *cs5535au = device->device_data; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 260 | 	return snd_cs5535audio_free(cs5535au); | 
 | 261 | } | 
 | 262 |  | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 263 | static int __devinit snd_cs5535audio_create(struct snd_card *card, | 
 | 264 | 					    struct pci_dev *pci, | 
 | 265 | 					    struct cs5535audio **rcs5535au) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 266 | { | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 267 | 	struct cs5535audio *cs5535au; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 268 |  | 
 | 269 | 	int err; | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 270 | 	static struct snd_device_ops ops = { | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 271 | 		.dev_free =	snd_cs5535audio_dev_free, | 
 | 272 | 	}; | 
 | 273 |  | 
 | 274 | 	*rcs5535au = NULL; | 
 | 275 | 	if ((err = pci_enable_device(pci)) < 0) | 
 | 276 | 		return err; | 
 | 277 |  | 
 | 278 | 	if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0 || | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 279 | 	    pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0) { | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 280 | 		printk(KERN_WARNING "unable to get 32bit dma\n"); | 
 | 281 | 		err = -ENXIO; | 
 | 282 | 		goto pcifail; | 
 | 283 | 	} | 
 | 284 |  | 
 | 285 | 	cs5535au = kzalloc(sizeof(*cs5535au), GFP_KERNEL); | 
 | 286 | 	if (cs5535au == NULL) { | 
 | 287 | 		err = -ENOMEM; | 
 | 288 | 		goto pcifail; | 
 | 289 | 	} | 
 | 290 |  | 
 | 291 | 	spin_lock_init(&cs5535au->reg_lock); | 
 | 292 | 	cs5535au->card = card; | 
 | 293 | 	cs5535au->pci = pci; | 
 | 294 | 	cs5535au->irq = -1; | 
 | 295 |  | 
 | 296 | 	if ((err = pci_request_regions(pci, "CS5535 Audio")) < 0) { | 
 | 297 | 		kfree(cs5535au); | 
 | 298 | 		goto pcifail; | 
 | 299 | 	} | 
 | 300 |  | 
 | 301 | 	cs5535au->port = pci_resource_start(pci, 0); | 
 | 302 |  | 
 | 303 | 	if (request_irq(pci->irq, snd_cs5535audio_interrupt, | 
| Takashi Iwai | 437a5a4 | 2006-11-21 12:14:23 +0100 | [diff] [blame] | 304 | 			IRQF_SHARED, "CS5535 Audio", cs5535au)) { | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 305 | 		snd_printk("unable to grab IRQ %d\n", pci->irq); | 
 | 306 | 		err = -EBUSY; | 
 | 307 | 		goto sndfail; | 
 | 308 | 	} | 
 | 309 |  | 
 | 310 | 	cs5535au->irq = pci->irq; | 
 | 311 | 	pci_set_master(pci); | 
 | 312 |  | 
 | 313 | 	if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 314 | 				  cs5535au, &ops)) < 0) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 315 | 		goto sndfail; | 
 | 316 |  | 
 | 317 | 	snd_card_set_dev(card, &pci->dev); | 
 | 318 |  | 
 | 319 | 	*rcs5535au = cs5535au; | 
 | 320 | 	return 0; | 
 | 321 |  | 
 | 322 | sndfail: /* leave the device alive, just kill the snd */ | 
 | 323 | 	snd_cs5535audio_free(cs5535au); | 
 | 324 | 	return err; | 
 | 325 |  | 
 | 326 | pcifail: | 
 | 327 | 	pci_disable_device(pci); | 
 | 328 | 	return err; | 
 | 329 | } | 
 | 330 |  | 
 | 331 | static int __devinit snd_cs5535audio_probe(struct pci_dev *pci, | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 332 | 					   const struct pci_device_id *pci_id) | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 333 | { | 
 | 334 | 	static int dev; | 
| Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 335 | 	struct snd_card *card; | 
 | 336 | 	struct cs5535audio *cs5535au; | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 337 | 	int err; | 
 | 338 |  | 
 | 339 | 	if (dev >= SNDRV_CARDS) | 
 | 340 | 		return -ENODEV; | 
| Takashi Iwai | 302e4c2 | 2006-05-23 13:24:30 +0200 | [diff] [blame] | 341 | 	if (!enable[dev]) { | 
 | 342 | 		dev++; | 
 | 343 | 		return -ENOENT; | 
 | 344 | 	} | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 345 |  | 
| Takashi Iwai | 302e4c2 | 2006-05-23 13:24:30 +0200 | [diff] [blame] | 346 | 	card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 347 | 	if (card == NULL) | 
 | 348 | 		return -ENOMEM; | 
 | 349 |  | 
 | 350 | 	if ((err = snd_cs5535audio_create(card, pci, &cs5535au)) < 0) | 
 | 351 | 		goto probefail_out; | 
 | 352 |  | 
| Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 353 | 	card->private_data = cs5535au; | 
 | 354 |  | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 355 | 	if ((err = snd_cs5535audio_mixer(cs5535au)) < 0) | 
 | 356 | 		goto probefail_out; | 
 | 357 |  | 
 | 358 | 	if ((err = snd_cs5535audio_pcm(cs5535au)) < 0) | 
 | 359 | 		goto probefail_out; | 
 | 360 |  | 
 | 361 | 	strcpy(card->driver, DRIVER_NAME); | 
 | 362 |  | 
 | 363 | 	strcpy(card->shortname, "CS5535 Audio"); | 
 | 364 | 	sprintf(card->longname, "%s %s at 0x%lx, irq %i", | 
 | 365 | 		card->shortname, card->driver, | 
 | 366 | 		cs5535au->port, cs5535au->irq); | 
 | 367 |  | 
 | 368 | 	if ((err = snd_card_register(card)) < 0) | 
 | 369 | 		goto probefail_out; | 
 | 370 |  | 
 | 371 | 	pci_set_drvdata(pci, card); | 
 | 372 | 	dev++; | 
 | 373 | 	return 0; | 
 | 374 |  | 
 | 375 | probefail_out: | 
 | 376 | 	snd_card_free(card); | 
 | 377 | 	return err; | 
 | 378 | } | 
 | 379 |  | 
 | 380 | static void __devexit snd_cs5535audio_remove(struct pci_dev *pci) | 
 | 381 | { | 
 | 382 | 	snd_card_free(pci_get_drvdata(pci)); | 
 | 383 | 	pci_set_drvdata(pci, NULL); | 
 | 384 | } | 
 | 385 |  | 
 | 386 | static struct pci_driver driver = { | 
 | 387 | 	.name = DRIVER_NAME, | 
 | 388 | 	.id_table = snd_cs5535audio_ids, | 
 | 389 | 	.probe = snd_cs5535audio_probe, | 
 | 390 | 	.remove = __devexit_p(snd_cs5535audio_remove), | 
| Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 391 | #ifdef CONFIG_PM | 
 | 392 | 	.suspend = snd_cs5535audio_suspend, | 
 | 393 | 	.resume = snd_cs5535audio_resume, | 
 | 394 | #endif | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 395 | }; | 
 | 396 |  | 
 | 397 | static int __init alsa_card_cs5535audio_init(void) | 
 | 398 | { | 
| Ben Gardner | e329113 | 2006-01-09 20:51:29 -0800 | [diff] [blame] | 399 | 	return pci_register_driver(&driver); | 
| Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 400 | } | 
 | 401 |  | 
 | 402 | static void __exit alsa_card_cs5535audio_exit(void) | 
 | 403 | { | 
 | 404 | 	pci_unregister_driver(&driver); | 
 | 405 | } | 
 | 406 |  | 
 | 407 | module_init(alsa_card_cs5535audio_init) | 
 | 408 | module_exit(alsa_card_cs5535audio_exit) | 
 | 409 |  | 
 | 410 | MODULE_AUTHOR("Jaya Kumar"); | 
 | 411 | MODULE_LICENSE("GPL"); | 
 | 412 | MODULE_DESCRIPTION("CS5535 Audio"); | 
 | 413 | MODULE_SUPPORTED_DEVICE("CS5535 Audio"); |