diff options
Diffstat (limited to '')
60 files changed, 705 insertions, 5397 deletions
diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c index 5b3274b465eb..199cca3366df 100644 --- a/sound/arm/pxa2xx-ac97.c +++ b/sound/arm/pxa2xx-ac97.c @@ -26,10 +26,10 @@ #include <asm/irq.h> #include <linux/mutex.h> -#include <asm/hardware.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/pxa2xx-gpio.h> -#include <asm/arch/audio.h> +#include <mach/hardware.h> +#include <mach/pxa-regs.h> +#include <mach/pxa2xx-gpio.h> +#include <mach/audio.h> #include "pxa2xx-pcm.h" diff --git a/sound/arm/pxa2xx-pcm.c b/sound/arm/pxa2xx-pcm.c index 0ede9e4656a8..381094aab235 100644 --- a/sound/arm/pxa2xx-pcm.c +++ b/sound/arm/pxa2xx-pcm.c @@ -21,8 +21,8 @@ #include <sound/pcm_params.h> #include <asm/dma.h> -#include <asm/hardware.h> -#include <asm/arch/pxa-regs.h> +#include <mach/hardware.h> +#include <mach/pxa-regs.h> #include "pxa2xx-pcm.h" diff --git a/sound/arm/sa11xx-uda1341.c b/sound/arm/sa11xx-uda1341.c index faeddf3ecedb..b9c51bf8cd71 100644 --- a/sound/arm/sa11xx-uda1341.c +++ b/sound/arm/sa11xx-uda1341.c @@ -71,8 +71,8 @@ #include <linux/pm.h> #endif -#include <asm/hardware.h> -#include <asm/arch/h3600.h> +#include <mach/hardware.h> +#include <mach/h3600.h> #include <asm/mach-types.h> #include <asm/dma.h> diff --git a/sound/core/info.c b/sound/core/info.c index cb5ead3e202d..c67773ad9298 100644 --- a/sound/core/info.c +++ b/sound/core/info.c @@ -21,6 +21,7 @@ #include <linux/init.h> #include <linux/time.h> +#include <linux/mm.h> #include <linux/smp_lock.h> #include <linux/string.h> #include <sound/core.h> diff --git a/sound/core/init.c b/sound/core/init.c index 5c254d498ae0..df46bbc25dc2 100644 --- a/sound/core/init.c +++ b/sound/core/init.c @@ -548,8 +548,9 @@ int snd_card_register(struct snd_card *card) snd_assert(card != NULL, return -EINVAL); #ifndef CONFIG_SYSFS_DEPRECATED if (!card->card_dev) { - card->card_dev = device_create(sound_class, card->dev, 0, - "card%i", card->number); + card->card_dev = device_create_drvdata(sound_class, card->dev, + MKDEV(0, 0), NULL, + "card%i", card->number); if (IS_ERR(card->card_dev)) card->card_dev = NULL; } diff --git a/sound/core/seq/oss/seq_oss_synth.c b/sound/core/seq/oss/seq_oss_synth.c index 558dadbf45f1..e024e4588b82 100644 --- a/sound/core/seq/oss/seq_oss_synth.c +++ b/sound/core/seq/oss/seq_oss_synth.c @@ -604,6 +604,9 @@ snd_seq_oss_synth_make_info(struct seq_oss_devinfo *dp, int dev, struct synth_in { struct seq_oss_synth *rec; + if (dev < 0 || dev >= dp->max_synthdev) + return -ENXIO; + if (dp->synths[dev].is_midi) { struct midi_info minf; snd_seq_oss_midi_make_info(dp, dp->synths[dev].midi_mapped, &minf); diff --git a/sound/i2c/other/tea575x-tuner.c b/sound/i2c/other/tea575x-tuner.c index 87e3aefeddc3..83e90057270e 100644 --- a/sound/i2c/other/tea575x-tuner.c +++ b/sound/i2c/other/tea575x-tuner.c @@ -189,9 +189,7 @@ void snd_tea575x_init(struct snd_tea575x *tea) } memset(&tea->vd, 0, sizeof(tea->vd)); - tea->vd.owner = tea->card->module; strcpy(tea->vd.name, tea->tea5759 ? "TEA5759 radio" : "TEA5757 radio"); - tea->vd.type = VID_TYPE_TUNER; tea->vd.release = snd_tea575x_release; video_set_drvdata(&tea->vd, tea); tea->vd.fops = &tea->fops; diff --git a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c index dbe63db4bfd6..4d4b8ddc26ba 100644 --- a/sound/isa/cs423x/cs4236.c +++ b/sound/isa/cs423x/cs4236.c @@ -325,6 +325,7 @@ static int __devinit snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev) static int __devinit snd_card_cs4232_pnp(int dev, struct snd_card_cs4236 *acard, struct pnp_dev *pdev) { + acard->wss = pdev; if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0) return -EBUSY; cport[dev] = -1; diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c index 41c047e665ec..0797ca441a37 100644 --- a/sound/isa/opti9xx/opti92x-ad1848.c +++ b/sound/isa/opti9xx/opti92x-ad1848.c @@ -68,7 +68,9 @@ MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (AD1848)}," static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ //static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */ +#ifdef CONFIG_PNP static int isapnp = 1; /* Enable ISA PnP detection */ +#endif static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */ static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */ static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */ @@ -85,8 +87,10 @@ module_param(id, charp, 0444); MODULE_PARM_DESC(id, "ID string for opti9xx based soundcard."); //module_param(enable, bool, 0444); //MODULE_PARM_DESC(enable, "Enable opti9xx soundcard."); +#ifdef CONFIG_PNP module_param(isapnp, bool, 0444); MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard."); +#endif module_param(port, long, 0444); MODULE_PARM_DESC(port, "WSS port # for opti9xx driver."); module_param(mpu_port, long, 0444); @@ -688,7 +692,7 @@ static void snd_card_opti9xx_free(struct snd_card *card) if (chip) { #ifdef OPTi93X struct snd_cs4231 *codec = chip->codec; - if (codec->irq > 0) { + if (codec && codec->irq > 0) { disable_irq(codec->irq); free_irq(codec->irq, codec); } diff --git a/sound/oss/Kconfig b/sound/oss/Kconfig index 33940139844b..d4fafb6eec6c 100644 --- a/sound/oss/Kconfig +++ b/sound/oss/Kconfig @@ -35,47 +35,6 @@ config SOUND_AU1550_AC97 tristate "Au1550/Au1200 AC97 Sound" depends on SOC_AU1550 || SOC_AU1200 -config SOUND_TRIDENT - tristate "Trident 4DWave DX/NX, SiS 7018 or ALi 5451 PCI Audio Core" - depends on PCI - ---help--- - Say Y or M if you have a PCI sound card utilizing the Trident - 4DWave-DX/NX chipset or your mother board chipset has SiS 7018 - or ALi 5451 built-in. The SiS 7018 PCI Audio Core is embedded - in SiS960 Super South Bridge and SiS540/630 Single Chipset. - The ALi 5451 PCI Audio Core is embedded in ALi M1535, M1535D, - M1535+ or M1535D+ South Bridge. - - Use lspci -n to find out if your sound card or chipset uses - Trident 4DWave or SiS 7018. PCI ID 1023:2000 or 1023:2001 stands - for Trident 4Dwave. PCI ID 1039:7018 stands for SiS7018. PCI ID - 10B9:5451 stands for ALi5451. - - This driver supports S/PDIF in/out (record/playback) for ALi 5451 - embedded in ALi M1535+ and M1535D+. Note that they aren't all - enabled by default; you can enable them by saying Y to "/proc file - system support" and "Sysctl support", and after the /proc file - system has been mounted, executing the command - - command what is enabled - - echo 0>/proc/ALi5451 pcm out is also set to S/PDIF out. (Default). - - echo 1>/proc/ALi5451 use S/PDIF out to output pcm data. - - echo 2>/proc/ALi5451 use S/PDIF out to output non-pcm data. - (AC3...). - - echo 3>/proc/ALi5451 record from Ac97 in(MIC, Line in...). - (Default). - - echo 4>/proc/ALi5451 no matter Ac97 settings, record from S/PDIF - in. - - - This driver differs slightly from OSS/Free, so PLEASE READ the - comments at the top of <file:sound/oss/trident.c>. - config SOUND_MSNDCLAS tristate "Support for Turtle Beach MultiSound Classic, Tahiti, Monterey" depends on (m || !STANDALONE) && ISA diff --git a/sound/oss/Makefile b/sound/oss/Makefile index 1f86299fae40..c611514f7ff1 100644 --- a/sound/oss/Makefile +++ b/sound/oss/Makefile @@ -29,11 +29,8 @@ obj-$(CONFIG_SOUND_MSNDCLAS) += msnd.o msnd_classic.o obj-$(CONFIG_SOUND_MSNDPIN) += msnd.o msnd_pinnacle.o obj-$(CONFIG_SOUND_VWSND) += vwsnd.o obj-$(CONFIG_SOUND_AU1550_AC97) += au1550_ac97.o ac97_codec.o -obj-$(CONFIG_SOUND_TRIDENT) += trident.o ac97_codec.o obj-$(CONFIG_SOUND_BCM_CS4297A) += swarm_cs4297a.o -obj-$(CONFIG_SOUND_WM97XX) += ac97_plugin_wm97xx.o - obj-$(CONFIG_DMASOUND) += dmasound/ # Declare multi-part drivers. diff --git a/sound/oss/soundcard.c b/sound/oss/soundcard.c index a9c23b2502ad..7d89c081a086 100644 --- a/sound/oss/soundcard.c +++ b/sound/oss/soundcard.c @@ -560,17 +560,19 @@ static int __init oss_init(void) sound_dmap_flag = (dmabuf > 0 ? 1 : 0); for (i = 0; i < ARRAY_SIZE(dev_list); i++) { - device_create(sound_class, NULL, - MKDEV(SOUND_MAJOR, dev_list[i].minor), - "%s", dev_list[i].name); + device_create_drvdata(sound_class, NULL, + MKDEV(SOUND_MAJOR, dev_list[i].minor), + NULL, "%s", dev_list[i].name); if (!dev_list[i].num) continue; for (j = 1; j < *dev_list[i].num; j++) - device_create(sound_class, NULL, - MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)), - "%s%d", dev_list[i].name, j); + device_create_drvdata(sound_class, NULL, + MKDEV(SOUND_MAJOR, + dev_list[i].minor + (j*0x10)), + NULL, + "%s%d", dev_list[i].name, j); } if (sound_nblocks >= 1024) diff --git a/sound/oss/trident.c b/sound/oss/trident.c deleted file mode 100644 index f43f91ef86c7..000000000000 --- a/sound/oss/trident.c +++ /dev/null @@ -1,4654 +0,0 @@ -/* - * OSS driver for Linux 2.[46].x for - * - * Trident 4D-Wave - * SiS 7018 - * ALi 5451 - * Tvia/IGST CyberPro 5050 - * - * Driver: Alan Cox <alan@redhat.com> - * - * Built from: - * Low level code: <audio@tridentmicro.com> from ALSA - * Framework: Thomas Sailer <sailer@ife.ee.ethz.ch> - * Extended by: Zach Brown <zab@redhat.com> - * - * Hacked up by: - * Aaron Holtzman <aholtzma@ess.engr.uvic.ca> - * Ollie Lho <ollie@sis.com.tw> SiS 7018 Audio Core Support - * Ching-Ling Lee <cling-li@ali.com.tw> ALi 5451 Audio Core Support - * Matt Wu <mattwu@acersoftech.com.cn> ALi 5451 Audio Core Support - * Peter Wächtler <pwaechtler@loewe-komp.de> CyberPro5050 support - * Muli Ben-Yehuda <mulix@mulix.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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * History - * v0.14.10j - * January 3 2004 Eugene Teo <eugeneteo@eugeneteo.net> - * minor cleanup to use pr_debug instead of TRDBG since it is already - * defined in linux/kernel.h. - * v0.14.10i - * December 29 2003 Muli Ben-Yehuda <mulix@mulix.org> - * major cleanup for 2.6, fix a few error patch buglets - * with returning without properly cleaning up first, - * get rid of lock_kernel(). - * v0.14.10h - * Sept 10 2002 Pascal Schmidt <der.eremit@email.de> - * added support for ALi 5451 joystick port - * v0.14.10g - * Sept 05 2002 Alan Cox <alan@redhat.com> - * adapt to new pci joystick attachment interface - * v0.14.10f - * July 24 2002 Muli Ben-Yehuda <mulix@actcom.co.il> - * patch from Eric Lemar (via Ian Soboroff): in suspend and resume, - * fix wrong cast from pci_dev* to struct trident_card*. - * v0.14.10e - * July 19 2002 Muli Ben-Yehuda <mulix@actcom.co.il> - * rewrite the DMA buffer allocation/deallcoation functions, to make it - * modular and fix a bug where we would call free_pages on memory - * obtained with pci_alloc_consistent. Also remove unnecessary #ifdef - * CONFIG_PROC_FS and various other cleanups. - * v0.14.10d - * July 19 2002 Muli Ben-Yehuda <mulix@actcom.co.il> - * made several printk(KERN_NOTICE...) into TRDBG(...), to avoid spamming - * my syslog with hundreds of messages. - * v0.14.10c - * July 16 2002 Muli Ben-Yehuda <mulix@actcom.co.il> - * Cleaned up Lei Hu's 0.4.10 driver to conform to Documentation/CodingStyle - * and the coding style used in the rest of the file. - * v0.14.10b - * June 23 2002 Muli Ben-Yehuda <mulix@actcom.co.il> - * add a missing unlock_set_fmt, remove a superflous lock/unlock pair - * with nothing in between. - * v0.14.10a - * June 21 2002 Muli Ben-Yehuda <mulix@actcom.co.il> - * use a debug macro instead of #ifdef CONFIG_DEBUG, trim to 80 columns - * per line, use 'do {} while (0)' in statement macros. - * v0.14.10 - * June 6 2002 Lei Hu <Lei_hu@ali.com.tw> - * rewrite the part to read/write registers of audio codec for Ali5451 - * v0.14.9e - * January 2 2002 Vojtech Pavlik <vojtech@ucw.cz> added gameport - * support to avoid resource conflict with pcigame.c - * v0.14.9d - * October 8 2001 Arnaldo Carvalho de Melo <acme@conectiva.com.br> - * use set_current_state, properly release resources on failure in - * trident_probe, get rid of check_region - * v0.14.9c - * August 10 2001 Peter Wächtler <pwaechtler@loewe-komp.de> - * added support for Tvia (formerly Integraphics/IGST) CyberPro5050 - * this chip is often found in settop boxes (combined video+audio) - * v0.14.9b - * Switch to static inline not extern inline (gcc 3) - * v0.14.9a - * Aug 6 2001 Alan Cox - * 0.14.9 crashed on rmmod due to a timer/bh left running. Simplified - * the existing logic (the BH doesn't help as ac97 is lock_irqsave) - * and used del_timer_sync to clean up - * Fixed a problem where the ALi change broke my generic card - * v0.14.9 - * Jul 10 2001 Matt Wu - * Add H/W Volume Control - * v0.14.8a - * July 7 2001 Alan Cox - * Moved Matt Wu's ac97 register cache into the card structure - * v0.14.8 - * Apr 30 2001 Matt Wu - * Set EBUF1 and EBUF2 to still mode - * Add dc97/ac97 reset function - * Fix power management: ali_restore_regs - * unreleased - * Mar 09 2001 Matt Wu - * Add cache for ac97 access - * v0.14.7 - * Feb 06 2001 Matt Wu - * Fix ac97 initialization - * Fix bug: an extra tail will be played when playing - * Jan 05 2001 Matt Wu - * Implement multi-channels and S/PDIF in support for ALi 1535+ - * v0.14.6 - * Nov 1 2000 Ching-Ling Lee - * Fix the bug of memory leak when switching 5.1-channels to 2 channels. - * Add lock protection into dynamic changing format of data. - * Oct 18 2000 Ching-Ling Lee - * 5.1-channels support for ALi - * June 28 2000 Ching-Ling Lee - * S/PDIF out/in(playback/record) support for ALi 1535+, using /proc to be selected by user - * Simple Power Management support for ALi - * v0.14.5 May 23 2000 Ollie Lho - * Misc bug fix from the Net - * v0.14.4 May 20 2000 Aaron Holtzman - * Fix kfree'd memory access in release - * Fix race in open while looking for a free virtual channel slot - * remove open_wait wq (which appears to be unused) - * v0.14.3 May 10 2000 Ollie Lho - * fixed a small bug in trident_update_ptr, xmms 1.0.1 no longer uses 100% CPU - * v0.14.2 Mar 29 2000 Ching-Ling Lee - * Add clear to silence advance in trident_update_ptr - * fix invalid data of the end of the sound - * v0.14.1 Mar 24 2000 Ching-Ling Lee - * ALi 5451 support added, playback and recording O.K. - * ALi 5451 originally developed and structured based on sonicvibes, and - * suggested to merge into this file by Alan Cox. - * v0.14 Mar 15 2000 Ollie Lho - * 5.1 channel output support with channel binding. What's the Matrix ? - * v0.13.1 Mar 10 2000 Ollie Lho - * few minor bugs on dual codec support, needs more testing - * v0.13 Mar 03 2000 Ollie Lho - * new pci_* for 2.4 kernel, back ported to 2.2 - * v0.12 Feb 23 2000 Ollie Lho - * Preliminary Recording support - * v0.11.2 Feb 19 2000 Ollie Lho - * removed incomplete full-dulplex support - * v0.11.1 Jan 28 2000 Ollie Lho - * small bug in setting sample rate for 4d-nx (reported by Aaron) - * v0.11 Jan 27 2000 Ollie Lho - * DMA bug, scheduler latency, second try - * v0.10 Jan 24 2000 Ollie Lho - * DMA bug fixed, found kernel scheduling problem - * v0.09 Jan 20 2000 Ollie Lho - * Clean up of channel register access routine (prepare for channel binding) - * v0.08 Jan 14 2000 Ollie Lho - * Isolation of AC97 codec code - * v0.07 Jan 13 2000 Ollie Lho - * Get rid of ugly old low level access routines (e.g. CHRegs.lp****) - * v0.06 Jan 11 2000 Ollie Lho - * Preliminary support for dual (more ?) AC97 codecs - * v0.05 Jan 08 2000 Luca Montecchiani <m.luca@iname.com> - * adapt to 2.3.x new __setup/__init call - * v0.04 Dec 31 1999 Ollie Lho - * Multiple Open, using Middle Loop Interrupt to smooth playback - * v0.03 Dec 24 1999 Ollie Lho - * mem leak in prog_dmabuf and dealloc_dmabuf removed - * v0.02 Dec 15 1999 Ollie Lho - * SiS 7018 support added, playback O.K. - * v0.01 Alan Cox et. al. - * Initial Release in kernel 2.3.30, does not work - * - * ToDo - * Clean up of low level channel register access code. (done) - * Fix the bug on dma buffer management in update_ptr, read/write, drain_dac (done) - * Dual AC97 codecs support (done) - * Recording support (done) - * Mmap support - * "Channel Binding" ioctl extension (done) - * new pci device driver interface for 2.4 kernel (done) - * - * Lock order (high->low) - * lock - hardware lock - * open_mutex - guard opens - * sem - guard dmabuf, write re-entry etc - */ - -#include <linux/module.h> -#include <linux/string.h> -#include <linux/ctype.h> -#include <linux/ioport.h> -#include <linux/sched.h> -#include <linux/delay.h> -#include <linux/sound.h> -#include <linux/slab.h> -#include <linux/soundcard.h> -#include <linux/pci.h> -#include <linux/init.h> -#include <linux/poll.h> -#include <linux/spinlock.h> -#include <linux/ac97_codec.h> -#include <linux/bitops.h> -#include <linux/proc_fs.h> -#include <linux/interrupt.h> -#include <linux/pm.h> -#include <linux/gameport.h> -#include <linux/kernel.h> -#include <linux/mutex.h> -#include <linux/mm.h> - -#include <asm/uaccess.h> -#include <asm/io.h> -#include <asm/dma.h> - -#if defined(CONFIG_ALPHA_NAUTILUS) || defined(CONFIG_ALPHA_GENERIC) -#include <asm/hwrpb.h> -#endif - -#include "trident.h" - -#define DRIVER_VERSION "0.14.10j-2.6" - -#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE)) -#define SUPPORT_JOYSTICK 1 -#endif - -/* magic numbers to protect our data structures */ -#define TRIDENT_CARD_MAGIC 0x5072696E /* "Prin" */ -#define TRIDENT_STATE_MAGIC 0x63657373 /* "cess" */ - -#define TRIDENT_DMA_MASK 0x3fffffff /* DMA buffer mask for pci_alloc_consist */ -#define ALI_DMA_MASK 0x7fffffff /* ALI Tridents have 31-bit DMA. Wow. */ - -#define NR_HW_CH 32 - -/* maximum number of AC97 codecs connected, AC97 2.0 defined 4, but 7018 and 4D-NX only - have 2 SDATA_IN lines (currently) */ -#define NR_AC97 2 - -/* minor number of /dev/swmodem (temporary, experimental) */ -#define SND_DEV_SWMODEM 7 - -static const unsigned ali_multi_channels_5_1[] = { - /*ALI_SURR_LEFT_CHANNEL, ALI_SURR_RIGHT_CHANNEL, */ - ALI_CENTER_CHANNEL, - ALI_LEF_CHANNEL, - ALI_SURR_LEFT_CHANNEL, - ALI_SURR_RIGHT_CHANNEL -}; - -static const unsigned sample_size[] = { 1, 2, 2, 4 }; -static const unsigned sample_shift[] = { 0, 1, 1, 2 }; - -static const char invalid_magic[] = KERN_CRIT "trident: invalid magic value in %s\n"; - -enum { - TRIDENT_4D_DX = 0, - TRIDENT_4D_NX, - SIS_7018, - ALI_5451, - CYBER5050 -}; - -static char *card_names[] = { - "Trident 4DWave DX", - "Trident 4DWave NX", - "SiS 7018 PCI Audio", - "ALi Audio Accelerator", - "Tvia/IGST CyberPro 5050" -}; - -static struct pci_device_id trident_pci_tbl[] = { - {PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_DX), - PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, TRIDENT_4D_DX}, - {PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_NX), - 0, 0, TRIDENT_4D_NX}, - {PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_7018), 0, 0, SIS_7018}, - {PCI_DEVICE(PCI_VENDOR_ID_ALI, PCI_DEVICE_ID_ALI_5451), 0, 0, ALI_5451}, - {PCI_DEVICE(PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_5050), - 0, 0, CYBER5050}, - {0,} -}; - -MODULE_DEVICE_TABLE(pci, trident_pci_tbl); - -/* "software" or virtual channel, an instance of opened /dev/dsp */ -struct trident_state { - unsigned int magic; - struct trident_card *card; /* Card info */ - - /* file mode */ - mode_t open_mode; - - /* virtual channel number */ - int virt; - - struct dmabuf { - /* wave sample stuff */ - unsigned int rate; - unsigned char fmt, enable; - - /* hardware channel */ - struct trident_channel *channel; - - /* OSS buffer management stuff */ - void *rawbuf; - dma_addr_t dma_handle; - unsigned buforder; - unsigned numfrag; - unsigned fragshift; - - /* our buffer acts like a circular ring */ - unsigned hwptr; /* where dma last started, updated by update_ptr */ - unsigned swptr; /* where driver last clear/filled, updated by read/write */ - int count; /* bytes to be comsumed or been generated by dma machine */ - unsigned total_bytes; /* total bytes dmaed by hardware */ - - unsigned error; /* number of over/underruns */ - /* put process on wait queue when no more space in buffer */ - wait_queue_head_t wait; - - /* redundant, but makes calculations easier */ - unsigned fragsize; - unsigned dmasize; - unsigned fragsamples; - - /* OSS stuff */ - unsigned mapped:1; - unsigned ready:1; - unsigned endcleared:1; - unsigned update_flag; - unsigned ossfragshift; - int ossmaxfrags; - unsigned subdivision; - - } dmabuf; - - /* 5.1 channels */ - struct trident_state *other_states[4]; - int multi_channels_adjust_count; - unsigned chans_num; - unsigned long fmt_flag; - /* Guard against mmap/write/read races */ - struct mutex sem; - -}; - -/* hardware channels */ -struct trident_channel { - int num; /* channel number */ - u32 lba; /* Loop Begine Address, where dma buffer starts */ - u32 eso; /* End Sample Offset, wehre dma buffer ends */ - /* (in the unit of samples) */ - u32 delta; /* delta value, sample rate / 48k for playback, */ - /* 48k/sample rate for recording */ - u16 attribute; /* control where PCM data go and come */ - u16 fm_vol; - u32 control; /* signed/unsigned, 8/16 bits, mono/stereo */ -}; - -struct trident_pcm_bank_address { - u32 start; - u32 stop; - u32 aint; - u32 aint_en; -}; - -static struct trident_pcm_bank_address bank_a_addrs = { - T4D_START_A, - T4D_STOP_A, - T4D_AINT_A, - T4D_AINTEN_A -}; - -static struct trident_pcm_bank_address bank_b_addrs = { - T4D_START_B, - T4D_STOP_B, - T4D_AINT_B, - T4D_AINTEN_B -}; - -struct trident_pcm_bank { - /* register addresses to control bank operations */ - struct trident_pcm_bank_address *addresses; - /* each bank has 32 channels */ - u32 bitmap; /* channel allocation bitmap */ - struct trident_channel channels[32]; -}; - -struct trident_card { - unsigned int magic; - - /* We keep trident cards in a linked list */ - struct trident_card *next; - - /* single open lock mechanism, only used for recording */ - struct mutex open_mutex; - - /* The trident has a certain amount of cross channel interaction - so we use a single per card lock */ - spinlock_t lock; - - /* PCI device stuff */ - struct pci_dev *pci_dev; - u16 pci_id; - u8 revision; - - /* soundcore stuff */ - int dev_audio; - - /* structures for abstraction of hardware facilities, codecs, */ - /* banks and channels */ - struct ac97_codec *ac97_codec[NR_AC97]; - struct trident_pcm_bank banks[NR_BANKS]; - struct trident_state *states[NR_HW_CH]; - - /* hardware resources */ - unsigned long iobase; - u32 irq; - - /* Function support */ - struct trident_channel *(*alloc_pcm_channel) (struct trident_card *); - struct trident_channel *(*alloc_rec_pcm_channel) (struct trident_card *); - void (*free_pcm_channel) (struct trident_card *, unsigned int chan); - void (*address_interrupt) (struct trident_card *); - - /* Added by Matt Wu 01-05-2001 for spdif in */ - int multi_channel_use_count; - int rec_channel_use_count; - u16 mixer_regs[64][NR_AC97]; /* Made card local by Alan */ - int mixer_regs_ready; - - /* Added for hardware volume control */ - int hwvolctl; - struct timer_list timer; - - /* Game port support */ - struct gameport *gameport; -}; - -enum dmabuf_mode { - DM_PLAYBACK = 0, - DM_RECORD -}; - -/* table to map from CHANNELMASK to channel attribute for SiS 7018 */ -static u16 mask2attr[] = { - PCM_LR, PCM_LR, SURR_LR, CENTER_LFE, - HSET, MIC, MODEM_LINE1, MODEM_LINE2, - I2S_LR, SPDIF_LR -}; - -/* table to map from channel attribute to CHANNELMASK for SiS 7018 */ -static int attr2mask[] = { - DSP_BIND_MODEM1, DSP_BIND_MODEM2, DSP_BIND_FRONT, DSP_BIND_HANDSET, - DSP_BIND_I2S, DSP_BIND_CENTER_LFE, DSP_BIND_SURR, DSP_BIND_SPDIF -}; - -/* Added by Matt Wu 01-05-2001 for spdif in */ -static int ali_close_multi_channels(void); -static void ali_delay(struct trident_card *card, int interval); -static void ali_detect_spdif_rate(struct trident_card *card); - -static void ali_ac97_write(struct ac97_codec *codec, u8 reg, u16 val); -static u16 ali_ac97_read(struct ac97_codec *codec, u8 reg); - -static struct trident_card *devs; - -static void trident_ac97_set(struct ac97_codec *codec, u8 reg, u16 val); -static u16 trident_ac97_get(struct ac97_codec *codec, u8 reg); - -static int trident_open_mixdev(struct inode *inode, struct file *file); -static int trident_ioctl_mixdev(struct inode *inode, struct file *file, - unsigned int cmd, unsigned long arg); - -static void ali_ac97_set(struct trident_card *card, int secondary, u8 reg, u16 val); -static u16 ali_ac97_get(struct trident_card *card, int secondary, u8 reg); -static void ali_set_spdif_out_rate(struct trident_card *card, unsigned int rate); -static void ali_enable_special_channel(struct trident_state *stat); -static struct trident_channel *ali_alloc_rec_pcm_channel(struct trident_card *card); -static struct trident_channel *ali_alloc_pcm_channel(struct trident_card *card); -static void ali_free_pcm_channel(struct trident_card *card, unsigned int channel); -static int ali_setup_multi_channels(struct trident_card *card, int chan_nums); -static unsigned int ali_get_spdif_in_rate(struct trident_card *card); -static void ali_setup_spdif_in(struct trident_card *card); -static void ali_disable_spdif_in(struct trident_card *card); -static void ali_disable_special_channel(struct trident_card *card, int ch); -static void ali_setup_spdif_out(struct trident_card *card, int flag); -static int ali_write_5_1(struct trident_state *state, - const char __user *buffer, - int cnt_for_multi_channel, unsigned int *copy_count, - unsigned int *state_cnt); -static int ali_allocate_other_states_resources(struct trident_state *state, - int chan_nums); -static void ali_free_other_states_resources(struct trident_state *state); - -#define seek_offset(dma_ptr, buffer, cnt, offset, copy_count) do { \ - (dma_ptr) += (offset); \ - (buffer) += (offset); \ - (cnt) -= (offset); \ - (copy_count) += (offset); \ -} while (0) - -static inline int lock_set_fmt(struct trident_state* state) -{ - if (test_and_set_bit(0, &state->fmt_flag)) - return -EFAULT; - - return 0; -} - -static inline void unlock_set_fmt(struct trident_state* state) -{ - clear_bit(0, &state->fmt_flag); -} - -static int -trident_enable_loop_interrupts(struct trident_card *card) -{ - u32 global_control; - - global_control = inl(TRID_REG(card, T4D_LFO_GC_CIR)); - - switch (card->pci_id) { - case PCI_DEVICE_ID_SI_7018: - global_control |= (ENDLP_IE | MIDLP_IE | BANK_B_EN); - break; - case PCI_DEVICE_ID_ALI_5451: - case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX: - case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX: - case PCI_DEVICE_ID_INTERG_5050: - global_control |= (ENDLP_IE | MIDLP_IE); - break; - default: - return 0; - } - - outl(global_control, TRID_REG(card, T4D_LFO_GC_CIR)); - - pr_debug("trident: Enable Loop Interrupts, globctl = 0x%08X\n", - inl(TRID_REG(card, T4D_LFO_GC_CIR))); - - return 1; -} - -static int -trident_disable_loop_interrupts(struct trident_card *card) -{ - u32 global_control; - - global_control = inl(TRID_REG(card, T4D_LFO_GC_CIR)); - global_control &= ~(ENDLP_IE | MIDLP_IE); - outl(global_control, TRID_REG(card, T4D_LFO_GC_CIR)); - - pr_debug("trident: Disabled Loop Interrupts, globctl = 0x%08X\n", - global_control); - - return 1; -} - -static void -trident_enable_voice_irq(struct trident_card *card, unsigned int channel) -{ - unsigned int mask = 1 << (channel & 0x1f); - struct trident_pcm_bank *bank = &card->banks[channel >> 5]; - u32 reg, addr = bank->addresses->aint_en; - - reg = inl(TRID_REG(card, addr)); - reg |= mask; - outl(reg, TRID_REG(card, addr)); - -#ifdef DEBUG - reg = inl(TRID_REG(card, addr)); - pr_debug("trident: enabled IRQ on channel %d, %s = 0x%08x(addr:%X)\n", - channel, addr == T4D_AINTEN_B ? "AINTEN_B" : "AINTEN_A", - reg, addr); -#endif /* DEBUG */ -} - -static void -trident_disable_voice_irq(struct trident_card *card, unsigned int channel) -{ - unsigned int mask = 1 << (channel & 0x1f); - struct trident_pcm_bank *bank = &card->banks[channel >> 5]; - u32 reg, addr = bank->addresses->aint_en; - - reg = inl(TRID_REG(card, addr)); - reg &= ~mask; - outl(reg, TRID_REG(card, addr)); - - /* Ack the channel in case the interrupt was set before we disable it. */ - outl(mask, TRID_REG(card, bank->addresses->aint)); - -#ifdef DEBUG - reg = inl(TRID_REG(card, addr)); - pr_debug("trident: disabled IRQ on channel %d, %s = 0x%08x(addr:%X)\n", - channel, addr == T4D_AINTEN_B ? "AINTEN_B" : "AINTEN_A", - reg, addr); -#endif /* DEBUG */ -} - -static void -trident_start_voice(struct trident_card *card, unsigned int channel) -{ - unsigned int mask = 1 << (channel & 0x1f); - struct trident_pcm_bank *bank = &card->banks[channel >> 5]; - u32 addr = bank->addresses->start; - -#ifdef DEBUG - u32 reg; -#endif /* DEBUG */ - - outl(mask, TRID_REG(card, addr)); - -#ifdef DEBUG - reg = inl(TRID_REG(card, addr)); - pr_debug("trident: start voice on channel %d, %s = 0x%08x(addr:%X)\n", - channel, addr == T4D_START_B ? "START_B" : "START_A", - reg, addr); -#endif /* DEBUG */ -} - -static void -trident_stop_voice(struct trident_card *card, unsigned int channel) -{ - unsigned int mask = 1 << (channel & 0x1f); - struct trident_pcm_bank *bank = &card->banks[channel >> 5]; - u32 addr = bank->addresses->stop; - -#ifdef DEBUG - u32 reg; -#endif /* DEBUG */ - - outl(mask, TRID_REG(card, addr)); - -#ifdef DEBUG - reg = inl(TRID_REG(card, addr)); - pr_debug("trident: stop voice on channel %d, %s = 0x%08x(addr:%X)\n", - channel, addr == T4D_STOP_B ? "STOP_B" : "STOP_A", - reg, addr); -#endif /* DEBUG */ -} - -static u32 -trident_get_interrupt_mask(struct trident_card *card, unsigned int channel) -{ - struct trident_pcm_bank *bank = &card->banks[channel]; - u32 addr = bank->addresses->aint; - return inl(TRID_REG(card, addr)); -} - -static int -trident_check_channel_interrupt(struct trident_card *card, unsigned int channel) -{ - unsigned int mask = 1 << (channel & 0x1f); - u32 reg = trident_get_interrupt_mask(card, channel >> 5); - -#ifdef DEBUG - if (reg & mask) - pr_debug("trident: channel %d has interrupt, %s = 0x%08x\n", - channel, reg == T4D_AINT_B ? "AINT_B" : "AINT_A", - reg); -#endif /* DEBUG */ - return (reg & mask) ? 1 : 0; -} - -static void -trident_ack_channel_interrupt(struct trident_card *card, unsigned int channel) -{ - unsigned int mask = 1 << (channel & 0x1f); - struct trident_pcm_bank *bank = &card->banks[channel >> 5]; - u32 reg, addr = bank->addresses->aint; - - reg = inl(TRID_REG(card, addr)); - reg &= mask; - outl(reg, TRID_REG(card, addr)); - -#ifdef DEBUG - reg = inl(TRID_REG(card, T4D_AINT_B)); - pr_debug("trident: Ack channel %d interrupt, AINT_B = 0x%08x\n", - channel, reg); -#endif /* DEBUG */ -} - -static struct trident_channel * -trident_alloc_pcm_channel(struct trident_card *card) -{ - struct trident_pcm_bank *bank; - int idx; - - bank = &card->banks[BANK_B]; - - for (idx = 31; idx >= 0; idx--) { - if (!(bank->bitmap & (1 << idx))) { - struct trident_channel *channel = &bank->channels[idx]; - bank->bitmap |= 1 << idx; - channel->num = idx + 32; - return channel; - } - } - - /* no more free channels available */ - printk(KERN_ERR "trident: no more channels available on Bank B.\n"); - return NULL; -} - -static void -trident_free_pcm_channel(struct trident_card *card, unsigned int channel) -{ - int bank; - unsigned char b; - - if (channel < 31 || channel > 63) - return; - - if (card->pci_id == PCI_DEVICE_ID_TRIDENT_4DWAVE_DX || - card->pci_id == PCI_DEVICE_ID_TRIDENT_4DWAVE_NX) { - b = inb(TRID_REG(card, T4D_REC_CH)); - if ((b & ~0x80) == channel) - outb(0x0, TRID_REG(card, T4D_REC_CH)); - } - - bank = channel >> 5; - channel = channel & 0x1f; - - card->banks[bank].bitmap &= ~(1 << (channel)); -} - -static struct trident_channel * -cyber_alloc_pcm_channel(struct trident_card *card) -{ - struct trident_pcm_bank *bank; - int idx; - - /* The cyberpro 5050 has only 32 voices and one bank */ - /* .. at least they are not documented (if you want to call that - * crap documentation), perhaps broken ? */ - - bank = &card->banks[BANK_A]; - - for (idx = 31; idx >= 0; idx--) { - if (!(bank->bitmap & (1 << idx))) { - struct trident_channel *channel = &bank->channels[idx]; - bank->bitmap |= 1 << idx; - channel->num = idx; - return channel; - } - } - - /* no more free channels available */ - printk(KERN_ERR "cyberpro5050: no more channels available on Bank A.\n"); - return NULL; -} - -static void -cyber_free_pcm_channel(struct trident_card *card, unsigned int channel) -{ - if (channel > 31) - return; - card->banks[BANK_A].bitmap &= ~(1 << (channel)); -} - -static inline void -cyber_outidx(int port, int idx, int data) -{ - outb(idx, port); - outb(data, port + 1); -} - -static inline int -cyber_inidx(int port, int idx) -{ - outb(idx, port); - return inb(port + 1); -} - -static int -cyber_init_ritual(struct trident_card *card) -{ - /* some black magic, taken from SDK samples */ - /* remove this and nothing will work */ - int portDat; - int ret = 0; - unsigned long flags; - - /* - * Keep interrupts off for the configure - we don't want to - * clash with another cyberpro config event - */ - - spin_lock_irqsave(&card->lock, flags); - portDat = cyber_inidx(CYBER_PORT_AUDIO, CYBER_IDX_AUDIO_ENABLE); - /* enable, if it was disabled */ - if ((portDat & CYBER_BMSK_AUENZ) != CYBER_BMSK_AUENZ_ENABLE) { - printk(KERN_INFO "cyberpro5050: enabling audio controller\n"); - cyber_outidx(CYBER_PORT_AUDIO, CYBER_IDX_AUDIO_ENABLE, - portDat | CYBER_BMSK_AUENZ_ENABLE); - /* check again if hardware is enabled now */ - portDat = cyber_inidx(CYBER_PORT_AUDIO, CYBER_IDX_AUDIO_ENABLE); - } - if ((portDat & CYBER_BMSK_AUENZ) != CYBER_BMSK_AUENZ_ENABLE) { - printk(KERN_ERR "cyberpro5050: initAudioAccess: no success\n"); - ret = -1; - } else { - cyber_outidx(CYBER_PORT_AUDIO, CYBER_IDX_IRQ_ENABLE, - CYBER_BMSK_AUDIO_INT_ENABLE); - cyber_outidx(CYBER_PORT_AUDIO, 0xbf, 0x01); - cyber_outidx(CYBER_PORT_AUDIO, 0xba, 0x20); - cyber_outidx(CYBER_PORT_AUDIO, 0xbb, 0x08); - cyber_outidx(CYBER_PORT_AUDIO, 0xbf, 0x02); - cyber_outidx(CYBER_PORT_AUDIO, 0xb3, 0x06); - cyber_outidx(CYBER_PORT_AUDIO, 0xbf, 0x00); - } - spin_unlock_irqrestore(&card->lock, flags); - return ret; -} - -/* called with spin lock held */ - -static int -trident_load_channel_registers(struct trident_card *card, u32 * data, - unsigned int channel) -{ - int i; - - if (channel > 63) - return 0; - - /* select hardware channel to write */ - outb(channel, TRID_REG(card, T4D_LFO_GC_CIR)); - - /* Output the channel registers, but don't write register - three to an ALI chip. */ - for (i = 0; i < CHANNEL_REGS; i++) { - if (i == 3 && card->pci_id == PCI_DEVICE_ID_ALI_5451) - continue; - outl(data[i], TRID_REG(card, CHANNEL_START + 4 * i)); - } - if (card->pci_id == PCI_DEVICE_ID_ALI_5451 || - card->pci_id == PCI_DEVICE_ID_INTERG_5050) { - outl(ALI_EMOD_Still, TRID_REG(card, ALI_EBUF1)); - outl(ALI_EMOD_Still, TRID_REG(card, ALI_EBUF2)); - } - return 1; -} - -/* called with spin lock held */ -static int -trident_write_voice_regs(struct trident_state *state) -{ - unsigned int data[CHANNEL_REGS + 1]; - struct trident_channel *channel; - - channel = state->dmabuf.channel; - - data[1] = channel->lba; - data[4] = channel->control; - - switch (state->card->pci_id) { - case PCI_DEVICE_ID_ALI_5451: - data[0] = 0; /* Current Sample Offset */ - data[2] = (channel->eso << 16) | (channel->delta & 0xffff); - data[3] = 0; - break; - case PCI_DEVICE_ID_SI_7018: - case PCI_DEVICE_ID_INTERG_5050: - data[0] = 0; /* Current Sample Offset */ - data[2] = (channel->eso << 16) | (channel->delta & 0xffff); - data[3] = (channel->attribute << 16) | (channel->fm_vol & 0xffff); - break; - case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX: - data[0] = 0; /* Current Sample Offset */ - data[2] = (channel->eso << 16) | (channel->delta & 0xffff); - data[3] = channel->fm_vol & 0xffff; - break; - case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX: - data[0] = (channel->delta << 24); - data[2] = ((channel->delta << 16) & 0xff000000) | - (channel->eso & 0x00ffffff); - data[3] = channel->fm_vol & 0xffff; - break; - default: - return 0; - } - - return trident_load_channel_registers(state->card, data, channel->num); -} - -static int -compute_rate_play(u32 rate) -{ - int delta; - /* We special case 44100 and 8000 since rounding with the equation - does not give us an accurate enough value. For 11025 and 22050 - the equation gives us the best answer. All other frequencies will - also use the equation. JDW */ - if (rate == 44100) - delta = 0xeb3; - else if (rate == 8000) - delta = 0x2ab; - else if (rate == 48000) - delta = 0x1000; - else - delta = (((rate << 12) + rate) / 48000) & 0x0000ffff; - return delta; -} - -static int -compute_rate_rec(u32 rate) -{ - int delta; - - if (rate == 44100) - delta = 0x116a; - else if (rate == 8000) - delta = 0x6000; - else if (rate == 48000) - delta = 0x1000; - else - delta = ((48000 << 12) / rate) & 0x0000ffff; - - return delta; -} - -/* set playback sample rate */ -static unsigned int -trident_set_dac_rate(struct trident_state *state, unsigned int rate) -{ - struct dmabuf *dmabuf = &state->dmabuf; - - if (rate > 48000) - rate = 48000; - if (rate < 4000) - rate = 4000; - - dmabuf->rate = rate; - dmabuf->channel->delta = compute_rate_play(rate); - - trident_write_voice_regs(state); - - pr_debug("trident: called trident_set_dac_rate : rate = %d\n", rate); - - return rate; -} - -/* set recording sample rate */ -static unsigned int -trident_set_adc_rate(struct trident_state *state, unsigned int rate) -{ - struct dmabuf *dmabuf = &state->dmabuf; - - if (rate > 48000) - rate = 48000; - if (rate < 4000) - rate = 4000; - - dmabuf->rate = rate; - dmabuf->channel->delta = compute_rate_rec(rate); - - trident_write_voice_regs(state); - - pr_debug("trident: called trident_set_adc_rate : rate = %d\n", rate); - - return rate; -} - -/* prepare channel attributes for playback */ -static void -trident_play_setup(struct trident_state *state) -{ - struct dmabuf *dmabuf = &state->dmabuf; - struct trident_channel *channel = dmabuf->channel; - - channel->lba = dmabuf->dma_handle; - channel->delta = compute_rate_play(dmabuf->rate); - - channel->eso = dmabuf->dmasize >> sample_shift[dmabuf->fmt]; - channel->eso -= 1; - - if (state->card->pci_id != PCI_DEVICE_ID_SI_7018) { - channel->attribute = 0; - if (state->card->pci_id == PCI_DEVICE_ID_ALI_5451) { - if ((channel->num == ALI_SPDIF_IN_CHANNEL) || - (channel->num == ALI_PCM_IN_CHANNEL)) - ali_disable_special_channel(state->card, channel->num); - else if ((inl(TRID_REG(state->card, ALI_GLOBAL_CONTROL)) - & ALI_SPDIF_OUT_CH_ENABLE) - && (channel->num == ALI_SPDIF_OUT_CHANNEL)) { - ali_set_spdif_out_rate(state->card, - state->dmabuf.rate); - state->dmabuf.channel->delta = 0x1000; - } - } - } - - channel->fm_vol = 0x0; - - channel->control = CHANNEL_LOOP; - if (dmabuf->fmt & TRIDENT_FMT_16BIT) { - /* 16-bits */ - channel->control |= CHANNEL_16BITS; - /* signed */ - channel->control |= CHANNEL_SIGNED; - } - if (dmabuf->fmt & TRIDENT_FMT_STEREO) - /* stereo */ - channel->control |= CHANNEL_STEREO; - - pr_debug("trident: trident_play_setup, LBA = 0x%08x, Delta = 0x%08x, " - "ESO = 0x%08x, Control = 0x%08x\n", channel->lba, - channel->delta, channel->eso, channel->control); - - trident_write_voice_regs(state); -} - -/* prepare channel attributes for recording */ -static void -trident_rec_setup(struct trident_state *state) -{ - u16 w; - u8 bval; - - struct trident_card *card = state->card; - struct dmabuf *dmabuf = &state->dmabuf; - struct trident_channel *channel = dmabuf->channel; - unsigned int rate; - - /* Enable AC-97 ADC (capture) */ - switch (card->pci_id) { - case PCI_DEVICE_ID_ALI_5451: - ali_enable_special_channel(state); - break; - case PCI_DEVICE_ID_SI_7018: - /* for 7018, the ac97 is always in playback/record (duplex) mode */ - break; - case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX: - w = inb(TRID_REG(card, DX_ACR2_AC97_COM_STAT)); - outb(w | 0x48, TRID_REG(card, DX_ACR2_AC97_COM_STAT)); - /* enable and set record channel */ - outb(0x80 | channel->num, TRID_REG(card, T4D_REC_CH)); - break; - case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX: - w = inw(TRID_REG(card, T4D_MISCINT)); - outw(w | 0x1000, TRID_REG(card, T4D_MISCINT)); - /* enable and set record channel */ - outb(0x80 | channel->num, TRID_REG(card, T4D_REC_CH)); - break; - case PCI_DEVICE_ID_INTERG_5050: - /* don't know yet, using special channel 22 in GC1(0xd4)? */ - break; - default: - return; - } - - channel->lba = dmabuf->dma_handle; - channel->delta = compute_rate_rec(dmabuf->rate); - if ((card->pci_id == PCI_DEVICE_ID_ALI_5451) && - (channel->num == ALI_SPDIF_IN_CHANNEL)) { - rate = ali_get_spdif_in_rate(card); - if (rate == 0) { - printk(KERN_WARNING "trident: ALi 5451 " - "S/PDIF input setup error!\n"); - rate = 48000; - } - bval = inb(TRID_REG(card, ALI_SPDIF_CTRL)); - if (bval & 0x10) { - outb(bval, TRID_REG(card, ALI_SPDIF_CTRL)); - printk(KERN_WARNING "trident: cleared ALi " - "5451 S/PDIF parity error flag.\n"); - } - - if (rate != 48000) - channel->delta = ((rate << 12) / dmabuf->rate) & 0x0000ffff; - } - - channel->eso = dmabuf->dmasize >> sample_shift[dmabuf->fmt]; - channel->eso -= 1; - - if (state->card->pci_id != PCI_DEVICE_ID_SI_7018) { - channel->attribute = 0; - } - - channel->fm_vol = 0x0; - - channel->control = CHANNEL_LOOP; - if (dmabuf->fmt & TRIDENT_FMT_16BIT) { - /* 16-bits */ - channel->control |= CHANNEL_16BITS; - /* signed */ - channel->control |= CHANNEL_SIGNED; - } - if (dmabuf->fmt & TRIDENT_FMT_STEREO) - /* stereo */ - channel->control |= CHANNEL_STEREO; - - pr_debug("trident: trident_rec_setup, LBA = 0x%08x, Delat = 0x%08x, " - "ESO = 0x%08x, Control = 0x%08x\n", channel->lba, - channel->delta, channel->eso, channel->control); - - trident_write_voice_regs(state); -} - -/* get current playback/recording dma buffer pointer (byte offset from LBA), - called with spinlock held! */ -static inline unsigned -trident_get_dma_addr(struct trident_state *state) -{ - struct dmabuf *dmabuf = &state->dmabuf; - u32 cso; - - if (!dmabuf->enable) - return 0; - - outb(dmabuf->channel->num, TRID_REG(state->card, T4D_LFO_GC_CIR)); - - switch (state->card->pci_id) { - case PCI_DEVICE_ID_ALI_5451: - case PCI_DEVICE_ID_SI_7018: - case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX: - case PCI_DEVICE_ID_INTERG_5050: - /* 16 bits ESO, CSO for 7018 and DX */ - cso = inw(TRID_REG(state->card, CH_DX_CSO_ALPHA_FMS + 2)); - break; - case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX: - /* 24 bits ESO, CSO for NX */ - cso = inl(TRID_REG(state->card, CH_NX_DELTA_CSO)) & 0x00ffffff; - break; - default: - return 0; - } - - pr_debug("trident: trident_get_dma_addr: chip reported channel: %d, " - "cso = 0x%04x\n", dmabuf->channel->num, cso); - - /* ESO and CSO are in units of Samples, convert to byte offset */ - cso <<= sample_shift[dmabuf->fmt]; - - return (cso % dmabuf->dmasize); -} - -/* Stop recording (lock held) */ -static inline void -__stop_adc(struct trident_state *state) -{ - struct dmabuf *dmabuf = &state->dmabuf; - unsigned int chan_num = dmabuf->channel->num; - struct trident_card *card = state->card; - - dmabuf->enable &= ~ADC_RUNNING; - trident_stop_voice(card, chan_num); - trident_disable_voice_irq(card, chan_num); -} - -static void -stop_adc(struct trident_state *state) -{ - struct trident_card *card = state->card; - unsigned long flags; - - spin_lock_irqsave(&card->lock, flags); - __stop_adc(state); - spin_unlock_irqrestore(&card->lock, flags); -} - -static void -start_adc(struct trident_state *state) -{ - struct dmabuf *dmabuf = &state->dmabuf; - unsigned int chan_num = dmabuf->channel->num; - struct trident_card *card = state->card; - unsigned long flags; - - spin_lock_irqsave(&card->lock, flags); - if ((dmabuf->mapped || - dmabuf->count < (signed) dmabuf->dmasize) && - dmabuf->ready) { - dmabuf->enable |= ADC_RUNNING; - trident_enable_voice_irq(card, chan_num); - trident_start_voice(card, chan_num); - } - spin_unlock_irqrestore(&card->lock, flags); -} - -/* stop playback (lock held) */ -static inline void -__stop_dac(struct trident_state *state) -{ - struct dmabuf *dmabuf = &state->dmabuf; - unsigned int chan_num = dmabuf->channel->num; - struct trident_card *card = state->card; - - dmabuf->enable &= ~DAC_RUNNING; - trident_stop_voice(card, chan_num); - if (state->chans_num == 6) { - trident_stop_voice(card, state->other_states[0]-> - dmabuf.channel->num); - trident_stop_voice(card, state->other_states[1]-> - dmabuf.channel->num); - trident_stop_voice(card, state->other_states[2]-> - dmabuf.channel->num); - trident_stop_voice(card, state->other_states[3]-> - dmabuf.channel->num); - } - trident_disable_voice_irq(card, chan_num); -} - -static void -stop_dac(struct trident_state *state) -{ - struct trident_card *card = state->card; - unsigned long flags; - - spin_lock_irqsave(&card->lock, flags); - __stop_dac(state); - spin_unlock_irqrestore(&card->lock, flags); -} - -static void -start_dac(struct trident_state *state) -{ - struct dmabuf *dmabuf = &state->dmabuf; - unsigned int chan_num = dmabuf->channel->num; - struct trident_card *card = state->card; - unsigned long flags; - - spin_lock_irqsave(&card->lock, flags); - if ((dmabuf->mapped || dmabuf->count > 0) && dmabuf->ready) { - dmabuf->enable |= DAC_RUNNING; - trident_enable_voice_irq(card, chan_num); - trident_start_voice(card, chan_num); - if (state->chans_num == 6) { - trident_start_voice(card, state->other_states[0]-> - dmabuf.channel->num); - trident_start_voice(card, state->other_states[1]-> - dmabuf.channel->num); - trident_start_voice(card, state->other_states[2]-> - dmabuf.channel->num); - trident_start_voice(card, state->other_states[3]-> - dmabuf.channel->num); - } - } - spin_unlock_irqrestore(&card->lock, flags); -} - -#define DMABUF_DEFAULTORDER (15-PAGE_SHIFT) -#define DMABUF_MINORDER 1 - -/* alloc a DMA buffer of with a buffer of this order */ -static int -alloc_dmabuf(struct dmabuf *dmabuf, struct pci_dev *pci_dev, int order) -{ - void *rawbuf = NULL; - struct page *page, *pend; - - if (!(rawbuf = pci_alloc_consistent(pci_dev, PAGE_SIZE << order, - &dmabuf->dma_handle))) - return -ENOMEM; - - pr_debug("trident: allocated %ld (order = %d) bytes at %p\n", - PAGE_SIZE << order, order, rawbuf); - - dmabuf->ready = dmabuf->mapped = 0; - dmabuf->rawbuf = rawbuf; - dmabuf->buforder = order; - - /* now mark the pages as reserved; otherwise */ - /* remap_pfn_range doesn't do what we want */ - pend = virt_to_page(rawbuf + (PAGE_SIZE << order) - 1); - for (page = virt_to_page(rawbuf); page <= pend; page++) - SetPageReserved(page); - - return 0; -} - -/* allocate the main DMA buffer, playback and recording buffer should be */ -/* allocated separately */ -static int -alloc_main_dmabuf(struct trident_state *state) -{ - struct dmabuf *dmabuf = &state->dmabuf; - int order; - int ret = -ENOMEM; - - /* alloc as big a chunk as we can, FIXME: is this necessary ?? */ - for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--) { - if (!(ret = alloc_dmabuf(dmabuf, state->card->pci_dev, order))) - return 0; - /* else try again */ - } - return ret; -} - -/* deallocate a DMA buffer */ -static void -dealloc_dmabuf(struct dmabuf *dmabuf, struct pci_dev *pci_dev) -{ - struct page *page, *pend; - - if (dmabuf->rawbuf) { - /* undo marking the pages as reserved */ - pend = virt_to_page(dmabuf->rawbuf + (PAGE_SIZE << dmabuf->buforder) - 1); - for (page = virt_to_page(dmabuf->rawbuf); page <= pend; page++) - ClearPageReserved(page); - pci_free_consistent(pci_dev, PAGE_SIZE << dmabuf->buforder, - dmabuf->rawbuf, dmabuf->dma_handle); - dmabuf->rawbuf = NULL; - } - dmabuf->mapped = dmabuf->ready = 0; -} - -static int -prog_dmabuf(struct trident_state *state, enum dmabuf_mode rec) -{ - struct dmabuf *dmabuf = &state->dmabuf; - unsigned bytepersec; - struct trident_state *s = state; - unsigned bufsize, dma_nums; - unsigned long flags; - int ret, i, order; - - if ((ret = lock_set_fmt(state)) < 0) - return ret; - - if (state->chans_num == 6) - dma_nums = 5; - else - dma_nums = 1; - - for (i = 0; i < dma_nums; i++) { - if (i > 0) { - s = state->other_states[i - 1]; - dmabuf = &s->dmabuf; - dmabuf->fmt = state->dmabuf.fmt; - dmabuf->rate = state->dmabuf.rate; - } - - spin_lock_irqsave(&s->card->lock, flags); - dmabuf->hwptr = dmabuf->swptr = dmabuf->total_bytes = 0; - dmabuf->count = dmabuf->error = 0; - spin_unlock_irqrestore(&s->card->lock, flags); - - /* allocate DMA buffer if not allocated yet */ - if (!dmabuf->rawbuf) { - if (i == 0) { - if ((ret = alloc_main_dmabuf(state))) { - unlock_set_fmt(state); - return ret; - } - } else { - ret = -ENOMEM; - order = state->dmabuf.buforder - 1; - if (order >= DMABUF_MINORDER) { - ret = alloc_dmabuf(dmabuf, - state->card->pci_dev, - order); - } - if (ret) { - /* release the main DMA buffer */ - dealloc_dmabuf(&state->dmabuf, state->card->pci_dev); - /* release the auxiliary DMA buffers */ - for (i -= 2; i >= 0; i--) - dealloc_dmabuf(&state->other_states[i]->dmabuf, - state->card->pci_dev); - unlock_set_fmt(state); - return ret; - } - } - } - /* FIXME: figure out all this OSS fragment stuff */ - bytepersec = dmabuf->rate << sample_shift[dmabuf->fmt]; - bufsize = PAGE_SIZE << dmabuf->buforder; - if (dmabuf->ossfragshift) { - if ((1000 << dmabuf->ossfragshift) < bytepersec) - dmabuf->fragshift = ld2(bytepersec / 1000); - else - dmabuf->fragshift = dmabuf->ossfragshift; - } else { - /* lets hand out reasonable big ass buffers by default */ - dmabuf->fragshift = (dmabuf->buforder + PAGE_SHIFT - 2); - } - dmabuf->numfrag = bufsize >> dmabuf->fragshift; - while (dmabuf->numfrag < 4 && dmabuf->fragshift > 3) { - dmabuf->fragshift--; - dmabuf->numfrag = bufsize >> dmabuf->fragshift; - } - dmabuf->fragsize = 1 << dmabuf->fragshift; - if (dmabuf->ossmaxfrags >= 4 && dmabuf->ossmaxfrags < dmabuf->numfrag) - dmabuf->numfrag = dmabuf->ossmaxfrags; - dmabuf->fragsamples = dmabuf->fragsize >> sample_shift[dmabuf->fmt]; - dmabuf->dmasize = dmabuf->numfrag << dmabuf->fragshift; - - memset(dmabuf->rawbuf, (dmabuf->fmt & TRIDENT_FMT_16BIT) ? 0 : 0x80, - dmabuf->dmasize); - - spin_lock_irqsave(&s->card->lock, flags); - if (rec == DM_RECORD) - trident_rec_setup(s); - else /* DM_PLAYBACK */ - trident_play_setup(s); - - spin_unlock_irqrestore(&s->card->lock, flags); - - /* set the ready flag for the dma buffer */ - dmabuf->ready = 1; - - pr_debug("trident: prog_dmabuf(%d), sample rate = %d, " - "format = %d, numfrag = %d, fragsize = %d " - "dmasize = %d\n", dmabuf->channel->num, - dmabuf->rate, dmabuf->fmt, dmabuf->numfrag, - dmabuf->fragsize, dmabuf->dmasize); - } - unlock_set_fmt(state); - return 0; -} - - -static inline int prog_dmabuf_record(struct trident_state* state) -{ - return prog_dmabuf(state, DM_RECORD); -} - -static inline int prog_dmabuf_playback(struct trident_state* state) -{ - return prog_dmabuf(state, DM_PLAYBACK); -} - -/* we are doing quantum mechanics here, the buffer can only be empty, half or full filled i.e. - |------------|------------| or |xxxxxxxxxxxx|------------| or |xxxxxxxxxxxx|xxxxxxxxxxxx| - but we almost always get this - |xxxxxx------|------------| or |xxxxxxxxxxxx|xxxxx-------| - so we have to clear the tail space to "silence" - |xxxxxx000000|------------| or |xxxxxxxxxxxx|xxxxxx000000| -*/ -static void -trident_clear_tail(struct trident_state *state) -{ - struct dmabuf *dmabuf = &state->dmabuf; - unsigned swptr; - unsigned char silence = (dmabuf->fmt & TRIDENT_FMT_16BIT) ? 0 : 0x80; - unsigned int len; - unsigned long flags; - - spin_lock_irqsave(&state->card->lock, flags); - swptr = dmabuf->swptr; - spin_unlock_irqrestore(&state->card->lock, flags); - - if (swptr == 0 || swptr == dmabuf->dmasize / 2 || - swptr == dmabuf->dmasize) - return; - - if (swptr < dmabuf->dmasize / 2) - len = dmabuf->dmasize / 2 - swptr; - else - len = dmabuf->dmasize - swptr; - - memset(dmabuf->rawbuf + swptr, silence, len); - if (state->card->pci_id != PCI_DEVICE_ID_ALI_5451) { - spin_lock_irqsave(&state->card->lock, flags); - dmabuf->swptr += len; - dmabuf->count += len; - spin_unlock_irqrestore(&state->card->lock, flags); - } - - /* restart the dma machine in case it is halted */ - start_dac(state); -} - -static int -drain_dac(struct trident_state *state, int nonblock) -{ - DECLARE_WAITQUEUE(wait, current); - struct dmabuf *dmabuf = &state->dmabuf; - unsigned long flags; - unsigned long tmo; - int count; - unsigned long diff = 0; - - if (dmabuf->mapped || !dmabuf->ready) - return 0; - - add_wait_queue(&dmabuf->wait, &wait); - for (;;) { - /* It seems that we have to set the current state to TASK_INTERRUPTIBLE - every time to make the process really go to sleep */ - set_current_state(TASK_INTERRUPTIBLE); - - spin_lock_irqsave(&state->card->lock, flags); - count = dmabuf->count; - spin_unlock_irqrestore(&state->card->lock, flags); - - if (count <= 0) - break; - - if (signal_pending(current)) - break; - - if (nonblock) { - remove_wait_queue(&dmabuf->wait, &wait); - set_current_state(TASK_RUNNING); - return -EBUSY; - } - - /* No matter how much data is left in the buffer, we have to wait until - CSO == ESO/2 or CSO == ESO when address engine interrupts */ - if (state->card->pci_id == PCI_DEVICE_ID_ALI_5451 || - state->card->pci_id == PCI_DEVICE_ID_INTERG_5050) { - diff = dmabuf->swptr - trident_get_dma_addr(state) + dmabuf->dmasize; - diff = diff % (dmabuf->dmasize); - tmo = (diff * HZ) / dmabuf->rate; - } else { - tmo = (dmabuf->dmasize * HZ) / dmabuf->rate; - } - tmo >>= sample_shift[dmabuf->fmt]; - if (!schedule_timeout(tmo ? tmo : 1) && tmo) { - break; - } - } - remove_wait_queue(&dmabuf->wait, &wait); - set_current_state(TASK_RUNNING); - if (signal_pending(current)) - return -ERESTARTSYS; - - return 0; -} - -/* update buffer manangement pointers, especially, */ -/* dmabuf->count and dmabuf->hwptr */ -static void -trident_update_ptr(struct trident_state *state) -{ - struct dmabuf *dmabuf = &state->dmabuf; - unsigned hwptr, swptr; - int clear_cnt = 0; - int diff; - unsigned char silence; - unsigned half_dmasize; - - /* update hardware pointer */ - hwptr = trident_get_dma_addr(state); - diff = (dmabuf->dmasize + hwptr - dmabuf->hwptr) % dmabuf->dmasize; - dmabuf->hwptr = hwptr; - dmabuf->total_bytes += diff; - - /* error handling and process wake up for ADC */ - if (dmabuf->enable == ADC_RUNNING) { - if (dmabuf->mapped) { - dmabuf->count -= diff; - if (dmabuf->count >= (signed) dmabuf->fragsize) - wake_up(&dmabuf->wait); - } else { - dmabuf->count += diff; - - if (dmabuf->count < 0 || - dmabuf->count > dmabuf->dmasize) { - /* buffer underrun or buffer overrun, */ - /* we have no way to recover it here, just */ - /* stop the machine and let the process */ - /* force hwptr and swptr to sync */ - __stop_adc(state); - dmabuf->error++; - } - if (dmabuf->count < (signed) dmabuf->dmasize / 2) - wake_up(&dmabuf->wait); - } - } - - /* error handling and process wake up for DAC */ - if (dmabuf->enable == DAC_RUNNING) { - if (dmabuf->mapped) { - dmabuf->count += diff; - if (dmabuf->count >= (signed) dmabuf->fragsize) - wake_up(&dmabuf->wait); - } else { - dmabuf->count -= diff; - - if (dmabuf->count < 0 || - dmabuf->count > dmabuf->dmasize) { - /* buffer underrun or buffer overrun, we have no way to recover - it here, just stop the machine and let the process force hwptr - and swptr to sync */ - __stop_dac(state); - dmabuf->error++; - } else if (!dmabuf->endcleared) { - swptr = dmabuf->swptr; - silence = (dmabuf->fmt & TRIDENT_FMT_16BIT ? 0 : 0x80); - if (dmabuf->update_flag & ALI_ADDRESS_INT_UPDATE) { - /* We must clear end data of 1/2 dmabuf if needed. - According to 1/2 algorithm of Address Engine Interrupt, - check the validation of the data of half dmasize. */ - half_dmasize = dmabuf->dmasize / 2; - if ((diff = hwptr - half_dmasize) < 0) - diff = hwptr; - if ((dmabuf->count + diff) < half_dmasize) { - //there is invalid data in the end of half buffer - if ((clear_cnt = half_dmasize - swptr) < 0) - clear_cnt += half_dmasize; - //clear the invalid data - memset(dmabuf->rawbuf + swptr, silence, clear_cnt); - if (state->chans_num == 6) { - clear_cnt = clear_cnt / 2; - swptr = swptr / 2; - memset(state->other_states[0]->dmabuf.rawbuf + swptr, - silence, clear_cnt); - memset(state->other_states[1]->dmabuf.rawbuf + swptr, - silence, clear_cnt); - memset(state->other_states[2]->dmabuf.rawbuf + swptr, - silence, clear_cnt); - memset(state->other_states[3]->dmabuf.rawbuf + swptr, - silence, clear_cnt); - } - dmabuf->endcleared = 1; - } - } else if (dmabuf->count < (signed) dmabuf->fragsize) { - clear_cnt = dmabuf->fragsize; - if ((swptr + clear_cnt) > dmabuf->dmasize) - clear_cnt = dmabuf->dmasize - swptr; - memset(dmabuf->rawbuf + swptr, silence, clear_cnt); - if (state->chans_num == 6) { - clear_cnt = clear_cnt / 2; - swptr = swptr / 2; - memset(state->other_states[0]->dmabuf.rawbuf + swptr, - silence, clear_cnt); - memset(state->other_states[1]->dmabuf.rawbuf + swptr, - silence, clear_cnt); - memset(state->other_states[2]->dmabuf.rawbuf + swptr, - silence, clear_cnt); - memset(state->other_states[3]->dmabuf.rawbuf + swptr, - silence, clear_cnt); - } - dmabuf->endcleared = 1; - } - } - /* trident_update_ptr is called by interrupt handler or by process via - ioctl/poll, we only wake up the waiting process when we have more - than 1/2 buffer free (always true for interrupt handler) */ - if (dmabuf->count < (signed) dmabuf->dmasize / 2) - wake_up(&dmabuf->wait); - } - } - dmabuf->update_flag &= ~ALI_ADDRESS_INT_UPDATE; -} - -static void -trident_address_interrupt(struct trident_card *card) -{ - int i; - struct trident_state *state; - unsigned int channel; - - /* Update the pointers for all channels we are running. */ - /* FIXME: should read interrupt status only once */ - for (i = 0; i < NR_HW_CH; i++) { - channel = 63 - i; - if (trident_check_channel_interrupt(card, channel)) { - trident_ack_channel_interrupt(card, channel); - if ((state = card->states[i]) != NULL) { - trident_update_ptr(state); - } else { - printk(KERN_WARNING "trident: spurious channel " - "irq %d.\n", channel); - trident_stop_voice(card, channel); - trident_disable_voice_irq(card, channel); - } - } - } -} - -static void -ali_hwvol_control(struct trident_card *card, int opt) -{ - u16 dwTemp, volume[2], mute, diff, *pVol[2]; - - dwTemp = ali_ac97_read(card->ac97_codec[0], 0x02); - mute = dwTemp & 0x8000; - volume[0] = dwTemp & 0x001f; - volume[1] = (dwTemp & 0x1f00) >> 8; - if (volume[0] < volume[1]) { - pVol[0] = &volume[0]; - pVol[1] = &volume[1]; - } else { - pVol[1] = &volume[0]; - pVol[0] = &volume[1]; - } - diff = *(pVol[1]) - *(pVol[0]); - - if (opt == 1) { // MUTE - dwTemp ^= 0x8000; - ali_ac97_write(card->ac97_codec[0], - 0x02, dwTemp); - } else if (opt == 2) { // Down - if (mute) - return; - if (*(pVol[1]) < 0x001f) { - (*pVol[1])++; - *(pVol[0]) = *(pVol[1]) - diff; - } - dwTemp &= 0xe0e0; - dwTemp |= (volume[0]) | (volume[1] << 8); - ali_ac97_write(card->ac97_codec[0], 0x02, dwTemp); - card->ac97_codec[0]->mixer_state[0] = ((32 - volume[0]) * 25 / 8) | - (((32 - volume[1]) * 25 / 8) << 8); - } else if (opt == 4) { // Up - if (mute) - return; - if (*(pVol[0]) > 0) { - (*pVol[0])--; - *(pVol[1]) = *(pVol[0]) + diff; - } - dwTemp &= 0xe0e0; - dwTemp |= (volume[0]) | (volume[1] << 8); - ali_ac97_write(card->ac97_codec[0], 0x02, dwTemp); - card->ac97_codec[0]->mixer_state[0] = ((32 - volume[0]) * 25 / 8) | - (((32 - volume[1]) * 25 / 8) << 8); - } else { - /* Nothing needs doing */ - } -} - -/* - * Re-enable reporting of vol change after 0.1 seconds - */ - -static void -ali_timeout(unsigned long ptr) -{ - struct trident_card *card = (struct trident_card *) ptr; - u16 temp = 0; - - /* Enable GPIO IRQ (MISCINT bit 18h) */ - temp = inw(TRID_REG(card, T4D_MISCINT + 2)); - temp |= 0x0004; - outw(temp, TRID_REG(card, T4D_MISCINT + 2)); -} - -/* - * Set up the timer to clear the vol change notification - */ - -static void -ali_set_timer(struct trident_card *card) -{ - /* Add Timer Routine to Enable GPIO IRQ */ - del_timer(&card->timer); /* Never queue twice */ - card->timer.function = ali_timeout; - card->timer.data = (unsigned long) card; - card->timer.expires = jiffies + HZ / 10; - add_timer(&card->timer); -} - -/* - * Process a GPIO event - */ - -static void -ali_queue_task(struct trident_card *card, int opt) -{ - u16 temp; - - /* Disable GPIO IRQ (MISCINT bit 18h) */ - temp = inw(TRID_REG(card, T4D_MISCINT + 2)); - temp &= (u16) (~0x0004); - outw(temp, TRID_REG(card, T4D_MISCINT + 2)); - - /* Adjust the volume */ - ali_hwvol_control(card, opt); - - /* Set the timer for 1/10th sec */ - ali_set_timer(card); -} - -static void -cyber_address_interrupt(struct trident_card *card) -{ - int i, irq_status; - struct trident_state *state; - unsigned int channel; - - /* Update the pointers for all channels we are running. */ - /* FIXED: read interrupt status only once */ - irq_status = inl(TRID_REG(card, T4D_AINT_A)); - - pr_debug("cyber_address_interrupt: irq_status 0x%X\n", irq_status); - - for (i = 0; i < NR_HW_CH; i++) { - channel = 31 - i; - if (irq_status & (1 << channel)) { - /* clear bit by writing a 1, zeroes are ignored */ - outl((1 << channel), TRID_REG(card, T4D_AINT_A)); - - pr_debug("cyber_interrupt: channel %d\n", channel); - - if ((state = card->states[i]) != NULL) { - trident_update_ptr(state); - } else { - printk(KERN_WARNING "cyber5050: spurious " - "channel irq %d.\n", channel); - trident_stop_voice(card, channel); - trident_disable_voice_irq(card, channel); - } - } - } -} - -static irqreturn_t -trident_interrupt(int irq, void *dev_id) -{ - struct trident_card *card = (struct trident_card *) dev_id; - u32 event; - u32 gpio; - - spin_lock(&card->lock); - event = inl(TRID_REG(card, T4D_MISCINT)); - - pr_debug("trident: trident_interrupt called, MISCINT = 0x%08x\n", - event); - - if (event & ADDRESS_IRQ) { - card->address_interrupt(card); - } - - if (card->pci_id == PCI_DEVICE_ID_ALI_5451) { - /* GPIO IRQ (H/W Volume Control) */ - event = inl(TRID_REG(card, T4D_MISCINT)); - if (event & (1 << 25)) { - gpio = inl(TRID_REG(card, ALI_GPIO)); - if (!timer_pending(&card->timer)) - ali_queue_task(card, gpio & 0x07); - } - event = inl(TRID_REG(card, T4D_MISCINT)); - outl(event | (ST_TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW), - TRID_REG(card, T4D_MISCINT)); - spin_unlock(&card->lock); - return IRQ_HANDLED; - } - - /* manually clear interrupt status, bad hardware design, blame T^2 */ - outl((ST_TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW), - TRID_REG(card, T4D_MISCINT)); - spin_unlock(&card->lock); - return IRQ_HANDLED; -} - -/* in this loop, dmabuf.count signifies the amount of data that is waiting */ -/* to be copied to the user's buffer. it is filled by the dma machine and */ -/* drained by this loop. */ -static ssize_t -trident_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos) -{ - struct trident_state *state = (struct trident_state *)file->private_data; - struct dmabuf *dmabuf = &state->dmabuf; - ssize_t ret = 0; - unsigned long flags; - unsigned swptr; - int cnt; - - pr_debug("trident: trident_read called, count = %zd\n", count); - - VALIDATE_STATE(state); - - if (dmabuf->mapped) - return -ENXIO; - if (!access_ok(VERIFY_WRITE, buffer, count)) - return -EFAULT; - - mutex_lock(&state->sem); - if (!dmabuf->ready && (ret = prog_dmabuf_record(state))) - goto out; - - while (count > 0) { - spin_lock_irqsave(&state->card->lock, flags); - if (dmabuf->count > (signed) dmabuf->dmasize) { - /* buffer overrun, we are recovering from */ - /* sleep_on_timeout, resync hwptr and swptr, */ - /* make process flush the buffer */ - dmabuf->count = dmabuf->dmasize; - dmabuf->swptr = dmabuf->hwptr; - } - swptr = dmabuf->swptr; - cnt = dmabuf->dmasize - swptr; - if (dmabuf->count < cnt) - cnt = dmabuf->count; - spin_unlock_irqrestore(&state->card->lock, flags); - - if (cnt > count) - cnt = count; - if (cnt <= 0) { - unsigned long tmo; - /* buffer is empty, start the dma machine and */ - /* wait for data to be recorded */ - start_adc(state); - if (file->f_flags & O_NONBLOCK) { - if (!ret) - ret = -EAGAIN; - goto out; - } - - mutex_unlock(&state->sem); - /* No matter how much space left in the buffer, */ - /* we have to wait until CSO == ESO/2 or CSO == ESO */ - /* when address engine interrupts */ - tmo = (dmabuf->dmasize * HZ) / (dmabuf->rate * 2); - tmo >>= sample_shift[dmabuf->fmt]; - /* There are two situations when sleep_on_timeout returns, one is when - the interrupt is serviced correctly and the process is waked up by - ISR ON TIME. Another is when timeout is expired, which means that - either interrupt is NOT serviced correctly (pending interrupt) or it - is TOO LATE for the process to be scheduled to run (scheduler latency) - which results in a (potential) buffer overrun. And worse, there is - NOTHING we can do to prevent it. */ - if (!interruptible_sleep_on_timeout(&dmabuf->wait, tmo)) { - pr_debug(KERN_ERR "trident: recording schedule timeout, " - "dmasz %u fragsz %u count %i hwptr %u swptr %u\n", - dmabuf->dmasize, dmabuf->fragsize, dmabuf->count, - dmabuf->hwptr, dmabuf->swptr); - - /* a buffer overrun, we delay the recovery until next time the - while loop begin and we REALLY have space to record */ - } - if (signal_pending(current)) { - if (!ret) - ret = -ERESTARTSYS; - goto out; - } - mutex_lock(&state->sem); - if (dmabuf->mapped) { - if (!ret) - ret = -ENXIO; - goto out; - } - continue; - } - - if (copy_to_user(buffer, dmabuf->rawbuf + swptr, cnt)) { - if (!ret) - ret = -EFAULT; - goto out; - } - - swptr = (swptr + cnt) % dmabuf->dmasize; - - spin_lock_irqsave(&state->card->lock, flags); - dmabuf->swptr = swptr; - dmabuf->count -= cnt; - spin_unlock_irqrestore(&state->card->lock, flags); - - count -= cnt; - buffer += cnt; - ret += cnt; - start_adc(state); - } -out: - mutex_unlock(&state->sem); - return ret; -} - -/* in this loop, dmabuf.count signifies the amount of data that is waiting to be dma to - the soundcard. it is drained by the dma machine and filled by this loop. */ - -static ssize_t -trident_write(struct file *file, const char __user *buffer, size_t count, loff_t * ppos) -{ - struct trident_state *state = (struct trident_state *)file->private_data; - struct dmabuf *dmabuf = &state->dmabuf; - ssize_t ret; - unsigned long flags; - unsigned swptr; - int cnt; - unsigned int state_cnt; - unsigned int copy_count; - int lret; /* for lock_set_fmt */ - - pr_debug("trident: trident_write called, count = %zd\n", count); - - VALIDATE_STATE(state); - - /* - * Guard against an mmap or ioctl while writing - */ - - mutex_lock(&state->sem); - - if (dmabuf->mapped) { - ret = -ENXIO; - goto out; - } - if (!dmabuf->ready && (ret = prog_dmabuf_playback(state))) - goto out; - - if (!access_ok(VERIFY_READ, buffer, count)) { - ret = -EFAULT; - goto out; - } - - ret = 0; - - while (count > 0) { - spin_lock_irqsave(&state->card->lock, flags); - if (dmabuf->count < 0) { - /* buffer underrun, we are recovering from */ - /* sleep_on_timeout, resync hwptr and swptr */ - dmabuf->count = 0; - dmabuf->swptr = dmabuf->hwptr; - } - swptr = dmabuf->swptr; - cnt = dmabuf->dmasize - swptr; - if (dmabuf->count + cnt > dmabuf->dmasize) - cnt = dmabuf->dmasize - dmabuf->count; - spin_unlock_irqrestore(&state->card->lock, flags); - - if (cnt > count) - cnt = count; - if (cnt <= 0) { - unsigned long tmo; - /* buffer is full, start the dma machine and */ - /* wait for data to be played */ - start_dac(state); - if (file->f_flags & O_NONBLOCK) { - if (!ret) - ret = -EAGAIN; - goto out; - } - /* No matter how much data left in the buffer, */ - /* we have to wait until CSO == ESO/2 or CSO == ESO */ - /* when address engine interrupts */ - lock_set_fmt(state); - tmo = (dmabuf->dmasize * HZ) / (dmabuf->rate * 2); - tmo >>= sample_shift[dmabuf->fmt]; - unlock_set_fmt(state); - mutex_unlock(&state->sem); - - /* There are two situations when sleep_on_timeout */ - /* returns, one is when the interrupt is serviced */ - /* correctly and the process is waked up by ISR */ - /* ON TIME. Another is when timeout is expired, which */ - /* means that either interrupt is NOT serviced */ - /* correctly (pending interrupt) or it is TOO LATE */ - /* for the process to be scheduled to run */ - /* (scheduler latency) which results in a (potential) */ - /* buffer underrun. And worse, there is NOTHING we */ - /* can do to prevent it. */ - if (!interruptible_sleep_on_timeout(&dmabuf->wait, tmo)) { - pr_debug(KERN_ERR "trident: playback schedule " - "timeout, dmasz %u fragsz %u count %i " - "hwptr %u swptr %u\n", dmabuf->dmasize, - dmabuf->fragsize, dmabuf->count, - dmabuf->hwptr, dmabuf->swptr); - - /* a buffer underrun, we delay the recovery */ - /* until next time the while loop begin and */ - /* we REALLY have data to play */ - } - if (signal_pending(current)) { - if (!ret) - ret = -ERESTARTSYS; - goto out_nolock; - } - mutex_lock(&state->sem); - if (dmabuf->mapped) { - if (!ret) - ret = -ENXIO; - goto out; - } - continue; - } - if ((lret = lock_set_fmt(state)) < 0) { - ret = lret; - goto out; - } - - if (state->chans_num == 6) { - copy_count = 0; - state_cnt = 0; - if (ali_write_5_1(state, buffer, cnt, ©_count, - &state_cnt) == -EFAULT) { - if (state_cnt) { - swptr = (swptr + state_cnt) % dmabuf->dmasize; - spin_lock_irqsave(&state->card->lock, flags); - dmabuf->swptr = swptr; - dmabuf->count += state_cnt; - dmabuf->endcleared = 0; - spin_unlock_irqrestore(&state->card->lock, flags); - } - ret += copy_count; - if (!ret) - ret = -EFAULT; - unlock_set_fmt(state); - goto out; - } - } else { - if (copy_from_user(dmabuf->rawbuf + swptr, - buffer, cnt)) { - if (!ret) - ret = -EFAULT; - unlock_set_fmt(state); - goto out; - } - state_cnt = cnt; - } - unlock_set_fmt(state); - - swptr = (swptr + state_cnt) % dmabuf->dmasize; - - spin_lock_irqsave(&state->card->lock, flags); - dmabuf->swptr = swptr; - dmabuf->count += state_cnt; - dmabuf->endcleared = 0; - spin_unlock_irqrestore(&state->card->lock, flags); - - count -= cnt; - buffer += cnt; - ret += cnt; - start_dac(state); - } -out: - mutex_unlock(&state->sem); -out_nolock: - return ret; -} - -/* No kernel lock - we have our own spinlock */ -static unsigned int -trident_poll(struct file *file, struct poll_table_struct *wait) -{ - struct trident_state *state = (struct trident_state *)file->private_data; - struct dmabuf *dmabuf = &state->dmabuf; - unsigned long flags; - unsigned int mask = 0; - - VALIDATE_STATE(state); - - /* - * Guard against a parallel poll and write causing multiple - * prog_dmabuf events - */ - - mutex_lock(&state->sem); - - if (file->f_mode & FMODE_WRITE) { - if (!dmabuf->ready && prog_dmabuf_playback(state)) { - mutex_unlock(&state->sem); - return 0; - } - poll_wait(file, &dmabuf->wait, wait); - } - if (file->f_mode & FMODE_READ) { - if (!dmabuf->ready && prog_dmabuf_record(state)) { - mutex_unlock(&state->sem); - return 0; - } - poll_wait(file, &dmabuf->wait, wait); - } - - mutex_unlock(&state->sem); - - spin_lock_irqsave(&state->card->lock, flags); - trident_update_ptr(state); - if (file->f_mode & FMODE_READ) { - if (dmabuf->count >= (signed) dmabuf->fragsize) - mask |= POLLIN | POLLRDNORM; - } - if (file->f_mode & FMODE_WRITE) { - if (dmabuf->mapped) { - if (dmabuf->count >= (signed) dmabuf->fragsize) - mask |= POLLOUT | POLLWRNORM; - } else { - if ((signed) dmabuf->dmasize >= dmabuf->count + - (signed) dmabuf->fragsize) - mask |= POLLOUT | POLLWRNORM; - } - } - spin_unlock_irqrestore(&state->card->lock, flags); - - return mask; -} - -static int -trident_mmap(struct file *file, struct vm_area_struct *vma) -{ - struct trident_state *state = (struct trident_state *)file->private_data; - struct dmabuf *dmabuf = &state->dmabuf; - int ret = -EINVAL; - unsigned long size; - - VALIDATE_STATE(state); - - /* - * Lock against poll read write or mmap creating buffers. Also lock - * a read or write against an mmap. - */ - - mutex_lock(&state->sem); - - if (vma->vm_flags & VM_WRITE) { - if ((ret = prog_dmabuf_playback(state)) != 0) - goto out; - } else if (vma->vm_flags & VM_READ) { - if ((ret = prog_dmabuf_record(state)) != 0) - goto out; - } else - goto out; - - ret = -EINVAL; - if (vma->vm_pgoff != 0) - goto out; - size = vma->vm_end - vma->vm_start; - if (size > (PAGE_SIZE << dmabuf->buforder)) - goto out; - ret = -EAGAIN; - if (remap_pfn_range(vma, vma->vm_start, - virt_to_phys(dmabuf->rawbuf) >> PAGE_SHIFT, - size, vma->vm_page_prot)) - goto out; - dmabuf->mapped = 1; - ret = 0; -out: - mutex_unlock(&state->sem); - return ret; -} - -static int -trident_ioctl(struct inode *inode, struct file *file, - unsigned int cmd, unsigned long arg) -{ - struct trident_state *state = (struct trident_state *)file->private_data; - struct dmabuf *dmabuf = &state->dmabuf; - unsigned long flags; - audio_buf_info abinfo; - count_info cinfo; - int val, mapped, ret = 0; - struct trident_card *card = state->card; - void __user *argp = (void __user *)arg; - int __user *p = argp; - - VALIDATE_STATE(state); - - - mapped = ((file->f_mode & (FMODE_WRITE | FMODE_READ)) && dmabuf->mapped); - - pr_debug("trident: trident_ioctl, command = %2d, arg = 0x%08x\n", - _IOC_NR(cmd), arg ? *p : 0); - - switch (cmd) { - case OSS_GETVERSION: - ret = put_user(SOUND_VERSION, p); - break; - - case SNDCTL_DSP_RESET: - /* FIXME: spin_lock ? */ - if (file->f_mode & FMODE_WRITE) { - stop_dac(state); - synchronize_irq(card->irq); - dmabuf->ready = 0; - dmabuf->swptr = dmabuf->hwptr = 0; - dmabuf->count = dmabuf->total_bytes = 0; - } - if (file->f_mode & FMODE_READ) { - stop_adc(state); - synchronize_irq(card->irq); - dmabuf->ready = 0; - dmabuf->swptr = dmabuf->hwptr = 0; - dmabuf->count = dmabuf->total_bytes = 0; - } - break; - - case SNDCTL_DSP_SYNC: - if (file->f_mode & FMODE_WRITE) - ret = drain_dac(state, file->f_flags & O_NONBLOCK); - break; - - case SNDCTL_DSP_SPEED: /* set smaple rate */ - if (get_user(val, p)) { - ret = -EFAULT; - break; - } - if (val >= 0) { - if (file->f_mode & FMODE_WRITE) { - stop_dac(state); - dmabuf->ready = 0; - spin_lock_irqsave(&state->card->lock, flags); - trident_set_dac_rate(state, val); - spin_unlock_irqrestore(&state->card->lock, flags); - } - if (file->f_mode & FMODE_READ) { - stop_adc(state); - dmabuf->ready = 0; - spin_lock_irqsave(&state->card->lock, flags); - trident_set_adc_rate(state, val); - spin_unlock_irqrestore(&state->card->lock, flags); - } - } - ret = put_user(dmabuf->rate, p); - break; - - case SNDCTL_DSP_STEREO: /* set stereo or mono channel */ - if (get_user(val, p)) { - ret = -EFAULT; - break; - } - if ((ret = lock_set_fmt(state)) < 0) - return ret; - - if (file->f_mode & FMODE_WRITE) { - stop_dac(state); - dmabuf->ready = 0; - if (val) - dmabuf->fmt |= TRIDENT_FMT_STEREO; - else - dmabuf->fmt &= ~TRIDENT_FMT_STEREO; - } - if (file->f_mode & FMODE_READ) { - stop_adc(state); - dmabuf->ready = 0; - if (val) - dmabuf->fmt |= TRIDENT_FMT_STEREO; - else - dmabuf->fmt &= ~TRIDENT_FMT_STEREO; - } - unlock_set_fmt(state); - break; - - case SNDCTL_DSP_GETBLKSIZE: - if (file->f_mode & FMODE_WRITE) { - if ((val = prog_dmabuf_playback(state))) - ret = val; - else - ret = put_user(dmabuf->fragsize, p); - break; - } - if (file->f_mode & FMODE_READ) { - if ((val = prog_dmabuf_record(state))) - ret = val; - else - ret = put_user(dmabuf->fragsize, p); - break; - } - /* neither READ nor WRITE? is this even possible? */ - ret = -EINVAL; - break; - - - case SNDCTL_DSP_GETFMTS: /* Returns a mask of supported sample format */ - ret = put_user(AFMT_S16_LE | AFMT_U16_LE | AFMT_S8 | - AFMT_U8, p); - break; - - case SNDCTL_DSP_SETFMT: /* Select sample format */ - if (get_user(val, p)) { - ret = -EFAULT; - break; - } - if ((ret = lock_set_fmt(state)) < 0) - return ret; - - if (val != AFMT_QUERY) { - if (file->f_mode & FMODE_WRITE) { - stop_dac(state); - dmabuf->ready = 0; - if (val == AFMT_S16_LE) - dmabuf->fmt |= TRIDENT_FMT_16BIT; - else - dmabuf->fmt &= ~TRIDENT_FMT_16BIT; - } - if (file->f_mode & FMODE_READ) { - stop_adc(state); - dmabuf->ready = 0; - if (val == AFMT_S16_LE) - dmabuf->fmt |= TRIDENT_FMT_16BIT; - else - dmabuf->fmt &= ~TRIDENT_FMT_16BIT; - } - } - unlock_set_fmt(state); - ret = put_user((dmabuf->fmt & TRIDENT_FMT_16BIT) ? AFMT_S16_LE : - AFMT_U8, p); - break; - - case SNDCTL_DSP_CHANNELS: - if (get_user(val, p)) { - ret = -EFAULT; - break; - } - if (val != 0) { - if ((ret = lock_set_fmt(state)) < 0) - return ret; - - if (file->f_mode & FMODE_WRITE) { - stop_dac(state); - dmabuf->ready = 0; - - //prevent from memory leak - if ((state->chans_num > 2) && (state->chans_num != val)) { - ali_free_other_states_resources(state); - state->chans_num = 1; - } - - if (val >= 2) { - - dmabuf->fmt |= TRIDENT_FMT_STEREO; - if ((val == 6) && (state->card->pci_id == PCI_DEVICE_ID_ALI_5451)) { - if (card->rec_channel_use_count > 0) { - printk(KERN_ERR "trident: Record is " - "working on the card!\n"); - ret = -EBUSY; - unlock_set_fmt(state); - break; - } - - ret = ali_setup_multi_channels(state->card, 6); - if (ret < 0) { - unlock_set_fmt(state); - break; - } - mutex_lock(&state->card->open_mutex); - ret = ali_allocate_other_states_resources(state, 6); - if (ret < 0) { - mutex_unlock(&state->card->open_mutex); - unlock_set_fmt(state); - break; - } - state->card->multi_channel_use_count++; - mutex_unlock(&state->card->open_mutex); - } else - val = 2; /*yield to 2-channels */ - } else - dmabuf->fmt &= ~TRIDENT_FMT_STEREO; - state->chans_num = val; - } - if (file->f_mode & FMODE_READ) { - stop_adc(state); - dmabuf->ready = 0; - if (val >= 2) { - if (!((file->f_mode & FMODE_WRITE) && - (val == 6))) - val = 2; - dmabuf->fmt |= TRIDENT_FMT_STEREO; - } else - dmabuf->fmt &= ~TRIDENT_FMT_STEREO; - state->chans_num = val; - } - unlock_set_fmt(state); - } - ret = put_user(val, p); - break; - - case SNDCTL_DSP_POST: - /* Cause the working fragment to be output */ - break; - - case SNDCTL_DSP_SUBDIVIDE: - if (dmabuf->subdivision) { - ret = -EINVAL; - break; - } - if (get_user(val, p)) { - ret = -EFAULT; - break; - } - if (val != 1 && val != 2 && val != 4) { - ret = -EINVAL; - break; - } - dmabuf->subdivision = val; - break; - - case SNDCTL_DSP_SETFRAGMENT: - if (get_user(val, p)) { - ret = -EFAULT; - break; - } - - dmabuf->ossfragshift = val & 0xffff; - dmabuf->ossmaxfrags = (val >> 16) & 0xffff; - if (dmabuf->ossfragshift < 4) - dmabuf->ossfragshift = 4; - if (dmabuf->ossfragshift > 15) - dmabuf->ossfragshift = 15; - if (dmabuf->ossmaxfrags < 4) - dmabuf->ossmaxfrags = 4; - - break; - - case SNDCTL_DSP_GETOSPACE: - if (!(file->f_mode & FMODE_WRITE)) { - ret = -EINVAL; - break; - } - if (!dmabuf->ready && (val = prog_dmabuf_playback(state)) != 0) { - ret = val; - break; - } - spin_lock_irqsave(&state->card->lock, flags); - trident_update_ptr(state); - abinfo.fragsize = dmabuf->fragsize; - abinfo.bytes = dmabuf->dmasize - dmabuf->count; - abinfo.fragstotal = dmabuf->numfrag; - abinfo.fragments = abinfo.bytes >> dmabuf->fragshift; - spin_unlock_irqrestore(&state->card->lock, flags); - ret = copy_to_user(argp, &abinfo, sizeof (abinfo)) ? - -EFAULT : 0; - break; - - case SNDCTL_DSP_GETISPACE: - if (!(file->f_mode & FMODE_READ)) { - ret = -EINVAL; - break; - } - if (!dmabuf->ready && (val = prog_dmabuf_record(state)) != 0) { - ret = val; - break; - } - spin_lock_irqsave(&state->card->lock, flags); - trident_update_ptr(state); - abinfo.fragsize = dmabuf->fragsize; - abinfo.bytes = dmabuf->count; - abinfo.fragstotal = dmabuf->numfrag; - abinfo.fragments = abinfo.bytes >> dmabuf->fragshift; - spin_unlock_irqrestore(&state->card->lock, flags); - ret = copy_to_user(argp, &abinfo, sizeof (abinfo)) ? - -EFAULT : 0; - break; - - case SNDCTL_DSP_NONBLOCK: - file->f_flags |= O_NONBLOCK; - break; - - case SNDCTL_DSP_GETCAPS: - ret = put_user(DSP_CAP_REALTIME | DSP_CAP_TRIGGER | - DSP_CAP_MMAP | DSP_CAP_BIND, p); - break; - - case SNDCTL_DSP_GETTRIGGER: - val = 0; - if ((file->f_mode & FMODE_READ) && dmabuf->enable) - val |= PCM_ENABLE_INPUT; - if ((file->f_mode & FMODE_WRITE) && dmabuf->enable) - val |= PCM_ENABLE_OUTPUT; - ret = put_user(val, p); - break; - - case SNDCTL_DSP_SETTRIGGER: - if (get_user(val, p)) { - ret = -EFAULT; - break; - } - if (file->f_mode & FMODE_READ) { - if (val & PCM_ENABLE_INPUT) { - if (!dmabuf->ready && - (ret = prog_dmabuf_record(state))) - break; - start_adc(state); - } else - stop_adc(state); - } - if (file->f_mode & FMODE_WRITE) { - if (val & PCM_ENABLE_OUTPUT) { - if (!dmabuf->ready && - (ret = prog_dmabuf_playback(state))) - break; - start_dac(state); - } else - stop_dac(state); - } - break; - - case SNDCTL_DSP_GETIPTR: - if (!(file->f_mode & FMODE_READ)) { - ret = -EINVAL; - break; - } - if (!dmabuf->ready && (val = prog_dmabuf_record(state)) - != 0) { - ret = val; - break; - } - spin_lock_irqsave(&state->card->lock, flags); - trident_update_ptr(state); - cinfo.bytes = dmabuf->total_bytes; - cinfo.blocks = dmabuf->count >> dmabuf->fragshift; - cinfo.ptr = dmabuf->hwptr; - if (dmabuf->mapped) - dmabuf->count &= dmabuf->fragsize - 1; - spin_unlock_irqrestore(&state->card->lock, flags); - ret = copy_to_user(argp, &cinfo, sizeof (cinfo)) ? - -EFAULT : 0; - break; - - case SNDCTL_DSP_GETOPTR: - if (!(file->f_mode & FMODE_WRITE)) { - ret = -EINVAL; - break; - } - if (!dmabuf->ready && (val = prog_dmabuf_playback(state)) - != 0) { - ret = val; - break; - } - - spin_lock_irqsave(&state->card->lock, flags); - trident_update_ptr(state); - cinfo.bytes = dmabuf->total_bytes; - cinfo.blocks = dmabuf->count >> dmabuf->fragshift; - cinfo.ptr = dmabuf->hwptr; - if (dmabuf->mapped) - dmabuf->count &= dmabuf->fragsize - 1; - spin_unlock_irqrestore(&state->card->lock, flags); - ret = copy_to_user(argp, &cinfo, sizeof (cinfo)) ? - -EFAULT : 0; - break; - - case SNDCTL_DSP_SETDUPLEX: - ret = -EINVAL; - break; - - case SNDCTL_DSP_GETODELAY: - if (!(file->f_mode & FMODE_WRITE)) { - ret = -EINVAL; - break; - } - if (!dmabuf->ready && (val = prog_dmabuf_playback(state)) != 0) { - ret = val; - break; - } - spin_lock_irqsave(&state->card->lock, flags); - trident_update_ptr(state); - val = dmabuf->count; - spin_unlock_irqrestore(&state->card->lock, flags); - ret = put_user(val, p); - break; - - case SOUND_PCM_READ_RATE: - ret = put_user(dmabuf->rate, p); - break; - - case SOUND_PCM_READ_CHANNELS: - ret = put_user((dmabuf->fmt & TRIDENT_FMT_STEREO) ? 2 : 1, - p); - break; - - case SOUND_PCM_READ_BITS: - ret = put_user((dmabuf->fmt & TRIDENT_FMT_16BIT) ? AFMT_S16_LE : - AFMT_U8, p); - break; - - case SNDCTL_DSP_GETCHANNELMASK: - ret = put_user(DSP_BIND_FRONT | DSP_BIND_SURR | - DSP_BIND_CENTER_LFE, p); - break; - - case SNDCTL_DSP_BIND_CHANNEL: - if (state->card->pci_id != PCI_DEVICE_ID_SI_7018) { - ret = -EINVAL; - break; - } - - if (get_user(val, p)) { - ret = -EFAULT; - break; - } - if (val == DSP_BIND_QUERY) { - val = dmabuf->channel->attribute | 0x3c00; - val = attr2mask[val >> 8]; - } else { - dmabuf->ready = 0; - if (file->f_mode & FMODE_READ) - dmabuf->channel->attribute = (CHANNEL_REC | - SRC_ENABLE); - if (file->f_mode & FMODE_WRITE) - dmabuf->channel->attribute = (CHANNEL_SPC_PB | - SRC_ENABLE); - dmabuf->channel->attribute |= mask2attr[ffs(val)]; - } - ret = put_user(val, p); - break; - - case SNDCTL_DSP_MAPINBUF: - case SNDCTL_DSP_MAPOUTBUF: - case SNDCTL_DSP_SETSYNCRO: - case SOUND_PCM_WRITE_FILTER: - case SOUND_PCM_READ_FILTER: - default: - ret = -EINVAL; - break; - - } - return ret; -} - -static int -trident_open(struct inode *inode, struct file *file) -{ - int i = 0; - int minor = iminor(inode); - struct trident_card *card = devs; - struct trident_state *state = NULL; - struct dmabuf *dmabuf = NULL; - unsigned long flags; - - /* Added by Matt Wu 01-05-2001 */ - /* TODO: there's some redundacy here wrt the check below */ - /* for multi_use_count > 0. Should we return -EBUSY or find */ - /* a different card? for now, don't break current behaviour */ - /* -- mulix */ - if (file->f_mode & FMODE_READ) { - if (card->pci_id == PCI_DEVICE_ID_ALI_5451) { - if (card->multi_channel_use_count > 0) - return -EBUSY; - } - } - - /* find an available virtual channel (instance of /dev/dsp) */ - while (card != NULL) { - mutex_lock(&card->open_mutex); - if (file->f_mode & FMODE_READ) { - /* Skip opens on cards that are in 6 channel mode */ - if (card->multi_channel_use_count > 0) { - mutex_unlock(&card->open_mutex); - card = card->next; - continue; - } - } - for (i = 0; i < NR_HW_CH; i++) { - if (card->states[i] == NULL) { - state = card->states[i] = kzalloc(sizeof(*state), GFP_KERNEL); - if (state == NULL) { - mutex_unlock(&card->open_mutex); - return -ENOMEM; - } - mutex_init(&state->sem); - dmabuf = &state->dmabuf; - goto found_virt; - } - } - mutex_unlock(&card->open_mutex); - card = card->next; - } - /* no more virtual channel avaiable */ - if (!state) { - return -ENODEV; - } - found_virt: - /* found a free virtual channel, allocate hardware channels */ - if (file->f_mode & FMODE_READ) - dmabuf->channel = card->alloc_rec_pcm_channel(card); - else - dmabuf->channel = card->alloc_pcm_channel(card); - - if (dmabuf->channel == NULL) { - kfree(card->states[i]); - card->states[i] = NULL; - return -ENODEV; - } - - /* initialize the virtual channel */ - state->virt = i; - state->card = card; - state->magic = TRIDENT_STATE_MAGIC; - init_waitqueue_head(&dmabuf->wait); - file->private_data = state; - - /* set default sample format. According to OSS Programmer's */ - /* Guide /dev/dsp should be default to unsigned 8-bits, mono, */ - /* with sample rate 8kHz and /dev/dspW will accept 16-bits sample */ - if (file->f_mode & FMODE_WRITE) { - dmabuf->fmt &= ~TRIDENT_FMT_MASK; - if ((minor & 0x0f) == SND_DEV_DSP16) - dmabuf->fmt |= TRIDENT_FMT_16BIT; - dmabuf->ossfragshift = 0; - dmabuf->ossmaxfrags = 0; - dmabuf->subdivision = 0; - if (card->pci_id == PCI_DEVICE_ID_SI_7018) { - /* set default channel attribute to normal playback */ - dmabuf->channel->attribute = CHANNEL_PB; - } - spin_lock_irqsave(&card->lock, flags); - trident_set_dac_rate(state, 8000); - spin_unlock_irqrestore(&card->lock, flags); - } - - if (file->f_mode & FMODE_READ) { - /* FIXME: Trident 4d can only record in signed 16-bits stereo, */ - /* 48kHz sample, to be dealed with in trident_set_adc_rate() ?? */ - dmabuf->fmt &= ~TRIDENT_FMT_MASK; - if ((minor & 0x0f) == SND_DEV_DSP16) - dmabuf->fmt |= TRIDENT_FMT_16BIT; - dmabuf->ossfragshift = 0; - dmabuf->ossmaxfrags = 0; - dmabuf->subdivision = 0; - if (card->pci_id == PCI_DEVICE_ID_SI_7018) { - /* set default channel attribute to 0x8a80, record from - PCM L/R FIFO and mono = (left + right + 1)/2 */ - dmabuf->channel->attribute = (CHANNEL_REC | PCM_LR | - MONO_MIX); - } - spin_lock_irqsave(&card->lock, flags); - trident_set_adc_rate(state, 8000); - spin_unlock_irqrestore(&card->lock, flags); - - /* Added by Matt Wu 01-05-2001 */ - if (card->pci_id == PCI_DEVICE_ID_ALI_5451) - card->rec_channel_use_count++; - } - - state->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE); - mutex_unlock(&card->open_mutex); - - pr_debug("trident: open virtual channel %d, hard channel %d\n", - state->virt, dmabuf->channel->num); - - return nonseekable_open(inode, file); -} - -static int -trident_release(struct inode *inode, struct file *file) -{ - struct trident_state *state = (struct trident_state *)file->private_data; - struct trident_card *card; - struct dmabuf *dmabuf; - - VALIDATE_STATE(state); - - card = state->card; - dmabuf = &state->dmabuf; - - if (file->f_mode & FMODE_WRITE) { - trident_clear_tail(state); - drain_dac(state, file->f_flags & O_NONBLOCK); - } - - pr_debug("trident: closing virtual channel %d, hard channel %d\n", - state->virt, dmabuf->channel->num); - - /* stop DMA state machine and free DMA buffers/channels */ - mutex_lock(&card->open_mutex); - - if (file->f_mode & FMODE_WRITE) { - stop_dac(state); - dealloc_dmabuf(&state->dmabuf, state->card->pci_dev); - state->card->free_pcm_channel(state->card, dmabuf->channel->num); - - /* Added by Matt Wu */ - if (card->pci_id == PCI_DEVICE_ID_ALI_5451) { - if (state->chans_num > 2) { - if (card->multi_channel_use_count-- < 0) - card->multi_channel_use_count = 0; - if (card->multi_channel_use_count == 0) - ali_close_multi_channels(); - ali_free_other_states_resources(state); - } - } - } - if (file->f_mode & FMODE_READ) { - stop_adc(state); - dealloc_dmabuf(&state->dmabuf, state->card->pci_dev); - state->card->free_pcm_channel(state->card, dmabuf->channel->num); - - /* Added by Matt Wu */ - if (card->pci_id == PCI_DEVICE_ID_ALI_5451) { - if (card->rec_channel_use_count-- < 0) - card->rec_channel_use_count = 0; - } - } - - card->states[state->virt] = NULL; - kfree(state); - - /* we're covered by the open_mutex */ - mutex_unlock(&card->open_mutex); - - return 0; -} - -static const struct file_operations trident_audio_fops = { - .owner = THIS_MODULE, - .llseek = no_llseek, - .read = trident_read, - .write = trident_write, - .poll = trident_poll, - .ioctl = trident_ioctl, - .mmap = trident_mmap, - .open = trident_open, - .release = trident_release, -}; - -/* trident specific AC97 functions */ -/* Write AC97 codec registers */ -static void -trident_ac97_set(struct ac97_codec *codec, u8 reg, u16 val) -{ - struct trident_card *card = (struct trident_card *)codec->private_data; - unsigned int address, mask, busy; - unsigned short count = 0xffff; - unsigned long flags; - u32 data; - - data = ((u32) val) << 16; - - switch (card->pci_id) { - default: - case PCI_DEVICE_ID_SI_7018: - address = SI_AC97_WRITE; - mask = SI_AC97_BUSY_WRITE | SI_AC97_AUDIO_BUSY; - if (codec->id) - mask |= SI_AC97_SECONDARY; - busy = SI_AC97_BUSY_WRITE; - break; - case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX: - address = DX_ACR0_AC97_W; - mask = busy = DX_AC97_BUSY_WRITE; - break; - case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX: - address = NX_ACR1_AC97_W; - mask = NX_AC97_BUSY_WRITE; - if (codec->id) - mask |= NX_AC97_WRITE_SECONDARY; - busy = NX_AC97_BUSY_WRITE; - break; - case PCI_DEVICE_ID_INTERG_5050: - address = SI_AC97_WRITE; - mask = busy = SI_AC97_BUSY_WRITE; - if (codec->id) - mask |= SI_AC97_SECONDARY; - break; - } - - spin_lock_irqsave(&card->lock, flags); - do { - if ((inw(TRID_REG(card, address)) & busy) == 0) - break; - } while (--count); - - data |= (mask | (reg & AC97_REG_ADDR)); - - if (count == 0) { - printk(KERN_ERR "trident: AC97 CODEC write timed out.\n"); - spin_unlock_irqrestore(&card->lock, flags); - return; - } - - outl(data, TRID_REG(card, address)); - spin_unlock_irqrestore(&card->lock, flags); -} - -/* Read AC97 codec registers */ -static u16 -trident_ac97_get(struct ac97_codec *codec, u8 reg) -{ - struct trident_card *card = (struct trident_card *)codec->private_data; - unsigned int address, mask, busy; - unsigned short count = 0xffff; - unsigned long flags; - u32 data; - - switch (card->pci_id) { - default: - case PCI_DEVICE_ID_SI_7018: - address = SI_AC97_READ; - mask = SI_AC97_BUSY_READ | SI_AC97_AUDIO_BUSY; - if (codec->id) - mask |= SI_AC97_SECONDARY; - busy = SI_AC97_BUSY_READ; - break; - case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX: - address = DX_ACR1_AC97_R; - mask = busy = DX_AC97_BUSY_READ; - break; - case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX: - if (codec->id) - address = NX_ACR3_AC97_R_SECONDARY; - else - address = NX_ACR2_AC97_R_PRIMARY; - mask = NX_AC97_BUSY_READ; - busy = NX_AC97_BUSY_READ | NX_AC97_BUSY_DATA; - break; - case PCI_DEVICE_ID_INTERG_5050: - address = SI_AC97_READ; - mask = busy = SI_AC97_BUSY_READ; - if (codec->id) - mask |= SI_AC97_SECONDARY; - break; - } - - data = (mask | (reg & AC97_REG_ADDR)); - - spin_lock_irqsave(&card->lock, flags); - outl(data, TRID_REG(card, address)); - do { - data = inl(TRID_REG(card, address)); - if ((data & busy) == 0) - break; - } while (--count); - spin_unlock_irqrestore(&card->lock, flags); - - if (count == 0) { - printk(KERN_ERR "trident: AC97 CODEC read timed out.\n"); - data = 0; - } - return ((u16) (data >> 16)); -} - -/* rewrite ac97 read and write mixer register by hulei for ALI*/ -static int -acquirecodecaccess(struct trident_card *card) -{ - u16 wsemamask = 0x6000; /* bit 14..13 */ - u16 wsemabits; - u16 wcontrol; - int block = 0; - int ncount = 25; - while (1) { - wcontrol = inw(TRID_REG(card, ALI_AC97_WRITE)); - wsemabits = wcontrol & wsemamask; - - if (wsemabits == 0x4000) - return 1; /* 0x4000 is audio ,then success */ - if (ncount-- < 0) - break; - if (wsemabits == 0) { - unlock: - outl(((u32) (wcontrol & 0x1eff) | 0x00004000), - TRID_REG(card, ALI_AC97_WRITE)); - continue; - } - udelay(20); - } - if (!block) { - pr_debug("accesscodecsemaphore: try unlock\n"); - block = 1; - goto unlock; - } - return 0; -} - -static void -releasecodecaccess(struct trident_card *card) -{ - unsigned long wcontrol; - wcontrol = inl(TRID_REG(card, ALI_AC97_WRITE)); - outl((wcontrol & 0xffff1eff), TRID_REG(card, ALI_AC97_WRITE)); -} - -static int -waitforstimertick(struct trident_card *card) -{ - unsigned long chk1, chk2; - unsigned int wcount = 0xffff; - chk1 = inl(TRID_REG(card, ALI_STIMER)); - - while (1) { - chk2 = inl(TRID_REG(card, ALI_STIMER)); - if ((wcount > 0) && chk1 != chk2) - return 1; - if (wcount <= 0) - break; - udelay(50); - } - return 0; -} - -/* Read AC97 codec registers for ALi*/ -static u16 -ali_ac97_get(struct trident_card *card, int secondary, u8 reg) -{ - unsigned int address, mask; - unsigned int ncount; - unsigned long aud_reg; - u32 data; - u16 wcontrol; - unsigned long flags; - - BUG_ON(!card); - - address = ALI_AC97_READ; - if (card->revision == ALI_5451_V02) { - address = ALI_AC97_WRITE; - } - mask = ALI_AC97_READ_ACTION | ALI_AC97_AUDIO_BUSY; - if (secondary) - mask |= ALI_AC97_SECONDARY; - - spin_lock_irqsave(&card->lock, flags); - - if (!acquirecodecaccess(card)) - printk(KERN_ERR "access codec fail\n"); - - wcontrol = inw(TRID_REG(card, ALI_AC97_WRITE)); - wcontrol &= 0xfe00; - wcontrol |= (0x8000 | reg); - outw(wcontrol, TRID_REG(card, ALI_AC97_WRITE)); - - data = (mask | (reg & AC97_REG_ADDR)); - - if (!waitforstimertick(card)) { - printk(KERN_ERR "ali_ac97_read: BIT_CLOCK is dead\n"); - goto releasecodec; - } - - udelay(20); - - ncount = 10; - - while (1) { - if ((inw(TRID_REG(card, ALI_AC97_WRITE)) & ALI_AC97_BUSY_READ) - != 0) - break; - if (ncount <= 0) - break; - if (ncount-- == 1) { - pr_debug("ali_ac97_read :try clear busy flag\n"); - aud_reg = inl(TRID_REG(card, ALI_AC97_WRITE)); - outl((aud_reg & 0xffff7fff), - TRID_REG(card, ALI_AC97_WRITE)); - } - udelay(10); - } - - data = inl(TRID_REG(card, address)); - - spin_unlock_irqrestore(&card->lock, flags); - - return ((u16) (data >> 16)); - - releasecodec: - releasecodecaccess(card); - spin_unlock_irqrestore(&card->lock, flags); - printk(KERN_ERR "ali_ac97_read: AC97 CODEC read timed out.\n"); - return 0; -} - -/* Write AC97 codec registers for hulei*/ -static void -ali_ac97_set(struct trident_card *card, int secondary, u8 reg, u16 val) -{ - unsigned int address, mask; - unsigned int ncount; - u32 data; - u16 wcontrol; - unsigned long flags; - - data = ((u32) val) << 16; - - BUG_ON(!card); - - address = ALI_AC97_WRITE; - mask = ALI_AC97_WRITE_ACTION | ALI_AC97_AUDIO_BUSY; - if (secondary) - mask |= ALI_AC97_SECONDARY; - if (card->revision == ALI_5451_V02) - mask |= ALI_AC97_WRITE_MIXER_REGISTER; - - spin_lock_irqsave(&card->lock, flags); - if (!acquirecodecaccess(card)) - printk(KERN_ERR "ali_ac97_write: access codec fail\n"); - - wcontrol = inw(TRID_REG(card, ALI_AC97_WRITE)); - wcontrol &= 0xff00; - wcontrol |= (0x8100 | reg); /* bit 8=1: (ali1535 )reserved/ */ - /* ali1535+ write */ - outl((data | wcontrol), TRID_REG(card, ALI_AC97_WRITE)); - - if (!waitforstimertick(card)) { - printk(KERN_ERR "BIT_CLOCK is dead\n"); - goto releasecodec; - } - - ncount = 10; - while (1) { - wcontrol = inw(TRID_REG(card, ALI_AC97_WRITE)); - if (!(wcontrol & 0x8000)) - break; - if (ncount <= 0) - break; - if (ncount-- == 1) { - pr_debug("ali_ac97_set :try clear busy flag!!\n"); - outw(wcontrol & 0x7fff, - TRID_REG(card, ALI_AC97_WRITE)); - } - udelay(10); - } - - releasecodec: - releasecodecaccess(card); - spin_unlock_irqrestore(&card->lock, flags); - return; -} - -static void -ali_enable_special_channel(struct trident_state *stat) -{ - struct trident_card *card = stat->card; - unsigned long s_channels; - - s_channels = inl(TRID_REG(card, ALI_GLOBAL_CONTROL)); - s_channels |= (1 << stat->dmabuf.channel->num); - outl(s_channels, TRID_REG(card, ALI_GLOBAL_CONTROL)); -} - -static u16 -ali_ac97_read(struct ac97_codec *codec, u8 reg) -{ - int id; - u16 data; - struct trident_card *card = NULL; - - /* Added by Matt Wu */ - BUG_ON(!codec); - - card = (struct trident_card *) codec->private_data; - - if (!card->mixer_regs_ready) - return ali_ac97_get(card, codec->id, reg); - - /* - * FIXME: need to stop this caching some registers - */ - if (codec->id) - id = 1; - else - id = 0; - - data = card->mixer_regs[reg / 2][id]; - return data; -} - -static void -ali_ac97_write(struct ac97_codec *codec, u8 reg, u16 val) -{ - int id; - struct trident_card *card; - - /* Added by Matt Wu */ - BUG_ON(!codec); - - card = (struct trident_card *) codec->private_data; - - if (!card->mixer_regs_ready) { - ali_ac97_set(card, codec->id, reg, val); - return; - } - - if (codec->id) - id = 1; - else - id = 0; - - card->mixer_regs[reg / 2][id] = val; - ali_ac97_set(card, codec->id, reg, val); -} - -/* -flag: ALI_SPDIF_OUT_TO_SPDIF_OUT - ALI_PCM_TO_SPDIF_OUT -*/ - -static void -ali_setup_spdif_out(struct trident_card *card, int flag) -{ - unsigned long spdif; - unsigned char ch; - - char temp; - struct pci_dev *pci_dev = NULL; - - pci_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, - pci_dev); - if (pci_dev == NULL) - return; - pci_read_config_byte(pci_dev, 0x61, &temp); - temp |= 0x40; - pci_write_config_byte(pci_dev, 0x61, temp); - pci_read_config_byte(pci_dev, 0x7d, &temp); - temp |= 0x01; - pci_write_config_byte(pci_dev, 0x7d, temp); - pci_read_config_byte(pci_dev, 0x7e, &temp); - temp &= (~0x20); - temp |= 0x10; - pci_write_config_byte(pci_dev, 0x7e, temp); - - pci_dev_put(pci_dev); - - ch = inb(TRID_REG(card, ALI_SCTRL)); - outb(ch | ALI_SPDIF_OUT_ENABLE, TRID_REG(card, ALI_SCTRL)); - ch = inb(TRID_REG(card, ALI_SPDIF_CTRL)); - outb(ch & ALI_SPDIF_OUT_CH_STATUS, TRID_REG(card, ALI_SPDIF_CTRL)); - - if (flag & ALI_SPDIF_OUT_TO_SPDIF_OUT) { - spdif = inw(TRID_REG(card, ALI_GLOBAL_CONTROL)); - spdif |= ALI_SPDIF_OUT_CH_ENABLE; - spdif &= ALI_SPDIF_OUT_SEL_SPDIF; - outw(spdif, TRID_REG(card, ALI_GLOBAL_CONTROL)); - spdif = inw(TRID_REG(card, ALI_SPDIF_CS)); - if (flag & ALI_SPDIF_OUT_NON_PCM) - spdif |= 0x0002; - else - spdif &= (~0x0002); - outw(spdif, TRID_REG(card, ALI_SPDIF_CS)); - } else { - spdif = inw(TRID_REG(card, ALI_GLOBAL_CONTROL)); - spdif |= ALI_SPDIF_OUT_SEL_PCM; - outw(spdif, TRID_REG(card, ALI_GLOBAL_CONTROL)); - } -} - -static void -ali_disable_special_channel(struct trident_card *card, int ch) -{ - unsigned long sc; - - sc = inl(TRID_REG(card, ALI_GLOBAL_CONTROL)); - sc &= ~(1 << ch); - outl(sc, TRID_REG(card, ALI_GLOBAL_CONTROL)); -} - -static void -ali_disable_spdif_in(struct trident_card *card) -{ - unsigned long spdif; - - spdif = inl(TRID_REG(card, ALI_GLOBAL_CONTROL)); - spdif &= (~ALI_SPDIF_IN_SUPPORT); - outl(spdif, TRID_REG(card, ALI_GLOBAL_CONTROL)); - - ali_disable_special_channel(card, ALI_SPDIF_IN_CHANNEL); -} - -static void -ali_setup_spdif_in(struct trident_card *card) -{ - unsigned long spdif; - - //Set SPDIF IN Supported - spdif = inl(TRID_REG(card, ALI_GLOBAL_CONTROL)); - spdif |= ALI_SPDIF_IN_SUPPORT; - outl(spdif, TRID_REG(card, ALI_GLOBAL_CONTROL)); - - //Set SPDIF IN Rec - spdif = inl(TRID_REG(card, ALI_GLOBAL_CONTROL)); - spdif |= ALI_SPDIF_IN_CH_ENABLE; - outl(spdif, TRID_REG(card, ALI_GLOBAL_CONTROL)); - - spdif = inb(TRID_REG(card, ALI_SPDIF_CTRL)); - spdif |= ALI_SPDIF_IN_CH_STATUS; - outb(spdif, TRID_REG(card, ALI_SPDIF_CTRL)); -/* - spdif = inb(TRID_REG(card, ALI_SPDIF_CTRL)); - spdif |= ALI_SPDIF_IN_FUNC_ENABLE; - outb(spdif, TRID_REG(card, ALI_SPDIF_CTRL)); -*/ -} - -static void -ali_delay(struct trident_card *card, int interval) -{ - unsigned long begintimer, currenttimer; - - begintimer = inl(TRID_REG(card, ALI_STIMER)); - currenttimer = inl(TRID_REG(card, ALI_STIMER)); - - while (currenttimer < begintimer + interval) - currenttimer = inl(TRID_REG(card, ALI_STIMER)); -} - -static void -ali_detect_spdif_rate(struct trident_card *card) -{ - u16 wval = 0; - u16 count = 0; - u8 bval = 0, R1 = 0, R2 = 0; - - bval = inb(TRID_REG(card, ALI_SPDIF_CTRL)); - bval |= 0x02; - outb(bval, TRID_REG(card, ALI_SPDIF_CTRL)); - - bval = inb(TRID_REG(card, ALI_SPDIF_CTRL + 1)); - bval |= 0x1F; - outb(bval, TRID_REG(card, ALI_SPDIF_CTRL + 1)); - - while (((R1 < 0x0B) || (R1 > 0x0E)) && (R1 != 0x12) && - count <= 50000) { - count++; - - ali_delay(card, 6); - - bval = inb(TRID_REG(card, ALI_SPDIF_CTRL + 1)); - R1 = bval & 0x1F; - } - - if (count > 50000) { - printk(KERN_WARNING "trident: Error in " - "ali_detect_spdif_rate!\n"); - return; - } - - count = 0; - - while (count <= 50000) { - count++; - - ali_delay(card, 6); - - bval = inb(TRID_REG(card, ALI_SPDIF_CTRL + 1)); - R2 = bval & 0x1F; - - if (R2 != R1) - R1 = R2; - else - break; - } - - if (count > 50000) { - printk(KERN_WARNING "trident: Error in " - "ali_detect_spdif_rate!\n"); - return; - } - - switch (R2) { - case 0x0b: - case 0x0c: - case 0x0d: - case 0x0e: - wval = inw(TRID_REG(card, ALI_SPDIF_CTRL + 2)); - wval &= 0xE0F0; - wval |= (u16) 0x09 << 8 | (u16) 0x05; - outw(wval, TRID_REG(card, ALI_SPDIF_CTRL + 2)); - - bval = inb(TRID_REG(card, ALI_SPDIF_CS + 3)) & 0xF0; - outb(bval | 0x02, TRID_REG(card, ALI_SPDIF_CS + 3)); - break; - - case 0x12: - wval = inw(TRID_REG(card, ALI_SPDIF_CTRL + 2)); - wval &= 0xE0F0; - wval |= (u16) 0x0E << 8 | (u16) 0x08; - outw(wval, TRID_REG(card, ALI_SPDIF_CTRL + 2)); - - bval = inb(TRID_REG(card, ALI_SPDIF_CS + 3)) & 0xF0; - outb(bval | 0x03, TRID_REG(card, ALI_SPDIF_CS + 3)); - break; - - default: - break; - } - -} - -static unsigned int -ali_get_spdif_in_rate(struct trident_card *card) -{ - u32 dwRate = 0; - u8 bval = 0; - - ali_detect_spdif_rate(card); - - bval = inb(TRID_REG(card, ALI_SPDIF_CTRL)); - bval &= 0x7F; - bval |= 0x40; - outb(bval, TRID_REG(card, ALI_SPDIF_CTRL)); - - bval = inb(TRID_REG(card, ALI_SPDIF_CS + 3)); - bval &= 0x0F; - - switch (bval) { - case 0: - dwRate = 44100; - break; - case 1: - dwRate = 48000; - break; - case 2: - dwRate = 32000; - break; - default: - // Error occurs - break; - } - - return dwRate; - -} - -static int -ali_close_multi_channels(void) -{ - char temp = 0; - struct pci_dev *pci_dev = NULL; - - pci_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, - pci_dev); - if (pci_dev == NULL) - return -1; - - pci_read_config_byte(pci_dev, 0x59, &temp); - temp &= ~0x80; - pci_write_config_byte(pci_dev, 0x59, temp); - - pci_dev_put(pci_dev); - - pci_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, - NULL); - if (pci_dev == NULL) - return -1; - - pci_read_config_byte(pci_dev, 0xB8, &temp); - temp &= ~0x20; - pci_write_config_byte(pci_dev, 0xB8, temp); - - pci_dev_put(pci_dev); - - return 0; -} - -static int -ali_setup_multi_channels(struct trident_card *card, int chan_nums) -{ - unsigned long dwValue; - char temp = 0; - struct pci_dev *pci_dev = NULL; - - pci_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, - pci_dev); - if (pci_dev == NULL) - return -1; - pci_read_config_byte(pci_dev, 0x59, &temp); - temp |= 0x80; - pci_write_config_byte(pci_dev, 0x59, temp); - - pci_dev_put(pci_dev); - - pci_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, - NULL); - if (pci_dev == NULL) - return -1; - pci_read_config_byte(pci_dev, (int) 0xB8, &temp); - temp |= 0x20; - pci_write_config_byte(pci_dev, (int) 0xB8, (u8) temp); - - pci_dev_put(pci_dev); - - if (chan_nums == 6) { - dwValue = inl(TRID_REG(card, ALI_SCTRL)) | 0x000f0000; - outl(dwValue, TRID_REG(card, ALI_SCTRL)); - mdelay(4); - dwValue = inl(TRID_REG(card, ALI_SCTRL)); - if (dwValue & 0x2000000) { - ali_ac97_write(card->ac97_codec[0], 0x02, 8080); - ali_ac97_write(card->ac97_codec[0], 0x36, 0); - ali_ac97_write(card->ac97_codec[0], 0x38, 0); - /* - * On a board with a single codec you won't get the - * surround. On other boards configure it. - */ - if (card->ac97_codec[1] != NULL) { - ali_ac97_write(card->ac97_codec[1], 0x36, 0); - ali_ac97_write(card->ac97_codec[1], 0x38, 0); - ali_ac97_write(card->ac97_codec[1], 0x02, 0x0606); - ali_ac97_write(card->ac97_codec[1], 0x18, 0x0303); - ali_ac97_write(card->ac97_codec[1], 0x74, 0x3); - } - return 1; - } - } - return -EINVAL; -} - -static void -ali_free_pcm_channel(struct trident_card *card, unsigned int channel) -{ - int bank; - - if (channel > 31) - return; - - bank = channel >> 5; - channel = channel & 0x1f; - - card->banks[bank].bitmap &= ~(1 << (channel)); -} - -static int -ali_allocate_other_states_resources(struct trident_state *state, int chan_nums) -{ - struct trident_card *card = state->card; - struct trident_state *s; - int i, state_count = 0; - struct trident_pcm_bank *bank; - struct trident_channel *channel; - unsigned long num; - - bank = &card->banks[BANK_A]; - - if (chan_nums != 6) - return 0; - - for (i = 0; (i < ALI_CHANNELS) && (state_count != 4); i++) { - if (card->states[i]) - continue; - - num = ali_multi_channels_5_1[state_count]; - if (!(bank->bitmap & (1 << num))) { - bank->bitmap |= 1 << num; - channel = &bank->channels[num]; - channel->num = num; - } else { - state_count--; - for (; state_count >= 0; state_count--) { - kfree(state->other_states[state_count]); - num = ali_multi_channels_5_1[state_count]; - ali_free_pcm_channel(card, num); - } - return -EBUSY; - } - s = card->states[i] = kzalloc(sizeof(*state), GFP_KERNEL); - if (!s) { - num = ali_multi_channels_5_1[state_count]; - ali_free_pcm_channel(card, num); - state_count--; - for (; state_count >= 0; state_count--) { - num = ali_multi_channels_5_1[state_count]; - ali_free_pcm_channel(card, num); - kfree(state->other_states[state_count]); - } - return -ENOMEM; - } - - s->dmabuf.channel = channel; - s->dmabuf.ossfragshift = s->dmabuf.ossmaxfrags = - s->dmabuf.subdivision = 0; - init_waitqueue_head(&s->dmabuf.wait); - s->magic = card->magic; - s->card = card; - s->virt = i; - ali_enable_special_channel(s); - state->other_states[state_count++] = s; - } - - if (state_count != 4) { - state_count--; - for (; state_count >= 0; state_count--) { - kfree(state->other_states[state_count]); - num = ali_multi_channels_5_1[state_count]; - ali_free_pcm_channel(card, num); - } - return -EBUSY; - } - return 0; -} - -#ifdef CONFIG_PM -/* save registers for ALi Power Management */ -static struct ali_saved_registers { - unsigned long global_regs[ALI_GLOBAL_REGS]; - unsigned long channel_regs[ALI_CHANNELS][ALI_CHANNEL_REGS]; - unsigned mixer_regs[ALI_MIXER_REGS]; -} ali_registers; - -static void -ali_save_regs(struct trident_card *card) -{ - unsigned long flags; - int i, j; - - spin_lock_irqsave(&card->lock, flags); - - ali_registers.global_regs[0x2c] = inl(TRID_REG(card, T4D_MISCINT)); - //ali_registers.global_regs[0x20] = inl(TRID_REG(card,T4D_START_A)); - ali_registers.global_regs[0x21] = inl(TRID_REG(card, T4D_STOP_A)); - - //disable all IRQ bits - outl(ALI_DISABLE_ALL_IRQ, TRID_REG(card, T4D_MISCINT)); - - for (i = 1; i < ALI_MIXER_REGS; i++) - ali_registers.mixer_regs[i] = ali_ac97_read(card->ac97_codec[0], - i * 2); - - for (i = 0; i < ALI_GLOBAL_REGS; i++) { - if ((i * 4 == T4D_MISCINT) || (i * 4 == T4D_STOP_A)) - continue; - ali_registers.global_regs[i] = inl(TRID_REG(card, i * 4)); - } - - for (i = 0; i < ALI_CHANNELS; i++) { - outb(i, TRID_REG(card, T4D_LFO_GC_CIR)); - for (j = 0; j < ALI_CHANNEL_REGS; j++) - ali_registers.channel_regs[i][j] = inl(TRID_REG(card, - j * 4 + 0xe0)); - } - - //Stop all HW channel - outl(ALI_STOP_ALL_CHANNELS, TRID_REG(card, T4D_STOP_A)); - - spin_unlock_irqrestore(&card->lock, flags); -} - -static void -ali_restore_regs(struct trident_card *card) -{ - unsigned long flags; - int i, j; - - spin_lock_irqsave(&card->lock, flags); - - for (i = 1; i < ALI_MIXER_REGS; i++) - ali_ac97_write(card->ac97_codec[0], i * 2, - ali_registers.mixer_regs[i]); - - for (i = 0; i < ALI_CHANNELS; i++) { - outb(i, TRID_REG(card, T4D_LFO_GC_CIR)); - for (j = 0; j < ALI_CHANNEL_REGS; j++) - outl(ali_registers.channel_regs[i][j], - TRID_REG(card, j * 4 + 0xe0)); - } - - for (i = 0; i < ALI_GLOBAL_REGS; i++) { - if ((i * 4 == T4D_MISCINT) || (i * 4 == T4D_STOP_A) || - (i * 4 == T4D_START_A)) - continue; - outl(ali_registers.global_regs[i], TRID_REG(card, i * 4)); - } - - //start HW channel - outl(ali_registers.global_regs[0x20], TRID_REG(card, T4D_START_A)); - //restore IRQ enable bits - outl(ali_registers.global_regs[0x2c], TRID_REG(card, T4D_MISCINT)); - - spin_unlock_irqrestore(&card->lock, flags); -} - -static int -trident_suspend(struct pci_dev *dev, pm_message_t unused) -{ - struct trident_card *card = pci_get_drvdata(dev); - - if (card->pci_id == PCI_DEVICE_ID_ALI_5451) { - ali_save_regs(card); - } - return 0; -} - -static int -trident_resume(struct pci_dev *dev) -{ - struct trident_card *card = pci_get_drvdata(dev); - - if (card->pci_id == PCI_DEVICE_ID_ALI_5451) { - ali_restore_regs(card); - } - return 0; -} -#endif - -static struct trident_channel * -ali_alloc_pcm_channel(struct trident_card *card) -{ - struct trident_pcm_bank *bank; - int idx; - - bank = &card->banks[BANK_A]; - - if (inl(TRID_REG(card, ALI_GLOBAL_CONTROL)) & - (ALI_SPDIF_OUT_CH_ENABLE)) { - idx = ALI_SPDIF_OUT_CHANNEL; - if (!(bank->bitmap & (1 << idx))) { - struct trident_channel *channel = &bank->channels[idx]; - bank->bitmap |= 1 << idx; - channel->num = idx; - return channel; - } - } - - for (idx = ALI_PCM_OUT_CHANNEL_FIRST; idx <= ALI_PCM_OUT_CHANNEL_LAST; - idx++) { - if (!(bank->bitmap & (1 << idx))) { - struct trident_channel *channel = &bank->channels[idx]; - bank->bitmap |= 1 << idx; - channel->num = idx; - return channel; - } - } - - /* no more free channels avaliable */ -#if 0 - printk(KERN_ERR "ali: no more channels available on Bank A.\n"); -#endif /* 0 */ - return NULL; -} - -static struct trident_channel * -ali_alloc_rec_pcm_channel(struct trident_card *card) -{ - struct trident_pcm_bank *bank; - int idx; - - if (inl(TRID_REG(card, ALI_GLOBAL_CONTROL)) & ALI_SPDIF_IN_SUPPORT) - idx = ALI_SPDIF_IN_CHANNEL; - else - idx = ALI_PCM_IN_CHANNEL; - - bank = &card->banks[BANK_A]; - - if (!(bank->bitmap & (1 << idx))) { - struct trident_channel *channel = &bank->channels[idx]; - bank->bitmap |= 1 << idx; - channel->num = idx; - return channel; - } - - /* no free recordable channels avaliable */ -#if 0 - printk(KERN_ERR "ali: no recordable channels available on Bank A.\n"); -#endif /* 0 */ - return NULL; -} - -static void -ali_set_spdif_out_rate(struct trident_card *card, unsigned int rate) -{ - unsigned char ch_st_sel; - unsigned short status_rate; - - switch (rate) { - case 44100: - status_rate = 0; - break; - case 32000: - status_rate = 0x300; - break; - case 48000: - default: - status_rate = 0x200; - break; - } - - /* select spdif_out */ - ch_st_sel = inb(TRID_REG(card, ALI_SPDIF_CTRL)) & ALI_SPDIF_OUT_CH_STATUS; - - ch_st_sel |= 0x80; /* select right */ - outb(ch_st_sel, TRID_REG(card, ALI_SPDIF_CTRL)); - outb(status_rate | 0x20, TRID_REG(card, ALI_SPDIF_CS + 2)); - - ch_st_sel &= (~0x80); /* select left */ - outb(ch_st_sel, TRID_REG(card, ALI_SPDIF_CTRL)); - outw(status_rate | 0x10, TRID_REG(card, ALI_SPDIF_CS + 2)); -} - -static void -ali_address_interrupt(struct trident_card *card) -{ - int i, channel; - struct trident_state *state; - u32 mask, channel_mask; - - mask = trident_get_interrupt_mask(card, 0); - for (i = 0; i < NR_HW_CH; i++) { - if ((state = card->states[i]) == NULL) - continue; - channel = state->dmabuf.channel->num; - if ((channel_mask = 1 << channel) & mask) { - mask &= ~channel_mask; - trident_ack_channel_interrupt(card, channel); - udelay(100); - state->dmabuf.update_flag |= ALI_ADDRESS_INT_UPDATE; - trident_update_ptr(state); - } - } - if (mask) { - for (i = 0; i < NR_HW_CH; i++) { - if (mask & (1 << i)) { - printk("ali: spurious channel irq %d.\n", i); - trident_ack_channel_interrupt(card, i); - trident_stop_voice(card, i); - trident_disable_voice_irq(card, i); - } - } - } -} - -/* Updating the values of counters of other_states' DMAs without lock -protection is no harm because all DMAs of multi-channels and interrupt -depend on a master state's DMA, and changing the counters of the master -state DMA is protected by a spinlock. -*/ -static int -ali_write_5_1(struct trident_state *state, const char __user *buf, - int cnt_for_multi_channel, unsigned int *copy_count, - unsigned int *state_cnt) -{ - - struct dmabuf *dmabuf = &state->dmabuf; - struct dmabuf *dmabuf_temp; - const char __user *buffer = buf; - unsigned swptr, other_dma_nums, sample_s; - unsigned int i, loop; - - other_dma_nums = 4; - sample_s = sample_size[dmabuf->fmt] >> 1; - swptr = dmabuf->swptr; - - if ((i = state->multi_channels_adjust_count) > 0) { - if (i == 1) { - if (copy_from_user(dmabuf->rawbuf + swptr, - buffer, sample_s)) - return -EFAULT; - seek_offset(swptr, buffer, cnt_for_multi_channel, - sample_s, *copy_count); - i--; - (*state_cnt) += sample_s; - state->multi_channels_adjust_count++; - } else - i = i - (state->chans_num - other_dma_nums); - for (; (i < other_dma_nums) && (cnt_for_multi_channel > 0); i++) { - dmabuf_temp = &state->other_states[i]->dmabuf; - if (copy_from_user(dmabuf_temp->rawbuf + dmabuf_temp->swptr, - buffer, sample_s)) - return -EFAULT; - seek_offset(dmabuf_temp->swptr, buffer, cnt_for_multi_channel, - sample_s, *copy_count); - } - if (cnt_for_multi_channel == 0) - state->multi_channels_adjust_count += i; - } - if (cnt_for_multi_channel > 0) { - loop = cnt_for_multi_channel / (state->chans_num * sample_s); - for (i = 0; i < loop; i++) { - if (copy_from_user(dmabuf->rawbuf + swptr, buffer, - sample_s * 2)) - return -EFAULT; - seek_offset(swptr, buffer, cnt_for_multi_channel, - sample_s * 2, *copy_count); - (*state_cnt) += (sample_s * 2); - - dmabuf_temp = &state->other_states[0]->dmabuf; - if (copy_from_user(dmabuf_temp->rawbuf + dmabuf_temp->swptr, - buffer, sample_s)) - return -EFAULT; - seek_offset(dmabuf_temp->swptr, buffer, cnt_for_multi_channel, - sample_s, *copy_count); - - dmabuf_temp = &state->other_states[1]->dmabuf; - if (copy_from_user(dmabuf_temp->rawbuf + dmabuf_temp->swptr, - buffer, sample_s)) - return -EFAULT; - seek_offset(dmabuf_temp->swptr, buffer, cnt_for_multi_channel, - sample_s, *copy_count); - - dmabuf_temp = &state->other_states[2]->dmabuf; - if (copy_from_user(dmabuf_temp->rawbuf + dmabuf_temp->swptr, - buffer, sample_s)) - return -EFAULT; - seek_offset(dmabuf_temp->swptr, buffer, cnt_for_multi_channel, - sample_s, *copy_count); - - dmabuf_temp = &state->other_states[3]->dmabuf; - if (copy_from_user(dmabuf_temp->rawbuf + dmabuf_temp->swptr, - buffer, sample_s)) - return -EFAULT; - seek_offset(dmabuf_temp->swptr, buffer, cnt_for_multi_channel, - sample_s, *copy_count); - } - - if (cnt_for_multi_channel > 0) { - state->multi_channels_adjust_count = cnt_for_multi_channel / sample_s; - - if (copy_from_user(dmabuf->rawbuf + swptr, buffer, sample_s)) - return -EFAULT; - seek_offset(swptr, buffer, cnt_for_multi_channel, - sample_s, *copy_count); - (*state_cnt) += sample_s; - - if (cnt_for_multi_channel > 0) { - if (copy_from_user(dmabuf->rawbuf + swptr, - buffer, sample_s)) - return -EFAULT; - seek_offset(swptr, buffer, cnt_for_multi_channel, - sample_s, *copy_count); - (*state_cnt) += sample_s; - - if (cnt_for_multi_channel > 0) { - int diff = state->chans_num - other_dma_nums; - loop = state->multi_channels_adjust_count - diff; - for (i = 0; i < loop; i++) { - dmabuf_temp = &state->other_states[i]->dmabuf; - if (copy_from_user(dmabuf_temp->rawbuf + - dmabuf_temp->swptr, - buffer, sample_s)) - return -EFAULT; - seek_offset(dmabuf_temp->swptr, buffer, - cnt_for_multi_channel, - sample_s, *copy_count); - } - } - } - } else - state->multi_channels_adjust_count = 0; - } - for (i = 0; i < other_dma_nums; i++) { - dmabuf_temp = &state->other_states[i]->dmabuf; - dmabuf_temp->swptr = dmabuf_temp->swptr % dmabuf_temp->dmasize; - } - return *state_cnt; -} - -static void -ali_free_other_states_resources(struct trident_state *state) -{ - int i; - struct trident_card *card = state->card; - struct trident_state *s; - unsigned other_states_count; - - other_states_count = state->chans_num - 2; /* except PCM L/R channels */ - for (i = 0; i < other_states_count; i++) { - s = state->other_states[i]; - dealloc_dmabuf(&s->dmabuf, card->pci_dev); - ali_disable_special_channel(s->card, s->dmabuf.channel->num); - state->card->free_pcm_channel(s->card, s->dmabuf.channel->num); - card->states[s->virt] = NULL; - kfree(s); - } -} - -static struct proc_dir_entry *res; - -static int -ali_write_proc(struct file *file, const char __user *buffer, unsigned long count, void *data) -{ - struct trident_card *card = (struct trident_card *) data; - unsigned long flags; - char c; - - if (count < 0) - return -EINVAL; - if (count == 0) - return 0; - if (get_user(c, buffer)) - return -EFAULT; - - spin_lock_irqsave(&card->lock, flags); - switch (c) { - case '0': - ali_setup_spdif_out(card, ALI_PCM_TO_SPDIF_OUT); - ali_disable_special_channel(card, ALI_SPDIF_OUT_CHANNEL); - break; - case '1': - ali_setup_spdif_out(card, ALI_SPDIF_OUT_TO_SPDIF_OUT | - ALI_SPDIF_OUT_PCM); - break; - case '2': - ali_setup_spdif_out(card, ALI_SPDIF_OUT_TO_SPDIF_OUT | - ALI_SPDIF_OUT_NON_PCM); - break; - case '3': - ali_disable_spdif_in(card); //default - break; - case '4': - ali_setup_spdif_in(card); - break; - } - spin_unlock_irqrestore(&card->lock, flags); - - return count; -} - -/* OSS /dev/mixer file operation methods */ -static int -trident_open_mixdev(struct inode *inode, struct file *file) -{ - int i = 0; - int minor = iminor(inode); - struct trident_card *card = devs; - - for (card = devs; card != NULL; card = card->next) - for (i = 0; i < NR_AC97; i++) - if (card->ac97_codec[i] != NULL && - card->ac97_codec[i]->dev_mixer == minor) - goto match; - - if (!card) { - return -ENODEV; - } - match: - file->private_data = card->ac97_codec[i]; - - return nonseekable_open(inode, file); -} - -static int -trident_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, - unsigned long arg) -{ - struct ac97_codec *codec = (struct ac97_codec *) file->private_data; - - return codec->mixer_ioctl(codec, cmd, arg); -} - -static const struct file_operations trident_mixer_fops = { - .owner = THIS_MODULE, - .llseek = no_llseek, - .ioctl = trident_ioctl_mixdev, - .open = trident_open_mixdev, -}; - -static int -ali_reset_5451(struct trident_card *card) -{ - struct pci_dev *pci_dev = NULL; - unsigned int dwVal; - unsigned short wCount, wReg; - - pci_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, - pci_dev); - if (pci_dev == NULL) - return -1; - - pci_read_config_dword(pci_dev, 0x7c, &dwVal); - pci_write_config_dword(pci_dev, 0x7c, dwVal | 0x08000000); - udelay(5000); - pci_read_config_dword(pci_dev, 0x7c, &dwVal); - pci_write_config_dword(pci_dev, 0x7c, dwVal & 0xf7ffffff); - udelay(5000); - pci_dev_put(pci_dev); - - pci_dev = card->pci_dev; - if (pci_dev == NULL) - return -1; - - pci_read_config_dword(pci_dev, 0x44, &dwVal); - pci_write_config_dword(pci_dev, 0x44, dwVal | 0x000c0000); - udelay(500); - pci_read_config_dword(pci_dev, 0x44, &dwVal); - pci_write_config_dword(pci_dev, 0x44, dwVal & 0xfffbffff); - udelay(5000); - - /* TODO: recognize if we have a PM capable codec and only do this */ - /* if the codec is PM capable */ - wCount = 2000; - while (wCount--) { - wReg = ali_ac97_get(card, 0, AC97_POWER_CONTROL); - if ((wReg & 0x000f) == 0x000f) - return 0; - udelay(5000); - } - /* This is non fatal if you have a non PM capable codec.. */ - return 0; -} - -/* AC97 codec initialisation. */ -static int __devinit -trident_ac97_init(struct trident_card *card) -{ - int num_ac97 = 0; - unsigned long ready_2nd = 0; - struct ac97_codec *codec; - int i = 0; - - /* initialize controller side of AC link, and find out if secondary codes - really exist */ - switch (card->pci_id) { - case PCI_DEVICE_ID_ALI_5451: - if (ali_reset_5451(card)) { - printk(KERN_ERR "trident_ac97_init: error " - "resetting 5451.\n"); - return -1; - } - outl(0x80000001, TRID_REG(card, ALI_GLOBAL_CONTROL)); - outl(0x00000000, TRID_REG(card, T4D_AINTEN_A)); - outl(0xffffffff, TRID_REG(card, T4D_AINT_A)); - outl(0x00000000, TRID_REG(card, T4D_MUSICVOL_WAVEVOL)); - outb(0x10, TRID_REG(card, ALI_MPUR2)); - ready_2nd = inl(TRID_REG(card, ALI_SCTRL)); - ready_2nd &= 0x3fff; - outl(ready_2nd | PCMOUT | 0x8000, TRID_REG(card, ALI_SCTRL)); - ready_2nd = inl(TRID_REG(card, ALI_SCTRL)); - ready_2nd &= SI_AC97_SECONDARY_READY; - if (card->revision < ALI_5451_V02) - ready_2nd = 0; - break; - case PCI_DEVICE_ID_SI_7018: - /* disable AC97 GPIO interrupt */ - outl(0x00, TRID_REG(card, SI_AC97_GPIO)); - /* when power up the AC link is in cold reset mode so stop it */ - outl(PCMOUT | SURROUT | CENTEROUT | LFEOUT | SECONDARY_ID, - TRID_REG(card, SI_SERIAL_INTF_CTRL)); - /* it take a long time to recover from a cold reset */ - /* (especially when you have more than one codec) */ - udelay(2000); - ready_2nd = inl(TRID_REG(card, SI_SERIAL_INTF_CTRL)); - ready_2nd &= SI_AC97_SECONDARY_READY; - break; - case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX: - /* playback on */ - outl(DX_AC97_PLAYBACK, TRID_REG(card, DX_ACR2_AC97_COM_STAT)); - break; - case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX: - /* enable AC97 Output Slot 3,4 (PCM Left/Right Playback) */ - outl(NX_AC97_PCM_OUTPUT, TRID_REG(card, NX_ACR0_AC97_COM_STAT)); - ready_2nd = inl(TRID_REG(card, NX_ACR0_AC97_COM_STAT)); - ready_2nd &= NX_AC97_SECONDARY_READY; - break; - case PCI_DEVICE_ID_INTERG_5050: - /* disable AC97 GPIO interrupt */ - outl(0x00, TRID_REG(card, SI_AC97_GPIO)); - /* when power up, the AC link is in cold reset mode, so stop it */ - outl(PCMOUT | SURROUT | CENTEROUT | LFEOUT, - TRID_REG(card, SI_SERIAL_INTF_CTRL)); - /* it take a long time to recover from a cold reset (especially */ - /* when you have more than one codec) */ - udelay(2000); - ready_2nd = inl(TRID_REG(card, SI_SERIAL_INTF_CTRL)); - ready_2nd &= SI_AC97_SECONDARY_READY; - break; - } - - for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) { - if ((codec = ac97_alloc_codec()) == NULL) - return -ENOMEM; - - /* initialize some basic codec information, other fields */ - /* will be filled in ac97_probe_codec */ - codec->private_data = card; - codec->id = num_ac97; - - if (card->pci_id == PCI_DEVICE_ID_ALI_5451) { - codec->codec_read = ali_ac97_read; - codec->codec_write = ali_ac97_write; - } else { - codec->codec_read = trident_ac97_get; - codec->codec_write = trident_ac97_set; - } - - if (ac97_probe_codec(codec) == 0) - break; - - codec->dev_mixer = register_sound_mixer(&trident_mixer_fops, -1); - if (codec->dev_mixer < 0) { - printk(KERN_ERR "trident: couldn't register mixer!\n"); - ac97_release_codec(codec); - break; - } - - card->ac97_codec[num_ac97] = codec; - - /* if there is no secondary codec at all, don't probe any more */ - if (!ready_2nd) - break; - } - - if (card->pci_id == PCI_DEVICE_ID_ALI_5451) { - for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) { - if (card->ac97_codec[num_ac97] == NULL) - break; - for (i = 0; i < 64; i++) { - u16 reg = ali_ac97_get(card, num_ac97, i * 2); - card->mixer_regs[i][num_ac97] = reg; - } - } - } - return num_ac97 + 1; -} - -#ifdef SUPPORT_JOYSTICK -/* Gameport functions for the cards ADC gameport */ - -static unsigned char trident_game_read(struct gameport *gameport) -{ - struct trident_card *card = gameport->port_data; - - return inb(TRID_REG(card, T4D_GAME_LEG)); -} - -static void trident_game_trigger(struct gameport *gameport) -{ - struct trident_card *card = gameport->port_data; - - outb(0xff, TRID_REG(card, T4D_GAME_LEG)); -} - -static int trident_game_cooked_read(struct gameport *gameport, - int *axes, int *buttons) -{ - struct trident_card *card = gameport->port_data; - int i; - - *buttons = (~inb(TRID_REG(card, T4D_GAME_LEG)) >> 4) & 0xf; - - for (i = 0; i < 4; i++) { - axes[i] = inw(TRID_REG(card, T4D_GAME_AXD) + i * sizeof (u16)); - if (axes[i] == 0xffff) - axes[i] = -1; - } - - return 0; -} - -static int trident_game_open(struct gameport *gameport, int mode) -{ - struct trident_card *card = gameport->port_data; - - switch (mode) { - case GAMEPORT_MODE_COOKED: - outb(0x80, TRID_REG(card, T4D_GAME_CR)); - msleep(20); - return 0; - case GAMEPORT_MODE_RAW: - outb(0x00, TRID_REG(card, T4D_GAME_CR)); - return 0; - default: - return -1; - } - - return 0; -} - -static int __devinit trident_register_gameport(struct trident_card *card) -{ - struct gameport *gp; - - card->gameport = gp = gameport_allocate_port(); - if (!gp) { - printk(KERN_ERR "trident: can not allocate memory for gameport\n"); - return -ENOMEM; - } - - gameport_set_name(gp, "Trident 4DWave"); - gameport_set_phys(gp, "pci%s/gameport0", pci_name(card->pci_dev)); - gp->read = trident_game_read; - gp->trigger = trident_game_trigger; - gp->cooked_read = trident_game_cooked_read; - gp->open = trident_game_open; - gp->fuzz = 64; - gp->port_data = card; - - gameport_register_port(gp); - - return 0; -} - -static inline void trident_unregister_gameport(struct trident_card *card) -{ - if (card->gameport) - gameport_unregister_port(card->gameport); -} - -#else -static inline int trident_register_gameport(struct trident_card *card) { return -ENOSYS; } -static inline void trident_unregister_gameport(struct trident_card *card) { } -#endif /* SUPPORT_JOYSTICK */ - -/* install the driver, we do not allocate hardware channel nor DMA buffer */ -/* now, they are defered until "ACCESS" time (in prog_dmabuf called by */ -/* open/read/write/ioctl/mmap) */ -static int __devinit -trident_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id) -{ - unsigned long iobase; - struct trident_card *card; - u8 bits; - u8 revision; - int i = 0; - u16 temp; - struct pci_dev *pci_dev_m1533 = NULL; - int rc = -ENODEV; - u64 dma_mask; - - if (pci_enable_device(pci_dev)) - goto out; - - if (pci_dev->device == PCI_DEVICE_ID_ALI_5451) - dma_mask = ALI_DMA_MASK; - else - dma_mask = TRIDENT_DMA_MASK; - if (pci_set_dma_mask(pci_dev, dma_mask)) { - printk(KERN_ERR "trident: architecture does not support" - " %s PCI busmaster DMA\n", - pci_dev->device == PCI_DEVICE_ID_ALI_5451 ? - "32-bit" : "30-bit"); - goto out; - } - pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &revision); - - if (pci_id->device == PCI_DEVICE_ID_INTERG_5050) - iobase = pci_resource_start(pci_dev, 1); - else - iobase = pci_resource_start(pci_dev, 0); - - if (!request_region(iobase, 256, card_names[pci_id->driver_data])) { - printk(KERN_ERR "trident: can't allocate I/O space at " - "0x%4.4lx\n", iobase); - goto out; - } - - rc = -ENOMEM; - if ((card = kzalloc(sizeof(*card), GFP_KERNEL)) == NULL) { - printk(KERN_ERR "trident: out of memory\n"); - goto out_release_region; - } - - init_timer(&card->timer); - card->iobase = iobase; - card->pci_dev = pci_dev_get(pci_dev); - card->pci_id = pci_id->device; - card->revision = revision; - card->irq = pci_dev->irq; - card->next = devs; - card->magic = TRIDENT_CARD_MAGIC; - card->banks[BANK_A].addresses = &bank_a_addrs; - card->banks[BANK_A].bitmap = 0UL; - card->banks[BANK_B].addresses = &bank_b_addrs; - card->banks[BANK_B].bitmap = 0UL; - - mutex_init(&card->open_mutex); - spin_lock_init(&card->lock); - init_timer(&card->timer); - - devs = card; - - pci_set_master(pci_dev); - - printk(KERN_INFO "trident: %s found at IO 0x%04lx, IRQ %d\n", - card_names[pci_id->driver_data], card->iobase, card->irq); - - if (card->pci_id == PCI_DEVICE_ID_ALI_5451) { - /* ALi channel Management */ - card->alloc_pcm_channel = ali_alloc_pcm_channel; - card->alloc_rec_pcm_channel = ali_alloc_rec_pcm_channel; - card->free_pcm_channel = ali_free_pcm_channel; - - card->address_interrupt = ali_address_interrupt; - - /* Added by Matt Wu 01-05-2001 for spdif in */ - card->multi_channel_use_count = 0; - card->rec_channel_use_count = 0; - - /* ALi SPDIF OUT function */ - if (card->revision == ALI_5451_V02) { - ali_setup_spdif_out(card, ALI_PCM_TO_SPDIF_OUT); - res = create_proc_entry("ALi5451", 0, NULL); - if (res) { - res->write_proc = ali_write_proc; - res->data = card; - } - } - - /* Add H/W Volume Control By Matt Wu Jul. 06, 2001 */ - card->hwvolctl = 0; - pci_dev_m1533 = pci_get_device(PCI_VENDOR_ID_AL, - PCI_DEVICE_ID_AL_M1533, - pci_dev_m1533); - rc = -ENODEV; - if (pci_dev_m1533 == NULL) - goto out_proc_fs; - pci_read_config_byte(pci_dev_m1533, 0x63, &bits); - if (bits & (1 << 5)) - card->hwvolctl = 1; - if (card->hwvolctl) { - /* Clear m1533 pci cfg 78h bit 30 to zero, which makes - GPIO11/12/13 work as ACGP_UP/DOWN/MUTE. */ - pci_read_config_byte(pci_dev_m1533, 0x7b, &bits); - bits &= 0xbf; /*clear bit 6 */ - pci_write_config_byte(pci_dev_m1533, 0x7b, bits); - } - pci_dev_put(pci_dev_m1533); - - } else if (card->pci_id == PCI_DEVICE_ID_INTERG_5050) { - card->alloc_pcm_channel = cyber_alloc_pcm_channel; - card->alloc_rec_pcm_channel = cyber_alloc_pcm_channel; - card->free_pcm_channel = cyber_free_pcm_channel; - card->address_interrupt = cyber_address_interrupt; - cyber_init_ritual(card); - } else { - card->alloc_pcm_channel = trident_alloc_pcm_channel; - card->alloc_rec_pcm_channel = trident_alloc_pcm_channel; - card->free_pcm_channel = trident_free_pcm_channel; - card->address_interrupt = trident_address_interrupt; - } - - /* claim our irq */ - rc = -ENODEV; - if (request_irq(card->irq, &trident_interrupt, IRQF_SHARED, - card_names[pci_id->driver_data], card)) { - printk(KERN_ERR "trident: unable to allocate irq %d\n", - card->irq); - goto out_proc_fs; - } - /* register /dev/dsp */ - if ((card->dev_audio = register_sound_dsp(&trident_audio_fops, -1)) < 0) { - printk(KERN_ERR "trident: couldn't register DSP device!\n"); - goto out_free_irq; - } - card->mixer_regs_ready = 0; - /* initialize AC97 codec and register /dev/mixer */ - if (trident_ac97_init(card) <= 0) { - /* unregister audio devices */ - for (i = 0; i < NR_AC97; i++) { - if (card->ac97_codec[i] != NULL) { - struct ac97_codec* codec = card->ac97_codec[i]; - unregister_sound_mixer(codec->dev_mixer); - ac97_release_codec(codec); - } - } - goto out_unregister_sound_dsp; - } - card->mixer_regs_ready = 1; - outl(0x00, TRID_REG(card, T4D_MUSICVOL_WAVEVOL)); - - if (card->pci_id == PCI_DEVICE_ID_ALI_5451) { - /* Add H/W Volume Control By Matt Wu Jul. 06, 2001 */ - if (card->hwvolctl) { - /* Enable GPIO IRQ (MISCINT bit 18h) */ - temp = inw(TRID_REG(card, T4D_MISCINT + 2)); - temp |= 0x0004; - outw(temp, TRID_REG(card, T4D_MISCINT + 2)); - - /* Enable H/W Volume Control GLOVAL CONTROL bit 0 */ - temp = inw(TRID_REG(card, ALI_GLOBAL_CONTROL)); - temp |= 0x0001; - outw(temp, TRID_REG(card, ALI_GLOBAL_CONTROL)); - - } - if (card->revision == ALI_5451_V02) - ali_close_multi_channels(); - /* edited by HMSEO for GT sound */ -#if defined(CONFIG_ALPHA_NAUTILUS) || defined(CONFIG_ALPHA_GENERIC) - { - u16 ac97_data; - extern struct hwrpb_struct *hwrpb; - - if ((hwrpb->sys_type) == 201) { - printk(KERN_INFO "trident: Running on Alpha system " - "type Nautilus\n"); - ac97_data = ali_ac97_get(card, 0, AC97_POWER_CONTROL); - ali_ac97_set(card, 0, AC97_POWER_CONTROL, - ac97_data | ALI_EAPD_POWER_DOWN); - } - } -#endif /* CONFIG_ALPHA_NAUTILUS || CONFIG_ALPHA_GENERIC */ - /* edited by HMSEO for GT sound */ - } - rc = 0; - pci_set_drvdata(pci_dev, card); - - /* Enable Address Engine Interrupts */ - trident_enable_loop_interrupts(card); - - /* Register gameport */ - trident_register_gameport(card); - -out: - return rc; - -out_unregister_sound_dsp: - unregister_sound_dsp(card->dev_audio); -out_free_irq: - free_irq(card->irq, card); -out_proc_fs: - pci_dev_put(card->pci_dev); - if (res) { - remove_proc_entry("ALi5451", NULL); - res = NULL; - } - kfree(card); - devs = NULL; -out_release_region: - release_region(iobase, 256); - return rc; -} - -static void __devexit -trident_remove(struct pci_dev *pci_dev) -{ - int i; - struct trident_card *card = pci_get_drvdata(pci_dev); - - /* - * Kill running timers before unload. We can't have them - * going off after rmmod! - */ - if (card->hwvolctl) - del_timer_sync(&card->timer); - - /* ALi S/PDIF and Power Management */ - if (card->pci_id == PCI_DEVICE_ID_ALI_5451) { - ali_setup_spdif_out(card, ALI_PCM_TO_SPDIF_OUT); - ali_disable_special_channel(card, ALI_SPDIF_OUT_CHANNEL); - ali_disable_spdif_in(card); - remove_proc_entry("ALi5451", NULL); - } - - /* Unregister gameport */ - trident_unregister_gameport(card); - - /* Kill interrupts, and SP/DIF */ - trident_disable_loop_interrupts(card); - - /* free hardware resources */ - free_irq(card->irq, card); - release_region(card->iobase, 256); - - /* unregister audio devices */ - for (i = 0; i < NR_AC97; i++) - if (card->ac97_codec[i] != NULL) { - unregister_sound_mixer(card->ac97_codec[i]->dev_mixer); - ac97_release_codec(card->ac97_codec[i]); - } - unregister_sound_dsp(card->dev_audio); - - pci_set_drvdata(pci_dev, NULL); - pci_dev_put(card->pci_dev); - kfree(card); -} - -MODULE_AUTHOR("Alan Cox, Aaron Holtzman, Ollie Lho, Ching Ling Lee, Muli Ben-Yehuda"); -MODULE_DESCRIPTION("Trident 4DWave/SiS 7018/ALi 5451 and Tvia/IGST CyberPro5050 PCI " - "Audio Driver"); -MODULE_LICENSE("GPL"); - -#define TRIDENT_MODULE_NAME "trident" - -static struct pci_driver trident_pci_driver = { - .name = TRIDENT_MODULE_NAME, - .id_table = trident_pci_tbl, - .probe = trident_probe, - .remove = __devexit_p(trident_remove), -#ifdef CONFIG_PM - .suspend = trident_suspend, - .resume = trident_resume -#endif -}; - -static int __init -trident_init_module(void) -{ - printk(KERN_INFO "Trident 4DWave/SiS 7018/ALi 5451,Tvia CyberPro " - "5050 PCI Audio, version " DRIVER_VERSION ", " __TIME__ " " - __DATE__ "\n"); - - return pci_register_driver(&trident_pci_driver); -} - -static void __exit -trident_cleanup_module(void) -{ - pci_unregister_driver(&trident_pci_driver); -} - -module_init(trident_init_module); -module_exit(trident_cleanup_module); diff --git a/sound/oss/trident.h b/sound/oss/trident.h deleted file mode 100644 index ff30a1d7c2f1..000000000000 --- a/sound/oss/trident.h +++ /dev/null @@ -1,358 +0,0 @@ -#ifndef __TRID4DWAVE_H -#define __TRID4DWAVE_H - -/* - * audio@tridentmicro.com - * Fri Feb 19 15:55:28 MST 1999 - * Definitions for Trident 4DWave DX/NX 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -/* PCI vendor and device ID */ -#ifndef PCI_VENDOR_ID_TRIDENT -#define PCI_VENDOR_ID_TRIDENT 0x1023 -#endif - -#ifndef PCI_VENDOR_ID_SI -#define PCI_VENDOR_ID_SI 0x1039 -#endif - -#ifndef PCI_VENDOR_ID_ALI -#define PCI_VENDOR_ID_ALI 0x10b9 -#endif - -#ifndef PCI_DEVICE_ID_TRIDENT_4DWAVE_DX -#define PCI_DEVICE_ID_TRIDENT_4DWAVE_DX 0x2000 -#endif - -#ifndef PCI_DEVICE_ID_TRIDENT_4DWAVE_NX -#define PCI_DEVICE_ID_TRIDENT_4DWAVE_NX 0x2001 -#endif - -#ifndef PCI_DEVICE_ID_SI_7018 -#define PCI_DEVICE_ID_SI_7018 0x7018 -#endif - -#ifndef PCI_DEVICE_ID_ALI_5451 -#define PCI_DEVICE_ID_ALI_5451 0x5451 -#endif - -#ifndef PCI_DEVICE_ID_ALI_1533 -#define PCI_DEVICE_ID_ALI_1533 0x1533 -#endif - -#define CHANNEL_REGS 5 -#define CHANNEL_START 0xe0 // The first bytes of the contiguous register space. - -#define BANK_A 0 -#define BANK_B 1 -#define NR_BANKS 2 - -#define TRIDENT_FMT_STEREO 0x01 -#define TRIDENT_FMT_16BIT 0x02 -#define TRIDENT_FMT_MASK 0x03 - -#define DAC_RUNNING 0x01 -#define ADC_RUNNING 0x02 - -/* Register Addresses */ - -/* operational registers common to DX, NX, 7018 */ -enum trident_op_registers { - T4D_GAME_CR = 0x30, T4D_GAME_LEG = 0x31, - T4D_GAME_AXD = 0x34, - T4D_REC_CH = 0x70, - T4D_START_A = 0x80, T4D_STOP_A = 0x84, - T4D_DLY_A = 0x88, T4D_SIGN_CSO_A = 0x8c, - T4D_CSPF_A = 0x90, T4D_CEBC_A = 0x94, - T4D_AINT_A = 0x98, T4D_EINT_A = 0x9c, - T4D_LFO_GC_CIR = 0xa0, T4D_AINTEN_A = 0xa4, - T4D_MUSICVOL_WAVEVOL = 0xa8, T4D_SBDELTA_DELTA_R = 0xac, - T4D_MISCINT = 0xb0, T4D_START_B = 0xb4, - T4D_STOP_B = 0xb8, T4D_CSPF_B = 0xbc, - T4D_SBBL_SBCL = 0xc0, T4D_SBCTRL_SBE2R_SBDD = 0xc4, - T4D_STIMER = 0xc8, T4D_LFO_B_I2S_DELTA = 0xcc, - T4D_AINT_B = 0xd8, T4D_AINTEN_B = 0xdc, - ALI_MPUR2 = 0x22, ALI_GPIO = 0x7c, - ALI_EBUF1 = 0xf4, - ALI_EBUF2 = 0xf8 -}; - -enum ali_op_registers { - ALI_SCTRL = 0x48, - ALI_GLOBAL_CONTROL = 0xd4, - ALI_STIMER = 0xc8, - ALI_SPDIF_CS = 0x70, - ALI_SPDIF_CTRL = 0x74 -}; - -enum ali_registers_number { - ALI_GLOBAL_REGS = 56, - ALI_CHANNEL_REGS = 8, - ALI_MIXER_REGS = 20 -}; - -enum ali_sctrl_control_bit { - ALI_SPDIF_OUT_ENABLE = 0x20 -}; - -enum ali_global_control_bit { - ALI_SPDIF_OUT_SEL_PCM = 0x00000400, - ALI_SPDIF_IN_SUPPORT = 0x00000800, - ALI_SPDIF_OUT_CH_ENABLE = 0x00008000, - ALI_SPDIF_IN_CH_ENABLE = 0x00080000, - ALI_PCM_IN_DISABLE = 0x7fffffff, - ALI_PCM_IN_ENABLE = 0x80000000, - ALI_SPDIF_IN_CH_DISABLE = 0xfff7ffff, - ALI_SPDIF_OUT_CH_DISABLE = 0xffff7fff, - ALI_SPDIF_OUT_SEL_SPDIF = 0xfffffbff - -}; - -enum ali_spdif_control_bit { - ALI_SPDIF_IN_FUNC_ENABLE = 0x02, - ALI_SPDIF_IN_CH_STATUS = 0x40, - ALI_SPDIF_OUT_CH_STATUS = 0xbf - -}; - -enum ali_control_all { - ALI_DISABLE_ALL_IRQ = 0, - ALI_CHANNELS = 32, - ALI_STOP_ALL_CHANNELS = 0xffffffff, - ALI_MULTI_CHANNELS_START_STOP = 0x07800000 -}; - -enum ali_EMOD_control_bit { - ALI_EMOD_DEC = 0x00000000, - ALI_EMOD_INC = 0x10000000, - ALI_EMOD_Delay = 0x20000000, - ALI_EMOD_Still = 0x30000000 -}; - -enum ali_pcm_in_channel_num { - ALI_NORMAL_CHANNEL = 0, - ALI_SPDIF_OUT_CHANNEL = 15, - ALI_SPDIF_IN_CHANNEL = 19, - ALI_LEF_CHANNEL = 23, - ALI_CENTER_CHANNEL = 24, - ALI_SURR_RIGHT_CHANNEL = 25, - ALI_SURR_LEFT_CHANNEL = 26, - ALI_PCM_IN_CHANNEL = 31 -}; - -enum ali_pcm_out_channel_num { - ALI_PCM_OUT_CHANNEL_FIRST = 0, - ALI_PCM_OUT_CHANNEL_LAST = 31 -}; - -enum ali_ac97_power_control_bit { - ALI_EAPD_POWER_DOWN = 0x8000 -}; - -enum ali_update_ptr_flags { - ALI_ADDRESS_INT_UPDATE = 0x01 -}; - -enum ali_revision { - ALI_5451_V02 = 0x02 -}; - -enum ali_spdif_out_control { - ALI_PCM_TO_SPDIF_OUT = 0, - ALI_SPDIF_OUT_TO_SPDIF_OUT = 1, - ALI_SPDIF_OUT_PCM = 0, - ALI_SPDIF_OUT_NON_PCM = 2 -}; - -/* S/PDIF Operational Registers for 4D-NX */ -enum nx_spdif_registers { - NX_SPCTRL_SPCSO = 0x24, NX_SPLBA = 0x28, - NX_SPESO = 0x2c, NX_SPCSTATUS = 0x64 -}; - -/* OP registers to access each hardware channel */ -enum channel_registers { - CH_DX_CSO_ALPHA_FMS = 0xe0, CH_DX_ESO_DELTA = 0xe8, - CH_DX_FMC_RVOL_CVOL = 0xec, - CH_NX_DELTA_CSO = 0xe0, CH_NX_DELTA_ESO = 0xe8, - CH_NX_ALPHA_FMS_FMC_RVOL_CVOL = 0xec, - CH_LBA = 0xe4, - CH_GVSEL_PAN_VOL_CTRL_EC = 0xf0 -}; - -/* registers to read/write/control AC97 codec */ -enum dx_ac97_registers { - DX_ACR0_AC97_W = 0x40, DX_ACR1_AC97_R = 0x44, - DX_ACR2_AC97_COM_STAT = 0x48 -}; - -enum nx_ac97_registers { - NX_ACR0_AC97_COM_STAT = 0x40, NX_ACR1_AC97_W = 0x44, - NX_ACR2_AC97_R_PRIMARY = 0x48, NX_ACR3_AC97_R_SECONDARY = 0x4c -}; - -enum si_ac97_registers { - SI_AC97_WRITE = 0x40, SI_AC97_READ = 0x44, - SI_SERIAL_INTF_CTRL = 0x48, SI_AC97_GPIO = 0x4c -}; - -enum ali_ac97_registers { - ALI_AC97_WRITE = 0x40, ALI_AC97_READ = 0x44 -}; - -/* Bit mask for operational registers */ -#define AC97_REG_ADDR 0x000000ff - -enum ali_ac97_bits { - ALI_AC97_BUSY_WRITE = 0x8000, ALI_AC97_BUSY_READ = 0x8000, - ALI_AC97_WRITE_ACTION = 0x8000, ALI_AC97_READ_ACTION = 0x8000, - ALI_AC97_AUDIO_BUSY = 0x4000, ALI_AC97_SECONDARY = 0x0080, - ALI_AC97_READ_MIXER_REGISTER = 0xfeff, - ALI_AC97_WRITE_MIXER_REGISTER = 0x0100 -}; - -enum sis7018_ac97_bits { - SI_AC97_BUSY_WRITE = 0x8000, SI_AC97_BUSY_READ = 0x8000, - SI_AC97_AUDIO_BUSY = 0x4000, SI_AC97_MODEM_BUSY = 0x2000, - SI_AC97_SECONDARY = 0x0080 -}; - -enum trident_dx_ac97_bits { - DX_AC97_BUSY_WRITE = 0x8000, DX_AC97_BUSY_READ = 0x8000, - DX_AC97_READY = 0x0010, DX_AC97_RECORD = 0x0008, - DX_AC97_PLAYBACK = 0x0002 -}; - -enum trident_nx_ac97_bits { - /* ACR1-3 */ - NX_AC97_BUSY_WRITE = 0x0800, NX_AC97_BUSY_READ = 0x0800, - NX_AC97_BUSY_DATA = 0x0400, NX_AC97_WRITE_SECONDARY = 0x0100, - /* ACR0 */ - NX_AC97_SECONDARY_READY = 0x0040, NX_AC97_SECONDARY_RECORD = 0x0020, - NX_AC97_SURROUND_OUTPUT = 0x0010, - NX_AC97_PRIMARY_READY = 0x0008, NX_AC97_PRIMARY_RECORD = 0x0004, - NX_AC97_PCM_OUTPUT = 0x0002, - NX_AC97_WARM_RESET = 0x0001 -}; - -enum serial_intf_ctrl_bits { - WARM_REST = 0x00000001, COLD_RESET = 0x00000002, - I2S_CLOCK = 0x00000004, PCM_SEC_AC97= 0x00000008, - AC97_DBL_RATE = 0x00000010, SPDIF_EN = 0x00000020, - I2S_OUTPUT_EN = 0x00000040, I2S_INPUT_EN = 0x00000080, - PCMIN = 0x00000100, LINE1IN = 0x00000200, - MICIN = 0x00000400, LINE2IN = 0x00000800, - HEAD_SET_IN = 0x00001000, GPIOIN = 0x00002000, - /* 7018 spec says id = 01 but the demo board routed to 10 - SECONDARY_ID= 0x00004000, */ - SECONDARY_ID= 0x00004000, - PCMOUT = 0x00010000, SURROUT = 0x00020000, - CENTEROUT = 0x00040000, LFEOUT = 0x00080000, - LINE1OUT = 0x00100000, LINE2OUT = 0x00200000, - GPIOOUT = 0x00400000, - SI_AC97_PRIMARY_READY = 0x01000000, - SI_AC97_SECONDARY_READY = 0x02000000, -}; - -enum global_control_bits { - CHANNLE_IDX = 0x0000003f, PB_RESET = 0x00000100, - PAUSE_ENG = 0x00000200, - OVERRUN_IE = 0x00000400, UNDERRUN_IE = 0x00000800, - ENDLP_IE = 0x00001000, MIDLP_IE = 0x00002000, - ETOG_IE = 0x00004000, - EDROP_IE = 0x00008000, BANK_B_EN = 0x00010000 -}; - -enum channel_control_bits { - CHANNEL_LOOP = 0x00001000, CHANNEL_SIGNED = 0x00002000, - CHANNEL_STEREO = 0x00004000, CHANNEL_16BITS = 0x00008000, -}; - -enum channel_attribute { - /* playback/record select */ - CHANNEL_PB = 0x0000, CHANNEL_SPC_PB = 0x4000, - CHANNEL_REC = 0x8000, CHANNEL_REC_PB = 0xc000, - /* playback destination/record source select */ - MODEM_LINE1 = 0x0000, MODEM_LINE2 = 0x0400, - PCM_LR = 0x0800, HSET = 0x0c00, - I2S_LR = 0x1000, CENTER_LFE = 0x1400, - SURR_LR = 0x1800, SPDIF_LR = 0x1c00, - MIC = 0x1400, - /* mist stuff */ - MONO_LEFT = 0x0000, MONO_RIGHT = 0x0100, - MONO_MIX = 0x0200, SRC_ENABLE = 0x0080, -}; - -enum miscint_bits { - PB_UNDERRUN_IRO = 0x00000001, REC_OVERRUN_IRQ = 0x00000002, - SB_IRQ = 0x00000004, MPU401_IRQ = 0x00000008, - OPL3_IRQ = 0x00000010, ADDRESS_IRQ = 0x00000020, - ENVELOPE_IRQ = 0x00000040, ST_IRQ = 0x00000080, - PB_UNDERRUN = 0x00000100, REC_OVERRUN = 0x00000200, - MIXER_UNDERFLOW = 0x00000400, MIXER_OVERFLOW = 0x00000800, - ST_TARGET_REACHED = 0x00008000, PB_24K_MODE = 0x00010000, - ST_IRQ_EN = 0x00800000, ACGPIO_IRQ = 0x01000000 -}; - -#define TRID_REG( trident, x ) ( (trident) -> iobase + (x) ) - -#define CYBER_PORT_AUDIO 0x3CE -#define CYBER_IDX_AUDIO_ENABLE 0x7B -#define CYBER_BMSK_AUDIO_INT_ENABLE 0x09 -#define CYBER_BMSK_AUENZ 0x01 -#define CYBER_BMSK_AUENZ_ENABLE 0x00 -#define CYBER_IDX_IRQ_ENABLE 0x12 - -#define VALIDATE_MAGIC(FOO,MAG) \ -({ \ - if (!(FOO) || (FOO)->magic != MAG) { \ - printk(invalid_magic,__func__); \ - return -ENXIO; \ - } \ -}) - -#define VALIDATE_STATE(a) VALIDATE_MAGIC(a,TRIDENT_STATE_MAGIC) -#define VALIDATE_CARD(a) VALIDATE_MAGIC(a,TRIDENT_CARD_MAGIC) - -static inline unsigned ld2(unsigned int x) -{ - unsigned r = 0; - - if (x >= 0x10000) { - x >>= 16; - r += 16; - } - if (x >= 0x100) { - x >>= 8; - r += 8; - } - if (x >= 0x10) { - x >>= 4; - r += 4; - } - if (x >= 4) { - x >>= 2; - r += 2; - } - if (x >= 2) - r++; - return r; -} - -#endif /* __TRID4DWAVE_H */ diff --git a/sound/oss/vidc.c b/sound/oss/vidc.c index bb4a0969f461..725fef0f59a3 100644 --- a/sound/oss/vidc.c +++ b/sound/oss/vidc.c @@ -22,7 +22,7 @@ #include <linux/kernel.h> #include <linux/interrupt.h> -#include <asm/hardware.h> +#include <mach/hardware.h> #include <asm/dma.h> #include <asm/io.h> #include <asm/hardware/iomd.h> diff --git a/sound/oss/vidc_fill.S b/sound/oss/vidc_fill.S index 01ccc074cc11..bed34921d176 100644 --- a/sound/oss/vidc_fill.S +++ b/sound/oss/vidc_fill.S @@ -11,7 +11,7 @@ */ #include <linux/linkage.h> #include <asm/assembler.h> -#include <asm/hardware.h> +#include <mach/hardware.h> #include <asm/hardware/iomd.h> .text diff --git a/sound/oss/waveartist.c b/sound/oss/waveartist.c index 88490418f932..c47842fad657 100644 --- a/sound/oss/waveartist.c +++ b/sound/oss/waveartist.c @@ -47,7 +47,7 @@ #include "waveartist.h" #ifdef CONFIG_ARM -#include <asm/hardware.h> +#include <mach/hardware.h> #include <asm/mach-types.h> #endif diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig index f7d95b224a98..31f52d3fc21f 100644 --- a/sound/pci/Kconfig +++ b/sound/pci/Kconfig @@ -845,7 +845,7 @@ config SND_VIRTUOSO select SND_OXYGEN_LIB help Say Y here to include support for sound cards based on the - Asus AV100/AV200 chips, i.e., Xonar D2, DX and D2X. + Asus AV100/AV200 chips, i.e., Xonar D1, DX, D2 and D2X. To compile this driver as a module, choose M here: the module will be called snd-virtuoso. diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c index 07364c00768a..8c49a00a5e39 100644 --- a/sound/pci/ac97/ac97_codec.c +++ b/sound/pci/ac97/ac97_codec.c @@ -161,6 +161,7 @@ static const struct ac97_codec_id snd_ac97_codec_ids[] = { { 0x50534304, 0xffffffff, "UCB1400", patch_ucb1400, NULL }, { 0x53494c20, 0xffffffe0, "Si3036,8", mpatch_si3036, mpatch_si3036, AC97_MODEM_PATCH }, { 0x54524102, 0xffffffff, "TR28022", NULL, NULL }, +{ 0x54524103, 0xffffffff, "TR28023", NULL, NULL }, { 0x54524106, 0xffffffff, "TR28026", NULL, NULL }, { 0x54524108, 0xffffffff, "TR28028", patch_tritech_tr28028, NULL }, // added by xin jin [07/09/99] { 0x54524123, 0xffffffff, "TR28602", NULL, NULL }, // only guess --jk [TR28023 = eMicro EM28023 (new CT1297)] @@ -169,7 +170,7 @@ static const struct ac97_codec_id snd_ac97_codec_ids[] = { { 0x56494170, 0xffffffff, "VIA1617A", patch_vt1617a, NULL }, // modified VT1616 with S/PDIF { 0x56494182, 0xffffffff, "VIA1618", NULL, NULL }, { 0x57454301, 0xffffffff, "W83971D", NULL, NULL }, -{ 0x574d4c00, 0xffffffff, "WM9701A", NULL, NULL }, +{ 0x574d4c00, 0xffffffff, "WM9701,WM9701A", NULL, NULL }, { 0x574d4C03, 0xffffffff, "WM9703,WM9707,WM9708,WM9717", patch_wolfson03, NULL}, { 0x574d4C04, 0xffffffff, "WM9704M,WM9704Q", patch_wolfson04, NULL}, { 0x574d4C05, 0xffffffff, "WM9705,WM9710", patch_wolfson05, NULL}, diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c index 0746e9ccc20b..f4fbc795ee81 100644 --- a/sound/pci/ac97/ac97_patch.c +++ b/sound/pci/ac97/ac97_patch.c @@ -3381,8 +3381,8 @@ static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97, } /* create a virtual master control and add slaves */ -int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name, - const unsigned int *tlv, const char **slaves) +static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name, + const unsigned int *tlv, const char **slaves) { struct snd_kcontrol *kctl; const char **s; diff --git a/sound/pci/azt3328.h b/sound/pci/azt3328.h index 7e3e8942d073..974e05122f00 100644 --- a/sound/pci/azt3328.h +++ b/sound/pci/azt3328.h @@ -94,7 +94,7 @@ enum azf_freq_t { AZF_FREQ(48000), AZF_FREQ(66200), #undef AZF_FREQ -} AZF_FREQUENCIES; +}; /** recording area (see also: playback bit flag definitions) **/ #define IDX_IO_REC_FLAGS 0x20 /* ??, PU:0x0000 */ @@ -210,7 +210,7 @@ enum azf_freq_t { enum { AZF_GAME_LEGACY_IO_PORT = 0x200 -} AZF_GAME_CONFIGS; +}; #define IDX_GAME_LEGACY_COMPATIBLE 0x00 /* in some operation mode, writing anything to this port diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c index fbf1124f7c79..9bf95367c882 100644 --- a/sound/pci/ens1370.c +++ b/sound/pci/ens1370.c @@ -522,7 +522,7 @@ static unsigned int snd_es1371_wait_src_ready(struct ensoniq * ensoniq) return r; cond_resched(); } - snd_printk(KERN_ERR "wait source ready timeout 0x%lx [0x%x]\n", + snd_printk(KERN_ERR "wait src ready timeout 0x%lx [0x%x]\n", ES_REG(ensoniq, 1371_SMPRATE), r); return 0; } @@ -1629,6 +1629,7 @@ static int __devinit snd_ensoniq_1371_mixer(struct ensoniq *ensoniq, memset(&ac97, 0, sizeof(ac97)); ac97.private_data = ensoniq; ac97.private_free = snd_ensoniq_mixer_free_ac97; + ac97.pci = ensoniq->pci; ac97.scaps = AC97_SCAP_AUDIO; if ((err = snd_ac97_mixer(pbus, &ac97, &ensoniq->u.es1371.ac97)) < 0) return err; diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 16715a68ba5e..a73d6ca0a906 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -101,6 +101,7 @@ MODULE_SUPPORTED_DEVICE("{{Intel, ICH6}," "{Intel, ICH8}," "{Intel, ICH9}," "{Intel, ICH10}," + "{Intel, PCH}," "{Intel, SCH}," "{ATI, SB450}," "{ATI, SB600}," @@ -1047,9 +1048,13 @@ static int azx_setup_periods(struct azx *chip, pos_adj = bdl_pos_adj[chip->dev_index]; if (pos_adj > 0) { struct snd_pcm_runtime *runtime = substream->runtime; + int pos_align = pos_adj; pos_adj = (pos_adj * runtime->rate + 47999) / 48000; if (!pos_adj) - pos_adj = 1; + pos_adj = pos_align; + else + pos_adj = ((pos_adj + pos_align - 1) / pos_align) * + pos_align; pos_adj = frames_to_bytes(runtime, pos_adj); if (pos_adj >= period_bytes) { snd_printk(KERN_WARNING "Too big adjustment %d\n", @@ -2259,6 +2264,8 @@ static struct pci_device_id azx_ids[] = { { PCI_DEVICE(0x8086, 0x293f), .driver_data = AZX_DRIVER_ICH }, { PCI_DEVICE(0x8086, 0x3a3e), .driver_data = AZX_DRIVER_ICH }, { PCI_DEVICE(0x8086, 0x3a6e), .driver_data = AZX_DRIVER_ICH }, + /* PCH */ + { PCI_DEVICE(0x8086, 0x3b56), .driver_data = AZX_DRIVER_ICH }, /* SCH */ { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH }, /* ATI SB 450/600 */ @@ -2268,6 +2275,7 @@ static struct pci_device_id azx_ids[] = { { PCI_DEVICE(0x1002, 0x793b), .driver_data = AZX_DRIVER_ATIHDMI }, { PCI_DEVICE(0x1002, 0x7919), .driver_data = AZX_DRIVER_ATIHDMI }, { PCI_DEVICE(0x1002, 0x960f), .driver_data = AZX_DRIVER_ATIHDMI }, + { PCI_DEVICE(0x1002, 0x970f), .driver_data = AZX_DRIVER_ATIHDMI }, { PCI_DEVICE(0x1002, 0xaa00), .driver_data = AZX_DRIVER_ATIHDMI }, { PCI_DEVICE(0x1002, 0xaa08), .driver_data = AZX_DRIVER_ATIHDMI }, { PCI_DEVICE(0x1002, 0xaa10), .driver_data = AZX_DRIVER_ATIHDMI }, diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 2807bc840d26..b80e725432f0 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -122,6 +122,8 @@ enum { /* ALC269 models */ enum { ALC269_BASIC, + ALC269_ASUS_EEEPC_P703, + ALC269_ASUS_EEEPC_P901, ALC269_AUTO, ALC269_MODEL_LAST /* last tag */ }; @@ -6435,6 +6437,39 @@ static void alc882_auto_init_analog_input(struct hda_codec *codec) } } +static void alc882_auto_init_input_src(struct hda_codec *codec) +{ + struct alc_spec *spec = codec->spec; + const struct hda_input_mux *imux = spec->input_mux; + int c; + + for (c = 0; c < spec->num_adc_nids; c++) { + hda_nid_t conn_list[HDA_MAX_NUM_INPUTS]; + hda_nid_t nid = spec->capsrc_nids[c]; + int conns, mute, idx, item; + + conns = snd_hda_get_connections(codec, nid, conn_list, + ARRAY_SIZE(conn_list)); + if (conns < 0) + continue; + for (idx = 0; idx < conns; idx++) { + /* if the current connection is the selected one, + * unmute it as default - otherwise mute it + */ + mute = AMP_IN_MUTE(idx); + for (item = 0; item < imux->num_items; item++) { + if (imux->items[item].index == idx) { + if (spec->cur_mux[c] == item) + mute = AMP_IN_UNMUTE(idx); + break; + } + } + snd_hda_codec_write(codec, nid, 0, + AC_VERB_SET_AMP_GAIN_MUTE, mute); + } + } +} + /* add mic boosts if needed */ static int alc_auto_add_mic_boost(struct hda_codec *codec) { @@ -6489,6 +6524,7 @@ static void alc882_auto_init(struct hda_codec *codec) alc882_auto_init_multi_out(codec); alc882_auto_init_hp_out(codec); alc882_auto_init_analog_input(codec); + alc882_auto_init_input_src(codec); if (spec->unsol_event) alc_sku_automute(codec); } @@ -7905,6 +7941,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = { SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE), SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE), SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE), + SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE), SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */ SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL), SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG), @@ -8282,6 +8319,8 @@ static void alc883_auto_init_analog_input(struct hda_codec *codec) } } +#define alc883_auto_init_input_src alc882_auto_init_input_src + /* almost identical with ALC880 parser... */ static int alc883_parse_auto_config(struct hda_codec *codec) { @@ -8312,6 +8351,7 @@ static void alc883_auto_init(struct hda_codec *codec) alc883_auto_init_multi_out(codec); alc883_auto_init_hp_out(codec); alc883_auto_init_analog_input(codec); + alc883_auto_init_input_src(codec); if (spec->unsol_event) alc_sku_automute(codec); } @@ -9660,6 +9700,7 @@ static int alc262_parse_auto_config(struct hda_codec *codec) #define alc262_auto_init_multi_out alc882_auto_init_multi_out #define alc262_auto_init_hp_out alc882_auto_init_hp_out #define alc262_auto_init_analog_input alc882_auto_init_analog_input +#define alc262_auto_init_input_src alc882_auto_init_input_src /* init callback for auto-configuration model -- overriding the default init */ @@ -9669,6 +9710,7 @@ static void alc262_auto_init(struct hda_codec *codec) alc262_auto_init_multi_out(codec); alc262_auto_init_hp_out(codec); alc262_auto_init_analog_input(codec); + alc262_auto_init_input_src(codec); if (spec->unsol_event) alc_sku_automute(codec); } @@ -10946,7 +10988,23 @@ static int patch_alc268(struct hda_codec *codec) static hda_nid_t alc269_adc_nids[1] = { /* ADC1 */ - 0x07, + 0x08, +}; + +static struct hda_input_mux alc269_eeepc_dmic_capture_source = { + .num_items = 2, + .items = { + { "i-Mic", 0x5 }, + { "e-Mic", 0x0 }, + }, +}; + +static struct hda_input_mux alc269_eeepc_amic_capture_source = { + .num_items = 2, + .items = { + { "i-Mic", 0x1 }, + { "e-Mic", 0x0 }, + }, }; #define alc269_modes alc260_modes @@ -10968,10 +11026,27 @@ static struct snd_kcontrol_new alc269_base_mixer[] = { { } /* end */ }; +/* bind volumes of both NID 0x0c and 0x0d */ +static struct hda_bind_ctls alc269_epc_bind_vol = { + .ops = &snd_hda_bind_vol, + .values = { + HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT), + HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT), + 0 + }, +}; + +static struct snd_kcontrol_new alc269_eeepc_mixer[] = { + HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT), + HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol), + HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT), + { } /* end */ +}; + /* capture mixer elements */ static struct snd_kcontrol_new alc269_capture_mixer[] = { - HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT), - HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT), + HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), + HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, /* The multiple "Capture Source" controls confuse alsamixer @@ -10987,6 +11062,13 @@ static struct snd_kcontrol_new alc269_capture_mixer[] = { { } /* end */ }; +/* capture mixer elements */ +static struct snd_kcontrol_new alc269_epc_capture_mixer[] = { + HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), + HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), + { } /* end */ +}; + /* * generic initialization of ADC, input mixers and output mixers */ @@ -10994,7 +11076,7 @@ static struct hda_verb alc269_init_verbs[] = { /* * Unmute ADC0 and set the default input to mic-in */ - {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, + {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the * analog-loopback mixer widget @@ -11057,6 +11139,98 @@ static struct hda_verb alc269_init_verbs[] = { { } }; +static struct hda_verb alc269_eeepc_dmic_init_verbs[] = { + {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, + {0x23, AC_VERB_SET_CONNECT_SEL, 0x05}, + {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 }, + {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))}, + {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, + {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, + {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT}, + {} +}; + +static struct hda_verb alc269_eeepc_amic_init_verbs[] = { + {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, + {0x23, AC_VERB_SET_CONNECT_SEL, 0x01}, + {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 }, + {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))}, + {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, + {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT}, + {} +}; + +/* toggle speaker-output according to the hp-jack state */ +static void alc269_speaker_automute(struct hda_codec *codec) +{ + unsigned int present; + unsigned int bits; + + present = snd_hda_codec_read(codec, 0x15, 0, + AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; + bits = present ? AMP_IN_MUTE(0) : 0; + snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, + AMP_IN_MUTE(0), bits); + snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1, + AMP_IN_MUTE(0), bits); +} + +static void alc269_eeepc_dmic_automute(struct hda_codec *codec) +{ + unsigned int present; + + present = snd_hda_codec_read(codec, 0x18, 0, AC_VERB_GET_PIN_SENSE, 0) + & AC_PINSENSE_PRESENCE; + snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL, + present ? 0 : 5); +} + +static void alc269_eeepc_amic_automute(struct hda_codec *codec) +{ + unsigned int present; + + present = snd_hda_codec_read(codec, 0x18, 0, AC_VERB_GET_PIN_SENSE, 0) + & AC_PINSENSE_PRESENCE; + snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE, + present ? AMP_IN_UNMUTE(0) : AMP_IN_MUTE(0)); + snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE, + present ? AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1)); +} + +/* unsolicited event for HP jack sensing */ +static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec, + unsigned int res) +{ + if ((res >> 26) == ALC880_HP_EVENT) + alc269_speaker_automute(codec); + + if ((res >> 26) == ALC880_MIC_EVENT) + alc269_eeepc_dmic_automute(codec); +} + +static void alc269_eeepc_dmic_inithook(struct hda_codec *codec) +{ + alc269_speaker_automute(codec); + alc269_eeepc_dmic_automute(codec); +} + +/* unsolicited event for HP jack sensing */ +static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec, + unsigned int res) +{ + if ((res >> 26) == ALC880_HP_EVENT) + alc269_speaker_automute(codec); + + if ((res >> 26) == ALC880_MIC_EVENT) + alc269_eeepc_amic_automute(codec); +} + +static void alc269_eeepc_amic_inithook(struct hda_codec *codec) +{ + alc269_speaker_automute(codec); + alc269_eeepc_amic_automute(codec); +} + /* add playback controls from the parsed DAC table */ static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg) @@ -11188,6 +11362,9 @@ static int alc269_parse_auto_config(struct hda_codec *codec) if (err < 0) return err; + spec->mixers[spec->num_mixers] = alc269_capture_mixer; + spec->num_mixers++; + return 1; } @@ -11215,12 +11392,16 @@ static const char *alc269_models[ALC269_MODEL_LAST] = { }; static struct snd_pci_quirk alc269_cfg_tbl[] = { + SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A", + ALC269_ASUS_EEEPC_P703), + SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901", + ALC269_ASUS_EEEPC_P901), {} }; static struct alc_config_preset alc269_presets[] = { [ALC269_BASIC] = { - .mixers = { alc269_base_mixer }, + .mixers = { alc269_base_mixer, alc269_capture_mixer }, .init_verbs = { alc269_init_verbs }, .num_dacs = ARRAY_SIZE(alc269_dac_nids), .dac_nids = alc269_dac_nids, @@ -11229,6 +11410,32 @@ static struct alc_config_preset alc269_presets[] = { .channel_mode = alc269_modes, .input_mux = &alc269_capture_source, }, + [ALC269_ASUS_EEEPC_P703] = { + .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer }, + .init_verbs = { alc269_init_verbs, + alc269_eeepc_amic_init_verbs }, + .num_dacs = ARRAY_SIZE(alc269_dac_nids), + .dac_nids = alc269_dac_nids, + .hp_nid = 0x03, + .num_channel_mode = ARRAY_SIZE(alc269_modes), + .channel_mode = alc269_modes, + .input_mux = &alc269_eeepc_amic_capture_source, + .unsol_event = alc269_eeepc_amic_unsol_event, + .init_hook = alc269_eeepc_amic_inithook, + }, + [ALC269_ASUS_EEEPC_P901] = { + .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer}, + .init_verbs = { alc269_init_verbs, + alc269_eeepc_dmic_init_verbs }, + .num_dacs = ARRAY_SIZE(alc269_dac_nids), + .dac_nids = alc269_dac_nids, + .hp_nid = 0x03, + .num_channel_mode = ARRAY_SIZE(alc269_modes), + .channel_mode = alc269_modes, + .input_mux = &alc269_eeepc_dmic_capture_source, + .unsol_event = alc269_eeepc_dmic_unsol_event, + .init_hook = alc269_eeepc_dmic_inithook, + }, }; static int patch_alc269(struct hda_codec *codec) @@ -11282,8 +11489,6 @@ static int patch_alc269(struct hda_codec *codec) spec->adc_nids = alc269_adc_nids; spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids); - spec->mixers[spec->num_mixers] = alc269_capture_mixer; - spec->num_mixers++; codec->patch_ops = alc_patch_ops; if (board_config == ALC269_AUTO) @@ -12994,6 +13199,7 @@ static struct snd_pci_quirk alc861vd_cfg_tbl[] = { SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP), SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST), SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST), + SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC861VD_LENOVO), SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG), SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST), SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO), @@ -13163,6 +13369,8 @@ static void alc861vd_auto_init_analog_input(struct hda_codec *codec) } } +#define alc861vd_auto_init_input_src alc882_auto_init_input_src + #define alc861vd_idx_to_mixer_vol(nid) ((nid) + 0x02) #define alc861vd_idx_to_mixer_switch(nid) ((nid) + 0x0c) @@ -13345,6 +13553,7 @@ static void alc861vd_auto_init(struct hda_codec *codec) alc861vd_auto_init_multi_out(codec); alc861vd_auto_init_hp_out(codec); alc861vd_auto_init_analog_input(codec); + alc861vd_auto_init_input_src(codec); if (spec->unsol_event) alc_sku_automute(codec); } @@ -14510,6 +14719,8 @@ static void alc662_auto_init_analog_input(struct hda_codec *codec) } } +#define alc662_auto_init_input_src alc882_auto_init_input_src + static int alc662_parse_auto_config(struct hda_codec *codec) { struct alc_spec *spec = codec->spec; @@ -14566,6 +14777,7 @@ static void alc662_auto_init(struct hda_codec *codec) alc662_auto_init_multi_out(codec); alc662_auto_init_hp_out(codec); alc662_auto_init_analog_input(codec); + alc662_auto_init_input_src(codec); if (spec->unsol_event) alc_sku_automute(codec); } diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index 08cb77f51880..7fdafcb0015d 100644 --- a/sound/pci/hda/patch_sigmatel.c +++ b/sound/pci/hda/patch_sigmatel.c @@ -94,6 +94,9 @@ enum { STAC_INTEL_MAC_V3, STAC_INTEL_MAC_V4, STAC_INTEL_MAC_V5, + STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter + * is given, one of the above models will be + * chosen according to the subsystem id. */ /* for backward compatibility */ STAC_MACMINI, STAC_MACBOOK, @@ -1483,6 +1486,7 @@ static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = { [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs, [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs, [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs, + [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs, /* for backward compatibility */ [STAC_MACMINI] = intel_mac_v3_pin_configs, [STAC_MACBOOK] = intel_mac_v5_pin_configs, @@ -1505,6 +1509,7 @@ static const char *stac922x_models[STAC_922X_MODELS] = { [STAC_INTEL_MAC_V3] = "intel-mac-v3", [STAC_INTEL_MAC_V4] = "intel-mac-v4", [STAC_INTEL_MAC_V5] = "intel-mac-v5", + [STAC_INTEL_MAC_AUTO] = "intel-mac-auto", /* for backward compatibility */ [STAC_MACMINI] = "macmini", [STAC_MACBOOK] = "macbook", @@ -1576,9 +1581,9 @@ static struct snd_pci_quirk stac922x_cfg_tbl[] = { SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707, "Intel D945P", STAC_D945GTP5), /* other systems */ - /* Apple Mac Mini (early 2006) */ + /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */ SND_PCI_QUIRK(0x8384, 0x7680, - "Mac Mini", STAC_INTEL_MAC_V3), + "Mac", STAC_INTEL_MAC_AUTO), /* Dell systems */ SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7, "unknown Dell", STAC_922X_DELL_D81), @@ -3725,7 +3730,7 @@ static int patch_stac922x(struct hda_codec *codec) spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS, stac922x_models, stac922x_cfg_tbl); - if (spec->board_config == STAC_INTEL_MAC_V3) { + if (spec->board_config == STAC_INTEL_MAC_AUTO) { spec->gpio_mask = spec->gpio_dir = 0x03; spec->gpio_data = 0x03; /* Intel Macs have all same PCI SSID, so we need to check @@ -3757,6 +3762,9 @@ static int patch_stac922x(struct hda_codec *codec) case 0x106b2200: spec->board_config = STAC_INTEL_MAC_V5; break; + default: + spec->board_config = STAC_INTEL_MAC_V3; + break; } } diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c index 9a2c16bf94e0..01d7b75f9182 100644 --- a/sound/pci/oxygen/virtuoso.c +++ b/sound/pci/oxygen/virtuoso.c @@ -36,15 +36,15 @@ */ /* - * Xonar DX - * -------- + * Xonar D1/DX + * ----------- * * CMI8788: * * I²C <-> CS4398 (front) * <-> CS4362A (surround, center/LFE, back) * - * GPI 0 <- external power present + * GPI 0 <- external power present (DX only) * * GPIO 0 -> enable output to speakers * GPIO 1 -> enable front panel I/O @@ -96,6 +96,7 @@ MODULE_PARM_DESC(enable, "enable card"); enum { MODEL_D2, MODEL_D2X, + MODEL_D1, MODEL_DX, }; @@ -103,6 +104,7 @@ static struct pci_device_id xonar_ids[] __devinitdata = { { OXYGEN_PCI_SUBID(0x1043, 0x8269), .driver_data = MODEL_D2 }, { OXYGEN_PCI_SUBID(0x1043, 0x8275), .driver_data = MODEL_DX }, { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X }, + { OXYGEN_PCI_SUBID(0x1043, 0x834f), .driver_data = MODEL_D1 }, { } }; MODULE_DEVICE_TABLE(pci, xonar_ids); @@ -313,15 +315,12 @@ static void cs43xx_init(struct oxygen *chip) cs4362a_write(chip, 0x01, CS4362A_CPEN); } -static void xonar_dx_init(struct oxygen *chip) +static void xonar_d1_init(struct oxygen *chip) { struct xonar_data *data = chip->model_data; data->anti_pop_delay = 800; data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE; - data->ext_power_reg = OXYGEN_GPI_DATA; - data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; - data->ext_power_bit = GPI_DX_EXT_POWER; data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST; data->cs4362a_fm = CS4362A_FM_SINGLE | CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L; @@ -345,6 +344,16 @@ static void xonar_dx_init(struct oxygen *chip) snd_component_add(chip->card, "CS5361"); } +static void xonar_dx_init(struct oxygen *chip) +{ + struct xonar_data *data = chip->model_data; + + data->ext_power_reg = OXYGEN_GPI_DATA; + data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; + data->ext_power_bit = GPI_DX_EXT_POWER; + xonar_d1_init(chip); +} + static void xonar_cleanup(struct oxygen *chip) { struct xonar_data *data = chip->model_data; @@ -352,7 +361,7 @@ static void xonar_cleanup(struct oxygen *chip) oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit); } -static void xonar_dx_cleanup(struct oxygen *chip) +static void xonar_d1_cleanup(struct oxygen *chip) { xonar_cleanup(chip); cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN); @@ -365,7 +374,7 @@ static void xonar_d2_resume(struct oxygen *chip) xonar_enable_output(chip); } -static void xonar_dx_resume(struct oxygen *chip) +static void xonar_d1_resume(struct oxygen *chip) { cs43xx_init(chip); xonar_enable_output(chip); @@ -513,7 +522,7 @@ static const struct snd_kcontrol_new front_panel_switch = { .put = front_panel_put, }; -static void xonar_dx_ac97_switch(struct oxygen *chip, +static void xonar_d1_ac97_switch(struct oxygen *chip, unsigned int reg, unsigned int mute) { if (reg == AC97_LINE) { @@ -536,7 +545,7 @@ static int xonar_d2_control_filter(struct snd_kcontrol_new *template) return 0; } -static int xonar_dx_control_filter(struct snd_kcontrol_new *template) +static int xonar_d1_control_filter(struct snd_kcontrol_new *template) { if (!strncmp(template->name, "CD Capture ", 11)) return 1; /* no CD input */ @@ -548,7 +557,7 @@ static int xonar_mixer_init(struct oxygen *chip) return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip)); } -static int xonar_dx_mixer_init(struct oxygen *chip) +static int xonar_d1_mixer_init(struct oxygen *chip) { return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip)); } @@ -615,23 +624,51 @@ static const struct oxygen_model xonar_models[] = { .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, }, + [MODEL_D1] = { + .shortname = "Xonar D1", + .longname = "Asus Virtuoso 100", + .chip = "AV200", + .owner = THIS_MODULE, + .init = xonar_d1_init, + .control_filter = xonar_d1_control_filter, + .mixer_init = xonar_d1_mixer_init, + .cleanup = xonar_d1_cleanup, + .suspend = xonar_d1_cleanup, + .resume = xonar_d1_resume, + .set_dac_params = set_cs43xx_params, + .set_adc_params = set_cs53x1_params, + .update_dac_volume = update_cs43xx_volume, + .update_dac_mute = update_cs43xx_mute, + .ac97_switch = xonar_d1_ac97_switch, + .dac_tlv = cs4362a_db_scale, + .model_data_size = sizeof(struct xonar_data), + .pcm_dev_cfg = PLAYBACK_0_TO_I2S | + PLAYBACK_1_TO_SPDIF | + CAPTURE_0_FROM_I2S_2, + .dac_channels = 8, + .dac_volume_min = 0, + .dac_volume_max = 127, + .function_flags = OXYGEN_FUNCTION_2WIRE, + .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, + .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, + }, [MODEL_DX] = { .shortname = "Xonar DX", .longname = "Asus Virtuoso 100", .chip = "AV200", .owner = THIS_MODULE, .init = xonar_dx_init, - .control_filter = xonar_dx_control_filter, - .mixer_init = xonar_dx_mixer_init, - .cleanup = xonar_dx_cleanup, - .suspend = xonar_dx_cleanup, - .resume = xonar_dx_resume, + .control_filter = xonar_d1_control_filter, + .mixer_init = xonar_d1_mixer_init, + .cleanup = xonar_d1_cleanup, + .suspend = xonar_d1_cleanup, + .resume = xonar_d1_resume, .set_dac_params = set_cs43xx_params, .set_adc_params = set_cs53x1_params, .update_dac_volume = update_cs43xx_volume, .update_dac_mute = update_cs43xx_mute, .gpio_changed = xonar_gpio_changed, - .ac97_switch = xonar_dx_ac97_switch, + .ac97_switch = xonar_d1_ac97_switch, .dac_tlv = cs4362a_db_scale, .model_data_size = sizeof(struct xonar_data), .pcm_dev_cfg = PLAYBACK_0_TO_I2S | diff --git a/sound/sh/aica.c b/sound/sh/aica.c index 9ca113326143..54df8baf916f 100644 --- a/sound/sh/aica.c +++ b/sound/sh/aica.c @@ -42,7 +42,7 @@ #include <sound/info.h> #include <asm/io.h> #include <asm/dma.h> -#include <asm/dreamcast/sysasic.h> +#include <mach/sysasic.h> #include "aica.h" MODULE_AUTHOR("Adrian McMenamin <adrian@mcmen.demon.co.uk>"); diff --git a/sound/soc/at32/playpaq_wm8510.c b/sound/soc/at32/playpaq_wm8510.c index fee5f8e58957..3f326219f1ec 100644 --- a/sound/soc/at32/playpaq_wm8510.c +++ b/sound/soc/at32/playpaq_wm8510.c @@ -36,8 +36,8 @@ #include <sound/soc.h> #include <sound/soc-dapm.h> -#include <asm/arch/at32ap700x.h> -#include <asm/arch/portmux.h> +#include <mach/at32ap700x.h> +#include <mach/portmux.h> #include "../codecs/wm8510.h" #include "at32-pcm.h" diff --git a/sound/soc/at91/at91-pcm.c b/sound/soc/at91/at91-pcm.c index d47492b2b6e5..7ab48bd25e4c 100644 --- a/sound/soc/at91/at91-pcm.c +++ b/sound/soc/at91/at91-pcm.c @@ -28,8 +28,8 @@ #include <sound/pcm_params.h> #include <sound/soc.h> -#include <asm/arch/hardware.h> -#include <asm/arch/at91_ssc.h> +#include <mach/hardware.h> +#include <mach/at91_ssc.h> #include "at91-pcm.h" diff --git a/sound/soc/at91/at91-pcm.h b/sound/soc/at91/at91-pcm.h index 58d0f00a07b2..e5aada2cb102 100644 --- a/sound/soc/at91/at91-pcm.h +++ b/sound/soc/at91/at91-pcm.h @@ -19,7 +19,7 @@ #ifndef _AT91_PCM_H #define _AT91_PCM_H -#include <asm/arch/hardware.h> +#include <mach/hardware.h> struct at91_ssc_periph { void __iomem *base; diff --git a/sound/soc/at91/at91-ssc.c b/sound/soc/at91/at91-ssc.c index 090e607f8692..5d44515e62e0 100644 --- a/sound/soc/at91/at91-ssc.c +++ b/sound/soc/at91/at91-ssc.c @@ -28,9 +28,9 @@ #include <sound/initval.h> #include <sound/soc.h> -#include <asm/arch/hardware.h> -#include <asm/arch/at91_pmc.h> -#include <asm/arch/at91_ssc.h> +#include <mach/hardware.h> +#include <mach/at91_pmc.h> +#include <mach/at91_ssc.h> #include "at91-pcm.h" #include "at91-ssc.h" diff --git a/sound/soc/at91/eti_b1_wm8731.c b/sound/soc/at91/eti_b1_wm8731.c index d532de954241..b081e83766b7 100644 --- a/sound/soc/at91/eti_b1_wm8731.c +++ b/sound/soc/at91/eti_b1_wm8731.c @@ -33,8 +33,8 @@ #include <sound/soc.h> #include <sound/soc-dapm.h> -#include <asm/hardware.h> -#include <asm/arch/gpio.h> +#include <mach/hardware.h> +#include <mach/gpio.h> #include "../codecs/wm8731.h" #include "at91-pcm.h" diff --git a/sound/soc/au1x/psc-i2s.c b/sound/soc/au1x/psc-i2s.c index ba4b5c199f21..9384702c7ebd 100644 --- a/sound/soc/au1x/psc-i2s.c +++ b/sound/soc/au1x/psc-i2s.c @@ -231,7 +231,7 @@ static int au1xpsc_i2s_stop(struct au1xpsc_audio_data *pscdata, int stype) /* if both TX and RX are idle, disable PSC */ stat = au_readl(I2S_STAT(pscdata)); - if (!(stat & (PSC_I2SSTAT_RB | PSC_I2SSTAT_RB))) { + if (!(stat & (PSC_I2SSTAT_TB | PSC_I2SSTAT_RB))) { au_writel(0, I2S_CFG(pscdata)); au_sync(); au_writel(PSC_CTRL_SUSPEND, PSC_CTRL(pscdata)); diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c index e23cb09f0d14..c6a8edf302ad 100644 --- a/sound/soc/codecs/wm8750.c +++ b/sound/soc/codecs/wm8750.c @@ -348,8 +348,9 @@ static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = { SND_SOC_DAPM_OUTPUT("ROUT1"), SND_SOC_DAPM_OUTPUT("LOUT2"), SND_SOC_DAPM_OUTPUT("ROUT2"), - SND_SOC_DAPM_OUTPUT("MONO"), + SND_SOC_DAPM_OUTPUT("MONO1"), SND_SOC_DAPM_OUTPUT("OUT3"), + SND_SOC_DAPM_OUTPUT("VREF"), SND_SOC_DAPM_INPUT("LINPUT1"), SND_SOC_DAPM_INPUT("LINPUT2"), diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c index 3ecce5168e94..e44153fa38de 100644 --- a/sound/soc/codecs/wm8990.c +++ b/sound/soc/codecs/wm8990.c @@ -82,7 +82,7 @@ static const u16 wm8990_reg[] = { 0x0003, /* R35 - ClassD1 */ 0x0000, /* R36 */ 0x0100, /* R37 - ClassD3 */ - 0x0000, /* R38 */ + 0x0079, /* R38 - ClassD4 */ 0x0000, /* R39 - Input Mixer1 */ 0x0000, /* R40 - Input Mixer2 */ 0x0000, /* R41 - Input Mixer3 */ @@ -311,11 +311,15 @@ SOC_SINGLE("Speaker Mode Switch", WM8990_CLASSD1, WM8990_CDMODE_BIT, 1, 0), SOC_SINGLE("Speaker Output Attenuation Volume", WM8990_SPEAKER_VOLUME, - WM8990_SPKVOL_SHIFT, WM8990_SPKVOL_MASK, 0), + WM8990_SPKATTN_SHIFT, WM8990_SPKATTN_MASK, 0), SOC_SINGLE("Speaker DC Boost Volume", WM8990_CLASSD3, WM8990_DCGAIN_SHIFT, WM8990_DCGAIN_MASK, 0), SOC_SINGLE("Speaker AC Boost Volume", WM8990_CLASSD3, WM8990_ACGAIN_SHIFT, WM8990_ACGAIN_MASK, 0), +SOC_SINGLE_TLV("Speaker Volume", WM8990_CLASSD4, + WM8990_SPKVOL_SHIFT, WM8990_SPKVOL_MASK, 0, out_pga_tlv), +SOC_SINGLE("Speaker ZC Switch", WM8990_CLASSD4, + WM8990_SPKZC_SHIFT, WM8990_SPKZC_MASK, 0), SOC_WM899X_OUTPGA_SINGLE_R_TLV("Left DAC Digital Volume", WM8990_LEFT_DAC_DIGITAL_VOLUME, @@ -920,7 +924,7 @@ static const struct snd_soc_dapm_route audio_map[] = { {"SPKMIX", "SPKMIX Left Mixer PGA Switch", "LOPGA"}, {"SPKMIX", "SPKMIX Right Mixer PGA Switch", "ROPGA"}, {"SPKMIX", "SPKMIX Right DAC Switch", "Right DAC"}, - {"SPKMIX", "SPKMIX Left DAC Switch", "Right DAC"}, + {"SPKMIX", "SPKMIX Left DAC Switch", "Left DAC"}, /* LONMIX */ {"LONMIX", "LONMIX Left Mixer PGA Switch", "LOPGA"}, diff --git a/sound/soc/codecs/wm8990.h b/sound/soc/codecs/wm8990.h index 6bea57485283..0a08325d5443 100644 --- a/sound/soc/codecs/wm8990.h +++ b/sound/soc/codecs/wm8990.h @@ -54,6 +54,7 @@ #define WM8990_SPEAKER_VOLUME 0x22 #define WM8990_CLASSD1 0x23 #define WM8990_CLASSD3 0x25 +#define WM8990_CLASSD4 0x26 #define WM8990_INPUT_MIXER1 0x27 #define WM8990_INPUT_MIXER2 0x28 #define WM8990_INPUT_MIXER3 0x29 @@ -528,8 +529,8 @@ /* * R34 (0x22) - Speaker Volume */ -#define WM8990_SPKVOL_MASK 0x0003 /* SPKVOL - [1:0] */ -#define WM8990_SPKVOL_SHIFT 0 +#define WM8990_SPKATTN_MASK 0x0003 /* SPKATTN - [1:0] */ +#define WM8990_SPKATTN_SHIFT 0 /* * R35 (0x23) - ClassD1 @@ -544,6 +545,15 @@ #define WM8990_DCGAIN_SHIFT 3 #define WM8990_ACGAIN_MASK 0x0007 /* ACGAIN - [2:0] */ #define WM8990_ACGAIN_SHIFT 0 + +/* + * R38 (0x26) - ClassD4 + */ +#define WM8990_SPKZC_MASK 0x0001 /* SPKZC */ +#define WM8990_SPKZC_SHIFT 7 /* SPKZC */ +#define WM8990_SPKVOL_MASK 0x007F /* SPKVOL - [6:0] */ +#define WM8990_SPKVOL_SHIFT 0 /* SPKVOL - [6:0] */ + /* * R39 (0x27) - Input Mixer1 */ diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c index 9fc8edd82225..1fb7f9a7aecd 100644 --- a/sound/soc/codecs/wm9712.c +++ b/sound/soc/codecs/wm9712.c @@ -427,20 +427,20 @@ static const struct snd_soc_dapm_route audio_map[] = { {"HPOUTR", NULL, "Headphone PGA"}, {"Headphone PGA", NULL, "Right HP Mixer"}, - /* mono hp mixer */ - {"Mono HP Mixer", NULL, "Left HP Mixer"}, - {"Mono HP Mixer", NULL, "Right HP Mixer"}, + /* mono mixer */ + {"Mono Mixer", NULL, "Left HP Mixer"}, + {"Mono Mixer", NULL, "Right HP Mixer"}, /* Out3 Mux */ {"Out3 Mux", "Left", "Left HP Mixer"}, {"Out3 Mux", "Mono", "Phone Mixer"}, - {"Out3 Mux", "Left + Right", "Mono HP Mixer"}, + {"Out3 Mux", "Left + Right", "Mono Mixer"}, {"Out 3 PGA", NULL, "Out3 Mux"}, {"OUT3", NULL, "Out 3 PGA"}, /* speaker Mux */ {"Speaker Mux", "Speaker Mix", "Speaker Mixer"}, - {"Speaker Mux", "Headphone Mix", "Mono HP Mixer"}, + {"Speaker Mux", "Headphone Mix", "Mono Mixer"}, {"Speaker PGA", NULL, "Speaker Mux"}, {"LOUT2", NULL, "Speaker PGA"}, {"ROUT2", NULL, "Speaker PGA"}, diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c index 5e2c306399ed..65fdbd81a379 100644 --- a/sound/soc/davinci/davinci-evm.c +++ b/sound/soc/davinci/davinci-evm.c @@ -19,9 +19,8 @@ #include <sound/soc.h> #include <sound/soc-dapm.h> -#include <asm/mach-types.h> #include <asm/dma.h> -#include <asm/arch/hardware.h> +#include <mach/hardware.h> #include "../codecs/tlv320aic3x.h" #include "davinci-pcm.h" diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c index da2bc5902864..d2d3da9729f2 100644 --- a/sound/soc/fsl/fsl_dma.c +++ b/sound/soc/fsl/fsl_dma.c @@ -132,12 +132,17 @@ struct fsl_dma_private { * Since each link descriptor has a 32-bit byte count field, we set * period_bytes_max to the largest 32-bit number. We also have no maximum * number of periods. + * + * Note that we specify SNDRV_PCM_INFO_JOINT_DUPLEX here, but only because a + * limitation in the SSI driver requires the sample rates for playback and + * capture to be the same. */ static const struct snd_pcm_hardware fsl_dma_hardware = { .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP | - SNDRV_PCM_INFO_MMAP_VALID, + SNDRV_PCM_INFO_MMAP_VALID | + SNDRV_PCM_INFO_JOINT_DUPLEX, .formats = FSLDMA_PCM_FORMATS, .rates = FSLDMA_PCM_RATES, .rate_min = 5512, @@ -322,14 +327,75 @@ static int fsl_dma_new(struct snd_card *card, struct snd_soc_dai *dai, * fsl_dma_open: open a new substream. * * Each substream has its own DMA buffer. + * + * ALSA divides the DMA buffer into N periods. We create NUM_DMA_LINKS link + * descriptors that ping-pong from one period to the next. For example, if + * there are six periods and two link descriptors, this is how they look + * before playback starts: + * + * The last link descriptor + * ____________ points back to the first + * | | + * V | + * ___ ___ | + * | |->| |->| + * |___| |___| + * | | + * | | + * V V + * _________________________________________ + * | | | | | | | The DMA buffer is + * | | | | | | | divided into 6 parts + * |______|______|______|______|______|______| + * + * and here's how they look after the first period is finished playing: + * + * ____________ + * | | + * V | + * ___ ___ | + * | |->| |->| + * |___| |___| + * | | + * |______________ + * | | + * V V + * _________________________________________ + * | | | | | | | + * | | | | | | | + * |______|______|______|______|______|______| + * + * The first link descriptor now points to the third period. The DMA + * controller is currently playing the second period. When it finishes, it + * will jump back to the first descriptor and play the third period. + * + * There are four reasons we do this: + * + * 1. The only way to get the DMA controller to automatically restart the + * transfer when it gets to the end of the buffer is to use chaining + * mode. Basic direct mode doesn't offer that feature. + * 2. We need to receive an interrupt at the end of every period. The DMA + * controller can generate an interrupt at the end of every link transfer + * (aka segment). Making each period into a DMA segment will give us the + * interrupts we need. + * 3. By creating only two link descriptors, regardless of the number of + * periods, we do not need to reallocate the link descriptors if the + * number of periods changes. + * 4. All of the audio data is still stored in a single, contiguous DMA + * buffer, which is what ALSA expects. We're just dividing it into + * contiguous parts, and creating a link descriptor for each one. */ static int fsl_dma_open(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct fsl_dma_private *dma_private; + struct ccsr_dma_channel __iomem *dma_channel; dma_addr_t ld_buf_phys; + u64 temp_link; /* Pointer to next link descriptor */ + u32 mr; unsigned int channel; int ret = 0; + unsigned int i; /* * Reject any DMA buffer whose size is not a multiple of the period @@ -390,68 +456,74 @@ static int fsl_dma_open(struct snd_pcm_substream *substream) snd_soc_set_runtime_hwparams(substream, &fsl_dma_hardware); runtime->private_data = dma_private; + /* Program the fixed DMA controller parameters */ + + dma_channel = dma_private->dma_channel; + + temp_link = dma_private->ld_buf_phys + + sizeof(struct fsl_dma_link_descriptor); + + for (i = 0; i < NUM_DMA_LINKS; i++) { + struct fsl_dma_link_descriptor *link = &dma_private->link[i]; + + link->source_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP); + link->dest_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP); + link->next = cpu_to_be64(temp_link); + + temp_link += sizeof(struct fsl_dma_link_descriptor); + } + /* The last link descriptor points to the first */ + dma_private->link[i - 1].next = cpu_to_be64(dma_private->ld_buf_phys); + + /* Tell the DMA controller where the first link descriptor is */ + out_be32(&dma_channel->clndar, + CCSR_DMA_CLNDAR_ADDR(dma_private->ld_buf_phys)); + out_be32(&dma_channel->eclndar, + CCSR_DMA_ECLNDAR_ADDR(dma_private->ld_buf_phys)); + + /* The manual says the BCR must be clear before enabling EMP */ + out_be32(&dma_channel->bcr, 0); + + /* + * Program the mode register for interrupts, external master control, + * and source/destination hold. Also clear the Channel Abort bit. + */ + mr = in_be32(&dma_channel->mr) & + ~(CCSR_DMA_MR_CA | CCSR_DMA_MR_DAHE | CCSR_DMA_MR_SAHE); + + /* + * We want External Master Start and External Master Pause enabled, + * because the SSI is controlling the DMA controller. We want the DMA + * controller to be set up in advance, and then we signal only the SSI + * to start transferring. + * + * We want End-Of-Segment Interrupts enabled, because this will generate + * an interrupt at the end of each segment (each link descriptor + * represents one segment). Each DMA segment is the same thing as an + * ALSA period, so this is how we get an interrupt at the end of every + * period. + * + * We want Error Interrupt enabled, so that we can get an error if + * the DMA controller is mis-programmed somehow. + */ + mr |= CCSR_DMA_MR_EOSIE | CCSR_DMA_MR_EIE | CCSR_DMA_MR_EMP_EN | + CCSR_DMA_MR_EMS_EN; + + /* For playback, we want the destination address to be held. For + capture, set the source address to be held. */ + mr |= (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? + CCSR_DMA_MR_DAHE : CCSR_DMA_MR_SAHE; + + out_be32(&dma_channel->mr, mr); + return 0; } /** - * fsl_dma_hw_params: allocate the DMA buffer and the DMA link descriptors. + * fsl_dma_hw_params: continue initializing the DMA links * - * ALSA divides the DMA buffer into N periods. We create NUM_DMA_LINKS link - * descriptors that ping-pong from one period to the next. For example, if - * there are six periods and two link descriptors, this is how they look - * before playback starts: - * - * The last link descriptor - * ____________ points back to the first - * | | - * V | - * ___ ___ | - * | |->| |->| - * |___| |___| - * | | - * | | - * V V - * _________________________________________ - * | | | | | | | The DMA buffer is - * | | | | | | | divided into 6 parts - * |______|______|______|______|______|______| - * - * and here's how they look after the first period is finished playing: - * - * ____________ - * | | - * V | - * ___ ___ | - * | |->| |->| - * |___| |___| - * | | - * |______________ - * | | - * V V - * _________________________________________ - * | | | | | | | - * | | | | | | | - * |______|______|______|______|______|______| - * - * The first link descriptor now points to the third period. The DMA - * controller is currently playing the second period. When it finishes, it - * will jump back to the first descriptor and play the third period. - * - * There are four reasons we do this: - * - * 1. The only way to get the DMA controller to automatically restart the - * transfer when it gets to the end of the buffer is to use chaining - * mode. Basic direct mode doesn't offer that feature. - * 2. We need to receive an interrupt at the end of every period. The DMA - * controller can generate an interrupt at the end of every link transfer - * (aka segment). Making each period into a DMA segment will give us the - * interrupts we need. - * 3. By creating only two link descriptors, regardless of the number of - * periods, we do not need to reallocate the link descriptors if the - * number of periods changes. - * 4. All of the audio data is still stored in a single, contiguous DMA - * buffer, which is what ALSA expects. We're just dividing it into - * contiguous parts, and creating a link descriptor for each one. + * This function obtains hardware parameters about the opened stream and + * programs the DMA controller accordingly. * * Note that due to a quirk of the SSI's STX register, the target address * for the DMA operations depends on the sample size. So we don't program @@ -463,11 +535,8 @@ static int fsl_dma_hw_params(struct snd_pcm_substream *substream, { struct snd_pcm_runtime *runtime = substream->runtime; struct fsl_dma_private *dma_private = runtime->private_data; - struct ccsr_dma_channel __iomem *dma_channel = dma_private->dma_channel; dma_addr_t temp_addr; /* Pointer to next period */ - u64 temp_link; /* Pointer to next link descriptor */ - u32 mr; /* Temporary variable for MR register */ unsigned int i; @@ -485,8 +554,6 @@ static int fsl_dma_hw_params(struct snd_pcm_substream *substream, dma_private->dma_buf_next = dma_private->dma_buf_phys; /* - * Initialize each link descriptor. - * * The actual address in STX0 (destination for playback, source for * capture) is based on the sample size, but we don't know the sample * size in this function, so we'll have to adjust that later. See @@ -502,16 +569,11 @@ static int fsl_dma_hw_params(struct snd_pcm_substream *substream, * buffer itself. */ temp_addr = substream->dma_buffer.addr; - temp_link = dma_private->ld_buf_phys + - sizeof(struct fsl_dma_link_descriptor); for (i = 0; i < NUM_DMA_LINKS; i++) { struct fsl_dma_link_descriptor *link = &dma_private->link[i]; link->count = cpu_to_be32(period_size); - link->source_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP); - link->dest_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP); - link->next = cpu_to_be64(temp_link); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) link->source_addr = cpu_to_be32(temp_addr); @@ -519,51 +581,7 @@ static int fsl_dma_hw_params(struct snd_pcm_substream *substream, link->dest_addr = cpu_to_be32(temp_addr); temp_addr += period_size; - temp_link += sizeof(struct fsl_dma_link_descriptor); } - /* The last link descriptor points to the first */ - dma_private->link[i - 1].next = cpu_to_be64(dma_private->ld_buf_phys); - - /* Tell the DMA controller where the first link descriptor is */ - out_be32(&dma_channel->clndar, - CCSR_DMA_CLNDAR_ADDR(dma_private->ld_buf_phys)); - out_be32(&dma_channel->eclndar, - CCSR_DMA_ECLNDAR_ADDR(dma_private->ld_buf_phys)); - - /* The manual says the BCR must be clear before enabling EMP */ - out_be32(&dma_channel->bcr, 0); - - /* - * Program the mode register for interrupts, external master control, - * and source/destination hold. Also clear the Channel Abort bit. - */ - mr = in_be32(&dma_channel->mr) & - ~(CCSR_DMA_MR_CA | CCSR_DMA_MR_DAHE | CCSR_DMA_MR_SAHE); - - /* - * We want External Master Start and External Master Pause enabled, - * because the SSI is controlling the DMA controller. We want the DMA - * controller to be set up in advance, and then we signal only the SSI - * to start transfering. - * - * We want End-Of-Segment Interrupts enabled, because this will generate - * an interrupt at the end of each segment (each link descriptor - * represents one segment). Each DMA segment is the same thing as an - * ALSA period, so this is how we get an interrupt at the end of every - * period. - * - * We want Error Interrupt enabled, so that we can get an error if - * the DMA controller is mis-programmed somehow. - */ - mr |= CCSR_DMA_MR_EOSIE | CCSR_DMA_MR_EIE | CCSR_DMA_MR_EMP_EN | - CCSR_DMA_MR_EMS_EN; - - /* For playback, we want the destination address to be held. For - capture, set the source address to be held. */ - mr |= (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? - CCSR_DMA_MR_DAHE : CCSR_DMA_MR_SAHE; - - out_be32(&dma_channel->mr, mr); return 0; } diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c index 71bff33f5528..157a7895ffa1 100644 --- a/sound/soc/fsl/fsl_ssi.c +++ b/sound/soc/fsl/fsl_ssi.c @@ -67,6 +67,8 @@ * @ssi: pointer to the SSI's registers * @ssi_phys: physical address of the SSI registers * @irq: IRQ of this SSI + * @first_stream: pointer to the stream that was opened first + * @second_stream: pointer to second stream * @dev: struct device pointer * @playback: the number of playback streams opened * @capture: the number of capture streams opened @@ -79,6 +81,8 @@ struct fsl_ssi_private { struct ccsr_ssi __iomem *ssi; dma_addr_t ssi_phys; unsigned int irq; + struct snd_pcm_substream *first_stream; + struct snd_pcm_substream *second_stream; struct device *dev; unsigned int playback; unsigned int capture; @@ -342,6 +346,49 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream) */ } + if (!ssi_private->first_stream) + ssi_private->first_stream = substream; + else { + /* This is the second stream open, so we need to impose sample + * rate and maybe sample size constraints. Note that this can + * cause a race condition if the second stream is opened before + * the first stream is fully initialized. + * + * We provide some protection by checking to make sure the first + * stream is initialized, but it's not perfect. ALSA sometimes + * re-initializes the driver with a different sample rate or + * size. If the second stream is opened before the first stream + * has received its final parameters, then the second stream may + * be constrained to the wrong sample rate or size. + * + * FIXME: This code does not handle opening and closing streams + * repeatedly. If you open two streams and then close the first + * one, you may not be able to open another stream until you + * close the second one as well. + */ + struct snd_pcm_runtime *first_runtime = + ssi_private->first_stream->runtime; + + if (!first_runtime->rate || !first_runtime->sample_bits) { + dev_err(substream->pcm->card->dev, + "set sample rate and size in %s stream first\n", + substream->stream == SNDRV_PCM_STREAM_PLAYBACK + ? "capture" : "playback"); + return -EAGAIN; + } + + snd_pcm_hw_constraint_minmax(substream->runtime, + SNDRV_PCM_HW_PARAM_RATE, + first_runtime->rate, first_runtime->rate); + + snd_pcm_hw_constraint_minmax(substream->runtime, + SNDRV_PCM_HW_PARAM_SAMPLE_BITS, + first_runtime->sample_bits, + first_runtime->sample_bits); + + ssi_private->second_stream = substream; + } + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ssi_private->playback++; @@ -371,18 +418,16 @@ static int fsl_ssi_prepare(struct snd_pcm_substream *substream) struct fsl_ssi_private *ssi_private = rtd->dai->cpu_dai->private_data; struct ccsr_ssi __iomem *ssi = ssi_private->ssi; - u32 wl; - wl = CCSR_SSI_SxCCR_WL(snd_pcm_format_width(runtime->format)); + if (substream == ssi_private->first_stream) { + u32 wl; - clrbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN); + /* The SSI should always be disabled at this points (SSIEN=0) */ + wl = CCSR_SSI_SxCCR_WL(snd_pcm_format_width(runtime->format)); - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + /* In synchronous mode, the SSI uses STCCR for capture */ clrsetbits_be32(&ssi->stccr, CCSR_SSI_SxCCR_WL_MASK, wl); - else - clrsetbits_be32(&ssi->srccr, CCSR_SSI_SxCCR_WL_MASK, wl); - - setbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN); + } return 0; } @@ -407,9 +452,13 @@ static int fsl_ssi_trigger(struct snd_pcm_substream *substream, int cmd) case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - setbits32(&ssi->scr, CCSR_SSI_SCR_TE); + clrbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN); + setbits32(&ssi->scr, + CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_TE); } else { - setbits32(&ssi->scr, CCSR_SSI_SCR_RE); + clrbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN); + setbits32(&ssi->scr, + CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_RE); /* * I think we need this delay to allow time for the SSI @@ -452,6 +501,11 @@ static void fsl_ssi_shutdown(struct snd_pcm_substream *substream) if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) ssi_private->capture--; + if (ssi_private->first_stream == substream) + ssi_private->first_stream = ssi_private->second_stream; + + ssi_private->second_stream = NULL; + /* * If this is the last active substream, disable the SSI and release * the IRQ. diff --git a/sound/soc/omap/n810.c b/sound/soc/omap/n810.c index 02cec96859b8..7694621ec40b 100644 --- a/sound/soc/omap/n810.c +++ b/sound/soc/omap/n810.c @@ -29,9 +29,9 @@ #include <sound/soc-dapm.h> #include <asm/mach-types.h> -#include <asm/arch/hardware.h> +#include <mach/hardware.h> #include <linux/gpio.h> -#include <asm/arch/mcbsp.h> +#include <mach/mcbsp.h> #include "omap-mcbsp.h" #include "omap-pcm.h" diff --git a/sound/soc/omap/omap-mcbsp.c b/sound/soc/omap/omap-mcbsp.c index 00b0c9d73cd4..35310e16d7f3 100644 --- a/sound/soc/omap/omap-mcbsp.c +++ b/sound/soc/omap/omap-mcbsp.c @@ -30,9 +30,9 @@ #include <sound/initval.h> #include <sound/soc.h> -#include <asm/arch/control.h> -#include <asm/arch/dma.h> -#include <asm/arch/mcbsp.h> +#include <mach/control.h> +#include <mach/dma.h> +#include <mach/mcbsp.h> #include "omap-mcbsp.h" #include "omap-pcm.h" diff --git a/sound/soc/omap/omap-pcm.c b/sound/soc/omap/omap-pcm.c index e092f3d836d0..690bfeaec4a0 100644 --- a/sound/soc/omap/omap-pcm.c +++ b/sound/soc/omap/omap-pcm.c @@ -27,7 +27,7 @@ #include <sound/pcm_params.h> #include <sound/soc.h> -#include <asm/arch/dma.h> +#include <mach/dma.h> #include "omap-pcm.h" static const struct snd_pcm_hardware omap_pcm_hardware = { diff --git a/sound/soc/pxa/Kconfig b/sound/soc/pxa/Kconfig index 12f6ac99b04c..9212c37a33b8 100644 --- a/sound/soc/pxa/Kconfig +++ b/sound/soc/pxa/Kconfig @@ -48,6 +48,7 @@ config SND_PXA2XX_SOC_POODLE config SND_PXA2XX_SOC_TOSA tristate "SoC AC97 Audio support for Tosa" depends on SND_PXA2XX_SOC && MACH_TOSA + depends on MFD_TC6393XB select SND_PXA2XX_SOC_AC97 select SND_SOC_WM9712 help diff --git a/sound/soc/pxa/corgi.c b/sound/soc/pxa/corgi.c index c0294464a23a..0a53f72077fd 100644 --- a/sound/soc/pxa/corgi.c +++ b/sound/soc/pxa/corgi.c @@ -25,10 +25,10 @@ #include <asm/mach-types.h> #include <asm/hardware/scoop.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/hardware.h> -#include <asm/arch/corgi.h> -#include <asm/arch/audio.h> +#include <mach/pxa-regs.h> +#include <mach/hardware.h> +#include <mach/corgi.h> +#include <mach/audio.h> #include "../codecs/wm8731.h" #include "pxa2xx-pcm.h" diff --git a/sound/soc/pxa/e800_wm9712.c b/sound/soc/pxa/e800_wm9712.c index 06e8afb25277..6781c5be242f 100644 --- a/sound/soc/pxa/e800_wm9712.c +++ b/sound/soc/pxa/e800_wm9712.c @@ -21,9 +21,9 @@ #include <sound/soc-dapm.h> #include <asm/mach-types.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/hardware.h> -#include <asm/arch/audio.h> +#include <mach/pxa-regs.h> +#include <mach/hardware.h> +#include <mach/audio.h> #include "../codecs/wm9712.h" #include "pxa2xx-pcm.h" diff --git a/sound/soc/pxa/em-x270.c b/sound/soc/pxa/em-x270.c index 02dcac39cdf6..d9c3f7b28be2 100644 --- a/sound/soc/pxa/em-x270.c +++ b/sound/soc/pxa/em-x270.c @@ -30,9 +30,9 @@ #include <sound/soc-dapm.h> #include <asm/mach-types.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/hardware.h> -#include <asm/arch/audio.h> +#include <mach/pxa-regs.h> +#include <mach/hardware.h> +#include <mach/audio.h> #include "../codecs/wm9712.h" #include "pxa2xx-pcm.h" diff --git a/sound/soc/pxa/poodle.c b/sound/soc/pxa/poodle.c index 65a4e9a8c39e..a4697f7e2921 100644 --- a/sound/soc/pxa/poodle.c +++ b/sound/soc/pxa/poodle.c @@ -26,10 +26,10 @@ #include <asm/mach-types.h> #include <asm/hardware/locomo.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/hardware.h> -#include <asm/arch/poodle.h> -#include <asm/arch/audio.h> +#include <mach/pxa-regs.h> +#include <mach/hardware.h> +#include <mach/poodle.h> +#include <mach/audio.h> #include "../codecs/wm8731.h" #include "pxa2xx-pcm.h" @@ -85,17 +85,13 @@ static int poodle_startup(struct snd_pcm_substream *substream) } /* we need to unmute the HP at shutdown as the mute burns power on poodle */ -static int poodle_shutdown(struct snd_pcm_substream *substream) +static void poodle_shutdown(struct snd_pcm_substream *substream) { - struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_codec *codec = rtd->socdev->codec; - /* set = unmute headphone */ locomo_gpio_write(&poodle_locomo_device.dev, POODLE_LOCOMO_GPIO_MUTE_L, 1); locomo_gpio_write(&poodle_locomo_device.dev, POODLE_LOCOMO_GPIO_MUTE_R, 1); - return 0; } static int poodle_hw_params(struct snd_pcm_substream *substream, @@ -232,7 +228,7 @@ static const struct soc_enum poodle_enum[] = { SOC_ENUM_SINGLE_EXT(2, spk_function), }; -static const snd_kcontrol_new_t wm8731_poodle_controls[] = { +static const struct snd_kcontrol_new wm8731_poodle_controls[] = { SOC_ENUM_EXT("Jack Function", poodle_enum[0], poodle_get_jack, poodle_set_jack), SOC_ENUM_EXT("Speaker Function", poodle_enum[1], poodle_get_spk, diff --git a/sound/soc/pxa/pxa2xx-ac97.c b/sound/soc/pxa/pxa2xx-ac97.c index 059af815ea0c..d94a495bd6bd 100644 --- a/sound/soc/pxa/pxa2xx-ac97.c +++ b/sound/soc/pxa/pxa2xx-ac97.c @@ -26,10 +26,10 @@ #include <asm/irq.h> #include <linux/mutex.h> -#include <asm/hardware.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/pxa2xx-gpio.h> -#include <asm/arch/audio.h> +#include <mach/hardware.h> +#include <mach/pxa-regs.h> +#include <mach/pxa2xx-gpio.h> +#include <mach/audio.h> #include "pxa2xx-pcm.h" #include "pxa2xx-ac97.h" diff --git a/sound/soc/pxa/pxa2xx-i2s.c b/sound/soc/pxa/pxa2xx-i2s.c index 8f96d87f7b4b..8548818eea08 100644 --- a/sound/soc/pxa/pxa2xx-i2s.c +++ b/sound/soc/pxa/pxa2xx-i2s.c @@ -21,10 +21,10 @@ #include <sound/initval.h> #include <sound/soc.h> -#include <asm/hardware.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/pxa2xx-gpio.h> -#include <asm/arch/audio.h> +#include <mach/hardware.h> +#include <mach/pxa-regs.h> +#include <mach/pxa2xx-gpio.h> +#include <mach/audio.h> #include "pxa2xx-pcm.h" #include "pxa2xx-i2s.h" diff --git a/sound/soc/pxa/pxa2xx-pcm.c b/sound/soc/pxa/pxa2xx-pcm.c index 2df03ee5819e..4345f387fe41 100644 --- a/sound/soc/pxa/pxa2xx-pcm.c +++ b/sound/soc/pxa/pxa2xx-pcm.c @@ -22,9 +22,9 @@ #include <sound/soc.h> #include <asm/dma.h> -#include <asm/hardware.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/audio.h> +#include <mach/hardware.h> +#include <mach/pxa-regs.h> +#include <mach/audio.h> #include "pxa2xx-pcm.h" diff --git a/sound/soc/pxa/spitz.c b/sound/soc/pxa/spitz.c index 64385797da5d..37cb768fc933 100644 --- a/sound/soc/pxa/spitz.c +++ b/sound/soc/pxa/spitz.c @@ -26,10 +26,10 @@ #include <asm/mach-types.h> #include <asm/hardware/scoop.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/hardware.h> -#include <asm/arch/akita.h> -#include <asm/arch/spitz.h> +#include <mach/pxa-regs.h> +#include <mach/hardware.h> +#include <mach/akita.h> +#include <mach/spitz.h> #include "../codecs/wm8750.h" #include "pxa2xx-pcm.h" #include "pxa2xx-i2s.h" @@ -297,7 +297,7 @@ static int spitz_wm8750_init(struct snd_soc_codec *codec) snd_soc_dapm_disable_pin(codec, "LINPUT3"); snd_soc_dapm_disable_pin(codec, "RINPUT3"); snd_soc_dapm_disable_pin(codec, "OUT3"); - snd_soc_dapm_disable_pin(codec, "MONO"); + snd_soc_dapm_disable_pin(codec, "MONO1"); /* Add spitz specific controls */ for (i = 0; i < ARRAY_SIZE(wm8750_spitz_controls); i++) { diff --git a/sound/soc/pxa/tosa.c b/sound/soc/pxa/tosa.c index b6edb61a3a30..2baaa750f123 100644 --- a/sound/soc/pxa/tosa.c +++ b/sound/soc/pxa/tosa.c @@ -21,6 +21,7 @@ #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/device.h> +#include <linux/gpio.h> #include <sound/core.h> #include <sound/pcm.h> @@ -28,11 +29,10 @@ #include <sound/soc-dapm.h> #include <asm/mach-types.h> -#include <asm/hardware/tmio.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/hardware.h> -#include <asm/arch/audio.h> -#include <asm/arch/tosa.h> +#include <mach/tosa.h> +#include <mach/pxa-regs.h> +#include <mach/hardware.h> +#include <mach/audio.h> #include "../codecs/wm9712.h" #include "pxa2xx-pcm.h" @@ -137,10 +137,7 @@ static int tosa_set_spk(struct snd_kcontrol *kcontrol, static int tosa_hp_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *k, int event) { - if (SND_SOC_DAPM_EVENT_ON(event)) - set_tc6393_gpio(&tc6393_device.dev,TOSA_TC6393_L_MUTE); - else - reset_tc6393_gpio(&tc6393_device.dev,TOSA_TC6393_L_MUTE); + gpio_set_value(TOSA_GPIO_L_MUTE, SND_SOC_DAPM_EVENT_ON(event) ? 1 :0); return 0; } @@ -254,16 +251,28 @@ static int __init tosa_init(void) if (!machine_is_tosa()) return -ENODEV; + ret = gpio_request(TOSA_GPIO_L_MUTE, "Headphone Jack"); + if (ret) + return ret; + gpio_direction_output(TOSA_GPIO_L_MUTE, 0); + tosa_snd_device = platform_device_alloc("soc-audio", -1); - if (!tosa_snd_device) - return -ENOMEM; + if (!tosa_snd_device) { + ret = -ENOMEM; + goto err_alloc; + } platform_set_drvdata(tosa_snd_device, &tosa_snd_devdata); tosa_snd_devdata.dev = &tosa_snd_device->dev; ret = platform_device_add(tosa_snd_device); - if (ret) - platform_device_put(tosa_snd_device); + if (!ret) + return 0; + + platform_device_put(tosa_snd_device); + +err_alloc: + gpio_free(TOSA_GPIO_L_MUTE); return ret; } @@ -271,6 +280,7 @@ static int __init tosa_init(void) static void __exit tosa_exit(void) { platform_device_unregister(tosa_snd_device); + gpio_free(TOSA_GPIO_L_MUTE); } module_init(tosa_init); diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c index 4d7a9aa15f1a..8089f8ee05c0 100644 --- a/sound/soc/s3c24xx/neo1973_wm8753.c +++ b/sound/soc/s3c24xx/neo1973_wm8753.c @@ -24,14 +24,13 @@ #include <sound/soc-dapm.h> #include <sound/tlv.h> -#include <asm/mach-types.h> #include <asm/hardware/scoop.h> -#include <asm/arch/regs-clock.h> -#include <asm/arch/regs-gpio.h> -#include <asm/hardware.h> -#include <asm/arch/audio.h> +#include <mach/regs-clock.h> +#include <mach/regs-gpio.h> +#include <mach/hardware.h> +#include <mach/audio.h> #include <linux/io.h> -#include <asm/arch/spi-gpio.h> +#include <mach/spi-gpio.h> #include <asm/plat-s3c24xx/regs-iis.h> diff --git a/sound/soc/s3c24xx/s3c2412-i2s.c b/sound/soc/s3c24xx/s3c2412-i2s.c index ee4676ed1283..ded7d995a922 100644 --- a/sound/soc/s3c24xx/s3c2412-i2s.c +++ b/sound/soc/s3c24xx/s3c2412-i2s.c @@ -28,16 +28,16 @@ #include <sound/pcm_params.h> #include <sound/initval.h> #include <sound/soc.h> -#include <asm/hardware.h> +#include <mach/hardware.h> #include <linux/io.h> #include <asm/dma.h> #include <asm/plat-s3c24xx/regs-s3c2412-iis.h> -#include <asm/arch/regs-gpio.h> -#include <asm/arch/audio.h> -#include <asm/arch/dma.h> +#include <mach/regs-gpio.h> +#include <mach/audio.h> +#include <mach/dma.h> #include "s3c24xx-pcm.h" #include "s3c2412-i2s.h" diff --git a/sound/soc/s3c24xx/s3c2443-ac97.c b/sound/soc/s3c24xx/s3c2443-ac97.c index 783349b7fede..19c5c3cf5d8c 100644 --- a/sound/soc/s3c24xx/s3c2443-ac97.c +++ b/sound/soc/s3c24xx/s3c2443-ac97.c @@ -27,13 +27,13 @@ #include <sound/initval.h> #include <sound/soc.h> -#include <asm/hardware.h> +#include <mach/hardware.h> #include <asm/plat-s3c/regs-ac97.h> -#include <asm/arch/regs-gpio.h> -#include <asm/arch/regs-clock.h> -#include <asm/arch/audio.h> +#include <mach/regs-gpio.h> +#include <mach/regs-clock.h> +#include <mach/audio.h> #include <asm/dma.h> -#include <asm/arch/dma.h> +#include <mach/dma.h> #include "s3c24xx-pcm.h" #include "s3c24xx-ac97.h" diff --git a/sound/soc/s3c24xx/s3c24xx-i2s.c b/sound/soc/s3c24xx/s3c24xx-i2s.c index 397524282b57..ba4476b55fbc 100644 --- a/sound/soc/s3c24xx/s3c24xx-i2s.c +++ b/sound/soc/s3c24xx/s3c24xx-i2s.c @@ -27,12 +27,12 @@ #include <sound/initval.h> #include <sound/soc.h> -#include <asm/hardware.h> -#include <asm/arch/regs-gpio.h> -#include <asm/arch/regs-clock.h> -#include <asm/arch/audio.h> +#include <mach/hardware.h> +#include <mach/regs-gpio.h> +#include <mach/regs-clock.h> +#include <mach/audio.h> #include <asm/dma.h> -#include <asm/arch/dma.h> +#include <mach/dma.h> #include <asm/plat-s3c24xx/regs-iis.h> diff --git a/sound/soc/s3c24xx/s3c24xx-pcm.c b/sound/soc/s3c24xx/s3c24xx-pcm.c index cef79b34dc6f..e13e614bada9 100644 --- a/sound/soc/s3c24xx/s3c24xx-pcm.c +++ b/sound/soc/s3c24xx/s3c24xx-pcm.c @@ -27,9 +27,9 @@ #include <sound/soc.h> #include <asm/dma.h> -#include <asm/hardware.h> -#include <asm/arch/dma.h> -#include <asm/arch/audio.h> +#include <mach/hardware.h> +#include <mach/dma.h> +#include <mach/audio.h> #include "s3c24xx-pcm.h" diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 2c87061c2a6b..f9d100bc8479 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -470,6 +470,7 @@ int dapm_reg_event(struct snd_soc_dapm_widget *w, return 0; } +EXPORT_SYMBOL_GPL(dapm_reg_event); /* * Scan each dapm widget for complete audio path. @@ -523,24 +524,6 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event) continue; } - /* programmable gain/attenuation */ - if (w->id == snd_soc_dapm_pga) { - int on; - in = is_connected_input_ep(w); - dapm_clear_walk(w->codec); - out = is_connected_output_ep(w); - dapm_clear_walk(w->codec); - w->power = on = (out != 0 && in != 0) ? 1 : 0; - - if (!on) - dapm_set_pga(w, on); /* lower volume to reduce pops */ - dapm_update_bits(w); - if (on) - dapm_set_pga(w, on); /* restore volume from zero */ - - continue; - } - /* pre and post event widgets */ if (w->id == snd_soc_dapm_pre) { if (!w->event) @@ -586,45 +569,56 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event) power_change = (w->power == power) ? 0: 1; w->power = power; + if (!power_change) + continue; + /* call any power change event handlers */ - if (power_change) { - if (w->event) { - pr_debug("power %s event for %s flags %x\n", - w->power ? "on" : "off", w->name, w->event_flags); - if (power) { - /* power up event */ - if (w->event_flags & SND_SOC_DAPM_PRE_PMU) { - ret = w->event(w, - NULL, SND_SOC_DAPM_PRE_PMU); - if (ret < 0) - return ret; - } - dapm_update_bits(w); - if (w->event_flags & SND_SOC_DAPM_POST_PMU){ - ret = w->event(w, - NULL, SND_SOC_DAPM_POST_PMU); - if (ret < 0) - return ret; - } - } else { - /* power down event */ - if (w->event_flags & SND_SOC_DAPM_PRE_PMD) { - ret = w->event(w, - NULL, SND_SOC_DAPM_PRE_PMD); - if (ret < 0) - return ret; - } - dapm_update_bits(w); - if (w->event_flags & SND_SOC_DAPM_POST_PMD) { - ret = w->event(w, - NULL, SND_SOC_DAPM_POST_PMD); - if (ret < 0) - return ret; - } - } - } else - /* no event handler */ - dapm_update_bits(w); + if (w->event) + pr_debug("power %s event for %s flags %x\n", + w->power ? "on" : "off", + w->name, w->event_flags); + + /* power up pre event */ + if (power && w->event && + (w->event_flags & SND_SOC_DAPM_PRE_PMU)) { + ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU); + if (ret < 0) + return ret; + } + + /* power down pre event */ + if (!power && w->event && + (w->event_flags & SND_SOC_DAPM_PRE_PMD)) { + ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD); + if (ret < 0) + return ret; + } + + /* Lower PGA volume to reduce pops */ + if (w->id == snd_soc_dapm_pga && !power) + dapm_set_pga(w, power); + + dapm_update_bits(w); + + /* Raise PGA volume to reduce pops */ + if (w->id == snd_soc_dapm_pga && power) + dapm_set_pga(w, power); + + /* power up post event */ + if (power && w->event && + (w->event_flags & SND_SOC_DAPM_POST_PMU)) { + ret = w->event(w, + NULL, SND_SOC_DAPM_POST_PMU); + if (ret < 0) + return ret; + } + + /* power down post event */ + if (!power && w->event && + (w->event_flags & SND_SOC_DAPM_POST_PMD)) { + ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD); + if (ret < 0) + return ret; } } } diff --git a/sound/sound_core.c b/sound/sound_core.c index dcfc1d5ce631..1b04259a4328 100644 --- a/sound/sound_core.c +++ b/sound/sound_core.c @@ -171,8 +171,9 @@ static int sound_insert_unit(struct sound_unit **list, const struct file_operati else sprintf(s->name, "sound/%s%d", name, r / SOUND_STEP); - device_create(sound_class, dev, MKDEV(SOUND_MAJOR, s->unit_minor), - s->name+6); + device_create_drvdata(sound_class, dev, + MKDEV(SOUND_MAJOR, s->unit_minor), + NULL, s->name+6); return r; fail: |