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