blob: 6117595fc075bba219b7b8a97cbd4de0e9154859 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * azt3328.c - driver for Aztech AZF3328 based soundcards (e.g. PCI168).
Andreas Mohradf59312010-12-27 21:16:43 +01003 * Copyright (C) 2002, 2005 - 2010 by Andreas Mohr <andi AT lisas.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
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).
8 * Other versions are:
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!!
12 *
Andreas Mohrdfbf9512009-07-05 13:55:46 +020013 * Keywords: Windows XP Vista 168nt4-125.zip 168win95-125.zip PCI 168 download
14 * (XP/Vista do not support this card at all but every Linux distribution
15 * has very good support out of the box;
16 * just to make sure that the right people hit this and get to know that,
17 * despite the high level of Internet ignorance - as usual :-P -
Andreas Mohr78df6172009-07-12 22:17:54 +020018 * about very good support for this card - on Linux!)
Andreas Mohrdfbf9512009-07-05 13:55:46 +020019 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * GPL LICENSE
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
24 * (at your option) any later version.
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 *
35 * NOTES
36 * Since Aztech does not provide any chipset documentation,
37 * even on repeated request to various addresses,
38 * and the answer that was finally given was negative
39 * (and I was stupid enough to manage to get hold of a PCI168 soundcard
40 * in the first place >:-P}),
41 * I was forced to base this driver on reverse engineering
42 * (3 weeks' worth of evenings filled with driver work).
Andreas Mohre2f87262006-05-17 11:04:19 +020043 * (and no, I did NOT go the easy way: to pick up a SB PCI128 for 9 Euros)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 *
Andreas Mohr02330fb2008-05-16 12:18:29 +020045 * It is quite likely that the AZF3328 chip is the PCI cousin of the
46 * AZF3318 ("azt1020 pnp", "MM Pro 16") ISA chip, given very similar specs.
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 *
Andreas Mohr02330fb2008-05-16 12:18:29 +020048 * The AZF3328 chip (note: AZF3328, *not* AZT3328, that's just the driver name
49 * for compatibility reasons) from Azfin (joint-venture of Aztech and Fincitec,
50 * Fincitec acquired by National Semiconductor in 2002, together with the
51 * Fincitec-related company ARSmikro) has the following features:
52 *
53 * - compatibility & compliance:
54 * - Microsoft PC 97 ("PC 97 Hardware Design Guide",
55 * http://www.microsoft.com/whdc/archive/pcguides.mspx)
56 * - Microsoft PC 98 Baseline Audio
57 * - MPU401 UART
58 * - Sound Blaster Emulation (DOS Box)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 * - builtin AC97 conformant codec (SNR over 80dB)
Andreas Mohr13769e32006-05-17 11:03:16 +020060 * Note that "conformant" != "compliant"!! this chip's mixer register layout
61 * *differs* from the standard AC97 layout:
62 * they chose to not implement the headphone register (which is not a
63 * problem since it's merely optional), yet when doing this, they committed
64 * the grave sin of letting other registers follow immediately instead of
65 * keeping a headphone dummy register, thereby shifting the mixer register
66 * addresses illegally. So far unfortunately it looks like the very flexible
67 * ALSA AC97 support is still not enough to easily compensate for such a
68 * grave layout violation despite all tweaks and quirks mechanisms it offers.
Andreas Mohr02330fb2008-05-16 12:18:29 +020069 * - builtin genuine OPL3 - verified to work fine, 20080506
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 * - full duplex 16bit playback/record at independent sampling rate
Andreas Mohr02330fb2008-05-16 12:18:29 +020071 * - MPU401 (+ legacy address support, claimed by one official spec sheet)
72 * FIXME: how to enable legacy addr??
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 * - game port (legacy address support)
Andreas Mohre24a1212007-03-26 12:49:45 +020074 * - builtin DirectInput support, helps reduce CPU overhead (interrupt-driven
Andreas Mohr02330fb2008-05-16 12:18:29 +020075 * features supported). - See common term "Digital Enhanced Game Port"...
76 * (probably DirectInput 3.0 spec - confirm)
77 * - builtin 3D enhancement (said to be YAMAHA Ymersion)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 * - built-in General DirectX timer having a 20 bits counter
Andreas Mohrd91c64c2005-10-25 11:17:45 +020079 * with 1us resolution (see below!)
Andreas Mohr02330fb2008-05-16 12:18:29 +020080 * - I2S serial output port for external DAC
Andreas Mohrdfbf9512009-07-05 13:55:46 +020081 * [FIXME: 3.3V or 5V level? maximum rate is 66.2kHz right?]
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 * - supports 33MHz PCI spec 2.1, PCI power management 1.0, compliant with ACPI
83 * - supports hardware volume control
84 * - single chip low cost solution (128 pin QFP)
Andreas Mohrdfbf9512009-07-05 13:55:46 +020085 * - supports programmable Sub-vendor and Sub-system ID [24C02 SEEPROM chip]
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 * required for Microsoft's logo compliance (FIXME: where?)
Andreas Mohr02330fb2008-05-16 12:18:29 +020087 * At least the Trident 4D Wave DX has one bit somewhere
88 * to enable writes to PCI subsystem VID registers, that should be it.
89 * This might easily be in extended PCI reg space, since PCI168 also has
90 * some custom data starting at 0x80. What kind of config settings
91 * are located in our extended PCI space anyway??
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 * - PCI168 AP(W) card: power amplifier with 4 Watts/channel at 4 Ohms
Andreas Mohrdfbf9512009-07-05 13:55:46 +020093 * [TDA1517P chip]
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 *
Andreas Mohrd91c64c2005-10-25 11:17:45 +020095 * Note that this driver now is actually *better* than the Windows driver,
96 * since it additionally supports the card's 1MHz DirectX timer - just try
97 * the following snd-seq module parameters etc.:
98 * - options snd-seq seq_default_timer_class=2 seq_default_timer_sclass=0
99 * seq_default_timer_card=0 seq_client_load=1 seq_default_timer_device=0
100 * seq_default_timer_subdevice=0 seq_default_timer_resolution=1000000
101 * - "timidity -iAv -B2,8 -Os -EFreverb=0"
102 * - "pmidi -p 128:0 jazz.mid"
103 *
Andreas Mohr02330fb2008-05-16 12:18:29 +0200104 * OPL3 hardware playback testing, try something like:
105 * cat /proc/asound/hwdep
106 * and
107 * aconnect -o
108 * Then use
109 * sbiload -Dhw:x,y --opl3 /usr/share/sounds/opl3/std.o3 ......./drums.o3
110 * where x,y is the xx-yy number as given in hwdep.
111 * Then try
112 * pmidi -p a:b jazz.mid
113 * where a:b is the client number plus 0 usually, as given by aconnect above.
114 * Oh, and make sure to unmute the FM mixer control (doh!)
115 * NOTE: power use during OPL3 playback is _VERY_ high (70W --> 90W!)
116 * despite no CPU activity, possibly due to hindering ACPI idling somehow.
117 * Shouldn't be a problem of the AZF3328 chip itself, I'd hope.
118 * Higher PCM / FM mixer levels seem to conflict (causes crackling),
119 * at least sometimes. Maybe even use with hardware sequencer timer above :)
120 * adplay/adplug-utils might soon offer hardware-based OPL3 playback, too.
121 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 * Certain PCI versions of this card are susceptible to DMA traffic underruns
123 * in some systems (resulting in sound crackling/clicking/popping),
124 * probably because they don't have a DMA FIFO buffer or so.
125 * Overview (PCI ID/PCI subID/PCI rev.):
126 * - no DMA crackling on SiS735: 0x50DC/0x1801/16
127 * - unknown performance: 0x50DC/0x1801/10
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200128 * (well, it's not bad on an Athlon 1800 with now very optimized IRQ handler)
129 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 * Crackling happens with VIA chipsets or, in my case, an SiS735, which is
131 * supposed to be very fast and supposed to get rid of crackling much
132 * better than a VIA, yet ironically I still get crackling, like many other
133 * people with the same chipset.
134 * Possible remedies:
Andreas Mohr02330fb2008-05-16 12:18:29 +0200135 * - use speaker (amplifier) output instead of headphone output
136 * (in case crackling is due to overloaded output clipping)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 * - plug card into a different PCI slot, preferrably one that isn't shared
138 * too much (this helps a lot, but not completely!)
139 * - get rid of PCI VGA card, use AGP instead
140 * - upgrade or downgrade BIOS
141 * - fiddle with PCI latency settings (setpci -v -s BUSID latency_timer=XX)
142 * Not too helpful.
143 * - Disable ACPI/power management/"Auto Detect RAM/PCI Clk" in BIOS
Andreas Mohr02330fb2008-05-16 12:18:29 +0200144 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 * BUGS
Andreas Mohr02330fb2008-05-16 12:18:29 +0200146 * - full-duplex might *still* be problematic, however a recent test was fine
Andreas Mohre24a1212007-03-26 12:49:45 +0200147 * - (non-bug) "Bass/Treble or 3D settings don't work" - they do get evaluated
148 * if you set PCM output switch to "pre 3D" instead of "post 3D".
149 * If this can't be set, then get a mixer application that Isn't Stupid (tm)
150 * (e.g. kmix, gamix) - unfortunately several are!!
Andreas Mohr02330fb2008-05-16 12:18:29 +0200151 * - locking is not entirely clean, especially the audio stream activity
152 * ints --> may be racy
153 * - an _unconnected_ secondary joystick at the gameport will be reported
154 * to be "active" (floating values, not precisely -1) due to the way we need
155 * to read the Digital Enhanced Game Port. Not sure whether it is fixable.
156 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 * TODO
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200158 * - use PCI_VDEVICE
159 * - verify driver status on x86_64
160 * - test multi-card driver operation
161 * - (ab)use 1MHz DirectX timer as kernel clocksource
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 * - test MPU401 MIDI playback etc.
Andreas Mohr02330fb2008-05-16 12:18:29 +0200163 * - add more power micro-management (disable various units of the card
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200164 * as long as they're unused, to improve audio quality and save power).
165 * However this requires more I/O ports which I haven't figured out yet
166 * and which thus might not even exist...
Andreas Mohrca54bde2006-05-17 11:02:24 +0200167 * The standard suspend/resume functionality could probably make use of
168 * some improvement, too...
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 * - figure out what all unknown port bits are responsible for
Andreas Mohr13769e32006-05-17 11:03:16 +0200170 * - figure out some cleverly evil scheme to possibly make ALSA AC97 code
171 * fully accept our quite incompatible ""AC97"" mixer and thus save some
172 * code (but I'm not too optimistic that doing this is possible at all)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200173 * - use MMIO (memory-mapped I/O)? Slightly faster access, e.g. for gameport.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 */
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#include <asm/io.h>
177#include <linux/init.h>
Andreas Mohr689c6912010-12-27 21:17:35 +0100178#include <linux/bug.h> /* WARN_ONCE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179#include <linux/pci.h>
180#include <linux/delay.h>
181#include <linux/slab.h>
182#include <linux/gameport.h>
183#include <linux/moduleparam.h>
Matthias Gehre910638a2006-03-28 01:56:48 -0800184#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185#include <sound/core.h>
186#include <sound/control.h>
187#include <sound/pcm.h>
188#include <sound/rawmidi.h>
189#include <sound/mpu401.h>
190#include <sound/opl3.h>
191#include <sound/initval.h>
192#include "azt3328.h"
193
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200194MODULE_AUTHOR("Andreas Mohr <andi AT lisas.de>");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195MODULE_DESCRIPTION("Aztech AZF3328 (PCI168)");
196MODULE_LICENSE("GPL");
197MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
198
199#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
Andreas Mohr02330fb2008-05-16 12:18:29 +0200200#define SUPPORT_GAMEPORT 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#endif
202
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200203/* === Debug settings ===
204 Further diagnostic functionality than the settings below
Andreas Mohradf59312010-12-27 21:16:43 +0100205 does not need to be provided, since one can easily write a POSIX shell script
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200206 to dump the card's I/O ports (those listed in lspci -v -v):
Andreas Mohradf59312010-12-27 21:16:43 +0100207 dump()
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200208 {
209 local descr=$1; local addr=$2; local count=$3
210
211 echo "${descr}: ${count} @ ${addr}:"
Andreas Mohradf59312010-12-27 21:16:43 +0100212 dd if=/dev/port skip=`printf %d ${addr}` count=${count} bs=1 \
213 2>/dev/null| hexdump -C
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200214 }
215 and then use something like
216 "dump joy200 0x200 8", "dump mpu388 0x388 4", "dump joy 0xb400 8",
217 "dump codec00 0xa800 32", "dump mixer 0xb800 64", "dump synth 0xbc00 8",
218 possibly within a "while true; do ... sleep 1; done" loop.
219 Tweaking ports could be done using
220 VALSTRING="`printf "%02x" $value`"
Andreas Mohradf59312010-12-27 21:16:43 +0100221 printf "\x""$VALSTRING"|dd of=/dev/port seek=`printf %d ${addr}` bs=1 \
222 2>/dev/null
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200223*/
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#define DEBUG_MISC 0
226#define DEBUG_CALLS 0
227#define DEBUG_MIXER 0
Andreas Mohr78df6172009-07-12 22:17:54 +0200228#define DEBUG_CODEC 0
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200229#define DEBUG_TIMER 0
Andreas Mohr02330fb2008-05-16 12:18:29 +0200230#define DEBUG_GAME 0
Andreas Mohr78df6172009-07-12 22:17:54 +0200231#define DEBUG_PM 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232#define MIXER_TESTING 0
233
234#if DEBUG_MISC
Andreas Mohr78df6172009-07-12 22:17:54 +0200235#define snd_azf3328_dbgmisc(format, args...) printk(KERN_DEBUG format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#else
237#define snd_azf3328_dbgmisc(format, args...)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200238#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240#if DEBUG_CALLS
241#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args)
Andreas Mohr78df6172009-07-12 22:17:54 +0200242#define snd_azf3328_dbgcallenter() printk(KERN_DEBUG "--> %s\n", __func__)
243#define snd_azf3328_dbgcallleave() printk(KERN_DEBUG "<-- %s\n", __func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#else
245#define snd_azf3328_dbgcalls(format, args...)
246#define snd_azf3328_dbgcallenter()
247#define snd_azf3328_dbgcallleave()
Andreas Mohr02330fb2008-05-16 12:18:29 +0200248#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250#if DEBUG_MIXER
Takashi Iwaiee419652009-02-05 16:11:31 +0100251#define snd_azf3328_dbgmixer(format, args...) printk(KERN_DEBUG format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252#else
253#define snd_azf3328_dbgmixer(format, args...)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200254#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Andreas Mohr78df6172009-07-12 22:17:54 +0200256#if DEBUG_CODEC
257#define snd_azf3328_dbgcodec(format, args...) printk(KERN_DEBUG format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#else
Andreas Mohr78df6172009-07-12 22:17:54 +0200259#define snd_azf3328_dbgcodec(format, args...)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200260#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200262#if DEBUG_MISC
Takashi Iwaiee419652009-02-05 16:11:31 +0100263#define snd_azf3328_dbgtimer(format, args...) printk(KERN_DEBUG format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#else
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200265#define snd_azf3328_dbgtimer(format, args...)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200266#endif
267
268#if DEBUG_GAME
Takashi Iwaiee419652009-02-05 16:11:31 +0100269#define snd_azf3328_dbggame(format, args...) printk(KERN_DEBUG format, ##args)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200270#else
271#define snd_azf3328_dbggame(format, args...)
272#endif
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200273
Andreas Mohr78df6172009-07-12 22:17:54 +0200274#if DEBUG_PM
275#define snd_azf3328_dbgpm(format, args...) printk(KERN_DEBUG format, ##args)
276#else
277#define snd_azf3328_dbgpm(format, args...)
278#endif
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
281module_param_array(index, int, NULL, 0444);
282MODULE_PARM_DESC(index, "Index value for AZF3328 soundcard.");
283
284static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
285module_param_array(id, charp, NULL, 0444);
286MODULE_PARM_DESC(id, "ID string for AZF3328 soundcard.");
287
288static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
289module_param_array(enable, bool, NULL, 0444);
290MODULE_PARM_DESC(enable, "Enable AZF3328 soundcard.");
291
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200292static int seqtimer_scaling = 128;
293module_param(seqtimer_scaling, int, 0444);
294MODULE_PARM_DESC(seqtimer_scaling, "Set 1024000Hz sequencer timer scale factor (lockup danger!). Default 128.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200296enum snd_azf3328_codec_type {
Andreas Mohradf59312010-12-27 21:16:43 +0100297 /* warning: fixed indices (also used for bitmask checks!) */
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200298 AZF_CODEC_PLAYBACK = 0,
299 AZF_CODEC_CAPTURE = 1,
300 AZF_CODEC_I2S_OUT = 2,
Andreas Mohr02330fb2008-05-16 12:18:29 +0200301};
302
Andreas Mohrda237f32010-12-27 21:17:26 +0100303struct snd_azf3328_codec_data {
304 unsigned long io_base; /* keep first! (avoid offset calc) */
305 unsigned int dma_base; /* helper to avoid an indirection in hotpath */
306 spinlock_t *lock; /* TODO: convert to our own per-codec lock member */
307 struct snd_pcm_substream *substream;
308 bool running;
309 enum snd_azf3328_codec_type type;
310 const char *name;
311};
312
Takashi Iwai95de7762005-11-17 15:02:42 +0100313struct snd_azf3328 {
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200314 /* often-used fields towards beginning, then grouped */
Andreas Mohr02330fb2008-05-16 12:18:29 +0200315
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200316 unsigned long ctrl_io; /* usually 0xb000, size 128 */
Andreas Mohr02330fb2008-05-16 12:18:29 +0200317 unsigned long game_io; /* usually 0xb400, size 8 */
318 unsigned long mpu_io; /* usually 0xb800, size 4 */
319 unsigned long opl3_io; /* usually 0xbc00, size 8 */
320 unsigned long mixer_io; /* usually 0xc000, size 64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200322 spinlock_t reg_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Takashi Iwai95de7762005-11-17 15:02:42 +0100324 struct snd_timer *timer;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200325
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200326 struct snd_pcm *pcm[3];
327
328 /* playback, recording and I2S out codecs */
329 struct snd_azf3328_codec_data codecs[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Takashi Iwai95de7762005-11-17 15:02:42 +0100331 struct snd_card *card;
332 struct snd_rawmidi *rmidi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Andreas Mohr02330fb2008-05-16 12:18:29 +0200334#ifdef SUPPORT_GAMEPORT
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200335 struct gameport *gameport;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200336 u16 axes[4];
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200337#endif
338
339 struct pci_dev *pci;
340 int irq;
Andreas Mohrca54bde2006-05-17 11:02:24 +0200341
Andreas Mohr627d3e72008-06-23 11:50:47 +0200342 /* register 0x6a is write-only, thus need to remember setting.
343 * If we need to add more registers here, then we might try to fold this
344 * into some transparent combined shadow register handling with
345 * CONFIG_PM register storage below, but that's slightly difficult. */
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200346 u16 shadow_reg_ctrl_6AH;
Andreas Mohr627d3e72008-06-23 11:50:47 +0200347
Andreas Mohrca54bde2006-05-17 11:02:24 +0200348#ifdef CONFIG_PM
349 /* register value containers for power management
Andreas Mohr78df6172009-07-12 22:17:54 +0200350 * Note: not always full I/O range preserved (similar to Win driver!) */
351 u32 saved_regs_ctrl[AZF_ALIGN(AZF_IO_SIZE_CTRL_PM) / 4];
352 u32 saved_regs_game[AZF_ALIGN(AZF_IO_SIZE_GAME_PM) / 4];
353 u32 saved_regs_mpu[AZF_ALIGN(AZF_IO_SIZE_MPU_PM) / 4];
354 u32 saved_regs_opl3[AZF_ALIGN(AZF_IO_SIZE_OPL3_PM) / 4];
355 u32 saved_regs_mixer[AZF_ALIGN(AZF_IO_SIZE_MIXER_PM) / 4];
Andreas Mohrca54bde2006-05-17 11:02:24 +0200356#endif
Takashi Iwai95de7762005-11-17 15:02:42 +0100357};
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200358
Alexey Dobriyancebe41d2010-02-06 00:21:03 +0200359static DEFINE_PCI_DEVICE_TABLE(snd_azf3328_ids) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 { 0x122D, 0x50DC, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* PCI168/3328 */
361 { 0x122D, 0x80DA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* 3328 */
362 { 0, }
363};
364
365MODULE_DEVICE_TABLE(pci, snd_azf3328_ids);
366
Andreas Mohr02330fb2008-05-16 12:18:29 +0200367
368static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200369snd_azf3328_io_reg_setb(unsigned reg, u8 mask, bool do_set)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200370{
Andreas Mohradf59312010-12-27 21:16:43 +0100371 /* Well, strictly spoken, the inb/outb sequence isn't atomic
372 and would need locking. However we currently don't care
373 since it potentially complicates matters. */
Andreas Mohr02330fb2008-05-16 12:18:29 +0200374 u8 prev = inb(reg), new;
375
376 new = (do_set) ? (prev|mask) : (prev & ~mask);
377 /* we need to always write the new value no matter whether it differs
378 * or not, since some register bits don't indicate their setting */
379 outb(new, reg);
380 if (new != prev)
381 return 1;
382
383 return 0;
384}
385
Andreas Mohr02330fb2008-05-16 12:18:29 +0200386static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200387snd_azf3328_codec_outb(const struct snd_azf3328_codec_data *codec,
388 unsigned reg,
389 u8 value
390)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200391{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200392 outb(value, codec->io_base + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200393}
394
395static inline u8
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200396snd_azf3328_codec_inb(const struct snd_azf3328_codec_data *codec, unsigned reg)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200397{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200398 return inb(codec->io_base + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200399}
400
401static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200402snd_azf3328_codec_outw(const struct snd_azf3328_codec_data *codec,
403 unsigned reg,
404 u16 value
405)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200406{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200407 outw(value, codec->io_base + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200408}
409
410static inline u16
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200411snd_azf3328_codec_inw(const struct snd_azf3328_codec_data *codec, unsigned reg)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200412{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200413 return inw(codec->io_base + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200414}
415
416static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200417snd_azf3328_codec_outl(const struct snd_azf3328_codec_data *codec,
418 unsigned reg,
419 u32 value
420)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200421{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200422 outl(value, codec->io_base + reg);
Andreas Mohr02330fb2008-05-16 12:18:29 +0200423}
424
Andreas Mohr689c6912010-12-27 21:17:35 +0100425static inline void
426snd_azf3328_codec_outl_multi(const struct snd_azf3328_codec_data *codec,
427 unsigned reg, const void *buffer, int count
428)
429{
430 unsigned long addr = codec->io_base + reg;
431 if (count) {
432 const u32 *buf = buffer;
433 do {
434 outl(*buf++, addr);
435 addr += 4;
436 } while (--count);
437 }
438}
439
Andreas Mohr02330fb2008-05-16 12:18:29 +0200440static inline u32
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200441snd_azf3328_codec_inl(const struct snd_azf3328_codec_data *codec, unsigned reg)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200442{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200443 return inl(codec->io_base + reg);
444}
445
446static inline void
447snd_azf3328_ctrl_outb(const struct snd_azf3328 *chip, unsigned reg, u8 value)
448{
449 outb(value, chip->ctrl_io + reg);
450}
451
452static inline u8
453snd_azf3328_ctrl_inb(const struct snd_azf3328 *chip, unsigned reg)
454{
455 return inb(chip->ctrl_io + reg);
456}
457
458static inline void
459snd_azf3328_ctrl_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
460{
461 outw(value, chip->ctrl_io + reg);
462}
463
464static inline void
465snd_azf3328_ctrl_outl(const struct snd_azf3328 *chip, unsigned reg, u32 value)
466{
467 outl(value, chip->ctrl_io + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200468}
469
470static inline void
Andreas Mohr02330fb2008-05-16 12:18:29 +0200471snd_azf3328_game_outb(const struct snd_azf3328 *chip, unsigned reg, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Andreas Mohr02330fb2008-05-16 12:18:29 +0200473 outb(value, chip->game_io + reg);
474}
475
476static inline void
477snd_azf3328_game_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
478{
479 outw(value, chip->game_io + reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
481
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200482static inline u8
Andreas Mohr02330fb2008-05-16 12:18:29 +0200483snd_azf3328_game_inb(const struct snd_azf3328 *chip, unsigned reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
Andreas Mohr02330fb2008-05-16 12:18:29 +0200485 return inb(chip->game_io + reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486}
487
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200488static inline u16
Andreas Mohr02330fb2008-05-16 12:18:29 +0200489snd_azf3328_game_inw(const struct snd_azf3328 *chip, unsigned reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
Andreas Mohr02330fb2008-05-16 12:18:29 +0200491 return inw(chip->game_io + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200492}
493
Andreas Mohr02330fb2008-05-16 12:18:29 +0200494static inline void
495snd_azf3328_mixer_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200496{
Andreas Mohr02330fb2008-05-16 12:18:29 +0200497 outw(value, chip->mixer_io + reg);
498}
499
500static inline u16
501snd_azf3328_mixer_inw(const struct snd_azf3328 *chip, unsigned reg)
502{
503 return inw(chip->mixer_io + reg);
504}
505
506#define AZF_MUTE_BIT 0x80
507
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200508static bool
Andreas Mohr02330fb2008-05-16 12:18:29 +0200509snd_azf3328_mixer_set_mute(const struct snd_azf3328 *chip,
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200510 unsigned reg, bool do_mute
Andreas Mohr02330fb2008-05-16 12:18:29 +0200511)
512{
513 unsigned long portbase = chip->mixer_io + reg + 1;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200514 bool updated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 /* the mute bit is on the *second* (i.e. right) register of a
517 * left/right channel setting */
Andreas Mohr02330fb2008-05-16 12:18:29 +0200518 updated = snd_azf3328_io_reg_setb(portbase, AZF_MUTE_BIT, do_mute);
519
520 /* indicate whether it was muted before */
521 return (do_mute) ? !updated : updated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522}
523
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200524static void
Andreas Mohr02330fb2008-05-16 12:18:29 +0200525snd_azf3328_mixer_write_volume_gradually(const struct snd_azf3328 *chip,
526 unsigned reg,
527 unsigned char dst_vol_left,
528 unsigned char dst_vol_right,
529 int chan_sel, int delay
530)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Andreas Mohr02330fb2008-05-16 12:18:29 +0200532 unsigned long portbase = chip->mixer_io + reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 unsigned char curr_vol_left = 0, curr_vol_right = 0;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200534 int left_change = 0, right_change = 0;
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 snd_azf3328_dbgcallenter();
Andreas Mohr02330fb2008-05-16 12:18:29 +0200537
538 if (chan_sel & SET_CHAN_LEFT) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200539 curr_vol_left = inb(portbase + 1);
Andreas Mohr02330fb2008-05-16 12:18:29 +0200540
541 /* take care of muting flag contained in left channel */
542 if (curr_vol_left & AZF_MUTE_BIT)
543 dst_vol_left |= AZF_MUTE_BIT;
544 else
545 dst_vol_left &= ~AZF_MUTE_BIT;
546
547 left_change = (curr_vol_left > dst_vol_left) ? -1 : 1;
548 }
549
550 if (chan_sel & SET_CHAN_RIGHT) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200551 curr_vol_right = inb(portbase + 0);
Andreas Mohr02330fb2008-05-16 12:18:29 +0200552
553 right_change = (curr_vol_right > dst_vol_right) ? -1 : 1;
554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Andreas Mohre2f87262006-05-17 11:04:19 +0200556 do {
Andreas Mohr02330fb2008-05-16 12:18:29 +0200557 if (left_change) {
558 if (curr_vol_left != dst_vol_left) {
559 curr_vol_left += left_change;
560 outb(curr_vol_left, portbase + 1);
561 } else
562 left_change = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 }
Andreas Mohr02330fb2008-05-16 12:18:29 +0200564 if (right_change) {
565 if (curr_vol_right != dst_vol_right) {
566 curr_vol_right += right_change;
567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 /* during volume change, the right channel is crackling
569 * somewhat more than the left channel, unfortunately.
570 * This seems to be a hardware issue. */
Andreas Mohr02330fb2008-05-16 12:18:29 +0200571 outb(curr_vol_right, portbase + 0);
572 } else
573 right_change = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 }
575 if (delay)
576 mdelay(delay);
Andreas Mohr02330fb2008-05-16 12:18:29 +0200577 } while ((left_change) || (right_change));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 snd_azf3328_dbgcallleave();
579}
580
581/*
582 * general mixer element
583 */
Takashi Iwai95de7762005-11-17 15:02:42 +0100584struct azf3328_mixer_reg {
Andreas Mohr02330fb2008-05-16 12:18:29 +0200585 unsigned reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 unsigned int lchan_shift, rchan_shift;
587 unsigned int mask;
588 unsigned int invert: 1;
589 unsigned int stereo: 1;
590 unsigned int enum_c: 4;
Takashi Iwai95de7762005-11-17 15:02:42 +0100591};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
593#define COMPOSE_MIXER_REG(reg,lchan_shift,rchan_shift,mask,invert,stereo,enum_c) \
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200594 ((reg) | (lchan_shift << 8) | (rchan_shift << 12) | \
595 (mask << 16) | \
596 (invert << 24) | \
597 (stereo << 25) | \
598 (enum_c << 26))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Takashi Iwai95de7762005-11-17 15:02:42 +0100600static void snd_azf3328_mixer_reg_decode(struct azf3328_mixer_reg *r, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
602 r->reg = val & 0xff;
603 r->lchan_shift = (val >> 8) & 0x0f;
604 r->rchan_shift = (val >> 12) & 0x0f;
605 r->mask = (val >> 16) & 0xff;
606 r->invert = (val >> 24) & 1;
607 r->stereo = (val >> 25) & 1;
608 r->enum_c = (val >> 26) & 0x0f;
609}
610
611/*
612 * mixer switches/volumes
613 */
614
615#define AZF3328_MIXER_SWITCH(xname, reg, shift, invert) \
616{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
617 .info = snd_azf3328_info_mixer, \
618 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
619 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, 0x1, invert, 0, 0), \
620}
621
622#define AZF3328_MIXER_VOL_STEREO(xname, reg, mask, invert) \
623{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
624 .info = snd_azf3328_info_mixer, \
625 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
626 .private_value = COMPOSE_MIXER_REG(reg, 8, 0, mask, invert, 1, 0), \
627}
628
629#define AZF3328_MIXER_VOL_MONO(xname, reg, mask, is_right_chan) \
630{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
631 .info = snd_azf3328_info_mixer, \
632 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
633 .private_value = COMPOSE_MIXER_REG(reg, is_right_chan ? 0 : 8, 0, mask, 1, 0, 0), \
634}
635
636#define AZF3328_MIXER_VOL_SPECIAL(xname, reg, mask, shift, invert) \
637{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
638 .info = snd_azf3328_info_mixer, \
639 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
640 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, mask, invert, 0, 0), \
641}
642
643#define AZF3328_MIXER_ENUM(xname, reg, enum_c, shift) \
644{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
645 .info = snd_azf3328_info_mixer_enum, \
646 .get = snd_azf3328_get_mixer_enum, .put = snd_azf3328_put_mixer_enum, \
647 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, 0, 0, 0, enum_c), \
648}
649
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200650static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100651snd_azf3328_info_mixer(struct snd_kcontrol *kcontrol,
652 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
Takashi Iwai95de7762005-11-17 15:02:42 +0100654 struct azf3328_mixer_reg reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
656 snd_azf3328_dbgcallenter();
657 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200658 uinfo->type = reg.mask == 1 ?
659 SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 uinfo->count = reg.stereo + 1;
661 uinfo->value.integer.min = 0;
662 uinfo->value.integer.max = reg.mask;
663 snd_azf3328_dbgcallleave();
664 return 0;
665}
666
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200667static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100668snd_azf3328_get_mixer(struct snd_kcontrol *kcontrol,
669 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670{
Takashi Iwai95de7762005-11-17 15:02:42 +0100671 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
672 struct azf3328_mixer_reg reg;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200673 u16 oreg, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
675 snd_azf3328_dbgcallenter();
676 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
677
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200678 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 val = (oreg >> reg.lchan_shift) & reg.mask;
680 if (reg.invert)
681 val = reg.mask - val;
682 ucontrol->value.integer.value[0] = val;
683 if (reg.stereo) {
684 val = (oreg >> reg.rchan_shift) & reg.mask;
685 if (reg.invert)
686 val = reg.mask - val;
687 ucontrol->value.integer.value[1] = val;
688 }
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200689 snd_azf3328_dbgmixer("get: %02x is %04x -> vol %02lx|%02lx "
690 "(shift %02d|%02d, mask %02x, inv. %d, stereo %d)\n",
691 reg.reg, oreg,
692 ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
693 reg.lchan_shift, reg.rchan_shift, reg.mask, reg.invert, reg.stereo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 snd_azf3328_dbgcallleave();
695 return 0;
696}
697
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200698static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100699snd_azf3328_put_mixer(struct snd_kcontrol *kcontrol,
700 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Takashi Iwai95de7762005-11-17 15:02:42 +0100702 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
703 struct azf3328_mixer_reg reg;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200704 u16 oreg, nreg, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
706 snd_azf3328_dbgcallenter();
707 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200708 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 val = ucontrol->value.integer.value[0] & reg.mask;
710 if (reg.invert)
711 val = reg.mask - val;
712 nreg = oreg & ~(reg.mask << reg.lchan_shift);
713 nreg |= (val << reg.lchan_shift);
714 if (reg.stereo) {
715 val = ucontrol->value.integer.value[1] & reg.mask;
716 if (reg.invert)
717 val = reg.mask - val;
718 nreg &= ~(reg.mask << reg.rchan_shift);
719 nreg |= (val << reg.rchan_shift);
720 }
721 if (reg.mask >= 0x07) /* it's a volume control, so better take care */
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200722 snd_azf3328_mixer_write_volume_gradually(
723 chip, reg.reg, nreg >> 8, nreg & 0xff,
724 /* just set both channels, doesn't matter */
725 SET_CHAN_LEFT|SET_CHAN_RIGHT,
726 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 else
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200728 snd_azf3328_mixer_outw(chip, reg.reg, nreg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200730 snd_azf3328_dbgmixer("put: %02x to %02lx|%02lx, "
731 "oreg %04x; shift %02d|%02d -> nreg %04x; after: %04x\n",
732 reg.reg, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
733 oreg, reg.lchan_shift, reg.rchan_shift,
734 nreg, snd_azf3328_mixer_inw(chip, reg.reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 snd_azf3328_dbgcallleave();
736 return (nreg != oreg);
737}
738
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200739static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100740snd_azf3328_info_mixer_enum(struct snd_kcontrol *kcontrol,
741 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200743 static const char * const texts1[] = {
Andreas Mohr13769e32006-05-17 11:03:16 +0200744 "Mic1", "Mic2"
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200745 };
746 static const char * const texts2[] = {
Andreas Mohr13769e32006-05-17 11:03:16 +0200747 "Mix", "Mic"
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200748 };
749 static const char * const texts3[] = {
Andreas Mohr02330fb2008-05-16 12:18:29 +0200750 "Mic", "CD", "Video", "Aux",
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200751 "Line", "Mix", "Mix Mono", "Phone"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 };
Andreas Mohr13769e32006-05-17 11:03:16 +0200753 static const char * const texts4[] = {
754 "pre 3D", "post 3D"
755 };
Takashi Iwai95de7762005-11-17 15:02:42 +0100756 struct azf3328_mixer_reg reg;
Andreas Mohr627d3e72008-06-23 11:50:47 +0200757 const char * const *p = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
759 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
760 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
761 uinfo->count = (reg.reg == IDX_MIXER_REC_SELECT) ? 2 : 1;
762 uinfo->value.enumerated.items = reg.enum_c;
763 if (uinfo->value.enumerated.item > reg.enum_c - 1U)
764 uinfo->value.enumerated.item = reg.enum_c - 1U;
Andreas Mohre2f87262006-05-17 11:04:19 +0200765 if (reg.reg == IDX_MIXER_ADVCTL2) {
Andreas Mohr13769e32006-05-17 11:03:16 +0200766 switch(reg.lchan_shift) {
767 case 8: /* modem out sel */
Andreas Mohr627d3e72008-06-23 11:50:47 +0200768 p = texts1;
Andreas Mohr13769e32006-05-17 11:03:16 +0200769 break;
770 case 9: /* mono sel source */
Andreas Mohr627d3e72008-06-23 11:50:47 +0200771 p = texts2;
Andreas Mohr13769e32006-05-17 11:03:16 +0200772 break;
773 case 15: /* PCM Out Path */
Andreas Mohr627d3e72008-06-23 11:50:47 +0200774 p = texts4;
Andreas Mohr13769e32006-05-17 11:03:16 +0200775 break;
776 }
Andreas Mohre2f87262006-05-17 11:04:19 +0200777 } else
Andreas Mohr02330fb2008-05-16 12:18:29 +0200778 if (reg.reg == IDX_MIXER_REC_SELECT)
Andreas Mohr627d3e72008-06-23 11:50:47 +0200779 p = texts3;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200780
Andreas Mohr627d3e72008-06-23 11:50:47 +0200781 strcpy(uinfo->value.enumerated.name, p[uinfo->value.enumerated.item]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 return 0;
783}
784
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200785static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100786snd_azf3328_get_mixer_enum(struct snd_kcontrol *kcontrol,
787 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788{
Takashi Iwai95de7762005-11-17 15:02:42 +0100789 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
790 struct azf3328_mixer_reg reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 unsigned short val;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200792
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200794 val = snd_azf3328_mixer_inw(chip, reg.reg);
Andreas Mohre2f87262006-05-17 11:04:19 +0200795 if (reg.reg == IDX_MIXER_REC_SELECT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 ucontrol->value.enumerated.item[0] = (val >> 8) & (reg.enum_c - 1);
797 ucontrol->value.enumerated.item[1] = (val >> 0) & (reg.enum_c - 1);
Andreas Mohre2f87262006-05-17 11:04:19 +0200798 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 ucontrol->value.enumerated.item[0] = (val >> reg.lchan_shift) & (reg.enum_c - 1);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200800
801 snd_azf3328_dbgmixer("get_enum: %02x is %04x -> %d|%d (shift %02d, enum_c %d)\n",
802 reg.reg, val, ucontrol->value.enumerated.item[0], ucontrol->value.enumerated.item[1],
803 reg.lchan_shift, reg.enum_c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 return 0;
805}
806
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200807static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100808snd_azf3328_put_mixer_enum(struct snd_kcontrol *kcontrol,
809 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
Takashi Iwai95de7762005-11-17 15:02:42 +0100811 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
812 struct azf3328_mixer_reg reg;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200813 u16 oreg, nreg, val;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200814
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200816 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 val = oreg;
Andreas Mohre2f87262006-05-17 11:04:19 +0200818 if (reg.reg == IDX_MIXER_REC_SELECT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 if (ucontrol->value.enumerated.item[0] > reg.enum_c - 1U ||
820 ucontrol->value.enumerated.item[1] > reg.enum_c - 1U)
821 return -EINVAL;
822 val = (ucontrol->value.enumerated.item[0] << 8) |
823 (ucontrol->value.enumerated.item[1] << 0);
Andreas Mohre2f87262006-05-17 11:04:19 +0200824 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 if (ucontrol->value.enumerated.item[0] > reg.enum_c - 1U)
826 return -EINVAL;
827 val &= ~((reg.enum_c - 1) << reg.lchan_shift);
828 val |= (ucontrol->value.enumerated.item[0] << reg.lchan_shift);
829 }
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200830 snd_azf3328_mixer_outw(chip, reg.reg, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 nreg = val;
832
833 snd_azf3328_dbgmixer("put_enum: %02x to %04x, oreg %04x\n", reg.reg, val, oreg);
834 return (nreg != oreg);
835}
836
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100837static struct snd_kcontrol_new snd_azf3328_mixer_controls[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 AZF3328_MIXER_SWITCH("Master Playback Switch", IDX_MIXER_PLAY_MASTER, 15, 1),
839 AZF3328_MIXER_VOL_STEREO("Master Playback Volume", IDX_MIXER_PLAY_MASTER, 0x1f, 1),
Andreas Mohr627d3e72008-06-23 11:50:47 +0200840 AZF3328_MIXER_SWITCH("PCM Playback Switch", IDX_MIXER_WAVEOUT, 15, 1),
841 AZF3328_MIXER_VOL_STEREO("PCM Playback Volume",
842 IDX_MIXER_WAVEOUT, 0x1f, 1),
843 AZF3328_MIXER_SWITCH("PCM 3D Bypass Playback Switch",
844 IDX_MIXER_ADVCTL2, 7, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 AZF3328_MIXER_SWITCH("FM Playback Switch", IDX_MIXER_FMSYNTH, 15, 1),
846 AZF3328_MIXER_VOL_STEREO("FM Playback Volume", IDX_MIXER_FMSYNTH, 0x1f, 1),
847 AZF3328_MIXER_SWITCH("CD Playback Switch", IDX_MIXER_CDAUDIO, 15, 1),
848 AZF3328_MIXER_VOL_STEREO("CD Playback Volume", IDX_MIXER_CDAUDIO, 0x1f, 1),
849 AZF3328_MIXER_SWITCH("Capture Switch", IDX_MIXER_REC_VOLUME, 15, 1),
850 AZF3328_MIXER_VOL_STEREO("Capture Volume", IDX_MIXER_REC_VOLUME, 0x0f, 0),
851 AZF3328_MIXER_ENUM("Capture Source", IDX_MIXER_REC_SELECT, 8, 0),
852 AZF3328_MIXER_SWITCH("Mic Playback Switch", IDX_MIXER_MIC, 15, 1),
853 AZF3328_MIXER_VOL_MONO("Mic Playback Volume", IDX_MIXER_MIC, 0x1f, 1),
854 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0),
855 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1),
856 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1),
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100857 AZF3328_MIXER_SWITCH("Beep Playback Switch", IDX_MIXER_PCBEEP, 15, 1),
858 AZF3328_MIXER_VOL_SPECIAL("Beep Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1),
860 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1),
861 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1),
862 AZF3328_MIXER_VOL_STEREO("Aux Playback Volume", IDX_MIXER_AUX, 0x1f, 1),
863 AZF3328_MIXER_SWITCH("Modem Playback Switch", IDX_MIXER_MODEMOUT, 15, 1),
864 AZF3328_MIXER_VOL_MONO("Modem Playback Volume", IDX_MIXER_MODEMOUT, 0x1f, 1),
865 AZF3328_MIXER_SWITCH("Modem Capture Switch", IDX_MIXER_MODEMIN, 15, 1),
866 AZF3328_MIXER_VOL_MONO("Modem Capture Volume", IDX_MIXER_MODEMIN, 0x1f, 1),
Andreas Mohr13769e32006-05-17 11:03:16 +0200867 AZF3328_MIXER_ENUM("Mic Select", IDX_MIXER_ADVCTL2, 2, 8),
868 AZF3328_MIXER_ENUM("Mono Output Select", IDX_MIXER_ADVCTL2, 2, 9),
Andreas Mohre24a1212007-03-26 12:49:45 +0200869 AZF3328_MIXER_ENUM("PCM Output Route", IDX_MIXER_ADVCTL2, 2, 15), /* PCM Out Path, place in front since it controls *both* 3D and Bass/Treble! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Treble", IDX_MIXER_BASSTREBLE, 0x07, 1, 0),
871 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Bass", IDX_MIXER_BASSTREBLE, 0x07, 9, 0),
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200872 AZF3328_MIXER_SWITCH("3D Control - Switch", IDX_MIXER_ADVCTL2, 13, 0),
Andreas Mohr13769e32006-05-17 11:03:16 +0200873 AZF3328_MIXER_VOL_SPECIAL("3D Control - Width", IDX_MIXER_ADVCTL1, 0x07, 1, 0), /* "3D Width" */
874 AZF3328_MIXER_VOL_SPECIAL("3D Control - Depth", IDX_MIXER_ADVCTL1, 0x03, 8, 0), /* "Hifi 3D" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875#if MIXER_TESTING
876 AZF3328_MIXER_SWITCH("0", IDX_MIXER_ADVCTL2, 0, 0),
877 AZF3328_MIXER_SWITCH("1", IDX_MIXER_ADVCTL2, 1, 0),
878 AZF3328_MIXER_SWITCH("2", IDX_MIXER_ADVCTL2, 2, 0),
879 AZF3328_MIXER_SWITCH("3", IDX_MIXER_ADVCTL2, 3, 0),
880 AZF3328_MIXER_SWITCH("4", IDX_MIXER_ADVCTL2, 4, 0),
881 AZF3328_MIXER_SWITCH("5", IDX_MIXER_ADVCTL2, 5, 0),
882 AZF3328_MIXER_SWITCH("6", IDX_MIXER_ADVCTL2, 6, 0),
883 AZF3328_MIXER_SWITCH("7", IDX_MIXER_ADVCTL2, 7, 0),
884 AZF3328_MIXER_SWITCH("8", IDX_MIXER_ADVCTL2, 8, 0),
885 AZF3328_MIXER_SWITCH("9", IDX_MIXER_ADVCTL2, 9, 0),
886 AZF3328_MIXER_SWITCH("10", IDX_MIXER_ADVCTL2, 10, 0),
887 AZF3328_MIXER_SWITCH("11", IDX_MIXER_ADVCTL2, 11, 0),
888 AZF3328_MIXER_SWITCH("12", IDX_MIXER_ADVCTL2, 12, 0),
889 AZF3328_MIXER_SWITCH("13", IDX_MIXER_ADVCTL2, 13, 0),
890 AZF3328_MIXER_SWITCH("14", IDX_MIXER_ADVCTL2, 14, 0),
891 AZF3328_MIXER_SWITCH("15", IDX_MIXER_ADVCTL2, 15, 0),
892#endif
893};
894
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100895static u16 __devinitdata snd_azf3328_init_values[][2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 { IDX_MIXER_PLAY_MASTER, MIXER_MUTE_MASK|0x1f1f },
897 { IDX_MIXER_MODEMOUT, MIXER_MUTE_MASK|0x1f1f },
898 { IDX_MIXER_BASSTREBLE, 0x0000 },
899 { IDX_MIXER_PCBEEP, MIXER_MUTE_MASK|0x1f1f },
900 { IDX_MIXER_MODEMIN, MIXER_MUTE_MASK|0x1f1f },
901 { IDX_MIXER_MIC, MIXER_MUTE_MASK|0x001f },
902 { IDX_MIXER_LINEIN, MIXER_MUTE_MASK|0x1f1f },
903 { IDX_MIXER_CDAUDIO, MIXER_MUTE_MASK|0x1f1f },
904 { IDX_MIXER_VIDEO, MIXER_MUTE_MASK|0x1f1f },
905 { IDX_MIXER_AUX, MIXER_MUTE_MASK|0x1f1f },
906 { IDX_MIXER_WAVEOUT, MIXER_MUTE_MASK|0x1f1f },
907 { IDX_MIXER_FMSYNTH, MIXER_MUTE_MASK|0x1f1f },
908 { IDX_MIXER_REC_VOLUME, MIXER_MUTE_MASK|0x0707 },
909};
910
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200911static int __devinit
Takashi Iwai95de7762005-11-17 15:02:42 +0100912snd_azf3328_mixer_new(struct snd_azf3328 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913{
Takashi Iwai95de7762005-11-17 15:02:42 +0100914 struct snd_card *card;
915 const struct snd_kcontrol_new *sw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 unsigned int idx;
917 int err;
918
919 snd_azf3328_dbgcallenter();
Takashi Iwaida3cec32008-08-08 17:12:14 +0200920 if (snd_BUG_ON(!chip || !chip->card))
921 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
923 card = chip->card;
924
925 /* mixer reset */
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200926 snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 /* mute and zero volume channels */
Andreas Mohr02330fb2008-05-16 12:18:29 +0200929 for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_init_values); ++idx) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200930 snd_azf3328_mixer_outw(chip,
931 snd_azf3328_init_values[idx][0],
932 snd_azf3328_init_values[idx][1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 }
Andreas Mohr02330fb2008-05-16 12:18:29 +0200934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 /* add mixer controls */
936 sw = snd_azf3328_mixer_controls;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200937 for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_mixer_controls);
938 ++idx, ++sw) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(sw, chip))) < 0)
940 return err;
941 }
942 snd_component_add(card, "AZF3328 mixer");
943 strcpy(card->mixername, "AZF3328 mixer");
944
945 snd_azf3328_dbgcallleave();
946 return 0;
947}
948
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200949static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100950snd_azf3328_hw_params(struct snd_pcm_substream *substream,
951 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
953 int res;
954 snd_azf3328_dbgcallenter();
955 res = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
956 snd_azf3328_dbgcallleave();
957 return res;
958}
959
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200960static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100961snd_azf3328_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962{
963 snd_azf3328_dbgcallenter();
964 snd_pcm_lib_free_pages(substream);
965 snd_azf3328_dbgcallleave();
966 return 0;
967}
968
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200969static void
Andreas Mohrda237f32010-12-27 21:17:26 +0100970snd_azf3328_codec_setfmt(struct snd_azf3328_codec_data *codec,
Andreas Mohr627d3e72008-06-23 11:50:47 +0200971 enum azf_freq_t bitrate,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 unsigned int format_width,
973 unsigned int channels
974)
975{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 unsigned long flags;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200977 u16 val = 0xff00;
Andreas Mohr8d9a1142010-12-27 21:16:49 +0100978 u8 freq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 snd_azf3328_dbgcallenter();
981 switch (bitrate) {
Andreas Mohr8d9a1142010-12-27 21:16:49 +0100982#define AZF_FMT_XLATE(in_freq, out_bits) \
983 do { \
984 case AZF_FREQ_ ## in_freq: \
985 freq = SOUNDFORMAT_FREQ_ ## out_bits; \
986 break; \
987 } while (0);
988 AZF_FMT_XLATE(4000, SUSPECTED_4000)
989 AZF_FMT_XLATE(4800, SUSPECTED_4800)
990 /* the AZF3328 names it "5510" for some strange reason: */
991 AZF_FMT_XLATE(5512, 5510)
992 AZF_FMT_XLATE(6620, 6620)
993 AZF_FMT_XLATE(8000, 8000)
994 AZF_FMT_XLATE(9600, 9600)
995 AZF_FMT_XLATE(11025, 11025)
996 AZF_FMT_XLATE(13240, SUSPECTED_13240)
997 AZF_FMT_XLATE(16000, 16000)
998 AZF_FMT_XLATE(22050, 22050)
999 AZF_FMT_XLATE(32000, 32000)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 default:
Takashi Iwai99b359b2005-10-20 18:26:44 +02001001 snd_printk(KERN_WARNING "unknown bitrate %d, assuming 44.1kHz!\n", bitrate);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001002 /* fall-through */
Andreas Mohr8d9a1142010-12-27 21:16:49 +01001003 AZF_FMT_XLATE(44100, 44100)
1004 AZF_FMT_XLATE(48000, 48000)
1005 AZF_FMT_XLATE(66200, SUSPECTED_66200)
1006#undef AZF_FMT_XLATE
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 }
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001008 /* val = 0xff07; 3m27.993s (65301Hz; -> 64000Hz???) hmm, 66120, 65967, 66123 */
1009 /* val = 0xff09; 17m15.098s (13123,478Hz; -> 12000Hz???) hmm, 13237.2Hz? */
1010 /* val = 0xff0a; 47m30.599s (4764,891Hz; -> 4800Hz???) yup, 4803Hz */
1011 /* val = 0xff0c; 57m0.510s (4010,263Hz; -> 4000Hz???) yup, 4003Hz */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 /* val = 0xff05; 5m11.556s (... -> 44100Hz) */
1013 /* val = 0xff03; 10m21.529s (21872,463Hz; -> 22050Hz???) */
1014 /* val = 0xff0f; 20m41.883s (10937,993Hz; -> 11025Hz???) */
1015 /* val = 0xff0d; 41m23.135s (5523,600Hz; -> 5512Hz???) */
1016 /* val = 0xff0e; 28m30.777s (8017Hz; -> 8000Hz???) */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001017
Andreas Mohr8d9a1142010-12-27 21:16:49 +01001018 val |= freq;
1019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 if (channels == 2)
1021 val |= SOUNDFORMAT_FLAG_2CHANNELS;
1022
1023 if (format_width == 16)
1024 val |= SOUNDFORMAT_FLAG_16BIT;
1025
Andreas Mohrda237f32010-12-27 21:17:26 +01001026 spin_lock_irqsave(codec->lock, flags);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001027
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 /* set bitrate/format */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001029 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_SOUNDFORMAT, val);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 /* changing the bitrate/format settings switches off the
1032 * audio output with an annoying click in case of 8/16bit format change
1033 * (maybe shutting down DAC/ADC?), thus immediately
1034 * do some tweaking to reenable it and get rid of the clicking
1035 * (FIXME: yes, it works, but what exactly am I doing here?? :)
1036 * FIXME: does this have some side effects for full-duplex
1037 * or other dramatic side effects? */
Andreas Mohradf59312010-12-27 21:16:43 +01001038 /* do it for non-capture codecs only */
Andreas Mohrda237f32010-12-27 21:17:26 +01001039 if (codec->type != AZF_CODEC_CAPTURE)
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001040 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1041 snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS) |
1042 DMA_RUN_SOMETHING1 |
1043 DMA_RUN_SOMETHING2 |
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001044 SOMETHING_ALMOST_ALWAYS_SET |
1045 DMA_EPILOGUE_SOMETHING |
1046 DMA_SOMETHING_ELSE
1047 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Andreas Mohrda237f32010-12-27 21:17:26 +01001049 spin_unlock_irqrestore(codec->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 snd_azf3328_dbgcallleave();
1051}
1052
Andreas Mohr02330fb2008-05-16 12:18:29 +02001053static inline void
Andreas Mohrda237f32010-12-27 21:17:26 +01001054snd_azf3328_codec_setfmt_lowpower(struct snd_azf3328_codec_data *codec
Andreas Mohr02330fb2008-05-16 12:18:29 +02001055)
1056{
1057 /* choose lowest frequency for low power consumption.
1058 * While this will cause louder noise due to rather coarse frequency,
1059 * it should never matter since output should always
1060 * get disabled properly when idle anyway. */
Andreas Mohrda237f32010-12-27 21:17:26 +01001061 snd_azf3328_codec_setfmt(codec, AZF_FREQ_4000, 8, 1);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001062}
1063
Andreas Mohr627d3e72008-06-23 11:50:47 +02001064static void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001065snd_azf3328_ctrl_reg_6AH_update(struct snd_azf3328 *chip,
Andreas Mohr627d3e72008-06-23 11:50:47 +02001066 unsigned bitmask,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001067 bool enable
Andreas Mohr627d3e72008-06-23 11:50:47 +02001068)
1069{
Andreas Mohr78df6172009-07-12 22:17:54 +02001070 bool do_mask = !enable;
1071 if (do_mask)
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001072 chip->shadow_reg_ctrl_6AH |= bitmask;
Andreas Mohr78df6172009-07-12 22:17:54 +02001073 else
1074 chip->shadow_reg_ctrl_6AH &= ~bitmask;
1075 snd_azf3328_dbgcodec("6AH_update mask 0x%04x do_mask %d: val 0x%04x\n",
1076 bitmask, do_mask, chip->shadow_reg_ctrl_6AH);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001077 snd_azf3328_ctrl_outw(chip, IDX_IO_6AH, chip->shadow_reg_ctrl_6AH);
Andreas Mohr627d3e72008-06-23 11:50:47 +02001078}
1079
Andreas Mohr02330fb2008-05-16 12:18:29 +02001080static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001081snd_azf3328_ctrl_enable_codecs(struct snd_azf3328 *chip, bool enable)
Andreas Mohr02330fb2008-05-16 12:18:29 +02001082{
Andreas Mohr78df6172009-07-12 22:17:54 +02001083 snd_azf3328_dbgcodec("codec_enable %d\n", enable);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001084 /* no idea what exactly is being done here, but I strongly assume it's
1085 * PM related */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001086 snd_azf3328_ctrl_reg_6AH_update(
Andreas Mohr627d3e72008-06-23 11:50:47 +02001087 chip, IO_6A_PAUSE_PLAYBACK_BIT8, enable
Andreas Mohr02330fb2008-05-16 12:18:29 +02001088 );
1089}
1090
1091static void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001092snd_azf3328_ctrl_codec_activity(struct snd_azf3328 *chip,
1093 enum snd_azf3328_codec_type codec_type,
1094 bool enable
Andreas Mohr02330fb2008-05-16 12:18:29 +02001095)
1096{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001097 struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
1098 bool need_change = (codec->running != enable);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001099
Andreas Mohr78df6172009-07-12 22:17:54 +02001100 snd_azf3328_dbgcodec(
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001101 "codec_activity: %s codec, enable %d, need_change %d\n",
1102 codec->name, enable, need_change
Andreas Mohr02330fb2008-05-16 12:18:29 +02001103 );
1104 if (need_change) {
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001105 static const struct {
1106 enum snd_azf3328_codec_type other1;
1107 enum snd_azf3328_codec_type other2;
1108 } peer_codecs[3] =
1109 { { AZF_CODEC_CAPTURE, AZF_CODEC_I2S_OUT },
1110 { AZF_CODEC_PLAYBACK, AZF_CODEC_I2S_OUT },
1111 { AZF_CODEC_PLAYBACK, AZF_CODEC_CAPTURE } };
1112 bool call_function;
1113
1114 if (enable)
1115 /* if enable codec, call enable_codecs func
1116 to enable codec supply... */
1117 call_function = 1;
1118 else {
1119 /* ...otherwise call enable_codecs func
1120 (which globally shuts down operation of codecs)
1121 only in case the other codecs are currently
1122 not active either! */
Andreas Mohr78df6172009-07-12 22:17:54 +02001123 call_function =
1124 ((!chip->codecs[peer_codecs[codec_type].other1]
1125 .running)
1126 && (!chip->codecs[peer_codecs[codec_type].other2]
1127 .running));
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001128 }
1129 if (call_function)
1130 snd_azf3328_ctrl_enable_codecs(chip, enable);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001131
1132 /* ...and adjust clock, too
1133 * (reduce noise and power consumption) */
1134 if (!enable)
Andreas Mohrda237f32010-12-27 21:17:26 +01001135 snd_azf3328_codec_setfmt_lowpower(codec);
Andreas Mohr78df6172009-07-12 22:17:54 +02001136 codec->running = enable;
Andreas Mohr02330fb2008-05-16 12:18:29 +02001137 }
Andreas Mohr02330fb2008-05-16 12:18:29 +02001138}
1139
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001140static void
Andreas Mohrda237f32010-12-27 21:17:26 +01001141snd_azf3328_codec_setdmaa(struct snd_azf3328_codec_data *codec,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001142 unsigned long addr,
Andreas Mohr689c6912010-12-27 21:17:35 +01001143 unsigned int period_bytes,
1144 unsigned int buffer_bytes
Andreas Mohr02330fb2008-05-16 12:18:29 +02001145)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 snd_azf3328_dbgcallenter();
Andreas Mohr689c6912010-12-27 21:17:35 +01001148 WARN_ONCE(period_bytes & 1, "odd period length!?\n");
1149 WARN_ONCE(buffer_bytes != 2 * period_bytes,
1150 "missed our input expectations! %u vs. %u\n",
1151 buffer_bytes, period_bytes);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001152 if (!codec->running) {
1153 /* AZF3328 uses a two buffer pointer DMA transfer approach */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001154
Andreas Mohr689c6912010-12-27 21:17:35 +01001155 unsigned long flags;
Andreas Mohr02330fb2008-05-16 12:18:29 +02001156
1157 /* width 32bit (prevent overflow): */
Andreas Mohr689c6912010-12-27 21:17:35 +01001158 u32 area_length;
1159 struct codec_setup_io {
1160 u32 dma_start_1;
1161 u32 dma_start_2;
1162 u32 dma_lengths;
1163 } __attribute__((packed)) setup_io;
Andreas Mohr02330fb2008-05-16 12:18:29 +02001164
Andreas Mohr689c6912010-12-27 21:17:35 +01001165 area_length = buffer_bytes/2;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001166
Andreas Mohr689c6912010-12-27 21:17:35 +01001167 setup_io.dma_start_1 = addr;
1168 setup_io.dma_start_2 = addr+area_length;
1169
1170 snd_azf3328_dbgcodec(
1171 "setdma: buffers %08x[%u] / %08x[%u], %u, %u\n",
1172 setup_io.dma_start_1, area_length,
1173 setup_io.dma_start_2, area_length,
1174 period_bytes, buffer_bytes);
1175
1176 /* Hmm, are we really supposed to decrement this by 1??
1177 Most definitely certainly not: configuring full length does
1178 work properly (i.e. likely better), and BTW we
1179 violated possibly differing frame sizes with this...
1180
1181 area_length--; |* max. index *|
1182 */
Andreas Mohr79741502010-11-21 12:09:32 +01001183
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001184 /* build combined I/O buffer length word */
Andreas Mohr689c6912010-12-27 21:17:35 +01001185 setup_io.dma_lengths = (area_length << 16) | (area_length);
1186
Andreas Mohrda237f32010-12-27 21:17:26 +01001187 spin_lock_irqsave(codec->lock, flags);
Andreas Mohr689c6912010-12-27 21:17:35 +01001188 snd_azf3328_codec_outl_multi(
1189 codec, IDX_IO_CODEC_DMA_START_1, &setup_io, 3
1190 );
Andreas Mohrda237f32010-12-27 21:17:26 +01001191 spin_unlock_irqrestore(codec->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 }
1193 snd_azf3328_dbgcallleave();
1194}
1195
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001196static int
Andreas Mohrda237f32010-12-27 21:17:26 +01001197snd_azf3328_pcm_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198{
Takashi Iwai95de7762005-11-17 15:02:42 +01001199 struct snd_pcm_runtime *runtime = substream->runtime;
Andreas Mohrda237f32010-12-27 21:17:26 +01001200 struct snd_azf3328_codec_data *codec = runtime->private_data;
Andreas Mohr34585592010-12-27 21:17:11 +01001201#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
1203 unsigned int count = snd_pcm_lib_period_bytes(substream);
1204#endif
1205
1206 snd_azf3328_dbgcallenter();
Andreas Mohr34585592010-12-27 21:17:11 +01001207
1208 codec->dma_base = runtime->dma_addr;
1209
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210#if 0
Andreas Mohrda237f32010-12-27 21:17:26 +01001211 snd_azf3328_codec_setfmt(codec,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001212 runtime->rate,
1213 snd_pcm_format_width(runtime->format),
1214 runtime->channels);
Andreas Mohrda237f32010-12-27 21:17:26 +01001215 snd_azf3328_codec_setdmaa(codec,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001216 runtime->dma_addr, count, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217#endif
1218 snd_azf3328_dbgcallleave();
1219 return 0;
1220}
1221
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001222static int
Andreas Mohrda237f32010-12-27 21:17:26 +01001223snd_azf3328_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
Takashi Iwai95de7762005-11-17 15:02:42 +01001225 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1226 struct snd_pcm_runtime *runtime = substream->runtime;
Andreas Mohrda237f32010-12-27 21:17:26 +01001227 struct snd_azf3328_codec_data *codec = runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 int result = 0;
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001229 u16 flags1;
1230 bool previously_muted = 0;
Andreas Mohrda237f32010-12-27 21:17:26 +01001231 bool is_main_mixer_playback_codec = (AZF_CODEC_PLAYBACK == codec->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Andreas Mohrda237f32010-12-27 21:17:26 +01001233 snd_azf3328_dbgcalls("snd_azf3328_pcm_trigger cmd %d\n", cmd);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001234
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 switch (cmd) {
1236 case SNDRV_PCM_TRIGGER_START:
Andreas Mohr78df6172009-07-12 22:17:54 +02001237 snd_azf3328_dbgcodec("START %s\n", codec->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
Andreas Mohrda237f32010-12-27 21:17:26 +01001239 if (is_main_mixer_playback_codec) {
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001240 /* mute WaveOut (avoid clicking during setup) */
1241 previously_muted =
1242 snd_azf3328_mixer_set_mute(
1243 chip, IDX_MIXER_WAVEOUT, 1
1244 );
1245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
Andreas Mohrda237f32010-12-27 21:17:26 +01001247 snd_azf3328_codec_setfmt(codec,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001248 runtime->rate,
1249 snd_pcm_format_width(runtime->format),
1250 runtime->channels);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Andreas Mohrda237f32010-12-27 21:17:26 +01001252 spin_lock(codec->lock);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001253 /* first, remember current value: */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001254 flags1 = snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001255
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001256 /* stop transfer */
1257 flags1 &= ~DMA_RESUME;
1258 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001259
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 /* FIXME: clear interrupts or what??? */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001261 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_IRQTYPE, 0xffff);
Andreas Mohrda237f32010-12-27 21:17:26 +01001262 spin_unlock(codec->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Andreas Mohrda237f32010-12-27 21:17:26 +01001264 snd_azf3328_codec_setdmaa(codec, runtime->dma_addr,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001265 snd_pcm_lib_period_bytes(substream),
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001266 snd_pcm_lib_buffer_bytes(substream)
1267 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
Andreas Mohrda237f32010-12-27 21:17:26 +01001269 spin_lock(codec->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270#ifdef WIN9X
1271 /* FIXME: enable playback/recording??? */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001272 flags1 |= DMA_RUN_SOMETHING1 | DMA_RUN_SOMETHING2;
1273 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001275 /* start transfer again */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 /* FIXME: what is this value (0x0010)??? */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001277 flags1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING;
1278 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279#else /* NT4 */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001280 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001281 0x0000);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001282 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1283 DMA_RUN_SOMETHING1);
1284 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1285 DMA_RUN_SOMETHING1 |
1286 DMA_RUN_SOMETHING2);
1287 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001288 DMA_RESUME |
1289 SOMETHING_ALMOST_ALWAYS_SET |
1290 DMA_EPILOGUE_SOMETHING |
1291 DMA_SOMETHING_ELSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292#endif
Andreas Mohrda237f32010-12-27 21:17:26 +01001293 spin_unlock(codec->lock);
1294 snd_azf3328_ctrl_codec_activity(chip, codec->type, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Andreas Mohrda237f32010-12-27 21:17:26 +01001296 if (is_main_mixer_playback_codec) {
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001297 /* now unmute WaveOut */
1298 if (!previously_muted)
1299 snd_azf3328_mixer_set_mute(
1300 chip, IDX_MIXER_WAVEOUT, 0
1301 );
1302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Andreas Mohr78df6172009-07-12 22:17:54 +02001304 snd_azf3328_dbgcodec("STARTED %s\n", codec->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 break;
Andreas Mohrca54bde2006-05-17 11:02:24 +02001306 case SNDRV_PCM_TRIGGER_RESUME:
Andreas Mohr78df6172009-07-12 22:17:54 +02001307 snd_azf3328_dbgcodec("RESUME %s\n", codec->name);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001308 /* resume codec if we were active */
Andreas Mohrda237f32010-12-27 21:17:26 +01001309 spin_lock(codec->lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001310 if (codec->running)
1311 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1312 snd_azf3328_codec_inw(
1313 codec, IDX_IO_CODEC_DMA_FLAGS
1314 ) | DMA_RESUME
1315 );
Andreas Mohrda237f32010-12-27 21:17:26 +01001316 spin_unlock(codec->lock);
Andreas Mohrca54bde2006-05-17 11:02:24 +02001317 break;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001318 case SNDRV_PCM_TRIGGER_STOP:
Andreas Mohr78df6172009-07-12 22:17:54 +02001319 snd_azf3328_dbgcodec("STOP %s\n", codec->name);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001320
Andreas Mohrda237f32010-12-27 21:17:26 +01001321 if (is_main_mixer_playback_codec) {
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001322 /* mute WaveOut (avoid clicking during setup) */
1323 previously_muted =
1324 snd_azf3328_mixer_set_mute(
1325 chip, IDX_MIXER_WAVEOUT, 1
1326 );
1327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
Andreas Mohrda237f32010-12-27 21:17:26 +01001329 spin_lock(codec->lock);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001330 /* first, remember current value: */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001331 flags1 = snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001333 /* stop transfer */
1334 flags1 &= ~DMA_RESUME;
1335 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001337 /* hmm, is this really required? we're resetting the same bit
1338 * immediately thereafter... */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001339 flags1 |= DMA_RUN_SOMETHING1;
1340 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001342 flags1 &= ~DMA_RUN_SOMETHING1;
1343 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Andreas Mohrda237f32010-12-27 21:17:26 +01001344 spin_unlock(codec->lock);
1345 snd_azf3328_ctrl_codec_activity(chip, codec->type, 0);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001346
Andreas Mohrda237f32010-12-27 21:17:26 +01001347 if (is_main_mixer_playback_codec) {
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001348 /* now unmute WaveOut */
1349 if (!previously_muted)
1350 snd_azf3328_mixer_set_mute(
1351 chip, IDX_MIXER_WAVEOUT, 0
1352 );
1353 }
Andreas Mohr02330fb2008-05-16 12:18:29 +02001354
Andreas Mohr78df6172009-07-12 22:17:54 +02001355 snd_azf3328_dbgcodec("STOPPED %s\n", codec->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 break;
Andreas Mohrca54bde2006-05-17 11:02:24 +02001357 case SNDRV_PCM_TRIGGER_SUSPEND:
Andreas Mohr78df6172009-07-12 22:17:54 +02001358 snd_azf3328_dbgcodec("SUSPEND %s\n", codec->name);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001359 /* make sure codec is stopped */
1360 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1361 snd_azf3328_codec_inw(
1362 codec, IDX_IO_CODEC_DMA_FLAGS
1363 ) & ~DMA_RESUME
1364 );
Andreas Mohrca54bde2006-05-17 11:02:24 +02001365 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Takashi Iwai99b359b2005-10-20 18:26:44 +02001367 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 break;
1369 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Takashi Iwai99b359b2005-10-20 18:26:44 +02001370 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 break;
1372 default:
Andreas Mohr78df6172009-07-12 22:17:54 +02001373 snd_printk(KERN_ERR "FIXME: unknown trigger mode!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 return -EINVAL;
1375 }
Andreas Mohr02330fb2008-05-16 12:18:29 +02001376
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 snd_azf3328_dbgcallleave();
1378 return result;
1379}
1380
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001381static snd_pcm_uframes_t
Andreas Mohrda237f32010-12-27 21:17:26 +01001382snd_azf3328_pcm_pointer(struct snd_pcm_substream *substream
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001383)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384{
Andreas Mohrda237f32010-12-27 21:17:26 +01001385 const struct snd_azf3328_codec_data *codec =
1386 substream->runtime->private_data;
Andreas Mohr34585592010-12-27 21:17:11 +01001387 unsigned long result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 snd_pcm_uframes_t frmres;
1389
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001390 result = snd_azf3328_codec_inl(codec, IDX_IO_CODEC_DMA_CURRPOS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001392 /* calculate offset */
Andreas Mohr34585592010-12-27 21:17:11 +01001393#ifdef QUERY_HARDWARE
1394 result -= snd_azf3328_codec_inl(codec, IDX_IO_CODEC_DMA_START_1);
1395#else
1396 result -= codec->dma_base;
1397#endif
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001398 frmres = bytes_to_frames( substream->runtime, result);
Andreas Mohradf59312010-12-27 21:16:43 +01001399 snd_azf3328_dbgcodec("%08li %s @ 0x%8lx, frames %8ld\n",
1400 jiffies, codec->name, result, frmres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 return frmres;
1402}
1403
Andreas Mohr02330fb2008-05-16 12:18:29 +02001404/******************************************************************/
1405
1406#ifdef SUPPORT_GAMEPORT
1407static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001408snd_azf3328_gameport_irq_enable(struct snd_azf3328 *chip,
1409 bool enable
1410)
Andreas Mohr02330fb2008-05-16 12:18:29 +02001411{
1412 snd_azf3328_io_reg_setb(
1413 chip->game_io+IDX_GAME_HWCONFIG,
1414 GAME_HWCFG_IRQ_ENABLE,
1415 enable
1416 );
1417}
1418
1419static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001420snd_azf3328_gameport_legacy_address_enable(struct snd_azf3328 *chip,
1421 bool enable
1422)
Andreas Mohr02330fb2008-05-16 12:18:29 +02001423{
1424 snd_azf3328_io_reg_setb(
1425 chip->game_io+IDX_GAME_HWCONFIG,
1426 GAME_HWCFG_LEGACY_ADDRESS_ENABLE,
1427 enable
1428 );
1429}
1430
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001431static void
1432snd_azf3328_gameport_set_counter_frequency(struct snd_azf3328 *chip,
1433 unsigned int freq_cfg
1434)
Andreas Mohr02330fb2008-05-16 12:18:29 +02001435{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001436 snd_azf3328_io_reg_setb(
1437 chip->game_io+IDX_GAME_HWCONFIG,
1438 0x02,
1439 (freq_cfg & 1) != 0
1440 );
1441 snd_azf3328_io_reg_setb(
1442 chip->game_io+IDX_GAME_HWCONFIG,
1443 0x04,
1444 (freq_cfg & 2) != 0
1445 );
1446}
1447
1448static inline void
1449snd_azf3328_gameport_axis_circuit_enable(struct snd_azf3328 *chip, bool enable)
1450{
1451 snd_azf3328_ctrl_reg_6AH_update(
Andreas Mohr627d3e72008-06-23 11:50:47 +02001452 chip, IO_6A_SOMETHING2_GAMEPORT, enable
Andreas Mohr02330fb2008-05-16 12:18:29 +02001453 );
1454}
1455
1456static inline void
1457snd_azf3328_gameport_interrupt(struct snd_azf3328 *chip)
1458{
1459 /*
1460 * skeleton handler only
1461 * (we do not want axis reading in interrupt handler - too much load!)
1462 */
1463 snd_azf3328_dbggame("gameport irq\n");
1464
1465 /* this should ACK the gameport IRQ properly, hopefully. */
1466 snd_azf3328_game_inw(chip, IDX_GAME_AXIS_VALUE);
1467}
1468
1469static int
1470snd_azf3328_gameport_open(struct gameport *gameport, int mode)
1471{
1472 struct snd_azf3328 *chip = gameport_get_port_data(gameport);
1473 int res;
1474
1475 snd_azf3328_dbggame("gameport_open, mode %d\n", mode);
1476 switch (mode) {
1477 case GAMEPORT_MODE_COOKED:
1478 case GAMEPORT_MODE_RAW:
1479 res = 0;
1480 break;
1481 default:
1482 res = -1;
1483 break;
1484 }
1485
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001486 snd_azf3328_gameport_set_counter_frequency(chip,
1487 GAME_HWCFG_ADC_COUNTER_FREQ_STD);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001488 snd_azf3328_gameport_axis_circuit_enable(chip, (res == 0));
1489
1490 return res;
1491}
1492
1493static void
1494snd_azf3328_gameport_close(struct gameport *gameport)
1495{
1496 struct snd_azf3328 *chip = gameport_get_port_data(gameport);
1497
1498 snd_azf3328_dbggame("gameport_close\n");
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001499 snd_azf3328_gameport_set_counter_frequency(chip,
1500 GAME_HWCFG_ADC_COUNTER_FREQ_1_200);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001501 snd_azf3328_gameport_axis_circuit_enable(chip, 0);
1502}
1503
1504static int
1505snd_azf3328_gameport_cooked_read(struct gameport *gameport,
1506 int *axes,
1507 int *buttons
1508)
1509{
1510 struct snd_azf3328 *chip = gameport_get_port_data(gameport);
1511 int i;
1512 u8 val;
1513 unsigned long flags;
1514
Takashi Iwaida3cec32008-08-08 17:12:14 +02001515 if (snd_BUG_ON(!chip))
1516 return 0;
Andreas Mohr02330fb2008-05-16 12:18:29 +02001517
1518 spin_lock_irqsave(&chip->reg_lock, flags);
1519 val = snd_azf3328_game_inb(chip, IDX_GAME_LEGACY_COMPATIBLE);
1520 *buttons = (~(val) >> 4) & 0xf;
1521
1522 /* ok, this one is a bit dirty: cooked_read is being polled by a timer,
1523 * thus we're atomic and cannot actively wait in here
1524 * (which would be useful for us since it probably would be better
1525 * to trigger a measurement in here, then wait a short amount of
1526 * time until it's finished, then read values of _this_ measurement).
1527 *
1528 * Thus we simply resort to reading values if they're available already
1529 * and trigger the next measurement.
1530 */
1531
1532 val = snd_azf3328_game_inb(chip, IDX_GAME_AXES_CONFIG);
1533 if (val & GAME_AXES_SAMPLING_READY) {
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001534 for (i = 0; i < ARRAY_SIZE(chip->axes); ++i) {
Andreas Mohr02330fb2008-05-16 12:18:29 +02001535 /* configure the axis to read */
1536 val = (i << 4) | 0x0f;
1537 snd_azf3328_game_outb(chip, IDX_GAME_AXES_CONFIG, val);
1538
1539 chip->axes[i] = snd_azf3328_game_inw(
1540 chip, IDX_GAME_AXIS_VALUE
1541 );
1542 }
1543 }
1544
Andreas Mohradf59312010-12-27 21:16:43 +01001545 /* trigger next sampling of axes, to be evaluated the next time we
Andreas Mohr02330fb2008-05-16 12:18:29 +02001546 * enter this function */
1547
1548 /* for some very, very strange reason we cannot enable
1549 * Measurement Ready monitoring for all axes here,
1550 * at least not when only one joystick connected */
1551 val = 0x03; /* we're able to monitor axes 1 and 2 only */
1552 snd_azf3328_game_outb(chip, IDX_GAME_AXES_CONFIG, val);
1553
1554 snd_azf3328_game_outw(chip, IDX_GAME_AXIS_VALUE, 0xffff);
1555 spin_unlock_irqrestore(&chip->reg_lock, flags);
1556
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001557 for (i = 0; i < ARRAY_SIZE(chip->axes); i++) {
Andreas Mohr02330fb2008-05-16 12:18:29 +02001558 axes[i] = chip->axes[i];
1559 if (axes[i] == 0xffff)
1560 axes[i] = -1;
1561 }
1562
1563 snd_azf3328_dbggame("cooked_read: axes %d %d %d %d buttons %d\n",
1564 axes[0], axes[1], axes[2], axes[3], *buttons
1565 );
1566
1567 return 0;
1568}
1569
1570static int __devinit
1571snd_azf3328_gameport(struct snd_azf3328 *chip, int dev)
1572{
1573 struct gameport *gp;
1574
Andreas Mohr02330fb2008-05-16 12:18:29 +02001575 chip->gameport = gp = gameport_allocate_port();
1576 if (!gp) {
1577 printk(KERN_ERR "azt3328: cannot alloc memory for gameport\n");
1578 return -ENOMEM;
1579 }
1580
1581 gameport_set_name(gp, "AZF3328 Gameport");
1582 gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
1583 gameport_set_dev_parent(gp, &chip->pci->dev);
Andreas Mohr627d3e72008-06-23 11:50:47 +02001584 gp->io = chip->game_io;
Andreas Mohr02330fb2008-05-16 12:18:29 +02001585 gameport_set_port_data(gp, chip);
1586
1587 gp->open = snd_azf3328_gameport_open;
1588 gp->close = snd_azf3328_gameport_close;
1589 gp->fuzz = 16; /* seems ok */
1590 gp->cooked_read = snd_azf3328_gameport_cooked_read;
1591
1592 /* DISABLE legacy address: we don't need it! */
1593 snd_azf3328_gameport_legacy_address_enable(chip, 0);
1594
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001595 snd_azf3328_gameport_set_counter_frequency(chip,
1596 GAME_HWCFG_ADC_COUNTER_FREQ_1_200);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001597 snd_azf3328_gameport_axis_circuit_enable(chip, 0);
1598
1599 gameport_register_port(chip->gameport);
1600
1601 return 0;
1602}
1603
1604static void
1605snd_azf3328_gameport_free(struct snd_azf3328 *chip)
1606{
1607 if (chip->gameport) {
1608 gameport_unregister_port(chip->gameport);
1609 chip->gameport = NULL;
1610 }
1611 snd_azf3328_gameport_irq_enable(chip, 0);
1612}
1613#else
1614static inline int
1615snd_azf3328_gameport(struct snd_azf3328 *chip, int dev) { return -ENOSYS; }
1616static inline void
1617snd_azf3328_gameport_free(struct snd_azf3328 *chip) { }
1618static inline void
1619snd_azf3328_gameport_interrupt(struct snd_azf3328 *chip)
1620{
1621 printk(KERN_WARNING "huh, game port IRQ occurred!?\n");
1622}
1623#endif /* SUPPORT_GAMEPORT */
1624
1625/******************************************************************/
1626
Andreas Mohr627d3e72008-06-23 11:50:47 +02001627static inline void
1628snd_azf3328_irq_log_unknown_type(u8 which)
1629{
Andreas Mohr78df6172009-07-12 22:17:54 +02001630 snd_azf3328_dbgcodec(
Andreas Mohr627d3e72008-06-23 11:50:47 +02001631 "azt3328: unknown IRQ type (%x) occurred, please report!\n",
1632 which
1633 );
1634}
1635
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001636static inline void
Andreas Mohrda237f32010-12-27 21:17:26 +01001637snd_azf3328_pcm_interrupt(const struct snd_azf3328_codec_data *first_codec,
1638 u8 status
1639)
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001640{
1641 u8 which;
1642 enum snd_azf3328_codec_type codec_type;
Andreas Mohrda237f32010-12-27 21:17:26 +01001643 const struct snd_azf3328_codec_data *codec = first_codec;
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001644
1645 for (codec_type = AZF_CODEC_PLAYBACK;
1646 codec_type <= AZF_CODEC_I2S_OUT;
Andreas Mohrda237f32010-12-27 21:17:26 +01001647 ++codec_type, ++codec) {
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001648
1649 /* skip codec if there's no interrupt for it */
1650 if (!(status & (1 << codec_type)))
1651 continue;
1652
Andreas Mohrda237f32010-12-27 21:17:26 +01001653 spin_lock(codec->lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001654 which = snd_azf3328_codec_inb(codec, IDX_IO_CODEC_IRQTYPE);
1655 /* ack all IRQ types immediately */
1656 snd_azf3328_codec_outb(codec, IDX_IO_CODEC_IRQTYPE, which);
Andreas Mohrda237f32010-12-27 21:17:26 +01001657 spin_unlock(codec->lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001658
Andreas Mohrda237f32010-12-27 21:17:26 +01001659 if (codec->substream) {
Andreas Mohr78df6172009-07-12 22:17:54 +02001660 snd_pcm_period_elapsed(codec->substream);
1661 snd_azf3328_dbgcodec("%s period done (#%x), @ %x\n",
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001662 codec->name,
1663 which,
1664 snd_azf3328_codec_inl(
1665 codec, IDX_IO_CODEC_DMA_CURRPOS
1666 )
1667 );
1668 } else
1669 printk(KERN_WARNING "azt3328: irq handler problem!\n");
1670 if (which & IRQ_SOMETHING)
1671 snd_azf3328_irq_log_unknown_type(which);
1672 }
1673}
1674
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001675static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001676snd_azf3328_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677{
Takashi Iwai95de7762005-11-17 15:02:42 +01001678 struct snd_azf3328 *chip = dev_id;
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001679 u8 status;
Andreas Mohr78df6172009-07-12 22:17:54 +02001680#if DEBUG_CODEC
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001681 static unsigned long irq_count;
Andreas Mohr02330fb2008-05-16 12:18:29 +02001682#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001684 status = snd_azf3328_ctrl_inb(chip, IDX_IO_IRQSTATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
1686 /* fast path out, to ease interrupt sharing */
Andreas Mohr02330fb2008-05-16 12:18:29 +02001687 if (!(status &
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001688 (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_I2S_OUT
1689 |IRQ_GAMEPORT|IRQ_MPU401|IRQ_TIMER)
Andreas Mohr02330fb2008-05-16 12:18:29 +02001690 ))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 return IRQ_NONE; /* must be interrupt for another device */
1692
Andreas Mohr78df6172009-07-12 22:17:54 +02001693 snd_azf3328_dbgcodec(
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001694 "irq_count %ld! IDX_IO_IRQSTATUS %04x\n",
Andreas Mohr627d3e72008-06-23 11:50:47 +02001695 irq_count++ /* debug-only */,
Andreas Mohr627d3e72008-06-23 11:50:47 +02001696 status
1697 );
Andreas Mohr02330fb2008-05-16 12:18:29 +02001698
Andreas Mohre2f87262006-05-17 11:04:19 +02001699 if (status & IRQ_TIMER) {
Andreas Mohr78df6172009-07-12 22:17:54 +02001700 /* snd_azf3328_dbgcodec("timer %ld\n",
Andreas Mohr02330fb2008-05-16 12:18:29 +02001701 snd_azf3328_codec_inl(chip, IDX_IO_TIMER_VALUE)
1702 & TIMER_VALUE_MASK
1703 ); */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001704 if (chip->timer)
1705 snd_timer_interrupt(chip->timer, chip->timer->sticks);
1706 /* ACK timer */
1707 spin_lock(&chip->reg_lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001708 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x07);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001709 spin_unlock(&chip->reg_lock);
Andreas Mohr78df6172009-07-12 22:17:54 +02001710 snd_azf3328_dbgcodec("azt3328: timer IRQ\n");
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001711 }
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001712
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001713 if (status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_I2S_OUT))
Andreas Mohrda237f32010-12-27 21:17:26 +01001714 snd_azf3328_pcm_interrupt(chip->codecs, status);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001715
Andreas Mohr02330fb2008-05-16 12:18:29 +02001716 if (status & IRQ_GAMEPORT)
1717 snd_azf3328_gameport_interrupt(chip);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001718
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001719 /* MPU401 has less critical IRQ requirements
1720 * than timer and playback/recording, right? */
Andreas Mohre2f87262006-05-17 11:04:19 +02001721 if (status & IRQ_MPU401) {
David Howells7d12e782006-10-05 14:55:46 +01001722 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001723
1724 /* hmm, do we have to ack the IRQ here somehow?
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001725 * If so, then I don't know how yet... */
Andreas Mohr78df6172009-07-12 22:17:54 +02001726 snd_azf3328_dbgcodec("azt3328: MPU401 IRQ\n");
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001727 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 return IRQ_HANDLED;
1729}
1730
1731/*****************************************************************/
1732
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001733/* as long as we think we have identical snd_pcm_hardware parameters
1734 for playback, capture and i2s out, we can use the same physical struct
1735 since the struct is simply being copied into a member.
1736*/
1737static const struct snd_pcm_hardware snd_azf3328_hardware =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738{
1739 /* FIXME!! Correct? */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001740 .info = SNDRV_PCM_INFO_MMAP |
1741 SNDRV_PCM_INFO_INTERLEAVED |
1742 SNDRV_PCM_INFO_MMAP_VALID,
1743 .formats = SNDRV_PCM_FMTBIT_S8 |
1744 SNDRV_PCM_FMTBIT_U8 |
1745 SNDRV_PCM_FMTBIT_S16_LE |
1746 SNDRV_PCM_FMTBIT_U16_LE,
1747 .rates = SNDRV_PCM_RATE_5512 |
1748 SNDRV_PCM_RATE_8000_48000 |
1749 SNDRV_PCM_RATE_KNOT,
Andreas Mohr02330fb2008-05-16 12:18:29 +02001750 .rate_min = AZF_FREQ_4000,
1751 .rate_max = AZF_FREQ_66200,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 .channels_min = 1,
1753 .channels_max = 2,
Andreas Mohr79741502010-11-21 12:09:32 +01001754 .buffer_bytes_max = (64*1024),
1755 .period_bytes_min = 1024,
1756 .period_bytes_max = (32*1024),
1757 /* We simply have two DMA areas (instead of a list of descriptors
1758 such as other cards); I believe that this is a fixed hardware
1759 attribute and there isn't much driver magic to be done to expand it.
1760 Thus indicate that we have at least and at most 2 periods. */
1761 .periods_min = 2,
1762 .periods_max = 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 /* FIXME: maybe that card actually has a FIFO?
1764 * Hmm, it seems newer revisions do have one, but we still don't know
1765 * its size... */
1766 .fifo_size = 0,
1767};
1768
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
1770static unsigned int snd_azf3328_fixed_rates[] = {
Andreas Mohr02330fb2008-05-16 12:18:29 +02001771 AZF_FREQ_4000,
1772 AZF_FREQ_4800,
1773 AZF_FREQ_5512,
1774 AZF_FREQ_6620,
1775 AZF_FREQ_8000,
1776 AZF_FREQ_9600,
1777 AZF_FREQ_11025,
1778 AZF_FREQ_13240,
1779 AZF_FREQ_16000,
1780 AZF_FREQ_22050,
1781 AZF_FREQ_32000,
1782 AZF_FREQ_44100,
1783 AZF_FREQ_48000,
1784 AZF_FREQ_66200
1785};
1786
Takashi Iwai95de7762005-11-17 15:02:42 +01001787static struct snd_pcm_hw_constraint_list snd_azf3328_hw_constraints_rates = {
Andreas Mohr02330fb2008-05-16 12:18:29 +02001788 .count = ARRAY_SIZE(snd_azf3328_fixed_rates),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 .list = snd_azf3328_fixed_rates,
1790 .mask = 0,
1791};
1792
1793/*****************************************************************/
1794
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001795static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001796snd_azf3328_pcm_open(struct snd_pcm_substream *substream,
1797 enum snd_azf3328_codec_type codec_type
1798)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799{
Takashi Iwai95de7762005-11-17 15:02:42 +01001800 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1801 struct snd_pcm_runtime *runtime = substream->runtime;
Andreas Mohrda237f32010-12-27 21:17:26 +01001802 struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
1804 snd_azf3328_dbgcallenter();
Andreas Mohrda237f32010-12-27 21:17:26 +01001805 codec->substream = substream;
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001806
1807 /* same parameters for all our codecs - at least we think so... */
1808 runtime->hw = snd_azf3328_hardware;
1809
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1811 &snd_azf3328_hw_constraints_rates);
Andreas Mohrda237f32010-12-27 21:17:26 +01001812 runtime->private_data = codec;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 snd_azf3328_dbgcallleave();
1814 return 0;
1815}
1816
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001817static int
Andreas Mohrda237f32010-12-27 21:17:26 +01001818snd_azf3328_pcm_playback_open(struct snd_pcm_substream *substream)
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001819{
1820 return snd_azf3328_pcm_open(substream, AZF_CODEC_PLAYBACK);
1821}
1822
1823static int
Andreas Mohrda237f32010-12-27 21:17:26 +01001824snd_azf3328_pcm_capture_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001826 return snd_azf3328_pcm_open(substream, AZF_CODEC_CAPTURE);
1827}
1828
1829static int
Andreas Mohrda237f32010-12-27 21:17:26 +01001830snd_azf3328_pcm_i2s_out_open(struct snd_pcm_substream *substream)
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001831{
1832 return snd_azf3328_pcm_open(substream, AZF_CODEC_I2S_OUT);
1833}
1834
1835static int
Andreas Mohrda237f32010-12-27 21:17:26 +01001836snd_azf3328_pcm_close(struct snd_pcm_substream *substream
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001837)
1838{
Andreas Mohrda237f32010-12-27 21:17:26 +01001839 struct snd_azf3328_codec_data *codec =
1840 substream->runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841
1842 snd_azf3328_dbgcallenter();
Andreas Mohrda237f32010-12-27 21:17:26 +01001843 codec->substream = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 snd_azf3328_dbgcallleave();
1845 return 0;
1846}
1847
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848/******************************************************************/
1849
Takashi Iwai95de7762005-11-17 15:02:42 +01001850static struct snd_pcm_ops snd_azf3328_playback_ops = {
Andreas Mohrda237f32010-12-27 21:17:26 +01001851 .open = snd_azf3328_pcm_playback_open,
1852 .close = snd_azf3328_pcm_close,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 .ioctl = snd_pcm_lib_ioctl,
1854 .hw_params = snd_azf3328_hw_params,
1855 .hw_free = snd_azf3328_hw_free,
Andreas Mohrda237f32010-12-27 21:17:26 +01001856 .prepare = snd_azf3328_pcm_prepare,
1857 .trigger = snd_azf3328_pcm_trigger,
1858 .pointer = snd_azf3328_pcm_pointer
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859};
1860
Takashi Iwai95de7762005-11-17 15:02:42 +01001861static struct snd_pcm_ops snd_azf3328_capture_ops = {
Andreas Mohrda237f32010-12-27 21:17:26 +01001862 .open = snd_azf3328_pcm_capture_open,
1863 .close = snd_azf3328_pcm_close,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 .ioctl = snd_pcm_lib_ioctl,
1865 .hw_params = snd_azf3328_hw_params,
1866 .hw_free = snd_azf3328_hw_free,
Andreas Mohrda237f32010-12-27 21:17:26 +01001867 .prepare = snd_azf3328_pcm_prepare,
1868 .trigger = snd_azf3328_pcm_trigger,
1869 .pointer = snd_azf3328_pcm_pointer
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001870};
1871
1872static struct snd_pcm_ops snd_azf3328_i2s_out_ops = {
Andreas Mohrda237f32010-12-27 21:17:26 +01001873 .open = snd_azf3328_pcm_i2s_out_open,
1874 .close = snd_azf3328_pcm_close,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001875 .ioctl = snd_pcm_lib_ioctl,
1876 .hw_params = snd_azf3328_hw_params,
1877 .hw_free = snd_azf3328_hw_free,
Andreas Mohrda237f32010-12-27 21:17:26 +01001878 .prepare = snd_azf3328_pcm_prepare,
1879 .trigger = snd_azf3328_pcm_trigger,
1880 .pointer = snd_azf3328_pcm_pointer
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881};
1882
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001883static int __devinit
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001884snd_azf3328_pcm(struct snd_azf3328 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001886enum { AZF_PCMDEV_STD, AZF_PCMDEV_I2S_OUT, NUM_AZF_PCMDEVS }; /* pcm devices */
1887
Takashi Iwai95de7762005-11-17 15:02:42 +01001888 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 int err;
1890
1891 snd_azf3328_dbgcallenter();
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001892
1893 err = snd_pcm_new(chip->card, "AZF3328 DSP", AZF_PCMDEV_STD,
1894 1, 1, &pcm);
1895 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 return err;
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001897 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1898 &snd_azf3328_playback_ops);
1899 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1900 &snd_azf3328_capture_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901
1902 pcm->private_data = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 pcm->info_flags = 0;
1904 strcpy(pcm->name, chip->card->shortname);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001905 /* same pcm object for playback/capture (see snd_pcm_new() above) */
1906 chip->pcm[AZF_CODEC_PLAYBACK] = pcm;
1907 chip->pcm[AZF_CODEC_CAPTURE] = pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
1909 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001910 snd_dma_pci_data(chip->pci),
1911 64*1024, 64*1024);
1912
1913 err = snd_pcm_new(chip->card, "AZF3328 I2S OUT", AZF_PCMDEV_I2S_OUT,
1914 1, 0, &pcm);
1915 if (err < 0)
1916 return err;
1917 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1918 &snd_azf3328_i2s_out_ops);
1919
1920 pcm->private_data = chip;
1921 pcm->info_flags = 0;
1922 strcpy(pcm->name, chip->card->shortname);
1923 chip->pcm[AZF_CODEC_I2S_OUT] = pcm;
1924
1925 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1926 snd_dma_pci_data(chip->pci),
1927 64*1024, 64*1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
1929 snd_azf3328_dbgcallleave();
1930 return 0;
1931}
1932
1933/******************************************************************/
1934
Andreas Mohr02330fb2008-05-16 12:18:29 +02001935/*** NOTE: the physical timer resolution actually is 1024000 ticks per second
1936 *** (probably derived from main crystal via a divider of 24),
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001937 *** but announcing those attributes to user-space would make programs
1938 *** configure the timer to a 1 tick value, resulting in an absolutely fatal
1939 *** timer IRQ storm.
1940 *** Thus I chose to announce a down-scaled virtual timer to the outside and
1941 *** calculate real timer countdown values internally.
1942 *** (the scale factor can be set via module parameter "seqtimer_scaling").
1943 ***/
1944
1945static int
Takashi Iwai95de7762005-11-17 15:02:42 +01001946snd_azf3328_timer_start(struct snd_timer *timer)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001947{
Takashi Iwai95de7762005-11-17 15:02:42 +01001948 struct snd_azf3328 *chip;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001949 unsigned long flags;
1950 unsigned int delay;
1951
1952 snd_azf3328_dbgcallenter();
1953 chip = snd_timer_chip(timer);
1954 delay = ((timer->sticks * seqtimer_scaling) - 1) & TIMER_VALUE_MASK;
Andreas Mohre2f87262006-05-17 11:04:19 +02001955 if (delay < 49) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001956 /* uhoh, that's not good, since user-space won't know about
1957 * this timing tweak
1958 * (we need to do it to avoid a lockup, though) */
1959
1960 snd_azf3328_dbgtimer("delay was too low (%d)!\n", delay);
1961 delay = 49; /* minimum time is 49 ticks */
1962 }
Andreas Mohradf59312010-12-27 21:16:43 +01001963 snd_azf3328_dbgtimer("setting timer countdown value %d\n", delay);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001964 delay |= TIMER_COUNTDOWN_ENABLE | TIMER_IRQ_ENABLE;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001965 spin_lock_irqsave(&chip->reg_lock, flags);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001966 snd_azf3328_ctrl_outl(chip, IDX_IO_TIMER_VALUE, delay);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001967 spin_unlock_irqrestore(&chip->reg_lock, flags);
1968 snd_azf3328_dbgcallleave();
1969 return 0;
1970}
1971
1972static int
Takashi Iwai95de7762005-11-17 15:02:42 +01001973snd_azf3328_timer_stop(struct snd_timer *timer)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001974{
Takashi Iwai95de7762005-11-17 15:02:42 +01001975 struct snd_azf3328 *chip;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001976 unsigned long flags;
1977
1978 snd_azf3328_dbgcallenter();
1979 chip = snd_timer_chip(timer);
1980 spin_lock_irqsave(&chip->reg_lock, flags);
1981 /* disable timer countdown and interrupt */
Andreas Mohr79741502010-11-21 12:09:32 +01001982 /* Hmm, should we write TIMER_IRQ_ACK here?
1983 YES indeed, otherwise a rogue timer operation - which prompts
1984 ALSA(?) to call repeated stop() in vain, but NOT start() -
1985 will never end (value 0x03 is kept shown in control byte).
1986 Simply manually poking 0x04 _once_ immediately successfully stops
1987 the hardware/ALSA interrupt activity. */
1988 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x04);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001989 spin_unlock_irqrestore(&chip->reg_lock, flags);
1990 snd_azf3328_dbgcallleave();
1991 return 0;
1992}
1993
1994
1995static int
Takashi Iwai95de7762005-11-17 15:02:42 +01001996snd_azf3328_timer_precise_resolution(struct snd_timer *timer,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001997 unsigned long *num, unsigned long *den)
1998{
1999 snd_azf3328_dbgcallenter();
2000 *num = 1;
2001 *den = 1024000 / seqtimer_scaling;
2002 snd_azf3328_dbgcallleave();
2003 return 0;
2004}
2005
Takashi Iwai95de7762005-11-17 15:02:42 +01002006static struct snd_timer_hardware snd_azf3328_timer_hw = {
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002007 .flags = SNDRV_TIMER_HW_AUTO,
2008 .resolution = 977, /* 1000000/1024000 = 0.9765625us */
2009 .ticks = 1024000, /* max tick count, defined by the value register; actually it's not 1024000, but 1048576, but we don't care */
2010 .start = snd_azf3328_timer_start,
2011 .stop = snd_azf3328_timer_stop,
2012 .precise_resolution = snd_azf3328_timer_precise_resolution,
2013};
2014
2015static int __devinit
Takashi Iwai95de7762005-11-17 15:02:42 +01002016snd_azf3328_timer(struct snd_azf3328 *chip, int device)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002017{
Takashi Iwai95de7762005-11-17 15:02:42 +01002018 struct snd_timer *timer = NULL;
2019 struct snd_timer_id tid;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002020 int err;
2021
2022 snd_azf3328_dbgcallenter();
2023 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
2024 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
2025 tid.card = chip->card->number;
2026 tid.device = device;
2027 tid.subdevice = 0;
2028
2029 snd_azf3328_timer_hw.resolution *= seqtimer_scaling;
2030 snd_azf3328_timer_hw.ticks /= seqtimer_scaling;
Andreas Mohr02330fb2008-05-16 12:18:29 +02002031
2032 err = snd_timer_new(chip->card, "AZF3328", &tid, &timer);
2033 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002034 goto out;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002035
2036 strcpy(timer->name, "AZF3328 timer");
2037 timer->private_data = chip;
2038 timer->hw = snd_azf3328_timer_hw;
2039
2040 chip->timer = timer;
2041
Andreas Mohr02330fb2008-05-16 12:18:29 +02002042 snd_azf3328_timer_stop(timer);
2043
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002044 err = 0;
2045
2046out:
2047 snd_azf3328_dbgcallleave();
2048 return err;
2049}
2050
2051/******************************************************************/
2052
Andreas Mohr02330fb2008-05-16 12:18:29 +02002053static int
2054snd_azf3328_free(struct snd_azf3328 *chip)
2055{
2056 if (chip->irq < 0)
2057 goto __end_hw;
2058
2059 /* reset (close) mixer:
2060 * first mute master volume, then reset
2061 */
2062 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1);
2063 snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
2064
2065 snd_azf3328_timer_stop(chip->timer);
2066 snd_azf3328_gameport_free(chip);
2067
2068 if (chip->irq >= 0)
2069 synchronize_irq(chip->irq);
2070__end_hw:
2071 if (chip->irq >= 0)
2072 free_irq(chip->irq, chip);
2073 pci_release_regions(chip->pci);
2074 pci_disable_device(chip->pci);
2075
2076 kfree(chip);
2077 return 0;
2078}
2079
2080static int
2081snd_azf3328_dev_free(struct snd_device *device)
2082{
2083 struct snd_azf3328 *chip = device->device_data;
2084 return snd_azf3328_free(chip);
2085}
2086
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087#if 0
2088/* check whether a bit can be modified */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002089static void
Andreas Mohr02330fb2008-05-16 12:18:29 +02002090snd_azf3328_test_bit(unsigned unsigned reg, int bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091{
2092 unsigned char val, valoff, valon;
2093
2094 val = inb(reg);
2095
2096 outb(val & ~(1 << bit), reg);
2097 valoff = inb(reg);
2098
2099 outb(val|(1 << bit), reg);
2100 valon = inb(reg);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002101
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 outb(val, reg);
2103
Andreas Mohr78df6172009-07-12 22:17:54 +02002104 printk(KERN_DEBUG "reg %04x bit %d: %02x %02x %02x\n",
Andreas Mohr02330fb2008-05-16 12:18:29 +02002105 reg, bit, val, valoff, valon
2106 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107}
2108#endif
2109
Andreas Mohr02330fb2008-05-16 12:18:29 +02002110static inline void
Takashi Iwai95de7762005-11-17 15:02:42 +01002111snd_azf3328_debug_show_ports(const struct snd_azf3328 *chip)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002112{
Andreas Mohr02330fb2008-05-16 12:18:29 +02002113#if DEBUG_MISC
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002114 u16 tmp;
2115
Andreas Mohr02330fb2008-05-16 12:18:29 +02002116 snd_azf3328_dbgmisc(
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002117 "ctrl_io 0x%lx, game_io 0x%lx, mpu_io 0x%lx, "
Andreas Mohr02330fb2008-05-16 12:18:29 +02002118 "opl3_io 0x%lx, mixer_io 0x%lx, irq %d\n",
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002119 chip->ctrl_io, chip->game_io, chip->mpu_io,
Andreas Mohr02330fb2008-05-16 12:18:29 +02002120 chip->opl3_io, chip->mixer_io, chip->irq
2121 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002122
Andreas Mohr02330fb2008-05-16 12:18:29 +02002123 snd_azf3328_dbgmisc("game %02x %02x %02x %02x %02x %02x\n",
2124 snd_azf3328_game_inb(chip, 0),
2125 snd_azf3328_game_inb(chip, 1),
2126 snd_azf3328_game_inb(chip, 2),
2127 snd_azf3328_game_inb(chip, 3),
2128 snd_azf3328_game_inb(chip, 4),
2129 snd_azf3328_game_inb(chip, 5)
2130 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002131
Andreas Mohr02330fb2008-05-16 12:18:29 +02002132 for (tmp = 0; tmp < 0x07; tmp += 1)
2133 snd_azf3328_dbgmisc("mpu_io 0x%04x\n", inb(chip->mpu_io + tmp));
2134
2135 for (tmp = 0; tmp <= 0x07; tmp += 1)
2136 snd_azf3328_dbgmisc("0x%02x: game200 0x%04x, game208 0x%04x\n",
2137 tmp, inb(0x200 + tmp), inb(0x208 + tmp));
2138
2139 for (tmp = 0; tmp <= 0x01; tmp += 1)
2140 snd_azf3328_dbgmisc(
2141 "0x%02x: mpu300 0x%04x, mpu310 0x%04x, mpu320 0x%04x, "
2142 "mpu330 0x%04x opl388 0x%04x opl38c 0x%04x\n",
2143 tmp,
2144 inb(0x300 + tmp),
2145 inb(0x310 + tmp),
2146 inb(0x320 + tmp),
2147 inb(0x330 + tmp),
2148 inb(0x388 + tmp),
2149 inb(0x38c + tmp)
2150 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002151
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002152 for (tmp = 0; tmp < AZF_IO_SIZE_CTRL; tmp += 2)
2153 snd_azf3328_dbgmisc("ctrl 0x%02x: 0x%04x\n",
2154 tmp, snd_azf3328_ctrl_inw(chip, tmp)
Andreas Mohr02330fb2008-05-16 12:18:29 +02002155 );
Andreas Mohre24a1212007-03-26 12:49:45 +02002156
2157 for (tmp = 0; tmp < AZF_IO_SIZE_MIXER; tmp += 2)
Andreas Mohr02330fb2008-05-16 12:18:29 +02002158 snd_azf3328_dbgmisc("mixer 0x%02x: 0x%04x\n",
2159 tmp, snd_azf3328_mixer_inw(chip, tmp)
2160 );
2161#endif /* DEBUG_MISC */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002162}
2163
2164static int __devinit
Takashi Iwai95de7762005-11-17 15:02:42 +01002165snd_azf3328_create(struct snd_card *card,
Andreas Mohr02330fb2008-05-16 12:18:29 +02002166 struct pci_dev *pci,
2167 unsigned long device_type,
2168 struct snd_azf3328 **rchip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
Takashi Iwai95de7762005-11-17 15:02:42 +01002170 struct snd_azf3328 *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 int err;
Takashi Iwai95de7762005-11-17 15:02:42 +01002172 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 .dev_free = snd_azf3328_dev_free,
2174 };
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002175 u8 dma_init;
2176 enum snd_azf3328_codec_type codec_type;
Andreas Mohrda237f32010-12-27 21:17:26 +01002177 struct snd_azf3328_codec_data *codec_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
2179 *rchip = NULL;
2180
Andreas Mohr02330fb2008-05-16 12:18:29 +02002181 err = pci_enable_device(pci);
2182 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 return err;
2184
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002185 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 if (chip == NULL) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002187 err = -ENOMEM;
2188 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 }
2190 spin_lock_init(&chip->reg_lock);
2191 chip->card = card;
2192 chip->pci = pci;
2193 chip->irq = -1;
2194
2195 /* check if we can restrict PCI DMA transfers to 24 bits */
Yang Hongyang2f4f27d2009-04-06 19:01:18 -07002196 if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 ||
2197 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) {
Andreas Mohr02330fb2008-05-16 12:18:29 +02002198 snd_printk(KERN_ERR "architecture does not support "
2199 "24bit PCI busmaster DMA\n"
2200 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002201 err = -ENXIO;
2202 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 }
2204
Andreas Mohr02330fb2008-05-16 12:18:29 +02002205 err = pci_request_regions(pci, "Aztech AZF3328");
2206 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002207 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002209 chip->ctrl_io = pci_resource_start(pci, 0);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002210 chip->game_io = pci_resource_start(pci, 1);
2211 chip->mpu_io = pci_resource_start(pci, 2);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002212 chip->opl3_io = pci_resource_start(pci, 3);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002213 chip->mixer_io = pci_resource_start(pci, 4);
2214
Andreas Mohr9fd8d362010-12-27 21:17:00 +01002215 codec_setup = &chip->codecs[AZF_CODEC_PLAYBACK];
2216 codec_setup->io_base = chip->ctrl_io + AZF_IO_OFFS_CODEC_PLAYBACK;
Andreas Mohrda237f32010-12-27 21:17:26 +01002217 codec_setup->lock = &chip->reg_lock;
2218 codec_setup->type = AZF_CODEC_PLAYBACK;
Andreas Mohr9fd8d362010-12-27 21:17:00 +01002219 codec_setup->name = "PLAYBACK";
2220
2221 codec_setup = &chip->codecs[AZF_CODEC_CAPTURE];
2222 codec_setup->io_base = chip->ctrl_io + AZF_IO_OFFS_CODEC_CAPTURE;
Andreas Mohrda237f32010-12-27 21:17:26 +01002223 codec_setup->lock = &chip->reg_lock;
2224 codec_setup->type = AZF_CODEC_CAPTURE;
Andreas Mohr9fd8d362010-12-27 21:17:00 +01002225 codec_setup->name = "CAPTURE";
2226
2227 codec_setup = &chip->codecs[AZF_CODEC_I2S_OUT];
2228 codec_setup->io_base = chip->ctrl_io + AZF_IO_OFFS_CODEC_I2S_OUT;
Andreas Mohrda237f32010-12-27 21:17:26 +01002229 codec_setup->lock = &chip->reg_lock;
2230 codec_setup->type = AZF_CODEC_I2S_OUT;
Andreas Mohr9fd8d362010-12-27 21:17:00 +01002231 codec_setup->name = "I2S_OUT";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
Takashi Iwai437a5a42006-11-21 12:14:23 +01002233 if (request_irq(pci->irq, snd_azf3328_interrupt,
2234 IRQF_SHARED, card->shortname, chip)) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002235 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002236 err = -EBUSY;
2237 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 }
2239 chip->irq = pci->irq;
2240 pci_set_master(pci);
2241 synchronize_irq(chip->irq);
2242
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002243 snd_azf3328_debug_show_ports(chip);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002244
2245 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
2246 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002247 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
2249 /* create mixer interface & switches */
Andreas Mohr02330fb2008-05-16 12:18:29 +02002250 err = snd_azf3328_mixer_new(chip);
2251 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002252 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002254 /* standard codec init stuff */
2255 /* default DMA init value */
2256 dma_init = DMA_RUN_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002258 for (codec_type = AZF_CODEC_PLAYBACK;
2259 codec_type <= AZF_CODEC_I2S_OUT; ++codec_type) {
2260 struct snd_azf3328_codec_data *codec =
2261 &chip->codecs[codec_type];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Andreas Mohradf59312010-12-27 21:16:43 +01002263 /* shutdown codecs to reduce power / noise */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002264 /* have ...ctrl_codec_activity() act properly */
2265 codec->running = 1;
2266 snd_azf3328_ctrl_codec_activity(chip, codec_type, 0);
2267
Andreas Mohrda237f32010-12-27 21:17:26 +01002268 spin_lock_irq(codec->lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002269 snd_azf3328_codec_outb(codec, IDX_IO_CODEC_DMA_FLAGS,
2270 dma_init);
Andreas Mohrda237f32010-12-27 21:17:26 +01002271 spin_unlock_irq(codec->lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273
2274 snd_card_set_dev(card, &pci->dev);
2275
2276 *rchip = chip;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002277
2278 err = 0;
2279 goto out;
2280
2281out_err:
2282 if (chip)
2283 snd_azf3328_free(chip);
2284 pci_disable_device(pci);
2285
2286out:
2287 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288}
2289
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002290static int __devinit
2291snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292{
2293 static int dev;
Takashi Iwai95de7762005-11-17 15:02:42 +01002294 struct snd_card *card;
2295 struct snd_azf3328 *chip;
2296 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 int err;
2298
2299 snd_azf3328_dbgcallenter();
2300 if (dev >= SNDRV_CARDS)
2301 return -ENODEV;
2302 if (!enable[dev]) {
2303 dev++;
2304 return -ENOENT;
2305 }
2306
Takashi Iwaie58de7b2008-12-28 16:44:30 +01002307 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2308 if (err < 0)
2309 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
2311 strcpy(card->driver, "AZF3328");
2312 strcpy(card->shortname, "Aztech AZF3328 (PCI168)");
2313
Andreas Mohr02330fb2008-05-16 12:18:29 +02002314 err = snd_azf3328_create(card, pci, pci_id->driver_data, &chip);
2315 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002316 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
Andreas Mohrca54bde2006-05-17 11:02:24 +02002318 card->private_data = chip;
2319
Andreas Mohr78df6172009-07-12 22:17:54 +02002320 /* chose to use MPU401_HW_AZT2320 ID instead of MPU401_HW_MPU401,
2321 since our hardware ought to be similar, thus use same ID. */
Andreas Mohr02330fb2008-05-16 12:18:29 +02002322 err = snd_mpu401_uart_new(
Andreas Mohr78df6172009-07-12 22:17:54 +02002323 card, 0,
2324 MPU401_HW_AZT2320, chip->mpu_io, MPU401_INFO_INTEGRATED,
Andreas Mohr02330fb2008-05-16 12:18:29 +02002325 pci->irq, 0, &chip->rmidi
2326 );
2327 if (err < 0) {
2328 snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n",
2329 chip->mpu_io
2330 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002331 goto out_err;
2332 }
2333
Andreas Mohr02330fb2008-05-16 12:18:29 +02002334 err = snd_azf3328_timer(chip, 0);
2335 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002336 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002338 err = snd_azf3328_pcm(chip);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002339 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002340 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Andreas Mohr02330fb2008-05-16 12:18:29 +02002342 if (snd_opl3_create(card, chip->opl3_io, chip->opl3_io+2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 OPL3_HW_AUTO, 1, &opl3) < 0) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002344 snd_printk(KERN_ERR "azf3328: no OPL3 device at 0x%lx-0x%lx?\n",
Andreas Mohr02330fb2008-05-16 12:18:29 +02002345 chip->opl3_io, chip->opl3_io+2
2346 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 } else {
Andreas Mohr02330fb2008-05-16 12:18:29 +02002348 /* need to use IDs 1, 2 since ID 0 is snd_azf3328_timer above */
2349 err = snd_opl3_timer_new(opl3, 1, 2);
2350 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002351 goto out_err;
Andreas Mohr02330fb2008-05-16 12:18:29 +02002352 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
2353 if (err < 0)
2354 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 }
2356
Andreas Mohrca54bde2006-05-17 11:02:24 +02002357 opl3->private_data = chip;
2358
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 sprintf(card->longname, "%s at 0x%lx, irq %i",
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002360 card->shortname, chip->ctrl_io, chip->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
Andreas Mohr02330fb2008-05-16 12:18:29 +02002362 err = snd_card_register(card);
2363 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002364 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
2366#ifdef MODULE
Andreas Mohr78df6172009-07-12 22:17:54 +02002367 printk(KERN_INFO
Andreas Mohre24a1212007-03-26 12:49:45 +02002368"azt3328: Sound driver for Aztech AZF3328-based soundcards such as PCI168.\n"
2369"azt3328: Hardware was completely undocumented, unfortunately.\n"
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002370"azt3328: Feel free to contact andi AT lisas.de for bug reports etc.!\n"
2371"azt3328: User-scalable sequencer timer set to %dHz (1024000Hz / %d).\n",
2372 1024000 / seqtimer_scaling, seqtimer_scaling);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373#endif
2374
Andreas Mohr02330fb2008-05-16 12:18:29 +02002375 snd_azf3328_gameport(chip, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376
2377 pci_set_drvdata(pci, card);
2378 dev++;
2379
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002380 err = 0;
2381 goto out;
Andreas Mohr02330fb2008-05-16 12:18:29 +02002382
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002383out_err:
Andreas Mohr02330fb2008-05-16 12:18:29 +02002384 snd_printk(KERN_ERR "azf3328: something failed, exiting\n");
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002385 snd_card_free(card);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002386
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002387out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 snd_azf3328_dbgcallleave();
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002389 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390}
2391
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002392static void __devexit
2393snd_azf3328_remove(struct pci_dev *pci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394{
2395 snd_azf3328_dbgcallenter();
2396 snd_card_free(pci_get_drvdata(pci));
2397 pci_set_drvdata(pci, NULL);
2398 snd_azf3328_dbgcallleave();
2399}
2400
Andreas Mohrca54bde2006-05-17 11:02:24 +02002401#ifdef CONFIG_PM
Andreas Mohr78df6172009-07-12 22:17:54 +02002402static inline void
2403snd_azf3328_suspend_regs(unsigned long io_addr, unsigned count, u32 *saved_regs)
2404{
2405 unsigned reg;
2406
2407 for (reg = 0; reg < count; ++reg) {
2408 *saved_regs = inl(io_addr);
2409 snd_azf3328_dbgpm("suspend: io 0x%04lx: 0x%08x\n",
2410 io_addr, *saved_regs);
2411 ++saved_regs;
2412 io_addr += sizeof(*saved_regs);
2413 }
2414}
2415
Andreas Mohrca54bde2006-05-17 11:02:24 +02002416static int
2417snd_azf3328_suspend(struct pci_dev *pci, pm_message_t state)
2418{
2419 struct snd_card *card = pci_get_drvdata(pci);
2420 struct snd_azf3328 *chip = card->private_data;
Andreas Mohr78df6172009-07-12 22:17:54 +02002421 u16 *saved_regs_ctrl_u16;
Andreas Mohrca54bde2006-05-17 11:02:24 +02002422
2423 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002424
Andreas Mohradf59312010-12-27 21:16:43 +01002425 /* same pcm object for playback/capture */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002426 snd_pcm_suspend_all(chip->pcm[AZF_CODEC_PLAYBACK]);
2427 snd_pcm_suspend_all(chip->pcm[AZF_CODEC_I2S_OUT]);
Andreas Mohrca54bde2006-05-17 11:02:24 +02002428
Andreas Mohr78df6172009-07-12 22:17:54 +02002429 snd_azf3328_suspend_regs(chip->mixer_io,
2430 ARRAY_SIZE(chip->saved_regs_mixer), chip->saved_regs_mixer);
Andreas Mohrca54bde2006-05-17 11:02:24 +02002431
2432 /* make sure to disable master volume etc. to prevent looping sound */
2433 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1);
2434 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002435
Andreas Mohr78df6172009-07-12 22:17:54 +02002436 snd_azf3328_suspend_regs(chip->ctrl_io,
2437 ARRAY_SIZE(chip->saved_regs_ctrl), chip->saved_regs_ctrl);
Andreas Mohr627d3e72008-06-23 11:50:47 +02002438
2439 /* manually store the one currently relevant write-only reg, too */
Andreas Mohr78df6172009-07-12 22:17:54 +02002440 saved_regs_ctrl_u16 = (u16 *)chip->saved_regs_ctrl;
2441 saved_regs_ctrl_u16[IDX_IO_6AH / 2] = chip->shadow_reg_ctrl_6AH;
Andreas Mohr627d3e72008-06-23 11:50:47 +02002442
Andreas Mohr78df6172009-07-12 22:17:54 +02002443 snd_azf3328_suspend_regs(chip->game_io,
2444 ARRAY_SIZE(chip->saved_regs_game), chip->saved_regs_game);
2445 snd_azf3328_suspend_regs(chip->mpu_io,
2446 ARRAY_SIZE(chip->saved_regs_mpu), chip->saved_regs_mpu);
2447 snd_azf3328_suspend_regs(chip->opl3_io,
2448 ARRAY_SIZE(chip->saved_regs_opl3), chip->saved_regs_opl3);
Andreas Mohrca54bde2006-05-17 11:02:24 +02002449
Andreas Mohrca54bde2006-05-17 11:02:24 +02002450 pci_disable_device(pci);
2451 pci_save_state(pci);
Takashi Iwai30b35392006-10-11 18:52:53 +02002452 pci_set_power_state(pci, pci_choose_state(pci, state));
Andreas Mohrca54bde2006-05-17 11:02:24 +02002453 return 0;
2454}
2455
Andreas Mohr78df6172009-07-12 22:17:54 +02002456static inline void
2457snd_azf3328_resume_regs(const u32 *saved_regs,
2458 unsigned long io_addr,
2459 unsigned count
2460)
2461{
2462 unsigned reg;
2463
2464 for (reg = 0; reg < count; ++reg) {
2465 outl(*saved_regs, io_addr);
2466 snd_azf3328_dbgpm("resume: io 0x%04lx: 0x%08x --> 0x%08x\n",
2467 io_addr, *saved_regs, inl(io_addr));
2468 ++saved_regs;
2469 io_addr += sizeof(*saved_regs);
2470 }
2471}
2472
Andreas Mohrca54bde2006-05-17 11:02:24 +02002473static int
2474snd_azf3328_resume(struct pci_dev *pci)
2475{
2476 struct snd_card *card = pci_get_drvdata(pci);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002477 const struct snd_azf3328 *chip = card->private_data;
Andreas Mohrca54bde2006-05-17 11:02:24 +02002478
Andreas Mohrca54bde2006-05-17 11:02:24 +02002479 pci_set_power_state(pci, PCI_D0);
Takashi Iwai30b35392006-10-11 18:52:53 +02002480 pci_restore_state(pci);
2481 if (pci_enable_device(pci) < 0) {
2482 printk(KERN_ERR "azt3328: pci_enable_device failed, "
2483 "disabling device\n");
2484 snd_card_disconnect(card);
2485 return -EIO;
2486 }
Andreas Mohrca54bde2006-05-17 11:02:24 +02002487 pci_set_master(pci);
2488
Andreas Mohr78df6172009-07-12 22:17:54 +02002489 snd_azf3328_resume_regs(chip->saved_regs_game, chip->game_io,
2490 ARRAY_SIZE(chip->saved_regs_game));
2491 snd_azf3328_resume_regs(chip->saved_regs_mpu, chip->mpu_io,
2492 ARRAY_SIZE(chip->saved_regs_mpu));
2493 snd_azf3328_resume_regs(chip->saved_regs_opl3, chip->opl3_io,
2494 ARRAY_SIZE(chip->saved_regs_opl3));
2495
2496 snd_azf3328_resume_regs(chip->saved_regs_mixer, chip->mixer_io,
2497 ARRAY_SIZE(chip->saved_regs_mixer));
2498
2499 /* unfortunately with 32bit transfers, IDX_MIXER_PLAY_MASTER (0x02)
2500 and IDX_MIXER_RESET (offset 0x00) get touched at the same time,
2501 resulting in a mixer reset condition persisting until _after_
2502 master vol was restored. Thus master vol needs an extra restore. */
2503 outw(((u16 *)chip->saved_regs_mixer)[1], chip->mixer_io + 2);
2504
2505 snd_azf3328_resume_regs(chip->saved_regs_ctrl, chip->ctrl_io,
2506 ARRAY_SIZE(chip->saved_regs_ctrl));
Andreas Mohrca54bde2006-05-17 11:02:24 +02002507
2508 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
2509 return 0;
2510}
Andreas Mohr02330fb2008-05-16 12:18:29 +02002511#endif /* CONFIG_PM */
Andreas Mohrca54bde2006-05-17 11:02:24 +02002512
2513
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514static struct pci_driver driver = {
2515 .name = "AZF3328",
2516 .id_table = snd_azf3328_ids,
2517 .probe = snd_azf3328_probe,
2518 .remove = __devexit_p(snd_azf3328_remove),
Andreas Mohrca54bde2006-05-17 11:02:24 +02002519#ifdef CONFIG_PM
2520 .suspend = snd_azf3328_suspend,
2521 .resume = snd_azf3328_resume,
2522#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523};
2524
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002525static int __init
2526alsa_card_azf3328_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527{
2528 int err;
2529 snd_azf3328_dbgcallenter();
Takashi Iwai01d25d42005-04-11 16:58:24 +02002530 err = pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 snd_azf3328_dbgcallleave();
2532 return err;
2533}
2534
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002535static void __exit
2536alsa_card_azf3328_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537{
2538 snd_azf3328_dbgcallenter();
2539 pci_unregister_driver(&driver);
2540 snd_azf3328_dbgcallleave();
2541}
2542
2543module_init(alsa_card_azf3328_init)
2544module_exit(alsa_card_azf3328_exit)