12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052 |
- #include <linux/init.h>
- #include <linux/pci.h>
- #include <linux/dma-mapping.h>
- #include <linux/slab.h>
- #include <linux/interrupt.h>
- #include <linux/compiler.h>
- #include <linux/delay.h>
- #include <linux/module.h>
- #include <linux/io.h>
- #include <sound/core.h>
- #include <sound/pcm.h>
- #include <sound/initval.h>
- #include <sound/ac97_codec.h>
- #include "ad1889.h"
- #include "ac97/ac97_id.h"
- #define AD1889_DRVVER "Version: 1.7"
- MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>, Thibaut Varene <t-bone@parisc-linux.org>");
- MODULE_DESCRIPTION("Analog Devices AD1889 ALSA sound driver");
- MODULE_LICENSE("GPL");
- MODULE_SUPPORTED_DEVICE("{{Analog Devices,AD1889}}");
- static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
- module_param_array(index, int, NULL, 0444);
- MODULE_PARM_DESC(index, "Index value for the AD1889 soundcard.");
- static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
- module_param_array(id, charp, NULL, 0444);
- MODULE_PARM_DESC(id, "ID string for the AD1889 soundcard.");
- static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
- module_param_array(enable, bool, NULL, 0444);
- MODULE_PARM_DESC(enable, "Enable AD1889 soundcard.");
- static char *ac97_quirk[SNDRV_CARDS];
- module_param_array(ac97_quirk, charp, NULL, 0444);
- MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
- #define DEVNAME "ad1889"
- #define PFX DEVNAME ": "
- struct ad1889_register_state {
- u16 reg;
- u32 addr;
- unsigned long size;
- };
- struct snd_ad1889 {
- struct snd_card *card;
- struct pci_dev *pci;
- int irq;
- unsigned long bar;
- void __iomem *iobase;
- struct snd_ac97 *ac97;
- struct snd_ac97_bus *ac97_bus;
- struct snd_pcm *pcm;
- struct snd_info_entry *proc;
- struct snd_pcm_substream *psubs;
- struct snd_pcm_substream *csubs;
-
- struct ad1889_register_state wave;
- struct ad1889_register_state ramc;
- spinlock_t lock;
- };
- static inline u16
- ad1889_readw(struct snd_ad1889 *chip, unsigned reg)
- {
- return readw(chip->iobase + reg);
- }
- static inline void
- ad1889_writew(struct snd_ad1889 *chip, unsigned reg, u16 val)
- {
- writew(val, chip->iobase + reg);
- }
- static inline u32
- ad1889_readl(struct snd_ad1889 *chip, unsigned reg)
- {
- return readl(chip->iobase + reg);
- }
- static inline void
- ad1889_writel(struct snd_ad1889 *chip, unsigned reg, u32 val)
- {
- writel(val, chip->iobase + reg);
- }
- static inline void
- ad1889_unmute(struct snd_ad1889 *chip)
- {
- u16 st;
- st = ad1889_readw(chip, AD_DS_WADA) &
- ~(AD_DS_WADA_RWAM | AD_DS_WADA_LWAM);
- ad1889_writew(chip, AD_DS_WADA, st);
- ad1889_readw(chip, AD_DS_WADA);
- }
- static inline void
- ad1889_mute(struct snd_ad1889 *chip)
- {
- u16 st;
- st = ad1889_readw(chip, AD_DS_WADA) | AD_DS_WADA_RWAM | AD_DS_WADA_LWAM;
- ad1889_writew(chip, AD_DS_WADA, st);
- ad1889_readw(chip, AD_DS_WADA);
- }
- static inline void
- ad1889_load_adc_buffer_address(struct snd_ad1889 *chip, u32 address)
- {
- ad1889_writel(chip, AD_DMA_ADCBA, address);
- ad1889_writel(chip, AD_DMA_ADCCA, address);
- }
- static inline void
- ad1889_load_adc_buffer_count(struct snd_ad1889 *chip, u32 count)
- {
- ad1889_writel(chip, AD_DMA_ADCBC, count);
- ad1889_writel(chip, AD_DMA_ADCCC, count);
- }
- static inline void
- ad1889_load_adc_interrupt_count(struct snd_ad1889 *chip, u32 count)
- {
- ad1889_writel(chip, AD_DMA_ADCIB, count);
- ad1889_writel(chip, AD_DMA_ADCIC, count);
- }
- static inline void
- ad1889_load_wave_buffer_address(struct snd_ad1889 *chip, u32 address)
- {
- ad1889_writel(chip, AD_DMA_WAVBA, address);
- ad1889_writel(chip, AD_DMA_WAVCA, address);
- }
- static inline void
- ad1889_load_wave_buffer_count(struct snd_ad1889 *chip, u32 count)
- {
- ad1889_writel(chip, AD_DMA_WAVBC, count);
- ad1889_writel(chip, AD_DMA_WAVCC, count);
- }
- static inline void
- ad1889_load_wave_interrupt_count(struct snd_ad1889 *chip, u32 count)
- {
- ad1889_writel(chip, AD_DMA_WAVIB, count);
- ad1889_writel(chip, AD_DMA_WAVIC, count);
- }
- static void
- ad1889_channel_reset(struct snd_ad1889 *chip, unsigned int channel)
- {
- u16 reg;
-
- if (channel & AD_CHAN_WAV) {
-
- reg = ad1889_readw(chip, AD_DS_WSMC) & ~AD_DS_WSMC_WAEN;
- ad1889_writew(chip, AD_DS_WSMC, reg);
- chip->wave.reg = reg;
-
-
- reg = ad1889_readw(chip, AD_DMA_WAV);
- reg &= AD_DMA_IM_DIS;
- reg &= ~AD_DMA_LOOP;
- ad1889_writew(chip, AD_DMA_WAV, reg);
-
- ad1889_load_wave_buffer_address(chip, 0x0);
- ad1889_load_wave_buffer_count(chip, 0x0);
- ad1889_load_wave_interrupt_count(chip, 0x0);
-
- ad1889_readw(chip, AD_DMA_WAV);
- }
-
- if (channel & AD_CHAN_ADC) {
-
- reg = ad1889_readw(chip, AD_DS_RAMC) & ~AD_DS_RAMC_ADEN;
- ad1889_writew(chip, AD_DS_RAMC, reg);
- chip->ramc.reg = reg;
- reg = ad1889_readw(chip, AD_DMA_ADC);
- reg &= AD_DMA_IM_DIS;
- reg &= ~AD_DMA_LOOP;
- ad1889_writew(chip, AD_DMA_ADC, reg);
-
- ad1889_load_adc_buffer_address(chip, 0x0);
- ad1889_load_adc_buffer_count(chip, 0x0);
- ad1889_load_adc_interrupt_count(chip, 0x0);
-
- ad1889_readw(chip, AD_DMA_ADC);
- }
- }
- static u16
- snd_ad1889_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
- {
- struct snd_ad1889 *chip = ac97->private_data;
- return ad1889_readw(chip, AD_AC97_BASE + reg);
- }
- static void
- snd_ad1889_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val)
- {
- struct snd_ad1889 *chip = ac97->private_data;
- ad1889_writew(chip, AD_AC97_BASE + reg, val);
- }
- static int
- snd_ad1889_ac97_ready(struct snd_ad1889 *chip)
- {
- int retry = 400;
-
- while (!(ad1889_readw(chip, AD_AC97_ACIC) & AD_AC97_ACIC_ACRDY)
- && --retry)
- mdelay(1);
- if (!retry) {
- dev_err(chip->card->dev, "[%s] Link is not ready.\n",
- __func__);
- return -EIO;
- }
- dev_dbg(chip->card->dev, "[%s] ready after %d ms\n", __func__, 400 - retry);
- return 0;
- }
- static int
- snd_ad1889_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *hw_params)
- {
- return snd_pcm_lib_malloc_pages(substream,
- params_buffer_bytes(hw_params));
- }
- static int
- snd_ad1889_hw_free(struct snd_pcm_substream *substream)
- {
- return snd_pcm_lib_free_pages(substream);
- }
- static struct snd_pcm_hardware snd_ad1889_playback_hw = {
- .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
- SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BLOCK_TRANSFER,
- .formats = SNDRV_PCM_FMTBIT_S16_LE,
- .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
- .rate_min = 8000,
- .rate_max = 48000,
- .channels_min = 1,
- .channels_max = 2,
- .buffer_bytes_max = BUFFER_BYTES_MAX,
- .period_bytes_min = PERIOD_BYTES_MIN,
- .period_bytes_max = PERIOD_BYTES_MAX,
- .periods_min = PERIODS_MIN,
- .periods_max = PERIODS_MAX,
-
- };
- static struct snd_pcm_hardware snd_ad1889_capture_hw = {
- .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
- SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BLOCK_TRANSFER,
- .formats = SNDRV_PCM_FMTBIT_S16_LE,
- .rates = SNDRV_PCM_RATE_48000,
- .rate_min = 48000,
- .rate_max = 48000,
- .channels_min = 1,
- .channels_max = 2,
- .buffer_bytes_max = BUFFER_BYTES_MAX,
- .period_bytes_min = PERIOD_BYTES_MIN,
- .period_bytes_max = PERIOD_BYTES_MAX,
- .periods_min = PERIODS_MIN,
- .periods_max = PERIODS_MAX,
-
- };
- static int
- snd_ad1889_playback_open(struct snd_pcm_substream *ss)
- {
- struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
- struct snd_pcm_runtime *rt = ss->runtime;
- chip->psubs = ss;
- rt->hw = snd_ad1889_playback_hw;
- return 0;
- }
- static int
- snd_ad1889_capture_open(struct snd_pcm_substream *ss)
- {
- struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
- struct snd_pcm_runtime *rt = ss->runtime;
- chip->csubs = ss;
- rt->hw = snd_ad1889_capture_hw;
- return 0;
- }
- static int
- snd_ad1889_playback_close(struct snd_pcm_substream *ss)
- {
- struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
- chip->psubs = NULL;
- return 0;
- }
- static int
- snd_ad1889_capture_close(struct snd_pcm_substream *ss)
- {
- struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
- chip->csubs = NULL;
- return 0;
- }
- static int
- snd_ad1889_playback_prepare(struct snd_pcm_substream *ss)
- {
- struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
- struct snd_pcm_runtime *rt = ss->runtime;
- unsigned int size = snd_pcm_lib_buffer_bytes(ss);
- unsigned int count = snd_pcm_lib_period_bytes(ss);
- u16 reg;
- ad1889_channel_reset(chip, AD_CHAN_WAV);
- reg = ad1889_readw(chip, AD_DS_WSMC);
-
-
- reg &= ~(AD_DS_WSMC_WA16 | AD_DS_WSMC_WAST);
- if (snd_pcm_format_width(rt->format) == 16)
- reg |= AD_DS_WSMC_WA16;
- if (rt->channels > 1)
- reg |= AD_DS_WSMC_WAST;
-
- spin_lock_irq(&chip->lock);
-
- chip->wave.size = size;
- chip->wave.reg = reg;
- chip->wave.addr = rt->dma_addr;
- ad1889_writew(chip, AD_DS_WSMC, chip->wave.reg);
-
-
- ad1889_writew(chip, AD_DS_WAS, rt->rate);
-
- ad1889_load_wave_buffer_address(chip, chip->wave.addr);
- ad1889_load_wave_buffer_count(chip, size);
- ad1889_load_wave_interrupt_count(chip, count);
-
- ad1889_readw(chip, AD_DS_WSMC);
-
- spin_unlock_irq(&chip->lock);
-
- dev_dbg(chip->card->dev,
- "prepare playback: addr = 0x%x, count = %u, size = %u, reg = 0x%x, rate = %u\n",
- chip->wave.addr, count, size, reg, rt->rate);
- return 0;
- }
- static int
- snd_ad1889_capture_prepare(struct snd_pcm_substream *ss)
- {
- struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
- struct snd_pcm_runtime *rt = ss->runtime;
- unsigned int size = snd_pcm_lib_buffer_bytes(ss);
- unsigned int count = snd_pcm_lib_period_bytes(ss);
- u16 reg;
- ad1889_channel_reset(chip, AD_CHAN_ADC);
-
- reg = ad1889_readw(chip, AD_DS_RAMC);
-
- reg &= ~(AD_DS_RAMC_AD16 | AD_DS_RAMC_ADST);
- if (snd_pcm_format_width(rt->format) == 16)
- reg |= AD_DS_RAMC_AD16;
- if (rt->channels > 1)
- reg |= AD_DS_RAMC_ADST;
-
- spin_lock_irq(&chip->lock);
-
- chip->ramc.size = size;
- chip->ramc.reg = reg;
- chip->ramc.addr = rt->dma_addr;
- ad1889_writew(chip, AD_DS_RAMC, chip->ramc.reg);
-
- ad1889_load_adc_buffer_address(chip, chip->ramc.addr);
- ad1889_load_adc_buffer_count(chip, size);
- ad1889_load_adc_interrupt_count(chip, count);
-
- ad1889_readw(chip, AD_DS_RAMC);
-
- spin_unlock_irq(&chip->lock);
-
- dev_dbg(chip->card->dev,
- "prepare capture: addr = 0x%x, count = %u, size = %u, reg = 0x%x, rate = %u\n",
- chip->ramc.addr, count, size, reg, rt->rate);
- return 0;
- }
- static int
- snd_ad1889_playback_trigger(struct snd_pcm_substream *ss, int cmd)
- {
- u16 wsmc;
- struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
-
- wsmc = ad1889_readw(chip, AD_DS_WSMC);
- switch (cmd) {
- case SNDRV_PCM_TRIGGER_START:
-
- ad1889_writew(chip, AD_DMA_WAV, AD_DMA_LOOP | AD_DMA_IM_CNT);
- wsmc |= AD_DS_WSMC_WAEN;
-
- ad1889_writel(chip, AD_DMA_CHSS, AD_DMA_CHSS_WAVS);
- ad1889_unmute(chip);
- break;
- case SNDRV_PCM_TRIGGER_STOP:
- ad1889_mute(chip);
- wsmc &= ~AD_DS_WSMC_WAEN;
- break;
- default:
- snd_BUG();
- return -EINVAL;
- }
-
- chip->wave.reg = wsmc;
- ad1889_writew(chip, AD_DS_WSMC, wsmc);
- ad1889_readw(chip, AD_DS_WSMC);
-
- if (cmd == SNDRV_PCM_TRIGGER_STOP)
- ad1889_channel_reset(chip, AD_CHAN_WAV);
- return 0;
- }
- static int
- snd_ad1889_capture_trigger(struct snd_pcm_substream *ss, int cmd)
- {
- u16 ramc;
- struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
- ramc = ad1889_readw(chip, AD_DS_RAMC);
-
- switch (cmd) {
- case SNDRV_PCM_TRIGGER_START:
-
- ad1889_writew(chip, AD_DMA_ADC, AD_DMA_LOOP | AD_DMA_IM_CNT);
- ramc |= AD_DS_RAMC_ADEN;
-
- ad1889_writel(chip, AD_DMA_CHSS, AD_DMA_CHSS_ADCS);
- break;
- case SNDRV_PCM_TRIGGER_STOP:
- ramc &= ~AD_DS_RAMC_ADEN;
- break;
- default:
- return -EINVAL;
- }
-
- chip->ramc.reg = ramc;
- ad1889_writew(chip, AD_DS_RAMC, ramc);
- ad1889_readw(chip, AD_DS_RAMC);
-
-
- if (cmd == SNDRV_PCM_TRIGGER_STOP)
- ad1889_channel_reset(chip, AD_CHAN_ADC);
-
- return 0;
- }
- static snd_pcm_uframes_t
- snd_ad1889_playback_pointer(struct snd_pcm_substream *ss)
- {
- size_t ptr = 0;
- struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
- if (unlikely(!(chip->wave.reg & AD_DS_WSMC_WAEN)))
- return 0;
- ptr = ad1889_readl(chip, AD_DMA_WAVCA);
- ptr -= chip->wave.addr;
-
- if (snd_BUG_ON(ptr >= chip->wave.size))
- return 0;
-
- return bytes_to_frames(ss->runtime, ptr);
- }
- static snd_pcm_uframes_t
- snd_ad1889_capture_pointer(struct snd_pcm_substream *ss)
- {
- size_t ptr = 0;
- struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
- if (unlikely(!(chip->ramc.reg & AD_DS_RAMC_ADEN)))
- return 0;
- ptr = ad1889_readl(chip, AD_DMA_ADCCA);
- ptr -= chip->ramc.addr;
- if (snd_BUG_ON(ptr >= chip->ramc.size))
- return 0;
-
- return bytes_to_frames(ss->runtime, ptr);
- }
- static struct snd_pcm_ops snd_ad1889_playback_ops = {
- .open = snd_ad1889_playback_open,
- .close = snd_ad1889_playback_close,
- .ioctl = snd_pcm_lib_ioctl,
- .hw_params = snd_ad1889_hw_params,
- .hw_free = snd_ad1889_hw_free,
- .prepare = snd_ad1889_playback_prepare,
- .trigger = snd_ad1889_playback_trigger,
- .pointer = snd_ad1889_playback_pointer,
- };
- static struct snd_pcm_ops snd_ad1889_capture_ops = {
- .open = snd_ad1889_capture_open,
- .close = snd_ad1889_capture_close,
- .ioctl = snd_pcm_lib_ioctl,
- .hw_params = snd_ad1889_hw_params,
- .hw_free = snd_ad1889_hw_free,
- .prepare = snd_ad1889_capture_prepare,
- .trigger = snd_ad1889_capture_trigger,
- .pointer = snd_ad1889_capture_pointer,
- };
- static irqreturn_t
- snd_ad1889_interrupt(int irq, void *dev_id)
- {
- unsigned long st;
- struct snd_ad1889 *chip = dev_id;
- st = ad1889_readl(chip, AD_DMA_DISR);
-
- ad1889_writel(chip, AD_DMA_DISR, st);
- st &= AD_INTR_MASK;
- if (unlikely(!st))
- return IRQ_NONE;
- if (st & (AD_DMA_DISR_PMAI|AD_DMA_DISR_PTAI))
- dev_dbg(chip->card->dev,
- "Unexpected master or target abort interrupt!\n");
- if ((st & AD_DMA_DISR_WAVI) && chip->psubs)
- snd_pcm_period_elapsed(chip->psubs);
- if ((st & AD_DMA_DISR_ADCI) && chip->csubs)
- snd_pcm_period_elapsed(chip->csubs);
- return IRQ_HANDLED;
- }
- static int
- snd_ad1889_pcm_init(struct snd_ad1889 *chip, int device)
- {
- int err;
- struct snd_pcm *pcm;
- err = snd_pcm_new(chip->card, chip->card->driver, device, 1, 1, &pcm);
- if (err < 0)
- return err;
- snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
- &snd_ad1889_playback_ops);
- snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
- &snd_ad1889_capture_ops);
- pcm->private_data = chip;
- pcm->info_flags = 0;
- strcpy(pcm->name, chip->card->shortname);
-
- chip->pcm = pcm;
- chip->psubs = NULL;
- chip->csubs = NULL;
- err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
- snd_dma_pci_data(chip->pci),
- BUFFER_BYTES_MAX / 2,
- BUFFER_BYTES_MAX);
- if (err < 0) {
- dev_err(chip->card->dev, "buffer allocation error: %d\n", err);
- return err;
- }
-
- return 0;
- }
- static void
- snd_ad1889_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
- {
- struct snd_ad1889 *chip = entry->private_data;
- u16 reg;
- int tmp;
- reg = ad1889_readw(chip, AD_DS_WSMC);
- snd_iprintf(buffer, "Wave output: %s\n",
- (reg & AD_DS_WSMC_WAEN) ? "enabled" : "disabled");
- snd_iprintf(buffer, "Wave Channels: %s\n",
- (reg & AD_DS_WSMC_WAST) ? "stereo" : "mono");
- snd_iprintf(buffer, "Wave Quality: %d-bit linear\n",
- (reg & AD_DS_WSMC_WA16) ? 16 : 8);
-
-
- tmp = (reg & AD_DS_WSMC_WARQ) ?
- ((((reg & AD_DS_WSMC_WARQ) >> 12) & 0x01) ? 12 : 18) : 4;
- tmp /= (reg & AD_DS_WSMC_WAST) ? 2 : 1;
-
- snd_iprintf(buffer, "Wave FIFO: %d %s words\n\n", tmp,
- (reg & AD_DS_WSMC_WAST) ? "stereo" : "mono");
-
-
- snd_iprintf(buffer, "Synthesis output: %s\n",
- reg & AD_DS_WSMC_SYEN ? "enabled" : "disabled");
-
-
- tmp = (reg & AD_DS_WSMC_SYRQ) ?
- ((((reg & AD_DS_WSMC_SYRQ) >> 4) & 0x01) ? 12 : 18) : 4;
- tmp /= (reg & AD_DS_WSMC_WAST) ? 2 : 1;
-
- snd_iprintf(buffer, "Synthesis FIFO: %d %s words\n\n", tmp,
- (reg & AD_DS_WSMC_WAST) ? "stereo" : "mono");
- reg = ad1889_readw(chip, AD_DS_RAMC);
- snd_iprintf(buffer, "ADC input: %s\n",
- (reg & AD_DS_RAMC_ADEN) ? "enabled" : "disabled");
- snd_iprintf(buffer, "ADC Channels: %s\n",
- (reg & AD_DS_RAMC_ADST) ? "stereo" : "mono");
- snd_iprintf(buffer, "ADC Quality: %d-bit linear\n",
- (reg & AD_DS_RAMC_AD16) ? 16 : 8);
-
-
- tmp = (reg & AD_DS_RAMC_ACRQ) ?
- ((((reg & AD_DS_RAMC_ACRQ) >> 4) & 0x01) ? 12 : 18) : 4;
- tmp /= (reg & AD_DS_RAMC_ADST) ? 2 : 1;
-
- snd_iprintf(buffer, "ADC FIFO: %d %s words\n\n", tmp,
- (reg & AD_DS_RAMC_ADST) ? "stereo" : "mono");
-
- snd_iprintf(buffer, "Resampler input: %s\n",
- reg & AD_DS_RAMC_REEN ? "enabled" : "disabled");
-
-
- tmp = (reg & AD_DS_RAMC_RERQ) ?
- ((((reg & AD_DS_RAMC_RERQ) >> 12) & 0x01) ? 12 : 18) : 4;
- tmp /= (reg & AD_DS_RAMC_ADST) ? 2 : 1;
-
- snd_iprintf(buffer, "Resampler FIFO: %d %s words\n\n", tmp,
- (reg & AD_DS_WSMC_WAST) ? "stereo" : "mono");
-
-
-
- reg = ad1889_readw(chip, AD_DS_WADA);
- snd_iprintf(buffer, "Left: %s, -%d dB\n",
- (reg & AD_DS_WADA_LWAM) ? "mute" : "unmute",
- ((reg & AD_DS_WADA_LWAA) >> 8) * 3);
- reg = ad1889_readw(chip, AD_DS_WADA);
- snd_iprintf(buffer, "Right: %s, -%d dB\n",
- (reg & AD_DS_WADA_RWAM) ? "mute" : "unmute",
- (reg & AD_DS_WADA_RWAA) * 3);
-
- reg = ad1889_readw(chip, AD_DS_WAS);
- snd_iprintf(buffer, "Wave samplerate: %u Hz\n", reg);
- reg = ad1889_readw(chip, AD_DS_RES);
- snd_iprintf(buffer, "Resampler samplerate: %u Hz\n", reg);
- }
- static void
- snd_ad1889_proc_init(struct snd_ad1889 *chip)
- {
- struct snd_info_entry *entry;
- if (!snd_card_proc_new(chip->card, chip->card->driver, &entry))
- snd_info_set_text_ops(entry, chip, snd_ad1889_proc_read);
- }
- static const struct ac97_quirk ac97_quirks[] = {
- {
- .subvendor = 0x11d4,
- .subdevice = 0x1889,
- .codec_id = AC97_ID_AD1819,
- .name = "AD1889",
- .type = AC97_TUNE_HP_ONLY
- },
- { }
- };
- static void
- snd_ad1889_ac97_xinit(struct snd_ad1889 *chip)
- {
- u16 reg;
- reg = ad1889_readw(chip, AD_AC97_ACIC);
- reg |= AD_AC97_ACIC_ACRD;
- ad1889_writew(chip, AD_AC97_ACIC, reg);
- ad1889_readw(chip, AD_AC97_ACIC);
- udelay(10);
-
- reg |= AD_AC97_ACIC_ACIE;
- ad1889_writew(chip, AD_AC97_ACIC, reg);
-
- snd_ad1889_ac97_ready(chip);
-
- reg = ad1889_readw(chip, AD_AC97_ACIC);
- reg |= AD_AC97_ACIC_ASOE | AD_AC97_ACIC_VSRM;
- ad1889_writew(chip, AD_AC97_ACIC, reg);
- ad1889_readw(chip, AD_AC97_ACIC);
- }
- static void
- snd_ad1889_ac97_bus_free(struct snd_ac97_bus *bus)
- {
- struct snd_ad1889 *chip = bus->private_data;
- chip->ac97_bus = NULL;
- }
- static void
- snd_ad1889_ac97_free(struct snd_ac97 *ac97)
- {
- struct snd_ad1889 *chip = ac97->private_data;
- chip->ac97 = NULL;
- }
- static int
- snd_ad1889_ac97_init(struct snd_ad1889 *chip, const char *quirk_override)
- {
- int err;
- struct snd_ac97_template ac97;
- static struct snd_ac97_bus_ops ops = {
- .write = snd_ad1889_ac97_write,
- .read = snd_ad1889_ac97_read,
- };
-
- snd_ad1889_ac97_xinit(chip);
- err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus);
- if (err < 0)
- return err;
-
- chip->ac97_bus->private_free = snd_ad1889_ac97_bus_free;
- memset(&ac97, 0, sizeof(ac97));
- ac97.private_data = chip;
- ac97.private_free = snd_ad1889_ac97_free;
- ac97.pci = chip->pci;
- err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97);
- if (err < 0)
- return err;
-
- snd_ac97_tune_hardware(chip->ac97, ac97_quirks, quirk_override);
-
- return 0;
- }
- static int
- snd_ad1889_free(struct snd_ad1889 *chip)
- {
- if (chip->irq < 0)
- goto skip_hw;
- spin_lock_irq(&chip->lock);
- ad1889_mute(chip);
-
- ad1889_channel_reset(chip, AD_CHAN_WAV | AD_CHAN_ADC);
-
- ad1889_writel(chip, AD_DMA_DISR, AD_DMA_DISR_PTAI | AD_DMA_DISR_PMAI);
- ad1889_readl(chip, AD_DMA_DISR);
- spin_unlock_irq(&chip->lock);
- if (chip->irq >= 0)
- free_irq(chip->irq, chip);
- skip_hw:
- iounmap(chip->iobase);
- pci_release_regions(chip->pci);
- pci_disable_device(chip->pci);
- kfree(chip);
- return 0;
- }
- static int
- snd_ad1889_dev_free(struct snd_device *device)
- {
- struct snd_ad1889 *chip = device->device_data;
- return snd_ad1889_free(chip);
- }
- static int
- snd_ad1889_init(struct snd_ad1889 *chip)
- {
- ad1889_writew(chip, AD_DS_CCS, AD_DS_CCS_CLKEN);
- ad1889_readw(chip, AD_DS_CCS);
- mdelay(10);
-
- ad1889_writel(chip, AD_DMA_DISR, AD_DMA_DISR_PMAE | AD_DMA_DISR_PTAE);
- return 0;
- }
- static int
- snd_ad1889_create(struct snd_card *card,
- struct pci_dev *pci,
- struct snd_ad1889 **rchip)
- {
- int err;
- struct snd_ad1889 *chip;
- static struct snd_device_ops ops = {
- .dev_free = snd_ad1889_dev_free,
- };
- *rchip = NULL;
- if ((err = pci_enable_device(pci)) < 0)
- return err;
-
- if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0 ||
- dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) {
- dev_err(card->dev, "error setting 32-bit DMA mask.\n");
- pci_disable_device(pci);
- return -ENXIO;
- }
-
- if ((chip = kzalloc(sizeof(*chip), GFP_KERNEL)) == NULL) {
- pci_disable_device(pci);
- return -ENOMEM;
- }
- chip->card = card;
- card->private_data = chip;
- chip->pci = pci;
- chip->irq = -1;
-
- if ((err = pci_request_regions(pci, card->driver)) < 0)
- goto free_and_ret;
- chip->bar = pci_resource_start(pci, 0);
- chip->iobase = pci_ioremap_bar(pci, 0);
- if (chip->iobase == NULL) {
- dev_err(card->dev, "unable to reserve region.\n");
- err = -EBUSY;
- goto free_and_ret;
- }
-
- pci_set_master(pci);
- spin_lock_init(&chip->lock);
- if (request_irq(pci->irq, snd_ad1889_interrupt,
- IRQF_SHARED, KBUILD_MODNAME, chip)) {
- dev_err(card->dev, "cannot obtain IRQ %d\n", pci->irq);
- snd_ad1889_free(chip);
- return -EBUSY;
- }
- chip->irq = pci->irq;
- synchronize_irq(chip->irq);
-
- if ((err = snd_ad1889_init(chip)) < 0) {
- snd_ad1889_free(chip);
- return err;
- }
- if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
- snd_ad1889_free(chip);
- return err;
- }
- *rchip = chip;
- return 0;
- free_and_ret:
- kfree(chip);
- pci_disable_device(pci);
- return err;
- }
- static int
- snd_ad1889_probe(struct pci_dev *pci,
- const struct pci_device_id *pci_id)
- {
- int err;
- static int devno;
- struct snd_card *card;
- struct snd_ad1889 *chip;
-
- if (devno >= SNDRV_CARDS)
- return -ENODEV;
- if (!enable[devno]) {
- devno++;
- return -ENOENT;
- }
-
- err = snd_card_new(&pci->dev, index[devno], id[devno], THIS_MODULE,
- 0, &card);
-
- if (err < 0)
- return err;
- strcpy(card->driver, "AD1889");
- strcpy(card->shortname, "Analog Devices AD1889");
-
- err = snd_ad1889_create(card, pci, &chip);
- if (err < 0)
- goto free_and_ret;
-
- sprintf(card->longname, "%s at 0x%lx irq %i",
- card->shortname, chip->bar, chip->irq);
-
-
- err = snd_ad1889_ac97_init(chip, ac97_quirk[devno]);
- if (err < 0)
- goto free_and_ret;
-
- err = snd_ad1889_pcm_init(chip, 0);
- if (err < 0)
- goto free_and_ret;
-
- snd_ad1889_proc_init(chip);
-
- err = snd_card_register(card);
- if (err < 0)
- goto free_and_ret;
-
- pci_set_drvdata(pci, card);
- devno++;
- return 0;
- free_and_ret:
- snd_card_free(card);
- return err;
- }
- static void
- snd_ad1889_remove(struct pci_dev *pci)
- {
- snd_card_free(pci_get_drvdata(pci));
- }
- static const struct pci_device_id snd_ad1889_ids[] = {
- { PCI_DEVICE(PCI_VENDOR_ID_ANALOG_DEVICES, PCI_DEVICE_ID_AD1889JS) },
- { 0, },
- };
- MODULE_DEVICE_TABLE(pci, snd_ad1889_ids);
- static struct pci_driver ad1889_pci_driver = {
- .name = KBUILD_MODNAME,
- .id_table = snd_ad1889_ids,
- .probe = snd_ad1889_probe,
- .remove = snd_ad1889_remove,
- };
- module_pci_driver(ad1889_pci_driver);
|