blob: 006f8c0ffb566ca0de9f24303059df03ab00664b [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>
178#include <linux/pci.h>
179#include <linux/delay.h>
180#include <linux/slab.h>
181#include <linux/gameport.h>
182#include <linux/moduleparam.h>
Matthias Gehre910638a2006-03-28 01:56:48 -0800183#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184#include <sound/core.h>
185#include <sound/control.h>
186#include <sound/pcm.h>
187#include <sound/rawmidi.h>
188#include <sound/mpu401.h>
189#include <sound/opl3.h>
190#include <sound/initval.h>
191#include "azt3328.h"
192
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200193MODULE_AUTHOR("Andreas Mohr <andi AT lisas.de>");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194MODULE_DESCRIPTION("Aztech AZF3328 (PCI168)");
195MODULE_LICENSE("GPL");
196MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
197
198#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
Andreas Mohr02330fb2008-05-16 12:18:29 +0200199#define SUPPORT_GAMEPORT 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#endif
201
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200202/* === Debug settings ===
203 Further diagnostic functionality than the settings below
Andreas Mohradf59312010-12-27 21:16:43 +0100204 does not need to be provided, since one can easily write a POSIX shell script
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200205 to dump the card's I/O ports (those listed in lspci -v -v):
Andreas Mohradf59312010-12-27 21:16:43 +0100206 dump()
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200207 {
208 local descr=$1; local addr=$2; local count=$3
209
210 echo "${descr}: ${count} @ ${addr}:"
Andreas Mohradf59312010-12-27 21:16:43 +0100211 dd if=/dev/port skip=`printf %d ${addr}` count=${count} bs=1 \
212 2>/dev/null| hexdump -C
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200213 }
214 and then use something like
215 "dump joy200 0x200 8", "dump mpu388 0x388 4", "dump joy 0xb400 8",
216 "dump codec00 0xa800 32", "dump mixer 0xb800 64", "dump synth 0xbc00 8",
217 possibly within a "while true; do ... sleep 1; done" loop.
218 Tweaking ports could be done using
219 VALSTRING="`printf "%02x" $value`"
Andreas Mohradf59312010-12-27 21:16:43 +0100220 printf "\x""$VALSTRING"|dd of=/dev/port seek=`printf %d ${addr}` bs=1 \
221 2>/dev/null
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200222*/
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224#define DEBUG_MISC 0
225#define DEBUG_CALLS 0
226#define DEBUG_MIXER 0
Andreas Mohr78df6172009-07-12 22:17:54 +0200227#define DEBUG_CODEC 0
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200228#define DEBUG_TIMER 0
Andreas Mohr02330fb2008-05-16 12:18:29 +0200229#define DEBUG_GAME 0
Andreas Mohr78df6172009-07-12 22:17:54 +0200230#define DEBUG_PM 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231#define MIXER_TESTING 0
232
233#if DEBUG_MISC
Andreas Mohr78df6172009-07-12 22:17:54 +0200234#define snd_azf3328_dbgmisc(format, args...) printk(KERN_DEBUG format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#else
236#define snd_azf3328_dbgmisc(format, args...)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200237#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239#if DEBUG_CALLS
240#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args)
Andreas Mohr78df6172009-07-12 22:17:54 +0200241#define snd_azf3328_dbgcallenter() printk(KERN_DEBUG "--> %s\n", __func__)
242#define snd_azf3328_dbgcallleave() printk(KERN_DEBUG "<-- %s\n", __func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243#else
244#define snd_azf3328_dbgcalls(format, args...)
245#define snd_azf3328_dbgcallenter()
246#define snd_azf3328_dbgcallleave()
Andreas Mohr02330fb2008-05-16 12:18:29 +0200247#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249#if DEBUG_MIXER
Takashi Iwaiee419652009-02-05 16:11:31 +0100250#define snd_azf3328_dbgmixer(format, args...) printk(KERN_DEBUG format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#else
252#define snd_azf3328_dbgmixer(format, args...)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200253#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Andreas Mohr78df6172009-07-12 22:17:54 +0200255#if DEBUG_CODEC
256#define snd_azf3328_dbgcodec(format, args...) printk(KERN_DEBUG format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#else
Andreas Mohr78df6172009-07-12 22:17:54 +0200258#define snd_azf3328_dbgcodec(format, args...)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200259#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200261#if DEBUG_MISC
Takashi Iwaiee419652009-02-05 16:11:31 +0100262#define snd_azf3328_dbgtimer(format, args...) printk(KERN_DEBUG format, ##args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#else
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200264#define snd_azf3328_dbgtimer(format, args...)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200265#endif
266
267#if DEBUG_GAME
Takashi Iwaiee419652009-02-05 16:11:31 +0100268#define snd_azf3328_dbggame(format, args...) printk(KERN_DEBUG format, ##args)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200269#else
270#define snd_azf3328_dbggame(format, args...)
271#endif
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200272
Andreas Mohr78df6172009-07-12 22:17:54 +0200273#if DEBUG_PM
274#define snd_azf3328_dbgpm(format, args...) printk(KERN_DEBUG format, ##args)
275#else
276#define snd_azf3328_dbgpm(format, args...)
277#endif
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
280module_param_array(index, int, NULL, 0444);
281MODULE_PARM_DESC(index, "Index value for AZF3328 soundcard.");
282
283static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
284module_param_array(id, charp, NULL, 0444);
285MODULE_PARM_DESC(id, "ID string for AZF3328 soundcard.");
286
287static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
288module_param_array(enable, bool, NULL, 0444);
289MODULE_PARM_DESC(enable, "Enable AZF3328 soundcard.");
290
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200291static int seqtimer_scaling = 128;
292module_param(seqtimer_scaling, int, 0444);
293MODULE_PARM_DESC(seqtimer_scaling, "Set 1024000Hz sequencer timer scale factor (lockup danger!). Default 128.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200295struct snd_azf3328_codec_data {
296 unsigned long io_base;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200297 struct snd_pcm_substream *substream;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200298 bool running;
299 const char *name;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200300};
301
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200302enum snd_azf3328_codec_type {
Andreas Mohradf59312010-12-27 21:16:43 +0100303 /* warning: fixed indices (also used for bitmask checks!) */
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200304 AZF_CODEC_PLAYBACK = 0,
305 AZF_CODEC_CAPTURE = 1,
306 AZF_CODEC_I2S_OUT = 2,
Andreas Mohr02330fb2008-05-16 12:18:29 +0200307};
308
Takashi Iwai95de7762005-11-17 15:02:42 +0100309struct snd_azf3328 {
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200310 /* often-used fields towards beginning, then grouped */
Andreas Mohr02330fb2008-05-16 12:18:29 +0200311
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200312 unsigned long ctrl_io; /* usually 0xb000, size 128 */
Andreas Mohr02330fb2008-05-16 12:18:29 +0200313 unsigned long game_io; /* usually 0xb400, size 8 */
314 unsigned long mpu_io; /* usually 0xb800, size 4 */
315 unsigned long opl3_io; /* usually 0xbc00, size 8 */
316 unsigned long mixer_io; /* usually 0xc000, size 64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200318 spinlock_t reg_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Takashi Iwai95de7762005-11-17 15:02:42 +0100320 struct snd_timer *timer;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200321
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200322 struct snd_pcm *pcm[3];
323
324 /* playback, recording and I2S out codecs */
325 struct snd_azf3328_codec_data codecs[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Takashi Iwai95de7762005-11-17 15:02:42 +0100327 struct snd_card *card;
328 struct snd_rawmidi *rmidi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Andreas Mohr02330fb2008-05-16 12:18:29 +0200330#ifdef SUPPORT_GAMEPORT
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200331 struct gameport *gameport;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200332 u16 axes[4];
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200333#endif
334
335 struct pci_dev *pci;
336 int irq;
Andreas Mohrca54bde2006-05-17 11:02:24 +0200337
Andreas Mohr627d3e72008-06-23 11:50:47 +0200338 /* register 0x6a is write-only, thus need to remember setting.
339 * If we need to add more registers here, then we might try to fold this
340 * into some transparent combined shadow register handling with
341 * CONFIG_PM register storage below, but that's slightly difficult. */
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200342 u16 shadow_reg_ctrl_6AH;
Andreas Mohr627d3e72008-06-23 11:50:47 +0200343
Andreas Mohrca54bde2006-05-17 11:02:24 +0200344#ifdef CONFIG_PM
345 /* register value containers for power management
Andreas Mohr78df6172009-07-12 22:17:54 +0200346 * Note: not always full I/O range preserved (similar to Win driver!) */
347 u32 saved_regs_ctrl[AZF_ALIGN(AZF_IO_SIZE_CTRL_PM) / 4];
348 u32 saved_regs_game[AZF_ALIGN(AZF_IO_SIZE_GAME_PM) / 4];
349 u32 saved_regs_mpu[AZF_ALIGN(AZF_IO_SIZE_MPU_PM) / 4];
350 u32 saved_regs_opl3[AZF_ALIGN(AZF_IO_SIZE_OPL3_PM) / 4];
351 u32 saved_regs_mixer[AZF_ALIGN(AZF_IO_SIZE_MIXER_PM) / 4];
Andreas Mohrca54bde2006-05-17 11:02:24 +0200352#endif
Takashi Iwai95de7762005-11-17 15:02:42 +0100353};
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200354
Alexey Dobriyancebe41d2010-02-06 00:21:03 +0200355static DEFINE_PCI_DEVICE_TABLE(snd_azf3328_ids) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 { 0x122D, 0x50DC, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* PCI168/3328 */
357 { 0x122D, 0x80DA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* 3328 */
358 { 0, }
359};
360
361MODULE_DEVICE_TABLE(pci, snd_azf3328_ids);
362
Andreas Mohr02330fb2008-05-16 12:18:29 +0200363
364static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200365snd_azf3328_io_reg_setb(unsigned reg, u8 mask, bool do_set)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200366{
Andreas Mohradf59312010-12-27 21:16:43 +0100367 /* Well, strictly spoken, the inb/outb sequence isn't atomic
368 and would need locking. However we currently don't care
369 since it potentially complicates matters. */
Andreas Mohr02330fb2008-05-16 12:18:29 +0200370 u8 prev = inb(reg), new;
371
372 new = (do_set) ? (prev|mask) : (prev & ~mask);
373 /* we need to always write the new value no matter whether it differs
374 * or not, since some register bits don't indicate their setting */
375 outb(new, reg);
376 if (new != prev)
377 return 1;
378
379 return 0;
380}
381
Andreas Mohr02330fb2008-05-16 12:18:29 +0200382static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200383snd_azf3328_codec_outb(const struct snd_azf3328_codec_data *codec,
384 unsigned reg,
385 u8 value
386)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200387{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200388 outb(value, codec->io_base + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200389}
390
391static inline u8
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200392snd_azf3328_codec_inb(const struct snd_azf3328_codec_data *codec, unsigned reg)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200393{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200394 return inb(codec->io_base + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200395}
396
397static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200398snd_azf3328_codec_outw(const struct snd_azf3328_codec_data *codec,
399 unsigned reg,
400 u16 value
401)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200402{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200403 outw(value, codec->io_base + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200404}
405
406static inline u16
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200407snd_azf3328_codec_inw(const struct snd_azf3328_codec_data *codec, unsigned reg)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200408{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200409 return inw(codec->io_base + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200410}
411
412static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200413snd_azf3328_codec_outl(const struct snd_azf3328_codec_data *codec,
414 unsigned reg,
415 u32 value
416)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200417{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200418 outl(value, codec->io_base + reg);
Andreas Mohr02330fb2008-05-16 12:18:29 +0200419}
420
421static inline u32
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200422snd_azf3328_codec_inl(const struct snd_azf3328_codec_data *codec, unsigned reg)
Andreas Mohr02330fb2008-05-16 12:18:29 +0200423{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200424 return inl(codec->io_base + reg);
425}
426
427static inline void
428snd_azf3328_ctrl_outb(const struct snd_azf3328 *chip, unsigned reg, u8 value)
429{
430 outb(value, chip->ctrl_io + reg);
431}
432
433static inline u8
434snd_azf3328_ctrl_inb(const struct snd_azf3328 *chip, unsigned reg)
435{
436 return inb(chip->ctrl_io + reg);
437}
438
439static inline void
440snd_azf3328_ctrl_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
441{
442 outw(value, chip->ctrl_io + reg);
443}
444
445static inline void
446snd_azf3328_ctrl_outl(const struct snd_azf3328 *chip, unsigned reg, u32 value)
447{
448 outl(value, chip->ctrl_io + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200449}
450
451static inline void
Andreas Mohr02330fb2008-05-16 12:18:29 +0200452snd_azf3328_game_outb(const struct snd_azf3328 *chip, unsigned reg, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
Andreas Mohr02330fb2008-05-16 12:18:29 +0200454 outb(value, chip->game_io + reg);
455}
456
457static inline void
458snd_azf3328_game_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
459{
460 outw(value, chip->game_io + reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}
462
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200463static inline u8
Andreas Mohr02330fb2008-05-16 12:18:29 +0200464snd_azf3328_game_inb(const struct snd_azf3328 *chip, unsigned reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465{
Andreas Mohr02330fb2008-05-16 12:18:29 +0200466 return inb(chip->game_io + reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467}
468
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200469static inline u16
Andreas Mohr02330fb2008-05-16 12:18:29 +0200470snd_azf3328_game_inw(const struct snd_azf3328 *chip, unsigned reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Andreas Mohr02330fb2008-05-16 12:18:29 +0200472 return inw(chip->game_io + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200473}
474
Andreas Mohr02330fb2008-05-16 12:18:29 +0200475static inline void
476snd_azf3328_mixer_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200477{
Andreas Mohr02330fb2008-05-16 12:18:29 +0200478 outw(value, chip->mixer_io + reg);
479}
480
481static inline u16
482snd_azf3328_mixer_inw(const struct snd_azf3328 *chip, unsigned reg)
483{
484 return inw(chip->mixer_io + reg);
485}
486
487#define AZF_MUTE_BIT 0x80
488
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200489static bool
Andreas Mohr02330fb2008-05-16 12:18:29 +0200490snd_azf3328_mixer_set_mute(const struct snd_azf3328 *chip,
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200491 unsigned reg, bool do_mute
Andreas Mohr02330fb2008-05-16 12:18:29 +0200492)
493{
494 unsigned long portbase = chip->mixer_io + reg + 1;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200495 bool updated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 /* the mute bit is on the *second* (i.e. right) register of a
498 * left/right channel setting */
Andreas Mohr02330fb2008-05-16 12:18:29 +0200499 updated = snd_azf3328_io_reg_setb(portbase, AZF_MUTE_BIT, do_mute);
500
501 /* indicate whether it was muted before */
502 return (do_mute) ? !updated : updated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503}
504
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200505static void
Andreas Mohr02330fb2008-05-16 12:18:29 +0200506snd_azf3328_mixer_write_volume_gradually(const struct snd_azf3328 *chip,
507 unsigned reg,
508 unsigned char dst_vol_left,
509 unsigned char dst_vol_right,
510 int chan_sel, int delay
511)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512{
Andreas Mohr02330fb2008-05-16 12:18:29 +0200513 unsigned long portbase = chip->mixer_io + reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 unsigned char curr_vol_left = 0, curr_vol_right = 0;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200515 int left_change = 0, right_change = 0;
516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 snd_azf3328_dbgcallenter();
Andreas Mohr02330fb2008-05-16 12:18:29 +0200518
519 if (chan_sel & SET_CHAN_LEFT) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200520 curr_vol_left = inb(portbase + 1);
Andreas Mohr02330fb2008-05-16 12:18:29 +0200521
522 /* take care of muting flag contained in left channel */
523 if (curr_vol_left & AZF_MUTE_BIT)
524 dst_vol_left |= AZF_MUTE_BIT;
525 else
526 dst_vol_left &= ~AZF_MUTE_BIT;
527
528 left_change = (curr_vol_left > dst_vol_left) ? -1 : 1;
529 }
530
531 if (chan_sel & SET_CHAN_RIGHT) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200532 curr_vol_right = inb(portbase + 0);
Andreas Mohr02330fb2008-05-16 12:18:29 +0200533
534 right_change = (curr_vol_right > dst_vol_right) ? -1 : 1;
535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Andreas Mohre2f87262006-05-17 11:04:19 +0200537 do {
Andreas Mohr02330fb2008-05-16 12:18:29 +0200538 if (left_change) {
539 if (curr_vol_left != dst_vol_left) {
540 curr_vol_left += left_change;
541 outb(curr_vol_left, portbase + 1);
542 } else
543 left_change = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 }
Andreas Mohr02330fb2008-05-16 12:18:29 +0200545 if (right_change) {
546 if (curr_vol_right != dst_vol_right) {
547 curr_vol_right += right_change;
548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 /* during volume change, the right channel is crackling
550 * somewhat more than the left channel, unfortunately.
551 * This seems to be a hardware issue. */
Andreas Mohr02330fb2008-05-16 12:18:29 +0200552 outb(curr_vol_right, portbase + 0);
553 } else
554 right_change = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 }
556 if (delay)
557 mdelay(delay);
Andreas Mohr02330fb2008-05-16 12:18:29 +0200558 } while ((left_change) || (right_change));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 snd_azf3328_dbgcallleave();
560}
561
562/*
563 * general mixer element
564 */
Takashi Iwai95de7762005-11-17 15:02:42 +0100565struct azf3328_mixer_reg {
Andreas Mohr02330fb2008-05-16 12:18:29 +0200566 unsigned reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 unsigned int lchan_shift, rchan_shift;
568 unsigned int mask;
569 unsigned int invert: 1;
570 unsigned int stereo: 1;
571 unsigned int enum_c: 4;
Takashi Iwai95de7762005-11-17 15:02:42 +0100572};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574#define COMPOSE_MIXER_REG(reg,lchan_shift,rchan_shift,mask,invert,stereo,enum_c) \
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200575 ((reg) | (lchan_shift << 8) | (rchan_shift << 12) | \
576 (mask << 16) | \
577 (invert << 24) | \
578 (stereo << 25) | \
579 (enum_c << 26))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Takashi Iwai95de7762005-11-17 15:02:42 +0100581static void snd_azf3328_mixer_reg_decode(struct azf3328_mixer_reg *r, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
583 r->reg = val & 0xff;
584 r->lchan_shift = (val >> 8) & 0x0f;
585 r->rchan_shift = (val >> 12) & 0x0f;
586 r->mask = (val >> 16) & 0xff;
587 r->invert = (val >> 24) & 1;
588 r->stereo = (val >> 25) & 1;
589 r->enum_c = (val >> 26) & 0x0f;
590}
591
592/*
593 * mixer switches/volumes
594 */
595
596#define AZF3328_MIXER_SWITCH(xname, reg, shift, invert) \
597{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
598 .info = snd_azf3328_info_mixer, \
599 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
600 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, 0x1, invert, 0, 0), \
601}
602
603#define AZF3328_MIXER_VOL_STEREO(xname, reg, mask, invert) \
604{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
605 .info = snd_azf3328_info_mixer, \
606 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
607 .private_value = COMPOSE_MIXER_REG(reg, 8, 0, mask, invert, 1, 0), \
608}
609
610#define AZF3328_MIXER_VOL_MONO(xname, reg, mask, is_right_chan) \
611{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
612 .info = snd_azf3328_info_mixer, \
613 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
614 .private_value = COMPOSE_MIXER_REG(reg, is_right_chan ? 0 : 8, 0, mask, 1, 0, 0), \
615}
616
617#define AZF3328_MIXER_VOL_SPECIAL(xname, reg, mask, shift, invert) \
618{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
619 .info = snd_azf3328_info_mixer, \
620 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
621 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, mask, invert, 0, 0), \
622}
623
624#define AZF3328_MIXER_ENUM(xname, reg, enum_c, shift) \
625{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
626 .info = snd_azf3328_info_mixer_enum, \
627 .get = snd_azf3328_get_mixer_enum, .put = snd_azf3328_put_mixer_enum, \
628 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, 0, 0, 0, enum_c), \
629}
630
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200631static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100632snd_azf3328_info_mixer(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634{
Takashi Iwai95de7762005-11-17 15:02:42 +0100635 struct azf3328_mixer_reg reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 snd_azf3328_dbgcallenter();
638 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200639 uinfo->type = reg.mask == 1 ?
640 SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 uinfo->count = reg.stereo + 1;
642 uinfo->value.integer.min = 0;
643 uinfo->value.integer.max = reg.mask;
644 snd_azf3328_dbgcallleave();
645 return 0;
646}
647
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200648static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100649snd_azf3328_get_mixer(struct snd_kcontrol *kcontrol,
650 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
Takashi Iwai95de7762005-11-17 15:02:42 +0100652 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
653 struct azf3328_mixer_reg reg;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200654 u16 oreg, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
656 snd_azf3328_dbgcallenter();
657 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
658
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200659 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 val = (oreg >> reg.lchan_shift) & reg.mask;
661 if (reg.invert)
662 val = reg.mask - val;
663 ucontrol->value.integer.value[0] = val;
664 if (reg.stereo) {
665 val = (oreg >> reg.rchan_shift) & reg.mask;
666 if (reg.invert)
667 val = reg.mask - val;
668 ucontrol->value.integer.value[1] = val;
669 }
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200670 snd_azf3328_dbgmixer("get: %02x is %04x -> vol %02lx|%02lx "
671 "(shift %02d|%02d, mask %02x, inv. %d, stereo %d)\n",
672 reg.reg, oreg,
673 ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
674 reg.lchan_shift, reg.rchan_shift, reg.mask, reg.invert, reg.stereo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 snd_azf3328_dbgcallleave();
676 return 0;
677}
678
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200679static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100680snd_azf3328_put_mixer(struct snd_kcontrol *kcontrol,
681 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
Takashi Iwai95de7762005-11-17 15:02:42 +0100683 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
684 struct azf3328_mixer_reg reg;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200685 u16 oreg, nreg, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687 snd_azf3328_dbgcallenter();
688 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200689 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 val = ucontrol->value.integer.value[0] & reg.mask;
691 if (reg.invert)
692 val = reg.mask - val;
693 nreg = oreg & ~(reg.mask << reg.lchan_shift);
694 nreg |= (val << reg.lchan_shift);
695 if (reg.stereo) {
696 val = ucontrol->value.integer.value[1] & reg.mask;
697 if (reg.invert)
698 val = reg.mask - val;
699 nreg &= ~(reg.mask << reg.rchan_shift);
700 nreg |= (val << reg.rchan_shift);
701 }
702 if (reg.mask >= 0x07) /* it's a volume control, so better take care */
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200703 snd_azf3328_mixer_write_volume_gradually(
704 chip, reg.reg, nreg >> 8, nreg & 0xff,
705 /* just set both channels, doesn't matter */
706 SET_CHAN_LEFT|SET_CHAN_RIGHT,
707 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 else
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200709 snd_azf3328_mixer_outw(chip, reg.reg, nreg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200711 snd_azf3328_dbgmixer("put: %02x to %02lx|%02lx, "
712 "oreg %04x; shift %02d|%02d -> nreg %04x; after: %04x\n",
713 reg.reg, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
714 oreg, reg.lchan_shift, reg.rchan_shift,
715 nreg, snd_azf3328_mixer_inw(chip, reg.reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 snd_azf3328_dbgcallleave();
717 return (nreg != oreg);
718}
719
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200720static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100721snd_azf3328_info_mixer_enum(struct snd_kcontrol *kcontrol,
722 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723{
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200724 static const char * const texts1[] = {
Andreas Mohr13769e32006-05-17 11:03:16 +0200725 "Mic1", "Mic2"
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200726 };
727 static const char * const texts2[] = {
Andreas Mohr13769e32006-05-17 11:03:16 +0200728 "Mix", "Mic"
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200729 };
730 static const char * const texts3[] = {
Andreas Mohr02330fb2008-05-16 12:18:29 +0200731 "Mic", "CD", "Video", "Aux",
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200732 "Line", "Mix", "Mix Mono", "Phone"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 };
Andreas Mohr13769e32006-05-17 11:03:16 +0200734 static const char * const texts4[] = {
735 "pre 3D", "post 3D"
736 };
Takashi Iwai95de7762005-11-17 15:02:42 +0100737 struct azf3328_mixer_reg reg;
Andreas Mohr627d3e72008-06-23 11:50:47 +0200738 const char * const *p = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
741 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
742 uinfo->count = (reg.reg == IDX_MIXER_REC_SELECT) ? 2 : 1;
743 uinfo->value.enumerated.items = reg.enum_c;
744 if (uinfo->value.enumerated.item > reg.enum_c - 1U)
745 uinfo->value.enumerated.item = reg.enum_c - 1U;
Andreas Mohre2f87262006-05-17 11:04:19 +0200746 if (reg.reg == IDX_MIXER_ADVCTL2) {
Andreas Mohr13769e32006-05-17 11:03:16 +0200747 switch(reg.lchan_shift) {
748 case 8: /* modem out sel */
Andreas Mohr627d3e72008-06-23 11:50:47 +0200749 p = texts1;
Andreas Mohr13769e32006-05-17 11:03:16 +0200750 break;
751 case 9: /* mono sel source */
Andreas Mohr627d3e72008-06-23 11:50:47 +0200752 p = texts2;
Andreas Mohr13769e32006-05-17 11:03:16 +0200753 break;
754 case 15: /* PCM Out Path */
Andreas Mohr627d3e72008-06-23 11:50:47 +0200755 p = texts4;
Andreas Mohr13769e32006-05-17 11:03:16 +0200756 break;
757 }
Andreas Mohre2f87262006-05-17 11:04:19 +0200758 } else
Andreas Mohr02330fb2008-05-16 12:18:29 +0200759 if (reg.reg == IDX_MIXER_REC_SELECT)
Andreas Mohr627d3e72008-06-23 11:50:47 +0200760 p = texts3;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200761
Andreas Mohr627d3e72008-06-23 11:50:47 +0200762 strcpy(uinfo->value.enumerated.name, p[uinfo->value.enumerated.item]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 return 0;
764}
765
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200766static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100767snd_azf3328_get_mixer_enum(struct snd_kcontrol *kcontrol,
768 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769{
Takashi Iwai95de7762005-11-17 15:02:42 +0100770 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
771 struct azf3328_mixer_reg reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 unsigned short val;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200773
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200775 val = snd_azf3328_mixer_inw(chip, reg.reg);
Andreas Mohre2f87262006-05-17 11:04:19 +0200776 if (reg.reg == IDX_MIXER_REC_SELECT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 ucontrol->value.enumerated.item[0] = (val >> 8) & (reg.enum_c - 1);
778 ucontrol->value.enumerated.item[1] = (val >> 0) & (reg.enum_c - 1);
Andreas Mohre2f87262006-05-17 11:04:19 +0200779 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 ucontrol->value.enumerated.item[0] = (val >> reg.lchan_shift) & (reg.enum_c - 1);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200781
782 snd_azf3328_dbgmixer("get_enum: %02x is %04x -> %d|%d (shift %02d, enum_c %d)\n",
783 reg.reg, val, ucontrol->value.enumerated.item[0], ucontrol->value.enumerated.item[1],
784 reg.lchan_shift, reg.enum_c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 return 0;
786}
787
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200788static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100789snd_azf3328_put_mixer_enum(struct snd_kcontrol *kcontrol,
790 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791{
Takashi Iwai95de7762005-11-17 15:02:42 +0100792 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
793 struct azf3328_mixer_reg reg;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200794 u16 oreg, nreg, val;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200795
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200797 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 val = oreg;
Andreas Mohre2f87262006-05-17 11:04:19 +0200799 if (reg.reg == IDX_MIXER_REC_SELECT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 if (ucontrol->value.enumerated.item[0] > reg.enum_c - 1U ||
801 ucontrol->value.enumerated.item[1] > reg.enum_c - 1U)
802 return -EINVAL;
803 val = (ucontrol->value.enumerated.item[0] << 8) |
804 (ucontrol->value.enumerated.item[1] << 0);
Andreas Mohre2f87262006-05-17 11:04:19 +0200805 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 if (ucontrol->value.enumerated.item[0] > reg.enum_c - 1U)
807 return -EINVAL;
808 val &= ~((reg.enum_c - 1) << reg.lchan_shift);
809 val |= (ucontrol->value.enumerated.item[0] << reg.lchan_shift);
810 }
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200811 snd_azf3328_mixer_outw(chip, reg.reg, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 nreg = val;
813
814 snd_azf3328_dbgmixer("put_enum: %02x to %04x, oreg %04x\n", reg.reg, val, oreg);
815 return (nreg != oreg);
816}
817
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100818static struct snd_kcontrol_new snd_azf3328_mixer_controls[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 AZF3328_MIXER_SWITCH("Master Playback Switch", IDX_MIXER_PLAY_MASTER, 15, 1),
820 AZF3328_MIXER_VOL_STEREO("Master Playback Volume", IDX_MIXER_PLAY_MASTER, 0x1f, 1),
Andreas Mohr627d3e72008-06-23 11:50:47 +0200821 AZF3328_MIXER_SWITCH("PCM Playback Switch", IDX_MIXER_WAVEOUT, 15, 1),
822 AZF3328_MIXER_VOL_STEREO("PCM Playback Volume",
823 IDX_MIXER_WAVEOUT, 0x1f, 1),
824 AZF3328_MIXER_SWITCH("PCM 3D Bypass Playback Switch",
825 IDX_MIXER_ADVCTL2, 7, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 AZF3328_MIXER_SWITCH("FM Playback Switch", IDX_MIXER_FMSYNTH, 15, 1),
827 AZF3328_MIXER_VOL_STEREO("FM Playback Volume", IDX_MIXER_FMSYNTH, 0x1f, 1),
828 AZF3328_MIXER_SWITCH("CD Playback Switch", IDX_MIXER_CDAUDIO, 15, 1),
829 AZF3328_MIXER_VOL_STEREO("CD Playback Volume", IDX_MIXER_CDAUDIO, 0x1f, 1),
830 AZF3328_MIXER_SWITCH("Capture Switch", IDX_MIXER_REC_VOLUME, 15, 1),
831 AZF3328_MIXER_VOL_STEREO("Capture Volume", IDX_MIXER_REC_VOLUME, 0x0f, 0),
832 AZF3328_MIXER_ENUM("Capture Source", IDX_MIXER_REC_SELECT, 8, 0),
833 AZF3328_MIXER_SWITCH("Mic Playback Switch", IDX_MIXER_MIC, 15, 1),
834 AZF3328_MIXER_VOL_MONO("Mic Playback Volume", IDX_MIXER_MIC, 0x1f, 1),
835 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0),
836 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1),
837 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1),
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100838 AZF3328_MIXER_SWITCH("Beep Playback Switch", IDX_MIXER_PCBEEP, 15, 1),
839 AZF3328_MIXER_VOL_SPECIAL("Beep Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1),
841 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1),
842 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1),
843 AZF3328_MIXER_VOL_STEREO("Aux Playback Volume", IDX_MIXER_AUX, 0x1f, 1),
844 AZF3328_MIXER_SWITCH("Modem Playback Switch", IDX_MIXER_MODEMOUT, 15, 1),
845 AZF3328_MIXER_VOL_MONO("Modem Playback Volume", IDX_MIXER_MODEMOUT, 0x1f, 1),
846 AZF3328_MIXER_SWITCH("Modem Capture Switch", IDX_MIXER_MODEMIN, 15, 1),
847 AZF3328_MIXER_VOL_MONO("Modem Capture Volume", IDX_MIXER_MODEMIN, 0x1f, 1),
Andreas Mohr13769e32006-05-17 11:03:16 +0200848 AZF3328_MIXER_ENUM("Mic Select", IDX_MIXER_ADVCTL2, 2, 8),
849 AZF3328_MIXER_ENUM("Mono Output Select", IDX_MIXER_ADVCTL2, 2, 9),
Andreas Mohre24a1212007-03-26 12:49:45 +0200850 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 -0700851 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Treble", IDX_MIXER_BASSTREBLE, 0x07, 1, 0),
852 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Bass", IDX_MIXER_BASSTREBLE, 0x07, 9, 0),
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200853 AZF3328_MIXER_SWITCH("3D Control - Switch", IDX_MIXER_ADVCTL2, 13, 0),
Andreas Mohr13769e32006-05-17 11:03:16 +0200854 AZF3328_MIXER_VOL_SPECIAL("3D Control - Width", IDX_MIXER_ADVCTL1, 0x07, 1, 0), /* "3D Width" */
855 AZF3328_MIXER_VOL_SPECIAL("3D Control - Depth", IDX_MIXER_ADVCTL1, 0x03, 8, 0), /* "Hifi 3D" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856#if MIXER_TESTING
857 AZF3328_MIXER_SWITCH("0", IDX_MIXER_ADVCTL2, 0, 0),
858 AZF3328_MIXER_SWITCH("1", IDX_MIXER_ADVCTL2, 1, 0),
859 AZF3328_MIXER_SWITCH("2", IDX_MIXER_ADVCTL2, 2, 0),
860 AZF3328_MIXER_SWITCH("3", IDX_MIXER_ADVCTL2, 3, 0),
861 AZF3328_MIXER_SWITCH("4", IDX_MIXER_ADVCTL2, 4, 0),
862 AZF3328_MIXER_SWITCH("5", IDX_MIXER_ADVCTL2, 5, 0),
863 AZF3328_MIXER_SWITCH("6", IDX_MIXER_ADVCTL2, 6, 0),
864 AZF3328_MIXER_SWITCH("7", IDX_MIXER_ADVCTL2, 7, 0),
865 AZF3328_MIXER_SWITCH("8", IDX_MIXER_ADVCTL2, 8, 0),
866 AZF3328_MIXER_SWITCH("9", IDX_MIXER_ADVCTL2, 9, 0),
867 AZF3328_MIXER_SWITCH("10", IDX_MIXER_ADVCTL2, 10, 0),
868 AZF3328_MIXER_SWITCH("11", IDX_MIXER_ADVCTL2, 11, 0),
869 AZF3328_MIXER_SWITCH("12", IDX_MIXER_ADVCTL2, 12, 0),
870 AZF3328_MIXER_SWITCH("13", IDX_MIXER_ADVCTL2, 13, 0),
871 AZF3328_MIXER_SWITCH("14", IDX_MIXER_ADVCTL2, 14, 0),
872 AZF3328_MIXER_SWITCH("15", IDX_MIXER_ADVCTL2, 15, 0),
873#endif
874};
875
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100876static u16 __devinitdata snd_azf3328_init_values[][2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 { IDX_MIXER_PLAY_MASTER, MIXER_MUTE_MASK|0x1f1f },
878 { IDX_MIXER_MODEMOUT, MIXER_MUTE_MASK|0x1f1f },
879 { IDX_MIXER_BASSTREBLE, 0x0000 },
880 { IDX_MIXER_PCBEEP, MIXER_MUTE_MASK|0x1f1f },
881 { IDX_MIXER_MODEMIN, MIXER_MUTE_MASK|0x1f1f },
882 { IDX_MIXER_MIC, MIXER_MUTE_MASK|0x001f },
883 { IDX_MIXER_LINEIN, MIXER_MUTE_MASK|0x1f1f },
884 { IDX_MIXER_CDAUDIO, MIXER_MUTE_MASK|0x1f1f },
885 { IDX_MIXER_VIDEO, MIXER_MUTE_MASK|0x1f1f },
886 { IDX_MIXER_AUX, MIXER_MUTE_MASK|0x1f1f },
887 { IDX_MIXER_WAVEOUT, MIXER_MUTE_MASK|0x1f1f },
888 { IDX_MIXER_FMSYNTH, MIXER_MUTE_MASK|0x1f1f },
889 { IDX_MIXER_REC_VOLUME, MIXER_MUTE_MASK|0x0707 },
890};
891
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200892static int __devinit
Takashi Iwai95de7762005-11-17 15:02:42 +0100893snd_azf3328_mixer_new(struct snd_azf3328 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894{
Takashi Iwai95de7762005-11-17 15:02:42 +0100895 struct snd_card *card;
896 const struct snd_kcontrol_new *sw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 unsigned int idx;
898 int err;
899
900 snd_azf3328_dbgcallenter();
Takashi Iwaida3cec32008-08-08 17:12:14 +0200901 if (snd_BUG_ON(!chip || !chip->card))
902 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
904 card = chip->card;
905
906 /* mixer reset */
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200907 snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 /* mute and zero volume channels */
Andreas Mohr02330fb2008-05-16 12:18:29 +0200910 for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_init_values); ++idx) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200911 snd_azf3328_mixer_outw(chip,
912 snd_azf3328_init_values[idx][0],
913 snd_azf3328_init_values[idx][1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 }
Andreas Mohr02330fb2008-05-16 12:18:29 +0200915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 /* add mixer controls */
917 sw = snd_azf3328_mixer_controls;
Andreas Mohr02330fb2008-05-16 12:18:29 +0200918 for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_mixer_controls);
919 ++idx, ++sw) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(sw, chip))) < 0)
921 return err;
922 }
923 snd_component_add(card, "AZF3328 mixer");
924 strcpy(card->mixername, "AZF3328 mixer");
925
926 snd_azf3328_dbgcallleave();
927 return 0;
928}
929
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200930static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100931snd_azf3328_hw_params(struct snd_pcm_substream *substream,
932 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933{
934 int res;
935 snd_azf3328_dbgcallenter();
936 res = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
937 snd_azf3328_dbgcallleave();
938 return res;
939}
940
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200941static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100942snd_azf3328_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
944 snd_azf3328_dbgcallenter();
945 snd_pcm_lib_free_pages(substream);
946 snd_azf3328_dbgcallleave();
947 return 0;
948}
949
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200950static void
Andreas Mohr02330fb2008-05-16 12:18:29 +0200951snd_azf3328_codec_setfmt(struct snd_azf3328 *chip,
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200952 enum snd_azf3328_codec_type codec_type,
Andreas Mohr627d3e72008-06-23 11:50:47 +0200953 enum azf_freq_t bitrate,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 unsigned int format_width,
955 unsigned int channels
956)
957{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 unsigned long flags;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200959 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
960 u16 val = 0xff00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962 snd_azf3328_dbgcallenter();
963 switch (bitrate) {
Andreas Mohr02330fb2008-05-16 12:18:29 +0200964 case AZF_FREQ_4000: val |= SOUNDFORMAT_FREQ_SUSPECTED_4000; break;
965 case AZF_FREQ_4800: val |= SOUNDFORMAT_FREQ_SUSPECTED_4800; break;
966 case AZF_FREQ_5512:
967 /* the AZF3328 names it "5510" for some strange reason */
968 val |= SOUNDFORMAT_FREQ_5510; break;
969 case AZF_FREQ_6620: val |= SOUNDFORMAT_FREQ_6620; break;
970 case AZF_FREQ_8000: val |= SOUNDFORMAT_FREQ_8000; break;
971 case AZF_FREQ_9600: val |= SOUNDFORMAT_FREQ_9600; break;
972 case AZF_FREQ_11025: val |= SOUNDFORMAT_FREQ_11025; break;
973 case AZF_FREQ_13240: val |= SOUNDFORMAT_FREQ_SUSPECTED_13240; break;
974 case AZF_FREQ_16000: val |= SOUNDFORMAT_FREQ_16000; break;
975 case AZF_FREQ_22050: val |= SOUNDFORMAT_FREQ_22050; break;
976 case AZF_FREQ_32000: val |= SOUNDFORMAT_FREQ_32000; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 default:
Takashi Iwai99b359b2005-10-20 18:26:44 +0200978 snd_printk(KERN_WARNING "unknown bitrate %d, assuming 44.1kHz!\n", bitrate);
Andreas Mohr02330fb2008-05-16 12:18:29 +0200979 /* fall-through */
980 case AZF_FREQ_44100: val |= SOUNDFORMAT_FREQ_44100; break;
981 case AZF_FREQ_48000: val |= SOUNDFORMAT_FREQ_48000; break;
982 case AZF_FREQ_66200: val |= SOUNDFORMAT_FREQ_SUSPECTED_66200; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 }
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200984 /* val = 0xff07; 3m27.993s (65301Hz; -> 64000Hz???) hmm, 66120, 65967, 66123 */
985 /* val = 0xff09; 17m15.098s (13123,478Hz; -> 12000Hz???) hmm, 13237.2Hz? */
986 /* val = 0xff0a; 47m30.599s (4764,891Hz; -> 4800Hz???) yup, 4803Hz */
987 /* val = 0xff0c; 57m0.510s (4010,263Hz; -> 4000Hz???) yup, 4003Hz */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 /* val = 0xff05; 5m11.556s (... -> 44100Hz) */
989 /* val = 0xff03; 10m21.529s (21872,463Hz; -> 22050Hz???) */
990 /* val = 0xff0f; 20m41.883s (10937,993Hz; -> 11025Hz???) */
991 /* val = 0xff0d; 41m23.135s (5523,600Hz; -> 5512Hz???) */
992 /* val = 0xff0e; 28m30.777s (8017Hz; -> 8000Hz???) */
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200993
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 if (channels == 2)
995 val |= SOUNDFORMAT_FLAG_2CHANNELS;
996
997 if (format_width == 16)
998 val |= SOUNDFORMAT_FLAG_16BIT;
999
1000 spin_lock_irqsave(&chip->reg_lock, flags);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001001
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 /* set bitrate/format */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001003 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_SOUNDFORMAT, val);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001004
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 /* changing the bitrate/format settings switches off the
1006 * audio output with an annoying click in case of 8/16bit format change
1007 * (maybe shutting down DAC/ADC?), thus immediately
1008 * do some tweaking to reenable it and get rid of the clicking
1009 * (FIXME: yes, it works, but what exactly am I doing here?? :)
1010 * FIXME: does this have some side effects for full-duplex
1011 * or other dramatic side effects? */
Andreas Mohradf59312010-12-27 21:16:43 +01001012 /* do it for non-capture codecs only */
1013 if (codec_type == AZF_CODEC_PLAYBACK)
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001014 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1015 snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS) |
1016 DMA_RUN_SOMETHING1 |
1017 DMA_RUN_SOMETHING2 |
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001018 SOMETHING_ALMOST_ALWAYS_SET |
1019 DMA_EPILOGUE_SOMETHING |
1020 DMA_SOMETHING_ELSE
1021 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
1023 spin_unlock_irqrestore(&chip->reg_lock, flags);
1024 snd_azf3328_dbgcallleave();
1025}
1026
Andreas Mohr02330fb2008-05-16 12:18:29 +02001027static inline void
1028snd_azf3328_codec_setfmt_lowpower(struct snd_azf3328 *chip,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001029 enum snd_azf3328_codec_type codec_type
Andreas Mohr02330fb2008-05-16 12:18:29 +02001030)
1031{
1032 /* choose lowest frequency for low power consumption.
1033 * While this will cause louder noise due to rather coarse frequency,
1034 * it should never matter since output should always
1035 * get disabled properly when idle anyway. */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001036 snd_azf3328_codec_setfmt(chip, codec_type, AZF_FREQ_4000, 8, 1);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001037}
1038
Andreas Mohr627d3e72008-06-23 11:50:47 +02001039static void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001040snd_azf3328_ctrl_reg_6AH_update(struct snd_azf3328 *chip,
Andreas Mohr627d3e72008-06-23 11:50:47 +02001041 unsigned bitmask,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001042 bool enable
Andreas Mohr627d3e72008-06-23 11:50:47 +02001043)
1044{
Andreas Mohr78df6172009-07-12 22:17:54 +02001045 bool do_mask = !enable;
1046 if (do_mask)
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001047 chip->shadow_reg_ctrl_6AH |= bitmask;
Andreas Mohr78df6172009-07-12 22:17:54 +02001048 else
1049 chip->shadow_reg_ctrl_6AH &= ~bitmask;
1050 snd_azf3328_dbgcodec("6AH_update mask 0x%04x do_mask %d: val 0x%04x\n",
1051 bitmask, do_mask, chip->shadow_reg_ctrl_6AH);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001052 snd_azf3328_ctrl_outw(chip, IDX_IO_6AH, chip->shadow_reg_ctrl_6AH);
Andreas Mohr627d3e72008-06-23 11:50:47 +02001053}
1054
Andreas Mohr02330fb2008-05-16 12:18:29 +02001055static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001056snd_azf3328_ctrl_enable_codecs(struct snd_azf3328 *chip, bool enable)
Andreas Mohr02330fb2008-05-16 12:18:29 +02001057{
Andreas Mohr78df6172009-07-12 22:17:54 +02001058 snd_azf3328_dbgcodec("codec_enable %d\n", enable);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001059 /* no idea what exactly is being done here, but I strongly assume it's
1060 * PM related */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001061 snd_azf3328_ctrl_reg_6AH_update(
Andreas Mohr627d3e72008-06-23 11:50:47 +02001062 chip, IO_6A_PAUSE_PLAYBACK_BIT8, enable
Andreas Mohr02330fb2008-05-16 12:18:29 +02001063 );
1064}
1065
1066static void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001067snd_azf3328_ctrl_codec_activity(struct snd_azf3328 *chip,
1068 enum snd_azf3328_codec_type codec_type,
1069 bool enable
Andreas Mohr02330fb2008-05-16 12:18:29 +02001070)
1071{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001072 struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
1073 bool need_change = (codec->running != enable);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001074
Andreas Mohr78df6172009-07-12 22:17:54 +02001075 snd_azf3328_dbgcodec(
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001076 "codec_activity: %s codec, enable %d, need_change %d\n",
1077 codec->name, enable, need_change
Andreas Mohr02330fb2008-05-16 12:18:29 +02001078 );
1079 if (need_change) {
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001080 static const struct {
1081 enum snd_azf3328_codec_type other1;
1082 enum snd_azf3328_codec_type other2;
1083 } peer_codecs[3] =
1084 { { AZF_CODEC_CAPTURE, AZF_CODEC_I2S_OUT },
1085 { AZF_CODEC_PLAYBACK, AZF_CODEC_I2S_OUT },
1086 { AZF_CODEC_PLAYBACK, AZF_CODEC_CAPTURE } };
1087 bool call_function;
1088
1089 if (enable)
1090 /* if enable codec, call enable_codecs func
1091 to enable codec supply... */
1092 call_function = 1;
1093 else {
1094 /* ...otherwise call enable_codecs func
1095 (which globally shuts down operation of codecs)
1096 only in case the other codecs are currently
1097 not active either! */
Andreas Mohr78df6172009-07-12 22:17:54 +02001098 call_function =
1099 ((!chip->codecs[peer_codecs[codec_type].other1]
1100 .running)
1101 && (!chip->codecs[peer_codecs[codec_type].other2]
1102 .running));
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001103 }
1104 if (call_function)
1105 snd_azf3328_ctrl_enable_codecs(chip, enable);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001106
1107 /* ...and adjust clock, too
1108 * (reduce noise and power consumption) */
1109 if (!enable)
1110 snd_azf3328_codec_setfmt_lowpower(
1111 chip,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001112 codec_type
Andreas Mohr02330fb2008-05-16 12:18:29 +02001113 );
Andreas Mohr78df6172009-07-12 22:17:54 +02001114 codec->running = enable;
Andreas Mohr02330fb2008-05-16 12:18:29 +02001115 }
Andreas Mohr02330fb2008-05-16 12:18:29 +02001116}
1117
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001118static void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001119snd_azf3328_codec_setdmaa(struct snd_azf3328 *chip,
1120 enum snd_azf3328_codec_type codec_type,
1121 unsigned long addr,
1122 unsigned int count,
1123 unsigned int size
Andreas Mohr02330fb2008-05-16 12:18:29 +02001124)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001126 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 snd_azf3328_dbgcallenter();
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001128 if (!codec->running) {
1129 /* AZF3328 uses a two buffer pointer DMA transfer approach */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001130
Andreas Mohr78df6172009-07-12 22:17:54 +02001131 unsigned long flags, addr_area2;
Andreas Mohr02330fb2008-05-16 12:18:29 +02001132
1133 /* width 32bit (prevent overflow): */
Andreas Mohr78df6172009-07-12 22:17:54 +02001134 u32 count_areas, lengths;
Andreas Mohr02330fb2008-05-16 12:18:29 +02001135
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001136 count_areas = size/2;
1137 addr_area2 = addr+count_areas;
Andreas Mohr78df6172009-07-12 22:17:54 +02001138 snd_azf3328_dbgcodec("setdma: buffers %08lx[%u] / %08lx[%u]\n",
1139 addr, count_areas, addr_area2, count_areas);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001140
Andreas Mohr79741502010-11-21 12:09:32 +01001141 count_areas--; /* max. index */
1142
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001143 /* build combined I/O buffer length word */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001144 lengths = (count_areas << 16) | (count_areas);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 spin_lock_irqsave(&chip->reg_lock, flags);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001146 snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_START_1, addr);
1147 snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_START_2,
1148 addr_area2);
1149 snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_LENGTHS,
1150 lengths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 spin_unlock_irqrestore(&chip->reg_lock, flags);
1152 }
1153 snd_azf3328_dbgcallleave();
1154}
1155
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001156static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001157snd_azf3328_codec_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158{
1159#if 0
Takashi Iwai95de7762005-11-17 15:02:42 +01001160 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1161 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
1163 unsigned int count = snd_pcm_lib_period_bytes(substream);
1164#endif
1165
1166 snd_azf3328_dbgcallenter();
1167#if 0
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001168 snd_azf3328_codec_setfmt(chip, AZF_CODEC_...,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001169 runtime->rate,
1170 snd_pcm_format_width(runtime->format),
1171 runtime->channels);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001172 snd_azf3328_codec_setdmaa(chip, AZF_CODEC_...,
1173 runtime->dma_addr, count, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174#endif
1175 snd_azf3328_dbgcallleave();
1176 return 0;
1177}
1178
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001179static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001180snd_azf3328_codec_trigger(enum snd_azf3328_codec_type codec_type,
1181 struct snd_pcm_substream *substream, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182{
Takashi Iwai95de7762005-11-17 15:02:42 +01001183 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001184 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
Takashi Iwai95de7762005-11-17 15:02:42 +01001185 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 int result = 0;
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001187 u16 flags1;
1188 bool previously_muted = 0;
1189 bool is_playback_codec = (AZF_CODEC_PLAYBACK == codec_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001191 snd_azf3328_dbgcalls("snd_azf3328_codec_trigger cmd %d\n", cmd);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001192
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 switch (cmd) {
1194 case SNDRV_PCM_TRIGGER_START:
Andreas Mohr78df6172009-07-12 22:17:54 +02001195 snd_azf3328_dbgcodec("START %s\n", codec->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001197 if (is_playback_codec) {
1198 /* mute WaveOut (avoid clicking during setup) */
1199 previously_muted =
1200 snd_azf3328_mixer_set_mute(
1201 chip, IDX_MIXER_WAVEOUT, 1
1202 );
1203 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001205 snd_azf3328_codec_setfmt(chip, codec_type,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001206 runtime->rate,
1207 snd_pcm_format_width(runtime->format),
1208 runtime->channels);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
1210 spin_lock(&chip->reg_lock);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001211 /* first, remember current value: */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001212 flags1 = snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001213
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001214 /* stop transfer */
1215 flags1 &= ~DMA_RESUME;
1216 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001217
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 /* FIXME: clear interrupts or what??? */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001219 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_IRQTYPE, 0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 spin_unlock(&chip->reg_lock);
1221
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001222 snd_azf3328_codec_setdmaa(chip, codec_type, runtime->dma_addr,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001223 snd_pcm_lib_period_bytes(substream),
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001224 snd_pcm_lib_buffer_bytes(substream)
1225 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
1227 spin_lock(&chip->reg_lock);
1228#ifdef WIN9X
1229 /* FIXME: enable playback/recording??? */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001230 flags1 |= DMA_RUN_SOMETHING1 | DMA_RUN_SOMETHING2;
1231 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001233 /* start transfer again */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 /* FIXME: what is this value (0x0010)??? */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001235 flags1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING;
1236 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237#else /* NT4 */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001238 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001239 0x0000);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001240 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1241 DMA_RUN_SOMETHING1);
1242 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1243 DMA_RUN_SOMETHING1 |
1244 DMA_RUN_SOMETHING2);
1245 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001246 DMA_RESUME |
1247 SOMETHING_ALMOST_ALWAYS_SET |
1248 DMA_EPILOGUE_SOMETHING |
1249 DMA_SOMETHING_ELSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250#endif
1251 spin_unlock(&chip->reg_lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001252 snd_azf3328_ctrl_codec_activity(chip, codec_type, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001254 if (is_playback_codec) {
1255 /* now unmute WaveOut */
1256 if (!previously_muted)
1257 snd_azf3328_mixer_set_mute(
1258 chip, IDX_MIXER_WAVEOUT, 0
1259 );
1260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Andreas Mohr78df6172009-07-12 22:17:54 +02001262 snd_azf3328_dbgcodec("STARTED %s\n", codec->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 break;
Andreas Mohrca54bde2006-05-17 11:02:24 +02001264 case SNDRV_PCM_TRIGGER_RESUME:
Andreas Mohr78df6172009-07-12 22:17:54 +02001265 snd_azf3328_dbgcodec("RESUME %s\n", codec->name);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001266 /* resume codec if we were active */
Andreas Mohr02330fb2008-05-16 12:18:29 +02001267 spin_lock(&chip->reg_lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001268 if (codec->running)
1269 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1270 snd_azf3328_codec_inw(
1271 codec, IDX_IO_CODEC_DMA_FLAGS
1272 ) | DMA_RESUME
1273 );
Andreas Mohr02330fb2008-05-16 12:18:29 +02001274 spin_unlock(&chip->reg_lock);
Andreas Mohrca54bde2006-05-17 11:02:24 +02001275 break;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001276 case SNDRV_PCM_TRIGGER_STOP:
Andreas Mohr78df6172009-07-12 22:17:54 +02001277 snd_azf3328_dbgcodec("STOP %s\n", codec->name);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001278
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001279 if (is_playback_codec) {
1280 /* mute WaveOut (avoid clicking during setup) */
1281 previously_muted =
1282 snd_azf3328_mixer_set_mute(
1283 chip, IDX_MIXER_WAVEOUT, 1
1284 );
1285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
1287 spin_lock(&chip->reg_lock);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001288 /* first, remember current value: */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001289 flags1 = snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001291 /* stop transfer */
1292 flags1 &= ~DMA_RESUME;
1293 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001295 /* hmm, is this really required? we're resetting the same bit
1296 * immediately thereafter... */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001297 flags1 |= DMA_RUN_SOMETHING1;
1298 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001300 flags1 &= ~DMA_RUN_SOMETHING1;
1301 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 spin_unlock(&chip->reg_lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001303 snd_azf3328_ctrl_codec_activity(chip, codec_type, 0);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001304
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001305 if (is_playback_codec) {
1306 /* now unmute WaveOut */
1307 if (!previously_muted)
1308 snd_azf3328_mixer_set_mute(
1309 chip, IDX_MIXER_WAVEOUT, 0
1310 );
1311 }
Andreas Mohr02330fb2008-05-16 12:18:29 +02001312
Andreas Mohr78df6172009-07-12 22:17:54 +02001313 snd_azf3328_dbgcodec("STOPPED %s\n", codec->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 break;
Andreas Mohrca54bde2006-05-17 11:02:24 +02001315 case SNDRV_PCM_TRIGGER_SUSPEND:
Andreas Mohr78df6172009-07-12 22:17:54 +02001316 snd_azf3328_dbgcodec("SUSPEND %s\n", codec->name);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001317 /* make sure codec is stopped */
1318 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1319 snd_azf3328_codec_inw(
1320 codec, IDX_IO_CODEC_DMA_FLAGS
1321 ) & ~DMA_RESUME
1322 );
Andreas Mohrca54bde2006-05-17 11:02:24 +02001323 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Takashi Iwai99b359b2005-10-20 18:26:44 +02001325 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 break;
1327 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Takashi Iwai99b359b2005-10-20 18:26:44 +02001328 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 break;
1330 default:
Andreas Mohr78df6172009-07-12 22:17:54 +02001331 snd_printk(KERN_ERR "FIXME: unknown trigger mode!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 return -EINVAL;
1333 }
Andreas Mohr02330fb2008-05-16 12:18:29 +02001334
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 snd_azf3328_dbgcallleave();
1336 return result;
1337}
1338
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001339static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001340snd_azf3328_codec_playback_trigger(struct snd_pcm_substream *substream, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001342 return snd_azf3328_codec_trigger(AZF_CODEC_PLAYBACK, substream, cmd);
1343}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001345static int
1346snd_azf3328_codec_capture_trigger(struct snd_pcm_substream *substream, int cmd)
1347{
1348 return snd_azf3328_codec_trigger(AZF_CODEC_CAPTURE, substream, cmd);
1349}
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001350
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001351static int
1352snd_azf3328_codec_i2s_out_trigger(struct snd_pcm_substream *substream, int cmd)
1353{
1354 return snd_azf3328_codec_trigger(AZF_CODEC_I2S_OUT, substream, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355}
1356
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001357static snd_pcm_uframes_t
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001358snd_azf3328_codec_pointer(struct snd_pcm_substream *substream,
1359 enum snd_azf3328_codec_type codec_type
1360)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001362 const struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1363 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001364 unsigned long bufptr, result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 snd_pcm_uframes_t frmres;
1366
1367#ifdef QUERY_HARDWARE
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001368 bufptr = snd_azf3328_codec_inl(codec, IDX_IO_CODEC_DMA_START_1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369#else
1370 bufptr = substream->runtime->dma_addr;
1371#endif
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001372 result = snd_azf3328_codec_inl(codec, IDX_IO_CODEC_DMA_CURRPOS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001374 /* calculate offset */
1375 result -= bufptr;
1376 frmres = bytes_to_frames( substream->runtime, result);
Andreas Mohradf59312010-12-27 21:16:43 +01001377 snd_azf3328_dbgcodec("%08li %s @ 0x%8lx, frames %8ld\n",
1378 jiffies, codec->name, result, frmres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 return frmres;
1380}
1381
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001382static snd_pcm_uframes_t
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001383snd_azf3328_codec_playback_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001385 return snd_azf3328_codec_pointer(substream, AZF_CODEC_PLAYBACK);
1386}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001388static snd_pcm_uframes_t
1389snd_azf3328_codec_capture_pointer(struct snd_pcm_substream *substream)
1390{
1391 return snd_azf3328_codec_pointer(substream, AZF_CODEC_CAPTURE);
1392}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001394static snd_pcm_uframes_t
1395snd_azf3328_codec_i2s_out_pointer(struct snd_pcm_substream *substream)
1396{
1397 return snd_azf3328_codec_pointer(substream, AZF_CODEC_I2S_OUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398}
1399
Andreas Mohr02330fb2008-05-16 12:18:29 +02001400/******************************************************************/
1401
1402#ifdef SUPPORT_GAMEPORT
1403static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001404snd_azf3328_gameport_irq_enable(struct snd_azf3328 *chip,
1405 bool enable
1406)
Andreas Mohr02330fb2008-05-16 12:18:29 +02001407{
1408 snd_azf3328_io_reg_setb(
1409 chip->game_io+IDX_GAME_HWCONFIG,
1410 GAME_HWCFG_IRQ_ENABLE,
1411 enable
1412 );
1413}
1414
1415static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001416snd_azf3328_gameport_legacy_address_enable(struct snd_azf3328 *chip,
1417 bool enable
1418)
Andreas Mohr02330fb2008-05-16 12:18:29 +02001419{
1420 snd_azf3328_io_reg_setb(
1421 chip->game_io+IDX_GAME_HWCONFIG,
1422 GAME_HWCFG_LEGACY_ADDRESS_ENABLE,
1423 enable
1424 );
1425}
1426
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001427static void
1428snd_azf3328_gameport_set_counter_frequency(struct snd_azf3328 *chip,
1429 unsigned int freq_cfg
1430)
Andreas Mohr02330fb2008-05-16 12:18:29 +02001431{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001432 snd_azf3328_io_reg_setb(
1433 chip->game_io+IDX_GAME_HWCONFIG,
1434 0x02,
1435 (freq_cfg & 1) != 0
1436 );
1437 snd_azf3328_io_reg_setb(
1438 chip->game_io+IDX_GAME_HWCONFIG,
1439 0x04,
1440 (freq_cfg & 2) != 0
1441 );
1442}
1443
1444static inline void
1445snd_azf3328_gameport_axis_circuit_enable(struct snd_azf3328 *chip, bool enable)
1446{
1447 snd_azf3328_ctrl_reg_6AH_update(
Andreas Mohr627d3e72008-06-23 11:50:47 +02001448 chip, IO_6A_SOMETHING2_GAMEPORT, enable
Andreas Mohr02330fb2008-05-16 12:18:29 +02001449 );
1450}
1451
1452static inline void
1453snd_azf3328_gameport_interrupt(struct snd_azf3328 *chip)
1454{
1455 /*
1456 * skeleton handler only
1457 * (we do not want axis reading in interrupt handler - too much load!)
1458 */
1459 snd_azf3328_dbggame("gameport irq\n");
1460
1461 /* this should ACK the gameport IRQ properly, hopefully. */
1462 snd_azf3328_game_inw(chip, IDX_GAME_AXIS_VALUE);
1463}
1464
1465static int
1466snd_azf3328_gameport_open(struct gameport *gameport, int mode)
1467{
1468 struct snd_azf3328 *chip = gameport_get_port_data(gameport);
1469 int res;
1470
1471 snd_azf3328_dbggame("gameport_open, mode %d\n", mode);
1472 switch (mode) {
1473 case GAMEPORT_MODE_COOKED:
1474 case GAMEPORT_MODE_RAW:
1475 res = 0;
1476 break;
1477 default:
1478 res = -1;
1479 break;
1480 }
1481
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001482 snd_azf3328_gameport_set_counter_frequency(chip,
1483 GAME_HWCFG_ADC_COUNTER_FREQ_STD);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001484 snd_azf3328_gameport_axis_circuit_enable(chip, (res == 0));
1485
1486 return res;
1487}
1488
1489static void
1490snd_azf3328_gameport_close(struct gameport *gameport)
1491{
1492 struct snd_azf3328 *chip = gameport_get_port_data(gameport);
1493
1494 snd_azf3328_dbggame("gameport_close\n");
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001495 snd_azf3328_gameport_set_counter_frequency(chip,
1496 GAME_HWCFG_ADC_COUNTER_FREQ_1_200);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001497 snd_azf3328_gameport_axis_circuit_enable(chip, 0);
1498}
1499
1500static int
1501snd_azf3328_gameport_cooked_read(struct gameport *gameport,
1502 int *axes,
1503 int *buttons
1504)
1505{
1506 struct snd_azf3328 *chip = gameport_get_port_data(gameport);
1507 int i;
1508 u8 val;
1509 unsigned long flags;
1510
Takashi Iwaida3cec32008-08-08 17:12:14 +02001511 if (snd_BUG_ON(!chip))
1512 return 0;
Andreas Mohr02330fb2008-05-16 12:18:29 +02001513
1514 spin_lock_irqsave(&chip->reg_lock, flags);
1515 val = snd_azf3328_game_inb(chip, IDX_GAME_LEGACY_COMPATIBLE);
1516 *buttons = (~(val) >> 4) & 0xf;
1517
1518 /* ok, this one is a bit dirty: cooked_read is being polled by a timer,
1519 * thus we're atomic and cannot actively wait in here
1520 * (which would be useful for us since it probably would be better
1521 * to trigger a measurement in here, then wait a short amount of
1522 * time until it's finished, then read values of _this_ measurement).
1523 *
1524 * Thus we simply resort to reading values if they're available already
1525 * and trigger the next measurement.
1526 */
1527
1528 val = snd_azf3328_game_inb(chip, IDX_GAME_AXES_CONFIG);
1529 if (val & GAME_AXES_SAMPLING_READY) {
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001530 for (i = 0; i < ARRAY_SIZE(chip->axes); ++i) {
Andreas Mohr02330fb2008-05-16 12:18:29 +02001531 /* configure the axis to read */
1532 val = (i << 4) | 0x0f;
1533 snd_azf3328_game_outb(chip, IDX_GAME_AXES_CONFIG, val);
1534
1535 chip->axes[i] = snd_azf3328_game_inw(
1536 chip, IDX_GAME_AXIS_VALUE
1537 );
1538 }
1539 }
1540
Andreas Mohradf59312010-12-27 21:16:43 +01001541 /* trigger next sampling of axes, to be evaluated the next time we
Andreas Mohr02330fb2008-05-16 12:18:29 +02001542 * enter this function */
1543
1544 /* for some very, very strange reason we cannot enable
1545 * Measurement Ready monitoring for all axes here,
1546 * at least not when only one joystick connected */
1547 val = 0x03; /* we're able to monitor axes 1 and 2 only */
1548 snd_azf3328_game_outb(chip, IDX_GAME_AXES_CONFIG, val);
1549
1550 snd_azf3328_game_outw(chip, IDX_GAME_AXIS_VALUE, 0xffff);
1551 spin_unlock_irqrestore(&chip->reg_lock, flags);
1552
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001553 for (i = 0; i < ARRAY_SIZE(chip->axes); i++) {
Andreas Mohr02330fb2008-05-16 12:18:29 +02001554 axes[i] = chip->axes[i];
1555 if (axes[i] == 0xffff)
1556 axes[i] = -1;
1557 }
1558
1559 snd_azf3328_dbggame("cooked_read: axes %d %d %d %d buttons %d\n",
1560 axes[0], axes[1], axes[2], axes[3], *buttons
1561 );
1562
1563 return 0;
1564}
1565
1566static int __devinit
1567snd_azf3328_gameport(struct snd_azf3328 *chip, int dev)
1568{
1569 struct gameport *gp;
1570
Andreas Mohr02330fb2008-05-16 12:18:29 +02001571 chip->gameport = gp = gameport_allocate_port();
1572 if (!gp) {
1573 printk(KERN_ERR "azt3328: cannot alloc memory for gameport\n");
1574 return -ENOMEM;
1575 }
1576
1577 gameport_set_name(gp, "AZF3328 Gameport");
1578 gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
1579 gameport_set_dev_parent(gp, &chip->pci->dev);
Andreas Mohr627d3e72008-06-23 11:50:47 +02001580 gp->io = chip->game_io;
Andreas Mohr02330fb2008-05-16 12:18:29 +02001581 gameport_set_port_data(gp, chip);
1582
1583 gp->open = snd_azf3328_gameport_open;
1584 gp->close = snd_azf3328_gameport_close;
1585 gp->fuzz = 16; /* seems ok */
1586 gp->cooked_read = snd_azf3328_gameport_cooked_read;
1587
1588 /* DISABLE legacy address: we don't need it! */
1589 snd_azf3328_gameport_legacy_address_enable(chip, 0);
1590
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001591 snd_azf3328_gameport_set_counter_frequency(chip,
1592 GAME_HWCFG_ADC_COUNTER_FREQ_1_200);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001593 snd_azf3328_gameport_axis_circuit_enable(chip, 0);
1594
1595 gameport_register_port(chip->gameport);
1596
1597 return 0;
1598}
1599
1600static void
1601snd_azf3328_gameport_free(struct snd_azf3328 *chip)
1602{
1603 if (chip->gameport) {
1604 gameport_unregister_port(chip->gameport);
1605 chip->gameport = NULL;
1606 }
1607 snd_azf3328_gameport_irq_enable(chip, 0);
1608}
1609#else
1610static inline int
1611snd_azf3328_gameport(struct snd_azf3328 *chip, int dev) { return -ENOSYS; }
1612static inline void
1613snd_azf3328_gameport_free(struct snd_azf3328 *chip) { }
1614static inline void
1615snd_azf3328_gameport_interrupt(struct snd_azf3328 *chip)
1616{
1617 printk(KERN_WARNING "huh, game port IRQ occurred!?\n");
1618}
1619#endif /* SUPPORT_GAMEPORT */
1620
1621/******************************************************************/
1622
Andreas Mohr627d3e72008-06-23 11:50:47 +02001623static inline void
1624snd_azf3328_irq_log_unknown_type(u8 which)
1625{
Andreas Mohr78df6172009-07-12 22:17:54 +02001626 snd_azf3328_dbgcodec(
Andreas Mohr627d3e72008-06-23 11:50:47 +02001627 "azt3328: unknown IRQ type (%x) occurred, please report!\n",
1628 which
1629 );
1630}
1631
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001632static inline void
1633snd_azf3328_codec_interrupt(struct snd_azf3328 *chip, u8 status)
1634{
1635 u8 which;
1636 enum snd_azf3328_codec_type codec_type;
1637 const struct snd_azf3328_codec_data *codec;
1638
1639 for (codec_type = AZF_CODEC_PLAYBACK;
1640 codec_type <= AZF_CODEC_I2S_OUT;
1641 ++codec_type) {
1642
1643 /* skip codec if there's no interrupt for it */
1644 if (!(status & (1 << codec_type)))
1645 continue;
1646
1647 codec = &chip->codecs[codec_type];
1648
1649 spin_lock(&chip->reg_lock);
1650 which = snd_azf3328_codec_inb(codec, IDX_IO_CODEC_IRQTYPE);
1651 /* ack all IRQ types immediately */
1652 snd_azf3328_codec_outb(codec, IDX_IO_CODEC_IRQTYPE, which);
1653 spin_unlock(&chip->reg_lock);
1654
Andreas Mohr78df6172009-07-12 22:17:54 +02001655 if ((chip->pcm[codec_type]) && (codec->substream)) {
1656 snd_pcm_period_elapsed(codec->substream);
1657 snd_azf3328_dbgcodec("%s period done (#%x), @ %x\n",
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001658 codec->name,
1659 which,
1660 snd_azf3328_codec_inl(
1661 codec, IDX_IO_CODEC_DMA_CURRPOS
1662 )
1663 );
1664 } else
1665 printk(KERN_WARNING "azt3328: irq handler problem!\n");
1666 if (which & IRQ_SOMETHING)
1667 snd_azf3328_irq_log_unknown_type(which);
1668 }
1669}
1670
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001671static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001672snd_azf3328_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673{
Takashi Iwai95de7762005-11-17 15:02:42 +01001674 struct snd_azf3328 *chip = dev_id;
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001675 u8 status;
Andreas Mohr78df6172009-07-12 22:17:54 +02001676#if DEBUG_CODEC
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001677 static unsigned long irq_count;
Andreas Mohr02330fb2008-05-16 12:18:29 +02001678#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001680 status = snd_azf3328_ctrl_inb(chip, IDX_IO_IRQSTATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
1682 /* fast path out, to ease interrupt sharing */
Andreas Mohr02330fb2008-05-16 12:18:29 +02001683 if (!(status &
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001684 (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_I2S_OUT
1685 |IRQ_GAMEPORT|IRQ_MPU401|IRQ_TIMER)
Andreas Mohr02330fb2008-05-16 12:18:29 +02001686 ))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 return IRQ_NONE; /* must be interrupt for another device */
1688
Andreas Mohr78df6172009-07-12 22:17:54 +02001689 snd_azf3328_dbgcodec(
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001690 "irq_count %ld! IDX_IO_IRQSTATUS %04x\n",
Andreas Mohr627d3e72008-06-23 11:50:47 +02001691 irq_count++ /* debug-only */,
Andreas Mohr627d3e72008-06-23 11:50:47 +02001692 status
1693 );
Andreas Mohr02330fb2008-05-16 12:18:29 +02001694
Andreas Mohre2f87262006-05-17 11:04:19 +02001695 if (status & IRQ_TIMER) {
Andreas Mohr78df6172009-07-12 22:17:54 +02001696 /* snd_azf3328_dbgcodec("timer %ld\n",
Andreas Mohr02330fb2008-05-16 12:18:29 +02001697 snd_azf3328_codec_inl(chip, IDX_IO_TIMER_VALUE)
1698 & TIMER_VALUE_MASK
1699 ); */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001700 if (chip->timer)
1701 snd_timer_interrupt(chip->timer, chip->timer->sticks);
1702 /* ACK timer */
1703 spin_lock(&chip->reg_lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001704 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x07);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001705 spin_unlock(&chip->reg_lock);
Andreas Mohr78df6172009-07-12 22:17:54 +02001706 snd_azf3328_dbgcodec("azt3328: timer IRQ\n");
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001707 }
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001708
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001709 if (status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_I2S_OUT))
1710 snd_azf3328_codec_interrupt(chip, status);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001711
Andreas Mohr02330fb2008-05-16 12:18:29 +02001712 if (status & IRQ_GAMEPORT)
1713 snd_azf3328_gameport_interrupt(chip);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001714
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001715 /* MPU401 has less critical IRQ requirements
1716 * than timer and playback/recording, right? */
Andreas Mohre2f87262006-05-17 11:04:19 +02001717 if (status & IRQ_MPU401) {
David Howells7d12e782006-10-05 14:55:46 +01001718 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001719
1720 /* hmm, do we have to ack the IRQ here somehow?
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001721 * If so, then I don't know how yet... */
Andreas Mohr78df6172009-07-12 22:17:54 +02001722 snd_azf3328_dbgcodec("azt3328: MPU401 IRQ\n");
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 return IRQ_HANDLED;
1725}
1726
1727/*****************************************************************/
1728
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001729/* as long as we think we have identical snd_pcm_hardware parameters
1730 for playback, capture and i2s out, we can use the same physical struct
1731 since the struct is simply being copied into a member.
1732*/
1733static const struct snd_pcm_hardware snd_azf3328_hardware =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734{
1735 /* FIXME!! Correct? */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001736 .info = SNDRV_PCM_INFO_MMAP |
1737 SNDRV_PCM_INFO_INTERLEAVED |
1738 SNDRV_PCM_INFO_MMAP_VALID,
1739 .formats = SNDRV_PCM_FMTBIT_S8 |
1740 SNDRV_PCM_FMTBIT_U8 |
1741 SNDRV_PCM_FMTBIT_S16_LE |
1742 SNDRV_PCM_FMTBIT_U16_LE,
1743 .rates = SNDRV_PCM_RATE_5512 |
1744 SNDRV_PCM_RATE_8000_48000 |
1745 SNDRV_PCM_RATE_KNOT,
Andreas Mohr02330fb2008-05-16 12:18:29 +02001746 .rate_min = AZF_FREQ_4000,
1747 .rate_max = AZF_FREQ_66200,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 .channels_min = 1,
1749 .channels_max = 2,
Andreas Mohr79741502010-11-21 12:09:32 +01001750 .buffer_bytes_max = (64*1024),
1751 .period_bytes_min = 1024,
1752 .period_bytes_max = (32*1024),
1753 /* We simply have two DMA areas (instead of a list of descriptors
1754 such as other cards); I believe that this is a fixed hardware
1755 attribute and there isn't much driver magic to be done to expand it.
1756 Thus indicate that we have at least and at most 2 periods. */
1757 .periods_min = 2,
1758 .periods_max = 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 /* FIXME: maybe that card actually has a FIFO?
1760 * Hmm, it seems newer revisions do have one, but we still don't know
1761 * its size... */
1762 .fifo_size = 0,
1763};
1764
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
1766static unsigned int snd_azf3328_fixed_rates[] = {
Andreas Mohr02330fb2008-05-16 12:18:29 +02001767 AZF_FREQ_4000,
1768 AZF_FREQ_4800,
1769 AZF_FREQ_5512,
1770 AZF_FREQ_6620,
1771 AZF_FREQ_8000,
1772 AZF_FREQ_9600,
1773 AZF_FREQ_11025,
1774 AZF_FREQ_13240,
1775 AZF_FREQ_16000,
1776 AZF_FREQ_22050,
1777 AZF_FREQ_32000,
1778 AZF_FREQ_44100,
1779 AZF_FREQ_48000,
1780 AZF_FREQ_66200
1781};
1782
Takashi Iwai95de7762005-11-17 15:02:42 +01001783static struct snd_pcm_hw_constraint_list snd_azf3328_hw_constraints_rates = {
Andreas Mohr02330fb2008-05-16 12:18:29 +02001784 .count = ARRAY_SIZE(snd_azf3328_fixed_rates),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 .list = snd_azf3328_fixed_rates,
1786 .mask = 0,
1787};
1788
1789/*****************************************************************/
1790
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001791static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001792snd_azf3328_pcm_open(struct snd_pcm_substream *substream,
1793 enum snd_azf3328_codec_type codec_type
1794)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795{
Takashi Iwai95de7762005-11-17 15:02:42 +01001796 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1797 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
1799 snd_azf3328_dbgcallenter();
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001800 chip->codecs[codec_type].substream = substream;
1801
1802 /* same parameters for all our codecs - at least we think so... */
1803 runtime->hw = snd_azf3328_hardware;
1804
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1806 &snd_azf3328_hw_constraints_rates);
1807 snd_azf3328_dbgcallleave();
1808 return 0;
1809}
1810
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001811static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001812snd_azf3328_playback_open(struct snd_pcm_substream *substream)
1813{
1814 return snd_azf3328_pcm_open(substream, AZF_CODEC_PLAYBACK);
1815}
1816
1817static int
Takashi Iwai95de7762005-11-17 15:02:42 +01001818snd_azf3328_capture_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001820 return snd_azf3328_pcm_open(substream, AZF_CODEC_CAPTURE);
1821}
1822
1823static int
1824snd_azf3328_i2s_out_open(struct snd_pcm_substream *substream)
1825{
1826 return snd_azf3328_pcm_open(substream, AZF_CODEC_I2S_OUT);
1827}
1828
1829static int
1830snd_azf3328_pcm_close(struct snd_pcm_substream *substream,
1831 enum snd_azf3328_codec_type codec_type
1832)
1833{
Takashi Iwai95de7762005-11-17 15:02:42 +01001834 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
1836 snd_azf3328_dbgcallenter();
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001837 chip->codecs[codec_type].substream = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 snd_azf3328_dbgcallleave();
1839 return 0;
1840}
1841
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001842static int
Takashi Iwai95de7762005-11-17 15:02:42 +01001843snd_azf3328_playback_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001845 return snd_azf3328_pcm_close(substream, AZF_CODEC_PLAYBACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846}
1847
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001848static int
Takashi Iwai95de7762005-11-17 15:02:42 +01001849snd_azf3328_capture_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001851 return snd_azf3328_pcm_close(substream, AZF_CODEC_CAPTURE);
1852}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001854static int
1855snd_azf3328_i2s_out_close(struct snd_pcm_substream *substream)
1856{
1857 return snd_azf3328_pcm_close(substream, AZF_CODEC_I2S_OUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858}
1859
1860/******************************************************************/
1861
Takashi Iwai95de7762005-11-17 15:02:42 +01001862static struct snd_pcm_ops snd_azf3328_playback_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 .open = snd_azf3328_playback_open,
1864 .close = snd_azf3328_playback_close,
1865 .ioctl = snd_pcm_lib_ioctl,
1866 .hw_params = snd_azf3328_hw_params,
1867 .hw_free = snd_azf3328_hw_free,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001868 .prepare = snd_azf3328_codec_prepare,
1869 .trigger = snd_azf3328_codec_playback_trigger,
1870 .pointer = snd_azf3328_codec_playback_pointer
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871};
1872
Takashi Iwai95de7762005-11-17 15:02:42 +01001873static struct snd_pcm_ops snd_azf3328_capture_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 .open = snd_azf3328_capture_open,
1875 .close = snd_azf3328_capture_close,
1876 .ioctl = snd_pcm_lib_ioctl,
1877 .hw_params = snd_azf3328_hw_params,
1878 .hw_free = snd_azf3328_hw_free,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001879 .prepare = snd_azf3328_codec_prepare,
1880 .trigger = snd_azf3328_codec_capture_trigger,
1881 .pointer = snd_azf3328_codec_capture_pointer
1882};
1883
1884static struct snd_pcm_ops snd_azf3328_i2s_out_ops = {
1885 .open = snd_azf3328_i2s_out_open,
1886 .close = snd_azf3328_i2s_out_close,
1887 .ioctl = snd_pcm_lib_ioctl,
1888 .hw_params = snd_azf3328_hw_params,
1889 .hw_free = snd_azf3328_hw_free,
1890 .prepare = snd_azf3328_codec_prepare,
1891 .trigger = snd_azf3328_codec_i2s_out_trigger,
1892 .pointer = snd_azf3328_codec_i2s_out_pointer
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893};
1894
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001895static int __devinit
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001896snd_azf3328_pcm(struct snd_azf3328 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001898enum { AZF_PCMDEV_STD, AZF_PCMDEV_I2S_OUT, NUM_AZF_PCMDEVS }; /* pcm devices */
1899
Takashi Iwai95de7762005-11-17 15:02:42 +01001900 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 int err;
1902
1903 snd_azf3328_dbgcallenter();
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001904
1905 err = snd_pcm_new(chip->card, "AZF3328 DSP", AZF_PCMDEV_STD,
1906 1, 1, &pcm);
1907 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 return err;
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001909 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1910 &snd_azf3328_playback_ops);
1911 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1912 &snd_azf3328_capture_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
1914 pcm->private_data = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 pcm->info_flags = 0;
1916 strcpy(pcm->name, chip->card->shortname);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001917 /* same pcm object for playback/capture (see snd_pcm_new() above) */
1918 chip->pcm[AZF_CODEC_PLAYBACK] = pcm;
1919 chip->pcm[AZF_CODEC_CAPTURE] = pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
1921 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001922 snd_dma_pci_data(chip->pci),
1923 64*1024, 64*1024);
1924
1925 err = snd_pcm_new(chip->card, "AZF3328 I2S OUT", AZF_PCMDEV_I2S_OUT,
1926 1, 0, &pcm);
1927 if (err < 0)
1928 return err;
1929 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1930 &snd_azf3328_i2s_out_ops);
1931
1932 pcm->private_data = chip;
1933 pcm->info_flags = 0;
1934 strcpy(pcm->name, chip->card->shortname);
1935 chip->pcm[AZF_CODEC_I2S_OUT] = pcm;
1936
1937 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1938 snd_dma_pci_data(chip->pci),
1939 64*1024, 64*1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
1941 snd_azf3328_dbgcallleave();
1942 return 0;
1943}
1944
1945/******************************************************************/
1946
Andreas Mohr02330fb2008-05-16 12:18:29 +02001947/*** NOTE: the physical timer resolution actually is 1024000 ticks per second
1948 *** (probably derived from main crystal via a divider of 24),
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001949 *** but announcing those attributes to user-space would make programs
1950 *** configure the timer to a 1 tick value, resulting in an absolutely fatal
1951 *** timer IRQ storm.
1952 *** Thus I chose to announce a down-scaled virtual timer to the outside and
1953 *** calculate real timer countdown values internally.
1954 *** (the scale factor can be set via module parameter "seqtimer_scaling").
1955 ***/
1956
1957static int
Takashi Iwai95de7762005-11-17 15:02:42 +01001958snd_azf3328_timer_start(struct snd_timer *timer)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001959{
Takashi Iwai95de7762005-11-17 15:02:42 +01001960 struct snd_azf3328 *chip;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001961 unsigned long flags;
1962 unsigned int delay;
1963
1964 snd_azf3328_dbgcallenter();
1965 chip = snd_timer_chip(timer);
1966 delay = ((timer->sticks * seqtimer_scaling) - 1) & TIMER_VALUE_MASK;
Andreas Mohre2f87262006-05-17 11:04:19 +02001967 if (delay < 49) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001968 /* uhoh, that's not good, since user-space won't know about
1969 * this timing tweak
1970 * (we need to do it to avoid a lockup, though) */
1971
1972 snd_azf3328_dbgtimer("delay was too low (%d)!\n", delay);
1973 delay = 49; /* minimum time is 49 ticks */
1974 }
Andreas Mohradf59312010-12-27 21:16:43 +01001975 snd_azf3328_dbgtimer("setting timer countdown value %d\n", delay);
Andreas Mohr02330fb2008-05-16 12:18:29 +02001976 delay |= TIMER_COUNTDOWN_ENABLE | TIMER_IRQ_ENABLE;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001977 spin_lock_irqsave(&chip->reg_lock, flags);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001978 snd_azf3328_ctrl_outl(chip, IDX_IO_TIMER_VALUE, delay);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001979 spin_unlock_irqrestore(&chip->reg_lock, flags);
1980 snd_azf3328_dbgcallleave();
1981 return 0;
1982}
1983
1984static int
Takashi Iwai95de7762005-11-17 15:02:42 +01001985snd_azf3328_timer_stop(struct snd_timer *timer)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001986{
Takashi Iwai95de7762005-11-17 15:02:42 +01001987 struct snd_azf3328 *chip;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001988 unsigned long flags;
1989
1990 snd_azf3328_dbgcallenter();
1991 chip = snd_timer_chip(timer);
1992 spin_lock_irqsave(&chip->reg_lock, flags);
1993 /* disable timer countdown and interrupt */
Andreas Mohr79741502010-11-21 12:09:32 +01001994 /* Hmm, should we write TIMER_IRQ_ACK here?
1995 YES indeed, otherwise a rogue timer operation - which prompts
1996 ALSA(?) to call repeated stop() in vain, but NOT start() -
1997 will never end (value 0x03 is kept shown in control byte).
1998 Simply manually poking 0x04 _once_ immediately successfully stops
1999 the hardware/ALSA interrupt activity. */
2000 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x04);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002001 spin_unlock_irqrestore(&chip->reg_lock, flags);
2002 snd_azf3328_dbgcallleave();
2003 return 0;
2004}
2005
2006
2007static int
Takashi Iwai95de7762005-11-17 15:02:42 +01002008snd_azf3328_timer_precise_resolution(struct snd_timer *timer,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002009 unsigned long *num, unsigned long *den)
2010{
2011 snd_azf3328_dbgcallenter();
2012 *num = 1;
2013 *den = 1024000 / seqtimer_scaling;
2014 snd_azf3328_dbgcallleave();
2015 return 0;
2016}
2017
Takashi Iwai95de7762005-11-17 15:02:42 +01002018static struct snd_timer_hardware snd_azf3328_timer_hw = {
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002019 .flags = SNDRV_TIMER_HW_AUTO,
2020 .resolution = 977, /* 1000000/1024000 = 0.9765625us */
2021 .ticks = 1024000, /* max tick count, defined by the value register; actually it's not 1024000, but 1048576, but we don't care */
2022 .start = snd_azf3328_timer_start,
2023 .stop = snd_azf3328_timer_stop,
2024 .precise_resolution = snd_azf3328_timer_precise_resolution,
2025};
2026
2027static int __devinit
Takashi Iwai95de7762005-11-17 15:02:42 +01002028snd_azf3328_timer(struct snd_azf3328 *chip, int device)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002029{
Takashi Iwai95de7762005-11-17 15:02:42 +01002030 struct snd_timer *timer = NULL;
2031 struct snd_timer_id tid;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002032 int err;
2033
2034 snd_azf3328_dbgcallenter();
2035 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
2036 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
2037 tid.card = chip->card->number;
2038 tid.device = device;
2039 tid.subdevice = 0;
2040
2041 snd_azf3328_timer_hw.resolution *= seqtimer_scaling;
2042 snd_azf3328_timer_hw.ticks /= seqtimer_scaling;
Andreas Mohr02330fb2008-05-16 12:18:29 +02002043
2044 err = snd_timer_new(chip->card, "AZF3328", &tid, &timer);
2045 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002046 goto out;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002047
2048 strcpy(timer->name, "AZF3328 timer");
2049 timer->private_data = chip;
2050 timer->hw = snd_azf3328_timer_hw;
2051
2052 chip->timer = timer;
2053
Andreas Mohr02330fb2008-05-16 12:18:29 +02002054 snd_azf3328_timer_stop(timer);
2055
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002056 err = 0;
2057
2058out:
2059 snd_azf3328_dbgcallleave();
2060 return err;
2061}
2062
2063/******************************************************************/
2064
Andreas Mohr02330fb2008-05-16 12:18:29 +02002065static int
2066snd_azf3328_free(struct snd_azf3328 *chip)
2067{
2068 if (chip->irq < 0)
2069 goto __end_hw;
2070
2071 /* reset (close) mixer:
2072 * first mute master volume, then reset
2073 */
2074 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1);
2075 snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
2076
2077 snd_azf3328_timer_stop(chip->timer);
2078 snd_azf3328_gameport_free(chip);
2079
2080 if (chip->irq >= 0)
2081 synchronize_irq(chip->irq);
2082__end_hw:
2083 if (chip->irq >= 0)
2084 free_irq(chip->irq, chip);
2085 pci_release_regions(chip->pci);
2086 pci_disable_device(chip->pci);
2087
2088 kfree(chip);
2089 return 0;
2090}
2091
2092static int
2093snd_azf3328_dev_free(struct snd_device *device)
2094{
2095 struct snd_azf3328 *chip = device->device_data;
2096 return snd_azf3328_free(chip);
2097}
2098
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099#if 0
2100/* check whether a bit can be modified */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002101static void
Andreas Mohr02330fb2008-05-16 12:18:29 +02002102snd_azf3328_test_bit(unsigned unsigned reg, int bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103{
2104 unsigned char val, valoff, valon;
2105
2106 val = inb(reg);
2107
2108 outb(val & ~(1 << bit), reg);
2109 valoff = inb(reg);
2110
2111 outb(val|(1 << bit), reg);
2112 valon = inb(reg);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002113
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 outb(val, reg);
2115
Andreas Mohr78df6172009-07-12 22:17:54 +02002116 printk(KERN_DEBUG "reg %04x bit %d: %02x %02x %02x\n",
Andreas Mohr02330fb2008-05-16 12:18:29 +02002117 reg, bit, val, valoff, valon
2118 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119}
2120#endif
2121
Andreas Mohr02330fb2008-05-16 12:18:29 +02002122static inline void
Takashi Iwai95de7762005-11-17 15:02:42 +01002123snd_azf3328_debug_show_ports(const struct snd_azf3328 *chip)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002124{
Andreas Mohr02330fb2008-05-16 12:18:29 +02002125#if DEBUG_MISC
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002126 u16 tmp;
2127
Andreas Mohr02330fb2008-05-16 12:18:29 +02002128 snd_azf3328_dbgmisc(
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002129 "ctrl_io 0x%lx, game_io 0x%lx, mpu_io 0x%lx, "
Andreas Mohr02330fb2008-05-16 12:18:29 +02002130 "opl3_io 0x%lx, mixer_io 0x%lx, irq %d\n",
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002131 chip->ctrl_io, chip->game_io, chip->mpu_io,
Andreas Mohr02330fb2008-05-16 12:18:29 +02002132 chip->opl3_io, chip->mixer_io, chip->irq
2133 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002134
Andreas Mohr02330fb2008-05-16 12:18:29 +02002135 snd_azf3328_dbgmisc("game %02x %02x %02x %02x %02x %02x\n",
2136 snd_azf3328_game_inb(chip, 0),
2137 snd_azf3328_game_inb(chip, 1),
2138 snd_azf3328_game_inb(chip, 2),
2139 snd_azf3328_game_inb(chip, 3),
2140 snd_azf3328_game_inb(chip, 4),
2141 snd_azf3328_game_inb(chip, 5)
2142 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002143
Andreas Mohr02330fb2008-05-16 12:18:29 +02002144 for (tmp = 0; tmp < 0x07; tmp += 1)
2145 snd_azf3328_dbgmisc("mpu_io 0x%04x\n", inb(chip->mpu_io + tmp));
2146
2147 for (tmp = 0; tmp <= 0x07; tmp += 1)
2148 snd_azf3328_dbgmisc("0x%02x: game200 0x%04x, game208 0x%04x\n",
2149 tmp, inb(0x200 + tmp), inb(0x208 + tmp));
2150
2151 for (tmp = 0; tmp <= 0x01; tmp += 1)
2152 snd_azf3328_dbgmisc(
2153 "0x%02x: mpu300 0x%04x, mpu310 0x%04x, mpu320 0x%04x, "
2154 "mpu330 0x%04x opl388 0x%04x opl38c 0x%04x\n",
2155 tmp,
2156 inb(0x300 + tmp),
2157 inb(0x310 + tmp),
2158 inb(0x320 + tmp),
2159 inb(0x330 + tmp),
2160 inb(0x388 + tmp),
2161 inb(0x38c + tmp)
2162 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002163
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002164 for (tmp = 0; tmp < AZF_IO_SIZE_CTRL; tmp += 2)
2165 snd_azf3328_dbgmisc("ctrl 0x%02x: 0x%04x\n",
2166 tmp, snd_azf3328_ctrl_inw(chip, tmp)
Andreas Mohr02330fb2008-05-16 12:18:29 +02002167 );
Andreas Mohre24a1212007-03-26 12:49:45 +02002168
2169 for (tmp = 0; tmp < AZF_IO_SIZE_MIXER; tmp += 2)
Andreas Mohr02330fb2008-05-16 12:18:29 +02002170 snd_azf3328_dbgmisc("mixer 0x%02x: 0x%04x\n",
2171 tmp, snd_azf3328_mixer_inw(chip, tmp)
2172 );
2173#endif /* DEBUG_MISC */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002174}
2175
2176static int __devinit
Takashi Iwai95de7762005-11-17 15:02:42 +01002177snd_azf3328_create(struct snd_card *card,
Andreas Mohr02330fb2008-05-16 12:18:29 +02002178 struct pci_dev *pci,
2179 unsigned long device_type,
2180 struct snd_azf3328 **rchip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181{
Takashi Iwai95de7762005-11-17 15:02:42 +01002182 struct snd_azf3328 *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 int err;
Takashi Iwai95de7762005-11-17 15:02:42 +01002184 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 .dev_free = snd_azf3328_dev_free,
2186 };
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002187 u8 dma_init;
2188 enum snd_azf3328_codec_type codec_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189
2190 *rchip = NULL;
2191
Andreas Mohr02330fb2008-05-16 12:18:29 +02002192 err = pci_enable_device(pci);
2193 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 return err;
2195
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002196 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 if (chip == NULL) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002198 err = -ENOMEM;
2199 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 }
2201 spin_lock_init(&chip->reg_lock);
2202 chip->card = card;
2203 chip->pci = pci;
2204 chip->irq = -1;
2205
2206 /* check if we can restrict PCI DMA transfers to 24 bits */
Yang Hongyang2f4f27d2009-04-06 19:01:18 -07002207 if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 ||
2208 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) {
Andreas Mohr02330fb2008-05-16 12:18:29 +02002209 snd_printk(KERN_ERR "architecture does not support "
2210 "24bit PCI busmaster DMA\n"
2211 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002212 err = -ENXIO;
2213 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 }
2215
Andreas Mohr02330fb2008-05-16 12:18:29 +02002216 err = pci_request_regions(pci, "Aztech AZF3328");
2217 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002218 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002220 chip->ctrl_io = pci_resource_start(pci, 0);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002221 chip->game_io = pci_resource_start(pci, 1);
2222 chip->mpu_io = pci_resource_start(pci, 2);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002223 chip->opl3_io = pci_resource_start(pci, 3);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002224 chip->mixer_io = pci_resource_start(pci, 4);
2225
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002226 chip->codecs[AZF_CODEC_PLAYBACK].io_base =
2227 chip->ctrl_io + AZF_IO_OFFS_CODEC_PLAYBACK;
2228 chip->codecs[AZF_CODEC_PLAYBACK].name = "PLAYBACK";
2229 chip->codecs[AZF_CODEC_CAPTURE].io_base =
2230 chip->ctrl_io + AZF_IO_OFFS_CODEC_CAPTURE;
2231 chip->codecs[AZF_CODEC_CAPTURE].name = "CAPTURE";
2232 chip->codecs[AZF_CODEC_I2S_OUT].io_base =
2233 chip->ctrl_io + AZF_IO_OFFS_CODEC_I2S_OUT;
2234 chip->codecs[AZF_CODEC_I2S_OUT].name = "I2S_OUT";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
Takashi Iwai437a5a42006-11-21 12:14:23 +01002236 if (request_irq(pci->irq, snd_azf3328_interrupt,
2237 IRQF_SHARED, card->shortname, chip)) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002238 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002239 err = -EBUSY;
2240 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 }
2242 chip->irq = pci->irq;
2243 pci_set_master(pci);
2244 synchronize_irq(chip->irq);
2245
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002246 snd_azf3328_debug_show_ports(chip);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002247
2248 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
2249 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002250 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251
2252 /* create mixer interface & switches */
Andreas Mohr02330fb2008-05-16 12:18:29 +02002253 err = snd_azf3328_mixer_new(chip);
2254 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002255 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002257 /* standard codec init stuff */
2258 /* default DMA init value */
2259 dma_init = DMA_RUN_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002261 for (codec_type = AZF_CODEC_PLAYBACK;
2262 codec_type <= AZF_CODEC_I2S_OUT; ++codec_type) {
2263 struct snd_azf3328_codec_data *codec =
2264 &chip->codecs[codec_type];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265
Andreas Mohradf59312010-12-27 21:16:43 +01002266 /* shutdown codecs to reduce power / noise */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002267 /* have ...ctrl_codec_activity() act properly */
2268 codec->running = 1;
2269 snd_azf3328_ctrl_codec_activity(chip, codec_type, 0);
2270
2271 spin_lock_irq(&chip->reg_lock);
2272 snd_azf3328_codec_outb(codec, IDX_IO_CODEC_DMA_FLAGS,
2273 dma_init);
2274 spin_unlock_irq(&chip->reg_lock);
2275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
2277 snd_card_set_dev(card, &pci->dev);
2278
2279 *rchip = chip;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002280
2281 err = 0;
2282 goto out;
2283
2284out_err:
2285 if (chip)
2286 snd_azf3328_free(chip);
2287 pci_disable_device(pci);
2288
2289out:
2290 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291}
2292
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002293static int __devinit
2294snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295{
2296 static int dev;
Takashi Iwai95de7762005-11-17 15:02:42 +01002297 struct snd_card *card;
2298 struct snd_azf3328 *chip;
2299 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 int err;
2301
2302 snd_azf3328_dbgcallenter();
2303 if (dev >= SNDRV_CARDS)
2304 return -ENODEV;
2305 if (!enable[dev]) {
2306 dev++;
2307 return -ENOENT;
2308 }
2309
Takashi Iwaie58de7b2008-12-28 16:44:30 +01002310 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2311 if (err < 0)
2312 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313
2314 strcpy(card->driver, "AZF3328");
2315 strcpy(card->shortname, "Aztech AZF3328 (PCI168)");
2316
Andreas Mohr02330fb2008-05-16 12:18:29 +02002317 err = snd_azf3328_create(card, pci, pci_id->driver_data, &chip);
2318 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002319 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Andreas Mohrca54bde2006-05-17 11:02:24 +02002321 card->private_data = chip;
2322
Andreas Mohr78df6172009-07-12 22:17:54 +02002323 /* chose to use MPU401_HW_AZT2320 ID instead of MPU401_HW_MPU401,
2324 since our hardware ought to be similar, thus use same ID. */
Andreas Mohr02330fb2008-05-16 12:18:29 +02002325 err = snd_mpu401_uart_new(
Andreas Mohr78df6172009-07-12 22:17:54 +02002326 card, 0,
2327 MPU401_HW_AZT2320, chip->mpu_io, MPU401_INFO_INTEGRATED,
Andreas Mohr02330fb2008-05-16 12:18:29 +02002328 pci->irq, 0, &chip->rmidi
2329 );
2330 if (err < 0) {
2331 snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n",
2332 chip->mpu_io
2333 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002334 goto out_err;
2335 }
2336
Andreas Mohr02330fb2008-05-16 12:18:29 +02002337 err = snd_azf3328_timer(chip, 0);
2338 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002339 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002341 err = snd_azf3328_pcm(chip);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002342 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002343 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
Andreas Mohr02330fb2008-05-16 12:18:29 +02002345 if (snd_opl3_create(card, chip->opl3_io, chip->opl3_io+2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 OPL3_HW_AUTO, 1, &opl3) < 0) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002347 snd_printk(KERN_ERR "azf3328: no OPL3 device at 0x%lx-0x%lx?\n",
Andreas Mohr02330fb2008-05-16 12:18:29 +02002348 chip->opl3_io, chip->opl3_io+2
2349 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 } else {
Andreas Mohr02330fb2008-05-16 12:18:29 +02002351 /* need to use IDs 1, 2 since ID 0 is snd_azf3328_timer above */
2352 err = snd_opl3_timer_new(opl3, 1, 2);
2353 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002354 goto out_err;
Andreas Mohr02330fb2008-05-16 12:18:29 +02002355 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
2356 if (err < 0)
2357 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 }
2359
Andreas Mohrca54bde2006-05-17 11:02:24 +02002360 opl3->private_data = chip;
2361
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 sprintf(card->longname, "%s at 0x%lx, irq %i",
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002363 card->shortname, chip->ctrl_io, chip->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
Andreas Mohr02330fb2008-05-16 12:18:29 +02002365 err = snd_card_register(card);
2366 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002367 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
2369#ifdef MODULE
Andreas Mohr78df6172009-07-12 22:17:54 +02002370 printk(KERN_INFO
Andreas Mohre24a1212007-03-26 12:49:45 +02002371"azt3328: Sound driver for Aztech AZF3328-based soundcards such as PCI168.\n"
2372"azt3328: Hardware was completely undocumented, unfortunately.\n"
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002373"azt3328: Feel free to contact andi AT lisas.de for bug reports etc.!\n"
2374"azt3328: User-scalable sequencer timer set to %dHz (1024000Hz / %d).\n",
2375 1024000 / seqtimer_scaling, seqtimer_scaling);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376#endif
2377
Andreas Mohr02330fb2008-05-16 12:18:29 +02002378 snd_azf3328_gameport(chip, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
2380 pci_set_drvdata(pci, card);
2381 dev++;
2382
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002383 err = 0;
2384 goto out;
Andreas Mohr02330fb2008-05-16 12:18:29 +02002385
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002386out_err:
Andreas Mohr02330fb2008-05-16 12:18:29 +02002387 snd_printk(KERN_ERR "azf3328: something failed, exiting\n");
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002388 snd_card_free(card);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002389
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002390out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 snd_azf3328_dbgcallleave();
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002392 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393}
2394
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002395static void __devexit
2396snd_azf3328_remove(struct pci_dev *pci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397{
2398 snd_azf3328_dbgcallenter();
2399 snd_card_free(pci_get_drvdata(pci));
2400 pci_set_drvdata(pci, NULL);
2401 snd_azf3328_dbgcallleave();
2402}
2403
Andreas Mohrca54bde2006-05-17 11:02:24 +02002404#ifdef CONFIG_PM
Andreas Mohr78df6172009-07-12 22:17:54 +02002405static inline void
2406snd_azf3328_suspend_regs(unsigned long io_addr, unsigned count, u32 *saved_regs)
2407{
2408 unsigned reg;
2409
2410 for (reg = 0; reg < count; ++reg) {
2411 *saved_regs = inl(io_addr);
2412 snd_azf3328_dbgpm("suspend: io 0x%04lx: 0x%08x\n",
2413 io_addr, *saved_regs);
2414 ++saved_regs;
2415 io_addr += sizeof(*saved_regs);
2416 }
2417}
2418
Andreas Mohrca54bde2006-05-17 11:02:24 +02002419static int
2420snd_azf3328_suspend(struct pci_dev *pci, pm_message_t state)
2421{
2422 struct snd_card *card = pci_get_drvdata(pci);
2423 struct snd_azf3328 *chip = card->private_data;
Andreas Mohr78df6172009-07-12 22:17:54 +02002424 u16 *saved_regs_ctrl_u16;
Andreas Mohrca54bde2006-05-17 11:02:24 +02002425
2426 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002427
Andreas Mohradf59312010-12-27 21:16:43 +01002428 /* same pcm object for playback/capture */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002429 snd_pcm_suspend_all(chip->pcm[AZF_CODEC_PLAYBACK]);
2430 snd_pcm_suspend_all(chip->pcm[AZF_CODEC_I2S_OUT]);
Andreas Mohrca54bde2006-05-17 11:02:24 +02002431
Andreas Mohr78df6172009-07-12 22:17:54 +02002432 snd_azf3328_suspend_regs(chip->mixer_io,
2433 ARRAY_SIZE(chip->saved_regs_mixer), chip->saved_regs_mixer);
Andreas Mohrca54bde2006-05-17 11:02:24 +02002434
2435 /* make sure to disable master volume etc. to prevent looping sound */
2436 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1);
2437 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
Andreas Mohr02330fb2008-05-16 12:18:29 +02002438
Andreas Mohr78df6172009-07-12 22:17:54 +02002439 snd_azf3328_suspend_regs(chip->ctrl_io,
2440 ARRAY_SIZE(chip->saved_regs_ctrl), chip->saved_regs_ctrl);
Andreas Mohr627d3e72008-06-23 11:50:47 +02002441
2442 /* manually store the one currently relevant write-only reg, too */
Andreas Mohr78df6172009-07-12 22:17:54 +02002443 saved_regs_ctrl_u16 = (u16 *)chip->saved_regs_ctrl;
2444 saved_regs_ctrl_u16[IDX_IO_6AH / 2] = chip->shadow_reg_ctrl_6AH;
Andreas Mohr627d3e72008-06-23 11:50:47 +02002445
Andreas Mohr78df6172009-07-12 22:17:54 +02002446 snd_azf3328_suspend_regs(chip->game_io,
2447 ARRAY_SIZE(chip->saved_regs_game), chip->saved_regs_game);
2448 snd_azf3328_suspend_regs(chip->mpu_io,
2449 ARRAY_SIZE(chip->saved_regs_mpu), chip->saved_regs_mpu);
2450 snd_azf3328_suspend_regs(chip->opl3_io,
2451 ARRAY_SIZE(chip->saved_regs_opl3), chip->saved_regs_opl3);
Andreas Mohrca54bde2006-05-17 11:02:24 +02002452
Andreas Mohrca54bde2006-05-17 11:02:24 +02002453 pci_disable_device(pci);
2454 pci_save_state(pci);
Takashi Iwai30b35392006-10-11 18:52:53 +02002455 pci_set_power_state(pci, pci_choose_state(pci, state));
Andreas Mohrca54bde2006-05-17 11:02:24 +02002456 return 0;
2457}
2458
Andreas Mohr78df6172009-07-12 22:17:54 +02002459static inline void
2460snd_azf3328_resume_regs(const u32 *saved_regs,
2461 unsigned long io_addr,
2462 unsigned count
2463)
2464{
2465 unsigned reg;
2466
2467 for (reg = 0; reg < count; ++reg) {
2468 outl(*saved_regs, io_addr);
2469 snd_azf3328_dbgpm("resume: io 0x%04lx: 0x%08x --> 0x%08x\n",
2470 io_addr, *saved_regs, inl(io_addr));
2471 ++saved_regs;
2472 io_addr += sizeof(*saved_regs);
2473 }
2474}
2475
Andreas Mohrca54bde2006-05-17 11:02:24 +02002476static int
2477snd_azf3328_resume(struct pci_dev *pci)
2478{
2479 struct snd_card *card = pci_get_drvdata(pci);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002480 const struct snd_azf3328 *chip = card->private_data;
Andreas Mohrca54bde2006-05-17 11:02:24 +02002481
Andreas Mohrca54bde2006-05-17 11:02:24 +02002482 pci_set_power_state(pci, PCI_D0);
Takashi Iwai30b35392006-10-11 18:52:53 +02002483 pci_restore_state(pci);
2484 if (pci_enable_device(pci) < 0) {
2485 printk(KERN_ERR "azt3328: pci_enable_device failed, "
2486 "disabling device\n");
2487 snd_card_disconnect(card);
2488 return -EIO;
2489 }
Andreas Mohrca54bde2006-05-17 11:02:24 +02002490 pci_set_master(pci);
2491
Andreas Mohr78df6172009-07-12 22:17:54 +02002492 snd_azf3328_resume_regs(chip->saved_regs_game, chip->game_io,
2493 ARRAY_SIZE(chip->saved_regs_game));
2494 snd_azf3328_resume_regs(chip->saved_regs_mpu, chip->mpu_io,
2495 ARRAY_SIZE(chip->saved_regs_mpu));
2496 snd_azf3328_resume_regs(chip->saved_regs_opl3, chip->opl3_io,
2497 ARRAY_SIZE(chip->saved_regs_opl3));
2498
2499 snd_azf3328_resume_regs(chip->saved_regs_mixer, chip->mixer_io,
2500 ARRAY_SIZE(chip->saved_regs_mixer));
2501
2502 /* unfortunately with 32bit transfers, IDX_MIXER_PLAY_MASTER (0x02)
2503 and IDX_MIXER_RESET (offset 0x00) get touched at the same time,
2504 resulting in a mixer reset condition persisting until _after_
2505 master vol was restored. Thus master vol needs an extra restore. */
2506 outw(((u16 *)chip->saved_regs_mixer)[1], chip->mixer_io + 2);
2507
2508 snd_azf3328_resume_regs(chip->saved_regs_ctrl, chip->ctrl_io,
2509 ARRAY_SIZE(chip->saved_regs_ctrl));
Andreas Mohrca54bde2006-05-17 11:02:24 +02002510
2511 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
2512 return 0;
2513}
Andreas Mohr02330fb2008-05-16 12:18:29 +02002514#endif /* CONFIG_PM */
Andreas Mohrca54bde2006-05-17 11:02:24 +02002515
2516
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517static struct pci_driver driver = {
2518 .name = "AZF3328",
2519 .id_table = snd_azf3328_ids,
2520 .probe = snd_azf3328_probe,
2521 .remove = __devexit_p(snd_azf3328_remove),
Andreas Mohrca54bde2006-05-17 11:02:24 +02002522#ifdef CONFIG_PM
2523 .suspend = snd_azf3328_suspend,
2524 .resume = snd_azf3328_resume,
2525#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526};
2527
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002528static int __init
2529alsa_card_azf3328_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530{
2531 int err;
2532 snd_azf3328_dbgcallenter();
Takashi Iwai01d25d42005-04-11 16:58:24 +02002533 err = pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 snd_azf3328_dbgcallleave();
2535 return err;
2536}
2537
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002538static void __exit
2539alsa_card_azf3328_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540{
2541 snd_azf3328_dbgcallenter();
2542 pci_unregister_driver(&driver);
2543 snd_azf3328_dbgcallleave();
2544}
2545
2546module_init(alsa_card_azf3328_init)
2547module_exit(alsa_card_azf3328_exit)