| 1 | /*
|
|---|
| 2 | * Driver for C-Media's CMI8330 soundcards.
|
|---|
| 3 | * Copyright (c) by George Talusan <gstalusan@uwaterloo.ca>
|
|---|
| 4 | * http://www.undergrad.math.uwaterloo.ca/~gstalusa
|
|---|
| 5 | *
|
|---|
| 6 | * This program is free software; you can redistribute it and/or modify
|
|---|
| 7 | * it under the terms of the GNU General Public License as published by
|
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or
|
|---|
| 9 | * (at your option) any later version.
|
|---|
| 10 | *
|
|---|
| 11 | * This program is distributed in the hope that it will be useful,
|
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | * GNU General Public License for more details.
|
|---|
| 15 | *
|
|---|
| 16 | * You should have received a copy of the GNU General Public License
|
|---|
| 17 | * along with this program; if not, write to the Free Software
|
|---|
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|---|
| 19 | *
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | /*
|
|---|
| 23 | * NOTES
|
|---|
| 24 | *
|
|---|
| 25 | * The extended registers contain mixer settings which are largely
|
|---|
| 26 | * untapped for the time being.
|
|---|
| 27 | *
|
|---|
| 28 | * MPU401 and SPDIF are not supported yet. I don't have the hardware
|
|---|
| 29 | * to aid in coding and testing, so I won't bother.
|
|---|
| 30 | *
|
|---|
| 31 | * To quickly load the module,
|
|---|
| 32 | *
|
|---|
| 33 | * modprobe -a snd-card-cmi8330 snd_sbport=0x220 snd_sbirq=5 snd_sbdma8=1
|
|---|
| 34 | * snd_sbdma16=5 snd_wssport=0x530 snd_wssirq=11 snd_wssdma=0
|
|---|
| 35 | *
|
|---|
| 36 | * This card has two mixers and two PCM devices. I've cheesed it such
|
|---|
| 37 | * that recording and playback can be done through the same device.
|
|---|
| 38 | * The driver "magically" routes the capturing to the AD1848 codec,
|
|---|
| 39 | * and playback to the SB16 codec. This allows for full-duplex mode
|
|---|
| 40 | * to some extent.
|
|---|
| 41 | * The utilities in alsa-utils are aware of both devices, so passing
|
|---|
| 42 | * the appropriate parameters to amixer and alsactl will give you
|
|---|
| 43 | * full control over both mixers.
|
|---|
| 44 | */
|
|---|
| 45 |
|
|---|
| 46 | #define SNDRV_MAIN_OBJECT_FILE
|
|---|
| 47 |
|
|---|
| 48 | #include <sound/driver.h>
|
|---|
| 49 | #include <sound/ad1848.h>
|
|---|
| 50 | #include <sound/sb.h>
|
|---|
| 51 | #define SNDRV_GET_ID
|
|---|
| 52 | #include <sound/initval.h>
|
|---|
| 53 |
|
|---|
| 54 | EXPORT_NO_SYMBOLS;
|
|---|
| 55 | MODULE_DESCRIPTION("C-Media CMI8330");
|
|---|
| 56 | MODULE_CLASSES("{sound}");
|
|---|
| 57 | MODULE_DEVICES("{{C-Media,CMI8330,isapnp:{CMI0001,@@@0001,@X@0001}}}");
|
|---|
| 58 |
|
|---|
| 59 | static int snd_index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
|
|---|
| 60 | static char *snd_id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
|
|---|
| 61 | static int snd_enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE;
|
|---|
| 62 | #ifdef __ISAPNP__
|
|---|
| 63 | #ifdef TARGET_OS2
|
|---|
| 64 | static int snd_isapnp[SNDRV_CARDS] = {REPEAT_SNDRV(1)};
|
|---|
| 65 | #else
|
|---|
| 66 | static int snd_isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
|
|---|
| 67 | #endif
|
|---|
| 68 | #endif
|
|---|
| 69 | static long snd_sbport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
|
|---|
| 70 | static int snd_sbirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
|
|---|
| 71 | static int snd_sbdma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
|
|---|
| 72 | static int snd_sbdma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
|
|---|
| 73 | static long snd_wssport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
|
|---|
| 74 | static int snd_wssirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
|
|---|
| 75 | static int snd_wssdma[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
|
|---|
| 76 |
|
|---|
| 77 | MODULE_AUTHOR("George Talusan <gstalusan@uwaterloo.ca>");
|
|---|
| 78 | MODULE_PARM(snd_index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
|---|
| 79 | MODULE_PARM_DESC(snd_index, "Index value for CMI8330 soundcard.");
|
|---|
| 80 | MODULE_PARM_SYNTAX(snd_index, SNDRV_INDEX_DESC);
|
|---|
| 81 | MODULE_PARM(snd_id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
|
|---|
| 82 | MODULE_PARM_DESC(snd_id, "ID string for CMI8330 soundcard.");
|
|---|
| 83 | MODULE_PARM_SYNTAX(snd_id, SNDRV_ID_DESC);
|
|---|
| 84 | MODULE_PARM(snd_enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
|---|
| 85 | MODULE_PARM_DESC(snd_enable, "Enable CMI8330 soundcard.");
|
|---|
| 86 | MODULE_PARM_SYNTAX(snd_enable, SNDRV_ENABLE_DESC);
|
|---|
| 87 | #ifdef __ISAPNP__
|
|---|
| 88 | MODULE_PARM(snd_isapnp, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
|---|
| 89 | MODULE_PARM_DESC(snd_isapnp, "ISA PnP detection for specified soundcard.");
|
|---|
| 90 | MODULE_PARM_SYNTAX(snd_isapnp, SNDRV_ISAPNP_DESC);
|
|---|
| 91 | #endif
|
|---|
| 92 |
|
|---|
| 93 | MODULE_PARM(snd_sbport, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
|
|---|
| 94 | MODULE_PARM_DESC(snd_sbport, "Port # for CMI8330 SB driver.");
|
|---|
| 95 | MODULE_PARM_SYNTAX(snd_sbport, SNDRV_ENABLED ",allows:{{0x220,0x280,0x20}},prefers:{0x220},base:16,dialog:list");
|
|---|
| 96 | MODULE_PARM(snd_sbirq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
|---|
| 97 | MODULE_PARM_DESC(snd_sbirq, "IRQ # for CMI8330 SB driver.");
|
|---|
| 98 | MODULE_PARM_SYNTAX(snd_sbirq, SNDRV_ENABLED ",allows:{{5},{7},{9},{10},{11},{12}},prefers:{5},dialog:list");
|
|---|
| 99 | MODULE_PARM(snd_sbdma8, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
|---|
| 100 | MODULE_PARM_DESC(snd_sbdma8, "DMA8 for CMI8330 SB driver.");
|
|---|
| 101 | MODULE_PARM_SYNTAX(snd_sbdma8, SNDRV_DMA8_DESC ",prefers:{1}");
|
|---|
| 102 | MODULE_PARM(snd_sbdma16, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
|---|
| 103 | MODULE_PARM_DESC(snd_sbdma16, "DMA16 for CMI8330 SB driver.");
|
|---|
| 104 | MODULE_PARM_SYNTAX(snd_sbdma16, SNDRV_ENABLED ",allows:{{5},{7}},prefers:{5},dialog:list");
|
|---|
| 105 |
|
|---|
| 106 | MODULE_PARM(snd_wssport, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
|
|---|
| 107 | MODULE_PARM_DESC(snd_wssport, "Port # for CMI8330 WSS driver.");
|
|---|
| 108 | MODULE_PARM_SYNTAX(snd_wssport, SNDRV_ENABLED ",allows:{{0x530},{0xe80,0xf40,0xc0}},prefers:{0x530},base:16,dialog:list");
|
|---|
| 109 | MODULE_PARM(snd_wssirq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
|---|
| 110 | MODULE_PARM_DESC(snd_wssirq, "IRQ # for CMI8330 WSS driver.");
|
|---|
| 111 | MODULE_PARM_SYNTAX(snd_wssirq, SNDRV_ENABLED ",allows:{{5},{7},{9},{10},{11},{12}},prefers:{11},dialog:list");
|
|---|
| 112 | MODULE_PARM(snd_wssdma, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
|---|
| 113 | MODULE_PARM_DESC(snd_wssdma, "DMA for CMI8330 WSS driver.");
|
|---|
| 114 | MODULE_PARM_SYNTAX(snd_wssdma, SNDRV_DMA8_DESC ",prefers:{0}");
|
|---|
| 115 |
|
|---|
| 116 | #define CMI8330_RMUX3D 16
|
|---|
| 117 | #define CMI8330_MUTEMUX 17
|
|---|
| 118 | #define CMI8330_OUTPUTVOL 18
|
|---|
| 119 | #define CMI8330_MASTVOL 19
|
|---|
| 120 | #define CMI8330_LINVOL 20
|
|---|
| 121 | #define CMI8330_CDINVOL 21
|
|---|
| 122 | #define CMI8330_WAVVOL 22
|
|---|
| 123 | #define CMI8330_RECMUX 23
|
|---|
| 124 | #define CMI8330_WAVGAIN 24
|
|---|
| 125 | #define CMI8330_LINGAIN 25
|
|---|
| 126 | #define CMI8330_CDINGAIN 26
|
|---|
| 127 |
|
|---|
| 128 | static unsigned char snd_cmi8330_image[((CMI8330_CDINGAIN)-16) + 1] =
|
|---|
| 129 | {
|
|---|
| 130 | 0x0, /* 16 - recording mux */
|
|---|
| 131 | 0x40, /* 17 - mute mux */
|
|---|
| 132 | 0x0, /* 18 - vol */
|
|---|
| 133 | 0x0, /* 19 - master volume */
|
|---|
| 134 | 0x0, /* 20 - line-in volume */
|
|---|
| 135 | 0x0, /* 21 - cd-in volume */
|
|---|
| 136 | 0x0, /* 22 - wave volume */
|
|---|
| 137 | 0x0, /* 23 - mute/rec mux */
|
|---|
| 138 | 0x0, /* 24 - wave rec gain */
|
|---|
| 139 | 0x0, /* 25 - line-in rec gain */
|
|---|
| 140 | 0x0 /* 26 - cd-in rec gain */
|
|---|
| 141 | };
|
|---|
| 142 |
|
|---|
| 143 | struct snd_cmi8330 {
|
|---|
| 144 | #ifdef __ISAPNP__
|
|---|
| 145 | struct isapnp_dev *cap;
|
|---|
| 146 | struct isapnp_dev *play;
|
|---|
| 147 | #endif
|
|---|
| 148 | };
|
|---|
| 149 |
|
|---|
| 150 | static snd_card_t *snd_cmi8330_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
|
|---|
| 151 |
|
|---|
| 152 | #ifdef __ISAPNP__
|
|---|
| 153 |
|
|---|
| 154 | static struct isapnp_card *snd_cmi8330_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
|
|---|
| 155 | static const struct isapnp_card_id *snd_cmi8330_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
|
|---|
| 156 |
|
|---|
| 157 | #ifdef TARGET_OS2
|
|---|
| 158 | #define ISAPNP_CMI8330(_va, _vb, _vc, _device, _audio1, _audio2) \
|
|---|
| 159 | { \
|
|---|
| 160 | 0, ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
|
|---|
| 161 | { ISAPNP_DEVICE_ID('@', '@', '@', _audio1), \
|
|---|
| 162 | ISAPNP_DEVICE_ID('@', 'X', '@', _audio2), } \
|
|---|
| 163 | }
|
|---|
| 164 | #else
|
|---|
| 165 | #define ISAPNP_CMI8330(_va, _vb, _vc, _device, _audio1, _audio2) \
|
|---|
| 166 | { \
|
|---|
| 167 | ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
|
|---|
| 168 | devs : { ISAPNP_DEVICE_ID('@', '@', '@', _audio1), \
|
|---|
| 169 | ISAPNP_DEVICE_ID('@', 'X', '@', _audio2), } \
|
|---|
| 170 | }
|
|---|
| 171 | #endif
|
|---|
| 172 |
|
|---|
| 173 | static struct isapnp_card_id snd_cmi8330_pnpids[] __devinitdata =
|
|---|
| 174 | {
|
|---|
| 175 | ISAPNP_CMI8330('C','M','I',0x0001,0x0001,0x0001),
|
|---|
| 176 | { ISAPNP_CARD_END, }
|
|---|
| 177 | };
|
|---|
| 178 |
|
|---|
| 179 | ISAPNP_CARD_TABLE(snd_cmi8330_pnpids);
|
|---|
| 180 |
|
|---|
| 181 | #endif
|
|---|
| 182 |
|
|---|
| 183 | #define CMI8330_CONTROLS (sizeof(snd_cmi8330_controls)/sizeof(snd_kcontrol_new_t))
|
|---|
| 184 |
|
|---|
| 185 | static snd_kcontrol_new_t snd_cmi8330_controls[] __devinitdata = {
|
|---|
| 186 | AD1848_DOUBLE("Master Playback Volume", 0, CMI8330_MASTVOL, CMI8330_MASTVOL, 4, 0, 15, 0),
|
|---|
| 187 | AD1848_SINGLE("Loud Playback Switch", 0, CMI8330_MUTEMUX, 6, 1, 1),
|
|---|
| 188 | AD1848_DOUBLE("PCM Playback Switch", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 7, 7, 1, 1),
|
|---|
| 189 | AD1848_DOUBLE("PCM Playback Volume", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 0, 0, 63, 0),
|
|---|
| 190 | AD1848_DOUBLE("Line Playback Switch", 0, CMI8330_MUTEMUX, CMI8330_MUTEMUX, 4, 3, 1, 0),
|
|---|
| 191 | AD1848_DOUBLE("Line Playback Volume", 0, CMI8330_LINVOL, CMI8330_LINVOL, 4, 0, 15, 0),
|
|---|
| 192 | AD1848_DOUBLE("Line Capture Switch", 0, CMI8330_RMUX3D, CMI8330_RMUX3D, 2, 1, 1, 0),
|
|---|
| 193 | AD1848_DOUBLE("Line Capture Volume", 0, CMI8330_LINGAIN, CMI8330_LINGAIN, 4, 0, 15, 0),
|
|---|
| 194 | AD1848_DOUBLE("CD Playback Switch", 0, CMI8330_MUTEMUX, CMI8330_MUTEMUX, 2, 1, 1, 0),
|
|---|
| 195 | AD1848_DOUBLE("CD Capture Switch", 0, CMI8330_RMUX3D, CMI8330_RMUX3D, 4, 3, 1, 0),
|
|---|
| 196 | AD1848_DOUBLE("CD Playback Volume", 0, CMI8330_CDINVOL, CMI8330_CDINVOL, 4, 0, 15, 0),
|
|---|
| 197 | AD1848_DOUBLE("CD Capture Switch", 0, CMI8330_CDINGAIN, CMI8330_CDINGAIN, 4, 0, 15, 0),
|
|---|
| 198 | AD1848_SINGLE("Mic Playback Switch", 0, CMI8330_MUTEMUX, 0, 1, 0),
|
|---|
| 199 | AD1848_SINGLE("Mic Playback Volume", 0, CMI8330_OUTPUTVOL, 0, 7, 0),
|
|---|
| 200 | AD1848_SINGLE("Mic Capture Switch", 0, CMI8330_RMUX3D, 0, 1, 0),
|
|---|
| 201 | AD1848_SINGLE("Mic Capture Volume", 0, CMI8330_OUTPUTVOL, 5, 7, 0),
|
|---|
| 202 | AD1848_DOUBLE("Wavetable Playback Switch", 0, CMI8330_RECMUX, CMI8330_RECMUX, 1, 0, 1, 0),
|
|---|
| 203 | AD1848_DOUBLE("Wavetable Playback Volume", 0, CMI8330_WAVVOL, CMI8330_WAVVOL, 4, 0, 15, 0),
|
|---|
| 204 | AD1848_DOUBLE("Wavetable Capture Switch", 0, CMI8330_RECMUX, CMI8330_RECMUX, 5, 4, 1, 0),
|
|---|
| 205 | AD1848_DOUBLE("Wavetable Capture Volume", 0, CMI8330_WAVGAIN, CMI8330_WAVGAIN, 4, 0, 15, 0),
|
|---|
| 206 | AD1848_SINGLE("3D Control - Switch", 0, CMI8330_RMUX3D, 5, 1, 1),
|
|---|
| 207 | AD1848_SINGLE("PC Speaker Playback Volume", 0, CMI8330_OUTPUTVOL, 3, 3, 0),
|
|---|
| 208 | AD1848_SINGLE("FM Playback Switch", 0, CMI8330_RECMUX, 3, 1, 1),
|
|---|
| 209 | AD1848_SINGLE("IEC958 Input Capture Switch", 0, CMI8330_RMUX3D, 7, 1, 1),
|
|---|
| 210 | AD1848_SINGLE("IEC958 Input Playback Switch", 0, CMI8330_MUTEMUX, 7, 1, 1),
|
|---|
| 211 | };
|
|---|
| 212 |
|
|---|
| 213 | static int __init snd_cmi8330_mixer(snd_card_t *card, ad1848_t *chip)
|
|---|
| 214 | {
|
|---|
| 215 | int idx, err;
|
|---|
| 216 |
|
|---|
| 217 | strcpy(card->mixername, "CMI8330/C3D");
|
|---|
| 218 |
|
|---|
| 219 | for (idx = 0; idx < CMI8330_CONTROLS; idx++)
|
|---|
| 220 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cmi8330_controls[idx], chip))) < 0)
|
|---|
| 221 | return err;
|
|---|
| 222 |
|
|---|
| 223 | return 0;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | #ifdef __ISAPNP__
|
|---|
| 227 | static int __init snd_cmi8330_isapnp(int dev, struct snd_cmi8330 *acard)
|
|---|
| 228 | {
|
|---|
| 229 | const struct isapnp_card_id *id = snd_cmi8330_isapnp_id[dev];
|
|---|
| 230 | struct isapnp_card *card = snd_cmi8330_isapnp_cards[dev];
|
|---|
| 231 | struct isapnp_dev *pdev;
|
|---|
| 232 |
|
|---|
| 233 | acard->cap = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
|
|---|
| 234 | if (acard->cap->active) {
|
|---|
| 235 | acard->cap = NULL;
|
|---|
| 236 | return -EBUSY;
|
|---|
| 237 | }
|
|---|
| 238 | acard->play = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
|
|---|
| 239 | if (acard->play->active) {
|
|---|
| 240 | acard->cap = acard->play = NULL;
|
|---|
| 241 | return -EBUSY;
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | pdev = acard->cap;
|
|---|
| 245 | if (pdev->prepare(pdev)<0)
|
|---|
| 246 | return -EAGAIN;
|
|---|
| 247 | /* allocate AD1848 resources */
|
|---|
| 248 | if (snd_wssport[dev] != SNDRV_AUTO_PORT)
|
|---|
| 249 | isapnp_resource_change(&pdev->resource[0], snd_wssport[dev], 8);
|
|---|
| 250 | if (snd_wssdma[dev] != SNDRV_AUTO_DMA)
|
|---|
| 251 | isapnp_resource_change(&pdev->dma_resource[0], snd_wssdma[dev], 1);
|
|---|
| 252 | if (snd_wssirq[dev] != SNDRV_AUTO_IRQ)
|
|---|
| 253 | isapnp_resource_change(&pdev->irq_resource[0], snd_wssirq[dev], 1);
|
|---|
| 254 |
|
|---|
| 255 | if (pdev->activate(pdev)<0) {
|
|---|
| 256 | snd_printk("(AD1848) PnP configure failure\n");
|
|---|
| 257 | return -EBUSY;
|
|---|
| 258 | }
|
|---|
| 259 | snd_wssport[dev] = pdev->resource[0].start;
|
|---|
| 260 | snd_wssdma[dev] = pdev->dma_resource[0].start;
|
|---|
| 261 | snd_wssirq[dev] = pdev->irq_resource[0].start;
|
|---|
| 262 |
|
|---|
| 263 | /* allocate SB16 resources */
|
|---|
| 264 | pdev = acard->play;
|
|---|
| 265 | if (pdev->prepare(pdev)<0) {
|
|---|
| 266 | acard->cap->deactivate(acard->cap);
|
|---|
| 267 | return -EAGAIN;
|
|---|
| 268 | }
|
|---|
| 269 | if (snd_sbport[dev] != SNDRV_AUTO_PORT)
|
|---|
| 270 | isapnp_resource_change(&pdev->resource[0], snd_sbport[dev], 16);
|
|---|
| 271 | if (snd_sbdma8[dev] != SNDRV_AUTO_DMA)
|
|---|
| 272 | isapnp_resource_change(&pdev->dma_resource[0], snd_sbdma8[dev], 1);
|
|---|
| 273 | if (snd_sbdma16[dev] != SNDRV_AUTO_DMA)
|
|---|
| 274 | isapnp_resource_change(&pdev->dma_resource[1], snd_sbdma16[dev], 1);
|
|---|
| 275 | if (snd_sbirq[dev] != SNDRV_AUTO_IRQ)
|
|---|
| 276 | isapnp_resource_change(&pdev->irq_resource[0], snd_sbirq[dev], 1);
|
|---|
| 277 |
|
|---|
| 278 | if (pdev->activate(pdev)<0) {
|
|---|
| 279 | snd_printk("CMI8330/C3D (SB16) PnP configure failure\n");
|
|---|
| 280 | acard->cap->deactivate(acard->cap);
|
|---|
| 281 | return -EBUSY;
|
|---|
| 282 | }
|
|---|
| 283 | snd_sbport[dev] = pdev->resource[0].start;
|
|---|
| 284 | snd_sbdma8[dev] = pdev->dma_resource[0].start;
|
|---|
| 285 | snd_sbdma16[dev] = pdev->dma_resource[1].start;
|
|---|
| 286 | snd_sbirq[dev] = pdev->irq_resource[0].start;
|
|---|
| 287 |
|
|---|
| 288 | return 0;
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | static void snd_cmi8330_deactivate(struct snd_cmi8330 *acard)
|
|---|
| 292 | {
|
|---|
| 293 | if (acard->cap) {
|
|---|
| 294 | acard->cap->deactivate(acard->cap);
|
|---|
| 295 | acard->cap = NULL;
|
|---|
| 296 | }
|
|---|
| 297 | if (acard->play) {
|
|---|
| 298 | acard->play->deactivate(acard->play);
|
|---|
| 299 | acard->play = NULL;
|
|---|
| 300 | }
|
|---|
| 301 | }
|
|---|
| 302 | #endif
|
|---|
| 303 |
|
|---|
| 304 | static void snd_cmi8330_free(snd_card_t *card)
|
|---|
| 305 | {
|
|---|
| 306 | struct snd_cmi8330 *acard = (struct snd_cmi8330 *)card->private_data;
|
|---|
| 307 |
|
|---|
| 308 | if (acard) {
|
|---|
| 309 | #ifdef __ISAPNP__
|
|---|
| 310 | snd_cmi8330_deactivate(acard);
|
|---|
| 311 | #endif
|
|---|
| 312 | }
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 | static int __init snd_cmi8330_probe(int dev)
|
|---|
| 316 | {
|
|---|
| 317 | snd_card_t *card;
|
|---|
| 318 | struct snd_cmi8330 *acard;
|
|---|
| 319 | ad1848_t *chip_wss;
|
|---|
| 320 | sb_t *chip_sb;
|
|---|
| 321 | unsigned long flags;
|
|---|
| 322 | int i, err;
|
|---|
| 323 | snd_pcm_t *pcm, *wss_pcm, *sb_pcm;
|
|---|
| 324 | snd_pcm_str_t *pstr;
|
|---|
| 325 |
|
|---|
| 326 | #ifdef __ISAPNP__
|
|---|
| 327 | if (!snd_isapnp[dev]) {
|
|---|
| 328 | #endif
|
|---|
| 329 | if (snd_wssport[dev] == SNDRV_AUTO_PORT) {
|
|---|
| 330 | snd_printk("specify snd_wssport\n");
|
|---|
| 331 | return -EINVAL;
|
|---|
| 332 | }
|
|---|
| 333 | if (snd_sbport[dev] == SNDRV_AUTO_PORT) {
|
|---|
| 334 | snd_printk("specify snd_sbport\n");
|
|---|
| 335 | return -EINVAL;
|
|---|
| 336 | }
|
|---|
| 337 | #ifdef __ISAPNP__
|
|---|
| 338 | }
|
|---|
| 339 | #endif
|
|---|
| 340 | card = snd_card_new(snd_index[dev], snd_id[dev], THIS_MODULE,
|
|---|
| 341 | sizeof(struct snd_cmi8330));
|
|---|
| 342 | if (card == NULL) {
|
|---|
| 343 | snd_printk("could not get a new card\n");
|
|---|
| 344 | return -ENOMEM;
|
|---|
| 345 | }
|
|---|
| 346 | acard = (struct snd_cmi8330 *)card->private_data;
|
|---|
| 347 | card->private_free = snd_cmi8330_free;
|
|---|
| 348 |
|
|---|
| 349 | #ifdef __ISAPNP__
|
|---|
| 350 | if (snd_isapnp[dev] && (err = snd_cmi8330_isapnp(dev, acard)) < 0) {
|
|---|
| 351 | snd_printk("PnP detection failed\n");
|
|---|
| 352 | snd_card_free(card);
|
|---|
| 353 | return err;
|
|---|
| 354 | }
|
|---|
| 355 | #endif
|
|---|
| 356 |
|
|---|
| 357 | if ((err = snd_ad1848_create(card,
|
|---|
| 358 | snd_wssport[dev] + 4,
|
|---|
| 359 | snd_wssirq[dev],
|
|---|
| 360 | snd_wssdma[dev],
|
|---|
| 361 | AD1848_HW_DETECT,
|
|---|
| 362 | &chip_wss)) < 0) {
|
|---|
| 363 | snd_printk("(AD1848) device busy??\n");
|
|---|
| 364 | snd_card_free(card);
|
|---|
| 365 | return err;
|
|---|
| 366 | }
|
|---|
| 367 | if (chip_wss->hardware != AD1848_HW_CMI8330) {
|
|---|
| 368 | snd_printk("(AD1848) not found during probe\n");
|
|---|
| 369 | snd_card_free(card);
|
|---|
| 370 | return -ENODEV;
|
|---|
| 371 | }
|
|---|
| 372 | if ((err = snd_ad1848_pcm(chip_wss, 0, &wss_pcm)) < 0) {
|
|---|
| 373 | snd_printk("(AD1848) no enough memory??\n");
|
|---|
| 374 | snd_card_free(card);
|
|---|
| 375 | return err;
|
|---|
| 376 | }
|
|---|
| 377 |
|
|---|
| 378 | if ((err = snd_sbdsp_create(card, snd_sbport[dev],
|
|---|
| 379 | snd_sbirq[dev],
|
|---|
| 380 | snd_sb16dsp_interrupt,
|
|---|
| 381 | snd_sbdma8[dev],
|
|---|
| 382 | snd_sbdma16[dev],
|
|---|
| 383 | SB_HW_AUTO, &chip_sb)) < 0) {
|
|---|
| 384 | snd_printk("(SB16) device busy??\n");
|
|---|
| 385 | snd_card_free(card);
|
|---|
| 386 | return err;
|
|---|
| 387 | }
|
|---|
| 388 | if ((err = snd_sb16dsp_pcm(chip_sb, 1, &sb_pcm)) < 0) {
|
|---|
| 389 | snd_printk("(SB16) no enough memory??\n");
|
|---|
| 390 | snd_card_free(card);
|
|---|
| 391 | return err;
|
|---|
| 392 | }
|
|---|
| 393 |
|
|---|
| 394 | if (chip_sb->hardware != SB_HW_16) {
|
|---|
| 395 | snd_printk("(SB16) not found during probe\n");
|
|---|
| 396 | snd_card_free(card);
|
|---|
| 397 | return -ENODEV;
|
|---|
| 398 | }
|
|---|
| 399 |
|
|---|
| 400 | memcpy(&chip_wss->image[16], &snd_cmi8330_image, sizeof(snd_cmi8330_image));
|
|---|
| 401 |
|
|---|
| 402 | spin_lock_irqsave(&chip_wss->reg_lock, flags);
|
|---|
| 403 | snd_ad1848_out(chip_wss, AD1848_MISC_INFO, /* switch on MODE2 */
|
|---|
| 404 | chip_wss->image[AD1848_MISC_INFO] |= 0x40);
|
|---|
| 405 | spin_unlock_irqrestore(&chip_wss->reg_lock, flags);
|
|---|
| 406 |
|
|---|
| 407 | if ((err = snd_cmi8330_mixer(card, chip_wss)) < 0) {
|
|---|
| 408 | snd_printk("failed to create mixers\n");
|
|---|
| 409 | snd_card_free(card);
|
|---|
| 410 | return err;
|
|---|
| 411 | }
|
|---|
| 412 | spin_lock_irqsave(&chip_wss->reg_lock, flags);
|
|---|
| 413 | for (i = CMI8330_RMUX3D; i <= CMI8330_CDINGAIN; i++)
|
|---|
| 414 | snd_ad1848_out(chip_wss, i, chip_wss->image[i]);
|
|---|
| 415 | spin_unlock_irqrestore(&chip_wss->reg_lock, flags);
|
|---|
| 416 |
|
|---|
| 417 | /*
|
|---|
| 418 | * KLUDGE ALERT
|
|---|
| 419 | * disable AD1848 playback
|
|---|
| 420 | * disable SB16 capture
|
|---|
| 421 | */
|
|---|
| 422 | pcm = wss_pcm;
|
|---|
| 423 | pstr = &pcm->streams[SNDRV_PCM_STREAM_PLAYBACK];
|
|---|
| 424 | snd_magic_kfree(pstr->substream);
|
|---|
| 425 | pstr->substream = 0;
|
|---|
| 426 | pstr->substream_count = 0;
|
|---|
| 427 |
|
|---|
| 428 | pcm = sb_pcm;
|
|---|
| 429 | pstr = &pcm->streams[SNDRV_PCM_STREAM_CAPTURE];
|
|---|
| 430 | snd_magic_kfree(pstr->substream);
|
|---|
| 431 | pstr->substream = 0;
|
|---|
| 432 | pstr->substream_count = 0;
|
|---|
| 433 |
|
|---|
| 434 | strcpy(card->driver, "CMI8330/C3D");
|
|---|
| 435 | strcpy(card->shortname, "C-Media CMI8330/C3D");
|
|---|
| 436 | sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
|
|---|
| 437 | wss_pcm->name,
|
|---|
| 438 | chip_wss->port,
|
|---|
| 439 | snd_wssirq[dev],
|
|---|
| 440 | snd_wssdma[dev]);
|
|---|
| 441 |
|
|---|
| 442 | if ((err = snd_card_register(card)) < 0) {
|
|---|
| 443 | snd_card_free(card);
|
|---|
| 444 | return err;
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 | snd_cmi8330_cards[dev] = card;
|
|---|
| 448 | return 0;
|
|---|
| 449 | }
|
|---|
| 450 |
|
|---|
| 451 | static void __exit alsa_card_cmi8330_exit(void)
|
|---|
| 452 | {
|
|---|
| 453 | int i;
|
|---|
| 454 |
|
|---|
| 455 | for (i = 0; i < SNDRV_CARDS; i++)
|
|---|
| 456 | snd_card_free(snd_cmi8330_cards[i]);
|
|---|
| 457 | }
|
|---|
| 458 |
|
|---|
| 459 | #ifdef __ISAPNP__
|
|---|
| 460 | static int __init snd_cmi8330_isapnp_detect(struct isapnp_card *card,
|
|---|
| 461 | const struct isapnp_card_id *id)
|
|---|
| 462 | {
|
|---|
| 463 | static int dev = 0;
|
|---|
| 464 | int res;
|
|---|
| 465 |
|
|---|
| 466 | for ( ; dev < SNDRV_CARDS; dev++) {
|
|---|
| 467 | if (!snd_enable[dev] || !snd_isapnp[dev])
|
|---|
| 468 | continue;
|
|---|
| 469 | snd_cmi8330_isapnp_cards[dev] = card;
|
|---|
| 470 | snd_cmi8330_isapnp_id[dev] = id;
|
|---|
| 471 | res = snd_cmi8330_probe(dev);
|
|---|
| 472 | if (res < 0)
|
|---|
| 473 | return res;
|
|---|
| 474 | dev++;
|
|---|
| 475 | return 0;
|
|---|
| 476 | }
|
|---|
| 477 | return -ENODEV;
|
|---|
| 478 | }
|
|---|
| 479 | #endif /* __ISAPNP__ */
|
|---|
| 480 |
|
|---|
| 481 | static int __init alsa_card_cmi8330_init(void)
|
|---|
| 482 | {
|
|---|
| 483 | int dev, cards = 0;
|
|---|
| 484 |
|
|---|
| 485 | for (dev = 0; dev < SNDRV_CARDS; dev++) {
|
|---|
| 486 | if (!snd_enable[dev])
|
|---|
| 487 | continue;
|
|---|
| 488 | #ifdef __ISAPNP__
|
|---|
| 489 | if (snd_isapnp[dev])
|
|---|
| 490 | continue;
|
|---|
| 491 | #endif
|
|---|
| 492 | if (snd_cmi8330_probe(dev) >= 0)
|
|---|
| 493 | cards++;
|
|---|
| 494 | }
|
|---|
| 495 | #ifdef __ISAPNP__
|
|---|
| 496 | cards += isapnp_probe_cards(snd_cmi8330_pnpids, snd_cmi8330_isapnp_detect);
|
|---|
| 497 | #endif
|
|---|
| 498 |
|
|---|
| 499 | if (!cards) {
|
|---|
| 500 | #ifdef MODULE
|
|---|
| 501 | snd_printk("CMI8330 not found or device busy\n");
|
|---|
| 502 | #endif
|
|---|
| 503 | return -ENODEV;
|
|---|
| 504 | }
|
|---|
| 505 | return 0;
|
|---|
| 506 | }
|
|---|
| 507 |
|
|---|
| 508 | module_init(alsa_card_cmi8330_init)
|
|---|
| 509 | module_exit(alsa_card_cmi8330_exit)
|
|---|
| 510 |
|
|---|
| 511 | #ifndef MODULE
|
|---|
| 512 |
|
|---|
| 513 | /* format is: snd-card-cmi8330=snd_enable,snd_index,snd_id,snd_isapnp,
|
|---|
| 514 | snd_sbport,snd_sbirq,
|
|---|
| 515 | snd_sbdma8,snd_sbdma16,
|
|---|
| 516 | snd_wssport,snd_wssirq,
|
|---|
| 517 | snd_wssdma */
|
|---|
| 518 |
|
|---|
| 519 | static int __init alsa_card_cmi8330_setup(char *str)
|
|---|
| 520 | {
|
|---|
| 521 | static unsigned __initdata nr_dev = 0;
|
|---|
| 522 | int __attribute__ ((__unused__)) pnp = INT_MAX;
|
|---|
| 523 |
|
|---|
| 524 | if (nr_dev >= SNDRV_CARDS)
|
|---|
| 525 | return 0;
|
|---|
| 526 | (void)(get_option(&str,&snd_enable[nr_dev]) == 2 &&
|
|---|
| 527 | get_option(&str,&snd_index[nr_dev]) == 2 &&
|
|---|
| 528 | get_id(&str,&snd_id[nr_dev]) == 2 &&
|
|---|
| 529 | get_option(&str,&pnp) == 2 &&
|
|---|
| 530 | get_option(&str,(int *)&snd_sbport[nr_dev]) == 2 &&
|
|---|
| 531 | get_option(&str,&snd_sbirq[nr_dev]) == 2 &&
|
|---|
| 532 | get_option(&str,&snd_sbdma8[nr_dev]) == 2 &&
|
|---|
| 533 | get_option(&str,&snd_sbdma16[nr_dev]) == 2 &&
|
|---|
| 534 | get_option(&str,&snd_wssport[nr_dev]) == 2 &&
|
|---|
| 535 | get_option(&str,&snd_wssirq[nr_dev]) == 2 &&
|
|---|
| 536 | get_option(&str,&snd_wssdma[nr_dev]) == 2);
|
|---|
| 537 | #ifdef __ISAPNP__
|
|---|
| 538 | if (pnp != INT_MAX)
|
|---|
| 539 | snd_isapnp[nr_dev] = pnp;
|
|---|
| 540 | #endif
|
|---|
| 541 | nr_dev++;
|
|---|
| 542 | return 1;
|
|---|
| 543 | }
|
|---|
| 544 |
|
|---|
| 545 | __setup("snd-card-cmi8330=", alsa_card_cmi8330_setup);
|
|---|
| 546 |
|
|---|
| 547 | #endif /* ifndef MODULE */
|
|---|