112bb5b78SClemens Ladisch /* Analog Devices 1889 audio driver 212bb5b78SClemens Ladisch * 312bb5b78SClemens Ladisch * This is a driver for the AD1889 PCI audio chipset found 412bb5b78SClemens Ladisch * on the HP PA-RISC [BCJ]-xxx0 workstations. 512bb5b78SClemens Ladisch * 612bb5b78SClemens Ladisch * Copyright (C) 2004-2005, Kyle McMartin <kyle@parisc-linux.org> 712bb5b78SClemens Ladisch * Copyright (C) 2005, Thibaut Varene <varenet@parisc-linux.org> 812bb5b78SClemens Ladisch * Based on the OSS AD1889 driver by Randolph Chung <tausq@debian.org> 912bb5b78SClemens Ladisch * 1012bb5b78SClemens Ladisch * This program is free software; you can redistribute it and/or modify 1112bb5b78SClemens Ladisch * it under the terms of the GNU General Public License, version 2, as 1212bb5b78SClemens Ladisch * published by the Free Software Foundation. 1312bb5b78SClemens Ladisch * 1412bb5b78SClemens Ladisch * This program is distributed in the hope that it will be useful, 1512bb5b78SClemens Ladisch * but WITHOUT ANY WARRANTY; without even the implied warranty of 1612bb5b78SClemens Ladisch * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1712bb5b78SClemens Ladisch * GNU General Public License for more details. 1812bb5b78SClemens Ladisch * 1912bb5b78SClemens Ladisch * You should have received a copy of the GNU General Public License 2012bb5b78SClemens Ladisch * along with this program; if not, write to the Free Software 2112bb5b78SClemens Ladisch * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 2212bb5b78SClemens Ladisch * 2312bb5b78SClemens Ladisch * TODO: 2412bb5b78SClemens Ladisch * Do we need to take care of CCS register? 2512bb5b78SClemens Ladisch * Maybe we could use finer grained locking (separate locks for pb/cap)? 2612bb5b78SClemens Ladisch * Wishlist: 2712bb5b78SClemens Ladisch * Control Interface (mixer) support 2812bb5b78SClemens Ladisch * Better AC97 support (VSR...)? 2912bb5b78SClemens Ladisch * PM support 3012bb5b78SClemens Ladisch * MIDI support 3112bb5b78SClemens Ladisch * Game Port support 3212bb5b78SClemens Ladisch * SG DMA support (this will need *a lot* of work) 3312bb5b78SClemens Ladisch */ 3412bb5b78SClemens Ladisch 3512bb5b78SClemens Ladisch #include <linux/init.h> 3612bb5b78SClemens Ladisch #include <linux/pci.h> 379d2f928dSTobias Klauser #include <linux/dma-mapping.h> 3812bb5b78SClemens Ladisch #include <linux/slab.h> 3912bb5b78SClemens Ladisch #include <linux/interrupt.h> 4012bb5b78SClemens Ladisch #include <linux/compiler.h> 4112bb5b78SClemens Ladisch #include <linux/delay.h> 42da155d5bSPaul Gortmaker #include <linux/module.h> 4312bb5b78SClemens Ladisch 4412bb5b78SClemens Ladisch #include <sound/core.h> 4512bb5b78SClemens Ladisch #include <sound/pcm.h> 4612bb5b78SClemens Ladisch #include <sound/initval.h> 4712bb5b78SClemens Ladisch #include <sound/ac97_codec.h> 4812bb5b78SClemens Ladisch 4912bb5b78SClemens Ladisch #include <asm/io.h> 5012bb5b78SClemens Ladisch 5112bb5b78SClemens Ladisch #include "ad1889.h" 5212bb5b78SClemens Ladisch #include "ac97/ac97_id.h" 5312bb5b78SClemens Ladisch 54c6f43290SJaroslav Kysela #define AD1889_DRVVER "Version: 1.7" 5512bb5b78SClemens Ladisch 5612bb5b78SClemens Ladisch MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>, Thibaut Varene <t-bone@parisc-linux.org>"); 5712bb5b78SClemens Ladisch MODULE_DESCRIPTION("Analog Devices AD1889 ALSA sound driver"); 5812bb5b78SClemens Ladisch MODULE_LICENSE("GPL"); 5912bb5b78SClemens Ladisch MODULE_SUPPORTED_DEVICE("{{Analog Devices,AD1889}}"); 6012bb5b78SClemens Ladisch 6112bb5b78SClemens Ladisch static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 6212bb5b78SClemens Ladisch module_param_array(index, int, NULL, 0444); 6312bb5b78SClemens Ladisch MODULE_PARM_DESC(index, "Index value for the AD1889 soundcard."); 6412bb5b78SClemens Ladisch 6512bb5b78SClemens Ladisch static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 6612bb5b78SClemens Ladisch module_param_array(id, charp, NULL, 0444); 6712bb5b78SClemens Ladisch MODULE_PARM_DESC(id, "ID string for the AD1889 soundcard."); 6812bb5b78SClemens Ladisch 69a67ff6a5SRusty Russell static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 7012bb5b78SClemens Ladisch module_param_array(enable, bool, NULL, 0444); 7112bb5b78SClemens Ladisch MODULE_PARM_DESC(enable, "Enable AD1889 soundcard."); 7212bb5b78SClemens Ladisch 7312bb5b78SClemens Ladisch static char *ac97_quirk[SNDRV_CARDS]; 7412bb5b78SClemens Ladisch module_param_array(ac97_quirk, charp, NULL, 0444); 7512bb5b78SClemens Ladisch MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); 7612bb5b78SClemens Ladisch 7712bb5b78SClemens Ladisch #define DEVNAME "ad1889" 7812bb5b78SClemens Ladisch #define PFX DEVNAME ": " 7912bb5b78SClemens Ladisch 8012bb5b78SClemens Ladisch /* keep track of some hw registers */ 8112bb5b78SClemens Ladisch struct ad1889_register_state { 8212bb5b78SClemens Ladisch u16 reg; /* reg setup */ 8312bb5b78SClemens Ladisch u32 addr; /* dma base address */ 8412bb5b78SClemens Ladisch unsigned long size; /* DMA buffer size */ 8512bb5b78SClemens Ladisch }; 8612bb5b78SClemens Ladisch 8712bb5b78SClemens Ladisch struct snd_ad1889 { 8802c2de69STakashi Iwai struct snd_card *card; 8912bb5b78SClemens Ladisch struct pci_dev *pci; 9012bb5b78SClemens Ladisch 9112bb5b78SClemens Ladisch int irq; 9212bb5b78SClemens Ladisch unsigned long bar; 9312bb5b78SClemens Ladisch void __iomem *iobase; 9412bb5b78SClemens Ladisch 9502c2de69STakashi Iwai struct snd_ac97 *ac97; 9602c2de69STakashi Iwai struct snd_ac97_bus *ac97_bus; 9702c2de69STakashi Iwai struct snd_pcm *pcm; 9802c2de69STakashi Iwai struct snd_info_entry *proc; 9912bb5b78SClemens Ladisch 10002c2de69STakashi Iwai struct snd_pcm_substream *psubs; 10102c2de69STakashi Iwai struct snd_pcm_substream *csubs; 10212bb5b78SClemens Ladisch 10312bb5b78SClemens Ladisch /* playback register state */ 10412bb5b78SClemens Ladisch struct ad1889_register_state wave; 10512bb5b78SClemens Ladisch struct ad1889_register_state ramc; 10612bb5b78SClemens Ladisch 10712bb5b78SClemens Ladisch spinlock_t lock; 10812bb5b78SClemens Ladisch }; 10912bb5b78SClemens Ladisch 11012bb5b78SClemens Ladisch static inline u16 11112bb5b78SClemens Ladisch ad1889_readw(struct snd_ad1889 *chip, unsigned reg) 11212bb5b78SClemens Ladisch { 11312bb5b78SClemens Ladisch return readw(chip->iobase + reg); 11412bb5b78SClemens Ladisch } 11512bb5b78SClemens Ladisch 11612bb5b78SClemens Ladisch static inline void 11712bb5b78SClemens Ladisch ad1889_writew(struct snd_ad1889 *chip, unsigned reg, u16 val) 11812bb5b78SClemens Ladisch { 11912bb5b78SClemens Ladisch writew(val, chip->iobase + reg); 12012bb5b78SClemens Ladisch } 12112bb5b78SClemens Ladisch 12212bb5b78SClemens Ladisch static inline u32 12312bb5b78SClemens Ladisch ad1889_readl(struct snd_ad1889 *chip, unsigned reg) 12412bb5b78SClemens Ladisch { 12512bb5b78SClemens Ladisch return readl(chip->iobase + reg); 12612bb5b78SClemens Ladisch } 12712bb5b78SClemens Ladisch 12812bb5b78SClemens Ladisch static inline void 12912bb5b78SClemens Ladisch ad1889_writel(struct snd_ad1889 *chip, unsigned reg, u32 val) 13012bb5b78SClemens Ladisch { 13112bb5b78SClemens Ladisch writel(val, chip->iobase + reg); 13212bb5b78SClemens Ladisch } 13312bb5b78SClemens Ladisch 13412bb5b78SClemens Ladisch static inline void 13512bb5b78SClemens Ladisch ad1889_unmute(struct snd_ad1889 *chip) 13612bb5b78SClemens Ladisch { 13712bb5b78SClemens Ladisch u16 st; 13812bb5b78SClemens Ladisch st = ad1889_readw(chip, AD_DS_WADA) & 13912bb5b78SClemens Ladisch ~(AD_DS_WADA_RWAM | AD_DS_WADA_LWAM); 14012bb5b78SClemens Ladisch ad1889_writew(chip, AD_DS_WADA, st); 14112bb5b78SClemens Ladisch ad1889_readw(chip, AD_DS_WADA); 14212bb5b78SClemens Ladisch } 14312bb5b78SClemens Ladisch 14412bb5b78SClemens Ladisch static inline void 14512bb5b78SClemens Ladisch ad1889_mute(struct snd_ad1889 *chip) 14612bb5b78SClemens Ladisch { 14712bb5b78SClemens Ladisch u16 st; 14812bb5b78SClemens Ladisch st = ad1889_readw(chip, AD_DS_WADA) | AD_DS_WADA_RWAM | AD_DS_WADA_LWAM; 14912bb5b78SClemens Ladisch ad1889_writew(chip, AD_DS_WADA, st); 15012bb5b78SClemens Ladisch ad1889_readw(chip, AD_DS_WADA); 15112bb5b78SClemens Ladisch } 15212bb5b78SClemens Ladisch 15312bb5b78SClemens Ladisch static inline void 15412bb5b78SClemens Ladisch ad1889_load_adc_buffer_address(struct snd_ad1889 *chip, u32 address) 15512bb5b78SClemens Ladisch { 15612bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_ADCBA, address); 15712bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_ADCCA, address); 15812bb5b78SClemens Ladisch } 15912bb5b78SClemens Ladisch 16012bb5b78SClemens Ladisch static inline void 16112bb5b78SClemens Ladisch ad1889_load_adc_buffer_count(struct snd_ad1889 *chip, u32 count) 16212bb5b78SClemens Ladisch { 16312bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_ADCBC, count); 16412bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_ADCCC, count); 16512bb5b78SClemens Ladisch } 16612bb5b78SClemens Ladisch 16712bb5b78SClemens Ladisch static inline void 16812bb5b78SClemens Ladisch ad1889_load_adc_interrupt_count(struct snd_ad1889 *chip, u32 count) 16912bb5b78SClemens Ladisch { 17012bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_ADCIB, count); 17112bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_ADCIC, count); 17212bb5b78SClemens Ladisch } 17312bb5b78SClemens Ladisch 17412bb5b78SClemens Ladisch static inline void 17512bb5b78SClemens Ladisch ad1889_load_wave_buffer_address(struct snd_ad1889 *chip, u32 address) 17612bb5b78SClemens Ladisch { 17712bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_WAVBA, address); 17812bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_WAVCA, address); 17912bb5b78SClemens Ladisch } 18012bb5b78SClemens Ladisch 18112bb5b78SClemens Ladisch static inline void 18212bb5b78SClemens Ladisch ad1889_load_wave_buffer_count(struct snd_ad1889 *chip, u32 count) 18312bb5b78SClemens Ladisch { 18412bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_WAVBC, count); 18512bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_WAVCC, count); 18612bb5b78SClemens Ladisch } 18712bb5b78SClemens Ladisch 18812bb5b78SClemens Ladisch static inline void 18912bb5b78SClemens Ladisch ad1889_load_wave_interrupt_count(struct snd_ad1889 *chip, u32 count) 19012bb5b78SClemens Ladisch { 19112bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_WAVIB, count); 19212bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_WAVIC, count); 19312bb5b78SClemens Ladisch } 19412bb5b78SClemens Ladisch 19512bb5b78SClemens Ladisch static void 19612bb5b78SClemens Ladisch ad1889_channel_reset(struct snd_ad1889 *chip, unsigned int channel) 19712bb5b78SClemens Ladisch { 19812bb5b78SClemens Ladisch u16 reg; 19912bb5b78SClemens Ladisch 20012bb5b78SClemens Ladisch if (channel & AD_CHAN_WAV) { 20112bb5b78SClemens Ladisch /* Disable wave channel */ 20212bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_DS_WSMC) & ~AD_DS_WSMC_WAEN; 20312bb5b78SClemens Ladisch ad1889_writew(chip, AD_DS_WSMC, reg); 20412bb5b78SClemens Ladisch chip->wave.reg = reg; 20512bb5b78SClemens Ladisch 20612bb5b78SClemens Ladisch /* disable IRQs */ 20712bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_DMA_WAV); 20812bb5b78SClemens Ladisch reg &= AD_DMA_IM_DIS; 20912bb5b78SClemens Ladisch reg &= ~AD_DMA_LOOP; 21012bb5b78SClemens Ladisch ad1889_writew(chip, AD_DMA_WAV, reg); 21112bb5b78SClemens Ladisch 21212bb5b78SClemens Ladisch /* clear IRQ and address counters and pointers */ 21312bb5b78SClemens Ladisch ad1889_load_wave_buffer_address(chip, 0x0); 21412bb5b78SClemens Ladisch ad1889_load_wave_buffer_count(chip, 0x0); 21512bb5b78SClemens Ladisch ad1889_load_wave_interrupt_count(chip, 0x0); 21612bb5b78SClemens Ladisch 21712bb5b78SClemens Ladisch /* flush */ 21812bb5b78SClemens Ladisch ad1889_readw(chip, AD_DMA_WAV); 21912bb5b78SClemens Ladisch } 22012bb5b78SClemens Ladisch 22112bb5b78SClemens Ladisch if (channel & AD_CHAN_ADC) { 22212bb5b78SClemens Ladisch /* Disable ADC channel */ 22312bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_DS_RAMC) & ~AD_DS_RAMC_ADEN; 22412bb5b78SClemens Ladisch ad1889_writew(chip, AD_DS_RAMC, reg); 22512bb5b78SClemens Ladisch chip->ramc.reg = reg; 22612bb5b78SClemens Ladisch 22712bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_DMA_ADC); 22812bb5b78SClemens Ladisch reg &= AD_DMA_IM_DIS; 22912bb5b78SClemens Ladisch reg &= ~AD_DMA_LOOP; 23012bb5b78SClemens Ladisch ad1889_writew(chip, AD_DMA_ADC, reg); 23112bb5b78SClemens Ladisch 23212bb5b78SClemens Ladisch ad1889_load_adc_buffer_address(chip, 0x0); 23312bb5b78SClemens Ladisch ad1889_load_adc_buffer_count(chip, 0x0); 23412bb5b78SClemens Ladisch ad1889_load_adc_interrupt_count(chip, 0x0); 23512bb5b78SClemens Ladisch 23612bb5b78SClemens Ladisch /* flush */ 23712bb5b78SClemens Ladisch ad1889_readw(chip, AD_DMA_ADC); 23812bb5b78SClemens Ladisch } 23912bb5b78SClemens Ladisch } 24012bb5b78SClemens Ladisch 241f40b6890STakashi Iwai static u16 24202c2de69STakashi Iwai snd_ad1889_ac97_read(struct snd_ac97 *ac97, unsigned short reg) 24312bb5b78SClemens Ladisch { 24412bb5b78SClemens Ladisch struct snd_ad1889 *chip = ac97->private_data; 24512bb5b78SClemens Ladisch return ad1889_readw(chip, AD_AC97_BASE + reg); 24612bb5b78SClemens Ladisch } 24712bb5b78SClemens Ladisch 248f40b6890STakashi Iwai static void 24902c2de69STakashi Iwai snd_ad1889_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val) 25012bb5b78SClemens Ladisch { 25112bb5b78SClemens Ladisch struct snd_ad1889 *chip = ac97->private_data; 25212bb5b78SClemens Ladisch ad1889_writew(chip, AD_AC97_BASE + reg, val); 25312bb5b78SClemens Ladisch } 25412bb5b78SClemens Ladisch 25512bb5b78SClemens Ladisch static int 25612bb5b78SClemens Ladisch snd_ad1889_ac97_ready(struct snd_ad1889 *chip) 25712bb5b78SClemens Ladisch { 25812bb5b78SClemens Ladisch int retry = 400; /* average needs 352 msec */ 25912bb5b78SClemens Ladisch 26012bb5b78SClemens Ladisch while (!(ad1889_readw(chip, AD_AC97_ACIC) & AD_AC97_ACIC_ACRDY) 26112bb5b78SClemens Ladisch && --retry) 26212bb5b78SClemens Ladisch mdelay(1); 26312bb5b78SClemens Ladisch if (!retry) { 26429633004STakashi Iwai dev_err(chip->card->dev, "[%s] Link is not ready.\n", 2659bf8e7ddSHarvey Harrison __func__); 26612bb5b78SClemens Ladisch return -EIO; 26712bb5b78SClemens Ladisch } 26829633004STakashi Iwai dev_dbg(chip->card->dev, "[%s] ready after %d ms\n", __func__, 400 - retry); 26912bb5b78SClemens Ladisch 27012bb5b78SClemens Ladisch return 0; 27112bb5b78SClemens Ladisch } 27212bb5b78SClemens Ladisch 27312bb5b78SClemens Ladisch static int 27402c2de69STakashi Iwai snd_ad1889_hw_params(struct snd_pcm_substream *substream, 27502c2de69STakashi Iwai struct snd_pcm_hw_params *hw_params) 27612bb5b78SClemens Ladisch { 27712bb5b78SClemens Ladisch return snd_pcm_lib_malloc_pages(substream, 27812bb5b78SClemens Ladisch params_buffer_bytes(hw_params)); 27912bb5b78SClemens Ladisch } 28012bb5b78SClemens Ladisch 28112bb5b78SClemens Ladisch static int 28202c2de69STakashi Iwai snd_ad1889_hw_free(struct snd_pcm_substream *substream) 28312bb5b78SClemens Ladisch { 28412bb5b78SClemens Ladisch return snd_pcm_lib_free_pages(substream); 28512bb5b78SClemens Ladisch } 28612bb5b78SClemens Ladisch 28702c2de69STakashi Iwai static struct snd_pcm_hardware snd_ad1889_playback_hw = { 28812bb5b78SClemens Ladisch .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 28912bb5b78SClemens Ladisch SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BLOCK_TRANSFER, 29012bb5b78SClemens Ladisch .formats = SNDRV_PCM_FMTBIT_S16_LE, 29112bb5b78SClemens Ladisch .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, 29212bb5b78SClemens Ladisch .rate_min = 8000, /* docs say 7000, but we're lazy */ 29312bb5b78SClemens Ladisch .rate_max = 48000, 29412bb5b78SClemens Ladisch .channels_min = 1, 29512bb5b78SClemens Ladisch .channels_max = 2, 29612bb5b78SClemens Ladisch .buffer_bytes_max = BUFFER_BYTES_MAX, 29712bb5b78SClemens Ladisch .period_bytes_min = PERIOD_BYTES_MIN, 29812bb5b78SClemens Ladisch .period_bytes_max = PERIOD_BYTES_MAX, 29912bb5b78SClemens Ladisch .periods_min = PERIODS_MIN, 30012bb5b78SClemens Ladisch .periods_max = PERIODS_MAX, 30112bb5b78SClemens Ladisch /*.fifo_size = 0,*/ 30212bb5b78SClemens Ladisch }; 30312bb5b78SClemens Ladisch 30402c2de69STakashi Iwai static struct snd_pcm_hardware snd_ad1889_capture_hw = { 30512bb5b78SClemens Ladisch .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 30612bb5b78SClemens Ladisch SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BLOCK_TRANSFER, 30712bb5b78SClemens Ladisch .formats = SNDRV_PCM_FMTBIT_S16_LE, 30812bb5b78SClemens Ladisch .rates = SNDRV_PCM_RATE_48000, 30912bb5b78SClemens Ladisch .rate_min = 48000, /* docs say we could to VSR, but we're lazy */ 31012bb5b78SClemens Ladisch .rate_max = 48000, 31112bb5b78SClemens Ladisch .channels_min = 1, 31212bb5b78SClemens Ladisch .channels_max = 2, 31312bb5b78SClemens Ladisch .buffer_bytes_max = BUFFER_BYTES_MAX, 31412bb5b78SClemens Ladisch .period_bytes_min = PERIOD_BYTES_MIN, 31512bb5b78SClemens Ladisch .period_bytes_max = PERIOD_BYTES_MAX, 31612bb5b78SClemens Ladisch .periods_min = PERIODS_MIN, 31712bb5b78SClemens Ladisch .periods_max = PERIODS_MAX, 31812bb5b78SClemens Ladisch /*.fifo_size = 0,*/ 31912bb5b78SClemens Ladisch }; 32012bb5b78SClemens Ladisch 32112bb5b78SClemens Ladisch static int 32202c2de69STakashi Iwai snd_ad1889_playback_open(struct snd_pcm_substream *ss) 32312bb5b78SClemens Ladisch { 32412bb5b78SClemens Ladisch struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); 32502c2de69STakashi Iwai struct snd_pcm_runtime *rt = ss->runtime; 32612bb5b78SClemens Ladisch 32712bb5b78SClemens Ladisch chip->psubs = ss; 32812bb5b78SClemens Ladisch rt->hw = snd_ad1889_playback_hw; 32912bb5b78SClemens Ladisch 33012bb5b78SClemens Ladisch return 0; 33112bb5b78SClemens Ladisch } 33212bb5b78SClemens Ladisch 33312bb5b78SClemens Ladisch static int 33402c2de69STakashi Iwai snd_ad1889_capture_open(struct snd_pcm_substream *ss) 33512bb5b78SClemens Ladisch { 33612bb5b78SClemens Ladisch struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); 33702c2de69STakashi Iwai struct snd_pcm_runtime *rt = ss->runtime; 33812bb5b78SClemens Ladisch 33912bb5b78SClemens Ladisch chip->csubs = ss; 34012bb5b78SClemens Ladisch rt->hw = snd_ad1889_capture_hw; 34112bb5b78SClemens Ladisch 34212bb5b78SClemens Ladisch return 0; 34312bb5b78SClemens Ladisch } 34412bb5b78SClemens Ladisch 34512bb5b78SClemens Ladisch static int 34602c2de69STakashi Iwai snd_ad1889_playback_close(struct snd_pcm_substream *ss) 34712bb5b78SClemens Ladisch { 34812bb5b78SClemens Ladisch struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); 34912bb5b78SClemens Ladisch chip->psubs = NULL; 35012bb5b78SClemens Ladisch return 0; 35112bb5b78SClemens Ladisch } 35212bb5b78SClemens Ladisch 35312bb5b78SClemens Ladisch static int 35402c2de69STakashi Iwai snd_ad1889_capture_close(struct snd_pcm_substream *ss) 35512bb5b78SClemens Ladisch { 35612bb5b78SClemens Ladisch struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); 35712bb5b78SClemens Ladisch chip->csubs = NULL; 35812bb5b78SClemens Ladisch return 0; 35912bb5b78SClemens Ladisch } 36012bb5b78SClemens Ladisch 36112bb5b78SClemens Ladisch static int 36202c2de69STakashi Iwai snd_ad1889_playback_prepare(struct snd_pcm_substream *ss) 36312bb5b78SClemens Ladisch { 36412bb5b78SClemens Ladisch struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); 36502c2de69STakashi Iwai struct snd_pcm_runtime *rt = ss->runtime; 36612bb5b78SClemens Ladisch unsigned int size = snd_pcm_lib_buffer_bytes(ss); 36712bb5b78SClemens Ladisch unsigned int count = snd_pcm_lib_period_bytes(ss); 36812bb5b78SClemens Ladisch u16 reg; 36912bb5b78SClemens Ladisch 37012bb5b78SClemens Ladisch ad1889_channel_reset(chip, AD_CHAN_WAV); 37112bb5b78SClemens Ladisch 37212bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_DS_WSMC); 37312bb5b78SClemens Ladisch 37412bb5b78SClemens Ladisch /* Mask out 16-bit / Stereo */ 37512bb5b78SClemens Ladisch reg &= ~(AD_DS_WSMC_WA16 | AD_DS_WSMC_WAST); 37612bb5b78SClemens Ladisch 37712bb5b78SClemens Ladisch if (snd_pcm_format_width(rt->format) == 16) 37812bb5b78SClemens Ladisch reg |= AD_DS_WSMC_WA16; 37912bb5b78SClemens Ladisch 38012bb5b78SClemens Ladisch if (rt->channels > 1) 38112bb5b78SClemens Ladisch reg |= AD_DS_WSMC_WAST; 38212bb5b78SClemens Ladisch 38312bb5b78SClemens Ladisch /* let's make sure we don't clobber ourselves */ 38412bb5b78SClemens Ladisch spin_lock_irq(&chip->lock); 38512bb5b78SClemens Ladisch 38612bb5b78SClemens Ladisch chip->wave.size = size; 38712bb5b78SClemens Ladisch chip->wave.reg = reg; 38812bb5b78SClemens Ladisch chip->wave.addr = rt->dma_addr; 38912bb5b78SClemens Ladisch 39012bb5b78SClemens Ladisch ad1889_writew(chip, AD_DS_WSMC, chip->wave.reg); 39112bb5b78SClemens Ladisch 39212bb5b78SClemens Ladisch /* Set sample rates on the codec */ 39312bb5b78SClemens Ladisch ad1889_writew(chip, AD_DS_WAS, rt->rate); 39412bb5b78SClemens Ladisch 39512bb5b78SClemens Ladisch /* Set up DMA */ 39612bb5b78SClemens Ladisch ad1889_load_wave_buffer_address(chip, chip->wave.addr); 39712bb5b78SClemens Ladisch ad1889_load_wave_buffer_count(chip, size); 39812bb5b78SClemens Ladisch ad1889_load_wave_interrupt_count(chip, count); 39912bb5b78SClemens Ladisch 40012bb5b78SClemens Ladisch /* writes flush */ 40112bb5b78SClemens Ladisch ad1889_readw(chip, AD_DS_WSMC); 40212bb5b78SClemens Ladisch 40312bb5b78SClemens Ladisch spin_unlock_irq(&chip->lock); 40412bb5b78SClemens Ladisch 40529633004STakashi Iwai dev_dbg(chip->card->dev, 40629633004STakashi Iwai "prepare playback: addr = 0x%x, count = %u, size = %u, reg = 0x%x, rate = %u\n", 40729633004STakashi Iwai chip->wave.addr, count, size, reg, rt->rate); 40812bb5b78SClemens Ladisch return 0; 40912bb5b78SClemens Ladisch } 41012bb5b78SClemens Ladisch 41112bb5b78SClemens Ladisch static int 41202c2de69STakashi Iwai snd_ad1889_capture_prepare(struct snd_pcm_substream *ss) 41312bb5b78SClemens Ladisch { 41412bb5b78SClemens Ladisch struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); 41502c2de69STakashi Iwai struct snd_pcm_runtime *rt = ss->runtime; 41612bb5b78SClemens Ladisch unsigned int size = snd_pcm_lib_buffer_bytes(ss); 41712bb5b78SClemens Ladisch unsigned int count = snd_pcm_lib_period_bytes(ss); 41812bb5b78SClemens Ladisch u16 reg; 41912bb5b78SClemens Ladisch 42012bb5b78SClemens Ladisch ad1889_channel_reset(chip, AD_CHAN_ADC); 42112bb5b78SClemens Ladisch 42212bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_DS_RAMC); 42312bb5b78SClemens Ladisch 42412bb5b78SClemens Ladisch /* Mask out 16-bit / Stereo */ 42512bb5b78SClemens Ladisch reg &= ~(AD_DS_RAMC_AD16 | AD_DS_RAMC_ADST); 42612bb5b78SClemens Ladisch 42712bb5b78SClemens Ladisch if (snd_pcm_format_width(rt->format) == 16) 42812bb5b78SClemens Ladisch reg |= AD_DS_RAMC_AD16; 42912bb5b78SClemens Ladisch 43012bb5b78SClemens Ladisch if (rt->channels > 1) 43112bb5b78SClemens Ladisch reg |= AD_DS_RAMC_ADST; 43212bb5b78SClemens Ladisch 43312bb5b78SClemens Ladisch /* let's make sure we don't clobber ourselves */ 43412bb5b78SClemens Ladisch spin_lock_irq(&chip->lock); 43512bb5b78SClemens Ladisch 43612bb5b78SClemens Ladisch chip->ramc.size = size; 43712bb5b78SClemens Ladisch chip->ramc.reg = reg; 43812bb5b78SClemens Ladisch chip->ramc.addr = rt->dma_addr; 43912bb5b78SClemens Ladisch 44012bb5b78SClemens Ladisch ad1889_writew(chip, AD_DS_RAMC, chip->ramc.reg); 44112bb5b78SClemens Ladisch 44212bb5b78SClemens Ladisch /* Set up DMA */ 44312bb5b78SClemens Ladisch ad1889_load_adc_buffer_address(chip, chip->ramc.addr); 44412bb5b78SClemens Ladisch ad1889_load_adc_buffer_count(chip, size); 44512bb5b78SClemens Ladisch ad1889_load_adc_interrupt_count(chip, count); 44612bb5b78SClemens Ladisch 44712bb5b78SClemens Ladisch /* writes flush */ 44812bb5b78SClemens Ladisch ad1889_readw(chip, AD_DS_RAMC); 44912bb5b78SClemens Ladisch 45012bb5b78SClemens Ladisch spin_unlock_irq(&chip->lock); 45112bb5b78SClemens Ladisch 45229633004STakashi Iwai dev_dbg(chip->card->dev, 45329633004STakashi Iwai "prepare capture: addr = 0x%x, count = %u, size = %u, reg = 0x%x, rate = %u\n", 45429633004STakashi Iwai chip->ramc.addr, count, size, reg, rt->rate); 45512bb5b78SClemens Ladisch return 0; 45612bb5b78SClemens Ladisch } 45712bb5b78SClemens Ladisch 45812bb5b78SClemens Ladisch /* this is called in atomic context with IRQ disabled. 45912bb5b78SClemens Ladisch Must be as fast as possible and not sleep. 46012bb5b78SClemens Ladisch DMA should be *triggered* by this call. 46112bb5b78SClemens Ladisch The WSMC "WAEN" bit triggers DMA Wave On/Off */ 46212bb5b78SClemens Ladisch static int 46302c2de69STakashi Iwai snd_ad1889_playback_trigger(struct snd_pcm_substream *ss, int cmd) 46412bb5b78SClemens Ladisch { 46512bb5b78SClemens Ladisch u16 wsmc; 46612bb5b78SClemens Ladisch struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); 46712bb5b78SClemens Ladisch 46812bb5b78SClemens Ladisch wsmc = ad1889_readw(chip, AD_DS_WSMC); 46912bb5b78SClemens Ladisch 47012bb5b78SClemens Ladisch switch (cmd) { 47112bb5b78SClemens Ladisch case SNDRV_PCM_TRIGGER_START: 47212bb5b78SClemens Ladisch /* enable DMA loop & interrupts */ 47312bb5b78SClemens Ladisch ad1889_writew(chip, AD_DMA_WAV, AD_DMA_LOOP | AD_DMA_IM_CNT); 47412bb5b78SClemens Ladisch wsmc |= AD_DS_WSMC_WAEN; 47512bb5b78SClemens Ladisch /* 1 to clear CHSS bit */ 47612bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_CHSS, AD_DMA_CHSS_WAVS); 47712bb5b78SClemens Ladisch ad1889_unmute(chip); 47812bb5b78SClemens Ladisch break; 47912bb5b78SClemens Ladisch case SNDRV_PCM_TRIGGER_STOP: 48012bb5b78SClemens Ladisch ad1889_mute(chip); 48112bb5b78SClemens Ladisch wsmc &= ~AD_DS_WSMC_WAEN; 48212bb5b78SClemens Ladisch break; 48312bb5b78SClemens Ladisch default: 48412bb5b78SClemens Ladisch snd_BUG(); 48512bb5b78SClemens Ladisch return -EINVAL; 48612bb5b78SClemens Ladisch } 48712bb5b78SClemens Ladisch 48812bb5b78SClemens Ladisch chip->wave.reg = wsmc; 48912bb5b78SClemens Ladisch ad1889_writew(chip, AD_DS_WSMC, wsmc); 49012bb5b78SClemens Ladisch ad1889_readw(chip, AD_DS_WSMC); /* flush */ 49112bb5b78SClemens Ladisch 49212bb5b78SClemens Ladisch /* reset the chip when STOP - will disable IRQs */ 49312bb5b78SClemens Ladisch if (cmd == SNDRV_PCM_TRIGGER_STOP) 49412bb5b78SClemens Ladisch ad1889_channel_reset(chip, AD_CHAN_WAV); 49512bb5b78SClemens Ladisch 49612bb5b78SClemens Ladisch return 0; 49712bb5b78SClemens Ladisch } 49812bb5b78SClemens Ladisch 49912bb5b78SClemens Ladisch /* this is called in atomic context with IRQ disabled. 50012bb5b78SClemens Ladisch Must be as fast as possible and not sleep. 50112bb5b78SClemens Ladisch DMA should be *triggered* by this call. 50212bb5b78SClemens Ladisch The RAMC "ADEN" bit triggers DMA ADC On/Off */ 50312bb5b78SClemens Ladisch static int 50402c2de69STakashi Iwai snd_ad1889_capture_trigger(struct snd_pcm_substream *ss, int cmd) 50512bb5b78SClemens Ladisch { 50612bb5b78SClemens Ladisch u16 ramc; 50712bb5b78SClemens Ladisch struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); 50812bb5b78SClemens Ladisch 50912bb5b78SClemens Ladisch ramc = ad1889_readw(chip, AD_DS_RAMC); 51012bb5b78SClemens Ladisch 51112bb5b78SClemens Ladisch switch (cmd) { 51212bb5b78SClemens Ladisch case SNDRV_PCM_TRIGGER_START: 51312bb5b78SClemens Ladisch /* enable DMA loop & interrupts */ 51412bb5b78SClemens Ladisch ad1889_writew(chip, AD_DMA_ADC, AD_DMA_LOOP | AD_DMA_IM_CNT); 51512bb5b78SClemens Ladisch ramc |= AD_DS_RAMC_ADEN; 51612bb5b78SClemens Ladisch /* 1 to clear CHSS bit */ 51712bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_CHSS, AD_DMA_CHSS_ADCS); 51812bb5b78SClemens Ladisch break; 51912bb5b78SClemens Ladisch case SNDRV_PCM_TRIGGER_STOP: 52012bb5b78SClemens Ladisch ramc &= ~AD_DS_RAMC_ADEN; 52112bb5b78SClemens Ladisch break; 52212bb5b78SClemens Ladisch default: 52312bb5b78SClemens Ladisch return -EINVAL; 52412bb5b78SClemens Ladisch } 52512bb5b78SClemens Ladisch 52612bb5b78SClemens Ladisch chip->ramc.reg = ramc; 52712bb5b78SClemens Ladisch ad1889_writew(chip, AD_DS_RAMC, ramc); 52812bb5b78SClemens Ladisch ad1889_readw(chip, AD_DS_RAMC); /* flush */ 52912bb5b78SClemens Ladisch 53012bb5b78SClemens Ladisch /* reset the chip when STOP - will disable IRQs */ 53112bb5b78SClemens Ladisch if (cmd == SNDRV_PCM_TRIGGER_STOP) 53212bb5b78SClemens Ladisch ad1889_channel_reset(chip, AD_CHAN_ADC); 53312bb5b78SClemens Ladisch 53412bb5b78SClemens Ladisch return 0; 53512bb5b78SClemens Ladisch } 53612bb5b78SClemens Ladisch 53712bb5b78SClemens Ladisch /* Called in atomic context with IRQ disabled */ 53812bb5b78SClemens Ladisch static snd_pcm_uframes_t 53902c2de69STakashi Iwai snd_ad1889_playback_pointer(struct snd_pcm_substream *ss) 54012bb5b78SClemens Ladisch { 54112bb5b78SClemens Ladisch size_t ptr = 0; 54212bb5b78SClemens Ladisch struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); 54312bb5b78SClemens Ladisch 54412bb5b78SClemens Ladisch if (unlikely(!(chip->wave.reg & AD_DS_WSMC_WAEN))) 54512bb5b78SClemens Ladisch return 0; 54612bb5b78SClemens Ladisch 54712bb5b78SClemens Ladisch ptr = ad1889_readl(chip, AD_DMA_WAVCA); 54812bb5b78SClemens Ladisch ptr -= chip->wave.addr; 54912bb5b78SClemens Ladisch 550da3cec35STakashi Iwai if (snd_BUG_ON(ptr >= chip->wave.size)) 551da3cec35STakashi Iwai return 0; 55212bb5b78SClemens Ladisch 55312bb5b78SClemens Ladisch return bytes_to_frames(ss->runtime, ptr); 55412bb5b78SClemens Ladisch } 55512bb5b78SClemens Ladisch 55612bb5b78SClemens Ladisch /* Called in atomic context with IRQ disabled */ 55712bb5b78SClemens Ladisch static snd_pcm_uframes_t 55802c2de69STakashi Iwai snd_ad1889_capture_pointer(struct snd_pcm_substream *ss) 55912bb5b78SClemens Ladisch { 56012bb5b78SClemens Ladisch size_t ptr = 0; 56112bb5b78SClemens Ladisch struct snd_ad1889 *chip = snd_pcm_substream_chip(ss); 56212bb5b78SClemens Ladisch 56312bb5b78SClemens Ladisch if (unlikely(!(chip->ramc.reg & AD_DS_RAMC_ADEN))) 56412bb5b78SClemens Ladisch return 0; 56512bb5b78SClemens Ladisch 56612bb5b78SClemens Ladisch ptr = ad1889_readl(chip, AD_DMA_ADCCA); 56712bb5b78SClemens Ladisch ptr -= chip->ramc.addr; 56812bb5b78SClemens Ladisch 569da3cec35STakashi Iwai if (snd_BUG_ON(ptr >= chip->ramc.size)) 570da3cec35STakashi Iwai return 0; 57112bb5b78SClemens Ladisch 57212bb5b78SClemens Ladisch return bytes_to_frames(ss->runtime, ptr); 57312bb5b78SClemens Ladisch } 57412bb5b78SClemens Ladisch 57502c2de69STakashi Iwai static struct snd_pcm_ops snd_ad1889_playback_ops = { 57612bb5b78SClemens Ladisch .open = snd_ad1889_playback_open, 57712bb5b78SClemens Ladisch .close = snd_ad1889_playback_close, 57812bb5b78SClemens Ladisch .ioctl = snd_pcm_lib_ioctl, 57912bb5b78SClemens Ladisch .hw_params = snd_ad1889_hw_params, 58012bb5b78SClemens Ladisch .hw_free = snd_ad1889_hw_free, 58112bb5b78SClemens Ladisch .prepare = snd_ad1889_playback_prepare, 58212bb5b78SClemens Ladisch .trigger = snd_ad1889_playback_trigger, 58312bb5b78SClemens Ladisch .pointer = snd_ad1889_playback_pointer, 58412bb5b78SClemens Ladisch }; 58512bb5b78SClemens Ladisch 58602c2de69STakashi Iwai static struct snd_pcm_ops snd_ad1889_capture_ops = { 58712bb5b78SClemens Ladisch .open = snd_ad1889_capture_open, 58812bb5b78SClemens Ladisch .close = snd_ad1889_capture_close, 58912bb5b78SClemens Ladisch .ioctl = snd_pcm_lib_ioctl, 59012bb5b78SClemens Ladisch .hw_params = snd_ad1889_hw_params, 59112bb5b78SClemens Ladisch .hw_free = snd_ad1889_hw_free, 59212bb5b78SClemens Ladisch .prepare = snd_ad1889_capture_prepare, 59312bb5b78SClemens Ladisch .trigger = snd_ad1889_capture_trigger, 59412bb5b78SClemens Ladisch .pointer = snd_ad1889_capture_pointer, 59512bb5b78SClemens Ladisch }; 59612bb5b78SClemens Ladisch 59712bb5b78SClemens Ladisch static irqreturn_t 5987d12e780SDavid Howells snd_ad1889_interrupt(int irq, void *dev_id) 59912bb5b78SClemens Ladisch { 60012bb5b78SClemens Ladisch unsigned long st; 60112bb5b78SClemens Ladisch struct snd_ad1889 *chip = dev_id; 60212bb5b78SClemens Ladisch 60312bb5b78SClemens Ladisch st = ad1889_readl(chip, AD_DMA_DISR); 60412bb5b78SClemens Ladisch 60512bb5b78SClemens Ladisch /* clear ISR */ 60612bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_DISR, st); 60712bb5b78SClemens Ladisch 60812bb5b78SClemens Ladisch st &= AD_INTR_MASK; 60912bb5b78SClemens Ladisch 61012bb5b78SClemens Ladisch if (unlikely(!st)) 61112bb5b78SClemens Ladisch return IRQ_NONE; 61212bb5b78SClemens Ladisch 61312bb5b78SClemens Ladisch if (st & (AD_DMA_DISR_PMAI|AD_DMA_DISR_PTAI)) 61429633004STakashi Iwai dev_dbg(chip->card->dev, 61529633004STakashi Iwai "Unexpected master or target abort interrupt!\n"); 61612bb5b78SClemens Ladisch 61712bb5b78SClemens Ladisch if ((st & AD_DMA_DISR_WAVI) && chip->psubs) 61812bb5b78SClemens Ladisch snd_pcm_period_elapsed(chip->psubs); 61912bb5b78SClemens Ladisch if ((st & AD_DMA_DISR_ADCI) && chip->csubs) 62012bb5b78SClemens Ladisch snd_pcm_period_elapsed(chip->csubs); 62112bb5b78SClemens Ladisch 62212bb5b78SClemens Ladisch return IRQ_HANDLED; 62312bb5b78SClemens Ladisch } 62412bb5b78SClemens Ladisch 6252f5c1302SBill Pemberton static int 62602c2de69STakashi Iwai snd_ad1889_pcm_init(struct snd_ad1889 *chip, int device, struct snd_pcm **rpcm) 62712bb5b78SClemens Ladisch { 62812bb5b78SClemens Ladisch int err; 62902c2de69STakashi Iwai struct snd_pcm *pcm; 63012bb5b78SClemens Ladisch 63112bb5b78SClemens Ladisch if (rpcm) 63212bb5b78SClemens Ladisch *rpcm = NULL; 63312bb5b78SClemens Ladisch 63412bb5b78SClemens Ladisch err = snd_pcm_new(chip->card, chip->card->driver, device, 1, 1, &pcm); 63512bb5b78SClemens Ladisch if (err < 0) 63612bb5b78SClemens Ladisch return err; 63712bb5b78SClemens Ladisch 63812bb5b78SClemens Ladisch snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, 63912bb5b78SClemens Ladisch &snd_ad1889_playback_ops); 64012bb5b78SClemens Ladisch snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 64112bb5b78SClemens Ladisch &snd_ad1889_capture_ops); 64212bb5b78SClemens Ladisch 64312bb5b78SClemens Ladisch pcm->private_data = chip; 64412bb5b78SClemens Ladisch pcm->info_flags = 0; 64512bb5b78SClemens Ladisch strcpy(pcm->name, chip->card->shortname); 64612bb5b78SClemens Ladisch 64712bb5b78SClemens Ladisch chip->pcm = pcm; 64812bb5b78SClemens Ladisch chip->psubs = NULL; 64912bb5b78SClemens Ladisch chip->csubs = NULL; 65012bb5b78SClemens Ladisch 65112bb5b78SClemens Ladisch err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 65212bb5b78SClemens Ladisch snd_dma_pci_data(chip->pci), 65312bb5b78SClemens Ladisch BUFFER_BYTES_MAX / 2, 65412bb5b78SClemens Ladisch BUFFER_BYTES_MAX); 65512bb5b78SClemens Ladisch 65612bb5b78SClemens Ladisch if (err < 0) { 65729633004STakashi Iwai dev_err(chip->card->dev, "buffer allocation error: %d\n", err); 65812bb5b78SClemens Ladisch return err; 65912bb5b78SClemens Ladisch } 66012bb5b78SClemens Ladisch 66112bb5b78SClemens Ladisch if (rpcm) 66212bb5b78SClemens Ladisch *rpcm = pcm; 66312bb5b78SClemens Ladisch 66412bb5b78SClemens Ladisch return 0; 66512bb5b78SClemens Ladisch } 66612bb5b78SClemens Ladisch 66712bb5b78SClemens Ladisch static void 66802c2de69STakashi Iwai snd_ad1889_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 66912bb5b78SClemens Ladisch { 67012bb5b78SClemens Ladisch struct snd_ad1889 *chip = entry->private_data; 67112bb5b78SClemens Ladisch u16 reg; 67212bb5b78SClemens Ladisch int tmp; 67312bb5b78SClemens Ladisch 67412bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_DS_WSMC); 67512bb5b78SClemens Ladisch snd_iprintf(buffer, "Wave output: %s\n", 67612bb5b78SClemens Ladisch (reg & AD_DS_WSMC_WAEN) ? "enabled" : "disabled"); 67712bb5b78SClemens Ladisch snd_iprintf(buffer, "Wave Channels: %s\n", 67812bb5b78SClemens Ladisch (reg & AD_DS_WSMC_WAST) ? "stereo" : "mono"); 67912bb5b78SClemens Ladisch snd_iprintf(buffer, "Wave Quality: %d-bit linear\n", 68012bb5b78SClemens Ladisch (reg & AD_DS_WSMC_WA16) ? 16 : 8); 68112bb5b78SClemens Ladisch 68212bb5b78SClemens Ladisch /* WARQ is at offset 12 */ 68312bb5b78SClemens Ladisch tmp = (reg & AD_DS_WSMC_WARQ) ? 68412bb5b78SClemens Ladisch (((reg & AD_DS_WSMC_WARQ >> 12) & 0x01) ? 12 : 18) : 4; 68512bb5b78SClemens Ladisch tmp /= (reg & AD_DS_WSMC_WAST) ? 2 : 1; 68612bb5b78SClemens Ladisch 68712bb5b78SClemens Ladisch snd_iprintf(buffer, "Wave FIFO: %d %s words\n\n", tmp, 68812bb5b78SClemens Ladisch (reg & AD_DS_WSMC_WAST) ? "stereo" : "mono"); 68912bb5b78SClemens Ladisch 69012bb5b78SClemens Ladisch 69112bb5b78SClemens Ladisch snd_iprintf(buffer, "Synthesis output: %s\n", 69212bb5b78SClemens Ladisch reg & AD_DS_WSMC_SYEN ? "enabled" : "disabled"); 69312bb5b78SClemens Ladisch 69412bb5b78SClemens Ladisch /* SYRQ is at offset 4 */ 69512bb5b78SClemens Ladisch tmp = (reg & AD_DS_WSMC_SYRQ) ? 69612bb5b78SClemens Ladisch (((reg & AD_DS_WSMC_SYRQ >> 4) & 0x01) ? 12 : 18) : 4; 69712bb5b78SClemens Ladisch tmp /= (reg & AD_DS_WSMC_WAST) ? 2 : 1; 69812bb5b78SClemens Ladisch 69912bb5b78SClemens Ladisch snd_iprintf(buffer, "Synthesis FIFO: %d %s words\n\n", tmp, 70012bb5b78SClemens Ladisch (reg & AD_DS_WSMC_WAST) ? "stereo" : "mono"); 70112bb5b78SClemens Ladisch 70212bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_DS_RAMC); 70312bb5b78SClemens Ladisch snd_iprintf(buffer, "ADC input: %s\n", 70412bb5b78SClemens Ladisch (reg & AD_DS_RAMC_ADEN) ? "enabled" : "disabled"); 70512bb5b78SClemens Ladisch snd_iprintf(buffer, "ADC Channels: %s\n", 70612bb5b78SClemens Ladisch (reg & AD_DS_RAMC_ADST) ? "stereo" : "mono"); 70712bb5b78SClemens Ladisch snd_iprintf(buffer, "ADC Quality: %d-bit linear\n", 70812bb5b78SClemens Ladisch (reg & AD_DS_RAMC_AD16) ? 16 : 8); 70912bb5b78SClemens Ladisch 71012bb5b78SClemens Ladisch /* ACRQ is at offset 4 */ 71112bb5b78SClemens Ladisch tmp = (reg & AD_DS_RAMC_ACRQ) ? 71212bb5b78SClemens Ladisch (((reg & AD_DS_RAMC_ACRQ >> 4) & 0x01) ? 12 : 18) : 4; 71312bb5b78SClemens Ladisch tmp /= (reg & AD_DS_RAMC_ADST) ? 2 : 1; 71412bb5b78SClemens Ladisch 71512bb5b78SClemens Ladisch snd_iprintf(buffer, "ADC FIFO: %d %s words\n\n", tmp, 71612bb5b78SClemens Ladisch (reg & AD_DS_RAMC_ADST) ? "stereo" : "mono"); 71712bb5b78SClemens Ladisch 71812bb5b78SClemens Ladisch snd_iprintf(buffer, "Resampler input: %s\n", 71912bb5b78SClemens Ladisch reg & AD_DS_RAMC_REEN ? "enabled" : "disabled"); 72012bb5b78SClemens Ladisch 72112bb5b78SClemens Ladisch /* RERQ is at offset 12 */ 72212bb5b78SClemens Ladisch tmp = (reg & AD_DS_RAMC_RERQ) ? 72312bb5b78SClemens Ladisch (((reg & AD_DS_RAMC_RERQ >> 12) & 0x01) ? 12 : 18) : 4; 72412bb5b78SClemens Ladisch tmp /= (reg & AD_DS_RAMC_ADST) ? 2 : 1; 72512bb5b78SClemens Ladisch 72612bb5b78SClemens Ladisch snd_iprintf(buffer, "Resampler FIFO: %d %s words\n\n", tmp, 72712bb5b78SClemens Ladisch (reg & AD_DS_WSMC_WAST) ? "stereo" : "mono"); 72812bb5b78SClemens Ladisch 72912bb5b78SClemens Ladisch 73012bb5b78SClemens Ladisch /* doc says LSB represents -1.5dB, but the max value (-94.5dB) 73112bb5b78SClemens Ladisch suggests that LSB is -3dB, which is more coherent with the logarithmic 73212bb5b78SClemens Ladisch nature of the dB scale */ 73312bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_DS_WADA); 73412bb5b78SClemens Ladisch snd_iprintf(buffer, "Left: %s, -%d dB\n", 73512bb5b78SClemens Ladisch (reg & AD_DS_WADA_LWAM) ? "mute" : "unmute", 73612bb5b78SClemens Ladisch ((reg & AD_DS_WADA_LWAA) >> 8) * 3); 73712bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_DS_WADA); 73812bb5b78SClemens Ladisch snd_iprintf(buffer, "Right: %s, -%d dB\n", 73912bb5b78SClemens Ladisch (reg & AD_DS_WADA_RWAM) ? "mute" : "unmute", 7409bd0f5c0STakashi Iwai (reg & AD_DS_WADA_RWAA) * 3); 74112bb5b78SClemens Ladisch 74212bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_DS_WAS); 74312bb5b78SClemens Ladisch snd_iprintf(buffer, "Wave samplerate: %u Hz\n", reg); 74412bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_DS_RES); 74512bb5b78SClemens Ladisch snd_iprintf(buffer, "Resampler samplerate: %u Hz\n", reg); 74612bb5b78SClemens Ladisch } 74712bb5b78SClemens Ladisch 7482f5c1302SBill Pemberton static void 74912bb5b78SClemens Ladisch snd_ad1889_proc_init(struct snd_ad1889 *chip) 75012bb5b78SClemens Ladisch { 75102c2de69STakashi Iwai struct snd_info_entry *entry; 75212bb5b78SClemens Ladisch 75312bb5b78SClemens Ladisch if (!snd_card_proc_new(chip->card, chip->card->driver, &entry)) 754bf850204STakashi Iwai snd_info_set_text_ops(entry, chip, snd_ad1889_proc_read); 75512bb5b78SClemens Ladisch } 75612bb5b78SClemens Ladisch 75712bb5b78SClemens Ladisch static struct ac97_quirk ac97_quirks[] = { 75812bb5b78SClemens Ladisch { 75912bb5b78SClemens Ladisch .subvendor = 0x11d4, /* AD */ 76012bb5b78SClemens Ladisch .subdevice = 0x1889, /* AD1889 */ 76112bb5b78SClemens Ladisch .codec_id = AC97_ID_AD1819, 76212bb5b78SClemens Ladisch .name = "AD1889", 76312bb5b78SClemens Ladisch .type = AC97_TUNE_HP_ONLY 76412bb5b78SClemens Ladisch }, 76512bb5b78SClemens Ladisch { } /* terminator */ 76612bb5b78SClemens Ladisch }; 76712bb5b78SClemens Ladisch 7682f5c1302SBill Pemberton static void 76912bb5b78SClemens Ladisch snd_ad1889_ac97_xinit(struct snd_ad1889 *chip) 77012bb5b78SClemens Ladisch { 77112bb5b78SClemens Ladisch u16 reg; 77212bb5b78SClemens Ladisch 77312bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_AC97_ACIC); 77412bb5b78SClemens Ladisch reg |= AD_AC97_ACIC_ACRD; /* Reset Disable */ 77512bb5b78SClemens Ladisch ad1889_writew(chip, AD_AC97_ACIC, reg); 77612bb5b78SClemens Ladisch ad1889_readw(chip, AD_AC97_ACIC); /* flush posted write */ 77712bb5b78SClemens Ladisch udelay(10); 77812bb5b78SClemens Ladisch /* Interface Enable */ 77912bb5b78SClemens Ladisch reg |= AD_AC97_ACIC_ACIE; 78012bb5b78SClemens Ladisch ad1889_writew(chip, AD_AC97_ACIC, reg); 78112bb5b78SClemens Ladisch 78212bb5b78SClemens Ladisch snd_ad1889_ac97_ready(chip); 78312bb5b78SClemens Ladisch 78412bb5b78SClemens Ladisch /* Audio Stream Output | Variable Sample Rate Mode */ 78512bb5b78SClemens Ladisch reg = ad1889_readw(chip, AD_AC97_ACIC); 78612bb5b78SClemens Ladisch reg |= AD_AC97_ACIC_ASOE | AD_AC97_ACIC_VSRM; 78712bb5b78SClemens Ladisch ad1889_writew(chip, AD_AC97_ACIC, reg); 78812bb5b78SClemens Ladisch ad1889_readw(chip, AD_AC97_ACIC); /* flush posted write */ 78912bb5b78SClemens Ladisch 79012bb5b78SClemens Ladisch } 79112bb5b78SClemens Ladisch 79212bb5b78SClemens Ladisch static void 79302c2de69STakashi Iwai snd_ad1889_ac97_bus_free(struct snd_ac97_bus *bus) 79412bb5b78SClemens Ladisch { 79512bb5b78SClemens Ladisch struct snd_ad1889 *chip = bus->private_data; 79612bb5b78SClemens Ladisch chip->ac97_bus = NULL; 79712bb5b78SClemens Ladisch } 79812bb5b78SClemens Ladisch 79912bb5b78SClemens Ladisch static void 80002c2de69STakashi Iwai snd_ad1889_ac97_free(struct snd_ac97 *ac97) 80112bb5b78SClemens Ladisch { 80212bb5b78SClemens Ladisch struct snd_ad1889 *chip = ac97->private_data; 80312bb5b78SClemens Ladisch chip->ac97 = NULL; 80412bb5b78SClemens Ladisch } 80512bb5b78SClemens Ladisch 8062f5c1302SBill Pemberton static int 80712bb5b78SClemens Ladisch snd_ad1889_ac97_init(struct snd_ad1889 *chip, const char *quirk_override) 80812bb5b78SClemens Ladisch { 80912bb5b78SClemens Ladisch int err; 81002c2de69STakashi Iwai struct snd_ac97_template ac97; 81102c2de69STakashi Iwai static struct snd_ac97_bus_ops ops = { 81212bb5b78SClemens Ladisch .write = snd_ad1889_ac97_write, 81312bb5b78SClemens Ladisch .read = snd_ad1889_ac97_read, 81412bb5b78SClemens Ladisch }; 81512bb5b78SClemens Ladisch 81612bb5b78SClemens Ladisch /* doing that here, it works. */ 81712bb5b78SClemens Ladisch snd_ad1889_ac97_xinit(chip); 81812bb5b78SClemens Ladisch 81912bb5b78SClemens Ladisch err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus); 82012bb5b78SClemens Ladisch if (err < 0) 82112bb5b78SClemens Ladisch return err; 82212bb5b78SClemens Ladisch 82312bb5b78SClemens Ladisch chip->ac97_bus->private_free = snd_ad1889_ac97_bus_free; 82412bb5b78SClemens Ladisch 82512bb5b78SClemens Ladisch memset(&ac97, 0, sizeof(ac97)); 82612bb5b78SClemens Ladisch ac97.private_data = chip; 82712bb5b78SClemens Ladisch ac97.private_free = snd_ad1889_ac97_free; 82812bb5b78SClemens Ladisch ac97.pci = chip->pci; 82912bb5b78SClemens Ladisch 83012bb5b78SClemens Ladisch err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97); 83112bb5b78SClemens Ladisch if (err < 0) 83212bb5b78SClemens Ladisch return err; 83312bb5b78SClemens Ladisch 83412bb5b78SClemens Ladisch snd_ac97_tune_hardware(chip->ac97, ac97_quirks, quirk_override); 83512bb5b78SClemens Ladisch 83612bb5b78SClemens Ladisch return 0; 83712bb5b78SClemens Ladisch } 83812bb5b78SClemens Ladisch 83912bb5b78SClemens Ladisch static int 84012bb5b78SClemens Ladisch snd_ad1889_free(struct snd_ad1889 *chip) 84112bb5b78SClemens Ladisch { 84212bb5b78SClemens Ladisch if (chip->irq < 0) 84312bb5b78SClemens Ladisch goto skip_hw; 84412bb5b78SClemens Ladisch 84512bb5b78SClemens Ladisch spin_lock_irq(&chip->lock); 84612bb5b78SClemens Ladisch 84712bb5b78SClemens Ladisch ad1889_mute(chip); 84812bb5b78SClemens Ladisch 84912bb5b78SClemens Ladisch /* Turn off interrupt on count and zero DMA registers */ 85012bb5b78SClemens Ladisch ad1889_channel_reset(chip, AD_CHAN_WAV | AD_CHAN_ADC); 85112bb5b78SClemens Ladisch 85212bb5b78SClemens Ladisch /* clear DISR. If we don't, we'd better jump off the Eiffel Tower */ 85312bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_DISR, AD_DMA_DISR_PTAI | AD_DMA_DISR_PMAI); 85412bb5b78SClemens Ladisch ad1889_readl(chip, AD_DMA_DISR); /* flush, dammit! */ 85512bb5b78SClemens Ladisch 85612bb5b78SClemens Ladisch spin_unlock_irq(&chip->lock); 85712bb5b78SClemens Ladisch 85812bb5b78SClemens Ladisch if (chip->irq >= 0) 859437a5a46STakashi Iwai free_irq(chip->irq, chip); 86012bb5b78SClemens Ladisch 86112bb5b78SClemens Ladisch skip_hw: 86212bb5b78SClemens Ladisch if (chip->iobase) 86312bb5b78SClemens Ladisch iounmap(chip->iobase); 86412bb5b78SClemens Ladisch 86512bb5b78SClemens Ladisch pci_release_regions(chip->pci); 86612bb5b78SClemens Ladisch pci_disable_device(chip->pci); 86712bb5b78SClemens Ladisch 86812bb5b78SClemens Ladisch kfree(chip); 86912bb5b78SClemens Ladisch return 0; 87012bb5b78SClemens Ladisch } 87112bb5b78SClemens Ladisch 872f40b6890STakashi Iwai static int 87302c2de69STakashi Iwai snd_ad1889_dev_free(struct snd_device *device) 87412bb5b78SClemens Ladisch { 87512bb5b78SClemens Ladisch struct snd_ad1889 *chip = device->device_data; 87612bb5b78SClemens Ladisch return snd_ad1889_free(chip); 87712bb5b78SClemens Ladisch } 87812bb5b78SClemens Ladisch 8792f5c1302SBill Pemberton static int 88012bb5b78SClemens Ladisch snd_ad1889_init(struct snd_ad1889 *chip) 88112bb5b78SClemens Ladisch { 88212bb5b78SClemens Ladisch ad1889_writew(chip, AD_DS_CCS, AD_DS_CCS_CLKEN); /* turn on clock */ 88312bb5b78SClemens Ladisch ad1889_readw(chip, AD_DS_CCS); /* flush posted write */ 88412bb5b78SClemens Ladisch 88512bb5b78SClemens Ladisch mdelay(10); 88612bb5b78SClemens Ladisch 88712bb5b78SClemens Ladisch /* enable Master and Target abort interrupts */ 88812bb5b78SClemens Ladisch ad1889_writel(chip, AD_DMA_DISR, AD_DMA_DISR_PMAE | AD_DMA_DISR_PTAE); 88912bb5b78SClemens Ladisch 89012bb5b78SClemens Ladisch return 0; 89112bb5b78SClemens Ladisch } 89212bb5b78SClemens Ladisch 8932f5c1302SBill Pemberton static int 89402c2de69STakashi Iwai snd_ad1889_create(struct snd_card *card, 89512bb5b78SClemens Ladisch struct pci_dev *pci, 89612bb5b78SClemens Ladisch struct snd_ad1889 **rchip) 89712bb5b78SClemens Ladisch { 89812bb5b78SClemens Ladisch int err; 89912bb5b78SClemens Ladisch 90012bb5b78SClemens Ladisch struct snd_ad1889 *chip; 90102c2de69STakashi Iwai static struct snd_device_ops ops = { 90212bb5b78SClemens Ladisch .dev_free = snd_ad1889_dev_free, 90312bb5b78SClemens Ladisch }; 90412bb5b78SClemens Ladisch 90512bb5b78SClemens Ladisch *rchip = NULL; 90612bb5b78SClemens Ladisch 90712bb5b78SClemens Ladisch if ((err = pci_enable_device(pci)) < 0) 90812bb5b78SClemens Ladisch return err; 90912bb5b78SClemens Ladisch 91012bb5b78SClemens Ladisch /* check PCI availability (32bit DMA) */ 911284901a9SYang Hongyang if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 || 912284901a9SYang Hongyang pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { 91329633004STakashi Iwai dev_err(card->dev, "error setting 32-bit DMA mask.\n"); 91412bb5b78SClemens Ladisch pci_disable_device(pci); 91512bb5b78SClemens Ladisch return -ENXIO; 91612bb5b78SClemens Ladisch } 91712bb5b78SClemens Ladisch 91812bb5b78SClemens Ladisch /* allocate chip specific data with zero-filled memory */ 919e560d8d8STakashi Iwai if ((chip = kzalloc(sizeof(*chip), GFP_KERNEL)) == NULL) { 92012bb5b78SClemens Ladisch pci_disable_device(pci); 92112bb5b78SClemens Ladisch return -ENOMEM; 92212bb5b78SClemens Ladisch } 92312bb5b78SClemens Ladisch 92412bb5b78SClemens Ladisch chip->card = card; 92512bb5b78SClemens Ladisch card->private_data = chip; 92612bb5b78SClemens Ladisch chip->pci = pci; 92712bb5b78SClemens Ladisch chip->irq = -1; 92812bb5b78SClemens Ladisch 92912bb5b78SClemens Ladisch /* (1) PCI resource allocation */ 93012bb5b78SClemens Ladisch if ((err = pci_request_regions(pci, card->driver)) < 0) 93112bb5b78SClemens Ladisch goto free_and_ret; 93212bb5b78SClemens Ladisch 93312bb5b78SClemens Ladisch chip->bar = pci_resource_start(pci, 0); 9342f5ad54eSArjan van de Ven chip->iobase = pci_ioremap_bar(pci, 0); 93512bb5b78SClemens Ladisch if (chip->iobase == NULL) { 93629633004STakashi Iwai dev_err(card->dev, "unable to reserve region.\n"); 93712bb5b78SClemens Ladisch err = -EBUSY; 93812bb5b78SClemens Ladisch goto free_and_ret; 93912bb5b78SClemens Ladisch } 94012bb5b78SClemens Ladisch 94112bb5b78SClemens Ladisch pci_set_master(pci); 94212bb5b78SClemens Ladisch 94312bb5b78SClemens Ladisch spin_lock_init(&chip->lock); /* only now can we call ad1889_free */ 94412bb5b78SClemens Ladisch 94512bb5b78SClemens Ladisch if (request_irq(pci->irq, snd_ad1889_interrupt, 946934c2b6dSTakashi Iwai IRQF_SHARED, KBUILD_MODNAME, chip)) { 94729633004STakashi Iwai dev_err(card->dev, "cannot obtain IRQ %d\n", pci->irq); 94812bb5b78SClemens Ladisch snd_ad1889_free(chip); 94912bb5b78SClemens Ladisch return -EBUSY; 95012bb5b78SClemens Ladisch } 95112bb5b78SClemens Ladisch 95212bb5b78SClemens Ladisch chip->irq = pci->irq; 95312bb5b78SClemens Ladisch synchronize_irq(chip->irq); 95412bb5b78SClemens Ladisch 95512bb5b78SClemens Ladisch /* (2) initialization of the chip hardware */ 95612bb5b78SClemens Ladisch if ((err = snd_ad1889_init(chip)) < 0) { 95712bb5b78SClemens Ladisch snd_ad1889_free(chip); 95812bb5b78SClemens Ladisch return err; 95912bb5b78SClemens Ladisch } 96012bb5b78SClemens Ladisch 96112bb5b78SClemens Ladisch if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 96212bb5b78SClemens Ladisch snd_ad1889_free(chip); 96312bb5b78SClemens Ladisch return err; 96412bb5b78SClemens Ladisch } 96512bb5b78SClemens Ladisch 96612bb5b78SClemens Ladisch *rchip = chip; 96712bb5b78SClemens Ladisch 96812bb5b78SClemens Ladisch return 0; 96912bb5b78SClemens Ladisch 97012bb5b78SClemens Ladisch free_and_ret: 97112bb5b78SClemens Ladisch kfree(chip); 97212bb5b78SClemens Ladisch pci_disable_device(pci); 97312bb5b78SClemens Ladisch 97412bb5b78SClemens Ladisch return err; 97512bb5b78SClemens Ladisch } 97612bb5b78SClemens Ladisch 9772f5c1302SBill Pemberton static int 97812bb5b78SClemens Ladisch snd_ad1889_probe(struct pci_dev *pci, 97912bb5b78SClemens Ladisch const struct pci_device_id *pci_id) 98012bb5b78SClemens Ladisch { 98112bb5b78SClemens Ladisch int err; 98212bb5b78SClemens Ladisch static int devno; 98302c2de69STakashi Iwai struct snd_card *card; 98412bb5b78SClemens Ladisch struct snd_ad1889 *chip; 98512bb5b78SClemens Ladisch 98612bb5b78SClemens Ladisch /* (1) */ 98712bb5b78SClemens Ladisch if (devno >= SNDRV_CARDS) 98812bb5b78SClemens Ladisch return -ENODEV; 98912bb5b78SClemens Ladisch if (!enable[devno]) { 99012bb5b78SClemens Ladisch devno++; 99112bb5b78SClemens Ladisch return -ENOENT; 99212bb5b78SClemens Ladisch } 99312bb5b78SClemens Ladisch 99412bb5b78SClemens Ladisch /* (2) */ 99560c5772bSTakashi Iwai err = snd_card_new(&pci->dev, index[devno], id[devno], THIS_MODULE, 99660c5772bSTakashi Iwai 0, &card); 99712bb5b78SClemens Ladisch /* XXX REVISIT: we can probably allocate chip in this call */ 998e58de7baSTakashi Iwai if (err < 0) 999e58de7baSTakashi Iwai return err; 100012bb5b78SClemens Ladisch 100112bb5b78SClemens Ladisch strcpy(card->driver, "AD1889"); 100212bb5b78SClemens Ladisch strcpy(card->shortname, "Analog Devices AD1889"); 100312bb5b78SClemens Ladisch 100412bb5b78SClemens Ladisch /* (3) */ 100512bb5b78SClemens Ladisch err = snd_ad1889_create(card, pci, &chip); 100612bb5b78SClemens Ladisch if (err < 0) 100712bb5b78SClemens Ladisch goto free_and_ret; 100812bb5b78SClemens Ladisch 100912bb5b78SClemens Ladisch /* (4) */ 101012bb5b78SClemens Ladisch sprintf(card->longname, "%s at 0x%lx irq %i", 101112bb5b78SClemens Ladisch card->shortname, chip->bar, chip->irq); 101212bb5b78SClemens Ladisch 101312bb5b78SClemens Ladisch /* (5) */ 101412bb5b78SClemens Ladisch /* register AC97 mixer */ 101512bb5b78SClemens Ladisch err = snd_ad1889_ac97_init(chip, ac97_quirk[devno]); 101612bb5b78SClemens Ladisch if (err < 0) 101712bb5b78SClemens Ladisch goto free_and_ret; 101812bb5b78SClemens Ladisch 101912bb5b78SClemens Ladisch err = snd_ad1889_pcm_init(chip, 0, NULL); 102012bb5b78SClemens Ladisch if (err < 0) 102112bb5b78SClemens Ladisch goto free_and_ret; 102212bb5b78SClemens Ladisch 102312bb5b78SClemens Ladisch /* register proc interface */ 102412bb5b78SClemens Ladisch snd_ad1889_proc_init(chip); 102512bb5b78SClemens Ladisch 102612bb5b78SClemens Ladisch /* (6) */ 102712bb5b78SClemens Ladisch err = snd_card_register(card); 102812bb5b78SClemens Ladisch if (err < 0) 102912bb5b78SClemens Ladisch goto free_and_ret; 103012bb5b78SClemens Ladisch 103112bb5b78SClemens Ladisch /* (7) */ 103212bb5b78SClemens Ladisch pci_set_drvdata(pci, card); 103312bb5b78SClemens Ladisch 103412bb5b78SClemens Ladisch devno++; 103512bb5b78SClemens Ladisch return 0; 103612bb5b78SClemens Ladisch 103712bb5b78SClemens Ladisch free_and_ret: 103812bb5b78SClemens Ladisch snd_card_free(card); 103912bb5b78SClemens Ladisch return err; 104012bb5b78SClemens Ladisch } 104112bb5b78SClemens Ladisch 10422f5c1302SBill Pemberton static void 104312bb5b78SClemens Ladisch snd_ad1889_remove(struct pci_dev *pci) 104412bb5b78SClemens Ladisch { 104512bb5b78SClemens Ladisch snd_card_free(pci_get_drvdata(pci)); 104612bb5b78SClemens Ladisch } 104712bb5b78SClemens Ladisch 1048cebe41d4SAlexey Dobriyan static DEFINE_PCI_DEVICE_TABLE(snd_ad1889_ids) = { 104912bb5b78SClemens Ladisch { PCI_DEVICE(PCI_VENDOR_ID_ANALOG_DEVICES, PCI_DEVICE_ID_AD1889JS) }, 105012bb5b78SClemens Ladisch { 0, }, 105112bb5b78SClemens Ladisch }; 105212bb5b78SClemens Ladisch MODULE_DEVICE_TABLE(pci, snd_ad1889_ids); 105312bb5b78SClemens Ladisch 1054e4d76815SRandy Dunlap static struct pci_driver ad1889_pci_driver = { 10553733e424STakashi Iwai .name = KBUILD_MODNAME, 105612bb5b78SClemens Ladisch .id_table = snd_ad1889_ids, 105712bb5b78SClemens Ladisch .probe = snd_ad1889_probe, 10582f5c1302SBill Pemberton .remove = snd_ad1889_remove, 105912bb5b78SClemens Ladisch }; 106012bb5b78SClemens Ladisch 1061e9f66d9bSTakashi Iwai module_pci_driver(ad1889_pci_driver); 1062