blob: b1fad46a7b02afe7be74c40354f7fc1e148fabdf [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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-05-16 12:18:29 +0200144 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 * BUGS
Andreas Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr02330fba2008-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 Mohr34585592010-12-27 21:17:11 +0100297 unsigned int dma_base; /* helper to avoid an indirection in hotpath */
Andreas Mohr02330fba2008-05-16 12:18:29 +0200298 struct snd_pcm_substream *substream;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200299 bool running;
300 const char *name;
Andreas Mohr02330fba2008-05-16 12:18:29 +0200301};
302
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200303enum snd_azf3328_codec_type {
Andreas Mohradf59312010-12-27 21:16:43 +0100304 /* warning: fixed indices (also used for bitmask checks!) */
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200305 AZF_CODEC_PLAYBACK = 0,
306 AZF_CODEC_CAPTURE = 1,
307 AZF_CODEC_I2S_OUT = 2,
Andreas Mohr02330fba2008-05-16 12:18:29 +0200308};
309
Takashi Iwai95de7762005-11-17 15:02:42 +0100310struct snd_azf3328 {
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200311 /* often-used fields towards beginning, then grouped */
Andreas Mohr02330fba2008-05-16 12:18:29 +0200312
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200313 unsigned long ctrl_io; /* usually 0xb000, size 128 */
Andreas Mohr02330fba2008-05-16 12:18:29 +0200314 unsigned long game_io; /* usually 0xb400, size 8 */
315 unsigned long mpu_io; /* usually 0xb800, size 4 */
316 unsigned long opl3_io; /* usually 0xbc00, size 8 */
317 unsigned long mixer_io; /* usually 0xc000, size 64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200319 spinlock_t reg_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Takashi Iwai95de7762005-11-17 15:02:42 +0100321 struct snd_timer *timer;
Andreas Mohr02330fba2008-05-16 12:18:29 +0200322
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200323 struct snd_pcm *pcm[3];
324
325 /* playback, recording and I2S out codecs */
326 struct snd_azf3328_codec_data codecs[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Takashi Iwai95de7762005-11-17 15:02:42 +0100328 struct snd_card *card;
329 struct snd_rawmidi *rmidi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Andreas Mohr02330fba2008-05-16 12:18:29 +0200331#ifdef SUPPORT_GAMEPORT
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200332 struct gameport *gameport;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200333 u16 axes[4];
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200334#endif
335
336 struct pci_dev *pci;
337 int irq;
Andreas Mohrca54bde2006-05-17 11:02:24 +0200338
Andreas Mohr627d3e72008-06-23 11:50:47 +0200339 /* register 0x6a is write-only, thus need to remember setting.
340 * If we need to add more registers here, then we might try to fold this
341 * into some transparent combined shadow register handling with
342 * CONFIG_PM register storage below, but that's slightly difficult. */
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200343 u16 shadow_reg_ctrl_6AH;
Andreas Mohr627d3e72008-06-23 11:50:47 +0200344
Andreas Mohrca54bde2006-05-17 11:02:24 +0200345#ifdef CONFIG_PM
346 /* register value containers for power management
Andreas Mohr78df6172009-07-12 22:17:54 +0200347 * Note: not always full I/O range preserved (similar to Win driver!) */
348 u32 saved_regs_ctrl[AZF_ALIGN(AZF_IO_SIZE_CTRL_PM) / 4];
349 u32 saved_regs_game[AZF_ALIGN(AZF_IO_SIZE_GAME_PM) / 4];
350 u32 saved_regs_mpu[AZF_ALIGN(AZF_IO_SIZE_MPU_PM) / 4];
351 u32 saved_regs_opl3[AZF_ALIGN(AZF_IO_SIZE_OPL3_PM) / 4];
352 u32 saved_regs_mixer[AZF_ALIGN(AZF_IO_SIZE_MIXER_PM) / 4];
Andreas Mohrca54bde2006-05-17 11:02:24 +0200353#endif
Takashi Iwai95de7762005-11-17 15:02:42 +0100354};
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200355
Alexey Dobriyancebe41d2010-02-06 00:21:03 +0200356static DEFINE_PCI_DEVICE_TABLE(snd_azf3328_ids) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 { 0x122D, 0x50DC, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* PCI168/3328 */
358 { 0x122D, 0x80DA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* 3328 */
359 { 0, }
360};
361
362MODULE_DEVICE_TABLE(pci, snd_azf3328_ids);
363
Andreas Mohr02330fba2008-05-16 12:18:29 +0200364
365static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200366snd_azf3328_io_reg_setb(unsigned reg, u8 mask, bool do_set)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200367{
Andreas Mohradf59312010-12-27 21:16:43 +0100368 /* Well, strictly spoken, the inb/outb sequence isn't atomic
369 and would need locking. However we currently don't care
370 since it potentially complicates matters. */
Andreas Mohr02330fba2008-05-16 12:18:29 +0200371 u8 prev = inb(reg), new;
372
373 new = (do_set) ? (prev|mask) : (prev & ~mask);
374 /* we need to always write the new value no matter whether it differs
375 * or not, since some register bits don't indicate their setting */
376 outb(new, reg);
377 if (new != prev)
378 return 1;
379
380 return 0;
381}
382
Andreas Mohr02330fba2008-05-16 12:18:29 +0200383static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200384snd_azf3328_codec_outb(const struct snd_azf3328_codec_data *codec,
385 unsigned reg,
386 u8 value
387)
Andreas Mohr02330fba2008-05-16 12:18:29 +0200388{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200389 outb(value, codec->io_base + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200390}
391
392static inline u8
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200393snd_azf3328_codec_inb(const struct snd_azf3328_codec_data *codec, unsigned reg)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200394{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200395 return inb(codec->io_base + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200396}
397
398static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200399snd_azf3328_codec_outw(const struct snd_azf3328_codec_data *codec,
400 unsigned reg,
401 u16 value
402)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200403{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200404 outw(value, codec->io_base + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200405}
406
407static inline u16
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200408snd_azf3328_codec_inw(const struct snd_azf3328_codec_data *codec, unsigned reg)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200409{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200410 return inw(codec->io_base + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200411}
412
413static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200414snd_azf3328_codec_outl(const struct snd_azf3328_codec_data *codec,
415 unsigned reg,
416 u32 value
417)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200418{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200419 outl(value, codec->io_base + reg);
Andreas Mohr02330fba2008-05-16 12:18:29 +0200420}
421
422static inline u32
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200423snd_azf3328_codec_inl(const struct snd_azf3328_codec_data *codec, unsigned reg)
Andreas Mohr02330fba2008-05-16 12:18:29 +0200424{
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200425 return inl(codec->io_base + reg);
426}
427
428static inline void
429snd_azf3328_ctrl_outb(const struct snd_azf3328 *chip, unsigned reg, u8 value)
430{
431 outb(value, chip->ctrl_io + reg);
432}
433
434static inline u8
435snd_azf3328_ctrl_inb(const struct snd_azf3328 *chip, unsigned reg)
436{
437 return inb(chip->ctrl_io + reg);
438}
439
440static inline void
441snd_azf3328_ctrl_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
442{
443 outw(value, chip->ctrl_io + reg);
444}
445
446static inline void
447snd_azf3328_ctrl_outl(const struct snd_azf3328 *chip, unsigned reg, u32 value)
448{
449 outl(value, chip->ctrl_io + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200450}
451
452static inline void
Andreas Mohr02330fba2008-05-16 12:18:29 +0200453snd_azf3328_game_outb(const struct snd_azf3328 *chip, unsigned reg, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
Andreas Mohr02330fba2008-05-16 12:18:29 +0200455 outb(value, chip->game_io + reg);
456}
457
458static inline void
459snd_azf3328_game_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
460{
461 outw(value, chip->game_io + reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
463
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200464static inline u8
Andreas Mohr02330fba2008-05-16 12:18:29 +0200465snd_azf3328_game_inb(const struct snd_azf3328 *chip, unsigned reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466{
Andreas Mohr02330fba2008-05-16 12:18:29 +0200467 return inb(chip->game_io + reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}
469
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200470static inline u16
Andreas Mohr02330fba2008-05-16 12:18:29 +0200471snd_azf3328_game_inw(const struct snd_azf3328 *chip, unsigned reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Andreas Mohr02330fba2008-05-16 12:18:29 +0200473 return inw(chip->game_io + reg);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200474}
475
Andreas Mohr02330fba2008-05-16 12:18:29 +0200476static inline void
477snd_azf3328_mixer_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200478{
Andreas Mohr02330fba2008-05-16 12:18:29 +0200479 outw(value, chip->mixer_io + reg);
480}
481
482static inline u16
483snd_azf3328_mixer_inw(const struct snd_azf3328 *chip, unsigned reg)
484{
485 return inw(chip->mixer_io + reg);
486}
487
488#define AZF_MUTE_BIT 0x80
489
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200490static bool
Andreas Mohr02330fba2008-05-16 12:18:29 +0200491snd_azf3328_mixer_set_mute(const struct snd_azf3328 *chip,
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200492 unsigned reg, bool do_mute
Andreas Mohr02330fba2008-05-16 12:18:29 +0200493)
494{
495 unsigned long portbase = chip->mixer_io + reg + 1;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200496 bool updated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 /* the mute bit is on the *second* (i.e. right) register of a
499 * left/right channel setting */
Andreas Mohr02330fba2008-05-16 12:18:29 +0200500 updated = snd_azf3328_io_reg_setb(portbase, AZF_MUTE_BIT, do_mute);
501
502 /* indicate whether it was muted before */
503 return (do_mute) ? !updated : updated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504}
505
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200506static void
Andreas Mohr02330fba2008-05-16 12:18:29 +0200507snd_azf3328_mixer_write_volume_gradually(const struct snd_azf3328 *chip,
508 unsigned reg,
509 unsigned char dst_vol_left,
510 unsigned char dst_vol_right,
511 int chan_sel, int delay
512)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513{
Andreas Mohr02330fba2008-05-16 12:18:29 +0200514 unsigned long portbase = chip->mixer_io + reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 unsigned char curr_vol_left = 0, curr_vol_right = 0;
Andreas Mohr02330fba2008-05-16 12:18:29 +0200516 int left_change = 0, right_change = 0;
517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 snd_azf3328_dbgcallenter();
Andreas Mohr02330fba2008-05-16 12:18:29 +0200519
520 if (chan_sel & SET_CHAN_LEFT) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200521 curr_vol_left = inb(portbase + 1);
Andreas Mohr02330fba2008-05-16 12:18:29 +0200522
523 /* take care of muting flag contained in left channel */
524 if (curr_vol_left & AZF_MUTE_BIT)
525 dst_vol_left |= AZF_MUTE_BIT;
526 else
527 dst_vol_left &= ~AZF_MUTE_BIT;
528
529 left_change = (curr_vol_left > dst_vol_left) ? -1 : 1;
530 }
531
532 if (chan_sel & SET_CHAN_RIGHT) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200533 curr_vol_right = inb(portbase + 0);
Andreas Mohr02330fba2008-05-16 12:18:29 +0200534
535 right_change = (curr_vol_right > dst_vol_right) ? -1 : 1;
536 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Andreas Mohre2f87262006-05-17 11:04:19 +0200538 do {
Andreas Mohr02330fba2008-05-16 12:18:29 +0200539 if (left_change) {
540 if (curr_vol_left != dst_vol_left) {
541 curr_vol_left += left_change;
542 outb(curr_vol_left, portbase + 1);
543 } else
544 left_change = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 }
Andreas Mohr02330fba2008-05-16 12:18:29 +0200546 if (right_change) {
547 if (curr_vol_right != dst_vol_right) {
548 curr_vol_right += right_change;
549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 /* during volume change, the right channel is crackling
551 * somewhat more than the left channel, unfortunately.
552 * This seems to be a hardware issue. */
Andreas Mohr02330fba2008-05-16 12:18:29 +0200553 outb(curr_vol_right, portbase + 0);
554 } else
555 right_change = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 }
557 if (delay)
558 mdelay(delay);
Andreas Mohr02330fba2008-05-16 12:18:29 +0200559 } while ((left_change) || (right_change));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 snd_azf3328_dbgcallleave();
561}
562
563/*
564 * general mixer element
565 */
Takashi Iwai95de7762005-11-17 15:02:42 +0100566struct azf3328_mixer_reg {
Andreas Mohr02330fba2008-05-16 12:18:29 +0200567 unsigned reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 unsigned int lchan_shift, rchan_shift;
569 unsigned int mask;
570 unsigned int invert: 1;
571 unsigned int stereo: 1;
572 unsigned int enum_c: 4;
Takashi Iwai95de7762005-11-17 15:02:42 +0100573};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
575#define COMPOSE_MIXER_REG(reg,lchan_shift,rchan_shift,mask,invert,stereo,enum_c) \
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200576 ((reg) | (lchan_shift << 8) | (rchan_shift << 12) | \
577 (mask << 16) | \
578 (invert << 24) | \
579 (stereo << 25) | \
580 (enum_c << 26))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Takashi Iwai95de7762005-11-17 15:02:42 +0100582static void snd_azf3328_mixer_reg_decode(struct azf3328_mixer_reg *r, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583{
584 r->reg = val & 0xff;
585 r->lchan_shift = (val >> 8) & 0x0f;
586 r->rchan_shift = (val >> 12) & 0x0f;
587 r->mask = (val >> 16) & 0xff;
588 r->invert = (val >> 24) & 1;
589 r->stereo = (val >> 25) & 1;
590 r->enum_c = (val >> 26) & 0x0f;
591}
592
593/*
594 * mixer switches/volumes
595 */
596
597#define AZF3328_MIXER_SWITCH(xname, reg, shift, invert) \
598{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
599 .info = snd_azf3328_info_mixer, \
600 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
601 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, 0x1, invert, 0, 0), \
602}
603
604#define AZF3328_MIXER_VOL_STEREO(xname, reg, mask, invert) \
605{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
606 .info = snd_azf3328_info_mixer, \
607 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
608 .private_value = COMPOSE_MIXER_REG(reg, 8, 0, mask, invert, 1, 0), \
609}
610
611#define AZF3328_MIXER_VOL_MONO(xname, reg, mask, is_right_chan) \
612{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
613 .info = snd_azf3328_info_mixer, \
614 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
615 .private_value = COMPOSE_MIXER_REG(reg, is_right_chan ? 0 : 8, 0, mask, 1, 0, 0), \
616}
617
618#define AZF3328_MIXER_VOL_SPECIAL(xname, reg, mask, shift, invert) \
619{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
620 .info = snd_azf3328_info_mixer, \
621 .get = snd_azf3328_get_mixer, .put = snd_azf3328_put_mixer, \
622 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, mask, invert, 0, 0), \
623}
624
625#define AZF3328_MIXER_ENUM(xname, reg, enum_c, shift) \
626{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
627 .info = snd_azf3328_info_mixer_enum, \
628 .get = snd_azf3328_get_mixer_enum, .put = snd_azf3328_put_mixer_enum, \
629 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, 0, 0, 0, enum_c), \
630}
631
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200632static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100633snd_azf3328_info_mixer(struct snd_kcontrol *kcontrol,
634 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635{
Takashi Iwai95de7762005-11-17 15:02:42 +0100636 struct azf3328_mixer_reg reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
638 snd_azf3328_dbgcallenter();
639 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200640 uinfo->type = reg.mask == 1 ?
641 SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 uinfo->count = reg.stereo + 1;
643 uinfo->value.integer.min = 0;
644 uinfo->value.integer.max = reg.mask;
645 snd_azf3328_dbgcallleave();
646 return 0;
647}
648
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200649static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100650snd_azf3328_get_mixer(struct snd_kcontrol *kcontrol,
651 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
Takashi Iwai95de7762005-11-17 15:02:42 +0100653 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
654 struct azf3328_mixer_reg reg;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200655 u16 oreg, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
657 snd_azf3328_dbgcallenter();
658 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
659
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200660 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 val = (oreg >> reg.lchan_shift) & reg.mask;
662 if (reg.invert)
663 val = reg.mask - val;
664 ucontrol->value.integer.value[0] = val;
665 if (reg.stereo) {
666 val = (oreg >> reg.rchan_shift) & reg.mask;
667 if (reg.invert)
668 val = reg.mask - val;
669 ucontrol->value.integer.value[1] = val;
670 }
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200671 snd_azf3328_dbgmixer("get: %02x is %04x -> vol %02lx|%02lx "
672 "(shift %02d|%02d, mask %02x, inv. %d, stereo %d)\n",
673 reg.reg, oreg,
674 ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
675 reg.lchan_shift, reg.rchan_shift, reg.mask, reg.invert, reg.stereo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 snd_azf3328_dbgcallleave();
677 return 0;
678}
679
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200680static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100681snd_azf3328_put_mixer(struct snd_kcontrol *kcontrol,
682 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683{
Takashi Iwai95de7762005-11-17 15:02:42 +0100684 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
685 struct azf3328_mixer_reg reg;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200686 u16 oreg, nreg, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
688 snd_azf3328_dbgcallenter();
689 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200690 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 val = ucontrol->value.integer.value[0] & reg.mask;
692 if (reg.invert)
693 val = reg.mask - val;
694 nreg = oreg & ~(reg.mask << reg.lchan_shift);
695 nreg |= (val << reg.lchan_shift);
696 if (reg.stereo) {
697 val = ucontrol->value.integer.value[1] & reg.mask;
698 if (reg.invert)
699 val = reg.mask - val;
700 nreg &= ~(reg.mask << reg.rchan_shift);
701 nreg |= (val << reg.rchan_shift);
702 }
703 if (reg.mask >= 0x07) /* it's a volume control, so better take care */
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200704 snd_azf3328_mixer_write_volume_gradually(
705 chip, reg.reg, nreg >> 8, nreg & 0xff,
706 /* just set both channels, doesn't matter */
707 SET_CHAN_LEFT|SET_CHAN_RIGHT,
708 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 else
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200710 snd_azf3328_mixer_outw(chip, reg.reg, nreg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200712 snd_azf3328_dbgmixer("put: %02x to %02lx|%02lx, "
713 "oreg %04x; shift %02d|%02d -> nreg %04x; after: %04x\n",
714 reg.reg, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
715 oreg, reg.lchan_shift, reg.rchan_shift,
716 nreg, snd_azf3328_mixer_inw(chip, reg.reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 snd_azf3328_dbgcallleave();
718 return (nreg != oreg);
719}
720
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200721static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100722snd_azf3328_info_mixer_enum(struct snd_kcontrol *kcontrol,
723 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724{
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200725 static const char * const texts1[] = {
Andreas Mohr13769e32006-05-17 11:03:16 +0200726 "Mic1", "Mic2"
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200727 };
728 static const char * const texts2[] = {
Andreas Mohr13769e32006-05-17 11:03:16 +0200729 "Mix", "Mic"
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200730 };
731 static const char * const texts3[] = {
Andreas Mohr02330fba2008-05-16 12:18:29 +0200732 "Mic", "CD", "Video", "Aux",
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200733 "Line", "Mix", "Mix Mono", "Phone"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 };
Andreas Mohr13769e32006-05-17 11:03:16 +0200735 static const char * const texts4[] = {
736 "pre 3D", "post 3D"
737 };
Takashi Iwai95de7762005-11-17 15:02:42 +0100738 struct azf3328_mixer_reg reg;
Andreas Mohr627d3e72008-06-23 11:50:47 +0200739 const char * const *p = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
741 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
742 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
743 uinfo->count = (reg.reg == IDX_MIXER_REC_SELECT) ? 2 : 1;
744 uinfo->value.enumerated.items = reg.enum_c;
745 if (uinfo->value.enumerated.item > reg.enum_c - 1U)
746 uinfo->value.enumerated.item = reg.enum_c - 1U;
Andreas Mohre2f87262006-05-17 11:04:19 +0200747 if (reg.reg == IDX_MIXER_ADVCTL2) {
Andreas Mohr13769e32006-05-17 11:03:16 +0200748 switch(reg.lchan_shift) {
749 case 8: /* modem out sel */
Andreas Mohr627d3e72008-06-23 11:50:47 +0200750 p = texts1;
Andreas Mohr13769e32006-05-17 11:03:16 +0200751 break;
752 case 9: /* mono sel source */
Andreas Mohr627d3e72008-06-23 11:50:47 +0200753 p = texts2;
Andreas Mohr13769e32006-05-17 11:03:16 +0200754 break;
755 case 15: /* PCM Out Path */
Andreas Mohr627d3e72008-06-23 11:50:47 +0200756 p = texts4;
Andreas Mohr13769e32006-05-17 11:03:16 +0200757 break;
758 }
Andreas Mohre2f87262006-05-17 11:04:19 +0200759 } else
Andreas Mohr02330fba2008-05-16 12:18:29 +0200760 if (reg.reg == IDX_MIXER_REC_SELECT)
Andreas Mohr627d3e72008-06-23 11:50:47 +0200761 p = texts3;
Andreas Mohr02330fba2008-05-16 12:18:29 +0200762
Andreas Mohr627d3e72008-06-23 11:50:47 +0200763 strcpy(uinfo->value.enumerated.name, p[uinfo->value.enumerated.item]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 return 0;
765}
766
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200767static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100768snd_azf3328_get_mixer_enum(struct snd_kcontrol *kcontrol,
769 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770{
Takashi Iwai95de7762005-11-17 15:02:42 +0100771 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
772 struct azf3328_mixer_reg reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 unsigned short val;
Andreas Mohr02330fba2008-05-16 12:18:29 +0200774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200776 val = snd_azf3328_mixer_inw(chip, reg.reg);
Andreas Mohre2f87262006-05-17 11:04:19 +0200777 if (reg.reg == IDX_MIXER_REC_SELECT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 ucontrol->value.enumerated.item[0] = (val >> 8) & (reg.enum_c - 1);
779 ucontrol->value.enumerated.item[1] = (val >> 0) & (reg.enum_c - 1);
Andreas Mohre2f87262006-05-17 11:04:19 +0200780 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 ucontrol->value.enumerated.item[0] = (val >> reg.lchan_shift) & (reg.enum_c - 1);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200782
783 snd_azf3328_dbgmixer("get_enum: %02x is %04x -> %d|%d (shift %02d, enum_c %d)\n",
784 reg.reg, val, ucontrol->value.enumerated.item[0], ucontrol->value.enumerated.item[1],
785 reg.lchan_shift, reg.enum_c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 return 0;
787}
788
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200789static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100790snd_azf3328_put_mixer_enum(struct snd_kcontrol *kcontrol,
791 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792{
Takashi Iwai95de7762005-11-17 15:02:42 +0100793 struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
794 struct azf3328_mixer_reg reg;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200795 u16 oreg, nreg, val;
Andreas Mohr02330fba2008-05-16 12:18:29 +0200796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200798 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 val = oreg;
Andreas Mohre2f87262006-05-17 11:04:19 +0200800 if (reg.reg == IDX_MIXER_REC_SELECT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 if (ucontrol->value.enumerated.item[0] > reg.enum_c - 1U ||
802 ucontrol->value.enumerated.item[1] > reg.enum_c - 1U)
803 return -EINVAL;
804 val = (ucontrol->value.enumerated.item[0] << 8) |
805 (ucontrol->value.enumerated.item[1] << 0);
Andreas Mohre2f87262006-05-17 11:04:19 +0200806 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 if (ucontrol->value.enumerated.item[0] > reg.enum_c - 1U)
808 return -EINVAL;
809 val &= ~((reg.enum_c - 1) << reg.lchan_shift);
810 val |= (ucontrol->value.enumerated.item[0] << reg.lchan_shift);
811 }
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200812 snd_azf3328_mixer_outw(chip, reg.reg, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 nreg = val;
814
815 snd_azf3328_dbgmixer("put_enum: %02x to %04x, oreg %04x\n", reg.reg, val, oreg);
816 return (nreg != oreg);
817}
818
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100819static struct snd_kcontrol_new snd_azf3328_mixer_controls[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 AZF3328_MIXER_SWITCH("Master Playback Switch", IDX_MIXER_PLAY_MASTER, 15, 1),
821 AZF3328_MIXER_VOL_STEREO("Master Playback Volume", IDX_MIXER_PLAY_MASTER, 0x1f, 1),
Andreas Mohr627d3e72008-06-23 11:50:47 +0200822 AZF3328_MIXER_SWITCH("PCM Playback Switch", IDX_MIXER_WAVEOUT, 15, 1),
823 AZF3328_MIXER_VOL_STEREO("PCM Playback Volume",
824 IDX_MIXER_WAVEOUT, 0x1f, 1),
825 AZF3328_MIXER_SWITCH("PCM 3D Bypass Playback Switch",
826 IDX_MIXER_ADVCTL2, 7, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 AZF3328_MIXER_SWITCH("FM Playback Switch", IDX_MIXER_FMSYNTH, 15, 1),
828 AZF3328_MIXER_VOL_STEREO("FM Playback Volume", IDX_MIXER_FMSYNTH, 0x1f, 1),
829 AZF3328_MIXER_SWITCH("CD Playback Switch", IDX_MIXER_CDAUDIO, 15, 1),
830 AZF3328_MIXER_VOL_STEREO("CD Playback Volume", IDX_MIXER_CDAUDIO, 0x1f, 1),
831 AZF3328_MIXER_SWITCH("Capture Switch", IDX_MIXER_REC_VOLUME, 15, 1),
832 AZF3328_MIXER_VOL_STEREO("Capture Volume", IDX_MIXER_REC_VOLUME, 0x0f, 0),
833 AZF3328_MIXER_ENUM("Capture Source", IDX_MIXER_REC_SELECT, 8, 0),
834 AZF3328_MIXER_SWITCH("Mic Playback Switch", IDX_MIXER_MIC, 15, 1),
835 AZF3328_MIXER_VOL_MONO("Mic Playback Volume", IDX_MIXER_MIC, 0x1f, 1),
836 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0),
837 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1),
838 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1),
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100839 AZF3328_MIXER_SWITCH("Beep Playback Switch", IDX_MIXER_PCBEEP, 15, 1),
840 AZF3328_MIXER_VOL_SPECIAL("Beep Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1),
842 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1),
843 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1),
844 AZF3328_MIXER_VOL_STEREO("Aux Playback Volume", IDX_MIXER_AUX, 0x1f, 1),
845 AZF3328_MIXER_SWITCH("Modem Playback Switch", IDX_MIXER_MODEMOUT, 15, 1),
846 AZF3328_MIXER_VOL_MONO("Modem Playback Volume", IDX_MIXER_MODEMOUT, 0x1f, 1),
847 AZF3328_MIXER_SWITCH("Modem Capture Switch", IDX_MIXER_MODEMIN, 15, 1),
848 AZF3328_MIXER_VOL_MONO("Modem Capture Volume", IDX_MIXER_MODEMIN, 0x1f, 1),
Andreas Mohr13769e32006-05-17 11:03:16 +0200849 AZF3328_MIXER_ENUM("Mic Select", IDX_MIXER_ADVCTL2, 2, 8),
850 AZF3328_MIXER_ENUM("Mono Output Select", IDX_MIXER_ADVCTL2, 2, 9),
Andreas Mohre24a1212007-03-26 12:49:45 +0200851 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 -0700852 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Treble", IDX_MIXER_BASSTREBLE, 0x07, 1, 0),
853 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Bass", IDX_MIXER_BASSTREBLE, 0x07, 9, 0),
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200854 AZF3328_MIXER_SWITCH("3D Control - Switch", IDX_MIXER_ADVCTL2, 13, 0),
Andreas Mohr13769e32006-05-17 11:03:16 +0200855 AZF3328_MIXER_VOL_SPECIAL("3D Control - Width", IDX_MIXER_ADVCTL1, 0x07, 1, 0), /* "3D Width" */
856 AZF3328_MIXER_VOL_SPECIAL("3D Control - Depth", IDX_MIXER_ADVCTL1, 0x03, 8, 0), /* "Hifi 3D" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857#if MIXER_TESTING
858 AZF3328_MIXER_SWITCH("0", IDX_MIXER_ADVCTL2, 0, 0),
859 AZF3328_MIXER_SWITCH("1", IDX_MIXER_ADVCTL2, 1, 0),
860 AZF3328_MIXER_SWITCH("2", IDX_MIXER_ADVCTL2, 2, 0),
861 AZF3328_MIXER_SWITCH("3", IDX_MIXER_ADVCTL2, 3, 0),
862 AZF3328_MIXER_SWITCH("4", IDX_MIXER_ADVCTL2, 4, 0),
863 AZF3328_MIXER_SWITCH("5", IDX_MIXER_ADVCTL2, 5, 0),
864 AZF3328_MIXER_SWITCH("6", IDX_MIXER_ADVCTL2, 6, 0),
865 AZF3328_MIXER_SWITCH("7", IDX_MIXER_ADVCTL2, 7, 0),
866 AZF3328_MIXER_SWITCH("8", IDX_MIXER_ADVCTL2, 8, 0),
867 AZF3328_MIXER_SWITCH("9", IDX_MIXER_ADVCTL2, 9, 0),
868 AZF3328_MIXER_SWITCH("10", IDX_MIXER_ADVCTL2, 10, 0),
869 AZF3328_MIXER_SWITCH("11", IDX_MIXER_ADVCTL2, 11, 0),
870 AZF3328_MIXER_SWITCH("12", IDX_MIXER_ADVCTL2, 12, 0),
871 AZF3328_MIXER_SWITCH("13", IDX_MIXER_ADVCTL2, 13, 0),
872 AZF3328_MIXER_SWITCH("14", IDX_MIXER_ADVCTL2, 14, 0),
873 AZF3328_MIXER_SWITCH("15", IDX_MIXER_ADVCTL2, 15, 0),
874#endif
875};
876
Takashi Iwai1b60f6b2007-03-13 22:13:47 +0100877static u16 __devinitdata snd_azf3328_init_values[][2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 { IDX_MIXER_PLAY_MASTER, MIXER_MUTE_MASK|0x1f1f },
879 { IDX_MIXER_MODEMOUT, MIXER_MUTE_MASK|0x1f1f },
880 { IDX_MIXER_BASSTREBLE, 0x0000 },
881 { IDX_MIXER_PCBEEP, MIXER_MUTE_MASK|0x1f1f },
882 { IDX_MIXER_MODEMIN, MIXER_MUTE_MASK|0x1f1f },
883 { IDX_MIXER_MIC, MIXER_MUTE_MASK|0x001f },
884 { IDX_MIXER_LINEIN, MIXER_MUTE_MASK|0x1f1f },
885 { IDX_MIXER_CDAUDIO, MIXER_MUTE_MASK|0x1f1f },
886 { IDX_MIXER_VIDEO, MIXER_MUTE_MASK|0x1f1f },
887 { IDX_MIXER_AUX, MIXER_MUTE_MASK|0x1f1f },
888 { IDX_MIXER_WAVEOUT, MIXER_MUTE_MASK|0x1f1f },
889 { IDX_MIXER_FMSYNTH, MIXER_MUTE_MASK|0x1f1f },
890 { IDX_MIXER_REC_VOLUME, MIXER_MUTE_MASK|0x0707 },
891};
892
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200893static int __devinit
Takashi Iwai95de7762005-11-17 15:02:42 +0100894snd_azf3328_mixer_new(struct snd_azf3328 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
Takashi Iwai95de7762005-11-17 15:02:42 +0100896 struct snd_card *card;
897 const struct snd_kcontrol_new *sw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 unsigned int idx;
899 int err;
900
901 snd_azf3328_dbgcallenter();
Takashi Iwaida3cec32008-08-08 17:12:14 +0200902 if (snd_BUG_ON(!chip || !chip->card))
903 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905 card = chip->card;
906
907 /* mixer reset */
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200908 snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 /* mute and zero volume channels */
Andreas Mohr02330fba2008-05-16 12:18:29 +0200911 for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_init_values); ++idx) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200912 snd_azf3328_mixer_outw(chip,
913 snd_azf3328_init_values[idx][0],
914 snd_azf3328_init_values[idx][1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 }
Andreas Mohr02330fba2008-05-16 12:18:29 +0200916
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 /* add mixer controls */
918 sw = snd_azf3328_mixer_controls;
Andreas Mohr02330fba2008-05-16 12:18:29 +0200919 for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_mixer_controls);
920 ++idx, ++sw) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(sw, chip))) < 0)
922 return err;
923 }
924 snd_component_add(card, "AZF3328 mixer");
925 strcpy(card->mixername, "AZF3328 mixer");
926
927 snd_azf3328_dbgcallleave();
928 return 0;
929}
930
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200931static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100932snd_azf3328_hw_params(struct snd_pcm_substream *substream,
933 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
935 int res;
936 snd_azf3328_dbgcallenter();
937 res = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
938 snd_azf3328_dbgcallleave();
939 return res;
940}
941
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200942static int
Takashi Iwai95de7762005-11-17 15:02:42 +0100943snd_azf3328_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944{
945 snd_azf3328_dbgcallenter();
946 snd_pcm_lib_free_pages(substream);
947 snd_azf3328_dbgcallleave();
948 return 0;
949}
950
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200951static void
Andreas Mohr02330fba2008-05-16 12:18:29 +0200952snd_azf3328_codec_setfmt(struct snd_azf3328 *chip,
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200953 enum snd_azf3328_codec_type codec_type,
Andreas Mohr627d3e72008-06-23 11:50:47 +0200954 enum azf_freq_t bitrate,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 unsigned int format_width,
956 unsigned int channels
957)
958{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 unsigned long flags;
Andreas Mohrdfbf9512009-07-05 13:55:46 +0200960 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
961 u16 val = 0xff00;
Andreas Mohr8d9a1142010-12-27 21:16:49 +0100962 u8 freq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 snd_azf3328_dbgcallenter();
965 switch (bitrate) {
Andreas Mohr8d9a1142010-12-27 21:16:49 +0100966#define AZF_FMT_XLATE(in_freq, out_bits) \
967 do { \
968 case AZF_FREQ_ ## in_freq: \
969 freq = SOUNDFORMAT_FREQ_ ## out_bits; \
970 break; \
971 } while (0);
972 AZF_FMT_XLATE(4000, SUSPECTED_4000)
973 AZF_FMT_XLATE(4800, SUSPECTED_4800)
974 /* the AZF3328 names it "5510" for some strange reason: */
975 AZF_FMT_XLATE(5512, 5510)
976 AZF_FMT_XLATE(6620, 6620)
977 AZF_FMT_XLATE(8000, 8000)
978 AZF_FMT_XLATE(9600, 9600)
979 AZF_FMT_XLATE(11025, 11025)
980 AZF_FMT_XLATE(13240, SUSPECTED_13240)
981 AZF_FMT_XLATE(16000, 16000)
982 AZF_FMT_XLATE(22050, 22050)
983 AZF_FMT_XLATE(32000, 32000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 default:
Takashi Iwai99b359b2005-10-20 18:26:44 +0200985 snd_printk(KERN_WARNING "unknown bitrate %d, assuming 44.1kHz!\n", bitrate);
Andreas Mohr02330fba2008-05-16 12:18:29 +0200986 /* fall-through */
Andreas Mohr8d9a1142010-12-27 21:16:49 +0100987 AZF_FMT_XLATE(44100, 44100)
988 AZF_FMT_XLATE(48000, 48000)
989 AZF_FMT_XLATE(66200, SUSPECTED_66200)
990#undef AZF_FMT_XLATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 }
Andreas Mohrd91c64c2005-10-25 11:17:45 +0200992 /* val = 0xff07; 3m27.993s (65301Hz; -> 64000Hz???) hmm, 66120, 65967, 66123 */
993 /* val = 0xff09; 17m15.098s (13123,478Hz; -> 12000Hz???) hmm, 13237.2Hz? */
994 /* val = 0xff0a; 47m30.599s (4764,891Hz; -> 4800Hz???) yup, 4803Hz */
995 /* val = 0xff0c; 57m0.510s (4010,263Hz; -> 4000Hz???) yup, 4003Hz */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 /* val = 0xff05; 5m11.556s (... -> 44100Hz) */
997 /* val = 0xff03; 10m21.529s (21872,463Hz; -> 22050Hz???) */
998 /* val = 0xff0f; 20m41.883s (10937,993Hz; -> 11025Hz???) */
999 /* val = 0xff0d; 41m23.135s (5523,600Hz; -> 5512Hz???) */
1000 /* val = 0xff0e; 28m30.777s (8017Hz; -> 8000Hz???) */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001001
Andreas Mohr8d9a1142010-12-27 21:16:49 +01001002 val |= freq;
1003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 if (channels == 2)
1005 val |= SOUNDFORMAT_FLAG_2CHANNELS;
1006
1007 if (format_width == 16)
1008 val |= SOUNDFORMAT_FLAG_16BIT;
1009
1010 spin_lock_irqsave(&chip->reg_lock, flags);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001011
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 /* set bitrate/format */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001013 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_SOUNDFORMAT, val);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001014
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 /* changing the bitrate/format settings switches off the
1016 * audio output with an annoying click in case of 8/16bit format change
1017 * (maybe shutting down DAC/ADC?), thus immediately
1018 * do some tweaking to reenable it and get rid of the clicking
1019 * (FIXME: yes, it works, but what exactly am I doing here?? :)
1020 * FIXME: does this have some side effects for full-duplex
1021 * or other dramatic side effects? */
Andreas Mohradf59312010-12-27 21:16:43 +01001022 /* do it for non-capture codecs only */
1023 if (codec_type == AZF_CODEC_PLAYBACK)
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001024 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1025 snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS) |
1026 DMA_RUN_SOMETHING1 |
1027 DMA_RUN_SOMETHING2 |
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001028 SOMETHING_ALMOST_ALWAYS_SET |
1029 DMA_EPILOGUE_SOMETHING |
1030 DMA_SOMETHING_ELSE
1031 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
1033 spin_unlock_irqrestore(&chip->reg_lock, flags);
1034 snd_azf3328_dbgcallleave();
1035}
1036
Andreas Mohr02330fba2008-05-16 12:18:29 +02001037static inline void
1038snd_azf3328_codec_setfmt_lowpower(struct snd_azf3328 *chip,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001039 enum snd_azf3328_codec_type codec_type
Andreas Mohr02330fba2008-05-16 12:18:29 +02001040)
1041{
1042 /* choose lowest frequency for low power consumption.
1043 * While this will cause louder noise due to rather coarse frequency,
1044 * it should never matter since output should always
1045 * get disabled properly when idle anyway. */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001046 snd_azf3328_codec_setfmt(chip, codec_type, AZF_FREQ_4000, 8, 1);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001047}
1048
Andreas Mohr627d3e72008-06-23 11:50:47 +02001049static void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001050snd_azf3328_ctrl_reg_6AH_update(struct snd_azf3328 *chip,
Andreas Mohr627d3e72008-06-23 11:50:47 +02001051 unsigned bitmask,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001052 bool enable
Andreas Mohr627d3e72008-06-23 11:50:47 +02001053)
1054{
Andreas Mohr78df6172009-07-12 22:17:54 +02001055 bool do_mask = !enable;
1056 if (do_mask)
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001057 chip->shadow_reg_ctrl_6AH |= bitmask;
Andreas Mohr78df6172009-07-12 22:17:54 +02001058 else
1059 chip->shadow_reg_ctrl_6AH &= ~bitmask;
1060 snd_azf3328_dbgcodec("6AH_update mask 0x%04x do_mask %d: val 0x%04x\n",
1061 bitmask, do_mask, chip->shadow_reg_ctrl_6AH);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001062 snd_azf3328_ctrl_outw(chip, IDX_IO_6AH, chip->shadow_reg_ctrl_6AH);
Andreas Mohr627d3e72008-06-23 11:50:47 +02001063}
1064
Andreas Mohr02330fba2008-05-16 12:18:29 +02001065static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001066snd_azf3328_ctrl_enable_codecs(struct snd_azf3328 *chip, bool enable)
Andreas Mohr02330fba2008-05-16 12:18:29 +02001067{
Andreas Mohr78df6172009-07-12 22:17:54 +02001068 snd_azf3328_dbgcodec("codec_enable %d\n", enable);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001069 /* no idea what exactly is being done here, but I strongly assume it's
1070 * PM related */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001071 snd_azf3328_ctrl_reg_6AH_update(
Andreas Mohr627d3e72008-06-23 11:50:47 +02001072 chip, IO_6A_PAUSE_PLAYBACK_BIT8, enable
Andreas Mohr02330fba2008-05-16 12:18:29 +02001073 );
1074}
1075
1076static void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001077snd_azf3328_ctrl_codec_activity(struct snd_azf3328 *chip,
1078 enum snd_azf3328_codec_type codec_type,
1079 bool enable
Andreas Mohr02330fba2008-05-16 12:18:29 +02001080)
1081{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001082 struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
1083 bool need_change = (codec->running != enable);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001084
Andreas Mohr78df6172009-07-12 22:17:54 +02001085 snd_azf3328_dbgcodec(
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001086 "codec_activity: %s codec, enable %d, need_change %d\n",
1087 codec->name, enable, need_change
Andreas Mohr02330fba2008-05-16 12:18:29 +02001088 );
1089 if (need_change) {
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001090 static const struct {
1091 enum snd_azf3328_codec_type other1;
1092 enum snd_azf3328_codec_type other2;
1093 } peer_codecs[3] =
1094 { { AZF_CODEC_CAPTURE, AZF_CODEC_I2S_OUT },
1095 { AZF_CODEC_PLAYBACK, AZF_CODEC_I2S_OUT },
1096 { AZF_CODEC_PLAYBACK, AZF_CODEC_CAPTURE } };
1097 bool call_function;
1098
1099 if (enable)
1100 /* if enable codec, call enable_codecs func
1101 to enable codec supply... */
1102 call_function = 1;
1103 else {
1104 /* ...otherwise call enable_codecs func
1105 (which globally shuts down operation of codecs)
1106 only in case the other codecs are currently
1107 not active either! */
Andreas Mohr78df6172009-07-12 22:17:54 +02001108 call_function =
1109 ((!chip->codecs[peer_codecs[codec_type].other1]
1110 .running)
1111 && (!chip->codecs[peer_codecs[codec_type].other2]
1112 .running));
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001113 }
1114 if (call_function)
1115 snd_azf3328_ctrl_enable_codecs(chip, enable);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001116
1117 /* ...and adjust clock, too
1118 * (reduce noise and power consumption) */
1119 if (!enable)
1120 snd_azf3328_codec_setfmt_lowpower(
1121 chip,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001122 codec_type
Andreas Mohr02330fba2008-05-16 12:18:29 +02001123 );
Andreas Mohr78df6172009-07-12 22:17:54 +02001124 codec->running = enable;
Andreas Mohr02330fba2008-05-16 12:18:29 +02001125 }
Andreas Mohr02330fba2008-05-16 12:18:29 +02001126}
1127
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001128static void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001129snd_azf3328_codec_setdmaa(struct snd_azf3328 *chip,
1130 enum snd_azf3328_codec_type codec_type,
1131 unsigned long addr,
1132 unsigned int count,
1133 unsigned int size
Andreas Mohr02330fba2008-05-16 12:18:29 +02001134)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001136 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 snd_azf3328_dbgcallenter();
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001138 if (!codec->running) {
1139 /* AZF3328 uses a two buffer pointer DMA transfer approach */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001140
Andreas Mohr78df6172009-07-12 22:17:54 +02001141 unsigned long flags, addr_area2;
Andreas Mohr02330fba2008-05-16 12:18:29 +02001142
1143 /* width 32bit (prevent overflow): */
Andreas Mohr78df6172009-07-12 22:17:54 +02001144 u32 count_areas, lengths;
Andreas Mohr02330fba2008-05-16 12:18:29 +02001145
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001146 count_areas = size/2;
1147 addr_area2 = addr+count_areas;
Andreas Mohr78df6172009-07-12 22:17:54 +02001148 snd_azf3328_dbgcodec("setdma: buffers %08lx[%u] / %08lx[%u]\n",
1149 addr, count_areas, addr_area2, count_areas);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001150
Andreas Mohr79741502010-11-21 12:09:32 +01001151 count_areas--; /* max. index */
1152
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001153 /* build combined I/O buffer length word */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001154 lengths = (count_areas << 16) | (count_areas);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 spin_lock_irqsave(&chip->reg_lock, flags);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001156 snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_START_1, addr);
1157 snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_START_2,
1158 addr_area2);
1159 snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_LENGTHS,
1160 lengths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 spin_unlock_irqrestore(&chip->reg_lock, flags);
1162 }
1163 snd_azf3328_dbgcallleave();
1164}
1165
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001166static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001167snd_azf3328_codec_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
Takashi Iwai95de7762005-11-17 15:02:42 +01001169 struct snd_pcm_runtime *runtime = substream->runtime;
Andreas Mohr34585592010-12-27 21:17:11 +01001170 struct snd_azf3328_codec *codec = runtime->private_data;
1171#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
1173 unsigned int count = snd_pcm_lib_period_bytes(substream);
1174#endif
1175
1176 snd_azf3328_dbgcallenter();
Andreas Mohr34585592010-12-27 21:17:11 +01001177
1178 codec->dma_base = runtime->dma_addr;
1179
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180#if 0
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001181 snd_azf3328_codec_setfmt(chip, AZF_CODEC_...,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001182 runtime->rate,
1183 snd_pcm_format_width(runtime->format),
1184 runtime->channels);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001185 snd_azf3328_codec_setdmaa(chip, AZF_CODEC_...,
1186 runtime->dma_addr, count, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187#endif
1188 snd_azf3328_dbgcallleave();
1189 return 0;
1190}
1191
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001192static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001193snd_azf3328_codec_trigger(enum snd_azf3328_codec_type codec_type,
1194 struct snd_pcm_substream *substream, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195{
Takashi Iwai95de7762005-11-17 15:02:42 +01001196 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001197 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
Takashi Iwai95de7762005-11-17 15:02:42 +01001198 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 int result = 0;
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001200 u16 flags1;
1201 bool previously_muted = 0;
1202 bool is_playback_codec = (AZF_CODEC_PLAYBACK == codec_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001204 snd_azf3328_dbgcalls("snd_azf3328_codec_trigger cmd %d\n", cmd);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001205
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 switch (cmd) {
1207 case SNDRV_PCM_TRIGGER_START:
Andreas Mohr78df6172009-07-12 22:17:54 +02001208 snd_azf3328_dbgcodec("START %s\n", codec->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001210 if (is_playback_codec) {
1211 /* mute WaveOut (avoid clicking during setup) */
1212 previously_muted =
1213 snd_azf3328_mixer_set_mute(
1214 chip, IDX_MIXER_WAVEOUT, 1
1215 );
1216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001218 snd_azf3328_codec_setfmt(chip, codec_type,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001219 runtime->rate,
1220 snd_pcm_format_width(runtime->format),
1221 runtime->channels);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
1223 spin_lock(&chip->reg_lock);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001224 /* first, remember current value: */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001225 flags1 = snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001226
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001227 /* stop transfer */
1228 flags1 &= ~DMA_RESUME;
1229 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001230
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 /* FIXME: clear interrupts or what??? */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001232 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_IRQTYPE, 0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 spin_unlock(&chip->reg_lock);
1234
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001235 snd_azf3328_codec_setdmaa(chip, codec_type, runtime->dma_addr,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001236 snd_pcm_lib_period_bytes(substream),
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001237 snd_pcm_lib_buffer_bytes(substream)
1238 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
1240 spin_lock(&chip->reg_lock);
1241#ifdef WIN9X
1242 /* FIXME: enable playback/recording??? */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001243 flags1 |= DMA_RUN_SOMETHING1 | DMA_RUN_SOMETHING2;
1244 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001246 /* start transfer again */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 /* FIXME: what is this value (0x0010)??? */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001248 flags1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING;
1249 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250#else /* NT4 */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001251 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001252 0x0000);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001253 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1254 DMA_RUN_SOMETHING1);
1255 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1256 DMA_RUN_SOMETHING1 |
1257 DMA_RUN_SOMETHING2);
1258 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001259 DMA_RESUME |
1260 SOMETHING_ALMOST_ALWAYS_SET |
1261 DMA_EPILOGUE_SOMETHING |
1262 DMA_SOMETHING_ELSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263#endif
1264 spin_unlock(&chip->reg_lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001265 snd_azf3328_ctrl_codec_activity(chip, codec_type, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001267 if (is_playback_codec) {
1268 /* now unmute WaveOut */
1269 if (!previously_muted)
1270 snd_azf3328_mixer_set_mute(
1271 chip, IDX_MIXER_WAVEOUT, 0
1272 );
1273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
Andreas Mohr78df6172009-07-12 22:17:54 +02001275 snd_azf3328_dbgcodec("STARTED %s\n", codec->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 break;
Andreas Mohrca54bde2006-05-17 11:02:24 +02001277 case SNDRV_PCM_TRIGGER_RESUME:
Andreas Mohr78df6172009-07-12 22:17:54 +02001278 snd_azf3328_dbgcodec("RESUME %s\n", codec->name);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001279 /* resume codec if we were active */
Andreas Mohr02330fba2008-05-16 12:18:29 +02001280 spin_lock(&chip->reg_lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001281 if (codec->running)
1282 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1283 snd_azf3328_codec_inw(
1284 codec, IDX_IO_CODEC_DMA_FLAGS
1285 ) | DMA_RESUME
1286 );
Andreas Mohr02330fba2008-05-16 12:18:29 +02001287 spin_unlock(&chip->reg_lock);
Andreas Mohrca54bde2006-05-17 11:02:24 +02001288 break;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001289 case SNDRV_PCM_TRIGGER_STOP:
Andreas Mohr78df6172009-07-12 22:17:54 +02001290 snd_azf3328_dbgcodec("STOP %s\n", codec->name);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001291
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001292 if (is_playback_codec) {
1293 /* mute WaveOut (avoid clicking during setup) */
1294 previously_muted =
1295 snd_azf3328_mixer_set_mute(
1296 chip, IDX_MIXER_WAVEOUT, 1
1297 );
1298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
1300 spin_lock(&chip->reg_lock);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001301 /* first, remember current value: */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001302 flags1 = snd_azf3328_codec_inw(codec, IDX_IO_CODEC_DMA_FLAGS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001304 /* stop transfer */
1305 flags1 &= ~DMA_RESUME;
1306 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001308 /* hmm, is this really required? we're resetting the same bit
1309 * immediately thereafter... */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001310 flags1 |= DMA_RUN_SOMETHING1;
1311 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001313 flags1 &= ~DMA_RUN_SOMETHING1;
1314 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, flags1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 spin_unlock(&chip->reg_lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001316 snd_azf3328_ctrl_codec_activity(chip, codec_type, 0);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001317
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001318 if (is_playback_codec) {
1319 /* now unmute WaveOut */
1320 if (!previously_muted)
1321 snd_azf3328_mixer_set_mute(
1322 chip, IDX_MIXER_WAVEOUT, 0
1323 );
1324 }
Andreas Mohr02330fba2008-05-16 12:18:29 +02001325
Andreas Mohr78df6172009-07-12 22:17:54 +02001326 snd_azf3328_dbgcodec("STOPPED %s\n", codec->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 break;
Andreas Mohrca54bde2006-05-17 11:02:24 +02001328 case SNDRV_PCM_TRIGGER_SUSPEND:
Andreas Mohr78df6172009-07-12 22:17:54 +02001329 snd_azf3328_dbgcodec("SUSPEND %s\n", codec->name);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001330 /* make sure codec is stopped */
1331 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1332 snd_azf3328_codec_inw(
1333 codec, IDX_IO_CODEC_DMA_FLAGS
1334 ) & ~DMA_RESUME
1335 );
Andreas Mohrca54bde2006-05-17 11:02:24 +02001336 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Takashi Iwai99b359b2005-10-20 18:26:44 +02001338 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 break;
1340 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Takashi Iwai99b359b2005-10-20 18:26:44 +02001341 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 break;
1343 default:
Andreas Mohr78df6172009-07-12 22:17:54 +02001344 snd_printk(KERN_ERR "FIXME: unknown trigger mode!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 return -EINVAL;
1346 }
Andreas Mohr02330fba2008-05-16 12:18:29 +02001347
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 snd_azf3328_dbgcallleave();
1349 return result;
1350}
1351
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001352static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001353snd_azf3328_codec_playback_trigger(struct snd_pcm_substream *substream, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001355 return snd_azf3328_codec_trigger(AZF_CODEC_PLAYBACK, substream, cmd);
1356}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001358static int
1359snd_azf3328_codec_capture_trigger(struct snd_pcm_substream *substream, int cmd)
1360{
1361 return snd_azf3328_codec_trigger(AZF_CODEC_CAPTURE, substream, cmd);
1362}
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001363
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001364static int
1365snd_azf3328_codec_i2s_out_trigger(struct snd_pcm_substream *substream, int cmd)
1366{
1367 return snd_azf3328_codec_trigger(AZF_CODEC_I2S_OUT, substream, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368}
1369
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001370static snd_pcm_uframes_t
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001371snd_azf3328_codec_pointer(struct snd_pcm_substream *substream,
1372 enum snd_azf3328_codec_type codec_type
1373)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001375 const struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1376 const struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
Andreas Mohr34585592010-12-27 21:17:11 +01001377 unsigned long result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 snd_pcm_uframes_t frmres;
1379
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001380 result = snd_azf3328_codec_inl(codec, IDX_IO_CODEC_DMA_CURRPOS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001382 /* calculate offset */
Andreas Mohr34585592010-12-27 21:17:11 +01001383#ifdef QUERY_HARDWARE
1384 result -= snd_azf3328_codec_inl(codec, IDX_IO_CODEC_DMA_START_1);
1385#else
1386 result -= codec->dma_base;
1387#endif
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001388 frmres = bytes_to_frames( substream->runtime, result);
Andreas Mohradf59312010-12-27 21:16:43 +01001389 snd_azf3328_dbgcodec("%08li %s @ 0x%8lx, frames %8ld\n",
1390 jiffies, codec->name, result, frmres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 return frmres;
1392}
1393
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001394static snd_pcm_uframes_t
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001395snd_azf3328_codec_playback_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001397 return snd_azf3328_codec_pointer(substream, AZF_CODEC_PLAYBACK);
1398}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001400static snd_pcm_uframes_t
1401snd_azf3328_codec_capture_pointer(struct snd_pcm_substream *substream)
1402{
1403 return snd_azf3328_codec_pointer(substream, AZF_CODEC_CAPTURE);
1404}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001406static snd_pcm_uframes_t
1407snd_azf3328_codec_i2s_out_pointer(struct snd_pcm_substream *substream)
1408{
1409 return snd_azf3328_codec_pointer(substream, AZF_CODEC_I2S_OUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410}
1411
Andreas Mohr02330fba2008-05-16 12:18:29 +02001412/******************************************************************/
1413
1414#ifdef SUPPORT_GAMEPORT
1415static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001416snd_azf3328_gameport_irq_enable(struct snd_azf3328 *chip,
1417 bool enable
1418)
Andreas Mohr02330fba2008-05-16 12:18:29 +02001419{
1420 snd_azf3328_io_reg_setb(
1421 chip->game_io+IDX_GAME_HWCONFIG,
1422 GAME_HWCFG_IRQ_ENABLE,
1423 enable
1424 );
1425}
1426
1427static inline void
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001428snd_azf3328_gameport_legacy_address_enable(struct snd_azf3328 *chip,
1429 bool enable
1430)
Andreas Mohr02330fba2008-05-16 12:18:29 +02001431{
1432 snd_azf3328_io_reg_setb(
1433 chip->game_io+IDX_GAME_HWCONFIG,
1434 GAME_HWCFG_LEGACY_ADDRESS_ENABLE,
1435 enable
1436 );
1437}
1438
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001439static void
1440snd_azf3328_gameport_set_counter_frequency(struct snd_azf3328 *chip,
1441 unsigned int freq_cfg
1442)
Andreas Mohr02330fba2008-05-16 12:18:29 +02001443{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001444 snd_azf3328_io_reg_setb(
1445 chip->game_io+IDX_GAME_HWCONFIG,
1446 0x02,
1447 (freq_cfg & 1) != 0
1448 );
1449 snd_azf3328_io_reg_setb(
1450 chip->game_io+IDX_GAME_HWCONFIG,
1451 0x04,
1452 (freq_cfg & 2) != 0
1453 );
1454}
1455
1456static inline void
1457snd_azf3328_gameport_axis_circuit_enable(struct snd_azf3328 *chip, bool enable)
1458{
1459 snd_azf3328_ctrl_reg_6AH_update(
Andreas Mohr627d3e72008-06-23 11:50:47 +02001460 chip, IO_6A_SOMETHING2_GAMEPORT, enable
Andreas Mohr02330fba2008-05-16 12:18:29 +02001461 );
1462}
1463
1464static inline void
1465snd_azf3328_gameport_interrupt(struct snd_azf3328 *chip)
1466{
1467 /*
1468 * skeleton handler only
1469 * (we do not want axis reading in interrupt handler - too much load!)
1470 */
1471 snd_azf3328_dbggame("gameport irq\n");
1472
1473 /* this should ACK the gameport IRQ properly, hopefully. */
1474 snd_azf3328_game_inw(chip, IDX_GAME_AXIS_VALUE);
1475}
1476
1477static int
1478snd_azf3328_gameport_open(struct gameport *gameport, int mode)
1479{
1480 struct snd_azf3328 *chip = gameport_get_port_data(gameport);
1481 int res;
1482
1483 snd_azf3328_dbggame("gameport_open, mode %d\n", mode);
1484 switch (mode) {
1485 case GAMEPORT_MODE_COOKED:
1486 case GAMEPORT_MODE_RAW:
1487 res = 0;
1488 break;
1489 default:
1490 res = -1;
1491 break;
1492 }
1493
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001494 snd_azf3328_gameport_set_counter_frequency(chip,
1495 GAME_HWCFG_ADC_COUNTER_FREQ_STD);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001496 snd_azf3328_gameport_axis_circuit_enable(chip, (res == 0));
1497
1498 return res;
1499}
1500
1501static void
1502snd_azf3328_gameport_close(struct gameport *gameport)
1503{
1504 struct snd_azf3328 *chip = gameport_get_port_data(gameport);
1505
1506 snd_azf3328_dbggame("gameport_close\n");
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001507 snd_azf3328_gameport_set_counter_frequency(chip,
1508 GAME_HWCFG_ADC_COUNTER_FREQ_1_200);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001509 snd_azf3328_gameport_axis_circuit_enable(chip, 0);
1510}
1511
1512static int
1513snd_azf3328_gameport_cooked_read(struct gameport *gameport,
1514 int *axes,
1515 int *buttons
1516)
1517{
1518 struct snd_azf3328 *chip = gameport_get_port_data(gameport);
1519 int i;
1520 u8 val;
1521 unsigned long flags;
1522
Takashi Iwaida3cec32008-08-08 17:12:14 +02001523 if (snd_BUG_ON(!chip))
1524 return 0;
Andreas Mohr02330fba2008-05-16 12:18:29 +02001525
1526 spin_lock_irqsave(&chip->reg_lock, flags);
1527 val = snd_azf3328_game_inb(chip, IDX_GAME_LEGACY_COMPATIBLE);
1528 *buttons = (~(val) >> 4) & 0xf;
1529
1530 /* ok, this one is a bit dirty: cooked_read is being polled by a timer,
1531 * thus we're atomic and cannot actively wait in here
1532 * (which would be useful for us since it probably would be better
1533 * to trigger a measurement in here, then wait a short amount of
1534 * time until it's finished, then read values of _this_ measurement).
1535 *
1536 * Thus we simply resort to reading values if they're available already
1537 * and trigger the next measurement.
1538 */
1539
1540 val = snd_azf3328_game_inb(chip, IDX_GAME_AXES_CONFIG);
1541 if (val & GAME_AXES_SAMPLING_READY) {
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001542 for (i = 0; i < ARRAY_SIZE(chip->axes); ++i) {
Andreas Mohr02330fba2008-05-16 12:18:29 +02001543 /* configure the axis to read */
1544 val = (i << 4) | 0x0f;
1545 snd_azf3328_game_outb(chip, IDX_GAME_AXES_CONFIG, val);
1546
1547 chip->axes[i] = snd_azf3328_game_inw(
1548 chip, IDX_GAME_AXIS_VALUE
1549 );
1550 }
1551 }
1552
Andreas Mohradf59312010-12-27 21:16:43 +01001553 /* trigger next sampling of axes, to be evaluated the next time we
Andreas Mohr02330fba2008-05-16 12:18:29 +02001554 * enter this function */
1555
1556 /* for some very, very strange reason we cannot enable
1557 * Measurement Ready monitoring for all axes here,
1558 * at least not when only one joystick connected */
1559 val = 0x03; /* we're able to monitor axes 1 and 2 only */
1560 snd_azf3328_game_outb(chip, IDX_GAME_AXES_CONFIG, val);
1561
1562 snd_azf3328_game_outw(chip, IDX_GAME_AXIS_VALUE, 0xffff);
1563 spin_unlock_irqrestore(&chip->reg_lock, flags);
1564
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001565 for (i = 0; i < ARRAY_SIZE(chip->axes); i++) {
Andreas Mohr02330fba2008-05-16 12:18:29 +02001566 axes[i] = chip->axes[i];
1567 if (axes[i] == 0xffff)
1568 axes[i] = -1;
1569 }
1570
1571 snd_azf3328_dbggame("cooked_read: axes %d %d %d %d buttons %d\n",
1572 axes[0], axes[1], axes[2], axes[3], *buttons
1573 );
1574
1575 return 0;
1576}
1577
1578static int __devinit
1579snd_azf3328_gameport(struct snd_azf3328 *chip, int dev)
1580{
1581 struct gameport *gp;
1582
Andreas Mohr02330fba2008-05-16 12:18:29 +02001583 chip->gameport = gp = gameport_allocate_port();
1584 if (!gp) {
1585 printk(KERN_ERR "azt3328: cannot alloc memory for gameport\n");
1586 return -ENOMEM;
1587 }
1588
1589 gameport_set_name(gp, "AZF3328 Gameport");
1590 gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
1591 gameport_set_dev_parent(gp, &chip->pci->dev);
Andreas Mohr627d3e72008-06-23 11:50:47 +02001592 gp->io = chip->game_io;
Andreas Mohr02330fba2008-05-16 12:18:29 +02001593 gameport_set_port_data(gp, chip);
1594
1595 gp->open = snd_azf3328_gameport_open;
1596 gp->close = snd_azf3328_gameport_close;
1597 gp->fuzz = 16; /* seems ok */
1598 gp->cooked_read = snd_azf3328_gameport_cooked_read;
1599
1600 /* DISABLE legacy address: we don't need it! */
1601 snd_azf3328_gameport_legacy_address_enable(chip, 0);
1602
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001603 snd_azf3328_gameport_set_counter_frequency(chip,
1604 GAME_HWCFG_ADC_COUNTER_FREQ_1_200);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001605 snd_azf3328_gameport_axis_circuit_enable(chip, 0);
1606
1607 gameport_register_port(chip->gameport);
1608
1609 return 0;
1610}
1611
1612static void
1613snd_azf3328_gameport_free(struct snd_azf3328 *chip)
1614{
1615 if (chip->gameport) {
1616 gameport_unregister_port(chip->gameport);
1617 chip->gameport = NULL;
1618 }
1619 snd_azf3328_gameport_irq_enable(chip, 0);
1620}
1621#else
1622static inline int
1623snd_azf3328_gameport(struct snd_azf3328 *chip, int dev) { return -ENOSYS; }
1624static inline void
1625snd_azf3328_gameport_free(struct snd_azf3328 *chip) { }
1626static inline void
1627snd_azf3328_gameport_interrupt(struct snd_azf3328 *chip)
1628{
1629 printk(KERN_WARNING "huh, game port IRQ occurred!?\n");
1630}
1631#endif /* SUPPORT_GAMEPORT */
1632
1633/******************************************************************/
1634
Andreas Mohr627d3e72008-06-23 11:50:47 +02001635static inline void
1636snd_azf3328_irq_log_unknown_type(u8 which)
1637{
Andreas Mohr78df6172009-07-12 22:17:54 +02001638 snd_azf3328_dbgcodec(
Andreas Mohr627d3e72008-06-23 11:50:47 +02001639 "azt3328: unknown IRQ type (%x) occurred, please report!\n",
1640 which
1641 );
1642}
1643
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001644static inline void
1645snd_azf3328_codec_interrupt(struct snd_azf3328 *chip, u8 status)
1646{
1647 u8 which;
1648 enum snd_azf3328_codec_type codec_type;
1649 const struct snd_azf3328_codec_data *codec;
1650
1651 for (codec_type = AZF_CODEC_PLAYBACK;
1652 codec_type <= AZF_CODEC_I2S_OUT;
1653 ++codec_type) {
1654
1655 /* skip codec if there's no interrupt for it */
1656 if (!(status & (1 << codec_type)))
1657 continue;
1658
1659 codec = &chip->codecs[codec_type];
1660
1661 spin_lock(&chip->reg_lock);
1662 which = snd_azf3328_codec_inb(codec, IDX_IO_CODEC_IRQTYPE);
1663 /* ack all IRQ types immediately */
1664 snd_azf3328_codec_outb(codec, IDX_IO_CODEC_IRQTYPE, which);
1665 spin_unlock(&chip->reg_lock);
1666
Andreas Mohr78df6172009-07-12 22:17:54 +02001667 if ((chip->pcm[codec_type]) && (codec->substream)) {
1668 snd_pcm_period_elapsed(codec->substream);
1669 snd_azf3328_dbgcodec("%s period done (#%x), @ %x\n",
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001670 codec->name,
1671 which,
1672 snd_azf3328_codec_inl(
1673 codec, IDX_IO_CODEC_DMA_CURRPOS
1674 )
1675 );
1676 } else
1677 printk(KERN_WARNING "azt3328: irq handler problem!\n");
1678 if (which & IRQ_SOMETHING)
1679 snd_azf3328_irq_log_unknown_type(which);
1680 }
1681}
1682
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001683static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +01001684snd_azf3328_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685{
Takashi Iwai95de7762005-11-17 15:02:42 +01001686 struct snd_azf3328 *chip = dev_id;
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001687 u8 status;
Andreas Mohr78df6172009-07-12 22:17:54 +02001688#if DEBUG_CODEC
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001689 static unsigned long irq_count;
Andreas Mohr02330fba2008-05-16 12:18:29 +02001690#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001692 status = snd_azf3328_ctrl_inb(chip, IDX_IO_IRQSTATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
1694 /* fast path out, to ease interrupt sharing */
Andreas Mohr02330fba2008-05-16 12:18:29 +02001695 if (!(status &
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001696 (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_I2S_OUT
1697 |IRQ_GAMEPORT|IRQ_MPU401|IRQ_TIMER)
Andreas Mohr02330fba2008-05-16 12:18:29 +02001698 ))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 return IRQ_NONE; /* must be interrupt for another device */
1700
Andreas Mohr78df6172009-07-12 22:17:54 +02001701 snd_azf3328_dbgcodec(
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001702 "irq_count %ld! IDX_IO_IRQSTATUS %04x\n",
Andreas Mohr627d3e72008-06-23 11:50:47 +02001703 irq_count++ /* debug-only */,
Andreas Mohr627d3e72008-06-23 11:50:47 +02001704 status
1705 );
Andreas Mohr02330fba2008-05-16 12:18:29 +02001706
Andreas Mohre2f87262006-05-17 11:04:19 +02001707 if (status & IRQ_TIMER) {
Andreas Mohr78df6172009-07-12 22:17:54 +02001708 /* snd_azf3328_dbgcodec("timer %ld\n",
Andreas Mohr02330fba2008-05-16 12:18:29 +02001709 snd_azf3328_codec_inl(chip, IDX_IO_TIMER_VALUE)
1710 & TIMER_VALUE_MASK
1711 ); */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001712 if (chip->timer)
1713 snd_timer_interrupt(chip->timer, chip->timer->sticks);
1714 /* ACK timer */
1715 spin_lock(&chip->reg_lock);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001716 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x07);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001717 spin_unlock(&chip->reg_lock);
Andreas Mohr78df6172009-07-12 22:17:54 +02001718 snd_azf3328_dbgcodec("azt3328: timer IRQ\n");
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001719 }
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001720
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001721 if (status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_I2S_OUT))
1722 snd_azf3328_codec_interrupt(chip, status);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001723
Andreas Mohr02330fba2008-05-16 12:18:29 +02001724 if (status & IRQ_GAMEPORT)
1725 snd_azf3328_gameport_interrupt(chip);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001726
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001727 /* MPU401 has less critical IRQ requirements
1728 * than timer and playback/recording, right? */
Andreas Mohre2f87262006-05-17 11:04:19 +02001729 if (status & IRQ_MPU401) {
David Howells7d12e782006-10-05 14:55:46 +01001730 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001731
1732 /* hmm, do we have to ack the IRQ here somehow?
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001733 * If so, then I don't know how yet... */
Andreas Mohr78df6172009-07-12 22:17:54 +02001734 snd_azf3328_dbgcodec("azt3328: MPU401 IRQ\n");
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001735 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 return IRQ_HANDLED;
1737}
1738
1739/*****************************************************************/
1740
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001741/* as long as we think we have identical snd_pcm_hardware parameters
1742 for playback, capture and i2s out, we can use the same physical struct
1743 since the struct is simply being copied into a member.
1744*/
1745static const struct snd_pcm_hardware snd_azf3328_hardware =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746{
1747 /* FIXME!! Correct? */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001748 .info = SNDRV_PCM_INFO_MMAP |
1749 SNDRV_PCM_INFO_INTERLEAVED |
1750 SNDRV_PCM_INFO_MMAP_VALID,
1751 .formats = SNDRV_PCM_FMTBIT_S8 |
1752 SNDRV_PCM_FMTBIT_U8 |
1753 SNDRV_PCM_FMTBIT_S16_LE |
1754 SNDRV_PCM_FMTBIT_U16_LE,
1755 .rates = SNDRV_PCM_RATE_5512 |
1756 SNDRV_PCM_RATE_8000_48000 |
1757 SNDRV_PCM_RATE_KNOT,
Andreas Mohr02330fba2008-05-16 12:18:29 +02001758 .rate_min = AZF_FREQ_4000,
1759 .rate_max = AZF_FREQ_66200,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 .channels_min = 1,
1761 .channels_max = 2,
Andreas Mohr79741502010-11-21 12:09:32 +01001762 .buffer_bytes_max = (64*1024),
1763 .period_bytes_min = 1024,
1764 .period_bytes_max = (32*1024),
1765 /* We simply have two DMA areas (instead of a list of descriptors
1766 such as other cards); I believe that this is a fixed hardware
1767 attribute and there isn't much driver magic to be done to expand it.
1768 Thus indicate that we have at least and at most 2 periods. */
1769 .periods_min = 2,
1770 .periods_max = 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 /* FIXME: maybe that card actually has a FIFO?
1772 * Hmm, it seems newer revisions do have one, but we still don't know
1773 * its size... */
1774 .fifo_size = 0,
1775};
1776
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
1778static unsigned int snd_azf3328_fixed_rates[] = {
Andreas Mohr02330fba2008-05-16 12:18:29 +02001779 AZF_FREQ_4000,
1780 AZF_FREQ_4800,
1781 AZF_FREQ_5512,
1782 AZF_FREQ_6620,
1783 AZF_FREQ_8000,
1784 AZF_FREQ_9600,
1785 AZF_FREQ_11025,
1786 AZF_FREQ_13240,
1787 AZF_FREQ_16000,
1788 AZF_FREQ_22050,
1789 AZF_FREQ_32000,
1790 AZF_FREQ_44100,
1791 AZF_FREQ_48000,
1792 AZF_FREQ_66200
1793};
1794
Takashi Iwai95de7762005-11-17 15:02:42 +01001795static struct snd_pcm_hw_constraint_list snd_azf3328_hw_constraints_rates = {
Andreas Mohr02330fba2008-05-16 12:18:29 +02001796 .count = ARRAY_SIZE(snd_azf3328_fixed_rates),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 .list = snd_azf3328_fixed_rates,
1798 .mask = 0,
1799};
1800
1801/*****************************************************************/
1802
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001803static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001804snd_azf3328_pcm_open(struct snd_pcm_substream *substream,
1805 enum snd_azf3328_codec_type codec_type
1806)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807{
Takashi Iwai95de7762005-11-17 15:02:42 +01001808 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
1809 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
1811 snd_azf3328_dbgcallenter();
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001812 chip->codecs[codec_type].substream = substream;
1813
1814 /* same parameters for all our codecs - at least we think so... */
1815 runtime->hw = snd_azf3328_hardware;
1816
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1818 &snd_azf3328_hw_constraints_rates);
1819 snd_azf3328_dbgcallleave();
1820 return 0;
1821}
1822
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001823static int
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001824snd_azf3328_playback_open(struct snd_pcm_substream *substream)
1825{
1826 return snd_azf3328_pcm_open(substream, AZF_CODEC_PLAYBACK);
1827}
1828
1829static int
Takashi Iwai95de7762005-11-17 15:02:42 +01001830snd_azf3328_capture_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001832 return snd_azf3328_pcm_open(substream, AZF_CODEC_CAPTURE);
1833}
1834
1835static int
1836snd_azf3328_i2s_out_open(struct snd_pcm_substream *substream)
1837{
1838 return snd_azf3328_pcm_open(substream, AZF_CODEC_I2S_OUT);
1839}
1840
1841static int
1842snd_azf3328_pcm_close(struct snd_pcm_substream *substream,
1843 enum snd_azf3328_codec_type codec_type
1844)
1845{
Takashi Iwai95de7762005-11-17 15:02:42 +01001846 struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
1848 snd_azf3328_dbgcallenter();
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001849 chip->codecs[codec_type].substream = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 snd_azf3328_dbgcallleave();
1851 return 0;
1852}
1853
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001854static int
Takashi Iwai95de7762005-11-17 15:02:42 +01001855snd_azf3328_playback_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001857 return snd_azf3328_pcm_close(substream, AZF_CODEC_PLAYBACK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858}
1859
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001860static int
Takashi Iwai95de7762005-11-17 15:02:42 +01001861snd_azf3328_capture_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001863 return snd_azf3328_pcm_close(substream, AZF_CODEC_CAPTURE);
1864}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001866static int
1867snd_azf3328_i2s_out_close(struct snd_pcm_substream *substream)
1868{
1869 return snd_azf3328_pcm_close(substream, AZF_CODEC_I2S_OUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870}
1871
1872/******************************************************************/
1873
Takashi Iwai95de7762005-11-17 15:02:42 +01001874static struct snd_pcm_ops snd_azf3328_playback_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 .open = snd_azf3328_playback_open,
1876 .close = snd_azf3328_playback_close,
1877 .ioctl = snd_pcm_lib_ioctl,
1878 .hw_params = snd_azf3328_hw_params,
1879 .hw_free = snd_azf3328_hw_free,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001880 .prepare = snd_azf3328_codec_prepare,
1881 .trigger = snd_azf3328_codec_playback_trigger,
1882 .pointer = snd_azf3328_codec_playback_pointer
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883};
1884
Takashi Iwai95de7762005-11-17 15:02:42 +01001885static struct snd_pcm_ops snd_azf3328_capture_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 .open = snd_azf3328_capture_open,
1887 .close = snd_azf3328_capture_close,
1888 .ioctl = snd_pcm_lib_ioctl,
1889 .hw_params = snd_azf3328_hw_params,
1890 .hw_free = snd_azf3328_hw_free,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001891 .prepare = snd_azf3328_codec_prepare,
1892 .trigger = snd_azf3328_codec_capture_trigger,
1893 .pointer = snd_azf3328_codec_capture_pointer
1894};
1895
1896static struct snd_pcm_ops snd_azf3328_i2s_out_ops = {
1897 .open = snd_azf3328_i2s_out_open,
1898 .close = snd_azf3328_i2s_out_close,
1899 .ioctl = snd_pcm_lib_ioctl,
1900 .hw_params = snd_azf3328_hw_params,
1901 .hw_free = snd_azf3328_hw_free,
1902 .prepare = snd_azf3328_codec_prepare,
1903 .trigger = snd_azf3328_codec_i2s_out_trigger,
1904 .pointer = snd_azf3328_codec_i2s_out_pointer
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905};
1906
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001907static int __devinit
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001908snd_azf3328_pcm(struct snd_azf3328 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909{
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001910enum { AZF_PCMDEV_STD, AZF_PCMDEV_I2S_OUT, NUM_AZF_PCMDEVS }; /* pcm devices */
1911
Takashi Iwai95de7762005-11-17 15:02:42 +01001912 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 int err;
1914
1915 snd_azf3328_dbgcallenter();
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001916
1917 err = snd_pcm_new(chip->card, "AZF3328 DSP", AZF_PCMDEV_STD,
1918 1, 1, &pcm);
1919 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 return err;
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001921 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1922 &snd_azf3328_playback_ops);
1923 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1924 &snd_azf3328_capture_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925
1926 pcm->private_data = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 pcm->info_flags = 0;
1928 strcpy(pcm->name, chip->card->shortname);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001929 /* same pcm object for playback/capture (see snd_pcm_new() above) */
1930 chip->pcm[AZF_CODEC_PLAYBACK] = pcm;
1931 chip->pcm[AZF_CODEC_CAPTURE] = pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
1933 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001934 snd_dma_pci_data(chip->pci),
1935 64*1024, 64*1024);
1936
1937 err = snd_pcm_new(chip->card, "AZF3328 I2S OUT", AZF_PCMDEV_I2S_OUT,
1938 1, 0, &pcm);
1939 if (err < 0)
1940 return err;
1941 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1942 &snd_azf3328_i2s_out_ops);
1943
1944 pcm->private_data = chip;
1945 pcm->info_flags = 0;
1946 strcpy(pcm->name, chip->card->shortname);
1947 chip->pcm[AZF_CODEC_I2S_OUT] = pcm;
1948
1949 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1950 snd_dma_pci_data(chip->pci),
1951 64*1024, 64*1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
1953 snd_azf3328_dbgcallleave();
1954 return 0;
1955}
1956
1957/******************************************************************/
1958
Andreas Mohr02330fba2008-05-16 12:18:29 +02001959/*** NOTE: the physical timer resolution actually is 1024000 ticks per second
1960 *** (probably derived from main crystal via a divider of 24),
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001961 *** but announcing those attributes to user-space would make programs
1962 *** configure the timer to a 1 tick value, resulting in an absolutely fatal
1963 *** timer IRQ storm.
1964 *** Thus I chose to announce a down-scaled virtual timer to the outside and
1965 *** calculate real timer countdown values internally.
1966 *** (the scale factor can be set via module parameter "seqtimer_scaling").
1967 ***/
1968
1969static int
Takashi Iwai95de7762005-11-17 15:02:42 +01001970snd_azf3328_timer_start(struct snd_timer *timer)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001971{
Takashi Iwai95de7762005-11-17 15:02:42 +01001972 struct snd_azf3328 *chip;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001973 unsigned long flags;
1974 unsigned int delay;
1975
1976 snd_azf3328_dbgcallenter();
1977 chip = snd_timer_chip(timer);
1978 delay = ((timer->sticks * seqtimer_scaling) - 1) & TIMER_VALUE_MASK;
Andreas Mohre2f87262006-05-17 11:04:19 +02001979 if (delay < 49) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001980 /* uhoh, that's not good, since user-space won't know about
1981 * this timing tweak
1982 * (we need to do it to avoid a lockup, though) */
1983
1984 snd_azf3328_dbgtimer("delay was too low (%d)!\n", delay);
1985 delay = 49; /* minimum time is 49 ticks */
1986 }
Andreas Mohradf59312010-12-27 21:16:43 +01001987 snd_azf3328_dbgtimer("setting timer countdown value %d\n", delay);
Andreas Mohr02330fba2008-05-16 12:18:29 +02001988 delay |= TIMER_COUNTDOWN_ENABLE | TIMER_IRQ_ENABLE;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001989 spin_lock_irqsave(&chip->reg_lock, flags);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02001990 snd_azf3328_ctrl_outl(chip, IDX_IO_TIMER_VALUE, delay);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001991 spin_unlock_irqrestore(&chip->reg_lock, flags);
1992 snd_azf3328_dbgcallleave();
1993 return 0;
1994}
1995
1996static int
Takashi Iwai95de7762005-11-17 15:02:42 +01001997snd_azf3328_timer_stop(struct snd_timer *timer)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02001998{
Takashi Iwai95de7762005-11-17 15:02:42 +01001999 struct snd_azf3328 *chip;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002000 unsigned long flags;
2001
2002 snd_azf3328_dbgcallenter();
2003 chip = snd_timer_chip(timer);
2004 spin_lock_irqsave(&chip->reg_lock, flags);
2005 /* disable timer countdown and interrupt */
Andreas Mohr79741502010-11-21 12:09:32 +01002006 /* Hmm, should we write TIMER_IRQ_ACK here?
2007 YES indeed, otherwise a rogue timer operation - which prompts
2008 ALSA(?) to call repeated stop() in vain, but NOT start() -
2009 will never end (value 0x03 is kept shown in control byte).
2010 Simply manually poking 0x04 _once_ immediately successfully stops
2011 the hardware/ALSA interrupt activity. */
2012 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x04);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002013 spin_unlock_irqrestore(&chip->reg_lock, flags);
2014 snd_azf3328_dbgcallleave();
2015 return 0;
2016}
2017
2018
2019static int
Takashi Iwai95de7762005-11-17 15:02:42 +01002020snd_azf3328_timer_precise_resolution(struct snd_timer *timer,
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002021 unsigned long *num, unsigned long *den)
2022{
2023 snd_azf3328_dbgcallenter();
2024 *num = 1;
2025 *den = 1024000 / seqtimer_scaling;
2026 snd_azf3328_dbgcallleave();
2027 return 0;
2028}
2029
Takashi Iwai95de7762005-11-17 15:02:42 +01002030static struct snd_timer_hardware snd_azf3328_timer_hw = {
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002031 .flags = SNDRV_TIMER_HW_AUTO,
2032 .resolution = 977, /* 1000000/1024000 = 0.9765625us */
2033 .ticks = 1024000, /* max tick count, defined by the value register; actually it's not 1024000, but 1048576, but we don't care */
2034 .start = snd_azf3328_timer_start,
2035 .stop = snd_azf3328_timer_stop,
2036 .precise_resolution = snd_azf3328_timer_precise_resolution,
2037};
2038
2039static int __devinit
Takashi Iwai95de7762005-11-17 15:02:42 +01002040snd_azf3328_timer(struct snd_azf3328 *chip, int device)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002041{
Takashi Iwai95de7762005-11-17 15:02:42 +01002042 struct snd_timer *timer = NULL;
2043 struct snd_timer_id tid;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002044 int err;
2045
2046 snd_azf3328_dbgcallenter();
2047 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
2048 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
2049 tid.card = chip->card->number;
2050 tid.device = device;
2051 tid.subdevice = 0;
2052
2053 snd_azf3328_timer_hw.resolution *= seqtimer_scaling;
2054 snd_azf3328_timer_hw.ticks /= seqtimer_scaling;
Andreas Mohr02330fba2008-05-16 12:18:29 +02002055
2056 err = snd_timer_new(chip->card, "AZF3328", &tid, &timer);
2057 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002058 goto out;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002059
2060 strcpy(timer->name, "AZF3328 timer");
2061 timer->private_data = chip;
2062 timer->hw = snd_azf3328_timer_hw;
2063
2064 chip->timer = timer;
2065
Andreas Mohr02330fba2008-05-16 12:18:29 +02002066 snd_azf3328_timer_stop(timer);
2067
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002068 err = 0;
2069
2070out:
2071 snd_azf3328_dbgcallleave();
2072 return err;
2073}
2074
2075/******************************************************************/
2076
Andreas Mohr02330fba2008-05-16 12:18:29 +02002077static int
2078snd_azf3328_free(struct snd_azf3328 *chip)
2079{
2080 if (chip->irq < 0)
2081 goto __end_hw;
2082
2083 /* reset (close) mixer:
2084 * first mute master volume, then reset
2085 */
2086 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1);
2087 snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
2088
2089 snd_azf3328_timer_stop(chip->timer);
2090 snd_azf3328_gameport_free(chip);
2091
2092 if (chip->irq >= 0)
2093 synchronize_irq(chip->irq);
2094__end_hw:
2095 if (chip->irq >= 0)
2096 free_irq(chip->irq, chip);
2097 pci_release_regions(chip->pci);
2098 pci_disable_device(chip->pci);
2099
2100 kfree(chip);
2101 return 0;
2102}
2103
2104static int
2105snd_azf3328_dev_free(struct snd_device *device)
2106{
2107 struct snd_azf3328 *chip = device->device_data;
2108 return snd_azf3328_free(chip);
2109}
2110
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111#if 0
2112/* check whether a bit can be modified */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002113static void
Andreas Mohr02330fba2008-05-16 12:18:29 +02002114snd_azf3328_test_bit(unsigned unsigned reg, int bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115{
2116 unsigned char val, valoff, valon;
2117
2118 val = inb(reg);
2119
2120 outb(val & ~(1 << bit), reg);
2121 valoff = inb(reg);
2122
2123 outb(val|(1 << bit), reg);
2124 valon = inb(reg);
Andreas Mohr02330fba2008-05-16 12:18:29 +02002125
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 outb(val, reg);
2127
Andreas Mohr78df6172009-07-12 22:17:54 +02002128 printk(KERN_DEBUG "reg %04x bit %d: %02x %02x %02x\n",
Andreas Mohr02330fba2008-05-16 12:18:29 +02002129 reg, bit, val, valoff, valon
2130 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131}
2132#endif
2133
Andreas Mohr02330fba2008-05-16 12:18:29 +02002134static inline void
Takashi Iwai95de7762005-11-17 15:02:42 +01002135snd_azf3328_debug_show_ports(const struct snd_azf3328 *chip)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002136{
Andreas Mohr02330fba2008-05-16 12:18:29 +02002137#if DEBUG_MISC
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002138 u16 tmp;
2139
Andreas Mohr02330fba2008-05-16 12:18:29 +02002140 snd_azf3328_dbgmisc(
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002141 "ctrl_io 0x%lx, game_io 0x%lx, mpu_io 0x%lx, "
Andreas Mohr02330fba2008-05-16 12:18:29 +02002142 "opl3_io 0x%lx, mixer_io 0x%lx, irq %d\n",
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002143 chip->ctrl_io, chip->game_io, chip->mpu_io,
Andreas Mohr02330fba2008-05-16 12:18:29 +02002144 chip->opl3_io, chip->mixer_io, chip->irq
2145 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002146
Andreas Mohr02330fba2008-05-16 12:18:29 +02002147 snd_azf3328_dbgmisc("game %02x %02x %02x %02x %02x %02x\n",
2148 snd_azf3328_game_inb(chip, 0),
2149 snd_azf3328_game_inb(chip, 1),
2150 snd_azf3328_game_inb(chip, 2),
2151 snd_azf3328_game_inb(chip, 3),
2152 snd_azf3328_game_inb(chip, 4),
2153 snd_azf3328_game_inb(chip, 5)
2154 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002155
Andreas Mohr02330fba2008-05-16 12:18:29 +02002156 for (tmp = 0; tmp < 0x07; tmp += 1)
2157 snd_azf3328_dbgmisc("mpu_io 0x%04x\n", inb(chip->mpu_io + tmp));
2158
2159 for (tmp = 0; tmp <= 0x07; tmp += 1)
2160 snd_azf3328_dbgmisc("0x%02x: game200 0x%04x, game208 0x%04x\n",
2161 tmp, inb(0x200 + tmp), inb(0x208 + tmp));
2162
2163 for (tmp = 0; tmp <= 0x01; tmp += 1)
2164 snd_azf3328_dbgmisc(
2165 "0x%02x: mpu300 0x%04x, mpu310 0x%04x, mpu320 0x%04x, "
2166 "mpu330 0x%04x opl388 0x%04x opl38c 0x%04x\n",
2167 tmp,
2168 inb(0x300 + tmp),
2169 inb(0x310 + tmp),
2170 inb(0x320 + tmp),
2171 inb(0x330 + tmp),
2172 inb(0x388 + tmp),
2173 inb(0x38c + tmp)
2174 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002175
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002176 for (tmp = 0; tmp < AZF_IO_SIZE_CTRL; tmp += 2)
2177 snd_azf3328_dbgmisc("ctrl 0x%02x: 0x%04x\n",
2178 tmp, snd_azf3328_ctrl_inw(chip, tmp)
Andreas Mohr02330fba2008-05-16 12:18:29 +02002179 );
Andreas Mohre24a1212007-03-26 12:49:45 +02002180
2181 for (tmp = 0; tmp < AZF_IO_SIZE_MIXER; tmp += 2)
Andreas Mohr02330fba2008-05-16 12:18:29 +02002182 snd_azf3328_dbgmisc("mixer 0x%02x: 0x%04x\n",
2183 tmp, snd_azf3328_mixer_inw(chip, tmp)
2184 );
2185#endif /* DEBUG_MISC */
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002186}
2187
2188static int __devinit
Takashi Iwai95de7762005-11-17 15:02:42 +01002189snd_azf3328_create(struct snd_card *card,
Andreas Mohr02330fba2008-05-16 12:18:29 +02002190 struct pci_dev *pci,
2191 unsigned long device_type,
2192 struct snd_azf3328 **rchip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193{
Takashi Iwai95de7762005-11-17 15:02:42 +01002194 struct snd_azf3328 *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 int err;
Takashi Iwai95de7762005-11-17 15:02:42 +01002196 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 .dev_free = snd_azf3328_dev_free,
2198 };
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002199 u8 dma_init;
2200 enum snd_azf3328_codec_type codec_type;
Andreas Mohr9fd8d362010-12-27 21:17:00 +01002201 struct snd_azf3328_codec *codec_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
2203 *rchip = NULL;
2204
Andreas Mohr02330fba2008-05-16 12:18:29 +02002205 err = pci_enable_device(pci);
2206 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 return err;
2208
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002209 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 if (chip == NULL) {
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002211 err = -ENOMEM;
2212 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 }
2214 spin_lock_init(&chip->reg_lock);
2215 chip->card = card;
2216 chip->pci = pci;
2217 chip->irq = -1;
2218
2219 /* check if we can restrict PCI DMA transfers to 24 bits */
Yang Hongyang2f4f27d2009-04-06 19:01:18 -07002220 if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 ||
2221 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) {
Andreas Mohr02330fba2008-05-16 12:18:29 +02002222 snd_printk(KERN_ERR "architecture does not support "
2223 "24bit PCI busmaster DMA\n"
2224 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002225 err = -ENXIO;
2226 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 }
2228
Andreas Mohr02330fba2008-05-16 12:18:29 +02002229 err = pci_request_regions(pci, "Aztech AZF3328");
2230 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002231 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002233 chip->ctrl_io = pci_resource_start(pci, 0);
Andreas Mohr02330fba2008-05-16 12:18:29 +02002234 chip->game_io = pci_resource_start(pci, 1);
2235 chip->mpu_io = pci_resource_start(pci, 2);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002236 chip->opl3_io = pci_resource_start(pci, 3);
Andreas Mohr02330fba2008-05-16 12:18:29 +02002237 chip->mixer_io = pci_resource_start(pci, 4);
2238
Andreas Mohr9fd8d362010-12-27 21:17:00 +01002239 codec_setup = &chip->codecs[AZF_CODEC_PLAYBACK];
2240 codec_setup->io_base = chip->ctrl_io + AZF_IO_OFFS_CODEC_PLAYBACK;
2241 codec_setup->name = "PLAYBACK";
2242
2243 codec_setup = &chip->codecs[AZF_CODEC_CAPTURE];
2244 codec_setup->io_base = chip->ctrl_io + AZF_IO_OFFS_CODEC_CAPTURE;
2245 codec_setup->name = "CAPTURE";
2246
2247 codec_setup = &chip->codecs[AZF_CODEC_I2S_OUT];
2248 codec_setup->io_base = chip->ctrl_io + AZF_IO_OFFS_CODEC_I2S_OUT;
2249 codec_setup->name = "I2S_OUT";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250
Takashi Iwai437a5a42006-11-21 12:14:23 +01002251 if (request_irq(pci->irq, snd_azf3328_interrupt,
2252 IRQF_SHARED, card->shortname, chip)) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002253 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002254 err = -EBUSY;
2255 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 }
2257 chip->irq = pci->irq;
2258 pci_set_master(pci);
2259 synchronize_irq(chip->irq);
2260
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002261 snd_azf3328_debug_show_ports(chip);
Andreas Mohr02330fba2008-05-16 12:18:29 +02002262
2263 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
2264 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002265 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
2267 /* create mixer interface & switches */
Andreas Mohr02330fba2008-05-16 12:18:29 +02002268 err = snd_azf3328_mixer_new(chip);
2269 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002270 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002272 /* standard codec init stuff */
2273 /* default DMA init value */
2274 dma_init = DMA_RUN_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002276 for (codec_type = AZF_CODEC_PLAYBACK;
2277 codec_type <= AZF_CODEC_I2S_OUT; ++codec_type) {
2278 struct snd_azf3328_codec_data *codec =
2279 &chip->codecs[codec_type];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
Andreas Mohradf59312010-12-27 21:16:43 +01002281 /* shutdown codecs to reduce power / noise */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002282 /* have ...ctrl_codec_activity() act properly */
2283 codec->running = 1;
2284 snd_azf3328_ctrl_codec_activity(chip, codec_type, 0);
2285
2286 spin_lock_irq(&chip->reg_lock);
2287 snd_azf3328_codec_outb(codec, IDX_IO_CODEC_DMA_FLAGS,
2288 dma_init);
2289 spin_unlock_irq(&chip->reg_lock);
2290 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
2292 snd_card_set_dev(card, &pci->dev);
2293
2294 *rchip = chip;
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002295
2296 err = 0;
2297 goto out;
2298
2299out_err:
2300 if (chip)
2301 snd_azf3328_free(chip);
2302 pci_disable_device(pci);
2303
2304out:
2305 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306}
2307
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002308static int __devinit
2309snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310{
2311 static int dev;
Takashi Iwai95de7762005-11-17 15:02:42 +01002312 struct snd_card *card;
2313 struct snd_azf3328 *chip;
2314 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 int err;
2316
2317 snd_azf3328_dbgcallenter();
2318 if (dev >= SNDRV_CARDS)
2319 return -ENODEV;
2320 if (!enable[dev]) {
2321 dev++;
2322 return -ENOENT;
2323 }
2324
Takashi Iwaie58de7b2008-12-28 16:44:30 +01002325 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2326 if (err < 0)
2327 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
2329 strcpy(card->driver, "AZF3328");
2330 strcpy(card->shortname, "Aztech AZF3328 (PCI168)");
2331
Andreas Mohr02330fba2008-05-16 12:18:29 +02002332 err = snd_azf3328_create(card, pci, pci_id->driver_data, &chip);
2333 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002334 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
Andreas Mohrca54bde2006-05-17 11:02:24 +02002336 card->private_data = chip;
2337
Andreas Mohr78df6172009-07-12 22:17:54 +02002338 /* chose to use MPU401_HW_AZT2320 ID instead of MPU401_HW_MPU401,
2339 since our hardware ought to be similar, thus use same ID. */
Andreas Mohr02330fba2008-05-16 12:18:29 +02002340 err = snd_mpu401_uart_new(
Andreas Mohr78df6172009-07-12 22:17:54 +02002341 card, 0,
2342 MPU401_HW_AZT2320, chip->mpu_io, MPU401_INFO_INTEGRATED,
Andreas Mohr02330fba2008-05-16 12:18:29 +02002343 pci->irq, 0, &chip->rmidi
2344 );
2345 if (err < 0) {
2346 snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n",
2347 chip->mpu_io
2348 );
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002349 goto out_err;
2350 }
2351
Andreas Mohr02330fba2008-05-16 12:18:29 +02002352 err = snd_azf3328_timer(chip, 0);
2353 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002354 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002356 err = snd_azf3328_pcm(chip);
Andreas Mohr02330fba2008-05-16 12:18:29 +02002357 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002358 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359
Andreas Mohr02330fba2008-05-16 12:18:29 +02002360 if (snd_opl3_create(card, chip->opl3_io, chip->opl3_io+2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 OPL3_HW_AUTO, 1, &opl3) < 0) {
Takashi Iwai99b359b2005-10-20 18:26:44 +02002362 snd_printk(KERN_ERR "azf3328: no OPL3 device at 0x%lx-0x%lx?\n",
Andreas Mohr02330fba2008-05-16 12:18:29 +02002363 chip->opl3_io, chip->opl3_io+2
2364 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 } else {
Andreas Mohr02330fba2008-05-16 12:18:29 +02002366 /* need to use IDs 1, 2 since ID 0 is snd_azf3328_timer above */
2367 err = snd_opl3_timer_new(opl3, 1, 2);
2368 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002369 goto out_err;
Andreas Mohr02330fba2008-05-16 12:18:29 +02002370 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
2371 if (err < 0)
2372 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 }
2374
Andreas Mohrca54bde2006-05-17 11:02:24 +02002375 opl3->private_data = chip;
2376
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 sprintf(card->longname, "%s at 0x%lx, irq %i",
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002378 card->shortname, chip->ctrl_io, chip->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
Andreas Mohr02330fba2008-05-16 12:18:29 +02002380 err = snd_card_register(card);
2381 if (err < 0)
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002382 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383
2384#ifdef MODULE
Andreas Mohr78df6172009-07-12 22:17:54 +02002385 printk(KERN_INFO
Andreas Mohre24a1212007-03-26 12:49:45 +02002386"azt3328: Sound driver for Aztech AZF3328-based soundcards such as PCI168.\n"
2387"azt3328: Hardware was completely undocumented, unfortunately.\n"
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002388"azt3328: Feel free to contact andi AT lisas.de for bug reports etc.!\n"
2389"azt3328: User-scalable sequencer timer set to %dHz (1024000Hz / %d).\n",
2390 1024000 / seqtimer_scaling, seqtimer_scaling);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391#endif
2392
Andreas Mohr02330fba2008-05-16 12:18:29 +02002393 snd_azf3328_gameport(chip, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
2395 pci_set_drvdata(pci, card);
2396 dev++;
2397
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002398 err = 0;
2399 goto out;
Andreas Mohr02330fba2008-05-16 12:18:29 +02002400
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002401out_err:
Andreas Mohr02330fba2008-05-16 12:18:29 +02002402 snd_printk(KERN_ERR "azf3328: something failed, exiting\n");
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002403 snd_card_free(card);
Andreas Mohr02330fba2008-05-16 12:18:29 +02002404
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002405out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 snd_azf3328_dbgcallleave();
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002407 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408}
2409
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002410static void __devexit
2411snd_azf3328_remove(struct pci_dev *pci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412{
2413 snd_azf3328_dbgcallenter();
2414 snd_card_free(pci_get_drvdata(pci));
2415 pci_set_drvdata(pci, NULL);
2416 snd_azf3328_dbgcallleave();
2417}
2418
Andreas Mohrca54bde2006-05-17 11:02:24 +02002419#ifdef CONFIG_PM
Andreas Mohr78df6172009-07-12 22:17:54 +02002420static inline void
2421snd_azf3328_suspend_regs(unsigned long io_addr, unsigned count, u32 *saved_regs)
2422{
2423 unsigned reg;
2424
2425 for (reg = 0; reg < count; ++reg) {
2426 *saved_regs = inl(io_addr);
2427 snd_azf3328_dbgpm("suspend: io 0x%04lx: 0x%08x\n",
2428 io_addr, *saved_regs);
2429 ++saved_regs;
2430 io_addr += sizeof(*saved_regs);
2431 }
2432}
2433
Andreas Mohrca54bde2006-05-17 11:02:24 +02002434static int
2435snd_azf3328_suspend(struct pci_dev *pci, pm_message_t state)
2436{
2437 struct snd_card *card = pci_get_drvdata(pci);
2438 struct snd_azf3328 *chip = card->private_data;
Andreas Mohr78df6172009-07-12 22:17:54 +02002439 u16 *saved_regs_ctrl_u16;
Andreas Mohrca54bde2006-05-17 11:02:24 +02002440
2441 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
Andreas Mohr02330fba2008-05-16 12:18:29 +02002442
Andreas Mohradf59312010-12-27 21:16:43 +01002443 /* same pcm object for playback/capture */
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002444 snd_pcm_suspend_all(chip->pcm[AZF_CODEC_PLAYBACK]);
2445 snd_pcm_suspend_all(chip->pcm[AZF_CODEC_I2S_OUT]);
Andreas Mohrca54bde2006-05-17 11:02:24 +02002446
Andreas Mohr78df6172009-07-12 22:17:54 +02002447 snd_azf3328_suspend_regs(chip->mixer_io,
2448 ARRAY_SIZE(chip->saved_regs_mixer), chip->saved_regs_mixer);
Andreas Mohrca54bde2006-05-17 11:02:24 +02002449
2450 /* make sure to disable master volume etc. to prevent looping sound */
2451 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1);
2452 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
Andreas Mohr02330fba2008-05-16 12:18:29 +02002453
Andreas Mohr78df6172009-07-12 22:17:54 +02002454 snd_azf3328_suspend_regs(chip->ctrl_io,
2455 ARRAY_SIZE(chip->saved_regs_ctrl), chip->saved_regs_ctrl);
Andreas Mohr627d3e72008-06-23 11:50:47 +02002456
2457 /* manually store the one currently relevant write-only reg, too */
Andreas Mohr78df6172009-07-12 22:17:54 +02002458 saved_regs_ctrl_u16 = (u16 *)chip->saved_regs_ctrl;
2459 saved_regs_ctrl_u16[IDX_IO_6AH / 2] = chip->shadow_reg_ctrl_6AH;
Andreas Mohr627d3e72008-06-23 11:50:47 +02002460
Andreas Mohr78df6172009-07-12 22:17:54 +02002461 snd_azf3328_suspend_regs(chip->game_io,
2462 ARRAY_SIZE(chip->saved_regs_game), chip->saved_regs_game);
2463 snd_azf3328_suspend_regs(chip->mpu_io,
2464 ARRAY_SIZE(chip->saved_regs_mpu), chip->saved_regs_mpu);
2465 snd_azf3328_suspend_regs(chip->opl3_io,
2466 ARRAY_SIZE(chip->saved_regs_opl3), chip->saved_regs_opl3);
Andreas Mohrca54bde2006-05-17 11:02:24 +02002467
Andreas Mohrca54bde2006-05-17 11:02:24 +02002468 pci_disable_device(pci);
2469 pci_save_state(pci);
Takashi Iwai30b35392006-10-11 18:52:53 +02002470 pci_set_power_state(pci, pci_choose_state(pci, state));
Andreas Mohrca54bde2006-05-17 11:02:24 +02002471 return 0;
2472}
2473
Andreas Mohr78df6172009-07-12 22:17:54 +02002474static inline void
2475snd_azf3328_resume_regs(const u32 *saved_regs,
2476 unsigned long io_addr,
2477 unsigned count
2478)
2479{
2480 unsigned reg;
2481
2482 for (reg = 0; reg < count; ++reg) {
2483 outl(*saved_regs, io_addr);
2484 snd_azf3328_dbgpm("resume: io 0x%04lx: 0x%08x --> 0x%08x\n",
2485 io_addr, *saved_regs, inl(io_addr));
2486 ++saved_regs;
2487 io_addr += sizeof(*saved_regs);
2488 }
2489}
2490
Andreas Mohrca54bde2006-05-17 11:02:24 +02002491static int
2492snd_azf3328_resume(struct pci_dev *pci)
2493{
2494 struct snd_card *card = pci_get_drvdata(pci);
Andreas Mohrdfbf9512009-07-05 13:55:46 +02002495 const struct snd_azf3328 *chip = card->private_data;
Andreas Mohrca54bde2006-05-17 11:02:24 +02002496
Andreas Mohrca54bde2006-05-17 11:02:24 +02002497 pci_set_power_state(pci, PCI_D0);
Takashi Iwai30b35392006-10-11 18:52:53 +02002498 pci_restore_state(pci);
2499 if (pci_enable_device(pci) < 0) {
2500 printk(KERN_ERR "azt3328: pci_enable_device failed, "
2501 "disabling device\n");
2502 snd_card_disconnect(card);
2503 return -EIO;
2504 }
Andreas Mohrca54bde2006-05-17 11:02:24 +02002505 pci_set_master(pci);
2506
Andreas Mohr78df6172009-07-12 22:17:54 +02002507 snd_azf3328_resume_regs(chip->saved_regs_game, chip->game_io,
2508 ARRAY_SIZE(chip->saved_regs_game));
2509 snd_azf3328_resume_regs(chip->saved_regs_mpu, chip->mpu_io,
2510 ARRAY_SIZE(chip->saved_regs_mpu));
2511 snd_azf3328_resume_regs(chip->saved_regs_opl3, chip->opl3_io,
2512 ARRAY_SIZE(chip->saved_regs_opl3));
2513
2514 snd_azf3328_resume_regs(chip->saved_regs_mixer, chip->mixer_io,
2515 ARRAY_SIZE(chip->saved_regs_mixer));
2516
2517 /* unfortunately with 32bit transfers, IDX_MIXER_PLAY_MASTER (0x02)
2518 and IDX_MIXER_RESET (offset 0x00) get touched at the same time,
2519 resulting in a mixer reset condition persisting until _after_
2520 master vol was restored. Thus master vol needs an extra restore. */
2521 outw(((u16 *)chip->saved_regs_mixer)[1], chip->mixer_io + 2);
2522
2523 snd_azf3328_resume_regs(chip->saved_regs_ctrl, chip->ctrl_io,
2524 ARRAY_SIZE(chip->saved_regs_ctrl));
Andreas Mohrca54bde2006-05-17 11:02:24 +02002525
2526 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
2527 return 0;
2528}
Andreas Mohr02330fba2008-05-16 12:18:29 +02002529#endif /* CONFIG_PM */
Andreas Mohrca54bde2006-05-17 11:02:24 +02002530
2531
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532static struct pci_driver driver = {
2533 .name = "AZF3328",
2534 .id_table = snd_azf3328_ids,
2535 .probe = snd_azf3328_probe,
2536 .remove = __devexit_p(snd_azf3328_remove),
Andreas Mohrca54bde2006-05-17 11:02:24 +02002537#ifdef CONFIG_PM
2538 .suspend = snd_azf3328_suspend,
2539 .resume = snd_azf3328_resume,
2540#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541};
2542
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002543static int __init
2544alsa_card_azf3328_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545{
2546 int err;
2547 snd_azf3328_dbgcallenter();
Takashi Iwai01d25d42005-04-11 16:58:24 +02002548 err = pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 snd_azf3328_dbgcallleave();
2550 return err;
2551}
2552
Andreas Mohrd91c64c2005-10-25 11:17:45 +02002553static void __exit
2554alsa_card_azf3328_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555{
2556 snd_azf3328_dbgcallenter();
2557 pci_unregister_driver(&driver);
2558 snd_azf3328_dbgcallleave();
2559}
2560
2561module_init(alsa_card_azf3328_init)
2562module_exit(alsa_card_azf3328_exit)