aboutsummaryrefslogtreecommitdiff
path: root/sound/isa
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /sound/isa
downloadlinux-stericsson-1da177e4c3f41524e886b7f1b8a0c1fc7321cac2.tar.gz
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'sound/isa')
-rw-r--r--sound/isa/Kconfig377
-rw-r--r--sound/isa/Makefile26
-rw-r--r--sound/isa/ad1816a/Makefile10
-rw-r--r--sound/isa/ad1816a/ad1816a.c312
-rw-r--r--sound/isa/ad1816a/ad1816a_lib.c974
-rw-r--r--sound/isa/ad1848/Makefile15
-rw-r--r--sound/isa/ad1848/ad1848.c151
-rw-r--r--sound/isa/ad1848/ad1848_lib.c1279
-rw-r--r--sound/isa/als100.c336
-rw-r--r--sound/isa/azt2320.c366
-rw-r--r--sound/isa/cmi8330.c633
-rw-r--r--sound/isa/cs423x/Makefile25
-rw-r--r--sound/isa/cs423x/cs4231.c169
-rw-r--r--sound/isa/cs423x/cs4231_lib.c1964
-rw-r--r--sound/isa/cs423x/cs4232.c2
-rw-r--r--sound/isa/cs423x/cs4236.c608
-rw-r--r--sound/isa/cs423x/cs4236_lib.c970
-rw-r--r--sound/isa/dt019x.c327
-rw-r--r--sound/isa/es1688/Makefile11
-rw-r--r--sound/isa/es1688/es1688.c204
-rw-r--r--sound/isa/es1688/es1688_lib.c1062
-rw-r--r--sound/isa/es18xx.c2224
-rw-r--r--sound/isa/gus/Makefile36
-rw-r--r--sound/isa/gus/gus_dma.c244
-rw-r--r--sound/isa/gus/gus_dram.c103
-rw-r--r--sound/isa/gus/gus_instr.c173
-rw-r--r--sound/isa/gus/gus_io.c531
-rw-r--r--sound/isa/gus/gus_irq.c142
-rw-r--r--sound/isa/gus/gus_main.c514
-rw-r--r--sound/isa/gus/gus_mem.c353
-rw-r--r--sound/isa/gus/gus_mem_proc.c135
-rw-r--r--sound/isa/gus/gus_mixer.c199
-rw-r--r--sound/isa/gus/gus_pcm.c903
-rw-r--r--sound/isa/gus/gus_reset.c413
-rw-r--r--sound/isa/gus/gus_sample.c155
-rw-r--r--sound/isa/gus/gus_simple.c634
-rw-r--r--sound/isa/gus/gus_synth.c329
-rw-r--r--sound/isa/gus/gus_tables.h86
-rw-r--r--sound/isa/gus/gus_timer.c204
-rw-r--r--sound/isa/gus/gus_uart.c257
-rw-r--r--sound/isa/gus/gus_volume.c210
-rw-r--r--sound/isa/gus/gusclassic.c260
-rw-r--r--sound/isa/gus/gusextreme.c374
-rw-r--r--sound/isa/gus/gusmax.c400
-rw-r--r--sound/isa/gus/interwave-stb.c2
-rw-r--r--sound/isa/gus/interwave.c969
-rw-r--r--sound/isa/opl3sa2.c860
-rw-r--r--sound/isa/opti9xx/Makefile13
-rw-r--r--sound/isa/opti9xx/opti92x-ad1848.c2226
-rw-r--r--sound/isa/opti9xx/opti92x-cs4231.c2
-rw-r--r--sound/isa/opti9xx/opti93x.c3
-rw-r--r--sound/isa/sb/Makefile39
-rw-r--r--sound/isa/sb/emu8000.c1170
-rw-r--r--sound/isa/sb/emu8000_callback.c543
-rw-r--r--sound/isa/sb/emu8000_local.h43
-rw-r--r--sound/isa/sb/emu8000_patch.c303
-rw-r--r--sound/isa/sb/emu8000_pcm.c704
-rw-r--r--sound/isa/sb/emu8000_synth.c134
-rw-r--r--sound/isa/sb/es968.c235
-rw-r--r--sound/isa/sb/sb16.c678
-rw-r--r--sound/isa/sb/sb16_csp.c1175
-rw-r--r--sound/isa/sb/sb16_csp_codecs.h949
-rw-r--r--sound/isa/sb/sb16_main.c916
-rw-r--r--sound/isa/sb/sb8.c223
-rw-r--r--sound/isa/sb/sb8_main.c565
-rw-r--r--sound/isa/sb/sb8_midi.c293
-rw-r--r--sound/isa/sb/sb_common.c313
-rw-r--r--sound/isa/sb/sb_mixer.c844
-rw-r--r--sound/isa/sb/sbawe.c2
-rw-r--r--sound/isa/sgalaxy.c322
-rw-r--r--sound/isa/sscape.c1517
-rw-r--r--sound/isa/wavefront/Makefile9
-rw-r--r--sound/isa/wavefront/wavefront.c716
-rw-r--r--sound/isa/wavefront/wavefront_fx.c1019
-rw-r--r--sound/isa/wavefront/wavefront_midi.c570
-rw-r--r--sound/isa/wavefront/wavefront_synth.c2243
76 files changed, 38300 insertions, 0 deletions
diff --git a/sound/isa/Kconfig b/sound/isa/Kconfig
new file mode 100644
index 000000000000..4a6be966bd9f
--- /dev/null
+++ b/sound/isa/Kconfig
@@ -0,0 +1,377 @@
+# ALSA ISA drivers
+
+menu "ISA devices"
+ depends on SND!=n && ISA
+
+config SND_AD1848_LIB
+ tristate
+ select SND_PCM
+ select SND_GENERIC_PM
+
+config SND_CS4231_LIB
+ tristate
+ select SND_PCM
+ select SND_GENERIC_PM
+
+config SND_AD1816A
+ tristate "Analog Devices SoundPort AD1816A"
+ depends on SND && ISAPNP
+ select SND_OPL3_LIB
+ select SND_MPU401_UART
+ select SND_PCM
+ help
+ Say Y here to include support for Analog Devices SoundPort
+ AD1816A or compatible sound chips.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-ad1816a.
+
+config SND_AD1848
+ tristate "Generic AD1848/CS4248 driver"
+ depends on SND
+ select SND_AD1848_LIB
+ help
+ Say Y here to include support for AD1848 (Analog Devices) or
+ CS4248 (Cirrus Logic - Crystal Semiconductors) chips.
+
+ For newer chips from Cirrus Logic, use the CS4231, CS4232 or
+ CS4236+ drivers.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-ad1848.
+
+config SND_CS4231
+ tristate "Generic Cirrus Logic CS4231 driver"
+ depends on SND
+ select SND_MPU401_UART
+ select SND_CS4231_LIB
+ help
+ Say Y here to include support for CS4231 chips from Cirrus
+ Logic - Crystal Semiconductors.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-cs4231.
+
+config SND_CS4232
+ tristate "Generic Cirrus Logic CS4232 driver"
+ depends on SND
+ select SND_OPL3_LIB
+ select SND_MPU401_UART
+ select SND_CS4231_LIB
+ help
+ Say Y here to include support for CS4232 chips from Cirrus
+ Logic - Crystal Semiconductors.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-cs4232.
+
+config SND_CS4236
+ tristate "Generic Cirrus Logic CS4236+ driver"
+ depends on SND
+ select SND_OPL3_LIB
+ select SND_MPU401_UART
+ select SND_CS4231_LIB
+ help
+ Say Y to include support for CS4235,CS4236,CS4237B,CS4238B,
+ CS4239 chips from Cirrus Logic - Crystal Semiconductors.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-cs4236.
+
+config SND_ES968
+ tristate "Generic ESS ES968 driver"
+ depends on SND && ISAPNP
+ select SND_MPU401_UART
+ select SND_PCM
+ help
+ Say Y here to include support for ESS AudioDrive ES968 chips.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-es968.
+
+config SND_ES1688
+ tristate "Generic ESS ES688/ES1688 driver"
+ depends on SND
+ select SND_OPL3_LIB
+ select SND_MPU401_UART
+ select SND_PCM
+ help
+ Say Y here to include support for ESS AudioDrive ES688 or
+ ES1688 chips.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-es1688.
+
+config SND_ES18XX
+ tristate "Generic ESS ES18xx driver"
+ depends on SND
+ select SND_OPL3_LIB
+ select SND_MPU401_UART
+ select SND_PCM
+ select SND_GENERIC_PM
+ help
+ Say Y here to include support for ESS AudioDrive ES18xx chips.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-es18xx.
+
+config SND_GUS_SYNTH
+ tristate
+
+config SND_GUSCLASSIC
+ tristate "Gravis UltraSound Classic"
+ depends on SND
+ select SND_RAWMIDI
+ select SND_PCM
+ select SND_GUS_SYNTH
+ help
+ Say Y here to include support for Gravis UltraSound Classic
+ soundcards.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-gusclassic.
+
+config SND_GUSEXTREME
+ tristate "Gravis UltraSound Extreme"
+ depends on SND
+ select SND_HWDEP
+ select SND_MPU401_UART
+ select SND_PCM
+ select SND_GUS_SYNTH
+ help
+ Say Y here to include support for Gravis UltraSound Extreme
+ soundcards.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-gusextreme.
+
+config SND_GUSMAX
+ tristate "Gravis UltraSound MAX"
+ depends on SND
+ select SND_RAWMIDI
+ select SND_CS4231_LIB
+ select SND_GUS_SYNTH
+ help
+ Say Y here to include support for Gravis UltraSound MAX
+ soundcards.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-gusmax.
+
+config SND_INTERWAVE
+ tristate "AMD InterWave, Gravis UltraSound PnP"
+ depends on SND
+ select SND_RAWMIDI
+ select SND_CS4231_LIB
+ select SND_GUS_SYNTH
+ help
+ Say Y here to include support for AMD InterWave based
+ soundcards (Gravis UltraSound Plug & Play, STB SoundRage32,
+ MED3210, Dynasonic Pro, Panasonic PCA761AW).
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-interwave.
+
+config SND_INTERWAVE_STB
+ tristate "AMD InterWave + TEA6330T (UltraSound 32-Pro)"
+ depends on SND
+ select SND_RAWMIDI
+ select SND_CS4231_LIB
+ select SND_GUS_SYNTH
+ help
+ Say Y here to include support for AMD InterWave based
+ soundcards with a TEA6330T bass and treble regulator
+ (UltraSound 32-Pro).
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-interwave-stb.
+
+config SND_OPTI92X_AD1848
+ tristate "OPTi 82C92x - AD1848"
+ depends on SND
+ select SND_OPL3_LIB
+ select SND_OPL4_LIB
+ select SND_MPU401_UART
+ select SND_AD1848_LIB
+ help
+ Say Y here to include support for soundcards based on Opti
+ 82C92x or OTI-601 chips and using an AD1848 codec.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-opti92x-ad1848.
+
+config SND_OPTI92X_CS4231
+ tristate "OPTi 82C92x - CS4231"
+ depends on SND
+ select SND_OPL3_LIB
+ select SND_OPL4_LIB
+ select SND_MPU401_UART
+ select SND_CS4231_LIB
+ help
+ Say Y here to include support for soundcards based on Opti
+ 82C92x chips and using a CS4231 codec.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-opti92x-cs4231.
+
+config SND_OPTI93X
+ tristate "OPTi 82C93x"
+ depends on SND
+ select SND_OPL3_LIB
+ select SND_MPU401_UART
+ select SND_PCM
+ help
+ Say Y here to include support for soundcards based on Opti
+ 82C93x chips.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-opti93x.
+
+config SND_SB8
+ tristate "Sound Blaster 1.0/2.0/Pro (8-bit)"
+ depends on SND
+ select SND_OPL3_LIB
+ select SND_RAWMIDI
+ select SND_PCM
+ help
+ Say Y here to include support for Creative Sound Blaster 1.0/
+ 2.0/Pro (8-bit) or 100% compatible soundcards.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-sb8.
+
+config SND_SB16
+ tristate "Sound Blaster 16 (PnP)"
+ depends on SND
+ select SND_OPL3_LIB
+ select SND_MPU401_UART
+ select SND_PCM
+ help
+ Say Y here to include support for Sound Blaster 16 soundcards
+ (including the Plug and Play version).
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-sb16.
+
+config SND_SBAWE
+ tristate "Sound Blaster AWE (32,64) (PnP)"
+ depends on SND
+ select SND_OPL3_LIB
+ select SND_MPU401_UART
+ select SND_PCM
+ help
+ Say Y here to include support for Sound Blaster AWE soundcards
+ (including the Plug and Play version).
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-sbawe.
+
+config SND_SB16_CSP
+ bool "Sound Blaster 16/AWE CSP support"
+ depends on (SND_SB16 || SND_SBAWE) && (BROKEN || !PPC)
+ help
+ Say Y here to include support for the CSP core. This special
+ coprocessor can do variable tasks like various compression and
+ decompression algorithms.
+
+config SND_WAVEFRONT
+ tristate "Turtle Beach Maui,Tropez,Tropez+ (Wavefront)"
+ depends on SND
+ select SND_OPL3_LIB
+ select SND_MPU401_UART
+ select SND_CS4231_LIB
+ help
+ Say Y here to include support for Turtle Beach Maui, Tropez
+ and Tropez+ soundcards based on the Wavefront chip.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-wavefront.
+
+config SND_ALS100
+ tristate "Avance Logic ALS100/ALS120"
+ depends on SND && ISAPNP
+ select SND_OPL3_LIB
+ select SND_MPU401_UART
+ select SND_PCM
+ help
+ Say Y here to include support for soundcards based on Avance
+ Logic ALS100, ALS110, ALS120 and ALS200 chips.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-als100.
+
+config SND_AZT2320
+ tristate "Aztech Systems AZT2320"
+ depends on SND && ISAPNP
+ select SND_OPL3_LIB
+ select SND_MPU401_UART
+ select SND_CS4231_LIB
+ help
+ Say Y here to include support for soundcards based on the
+ Aztech Systems AZT2320 chip.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-azt2320.
+
+config SND_CMI8330
+ tristate "C-Media CMI8330"
+ depends on SND
+ select SND_AD1848_LIB
+ help
+ Say Y here to include support for soundcards based on the
+ C-Media CMI8330 chip.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-cmi8330.
+
+config SND_DT019X
+ tristate "Diamond Technologies DT-019X, Avance Logic ALS-007"
+ depends on SND && ISAPNP
+ select SND_OPL3_LIB
+ select SND_MPU401_UART
+ select SND_PCM
+ help
+ Say Y here to include support for soundcards based on the
+ Diamond Technologies DT-019X or Avance Logic ALS-007 chips.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-dt019x.
+
+config SND_OPL3SA2
+ tristate "Yamaha OPL3-SA2/SA3"
+ depends on SND
+ select SND_OPL3_LIB
+ select SND_MPU401_UART
+ select SND_CS4231_LIB
+ help
+ Say Y here to include support for Yamaha OPL3-SA2 and OPL3-SA3
+ chips.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-opl3sa2.
+
+config SND_SGALAXY
+ tristate "Aztech Sound Galaxy"
+ depends on SND
+ select SND_AD1848_LIB
+ help
+ Say Y here to include support for Aztech Sound Galaxy
+ soundcards.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-sgalaxy.
+
+config SND_SSCAPE
+ tristate "Ensoniq SoundScape PnP driver"
+ depends on SND
+ select SND_HWDEP
+ select SND_MPU401_UART
+ select SND_CS4231_LIB
+ help
+ Say Y here to include support for Ensoniq SoundScape PnP
+ soundcards.
+
+ To compile this driver as a module, choose M here: the module
+ will be called snd-sscape.
+
+endmenu
diff --git a/sound/isa/Makefile b/sound/isa/Makefile
new file mode 100644
index 000000000000..05724eb7bfe4
--- /dev/null
+++ b/sound/isa/Makefile
@@ -0,0 +1,26 @@
+#
+# Makefile for ALSA
+# Copyright (c) 2001 by Jaroslav Kysela <perex@suse.cz>
+#
+
+snd-als100-objs := als100.o
+snd-azt2320-objs := azt2320.o
+snd-cmi8330-objs := cmi8330.o
+snd-dt019x-objs := dt019x.o
+snd-es18xx-objs := es18xx.o
+snd-opl3sa2-objs := opl3sa2.o
+snd-sgalaxy-objs := sgalaxy.o
+snd-sscape-objs := sscape.o
+
+# Toplevel Module Dependency
+obj-$(CONFIG_SND_ALS100) += snd-als100.o
+obj-$(CONFIG_SND_AZT2320) += snd-azt2320.o
+obj-$(CONFIG_SND_CMI8330) += snd-cmi8330.o
+obj-$(CONFIG_SND_DT019X) += snd-dt019x.o
+obj-$(CONFIG_SND_ES18XX) += snd-es18xx.o
+obj-$(CONFIG_SND_OPL3SA2) += snd-opl3sa2.o
+obj-$(CONFIG_SND_SGALAXY) += snd-sgalaxy.o
+obj-$(CONFIG_SND_SSCAPE) += snd-sscape.o
+
+obj-$(CONFIG_SND) += ad1816a/ ad1848/ cs423x/ es1688/ gus/ opti9xx/ \
+ sb/ wavefront/
diff --git a/sound/isa/ad1816a/Makefile b/sound/isa/ad1816a/Makefile
new file mode 100644
index 000000000000..a42b29cf8549
--- /dev/null
+++ b/sound/isa/ad1816a/Makefile
@@ -0,0 +1,10 @@
+#
+# Makefile for ALSA
+# Copyright (c) 2001 by Jaroslav Kysela <perex@suse.cz>
+#
+
+snd-ad1816a-lib-objs := ad1816a_lib.o
+snd-ad1816a-objs := ad1816a.o
+
+# Toplevel Module Dependency
+obj-$(CONFIG_SND_AD1816A) += snd-ad1816a.o snd-ad1816a-lib.o
diff --git a/sound/isa/ad1816a/ad1816a.c b/sound/isa/ad1816a/ad1816a.c
new file mode 100644
index 000000000000..9fa7a78da6c3
--- /dev/null
+++ b/sound/isa/ad1816a/ad1816a.c
@@ -0,0 +1,312 @@
+
+/*
+ card-ad1816a.c - driver for ADI SoundPort AD1816A based soundcards.
+ Copyright (C) 2000 by Massimo Piccioni <dafastidio@libero.it>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include <sound/driver.h>
+#include <linux/init.h>
+#include <linux/time.h>
+#include <linux/wait.h>
+#include <linux/pnp.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/initval.h>
+#include <sound/ad1816a.h>
+#include <sound/mpu401.h>
+#include <sound/opl3.h>
+
+#define PFX "ad1816a: "
+
+MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
+MODULE_DESCRIPTION("AD1816A, AD1815");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{Highscreen,Sound-Boostar 16 3D},"
+ "{Analog Devices,AD1815},"
+ "{Analog Devices,AD1816A},"
+ "{TerraTec,Base 64},"
+ "{TerraTec,AudioSystem EWS64S},"
+ "{Aztech/Newcom SC-16 3D},"
+ "{Shark Predator ISA}}");
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 1-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
+static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
+static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
+static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
+static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for ad1816a based soundcard.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for ad1816a based soundcard.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable ad1816a based soundcard.");
+module_param_array(port, long, NULL, 0444);
+MODULE_PARM_DESC(port, "Port # for ad1816a driver.");
+module_param_array(mpu_port, long, NULL, 0444);
+MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ad1816a driver.");
+module_param_array(fm_port, long, NULL, 0444);
+MODULE_PARM_DESC(fm_port, "FM port # for ad1816a driver.");
+module_param_array(irq, int, NULL, 0444);
+MODULE_PARM_DESC(irq, "IRQ # for ad1816a driver.");
+module_param_array(mpu_irq, int, NULL, 0444);
+MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for ad1816a driver.");
+module_param_array(dma1, int, NULL, 0444);
+MODULE_PARM_DESC(dma1, "1st DMA # for ad1816a driver.");
+module_param_array(dma2, int, NULL, 0444);
+MODULE_PARM_DESC(dma2, "2nd DMA # for ad1816a driver.");
+
+struct snd_card_ad1816a {
+ struct pnp_dev *dev;
+ struct pnp_dev *devmpu;
+};
+
+static struct pnp_card_device_id snd_ad1816a_pnpids[] = {
+ /* Analog Devices AD1815 */
+ { .id = "ADS7150", .devs = { { .id = "ADS7150" }, { .id = "ADS7151" } } },
+ /* Analog Devices AD1816A - added by Kenneth Platz <kxp@atl.hp.com> */
+ { .id = "ADS7181", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
+ /* Analog Devices AD1816A - Aztech/Newcom SC-16 3D */
+ { .id = "AZT1022", .devs = { { .id = "AZT1018" }, { .id = "AZT2002" } } },
+ /* Highscreen Sound-Boostar 16 3D - added by Stefan Behnel */
+ { .id = "LWC1061", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
+ /* Highscreen Sound-Boostar 16 3D */
+ { .id = "MDK1605", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
+ /* Shark Predator ISA - added by Ken Arromdee */
+ { .id = "SMM7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
+ /* Analog Devices AD1816A - Terratec AudioSystem EWS64S */
+ { .id = "TER1112", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
+ /* Analog Devices AD1816A - Terratec Base 64 */
+ { .id = "TER1411", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
+ /* end */
+ { .id = "" }
+};
+
+MODULE_DEVICE_TABLE(pnp_card, snd_ad1816a_pnpids);
+
+
+#define DRIVER_NAME "snd-card-ad1816a"
+
+
+static int __devinit snd_card_ad1816a_pnp(int dev, struct snd_card_ad1816a *acard,
+ struct pnp_card_link *card,
+ const struct pnp_card_device_id *id)
+{
+ struct pnp_dev *pdev;
+ struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
+ int err;
+
+ acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
+ if (acard->dev == NULL) {
+ kfree(cfg);
+ return -EBUSY;
+ }
+ acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
+ if (acard->devmpu == NULL) {
+ kfree(cfg);
+ return -EBUSY;
+ }
+
+ pdev = acard->dev;
+ pnp_init_resource_table(cfg);
+
+ if (port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[2], port[dev], 16);
+ if (fm_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
+ if (dma1[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
+ if (dma2[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
+ if (irq[dev] != SNDRV_AUTO_IRQ)
+ pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
+
+ if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
+ snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ printk(KERN_ERR PFX "AUDIO PnP configure failure\n");
+ kfree(cfg);
+ return -EBUSY;
+ }
+
+ port[dev] = pnp_port_start(pdev, 2);
+ fm_port[dev] = pnp_port_start(pdev, 1);
+ dma1[dev] = pnp_dma(pdev, 0);
+ dma2[dev] = pnp_dma(pdev, 1);
+ irq[dev] = pnp_irq(pdev, 0);
+
+ pdev = acard->devmpu;
+ pnp_init_resource_table(cfg);
+
+ if (mpu_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
+ if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
+ pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
+
+ if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
+ snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ printk(KERN_ERR PFX "MPU401 PnP configure failure\n");
+ mpu_port[dev] = -1;
+ acard->devmpu = NULL;
+ } else {
+ mpu_port[dev] = pnp_port_start(pdev, 0);
+ mpu_irq[dev] = pnp_irq(pdev, 0);
+ }
+
+ kfree(cfg);
+ return 0;
+}
+
+static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard,
+ const struct pnp_card_device_id *pid)
+{
+ int error;
+ snd_card_t *card;
+ struct snd_card_ad1816a *acard;
+ ad1816a_t *chip;
+ opl3_t *opl3;
+
+ if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
+ sizeof(struct snd_card_ad1816a))) == NULL)
+ return -ENOMEM;
+ acard = (struct snd_card_ad1816a *)card->private_data;
+
+ if ((error = snd_card_ad1816a_pnp(dev, acard, pcard, pid))) {
+ snd_card_free(card);
+ return error;
+ }
+ snd_card_set_dev(card, &pcard->card->dev);
+
+ if ((error = snd_ad1816a_create(card, port[dev],
+ irq[dev],
+ dma1[dev],
+ dma2[dev],
+ &chip)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+
+ strcpy(card->driver, "AD1816A");
+ strcpy(card->shortname, "ADI SoundPort AD1816A");
+ sprintf(card->longname, "%s, SS at 0x%lx, irq %d, dma %d&%d",
+ card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
+
+ if ((error = snd_ad1816a_pcm(chip, 0, NULL)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+
+ if ((error = snd_ad1816a_mixer(chip)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+
+ if (mpu_port[dev] > 0) {
+ if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
+ mpu_port[dev], 0, mpu_irq[dev], SA_INTERRUPT,
+ NULL) < 0)
+ printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]);
+ }
+
+ if (fm_port[dev] > 0) {
+ if (snd_opl3_create(card,
+ fm_port[dev], fm_port[dev] + 2,
+ OPL3_HW_AUTO, 0, &opl3) < 0) {
+ printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx.\n", fm_port[dev], fm_port[dev] + 2);
+ } else {
+ if ((error = snd_opl3_timer_new(opl3, 1, 2)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ }
+ }
+
+ if ((error = snd_card_register(card)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ pnp_set_card_drvdata(pcard, card);
+ return 0;
+}
+
+static int __devinit snd_ad1816a_pnp_detect(struct pnp_card_link *card,
+ const struct pnp_card_device_id *id)
+{
+ static int dev;
+ int res;
+
+ for ( ; dev < SNDRV_CARDS; dev++) {
+ if (!enable[dev])
+ continue;
+ res = snd_card_ad1816a_probe(dev, card, id);
+ if (res < 0)
+ return res;
+ dev++;
+ return 0;
+ }
+ return -ENODEV;
+}
+
+static void __devexit snd_ad1816a_pnp_remove(struct pnp_card_link * pcard)
+{
+ snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
+
+ snd_card_disconnect(card);
+ snd_card_free_in_thread(card);
+}
+
+static struct pnp_card_driver ad1816a_pnpc_driver = {
+ .flags = PNP_DRIVER_RES_DISABLE,
+ .name = "ad1816a",
+ .id_table = snd_ad1816a_pnpids,
+ .probe = snd_ad1816a_pnp_detect,
+ .remove = __devexit_p(snd_ad1816a_pnp_remove),
+};
+
+static int __init alsa_card_ad1816a_init(void)
+{
+ int cards = 0;
+
+ cards += pnp_register_card_driver(&ad1816a_pnpc_driver);
+#ifdef MODULE
+ if (!cards) {
+ pnp_unregister_card_driver(&ad1816a_pnpc_driver);
+ printk(KERN_ERR "no AD1816A based soundcards found.\n");
+ }
+#endif /* MODULE */
+ return cards ? 0 : -ENODEV;
+}
+
+static void __exit alsa_card_ad1816a_exit(void)
+{
+ pnp_unregister_card_driver(&ad1816a_pnpc_driver);
+}
+
+module_init(alsa_card_ad1816a_init)
+module_exit(alsa_card_ad1816a_exit)
diff --git a/sound/isa/ad1816a/ad1816a_lib.c b/sound/isa/ad1816a/ad1816a_lib.c
new file mode 100644
index 000000000000..625b2eff14a1
--- /dev/null
+++ b/sound/isa/ad1816a/ad1816a_lib.c
@@ -0,0 +1,974 @@
+
+/*
+ ad1816a.c - lowlevel code for Analog Devices AD1816A chip.
+ Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include <sound/driver.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/slab.h>
+#include <linux/ioport.h>
+#include <sound/core.h>
+#include <sound/ad1816a.h>
+
+#include <asm/io.h>
+#include <asm/dma.h>
+
+MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
+MODULE_DESCRIPTION("lowlevel code for Analog Devices AD1816A chip");
+MODULE_LICENSE("GPL");
+
+static inline int snd_ad1816a_busy_wait(ad1816a_t *chip)
+{
+ int timeout;
+
+ for (timeout = 1000; timeout-- > 0; udelay(10))
+ if (inb(AD1816A_REG(AD1816A_CHIP_STATUS)) & AD1816A_READY)
+ return 0;
+
+ snd_printk("chip busy.\n");
+ return -EBUSY;
+}
+
+static inline unsigned char snd_ad1816a_in(ad1816a_t *chip, unsigned char reg)
+{
+ snd_ad1816a_busy_wait(chip);
+ return inb(AD1816A_REG(reg));
+}
+
+static inline void snd_ad1816a_out(ad1816a_t *chip, unsigned char reg,
+ unsigned char value)
+{
+ snd_ad1816a_busy_wait(chip);
+ outb(value, AD1816A_REG(reg));
+}
+
+static inline void snd_ad1816a_out_mask(ad1816a_t *chip, unsigned char reg,
+ unsigned char mask, unsigned char value)
+{
+ snd_ad1816a_out(chip, reg,
+ (value & mask) | (snd_ad1816a_in(chip, reg) & ~mask));
+}
+
+static unsigned short snd_ad1816a_read(ad1816a_t *chip, unsigned char reg)
+{
+ snd_ad1816a_out(chip, AD1816A_INDIR_ADDR, reg & 0x3f);
+ return snd_ad1816a_in(chip, AD1816A_INDIR_DATA_LOW) |
+ (snd_ad1816a_in(chip, AD1816A_INDIR_DATA_HIGH) << 8);
+}
+
+static void snd_ad1816a_write(ad1816a_t *chip, unsigned char reg,
+ unsigned short value)
+{
+ snd_ad1816a_out(chip, AD1816A_INDIR_ADDR, reg & 0x3f);
+ snd_ad1816a_out(chip, AD1816A_INDIR_DATA_LOW, value & 0xff);
+ snd_ad1816a_out(chip, AD1816A_INDIR_DATA_HIGH, (value >> 8) & 0xff);
+}
+
+static void snd_ad1816a_write_mask(ad1816a_t *chip, unsigned char reg,
+ unsigned short mask, unsigned short value)
+{
+ snd_ad1816a_write(chip, reg,
+ (value & mask) | (snd_ad1816a_read(chip, reg) & ~mask));
+}
+
+
+static unsigned char snd_ad1816a_get_format(ad1816a_t *chip,
+ unsigned int format, int channels)
+{
+ unsigned char retval = AD1816A_FMT_LINEAR_8;
+
+ switch (format) {
+ case SNDRV_PCM_FORMAT_MU_LAW:
+ retval = AD1816A_FMT_ULAW_8;
+ break;
+ case SNDRV_PCM_FORMAT_A_LAW:
+ retval = AD1816A_FMT_ALAW_8;
+ break;
+ case SNDRV_PCM_FORMAT_S16_LE:
+ retval = AD1816A_FMT_LINEAR_16_LIT;
+ break;
+ case SNDRV_PCM_FORMAT_S16_BE:
+ retval = AD1816A_FMT_LINEAR_16_BIG;
+ }
+ return (channels > 1) ? (retval | AD1816A_FMT_STEREO) : retval;
+}
+
+static int snd_ad1816a_open(ad1816a_t *chip, unsigned int mode)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&chip->lock, flags);
+
+ if (chip->mode & mode) {
+ spin_unlock_irqrestore(&chip->lock, flags);
+ return -EAGAIN;
+ }
+
+ switch ((mode &= AD1816A_MODE_OPEN)) {
+ case AD1816A_MODE_PLAYBACK:
+ snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
+ AD1816A_PLAYBACK_IRQ_PENDING, 0x00);
+ snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
+ AD1816A_PLAYBACK_IRQ_ENABLE, 0xffff);
+ break;
+ case AD1816A_MODE_CAPTURE:
+ snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
+ AD1816A_CAPTURE_IRQ_PENDING, 0x00);
+ snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
+ AD1816A_CAPTURE_IRQ_ENABLE, 0xffff);
+ break;
+ case AD1816A_MODE_TIMER:
+ snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
+ AD1816A_TIMER_IRQ_PENDING, 0x00);
+ snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
+ AD1816A_TIMER_IRQ_ENABLE, 0xffff);
+ }
+ chip->mode |= mode;
+
+ spin_unlock_irqrestore(&chip->lock, flags);
+ return 0;
+}
+
+static void snd_ad1816a_close(ad1816a_t *chip, unsigned int mode)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&chip->lock, flags);
+
+ switch ((mode &= AD1816A_MODE_OPEN)) {
+ case AD1816A_MODE_PLAYBACK:
+ snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
+ AD1816A_PLAYBACK_IRQ_PENDING, 0x00);
+ snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
+ AD1816A_PLAYBACK_IRQ_ENABLE, 0x0000);
+ break;
+ case AD1816A_MODE_CAPTURE:
+ snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
+ AD1816A_CAPTURE_IRQ_PENDING, 0x00);
+ snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
+ AD1816A_CAPTURE_IRQ_ENABLE, 0x0000);
+ break;
+ case AD1816A_MODE_TIMER:
+ snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
+ AD1816A_TIMER_IRQ_PENDING, 0x00);
+ snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
+ AD1816A_TIMER_IRQ_ENABLE, 0x0000);
+ }
+ if (!((chip->mode &= ~mode) & AD1816A_MODE_OPEN))
+ chip->mode = 0;
+
+ spin_unlock_irqrestore(&chip->lock, flags);
+}
+
+
+static int snd_ad1816a_trigger(ad1816a_t *chip, unsigned char what,
+ int channel, int cmd)
+{
+ int error = 0;
+
+ switch (cmd) {
+ case SNDRV_PCM_TRIGGER_START:
+ case SNDRV_PCM_TRIGGER_STOP:
+ spin_lock(&chip->lock);
+ cmd = (cmd == SNDRV_PCM_TRIGGER_START) ? 0xff: 0x00;
+ if (what & AD1816A_PLAYBACK_ENABLE)
+ snd_ad1816a_out_mask(chip, AD1816A_PLAYBACK_CONFIG,
+ AD1816A_PLAYBACK_ENABLE, cmd);
+ if (what & AD1816A_CAPTURE_ENABLE)
+ snd_ad1816a_out_mask(chip, AD1816A_CAPTURE_CONFIG,
+ AD1816A_CAPTURE_ENABLE, cmd);
+ spin_unlock(&chip->lock);
+ break;
+ default:
+ snd_printk("invalid trigger mode 0x%x.\n", what);
+ error = -EINVAL;
+ }
+
+ return error;
+}
+
+static int snd_ad1816a_playback_trigger(snd_pcm_substream_t *substream, int cmd)
+{
+ ad1816a_t *chip = snd_pcm_substream_chip(substream);
+ return snd_ad1816a_trigger(chip, AD1816A_PLAYBACK_ENABLE,
+ SNDRV_PCM_STREAM_PLAYBACK, cmd);
+}
+
+static int snd_ad1816a_capture_trigger(snd_pcm_substream_t *substream, int cmd)
+{
+ ad1816a_t *chip = snd_pcm_substream_chip(substream);
+ return snd_ad1816a_trigger(chip, AD1816A_CAPTURE_ENABLE,
+ SNDRV_PCM_STREAM_CAPTURE, cmd);
+}
+
+static int snd_ad1816a_hw_params(snd_pcm_substream_t * substream,
+ snd_pcm_hw_params_t * hw_params)
+{
+ return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
+}
+
+static int snd_ad1816a_hw_free(snd_pcm_substream_t * substream)
+{
+ return snd_pcm_lib_free_pages(substream);
+}
+
+static int snd_ad1816a_playback_prepare(snd_pcm_substream_t *substream)
+{
+ ad1816a_t *chip = snd_pcm_substream_chip(substream);
+ unsigned long flags;
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ unsigned int size;
+
+ spin_lock_irqsave(&chip->lock, flags);
+
+ chip->p_dma_size = size = snd_pcm_lib_buffer_bytes(substream);
+ snd_ad1816a_out_mask(chip, AD1816A_PLAYBACK_CONFIG,
+ AD1816A_PLAYBACK_ENABLE | AD1816A_PLAYBACK_PIO, 0x00);
+
+ snd_dma_program(chip->dma1, runtime->dma_addr, size,
+ DMA_MODE_WRITE | DMA_AUTOINIT);
+
+ snd_ad1816a_write(chip, AD1816A_PLAYBACK_SAMPLE_RATE, runtime->rate);
+ snd_ad1816a_out_mask(chip, AD1816A_PLAYBACK_CONFIG,
+ AD1816A_FMT_ALL | AD1816A_FMT_STEREO,
+ snd_ad1816a_get_format(chip, runtime->format,
+ runtime->channels));
+
+ snd_ad1816a_write(chip, AD1816A_PLAYBACK_BASE_COUNT,
+ snd_pcm_lib_period_bytes(substream) / 4 - 1);
+
+ spin_unlock_irqrestore(&chip->lock, flags);
+ return 0;
+}
+
+static int snd_ad1816a_capture_prepare(snd_pcm_substream_t *substream)
+{
+ ad1816a_t *chip = snd_pcm_substream_chip(substream);
+ unsigned long flags;
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ unsigned int size;
+
+ spin_lock_irqsave(&chip->lock, flags);
+
+ chip->c_dma_size = size = snd_pcm_lib_buffer_bytes(substream);
+ snd_ad1816a_out_mask(chip, AD1816A_CAPTURE_CONFIG,
+ AD1816A_CAPTURE_ENABLE | AD1816A_CAPTURE_PIO, 0x00);
+
+ snd_dma_program(chip->dma2, runtime->dma_addr, size,
+ DMA_MODE_READ | DMA_AUTOINIT);
+
+ snd_ad1816a_write(chip, AD1816A_CAPTURE_SAMPLE_RATE, runtime->rate);
+ snd_ad1816a_out_mask(chip, AD1816A_CAPTURE_CONFIG,
+ AD1816A_FMT_ALL | AD1816A_FMT_STEREO,
+ snd_ad1816a_get_format(chip, runtime->format,
+ runtime->channels));
+
+ snd_ad1816a_write(chip, AD1816A_CAPTURE_BASE_COUNT,
+ snd_pcm_lib_period_bytes(substream) / 4 - 1);
+
+ spin_unlock_irqrestore(&chip->lock, flags);
+ return 0;
+}
+
+
+static snd_pcm_uframes_t snd_ad1816a_playback_pointer(snd_pcm_substream_t *substream)
+{
+ ad1816a_t *chip = snd_pcm_substream_chip(substream);
+ size_t ptr;
+ if (!(chip->mode & AD1816A_MODE_PLAYBACK))
+ return 0;
+ ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size);
+ return bytes_to_frames(substream->runtime, ptr);
+}
+
+static snd_pcm_uframes_t snd_ad1816a_capture_pointer(snd_pcm_substream_t *substream)
+{
+ ad1816a_t *chip = snd_pcm_substream_chip(substream);
+ size_t ptr;
+ if (!(chip->mode & AD1816A_MODE_CAPTURE))
+ return 0;
+ ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
+ return bytes_to_frames(substream->runtime, ptr);
+}
+
+
+static irqreturn_t snd_ad1816a_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ ad1816a_t *chip = dev_id;
+ unsigned char status;
+
+ spin_lock(&chip->lock);
+ status = snd_ad1816a_in(chip, AD1816A_INTERRUPT_STATUS);
+ spin_unlock(&chip->lock);
+
+ if ((status & AD1816A_PLAYBACK_IRQ_PENDING) && chip->playback_substream)
+ snd_pcm_period_elapsed(chip->playback_substream);
+
+ if ((status & AD1816A_CAPTURE_IRQ_PENDING) && chip->capture_substream)
+ snd_pcm_period_elapsed(chip->capture_substream);
+
+ if ((status & AD1816A_TIMER_IRQ_PENDING) && chip->timer)
+ snd_timer_interrupt(chip->timer, chip->timer->sticks);
+
+ spin_lock(&chip->lock);
+ snd_ad1816a_out(chip, AD1816A_INTERRUPT_STATUS, 0x00);
+ spin_unlock(&chip->lock);
+ return IRQ_HANDLED;
+}
+
+
+static snd_pcm_hardware_t snd_ad1816a_playback = {
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_MMAP_VALID),
+ .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
+ SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
+ SNDRV_PCM_FMTBIT_S16_BE),
+ .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
+ .rate_min = 4000,
+ .rate_max = 55200,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = (128*1024),
+ .period_bytes_min = 64,
+ .period_bytes_max = (128*1024),
+ .periods_min = 1,
+ .periods_max = 1024,
+ .fifo_size = 0,
+};
+
+static snd_pcm_hardware_t snd_ad1816a_capture = {
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_MMAP_VALID),
+ .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
+ SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
+ SNDRV_PCM_FMTBIT_S16_BE),
+ .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
+ .rate_min = 4000,
+ .rate_max = 55200,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = (128*1024),
+ .period_bytes_min = 64,
+ .period_bytes_max = (128*1024),
+ .periods_min = 1,
+ .periods_max = 1024,
+ .fifo_size = 0,
+};
+
+#if 0 /* not used now */
+static int snd_ad1816a_timer_close(snd_timer_t *timer)
+{
+ ad1816a_t *chip = snd_timer_chip(timer);
+ snd_ad1816a_close(chip, AD1816A_MODE_TIMER);
+ return 0;
+}
+
+static int snd_ad1816a_timer_open(snd_timer_t *timer)
+{
+ ad1816a_t *chip = snd_timer_chip(timer);
+ snd_ad1816a_open(chip, AD1816A_MODE_TIMER);
+ return 0;
+}
+
+static unsigned long snd_ad1816a_timer_resolution(snd_timer_t *timer)
+{
+ snd_assert(timer != NULL, return 0);
+
+ return 10000;
+}
+
+static int snd_ad1816a_timer_start(snd_timer_t *timer)
+{
+ unsigned short bits;
+ unsigned long flags;
+ ad1816a_t *chip = snd_timer_chip(timer);
+ spin_lock_irqsave(&chip->lock, flags);
+ bits = snd_ad1816a_read(chip, AD1816A_INTERRUPT_ENABLE);
+
+ if (!(bits & AD1816A_TIMER_ENABLE)) {
+ snd_ad1816a_write(chip, AD1816A_TIMER_BASE_COUNT,
+ timer->sticks & 0xffff);
+
+ snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
+ AD1816A_TIMER_ENABLE, 0xffff);
+ }
+ spin_unlock_irqrestore(&chip->lock, flags);
+ return 0;
+}
+
+static int snd_ad1816a_timer_stop(snd_timer_t *timer)
+{
+ unsigned long flags;
+ ad1816a_t *chip = snd_timer_chip(timer);
+ spin_lock_irqsave(&chip->lock, flags);
+
+ snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
+ AD1816A_TIMER_ENABLE, 0x0000);
+
+ spin_unlock_irqrestore(&chip->lock, flags);
+ return 0;
+}
+
+static struct _snd_timer_hardware snd_ad1816a_timer_table = {
+ .flags = SNDRV_TIMER_HW_AUTO,
+ .resolution = 10000,
+ .ticks = 65535,
+ .open = snd_ad1816a_timer_open,
+ .close = snd_ad1816a_timer_close,
+ .c_resolution = snd_ad1816a_timer_resolution,
+ .start = snd_ad1816a_timer_start,
+ .stop = snd_ad1816a_timer_stop,
+};
+#endif /* not used now */
+
+
+static int snd_ad1816a_playback_open(snd_pcm_substream_t *substream)
+{
+ ad1816a_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ int error;
+
+ if ((error = snd_ad1816a_open(chip, AD1816A_MODE_PLAYBACK)) < 0)
+ return error;
+ snd_pcm_set_sync(substream);
+ runtime->hw = snd_ad1816a_playback;
+ snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
+ snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.period_bytes_max);
+ chip->playback_substream = substream;
+ return 0;
+}
+
+static int snd_ad1816a_capture_open(snd_pcm_substream_t *substream)
+{
+ ad1816a_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ int error;
+
+ if ((error = snd_ad1816a_open(chip, AD1816A_MODE_CAPTURE)) < 0)
+ return error;
+ snd_pcm_set_sync(substream);
+ runtime->hw = snd_ad1816a_capture;
+ snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
+ snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.period_bytes_max);
+ chip->capture_substream = substream;
+ return 0;
+}
+
+static int snd_ad1816a_playback_close(snd_pcm_substream_t *substream)
+{
+ ad1816a_t *chip = snd_pcm_substream_chip(substream);
+
+ chip->playback_substream = NULL;
+ snd_ad1816a_close(chip, AD1816A_MODE_PLAYBACK);
+ return 0;
+}
+
+static int snd_ad1816a_capture_close(snd_pcm_substream_t *substream)
+{
+ ad1816a_t *chip = snd_pcm_substream_chip(substream);
+
+ chip->capture_substream = NULL;
+ snd_ad1816a_close(chip, AD1816A_MODE_CAPTURE);
+ return 0;
+}
+
+
+static void snd_ad1816a_init(ad1816a_t *chip)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&chip->lock, flags);
+
+ snd_ad1816a_out(chip, AD1816A_INTERRUPT_STATUS, 0x00);
+ snd_ad1816a_out_mask(chip, AD1816A_PLAYBACK_CONFIG,
+ AD1816A_PLAYBACK_ENABLE | AD1816A_PLAYBACK_PIO, 0x00);
+ snd_ad1816a_out_mask(chip, AD1816A_CAPTURE_CONFIG,
+ AD1816A_CAPTURE_ENABLE | AD1816A_CAPTURE_PIO, 0x00);
+ snd_ad1816a_write(chip, AD1816A_INTERRUPT_ENABLE, 0x0000);
+ snd_ad1816a_write_mask(chip, AD1816A_CHIP_CONFIG,
+ AD1816A_CAPTURE_NOT_EQUAL | AD1816A_WSS_ENABLE, 0xffff);
+ snd_ad1816a_write(chip, AD1816A_DSP_CONFIG, 0x0000);
+ snd_ad1816a_write(chip, AD1816A_POWERDOWN_CTRL, 0x0000);
+
+ spin_unlock_irqrestore(&chip->lock, flags);
+}
+
+static int snd_ad1816a_probe(ad1816a_t *chip)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&chip->lock, flags);
+
+ switch (chip->version = snd_ad1816a_read(chip, AD1816A_VERSION_ID)) {
+ case 0:
+ chip->hardware = AD1816A_HW_AD1815;
+ break;
+ case 1:
+ chip->hardware = AD1816A_HW_AD18MAX10;
+ break;
+ case 3:
+ chip->hardware = AD1816A_HW_AD1816A;
+ break;
+ default:
+ chip->hardware = AD1816A_HW_AUTO;
+ }
+
+ spin_unlock_irqrestore(&chip->lock, flags);
+ return 0;
+}
+
+static int snd_ad1816a_free(ad1816a_t *chip)
+{
+ if (chip->res_port) {
+ release_resource(chip->res_port);
+ kfree_nocheck(chip->res_port);
+ }
+ if (chip->irq >= 0)
+ free_irq(chip->irq, (void *) chip);
+ if (chip->dma1 >= 0) {
+ snd_dma_disable(chip->dma1);
+ free_dma(chip->dma1);
+ }
+ if (chip->dma2 >= 0) {
+ snd_dma_disable(chip->dma2);
+ free_dma(chip->dma2);
+ }
+ kfree(chip);
+ return 0;
+}
+
+static int snd_ad1816a_dev_free(snd_device_t *device)
+{
+ ad1816a_t *chip = device->device_data;
+ return snd_ad1816a_free(chip);
+}
+
+static const char *snd_ad1816a_chip_id(ad1816a_t *chip)
+{
+ switch (chip->hardware) {
+ case AD1816A_HW_AD1816A: return "AD1816A";
+ case AD1816A_HW_AD1815: return "AD1815";
+ case AD1816A_HW_AD18MAX10: return "AD18max10";
+ default:
+ snd_printk("Unknown chip version %d:%d.\n",
+ chip->version, chip->hardware);
+ return "AD1816A - unknown";
+ }
+}
+
+int snd_ad1816a_create(snd_card_t *card,
+ unsigned long port, int irq, int dma1, int dma2,
+ ad1816a_t **rchip)
+{
+ static snd_device_ops_t ops = {
+ .dev_free = snd_ad1816a_dev_free,
+ };
+ int error;
+ ad1816a_t *chip;
+
+ *rchip = NULL;
+
+ chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
+ if (chip == NULL)
+ return -ENOMEM;
+ chip->irq = -1;
+ chip->dma1 = -1;
+ chip->dma2 = -1;
+
+ if ((chip->res_port = request_region(port, 16, "AD1816A")) == NULL) {
+ snd_printk(KERN_ERR "ad1816a: can't grab port 0x%lx\n", port);
+ snd_ad1816a_free(chip);
+ return -EBUSY;
+ }
+ if (request_irq(irq, snd_ad1816a_interrupt, SA_INTERRUPT, "AD1816A", (void *) chip)) {
+ snd_printk(KERN_ERR "ad1816a: can't grab IRQ %d\n", irq);
+ snd_ad1816a_free(chip);
+ return -EBUSY;
+ }
+ chip->irq = irq;
+ if (request_dma(dma1, "AD1816A - 1")) {
+ snd_printk(KERN_ERR "ad1816a: can't grab DMA1 %d\n", dma1);
+ snd_ad1816a_free(chip);
+ return -EBUSY;
+ }
+ chip->dma1 = dma1;
+ if (request_dma(dma2, "AD1816A - 2")) {
+ snd_printk(KERN_ERR "ad1816a: can't grab DMA2 %d\n", dma2);
+ snd_ad1816a_free(chip);
+ return -EBUSY;
+ }
+ chip->dma2 = dma2;
+
+ chip->card = card;
+ chip->port = port;
+ spin_lock_init(&chip->lock);
+
+ if ((error = snd_ad1816a_probe(chip))) {
+ snd_ad1816a_free(chip);
+ return error;
+ }
+
+ snd_ad1816a_init(chip);
+
+ /* Register device */
+ if ((error = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
+ snd_ad1816a_free(chip);
+ return error;
+ }
+
+ *rchip = chip;
+ return 0;
+}
+
+static snd_pcm_ops_t snd_ad1816a_playback_ops = {
+ .open = snd_ad1816a_playback_open,
+ .close = snd_ad1816a_playback_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_ad1816a_hw_params,
+ .hw_free = snd_ad1816a_hw_free,
+ .prepare = snd_ad1816a_playback_prepare,
+ .trigger = snd_ad1816a_playback_trigger,
+ .pointer = snd_ad1816a_playback_pointer,
+};
+
+static snd_pcm_ops_t snd_ad1816a_capture_ops = {
+ .open = snd_ad1816a_capture_open,
+ .close = snd_ad1816a_capture_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_ad1816a_hw_params,
+ .hw_free = snd_ad1816a_hw_free,
+ .prepare = snd_ad1816a_capture_prepare,
+ .trigger = snd_ad1816a_capture_trigger,
+ .pointer = snd_ad1816a_capture_pointer,
+};
+
+static void snd_ad1816a_pcm_free(snd_pcm_t *pcm)
+{
+ ad1816a_t *chip = pcm->private_data;
+ chip->pcm = NULL;
+ snd_pcm_lib_preallocate_free_for_all(pcm);
+}
+
+int snd_ad1816a_pcm(ad1816a_t *chip, int device, snd_pcm_t **rpcm)
+{
+ int error;
+ snd_pcm_t *pcm;
+
+ if ((error = snd_pcm_new(chip->card, "AD1816A", device, 1, 1, &pcm)))
+ return error;
+
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ad1816a_playback_ops);
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ad1816a_capture_ops);
+
+ pcm->private_data = chip;
+ pcm->private_free = snd_ad1816a_pcm_free;
+ pcm->info_flags = (chip->dma1 == chip->dma2 ) ? SNDRV_PCM_INFO_JOINT_DUPLEX : 0;
+
+ strcpy(pcm->name, snd_ad1816a_chip_id(chip));
+ snd_ad1816a_init(chip);
+
+ snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
+ snd_dma_isa_data(),
+ 64*1024, chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
+
+ chip->pcm = pcm;
+ if (rpcm)
+ *rpcm = pcm;
+ return 0;
+}
+
+#if 0 /* not used now */
+static void snd_ad1816a_timer_free(snd_timer_t *timer)
+{
+ ad1816a_t *chip = timer->private_data;
+ chip->timer = NULL;
+}
+
+int snd_ad1816a_timer(ad1816a_t *chip, int device, snd_timer_t **rtimer)
+{
+ snd_timer_t *timer;
+ snd_timer_id_t tid;
+ int error;
+
+ tid.dev_class = SNDRV_TIMER_CLASS_CARD;
+ tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
+ tid.card = chip->card->number;
+ tid.device = device;
+ tid.subdevice = 0;
+ if ((error = snd_timer_new(chip->card, "AD1816A", &tid, &timer)) < 0)
+ return error;
+ strcpy(timer->name, snd_ad1816a_chip_id(chip));
+ timer->private_data = chip;
+ timer->private_free = snd_ad1816a_timer_free;
+ chip->timer = timer;
+ timer->hw = snd_ad1816a_timer_table;
+ if (rtimer)
+ *rtimer = timer;
+ return 0;
+}
+#endif /* not used now */
+
+/*
+ *
+ */
+
+static int snd_ad1816a_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ static char *texts[8] = {
+ "Line", "Mix", "CD", "Synth", "Video",
+ "Mic", "Phone",
+ };
+
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+ uinfo->count = 2;
+ uinfo->value.enumerated.items = 7;
+ if (uinfo->value.enumerated.item > 6)
+ uinfo->value.enumerated.item = 6;
+ strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+ return 0;
+}
+
+static int snd_ad1816a_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ ad1816a_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ unsigned short val;
+
+ spin_lock_irqsave(&chip->lock, flags);
+ val = snd_ad1816a_read(chip, AD1816A_ADC_SOURCE_SEL);
+ spin_unlock_irqrestore(&chip->lock, flags);
+ ucontrol->value.enumerated.item[0] = (val >> 12) & 7;
+ ucontrol->value.enumerated.item[1] = (val >> 4) & 7;
+ return 0;
+}
+
+static int snd_ad1816a_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ ad1816a_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ unsigned short val;
+ int change;
+
+ if (ucontrol->value.enumerated.item[0] > 6 ||
+ ucontrol->value.enumerated.item[1] > 6)
+ return -EINVAL;
+ val = (ucontrol->value.enumerated.item[0] << 12) |
+ (ucontrol->value.enumerated.item[1] << 4);
+ spin_lock_irqsave(&chip->lock, flags);
+ change = snd_ad1816a_read(chip, AD1816A_ADC_SOURCE_SEL) != val;
+ snd_ad1816a_write(chip, AD1816A_ADC_SOURCE_SEL, val);
+ spin_unlock_irqrestore(&chip->lock, flags);
+ return change;
+}
+
+#define AD1816A_SINGLE(xname, reg, shift, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ad1816a_info_single, \
+ .get = snd_ad1816a_get_single, .put = snd_ad1816a_put_single, \
+ .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
+
+static int snd_ad1816a_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+
+ uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = mask;
+ return 0;
+}
+
+static int snd_ad1816a_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ ad1816a_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+
+ spin_lock_irqsave(&chip->lock, flags);
+ ucontrol->value.integer.value[0] = (snd_ad1816a_read(chip, reg) >> shift) & mask;
+ spin_unlock_irqrestore(&chip->lock, flags);
+ if (invert)
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ return 0;
+}
+
+static int snd_ad1816a_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ ad1816a_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+ int change;
+ unsigned short old_val, val;
+
+ val = (ucontrol->value.integer.value[0] & mask);
+ if (invert)
+ val = mask - val;
+ val <<= shift;
+ spin_lock_irqsave(&chip->lock, flags);
+ old_val = snd_ad1816a_read(chip, reg);
+ val = (old_val & ~(mask << shift)) | val;
+ change = val != old_val;
+ snd_ad1816a_write(chip, reg, val);
+ spin_unlock_irqrestore(&chip->lock, flags);
+ return change;
+}
+
+#define AD1816A_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ad1816a_info_double, \
+ .get = snd_ad1816a_get_double, .put = snd_ad1816a_put_double, \
+ .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) }
+
+static int snd_ad1816a_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+
+ uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 2;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = mask;
+ return 0;
+}
+
+static int snd_ad1816a_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ ad1816a_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift_left = (kcontrol->private_value >> 8) & 0x0f;
+ int shift_right = (kcontrol->private_value >> 12) & 0x0f;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+ unsigned short val;
+
+ spin_lock_irqsave(&chip->lock, flags);
+ val = snd_ad1816a_read(chip, reg);
+ ucontrol->value.integer.value[0] = (val >> shift_left) & mask;
+ ucontrol->value.integer.value[1] = (val >> shift_right) & mask;
+ spin_unlock_irqrestore(&chip->lock, flags);
+ if (invert) {
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
+ }
+ return 0;
+}
+
+static int snd_ad1816a_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ ad1816a_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift_left = (kcontrol->private_value >> 8) & 0x0f;
+ int shift_right = (kcontrol->private_value >> 12) & 0x0f;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+ int change;
+ unsigned short old_val, val1, val2;
+
+ val1 = ucontrol->value.integer.value[0] & mask;
+ val2 = ucontrol->value.integer.value[1] & mask;
+ if (invert) {
+ val1 = mask - val1;
+ val2 = mask - val2;
+ }
+ val1 <<= shift_left;
+ val2 <<= shift_right;
+ spin_lock_irqsave(&chip->lock, flags);
+ old_val = snd_ad1816a_read(chip, reg);
+ val1 = (old_val & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
+ change = val1 != old_val;
+ snd_ad1816a_write(chip, reg, val1);
+ spin_unlock_irqrestore(&chip->lock, flags);
+ return change;
+}
+
+static snd_kcontrol_new_t snd_ad1816a_controls[] = {
+AD1816A_DOUBLE("Master Playback Switch", AD1816A_MASTER_ATT, 15, 7, 1, 1),
+AD1816A_DOUBLE("Master Playback Volume", AD1816A_MASTER_ATT, 8, 0, 31, 1),
+AD1816A_DOUBLE("PCM Playback Switch", AD1816A_VOICE_ATT, 15, 7, 1, 1),
+AD1816A_DOUBLE("PCM Playback Volume", AD1816A_VOICE_ATT, 8, 0, 63, 1),
+AD1816A_DOUBLE("Line Playback Switch", AD1816A_LINE_GAIN_ATT, 15, 7, 1, 1),
+AD1816A_DOUBLE("Line Playback Volume", AD1816A_LINE_GAIN_ATT, 8, 0, 31, 1),
+AD1816A_DOUBLE("CD Playback Switch", AD1816A_CD_GAIN_ATT, 15, 7, 1, 1),
+AD1816A_DOUBLE("CD Playback Volume", AD1816A_CD_GAIN_ATT, 8, 0, 31, 1),
+AD1816A_DOUBLE("Synth Playback Switch", AD1816A_SYNTH_GAIN_ATT, 15, 7, 1, 1),
+AD1816A_DOUBLE("Synth Playback Volume", AD1816A_SYNTH_GAIN_ATT, 8, 0, 31, 1),
+AD1816A_DOUBLE("FM Playback Switch", AD1816A_FM_ATT, 15, 7, 1, 1),
+AD1816A_DOUBLE("FM Playback Volume", AD1816A_FM_ATT, 8, 0, 63, 1),
+AD1816A_SINGLE("Mic Playback Switch", AD1816A_MIC_GAIN_ATT, 15, 1, 1),
+AD1816A_SINGLE("Mic Playback Volume", AD1816A_MIC_GAIN_ATT, 8, 31, 1),
+AD1816A_SINGLE("Mic Boost", AD1816A_MIC_GAIN_ATT, 14, 1, 0),
+AD1816A_DOUBLE("Video Playback Switch", AD1816A_VID_GAIN_ATT, 15, 7, 1, 1),
+AD1816A_DOUBLE("Video Playback Volume", AD1816A_VID_GAIN_ATT, 8, 0, 31, 1),
+AD1816A_SINGLE("Phone Capture Switch", AD1816A_PHONE_IN_GAIN_ATT, 15, 1, 1),
+AD1816A_SINGLE("Phone Capture Volume", AD1816A_PHONE_IN_GAIN_ATT, 0, 15, 1),
+AD1816A_SINGLE("Phone Playback Switch", AD1816A_PHONE_OUT_ATT, 7, 1, 1),
+AD1816A_SINGLE("Phone Playback Volume", AD1816A_PHONE_OUT_ATT, 0, 31, 1),
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "Capture Source",
+ .info = snd_ad1816a_info_mux,
+ .get = snd_ad1816a_get_mux,
+ .put = snd_ad1816a_put_mux,
+},
+AD1816A_DOUBLE("Capture Switch", AD1816A_ADC_PGA, 15, 7, 1, 1),
+AD1816A_DOUBLE("Capture Volume", AD1816A_ADC_PGA, 8, 0, 15, 0),
+AD1816A_SINGLE("3D Control - Switch", AD1816A_3D_PHAT_CTRL, 15, 1, 1),
+AD1816A_SINGLE("3D Control - Level", AD1816A_3D_PHAT_CTRL, 0, 15, 0),
+};
+
+int snd_ad1816a_mixer(ad1816a_t *chip)
+{
+ snd_card_t *card;
+ unsigned int idx;
+ int err;
+
+ snd_assert(chip != NULL && chip->card != NULL, return -EINVAL);
+
+ card = chip->card;
+
+ strcpy(card->mixername, snd_ad1816a_chip_id(chip));
+
+ for (idx = 0; idx < ARRAY_SIZE(snd_ad1816a_controls); idx++) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ad1816a_controls[idx], chip))) < 0)
+ return err;
+ }
+ return 0;
+}
+
+EXPORT_SYMBOL(snd_ad1816a_create);
+EXPORT_SYMBOL(snd_ad1816a_pcm);
+EXPORT_SYMBOL(snd_ad1816a_mixer);
+
+static int __init alsa_ad1816a_init(void)
+{
+ return 0;
+}
+
+static void __exit alsa_ad1816a_exit(void)
+{
+}
+
+module_init(alsa_ad1816a_init)
+module_exit(alsa_ad1816a_exit)
diff --git a/sound/isa/ad1848/Makefile b/sound/isa/ad1848/Makefile
new file mode 100644
index 000000000000..45d59998aa69
--- /dev/null
+++ b/sound/isa/ad1848/Makefile
@@ -0,0 +1,15 @@
+#
+# Makefile for ALSA
+# Copyright (c) 2001 by Jaroslav Kysela <perex@suse.cz>
+#
+
+snd-ad1848-lib-objs := ad1848_lib.o
+snd-ad1848-objs := ad1848.o
+
+# Toplevel Module Dependency
+obj-$(CONFIG_SND_CMI8330) += snd-ad1848-lib.o
+obj-$(CONFIG_SND_SGALAXY) += snd-ad1848-lib.o
+obj-$(CONFIG_SND_AD1848) += snd-ad1848.o snd-ad1848-lib.o
+obj-$(CONFIG_SND_OPTI92X_AD1848) += snd-ad1848-lib.o
+
+obj-m := $(sort $(obj-m))
diff --git a/sound/isa/ad1848/ad1848.c b/sound/isa/ad1848/ad1848.c
new file mode 100644
index 000000000000..8c399340cd72
--- /dev/null
+++ b/sound/isa/ad1848/ad1848.c
@@ -0,0 +1,151 @@
+/*
+ * Generic driver for AD1848/AD1847/CS4248 chips (0.1 Alpha)
+ * Copyright (c) by Tugrul Galatali <galatalt@stuy.edu>,
+ * Jaroslav Kysela <perex@suse.cz>
+ * Based on card-4232.c by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/init.h>
+#include <linux/time.h>
+#include <linux/wait.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/ad1848.h>
+#include <sound/initval.h>
+
+MODULE_AUTHOR("Tugrul Galatali <galatalt@stuy.edu>, Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("AD1848/AD1847/CS4248");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{Analog Devices,AD1848},"
+ "{Analog Devices,AD1847},"
+ "{Crystal Semiconductors,CS4248}}");
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
+static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
+static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
+static int thinkpad[SNDRV_CARDS]; /* Thinkpad special case */
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for AD1848 soundcard.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for AD1848 soundcard.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable AD1848 soundcard.");
+module_param_array(port, long, NULL, 0444);
+MODULE_PARM_DESC(port, "Port # for AD1848 driver.");
+module_param_array(irq, int, NULL, 0444);
+MODULE_PARM_DESC(irq, "IRQ # for AD1848 driver.");
+module_param_array(dma1, int, NULL, 0444);
+MODULE_PARM_DESC(dma1, "DMA1 # for AD1848 driver.");
+module_param_array(thinkpad, bool, NULL, 0444);
+MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series.");
+
+static snd_card_t *snd_ad1848_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
+
+
+static int __init snd_card_ad1848_probe(int dev)
+{
+ snd_card_t *card;
+ ad1848_t *chip;
+ snd_pcm_t *pcm;
+ int err;
+
+ if (port[dev] == SNDRV_AUTO_PORT) {
+ snd_printk(KERN_ERR "ad1848: specify port\n");
+ return -EINVAL;
+ }
+ if (irq[dev] == SNDRV_AUTO_IRQ) {
+ snd_printk(KERN_ERR "ad1848: specify irq\n");
+ return -EINVAL;
+ }
+ if (dma1[dev] == SNDRV_AUTO_DMA) {
+ snd_printk(KERN_ERR "ad1848: specify dma1\n");
+ return -EINVAL;
+ }
+
+ card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
+ if (card == NULL)
+ return -ENOMEM;
+
+ if ((err = snd_ad1848_create(card, port[dev],
+ irq[dev],
+ dma1[dev],
+ thinkpad[dev] ? AD1848_HW_THINKPAD : AD1848_HW_DETECT,
+ &chip)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+
+ if ((err = snd_ad1848_pcm(chip, 0, &pcm)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if ((err = snd_ad1848_mixer(chip)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ strcpy(card->driver, "AD1848");
+ strcpy(card->shortname, pcm->name);
+
+ sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
+ pcm->name, chip->port, irq[dev], dma1[dev]);
+
+ if (thinkpad[dev]) {
+ strcat(card->longname, " [Thinkpad]");
+ }
+
+ if ((err = snd_card_register(card)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ snd_ad1848_cards[dev] = card;
+ return 0;
+}
+
+static int __init alsa_card_ad1848_init(void)
+{
+ int dev, cards;
+
+ for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++)
+ if (snd_card_ad1848_probe(dev) >= 0)
+ cards++;
+
+ if (!cards) {
+#ifdef MODULE
+ printk(KERN_ERR "AD1848 soundcard not found or device busy\n");
+#endif
+ return -ENODEV;
+ }
+ return 0;
+}
+
+static void __exit alsa_card_ad1848_exit(void)
+{
+ int idx;
+
+ for (idx = 0; idx < SNDRV_CARDS; idx++)
+ snd_card_free(snd_ad1848_cards[idx]);
+}
+
+module_init(alsa_card_ad1848_init)
+module_exit(alsa_card_ad1848_exit)
diff --git a/sound/isa/ad1848/ad1848_lib.c b/sound/isa/ad1848/ad1848_lib.c
new file mode 100644
index 000000000000..8fb3db103e48
--- /dev/null
+++ b/sound/isa/ad1848/ad1848_lib.c
@@ -0,0 +1,1279 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ * Routines for control of AD1848/AD1847/CS4248
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#define SNDRV_MAIN_OBJECT_FILE
+#include <sound/driver.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/pm.h>
+#include <linux/slab.h>
+#include <linux/ioport.h>
+#include <sound/core.h>
+#include <sound/ad1848.h>
+#include <sound/control.h>
+#include <sound/pcm_params.h>
+
+#include <asm/io.h>
+#include <asm/dma.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("Routines for control of AD1848/AD1847/CS4248");
+MODULE_LICENSE("GPL");
+
+#if 0
+#define SNDRV_DEBUG_MCE
+#endif
+
+/*
+ * Some variables
+ */
+
+static unsigned char freq_bits[14] = {
+ /* 5510 */ 0x00 | AD1848_XTAL2,
+ /* 6620 */ 0x0E | AD1848_XTAL2,
+ /* 8000 */ 0x00 | AD1848_XTAL1,
+ /* 9600 */ 0x0E | AD1848_XTAL1,
+ /* 11025 */ 0x02 | AD1848_XTAL2,
+ /* 16000 */ 0x02 | AD1848_XTAL1,
+ /* 18900 */ 0x04 | AD1848_XTAL2,
+ /* 22050 */ 0x06 | AD1848_XTAL2,
+ /* 27042 */ 0x04 | AD1848_XTAL1,
+ /* 32000 */ 0x06 | AD1848_XTAL1,
+ /* 33075 */ 0x0C | AD1848_XTAL2,
+ /* 37800 */ 0x08 | AD1848_XTAL2,
+ /* 44100 */ 0x0A | AD1848_XTAL2,
+ /* 48000 */ 0x0C | AD1848_XTAL1
+};
+
+static unsigned int rates[14] = {
+ 5510, 6620, 8000, 9600, 11025, 16000, 18900, 22050,
+ 27042, 32000, 33075, 37800, 44100, 48000
+};
+
+static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
+ .count = 14,
+ .list = rates,
+ .mask = 0,
+};
+
+static unsigned char snd_ad1848_original_image[16] =
+{
+ 0x00, /* 00 - lic */
+ 0x00, /* 01 - ric */
+ 0x9f, /* 02 - la1ic */
+ 0x9f, /* 03 - ra1ic */
+ 0x9f, /* 04 - la2ic */
+ 0x9f, /* 05 - ra2ic */
+ 0xbf, /* 06 - loc */
+ 0xbf, /* 07 - roc */
+ 0x20, /* 08 - dfr */
+ AD1848_AUTOCALIB, /* 09 - ic */
+ 0x00, /* 0a - pc */
+ 0x00, /* 0b - ti */
+ 0x00, /* 0c - mi */
+ 0x00, /* 0d - lbc */
+ 0x00, /* 0e - dru */
+ 0x00, /* 0f - drl */
+};
+
+/*
+ * Basic I/O functions
+ */
+
+void snd_ad1848_out(ad1848_t *chip,
+ unsigned char reg,
+ unsigned char value)
+{
+ int timeout;
+
+ for (timeout = 250; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
+ udelay(100);
+#ifdef CONFIG_SND_DEBUG
+ if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
+ snd_printk("auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
+#endif
+ outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
+ outb(chip->image[reg] = value, AD1848P(chip, REG));
+ mb();
+#if 0
+ printk("codec out - reg 0x%x = 0x%x\n", chip->mce_bit | reg, value);
+#endif
+}
+
+static void snd_ad1848_dout(ad1848_t *chip,
+ unsigned char reg, unsigned char value)
+{
+ int timeout;
+
+ for (timeout = 250; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
+ udelay(100);
+ outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
+ outb(value, AD1848P(chip, REG));
+ mb();
+}
+
+static unsigned char snd_ad1848_in(ad1848_t *chip, unsigned char reg)
+{
+ int timeout;
+
+ for (timeout = 250; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
+ udelay(100);
+#ifdef CONFIG_SND_DEBUG
+ if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
+ snd_printk("auto calibration time out - reg = 0x%x\n", reg);
+#endif
+ outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
+ mb();
+ return inb(AD1848P(chip, REG));
+}
+
+#if 0
+
+static void snd_ad1848_debug(ad1848_t *chip)
+{
+ printk("AD1848 REGS: INDEX = 0x%02x ", inb(AD1848P(chip, REGSEL)));
+ printk(" STATUS = 0x%02x\n", inb(AD1848P(chip, STATUS)));
+ printk(" 0x00: left input = 0x%02x ", snd_ad1848_in(chip, 0x00));
+ printk(" 0x08: playback format = 0x%02x\n", snd_ad1848_in(chip, 0x08));
+ printk(" 0x01: right input = 0x%02x ", snd_ad1848_in(chip, 0x01));
+ printk(" 0x09: iface (CFIG 1) = 0x%02x\n", snd_ad1848_in(chip, 0x09));
+ printk(" 0x02: AUXA left = 0x%02x ", snd_ad1848_in(chip, 0x02));
+ printk(" 0x0a: pin control = 0x%02x\n", snd_ad1848_in(chip, 0x0a));
+ printk(" 0x03: AUXA right = 0x%02x ", snd_ad1848_in(chip, 0x03));
+ printk(" 0x0b: init & status = 0x%02x\n", snd_ad1848_in(chip, 0x0b));
+ printk(" 0x04: AUXB left = 0x%02x ", snd_ad1848_in(chip, 0x04));
+ printk(" 0x0c: revision & mode = 0x%02x\n", snd_ad1848_in(chip, 0x0c));
+ printk(" 0x05: AUXB right = 0x%02x ", snd_ad1848_in(chip, 0x05));
+ printk(" 0x0d: loopback = 0x%02x\n", snd_ad1848_in(chip, 0x0d));
+ printk(" 0x06: left output = 0x%02x ", snd_ad1848_in(chip, 0x06));
+ printk(" 0x0e: data upr count = 0x%02x\n", snd_ad1848_in(chip, 0x0e));
+ printk(" 0x07: right output = 0x%02x ", snd_ad1848_in(chip, 0x07));
+ printk(" 0x0f: data lwr count = 0x%02x\n", snd_ad1848_in(chip, 0x0f));
+}
+
+#endif
+
+/*
+ * AD1848 detection / MCE routines
+ */
+
+static void snd_ad1848_mce_up(ad1848_t *chip)
+{
+ unsigned long flags;
+ int timeout;
+
+ for (timeout = 250; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
+ udelay(100);
+#ifdef CONFIG_SND_DEBUG
+ if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
+ snd_printk("mce_up - auto calibration time out (0)\n");
+#endif
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ chip->mce_bit |= AD1848_MCE;
+ timeout = inb(AD1848P(chip, REGSEL));
+ if (timeout == 0x80)
+ snd_printk("mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port);
+ if (!(timeout & AD1848_MCE))
+ outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL));
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+}
+
+static void snd_ad1848_mce_down(ad1848_t *chip)
+{
+ unsigned long flags;
+ int timeout;
+ signed long time;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ for (timeout = 5; timeout > 0; timeout--)
+ inb(AD1848P(chip, REGSEL));
+ /* end of cleanup sequence */
+ for (timeout = 12000; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
+ udelay(100);
+#if 0
+ printk("(1) timeout = %i\n", timeout);
+#endif
+#ifdef CONFIG_SND_DEBUG
+ if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
+ snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", AD1848P(chip, REGSEL));
+#endif
+ chip->mce_bit &= ~AD1848_MCE;
+ timeout = inb(AD1848P(chip, REGSEL));
+ outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL));
+ if (timeout == 0x80)
+ snd_printk("mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port);
+ if ((timeout & AD1848_MCE) == 0) {
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return;
+ }
+ /* calibration process */
+
+ for (timeout = 500; timeout > 0 && (snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) == 0; timeout--);
+ if ((snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) == 0) {
+ snd_printd("mce_down - auto calibration time out (1)\n");
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return;
+ }
+#if 0
+ printk("(2) timeout = %i, jiffies = %li\n", timeout, jiffies);
+#endif
+ time = HZ / 4;
+ while (snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) {
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (time <= 0) {
+ snd_printk("mce_down - auto calibration time out (2)\n");
+ return;
+ }
+ set_current_state(TASK_INTERRUPTIBLE);
+ time = schedule_timeout(time);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ }
+#if 0
+ printk("(3) jiffies = %li\n", jiffies);
+#endif
+ time = HZ / 10;
+ while (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) {
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (time <= 0) {
+ snd_printk("mce_down - auto calibration time out (3)\n");
+ return;
+ }
+ set_current_state(TASK_INTERRUPTIBLE);
+ time = schedule_timeout(time);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ }
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+#if 0
+ printk("(4) jiffies = %li\n", jiffies);
+ snd_printk("mce_down - exit = 0x%x\n", inb(AD1848P(chip, REGSEL)));
+#endif
+}
+
+static unsigned int snd_ad1848_get_count(unsigned char format,
+ unsigned int size)
+{
+ switch (format & 0xe0) {
+ case AD1848_LINEAR_16:
+ size >>= 1;
+ break;
+ }
+ if (format & AD1848_STEREO)
+ size >>= 1;
+ return size;
+}
+
+static int snd_ad1848_trigger(ad1848_t *chip, unsigned char what,
+ int channel, int cmd)
+{
+ int result = 0;
+
+#if 0
+ printk("codec trigger!!! - what = %i, enable = %i, status = 0x%x\n", what, enable, inb(AD1848P(card, STATUS)));
+#endif
+ spin_lock(&chip->reg_lock);
+ if (cmd == SNDRV_PCM_TRIGGER_START) {
+ if (chip->image[AD1848_IFACE_CTRL] & what) {
+ spin_unlock(&chip->reg_lock);
+ return 0;
+ }
+ snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL] |= what);
+ chip->mode |= AD1848_MODE_RUNNING;
+ } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
+ if (!(chip->image[AD1848_IFACE_CTRL] & what)) {
+ spin_unlock(&chip->reg_lock);
+ return 0;
+ }
+ snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL] &= ~what);
+ chip->mode &= ~AD1848_MODE_RUNNING;
+ } else {
+ result = -EINVAL;
+ }
+ spin_unlock(&chip->reg_lock);
+ return result;
+}
+
+/*
+ * CODEC I/O
+ */
+
+static unsigned char snd_ad1848_get_rate(unsigned int rate)
+{
+ int i;
+
+ for (i = 0; i < 14; i++)
+ if (rate == rates[i])
+ return freq_bits[i];
+ snd_BUG();
+ return freq_bits[13];
+}
+
+static int snd_ad1848_ioctl(snd_pcm_substream_t * substream,
+ unsigned int cmd, void *arg)
+{
+ return snd_pcm_lib_ioctl(substream, cmd, arg);
+}
+
+static unsigned char snd_ad1848_get_format(int format, int channels)
+{
+ unsigned char rformat;
+
+ rformat = AD1848_LINEAR_8;
+ switch (format) {
+ case SNDRV_PCM_FORMAT_A_LAW: rformat = AD1848_ALAW_8; break;
+ case SNDRV_PCM_FORMAT_MU_LAW: rformat = AD1848_ULAW_8; break;
+ case SNDRV_PCM_FORMAT_S16_LE: rformat = AD1848_LINEAR_16; break;
+ }
+ if (channels > 1)
+ rformat |= AD1848_STEREO;
+#if 0
+ snd_printk("get_format: 0x%x (mode=0x%x)\n", format, mode);
+#endif
+ return rformat;
+}
+
+static void snd_ad1848_calibrate_mute(ad1848_t *chip, int mute)
+{
+ unsigned long flags;
+
+ mute = mute ? 1 : 0;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ if (chip->calibrate_mute == mute) {
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return;
+ }
+ if (!mute) {
+ snd_ad1848_dout(chip, AD1848_LEFT_INPUT, chip->image[AD1848_LEFT_INPUT]);
+ snd_ad1848_dout(chip, AD1848_RIGHT_INPUT, chip->image[AD1848_RIGHT_INPUT]);
+ }
+ snd_ad1848_dout(chip, AD1848_AUX1_LEFT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX1_LEFT_INPUT]);
+ snd_ad1848_dout(chip, AD1848_AUX1_RIGHT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX1_RIGHT_INPUT]);
+ snd_ad1848_dout(chip, AD1848_AUX2_LEFT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX2_LEFT_INPUT]);
+ snd_ad1848_dout(chip, AD1848_AUX2_RIGHT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX2_RIGHT_INPUT]);
+ snd_ad1848_dout(chip, AD1848_LEFT_OUTPUT, mute ? 0x80 : chip->image[AD1848_LEFT_OUTPUT]);
+ snd_ad1848_dout(chip, AD1848_RIGHT_OUTPUT, mute ? 0x80 : chip->image[AD1848_RIGHT_OUTPUT]);
+ chip->calibrate_mute = mute;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+}
+
+static void snd_ad1848_set_data_format(ad1848_t *chip, snd_pcm_hw_params_t *hw_params)
+{
+ if (hw_params == NULL) {
+ chip->image[AD1848_DATA_FORMAT] = 0x20;
+ } else {
+ chip->image[AD1848_DATA_FORMAT] =
+ snd_ad1848_get_format(params_format(hw_params), params_channels(hw_params)) |
+ snd_ad1848_get_rate(params_rate(hw_params));
+ }
+ // snd_printk(">>> pmode = 0x%x, dfr = 0x%x\n", pstr->mode, chip->image[AD1848_DATA_FORMAT]);
+}
+
+static int snd_ad1848_open(ad1848_t *chip, unsigned int mode)
+{
+ unsigned long flags;
+
+ down(&chip->open_mutex);
+ if (chip->mode & AD1848_MODE_OPEN) {
+ up(&chip->open_mutex);
+ return -EAGAIN;
+ }
+ snd_ad1848_mce_down(chip);
+
+#ifdef SNDRV_DEBUG_MCE
+ snd_printk("open: (1)\n");
+#endif
+ snd_ad1848_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO |
+ AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO |
+ AD1848_CALIB_MODE);
+ chip->image[AD1848_IFACE_CTRL] |= AD1848_AUTOCALIB;
+ snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_ad1848_mce_down(chip);
+
+#ifdef SNDRV_DEBUG_MCE
+ snd_printk("open: (2)\n");
+#endif
+
+ snd_ad1848_set_data_format(chip, NULL);
+
+ snd_ad1848_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_ad1848_mce_down(chip);
+
+#ifdef SNDRV_DEBUG_MCE
+ snd_printk("open: (3)\n");
+#endif
+
+ /* ok. now enable and ack CODEC IRQ */
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
+ outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
+ chip->image[AD1848_PIN_CTRL] |= AD1848_IRQ_ENABLE;
+ snd_ad1848_out(chip, AD1848_PIN_CTRL, chip->image[AD1848_PIN_CTRL]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+
+ chip->mode = mode;
+ up(&chip->open_mutex);
+
+ return 0;
+}
+
+static void snd_ad1848_close(ad1848_t *chip)
+{
+ unsigned long flags;
+
+ down(&chip->open_mutex);
+ if (!chip->mode) {
+ up(&chip->open_mutex);
+ return;
+ }
+ /* disable IRQ */
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
+ outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
+ chip->image[AD1848_PIN_CTRL] &= ~AD1848_IRQ_ENABLE;
+ snd_ad1848_out(chip, AD1848_PIN_CTRL, chip->image[AD1848_PIN_CTRL]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+
+ /* now disable capture & playback */
+
+ snd_ad1848_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO |
+ AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO);
+ snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_ad1848_mce_down(chip);
+
+ /* clear IRQ again */
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
+ outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+
+ chip->mode = 0;
+ up(&chip->open_mutex);
+}
+
+/*
+ * ok.. exported functions..
+ */
+
+static int snd_ad1848_playback_trigger(snd_pcm_substream_t * substream,
+ int cmd)
+{
+ ad1848_t *chip = snd_pcm_substream_chip(substream);
+ return snd_ad1848_trigger(chip, AD1848_PLAYBACK_ENABLE, SNDRV_PCM_STREAM_PLAYBACK, cmd);
+}
+
+static int snd_ad1848_capture_trigger(snd_pcm_substream_t * substream,
+ int cmd)
+{
+ ad1848_t *chip = snd_pcm_substream_chip(substream);
+ return snd_ad1848_trigger(chip, AD1848_CAPTURE_ENABLE, SNDRV_PCM_STREAM_CAPTURE, cmd);
+}
+
+static int snd_ad1848_playback_hw_params(snd_pcm_substream_t * substream,
+ snd_pcm_hw_params_t * hw_params)
+{
+ ad1848_t *chip = snd_pcm_substream_chip(substream);
+ unsigned long flags;
+ int err;
+
+ if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
+ return err;
+ snd_ad1848_calibrate_mute(chip, 1);
+ snd_ad1848_set_data_format(chip, hw_params);
+ snd_ad1848_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_ad1848_mce_down(chip);
+ snd_ad1848_calibrate_mute(chip, 0);
+ return 0;
+}
+
+static int snd_ad1848_playback_hw_free(snd_pcm_substream_t * substream)
+{
+ return snd_pcm_lib_free_pages(substream);
+}
+
+static int snd_ad1848_playback_prepare(snd_pcm_substream_t * substream)
+{
+ ad1848_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ unsigned long flags;
+ unsigned int size = snd_pcm_lib_buffer_bytes(substream);
+ unsigned int count = snd_pcm_lib_period_bytes(substream);
+
+ chip->dma_size = size;
+ chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO);
+ snd_dma_program(chip->dma, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
+ count = snd_ad1848_get_count(chip->image[AD1848_DATA_FORMAT], count) - 1;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_ad1848_out(chip, AD1848_DATA_LWR_CNT, (unsigned char) count);
+ snd_ad1848_out(chip, AD1848_DATA_UPR_CNT, (unsigned char) (count >> 8));
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return 0;
+}
+
+static int snd_ad1848_capture_hw_params(snd_pcm_substream_t * substream,
+ snd_pcm_hw_params_t * hw_params)
+{
+ ad1848_t *chip = snd_pcm_substream_chip(substream);
+ unsigned long flags;
+ int err;
+
+ if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
+ return err;
+ snd_ad1848_calibrate_mute(chip, 1);
+ snd_ad1848_set_data_format(chip, hw_params);
+ snd_ad1848_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_ad1848_mce_down(chip);
+ snd_ad1848_calibrate_mute(chip, 0);
+ return 0;
+}
+
+static int snd_ad1848_capture_hw_free(snd_pcm_substream_t * substream)
+{
+ return snd_pcm_lib_free_pages(substream);
+}
+
+static int snd_ad1848_capture_prepare(snd_pcm_substream_t * substream)
+{
+ ad1848_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ unsigned long flags;
+ unsigned int size = snd_pcm_lib_buffer_bytes(substream);
+ unsigned int count = snd_pcm_lib_period_bytes(substream);
+
+ chip->dma_size = size;
+ chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO);
+ snd_dma_program(chip->dma, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
+ count = snd_ad1848_get_count(chip->image[AD1848_DATA_FORMAT], count) - 1;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_ad1848_out(chip, AD1848_DATA_LWR_CNT, (unsigned char) count);
+ snd_ad1848_out(chip, AD1848_DATA_UPR_CNT, (unsigned char) (count >> 8));
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return 0;
+}
+
+static irqreturn_t snd_ad1848_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ ad1848_t *chip = dev_id;
+
+ if ((chip->mode & AD1848_MODE_PLAY) && chip->playback_substream &&
+ (chip->mode & AD1848_MODE_RUNNING))
+ snd_pcm_period_elapsed(chip->playback_substream);
+ if ((chip->mode & AD1848_MODE_CAPTURE) && chip->capture_substream &&
+ (chip->mode & AD1848_MODE_RUNNING))
+ snd_pcm_period_elapsed(chip->capture_substream);
+ outb(0, AD1848P(chip, STATUS)); /* clear global interrupt bit */
+ return IRQ_HANDLED;
+}
+
+static snd_pcm_uframes_t snd_ad1848_playback_pointer(snd_pcm_substream_t * substream)
+{
+ ad1848_t *chip = snd_pcm_substream_chip(substream);
+ size_t ptr;
+
+ if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_PLAYBACK_ENABLE))
+ return 0;
+ ptr = snd_dma_pointer(chip->dma, chip->dma_size);
+ return bytes_to_frames(substream->runtime, ptr);
+}
+
+static snd_pcm_uframes_t snd_ad1848_capture_pointer(snd_pcm_substream_t * substream)
+{
+ ad1848_t *chip = snd_pcm_substream_chip(substream);
+ size_t ptr;
+
+ if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_CAPTURE_ENABLE))
+ return 0;
+ ptr = snd_dma_pointer(chip->dma, chip->dma_size);
+ return bytes_to_frames(substream->runtime, ptr);
+}
+
+/*
+
+ */
+
+static void snd_ad1848_thinkpad_twiddle(ad1848_t *chip, int on) {
+
+ int tmp;
+
+ if (!chip->thinkpad_flag) return;
+
+ outb(0x1c, AD1848_THINKPAD_CTL_PORT1);
+ tmp = inb(AD1848_THINKPAD_CTL_PORT2);
+
+ if (on)
+ /* turn it on */
+ tmp |= AD1848_THINKPAD_CS4248_ENABLE_BIT;
+ else
+ /* turn it off */
+ tmp &= ~AD1848_THINKPAD_CS4248_ENABLE_BIT;
+
+ outb(tmp, AD1848_THINKPAD_CTL_PORT2);
+
+}
+
+#ifdef CONFIG_PM
+static int snd_ad1848_suspend(snd_card_t *card, pm_message_t state)
+{
+ ad1848_t *chip = card->pm_private_data;
+
+ snd_pcm_suspend_all(chip->pcm);
+ /* FIXME: save registers? */
+
+ if (chip->thinkpad_flag)
+ snd_ad1848_thinkpad_twiddle(chip, 0);
+
+ return 0;
+}
+
+static int snd_ad1848_resume(snd_card_t *card)
+{
+ ad1848_t *chip = card->pm_private_data;
+
+ if (chip->thinkpad_flag)
+ snd_ad1848_thinkpad_twiddle(chip, 1);
+
+ /* FIXME: restore registers? */
+
+ return 0;
+}
+#endif /* CONFIG_PM */
+
+static int snd_ad1848_probe(ad1848_t * chip)
+{
+ unsigned long flags;
+ int i, id, rev, ad1847;
+ unsigned char *ptr;
+
+#if 0
+ snd_ad1848_debug(chip);
+#endif
+ id = ad1847 = 0;
+ for (i = 0; i < 1000; i++) {
+ mb();
+ if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
+ udelay(500);
+ else {
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_ad1848_out(chip, AD1848_MISC_INFO, 0x00);
+ snd_ad1848_out(chip, AD1848_LEFT_INPUT, 0xaa);
+ snd_ad1848_out(chip, AD1848_RIGHT_INPUT, 0x45);
+ rev = snd_ad1848_in(chip, AD1848_RIGHT_INPUT);
+ if (rev == 0x65) {
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ id = 1;
+ ad1847 = 1;
+ break;
+ }
+ if (snd_ad1848_in(chip, AD1848_LEFT_INPUT) == 0xaa && rev == 0x45) {
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ id = 1;
+ break;
+ }
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ }
+ }
+ if (id != 1)
+ return -ENODEV; /* no valid device found */
+ if (chip->hardware == AD1848_HW_DETECT) {
+ if (ad1847) {
+ chip->hardware = AD1848_HW_AD1847;
+ } else {
+ chip->hardware = AD1848_HW_AD1848;
+ rev = snd_ad1848_in(chip, AD1848_MISC_INFO);
+ if (rev & 0x80) {
+ chip->hardware = AD1848_HW_CS4248;
+ } else if ((rev & 0x0f) == 0x0a) {
+ snd_ad1848_out(chip, AD1848_MISC_INFO, 0x40);
+ for (i = 0; i < 16; ++i) {
+ if (snd_ad1848_in(chip, i) != snd_ad1848_in(chip, i + 16)) {
+ chip->hardware = AD1848_HW_CMI8330;
+ break;
+ }
+ }
+ snd_ad1848_out(chip, AD1848_MISC_INFO, 0x00);
+ }
+ }
+ }
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ inb(AD1848P(chip, STATUS)); /* clear any pendings IRQ */
+ outb(0, AD1848P(chip, STATUS));
+ mb();
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+
+ chip->image[AD1848_MISC_INFO] = 0x00;
+ chip->image[AD1848_IFACE_CTRL] =
+ (chip->image[AD1848_IFACE_CTRL] & ~AD1848_SINGLE_DMA) | AD1848_SINGLE_DMA;
+ ptr = (unsigned char *) &chip->image;
+ snd_ad1848_mce_down(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ for (i = 0; i < 16; i++) /* ok.. fill all AD1848 registers */
+ snd_ad1848_out(chip, i, *ptr++);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_ad1848_mce_up(chip);
+ snd_ad1848_mce_down(chip);
+ return 0; /* all things are ok.. */
+}
+
+/*
+
+ */
+
+static snd_pcm_hardware_t snd_ad1848_playback =
+{
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_MMAP_VALID),
+ .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
+ SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE),
+ .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
+ .rate_min = 5510,
+ .rate_max = 48000,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = (128*1024),
+ .period_bytes_min = 64,
+ .period_bytes_max = (128*1024),
+ .periods_min = 1,
+ .periods_max = 1024,
+ .fifo_size = 0,
+};
+
+static snd_pcm_hardware_t snd_ad1848_capture =
+{
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_MMAP_VALID),
+ .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
+ SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE),
+ .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
+ .rate_min = 5510,
+ .rate_max = 48000,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = (128*1024),
+ .period_bytes_min = 64,
+ .period_bytes_max = (128*1024),
+ .periods_min = 1,
+ .periods_max = 1024,
+ .fifo_size = 0,
+};
+
+/*
+
+ */
+
+static int snd_ad1848_playback_open(snd_pcm_substream_t * substream)
+{
+ ad1848_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ int err;
+
+ if ((err = snd_ad1848_open(chip, AD1848_MODE_PLAY)) < 0)
+ return err;
+ chip->playback_substream = substream;
+ runtime->hw = snd_ad1848_playback;
+ snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.buffer_bytes_max);
+ snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.period_bytes_max);
+ snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
+ return 0;
+}
+
+static int snd_ad1848_capture_open(snd_pcm_substream_t * substream)
+{
+ ad1848_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ int err;
+
+ if ((err = snd_ad1848_open(chip, AD1848_MODE_CAPTURE)) < 0)
+ return err;
+ chip->capture_substream = substream;
+ runtime->hw = snd_ad1848_capture;
+ snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.buffer_bytes_max);
+ snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.period_bytes_max);
+ snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
+ return 0;
+}
+
+static int snd_ad1848_playback_close(snd_pcm_substream_t * substream)
+{
+ ad1848_t *chip = snd_pcm_substream_chip(substream);
+
+ chip->mode &= ~AD1848_MODE_PLAY;
+ chip->playback_substream = NULL;
+ snd_ad1848_close(chip);
+ return 0;
+}
+
+static int snd_ad1848_capture_close(snd_pcm_substream_t * substream)
+{
+ ad1848_t *chip = snd_pcm_substream_chip(substream);
+
+ chip->mode &= ~AD1848_MODE_CAPTURE;
+ chip->capture_substream = NULL;
+ snd_ad1848_close(chip);
+ return 0;
+}
+
+static int snd_ad1848_free(ad1848_t *chip)
+{
+ if (chip->res_port) {
+ release_resource(chip->res_port);
+ kfree_nocheck(chip->res_port);
+ }
+ if (chip->irq >= 0)
+ free_irq(chip->irq, (void *) chip);
+ if (chip->dma >= 0) {
+ snd_dma_disable(chip->dma);
+ free_dma(chip->dma);
+ }
+ kfree(chip);
+ return 0;
+}
+
+static int snd_ad1848_dev_free(snd_device_t *device)
+{
+ ad1848_t *chip = device->device_data;
+ return snd_ad1848_free(chip);
+}
+
+static const char *snd_ad1848_chip_id(ad1848_t *chip)
+{
+ switch (chip->hardware) {
+ case AD1848_HW_AD1847: return "AD1847";
+ case AD1848_HW_AD1848: return "AD1848";
+ case AD1848_HW_CS4248: return "CS4248";
+ case AD1848_HW_CMI8330: return "CMI8330/C3D";
+ default: return "???";
+ }
+}
+
+int snd_ad1848_create(snd_card_t * card,
+ unsigned long port,
+ int irq, int dma,
+ unsigned short hardware,
+ ad1848_t ** rchip)
+{
+ static snd_device_ops_t ops = {
+ .dev_free = snd_ad1848_dev_free,
+ };
+ ad1848_t *chip;
+ int err;
+
+ *rchip = NULL;
+ chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
+ if (chip == NULL)
+ return -ENOMEM;
+ spin_lock_init(&chip->reg_lock);
+ init_MUTEX(&chip->open_mutex);
+ chip->card = card;
+ chip->port = port;
+ chip->irq = -1;
+ chip->dma = -1;
+ chip->hardware = hardware;
+ memcpy(&chip->image, &snd_ad1848_original_image, sizeof(snd_ad1848_original_image));
+
+ if ((chip->res_port = request_region(port, 4, "AD1848")) == NULL) {
+ snd_printk(KERN_ERR "ad1848: can't grab port 0x%lx\n", port);
+ snd_ad1848_free(chip);
+ return -EBUSY;
+ }
+ if (request_irq(irq, snd_ad1848_interrupt, SA_INTERRUPT, "AD1848", (void *) chip)) {
+ snd_printk(KERN_ERR "ad1848: can't grab IRQ %d\n", irq);
+ snd_ad1848_free(chip);
+ return -EBUSY;
+ }
+ chip->irq = irq;
+ if (request_dma(dma, "AD1848")) {
+ snd_printk(KERN_ERR "ad1848: can't grab DMA %d\n", dma);
+ snd_ad1848_free(chip);
+ return -EBUSY;
+ }
+ chip->dma = dma;
+
+ if (hardware == AD1848_HW_THINKPAD) {
+ chip->thinkpad_flag = 1;
+ chip->hardware = AD1848_HW_DETECT; /* reset */
+ snd_ad1848_thinkpad_twiddle(chip, 1);
+ snd_card_set_isa_pm_callback(card, snd_ad1848_suspend, snd_ad1848_resume, chip);
+ }
+
+ if (snd_ad1848_probe(chip) < 0) {
+ snd_ad1848_free(chip);
+ return -ENODEV;
+ }
+
+ /* Register device */
+ if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
+ snd_ad1848_free(chip);
+ return err;
+ }
+
+ *rchip = chip;
+ return 0;
+}
+
+static snd_pcm_ops_t snd_ad1848_playback_ops = {
+ .open = snd_ad1848_playback_open,
+ .close = snd_ad1848_playback_close,
+ .ioctl = snd_ad1848_ioctl,
+ .hw_params = snd_ad1848_playback_hw_params,
+ .hw_free = snd_ad1848_playback_hw_free,
+ .prepare = snd_ad1848_playback_prepare,
+ .trigger = snd_ad1848_playback_trigger,
+ .pointer = snd_ad1848_playback_pointer,
+};
+
+static snd_pcm_ops_t snd_ad1848_capture_ops = {
+ .open = snd_ad1848_capture_open,
+ .close = snd_ad1848_capture_close,
+ .ioctl = snd_ad1848_ioctl,
+ .hw_params = snd_ad1848_capture_hw_params,
+ .hw_free = snd_ad1848_capture_hw_free,
+ .prepare = snd_ad1848_capture_prepare,
+ .trigger = snd_ad1848_capture_trigger,
+ .pointer = snd_ad1848_capture_pointer,
+};
+
+static void snd_ad1848_pcm_free(snd_pcm_t *pcm)
+{
+ ad1848_t *chip = pcm->private_data;
+ chip->pcm = NULL;
+ snd_pcm_lib_preallocate_free_for_all(pcm);
+}
+
+int snd_ad1848_pcm(ad1848_t *chip, int device, snd_pcm_t **rpcm)
+{
+ snd_pcm_t *pcm;
+ int err;
+
+ if ((err = snd_pcm_new(chip->card, "AD1848", device, 1, 1, &pcm)) < 0)
+ return err;
+
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ad1848_playback_ops);
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ad1848_capture_ops);
+
+ pcm->private_free = snd_ad1848_pcm_free;
+ pcm->private_data = chip;
+ pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
+ strcpy(pcm->name, snd_ad1848_chip_id(chip));
+
+ snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
+ snd_dma_isa_data(),
+ 64*1024, chip->dma > 3 ? 128*1024 : 64*1024);
+
+ chip->pcm = pcm;
+ if (rpcm)
+ *rpcm = pcm;
+ return 0;
+}
+
+const snd_pcm_ops_t *snd_ad1848_get_pcm_ops(int direction)
+{
+ return direction == SNDRV_PCM_STREAM_PLAYBACK ?
+ &snd_ad1848_playback_ops : &snd_ad1848_capture_ops;
+}
+
+/*
+ * MIXER part
+ */
+
+static int snd_ad1848_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ static char *texts[4] = {
+ "Line", "Aux", "Mic", "Mix"
+ };
+
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+ uinfo->count = 2;
+ uinfo->value.enumerated.items = 4;
+ if (uinfo->value.enumerated.item > 3)
+ uinfo->value.enumerated.item = 3;
+ strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+ return 0;
+}
+
+static int snd_ad1848_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ ad1848_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.enumerated.item[0] = (chip->image[AD1848_LEFT_INPUT] & AD1848_MIXS_ALL) >> 6;
+ ucontrol->value.enumerated.item[1] = (chip->image[AD1848_RIGHT_INPUT] & AD1848_MIXS_ALL) >> 6;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return 0;
+}
+
+static int snd_ad1848_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ ad1848_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ unsigned short left, right;
+ int change;
+
+ if (ucontrol->value.enumerated.item[0] > 3 ||
+ ucontrol->value.enumerated.item[1] > 3)
+ return -EINVAL;
+ left = ucontrol->value.enumerated.item[0] << 6;
+ right = ucontrol->value.enumerated.item[1] << 6;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ left = (chip->image[AD1848_LEFT_INPUT] & ~AD1848_MIXS_ALL) | left;
+ right = (chip->image[AD1848_RIGHT_INPUT] & ~AD1848_MIXS_ALL) | right;
+ change = left != chip->image[AD1848_LEFT_INPUT] ||
+ right != chip->image[AD1848_RIGHT_INPUT];
+ snd_ad1848_out(chip, AD1848_LEFT_INPUT, left);
+ snd_ad1848_out(chip, AD1848_RIGHT_INPUT, right);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+static int snd_ad1848_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+
+ uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = mask;
+ return 0;
+}
+
+static int snd_ad1848_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ ad1848_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (invert)
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ return 0;
+}
+
+static int snd_ad1848_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ ad1848_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+ int change;
+ unsigned short val;
+
+ val = (ucontrol->value.integer.value[0] & mask);
+ if (invert)
+ val = mask - val;
+ val <<= shift;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ val = (chip->image[reg] & ~(mask << shift)) | val;
+ change = val != chip->image[reg];
+ snd_ad1848_out(chip, reg, val);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+static int snd_ad1848_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+
+ uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 2;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = mask;
+ return 0;
+}
+
+static int snd_ad1848_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ ad1848_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int left_reg = kcontrol->private_value & 0xff;
+ int right_reg = (kcontrol->private_value >> 8) & 0xff;
+ int shift_left = (kcontrol->private_value >> 16) & 0x07;
+ int shift_right = (kcontrol->private_value >> 19) & 0x07;
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+ int invert = (kcontrol->private_value >> 22) & 1;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
+ ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (invert) {
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
+ }
+ return 0;
+}
+
+static int snd_ad1848_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ ad1848_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int left_reg = kcontrol->private_value & 0xff;
+ int right_reg = (kcontrol->private_value >> 8) & 0xff;
+ int shift_left = (kcontrol->private_value >> 16) & 0x07;
+ int shift_right = (kcontrol->private_value >> 19) & 0x07;
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+ int invert = (kcontrol->private_value >> 22) & 1;
+ int change;
+ unsigned short val1, val2;
+
+ val1 = ucontrol->value.integer.value[0] & mask;
+ val2 = ucontrol->value.integer.value[1] & mask;
+ if (invert) {
+ val1 = mask - val1;
+ val2 = mask - val2;
+ }
+ val1 <<= shift_left;
+ val2 <<= shift_right;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ if (left_reg != right_reg) {
+ val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
+ val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
+ change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg];
+ snd_ad1848_out(chip, left_reg, val1);
+ snd_ad1848_out(chip, right_reg, val2);
+ } else {
+ val1 = (chip->image[left_reg] & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
+ change = val1 != chip->image[left_reg];
+ snd_ad1848_out(chip, left_reg, val1);
+ }
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+/*
+ */
+int snd_ad1848_add_ctl(ad1848_t *chip, const char *name, int index, int type, unsigned long value)
+{
+ static snd_kcontrol_new_t newctls[] = {
+ [AD1848_MIX_SINGLE] = {
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .info = snd_ad1848_info_single,
+ .get = snd_ad1848_get_single,
+ .put = snd_ad1848_put_single,
+ },
+ [AD1848_MIX_DOUBLE] = {
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .info = snd_ad1848_info_double,
+ .get = snd_ad1848_get_double,
+ .put = snd_ad1848_put_double,
+ },
+ [AD1848_MIX_CAPTURE] = {
+ .info = snd_ad1848_info_mux,
+ .get = snd_ad1848_get_mux,
+ .put = snd_ad1848_put_mux,
+ },
+ };
+ snd_kcontrol_t *ctl;
+ int err;
+
+ ctl = snd_ctl_new1(&newctls[type], chip);
+ if (! ctl)
+ return -ENOMEM;
+ strlcpy(ctl->id.name, name, sizeof(ctl->id.name));
+ ctl->id.index = index;
+ ctl->private_value = value;
+ if ((err = snd_ctl_add(chip->card, ctl)) < 0) {
+ snd_ctl_free_one(ctl);
+ return err;
+ }
+ return 0;
+}
+
+
+static struct ad1848_mix_elem snd_ad1848_controls[] = {
+AD1848_DOUBLE("PCM Playback Switch", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 7, 7, 1, 1),
+AD1848_DOUBLE("PCM Playback Volume", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 0, 0, 63, 1),
+AD1848_DOUBLE("Aux Playback Switch", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
+AD1848_DOUBLE("Aux Playback Volume", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
+AD1848_DOUBLE("Aux Playback Switch", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
+AD1848_DOUBLE("Aux Playback Volume", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
+AD1848_DOUBLE("Capture Volume", 0, AD1848_LEFT_INPUT, AD1848_RIGHT_INPUT, 0, 0, 15, 0),
+{
+ .name = "Capture Source",
+ .type = AD1848_MIX_CAPTURE,
+},
+AD1848_SINGLE("Loopback Capture Switch", 0, AD1848_LOOPBACK, 0, 1, 0),
+AD1848_SINGLE("Loopback Capture Volume", 0, AD1848_LOOPBACK, 1, 63, 0)
+};
+
+int snd_ad1848_mixer(ad1848_t *chip)
+{
+ snd_card_t *card;
+ snd_pcm_t *pcm;
+ unsigned int idx;
+ int err;
+
+ snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL);
+
+ pcm = chip->pcm;
+ card = chip->card;
+
+ strcpy(card->mixername, pcm->name);
+
+ for (idx = 0; idx < ARRAY_SIZE(snd_ad1848_controls); idx++)
+ if ((err = snd_ad1848_add_ctl_elem(chip, &snd_ad1848_controls[idx])) < 0)
+ return err;
+
+ return 0;
+}
+
+EXPORT_SYMBOL(snd_ad1848_out);
+EXPORT_SYMBOL(snd_ad1848_create);
+EXPORT_SYMBOL(snd_ad1848_pcm);
+EXPORT_SYMBOL(snd_ad1848_get_pcm_ops);
+EXPORT_SYMBOL(snd_ad1848_mixer);
+EXPORT_SYMBOL(snd_ad1848_add_ctl);
+
+/*
+ * INIT part
+ */
+
+static int __init alsa_ad1848_init(void)
+{
+ return 0;
+}
+
+static void __exit alsa_ad1848_exit(void)
+{
+}
+
+module_init(alsa_ad1848_init)
+module_exit(alsa_ad1848_exit)
diff --git a/sound/isa/als100.c b/sound/isa/als100.c
new file mode 100644
index 000000000000..ac8f13664983
--- /dev/null
+++ b/sound/isa/als100.c
@@ -0,0 +1,336 @@
+
+/*
+ card-als100.c - driver for Avance Logic ALS100 based soundcards.
+ Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
+
+ Thanks to Pierfrancesco 'qM2' Passerini.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include <sound/driver.h>
+#include <linux/init.h>
+#include <linux/wait.h>
+#include <linux/time.h>
+#include <linux/pnp.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/initval.h>
+#include <sound/mpu401.h>
+#include <sound/opl3.h>
+#include <sound/sb.h>
+
+#define PFX "als100: "
+
+MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
+MODULE_DESCRIPTION("Avance Logic ALS1X0");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS100 - PRO16PNP},"
+ "{Avance Logic,ALS110},"
+ "{Avance Logic,ALS120},"
+ "{Avance Logic,ALS200},"
+ "{3D Melody,MF1000},"
+ "{Digimate,3D Sound},"
+ "{Avance Logic,ALS120},"
+ "{RTL,RTL3000}}");
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
+static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
+static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
+static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
+static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for als100 based soundcard.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for als100 based soundcard.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable als100 based soundcard.");
+module_param_array(port, long, NULL, 0444);
+MODULE_PARM_DESC(port, "Port # for als100 driver.");
+module_param_array(mpu_port, long, NULL, 0444);
+MODULE_PARM_DESC(mpu_port, "MPU-401 port # for als100 driver.");
+module_param_array(fm_port, long, NULL, 0444);
+MODULE_PARM_DESC(fm_port, "FM port # for als100 driver.");
+module_param_array(irq, int, NULL, 0444);
+MODULE_PARM_DESC(irq, "IRQ # for als100 driver.");
+module_param_array(mpu_irq, int, NULL, 0444);
+MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for als100 driver.");
+module_param_array(dma8, int, NULL, 0444);
+MODULE_PARM_DESC(dma8, "8-bit DMA # for als100 driver.");
+module_param_array(dma16, int, NULL, 0444);
+MODULE_PARM_DESC(dma16, "16-bit DMA # for als100 driver.");
+
+struct snd_card_als100 {
+ int dev_no;
+ struct pnp_dev *dev;
+ struct pnp_dev *devmpu;
+ struct pnp_dev *devopl;
+};
+
+static struct pnp_card_device_id snd_als100_pnpids[] = {
+ /* ALS100 - PRO16PNP */
+ { .id = "ALS0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } } },
+ /* ALS110 - MF1000 - Digimate 3D Sound */
+ { .id = "ALS0110", .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" } } },
+ /* ALS120 */
+ { .id = "ALS0120", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
+ /* ALS200 */
+ { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" } } },
+ /* ALS200 OEM */
+ { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0020" } } },
+ /* RTL3000 */
+ { .id = "RTL3000", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
+ { .id = "", } /* end */
+};
+
+MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);
+
+#define DRIVER_NAME "snd-card-als100"
+
+static int __devinit snd_card_als100_pnp(int dev, struct snd_card_als100 *acard,
+ struct pnp_card_link *card,
+ const struct pnp_card_device_id *id)
+{
+ struct pnp_dev *pdev;
+ struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
+ int err;
+
+ if (!cfg)
+ return -ENOMEM;
+ acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
+ if (acard->dev == NULL) {
+ kfree(cfg);
+ return -ENODEV;
+ }
+ acard->devmpu = pnp_request_card_device(card, id->devs[1].id, acard->dev);
+ acard->devopl = pnp_request_card_device(card, id->devs[2].id, acard->dev);
+
+ pdev = acard->dev;
+
+ pnp_init_resource_table(cfg);
+
+ /* override resources */
+ if (port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
+ if (dma8[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
+ if (dma16[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[1], dma16[dev], 1);
+ if (irq[dev] != SNDRV_AUTO_IRQ)
+ pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
+ if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
+ snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
+ kfree(cfg);
+ return err;
+ }
+ port[dev] = pnp_port_start(pdev, 0);
+ dma8[dev] = pnp_dma(pdev, 1);
+ dma16[dev] = pnp_dma(pdev, 0);
+ irq[dev] = pnp_irq(pdev, 0);
+
+ pdev = acard->devmpu;
+ if (pdev != NULL) {
+ pnp_init_resource_table(cfg);
+ if (mpu_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
+ if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
+ pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
+ if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
+ snd_printk(KERN_ERR PFX "MPU401 the requested resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0)
+ goto __mpu_error;
+ mpu_port[dev] = pnp_port_start(pdev, 0);
+ mpu_irq[dev] = pnp_irq(pdev, 0);
+ } else {
+ __mpu_error:
+ if (pdev) {
+ pnp_release_card_device(pdev);
+ snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
+ }
+ acard->devmpu = NULL;
+ mpu_port[dev] = -1;
+ }
+
+ pdev = acard->devopl;
+ if (pdev != NULL) {
+ pnp_init_resource_table(cfg);
+ if (fm_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4);
+ if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
+ snd_printk(KERN_ERR PFX "OPL3 the requested resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0)
+ goto __fm_error;
+ fm_port[dev] = pnp_port_start(pdev, 0);
+ } else {
+ __fm_error:
+ if (pdev) {
+ pnp_release_card_device(pdev);
+ snd_printk(KERN_ERR PFX "OPL3 pnp configure failure, skipping\n");
+ }
+ acard->devopl = NULL;
+ fm_port[dev] = -1;
+ }
+
+ kfree(cfg);
+ return 0;
+}
+
+static int __init snd_card_als100_probe(int dev,
+ struct pnp_card_link *pcard,
+ const struct pnp_card_device_id *pid)
+{
+ int error;
+ sb_t *chip;
+ snd_card_t *card;
+ struct snd_card_als100 *acard;
+ opl3_t *opl3;
+
+ if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
+ sizeof(struct snd_card_als100))) == NULL)
+ return -ENOMEM;
+ acard = (struct snd_card_als100 *)card->private_data;
+
+ if ((error = snd_card_als100_pnp(dev, acard, pcard, pid))) {
+ snd_card_free(card);
+ return error;
+ }
+ snd_card_set_dev(card, &pcard->card->dev);
+
+ if ((error = snd_sbdsp_create(card, port[dev],
+ irq[dev],
+ snd_sb16dsp_interrupt,
+ dma8[dev],
+ dma16[dev],
+ SB_HW_ALS100, &chip)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+
+ strcpy(card->driver, "ALS100");
+ strcpy(card->shortname, "Avance Logic ALS100");
+ sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
+ card->shortname, chip->name, chip->port,
+ irq[dev], dma8[dev], dma16[dev]);
+
+ if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+
+ if ((error = snd_sbmixer_new(chip)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+
+ if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
+ if (snd_mpu401_uart_new(card, 0, MPU401_HW_ALS100,
+ mpu_port[dev], 0,
+ mpu_irq[dev], SA_INTERRUPT,
+ NULL) < 0)
+ snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
+ }
+
+ if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
+ if (snd_opl3_create(card,
+ fm_port[dev], fm_port[dev] + 2,
+ OPL3_HW_AUTO, 0, &opl3) < 0) {
+ snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
+ fm_port[dev], fm_port[dev] + 2);
+ } else {
+ if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ }
+ }
+
+ if ((error = snd_card_register(card)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ pnp_set_card_drvdata(pcard, card);
+ return 0;
+}
+
+static int __devinit snd_als100_pnp_detect(struct pnp_card_link *card,
+ const struct pnp_card_device_id *id)
+{
+ static int dev;
+ int res;
+
+ for ( ; dev < SNDRV_CARDS; dev++) {
+ if (!enable[dev])
+ continue;
+ res = snd_card_als100_probe(dev, card, id);
+ if (res < 0)
+ return res;
+ dev++;
+ return 0;
+ }
+ return -ENODEV;
+}
+
+static void __devexit snd_als100_pnp_remove(struct pnp_card_link * pcard)
+{
+ snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
+
+ snd_card_disconnect(card);
+ snd_card_free_in_thread(card);
+}
+
+static struct pnp_card_driver als100_pnpc_driver = {
+ .flags = PNP_DRIVER_RES_DISABLE,
+ .name = "als100",
+ .id_table = snd_als100_pnpids,
+ .probe = snd_als100_pnp_detect,
+ .remove = __devexit_p(snd_als100_pnp_remove),
+};
+
+static int __init alsa_card_als100_init(void)
+{
+ int cards = 0;
+
+ cards += pnp_register_card_driver(&als100_pnpc_driver);
+#ifdef MODULE
+ if (!cards) {
+ pnp_unregister_card_driver(&als100_pnpc_driver);
+ snd_printk(KERN_ERR "no ALS100 based soundcards found\n");
+ }
+#endif
+ return cards ? 0 : -ENODEV;
+}
+
+static void __exit alsa_card_als100_exit(void)
+{
+ pnp_unregister_card_driver(&als100_pnpc_driver);
+}
+
+module_init(alsa_card_als100_init)
+module_exit(alsa_card_als100_exit)
diff --git a/sound/isa/azt2320.c b/sound/isa/azt2320.c
new file mode 100644
index 000000000000..bb41c6ec2f43
--- /dev/null
+++ b/sound/isa/azt2320.c
@@ -0,0 +1,366 @@
+/*
+ card-azt2320.c - driver for Aztech Systems AZT2320 based soundcards.
+ Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/*
+ This driver should provide support for most Aztech AZT2320 based cards.
+ Several AZT2316 chips are also supported/tested, but autoprobe doesn't
+ work: all module option have to be set.
+
+ No docs available for us at Aztech headquarters !!! Unbelievable ...
+ No other help obtained.
+
+ Thanks to Rainer Wiesner <rainer.wiesner@01019freenet.de> for the WSS
+ activation method (full-duplex audio!).
+*/
+
+#include <sound/driver.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/time.h>
+#include <linux/wait.h>
+#include <linux/pnp.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/initval.h>
+#include <sound/cs4231.h>
+#include <sound/mpu401.h>
+#include <sound/opl3.h>
+
+#define PFX "azt2320: "
+
+MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
+MODULE_DESCRIPTION("Aztech Systems AZT2320");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{Aztech Systems,PRO16V},"
+ "{Aztech Systems,AZT2320},"
+ "{Aztech Systems,AZT3300},"
+ "{Aztech Systems,AZT2320},"
+ "{Aztech Systems,AZT3000}}");
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
+static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static long wss_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
+static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
+static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
+static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for azt2320 based soundcard.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for azt2320 based soundcard.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable azt2320 based soundcard.");
+module_param_array(port, long, NULL, 0444);
+MODULE_PARM_DESC(port, "Port # for azt2320 driver.");
+module_param_array(wss_port, long, NULL, 0444);
+MODULE_PARM_DESC(wss_port, "WSS Port # for azt2320 driver.");
+module_param_array(mpu_port, long, NULL, 0444);
+MODULE_PARM_DESC(mpu_port, "MPU-401 port # for azt2320 driver.");
+module_param_array(fm_port, long, NULL, 0444);
+MODULE_PARM_DESC(fm_port, "FM port # for azt2320 driver.");
+module_param_array(irq, int, NULL, 0444);
+MODULE_PARM_DESC(irq, "IRQ # for azt2320 driver.");
+module_param_array(mpu_irq, int, NULL, 0444);
+MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for azt2320 driver.");
+module_param_array(dma1, int, NULL, 0444);
+MODULE_PARM_DESC(dma1, "1st DMA # for azt2320 driver.");
+module_param_array(dma2, int, NULL, 0444);
+MODULE_PARM_DESC(dma2, "2nd DMA # for azt2320 driver.");
+
+struct snd_card_azt2320 {
+ int dev_no;
+ struct pnp_dev *dev;
+ struct pnp_dev *devmpu;
+};
+
+static struct pnp_card_device_id snd_azt2320_pnpids[] = {
+ /* PRO16V */
+ { .id = "AZT1008", .devs = { { "AZT1008" }, { "AZT2001" }, } },
+ /* Aztech Sound Galaxy 16 */
+ { .id = "AZT2320", .devs = { { "AZT0001" }, { "AZT0002" }, } },
+ /* Packard Bell Sound III 336 AM/SP */
+ { .id = "AZT3000", .devs = { { "AZT1003" }, { "AZT2001" }, } },
+ /* AT3300 */
+ { .id = "AZT3002", .devs = { { "AZT1004" }, { "AZT2001" }, } },
+ /* --- */
+ { .id = "AZT3005", .devs = { { "AZT1003" }, { "AZT2001" }, } },
+ /* --- */
+ { .id = "AZT3011", .devs = { { "AZT1003" }, { "AZT2001" }, } },
+ { .id = "" } /* end */
+};
+
+MODULE_DEVICE_TABLE(pnp_card, snd_azt2320_pnpids);
+
+#define DRIVER_NAME "snd-card-azt2320"
+
+static int __devinit snd_card_azt2320_pnp(int dev, struct snd_card_azt2320 *acard,
+ struct pnp_card_link *card,
+ const struct pnp_card_device_id *id)
+{
+ struct pnp_dev *pdev;
+ struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
+ int err;
+
+ if (!cfg)
+ return -ENOMEM;
+
+ acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
+ if (acard->dev == NULL) {
+ kfree(cfg);
+ return -ENODEV;
+ }
+
+ acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
+
+ pdev = acard->dev;
+ pnp_init_resource_table(cfg);
+
+ /* override resources */
+ if (port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
+ if (fm_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
+ if (wss_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[2], wss_port[dev], 4);
+ if (dma1[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
+ if (dma2[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
+ if (irq[dev] != SNDRV_AUTO_IRQ)
+ pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
+ if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
+ snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
+
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
+ kfree(cfg);
+ return err;
+ }
+ port[dev] = pnp_port_start(pdev, 0);
+ fm_port[dev] = pnp_port_start(pdev, 1);
+ wss_port[dev] = pnp_port_start(pdev, 2);
+ dma1[dev] = pnp_dma(pdev, 0);
+ dma2[dev] = pnp_dma(pdev, 1);
+ irq[dev] = pnp_irq(pdev, 0);
+
+ pdev = acard->devmpu;
+ if (pdev != NULL) {
+ pnp_init_resource_table(cfg);
+ if (mpu_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
+ if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
+ pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
+ if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
+ snd_printk(KERN_ERR PFX "MPU401 the requested resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0)
+ goto __mpu_error;
+ mpu_port[dev] = pnp_port_start(pdev, 0);
+ mpu_irq[dev] = pnp_irq(pdev, 0);
+ } else {
+ __mpu_error:
+ if (pdev) {
+ pnp_release_card_device(pdev);
+ snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
+ }
+ acard->devmpu = NULL;
+ mpu_port[dev] = -1;
+ }
+
+ kfree (cfg);
+ return 0;
+}
+
+/* same of snd_sbdsp_command by Jaroslav Kysela */
+static int __devinit snd_card_azt2320_command(unsigned long port, unsigned char val)
+{
+ int i;
+ unsigned long limit;
+
+ limit = jiffies + HZ / 10;
+ for (i = 50000; i && time_after(limit, jiffies); i--)
+ if (!(inb(port + 0x0c) & 0x80)) {
+ outb(val, port + 0x0c);
+ return 0;
+ }
+ return -EBUSY;
+}
+
+static int __devinit snd_card_azt2320_enable_wss(unsigned long port)
+{
+ int error;
+
+ if ((error = snd_card_azt2320_command(port, 0x09)))
+ return error;
+ if ((error = snd_card_azt2320_command(port, 0x00)))
+ return error;
+
+ mdelay(5);
+ return 0;
+}
+
+static int __devinit snd_card_azt2320_probe(int dev,
+ struct pnp_card_link *pcard,
+ const struct pnp_card_device_id *pid)
+{
+ int error;
+ snd_card_t *card;
+ struct snd_card_azt2320 *acard;
+ cs4231_t *chip;
+ opl3_t *opl3;
+
+ if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
+ sizeof(struct snd_card_azt2320))) == NULL)
+ return -ENOMEM;
+ acard = (struct snd_card_azt2320 *)card->private_data;
+
+ if ((error = snd_card_azt2320_pnp(dev, acard, pcard, pid))) {
+ snd_card_free(card);
+ return error;
+ }
+ snd_card_set_dev(card, &pcard->card->dev);
+
+ if ((error = snd_card_azt2320_enable_wss(port[dev]))) {
+ snd_card_free(card);
+ return error;
+ }
+
+ if ((error = snd_cs4231_create(card, wss_port[dev], -1,
+ irq[dev],
+ dma1[dev],
+ dma2[dev],
+ CS4231_HW_DETECT, 0, &chip)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+
+ strcpy(card->driver, "AZT2320");
+ strcpy(card->shortname, "Aztech AZT2320");
+ sprintf(card->longname, "%s, WSS at 0x%lx, irq %i, dma %i&%i",
+ card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
+
+ if ((error = snd_cs4231_pcm(chip, 0, NULL)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ if ((error = snd_cs4231_mixer(chip)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ if ((error = snd_cs4231_timer(chip, 0, NULL)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+
+ if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
+ if (snd_mpu401_uart_new(card, 0, MPU401_HW_AZT2320,
+ mpu_port[dev], 0,
+ mpu_irq[dev], SA_INTERRUPT,
+ NULL) < 0)
+ snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
+ }
+
+ if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
+ if (snd_opl3_create(card,
+ fm_port[dev], fm_port[dev] + 2,
+ OPL3_HW_AUTO, 0, &opl3) < 0) {
+ snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
+ fm_port[dev], fm_port[dev] + 2);
+ } else {
+ if ((error = snd_opl3_timer_new(opl3, 1, 2)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ }
+ }
+
+ if ((error = snd_card_register(card)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ pnp_set_card_drvdata(pcard, card);
+ return 0;
+}
+
+static int __devinit snd_azt2320_pnp_detect(struct pnp_card_link *card,
+ const struct pnp_card_device_id *id)
+{
+ static int dev;
+ int res;
+
+ for ( ; dev < SNDRV_CARDS; dev++) {
+ if (!enable[dev])
+ continue;
+ res = snd_card_azt2320_probe(dev, card, id);
+ if (res < 0)
+ return res;
+ dev++;
+ return 0;
+ }
+ return -ENODEV;
+}
+
+static void __devexit snd_azt2320_pnp_remove(struct pnp_card_link * pcard)
+{
+ snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
+
+ snd_card_disconnect(card);
+ snd_card_free_in_thread(card);
+}
+
+static struct pnp_card_driver azt2320_pnpc_driver = {
+ .flags = PNP_DRIVER_RES_DISABLE,
+ .name = "azt2320",
+ .id_table = snd_azt2320_pnpids,
+ .probe = snd_azt2320_pnp_detect,
+ .remove = __devexit_p(snd_azt2320_pnp_remove),
+};
+
+static int __init alsa_card_azt2320_init(void)
+{
+ int cards = 0;
+
+ cards += pnp_register_card_driver(&azt2320_pnpc_driver);
+#ifdef MODULE
+ if (!cards) {
+ pnp_unregister_card_driver(&azt2320_pnpc_driver);
+ snd_printk(KERN_ERR "no AZT2320 based soundcards found\n");
+ }
+#endif
+ return cards ? 0 : -ENODEV;
+}
+
+static void __exit alsa_card_azt2320_exit(void)
+{
+ pnp_unregister_card_driver(&azt2320_pnpc_driver);
+}
+
+module_init(alsa_card_azt2320_init)
+module_exit(alsa_card_azt2320_exit)
diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
new file mode 100644
index 000000000000..46776cc0c157
--- /dev/null
+++ b/sound/isa/cmi8330.c
@@ -0,0 +1,633 @@
+/*
+ * Driver for C-Media's CMI8330 soundcards.
+ * Copyright (c) by George Talusan <gstalusan@uwaterloo.ca>
+ * http://www.undergrad.math.uwaterloo.ca/~gstalusa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*
+ * NOTES
+ *
+ * The extended registers contain mixer settings which are largely
+ * untapped for the time being.
+ *
+ * MPU401 and SPDIF are not supported yet. I don't have the hardware
+ * to aid in coding and testing, so I won't bother.
+ *
+ * To quickly load the module,
+ *
+ * modprobe -a snd-cmi8330 sbport=0x220 sbirq=5 sbdma8=1
+ * sbdma16=5 wssport=0x530 wssirq=11 wssdma=0
+ *
+ * This card has two mixers and two PCM devices. I've cheesed it such
+ * that recording and playback can be done through the same device.
+ * The driver "magically" routes the capturing to the AD1848 codec,
+ * and playback to the SB16 codec. This allows for full-duplex mode
+ * to some extent.
+ * The utilities in alsa-utils are aware of both devices, so passing
+ * the appropriate parameters to amixer and alsactl will give you
+ * full control over both mixers.
+ */
+
+#include <sound/driver.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/pnp.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/ad1848.h>
+#include <sound/sb.h>
+#include <sound/initval.h>
+
+/*
+ */
+/* #define ENABLE_SB_MIXER */
+#define PLAYBACK_ON_SB
+
+/*
+ */
+MODULE_AUTHOR("George Talusan <gstalusan@uwaterloo.ca>");
+MODULE_DESCRIPTION("C-Media CMI8330");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{C-Media,CMI8330,isapnp:{CMI0001,@@@0001,@X@0001}}}");
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP;
+#ifdef CONFIG_PNP
+static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
+#endif
+static long sbport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
+static int sbirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
+static int sbdma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
+static int sbdma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
+static long wssport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
+static int wssirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
+static int wssdma[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for CMI8330 soundcard.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for CMI8330 soundcard.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable CMI8330 soundcard.");
+#ifdef CONFIG_PNP
+module_param_array(isapnp, bool, NULL, 0444);
+MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
+#endif
+
+module_param_array(sbport, long, NULL, 0444);
+MODULE_PARM_DESC(sbport, "Port # for CMI8330 SB driver.");
+module_param_array(sbirq, int, NULL, 0444);
+MODULE_PARM_DESC(sbirq, "IRQ # for CMI8330 SB driver.");
+module_param_array(sbdma8, int, NULL, 0444);
+MODULE_PARM_DESC(sbdma8, "DMA8 for CMI8330 SB driver.");
+module_param_array(sbdma16, int, NULL, 0444);
+MODULE_PARM_DESC(sbdma16, "DMA16 for CMI8330 SB driver.");
+
+module_param_array(wssport, long, NULL, 0444);
+MODULE_PARM_DESC(wssport, "Port # for CMI8330 WSS driver.");
+module_param_array(wssirq, int, NULL, 0444);
+MODULE_PARM_DESC(wssirq, "IRQ # for CMI8330 WSS driver.");
+module_param_array(wssdma, int, NULL, 0444);
+MODULE_PARM_DESC(wssdma, "DMA for CMI8330 WSS driver.");
+
+#define CMI8330_RMUX3D 16
+#define CMI8330_MUTEMUX 17
+#define CMI8330_OUTPUTVOL 18
+#define CMI8330_MASTVOL 19
+#define CMI8330_LINVOL 20
+#define CMI8330_CDINVOL 21
+#define CMI8330_WAVVOL 22
+#define CMI8330_RECMUX 23
+#define CMI8330_WAVGAIN 24
+#define CMI8330_LINGAIN 25
+#define CMI8330_CDINGAIN 26
+
+static unsigned char snd_cmi8330_image[((CMI8330_CDINGAIN)-16) + 1] =
+{
+ 0x40, /* 16 - recording mux (SB-mixer-enabled) */
+#ifdef ENABLE_SB_MIXER
+ 0x40, /* 17 - mute mux (Mode2) */
+#else
+ 0x0, /* 17 - mute mux */
+#endif
+ 0x0, /* 18 - vol */
+ 0x0, /* 19 - master volume */
+ 0x0, /* 20 - line-in volume */
+ 0x0, /* 21 - cd-in volume */
+ 0x0, /* 22 - wave volume */
+ 0x0, /* 23 - mute/rec mux */
+ 0x0, /* 24 - wave rec gain */
+ 0x0, /* 25 - line-in rec gain */
+ 0x0 /* 26 - cd-in rec gain */
+};
+
+typedef int (*snd_pcm_open_callback_t)(snd_pcm_substream_t *);
+
+struct snd_cmi8330 {
+#ifdef CONFIG_PNP
+ struct pnp_dev *cap;
+ struct pnp_dev *play;
+#endif
+ snd_card_t *card;
+ ad1848_t *wss;
+ sb_t *sb;
+
+ snd_pcm_t *pcm;
+ struct snd_cmi8330_stream {
+ snd_pcm_ops_t ops;
+ snd_pcm_open_callback_t open;
+ void *private_data; /* sb or wss */
+ } streams[2];
+};
+
+static snd_card_t *snd_cmi8330_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
+
+#ifdef CONFIG_PNP
+
+static struct pnp_card_device_id snd_cmi8330_pnpids[] = {
+ { .id = "CMI0001", .devs = { { "@@@0001" }, { "@X@0001" } } },
+ { .id = "" }
+};
+
+MODULE_DEVICE_TABLE(pnp_card, snd_cmi8330_pnpids);
+
+#endif
+
+
+static struct ad1848_mix_elem snd_cmi8330_controls[] __initdata = {
+AD1848_DOUBLE("Master Playback Volume", 0, CMI8330_MASTVOL, CMI8330_MASTVOL, 4, 0, 15, 0),
+AD1848_SINGLE("Loud Playback Switch", 0, CMI8330_MUTEMUX, 6, 1, 1),
+AD1848_DOUBLE("PCM Playback Switch", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 7, 7, 1, 1),
+AD1848_DOUBLE("PCM Playback Volume", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 0, 0, 63, 1),
+AD1848_DOUBLE("Line Playback Switch", 0, CMI8330_MUTEMUX, CMI8330_MUTEMUX, 4, 3, 1, 0),
+AD1848_DOUBLE("Line Playback Volume", 0, CMI8330_LINVOL, CMI8330_LINVOL, 4, 0, 15, 0),
+AD1848_DOUBLE("Line Capture Switch", 0, CMI8330_RMUX3D, CMI8330_RMUX3D, 2, 1, 1, 0),
+AD1848_DOUBLE("Line Capture Volume", 0, CMI8330_LINGAIN, CMI8330_LINGAIN, 4, 0, 15, 0),
+AD1848_DOUBLE("CD Playback Switch", 0, CMI8330_MUTEMUX, CMI8330_MUTEMUX, 2, 1, 1, 0),
+AD1848_DOUBLE("CD Capture Switch", 0, CMI8330_RMUX3D, CMI8330_RMUX3D, 4, 3, 1, 0),
+AD1848_DOUBLE("CD Playback Volume", 0, CMI8330_CDINVOL, CMI8330_CDINVOL, 4, 0, 15, 0),
+AD1848_DOUBLE("CD Capture Volume", 0, CMI8330_CDINGAIN, CMI8330_CDINGAIN, 4, 0, 15, 0),
+AD1848_SINGLE("Mic Playback Switch", 0, CMI8330_MUTEMUX, 0, 1, 0),
+AD1848_SINGLE("Mic Playback Volume", 0, CMI8330_OUTPUTVOL, 0, 7, 0),
+AD1848_SINGLE("Mic Capture Switch", 0, CMI8330_RMUX3D, 0, 1, 0),
+AD1848_SINGLE("Mic Capture Volume", 0, CMI8330_OUTPUTVOL, 5, 7, 0),
+AD1848_DOUBLE("Wavetable Playback Switch", 0, CMI8330_RECMUX, CMI8330_RECMUX, 1, 0, 1, 0),
+AD1848_DOUBLE("Wavetable Playback Volume", 0, CMI8330_WAVVOL, CMI8330_WAVVOL, 4, 0, 15, 0),
+AD1848_DOUBLE("Wavetable Capture Switch", 0, CMI8330_RECMUX, CMI8330_RECMUX, 5, 4, 1, 0),
+AD1848_DOUBLE("Wavetable Capture Volume", 0, CMI8330_WAVGAIN, CMI8330_WAVGAIN, 4, 0, 15, 0),
+AD1848_SINGLE("3D Control - Switch", 0, CMI8330_RMUX3D, 5, 1, 1),
+AD1848_SINGLE("PC Speaker Playback Volume", 0, CMI8330_OUTPUTVOL, 3, 3, 0),
+AD1848_SINGLE("FM Playback Switch", 0, CMI8330_RECMUX, 3, 1, 1),
+AD1848_SINGLE("IEC958 Input Capture Switch", 0, CMI8330_RMUX3D, 7, 1, 1),
+AD1848_SINGLE("IEC958 Input Playback Switch", 0, CMI8330_MUTEMUX, 7, 1, 1),
+};
+
+#ifdef ENABLE_SB_MIXER
+static struct sbmix_elem cmi8330_sb_mixers[] __initdata = {
+SB_DOUBLE("SB Master Playback Volume", SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31),
+SB_DOUBLE("Tone Control - Bass", SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15),
+SB_DOUBLE("Tone Control - Treble", SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15),
+SB_DOUBLE("SB PCM Playback Volume", SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31),
+SB_DOUBLE("SB Synth Playback Volume", SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31),
+SB_DOUBLE("SB CD Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1),
+SB_DOUBLE("SB CD Playback Volume", SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31),
+SB_DOUBLE("SB Line Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1),
+SB_DOUBLE("SB Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31),
+SB_SINGLE("SB Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1),
+SB_SINGLE("SB Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31),
+SB_SINGLE("SB PC Speaker Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
+SB_DOUBLE("SB Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3),
+SB_DOUBLE("SB Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3),
+SB_SINGLE("SB Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1),
+};
+
+static unsigned char cmi8330_sb_init_values[][2] __initdata = {
+ { SB_DSP4_MASTER_DEV + 0, 0 },
+ { SB_DSP4_MASTER_DEV + 1, 0 },
+ { SB_DSP4_PCM_DEV + 0, 0 },
+ { SB_DSP4_PCM_DEV + 1, 0 },
+ { SB_DSP4_SYNTH_DEV + 0, 0 },
+ { SB_DSP4_SYNTH_DEV + 1, 0 },
+ { SB_DSP4_INPUT_LEFT, 0 },
+ { SB_DSP4_INPUT_RIGHT, 0 },
+ { SB_DSP4_OUTPUT_SW, 0 },
+ { SB_DSP4_SPEAKER_DEV, 0 },
+};
+
+
+static int __devinit cmi8330_add_sb_mixers(sb_t *chip)
+{
+ int idx, err;
+ unsigned long flags;
+
+ spin_lock_irqsave(&chip->mixer_lock, flags);
+ snd_sbmixer_write(chip, 0x00, 0x00); /* mixer reset */
+ spin_unlock_irqrestore(&chip->mixer_lock, flags);
+
+ /* mute and zero volume channels */
+ for (idx = 0; idx < ARRAY_SIZE(cmi8330_sb_init_values); idx++) {
+ spin_lock_irqsave(&chip->mixer_lock, flags);
+ snd_sbmixer_write(chip, cmi8330_sb_init_values[idx][0],
+ cmi8330_sb_init_values[idx][1]);
+ spin_unlock_irqrestore(&chip->mixer_lock, flags);
+ }
+
+ for (idx = 0; idx < ARRAY_SIZE(cmi8330_sb_mixers); idx++) {
+ if ((err = snd_sbmixer_add_ctl_elem(chip, &cmi8330_sb_mixers[idx])) < 0)
+ return err;
+ }
+ return 0;
+}
+#endif
+
+static int __devinit snd_cmi8330_mixer(snd_card_t *card, struct snd_cmi8330 *acard)
+{
+ unsigned int idx;
+ int err;
+
+ strcpy(card->mixername, "CMI8330/C3D");
+
+ for (idx = 0; idx < ARRAY_SIZE(snd_cmi8330_controls); idx++) {
+ if ((err = snd_ad1848_add_ctl_elem(acard->wss, &snd_cmi8330_controls[idx])) < 0)
+ return err;
+ }
+
+#ifdef ENABLE_SB_MIXER
+ if ((err = cmi8330_add_sb_mixers(acard->sb)) < 0)
+ return err;
+#endif
+ return 0;
+}
+
+#ifdef CONFIG_PNP
+static int __devinit snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard,
+ struct pnp_card_link *card,
+ const struct pnp_card_device_id *id)
+{
+ struct pnp_dev *pdev;
+ struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
+ int err;
+
+ acard->cap = pnp_request_card_device(card, id->devs[0].id, NULL);
+ if (acard->cap == NULL) {
+ kfree(cfg);
+ return -EBUSY;
+ }
+ acard->play = pnp_request_card_device(card, id->devs[1].id, NULL);
+ if (acard->play == NULL) {
+ kfree(cfg);
+ return -EBUSY;
+ }
+
+ pdev = acard->cap;
+ pnp_init_resource_table(cfg);
+ /* allocate AD1848 resources */
+ if (wssport[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], wssport[dev], 8);
+ if (wssdma[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[0], wssdma[dev], 1);
+ if (wssirq[dev] != SNDRV_AUTO_IRQ)
+ pnp_resource_change(&cfg->irq_resource[0], wssirq[dev], 1);
+
+ err = pnp_manual_config_dev(pdev, cfg, 0);
+ if (err < 0)
+ snd_printk(KERN_ERR "CMI8330/C3D (AD1848) PnP manual resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ snd_printk(KERN_ERR "CMI8330/C3D (AD1848) PnP configure failure\n");
+ kfree(cfg);
+ return -EBUSY;
+ }
+ wssport[dev] = pnp_port_start(pdev, 0);
+ wssdma[dev] = pnp_dma(pdev, 0);
+ wssirq[dev] = pnp_irq(pdev, 0);
+
+ /* allocate SB16 resources */
+ pdev = acard->play;
+ pnp_init_resource_table(cfg);
+ if (sbport[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], sbport[dev], 16);
+ if (sbdma8[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[0], sbdma8[dev], 1);
+ if (sbdma16[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[1], sbdma16[dev], 1);
+ if (sbirq[dev] != SNDRV_AUTO_IRQ)
+ pnp_resource_change(&cfg->irq_resource[0], sbirq[dev], 1);
+
+ err = pnp_manual_config_dev(pdev, cfg, 0);
+ if (err < 0)
+ snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP manual resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP configure failure\n");
+ kfree(cfg);
+ return -EBUSY;
+ }
+ sbport[dev] = pnp_port_start(pdev, 0);
+ sbdma8[dev] = pnp_dma(pdev, 0);
+ sbdma16[dev] = pnp_dma(pdev, 1);
+ sbirq[dev] = pnp_irq(pdev, 0);
+
+ kfree(cfg);
+ return 0;
+}
+#endif
+
+/*
+ * PCM interface
+ *
+ * since we call the different chip interfaces for playback and capture
+ * directions, we need a trick.
+ *
+ * - copy the ops for each direction into a local record.
+ * - replace the open callback with the new one, which replaces the
+ * substream->private_data with the corresponding chip instance
+ * and calls again the original open callback of the chip.
+ *
+ */
+
+#ifdef PLAYBACK_ON_SB
+#define CMI_SB_STREAM SNDRV_PCM_STREAM_PLAYBACK
+#define CMI_AD_STREAM SNDRV_PCM_STREAM_CAPTURE
+#else
+#define CMI_SB_STREAM SNDRV_PCM_STREAM_CAPTURE
+#define CMI_AD_STREAM SNDRV_PCM_STREAM_PLAYBACK
+#endif
+
+static int snd_cmi8330_playback_open(snd_pcm_substream_t * substream)
+{
+ struct snd_cmi8330 *chip = snd_pcm_substream_chip(substream);
+
+ /* replace the private_data and call the original open callback */
+ substream->private_data = chip->streams[SNDRV_PCM_STREAM_PLAYBACK].private_data;
+ return chip->streams[SNDRV_PCM_STREAM_PLAYBACK].open(substream);
+}
+
+static int snd_cmi8330_capture_open(snd_pcm_substream_t * substream)
+{
+ struct snd_cmi8330 *chip = snd_pcm_substream_chip(substream);
+
+ /* replace the private_data and call the original open callback */
+ substream->private_data = chip->streams[SNDRV_PCM_STREAM_CAPTURE].private_data;
+ return chip->streams[SNDRV_PCM_STREAM_CAPTURE].open(substream);
+}
+
+static void snd_cmi8330_pcm_free(snd_pcm_t *pcm)
+{
+ snd_pcm_lib_preallocate_free_for_all(pcm);
+}
+
+static int __devinit snd_cmi8330_pcm(snd_card_t *card, struct snd_cmi8330 *chip)
+{
+ snd_pcm_t *pcm;
+ const snd_pcm_ops_t *ops;
+ int err;
+ static snd_pcm_open_callback_t cmi_open_callbacks[2] = {
+ snd_cmi8330_playback_open,
+ snd_cmi8330_capture_open
+ };
+
+ if ((err = snd_pcm_new(card, "CMI8330", 0, 1, 1, &pcm)) < 0)
+ return err;
+ strcpy(pcm->name, "CMI8330");
+ pcm->private_data = chip;
+ pcm->private_free = snd_cmi8330_pcm_free;
+
+ /* SB16 */
+ ops = snd_sb16dsp_get_pcm_ops(CMI_SB_STREAM);
+ chip->streams[CMI_SB_STREAM].ops = *ops;
+ chip->streams[CMI_SB_STREAM].open = ops->open;
+ chip->streams[CMI_SB_STREAM].ops.open = cmi_open_callbacks[CMI_SB_STREAM];
+ chip->streams[CMI_SB_STREAM].private_data = chip->sb;
+
+ /* AD1848 */
+ ops = snd_ad1848_get_pcm_ops(CMI_AD_STREAM);
+ chip->streams[CMI_AD_STREAM].ops = *ops;
+ chip->streams[CMI_AD_STREAM].open = ops->open;
+ chip->streams[CMI_AD_STREAM].ops.open = cmi_open_callbacks[CMI_AD_STREAM];
+ chip->streams[CMI_AD_STREAM].private_data = chip->wss;
+
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &chip->streams[SNDRV_PCM_STREAM_PLAYBACK].ops);
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &chip->streams[SNDRV_PCM_STREAM_CAPTURE].ops);
+
+ snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
+ snd_dma_isa_data(),
+ 64*1024, 128*1024);
+ chip->pcm = pcm;
+
+ return 0;
+}
+
+
+/*
+ */
+
+static int __devinit snd_cmi8330_probe(int dev,
+ struct pnp_card_link *pcard,
+ const struct pnp_card_device_id *pid)
+{
+ snd_card_t *card;
+ struct snd_cmi8330 *acard;
+ unsigned long flags;
+ int i, err;
+
+#ifdef CONFIG_PNP
+ if (!isapnp[dev]) {
+#endif
+ if (wssport[dev] == SNDRV_AUTO_PORT) {
+ snd_printk("specify wssport\n");
+ return -EINVAL;
+ }
+ if (sbport[dev] == SNDRV_AUTO_PORT) {
+ snd_printk("specify sbport\n");
+ return -EINVAL;
+ }
+#ifdef CONFIG_PNP
+ }
+#endif
+ card = snd_card_new(index[dev], id[dev], THIS_MODULE,
+ sizeof(struct snd_cmi8330));
+ if (card == NULL) {
+ snd_printk("could not get a new card\n");
+ return -ENOMEM;
+ }
+ acard = (struct snd_cmi8330 *)card->private_data;
+ acard->card = card;
+
+#ifdef CONFIG_PNP
+ if (isapnp[dev]) {
+ if ((err = snd_cmi8330_pnp(dev, acard, pcard, pid)) < 0) {
+ snd_printk("PnP detection failed\n");
+ snd_card_free(card);
+ return err;
+ }
+ snd_card_set_dev(card, &pcard->card->dev);
+ }
+#endif
+
+ if ((err = snd_ad1848_create(card,
+ wssport[dev] + 4,
+ wssirq[dev],
+ wssdma[dev],
+ AD1848_HW_DETECT,
+ &acard->wss)) < 0) {
+ snd_printk("(AD1848) device busy??\n");
+ snd_card_free(card);
+ return err;
+ }
+ if (acard->wss->hardware != AD1848_HW_CMI8330) {
+ snd_printk("(AD1848) not found during probe\n");
+ snd_card_free(card);
+ return -ENODEV;
+ }
+
+ if ((err = snd_sbdsp_create(card, sbport[dev],
+ sbirq[dev],
+ snd_sb16dsp_interrupt,
+ sbdma8[dev],
+ sbdma16[dev],
+ SB_HW_AUTO, &acard->sb)) < 0) {
+ snd_printk("(SB16) device busy??\n");
+ snd_card_free(card);
+ return err;
+ }
+ if (acard->sb->hardware != SB_HW_16) {
+ snd_printk("(SB16) not found during probe\n");
+ snd_card_free(card);
+ return -ENODEV;
+ }
+
+ spin_lock_irqsave(&acard->wss->reg_lock, flags);
+ snd_ad1848_out(acard->wss, AD1848_MISC_INFO, 0x40); /* switch on MODE2 */
+ for (i = CMI8330_RMUX3D; i <= CMI8330_CDINGAIN; i++)
+ snd_ad1848_out(acard->wss, i, snd_cmi8330_image[i - CMI8330_RMUX3D]);
+ spin_unlock_irqrestore(&acard->wss->reg_lock, flags);
+
+ if ((err = snd_cmi8330_mixer(card, acard)) < 0) {
+ snd_printk("failed to create mixers\n");
+ snd_card_free(card);
+ return err;
+ }
+
+ if ((err = snd_cmi8330_pcm(card, acard)) < 0) {
+ snd_printk("failed to create pcms\n");
+ snd_card_free(card);
+ return err;
+ }
+
+ strcpy(card->driver, "CMI8330/C3D");
+ strcpy(card->shortname, "C-Media CMI8330/C3D");
+ sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
+ card->shortname,
+ acard->wss->port,
+ wssirq[dev],
+ wssdma[dev]);
+
+ if ((err = snd_card_register(card)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+
+ if (pcard)
+ pnp_set_card_drvdata(pcard, card);
+ else
+ snd_cmi8330_legacy[dev] = card;
+ return 0;
+}
+
+#ifdef CONFIG_PNP
+static int __devinit snd_cmi8330_pnp_detect(struct pnp_card_link *card,
+ const struct pnp_card_device_id *id)
+{
+ static int dev;
+ int res;
+
+ for ( ; dev < SNDRV_CARDS; dev++) {
+ if (!enable[dev] || !isapnp[dev])
+ continue;
+ res = snd_cmi8330_probe(dev, card, id);
+ if (res < 0)
+ return res;
+ dev++;
+ return 0;
+ }
+ return -ENODEV;
+}
+
+static void __devexit snd_cmi8330_pnp_remove(struct pnp_card_link * pcard)
+{
+ snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
+
+ snd_card_disconnect(card);
+ snd_card_free_in_thread(card);
+}
+
+static struct pnp_card_driver cmi8330_pnpc_driver = {
+ .flags = PNP_DRIVER_RES_DISABLE,
+ .name = "cmi8330",
+ .id_table = snd_cmi8330_pnpids,
+ .probe = snd_cmi8330_pnp_detect,
+ .remove = __devexit_p(snd_cmi8330_pnp_remove),
+};
+#endif /* CONFIG_PNP */
+
+static int __init alsa_card_cmi8330_init(void)
+{
+ int dev, cards = 0;
+
+ for (dev = 0; dev < SNDRV_CARDS; dev++) {
+ if (!enable[dev])
+ continue;
+#ifdef CONFIG_PNP
+ if (isapnp[dev])
+ continue;
+#endif
+ if (snd_cmi8330_probe(dev, NULL, NULL) >= 0)
+ cards++;
+ }
+#ifdef CONFIG_PNP
+ cards += pnp_register_card_driver(&cmi8330_pnpc_driver);
+#endif
+
+ if (!cards) {
+#ifdef CONFIG_PNP
+ pnp_unregister_card_driver(&cmi8330_pnpc_driver);
+#endif
+#ifdef MODULE
+ snd_printk(KERN_ERR "CMI8330 not found or device busy\n");
+#endif
+ return -ENODEV;
+ }
+ return 0;
+}
+
+static void __exit alsa_card_cmi8330_exit(void)
+{
+ int i;
+
+#ifdef CONFIG_PNP
+ /* PnP cards first */
+ pnp_unregister_card_driver(&cmi8330_pnpc_driver);
+#endif
+ for (i = 0; i < SNDRV_CARDS; i++)
+ snd_card_free(snd_cmi8330_legacy[i]);
+}
+
+module_init(alsa_card_cmi8330_init)
+module_exit(alsa_card_cmi8330_exit)
diff --git a/sound/isa/cs423x/Makefile b/sound/isa/cs423x/Makefile
new file mode 100644
index 000000000000..d2afaea30cbc
--- /dev/null
+++ b/sound/isa/cs423x/Makefile
@@ -0,0 +1,25 @@
+#
+# Makefile for ALSA
+# Copyright (c) 2001 by Jaroslav Kysela <perex@suse.cz>
+#
+
+snd-cs4231-lib-objs := cs4231_lib.o
+snd-cs4236-lib-objs := cs4236_lib.o
+snd-cs4231-objs := cs4231.o
+snd-cs4232-objs := cs4232.o
+snd-cs4236-objs := cs4236.o
+
+# Toplevel Module Dependency
+obj-$(CONFIG_SND_AZT2320) += snd-cs4231-lib.o
+obj-$(CONFIG_SND_OPL3SA2) += snd-cs4231-lib.o
+obj-$(CONFIG_SND_CS4231) += snd-cs4231.o snd-cs4231-lib.o
+obj-$(CONFIG_SND_CS4232) += snd-cs4232.o snd-cs4231-lib.o
+obj-$(CONFIG_SND_CS4236) += snd-cs4236.o snd-cs4236-lib.o snd-cs4231-lib.o
+obj-$(CONFIG_SND_GUSMAX) += snd-cs4231-lib.o
+obj-$(CONFIG_SND_INTERWAVE) += snd-cs4231-lib.o
+obj-$(CONFIG_SND_INTERWAVE_STB) += snd-cs4231-lib.o
+obj-$(CONFIG_SND_OPTI92X_CS4231) += snd-cs4231-lib.o
+obj-$(CONFIG_SND_WAVEFRONT) += snd-cs4231-lib.o
+obj-$(CONFIG_SND_SSCAPE) += snd-cs4231-lib.o
+
+obj-m := $(sort $(obj-m))
diff --git a/sound/isa/cs423x/cs4231.c b/sound/isa/cs423x/cs4231.c
new file mode 100644
index 000000000000..7640837659ea
--- /dev/null
+++ b/sound/isa/cs423x/cs4231.c
@@ -0,0 +1,169 @@
+/*
+ * Generic driver for CS4231 chips
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ * Originally the CS4232/CS4232A driver, modified for use on CS4231 by
+ * Tugrul Galatali <galatalt@stuy.edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/init.h>
+#include <linux/time.h>
+#include <linux/wait.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/cs4231.h>
+#include <sound/mpu401.h>
+#include <sound/initval.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("Generic CS4231");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{Crystal Semiconductors,CS4231}}");
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
+static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
+static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
+static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
+static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for CS4231 soundcard.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for CS4231 soundcard.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable CS4231 soundcard.");
+module_param_array(port, long, NULL, 0444);
+MODULE_PARM_DESC(port, "Port # for CS4231 driver.");
+module_param_array(mpu_port, long, NULL, 0444);
+MODULE_PARM_DESC(mpu_port, "MPU-401 port # for CS4231 driver.");
+module_param_array(irq, int, NULL, 0444);
+MODULE_PARM_DESC(irq, "IRQ # for CS4231 driver.");
+module_param_array(mpu_irq, int, NULL, 0444);
+MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for CS4231 driver.");
+module_param_array(dma1, int, NULL, 0444);
+MODULE_PARM_DESC(dma1, "DMA1 # for CS4231 driver.");
+module_param_array(dma2, int, NULL, 0444);
+MODULE_PARM_DESC(dma2, "DMA2 # for CS4231 driver.");
+
+static snd_card_t *snd_cs4231_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
+
+
+static int __init snd_card_cs4231_probe(int dev)
+{
+ snd_card_t *card;
+ struct snd_card_cs4231 *acard;
+ snd_pcm_t *pcm = NULL;
+ cs4231_t *chip;
+ int err;
+
+ if (port[dev] == SNDRV_AUTO_PORT) {
+ snd_printk("specify port\n");
+ return -EINVAL;
+ }
+ if (irq[dev] == SNDRV_AUTO_IRQ) {
+ snd_printk("specify irq\n");
+ return -EINVAL;
+ }
+ if (dma1[dev] == SNDRV_AUTO_DMA) {
+ snd_printk("specify dma1\n");
+ return -EINVAL;
+ }
+ card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
+ if (card == NULL)
+ return -ENOMEM;
+ acard = (struct snd_card_cs4231 *)card->private_data;
+ if ((err = snd_cs4231_create(card, port[dev], -1,
+ irq[dev],
+ dma1[dev],
+ dma2[dev],
+ CS4231_HW_DETECT,
+ 0, &chip)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+
+ if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+
+ strcpy(card->driver, "CS4231");
+ strcpy(card->shortname, pcm->name);
+ sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
+ pcm->name, chip->port, irq[dev], dma1[dev]);
+ if (dma2[dev] >= 0)
+ sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
+
+ if ((err = snd_cs4231_mixer(chip)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+
+ if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
+ if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
+ mpu_irq[dev] = -1;
+ if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
+ mpu_port[dev], 0,
+ mpu_irq[dev],
+ mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0,
+ NULL) < 0)
+ printk(KERN_ERR "cs4231: MPU401 not detected\n");
+ }
+ if ((err = snd_card_register(card)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ snd_cs4231_cards[dev] = card;
+ return 0;
+}
+
+static int __init alsa_card_cs4231_init(void)
+{
+ int dev, cards;
+
+ for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
+ if (snd_card_cs4231_probe(dev) >= 0)
+ cards++;
+ }
+ if (!cards) {
+#ifdef MODULE
+ printk(KERN_ERR "CS4231 soundcard not found or device busy\n");
+#endif
+ return -ENODEV;
+ }
+ return 0;
+}
+
+static void __exit alsa_card_cs4231_exit(void)
+{
+ int idx;
+
+ for (idx = 0; idx < SNDRV_CARDS; idx++)
+ snd_card_free(snd_cs4231_cards[idx]);
+}
+
+module_init(alsa_card_cs4231_init)
+module_exit(alsa_card_cs4231_exit)
diff --git a/sound/isa/cs423x/cs4231_lib.c b/sound/isa/cs423x/cs4231_lib.c
new file mode 100644
index 000000000000..3e7a2a33a5ca
--- /dev/null
+++ b/sound/isa/cs423x/cs4231_lib.c
@@ -0,0 +1,1964 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ * Routines for control of CS4231(A)/CS4232/InterWave & compatible chips
+ *
+ * Bugs:
+ * - sometimes record brokes playback with WSS portion of
+ * Yamaha OPL3-SA3 chip
+ * - CS4231 (GUS MAX) - still trouble with occasional noises
+ * - broken initialization?
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/slab.h>
+#include <linux/ioport.h>
+#include <sound/core.h>
+#include <sound/cs4231.h>
+#include <sound/pcm_params.h>
+
+#include <asm/io.h>
+#include <asm/dma.h>
+#include <asm/irq.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("Routines for control of CS4231(A)/CS4232/InterWave & compatible chips");
+MODULE_LICENSE("GPL");
+
+#if 0
+#define SNDRV_DEBUG_MCE
+#endif
+
+/*
+ * Some variables
+ */
+
+static unsigned char freq_bits[14] = {
+ /* 5510 */ 0x00 | CS4231_XTAL2,
+ /* 6620 */ 0x0E | CS4231_XTAL2,
+ /* 8000 */ 0x00 | CS4231_XTAL1,
+ /* 9600 */ 0x0E | CS4231_XTAL1,
+ /* 11025 */ 0x02 | CS4231_XTAL2,
+ /* 16000 */ 0x02 | CS4231_XTAL1,
+ /* 18900 */ 0x04 | CS4231_XTAL2,
+ /* 22050 */ 0x06 | CS4231_XTAL2,
+ /* 27042 */ 0x04 | CS4231_XTAL1,
+ /* 32000 */ 0x06 | CS4231_XTAL1,
+ /* 33075 */ 0x0C | CS4231_XTAL2,
+ /* 37800 */ 0x08 | CS4231_XTAL2,
+ /* 44100 */ 0x0A | CS4231_XTAL2,
+ /* 48000 */ 0x0C | CS4231_XTAL1
+};
+
+static unsigned int rates[14] = {
+ 5510, 6620, 8000, 9600, 11025, 16000, 18900, 22050,
+ 27042, 32000, 33075, 37800, 44100, 48000
+};
+
+static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
+ .count = 14,
+ .list = rates,
+ .mask = 0,
+};
+
+static int snd_cs4231_xrate(snd_pcm_runtime_t *runtime)
+{
+ return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
+}
+
+static unsigned char snd_cs4231_original_image[32] =
+{
+ 0x00, /* 00/00 - lic */
+ 0x00, /* 01/01 - ric */
+ 0x9f, /* 02/02 - la1ic */
+ 0x9f, /* 03/03 - ra1ic */
+ 0x9f, /* 04/04 - la2ic */
+ 0x9f, /* 05/05 - ra2ic */
+ 0xbf, /* 06/06 - loc */
+ 0xbf, /* 07/07 - roc */
+ 0x20, /* 08/08 - pdfr */
+ CS4231_AUTOCALIB, /* 09/09 - ic */
+ 0x00, /* 0a/10 - pc */
+ 0x00, /* 0b/11 - ti */
+ CS4231_MODE2, /* 0c/12 - mi */
+ 0xfc, /* 0d/13 - lbc */
+ 0x00, /* 0e/14 - pbru */
+ 0x00, /* 0f/15 - pbrl */
+ 0x80, /* 10/16 - afei */
+ 0x01, /* 11/17 - afeii */
+ 0x9f, /* 12/18 - llic */
+ 0x9f, /* 13/19 - rlic */
+ 0x00, /* 14/20 - tlb */
+ 0x00, /* 15/21 - thb */
+ 0x00, /* 16/22 - la3mic/reserved */
+ 0x00, /* 17/23 - ra3mic/reserved */
+ 0x00, /* 18/24 - afs */
+ 0x00, /* 19/25 - lamoc/version */
+ 0xcf, /* 1a/26 - mioc */
+ 0x00, /* 1b/27 - ramoc/reserved */
+ 0x20, /* 1c/28 - cdfr */
+ 0x00, /* 1d/29 - res4 */
+ 0x00, /* 1e/30 - cbru */
+ 0x00, /* 1f/31 - cbrl */
+};
+
+/*
+ * Basic I/O functions
+ */
+
+#if !defined(EBUS_SUPPORT) && !defined(SBUS_SUPPORT)
+#define __CS4231_INLINE__ inline
+#else
+#define __CS4231_INLINE__ /* nothing */
+#endif
+
+static __CS4231_INLINE__ void cs4231_outb(cs4231_t *chip, u8 offset, u8 val)
+{
+#ifdef EBUS_SUPPORT
+ if (chip->ebus->flag) {
+ writeb(val, chip->port + (offset << 2));
+ } else {
+#endif
+#ifdef SBUS_SUPPORT
+ sbus_writeb(val, chip->port + (offset << 2));
+#endif
+#ifdef EBUS_SUPPORT
+ }
+#endif
+#ifdef LEGACY_SUPPORT
+ outb(val, chip->port + offset);
+#endif
+}
+
+static __CS4231_INLINE__ u8 cs4231_inb(cs4231_t *chip, u8 offset)
+{
+#ifdef EBUS_SUPPORT
+ if (chip->ebus_flag) {
+ return readb(chip->port + (offset << 2));
+ } else {
+#endif
+#ifdef SBUS_SUPPORT
+ return sbus_readb(chip->port + (offset << 2));
+#endif
+#ifdef EBUS_SUPPORT
+ }
+#endif
+#ifdef LEGACY_SUPPORT
+ return inb(chip->port + offset);
+#endif
+}
+
+static void snd_cs4231_outm(cs4231_t *chip, unsigned char reg,
+ unsigned char mask, unsigned char value)
+{
+ int timeout;
+ unsigned char tmp;
+
+ for (timeout = 250;
+ timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
+ timeout--)
+ udelay(100);
+#ifdef CONFIG_SND_DEBUG
+ if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
+ snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
+#endif
+ if (chip->calibrate_mute) {
+ chip->image[reg] &= mask;
+ chip->image[reg] |= value;
+ } else {
+ cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
+ mb();
+ tmp = (chip->image[reg] & mask) | value;
+ cs4231_outb(chip, CS4231P(REG), tmp);
+ chip->image[reg] = tmp;
+ mb();
+ }
+}
+
+static void snd_cs4231_dout(cs4231_t *chip, unsigned char reg, unsigned char value)
+{
+ int timeout;
+
+ for (timeout = 250;
+ timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
+ timeout--)
+ udelay(10);
+ cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
+ cs4231_outb(chip, CS4231P(REG), value);
+ mb();
+}
+
+void snd_cs4231_out(cs4231_t *chip, unsigned char reg, unsigned char value)
+{
+ int timeout;
+
+ for (timeout = 250;
+ timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
+ timeout--)
+ udelay(100);
+#ifdef CONFIG_SND_DEBUG
+ if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
+ snd_printk("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
+#endif
+ cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
+ cs4231_outb(chip, CS4231P(REG), value);
+ chip->image[reg] = value;
+ mb();
+#if 0
+ printk("codec out - reg 0x%x = 0x%x\n", chip->mce_bit | reg, value);
+#endif
+}
+
+unsigned char snd_cs4231_in(cs4231_t *chip, unsigned char reg)
+{
+ int timeout;
+
+ for (timeout = 250;
+ timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
+ timeout--)
+ udelay(100);
+#ifdef CONFIG_SND_DEBUG
+ if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
+ snd_printk("in: auto calibration time out - reg = 0x%x\n", reg);
+#endif
+ cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
+ mb();
+ return cs4231_inb(chip, CS4231P(REG));
+}
+
+void snd_cs4236_ext_out(cs4231_t *chip, unsigned char reg, unsigned char val)
+{
+ cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17);
+ cs4231_outb(chip, CS4231P(REG), reg | (chip->image[CS4236_EXT_REG] & 0x01));
+ cs4231_outb(chip, CS4231P(REG), val);
+ chip->eimage[CS4236_REG(reg)] = val;
+#if 0
+ printk("ext out : reg = 0x%x, val = 0x%x\n", reg, val);
+#endif
+}
+
+unsigned char snd_cs4236_ext_in(cs4231_t *chip, unsigned char reg)
+{
+ cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17);
+ cs4231_outb(chip, CS4231P(REG), reg | (chip->image[CS4236_EXT_REG] & 0x01));
+#if 1
+ return cs4231_inb(chip, CS4231P(REG));
+#else
+ {
+ unsigned char res;
+ res = cs4231_inb(chip, CS4231P(REG));
+ printk("ext in : reg = 0x%x, val = 0x%x\n", reg, res);
+ return res;
+ }
+#endif
+}
+
+#if 0
+
+static void snd_cs4231_debug(cs4231_t *chip)
+{
+ printk("CS4231 REGS: INDEX = 0x%02x ", cs4231_inb(chip, CS4231P(REGSEL)));
+ printk(" STATUS = 0x%02x\n", cs4231_inb(chip, CS4231P(STATUS)));
+ printk(" 0x00: left input = 0x%02x ", snd_cs4231_in(chip, 0x00));
+ printk(" 0x10: alt 1 (CFIG 2) = 0x%02x\n", snd_cs4231_in(chip, 0x10));
+ printk(" 0x01: right input = 0x%02x ", snd_cs4231_in(chip, 0x01));
+ printk(" 0x11: alt 2 (CFIG 3) = 0x%02x\n", snd_cs4231_in(chip, 0x11));
+ printk(" 0x02: GF1 left input = 0x%02x ", snd_cs4231_in(chip, 0x02));
+ printk(" 0x12: left line in = 0x%02x\n", snd_cs4231_in(chip, 0x12));
+ printk(" 0x03: GF1 right input = 0x%02x ", snd_cs4231_in(chip, 0x03));
+ printk(" 0x13: right line in = 0x%02x\n", snd_cs4231_in(chip, 0x13));
+ printk(" 0x04: CD left input = 0x%02x ", snd_cs4231_in(chip, 0x04));
+ printk(" 0x14: timer low = 0x%02x\n", snd_cs4231_in(chip, 0x14));
+ printk(" 0x05: CD right input = 0x%02x ", snd_cs4231_in(chip, 0x05));
+ printk(" 0x15: timer high = 0x%02x\n", snd_cs4231_in(chip, 0x15));
+ printk(" 0x06: left output = 0x%02x ", snd_cs4231_in(chip, 0x06));
+ printk(" 0x16: left MIC (PnP) = 0x%02x\n", snd_cs4231_in(chip, 0x16));
+ printk(" 0x07: right output = 0x%02x ", snd_cs4231_in(chip, 0x07));
+ printk(" 0x17: right MIC (PnP) = 0x%02x\n", snd_cs4231_in(chip, 0x17));
+ printk(" 0x08: playback format = 0x%02x ", snd_cs4231_in(chip, 0x08));
+ printk(" 0x18: IRQ status = 0x%02x\n", snd_cs4231_in(chip, 0x18));
+ printk(" 0x09: iface (CFIG 1) = 0x%02x ", snd_cs4231_in(chip, 0x09));
+ printk(" 0x19: left line out = 0x%02x\n", snd_cs4231_in(chip, 0x19));
+ printk(" 0x0a: pin control = 0x%02x ", snd_cs4231_in(chip, 0x0a));
+ printk(" 0x1a: mono control = 0x%02x\n", snd_cs4231_in(chip, 0x1a));
+ printk(" 0x0b: init & status = 0x%02x ", snd_cs4231_in(chip, 0x0b));
+ printk(" 0x1b: right line out = 0x%02x\n", snd_cs4231_in(chip, 0x1b));
+ printk(" 0x0c: revision & mode = 0x%02x ", snd_cs4231_in(chip, 0x0c));
+ printk(" 0x1c: record format = 0x%02x\n", snd_cs4231_in(chip, 0x1c));
+ printk(" 0x0d: loopback = 0x%02x ", snd_cs4231_in(chip, 0x0d));
+ printk(" 0x1d: var freq (PnP) = 0x%02x\n", snd_cs4231_in(chip, 0x1d));
+ printk(" 0x0e: ply upr count = 0x%02x ", snd_cs4231_in(chip, 0x0e));
+ printk(" 0x1e: ply lwr count = 0x%02x\n", snd_cs4231_in(chip, 0x1e));
+ printk(" 0x0f: rec upr count = 0x%02x ", snd_cs4231_in(chip, 0x0f));
+ printk(" 0x1f: rec lwr count = 0x%02x\n", snd_cs4231_in(chip, 0x1f));
+}
+
+#endif
+
+/*
+ * CS4231 detection / MCE routines
+ */
+
+static void snd_cs4231_busy_wait(cs4231_t *chip)
+{
+ int timeout;
+
+ /* huh.. looks like this sequence is proper for CS4231A chip (GUS MAX) */
+ for (timeout = 5; timeout > 0; timeout--)
+ cs4231_inb(chip, CS4231P(REGSEL));
+ /* end of cleanup sequence */
+ for (timeout = 250;
+ timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
+ timeout--)
+ udelay(10);
+}
+
+void snd_cs4231_mce_up(cs4231_t *chip)
+{
+ unsigned long flags;
+ int timeout;
+
+ for (timeout = 250; timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT); timeout--)
+ udelay(100);
+#ifdef CONFIG_SND_DEBUG
+ if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
+ snd_printk("mce_up - auto calibration time out (0)\n");
+#endif
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ chip->mce_bit |= CS4231_MCE;
+ timeout = cs4231_inb(chip, CS4231P(REGSEL));
+ if (timeout == 0x80)
+ snd_printk("mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port);
+ if (!(timeout & CS4231_MCE))
+ cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+}
+
+void snd_cs4231_mce_down(cs4231_t *chip)
+{
+ unsigned long flags;
+ int timeout;
+
+ snd_cs4231_busy_wait(chip);
+#if 0
+ printk("(1) timeout = %i\n", timeout);
+#endif
+#ifdef CONFIG_SND_DEBUG
+ if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
+ snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", (long)CS4231P(REGSEL));
+#endif
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ chip->mce_bit &= ~CS4231_MCE;
+ timeout = cs4231_inb(chip, CS4231P(REGSEL));
+ cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (timeout == 0x80)
+ snd_printk("mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port);
+ if ((timeout & CS4231_MCE) == 0 ||
+ !(chip->hardware & (CS4231_HW_CS4231_MASK | CS4231_HW_CS4232_MASK))) {
+ return;
+ }
+ snd_cs4231_busy_wait(chip);
+
+ /* calibration process */
+
+ for (timeout = 500; timeout > 0 && (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) == 0; timeout--)
+ udelay(10);
+ if ((snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) == 0) {
+ snd_printd("cs4231_mce_down - auto calibration time out (1)\n");
+ return;
+ }
+#if 0
+ printk("(2) timeout = %i, jiffies = %li\n", timeout, jiffies);
+#endif
+ /* in 10 ms increments, check condition, up to 250 ms */
+ timeout = 25;
+ while (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) {
+ if (--timeout < 0) {
+ snd_printk("mce_down - auto calibration time out (2)\n");
+ return;
+ }
+ msleep(10);
+ }
+#if 0
+ printk("(3) jiffies = %li\n", jiffies);
+#endif
+ /* in 10 ms increments, check condition, up to 100 ms */
+ timeout = 10;
+ while (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) {
+ if (--timeout < 0) {
+ snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n");
+ return;
+ }
+ msleep(10);
+ }
+#if 0
+ printk("(4) jiffies = %li\n", jiffies);
+ snd_printk("mce_down - exit = 0x%x\n", cs4231_inb(chip, CS4231P(REGSEL)));
+#endif
+}
+
+static unsigned int snd_cs4231_get_count(unsigned char format, unsigned int size)
+{
+ switch (format & 0xe0) {
+ case CS4231_LINEAR_16:
+ case CS4231_LINEAR_16_BIG:
+ size >>= 1;
+ break;
+ case CS4231_ADPCM_16:
+ return size >> 2;
+ }
+ if (format & CS4231_STEREO)
+ size >>= 1;
+ return size;
+}
+
+static int snd_cs4231_trigger(snd_pcm_substream_t *substream,
+ int cmd)
+{
+ cs4231_t *chip = snd_pcm_substream_chip(substream);
+ int result = 0;
+ unsigned int what;
+ struct list_head *pos;
+ snd_pcm_substream_t *s;
+ int do_start;
+
+#if 0
+ printk("codec trigger!!! - what = %i, enable = %i, status = 0x%x\n", what, enable, cs4231_inb(chip, CS4231P(STATUS)));
+#endif
+
+ switch (cmd) {
+ case SNDRV_PCM_TRIGGER_START:
+ case SNDRV_PCM_TRIGGER_RESUME:
+ do_start = 1; break;
+ case SNDRV_PCM_TRIGGER_STOP:
+ case SNDRV_PCM_TRIGGER_SUSPEND:
+ do_start = 0; break;
+ default:
+ return -EINVAL;
+ }
+
+ what = 0;
+ snd_pcm_group_for_each(pos, substream) {
+ s = snd_pcm_group_substream_entry(pos);
+ if (s == chip->playback_substream) {
+ what |= CS4231_PLAYBACK_ENABLE;
+ snd_pcm_trigger_done(s, substream);
+ } else if (s == chip->capture_substream) {
+ what |= CS4231_RECORD_ENABLE;
+ snd_pcm_trigger_done(s, substream);
+ }
+ }
+ spin_lock(&chip->reg_lock);
+ if (do_start) {
+ chip->image[CS4231_IFACE_CTRL] |= what;
+ if (chip->trigger)
+ chip->trigger(chip, what, 1);
+ } else {
+ chip->image[CS4231_IFACE_CTRL] &= ~what;
+ if (chip->trigger)
+ chip->trigger(chip, what, 0);
+ }
+ snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
+ spin_unlock(&chip->reg_lock);
+#if 0
+ snd_cs4231_debug(chip);
+#endif
+ return result;
+}
+
+/*
+ * CODEC I/O
+ */
+
+static unsigned char snd_cs4231_get_rate(unsigned int rate)
+{
+ int i;
+
+ for (i = 0; i < 14; i++)
+ if (rate == rates[i])
+ return freq_bits[i];
+ // snd_BUG();
+ return freq_bits[13];
+}
+
+static unsigned char snd_cs4231_get_format(cs4231_t *chip,
+ int format,
+ int channels)
+{
+ unsigned char rformat;
+
+ rformat = CS4231_LINEAR_8;
+ switch (format) {
+ case SNDRV_PCM_FORMAT_MU_LAW: rformat = CS4231_ULAW_8; break;
+ case SNDRV_PCM_FORMAT_A_LAW: rformat = CS4231_ALAW_8; break;
+ case SNDRV_PCM_FORMAT_S16_LE: rformat = CS4231_LINEAR_16; break;
+ case SNDRV_PCM_FORMAT_S16_BE: rformat = CS4231_LINEAR_16_BIG; break;
+ case SNDRV_PCM_FORMAT_IMA_ADPCM: rformat = CS4231_ADPCM_16; break;
+ }
+ if (channels > 1)
+ rformat |= CS4231_STEREO;
+#if 0
+ snd_printk("get_format: 0x%x (mode=0x%x)\n", format, mode);
+#endif
+ return rformat;
+}
+
+static void snd_cs4231_calibrate_mute(cs4231_t *chip, int mute)
+{
+ unsigned long flags;
+
+ mute = mute ? 1 : 0;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ if (chip->calibrate_mute == mute) {
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return;
+ }
+ if (!mute) {
+ snd_cs4231_dout(chip, CS4231_LEFT_INPUT, chip->image[CS4231_LEFT_INPUT]);
+ snd_cs4231_dout(chip, CS4231_RIGHT_INPUT, chip->image[CS4231_RIGHT_INPUT]);
+ snd_cs4231_dout(chip, CS4231_LOOPBACK, chip->image[CS4231_LOOPBACK]);
+ }
+ snd_cs4231_dout(chip, CS4231_AUX1_LEFT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX1_LEFT_INPUT]);
+ snd_cs4231_dout(chip, CS4231_AUX1_RIGHT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX1_RIGHT_INPUT]);
+ snd_cs4231_dout(chip, CS4231_AUX2_LEFT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX2_LEFT_INPUT]);
+ snd_cs4231_dout(chip, CS4231_AUX2_RIGHT_INPUT, mute ? 0x80 : chip->image[CS4231_AUX2_RIGHT_INPUT]);
+ snd_cs4231_dout(chip, CS4231_LEFT_OUTPUT, mute ? 0x80 : chip->image[CS4231_LEFT_OUTPUT]);
+ snd_cs4231_dout(chip, CS4231_RIGHT_OUTPUT, mute ? 0x80 : chip->image[CS4231_RIGHT_OUTPUT]);
+ snd_cs4231_dout(chip, CS4231_LEFT_LINE_IN, mute ? 0x80 : chip->image[CS4231_LEFT_LINE_IN]);
+ snd_cs4231_dout(chip, CS4231_RIGHT_LINE_IN, mute ? 0x80 : chip->image[CS4231_RIGHT_LINE_IN]);
+ snd_cs4231_dout(chip, CS4231_MONO_CTRL, mute ? 0xc0 : chip->image[CS4231_MONO_CTRL]);
+ if (chip->hardware == CS4231_HW_INTERWAVE) {
+ snd_cs4231_dout(chip, CS4231_LEFT_MIC_INPUT, mute ? 0x80 : chip->image[CS4231_LEFT_MIC_INPUT]);
+ snd_cs4231_dout(chip, CS4231_RIGHT_MIC_INPUT, mute ? 0x80 : chip->image[CS4231_RIGHT_MIC_INPUT]);
+ snd_cs4231_dout(chip, CS4231_LINE_LEFT_OUTPUT, mute ? 0x80 : chip->image[CS4231_LINE_LEFT_OUTPUT]);
+ snd_cs4231_dout(chip, CS4231_LINE_RIGHT_OUTPUT, mute ? 0x80 : chip->image[CS4231_LINE_RIGHT_OUTPUT]);
+ }
+ chip->calibrate_mute = mute;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+}
+
+static void snd_cs4231_playback_format(cs4231_t *chip,
+ snd_pcm_hw_params_t *params,
+ unsigned char pdfr)
+{
+ unsigned long flags;
+ int full_calib = 1;
+
+ down(&chip->mce_mutex);
+ snd_cs4231_calibrate_mute(chip, 1);
+ if (chip->hardware == CS4231_HW_CS4231A ||
+ (chip->hardware & CS4231_HW_CS4232_MASK)) {
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ if ((chip->image[CS4231_PLAYBK_FORMAT] & 0x0f) == (pdfr & 0x0f)) { /* rate is same? */
+ snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x10);
+ snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT] = pdfr);
+ snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] &= ~0x10);
+ udelay(100); /* Fixes audible clicks at least on GUS MAX */
+ full_calib = 0;
+ }
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ }
+ if (full_calib) {
+ snd_cs4231_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ if (chip->hardware != CS4231_HW_INTERWAVE && !chip->single_dma) {
+ snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT,
+ (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) ?
+ (pdfr & 0xf0) | (chip->image[CS4231_REC_FORMAT] & 0x0f) :
+ pdfr);
+ } else {
+ snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT] = pdfr);
+ }
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_cs4231_mce_down(chip);
+ }
+ snd_cs4231_calibrate_mute(chip, 0);
+ up(&chip->mce_mutex);
+}
+
+static void snd_cs4231_capture_format(cs4231_t *chip,
+ snd_pcm_hw_params_t *params,
+ unsigned char cdfr)
+{
+ unsigned long flags;
+ int full_calib = 1;
+
+ down(&chip->mce_mutex);
+ snd_cs4231_calibrate_mute(chip, 1);
+ if (chip->hardware == CS4231_HW_CS4231A ||
+ (chip->hardware & CS4231_HW_CS4232_MASK)) {
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ if ((chip->image[CS4231_PLAYBK_FORMAT] & 0x0f) == (cdfr & 0x0f) || /* rate is same? */
+ (chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) {
+ snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x20);
+ snd_cs4231_out(chip, CS4231_REC_FORMAT, chip->image[CS4231_REC_FORMAT] = cdfr);
+ snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] &= ~0x20);
+ full_calib = 0;
+ }
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ }
+ if (full_calib) {
+ snd_cs4231_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ if (chip->hardware != CS4231_HW_INTERWAVE) {
+ if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) {
+ snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT,
+ ((chip->single_dma ? cdfr : chip->image[CS4231_PLAYBK_FORMAT]) & 0xf0) |
+ (cdfr & 0x0f));
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_cs4231_mce_down(chip);
+ snd_cs4231_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ }
+ }
+ snd_cs4231_out(chip, CS4231_REC_FORMAT, cdfr);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_cs4231_mce_down(chip);
+ }
+ snd_cs4231_calibrate_mute(chip, 0);
+ up(&chip->mce_mutex);
+}
+
+/*
+ * Timer interface
+ */
+
+static unsigned long snd_cs4231_timer_resolution(snd_timer_t * timer)
+{
+ cs4231_t *chip = snd_timer_chip(timer);
+ if (chip->hardware & CS4231_HW_CS4236B_MASK)
+ return 14467;
+ else
+ return chip->image[CS4231_PLAYBK_FORMAT] & 1 ? 9969 : 9920;
+}
+
+static int snd_cs4231_timer_start(snd_timer_t * timer)
+{
+ unsigned long flags;
+ unsigned int ticks;
+ cs4231_t *chip = snd_timer_chip(timer);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ticks = timer->sticks;
+ if ((chip->image[CS4231_ALT_FEATURE_1] & CS4231_TIMER_ENABLE) == 0 ||
+ (unsigned char)(ticks >> 8) != chip->image[CS4231_TIMER_HIGH] ||
+ (unsigned char)ticks != chip->image[CS4231_TIMER_LOW]) {
+ snd_cs4231_out(chip, CS4231_TIMER_HIGH, chip->image[CS4231_TIMER_HIGH] = (unsigned char) (ticks >> 8));
+ snd_cs4231_out(chip, CS4231_TIMER_LOW, chip->image[CS4231_TIMER_LOW] = (unsigned char) ticks);
+ snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | CS4231_TIMER_ENABLE);
+ }
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return 0;
+}
+
+static int snd_cs4231_timer_stop(snd_timer_t * timer)
+{
+ unsigned long flags;
+ cs4231_t *chip = snd_timer_chip(timer);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] &= ~CS4231_TIMER_ENABLE);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return 0;
+}
+
+static void snd_cs4231_init(cs4231_t *chip)
+{
+ unsigned long flags;
+
+ snd_cs4231_mce_down(chip);
+
+#ifdef SNDRV_DEBUG_MCE
+ snd_printk("init: (1)\n");
+#endif
+ snd_cs4231_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
+ CS4231_RECORD_ENABLE | CS4231_RECORD_PIO |
+ CS4231_CALIB_MODE);
+ chip->image[CS4231_IFACE_CTRL] |= CS4231_AUTOCALIB;
+ snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_cs4231_mce_down(chip);
+
+#ifdef SNDRV_DEBUG_MCE
+ snd_printk("init: (2)\n");
+#endif
+
+ snd_cs4231_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_cs4231_mce_down(chip);
+
+#ifdef SNDRV_DEBUG_MCE
+ snd_printk("init: (3) - afei = 0x%x\n", chip->image[CS4231_ALT_FEATURE_1]);
+#endif
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_cs4231_out(chip, CS4231_ALT_FEATURE_2, chip->image[CS4231_ALT_FEATURE_2]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+
+ snd_cs4231_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_cs4231_mce_down(chip);
+
+#ifdef SNDRV_DEBUG_MCE
+ snd_printk("init: (4)\n");
+#endif
+
+ snd_cs4231_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_cs4231_out(chip, CS4231_REC_FORMAT, chip->image[CS4231_REC_FORMAT]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_cs4231_mce_down(chip);
+
+#ifdef SNDRV_DEBUG_MCE
+ snd_printk("init: (5)\n");
+#endif
+}
+
+static int snd_cs4231_open(cs4231_t *chip, unsigned int mode)
+{
+ unsigned long flags;
+
+ down(&chip->open_mutex);
+ if ((chip->mode & mode) ||
+ ((chip->mode & CS4231_MODE_OPEN) && chip->single_dma)) {
+ up(&chip->open_mutex);
+ return -EAGAIN;
+ }
+ if (chip->mode & CS4231_MODE_OPEN) {
+ chip->mode |= mode;
+ up(&chip->open_mutex);
+ return 0;
+ }
+ /* ok. now enable and ack CODEC IRQ */
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ |
+ CS4231_RECORD_IRQ |
+ CS4231_TIMER_IRQ);
+ snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
+ cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
+ cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
+ chip->image[CS4231_PIN_CTRL] |= CS4231_IRQ_ENABLE;
+ snd_cs4231_out(chip, CS4231_PIN_CTRL, chip->image[CS4231_PIN_CTRL]);
+ snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ |
+ CS4231_RECORD_IRQ |
+ CS4231_TIMER_IRQ);
+ snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+
+ chip->mode = mode;
+ up(&chip->open_mutex);
+ return 0;
+}
+
+static void snd_cs4231_close(cs4231_t *chip, unsigned int mode)
+{
+ unsigned long flags;
+
+ down(&chip->open_mutex);
+ chip->mode &= ~mode;
+ if (chip->mode & CS4231_MODE_OPEN) {
+ up(&chip->open_mutex);
+ return;
+ }
+ snd_cs4231_calibrate_mute(chip, 1);
+
+ /* disable IRQ */
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
+ cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
+ cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
+ chip->image[CS4231_PIN_CTRL] &= ~CS4231_IRQ_ENABLE;
+ snd_cs4231_out(chip, CS4231_PIN_CTRL, chip->image[CS4231_PIN_CTRL]);
+
+ /* now disable record & playback */
+
+ if (chip->image[CS4231_IFACE_CTRL] & (CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
+ CS4231_RECORD_ENABLE | CS4231_RECORD_PIO)) {
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_cs4231_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
+ CS4231_RECORD_ENABLE | CS4231_RECORD_PIO);
+ snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_cs4231_mce_down(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ }
+
+ /* clear IRQ again */
+ snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0);
+ cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
+ cs4231_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+
+ snd_cs4231_calibrate_mute(chip, 0);
+
+ chip->mode = 0;
+ up(&chip->open_mutex);
+}
+
+/*
+ * timer open/close
+ */
+
+static int snd_cs4231_timer_open(snd_timer_t * timer)
+{
+ cs4231_t *chip = snd_timer_chip(timer);
+ snd_cs4231_open(chip, CS4231_MODE_TIMER);
+ return 0;
+}
+
+static int snd_cs4231_timer_close(snd_timer_t * timer)
+{
+ cs4231_t *chip = snd_timer_chip(timer);
+ snd_cs4231_close(chip, CS4231_MODE_TIMER);
+ return 0;
+}
+
+static struct _snd_timer_hardware snd_cs4231_timer_table =
+{
+ .flags = SNDRV_TIMER_HW_AUTO,
+ .resolution = 9945,
+ .ticks = 65535,
+ .open = snd_cs4231_timer_open,
+ .close = snd_cs4231_timer_close,
+ .c_resolution = snd_cs4231_timer_resolution,
+ .start = snd_cs4231_timer_start,
+ .stop = snd_cs4231_timer_stop,
+};
+
+/*
+ * ok.. exported functions..
+ */
+
+static int snd_cs4231_playback_hw_params(snd_pcm_substream_t * substream,
+ snd_pcm_hw_params_t * hw_params)
+{
+ cs4231_t *chip = snd_pcm_substream_chip(substream);
+ unsigned char new_pdfr;
+ int err;
+
+ if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
+ return err;
+ new_pdfr = snd_cs4231_get_format(chip, params_format(hw_params), params_channels(hw_params)) |
+ snd_cs4231_get_rate(params_rate(hw_params));
+ chip->set_playback_format(chip, hw_params, new_pdfr);
+ return 0;
+}
+
+static int snd_cs4231_playback_hw_free(snd_pcm_substream_t * substream)
+{
+ return snd_pcm_lib_free_pages(substream);
+}
+
+#ifdef LEGACY_SUPPORT
+static int snd_cs4231_playback_prepare(snd_pcm_substream_t * substream)
+{
+ cs4231_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ unsigned long flags;
+ unsigned int size = snd_pcm_lib_buffer_bytes(substream);
+ unsigned int count = snd_pcm_lib_period_bytes(substream);
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ chip->p_dma_size = size;
+ chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO);
+ snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
+ count = snd_cs4231_get_count(chip->image[CS4231_PLAYBK_FORMAT], count) - 1;
+ snd_cs4231_out(chip, CS4231_PLY_LWR_CNT, (unsigned char) count);
+ snd_cs4231_out(chip, CS4231_PLY_UPR_CNT, (unsigned char) (count >> 8));
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+#if 0
+ snd_cs4231_debug(chip);
+#endif
+ return 0;
+}
+#endif /* LEGACY_SUPPORT */
+
+static int snd_cs4231_capture_hw_params(snd_pcm_substream_t * substream,
+ snd_pcm_hw_params_t * hw_params)
+{
+ cs4231_t *chip = snd_pcm_substream_chip(substream);
+ unsigned char new_cdfr;
+ int err;
+
+ if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
+ return err;
+ new_cdfr = snd_cs4231_get_format(chip, params_format(hw_params), params_channels(hw_params)) |
+ snd_cs4231_get_rate(params_rate(hw_params));
+ chip->set_capture_format(chip, hw_params, new_cdfr);
+ return 0;
+}
+
+static int snd_cs4231_capture_hw_free(snd_pcm_substream_t * substream)
+{
+ return snd_pcm_lib_free_pages(substream);
+}
+
+#ifdef LEGACY_SUPPORT
+static int snd_cs4231_capture_prepare(snd_pcm_substream_t * substream)
+{
+ cs4231_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ unsigned long flags;
+ unsigned int size = snd_pcm_lib_buffer_bytes(substream);
+ unsigned int count = snd_pcm_lib_period_bytes(substream);
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ chip->c_dma_size = size;
+ chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_RECORD_ENABLE | CS4231_RECORD_PIO);
+ snd_dma_program(chip->dma2, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
+ count = snd_cs4231_get_count(chip->image[CS4231_REC_FORMAT], count) - 1;
+ if (chip->single_dma && chip->hardware != CS4231_HW_INTERWAVE) {
+ snd_cs4231_out(chip, CS4231_PLY_LWR_CNT, (unsigned char) count);
+ snd_cs4231_out(chip, CS4231_PLY_UPR_CNT, (unsigned char) (count >> 8));
+ } else {
+ snd_cs4231_out(chip, CS4231_REC_LWR_CNT, (unsigned char) count);
+ snd_cs4231_out(chip, CS4231_REC_UPR_CNT, (unsigned char) (count >> 8));
+ }
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return 0;
+}
+#endif
+
+static void snd_cs4231_overrange(cs4231_t *chip)
+{
+ unsigned long flags;
+ unsigned char res;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ res = snd_cs4231_in(chip, CS4231_TEST_INIT);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (res & (0x08 | 0x02)) /* detect overrange only above 0dB; may be user selectable? */
+ chip->capture_substream->runtime->overrange++;
+}
+
+irqreturn_t snd_cs4231_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ cs4231_t *chip = dev_id;
+ unsigned char status;
+
+ status = snd_cs4231_in(chip, CS4231_IRQ_STATUS);
+ if (status & CS4231_TIMER_IRQ) {
+ if (chip->timer)
+ snd_timer_interrupt(chip->timer, chip->timer->sticks);
+ }
+ if (chip->single_dma && chip->hardware != CS4231_HW_INTERWAVE) {
+ if (status & CS4231_PLAYBACK_IRQ) {
+ if (chip->mode & CS4231_MODE_PLAY) {
+ if (chip->playback_substream)
+ snd_pcm_period_elapsed(chip->playback_substream);
+ }
+ if (chip->mode & CS4231_MODE_RECORD) {
+ if (chip->capture_substream) {
+ snd_cs4231_overrange(chip);
+ snd_pcm_period_elapsed(chip->capture_substream);
+ }
+ }
+ }
+ } else {
+ if (status & CS4231_PLAYBACK_IRQ) {
+ if (chip->playback_substream)
+ snd_pcm_period_elapsed(chip->playback_substream);
+ }
+ if (status & CS4231_RECORD_IRQ) {
+ if (chip->capture_substream) {
+ snd_cs4231_overrange(chip);
+ snd_pcm_period_elapsed(chip->capture_substream);
+ }
+ }
+ }
+
+ spin_lock(&chip->reg_lock);
+ snd_cs4231_outm(chip, CS4231_IRQ_STATUS, ~CS4231_ALL_IRQS | ~status, 0);
+ spin_unlock(&chip->reg_lock);
+ return IRQ_HANDLED;
+}
+
+#ifdef LEGACY_SUPPORT
+static snd_pcm_uframes_t snd_cs4231_playback_pointer(snd_pcm_substream_t * substream)
+{
+ cs4231_t *chip = snd_pcm_substream_chip(substream);
+ size_t ptr;
+
+ if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE))
+ return 0;
+ ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size);
+ return bytes_to_frames(substream->runtime, ptr);
+}
+
+static snd_pcm_uframes_t snd_cs4231_capture_pointer(snd_pcm_substream_t * substream)
+{
+ cs4231_t *chip = snd_pcm_substream_chip(substream);
+ size_t ptr;
+
+ if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE))
+ return 0;
+ ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
+ return bytes_to_frames(substream->runtime, ptr);
+}
+#endif /* LEGACY_SUPPORT */
+
+/*
+
+ */
+
+static int snd_cs4231_probe(cs4231_t *chip)
+{
+ unsigned long flags;
+ int i, id, rev;
+ unsigned char *ptr;
+ unsigned int hw;
+
+#if 0
+ snd_cs4231_debug(chip);
+#endif
+ id = 0;
+ for (i = 0; i < 50; i++) {
+ mb();
+ if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
+ udelay(2000);
+ else {
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_cs4231_out(chip, CS4231_MISC_INFO, CS4231_MODE2);
+ id = snd_cs4231_in(chip, CS4231_MISC_INFO) & 0x0f;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (id == 0x0a)
+ break; /* this is valid value */
+ }
+ }
+ snd_printdd("cs4231: port = 0x%lx, id = 0x%x\n", chip->port, id);
+ if (id != 0x0a)
+ return -ENODEV; /* no valid device found */
+
+ if (((hw = chip->hardware) & CS4231_HW_TYPE_MASK) == CS4231_HW_DETECT) {
+ rev = snd_cs4231_in(chip, CS4231_VERSION) & 0xe7;
+ snd_printdd("CS4231: VERSION (I25) = 0x%x\n", rev);
+ if (rev == 0x80) {
+ unsigned char tmp = snd_cs4231_in(chip, 23);
+ snd_cs4231_out(chip, 23, ~tmp);
+ if (snd_cs4231_in(chip, 23) != tmp)
+ chip->hardware = CS4231_HW_AD1845;
+ else
+ chip->hardware = CS4231_HW_CS4231;
+ } else if (rev == 0xa0) {
+ chip->hardware = CS4231_HW_CS4231A;
+ } else if (rev == 0xa2) {
+ chip->hardware = CS4231_HW_CS4232;
+ } else if (rev == 0xb2) {
+ chip->hardware = CS4231_HW_CS4232A;
+ } else if (rev == 0x83) {
+ chip->hardware = CS4231_HW_CS4236;
+ } else if (rev == 0x03) {
+ chip->hardware = CS4231_HW_CS4236B;
+ } else {
+ snd_printk("unknown CS chip with version 0x%x\n", rev);
+ return -ENODEV; /* unknown CS4231 chip? */
+ }
+ }
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ cs4231_inb(chip, CS4231P(STATUS)); /* clear any pendings IRQ */
+ cs4231_outb(chip, CS4231P(STATUS), 0);
+ mb();
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+
+ chip->image[CS4231_MISC_INFO] = CS4231_MODE2;
+ switch (chip->hardware) {
+ case CS4231_HW_INTERWAVE:
+ chip->image[CS4231_MISC_INFO] = CS4231_IW_MODE3;
+ break;
+ case CS4231_HW_CS4235:
+ case CS4231_HW_CS4236B:
+ case CS4231_HW_CS4237B:
+ case CS4231_HW_CS4238B:
+ case CS4231_HW_CS4239:
+ if (hw == CS4231_HW_DETECT3)
+ chip->image[CS4231_MISC_INFO] = CS4231_4236_MODE3;
+ else
+ chip->hardware = CS4231_HW_CS4236;
+ break;
+ }
+
+ chip->image[CS4231_IFACE_CTRL] =
+ (chip->image[CS4231_IFACE_CTRL] & ~CS4231_SINGLE_DMA) |
+ (chip->single_dma ? CS4231_SINGLE_DMA : 0);
+ chip->image[CS4231_ALT_FEATURE_1] = 0x80;
+ chip->image[CS4231_ALT_FEATURE_2] = chip->hardware == CS4231_HW_INTERWAVE ? 0xc2 : 0x01;
+ ptr = (unsigned char *) &chip->image;
+ snd_cs4231_mce_down(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ for (i = 0; i < 32; i++) /* ok.. fill all CS4231 registers */
+ snd_cs4231_out(chip, i, *ptr++);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_cs4231_mce_up(chip);
+ snd_cs4231_mce_down(chip);
+
+ mdelay(2);
+
+ /* ok.. try check hardware version for CS4236+ chips */
+ if ((hw & CS4231_HW_TYPE_MASK) == CS4231_HW_DETECT) {
+ if (chip->hardware == CS4231_HW_CS4236B) {
+ rev = snd_cs4236_ext_in(chip, CS4236_VERSION);
+ snd_cs4236_ext_out(chip, CS4236_VERSION, 0xff);
+ id = snd_cs4236_ext_in(chip, CS4236_VERSION);
+ snd_cs4236_ext_out(chip, CS4236_VERSION, rev);
+ snd_printdd("CS4231: ext version; rev = 0x%x, id = 0x%x\n", rev, id);
+ if ((id & 0x1f) == 0x1d) { /* CS4235 */
+ chip->hardware = CS4231_HW_CS4235;
+ switch (id >> 5) {
+ case 4:
+ case 5:
+ case 6:
+ break;
+ default:
+ snd_printk("unknown CS4235 chip (enhanced version = 0x%x)\n", id);
+ }
+ } else if ((id & 0x1f) == 0x0b) { /* CS4236/B */
+ switch (id >> 5) {
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ chip->hardware = CS4231_HW_CS4236B;
+ break;
+ default:
+ snd_printk("unknown CS4236 chip (enhanced version = 0x%x)\n", id);
+ }
+ } else if ((id & 0x1f) == 0x08) { /* CS4237B */
+ chip->hardware = CS4231_HW_CS4237B;
+ switch (id >> 5) {
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ break;
+ default:
+ snd_printk("unknown CS4237B chip (enhanced version = 0x%x)\n", id);
+ }
+ } else if ((id & 0x1f) == 0x09) { /* CS4238B */
+ chip->hardware = CS4231_HW_CS4238B;
+ switch (id >> 5) {
+ case 5:
+ case 6:
+ case 7:
+ break;
+ default:
+ snd_printk("unknown CS4238B chip (enhanced version = 0x%x)\n", id);
+ }
+ } else if ((id & 0x1f) == 0x1e) { /* CS4239 */
+ chip->hardware = CS4231_HW_CS4239;
+ switch (id >> 5) {
+ case 4:
+ case 5:
+ case 6:
+ break;
+ default:
+ snd_printk("unknown CS4239 chip (enhanced version = 0x%x)\n", id);
+ }
+ } else {
+ snd_printk("unknown CS4236/CS423xB chip (enhanced version = 0x%x)\n", id);
+ }
+ }
+ }
+ return 0; /* all things are ok.. */
+}
+
+/*
+
+ */
+
+static snd_pcm_hardware_t snd_cs4231_playback =
+{
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_MMAP_VALID |
+ SNDRV_PCM_INFO_RESUME |
+ SNDRV_PCM_INFO_SYNC_START),
+ .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
+ SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
+ .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
+ .rate_min = 5510,
+ .rate_max = 48000,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = (128*1024),
+ .period_bytes_min = 64,
+ .period_bytes_max = (128*1024),
+ .periods_min = 1,
+ .periods_max = 1024,
+ .fifo_size = 0,
+};
+
+static snd_pcm_hardware_t snd_cs4231_capture =
+{
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_MMAP_VALID |
+ SNDRV_PCM_INFO_RESUME |
+ SNDRV_PCM_INFO_SYNC_START),
+ .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
+ SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
+ .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
+ .rate_min = 5510,
+ .rate_max = 48000,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = (128*1024),
+ .period_bytes_min = 64,
+ .period_bytes_max = (128*1024),
+ .periods_min = 1,
+ .periods_max = 1024,
+ .fifo_size = 0,
+};
+
+/*
+
+ */
+
+static int snd_cs4231_playback_open(snd_pcm_substream_t * substream)
+{
+ cs4231_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ int err;
+
+ runtime->hw = snd_cs4231_playback;
+
+ /* hardware bug in InterWave chipset */
+ if (chip->hardware == CS4231_HW_INTERWAVE && chip->dma1 > 3)
+ runtime->hw.formats &= ~SNDRV_PCM_FMTBIT_MU_LAW;
+
+ /* hardware limitation of cheap chips */
+ if (chip->hardware == CS4231_HW_CS4235 ||
+ chip->hardware == CS4231_HW_CS4239)
+ runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE;
+
+#ifdef LEGACY_SUPPORT
+ snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
+ snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.period_bytes_max);
+
+ if (chip->claim_dma) {
+ if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma1)) < 0)
+ return err;
+ }
+#endif
+
+ if ((err = snd_cs4231_open(chip, CS4231_MODE_PLAY)) < 0) {
+#ifdef LEGACY_SUPPORT
+ if (chip->release_dma)
+ chip->release_dma(chip, chip->dma_private_data, chip->dma1);
+#endif
+ snd_free_pages(runtime->dma_area, runtime->dma_bytes);
+ return err;
+ }
+ chip->playback_substream = substream;
+#if defined(SBUS_SUPPORT) || defined(EBUS_SUPPORT)
+ chip->p_periods_sent = 0;
+#endif
+ snd_pcm_set_sync(substream);
+ chip->rate_constraint(runtime);
+ return 0;
+}
+
+static int snd_cs4231_capture_open(snd_pcm_substream_t * substream)
+{
+ cs4231_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ int err;
+
+ runtime->hw = snd_cs4231_capture;
+
+ /* hardware limitation of cheap chips */
+ if (chip->hardware == CS4231_HW_CS4235 ||
+ chip->hardware == CS4231_HW_CS4239)
+ runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE;
+
+#ifdef LEGACY_SUPPORT
+ snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
+ snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.period_bytes_max);
+
+ if (chip->claim_dma) {
+ if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma2)) < 0)
+ return err;
+ }
+#endif
+
+ if ((err = snd_cs4231_open(chip, CS4231_MODE_RECORD)) < 0) {
+#ifdef LEGACY_SUPPORT
+ if (chip->release_dma)
+ chip->release_dma(chip, chip->dma_private_data, chip->dma2);
+#endif
+ snd_free_pages(runtime->dma_area, runtime->dma_bytes);
+ return err;
+ }
+ chip->capture_substream = substream;
+#if defined(SBUS_SUPPORT) || defined(EBUS_SUPPORT)
+ chip->c_periods_sent = 0;
+#endif
+ snd_pcm_set_sync(substream);
+ chip->rate_constraint(runtime);
+ return 0;
+}
+
+static int snd_cs4231_playback_close(snd_pcm_substream_t * substream)
+{
+ cs4231_t *chip = snd_pcm_substream_chip(substream);
+
+ chip->playback_substream = NULL;
+ snd_cs4231_close(chip, CS4231_MODE_PLAY);
+ return 0;
+}
+
+static int snd_cs4231_capture_close(snd_pcm_substream_t * substream)
+{
+ cs4231_t *chip = snd_pcm_substream_chip(substream);
+
+ chip->capture_substream = NULL;
+ snd_cs4231_close(chip, CS4231_MODE_RECORD);
+ return 0;
+}
+
+#ifdef CONFIG_PM
+
+/* lowlevel suspend callback for CS4231 */
+static void snd_cs4231_suspend(cs4231_t *chip)
+{
+ int reg;
+ unsigned long flags;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ for (reg = 0; reg < 32; reg++)
+ chip->image[reg] = snd_cs4231_in(chip, reg);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+}
+
+/* lowlevel resume callback for CS4231 */
+static void snd_cs4231_resume(cs4231_t *chip)
+{
+ int reg;
+ unsigned long flags;
+ int timeout;
+
+ snd_cs4231_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ for (reg = 0; reg < 32; reg++) {
+ switch (reg) {
+ case CS4231_VERSION:
+ break;
+ default:
+ snd_cs4231_out(chip, reg, chip->image[reg]);
+ break;
+ }
+ }
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+#if 0
+ snd_cs4231_mce_down(chip);
+#else
+ /* The following is a workaround to avoid freeze after resume on TP600E.
+ This is the first half of copy of snd_cs4231_mce_down(), but doesn't
+ include rescheduling. -- iwai
+ */
+ snd_cs4231_busy_wait(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ chip->mce_bit &= ~CS4231_MCE;
+ timeout = cs4231_inb(chip, CS4231P(REGSEL));
+ cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (timeout == 0x80)
+ snd_printk("down [0x%lx]: serious init problem - codec still busy\n", chip->port);
+ if ((timeout & CS4231_MCE) == 0 ||
+ !(chip->hardware & (CS4231_HW_CS4231_MASK | CS4231_HW_CS4232_MASK))) {
+ return;
+ }
+ snd_cs4231_busy_wait(chip);
+#endif
+}
+
+static int snd_cs4231_pm_suspend(snd_card_t *card, pm_message_t state)
+{
+ cs4231_t *chip = card->pm_private_data;
+ if (chip->suspend)
+ chip->suspend(chip);
+ return 0;
+}
+
+static int snd_cs4231_pm_resume(snd_card_t *card)
+{
+ cs4231_t *chip = card->pm_private_data;
+ if (chip->resume)
+ chip->resume(chip);
+ return 0;
+}
+#endif /* CONFIG_PM */
+
+#ifdef LEGACY_SUPPORT
+
+static int snd_cs4231_free(cs4231_t *chip)
+{
+ if (chip->res_port) {
+ release_resource(chip->res_port);
+ kfree_nocheck(chip->res_port);
+ }
+ if (chip->res_cport) {
+ release_resource(chip->res_cport);
+ kfree_nocheck(chip->res_cport);
+ }
+ if (chip->irq >= 0) {
+ disable_irq(chip->irq);
+ if (!(chip->hwshare & CS4231_HWSHARE_IRQ))
+ free_irq(chip->irq, (void *) chip);
+ }
+ if (!(chip->hwshare & CS4231_HWSHARE_DMA1) && chip->dma1 >= 0) {
+ snd_dma_disable(chip->dma1);
+ free_dma(chip->dma1);
+ }
+ if (!(chip->hwshare & CS4231_HWSHARE_DMA2) && chip->dma2 >= 0 && chip->dma2 != chip->dma1) {
+ snd_dma_disable(chip->dma2);
+ free_dma(chip->dma2);
+ }
+ if (chip->timer)
+ snd_device_free(chip->card, chip->timer);
+ kfree(chip);
+ return 0;
+}
+
+static int snd_cs4231_dev_free(snd_device_t *device)
+{
+ cs4231_t *chip = device->device_data;
+ return snd_cs4231_free(chip);
+}
+
+#endif /* LEGACY_SUPPORT */
+
+const char *snd_cs4231_chip_id(cs4231_t *chip)
+{
+ switch (chip->hardware) {
+ case CS4231_HW_CS4231: return "CS4231";
+ case CS4231_HW_CS4231A: return "CS4231A";
+ case CS4231_HW_CS4232: return "CS4232";
+ case CS4231_HW_CS4232A: return "CS4232A";
+ case CS4231_HW_CS4235: return "CS4235";
+ case CS4231_HW_CS4236: return "CS4236";
+ case CS4231_HW_CS4236B: return "CS4236B";
+ case CS4231_HW_CS4237B: return "CS4237B";
+ case CS4231_HW_CS4238B: return "CS4238B";
+ case CS4231_HW_CS4239: return "CS4239";
+ case CS4231_HW_INTERWAVE: return "AMD InterWave";
+ case CS4231_HW_OPL3SA2: return chip->card->shortname;
+ case CS4231_HW_AD1845: return "AD1845";
+ default: return "???";
+ }
+}
+
+static int snd_cs4231_new(snd_card_t * card,
+ unsigned short hardware,
+ unsigned short hwshare,
+ cs4231_t ** rchip)
+{
+ cs4231_t *chip;
+
+ *rchip = NULL;
+ chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
+ if (chip == NULL)
+ return -ENOMEM;
+ chip->hardware = hardware;
+ chip->hwshare = hwshare;
+
+ spin_lock_init(&chip->reg_lock);
+ init_MUTEX(&chip->mce_mutex);
+ init_MUTEX(&chip->open_mutex);
+ chip->card = card;
+ chip->rate_constraint = snd_cs4231_xrate;
+ chip->set_playback_format = snd_cs4231_playback_format;
+ chip->set_capture_format = snd_cs4231_capture_format;
+ memcpy(&chip->image, &snd_cs4231_original_image, sizeof(snd_cs4231_original_image));
+
+ *rchip = chip;
+ return 0;
+}
+
+#ifdef LEGACY_SUPPORT
+
+int snd_cs4231_create(snd_card_t * card,
+ unsigned long port,
+ unsigned long cport,
+ int irq, int dma1, int dma2,
+ unsigned short hardware,
+ unsigned short hwshare,
+ cs4231_t ** rchip)
+{
+ static snd_device_ops_t ops = {
+ .dev_free = snd_cs4231_dev_free,
+ };
+ cs4231_t *chip;
+ int err;
+
+ err = snd_cs4231_new(card, hardware, hwshare, &chip);
+ if (err < 0)
+ return err;
+
+ chip->irq = -1;
+ chip->dma1 = -1;
+ chip->dma2 = -1;
+
+ if ((chip->res_port = request_region(port, 4, "CS4231")) == NULL) {
+ snd_printk(KERN_ERR "cs4231: can't grab port 0x%lx\n", port);
+ snd_cs4231_free(chip);
+ return -EBUSY;
+ }
+ chip->port = port;
+ if ((long)cport >= 0 && (chip->res_cport = request_region(cport, 8, "CS4232 Control")) == NULL) {
+ snd_printk(KERN_ERR "cs4231: can't grab control port 0x%lx\n", cport);
+ snd_cs4231_free(chip);
+ return -ENODEV;
+ }
+ chip->cport = cport;
+ if (!(hwshare & CS4231_HWSHARE_IRQ) && request_irq(irq, snd_cs4231_interrupt, SA_INTERRUPT, "CS4231", (void *) chip)) {
+ snd_printk(KERN_ERR "cs4231: can't grab IRQ %d\n", irq);
+ snd_cs4231_free(chip);
+ return -EBUSY;
+ }
+ chip->irq = irq;
+ if (!(hwshare & CS4231_HWSHARE_DMA1) && request_dma(dma1, "CS4231 - 1")) {
+ snd_printk(KERN_ERR "cs4231: can't grab DMA1 %d\n", dma1);
+ snd_cs4231_free(chip);
+ return -EBUSY;
+ }
+ chip->dma1 = dma1;
+ if (!(hwshare & CS4231_HWSHARE_DMA2) && dma1 != dma2 && dma2 >= 0 && request_dma(dma2, "CS4231 - 2")) {
+ snd_printk(KERN_ERR "cs4231: can't grab DMA2 %d\n", dma2);
+ snd_cs4231_free(chip);
+ return -EBUSY;
+ }
+ if (dma1 == dma2 || dma2 < 0) {
+ chip->single_dma = 1;
+ chip->dma2 = chip->dma1;
+ } else
+ chip->dma2 = dma2;
+
+ /* global setup */
+ if (snd_cs4231_probe(chip) < 0) {
+ snd_cs4231_free(chip);
+ return -ENODEV;
+ }
+ snd_cs4231_init(chip);
+
+ if (chip->hardware & CS4231_HW_CS4232_MASK) {
+ if (chip->res_cport == NULL)
+ snd_printk("CS4232 control port features are not accessible\n");
+ }
+
+ /* Register device */
+ if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
+ snd_cs4231_free(chip);
+ return err;
+ }
+
+#ifdef CONFIG_PM
+ /* Power Management */
+ chip->suspend = snd_cs4231_suspend;
+ chip->resume = snd_cs4231_resume;
+ snd_card_set_isa_pm_callback(card, snd_cs4231_pm_suspend, snd_cs4231_pm_resume, chip);
+#endif
+
+ *rchip = chip;
+ return 0;
+}
+
+#endif /* LEGACY_SUPPORT */
+
+static snd_pcm_ops_t snd_cs4231_playback_ops = {
+ .open = snd_cs4231_playback_open,
+ .close = snd_cs4231_playback_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_cs4231_playback_hw_params,
+ .hw_free = snd_cs4231_playback_hw_free,
+ .prepare = snd_cs4231_playback_prepare,
+ .trigger = snd_cs4231_trigger,
+ .pointer = snd_cs4231_playback_pointer,
+};
+
+static snd_pcm_ops_t snd_cs4231_capture_ops = {
+ .open = snd_cs4231_capture_open,
+ .close = snd_cs4231_capture_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_cs4231_capture_hw_params,
+ .hw_free = snd_cs4231_capture_hw_free,
+ .prepare = snd_cs4231_capture_prepare,
+ .trigger = snd_cs4231_trigger,
+ .pointer = snd_cs4231_capture_pointer,
+};
+
+static void snd_cs4231_pcm_free(snd_pcm_t *pcm)
+{
+ cs4231_t *chip = pcm->private_data;
+ chip->pcm = NULL;
+ snd_pcm_lib_preallocate_free_for_all(pcm);
+}
+
+int snd_cs4231_pcm(cs4231_t *chip, int device, snd_pcm_t **rpcm)
+{
+ snd_pcm_t *pcm;
+ int err;
+
+ if ((err = snd_pcm_new(chip->card, "CS4231", device, 1, 1, &pcm)) < 0)
+ return err;
+
+ spin_lock_init(&chip->reg_lock);
+ init_MUTEX(&chip->mce_mutex);
+ init_MUTEX(&chip->open_mutex);
+
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs4231_playback_ops);
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cs4231_capture_ops);
+
+ /* global setup */
+ pcm->private_data = chip;
+ pcm->private_free = snd_cs4231_pcm_free;
+ pcm->info_flags = 0;
+ if (chip->single_dma)
+ pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX;
+ if (chip->hardware != CS4231_HW_INTERWAVE)
+ pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX;
+ strcpy(pcm->name, snd_cs4231_chip_id(chip));
+
+#ifdef LEGACY_SUPPORT
+ snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
+ snd_dma_isa_data(),
+ 64*1024, chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
+#else
+# ifdef EBUS_SUPPORT
+ if (chip->ebus_flag) {
+ snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
+ chip->dev_u.pdev,
+ 64*1024, 128*1024);
+ } else {
+# endif
+# ifdef SBUS_SUPPORT
+ snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_SBUS,
+ chip->dev_u.sdev,
+ 64*1024, 128*1024);
+# endif
+# ifdef EBUS_SUPPORT
+ }
+# endif
+#endif
+
+ chip->pcm = pcm;
+ if (rpcm)
+ *rpcm = pcm;
+ return 0;
+}
+
+static void snd_cs4231_timer_free(snd_timer_t *timer)
+{
+ cs4231_t *chip = timer->private_data;
+ chip->timer = NULL;
+}
+
+int snd_cs4231_timer(cs4231_t *chip, int device, snd_timer_t **rtimer)
+{
+ snd_timer_t *timer;
+ snd_timer_id_t tid;
+ int err;
+
+ /* Timer initialization */
+ tid.dev_class = SNDRV_TIMER_CLASS_CARD;
+ tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
+ tid.card = chip->card->number;
+ tid.device = device;
+ tid.subdevice = 0;
+ if ((err = snd_timer_new(chip->card, "CS4231", &tid, &timer)) < 0)
+ return err;
+ strcpy(timer->name, snd_cs4231_chip_id(chip));
+ timer->private_data = chip;
+ timer->private_free = snd_cs4231_timer_free;
+ timer->hw = snd_cs4231_timer_table;
+ chip->timer = timer;
+ if (rtimer)
+ *rtimer = timer;
+ return 0;
+}
+
+/*
+ * MIXER part
+ */
+
+static int snd_cs4231_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ static char *texts[4] = {
+ "Line", "Aux", "Mic", "Mix"
+ };
+ static char *opl3sa_texts[4] = {
+ "Line", "CD", "Mic", "Mix"
+ };
+ static char *gusmax_texts[4] = {
+ "Line", "Synth", "Mic", "Mix"
+ };
+ char **ptexts = texts;
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+
+ snd_assert(chip->card != NULL, return -EINVAL);
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+ uinfo->count = 2;
+ uinfo->value.enumerated.items = 4;
+ if (uinfo->value.enumerated.item > 3)
+ uinfo->value.enumerated.item = 3;
+ if (!strcmp(chip->card->driver, "GUS MAX"))
+ ptexts = gusmax_texts;
+ switch (chip->hardware) {
+ case CS4231_HW_INTERWAVE: ptexts = gusmax_texts; break;
+ case CS4231_HW_OPL3SA2: ptexts = opl3sa_texts; break;
+ }
+ strcpy(uinfo->value.enumerated.name, ptexts[uinfo->value.enumerated.item]);
+ return 0;
+}
+
+static int snd_cs4231_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.enumerated.item[0] = (chip->image[CS4231_LEFT_INPUT] & CS4231_MIXS_ALL) >> 6;
+ ucontrol->value.enumerated.item[1] = (chip->image[CS4231_RIGHT_INPUT] & CS4231_MIXS_ALL) >> 6;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return 0;
+}
+
+static int snd_cs4231_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ unsigned short left, right;
+ int change;
+
+ if (ucontrol->value.enumerated.item[0] > 3 ||
+ ucontrol->value.enumerated.item[1] > 3)
+ return -EINVAL;
+ left = ucontrol->value.enumerated.item[0] << 6;
+ right = ucontrol->value.enumerated.item[1] << 6;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ left = (chip->image[CS4231_LEFT_INPUT] & ~CS4231_MIXS_ALL) | left;
+ right = (chip->image[CS4231_RIGHT_INPUT] & ~CS4231_MIXS_ALL) | right;
+ change = left != chip->image[CS4231_LEFT_INPUT] ||
+ right != chip->image[CS4231_RIGHT_INPUT];
+ snd_cs4231_out(chip, CS4231_LEFT_INPUT, left);
+ snd_cs4231_out(chip, CS4231_RIGHT_INPUT, right);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+int snd_cs4231_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+
+ uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = mask;
+ return 0;
+}
+
+int snd_cs4231_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (invert)
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ return 0;
+}
+
+int snd_cs4231_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+ int change;
+ unsigned short val;
+
+ val = (ucontrol->value.integer.value[0] & mask);
+ if (invert)
+ val = mask - val;
+ val <<= shift;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ val = (chip->image[reg] & ~(mask << shift)) | val;
+ change = val != chip->image[reg];
+ snd_cs4231_out(chip, reg, val);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+int snd_cs4231_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+
+ uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 2;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = mask;
+ return 0;
+}
+
+int snd_cs4231_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int left_reg = kcontrol->private_value & 0xff;
+ int right_reg = (kcontrol->private_value >> 8) & 0xff;
+ int shift_left = (kcontrol->private_value >> 16) & 0x07;
+ int shift_right = (kcontrol->private_value >> 19) & 0x07;
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+ int invert = (kcontrol->private_value >> 22) & 1;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
+ ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (invert) {
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
+ }
+ return 0;
+}
+
+int snd_cs4231_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int left_reg = kcontrol->private_value & 0xff;
+ int right_reg = (kcontrol->private_value >> 8) & 0xff;
+ int shift_left = (kcontrol->private_value >> 16) & 0x07;
+ int shift_right = (kcontrol->private_value >> 19) & 0x07;
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+ int invert = (kcontrol->private_value >> 22) & 1;
+ int change;
+ unsigned short val1, val2;
+
+ val1 = ucontrol->value.integer.value[0] & mask;
+ val2 = ucontrol->value.integer.value[1] & mask;
+ if (invert) {
+ val1 = mask - val1;
+ val2 = mask - val2;
+ }
+ val1 <<= shift_left;
+ val2 <<= shift_right;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
+ val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
+ change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg];
+ snd_cs4231_out(chip, left_reg, val1);
+ snd_cs4231_out(chip, right_reg, val2);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+static snd_kcontrol_new_t snd_cs4231_controls[] = {
+CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
+CS4231_DOUBLE("Line Playback Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
+CS4231_DOUBLE("Line Playback Volume", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1),
+CS4231_DOUBLE("Aux Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("Aux Playback Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
+CS4231_DOUBLE("Aux Playback Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("Aux Playback Volume", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
+CS4231_SINGLE("Mono Playback Switch", 0, CS4231_MONO_CTRL, 7, 1, 1),
+CS4231_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
+CS4231_SINGLE("Mono Output Playback Switch", 0, CS4231_MONO_CTRL, 6, 1, 1),
+CS4231_SINGLE("Mono Output Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0),
+CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "Capture Source",
+ .info = snd_cs4231_info_mux,
+ .get = snd_cs4231_get_mux,
+ .put = snd_cs4231_put_mux,
+},
+CS4231_DOUBLE("Mic Boost", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
+CS4231_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0),
+CS4231_SINGLE("Loopback Capture Volume", 0, CS4231_LOOPBACK, 2, 63, 1)
+};
+
+int snd_cs4231_mixer(cs4231_t *chip)
+{
+ snd_card_t *card;
+ unsigned int idx;
+ int err;
+
+ snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL);
+
+ card = chip->card;
+
+ strcpy(card->mixername, chip->pcm->name);
+
+ for (idx = 0; idx < ARRAY_SIZE(snd_cs4231_controls); idx++) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4231_controls[idx], chip))) < 0)
+ return err;
+ }
+ return 0;
+}
+
+EXPORT_SYMBOL(snd_cs4231_out);
+EXPORT_SYMBOL(snd_cs4231_in);
+EXPORT_SYMBOL(snd_cs4236_ext_out);
+EXPORT_SYMBOL(snd_cs4236_ext_in);
+EXPORT_SYMBOL(snd_cs4231_mce_up);
+EXPORT_SYMBOL(snd_cs4231_mce_down);
+EXPORT_SYMBOL(snd_cs4231_interrupt);
+EXPORT_SYMBOL(snd_cs4231_chip_id);
+EXPORT_SYMBOL(snd_cs4231_create);
+EXPORT_SYMBOL(snd_cs4231_pcm);
+EXPORT_SYMBOL(snd_cs4231_mixer);
+EXPORT_SYMBOL(snd_cs4231_timer);
+EXPORT_SYMBOL(snd_cs4231_info_single);
+EXPORT_SYMBOL(snd_cs4231_get_single);
+EXPORT_SYMBOL(snd_cs4231_put_single);
+EXPORT_SYMBOL(snd_cs4231_info_double);
+EXPORT_SYMBOL(snd_cs4231_get_double);
+EXPORT_SYMBOL(snd_cs4231_put_double);
+
+/*
+ * INIT part
+ */
+
+static int __init alsa_cs4231_init(void)
+{
+ return 0;
+}
+
+static void __exit alsa_cs4231_exit(void)
+{
+}
+
+module_init(alsa_cs4231_init)
+module_exit(alsa_cs4231_exit)
diff --git a/sound/isa/cs423x/cs4232.c b/sound/isa/cs423x/cs4232.c
new file mode 100644
index 000000000000..9fad2e6c0c2c
--- /dev/null
+++ b/sound/isa/cs423x/cs4232.c
@@ -0,0 +1,2 @@
+#define CS4232
+#include "cs4236.c"
diff --git a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c
new file mode 100644
index 000000000000..e745a54e00a1
--- /dev/null
+++ b/sound/isa/cs423x/cs4236.c
@@ -0,0 +1,608 @@
+/*
+ * Driver for generic CS4232/CS4235/CS4236/CS4236B/CS4237B/CS4238B/CS4239 chips
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/pnp.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/cs4231.h>
+#include <sound/mpu401.h>
+#include <sound/opl3.h>
+#include <sound/initval.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_LICENSE("GPL");
+#ifdef CS4232
+MODULE_DESCRIPTION("Cirrus Logic CS4232");
+MODULE_SUPPORTED_DEVICE("{{Turtle Beach,TBS-2000},"
+ "{Turtle Beach,Tropez Plus},"
+ "{SIC CrystalWave 32},"
+ "{Hewlett Packard,Omnibook 5500},"
+ "{TerraTec,Maestro 32/96},"
+ "{Philips,PCA70PS}}");
+#else
+MODULE_DESCRIPTION("Cirrus Logic CS4235-9");
+MODULE_SUPPORTED_DEVICE("{{Crystal Semiconductors,CS4235},"
+ "{Crystal Semiconductors,CS4236},"
+ "{Crystal Semiconductors,CS4237},"
+ "{Crystal Semiconductors,CS4238},"
+ "{Crystal Semiconductors,CS4239},"
+ "{Acer,AW37},"
+ "{Acer,AW35/Pro},"
+ "{Crystal,3D},"
+ "{Crystal Computer,TidalWave128},"
+ "{Dell,Optiplex GX1},"
+ "{Dell,Workstation 400 sound},"
+ "{EliteGroup,P5TX-LA sound},"
+ "{Gallant,SC-70P},"
+ "{Gateway,E1000 Onboard CS4236B},"
+ "{Genius,Sound Maker 3DJ},"
+ "{Hewlett Packard,HP6330 sound},"
+ "{IBM,PC 300PL sound},"
+ "{IBM,Aptiva 2137 E24},"
+ "{IBM,IntelliStation M Pro},"
+ "{Intel,Marlin Spike Mobo CS4235},"
+ "{Intel PR440FX Onboard},"
+ "{Guillemot,MaxiSound 16 PnP},"
+ "{NewClear,3D},"
+ "{TerraTec,AudioSystem EWS64L/XL},"
+ "{Typhoon Soundsystem,CS4236B},"
+ "{Turtle Beach,Malibu},"
+ "{Unknown,Digital PC 5000 Onboard}}");
+#endif
+
+#ifdef CS4232
+#define IDENT "CS4232"
+#else
+#define IDENT "CS4236+"
+#endif
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
+#ifdef CONFIG_PNP
+static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
+#endif
+static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */
+static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
+static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
+static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
+static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
+#ifdef CONFIG_PNP
+module_param_array(isapnp, bool, NULL, 0444);
+MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
+#endif
+module_param_array(port, long, NULL, 0444);
+MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
+module_param_array(cport, long, NULL, 0444);
+MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
+module_param_array(mpu_port, long, NULL, 0444);
+MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
+module_param_array(fm_port, long, NULL, 0444);
+MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
+module_param_array(sb_port, long, NULL, 0444);
+MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional).");
+module_param_array(irq, int, NULL, 0444);
+MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
+module_param_array(mpu_irq, int, NULL, 0444);
+MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
+module_param_array(dma1, int, NULL, 0444);
+MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
+module_param_array(dma2, int, NULL, 0444);
+MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
+
+struct snd_card_cs4236 {
+ struct resource *res_sb_port;
+#ifdef CONFIG_PNP
+ struct pnp_dev *wss;
+ struct pnp_dev *ctrl;
+ struct pnp_dev *mpu;
+#endif
+};
+
+static snd_card_t *snd_cs4236_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
+
+#ifdef CONFIG_PNP
+
+#define ISAPNP_CS4232(_va, _vb, _vc, _device, _wss, _ctrl, _mpu401) \
+ { \
+ ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
+ .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _wss), \
+ ISAPNP_DEVICE_ID(_va, _vb, _vc, _ctrl), \
+ ISAPNP_DEVICE_ID(_va, _vb, _vc, _mpu401) } \
+ }
+#define ISAPNP_CS4232_1(_va, _vb, _vc, _device, _wss, _ctrl, _mpu401) \
+ { \
+ ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
+ .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _wss), \
+ ISAPNP_DEVICE_ID(_va, _vb, _vc, _ctrl), \
+ ISAPNP_DEVICE_ID('P', 'N', 'P', _mpu401) } \
+ }
+#define ISAPNP_CS4232_WOMPU(_va, _vb, _vc, _device, _wss, _ctrl) \
+ { \
+ ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
+ .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _wss), \
+ ISAPNP_DEVICE_ID(_va, _vb, _vc, _ctrl) } \
+ }
+
+
+#ifdef CS4232
+static struct pnp_card_device_id snd_cs423x_pnpids[] = {
+ /* Philips PCA70PS */
+ { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
+ /* TerraTec Maestro 32/96 (CS4232) */
+ { .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* HP Omnibook 5500 onboard */
+ { .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } },
+ /* Unnamed CS4236 card (Made in Taiwan) */
+ { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* Turtle Beach TBS-2000 (CS4232) */
+ { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } },
+ /* Turtle Beach Tropez Plus (CS4232) */
+ { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
+ /* SIC CrystalWave 32 (CS4232) */
+ { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* --- */
+ { .id = "" } /* end */
+};
+#else /* CS4236 */
+static struct pnp_card_device_id snd_cs423x_pnpids[] = {
+ /* Intel Marlin Spike Motherboard - CS4235 */
+ { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* Intel Marlin Spike Motherboard (#2) - CS4235 */
+ { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
+ /* Unknown Intel mainboard - CS4235 */
+ { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } },
+ /* Genius Sound Maker 3DJ - CS4237B */
+ { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* Digital PC 5000 Onboard - CS4236B */
+ { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
+ /* some uknown CS4236B */
+ { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* Intel PR440FX Onboard sound */
+ { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* CS4235 on mainboard without MPU */
+ { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
+ /* Gateway E1000 Onboard CS4236B */
+ { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* HP 6330 Onboard sound */
+ { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
+ /* Crystal Computer TidalWave128 */
+ { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* ACER AW37 - CS4235 */
+ { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */
+ { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* Crystal 3D - CS4237B */
+ { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* Typhoon Soundsystem PnP - CS4236B */
+ { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* Crystal CX4235-XQ3 EP - CS4235 */
+ { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
+ /* Crystal Semiconductors CS4237B */
+ { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* NewClear 3D - CX4237B-XQ3 */
+ { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* Dell Optiplex GX1 - CS4236B */
+ { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* Dell P410 motherboard - CS4236B */
+ { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
+ /* Dell Workstation 400 Onboard - CS4236B */
+ { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* Turtle Beach Malibu - CS4237B */
+ { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* CS4235 - onboard */
+ { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
+ /* IBM Aptiva 2137 E24 Onboard - CS4237B */
+ { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* IBM IntelliStation M Pro motherboard */
+ { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
+ /* Guillemot MaxiSound 16 PnP - CS4236B */
+ { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* Gallant SC-70P */
+ { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* TerraTec AudioSystem EWS64XL - CS4236B */
+ { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } },
+ /* TerraTec AudioSystem EWS64XL - CS4236B */
+ { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } },
+ /* ACER AW37/Pro - CS4235 */
+ { .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* ACER AW35/Pro - CS4237B */
+ { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* CS4235 without MPU401 */
+ { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } },
+ /* Unknown SiS530 - CS4235 */
+ { .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } },
+ /* IBM IntelliStation M Pro 6898 11U - CS4236B */
+ { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } },
+ /* IBM PC 300PL Onboard - CS4236B */
+ { .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } },
+ /* Some noname CS4236 based card */
+ { .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* CS4236B */
+ { .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* CS4236B */
+ { .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
+ /* --- */
+ { .id = "" } /* end */
+};
+#endif
+
+MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
+
+static int __devinit snd_card_cs4236_pnp(int dev, struct snd_card_cs4236 *acard,
+ struct pnp_card_link *card,
+ const struct pnp_card_device_id *id)
+{
+ struct pnp_dev *pdev;
+ struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
+ int err;
+
+ if (!cfg)
+ return -ENOMEM;
+
+ acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
+ if (acard->wss == NULL) {
+ kfree(cfg);
+ return -EBUSY;
+ }
+ acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
+ if (acard->ctrl == NULL) {
+ kfree(cfg);
+ return -EBUSY;
+ }
+ if (id->devs[2].id[0]) {
+ acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
+ if (acard->mpu == NULL) {
+ kfree(cfg);
+ return -EBUSY;
+ }
+ }
+
+ /* WSS initialization */
+ pdev = acard->wss;
+ pnp_init_resource_table(cfg);
+ if (port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], port[dev], 4);
+ if (fm_port[dev] != SNDRV_AUTO_PORT && fm_port[dev] > 0)
+ pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
+ if (sb_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[2], sb_port[dev], 16);
+ if (irq[dev] != SNDRV_AUTO_IRQ)
+ pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
+ if (dma1[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
+ if (dma2[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[1], dma2[dev] < 0 ? 4 : dma2[dev], 1);
+ err = pnp_manual_config_dev(pdev, cfg, 0);
+ if (err < 0)
+ snd_printk(KERN_ERR IDENT " WSS PnP manual resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ kfree(cfg);
+ printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n");
+ return -EBUSY;
+ }
+ port[dev] = pnp_port_start(pdev, 0);
+ if (fm_port[dev] > 0)
+ fm_port[dev] = pnp_port_start(pdev, 1);
+ sb_port[dev] = pnp_port_start(pdev, 2);
+ irq[dev] = pnp_irq(pdev, 0);
+ dma1[dev] = pnp_dma(pdev, 0);
+ dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1);
+ snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
+ port[dev], fm_port[dev], sb_port[dev]);
+ snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n",
+ irq[dev], dma1[dev], dma2[dev]);
+ /* CTRL initialization */
+ if (acard->ctrl && cport[dev] > 0) {
+ pdev = acard->ctrl;
+ pnp_init_resource_table(cfg);
+ if (cport[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], cport[dev], 8);
+ err = pnp_manual_config_dev(pdev, cfg, 0);
+ if (err < 0)
+ snd_printk(KERN_ERR IDENT " CTRL PnP manual resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ kfree(cfg);
+ printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
+ return -EBUSY;
+ }
+ cport[dev] = pnp_port_start(pdev, 0);
+ snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]);
+ }
+ /* MPU initialization */
+ if (acard->mpu && mpu_port[dev] > 0) {
+ pdev = acard->mpu;
+ pnp_init_resource_table(cfg);
+ if (mpu_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
+ if (mpu_irq[dev] != SNDRV_AUTO_IRQ && mpu_irq[dev] >= 0 &&
+ pnp_irq_valid(pdev, 0))
+ pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
+ err = pnp_manual_config_dev(pdev, cfg, 0);
+ if (err < 0)
+ snd_printk(KERN_ERR IDENT " MPU401 PnP manual resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
+ mpu_port[dev] = SNDRV_AUTO_PORT;
+ mpu_irq[dev] = SNDRV_AUTO_IRQ;
+ } else {
+ mpu_port[dev] = pnp_port_start(pdev, 0);
+ if (mpu_irq[dev] >= 0 &&
+ pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) {
+ mpu_irq[dev] = pnp_irq(pdev, 0);
+ } else {
+ mpu_irq[dev] = -1; /* disable interrupt */
+ }
+ }
+ snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
+ }
+ kfree(cfg);
+ return 0;
+}
+#endif /* CONFIG_PNP */
+
+static void snd_card_cs4236_free(snd_card_t *card)
+{
+ struct snd_card_cs4236 *acard = (struct snd_card_cs4236 *)card->private_data;
+
+ if (acard) {
+ if (acard->res_sb_port) {
+ release_resource(acard->res_sb_port);
+ kfree_nocheck(acard->res_sb_port);
+ }
+ }
+}
+
+static int __devinit snd_card_cs423x_probe(int dev, struct pnp_card_link *pcard,
+ const struct pnp_card_device_id *pid)
+{
+ snd_card_t *card;
+ struct snd_card_cs4236 *acard;
+ snd_pcm_t *pcm = NULL;
+ cs4231_t *chip;
+ opl3_t *opl3;
+ int err;
+
+#ifdef CONFIG_PNP
+ if (!isapnp[dev]) {
+#endif
+ if (port[dev] == SNDRV_AUTO_PORT) {
+ snd_printk("specify port\n");
+ return -EINVAL;
+ }
+ if (cport[dev] == SNDRV_AUTO_PORT) {
+ snd_printk("specify cport\n");
+ return -EINVAL;
+ }
+#ifdef CONFIG_PNP
+ }
+#endif
+ card = snd_card_new(index[dev], id[dev], THIS_MODULE,
+ sizeof(struct snd_card_cs4236));
+ if (card == NULL)
+ return -ENOMEM;
+ acard = (struct snd_card_cs4236 *)card->private_data;
+ card->private_free = snd_card_cs4236_free;
+#ifdef CONFIG_PNP
+ if (isapnp[dev]) {
+ if ((err = snd_card_cs4236_pnp(dev, acard, pcard, pid))<0) {
+ printk(KERN_ERR "isapnp detection failed and probing for " IDENT " is not supported\n");
+ snd_card_free(card);
+ return -ENXIO;
+ }
+ snd_card_set_dev(card, &pcard->card->dev);
+ }
+#endif
+ if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
+ if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
+ printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
+ snd_card_free(card);
+ return -ENOMEM;
+ }
+
+#ifdef CS4232
+ if ((err = snd_cs4231_create(card,
+ port[dev],
+ cport[dev],
+ irq[dev],
+ dma1[dev],
+ dma2[dev],
+ CS4231_HW_DETECT,
+ 0,
+ &chip)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if ((err = snd_cs4231_mixer(chip)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+
+#else /* CS4236 */
+ if ((err = snd_cs4236_create(card,
+ port[dev],
+ cport[dev],
+ irq[dev],
+ dma1[dev],
+ dma2[dev],
+ CS4231_HW_DETECT,
+ 0,
+ &chip)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if ((err = snd_cs4236_pcm(chip, 0, &pcm)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if ((err = snd_cs4236_mixer(chip)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+#endif
+ strcpy(card->driver, pcm->name);
+ strcpy(card->shortname, pcm->name);
+ sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
+ pcm->name,
+ chip->port,
+ irq[dev],
+ dma1[dev]);
+ if (dma2[dev] >= 0)
+ sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
+
+ if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+
+ if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
+ if (snd_opl3_create(card,
+ fm_port[dev], fm_port[dev] + 2,
+ OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
+ printk(KERN_ERR IDENT ": OPL3 not detected\n");
+ } else {
+ if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ }
+ }
+
+ if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
+ if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
+ mpu_irq[dev] = -1;
+ if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
+ mpu_port[dev], 0,
+ mpu_irq[dev],
+ mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0, NULL) < 0)
+ printk(KERN_ERR IDENT ": MPU401 not detected\n");
+ }
+ if ((err = snd_card_register(card)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if (pcard)
+ pnp_set_card_drvdata(pcard, card);
+ else
+ snd_cs4236_legacy[dev] = card;
+ return 0;
+}
+
+#ifdef CONFIG_PNP
+static int __devinit snd_cs423x_pnp_detect(struct pnp_card_link *card,
+ const struct pnp_card_device_id *id)
+{
+ static int dev;
+ int res;
+
+ for ( ; dev < SNDRV_CARDS; dev++) {
+ if (!enable[dev] || !isapnp[dev])
+ continue;
+ res = snd_card_cs423x_probe(dev, card, id);
+ if (res < 0)
+ return res;
+ dev++;
+ return 0;
+ }
+ return -ENODEV;
+}
+
+static void __devexit snd_cs423x_pnp_remove(struct pnp_card_link * pcard)
+{
+ snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
+
+ snd_card_disconnect(card);
+ snd_card_free_in_thread(card);
+}
+
+static struct pnp_card_driver cs423x_pnpc_driver = {
+ .flags = PNP_DRIVER_RES_DISABLE,
+ .name = "cs423x",
+ .id_table = snd_cs423x_pnpids,
+ .probe = snd_cs423x_pnp_detect,
+ .remove = __devexit_p(snd_cs423x_pnp_remove),
+};
+#endif /* CONFIG_PNP */
+
+static int __init alsa_card_cs423x_init(void)
+{
+ int dev, cards = 0;
+
+ for (dev = 0; dev < SNDRV_CARDS; dev++) {
+ if (!enable[dev])
+ continue;
+#ifdef CONFIG_PNP
+ if (isapnp[dev])
+ continue;
+#endif
+ if (snd_card_cs423x_probe(dev, NULL, NULL) >= 0)
+ cards++;
+ }
+#ifdef CONFIG_PNP
+ cards += pnp_register_card_driver(&cs423x_pnpc_driver);
+#endif
+ if (!cards) {
+#ifdef CONFIG_PNP
+ pnp_unregister_card_driver(&cs423x_pnpc_driver);
+#endif
+#ifdef MODULE
+ printk(KERN_ERR IDENT " soundcard not found or device busy\n");
+#endif
+ return -ENODEV;
+ }
+ return 0;
+}
+
+static void __exit alsa_card_cs423x_exit(void)
+{
+ int idx;
+
+#ifdef CONFIG_PNP
+ /* PnP cards first */
+ pnp_unregister_card_driver(&cs423x_pnpc_driver);
+#endif
+ for (idx = 0; idx < SNDRV_CARDS; idx++)
+ snd_card_free(snd_cs4236_legacy[idx]);
+}
+
+module_init(alsa_card_cs423x_init)
+module_exit(alsa_card_cs423x_exit)
diff --git a/sound/isa/cs423x/cs4236_lib.c b/sound/isa/cs423x/cs4236_lib.c
new file mode 100644
index 000000000000..2128d4bdef41
--- /dev/null
+++ b/sound/isa/cs423x/cs4236_lib.c
@@ -0,0 +1,970 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ * Routines for control of CS4235/4236B/4237B/4238B/4239 chips
+ *
+ * Note:
+ * -----
+ *
+ * Bugs:
+ * -----
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*
+ * Indirect control registers (CS4236B+)
+ *
+ * C0
+ * D8: WSS reset (all chips)
+ *
+ * C1 (all chips except CS4236)
+ * D7-D5: version
+ * D4-D0: chip id
+ * 11101 - CS4235
+ * 01011 - CS4236B
+ * 01000 - CS4237B
+ * 01001 - CS4238B
+ * 11110 - CS4239
+ *
+ * C2
+ * D7-D4: 3D Space (CS4235,CS4237B,CS4238B,CS4239)
+ * D3-D0: 3D Center (CS4237B); 3D Volume (CS4238B)
+ *
+ * C3
+ * D7: 3D Enable (CS4237B)
+ * D6: 3D Mono Enable (CS4237B)
+ * D5: 3D Serial Output (CS4237B,CS4238B)
+ * D4: 3D Enable (CS4235,CS4238B,CS4239)
+ *
+ * C4
+ * D7: consumer serial port enable (CS4237B,CS4238B)
+ * D6: channels status block reset (CS4237B,CS4238B)
+ * D5: user bit in sub-frame of digital audio data (CS4237B,CS4238B)
+ * D4: validity bit bit in sub-frame of digital audio data (CS4237B,CS4238B)
+ *
+ * C5 lower channel status (digital serial data description) (CS4237B,CS4238B)
+ * D7-D6: first two bits of category code
+ * D5: lock
+ * D4-D3: pre-emphasis (0 = none, 1 = 50/15us)
+ * D2: copy/copyright (0 = copy inhibited)
+ * D1: 0 = digital audio / 1 = non-digital audio
+ *
+ * C6 upper channel status (digital serial data description) (CS4237B,CS4238B)
+ * D7-D6: sample frequency (0 = 44.1kHz)
+ * D5: generation status (0 = no indication, 1 = original/commercially precaptureed data)
+ * D4-D0: category code (upper bits)
+ *
+ * C7 reserved (must write 0)
+ *
+ * C8 wavetable control
+ * D7: volume control interrupt enable (CS4235,CS4239)
+ * D6: hardware volume control format (CS4235,CS4239)
+ * D3: wavetable serial port enable (all chips)
+ * D2: DSP serial port switch (all chips)
+ * D1: disable MCLK (all chips)
+ * D0: force BRESET low (all chips)
+ *
+ */
+
+#include <sound/driver.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/time.h>
+#include <linux/wait.h>
+#include <sound/core.h>
+#include <sound/cs4231.h>
+#include <sound/asoundef.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("Routines for control of CS4235/4236B/4237B/4238B/4239 chips");
+MODULE_LICENSE("GPL");
+
+/*
+ *
+ */
+
+static unsigned char snd_cs4236_ext_map[18] = {
+ /* CS4236_LEFT_LINE */ 0xff,
+ /* CS4236_RIGHT_LINE */ 0xff,
+ /* CS4236_LEFT_MIC */ 0xdf,
+ /* CS4236_RIGHT_MIC */ 0xdf,
+ /* CS4236_LEFT_MIX_CTRL */ 0xe0 | 0x18,
+ /* CS4236_RIGHT_MIX_CTRL */ 0xe0,
+ /* CS4236_LEFT_FM */ 0xbf,
+ /* CS4236_RIGHT_FM */ 0xbf,
+ /* CS4236_LEFT_DSP */ 0xbf,
+ /* CS4236_RIGHT_DSP */ 0xbf,
+ /* CS4236_RIGHT_LOOPBACK */ 0xbf,
+ /* CS4236_DAC_MUTE */ 0xe0,
+ /* CS4236_ADC_RATE */ 0x01, /* 48kHz */
+ /* CS4236_DAC_RATE */ 0x01, /* 48kHz */
+ /* CS4236_LEFT_MASTER */ 0xbf,
+ /* CS4236_RIGHT_MASTER */ 0xbf,
+ /* CS4236_LEFT_WAVE */ 0xbf,
+ /* CS4236_RIGHT_WAVE */ 0xbf
+};
+
+/*
+ *
+ */
+
+static void snd_cs4236_ctrl_out(cs4231_t *chip, unsigned char reg, unsigned char val)
+{
+ outb(reg, chip->cport + 3);
+ outb(chip->cimage[reg] = val, chip->cport + 4);
+}
+
+static unsigned char snd_cs4236_ctrl_in(cs4231_t *chip, unsigned char reg)
+{
+ outb(reg, chip->cport + 3);
+ return inb(chip->cport + 4);
+}
+
+/*
+ * PCM
+ */
+
+#define CLOCKS 8
+
+static ratnum_t clocks[CLOCKS] = {
+ { .num = 16934400, .den_min = 353, .den_max = 353, .den_step = 1 },
+ { .num = 16934400, .den_min = 529, .den_max = 529, .den_step = 1 },
+ { .num = 16934400, .den_min = 617, .den_max = 617, .den_step = 1 },
+ { .num = 16934400, .den_min = 1058, .den_max = 1058, .den_step = 1 },
+ { .num = 16934400, .den_min = 1764, .den_max = 1764, .den_step = 1 },
+ { .num = 16934400, .den_min = 2117, .den_max = 2117, .den_step = 1 },
+ { .num = 16934400, .den_min = 2558, .den_max = 2558, .den_step = 1 },
+ { .num = 16934400/16, .den_min = 21, .den_max = 192, .den_step = 1 }
+};
+
+static snd_pcm_hw_constraint_ratnums_t hw_constraints_clocks = {
+ .nrats = CLOCKS,
+ .rats = clocks,
+};
+
+static int snd_cs4236_xrate(snd_pcm_runtime_t *runtime)
+{
+ return snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+ &hw_constraints_clocks);
+}
+
+static unsigned char divisor_to_rate_register(unsigned int divisor)
+{
+ switch (divisor) {
+ case 353: return 1;
+ case 529: return 2;
+ case 617: return 3;
+ case 1058: return 4;
+ case 1764: return 5;
+ case 2117: return 6;
+ case 2558: return 7;
+ default:
+ snd_runtime_check(divisor >= 21 && divisor <= 192, return 192);
+ return divisor;
+ }
+}
+
+static void snd_cs4236_playback_format(cs4231_t *chip, snd_pcm_hw_params_t *params, unsigned char pdfr)
+{
+ unsigned long flags;
+ unsigned char rate = divisor_to_rate_register(params->rate_den);
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ /* set fast playback format change and clean playback FIFO */
+ snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x10);
+ snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, pdfr & 0xf0);
+ snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] & ~0x10);
+ snd_cs4236_ext_out(chip, CS4236_DAC_RATE, rate);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+}
+
+static void snd_cs4236_capture_format(cs4231_t *chip, snd_pcm_hw_params_t *params, unsigned char cdfr)
+{
+ unsigned long flags;
+ unsigned char rate = divisor_to_rate_register(params->rate_den);
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ /* set fast capture format change and clean capture FIFO */
+ snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x20);
+ snd_cs4231_out(chip, CS4231_REC_FORMAT, cdfr & 0xf0);
+ snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] & ~0x20);
+ snd_cs4236_ext_out(chip, CS4236_ADC_RATE, rate);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+}
+
+#ifdef CONFIG_PM
+
+static void snd_cs4236_suspend(cs4231_t *chip)
+{
+ int reg;
+ unsigned long flags;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ for (reg = 0; reg < 32; reg++)
+ chip->image[reg] = snd_cs4231_in(chip, reg);
+ for (reg = 0; reg < 18; reg++)
+ chip->eimage[reg] = snd_cs4236_ext_in(chip, CS4236_I23VAL(reg));
+ for (reg = 2; reg < 9; reg++)
+ chip->cimage[reg] = snd_cs4236_ctrl_in(chip, reg);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+}
+
+static void snd_cs4236_resume(cs4231_t *chip)
+{
+ int reg;
+ unsigned long flags;
+
+ snd_cs4231_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ for (reg = 0; reg < 32; reg++) {
+ switch (reg) {
+ case CS4236_EXT_REG:
+ case CS4231_VERSION:
+ case 27: /* why? CS4235 - master left */
+ case 29: /* why? CS4235 - master right */
+ break;
+ default:
+ snd_cs4231_out(chip, reg, chip->image[reg]);
+ break;
+ }
+ }
+ for (reg = 0; reg < 18; reg++)
+ snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), chip->eimage[reg]);
+ for (reg = 2; reg < 9; reg++) {
+ switch (reg) {
+ case 7:
+ break;
+ default:
+ snd_cs4236_ctrl_out(chip, reg, chip->cimage[reg]);
+ }
+ }
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_cs4231_mce_down(chip);
+}
+
+#endif /* CONFIG_PM */
+
+int snd_cs4236_create(snd_card_t * card,
+ unsigned long port,
+ unsigned long cport,
+ int irq, int dma1, int dma2,
+ unsigned short hardware,
+ unsigned short hwshare,
+ cs4231_t ** rchip)
+{
+ cs4231_t *chip;
+ unsigned char ver1, ver2;
+ unsigned int reg;
+ int err;
+
+ *rchip = NULL;
+ if (hardware == CS4231_HW_DETECT)
+ hardware = CS4231_HW_DETECT3;
+ if (cport < 0x100) {
+ snd_printk("please, specify control port for CS4236+ chips\n");
+ return -ENODEV;
+ }
+ if ((err = snd_cs4231_create(card, port, cport, irq, dma1, dma2, hardware, hwshare, &chip)) < 0)
+ return err;
+
+ if (!(chip->hardware & CS4231_HW_CS4236B_MASK)) {
+ snd_printk("CS4236+: MODE3 and extended registers not available, hardware=0x%x\n",chip->hardware);
+ snd_device_free(card, chip);
+ return -ENODEV;
+ }
+#if 0
+ {
+ int idx;
+ for (idx = 0; idx < 8; idx++)
+ snd_printk("CD%i = 0x%x\n", idx, inb(chip->cport + idx));
+ for (idx = 0; idx < 9; idx++)
+ snd_printk("C%i = 0x%x\n", idx, snd_cs4236_ctrl_in(chip, idx));
+ }
+#endif
+ ver1 = snd_cs4236_ctrl_in(chip, 1);
+ ver2 = snd_cs4236_ext_in(chip, CS4236_VERSION);
+ snd_printdd("CS4236: [0x%lx] C1 (version) = 0x%x, ext = 0x%x\n", cport, ver1, ver2);
+ if (ver1 != ver2) {
+ snd_printk("CS4236+ chip detected, but control port 0x%lx is not valid\n", cport);
+ snd_device_free(card, chip);
+ return -ENODEV;
+ }
+ snd_cs4236_ctrl_out(chip, 0, 0x00);
+ snd_cs4236_ctrl_out(chip, 2, 0xff);
+ snd_cs4236_ctrl_out(chip, 3, 0x00);
+ snd_cs4236_ctrl_out(chip, 4, 0x80);
+ snd_cs4236_ctrl_out(chip, 5, ((IEC958_AES1_CON_PCM_CODER & 3) << 6) | IEC958_AES0_CON_EMPHASIS_NONE);
+ snd_cs4236_ctrl_out(chip, 6, IEC958_AES1_CON_PCM_CODER >> 2);
+ snd_cs4236_ctrl_out(chip, 7, 0x00);
+ /* 0x8c for C8 is valid for Turtle Beach Malibu - the IEC-958 output */
+ /* is working with this setup, other hardware should have */
+ /* different signal paths and this value should be selectable */
+ /* in the future */
+ snd_cs4236_ctrl_out(chip, 8, 0x8c);
+ chip->rate_constraint = snd_cs4236_xrate;
+ chip->set_playback_format = snd_cs4236_playback_format;
+ chip->set_capture_format = snd_cs4236_capture_format;
+#ifdef CONFIG_PM
+ chip->suspend = snd_cs4236_suspend;
+ chip->resume = snd_cs4236_resume;
+#endif
+
+ /* initialize extended registers */
+ for (reg = 0; reg < sizeof(snd_cs4236_ext_map); reg++)
+ snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), snd_cs4236_ext_map[reg]);
+
+ /* initialize compatible but more featured registers */
+ snd_cs4231_out(chip, CS4231_LEFT_INPUT, 0x40);
+ snd_cs4231_out(chip, CS4231_RIGHT_INPUT, 0x40);
+ snd_cs4231_out(chip, CS4231_AUX1_LEFT_INPUT, 0xff);
+ snd_cs4231_out(chip, CS4231_AUX1_RIGHT_INPUT, 0xff);
+ snd_cs4231_out(chip, CS4231_AUX2_LEFT_INPUT, 0xdf);
+ snd_cs4231_out(chip, CS4231_AUX2_RIGHT_INPUT, 0xdf);
+ snd_cs4231_out(chip, CS4231_RIGHT_LINE_IN, 0xff);
+ snd_cs4231_out(chip, CS4231_LEFT_LINE_IN, 0xff);
+ snd_cs4231_out(chip, CS4231_RIGHT_LINE_IN, 0xff);
+ switch (chip->hardware) {
+ case CS4231_HW_CS4235:
+ case CS4231_HW_CS4239:
+ snd_cs4231_out(chip, CS4235_LEFT_MASTER, 0xff);
+ snd_cs4231_out(chip, CS4235_RIGHT_MASTER, 0xff);
+ break;
+ }
+
+ *rchip = chip;
+ return 0;
+}
+
+int snd_cs4236_pcm(cs4231_t *chip, int device, snd_pcm_t **rpcm)
+{
+ snd_pcm_t *pcm;
+ int err;
+
+ if ((err = snd_cs4231_pcm(chip, device, &pcm)) < 0)
+ return err;
+ pcm->info_flags &= ~SNDRV_PCM_INFO_JOINT_DUPLEX;
+ if (rpcm)
+ *rpcm = pcm;
+ return 0;
+}
+
+/*
+ * MIXER
+ */
+
+#define CS4236_SINGLE(xname, xindex, reg, shift, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+ .info = snd_cs4236_info_single, \
+ .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \
+ .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
+
+static int snd_cs4236_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+
+ uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = mask;
+ return 0;
+}
+
+static int snd_cs4236_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(reg)] >> shift) & mask;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (invert)
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ return 0;
+}
+
+static int snd_cs4236_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+ int change;
+ unsigned short val;
+
+ val = (ucontrol->value.integer.value[0] & mask);
+ if (invert)
+ val = mask - val;
+ val <<= shift;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ val = (chip->eimage[CS4236_REG(reg)] & ~(mask << shift)) | val;
+ change = val != chip->eimage[CS4236_REG(reg)];
+ snd_cs4236_ext_out(chip, reg, val);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+#define CS4236_SINGLEC(xname, xindex, reg, shift, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+ .info = snd_cs4236_info_single, \
+ .get = snd_cs4236_get_singlec, .put = snd_cs4236_put_singlec, \
+ .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
+
+static int snd_cs4236_get_singlec(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.integer.value[0] = (chip->cimage[reg] >> shift) & mask;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (invert)
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ return 0;
+}
+
+static int snd_cs4236_put_singlec(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+ int change;
+ unsigned short val;
+
+ val = (ucontrol->value.integer.value[0] & mask);
+ if (invert)
+ val = mask - val;
+ val <<= shift;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ val = (chip->cimage[reg] & ~(mask << shift)) | val;
+ change = val != chip->cimage[reg];
+ snd_cs4236_ctrl_out(chip, reg, val);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+#define CS4236_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+ .info = snd_cs4236_info_double, \
+ .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \
+ .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
+
+static int snd_cs4236_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+
+ uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 2;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = mask;
+ return 0;
+}
+
+static int snd_cs4236_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int left_reg = kcontrol->private_value & 0xff;
+ int right_reg = (kcontrol->private_value >> 8) & 0xff;
+ int shift_left = (kcontrol->private_value >> 16) & 0x07;
+ int shift_right = (kcontrol->private_value >> 19) & 0x07;
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+ int invert = (kcontrol->private_value >> 22) & 1;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(left_reg)] >> shift_left) & mask;
+ ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (invert) {
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
+ }
+ return 0;
+}
+
+static int snd_cs4236_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int left_reg = kcontrol->private_value & 0xff;
+ int right_reg = (kcontrol->private_value >> 8) & 0xff;
+ int shift_left = (kcontrol->private_value >> 16) & 0x07;
+ int shift_right = (kcontrol->private_value >> 19) & 0x07;
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+ int invert = (kcontrol->private_value >> 22) & 1;
+ int change;
+ unsigned short val1, val2;
+
+ val1 = ucontrol->value.integer.value[0] & mask;
+ val2 = ucontrol->value.integer.value[1] & mask;
+ if (invert) {
+ val1 = mask - val1;
+ val2 = mask - val2;
+ }
+ val1 <<= shift_left;
+ val2 <<= shift_right;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ if (left_reg != right_reg) {
+ val1 = (chip->eimage[CS4236_REG(left_reg)] & ~(mask << shift_left)) | val1;
+ val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2;
+ change = val1 != chip->eimage[CS4236_REG(left_reg)] || val2 != chip->eimage[CS4236_REG(right_reg)];
+ snd_cs4236_ext_out(chip, left_reg, val1);
+ snd_cs4236_ext_out(chip, right_reg, val2);
+ } else {
+ val1 = (chip->eimage[CS4236_REG(left_reg)] & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
+ change = val1 != chip->eimage[CS4236_REG(left_reg)];
+ snd_cs4236_ext_out(chip, left_reg, val1);
+ }
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+#define CS4236_DOUBLE1(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+ .info = snd_cs4236_info_double, \
+ .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \
+ .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
+
+static int snd_cs4236_get_double1(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int left_reg = kcontrol->private_value & 0xff;
+ int right_reg = (kcontrol->private_value >> 8) & 0xff;
+ int shift_left = (kcontrol->private_value >> 16) & 0x07;
+ int shift_right = (kcontrol->private_value >> 19) & 0x07;
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+ int invert = (kcontrol->private_value >> 22) & 1;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
+ ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (invert) {
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
+ }
+ return 0;
+}
+
+static int snd_cs4236_put_double1(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int left_reg = kcontrol->private_value & 0xff;
+ int right_reg = (kcontrol->private_value >> 8) & 0xff;
+ int shift_left = (kcontrol->private_value >> 16) & 0x07;
+ int shift_right = (kcontrol->private_value >> 19) & 0x07;
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+ int invert = (kcontrol->private_value >> 22) & 1;
+ int change;
+ unsigned short val1, val2;
+
+ val1 = ucontrol->value.integer.value[0] & mask;
+ val2 = ucontrol->value.integer.value[1] & mask;
+ if (invert) {
+ val1 = mask - val1;
+ val2 = mask - val2;
+ }
+ val1 <<= shift_left;
+ val2 <<= shift_right;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
+ val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2;
+ change = val1 != chip->image[left_reg] || val2 != chip->eimage[CS4236_REG(right_reg)];
+ snd_cs4231_out(chip, left_reg, val1);
+ snd_cs4236_ext_out(chip, right_reg, val2);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+#define CS4236_MASTER_DIGITAL(xname, xindex) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+ .info = snd_cs4236_info_double, \
+ .get = snd_cs4236_get_master_digital, .put = snd_cs4236_put_master_digital, \
+ .private_value = 71 << 24 }
+
+static inline int snd_cs4236_mixer_master_digital_invert_volume(int vol)
+{
+ return (vol < 64) ? 63 - vol : 64 + (71 - vol);
+}
+
+static int snd_cs4236_get_master_digital(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.integer.value[0] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & 0x7f);
+ ucontrol->value.integer.value[1] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & 0x7f);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return 0;
+}
+
+static int snd_cs4236_put_master_digital(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int change;
+ unsigned short val1, val2;
+
+ val1 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[0] & 0x7f);
+ val2 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[1] & 0x7f);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ val1 = (chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & ~0x7f) | val1;
+ val2 = (chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & ~0x7f) | val2;
+ change = val1 != chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] || val2 != chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)];
+ snd_cs4236_ext_out(chip, CS4236_LEFT_MASTER, val1);
+ snd_cs4236_ext_out(chip, CS4236_RIGHT_MASTER, val1);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+#define CS4235_OUTPUT_ACCU(xname, xindex) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+ .info = snd_cs4236_info_double, \
+ .get = snd_cs4235_get_output_accu, .put = snd_cs4235_put_output_accu, \
+ .private_value = 3 << 24 }
+
+static inline int snd_cs4235_mixer_output_accu_get_volume(int vol)
+{
+ switch ((vol >> 5) & 3) {
+ case 0: return 1;
+ case 1: return 3;
+ case 2: return 2;
+ case 3: return 0;
+ }
+ return 3;
+}
+
+static inline int snd_cs4235_mixer_output_accu_set_volume(int vol)
+{
+ switch (vol & 3) {
+ case 0: return 3 << 5;
+ case 1: return 0 << 5;
+ case 2: return 2 << 5;
+ case 3: return 1 << 5;
+ }
+ return 1 << 5;
+}
+
+static int snd_cs4235_get_output_accu(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.integer.value[0] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_LEFT_MASTER]);
+ ucontrol->value.integer.value[1] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_RIGHT_MASTER]);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return 0;
+}
+
+static int snd_cs4235_put_output_accu(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int change;
+ unsigned short val1, val2;
+
+ val1 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[0]);
+ val2 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[1]);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ val1 = (chip->image[CS4235_LEFT_MASTER] & ~(3 << 5)) | val1;
+ val2 = (chip->image[CS4235_RIGHT_MASTER] & ~(3 << 5)) | val2;
+ change = val1 != chip->image[CS4235_LEFT_MASTER] || val2 != chip->image[CS4235_RIGHT_MASTER];
+ snd_cs4231_out(chip, CS4235_LEFT_MASTER, val1);
+ snd_cs4231_out(chip, CS4235_RIGHT_MASTER, val2);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+static snd_kcontrol_new_t snd_cs4236_controls[] = {
+
+CS4236_DOUBLE("Master Digital Playback Switch", 0, CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1),
+CS4236_DOUBLE("Master Digital Capture Switch", 0, CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
+CS4236_MASTER_DIGITAL("Master Digital Volume", 0),
+
+CS4236_DOUBLE("Capture Boost Volume", 0, CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1),
+
+CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
+
+CS4236_DOUBLE("DSP Playback Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1),
+CS4236_DOUBLE("DSP Playback Volume", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 0, 0, 63, 1),
+
+CS4236_DOUBLE("FM Playback Switch", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1),
+CS4236_DOUBLE("FM Playback Volume", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 0, 0, 63, 1),
+
+CS4236_DOUBLE("Wavetable Playback Switch", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1),
+CS4236_DOUBLE("Wavetable Playback Volume", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 0, 0, 63, 1),
+
+CS4231_DOUBLE("Synth Playback Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
+CS4231_DOUBLE("Synth Volume", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1),
+CS4231_DOUBLE("Synth Capture Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1),
+CS4231_DOUBLE("Synth Capture Bypass", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 5, 5, 1, 1),
+
+CS4236_DOUBLE("Mic Playback Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1),
+CS4236_DOUBLE("Mic Capture Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1),
+CS4236_DOUBLE("Mic Volume", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 0, 0, 31, 1),
+CS4236_DOUBLE("Mic Playback Boost", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 5, 5, 1, 0),
+
+CS4231_DOUBLE("Line Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("Line Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
+CS4231_DOUBLE("Line Capture Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1),
+CS4231_DOUBLE("Line Capture Bypass", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 5, 5, 1, 1),
+
+CS4231_DOUBLE("CD Playback Switch", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("CD Volume", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
+CS4231_DOUBLE("CD Capture Switch", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1),
+
+CS4236_DOUBLE1("Mono Output Playback Switch", 0, CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1),
+CS4236_DOUBLE1("Mono Playback Switch", 0, CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1),
+CS4231_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
+CS4231_SINGLE("Mono Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0),
+
+CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
+CS4231_DOUBLE("Analog Loopback Capture Switch", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0),
+
+CS4231_SINGLE("Digital Loopback Playback Switch", 0, CS4231_LOOPBACK, 0, 1, 0),
+CS4236_DOUBLE1("Digital Loopback Playback Volume", 0, CS4231_LOOPBACK, CS4236_RIGHT_LOOPBACK, 2, 0, 63, 1)
+};
+
+static snd_kcontrol_new_t snd_cs4235_controls[] = {
+
+CS4231_DOUBLE("Master Switch", 0, CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 7, 7, 1, 1),
+CS4231_DOUBLE("Master Volume", 0, CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 0, 0, 31, 1),
+
+CS4235_OUTPUT_ACCU("Playback Volume", 0),
+
+CS4236_DOUBLE("Master Digital Playback Switch", 0, CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1),
+CS4236_DOUBLE("Master Digital Capture Switch", 0, CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
+CS4236_MASTER_DIGITAL("Master Digital Volume", 0),
+
+CS4231_DOUBLE("Master Digital Playback Switch", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
+CS4231_DOUBLE("Master Digital Capture Switch", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1),
+CS4231_DOUBLE("Master Digital Volume", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1),
+
+CS4236_DOUBLE("Capture Volume", 0, CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1),
+
+CS4231_DOUBLE("PCM Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("PCM Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
+
+CS4236_DOUBLE("DSP Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1),
+
+CS4236_DOUBLE("FM Switch", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1),
+
+CS4236_DOUBLE("Wavetable Switch", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1),
+
+CS4236_DOUBLE("Mic Capture Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1),
+CS4236_DOUBLE("Mic Playback Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1),
+CS4236_SINGLE("Mic Volume", 0, CS4236_LEFT_MIC, 0, 31, 1),
+CS4236_SINGLE("Mic Playback Boost", 0, CS4236_LEFT_MIC, 5, 1, 0),
+
+CS4231_DOUBLE("Aux Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("Aux Capture Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1),
+CS4231_DOUBLE("Aux Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
+
+CS4231_DOUBLE("Aux Playback Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("Aux Capture Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1),
+CS4231_DOUBLE("Aux Volume", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
+
+CS4236_DOUBLE1("Master Mono Switch", 0, CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1),
+
+CS4236_DOUBLE1("Mono Switch", 0, CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1),
+CS4231_SINGLE("Mono Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
+
+CS4231_DOUBLE("Analog Loopback Switch", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0),
+};
+
+#define CS4236_IEC958_ENABLE(xname, xindex) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+ .info = snd_cs4236_info_single, \
+ .get = snd_cs4236_get_iec958_switch, .put = snd_cs4236_put_iec958_switch, \
+ .private_value = 1 << 16 }
+
+static int snd_cs4236_get_iec958_switch(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.integer.value[0] = chip->image[CS4231_ALT_FEATURE_1] & 0x02 ? 1 : 0;
+#if 0
+ printk("get valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n",
+ snd_cs4231_in(chip, CS4231_ALT_FEATURE_1),
+ snd_cs4236_ctrl_in(chip, 3),
+ snd_cs4236_ctrl_in(chip, 4),
+ snd_cs4236_ctrl_in(chip, 5),
+ snd_cs4236_ctrl_in(chip, 6),
+ snd_cs4236_ctrl_in(chip, 8));
+#endif
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return 0;
+}
+
+static int snd_cs4236_put_iec958_switch(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int change;
+ unsigned short enable, val;
+
+ enable = ucontrol->value.integer.value[0] & 1;
+
+ down(&chip->mce_mutex);
+ snd_cs4231_mce_up(chip);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ val = (chip->image[CS4231_ALT_FEATURE_1] & ~0x0e) | (0<<2) | (enable << 1);
+ change = val != chip->image[CS4231_ALT_FEATURE_1];
+ snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, val);
+ val = snd_cs4236_ctrl_in(chip, 4) | 0xc0;
+ snd_cs4236_ctrl_out(chip, 4, val);
+ udelay(100);
+ val &= ~0x40;
+ snd_cs4236_ctrl_out(chip, 4, val);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ snd_cs4231_mce_down(chip);
+ up(&chip->mce_mutex);
+
+#if 0
+ printk("set valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n",
+ snd_cs4231_in(chip, CS4231_ALT_FEATURE_1),
+ snd_cs4236_ctrl_in(chip, 3),
+ snd_cs4236_ctrl_in(chip, 4),
+ snd_cs4236_ctrl_in(chip, 5),
+ snd_cs4236_ctrl_in(chip, 6),
+ snd_cs4236_ctrl_in(chip, 8));
+#endif
+ return change;
+}
+
+static snd_kcontrol_new_t snd_cs4236_iec958_controls[] = {
+CS4236_IEC958_ENABLE("IEC958 Output Enable", 0),
+CS4236_SINGLEC("IEC958 Output Validity", 0, 4, 4, 1, 0),
+CS4236_SINGLEC("IEC958 Output User", 0, 4, 5, 1, 0),
+CS4236_SINGLEC("IEC958 Output CSBR", 0, 4, 6, 1, 0),
+CS4236_SINGLEC("IEC958 Output Channel Status Low", 0, 5, 1, 127, 0),
+CS4236_SINGLEC("IEC958 Output Channel Status High", 0, 6, 0, 255, 0)
+};
+
+static snd_kcontrol_new_t snd_cs4236_3d_controls_cs4235[] = {
+CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0),
+CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1)
+};
+
+static snd_kcontrol_new_t snd_cs4236_3d_controls_cs4237[] = {
+CS4236_SINGLEC("3D Control - Switch", 0, 3, 7, 1, 0),
+CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1),
+CS4236_SINGLEC("3D Control - Center", 0, 2, 0, 15, 1),
+CS4236_SINGLEC("3D Control - Mono", 0, 3, 6, 1, 0),
+CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0)
+};
+
+static snd_kcontrol_new_t snd_cs4236_3d_controls_cs4238[] = {
+CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0),
+CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1),
+CS4236_SINGLEC("3D Control - Volume", 0, 2, 0, 15, 1),
+CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0)
+};
+
+int snd_cs4236_mixer(cs4231_t *chip)
+{
+ snd_card_t *card;
+ unsigned int idx, count;
+ int err;
+ snd_kcontrol_new_t *kcontrol;
+
+ snd_assert(chip != NULL && chip->card != NULL, return -EINVAL);
+ card = chip->card;
+ strcpy(card->mixername, snd_cs4231_chip_id(chip));
+
+ if (chip->hardware == CS4231_HW_CS4235 ||
+ chip->hardware == CS4231_HW_CS4239) {
+ for (idx = 0; idx < ARRAY_SIZE(snd_cs4235_controls); idx++) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4235_controls[idx], chip))) < 0)
+ return err;
+ }
+ } else {
+ for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_controls); idx++) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_controls[idx], chip))) < 0)
+ return err;
+ }
+ }
+ switch (chip->hardware) {
+ case CS4231_HW_CS4235:
+ case CS4231_HW_CS4239:
+ count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4235);
+ kcontrol = snd_cs4236_3d_controls_cs4235;
+ break;
+ case CS4231_HW_CS4237B:
+ count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4237);
+ kcontrol = snd_cs4236_3d_controls_cs4237;
+ break;
+ case CS4231_HW_CS4238B:
+ count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4238);
+ kcontrol = snd_cs4236_3d_controls_cs4238;
+ break;
+ default:
+ count = 0;
+ kcontrol = NULL;
+ }
+ for (idx = 0; idx < count; idx++, kcontrol++) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(kcontrol, chip))) < 0)
+ return err;
+ }
+ if (chip->hardware == CS4231_HW_CS4237B ||
+ chip->hardware == CS4231_HW_CS4238B) {
+ for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_iec958_controls); idx++) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_iec958_controls[idx], chip))) < 0)
+ return err;
+ }
+ }
+ return 0;
+}
+
+EXPORT_SYMBOL(snd_cs4236_create);
+EXPORT_SYMBOL(snd_cs4236_pcm);
+EXPORT_SYMBOL(snd_cs4236_mixer);
+
+/*
+ * INIT part
+ */
+
+static int __init alsa_cs4236_init(void)
+{
+ return 0;
+}
+
+static void __exit alsa_cs4236_exit(void)
+{
+}
+
+module_init(alsa_cs4236_init)
+module_exit(alsa_cs4236_exit)
diff --git a/sound/isa/dt019x.c b/sound/isa/dt019x.c
new file mode 100644
index 000000000000..db7c3397b323
--- /dev/null
+++ b/sound/isa/dt019x.c
@@ -0,0 +1,327 @@
+
+/*
+ dt019x.c - driver for Diamond Technologies DT-0197H based soundcards.
+ Copyright (C) 1999, 2002 by Massimo Piccioni <dafastidio@libero.it>
+
+ Generalised for soundcards based on DT-0196 and ALS-007 chips
+ by Jonathan Woithe <jwoithe@physics.adelaide.edu.au>: June 2002.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include <sound/driver.h>
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/wait.h>
+#include <linux/pnp.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/initval.h>
+#include <sound/mpu401.h>
+#include <sound/opl3.h>
+#include <sound/sb.h>
+
+#define PFX "dt019x: "
+
+MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
+MODULE_DESCRIPTION("Diamond Technologies DT-019X / Avance Logic ALS-007");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{Diamond Technologies DT-019X},"
+ "{Avance Logic ALS-007}}");
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
+static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
+static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
+static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
+static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for DT-019X based soundcard.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for DT-019X based soundcard.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable DT-019X based soundcard.");
+module_param_array(port, long, NULL, 0444);
+MODULE_PARM_DESC(port, "Port # for dt019x driver.");
+module_param_array(mpu_port, long, NULL, 0444);
+MODULE_PARM_DESC(mpu_port, "MPU-401 port # for dt019x driver.");
+module_param_array(fm_port, long, NULL, 0444);
+MODULE_PARM_DESC(fm_port, "FM port # for dt019x driver.");
+module_param_array(irq, int, NULL, 0444);
+MODULE_PARM_DESC(irq, "IRQ # for dt019x driver.");
+module_param_array(mpu_irq, int, NULL, 0444);
+MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for dt019x driver.");
+module_param_array(dma8, int, NULL, 0444);
+MODULE_PARM_DESC(dma8, "8-bit DMA # for dt019x driver.");
+
+struct snd_card_dt019x {
+ struct pnp_dev *dev;
+ struct pnp_dev *devmpu;
+ struct pnp_dev *devopl;
+};
+
+static struct pnp_card_device_id snd_dt019x_pnpids[] = {
+ /* DT197A30 */
+ { .id = "RWB1688", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
+ /* DT0196 / ALS-007 */
+ { .id = "ALS0007", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
+ { .id = "", }
+};
+
+MODULE_DEVICE_TABLE(pnp_card, snd_dt019x_pnpids);
+
+
+#define DRIVER_NAME "snd-card-dt019x"
+
+
+static int __devinit snd_card_dt019x_pnp(int dev, struct snd_card_dt019x *acard,
+ struct pnp_card_link *card,
+ const struct pnp_card_device_id *pid)
+{
+ struct pnp_dev *pdev;
+ struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
+ int err;
+
+ if (!cfg)
+ return -ENOMEM;
+
+ acard->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
+ if (acard->dev == NULL) {
+ kfree (cfg);
+ return -ENODEV;
+ }
+ acard->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
+ acard->devopl = pnp_request_card_device(card, pid->devs[2].id, NULL);
+
+ pdev = acard->dev;
+ pnp_init_resource_table(cfg);
+
+ if (port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
+ if (dma8[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
+ if (irq[dev] != SNDRV_AUTO_IRQ)
+ pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
+
+ if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
+ snd_printk(KERN_ERR PFX "DT-019X AUDIO the requested resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ snd_printk(KERN_ERR PFX "DT-019X AUDIO pnp configure failure\n");
+ kfree(cfg);
+ return err;
+ }
+
+ port[dev] = pnp_port_start(pdev, 0);
+ dma8[dev] = pnp_dma(pdev, 0);
+ irq[dev] = pnp_irq(pdev, 0);
+ snd_printdd("dt019x: found audio interface: port=0x%lx, irq=0x%x, dma=0x%x\n",
+ port[dev],irq[dev],dma8[dev]);
+
+ pdev = acard->devmpu;
+
+ if (pdev != NULL) {
+ pnp_init_resource_table(cfg);
+ if (mpu_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
+ if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
+ pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
+ if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
+ snd_printk(KERN_ERR PFX "DT-019X MPU401 the requested resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ pnp_release_card_device(pdev);
+ snd_printk(KERN_ERR PFX "DT-019X MPU401 pnp configure failure, skipping\n");
+ goto __mpu_error;
+ }
+ mpu_port[dev] = pnp_port_start(pdev, 0);
+ mpu_irq[dev] = pnp_irq(pdev, 0);
+ snd_printdd("dt019x: found MPU-401: port=0x%lx, irq=0x%x\n",
+ mpu_port[dev],mpu_irq[dev]);
+ } else {
+ __mpu_error:
+ acard->devmpu = NULL;
+ mpu_port[dev] = -1;
+ }
+
+ pdev = acard->devopl;
+ if (pdev != NULL) {
+ pnp_init_resource_table(cfg);
+ if (fm_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4);
+ if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
+ snd_printk(KERN_ERR PFX "DT-019X OPL3 the requested resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ pnp_release_card_device(pdev);
+ snd_printk(KERN_ERR PFX "DT-019X OPL3 pnp configure failure, skipping\n");
+ goto __fm_error;
+ }
+ fm_port[dev] = pnp_port_start(pdev, 0);
+ snd_printdd("dt019x: found OPL3 synth: port=0x%lx\n",fm_port[dev]);
+ } else {
+ __fm_error:
+ acard->devopl = NULL;
+ fm_port[dev] = -1;
+ }
+
+ kfree(cfg);
+ return 0;
+}
+
+static int __devinit snd_card_dt019x_probe(int dev, struct pnp_card_link *pcard, const struct pnp_card_device_id *pid)
+{
+ int error;
+ sb_t *chip;
+ snd_card_t *card;
+ struct snd_card_dt019x *acard;
+ opl3_t *opl3;
+
+ if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
+ sizeof(struct snd_card_dt019x))) == NULL)
+ return -ENOMEM;
+ acard = (struct snd_card_dt019x *)card->private_data;
+
+ snd_card_set_dev(card, &pcard->card->dev);
+ if ((error = snd_card_dt019x_pnp(dev, acard, pcard, pid))) {
+ snd_card_free(card);
+ return error;
+ }
+
+ if ((error = snd_sbdsp_create(card, port[dev],
+ irq[dev],
+ snd_sb16dsp_interrupt,
+ dma8[dev],
+ -1,
+ SB_HW_DT019X,
+ &chip)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+
+ strcpy(card->driver, "DT-019X");
+ strcpy(card->shortname, "Diamond Tech. DT-019X");
+ sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
+ card->shortname, chip->name, chip->port,
+ irq[dev], dma8[dev]);
+
+ if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ if ((error = snd_sbmixer_new(chip)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+
+ if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
+ if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
+ mpu_irq[dev] = -1;
+ if (snd_mpu401_uart_new(card, 0,
+/* MPU401_HW_SB,*/
+ MPU401_HW_MPU401,
+ mpu_port[dev], 0,
+ mpu_irq[dev],
+ mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0,
+ NULL) < 0)
+ snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n", mpu_port[dev]);
+ }
+
+ if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
+ if (snd_opl3_create(card,
+ fm_port[dev],
+ fm_port[dev] + 2,
+ OPL3_HW_AUTO, 0, &opl3) < 0) {
+ snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n",
+ fm_port[dev], fm_port[dev] + 2);
+ } else {
+ if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ }
+ }
+
+ if ((error = snd_card_register(card)) < 0) {
+ snd_card_free(card);
+ return error;
+ }
+ pnp_set_card_drvdata(pcard, card);
+ return 0;
+}
+
+static int __devinit snd_dt019x_pnp_probe(struct pnp_card_link *card,
+ const struct pnp_card_device_id *pid)
+{
+ static int dev;
+ int res;
+
+ for ( ; dev < SNDRV_CARDS; dev++) {
+ if (!enable[dev])
+ continue;
+ res = snd_card_dt019x_probe(dev, card, pid);
+ if (res < 0)
+ return res;
+ dev++;
+ return 0;
+ }
+ return -ENODEV;
+}
+
+static void __devexit snd_dt019x_pnp_remove(struct pnp_card_link * pcard)
+{
+ snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
+ snd_card_disconnect(card);
+ snd_card_free_in_thread(card);
+}
+
+static struct pnp_card_driver dt019x_pnpc_driver = {
+ .flags = PNP_DRIVER_RES_DISABLE,
+ .name = "dt019x",
+ .id_table = snd_dt019x_pnpids,
+ .probe = snd_dt019x_pnp_probe,
+ .remove = __devexit_p(snd_dt019x_pnp_remove),
+};
+
+static int __init alsa_card_dt019x_init(void)
+{
+ int cards = 0;
+
+ cards += pnp_register_card_driver(&dt019x_pnpc_driver);
+
+#ifdef MODULE
+ if (!cards) {
+ pnp_unregister_card_driver(&dt019x_pnpc_driver);
+ snd_printk(KERN_ERR "no DT-019X / ALS-007 based soundcards found\n");
+ }
+#endif
+ return cards ? 0 : -ENODEV;
+}
+
+static void __exit alsa_card_dt019x_exit(void)
+{
+ pnp_unregister_card_driver(&dt019x_pnpc_driver);
+}
+
+module_init(alsa_card_dt019x_init)
+module_exit(alsa_card_dt019x_exit)
diff --git a/sound/isa/es1688/Makefile b/sound/isa/es1688/Makefile
new file mode 100644
index 000000000000..501c8bf903af
--- /dev/null
+++ b/sound/isa/es1688/Makefile
@@ -0,0 +1,11 @@
+#
+# Makefile for ALSA
+# Copyright (c) 2001 by Jaroslav Kysela <perex@suse.cz>
+#
+
+snd-es1688-lib-objs := es1688_lib.o
+snd-es1688-objs := es1688.o
+
+# Toplevel Module Dependency
+obj-$(CONFIG_SND_ES1688) += snd-es1688.o snd-es1688-lib.o
+obj-$(CONFIG_SND_GUSEXTREME) += snd-es1688-lib.o
diff --git a/sound/isa/es1688/es1688.c b/sound/isa/es1688/es1688.c
new file mode 100644
index 000000000000..c5eaec087b46
--- /dev/null
+++ b/sound/isa/es1688/es1688.c
@@ -0,0 +1,204 @@
+/*
+ * Driver for generic ESS AudioDrive ESx688 soundcards
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <asm/dma.h>
+#include <linux/init.h>
+#include <linux/time.h>
+#include <linux/wait.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/es1688.h>
+#include <sound/mpu401.h>
+#include <sound/opl3.h>
+#define SNDRV_LEGACY_AUTO_PROBE
+#define SNDRV_LEGACY_FIND_FREE_IRQ
+#define SNDRV_LEGACY_FIND_FREE_DMA
+#include <sound/initval.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("ESS ESx688 AudioDrive");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{ESS,ES688 PnP AudioDrive,pnp:ESS0100},"
+ "{ESS,ES1688 PnP AudioDrive,pnp:ESS0102},"
+ "{ESS,ES688 AudioDrive,pnp:ESS6881},"
+ "{ESS,ES1688 AudioDrive,pnp:ESS1681}}");
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
+static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
+static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
+static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
+static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
+static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for ESx688 soundcard.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for ESx688 soundcard.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable ESx688 soundcard.");
+module_param_array(port, long, NULL, 0444);
+MODULE_PARM_DESC(port, "Port # for ESx688 driver.");
+module_param_array(mpu_port, long, NULL, 0444);
+MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ESx688 driver.");
+module_param_array(irq, int, NULL, 0444);
+MODULE_PARM_DESC(irq, "IRQ # for ESx688 driver.");
+module_param_array(mpu_irq, int, NULL, 0444);
+MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for ESx688 driver.");
+module_param_array(dma8, int, NULL, 0444);
+MODULE_PARM_DESC(dma8, "8-bit DMA # for ESx688 driver.");
+
+static snd_card_t *snd_audiodrive_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
+
+
+static int __init snd_audiodrive_probe(int dev)
+{
+ static int possible_irqs[] = {5, 9, 10, 7, -1};
+ static int possible_dmas[] = {1, 3, 0, -1};
+ int xirq, xdma, xmpu_irq;
+ snd_card_t *card;
+ es1688_t *chip;
+ opl3_t *opl3;
+ snd_pcm_t *pcm;
+ int err;
+
+ card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
+ if (card == NULL)
+ return -ENOMEM;
+
+ xirq = irq[dev];
+ if (xirq == SNDRV_AUTO_IRQ) {
+ if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
+ snd_card_free(card);
+ snd_printk("unable to find a free IRQ\n");
+ return -EBUSY;
+ }
+ }
+ xmpu_irq = mpu_irq[dev];
+ xdma = dma8[dev];
+ if (xdma == SNDRV_AUTO_DMA) {
+ if ((xdma = snd_legacy_find_free_dma(possible_dmas)) < 0) {
+ snd_card_free(card);
+ snd_printk("unable to find a free DMA\n");
+ return -EBUSY;
+ }
+ }
+
+ if ((err = snd_es1688_create(card, port[dev], mpu_port[dev],
+ xirq, xmpu_irq, xdma,
+ ES1688_HW_AUTO, &chip)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if ((err = snd_es1688_pcm(chip, 0, &pcm)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if ((err = snd_es1688_mixer(chip)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+
+ strcpy(card->driver, "ES1688");
+ strcpy(card->shortname, pcm->name);
+ sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name, chip->port, xirq, xdma);
+
+ if ((snd_opl3_create(card, chip->port, chip->port + 2, OPL3_HW_OPL3, 0, &opl3)) < 0) {
+ printk(KERN_ERR "es1688: opl3 not detected at 0x%lx\n", chip->port);
+ } else {
+ if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ }
+
+ if (xmpu_irq >= 0 && xmpu_irq != SNDRV_AUTO_IRQ && chip->mpu_port > 0) {
+ if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
+ chip->mpu_port, 0,
+ xmpu_irq,
+ SA_INTERRUPT,
+ NULL)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ }
+ if ((err = snd_card_register(card)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ snd_audiodrive_cards[dev] = card;
+ return 0;
+
+}
+
+static int __init snd_audiodrive_legacy_auto_probe(unsigned long xport)
+{
+ static int dev;
+ int res;
+
+ for ( ; dev < SNDRV_CARDS; dev++) {
+ if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
+ continue;
+ port[dev] = xport;
+ res = snd_audiodrive_probe(dev);
+ if (res < 0)
+ port[dev] = SNDRV_AUTO_PORT;
+ return res;
+ }
+ return -ENODEV;
+}
+
+static int __init alsa_card_es1688_init(void)
+{
+ static unsigned long possible_ports[] = {0x220, 0x240, 0x260, -1};
+ int dev, cards = 0, i;
+
+ for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
+ if (port[dev] == SNDRV_AUTO_PORT)
+ continue;
+ if (snd_audiodrive_probe(dev) >= 0)
+ cards++;
+ }
+ i = snd_legacy_auto_probe(possible_ports, snd_audiodrive_legacy_auto_probe);
+ if (i > 0)
+ cards += i;
+
+ if (!cards) {
+#ifdef MODULE
+ printk(KERN_ERR "ESS AudioDrive ES1688 soundcard not found or device busy\n");
+#endif
+ return -ENODEV;
+ }
+ return 0;
+}
+
+static void __exit alsa_card_es1688_exit(void)
+{
+ int idx;
+
+ for (idx = 0; idx < SNDRV_CARDS; idx++)
+ snd_card_free(snd_audiodrive_cards[idx]);
+}
+
+module_init(alsa_card_es1688_init)
+module_exit(alsa_card_es1688_exit)
diff --git a/sound/isa/es1688/es1688_lib.c b/sound/isa/es1688/es1688_lib.c
new file mode 100644
index 000000000000..17f68d07d9b2
--- /dev/null
+++ b/sound/isa/es1688/es1688_lib.c
@@ -0,0 +1,1062 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ * Routines for control of ESS ES1688/688/488 chip
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/ioport.h>
+#include <sound/core.h>
+#include <sound/es1688.h>
+#include <sound/initval.h>
+
+#include <asm/io.h>
+#include <asm/dma.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("ESS ESx688 lowlevel module");
+MODULE_LICENSE("GPL");
+
+static int snd_es1688_dsp_command(es1688_t *chip, unsigned char val)
+{
+ int i;
+
+ for (i = 10000; i; i--)
+ if ((inb(ES1688P(chip, STATUS)) & 0x80) == 0) {
+ outb(val, ES1688P(chip, COMMAND));
+ return 1;
+ }
+#ifdef CONFIG_SND_DEBUG
+ printk("snd_es1688_dsp_command: timeout (0x%x)\n", val);
+#endif
+ return 0;
+}
+
+static int snd_es1688_dsp_get_byte(es1688_t *chip)
+{
+ int i;
+
+ for (i = 1000; i; i--)
+ if (inb(ES1688P(chip, DATA_AVAIL)) & 0x80)
+ return inb(ES1688P(chip, READ));
+ snd_printd("es1688 get byte failed: 0x%lx = 0x%x!!!\n", ES1688P(chip, DATA_AVAIL), inb(ES1688P(chip, DATA_AVAIL)));
+ return -ENODEV;
+}
+
+static int snd_es1688_write(es1688_t *chip,
+ unsigned char reg, unsigned char data)
+{
+ if (!snd_es1688_dsp_command(chip, reg))
+ return 0;
+ return snd_es1688_dsp_command(chip, data);
+}
+
+static int snd_es1688_read(es1688_t *chip, unsigned char reg)
+{
+ /* Read a byte from an extended mode register of ES1688 */
+ if (!snd_es1688_dsp_command(chip, 0xc0))
+ return -1;
+ if (!snd_es1688_dsp_command(chip, reg))
+ return -1;
+ return snd_es1688_dsp_get_byte(chip);
+}
+
+void snd_es1688_mixer_write(es1688_t *chip,
+ unsigned char reg, unsigned char data)
+{
+ outb(reg, ES1688P(chip, MIXER_ADDR));
+ udelay(10);
+ outb(data, ES1688P(chip, MIXER_DATA));
+ udelay(10);
+}
+
+static unsigned char snd_es1688_mixer_read(es1688_t *chip, unsigned char reg)
+{
+ unsigned char result;
+
+ outb(reg, ES1688P(chip, MIXER_ADDR));
+ udelay(10);
+ result = inb(ES1688P(chip, MIXER_DATA));
+ udelay(10);
+ return result;
+}
+
+static int snd_es1688_reset(es1688_t *chip)
+{
+ int i;
+
+ outb(3, ES1688P(chip, RESET)); /* valid only for ESS chips, SB -> 1 */
+ udelay(10);
+ outb(0, ES1688P(chip, RESET));
+ udelay(30);
+ for (i = 0; i < 1000 && !(inb(ES1688P(chip, DATA_AVAIL)) & 0x80); i++);
+ if (inb(ES1688P(chip, READ)) != 0xaa) {
+ snd_printd("ess_reset at 0x%lx: failed!!!\n", chip->port);
+ return -ENODEV;
+ }
+ snd_es1688_dsp_command(chip, 0xc6); /* enable extended mode */
+ return 0;
+}
+
+static int snd_es1688_probe(es1688_t *chip)
+{
+ unsigned long flags;
+ unsigned short major, minor, hw;
+ int i;
+
+ /*
+ * initialization sequence
+ */
+
+ spin_lock_irqsave(&chip->reg_lock, flags); /* Some ESS1688 cards need this */
+ inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
+ inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
+ inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
+ inb(ES1688P(chip, ENABLE2)); /* ENABLE2 */
+ inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
+ inb(ES1688P(chip, ENABLE2)); /* ENABLE2 */
+ inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
+ inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
+ inb(ES1688P(chip, ENABLE2)); /* ENABLE2 */
+ inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */
+ inb(ES1688P(chip, ENABLE0)); /* ENABLE0 */
+
+ if (snd_es1688_reset(chip) < 0) {
+ snd_printdd("ESS: [0x%lx] reset failed... 0x%x\n", chip->port, inb(ES1688P(chip, READ)));
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return -ENODEV;
+ }
+ snd_es1688_dsp_command(chip, 0xe7); /* return identification */
+
+ for (i = 1000, major = minor = 0; i; i--) {
+ if (inb(ES1688P(chip, DATA_AVAIL)) & 0x80) {
+ if (major == 0) {
+ major = inb(ES1688P(chip, READ));
+ } else {
+ minor = inb(ES1688P(chip, READ));
+ }
+ }
+ }
+
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+
+ snd_printdd("ESS: [0x%lx] found.. major = 0x%x, minor = 0x%x\n", chip->port, major, minor);
+
+ chip->version = (major << 8) | minor;
+ if (!chip->version)
+ return -ENODEV; /* probably SB */
+
+ hw = ES1688_HW_AUTO;
+ switch (chip->version & 0xfff0) {
+ case 0x4880:
+ snd_printk("[0x%lx] ESS: AudioDrive ES488 detected, but driver is in another place\n", chip->port);
+ return -ENODEV;
+ case 0x6880:
+ hw = (chip->version & 0x0f) >= 8 ? ES1688_HW_1688 : ES1688_HW_688;
+ break;
+ default:
+ snd_printk("[0x%lx] ESS: unknown AudioDrive chip with version 0x%x (Jazz16 soundcard?)\n", chip->port, chip->version);
+ return -ENODEV;
+ }
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_es1688_write(chip, 0xb1, 0x10); /* disable IRQ */
+ snd_es1688_write(chip, 0xb2, 0x00); /* disable DMA */
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+
+ /* enable joystick, but disable OPL3 */
+ spin_lock_irqsave(&chip->mixer_lock, flags);
+ snd_es1688_mixer_write(chip, 0x40, 0x01);
+ spin_unlock_irqrestore(&chip->mixer_lock, flags);
+
+ return 0;
+}
+
+static int snd_es1688_init(es1688_t * chip, int enable)
+{
+ static int irqs[16] = {-1, -1, 0, -1, -1, 1, -1, 2, -1, 0, 3, -1, -1, -1, -1, -1};
+ unsigned long flags;
+ int cfg, irq_bits, dma, dma_bits, tmp, tmp1;
+
+ /* ok.. setup MPU-401 port and joystick and OPL3 */
+ cfg = 0x01; /* enable joystick, but disable OPL3 */
+ if (enable && chip->mpu_port >= 0x300 && chip->mpu_irq > 0 && chip->hardware != ES1688_HW_688) {
+ tmp = (chip->mpu_port & 0x0f0) >> 4;
+ if (tmp <= 3) {
+ switch (chip->mpu_irq) {
+ case 9:
+ tmp1 = 4;
+ break;
+ case 5:
+ tmp1 = 5;
+ break;
+ case 7:
+ tmp1 = 6;
+ break;
+ case 10:
+ tmp1 = 7;
+ break;
+ default:
+ tmp1 = 0;
+ }
+ if (tmp1) {
+ cfg |= (tmp << 3) | (tmp1 << 5);
+ }
+ }
+ }
+#if 0
+ snd_printk("mpu cfg = 0x%x\n", cfg);
+#endif
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_es1688_mixer_write(chip, 0x40, cfg);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ /* --- */
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_es1688_read(chip, 0xb1);
+ snd_es1688_read(chip, 0xb2);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (enable) {
+ cfg = 0xf0; /* enable only DMA counter interrupt */
+ irq_bits = irqs[chip->irq & 0x0f];
+ if (irq_bits < 0) {
+ snd_printk("[0x%lx] ESS: bad IRQ %d for ES1688 chip!!\n", chip->port, chip->irq);
+#if 0
+ irq_bits = 0;
+ cfg = 0x10;
+#endif
+ return -EINVAL;
+ }
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_es1688_write(chip, 0xb1, cfg | (irq_bits << 2));
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ cfg = 0xf0; /* extended mode DMA enable */
+ dma = chip->dma8;
+ if (dma > 3 || dma == 2) {
+ snd_printk("[0x%lx] ESS: bad DMA channel %d for ES1688 chip!!\n", chip->port, dma);
+#if 0
+ dma_bits = 0;
+ cfg = 0x00; /* disable all DMA */
+#endif
+ return -EINVAL;
+ } else {
+ dma_bits = dma;
+ if (dma != 3)
+ dma_bits++;
+ }
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_es1688_write(chip, 0xb2, cfg | (dma_bits << 2));
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ } else {
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_es1688_write(chip, 0xb1, 0x10); /* disable IRQ */
+ snd_es1688_write(chip, 0xb2, 0x00); /* disable DMA */
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ }
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_es1688_read(chip, 0xb1);
+ snd_es1688_read(chip, 0xb2);
+ snd_es1688_reset(chip);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return 0;
+}
+
+/*
+
+ */
+
+static ratnum_t clocks[2] = {
+ {
+ .num = 795444,
+ .den_min = 1,
+ .den_max = 128,
+ .den_step = 1,
+ },
+ {
+ .num = 397722,
+ .den_min = 1,
+ .den_max = 128,
+ .den_step = 1,
+ }
+};
+
+static snd_pcm_hw_constraint_ratnums_t hw_constraints_clocks = {
+ .nrats = 2,
+ .rats = clocks,
+};
+
+static void snd_es1688_set_rate(es1688_t *chip, snd_pcm_substream_t *substream)
+{
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ unsigned int bits, divider;
+
+ if (runtime->rate_num == clocks[0].num)
+ bits = 256 - runtime->rate_den;
+ else
+ bits = 128 - runtime->rate_den;
+ /* set filter register */
+ divider = 256 - 7160000*20/(8*82*runtime->rate);
+ /* write result to hardware */
+ snd_es1688_write(chip, 0xa1, bits);
+ snd_es1688_write(chip, 0xa2, divider);
+}
+
+static int snd_es1688_ioctl(snd_pcm_substream_t * substream,
+ unsigned int cmd, void *arg)
+{
+ return snd_pcm_lib_ioctl(substream, cmd, arg);
+}
+
+static int snd_es1688_trigger(es1688_t *chip, int cmd, unsigned char value)
+{
+ int val;
+
+ if (cmd == SNDRV_PCM_TRIGGER_STOP) {
+ value = 0x00;
+ } else if (cmd != SNDRV_PCM_TRIGGER_START) {
+ return -EINVAL;
+ }
+ spin_lock(&chip->reg_lock);
+ chip->trigger_value = value;
+ val = snd_es1688_read(chip, 0xb8);
+ if ((val < 0) || (val & 0x0f) == value) {
+ spin_unlock(&chip->reg_lock);
+ return -EINVAL; /* something is wrong */
+ }
+#if 0
+ printk("trigger: val = 0x%x, value = 0x%x\n", val, value);
+ printk("trigger: pointer = 0x%x\n", snd_dma_pointer(chip->dma8, chip->dma_size));
+#endif
+ snd_es1688_write(chip, 0xb8, (val & 0xf0) | value);
+ spin_unlock(&chip->reg_lock);
+ return 0;
+}
+
+static int snd_es1688_hw_params(snd_pcm_substream_t * substream,
+ snd_pcm_hw_params_t * hw_params)
+{
+ return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
+}
+
+static int snd_es1688_hw_free(snd_pcm_substream_t * substream)
+{
+ return snd_pcm_lib_free_pages(substream);
+}
+
+static int snd_es1688_playback_prepare(snd_pcm_substream_t * substream)
+{
+ unsigned long flags;
+ es1688_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ unsigned int size = snd_pcm_lib_buffer_bytes(substream);
+ unsigned int count = snd_pcm_lib_period_bytes(substream);
+
+ chip->dma_size = size;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_es1688_reset(chip);
+ snd_es1688_set_rate(chip, substream);
+ snd_es1688_write(chip, 0xb8, 4); /* auto init DMA mode */
+ snd_es1688_write(chip, 0xa8, (snd_es1688_read(chip, 0xa8) & ~0x03) | (3 - runtime->channels));
+ snd_es1688_write(chip, 0xb9, 2); /* demand mode (4 bytes/request) */
+ if (runtime->channels == 1) {
+ if (snd_pcm_format_width(runtime->format) == 8) {
+ /* 8. bit mono */
+ snd_es1688_write(chip, 0xb6, 0x80);
+ snd_es1688_write(chip, 0xb7, 0x51);
+ snd_es1688_write(chip, 0xb7, 0xd0);
+ } else {
+ /* 16. bit mono */
+ snd_es1688_write(chip, 0xb6, 0x00);
+ snd_es1688_write(chip, 0xb7, 0x71);
+ snd_es1688_write(chip, 0xb7, 0xf4);
+ }
+ } else {
+ if (snd_pcm_format_width(runtime->format) == 8) {
+ /* 8. bit stereo */
+ snd_es1688_write(chip, 0xb6, 0x80);
+ snd_es1688_write(chip, 0xb7, 0x51);
+ snd_es1688_write(chip, 0xb7, 0x98);
+ } else {
+ /* 16. bit stereo */
+ snd_es1688_write(chip, 0xb6, 0x00);
+ snd_es1688_write(chip, 0xb7, 0x71);
+ snd_es1688_write(chip, 0xb7, 0xbc);
+ }
+ }
+ snd_es1688_write(chip, 0xb1, (snd_es1688_read(chip, 0xb1) & 0x0f) | 0x50);
+ snd_es1688_write(chip, 0xb2, (snd_es1688_read(chip, 0xb2) & 0x0f) | 0x50);
+ snd_es1688_dsp_command(chip, ES1688_DSP_CMD_SPKON);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ /* --- */
+ count = -count;
+ snd_dma_program(chip->dma8, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_es1688_write(chip, 0xa4, (unsigned char) count);
+ snd_es1688_write(chip, 0xa5, (unsigned char) (count >> 8));
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return 0;
+}
+
+static int snd_es1688_playback_trigger(snd_pcm_substream_t * substream,
+ int cmd)
+{
+ es1688_t *chip = snd_pcm_substream_chip(substream);
+ return snd_es1688_trigger(chip, cmd, 0x05);
+}
+
+static int snd_es1688_capture_prepare(snd_pcm_substream_t * substream)
+{
+ unsigned long flags;
+ es1688_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ unsigned int size = snd_pcm_lib_buffer_bytes(substream);
+ unsigned int count = snd_pcm_lib_period_bytes(substream);
+
+ chip->dma_size = size;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_es1688_reset(chip);
+ snd_es1688_set_rate(chip, substream);
+ snd_es1688_dsp_command(chip, ES1688_DSP_CMD_SPKOFF);
+ snd_es1688_write(chip, 0xb8, 0x0e); /* auto init DMA mode */
+ snd_es1688_write(chip, 0xa8, (snd_es1688_read(chip, 0xa8) & ~0x03) | (3 - runtime->channels));
+ snd_es1688_write(chip, 0xb9, 2); /* demand mode (4 bytes/request) */
+ if (runtime->channels == 1) {
+ if (snd_pcm_format_width(runtime->format) == 8) {
+ /* 8. bit mono */
+ snd_es1688_write(chip, 0xb7, 0x51);
+ snd_es1688_write(chip, 0xb7, 0xd0);
+ } else {
+ /* 16. bit mono */
+ snd_es1688_write(chip, 0xb7, 0x71);
+ snd_es1688_write(chip, 0xb7, 0xf4);
+ }
+ } else {
+ if (snd_pcm_format_width(runtime->format) == 8) {
+ /* 8. bit stereo */
+ snd_es1688_write(chip, 0xb7, 0x51);
+ snd_es1688_write(chip, 0xb7, 0x98);
+ } else {
+ /* 16. bit stereo */
+ snd_es1688_write(chip, 0xb7, 0x71);
+ snd_es1688_write(chip, 0xb7, 0xbc);
+ }
+ }
+ snd_es1688_write(chip, 0xb1, (snd_es1688_read(chip, 0xb1) & 0x0f) | 0x50);
+ snd_es1688_write(chip, 0xb2, (snd_es1688_read(chip, 0xb2) & 0x0f) | 0x50);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ /* --- */
+ count = -count;
+ snd_dma_program(chip->dma8, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ snd_es1688_write(chip, 0xa4, (unsigned char) count);
+ snd_es1688_write(chip, 0xa5, (unsigned char) (count >> 8));
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return 0;
+}
+
+static int snd_es1688_capture_trigger(snd_pcm_substream_t * substream,
+ int cmd)
+{
+ es1688_t *chip = snd_pcm_substream_chip(substream);
+ return snd_es1688_trigger(chip, cmd, 0x0f);
+}
+
+static irqreturn_t snd_es1688_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ es1688_t *chip = dev_id;
+
+ if (chip->trigger_value == 0x05) /* ok.. playback is active */
+ snd_pcm_period_elapsed(chip->playback_substream);
+ if (chip->trigger_value == 0x0f) /* ok.. capture is active */
+ snd_pcm_period_elapsed(chip->capture_substream);
+
+ inb(ES1688P(chip, DATA_AVAIL)); /* ack interrupt */
+ return IRQ_HANDLED;
+}
+
+static snd_pcm_uframes_t snd_es1688_playback_pointer(snd_pcm_substream_t * substream)
+{
+ es1688_t *chip = snd_pcm_substream_chip(substream);
+ size_t ptr;
+
+ if (chip->trigger_value != 0x05)
+ return 0;
+ ptr = snd_dma_pointer(chip->dma8, chip->dma_size);
+ return bytes_to_frames(substream->runtime, ptr);
+}
+
+static snd_pcm_uframes_t snd_es1688_capture_pointer(snd_pcm_substream_t * substream)
+{
+ es1688_t *chip = snd_pcm_substream_chip(substream);
+ size_t ptr;
+
+ if (chip->trigger_value != 0x0f)
+ return 0;
+ ptr = snd_dma_pointer(chip->dma8, chip->dma_size);
+ return bytes_to_frames(substream->runtime, ptr);
+}
+
+/*
+
+ */
+
+static snd_pcm_hardware_t snd_es1688_playback =
+{
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_MMAP_VALID),
+ .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
+ .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
+ .rate_min = 4000,
+ .rate_max = 48000,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = 65536,
+ .period_bytes_min = 64,
+ .period_bytes_max = 65536,
+ .periods_min = 1,
+ .periods_max = 1024,
+ .fifo_size = 0,
+};
+
+static snd_pcm_hardware_t snd_es1688_capture =
+{
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_MMAP_VALID),
+ .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
+ .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
+ .rate_min = 4000,
+ .rate_max = 48000,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = 65536,
+ .period_bytes_min = 64,
+ .period_bytes_max = 65536,
+ .periods_min = 1,
+ .periods_max = 1024,
+ .fifo_size = 0,
+};
+
+/*
+
+ */
+
+static int snd_es1688_playback_open(snd_pcm_substream_t * substream)
+{
+ es1688_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+
+ if (chip->capture_substream != NULL)
+ return -EAGAIN;
+ chip->playback_substream = substream;
+ runtime->hw = snd_es1688_playback;
+ snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+ &hw_constraints_clocks);
+ return 0;
+}
+
+static int snd_es1688_capture_open(snd_pcm_substream_t * substream)
+{
+ es1688_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+
+ if (chip->playback_substream != NULL)
+ return -EAGAIN;
+ chip->capture_substream = substream;
+ runtime->hw = snd_es1688_capture;
+ snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+ &hw_constraints_clocks);
+ return 0;
+}
+
+static int snd_es1688_playback_close(snd_pcm_substream_t * substream)
+{
+ es1688_t *chip = snd_pcm_substream_chip(substream);
+
+ chip->playback_substream = NULL;
+ return 0;
+}
+
+static int snd_es1688_capture_close(snd_pcm_substream_t * substream)
+{
+ es1688_t *chip = snd_pcm_substream_chip(substream);
+
+ chip->capture_substream = NULL;
+ return 0;
+}
+
+static int snd_es1688_free(es1688_t *chip)
+{
+ if (chip->res_port) {
+ snd_es1688_init(chip, 0);
+ release_resource(chip->res_port);
+ kfree_nocheck(chip->res_port);
+ }
+ if (chip->irq >= 0)
+ free_irq(chip->irq, (void *) chip);
+ if (chip->dma8 >= 0) {
+ disable_dma(chip->dma8);
+ free_dma(chip->dma8);
+ }
+ kfree(chip);
+ return 0;
+}
+
+static int snd_es1688_dev_free(snd_device_t *device)
+{
+ es1688_t *chip = device->device_data;
+ return snd_es1688_free(chip);
+}
+
+static const char *snd_es1688_chip_id(es1688_t *chip)
+{
+ static char tmp[16];
+ sprintf(tmp, "ES%s688 rev %i", chip->hardware == ES1688_HW_688 ? "" : "1", chip->version & 0x0f);
+ return tmp;
+}
+
+int snd_es1688_create(snd_card_t * card,
+ unsigned long port,
+ unsigned long mpu_port,
+ int irq,
+ int mpu_irq,
+ int dma8,
+ unsigned short hardware,
+ es1688_t **rchip)
+{
+ static snd_device_ops_t ops = {
+ .dev_free = snd_es1688_dev_free,
+ };
+
+ es1688_t *chip;
+ int err;
+
+ *rchip = NULL;
+ chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
+ if (chip == NULL)
+ return -ENOMEM;
+ chip->irq = -1;
+ chip->dma8 = -1;
+
+ if ((chip->res_port = request_region(port + 4, 12, "ES1688")) == NULL) {
+ snd_printk(KERN_ERR "es1688: can't grab port 0x%lx\n", port + 4);
+ snd_es1688_free(chip);
+ return -EBUSY;
+ }
+ if (request_irq(irq, snd_es1688_interrupt, SA_INTERRUPT, "ES1688", (void *) chip)) {
+ snd_printk(KERN_ERR "es1688: can't grab IRQ %d\n", irq);
+ snd_es1688_free(chip);
+ return -EBUSY;
+ }
+ chip->irq = irq;
+ if (request_dma(dma8, "ES1688")) {
+ snd_printk(KERN_ERR "es1688: can't grab DMA8 %d\n", dma8);
+ snd_es1688_free(chip);
+ return -EBUSY;
+ }
+ chip->dma8 = dma8;
+
+ spin_lock_init(&chip->reg_lock);
+ spin_lock_init(&chip->mixer_lock);
+ chip->card = card;
+ chip->port = port;
+ mpu_port &= ~0x000f;
+ if (mpu_port < 0x300 || mpu_port > 0x330)
+ mpu_port = 0;
+ chip->mpu_port = mpu_port;
+ chip->mpu_irq = mpu_irq;
+ chip->hardware = hardware;
+
+ if ((err = snd_es1688_probe(chip)) < 0) {
+ snd_es1688_free(chip);
+ return err;
+ }
+ if ((err = snd_es1688_init(chip, 1)) < 0) {
+ snd_es1688_free(chip);
+ return err;
+ }
+
+ /* Register device */
+ if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
+ snd_es1688_free(chip);
+ return err;
+ }
+
+ *rchip = chip;
+ return 0;
+}
+
+static snd_pcm_ops_t snd_es1688_playback_ops = {
+ .open = snd_es1688_playback_open,
+ .close = snd_es1688_playback_close,
+ .ioctl = snd_es1688_ioctl,
+ .hw_params = snd_es1688_hw_params,
+ .hw_free = snd_es1688_hw_free,
+ .prepare = snd_es1688_playback_prepare,
+ .trigger = snd_es1688_playback_trigger,
+ .pointer = snd_es1688_playback_pointer,
+};
+
+static snd_pcm_ops_t snd_es1688_capture_ops = {
+ .open = snd_es1688_capture_open,
+ .close = snd_es1688_capture_close,
+ .ioctl = snd_es1688_ioctl,
+ .hw_params = snd_es1688_hw_params,
+ .hw_free = snd_es1688_hw_free,
+ .prepare = snd_es1688_capture_prepare,
+ .trigger = snd_es1688_capture_trigger,
+ .pointer = snd_es1688_capture_pointer,
+};
+
+static void snd_es1688_pcm_free(snd_pcm_t *pcm)
+{
+ es1688_t *chip = pcm->private_data;
+ chip->pcm = NULL;
+ snd_pcm_lib_preallocate_free_for_all(pcm);
+}
+
+int snd_es1688_pcm(es1688_t * chip, int device, snd_pcm_t ** rpcm)
+{
+ snd_pcm_t *pcm;
+ int err;
+
+ if ((err = snd_pcm_new(chip->card, "ESx688", device, 1, 1, &pcm)) < 0)
+ return err;
+
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es1688_playback_ops);
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es1688_capture_ops);
+
+ pcm->private_data = chip;
+ pcm->private_free = snd_es1688_pcm_free;
+ pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
+ sprintf(pcm->name, snd_es1688_chip_id(chip));
+ chip->pcm = pcm;
+
+ snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
+ snd_dma_isa_data(),
+ 64*1024, 64*1024);
+
+ if (rpcm)
+ *rpcm = pcm;
+ return 0;
+}
+
+/*
+ * MIXER part
+ */
+
+static int snd_es1688_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ static char *texts[9] = {
+ "Mic", "Mic Master", "CD", "AOUT",
+ "Mic1", "Mix", "Line", "Master"
+ };
+
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+ uinfo->count = 1;
+ uinfo->value.enumerated.items = 8;
+ if (uinfo->value.enumerated.item > 7)
+ uinfo->value.enumerated.item = 7;
+ strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+ return 0;
+}
+
+static int snd_es1688_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es1688_t *chip = snd_kcontrol_chip(kcontrol);
+ ucontrol->value.enumerated.item[0] = snd_es1688_mixer_read(chip, ES1688_REC_DEV) & 7;
+ return 0;
+}
+
+static int snd_es1688_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es1688_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ unsigned char oval, nval;
+ int change;
+
+ if (ucontrol->value.enumerated.item[0] > 8)
+ return -EINVAL;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ oval = snd_es1688_mixer_read(chip, ES1688_REC_DEV);
+ nval = (ucontrol->value.enumerated.item[0] & 7) | (oval & ~15);
+ change = nval != oval;
+ if (change)
+ snd_es1688_mixer_write(chip, ES1688_REC_DEV, nval);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+#define ES1688_SINGLE(xname, xindex, reg, shift, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+ .info = snd_es1688_info_single, \
+ .get = snd_es1688_get_single, .put = snd_es1688_put_single, \
+ .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
+
+static int snd_es1688_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+
+ uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = mask;
+ return 0;
+}
+
+static int snd_es1688_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es1688_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ucontrol->value.integer.value[0] = (snd_es1688_mixer_read(chip, reg) >> shift) & mask;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ if (invert)
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ return 0;
+}
+
+static int snd_es1688_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es1688_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+ int change;
+ unsigned char oval, nval;
+
+ nval = (ucontrol->value.integer.value[0] & mask);
+ if (invert)
+ nval = mask - nval;
+ nval <<= shift;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ oval = snd_es1688_mixer_read(chip, reg);
+ nval = (oval & ~(mask << shift)) | nval;
+ change = nval != oval;
+ if (change)
+ snd_es1688_mixer_write(chip, reg, nval);
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+#define ES1688_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+ .info = snd_es1688_info_double, \
+ .get = snd_es1688_get_double, .put = snd_es1688_put_double, \
+ .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
+
+static int snd_es1688_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+
+ uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 2;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = mask;
+ return 0;
+}
+
+static int snd_es1688_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es1688_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int left_reg = kcontrol->private_value & 0xff;
+ int right_reg = (kcontrol->private_value >> 8) & 0xff;
+ int shift_left = (kcontrol->private_value >> 16) & 0x07;
+ int shift_right = (kcontrol->private_value >> 19) & 0x07;
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+ int invert = (kcontrol->private_value >> 22) & 1;
+ unsigned char left, right;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ if (left_reg < 0xa0)
+ left = snd_es1688_mixer_read(chip, left_reg);
+ else
+ left = snd_es1688_read(chip, left_reg);
+ if (left_reg != right_reg) {
+ if (right_reg < 0xa0)
+ right = snd_es1688_mixer_read(chip, right_reg);
+ else
+ right = snd_es1688_read(chip, right_reg);
+ } else
+ right = left;
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ ucontrol->value.integer.value[0] = (left >> shift_left) & mask;
+ ucontrol->value.integer.value[1] = (right >> shift_right) & mask;
+ if (invert) {
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
+ }
+ return 0;
+}
+
+static int snd_es1688_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es1688_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int left_reg = kcontrol->private_value & 0xff;
+ int right_reg = (kcontrol->private_value >> 8) & 0xff;
+ int shift_left = (kcontrol->private_value >> 16) & 0x07;
+ int shift_right = (kcontrol->private_value >> 19) & 0x07;
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+ int invert = (kcontrol->private_value >> 22) & 1;
+ int change;
+ unsigned char val1, val2, oval1, oval2;
+
+ val1 = ucontrol->value.integer.value[0] & mask;
+ val2 = ucontrol->value.integer.value[1] & mask;
+ if (invert) {
+ val1 = mask - val1;
+ val2 = mask - val2;
+ }
+ val1 <<= shift_left;
+ val2 <<= shift_right;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ if (left_reg != right_reg) {
+ if (left_reg < 0xa0)
+ oval1 = snd_es1688_mixer_read(chip, left_reg);
+ else
+ oval1 = snd_es1688_read(chip, left_reg);
+ if (right_reg < 0xa0)
+ oval2 = snd_es1688_mixer_read(chip, right_reg);
+ else
+ oval2 = snd_es1688_read(chip, right_reg);
+ val1 = (oval1 & ~(mask << shift_left)) | val1;
+ val2 = (oval2 & ~(mask << shift_right)) | val2;
+ change = val1 != oval1 || val2 != oval2;
+ if (change) {
+ if (left_reg < 0xa0)
+ snd_es1688_mixer_write(chip, left_reg, val1);
+ else
+ snd_es1688_write(chip, left_reg, val1);
+ if (right_reg < 0xa0)
+ snd_es1688_mixer_write(chip, right_reg, val1);
+ else
+ snd_es1688_write(chip, right_reg, val1);
+ }
+ } else {
+ if (left_reg < 0xa0)
+ oval1 = snd_es1688_mixer_read(chip, left_reg);
+ else
+ oval1 = snd_es1688_read(chip, left_reg);
+ val1 = (oval1 & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
+ change = val1 != oval1;
+ if (change) {
+ if (left_reg < 0xa0)
+ snd_es1688_mixer_write(chip, left_reg, val1);
+ else
+ snd_es1688_write(chip, left_reg, val1);
+ }
+
+ }
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return change;
+}
+
+static snd_kcontrol_new_t snd_es1688_controls[] = {
+ES1688_DOUBLE("Master Playback Volume", 0, ES1688_MASTER_DEV, ES1688_MASTER_DEV, 4, 0, 15, 0),
+ES1688_DOUBLE("PCM Playback Volume", 0, ES1688_PCM_DEV, ES1688_PCM_DEV, 4, 0, 15, 0),
+ES1688_DOUBLE("Line Playback Volume", 0, ES1688_LINE_DEV, ES1688_LINE_DEV, 4, 0, 15, 0),
+ES1688_DOUBLE("CD Playback Volume", 0, ES1688_CD_DEV, ES1688_CD_DEV, 4, 0, 15, 0),
+ES1688_DOUBLE("FM Playback Volume", 0, ES1688_FM_DEV, ES1688_FM_DEV, 4, 0, 15, 0),
+ES1688_DOUBLE("Mic Playback Volume", 0, ES1688_MIC_DEV, ES1688_MIC_DEV, 4, 0, 15, 0),
+ES1688_DOUBLE("Aux Playback Volume", 0, ES1688_AUX_DEV, ES1688_AUX_DEV, 4, 0, 15, 0),
+ES1688_SINGLE("PC Speaker Playback Volume", 0, ES1688_SPEAKER_DEV, 0, 7, 0),
+ES1688_DOUBLE("Capture Volume", 0, ES1688_RECLEV_DEV, ES1688_RECLEV_DEV, 4, 0, 15, 0),
+ES1688_SINGLE("Capture Switch", 0, ES1688_REC_DEV, 4, 1, 1),
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "Capture Source",
+ .info = snd_es1688_info_mux,
+ .get = snd_es1688_get_mux,
+ .put = snd_es1688_put_mux,
+},
+};
+
+#define ES1688_INIT_TABLE_SIZE (sizeof(snd_es1688_init_table)/2)
+
+static unsigned char snd_es1688_init_table[][2] = {
+ { ES1688_MASTER_DEV, 0 },
+ { ES1688_PCM_DEV, 0 },
+ { ES1688_LINE_DEV, 0 },
+ { ES1688_CD_DEV, 0 },
+ { ES1688_FM_DEV, 0 },
+ { ES1688_MIC_DEV, 0 },
+ { ES1688_AUX_DEV, 0 },
+ { ES1688_SPEAKER_DEV, 0 },
+ { ES1688_RECLEV_DEV, 0 },
+ { ES1688_REC_DEV, 0x17 }
+};
+
+int snd_es1688_mixer(es1688_t *chip)
+{
+ snd_card_t *card;
+ unsigned int idx;
+ int err;
+ unsigned char reg, val;
+
+ snd_assert(chip != NULL && chip->card != NULL, return -EINVAL);
+
+ card = chip->card;
+
+ strcpy(card->mixername, snd_es1688_chip_id(chip));
+
+ for (idx = 0; idx < ARRAY_SIZE(snd_es1688_controls); idx++) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es1688_controls[idx], chip))) < 0)
+ return err;
+ }
+ for (idx = 0; idx < ES1688_INIT_TABLE_SIZE; idx++) {
+ reg = snd_es1688_init_table[idx][0];
+ val = snd_es1688_init_table[idx][1];
+ if (reg < 0xa0)
+ snd_es1688_mixer_write(chip, reg, val);
+ else
+ snd_es1688_write(chip, reg, val);
+ }
+ return 0;
+}
+
+EXPORT_SYMBOL(snd_es1688_mixer_write);
+EXPORT_SYMBOL(snd_es1688_create);
+EXPORT_SYMBOL(snd_es1688_pcm);
+EXPORT_SYMBOL(snd_es1688_mixer);
+
+/*
+ * INIT part
+ */
+
+static int __init alsa_es1688_init(void)
+{
+ return 0;
+}
+
+static void __exit alsa_es1688_exit(void)
+{
+}
+
+module_init(alsa_es1688_init)
+module_exit(alsa_es1688_exit)
diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c
new file mode 100644
index 000000000000..1d832b2adb7c
--- /dev/null
+++ b/sound/isa/es18xx.c
@@ -0,0 +1,2224 @@
+/*
+ * Driver for generic ESS AudioDrive ES18xx soundcards
+ * Copyright (c) by Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de>
+ * Copyright (c) by Abramo Bagnara <abramo@alsa-project.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+/* GENERAL NOTES:
+ *
+ * BUGS:
+ * - There are pops (we can't delay in trigger function, cause midlevel
+ * often need to trigger down and then up very quickly).
+ * Any ideas?
+ * - Support for 16 bit DMA seems to be broken. I've no hardware to tune it.
+ */
+
+/*
+ * ES1868 NOTES:
+ * - The chip has one half duplex pcm (with very limited full duplex support).
+ *
+ * - Duplex stereophonic sound is impossible.
+ * - Record and playback must share the same frequency rate.
+ *
+ * - The driver use dma2 for playback and dma1 for capture.
+ */
+
+/*
+ * ES1869 NOTES:
+ *
+ * - there are a first full duplex pcm and a second playback only pcm
+ * (incompatible with first pcm capture)
+ *
+ * - there is support for the capture volume and ESS Spatializer 3D effect.
+ *
+ * - contrarily to some pages in DS_1869.PDF the rates can be set
+ * independently.
+ *
+ * BUGS:
+ *
+ * - There is a major trouble I noted:
+ *
+ * using both channel for playback stereo 16 bit samples at 44100 Hz
+ * the second pcm (Audio1) DMA slows down irregularly and sound is garbled.
+ *
+ * The same happens using Audio1 for captureing.
+ *
+ * The Windows driver does not suffer of this (although it use Audio1
+ * only for captureing). I'm unable to discover why.
+ *
+ */
+
+
+#include <sound/driver.h>
+#include <asm/io.h>
+#include <asm/dma.h>
+#include <linux/init.h>
+#include <linux/pm.h>
+#include <linux/slab.h>
+#include <linux/pnp.h>
+#include <linux/isapnp.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/control.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/mpu401.h>
+#include <sound/opl3.h>
+#define SNDRV_LEGACY_AUTO_PROBE
+#define SNDRV_LEGACY_FIND_FREE_IRQ
+#define SNDRV_LEGACY_FIND_FREE_DMA
+#include <sound/initval.h>
+
+#define PFX "es18xx: "
+
+struct _snd_es18xx {
+ unsigned long port; /* port of ESS chip */
+ unsigned long mpu_port; /* MPU-401 port of ESS chip */
+ unsigned long fm_port; /* FM port */
+ unsigned long ctrl_port; /* Control port of ESS chip */
+ struct resource *res_port;
+ struct resource *res_mpu_port;
+ struct resource *res_ctrl_port;
+ int irq; /* IRQ number of ESS chip */
+ int dma1; /* DMA1 */
+ int dma2; /* DMA2 */
+ unsigned short version; /* version of ESS chip */
+ int caps; /* Chip capabilities */
+ unsigned short audio2_vol; /* volume level of audio2 */
+
+ unsigned short active; /* active channel mask */
+ unsigned int dma1_size;
+ unsigned int dma2_size;
+ unsigned int dma1_shift;
+ unsigned int dma2_shift;
+
+ snd_card_t *card;
+ snd_pcm_t *pcm;
+ snd_pcm_substream_t *playback_a_substream;
+ snd_pcm_substream_t *capture_a_substream;
+ snd_pcm_substream_t *playback_b_substream;
+
+ snd_rawmidi_t *rmidi;
+
+ snd_kcontrol_t *hw_volume;
+ snd_kcontrol_t *hw_switch;
+ snd_kcontrol_t *master_volume;
+ snd_kcontrol_t *master_switch;
+
+ spinlock_t reg_lock;
+ spinlock_t mixer_lock;
+ spinlock_t ctrl_lock;
+#ifdef CONFIG_PM
+ unsigned char pm_reg;
+#endif
+};
+
+#define AUDIO1_IRQ 0x01
+#define AUDIO2_IRQ 0x02
+#define HWV_IRQ 0x04
+#define MPU_IRQ 0x08
+
+#define ES18XX_PCM2 0x0001 /* Has two useable PCM */
+#define ES18XX_SPATIALIZER 0x0002 /* Has 3D Spatializer */
+#define ES18XX_RECMIX 0x0004 /* Has record mixer */
+#define ES18XX_DUPLEX_MONO 0x0008 /* Has mono duplex only */
+#define ES18XX_DUPLEX_SAME 0x0010 /* Playback and record must share the same rate */
+#define ES18XX_NEW_RATE 0x0020 /* More precise rate setting */
+#define ES18XX_AUXB 0x0040 /* AuxB mixer control */
+#define ES18XX_HWV 0x0080 /* Has hardware volume */
+#define ES18XX_MONO 0x0100 /* Mono_in mixer control */
+#define ES18XX_I2S 0x0200 /* I2S mixer control */
+#define ES18XX_MUTEREC 0x0400 /* Record source can be muted */
+#define ES18XX_CONTROL 0x0800 /* Has control ports */
+
+/* Power Management */
+#define ES18XX_PM 0x07
+#define ES18XX_PM_GPO0 0x01
+#define ES18XX_PM_GPO1 0x02
+#define ES18XX_PM_PDR 0x04
+#define ES18XX_PM_ANA 0x08
+#define ES18XX_PM_FM 0x020
+#define ES18XX_PM_SUS 0x080
+
+typedef struct _snd_es18xx es18xx_t;
+
+/* Lowlevel */
+
+#define DAC1 0x01
+#define ADC1 0x02
+#define DAC2 0x04
+#define MILLISECOND 10000
+
+static int snd_es18xx_dsp_command(es18xx_t *chip, unsigned char val)
+{
+ int i;
+
+ for(i = MILLISECOND; i; i--)
+ if ((inb(chip->port + 0x0C) & 0x80) == 0) {
+ outb(val, chip->port + 0x0C);
+ return 0;
+ }
+ snd_printk("dsp_command: timeout (0x%x)\n", val);
+ return -EINVAL;
+}
+
+static int snd_es18xx_dsp_get_byte(es18xx_t *chip)
+{
+ int i;
+
+ for(i = MILLISECOND/10; i; i--)
+ if (inb(chip->port + 0x0C) & 0x40)
+ return inb(chip->port + 0x0A);
+ snd_printk("dsp_get_byte failed: 0x%lx = 0x%x!!!\n", chip->port + 0x0A, inb(chip->port + 0x0A));
+ return -ENODEV;
+}
+
+#undef REG_DEBUG
+
+static int snd_es18xx_write(es18xx_t *chip,
+ unsigned char reg, unsigned char data)
+{
+ unsigned long flags;
+ int ret;
+
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ret = snd_es18xx_dsp_command(chip, reg);
+ if (ret < 0)
+ goto end;
+ ret = snd_es18xx_dsp_command(chip, data);
+ end:
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+#ifdef REG_DEBUG
+ snd_printk("Reg %02x set to %02x\n", reg, data);
+#endif
+ return ret;
+}
+
+static int snd_es18xx_read(es18xx_t *chip, unsigned char reg)
+{
+ unsigned long flags;
+ int ret, data;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ret = snd_es18xx_dsp_command(chip, 0xC0);
+ if (ret < 0)
+ goto end;
+ ret = snd_es18xx_dsp_command(chip, reg);
+ if (ret < 0)
+ goto end;
+ data = snd_es18xx_dsp_get_byte(chip);
+ ret = data;
+#ifdef REG_DEBUG
+ snd_printk("Reg %02x now is %02x (%d)\n", reg, data, ret);
+#endif
+ end:
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return ret;
+}
+
+/* Return old value */
+static int snd_es18xx_bits(es18xx_t *chip, unsigned char reg,
+ unsigned char mask, unsigned char val)
+{
+ int ret;
+ unsigned char old, new, oval;
+ unsigned long flags;
+ spin_lock_irqsave(&chip->reg_lock, flags);
+ ret = snd_es18xx_dsp_command(chip, 0xC0);
+ if (ret < 0)
+ goto end;
+ ret = snd_es18xx_dsp_command(chip, reg);
+ if (ret < 0)
+ goto end;
+ ret = snd_es18xx_dsp_get_byte(chip);
+ if (ret < 0) {
+ goto end;
+ }
+ old = ret;
+ oval = old & mask;
+ if (val != oval) {
+ ret = snd_es18xx_dsp_command(chip, reg);
+ if (ret < 0)
+ goto end;
+ new = (old & ~mask) | (val & mask);
+ ret = snd_es18xx_dsp_command(chip, new);
+ if (ret < 0)
+ goto end;
+#ifdef REG_DEBUG
+ snd_printk("Reg %02x was %02x, set to %02x (%d)\n", reg, old, new, ret);
+#endif
+ }
+ ret = oval;
+ end:
+ spin_unlock_irqrestore(&chip->reg_lock, flags);
+ return ret;
+}
+
+static inline void snd_es18xx_mixer_write(es18xx_t *chip,
+ unsigned char reg, unsigned char data)
+{
+ unsigned long flags;
+ spin_lock_irqsave(&chip->mixer_lock, flags);
+ outb(reg, chip->port + 0x04);
+ outb(data, chip->port + 0x05);
+ spin_unlock_irqrestore(&chip->mixer_lock, flags);
+#ifdef REG_DEBUG
+ snd_printk("Mixer reg %02x set to %02x\n", reg, data);
+#endif
+}
+
+static inline int snd_es18xx_mixer_read(es18xx_t *chip, unsigned char reg)
+{
+ unsigned long flags;
+ int data;
+ spin_lock_irqsave(&chip->mixer_lock, flags);
+ outb(reg, chip->port + 0x04);
+ data = inb(chip->port + 0x05);
+ spin_unlock_irqrestore(&chip->mixer_lock, flags);
+#ifdef REG_DEBUG
+ snd_printk("Mixer reg %02x now is %02x\n", reg, data);
+#endif
+ return data;
+}
+
+/* Return old value */
+static inline int snd_es18xx_mixer_bits(es18xx_t *chip, unsigned char reg,
+ unsigned char mask, unsigned char val)
+{
+ unsigned char old, new, oval;
+ unsigned long flags;
+ spin_lock_irqsave(&chip->mixer_lock, flags);
+ outb(reg, chip->port + 0x04);
+ old = inb(chip->port + 0x05);
+ oval = old & mask;
+ if (val != oval) {
+ new = (old & ~mask) | (val & mask);
+ outb(new, chip->port + 0x05);
+#ifdef REG_DEBUG
+ snd_printk("Mixer reg %02x was %02x, set to %02x\n", reg, old, new);
+#endif
+ }
+ spin_unlock_irqrestore(&chip->mixer_lock, flags);
+ return oval;
+}
+
+static inline int snd_es18xx_mixer_writable(es18xx_t *chip, unsigned char reg,
+ unsigned char mask)
+{
+ int old, expected, new;
+ unsigned long flags;
+ spin_lock_irqsave(&chip->mixer_lock, flags);
+ outb(reg, chip->port + 0x04);
+ old = inb(chip->port + 0x05);
+ expected = old ^ mask;
+ outb(expected, chip->port + 0x05);
+ new = inb(chip->port + 0x05);
+ spin_unlock_irqrestore(&chip->mixer_lock, flags);
+#ifdef REG_DEBUG
+ snd_printk("Mixer reg %02x was %02x, set to %02x, now is %02x\n", reg, old, expected, new);
+#endif
+ return expected == new;
+}
+
+
+static int snd_es18xx_reset(es18xx_t *chip)
+{
+ int i;
+ outb(0x03, chip->port + 0x06);
+ inb(chip->port + 0x06);
+ outb(0x00, chip->port + 0x06);
+ for(i = 0; i < MILLISECOND && !(inb(chip->port + 0x0E) & 0x80); i++);
+ if (inb(chip->port + 0x0A) != 0xAA)
+ return -1;
+ return 0;
+}
+
+static int snd_es18xx_reset_fifo(es18xx_t *chip)
+{
+ outb(0x02, chip->port + 0x06);
+ inb(chip->port + 0x06);
+ outb(0x00, chip->port + 0x06);
+ return 0;
+}
+
+static ratnum_t new_clocks[2] = {
+ {
+ .num = 793800,
+ .den_min = 1,
+ .den_max = 128,
+ .den_step = 1,
+ },
+ {
+ .num = 768000,
+ .den_min = 1,
+ .den_max = 128,
+ .den_step = 1,
+ }
+};
+
+static snd_pcm_hw_constraint_ratnums_t new_hw_constraints_clocks = {
+ .nrats = 2,
+ .rats = new_clocks,
+};
+
+static ratnum_t old_clocks[2] = {
+ {
+ .num = 795444,
+ .den_min = 1,
+ .den_max = 128,
+ .den_step = 1,
+ },
+ {
+ .num = 397722,
+ .den_min = 1,
+ .den_max = 128,
+ .den_step = 1,
+ }
+};
+
+static snd_pcm_hw_constraint_ratnums_t old_hw_constraints_clocks = {
+ .nrats = 2,
+ .rats = old_clocks,
+};
+
+
+static void snd_es18xx_rate_set(es18xx_t *chip,
+ snd_pcm_substream_t *substream,
+ int mode)
+{
+ unsigned int bits, div0;
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ if (chip->caps & ES18XX_NEW_RATE) {
+ if (runtime->rate_num == new_clocks[0].num)
+ bits = 128 - runtime->rate_den;
+ else
+ bits = 256 - runtime->rate_den;
+ } else {
+ if (runtime->rate_num == old_clocks[0].num)
+ bits = 256 - runtime->rate_den;
+ else
+ bits = 128 - runtime->rate_den;
+ }
+
+ /* set filter register */
+ div0 = 256 - 7160000*20/(8*82*runtime->rate);
+
+ if ((chip->caps & ES18XX_PCM2) && mode == DAC2) {
+ snd_es18xx_mixer_write(chip, 0x70, bits);
+ /*
+ * Comment from kernel oss driver:
+ * FKS: fascinating: 0x72 doesn't seem to work.
+ */
+ snd_es18xx_write(chip, 0xA2, div0);
+ snd_es18xx_mixer_write(chip, 0x72, div0);
+ } else {
+ snd_es18xx_write(chip, 0xA1, bits);
+ snd_es18xx_write(chip, 0xA2, div0);
+ }
+}
+
+static int snd_es18xx_playback_hw_params(snd_pcm_substream_t * substream,
+ snd_pcm_hw_params_t * hw_params)
+{
+ es18xx_t *chip = snd_pcm_substream_chip(substream);
+ int shift, err;
+
+ shift = 0;
+ if (params_channels(hw_params) == 2)
+ shift++;
+ if (snd_pcm_format_width(params_format(hw_params)) == 16)
+ shift++;
+
+ if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
+ if ((chip->caps & ES18XX_DUPLEX_MONO) &&
+ (chip->capture_a_substream) &&
+ params_channels(hw_params) != 1) {
+ _snd_pcm_hw_param_setempty(hw_params, SNDRV_PCM_HW_PARAM_CHANNELS);
+ return -EBUSY;
+ }
+ chip->dma2_shift = shift;
+ } else {
+ chip->dma1_shift = shift;
+ }
+ if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
+ return err;
+ return 0;
+}
+
+static int snd_es18xx_pcm_hw_free(snd_pcm_substream_t * substream)
+{
+ return snd_pcm_lib_free_pages(substream);
+}
+
+static int snd_es18xx_playback1_prepare(es18xx_t *chip,
+ snd_pcm_substream_t *substream)
+{
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ unsigned int size = snd_pcm_lib_buffer_bytes(substream);
+ unsigned int count = snd_pcm_lib_period_bytes(substream);
+
+ chip->dma2_size = size;
+
+ snd_es18xx_rate_set(chip, substream, DAC2);
+
+ /* Transfer Count Reload */
+ count = 0x10000 - count;
+ snd_es18xx_mixer_write(chip, 0x74, count & 0xff);
+ snd_es18xx_mixer_write(chip, 0x76, count >> 8);
+
+ /* Set format */
+ snd_es18xx_mixer_bits(chip, 0x7A, 0x07,
+ ((runtime->channels == 1) ? 0x00 : 0x02) |
+ (snd_pcm_format_width(runtime->format) == 16 ? 0x01 : 0x00) |
+ (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x04));
+
+ /* Set DMA controller */
+ snd_dma_program(chip->dma2, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
+
+ return 0;
+}
+
+static int snd_es18xx_playback1_trigger(es18xx_t *chip,
+ snd_pcm_substream_t * substream,
+ int cmd)
+{
+ switch (cmd) {
+ case SNDRV_PCM_TRIGGER_START:
+ case SNDRV_PCM_TRIGGER_RESUME:
+ if (chip->active & DAC2)
+ return 0;
+ chip->active |= DAC2;
+ /* Start DMA */
+ if (chip->dma2 >= 4)
+ snd_es18xx_mixer_write(chip, 0x78, 0xb3);
+ else
+ snd_es18xx_mixer_write(chip, 0x78, 0x93);
+#ifdef AVOID_POPS
+ /* Avoid pops */
+ udelay(100000);
+ if (chip->caps & ES18XX_PCM2)
+ /* Restore Audio 2 volume */
+ snd_es18xx_mixer_write(chip, 0x7C, chip->audio2_vol);
+ else
+ /* Enable PCM output */
+ snd_es18xx_dsp_command(chip, 0xD1);
+#endif
+ break;
+ case SNDRV_PCM_TRIGGER_STOP:
+ case SNDRV_PCM_TRIGGER_SUSPEND:
+ if (!(chip->active & DAC2))
+ return 0;
+ chip->active &= ~DAC2;
+ /* Stop DMA */
+ snd_es18xx_mixer_write(chip, 0x78, 0x00);
+#ifdef AVOID_POPS
+ udelay(25000);
+ if (chip->caps & ES18XX_PCM2)
+ /* Set Audio 2 volume to 0 */
+ snd_es18xx_mixer_write(chip, 0x7C, 0);
+ else
+ /* Disable PCM output */
+ snd_es18xx_dsp_command(chip, 0xD3);
+#endif
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int snd_es18xx_capture_hw_params(snd_pcm_substream_t * substream,
+ snd_pcm_hw_params_t * hw_params)
+{
+ es18xx_t *chip = snd_pcm_substream_chip(substream);
+ int shift, err;
+
+ shift = 0;
+ if ((chip->caps & ES18XX_DUPLEX_MONO) &&
+ chip->playback_a_substream &&
+ params_channels(hw_params) != 1) {
+ _snd_pcm_hw_param_setempty(hw_params, SNDRV_PCM_HW_PARAM_CHANNELS);
+ return -EBUSY;
+ }
+ if (params_channels(hw_params) == 2)
+ shift++;
+ if (snd_pcm_format_width(params_format(hw_params)) == 16)
+ shift++;
+ chip->dma1_shift = shift;
+ if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
+ return err;
+ return 0;
+}
+
+static int snd_es18xx_capture_prepare(snd_pcm_substream_t *substream)
+{
+ es18xx_t *chip = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ unsigned int size = snd_pcm_lib_buffer_bytes(substream);
+ unsigned int count = snd_pcm_lib_period_bytes(substream);
+
+ chip->dma1_size = size;
+
+ snd_es18xx_reset_fifo(chip);
+
+ /* Set stereo/mono */
+ snd_es18xx_bits(chip, 0xA8, 0x03, runtime->channels == 1 ? 0x02 : 0x01);
+
+ snd_es18xx_rate_set(chip, substream, ADC1);
+
+ /* Transfer Count Reload */
+ count = 0x10000 - count;
+ snd_es18xx_write(chip, 0xA4, count & 0xff);
+ snd_es18xx_write(chip, 0xA5, count >> 8);
+
+#ifdef AVOID_POPS
+ udelay(100000);
+#endif
+
+ /* Set format */
+ snd_es18xx_write(chip, 0xB7,
+ snd_pcm_format_unsigned(runtime->format) ? 0x51 : 0x71);
+ snd_es18xx_write(chip, 0xB7, 0x90 |
+ ((runtime->channels == 1) ? 0x40 : 0x08) |
+ (snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) |
+ (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20));
+
+ /* Set DMA controler */
+ snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
+
+ return 0;
+}
+
+static int snd_es18xx_capture_trigger(snd_pcm_substream_t *substream,
+ int cmd)
+{
+ es18xx_t *chip = snd_pcm_substream_chip(substream);
+
+ switch (cmd) {
+ case SNDRV_PCM_TRIGGER_START:
+ case SNDRV_PCM_TRIGGER_RESUME:
+ if (chip->active & ADC1)
+ return 0;
+ chip->active |= ADC1;
+ /* Start DMA */
+ snd_es18xx_write(chip, 0xB8, 0x0f);
+ break;
+ case SNDRV_PCM_TRIGGER_STOP:
+ case SNDRV_PCM_TRIGGER_SUSPEND:
+ if (!(chip->active & ADC1))
+ return 0;
+ chip->active &= ~ADC1;
+ /* Stop DMA */
+ snd_es18xx_write(chip, 0xB8, 0x00);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int snd_es18xx_playback2_prepare(es18xx_t *chip,
+ snd_pcm_substream_t *substream)
+{
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ unsigned int size = snd_pcm_lib_buffer_bytes(substream);
+ unsigned int count = snd_pcm_lib_period_bytes(substream);
+
+ chip->dma1_size = size;
+
+ snd_es18xx_reset_fifo(chip);
+
+ /* Set stereo/mono */
+ snd_es18xx_bits(chip, 0xA8, 0x03, runtime->channels == 1 ? 0x02 : 0x01);
+
+ snd_es18xx_rate_set(chip, substream, DAC1);
+
+ /* Transfer Count Reload */
+ count = 0x10000 - count;
+ snd_es18xx_write(chip, 0xA4, count & 0xff);
+ snd_es18xx_write(chip, 0xA5, count >> 8);
+
+ /* Set format */
+ snd_es18xx_write(chip, 0xB6,
+ snd_pcm_format_unsigned(runtime->format) ? 0x80 : 0x00);
+ snd_es18xx_write(chip, 0xB7,
+ snd_pcm_format_unsigned(runtime->format) ? 0x51 : 0x71);
+ snd_es18xx_write(chip, 0xB7, 0x90 |
+ (runtime->channels == 1 ? 0x40 : 0x08) |
+ (snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) |
+ (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20));
+
+ /* Set DMA controler */
+ snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
+
+ return 0;
+}
+
+static int snd_es18xx_playback2_trigger(es18xx_t *chip,
+ snd_pcm_substream_t *substream,
+ int cmd)
+{
+ switch (cmd) {
+ case SNDRV_PCM_TRIGGER_START:
+ case SNDRV_PCM_TRIGGER_RESUME:
+ if (chip->active & DAC1)
+ return 0;
+ chip->active |= DAC1;
+ /* Start DMA */
+ snd_es18xx_write(chip, 0xB8, 0x05);
+#ifdef AVOID_POPS
+ /* Avoid pops */
+ udelay(100000);
+ /* Enable Audio 1 */
+ snd_es18xx_dsp_command(chip, 0xD1);
+#endif
+ break;
+ case SNDRV_PCM_TRIGGER_STOP:
+ case SNDRV_PCM_TRIGGER_SUSPEND:
+ if (!(chip->active & DAC1))
+ return 0;
+ chip->active &= ~DAC1;
+ /* Stop DMA */
+ snd_es18xx_write(chip, 0xB8, 0x00);
+#ifdef AVOID_POPS
+ /* Avoid pops */
+ udelay(25000);
+ /* Disable Audio 1 */
+ snd_es18xx_dsp_command(chip, 0xD3);
+#endif
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int snd_es18xx_playback_prepare(snd_pcm_substream_t *substream)
+{
+ es18xx_t *chip = snd_pcm_substream_chip(substream);
+ if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
+ return snd_es18xx_playback1_prepare(chip, substream);
+ else
+ return snd_es18xx_playback2_prepare(chip, substream);
+}
+
+static int snd_es18xx_playback_trigger(snd_pcm_substream_t *substream,
+ int cmd)
+{
+ es18xx_t *chip = snd_pcm_substream_chip(substream);
+ if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
+ return snd_es18xx_playback1_trigger(chip, substream, cmd);
+ else
+ return snd_es18xx_playback2_trigger(chip, substream, cmd);
+}
+
+static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ es18xx_t *chip = dev_id;
+ unsigned char status;
+
+ if (chip->caps & ES18XX_CONTROL) {
+ /* Read Interrupt status */
+ status = inb(chip->ctrl_port + 6);
+ } else {
+ /* Read Interrupt status */
+ status = snd_es18xx_mixer_read(chip, 0x7f) >> 4;
+ }
+#if 0
+ else {
+ status = 0;
+ if (inb(chip->port + 0x0C) & 0x01)
+ status |= AUDIO1_IRQ;
+ if (snd_es18xx_mixer_read(chip, 0x7A) & 0x80)
+ status |= AUDIO2_IRQ;
+ if ((chip->caps & ES18XX_HWV) &&
+ snd_es18xx_mixer_read(chip, 0x64) & 0x10)
+ status |= HWV_IRQ;
+ }
+#endif
+
+ /* Audio 1 & Audio 2 */
+ if (status & AUDIO2_IRQ) {
+ if (chip->active & DAC2)
+ snd_pcm_period_elapsed(chip->playback_a_substream);
+ /* ack interrupt */
+ snd_es18xx_mixer_bits(chip, 0x7A, 0x80, 0x00);
+ }
+ if (status & AUDIO1_IRQ) {
+ /* ok.. capture is active */
+ if (chip->active & ADC1)
+ snd_pcm_period_elapsed(chip->capture_a_substream);
+ /* ok.. playback2 is active */
+ else if (chip->active & DAC1)
+ snd_pcm_period_elapsed(chip->playback_b_substream);
+ /* ack interrupt */
+ inb(chip->port + 0x0E);
+ }
+
+ /* MPU */
+ if ((status & MPU_IRQ) && chip->rmidi)
+ snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
+
+ /* Hardware volume */
+ if (status & HWV_IRQ) {
+ int split = snd_es18xx_mixer_read(chip, 0x64) & 0x80;
+ snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_switch->id);
+ snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_volume->id);
+ if (!split) {
+ snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_switch->id);
+ snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_volume->id);
+ }
+ /* ack interrupt */
+ snd_es18xx_mixer_write(chip, 0x66, 0x00);
+ }
+ return IRQ_HANDLED;
+}
+
+static snd_pcm_uframes_t snd_es18xx_playback_pointer(snd_pcm_substream_t * substream)
+{
+ es18xx_t *chip = snd_pcm_substream_chip(substream);
+ int pos;
+
+ if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
+ if (!(chip->active & DAC2))
+ return 0;
+ pos = snd_dma_pointer(chip->dma2, chip->dma2_size);
+ return pos >> chip->dma2_shift;
+ } else {
+ if (!(chip->active & DAC1))
+ return 0;
+ pos = snd_dma_pointer(chip->dma1, chip->dma1_size);
+ return pos >> chip->dma1_shift;
+ }
+}
+
+static snd_pcm_uframes_t snd_es18xx_capture_pointer(snd_pcm_substream_t * substream)
+{
+ es18xx_t *chip = snd_pcm_substream_chip(substream);
+ int pos;
+
+ if (!(chip->active & ADC1))
+ return 0;
+ pos = snd_dma_pointer(chip->dma1, chip->dma1_size);
+ return pos >> chip->dma1_shift;
+}
+
+static snd_pcm_hardware_t snd_es18xx_playback =
+{
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_RESUME |
+ SNDRV_PCM_INFO_MMAP_VALID),
+ .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
+ SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE),
+ .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
+ .rate_min = 4000,
+ .rate_max = 48000,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = 65536,
+ .period_bytes_min = 64,
+ .period_bytes_max = 65536,
+ .periods_min = 1,
+ .periods_max = 1024,
+ .fifo_size = 0,
+};
+
+static snd_pcm_hardware_t snd_es18xx_capture =
+{
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_RESUME |
+ SNDRV_PCM_INFO_MMAP_VALID),
+ .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
+ SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE),
+ .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
+ .rate_min = 4000,
+ .rate_max = 48000,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = 65536,
+ .period_bytes_min = 64,
+ .period_bytes_max = 65536,
+ .periods_min = 1,
+ .periods_max = 1024,
+ .fifo_size = 0,
+};
+
+static int snd_es18xx_playback_open(snd_pcm_substream_t * substream)
+{
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ es18xx_t *chip = snd_pcm_substream_chip(substream);
+
+ if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
+ if ((chip->caps & ES18XX_DUPLEX_MONO) &&
+ chip->capture_a_substream &&
+ chip->capture_a_substream->runtime->channels != 1)
+ return -EAGAIN;
+ chip->playback_a_substream = substream;
+ } else if (substream->number <= 1) {
+ if (chip->capture_a_substream)
+ return -EAGAIN;
+ chip->playback_b_substream = substream;
+ } else {
+ snd_BUG();
+ return -EINVAL;
+ }
+ substream->runtime->hw = snd_es18xx_playback;
+ snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+ (chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks);
+ return 0;
+}
+
+static int snd_es18xx_capture_open(snd_pcm_substream_t * substream)
+{
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ es18xx_t *chip = snd_pcm_substream_chip(substream);
+
+ if (chip->playback_b_substream)
+ return -EAGAIN;
+ if ((chip->caps & ES18XX_DUPLEX_MONO) &&
+ chip->playback_a_substream &&
+ chip->playback_a_substream->runtime->channels != 1)
+ return -EAGAIN;
+ chip->capture_a_substream = substream;
+ substream->runtime->hw = snd_es18xx_capture;
+ snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+ (chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks);
+ return 0;
+}
+
+static int snd_es18xx_playback_close(snd_pcm_substream_t * substream)
+{
+ es18xx_t *chip = snd_pcm_substream_chip(substream);
+
+ if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
+ chip->playback_a_substream = NULL;
+ else
+ chip->playback_b_substream = NULL;
+
+ snd_pcm_lib_free_pages(substream);
+ return 0;
+}
+
+static int snd_es18xx_capture_close(snd_pcm_substream_t * substream)
+{
+ es18xx_t *chip = snd_pcm_substream_chip(substream);
+
+ chip->capture_a_substream = NULL;
+ snd_pcm_lib_free_pages(substream);
+ return 0;
+}
+
+/*
+ * MIXER part
+ */
+
+static int snd_es18xx_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ static char *texts[8] = {
+ "Mic", "Mic Master", "CD", "AOUT",
+ "Mic1", "Mix", "Line", "Master"
+ };
+
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+ uinfo->count = 1;
+ uinfo->value.enumerated.items = 8;
+ if (uinfo->value.enumerated.item > 7)
+ uinfo->value.enumerated.item = 7;
+ strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+ return 0;
+}
+
+static int snd_es18xx_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+ ucontrol->value.enumerated.item[0] = snd_es18xx_mixer_read(chip, 0x1c) & 0x07;
+ return 0;
+}
+
+static int snd_es18xx_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned char val = ucontrol->value.enumerated.item[0];
+
+ if (val > 7)
+ return -EINVAL;
+ return snd_es18xx_mixer_bits(chip, 0x1c, 0x07, val) != val;
+}
+
+static int snd_es18xx_info_spatializer_enable(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 1;
+ return 0;
+}
+
+static int snd_es18xx_get_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned char val = snd_es18xx_mixer_read(chip, 0x50);
+ ucontrol->value.integer.value[0] = !!(val & 8);
+ return 0;
+}
+
+static int snd_es18xx_put_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+ unsigned char oval, nval;
+ int change;
+ nval = ucontrol->value.integer.value[0] ? 0x0c : 0x04;
+ oval = snd_es18xx_mixer_read(chip, 0x50) & 0x0c;
+ change = nval != oval;
+ if (change) {
+ snd_es18xx_mixer_write(chip, 0x50, nval & ~0x04);
+ snd_es18xx_mixer_write(chip, 0x50, nval);
+ }
+ return change;
+}
+
+static int snd_es18xx_info_hw_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 2;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 63;
+ return 0;
+}
+
+static int snd_es18xx_get_hw_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+ ucontrol->value.integer.value[0] = snd_es18xx_mixer_read(chip, 0x61) & 0x3f;
+ ucontrol->value.integer.value[1] = snd_es18xx_mixer_read(chip, 0x63) & 0x3f;
+ return 0;
+}
+
+static int snd_es18xx_info_hw_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
+ uinfo->count = 2;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 1;
+ return 0;
+}
+
+static int snd_es18xx_get_hw_switch(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+ ucontrol->value.integer.value[0] = !(snd_es18xx_mixer_read(chip, 0x61) & 0x40);
+ ucontrol->value.integer.value[1] = !(snd_es18xx_mixer_read(chip, 0x63) & 0x40);
+ return 0;
+}
+
+static void snd_es18xx_hwv_free(snd_kcontrol_t *kcontrol)
+{
+ es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+ chip->master_volume = NULL;
+ chip->master_switch = NULL;
+ chip->hw_volume = NULL;
+ chip->hw_switch = NULL;
+}
+
+static int snd_es18xx_reg_bits(es18xx_t *chip, unsigned char reg,
+ unsigned char mask, unsigned char val)
+{
+ if (reg < 0xa0)
+ return snd_es18xx_mixer_bits(chip, reg, mask, val);
+ else
+ return snd_es18xx_bits(chip, reg, mask, val);
+}
+
+static int snd_es18xx_reg_read(es18xx_t *chip, unsigned char reg)
+{
+ if (reg < 0xa0)
+ return snd_es18xx_mixer_read(chip, reg);
+ else
+ return snd_es18xx_read(chip, reg);
+}
+
+#define ES18XX_SINGLE(xname, xindex, reg, shift, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+ .info = snd_es18xx_info_single, \
+ .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \
+ .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
+
+static int snd_es18xx_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+
+ uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = mask;
+ return 0;
+}
+
+static int snd_es18xx_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+ int val;
+
+ val = snd_es18xx_reg_read(chip, reg);
+ ucontrol->value.integer.value[0] = (val >> shift) & mask;
+ if (invert)
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ return 0;
+}
+
+static int snd_es18xx_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+ int reg = kcontrol->private_value & 0xff;
+ int shift = (kcontrol->private_value >> 8) & 0xff;
+ int mask = (kcontrol->private_value >> 16) & 0xff;
+ int invert = (kcontrol->private_value >> 24) & 0xff;
+ unsigned char val;
+
+ val = (ucontrol->value.integer.value[0] & mask);
+ if (invert)
+ val = mask - val;
+ mask <<= shift;
+ val <<= shift;
+ return snd_es18xx_reg_bits(chip, reg, mask, val) != val;
+}
+
+#define ES18XX_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+ .info = snd_es18xx_info_double, \
+ .get = snd_es18xx_get_double, .put = snd_es18xx_put_double, \
+ .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
+
+static int snd_es18xx_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+
+ uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 2;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = mask;
+ return 0;
+}
+
+static int snd_es18xx_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+ int left_reg = kcontrol->private_value & 0xff;
+ int right_reg = (kcontrol->private_value >> 8) & 0xff;
+ int shift_left = (kcontrol->private_value >> 16) & 0x07;
+ int shift_right = (kcontrol->private_value >> 19) & 0x07;
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+ int invert = (kcontrol->private_value >> 22) & 1;
+ unsigned char left, right;
+
+ left = snd_es18xx_reg_read(chip, left_reg);
+ if (left_reg != right_reg)
+ right = snd_es18xx_reg_read(chip, right_reg);
+ else
+ right = left;
+ ucontrol->value.integer.value[0] = (left >> shift_left) & mask;
+ ucontrol->value.integer.value[1] = (right >> shift_right) & mask;
+ if (invert) {
+ ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
+ ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
+ }
+ return 0;
+}
+
+static int snd_es18xx_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+ int left_reg = kcontrol->private_value & 0xff;
+ int right_reg = (kcontrol->private_value >> 8) & 0xff;
+ int shift_left = (kcontrol->private_value >> 16) & 0x07;
+ int shift_right = (kcontrol->private_value >> 19) & 0x07;
+ int mask = (kcontrol->private_value >> 24) & 0xff;
+ int invert = (kcontrol->private_value >> 22) & 1;
+ int change;
+ unsigned char val1, val2, mask1, mask2;
+
+ val1 = ucontrol->value.integer.value[0] & mask;
+ val2 = ucontrol->value.integer.value[1] & mask;
+ if (invert) {
+ val1 = mask - val1;
+ val2 = mask - val2;
+ }
+ val1 <<= shift_left;
+ val2 <<= shift_right;
+ mask1 = mask << shift_left;
+ mask2 = mask << shift_right;
+ if (left_reg != right_reg) {
+ change = 0;
+ if (snd_es18xx_reg_bits(chip, left_reg, mask1, val1) != val1)
+ change = 1;
+ if (snd_es18xx_reg_bits(chip, right_reg, mask2, val2) != val2)
+ change = 1;
+ } else {
+ change = (snd_es18xx_reg_bits(chip, left_reg, mask1 | mask2,
+ val1 | val2) != (val1 | val2));
+ }
+ return change;
+}
+
+static snd_kcontrol_new_t snd_es18xx_base_controls[] = {
+ES18XX_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0),
+ES18XX_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1),
+ES18XX_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0),
+ES18XX_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0),
+ES18XX_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0),
+ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
+ES18XX_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0),
+ES18XX_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0),
+ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0),
+ES18XX_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
+ES18XX_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0),
+ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "Capture Source",
+ .info = snd_es18xx_info_mux,
+ .get = snd_es18xx_get_mux,
+ .put = snd_es18xx_put_mux,
+}
+};
+
+static snd_kcontrol_new_t snd_es18xx_mono_in_control =
+ES18XX_DOUBLE("Mono Input Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0);
+
+static snd_kcontrol_new_t snd_es18xx_recmix_controls[] = {
+ES18XX_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0),
+ES18XX_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0),
+ES18XX_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0),
+ES18XX_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0),
+ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0),
+ES18XX_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0),
+ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0)
+};
+
+static snd_kcontrol_new_t snd_es18xx_pcm1_controls[] = {
+ES18XX_DOUBLE("PCM Playback Volume", 0, 0x14, 0x14, 4, 0, 15, 0),
+};
+
+static snd_kcontrol_new_t snd_es18xx_pcm2_controls[] = {
+ES18XX_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0),
+ES18XX_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0)
+};
+
+static snd_kcontrol_new_t snd_es18xx_spatializer_controls[] = {
+ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "3D Control - Switch",
+ .info = snd_es18xx_info_spatializer_enable,
+ .get = snd_es18xx_get_spatializer_enable,
+ .put = snd_es18xx_put_spatializer_enable,
+}
+};
+
+static snd_kcontrol_new_t snd_es18xx_micpre1_control =
+ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0xa9, 2, 1, 0);
+
+static snd_kcontrol_new_t snd_es18xx_micpre2_control =
+ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0);
+
+static snd_kcontrol_new_t snd_es18xx_hw_volume_controls[] = {
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "Hardware Master Playback Volume",
+ .access = SNDRV_CTL_ELEM_ACCESS_READ,
+ .info = snd_es18xx_info_hw_volume,
+ .get = snd_es18xx_get_hw_volume,
+},
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "Hardware Master Playback Switch",
+ .access = SNDRV_CTL_ELEM_ACCESS_READ,
+ .info = snd_es18xx_info_hw_switch,
+ .get = snd_es18xx_get_hw_switch,
+},
+ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
+};
+
+#if 0
+static int __devinit snd_es18xx_config_read(es18xx_t *chip, unsigned char reg)
+{
+ int data;
+ unsigned long flags;
+ spin_lock_irqsave(&chip->ctrl_lock, flags);
+ outb(reg, chip->ctrl_port);
+ data = inb(chip->ctrl_port + 1);
+ spin_unlock_irqrestore(&chip->ctrl_lock, flags);
+ return data;
+}
+#endif
+
+static void __devinit snd_es18xx_config_write(es18xx_t *chip,
+ unsigned char reg, unsigned char data)
+{
+ /* No need for spinlocks, this function is used only in
+ otherwise protected init code */
+ outb(reg, chip->ctrl_port);
+ outb(data, chip->ctrl_port + 1);
+#ifdef REG_DEBUG
+ snd_printk("Config reg %02x set to %02x\n", reg, data);
+#endif
+}
+
+static int __devinit snd_es18xx_initialize(es18xx_t *chip)
+{
+ int mask = 0;
+
+ /* enable extended mode */
+ snd_es18xx_dsp_command(chip, 0xC6);
+ /* Reset mixer registers */
+ snd_es18xx_mixer_write(chip, 0x00, 0x00);
+
+ /* Audio 1 DMA demand mode (4 bytes/request) */
+ snd_es18xx_write(chip, 0xB9, 2);
+ if (chip->caps & ES18XX_CONTROL) {
+ /* Hardware volume IRQ */
+ snd_es18xx_config_write(chip, 0x27, chip->irq);
+ if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) {
+ /* FM I/O */
+ snd_es18xx_config_write(chip, 0x62, chip->fm_port >> 8);
+ snd_es18xx_config_write(chip, 0x63, chip->fm_port & 0xff);
+ }
+ if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) {
+ /* MPU-401 I/O */
+ snd_es18xx_config_write(chip, 0x64, chip->mpu_port >> 8);
+ snd_es18xx_config_write(chip, 0x65, chip->mpu_port & 0xff);
+ /* MPU-401 IRQ */
+ snd_es18xx_config_write(chip, 0x28, chip->irq);
+ }
+ /* Audio1 IRQ */
+ snd_es18xx_config_write(chip, 0x70, chip->irq);
+ /* Audio2 IRQ */
+ snd_es18xx_config_write(chip, 0x72, chip->irq);
+ /* Audio1 DMA */
+ snd_es18xx_config_write(chip, 0x74, chip->dma1);
+ /* Audio2 DMA */
+ snd_es18xx_config_write(chip, 0x75, chip->dma2);
+
+ /* Enable Audio 1 IRQ */
+ snd_es18xx_write(chip, 0xB1, 0x50);
+ /* Enable Audio 2 IRQ */
+ snd_es18xx_mixer_write(chip, 0x7A, 0x40);
+ /* Enable Audio 1 DMA */
+ snd_es18xx_write(chip, 0xB2, 0x50);
+ /* Enable MPU and hardware volume interrupt */
+ snd_es18xx_mixer_write(chip, 0x64, 0x42);
+ }
+ else {
+ int irqmask, dma1mask, dma2mask;
+ switch (chip->irq) {
+ case 2:
+ case 9:
+ irqmask = 0;
+ break;
+ case 5:
+ irqmask = 1;
+ break;
+ case 7:
+ irqmask = 2;
+ break;
+ case 10:
+ irqmask = 3;
+ break;
+ default:
+ snd_printk("invalid irq %d\n", chip->irq);
+ return -ENODEV;
+ }
+ switch (chip->dma1) {
+ case 0:
+ dma1mask = 1;
+ break;
+ case 1:
+ dma1mask = 2;
+ break;
+ case 3:
+ dma1mask = 3;
+ break;
+ default:
+ snd_printk("invalid dma1 %d\n", chip->dma1);
+ return -ENODEV;
+ }
+ switch (chip->dma2) {
+ case 0:
+ dma2mask = 0;
+ break;
+ case 1:
+ dma2mask = 1;
+ break;
+ case 3:
+ dma2mask = 2;
+ break;
+ case 5:
+ dma2mask = 3;
+ break;
+ default:
+ snd_printk("invalid dma2 %d\n", chip->dma2);
+ return -ENODEV;
+ }
+
+ /* Enable and set Audio 1 IRQ */
+ snd_es18xx_write(chip, 0xB1, 0x50 | (irqmask << 2));
+ /* Enable and set Audio 1 DMA */
+ snd_es18xx_write(chip, 0xB2, 0x50 | (dma1mask << 2));
+ /* Set Audio 2 DMA */
+ snd_es18xx_mixer_bits(chip, 0x7d, 0x07, 0x04 | dma2mask);
+ /* Enable Audio 2 IRQ and DMA
+ Set capture mixer input */
+ snd_es18xx_mixer_write(chip, 0x7A, 0x68);
+ /* Enable and set hardware volume interrupt */
+ snd_es18xx_mixer_write(chip, 0x64, 0x06);
+ if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) {
+ /* MPU401 share irq with audio
+ Joystick enabled
+ FM enabled */
+ snd_es18xx_mixer_write(chip, 0x40, 0x43 | (chip->mpu_port & 0xf0) >> 1);
+ }
+ snd_es18xx_mixer_write(chip, 0x7f, ((irqmask + 1) << 1) | 0x01);
+ }
+ if (chip->caps & ES18XX_NEW_RATE) {
+ /* Change behaviour of register A1
+ 4x oversampling
+ 2nd channel DAC asynchronous */
+ snd_es18xx_mixer_write(chip, 0x71, 0x32);
+ }
+ if (!(chip->caps & ES18XX_PCM2)) {
+ /* Enable DMA FIFO */
+ snd_es18xx_write(chip, 0xB7, 0x80);
+ }
+ if (chip->caps & ES18XX_SPATIALIZER) {
+ /* Set spatializer parameters to recommended values */
+ snd_es18xx_mixer_write(chip, 0x54, 0x8f);
+ snd_es18xx_mixer_write(chip, 0x56, 0x95);
+ snd_es18xx_mixer_write(chip, 0x58, 0x94);
+ snd_es18xx_mixer_write(chip, 0x5a, 0x80);
+ }
+ /* Mute input source */
+ if (chip->caps & ES18XX_MUTEREC)
+ mask = 0x10;
+ if (chip->caps & ES18XX_RECMIX)
+ snd_es18xx_mixer_write(chip, 0x1c, 0x05 | mask);
+ else {
+ snd_es18xx_mixer_write(chip, 0x1c, 0x00 | mask);
+ snd_es18xx_write(chip, 0xb4, 0x00);
+ }
+#ifndef AVOID_POPS
+ /* Enable PCM output */
+ snd_es18xx_dsp_command(chip, 0xD1);
+#endif
+
+ return 0;
+}
+
+static int __devinit snd_es18xx_identify(es18xx_t *chip)
+{
+ int hi,lo;
+
+ /* reset */
+ if (snd_es18xx_reset(chip) < 0) {
+ snd_printk("reset at 0x%lx failed!!!\n", chip->port);
+ return -ENODEV;
+ }
+
+ snd_es18xx_dsp_command(chip, 0xe7);
+ hi = snd_es18xx_dsp_get_byte(chip);
+ if (hi < 0) {
+ return hi;
+ }
+ lo = snd_es18xx_dsp_get_byte(chip);
+ if ((lo & 0xf0) != 0x80) {
+ return -ENODEV;
+ }
+ if (hi == 0x48) {
+ chip->version = 0x488;
+ return 0;
+ }
+ if (hi != 0x68) {
+ return -ENODEV;
+ }
+ if ((lo & 0x0f) < 8) {
+ chip->version = 0x688;
+ return 0;
+ }
+
+ outb(0x40, chip->port + 0x04);
+ hi = inb(chip->port + 0x05);
+ lo = inb(chip->port + 0x05);
+ if (hi != lo) {
+ chip->version = hi << 8 | lo;
+ chip->ctrl_port = inb(chip->port + 0x05) << 8;
+ chip->ctrl_port += inb(chip->port + 0x05);
+
+ if ((chip->res_ctrl_port = request_region(chip->ctrl_port, 8, "ES18xx - CTRL")) == NULL) {
+ snd_printk(KERN_ERR PFX "unable go grab port 0x%lx\n", chip->ctrl_port);
+ return -EBUSY;
+ }
+
+ return 0;
+ }
+
+ /* If has Hardware volume */
+ if (snd_es18xx_mixer_writable(chip, 0x64, 0x04)) {
+ /* If has Audio2 */
+ if (snd_es18xx_mixer_writable(chip, 0x70, 0x7f)) {
+ /* If has volume count */
+ if (snd_es18xx_mixer_writable(chip, 0x64, 0x20)) {
+ chip->version = 0x1887;
+ } else {
+ chip->version = 0x1888;
+ }
+ } else {
+ chip->version = 0x1788;
+ }
+ }
+ else
+ chip->version = 0x1688;
+ return 0;
+}
+
+static int __devinit snd_es18xx_probe(es18xx_t *chip)
+{
+ if (snd_es18xx_identify(chip) < 0) {
+ snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port);
+ return -ENODEV;
+ }
+
+ switch (chip->version) {
+ case 0x1868:
+ chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_CONTROL | ES18XX_HWV;
+ break;
+ case 0x1869:
+ chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_MONO | ES18XX_MUTEREC | ES18XX_CONTROL | ES18XX_HWV;
+ break;
+ case 0x1878:
+ chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV;
+ break;
+ case 0x1879:
+ chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV;
+ break;
+ case 0x1887:
+ chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME | ES18XX_HWV;
+ break;
+ case 0x1888:
+ chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME | ES18XX_HWV;
+ break;
+ default:
+ snd_printk("[0x%lx] unsupported chip ES%x\n",
+ chip->port, chip->version);
+ return -ENODEV;
+ }
+
+ snd_printd("[0x%lx] ESS%x chip found\n", chip->port, chip->version);
+
+ if (chip->dma1 == chip->dma2)
+ chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME);
+
+ return snd_es18xx_initialize(chip);
+}
+
+static snd_pcm_ops_t snd_es18xx_playback_ops = {
+ .open = snd_es18xx_playback_open,
+ .close = snd_es18xx_playback_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_es18xx_playback_hw_params,
+ .hw_free = snd_es18xx_pcm_hw_free,
+ .prepare = snd_es18xx_playback_prepare,
+ .trigger = snd_es18xx_playback_trigger,
+ .pointer = snd_es18xx_playback_pointer,
+};
+
+static snd_pcm_ops_t snd_es18xx_capture_ops = {
+ .open = snd_es18xx_capture_open,
+ .close = snd_es18xx_capture_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_es18xx_capture_hw_params,
+ .hw_free = snd_es18xx_pcm_hw_free,
+ .prepare = snd_es18xx_capture_prepare,
+ .trigger = snd_es18xx_capture_trigger,
+ .pointer = snd_es18xx_capture_pointer,
+};
+
+static void snd_es18xx_pcm_free(snd_pcm_t *pcm)
+{
+ es18xx_t *codec = pcm->private_data;
+ codec->pcm = NULL;
+ snd_pcm_lib_preallocate_free_for_all(pcm);
+}
+
+static int __devinit snd_es18xx_pcm(es18xx_t *chip, int device, snd_pcm_t ** rpcm)
+{
+ snd_pcm_t *pcm;
+ char str[16];
+ int err;
+
+ if (rpcm)
+ *rpcm = NULL;
+ sprintf(str, "ES%x", chip->version);
+ if (chip->caps & ES18XX_PCM2) {
+ err = snd_pcm_new(chip->card, str, device, 2, 1, &pcm);
+ } else {
+ err = snd_pcm_new(chip->card, str, device, 1, 1, &pcm);
+ }
+ if (err < 0)
+ return err;
+
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es18xx_playback_ops);
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es18xx_capture_ops);
+
+ /* global setup */
+ pcm->private_data = chip;
+ pcm->private_free = snd_es18xx_pcm_free;
+ pcm->info_flags = 0;
+ if (chip->caps & ES18XX_DUPLEX_SAME)
+ pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX;
+ if (! (chip->caps & ES18XX_PCM2))
+ pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX;
+ sprintf(pcm->name, "ESS AudioDrive ES%x", chip->version);
+ chip->pcm = pcm;
+
+ snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
+ snd_dma_isa_data(),
+ 64*1024,
+ chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
+
+ if (rpcm)
+ *rpcm = pcm;
+ return 0;
+}
+
+/* Power Management support functions */
+#ifdef CONFIG_PM
+static int snd_es18xx_suspend(snd_card_t *card, pm_message_t state)
+{
+ es18xx_t *chip = card->pm_private_data;
+
+ snd_pcm_suspend_all(chip->pcm);
+
+ /* power down */
+ chip->pm_reg = (unsigned char)snd_es18xx_read(chip, ES18XX_PM);
+ chip->pm_reg |= (ES18XX_PM_FM | ES18XX_PM_SUS);
+ snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg);
+ snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_SUS);
+
+ return 0;
+}
+
+static int snd_es18xx_resume(snd_card_t *card)
+{
+ es18xx_t *chip = card->pm_private_data;
+
+ /* restore PM register, we won't wake till (not 0x07) i/o activity though */
+ snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM);
+
+ return 0;
+}
+#endif /* CONFIG_PM */
+
+static int snd_es18xx_free(es18xx_t *chip)
+{
+ if (chip->res_port) {
+ release_resource(chip->res_port);
+ kfree_nocheck(chip->res_port);
+ }
+ if (chip->res_ctrl_port) {
+ release_resource(chip->res_ctrl_port);
+ kfree_nocheck(chip->res_ctrl_port);
+ }
+ if (chip->res_mpu_port) {
+ release_resource(chip->res_mpu_port);
+ kfree_nocheck(chip->res_mpu_port);
+ }
+ if (chip->irq >= 0)
+ free_irq(chip->irq, (void *) chip);
+ if (chip->dma1 >= 0) {
+ disable_dma(chip->dma1);
+ free_dma(chip->dma1);
+ }
+ if (chip->dma2 >= 0 && chip->dma1 != chip->dma2) {
+ disable_dma(chip->dma2);
+ free_dma(chip->dma2);
+ }
+ kfree(chip);
+ return 0;
+}
+
+static int snd_es18xx_dev_free(snd_device_t *device)
+{
+ es18xx_t *chip = device->device_data;
+ return snd_es18xx_free(chip);
+}
+
+static int __devinit snd_es18xx_new_device(snd_card_t * card,
+ unsigned long port,
+ unsigned long mpu_port,
+ unsigned long fm_port,
+ int irq, int dma1, int dma2,
+ es18xx_t ** rchip)
+{
+ es18xx_t *chip;
+ static snd_device_ops_t ops = {
+ .dev_free = snd_es18xx_dev_free,
+ };
+ int err;
+
+ *rchip = NULL;
+ chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
+ if (chip == NULL)
+ return -ENOMEM;
+ spin_lock_init(&chip->reg_lock);
+ spin_lock_init(&chip->mixer_lock);
+ spin_lock_init(&chip->ctrl_lock);
+ chip->card = card;
+ chip->port = port;
+ chip->mpu_port = mpu_port;
+ chip->fm_port = fm_port;
+ chip->irq = -1;
+ chip->dma1 = -1;
+ chip->dma2 = -1;
+ chip->audio2_vol = 0x00;
+ chip->active = 0;
+
+ if ((chip->res_port = request_region(port, 16, "ES18xx")) == NULL) {
+ snd_es18xx_free(chip);
+ snd_printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1);
+ return -EBUSY;
+ }
+
+ if (request_irq(irq, snd_es18xx_interrupt, SA_INTERRUPT, "ES18xx", (void *) chip)) {
+ snd_es18xx_free(chip);
+ snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq);
+ return -EBUSY;
+ }
+ chip->irq = irq;
+
+ if (request_dma(dma1, "ES18xx DMA 1")) {
+ snd_es18xx_free(chip);
+ snd_printk(KERN_ERR PFX "unable to grap DMA1 %d\n", dma1);
+ return -EBUSY;
+ }
+ chip->dma1 = dma1;
+
+ if (dma2 != dma1 && request_dma(dma2, "ES18xx DMA 2")) {
+ snd_es18xx_free(chip);
+ snd_printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2);
+ return -EBUSY;
+ }
+ chip->dma2 = dma2;
+
+ if (snd_es18xx_probe(chip) < 0) {
+ snd_es18xx_free(chip);
+ return -ENODEV;
+ }
+ if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
+ snd_es18xx_free(chip);
+ return err;
+ }
+ *rchip = chip;
+ return 0;
+}
+
+static int __devinit snd_es18xx_mixer(es18xx_t *chip)
+{
+ snd_card_t *card;
+ int err;
+ unsigned int idx;
+
+ card = chip->card;
+
+ strcpy(card->mixername, chip->pcm->name);
+
+ for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) {
+ snd_kcontrol_t *kctl;
+ kctl = snd_ctl_new1(&snd_es18xx_base_controls[idx], chip);
+ if (chip->caps & ES18XX_HWV) {
+ switch (idx) {
+ case 0:
+ chip->master_volume = kctl;
+ kctl->private_free = snd_es18xx_hwv_free;
+ break;
+ case 1:
+ chip->master_switch = kctl;
+ kctl->private_free = snd_es18xx_hwv_free;
+ break;
+ }
+ }
+ if ((err = snd_ctl_add(card, kctl)) < 0)
+ return err;
+ }
+ if (chip->caps & ES18XX_PCM2) {
+ for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_pcm2_controls); idx++) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_pcm2_controls[idx], chip))) < 0)
+ return err;
+ }
+ } else {
+ for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_pcm1_controls); idx++) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_pcm1_controls[idx], chip))) < 0)
+ return err;
+ }
+ }
+
+ if (chip->caps & ES18XX_MONO) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_mono_in_control, chip))) < 0)
+ return err;
+ }
+ if (chip->caps & ES18XX_RECMIX) {
+ for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_recmix_controls); idx++) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_recmix_controls[idx], chip))) < 0)
+ return err;
+ }
+ }
+ switch (chip->version) {
+ default:
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_micpre1_control, chip))) < 0)
+ return err;
+ break;
+ case 0x1869:
+ case 0x1879:
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_micpre2_control, chip))) < 0)
+ return err;
+ break;
+ }
+ if (chip->caps & ES18XX_SPATIALIZER) {
+ for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_spatializer_controls); idx++) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_spatializer_controls[idx], chip))) < 0)
+ return err;
+ }
+ }
+ if (chip->caps & ES18XX_HWV) {
+ for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_hw_volume_controls); idx++) {
+ snd_kcontrol_t *kctl;
+ kctl = snd_ctl_new1(&snd_es18xx_hw_volume_controls[idx], chip);
+ if (idx == 0)
+ chip->hw_volume = kctl;
+ else
+ chip->hw_switch = kctl;
+ kctl->private_free = snd_es18xx_hwv_free;
+ if ((err = snd_ctl_add(card, kctl)) < 0)
+ return err;
+
+ }
+ }
+ return 0;
+}
+
+
+/* Card level */
+
+MODULE_AUTHOR("Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de>, Abramo Bagnara <abramo@alsa-project.org>");
+MODULE_DESCRIPTION("ESS ES18xx AudioDrive");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{ESS,ES1868 PnP AudioDrive},"
+ "{ESS,ES1869 PnP AudioDrive},"
+ "{ESS,ES1878 PnP AudioDrive},"
+ "{ESS,ES1879 PnP AudioDrive},"
+ "{ESS,ES1887 PnP AudioDrive},"
+ "{ESS,ES1888 PnP AudioDrive},"
+ "{ESS,ES1887 AudioDrive},"
+ "{ESS,ES1888 AudioDrive}}");
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
+#ifdef CONFIG_PNP
+static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
+#endif
+static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */
+#ifndef CONFIG_PNP
+static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
+#else
+static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
+#endif
+static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
+static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
+static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
+static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for ES18xx soundcard.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for ES18xx soundcard.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable ES18xx soundcard.");
+#ifdef CONFIG_PNP
+module_param_array(isapnp, bool, NULL, 0444);
+MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
+#endif
+module_param_array(port, long, NULL, 0444);
+MODULE_PARM_DESC(port, "Port # for ES18xx driver.");
+module_param_array(mpu_port, long, NULL, 0444);
+MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ES18xx driver.");
+module_param_array(fm_port, long, NULL, 0444);
+MODULE_PARM_DESC(fm_port, "FM port # for ES18xx driver.");
+module_param_array(irq, int, NULL, 0444);
+MODULE_PARM_DESC(irq, "IRQ # for ES18xx driver.");
+module_param_array(dma1, int, NULL, 0444);
+MODULE_PARM_DESC(dma1, "DMA 1 # for ES18xx driver.");
+module_param_array(dma2, int, NULL, 0444);
+MODULE_PARM_DESC(dma2, "DMA 2 # for ES18xx driver.");
+
+struct snd_audiodrive {
+#ifdef CONFIG_PNP
+ struct pnp_dev *dev;
+ struct pnp_dev *devc;
+#endif
+};
+
+static snd_card_t *snd_audiodrive_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
+
+#ifdef CONFIG_PNP
+
+static struct pnp_card_device_id snd_audiodrive_pnpids[] = {
+ /* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */
+ { .id = "ESS1868", .devs = { { "ESS1868" }, { "ESS0000" } } },
+ /* ESS 1868 (integrated on Maxisound Cards) */
+ { .id = "ESS1868", .devs = { { "ESS8601" }, { "ESS8600" } } },
+ /* ESS 1868 (integrated on Maxisound Cards) */
+ { .id = "ESS1868", .devs = { { "ESS8611" }, { "ESS8610" } } },
+ /* ESS ES1869 Plug and Play AudioDrive */
+ { .id = "ESS0003", .devs = { { "ESS1869" }, { "ESS0006" } } },
+ /* ESS 1869 */
+ { .id = "ESS1869", .devs = { { "ESS1869" }, { "ESS0006" } } },
+ /* ESS 1878 */
+ { .id = "ESS1878", .devs = { { "ESS1878" }, { "ESS0004" } } },
+ /* ESS 1879 */
+ { .id = "ESS1879", .devs = { { "ESS1879" }, { "ESS0009" } } },
+ /* --- */
+ { .id = "" } /* end */
+};
+
+MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids);
+
+static int __devinit snd_audiodrive_pnp(int dev, struct snd_audiodrive *acard,
+ struct pnp_card_link *card,
+ const struct pnp_card_device_id *id)
+{
+ struct pnp_dev *pdev;
+ struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
+ int err;
+
+ if (!cfg)
+ return -ENOMEM;
+ acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
+ if (acard->dev == NULL) {
+ kfree(cfg);
+ return -EBUSY;
+ }
+ acard->devc = pnp_request_card_device(card, id->devs[1].id, NULL);
+ if (acard->devc == NULL) {
+ kfree(cfg);
+ return -EBUSY;
+ }
+ /* Control port initialization */
+ err = pnp_activate_dev(acard->devc);
+ if (err < 0) {
+ snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n");
+ return -EAGAIN;
+ }
+ snd_printdd("pnp: port=0x%lx\n", pnp_port_start(acard->devc, 0));
+ /* PnP initialization */
+ pdev = acard->dev;
+ pnp_init_resource_table(cfg);
+ if (port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
+ if (fm_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
+ if (mpu_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[2], mpu_port[dev], 2);
+ if (dma1[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
+ if (dma2[dev] != SNDRV_AUTO_DMA)
+ pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
+ if (irq[dev] != SNDRV_AUTO_IRQ)
+ pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
+ err = pnp_manual_config_dev(pdev, cfg, 0);
+ if (err < 0)
+ snd_printk(KERN_ERR PFX "PnP manual resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ snd_printk(KERN_ERR PFX "PnP configure failure (out of resources?)\n");
+ kfree(cfg);
+ return -EBUSY;
+ }
+ /* ok. hack using Vendor-Defined Card-Level registers */
+ /* skip csn and logdev initialization - already done in isapnp_configure */
+ if (pnp_device_is_isapnp(pdev)) {
+ isapnp_cfg_begin(isapnp_card_number(pdev), isapnp_csn_number(pdev));
+ isapnp_write_byte(0x27, pnp_irq(pdev, 0)); /* Hardware Volume IRQ Number */
+ if (mpu_port[dev] != SNDRV_AUTO_PORT)
+ isapnp_write_byte(0x28, pnp_irq(pdev, 0)); /* MPU-401 IRQ Number */
+ isapnp_write_byte(0x72, pnp_irq(pdev, 0)); /* second IRQ */
+ isapnp_cfg_end();
+ } else {
+ snd_printk(KERN_ERR PFX "unable to install ISA PnP hack, expect malfunction\n");
+ }
+ port[dev] = pnp_port_start(pdev, 0);
+ fm_port[dev] = pnp_port_start(pdev, 1);
+ mpu_port[dev] = pnp_port_start(pdev, 2);
+ dma1[dev] = pnp_dma(pdev, 0);
+ dma2[dev] = pnp_dma(pdev, 1);
+ irq[dev] = pnp_irq(pdev, 0);
+ snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port[dev], fm_port[dev], mpu_port[dev]);
+ snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
+ kfree(cfg);
+ return 0;
+}
+#endif /* CONFIG_PNP */
+
+static int __devinit snd_audiodrive_probe(int dev, struct pnp_card_link *pcard,
+ const struct pnp_card_device_id *pid)
+{
+ static int possible_irqs[] = {5, 9, 10, 7, 11, 12, -1};
+ static int possible_dmas[] = {1, 0, 3, 5, -1};
+ int xirq, xdma1, xdma2;
+ snd_card_t *card;
+ struct snd_audiodrive *acard;
+ snd_rawmidi_t *rmidi = NULL;
+ es18xx_t *chip;
+ opl3_t *opl3;
+ int err;
+
+ card = snd_card_new(index[dev], id[dev], THIS_MODULE,
+ sizeof(struct snd_audiodrive));
+ if (card == NULL)
+ return -ENOMEM;
+ acard = (struct snd_audiodrive *)card->private_data;
+#ifdef CONFIG_PNP
+ if (isapnp[dev]) {
+ if ((err = snd_audiodrive_pnp(dev, acard, pcard, pid)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ snd_card_set_dev(card, &pcard->card->dev);
+ }
+#endif
+
+ xirq = irq[dev];
+ if (xirq == SNDRV_AUTO_IRQ) {
+ if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
+ snd_card_free(card);
+ snd_printk("unable to find a free IRQ\n");
+ return -EBUSY;
+ }
+ }
+ xdma1 = dma1[dev];
+ if (xdma1 == SNDRV_AUTO_DMA) {
+ if ((xdma1 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
+ snd_card_free(card);
+ snd_printk("unable to find a free DMA1\n");
+ return -EBUSY;
+ }
+ }
+ xdma2 = dma2[dev];
+ if (xdma2 == SNDRV_AUTO_DMA) {
+ if ((xdma2 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
+ snd_card_free(card);
+ snd_printk("unable to find a free DMA2\n");
+ return -EBUSY;
+ }
+ }
+
+ if ((err = snd_es18xx_new_device(card,
+ port[dev],
+ mpu_port[dev],
+ fm_port[dev],
+ xirq, xdma1, xdma2,
+ &chip)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+
+ sprintf(card->driver, "ES%x", chip->version);
+ sprintf(card->shortname, "ESS AudioDrive ES%x", chip->version);
+ if (xdma1 != xdma2)
+ sprintf(card->longname, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d",
+ card->shortname,
+ chip->port,
+ xirq, xdma1, xdma2);
+ else
+ sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
+ card->shortname,
+ chip->port,
+ xirq, xdma1);
+
+ if ((err = snd_es18xx_pcm(chip, 0, NULL)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if ((err = snd_es18xx_mixer(chip)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+
+ if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
+ if (snd_opl3_create(card, chip->fm_port, chip->fm_port + 2, OPL3_HW_OPL3, 0, &opl3) < 0) {
+ snd_printk(KERN_ERR PFX "opl3 not detected at 0x%lx\n", chip->fm_port);
+ } else {
+ if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ }
+ }
+
+ if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
+ if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX,
+ chip->mpu_port, 0,
+ xirq, 0,
+ &rmidi)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ chip->rmidi = rmidi;
+ }
+
+ /* Power Management */
+ snd_card_set_isa_pm_callback(card, snd_es18xx_suspend, snd_es18xx_resume, chip);
+
+ if ((err = snd_card_register(card)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if (pcard)
+ pnp_set_card_drvdata(pcard, card);
+ else
+ snd_audiodrive_legacy[dev] = card;
+ return 0;
+}
+
+static int __devinit snd_audiodrive_probe_legacy_port(unsigned long xport)
+{
+ static int dev;
+ int res;
+
+ for ( ; dev < SNDRV_CARDS; dev++) {
+ if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
+ continue;
+#ifdef CONFIG_PNP
+ if (isapnp[dev])
+ continue;
+#endif
+ port[dev] = xport;
+ res = snd_audiodrive_probe(dev, NULL, NULL);
+ if (res < 0)
+ port[dev] = SNDRV_AUTO_PORT;
+ return res;
+ }
+ return -ENODEV;
+}
+
+
+#ifdef CONFIG_PNP
+static int __devinit snd_audiodrive_pnp_detect(struct pnp_card_link *card,
+ const struct pnp_card_device_id *id)
+{
+ static int dev;
+ int res;
+
+ for ( ; dev < SNDRV_CARDS; dev++) {
+ if (!enable[dev] || !isapnp[dev])
+ continue;
+ res = snd_audiodrive_probe(dev, card, id);
+ if (res < 0)
+ return res;
+ dev++;
+ return 0;
+ }
+
+ return -ENODEV;
+}
+
+static void __devexit snd_audiodrive_pnp_remove(struct pnp_card_link * pcard)
+{
+ snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
+
+ snd_card_disconnect(card);
+ snd_card_free_in_thread(card);
+}
+
+static struct pnp_card_driver es18xx_pnpc_driver = {
+ .flags = PNP_DRIVER_RES_DISABLE,
+ .name = "es18xx",
+ .id_table = snd_audiodrive_pnpids,
+ .probe = snd_audiodrive_pnp_detect,
+ .remove = __devexit_p(snd_audiodrive_pnp_remove),
+};
+#endif /* CONFIG_PNP */
+
+static int __init alsa_card_es18xx_init(void)
+{
+ static unsigned long possible_ports[] = {0x220, 0x240, 0x260, 0x280, -1};
+ int dev, cards = 0, i;
+
+ /* legacy non-auto cards at first */
+ for (dev = 0; dev < SNDRV_CARDS; dev++) {
+ if (!enable[dev] || port[dev] == SNDRV_AUTO_PORT)
+ continue;
+#ifdef CONFIG_PNP
+ if (isapnp[dev])
+ continue;
+#endif
+ if (snd_audiodrive_probe(dev, NULL, NULL) >= 0)
+ cards++;
+ }
+ /* legacy auto configured cards */
+ i = snd_legacy_auto_probe(possible_ports, snd_audiodrive_probe_legacy_port);
+ if (i > 0)
+ cards += i;
+
+#ifdef CONFIG_PNP
+ /* ISA PnP cards at last */
+ i = pnp_register_card_driver(&es18xx_pnpc_driver);
+ if (i > 0)
+ cards += i;
+
+#endif
+ if(!cards) {
+#ifdef CONFIG_PNP
+ pnp_unregister_card_driver(&es18xx_pnpc_driver);
+#endif
+#ifdef MODULE
+ snd_printk(KERN_ERR "ESS AudioDrive ES18xx soundcard not found or device busy\n");
+#endif
+ return -ENODEV;
+ }
+ return 0;
+}
+
+static void __exit alsa_card_es18xx_exit(void)
+{
+ int idx;
+
+#ifdef CONFIG_PNP
+ /* PnP cards first */
+ pnp_unregister_card_driver(&es18xx_pnpc_driver);
+#endif
+ for(idx = 0; idx < SNDRV_CARDS; idx++)
+ snd_card_free(snd_audiodrive_legacy[idx]);
+}
+
+module_init(alsa_card_es18xx_init)
+module_exit(alsa_card_es18xx_exit)
diff --git a/sound/isa/gus/Makefile b/sound/isa/gus/Makefile
new file mode 100644
index 000000000000..bae5dbd6c8e5
--- /dev/null
+++ b/sound/isa/gus/Makefile
@@ -0,0 +1,36 @@
+#
+# Makefile for ALSA
+# Copyright (c) 2001 by Jaroslav Kysela <perex@suse.cz>
+#
+
+snd-gus-lib-objs := gus_main.o \
+ gus_io.o gus_irq.o gus_timer.o \
+ gus_mem.o gus_mem_proc.o gus_dram.o gus_dma.o gus_volume.o \
+ gus_pcm.o gus_mixer.o \
+ gus_uart.o \
+ gus_reset.o
+snd-gus-synth-objs := gus_synth.o gus_sample.o gus_simple.o gus_instr.o
+
+snd-gusclassic-objs := gusclassic.o
+snd-gusextreme-objs := gusextreme.o
+snd-gusmax-objs := gusmax.o
+snd-interwave-objs := interwave.o
+snd-interwave-stb-objs := interwave-stb.o
+
+#
+# this function returns:
+# "m" - CONFIG_SND_SEQUENCER is m
+# <empty string> - CONFIG_SND_SEQUENCER is undefined
+# otherwise parameter #1 value
+#
+sequencer = $(if $(subst y,,$(CONFIG_SND_SEQUENCER)),$(if $(1),m),$(if $(CONFIG_SND_SEQUENCER),$(1)))
+
+# Toplevel Module Dependency
+obj-$(CONFIG_SND_GUSCLASSIC) += snd-gusclassic.o snd-gus-lib.o
+obj-$(CONFIG_SND_GUSMAX) += snd-gusmax.o snd-gus-lib.o
+obj-$(CONFIG_SND_GUSEXTREME) += snd-gusextreme.o snd-gus-lib.o
+obj-$(CONFIG_SND_INTERWAVE) += snd-interwave.o snd-gus-lib.o
+obj-$(CONFIG_SND_INTERWAVE_STB) += snd-interwave-stb.o snd-gus-lib.o
+obj-$(call sequencer,$(CONFIG_SND_GUS_SYNTH)) += snd-gus-synth.o
+
+obj-m := $(sort $(obj-m))
diff --git a/sound/isa/gus/gus_dma.c b/sound/isa/gus/gus_dma.c
new file mode 100644
index 000000000000..de4b56d80b35
--- /dev/null
+++ b/sound/isa/gus/gus_dma.c
@@ -0,0 +1,244 @@
+/*
+ * Routines for GF1 DMA control
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <asm/dma.h>
+#include <linux/slab.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+
+static void snd_gf1_dma_ack(snd_gus_card_t * gus)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_write8(gus, SNDRV_GF1_GB_DRAM_DMA_CONTROL, 0x00);
+ snd_gf1_look8(gus, SNDRV_GF1_GB_DRAM_DMA_CONTROL);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+static void snd_gf1_dma_program(snd_gus_card_t * gus,
+ unsigned int addr,
+ unsigned long buf_addr,
+ unsigned int count,
+ unsigned int cmd)
+{
+ unsigned long flags;
+ unsigned int address;
+ unsigned char dma_cmd;
+ unsigned int address_high;
+
+ // snd_printk("dma_transfer: addr=0x%x, buf=0x%lx, count=0x%x\n", addr, (long) buf, count);
+
+ if (gus->gf1.dma1 > 3) {
+ if (gus->gf1.enh_mode) {
+ address = addr >> 1;
+ } else {
+ if (addr & 0x1f) {
+ snd_printd("snd_gf1_dma_transfer: unaligned address (0x%x)?\n", addr);
+ return;
+ }
+ address = (addr & 0x000c0000) | ((addr & 0x0003ffff) >> 1);
+ }
+ } else {
+ address = addr;
+ }
+
+ dma_cmd = SNDRV_GF1_DMA_ENABLE | (unsigned short) cmd;
+#if 0
+ dma_cmd |= 0x08;
+#endif
+ if (dma_cmd & SNDRV_GF1_DMA_16BIT) {
+ count++;
+ count &= ~1; /* align */
+ }
+ if (gus->gf1.dma1 > 3) {
+ dma_cmd |= SNDRV_GF1_DMA_WIDTH16;
+ count++;
+ count &= ~1; /* align */
+ }
+ snd_gf1_dma_ack(gus);
+ snd_dma_program(gus->gf1.dma1, buf_addr, count, dma_cmd & SNDRV_GF1_DMA_READ ? DMA_MODE_READ : DMA_MODE_WRITE);
+#if 0
+ snd_printk("address = 0x%x, count = 0x%x, dma_cmd = 0x%x\n", address << 1, count, dma_cmd);
+#endif
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ if (gus->gf1.enh_mode) {
+ address_high = ((address >> 16) & 0x000000f0) | (address & 0x0000000f);
+ snd_gf1_write16(gus, SNDRV_GF1_GW_DRAM_DMA_LOW, (unsigned short) (address >> 4));
+ snd_gf1_write8(gus, SNDRV_GF1_GB_DRAM_DMA_HIGH, (unsigned char) address_high);
+ } else
+ snd_gf1_write16(gus, SNDRV_GF1_GW_DRAM_DMA_LOW, (unsigned short) (address >> 4));
+ snd_gf1_write8(gus, SNDRV_GF1_GB_DRAM_DMA_CONTROL, dma_cmd);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+static snd_gf1_dma_block_t *snd_gf1_dma_next_block(snd_gus_card_t * gus)
+{
+ snd_gf1_dma_block_t *block;
+
+ /* PCM block have bigger priority than synthesizer one */
+ if (gus->gf1.dma_data_pcm) {
+ block = gus->gf1.dma_data_pcm;
+ if (gus->gf1.dma_data_pcm_last == block) {
+ gus->gf1.dma_data_pcm =
+ gus->gf1.dma_data_pcm_last = NULL;
+ } else {
+ gus->gf1.dma_data_pcm = block->next;
+ }
+ } else if (gus->gf1.dma_data_synth) {
+ block = gus->gf1.dma_data_synth;
+ if (gus->gf1.dma_data_synth_last == block) {
+ gus->gf1.dma_data_synth =
+ gus->gf1.dma_data_synth_last = NULL;
+ } else {
+ gus->gf1.dma_data_synth = block->next;
+ }
+ } else {
+ block = NULL;
+ }
+ if (block) {
+ gus->gf1.dma_ack = block->ack;
+ gus->gf1.dma_private_data = block->private_data;
+ }
+ return block;
+}
+
+
+static void snd_gf1_dma_interrupt(snd_gus_card_t * gus)
+{
+ snd_gf1_dma_block_t *block;
+
+ snd_gf1_dma_ack(gus);
+ if (gus->gf1.dma_ack)
+ gus->gf1.dma_ack(gus, gus->gf1.dma_private_data);
+ spin_lock(&gus->dma_lock);
+ if (gus->gf1.dma_data_pcm == NULL &&
+ gus->gf1.dma_data_synth == NULL) {
+ gus->gf1.dma_ack = NULL;
+ gus->gf1.dma_flags &= ~SNDRV_GF1_DMA_TRIGGER;
+ spin_unlock(&gus->dma_lock);
+ return;
+ }
+ block = snd_gf1_dma_next_block(gus);
+ spin_unlock(&gus->dma_lock);
+ snd_gf1_dma_program(gus, block->addr, block->buf_addr, block->count, (unsigned short) block->cmd);
+ kfree(block);
+#if 0
+ printk("program dma (IRQ) - addr = 0x%x, buffer = 0x%lx, count = 0x%x, cmd = 0x%x\n", addr, (long) buffer, count, cmd);
+#endif
+}
+
+int snd_gf1_dma_init(snd_gus_card_t * gus)
+{
+ down(&gus->dma_mutex);
+ gus->gf1.dma_shared++;
+ if (gus->gf1.dma_shared > 1) {
+ up(&gus->dma_mutex);
+ return 0;
+ }
+ gus->gf1.interrupt_handler_dma_write = snd_gf1_dma_interrupt;
+ gus->gf1.dma_data_pcm =
+ gus->gf1.dma_data_pcm_last =
+ gus->gf1.dma_data_synth =
+ gus->gf1.dma_data_synth_last = NULL;
+ up(&gus->dma_mutex);
+ return 0;
+}
+
+int snd_gf1_dma_done(snd_gus_card_t * gus)
+{
+ snd_gf1_dma_block_t *block;
+
+ down(&gus->dma_mutex);
+ gus->gf1.dma_shared--;
+ if (!gus->gf1.dma_shared) {
+ snd_dma_disable(gus->gf1.dma1);
+ snd_gf1_set_default_handlers(gus, SNDRV_GF1_HANDLER_DMA_WRITE);
+ snd_gf1_dma_ack(gus);
+ while ((block = gus->gf1.dma_data_pcm)) {
+ gus->gf1.dma_data_pcm = block->next;
+ kfree(block);
+ }
+ while ((block = gus->gf1.dma_data_synth)) {
+ gus->gf1.dma_data_synth = block->next;
+ kfree(block);
+ }
+ gus->gf1.dma_data_pcm_last =
+ gus->gf1.dma_data_synth_last = NULL;
+ }
+ up(&gus->dma_mutex);
+ return 0;
+}
+
+int snd_gf1_dma_transfer_block(snd_gus_card_t * gus,
+ snd_gf1_dma_block_t * __block,
+ int atomic,
+ int synth)
+{
+ unsigned long flags;
+ snd_gf1_dma_block_t *block;
+
+ block = kmalloc(sizeof(*block), atomic ? GFP_ATOMIC : GFP_KERNEL);
+ if (block == NULL) {
+ snd_printk("gf1: DMA transfer failure; not enough memory\n");
+ return -ENOMEM;
+ }
+ *block = *__block;
+ block->next = NULL;
+#if 0
+ printk("addr = 0x%x, buffer = 0x%lx, count = 0x%x, cmd = 0x%x\n", block->addr, (long) block->buffer, block->count, block->cmd);
+#endif
+#if 0
+ printk("gus->gf1.dma_data_pcm_last = 0x%lx\n", (long)gus->gf1.dma_data_pcm_last);
+ printk("gus->gf1.dma_data_pcm = 0x%lx\n", (long)gus->gf1.dma_data_pcm);
+#endif
+ spin_lock_irqsave(&gus->dma_lock, flags);
+ if (synth) {
+ if (gus->gf1.dma_data_synth_last) {
+ gus->gf1.dma_data_synth_last->next = block;
+ gus->gf1.dma_data_synth_last = block;
+ } else {
+ gus->gf1.dma_data_synth =
+ gus->gf1.dma_data_synth_last = block;
+ }
+ } else {
+ if (gus->gf1.dma_data_pcm_last) {
+ gus->gf1.dma_data_pcm_last->next = block;
+ gus->gf1.dma_data_pcm_last = block;
+ } else {
+ gus->gf1.dma_data_pcm =
+ gus->gf1.dma_data_pcm_last = block;
+ }
+ }
+ if (!(gus->gf1.dma_flags & SNDRV_GF1_DMA_TRIGGER)) {
+ gus->gf1.dma_flags |= SNDRV_GF1_DMA_TRIGGER;
+ block = snd_gf1_dma_next_block(gus);
+ spin_unlock_irqrestore(&gus->dma_lock, flags);
+ if (block == NULL)
+ return 0;
+ snd_gf1_dma_program(gus, block->addr, block->buf_addr, block->count, (unsigned short) block->cmd);
+ kfree(block);
+ return 0;
+ }
+ spin_unlock_irqrestore(&gus->dma_lock, flags);
+ return 0;
+}
diff --git a/sound/isa/gus/gus_dram.c b/sound/isa/gus/gus_dram.c
new file mode 100644
index 000000000000..22120b868b5c
--- /dev/null
+++ b/sound/isa/gus/gus_dram.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ * DRAM access routines
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/time.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+#include <sound/info.h>
+
+
+static int snd_gus_dram_poke(snd_gus_card_t *gus, char __user *_buffer,
+ unsigned int address, unsigned int size)
+{
+ unsigned long flags;
+ unsigned int size1, size2;
+ char buffer[256], *pbuffer;
+
+ while (size > 0) {
+ size1 = size > sizeof(buffer) ? sizeof(buffer) : size;
+ if (copy_from_user(buffer, _buffer, size1))
+ return -EFAULT;
+ if (gus->interwave) {
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01);
+ snd_gf1_dram_addr(gus, address);
+ outsb(GUSP(gus, DRAM), buffer, size1);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ address += size1;
+ } else {
+ pbuffer = buffer;
+ size2 = size1;
+ while (size2--)
+ snd_gf1_poke(gus, address++, *pbuffer++);
+ }
+ size -= size1;
+ _buffer += size1;
+ }
+ return 0;
+}
+
+
+int snd_gus_dram_write(snd_gus_card_t *gus, char __user *buffer,
+ unsigned int address, unsigned int size)
+{
+ return snd_gus_dram_poke(gus, buffer, address, size);
+}
+
+static int snd_gus_dram_peek(snd_gus_card_t *gus, char __user *_buffer,
+ unsigned int address, unsigned int size,
+ int rom)
+{
+ unsigned long flags;
+ unsigned int size1, size2;
+ char buffer[256], *pbuffer;
+
+ while (size > 0) {
+ size1 = size > sizeof(buffer) ? sizeof(buffer) : size;
+ if (gus->interwave) {
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, rom ? 0x03 : 0x01);
+ snd_gf1_dram_addr(gus, address);
+ insb(GUSP(gus, DRAM), buffer, size1);
+ snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ address += size1;
+ } else {
+ pbuffer = buffer;
+ size2 = size1;
+ while (size2--)
+ *pbuffer++ = snd_gf1_peek(gus, address++);
+ }
+ if (copy_to_user(_buffer, buffer, size1))
+ return -EFAULT;
+ size -= size1;
+ _buffer += size1;
+ }
+ return 0;
+}
+
+int snd_gus_dram_read(snd_gus_card_t *gus, char __user *buffer,
+ unsigned int address, unsigned int size,
+ int rom)
+{
+ return snd_gus_dram_peek(gus, buffer, address, size, rom);
+}
diff --git a/sound/isa/gus/gus_instr.c b/sound/isa/gus/gus_instr.c
new file mode 100644
index 000000000000..591a9a17feb5
--- /dev/null
+++ b/sound/isa/gus/gus_instr.c
@@ -0,0 +1,173 @@
+/*
+ * Routines for Gravis UltraSound soundcards - Synthesizer
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/time.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+
+/*
+ *
+ */
+
+int snd_gus_iwffff_put_sample(void *private_data, iwffff_wave_t *wave,
+ char __user *data, long len, int atomic)
+{
+ snd_gus_card_t *gus = private_data;
+ snd_gf1_mem_block_t *block;
+ int err;
+
+ if (wave->format & IWFFFF_WAVE_ROM)
+ return 0; /* it's probably ok - verify the address? */
+ if (wave->format & IWFFFF_WAVE_STEREO)
+ return -EINVAL; /* not supported */
+ block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc,
+ SNDRV_GF1_MEM_OWNER_WAVE_IWFFFF,
+ NULL, wave->size,
+ wave->format & IWFFFF_WAVE_16BIT, 1,
+ wave->share_id);
+ if (block == NULL)
+ return -ENOMEM;
+ err = snd_gus_dram_write(gus, data,
+ block->ptr, wave->size);
+ if (err < 0) {
+ snd_gf1_mem_lock(&gus->gf1.mem_alloc, 0);
+ snd_gf1_mem_xfree(&gus->gf1.mem_alloc, block);
+ snd_gf1_mem_lock(&gus->gf1.mem_alloc, 1);
+ return err;
+ }
+ wave->address.memory = block->ptr;
+ return 0;
+}
+
+int snd_gus_iwffff_get_sample(void *private_data, iwffff_wave_t *wave,
+ char __user *data, long len, int atomic)
+{
+ snd_gus_card_t *gus = private_data;
+
+ return snd_gus_dram_read(gus, data, wave->address.memory, wave->size,
+ wave->format & IWFFFF_WAVE_ROM ? 1 : 0);
+}
+
+int snd_gus_iwffff_remove_sample(void *private_data, iwffff_wave_t *wave,
+ int atomic)
+{
+ snd_gus_card_t *gus = private_data;
+
+ if (wave->format & IWFFFF_WAVE_ROM)
+ return 0; /* it's probably ok - verify the address? */
+ return snd_gf1_mem_free(&gus->gf1.mem_alloc, wave->address.memory);
+}
+
+/*
+ *
+ */
+
+int snd_gus_gf1_put_sample(void *private_data, gf1_wave_t *wave,
+ char __user *data, long len, int atomic)
+{
+ snd_gus_card_t *gus = private_data;
+ snd_gf1_mem_block_t *block;
+ int err;
+
+ if (wave->format & GF1_WAVE_STEREO)
+ return -EINVAL; /* not supported */
+ block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc,
+ SNDRV_GF1_MEM_OWNER_WAVE_GF1,
+ NULL, wave->size,
+ wave->format & GF1_WAVE_16BIT, 1,
+ wave->share_id);
+ if (block == NULL)
+ return -ENOMEM;
+ err = snd_gus_dram_write(gus, data,
+ block->ptr, wave->size);
+ if (err < 0) {
+ snd_gf1_mem_lock(&gus->gf1.mem_alloc, 0);
+ snd_gf1_mem_xfree(&gus->gf1.mem_alloc, block);
+ snd_gf1_mem_lock(&gus->gf1.mem_alloc, 1);
+ return err;
+ }
+ wave->address.memory = block->ptr;
+ return 0;
+}
+
+int snd_gus_gf1_get_sample(void *private_data, gf1_wave_t *wave,
+ char __user *data, long len, int atomic)
+{
+ snd_gus_card_t *gus = private_data;
+
+ return snd_gus_dram_read(gus, data, wave->address.memory, wave->size, 0);
+}
+
+int snd_gus_gf1_remove_sample(void *private_data, gf1_wave_t *wave,
+ int atomic)
+{
+ snd_gus_card_t *gus = private_data;
+
+ return snd_gf1_mem_free(&gus->gf1.mem_alloc, wave->address.memory);
+}
+
+/*
+ *
+ */
+
+int snd_gus_simple_put_sample(void *private_data, simple_instrument_t *instr,
+ char __user *data, long len, int atomic)
+{
+ snd_gus_card_t *gus = private_data;
+ snd_gf1_mem_block_t *block;
+ int err;
+
+ if (instr->format & SIMPLE_WAVE_STEREO)
+ return -EINVAL; /* not supported */
+ block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc,
+ SNDRV_GF1_MEM_OWNER_WAVE_SIMPLE,
+ NULL, instr->size,
+ instr->format & SIMPLE_WAVE_16BIT, 1,
+ instr->share_id);
+ if (block == NULL)
+ return -ENOMEM;
+ err = snd_gus_dram_write(gus, data, block->ptr, instr->size);
+ if (err < 0) {
+ snd_gf1_mem_lock(&gus->gf1.mem_alloc, 0);
+ snd_gf1_mem_xfree(&gus->gf1.mem_alloc, block);
+ snd_gf1_mem_lock(&gus->gf1.mem_alloc, 1);
+ return err;
+ }
+ instr->address.memory = block->ptr;
+ return 0;
+}
+
+int snd_gus_simple_get_sample(void *private_data, simple_instrument_t *instr,
+ char __user *data, long len, int atomic)
+{
+ snd_gus_card_t *gus = private_data;
+
+ return snd_gus_dram_read(gus, data, instr->address.memory, instr->size, 0);
+}
+
+int snd_gus_simple_remove_sample(void *private_data, simple_instrument_t *instr,
+ int atomic)
+{
+ snd_gus_card_t *gus = private_data;
+
+ return snd_gf1_mem_free(&gus->gf1.mem_alloc, instr->address.memory);
+}
diff --git a/sound/isa/gus/gus_io.c b/sound/isa/gus/gus_io.c
new file mode 100644
index 000000000000..f0570f2bf75f
--- /dev/null
+++ b/sound/isa/gus/gus_io.c
@@ -0,0 +1,531 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ * I/O routines for GF1/InterWave synthesizer chips
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/delay.h>
+#include <linux/time.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+
+void snd_gf1_delay(snd_gus_card_t * gus)
+{
+ int i;
+
+ for (i = 0; i < 6; i++) {
+ mb();
+ inb(GUSP(gus, DRAM));
+ }
+}
+
+/*
+ * =======================================================================
+ */
+
+/*
+ * ok.. stop of control registers (wave & ramp) need some special things..
+ * big UltraClick (tm) elimination...
+ */
+
+static inline void __snd_gf1_ctrl_stop(snd_gus_card_t * gus, unsigned char reg)
+{
+ unsigned char value;
+
+ outb(reg | 0x80, gus->gf1.reg_regsel);
+ mb();
+ value = inb(gus->gf1.reg_data8);
+ mb();
+ outb(reg, gus->gf1.reg_regsel);
+ mb();
+ outb((value | 0x03) & ~(0x80 | 0x20), gus->gf1.reg_data8);
+ mb();
+}
+
+static inline void __snd_gf1_write8(snd_gus_card_t * gus,
+ unsigned char reg,
+ unsigned char data)
+{
+ outb(reg, gus->gf1.reg_regsel);
+ mb();
+ outb(data, gus->gf1.reg_data8);
+ mb();
+}
+
+static inline unsigned char __snd_gf1_look8(snd_gus_card_t * gus,
+ unsigned char reg)
+{
+ outb(reg, gus->gf1.reg_regsel);
+ mb();
+ return inb(gus->gf1.reg_data8);
+}
+
+static inline void __snd_gf1_write16(snd_gus_card_t * gus,
+ unsigned char reg, unsigned int data)
+{
+ outb(reg, gus->gf1.reg_regsel);
+ mb();
+ outw((unsigned short) data, gus->gf1.reg_data16);
+ mb();
+}
+
+static inline unsigned short __snd_gf1_look16(snd_gus_card_t * gus,
+ unsigned char reg)
+{
+ outb(reg, gus->gf1.reg_regsel);
+ mb();
+ return inw(gus->gf1.reg_data16);
+}
+
+static inline void __snd_gf1_adlib_write(snd_gus_card_t * gus,
+ unsigned char reg, unsigned char data)
+{
+ outb(reg, gus->gf1.reg_timerctrl);
+ inb(gus->gf1.reg_timerctrl);
+ inb(gus->gf1.reg_timerctrl);
+ outb(data, gus->gf1.reg_timerdata);
+ inb(gus->gf1.reg_timerctrl);
+ inb(gus->gf1.reg_timerctrl);
+}
+
+static inline void __snd_gf1_write_addr(snd_gus_card_t * gus, unsigned char reg,
+ unsigned int addr, int w_16bit)
+{
+ if (gus->gf1.enh_mode) {
+ if (w_16bit)
+ addr = ((addr >> 1) & ~0x0000000f) | (addr & 0x0000000f);
+ __snd_gf1_write8(gus, SNDRV_GF1_VB_UPPER_ADDRESS, (unsigned char) ((addr >> 26) & 0x03));
+ } else if (w_16bit)
+ addr = (addr & 0x00c0000f) | ((addr & 0x003ffff0) >> 1);
+ __snd_gf1_write16(gus, reg, (unsigned short) (addr >> 11));
+ __snd_gf1_write16(gus, reg + 1, (unsigned short) (addr << 5));
+}
+
+static inline unsigned int __snd_gf1_read_addr(snd_gus_card_t * gus,
+ unsigned char reg, short w_16bit)
+{
+ unsigned int res;
+
+ res = ((unsigned int) __snd_gf1_look16(gus, reg | 0x80) << 11) & 0xfff800;
+ res |= ((unsigned int) __snd_gf1_look16(gus, (reg + 1) | 0x80) >> 5) & 0x0007ff;
+ if (gus->gf1.enh_mode) {
+ res |= (unsigned int) __snd_gf1_look8(gus, SNDRV_GF1_VB_UPPER_ADDRESS | 0x80) << 26;
+ if (w_16bit)
+ res = ((res << 1) & 0xffffffe0) | (res & 0x0000000f);
+ } else if (w_16bit)
+ res = ((res & 0x001ffff0) << 1) | (res & 0x00c0000f);
+ return res;
+}
+
+
+/*
+ * =======================================================================
+ */
+
+void snd_gf1_ctrl_stop(snd_gus_card_t * gus, unsigned char reg)
+{
+ __snd_gf1_ctrl_stop(gus, reg);
+}
+
+void snd_gf1_write8(snd_gus_card_t * gus,
+ unsigned char reg,
+ unsigned char data)
+{
+ __snd_gf1_write8(gus, reg, data);
+}
+
+unsigned char snd_gf1_look8(snd_gus_card_t * gus, unsigned char reg)
+{
+ return __snd_gf1_look8(gus, reg);
+}
+
+void snd_gf1_write16(snd_gus_card_t * gus,
+ unsigned char reg,
+ unsigned int data)
+{
+ __snd_gf1_write16(gus, reg, data);
+}
+
+unsigned short snd_gf1_look16(snd_gus_card_t * gus, unsigned char reg)
+{
+ return __snd_gf1_look16(gus, reg);
+}
+
+void snd_gf1_adlib_write(snd_gus_card_t * gus,
+ unsigned char reg,
+ unsigned char data)
+{
+ __snd_gf1_adlib_write(gus, reg, data);
+}
+
+void snd_gf1_write_addr(snd_gus_card_t * gus, unsigned char reg,
+ unsigned int addr, short w_16bit)
+{
+ __snd_gf1_write_addr(gus, reg, addr, w_16bit);
+}
+
+unsigned int snd_gf1_read_addr(snd_gus_card_t * gus,
+ unsigned char reg,
+ short w_16bit)
+{
+ return __snd_gf1_read_addr(gus, reg, w_16bit);
+}
+
+/*
+
+ */
+
+void snd_gf1_i_ctrl_stop(snd_gus_card_t * gus, unsigned char reg)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ __snd_gf1_ctrl_stop(gus, reg);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+void snd_gf1_i_write8(snd_gus_card_t * gus,
+ unsigned char reg,
+ unsigned char data)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ __snd_gf1_write8(gus, reg, data);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+unsigned char snd_gf1_i_look8(snd_gus_card_t * gus, unsigned char reg)
+{
+ unsigned long flags;
+ unsigned char res;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ res = __snd_gf1_look8(gus, reg);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return res;
+}
+
+void snd_gf1_i_write16(snd_gus_card_t * gus,
+ unsigned char reg,
+ unsigned int data)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ __snd_gf1_write16(gus, reg, data);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+unsigned short snd_gf1_i_look16(snd_gus_card_t * gus, unsigned char reg)
+{
+ unsigned long flags;
+ unsigned short res;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ res = __snd_gf1_look16(gus, reg);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return res;
+}
+
+void snd_gf1_i_adlib_write(snd_gus_card_t * gus,
+ unsigned char reg,
+ unsigned char data)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ __snd_gf1_adlib_write(gus, reg, data);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+void snd_gf1_i_write_addr(snd_gus_card_t * gus, unsigned char reg,
+ unsigned int addr, short w_16bit)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ __snd_gf1_write_addr(gus, reg, addr, w_16bit);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+unsigned int snd_gf1_i_read_addr(snd_gus_card_t * gus,
+ unsigned char reg, short w_16bit)
+{
+ unsigned int res;
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ res = __snd_gf1_read_addr(gus, reg, w_16bit);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return res;
+}
+
+/*
+
+ */
+
+void snd_gf1_dram_addr(snd_gus_card_t * gus, unsigned int addr)
+{
+ outb(0x43, gus->gf1.reg_regsel);
+ mb();
+ outw((unsigned short) addr, gus->gf1.reg_data16);
+ mb();
+ outb(0x44, gus->gf1.reg_regsel);
+ mb();
+ outb((unsigned char) (addr >> 16), gus->gf1.reg_data8);
+ mb();
+}
+
+void snd_gf1_poke(snd_gus_card_t * gus, unsigned int addr, unsigned char data)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ outb(SNDRV_GF1_GW_DRAM_IO_LOW, gus->gf1.reg_regsel);
+ mb();
+ outw((unsigned short) addr, gus->gf1.reg_data16);
+ mb();
+ outb(SNDRV_GF1_GB_DRAM_IO_HIGH, gus->gf1.reg_regsel);
+ mb();
+ outb((unsigned char) (addr >> 16), gus->gf1.reg_data8);
+ mb();
+ outb(data, gus->gf1.reg_dram);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+unsigned char snd_gf1_peek(snd_gus_card_t * gus, unsigned int addr)
+{
+ unsigned long flags;
+ unsigned char res;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ outb(SNDRV_GF1_GW_DRAM_IO_LOW, gus->gf1.reg_regsel);
+ mb();
+ outw((unsigned short) addr, gus->gf1.reg_data16);
+ mb();
+ outb(SNDRV_GF1_GB_DRAM_IO_HIGH, gus->gf1.reg_regsel);
+ mb();
+ outb((unsigned char) (addr >> 16), gus->gf1.reg_data8);
+ mb();
+ res = inb(gus->gf1.reg_dram);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return res;
+}
+
+void snd_gf1_pokew(snd_gus_card_t * gus, unsigned int addr, unsigned short data)
+{
+ unsigned long flags;
+
+#ifdef CONFIG_SND_DEBUG
+ if (!gus->interwave)
+ snd_printk("snd_gf1_pokew - GF1!!!\n");
+#endif
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ outb(SNDRV_GF1_GW_DRAM_IO_LOW, gus->gf1.reg_regsel);
+ mb();
+ outw((unsigned short) addr, gus->gf1.reg_data16);
+ mb();
+ outb(SNDRV_GF1_GB_DRAM_IO_HIGH, gus->gf1.reg_regsel);
+ mb();
+ outb((unsigned char) (addr >> 16), gus->gf1.reg_data8);
+ mb();
+ outb(SNDRV_GF1_GW_DRAM_IO16, gus->gf1.reg_regsel);
+ mb();
+ outw(data, gus->gf1.reg_data16);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+unsigned short snd_gf1_peekw(snd_gus_card_t * gus, unsigned int addr)
+{
+ unsigned long flags;
+ unsigned short res;
+
+#ifdef CONFIG_SND_DEBUG
+ if (!gus->interwave)
+ snd_printk("snd_gf1_peekw - GF1!!!\n");
+#endif
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ outb(SNDRV_GF1_GW_DRAM_IO_LOW, gus->gf1.reg_regsel);
+ mb();
+ outw((unsigned short) addr, gus->gf1.reg_data16);
+ mb();
+ outb(SNDRV_GF1_GB_DRAM_IO_HIGH, gus->gf1.reg_regsel);
+ mb();
+ outb((unsigned char) (addr >> 16), gus->gf1.reg_data8);
+ mb();
+ outb(SNDRV_GF1_GW_DRAM_IO16, gus->gf1.reg_regsel);
+ mb();
+ res = inw(gus->gf1.reg_data16);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return res;
+}
+
+void snd_gf1_dram_setmem(snd_gus_card_t * gus, unsigned int addr,
+ unsigned short value, unsigned int count)
+{
+ unsigned long port;
+ unsigned long flags;
+
+#ifdef CONFIG_SND_DEBUG
+ if (!gus->interwave)
+ snd_printk("snd_gf1_dram_setmem - GF1!!!\n");
+#endif
+ addr &= ~1;
+ count >>= 1;
+ port = GUSP(gus, GF1DATALOW);
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ outb(SNDRV_GF1_GW_DRAM_IO_LOW, gus->gf1.reg_regsel);
+ mb();
+ outw((unsigned short) addr, gus->gf1.reg_data16);
+ mb();
+ outb(SNDRV_GF1_GB_DRAM_IO_HIGH, gus->gf1.reg_regsel);
+ mb();
+ outb((unsigned char) (addr >> 16), gus->gf1.reg_data8);
+ mb();
+ outb(SNDRV_GF1_GW_DRAM_IO16, gus->gf1.reg_regsel);
+ while (count--)
+ outw(value, port);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+/*
+
+ */
+
+void snd_gf1_select_active_voices(snd_gus_card_t * gus)
+{
+ unsigned short voices;
+
+ static unsigned short voices_tbl[32 - 14 + 1] =
+ {
+ 44100, 41160, 38587, 36317, 34300, 32494, 30870, 29400, 28063, 26843,
+ 25725, 24696, 23746, 22866, 22050, 21289, 20580, 19916, 19293
+ };
+
+ voices = gus->gf1.active_voices;
+ if (voices > 32)
+ voices = 32;
+ if (voices < 14)
+ voices = 14;
+ if (gus->gf1.enh_mode)
+ voices = 32;
+ gus->gf1.active_voices = voices;
+ gus->gf1.playback_freq =
+ gus->gf1.enh_mode ? 44100 : voices_tbl[voices - 14];
+ if (!gus->gf1.enh_mode) {
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_ACTIVE_VOICES, 0xc0 | (voices - 1));
+ udelay(100);
+ }
+}
+
+#ifdef CONFIG_SND_DEBUG
+
+void snd_gf1_print_voice_registers(snd_gus_card_t * gus)
+{
+ unsigned char mode;
+ int voice, ctrl;
+
+ voice = gus->gf1.active_voice;
+ printk(" -%i- GF1 voice ctrl, ramp ctrl = 0x%x, 0x%x\n", voice, ctrl = snd_gf1_i_read8(gus, 0), snd_gf1_i_read8(gus, 0x0d));
+ printk(" -%i- GF1 frequency = 0x%x\n", voice, snd_gf1_i_read16(gus, 1));
+ printk(" -%i- GF1 loop start, end = 0x%x (0x%x), 0x%x (0x%x)\n", voice, snd_gf1_i_read_addr(gus, 2, ctrl & 4), snd_gf1_i_read_addr(gus, 2, (ctrl & 4) ^ 4), snd_gf1_i_read_addr(gus, 4, ctrl & 4), snd_gf1_i_read_addr(gus, 4, (ctrl & 4) ^ 4));
+ printk(" -%i- GF1 ramp start, end, rate = 0x%x, 0x%x, 0x%x\n", voice, snd_gf1_i_read8(gus, 7), snd_gf1_i_read8(gus, 8), snd_gf1_i_read8(gus, 6));
+ printk(" -%i- GF1 volume = 0x%x\n", voice, snd_gf1_i_read16(gus, 9));
+ printk(" -%i- GF1 position = 0x%x (0x%x)\n", voice, snd_gf1_i_read_addr(gus, 0x0a, ctrl & 4), snd_gf1_i_read_addr(gus, 0x0a, (ctrl & 4) ^ 4));
+ if (gus->interwave && snd_gf1_i_read8(gus, 0x19) & 0x01) { /* enhanced mode */
+ mode = snd_gf1_i_read8(gus, 0x15);
+ printk(" -%i- GFA1 mode = 0x%x\n", voice, mode);
+ if (mode & 0x01) { /* Effect processor */
+ printk(" -%i- GFA1 effect address = 0x%x\n", voice, snd_gf1_i_read_addr(gus, 0x11, ctrl & 4));
+ printk(" -%i- GFA1 effect volume = 0x%x\n", voice, snd_gf1_i_read16(gus, 0x16));
+ printk(" -%i- GFA1 effect volume final = 0x%x\n", voice, snd_gf1_i_read16(gus, 0x1d));
+ printk(" -%i- GFA1 effect acumulator = 0x%x\n", voice, snd_gf1_i_read8(gus, 0x14));
+ }
+ if (mode & 0x20) {
+ printk(" -%i- GFA1 left offset = 0x%x (%i)\n", voice, snd_gf1_i_read16(gus, 0x13), snd_gf1_i_read16(gus, 0x13) >> 4);
+ printk(" -%i- GFA1 left offset final = 0x%x (%i)\n", voice, snd_gf1_i_read16(gus, 0x1c), snd_gf1_i_read16(gus, 0x1c) >> 4);
+ printk(" -%i- GFA1 right offset = 0x%x (%i)\n", voice, snd_gf1_i_read16(gus, 0x0c), snd_gf1_i_read16(gus, 0x0c) >> 4);
+ printk(" -%i- GFA1 right offset final = 0x%x (%i)\n", voice, snd_gf1_i_read16(gus, 0x1b), snd_gf1_i_read16(gus, 0x1b) >> 4);
+ } else
+ printk(" -%i- GF1 pan = 0x%x\n", voice, snd_gf1_i_read8(gus, 0x0c));
+ } else
+ printk(" -%i- GF1 pan = 0x%x\n", voice, snd_gf1_i_read8(gus, 0x0c));
+}
+
+void snd_gf1_print_global_registers(snd_gus_card_t * gus)
+{
+ unsigned char global_mode = 0x00;
+
+ printk(" -G- GF1 active voices = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_ACTIVE_VOICES));
+ if (gus->interwave) {
+ global_mode = snd_gf1_i_read8(gus, SNDRV_GF1_GB_GLOBAL_MODE);
+ printk(" -G- GF1 global mode = 0x%x\n", global_mode);
+ }
+ if (global_mode & 0x02) /* LFO enabled? */
+ printk(" -G- GF1 LFO base = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_LFO_BASE));
+ printk(" -G- GF1 voices IRQ read = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_VOICES_IRQ_READ));
+ printk(" -G- GF1 DRAM DMA control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_DMA_CONTROL));
+ printk(" -G- GF1 DRAM DMA high/low = 0x%x/0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_DMA_HIGH), snd_gf1_i_read16(gus, SNDRV_GF1_GW_DRAM_DMA_LOW));
+ printk(" -G- GF1 DRAM IO high/low = 0x%x/0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_IO_HIGH), snd_gf1_i_read16(gus, SNDRV_GF1_GW_DRAM_IO_LOW));
+ if (!gus->interwave)
+ printk(" -G- GF1 record DMA control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL));
+ printk(" -G- GF1 DRAM IO 16 = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_DRAM_IO16));
+ if (gus->gf1.enh_mode) {
+ printk(" -G- GFA1 memory config = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG));
+ printk(" -G- GFA1 memory control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_MEMORY_CONTROL));
+ printk(" -G- GFA1 FIFO record base = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_FIFO_RECORD_BASE_ADDR));
+ printk(" -G- GFA1 FIFO playback base = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_FIFO_PLAY_BASE_ADDR));
+ printk(" -G- GFA1 interleave control = 0x%x\n", snd_gf1_i_look16(gus, SNDRV_GF1_GW_INTERLEAVE));
+ }
+}
+
+void snd_gf1_print_setup_registers(snd_gus_card_t * gus)
+{
+ printk(" -S- mix control = 0x%x\n", inb(GUSP(gus, MIXCNTRLREG)));
+ printk(" -S- IRQ status = 0x%x\n", inb(GUSP(gus, IRQSTAT)));
+ printk(" -S- timer control = 0x%x\n", inb(GUSP(gus, TIMERCNTRL)));
+ printk(" -S- timer data = 0x%x\n", inb(GUSP(gus, TIMERDATA)));
+ printk(" -S- status read = 0x%x\n", inb(GUSP(gus, REGCNTRLS)));
+ printk(" -S- Sound Blaster control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL));
+ printk(" -S- AdLib timer 1/2 = 0x%x/0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_ADLIB_TIMER_1), snd_gf1_i_look8(gus, SNDRV_GF1_GB_ADLIB_TIMER_2));
+ printk(" -S- reset = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET));
+ if (gus->interwave) {
+ printk(" -S- compatibility = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_COMPATIBILITY));
+ printk(" -S- decode control = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_DECODE_CONTROL));
+ printk(" -S- version number = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER));
+ printk(" -S- MPU-401 emul. control A/B = 0x%x/0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_MPU401_CONTROL_A), snd_gf1_i_look8(gus, SNDRV_GF1_GB_MPU401_CONTROL_B));
+ printk(" -S- emulation IRQ = 0x%x\n", snd_gf1_i_look8(gus, SNDRV_GF1_GB_EMULATION_IRQ));
+ }
+}
+
+void snd_gf1_peek_print_block(snd_gus_card_t * gus, unsigned int addr, int count, int w_16bit)
+{
+ if (!w_16bit) {
+ while (count-- > 0)
+ printk(count > 0 ? "%02x:" : "%02x", snd_gf1_peek(gus, addr++));
+ } else {
+ while (count-- > 0) {
+ printk(count > 0 ? "%04x:" : "%04x", snd_gf1_peek(gus, addr) | (snd_gf1_peek(gus, addr + 1) << 8));
+ addr += 2;
+ }
+ }
+}
+
+#endif
diff --git a/sound/isa/gus/gus_irq.c b/sound/isa/gus/gus_irq.c
new file mode 100644
index 000000000000..1e2a15eb8106
--- /dev/null
+++ b/sound/isa/gus/gus_irq.c
@@ -0,0 +1,142 @@
+/*
+ * Routine for IRQ handling from GF1/InterWave chip
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/info.h>
+#include <sound/gus.h>
+
+#ifdef CONFIG_SND_DEBUG
+#define STAT_ADD(x) ((x)++)
+#else
+#define STAT_ADD(x) while (0) { ; }
+#endif
+
+irqreturn_t snd_gus_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ snd_gus_card_t * gus = dev_id;
+ unsigned char status;
+ int loop = 100;
+ int handled = 0;
+
+__again:
+ status = inb(gus->gf1.reg_irqstat);
+ if (status == 0)
+ return IRQ_RETVAL(handled);
+ handled = 1;
+ // snd_printk("IRQ: status = 0x%x\n", status);
+ if (status & 0x02) {
+ STAT_ADD(gus->gf1.interrupt_stat_midi_in);
+ gus->gf1.interrupt_handler_midi_in(gus);
+ }
+ if (status & 0x01) {
+ STAT_ADD(gus->gf1.interrupt_stat_midi_out);
+ gus->gf1.interrupt_handler_midi_out(gus);
+ }
+ if (status & (0x20 | 0x40)) {
+ unsigned int already, _current_;
+ unsigned char voice_status, voice;
+ snd_gus_voice_t *pvoice;
+
+ already = 0;
+ while (((voice_status = snd_gf1_i_read8(gus, SNDRV_GF1_GB_VOICES_IRQ)) & 0xc0) != 0xc0) {
+ voice = voice_status & 0x1f;
+ _current_ = 1 << voice;
+ if (already & _current_)
+ continue; /* multi request */
+ already |= _current_; /* mark request */
+#if 0
+ printk("voice = %i, voice_status = 0x%x, voice_verify = %i\n", voice, voice_status, inb(GUSP(gus, GF1PAGE)));
+#endif
+ pvoice = &gus->gf1.voices[voice];
+ if (pvoice->use) {
+ if (!(voice_status & 0x80)) { /* voice position IRQ */
+ STAT_ADD(pvoice->interrupt_stat_wave);
+ pvoice->handler_wave(gus, pvoice);
+ }
+ if (!(voice_status & 0x40)) { /* volume ramp IRQ */
+ STAT_ADD(pvoice->interrupt_stat_volume);
+ pvoice->handler_volume(gus, pvoice);
+ }
+ } else {
+ STAT_ADD(gus->gf1.interrupt_stat_voice_lost);
+ snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL);
+ snd_gf1_i_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
+ }
+ }
+ }
+ if (status & 0x04) {
+ STAT_ADD(gus->gf1.interrupt_stat_timer1);
+ gus->gf1.interrupt_handler_timer1(gus);
+ }
+ if (status & 0x08) {
+ STAT_ADD(gus->gf1.interrupt_stat_timer2);
+ gus->gf1.interrupt_handler_timer2(gus);
+ }
+ if (status & 0x80) {
+ if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_DRAM_DMA_CONTROL) & 0x40) {
+ STAT_ADD(gus->gf1.interrupt_stat_dma_write);
+ gus->gf1.interrupt_handler_dma_write(gus);
+ }
+ if (snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL) & 0x40) {
+ STAT_ADD(gus->gf1.interrupt_stat_dma_read);
+ gus->gf1.interrupt_handler_dma_read(gus);
+ }
+ }
+ if (--loop > 0)
+ goto __again;
+ return IRQ_NONE;
+}
+
+#ifdef CONFIG_SND_DEBUG
+static void snd_gus_irq_info_read(snd_info_entry_t *entry,
+ snd_info_buffer_t * buffer)
+{
+ snd_gus_card_t *gus;
+ snd_gus_voice_t *pvoice;
+ int idx;
+
+ gus = entry->private_data;
+ snd_iprintf(buffer, "midi out = %u\n", gus->gf1.interrupt_stat_midi_out);
+ snd_iprintf(buffer, "midi in = %u\n", gus->gf1.interrupt_stat_midi_in);
+ snd_iprintf(buffer, "timer1 = %u\n", gus->gf1.interrupt_stat_timer1);
+ snd_iprintf(buffer, "timer2 = %u\n", gus->gf1.interrupt_stat_timer2);
+ snd_iprintf(buffer, "dma write = %u\n", gus->gf1.interrupt_stat_dma_write);
+ snd_iprintf(buffer, "dma read = %u\n", gus->gf1.interrupt_stat_dma_read);
+ snd_iprintf(buffer, "voice lost = %u\n", gus->gf1.interrupt_stat_voice_lost);
+ for (idx = 0; idx < 32; idx++) {
+ pvoice = &gus->gf1.voices[idx];
+ snd_iprintf(buffer, "voice %i: wave = %u, volume = %u\n",
+ idx,
+ pvoice->interrupt_stat_wave,
+ pvoice->interrupt_stat_volume);
+ }
+}
+
+void snd_gus_irq_profile_init(snd_gus_card_t *gus)
+{
+ snd_info_entry_t *entry;
+
+ if (! snd_card_proc_new(gus->card, "gusirq", &entry))
+ snd_info_set_text_ops(entry, gus, 1024, snd_gus_irq_info_read);
+}
+
+#endif
diff --git a/sound/isa/gus/gus_main.c b/sound/isa/gus/gus_main.c
new file mode 100644
index 000000000000..73f81c14f768
--- /dev/null
+++ b/sound/isa/gus/gus_main.c
@@ -0,0 +1,514 @@
+/*
+ * Routines for Gravis UltraSound soundcards
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/ioport.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+#include <sound/control.h>
+
+#include <asm/dma.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("Routines for Gravis UltraSound soundcards");
+MODULE_LICENSE("GPL");
+
+static int snd_gus_init_dma_irq(snd_gus_card_t * gus, int latches);
+
+int snd_gus_use_inc(snd_gus_card_t * gus)
+{
+ if (!try_module_get(gus->card->module))
+ return 0;
+ return 1;
+}
+
+void snd_gus_use_dec(snd_gus_card_t * gus)
+{
+ module_put(gus->card->module);
+}
+
+static int snd_gus_joystick_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 31;
+ return 0;
+}
+
+static int snd_gus_joystick_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ snd_gus_card_t *gus = snd_kcontrol_chip(kcontrol);
+
+ ucontrol->value.integer.value[0] = gus->joystick_dac & 31;
+ return 0;
+}
+
+static int snd_gus_joystick_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ snd_gus_card_t *gus = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int change;
+ unsigned char nval;
+
+ nval = ucontrol->value.integer.value[0] & 31;
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ change = gus->joystick_dac != nval;
+ gus->joystick_dac = nval;
+ snd_gf1_write8(gus, SNDRV_GF1_GB_JOYSTICK_DAC_LEVEL, gus->joystick_dac);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return change;
+}
+
+static snd_kcontrol_new_t snd_gus_joystick_control = {
+ .iface = SNDRV_CTL_ELEM_IFACE_CARD,
+ .name = "Joystick Speed",
+ .info = snd_gus_joystick_info,
+ .get = snd_gus_joystick_get,
+ .put = snd_gus_joystick_put
+};
+
+static void snd_gus_init_control(snd_gus_card_t *gus)
+{
+ if (!gus->ace_flag)
+ snd_ctl_add(gus->card, snd_ctl_new1(&snd_gus_joystick_control, gus));
+}
+
+/*
+ *
+ */
+
+static int snd_gus_free(snd_gus_card_t *gus)
+{
+ if (gus->gf1.res_port2 == NULL)
+ goto __hw_end;
+#if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
+ if (gus->seq_dev) {
+ snd_device_free(gus->card, gus->seq_dev);
+ gus->seq_dev = NULL;
+ }
+#endif
+ snd_gf1_stop(gus);
+ snd_gus_init_dma_irq(gus, 0);
+ __hw_end:
+ if (gus->gf1.res_port1) {
+ release_resource(gus->gf1.res_port1);
+ kfree_nocheck(gus->gf1.res_port1);
+ }
+ if (gus->gf1.res_port2) {
+ release_resource(gus->gf1.res_port2);
+ kfree_nocheck(gus->gf1.res_port2);
+ }
+ if (gus->gf1.irq >= 0)
+ free_irq(gus->gf1.irq, (void *) gus);
+ if (gus->gf1.dma1 >= 0) {
+ disable_dma(gus->gf1.dma1);
+ free_dma(gus->gf1.dma1);
+ }
+ if (!gus->equal_dma && gus->gf1.dma2 >= 0) {
+ disable_dma(gus->gf1.dma2);
+ free_dma(gus->gf1.dma2);
+ }
+ kfree(gus);
+ return 0;
+}
+
+static int snd_gus_dev_free(snd_device_t *device)
+{
+ snd_gus_card_t *gus = device->device_data;
+ return snd_gus_free(gus);
+}
+
+int snd_gus_create(snd_card_t * card,
+ unsigned long port,
+ int irq, int dma1, int dma2,
+ int timer_dev,
+ int voices,
+ int pcm_channels,
+ int effect,
+ snd_gus_card_t **rgus)
+{
+ snd_gus_card_t *gus;
+ int err;
+ static snd_device_ops_t ops = {
+ .dev_free = snd_gus_dev_free,
+ };
+
+ *rgus = NULL;
+ gus = kcalloc(1, sizeof(*gus), GFP_KERNEL);
+ if (gus == NULL)
+ return -ENOMEM;
+ gus->gf1.irq = -1;
+ gus->gf1.dma1 = -1;
+ gus->gf1.dma2 = -1;
+ gus->card = card;
+ gus->gf1.port = port;
+ /* fill register variables for speedup */
+ gus->gf1.reg_page = GUSP(gus, GF1PAGE);
+ gus->gf1.reg_regsel = GUSP(gus, GF1REGSEL);
+ gus->gf1.reg_data8 = GUSP(gus, GF1DATAHIGH);
+ gus->gf1.reg_data16 = GUSP(gus, GF1DATALOW);
+ gus->gf1.reg_irqstat = GUSP(gus, IRQSTAT);
+ gus->gf1.reg_dram = GUSP(gus, DRAM);
+ gus->gf1.reg_timerctrl = GUSP(gus, TIMERCNTRL);
+ gus->gf1.reg_timerdata = GUSP(gus, TIMERDATA);
+ /* allocate resources */
+ if ((gus->gf1.res_port1 = request_region(port, 16, "GUS GF1 (Adlib/SB)")) == NULL) {
+ snd_printk(KERN_ERR "gus: can't grab SB port 0x%lx\n", port);
+ snd_gus_free(gus);
+ return -EBUSY;
+ }
+ if ((gus->gf1.res_port2 = request_region(port + 0x100, 12, "GUS GF1 (Synth)")) == NULL) {
+ snd_printk(KERN_ERR "gus: can't grab synth port 0x%lx\n", port + 0x100);
+ snd_gus_free(gus);
+ return -EBUSY;
+ }
+ if (irq >= 0 && request_irq(irq, snd_gus_interrupt, SA_INTERRUPT, "GUS GF1", (void *) gus)) {
+ snd_printk(KERN_ERR "gus: can't grab irq %d\n", irq);
+ snd_gus_free(gus);
+ return -EBUSY;
+ }
+ gus->gf1.irq = irq;
+ if (request_dma(dma1, "GUS - 1")) {
+ snd_printk(KERN_ERR "gus: can't grab DMA1 %d\n", dma1);
+ snd_gus_free(gus);
+ return -EBUSY;
+ }
+ gus->gf1.dma1 = dma1;
+ if (dma2 >= 0 && dma1 != dma2) {
+ if (request_dma(dma2, "GUS - 2")) {
+ snd_printk(KERN_ERR "gus: can't grab DMA2 %d\n", dma2);
+ snd_gus_free(gus);
+ return -EBUSY;
+ }
+ gus->gf1.dma2 = dma2;
+ } else {
+ gus->gf1.dma2 = gus->gf1.dma1;
+ gus->equal_dma = 1;
+ }
+ gus->timer_dev = timer_dev;
+ if (voices < 14)
+ voices = 14;
+ if (voices > 32)
+ voices = 32;
+ if (pcm_channels < 0)
+ pcm_channels = 0;
+ if (pcm_channels > 8)
+ pcm_channels = 8;
+ pcm_channels++;
+ pcm_channels &= ~1;
+ gus->gf1.effect = effect ? 1 : 0;
+ gus->gf1.active_voices = voices;
+ gus->gf1.pcm_channels = pcm_channels;
+ gus->gf1.volume_ramp = 25;
+ gus->gf1.smooth_pan = 1;
+ spin_lock_init(&gus->reg_lock);
+ spin_lock_init(&gus->voice_alloc);
+ spin_lock_init(&gus->active_voice_lock);
+ spin_lock_init(&gus->event_lock);
+ spin_lock_init(&gus->dma_lock);
+ spin_lock_init(&gus->pcm_volume_level_lock);
+ spin_lock_init(&gus->uart_cmd_lock);
+ init_MUTEX(&gus->dma_mutex);
+ if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, gus, &ops)) < 0) {
+ snd_gus_free(gus);
+ return err;
+ }
+ *rgus = gus;
+ return 0;
+}
+
+/*
+ * Memory detection routine for plain GF1 soundcards
+ */
+
+static int snd_gus_detect_memory(snd_gus_card_t * gus)
+{
+ int l, idx, local;
+ unsigned char d;
+
+ snd_gf1_poke(gus, 0L, 0xaa);
+ snd_gf1_poke(gus, 1L, 0x55);
+ if (snd_gf1_peek(gus, 0L) != 0xaa || snd_gf1_peek(gus, 1L) != 0x55) {
+ snd_printk("plain GF1 card at 0x%lx without onboard DRAM?\n", gus->gf1.port);
+ return -ENOMEM;
+ }
+ for (idx = 1, d = 0xab; idx < 4; idx++, d++) {
+ local = idx << 18;
+ snd_gf1_poke(gus, local, d);
+ snd_gf1_poke(gus, local + 1, d + 1);
+ if (snd_gf1_peek(gus, local) != d ||
+ snd_gf1_peek(gus, local + 1) != d + 1 ||
+ snd_gf1_peek(gus, 0L) != 0xaa)
+ break;
+ }
+#if 1
+ gus->gf1.memory = idx << 18;
+#else
+ gus->gf1.memory = 256 * 1024;
+#endif
+ for (l = 0, local = gus->gf1.memory; l < 4; l++, local -= 256 * 1024) {
+ gus->gf1.mem_alloc.banks_8[l].address =
+ gus->gf1.mem_alloc.banks_8[l].size = 0;
+ gus->gf1.mem_alloc.banks_16[l].address = l << 18;
+ gus->gf1.mem_alloc.banks_16[l].size = local > 0 ? 256 * 1024 : 0;
+ }
+ gus->gf1.mem_alloc.banks_8[0].size = gus->gf1.memory;
+ return 0; /* some memory were detected */
+}
+
+static int snd_gus_init_dma_irq(snd_gus_card_t * gus, int latches)
+{
+ snd_card_t *card;
+ unsigned long flags;
+ int irq, dma1, dma2;
+ static unsigned char irqs[16] =
+ {0, 0, 1, 3, 0, 2, 0, 4, 0, 1, 0, 5, 6, 0, 0, 7};
+ static unsigned char dmas[8] =
+ {6, 1, 0, 2, 0, 3, 4, 5};
+
+ snd_assert(gus != NULL, return -EINVAL);
+ card = gus->card;
+ snd_assert(card != NULL, return -EINVAL);
+
+ gus->mix_cntrl_reg &= 0xf8;
+ gus->mix_cntrl_reg |= 0x01; /* disable MIC, LINE IN, enable LINE OUT */
+ if (gus->codec_flag || gus->ess_flag) {
+ gus->mix_cntrl_reg &= ~1; /* enable LINE IN */
+ gus->mix_cntrl_reg |= 4; /* enable MIC */
+ }
+ dma1 = gus->gf1.dma1;
+ dma1 = dma1 < 0 ? -dma1 : dma1;
+ dma1 = dmas[dma1 & 7];
+ dma2 = gus->gf1.dma2;
+ dma2 = dma2 < 0 ? -dma2 : dma2;
+ dma2 = dmas[dma2 & 7];
+#if 0
+ printk("dma1 = %i, dma2 = %i\n", gus->gf1.dma1, gus->gf1.dma2);
+#endif
+ dma1 |= gus->equal_dma ? 0x40 : (dma2 << 3);
+
+ if ((dma1 & 7) == 0 || (dma2 & 7) == 0) {
+ snd_printk("Error! DMA isn't defined.\n");
+ return -EINVAL;
+ }
+ irq = gus->gf1.irq;
+ irq = irq < 0 ? -irq : irq;
+ irq = irqs[irq & 0x0f];
+ if (irq == 0) {
+ snd_printk("Error! IRQ isn't defined.\n");
+ return -EINVAL;
+ }
+ irq |= 0x40;
+#if 0
+ card->mixer.mix_ctrl_reg |= 0x10;
+#endif
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ outb(5, GUSP(gus, REGCNTRLS));
+ outb(gus->mix_cntrl_reg, GUSP(gus, MIXCNTRLREG));
+ outb(0x00, GUSP(gus, IRQDMACNTRLREG));
+ outb(0, GUSP(gus, REGCNTRLS));
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+
+ udelay(100);
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ outb(0x00 | gus->mix_cntrl_reg, GUSP(gus, MIXCNTRLREG));
+ outb(dma1, GUSP(gus, IRQDMACNTRLREG));
+ if (latches) {
+ outb(0x40 | gus->mix_cntrl_reg, GUSP(gus, MIXCNTRLREG));
+ outb(irq, GUSP(gus, IRQDMACNTRLREG));
+ }
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+
+ udelay(100);
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ outb(0x00 | gus->mix_cntrl_reg, GUSP(gus, MIXCNTRLREG));
+ outb(dma1, GUSP(gus, IRQDMACNTRLREG));
+ if (latches) {
+ outb(0x40 | gus->mix_cntrl_reg, GUSP(gus, MIXCNTRLREG));
+ outb(irq, GUSP(gus, IRQDMACNTRLREG));
+ }
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+
+ snd_gf1_delay(gus);
+
+ if (latches)
+ gus->mix_cntrl_reg |= 0x08; /* enable latches */
+ else
+ gus->mix_cntrl_reg &= ~0x08; /* disable latches */
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ outb(gus->mix_cntrl_reg, GUSP(gus, MIXCNTRLREG));
+ outb(0, GUSP(gus, GF1PAGE));
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+
+ return 0;
+}
+
+static int snd_gus_check_version(snd_gus_card_t * gus)
+{
+ unsigned long flags;
+ unsigned char val, rev;
+ snd_card_t *card;
+
+ card = gus->card;
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ outb(0x20, GUSP(gus, REGCNTRLS));
+ val = inb(GUSP(gus, REGCNTRLS));
+ rev = inb(GUSP(gus, BOARDVERSION));
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ snd_printdd("GF1 [0x%lx] init - val = 0x%x, rev = 0x%x\n", gus->gf1.port, val, rev);
+ strcpy(card->driver, "GUS");
+ strcpy(card->longname, "Gravis UltraSound Classic (2.4)");
+ if ((val != 255 && (val & 0x06)) || (rev >= 5 && rev != 255)) {
+ if (rev >= 5 && rev <= 9) {
+ gus->ics_flag = 1;
+ if (rev == 5)
+ gus->ics_flipped = 1;
+ card->longname[27] = '3';
+ card->longname[29] = rev == 5 ? '5' : '7';
+ }
+ if (rev >= 10 && rev != 255) {
+ if (rev >= 10 && rev <= 11) {
+ strcpy(card->driver, "GUS MAX");
+ strcpy(card->longname, "Gravis UltraSound MAX");
+ gus->max_flag = 1;
+ } else if (rev == 0x30) {
+ strcpy(card->driver, "GUS ACE");
+ strcpy(card->longname, "Gravis UltraSound Ace");
+ gus->ace_flag = 1;
+ } else if (rev == 0x50) {
+ strcpy(card->driver, "GUS Extreme");
+ strcpy(card->longname, "Gravis UltraSound Extreme");
+ gus->ess_flag = 1;
+ } else {
+ snd_printk("unknown GF1 revision number at 0x%lx - 0x%x (0x%x)\n", gus->gf1.port, rev, val);
+ snd_printk(" please - report to <perex@suse.cz>\n");
+ }
+ }
+ }
+ strcpy(card->shortname, card->longname);
+ gus->uart_enable = 1; /* standard GUSes doesn't have midi uart trouble */
+ snd_gus_init_control(gus);
+ return 0;
+}
+
+static void snd_gus_seq_dev_free(snd_seq_device_t *seq_dev)
+{
+ snd_gus_card_t *gus = seq_dev->private_data;
+ gus->seq_dev = NULL;
+}
+
+int snd_gus_initialize(snd_gus_card_t *gus)
+{
+ int err;
+
+ if (!gus->interwave) {
+ if ((err = snd_gus_check_version(gus)) < 0) {
+ snd_printk("version check failed\n");
+ return err;
+ }
+ if ((err = snd_gus_detect_memory(gus)) < 0)
+ return err;
+ }
+ if ((err = snd_gus_init_dma_irq(gus, 1)) < 0)
+ return err;
+#if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
+ if (snd_seq_device_new(gus->card, 1, SNDRV_SEQ_DEV_ID_GUS,
+ sizeof(snd_gus_card_t*), &gus->seq_dev) >= 0) {
+ strcpy(gus->seq_dev->name, "GUS");
+ *(snd_gus_card_t**)SNDRV_SEQ_DEVICE_ARGPTR(gus->seq_dev) = gus;
+ gus->seq_dev->private_data = gus;
+ gus->seq_dev->private_free = snd_gus_seq_dev_free;
+ }
+#endif
+ snd_gf1_start(gus);
+ gus->initialized = 1;
+ return 0;
+}
+
+ /* gus_io.c */
+EXPORT_SYMBOL(snd_gf1_delay);
+EXPORT_SYMBOL(snd_gf1_write8);
+EXPORT_SYMBOL(snd_gf1_look8);
+EXPORT_SYMBOL(snd_gf1_write16);
+EXPORT_SYMBOL(snd_gf1_look16);
+EXPORT_SYMBOL(snd_gf1_i_write8);
+EXPORT_SYMBOL(snd_gf1_i_look8);
+EXPORT_SYMBOL(snd_gf1_i_write16);
+EXPORT_SYMBOL(snd_gf1_i_look16);
+EXPORT_SYMBOL(snd_gf1_dram_addr);
+EXPORT_SYMBOL(snd_gf1_write_addr);
+EXPORT_SYMBOL(snd_gf1_poke);
+EXPORT_SYMBOL(snd_gf1_peek);
+ /* gus_reset.c */
+EXPORT_SYMBOL(snd_gf1_alloc_voice);
+EXPORT_SYMBOL(snd_gf1_free_voice);
+EXPORT_SYMBOL(snd_gf1_ctrl_stop);
+EXPORT_SYMBOL(snd_gf1_stop_voice);
+EXPORT_SYMBOL(snd_gf1_start);
+EXPORT_SYMBOL(snd_gf1_stop);
+ /* gus_mixer.c */
+EXPORT_SYMBOL(snd_gf1_new_mixer);
+ /* gus_pcm.c */
+EXPORT_SYMBOL(snd_gf1_pcm_new);
+ /* gus.c */
+EXPORT_SYMBOL(snd_gus_use_inc);
+EXPORT_SYMBOL(snd_gus_use_dec);
+EXPORT_SYMBOL(snd_gus_create);
+EXPORT_SYMBOL(snd_gus_initialize);
+ /* gus_irq.c */
+EXPORT_SYMBOL(snd_gus_interrupt);
+ /* gus_uart.c */
+EXPORT_SYMBOL(snd_gf1_rawmidi_new);
+ /* gus_dram.c */
+EXPORT_SYMBOL(snd_gus_dram_write);
+EXPORT_SYMBOL(snd_gus_dram_read);
+ /* gus_volume.c */
+EXPORT_SYMBOL(snd_gf1_lvol_to_gvol_raw);
+EXPORT_SYMBOL(snd_gf1_translate_freq);
+ /* gus_mem.c */
+EXPORT_SYMBOL(snd_gf1_mem_alloc);
+EXPORT_SYMBOL(snd_gf1_mem_xfree);
+EXPORT_SYMBOL(snd_gf1_mem_free);
+EXPORT_SYMBOL(snd_gf1_mem_lock);
+
+/*
+ * INIT part
+ */
+
+static int __init alsa_gus_init(void)
+{
+ return 0;
+}
+
+static void __exit alsa_gus_exit(void)
+{
+}
+
+module_init(alsa_gus_init)
+module_exit(alsa_gus_exit)
diff --git a/sound/isa/gus/gus_mem.c b/sound/isa/gus/gus_mem.c
new file mode 100644
index 000000000000..bfc2b91001d5
--- /dev/null
+++ b/sound/isa/gus/gus_mem.c
@@ -0,0 +1,353 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ * GUS's memory allocation routines / bottom layer
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/slab.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+#include <sound/info.h>
+
+#ifdef CONFIG_SND_DEBUG
+static void snd_gf1_mem_info_read(snd_info_entry_t *entry,
+ snd_info_buffer_t * buffer);
+#endif
+
+void snd_gf1_mem_lock(snd_gf1_mem_t * alloc, int xup)
+{
+ if (!xup) {
+ down(&alloc->memory_mutex);
+ } else {
+ up(&alloc->memory_mutex);
+ }
+}
+
+snd_gf1_mem_block_t *snd_gf1_mem_xalloc(snd_gf1_mem_t * alloc,
+ snd_gf1_mem_block_t * block)
+{
+ snd_gf1_mem_block_t *pblock, *nblock;
+
+ nblock = (snd_gf1_mem_block_t *) kmalloc(sizeof(snd_gf1_mem_block_t), GFP_KERNEL);
+ if (nblock == NULL)
+ return NULL;
+ *nblock = *block;
+ pblock = alloc->first;
+ while (pblock) {
+ if (pblock->ptr > nblock->ptr) {
+ nblock->prev = pblock->prev;
+ nblock->next = pblock;
+ pblock->prev = nblock;
+ if (pblock == alloc->first)
+ alloc->first = nblock;
+ else
+ nblock->prev->next = nblock;
+ up(&alloc->memory_mutex);
+ return NULL;
+ }
+ pblock = pblock->next;
+ }
+ nblock->next = NULL;
+ if (alloc->last == NULL) {
+ nblock->prev = NULL;
+ alloc->first = alloc->last = nblock;
+ } else {
+ nblock->prev = alloc->last;
+ alloc->last->next = nblock;
+ alloc->last = nblock;
+ }
+ return nblock;
+}
+
+int snd_gf1_mem_xfree(snd_gf1_mem_t * alloc, snd_gf1_mem_block_t * block)
+{
+ if (block->share) { /* ok.. shared block */
+ block->share--;
+ up(&alloc->memory_mutex);
+ return 0;
+ }
+ if (alloc->first == block) {
+ alloc->first = block->next;
+ if (block->next)
+ block->next->prev = NULL;
+ } else {
+ block->prev->next = block->next;
+ if (block->next)
+ block->next->prev = block->prev;
+ }
+ if (alloc->last == block) {
+ alloc->last = block->prev;
+ if (block->prev)
+ block->prev->next = NULL;
+ } else {
+ block->next->prev = block->prev;
+ if (block->prev)
+ block->prev->next = block->next;
+ }
+ kfree(block->name);
+ kfree(block);
+ return 0;
+}
+
+snd_gf1_mem_block_t *snd_gf1_mem_look(snd_gf1_mem_t * alloc,
+ unsigned int address)
+{
+ snd_gf1_mem_block_t *block;
+
+ for (block = alloc->first; block; block = block->next) {
+ if (block->ptr == address) {
+ return block;
+ }
+ }
+ return NULL;
+}
+
+snd_gf1_mem_block_t *snd_gf1_mem_share(snd_gf1_mem_t * alloc,
+ unsigned int *share_id)
+{
+ snd_gf1_mem_block_t *block;
+
+ if (!share_id[0] && !share_id[1] &&
+ !share_id[2] && !share_id[3])
+ return NULL;
+ for (block = alloc->first; block; block = block->next)
+ if (!memcmp(share_id, block->share_id, sizeof(share_id)))
+ return block;
+ return NULL;
+}
+
+static int snd_gf1_mem_find(snd_gf1_mem_t * alloc,
+ snd_gf1_mem_block_t * block,
+ unsigned int size, int w_16, int align)
+{
+ snd_gf1_bank_info_t *info = w_16 ? alloc->banks_16 : alloc->banks_8;
+ unsigned int idx, boundary;
+ int size1;
+ snd_gf1_mem_block_t *pblock;
+ unsigned int ptr1, ptr2;
+
+ align--;
+ if (w_16 && align < 1)
+ align = 1;
+ block->flags = w_16 ? SNDRV_GF1_MEM_BLOCK_16BIT : 0;
+ block->owner = SNDRV_GF1_MEM_OWNER_DRIVER;
+ block->share = 0;
+ block->share_id[0] = block->share_id[1] =
+ block->share_id[2] = block->share_id[3] = 0;
+ block->name = NULL;
+ block->prev = block->next = NULL;
+ for (pblock = alloc->first, idx = 0; pblock; pblock = pblock->next) {
+ while (pblock->ptr >= (boundary = info[idx].address + info[idx].size))
+ idx++;
+ while (pblock->ptr + pblock->size >= (boundary = info[idx].address + info[idx].size))
+ idx++;
+ ptr2 = boundary;
+ if (pblock->next) {
+ if (pblock->ptr + pblock->size == pblock->next->ptr)
+ continue;
+ if (pblock->next->ptr < boundary)
+ ptr2 = pblock->next->ptr;
+ }
+ ptr1 = (pblock->ptr + pblock->size + align) & ~align;
+ if (ptr1 >= ptr2)
+ continue;
+ size1 = ptr2 - ptr1;
+ if ((int)size <= size1) {
+ block->ptr = ptr1;
+ block->size = size;
+ return 0;
+ }
+ }
+ while (++idx < 4) {
+ if (size <= info[idx].size) {
+ /* I assume that bank address is already aligned.. */
+ block->ptr = info[idx].address;
+ block->size = size;
+ return 0;
+ }
+ }
+ return -ENOMEM;
+}
+
+snd_gf1_mem_block_t *snd_gf1_mem_alloc(snd_gf1_mem_t * alloc, int owner,
+ char *name, int size, int w_16, int align,
+ unsigned int *share_id)
+{
+ snd_gf1_mem_block_t block, *nblock;
+
+ snd_gf1_mem_lock(alloc, 0);
+ if (share_id != NULL) {
+ nblock = snd_gf1_mem_share(alloc, share_id);
+ if (nblock != NULL) {
+ if (size != (int)nblock->size) {
+ /* TODO: remove in the future */
+ snd_printk("snd_gf1_mem_alloc - share: sizes differ\n");
+ goto __std;
+ }
+ nblock->share++;
+ snd_gf1_mem_lock(alloc, 1);
+ return NULL;
+ }
+ }
+ __std:
+ if (snd_gf1_mem_find(alloc, &block, size, w_16, align) < 0) {
+ snd_gf1_mem_lock(alloc, 1);
+ return NULL;
+ }
+ if (share_id != NULL)
+ memcpy(&block.share_id, share_id, sizeof(block.share_id));
+ block.owner = owner;
+ block.name = snd_kmalloc_strdup(name, GFP_KERNEL);
+ nblock = snd_gf1_mem_xalloc(alloc, &block);
+ snd_gf1_mem_lock(alloc, 1);
+ return nblock;
+}
+
+int snd_gf1_mem_free(snd_gf1_mem_t * alloc, unsigned int address)
+{
+ int result;
+ snd_gf1_mem_block_t *block;
+
+ snd_gf1_mem_lock(alloc, 0);
+ if ((block = snd_gf1_mem_look(alloc, address)) != NULL) {
+ result = snd_gf1_mem_xfree(alloc, block);
+ snd_gf1_mem_lock(alloc, 1);
+ return result;
+ }
+ snd_gf1_mem_lock(alloc, 1);
+ return -EINVAL;
+}
+
+int snd_gf1_mem_init(snd_gus_card_t * gus)
+{
+ snd_gf1_mem_t *alloc;
+ snd_gf1_mem_block_t block;
+#ifdef CONFIG_SND_DEBUG
+ snd_info_entry_t *entry;
+#endif
+
+ alloc = &gus->gf1.mem_alloc;
+ init_MUTEX(&alloc->memory_mutex);
+ alloc->first = alloc->last = NULL;
+ if (!gus->gf1.memory)
+ return 0;
+
+ memset(&block, 0, sizeof(block));
+ block.owner = SNDRV_GF1_MEM_OWNER_DRIVER;
+ if (gus->gf1.enh_mode) {
+ block.ptr = 0;
+ block.size = 1024;
+ block.name = snd_kmalloc_strdup("InterWave LFOs", GFP_KERNEL);
+ if (snd_gf1_mem_xalloc(alloc, &block) == NULL)
+ return -ENOMEM;
+ }
+ block.ptr = gus->gf1.default_voice_address;
+ block.size = 4;
+ block.name = snd_kmalloc_strdup("Voice default (NULL's)", GFP_KERNEL);
+ if (snd_gf1_mem_xalloc(alloc, &block) == NULL)
+ return -ENOMEM;
+#ifdef CONFIG_SND_DEBUG
+ if (! snd_card_proc_new(gus->card, "gusmem", &entry)) {
+ snd_info_set_text_ops(entry, gus, 1024, snd_gf1_mem_info_read);
+ entry->c.text.read_size = 256 * 1024;
+ }
+#endif
+ return 0;
+}
+
+int snd_gf1_mem_done(snd_gus_card_t * gus)
+{
+ snd_gf1_mem_t *alloc;
+ snd_gf1_mem_block_t *block, *nblock;
+
+ alloc = &gus->gf1.mem_alloc;
+ block = alloc->first;
+ while (block) {
+ nblock = block->next;
+ snd_gf1_mem_xfree(alloc, block);
+ block = nblock;
+ }
+ return 0;
+}
+
+#ifdef CONFIG_SND_DEBUG
+static void snd_gf1_mem_info_read(snd_info_entry_t *entry,
+ snd_info_buffer_t * buffer)
+{
+ snd_gus_card_t *gus;
+ snd_gf1_mem_t *alloc;
+ snd_gf1_mem_block_t *block;
+ unsigned int total, used;
+ int i;
+
+ gus = entry->private_data;
+ alloc = &gus->gf1.mem_alloc;
+ down(&alloc->memory_mutex);
+ snd_iprintf(buffer, "8-bit banks : \n ");
+ for (i = 0; i < 4; i++)
+ snd_iprintf(buffer, "0x%06x (%04ik)%s", alloc->banks_8[i].address, alloc->banks_8[i].size >> 10, i + 1 < 4 ? "," : "");
+ snd_iprintf(buffer, "\n"
+ "16-bit banks : \n ");
+ for (i = total = 0; i < 4; i++) {
+ snd_iprintf(buffer, "0x%06x (%04ik)%s", alloc->banks_16[i].address, alloc->banks_16[i].size >> 10, i + 1 < 4 ? "," : "");
+ total += alloc->banks_16[i].size;
+ }
+ snd_iprintf(buffer, "\n");
+ used = 0;
+ for (block = alloc->first, i = 0; block; block = block->next, i++) {
+ used += block->size;
+ snd_iprintf(buffer, "Block %i at 0x%lx onboard 0x%x size %i (0x%x):\n", i, (long) block, block->ptr, block->size, block->size);
+ if (block->share ||
+ block->share_id[0] || block->share_id[1] ||
+ block->share_id[2] || block->share_id[3])
+ snd_iprintf(buffer, " Share : %i [id0 0x%x] [id1 0x%x] [id2 0x%x] [id3 0x%x]\n",
+ block->share,
+ block->share_id[0], block->share_id[1],
+ block->share_id[2], block->share_id[3]);
+ snd_iprintf(buffer, " Flags :%s\n",
+ block->flags & SNDRV_GF1_MEM_BLOCK_16BIT ? " 16-bit" : "");
+ snd_iprintf(buffer, " Owner : ");
+ switch (block->owner) {
+ case SNDRV_GF1_MEM_OWNER_DRIVER:
+ snd_iprintf(buffer, "driver - %s\n", block->name);
+ break;
+ case SNDRV_GF1_MEM_OWNER_WAVE_SIMPLE:
+ snd_iprintf(buffer, "SIMPLE wave\n");
+ break;
+ case SNDRV_GF1_MEM_OWNER_WAVE_GF1:
+ snd_iprintf(buffer, "GF1 wave\n");
+ break;
+ case SNDRV_GF1_MEM_OWNER_WAVE_IWFFFF:
+ snd_iprintf(buffer, "IWFFFF wave\n");
+ break;
+ default:
+ snd_iprintf(buffer, "unknown\n");
+ }
+ }
+ snd_iprintf(buffer, " Total: memory = %i, used = %i, free = %i\n",
+ total, used, total - used);
+ up(&alloc->memory_mutex);
+#if 0
+ ultra_iprintf(buffer, " Verify: free = %i, max 8-bit block = %i, max 16-bit block = %i\n",
+ ultra_memory_free_size(card, &card->gf1.mem_alloc),
+ ultra_memory_free_block(card, &card->gf1.mem_alloc, 0),
+ ultra_memory_free_block(card, &card->gf1.mem_alloc, 1));
+#endif
+}
+#endif
diff --git a/sound/isa/gus/gus_mem_proc.c b/sound/isa/gus/gus_mem_proc.c
new file mode 100644
index 000000000000..886763f12132
--- /dev/null
+++ b/sound/isa/gus/gus_mem_proc.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ * GUS's memory access via proc filesystem
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/slab.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+#include <sound/info.h>
+
+typedef struct gus_proc_private {
+ int rom; /* data are in ROM */
+ unsigned int address;
+ unsigned int size;
+ snd_gus_card_t * gus;
+} gus_proc_private_t;
+
+static long snd_gf1_mem_proc_dump(snd_info_entry_t *entry, void *file_private_data,
+ struct file *file, char __user *buf,
+ unsigned long count, unsigned long pos)
+{
+ long size;
+ gus_proc_private_t *priv = entry->private_data;
+ snd_gus_card_t *gus = priv->gus;
+ int err;
+
+ size = count;
+ if (pos + size > priv->size)
+ size = (long)priv->size - pos;
+ if (size > 0) {
+ if ((err = snd_gus_dram_read(gus, buf, pos, size, priv->rom)) < 0)
+ return err;
+ return size;
+ }
+ return 0;
+}
+
+static long long snd_gf1_mem_proc_llseek(snd_info_entry_t *entry,
+ void *private_file_data,
+ struct file *file,
+ long long offset,
+ int orig)
+{
+ gus_proc_private_t *priv = entry->private_data;
+
+ switch (orig) {
+ case 0: /* SEEK_SET */
+ file->f_pos = offset;
+ break;
+ case 1: /* SEEK_CUR */
+ file->f_pos += offset;
+ break;
+ case 2: /* SEEK_END, offset is negative */
+ file->f_pos = priv->size + offset;
+ break;
+ default:
+ return -EINVAL;
+ }
+ if (file->f_pos > priv->size)
+ file->f_pos = priv->size;
+ return file->f_pos;
+}
+
+static void snd_gf1_mem_proc_free(snd_info_entry_t *entry)
+{
+ gus_proc_private_t *priv = entry->private_data;
+ kfree(priv);
+}
+
+static struct snd_info_entry_ops snd_gf1_mem_proc_ops = {
+ .read = snd_gf1_mem_proc_dump,
+ .llseek = snd_gf1_mem_proc_llseek,
+};
+
+int snd_gf1_mem_proc_init(snd_gus_card_t * gus)
+{
+ int idx;
+ char name[16];
+ gus_proc_private_t *priv;
+ snd_info_entry_t *entry;
+
+ for (idx = 0; idx < 4; idx++) {
+ if (gus->gf1.mem_alloc.banks_8[idx].size > 0) {
+ priv = kcalloc(1, sizeof(*priv), GFP_KERNEL);
+ if (priv == NULL)
+ return -ENOMEM;
+ priv->gus = gus;
+ sprintf(name, "gus-ram-%i", idx);
+ if (! snd_card_proc_new(gus->card, name, &entry)) {
+ entry->content = SNDRV_INFO_CONTENT_DATA;
+ entry->private_data = priv;
+ entry->private_free = snd_gf1_mem_proc_free;
+ entry->c.ops = &snd_gf1_mem_proc_ops;
+ priv->address = gus->gf1.mem_alloc.banks_8[idx].address;
+ priv->size = entry->size = gus->gf1.mem_alloc.banks_8[idx].size;
+ }
+ }
+ }
+ for (idx = 0; idx < 4; idx++) {
+ if (gus->gf1.rom_present & (1 << idx)) {
+ priv = kcalloc(1, sizeof(*priv), GFP_KERNEL);
+ if (priv == NULL)
+ return -ENOMEM;
+ priv->rom = 1;
+ priv->gus = gus;
+ sprintf(name, "gus-rom-%i", idx);
+ if (! snd_card_proc_new(gus->card, name, &entry)) {
+ entry->content = SNDRV_INFO_CONTENT_DATA;
+ entry->private_data = priv;
+ entry->private_free = snd_gf1_mem_proc_free;
+ entry->c.ops = &snd_gf1_mem_proc_ops;
+ priv->address = idx * 4096 * 1024;
+ priv->size = entry->size = gus->gf1.rom_memory;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/sound/isa/gus/gus_mixer.c b/sound/isa/gus/gus_mixer.c
new file mode 100644
index 000000000000..a051094d510e
--- /dev/null
+++ b/sound/isa/gus/gus_mixer.c
@@ -0,0 +1,199 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ * Routines for control of ICS 2101 chip and "mixer" in GF1 chip
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/time.h>
+#include <linux/wait.h>
+#include <sound/core.h>
+#include <sound/control.h>
+#include <sound/gus.h>
+
+/*
+ *
+ */
+
+#define GF1_SINGLE(xname, xindex, shift, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+ .info = snd_gf1_info_single, \
+ .get = snd_gf1_get_single, .put = snd_gf1_put_single, \
+ .private_value = shift | (invert << 8) }
+
+static int snd_gf1_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 1;
+ return 0;
+}
+
+static int snd_gf1_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ snd_gus_card_t *gus = snd_kcontrol_chip(kcontrol);
+ int shift = kcontrol->private_value & 0xff;
+ int invert = (kcontrol->private_value >> 8) & 1;
+
+ ucontrol->value.integer.value[0] = (gus->mix_cntrl_reg >> shift) & 1;
+ if (invert)
+ ucontrol->value.integer.value[0] ^= 1;
+ return 0;
+}
+
+static int snd_gf1_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ snd_gus_card_t *gus = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int shift = kcontrol->private_value & 0xff;
+ int invert = (kcontrol->private_value >> 8) & 1;
+ int change;
+ unsigned char oval, nval;
+
+ nval = ucontrol->value.integer.value[0] & 1;
+ if (invert)
+ nval ^= 1;
+ nval <<= shift;
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ oval = gus->mix_cntrl_reg;
+ nval = (oval & ~(1 << shift)) | nval;
+ change = nval != oval;
+ outb(gus->mix_cntrl_reg = nval, GUSP(gus, MIXCNTRLREG));
+ outb(gus->gf1.active_voice = 0, GUSP(gus, GF1PAGE));
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return change;
+}
+
+#define ICS_DOUBLE(xname, xindex, addr) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+ .info = snd_ics_info_double, \
+ .get = snd_ics_get_double, .put = snd_ics_put_double, \
+ .private_value = addr }
+
+static int snd_ics_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 2;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 127;
+ return 0;
+}
+
+static int snd_ics_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ snd_gus_card_t *gus = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int addr = kcontrol->private_value & 0xff;
+ unsigned char left, right;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ left = gus->gf1.ics_regs[addr][0];
+ right = gus->gf1.ics_regs[addr][1];
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ ucontrol->value.integer.value[0] = left & 127;
+ ucontrol->value.integer.value[1] = right & 127;
+ return 0;
+}
+
+static int snd_ics_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ snd_gus_card_t *gus = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int addr = kcontrol->private_value & 0xff;
+ int change;
+ unsigned char val1, val2, oval1, oval2, tmp;
+
+ val1 = ucontrol->value.integer.value[0] & 127;
+ val2 = ucontrol->value.integer.value[1] & 127;
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ oval1 = gus->gf1.ics_regs[addr][0];
+ oval2 = gus->gf1.ics_regs[addr][1];
+ change = val1 != oval1 || val2 != oval2;
+ gus->gf1.ics_regs[addr][0] = val1;
+ gus->gf1.ics_regs[addr][1] = val2;
+ if (gus->ics_flag && gus->ics_flipped &&
+ (addr == SNDRV_ICS_GF1_DEV || addr == SNDRV_ICS_MASTER_DEV)) {
+ tmp = val1;
+ val1 = val2;
+ val2 = tmp;
+ }
+ addr <<= 3;
+ outb(addr | 0, GUSP(gus, MIXCNTRLPORT));
+ outb(1, GUSP(gus, MIXDATAPORT));
+ outb(addr | 2, GUSP(gus, MIXCNTRLPORT));
+ outb((unsigned char) val1, GUSP(gus, MIXDATAPORT));
+ outb(addr | 1, GUSP(gus, MIXCNTRLPORT));
+ outb(2, GUSP(gus, MIXDATAPORT));
+ outb(addr | 3, GUSP(gus, MIXCNTRLPORT));
+ outb((unsigned char) val2, GUSP(gus, MIXDATAPORT));
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return change;
+}
+
+static snd_kcontrol_new_t snd_gf1_controls[] = {
+GF1_SINGLE("Master Playback Switch", 0, 1, 1),
+GF1_SINGLE("Line Switch", 0, 0, 1),
+GF1_SINGLE("Mic Switch", 0, 2, 0)
+};
+
+static snd_kcontrol_new_t snd_ics_controls[] = {
+GF1_SINGLE("Master Playback Switch", 0, 1, 1),
+ICS_DOUBLE("Master Playback Volume", 0, SNDRV_ICS_MASTER_DEV),
+ICS_DOUBLE("Synth Playback Volume", 0, SNDRV_ICS_GF1_DEV),
+GF1_SINGLE("Line Switch", 0, 0, 1),
+ICS_DOUBLE("Line Playback Volume", 0, SNDRV_ICS_LINE_DEV),
+GF1_SINGLE("Mic Switch", 0, 2, 0),
+ICS_DOUBLE("Mic Playback Volume", 0, SNDRV_ICS_MIC_DEV),
+ICS_DOUBLE("CD Playback Volume", 0, SNDRV_ICS_CD_DEV)
+};
+
+int snd_gf1_new_mixer(snd_gus_card_t * gus)
+{
+ snd_card_t *card;
+ unsigned int idx, max;
+ int err;
+
+ snd_assert(gus != NULL, return -EINVAL);
+ card = gus->card;
+ snd_assert(card != NULL, return -EINVAL);
+
+ if (gus->ics_flag)
+ snd_component_add(card, "ICS2101");
+ if (card->mixername[0] == '\0') {
+ strcpy(card->mixername, gus->ics_flag ? "GF1,ICS2101" : "GF1");
+ } else {
+ if (gus->ics_flag)
+ strcat(card->mixername, ",ICS2101");
+ strcat(card->mixername, ",GF1");
+ }
+
+ if (!gus->ics_flag) {
+ max = gus->ess_flag ? 1 : ARRAY_SIZE(snd_gf1_controls);
+ for (idx = 0; idx < max; idx++) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_gf1_controls[idx], gus))) < 0)
+ return err;
+ }
+ } else {
+ for (idx = 0; idx < ARRAY_SIZE(snd_ics_controls); idx++) {
+ if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ics_controls[idx], gus))) < 0)
+ return err;
+ }
+ }
+ return 0;
+}
diff --git a/sound/isa/gus/gus_pcm.c b/sound/isa/gus/gus_pcm.c
new file mode 100644
index 000000000000..8995ad9c516d
--- /dev/null
+++ b/sound/isa/gus/gus_pcm.c
@@ -0,0 +1,903 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ * Routines for control of GF1 chip (PCM things)
+ *
+ * InterWave chips supports interleaved DMA, but this feature isn't used in
+ * this code.
+ *
+ * This code emulates autoinit DMA transfer for playback, recording by GF1
+ * chip doesn't support autoinit DMA.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <asm/dma.h>
+#include <linux/slab.h>
+#include <sound/core.h>
+#include <sound/control.h>
+#include <sound/gus.h>
+#include <sound/pcm_params.h>
+#include "gus_tables.h"
+
+/* maximum rate */
+
+#define SNDRV_GF1_PCM_RATE 48000
+
+#define SNDRV_GF1_PCM_PFLG_NONE 0
+#define SNDRV_GF1_PCM_PFLG_ACTIVE (1<<0)
+#define SNDRV_GF1_PCM_PFLG_NEUTRAL (2<<0)
+
+typedef struct {
+ snd_gus_card_t * gus;
+ snd_pcm_substream_t * substream;
+ spinlock_t lock;
+ unsigned int voices;
+ snd_gus_voice_t *pvoices[2];
+ unsigned int memory;
+ unsigned short flags;
+ unsigned char voice_ctrl, ramp_ctrl;
+ unsigned int bpos;
+ unsigned int blocks;
+ unsigned int block_size;
+ unsigned int dma_size;
+ wait_queue_head_t sleep;
+ atomic_t dma_count;
+ int final_volume;
+} gus_pcm_private_t;
+
+static int snd_gf1_pcm_use_dma = 1;
+
+static void snd_gf1_pcm_block_change_ack(snd_gus_card_t * gus, void *private_data)
+{
+ gus_pcm_private_t *pcmp = private_data;
+
+ if (pcmp) {
+ atomic_dec(&pcmp->dma_count);
+ wake_up(&pcmp->sleep);
+ }
+}
+
+static int snd_gf1_pcm_block_change(snd_pcm_substream_t * substream,
+ unsigned int offset,
+ unsigned int addr,
+ unsigned int count)
+{
+ snd_gf1_dma_block_t block;
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ gus_pcm_private_t *pcmp = runtime->private_data;
+
+ count += offset & 31;
+ offset &= ~31;
+ // snd_printk("block change - offset = 0x%x, count = 0x%x\n", offset, count);
+ memset(&block, 0, sizeof(block));
+ block.cmd = SNDRV_GF1_DMA_IRQ;
+ if (snd_pcm_format_unsigned(runtime->format))
+ block.cmd |= SNDRV_GF1_DMA_UNSIGNED;
+ if (snd_pcm_format_width(runtime->format) == 16)
+ block.cmd |= SNDRV_GF1_DMA_16BIT;
+ block.addr = addr & ~31;
+ block.buffer = runtime->dma_area + offset;
+ block.buf_addr = runtime->dma_addr + offset;
+ block.count = count;
+ block.private_data = pcmp;
+ block.ack = snd_gf1_pcm_block_change_ack;
+ if (!snd_gf1_dma_transfer_block(pcmp->gus, &block, 0, 0))
+ atomic_inc(&pcmp->dma_count);
+ return 0;
+}
+
+static void snd_gf1_pcm_trigger_up(snd_pcm_substream_t * substream)
+{
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ gus_pcm_private_t *pcmp = runtime->private_data;
+ snd_gus_card_t * gus = pcmp->gus;
+ unsigned long flags;
+ unsigned char voice_ctrl, ramp_ctrl;
+ unsigned short rate;
+ unsigned int curr, begin, end;
+ unsigned short vol;
+ unsigned char pan;
+ unsigned int voice;
+
+ if (substream == NULL)
+ return;
+ spin_lock_irqsave(&pcmp->lock, flags);
+ if (pcmp->flags & SNDRV_GF1_PCM_PFLG_ACTIVE) {
+ spin_unlock_irqrestore(&pcmp->lock, flags);
+ return;
+ }
+ pcmp->flags |= SNDRV_GF1_PCM_PFLG_ACTIVE;
+ pcmp->final_volume = 0;
+ spin_unlock_irqrestore(&pcmp->lock, flags);
+ rate = snd_gf1_translate_freq(gus, runtime->rate << 4);
+ /* enable WAVE IRQ */
+ voice_ctrl = snd_pcm_format_width(runtime->format) == 16 ? 0x24 : 0x20;
+ /* enable RAMP IRQ + rollover */
+ ramp_ctrl = 0x24;
+ if (pcmp->blocks == 1) {
+ voice_ctrl |= 0x08; /* loop enable */
+ ramp_ctrl &= ~0x04; /* disable rollover */
+ }
+ for (voice = 0; voice < pcmp->voices; voice++) {
+ begin = pcmp->memory + voice * (pcmp->dma_size / runtime->channels);
+ curr = begin + (pcmp->bpos * pcmp->block_size) / runtime->channels;
+ end = curr + (pcmp->block_size / runtime->channels);
+ end -= snd_pcm_format_width(runtime->format) == 16 ? 2 : 1;
+ // snd_printk("init: curr=0x%x, begin=0x%x, end=0x%x, ctrl=0x%x, ramp=0x%x, rate=0x%x\n", curr, begin, end, voice_ctrl, ramp_ctrl, rate);
+ pan = runtime->channels == 2 ? (!voice ? 1 : 14) : 8;
+ vol = !voice ? gus->gf1.pcm_volume_level_left : gus->gf1.pcm_volume_level_right;
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, pcmp->pvoices[voice]->number);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_PAN, pan);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_FREQUENCY, rate);
+ snd_gf1_write_addr(gus, SNDRV_GF1_VA_START, begin << 4, voice_ctrl & 4);
+ snd_gf1_write_addr(gus, SNDRV_GF1_VA_END, end << 4, voice_ctrl & 4);
+ snd_gf1_write_addr(gus, SNDRV_GF1_VA_CURRENT, curr << 4, voice_ctrl & 4);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, SNDRV_GF1_MIN_VOLUME << 4);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_RATE, 0x2f);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_START, SNDRV_GF1_MIN_OFFSET);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_END, vol >> 8);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, ramp_ctrl);
+ if (!gus->gf1.enh_mode) {
+ snd_gf1_delay(gus);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, ramp_ctrl);
+ }
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ }
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ for (voice = 0; voice < pcmp->voices; voice++) {
+ snd_gf1_select_voice(gus, pcmp->pvoices[voice]->number);
+ if (gus->gf1.enh_mode)
+ snd_gf1_write8(gus, SNDRV_GF1_VB_MODE, 0x00); /* deactivate voice */
+ snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice_ctrl);
+ voice_ctrl &= ~0x20;
+ }
+ voice_ctrl |= 0x20;
+ if (!gus->gf1.enh_mode) {
+ snd_gf1_delay(gus);
+ for (voice = 0; voice < pcmp->voices; voice++) {
+ snd_gf1_select_voice(gus, pcmp->pvoices[voice]->number);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice_ctrl);
+ voice_ctrl &= ~0x20; /* disable IRQ for next voice */
+ }
+ }
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+static void snd_gf1_pcm_interrupt_wave(snd_gus_card_t * gus, snd_gus_voice_t *pvoice)
+{
+ gus_pcm_private_t * pcmp;
+ snd_pcm_runtime_t * runtime;
+ unsigned char voice_ctrl, ramp_ctrl;
+ unsigned int idx;
+ unsigned int end, step;
+
+ if (!pvoice->private_data) {
+ snd_printd("snd_gf1_pcm: unknown wave irq?\n");
+ snd_gf1_smart_stop_voice(gus, pvoice->number);
+ return;
+ }
+ pcmp = pvoice->private_data;
+ if (pcmp == NULL) {
+ snd_printd("snd_gf1_pcm: unknown wave irq?\n");
+ snd_gf1_smart_stop_voice(gus, pvoice->number);
+ return;
+ }
+ gus = pcmp->gus;
+ runtime = pcmp->substream->runtime;
+
+ spin_lock(&gus->reg_lock);
+ snd_gf1_select_voice(gus, pvoice->number);
+ voice_ctrl = snd_gf1_read8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL) & ~0x8b;
+ ramp_ctrl = (snd_gf1_read8(gus, SNDRV_GF1_VB_VOLUME_CONTROL) & ~0xa4) | 0x03;
+#if 0
+ snd_gf1_select_voice(gus, pvoice->number);
+ printk("position = 0x%x\n", (snd_gf1_read_addr(gus, SNDRV_GF1_VA_CURRENT, voice_ctrl & 4) >> 4));
+ snd_gf1_select_voice(gus, pcmp->pvoices[1]->number);
+ printk("position = 0x%x\n", (snd_gf1_read_addr(gus, SNDRV_GF1_VA_CURRENT, voice_ctrl & 4) >> 4));
+ snd_gf1_select_voice(gus, pvoice->number);
+#endif
+ pcmp->bpos++;
+ pcmp->bpos %= pcmp->blocks;
+ if (pcmp->bpos + 1 >= pcmp->blocks) { /* last block? */
+ voice_ctrl |= 0x08; /* enable loop */
+ } else {
+ ramp_ctrl |= 0x04; /* enable rollover */
+ }
+ end = pcmp->memory + (((pcmp->bpos + 1) * pcmp->block_size) / runtime->channels);
+ end -= voice_ctrl & 4 ? 2 : 1;
+ step = pcmp->dma_size / runtime->channels;
+ voice_ctrl |= 0x20;
+ if (!pcmp->final_volume) {
+ ramp_ctrl |= 0x20;
+ ramp_ctrl &= ~0x03;
+ }
+ for (idx = 0; idx < pcmp->voices; idx++, end += step) {
+ snd_gf1_select_voice(gus, pcmp->pvoices[idx]->number);
+ snd_gf1_write_addr(gus, SNDRV_GF1_VA_END, end << 4, voice_ctrl & 4);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice_ctrl);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, ramp_ctrl);
+ voice_ctrl &= ~0x20;
+ }
+ if (!gus->gf1.enh_mode) {
+ snd_gf1_delay(gus);
+ voice_ctrl |= 0x20;
+ for (idx = 0; idx < pcmp->voices; idx++) {
+ snd_gf1_select_voice(gus, pcmp->pvoices[idx]->number);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice_ctrl);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, ramp_ctrl);
+ voice_ctrl &= ~0x20;
+ }
+ }
+ spin_unlock(&gus->reg_lock);
+
+ snd_pcm_period_elapsed(pcmp->substream);
+#if 0
+ if ((runtime->flags & SNDRV_PCM_FLG_MMAP) &&
+ *runtime->state == SNDRV_PCM_STATE_RUNNING) {
+ end = pcmp->bpos * pcmp->block_size;
+ if (runtime->channels > 1) {
+ snd_gf1_pcm_block_change(pcmp->substream, end, pcmp->memory + (end / 2), pcmp->block_size / 2);
+ snd_gf1_pcm_block_change(pcmp->substream, end + (pcmp->block_size / 2), pcmp->memory + (pcmp->dma_size / 2) + (end / 2), pcmp->block_size / 2);
+ } else {
+ snd_gf1_pcm_block_change(pcmp->substream, end, pcmp->memory + end, pcmp->block_size);
+ }
+ }
+#endif
+}
+
+static void snd_gf1_pcm_interrupt_volume(snd_gus_card_t * gus, snd_gus_voice_t * pvoice)
+{
+ unsigned short vol;
+ int cvoice;
+ gus_pcm_private_t *pcmp = pvoice->private_data;
+
+ /* stop ramp, but leave rollover bit untouched */
+ spin_lock(&gus->reg_lock);
+ snd_gf1_select_voice(gus, pvoice->number);
+ snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
+ spin_unlock(&gus->reg_lock);
+ if (pcmp == NULL)
+ return;
+ /* are we active? */
+ if (!(pcmp->flags & SNDRV_GF1_PCM_PFLG_ACTIVE))
+ return;
+ /* load real volume - better precision */
+ cvoice = pcmp->pvoices[0] == pvoice ? 0 : 1;
+ if (pcmp->substream == NULL)
+ return;
+ vol = !cvoice ? gus->gf1.pcm_volume_level_left : gus->gf1.pcm_volume_level_right;
+ spin_lock(&gus->reg_lock);
+ snd_gf1_select_voice(gus, pvoice->number);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, vol);
+ pcmp->final_volume = 1;
+ spin_unlock(&gus->reg_lock);
+}
+
+static void snd_gf1_pcm_volume_change(snd_gus_card_t * gus)
+{
+}
+
+static int snd_gf1_pcm_poke_block(snd_gus_card_t *gus, unsigned char *buf,
+ unsigned int pos, unsigned int count,
+ int w16, int invert)
+{
+ unsigned int len;
+ unsigned long flags;
+
+ // printk("poke block; buf = 0x%x, pos = %i, count = %i, port = 0x%x\n", (int)buf, pos, count, gus->gf1.port);
+ while (count > 0) {
+ len = count;
+ if (len > 512) /* limit, to allow IRQ */
+ len = 512;
+ count -= len;
+ if (gus->interwave) {
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01 | (invert ? 0x08 : 0x00));
+ snd_gf1_dram_addr(gus, pos);
+ if (w16) {
+ outb(SNDRV_GF1_GW_DRAM_IO16, GUSP(gus, GF1REGSEL));
+ outsw(GUSP(gus, GF1DATALOW), buf, len >> 1);
+ } else {
+ outsb(GUSP(gus, DRAM), buf, len);
+ }
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ buf += 512;
+ pos += 512;
+ } else {
+ invert = invert ? 0x80 : 0x00;
+ if (w16) {
+ len >>= 1;
+ while (len--) {
+ snd_gf1_poke(gus, pos++, *buf++);
+ snd_gf1_poke(gus, pos++, *buf++ ^ invert);
+ }
+ } else {
+ while (len--)
+ snd_gf1_poke(gus, pos++, *buf++ ^ invert);
+ }
+ }
+ if (count > 0 && !in_interrupt()) {
+ set_current_state(TASK_INTERRUPTIBLE);
+ schedule_timeout(1);
+ if (signal_pending(current))
+ return -EAGAIN;
+ }
+ }
+ return 0;
+}
+
+static int snd_gf1_pcm_playback_copy(snd_pcm_substream_t *substream,
+ int voice,
+ snd_pcm_uframes_t pos,
+ void __user *src,
+ snd_pcm_uframes_t count)
+{
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ gus_pcm_private_t *pcmp = runtime->private_data;
+ unsigned int bpos, len;
+
+ bpos = samples_to_bytes(runtime, pos) + (voice * (pcmp->dma_size / 2));
+ len = samples_to_bytes(runtime, count);
+ snd_assert(bpos <= pcmp->dma_size, return -EIO);
+ snd_assert(bpos + len <= pcmp->dma_size, return -EIO);
+ if (copy_from_user(runtime->dma_area + bpos, src, len))
+ return -EFAULT;
+ if (snd_gf1_pcm_use_dma && len > 32) {
+ return snd_gf1_pcm_block_change(substream, bpos, pcmp->memory + bpos, len);
+ } else {
+ snd_gus_card_t *gus = pcmp->gus;
+ int err, w16, invert;
+
+ w16 = (snd_pcm_format_width(runtime->format) == 16);
+ invert = snd_pcm_format_unsigned(runtime->format);
+ if ((err = snd_gf1_pcm_poke_block(gus, runtime->dma_area + bpos, pcmp->memory + bpos, len, w16, invert)) < 0)
+ return err;
+ }
+ return 0;
+}
+
+static int snd_gf1_pcm_playback_silence(snd_pcm_substream_t *substream,
+ int voice,
+ snd_pcm_uframes_t pos,
+ snd_pcm_uframes_t count)
+{
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ gus_pcm_private_t *pcmp = runtime->private_data;
+ unsigned int bpos, len;
+
+ bpos = samples_to_bytes(runtime, pos) + (voice * (pcmp->dma_size / 2));
+ len = samples_to_bytes(runtime, count);
+ snd_assert(bpos <= pcmp->dma_size, return -EIO);
+ snd_assert(bpos + len <= pcmp->dma_size, return -EIO);
+ snd_pcm_format_set_silence(runtime->format, runtime->dma_area + bpos, count);
+ if (snd_gf1_pcm_use_dma && len > 32) {
+ return snd_gf1_pcm_block_change(substream, bpos, pcmp->memory + bpos, len);
+ } else {
+ snd_gus_card_t *gus = pcmp->gus;
+ int err, w16, invert;
+
+ w16 = (snd_pcm_format_width(runtime->format) == 16);
+ invert = snd_pcm_format_unsigned(runtime->format);
+ if ((err = snd_gf1_pcm_poke_block(gus, runtime->dma_area + bpos, pcmp->memory + bpos, len, w16, invert)) < 0)
+ return err;
+ }
+ return 0;
+}
+
+static int snd_gf1_pcm_playback_hw_params(snd_pcm_substream_t * substream,
+ snd_pcm_hw_params_t * hw_params)
+{
+ snd_gus_card_t *gus = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ gus_pcm_private_t *pcmp = runtime->private_data;
+ int err;
+
+ if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
+ return err;
+ if (err > 0) { /* change */
+ snd_gf1_mem_block_t *block;
+ if (pcmp->memory > 0) {
+ snd_gf1_mem_free(&gus->gf1.mem_alloc, pcmp->memory);
+ pcmp->memory = 0;
+ }
+ if ((block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc,
+ SNDRV_GF1_MEM_OWNER_DRIVER,
+ "GF1 PCM",
+ runtime->dma_bytes, 1, 32,
+ NULL)) == NULL)
+ return -ENOMEM;
+ pcmp->memory = block->ptr;
+ }
+ pcmp->voices = params_channels(hw_params);
+ if (pcmp->pvoices[0] == NULL) {
+ if ((pcmp->pvoices[0] = snd_gf1_alloc_voice(pcmp->gus, SNDRV_GF1_VOICE_TYPE_PCM, 0, 0)) == NULL)
+ return -ENOMEM;
+ pcmp->pvoices[0]->handler_wave = snd_gf1_pcm_interrupt_wave;
+ pcmp->pvoices[0]->handler_volume = snd_gf1_pcm_interrupt_volume;
+ pcmp->pvoices[0]->volume_change = snd_gf1_pcm_volume_change;
+ pcmp->pvoices[0]->private_data = pcmp;
+ }
+ if (pcmp->voices > 1 && pcmp->pvoices[1] == NULL) {
+ if ((pcmp->pvoices[1] = snd_gf1_alloc_voice(pcmp->gus, SNDRV_GF1_VOICE_TYPE_PCM, 0, 0)) == NULL)
+ return -ENOMEM;
+ pcmp->pvoices[1]->handler_wave = snd_gf1_pcm_interrupt_wave;
+ pcmp->pvoices[1]->handler_volume = snd_gf1_pcm_interrupt_volume;
+ pcmp->pvoices[1]->volume_change = snd_gf1_pcm_volume_change;
+ pcmp->pvoices[1]->private_data = pcmp;
+ } else if (pcmp->voices == 1) {
+ if (pcmp->pvoices[1]) {
+ snd_gf1_free_voice(pcmp->gus, pcmp->pvoices[1]);
+ pcmp->pvoices[1] = NULL;
+ }
+ }
+ return 0;
+}
+
+static int snd_gf1_pcm_playback_hw_free(snd_pcm_substream_t * substream)
+{
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ gus_pcm_private_t *pcmp = runtime->private_data;
+
+ snd_pcm_lib_free_pages(substream);
+ if (pcmp->pvoices[0]) {
+ snd_gf1_free_voice(pcmp->gus, pcmp->pvoices[0]);
+ pcmp->pvoices[0] = NULL;
+ }
+ if (pcmp->pvoices[1]) {
+ snd_gf1_free_voice(pcmp->gus, pcmp->pvoices[1]);
+ pcmp->pvoices[1] = NULL;
+ }
+ if (pcmp->memory > 0) {
+ snd_gf1_mem_free(&pcmp->gus->gf1.mem_alloc, pcmp->memory);
+ pcmp->memory = 0;
+ }
+ return 0;
+}
+
+static int snd_gf1_pcm_playback_prepare(snd_pcm_substream_t * substream)
+{
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ gus_pcm_private_t *pcmp = runtime->private_data;
+
+ pcmp->bpos = 0;
+ pcmp->dma_size = snd_pcm_lib_buffer_bytes(substream);
+ pcmp->block_size = snd_pcm_lib_period_bytes(substream);
+ pcmp->blocks = pcmp->dma_size / pcmp->block_size;
+ return 0;
+}
+
+static int snd_gf1_pcm_playback_trigger(snd_pcm_substream_t * substream,
+ int cmd)
+{
+ snd_gus_card_t *gus = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ gus_pcm_private_t *pcmp = runtime->private_data;
+ int voice;
+
+ if (cmd == SNDRV_PCM_TRIGGER_START) {
+ snd_gf1_pcm_trigger_up(substream);
+ } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
+ spin_lock(&pcmp->lock);
+ pcmp->flags &= ~SNDRV_GF1_PCM_PFLG_ACTIVE;
+ spin_unlock(&pcmp->lock);
+ voice = pcmp->pvoices[0]->number;
+ snd_gf1_stop_voices(gus, voice, voice);
+ if (pcmp->pvoices[1]) {
+ voice = pcmp->pvoices[1]->number;
+ snd_gf1_stop_voices(gus, voice, voice);
+ }
+ } else {
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static snd_pcm_uframes_t snd_gf1_pcm_playback_pointer(snd_pcm_substream_t * substream)
+{
+ snd_gus_card_t *gus = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ gus_pcm_private_t *pcmp = runtime->private_data;
+ unsigned int pos;
+ unsigned char voice_ctrl;
+
+ pos = 0;
+ spin_lock(&gus->reg_lock);
+ if (pcmp->flags & SNDRV_GF1_PCM_PFLG_ACTIVE) {
+ snd_gf1_select_voice(gus, pcmp->pvoices[0]->number);
+ voice_ctrl = snd_gf1_read8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL);
+ pos = (snd_gf1_read_addr(gus, SNDRV_GF1_VA_CURRENT, voice_ctrl & 4) >> 4) - pcmp->memory;
+ if (substream->runtime->channels > 1)
+ pos <<= 1;
+ pos = bytes_to_frames(runtime, pos);
+ }
+ spin_unlock(&gus->reg_lock);
+ return pos;
+}
+
+static ratnum_t clock = {
+ .num = 9878400/16,
+ .den_min = 2,
+ .den_max = 257,
+ .den_step = 1,
+};
+
+static snd_pcm_hw_constraint_ratnums_t hw_constraints_clocks = {
+ .nrats = 1,
+ .rats = &clock,
+};
+
+static int snd_gf1_pcm_capture_hw_params(snd_pcm_substream_t * substream,
+ snd_pcm_hw_params_t * hw_params)
+{
+ snd_gus_card_t *gus = snd_pcm_substream_chip(substream);
+
+ gus->c_dma_size = params_buffer_bytes(hw_params);
+ gus->c_period_size = params_period_bytes(hw_params);
+ gus->c_pos = 0;
+ gus->gf1.pcm_rcntrl_reg = 0x21; /* IRQ at end, enable & start */
+ if (params_channels(hw_params) > 1)
+ gus->gf1.pcm_rcntrl_reg |= 2;
+ if (gus->gf1.dma2 > 3)
+ gus->gf1.pcm_rcntrl_reg |= 4;
+ if (snd_pcm_format_unsigned(params_format(hw_params)))
+ gus->gf1.pcm_rcntrl_reg |= 0x80;
+ return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
+}
+
+static int snd_gf1_pcm_capture_hw_free(snd_pcm_substream_t * substream)
+{
+ return snd_pcm_lib_free_pages(substream);
+}
+
+static int snd_gf1_pcm_capture_prepare(snd_pcm_substream_t * substream)
+{
+ snd_gus_card_t *gus = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_RECORD_RATE, runtime->rate_den - 2);
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL, 0); /* disable sampling */
+ snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL); /* Sampling Control Register */
+ snd_dma_program(gus->gf1.dma2, runtime->dma_addr, gus->c_period_size, DMA_MODE_READ);
+ return 0;
+}
+
+static int snd_gf1_pcm_capture_trigger(snd_pcm_substream_t * substream,
+ int cmd)
+{
+ snd_gus_card_t *gus = snd_pcm_substream_chip(substream);
+ int val;
+
+ if (cmd == SNDRV_PCM_TRIGGER_START) {
+ val = gus->gf1.pcm_rcntrl_reg;
+ } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
+ val = 0;
+ } else {
+ return -EINVAL;
+ }
+
+ spin_lock(&gus->reg_lock);
+ snd_gf1_write8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL, val);
+ snd_gf1_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL);
+ spin_unlock(&gus->reg_lock);
+ return 0;
+}
+
+static snd_pcm_uframes_t snd_gf1_pcm_capture_pointer(snd_pcm_substream_t * substream)
+{
+ snd_gus_card_t *gus = snd_pcm_substream_chip(substream);
+ int pos = snd_dma_pointer(gus->gf1.dma2, gus->c_period_size);
+ pos = bytes_to_frames(substream->runtime, (gus->c_pos + pos) % gus->c_dma_size);
+ return pos;
+}
+
+static void snd_gf1_pcm_interrupt_dma_read(snd_gus_card_t * gus)
+{
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL, 0); /* disable sampling */
+ snd_gf1_i_look8(gus, SNDRV_GF1_GB_REC_DMA_CONTROL); /* Sampling Control Register */
+ if (gus->pcm_cap_substream != NULL) {
+ snd_gf1_pcm_capture_prepare(gus->pcm_cap_substream);
+ snd_gf1_pcm_capture_trigger(gus->pcm_cap_substream, SNDRV_PCM_TRIGGER_START);
+ gus->c_pos += gus->c_period_size;
+ snd_pcm_period_elapsed(gus->pcm_cap_substream);
+ }
+}
+
+static snd_pcm_hardware_t snd_gf1_pcm_playback =
+{
+ .info = SNDRV_PCM_INFO_NONINTERLEAVED,
+ .formats = (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 |
+ SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE),
+ .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
+ .rate_min = 5510,
+ .rate_max = 48000,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = (128*1024),
+ .period_bytes_min = 64,
+ .period_bytes_max = (128*1024),
+ .periods_min = 1,
+ .periods_max = 1024,
+ .fifo_size = 0,
+};
+
+static snd_pcm_hardware_t snd_gf1_pcm_capture =
+{
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+ SNDRV_PCM_INFO_MMAP_VALID),
+ .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8,
+ .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_44100,
+ .rate_min = 5510,
+ .rate_max = 44100,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = (128*1024),
+ .period_bytes_min = 64,
+ .period_bytes_max = (128*1024),
+ .periods_min = 1,
+ .periods_max = 1024,
+ .fifo_size = 0,
+};
+
+static void snd_gf1_pcm_playback_free(snd_pcm_runtime_t *runtime)
+{
+ gus_pcm_private_t * pcmp = runtime->private_data;
+ kfree(pcmp);
+}
+
+static int snd_gf1_pcm_playback_open(snd_pcm_substream_t *substream)
+{
+ gus_pcm_private_t *pcmp;
+ snd_gus_card_t *gus = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ int err;
+
+ pcmp = kcalloc(1, sizeof(*pcmp), GFP_KERNEL);
+ if (pcmp == NULL)
+ return -ENOMEM;
+ pcmp->gus = gus;
+ spin_lock_init(&pcmp->lock);
+ init_waitqueue_head(&pcmp->sleep);
+ atomic_set(&pcmp->dma_count, 0);
+
+ runtime->private_data = pcmp;
+ runtime->private_free = snd_gf1_pcm_playback_free;
+
+#if 0
+ printk("playback.buffer = 0x%lx, gf1.pcm_buffer = 0x%lx\n", (long) pcm->playback.buffer, (long) gus->gf1.pcm_buffer);
+#endif
+ if ((err = snd_gf1_dma_init(gus)) < 0)
+ return err;
+ pcmp->flags = SNDRV_GF1_PCM_PFLG_NONE;
+ pcmp->substream = substream;
+ runtime->hw = snd_gf1_pcm_playback;
+ snd_pcm_limit_isa_dma_size(gus->gf1.dma1, &runtime->hw.buffer_bytes_max);
+ snd_pcm_limit_isa_dma_size(gus->gf1.dma1, &runtime->hw.period_bytes_max);
+ snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64);
+ return 0;
+}
+
+static int snd_gf1_pcm_playback_close(snd_pcm_substream_t * substream)
+{
+ snd_gus_card_t *gus = snd_pcm_substream_chip(substream);
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ gus_pcm_private_t *pcmp = runtime->private_data;
+
+ if (!wait_event_timeout(pcmp->sleep, (atomic_read(&pcmp->dma_count) <= 0), 2*HZ))
+ snd_printk("gf1 pcm - serious DMA problem\n");
+
+ snd_gf1_dma_done(gus);
+ return 0;
+}
+
+static int snd_gf1_pcm_capture_open(snd_pcm_substream_t * substream)
+{
+ snd_pcm_runtime_t *runtime = substream->runtime;
+ snd_gus_card_t *gus = snd_pcm_substream_chip(substream);
+
+ gus->gf1.interrupt_handler_dma_read = snd_gf1_pcm_interrupt_dma_read;
+ gus->pcm_cap_substream = substream;
+ substream->runtime->hw = snd_gf1_pcm_capture;
+ snd_pcm_limit_isa_dma_size(gus->gf1.dma2, &runtime->hw.buffer_bytes_max);
+ snd_pcm_limit_isa_dma_size(gus->gf1.dma2, &runtime->hw.period_bytes_max);
+ snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+ &hw_constraints_clocks);
+ return 0;
+}
+
+static int snd_gf1_pcm_capture_close(snd_pcm_substream_t * substream)
+{
+ snd_gus_card_t *gus = snd_pcm_substream_chip(substream);
+
+ gus->pcm_cap_substream = NULL;
+ snd_gf1_set_default_handlers(gus, SNDRV_GF1_HANDLER_DMA_READ);
+ return 0;
+}
+
+static void snd_gf1_pcm_free(snd_pcm_t *pcm)
+{
+ snd_gus_card_t *gus = pcm->private_data;
+ gus->pcm = NULL;
+ snd_pcm_lib_preallocate_free_for_all(pcm);
+}
+
+static int snd_gf1_pcm_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 2;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 127;
+ return 0;
+}
+
+static int snd_gf1_pcm_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ snd_gus_card_t *gus = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->pcm_volume_level_lock, flags);
+ ucontrol->value.integer.value[0] = gus->gf1.pcm_volume_level_left1;
+ ucontrol->value.integer.value[1] = gus->gf1.pcm_volume_level_right1;
+ spin_unlock_irqrestore(&gus->pcm_volume_level_lock, flags);
+ return 0;
+}
+
+static int snd_gf1_pcm_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+ snd_gus_card_t *gus = snd_kcontrol_chip(kcontrol);
+ unsigned long flags;
+ int change;
+ unsigned int idx;
+ unsigned short val1, val2, vol;
+ gus_pcm_private_t *pcmp;
+ snd_gus_voice_t *pvoice;
+
+ val1 = ucontrol->value.integer.value[0] & 127;
+ val2 = ucontrol->value.integer.value[1] & 127;
+ spin_lock_irqsave(&gus->pcm_volume_level_lock, flags);
+ change = val1 != gus->gf1.pcm_volume_level_left1 ||
+ val2 != gus->gf1.pcm_volume_level_right1;
+ gus->gf1.pcm_volume_level_left1 = val1;
+ gus->gf1.pcm_volume_level_right1 = val2;
+ gus->gf1.pcm_volume_level_left = snd_gf1_lvol_to_gvol_raw(val1 << 9) << 4;
+ gus->gf1.pcm_volume_level_right = snd_gf1_lvol_to_gvol_raw(val2 << 9) << 4;
+ spin_unlock_irqrestore(&gus->pcm_volume_level_lock, flags);
+ /* are we active? */
+ spin_lock_irqsave(&gus->voice_alloc, flags);
+ for (idx = 0; idx < 32; idx++) {
+ pvoice = &gus->gf1.voices[idx];
+ if (!pvoice->pcm)
+ continue;
+ pcmp = pvoice->private_data;
+ if (!(pcmp->flags & SNDRV_GF1_PCM_PFLG_ACTIVE))
+ continue;
+ /* load real volume - better precision */
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, pvoice->number);
+ snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
+ vol = pvoice == pcmp->pvoices[0] ? gus->gf1.pcm_volume_level_left : gus->gf1.pcm_volume_level_right;
+ snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, vol);
+ pcmp->final_volume = 1;
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ }
+ spin_unlock_irqrestore(&gus->voice_alloc, flags);
+ return change;
+}
+
+static snd_kcontrol_new_t snd_gf1_pcm_volume_control =
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "PCM Playback Volume",
+ .info = snd_gf1_pcm_volume_info,
+ .get = snd_gf1_pcm_volume_get,
+ .put = snd_gf1_pcm_volume_put
+};
+
+static snd_kcontrol_new_t snd_gf1_pcm_volume_control1 =
+{
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "GPCM Playback Volume",
+ .info = snd_gf1_pcm_volume_info,
+ .get = snd_gf1_pcm_volume_get,
+ .put = snd_gf1_pcm_volume_put
+};
+
+static snd_pcm_ops_t snd_gf1_pcm_playback_ops = {
+ .open = snd_gf1_pcm_playback_open,
+ .close = snd_gf1_pcm_playback_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_gf1_pcm_playback_hw_params,
+ .hw_free = snd_gf1_pcm_playback_hw_free,
+ .prepare = snd_gf1_pcm_playback_prepare,
+ .trigger = snd_gf1_pcm_playback_trigger,
+ .pointer = snd_gf1_pcm_playback_pointer,
+ .copy = snd_gf1_pcm_playback_copy,
+ .silence = snd_gf1_pcm_playback_silence,
+};
+
+static snd_pcm_ops_t snd_gf1_pcm_capture_ops = {
+ .open = snd_gf1_pcm_capture_open,
+ .close = snd_gf1_pcm_capture_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_gf1_pcm_capture_hw_params,
+ .hw_free = snd_gf1_pcm_capture_hw_free,
+ .prepare = snd_gf1_pcm_capture_prepare,
+ .trigger = snd_gf1_pcm_capture_trigger,
+ .pointer = snd_gf1_pcm_capture_pointer,
+};
+
+int snd_gf1_pcm_new(snd_gus_card_t * gus, int pcm_dev, int control_index, snd_pcm_t ** rpcm)
+{
+ snd_card_t *card;
+ snd_kcontrol_t *kctl;
+ snd_pcm_t *pcm;
+ snd_pcm_substream_t *substream;
+ int capture, err;
+
+ if (rpcm)
+ *rpcm = NULL;
+ card = gus->card;
+ capture = !gus->interwave && !gus->ess_flag && !gus->ace_flag ? 1 : 0;
+ err = snd_pcm_new(card,
+ gus->interwave ? "AMD InterWave" : "GF1",
+ pcm_dev,
+ gus->gf1.pcm_channels / 2,
+ capture,
+ &pcm);
+ if (err < 0)
+ return err;
+ pcm->private_data = gus;
+ pcm->private_free = snd_gf1_pcm_free;
+ /* playback setup */
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_gf1_pcm_playback_ops);
+
+ for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
+ snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV,
+ snd_dma_isa_data(),
+ 64*1024, gus->gf1.dma1 > 3 ? 128*1024 : 64*1024);
+
+ pcm->info_flags = 0;
+ pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
+ if (capture) {
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_gf1_pcm_capture_ops);
+ if (gus->gf1.dma2 == gus->gf1.dma1)
+ pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX;
+ snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream,
+ SNDRV_DMA_TYPE_DEV, snd_dma_isa_data(),
+ 64*1024, gus->gf1.dma2 > 3 ? 128*1024 : 64*1024);
+ }
+ strcpy(pcm->name, pcm->id);
+ if (gus->interwave) {
+ sprintf(pcm->name + strlen(pcm->name), " rev %c", gus->revision + 'A');
+ }
+ strcat(pcm->name, " (synth)");
+ gus->pcm = pcm;
+
+ if (gus->codec_flag)
+ kctl = snd_ctl_new1(&snd_gf1_pcm_volume_control1, gus);
+ else
+ kctl = snd_ctl_new1(&snd_gf1_pcm_volume_control, gus);
+ if ((err = snd_ctl_add(card, kctl)) < 0)
+ return err;
+ kctl->id.index = control_index;
+
+ if (rpcm)
+ *rpcm = pcm;
+ return 0;
+}
+
diff --git a/sound/isa/gus/gus_reset.c b/sound/isa/gus/gus_reset.c
new file mode 100644
index 000000000000..b4e66f6a10ae
--- /dev/null
+++ b/sound/isa/gus/gus_reset.c
@@ -0,0 +1,413 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/time.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+
+extern void snd_gf1_timers_init(snd_gus_card_t * gus);
+extern void snd_gf1_timers_done(snd_gus_card_t * gus);
+extern int snd_gf1_synth_init(snd_gus_card_t * gus);
+extern void snd_gf1_synth_done(snd_gus_card_t * gus);
+
+/*
+ * ok.. default interrupt handlers...
+ */
+
+static void snd_gf1_default_interrupt_handler_midi_out(snd_gus_card_t * gus)
+{
+ snd_gf1_uart_cmd(gus, gus->gf1.uart_cmd &= ~0x20);
+}
+
+static void snd_gf1_default_interrupt_handler_midi_in(snd_gus_card_t * gus)
+{
+ snd_gf1_uart_cmd(gus, gus->gf1.uart_cmd &= ~0x80);
+}
+
+static void snd_gf1_default_interrupt_handler_timer1(snd_gus_card_t * gus)
+{
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, gus->gf1.timer_enabled &= ~4);
+}
+
+static void snd_gf1_default_interrupt_handler_timer2(snd_gus_card_t * gus)
+{
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, gus->gf1.timer_enabled &= ~8);
+}
+
+static void snd_gf1_default_interrupt_handler_wave_and_volume(snd_gus_card_t * gus, snd_gus_voice_t * voice)
+{
+ snd_gf1_i_ctrl_stop(gus, 0x00);
+ snd_gf1_i_ctrl_stop(gus, 0x0d);
+}
+
+static void snd_gf1_default_interrupt_handler_dma_write(snd_gus_card_t * gus)
+{
+ snd_gf1_i_write8(gus, 0x41, 0x00);
+}
+
+static void snd_gf1_default_interrupt_handler_dma_read(snd_gus_card_t * gus)
+{
+ snd_gf1_i_write8(gus, 0x49, 0x00);
+}
+
+void snd_gf1_set_default_handlers(snd_gus_card_t * gus, unsigned int what)
+{
+ if (what & SNDRV_GF1_HANDLER_MIDI_OUT)
+ gus->gf1.interrupt_handler_midi_out = snd_gf1_default_interrupt_handler_midi_out;
+ if (what & SNDRV_GF1_HANDLER_MIDI_IN)
+ gus->gf1.interrupt_handler_midi_in = snd_gf1_default_interrupt_handler_midi_in;
+ if (what & SNDRV_GF1_HANDLER_TIMER1)
+ gus->gf1.interrupt_handler_timer1 = snd_gf1_default_interrupt_handler_timer1;
+ if (what & SNDRV_GF1_HANDLER_TIMER2)
+ gus->gf1.interrupt_handler_timer2 = snd_gf1_default_interrupt_handler_timer2;
+ if (what & SNDRV_GF1_HANDLER_VOICE) {
+ snd_gus_voice_t *voice;
+
+ voice = &gus->gf1.voices[what & 0xffff];
+ voice->handler_wave =
+ voice->handler_volume = snd_gf1_default_interrupt_handler_wave_and_volume;
+ voice->handler_effect = NULL;
+ voice->volume_change = NULL;
+ }
+ if (what & SNDRV_GF1_HANDLER_DMA_WRITE)
+ gus->gf1.interrupt_handler_dma_write = snd_gf1_default_interrupt_handler_dma_write;
+ if (what & SNDRV_GF1_HANDLER_DMA_READ)
+ gus->gf1.interrupt_handler_dma_read = snd_gf1_default_interrupt_handler_dma_read;
+}
+
+/*
+
+ */
+
+static void snd_gf1_clear_regs(snd_gus_card_t * gus)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ inb(GUSP(gus, IRQSTAT));
+ snd_gf1_write8(gus, 0x41, 0); /* DRAM DMA Control Register */
+ snd_gf1_write8(gus, 0x45, 0); /* Timer Control */
+ snd_gf1_write8(gus, 0x49, 0); /* Sampling Control Register */
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+static void snd_gf1_look_regs(snd_gus_card_t * gus)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_look8(gus, 0x41); /* DRAM DMA Control Register */
+ snd_gf1_look8(gus, 0x49); /* Sampling Control Register */
+ inb(GUSP(gus, IRQSTAT));
+ snd_gf1_read8(gus, 0x0f); /* IRQ Source Register */
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+/*
+ * put selected GF1 voices to initial stage...
+ */
+
+void snd_gf1_smart_stop_voice(snd_gus_card_t * gus, unsigned short voice)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice);
+#if 0
+ printk(" -%i- smart stop voice - volume = 0x%x\n", voice, snd_gf1_i_read16(gus, SNDRV_GF1_VW_VOLUME));
+#endif
+ snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL);
+ snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+void snd_gf1_stop_voice(snd_gus_card_t * gus, unsigned short voice)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice);
+#if 0
+ printk(" -%i- stop voice - volume = 0x%x\n", voice, snd_gf1_i_read16(gus, SNDRV_GF1_VW_VOLUME));
+#endif
+ snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL);
+ snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
+ if (gus->gf1.enh_mode)
+ snd_gf1_write8(gus, SNDRV_GF1_VB_ACCUMULATOR, 0);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+#if 0
+ snd_gf1_lfo_shutdown(gus, voice, ULTRA_LFO_VIBRATO);
+ snd_gf1_lfo_shutdown(gus, voice, ULTRA_LFO_TREMOLO);
+#endif
+}
+
+void snd_gf1_clear_voices(snd_gus_card_t * gus, unsigned short v_min, unsigned short v_max)
+{
+ unsigned long flags;
+ unsigned int daddr;
+ unsigned short i, w_16;
+
+ daddr = gus->gf1.default_voice_address << 4;
+ for (i = v_min; i <= v_max; i++) {
+#if 0
+ if (gus->gf1.syn_voices)
+ gus->gf1.syn_voices[i].flags = ~VFLG_DYNAMIC;
+#endif
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, i);
+ snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_ADDRESS_CONTROL); /* Voice Control Register = voice stop */
+ snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL); /* Volume Ramp Control Register = ramp off */
+ if (gus->gf1.enh_mode)
+ snd_gf1_write8(gus, SNDRV_GF1_VB_MODE, gus->gf1.memory ? 0x02 : 0x82); /* Deactivate voice */
+ w_16 = snd_gf1_read8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL) & 0x04;
+ snd_gf1_write16(gus, SNDRV_GF1_VW_FREQUENCY, 0x400);
+ snd_gf1_write_addr(gus, SNDRV_GF1_VA_START, daddr, w_16);
+ snd_gf1_write_addr(gus, SNDRV_GF1_VA_END, daddr, w_16);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_START, 0);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_END, 0);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_RATE, 0);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, 0);
+ snd_gf1_write_addr(gus, SNDRV_GF1_VA_CURRENT, daddr, w_16);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_PAN, 7);
+ if (gus->gf1.enh_mode) {
+ snd_gf1_write8(gus, SNDRV_GF1_VB_ACCUMULATOR, 0);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_EFFECT_VOLUME, 0);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_EFFECT_VOLUME_FINAL, 0);
+ }
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+#if 0
+ snd_gf1_lfo_shutdown(gus, i, ULTRA_LFO_VIBRATO);
+ snd_gf1_lfo_shutdown(gus, i, ULTRA_LFO_TREMOLO);
+#endif
+ }
+}
+
+void snd_gf1_stop_voices(snd_gus_card_t * gus, unsigned short v_min, unsigned short v_max)
+{
+ unsigned long flags;
+ short i, ramp_ok;
+ unsigned short ramp_end;
+
+ if (!in_interrupt()) { /* this can't be done in interrupt */
+ for (i = v_min, ramp_ok = 0; i <= v_max; i++) {
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, i);
+ ramp_end = snd_gf1_read16(gus, 9) >> 8;
+ if (ramp_end > SNDRV_GF1_MIN_OFFSET) {
+ ramp_ok++;
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_RATE, 20); /* ramp rate */
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_START, SNDRV_GF1_MIN_OFFSET); /* ramp start */
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_END, ramp_end); /* ramp end */
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, 0x40); /* ramp down */
+ if (gus->gf1.enh_mode) {
+ snd_gf1_delay(gus);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, 0x40);
+ }
+ }
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ }
+ msleep_interruptible(50);
+ }
+ snd_gf1_clear_voices(gus, v_min, v_max);
+}
+
+static void snd_gf1_alloc_voice_use(snd_gus_card_t * gus,
+ snd_gus_voice_t * pvoice,
+ int type, int client, int port)
+{
+ pvoice->use = 1;
+ switch (type) {
+ case SNDRV_GF1_VOICE_TYPE_PCM:
+ gus->gf1.pcm_alloc_voices++;
+ pvoice->pcm = 1;
+ break;
+ case SNDRV_GF1_VOICE_TYPE_SYNTH:
+ pvoice->synth = 1;
+ pvoice->client = client;
+ pvoice->port = port;
+ break;
+ case SNDRV_GF1_VOICE_TYPE_MIDI:
+ pvoice->midi = 1;
+ pvoice->client = client;
+ pvoice->port = port;
+ break;
+ }
+}
+
+snd_gus_voice_t *snd_gf1_alloc_voice(snd_gus_card_t * gus, int type, int client, int port)
+{
+ snd_gus_voice_t *pvoice;
+ unsigned long flags;
+ int idx;
+
+ spin_lock_irqsave(&gus->voice_alloc, flags);
+ if (type == SNDRV_GF1_VOICE_TYPE_PCM) {
+ if (gus->gf1.pcm_alloc_voices >= gus->gf1.pcm_channels) {
+ spin_unlock_irqrestore(&gus->voice_alloc, flags);
+ return NULL;
+ }
+ }
+ for (idx = 0; idx < 32; idx++) {
+ pvoice = &gus->gf1.voices[idx];
+ if (!pvoice->use) {
+ snd_gf1_alloc_voice_use(gus, pvoice, type, client, port);
+ spin_unlock_irqrestore(&gus->voice_alloc, flags);
+ return pvoice;
+ }
+ }
+ for (idx = 0; idx < 32; idx++) {
+ pvoice = &gus->gf1.voices[idx];
+ if (pvoice->midi && !pvoice->client) {
+ snd_gf1_clear_voices(gus, pvoice->number, pvoice->number);
+ snd_gf1_alloc_voice_use(gus, pvoice, type, client, port);
+ spin_unlock_irqrestore(&gus->voice_alloc, flags);
+ return pvoice;
+ }
+ }
+ spin_unlock_irqrestore(&gus->voice_alloc, flags);
+ return NULL;
+}
+
+void snd_gf1_free_voice(snd_gus_card_t * gus, snd_gus_voice_t *voice)
+{
+ unsigned long flags;
+ void (*private_free)(snd_gus_voice_t *voice);
+ void *private_data;
+
+ if (voice == NULL || !voice->use)
+ return;
+ snd_gf1_set_default_handlers(gus, SNDRV_GF1_HANDLER_VOICE | voice->number);
+ snd_gf1_clear_voices(gus, voice->number, voice->number);
+ spin_lock_irqsave(&gus->voice_alloc, flags);
+ private_free = voice->private_free;
+ private_data = voice->private_data;
+ voice->private_free = NULL;
+ voice->private_data = NULL;
+ if (voice->pcm)
+ gus->gf1.pcm_alloc_voices--;
+ voice->use = voice->pcm = 0;
+ voice->sample_ops = NULL;
+ spin_unlock_irqrestore(&gus->voice_alloc, flags);
+ if (private_free)
+ private_free(voice);
+}
+
+/*
+ * call this function only by start of driver
+ */
+
+int snd_gf1_start(snd_gus_card_t * gus)
+{
+ unsigned long flags;
+ unsigned int i;
+
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
+ udelay(160);
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* disable IRQ & DAC */
+ udelay(160);
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_JOYSTICK_DAC_LEVEL, gus->joystick_dac);
+
+ snd_gf1_set_default_handlers(gus, SNDRV_GF1_HANDLER_ALL);
+ for (i = 0; i < 32; i++) {
+ gus->gf1.voices[i].number = i;
+ snd_gf1_set_default_handlers(gus, SNDRV_GF1_HANDLER_VOICE | i);
+ }
+
+ snd_gf1_uart_cmd(gus, 0x03); /* huh.. this cleanup took me some time... */
+
+ if (gus->gf1.enh_mode) { /* enhanced mode !!!! */
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_GLOBAL_MODE, snd_gf1_i_look8(gus, SNDRV_GF1_GB_GLOBAL_MODE) | 0x01);
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01);
+ }
+ snd_gf1_clear_regs(gus);
+ snd_gf1_select_active_voices(gus);
+ snd_gf1_delay(gus);
+ gus->gf1.default_voice_address = gus->gf1.memory > 0 ? 0 : 512 - 8;
+ /* initialize LFOs & clear LFOs memory */
+ if (gus->gf1.enh_mode && gus->gf1.memory) {
+ gus->gf1.hw_lfo = 1;
+ gus->gf1.default_voice_address += 1024;
+ } else {
+ gus->gf1.sw_lfo = 1;
+ }
+#if 0
+ snd_gf1_lfo_init(gus);
+#endif
+ if (gus->gf1.memory > 0)
+ for (i = 0; i < 4; i++)
+ snd_gf1_poke(gus, gus->gf1.default_voice_address + i, 0);
+ snd_gf1_clear_regs(gus);
+ snd_gf1_clear_voices(gus, 0, 31);
+ snd_gf1_look_regs(gus);
+ udelay(160);
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 7); /* Reset Register = IRQ enable, DAC enable */
+ udelay(160);
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 7); /* Reset Register = IRQ enable, DAC enable */
+ if (gus->gf1.enh_mode) { /* enhanced mode !!!! */
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_GLOBAL_MODE, snd_gf1_i_look8(gus, SNDRV_GF1_GB_GLOBAL_MODE) | 0x01);
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01);
+ }
+ while ((snd_gf1_i_read8(gus, SNDRV_GF1_GB_VOICES_IRQ) & 0xc0) != 0xc0);
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ outb(gus->gf1.active_voice = 0, GUSP(gus, GF1PAGE));
+ outb(gus->mix_cntrl_reg, GUSP(gus, MIXCNTRLREG));
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+
+ snd_gf1_timers_init(gus);
+ snd_gf1_look_regs(gus);
+ snd_gf1_mem_init(gus);
+ snd_gf1_mem_proc_init(gus);
+#ifdef CONFIG_SND_DEBUG
+ snd_gus_irq_profile_init(gus);
+#endif
+
+#if 0
+ if (gus->pnp_flag) {
+ if (gus->chip.playback_fifo_size > 0)
+ snd_gf1_i_write16(gus, SNDRV_GF1_GW_FIFO_RECORD_BASE_ADDR, gus->chip.playback_fifo_block->ptr >> 8);
+ if (gus->chip.record_fifo_size > 0)
+ snd_gf1_i_write16(gus, SNDRV_GF1_GW_FIFO_PLAY_BASE_ADDR, gus->chip.record_fifo_block->ptr >> 8);
+ snd_gf1_i_write16(gus, SNDRV_GF1_GW_FIFO_SIZE, gus->chip.interwave_fifo_reg);
+ }
+#endif
+
+ return 0;
+}
+
+/*
+ * call this function only by shutdown of driver
+ */
+
+int snd_gf1_stop(snd_gus_card_t * gus)
+{
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, 0); /* stop all timers */
+ snd_gf1_stop_voices(gus, 0, 31); /* stop all voices */
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* disable IRQ & DAC */
+ snd_gf1_timers_done(gus);
+ snd_gf1_mem_done(gus);
+#if 0
+ snd_gf1_lfo_done(gus);
+#endif
+ return 0;
+}
diff --git a/sound/isa/gus/gus_sample.c b/sound/isa/gus/gus_sample.c
new file mode 100644
index 000000000000..4290e03acd51
--- /dev/null
+++ b/sound/isa/gus/gus_sample.c
@@ -0,0 +1,155 @@
+/*
+ * Routines for Gravis UltraSound soundcards - Sample support
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/time.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+
+/*
+ *
+ */
+
+static void select_instrument(snd_gus_card_t * gus, snd_gus_voice_t * v)
+{
+ snd_seq_kinstr_t *instr;
+
+#if 0
+ printk("select instrument: cluster = %li, std = 0x%x, bank = %i, prg = %i\n",
+ v->instr.cluster,
+ v->instr.std,
+ v->instr.bank,
+ v->instr.prg);
+#endif
+ instr = snd_seq_instr_find(gus->gf1.ilist, &v->instr, 0, 1);
+ if (instr != NULL) {
+ if (instr->ops) {
+ if (!strcmp(instr->ops->instr_type, SNDRV_SEQ_INSTR_ID_SIMPLE))
+ snd_gf1_simple_init(v);
+ }
+ snd_seq_instr_free_use(gus->gf1.ilist, instr);
+ }
+}
+
+/*
+ *
+ */
+
+static void event_sample(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
+{
+ if (v->sample_ops && v->sample_ops->sample_stop)
+ v->sample_ops->sample_stop(p->gus, v, SAMPLE_STOP_IMMEDIATELY);
+ v->instr.std = ev->data.sample.param.sample.std;
+ if (v->instr.std & 0xff000000) { /* private instrument */
+ v->instr.std &= 0x00ffffff;
+ v->instr.std |= (unsigned int)ev->source.client << 24;
+ }
+ v->instr.bank = ev->data.sample.param.sample.bank;
+ v->instr.prg = ev->data.sample.param.sample.prg;
+ select_instrument(p->gus, v);
+}
+
+static void event_cluster(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
+{
+ if (v->sample_ops && v->sample_ops->sample_stop)
+ v->sample_ops->sample_stop(p->gus, v, SAMPLE_STOP_IMMEDIATELY);
+ v->instr.cluster = ev->data.sample.param.cluster.cluster;
+ select_instrument(p->gus, v);
+}
+
+static void event_start(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
+{
+ if (v->sample_ops && v->sample_ops->sample_start)
+ v->sample_ops->sample_start(p->gus, v, ev->data.sample.param.position);
+}
+
+static void event_stop(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
+{
+ if (v->sample_ops && v->sample_ops->sample_stop)
+ v->sample_ops->sample_stop(p->gus, v, ev->data.sample.param.stop_mode);
+}
+
+static void event_freq(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
+{
+ if (v->sample_ops && v->sample_ops->sample_freq)
+ v->sample_ops->sample_freq(p->gus, v, ev->data.sample.param.frequency);
+}
+
+static void event_volume(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
+{
+ if (v->sample_ops && v->sample_ops->sample_volume)
+ v->sample_ops->sample_volume(p->gus, v, &ev->data.sample.param.volume);
+}
+
+static void event_loop(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
+{
+ if (v->sample_ops && v->sample_ops->sample_loop)
+ v->sample_ops->sample_loop(p->gus, v, &ev->data.sample.param.loop);
+}
+
+static void event_position(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
+{
+ if (v->sample_ops && v->sample_ops->sample_pos)
+ v->sample_ops->sample_pos(p->gus, v, ev->data.sample.param.position);
+}
+
+static void event_private1(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
+{
+ if (v->sample_ops && v->sample_ops->sample_private1)
+ v->sample_ops->sample_private1(p->gus, v, (unsigned char *)&ev->data.sample.param.raw8);
+}
+
+typedef void (gus_sample_event_handler_t)(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v);
+
+static gus_sample_event_handler_t *gus_sample_event_handlers[9] = {
+ event_sample,
+ event_cluster,
+ event_start,
+ event_stop,
+ event_freq,
+ event_volume,
+ event_loop,
+ event_position,
+ event_private1
+};
+
+void snd_gus_sample_event(snd_seq_event_t *ev, snd_gus_port_t *p)
+{
+ int idx, voice;
+ snd_gus_card_t *gus = p->gus;
+ snd_gus_voice_t *v;
+ unsigned long flags;
+
+ idx = ev->type - SNDRV_SEQ_EVENT_SAMPLE;
+ if (idx < 0 || idx > 8)
+ return;
+ for (voice = 0; voice < 32; voice++) {
+ v = &gus->gf1.voices[voice];
+ if (v->use && v->client == ev->source.client &&
+ v->port == ev->source.port &&
+ v->index == ev->data.sample.channel) {
+ spin_lock_irqsave(&gus->event_lock, flags);
+ gus_sample_event_handlers[idx](ev, p, v);
+ spin_unlock_irqrestore(&gus->event_lock, flags);
+ return;
+ }
+ }
+}
diff --git a/sound/isa/gus/gus_simple.c b/sound/isa/gus/gus_simple.c
new file mode 100644
index 000000000000..c122e7be6ceb
--- /dev/null
+++ b/sound/isa/gus/gus_simple.c
@@ -0,0 +1,634 @@
+/*
+ * Routines for Gravis UltraSound soundcards - Simple instrument handlers
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/time.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+#include "gus_tables.h"
+
+/*
+ *
+ */
+
+static void interrupt_wave(snd_gus_card_t *gus, snd_gus_voice_t *voice);
+static void interrupt_volume(snd_gus_card_t *gus, snd_gus_voice_t *voice);
+static void interrupt_effect(snd_gus_card_t *gus, snd_gus_voice_t *voice);
+
+static void sample_start(snd_gus_card_t *gus, snd_gus_voice_t *voice, snd_seq_position_t position);
+static void sample_stop(snd_gus_card_t *gus, snd_gus_voice_t *voice, snd_seq_stop_mode_t mode);
+static void sample_freq(snd_gus_card_t *gus, snd_gus_voice_t *voice, snd_seq_frequency_t freq);
+static void sample_volume(snd_gus_card_t *card, snd_gus_voice_t *voice, snd_seq_ev_volume_t *volume);
+static void sample_loop(snd_gus_card_t *card, snd_gus_voice_t *voice, snd_seq_ev_loop_t *loop);
+static void sample_pos(snd_gus_card_t *card, snd_gus_voice_t *voice, snd_seq_position_t position);
+static void sample_private1(snd_gus_card_t *card, snd_gus_voice_t *voice, unsigned char *data);
+
+static snd_gus_sample_ops_t sample_ops = {
+ sample_start,
+ sample_stop,
+ sample_freq,
+ sample_volume,
+ sample_loop,
+ sample_pos,
+ sample_private1
+};
+
+#if 0
+
+static void note_stop(snd_gus_card_t *gus, snd_gus_voice_t *voice, int wait);
+static void note_wait(snd_gus_card_t *gus, snd_gus_voice_t *voice);
+static void note_off(snd_gus_card_t *gus, snd_gus_voice_t *voice);
+static void note_volume(snd_gus_card_t *card, snd_gus_voice_t *voice);
+static void note_pitchbend(snd_gus_card_t *card, snd_gus_voice_t *voice);
+static void note_vibrato(snd_gus_card_t *card, snd_gus_voice_t *voice);
+static void note_tremolo(snd_gus_card_t *card, snd_gus_voice_t *voice);
+
+static struct snd_gus_note_handlers note_commands = {
+ note_stop,
+ note_wait,
+ note_off,
+ note_volume,
+ note_pitchbend,
+ note_vibrato,
+ note_tremolo
+};
+
+static void chn_trigger_down(snd_gus_card_t *card, ultra_channel_t *channel, ultra_instrument_t *instrument, unsigned char note, unsigned char velocity, unsigned char priority );
+static void chn_trigger_up( ultra_card_t *card, ultra_note_t *note );
+static void chn_control( ultra_card_t *card, ultra_channel_t *channel, unsigned short p1, unsigned short p2 );
+
+static struct ULTRA_STRU_INSTRUMENT_CHANNEL_COMMANDS channel_commands = {
+ chn_trigger_down,
+ chn_trigger_up,
+ chn_control
+};
+
+#endif
+
+static void do_volume_envelope(snd_gus_card_t *card, snd_gus_voice_t *voice);
+static void do_pan_envelope(snd_gus_card_t *card, snd_gus_voice_t *voice);
+
+/*
+ *
+ */
+
+static void interrupt_wave(snd_gus_card_t *gus, snd_gus_voice_t *voice)
+{
+ spin_lock(&gus->event_lock);
+ snd_gf1_stop_voice(gus, voice->number);
+ spin_lock(&gus->reg_lock);
+ snd_gf1_select_voice(gus, voice->number);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, 0);
+ spin_unlock(&gus->reg_lock);
+ voice->flags &= ~SNDRV_GF1_VFLG_RUNNING;
+ spin_unlock(&gus->event_lock);
+}
+
+static void interrupt_volume(snd_gus_card_t *gus, snd_gus_voice_t *voice)
+{
+ spin_lock(&gus->event_lock);
+ if (voice->flags & SNDRV_GF1_VFLG_RUNNING)
+ do_volume_envelope(gus, voice);
+ else
+ snd_gf1_stop_voice(gus, voice->number);
+ spin_unlock(&gus->event_lock);
+}
+
+static void interrupt_effect(snd_gus_card_t *gus, snd_gus_voice_t *voice)
+{
+ spin_lock(&gus->event_lock);
+ if ((voice->flags & (SNDRV_GF1_VFLG_RUNNING|SNDRV_GF1_VFLG_EFFECT_TIMER1)) ==
+ (SNDRV_GF1_VFLG_RUNNING|SNDRV_GF1_VFLG_EFFECT_TIMER1))
+ do_pan_envelope(gus, voice);
+ spin_unlock(&gus->event_lock);
+}
+
+/*
+ *
+ */
+
+static void do_volume_envelope(snd_gus_card_t *gus, snd_gus_voice_t *voice)
+{
+ unsigned short next, rate, old_volume;
+ int program_next_ramp;
+ unsigned long flags;
+
+ if (!gus->gf1.volume_ramp) {
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice->number);
+ snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, voice->gf1_volume);
+ printk("gf1_volume = 0x%x\n", voice->gf1_volume);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return;
+ }
+ program_next_ramp = 0;
+ rate = next = 0;
+ while (1) {
+ program_next_ramp = 0;
+ rate = next = 0;
+ switch (voice->venv_state) {
+ case VENV_BEFORE:
+ voice->venv_state = VENV_ATTACK;
+ voice->venv_value_next = 0;
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice->number);
+ snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, SNDRV_GF1_MIN_VOLUME);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ break;
+ case VENV_ATTACK:
+ voice->venv_state = VENV_SUSTAIN;
+ program_next_ramp++;
+ next = 255;
+ rate = gus->gf1.volume_ramp;
+ break;
+ case VENV_SUSTAIN:
+ voice->venv_state = VENV_RELEASE;
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice->number);
+ snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, ((int)voice->gf1_volume * (int)voice->venv_value_next) / 255);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return;
+ case VENV_RELEASE:
+ voice->venv_state = VENV_DONE;
+ program_next_ramp++;
+ next = 0;
+ rate = gus->gf1.volume_ramp;
+ break;
+ case VENV_DONE:
+ snd_gf1_stop_voice(gus, voice->number);
+ voice->flags &= ~SNDRV_GF1_VFLG_RUNNING;
+ return;
+ case VENV_VOLUME:
+ program_next_ramp++;
+ next = voice->venv_value_next;
+ rate = gus->gf1.volume_ramp;
+ voice->venv_state = voice->venv_state_prev;
+ break;
+ }
+ voice->venv_value_next = next;
+ if (!program_next_ramp)
+ continue;
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice->number);
+ snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
+ old_volume = snd_gf1_read16(gus, SNDRV_GF1_VW_VOLUME) >> 8;
+ if (!rate) {
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ continue;
+ }
+ next = (((int)voice->gf1_volume * (int)next) / 255) >> 8;
+ if (old_volume < SNDRV_GF1_MIN_OFFSET)
+ old_volume = SNDRV_GF1_MIN_OFFSET;
+ if (next < SNDRV_GF1_MIN_OFFSET)
+ next = SNDRV_GF1_MIN_OFFSET;
+ if (next > SNDRV_GF1_MAX_OFFSET)
+ next = SNDRV_GF1_MAX_OFFSET;
+ if (old_volume == next) {
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ continue;
+ }
+ voice->volume_control &= ~0xc3;
+ voice->volume_control |= 0x20;
+ if (old_volume > next) {
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_START, next);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_END, old_volume);
+ voice->volume_control |= 0x40;
+ } else {
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_START, old_volume);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_END, next);
+ }
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_RATE, rate);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, voice->volume_control);
+ if (!gus->gf1.enh_mode) {
+ snd_gf1_delay(gus);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, voice->volume_control);
+ }
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return;
+ }
+}
+
+static void do_pan_envelope(snd_gus_card_t *gus, snd_gus_voice_t *voice)
+{
+ unsigned long flags;
+ unsigned char old_pan;
+
+#if 0
+ snd_gf1_select_voice(gus, voice->number);
+ printk(" -%i- do_pan_envelope - flags = 0x%x (0x%x -> 0x%x)\n",
+ voice->number,
+ voice->flags,
+ voice->gf1_pan,
+ snd_gf1_i_read8(gus, SNDRV_GF1_VB_PAN) & 0x0f);
+#endif
+ if (gus->gf1.enh_mode) {
+ voice->flags &= ~(SNDRV_GF1_VFLG_EFFECT_TIMER1|SNDRV_GF1_VFLG_PAN);
+ return;
+ }
+ if (!gus->gf1.smooth_pan) {
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice->number);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_PAN, voice->gf1_pan);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return;
+ }
+ if (!(voice->flags & SNDRV_GF1_VFLG_PAN)) /* before */
+ voice->flags |= SNDRV_GF1_VFLG_EFFECT_TIMER1|SNDRV_GF1_VFLG_PAN;
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice->number);
+ old_pan = snd_gf1_read8(gus, SNDRV_GF1_VB_PAN) & 0x0f;
+ if (old_pan > voice->gf1_pan )
+ old_pan--;
+ if (old_pan < voice->gf1_pan)
+ old_pan++;
+ snd_gf1_write8(gus, SNDRV_GF1_VB_PAN, old_pan);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ if (old_pan == voice->gf1_pan) /* the goal was reached */
+ voice->flags &= ~(SNDRV_GF1_VFLG_EFFECT_TIMER1|SNDRV_GF1_VFLG_PAN);
+#if 0
+ snd_gf1_select_voice(gus, voice->number);
+ printk(" -%i- (1) do_pan_envelope - flags = 0x%x (0x%x -> 0x%x)\n",
+ voice->number,
+ voice->flags,
+ voice->gf1_pan,
+ snd_gf1_i_read8(gus, GF1_VB_PAN) & 0x0f);
+#endif
+}
+
+static void set_enhanced_pan(snd_gus_card_t *gus, snd_gus_voice_t *voice, unsigned short pan)
+{
+ unsigned long flags;
+ unsigned short vlo, vro;
+
+ vlo = SNDRV_GF1_ATTEN((SNDRV_GF1_ATTEN_TABLE_SIZE-1) - pan);
+ vro = SNDRV_GF1_ATTEN(pan);
+ if (pan != SNDRV_GF1_ATTEN_TABLE_SIZE - 1 && pan != 0) {
+ vlo >>= 1;
+ vro >>= 1;
+ }
+ vlo <<= 4;
+ vro <<= 4;
+#if 0
+ printk("vlo = 0x%x (0x%x), vro = 0x%x (0x%x)\n",
+ vlo, snd_gf1_i_read16(gus, GF1_VW_OFFSET_LEFT),
+ vro, snd_gf1_i_read16(gus, GF1_VW_OFFSET_RIGHT));
+#endif
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice->number);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_LEFT_FINAL, vlo);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_RIGHT_FINAL, vro);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ voice->vlo = vlo;
+ voice->vro = vro;
+}
+
+/*
+ *
+ */
+
+static void sample_start(snd_gus_card_t *gus, snd_gus_voice_t *voice, snd_seq_position_t position)
+{
+ unsigned long flags;
+ unsigned int begin, addr, addr_end, addr_start;
+ int w_16;
+ simple_instrument_t *simple;
+ snd_seq_kinstr_t *instr;
+
+ instr = snd_seq_instr_find(gus->gf1.ilist, &voice->instr, 0, 1);
+ if (instr == NULL)
+ return;
+ voice->instr = instr->instr; /* copy ID to speedup aliases */
+ simple = KINSTR_DATA(instr);
+ begin = simple->address.memory << 4;
+ w_16 = simple->format & SIMPLE_WAVE_16BIT ? 0x04 : 0;
+ addr_start = simple->loop_start;
+ if (simple->format & SIMPLE_WAVE_LOOP) {
+ addr_end = simple->loop_end;
+ } else {
+ addr_end = (simple->size << 4) - (w_16 ? 40 : 24);
+ }
+ if (simple->format & SIMPLE_WAVE_BACKWARD) {
+ addr = simple->loop_end;
+ if (position < simple->loop_end)
+ addr -= position;
+ } else {
+ addr = position;
+ }
+ voice->control = 0x00;
+ voice->mode = 0x20; /* enable offset registers */
+ if (simple->format & SIMPLE_WAVE_16BIT)
+ voice->control |= 0x04;
+ if (simple->format & SIMPLE_WAVE_BACKWARD)
+ voice->control |= 0x40;
+ if (simple->format & SIMPLE_WAVE_LOOP) {
+ voice->control |= 0x08;
+ } else {
+ voice->control |= 0x20;
+ }
+ if (simple->format & SIMPLE_WAVE_BIDIR)
+ voice->control |= 0x10;
+ if (simple->format & SIMPLE_WAVE_ULAW)
+ voice->mode |= 0x40;
+ if (w_16) {
+ addr = ((addr << 1) & ~0x1f) | (addr & 0x0f);
+ addr_start = ((addr_start << 1) & ~0x1f) | (addr_start & 0x0f);
+ addr_end = ((addr_end << 1) & ~0x1f) | (addr_end & 0x0f);
+ }
+ addr += begin;
+ addr_start += begin;
+ addr_end += begin;
+ snd_gf1_stop_voice(gus, voice->number);
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice->number);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_FREQUENCY, voice->fc_register + voice->fc_lfo);
+ voice->venv_state = VENV_BEFORE;
+ voice->volume_control = 0x03;
+ snd_gf1_write_addr(gus, SNDRV_GF1_VA_START, addr_start, w_16);
+ snd_gf1_write_addr(gus, SNDRV_GF1_VA_END, addr_end, w_16);
+ snd_gf1_write_addr(gus, SNDRV_GF1_VA_CURRENT, addr, w_16);
+ if (!gus->gf1.enh_mode) {
+ snd_gf1_write8(gus, SNDRV_GF1_VB_PAN, voice->gf1_pan);
+ } else {
+ snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_LEFT, voice->vlo);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_LEFT_FINAL, voice->vlo);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_RIGHT, voice->vro);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_RIGHT_FINAL, voice->vro);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_ACCUMULATOR, voice->effect_accumulator);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_EFFECT_VOLUME, voice->gf1_effect_volume);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_EFFECT_VOLUME_FINAL, voice->gf1_effect_volume);
+ }
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ do_volume_envelope(gus, voice);
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice->number);
+ if (gus->gf1.enh_mode)
+ snd_gf1_write8(gus, SNDRV_GF1_VB_MODE, voice->mode);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice->control);
+ if (!gus->gf1.enh_mode) {
+ snd_gf1_delay(gus);
+ snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice->control );
+ }
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+#if 0
+ snd_gf1_print_voice_registers(gus);
+#endif
+ voice->flags |= SNDRV_GF1_VFLG_RUNNING;
+ snd_seq_instr_free_use(gus->gf1.ilist, instr);
+}
+
+static void sample_stop(snd_gus_card_t *gus, snd_gus_voice_t *voice, snd_seq_stop_mode_t mode)
+{
+ unsigned char control;
+ unsigned long flags;
+
+ if (!(voice->flags & SNDRV_GF1_VFLG_RUNNING))
+ return;
+ switch (mode) {
+ default:
+ if (gus->gf1.volume_ramp > 0) {
+ if (voice->venv_state < VENV_RELEASE) {
+ voice->venv_state = VENV_RELEASE;
+ do_volume_envelope(gus, voice);
+ }
+ }
+ if (mode != SAMPLE_STOP_VENVELOPE) {
+ snd_gf1_stop_voice(gus, voice->number);
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice->number);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, SNDRV_GF1_MIN_VOLUME);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ voice->flags &= ~SNDRV_GF1_VFLG_RUNNING;
+ }
+ break;
+ case SAMPLE_STOP_LOOP: /* disable loop only */
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice->number);
+ control = snd_gf1_read8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL);
+ control &= ~(0x83 | 0x04);
+ control |= 0x20;
+ snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, control);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ break;
+ }
+}
+
+static void sample_freq(snd_gus_card_t *gus, snd_gus_voice_t *voice, snd_seq_frequency_t freq)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ voice->fc_register = snd_gf1_translate_freq(gus, freq);
+ snd_gf1_select_voice(gus, voice->number);
+ snd_gf1_write16(gus, SNDRV_GF1_VW_FREQUENCY, voice->fc_register + voice->fc_lfo);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+}
+
+static void sample_volume(snd_gus_card_t *gus, snd_gus_voice_t *voice, snd_seq_ev_volume_t *volume)
+{
+ if (volume->volume >= 0) {
+ volume->volume &= 0x3fff;
+ voice->gf1_volume = snd_gf1_lvol_to_gvol_raw(volume->volume << 2) << 4;
+ voice->venv_state_prev = VENV_SUSTAIN;
+ voice->venv_state = VENV_VOLUME;
+ do_volume_envelope(gus, voice);
+ }
+ if (volume->lr >= 0) {
+ volume->lr &= 0x3fff;
+ if (!gus->gf1.enh_mode) {
+ voice->gf1_pan = (volume->lr >> 10) & 15;
+ if (!gus->gf1.full_range_pan) {
+ if (voice->gf1_pan == 0)
+ voice->gf1_pan++;
+ if (voice->gf1_pan == 15)
+ voice->gf1_pan--;
+ }
+ voice->flags &= ~SNDRV_GF1_VFLG_PAN; /* before */
+ do_pan_envelope(gus, voice);
+ } else {
+ set_enhanced_pan(gus, voice, volume->lr >> 7);
+ }
+ }
+}
+
+static void sample_loop(snd_gus_card_t *gus, snd_gus_voice_t *voice, snd_seq_ev_loop_t *loop)
+{
+ unsigned long flags;
+ int w_16 = voice->control & 0x04;
+ unsigned int begin, addr_start, addr_end;
+ simple_instrument_t *simple;
+ snd_seq_kinstr_t *instr;
+
+#if 0
+ printk("voice_loop: start = 0x%x, end = 0x%x\n", loop->start, loop->end);
+#endif
+ instr = snd_seq_instr_find(gus->gf1.ilist, &voice->instr, 0, 1);
+ if (instr == NULL)
+ return;
+ voice->instr = instr->instr; /* copy ID to speedup aliases */
+ simple = KINSTR_DATA(instr);
+ begin = simple->address.memory;
+ addr_start = loop->start;
+ addr_end = loop->end;
+ addr_start = (((addr_start << 1) & ~0x1f) | (addr_start & 0x0f)) + begin;
+ addr_end = (((addr_end << 1) & ~0x1f) | (addr_end & 0x0f)) + begin;
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice->number);
+ snd_gf1_write_addr(gus, SNDRV_GF1_VA_START, addr_start, w_16);
+ snd_gf1_write_addr(gus, SNDRV_GF1_VA_END, addr_end, w_16);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ snd_seq_instr_free_use(gus->gf1.ilist, instr);
+}
+
+static void sample_pos(snd_gus_card_t *gus, snd_gus_voice_t *voice, snd_seq_position_t position)
+{
+ unsigned long flags;
+ int w_16 = voice->control & 0x04;
+ unsigned int begin, addr;
+ simple_instrument_t *simple;
+ snd_seq_kinstr_t *instr;
+
+#if 0
+ printk("voice_loop: start = 0x%x, end = 0x%x\n", loop->start, loop->end);
+#endif
+ instr = snd_seq_instr_find(gus->gf1.ilist, &voice->instr, 0, 1);
+ if (instr == NULL)
+ return;
+ voice->instr = instr->instr; /* copy ID to speedup aliases */
+ simple = KINSTR_DATA(instr);
+ begin = simple->address.memory;
+ addr = (((position << 1) & ~0x1f) | (position & 0x0f)) + begin;
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ snd_gf1_select_voice(gus, voice->number);
+ snd_gf1_write_addr(gus, SNDRV_GF1_VA_CURRENT, addr, w_16);
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ snd_seq_instr_free_use(gus->gf1.ilist, instr);
+}
+
+#if 0
+
+static unsigned char get_effects_mask( ultra_card_t *card, int value )
+{
+ if ( value > 7 ) return 0;
+ if ( card -> gf1.effects && card -> gf1.effects -> chip_type == ULTRA_EFFECT_CHIP_INTERWAVE )
+ return card -> gf1.effects -> chip.interwave.voice_output[ value ];
+ return 0;
+}
+
+#endif
+
+static void sample_private1(snd_gus_card_t *card, snd_gus_voice_t *voice, unsigned char *data)
+{
+#if 0
+ unsigned long flags;
+ unsigned char uc;
+
+ switch ( *data ) {
+ case ULTRA_PRIV1_IW_EFFECT:
+ uc = get_effects_mask( card, ultra_get_byte( data, 4 ) );
+ uc |= get_effects_mask( card, ultra_get_byte( data, 4 ) >> 4 );
+ uc |= get_effects_mask( card, ultra_get_byte( data, 5 ) );
+ uc |= get_effects_mask( card, ultra_get_byte( data, 5 ) >> 4 );
+ voice -> data.simple.effect_accumulator = uc;
+ voice -> data.simple.effect_volume = ultra_translate_voice_volume( card, ultra_get_word( data, 2 ) ) << 4;
+ if ( !card -> gf1.enh_mode ) return;
+ if ( voice -> flags & VFLG_WAIT_FOR_START ) return;
+ if ( voice -> flags & VFLG_RUNNING )
+ {
+ CLI( &flags );
+ gf1_select_voice( card, voice -> number );
+ ultra_write8( card, GF1_VB_ACCUMULATOR, voice -> data.simple.effect_accumulator );
+ ultra_write16( card, GF1_VW_EFFECT_VOLUME_FINAL, voice -> data.simple.effect_volume );
+ STI( &flags );
+ }
+ break;
+ case ULTRA_PRIV1_IW_LFO:
+ ultra_lfo_command( card, voice -> number, data );
+ }
+#endif
+}
+
+#if 0
+
+/*
+ *
+ */
+
+static void note_stop( ultra_card_t *card, ultra_voice_t *voice, int wait )
+{
+}
+
+static void note_wait( ultra_card_t *card, ultra_voice_t *voice )
+{
+}
+
+static void note_off( ultra_card_t *card, ultra_voice_t *voice )
+{
+}
+
+static void note_volume( ultra_card_t *card, ultra_voice_t *voice )
+{
+}
+
+static void note_pitchbend( ultra_card_t *card, ultra_voice_t *voice )
+{
+}
+
+static void note_vibrato( ultra_card_t *card, ultra_voice_t *voice )
+{
+}
+
+static void note_tremolo( ultra_card_t *card, ultra_voice_t *voice )
+{
+}
+
+/*
+ *
+ */
+
+static void chn_trigger_down( ultra_card_t *card, ultra_channel_t *channel, ultra_instrument_t *instrument, unsigned char note, unsigned char velocity, unsigned char priority )
+{
+}
+
+static void chn_trigger_up( ultra_card_t *card, ultra_note_t *note )
+{
+}
+
+static void chn_control( ultra_card_t *card, ultra_channel_t *channel, unsigned short p1, unsigned short p2 )
+{
+}
+
+/*
+ *
+ */
+
+#endif
+
+void snd_gf1_simple_init(snd_gus_voice_t *voice)
+{
+ voice->handler_wave = interrupt_wave;
+ voice->handler_volume = interrupt_volume;
+ voice->handler_effect = interrupt_effect;
+ voice->volume_change = NULL;
+ voice->sample_ops = &sample_ops;
+}
diff --git a/sound/isa/gus/gus_synth.c b/sound/isa/gus/gus_synth.c
new file mode 100644
index 000000000000..66552e6013a4
--- /dev/null
+++ b/sound/isa/gus/gus_synth.c
@@ -0,0 +1,329 @@
+/*
+ * Routines for Gravis UltraSound soundcards - Synthesizer
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/init.h>
+#include <linux/time.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+#include <sound/seq_device.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("Routines for Gravis UltraSound soundcards - Synthesizer");
+MODULE_LICENSE("GPL");
+
+/*
+ *
+ */
+
+static void snd_gus_synth_free_voices(snd_gus_card_t * gus, int client, int port)
+{
+ int idx;
+ snd_gus_voice_t * voice;
+
+ for (idx = 0; idx < 32; idx++) {
+ voice = &gus->gf1.voices[idx];
+ if (voice->use && voice->client == client && voice->port == port)
+ snd_gf1_free_voice(gus, voice);
+ }
+}
+
+static int snd_gus_synth_use(void *private_data, snd_seq_port_subscribe_t *info)
+{
+ snd_gus_port_t * port = (snd_gus_port_t *)private_data;
+ snd_gus_card_t * gus = port->gus;
+ snd_gus_voice_t * voice;
+ unsigned int idx;
+
+ if (info->voices > 32)
+ return -EINVAL;
+ down(&gus->register_mutex);
+ if (!snd_gus_use_inc(gus)) {
+ up(&gus->register_mutex);
+ return -EFAULT;
+ }
+ for (idx = 0; idx < info->voices; idx++) {
+ voice = snd_gf1_alloc_voice(gus, SNDRV_GF1_VOICE_TYPE_SYNTH, info->sender.client, info->sender.port);
+ if (voice == NULL) {
+ snd_gus_synth_free_voices(gus, info->sender.client, info->sender.port);
+ snd_gus_use_dec(gus);
+ up(&gus->register_mutex);
+ return -EBUSY;
+ }
+ voice->index = idx;
+ }
+ up(&gus->register_mutex);
+ return 0;
+}
+
+static int snd_gus_synth_unuse(void *private_data, snd_seq_port_subscribe_t *info)
+{
+ snd_gus_port_t * port = (snd_gus_port_t *)private_data;
+ snd_gus_card_t * gus = port->gus;
+
+ down(&gus->register_mutex);
+ snd_gus_synth_free_voices(gus, info->sender.client, info->sender.port);
+ snd_gus_use_dec(gus);
+ up(&gus->register_mutex);
+ return 0;
+}
+
+/*
+ *
+ */
+
+static void snd_gus_synth_free_private_instruments(snd_gus_port_t *p, int client)
+{
+ snd_seq_instr_header_t ifree;
+
+ memset(&ifree, 0, sizeof(ifree));
+ ifree.cmd = SNDRV_SEQ_INSTR_FREE_CMD_PRIVATE;
+ snd_seq_instr_list_free_cond(p->gus->gf1.ilist, &ifree, client, 0);
+}
+
+int snd_gus_synth_event_input(snd_seq_event_t *ev, int direct, void *private_data, int atomic, int hop)
+{
+ snd_gus_port_t * p = (snd_gus_port_t *) private_data;
+
+ snd_assert(p != NULL, return -EINVAL);
+ if (ev->type >= SNDRV_SEQ_EVENT_SAMPLE &&
+ ev->type <= SNDRV_SEQ_EVENT_SAMPLE_PRIVATE1) {
+ snd_gus_sample_event(ev, p);
+ return 0;
+ }
+ if (ev->source.client == SNDRV_SEQ_CLIENT_SYSTEM &&
+ ev->source.port == SNDRV_SEQ_PORT_SYSTEM_ANNOUNCE) {
+ if (ev->type == SNDRV_SEQ_EVENT_CLIENT_EXIT) {
+ snd_gus_synth_free_private_instruments(p, ev->data.addr.client);
+ return 0;
+ }
+ }
+ if (direct) {
+ if (ev->type >= SNDRV_SEQ_EVENT_INSTR_BEGIN) {
+ snd_seq_instr_event(&p->gus->gf1.iwffff_ops.kops,
+ p->gus->gf1.ilist,
+ ev,
+ p->gus->gf1.seq_client,
+ atomic, hop);
+ return 0;
+ }
+ }
+ return 0;
+}
+
+static void snd_gus_synth_instr_notify(void *private_data,
+ snd_seq_kinstr_t *instr,
+ int what)
+{
+ unsigned int idx;
+ snd_gus_card_t *gus = private_data;
+ snd_gus_voice_t *pvoice;
+ unsigned long flags;
+
+ spin_lock_irqsave(&gus->event_lock, flags);
+ for (idx = 0; idx < 32; idx++) {
+ pvoice = &gus->gf1.voices[idx];
+ if (pvoice->use && !memcmp(&pvoice->instr, &instr->instr, sizeof(pvoice->instr))) {
+ if (pvoice->sample_ops && pvoice->sample_ops->sample_stop) {
+ pvoice->sample_ops->sample_stop(gus, pvoice, SAMPLE_STOP_IMMEDIATELY);
+ } else {
+ snd_gf1_stop_voice(gus, pvoice->number);
+ pvoice->flags &= ~SNDRV_GF1_VFLG_RUNNING;
+ }
+ }
+ }
+ spin_unlock_irqrestore(&gus->event_lock, flags);
+}
+
+/*
+ *
+ */
+
+static void snd_gus_synth_free_port(void *private_data)
+{
+ snd_gus_port_t * p = (snd_gus_port_t *)private_data;
+
+ if (p)
+ snd_midi_channel_free_set(p->chset);
+}
+
+static int snd_gus_synth_create_port(snd_gus_card_t * gus, int idx)
+{
+ snd_gus_port_t * p;
+ snd_seq_port_callback_t callbacks;
+ char name[32];
+ int result;
+
+ p = &gus->gf1.seq_ports[idx];
+ p->chset = snd_midi_channel_alloc_set(16);
+ if (p->chset == NULL)
+ return -ENOMEM;
+ p->chset->private_data = p;
+ p->gus = gus;
+ p->client = gus->gf1.seq_client;
+
+ memset(&callbacks, 0, sizeof(callbacks));
+ callbacks.owner = THIS_MODULE;
+ callbacks.use = snd_gus_synth_use;
+ callbacks.unuse = snd_gus_synth_unuse;
+ callbacks.event_input = snd_gus_synth_event_input;
+ callbacks.private_free = snd_gus_synth_free_port;
+ callbacks.private_data = p;
+
+ sprintf(name, "%s port %i", gus->interwave ? "AMD InterWave" : "GF1", idx);
+ p->chset->port = snd_seq_event_port_attach(gus->gf1.seq_client,
+ &callbacks,
+ SNDRV_SEQ_PORT_CAP_WRITE | SNDRV_SEQ_PORT_CAP_SUBS_WRITE,
+ SNDRV_SEQ_PORT_TYPE_DIRECT_SAMPLE |
+ SNDRV_SEQ_PORT_TYPE_SYNTH,
+ 16, 0,
+ name);
+ if (p->chset->port < 0) {
+ result = p->chset->port;
+ snd_gus_synth_free_port(p);
+ return result;
+ }
+ p->port = p->chset->port;
+ return 0;
+}
+
+/*
+ *
+ */
+
+static int snd_gus_synth_new_device(snd_seq_device_t *dev)
+{
+ snd_gus_card_t *gus;
+ int client, i;
+ snd_seq_client_callback_t callbacks;
+ snd_seq_client_info_t *cinfo;
+ snd_seq_port_subscribe_t sub;
+ snd_iwffff_ops_t *iwops;
+ snd_gf1_ops_t *gf1ops;
+ snd_simple_ops_t *simpleops;
+
+ gus = *(snd_gus_card_t**)SNDRV_SEQ_DEVICE_ARGPTR(dev);
+ if (gus == NULL)
+ return -EINVAL;
+
+ init_MUTEX(&gus->register_mutex);
+ gus->gf1.seq_client = -1;
+
+ cinfo = kmalloc(sizeof(*cinfo), GFP_KERNEL);
+ if (! cinfo)
+ return -ENOMEM;
+
+ /* allocate new client */
+ memset(&callbacks, 0, sizeof(callbacks));
+ callbacks.private_data = gus;
+ callbacks.allow_output = callbacks.allow_input = 1;
+ client = gus->gf1.seq_client =
+ snd_seq_create_kernel_client(gus->card, 1, &callbacks);
+ if (client < 0) {
+ kfree(cinfo);
+ return client;
+ }
+
+ /* change name of client */
+ memset(cinfo, 0, sizeof(*cinfo));
+ cinfo->client = client;
+ cinfo->type = KERNEL_CLIENT;
+ sprintf(cinfo->name, gus->interwave ? "AMD InterWave" : "GF1");
+ snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, cinfo);
+ kfree(cinfo);
+
+ for (i = 0; i < 4; i++)
+ snd_gus_synth_create_port(gus, i);
+
+ gus->gf1.ilist = snd_seq_instr_list_new();
+ if (gus->gf1.ilist == NULL) {
+ snd_seq_delete_kernel_client(client);
+ gus->gf1.seq_client = -1;
+ return -ENOMEM;
+ }
+ gus->gf1.ilist->flags = SNDRV_SEQ_INSTR_FLG_DIRECT;
+
+ simpleops = &gus->gf1.simple_ops;
+ snd_seq_simple_init(simpleops, gus, NULL);
+ simpleops->put_sample = snd_gus_simple_put_sample;
+ simpleops->get_sample = snd_gus_simple_get_sample;
+ simpleops->remove_sample = snd_gus_simple_remove_sample;
+ simpleops->notify = snd_gus_synth_instr_notify;
+
+ gf1ops = &gus->gf1.gf1_ops;
+ snd_seq_gf1_init(gf1ops, gus, &simpleops->kops);
+ gf1ops->put_sample = snd_gus_gf1_put_sample;
+ gf1ops->get_sample = snd_gus_gf1_get_sample;
+ gf1ops->remove_sample = snd_gus_gf1_remove_sample;
+ gf1ops->notify = snd_gus_synth_instr_notify;
+
+ iwops = &gus->gf1.iwffff_ops;
+ snd_seq_iwffff_init(iwops, gus, &gf1ops->kops);
+ iwops->put_sample = snd_gus_iwffff_put_sample;
+ iwops->get_sample = snd_gus_iwffff_get_sample;
+ iwops->remove_sample = snd_gus_iwffff_remove_sample;
+ iwops->notify = snd_gus_synth_instr_notify;
+
+ memset(&sub, 0, sizeof(sub));
+ sub.sender.client = SNDRV_SEQ_CLIENT_SYSTEM;
+ sub.sender.port = SNDRV_SEQ_PORT_SYSTEM_ANNOUNCE;
+ sub.dest.client = client;
+ sub.dest.port = 0;
+ snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT, &sub);
+
+ return 0;
+}
+
+static int snd_gus_synth_delete_device(snd_seq_device_t *dev)
+{
+ snd_gus_card_t *gus;
+
+ gus = *(snd_gus_card_t**)SNDRV_SEQ_DEVICE_ARGPTR(dev);
+ if (gus == NULL)
+ return -EINVAL;
+
+ if (gus->gf1.seq_client >= 0) {
+ snd_seq_delete_kernel_client(gus->gf1.seq_client);
+ gus->gf1.seq_client = -1;
+ }
+ if (gus->gf1.ilist)
+ snd_seq_instr_list_free(&gus->gf1.ilist);
+ return 0;
+}
+
+static int __init alsa_gus_synth_init(void)
+{
+ static snd_seq_dev_ops_t ops = {
+ snd_gus_synth_new_device,
+ snd_gus_synth_delete_device
+ };
+
+ return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_GUS, &ops,
+ sizeof(snd_gus_card_t*));
+}
+
+static void __exit alsa_gus_synth_exit(void)
+{
+ snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_GUS);
+}
+
+module_init(alsa_gus_synth_init)
+module_exit(alsa_gus_synth_exit)
diff --git a/sound/isa/gus/gus_tables.h b/sound/isa/gus/gus_tables.h
new file mode 100644
index 000000000000..ed8e9d85ad31
--- /dev/null
+++ b/sound/isa/gus/gus_tables.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#define SNDRV_GF1_SCALE_TABLE_SIZE 128
+#define SNDRV_GF1_ATTEN_TABLE_SIZE 128
+
+#ifdef __GUS_TABLES_ALLOC__
+
+unsigned int snd_gf1_scale_table[SNDRV_GF1_SCALE_TABLE_SIZE] =
+{
+ 8372, 8870, 9397, 9956, 10548, 11175,
+ 11840, 12544, 13290, 14080, 14917, 15804,
+ 16744, 17740, 18795, 19912, 21096, 22351,
+ 23680, 25088, 26580, 28160, 29834, 31609,
+ 33488, 35479, 37589, 39824, 42192, 44701,
+ 47359, 50175, 53159, 56320, 59669, 63217,
+ 66976, 70959, 75178, 79649, 84385, 89402,
+ 94719, 100351, 106318, 112640, 119338, 126434,
+ 133952, 141918, 150356, 159297, 168769, 178805,
+ 189437, 200702, 212636, 225280, 238676, 252868,
+ 267905, 283835, 300713, 318594, 337539, 357610,
+ 378874, 401403, 425272, 450560, 477352, 505737,
+ 535809, 567670, 601425, 637188, 675077, 715219,
+ 757749, 802807, 850544, 901120, 954703, 1011473,
+ 1071618, 1135340, 1202851, 1274376, 1350154, 1430439,
+ 1515497, 1605613, 1701088, 1802240, 1909407, 2022946,
+ 2143237, 2270680, 2405702, 2548752, 2700309, 2860878,
+ 3030994, 3211227, 3402176, 3604480, 3818814, 4045892,
+ 4286473, 4541360, 4811404, 5097505, 5400618, 5721755,
+ 6061989, 6422453, 6804352, 7208960, 7637627, 8091784,
+ 8572947, 9082720, 9622807, 10195009, 10801236, 11443511,
+ 12123977, 12844906
+};
+
+unsigned short snd_gf1_atten_table[SNDRV_GF1_ATTEN_TABLE_SIZE] = {
+ 4095 /* 0 */,1789 /* 1 */,1533 /* 2 */,1383 /* 3 */,1277 /* 4 */,
+ 1195 /* 5 */,1127 /* 6 */,1070 /* 7 */,1021 /* 8 */,978 /* 9 */,
+ 939 /* 10 */,903 /* 11 */,871 /* 12 */,842 /* 13 */,814 /* 14 */,
+ 789 /* 15 */,765 /* 16 */,743 /* 17 */,722 /* 18 */,702 /* 19 */,
+ 683 /* 20 */,665 /* 21 */,647 /* 22 */,631 /* 23 */,615 /* 24 */,
+ 600 /* 25 */,586 /* 26 */,572 /* 27 */,558 /* 28 */,545 /* 29 */,
+ 533 /* 30 */,521 /* 31 */,509 /* 32 */,498 /* 33 */,487 /* 34 */,
+ 476 /* 35 */,466 /* 36 */,455 /* 37 */,446 /* 38 */,436 /* 39 */,
+ 427 /* 40 */,418 /* 41 */,409 /* 42 */,400 /* 43 */,391 /* 44 */,
+ 383 /* 45 */,375 /* 46 */,367 /* 47 */,359 /* 48 */,352 /* 49 */,
+ 344 /* 50 */,337 /* 51 */,330 /* 52 */,323 /* 53 */,316 /* 54 */,
+ 309 /* 55 */,302 /* 56 */,296 /* 57 */,289 /* 58 */,283 /* 59 */,
+ 277 /* 60 */,271 /* 61 */,265 /* 62 */,259 /* 63 */,253 /* 64 */,
+ 247 /* 65 */,242 /* 66 */,236 /* 67 */,231 /* 68 */,225 /* 69 */,
+ 220 /* 70 */,215 /* 71 */,210 /* 72 */,205 /* 73 */,199 /* 74 */,
+ 195 /* 75 */,190 /* 76 */,185 /* 77 */,180 /* 78 */,175 /* 79 */,
+ 171 /* 80 */,166 /* 81 */,162 /* 82 */,157 /* 83 */,153 /* 84 */,
+ 148 /* 85 */,144 /* 86 */,140 /* 87 */,135 /* 88 */,131 /* 89 */,
+ 127 /* 90 */,123 /* 91 */,119 /* 92 */,115 /* 93 */,111 /* 94 */,
+ 107 /* 95 */,103 /* 96 */,100 /* 97 */,96 /* 98 */,92 /* 99 */,
+ 88 /* 100 */,85 /* 101 */,81 /* 102 */,77 /* 103 */,74 /* 104 */,
+ 70 /* 105 */,67 /* 106 */,63 /* 107 */,60 /* 108 */,56 /* 109 */,
+ 53 /* 110 */,50 /* 111 */,46 /* 112 */,43 /* 113 */,40 /* 114 */,
+ 37 /* 115 */,33 /* 116 */,30 /* 117 */,27 /* 118 */,24 /* 119 */,
+ 21 /* 120 */,18 /* 121 */,15 /* 122 */,12 /* 123 */,9 /* 124 */,
+ 6 /* 125 */,3 /* 126 */,0 /* 127 */,
+};
+
+#else
+
+extern unsigned int snd_gf1_scale_table[SNDRV_GF1_SCALE_TABLE_SIZE];
+extern unsigned short snd_gf1_atten_table[SNDRV_GF1_ATTEN_TABLE_SIZE];
+
+#endif
diff --git a/sound/isa/gus/gus_timer.c b/sound/isa/gus/gus_timer.c
new file mode 100644
index 000000000000..9876603ff6c1
--- /dev/null
+++ b/sound/isa/gus/gus_timer.c
@@ -0,0 +1,204 @@
+/*
+ * Routines for Gravis UltraSound soundcards - Timers
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ * GUS have similar timers as AdLib (OPL2/OPL3 chips).
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/time.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+
+/*
+ * Timer 1 - 80us
+ */
+
+static int snd_gf1_timer1_start(snd_timer_t * timer)
+{
+ unsigned long flags;
+ unsigned char tmp;
+ unsigned int ticks;
+ snd_gus_card_t *gus;
+
+ gus = snd_timer_chip(timer);
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ ticks = timer->sticks;
+ tmp = (gus->gf1.timer_enabled |= 4);
+ snd_gf1_write8(gus, SNDRV_GF1_GB_ADLIB_TIMER_1, 256 - ticks); /* timer 1 count */
+ snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, tmp); /* enable timer 1 IRQ */
+ snd_gf1_adlib_write(gus, 0x04, tmp >> 2); /* timer 2 start */
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return 0;
+}
+
+static int snd_gf1_timer1_stop(snd_timer_t * timer)
+{
+ unsigned long flags;
+ unsigned char tmp;
+ snd_gus_card_t *gus;
+
+ gus = snd_timer_chip(timer);
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ tmp = (gus->gf1.timer_enabled &= ~4);
+ snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, tmp); /* disable timer #1 */
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return 0;
+}
+
+/*
+ * Timer 2 - 320us
+ */
+
+static int snd_gf1_timer2_start(snd_timer_t * timer)
+{
+ unsigned long flags;
+ unsigned char tmp;
+ unsigned int ticks;
+ snd_gus_card_t *gus;
+
+ gus = snd_timer_chip(timer);
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ ticks = timer->sticks;
+ tmp = (gus->gf1.timer_enabled |= 8);
+ snd_gf1_write8(gus, SNDRV_GF1_GB_ADLIB_TIMER_2, 256 - ticks); /* timer 2 count */
+ snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, tmp); /* enable timer 2 IRQ */
+ snd_gf1_adlib_write(gus, 0x04, tmp >> 2); /* timer 2 start */
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return 0;
+}
+
+static int snd_gf1_timer2_stop(snd_timer_t * timer)
+{
+ unsigned long flags;
+ unsigned char tmp;
+ snd_gus_card_t *gus;
+
+ gus = snd_timer_chip(timer);
+ spin_lock_irqsave(&gus->reg_lock, flags);
+ tmp = (gus->gf1.timer_enabled &= ~8);
+ snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, tmp); /* disable timer #1 */
+ spin_unlock_irqrestore(&gus->reg_lock, flags);
+ return 0;
+}
+
+/*
+
+ */
+
+static void snd_gf1_interrupt_timer1(snd_gus_card_t * gus)
+{
+ snd_timer_t *timer = gus->gf1.timer1;
+
+ if (timer == NULL)
+ return;
+ snd_timer_interrupt(timer, timer->sticks);
+}
+
+static void snd_gf1_interrupt_timer2(snd_gus_card_t * gus)
+{
+ snd_timer_t *timer = gus->gf1.timer2;
+
+ if (timer == NULL)
+ return;
+ snd_timer_interrupt(timer, timer->sticks);
+}
+
+/*
+
+ */
+
+static struct _snd_timer_hardware snd_gf1_timer1 =
+{
+ .flags = SNDRV_TIMER_HW_STOP,
+ .resolution = 80000,
+ .ticks = 256,
+ .start = snd_gf1_timer1_start,
+ .stop = snd_gf1_timer1_stop,
+};
+
+static struct _snd_timer_hardware snd_gf1_timer2 =
+{
+ .flags = SNDRV_TIMER_HW_STOP,
+ .resolution = 320000,
+ .ticks = 256,
+ .start = snd_gf1_timer2_start,
+ .stop = snd_gf1_timer2_stop,
+};
+
+static void snd_gf1_timer1_free(snd_timer_t *timer)
+{
+ snd_gus_card_t *gus = timer->private_data;
+ gus->gf1.timer1 = NULL;
+}
+
+static void snd_gf1_timer2_free(snd_timer_t *timer)
+{
+ snd_gus_card_t *gus = timer->private_data;
+ gus->gf1.timer2 = NULL;
+}
+
+void snd_gf1_timers_init(snd_gus_card_t * gus)
+{
+ snd_timer_t *timer;
+ snd_timer_id_t tid;
+
+ if (gus->gf1.timer1 != NULL || gus->gf1.timer2 != NULL)
+ return;
+
+ gus->gf1.interrupt_handler_timer1 = snd_gf1_interrupt_timer1;
+ gus->gf1.interrupt_handler_timer2 = snd_gf1_interrupt_timer2;
+
+ tid.dev_class = SNDRV_TIMER_CLASS_CARD;
+ tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
+ tid.card = gus->card->number;
+ tid.device = gus->timer_dev;
+ tid.subdevice = 0;
+
+ if (snd_timer_new(gus->card, "GF1 timer", &tid, &timer) >= 0) {
+ strcpy(timer->name, "GF1 timer #1");
+ timer->private_data = gus;
+ timer->private_free = snd_gf1_timer1_free;
+ timer->hw = snd_gf1_timer1;
+ }
+ gus->gf1.timer1 = timer;
+
+ tid.device++;
+
+ if (snd_timer_new(gus->card, "GF1 timer", &tid, &timer) >= 0) {
+ strcpy(timer->name, "GF1 timer #2");
+ timer->private_data = gus;
+ timer->private_free = snd_gf1_timer2_free;
+ timer->hw = snd_gf1_timer2;
+ }
+ gus->gf1.timer2 = timer;
+}
+
+void snd_gf1_timers_done(snd_gus_card_t * gus)
+{
+ snd_gf1_set_default_handlers(gus, SNDRV_GF1_HANDLER_TIMER1 | SNDRV_GF1_HANDLER_TIMER2);
+ if (gus->gf1.timer1) {
+ snd_device_free(gus->card, gus->gf1.timer1);
+ gus->gf1.timer1 = NULL;
+ }
+ if (gus->gf1.timer2) {
+ snd_device_free(gus->card, gus->gf1.timer2);
+ gus->gf1.timer2 = NULL;
+ }
+}
diff --git a/sound/isa/gus/gus_uart.c b/sound/isa/gus/gus_uart.c
new file mode 100644
index 000000000000..1bc2da8784e0
--- /dev/null
+++ b/sound/isa/gus/gus_uart.c
@@ -0,0 +1,257 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ * Routines for the GF1 MIDI interface - like UART 6850
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/time.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+
+static void snd_gf1_interrupt_midi_in(snd_gus_card_t * gus)
+{
+ int count;
+ unsigned char stat, data, byte;
+ unsigned long flags;
+
+ count = 10;
+ while (count) {
+ spin_lock_irqsave(&gus->uart_cmd_lock, flags);
+ stat = snd_gf1_uart_stat(gus);
+ if (!(stat & 0x01)) { /* data in Rx FIFO? */
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+ count--;
+ continue;
+ }
+ count = 100; /* arm counter to new value */
+ data = snd_gf1_uart_get(gus);
+ if (!(gus->gf1.uart_cmd & 0x80)) {
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+ continue;
+ }
+ if (stat & 0x10) { /* framing error */
+ gus->gf1.uart_framing++;
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+ continue;
+ }
+ byte = snd_gf1_uart_get(gus);
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+ snd_rawmidi_receive(gus->midi_substream_input, &byte, 1);
+ if (stat & 0x20) {
+ gus->gf1.uart_overrun++;
+ }
+ }
+}
+
+static void snd_gf1_interrupt_midi_out(snd_gus_card_t * gus)
+{
+ char byte;
+ unsigned long flags;
+
+ /* try unlock output */
+ if (snd_gf1_uart_stat(gus) & 0x01)
+ snd_gf1_interrupt_midi_in(gus);
+
+ spin_lock_irqsave(&gus->uart_cmd_lock, flags);
+ if (snd_gf1_uart_stat(gus) & 0x02) { /* Tx FIFO free? */
+ if (snd_rawmidi_transmit(gus->midi_substream_output, &byte, 1) != 1) { /* no other bytes or error */
+ snd_gf1_uart_cmd(gus, gus->gf1.uart_cmd & ~0x20); /* disable Tx interrupt */
+ } else {
+ snd_gf1_uart_put(gus, byte);
+ }
+ }
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+}
+
+static void snd_gf1_uart_reset(snd_gus_card_t * gus, int close)
+{
+ snd_gf1_uart_cmd(gus, 0x03); /* reset */
+ if (!close && gus->uart_enable) {
+ udelay(160);
+ snd_gf1_uart_cmd(gus, 0x00); /* normal operations */
+ }
+}
+
+static int snd_gf1_uart_output_open(snd_rawmidi_substream_t * substream)
+{
+ unsigned long flags;
+ snd_gus_card_t *gus;
+
+ gus = substream->rmidi->private_data;
+ spin_lock_irqsave(&gus->uart_cmd_lock, flags);
+ if (!(gus->gf1.uart_cmd & 0x80)) { /* input active? */
+ snd_gf1_uart_reset(gus, 0);
+ }
+ gus->gf1.interrupt_handler_midi_out = snd_gf1_interrupt_midi_out;
+ gus->midi_substream_output = substream;
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+#if 0
+ snd_printk("write init - cmd = 0x%x, stat = 0x%x\n", gus->gf1.uart_cmd, snd_gf1_uart_stat(gus));
+#endif
+ return 0;
+}
+
+static int snd_gf1_uart_input_open(snd_rawmidi_substream_t * substream)
+{
+ unsigned long flags;
+ snd_gus_card_t *gus;
+ int i;
+
+ gus = substream->rmidi->private_data;
+ spin_lock_irqsave(&gus->uart_cmd_lock, flags);
+ if (gus->gf1.interrupt_handler_midi_out != snd_gf1_interrupt_midi_out) {
+ snd_gf1_uart_reset(gus, 0);
+ }
+ gus->gf1.interrupt_handler_midi_in = snd_gf1_interrupt_midi_in;
+ gus->midi_substream_input = substream;
+ if (gus->uart_enable) {
+ for (i = 0; i < 1000 && (snd_gf1_uart_stat(gus) & 0x01); i++)
+ snd_gf1_uart_get(gus); /* clean Rx */
+ if (i >= 1000)
+ snd_printk("gus midi uart init read - cleanup error\n");
+ }
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+#if 0
+ snd_printk("read init - enable = %i, cmd = 0x%x, stat = 0x%x\n", gus->uart_enable, gus->gf1.uart_cmd, snd_gf1_uart_stat(gus));
+ snd_printk("[0x%x] reg (ctrl/status) = 0x%x, reg (data) = 0x%x (page = 0x%x)\n", gus->gf1.port + 0x100, inb(gus->gf1.port + 0x100), inb(gus->gf1.port + 0x101), inb(gus->gf1.port + 0x102));
+#endif
+ return 0;
+}
+
+static int snd_gf1_uart_output_close(snd_rawmidi_substream_t * substream)
+{
+ unsigned long flags;
+ snd_gus_card_t *gus;
+
+ gus = substream->rmidi->private_data;
+ spin_lock_irqsave(&gus->uart_cmd_lock, flags);
+ if (gus->gf1.interrupt_handler_midi_in != snd_gf1_interrupt_midi_in)
+ snd_gf1_uart_reset(gus, 1);
+ snd_gf1_set_default_handlers(gus, SNDRV_GF1_HANDLER_MIDI_OUT);
+ gus->midi_substream_output = NULL;
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+ return 0;
+}
+
+static int snd_gf1_uart_input_close(snd_rawmidi_substream_t * substream)
+{
+ unsigned long flags;
+ snd_gus_card_t *gus;
+
+ gus = substream->rmidi->private_data;
+ spin_lock_irqsave(&gus->uart_cmd_lock, flags);
+ if (gus->gf1.interrupt_handler_midi_out != snd_gf1_interrupt_midi_out)
+ snd_gf1_uart_reset(gus, 1);
+ snd_gf1_set_default_handlers(gus, SNDRV_GF1_HANDLER_MIDI_IN);
+ gus->midi_substream_input = NULL;
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+ return 0;
+}
+
+static void snd_gf1_uart_input_trigger(snd_rawmidi_substream_t * substream, int up)
+{
+ snd_gus_card_t *gus;
+ unsigned long flags;
+
+ gus = substream->rmidi->private_data;
+
+ spin_lock_irqsave(&gus->uart_cmd_lock, flags);
+ if (up) {
+ if ((gus->gf1.uart_cmd & 0x80) == 0)
+ snd_gf1_uart_cmd(gus, gus->gf1.uart_cmd | 0x80); /* enable Rx interrupts */
+ } else {
+ if (gus->gf1.uart_cmd & 0x80)
+ snd_gf1_uart_cmd(gus, gus->gf1.uart_cmd & ~0x80); /* disable Rx interrupts */
+ }
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+}
+
+static void snd_gf1_uart_output_trigger(snd_rawmidi_substream_t * substream, int up)
+{
+ unsigned long flags;
+ snd_gus_card_t *gus;
+ char byte;
+ int timeout;
+
+ gus = substream->rmidi->private_data;
+
+ spin_lock_irqsave(&gus->uart_cmd_lock, flags);
+ if (up) {
+ if ((gus->gf1.uart_cmd & 0x20) == 0) {
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+ /* wait for empty Rx - Tx is probably unlocked */
+ timeout = 10000;
+ while (timeout-- > 0 && snd_gf1_uart_stat(gus) & 0x01);
+ /* Tx FIFO free? */
+ spin_lock_irqsave(&gus->uart_cmd_lock, flags);
+ if (gus->gf1.uart_cmd & 0x20) {
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+ return;
+ }
+ if (snd_gf1_uart_stat(gus) & 0x02) {
+ if (snd_rawmidi_transmit(substream, &byte, 1) != 1) {
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+ return;
+ }
+ snd_gf1_uart_put(gus, byte);
+ }
+ snd_gf1_uart_cmd(gus, gus->gf1.uart_cmd | 0x20); /* enable Tx interrupt */
+ }
+ } else {
+ if (gus->gf1.uart_cmd & 0x20)
+ snd_gf1_uart_cmd(gus, gus->gf1.uart_cmd & ~0x20);
+ }
+ spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
+}
+
+static snd_rawmidi_ops_t snd_gf1_uart_output =
+{
+ .open = snd_gf1_uart_output_open,
+ .close = snd_gf1_uart_output_close,
+ .trigger = snd_gf1_uart_output_trigger,
+};
+
+static snd_rawmidi_ops_t snd_gf1_uart_input =
+{
+ .open = snd_gf1_uart_input_open,
+ .close = snd_gf1_uart_input_close,
+ .trigger = snd_gf1_uart_input_trigger,
+};
+
+int snd_gf1_rawmidi_new(snd_gus_card_t * gus, int device, snd_rawmidi_t ** rrawmidi)
+{
+ snd_rawmidi_t *rmidi;
+ int err;
+
+ if (rrawmidi)
+ *rrawmidi = NULL;
+ if ((err = snd_rawmidi_new(gus->card, "GF1", device, 1, 1, &rmidi)) < 0)
+ return err;
+ strcpy(rmidi->name, gus->interwave ? "AMD InterWave" : "GF1");
+ snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_gf1_uart_output);
+ snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_gf1_uart_input);
+ rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX;
+ rmidi->private_data = gus;
+ gus->midi_uart = rmidi;
+ if (rrawmidi)
+ *rrawmidi = rmidi;
+ return err;
+}
diff --git a/sound/isa/gus/gus_volume.c b/sound/isa/gus/gus_volume.c
new file mode 100644
index 000000000000..b72bcfb28617
--- /dev/null
+++ b/sound/isa/gus/gus_volume.c
@@ -0,0 +1,210 @@
+/*
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <linux/time.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+#define __GUS_TABLES_ALLOC__
+#include "gus_tables.h"
+
+EXPORT_SYMBOL(snd_gf1_atten_table); /* for snd-gus-synth module */
+
+unsigned short snd_gf1_lvol_to_gvol_raw(unsigned int vol)
+{
+ unsigned short e, m, tmp;
+
+ if (vol > 65535)
+ vol = 65535;
+ tmp = vol;
+ e = 7;
+ if (tmp < 128) {
+ while (e > 0 && tmp < (1 << e))
+ e--;
+ } else {
+ while (tmp > 255) {
+ tmp >>= 1;
+ e++;
+ }
+ }
+ m = vol - (1 << e);
+ if (m > 0) {
+ if (e > 8)
+ m >>= e - 8;
+ else if (e < 8)
+ m <<= 8 - e;
+ m &= 255;
+ }
+ return (e << 8) | m;
+}
+
+unsigned int snd_gf1_gvol_to_lvol_raw(unsigned short gf1_vol)
+{
+ unsigned int rvol;
+ unsigned short e, m;
+
+ if (!gf1_vol)
+ return 0;
+ e = gf1_vol >> 8;
+ m = (unsigned char) gf1_vol;
+ rvol = 1 << e;
+ if (e > 8)
+ return rvol | (m << (e - 8));
+ return rvol | (m >> (8 - e));
+}
+
+unsigned int snd_gf1_calc_ramp_rate(snd_gus_card_t * gus,
+ unsigned short start,
+ unsigned short end,
+ unsigned int us)
+{
+ static unsigned char vol_rates[19] =
+ {
+ 23, 24, 26, 28, 29, 31, 32, 34,
+ 36, 37, 39, 40, 42, 44, 45, 47,
+ 49, 50, 52
+ };
+ unsigned short range, increment, value, i;
+
+ start >>= 4;
+ end >>= 4;
+ if (start < end)
+ us /= end - start;
+ else
+ us /= start - end;
+ range = 4;
+ value = gus->gf1.enh_mode ?
+ vol_rates[0] :
+ vol_rates[gus->gf1.active_voices - 14];
+ for (i = 0; i < 3; i++) {
+ if (us < value) {
+ range = i;
+ break;
+ } else
+ value <<= 3;
+ }
+ if (range == 4) {
+ range = 3;
+ increment = 1;
+ } else
+ increment = (value + (value >> 1)) / us;
+ return (range << 6) | (increment & 0x3f);
+}
+
+unsigned short snd_gf1_translate_freq(snd_gus_card_t * gus, unsigned int freq16)
+{
+ freq16 >>= 3;
+ if (freq16 < 50)
+ freq16 = 50;
+ if (freq16 & 0xf8000000) {
+ freq16 = ~0xf8000000;
+ snd_printk("snd_gf1_translate_freq: overflow - freq = 0x%x\n", freq16);
+ }
+ return ((freq16 << 9) + (gus->gf1.playback_freq >> 1)) / gus->gf1.playback_freq;
+}
+
+short snd_gf1_compute_vibrato(short cents, unsigned short fc_register)
+{
+ static short vibrato_table[] =
+ {
+ 0, 0, 32, 592, 61, 1175, 93, 1808,
+ 124, 2433, 152, 3007, 182, 3632, 213, 4290,
+ 241, 4834, 255, 5200
+ };
+
+ long depth;
+ short *vi1, *vi2, pcents, v1;
+
+ pcents = cents < 0 ? -cents : cents;
+ for (vi1 = vibrato_table, vi2 = vi1 + 2; pcents > *vi2; vi1 = vi2, vi2 += 2);
+ v1 = *(vi1 + 1);
+ /* The FC table above is a list of pairs. The first number in the pair */
+ /* is the cents index from 0-255 cents, and the second number in the */
+ /* pair is the FC adjustment needed to change the pitch by the indexed */
+ /* number of cents. The table was created for an FC of 32768. */
+ /* The following expression does a linear interpolation against the */
+ /* approximated log curve in the table above, and then scales the number */
+ /* by the FC before the LFO. This calculation also adjusts the output */
+ /* value to produce the appropriate depth for the hardware. The depth */
+ /* is 2 * desired FC + 1. */
+ depth = (((int) (*(vi2 + 1) - *vi1) * (pcents - *vi1) / (*vi2 - *vi1)) + v1) * fc_register >> 14;
+ if (depth)
+ depth++;
+ if (depth > 255)
+ depth = 255;
+ return cents < 0 ? -(short) depth : (short) depth;
+}
+
+unsigned short snd_gf1_compute_pitchbend(unsigned short pitchbend, unsigned short sens)
+{
+ static long log_table[] = {1024, 1085, 1149, 1218, 1290, 1367, 1448, 1534, 1625, 1722, 1825, 1933};
+ int wheel, sensitivity;
+ unsigned int mantissa, f1, f2;
+ unsigned short semitones, f1_index, f2_index, f1_power, f2_power;
+ char bend_down = 0;
+ int bend;
+
+ if (!sens)
+ return 1024;
+ wheel = (int) pitchbend - 8192;
+ sensitivity = ((int) sens * wheel) / 128;
+ if (sensitivity < 0) {
+ bend_down = 1;
+ sensitivity = -sensitivity;
+ }
+ semitones = (unsigned int) (sensitivity >> 13);
+ mantissa = sensitivity % 8192;
+ f1_index = semitones % 12;
+ f2_index = (semitones + 1) % 12;
+ f1_power = semitones / 12;
+ f2_power = (semitones + 1) / 12;
+ f1 = log_table[f1_index] << f1_power;
+ f2 = log_table[f2_index] << f2_power;
+ bend = (int) ((((f2 - f1) * mantissa) >> 13) + f1);
+ if (bend_down)
+ bend = 1048576L / bend;
+ return bend;
+}
+
+unsigned short snd_gf1_compute_freq(unsigned int freq,
+ unsigned int rate,
+ unsigned short mix_rate)
+{
+ unsigned int fc;
+ int scale = 0;
+
+ while (freq >= 4194304L) {
+ scale++;
+ freq >>= 1;
+ }
+ fc = (freq << 10) / rate;
+ if (fc > 97391L) {
+ fc = 97391;
+ snd_printk("patch: (1) fc frequency overflow - %u\n", fc);
+ }
+ fc = (fc * 44100UL) / mix_rate;
+ while (scale--)
+ fc <<= 1;
+ if (fc > 65535L) {
+ fc = 65535;
+ snd_printk("patch: (2) fc frequency overflow - %u\n", fc);
+ }
+ return (unsigned short) fc;
+}
diff --git a/sound/isa/gus/gusclassic.c b/sound/isa/gus/gusclassic.c
new file mode 100644
index 000000000000..a99fa5040b46
--- /dev/null
+++ b/sound/isa/gus/gusclassic.c
@@ -0,0 +1,260 @@
+/*
+ * Driver for Gravis UltraSound Classic soundcard
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <asm/dma.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/time.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+#define SNDRV_LEGACY_AUTO_PROBE
+#define SNDRV_LEGACY_FIND_FREE_IRQ
+#define SNDRV_LEGACY_FIND_FREE_DMA
+#include <sound/initval.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("Gravis UltraSound Classic");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Classic}}");
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
+static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x230,0x240,0x250,0x260 */
+static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 3,5,9,11,12,15 */
+static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
+static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
+static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
+ /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
+static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24};
+static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for GUS Classic soundcard.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for GUS Classic soundcard.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable GUS Classic soundcard.");
+module_param_array(port, long, NULL, 0444);
+MODULE_PARM_DESC(port, "Port # for GUS Classic driver.");
+module_param_array(irq, int, NULL, 0444);
+MODULE_PARM_DESC(irq, "IRQ # for GUS Classic driver.");
+module_param_array(dma1, int, NULL, 0444);
+MODULE_PARM_DESC(dma1, "DMA1 # for GUS Classic driver.");
+module_param_array(dma2, int, NULL, 0444);
+MODULE_PARM_DESC(dma2, "DMA2 # for GUS Classic driver.");
+module_param_array(joystick_dac, int, NULL, 0444);
+MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for GUS Classic driver.");
+module_param_array(channels, int, NULL, 0444);
+MODULE_PARM_DESC(channels, "GF1 channels for GUS Classic driver.");
+module_param_array(pcm_channels, int, NULL, 0444);
+MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for GUS Classic driver.");
+
+static snd_card_t *snd_gusclassic_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
+
+
+static int __init snd_gusclassic_detect(snd_gus_card_t * gus)
+{
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
+#ifdef CONFIG_SND_DEBUG_DETECT
+ {
+ unsigned char d;
+
+ if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
+ snd_printk("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
+ return -ENODEV;
+ }
+ }
+#else
+ if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 0)
+ return -ENODEV;
+#endif
+ udelay(160);
+ snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
+ udelay(160);
+#ifdef CONFIG_SND_DEBUG_DETECT
+ {
+ unsigned char d;
+
+ if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
+ snd_printk("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
+ return -ENODEV;
+ }
+ }
+#else
+ if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 1)
+ return -ENODEV;
+#endif
+
+ return 0;
+}
+
+static void __init snd_gusclassic_init(int dev, snd_gus_card_t * gus)
+{
+ gus->equal_irq = 0;
+ gus->codec_flag = 0;
+ gus->max_flag = 0;
+ gus->joystick_dac = joystick_dac[dev];
+}
+
+static int __init snd_gusclassic_probe(int dev)
+{
+ static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, 4, -1};
+ static int possible_dmas[] = {5, 6, 7, 1, 3, -1};
+ int xirq, xdma1, xdma2;
+ snd_card_t *card;
+ struct snd_gusclassic *guscard;
+ snd_gus_card_t *gus = NULL;
+ int err;
+
+ card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
+ if (card == NULL)
+ return -ENOMEM;
+ guscard = (struct snd_gusclassic *)card->private_data;
+ if (pcm_channels[dev] < 2)
+ pcm_channels[dev] = 2;
+
+ xirq = irq[dev];
+ if (xirq == SNDRV_AUTO_IRQ) {
+ if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
+ snd_card_free(card);
+ snd_printk("unable to find a free IRQ\n");
+ return -EBUSY;
+ }
+ }
+ xdma1 = dma1[dev];
+ if (xdma1 == SNDRV_AUTO_DMA) {
+ if ((xdma1 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
+ snd_card_free(card);
+ snd_printk("unable to find a free DMA1\n");
+ return -EBUSY;
+ }
+ }
+ xdma2 = dma2[dev];
+ if (xdma2 == SNDRV_AUTO_DMA) {
+ if ((xdma2 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
+ snd_card_free(card);
+ snd_printk("unable to find a free DMA2\n");
+ return -EBUSY;
+ }
+ }
+
+
+ if ((err = snd_gus_create(card,
+ port[dev],
+ xirq, xdma1, xdma2,
+ 0, channels[dev], pcm_channels[dev],
+ 0, &gus)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if ((err = snd_gusclassic_detect(gus)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ snd_gusclassic_init(dev, gus);
+ if ((err = snd_gus_initialize(gus)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if (gus->max_flag || gus->ess_flag) {
+ snd_printdd("GUS Classic or ACE soundcard was not detected at 0x%lx\n", gus->gf1.port);
+ snd_card_free(card);
+ return -ENODEV;
+ }
+ if ((err = snd_gf1_new_mixer(gus)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if ((err = snd_gf1_pcm_new(gus, 0, 0, NULL)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ if (!gus->ace_flag) {
+ if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ }
+ sprintf(card->longname + strlen(card->longname), " at 0x%lx, irq %d, dma %d", gus->gf1.port, xirq, xdma1);
+ if (dma2 >= 0)
+ sprintf(card->longname + strlen(card->longname), "&%d", xdma2);
+ if ((err = snd_card_register(card)) < 0) {
+ snd_card_free(card);
+ return err;
+ }
+ snd_gusclassic_cards[dev] = card;
+ return 0;
+}
+
+static int __init snd_gusclassic_legacy_auto_probe(unsigned long xport)
+{
+ static int dev;
+ int res;
+
+ for ( ; dev < SNDRV_CARDS; dev++) {
+ if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
+ continue;
+ port[dev] = xport;
+ res = snd_gusclassic_probe(dev);
+ if (res < 0)
+ port[dev] = SNDRV_AUTO_PORT;
+ return res;
+ }
+ return -ENODEV;
+}
+
+static int __init alsa_card_gusclassic_init(void)
+{
+ static unsigned long possible_ports[] = {0x220, 0x230, 0x240, 0x250, 0x260, -1};
+ int dev, cards, i;
+
+ for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
+ if (port[dev] == SNDRV_AUTO_PORT)
+ continue;
+ if (snd_gusclassic_probe(dev) >= 0)
+ cards++;
+ }
+ i = snd_legacy_auto_probe(possible_ports, snd_gusclassic_legacy_auto_probe);
+ if (i > 0)
+ cards += i;
+
+ if (!cards) {
+#ifdef MODULE
+ printk(KERN_ERR "GUS Classic soundcard not found or device busy\n");
+#endif
+ return -ENODEV;
+ }
+ return 0;
+}
+
+static void __exit alsa_card_gusclassic_exit(void)
+{
+ int idx;
+
+ for (idx = 0; idx < SNDRV_CARDS; idx++)
+ snd_card_free(snd_gusclassic_cards[idx]);
+}
+
+module_init(alsa_card_gusclassic_init)
+module_exit(alsa_card_gusclassic_exit)
diff --git a/sound/isa/gus/gusextreme.c b/sound/isa/gus/gusextreme.c
new file mode 100644
index 000000000000..bc6fecb18dcf
--- /dev/null
+++ b/sound/isa/gus/gusextreme.c
@@ -0,0 +1,374 @@
+/*
+ * Driver for Gravis UltraSound Extreme soundcards
+ * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <sound/driver.h>
+#include <asm/dma.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/time.h>
+#include <linux/moduleparam.h>
+#include <sound/core.h>
+#include <sound/gus.h>
+#include <sound/es1688.h>
+#include <sound/mpu401.h>
+#include <sound/opl3.h>
+#define SNDRV_LEGACY_AUTO_PROBE
+#define SNDRV_LEGACY_FIND_FREE_IRQ
+#define SNDRV_LEGACY_FIND_FREE_DMA
+#include <sound/initval.h>
+
+MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_DESCRIPTION("Gravis UltraSound Extreme");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Extreme}}");
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
+static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
+static long gf1_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS) - 1] = -1}; /* 0x210,0x220,0x230,0x240,0x250,0x260,0x270 */
+static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS) - 1] = -1}; /* 0x300,0x310,0x320 */
+static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
+static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
+static int gf1_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,3,5,9,11,12,15 */
+static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
+static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
+static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
+ /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
+static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24};
+static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for GU