2 * azt3328.c - driver for Aztech AZF3328 based soundcards (e.g. PCI168).
3 * Copyright (C) 2002, 2005 by Andreas Mohr <andi AT lisas.de>
5 * Framework borrowed from Bart Hartgers's als4000.c.
6 * Driver developed on PCI168 AP(W) version (PCI rev. 10, subsystem ID 1801),
7 * found in a Fujitsu-Siemens PC ("Cordant", aluminum case).
9 * PCI168 A(W), sub ID 1800
10 * PCI168 A/AP, sub ID 8000
11 * Please give me feedback in case you try my driver with one of these!!
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * Since Aztech does not provide any chipset documentation,
30 * even on repeated request to various addresses,
31 * and the answer that was finally given was negative
32 * (and I was stupid enough to manage to get hold of a PCI168 soundcard
33 * in the first place >:-P}),
34 * I was forced to base this driver on reverse engineering
35 * (3 weeks' worth of evenings filled with driver work).
36 * (and no, I did NOT go the easy way: to pick up a SB PCI128 for 9 Euros)
38 * The AZF3328 chip (note: AZF3328, *not* AZT3328, that's just the driver name
39 * for compatibility reasons) has the following features:
41 * - builtin AC97 conformant codec (SNR over 80dB)
42 * Note that "conformant" != "compliant"!! this chip's mixer register layout
43 * *differs* from the standard AC97 layout:
44 * they chose to not implement the headphone register (which is not a
45 * problem since it's merely optional), yet when doing this, they committed
46 * the grave sin of letting other registers follow immediately instead of
47 * keeping a headphone dummy register, thereby shifting the mixer register
48 * addresses illegally. So far unfortunately it looks like the very flexible
49 * ALSA AC97 support is still not enough to easily compensate for such a
50 * grave layout violation despite all tweaks and quirks mechanisms it offers.
51 * - builtin genuine OPL3
52 * - full duplex 16bit playback/record at independent sampling rate
53 * - MPU401 (+ legacy address support) FIXME: how to enable legacy addr??
54 * - game port (legacy address support)
55 * - built-in General DirectX timer having a 20 bits counter
56 * with 1us resolution (see below!)
57 * - I2S serial port for external DAC
58 * - supports 33MHz PCI spec 2.1, PCI power management 1.0, compliant with ACPI
59 * - supports hardware volume control
60 * - single chip low cost solution (128 pin QFP)
61 * - supports programmable Sub-vendor and Sub-system ID
62 * required for Microsoft's logo compliance (FIXME: where?)
63 * - PCI168 AP(W) card: power amplifier with 4 Watts/channel at 4 Ohms
65 * Note that this driver now is actually *better* than the Windows driver,
66 * since it additionally supports the card's 1MHz DirectX timer - just try
67 * the following snd-seq module parameters etc.:
68 * - options snd-seq seq_default_timer_class=2 seq_default_timer_sclass=0
69 * seq_default_timer_card=0 seq_client_load=1 seq_default_timer_device=0
70 * seq_default_timer_subdevice=0 seq_default_timer_resolution=1000000
71 * - "timidity -iAv -B2,8 -Os -EFreverb=0"
72 * - "pmidi -p 128:0 jazz.mid"
74 * Certain PCI versions of this card are susceptible to DMA traffic underruns
75 * in some systems (resulting in sound crackling/clicking/popping),
76 * probably because they don't have a DMA FIFO buffer or so.
77 * Overview (PCI ID/PCI subID/PCI rev.):
78 * - no DMA crackling on SiS735: 0x50DC/0x1801/16
79 * - unknown performance: 0x50DC/0x1801/10
80 * (well, it's not bad on an Athlon 1800 with now very optimized IRQ handler)
82 * Crackling happens with VIA chipsets or, in my case, an SiS735, which is
83 * supposed to be very fast and supposed to get rid of crackling much
84 * better than a VIA, yet ironically I still get crackling, like many other
85 * people with the same chipset.
87 * - plug card into a different PCI slot, preferrably one that isn't shared
88 * too much (this helps a lot, but not completely!)
89 * - get rid of PCI VGA card, use AGP instead
90 * - upgrade or downgrade BIOS
91 * - fiddle with PCI latency settings (setpci -v -s BUSID latency_timer=XX)
93 * - Disable ACPI/power management/"Auto Detect RAM/PCI Clk" in BIOS
96 * - full-duplex might *still* be problematic, not fully tested recently
99 * - test MPU401 MIDI playback etc.
100 * - add some power micro-management (disable various units of the card
101 * as long as they're unused). However this requires I/O ports which I
102 * haven't figured out yet and which thus might not even exist...
103 * The standard suspend/resume functionality could probably make use of
104 * some improvement, too...
105 * - figure out what all unknown port bits are responsible for
106 * - figure out some cleverly evil scheme to possibly make ALSA AC97 code
107 * fully accept our quite incompatible ""AC97"" mixer and thus save some
108 * code (but I'm not too optimistic that doing this is possible at all)
111 #include <sound/driver.h>
113 #include <linux/init.h>
114 #include <linux/pci.h>
115 #include <linux/delay.h>
116 #include <linux/slab.h>
117 #include <linux/gameport.h>
118 #include <linux/moduleparam.h>
119 #include <linux/dma-mapping.h>
120 #include <sound/core.h>
121 #include <sound/control.h>
122 #include <sound/pcm.h>
123 #include <sound/rawmidi.h>
124 #include <sound/mpu401.h>
125 #include <sound/opl3.h>
126 #include <sound/initval.h>
129 MODULE_AUTHOR("Andreas Mohr <andi AT lisas.de>");
130 MODULE_DESCRIPTION("Aztech AZF3328 (PCI168)");
131 MODULE_LICENSE("GPL");
132 MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
134 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
135 #define SUPPORT_JOYSTICK 1
139 #define DEBUG_CALLS 0
140 #define DEBUG_MIXER 0
141 #define DEBUG_PLAY_REC 0
143 #define DEBUG_TIMER 0
144 #define MIXER_TESTING 0
147 #define snd_azf3328_dbgmisc(format, args...) printk(KERN_ERR format, ##args)
149 #define snd_azf3328_dbgmisc(format, args...)
153 #define snd_azf3328_dbgcalls(format, args...) printk(format, ##args)
154 #define snd_azf3328_dbgcallenter() printk(KERN_ERR "--> %s\n", __FUNCTION__)
155 #define snd_azf3328_dbgcallleave() printk(KERN_ERR "<-- %s\n", __FUNCTION__)
157 #define snd_azf3328_dbgcalls(format, args...)
158 #define snd_azf3328_dbgcallenter()
159 #define snd_azf3328_dbgcallleave()
163 #define snd_azf3328_dbgmixer(format, args...) printk(format, ##args)
165 #define snd_azf3328_dbgmixer(format, args...)
169 #define snd_azf3328_dbgplay(format, args...) printk(KERN_ERR format, ##args)
171 #define snd_azf3328_dbgplay(format, args...)
175 #define snd_azf3328_dbgtimer(format, args...) printk(KERN_ERR format, ##args)
177 #define snd_azf3328_dbgtimer(format, args...)
180 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
181 module_param_array(index, int, NULL, 0444);
182 MODULE_PARM_DESC(index, "Index value for AZF3328 soundcard.");
184 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
185 module_param_array(id, charp, NULL, 0444);
186 MODULE_PARM_DESC(id, "ID string for AZF3328 soundcard.");
188 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
189 module_param_array(enable, bool, NULL, 0444);
190 MODULE_PARM_DESC(enable, "Enable AZF3328 soundcard.");
192 #ifdef SUPPORT_JOYSTICK
193 static int joystick[SNDRV_CARDS];
194 module_param_array(joystick, bool, NULL, 0444);
195 MODULE_PARM_DESC(joystick, "Enable joystick for AZF3328 soundcard.");
198 static int seqtimer_scaling = 128;
199 module_param(seqtimer_scaling, int, 0444);
200 MODULE_PARM_DESC(seqtimer_scaling, "Set 1024000Hz sequencer timer scale factor (lockup danger!). Default 128.");
203 /* often-used fields towards beginning, then grouped */
204 unsigned long codec_port;
205 unsigned long io2_port;
206 unsigned long mpu_port;
207 unsigned long synth_port;
208 unsigned long mixer_port;
212 struct snd_timer *timer;
215 struct snd_pcm_substream *playback_substream;
216 struct snd_pcm_substream *capture_substream;
217 unsigned int is_playing;
218 unsigned int is_recording;
220 struct snd_card *card;
221 struct snd_rawmidi *rmidi;
223 #ifdef SUPPORT_JOYSTICK
224 struct gameport *gameport;
231 /* register value containers for power management
232 * Note: not always full I/O range preserved (just like Win driver!) */
233 u16 saved_regs_codec [AZF_IO_SIZE_CODEC_PM / 2];
234 u16 saved_regs_io2 [AZF_IO_SIZE_IO2_PM / 2];
235 u16 saved_regs_mpu [AZF_IO_SIZE_MPU_PM / 2];
236 u16 saved_regs_synth[AZF_IO_SIZE_SYNTH_PM / 2];
237 u16 saved_regs_mixer[AZF_IO_SIZE_MIXER_PM / 2];
241 static const struct pci_device_id snd_azf3328_ids[] __devinitdata = {
242 { 0x122D, 0x50DC, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* PCI168/3328 */
243 { 0x122D, 0x80DA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* 3328 */
247 MODULE_DEVICE_TABLE(pci, snd_azf3328_ids);
250 snd_azf3328_codec_outb(const struct snd_azf3328 *chip, int reg, u8 value)
252 outb(value, chip->codec_port + reg);
256 snd_azf3328_codec_inb(const struct snd_azf3328 *chip, int reg)
258 return inb(chip->codec_port + reg);
262 snd_azf3328_codec_outw(const struct snd_azf3328 *chip, int reg, u16 value)
264 outw(value, chip->codec_port + reg);
268 snd_azf3328_codec_inw(const struct snd_azf3328 *chip, int reg)
270 return inw(chip->codec_port + reg);
274 snd_azf3328_codec_outl(const struct snd_azf3328 *chip, int reg, u32 value)
276 outl(value, chip->codec_port + reg);
280 snd_azf3328_io2_outb(const struct snd_azf3328 *chip, int reg, u8 value)
282 outb(value, chip->io2_port + reg);
286 snd_azf3328_io2_inb(const struct snd_azf3328 *chip, int reg)
288 return inb(chip->io2_port + reg);
292 snd_azf3328_mixer_outw(const struct snd_azf3328 *chip, int reg, u16 value)
294 outw(value, chip->mixer_port + reg);
298 snd_azf3328_mixer_inw(const struct snd_azf3328 *chip, int reg)
300 return inw(chip->mixer_port + reg);
304 snd_azf3328_mixer_set_mute(const struct snd_azf3328 *chip, int reg, int do_mute)
306 unsigned long portbase = chip->mixer_port + reg + 1;
307 unsigned char oldval;
309 /* the mute bit is on the *second* (i.e. right) register of a
310 * left/right channel setting */
311 oldval = inb(portbase);
316 outb(oldval, portbase);
320 snd_azf3328_mixer_write_volume_gradually(const struct snd_azf3328 *chip, int reg, unsigned char dst_vol_left, unsigned char dst_vol_right, int chan_sel, int delay)
322 unsigned long portbase = chip->mixer_port + reg;
323 unsigned char curr_vol_left = 0, curr_vol_right = 0;
324 int left_done = 0, right_done = 0;
326 snd_azf3328_dbgcallenter();
327 if (chan_sel & SET_CHAN_LEFT)
328 curr_vol_left = inb(portbase + 1);
331 if (chan_sel & SET_CHAN_RIGHT)
332 curr_vol_right = inb(portbase + 0);
336 /* take care of muting flag (0x80) contained in left channel */
337 if (curr_vol_left & 0x80)
338 dst_vol_left |= 0x80;
340 dst_vol_left &= ~0x80;
344 if (curr_vol_left > dst_vol_left)
347 if (curr_vol_left < dst_vol_left)
351 outb(curr_vol_left, portbase + 1);
354 if (curr_vol_right > dst_vol_right)
357 if (curr_vol_right < dst_vol_right)
361 /* during volume change, the right channel is crackling
362 * somewhat more than the left channel, unfortunately.
363 * This seems to be a hardware issue. */
364 outb(curr_vol_right, portbase + 0);
368 } while ((!left_done) || (!right_done));
369 snd_azf3328_dbgcallleave();
373 * general mixer element
375 struct azf3328_mixer_reg {
377 unsigned int lchan_shift, rchan_shift;
379 unsigned int invert: 1;
380 unsigned int stereo: 1;
381 unsigned int enum_c: 4;
384 #define COMPOSE_MIXER_REG(reg,lchan_shift,rchan_shift,mask,invert,stereo,enum_c) \
385 ((reg) | (lchan_shift << 8) | (rchan_shift << 12) | \
391 static void snd_azf3328_mixer_reg_decode(struct azf3328_mixer_reg *r, unsigned long val)
394 r->lchan_shift = (val >> 8) & 0x0f;
395 r->rchan_shift = (val >> 12) & 0x0f;
396 r->mask = (val >> 16) & 0xff;
397 r->invert = (val >> 24) & 1;
398 r->stereo = (val >> 25) & 1;
399 r->enum_c = (val >> 26) & 0x0f;
403 * mixer switches/volumes
406 #define AZF3328_MIXER_SWITCH(xname, reg, shift, invert) \
407 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
408 .info = snd_azf3328_info_mixer, \
409 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
410 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, 0x1, invert, 0, 0), \
413 #define AZF3328_MIXER_VOL_STEREO(xname, reg, mask, invert) \
414 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
415 .info = snd_azf3328_info_mixer, \
416 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
417 .private_value = COMPOSE_MIXER_REG(reg, 8, 0, mask, invert, 1, 0), \
420 #define AZF3328_MIXER_VOL_MONO(xname, reg, mask, is_right_chan) \
421 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
422 .info = snd_azf3328_info_mixer, \
423 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
424 .private_value = COMPOSE_MIXER_REG(reg, is_right_chan ? 0 : 8, 0, mask, 1, 0, 0), \
427 #define AZF3328_MIXER_VOL_SPECIAL(xname, reg, mask, shift, invert) \
428 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
429 .info = snd_azf3328_info_mixer, \
430 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
431 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, mask, invert, 0, 0), \
434 #define AZF3328_MIXER_ENUM(xname, reg, enum_c, shift) \
435 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
436 .info = snd_azf3328_info_mixer_enum, \
437 .get = snd_azf3328_get_mixer_enum, .put = snd_azf3328_put_mixer_enum, \
438 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, 0, 0, 0, enum_c), \
442 snd_azf3328_info_mixer(struct snd_kcontrol *kcontrol,
443 struct snd_ctl_elem_info *uinfo)
445 struct azf3328_mixer_reg reg;
447 snd_azf3328_dbgcallenter();
448 snd_azf3328_mixer_reg_decode(®, kcontrol->private_value);
449 uinfo->type = reg.mask == 1 ?
450 SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
451 uinfo->count = reg.stereo + 1;
452 uinfo->value.integer.min = 0;
453 uinfo->value.integer.max = reg.mask;
454 snd_azf3328_dbgcallleave();
459 snd_azf3328_get_mixer(struct snd_kcontrol *kcontrol,
460 struct snd_ctl_elem_value *ucontrol)
462 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
463 struct azf3328_mixer_reg reg;
464 unsigned int oreg, val;
466 snd_azf3328_dbgcallenter();
467 snd_azf3328_mixer_reg_decode(®, kcontrol->private_value);
469 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
470 val = (oreg >> reg.lchan_shift) & reg.mask;
472 val = reg.mask - val;
473 ucontrol->value.integer.value[0] = val;
475 val = (oreg >> reg.rchan_shift) & reg.mask;
477 val = reg.mask - val;
478 ucontrol->value.integer.value[1] = val;
480 snd_azf3328_dbgmixer("get: %02x is %04x -> vol %02lx|%02lx "
481 "(shift %02d|%02d, mask %02x, inv. %d, stereo %d)\n",
483 ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
484 reg.lchan_shift, reg.rchan_shift, reg.mask, reg.invert, reg.stereo);
485 snd_azf3328_dbgcallleave();
490 snd_azf3328_put_mixer(struct snd_kcontrol *kcontrol,
491 struct snd_ctl_elem_value *ucontrol)
493 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
494 struct azf3328_mixer_reg reg;
495 unsigned int oreg, nreg, val;
497 snd_azf3328_dbgcallenter();
498 snd_azf3328_mixer_reg_decode(®, kcontrol->private_value);
499 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
500 val = ucontrol->value.integer.value[0] & reg.mask;
502 val = reg.mask - val;
503 nreg = oreg & ~(reg.mask << reg.lchan_shift);
504 nreg |= (val << reg.lchan_shift);
506 val = ucontrol->value.integer.value[1] & reg.mask;
508 val = reg.mask - val;
509 nreg &= ~(reg.mask << reg.rchan_shift);
510 nreg |= (val << reg.rchan_shift);
512 if (reg.mask >= 0x07) /* it's a volume control, so better take care */
513 snd_azf3328_mixer_write_volume_gradually(
514 chip, reg.reg, nreg >> 8, nreg & 0xff,
515 /* just set both channels, doesn't matter */
516 SET_CHAN_LEFT|SET_CHAN_RIGHT,
519 snd_azf3328_mixer_outw(chip, reg.reg, nreg);
521 snd_azf3328_dbgmixer("put: %02x to %02lx|%02lx, "
522 "oreg %04x; shift %02d|%02d -> nreg %04x; after: %04x\n",
523 reg.reg, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
524 oreg, reg.lchan_shift, reg.rchan_shift,
525 nreg, snd_azf3328_mixer_inw(chip, reg.reg));
526 snd_azf3328_dbgcallleave();
527 return (nreg != oreg);
531 snd_azf3328_info_mixer_enum(struct snd_kcontrol *kcontrol,
532 struct snd_ctl_elem_info *uinfo)
534 static const char * const texts1[] = {
537 static const char * const texts2[] = {
540 static const char * const texts3[] = {
541 "Mic", "CD", "Video", "Aux",
542 "Line", "Mix", "Mix Mono", "Phone"
544 static const char * const texts4[] = {
547 struct azf3328_mixer_reg reg;
549 snd_azf3328_mixer_reg_decode(®, kcontrol->private_value);
550 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
551 uinfo->count = (reg.reg == IDX_MIXER_REC_SELECT) ? 2 : 1;
552 uinfo->value.enumerated.items = reg.enum_c;
553 if (uinfo->value.enumerated.item > reg.enum_c - 1U)
554 uinfo->value.enumerated.item = reg.enum_c - 1U;
555 if (reg.reg == IDX_MIXER_ADVCTL2) {
556 switch(reg.lchan_shift) {
557 case 8: /* modem out sel */
558 strcpy(uinfo->value.enumerated.name, texts1[uinfo->value.enumerated.item]);
560 case 9: /* mono sel source */
561 strcpy(uinfo->value.enumerated.name, texts2[uinfo->value.enumerated.item]);
563 case 15: /* PCM Out Path */
564 strcpy(uinfo->value.enumerated.name, texts4[uinfo->value.enumerated.item]);
568 strcpy(uinfo->value.enumerated.name, texts3[uinfo->value.enumerated.item]
574 snd_azf3328_get_mixer_enum(struct snd_kcontrol *kcontrol,
575 struct snd_ctl_elem_value *ucontrol)
577 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
578 struct azf3328_mixer_reg reg;
581 snd_azf3328_mixer_reg_decode(®, kcontrol->private_value);
582 val = snd_azf3328_mixer_inw(chip, reg.reg);
583 if (reg.reg == IDX_MIXER_REC_SELECT) {
584 ucontrol->value.enumerated.item[0] = (val >> 8) & (reg.enum_c - 1);
585 ucontrol->value.enumerated.item[1] = (val >> 0) & (reg.enum_c - 1);
587 ucontrol->value.enumerated.item[0] = (val >> reg.lchan_shift) & (reg.enum_c - 1);
589 snd_azf3328_dbgmixer("get_enum: %02x is %04x -> %d|%d (shift %02d, enum_c %d)\n",
590 reg.reg, val, ucontrol->value.enumerated.item[0], ucontrol->value.enumerated.item[1],
591 reg.lchan_shift, reg.enum_c);
596 snd_azf3328_put_mixer_enum(struct snd_kcontrol *kcontrol,
597 struct snd_ctl_elem_value *ucontrol)
599 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
600 struct azf3328_mixer_reg reg;
601 unsigned int oreg, nreg, val;
603 snd_azf3328_mixer_reg_decode(®, kcontrol->private_value);
604 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
606 if (reg.reg == IDX_MIXER_REC_SELECT) {
607 if (ucontrol->value.enumerated.item[0] > reg.enum_c - 1U ||
608 ucontrol->value.enumerated.item[1] > reg.enum_c - 1U)
610 val = (ucontrol->value.enumerated.item[0] << 8) |
611 (ucontrol->value.enumerated.item[1] << 0);
613 if (ucontrol->value.enumerated.item[0] > reg.enum_c - 1U)
615 val &= ~((reg.enum_c - 1) << reg.lchan_shift);
616 val |= (ucontrol->value.enumerated.item[0] << reg.lchan_shift);
618 snd_azf3328_mixer_outw(chip, reg.reg, val);
621 snd_azf3328_dbgmixer("put_enum: %02x to %04x, oreg %04x\n", reg.reg, val, oreg);
622 return (nreg != oreg);
625 static const struct snd_kcontrol_new snd_azf3328_mixer_controls[] __devinitdata = {
626 AZF3328_MIXER_SWITCH("Master Playback Switch", IDX_MIXER_PLAY_MASTER, 15, 1),
627 AZF3328_MIXER_VOL_STEREO("Master Playback Volume", IDX_MIXER_PLAY_MASTER, 0x1f, 1),
628 AZF3328_MIXER_SWITCH("Wave Playback Switch", IDX_MIXER_WAVEOUT, 15, 1),
629 AZF3328_MIXER_VOL_STEREO("Wave Playback Volume", IDX_MIXER_WAVEOUT, 0x1f, 1),
630 AZF3328_MIXER_SWITCH("Wave 3D Bypass Playback Switch", IDX_MIXER_ADVCTL2, 7, 1),
631 AZF3328_MIXER_SWITCH("FM Playback Switch", IDX_MIXER_FMSYNTH, 15, 1),
632 AZF3328_MIXER_VOL_STEREO("FM Playback Volume", IDX_MIXER_FMSYNTH, 0x1f, 1),
633 AZF3328_MIXER_SWITCH("CD Playback Switch", IDX_MIXER_CDAUDIO, 15, 1),
634 AZF3328_MIXER_VOL_STEREO("CD Playback Volume", IDX_MIXER_CDAUDIO, 0x1f, 1),
635 AZF3328_MIXER_SWITCH("Capture Switch", IDX_MIXER_REC_VOLUME, 15, 1),
636 AZF3328_MIXER_VOL_STEREO("Capture Volume", IDX_MIXER_REC_VOLUME, 0x0f, 0),
637 AZF3328_MIXER_ENUM("Capture Source", IDX_MIXER_REC_SELECT, 8, 0),
638 AZF3328_MIXER_SWITCH("Mic Playback Switch", IDX_MIXER_MIC, 15, 1),
639 AZF3328_MIXER_VOL_MONO("Mic Playback Volume", IDX_MIXER_MIC, 0x1f, 1),
640 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0),
641 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1),
642 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1),
643 AZF3328_MIXER_SWITCH("PC Speaker Playback Switch", IDX_MIXER_PCBEEP, 15, 1),
644 AZF3328_MIXER_VOL_SPECIAL("PC Speaker Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1),
645 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1),
646 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1),
647 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1),
648 AZF3328_MIXER_VOL_STEREO("Aux Playback Volume", IDX_MIXER_AUX, 0x1f, 1),
649 AZF3328_MIXER_SWITCH("Modem Playback Switch", IDX_MIXER_MODEMOUT, 15, 1),
650 AZF3328_MIXER_VOL_MONO("Modem Playback Volume", IDX_MIXER_MODEMOUT, 0x1f, 1),
651 AZF3328_MIXER_SWITCH("Modem Capture Switch", IDX_MIXER_MODEMIN, 15, 1),
652 AZF3328_MIXER_VOL_MONO("Modem Capture Volume", IDX_MIXER_MODEMIN, 0x1f, 1),
653 AZF3328_MIXER_ENUM("Mic Select", IDX_MIXER_ADVCTL2, 2, 8),
654 AZF3328_MIXER_ENUM("Mono Output Select", IDX_MIXER_ADVCTL2, 2, 9),
655 AZF3328_MIXER_ENUM("PCM", IDX_MIXER_ADVCTL2, 2, 15), /* PCM Out Path, place in front since it controls *both* 3D and Bass/Treble! */
656 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Treble", IDX_MIXER_BASSTREBLE, 0x07, 1, 0),
657 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Bass", IDX_MIXER_BASSTREBLE, 0x07, 9, 0),
658 AZF3328_MIXER_SWITCH("3D Control - Switch", IDX_MIXER_ADVCTL2, 13, 0),
659 AZF3328_MIXER_VOL_SPECIAL("3D Control - Width", IDX_MIXER_ADVCTL1, 0x07, 1, 0), /* "3D Width" */
660 AZF3328_MIXER_VOL_SPECIAL("3D Control - Depth", IDX_MIXER_ADVCTL1, 0x03, 8, 0), /* "Hifi 3D" */
662 AZF3328_MIXER_SWITCH("0", IDX_MIXER_ADVCTL2, 0, 0),
663 AZF3328_MIXER_SWITCH("1", IDX_MIXER_ADVCTL2, 1, 0),
664 AZF3328_MIXER_SWITCH("2", IDX_MIXER_ADVCTL2, 2, 0),
665 AZF3328_MIXER_SWITCH("3", IDX_MIXER_ADVCTL2, 3, 0),
666 AZF3328_MIXER_SWITCH("4", IDX_MIXER_ADVCTL2, 4, 0),
667 AZF3328_MIXER_SWITCH("5", IDX_MIXER_ADVCTL2, 5, 0),
668 AZF3328_MIXER_SWITCH("6", IDX_MIXER_ADVCTL2, 6, 0),
669 AZF3328_MIXER_SWITCH("7", IDX_MIXER_ADVCTL2, 7, 0),
670 AZF3328_MIXER_SWITCH("8", IDX_MIXER_ADVCTL2, 8, 0),
671 AZF3328_MIXER_SWITCH("9", IDX_MIXER_ADVCTL2, 9, 0),
672 AZF3328_MIXER_SWITCH("10", IDX_MIXER_ADVCTL2, 10, 0),
673 AZF3328_MIXER_SWITCH("11", IDX_MIXER_ADVCTL2, 11, 0),
674 AZF3328_MIXER_SWITCH("12", IDX_MIXER_ADVCTL2, 12, 0),
675 AZF3328_MIXER_SWITCH("13", IDX_MIXER_ADVCTL2, 13, 0),
676 AZF3328_MIXER_SWITCH("14", IDX_MIXER_ADVCTL2, 14, 0),
677 AZF3328_MIXER_SWITCH("15", IDX_MIXER_ADVCTL2, 15, 0),
681 static const u16 __devinitdata snd_azf3328_init_values[][2] = {
682 { IDX_MIXER_PLAY_MASTER, MIXER_MUTE_MASK|0x1f1f },
683 { IDX_MIXER_MODEMOUT, MIXER_MUTE_MASK|0x1f1f },
684 { IDX_MIXER_BASSTREBLE, 0x0000 },
685 { IDX_MIXER_PCBEEP, MIXER_MUTE_MASK|0x1f1f },
686 { IDX_MIXER_MODEMIN, MIXER_MUTE_MASK|0x1f1f },
687 { IDX_MIXER_MIC, MIXER_MUTE_MASK|0x001f },
688 { IDX_MIXER_LINEIN, MIXER_MUTE_MASK|0x1f1f },
689 { IDX_MIXER_CDAUDIO, MIXER_MUTE_MASK|0x1f1f },
690 { IDX_MIXER_VIDEO, MIXER_MUTE_MASK|0x1f1f },
691 { IDX_MIXER_AUX, MIXER_MUTE_MASK|0x1f1f },
692 { IDX_MIXER_WAVEOUT, MIXER_MUTE_MASK|0x1f1f },
693 { IDX_MIXER_FMSYNTH, MIXER_MUTE_MASK|0x1f1f },
694 { IDX_MIXER_REC_VOLUME, MIXER_MUTE_MASK|0x0707 },
698 snd_azf3328_mixer_new(struct snd_azf3328 *chip)
700 struct snd_card *card;
701 const struct snd_kcontrol_new *sw;
705 snd_azf3328_dbgcallenter();
706 snd_assert(chip != NULL && chip->card != NULL, return -EINVAL);
711 snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
713 /* mute and zero volume channels */
714 for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_init_values); idx++) {
715 snd_azf3328_mixer_outw(chip,
716 snd_azf3328_init_values[idx][0],
717 snd_azf3328_init_values[idx][1]);
720 /* add mixer controls */
721 sw = snd_azf3328_mixer_controls;
722 for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_mixer_controls); idx++, sw++) {
723 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(sw, chip))) < 0)
726 snd_component_add(card, "AZF3328 mixer");
727 strcpy(card->mixername, "AZF3328 mixer");
729 snd_azf3328_dbgcallleave();
734 snd_azf3328_hw_params(struct snd_pcm_substream *substream,
735 struct snd_pcm_hw_params *hw_params)
738 snd_azf3328_dbgcallenter();
739 res = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
740 snd_azf3328_dbgcallleave();
745 snd_azf3328_hw_free(struct snd_pcm_substream *substream)
747 snd_azf3328_dbgcallenter();
748 snd_pcm_lib_free_pages(substream);
749 snd_azf3328_dbgcallleave();
754 snd_azf3328_setfmt(struct snd_azf3328 *chip,
756 unsigned int bitrate,
757 unsigned int format_width,
758 unsigned int channels
764 snd_azf3328_dbgcallenter();
766 case 4000: val |= SOUNDFORMAT_FREQ_SUSPECTED_4000; break;
767 case 4800: val |= SOUNDFORMAT_FREQ_SUSPECTED_4800; break;
768 case 5512: val |= SOUNDFORMAT_FREQ_5510; break; /* the AZF3328 names it "5510" for some strange reason */
769 case 6620: val |= SOUNDFORMAT_FREQ_6620; break;
770 case 8000: val |= SOUNDFORMAT_FREQ_8000; break;
771 case 9600: val |= SOUNDFORMAT_FREQ_9600; break;
772 case 11025: val |= SOUNDFORMAT_FREQ_11025; break;
773 case 13240: val |= SOUNDFORMAT_FREQ_SUSPECTED_13240; break;
774 case 16000: val |= SOUNDFORMAT_FREQ_16000; break;
775 case 22050: val |= SOUNDFORMAT_FREQ_22050; break;
776 case 32000: val |= SOUNDFORMAT_FREQ_32000; break;
777 case 44100: val |= SOUNDFORMAT_FREQ_44100; break;
778 case 48000: val |= SOUNDFORMAT_FREQ_48000; break;
779 case 66200: val |= SOUNDFORMAT_FREQ_SUSPECTED_66200; break;
781 snd_printk(KERN_WARNING "unknown bitrate %d, assuming 44.1kHz!\n", bitrate);
782 val |= SOUNDFORMAT_FREQ_44100;
785 /* val = 0xff07; 3m27.993s (65301Hz; -> 64000Hz???) hmm, 66120, 65967, 66123 */
786 /* val = 0xff09; 17m15.098s (13123,478Hz; -> 12000Hz???) hmm, 13237.2Hz? */
787 /* val = 0xff0a; 47m30.599s (4764,891Hz; -> 4800Hz???) yup, 4803Hz */
788 /* val = 0xff0c; 57m0.510s (4010,263Hz; -> 4000Hz???) yup, 4003Hz */
789 /* val = 0xff05; 5m11.556s (... -> 44100Hz) */
790 /* val = 0xff03; 10m21.529s (21872,463Hz; -> 22050Hz???) */
791 /* val = 0xff0f; 20m41.883s (10937,993Hz; -> 11025Hz???) */
792 /* val = 0xff0d; 41m23.135s (5523,600Hz; -> 5512Hz???) */
793 /* val = 0xff0e; 28m30.777s (8017Hz; -> 8000Hz???) */
796 val |= SOUNDFORMAT_FLAG_2CHANNELS;
798 if (format_width == 16)
799 val |= SOUNDFORMAT_FLAG_16BIT;
801 spin_lock_irqsave(&chip->reg_lock, flags);
803 /* set bitrate/format */
804 snd_azf3328_codec_outw(chip, reg, val);
806 /* changing the bitrate/format settings switches off the
807 * audio output with an annoying click in case of 8/16bit format change
808 * (maybe shutting down DAC/ADC?), thus immediately
809 * do some tweaking to reenable it and get rid of the clicking
810 * (FIXME: yes, it works, but what exactly am I doing here?? :)
811 * FIXME: does this have some side effects for full-duplex
812 * or other dramatic side effects? */
813 if (reg == IDX_IO_PLAY_SOUNDFORMAT) /* only do it for playback */
814 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
815 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS) |
816 DMA_PLAY_SOMETHING1 |
817 DMA_PLAY_SOMETHING2 |
818 SOMETHING_ALMOST_ALWAYS_SET |
819 DMA_EPILOGUE_SOMETHING |
823 spin_unlock_irqrestore(&chip->reg_lock, flags);
824 snd_azf3328_dbgcallleave();
828 snd_azf3328_setdmaa(struct snd_azf3328 *chip,
829 long unsigned int addr,
834 unsigned long flags, portbase;
835 unsigned int is_running;
837 snd_azf3328_dbgcallenter();
839 /* access capture registers, i.e. skip playback reg section */
840 portbase = chip->codec_port + 0x20;
841 is_running = chip->is_recording;
843 /* access the playback register section */
844 portbase = chip->codec_port + 0x00;
845 is_running = chip->is_playing;
848 /* AZF3328 uses a two buffer pointer DMA playback approach */
850 unsigned long addr_area2;
851 unsigned long count_areas, count_tmp; /* width 32bit -- overflow!! */
852 count_areas = size/2;
853 addr_area2 = addr+count_areas;
854 count_areas--; /* max. index */
855 snd_azf3328_dbgplay("set DMA: buf1 %08lx[%lu], buf2 %08lx[%lu]\n", addr, count_areas, addr_area2, count_areas);
857 /* build combined I/O buffer length word */
858 count_tmp = count_areas;
859 count_areas |= (count_tmp << 16);
860 spin_lock_irqsave(&chip->reg_lock, flags);
861 outl(addr, portbase + IDX_IO_PLAY_DMA_START_1);
862 outl(addr_area2, portbase + IDX_IO_PLAY_DMA_START_2);
863 outl(count_areas, portbase + IDX_IO_PLAY_DMA_LEN_1);
864 spin_unlock_irqrestore(&chip->reg_lock, flags);
866 snd_azf3328_dbgcallleave();
870 snd_azf3328_playback_prepare(struct snd_pcm_substream *substream)
873 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
874 struct snd_pcm_runtime *runtime = substream->runtime;
875 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
876 unsigned int count = snd_pcm_lib_period_bytes(substream);
879 snd_azf3328_dbgcallenter();
881 snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT,
883 snd_pcm_format_width(runtime->format),
885 snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, 0);
887 snd_azf3328_dbgcallleave();
892 snd_azf3328_capture_prepare(struct snd_pcm_substream *substream)
895 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
896 struct snd_pcm_runtime *runtime = substream->runtime;
897 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
898 unsigned int count = snd_pcm_lib_period_bytes(substream);
901 snd_azf3328_dbgcallenter();
903 snd_azf3328_setfmt(chip, IDX_IO_REC_SOUNDFORMAT,
905 snd_pcm_format_width(runtime->format),
907 snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, 1);
909 snd_azf3328_dbgcallleave();
914 snd_azf3328_playback_trigger(struct snd_pcm_substream *substream, int cmd)
916 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
917 struct snd_pcm_runtime *runtime = substream->runtime;
919 unsigned int status1;
921 snd_azf3328_dbgcalls("snd_azf3328_playback_trigger cmd %d\n", cmd);
924 case SNDRV_PCM_TRIGGER_START:
925 snd_azf3328_dbgplay("START PLAYBACK\n");
928 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
930 snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT,
932 snd_pcm_format_width(runtime->format),
935 spin_lock(&chip->reg_lock);
937 status1 = snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS);
938 status1 &= ~DMA_RESUME;
939 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
941 /* FIXME: clear interrupts or what??? */
942 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_IRQTYPE, 0xffff);
943 spin_unlock(&chip->reg_lock);
945 snd_azf3328_setdmaa(chip, runtime->dma_addr,
946 snd_pcm_lib_period_bytes(substream),
947 snd_pcm_lib_buffer_bytes(substream),
950 spin_lock(&chip->reg_lock);
952 /* FIXME: enable playback/recording??? */
953 status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2;
954 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
956 /* start playback again */
957 /* FIXME: what is this value (0x0010)??? */
958 status1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING;
959 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
961 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
963 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
964 DMA_PLAY_SOMETHING1);
965 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
966 DMA_PLAY_SOMETHING1 |
967 DMA_PLAY_SOMETHING2);
968 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
970 SOMETHING_ALMOST_ALWAYS_SET |
971 DMA_EPILOGUE_SOMETHING |
974 spin_unlock(&chip->reg_lock);
976 /* now unmute WaveOut */
977 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0);
979 chip->is_playing = 1;
980 snd_azf3328_dbgplay("STARTED PLAYBACK\n");
982 case SNDRV_PCM_TRIGGER_RESUME:
983 snd_azf3328_dbgplay("RESUME PLAYBACK\n");
984 /* resume playback if we were active */
985 if (chip->is_playing)
986 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
987 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS) | DMA_RESUME);
989 case SNDRV_PCM_TRIGGER_STOP:
990 snd_azf3328_dbgplay("STOP PLAYBACK\n");
993 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
995 spin_lock(&chip->reg_lock);
997 status1 = snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS);
999 status1 &= ~DMA_RESUME;
1000 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
1002 /* hmm, is this really required? we're resetting the same bit
1003 * immediately thereafter... */
1004 status1 |= DMA_PLAY_SOMETHING1;
1005 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
1007 status1 &= ~DMA_PLAY_SOMETHING1;
1008 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
1009 spin_unlock(&chip->reg_lock);
1011 /* now unmute WaveOut */
1012 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0);
1013 chip->is_playing = 0;
1014 snd_azf3328_dbgplay("STOPPED PLAYBACK\n");
1016 case SNDRV_PCM_TRIGGER_SUSPEND:
1017 snd_azf3328_dbgplay("SUSPEND PLAYBACK\n");
1018 /* make sure playback is stopped */
1019 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
1020 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS) & ~DMA_RESUME);
1022 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1023 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n");
1025 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1026 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n");
1029 printk(KERN_ERR "FIXME: unknown trigger mode!\n");
1033 snd_azf3328_dbgcallleave();
1037 /* this is just analogous to playback; I'm not quite sure whether recording
1038 * should actually be triggered like that */
1040 snd_azf3328_capture_trigger(struct snd_pcm_substream *substream, int cmd)
1042 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1043 struct snd_pcm_runtime *runtime = substream->runtime;
1045 unsigned int status1;
1047 snd_azf3328_dbgcalls("snd_azf3328_capture_trigger cmd %d\n", cmd);
1050 case SNDRV_PCM_TRIGGER_START:
1052 snd_azf3328_dbgplay("START CAPTURE\n");
1054 snd_azf3328_setfmt(chip, IDX_IO_REC_SOUNDFORMAT,
1056 snd_pcm_format_width(runtime->format),
1059 spin_lock(&chip->reg_lock);
1060 /* stop recording */
1061 status1 = snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS);
1062 status1 &= ~DMA_RESUME;
1063 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
1065 /* FIXME: clear interrupts or what??? */
1066 snd_azf3328_codec_outw(chip, IDX_IO_REC_IRQTYPE, 0xffff);
1067 spin_unlock(&chip->reg_lock);
1069 snd_azf3328_setdmaa(chip, runtime->dma_addr,
1070 snd_pcm_lib_period_bytes(substream),
1071 snd_pcm_lib_buffer_bytes(substream),
1074 spin_lock(&chip->reg_lock);
1076 /* FIXME: enable playback/recording??? */
1077 status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2;
1078 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
1080 /* start capture again */
1081 /* FIXME: what is this value (0x0010)??? */
1082 status1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING;
1083 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
1085 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1087 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1088 DMA_PLAY_SOMETHING1);
1089 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1090 DMA_PLAY_SOMETHING1 |
1091 DMA_PLAY_SOMETHING2);
1092 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1094 SOMETHING_ALMOST_ALWAYS_SET |
1095 DMA_EPILOGUE_SOMETHING |
1096 DMA_SOMETHING_ELSE);
1098 spin_unlock(&chip->reg_lock);
1100 chip->is_recording = 1;
1101 snd_azf3328_dbgplay("STARTED CAPTURE\n");
1103 case SNDRV_PCM_TRIGGER_RESUME:
1104 snd_azf3328_dbgplay("RESUME CAPTURE\n");
1105 /* resume recording if we were active */
1106 if (chip->is_recording)
1107 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1108 snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS) | DMA_RESUME);
1110 case SNDRV_PCM_TRIGGER_STOP:
1111 snd_azf3328_dbgplay("STOP CAPTURE\n");
1113 spin_lock(&chip->reg_lock);
1114 /* stop recording */
1115 status1 = snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS);
1117 status1 &= ~DMA_RESUME;
1118 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
1120 status1 |= DMA_PLAY_SOMETHING1;
1121 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
1123 status1 &= ~DMA_PLAY_SOMETHING1;
1124 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
1125 spin_unlock(&chip->reg_lock);
1127 chip->is_recording = 0;
1128 snd_azf3328_dbgplay("STOPPED CAPTURE\n");
1130 case SNDRV_PCM_TRIGGER_SUSPEND:
1131 snd_azf3328_dbgplay("SUSPEND CAPTURE\n");
1132 /* make sure recording is stopped */
1133 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1134 snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS) & ~DMA_RESUME);
1136 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1137 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n");
1139 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1140 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n");
1143 printk(KERN_ERR "FIXME: unknown trigger mode!\n");
1147 snd_azf3328_dbgcallleave();
1151 static snd_pcm_uframes_t
1152 snd_azf3328_playback_pointer(struct snd_pcm_substream *substream)
1154 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1155 unsigned long bufptr, result;
1156 snd_pcm_uframes_t frmres;
1158 #ifdef QUERY_HARDWARE
1159 bufptr = inl(chip->codec_port+IDX_IO_PLAY_DMA_START_1);
1161 bufptr = substream->runtime->dma_addr;
1163 result = inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS);
1165 /* calculate offset */
1167 frmres = bytes_to_frames( substream->runtime, result);
1168 snd_azf3328_dbgplay("PLAY @ 0x%8lx, frames %8ld\n", result, frmres);
1172 static snd_pcm_uframes_t
1173 snd_azf3328_capture_pointer(struct snd_pcm_substream *substream)
1175 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1176 unsigned long bufptr, result;
1177 snd_pcm_uframes_t frmres;
1179 #ifdef QUERY_HARDWARE
1180 bufptr = inl(chip->codec_port+IDX_IO_REC_DMA_START_1);
1182 bufptr = substream->runtime->dma_addr;
1184 result = inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS);
1186 /* calculate offset */
1188 frmres = bytes_to_frames( substream->runtime, result);
1189 snd_azf3328_dbgplay("REC @ 0x%8lx, frames %8ld\n", result, frmres);
1194 snd_azf3328_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1196 struct snd_azf3328 *chip = dev_id;
1198 static unsigned long irq_count;
1200 status = snd_azf3328_codec_inb(chip, IDX_IO_IRQSTATUS);
1202 /* fast path out, to ease interrupt sharing */
1203 if (!(status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_MPU401|IRQ_TIMER)))
1204 return IRQ_NONE; /* must be interrupt for another device */
1206 snd_azf3328_dbgplay("Interrupt %ld!\nIDX_IO_PLAY_FLAGS %04x, IDX_IO_PLAY_IRQTYPE %04x, IDX_IO_IRQSTATUS %04x\n",
1208 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS),
1209 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_IRQTYPE),
1212 if (status & IRQ_TIMER) {
1213 /* snd_azf3328_dbgplay("timer %ld\n", inl(chip->codec_port+IDX_IO_TIMER_VALUE) & TIMER_VALUE_MASK); */
1215 snd_timer_interrupt(chip->timer, chip->timer->sticks);
1217 spin_lock(&chip->reg_lock);
1218 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x07);
1219 spin_unlock(&chip->reg_lock);
1220 snd_azf3328_dbgplay("azt3328: timer IRQ\n");
1222 if (status & IRQ_PLAYBACK) {
1223 spin_lock(&chip->reg_lock);
1224 which = snd_azf3328_codec_inb(chip, IDX_IO_PLAY_IRQTYPE);
1225 /* ack all IRQ types immediately */
1226 snd_azf3328_codec_outb(chip, IDX_IO_PLAY_IRQTYPE, which);
1227 spin_unlock(&chip->reg_lock);
1229 if (chip->pcm && chip->playback_substream) {
1230 snd_pcm_period_elapsed(chip->playback_substream);
1231 snd_azf3328_dbgplay("PLAY period done (#%x), @ %x\n",
1233 inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS));
1235 snd_azf3328_dbgplay("azt3328: ouch, irq handler problem!\n");
1236 if (which & IRQ_PLAY_SOMETHING)
1237 snd_azf3328_dbgplay("azt3328: unknown play IRQ type occurred, please report!\n");
1239 if (status & IRQ_RECORDING) {
1240 spin_lock(&chip->reg_lock);
1241 which = snd_azf3328_codec_inb(chip, IDX_IO_REC_IRQTYPE);
1242 /* ack all IRQ types immediately */
1243 snd_azf3328_codec_outb(chip, IDX_IO_REC_IRQTYPE, which);
1244 spin_unlock(&chip->reg_lock);
1246 if (chip->pcm && chip->capture_substream) {
1247 snd_pcm_period_elapsed(chip->capture_substream);
1248 snd_azf3328_dbgplay("REC period done (#%x), @ %x\n",
1250 inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS));
1252 snd_azf3328_dbgplay("azt3328: ouch, irq handler problem!\n");
1253 if (which & IRQ_REC_SOMETHING)
1254 snd_azf3328_dbgplay("azt3328: unknown rec IRQ type occurred, please report!\n");
1256 /* MPU401 has less critical IRQ requirements
1257 * than timer and playback/recording, right? */
1258 if (status & IRQ_MPU401) {
1259 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
1261 /* hmm, do we have to ack the IRQ here somehow?
1262 * If so, then I don't know how... */
1263 snd_azf3328_dbgplay("azt3328: MPU401 IRQ\n");
1269 /*****************************************************************/
1271 static const struct snd_pcm_hardware snd_azf3328_playback =
1273 /* FIXME!! Correct? */
1274 .info = SNDRV_PCM_INFO_MMAP |
1275 SNDRV_PCM_INFO_INTERLEAVED |
1276 SNDRV_PCM_INFO_MMAP_VALID,
1277 .formats = SNDRV_PCM_FMTBIT_S8 |
1278 SNDRV_PCM_FMTBIT_U8 |
1279 SNDRV_PCM_FMTBIT_S16_LE |
1280 SNDRV_PCM_FMTBIT_U16_LE,
1281 .rates = SNDRV_PCM_RATE_5512 |
1282 SNDRV_PCM_RATE_8000_48000 |
1283 SNDRV_PCM_RATE_KNOT,
1288 .buffer_bytes_max = 65536,
1289 .period_bytes_min = 64,
1290 .period_bytes_max = 65536,
1292 .periods_max = 1024,
1293 /* FIXME: maybe that card actually has a FIFO?
1294 * Hmm, it seems newer revisions do have one, but we still don't know
1299 static const struct snd_pcm_hardware snd_azf3328_capture =
1302 .info = SNDRV_PCM_INFO_MMAP |
1303 SNDRV_PCM_INFO_INTERLEAVED |
1304 SNDRV_PCM_INFO_MMAP_VALID,
1305 .formats = SNDRV_PCM_FMTBIT_S8 |
1306 SNDRV_PCM_FMTBIT_U8 |
1307 SNDRV_PCM_FMTBIT_S16_LE |
1308 SNDRV_PCM_FMTBIT_U16_LE,
1309 .rates = SNDRV_PCM_RATE_5512 |
1310 SNDRV_PCM_RATE_8000_48000 |
1311 SNDRV_PCM_RATE_KNOT,
1316 .buffer_bytes_max = 65536,
1317 .period_bytes_min = 64,
1318 .period_bytes_max = 65536,
1320 .periods_max = 1024,
1325 static unsigned int snd_azf3328_fixed_rates[] = {
1326 4000, 4800, 5512, 6620, 8000, 9600, 11025, 13240, 16000, 22050, 32000,
1327 44100, 48000, 66200 };
1328 static struct snd_pcm_hw_constraint_list snd_azf3328_hw_constraints_rates = {
1329 .count = ARRAY_SIZE(snd_azf3328_fixed_rates),
1330 .list = snd_azf3328_fixed_rates,
1334 /*****************************************************************/
1337 snd_azf3328_playback_open(struct snd_pcm_substream *substream)
1339 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1340 struct snd_pcm_runtime *runtime = substream->runtime;
1342 snd_azf3328_dbgcallenter();
1343 chip->playback_substream = substream;
1344 runtime->hw = snd_azf3328_playback;
1345 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1346 &snd_azf3328_hw_constraints_rates);
1347 snd_azf3328_dbgcallleave();
1352 snd_azf3328_capture_open(struct snd_pcm_substream *substream)
1354 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1355 struct snd_pcm_runtime *runtime = substream->runtime;
1357 snd_azf3328_dbgcallenter();
1358 chip->capture_substream = substream;
1359 runtime->hw = snd_azf3328_capture;
1360 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1361 &snd_azf3328_hw_constraints_rates);
1362 snd_azf3328_dbgcallleave();
1367 snd_azf3328_playback_close(struct snd_pcm_substream *substream)
1369 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1371 snd_azf3328_dbgcallenter();
1373 chip->playback_substream = NULL;
1374 snd_azf3328_dbgcallleave();
1379 snd_azf3328_capture_close(struct snd_pcm_substream *substream)
1381 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1383 snd_azf3328_dbgcallenter();
1384 chip->capture_substream = NULL;
1385 snd_azf3328_dbgcallleave();
1389 /******************************************************************/
1391 static struct snd_pcm_ops snd_azf3328_playback_ops = {
1392 .open = snd_azf3328_playback_open,
1393 .close = snd_azf3328_playback_close,
1394 .ioctl = snd_pcm_lib_ioctl,
1395 .hw_params = snd_azf3328_hw_params,
1396 .hw_free = snd_azf3328_hw_free,
1397 .prepare = snd_azf3328_playback_prepare,
1398 .trigger = snd_azf3328_playback_trigger,
1399 .pointer = snd_azf3328_playback_pointer
1402 static struct snd_pcm_ops snd_azf3328_capture_ops = {
1403 .open = snd_azf3328_capture_open,
1404 .close = snd_azf3328_capture_close,
1405 .ioctl = snd_pcm_lib_ioctl,
1406 .hw_params = snd_azf3328_hw_params,
1407 .hw_free = snd_azf3328_hw_free,
1408 .prepare = snd_azf3328_capture_prepare,
1409 .trigger = snd_azf3328_capture_trigger,
1410 .pointer = snd_azf3328_capture_pointer
1413 static int __devinit
1414 snd_azf3328_pcm(struct snd_azf3328 *chip, int device)
1416 struct snd_pcm *pcm;
1419 snd_azf3328_dbgcallenter();
1420 if ((err = snd_pcm_new(chip->card, "AZF3328 DSP", device, 1, 1, &pcm)) < 0)
1422 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_azf3328_playback_ops);
1423 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_azf3328_capture_ops);
1425 pcm->private_data = chip;
1426 pcm->info_flags = 0;
1427 strcpy(pcm->name, chip->card->shortname);
1430 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1431 snd_dma_pci_data(chip->pci), 64*1024, 64*1024);
1433 snd_azf3328_dbgcallleave();
1437 /******************************************************************/
1439 #ifdef SUPPORT_JOYSTICK
1440 static int __devinit
1441 snd_azf3328_config_joystick(struct snd_azf3328 *chip, int dev)
1443 struct gameport *gp;
1449 if (!(r = request_region(0x200, 8, "AZF3328 gameport"))) {
1450 printk(KERN_WARNING "azt3328: cannot reserve joystick ports\n");
1454 chip->gameport = gp = gameport_allocate_port();
1456 printk(KERN_ERR "azt3328: cannot allocate memory for gameport\n");
1457 release_and_free_resource(r);
1461 gameport_set_name(gp, "AZF3328 Gameport");
1462 gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
1463 gameport_set_dev_parent(gp, &chip->pci->dev);
1465 gameport_set_port_data(gp, r);
1467 snd_azf3328_io2_outb(chip, IDX_IO2_LEGACY_ADDR,
1468 snd_azf3328_io2_inb(chip, IDX_IO2_LEGACY_ADDR) | LEGACY_JOY);
1470 gameport_register_port(chip->gameport);
1476 snd_azf3328_free_joystick(struct snd_azf3328 *chip)
1478 if (chip->gameport) {
1479 struct resource *r = gameport_get_port_data(chip->gameport);
1481 gameport_unregister_port(chip->gameport);
1482 chip->gameport = NULL;
1483 /* disable gameport */
1484 snd_azf3328_io2_outb(chip, IDX_IO2_LEGACY_ADDR,
1485 snd_azf3328_io2_inb(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY);
1486 release_and_free_resource(r);
1491 snd_azf3328_config_joystick(struct snd_azf3328 *chip, int dev) { return -ENOSYS; }
1493 snd_azf3328_free_joystick(struct snd_azf3328 *chip) { }
1496 /******************************************************************/
1499 snd_azf3328_free(struct snd_azf3328 *chip)
1504 /* reset (close) mixer */
1505 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1); /* first mute master volume */
1506 snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
1508 /* interrupt setup - mask everything (FIXME!) */
1509 /* well, at least we know how to disable the timer IRQ */
1510 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00);
1512 synchronize_irq(chip->irq);
1514 snd_azf3328_free_joystick(chip);
1516 free_irq(chip->irq, (void *)chip);
1517 pci_release_regions(chip->pci);
1518 pci_disable_device(chip->pci);
1525 snd_azf3328_dev_free(struct snd_device *device)
1527 struct snd_azf3328 *chip = device->device_data;
1528 return snd_azf3328_free(chip);
1531 /******************************************************************/
1533 /*** NOTE: the physical timer resolution actually is 1024000 ticks per second,
1534 *** but announcing those attributes to user-space would make programs
1535 *** configure the timer to a 1 tick value, resulting in an absolutely fatal
1536 *** timer IRQ storm.
1537 *** Thus I chose to announce a down-scaled virtual timer to the outside and
1538 *** calculate real timer countdown values internally.
1539 *** (the scale factor can be set via module parameter "seqtimer_scaling").
1543 snd_azf3328_timer_start(struct snd_timer *timer)
1545 struct snd_azf3328 *chip;
1546 unsigned long flags;
1549 snd_azf3328_dbgcallenter();
1550 chip = snd_timer_chip(timer);
1551 delay = ((timer->sticks * seqtimer_scaling) - 1) & TIMER_VALUE_MASK;
1553 /* uhoh, that's not good, since user-space won't know about
1555 * (we need to do it to avoid a lockup, though) */
1557 snd_azf3328_dbgtimer("delay was too low (%d)!\n", delay);
1558 delay = 49; /* minimum time is 49 ticks */
1560 snd_azf3328_dbgtimer("setting timer countdown value %d, add COUNTDOWN|IRQ\n", delay);
1561 delay |= TIMER_ENABLE_COUNTDOWN | TIMER_ENABLE_IRQ;
1562 spin_lock_irqsave(&chip->reg_lock, flags);
1563 snd_azf3328_codec_outl(chip, IDX_IO_TIMER_VALUE, delay);
1564 spin_unlock_irqrestore(&chip->reg_lock, flags);
1565 snd_azf3328_dbgcallleave();
1570 snd_azf3328_timer_stop(struct snd_timer *timer)
1572 struct snd_azf3328 *chip;
1573 unsigned long flags;
1575 snd_azf3328_dbgcallenter();
1576 chip = snd_timer_chip(timer);
1577 spin_lock_irqsave(&chip->reg_lock, flags);
1578 /* disable timer countdown and interrupt */
1579 /* FIXME: should we write TIMER_ACK_IRQ here? */
1580 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0);
1581 spin_unlock_irqrestore(&chip->reg_lock, flags);
1582 snd_azf3328_dbgcallleave();
1588 snd_azf3328_timer_precise_resolution(struct snd_timer *timer,
1589 unsigned long *num, unsigned long *den)
1591 snd_azf3328_dbgcallenter();
1593 *den = 1024000 / seqtimer_scaling;
1594 snd_azf3328_dbgcallleave();
1598 static struct snd_timer_hardware snd_azf3328_timer_hw = {
1599 .flags = SNDRV_TIMER_HW_AUTO,
1600 .resolution = 977, /* 1000000/1024000 = 0.9765625us */
1601 .ticks = 1024000, /* max tick count, defined by the value register; actually it's not 1024000, but 1048576, but we don't care */
1602 .start = snd_azf3328_timer_start,
1603 .stop = snd_azf3328_timer_stop,
1604 .precise_resolution = snd_azf3328_timer_precise_resolution,
1607 static int __devinit
1608 snd_azf3328_timer(struct snd_azf3328 *chip, int device)
1610 struct snd_timer *timer = NULL;
1611 struct snd_timer_id tid;
1614 snd_azf3328_dbgcallenter();
1615 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
1616 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
1617 tid.card = chip->card->number;
1618 tid.device = device;
1621 snd_azf3328_timer_hw.resolution *= seqtimer_scaling;
1622 snd_azf3328_timer_hw.ticks /= seqtimer_scaling;
1623 if ((err = snd_timer_new(chip->card, "AZF3328", &tid, &timer)) < 0) {
1627 strcpy(timer->name, "AZF3328 timer");
1628 timer->private_data = chip;
1629 timer->hw = snd_azf3328_timer_hw;
1631 chip->timer = timer;
1636 snd_azf3328_dbgcallleave();
1640 /******************************************************************/
1643 /* check whether a bit can be modified */
1645 snd_azf3328_test_bit(unsigned int reg, int bit)
1647 unsigned char val, valoff, valon;
1651 outb(val & ~(1 << bit), reg);
1654 outb(val|(1 << bit), reg);
1659 printk(KERN_ERR "reg %04x bit %d: %02x %02x %02x\n", reg, bit, val, valoff, valon);
1664 snd_azf3328_debug_show_ports(const struct snd_azf3328 *chip)
1669 snd_azf3328_dbgmisc("codec_port 0x%lx, io2_port 0x%lx, mpu_port 0x%lx, synth_port 0x%lx, mixer_port 0x%lx, irq %d\n", chip->codec_port, chip->io2_port, chip->mpu_port, chip->synth_port, chip->mixer_port, chip->irq);
1671 snd_azf3328_dbgmisc("io2 %02x %02x %02x %02x %02x %02x\n", snd_azf3328_io2_inb(chip, 0), snd_azf3328_io2_inb(chip, 1), snd_azf3328_io2_inb(chip, 2), snd_azf3328_io2_inb(chip, 3), snd_azf3328_io2_inb(chip, 4), snd_azf3328_io2_inb(chip, 5));
1673 for (tmp=0; tmp <= 0x01; tmp += 1)
1674 snd_azf3328_dbgmisc("0x%02x: opl 0x%04x, mpu300 0x%04x, mpu310 0x%04x, mpu320 0x%04x, mpu330 0x%04x\n", tmp, inb(0x388 + tmp), inb(0x300 + tmp), inb(0x310 + tmp), inb(0x320 + tmp), inb(0x330 + tmp));
1676 for (tmp = 0; tmp <= 0x6E; tmp += 2)
1677 snd_azf3328_dbgmisc("0x%02x: 0x%04x\n", tmp, snd_azf3328_codec_inb(chip, tmp));
1681 static int __devinit
1682 snd_azf3328_create(struct snd_card *card,
1683 struct pci_dev *pci,
1684 unsigned long device_type,
1685 struct snd_azf3328 ** rchip)
1687 struct snd_azf3328 *chip;
1689 static struct snd_device_ops ops = {
1690 .dev_free = snd_azf3328_dev_free,
1696 if ((err = pci_enable_device(pci)) < 0)
1699 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1704 spin_lock_init(&chip->reg_lock);
1709 /* check if we can restrict PCI DMA transfers to 24 bits */
1710 if (pci_set_dma_mask(pci, DMA_24BIT_MASK) < 0 ||
1711 pci_set_consistent_dma_mask(pci, DMA_24BIT_MASK) < 0) {
1712 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n");
1717 if ((err = pci_request_regions(pci, "Aztech AZF3328")) < 0) {
1721 chip->codec_port = pci_resource_start(pci, 0);
1722 chip->io2_port = pci_resource_start(pci, 1);
1723 chip->mpu_port = pci_resource_start(pci, 2);
1724 chip->synth_port = pci_resource_start(pci, 3);
1725 chip->mixer_port = pci_resource_start(pci, 4);
1727 if (request_irq(pci->irq, snd_azf3328_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
1728 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1732 chip->irq = pci->irq;
1733 pci_set_master(pci);
1734 synchronize_irq(chip->irq);
1736 snd_azf3328_debug_show_ports(chip);
1738 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1742 /* create mixer interface & switches */
1743 if ((err = snd_azf3328_mixer_new(chip)) < 0)
1747 /* set very low bitrate to reduce noise and power consumption? */
1748 snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT, 5512, 8, 1);
1751 /* standard chip init stuff */
1752 /* default IRQ init value */
1753 tmp = DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE;
1755 spin_lock_irq(&chip->reg_lock);
1756 snd_azf3328_codec_outb(chip, IDX_IO_PLAY_FLAGS, tmp);
1757 snd_azf3328_codec_outb(chip, IDX_IO_REC_FLAGS, tmp);
1758 snd_azf3328_codec_outb(chip, IDX_IO_SOMETHING_FLAGS, tmp);
1759 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00); /* disable timer */
1760 spin_unlock_irq(&chip->reg_lock);
1762 snd_card_set_dev(card, &pci->dev);
1771 snd_azf3328_free(chip);
1772 pci_disable_device(pci);
1778 static int __devinit
1779 snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
1782 struct snd_card *card;
1783 struct snd_azf3328 *chip;
1784 struct snd_opl3 *opl3;
1787 snd_azf3328_dbgcallenter();
1788 if (dev >= SNDRV_CARDS)
1795 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0 );
1799 strcpy(card->driver, "AZF3328");
1800 strcpy(card->shortname, "Aztech AZF3328 (PCI168)");
1802 if ((err = snd_azf3328_create(card, pci, pci_id->driver_data, &chip)) < 0) {
1806 card->private_data = chip;
1808 if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_MPU401,
1809 chip->mpu_port, MPU401_INFO_INTEGRATED,
1810 pci->irq, 0, &chip->rmidi)) < 0) {
1811 snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n", chip->mpu_port);
1815 if ((err = snd_azf3328_timer(chip, 0)) < 0) {
1819 if ((err = snd_azf3328_pcm(chip, 0)) < 0) {
1823 if (snd_opl3_create(card, chip->synth_port, chip->synth_port+2,
1824 OPL3_HW_AUTO, 1, &opl3) < 0) {
1825 snd_printk(KERN_ERR "azf3328: no OPL3 device at 0x%lx-0x%lx?\n",
1826 chip->synth_port, chip->synth_port+2 );
1828 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
1833 opl3->private_data = chip;
1835 sprintf(card->longname, "%s at 0x%lx, irq %i",
1836 card->shortname, chip->codec_port, chip->irq);
1838 if ((err = snd_card_register(card)) < 0) {
1844 "azt3328: Sound driver for Aztech AZF3328-based soundcards such as PCI168\n"
1845 "azt3328: (hardware was completely undocumented - ZERO support from Aztech).\n"
1846 "azt3328: Feel free to contact andi AT lisas.de for bug reports etc.!\n"
1847 "azt3328: User-scalable sequencer timer set to %dHz (1024000Hz / %d).\n",
1848 1024000 / seqtimer_scaling, seqtimer_scaling);
1851 if (snd_azf3328_config_joystick(chip, dev) < 0)
1852 snd_azf3328_io2_outb(chip, IDX_IO2_LEGACY_ADDR,
1853 snd_azf3328_io2_inb(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY);
1855 pci_set_drvdata(pci, card);
1862 snd_card_free(card);
1865 snd_azf3328_dbgcallleave();
1869 static void __devexit
1870 snd_azf3328_remove(struct pci_dev *pci)
1872 snd_azf3328_dbgcallenter();
1873 snd_card_free(pci_get_drvdata(pci));
1874 pci_set_drvdata(pci, NULL);
1875 snd_azf3328_dbgcallleave();
1880 snd_azf3328_suspend(struct pci_dev *pci, pm_message_t state)
1882 struct snd_card *card = pci_get_drvdata(pci);
1883 struct snd_azf3328 *chip = card->private_data;
1886 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1888 snd_pcm_suspend_all(chip->pcm);
1890 for (reg = 0; reg < AZF_IO_SIZE_MIXER_PM / 2; reg++)
1891 chip->saved_regs_mixer[reg] = inw(chip->mixer_port + reg * 2);
1893 /* make sure to disable master volume etc. to prevent looping sound */
1894 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1);
1895 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
1897 for (reg = 0; reg < AZF_IO_SIZE_CODEC_PM / 2; reg++)
1898 chip->saved_regs_codec[reg] = inw(chip->codec_port + reg * 2);
1899 for (reg = 0; reg < AZF_IO_SIZE_IO2_PM / 2; reg++)
1900 chip->saved_regs_io2[reg] = inw(chip->io2_port + reg * 2);
1901 for (reg = 0; reg < AZF_IO_SIZE_MPU_PM / 2; reg++)
1902 chip->saved_regs_mpu[reg] = inw(chip->mpu_port + reg * 2);
1903 for (reg = 0; reg < AZF_IO_SIZE_SYNTH_PM / 2; reg++)
1904 chip->saved_regs_synth[reg] = inw(chip->synth_port + reg * 2);
1906 pci_set_power_state(pci, PCI_D3hot);
1907 pci_disable_device(pci);
1908 pci_save_state(pci);
1913 snd_azf3328_resume(struct pci_dev *pci)
1915 struct snd_card *card = pci_get_drvdata(pci);
1916 struct snd_azf3328 *chip = card->private_data;
1919 pci_restore_state(pci);
1920 pci_enable_device(pci);
1921 pci_set_power_state(pci, PCI_D0);
1922 pci_set_master(pci);
1924 for (reg = 0; reg < AZF_IO_SIZE_IO2_PM / 2; reg++)
1925 outw(chip->saved_regs_io2[reg], chip->io2_port + reg * 2);
1926 for (reg = 0; reg < AZF_IO_SIZE_MPU_PM / 2; reg++)
1927 outw(chip->saved_regs_mpu[reg], chip->mpu_port + reg * 2);
1928 for (reg = 0; reg < AZF_IO_SIZE_SYNTH_PM / 2; reg++)
1929 outw(chip->saved_regs_synth[reg], chip->synth_port + reg * 2);
1930 for (reg = 0; reg < AZF_IO_SIZE_MIXER_PM / 2; reg++)
1931 outw(chip->saved_regs_mixer[reg], chip->mixer_port + reg * 2);
1932 for (reg = 0; reg < AZF_IO_SIZE_CODEC_PM / 2; reg++)
1933 outw(chip->saved_regs_codec[reg], chip->codec_port + reg * 2);
1935 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1943 static struct pci_driver driver = {
1945 .id_table = snd_azf3328_ids,
1946 .probe = snd_azf3328_probe,
1947 .remove = __devexit_p(snd_azf3328_remove),
1949 .suspend = snd_azf3328_suspend,
1950 .resume = snd_azf3328_resume,
1955 alsa_card_azf3328_init(void)
1958 snd_azf3328_dbgcallenter();
1959 err = pci_register_driver(&driver);
1960 snd_azf3328_dbgcallleave();
1965 alsa_card_azf3328_exit(void)
1967 snd_azf3328_dbgcallenter();
1968 pci_unregister_driver(&driver);
1969 snd_azf3328_dbgcallleave();
1972 module_init(alsa_card_azf3328_init)
1973 module_exit(alsa_card_azf3328_exit)