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> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 29 | #include <linux/module.h> |
Takashi Iwai | 6cbbfe1 | 2015-01-28 16:49:33 +0100 | [diff] [blame] | 30 | #include <linux/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 | |
Joe Perches | eab0fbf | 2015-04-04 13:38:25 -0700 | [diff] [blame] | 46 | static const struct ac97_quirk ac97_quirks[] = { |
Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 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; |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 60 | static bool 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 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 69 | static const 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) |
Takashi Iwai | 00980aa | 2014-02-25 16:10:25 +0100 | [diff] [blame] | 87 | dev_err(cs5535au->card->dev, |
| 88 | "Failure writing to cs5535 codec\n"); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 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) |
Takashi Iwai | 00980aa | 2014-02-25 16:10:25 +0100 | [diff] [blame] | 113 | dev_err(cs5535au->card->dev, |
| 114 | "Failure reading codec reg 0x%x, Last value=0x%x\n", |
| 115 | reg, val); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 116 | |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 117 | return (unsigned short) val; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 120 | static void snd_cs5535audio_codec_write(struct cs5535audio *cs5535au, |
| 121 | unsigned short reg, unsigned short val) |
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 | unsigned int regdata; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 124 | |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 125 | regdata = ((unsigned int) reg) << 24; |
| 126 | regdata |= val; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 127 | regdata &= CMD_MASK; |
| 128 | regdata |= CMD_NEW; |
| 129 | regdata &= ACC_CODEC_CNTL_WR_CMD; |
| 130 | |
| 131 | cs_writel(cs5535au, ACC_CODEC_CNTL, regdata); |
| 132 | wait_till_cmd_acked(cs5535au, 50); |
| 133 | } |
| 134 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 135 | static void snd_cs5535audio_ac97_codec_write(struct snd_ac97 *ac97, |
| 136 | unsigned short reg, unsigned short val) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 137 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 138 | struct cs5535audio *cs5535au = ac97->private_data; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 139 | snd_cs5535audio_codec_write(cs5535au, reg, val); |
| 140 | } |
| 141 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 142 | static unsigned short snd_cs5535audio_ac97_codec_read(struct snd_ac97 *ac97, |
| 143 | unsigned short reg) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 144 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 145 | struct cs5535audio *cs5535au = ac97->private_data; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 146 | return snd_cs5535audio_codec_read(cs5535au, reg); |
| 147 | } |
| 148 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 149 | static int snd_cs5535audio_mixer(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 150 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 151 | struct snd_card *card = cs5535au->card; |
| 152 | struct snd_ac97_bus *pbus; |
| 153 | struct snd_ac97_template ac97; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 154 | int err; |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 155 | static struct snd_ac97_bus_ops ops = { |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 156 | .write = snd_cs5535audio_ac97_codec_write, |
| 157 | .read = snd_cs5535audio_ac97_codec_read, |
| 158 | }; |
| 159 | |
| 160 | if ((err = snd_ac97_bus(card, 0, &ops, NULL, &pbus)) < 0) |
| 161 | return err; |
| 162 | |
| 163 | memset(&ac97, 0, sizeof(ac97)); |
Jaya Kumar | b035ce0 | 2008-11-05 17:30:08 -0500 | [diff] [blame] | 164 | ac97.scaps = AC97_SCAP_AUDIO | AC97_SCAP_SKIP_MODEM |
| 165 | | AC97_SCAP_POWER_SAVE; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 166 | ac97.private_data = cs5535au; |
| 167 | ac97.pci = cs5535au->pci; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 168 | |
Andres Salomon | 3556d18 | 2008-11-06 16:44:08 -0500 | [diff] [blame] | 169 | /* set any OLPC-specific scaps */ |
| 170 | olpc_prequirks(card, &ac97); |
| 171 | |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 172 | if ((err = snd_ac97_mixer(pbus, &ac97, &cs5535au->ac97)) < 0) { |
Takashi Iwai | 00980aa | 2014-02-25 16:10:25 +0100 | [diff] [blame] | 173 | dev_err(card->dev, "mixer failed\n"); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 174 | return err; |
| 175 | } |
| 176 | |
Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 177 | snd_ac97_tune_hardware(cs5535au->ac97, ac97_quirks, ac97_quirk); |
| 178 | |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 179 | err = olpc_quirks(card, cs5535au->ac97); |
| 180 | if (err < 0) { |
Takashi Iwai | 00980aa | 2014-02-25 16:10:25 +0100 | [diff] [blame] | 181 | dev_err(card->dev, "olpc quirks failed\n"); |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 182 | return err; |
| 183 | } |
| 184 | |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 185 | return 0; |
| 186 | } |
| 187 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 188 | static void process_bm0_irq(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 189 | { |
| 190 | u8 bm_stat; |
| 191 | spin_lock(&cs5535au->reg_lock); |
| 192 | bm_stat = cs_readb(cs5535au, ACC_BM0_STATUS); |
| 193 | spin_unlock(&cs5535au->reg_lock); |
| 194 | if (bm_stat & EOP) { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 195 | struct cs5535audio_dma *dma; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 196 | dma = cs5535au->playback_substream->runtime->private_data; |
| 197 | snd_pcm_period_elapsed(cs5535au->playback_substream); |
| 198 | } else { |
Takashi Iwai | 00980aa | 2014-02-25 16:10:25 +0100 | [diff] [blame] | 199 | dev_err(cs5535au->card->dev, |
| 200 | "unexpected bm0 irq src, bm_stat=%x\n", |
| 201 | bm_stat); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 205 | static void process_bm1_irq(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 206 | { |
| 207 | u8 bm_stat; |
| 208 | spin_lock(&cs5535au->reg_lock); |
| 209 | bm_stat = cs_readb(cs5535au, ACC_BM1_STATUS); |
| 210 | spin_unlock(&cs5535au->reg_lock); |
| 211 | if (bm_stat & EOP) { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 212 | struct cs5535audio_dma *dma; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 213 | dma = cs5535au->capture_substream->runtime->private_data; |
| 214 | snd_pcm_period_elapsed(cs5535au->capture_substream); |
| 215 | } |
| 216 | } |
| 217 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 218 | static irqreturn_t snd_cs5535audio_interrupt(int irq, void *dev_id) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 219 | { |
| 220 | u16 acc_irq_stat; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 221 | unsigned char count; |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 222 | struct cs5535audio *cs5535au = dev_id; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 223 | |
| 224 | if (cs5535au == NULL) |
| 225 | return IRQ_NONE; |
| 226 | |
| 227 | acc_irq_stat = cs_readw(cs5535au, ACC_IRQ_STATUS); |
| 228 | |
| 229 | if (!acc_irq_stat) |
| 230 | return IRQ_NONE; |
Andres Salomon | 4ea2416 | 2007-09-03 15:43:43 +0200 | [diff] [blame] | 231 | for (count = 0; count < 4; count++) { |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 232 | if (acc_irq_stat & (1 << count)) { |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 233 | switch (count) { |
| 234 | case IRQ_STS: |
| 235 | cs_readl(cs5535au, ACC_GPIO_STATUS); |
| 236 | break; |
| 237 | case WU_IRQ_STS: |
| 238 | cs_readl(cs5535au, ACC_GPIO_STATUS); |
| 239 | break; |
| 240 | case BM0_IRQ_STS: |
| 241 | process_bm0_irq(cs5535au); |
| 242 | break; |
| 243 | case BM1_IRQ_STS: |
| 244 | process_bm1_irq(cs5535au); |
| 245 | break; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 246 | default: |
Takashi Iwai | 00980aa | 2014-02-25 16:10:25 +0100 | [diff] [blame] | 247 | dev_err(cs5535au->card->dev, |
| 248 | "Unexpected irq src: 0x%x\n", |
| 249 | acc_irq_stat); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 250 | break; |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | return IRQ_HANDLED; |
| 255 | } |
| 256 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 257 | static int snd_cs5535audio_free(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 258 | { |
| 259 | synchronize_irq(cs5535au->irq); |
Julia Lawall | ec06b2b | 2014-01-03 00:40:30 +0100 | [diff] [blame] | 260 | pci_set_power_state(cs5535au->pci, PCI_D3hot); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 261 | |
| 262 | if (cs5535au->irq >= 0) |
| 263 | free_irq(cs5535au->irq, cs5535au); |
| 264 | |
| 265 | pci_release_regions(cs5535au->pci); |
| 266 | pci_disable_device(cs5535au->pci); |
| 267 | kfree(cs5535au); |
| 268 | return 0; |
| 269 | } |
| 270 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 271 | static int snd_cs5535audio_dev_free(struct snd_device *device) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 272 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 273 | struct cs5535audio *cs5535au = device->device_data; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 274 | return snd_cs5535audio_free(cs5535au); |
| 275 | } |
| 276 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 277 | static int snd_cs5535audio_create(struct snd_card *card, |
| 278 | struct pci_dev *pci, |
| 279 | struct cs5535audio **rcs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 280 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 281 | struct cs5535audio *cs5535au; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 282 | |
| 283 | int err; |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 284 | static struct snd_device_ops ops = { |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 285 | .dev_free = snd_cs5535audio_dev_free, |
| 286 | }; |
| 287 | |
| 288 | *rcs5535au = NULL; |
| 289 | if ((err = pci_enable_device(pci)) < 0) |
| 290 | return err; |
| 291 | |
Quentin Lambert | 412b979 | 2015-04-15 16:10:17 +0200 | [diff] [blame] | 292 | if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0 || |
| 293 | dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { |
Takashi Iwai | 00980aa | 2014-02-25 16:10:25 +0100 | [diff] [blame] | 294 | dev_warn(card->dev, "unable to get 32bit dma\n"); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 295 | err = -ENXIO; |
| 296 | goto pcifail; |
| 297 | } |
| 298 | |
| 299 | cs5535au = kzalloc(sizeof(*cs5535au), GFP_KERNEL); |
| 300 | if (cs5535au == NULL) { |
| 301 | err = -ENOMEM; |
| 302 | goto pcifail; |
| 303 | } |
| 304 | |
| 305 | spin_lock_init(&cs5535au->reg_lock); |
| 306 | cs5535au->card = card; |
| 307 | cs5535au->pci = pci; |
| 308 | cs5535au->irq = -1; |
| 309 | |
| 310 | if ((err = pci_request_regions(pci, "CS5535 Audio")) < 0) { |
| 311 | kfree(cs5535au); |
| 312 | goto pcifail; |
| 313 | } |
| 314 | |
| 315 | cs5535au->port = pci_resource_start(pci, 0); |
| 316 | |
| 317 | if (request_irq(pci->irq, snd_cs5535audio_interrupt, |
Takashi Iwai | 934c2b6 | 2011-06-10 16:36:37 +0200 | [diff] [blame] | 318 | IRQF_SHARED, KBUILD_MODNAME, cs5535au)) { |
Takashi Iwai | 00980aa | 2014-02-25 16:10:25 +0100 | [diff] [blame] | 319 | dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 320 | err = -EBUSY; |
| 321 | goto sndfail; |
| 322 | } |
| 323 | |
| 324 | cs5535au->irq = pci->irq; |
| 325 | pci_set_master(pci); |
| 326 | |
| 327 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 328 | cs5535au, &ops)) < 0) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 329 | goto sndfail; |
| 330 | |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 331 | *rcs5535au = cs5535au; |
| 332 | return 0; |
| 333 | |
| 334 | sndfail: /* leave the device alive, just kill the snd */ |
| 335 | snd_cs5535audio_free(cs5535au); |
| 336 | return err; |
| 337 | |
| 338 | pcifail: |
| 339 | pci_disable_device(pci); |
| 340 | return err; |
| 341 | } |
| 342 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 343 | static int snd_cs5535audio_probe(struct pci_dev *pci, |
| 344 | const struct pci_device_id *pci_id) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 345 | { |
| 346 | static int dev; |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 347 | struct snd_card *card; |
| 348 | struct cs5535audio *cs5535au; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 349 | int err; |
| 350 | |
| 351 | if (dev >= SNDRV_CARDS) |
| 352 | return -ENODEV; |
Takashi Iwai | 302e4c2 | 2006-05-23 13:24:30 +0200 | [diff] [blame] | 353 | if (!enable[dev]) { |
| 354 | dev++; |
| 355 | return -ENOENT; |
| 356 | } |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 357 | |
Takashi Iwai | 60c5772 | 2014-01-29 14:20:19 +0100 | [diff] [blame] | 358 | err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, |
| 359 | 0, &card); |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 360 | if (err < 0) |
| 361 | return err; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 362 | |
| 363 | if ((err = snd_cs5535audio_create(card, pci, &cs5535au)) < 0) |
| 364 | goto probefail_out; |
| 365 | |
Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 366 | card->private_data = cs5535au; |
| 367 | |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 368 | if ((err = snd_cs5535audio_mixer(cs5535au)) < 0) |
| 369 | goto probefail_out; |
| 370 | |
| 371 | if ((err = snd_cs5535audio_pcm(cs5535au)) < 0) |
| 372 | goto probefail_out; |
| 373 | |
| 374 | strcpy(card->driver, DRIVER_NAME); |
| 375 | |
| 376 | strcpy(card->shortname, "CS5535 Audio"); |
| 377 | sprintf(card->longname, "%s %s at 0x%lx, irq %i", |
| 378 | card->shortname, card->driver, |
| 379 | cs5535au->port, cs5535au->irq); |
| 380 | |
| 381 | if ((err = snd_card_register(card)) < 0) |
| 382 | goto probefail_out; |
| 383 | |
| 384 | pci_set_drvdata(pci, card); |
| 385 | dev++; |
| 386 | return 0; |
| 387 | |
| 388 | probefail_out: |
| 389 | snd_card_free(card); |
| 390 | return err; |
| 391 | } |
| 392 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 393 | static void snd_cs5535audio_remove(struct pci_dev *pci) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 394 | { |
Andres Salomon | 3c55494 | 2009-12-14 18:00:36 -0800 | [diff] [blame] | 395 | olpc_quirks_cleanup(); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 396 | snd_card_free(pci_get_drvdata(pci)); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 397 | } |
| 398 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 399 | static struct pci_driver cs5535audio_driver = { |
Takashi Iwai | 3733e42 | 2011-06-10 16:20:20 +0200 | [diff] [blame] | 400 | .name = KBUILD_MODNAME, |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 401 | .id_table = snd_cs5535audio_ids, |
| 402 | .probe = snd_cs5535audio_probe, |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 403 | .remove = snd_cs5535audio_remove, |
Takashi Iwai | c7561cd | 2012-08-14 18:12:04 +0200 | [diff] [blame] | 404 | #ifdef CONFIG_PM_SLEEP |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 405 | .driver = { |
| 406 | .pm = &snd_cs5535audio_pm, |
| 407 | }, |
Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 408 | #endif |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 409 | }; |
| 410 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 411 | module_pci_driver(cs5535audio_driver); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 412 | |
| 413 | MODULE_AUTHOR("Jaya Kumar"); |
| 414 | MODULE_LICENSE("GPL"); |
| 415 | MODULE_DESCRIPTION("CS5535 Audio"); |
| 416 | MODULE_SUPPORTED_DEVICE("CS5535 Audio"); |